riched20: Reduced screen flicker by using proper update region invalidation.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
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>
41
42 #include "wine/debug.h"
43
44 typedef struct tagME_String
45 {
46   WCHAR *szData;
47   int nLen, nBuffer;
48 } ME_String;
49
50 typedef struct tagME_Style
51 {
52   CHARFORMAT2W fmt;
53
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;
59
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 */
66   
67   /********************* these below are meant for finding only *********************/
68   diStartRowOrParagraph, /* 5 */
69   diStartRowOrParagraphOrEnd,
70   diRunOrParagraph,
71   diRunOrStartRow,
72   diParagraphOrEnd,
73   diRunOrParagraphOrEnd, /* 10 */
74   
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;
84
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
91
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
107 /* runs with any of these flags set cannot be joined */
108 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
109 /* runs that don't contain real text */
110 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
111
112 /* those flags are kept when the row is split */
113 #define MERF_SPLITMASK (~(0))
114
115 /******************************** para flags *************************/
116
117 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
118 #define MEPF_REWRAP 1
119 #define MEPF_REPAINT 2
120
121 /******************************** structures *************************/
122
123 struct tagME_DisplayItem;
124
125 typedef struct tagME_Run
126 {
127   ME_String *strText;
128   ME_Style *style;
129   int nCharOfs; /* relative to para's offset */
130   int nWidth; /* width of full run, width of leading&trailing ws */
131   int nFlags;
132   int nAscent, nDescent; /* pixels above/below baseline */
133   POINT pt; /* relative to para's position */
134 } ME_Run;
135
136 typedef struct tagME_Document {
137   struct tagME_DisplayItem *def_char_style;
138   struct tagME_DisplayItem *def_para_style;
139   int last_wrapped_line;
140 } ME_Document;
141
142 typedef struct tagME_Paragraph
143 {
144   PARAFORMAT2 *pFmt;
145   int nLeftMargin, nRightMargin, nFirstMargin;
146   int nCharOfs;
147   int nFlags;
148   int nYPos, nHeight;
149   int nLastPaintYPos, nLastPaintHeight;
150   int nRows;
151   struct tagME_DisplayItem *prev_para, *next_para, *document;
152 } ME_Paragraph;
153
154 typedef struct tagME_Row
155 {
156   int nHeight;
157   int nBaseline;
158   int nWidth;
159   int nLMargin;
160   int nRMargin;
161   int nYPos;
162 } ME_Row;
163
164 /* the display item list layout is like this:
165  * - the document consists of paragraphs
166  * - each paragraph contains at least one run, the last run in the paragraph
167  *   is an end-of-paragraph run
168  * - each formatted paragraph contains at least one row, which corresponds
169  *   to a screen line (that's why there are no rows in an unformatted
170  *   paragraph
171  * - the paragraphs contain "shortcut" pointers to the previous and the next
172  *   paragraph, that makes iteration over paragraphs faster 
173  * - the list starts with diTextStart and ends with diTextEnd
174  */
175
176 typedef struct tagME_DisplayItem
177 {
178   ME_DIType type;
179   struct tagME_DisplayItem *prev, *next;
180   union {
181     ME_Run run;
182     ME_Row row;
183     ME_Paragraph para;
184     ME_Document doc; /* not used */
185     ME_Style *ustyle; /* used by diUndoSetCharFormat */
186   } member;
187 } ME_DisplayItem;
188
189 typedef struct tagME_UndoItem
190 {
191   ME_DisplayItem di;
192   int nStart, nLen;
193 } ME_UndoItem;
194
195 typedef struct tagME_TextBuffer
196 {
197   ME_DisplayItem *pFirst, *pLast;
198   ME_Style *pCharStyle;
199   ME_Style *pDefaultStyle;
200 } ME_TextBuffer;
201
202 typedef struct tagME_Cursor
203 {
204   ME_DisplayItem *pRun;
205   int nOffset;
206 } ME_Cursor;
207
208 typedef enum {
209   umAddToUndo,
210   umAddToRedo,
211   umIgnore,
212   umAddBackToUndo
213 } ME_UndoMode;
214
215 typedef struct tagME_FontTableItem {
216   BYTE bCharSet;
217   WCHAR *szFaceName;
218 } ME_FontTableItem;
219
220
221 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
222
223 struct tagME_InStream {
224   EDITSTREAM *editstream;
225   DWORD dwSize;
226   DWORD dwUsed;
227   char buffer[STREAMIN_BUFFER_SIZE];
228 };
229 typedef struct tagME_InStream ME_InStream;
230
231
232 #define STREAMOUT_BUFFER_SIZE 4096
233 #define STREAMOUT_FONTTBL_SIZE 8192
234 #define STREAMOUT_COLORTBL_SIZE 1024
235
236 typedef struct tagME_OutStream {
237   EDITSTREAM *stream;
238   char buffer[STREAMOUT_BUFFER_SIZE];
239   UINT pos, written;
240   UINT nCodePage;
241   UINT nFontTblLen;
242   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
243   UINT nColorTblLen;
244   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
245   UINT nDefaultFont;
246   UINT nDefaultCodePage;
247 } ME_OutStream;
248
249 typedef struct tagME_FontCacheItem
250 {
251   LOGFONTW lfSpecs;
252   HFONT hFont;
253   int nRefs;
254   int nAge;
255 } ME_FontCacheItem;
256
257 #define HFONT_CACHE_SIZE 10
258
259 typedef struct tagME_TextEditor
260 {
261   HWND hWnd;
262   BOOL bEmulateVersion10;
263   BOOL bCaretShown;
264   ME_TextBuffer *pBuffer;
265   ME_Cursor *pCursors;
266   int nCursors;
267   SIZE sizeWindow;
268   int nTotalLength, nLastTotalLength;
269   int nUDArrowX;
270   int nSequence;
271   int nOldSelFrom, nOldSelTo;
272   COLORREF rgbBackColor;
273   HBRUSH hbrBackground;
274   BOOL bCaretAtEnd;
275   int nEventMask;
276   int nModifyStep;
277   ME_DisplayItem *pUndoStack, *pRedoStack;
278   ME_UndoMode nUndoMode;
279   int nParagraphs;
280   int nLastSelStart, nLastSelEnd;
281   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
282   ME_OutStream *pStream;
283   BOOL bScrollX, bScrollY;
284   int nScrollPosY;
285   int nZoomNumerator, nZoomDenominator;
286   RECT rcFormat;
287   BOOL bRedraw;
288   int nInvalidOfs;
289 } ME_TextEditor;
290
291 typedef struct tagME_Context
292 {
293   HDC hDC;
294   POINT pt;
295   POINT ptRowOffset;
296   RECT rcView;
297   HBRUSH hbrMargin;
298
299   /* those are valid inside ME_WrapTextParagraph and related */
300   POINT ptFirstRun;
301   ME_TextEditor *editor;
302   int nSequence;
303 } ME_Context;
304
305 typedef struct tagME_WrapContext
306 {
307   ME_Style *style;
308   ME_Context *context;
309   int nLeftMargin, nRightMargin, nFirstMargin;
310   int nTotalWidth, nAvailWidth;
311   int nRow;
312   POINT pt;
313   BOOL bOverflown;
314   ME_DisplayItem *pRowStart;
315   
316   ME_DisplayItem *pLastSplittableRun;
317   POINT ptLastSplittableRun;
318 } ME_WrapContext;  
319
320 #endif