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