home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / MTYPES.H < prev    next >
C/C++ Source or Header  |  1989-02-08  |  13KB  |  328 lines

  1. /*
  2.  * mtypes.h -- Types for the MLE
  3.  *
  4.  * Created by Microsoft Corporation, 1989
  5.  */
  6.  
  7. /***********************************************************************
  8. * Measurements
  9. ***********************************************************************/
  10.  
  11. #ifndef MLE
  12. typedef LONG IPT;       // insertion point in text (between two chars)
  13. typedef SHORT LINE;     // line number
  14. #endif
  15.  
  16. typedef IPT FAR *PIPT;
  17. typedef SHORT PIX;      // pixel offset
  18. typedef PIX FAR *PPIX;
  19. typedef USHORT OFFSET;  // offset within a segment or a piece
  20. typedef OFFSET FAR *POFFSET;
  21.  
  22. /***********************************************************************
  23. * Piece Management
  24. ***********************************************************************/
  25.  
  26. /* Segment record:  used to track information about segments containing
  27.  * piece information.
  28.  */
  29.  
  30. typedef struct _SEGDESC {
  31.         OFFSET cchLen;
  32.         SEL    sel;
  33.         OFFSET cchFree;
  34.         struct _PIECE FAR *pprPhysLast;
  35.         struct _SEGDESC FAR *psdNext;
  36.         struct _SEGDESC FAR *psdPrev;
  37. } SEGDESC;
  38. typedef SEGDESC FAR *PSEGDESC;
  39.  
  40. /*
  41.  * Piece manager tuning parameters
  42.  */
  43.  
  44. // GrowSize -- minimum amount by which segments should be grown during
  45. //             an ExtendSpace operation
  46.  
  47. #define PIECE_GROWSIZE (ULONG)16384
  48.  
  49. // MaxSegSize -- maximum size a segment is allowed to grow to before
  50. //               another segment must be used.  Is equal to 64K-1 so
  51. //               it can be represented in a USHORT.
  52. #define PIECE_MAXSEGSIZE (ULONG)65535
  53.  
  54. // MinCreate and MaxCreate are used during InsEndChars.  When a piece
  55. // runs out of room, then a new piece of size MinCreate <= size <= MaxCreate
  56. // will be created.  MinCreate should be set so that it is reasonably likely
  57. // that future insertions will not need to create new space; MaxCreate should
  58. // be small enough so that fragmentation doesn't get too bad.
  59. #define PIECE_MINCREATE PIECE_GROWSIZE
  60. #define PIECE_MAXCREATE PIECE_MAXSEGSIZE
  61.  
  62. // MinDelete -- when a deletion causes a free space of size >= MinDelete,
  63. //              the associated segment is bubbled to the front of the
  64. //              segment list.
  65. #define PIECE_MINDELETE 512
  66.  
  67. /*
  68.  * Piece record:  used to connect chunks of text.  Chunks never extend
  69.  * beyond paragraph boundaries.  There is one sequence of chunks, defined
  70.  * by the TextNext/TextPrev list, that defines the contents of a paragraph.
  71.  * In addition pieces are linked in physical order (to accomodate the
  72.  * PieceMemory manager.
  73.  * Note that a piece record really only serves to mark the existence
  74.  * of the actual piece.
  75.  */
  76.  
  77. struct _PIECE {
  78.         struct _PIECE FAR *pprTextNext;   // next and previous in text order
  79.         struct _PIECE FAR *pprTextPrev;
  80.         CHAR FAR *pchText;                // actual piece
  81.         OFFSET cchText;                   // amount of valid text in piece
  82.         OFFSET cchUnused;                 // amt of unused space in piece
  83.         struct _PIECE FAR *pprPhysNext;   // next/prev in phys memory order
  84.         struct _PIECE FAR *pprPhysPrev;
  85.         PSEGDESC psd;                     // descriptor for containing segment
  86. };
  87. typedef struct _PIECE PIECE;
  88. typedef PIECE FAR *PPR;
  89. typedef PPR FAR *PPPR;
  90.  
  91. /*
  92.  * Marker Piece record:  used to insert special markers into the text stream.
  93.  * In particular, marks beginnings of lines.  Combined into the heterogeneous
  94.  * text-order list with Piece records (above); marker records can be
  95.  * identified by a NULL value for pchText.  The text manager only maintains
  96.  * the marker's order in the text list; it may dispose of the marker at will
  97.  * (unless the marker is locked)
  98.  * and may create new markers as text is changed.  Whenever the text manager
  99.  * creates a marker, it will set cchValid to zero; the display manager
  100.  * must then not rely on the values it is responsible for setting.
  101.  * The text manager is also responsible for shortening cchValid whenever
  102.  * text changes.
  103.  */
  104.  
  105. struct _MARKERPIECE {
  106.         PIECE pr;                         // general piece fields
  107.         BOOL fLocked;                     // true => cannot be deleted
  108.         USHORT fFlags;                    // attribute flags
  109.         LINE sScreenLine;                 // screen line number
  110.         IPT cchLine;                       // line length in chars
  111.         IPT cchValid;                      // count of drawn chars
  112.         PIX pixLine;                       // line length in pixels
  113.         PIX pixValid;                      // pix index of first invalid char
  114.         IPT cchBegin;                      // char index of first inversion
  115.         IPT cchEnd;                        // char index of last inversion
  116. };
  117. typedef struct _MARKERPIECE MARKERPIECE;
  118. typedef MARKERPIECE FAR *PMR;
  119. typedef PMR FAR *PPMR;
  120.  
  121. // Marker flags
  122. #define MARKER_BOT     0x0001           // beginning of text
  123. #define MARKER_LB      0x0002           // line break
  124. #define MARKER_EOT     0x0004           // end of text
  125. #define MARKER_SLB     0x0008           // soft line break
  126. #define MARKER_SPILL   0x0010           // spill line break (broken word)
  127. #define MARKER_DISPLAY 0x0020           // display position marker
  128.  
  129. #define MARKER_ANY     0xffff           // matches any marker
  130. #define MARKER_LINE    0x001f           // matches any line marker
  131. #define MARKER_NOTLINE 0xffe0           // matches anything but a line
  132. #define MARKER_HARDLINE (MARKER_BOT | MARKER_LB | MARKER_EOT)
  133. #define MARKER_SOFTLINE (MARKER_SLB | MARKER_SPILL)
  134.  
  135. /***********************************************************************
  136. *  Text Management
  137. ***********************************************************************/
  138.  
  139. // CCHDEFAULTMAX -- unless the app specifies otherwise, this is the default
  140. // size the MLE will configure itself for.  Note that a nonpositive max will
  141. // imply no predefined limit.
  142. #define CCHDEFAULTMAX PIECE_MINCREATE
  143.  
  144. // DEFAULT_TABSIZE -- # of average char widths per tab stop
  145. #define DEFAULT_TABSIZE 8
  146.  
  147. /***********************************************************************
  148. *  Memory Management
  149. ***********************************************************************/
  150.  
  151.  
  152. // Segment sizes that can be allocated
  153. //   must be 2**i
  154. #define SEG8K (ULONG)8192
  155. #define SEG16K (ULONG)16384
  156. #define SEG32K (ULONG)32768
  157. #define SEG64K (ULONG)65536
  158.  
  159. #define STORE_INITSIZE SEG8K
  160. #define STORE_MAXSEG (SEG64K-1)
  161.  
  162. /*
  163.  * Segment header -- defines the size and contents of a segment
  164.  */
  165.  
  166. typedef struct _seghdr {
  167.         SEL this;
  168.         struct _seghdr FAR *next;
  169.         struct _seghdr FAR *prev;
  170.         LONG size;
  171. } SEGHDR;
  172. typedef SEGHDR FAR *PSEGHDR;
  173.  
  174. #define SEGHDROF(sel) (PSEGHDR)(MAKEP(sel,0))
  175.  
  176. /*
  177.  * free block -- links together free spots in a segment
  178.  */
  179.  
  180. typedef struct _freeblock {
  181.         BYTE  tag;
  182.         struct _freeblock FAR *next;
  183.         struct _freeblock FAR *prev;
  184. } FREEBLOCK;
  185. typedef FREEBLOCK FAR *PFREEBLOCK;
  186.  
  187. #define PFB_TAGRESERVED (UCHAR)0x70     // tag & this indicates block reserved
  188. #define PFB_TAGSIZE     (UCHAR)0x0f     // 4 bits representing size
  189.                                         //    (2**field+1)
  190.  
  191. #define freeblock_size(pfb) (IndexToSize(((pfb)->tag)&PFB_TAGSIZE))
  192.  
  193. /***********************************************************************
  194. * Buffer Manager Types
  195. ***********************************************************************/
  196.  
  197. /***********************************************************************
  198. * Display manager types
  199. ***********************************************************************/
  200.  
  201. // character rounding modes
  202. #define ROUND_CLOSEST 0
  203. #define ROUND_UP 1
  204. #define ROUND_DOWN 2
  205.  
  206. // font identifiers
  207. #define SPECIAL_FONT_SETID 1L           // User-selected font id
  208. #define DUMMY_FONT_SETID 2L             // Dummy id to test the pfattrs
  209.  
  210. // character width table size and base
  211. #define MAXCHAR 256L                    // maximum character code (used as
  212.                                         // size of character width table)
  213. #define MINCHAR 0L                      // minimum character code
  214.  
  215.  
  216. // minimum margins, in characters.  The numerator/denominator form is used
  217. // to save floating point ops.
  218. //
  219. // Apparent margins may actually be greater; e.g., if the window is
  220. // 5.5 chars high after the minimum margins are subtracted, only 5
  221. // lines are displayed, and the extra half line of space is distributed
  222. // between the top and bottom margins.
  223.  
  224. #define MARG_LFTNUM 1
  225. #define MARG_LFTDEN 1  /* Left Margin is 1.0 ACW */
  226. #define MARG_RGTNUM 1
  227. #define MARG_RGTDEN 1  /* Right Margin is 1.0 ACW */
  228. #define MARG_TOPNUM 1
  229. #define MARG_TOPDEN 2  /* Top Margin is 0.5 MBE */
  230. #define MARG_BOTNUM 1
  231. #define MARG_BOTDEN 2  /* Bottom Margin is 0.5 MBE */
  232.  
  233. // maximum number of lines allowed on the screen
  234. // defines size of line validation array
  235.  
  236. #define DISPLAY_MAXLINES 250
  237.  
  238. // maximum pixel width of the display.  When not in word-wrap mode, lines
  239. // which exceed BREAKPIX will be broken arbitrarily so that the pixel length
  240. // is less than MAXPIX.
  241.  
  242. #define DISPLAY_BREAKPIX 32000
  243. #define DISPLAY_MAXPIX   32700
  244.  
  245. // number of average character widths to scroll when mouse clicks
  246. // occur left or right of the window or in response to a scroll bar
  247. // col-left or col-right
  248. #define DISPLAY_SCROLLACWS 2
  249.  
  250. // character to be drawn when a newline character is encountered
  251. #define DISPLAY_NEWLINECHAR ' '
  252.  
  253. /***********************************************************************
  254. * Global state info
  255. ***********************************************************************/
  256.  
  257. /*
  258.  * PED -- pointer to the edit record; defines all permanent state
  259.  * information for a window
  260.  */
  261.  
  262. typedef struct _ed {
  263.  
  264.         // Generally global stuff
  265.         HWND hwnd;         // handle of window associated with edit ctl
  266.         USHORT idChild;    // child ID of edit window
  267.         ULONG  flStyle;    // edit window style bits
  268.  
  269.         // Memory Manager Fields
  270.         PSEGHDR selHead, selTail;       // list of segments
  271.         PFREEBLOCK pfbHead, pfbTail;    // free list
  272.  
  273.         // Text Manager Fields
  274.         BOOL fChanged;                  // set => change since last query
  275.         PPR pprHead, pprTail;           // text-order piece list
  276.         IPT iptCursor, iptAnchor;
  277.         BOOL fWordWrap;                 // set => word wrap is on
  278.         IPT iptMac;                     // greatest existing ipt
  279.         IPT iptMax;                     // greatest allowable ipt
  280.  
  281.         // Piece Manager Fields
  282.         PSEGDESC psdCurrent;            // head of piece segment list
  283.         PSEGDESC psdLast;               // tail of piece segment list
  284.  
  285.         // Display Manager Fields
  286.         BOOL fFocus;                    // set => window has focus
  287.         HPS hps;                        // presentation space for text
  288.         RECTL rclWnd;                   // entire area of window
  289.         BOOL fHSizeDelta;               // Horiz size chg since last refresh
  290.         BOOL fVSizeDelta;               // Vert size chg since last refresh
  291.         BOOL fScrollDelta;              // Scrolling has changed
  292.         RECTL rclText;                  // area text can be drawn in
  293.         LINE lyWndSize;                 // number of lines on screen
  294.         PPMR papmrValid;                // array of line validation pointers
  295.         PIX pixCurMax;                  // max found width of document
  296.         PIX AveCharWidth;               // average character width, pixels
  297.         PIX pixMaxChar;                 // character widths for estimating
  298.         PIX pixMinChar;                 //     display areas
  299.         PIX yCharPels;                  // maxbaselineextent of font
  300.         PIX yDescPels;                  // descender below baseline
  301.         PIX hScroll;                    // current horiz scroll, in pixels
  302.         USHORT iHSlider, iVSlider;      // horiz & vert slider positions
  303.         IPT iptFVL;                     // ipt just before first vis line
  304.         PMR pmrFVL;                     // marker for beginning of display
  305.         HRGN hrgnT;                     // scratch region associated with hps
  306.         LONG FAR *pcwt;                 // pointer to character width table
  307.         PIX TabSize;                    // tab size, in ave char widths
  308.         PFATTRS pfattrs;                // current font attributes
  309.         BOOL fFattrDelta;               // fattrs changed since last redraw
  310.         BOOL fSelDelta;                 // selection changed since last redraw
  311.         BOOL fExistsCursor;             // TRUE => window has a cursor
  312.         BOOL fInvert;                   // TRUE => ps is in inverted color
  313.  
  314.         // Mouse Manager Fields
  315.         BOOL fMouseDown;                // set => button 1 held down
  316.         BOOL fMouseScroll;              // set => mouse scroll timer on
  317.  
  318.         // Keyboard Handler Fields
  319.         BOOL fTyping;                   // set => user can type into window
  320.  
  321.         // Buffer Manager Fields
  322.         PCHAR pchBlockBuf;              // buffer for block transfers
  323.         USHORT usBufLength;             // length of buffer
  324.         USHORT usBlockType;             // import/export format
  325.  
  326. } ED;
  327. typedef ED FAR *PED;
  328.