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