]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/textentry.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textentry.h
3 // Purpose: interface of wxTextEntry
4 // Author: Vadim Zeitlin
5 // Created: 2009-03-01 (extracted from wx/textctrl.h)
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
14 Common base class for single line text entry fields.
16 This class is not a control itself, as it doesn't derive from wxWindow.
17 Instead it is used as a base class by other controls, notably wxTextCtrl
18 and wxComboBox and gathers the methods common to both of them.
23 @see wxTextCtrl, wxComboBox
29 Appends the text to the end of the text control.
32 Text to write to the text control.
35 After the text is appended, the insertion point will be at the
36 end of the text control. If this behaviour is not desired, the
37 programmer should use GetInsertionPoint() and SetInsertionPoint().
41 virtual void AppendText(const wxString
& text
);
44 Call this function to enable auto-completion of the text typed in a
45 single-line text control using the given @a choices.
47 Notice that currently this function is only implemented in wxGTK2 and
48 wxMSW ports and does nothing under the other platforms.
53 @true if the auto-completion was enabled or @false if the operation
54 failed, typically because auto-completion is not supported by the
57 @see AutoCompleteFileNames()
59 virtual bool AutoComplete(const wxArrayString
& choices
);
62 Call this function to enable auto-completion of the text typed in a
63 single-line text control using all valid file system paths.
65 Notice that currently this function is only implemented in wxGTK2 port
66 and does nothing under the other platforms.
71 @true if the auto-completion was enabled or @false if the operation
72 failed, typically because auto-completion is not supported by the
77 virtual bool AutoCompleteFileNames();
80 Returns @true if the selection can be copied to the clipboard.
82 virtual bool CanCopy() const;
85 Returns @true if the selection can be cut to the clipboard.
87 virtual bool CanCut() const;
90 Returns @true if the contents of the clipboard can be pasted into the
93 On some platforms (Motif, GTK) this is an approximation and returns
94 @true if the control is editable, @false otherwise.
96 virtual bool CanPaste() const;
99 Returns @true if there is a redo facility available and the last
100 operation can be redone.
102 virtual bool CanRedo() const;
105 Returns @true if there is an undo facility available and the last
106 operation can be undone.
108 virtual bool CanUndo() const;
111 Sets the new text control value.
113 It also marks the control as not-modified which means that IsModified()
114 would return @false immediately after the call to ChangeValue().
116 The insertion point is set to the start of the control (i.e. position
119 This functions does not generate the @c wxEVT_COMMAND_TEXT_UPDATED
120 event but otherwise is identical to SetValue().
122 See @ref overview_events_prog for more information.
127 The new value to set. It may contain newline characters if the text
128 control is multi-line.
130 virtual void ChangeValue(const wxString
& value
);
133 Clears the text in the control.
135 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
136 event, i.e. its effect is identical to calling @c SetValue("").
138 virtual void Clear();
141 Copies the selected text to the clipboard.
146 Returns the insertion point, or cursor, position.
148 This is defined as the zero based index of the character position to
149 the right of the insertion point. For example, if the insertion point
150 is at the end of the single-line text control, it is equal to both
151 GetLastPosition() and @c "GetValue().Length()" (but notice that the latter
152 equality is not necessarily true for multiline edit controls which may
153 use multiple new line characters).
155 The following code snippet safely returns the character at the insertion
156 point or the zero character if the point is at the end of the control.
159 char GetCurrentChar(wxTextCtrl *tc) {
160 if (tc->GetInsertionPoint() == tc->GetLastPosition())
162 return tc->GetValue[tc->GetInsertionPoint()];
166 virtual long GetInsertionPoint() const;
169 Returns the zero based index of the last position in the text control,
170 which is equal to the number of characters in the control.
172 virtual wxTextPos
GetLastPosition() const;
175 Returns the string containing the text starting in the positions
176 @a from and up to @a to in the control.
178 The positions must have been returned by another wxTextCtrl method.
179 Please note that the positions in a multiline wxTextCtrl do @b not
180 correspond to the indices in the string returned by GetValue() because
181 of the different new line representations (@c CR or @c CR LF) and so
182 this method should be used to obtain the correct results instead of
183 extracting parts of the entire value. It may also be more efficient,
184 especially if the control contains a lot of data.
186 virtual wxString
GetRange(long from
, long to
) const;
189 Gets the current selection span.
191 If the returned values are equal, there was no selection. Please note
192 that the indices returned may be used with the other wxTextCtrl methods
193 but don't necessarily represent the correct indices into the string
194 returned by GetValue() for multiline controls under Windows (at least,)
195 you should use GetStringSelection() to get the selected text.
198 The returned first position.
200 The returned last position.
203 In wxPerl this method takes no parameters and returns a
204 2-element list (from, to).
207 virtual void GetSelection(long* from
, long* to
) const;
210 Gets the text currently selected in the control.
212 If there is no selection, the returned string is empty.
214 virtual wxString
GetStringSelection() const;
217 Gets the contents of the control.
219 Notice that for a multiline text control, the lines will be separated
220 by (Unix-style) @c \\n characters, even under Windows where they are
221 separated by a @c \\r\\n sequence in the native control.
223 virtual wxString
GetValue() const;
226 Returns @true if the controls contents may be edited by user (note that
227 it always can be changed by the program).
229 In other words, this functions returns @true if the control hasn't been
230 put in read-only mode by a previous call to SetEditable().
232 virtual bool IsEditable() const;
235 Returns @true if the control is currently empty.
237 This is the same as @c GetValue().empty() but can be much more
238 efficient for the multiline controls containing big amounts of text.
242 virtual bool IsEmpty() const;
245 Pastes text from the clipboard to the text item.
247 virtual void Paste();
250 If there is a redo facility and the last operation can be redone,
251 redoes the last operation.
253 Does nothing if there is no redo facility.
258 Removes the text starting at the first given position up to
259 (but not including) the character at the last position.
261 This function puts the current insertion point position at @a to as a
269 virtual void Remove(long from
, long to
);
272 Replaces the text starting at the first position up to
273 (but not including) the character at the last position with the given text.
275 This function puts the current insertion point position at @a to as a
283 The value to replace the existing text with.
285 virtual void Replace(long from
, long to
, const wxString
& value
);
288 Makes the text item editable or read-only, overriding the
289 @b wxTE_READONLY flag.
292 If @true, the control is editable. If @false, the control is
297 virtual void SetEditable(bool editable
);
300 Sets the insertion point at the given position.
303 Position to set, in the range from 0 to GetLastPosition() inclusive.
305 virtual void SetInsertionPoint(long pos
);
308 Sets the insertion point at the end of the text control.
310 This is equivalent to calling wxTextCtrl::SetInsertionPoint() with
311 wxTextCtrl::GetLastPosition() argument.
313 virtual void SetInsertionPointEnd();
316 This function sets the maximum number of characters the user can enter
319 In other words, it allows to limit the text value length to @a len not
320 counting the terminating @c NUL character.
322 If @a len is 0, the previously set max length limit, if any, is discarded
323 and the user may enter as much text as the underlying native text control widget
324 supports (typically at least 32Kb).
325 If the user tries to enter more characters into the text control when it
326 already is filled up to the maximal length, a @c wxEVT_COMMAND_TEXT_MAXLEN
327 event is sent to notify the program about it (giving it the possibility
328 to show an explanatory message, for example) and the extra input is discarded.
330 Note that in wxGTK this function may only be used with single line text controls.
332 virtual void SetMaxLength(unsigned long len
);
335 Selects the text starting at the first position up to (but not
336 including) the character at the last position.
338 If both parameters are equal to -1 all text in the control is selected.
340 Notice that the insertion point will be moved to @a from by this
350 virtual void SetSelection(long from
, long to
);
353 Selects all text in the control.
357 virtual void SelectAll();
360 Sets a hint shown in an empty unfocused text control.
362 The hints are usually used to indicate to the user what is supposed to
363 be entered into the given entry field, e.g. a common use of them is to
364 show an explanation of what can be entered in a wxSearchCtrl.
366 The hint is shown (usually greyed out) for an empty control until it
367 gets focus and is shown again if the control loses it and remains
368 empty. It won't be shown once the control has a non-empty value,
369 although it will be shown again if the control contents is cleared.
370 Because of this, it generally only makes sense to use hints with the
371 controls which are initially empty.
373 Notice that hints are known as <em>cue banners</em> under MSW or
374 <em>placeholder strings</em> under OS X.
378 virtual void SetHint(const wxString
& hint
);
381 Returns the current hint string.
383 See SetHint() for more information about hints.
387 virtual wxString
GetHint() const;
391 Attempts to set the control margins. When margins are given as wxPoint,
392 x indicates the left and y the top margin. Use -1 to indicate that
393 an existing value should be used.
396 @true if setting of all requested margins was successful.
400 bool SetMargins(const wxPoint
& pt
);
401 bool SetMargins(wxCoord left
, wxCoord top
= -1);
405 Returns the margins used by the control. The @c x field of the returned
406 point is the horizontal margin and the @c y field is the vertical one.
408 @remarks If given margin cannot be accurately determined, its value
409 will be set to -1. On some platforms you cannot obtain valid
410 margin values until you have called SetMargins().
416 wxPoint
GetMargins() const;
419 Sets the new text control value.
421 It also marks the control as not-modified which means that IsModified()
422 would return @false immediately after the call to SetValue().
424 The insertion point is set to the start of the control (i.e. position
427 Note that, unlike most other functions changing the controls values,
428 this function generates a @c wxEVT_COMMAND_TEXT_UPDATED event. To avoid
429 this you can use ChangeValue() instead.
432 The new value to set. It may contain newline characters if the text
433 control is multi-line.
435 virtual void SetValue(const wxString
& value
);
438 If there is an undo facility and the last operation can be undone,
439 undoes the last operation.
441 Does nothing if there is no undo facility.
446 Writes the text into the text control at the current insertion position.
449 Text to write to the text control.
452 Newlines in the text string are the only control characters
453 allowed, and they will cause appropriate line breaks.
454 See operator<<() and AppendText() for more convenient ways of
455 writing to the window.
456 After the write operation, the insertion point will be at the end
457 of the inserted text, so subsequent write operations will be appended.
458 To append text after the user may have interacted with the control,
459 call wxTextCtrl::SetInsertionPointEnd() before writing.
461 virtual void WriteText(const wxString
& text
);