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