Module: Wx::TextEntry

Included in:
ComboBox, ComboCtrl, RTC::RichTextCtrl, STC::StyledTextCtrl, SearchCtrl, TextCtrl
Defined in:
lib/wx/doc/gen/text_entry.rb

Overview

Note:

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

See Also:

Instance Method Summary collapse

Instance Method Details

#append_text(text) ⇒ void

This method returns an undefined value.

Appends the text to the end of the text control.

Remark:

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.

Parameters:

  • text (String)

    Text to write to the text control.

See Also:



50
# File 'lib/wx/doc/gen/text_entry.rb', line 50

def append_text(text) end

#auto_complete(choices) ⇒ Boolean #auto_complete(completer) ⇒ Boolean

Overloads:

  • #auto_complete(choices) ⇒ Boolean

    Call this function to enable auto-completion of the text typed in a single-line text control using the given choices.

    true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.

    Parameters:

    • choices (Array<String>)

    Returns:

    • (Boolean)

    See Also:

  • #auto_complete(completer) ⇒ Boolean

    Enable auto-completion using the provided completer object.

    This method should be used instead of #auto_complete overload taking the array of possible completions if the total number of strings is too big as it allows returning the completions dynamically, depending on the text already entered by user and so is more efficient. The specified completer object will be used to retrieve the list of possible completions for the already entered text and will be deleted by Wx::TextEntry itself when it’s not needed any longer. Notice that you need to include Wx::/textcompleter.h in order to define your class inheriting from Wx::TextCompleter.

    true if the auto-completion was enabled or false if the operation failed, typically because auto-completion is not supported by the current platform.

    Parameters:

    • completer (Wx::TextCompleter)

      The object to be used for generating completions if non-NULL. If it is NULL, auto-completion is disabled. The Wx::TextEntry object takes ownership of this pointer and will delete it in any case (i.e. even if this method returns false).

    Returns:

    • (Boolean)

    See Also:



70
# File 'lib/wx/doc/gen/text_entry.rb', line 70

def auto_complete(*args) end

#auto_complete_directoriesBoolean

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.

Returns:

  • (Boolean)

See Also:



89
# File 'lib/wx/doc/gen/text_entry.rb', line 89

def auto_complete_directories; end

#auto_complete_file_namesBoolean

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.

Returns:

  • (Boolean)

See Also:



79
# File 'lib/wx/doc/gen/text_entry.rb', line 79

def auto_complete_file_names; end

#can_copyBoolean Also known as: can_copy?

Returns true if the selection can be copied to the clipboard.

Returns:

  • (Boolean)


93
# File 'lib/wx/doc/gen/text_entry.rb', line 93

def can_copy; end

#can_cutBoolean Also known as: can_cut?

Returns true if the selection can be cut to the clipboard.

Returns:

  • (Boolean)


98
# File 'lib/wx/doc/gen/text_entry.rb', line 98

def can_cut; end

#can_pasteBoolean 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.

Returns:

  • (Boolean)


105
# File 'lib/wx/doc/gen/text_entry.rb', line 105

def can_paste; end

#can_redoBoolean Also known as: can_redo?

Returns true if there is a redo facility available and the last operation can be redone.

Returns:

  • (Boolean)


110
# File 'lib/wx/doc/gen/text_entry.rb', line 110

def can_redo; end

#can_undoBoolean Also known as: can_undo?

Returns true if there is an undo facility available and the last operation can be undone.

Returns:

  • (Boolean)


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.

Parameters:

  • value (String)

    The new value to set. It may contain newline characters if the text control is multi-line.



126
# File 'lib/wx/doc/gen/text_entry.rb', line 126

def change_value(value) end

#clearvoid

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

#copyvoid

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

#cutvoid

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_uppervoid

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_hintString Also known as: hint

Returns the current hint string.

See #set_hint for more information about hints.

Returns:

  • (String)


323
# File 'lib/wx/doc/gen/text_entry.rb', line 323

def get_hint; end

#get_insertion_pointInteger 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

Returns:

  • (Integer)


163
# File 'lib/wx/doc/gen/text_entry.rb', line 163

def get_insertion_point; end

#get_last_positionWx::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.

Returns:

  • (Wx::TextPos)


168
# File 'lib/wx/doc/gen/text_entry.rb', line 168

def get_last_position; end

#get_marginsWx::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.

Remark:

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.

Returns:

See Also:



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.

Parameters:

  • from (Integer)
  • to (Integer)

Returns:

  • (String)


177
# File 'lib/wx/doc/gen/text_entry.rb', line 177

def get_range(from, to) end

#get_selectionArray(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.

Returns:

  • (Array(Integer,Integer))


184
# File 'lib/wx/doc/gen/text_entry.rb', line 184

def get_selection; end

#get_string_selectionString Also known as: string_selection

Gets the text currently selected in the control.

If there is no selection, the returned string is empty.

Returns:

  • (String)


191
# File 'lib/wx/doc/gen/text_entry.rb', line 191

def get_string_selection; end

#get_valueString 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.

Returns:

  • (String)


198
# File 'lib/wx/doc/gen/text_entry.rb', line 198

def get_value; end

#is_editableBoolean 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.

Returns:

  • (Boolean)


205
# File 'lib/wx/doc/gen/text_entry.rb', line 205

def is_editable; end

#is_emptyBoolean 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.

Returns:

  • (Boolean)


212
# File 'lib/wx/doc/gen/text_entry.rb', line 212

def is_empty; end

#pastevoid

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.

Parameters:

  • from (Integer)

    The first position.

  • to (Integer)

    The last position.



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.

Parameters:

  • from (Integer)

    The first position.

  • to (Integer)

    The last position.

  • value (String)

    The value to replace the existing text with.



240
# File 'lib/wx/doc/gen/text_entry.rb', line 240

def replace(from, to, value) end

#select_allvoid

This method returns an undefined value.

Selects all text in the control.

See Also:



288
# File 'lib/wx/doc/gen/text_entry.rb', line 288

def select_all; end

#select_nonevoid

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.

Parameters:

  • editable (Boolean)

    If true, the control is editable. If false, the control is read-only.

See Also:



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.

Remark:

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.

Remark:

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.

Parameters:

  • hint (String)

Returns:

  • (Boolean)


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.

Parameters:



254
# File 'lib/wx/doc/gen/text_entry.rb', line 254

def set_insertion_point(pos) end

#set_insertion_point_endvoid

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=

Overloads:

  • #set_margins(pt) ⇒ Boolean

    Attempts to set the control margins.

    When margins are given as Point, x indicates the left and y the top margin. Use -1 to indicate that an existing value should be used. true if setting of all requested margins was successful.

    Parameters:

    Returns:

    • (Boolean)
  • #set_margins(left, top = -1) ⇒ Boolean

    Attempts to set the control margins.

    When margins are given as Point, x indicates the left and y the top margin. Use -1 to indicate that an existing value should be used. true if setting of all requested margins was successful.

    Parameters:

    • left (Integer)
    • top (Integer) (defaults to: -1)

    Returns:

    • (Boolean)


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.

Parameters:

  • len (Integer)


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.

Parameters:

  • from (Integer)

    The first position.

  • to (Integer)

    The last position.

See Also:



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.

Parameters:

  • value (String)

    The new value to set. It may contain newline characters if the text control is multi-line.



347
# File 'lib/wx/doc/gen/text_entry.rb', line 347

def set_value(value) end

#undovoid

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.

Remark:

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.

Parameters:

  • text (String)

    Text to write to the text control.



365
# File 'lib/wx/doc/gen/text_entry.rb', line 365

def write_text(text) end