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