riched20: Added support for hidden text.
[wine/wine-kai.git] / dlls / riched20 / editstr.h
blob919dd029dc0910688015f5c337beef6343adfa2a
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 #include <windef.h>
34 #include <winbase.h>
35 #include <winnls.h>
36 #include <winnt.h>
37 #include <wingdi.h>
38 #include <winuser.h>
39 #include <richedit.h>
40 #include <commctrl.h>
42 #include "wine/debug.h"
44 typedef struct tagME_String
46 WCHAR *szData;
47 int nLen, nBuffer;
48 } ME_String;
50 typedef struct tagME_Style
52 CHARFORMAT2W fmt;
54 HFONT hFont; /* cached font for the style */
55 TEXTMETRICW tm; /* cached font metrics for the style */
56 int nRefs; /* reference count */
57 int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
58 } ME_Style;
60 typedef enum {
61 diTextStart, /* start of the text buffer */
62 diParagraph, /* paragraph start */
63 diRun, /* run (sequence of chars with the same character format) */
64 diStartRow, /* start of the row (line of text on the screen) */
65 diTextEnd, /* end of the text buffer */
67 /********************* these below are meant for finding only *********************/
68 diStartRowOrParagraph, /* 5 */
69 diStartRowOrParagraphOrEnd,
70 diRunOrParagraph,
71 diRunOrStartRow,
72 diParagraphOrEnd,
73 diRunOrParagraphOrEnd, /* 10 */
75 diUndoInsertRun, /* 11 */
76 diUndoDeleteRun, /* 12 */
77 diUndoJoinParagraphs, /* 13 */
78 diUndoSplitParagraph, /* 14 */
79 diUndoSetParagraphFormat, /* 15 */
80 diUndoSetCharFormat, /* 16 */
81 diUndoEndTransaction, /* 17 */
82 diUndoSetDefaultCharFormat, /* 18 */
83 } ME_DIType;
85 /******************************** run flags *************************/
86 #define MERF_STYLEFLAGS 0x0FFF
87 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
88 #define MERF_GRAPHICS 1
89 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
90 #define MERF_TAB 2
92 /* run is splittable (contains white spaces in the middle or end) */
93 #define MERF_SPLITTABLE 0x001000
94 /* run starts with whitespaces */
95 #define MERF_STARTWHITE 0x002000
96 /* run ends with whitespaces */
97 #define MERF_ENDWHITE 0x004000
98 /* run is completely made of whitespaces */
99 #define MERF_WHITESPACE 0x008000
100 /* run is a last (dummy) run in the paragraph */
101 #define MERF_SKIPPED 0x010000
102 /* flags that are calculated during text wrapping */
103 #define MERF_CALCBYWRAP 0x0F0000
104 /* the "end of paragraph" run, contains 1 character */
105 #define MERF_ENDPARA 0x100000
106 /* run is hidden */
107 #define MERF_HIDDEN 0x200000
109 /* runs with any of these flags set cannot be joined */
110 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
111 /* runs that don't contain real text */
112 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
114 /* those flags are kept when the row is split */
115 #define MERF_SPLITMASK (~(0))
117 /******************************** para flags *************************/
119 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
120 #define MEPF_REWRAP 1
121 #define MEPF_REPAINT 2
123 /******************************** structures *************************/
125 struct tagME_DisplayItem;
127 typedef struct tagME_Run
129 ME_String *strText;
130 ME_Style *style;
131 int nCharOfs; /* relative to para's offset */
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 } ME_Run;
138 typedef struct tagME_Document {
139 struct tagME_DisplayItem *def_char_style;
140 struct tagME_DisplayItem *def_para_style;
141 int last_wrapped_line;
142 } ME_Document;
144 typedef struct tagME_Paragraph
146 PARAFORMAT2 *pFmt;
147 int nLeftMargin, nRightMargin, nFirstMargin;
148 int nCharOfs;
149 int nFlags;
150 int nYPos, nHeight;
151 int nLastPaintYPos, nLastPaintHeight;
152 int nRows;
153 struct tagME_DisplayItem *prev_para, *next_para, *document;
154 } ME_Paragraph;
156 typedef struct tagME_Row
158 int nHeight;
159 int nBaseline;
160 int nWidth;
161 int nLMargin;
162 int nRMargin;
163 int nYPos;
164 } ME_Row;
166 /* the display item list layout is like this:
167 * - the document consists of paragraphs
168 * - each paragraph contains at least one run, the last run in the paragraph
169 * is an end-of-paragraph run
170 * - each formatted paragraph contains at least one row, which corresponds
171 * to a screen line (that's why there are no rows in an unformatted
172 * paragraph
173 * - the paragraphs contain "shortcut" pointers to the previous and the next
174 * paragraph, that makes iteration over paragraphs faster
175 * - the list starts with diTextStart and ends with diTextEnd
178 typedef struct tagME_DisplayItem
180 ME_DIType type;
181 struct tagME_DisplayItem *prev, *next;
182 union {
183 ME_Run run;
184 ME_Row row;
185 ME_Paragraph para;
186 ME_Document doc; /* not used */
187 ME_Style *ustyle; /* used by diUndoSetCharFormat */
188 } member;
189 } ME_DisplayItem;
191 typedef struct tagME_UndoItem
193 ME_DisplayItem di;
194 int nStart, nLen;
195 } ME_UndoItem;
197 typedef struct tagME_TextBuffer
199 ME_DisplayItem *pFirst, *pLast;
200 ME_Style *pCharStyle;
201 ME_Style *pDefaultStyle;
202 } ME_TextBuffer;
204 typedef struct tagME_Cursor
206 ME_DisplayItem *pRun;
207 int nOffset;
208 } ME_Cursor;
210 typedef enum {
211 umAddToUndo,
212 umAddToRedo,
213 umIgnore,
214 umAddBackToUndo
215 } ME_UndoMode;
217 typedef struct tagME_FontTableItem {
218 BYTE bCharSet;
219 WCHAR *szFaceName;
220 } ME_FontTableItem;
223 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
225 struct tagME_InStream {
226 EDITSTREAM *editstream;
227 DWORD dwSize;
228 DWORD dwUsed;
229 char buffer[STREAMIN_BUFFER_SIZE];
231 typedef struct tagME_InStream ME_InStream;
234 #define STREAMOUT_BUFFER_SIZE 4096
235 #define STREAMOUT_FONTTBL_SIZE 8192
236 #define STREAMOUT_COLORTBL_SIZE 1024
238 typedef struct tagME_OutStream {
239 EDITSTREAM *stream;
240 char buffer[STREAMOUT_BUFFER_SIZE];
241 UINT pos, written;
242 UINT nCodePage;
243 UINT nFontTblLen;
244 ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
245 UINT nColorTblLen;
246 COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
247 UINT nDefaultFont;
248 UINT nDefaultCodePage;
249 } ME_OutStream;
251 typedef struct tagME_FontCacheItem
253 LOGFONTW lfSpecs;
254 HFONT hFont;
255 int nRefs;
256 int nAge;
257 } ME_FontCacheItem;
259 #define HFONT_CACHE_SIZE 10
261 typedef struct tagME_TextEditor
263 HWND hWnd;
264 BOOL bEmulateVersion10;
265 BOOL bCaretShown;
266 ME_TextBuffer *pBuffer;
267 ME_Cursor *pCursors;
268 int nCursors;
269 SIZE sizeWindow;
270 int nTotalLength, nLastTotalLength;
271 int nUDArrowX;
272 int nSequence;
273 int nOldSelFrom, nOldSelTo;
274 COLORREF rgbBackColor;
275 HBRUSH hbrBackground;
276 BOOL bCaretAtEnd;
277 int nEventMask;
278 int nModifyStep;
279 ME_DisplayItem *pUndoStack, *pRedoStack;
280 ME_UndoMode nUndoMode;
281 int nParagraphs;
282 int nLastSelStart, nLastSelEnd;
283 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
284 ME_OutStream *pStream;
285 BOOL bScrollX, bScrollY;
286 int nScrollPosY;
287 int nZoomNumerator, nZoomDenominator;
288 RECT rcFormat;
289 BOOL bRedraw;
290 int nInvalidOfs;
291 EDITWORDBREAKPROCW pfnWordBreak;
292 } ME_TextEditor;
294 typedef struct tagME_Context
296 HDC hDC;
297 POINT pt;
298 POINT ptRowOffset;
299 RECT rcView;
300 HBRUSH hbrMargin;
302 /* those are valid inside ME_WrapTextParagraph and related */
303 POINT ptFirstRun;
304 ME_TextEditor *editor;
305 int nSequence;
306 } ME_Context;
308 typedef struct tagME_WrapContext
310 ME_Style *style;
311 ME_Context *context;
312 int nLeftMargin, nRightMargin, nFirstMargin;
313 int nTotalWidth, nAvailWidth;
314 int nRow;
315 POINT pt;
316 BOOL bOverflown;
317 ME_DisplayItem *pRowStart;
319 ME_DisplayItem *pLastSplittableRun;
320 POINT ptLastSplittableRun;
321 } ME_WrapContext;
323 #endif