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