home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / MFUNCS.H < prev    next >
Text File  |  1989-02-08  |  13KB  |  353 lines

  1. /*
  2.  * mfuncs.h -- Global functions within MLE
  3.  *
  4.  * Created by Microsoft Corporation, 1989
  5.  */
  6.  
  7. #define private         // keyword for a function local to a module
  8. #define public          // keyword for a global function
  9.  
  10. /***********************************************************************
  11. *  Generally important constants
  12. ***********************************************************************/
  13.  
  14. #define QWP_PED QWL_USER
  15. #define TID_MOUSESCROLL 1
  16.  
  17. /***********************************************************************
  18. *  Global functions
  19. ***********************************************************************/
  20.  
  21. public VOID InitInstance(HWND hwnd);
  22.     // Initializes an MLE window
  23.  
  24. MRESULT CALLBACK MleWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  25.     // Window procedure for MLE
  26.  
  27. /***********************************************************************
  28. * Owner Notification functions
  29. ***********************************************************************/
  30.  
  31. public VOID NotifyOwner(PED ped, USHORT usENCode, MPARAM mparam);
  32.     // Notifies the ownder of some event
  33.  
  34. public VOID NotifyScroll(PED ped, SHORT usCode, BOOL fForce);
  35.     // Notifies the owner in case of scroll
  36.  
  37. /***********************************************************************
  38. *  Memory Manager functions
  39. ***********************************************************************/
  40.  
  41. public PVOID AllocStore(PED ped, USHORT size);
  42.     // Allocate size bytes
  43.  
  44. public VOID FreeStore(PED ped, PVOID p);
  45.     // Releases memory allocated by AllocStore
  46.  
  47. public BOOL InitStore(PED ped);
  48.     // Initializes memory manager; must be called before other mm ops
  49.  
  50.  
  51. /***********************************************************************
  52. *  Text Manager Functions
  53. ***********************************************************************/
  54.  
  55. public BOOL TxtInit(PED ped);
  56.     // Initializes the text manager
  57.  
  58. public BOOL TxtChange(PED ped, IPT iptFrom, IPT iptTo, PCHAR pch, OFFSET cch);
  59.     // Change text in MLE
  60.  
  61. public VOID TxtReformat(PED ped, PPR ppr, BOOL fAllText);
  62.     // Reformats text with changed area starting at ppr
  63.  
  64. public IPT TxtLength(PED ped);
  65.     // Length of text in MLE
  66.  
  67. public IPT TxtLineLength(PED ped, PPR ppr);
  68.     // Return the length of line containing a piece
  69.  
  70. public IPT TxtLengthToEOL(PED ped, IPT ipt, BOOL fIncludeLBCh);
  71.     // Return the length from an ipt to the end of line
  72.  
  73. public IPT TxtLengthToEOLPPR(PED ped, PPR ppr, OFFSET off, BOOL fIncludeLBCh);
  74.     // Return the length from a ppr/offset to the end of line
  75.  
  76. public IPT TxtLengthToBOL(PED ped, IPT ipt);
  77.     // Return the length from an ipt to the beginning of line
  78.  
  79. public IPT TxtLengthToBOLPPR(PED ped, PPR ppr, OFFSET off);
  80.     // Return the length from a ppr/offset to the beginning of line
  81.  
  82. public IPT TxtCchToBegOfToken(PPR ppr, OFFSET off);
  83. public IPT TxtCchToEndOfToken(PPR ppr, OFFSET off);
  84.     // Return the characters to the beginning (end) of a token
  85.  
  86. public BOOL TxtQueryWordWrap(PED ped);
  87.     // Return the word wrap status of a document
  88.  
  89. public BOOL TxtSetWordWrap(PED ped, BOOL fWW);
  90.     // Set the word wrap status of a document
  91.  
  92. public IPT TxtQueryAnchor(PED ped);
  93. public IPT TxtQueryCursor(PED ped);
  94. public IPT TxtQueryMinSel(PED ped);
  95. public IPT TxtQueryMaxSel(PED ped);
  96.     // Query the anchor and cursor positions
  97.  
  98. public IPT TxtSetAnchorCursor(PED ped, IPT iptAnchor, IPT iptCursor);
  99.     // Set the anchor and/or cursor position
  100.  
  101. public BOOL TxtSetLimit(PED ped, IPT iptMax);
  102.     // Set the text limit
  103.  
  104. public BOOL TxtQueryChanged(PED ped);
  105.     // Returns current change status
  106.  
  107. public BOOL TxtSetChanged(PED ped, BOOL fChanged);
  108.     // Sets the change flag to a particular value; sends EN_CHANGE if needed
  109.  
  110. public PPR TxtPPROfIpt(PED ped, PIPT pipt);
  111.     // Finds the piece and offset associated with a particular offset
  112.  
  113. /***********************************************************************
  114. * Clipboard functions
  115. ***********************************************************************/
  116.  
  117. public BOOL TxtClipCut(PED ped, IPT iptFrom, IPT iptTo);
  118.     // Cut the given range to the clipboard
  119.  
  120. public BOOL TxtClipCopy(PED ped, IPT iptFrom, IPT iptTo);
  121.     // Copy the given range to the clipboard
  122.  
  123. public BOOL TxtClipPaste(PED ped, IPT iptFrom, IPT iptTo);
  124.     // Paste from the clipboard, replacing the given range
  125.  
  126. public BOOL TxtClipClear(PED ped, IPT iptFrom, IPT iptTo);
  127.     // Clear the given range
  128.  
  129. /***********************************************************************
  130. * Piece manager functions
  131. ***********************************************************************/
  132.  
  133. public PPR PieceInit(PED ped, OFFSET offSize);
  134.     // initializes piece manager
  135.  
  136. public IPT PieceLength(PPR ppr);
  137.     // returns length of a piece
  138.  
  139. public PPR CreateSizedPiece(PED ped, OFFSET cchMin, OFFSET cchReq);
  140.     // create a new piece of a given size
  141.  
  142. public PCHAR InsEndChars(PED ped, PPPR pppr, POFFSET pcch);
  143.     // reserve *cch characters at the end of a piece for insertion
  144.  
  145. public PMR InsEndMarker(PED ped, PPR ppr, USHORT fFlags);
  146.     // inserts a marker piece after ppr in text order
  147.  
  148. public PMR InsBeforeMarker(PED ped, PPR ppr, USHORT fFlags);
  149.     // inserts a marker piece before ppr in text order
  150.  
  151. public PPR DelStartChars(PED ped, PPR ppr, OFFSET cch);
  152.     // delete cch charactes from the beginning of a piece
  153.  
  154. public PPR DelEndChars(PED ped, PPR ppr, OFFSET cch);
  155.     // delete cch characters from the end of a piece
  156.  
  157. public PPR DelMarker(PED ped, PMR pmr);
  158.     // delete a marker piece
  159.  
  160. public PPR SplitPiece(PED ped, PPR pprLeft, OFFSET cch);
  161.     // split a piece into two pieces at a given point
  162.  
  163. public PPR ConditionalSplitPiece(PED ped, PPR pprLeft, OFFSET cch);
  164.     // split a piece into two pieces at a given point, if they aren't already
  165.  
  166. public PPR AppendSegment(PED ped, PPR ppr, SEL sel, OFFSET cch);
  167.     // appends a segment full of text in fastest possible way
  168.  
  169. public PPR PprOfOffset(PPR ppr, PIPT poffCh);
  170.     // given a ppr, finds ppr *poffCh chars later and offset into that piece
  171.  
  172. public BOOL fIsMarker(PPR ppr);
  173.     // returns whether a piece is a marker piece or not
  174.  
  175. #define fIsMarkerType(ppr, mtype) (fIsMarker(ppr) && (((PMR)ppr)->fFlags & (mtype)))
  176.     // helper macro -- whether a piece is a marker of a given type or not
  177.  
  178. public PPR SkipMarkers(PPR ppr, USHORT fMask);
  179.     // returns the first non-matching piece, searching from ppr along 'next'
  180.  
  181. public PPR SkipText(PPR ppr, USHORT fMask);
  182.     // returns the first matching marker piece, searching from ppr along next
  183.  
  184. public PPR SkipBackText(PPR ppr, USHORT fMask);
  185.     // returns the first matching marker piece, searching from ppr along prev
  186.  
  187. public BOOL LockMarker(PMR pmr, BOOL fLocked);
  188.     // locks or unlocks a marker piece (locked => no delete)
  189.  
  190. public CHAR AdvancePointer(PPPR pppr, POFFSET poff);
  191.     // moves *pppr / *poff one char further along the text chain
  192.  
  193. public CHAR RetreatPointer(PPPR pppr, POFFSET poff);
  194.     // moves *pppr / *poff one char previous along the text chain
  195.  
  196. public CHAR CharOfPointer(PPR ppr, OFFSET off);
  197.     // returns the character at a given point in text
  198.  
  199. /***********************************************************************
  200. * Mouse manager functions
  201. ***********************************************************************/
  202.  
  203. public VOID MouseInit(PED ped);
  204.     // Initializes mouse manager
  205.  
  206. public VOID ProcessMouse (PED ped, USHORT nMessage, SHORT x, SHORT y);
  207.     // processes one mouse message
  208.  
  209.  
  210. /***********************************************************************
  211. * Keyboard manager functions
  212. ***********************************************************************/
  213.  
  214. public BOOL KbdInit(PED ped);
  215.     // initializes the Keyboard Manager
  216.  
  217. public VOID ProcessKey (PED ped, USHORT usVirtKey, USHORT usChar,
  218.         USHORT fus, SHORT cchRepeats);
  219.     // processes one keyboard message
  220.  
  221. public BOOL SetTyping(PED ped, BOOL fTyping);
  222.     // sets typing mode on or off
  223.  
  224. public BOOL QueryTyping(PED ped);
  225.     // returns the current typing mode
  226.  
  227. /***********************************************************************
  228. * Pixel-mapping functions
  229. ***********************************************************************/
  230.  
  231. public PIX TabWidth(PED ped, PIX pix);
  232.     // returns pixel width of a tab starting at pix
  233.  
  234. public PIX PixOfChar(PED ped, PIX pix, CHAR ch);
  235.     // returns pixel width of any character, starting at pix
  236.  
  237. public PIX SetTabWidth(PED ped, PIX TabSize);
  238.     // sets tab-width
  239.  
  240. public PIX QueryTabWidth(PED ped);
  241.     // returns current tab-width setting
  242.  
  243. public PIX PixFromText(PED ped,PPPR pppr,POFFSET poff,OFFSET cch,PIX pixStart);
  244.     // returns pixel width of a run of text on one line
  245.  
  246. public IPT TextFromPix(PED ped, PPPR pppr, POFFSET poff,
  247.                         PPIX ppix, USHORT usMode);
  248.     // finds the text position in a line associated with a pixel index
  249.  
  250. /***********************************************************************
  251. * Buffer Manager functions
  252. ***********************************************************************/
  253.  
  254. public VOID BufInit(PED ped);
  255.     // initializes buffer manager
  256.  
  257. public BOOL BufSetBuf(PED ped,PCHAR pch,USHORT usLen);
  258.     // Sets the default transfer buffer and size
  259.  
  260. public PCHAR BufQueryBuf(PED ped);
  261.     // Queries the default transfer buffer
  262.  
  263. public USHORT BufQueryBufSize(PED ped);
  264.     // Queries size of the default transfer buffer
  265.  
  266. public BOOL BufSetFormat(PED ped,USHORT usFmt);
  267.     // Sets the default transfer format
  268.  
  269. public USHORT BufQueryFormat(PED ped);
  270.     // Queries the default transfer format
  271.  
  272. public IPT BufFormattedSize(PED ped, IPT iptFrom, IPT iptTo, USHORT usFormat);
  273.     // returns the number of bytes required to hold the text in usFormat
  274.  
  275. public OFFSET BufCopyOut(PED ped, IPT iptFrom, USHORT usFormat,
  276.                       PSZ pszBuff, OFFSET cch);
  277.     // copies formatted text from edit control to a buffer
  278.  
  279. public BOOL BufCopyIn(PED ped, IPT iptFrom, IPT iptTo,
  280.                         PSZ pszBuff, OFFSET cch);
  281.     // copies formatted text from a buffer to edit control
  282.  
  283. /***********************************************************************
  284. * Display Manager functions
  285. ***********************************************************************/
  286.  
  287. public VOID DisplayInit(PED ped);
  288.     // initializes display manager
  289.  
  290. public VOID SetFocus(PED ped, BOOL fReceiveFocus);
  291.     // get or lose focus
  292.  
  293. public VOID DispChangeFont(PED ped, PFATTRS pfattrs);
  294.     // set the drawing font
  295.  
  296. public VOID DispChangeSize (PED ped, USHORT xWndPels, USHORT yWndPels);
  297.     // handle change in window size
  298.  
  299. public PIX DispWidth(PED ped);
  300.     // returns width of display area, in pixels
  301.  
  302. public LINE DispHeight(PED ped);
  303.     // returns number of lines displayable on screen
  304.  
  305. public VOID DispRefresh(PED ped, BOOL fForce, RECTL rcl);
  306.     // causes the display to refresh itself
  307.  
  308. public VOID DispHScroll(PED ped, PIX dx, BOOL fNotify);
  309.     // changes the horizontal scrolling by dx
  310.  
  311. public VOID DispHScrollTo(PED ped, PIX x, BOOL fNotify);
  312.     // sets the horizontal scrolling to x
  313.  
  314. public VOID DispVScroll(PED ped, LINE dy, BOOL fNotify);
  315.     // changes the vertical scrolling by dy lines
  316.  
  317. public VOID DispVScrollToIPT(PED ped, IPT ipt, BOOL fNotify);
  318.     // sets the vertical scrolling to line containing ipt
  319.  
  320. public VOID DispSetCursorXY(PED ped, PIX x, PIX y, BOOL fExtend, BOOL fWord);
  321.     // sets the cursor to an x,y position on the screen
  322.  
  323. /***********************************************************************
  324. * Assembler utility functions
  325. ***********************************************************************/
  326.  
  327. public USHORT MultDivNR(USHORT a, USHORT b, USHORT c);
  328.     // returns (a*b)/c with long intermediates
  329.  
  330. /***********************************************************************
  331. * Generally useful macros
  332. ***********************************************************************/
  333.  
  334. #define min(a,b) ((a)<(b)?(a):(b))
  335. #define max(a,b) ((a)>(b)?(a):(b))
  336.  
  337. #define abs(x)  ((x) >= 0 ? (x) : -(x))
  338. #define FORCE(iMin,iMac,i) (((i)<(iMin))?(iMin):(((i)>(iMac))?(iMac):(i)))
  339.     // force i into the range [iMin, iMac]
  340.  
  341. #define LOSHORTFROMMP(mp) SHORT1FROMMP(mp)   // synonyms for standard macros
  342. #define HISHORTFROMMP(mp) SHORT2FROMMP(mp)
  343.  
  344.  
  345.    /* Get a pointer to the edit record associated with an MLE window. */
  346. #define GETPED(hwnd) ((PED)WinQueryWindowPtr((hwnd),QWP_PED))
  347.  
  348. // characters considered whitespace in a line
  349. #define fIsWhiteSpace(ch) (((ch)==' ') || ((ch)=='\t'))
  350.  
  351. // Sets a rectangle to all-zero.
  352. #define ZeroRect(rcl) (LFillStruct((PCH)&(rcl),sizeof(RECTL),(BYTE)0))
  353.