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