]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/text.tex
70b60ee31a9d618162b3510dad98d0b4f4919812
[wxWidgets.git] / docs / latex / wx / text.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextAttr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 \section{\class{wxTextAttr}}\label{wxtextattr}
4
5 wxTextAttr represents the character and paragraph attributes, or style, for a range of text in a\rtfsp
6 \helpref{wxTextCtrl}{wxtextctrl}.
7
8 When setting up a wxTextAttr object, pass a bitlist mask to SetFlags to indicate
9 which style elements should be changed. As a convenience, when you call a
10 setter such as SetFont, the relevant bit will be set.
11
12 \wxheading{Derived from}
13
14 No base class
15
16 \wxheading{Include files}
17
18 <wx/textctrl.h>
19
20 \wxheading{Typedefs}
21
22 \texttt{wxTextPos} is the type containing the index of a position in a text
23 control. \texttt{wxTextCoord} contains the index of a column or a row in the
24 control.
25
26 Note that alghough both of these types should probably have been unsigned, due
27 to backwards compatibility reasons, are defined as \texttt{long} currently.
28 Their use (instead of plain \texttt{long}) is still encouraged as it makes the
29 code more readable.
30
31 \wxheading{Constants}
32
33 The following values can be passed to SetAlignment to determine
34 paragraph alignment.
35
36 {\small
37 \begin{verbatim}
38 enum wxTextAttrAlignment
39 {
40 wxTEXT_ALIGNMENT_DEFAULT,
41 wxTEXT_ALIGNMENT_LEFT,
42 wxTEXT_ALIGNMENT_CENTRE,
43 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
44 wxTEXT_ALIGNMENT_RIGHT,
45 wxTEXT_ALIGNMENT_JUSTIFIED
46 };
47 \end{verbatim}
48 }
49
50 These values are passed in a bitlist to SetFlags to determine
51 what attributes will be considered when setting the attributes
52 for a text control.
53
54 {\small
55 \begin{verbatim}
56 #define wxTEXT_ATTR_TEXT_COLOUR 0x0001
57 #define wxTEXT_ATTR_BACKGROUND_COLOUR 0x0002
58 #define wxTEXT_ATTR_FONT_FACE 0x0004
59 #define wxTEXT_ATTR_FONT_SIZE 0x0008
60 #define wxTEXT_ATTR_FONT_WEIGHT 0x0010
61 #define wxTEXT_ATTR_FONT_ITALIC 0x0020
62 #define wxTEXT_ATTR_FONT_UNDERLINE 0x0040
63 #define wxTEXT_ATTR_FONT \
64 wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT \
65 | wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE
66 #define wxTEXT_ATTR_ALIGNMENT 0x0080
67 #define wxTEXT_ATTR_LEFT_INDENT 0x0100
68 #define wxTEXT_ATTR_RIGHT_INDENT 0x0200
69 #define wxTEXT_ATTR_TABS 0x0400
70 \end{verbatim}
71 }
72
73 The values below are the possible return codes of the
74 \helpref{HitTest}{wxtextctrlhittest} method:
75 {\small
76 \begin{verbatim}
77 // the point asked is ...
78 enum wxTextCtrlHitTestResult
79 {
80 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
81 wxTE_HT_BEFORE, // either to the left or upper
82 wxTE_HT_ON_TEXT, // directly on
83 wxTE_HT_BELOW, // below [the last line]
84 wxTE_HT_BEYOND // after [the end of line]
85 };
86 // ... the character returned
87 \end{verbatim}
88 }
89
90
91 \latexignore{\rtfignore{\wxheading{Members}}}
92
93
94 \membersection{wxTextAttr::wxTextAttr}\label{wxtextattrctor}
95
96 \func{}{wxTextAttr}{\void}
97
98 \func{}{wxTextAttr}{\param{const wxColour\& }{colText}, \param{const wxColour\& }{colBack = wxNullColour},
99 \param{const wxFont\& }{font = wxNullFont}, \param{wxTextAttrAlignment }{alignment = wxTEXT\_ALIGNMENT\_DEFAULT}}
100
101 The constructors initialize one or more of the text foreground colour, background
102 colour, font, and alignment. The values not initialized in the constructor can be set
103 later, otherwise \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle} will use
104 the default values for them.
105
106
107 \membersection{wxTextAttr::GetAlignment}\label{wxtextattrgetalignment}
108
109 \constfunc{wxTextAttrAlignment}{GetAlignment}{\void}
110
111 Returns the paragraph alignment.
112
113
114 \membersection{wxTextAttr::GetBackgroundColour}\label{wxtextattrgetbackgroundcolour}
115
116 \constfunc{const wxColour\&}{GetBackgroundColour}{\void}
117
118 Return the background colour specified by this attribute.
119
120
121 \membersection{wxTextAttr::GetFont}\label{wxtextattrgetfont}
122
123 \constfunc{const wxFont\&}{GetFont}{\void}
124
125 Return the text font specified by this attribute.
126
127
128 \membersection{wxTextAttr::GetLeftIndent}\label{wxtextattrgetleftindent}
129
130 \constfunc{int}{GetLeftIndent}{\void}
131
132 Returns the left indent in tenths of a millimetre.
133
134
135 \membersection{wxTextAttr::GetRightIndent}\label{wxtextattrgetrightindent}
136
137 \constfunc{int}{GetRightIndent}{\void}
138
139 Returns the right indent in tenths of a millimetre.
140
141
142 \membersection{wxTextAttr::GetTabs}\label{wxtextattrgettabs}
143
144 \constfunc{const wxArrayInt\&}{GetTabs}{\void}
145
146 Returns the array of integers representing the tab stops. Each
147 array element specifies the tab stop in tenths of a millimetre.
148
149
150 \membersection{wxTextAttr::GetTextColour}\label{wxtextattrgettextcolour}
151
152 \constfunc{const wxColour\&}{GetTextColour}{\void}
153
154 Return the text colour specified by this attribute.
155
156
157 \membersection{wxTextAttr::HasBackgroundColour}\label{wxtextattrhasbackgroundcolour}
158
159 \constfunc{bool}{HasBackgroundColour}{\void}
160
161 Returns {\tt true} if this style specifies the background colour to use.
162
163
164 \membersection{wxTextAttr::HasFont}\label{wxtextattrhasfont}
165
166 \constfunc{bool}{HasFont}{\void}
167
168 Returns {\tt true} if this style specifies the font to use.
169
170
171 \membersection{wxTextAttr::HasTextColour}\label{wxtextattrhastextcolour}
172
173 \constfunc{bool}{HasTextColour}{\void}
174
175 Returns {\tt true} if this style specifies the foreground colour to use.
176
177
178 \membersection{wxTextAttr::GetFlags}\label{wxtextattrgetflags}
179
180 \func{long}{GetFlags}{\void}
181
182 Returns a bitlist indicating which attributes will be set.
183
184
185 \membersection{wxTextAttr::IsDefault}\label{wxtextattrisdefault}
186
187 \constfunc{bool}{IsDefault}{\void}
188
189 Returns {\tt true} if this style specifies any non-default attributes.
190
191
192 \membersection{wxTextAttr::SetAlignment}\label{wxtextattrsetalignment}
193
194 \func{void}{SetAlignment}{\param{wxTextAttrAlignment}{ alignment}}
195
196 Sets the paragraph alignment.
197
198
199 \membersection{wxTextAttr::SetBackgroundColour}\label{wxtextattrsetbackgroundcolour}
200
201 \func{void}{SetBackgroundColour}{\param{const wxColour\& }{colour}}
202
203 Sets the background colour.
204
205
206 \membersection{wxTextAttr::SetFlags}\label{wxtextattrsetflags}
207
208 \func{void}{SetFlags}{\param{long}{ flags}}
209
210 Pass a bitlist indicating which attributes will be set.
211
212
213 \membersection{wxTextAttr::SetFont}\label{wxtextattrsetfont}
214
215 \func{void}{SetFont}{\param{const wxFont\&}{ font}}
216
217 Sets the text font.
218
219
220 \membersection{wxTextAttr::SetLeftIndent}\label{wxtextattrsetleftindent}
221
222 \func{void}{SetLeftIndent}{\param{int }{indent}}
223
224 Sets the left indent in tenths of a millimetre.
225
226
227 \membersection{wxTextAttr::SetRightIndent}\label{wxtextattrsetrightindent}
228
229 \func{void}{SetRightIndent}{\param{int }{indent}}
230
231 Sets the right indent in tenths of a millimetre.
232
233
234 \membersection{wxTextAttr::SetTabs}\label{wxtextattrsettabs}
235
236 \func{void}{SetTabs}{\param{const wxArrayInt\&}{ tabs}}
237
238 Sets the array of integers representing the tab stops. Each
239 array element specifies the tab stop in tenths of a millimetre.
240
241
242 \membersection{wxTextAttr::SetTextColour}\label{wxtextattrsettextcolour}
243
244 \func{void}{SetTextColour}{\param{const wxColour\& }{colour}}
245
246 Sets the text colour.
247
248
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250
251 \section{\class{wxTextCtrl}}\label{wxtextctrl}
252
253 A text control allows text to be displayed and edited. It may be
254 single line or multi-line.
255
256 \wxheading{Derived from}
257
258 streambuf\\
259 \helpref{wxControl}{wxcontrol}\\
260 \helpref{wxWindow}{wxwindow}\\
261 \helpref{wxEvtHandler}{wxevthandler}\\
262 \helpref{wxObject}{wxobject}
263
264 \wxheading{Include files}
265
266 <wx/textctrl.h>
267
268 \wxheading{Window styles}
269
270 \twocolwidtha{5cm}
271 \begin{twocollist}\itemsep=0pt
272 \twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The control will generate
273 the message wxEVENT\_TYPE\_TEXT\_ENTER\_COMMAND (otherwise pressing Enter key
274 is either processed internally by the control or used for navigation between
275 dialog controls).}
276 \twocolitem{\windowstyle{wxTE\_PROCESS\_TAB}}{The control will receive
277 EVT\_CHAR messages for TAB pressed - normally, TAB is used for passing to the
278 next control in a dialog instead. For the control created with this style,
279 you can still use Ctrl-Enter to pass to the next control from the keyboard.}
280 \twocolitem{\windowstyle{wxTE\_MULTILINE}}{The text control allows multiple lines.}
281 \twocolitem{\windowstyle{wxTE\_PASSWORD}}{The text will be echoed as asterisks.}
282 \twocolitem{\windowstyle{wxTE\_READONLY}}{The text will not be user-editable.}
283 \twocolitem{\windowstyle{wxTE\_RICH}}{Use rich text control under Win32, this
284 allows to have more than 64Kb of text in the control even under Win9x. This
285 style is ignored under other platforms.}
286 \twocolitem{\windowstyle{wxTE\_RICH2}}{Use rich text control version 2.0 or 3.0
287 under Win32, this style is ignored under other platforms}
288 \twocolitem{\windowstyle{wxTE\_AUTO\_URL}}{Highlight the URLs and generate the
289 wxTextUrlEvents when mouse events occur over them. This style is supported
290 under Win32 only and requires wxTE\_RICH.}
291 \twocolitem{\windowstyle{wxTE\_NOHIDESEL}}{By default, the Windows text control
292 doesn't show the selection when it doesn't have focus - use this style to force
293 it to always show it. It doesn't do anything under other platforms.}
294 \twocolitem{\windowstyle{wxHSCROLL}}{A horizontal scrollbar will be created and
295 used, so that text won't be wrapped. No effect under GTK+.}
296 \twocolitem{\windowstyle{wxTE\_LEFT}}{The text in the control will be left-justified (default).}
297 \twocolitem{\windowstyle{wxTE\_CENTRE}}{The text in the control will be centered.}
298 \twocolitem{\windowstyle{wxTE\_RIGHT}}{The text in the control will be right-justified.}
299 \twocolitem{\windowstyle{wxTE\_DONTWRAP}}{Same as {\tt wxHSCROLL} style.}
300 \twocolitem{\windowstyle{wxTE\_LINEWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv only currently).}
301 \twocolitem{\windowstyle{wxTE\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries only (wxUniv only currently).}
302 \end{twocollist}
303
304 See also \helpref{window styles overview}{windowstyles} and
305 \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}.
306
307 \wxheading{wxTextCtrl text format}
308
309 The multiline text controls always store the text as a sequence of lines
310 separated by {\tt $\backslash$n} characters, i.e. in the Unix text format even
311 on non-Unix platforms. This allows the user code to ignore the differences
312 between the platforms but at a price: the indices in the control such as those
313 returned by \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} or
314 \helpref{GetSelection}{wxtextctrlgetselection} can {\bf not} be used as
315 indices into the string returned by \helpref{GetValue}{wxtextctrlgetvalue} as
316 they're going to be slightly off for platforms using
317 {\tt $\backslash$r$\backslash$n} as separator (as Windows does), for example.
318
319 Instead, if you need to obtain a substring between the $2$ indices obtained
320 from the control with the help of the functions mentioned above, you should
321 use \helpref{GetRange}{wxtextctrlgetrange}. And the indices themselves can
322 only be passed to other methods, for example
323 \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint} or
324 \helpref{SetSelection}{wxtextctrlsetselection}.
325
326 To summarize: never use the indices returned by (multiline) wxTextCtrl as
327 indices into the string it contains, but only as arguments to be passed back
328 to the other wxTextCtrl methods.
329
330 \wxheading{wxTextCtrl styles}
331
332 Multi-line text controls support the styles, i.e. provide a possibility to set
333 colours and font for individual characters in it (note that under Windows {\tt
334 wxTE\_RICH} style is required for style support). To use the styles you can
335 either call \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} before
336 inserting the text or call \helpref{SetStyle}{wxtextctrlsetstyle} later to
337 change the style of the text already in the control (the first solution is
338 much more efficient).
339
340 In either case, if the style doesn't specify some of the attributes (for
341 example you only want to set the text colour but without changing the font nor
342 the text background), the values of the default style will be used for them.
343 If there is no default style, the attributes of the text control itself are
344 used.
345
346 So the following code correctly describes what it does: the second call
347 to \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} doesn't change the
348 text foreground colour (which stays red) while the last one doesn't change the
349 background colour (which stays grey):
350
351 {\small%
352 \begin{verbatim}
353 text->SetDefaultStyle(wxTextAttr(*wxRED));
354 text->AppendText("Red text\n");
355 text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
356 text->AppendText("Red on grey text\n");
357 text->SetDefaultStyle(wxTextAttr(*wxBLUE);
358 text->AppendText("Blue on grey text\n");
359 \end{verbatim}
360 }%
361
362 \wxheading{wxTextCtrl and C++ streams}
363
364 This class multiply-inherits from {\bf streambuf} where compilers allow,
365 allowing code such as the following:
366
367 {\small%
368 \begin{verbatim}
369 wxTextCtrl *control = new wxTextCtrl(...);
370
371 ostream stream(control)
372
373 stream << 123.456 << " some text\n";
374 stream.flush();
375 \end{verbatim}
376 }%
377
378 If your compiler does not support derivation from {\bf streambuf} and gives a
379 compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
380 wxTextCtrl header file.
381
382 Note that independently of this setting you can always use wxTextCtrl itself
383 in a stream-like manner:
384
385 {\small%
386 \begin{verbatim}
387 wxTextCtrl *control = new wxTextCtrl(...);
388
389 *control << 123.456 << " some text\n";
390 \end{verbatim}
391 }%
392
393 always works. However the possibility to create an ostream associated with
394 wxTextCtrl may be useful if you need to redirect the output of a function
395 taking an ostream as parameter to a text control.
396
397 Another commonly requested need is to redirect {\bf std::cout} to the text
398 control. This could be done in the following way:
399
400 {\small%
401 \begin{verbatim}
402 #include <iostream>
403
404 wxTextCtrl *control = new wxTextCtrl(...);
405
406 std::streambuf *sbOld = std::cout.rdbuf();
407 std::cout.rdbuf(*control);
408
409 // use cout as usual, the output appears in the text control
410 ...
411
412 std::cout.rdbuf(sbOld);
413 \end{verbatim}
414 }%
415
416 But wxWindows provides a convenient class to make it even simpler so instead
417 you may just do
418
419 {\small%
420 \begin{verbatim}
421 #include <iostream>
422
423 wxTextCtrl *control = new wxTextCtrl(...);
424
425 wxStreamToTextRedirector redirect(control);
426
427 // all output to cout goes into the text control until the exit from current
428 // scope
429 \end{verbatim}
430 }%
431
432 See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
433 details.
434
435 \wxheading{Event handling}
436
437 The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
438 wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
439 automatically, when the control has the focus.
440
441 To process input from a text control, use these event handler macros to direct input to member
442 functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
443
444 \twocolwidtha{7cm}%
445 \begin{twocollist}\itemsep=0pt
446 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
447 generated when the text changes. Notice that this event will always be sent
448 when the text controls contents changes - whether this is due to user input or
449 comes from the program itself (for example, if SetValue() is called)}
450 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
451 generated when enter is pressed in a text control (which must have
452 wxTE\_PROCESS\_ENTER style for this event to be generated).}
453 \twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occured over an URL
454 in the text control (Win32 only)}
455 \twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
456 into the control than the limit set by
457 \helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
458 \end{twocollist}%
459
460 \latexignore{\rtfignore{\wxheading{Members}}}
461
462
463 \membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlconstr}
464
465 \func{}{wxTextCtrl}{\void}
466
467 Default constructor.
468
469 \func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
470 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
471 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
472
473 Constructor, creating and showing a text control.
474
475 \wxheading{Parameters}
476
477 \docparam{parent}{Parent window. Should not be NULL.}
478
479 \docparam{id}{Control identifier. A value of -1 denotes a default value.}
480
481 \docparam{value}{Default text value.}
482
483 \docparam{pos}{Text control position.}
484
485 \docparam{size}{Text control size.}
486
487 \docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
488
489 \docparam{validator}{Window validator.}
490
491 \docparam{name}{Window name.}
492
493 \wxheading{Remarks}
494
495 The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
496 for multi-line text controls.
497 Without a horizontal scrollbar, text lines that don't fit in the control's
498 size will be wrapped (but no newline character is inserted). Single line
499 controls don't have a horizontal scrollbar, the text is automatically scrolled
500 so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
501 visible.
502
503 % VZ: this is no longer true
504 %Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
505 %as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
506 %apply.
507
508 \wxheading{See also}
509
510 \helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
511
512
513 \membersection{wxTextCtrl::\destruct{wxTextCtrl}}
514
515 \func{}{\destruct{wxTextCtrl}}{\void}
516
517 Destructor, destroying the text control.
518
519
520 \membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
521
522 \func{void}{AppendText}{\param{const wxString\& }{ text}}
523
524 Appends the text to the end of the text control.
525
526 \wxheading{Parameters}
527
528 \docparam{text}{Text to write to the text control.}
529
530 \wxheading{Remarks}
531
532 After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
533 the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
534
535 \wxheading{See also}
536
537 \helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
538
539
540 \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
541
542 \func{virtual bool}{CanCopy}{\void}
543
544 Returns {\tt true} if the selection can be copied to the clipboard.
545
546
547 \membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
548
549 \func{virtual bool}{CanCut}{\void}
550
551 Returns {\tt true} if the selection can be cut to the clipboard.
552
553
554 \membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
555
556 \func{virtual bool}{CanPaste}{\void}
557
558 Returns {\tt true} if the contents of the clipboard can be pasted into the
559 text control. On some platforms (Motif, GTK) this is an approximation
560 and returns {\tt true} if the control is editable, {\tt false} otherwise.
561
562
563 \membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
564
565 \func{virtual bool}{CanRedo}{\void}
566
567 Returns {\tt true} if there is a redo facility available and the last operation
568 can be redone.
569
570
571 \membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
572
573 \func{virtual bool}{CanUndo}{\void}
574
575 Returns {\tt true} if there is an undo facility available and the last operation
576 can be undone.
577
578
579 \membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}
580
581 \func{virtual void}{Clear}{\void}
582
583 Clears the text in the control.
584
585 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
586 event.
587
588
589 \membersection{wxTextCtrl::Copy}\label{wxtextctrlcopy}
590
591 \func{virtual void}{Copy}{\void}
592
593 Copies the selected text to the clipboard under Motif and MS Windows.
594
595
596 \membersection{wxTextCtrl::Create}\label{wxtextctrlcreate}
597
598 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
599 \param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
600 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
601
602 Creates the text control for two-step construction. Derived classes
603 should call or replace this function. See \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlconstr}\rtfsp
604 for further details.
605
606
607 \membersection{wxTextCtrl::Cut}\label{wxtextctrlcut}
608
609 \func{virtual void}{Cut}{\void}
610
611 Copies the selected text to the clipboard and removes the selection.
612
613
614 \membersection{wxTextCtrl::DiscardEdits}
615
616 \func{void}{DiscardEdits}{\void}
617
618 Resets the internal `modified' flag as if the current edits had been saved.
619
620
621 \membersection{wxTextCtrl::EmulateKeyPress}
622
623 \func{bool}{EmulateKeyPress}{\param{const wxKeyEvent\& }{event}}
624
625 This functions inserts into the control the character which would have been
626 inserted if the given key event had occured in the text control. The
627 {\it event} object should be the same as the one passed to {\tt EVT\_KEY\_DOWN}
628 handler previously by wxWindows.
629
630 Please note that this function doesn't currently work correctly for all keys
631 under any platform but MSW.
632
633 \wxheading{Return value}
634
635 {\tt true} if the event resulted in a change to the control, {\tt false}
636 otherwise.
637
638
639 \membersection{wxTextCtrl::GetDefaultStyle}\label{wxtextctrlgetdefaultstyle}
640
641 \constfunc{const wxTextAttr\& }{GetDefaultStyle}{\void}
642
643 Returns the style currently used for the new text.
644
645 \wxheading{See also}
646
647 \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle}
648
649
650 \membersection{wxTextCtrl::GetInsertionPoint}\label{wxtextctrlgetinsertionpoint}
651
652 \constfunc{virtual long}{GetInsertionPoint}{\void}
653
654 Returns the insertion point. This is defined as the zero based index of the
655 character position to the right of the insertion point. For example, if
656 the insertion point is at the end of the text control, it is equal to
657 both \helpref{GetValue()}{wxtextctrlgetvalue}.Length() and
658 \helpref{GetLastPosition()}{wxtextctrlgetlastposition}.
659
660 The following code snippet safely returns the character at the insertion
661 point or the zero character if the point is at the end of the control.
662
663 {\small%
664 \begin{verbatim}
665 char GetCurrentChar(wxTextCtrl *tc) {
666 if (tc->GetInsertionPoint() == tc->GetLastPosition())
667 return '\0';
668 return tc->GetValue[tc->GetInsertionPoint()];
669 }
670 \end{verbatim}
671 }%
672
673
674 \membersection{wxTextCtrl::GetLastPosition}\label{wxtextctrlgetlastposition}
675
676 \constfunc{virtual long}{GetLastPosition}{\void}
677
678 Returns the zero based index of the last position in the text control,
679 which is equal to the number of characters in the control.
680
681
682 \membersection{wxTextCtrl::GetLineLength}\label{wxtextctrlgetlinelength}
683
684 \constfunc{int}{GetLineLength}{\param{long}{ lineNo}}
685
686 Gets the length of the specified line, not including any trailing newline
687 character(s).
688
689 \wxheading{Parameters}
690
691 \docparam{lineNo}{Line number (starting from zero).}
692
693 \wxheading{Return value}
694
695 The length of the line, or -1 if {\it lineNo} was invalid.
696
697
698 \membersection{wxTextCtrl::GetLineText}\label{wxtextctrlgetlinetext}
699
700 \constfunc{wxString}{GetLineText}{\param{long}{ lineNo}}
701
702 Returns the contents of a given line in the text control, not including
703 any trailing newline character(s).
704
705 \wxheading{Parameters}
706
707 \docparam{lineNo}{The line number, starting from zero.}
708
709 \wxheading{Return value}
710
711 The contents of the line.
712
713
714 \membersection{wxTextCtrl::GetNumberOfLines}\label{wxtextctrlgetnumberoflines}
715
716 \constfunc{int}{GetNumberOfLines}{\void}
717
718 Returns the number of lines in the text control buffer.
719
720 \wxheading{Remarks}
721
722 Note that even empty text controls have one line (where the insertion point
723 is), so GetNumberOfLines() never returns 0.
724
725 For gtk\_text (multi-line) controls, the number of lines is
726 calculated by actually counting newline characters in the buffer. You
727 may wish to avoid using functions that work with line numbers if you are
728 working with controls that contain large amounts of text.
729
730
731 \membersection{wxTextCtrl::GetRange}\label{wxtextctrlgetrange}
732
733 \constfunc{virtual wxString}{GetRange}{\param{long}{ from}, \param{long}{ to}}
734
735 Returns the string containing the text staring in the positions {\it from} and
736 up to {\it to} in the control. The positions must have been returned by another
737 wxTextCtrl method.
738
739 Please note that the positions in a multiline wxTextCtrl do {\bf not}
740 correspond to the indices in the string returned by
741 \helpref{GetValue}{wxtextctrlgetvalue} because of the different new line
742 representations ({\tt CR} or {\tt CR LF}) and so this method should be used to
743 obtain the correct results instead of extracting parts of the entire value. It
744 may also be more efficient, especially if the control contains a lot of data.
745
746
747 \membersection{wxTextCtrl::GetSelection}\label{wxtextctrlgetselection}
748
749 \constfunc{virtual void}{GetSelection}{\param{long*}{ from}, \param{long*}{ to}}
750
751 Gets the current selection span. If the returned values are equal, there was
752 no selection.
753
754 Please note that the indices returned may be used with the other wxTextctrl
755 methods but don't necessarily represent the correct indices into the string
756 returned by \helpref{GetValue()}{wxtextctrlgetvalue} for multiline controls
757 under Windows (at least,) you should use
758 \helpref{GetStringSelection()}{wxtextctrlgetstringselection} to get the selected
759 text.
760
761 \wxheading{Parameters}
762
763 \docparam{from}{The returned first position.}
764
765 \docparam{to}{The returned last position.}
766
767 \pythonnote{The wxPython version of this method returns a tuple
768 consisting of the from and to values.}
769
770 \perlnote{In wxPerl this method takes no parameter and returns a
771 2-element list {\tt ( from, to )}.}
772
773
774 \membersection{wxTextCtrl::GetStringSelection}\label{wxtextctrlgetstringselection}
775
776 \func{virtual wxString}{GetStringSelection}{\void}
777
778 Gets the text currently selected in the control. If there is no selection, the
779 returned string is empty.
780
781
782 \membersection{wxTextCtrl::GetStyle}\label{wxtextctrlgetstyle}
783
784 \func{bool}{GetStyle}{\param{long }{position}, \param{wxTextAttr\& }{style}}
785
786 Returns the style at this position in the text control. Not all platforms
787 support this function.
788
789 \wxheading{Return value}
790
791 {\tt true} on success, {\tt false} if an error occured - it may also mean that
792 the styles are not supported under this platform.
793
794 \wxheading{See also}
795
796 \helpref{wxTextCtrl::SetStyle}{wxtextctrlsetstyle}, \helpref{wxTextAttr}{wxtextattr}
797
798
799 \membersection{wxTextCtrl::GetValue}\label{wxtextctrlgetvalue}
800
801 \constfunc{wxString}{GetValue}{\void}
802
803 Gets the contents of the control. Notice that for a multiline text control,
804 the lines will be separated by (Unix-style) $\backslash$n characters, even
805 under Windows where they are separated by a $\backslash$r$\backslash$n
806 sequence in the native control.
807
808
809 \membersection{wxTextCtrl::HitTest}\label{wxtextctrlhittest}
810
811 \constfunc{wxTextCtrlHitTestResult}{HitTest}{\param{const wxPoint\& }{pt}, \param{wxTextCoord }{*col}, \param{wxTextCoord }{*row}}
812
813 This function finds the character at the specified position expressed in
814 pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
815 of the character closest to this position are returned in the \arg{col} and
816 \arg{row} parameters (unless the pointers are \tt{NULL} which is allowed).
817
818 Please note that this function is currently only implemented in wxUniv and
819 wxMSW ports.
820
821 \wxheading{See also}
822
823 \helpref{PositionToXY}{wxtextctrlpositiontoxy}, \helpref{XYToPosition}{wxtextctrlxytoposition},
824
825 \perlnote{In wxPerl this function takes only the position argument and
826 returns a 3-element list \texttt{(result, col, row)}.
827
828
829 \membersection{wxTextCtrl::IsEditable}\label{wxtextctrliseditable}
830
831 \constfunc{bool}{IsEditable}{\void}
832
833 Returns {\tt true} if the controls contents may be edited by user (note that it
834 always can be changed by the program), i.e. if the control hasn't been put in
835 read-only mode by a previous call to
836 \helpref{SetEditable}{wxtextctrlseteditable}.
837
838
839 \membersection{wxTextCtrl::IsModified}\label{wxtextctrlismodified}
840
841 \constfunc{bool}{IsModified}{\void}
842
843 Returns {\tt true} if the text has been modified by user. Note that calling
844 \helpref{SetValue}{wxtextctrlsetvalue} doesn't make the control modified.
845
846
847 \membersection{wxTextCtrl::IsMultiLine}\label{wxtextctrlismultiline}
848
849 \constfunc{bool}{IsMultiLine}{\void}
850
851 Returns {\tt true} if this is a multi line edit control and {\tt false}
852 otherwise.
853
854 \wxheading{See also}
855
856 \helpref{IsSingleLine}{wxtextctrlissingleline}
857
858
859 \membersection{wxTextCtrl::IsSingleLine}\label{wxtextctrlissingleline}
860
861 \constfunc{bool}{IsSingleLine}{\void}
862
863 Returns {\tt true} if this is a single line edit control and {\tt false}
864 otherwise.
865
866 \wxheading{See also}
867
868 \helpref{IsMultiLine}{wxtextctrlissingleline}
869
870
871 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
872
873 \func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
874
875 Loads and displays the named file, if it exists.
876
877 \wxheading{Parameters}
878
879 \docparam{filename}{The filename of the file to load.}
880
881 \wxheading{Return value}
882
883 {\tt true} if successful, {\tt false} otherwise.
884
885 % VZ: commenting this out as: (a) the docs are wrong (you can't replace
886 % anything), (b) wxTextCtrl doesn't have any OnChar() anyhow
887 %% \membersection{wxTextCtrl::OnChar}\label{wxtextctrlonchar}
888 %%
889 %% \func{void}{OnChar}{\param{wxKeyEvent\& }{event}}
890 %%
891 %% Default handler for character input.
892 %%
893 %% \wxheading{Remarks}
894 %%
895 %% It is possible to intercept character
896 %% input by overriding this member. Call this function
897 %% to let the default behaviour take place; not calling
898 %% it results in the character being ignored. You can
899 %% replace the {\it keyCode} member of {\it event} to
900 %% translate keystrokes.
901 %%
902 %% Note that Windows and Motif have different ways
903 %% of implementing the default behaviour. In Windows,
904 %% calling wxTextCtrl::OnChar immediately
905 %% processes the character. In Motif,
906 %% calling this function simply sets a flag
907 %% to let default processing happen. This might affect
908 %% the way in which you write your OnChar function
909 %% on different platforms.
910 %%
911 %% \wxheading{See also}
912 %%
913 %% \helpref{wxKeyEvent}{wxkeyevent}
914
915
916 \membersection{wxTextCtrl::OnDropFiles}\label{wxtextctrlondropfiles}
917
918 \func{void}{OnDropFiles}{\param{wxDropFilesEvent\& }{event}}
919
920 This event handler function implements default drag and drop behaviour, which
921 is to load the first dropped file into the control.
922
923 \wxheading{Parameters}
924
925 \docparam{event}{The drop files event.}
926
927 \wxheading{Remarks}
928
929 This is not implemented on non-Windows platforms.
930
931 \wxheading{See also}
932
933 \helpref{wxDropFilesEvent}{wxdropfilesevent}
934
935
936 \membersection{wxTextCtrl::Paste}\label{wxtextctrlpaste}
937
938 \func{virtual void}{Paste}{\void}
939
940 Pastes text from the clipboard to the text item.
941
942
943 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
944
945 \constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
946
947 Converts given position to a zero-based column, line number pair.
948
949 \wxheading{Parameters}
950
951 \docparam{pos}{Position.}
952
953 \docparam{x}{Receives zero based column number.}
954
955 \docparam{y}{Receives zero based line number.}
956
957 \wxheading{Return value}
958
959 {\tt true} on success, {\tt false} on failure (most likely due to a too large position
960 parameter).
961
962 \wxheading{See also}
963
964 \helpref{wxTextCtrl::XYToPosition}{wxtextctrlxytoposition}
965
966 \pythonnote{In Python, PositionToXY() returns a tuple containing the x and
967 y values, so (x,y) = PositionToXY() is equivalent to the call described
968 above.}
969
970 \perlnote{In wxPerl this method only takes the {\tt pos} parameter, and
971 returns a 2-element list {\tt ( x, y )}.}
972
973
974 \membersection{wxTextCtrl::Redo}\label{wxtextctrlredo}
975
976 \func{virtual void}{Redo}{\void}
977
978 If there is a redo facility and the last operation can be redone, redoes the last operation. Does nothing
979 if there is no redo facility.
980
981
982 \membersection{wxTextCtrl::Remove}\label{wxtextctrlremove}
983
984 \func{virtual void}{Remove}{\param{long}{ from}, \param{long}{ to}}
985
986 Removes the text starting at the first given position up to (but not including)
987 the character at the last position.
988
989 \wxheading{Parameters}
990
991 \docparam{from}{The first position.}
992
993 \docparam{to}{The last position.}
994
995
996 \membersection{wxTextCtrl::Replace}\label{wxtextctrlreplace}
997
998 \func{virtual void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{value}}
999
1000 Replaces the text starting at the first position up to (but not including)
1001 the character at the last position with the given text.
1002
1003 \wxheading{Parameters}
1004
1005 \docparam{from}{The first position.}
1006
1007 \docparam{to}{The last position.}
1008
1009 \docparam{value}{The value to replace the existing text with.}
1010
1011
1012 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
1013
1014 \func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
1015
1016 Saves the contents of the control in a text file.
1017
1018 \wxheading{Parameters}
1019
1020 \docparam{filename}{The name of the file in which to save the text.}
1021
1022 \wxheading{Return value}
1023
1024 {\tt true} if the operation was successful, {\tt false} otherwise.
1025
1026
1027 \membersection{wxTextCtrl::SetDefaultStyle}\label{wxtextctrlsetdefaultstyle}
1028
1029 \func{bool}{SetDefaultStyle}{\param{const wxTextAttr\& }{style}}
1030
1031 Changes the default style to use for the new text which is going to be added
1032 to the control using \helpref{WriteText}{wxtextctrlwritetext} or\rtfsp
1033 \helpref{AppendText}{wxtextctrlappendtext}.
1034
1035 If either of the font, foreground, or background colour is not set in\rtfsp
1036 {\it style}, the values of the previous default style are used for them. If
1037 the previous default style didn't set them neither, the global font or colours
1038 of the text control itself are used as fall back.
1039
1040 However if the {\it style} parameter is the default wxTextAttr, then the
1041 default style is just reset (instead of being combined with the new style which
1042 wouldn't change it at all).
1043
1044 \wxheading{Parameters}
1045
1046 \docparam{style}{The style for the new text.}
1047
1048 \wxheading{Return value}
1049
1050 {\tt true} on success, {\tt false} if an error occured - may also mean that
1051 the styles are not supported under this platform.
1052
1053 \wxheading{See also}
1054
1055 \helpref{GetDefaultStyle}{wxtextctrlgetdefaultstyle}
1056
1057
1058 \membersection{wxTextCtrl::SetEditable}\label{wxtextctrlseteditable}
1059
1060 \func{virtual void}{SetEditable}{\param{const bool}{ editable}}
1061
1062 Makes the text item editable or read-only, overriding the {\bf wxTE\_READONLY} flag.
1063
1064 \wxheading{Parameters}
1065
1066 \docparam{editable}{If {\tt true}, the control is editable. If {\tt false}, the control is read-only.}
1067
1068 \wxheading{See also}
1069
1070 \helpref{IsEditable}{wxtextctrliseditable}
1071
1072
1073 \membersection{wxTextCtrl::SetInsertionPoint}\label{wxtextctrlsetinsertionpoint}
1074
1075 \func{virtual void}{SetInsertionPoint}{\param{long}{ pos}}
1076
1077 Sets the insertion point at the given position.
1078
1079 \wxheading{Parameters}
1080
1081 \docparam{pos}{Position to set.}
1082
1083
1084 \membersection{wxTextCtrl::SetInsertionPointEnd}\label{wxtextctrlsetinsertionpointend}
1085
1086 \func{virtual void}{SetInsertionPointEnd}{\void}
1087
1088 Sets the insertion point at the end of the text control. This is equivalent
1089 to \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}(\helpref{GetLastPosition}{wxtextctrlgetlastposition}()).
1090
1091
1092 \membersection{wxTextCtrl::SetMaxLength}\label{wxtextctrlsetmaxlength}
1093
1094 \func{virtual void}{SetMaxLength}{\param{unsigned long }{len}}
1095
1096 This function sets the maximum number of characters the user can enter into the
1097 control. In other words, it allows to limit the text value length to {\it len}
1098 not counting the terminating {\tt NUL} character.
1099
1100 If {\it len} is $0$, the previously set max length limit, if any, is discarded
1101 and the user may enter as much text as the underlying native text control
1102 widget supports (typically at least 32Kb).
1103
1104 If the user tries to enter more characters into the text control when it
1105 already is filled up to the maximal length, a
1106 {\tt wxEVT\_COMMAND\_TEXT\_MAXLEN} event is sent to notify the program about it
1107 (giving it the possibility to show an explanatory message, for example) and the
1108 extra input is discarded.
1109
1110 Note that this function may only be used with single line text controls.
1111
1112 \wxheading{Compatibility}
1113
1114 Only implemented in wxMSW/wxGTK starting with wxWindows 2.3.2.
1115
1116
1117 \membersection{wxTextCtrl::SetSelection}\label{wxtextctrlsetselection}
1118
1119 \func{virtual void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
1120
1121 Selects the text starting at the first position up to (but not including) the
1122 character at the last position. If both parameters are equal to $-1$ all text
1123 in the control is selected.
1124
1125 \wxheading{Parameters}
1126
1127 \docparam{from}{The first position.}
1128
1129 \docparam{to}{The last position.}
1130
1131
1132 \membersection{wxTextCtrl::SetStyle}\label{wxtextctrlsetstyle}
1133
1134 \func{bool}{SetStyle}{\param{long }{start}, \param{long }{end}, \param{const wxTextAttr\& }{style}}
1135
1136 Changes the style of the given range. If any attribute within {\it style} is
1137 not set, the correspondign attribute from \helpref{GetDefaultStyle()}{wxtextctrlgetdefaultstyle} is used.
1138
1139 \wxheading{Parameters}
1140
1141 \docparam{start}{The start of the range to change.}
1142
1143 \docparam{end}{The end of the range to change.}
1144
1145 \docparam{style}{The new style for the range.}
1146
1147 \wxheading{Return value}
1148
1149 {\tt true} on success, {\tt false} if an error occured - it may also mean that
1150 the styles are not supported under this platform.
1151
1152 \wxheading{See also}
1153
1154 \helpref{wxTextCtrl::GetStyle}{wxtextctrlgetstyle}, \helpref{wxTextAttr}{wxtextattr}
1155
1156
1157 \membersection{wxTextCtrl::SetValue}\label{wxtextctrlsetvalue}
1158
1159 \func{virtual void}{SetValue}{\param{const wxString\& }{ value}}
1160
1161 Sets the text value and marks the control as not-modified (which means that
1162 \helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
1163 after the call to SetValue).
1164
1165 Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
1166 event.
1167
1168 \wxheading{Parameters}
1169
1170 \docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
1171
1172
1173 \membersection{wxTextCtrl::ShowPosition}\label{wxtextctrlshowposition}
1174
1175 \func{void}{ShowPosition}{\param{long}{ pos}}
1176
1177 Makes the line containing the given position visible.
1178
1179 \wxheading{Parameters}
1180
1181 \docparam{pos}{The position that should be visible.}
1182
1183
1184 \membersection{wxTextCtrl::Undo}\label{wxtextctrlundo}
1185
1186 \func{virtual void}{Undo}{\void}
1187
1188 If there is an undo facility and the last operation can be undone, undoes the last operation. Does nothing
1189 if there is no undo facility.
1190
1191
1192 \membersection{wxTextCtrl::WriteText}\label{wxtextctrlwritetext}
1193
1194 \func{void}{WriteText}{\param{const wxString\& }{ text}}
1195
1196 Writes the text into the text control at the current insertion position.
1197
1198 \wxheading{Parameters}
1199
1200 \docparam{text}{Text to write to the text control.}
1201
1202 \wxheading{Remarks}
1203
1204 Newlines in the text string
1205 are the only control characters allowed, and they will cause appropriate
1206 line breaks. See \helpref{wxTextCtrl::\cinsert}{wxtextctrlinsert} and \helpref{wxTextCtrl::AppendText}{wxtextctrlappendtext} for more convenient ways of writing to the window.
1207
1208 After the write operation, the insertion point will be at the end of the inserted text, so subsequent write operations will be appended. To append text after the user may have interacted with the control, call \helpref{wxTextCtrl::SetInsertionPointEnd}{wxtextctrlsetinsertionpointend} before writing.
1209
1210
1211 \membersection{wxTextCtrl::XYToPosition}\label{wxtextctrlxytoposition}
1212
1213 \func{long}{XYToPosition}{\param{long}{ x}, \param{long}{ y}}
1214
1215 Converts the given zero based column and line number to a position.
1216
1217 \wxheading{Parameters}
1218
1219 \docparam{x}{The column number.}
1220
1221 \docparam{y}{The line number.}
1222
1223 \wxheading{Return value}
1224
1225 The position value.
1226
1227
1228 \membersection{wxTextCtrl::operator \cinsert}\label{wxtextctrlinsert}
1229
1230 \func{wxTextCtrl\&}{operator \cinsert}{\param{const wxString\& }{s}}
1231
1232 \func{wxTextCtrl\&}{operator \cinsert}{\param{int}{ i}}
1233
1234 \func{wxTextCtrl\&}{operator \cinsert}{\param{long}{ i}}
1235
1236 \func{wxTextCtrl\&}{operator \cinsert}{\param{float}{ f}}
1237
1238 \func{wxTextCtrl\&}{operator \cinsert}{\param{double}{ d}}
1239
1240 \func{wxTextCtrl\&}{operator \cinsert}{\param{char}{ c}}
1241
1242 Operator definitions for appending to a text control, for example:
1243
1244 \begin{verbatim}
1245 wxTextCtrl *wnd = new wxTextCtrl(my_frame);
1246
1247 (*wnd) << "Welcome to text control number " << 1 << ".\n";
1248 \end{verbatim}
1249