Source code of Windows XP (NT5)
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.

329 lines
12 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-1997, 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 13 // Enuf for 4 billion + 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. // Effect flags beyond CHARFORMAT2. Go in high word of CCharFormat::_dwEffects
  96. // which aren't used in CHARFORMAT2 (except for CFE_AUTOCOLOR: 0x40000000,
  97. // CFE_AUTOBACKCOLOR: 0x04000000, CFE_SUBSCRIPT: 0x00010000, and
  98. // CFE_SUPERSCRIPT: 0x00020000), since they overlap with noneffect parms.
  99. // Use corresponding high-word bits in dwMask2 to access. Be careful not
  100. // to define new effects that conflict with CFE_AUTOCOLOR, CFE_AUTOBACKCOLOR,
  101. // CFE_SUBSCRIPT, or CFE_SUPERSCRIPT.
  102. // CFE_SUBSCRIPT 0x00010000 // Defined in richedit.h
  103. // CFE_SUPERSCRIPT 0x00020000 // Defined in richedit.h
  104. #define CFM2_RUNISDBCS 0x00040000 // Says run is DBCS put
  105. #define CFE_RUNISDBCS CFM2_RUNISDBCS // into Unicode buffer
  106. #define CFM2_FACENAMEISDBCS 0x00080000 // Says szFaceName is DBCS
  107. #define CFE_FACENAMEISDBCS CFM2_FACENAMEISDBCS // put into Unicode buffer
  108. #define CFM2_TRUETYPEONLY 0x00100000 // Says that font matching
  109. #define CFE_TRUETYPEONLY CFM2_TRUETYPEONLY // CF should be TrueType
  110. #define CFM2_DELETED 0x00200000 // Says text was deleted
  111. #define CFE_DELETED CFM2_DELETED // (roundtrips \deleted)
  112. // CFE_AUTOBACKCOLOR 0x04000000 // Defined in richedit.h
  113. // CFE_AUTOCOLOR 0x40000000 // Defined in richedit.h
  114. #define CFM2_CHARFORMAT 0x00008000 // Noneffect mask flags
  115. #define CFM2_USABLEFONT 0x00004000 // EM_SETFONTSIZE functionality
  116. #define CFM2_SCRIPT 0x00002000 // Uniscribe's script ID
  117. #define CFM2_NOCHARSETCHECK 0x00001000 // Suppress CharSet check
  118. #define CFM2_HOLDITEMIZE 0x00000800 // Hold off Itemization
  119. #define CFM2_ADJUSTFONTSIZE 0x00000400 // Font size adjustment (SAMECHARSET case only)
  120. #define CFM2_UIFONT 0x00000200 // UI Font (SAMECHARSET case only)
  121. #define CFM2_MATCHFONT 0x00000100 // Match font to charset
  122. /*
  123. * CCharFormat
  124. *
  125. * @class
  126. * Collects character format methods along with data members
  127. * corresponding to CHARFORMAT2. Only 10 DWORDs are used, whereas
  128. * CHARFORMAT2 has 30. Some bits in the high word of _dwEffects
  129. * are used for additional effects, since only CFE_AUTOCOLOR,
  130. * CFE_AUTOBACKCOLOR, CFE_SUBSCRIPT, and CFE_SUPERSCRIPT are used
  131. * by CHARFORMAT2 (the associated mask bits for the others are used
  132. * for noneffect parameters, such as yHeight).
  133. *
  134. * @devnote
  135. * Could add extra data for round tripping more RTF info. This data
  136. * wouldn't be exposed at the API level (other than via RTF).
  137. * The order below is optimized for transfer to CHARFORMAT and for
  138. * early out on font lookup, i.e., the most common 2 DWORDs are the
  139. * first 2.
  140. */
  141. class CCharFormat
  142. {
  143. public:
  144. DWORD _dwEffects; // CFE_xxx effects
  145. BYTE _bCharSet; // CharSet
  146. BYTE _bPitchAndFamily; // Pitch and Family
  147. SHORT _iFont; // Index into FONTNAME table
  148. SHORT _yHeight; // Font height
  149. SHORT _yOffset; // Vertical offset from baseline
  150. COLORREF _crTextColor; // Foreground color
  151. WORD _wWeight; // Font weight (LOGFONT value)
  152. SHORT _sSpacing; // Amount to space between letters
  153. COLORREF _crBackColor; // Background color
  154. LCID _lcid; // Locale ID
  155. SHORT _sStyle; // Style handle
  156. WORD _wKerning; // Twip size above which to kern char pair
  157. BYTE _bUnderlineType; // Underline type
  158. BYTE _bAnimation; // Animated text like marching ants
  159. BYTE _bRevAuthor; // Revision author index
  160. BYTE _bReserved; // Need to 0 this before storing in array
  161. WORD _wScript; // Uniscribe's script ID
  162. WORD _wCodePageSave; // Previous codepage for SYMBOL_CHARSET
  163. CCharFormat() {}
  164. //@cmember Apply *<p pCF>
  165. HRESULT Apply (const CCharFormat *pCF, // to this CCharFormat
  166. DWORD dwMask, DWORD dwMask2);
  167. void ApplyDefaultStyle (LONG Style);
  168. BOOL Compare (const CCharFormat *pCF) const; //@cmember Compare this CF
  169. // to *<p pCF>
  170. DWORD Delta (CCharFormat *pCF, //@cmember Get difference
  171. BOOL fCHARFORMAT) const; // mask between this and
  172. // *<p pCF>
  173. BOOL fSetStyle(DWORD dwMask, DWORD dwMask2) const;
  174. void Get (CHARFORMAT2 *pCF, UINT CodePage) const;//@cmember Copies this to
  175. // CHARFORMAT pCF
  176. HRESULT InitDefault (HFONT hfont); //@cmember Initialize using
  177. // font info from <p hfont>
  178. void Set(const CHARFORMAT2 *pCF, UINT CodePage);//@cmember Copy *<p pCF>
  179. // to this CF
  180. };
  181. // NB: don't define the following bit some other way in richedit.h unless you
  182. // implement some other way to say that only PARAFORMAT parms are specified
  183. #define PFM_PARAFORMAT 0x20000000 // Only PARAFORMAT parms used
  184. /*
  185. * CParaFormat
  186. *
  187. * @class
  188. * Collects related paragraph formatting methods and data
  189. *
  190. * @devnote
  191. * Could add extra data for round tripping more RTF and TOM info
  192. */
  193. class CParaFormat
  194. {
  195. public:
  196. WORD _wNumbering;
  197. WORD _wEffects;
  198. LONG _dxStartIndent;
  199. LONG _dxRightIndent;
  200. LONG _dxOffset;
  201. BYTE _bAlignment;
  202. BYTE _bTabCount;
  203. SHORT _iTabs; // Tabs index in CTabs cache
  204. LONG _dySpaceBefore; // Vertical spacing before para
  205. LONG _dySpaceAfter; // Vertical spacing after para
  206. LONG _dyLineSpacing; // Line spacing depending on Rule
  207. SHORT _sStyle; // Style handle
  208. BYTE _bLineSpacingRule; // Rule for line spacing (see tom.doc)
  209. BYTE _bOutlineLevel; // Outline Level
  210. WORD _wShadingWeight; // Shading in hundredths of a per cent
  211. WORD _wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat
  212. WORD _wNumberingStart; // Starting value for numbering
  213. WORD _wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc.
  214. WORD _wNumberingTab; // Space bet 1st indent and 1st-line text
  215. WORD _wBorderSpace; // Border-text spaces (nbl/bdr in pts)
  216. WORD _wBorderWidth; // Pen widths (nbl/bdr in half twips)
  217. WORD _wBorders; // Border styles (nibble/border)
  218. DWORD _dwBorderColor; // Colors/attribs
  219. CParaFormat() {}
  220. //@cmember Add tab at
  221. HRESULT AddTab (LONG tabPos, LONG tabType, // position <p tabPos>
  222. LONG tabStyle, BOOL fInTable,
  223. LONG *prgxTabs);
  224. HRESULT Apply(const CParaFormat *pPF, DWORD dwMask);//@cmember Apply *<p pPF>
  225. // to this CParaFormat
  226. void ApplyDefaultStyle (LONG Style);
  227. HRESULT DeleteTab(LONG tabPos, LONG *prgxTabs); //@cmember Delete tab at
  228. // <p tabPos>
  229. DWORD Delta (CParaFormat *pPF, //@cmember Set difference
  230. BOOL fPARAFORMAT) const; // mask between this and
  231. // *<p pPF>
  232. BOOL fSetStyle(DWORD dwMask) const;
  233. void Get (PARAFORMAT2 *pPF2) const; //@cmember Copy this PF to
  234. // *<p pPF>
  235. char GetOutlineLevel(){return _bOutlineLevel;}
  236. //@cmember Get tab position
  237. HRESULT GetTab (long iTab, long *pdxptab, // type, and style
  238. long *ptbt, long *pstyle,
  239. const LONG *prgxTabs) const;
  240. const LONG *GetTabs () const; //@cmember Get ptr to tab array
  241. BOOL HandleStyle(LONG Mode); //@cmember Handle sStyle
  242. //@cmember Initialize this
  243. HRESULT InitDefault (WORD wDefEffects); // PF to default values
  244. BOOL IsRtlPara() const {return _wEffects & PFE_RTLPARA;}
  245. BOOL InTable() const {return (_wEffects & PFE_TABLE) != 0;}
  246. BOOL IsListNumbered() const {return IN_RANGE(tomListNumberAsArabic,
  247. _wNumbering,
  248. tomListNumberAsSequence);}
  249. BOOL IsNumberSuppressed() const
  250. {return (_wNumberingStyle & 0xF00) == PFNS_NONUMBER;}
  251. LONG NumToStr(TCHAR *pch, LONG n, DWORD grf = 0) const;
  252. //@cmember Copy *<p pPF>
  253. void Set (const PARAFORMAT2 *pPF2); // to this PF
  254. LONG UpdateNumber (LONG n, const CParaFormat *pPF) const;
  255. #ifdef DEBUG
  256. void ValidateTabs();
  257. #endif // DEBUG
  258. };
  259. #define fRtfWrite 0x1
  260. #define fIndicDigits 0x2
  261. #define GetTabPos(tab) ((tab) & 0xffffff)
  262. #define GetTabAlign(tab) (((tab) >> 24) & 0xf)
  263. #define GetTabLdr(tab) ((tab) >> 28)
  264. /*
  265. * CTabs
  266. *
  267. * @class
  268. * CFixArray element for tab and cell arrays
  269. */
  270. class CTabs
  271. {
  272. public:
  273. LONG _cTab; // Count of tabs
  274. LONG *_prgxTabs; // Ptr to tab array
  275. };
  276. #endif
  277. /* FUTURE: Possible Table Storage Layout:
  278. *
  279. * A table could be stored as a sequence of paragraphs with special
  280. * characteristics. Each table row starts with a table-row paragraph whose
  281. * properties identify the row properties: alignment, StartIndent, line
  282. * spacing, line spacing rule, PFE_KEEP and PFE_RTLPARA bits, and border
  283. * info, which all work the same way for the row that they work for an
  284. * ordinary paragraph. The offset field gives the half-gap space between
  285. * cells in the row. A table-row paragraph is identified by the PFM_TABLE
  286. * mask field equal to PFE_ROWSTART.
  287. */
  288. BOOL IsValidTwip(LONG dl);