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