]>
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 SetValue().
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.
202 virtual void GetSelection(long* from
, long* to
) const;
205 Gets the text currently selected in the control.
207 If there is no selection, the returned string is empty.
209 virtual wxString
GetStringSelection() const;
212 Gets the contents of the control.
214 Notice that for a multiline text control, the lines will be separated
215 by (Unix-style) @c \\n characters, even under Windows where they are
216 separated by a @c \\r\\n sequence in the native control.
218 virtual wxString
GetValue() const;
221 Returns @true if the controls contents may be edited by user (note that
222 it always can be changed by the program).
224 In other words, this functions returns @true if the control hasn't been
225 put in read-only mode by a previous call to SetEditable().
227 virtual bool IsEditable() const;
230 Returns @true if the control is currently empty.
232 This is the same as @c GetValue().empty() but can be much more
233 efficient for the multiline controls containing big amounts of text.
237 virtual bool IsEmpty() const;
240 Pastes text from the clipboard to the text item.
242 virtual void Paste();
245 If there is a redo facility and the last operation can be redone,
246 redoes the last operation.
248 Does nothing if there is no redo facility.
253 Removes the text starting at the first given position up to
254 (but not including) the character at the last position.
256 This function puts the current insertion point position at @a to as a
264 virtual void Remove(long from
, long to
);
267 Replaces the text starting at the first position up to
268 (but not including) the character at the last position with the given text.
270 This function puts the current insertion point position at @a to as a
278 The value to replace the existing text with.
280 virtual void Replace(long from
, long to
, const wxString
& value
);
283 Makes the text item editable or read-only, overriding the
284 @b wxTE_READONLY flag.
287 If @true, the control is editable. If @false, the control is
292 virtual void SetEditable(bool editable
);
295 Sets the insertion point at the given position.
298 Position to set, in the range from 0 to GetLastPosition() inclusive.
300 virtual void SetInsertionPoint(long pos
);
303 Sets the insertion point at the end of the text control.
305 This is equivalent to calling wxTextCtrl::SetInsertionPoint() with
306 wxTextCtrl::GetLastPosition() argument.
308 virtual void SetInsertionPointEnd();
311 This function sets the maximum number of characters the user can enter
314 In other words, it allows to limit the text value length to @a len not
315 counting the terminating @c NUL character.
317 If @a len is 0, the previously set max length limit, if any, is discarded
318 and the user may enter as much text as the underlying native text control widget
319 supports (typically at least 32Kb).
320 If the user tries to enter more characters into the text control when it
321 already is filled up to the maximal length, a @c wxEVT_COMMAND_TEXT_MAXLEN
322 event is sent to notify the program about it (giving it the possibility
323 to show an explanatory message, for example) and the extra input is discarded.
325 Note that in wxGTK this function may only be used with single line text controls.
327 virtual void SetMaxLength(unsigned long len
);
330 Selects the text starting at the first position up to (but not
331 including) the character at the last position.
333 If both parameters are equal to -1 all text in the control is selected.
335 Notice that the insertion point will be moved to @a from by this
345 virtual void SetSelection(long from
, long to
);
348 Selects all text in the control.
352 virtual void SelectAll();
355 Sets a hint shown in an empty unfocused text control.
357 The hints are usually used to indicate to the user what is supposed to
358 be entered into the given entry field, e.g. a common use of them is to
359 show an explanation of what can be entered in a wxSearchCtrl.
361 The hint is shown (usually greyed out) for an empty control until it
362 gets focus and is shown again if the control loses it and remains
363 empty. It won't be shown once the control has a non-empty value,
364 although it will be shown again if the control contents is cleared.
365 Because of this, it generally only makes sense to use hints with the
366 controls which are initially empty.
368 Notice that hints are known as <em>cue banners</em> under MSW or
369 <em>placeholder strings</em> under OS X.
373 virtual void SetHint(const wxString
& hint
);
376 Returns the current hint string.
378 See SetHint() for more information about hints.
382 virtual wxString
GetHint() const;
386 Attempts to set the control margins. When margins are given as wxPoint,
387 x indicates the left and y the top margin. Use -1 to indicate that
388 an existing value should be used.
391 @true if setting of all requested margins was successful.
395 bool SetMargins(const wxPoint
& pt
);
396 bool SetMargins(wxCoord left
, wxCoord top
= -1);
400 Returns the margins used by the control. The @c x field of the returned
401 point is the horizontal margin and the @c y field is the vertical one.
403 @remarks If given margin cannot be accurately determined, its value
404 will be set to -1. On some platforms you cannot obtain valid
405 margin values until you have called SetMargins().
411 wxPoint
GetMargins() const;
414 Sets the new text control value.
416 It also marks the control as not-modified which means that IsModified()
417 would return @false immediately after the call to SetValue().
419 The insertion point is set to the start of the control (i.e. position
422 Note that, unlike most other functions changing the controls values,
423 this function generates a @c wxEVT_COMMAND_TEXT_UPDATED event. To avoid
424 this you can use ChangeValue() instead.
427 The new value to set. It may contain newline characters if the text
428 control is multi-line.
430 virtual void SetValue(const wxString
& value
);
433 If there is an undo facility and the last operation can be undone,
434 undoes the last operation.
436 Does nothing if there is no undo facility.
441 Writes the text into the text control at the current insertion position.
444 Text to write to the text control.
447 Newlines in the text string are the only control characters
448 allowed, and they will cause appropriate line breaks.
449 See operator<<() and AppendText() for more convenient ways of
450 writing to the window.
451 After the write operation, the insertion point will be at the end
452 of the inserted text, so subsequent write operations will be appended.
453 To append text after the user may have interacted with the control,
454 call wxTextCtrl::SetInsertionPointEnd() before writing.
456 virtual void WriteText(const wxString
& text
);