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