ddraw: Get rid of ddcomimpl.h.
[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 #include "imm.h"
48 #include <textserv.h>
49
50 #include "wine/debug.h"
51
52 #ifdef __i386__
53 extern struct ITextHostVtbl itextHostStdcallVtbl;
54 #endif /* __i386__ */
55
56 typedef struct tagME_String
57 {
58   WCHAR *szData;
59   int nLen, nBuffer;
60 } ME_String;
61
62 typedef struct tagME_Style
63 {
64   CHARFORMAT2W fmt;
65
66   HFONT hFont; /* cached font for the style */
67   TEXTMETRICW tm; /* cached font metrics for the style */
68   int nRefs; /* reference count */
69   int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
70 } ME_Style;
71
72 typedef enum {
73   diInvalid,
74   diTextStart, /* start of the text buffer */
75   diParagraph, /* paragraph start */
76   diCell, /* cell start */
77   diRun, /* run (sequence of chars with the same character format) */
78   diStartRow, /* start of the row (line of text on the screen) */
79   diTextEnd, /* end of the text buffer */
80   
81   /********************* these below are meant for finding only *********************/
82   diStartRowOrParagraph, /* 7 */
83   diStartRowOrParagraphOrEnd,
84   diRunOrParagraph,
85   diRunOrStartRow,
86   diParagraphOrEnd,
87   diRunOrParagraphOrEnd, /* 12 */
88   
89   diUndoInsertRun, /* 13 */
90   diUndoDeleteRun, /* 14 */
91   diUndoJoinParagraphs, /* 15 */
92   diUndoSplitParagraph, /* 16 */
93   diUndoSetParagraphFormat, /* 17 */
94   diUndoSetCharFormat, /* 18 */
95   diUndoEndTransaction, /* 19 - marks the end of a group of changes for undo */
96   diUndoPotentialEndTransaction, /* 20 - allows grouping typed chars for undo */
97 } ME_DIType;
98
99 #define SELECTIONBAR_WIDTH 8
100
101 /******************************** run flags *************************/
102 #define MERF_STYLEFLAGS 0x0FFF
103 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
104 #define MERF_GRAPHICS   0x001
105 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
106 #define MERF_TAB        0x002
107 /* run is a cell boundary */
108 #define MERF_ENDCELL    0x004 /* v4.1 */
109
110 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
111
112 /* run is splittable (contains white spaces in the middle or end) */
113 #define MERF_SPLITTABLE 0x001000
114 /* run starts with whitespaces */
115 #define MERF_STARTWHITE 0x002000
116 /* run ends with whitespaces */
117 #define MERF_ENDWHITE   0x004000
118 /* run is completely made of whitespaces */
119 #define MERF_WHITESPACE 0x008000
120 /* run is a last (dummy) run in the paragraph */
121 #define MERF_SKIPPED    0x010000
122 /* flags that are calculated during text wrapping */
123 #define MERF_CALCBYWRAP 0x0F0000
124 /* the "end of paragraph" run, contains 1 character */
125 #define MERF_ENDPARA    0x100000
126 /* forcing the "end of row" run, contains 1 character */
127 #define MERF_ENDROW     0x200000
128 /* run is hidden */
129 #define MERF_HIDDEN     0x400000
130 /* start of a table row has an empty paragraph that should be skipped over. */
131 #define MERF_TABLESTART 0x800000 /* v4.1 */
132
133 /* runs with any of these flags set cannot be joined */
134 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
135 /* runs that don't contain real text */
136 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
137
138 /* those flags are kept when the row is split */
139 #define MERF_SPLITMASK (~(0))
140
141 /******************************** para flags *************************/
142
143 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
144 #define MEPF_REWRAP   0x01
145 #define MEPF_REPAINT  0x02
146 /* v4.1 */
147 #define MEPF_CELL     0x04 /* The paragraph is nested in a cell */
148 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
149 #define MEPF_ROWEND   0x10 /* Visible empty paragraph at the end of the row */
150
151 /******************************** structures *************************/
152
153 struct tagME_DisplayItem;
154
155 typedef struct tagME_Run
156 {
157   ME_String *strText;
158   ME_Style *style;
159   int nCharOfs; /* relative to para's offset */
160   int nWidth; /* width of full run, width of leading&trailing ws */
161   int nFlags;
162   int nAscent, nDescent; /* pixels above/below baseline */
163   POINT pt; /* relative to para's position */
164   REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
165   int nCR; int nLF;  /* for MERF_ENDPARA: number of \r and \n characters encoded by run */
166 } ME_Run;
167
168 typedef struct tagME_Document {
169   struct tagME_DisplayItem *def_char_style;
170   struct tagME_DisplayItem *def_para_style;
171   int last_wrapped_line;
172 } ME_Document;
173
174 typedef struct tagME_Border
175 {
176   int width;
177   COLORREF colorRef;
178 } ME_Border;
179
180 typedef struct tagME_BorderRect
181 {
182   ME_Border top;
183   ME_Border left;
184   ME_Border bottom;
185   ME_Border right;
186 } ME_BorderRect;
187
188 typedef struct tagME_Paragraph
189 {
190   PARAFORMAT2 *pFmt;
191
192   struct tagME_DisplayItem *pCell; /* v4.1 */
193   ME_BorderRect border;
194
195   int nCharOfs;
196   int nFlags;
197   POINT pt;
198   int nHeight, nWidth;
199   int nLastPaintYPos, nLastPaintHeight;
200   int nRows;
201   struct tagME_DisplayItem *prev_para, *next_para, *document;
202 } ME_Paragraph;
203
204 typedef struct tagME_Cell /* v4.1 */
205 {
206   int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
207   int nRightBoundary;
208   ME_BorderRect border;
209   POINT pt;
210   int nHeight, nWidth;
211   int yTextOffset; /* The text offset is caused by the largest top border. */
212   struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
213 } ME_Cell;
214
215 typedef struct tagME_Row
216 {
217   int nHeight;
218   int nBaseline;
219   int nWidth;
220   int nLMargin;
221   int nRMargin;
222   POINT pt;
223 } ME_Row;
224
225 /* the display item list layout is like this:
226  * - the document consists of paragraphs
227  * - each paragraph contains at least one run, the last run in the paragraph
228  *   is an end-of-paragraph run
229  * - each formatted paragraph contains at least one row, which corresponds
230  *   to a screen line (that's why there are no rows in an unformatted
231  *   paragraph
232  * - the paragraphs contain "shortcut" pointers to the previous and the next
233  *   paragraph, that makes iteration over paragraphs faster 
234  * - the list starts with diTextStart and ends with diTextEnd
235  */
236
237 typedef struct tagME_DisplayItem
238 {
239   ME_DIType type;
240   struct tagME_DisplayItem *prev, *next;
241   union {
242     ME_Run run;
243     ME_Row row;
244     ME_Cell cell;
245     ME_Paragraph para;
246     ME_Document doc; /* not used */
247     ME_Style *ustyle; /* used by diUndoSetCharFormat */
248   } member;
249 } ME_DisplayItem;
250
251 typedef struct tagME_UndoItem
252 {
253   ME_DisplayItem di;
254   int nStart, nLen;
255   int nCR, nLF;      /* used by diUndoSplitParagraph */
256 } ME_UndoItem;
257
258 typedef struct tagME_TextBuffer
259 {
260   ME_DisplayItem *pFirst, *pLast;
261   ME_Style *pCharStyle;
262   ME_Style *pDefaultStyle;
263 } ME_TextBuffer;
264
265 typedef struct tagME_Cursor
266 {
267   ME_DisplayItem *pRun;
268   int nOffset;
269 } ME_Cursor;
270
271 typedef enum {
272   umAddToUndo,
273   umAddToRedo,
274   umIgnore,
275   umAddBackToUndo
276 } ME_UndoMode;
277
278 typedef enum {
279   stPosition = 0,
280   stWord,
281   stLine,
282   stParagraph,
283   stDocument
284 } ME_SelectionType;
285
286 typedef struct tagME_FontTableItem {
287   BYTE bCharSet;
288   WCHAR *szFaceName;
289 } ME_FontTableItem;
290
291
292 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
293
294 struct tagME_InStream {
295   EDITSTREAM *editstream;
296   DWORD dwSize;
297   DWORD dwUsed;
298   char buffer[STREAMIN_BUFFER_SIZE];
299 };
300 typedef struct tagME_InStream ME_InStream;
301
302
303 #define STREAMOUT_BUFFER_SIZE 4096
304 #define STREAMOUT_FONTTBL_SIZE 8192
305 #define STREAMOUT_COLORTBL_SIZE 1024
306
307 typedef struct tagME_OutStream {
308   EDITSTREAM *stream;
309   char buffer[STREAMOUT_BUFFER_SIZE];
310   UINT pos, written;
311   UINT nCodePage;
312   UINT nFontTblLen;
313   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
314   UINT nColorTblLen;
315   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
316   UINT nDefaultFont;
317   UINT nDefaultCodePage;
318   /* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
319    * an greater numbers mean we are in a cell nested within a cell. */
320   UINT nNestingLevel;
321 } ME_OutStream;
322
323 typedef struct tagME_FontCacheItem
324 {
325   LOGFONTW lfSpecs;
326   HFONT hFont;
327   int nRefs;
328   int nAge;
329 } ME_FontCacheItem;
330
331 #define HFONT_CACHE_SIZE 10
332
333 typedef struct tagME_TextEditor
334 {
335   HWND hWnd;
336   ITextHost *texthost;
337   BOOL bEmulateVersion10;
338   ME_TextBuffer *pBuffer;
339   ME_Cursor *pCursors;
340   DWORD styleFlags;
341   DWORD exStyleFlags;
342   int nCursors;
343   SIZE sizeWindow;
344   int nTotalLength, nLastTotalLength;
345   int nTotalWidth, nLastTotalWidth;
346   int nUDArrowX;
347   int nSequence;
348   COLORREF rgbBackColor;
349   HBRUSH hbrBackground;
350   BOOL bCaretAtEnd;
351   int nEventMask;
352   int nModifyStep;
353   ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
354   int nUndoStackSize;
355   int nUndoLimit;
356   ME_UndoMode nUndoMode;
357   int nParagraphs;
358   int nLastSelStart, nLastSelEnd;
359   ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
360   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
361   int nZoomNumerator, nZoomDenominator;
362   RECT prevClientRect;
363   RECT rcFormat;
364   BOOL bDefaultFormatRect;
365   BOOL bWordWrap;
366   int nInvalidOfs;
367   int nTextLimit;
368   EDITWORDBREAKPROCW pfnWordBreak;
369   LPRICHEDITOLECALLBACK lpOleCallback;
370   /*TEXTMODE variable; contains only one of each of the following options:
371    *TM_RICHTEXT or TM_PLAINTEXT
372    *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
373    *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
374   int mode;
375   BOOL bHideSelection;
376   BOOL AutoURLDetect_bEnable;
377   WCHAR cPasswordMask;
378   BOOL bHaveFocus;
379   /*for IME */
380   int imeStartIndex;
381   DWORD selofs; /* The size of the selection bar on the left side of control */
382   ME_SelectionType nSelectionType;
383
384   /* Track previous notified selection */
385   CHARRANGE notified_cr;
386
387   /* Cache previously set scrollbar info */
388   SCROLLINFO vert_si, horz_si;
389
390   BOOL bMouseCaptured;
391 } ME_TextEditor;
392
393 typedef struct tagME_Context
394 {
395   HDC hDC;
396   POINT pt;
397   POINT ptRowOffset;
398   RECT rcView;
399   HBRUSH hbrMargin;
400   SIZE dpi;
401
402   /* those are valid inside ME_WrapTextParagraph and related */
403   POINT ptFirstRun;
404   ME_TextEditor *editor;
405   int nSequence;
406 } ME_Context;
407
408 typedef struct tagME_WrapContext
409 {
410   ME_Style *style;
411   ME_Context *context;
412   int nLeftMargin, nRightMargin, nFirstMargin;
413   int nAvailWidth;
414   int nRow;
415   POINT pt;
416   BOOL bOverflown, bWordWrap;
417   ME_DisplayItem *pRowStart;
418   
419   ME_DisplayItem *pLastSplittableRun;
420   POINT ptLastSplittableRun;
421 } ME_WrapContext;  
422
423 #endif