d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / riched20 / editstr.h
blob4fd965c4f116c940c9d0b0b2f4c090ad8305bd89
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
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
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 #include "usp10.h"
52 #include "wine/debug.h"
53 #include "wine/list.h"
55 #ifdef __i386__
56 extern const struct ITextHostVtbl itextHostStdcallVtbl;
57 #endif /* __i386__ */
59 typedef struct tagME_String
61 WCHAR *szData;
62 int nLen, nBuffer;
63 } ME_String;
65 typedef struct tagME_Style
67 CHARFORMAT2W fmt;
69 HFONT hFont; /* cached font for the style */
70 TEXTMETRICW tm; /* cached font metrics for the style */
71 int nRefs; /* reference count */
72 SCRIPT_CACHE script_cache;
73 } ME_Style;
75 typedef enum {
76 diInvalid,
77 diTextStart, /* start of the text buffer */
78 diParagraph, /* paragraph start */
79 diCell, /* cell start */
80 diRun, /* run (sequence of chars with the same character format) */
81 diStartRow, /* start of the row (line of text on the screen) */
82 diTextEnd, /* end of the text buffer */
84 /********************* these below are meant for finding only *********************/
85 diStartRowOrParagraph, /* 7 */
86 diStartRowOrParagraphOrEnd,
87 diRunOrParagraph,
88 diRunOrStartRow,
89 diParagraphOrEnd,
90 diRunOrParagraphOrEnd, /* 12 */
91 } ME_DIType;
93 #define SELECTIONBAR_WIDTH 8
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 */
104 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
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 /* the "end of paragraph" run, contains 1 character */
115 #define MERF_ENDPARA 0x100000
116 /* forcing the "end of row" run, contains 1 character */
117 #define MERF_ENDROW 0x200000
118 /* run is hidden */
119 #define MERF_HIDDEN 0x400000
120 /* start of a table row has an empty paragraph that should be skipped over. */
121 #define MERF_TABLESTART 0x800000 /* v4.1 */
123 /* runs with any of these flags set cannot be joined */
124 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
125 /* runs that don't contain real text */
126 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
128 /* those flags are kept when the row is split */
129 #define MERF_SPLITMASK (~(0))
131 /******************************** para flags *************************/
133 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
134 #define MEPF_REWRAP 0x01
135 /* v4.1 */
136 #define MEPF_CELL 0x04 /* The paragraph is nested in a cell */
137 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
138 #define MEPF_ROWEND 0x10 /* Visible empty paragraph at the end of the row */
139 #define MEPF_COMPLEX 0x20 /* Use uniscribe */
141 /******************************** structures *************************/
143 struct tagME_DisplayItem;
145 typedef struct tagME_Run
147 ME_Style *style;
148 struct tagME_Paragraph *para; /* ptr to the run's paragraph */
149 int nCharOfs; /* relative to para's offset */
150 int len; /* length of run's text */
151 int nWidth; /* width of full run, width of leading&trailing ws */
152 int nFlags;
153 int nAscent, nDescent; /* pixels above/below baseline */
154 POINT pt; /* relative to para's position */
155 REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
157 SCRIPT_ANALYSIS script_analysis;
158 int num_glyphs, max_glyphs;
159 WORD *glyphs;
160 SCRIPT_VISATTR *vis_attrs;
161 int *advances;
162 GOFFSET *offsets;
163 int max_clusters;
164 WORD *clusters;
165 } ME_Run;
167 typedef struct tagME_Border
169 int width;
170 COLORREF colorRef;
171 } ME_Border;
173 typedef struct tagME_BorderRect
175 ME_Border top;
176 ME_Border left;
177 ME_Border bottom;
178 ME_Border right;
179 } ME_BorderRect;
181 typedef struct tagME_Paragraph
183 PARAFORMAT2 *pFmt;
184 ME_String *text;
186 struct tagME_DisplayItem *pCell; /* v4.1 */
187 ME_BorderRect border;
189 int nCharOfs;
190 int nFlags;
191 POINT pt;
192 int nHeight, nWidth;
193 int nRows;
194 struct tagME_DisplayItem *prev_para, *next_para;
195 } ME_Paragraph;
197 typedef struct tagME_Cell /* v4.1 */
199 int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
200 int nRightBoundary;
201 ME_BorderRect border;
202 POINT pt;
203 int nHeight, nWidth;
204 int yTextOffset; /* The text offset is caused by the largest top border. */
205 struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
206 } ME_Cell;
208 typedef struct tagME_Row
210 int nHeight;
211 int nBaseline;
212 int nWidth;
213 int nLMargin;
214 int nRMargin;
215 POINT pt;
216 } ME_Row;
218 /* the display item list layout is like this:
219 * - the document consists of paragraphs
220 * - each paragraph contains at least one run, the last run in the paragraph
221 * is an end-of-paragraph run
222 * - each formatted paragraph contains at least one row, which corresponds
223 * to a screen line (that's why there are no rows in an unformatted
224 * paragraph
225 * - the paragraphs contain "shortcut" pointers to the previous and the next
226 * paragraph, that makes iteration over paragraphs faster
227 * - the list starts with diTextStart and ends with diTextEnd
230 typedef struct tagME_DisplayItem
232 ME_DIType type;
233 struct tagME_DisplayItem *prev, *next;
234 union {
235 ME_Run run;
236 ME_Row row;
237 ME_Cell cell;
238 ME_Paragraph para;
239 } member;
240 } ME_DisplayItem;
242 typedef struct tagME_TextBuffer
244 ME_DisplayItem *pFirst, *pLast;
245 ME_Style *pCharStyle;
246 ME_Style *pDefaultStyle;
247 } ME_TextBuffer;
249 typedef struct tagME_Cursor
251 ME_DisplayItem *pPara;
252 ME_DisplayItem *pRun;
253 int nOffset;
254 } ME_Cursor;
256 typedef enum {
257 umAddToUndo,
258 umAddToRedo,
259 umIgnore,
260 umAddBackToUndo
261 } ME_UndoMode;
263 enum undo_type
265 undo_insert_run,
266 undo_delete_run,
267 undo_join_paras,
268 undo_split_para,
269 undo_set_para_fmt,
270 undo_set_char_fmt,
271 undo_end_transaction, /* marks the end of a group of changes for undo */
272 undo_potential_end_transaction /* allows grouping typed chars for undo */
275 struct insert_run_item
277 int pos, len;
278 WCHAR *str;
279 ME_Style *style;
280 DWORD flags;
283 struct delete_run_item
285 int pos, len;
288 struct join_paras_item
290 int pos;
293 struct split_para_item
295 int pos;
296 PARAFORMAT2 fmt;
297 ME_BorderRect border;
298 ME_String *eol_str;
299 DWORD flags;
300 ME_BorderRect cell_border;
301 int cell_right_boundary;
304 struct set_para_fmt_item
306 int pos;
307 PARAFORMAT2 fmt;
308 ME_BorderRect border;
311 struct set_char_fmt_item
313 int pos, len;
314 CHARFORMAT2W fmt;
317 struct undo_item
319 struct list entry;
320 enum undo_type type;
321 union
323 struct insert_run_item insert_run;
324 struct delete_run_item delete_run;
325 struct join_paras_item join_paras;
326 struct split_para_item split_para;
327 struct set_para_fmt_item set_para_fmt;
328 struct set_char_fmt_item set_char_fmt;
329 } u;
332 typedef enum {
333 stPosition = 0,
334 stWord,
335 stLine,
336 stParagraph,
337 stDocument
338 } ME_SelectionType;
340 typedef struct tagME_FontTableItem {
341 BYTE bCharSet;
342 WCHAR *szFaceName;
343 } ME_FontTableItem;
346 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
348 struct tagME_InStream {
349 EDITSTREAM *editstream;
350 DWORD dwSize;
351 DWORD dwUsed;
352 char buffer[STREAMIN_BUFFER_SIZE];
354 typedef struct tagME_InStream ME_InStream;
357 #define STREAMOUT_BUFFER_SIZE 4096
358 #define STREAMOUT_FONTTBL_SIZE 8192
359 #define STREAMOUT_COLORTBL_SIZE 1024
361 typedef struct tagME_OutStream {
362 EDITSTREAM *stream;
363 char buffer[STREAMOUT_BUFFER_SIZE];
364 UINT pos, written;
365 UINT nCodePage;
366 UINT nFontTblLen;
367 ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
368 UINT nColorTblLen;
369 COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
370 UINT nDefaultFont;
371 UINT nDefaultCodePage;
372 /* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
373 * an greater numbers mean we are in a cell nested within a cell. */
374 UINT nNestingLevel;
375 } ME_OutStream;
377 typedef struct tagME_FontCacheItem
379 LOGFONTW lfSpecs;
380 HFONT hFont;
381 int nRefs;
382 int nAge;
383 } ME_FontCacheItem;
385 #define HFONT_CACHE_SIZE 10
387 typedef struct tagME_TextEditor
389 HWND hWnd, hwndParent;
390 ITextHost *texthost;
391 IRichEditOle *reOle;
392 BOOL bEmulateVersion10;
393 ME_TextBuffer *pBuffer;
394 ME_Cursor *pCursors;
395 DWORD styleFlags;
396 DWORD exStyleFlags;
397 int nCursors;
398 SIZE sizeWindow;
399 int nTotalLength, nLastTotalLength;
400 int nTotalWidth, nLastTotalWidth;
401 int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
402 int nUDArrowX;
403 COLORREF rgbBackColor;
404 HBRUSH hbrBackground;
405 BOOL bCaretAtEnd;
406 int nEventMask;
407 int nModifyStep;
408 struct list undo_stack;
409 struct list redo_stack;
410 int nUndoStackSize;
411 int nUndoLimit;
412 ME_UndoMode nUndoMode;
413 int nParagraphs;
414 int nLastSelStart, nLastSelEnd;
415 ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
416 ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
417 int nZoomNumerator, nZoomDenominator;
418 RECT prevClientRect;
419 RECT rcFormat;
420 BOOL bDefaultFormatRect;
421 BOOL bWordWrap;
422 int nTextLimit;
423 EDITWORDBREAKPROCW pfnWordBreak;
424 LPRICHEDITOLECALLBACK lpOleCallback;
425 /*TEXTMODE variable; contains only one of each of the following options:
426 *TM_RICHTEXT or TM_PLAINTEXT
427 *TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
428 *TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
429 int mode;
430 BOOL bHideSelection;
431 BOOL AutoURLDetect_bEnable;
432 WCHAR cPasswordMask;
433 BOOL bHaveFocus;
434 BOOL bDialogMode; /* Indicates that we are inside a dialog window */
435 /*for IME */
436 int imeStartIndex;
437 DWORD selofs; /* The size of the selection bar on the left side of control */
438 ME_SelectionType nSelectionType;
440 /* Track previous notified selection */
441 CHARRANGE notified_cr;
443 /* Cache previously set scrollbar info */
444 SCROLLINFO vert_si, horz_si;
446 BOOL bMouseCaptured;
447 int wheel_remain;
448 } ME_TextEditor;
450 typedef struct tagME_Context
452 HDC hDC;
453 POINT pt;
454 RECT rcView;
455 SIZE dpi;
456 int nAvailWidth;
458 /* those are valid inside ME_WrapTextParagraph and related */
459 ME_TextEditor *editor;
460 } ME_Context;
462 typedef struct tagME_WrapContext
464 ME_Style *style;
465 ME_Context *context;
466 int nLeftMargin, nRightMargin, nFirstMargin;
467 int nAvailWidth;
468 int nRow;
469 POINT pt;
470 BOOL bOverflown, bWordWrap;
471 ME_DisplayItem *pPara;
472 ME_DisplayItem *pRowStart;
474 ME_DisplayItem *pLastSplittableRun;
475 } ME_WrapContext;
477 #endif