kernel: Use a standard LoadLibrary call to load the main exe.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
33 #include <windef.h>
34 #include <winbase.h>
35 #include <winnls.h>
36 #include <winnt.h>
37 #include <wingdi.h>
38 #include <winuser.h>
39 #include <richedit.h>
40 #include <commctrl.h>
41 #define COBJMACROS
42 #include <ole2.h>
43 #include <richole.h>
44
45 #include "wine/debug.h"
46
47 typedef struct tagME_String
48 {
49   WCHAR *szData;
50   int nLen, nBuffer;
51 } ME_String;
52
53 typedef struct tagME_Style
54 {
55   CHARFORMAT2W fmt;
56
57   HFONT hFont; /* cached font for the style */
58   TEXTMETRICW tm; /* cached font metrics for the style */
59   int nRefs; /* reference count */
60   int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
61 } ME_Style;
62
63 typedef enum {
64   diTextStart, /* start of the text buffer */
65   diParagraph, /* paragraph start */
66   diRun, /* run (sequence of chars with the same character format) */
67   diStartRow, /* start of the row (line of text on the screen) */
68   diTextEnd, /* end of the text buffer */
69   
70   /********************* these below are meant for finding only *********************/
71   diStartRowOrParagraph, /* 5 */
72   diStartRowOrParagraphOrEnd,
73   diRunOrParagraph,
74   diRunOrStartRow,
75   diParagraphOrEnd,
76   diRunOrParagraphOrEnd, /* 10 */
77   
78   diUndoInsertRun, /* 11 */
79   diUndoDeleteRun, /* 12 */
80   diUndoJoinParagraphs, /* 13 */
81   diUndoSplitParagraph, /* 14 */
82   diUndoSetParagraphFormat, /* 15 */
83   diUndoSetCharFormat, /* 16 */
84   diUndoEndTransaction, /* 17 */
85   diUndoSetDefaultCharFormat, /* 18 */
86 } ME_DIType;
87
88 /******************************** run flags *************************/
89 #define MERF_STYLEFLAGS 0x0FFF
90 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
91 #define MERF_GRAPHICS 1
92 /* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
93 #define MERF_TAB 2
94 /* run is a cell boundary */
95 #define MERF_CELL 4
96
97 #define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_CELL)
98
99 /* run is splittable (contains white spaces in the middle or end) */
100 #define MERF_SPLITTABLE 0x001000
101 /* run starts with whitespaces */
102 #define MERF_STARTWHITE 0x002000
103 /* run ends with whitespaces */
104 #define MERF_ENDWHITE   0x004000
105 /* run is completely made of whitespaces */
106 #define MERF_WHITESPACE 0x008000
107 /* run is a last (dummy) run in the paragraph */
108 #define MERF_SKIPPED    0x010000
109 /* flags that are calculated during text wrapping */
110 #define MERF_CALCBYWRAP 0x0F0000
111 /* the "end of paragraph" run, contains 1 character */
112 #define MERF_ENDPARA    0x100000
113 /* run is hidden */
114 #define MERF_HIDDEN     0x200000
115
116 /* runs with any of these flags set cannot be joined */
117 #define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
118 /* runs that don't contain real text */
119 #define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA)
120
121 /* those flags are kept when the row is split */
122 #define MERF_SPLITMASK (~(0))
123
124 /******************************** para flags *************************/
125
126 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
127 #define MEPF_REWRAP 1
128 #define MEPF_REPAINT 2
129
130 /******************************** structures *************************/
131
132 struct tagME_DisplayItem;
133
134 typedef struct tagME_Run
135 {
136   ME_String *strText;
137   ME_Style *style;
138   int nCharOfs; /* relative to para's offset */
139   int nWidth; /* width of full run, width of leading&trailing ws */
140   int nFlags;
141   int nAscent, nDescent; /* pixels above/below baseline */
142   POINT pt; /* relative to para's position */
143   struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */
144 } ME_Run;
145
146 typedef struct tagME_Document {
147   struct tagME_DisplayItem *def_char_style;
148   struct tagME_DisplayItem *def_para_style;
149   int last_wrapped_line;
150 } ME_Document;
151
152 typedef struct tagME_TableCell
153 {
154   int nRightBoundary;
155   struct tagME_TableCell *next;
156 } ME_TableCell;
157
158 typedef struct tagME_Paragraph
159 {
160   PARAFORMAT2 *pFmt;
161   
162   BOOL bTable;                       /* this paragraph is a table row */
163   struct tagME_TableCell *pCells;    /* list of cells and their properties */
164   struct tagME_TableCell *pLastCell; /* points to the last cell in the list */
165
166   int nLeftMargin, nRightMargin, nFirstMargin;
167   int nCharOfs;
168   int nFlags;
169   int nYPos, nHeight;
170   int nLastPaintYPos, nLastPaintHeight;
171   int nRows;
172   struct tagME_DisplayItem *prev_para, *next_para, *document;
173 } ME_Paragraph;
174
175 typedef struct tagME_Row
176 {
177   int nHeight;
178   int nBaseline;
179   int nWidth;
180   int nLMargin;
181   int nRMargin;
182   int nYPos;
183 } ME_Row;
184
185 /* the display item list layout is like this:
186  * - the document consists of paragraphs
187  * - each paragraph contains at least one run, the last run in the paragraph
188  *   is an end-of-paragraph run
189  * - each formatted paragraph contains at least one row, which corresponds
190  *   to a screen line (that's why there are no rows in an unformatted
191  *   paragraph
192  * - the paragraphs contain "shortcut" pointers to the previous and the next
193  *   paragraph, that makes iteration over paragraphs faster 
194  * - the list starts with diTextStart and ends with diTextEnd
195  */
196
197 typedef struct tagME_DisplayItem
198 {
199   ME_DIType type;
200   struct tagME_DisplayItem *prev, *next;
201   union {
202     ME_Run run;
203     ME_Row row;
204     ME_Paragraph para;
205     ME_Document doc; /* not used */
206     ME_Style *ustyle; /* used by diUndoSetCharFormat */
207   } member;
208 } ME_DisplayItem;
209
210 typedef struct tagME_UndoItem
211 {
212   ME_DisplayItem di;
213   int nStart, nLen;
214 } ME_UndoItem;
215
216 typedef struct tagME_TextBuffer
217 {
218   ME_DisplayItem *pFirst, *pLast;
219   ME_Style *pCharStyle;
220   ME_Style *pDefaultStyle;
221 } ME_TextBuffer;
222
223 typedef struct tagME_Cursor
224 {
225   ME_DisplayItem *pRun;
226   int nOffset;
227 } ME_Cursor;
228
229 typedef enum {
230   umAddToUndo,
231   umAddToRedo,
232   umIgnore,
233   umAddBackToUndo
234 } ME_UndoMode;
235
236 typedef struct tagME_FontTableItem {
237   BYTE bCharSet;
238   WCHAR *szFaceName;
239 } ME_FontTableItem;
240
241
242 #define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
243
244 struct tagME_InStream {
245   EDITSTREAM *editstream;
246   DWORD dwSize;
247   DWORD dwUsed;
248   char buffer[STREAMIN_BUFFER_SIZE];
249 };
250 typedef struct tagME_InStream ME_InStream;
251
252
253 #define STREAMOUT_BUFFER_SIZE 4096
254 #define STREAMOUT_FONTTBL_SIZE 8192
255 #define STREAMOUT_COLORTBL_SIZE 1024
256
257 typedef struct tagME_OutStream {
258   EDITSTREAM *stream;
259   char buffer[STREAMOUT_BUFFER_SIZE];
260   UINT pos, written;
261   UINT nCodePage;
262   UINT nFontTblLen;
263   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
264   UINT nColorTblLen;
265   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
266   UINT nDefaultFont;
267   UINT nDefaultCodePage;
268 } ME_OutStream;
269
270 typedef struct tagME_FontCacheItem
271 {
272   LOGFONTW lfSpecs;
273   HFONT hFont;
274   int nRefs;
275   int nAge;
276 } ME_FontCacheItem;
277
278 #define HFONT_CACHE_SIZE 10
279
280 typedef struct tagME_TextEditor
281 {
282   HWND hWnd;
283   BOOL bEmulateVersion10;
284   BOOL bCaretShown;
285   ME_TextBuffer *pBuffer;
286   ME_Cursor *pCursors;
287   int nCursors;
288   SIZE sizeWindow;
289   int nTotalLength, nLastTotalLength;
290   int nUDArrowX;
291   int nSequence;
292   int nOldSelFrom, nOldSelTo;
293   COLORREF rgbBackColor;
294   HBRUSH hbrBackground;
295   BOOL bCaretAtEnd;
296   int nEventMask;
297   int nModifyStep;
298   ME_DisplayItem *pUndoStack, *pRedoStack;
299   ME_UndoMode nUndoMode;
300   int nParagraphs;
301   int nLastSelStart, nLastSelEnd;
302   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
303   BOOL bScrollX, bScrollY;
304   int nScrollPosY;
305   int nZoomNumerator, nZoomDenominator;
306   RECT rcFormat;
307   BOOL bRedraw;
308   int nInvalidOfs;
309   EDITWORDBREAKPROCW pfnWordBreak;
310   LPRICHEDITOLECALLBACK lpOleCallback;
311 } ME_TextEditor;
312
313 typedef struct tagME_Context
314 {
315   HDC hDC;
316   POINT pt;
317   POINT ptRowOffset;
318   RECT rcView;
319   HBRUSH hbrMargin;
320
321   /* those are valid inside ME_WrapTextParagraph and related */
322   POINT ptFirstRun;
323   ME_TextEditor *editor;
324   int nSequence;
325 } ME_Context;
326
327 typedef struct tagME_WrapContext
328 {
329   ME_Style *style;
330   ME_Context *context;
331   int nLeftMargin, nRightMargin, nFirstMargin;
332   int nTotalWidth, nAvailWidth;
333   int nRow;
334   POINT pt;
335   BOOL bOverflown;
336   ME_DisplayItem *pRowStart;
337   
338   ME_DisplayItem *pLastSplittableRun;
339   POINT ptLastSplittableRun;
340 } ME_WrapContext;  
341
342 #endif