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