riched20: Implement EM_SETUNDOLIMIT and its conformance tests.
[wine/multimedia.git] / dlls / riched20 / editstr.h
blobbb151faadf1bd4710cb7b15cc3c4b729b2f90da3
1 /*
2 * RichEdit - structures and constant
4 * Copyright 2004 by Krzysztof Foltman
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __EDITSTR_H
22 #define __EDITSTR_H
24 #ifndef _WIN32_IE
25 #define _WIN32_IE 0x0400
26 #endif
28 #include <assert.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include <windef.h>
38 #include <winbase.h>
39 #include <winnls.h>
40 #include <winnt.h>
41 #include <wingdi.h>
42 #include <winuser.h>
43 #include <richedit.h>
44 #include <commctrl.h>
45 #include <ole2.h>
46 #include <richole.h>
48 #include "wine/debug.h"
50 typedef struct tagME_String
52 WCHAR *szData;
53 int nLen, nBuffer;
54 } ME_String;
56 typedef struct tagME_Style
58 CHARFORMAT2W fmt;
60 HFONT hFont; /* cached font for the style */
61 TEXTMETRICW tm; /* cached font metrics for the style */
62 int nRefs; /* reference count */
63 int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
64 } ME_Style;
66 typedef enum {
67 diTextStart, /* start of the text buffer */
68 diParagraph, /* paragraph start */
69 diRun, /* run (sequence of chars with the same character format) */
70 diStartRow, /* start of the row (line of text on the screen) */
71 diTextEnd, /* end of the text buffer */
73 /********************* these below are meant for finding only *********************/
74 diStartRowOrParagraph, /* 5 */
75 diStartRowOrParagraphOrEnd,
76 diRunOrParagraph,
77 diRunOrStartRow,
78 diParagraphOrEnd,
79 diRunOrParagraphOrEnd, /* 10 */
81 diUndoInsertRun, /* 11 */
82 diUndoDeleteRun, /* 12 */
83 diUndoJoinParagraphs, /* 13 */
84 diUndoSplitParagraph, /* 14 */
85 diUndoSetParagraphFormat, /* 15 */
86 diUndoSetCharFormat, /* 16 */
87 diUndoEndTransaction, /* 17 */
88 diUndoSetDefaultCharFormat, /* 18 */
89 } ME_DIType;
91 /******************************** run flags *************************/
92 #define MERF_STYLEFLAGS 0x0FFF
93 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
94 #define MERF_GRAPHICS 1
95 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
96 #define MERF_TAB 2
97 /* run is a cell boundary */
98 #define MERF_CELL 4
100 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_CELL)
102 /* run is splittable (contains white spaces in the middle or end) */
103 #define MERF_SPLITTABLE 0x001000
104 /* run starts with whitespaces */
105 #define MERF_STARTWHITE 0x002000
106 /* run ends with whitespaces */
107 #define MERF_ENDWHITE 0x004000
108 /* run is completely made of whitespaces */
109 #define MERF_WHITESPACE 0x008000
110 /* run is a last (dummy) run in the paragraph */
111 #define MERF_SKIPPED 0x010000
112 /* flags that are calculated during text wrapping */
113 #define MERF_CALCBYWRAP 0x0F0000
114 /* the "end of paragraph" run, contains 1 character */
115 #define MERF_ENDPARA 0x100000
116 /* run is hidden */
117 #define MERF_HIDDEN 0x200000
119 /* runs with any of these flags set cannot be joined */
120 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
121 /* runs that don't contain real text */
122 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
124 /* those flags are kept when the row is split */
125 #define MERF_SPLITMASK (~(0))
127 /******************************** para flags *************************/
129 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
130 #define MEPF_REWRAP 1
131 #define MEPF_REPAINT 2
133 /******************************** structures *************************/
135 struct tagME_DisplayItem;
137 typedef struct tagME_Run
139 ME_String *strText;
140 ME_Style *style;
141 int nCharOfs; /* relative to para's offset */
142 int nWidth; /* width of full run, width of leading&trailing ws */
143 int nFlags;
144 int nAscent, nDescent; /* pixels above/below baseline */
145 POINT pt; /* relative to para's position */
146 struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */
147 } ME_Run;
149 typedef struct tagME_Document {
150 struct tagME_DisplayItem *def_char_style;
151 struct tagME_DisplayItem *def_para_style;
152 int last_wrapped_line;
153 } ME_Document;
155 typedef struct tagME_TableCell
157 int nRightBoundary;
158 struct tagME_TableCell *next;
159 } ME_TableCell;
161 typedef struct tagME_Paragraph
163 PARAFORMAT2 *pFmt;
165 BOOL bTable; /* this paragraph is a table row */
166 struct tagME_TableCell *pCells; /* list of cells and their properties */
167 struct tagME_TableCell *pLastCell; /* points to the last cell in the list */
169 int nLeftMargin, nRightMargin, nFirstMargin;
170 int nCharOfs;
171 int nFlags;
172 int nYPos, nHeight;
173 int nLastPaintYPos, nLastPaintHeight;
174 int nRows;
175 struct tagME_DisplayItem *prev_para, *next_para, *document;
176 } ME_Paragraph;
178 typedef struct tagME_Row
180 int nHeight;
181 int nBaseline;
182 int nWidth;
183 int nLMargin;
184 int nRMargin;
185 int nYPos;
186 } ME_Row;
188 /* the display item list layout is like this:
189 * - the document consists of paragraphs
190 * - each paragraph contains at least one run, the last run in the paragraph
191 * is an end-of-paragraph run
192 * - each formatted paragraph contains at least one row, which corresponds
193 * to a screen line (that's why there are no rows in an unformatted
194 * paragraph
195 * - the paragraphs contain "shortcut" pointers to the previous and the next
196 * paragraph, that makes iteration over paragraphs faster
197 * - the list starts with diTextStart and ends with diTextEnd
200 typedef struct tagME_DisplayItem
202 ME_DIType type;
203 struct tagME_DisplayItem *prev, *next;
204 union {
205 ME_Run run;
206 ME_Row row;
207 ME_Paragraph para;
208 ME_Document doc; /* not used */
209 ME_Style *ustyle; /* used by diUndoSetCharFormat */
210 } member;
211 } ME_DisplayItem;
213 typedef struct tagME_UndoItem
215 ME_DisplayItem di;
216 int nStart, nLen;
217 } ME_UndoItem;
219 typedef struct tagME_TextBuffer
221 ME_DisplayItem *pFirst, *pLast;
222 ME_Style *pCharStyle;
223 ME_Style *pDefaultStyle;
224 } ME_TextBuffer;
226 typedef struct tagME_Cursor
228 ME_DisplayItem *pRun;
229 int nOffset;
230 } ME_Cursor;
232 typedef enum {
233 umAddToUndo,
234 umAddToRedo,
235 umIgnore,
236 umAddBackToUndo
237 } ME_UndoMode;
239 typedef struct tagME_FontTableItem {
240 BYTE bCharSet;
241 WCHAR *szFaceName;
242 } ME_FontTableItem;
245 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
247 struct tagME_InStream {
248 EDITSTREAM *editstream;
249 DWORD dwSize;
250 DWORD dwUsed;
251 char buffer[STREAMIN_BUFFER_SIZE];
253 typedef struct tagME_InStream ME_InStream;
256 #define STREAMOUT_BUFFER_SIZE 4096
257 #define STREAMOUT_FONTTBL_SIZE 8192
258 #define STREAMOUT_COLORTBL_SIZE 1024
260 typedef struct tagME_OutStream {
261 EDITSTREAM *stream;
262 char buffer[STREAMOUT_BUFFER_SIZE];
263 UINT pos, written;
264 UINT nCodePage;
265 UINT nFontTblLen;
266 ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
267 UINT nColorTblLen;
268 COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
269 UINT nDefaultFont;
270 UINT nDefaultCodePage;
271 } ME_OutStream;
273 typedef struct tagME_FontCacheItem
275 LOGFONTW lfSpecs;
276 HFONT hFont;
277 int nRefs;
278 int nAge;
279 } ME_FontCacheItem;
281 #define HFONT_CACHE_SIZE 10
283 typedef struct tagME_TextEditor
285 HWND hWnd;
286 BOOL bEmulateVersion10;
287 BOOL bCaretShown;
288 ME_TextBuffer *pBuffer;
289 ME_Cursor *pCursors;
290 int nCursors;
291 SIZE sizeWindow;
292 int nTotalLength, nLastTotalLength;
293 int nUDArrowX;
294 int nSequence;
295 int nOldSelFrom, nOldSelTo;
296 COLORREF rgbBackColor;
297 HBRUSH hbrBackground;
298 BOOL bCaretAtEnd;
299 int nEventMask;
300 int nModifyStep;
301 ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
302 int nUndoStackSize;
303 int nUndoLimit;
304 ME_UndoMode nUndoMode;
305 int nParagraphs;
306 int nLastSelStart, nLastSelEnd;
307 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
308 BOOL bScrollX, bScrollY;
309 int nScrollPosY;
310 int nZoomNumerator, nZoomDenominator;
311 RECT rcFormat;
312 BOOL bRedraw;
313 int nInvalidOfs;
314 EDITWORDBREAKPROCW pfnWordBreak;
315 LPRICHEDITOLECALLBACK lpOleCallback;
316 /*TEXTMODE variable; contains only one of each of the following options:
317 *TM_RICHTEXT or TM_PLAINTEXT
318 *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
319 *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
320 int mode;
321 BOOL bHideSelection;
322 BOOL AutoURLDetect_bEnable;
323 } ME_TextEditor;
325 typedef struct tagME_Context
327 HDC hDC;
328 POINT pt;
329 POINT ptRowOffset;
330 RECT rcView;
331 HBRUSH hbrMargin;
333 /* those are valid inside ME_WrapTextParagraph and related */
334 POINT ptFirstRun;
335 ME_TextEditor *editor;
336 int nSequence;
337 } ME_Context;
339 typedef struct tagME_WrapContext
341 ME_Style *style;
342 ME_Context *context;
343 int nLeftMargin, nRightMargin, nFirstMargin;
344 int nTotalWidth, nAvailWidth;
345 int nRow;
346 POINT pt;
347 BOOL bOverflown;
348 ME_DisplayItem *pRowStart;
350 ME_DisplayItem *pLastSplittableRun;
351 POINT ptLastSplittableRun;
352 } ME_WrapContext;
354 #endif