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 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" 49 50 #include "wine/debug.h" 51 #include "wine/heap.h" 52 #include "wine/list.h" 53 54 #if defined(__i386__) && !defined(__MINGW32__) 55 extern const struct ITextHostVtbl itextHostStdcallVtbl DECLSPEC_HIDDEN; 56 #endif /* __i386__ */ 57 58 typedef struct tagME_String 59 { 60 WCHAR *szData; 61 int nLen, nBuffer; 62 void (*free)(struct tagME_String *); 63 } ME_String; 64 65 typedef struct tagME_FontCacheItem 66 { 67 LOGFONTW lfSpecs; 68 HFONT hFont; 69 int nRefs; 70 int nAge; 71 } ME_FontCacheItem; 72 73 #define HFONT_CACHE_SIZE 10 74 75 typedef struct tagME_Style 76 { 77 CHARFORMAT2W fmt; 78 79 ME_FontCacheItem *font_cache; /* cached font for the style */ 80 TEXTMETRICW tm; /* cached font metrics for the style */ 81 int nRefs; /* reference count */ 82 SCRIPT_CACHE script_cache; 83 struct list entry; 84 } ME_Style; 85 86 typedef enum { 87 diInvalid, 88 diTextStart, /* start of the text buffer */ 89 diParagraph, /* paragraph start */ 90 diCell, /* cell start */ 91 diRun, /* run (sequence of chars with the same character format) */ 92 diStartRow, /* start of the row (line of text on the screen) */ 93 diTextEnd, /* end of the text buffer */ 94 95 /********************* these below are meant for finding only *********************/ 96 diStartRowOrParagraph, /* 7 */ 97 diStartRowOrParagraphOrEnd, 98 diRunOrParagraph, 99 diRunOrStartRow, 100 diParagraphOrEnd, 101 diRunOrParagraphOrEnd, /* 12 */ 102 } ME_DIType; 103 104 #define SELECTIONBAR_WIDTH 8 105 106 /******************************** run flags *************************/ 107 #define MERF_STYLEFLAGS 0x0FFF 108 /* run contains non-text content, which has its own rules for wrapping, sizing etc */ 109 #define MERF_GRAPHICS 0x001 110 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */ 111 #define MERF_TAB 0x002 112 /* run is a cell boundary */ 113 #define MERF_ENDCELL 0x004 /* v4.1 */ 114 115 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL) 116 117 /* run is splittable (contains white spaces in the middle or end) */ 118 #define MERF_SPLITTABLE 0x001000 119 /* run starts with whitespaces */ 120 #define MERF_STARTWHITE 0x002000 121 /* run ends with whitespaces */ 122 #define MERF_ENDWHITE 0x004000 123 /* run is completely made of whitespaces */ 124 #define MERF_WHITESPACE 0x008000 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 /* v4.1 */ 147 #define MEPF_CELL 0x04 /* The paragraph is nested in a cell */ 148 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */ 149 #define MEPF_ROWEND 0x10 /* Visible empty paragraph at the end of the row */ 150 #define MEPF_COMPLEX 0x20 /* Use uniscribe */ 151 152 /******************************** structures *************************/ 153 154 struct tagME_DisplayItem; 155 156 struct re_object 157 { 158 struct list entry; 159 REOBJECT obj; 160 }; 161 162 typedef struct tagME_Run 163 { 164 ME_Style *style; 165 struct tagME_Paragraph *para; /* ptr to the run's paragraph */ 166 int nCharOfs; /* relative to para's offset */ 167 int len; /* length of run's text */ 168 int nWidth; /* width of full run, width of leading&trailing ws */ 169 int nFlags; 170 int nAscent, nDescent; /* pixels above/below baseline */ 171 POINT pt; /* relative to para's position */ 172 struct re_object *reobj; /* FIXME: should be a union with strText (at least) */ 173 174 SCRIPT_ANALYSIS script_analysis; 175 int num_glyphs, max_glyphs; 176 WORD *glyphs; 177 SCRIPT_VISATTR *vis_attrs; 178 int *advances; 179 GOFFSET *offsets; 180 int max_clusters; 181 WORD *clusters; 182 } ME_Run; 183 184 typedef struct tagME_Border 185 { 186 int width; 187 COLORREF colorRef; 188 } ME_Border; 189 190 typedef struct tagME_BorderRect 191 { 192 ME_Border top; 193 ME_Border left; 194 ME_Border bottom; 195 ME_Border right; 196 } ME_BorderRect; 197 198 struct para_num 199 { 200 ME_Style *style; 201 ME_String *text; 202 INT width; 203 POINT pt; 204 }; 205 206 typedef struct tagME_Paragraph 207 { 208 PARAFORMAT2 fmt; 209 ME_String *text; 210 211 struct tagME_DisplayItem *pCell; /* v4.1 */ 212 ME_BorderRect border; 213 214 int nCharOfs; 215 int nFlags; 216 POINT pt; 217 int nHeight, nWidth; 218 int nRows; 219 struct para_num para_num; 220 ME_Run *eop_run; /* ptr to the end-of-para run */ 221 struct tagME_DisplayItem *prev_para, *next_para; 222 struct tagME_DisplayItem *prev_marked, *next_marked; 223 } ME_Paragraph; 224 225 typedef struct tagME_Cell /* v4.1 */ 226 { 227 int nNestingLevel; /* 0 for normal cells, and greater for nested cells */ 228 int nRightBoundary; 229 ME_BorderRect border; 230 POINT pt; 231 int nHeight, nWidth; 232 int yTextOffset; /* The text offset is caused by the largest top border. */ 233 struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell; 234 } ME_Cell; 235 236 typedef struct tagME_Row 237 { 238 int nHeight; 239 int nBaseline; 240 int nWidth; 241 int nLMargin; 242 int nRMargin; 243 POINT pt; 244 } ME_Row; 245 246 /* the display item list layout is like this: 247 * - the document consists of paragraphs 248 * - each paragraph contains at least one run, the last run in the paragraph 249 * is an end-of-paragraph run 250 * - each formatted paragraph contains at least one row, which corresponds 251 * to a screen line (that's why there are no rows in an unformatted 252 * paragraph 253 * - the paragraphs contain "shortcut" pointers to the previous and the next 254 * paragraph, that makes iteration over paragraphs faster 255 * - the list starts with diTextStart and ends with diTextEnd 256 */ 257 258 typedef struct tagME_DisplayItem 259 { 260 ME_DIType type; 261 struct tagME_DisplayItem *prev, *next; 262 union { 263 ME_Run run; 264 ME_Row row; 265 ME_Cell cell; 266 ME_Paragraph para; 267 } member; 268 } ME_DisplayItem; 269 270 typedef struct tagME_TextBuffer 271 { 272 ME_DisplayItem *pFirst, *pLast; 273 ME_Style *pCharStyle; 274 ME_Style *pDefaultStyle; 275 } ME_TextBuffer; 276 277 typedef struct tagME_Cursor 278 { 279 ME_DisplayItem *pPara; 280 ME_DisplayItem *pRun; 281 int nOffset; 282 } ME_Cursor; 283 284 typedef enum { 285 umAddToUndo, 286 umAddToRedo, 287 umIgnore, 288 umAddBackToUndo 289 } ME_UndoMode; 290 291 enum undo_type 292 { 293 undo_insert_run, 294 undo_delete_run, 295 undo_join_paras, 296 undo_split_para, 297 undo_set_para_fmt, 298 undo_set_char_fmt, 299 undo_end_transaction, /* marks the end of a group of changes for undo */ 300 undo_potential_end_transaction /* allows grouping typed chars for undo */ 301 }; 302 303 struct insert_run_item 304 { 305 int pos, len; 306 WCHAR *str; 307 ME_Style *style; 308 DWORD flags; 309 }; 310 311 struct delete_run_item 312 { 313 int pos, len; 314 }; 315 316 struct join_paras_item 317 { 318 int pos; 319 }; 320 321 struct split_para_item 322 { 323 int pos; 324 PARAFORMAT2 fmt; 325 ME_BorderRect border; 326 ME_String *eol_str; 327 DWORD flags; 328 ME_BorderRect cell_border; 329 int cell_right_boundary; 330 }; 331 332 struct set_para_fmt_item 333 { 334 int pos; 335 PARAFORMAT2 fmt; 336 ME_BorderRect border; 337 }; 338 339 struct set_char_fmt_item 340 { 341 int pos, len; 342 CHARFORMAT2W fmt; 343 }; 344 345 struct undo_item 346 { 347 struct list entry; 348 enum undo_type type; 349 union 350 { 351 struct insert_run_item insert_run; 352 struct delete_run_item delete_run; 353 struct join_paras_item join_paras; 354 struct split_para_item split_para; 355 struct set_para_fmt_item set_para_fmt; 356 struct set_char_fmt_item set_char_fmt; 357 } u; 358 }; 359 360 typedef enum { 361 stPosition = 0, 362 stWord, 363 stLine, 364 stParagraph, 365 stDocument 366 } ME_SelectionType; 367 368 typedef struct tagME_FontTableItem { 369 BYTE bCharSet; 370 WCHAR *szFaceName; 371 } ME_FontTableItem; 372 373 374 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */ 375 376 struct tagME_InStream { 377 EDITSTREAM *editstream; 378 DWORD dwSize; 379 DWORD dwUsed; 380 char buffer[STREAMIN_BUFFER_SIZE]; 381 }; 382 typedef struct tagME_InStream ME_InStream; 383 384 typedef struct tagME_TextEditor 385 { 386 HWND hWnd, hwndParent; 387 ITextHost *texthost; 388 IUnknown *reOle; 389 BOOL bEmulateVersion10; 390 ME_TextBuffer *pBuffer; 391 ME_Cursor *pCursors; 392 DWORD styleFlags; 393 DWORD exStyleFlags; 394 int nCursors; 395 SIZE sizeWindow; 396 int nTotalLength, nLastTotalLength; 397 int nTotalWidth, nLastTotalWidth; 398 int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */ 399 int nUDArrowX; 400 int total_rows; 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; 437 ME_DisplayItem *first_marked_para; 438 439 /* Track previous notified selection */ 440 CHARRANGE notified_cr; 441 442 /* Cache previously set scrollbar info */ 443 SCROLLINFO vert_si, horz_si; 444 445 int caret_height; 446 BOOL caret_hidden; 447 BOOL bMouseCaptured; 448 int wheel_remain; 449 struct list style_list; 450 struct list reobj_list; 451 } ME_TextEditor; 452 453 typedef struct tagME_Context 454 { 455 HDC hDC; 456 POINT pt; 457 RECT rcView; 458 SIZE dpi; 459 int nAvailWidth; 460 ME_Style *current_style; 461 HFONT orig_font; 462 463 /* those are valid inside ME_WrapTextParagraph and related */ 464 ME_TextEditor *editor; 465 } ME_Context; 466 467 #endif 468