riched20: Implement EM_AUTOURLDETECT & EM_GETAUTOURLDETECT.
[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 #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   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 */
72   
73   /********************* these below are meant for finding only *********************/
74   diStartRowOrParagraph, /* 5 */
75   diStartRowOrParagraphOrEnd,
76   diRunOrParagraph,
77   diRunOrStartRow,
78   diParagraphOrEnd,
79   diRunOrParagraphOrEnd, /* 10 */
80   
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;
90
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
99
100 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_CELL)
101
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
118
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)
123
124 /* those flags are kept when the row is split */
125 #define MERF_SPLITMASK (~(0))
126
127 /******************************** para flags *************************/
128
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
132
133 /******************************** structures *************************/
134
135 struct tagME_DisplayItem;
136
137 typedef struct tagME_Run
138 {
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;
148
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;
154
155 typedef struct tagME_TableCell
156 {
157   int nRightBoundary;
158   struct tagME_TableCell *next;
159 } ME_TableCell;
160
161 typedef struct tagME_Paragraph
162 {
163   PARAFORMAT2 *pFmt;
164   
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 */
168
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;
177
178 typedef struct tagME_Row
179 {
180   int nHeight;
181   int nBaseline;
182   int nWidth;
183   int nLMargin;
184   int nRMargin;
185   int nYPos;
186 } ME_Row;
187
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
198  */
199
200 typedef struct tagME_DisplayItem
201 {
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;
212
213 typedef struct tagME_UndoItem
214 {
215   ME_DisplayItem di;
216   int nStart, nLen;
217 } ME_UndoItem;
218
219 typedef struct tagME_TextBuffer
220 {
221   ME_DisplayItem *pFirst, *pLast;
222   ME_Style *pCharStyle;
223   ME_Style *pDefaultStyle;
224 } ME_TextBuffer;
225
226 typedef struct tagME_Cursor
227 {
228   ME_DisplayItem *pRun;
229   int nOffset;
230 } ME_Cursor;
231
232 typedef enum {
233   umAddToUndo,
234   umAddToRedo,
235   umIgnore,
236   umAddBackToUndo
237 } ME_UndoMode;
238
239 typedef struct tagME_FontTableItem {
240   BYTE bCharSet;
241   WCHAR *szFaceName;
242 } ME_FontTableItem;
243
244
245 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
246
247 struct tagME_InStream {
248   EDITSTREAM *editstream;
249   DWORD dwSize;
250   DWORD dwUsed;
251   char buffer[STREAMIN_BUFFER_SIZE];
252 };
253 typedef struct tagME_InStream ME_InStream;
254
255
256 #define STREAMOUT_BUFFER_SIZE 4096
257 #define STREAMOUT_FONTTBL_SIZE 8192
258 #define STREAMOUT_COLORTBL_SIZE 1024
259
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;
272
273 typedef struct tagME_FontCacheItem
274 {
275   LOGFONTW lfSpecs;
276   HFONT hFont;
277   int nRefs;
278   int nAge;
279 } ME_FontCacheItem;
280
281 #define HFONT_CACHE_SIZE 10
282
283 typedef struct tagME_TextEditor
284 {
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;
302   ME_UndoMode nUndoMode;
303   int nParagraphs;
304   int nLastSelStart, nLastSelEnd;
305   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
306   BOOL bScrollX, bScrollY;
307   int nScrollPosY;
308   int nZoomNumerator, nZoomDenominator;
309   RECT rcFormat;
310   BOOL bRedraw;
311   int nInvalidOfs;
312   EDITWORDBREAKPROCW pfnWordBreak;
313   LPRICHEDITOLECALLBACK lpOleCallback;
314   /*TEXTMODE variable; contains only one of each of the following options:
315    *TM_RICHTEXT or TM_PLAINTEXT
316    *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
317    *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
318   int mode;
319   BOOL bHideSelection;
320   BOOL AutoURLDetect_bEnable;
321 } ME_TextEditor;
322
323 typedef struct tagME_Context
324 {
325   HDC hDC;
326   POINT pt;
327   POINT ptRowOffset;
328   RECT rcView;
329   HBRUSH hbrMargin;
330
331   /* those are valid inside ME_WrapTextParagraph and related */
332   POINT ptFirstRun;
333   ME_TextEditor *editor;
334   int nSequence;
335 } ME_Context;
336
337 typedef struct tagME_WrapContext
338 {
339   ME_Style *style;
340   ME_Context *context;
341   int nLeftMargin, nRightMargin, nFirstMargin;
342   int nTotalWidth, nAvailWidth;
343   int nRow;
344   POINT pt;
345   BOOL bOverflown;
346   ME_DisplayItem *pRowStart;
347   
348   ME_DisplayItem *pLastSplittableRun;
349   POINT ptLastSplittableRun;
350 } ME_WrapContext;  
351
352 #endif