]> git.saurik.com Git - wxWidgets.git/blob - include/wx/textctrl.h
add yet another overload of assertEquals to fix another compilation error due to...
[wxWidgets.git] / include / wx / textctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textctrl.h
3 // Purpose: wxTextCtrlBase class - the interface of wxTextCtrl
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 13.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TEXTCTRL_H_BASE_
13 #define _WX_TEXTCTRL_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20
21 #if wxUSE_TEXTCTRL
22
23 #include "wx/control.h" // the base class
24 #include "wx/textentry.h" // single-line text entry interface
25 #include "wx/dynarray.h" // wxArrayInt
26 #include "wx/gdicmn.h" // wxPoint
27
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)
30 #if defined(__WATCOMC__) || \
31 defined(__MWERKS__) || \
32 ((defined(__VISUALC5__) || defined(__VISUALC6__)) && wxUSE_IOSTREAMH)
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
39 #endif
40
41 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
42 class WXDLLIMPEXP_FWD_CORE wxTextCtrlBase;
43
44 // ----------------------------------------------------------------------------
45 // wxTextCtrl types
46 // ----------------------------------------------------------------------------
47
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
52 // ----------------------------------------------------------------------------
53 // constants
54 // ----------------------------------------------------------------------------
55
56 extern WXDLLIMPEXP_DATA_CORE(const char) wxTextCtrlNameStr[];
57
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
63 // ----------------------------------------------------------------------------
64 // wxTextCtrl style flags
65 // ----------------------------------------------------------------------------
66
67 #define wxTE_NO_VSCROLL 0x0002
68
69 #define wxTE_READONLY 0x0010
70 #define wxTE_MULTILINE 0x0020
71 #define wxTE_PROCESS_TAB 0x0040
72
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
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
82
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 //
89 // this is for Win32 richedit and wxGTK2 multiline controls only so far
90 #define wxTE_AUTO_URL 0x1000
91
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
96 // use wxHSCROLL to not wrap text at all, wxTE_CHARWRAP to wrap it at any
97 // position and wxTE_WORDWRAP to wrap at words boundary
98 //
99 // if no wrapping style is given at all, the control wraps at word boundary
100 #define wxTE_DONTWRAP wxHSCROLL
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
105 #if WXWIN_COMPATIBILITY_2_6
106 // obsolete synonym
107 #define wxTE_LINEWRAP wxTE_CHARWRAP
108 #endif // WXWIN_COMPATIBILITY_2_6
109
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
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
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
126 // ----------------------------------------------------------------------------
127 // wxTextCtrl file types
128 // ----------------------------------------------------------------------------
129
130 #define wxTEXT_TYPE_ANY 0
131
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
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
164 enum wxTextAttrFlags
165 {
166 wxTEXT_ATTR_TEXT_COLOUR = 0x00000001,
167 wxTEXT_ATTR_BACKGROUND_COLOUR = 0x00000002,
168 wxTEXT_ATTR_FONT_FACE = 0x00000004,
169 wxTEXT_ATTR_FONT_SIZE = 0x00000008,
170 wxTEXT_ATTR_FONT_WEIGHT = 0x00000010,
171 wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
172 wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
173 wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
174 wxTEXT_ATTR_FONT = \
175 ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
176 wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING ),
177
178 wxTEXT_ATTR_ALIGNMENT = 0x00000080,
179 wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
180 wxTEXT_ATTR_RIGHT_INDENT = 0x00000200,
181 wxTEXT_ATTR_TABS = 0x00000400,
182
183 wxTEXT_ATTR_PARA_SPACING_AFTER = 0x00000800,
184 wxTEXT_ATTR_PARA_SPACING_BEFORE = 0x00001000,
185 wxTEXT_ATTR_LINE_SPACING = 0x00002000,
186 wxTEXT_ATTR_CHARACTER_STYLE_NAME = 0x00004000,
187 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME = 0x00008000,
188 wxTEXT_ATTR_LIST_STYLE_NAME = 0x00010000,
189 wxTEXT_ATTR_BULLET_STYLE = 0x00020000,
190 wxTEXT_ATTR_BULLET_NUMBER = 0x00040000,
191 wxTEXT_ATTR_BULLET_TEXT = 0x00080000,
192 wxTEXT_ATTR_BULLET_NAME = 0x00100000,
193 wxTEXT_ATTR_URL = 0x00200000,
194 wxTEXT_ATTR_PAGE_BREAK = 0x00400000,
195 wxTEXT_ATTR_EFFECTS = 0x00800000,
196 wxTEXT_ATTR_OUTLINE_LEVEL = 0x01000000,
197
198 /*!
199 * Character and paragraph combined styles
200 */
201
202 wxTEXT_ATTR_CHARACTER = \
203 (wxTEXT_ATTR_FONT|wxTEXT_ATTR_FONT_ENCODING|wxTEXT_ATTR_EFFECTS| \
204 wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL),
205
206 wxTEXT_ATTR_PARAGRAPH = \
207 (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
208 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
209 wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_TEXT|wxTEXT_ATTR_BULLET_NAME|\
210 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL),
211
212 wxTEXT_ATTR_ALL = (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
213 };
214
215 /*!
216 * Styles for wxTextAttr::SetBulletStyle
217 */
218 enum wxTextAttrBulletStyle
219 {
220 wxTEXT_ATTR_BULLET_STYLE_NONE = 0x00000000,
221 wxTEXT_ATTR_BULLET_STYLE_ARABIC = 0x00000001,
222 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER = 0x00000002,
223 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER = 0x00000004,
224 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER = 0x00000008,
225 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER = 0x00000010,
226 wxTEXT_ATTR_BULLET_STYLE_SYMBOL = 0x00000020,
227 wxTEXT_ATTR_BULLET_STYLE_BITMAP = 0x00000040,
228 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES = 0x00000080,
229 wxTEXT_ATTR_BULLET_STYLE_PERIOD = 0x00000100,
230 wxTEXT_ATTR_BULLET_STYLE_STANDARD = 0x00000200,
231 wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS = 0x00000400,
232 wxTEXT_ATTR_BULLET_STYLE_OUTLINE = 0x00000800,
233
234 wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT = 0x00000000,
235 wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT = 0x00001000,
236 wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE = 0x00002000
237 };
238
239 /*!
240 * Styles for wxTextAttr::SetTextEffects
241 */
242 enum wxTextAttrEffects
243 {
244 wxTEXT_ATTR_EFFECT_NONE = 0x00000000,
245 wxTEXT_ATTR_EFFECT_CAPITALS = 0x00000001,
246 wxTEXT_ATTR_EFFECT_SMALL_CAPITALS = 0x00000002,
247 wxTEXT_ATTR_EFFECT_STRIKETHROUGH = 0x00000004,
248 wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH = 0x00000008,
249 wxTEXT_ATTR_EFFECT_SHADOW = 0x00000010,
250 wxTEXT_ATTR_EFFECT_EMBOSS = 0x00000020,
251 wxTEXT_ATTR_EFFECT_OUTLINE = 0x00000040,
252 wxTEXT_ATTR_EFFECT_ENGRAVE = 0x00000080,
253 wxTEXT_ATTR_EFFECT_SUPERSCRIPT = 0x00000100,
254 wxTEXT_ATTR_EFFECT_SUBSCRIPT = 0x00000200
255 };
256
257 /*!
258 * Line spacing values
259 */
260 enum wxTextAttrLineSpacing
261 {
262 wxTEXT_ATTR_LINE_SPACING_NORMAL = 10,
263 wxTEXT_ATTR_LINE_SPACING_HALF = 15,
264 wxTEXT_ATTR_LINE_SPACING_TWICE = 20
265 };
266
267 // ----------------------------------------------------------------------------
268 // wxTextAttr: a structure containing the visual attributes of a text
269 // ----------------------------------------------------------------------------
270
271 class WXDLLIMPEXP_CORE wxTextAttr
272 {
273 public:
274 // ctors
275 wxTextAttr() { Init(); }
276 wxTextAttr(const wxTextAttr& attr) { Init(); Copy(attr); }
277 wxTextAttr(const wxColour& colText,
278 const wxColour& colBack = wxNullColour,
279 const wxFont& font = wxNullFont,
280 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
281
282 // Initialise this object.
283 void Init();
284
285 // Copy
286 void Copy(const wxTextAttr& attr);
287
288 // Assignment
289 void operator= (const wxTextAttr& attr);
290
291 // Equality test
292 bool operator== (const wxTextAttr& attr) const;
293
294 // Partial equality test taking flags into account
295 bool EqPartial(const wxTextAttr& attr, int flags) const;
296
297 // Get attributes from font.
298 bool GetFontAttributes(const wxFont& font, int flags = wxTEXT_ATTR_FONT);
299
300 // setters
301 void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; }
302 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; }
303 void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; }
304 void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; }
305 void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; }
306 void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; }
307
308 void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; }
309 void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; }
310 void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; }
311 void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
312 void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
313 void SetFontEncoding(wxFontEncoding encoding) { m_fontEncoding = encoding; m_flags |= wxTEXT_ATTR_FONT_ENCODING; }
314
315 // Set font
316 void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT) { GetFontAttributes(font, flags); }
317
318 void SetFlags(long flags) { m_flags = flags; }
319
320 void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; }
321 void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; }
322 void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
323 void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; }
324 void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; }
325 void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; }
326 void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; }
327 void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
328 void SetBulletText(const wxString& text) { m_bulletText = text; m_flags |= wxTEXT_ATTR_BULLET_TEXT; }
329 void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
330 void SetBulletName(const wxString& name) { m_bulletName = name; m_flags |= wxTEXT_ATTR_BULLET_NAME; }
331 void SetURL(const wxString& url) { m_urlTarget = url; m_flags |= wxTEXT_ATTR_URL; }
332 void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); }
333 void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); }
334 void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; }
335 void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); }
336
337 const wxColour& GetTextColour() const { return m_colText; }
338 const wxColour& GetBackgroundColour() const { return m_colBack; }
339 wxTextAttrAlignment GetAlignment() const { return m_textAlignment; }
340 const wxArrayInt& GetTabs() const { return m_tabs; }
341 long GetLeftIndent() const { return m_leftIndent; }
342 long GetLeftSubIndent() const { return m_leftSubIndent; }
343 long GetRightIndent() const { return m_rightIndent; }
344 long GetFlags() const { return m_flags; }
345
346 int GetFontSize() const { return m_fontSize; }
347 int GetFontStyle() const { return m_fontStyle; }
348 int GetFontWeight() const { return m_fontWeight; }
349 bool GetFontUnderlined() const { return m_fontUnderlined; }
350 const wxString& GetFontFaceName() const { return m_fontFaceName; }
351 wxFontEncoding GetFontEncoding() const { return m_fontEncoding; }
352
353 wxFont GetFont() const;
354
355 const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
356 const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
357 const wxString& GetListStyleName() const { return m_listStyleName; }
358 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
359 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
360
361 // TODO: should return the relative wxTextAttr* enumeration values
362 int GetLineSpacing() const { return m_lineSpacing; }
363 int GetBulletStyle() const { return m_bulletStyle; }
364 int GetBulletNumber() const { return m_bulletNumber; }
365 const wxString& GetBulletText() const { return m_bulletText; }
366 const wxString& GetBulletFont() const { return m_bulletFont; }
367 const wxString& GetBulletName() const { return m_bulletName; }
368 const wxString& GetURL() const { return m_urlTarget; }
369 int GetTextEffects() const { return m_textEffects; }
370 int GetTextEffectFlags() const { return m_textEffectFlags; }
371 int GetOutlineLevel() const { return m_outlineLevel; }
372
373 // accessors
374 bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
375 bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; }
376 bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) && HasFlag(wxTEXT_ATTR_ALIGNMENT) ; }
377 bool HasTabs() const { return HasFlag(wxTEXT_ATTR_TABS) ; }
378 bool HasLeftIndent() const { return HasFlag(wxTEXT_ATTR_LEFT_INDENT); }
379 bool HasRightIndent() const { return HasFlag(wxTEXT_ATTR_RIGHT_INDENT); }
380 bool HasFontWeight() const { return HasFlag(wxTEXT_ATTR_FONT_WEIGHT); }
381 bool HasFontSize() const { return HasFlag(wxTEXT_ATTR_FONT_SIZE); }
382 bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); }
383 bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); }
384 bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); }
385 bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); }
386 bool HasFont() const { return HasFlag(wxTEXT_ATTR_FONT); }
387
388 bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); }
389 bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); }
390 bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); }
391 bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) && !m_characterStyleName.IsEmpty(); }
392 bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && !m_paragraphStyleName.IsEmpty(); }
393 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
394 bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
395 bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
396 bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT); }
397 bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME); }
398 bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); }
399 bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); }
400 bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); }
401 bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); }
402 bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); }
403
404 bool HasFlag(long flag) const { return (m_flags & flag) != 0; }
405
406 // Is this a character style?
407 bool IsCharacterStyle() const { return HasFlag(wxTEXT_ATTR_CHARACTER); }
408 bool IsParagraphStyle() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH); }
409
410 // returns false if we have any attributes set, true otherwise
411 bool IsDefault() const
412 {
413 return GetFlags() == 0;
414 }
415
416 // Merges the given attributes. Does not affect 'this'. If compareWith
417 // is non-NULL, then it will be used to mask out those attributes that are the same in style
418 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
419 bool Apply(const wxTextAttr& style, const wxTextAttr* compareWith = NULL);
420
421 // merges the attributes of the base and the overlay objects and returns
422 // the result; the parameter attributes take precedence
423 //
424 // WARNING: the order of arguments is the opposite of Combine()
425 static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay)
426 {
427 return Combine(overlay, base, NULL);
428 }
429
430 // merges the attributes of this object and overlay
431 void Merge(const wxTextAttr& overlay)
432 {
433 *this = Merge(*this, overlay);
434 }
435
436 // return the attribute having the valid font and colours: it uses the
437 // attributes set in attr and falls back first to attrDefault and then to
438 // the text control font/colours for those attributes which are not set
439 static wxTextAttr Combine(const wxTextAttr& attr,
440 const wxTextAttr& attrDef,
441 const wxTextCtrlBase *text);
442
443 // Compare tabs
444 static bool TabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2);
445
446 // Remove attributes
447 static bool RemoveStyle(wxTextAttr& destStyle, const wxTextAttr& style);
448
449 // Combine two bitlists, specifying the bits of interest with separate flags.
450 static bool CombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB);
451
452 // Compare two bitlists
453 static bool BitlistsEqPartial(int valueA, int valueB, int flags);
454
455 // Split into paragraph and character styles
456 static bool SplitParaCharStyles(const wxTextAttr& style, wxTextAttr& parStyle, wxTextAttr& charStyle);
457
458 private:
459 long m_flags;
460
461 // Paragraph styles
462 wxArrayInt m_tabs; // array of int: tab stops in 1/10 mm
463 int m_leftIndent; // left indent in 1/10 mm
464 int m_leftSubIndent; // left indent for all but the first
465 // line in a paragraph relative to the
466 // first line, in 1/10 mm
467 int m_rightIndent; // right indent in 1/10 mm
468 wxTextAttrAlignment m_textAlignment;
469
470 int m_paragraphSpacingAfter;
471 int m_paragraphSpacingBefore;
472 int m_lineSpacing;
473 int m_bulletStyle;
474 int m_bulletNumber;
475 int m_textEffects;
476 int m_textEffectFlags;
477 int m_outlineLevel;
478 wxString m_bulletText;
479 wxString m_bulletFont;
480 wxString m_bulletName;
481 wxString m_urlTarget;
482 wxFontEncoding m_fontEncoding;
483
484 // Character styles
485 wxColour m_colText,
486 m_colBack;
487 int m_fontSize;
488 int m_fontStyle;
489 int m_fontWeight;
490 bool m_fontUnderlined;
491 wxString m_fontFaceName;
492
493 // Character style
494 wxString m_characterStyleName;
495
496 // Paragraph style
497 wxString m_paragraphStyleName;
498
499 // List style
500 wxString m_listStyleName;
501 };
502
503 // ----------------------------------------------------------------------------
504 // wxTextAreaBase: multiline text control specific methods
505 // ----------------------------------------------------------------------------
506
507 class WXDLLIMPEXP_CORE wxTextAreaBase
508 {
509 public:
510 wxTextAreaBase() { }
511 virtual ~wxTextAreaBase() { }
512
513 // lines access
514 // ------------
515
516 virtual int GetLineLength(long lineNo) const = 0;
517 virtual wxString GetLineText(long lineNo) const = 0;
518 virtual int GetNumberOfLines() const = 0;
519
520
521 // file IO
522 // -------
523
524 bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY)
525 { return DoLoadFile(file, fileType); }
526 bool SaveFile(const wxString& file = wxEmptyString,
527 int fileType = wxTEXT_TYPE_ANY);
528
529 // dirty flag handling
530 // -------------------
531
532 virtual bool IsModified() const = 0;
533 virtual void MarkDirty() = 0;
534 virtual void DiscardEdits() = 0;
535 void SetModified(bool modified)
536 {
537 if ( modified )
538 MarkDirty();
539 else
540 DiscardEdits();
541 }
542
543
544 // styles handling
545 // ---------------
546
547 // text control under some platforms supports the text styles: these
548 // methods allow to apply the given text style to the given selection or to
549 // set/get the style which will be used for all appended text
550 virtual bool SetStyle(long start, long end, const wxTextAttr& style) = 0;
551 virtual bool GetStyle(long position, wxTextAttr& style) = 0;
552 virtual bool SetDefaultStyle(const wxTextAttr& style) = 0;
553 virtual const wxTextAttr& GetDefaultStyle() const { return m_defaultStyle; }
554
555
556 // coordinates translation
557 // -----------------------
558
559 // translate between the position (which is just an index in the text ctrl
560 // considering all its contents as a single strings) and (x, y) coordinates
561 // which represent column and line.
562 virtual long XYToPosition(long x, long y) const = 0;
563 virtual bool PositionToXY(long pos, long *x, long *y) const = 0;
564
565 virtual void ShowPosition(long pos) = 0;
566
567 // find the character at position given in pixels
568 //
569 // NB: pt is in device coords (not adjusted for the client area origin nor
570 // scrolling)
571 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
572 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
573 wxTextCoord *col,
574 wxTextCoord *row) const;
575
576 protected:
577 // implementation of loading/saving
578 virtual bool DoLoadFile(const wxString& file, int fileType) = 0;
579 virtual bool DoSaveFile(const wxString& file, int fileType) = 0;
580
581
582 // the name of the last file loaded with LoadFile() which will be used by
583 // SaveFile() by default
584 wxString m_filename;
585
586 // the text style which will be used for any new text added to the control
587 wxTextAttr m_defaultStyle;
588
589
590 DECLARE_NO_COPY_CLASS(wxTextAreaBase)
591 };
592
593 // this class defines wxTextCtrl interface, wxTextCtrlBase actually implements
594 // too much things because it derives from wxTextEntry and not wxTextEntryBase
595 // and so any classes which "look like" wxTextCtrl (such as wxRichTextCtrl)
596 // but don't need the (native) implementation bits from wxTextEntry should
597 // actually derive from this one and not wxTextCtrlBase
598 class WXDLLIMPEXP_CORE wxTextCtrlIface : public wxTextAreaBase,
599 public wxTextEntryBase
600 {
601 public:
602 wxTextCtrlIface() { }
603
604 private:
605 DECLARE_NO_COPY_CLASS(wxTextCtrlIface)
606 };
607
608 // ----------------------------------------------------------------------------
609 // wxTextCtrl: a single or multiple line text zone where user can edit text
610 // ----------------------------------------------------------------------------
611
612 class WXDLLIMPEXP_CORE wxTextCtrlBase : public wxControl,
613 #if wxHAS_TEXT_WINDOW_STREAM
614 public wxSTD streambuf,
615 #endif
616 public wxTextAreaBase,
617 public wxTextEntry
618 {
619 public:
620 // creation
621 // --------
622
623 wxTextCtrlBase() { }
624 virtual ~wxTextCtrlBase() { }
625
626
627 // more readable flag testing methods
628 bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); }
629 bool IsMultiLine() const { return !IsSingleLine(); }
630
631 // stream-like insertion operators: these are always available, whether we
632 // were, or not, compiled with streambuf support
633 wxTextCtrl& operator<<(const wxString& s);
634 wxTextCtrl& operator<<(int i);
635 wxTextCtrl& operator<<(long i);
636 wxTextCtrl& operator<<(float f) { return *this << double(f); }
637 wxTextCtrl& operator<<(double d);
638 wxTextCtrl& operator<<(char c) { return *this << wxString(c); }
639 wxTextCtrl& operator<<(wchar_t c) { return *this << wxString(c); }
640
641 // insert the character which would have resulted from this key event,
642 // return true if anything has been inserted
643 virtual bool EmulateKeyPress(const wxKeyEvent& event);
644
645
646 // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does and
647 // return true if the event was processed
648 static bool SendTextUpdatedEvent(wxWindow *win);
649 bool SendTextUpdatedEvent() { return SendTextUpdatedEvent(this); }
650
651 // do the window-specific processing after processing the update event
652 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
653
654 virtual bool ShouldInheritColours() const { return false; }
655
656 // work around the problem with having HitTest() both in wxControl and
657 // wxTextAreaBase base classes
658 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const
659 {
660 return wxTextAreaBase::HitTest(pt, pos);
661 }
662
663 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
664 wxTextCoord *col,
665 wxTextCoord *row) const
666 {
667 return wxTextAreaBase::HitTest(pt, col, row);
668 }
669
670 // we provide stubs for these functions as not all platforms have styles
671 // support, but we really should leave them pure virtual here
672 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
673 virtual bool GetStyle(long position, wxTextAttr& style);
674 virtual bool SetDefaultStyle(const wxTextAttr& style);
675
676 protected:
677 // override streambuf method
678 #if wxHAS_TEXT_WINDOW_STREAM
679 int overflow(int i);
680 #endif // wxHAS_TEXT_WINDOW_STREAM
681
682 virtual bool DoLoadFile(const wxString& file, int fileType);
683 virtual bool DoSaveFile(const wxString& file, int fileType);
684
685
686 DECLARE_NO_COPY_CLASS(wxTextCtrlBase)
687 DECLARE_ABSTRACT_CLASS(wxTextCtrlBase)
688 };
689
690 // ----------------------------------------------------------------------------
691 // include the platform-dependent class definition
692 // ----------------------------------------------------------------------------
693
694 #if defined(__WXX11__)
695 #include "wx/x11/textctrl.h"
696 #elif defined(__WXUNIVERSAL__)
697 #include "wx/univ/textctrl.h"
698 #elif defined(__SMARTPHONE__) && defined(__WXWINCE__)
699 #include "wx/msw/wince/textctrlce.h"
700 #elif defined(__WXMSW__)
701 #include "wx/msw/textctrl.h"
702 #elif defined(__WXMOTIF__)
703 #include "wx/motif/textctrl.h"
704 #elif defined(__WXGTK20__)
705 #include "wx/gtk/textctrl.h"
706 #elif defined(__WXGTK__)
707 #include "wx/gtk1/textctrl.h"
708 #elif defined(__WXMAC__)
709 #include "wx/osx/textctrl.h"
710 #elif defined(__WXCOCOA__)
711 #include "wx/cocoa/textctrl.h"
712 #elif defined(__WXPM__)
713 #include "wx/os2/textctrl.h"
714 #elif defined(__WXPALMOS__)
715 #include "wx/palmos/textctrl.h"
716 #endif
717
718 // ----------------------------------------------------------------------------
719 // wxTextCtrl events
720 // ----------------------------------------------------------------------------
721
722 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_UPDATED;
723 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_ENTER;
724 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_URL;
725 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
726
727 class WXDLLIMPEXP_CORE wxTextUrlEvent : public wxCommandEvent
728 {
729 public:
730 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
731 long start, long end)
732 : wxCommandEvent(wxEVT_COMMAND_TEXT_URL, winid)
733 , m_evtMouse(evtMouse), m_start(start), m_end(end)
734 { }
735
736 // get the mouse event which happend over the URL
737 const wxMouseEvent& GetMouseEvent() const { return m_evtMouse; }
738
739 // get the start of the URL
740 long GetURLStart() const { return m_start; }
741
742 // get the end of the URL
743 long GetURLEnd() const { return m_end; }
744
745 protected:
746 // the corresponding mouse event
747 wxMouseEvent m_evtMouse;
748
749 // the start and end indices of the URL in the text control
750 long m_start,
751 m_end;
752
753 private:
754 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextUrlEvent)
755
756 public:
757 // for wxWin RTTI only, don't use
758 wxTextUrlEvent() : m_evtMouse(), m_start(0), m_end(0) { }
759 };
760
761 typedef void (wxEvtHandler::*wxTextUrlEventFunction)(wxTextUrlEvent&);
762
763 #define wxTextEventHandler(func) wxCommandEventHandler(func)
764 #define wxTextUrlEventHandler(func) \
765 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxTextUrlEventFunction, &func)
766
767 #define wx__DECLARE_TEXTEVT(evt, id, fn) \
768 wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_ ## evt, id, wxTextEventHandler(fn))
769
770 #define wx__DECLARE_TEXTURLEVT(evt, id, fn) \
771 wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_ ## evt, id, wxTextUrlEventHandler(fn))
772
773 #define EVT_TEXT(id, fn) wx__DECLARE_TEXTEVT(UPDATED, id, fn)
774 #define EVT_TEXT_ENTER(id, fn) wx__DECLARE_TEXTEVT(ENTER, id, fn)
775 #define EVT_TEXT_URL(id, fn) wx__DECLARE_TEXTURLEVT(URL, id, fn)
776 #define EVT_TEXT_MAXLEN(id, fn) wx__DECLARE_TEXTEVT(MAXLEN, id, fn)
777
778 #if wxHAS_TEXT_WINDOW_STREAM
779
780 // ----------------------------------------------------------------------------
781 // wxStreamToTextRedirector: this class redirects all data sent to the given
782 // C++ stream to the wxTextCtrl given to its ctor during its lifetime.
783 // ----------------------------------------------------------------------------
784
785 class WXDLLIMPEXP_CORE wxStreamToTextRedirector
786 {
787 private:
788 void Init(wxTextCtrl *text)
789 {
790 m_sbufOld = m_ostr.rdbuf();
791 m_ostr.rdbuf(text);
792 }
793
794 public:
795 wxStreamToTextRedirector(wxTextCtrl *text)
796 : m_ostr(wxSTD cout)
797 {
798 Init(text);
799 }
800
801 wxStreamToTextRedirector(wxTextCtrl *text, wxSTD ostream *ostr)
802 : m_ostr(*ostr)
803 {
804 Init(text);
805 }
806
807 ~wxStreamToTextRedirector()
808 {
809 m_ostr.rdbuf(m_sbufOld);
810 }
811
812 private:
813 // the stream we're redirecting
814 wxSTD ostream& m_ostr;
815
816 // the old streambuf (before we changed it)
817 wxSTD streambuf *m_sbufOld;
818 };
819
820 #endif // wxHAS_TEXT_WINDOW_STREAM
821
822 #endif // wxUSE_TEXTCTRL
823
824 #endif
825 // _WX_TEXTCTRL_H_BASE_