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