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