[RICHED20] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / dll / win32 / 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 #ifdef __i386__
25 extern const struct ITextHostVtbl itextHostStdcallVtbl DECLSPEC_HIDDEN;
26 #endif /* __i386__ */
27
28 typedef struct tagME_String
29 {
30 WCHAR *szData;
31 int nLen, nBuffer;
32 } ME_String;
33
34 typedef struct tagME_FontCacheItem
35 {
36 LOGFONTW lfSpecs;
37 HFONT hFont;
38 int nRefs;
39 int nAge;
40 } ME_FontCacheItem;
41
42 #define HFONT_CACHE_SIZE 10
43
44 typedef struct tagME_Style
45 {
46 CHARFORMAT2W fmt;
47
48 ME_FontCacheItem *font_cache; /* cached font for the style */
49 TEXTMETRICW tm; /* cached font metrics for the style */
50 int nRefs; /* reference count */
51 SCRIPT_CACHE script_cache;
52 struct list entry;
53 } ME_Style;
54
55 typedef enum {
56 diInvalid,
57 diTextStart, /* start of the text buffer */
58 diParagraph, /* paragraph start */
59 diCell, /* cell start */
60 diRun, /* run (sequence of chars with the same character format) */
61 diStartRow, /* start of the row (line of text on the screen) */
62 diTextEnd, /* end of the text buffer */
63
64 /********************* these below are meant for finding only *********************/
65 diStartRowOrParagraph, /* 7 */
66 diStartRowOrParagraphOrEnd,
67 diRunOrParagraph,
68 diRunOrStartRow,
69 diParagraphOrEnd,
70 diRunOrParagraphOrEnd, /* 12 */
71 } ME_DIType;
72
73 #define SELECTIONBAR_WIDTH 8
74
75 /******************************** run flags *************************/
76 #define MERF_STYLEFLAGS 0x0FFF
77 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
78 #define MERF_GRAPHICS 0x001
79 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
80 #define MERF_TAB 0x002
81 /* run is a cell boundary */
82 #define MERF_ENDCELL 0x004 /* v4.1 */
83
84 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
85
86 /* run is splittable (contains white spaces in the middle or end) */
87 #define MERF_SPLITTABLE 0x001000
88 /* run starts with whitespaces */
89 #define MERF_STARTWHITE 0x002000
90 /* run ends with whitespaces */
91 #define MERF_ENDWHITE 0x004000
92 /* run is completely made of whitespaces */
93 #define MERF_WHITESPACE 0x008000
94 /* the "end of paragraph" run, contains 1 character */
95 #define MERF_ENDPARA 0x100000
96 /* forcing the "end of row" run, contains 1 character */
97 #define MERF_ENDROW 0x200000
98 /* run is hidden */
99 #define MERF_HIDDEN 0x400000
100 /* start of a table row has an empty paragraph that should be skipped over. */
101 #define MERF_TABLESTART 0x800000 /* v4.1 */
102
103 /* runs with any of these flags set cannot be joined */
104 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
105 /* runs that don't contain real text */
106 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
107
108 /* those flags are kept when the row is split */
109 #define MERF_SPLITMASK (~(0))
110
111 /******************************** para flags *************************/
112
113 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
114 #define MEPF_REWRAP 0x01
115 /* v4.1 */
116 #define MEPF_CELL 0x04 /* The paragraph is nested in a cell */
117 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
118 #define MEPF_ROWEND 0x10 /* Visible empty paragraph at the end of the row */
119 #define MEPF_COMPLEX 0x20 /* Use uniscribe */
120
121 /******************************** structures *************************/
122
123 struct tagME_DisplayItem;
124
125 typedef struct tagME_Run
126 {
127 ME_Style *style;
128 struct tagME_Paragraph *para; /* ptr to the run's paragraph */
129 int nCharOfs; /* relative to para's offset */
130 int len; /* length of run's text */
131 int nWidth; /* width of full run, width of leading&trailing ws */
132 int nFlags;
133 int nAscent, nDescent; /* pixels above/below baseline */
134 POINT pt; /* relative to para's position */
135 REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
136
137 SCRIPT_ANALYSIS script_analysis;
138 int num_glyphs, max_glyphs;
139 WORD *glyphs;
140 SCRIPT_VISATTR *vis_attrs;
141 int *advances;
142 GOFFSET *offsets;
143 int max_clusters;
144 WORD *clusters;
145 } ME_Run;
146
147 typedef struct tagME_Border
148 {
149 int width;
150 COLORREF colorRef;
151 } ME_Border;
152
153 typedef struct tagME_BorderRect
154 {
155 ME_Border top;
156 ME_Border left;
157 ME_Border bottom;
158 ME_Border right;
159 } ME_BorderRect;
160
161 typedef struct tagME_Paragraph
162 {
163 PARAFORMAT2 *pFmt;
164 ME_String *text;
165
166 struct tagME_DisplayItem *pCell; /* v4.1 */
167 ME_BorderRect border;
168
169 int nCharOfs;
170 int nFlags;
171 POINT pt;
172 int nHeight, nWidth;
173 int nRows;
174 struct tagME_DisplayItem *prev_para, *next_para;
175 } ME_Paragraph;
176
177 typedef struct tagME_Cell /* v4.1 */
178 {
179 int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
180 int nRightBoundary;
181 ME_BorderRect border;
182 POINT pt;
183 int nHeight, nWidth;
184 int yTextOffset; /* The text offset is caused by the largest top border. */
185 struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
186 } ME_Cell;
187
188 typedef struct tagME_Row
189 {
190 int nHeight;
191 int nBaseline;
192 int nWidth;
193 int nLMargin;
194 int nRMargin;
195 POINT pt;
196 } ME_Row;
197
198 /* the display item list layout is like this:
199 * - the document consists of paragraphs
200 * - each paragraph contains at least one run, the last run in the paragraph
201 * is an end-of-paragraph run
202 * - each formatted paragraph contains at least one row, which corresponds
203 * to a screen line (that's why there are no rows in an unformatted
204 * paragraph
205 * - the paragraphs contain "shortcut" pointers to the previous and the next
206 * paragraph, that makes iteration over paragraphs faster
207 * - the list starts with diTextStart and ends with diTextEnd
208 */
209
210 typedef struct tagME_DisplayItem
211 {
212 ME_DIType type;
213 struct tagME_DisplayItem *prev, *next;
214 union {
215 ME_Run run;
216 ME_Row row;
217 ME_Cell cell;
218 ME_Paragraph para;
219 } member;
220 } ME_DisplayItem;
221
222 typedef struct tagME_TextBuffer
223 {
224 ME_DisplayItem *pFirst, *pLast;
225 ME_Style *pCharStyle;
226 ME_Style *pDefaultStyle;
227 } ME_TextBuffer;
228
229 typedef struct tagME_Cursor
230 {
231 ME_DisplayItem *pPara;
232 ME_DisplayItem *pRun;
233 int nOffset;
234 } ME_Cursor;
235
236 typedef enum {
237 umAddToUndo,
238 umAddToRedo,
239 umIgnore,
240 umAddBackToUndo
241 } ME_UndoMode;
242
243 enum undo_type
244 {
245 undo_insert_run,
246 undo_delete_run,
247 undo_join_paras,
248 undo_split_para,
249 undo_set_para_fmt,
250 undo_set_char_fmt,
251 undo_end_transaction, /* marks the end of a group of changes for undo */
252 undo_potential_end_transaction /* allows grouping typed chars for undo */
253 };
254
255 struct insert_run_item
256 {
257 int pos, len;
258 WCHAR *str;
259 ME_Style *style;
260 DWORD flags;
261 };
262
263 struct delete_run_item
264 {
265 int pos, len;
266 };
267
268 struct join_paras_item
269 {
270 int pos;
271 };
272
273 struct split_para_item
274 {
275 int pos;
276 PARAFORMAT2 fmt;
277 ME_BorderRect border;
278 ME_String *eol_str;
279 DWORD flags;
280 ME_BorderRect cell_border;
281 int cell_right_boundary;
282 };
283
284 struct set_para_fmt_item
285 {
286 int pos;
287 PARAFORMAT2 fmt;
288 ME_BorderRect border;
289 };
290
291 struct set_char_fmt_item
292 {
293 int pos, len;
294 CHARFORMAT2W fmt;
295 };
296
297 struct undo_item
298 {
299 struct list entry;
300 enum undo_type type;
301 union
302 {
303 struct insert_run_item insert_run;
304 struct delete_run_item delete_run;
305 struct join_paras_item join_paras;
306 struct split_para_item split_para;
307 struct set_para_fmt_item set_para_fmt;
308 struct set_char_fmt_item set_char_fmt;
309 } u;
310 };
311
312 typedef enum {
313 stPosition = 0,
314 stWord,
315 stLine,
316 stParagraph,
317 stDocument
318 } ME_SelectionType;
319
320 typedef struct tagME_FontTableItem {
321 BYTE bCharSet;
322 WCHAR *szFaceName;
323 } ME_FontTableItem;
324
325
326 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
327
328 struct tagME_InStream {
329 EDITSTREAM *editstream;
330 DWORD dwSize;
331 DWORD dwUsed;
332 char buffer[STREAMIN_BUFFER_SIZE];
333 };
334 typedef struct tagME_InStream ME_InStream;
335
336
337 #define STREAMOUT_BUFFER_SIZE 4096
338 #define STREAMOUT_FONTTBL_SIZE 8192
339 #define STREAMOUT_COLORTBL_SIZE 1024
340
341 typedef struct tagME_OutStream {
342 EDITSTREAM *stream;
343 char buffer[STREAMOUT_BUFFER_SIZE];
344 UINT pos, written;
345 UINT nCodePage;
346 UINT nFontTblLen;
347 ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
348 UINT nColorTblLen;
349 COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
350 UINT nDefaultFont;
351 UINT nDefaultCodePage;
352 /* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
353 * an greater numbers mean we are in a cell nested within a cell. */
354 UINT nNestingLevel;
355 } ME_OutStream;
356
357 typedef struct tagME_TextEditor
358 {
359 HWND hWnd, hwndParent;
360 ITextHost *texthost;
361 IRichEditOle *reOle;
362 BOOL bEmulateVersion10;
363 ME_TextBuffer *pBuffer;
364 ME_Cursor *pCursors;
365 DWORD styleFlags;
366 DWORD alignStyle;
367 DWORD exStyleFlags;
368 int nCursors;
369 SIZE sizeWindow;
370 int nTotalLength, nLastTotalLength;
371 int nTotalWidth, nLastTotalWidth;
372 int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
373 int nUDArrowX;
374 COLORREF rgbBackColor;
375 HBRUSH hbrBackground;
376 BOOL bCaretAtEnd;
377 int nEventMask;
378 int nModifyStep;
379 struct list undo_stack;
380 struct list redo_stack;
381 int nUndoStackSize;
382 int nUndoLimit;
383 ME_UndoMode nUndoMode;
384 int nParagraphs;
385 int nLastSelStart, nLastSelEnd;
386 ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
387 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
388 int nZoomNumerator, nZoomDenominator;
389 RECT prevClientRect;
390 RECT rcFormat;
391 BOOL bDefaultFormatRect;
392 BOOL bWordWrap;
393 int nTextLimit;
394 EDITWORDBREAKPROCW pfnWordBreak;
395 LPRICHEDITOLECALLBACK lpOleCallback;
396 /*TEXTMODE variable; contains only one of each of the following options:
397 *TM_RICHTEXT or TM_PLAINTEXT
398 *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
399 *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
400 int mode;
401 BOOL bHideSelection;
402 BOOL AutoURLDetect_bEnable;
403 WCHAR cPasswordMask;
404 BOOL bHaveFocus;
405 BOOL bDialogMode; /* Indicates that we are inside a dialog window */
406 /*for IME */
407 int imeStartIndex;
408 DWORD selofs; /* The size of the selection bar on the left side of control */
409 ME_SelectionType nSelectionType;
410
411 /* Track previous notified selection */
412 CHARRANGE notified_cr;
413
414 /* Cache previously set scrollbar info */
415 SCROLLINFO vert_si, horz_si;
416
417 BOOL bMouseCaptured;
418 int wheel_remain;
419 struct list style_list;
420 } ME_TextEditor;
421
422 typedef struct tagME_Context
423 {
424 HDC hDC;
425 POINT pt;
426 RECT rcView;
427 SIZE dpi;
428 int nAvailWidth;
429
430 /* those are valid inside ME_WrapTextParagraph and related */
431 ME_TextEditor *editor;
432 } ME_Context;
433
434 typedef struct tagME_WrapContext
435 {
436 ME_Style *style;
437 ME_Context *context;
438 int nLeftMargin, nRightMargin, nFirstMargin;
439 int nAvailWidth;
440 int nRow;
441 POINT pt;
442 BOOL bOverflown, bWordWrap;
443 ME_DisplayItem *pPara;
444 ME_DisplayItem *pRowStart;
445
446 ME_DisplayItem *pLastSplittableRun;
447 } ME_WrapContext;
448
449 #endif