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