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