Revert "winex11.drv: Optimise getting the bits of a DIB after calling SetDIBits."
[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 - marks the end of a group of changes for undo */
89   diUndoPotentialEndTransaction, /* 18 - allows grouping typed chars for undo */
90 } ME_DIType;
91
92 #define SELECTIONBAR_WIDTH 9
93
94 /******************************** run flags *************************/
95 #define MERF_STYLEFLAGS 0x0FFF
96 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
97 #define MERF_GRAPHICS   0x001
98 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
99 #define MERF_TAB        0x002
100 /* run is a cell boundary */
101 #define MERF_CELL       0x004
102
103 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_CELL)
104
105 /* run is splittable (contains white spaces in the middle or end) */
106 #define MERF_SPLITTABLE 0x001000
107 /* run starts with whitespaces */
108 #define MERF_STARTWHITE 0x002000
109 /* run ends with whitespaces */
110 #define MERF_ENDWHITE   0x004000
111 /* run is completely made of whitespaces */
112 #define MERF_WHITESPACE 0x008000
113 /* run is a last (dummy) run in the paragraph */
114 #define MERF_SKIPPED    0x010000
115 /* flags that are calculated during text wrapping */
116 #define MERF_CALCBYWRAP 0x0F0000
117 /* the "end of paragraph" run, contains 1 character */
118 #define MERF_ENDPARA    0x100000
119 /* forcing the "end of row" run, contains 1 character */
120 #define MERF_ENDROW     0x200000
121 /* run is hidden */
122 #define MERF_HIDDEN     0x400000
123
124 /* runs with any of these flags set cannot be joined */
125 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
126 /* runs that don't contain real text */
127 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
128
129 /* those flags are kept when the row is split */
130 #define MERF_SPLITMASK (~(0))
131
132 /******************************** para flags *************************/
133
134 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
135 #define MEPF_REWRAP 1
136 #define MEPF_REPAINT 2
137
138 /******************************** structures *************************/
139
140 struct tagME_DisplayItem;
141
142 typedef struct tagME_Run
143 {
144   ME_String *strText;
145   ME_Style *style;
146   int nCharOfs; /* relative to para's offset */
147   int nWidth; /* width of full run, width of leading&trailing ws */
148   int nFlags;
149   int nAscent, nDescent; /* pixels above/below baseline */
150   POINT pt; /* relative to para's position */
151   struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */
152   REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
153   int nCR; int nLF;  /* for MERF_ENDPARA: number of \r and \n characters encoded by run */
154 } ME_Run;
155
156 typedef struct tagME_Document {
157   struct tagME_DisplayItem *def_char_style;
158   struct tagME_DisplayItem *def_para_style;
159   int last_wrapped_line;
160 } ME_Document;
161
162 typedef struct tagME_TableCell
163 {
164   int nRightBoundary;
165   struct tagME_TableCell *next;
166 } ME_TableCell;
167
168 typedef struct tagME_Paragraph
169 {
170   PARAFORMAT2 *pFmt;
171
172   struct tagME_TableCell *pCells;    /* list of cells and their properties */
173   struct tagME_TableCell *pLastCell; /* points to the last cell in the list */
174
175   int nCharOfs;
176   int nFlags;
177   int nYPos, nHeight;
178   int nLastPaintYPos, nLastPaintHeight;
179   int nRows;
180   struct tagME_DisplayItem *prev_para, *next_para, *document;
181 } ME_Paragraph;
182
183 typedef struct tagME_Row
184 {
185   int nHeight;
186   int nBaseline;
187   int nWidth;
188   int nLMargin;
189   int nRMargin;
190   int nYPos;
191 } ME_Row;
192
193 /* the display item list layout is like this:
194  * - the document consists of paragraphs
195  * - each paragraph contains at least one run, the last run in the paragraph
196  *   is an end-of-paragraph run
197  * - each formatted paragraph contains at least one row, which corresponds
198  *   to a screen line (that's why there are no rows in an unformatted
199  *   paragraph
200  * - the paragraphs contain "shortcut" pointers to the previous and the next
201  *   paragraph, that makes iteration over paragraphs faster 
202  * - the list starts with diTextStart and ends with diTextEnd
203  */
204
205 typedef struct tagME_DisplayItem
206 {
207   ME_DIType type;
208   struct tagME_DisplayItem *prev, *next;
209   union {
210     ME_Run run;
211     ME_Row row;
212     ME_Paragraph para;
213     ME_Document doc; /* not used */
214     ME_Style *ustyle; /* used by diUndoSetCharFormat */
215   } member;
216 } ME_DisplayItem;
217
218 typedef struct tagME_UndoItem
219 {
220   ME_DisplayItem di;
221   int nStart, nLen;
222   int nCR, nLF;      /* used by diUndoSplitParagraph */
223 } ME_UndoItem;
224
225 typedef struct tagME_TextBuffer
226 {
227   ME_DisplayItem *pFirst, *pLast;
228   ME_Style *pCharStyle;
229   ME_Style *pDefaultStyle;
230 } ME_TextBuffer;
231
232 typedef struct tagME_Cursor
233 {
234   ME_DisplayItem *pRun;
235   int nOffset;
236 } ME_Cursor;
237
238 typedef enum {
239   umAddToUndo,
240   umAddToRedo,
241   umIgnore,
242   umAddBackToUndo
243 } ME_UndoMode;
244
245 typedef enum {
246   stPosition = 0,
247   stWord,
248   stLine,
249   stParagraph,
250   stDocument
251 } ME_SelectionType;
252
253 typedef struct tagME_FontTableItem {
254   BYTE bCharSet;
255   WCHAR *szFaceName;
256 } ME_FontTableItem;
257
258
259 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
260
261 struct tagME_InStream {
262   EDITSTREAM *editstream;
263   DWORD dwSize;
264   DWORD dwUsed;
265   char buffer[STREAMIN_BUFFER_SIZE];
266 };
267 typedef struct tagME_InStream ME_InStream;
268
269
270 #define STREAMOUT_BUFFER_SIZE 4096
271 #define STREAMOUT_FONTTBL_SIZE 8192
272 #define STREAMOUT_COLORTBL_SIZE 1024
273
274 typedef struct tagME_OutStream {
275   EDITSTREAM *stream;
276   char buffer[STREAMOUT_BUFFER_SIZE];
277   UINT pos, written;
278   UINT nCodePage;
279   UINT nFontTblLen;
280   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
281   UINT nColorTblLen;
282   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
283   UINT nDefaultFont;
284   UINT nDefaultCodePage;
285 } ME_OutStream;
286
287 typedef struct tagME_FontCacheItem
288 {
289   LOGFONTW lfSpecs;
290   HFONT hFont;
291   int nRefs;
292   int nAge;
293 } ME_FontCacheItem;
294
295 #define HFONT_CACHE_SIZE 10
296
297 typedef struct tagME_TextEditor
298 {
299   HWND hWnd;
300   BOOL bEmulateVersion10;
301   ME_TextBuffer *pBuffer;
302   ME_Cursor *pCursors;
303   int nCursors;
304   SIZE sizeWindow;
305   int nTotalLength, nLastTotalLength;
306   int nHeight;
307   int nUDArrowX;
308   int nSequence;
309   COLORREF rgbBackColor;
310   HBRUSH hbrBackground;
311   BOOL bCaretAtEnd;
312   int nEventMask;
313   int nModifyStep;
314   ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
315   int nUndoStackSize;
316   int nUndoLimit;
317   ME_UndoMode nUndoMode;
318   int nParagraphs;
319   int nLastSelStart, nLastSelEnd;
320   ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
321   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
322   int nZoomNumerator, nZoomDenominator;
323   RECT rcFormat;
324   BOOL bRedraw;
325   BOOL bWordWrap;
326   int nInvalidOfs;
327   int nTextLimit;
328   EDITWORDBREAKPROCW pfnWordBreak;
329   LPRICHEDITOLECALLBACK lpOleCallback;
330   /*TEXTMODE variable; contains only one of each of the following options:
331    *TM_RICHTEXT or TM_PLAINTEXT
332    *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
333    *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
334   int mode;
335   BOOL bHideSelection;
336   BOOL AutoURLDetect_bEnable;
337   WCHAR cPasswordMask;
338   BOOL bHaveFocus;
339   /*for IME */
340   int imeStartIndex;
341   DWORD selofs; /* The size of the selection bar on the left side of control */
342   ME_SelectionType nSelectionType;
343
344   /* Track previous notified selection */
345   CHARRANGE notified_cr;
346 } ME_TextEditor;
347
348 typedef struct tagME_Context
349 {
350   HDC hDC;
351   POINT pt;
352   POINT ptRowOffset;
353   RECT rcView;
354   HBRUSH hbrMargin;
355   SIZE dpi;
356
357   /* those are valid inside ME_WrapTextParagraph and related */
358   POINT ptFirstRun;
359   ME_TextEditor *editor;
360   int nSequence;
361 } ME_Context;
362
363 typedef struct tagME_WrapContext
364 {
365   ME_Style *style;
366   ME_Context *context;
367   int nLeftMargin, nRightMargin, nFirstMargin;
368   int nAvailWidth;
369   int nRow;
370   POINT pt;
371   BOOL bOverflown;
372   ME_DisplayItem *pRowStart;
373   
374   ME_DisplayItem *pLastSplittableRun;
375   POINT ptLastSplittableRun;
376 } ME_WrapContext;  
377
378 #endif