direct3d: Add a fixed function fog test.
[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
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
36
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>
47
48 #include "wine/debug.h"
49
50 typedef struct tagME_String
51 {
52   WCHAR *szData;
53   int nLen, nBuffer;
54 } ME_String;
55
56 typedef struct tagME_Style
57 {
58   CHARFORMAT2W fmt;
59
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;
65
66 typedef enum {
67   diInvalid,
68   diTextStart, /* start of the text buffer */
69   diParagraph, /* paragraph start */
70   diRun, /* run (sequence of chars with the same character format) */
71   diStartRow, /* start of the row (line of text on the screen) */
72   diTextEnd, /* end of the text buffer */
73   
74   /********************* these below are meant for finding only *********************/
75   diStartRowOrParagraph, /* 5 */
76   diStartRowOrParagraphOrEnd,
77   diRunOrParagraph,
78   diRunOrStartRow,
79   diParagraphOrEnd,
80   diRunOrParagraphOrEnd, /* 10 */
81   
82   diUndoInsertRun, /* 11 */
83   diUndoDeleteRun, /* 12 */
84   diUndoJoinParagraphs, /* 13 */
85   diUndoSplitParagraph, /* 14 */
86   diUndoSetParagraphFormat, /* 15 */
87   diUndoSetCharFormat, /* 16 */
88   diUndoEndTransaction, /* 17 */
89   diUndoSetDefaultCharFormat, /* 18 */
90 } ME_DIType;
91
92 /******************************** run flags *************************/
93 #define MERF_STYLEFLAGS 0x0FFF
94 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
95 #define MERF_GRAPHICS 1
96 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
97 #define MERF_TAB 2
98 /* run is a cell boundary */
99 #define MERF_CELL 4
100
101 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_CELL)
102
103 /* run is splittable (contains white spaces in the middle or end) */
104 #define MERF_SPLITTABLE 0x001000
105 /* run starts with whitespaces */
106 #define MERF_STARTWHITE 0x002000
107 /* run ends with whitespaces */
108 #define MERF_ENDWHITE   0x004000
109 /* run is completely made of whitespaces */
110 #define MERF_WHITESPACE 0x008000
111 /* run is a last (dummy) run in the paragraph */
112 #define MERF_SKIPPED    0x010000
113 /* flags that are calculated during text wrapping */
114 #define MERF_CALCBYWRAP 0x0F0000
115 /* the "end of paragraph" run, contains 1 character */
116 #define MERF_ENDPARA    0x100000
117 /* run is hidden */
118 #define MERF_HIDDEN     0x200000
119
120 /* runs with any of these flags set cannot be joined */
121 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
122 /* runs that don't contain real text */
123 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
124
125 /* those flags are kept when the row is split */
126 #define MERF_SPLITMASK (~(0))
127
128 /******************************** para flags *************************/
129
130 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
131 #define MEPF_REWRAP 1
132 #define MEPF_REPAINT 2
133
134 /******************************** structures *************************/
135
136 struct tagME_DisplayItem;
137
138 typedef struct tagME_Run
139 {
140   ME_String *strText;
141   ME_Style *style;
142   int nCharOfs; /* relative to para's offset */
143   int nWidth; /* width of full run, width of leading&trailing ws */
144   int nFlags;
145   int nAscent, nDescent; /* pixels above/below baseline */
146   POINT pt; /* relative to para's position */
147   struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */
148 } ME_Run;
149
150 typedef struct tagME_Document {
151   struct tagME_DisplayItem *def_char_style;
152   struct tagME_DisplayItem *def_para_style;
153   int last_wrapped_line;
154 } ME_Document;
155
156 typedef struct tagME_TableCell
157 {
158   int nRightBoundary;
159   struct tagME_TableCell *next;
160 } ME_TableCell;
161
162 typedef struct tagME_Paragraph
163 {
164   PARAFORMAT2 *pFmt;
165   
166   BOOL bTable;                       /* this paragraph is a table row */
167   struct tagME_TableCell *pCells;    /* list of cells and their properties */
168   struct tagME_TableCell *pLastCell; /* points to the last cell in the list */
169
170   int nLeftMargin, nRightMargin, nFirstMargin;
171   int nCharOfs;
172   int nFlags;
173   int nYPos, nHeight;
174   int nLastPaintYPos, nLastPaintHeight;
175   int nRows;
176   struct tagME_DisplayItem *prev_para, *next_para, *document;
177 } ME_Paragraph;
178
179 typedef struct tagME_Row
180 {
181   int nHeight;
182   int nBaseline;
183   int nWidth;
184   int nLMargin;
185   int nRMargin;
186   int nYPos;
187 } ME_Row;
188
189 /* the display item list layout is like this:
190  * - the document consists of paragraphs
191  * - each paragraph contains at least one run, the last run in the paragraph
192  *   is an end-of-paragraph run
193  * - each formatted paragraph contains at least one row, which corresponds
194  *   to a screen line (that's why there are no rows in an unformatted
195  *   paragraph
196  * - the paragraphs contain "shortcut" pointers to the previous and the next
197  *   paragraph, that makes iteration over paragraphs faster 
198  * - the list starts with diTextStart and ends with diTextEnd
199  */
200
201 typedef struct tagME_DisplayItem
202 {
203   ME_DIType type;
204   struct tagME_DisplayItem *prev, *next;
205   union {
206     ME_Run run;
207     ME_Row row;
208     ME_Paragraph para;
209     ME_Document doc; /* not used */
210     ME_Style *ustyle; /* used by diUndoSetCharFormat */
211   } member;
212 } ME_DisplayItem;
213
214 typedef struct tagME_UndoItem
215 {
216   ME_DisplayItem di;
217   int nStart, nLen;
218 } ME_UndoItem;
219
220 typedef struct tagME_TextBuffer
221 {
222   ME_DisplayItem *pFirst, *pLast;
223   ME_Style *pCharStyle;
224   ME_Style *pDefaultStyle;
225 } ME_TextBuffer;
226
227 typedef struct tagME_Cursor
228 {
229   ME_DisplayItem *pRun;
230   int nOffset;
231 } ME_Cursor;
232
233 typedef enum {
234   umAddToUndo,
235   umAddToRedo,
236   umIgnore,
237   umAddBackToUndo
238 } ME_UndoMode;
239
240 typedef struct tagME_FontTableItem {
241   BYTE bCharSet;
242   WCHAR *szFaceName;
243 } ME_FontTableItem;
244
245
246 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
247
248 struct tagME_InStream {
249   EDITSTREAM *editstream;
250   DWORD dwSize;
251   DWORD dwUsed;
252   char buffer[STREAMIN_BUFFER_SIZE];
253 };
254 typedef struct tagME_InStream ME_InStream;
255
256
257 #define STREAMOUT_BUFFER_SIZE 4096
258 #define STREAMOUT_FONTTBL_SIZE 8192
259 #define STREAMOUT_COLORTBL_SIZE 1024
260
261 typedef struct tagME_OutStream {
262   EDITSTREAM *stream;
263   char buffer[STREAMOUT_BUFFER_SIZE];
264   UINT pos, written;
265   UINT nCodePage;
266   UINT nFontTblLen;
267   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
268   UINT nColorTblLen;
269   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
270   UINT nDefaultFont;
271   UINT nDefaultCodePage;
272 } ME_OutStream;
273
274 typedef struct tagME_FontCacheItem
275 {
276   LOGFONTW lfSpecs;
277   HFONT hFont;
278   int nRefs;
279   int nAge;
280 } ME_FontCacheItem;
281
282 #define HFONT_CACHE_SIZE 10
283
284 typedef struct tagME_TextEditor
285 {
286   HWND hWnd;
287   BOOL bEmulateVersion10;
288   BOOL bCaretShown;
289   ME_TextBuffer *pBuffer;
290   ME_Cursor *pCursors;
291   int nCursors;
292   SIZE sizeWindow;
293   int nTotalLength, nLastTotalLength;
294   int nUDArrowX;
295   int nSequence;
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_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
308   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
309   int nZoomNumerator, nZoomDenominator;
310   RECT rcFormat;
311   BOOL bRedraw;
312   int nInvalidOfs;
313   int nTextLimit;
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   WCHAR cPasswordMask;
324 } ME_TextEditor;
325
326 typedef struct tagME_Context
327 {
328   HDC hDC;
329   POINT pt;
330   POINT ptRowOffset;
331   RECT rcView;
332   HBRUSH hbrMargin;
333
334   /* those are valid inside ME_WrapTextParagraph and related */
335   POINT ptFirstRun;
336   ME_TextEditor *editor;
337   int nSequence;
338 } ME_Context;
339
340 typedef struct tagME_WrapContext
341 {
342   ME_Style *style;
343   ME_Context *context;
344   int nLeftMargin, nRightMargin, nFirstMargin;
345   int nTotalWidth, nAvailWidth;
346   int nRow;
347   POINT pt;
348   BOOL bOverflown;
349   ME_DisplayItem *pRowStart;
350   
351   ME_DisplayItem *pLastSplittableRun;
352   POINT ptLastSplittableRun;
353 } ME_WrapContext;  
354
355 #endif