]>
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
31 Appends the text to the end of the text control.
34 Text to write to the text control.
37 After the text is appended, the insertion point will be at the
38 end of the text control. If this behaviour is not desired, the
39 programmer should use GetInsertionPoint() and SetInsertionPoint().
43 virtual void AppendText(const wxString
& text
);
46 Call this function to enable auto-completion of the text typed in a
47 single-line text control using the given @a choices.
49 Notice that currently this function is only implemented in wxGTK2 and
50 wxMSW ports and does nothing under the other platforms.
55 @true if the auto-completion was enabled or @false if the operation
56 failed, typically because auto-completion is not supported by the
59 @see AutoCompleteFileNames()
61 virtual bool AutoComplete(const wxArrayString
& choices
);
64 Call this function to enable auto-completion of the text typed in a
65 single-line text control using all valid file system paths.
67 Notice that currently this function is only implemented in wxGTK2 port
68 and does nothing under the other platforms.
73 @true if the auto-completion was enabled or @false if the operation
74 failed, typically because auto-completion is not supported by the
79 virtual bool AutoCompleteFileNames();
82 Returns @true if the selection can be copied to the clipboard.
84 virtual bool CanCopy() const;
87 Returns @true if the selection can be cut to the clipboard.
89 virtual bool CanCut() const;
92 Returns @true if the contents of the clipboard can be pasted into the
95 On some platforms (Motif, GTK) this is an approximation and returns
96 @true if the control is editable, @false otherwise.
98 virtual bool CanPaste() const;
101 Returns @true if there is a redo facility available and the last
102 operation can be redone.
104 virtual bool CanRedo() const;
107 Returns @true if there is an undo facility available and the last
108 operation can be undone.
110 virtual bool CanUndo() const;
113 Sets the new text control value.
115 It also marks the control as not-modified which means that IsModified()
116 would return @false immediately after the call to ChangeValue().
118 The insertion point is set to the start of the control (i.e. position
121 This functions does not generate the @c wxEVT_COMMAND_TEXT_UPDATED
122 event but otherwise is identical to SetValue().
124 See @ref overview_events_prog for more information.
129 The new value to set. It may contain newline characters if the text
130 control is multi-line.
132 virtual void ChangeValue(const wxString
& value
);
135 Clears the text in the control.
137 Note that this function will generate a @c wxEVT_COMMAND_TEXT_UPDATED
138 event, i.e. its effect is identical to calling @c SetValue("").
140 virtual void Clear();
143 Copies the selected text to the clipboard.
148 Returns the insertion point, or cursor, position.
150 This is defined as the zero based index of the character position to
151 the right of the insertion point. For example, if the insertion point
152 is at the end of the single-line text control, it is equal to both
153 GetLastPosition() and @c "GetValue().Length()" (but notice that the latter
154 equality is not necessarily true for multiline edit controls which may
155 use multiple new line characters).
157 The following code snippet safely returns the character at the insertion
158 point or the zero character if the point is at the end of the control.
161 char GetCurrentChar(wxTextCtrl *tc) {
162 if (tc->GetInsertionPoint() == tc->GetLastPosition())
164 return tc->GetValue[tc->GetInsertionPoint()];
168 virtual long GetInsertionPoint() const;
171 Returns the zero based index of the last position in the text control,
172 which is equal to the number of characters in the control.
174 virtual wxTextPos
GetLastPosition() const;
177 Returns the string containing the text starting in the positions
178 @a from and up to @a to in the control.
180 The positions must have been returned by another wxTextCtrl method.
181 Please note that the positions in a multiline wxTextCtrl do @b not
182 correspond to the indices in the string returned by GetValue() because
183 of the different new line representations (@c CR or @c CR LF) and so
184 this method should be used to obtain the correct results instead of
185 extracting parts of the entire value. It may also be more efficient,
186 especially if the control contains a lot of data.
188 virtual wxString
GetRange(long from
, long to
) const;
191 Gets the current selection span.
193 If the returned values are equal, there was no selection. Please note
194 that the indices returned may be used with the other wxTextCtrl methods
195 but don't necessarily represent the correct indices into the string
196 returned by GetValue() for multiline controls under Windows (at least,)
197 you should use GetStringSelection() to get the selected text.
200 The returned first position.
202 The returned last position.
205 In wxPerl this method takes no parameters and returns a
206 2-element list (from, to).
209 virtual void GetSelection(long* from
, long* to
) const;
212 Gets the text currently selected in the control.
214 If there is no selection, the returned string is empty.
216 virtual wxString
GetStringSelection() const;
219 Gets the contents of the control.
221 Notice that for a multiline text control, the lines will be separated
222 by (Unix-style) @c \\n characters, even under Windows where they are
223 separated by a @c \\r\\n sequence in the native control.
225 virtual wxString
GetValue() const;
228 Returns @true if the controls contents may be edited by user (note that
229 it always can be changed by the program).
231 In other words, this functions returns @true if the control hasn't been
232 put in read-only mode by a previous call to SetEditable().
234 virtual bool IsEditable() const;
237 Returns @true if the control is currently empty.
239 This is the same as @c GetValue().empty() but can be much more
240 efficient for the multiline controls containing big amounts of text.
244 virtual bool IsEmpty() const;
247 Pastes text from the clipboard to the text item.
249 virtual void Paste();
252 If there is a redo facility and the last operation can be redone,
253 redoes the last operation.
255 Does nothing if there is no redo facility.
260 Removes the text starting at the first given position up to
261 (but not including) the character at the last position.
263 This function puts the current insertion point position at @a to as a
271 virtual void Remove(long from
, long to
);
274 Replaces the text starting at the first position up to
275 (but not including) the character at the last position with the given text.
277 This function puts the current insertion point position at @a to as a
285 The value to replace the existing text with.
287 virtual void Replace(long from
, long to
, const wxString
& value
);
290 Makes the text item editable or read-only, overriding the
291 @b wxTE_READONLY flag.
294 If @true, the control is editable. If @false, the control is
299 virtual void SetEditable(bool editable
);
302 Sets the insertion point at the given position.
305 Position to set, in the range from 0 to GetLastPosition() inclusive.
307 virtual void SetInsertionPoint(long pos
);
310 Sets the insertion point at the end of the text control.
312 This is equivalent to calling wxTextCtrl::SetInsertionPoint() with
313 wxTextCtrl::GetLastPosition() argument.
315 virtual void SetInsertionPointEnd();
318 This function sets the maximum number of characters the user can enter
321 In other words, it allows to limit the text value length to @a len not
322 counting the terminating @c NUL character.
324 If @a len is 0, the previously set max length limit, if any, is discarded
325 and the user may enter as much text as the underlying native text control widget
326 supports (typically at least 32Kb).
327 If the user tries to enter more characters into the text control when it
328 already is filled up to the maximal length, a @c wxEVT_COMMAND_TEXT_MAXLEN
329 event is sent to notify the program about it (giving it the possibility
330 to show an explanatory message, for example) and the extra input is discarded.
332 Note that in wxGTK this function may only be used with single line text controls.
334 virtual void SetMaxLength(unsigned long len
);
337 Selects the text starting at the first position up to (but not
338 including) the character at the last position.
340 If both parameters are equal to -1 all text in the control is selected.
342 Notice that the insertion point will be moved to @a from by this
352 virtual void SetSelection(long from
, long to
);
355 Selects all text in the control.
359 virtual void SelectAll();
362 Sets a hint shown in an empty unfocused text control.
364 The hints are usually used to indicate to the user what is supposed to
365 be entered into the given entry field, e.g. a common use of them is to
366 show an explanation of what can be entered in a wxSearchCtrl.
368 The hint is shown (usually greyed out) for an empty control until it
369 gets focus and is shown again if the control loses it and remains
370 empty. It won't be shown once the control has a non-empty value,
371 although it will be shown again if the control contents is cleared.
372 Because of this, it generally only makes sense to use hints with the
373 controls which are initially empty.
375 Notice that hints are known as <em>cue banners</em> under MSW or
376 <em>placeholder strings</em> under OS X.
380 virtual void SetHint(const wxString
& hint
);
383 Returns the current hint string.
385 See SetHint() for more information about hints.
389 virtual wxString
GetHint() const;
393 Attempts to set the control margins. When margins are given as wxPoint,
394 x indicates the left and y the top margin. Use -1 to indicate that
395 an existing value should be used.
398 @true if setting of all requested margins was successful.
402 bool SetMargins(const wxPoint
& pt
);
403 bool SetMargins(wxCoord left
, wxCoord top
= -1);
407 Returns the margins used by the control. The @c x field of the returned
408 point is the horizontal margin and the @c y field is the vertical one.
410 @remarks If given margin cannot be accurately determined, its value
411 will be set to -1. On some platforms you cannot obtain valid
412 margin values until you have called SetMargins().
418 wxPoint
GetMargins() const;
421 Sets the new text control value.
423 It also marks the control as not-modified which means that IsModified()
424 would return @false immediately after the call to SetValue().
426 The insertion point is set to the start of the control (i.e. position
429 Note that, unlike most other functions changing the controls values,
430 this function generates a @c wxEVT_COMMAND_TEXT_UPDATED event. To avoid
431 this you can use ChangeValue() instead.
434 The new value to set. It may contain newline characters if the text
435 control is multi-line.
437 virtual void SetValue(const wxString
& value
);
440 If there is an undo facility and the last operation can be undone,
441 undoes the last operation.
443 Does nothing if there is no undo facility.
448 Writes the text into the text control at the current insertion position.
451 Text to write to the text control.
454 Newlines in the text string are the only control characters
455 allowed, and they will cause appropriate line breaks.
456 See operator<<() and AppendText() for more convenient ways of
457 writing to the window.
458 After the write operation, the insertion point will be at the end
459 of the inserted text, so subsequent write operations will be appended.
460 To append text after the user may have interacted with the control,
461 call wxTextCtrl::SetInsertionPointEnd() before writing.
463 virtual void WriteText(const wxString
& text
);