riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / riched20 / editstr.h
blob57d7fef44fe84dd4eb3fd2b7205bedb022b26c49
1 /*
2 * RichEdit - structures and constant
4 * Copyright 2004 by Krzysztof Foltman
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.
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.
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
21 #ifndef __EDITSTR_H
22 #define __EDITSTR_H
24 #ifndef _WIN32_IE
25 #define _WIN32_IE 0x0400
26 #endif
28 #include <assert.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <limits.h>
34 #define COBJMACROS
36 #include <windef.h>
37 #include <winbase.h>
38 #include <winnls.h>
39 #include <winnt.h>
40 #include <wingdi.h>
41 #include <winuser.h>
42 #include <richedit.h>
43 #include <commctrl.h>
44 #include <ole2.h>
45 #include <richole.h>
46 #include "imm.h"
47 #include <textserv.h>
48 #include "usp10.h"
50 #include "wine/debug.h"
51 #include "wine/list.h"
53 #ifdef __i386__
54 extern const struct ITextHostVtbl itextHostStdcallVtbl DECLSPEC_HIDDEN;
55 #endif /* __i386__ */
57 typedef struct tagME_String
59 WCHAR *szData;
60 int nLen, nBuffer;
61 } ME_String;
63 typedef struct tagME_Style
65 CHARFORMAT2W fmt;
67 HFONT hFont; /* cached font for the style */
68 TEXTMETRICW tm; /* cached font metrics for the style */
69 int nRefs; /* reference count */
70 SCRIPT_CACHE script_cache;
71 } ME_Style;
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 */
82 /********************* these below are meant for finding only *********************/
83 diStartRowOrParagraph, /* 7 */
84 diStartRowOrParagraphOrEnd,
85 diRunOrParagraph,
86 diRunOrStartRow,
87 diParagraphOrEnd,
88 diRunOrParagraphOrEnd, /* 12 */
89 } ME_DIType;
91 #define SELECTIONBAR_WIDTH 8
93 /******************************** run flags *************************/
94 #define MERF_STYLEFLAGS 0x0FFF
95 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
96 #define MERF_GRAPHICS 0x001
97 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
98 #define MERF_TAB 0x002
99 /* run is a cell boundary */
100 #define MERF_ENDCELL 0x004 /* v4.1 */
102 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
104 /* run is splittable (contains white spaces in the middle or end) */
105 #define MERF_SPLITTABLE 0x001000
106 /* run starts with whitespaces */
107 #define MERF_STARTWHITE 0x002000
108 /* run ends with whitespaces */
109 #define MERF_ENDWHITE 0x004000
110 /* run is completely made of whitespaces */
111 #define MERF_WHITESPACE 0x008000
112 /* the "end of paragraph" run, contains 1 character */
113 #define MERF_ENDPARA 0x100000
114 /* forcing the "end of row" run, contains 1 character */
115 #define MERF_ENDROW 0x200000
116 /* run is hidden */
117 #define MERF_HIDDEN 0x400000
118 /* start of a table row has an empty paragraph that should be skipped over. */
119 #define MERF_TABLESTART 0x800000 /* v4.1 */
121 /* runs with any of these flags set cannot be joined */
122 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
123 /* runs that don't contain real text */
124 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
126 /* those flags are kept when the row is split */
127 #define MERF_SPLITMASK (~(0))
129 /******************************** para flags *************************/
131 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
132 #define MEPF_REWRAP 0x01
133 /* v4.1 */
134 #define MEPF_CELL 0x04 /* The paragraph is nested in a cell */
135 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
136 #define MEPF_ROWEND 0x10 /* Visible empty paragraph at the end of the row */
137 #define MEPF_COMPLEX 0x20 /* Use uniscribe */
139 /******************************** structures *************************/
141 struct tagME_DisplayItem;
143 typedef struct tagME_Run
145 ME_Style *style;
146 struct tagME_Paragraph *para; /* ptr to the run's paragraph */
147 int nCharOfs; /* relative to para's offset */
148 int len; /* length of run's text */
149 int nWidth; /* width of full run, width of leading&trailing ws */
150 int nFlags;
151 int nAscent, nDescent; /* pixels above/below baseline */
152 POINT pt; /* relative to para's position */
153 REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
155 SCRIPT_ANALYSIS script_analysis;
156 int num_glyphs, max_glyphs;
157 WORD *glyphs;
158 SCRIPT_VISATTR *vis_attrs;
159 int *advances;
160 GOFFSET *offsets;
161 int max_clusters;
162 WORD *clusters;
163 } ME_Run;
165 typedef struct tagME_Border
167 int width;
168 COLORREF colorRef;
169 } ME_Border;
171 typedef struct tagME_BorderRect
173 ME_Border top;
174 ME_Border left;
175 ME_Border bottom;
176 ME_Border right;
177 } ME_BorderRect;
179 typedef struct tagME_Paragraph
181 PARAFORMAT2 *pFmt;
182 ME_String *text;
184 struct tagME_DisplayItem *pCell; /* v4.1 */
185 ME_BorderRect border;
187 int nCharOfs;
188 int nFlags;
189 POINT pt;
190 int nHeight, nWidth;
191 int nRows;
192 struct tagME_DisplayItem *prev_para, *next_para;
193 } ME_Paragraph;
195 typedef struct tagME_Cell /* v4.1 */
197 int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
198 int nRightBoundary;
199 ME_BorderRect border;
200 POINT pt;
201 int nHeight, nWidth;
202 int yTextOffset; /* The text offset is caused by the largest top border. */
203 struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
204 } ME_Cell;
206 typedef struct tagME_Row
208 int nHeight;
209 int nBaseline;
210 int nWidth;
211 int nLMargin;
212 int nRMargin;
213 POINT pt;
214 } ME_Row;
216 /* the display item list layout is like this:
217 * - the document consists of paragraphs
218 * - each paragraph contains at least one run, the last run in the paragraph
219 * is an end-of-paragraph run
220 * - each formatted paragraph contains at least one row, which corresponds
221 * to a screen line (that's why there are no rows in an unformatted
222 * paragraph
223 * - the paragraphs contain "shortcut" pointers to the previous and the next
224 * paragraph, that makes iteration over paragraphs faster
225 * - the list starts with diTextStart and ends with diTextEnd
228 typedef struct tagME_DisplayItem
230 ME_DIType type;
231 struct tagME_DisplayItem *prev, *next;
232 union {
233 ME_Run run;
234 ME_Row row;
235 ME_Cell cell;
236 ME_Paragraph para;
237 } member;
238 } ME_DisplayItem;
240 typedef struct tagME_TextBuffer
242 ME_DisplayItem *pFirst, *pLast;
243 ME_Style *pCharStyle;
244 ME_Style *pDefaultStyle;
245 } ME_TextBuffer;
247 typedef struct tagME_Cursor
249 ME_DisplayItem *pPara;
250 ME_DisplayItem *pRun;
251 int nOffset;
252 } ME_Cursor;
254 typedef enum {
255 umAddToUndo,
256 umAddToRedo,
257 umIgnore,
258 umAddBackToUndo
259 } ME_UndoMode;
261 enum undo_type
263 undo_insert_run,
264 undo_delete_run,
265 undo_join_paras,
266 undo_split_para,
267 undo_set_para_fmt,
268 undo_set_char_fmt,
269 undo_end_transaction, /* marks the end of a group of changes for undo */
270 undo_potential_end_transaction /* allows grouping typed chars for undo */
273 struct insert_run_item
275 int pos, len;
276 WCHAR *str;
277 ME_Style *style;
278 DWORD flags;
281 struct delete_run_item
283 int pos, len;
286 struct join_paras_item
288 int pos;
291 struct split_para_item
293 int pos;
294 PARAFORMAT2 fmt;
295 ME_BorderRect border;
296 ME_String *eol_str;
297 DWORD flags;
298 ME_BorderRect cell_border;
299 int cell_right_boundary;
302 struct set_para_fmt_item
304 int pos;
305 PARAFORMAT2 fmt;
306 ME_BorderRect border;
309 struct set_char_fmt_item
311 int pos, len;
312 CHARFORMAT2W fmt;
315 struct undo_item
317 struct list entry;
318 enum undo_type type;
319 union
321 struct insert_run_item insert_run;
322 struct delete_run_item delete_run;
323 struct join_paras_item join_paras;
324 struct split_para_item split_para;
325 struct set_para_fmt_item set_para_fmt;
326 struct set_char_fmt_item set_char_fmt;
327 } u;
330 typedef enum {
331 stPosition = 0,
332 stWord,
333 stLine,
334 stParagraph,
335 stDocument
336 } ME_SelectionType;
338 typedef struct tagME_FontTableItem {
339 BYTE bCharSet;
340 WCHAR *szFaceName;
341 } ME_FontTableItem;
344 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
346 struct tagME_InStream {
347 EDITSTREAM *editstream;
348 DWORD dwSize;
349 DWORD dwUsed;
350 char buffer[STREAMIN_BUFFER_SIZE];
352 typedef struct tagME_InStream ME_InStream;
355 #define STREAMOUT_BUFFER_SIZE 4096
356 #define STREAMOUT_FONTTBL_SIZE 8192
357 #define STREAMOUT_COLORTBL_SIZE 1024
359 typedef struct tagME_OutStream {
360 EDITSTREAM *stream;
361 char buffer[STREAMOUT_BUFFER_SIZE];
362 UINT pos, written;
363 UINT nCodePage;
364 UINT nFontTblLen;
365 ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
366 UINT nColorTblLen;
367 COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
368 UINT nDefaultFont;
369 UINT nDefaultCodePage;
370 /* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
371 * an greater numbers mean we are in a cell nested within a cell. */
372 UINT nNestingLevel;
373 } ME_OutStream;
375 typedef struct tagME_FontCacheItem
377 LOGFONTW lfSpecs;
378 HFONT hFont;
379 int nRefs;
380 int nAge;
381 } ME_FontCacheItem;
383 #define HFONT_CACHE_SIZE 10
385 typedef struct tagME_TextEditor
387 HWND hWnd, hwndParent;
388 ITextHost *texthost;
389 IRichEditOle *reOle;
390 BOOL bEmulateVersion10;
391 ME_TextBuffer *pBuffer;
392 ME_Cursor *pCursors;
393 DWORD styleFlags;
394 DWORD exStyleFlags;
395 int nCursors;
396 SIZE sizeWindow;
397 int nTotalLength, nLastTotalLength;
398 int nTotalWidth, nLastTotalWidth;
399 int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
400 int nUDArrowX;
401 COLORREF rgbBackColor;
402 HBRUSH hbrBackground;
403 BOOL bCaretAtEnd;
404 int nEventMask;
405 int nModifyStep;
406 struct list undo_stack;
407 struct list redo_stack;
408 int nUndoStackSize;
409 int nUndoLimit;
410 ME_UndoMode nUndoMode;
411 int nParagraphs;
412 int nLastSelStart, nLastSelEnd;
413 ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
414 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
415 int nZoomNumerator, nZoomDenominator;
416 RECT prevClientRect;
417 RECT rcFormat;
418 BOOL bDefaultFormatRect;
419 BOOL bWordWrap;
420 int nTextLimit;
421 EDITWORDBREAKPROCW pfnWordBreak;
422 LPRICHEDITOLECALLBACK lpOleCallback;
423 /*TEXTMODE variable; contains only one of each of the following options:
424 *TM_RICHTEXT or TM_PLAINTEXT
425 *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
426 *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
427 int mode;
428 BOOL bHideSelection;
429 BOOL AutoURLDetect_bEnable;
430 WCHAR cPasswordMask;
431 BOOL bHaveFocus;
432 BOOL bDialogMode; /* Indicates that we are inside a dialog window */
433 /*for IME */
434 int imeStartIndex;
435 DWORD selofs; /* The size of the selection bar on the left side of control */
436 ME_SelectionType nSelectionType;
438 /* Track previous notified selection */
439 CHARRANGE notified_cr;
441 /* Cache previously set scrollbar info */
442 SCROLLINFO vert_si, horz_si;
444 BOOL bMouseCaptured;
445 int wheel_remain;
446 } ME_TextEditor;
448 typedef struct tagME_Context
450 HDC hDC;
451 POINT pt;
452 RECT rcView;
453 SIZE dpi;
454 int nAvailWidth;
456 /* those are valid inside ME_WrapTextParagraph and related */
457 ME_TextEditor *editor;
458 } ME_Context;
460 typedef struct tagME_WrapContext
462 ME_Style *style;
463 ME_Context *context;
464 int nLeftMargin, nRightMargin, nFirstMargin;
465 int nAvailWidth;
466 int nRow;
467 POINT pt;
468 BOOL bOverflown, bWordWrap;
469 ME_DisplayItem *pPara;
470 ME_DisplayItem *pRowStart;
472 ME_DisplayItem *pLastSplittableRun;
473 } ME_WrapContext;
475 #endif