gdi32: Avoid creating a family object just to retrieve the font data.
[wine] / dlls / riched20 / editstr.h
1 /*
2  * RichEdit - structures and constant
3  *
4  * Copyright 2004 by Krzysztof Foltman
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef __EDITSTR_H
22 #define __EDITSTR_H
23
24 #ifndef _WIN32_IE
25 #define _WIN32_IE 0x0400
26 #endif
27
28 #include <assert.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <limits.h>
33
34 #define COBJMACROS
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
37
38 #include <windef.h>
39 #include <winbase.h>
40 #include <winnls.h>
41 #include <winnt.h>
42 #include <wingdi.h>
43 #include <winuser.h>
44 #include <richedit.h>
45 #include <commctrl.h>
46 #include <ole2.h>
47 #include <richole.h>
48 #include "imm.h"
49 #include <textserv.h>
50
51 #include "wine/debug.h"
52
53 #ifdef __i386__
54 extern const struct ITextHostVtbl itextHostStdcallVtbl;
55 #endif /* __i386__ */
56
57 typedef struct tagME_String
58 {
59   WCHAR *szData;
60   int nLen, nBuffer;
61 } ME_String;
62
63 typedef struct tagME_Style
64 {
65   CHARFORMAT2W fmt;
66
67   HFONT hFont; /* cached font for the style */
68   TEXTMETRICW tm; /* cached font metrics for the style */
69   int nRefs; /* reference count */
70 } ME_Style;
71
72 typedef enum {
73   diInvalid,
74   diTextStart, /* start of the text buffer */
75   diParagraph, /* paragraph start */
76   diCell, /* cell start */
77   diRun, /* run (sequence of chars with the same character format) */
78   diStartRow, /* start of the row (line of text on the screen) */
79   diTextEnd, /* end of the text buffer */
80   
81   /********************* these below are meant for finding only *********************/
82   diStartRowOrParagraph, /* 7 */
83   diStartRowOrParagraphOrEnd,
84   diRunOrParagraph,
85   diRunOrStartRow,
86   diParagraphOrEnd,
87   diRunOrParagraphOrEnd, /* 12 */
88   
89   diUndoInsertRun, /* 13 */
90   diUndoDeleteRun, /* 14 */
91   diUndoJoinParagraphs, /* 15 */
92   diUndoSplitParagraph, /* 16 */
93   diUndoSetParagraphFormat, /* 17 */
94   diUndoSetCharFormat, /* 18 */
95   diUndoEndTransaction, /* 19 - marks the end of a group of changes for undo */
96   diUndoPotentialEndTransaction, /* 20 - allows grouping typed chars for undo */
97 } ME_DIType;
98
99 #define SELECTIONBAR_WIDTH 8
100
101 /******************************** run flags *************************/
102 #define MERF_STYLEFLAGS 0x0FFF
103 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
104 #define MERF_GRAPHICS   0x001
105 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
106 #define MERF_TAB        0x002
107 /* run is a cell boundary */
108 #define MERF_ENDCELL    0x004 /* v4.1 */
109
110 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
111
112 /* run is splittable (contains white spaces in the middle or end) */
113 #define MERF_SPLITTABLE 0x001000
114 /* run starts with whitespaces */
115 #define MERF_STARTWHITE 0x002000
116 /* run ends with whitespaces */
117 #define MERF_ENDWHITE   0x004000
118 /* run is completely made of whitespaces */
119 #define MERF_WHITESPACE 0x008000
120 /* the "end of paragraph" run, contains 1 character */
121 #define MERF_ENDPARA    0x100000
122 /* forcing the "end of row" run, contains 1 character */
123 #define MERF_ENDROW     0x200000
124 /* run is hidden */
125 #define MERF_HIDDEN     0x400000
126 /* start of a table row has an empty paragraph that should be skipped over. */
127 #define MERF_TABLESTART 0x800000 /* v4.1 */
128
129 /* runs with any of these flags set cannot be joined */
130 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
131 /* runs that don't contain real text */
132 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
133
134 /* those flags are kept when the row is split */
135 #define MERF_SPLITMASK (~(0))
136
137 /******************************** para flags *************************/
138
139 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
140 #define MEPF_REWRAP   0x01
141 /* v4.1 */
142 #define MEPF_CELL     0x04 /* The paragraph is nested in a cell */
143 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
144 #define MEPF_ROWEND   0x10 /* Visible empty paragraph at the end of the row */
145
146 /******************************** structures *************************/
147
148 struct tagME_DisplayItem;
149
150 typedef struct tagME_Run
151 {
152   ME_String *strText;
153   ME_Style *style;
154   int nCharOfs; /* relative to para's offset */
155   int nWidth; /* width of full run, width of leading&trailing ws */
156   int nFlags;
157   int nAscent, nDescent; /* pixels above/below baseline */
158   POINT pt; /* relative to para's position */
159   REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
160 } ME_Run;
161
162 typedef struct tagME_Border
163 {
164   int width;
165   COLORREF colorRef;
166 } ME_Border;
167
168 typedef struct tagME_BorderRect
169 {
170   ME_Border top;
171   ME_Border left;
172   ME_Border bottom;
173   ME_Border right;
174 } ME_BorderRect;
175
176 typedef struct tagME_Paragraph
177 {
178   PARAFORMAT2 *pFmt;
179
180   struct tagME_DisplayItem *pCell; /* v4.1 */
181   ME_BorderRect border;
182
183   int nCharOfs;
184   int nFlags;
185   POINT pt;
186   int nHeight, nWidth;
187   int nRows;
188   struct tagME_DisplayItem *prev_para, *next_para;
189 } ME_Paragraph;
190
191 typedef struct tagME_Cell /* v4.1 */
192 {
193   int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
194   int nRightBoundary;
195   ME_BorderRect border;
196   POINT pt;
197   int nHeight, nWidth;
198   int yTextOffset; /* The text offset is caused by the largest top border. */
199   struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
200 } ME_Cell;
201
202 typedef struct tagME_Row
203 {
204   int nHeight;
205   int nBaseline;
206   int nWidth;
207   int nLMargin;
208   int nRMargin;
209   POINT pt;
210 } ME_Row;
211
212 /* the display item list layout is like this:
213  * - the document consists of paragraphs
214  * - each paragraph contains at least one run, the last run in the paragraph
215  *   is an end-of-paragraph run
216  * - each formatted paragraph contains at least one row, which corresponds
217  *   to a screen line (that's why there are no rows in an unformatted
218  *   paragraph
219  * - the paragraphs contain "shortcut" pointers to the previous and the next
220  *   paragraph, that makes iteration over paragraphs faster 
221  * - the list starts with diTextStart and ends with diTextEnd
222  */
223
224 typedef struct tagME_DisplayItem
225 {
226   ME_DIType type;
227   struct tagME_DisplayItem *prev, *next;
228   union {
229     ME_Run run;
230     ME_Row row;
231     ME_Cell cell;
232     ME_Paragraph para;
233     ME_Style *ustyle; /* used by diUndoSetCharFormat */
234   } member;
235 } ME_DisplayItem;
236
237 typedef struct tagME_UndoItem
238 {
239   ME_DisplayItem di;
240   int nStart, nLen;
241   ME_String *eol_str; /* used by diUndoSplitParagraph */
242 } ME_UndoItem;
243
244 typedef struct tagME_TextBuffer
245 {
246   ME_DisplayItem *pFirst, *pLast;
247   ME_Style *pCharStyle;
248   ME_Style *pDefaultStyle;
249 } ME_TextBuffer;
250
251 typedef struct tagME_Cursor
252 {
253   ME_DisplayItem *pPara;
254   ME_DisplayItem *pRun;
255   int nOffset;
256 } ME_Cursor;
257
258 typedef enum {
259   umAddToUndo,
260   umAddToRedo,
261   umIgnore,
262   umAddBackToUndo
263 } ME_UndoMode;
264
265 typedef enum {
266   stPosition = 0,
267   stWord,
268   stLine,
269   stParagraph,
270   stDocument
271 } ME_SelectionType;
272
273 typedef struct tagME_FontTableItem {
274   BYTE bCharSet;
275   WCHAR *szFaceName;
276 } ME_FontTableItem;
277
278
279 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
280
281 struct tagME_InStream {
282   EDITSTREAM *editstream;
283   DWORD dwSize;
284   DWORD dwUsed;
285   char buffer[STREAMIN_BUFFER_SIZE];
286 };
287 typedef struct tagME_InStream ME_InStream;
288
289
290 #define STREAMOUT_BUFFER_SIZE 4096
291 #define STREAMOUT_FONTTBL_SIZE 8192
292 #define STREAMOUT_COLORTBL_SIZE 1024
293
294 typedef struct tagME_OutStream {
295   EDITSTREAM *stream;
296   char buffer[STREAMOUT_BUFFER_SIZE];
297   UINT pos, written;
298   UINT nCodePage;
299   UINT nFontTblLen;
300   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
301   UINT nColorTblLen;
302   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
303   UINT nDefaultFont;
304   UINT nDefaultCodePage;
305   /* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
306    * an greater numbers mean we are in a cell nested within a cell. */
307   UINT nNestingLevel;
308 } ME_OutStream;
309
310 typedef struct tagME_FontCacheItem
311 {
312   LOGFONTW lfSpecs;
313   HFONT hFont;
314   int nRefs;
315   int nAge;
316 } ME_FontCacheItem;
317
318 #define HFONT_CACHE_SIZE 10
319
320 typedef struct tagME_TextEditor
321 {
322   HWND hWnd, hwndParent;
323   ITextHost *texthost;
324   BOOL bEmulateVersion10;
325   ME_TextBuffer *pBuffer;
326   ME_Cursor *pCursors;
327   DWORD styleFlags;
328   DWORD exStyleFlags;
329   int nCursors;
330   SIZE sizeWindow;
331   int nTotalLength, nLastTotalLength;
332   int nTotalWidth, nLastTotalWidth;
333   int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
334   int nUDArrowX;
335   COLORREF rgbBackColor;
336   HBRUSH hbrBackground;
337   BOOL bCaretAtEnd;
338   int nEventMask;
339   int nModifyStep;
340   ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
341   int nUndoStackSize;
342   int nUndoLimit;
343   ME_UndoMode nUndoMode;
344   int nParagraphs;
345   int nLastSelStart, nLastSelEnd;
346   ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
347   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
348   int nZoomNumerator, nZoomDenominator;
349   RECT prevClientRect;
350   RECT rcFormat;
351   BOOL bDefaultFormatRect;
352   BOOL bWordWrap;
353   int nTextLimit;
354   EDITWORDBREAKPROCW pfnWordBreak;
355   LPRICHEDITOLECALLBACK lpOleCallback;
356   /*TEXTMODE variable; contains only one of each of the following options:
357    *TM_RICHTEXT or TM_PLAINTEXT
358    *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
359    *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
360   int mode;
361   BOOL bHideSelection;
362   BOOL AutoURLDetect_bEnable;
363   WCHAR cPasswordMask;
364   BOOL bHaveFocus;
365   BOOL bDialogMode; /* Indicates that we are inside a dialog window */
366   /*for IME */
367   int imeStartIndex;
368   DWORD selofs; /* The size of the selection bar on the left side of control */
369   ME_SelectionType nSelectionType;
370
371   /* Track previous notified selection */
372   CHARRANGE notified_cr;
373
374   /* Cache previously set scrollbar info */
375   SCROLLINFO vert_si, horz_si;
376
377   BOOL bMouseCaptured;
378 } ME_TextEditor;
379
380 typedef struct tagME_Context
381 {
382   HDC hDC;
383   POINT pt;
384   RECT rcView;
385   SIZE dpi;
386   int nAvailWidth;
387
388   /* those are valid inside ME_WrapTextParagraph and related */
389   ME_TextEditor *editor;
390 } ME_Context;
391
392 typedef struct tagME_WrapContext
393 {
394   ME_Style *style;
395   ME_Context *context;
396   int nLeftMargin, nRightMargin, nFirstMargin;
397   int nAvailWidth;
398   int nRow;
399   POINT pt;
400   BOOL bOverflown, bWordWrap;
401   ME_DisplayItem *pPara;
402   ME_DisplayItem *pRowStart;
403
404   ME_DisplayItem *pLastSplittableRun;
405 } ME_WrapContext;
406
407 #endif