comctl32/tests: Use CRT allocation functions.
[wine.git] / dlls / riched20 / editstr.h
blob1f766a3664658db783a23093ef9f6f575f0e4bf4
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 #include <assert.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <limits.h>
30 #define COBJMACROS
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winnls.h>
35 #include <winnt.h>
36 #include <wingdi.h>
37 #include <winuser.h>
38 #include <richedit.h>
39 #include <commctrl.h>
40 #include <ole2.h>
41 #include <richole.h>
42 #include "imm.h"
43 #include <textserv.h>
44 #include <tom.h>
45 #include "usp10.h"
47 #include "wine/asm.h"
48 #include "wine/debug.h"
49 #include "wine/list.h"
50 #include "wine/rbtree.h"
52 typedef struct tagME_String
54 WCHAR *szData;
55 int nLen, nBuffer;
56 void (*free)(struct tagME_String *);
57 } ME_String;
59 typedef struct tagME_FontCacheItem
61 LOGFONTW lfSpecs;
62 HFONT hFont;
63 int nRefs;
64 int nAge;
65 } ME_FontCacheItem;
67 #define HFONT_CACHE_SIZE 10
69 typedef struct tagME_Style
71 CHARFORMAT2W fmt;
73 ME_FontCacheItem *font_cache; /* cached font for the style */
74 TEXTMETRICW tm; /* cached font metrics for the style */
75 int nRefs; /* reference count */
76 SCRIPT_CACHE script_cache;
77 struct list entry;
78 } ME_Style;
80 typedef enum {
81 diInvalid,
82 diTextStart, /* start of the text buffer */
83 diParagraph, /* paragraph start */
84 diCell, /* cell start */
85 diRun, /* run (sequence of chars with the same character format) */
86 diStartRow, /* start of the row (line of text on the screen) */
87 diTextEnd, /* end of the text buffer */
89 /********************* these below are meant for finding only *********************/
90 diStartRowOrParagraph, /* 7 */
91 diStartRowOrParagraphOrEnd,
92 diRunOrParagraph,
93 diRunOrStartRow,
94 diParagraphOrEnd,
95 diRunOrParagraphOrEnd, /* 12 */
96 } ME_DIType;
98 #define SELECTIONBAR_WIDTH 8
100 /******************************** run flags *************************/
101 #define MERF_STYLEFLAGS 0x0FFF
102 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
103 #define MERF_GRAPHICS 0x001
104 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
105 #define MERF_TAB 0x002
106 /* run is a cell boundary */
107 #define MERF_ENDCELL 0x004 /* v4.1 */
109 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
111 /* run is splittable (contains white spaces in the middle or end) */
112 #define MERF_SPLITTABLE 0x001000
113 /* run starts with whitespaces */
114 #define MERF_STARTWHITE 0x002000
115 /* run ends with whitespaces */
116 #define MERF_ENDWHITE 0x004000
117 /* run is completely made of whitespaces */
118 #define MERF_WHITESPACE 0x008000
119 /* the "end of paragraph" run, contains 1 character */
120 #define MERF_ENDPARA 0x100000
121 /* forcing the "end of row" run, contains 1 character */
122 #define MERF_ENDROW 0x200000
123 /* run is hidden */
124 #define MERF_HIDDEN 0x400000
125 /* start of a table row has an empty paragraph that should be skipped over. */
126 #define MERF_TABLESTART 0x800000 /* v4.1 */
128 /* runs with any of these flags set cannot be joined */
129 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
130 /* runs that don't contain real text */
131 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
133 /* those flags are kept when the row is split */
134 #define MERF_SPLITMASK (~(0))
136 /******************************** para flags *************************/
138 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
139 #define MEPF_REWRAP 0x01
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 #define MEPF_COMPLEX 0x20 /* Use uniscribe */
146 /******************************** structures *************************/
148 struct tagME_DisplayItem;
149 struct tagME_Run;
151 struct re_object
153 struct list entry;
154 REOBJECT obj;
155 struct tagME_Run *run; /* ptr to the reobj's run */
158 typedef struct tagME_Run
160 ME_Style *style;
161 struct tagME_Paragraph *para; /* ptr to the run's paragraph */
162 int nCharOfs; /* relative to para's offset */
163 int len; /* length of run's text */
164 int nWidth; /* width of full run, width of leading&trailing ws */
165 int nFlags;
166 int nAscent, nDescent; /* pixels above/below baseline */
167 POINT pt; /* relative to para's position */
168 struct re_object *reobj; /* FIXME: should be a union with strText (at least) */
170 SCRIPT_ANALYSIS script_analysis;
171 int num_glyphs, max_glyphs;
172 WORD *glyphs;
173 SCRIPT_VISATTR *vis_attrs;
174 int *advances;
175 GOFFSET *offsets;
176 int max_clusters;
177 WORD *clusters;
178 } ME_Run;
180 typedef struct tagME_Border
182 int width;
183 COLORREF colorRef;
184 } ME_Border;
186 typedef struct tagME_BorderRect
188 ME_Border top;
189 ME_Border left;
190 ME_Border bottom;
191 ME_Border right;
192 } ME_BorderRect;
194 struct para_num
196 ME_Style *style;
197 ME_String *text;
198 INT width;
199 POINT pt;
202 typedef struct tagME_Paragraph
204 PARAFORMAT2 fmt;
205 ME_String *text;
207 struct tagME_Cell *cell; /* v4.1 */
208 ME_BorderRect border;
210 int nCharOfs;
211 int nFlags;
212 POINT pt;
213 int nHeight, nWidth;
214 int nRows;
215 struct para_num para_num;
216 ME_Run *eop_run; /* ptr to the end-of-para run */
217 struct tagME_DisplayItem *prev_para, *next_para;
218 struct wine_rb_entry marked_entry;
219 } ME_Paragraph;
221 typedef struct tagME_Cell /* v4.1 */
223 int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
224 int nRightBoundary;
225 ME_BorderRect border;
226 POINT pt;
227 int nHeight, nWidth;
228 int yTextOffset; /* The text offset is caused by the largest top border. */
229 struct tagME_Cell *prev_cell, *next_cell, *parent_cell;
230 } ME_Cell;
232 typedef struct tagME_Row
234 int nHeight;
235 int nBaseline;
236 int nWidth;
237 int nLMargin;
238 int nRMargin;
239 POINT pt;
240 } ME_Row;
242 /* the display item list layout is like this:
243 * - the document consists of paragraphs
244 * - each paragraph contains at least one run, the last run in the paragraph
245 * is an end-of-paragraph run
246 * - each formatted paragraph contains at least one row, which corresponds
247 * to a screen line (that's why there are no rows in an unformatted
248 * paragraph
249 * - the paragraphs contain "shortcut" pointers to the previous and the next
250 * paragraph, that makes iteration over paragraphs faster
251 * - the list starts with diTextStart and ends with diTextEnd
254 typedef struct tagME_DisplayItem
256 ME_DIType type;
257 struct tagME_DisplayItem *prev, *next;
258 union {
259 ME_Run run;
260 ME_Row row;
261 ME_Cell cell;
262 ME_Paragraph para;
263 } member;
264 } ME_DisplayItem;
266 typedef struct tagME_TextBuffer
268 ME_DisplayItem *pFirst, *pLast;
269 ME_Style *pCharStyle;
270 ME_Style *pDefaultStyle;
271 } ME_TextBuffer;
273 typedef struct tagME_Cursor
275 ME_Paragraph *para;
276 ME_Run *run;
277 int nOffset;
278 } ME_Cursor;
280 typedef enum {
281 umAddToUndo,
282 umAddToRedo,
283 umIgnore,
284 umAddBackToUndo
285 } ME_UndoMode;
287 typedef enum {
288 undoActive,
289 undoSuspended,
290 undoDisabled
291 } ME_UndoControlState;
293 enum undo_type
295 undo_insert_run,
296 undo_delete_run,
297 undo_join_paras,
298 undo_split_para,
299 undo_set_para_fmt,
300 undo_set_char_fmt,
301 undo_end_transaction, /* marks the end of a group of changes for undo */
302 undo_potential_end_transaction /* allows grouping typed chars for undo */
305 struct insert_run_item
307 int pos, len;
308 WCHAR *str;
309 ME_Style *style;
310 DWORD flags;
313 struct delete_run_item
315 int pos, len;
318 struct join_paras_item
320 int pos;
323 struct split_para_item
325 int pos;
326 PARAFORMAT2 fmt;
327 ME_BorderRect border;
328 ME_String *eol_str;
329 DWORD flags;
330 ME_BorderRect cell_border;
331 int cell_right_boundary;
334 struct set_para_fmt_item
336 int pos;
337 PARAFORMAT2 fmt;
338 ME_BorderRect border;
341 struct set_char_fmt_item
343 int pos, len;
344 CHARFORMAT2W fmt;
347 struct undo_item
349 struct list entry;
350 enum undo_type type;
351 union
353 struct insert_run_item insert_run;
354 struct delete_run_item delete_run;
355 struct join_paras_item join_paras;
356 struct split_para_item split_para;
357 struct set_para_fmt_item set_para_fmt;
358 struct set_char_fmt_item set_char_fmt;
359 } u;
362 typedef enum {
363 stPosition = 0,
364 stWord,
365 stLine,
366 stParagraph,
367 stDocument
368 } ME_SelectionType;
370 typedef struct tagME_FontTableItem {
371 BYTE bCharSet;
372 WCHAR *szFaceName;
373 } ME_FontTableItem;
376 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
378 struct tagME_InStream {
379 EDITSTREAM *editstream;
380 DWORD dwSize;
381 DWORD dwUsed;
382 char buffer[STREAMIN_BUFFER_SIZE];
384 typedef struct tagME_InStream ME_InStream;
386 typedef struct tagME_TextEditor
388 ITextHost2 *texthost;
389 unsigned int bEmulateVersion10 : 1;
390 unsigned int in_place_active : 1;
391 unsigned int have_texthost2 : 1;
392 ME_TextBuffer *pBuffer;
393 ME_Cursor *pCursors;
394 DWORD props;
395 DWORD scrollbars;
396 int nCursors;
397 SIZE sizeWindow;
398 int nTotalLength, nLastTotalLength;
399 int nTotalWidth, nLastTotalWidth;
400 int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
401 int nUDArrowX;
402 int total_rows;
403 int nEventMask;
404 int nModifyStep;
405 struct list undo_stack;
406 struct list redo_stack;
407 int nUndoStackSize;
408 int nUndoLimit;
409 ME_UndoMode nUndoMode;
410 ME_UndoControlState undo_ctl_state;
411 int nParagraphs;
412 LONG nLastSelStart, nLastSelEnd;
413 ME_Paragraph *last_sel_start_para, *last_sel_end_para;
414 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
415 int nZoomNumerator, nZoomDenominator;
416 RECT rcFormat;
417 BOOL bWordWrap;
418 int nTextLimit;
419 EDITWORDBREAKPROCW pfnWordBreak;
420 IRichEditOle *richole;
421 LPRICHEDITOLECALLBACK lpOleCallback;
422 /*TEXTMODE variable; contains only one of each of the following options:
423 *TM_RICHTEXT or TM_PLAINTEXT
424 *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
425 *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
426 int mode;
427 BOOL bHideSelection;
428 BOOL AutoURLDetect_bEnable;
429 WCHAR password_char;
430 BOOL bHaveFocus;
431 DWORD freeze_count;
432 /*for IME */
433 int imeStartIndex;
434 DWORD selofs; /* The size of the selection bar on the left side of control */
435 ME_SelectionType nSelectionType;
437 /* Track previous notified selection */
438 CHARRANGE notified_cr;
440 /* Cache previously set scrollbar info */
441 SCROLLINFO vert_si, horz_si;
442 unsigned int vert_sb_enabled : 1;
443 unsigned int horz_sb_enabled : 1;
445 int caret_height;
446 BOOL caret_hidden;
447 BOOL bMouseCaptured;
448 int wheel_remain;
449 TXTBACKSTYLE back_style;
450 struct list style_list;
451 struct list reobj_list;
452 struct wine_rb_tree marked_paras;
453 } ME_TextEditor;
455 typedef struct tagME_Context
457 HDC hDC;
458 POINT pt;
459 RECT rcView;
460 SIZE dpi;
461 int nAvailWidth;
462 ME_Style *current_style;
463 HFONT orig_font;
465 /* those are valid inside ME_WrapTextParagraph and related */
466 ME_TextEditor *editor;
467 } ME_Context;
469 struct text_selection
471 ITextSelection ITextSelection_iface;
472 LONG ref;
474 struct text_services *services;
477 struct text_services
479 IUnknown IUnknown_inner;
480 ITextServices ITextServices_iface;
481 IRichEditOle IRichEditOle_iface;
482 ITextDocument2Old ITextDocument2Old_iface;
483 IUnknown *outer_unk;
484 LONG ref;
485 ME_TextEditor *editor;
486 struct text_selection *text_selection;
487 struct list rangelist;
488 struct list clientsites;
489 char spare[256]; /* for bug #12179 */
492 #endif