Module: Wx::TextEntry
- Included in:
- ComboBox, ComboCtrl, RTC::RichTextCtrl, STC::StyledTextCtrl, SearchCtrl, TextCtrl
- Defined in:
- lib/wx/doc/gen/text_entry.rb
Overview
In wxRuby this is a mixin module instead of a (base) class.
Common base class for single line text entry fields.
This class is not a control itself, as it doesn’t derive from Window. Instead it is used as a base class by other controls, notably TextCtrl and ComboBox and gathers the methods common to both of them.
Category: Controls
Instance Method Summary collapse
-
#append_text(text) ⇒ void
Appends the text to the end of the text control.
- #auto_complete(*args) ⇒ Object
-
#auto_complete_directories ⇒ Boolean
Call this function to enable auto-completion of the text using the file system directories.
-
#auto_complete_file_names ⇒ Boolean
Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths.
-
#can_copy ⇒ Boolean
(also: #can_copy?)
Returns true if the selection can be copied to the clipboard.
-
#can_cut ⇒ Boolean
(also: #can_cut?)
Returns true if the selection can be cut to the clipboard.
-
#can_paste ⇒ Boolean
(also: #can_paste?)
Returns true if the contents of the clipboard can be pasted into the text control.
-
#can_redo ⇒ Boolean
(also: #can_redo?)
Returns true if there is a redo facility available and the last operation can be redone.
-
#can_undo ⇒ Boolean
(also: #can_undo?)
Returns true if there is an undo facility available and the last operation can be undone.
-
#change_value(value) ⇒ void
Sets the new text control value.
-
#clear ⇒ void
Clears the text in the control.
-
#copy ⇒ void
Copies the selected text to the clipboard.
-
#cut ⇒ void
Copies the selected text to the clipboard and removes it from the control.
-
#force_upper ⇒ void
Convert all text entered into the control to upper case.
-
#get_hint ⇒ String
(also: #hint)
Returns the current hint string.
-
#get_insertion_point ⇒ Integer
(also: #insertion_point)
Returns the insertion point, or cursor, position.
-
#get_last_position ⇒ Wx::TextPos
(also: #last_position)
Returns the zero based index of the last position in the text control, which is equal to the number of characters in the control.
-
#get_margins ⇒ Wx::Point
(also: #margins)
Returns the margins used by the control.
-
#get_range(from, to) ⇒ String
(also: #range)
Returns the string containing the text starting in the positions from and up to to in the control.
-
#get_selection ⇒ Array(Integer,Integer)
(also: #selection)
Gets the current selection span.
-
#get_string_selection ⇒ String
(also: #string_selection)
Gets the text currently selected in the control.
-
#get_value ⇒ String
(also: #value)
Gets the contents of the control.
-
#is_editable ⇒ Boolean
(also: #editable?)
Returns true if the controls contents may be edited by user (note that it always can be changed by the program).
-
#is_empty ⇒ Boolean
(also: #empty?)
Returns true if the control is currently empty.
-
#paste ⇒ void
Pastes text from the clipboard to the text item.
-
#redo_ ⇒ void
If there is a redo facility and the last operation can be redone, redoes the last operation.
-
#remove(from, to) ⇒ void
Removes the text starting at the first given position up to (but not including) the character at the last position.
-
#replace(from, to, value) ⇒ void
Replaces the text starting at the first position up to (but not including) the character at the last position with the given text.
-
#select_all ⇒ void
Selects all text in the control.
-
#select_none ⇒ void
Deselects selected text in the control.
-
#set_editable(editable) ⇒ void
(also: #editable=)
Makes the text item editable or read-only, overriding the TE_READONLY flag.
-
#set_hint(hint) ⇒ Boolean
(also: #hint=)
Sets a hint shown in an empty unfocused text control.
-
#set_insertion_point(pos) ⇒ void
(also: #insertion_point=)
Sets the insertion point at the given position.
-
#set_insertion_point_end ⇒ void
Sets the insertion point at the end of the text control.
- #set_margins(*args) ⇒ Object (also: #margins=)
-
#set_max_length(len) ⇒ void
(also: #max_length=)
This function sets the maximum number of characters the user can enter into the control.
-
#set_selection(from, to) ⇒ void
Selects the text starting at the first position up to (but not including) the character at the last position.
-
#set_value(value) ⇒ void
(also: #value=)
Sets the new text control value.
-
#undo ⇒ void
If there is an undo facility and the last operation can be undone, undoes the last operation.
-
#write_text(text) ⇒ void
Writes the text into the text control at the current insertion position.
Instance Method Details
#append_text(text) ⇒ void
This method returns an undefined value.
Appends the text to the end of the text control.
After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired, the programmer should use #get_insertion_point and #set_insertion_point.
50 |
# File 'lib/wx/doc/gen/text_entry.rb', line 50 def append_text(text) end |
#auto_complete(choices) ⇒ Boolean #auto_complete(completer) ⇒ Boolean
70 |
# File 'lib/wx/doc/gen/text_entry.rb', line 70 def auto_complete(*args) end |
#auto_complete_directories ⇒ Boolean
Call this function to enable auto-completion of the text using the file system directories.
Unlike #auto_complete_file_names which completes both file names and directories, this function only completes the directory names. Notice that currently this function is only implemented in WXMSW port and does nothing under the other platforms.
true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.
89 |
# File 'lib/wx/doc/gen/text_entry.rb', line 89 def auto_complete_directories; end |
#auto_complete_file_names ⇒ Boolean
Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths.
Notice that currently this function is only implemented in WXMSW port and does nothing under the other platforms.
true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.
79 |
# File 'lib/wx/doc/gen/text_entry.rb', line 79 def auto_complete_file_names; end |
#can_copy ⇒ Boolean Also known as: can_copy?
Returns true if the selection can be copied to the clipboard.
93 |
# File 'lib/wx/doc/gen/text_entry.rb', line 93 def can_copy; end |
#can_cut ⇒ Boolean Also known as: can_cut?
Returns true if the selection can be cut to the clipboard.
98 |
# File 'lib/wx/doc/gen/text_entry.rb', line 98 def can_cut; end |
#can_paste ⇒ Boolean Also known as: can_paste?
Returns true if the contents of the clipboard can be pasted into the text control.
On some platforms (Motif, GTK) this is an approximation and returns true if the control is editable, false otherwise.
105 |
# File 'lib/wx/doc/gen/text_entry.rb', line 105 def can_paste; end |
#can_redo ⇒ Boolean Also known as: can_redo?
Returns true if there is a redo facility available and the last operation can be redone.
110 |
# File 'lib/wx/doc/gen/text_entry.rb', line 110 def can_redo; end |
#can_undo ⇒ Boolean Also known as: can_undo?
Returns true if there is an undo facility available and the last operation can be undone.
115 |
# File 'lib/wx/doc/gen/text_entry.rb', line 115 def can_undo; end |
#change_value(value) ⇒ void
This method returns an undefined value.
Sets the new text control value.
It also marks the control as not-modified which means that IsModified() would return false immediately after the call to #change_value. The insertion point is set to the start of the control (i.e. position 0) by this function. This functions does not generate the EVT_TEXT event but otherwise is identical to #set_value. See User Generated Events vs Programmatically Generated Events for more information.
126 |
# File 'lib/wx/doc/gen/text_entry.rb', line 126 def change_value(value) end |
#clear ⇒ void
This method returns an undefined value.
Clears the text in the control.
Note that this function will generate a EVT_TEXT event, i.e. its effect is identical to calling SetValue(“”).
132 |
# File 'lib/wx/doc/gen/text_entry.rb', line 132 def clear; end |
#copy ⇒ void
This method returns an undefined value.
Copies the selected text to the clipboard.
136 |
# File 'lib/wx/doc/gen/text_entry.rb', line 136 def copy; end |
#cut ⇒ void
This method returns an undefined value.
Copies the selected text to the clipboard and removes it from the control.
140 |
# File 'lib/wx/doc/gen/text_entry.rb', line 140 def cut; end |
#force_upper ⇒ void
This method returns an undefined value.
Convert all text entered into the control to upper case.
Call this method to ensure that all text entered into the control is converted on the fly to upper case. If the control is not empty, its existing contents is also converted to upper case.
146 |
# File 'lib/wx/doc/gen/text_entry.rb', line 146 def force_upper; end |
#get_hint ⇒ String Also known as: hint
Returns the current hint string.
See #set_hint for more information about hints.
323 |
# File 'lib/wx/doc/gen/text_entry.rb', line 323 def get_hint; end |
#get_insertion_point ⇒ Integer Also known as: insertion_point
Returns the insertion point, or cursor, position.
This is defined as the zero based index of the character position to the right of the insertion point. For example, if the insertion point is at the end of the single-line text control, it is equal to #get_last_position. Notice that insertion position is, in general, different from the index of the character the cursor position at in the string returned by #get_value. While this is always the case for the single line controls, multi-line controls can use two characters "\r\n"
as line separator (this is notably the case under MSW) meaning that indices in the control and its string value are offset by 1 for every line. Hence to correctly get the character at the current cursor position, taking into account that there can be none if the cursor is at the end of the string, you could do the following:
def get_current_char(txt_ctrl)
pos = txt_ctrl.get_insertion_point
return '' if pos == txt_ctrl.get_last_position
txt_ctrl.get_range(pos, pos + 1)
end
163 |
# File 'lib/wx/doc/gen/text_entry.rb', line 163 def get_insertion_point; end |
#get_last_position ⇒ Wx::TextPos Also known as: last_position
Returns the zero based index of the last position in the text control, which is equal to the number of characters in the control.
168 |
# File 'lib/wx/doc/gen/text_entry.rb', line 168 def get_last_position; end |
#get_margins ⇒ Wx::Point Also known as: margins
Returns the margins used by the control.
The x field of the returned point is the horizontal margin and the y field is the vertical one.
If given margin cannot be accurately determined, its value will be set to -1. On some platforms you cannot obtain valid margin values until you have called #set_margins.
337 |
# File 'lib/wx/doc/gen/text_entry.rb', line 337 def get_margins; end |
#get_range(from, to) ⇒ String Also known as: range
Returns the string containing the text starting in the positions from and up to to in the control.
The positions must have been returned by another Wx::TextCtrl method. Please note that the positions in a multiline Wx::TextCtrl do not correspond to the indices in the string returned by #get_value because of the different new line representations (CR or CR LF) and so this method should be used to obtain the correct results instead of extracting parts of the entire value. It may also be more efficient, especially if the control contains a lot of data.
177 |
# File 'lib/wx/doc/gen/text_entry.rb', line 177 def get_range(from, to) end |
#get_selection ⇒ Array(Integer,Integer) Also known as: selection
Gets the current selection span.
If the returned values are equal, there was no selection. Please note that the indices returned may be used with the other Wx::TextCtrl methods but don’t necessarily represent the correct indices into the string returned by #get_value for multiline controls under Windows (at least,) you should use #get_string_selection to get the selected text.
184 |
# File 'lib/wx/doc/gen/text_entry.rb', line 184 def get_selection; end |
#get_string_selection ⇒ String Also known as: string_selection
Gets the text currently selected in the control.
If there is no selection, the returned string is empty.
191 |
# File 'lib/wx/doc/gen/text_entry.rb', line 191 def get_string_selection; end |
#get_value ⇒ String Also known as: value
Gets the contents of the control.
Notice that for a multiline text control, the lines will be separated by (Unix-style) \n
characters, even under Windows where they are separated by a \r\n
sequence in the native control.
198 |
# File 'lib/wx/doc/gen/text_entry.rb', line 198 def get_value; end |
#is_editable ⇒ Boolean Also known as: editable?
Returns true if the controls contents may be edited by user (note that it always can be changed by the program).
In other words, this functions returns true if the control hasn’t been put in read-only mode by a previous call to #set_editable.
205 |
# File 'lib/wx/doc/gen/text_entry.rb', line 205 def is_editable; end |
#is_empty ⇒ Boolean Also known as: empty?
Returns true if the control is currently empty.
This is the same as get_value
.empty() but can be much more efficient for the multiline controls containing big amounts of text.
212 |
# File 'lib/wx/doc/gen/text_entry.rb', line 212 def is_empty; end |
#paste ⇒ void
This method returns an undefined value.
Pastes text from the clipboard to the text item.
217 |
# File 'lib/wx/doc/gen/text_entry.rb', line 217 def paste; end |
#redo_ ⇒ void
This method returns an undefined value.
If there is a redo facility and the last operation can be redone, redoes the last operation.
Does nothing if there is no redo facility.
223 |
# File 'lib/wx/doc/gen/text_entry.rb', line 223 def redo_; end |
#remove(from, to) ⇒ void
This method returns an undefined value.
Removes the text starting at the first given position up to (but not including) the character at the last position.
This function puts the current insertion point position at to as a side effect.
231 |
# File 'lib/wx/doc/gen/text_entry.rb', line 231 def remove(from, to) end |
#replace(from, to, value) ⇒ void
This method returns an undefined value.
Replaces the text starting at the first position up to (but not including) the character at the last position with the given text.
This function puts the current insertion point position at to as a side effect.
240 |
# File 'lib/wx/doc/gen/text_entry.rb', line 240 def replace(from, to, value) end |
#select_all ⇒ void
This method returns an undefined value.
Selects all text in the control.
288 |
# File 'lib/wx/doc/gen/text_entry.rb', line 288 def select_all; end |
#select_none ⇒ void
This method returns an undefined value.
Deselects selected text in the control.
292 |
# File 'lib/wx/doc/gen/text_entry.rb', line 292 def select_none; end |
#set_editable(editable) ⇒ void Also known as: editable=
This method returns an undefined value.
Makes the text item editable or read-only, overriding the Wx::TE_READONLY flag.
248 |
# File 'lib/wx/doc/gen/text_entry.rb', line 248 def set_editable(editable) end |
#set_hint(hint) ⇒ Boolean Also known as: hint=
Sets a hint shown in an empty unfocused text control.
The hints are usually used to indicate to the user what is supposed to be entered into the given entry field, e.g. a common use of them is to show an explanation of what can be entered in a SearchCtrl. The hint is shown (usually greyed out) for an empty control until it gets focus and is shown again if the control loses it and remains empty. It won’t be shown once the control has a non-empty value, although it will be shown again if the control contents is cleared. Because of this, it generally only makes sense to use hints with the controls which are initially empty. Notice that hints are known as cue banners under MSW or placeholder strings under macOS.
Currently implemented natively on Windows (Vista and later only), macOS and GTK+ (3.2 and later).
For the platforms without native hints support, the implementation has several known limitations. Notably, the hint display will not be properly updated if you change Wx::TextEntry contents programmatically when the hint is displayed using methods other than #set_value or #change_value or others which use them internally (e.g. #clear). In other words, currently you should avoid calling methods such as #write_text or #replace when using hints and the text control is empty. If you bind to the control’s focus and EVT_TEXT events, you must call Event#skip on them so that the generic implementation works correctly. Another limitation is that hints are ignored for the controls with Wx::TE_PASSWORD style.
Hints can be used for single line text controls under all platforms, but only MSW and GTK+ 2 support them for multi-line text controls, they are ignored for them under the other platforms.
316 |
# File 'lib/wx/doc/gen/text_entry.rb', line 316 def set_hint(hint) end |
#set_insertion_point(pos) ⇒ void Also known as: insertion_point=
This method returns an undefined value.
Sets the insertion point at the given position.
254 |
# File 'lib/wx/doc/gen/text_entry.rb', line 254 def set_insertion_point(pos) end |
#set_insertion_point_end ⇒ void
This method returns an undefined value.
Sets the insertion point at the end of the text control.
This is equivalent to calling Wx::TextCtrl#set_insertion_point with Wx::TextCtrl#get_last_position argument.
261 |
# File 'lib/wx/doc/gen/text_entry.rb', line 261 def set_insertion_point_end; end |
#set_margins(pt) ⇒ Boolean #set_margins(left, top = -1) ⇒ Boolean Also known as: margins=
37 |
# File 'lib/wx/doc/gen/text_entry.rb', line 37 def set_margins(*args) end |
#set_max_length(len) ⇒ void Also known as: max_length=
This method returns an undefined value.
This function sets the maximum number of characters the user can enter into the control.
In other words, it allows limiting the text value length to len not counting the terminating NUL character. If len is 0, the previously set max length limit, if any, is discarded and the user may enter as much text as the underlying native text control widget supports (typically at least 32Kb). If the user tries to enter more characters into the text control when it already is filled up to the maximal length, a EVT_TEXT_MAXLEN event is sent to notify the program about it (giving it the possibility to show an explanatory message, for example) and the extra input is discarded. Note that in WXGTK this function may only be used with single line text controls.
270 |
# File 'lib/wx/doc/gen/text_entry.rb', line 270 def set_max_length(len) end |
#set_selection(from, to) ⇒ void
This method returns an undefined value.
Selects the text starting at the first position up to (but not including) the character at the last position.
If both parameters are equal to -1 all text in the control is selected. Notice that the insertion point will be moved to from by this function.
281 |
# File 'lib/wx/doc/gen/text_entry.rb', line 281 def set_selection(from, to) end |
#set_value(value) ⇒ void Also known as: value=
This method returns an undefined value.
Sets the new text control value.
It also marks the control as not-modified which means that IsModified() would return false immediately after the call to #set_value. The insertion point is set to the start of the control (i.e. position 0) by this function unless the control value doesn’t change at all, in which case the insertion point is left at its original position. Note that, unlike most other functions changing the controls values, this function generates a EVT_TEXT event. To avoid this you can use #change_value instead.
347 |
# File 'lib/wx/doc/gen/text_entry.rb', line 347 def set_value(value) end |
#undo ⇒ void
This method returns an undefined value.
If there is an undo facility and the last operation can be undone, undoes the last operation.
Does nothing if there is no undo facility.
354 |
# File 'lib/wx/doc/gen/text_entry.rb', line 354 def undo; end |
#write_text(text) ⇒ void
This method returns an undefined value.
Writes the text into the text control at the current insertion position.
Newlines in the text string are the only control characters allowed, and they will cause appropriate line breaks. See operator<<() and #append_text for more convenient ways of writing to the window. 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 Wx::TextCtrl#set_insertion_point_end before writing.
365 |
# File 'lib/wx/doc/gen/text_entry.rb', line 365 def write_text(text) end |