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