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