Prevent crash when no URL is specified.
[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
42 #include "wine/debug.h"
43
44 typedef struct tagME_String
45 {
46   WCHAR *szData;
47   int nLen, nBuffer;
48 } ME_String;
49
50 typedef struct tagME_Style
51 {
52   CHARFORMAT2W fmt;
53
54   HFONT hFont; /* cached font for the style */
55   TEXTMETRICW tm; /* cached font metrics for the style */
56   int nRefs; /* reference count */
57   int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
58 } ME_Style;
59
60 typedef enum {
61   diTextStart, /* start of the text buffer */
62   diParagraph, /* paragraph start */
63   diRun, /* run (sequence of chars with the same character format) */
64   diStartRow, /* start of the row (line of text on the screen) */
65   diTextEnd, /* end of the text buffer */
66   
67   /********************* these below are meant for finding only *********************/
68   diStartRowOrParagraph, /* 5 */
69   diStartRowOrParagraphOrEnd,
70   diRunOrParagraph,
71   diRunOrStartRow,
72   diParagraphOrEnd,
73   diRunOrParagraphOrEnd, /* 10 */
74   
75   diUndoInsertRun, /* 11 */
76   diUndoDeleteRun, /* 12 */
77   diUndoJoinParagraphs, /* 13 */
78   diUndoSplitParagraph, /* 14 */
79   diUndoSetParagraphFormat, /* 15 */
80   diUndoSetCharFormat, /* 16 */
81   diUndoEndTransaction, /* 17 */
82   diUndoSetDefaultCharFormat, /* 18 */
83 } ME_DIType;
84
85 /******************************** run flags *************************/
86 #define MERF_STYLEFLAGS 0x0FFF
87 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
88 #define MERF_GRAPHICS 1
89
90 /* run is splittable (contains white spaces in the middle or end) */
91 #define MERF_SPLITTABLE 0x001000
92 /* run starts with whitespaces */
93 #define MERF_STARTWHITE 0x002000
94 /* run ends with whitespaces */
95 #define MERF_ENDWHITE   0x004000
96 /* run is completely made of whitespaces */
97 #define MERF_WHITESPACE 0x008000
98 /* run is a last (dummy) run in the paragraph */
99 #define MERF_SKIPPED    0x010000
100 /* flags that are calculated during text wrapping */
101 #define MERF_CALCBYWRAP 0x0F0000
102 /* the "end of paragraph" run, contains 1 character */
103 #define MERF_ENDPARA    0x100000
104
105 /* those flags are kept when the row is split */
106 #define MERF_SPLITMASK (~(0))
107
108 /******************************** para flags *************************/
109
110 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
111 #define MEPF_REWRAP 1
112 #define MEPF_REPAINT 2
113
114 /******************************** structures *************************/
115
116 struct tagME_DisplayItem;
117
118 typedef struct tagME_Run
119 {
120   ME_String *strText;
121   ME_Style *style;
122   int nCharOfs; /* relative to para's offset */
123   int nWidth; /* width of full run, width of leading&trailing ws */
124   int nFlags;
125   int nAscent, nDescent; /* pixels above/below baseline */
126   POINT pt; /* relative to para's position */
127 } ME_Run;
128
129 typedef struct tagME_Document {
130   struct tagME_DisplayItem *def_char_style;
131   struct tagME_DisplayItem *def_para_style;
132   int last_wrapped_line;
133 } ME_Document;
134
135 typedef struct tagME_Paragraph
136 {
137   PARAFORMAT2 *pFmt;
138   int nLeftMargin, nRightMargin, nFirstMargin;
139   int nCharOfs;
140   int nFlags;
141   int nYPos, nHeight;
142   int nLastPaintYPos, nLastPaintHeight;
143   struct tagME_DisplayItem *prev_para, *next_para, *document;
144 } ME_Paragraph;
145
146 typedef struct tagME_Row
147 {
148   int nHeight;
149   int nBaseline;
150   int nWidth;
151   int nLMargin;
152   int nRMargin;
153   int nYPos;
154 } ME_Row;
155
156 typedef struct tagME_DisplayItem
157 {
158   ME_DIType type;
159   struct tagME_DisplayItem *prev, *next;
160   union {
161     ME_Run run;
162     ME_Row row;
163     ME_Paragraph para;
164     ME_Document doc; /* not used */
165     ME_Style *ustyle; /* used by diUndoSetCharFormat */
166   } member;
167 } ME_DisplayItem;
168
169 typedef struct tagME_UndoItem
170 {
171   ME_DisplayItem di;
172   int nStart, nLen;
173 } ME_UndoItem;
174
175 typedef struct tagME_TextBuffer
176 {
177   ME_DisplayItem *pFirst, *pLast;
178   ME_Style *pCharStyle;
179   ME_Style *pDefaultStyle;
180 } ME_TextBuffer;
181
182 typedef struct tagME_Cursor
183 {
184   ME_DisplayItem *pRun;
185   int nOffset;
186 } ME_Cursor;
187
188 typedef enum {
189   umAddToUndo,
190   umAddToRedo,
191   umIgnore,
192   umAddBackToUndo
193 } ME_UndoMode;
194
195 typedef struct tagME_FontTableItem {
196   BYTE bCharSet;
197   WCHAR *szFaceName;
198 } ME_FontTableItem;
199
200 #define STREAMOUT_BUFFER_SIZE 4096
201 #define STREAMOUT_FONTTBL_SIZE 8192
202 #define STREAMOUT_COLORTBL_SIZE 1024
203
204 typedef struct tagME_OutStream {
205   EDITSTREAM *stream;
206   char buffer[STREAMOUT_BUFFER_SIZE];
207   UINT pos, written;
208   UINT nCodePage;
209   UINT nFontTblLen;
210   ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
211   UINT nColorTblLen;
212   COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
213   UINT nDefaultFont;
214 } ME_OutStream;
215
216 typedef struct tagME_FontCacheItem
217 {
218   LOGFONTW lfSpecs;
219   HFONT hFont;
220   int nRefs;
221   int nAge;
222 } ME_FontCacheItem;
223
224 #define HFONT_CACHE_SIZE 10
225
226 typedef struct tagME_TextEditor
227 {
228   HWND hWnd;
229   BOOL bCaretShown;
230   ME_TextBuffer *pBuffer;
231   ME_Cursor *pCursors;
232   int nCursors;
233   SIZE sizeWindow;
234   int nTotalLength, nLastTotalLength;
235   int nUDArrowX;
236   int nSequence;
237   int nOldSelFrom, nOldSelTo;
238   COLORREF rgbBackColor;
239   BOOL bCaretAtEnd;
240   int nEventMask;
241   int nModifyStep;
242   ME_DisplayItem *pUndoStack, *pRedoStack;
243   ME_UndoMode nUndoMode;
244   int nParagraphs;
245   int nLastSelStart, nLastSelEnd;
246   ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
247   ME_OutStream *pStream;
248   BOOL bScrollX, bScrollY;
249   int nScrollPosY;
250 } ME_TextEditor;
251
252 typedef struct tagME_Context
253 {
254   HDC hDC;
255   POINT pt;
256   POINT ptRowOffset;
257   RECT rcView;
258   HBRUSH hbrMargin;
259
260   /* those are valid inside ME_WrapTextParagraph and related */
261   POINT ptFirstRun;
262   ME_TextEditor *editor;
263   int nSequence;
264 } ME_Context;
265
266 typedef struct tagME_WrapContext
267 {
268   ME_Style *style;
269   ME_Context *context;
270   int nLeftMargin, nRightMargin, nFirstMargin;
271   int nTotalWidth, nAvailWidth;
272   int nRow;
273   POINT pt;
274   BOOL bOverflown;
275   ME_DisplayItem *pRowStart;
276   
277   ME_DisplayItem *pLastSplittableRun;
278   POINT ptLastSplittableRun;
279 } ME_WrapContext;  
280
281 #endif