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