]>
Commit | Line | Data |
---|---|---|
a1b82138 | 1 | /////////////////////////////////////////////////////////////////////////////// |
40ff126a | 2 | // Name: wx/textctrl.h |
7d76fbd5 | 3 | // Purpose: wxTextAttr and wxTextCtrlBase class - the interface of wxTextCtrl |
a1b82138 VZ |
4 | // Author: Vadim Zeitlin |
5 | // Modified by: | |
6 | // Created: 13.07.99 | |
7 | // RCS-ID: $Id$ | |
99d80019 | 8 | // Copyright: (c) Vadim Zeitlin |
65571936 | 9 | // Licence: wxWindows licence |
a1b82138 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_TEXTCTRL_H_BASE_ |
13 | #define _WX_TEXTCTRL_H_BASE_ | |
c801d85f | 14 | |
a1b82138 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
4bc1afd5 | 18 | |
a1b82138 | 19 | #include "wx/defs.h" |
1e6feb95 VZ |
20 | |
21 | #if wxUSE_TEXTCTRL | |
22 | ||
a1b82138 | 23 | #include "wx/control.h" // the base class |
0ec1179b | 24 | #include "wx/textentry.h" // single-line text entry interface |
efe66bbc VZ |
25 | #include "wx/dynarray.h" // wxArrayInt |
26 | #include "wx/gdicmn.h" // wxPoint | |
a1b82138 | 27 | |
8ca2ebc8 VZ |
28 | // some compilers don't have standard compliant rdbuf() (and MSVC has it only |
29 | // in its new iostream library, not in the old one used with iostream.h) | |
15cdc341 | 30 | #if defined(__WATCOMC__) || \ |
8ca2ebc8 | 31 | ((defined(__VISUALC5__) || defined(__VISUALC6__)) && wxUSE_IOSTREAMH) |
15cdc341 WS |
32 | #define wxHAS_TEXT_WINDOW_STREAM 0 |
33 | #elif wxUSE_STD_IOSTREAM | |
34 | #include "wx/ioswrap.h" | |
35 | #define wxHAS_TEXT_WINDOW_STREAM 1 | |
36 | #else | |
37 | #define wxHAS_TEXT_WINDOW_STREAM 0 | |
a1b82138 VZ |
38 | #endif |
39 | ||
b5dbe15d VS |
40 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; |
41 | class WXDLLIMPEXP_FWD_CORE wxTextCtrlBase; | |
0efe5ba7 | 42 | |
efe66bbc VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxTextCtrl types | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
efe66bbc VZ |
47 | // wxTextCoord is the line or row number (which should have been unsigned but |
48 | // is long for backwards compatibility) | |
49 | typedef long wxTextCoord; | |
50 | ||
a1b82138 VZ |
51 | // ---------------------------------------------------------------------------- |
52 | // constants | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
53a2db12 | 55 | extern WXDLLIMPEXP_DATA_CORE(const char) wxTextCtrlNameStr[]; |
a1b82138 | 56 | |
7d8268a1 WS |
57 | // this is intentionally not enum to avoid warning fixes with |
58 | // typecasting from enum type to wxTextCoord | |
59 | const wxTextCoord wxOutOfRangeTextCoord = -1; | |
60 | const wxTextCoord wxInvalidTextCoord = -2; | |
61 | ||
c57e3339 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // wxTextCtrl style flags | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
e015d1f7 | 66 | #define wxTE_NO_VSCROLL 0x0002 |
e015d1f7 | 67 | |
c57e3339 VZ |
68 | #define wxTE_READONLY 0x0010 |
69 | #define wxTE_MULTILINE 0x0020 | |
70 | #define wxTE_PROCESS_TAB 0x0040 | |
71 | ||
e015d1f7 JS |
72 | // alignment flags |
73 | #define wxTE_LEFT 0x0000 // 0x0000 | |
74 | #define wxTE_CENTER wxALIGN_CENTER_HORIZONTAL // 0x0100 | |
75 | #define wxTE_RIGHT wxALIGN_RIGHT // 0x0200 | |
76 | #define wxTE_CENTRE wxTE_CENTER | |
77 | ||
c57e3339 VZ |
78 | // this style means to use RICHEDIT control and does something only under wxMSW |
79 | // and Win32 and is silently ignored under all other platforms | |
80 | #define wxTE_RICH 0x0080 | |
e015d1f7 | 81 | |
c57e3339 VZ |
82 | #define wxTE_PROCESS_ENTER 0x0400 |
83 | #define wxTE_PASSWORD 0x0800 | |
84 | ||
85 | // automatically detect the URLs and generate the events when mouse is | |
86 | // moved/clicked over an URL | |
87 | // | |
9440c3d0 | 88 | // this is for Win32 richedit and wxGTK2 multiline controls only so far |
c57e3339 VZ |
89 | #define wxTE_AUTO_URL 0x1000 |
90 | ||
5a8f04e3 VZ |
91 | // by default, the Windows text control doesn't show the selection when it |
92 | // doesn't have focus - use this style to force it to always show it | |
93 | #define wxTE_NOHIDESEL 0x2000 | |
94 | ||
fb4888a6 | 95 | // use wxHSCROLL to not wrap text at all, wxTE_CHARWRAP to wrap it at any |
65c12361 | 96 | // position and wxTE_WORDWRAP to wrap at words boundary |
fb4888a6 VZ |
97 | // |
98 | // if no wrapping style is given at all, the control wraps at word boundary | |
65c12361 | 99 | #define wxTE_DONTWRAP wxHSCROLL |
fb4888a6 VZ |
100 | #define wxTE_CHARWRAP 0x4000 // wrap at any position |
101 | #define wxTE_WORDWRAP 0x0001 // wrap only at words boundaries | |
102 | #define wxTE_BESTWRAP 0x0000 // this is the default | |
103 | ||
40ff126a WS |
104 | #if WXWIN_COMPATIBILITY_2_6 |
105 | // obsolete synonym | |
106 | #define wxTE_LINEWRAP wxTE_CHARWRAP | |
107 | #endif // WXWIN_COMPATIBILITY_2_6 | |
65c12361 | 108 | |
053ac76f VZ |
109 | #if WXWIN_COMPATIBILITY_2_8 |
110 | // this style is (or at least should be) on by default now, don't use it | |
111 | #define wxTE_AUTO_SCROLL 0 | |
112 | #endif // WXWIN_COMPATIBILITY_2_8 | |
113 | ||
a5aa8086 VZ |
114 | // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for |
115 | // wxTE_RICH controls - can be used together with or instead of wxTE_RICH | |
116 | #define wxTE_RICH2 0x8000 | |
117 | ||
afafd942 JS |
118 | // reuse wxTE_RICH2's value for CAPEDIT control on Windows CE |
119 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) | |
120 | #define wxTE_CAPITALIZE wxTE_RICH2 | |
121 | #else | |
122 | #define wxTE_CAPITALIZE 0 | |
123 | #endif | |
124 | ||
3306aec1 JS |
125 | // ---------------------------------------------------------------------------- |
126 | // wxTextCtrl file types | |
127 | // ---------------------------------------------------------------------------- | |
128 | ||
129 | #define wxTEXT_TYPE_ANY 0 | |
130 | ||
efe66bbc VZ |
131 | // ---------------------------------------------------------------------------- |
132 | // wxTextCtrl::HitTest return values | |
133 | // ---------------------------------------------------------------------------- | |
134 | ||
135 | // the point asked is ... | |
136 | enum wxTextCtrlHitTestResult | |
137 | { | |
138 | wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented | |
139 | wxTE_HT_BEFORE, // either to the left or upper | |
140 | wxTE_HT_ON_TEXT, // directly on | |
141 | wxTE_HT_BELOW, // below [the last line] | |
142 | wxTE_HT_BEYOND // after [the end of line] | |
143 | }; | |
144 | // ... the character returned | |
145 | ||
e00a5d3c JS |
146 | // ---------------------------------------------------------------------------- |
147 | // Types for wxTextAttr | |
148 | // ---------------------------------------------------------------------------- | |
149 | ||
150 | // Alignment | |
151 | ||
152 | enum wxTextAttrAlignment | |
153 | { | |
154 | wxTEXT_ALIGNMENT_DEFAULT, | |
155 | wxTEXT_ALIGNMENT_LEFT, | |
156 | wxTEXT_ALIGNMENT_CENTRE, | |
157 | wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE, | |
158 | wxTEXT_ALIGNMENT_RIGHT, | |
159 | wxTEXT_ALIGNMENT_JUSTIFIED | |
160 | }; | |
161 | ||
162 | // Flags to indicate which attributes are being applied | |
c6cf894a FM |
163 | enum wxTextAttrFlags |
164 | { | |
165 | wxTEXT_ATTR_TEXT_COLOUR = 0x00000001, | |
166 | wxTEXT_ATTR_BACKGROUND_COLOUR = 0x00000002, | |
7d76fbd5 | 167 | |
c6cf894a | 168 | wxTEXT_ATTR_FONT_FACE = 0x00000004, |
32423dd8 JS |
169 | wxTEXT_ATTR_FONT_POINT_SIZE = 0x00000008, |
170 | wxTEXT_ATTR_FONT_PIXEL_SIZE = 0x10000000, | |
c6cf894a FM |
171 | wxTEXT_ATTR_FONT_WEIGHT = 0x00000010, |
172 | wxTEXT_ATTR_FONT_ITALIC = 0x00000020, | |
173 | wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040, | |
c7a49742 | 174 | wxTEXT_ATTR_FONT_STRIKETHROUGH = 0x08000000, |
c6cf894a | 175 | wxTEXT_ATTR_FONT_ENCODING = 0x02000000, |
9c4cb611 | 176 | wxTEXT_ATTR_FONT_FAMILY = 0x04000000, |
32423dd8 JS |
177 | wxTEXT_ATTR_FONT_SIZE = \ |
178 | ( wxTEXT_ATTR_FONT_POINT_SIZE | wxTEXT_ATTR_FONT_PIXEL_SIZE ), | |
c6cf894a FM |
179 | wxTEXT_ATTR_FONT = \ |
180 | ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \ | |
c7a49742 | 181 | wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_STRIKETHROUGH | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ), |
c6cf894a FM |
182 | |
183 | wxTEXT_ATTR_ALIGNMENT = 0x00000080, | |
184 | wxTEXT_ATTR_LEFT_INDENT = 0x00000100, | |
185 | wxTEXT_ATTR_RIGHT_INDENT = 0x00000200, | |
186 | wxTEXT_ATTR_TABS = 0x00000400, | |
c6cf894a FM |
187 | wxTEXT_ATTR_PARA_SPACING_AFTER = 0x00000800, |
188 | wxTEXT_ATTR_PARA_SPACING_BEFORE = 0x00001000, | |
189 | wxTEXT_ATTR_LINE_SPACING = 0x00002000, | |
190 | wxTEXT_ATTR_CHARACTER_STYLE_NAME = 0x00004000, | |
191 | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME = 0x00008000, | |
192 | wxTEXT_ATTR_LIST_STYLE_NAME = 0x00010000, | |
7d76fbd5 | 193 | |
c6cf894a FM |
194 | wxTEXT_ATTR_BULLET_STYLE = 0x00020000, |
195 | wxTEXT_ATTR_BULLET_NUMBER = 0x00040000, | |
196 | wxTEXT_ATTR_BULLET_TEXT = 0x00080000, | |
197 | wxTEXT_ATTR_BULLET_NAME = 0x00100000, | |
7d76fbd5 FM |
198 | |
199 | wxTEXT_ATTR_BULLET = \ | |
200 | ( wxTEXT_ATTR_BULLET_STYLE | wxTEXT_ATTR_BULLET_NUMBER | wxTEXT_ATTR_BULLET_TEXT | \ | |
201 | wxTEXT_ATTR_BULLET_NAME ), | |
202 | ||
203 | ||
c6cf894a FM |
204 | wxTEXT_ATTR_URL = 0x00200000, |
205 | wxTEXT_ATTR_PAGE_BREAK = 0x00400000, | |
206 | wxTEXT_ATTR_EFFECTS = 0x00800000, | |
207 | wxTEXT_ATTR_OUTLINE_LEVEL = 0x01000000, | |
208 | ||
209 | /*! | |
210 | * Character and paragraph combined styles | |
211 | */ | |
212 | ||
213 | wxTEXT_ATTR_CHARACTER = \ | |
9c4cb611 | 214 | (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS| \ |
c6cf894a FM |
215 | wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL), |
216 | ||
217 | wxTEXT_ATTR_PARAGRAPH = \ | |
218 | (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\ | |
219 | wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\ | |
8698cfea | 220 | wxTEXT_ATTR_BULLET|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL|wxTEXT_ATTR_PAGE_BREAK), |
c6cf894a FM |
221 | |
222 | wxTEXT_ATTR_ALL = (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH) | |
223 | }; | |
44cc96a8 JS |
224 | |
225 | /*! | |
226 | * Styles for wxTextAttr::SetBulletStyle | |
227 | */ | |
c6cf894a FM |
228 | enum wxTextAttrBulletStyle |
229 | { | |
230 | wxTEXT_ATTR_BULLET_STYLE_NONE = 0x00000000, | |
231 | wxTEXT_ATTR_BULLET_STYLE_ARABIC = 0x00000001, | |
232 | wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER = 0x00000002, | |
233 | wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER = 0x00000004, | |
234 | wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER = 0x00000008, | |
235 | wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER = 0x00000010, | |
236 | wxTEXT_ATTR_BULLET_STYLE_SYMBOL = 0x00000020, | |
237 | wxTEXT_ATTR_BULLET_STYLE_BITMAP = 0x00000040, | |
238 | wxTEXT_ATTR_BULLET_STYLE_PARENTHESES = 0x00000080, | |
239 | wxTEXT_ATTR_BULLET_STYLE_PERIOD = 0x00000100, | |
240 | wxTEXT_ATTR_BULLET_STYLE_STANDARD = 0x00000200, | |
241 | wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS = 0x00000400, | |
242 | wxTEXT_ATTR_BULLET_STYLE_OUTLINE = 0x00000800, | |
243 | ||
244 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT = 0x00000000, | |
245 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT = 0x00001000, | |
4ce3ebd3 JS |
246 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE = 0x00002000, |
247 | ||
248 | wxTEXT_ATTR_BULLET_STYLE_CONTINUATION = 0x00004000 | |
c6cf894a | 249 | }; |
44cc96a8 JS |
250 | |
251 | /*! | |
252 | * Styles for wxTextAttr::SetTextEffects | |
253 | */ | |
c6cf894a FM |
254 | enum wxTextAttrEffects |
255 | { | |
256 | wxTEXT_ATTR_EFFECT_NONE = 0x00000000, | |
257 | wxTEXT_ATTR_EFFECT_CAPITALS = 0x00000001, | |
258 | wxTEXT_ATTR_EFFECT_SMALL_CAPITALS = 0x00000002, | |
259 | wxTEXT_ATTR_EFFECT_STRIKETHROUGH = 0x00000004, | |
260 | wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH = 0x00000008, | |
261 | wxTEXT_ATTR_EFFECT_SHADOW = 0x00000010, | |
262 | wxTEXT_ATTR_EFFECT_EMBOSS = 0x00000020, | |
263 | wxTEXT_ATTR_EFFECT_OUTLINE = 0x00000040, | |
264 | wxTEXT_ATTR_EFFECT_ENGRAVE = 0x00000080, | |
265 | wxTEXT_ATTR_EFFECT_SUPERSCRIPT = 0x00000100, | |
266 | wxTEXT_ATTR_EFFECT_SUBSCRIPT = 0x00000200 | |
267 | }; | |
44cc96a8 JS |
268 | |
269 | /*! | |
270 | * Line spacing values | |
271 | */ | |
c6cf894a FM |
272 | enum wxTextAttrLineSpacing |
273 | { | |
274 | wxTEXT_ATTR_LINE_SPACING_NORMAL = 10, | |
275 | wxTEXT_ATTR_LINE_SPACING_HALF = 15, | |
276 | wxTEXT_ATTR_LINE_SPACING_TWICE = 20 | |
277 | }; | |
e00a5d3c | 278 | |
4bc1afd5 VZ |
279 | // ---------------------------------------------------------------------------- |
280 | // wxTextAttr: a structure containing the visual attributes of a text | |
281 | // ---------------------------------------------------------------------------- | |
282 | ||
53a2db12 | 283 | class WXDLLIMPEXP_CORE wxTextAttr |
4bc1afd5 VZ |
284 | { |
285 | public: | |
286 | // ctors | |
e00a5d3c | 287 | wxTextAttr() { Init(); } |
44cc96a8 | 288 | wxTextAttr(const wxTextAttr& attr) { Init(); Copy(attr); } |
4bc1afd5 VZ |
289 | wxTextAttr(const wxColour& colText, |
290 | const wxColour& colBack = wxNullColour, | |
e00a5d3c JS |
291 | const wxFont& font = wxNullFont, |
292 | wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT); | |
293 | ||
44cc96a8 | 294 | // Initialise this object. |
e00a5d3c JS |
295 | void Init(); |
296 | ||
44cc96a8 JS |
297 | // Copy |
298 | void Copy(const wxTextAttr& attr); | |
53ee6090 | 299 | |
44cc96a8 JS |
300 | // Assignment |
301 | void operator= (const wxTextAttr& attr); | |
53ee6090 | 302 | |
44cc96a8 JS |
303 | // Equality test |
304 | bool operator== (const wxTextAttr& attr) const; | |
53ee6090 | 305 | |
32423dd8 JS |
306 | // Partial equality test. If @a weakTest is @true, attributes of this object do not |
307 | // have to be present if those attributes of @a attr are present. If @a weakTest is | |
308 | // @false, the function will fail if an attribute is present in @a attr but not | |
309 | // in this object. | |
310 | bool EqPartial(const wxTextAttr& attr, bool weakTest = true) const; | |
44cc96a8 | 311 | |
44cc96a8 JS |
312 | // Get attributes from font. |
313 | bool GetFontAttributes(const wxFont& font, int flags = wxTEXT_ATTR_FONT); | |
4bc1afd5 VZ |
314 | |
315 | // setters | |
e00a5d3c JS |
316 | void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; } |
317 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; } | |
e00a5d3c JS |
318 | void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; } |
319 | void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; } | |
89b67477 | 320 | void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; } |
e00a5d3c | 321 | void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; } |
44cc96a8 | 322 | |
32423dd8 JS |
323 | void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_POINT_SIZE; } |
324 | void SetFontPointSize(int pointSize) { m_fontSize = pointSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_POINT_SIZE; } | |
325 | void SetFontPixelSize(int pixelSize) { m_fontSize = pixelSize; m_flags &= ~wxTEXT_ATTR_FONT_SIZE; m_flags |= wxTEXT_ATTR_FONT_PIXEL_SIZE; } | |
7d76fbd5 FM |
326 | void SetFontStyle(wxFontStyle fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; } |
327 | void SetFontWeight(wxFontWeight fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; } | |
44cc96a8 JS |
328 | void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; } |
329 | void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; } | |
c7a49742 | 330 | void SetFontStrikethrough(bool strikethrough) { m_fontStrikethrough = strikethrough; m_flags |= wxTEXT_ATTR_FONT_STRIKETHROUGH; } |
44cc96a8 | 331 | void SetFontEncoding(wxFontEncoding encoding) { m_fontEncoding = encoding; m_flags |= wxTEXT_ATTR_FONT_ENCODING; } |
7d76fbd5 | 332 | void SetFontFamily(wxFontFamily family) { m_fontFamily = family; m_flags |= wxTEXT_ATTR_FONT_FAMILY; } |
44cc96a8 JS |
333 | |
334 | // Set font | |
32423dd8 | 335 | void SetFont(const wxFont& font, int flags = (wxTEXT_ATTR_FONT & ~wxTEXT_ATTR_FONT_PIXEL_SIZE)) { GetFontAttributes(font, flags); } |
44cc96a8 | 336 | |
e00a5d3c | 337 | void SetFlags(long flags) { m_flags = flags; } |
4bc1afd5 | 338 | |
44cc96a8 JS |
339 | void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; } |
340 | void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; } | |
341 | void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); } | |
342 | void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; } | |
343 | void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; } | |
344 | void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; } | |
345 | void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; } | |
346 | void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; } | |
347 | void SetBulletText(const wxString& text) { m_bulletText = text; m_flags |= wxTEXT_ATTR_BULLET_TEXT; } | |
348 | void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; } | |
349 | void SetBulletName(const wxString& name) { m_bulletName = name; m_flags |= wxTEXT_ATTR_BULLET_NAME; } | |
350 | void SetURL(const wxString& url) { m_urlTarget = url; m_flags |= wxTEXT_ATTR_URL; } | |
351 | void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); } | |
352 | void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); } | |
353 | void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; } | |
354 | void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); } | |
4bc1afd5 VZ |
355 | |
356 | const wxColour& GetTextColour() const { return m_colText; } | |
357 | const wxColour& GetBackgroundColour() const { return m_colBack; } | |
e00a5d3c JS |
358 | wxTextAttrAlignment GetAlignment() const { return m_textAlignment; } |
359 | const wxArrayInt& GetTabs() const { return m_tabs; } | |
360 | long GetLeftIndent() const { return m_leftIndent; } | |
89b67477 | 361 | long GetLeftSubIndent() const { return m_leftSubIndent; } |
e00a5d3c JS |
362 | long GetRightIndent() const { return m_rightIndent; } |
363 | long GetFlags() const { return m_flags; } | |
4bc1afd5 | 364 | |
44cc96a8 | 365 | int GetFontSize() const { return m_fontSize; } |
7d76fbd5 FM |
366 | wxFontStyle GetFontStyle() const { return m_fontStyle; } |
367 | wxFontWeight GetFontWeight() const { return m_fontWeight; } | |
44cc96a8 | 368 | bool GetFontUnderlined() const { return m_fontUnderlined; } |
c7a49742 | 369 | bool GetFontStrikethrough() const { return m_fontStrikethrough; } |
44cc96a8 JS |
370 | const wxString& GetFontFaceName() const { return m_fontFaceName; } |
371 | wxFontEncoding GetFontEncoding() const { return m_fontEncoding; } | |
7d76fbd5 | 372 | wxFontFamily GetFontFamily() const { return m_fontFamily; } |
44cc96a8 | 373 | |
1fee6e25 | 374 | wxFont GetFont() const; |
44cc96a8 JS |
375 | |
376 | const wxString& GetCharacterStyleName() const { return m_characterStyleName; } | |
377 | const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; } | |
378 | const wxString& GetListStyleName() const { return m_listStyleName; } | |
379 | int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; } | |
380 | int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; } | |
c6cf894a | 381 | |
44cc96a8 JS |
382 | int GetLineSpacing() const { return m_lineSpacing; } |
383 | int GetBulletStyle() const { return m_bulletStyle; } | |
384 | int GetBulletNumber() const { return m_bulletNumber; } | |
385 | const wxString& GetBulletText() const { return m_bulletText; } | |
386 | const wxString& GetBulletFont() const { return m_bulletFont; } | |
387 | const wxString& GetBulletName() const { return m_bulletName; } | |
388 | const wxString& GetURL() const { return m_urlTarget; } | |
389 | int GetTextEffects() const { return m_textEffects; } | |
390 | int GetTextEffectFlags() const { return m_textEffectFlags; } | |
391 | int GetOutlineLevel() const { return m_outlineLevel; } | |
392 | ||
393 | // accessors | |
a1b806b9 DS |
394 | bool HasTextColour() const { return m_colText.IsOk() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; } |
395 | bool HasBackgroundColour() const { return m_colBack.IsOk() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; } | |
6470ffba | 396 | bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) && HasFlag(wxTEXT_ATTR_ALIGNMENT) ; } |
44cc96a8 JS |
397 | bool HasTabs() const { return HasFlag(wxTEXT_ATTR_TABS) ; } |
398 | bool HasLeftIndent() const { return HasFlag(wxTEXT_ATTR_LEFT_INDENT); } | |
399 | bool HasRightIndent() const { return HasFlag(wxTEXT_ATTR_RIGHT_INDENT); } | |
400 | bool HasFontWeight() const { return HasFlag(wxTEXT_ATTR_FONT_WEIGHT); } | |
401 | bool HasFontSize() const { return HasFlag(wxTEXT_ATTR_FONT_SIZE); } | |
32423dd8 JS |
402 | bool HasFontPointSize() const { return HasFlag(wxTEXT_ATTR_FONT_POINT_SIZE); } |
403 | bool HasFontPixelSize() const { return HasFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); } | |
44cc96a8 JS |
404 | bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); } |
405 | bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); } | |
c7a49742 | 406 | bool HasFontStrikethrough() const { return HasFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); } |
44cc96a8 JS |
407 | bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); } |
408 | bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); } | |
9c4cb611 | 409 | bool HasFontFamily() const { return HasFlag(wxTEXT_ATTR_FONT_FAMILY); } |
44cc96a8 JS |
410 | bool HasFont() const { return HasFlag(wxTEXT_ATTR_FONT); } |
411 | ||
412 | bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); } | |
413 | bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); } | |
414 | bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); } | |
415 | bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) && !m_characterStyleName.IsEmpty(); } | |
416 | bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && !m_paragraphStyleName.IsEmpty(); } | |
417 | bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); } | |
418 | bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); } | |
419 | bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); } | |
420 | bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT); } | |
421 | bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME); } | |
422 | bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); } | |
423 | bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); } | |
424 | bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); } | |
425 | bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); } | |
426 | bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); } | |
427 | ||
428 | bool HasFlag(long flag) const { return (m_flags & flag) != 0; } | |
24777478 JS |
429 | void RemoveFlag(long flag) { m_flags &= ~flag; } |
430 | void AddFlag(long flag) { m_flags |= flag; } | |
44cc96a8 JS |
431 | |
432 | // Is this a character style? | |
433 | bool IsCharacterStyle() const { return HasFlag(wxTEXT_ATTR_CHARACTER); } | |
434 | bool IsParagraphStyle() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH); } | |
435 | ||
17665a2b VZ |
436 | // returns false if we have any attributes set, true otherwise |
437 | bool IsDefault() const | |
438 | { | |
44cc96a8 JS |
439 | return GetFlags() == 0; |
440 | } | |
441 | ||
24777478 | 442 | // Merges the given attributes. If compareWith |
44cc96a8 JS |
443 | // is non-NULL, then it will be used to mask out those attributes that are the same in style |
444 | // and compareWith, for situations where we don't want to explicitly set inherited attributes. | |
445 | bool Apply(const wxTextAttr& style, const wxTextAttr* compareWith = NULL); | |
32423dd8 | 446 | |
44cc96a8 JS |
447 | // merges the attributes of the base and the overlay objects and returns |
448 | // the result; the parameter attributes take precedence | |
449 | // | |
450 | // WARNING: the order of arguments is the opposite of Combine() | |
451 | static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay) | |
452 | { | |
453 | return Combine(overlay, base, NULL); | |
454 | } | |
455 | ||
456 | // merges the attributes of this object and overlay | |
457 | void Merge(const wxTextAttr& overlay) | |
458 | { | |
459 | *this = Merge(*this, overlay); | |
17665a2b VZ |
460 | } |
461 | ||
eda40bfc VZ |
462 | // return the attribute having the valid font and colours: it uses the |
463 | // attributes set in attr and falls back first to attrDefault and then to | |
464 | // the text control font/colours for those attributes which are not set | |
465 | static wxTextAttr Combine(const wxTextAttr& attr, | |
466 | const wxTextAttr& attrDef, | |
467 | const wxTextCtrlBase *text); | |
468 | ||
44cc96a8 JS |
469 | // Compare tabs |
470 | static bool TabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2); | |
471 | ||
472 | // Remove attributes | |
473 | static bool RemoveStyle(wxTextAttr& destStyle, const wxTextAttr& style); | |
474 | ||
475 | // Combine two bitlists, specifying the bits of interest with separate flags. | |
476 | static bool CombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB); | |
477 | ||
478 | // Compare two bitlists | |
479 | static bool BitlistsEqPartial(int valueA, int valueB, int flags); | |
480 | ||
481 | // Split into paragraph and character styles | |
482 | static bool SplitParaCharStyles(const wxTextAttr& style, wxTextAttr& parStyle, wxTextAttr& charStyle); | |
483 | ||
4bc1afd5 | 484 | private: |
e00a5d3c | 485 | long m_flags; |
44cc96a8 JS |
486 | |
487 | // Paragraph styles | |
e00a5d3c JS |
488 | wxArrayInt m_tabs; // array of int: tab stops in 1/10 mm |
489 | int m_leftIndent; // left indent in 1/10 mm | |
cb719f2e | 490 | int m_leftSubIndent; // left indent for all but the first |
89b67477 VZ |
491 | // line in a paragraph relative to the |
492 | // first line, in 1/10 mm | |
e00a5d3c | 493 | int m_rightIndent; // right indent in 1/10 mm |
44cc96a8 JS |
494 | wxTextAttrAlignment m_textAlignment; |
495 | ||
496 | int m_paragraphSpacingAfter; | |
497 | int m_paragraphSpacingBefore; | |
498 | int m_lineSpacing; | |
499 | int m_bulletStyle; | |
500 | int m_bulletNumber; | |
501 | int m_textEffects; | |
502 | int m_textEffectFlags; | |
503 | int m_outlineLevel; | |
504 | wxString m_bulletText; | |
505 | wxString m_bulletFont; | |
506 | wxString m_bulletName; | |
507 | wxString m_urlTarget; | |
508 | wxFontEncoding m_fontEncoding; | |
509 | ||
510 | // Character styles | |
511 | wxColour m_colText, | |
512 | m_colBack; | |
513 | int m_fontSize; | |
7d76fbd5 FM |
514 | wxFontStyle m_fontStyle; |
515 | wxFontWeight m_fontWeight; | |
516 | wxFontFamily m_fontFamily; | |
44cc96a8 | 517 | bool m_fontUnderlined; |
c7a49742 | 518 | bool m_fontStrikethrough; |
44cc96a8 JS |
519 | wxString m_fontFaceName; |
520 | ||
521 | // Character style | |
522 | wxString m_characterStyleName; | |
523 | ||
524 | // Paragraph style | |
525 | wxString m_paragraphStyleName; | |
526 | ||
527 | // List style | |
528 | wxString m_listStyleName; | |
4bc1afd5 VZ |
529 | }; |
530 | ||
a1b82138 | 531 | // ---------------------------------------------------------------------------- |
0ec1179b | 532 | // wxTextAreaBase: multiline text control specific methods |
a1b82138 VZ |
533 | // ---------------------------------------------------------------------------- |
534 | ||
0ec1179b | 535 | class WXDLLIMPEXP_CORE wxTextAreaBase |
a1b82138 VZ |
536 | { |
537 | public: | |
0ec1179b VZ |
538 | wxTextAreaBase() { } |
539 | virtual ~wxTextAreaBase() { } | |
a1b82138 | 540 | |
0ec1179b VZ |
541 | // lines access |
542 | // ------------ | |
a5aa8086 | 543 | |
a1b82138 VZ |
544 | virtual int GetLineLength(long lineNo) const = 0; |
545 | virtual wxString GetLineText(long lineNo) const = 0; | |
546 | virtual int GetNumberOfLines() const = 0; | |
547 | ||
a1b82138 | 548 | |
0ec1179b VZ |
549 | // file IO |
550 | // ------- | |
aa8e9a36 | 551 | |
0ec1179b VZ |
552 | bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY) |
553 | { return DoLoadFile(file, fileType); } | |
554 | bool SaveFile(const wxString& file = wxEmptyString, | |
555 | int fileType = wxTEXT_TYPE_ANY); | |
a1b82138 | 556 | |
0ec1179b VZ |
557 | // dirty flag handling |
558 | // ------------------- | |
a1b82138 | 559 | |
0ec1179b | 560 | virtual bool IsModified() const = 0; |
3a9fa0d6 | 561 | virtual void MarkDirty() = 0; |
a1b82138 | 562 | virtual void DiscardEdits() = 0; |
be0ac181 VZ |
563 | void SetModified(bool modified) |
564 | { | |
565 | if ( modified ) | |
566 | MarkDirty(); | |
567 | else | |
568 | DiscardEdits(); | |
569 | } | |
a1b82138 | 570 | |
d7eee191 | 571 | |
0ec1179b VZ |
572 | // styles handling |
573 | // --------------- | |
94af7d45 | 574 | |
4bc1afd5 VZ |
575 | // text control under some platforms supports the text styles: these |
576 | // methods allow to apply the given text style to the given selection or to | |
577 | // set/get the style which will be used for all appended text | |
0ec1179b VZ |
578 | virtual bool SetStyle(long start, long end, const wxTextAttr& style) = 0; |
579 | virtual bool GetStyle(long position, wxTextAttr& style) = 0; | |
580 | virtual bool SetDefaultStyle(const wxTextAttr& style) = 0; | |
581 | virtual const wxTextAttr& GetDefaultStyle() const { return m_defaultStyle; } | |
582 | ||
583 | ||
584 | // coordinates translation | |
585 | // ----------------------- | |
4bc1afd5 | 586 | |
a1b82138 VZ |
587 | // translate between the position (which is just an index in the text ctrl |
588 | // considering all its contents as a single strings) and (x, y) coordinates | |
589 | // which represent column and line. | |
590 | virtual long XYToPosition(long x, long y) const = 0; | |
0efe5ba7 | 591 | virtual bool PositionToXY(long pos, long *x, long *y) const = 0; |
a1b82138 | 592 | |
6ce83213 VZ |
593 | // translate the given position (which is just an index in the text control) |
594 | // to client coordinates | |
595 | wxPoint PositionToCoords(long pos) const; | |
596 | ||
597 | ||
a1b82138 VZ |
598 | virtual void ShowPosition(long pos) = 0; |
599 | ||
efe66bbc VZ |
600 | // find the character at position given in pixels |
601 | // | |
602 | // NB: pt is in device coords (not adjusted for the client area origin nor | |
603 | // scrolling) | |
692c9b86 | 604 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; |
efe66bbc VZ |
605 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, |
606 | wxTextCoord *col, | |
607 | wxTextCoord *row) const; | |
3396739d VZ |
608 | virtual wxString GetValue() const = 0; |
609 | virtual void SetValue(const wxString& value) = 0; | |
efe66bbc | 610 | |
0ec1179b VZ |
611 | protected: |
612 | // implementation of loading/saving | |
3396739d VZ |
613 | virtual bool DoLoadFile(const wxString& file, int fileType); |
614 | virtual bool DoSaveFile(const wxString& file, int fileType); | |
0ec1179b | 615 | |
6ce83213 VZ |
616 | // Return true if the given position is valid, i.e. positive and less than |
617 | // the last position. | |
618 | virtual bool IsValidPosition(long pos) const = 0; | |
619 | ||
620 | // Default stub implementation of PositionToCoords() always returns | |
621 | // wxDefaultPosition. | |
622 | virtual wxPoint DoPositionToCoords(long pos) const; | |
a1b82138 | 623 | |
0ec1179b VZ |
624 | // the name of the last file loaded with LoadFile() which will be used by |
625 | // SaveFile() by default | |
626 | wxString m_filename; | |
a1b82138 | 627 | |
0ec1179b VZ |
628 | // the text style which will be used for any new text added to the control |
629 | wxTextAttr m_defaultStyle; | |
a1b82138 | 630 | |
a1b82138 | 631 | |
c0c133e1 | 632 | wxDECLARE_NO_COPY_CLASS(wxTextAreaBase); |
0ec1179b | 633 | }; |
a1b82138 | 634 | |
0ec1179b VZ |
635 | // this class defines wxTextCtrl interface, wxTextCtrlBase actually implements |
636 | // too much things because it derives from wxTextEntry and not wxTextEntryBase | |
637 | // and so any classes which "look like" wxTextCtrl (such as wxRichTextCtrl) | |
638 | // but don't need the (native) implementation bits from wxTextEntry should | |
639 | // actually derive from this one and not wxTextCtrlBase | |
640 | class WXDLLIMPEXP_CORE wxTextCtrlIface : public wxTextAreaBase, | |
641 | public wxTextEntryBase | |
642 | { | |
643 | public: | |
644 | wxTextCtrlIface() { } | |
645 | ||
3396739d VZ |
646 | // wxTextAreaBase overrides |
647 | virtual wxString GetValue() const | |
648 | { | |
649 | return wxTextEntryBase::GetValue(); | |
650 | } | |
651 | virtual void SetValue(const wxString& value) | |
652 | { | |
653 | wxTextEntryBase::SetValue(value); | |
654 | } | |
655 | ||
6ce83213 VZ |
656 | protected: |
657 | virtual bool IsValidPosition(long pos) const | |
658 | { | |
659 | return pos >= 0 && pos <= GetLastPosition(); | |
660 | } | |
661 | ||
0ec1179b | 662 | private: |
c0c133e1 | 663 | wxDECLARE_NO_COPY_CLASS(wxTextCtrlIface); |
0ec1179b VZ |
664 | }; |
665 | ||
666 | // ---------------------------------------------------------------------------- | |
667 | // wxTextCtrl: a single or multiple line text zone where user can edit text | |
668 | // ---------------------------------------------------------------------------- | |
669 | ||
53a2db12 | 670 | class WXDLLIMPEXP_CORE wxTextCtrlBase : public wxControl, |
0ec1179b VZ |
671 | #if wxHAS_TEXT_WINDOW_STREAM |
672 | public wxSTD streambuf, | |
673 | #endif | |
674 | public wxTextAreaBase, | |
675 | public wxTextEntry | |
676 | { | |
677 | public: | |
678 | // creation | |
679 | // -------- | |
680 | ||
681 | wxTextCtrlBase() { } | |
a0e55920 | 682 | virtual ~wxTextCtrlBase() { } |
0ec1179b VZ |
683 | |
684 | ||
685 | // more readable flag testing methods | |
686 | bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); } | |
687 | bool IsMultiLine() const { return !IsSingleLine(); } | |
a1b82138 | 688 | |
a1b82138 VZ |
689 | // stream-like insertion operators: these are always available, whether we |
690 | // were, or not, compiled with streambuf support | |
691 | wxTextCtrl& operator<<(const wxString& s); | |
692 | wxTextCtrl& operator<<(int i); | |
693 | wxTextCtrl& operator<<(long i); | |
9e50ed28 | 694 | wxTextCtrl& operator<<(float f) { return *this << double(f); } |
a1b82138 | 695 | wxTextCtrl& operator<<(double d); |
9e50ed28 VZ |
696 | wxTextCtrl& operator<<(char c) { return *this << wxString(c); } |
697 | wxTextCtrl& operator<<(wchar_t c) { return *this << wxString(c); } | |
a1b82138 | 698 | |
0ec1179b VZ |
699 | // insert the character which would have resulted from this key event, |
700 | // return true if anything has been inserted | |
701 | virtual bool EmulateKeyPress(const wxKeyEvent& event); | |
702 | ||
703 | ||
e39af974 | 704 | // do the window-specific processing after processing the update event |
d4864e97 VZ |
705 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); |
706 | ||
707 | virtual bool ShouldInheritColours() const { return false; } | |
e39af974 | 708 | |
0ec1179b VZ |
709 | // work around the problem with having HitTest() both in wxControl and |
710 | // wxTextAreaBase base classes | |
711 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const | |
712 | { | |
713 | return wxTextAreaBase::HitTest(pt, pos); | |
714 | } | |
715 | ||
716 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, | |
717 | wxTextCoord *col, | |
718 | wxTextCoord *row) const | |
719 | { | |
720 | return wxTextAreaBase::HitTest(pt, col, row); | |
721 | } | |
722 | ||
723 | // we provide stubs for these functions as not all platforms have styles | |
724 | // support, but we really should leave them pure virtual here | |
725 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); | |
726 | virtual bool GetStyle(long position, wxTextAttr& style); | |
727 | virtual bool SetDefaultStyle(const wxTextAttr& style); | |
728 | ||
3396739d VZ |
729 | // wxTextAreaBase overrides |
730 | virtual wxString GetValue() const | |
731 | { | |
732 | return wxTextEntry::GetValue(); | |
733 | } | |
734 | virtual void SetValue(const wxString& value) | |
735 | { | |
736 | wxTextEntry::SetValue(value); | |
737 | } | |
738 | ||
7dd65e5a VZ |
739 | // wxTextEntry overrides |
740 | virtual bool SetHint(const wxString& hint); | |
741 | ||
b7421ab6 VZ |
742 | // wxWindow overrides |
743 | virtual wxVisualAttributes GetDefaultAttributes() const | |
744 | { | |
745 | return GetClassDefaultAttributes(GetWindowVariant()); | |
746 | } | |
747 | ||
748 | static wxVisualAttributes | |
749 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL) | |
750 | { | |
751 | return GetCompositeControlsDefaultAttributes(variant); | |
752 | } | |
753 | ||
5bd3a2da | 754 | protected: |
6f02a879 VZ |
755 | // override streambuf method |
756 | #if wxHAS_TEXT_WINDOW_STREAM | |
757 | int overflow(int i); | |
758 | #endif // wxHAS_TEXT_WINDOW_STREAM | |
759 | ||
6ce83213 VZ |
760 | // Another wxTextAreaBase override. |
761 | virtual bool IsValidPosition(long pos) const | |
762 | { | |
763 | return pos >= 0 && pos <= GetLastPosition(); | |
764 | } | |
765 | ||
63f7d502 VZ |
766 | // implement the wxTextEntry pure virtual method |
767 | virtual wxWindow *GetEditableWindow() { return this; } | |
fc7a2a60 | 768 | |
c0c133e1 | 769 | wxDECLARE_NO_COPY_CLASS(wxTextCtrlBase); |
9d112688 | 770 | DECLARE_ABSTRACT_CLASS(wxTextCtrlBase) |
a1b82138 VZ |
771 | }; |
772 | ||
773 | // ---------------------------------------------------------------------------- | |
774 | // include the platform-dependent class definition | |
775 | // ---------------------------------------------------------------------------- | |
776 | ||
4175e952 RR |
777 | #if defined(__WXX11__) |
778 | #include "wx/x11/textctrl.h" | |
779 | #elif defined(__WXUNIVERSAL__) | |
1e6feb95 | 780 | #include "wx/univ/textctrl.h" |
9b141468 | 781 | #elif defined(__SMARTPHONE__) && defined(__WXWINCE__) |
302e251b | 782 | #include "wx/msw/wince/textctrlce.h" |
1e6feb95 | 783 | #elif defined(__WXMSW__) |
a1b82138 | 784 | #include "wx/msw/textctrl.h" |
2049ba38 | 785 | #elif defined(__WXMOTIF__) |
a1b82138 | 786 | #include "wx/motif/textctrl.h" |
1be7a35c | 787 | #elif defined(__WXGTK20__) |
a1b82138 | 788 | #include "wx/gtk/textctrl.h" |
1be7a35c MR |
789 | #elif defined(__WXGTK__) |
790 | #include "wx/gtk1/textctrl.h" | |
34138703 | 791 | #elif defined(__WXMAC__) |
ef0e9220 | 792 | #include "wx/osx/textctrl.h" |
e64df9bc DE |
793 | #elif defined(__WXCOCOA__) |
794 | #include "wx/cocoa/textctrl.h" | |
1777b9bb DW |
795 | #elif defined(__WXPM__) |
796 | #include "wx/os2/textctrl.h" | |
c801d85f KB |
797 | #endif |
798 | ||
c57e3339 VZ |
799 | // ---------------------------------------------------------------------------- |
800 | // wxTextCtrl events | |
801 | // ---------------------------------------------------------------------------- | |
802 | ||
3c778901 VZ |
803 | class WXDLLIMPEXP_FWD_CORE wxTextUrlEvent; |
804 | ||
ce7fe42e VZ |
805 | wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT, wxCommandEvent); |
806 | wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_ENTER, wxCommandEvent); | |
807 | wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_URL, wxTextUrlEvent); | |
808 | wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TEXT_MAXLEN, wxCommandEvent); | |
c57e3339 | 809 | |
53a2db12 | 810 | class WXDLLIMPEXP_CORE wxTextUrlEvent : public wxCommandEvent |
c57e3339 VZ |
811 | { |
812 | public: | |
d9e2e4c2 | 813 | wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse, |
c57e3339 | 814 | long start, long end) |
ce7fe42e | 815 | : wxCommandEvent(wxEVT_TEXT_URL, winid), |
7e7a19f1 | 816 | m_evtMouse(evtMouse), m_start(start), m_end(end) |
7ee31b00 | 817 | { } |
7e7a19f1 FM |
818 | wxTextUrlEvent(const wxTextUrlEvent& event) |
819 | : wxCommandEvent(event), | |
820 | m_evtMouse(event.m_evtMouse), | |
821 | m_start(event.m_start), | |
822 | m_end(event.m_end) { } | |
c57e3339 | 823 | |
1582a1db | 824 | // get the mouse event which happened over the URL |
c57e3339 VZ |
825 | const wxMouseEvent& GetMouseEvent() const { return m_evtMouse; } |
826 | ||
827 | // get the start of the URL | |
828 | long GetURLStart() const { return m_start; } | |
829 | ||
830 | // get the end of the URL | |
831 | long GetURLEnd() const { return m_end; } | |
832 | ||
7e7a19f1 FM |
833 | virtual wxEvent *Clone() const { return new wxTextUrlEvent(*this); } |
834 | ||
c57e3339 VZ |
835 | protected: |
836 | // the corresponding mouse event | |
837 | wxMouseEvent m_evtMouse; | |
838 | ||
839 | // the start and end indices of the URL in the text control | |
840 | long m_start, | |
841 | m_end; | |
842 | ||
843 | private: | |
7e7a19f1 | 844 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTextUrlEvent) |
c57e3339 VZ |
845 | |
846 | public: | |
847 | // for wxWin RTTI only, don't use | |
7ee31b00 | 848 | wxTextUrlEvent() : m_evtMouse(), m_start(0), m_end(0) { } |
c57e3339 VZ |
849 | }; |
850 | ||
851 | typedef void (wxEvtHandler::*wxTextUrlEventFunction)(wxTextUrlEvent&); | |
852 | ||
7fa03f04 | 853 | #define wxTextEventHandler(func) wxCommandEventHandler(func) |
b629d6d9 | 854 | #define wxTextUrlEventHandler(func) \ |
3c778901 | 855 | wxEVENT_HANDLER_CAST(wxTextUrlEventFunction, func) |
7fa03f04 VZ |
856 | |
857 | #define wx__DECLARE_TEXTEVT(evt, id, fn) \ | |
ce7fe42e | 858 | wx__DECLARE_EVT1(wxEVT_TEXT_ ## evt, id, wxTextEventHandler(fn)) |
7fa03f04 | 859 | |
b629d6d9 | 860 | #define wx__DECLARE_TEXTURLEVT(evt, id, fn) \ |
ce7fe42e | 861 | wx__DECLARE_EVT1(wxEVT_TEXT_ ## evt, id, wxTextUrlEventHandler(fn)) |
b629d6d9 | 862 | |
ce7fe42e | 863 | #define EVT_TEXT(id, fn) wx__DECLARE_EVT1(wxEVT_TEXT, id, wxTextEventHandler(fn)) |
7fa03f04 | 864 | #define EVT_TEXT_ENTER(id, fn) wx__DECLARE_TEXTEVT(ENTER, id, fn) |
b629d6d9 | 865 | #define EVT_TEXT_URL(id, fn) wx__DECLARE_TEXTURLEVT(URL, id, fn) |
7fa03f04 | 866 | #define EVT_TEXT_MAXLEN(id, fn) wx__DECLARE_TEXTEVT(MAXLEN, id, fn) |
c57e3339 | 867 | |
15cdc341 | 868 | #if wxHAS_TEXT_WINDOW_STREAM |
d73e6791 VZ |
869 | |
870 | // ---------------------------------------------------------------------------- | |
871 | // wxStreamToTextRedirector: this class redirects all data sent to the given | |
872 | // C++ stream to the wxTextCtrl given to its ctor during its lifetime. | |
873 | // ---------------------------------------------------------------------------- | |
874 | ||
53a2db12 | 875 | class WXDLLIMPEXP_CORE wxStreamToTextRedirector |
d73e6791 | 876 | { |
9806a823 | 877 | private: |
6eaebb29 | 878 | void Init(wxTextCtrl *text) |
d73e6791 VZ |
879 | { |
880 | m_sbufOld = m_ostr.rdbuf(); | |
881 | m_ostr.rdbuf(text); | |
882 | } | |
883 | ||
9806a823 VZ |
884 | public: |
885 | wxStreamToTextRedirector(wxTextCtrl *text) | |
886 | : m_ostr(wxSTD cout) | |
887 | { | |
6eaebb29 | 888 | Init(text); |
9806a823 VZ |
889 | } |
890 | ||
891 | wxStreamToTextRedirector(wxTextCtrl *text, wxSTD ostream *ostr) | |
892 | : m_ostr(*ostr) | |
893 | { | |
6eaebb29 | 894 | Init(text); |
9806a823 VZ |
895 | } |
896 | ||
d73e6791 VZ |
897 | ~wxStreamToTextRedirector() |
898 | { | |
899 | m_ostr.rdbuf(m_sbufOld); | |
900 | } | |
901 | ||
902 | private: | |
903 | // the stream we're redirecting | |
904 | wxSTD ostream& m_ostr; | |
905 | ||
906 | // the old streambuf (before we changed it) | |
907 | wxSTD streambuf *m_sbufOld; | |
908 | }; | |
909 | ||
15cdc341 | 910 | #endif // wxHAS_TEXT_WINDOW_STREAM |
d73e6791 | 911 | |
ce7fe42e VZ |
912 | // old wxEVT_COMMAND_* constants |
913 | #define wxEVT_COMMAND_TEXT_UPDATED wxEVT_TEXT | |
914 | #define wxEVT_COMMAND_TEXT_ENTER wxEVT_TEXT_ENTER | |
915 | #define wxEVT_COMMAND_TEXT_URL wxEVT_TEXT_URL | |
916 | #define wxEVT_COMMAND_TEXT_MAXLEN wxEVT_TEXT_MAXLEN | |
917 | ||
1e6feb95 VZ |
918 | #endif // wxUSE_TEXTCTRL |
919 | ||
c801d85f | 920 | #endif |
34138703 | 921 | // _WX_TEXTCTRL_H_BASE_ |