Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

421 lines
16 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _CFPF.H -- RichEdit CCharFormat and CParaFormat Classes |
  5. *
  6. * These classes are derived from the RichEdit 1.0 CHARFORMAT and PARAFORMAT
  7. * structures and are the RichEdit 2.0 internal versions of these structures.
  8. * Member functions (like Copy()) that use external (API) CHARFORMATs and
  9. * PARAFORMATs need to check the <p cbSize> value to see what members are
  10. * defined. Default values that yield RichEdit 1.0 behavior should be stored
  11. * for RichEdit 1.0 format structures, e.g., so that the renderer doesn't do
  12. * anomalous things with random RichEdit 2.0 format values. Generally the
  13. * appropriate default value is 0.
  14. *
  15. * All character and paragraph format measurements are in twips. Undefined
  16. * mask and effect bits are reserved and must be 0 to be compatible with
  17. * future versions.
  18. *
  19. * Effects that appear with an asterisk (*) are stored, but won't be
  20. * displayed by RichEdit 2.0. They are place holders for TOM and/or Word
  21. * compatibility.
  22. *
  23. * Note: these structures are much bigger than they need to be for internal
  24. * use especially if we use SHORTs instead of LONGs for dimensions and
  25. * the tab and font info are accessed via ptrs. Nevertheless, in view of our
  26. * tight delivery schedule, RichEdit 2.0 uses the classes below.
  27. *
  28. * History:
  29. * 9/1995 -- MurrayS: Created
  30. * 11/1995 -- MurrayS: Extended to full Word97 FormatFont/Format/Para
  31. *
  32. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  33. */
  34. #ifndef _CFPF_H
  35. #define _CFPF_H
  36. #define TABS
  37. SHORT Get16BitTwips(LONG dy);
  38. LONG GetUsableFontHeight(LONG ySrcHeight, LONG lPointChange);
  39. BOOL IsValidCharFormatW(const CHARFORMATW * pCF);
  40. BOOL IsValidCharFormatA(const CHARFORMATA * pCFA);
  41. BOOL IsValidParaFormat (const PARAFORMAT * pPF);
  42. // CParaFormat Style enums and defines (maybe move to richedit.h?)
  43. enum STYLES
  44. {
  45. STYLE_NORMAL = -1,
  46. STYLE_HEADING_1 = -2,
  47. STYLE_HEADING_9 = -10
  48. };
  49. #define NHSTYLES 9 // # of heading styles
  50. #define STYLE_COMMAND 0x8000
  51. #define TWIPS_PER_POINT 20
  52. #define IsHeadingStyle(Style) (Style <= STYLE_HEADING_1 && \
  53. Style >= STYLE_HEADING_9)
  54. #define IsKnownStyle(Style) (IsHeadingStyle(Style) || Style == STYLE_NORMAL)
  55. #define IsStyleCommand(Style) ((Style & 0xFF00) == STYLE_COMMAND)
  56. #define CCHMAXNUMTOSTR 20 // Enuf for billions + parens + null term
  57. typedef struct _styleformat
  58. {
  59. BYTE bEffects;
  60. BYTE bHeight;
  61. } STYLEFORMAT;
  62. /*
  63. * Tab Structure Template
  64. *
  65. * To help keep the size of the tab array small, we use the two high nibbles
  66. * of the tab LONG entries in rgxTabs[] to give the tab type and tab leader
  67. * (style) values. The measurer and renderer need to ignore (or implement)
  68. * these nibbles. We also need to be sure that the compiler does something
  69. * rational with this idea...
  70. */
  71. typedef struct tagTab
  72. {
  73. DWORD tbPos : 24; // 24-bit unsigned tab displacement
  74. DWORD tbAlign : 4; // 4-bit tab type (see enum PFTABTYPE)
  75. DWORD tbLeader : 4; // 4-bit tab style (see enum PFTABSTYLE)
  76. } TABTEMPLATE;
  77. enum PFTABTYPE // Same as tomAlignLeft, tomAlignCenter,
  78. { // tomAlignRight, tomAlignDecimal, tomAlignBar
  79. PFT_LEFT = 0, // ordinary tab
  80. PFT_CENTER, // center tab
  81. PFT_RIGHT, // right-justified tab
  82. PFT_DECIMAL, // decimal tab
  83. PFT_BAR // Word bar tab (vertical bar)
  84. };
  85. enum PFTABSTYLE // Same as tomSpaces, tomDots, tomDashes,
  86. { // tomLines
  87. PFTL_NONE = 0, // no leader
  88. PFTL_DOTS, // dotted
  89. PFTL_DASH, // dashed
  90. PFTL_UNDERLINE, // underlined
  91. PFTL_THICK, // thick line
  92. PFTL_EQUAL // double line
  93. };
  94. #define PFT_DEFAULT 0xff000000
  95. typedef struct _cellparms
  96. {
  97. LONG uCell; // Low 24 bits; high byte has flags
  98. DWORD dxBrdrWidths; // Widths of borders (left, top, right, bottom)
  99. DWORD dwColors; // Borders and background color
  100. BYTE bShading; // Shading in .5 per cent
  101. // Border widths and colors are packed in same low-to-high order as in
  102. // RECT, that is, left, top, right, bottom.
  103. LONG GetBrdrWidthLeft() const {return (dxBrdrWidths >> 0*8) & 0xFF;}
  104. LONG GetBrdrWidthTop() const {return (dxBrdrWidths >> 1*8) & 0xFF;}
  105. LONG GetBrdrWidthRight() const {return (dxBrdrWidths >> 2*8) & 0xFF;}
  106. LONG GetBrdrWidthBottom() const {return (dxBrdrWidths >> 3*8) & 0xFF;}
  107. void SetBrdrWidthBottom(BYTE bBrdrWidth)
  108. {dxBrdrWidths = (dxBrdrWidths & 0x00FFFFFF) | (bBrdrWidth << 24);}
  109. LONG GetColorIndexLeft() const {return (dwColors >> 0*5) & 0x1F;}
  110. LONG GetColorIndexTop() const {return (dwColors >> 1*5) & 0x1F;}
  111. LONG GetColorIndexRight() const {return (dwColors >> 2*5) & 0x1F;}
  112. LONG GetColorIndexBottom() const {return (dwColors >> 3*5) & 0x1F;}
  113. LONG GetColorIndexBackgound() const {return (dwColors >> 4*5) & 0x1F;}
  114. LONG GetColorIndexForegound() const {return (dwColors >> 5*5) & 0x1F;}
  115. LONG ICellFromUCell(LONG dul, LONG cCell) const;
  116. } CELLPARMS;
  117. // Effect flags beyond CHARFORMAT2. Go in high word of CCharFormat::_dwEffects
  118. // which aren't used in CHARFORMAT2 (except for CFE_AUTOCOLOR: 0x40000000,
  119. // CFE_AUTOBACKCOLOR: 0x04000000, CFE_SUBSCRIPT: 0x00010000, and
  120. // CFE_SUPERSCRIPT: 0x00020000), since they overlap with noneffect parms.
  121. // Use corresponding high-word bits in dwMask2 to access. Be careful not
  122. // to define new effects that conflict with CFE_AUTOCOLOR, CFE_AUTOBACKCOLOR,
  123. // CFE_SUBSCRIPT, or CFE_SUPERSCRIPT.
  124. // CFE_SUBSCRIPT 0x00010000 // Defined in richedit.h
  125. // CFE_SUPERSCRIPT 0x00020000 // Defined in richedit.h
  126. #define CFM2_RUNISDBCS 0x00040000 // Says run is DBCS put
  127. #define CFE_RUNISDBCS CFM2_RUNISDBCS // into Unicode buffer
  128. #define CFM2_FACENAMEISDBCS 0x00080000 // Says szFaceName is DBCS
  129. #define CFE_FACENAMEISDBCS CFM2_FACENAMEISDBCS // put into Unicode buffer
  130. #define CFE_AVAILABLE 0x00100000 // Use me!!!
  131. #define CFM2_DELETED 0x00200000 // Says text was deleted
  132. #define CFE_DELETED CFM2_DELETED // (roundtrips \deleted)
  133. #define CFM2_CUSTOMTEXTOUT 0x00400000 // Font has custom textout
  134. #define CFE_CUSTOMTEXTOUT CFM2_CUSTOMTEXTOUT // handling
  135. #define CFM2_LINKPROTECTED 0x00800000 // Word hyperlink field
  136. #define CFE_LINKPROTECTED CFM2_LINKPROTECTED // Don't let urlsup.cpp touch!
  137. // CFE_AUTOBACKCOLOR 0x04000000 // Defined in richedit.h
  138. // CFE_AUTOCOLOR 0x40000000 // Defined in richedit.h
  139. #define CFM2_CHARFORMAT 0x00008000 // Noneffect mask flags
  140. #define CFM2_USABLEFONT 0x00004000 // EM_SETFONTSIZE functionality
  141. #define CFM2_SCRIPT 0x00002000 // Uniscribe's script ID
  142. #define CFM2_NOCHARSETCHECK 0x00001000 // Suppress CharSet check
  143. #define CFM2_HOLDITEMIZE 0x00000800 // Hold off Itemization
  144. #define CFM2_ADJUSTFONTSIZE 0x00000400 // Font size adjustment (SAMECHARSET case only)
  145. #define CFM2_UIFONT 0x00000200 // UI Font (SAMECHARSET case only)
  146. #define CFM2_MATCHFONT 0x00000100 // Match font to charset
  147. #define CFM2_USETMPDISPATTR 0x00000080 // Use Temp display attribute
  148. /*
  149. * CCharFormat
  150. *
  151. * @class
  152. * Collects character format methods along with data members
  153. * corresponding to CHARFORMAT2. Only 10 DWORDs are used, whereas
  154. * CHARFORMAT2 has 30. Some bits in the high word of _dwEffects
  155. * are used for additional effects, since only CFE_AUTOCOLOR,
  156. * CFE_AUTOBACKCOLOR, CFE_SUBSCRIPT, and CFE_SUPERSCRIPT are used
  157. * by CHARFORMAT2 (the associated mask bits for the others are used
  158. * for noneffect parameters, such as yHeight).
  159. *
  160. * @devnote
  161. * Could add extra data for round tripping more RTF info. This data
  162. * wouldn't be exposed at the API level (other than via RTF).
  163. * The order below is optimized for transfer to CHARFORMAT and for
  164. * early out on font lookup, i.e., the most common 2 DWORDs are the
  165. * first 2.
  166. */
  167. class CCharFormat
  168. {
  169. public:
  170. #ifdef DEBUG
  171. const WCHAR *_pchFaceName; // Facename given by _iFont
  172. #endif
  173. DWORD _dwEffects; // CFE_xxx effects
  174. BYTE _iCharRep; // Character Repertoire
  175. BYTE _bPitchAndFamily; // Pitch and Family
  176. SHORT _iFont; // Index into FONTNAME table
  177. SHORT _yHeight; // Font height
  178. SHORT _yOffset; // Vertical offset from baseline
  179. COLORREF _crTextColor; // Foreground color
  180. WORD _wWeight; // Font weight (LOGFONT value)
  181. SHORT _sSpacing; // Amount to space between letters
  182. COLORREF _crBackColor; // Background color
  183. LCID _lcid; // Locale ID
  184. SHORT _sStyle; // Style handle
  185. WORD _wKerning; // Twip size above which to kern char pair
  186. BYTE _bUnderlineType; // Underline type
  187. BYTE _bAnimation; // Animated text like marching ants
  188. BYTE _bRevAuthor; // Revision author index
  189. BYTE _bUnderlineColor; // Used only by IME/UIM
  190. WORD _wScript; // Uniscribe's script ID
  191. BYTE _iCharRepSave; // Previous char repertoire for SYMBOL_CHARSET
  192. BYTE _bQuality; // Font quality (ClearType or whatever)
  193. SHORT _sTmpDisplayAttrIdx; // Index to the temp. display attrib array
  194. CCharFormat() { _sTmpDisplayAttrIdx = -1; }
  195. //@cmember Apply *<p pCF>
  196. HRESULT Apply (const CCharFormat *pCF, // to this CCharFormat
  197. DWORD dwMask, DWORD dwMask2);
  198. void ApplyDefaultStyle (LONG Style);
  199. BOOL CanKern() const {return _wKerning && _yHeight >= _wKerning;}
  200. BOOL CanKernWith(const CCharFormat *pCF) const;
  201. BOOL Compare (const CCharFormat *pCF) const; //@cmember Compare this CF
  202. // to *<p pCF>
  203. DWORD Delta (CCharFormat *pCF, //@cmember Get difference
  204. BOOL fCHARFORMAT) const; // mask between this and
  205. // *<p pCF>
  206. BOOL fSetStyle(DWORD dwMask, DWORD dwMask2) const;
  207. void Get (CHARFORMAT2 *pCF, UINT CodePage) const;//@cmember Copies this to
  208. // CHARFORMAT pCF
  209. HRESULT InitDefault (HFONT hfont); //@cmember Initialize using
  210. // font info from <p hfont>
  211. void Set(const CHARFORMAT2 *pCF, UINT CodePage);//@cmember Copy *<p pCF>
  212. // to this CF
  213. };
  214. // dwMask2 bits
  215. #define PFM2_PARAFORMAT 0x80000000 // Only PARAFORMAT parms used
  216. #define PFM2_ALLOWTRDCHANGE 0x40000000 // Allow TRD changes
  217. #define PFM2_TABLEROWSHIFTED 0x00008000 // Allow only TRD changes
  218. #define PFE_TABLEROWSHIFTED PFM2_TABLEROWSHIFTED
  219. /*
  220. * CParaFormat
  221. *
  222. * @class
  223. * Collects related paragraph formatting methods and data
  224. *
  225. * @devnote
  226. * Could add extra data for round tripping more RTF and TOM info
  227. */
  228. class CParaFormat
  229. {
  230. public:
  231. WORD _wNumbering;
  232. WORD _wEffects;
  233. LONG _dxStartIndent;
  234. LONG _dxRightIndent;
  235. LONG _dxOffset;
  236. BYTE _bAlignment;
  237. BYTE _bTabCount;
  238. SHORT _iTabs; // Tabs index in CTabs cache
  239. LONG _dySpaceBefore; // Vertical spacing before para
  240. LONG _dySpaceAfter; // Vertical spacing after para
  241. LONG _dyLineSpacing; // Line spacing depending on Rule
  242. SHORT _sStyle; // Style handle
  243. BYTE _bLineSpacingRule; // Rule for line spacing (see tom.doc)
  244. BYTE _bOutlineLevel; // Outline Level
  245. union
  246. {
  247. struct
  248. {
  249. WORD _wShadingWeight; // Shading in hundredths of a per cent
  250. WORD _wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat
  251. WORD _wNumberingStart; // Starting value for numbering
  252. WORD _wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc.
  253. };
  254. struct
  255. {
  256. COLORREF _crCustom1; // In table-row delimiters, this area has
  257. COLORREF _crCustom2; // custom colors instead of shading and
  258. }; // numbering
  259. };
  260. WORD _wNumberingTab; // Space bet 1st indent and 1st-line text
  261. WORD _wBorderSpace; // Border-text spaces (nbl/bdr in pts)
  262. WORD _wBorderWidth; // Pen widths (nbl/bdr in half twips)
  263. WORD _wBorders; // Border styles (nibble/border)
  264. DWORD _dwBorderColor; // Colors/attribs
  265. char _bTableLevel; // Table nesting level
  266. CParaFormat() {}
  267. //@cmember Add tab at
  268. HRESULT AddTab (LONG tabPos, LONG tabType, // position <p tabPos>
  269. LONG tabStyle, LONG *prgxTabs);
  270. //@cmember Apply *<p pPF> to
  271. HRESULT Apply(const CParaFormat *pPF, DWORD dwMask, DWORD dwMask2);// this PF
  272. void ApplyDefaultStyle (LONG Style);
  273. HRESULT DeleteTab(LONG tabPos, LONG *prgxTabs); //@cmember Delete tab at
  274. // <p tabPos>
  275. DWORD Delta (CParaFormat *pPF, //@cmember Set difference
  276. BOOL fPARAFORMAT) const; // mask between this and
  277. // *<p pPF>
  278. BOOL fSetStyle(DWORD dwMask, DWORD dwMask2) const;
  279. void Get (PARAFORMAT2 *pPF2) const; //@cmember Copy this PF to
  280. // *<p pPF>
  281. char GetOutlineLevel(){return _bOutlineLevel;}
  282. LONG GetRTLRowLength() const; //@cmember Get RTL row length
  283. //@cmember Get tab position
  284. HRESULT GetTab (long iTab, long *pdxptab, // type, and style
  285. long *ptbt, long *pstyle,
  286. const LONG *prgxTabs) const;
  287. const LONG *GetTabs () const; //@cmember Get ptr to tab array
  288. const CELLPARMS *GetCellParms () const //@cmember Get ptr to cell array
  289. {return (const CELLPARMS *)GetTabs();}
  290. BOOL HandleStyle(LONG Mode); //@cmember Handle sStyle
  291. //@cmember Initialize this
  292. HRESULT InitDefault (WORD wDefEffects); // PF to default values
  293. BOOL IsRtlPara() const
  294. {return (_wEffects & (PFE_RTLPARA | PFE_TABLEROWDELIMITER)) == PFE_RTLPARA;}
  295. BOOL IsRtl() const {return _wEffects & PFE_RTLPARA;}
  296. BOOL InTable() const {return (_wEffects & PFE_TABLE) != 0;}
  297. BOOL IsTableRowDelimiter() const {return (_wEffects & PFE_TABLEROWDELIMITER) != 0;}
  298. BOOL IsListNumbered() const {return IN_RANGE(tomListNumberAsArabic,
  299. _wNumbering,
  300. tomListNumberAsSequence);}
  301. BOOL IsNumberSuppressed() const
  302. {return (_wNumberingStyle & 0xF00) == PFNS_NONUMBER;}
  303. LONG NumToStr(TCHAR *pch, LONG n, DWORD grf = 0) const;
  304. //@cmember Copy *<p pPF>
  305. void Set (const PARAFORMAT2 *pPF2); // to this PF
  306. LONG UpdateNumber (LONG n, const CParaFormat *pPF) const;
  307. #ifdef DEBUG
  308. void ValidateTabs();
  309. #endif // DEBUG
  310. };
  311. #define fRtfWrite 0x1
  312. #define fIndicDigits 0x2
  313. #define GetTabPos(tab) ((tab) & 0xFFFFFF)
  314. #define GetTabAlign(tab) (((tab) >> 24) & 0xF)
  315. #define GetTabLdr(tab) ((tab) >> 28)
  316. #define fTopCell 0x04000000
  317. #define fLowCell 0x08000000
  318. #define fVerticalCell 0x10000000
  319. #define GetCellWidth(x) ((x) & 0xFFFFFF)
  320. #define IsTopCell(x) (((x) & fTopCell) != 0)
  321. #define IsLowCell(x) ((x) & fLowCell)
  322. #define IsVertMergedCell(x) ((x) & (fTopCell | fLowCell))
  323. #define IsVerticalCell(x) ((x) & fVerticalCell)
  324. #define GetCellVertAlign(x) ((x) & 0x03000000)
  325. #define IsCellVertAlignCenter(x) ((x) & 0x01000000)
  326. #define CELL_EXTRA (sizeof(CELLPARMS)/sizeof(LONG) - 1)
  327. /*
  328. * CTabs
  329. *
  330. * @class
  331. * CFixArray element for tab and cell arrays
  332. */
  333. class CTabs
  334. {
  335. public:
  336. LONG _cTab; // Count of tabs (or total LONGs in cells)
  337. LONG *_prgxTabs; // Ptr to tab array
  338. };
  339. #endif
  340. /* Table Storage Layout:
  341. *
  342. * Tables are stored using paragraphs with special characteristics.
  343. * Each table row starts with a two-character paragraph consisting of
  344. * a STARTFIELD character followed by a CR. The associated CParaFormat
  345. * has the PFE_TABLEROWDELIMITER bit of _wEffects set to 1. The CParaFormat
  346. * properties identify the row properties: alignment, StartIndent, line
  347. * spacing, line spacing rule, PFE_KEEP and PFE_RTLPARA bits, and border
  348. * info, which all work the same way for the row that they work for an
  349. * ordinary paragraph. The offset field gives the half-gap space between
  350. * cells in the row. The CTabArray for the paragraph gives the cell widths
  351. * and other info, such as vertical cell merge.
  352. *
  353. * Cells in the row are delimited by CELL, which can have a CParaFormat like
  354. * a CR, so that properties like alignment can be attached to a cell without
  355. * having an explicit CR. CRs are allowed in cells and the text may wrap
  356. * in the cell.
  357. *
  358. * The table row ends with a two-character paragraph consisting of
  359. * a ENDFIELD character followed by a CR. The associated CParaFormat is
  360. * the same as the corresponding table row start paragraph.
  361. *
  362. * Tables can be nested. The _bTableLevel gives the nesting level: 1 for
  363. * the outermost table, 2 for the next to outermost table, etc.
  364. */
  365. BOOL IsValidTwip(LONG dl);