TextView
Object Hierarchy:
Description:
public class TextView : Widget, Accessible, AccessibleText, Buildable, ConstraintTarget, Scrollable
A widget that displays the contents of a [class@Gtk.
TextBuffer].
![An example GtkTextview](multiline-text.png)
You may wish to begin by reading the [conceptual overview](section-text-widget.html), which gives an overview of all the objects and data types related to the text widget and how they work together.
CSS nodes
``` textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├── border.bottom ╰── [window.popup] ```
`GtkTextView` has a main css node with name textview and style class .view, and subnodes for each of the border windows, and the main text area, with names border and text, respectively. The border nodes each get one of the style classes .left, .right, .top or .bottom.
A node representing the selection will appear below the text node.
If a context menu is opened, the window node will appear as a subnode of the main node.
Accessibility
`GtkTextView` uses the gtk_accessible_role_text_box role.
Content:
Properties:
- public bool accepts_tab { get; set; }
Whether Tab will result in a tab character being entered.
- public int bottom_margin { get; set; }
The bottom margin for text in the text view.
- public TextBuffer buffer { get; set; }
The buffer which is displayed.
- public bool cursor_visible { get; set; }
If the insertion cursor is shown.
- public bool editable { get; set; }
- public MenuModel extra_menu { get; set; }
A menu model whose contents will be appended to the context menu.
- public string im_module { owned get; set; }
Which IM (input method) module should be used for this text_view.
- public int indent { get; set; }
Amount to indent the paragraph, in pixels.
- public InputHints input_hints { get; set; }
Additional hints (beyond [property@Gtk.
- public InputPurpose input_purpose { get; set; }
The purpose of this text field.
- public Justification justification { get; set; }
- public int left_margin { get; set; }
The default left margin for text in the text view.
- public bool monospace { get; set; }
Whether text should be displayed in a monospace font.
- public bool overwrite { get; set; }
Whether entered text overwrites existing contents.
- public int pixels_above_lines { get; set; }
- public int pixels_below_lines { get; set; }
- public int pixels_inside_wrap { get; set; }
- public int right_margin { get; set; }
The default right margin for text in the text view.
- public TabArray tabs { owned get; set; }
- public int top_margin { get; set; }
The top margin for text in the text view.
- public WrapMode wrap_mode { get; set; }
Creation methods:
- public TextView ()
Creates a new `GtkTextView`.
- public TextView.with_buffer (TextBuffer buffer)
Creates a new `GtkTextView` widget displaying the buffer
buffer
.
Methods:
- public void add_child_at_anchor (Widget child, TextChildAnchor anchor)
Adds a child widget in the text buffer, at the given
anchor
. - public void add_overlay (Widget child, int xpos, int ypos)
Adds
child
at a fixed coordinate in the `GtkTextView`'s text window. - public bool backward_display_line (ref TextIter iter)
Moves the given
iter
backward by one display (wrapped) line. - public bool backward_display_line_start (ref TextIter iter)
Moves the given
iter
backward to the next display line start. - public void buffer_to_window_coords (TextWindowType win, int buffer_x, int buffer_y, out int window_x, out int window_y)
Converts buffer coordinates to window coordinates.
- public virtual TextBuffer create_buffer ()
The create_buffer vfunc is called to create a `GtkTextBuffer` for the text view.
- public bool forward_display_line (ref TextIter iter)
Moves the given
iter
forward by one display (wrapped) line. - public bool forward_display_line_end (ref TextIter iter)
Moves the given
iter
forward to the next display line end. - public bool get_accepts_tab ()
Returns whether pressing the <kbd>Tab</kbd> key inserts a tab characters.
- public int get_bottom_margin ()
Gets the bottom margin for text in the this .
- public unowned TextBuffer get_buffer ()
Returns the `GtkTextBuffer` being displayed by this text view.
- public void get_cursor_locations (TextIter? iter, out Rectangle strong, out Rectangle @weak)
Determine the positions of the strong and weak cursors if the insertion point is at
iter
. - public bool get_cursor_visible ()
Find out whether the cursor should be displayed.
- public bool get_editable ()
Returns the default editability of the `GtkTextView`.
- public unowned MenuModel get_extra_menu ()
Gets the menu model that gets added to the context menu or null if none has been set.
- public unowned Widget? get_gutter (TextWindowType win)
Gets a `GtkWidget` that has previously been set as gutter.
- public int get_indent ()
Gets the default indentation of paragraphs in this.
- public InputHints get_input_hints ()
Gets the `input-hints` of the `GtkTextView`.
- public InputPurpose get_input_purpose ()
Gets the `input-purpose` of the `GtkTextView`.
- public bool get_iter_at_location (out TextIter iter, int x, int y)
Retrieves the iterator at buffer coordinates
x
andy
. - public bool get_iter_at_position (out TextIter iter, out int trailing, int x, int y)
Retrieves the iterator pointing to the character at buffer coordinates
x
andy
. - public void get_iter_location (TextIter iter, out Rectangle location)
Gets a rectangle which roughly contains the character at
iter
. - public Justification get_justification ()
Gets the default justification of paragraphs in this.
- public int get_left_margin ()
Gets the default left margin size of paragraphs in the this.
- public void get_line_at_y (out TextIter target_iter, int y, out int line_top)
Gets the `GtkTextIter` at the start of the line containing the coordinate
y
. - public void get_line_yrange (TextIter iter, out int y, out int height)
Gets the y coordinate of the top of the line containing
iter
, and the height of the line. - public unowned Context get_ltr_context ()
Gets the `PangoContext` that is used for rendering LTR directed text layouts.
- public bool get_monospace ()
Gets whether the `GtkTextView` uses monospace styling.
- public bool get_overwrite ()
Returns whether the `GtkTextView` is in overwrite mode or not.
- public int get_pixels_above_lines ()
Gets the default number of pixels to put above paragraphs.
- public int get_pixels_below_lines ()
Gets the default number of pixels to put below paragraphs.
- public int get_pixels_inside_wrap ()
Gets the default number of pixels to put between wrapped lines inside a paragraph.
- public int get_right_margin ()
Gets the default right margin for text in this .
- public unowned Context get_rtl_context ()
Gets the `PangoContext` that is used for rendering RTL directed text layouts.
- public TabArray? get_tabs ()
Gets the default tabs for this.
- public int get_top_margin ()
Gets the top margin for text in the this.
- public void get_visible_rect (out Rectangle visible_rect)
Fills
visible_rect
with the currently-visible region of the buffer, in buffer coordinates. - public WrapMode get_wrap_mode ()
Gets the line wrapping for the view.
- public bool im_context_filter_keypress (Event event)
Allow the `GtkTextView` input method to internally handle key press and release events.
- public bool move_mark_onscreen (TextMark mark)
Moves a mark within the buffer so that it's located within the currently-visible text area.
- public void move_overlay (Widget child, int xpos, int ypos)
Updates the position of a child.
- public bool move_visually (ref TextIter iter, int count)
Move the iterator a given number of characters visually, treating it as the strong cursor position.
- public bool place_cursor_onscreen ()
Moves the cursor to the currently visible region of the buffer.
- public void remove (Widget child)
Removes a child widget from this.
- public void reset_cursor_blink ()
Ensures that the cursor is shown.
- public void reset_im_context ()
Reset the input method context of the text view if needed.
- public void scroll_mark_onscreen (TextMark mark)
Scrolls this the minimum distance such that
mark
is contained within the visible area of the widget. - public bool scroll_to_iter (TextIter iter, double within_margin, bool use_align, double xalign, double yalign)
Scrolls this so that
iter
is on the screen in the position indicated byxalign
andyalign
. - public void scroll_to_mark (TextMark mark, double within_margin, bool use_align, double xalign, double yalign)
Scrolls this so that
mark
is on the screen in the position indicated byxalign
andyalign
. - public void set_accepts_tab (bool accepts_tab)
Sets the behavior of the text widget when the <kbd>Tab</kbd> key is pressed.
- public void set_bottom_margin (int bottom_margin)
Sets the bottom margin for text in this.
- public void set_buffer (TextBuffer? buffer)
Sets
buffer
as the buffer being displayed by this. - public void set_cursor_visible (bool setting)
Toggles whether the insertion point should be displayed.
- public void set_editable (bool setting)
Sets the default editability of the `GtkTextView`.
- public void set_extra_menu (MenuModel? model)
Sets a menu model to add when constructing the context menu for this.
- public void set_gutter (TextWindowType win, Widget? widget)
Places
widget
into the gutter specified bywin
. - public void set_indent (int indent)
Sets the default indentation for paragraphs in this.
- public void set_input_hints (InputHints hints)
Sets the `input-hints` of the `GtkTextView`.
- public void set_input_purpose (InputPurpose purpose)
Sets the `input-purpose` of the `GtkTextView`.
- public void set_justification (Justification justification)
Sets the default justification of text in this .
- public void set_left_margin (int left_margin)
Sets the default left margin for text in this .
- public void set_monospace (bool monospace)
Sets whether the `GtkTextView` should display text in monospace styling.
- public void set_overwrite (bool overwrite)
Changes the `GtkTextView` overwrite mode.
- public void set_pixels_above_lines (int pixels_above_lines)
Sets the default number of blank pixels above paragraphs in this.
- public void set_pixels_below_lines (int pixels_below_lines)
Sets the default number of pixels of blank space to put below paragraphs in this.
- public void set_pixels_inside_wrap (int pixels_inside_wrap)
Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph.
- public void set_right_margin (int right_margin)
Sets the default right margin for text in the text view.
- public void set_tabs (TabArray tabs)
Sets the default tab stops for paragraphs in this .
- public void set_top_margin (int top_margin)
Sets the top margin for text in this.
- public void set_wrap_mode (WrapMode wrap_mode)
Sets the line wrapping for the view.
- public virtual void snapshot_layer (TextViewLayer layer, Snapshot snapshot)
The snapshot_layer vfunc is called before and after the text view is drawing its own text.
- public bool starts_display_line (TextIter iter)
Determines whether
iter
is at the start of a display line. - public void window_to_buffer_coords (TextWindowType win, int window_x, int window_y, out int buffer_x, out int buffer_y)
Converts coordinates on the window identified by
win
to buffer coordinates.
Signals:
- public virtual signal void backspace ()
Gets emitted when the user asks for it.
- public virtual signal void copy_clipboard ()
Gets emitted to copy the selection to the clipboard.
- public virtual signal void cut_clipboard ()
Gets emitted to cut the selection to the clipboard.
- public virtual signal void delete_from_cursor (DeleteType type, int count)
Gets emitted when the user initiates a text deletion.
- public virtual signal bool extend_selection (TextExtendSelection granularity, TextIter location, TextIter start, TextIter end)
Emitted when the selection needs to be extended at
location
. - public virtual signal void insert_at_cursor (string str)
Gets emitted when the user initiates the insertion of a fixed string at the cursor.
- public virtual signal void insert_emoji ()
Gets emitted to present the Emoji chooser for the
text_view
. - public virtual signal void move_cursor (MovementStep step, int count, bool extend_selection)
Gets emitted when the user initiates a cursor movement.
- public signal void move_viewport (ScrollStep step, int count)
Gets emitted to move the viewport.
- public virtual signal void paste_clipboard ()
Gets emitted to paste the contents of the clipboard into the text view.
- public signal void preedit_changed (string preedit)
Emitted when preedit text of the active IM changes.
- public signal void select_all (bool select)
Gets emitted to select or unselect the complete contents of the text view.
- public virtual signal void set_anchor ()
Gets emitted when the user initiates settings the "anchor" mark.
- public signal void toggle_cursor_visible ()
Gets emitted to toggle the `cursor-visible` property.
- public virtual signal void toggle_overwrite ()
Gets emitted to toggle the overwrite mode of the text view.
Inherited Members:
- action_set_enabled
- activate
- activate_action
- activate_action_variant
- activate_default
- add_binding
- add_binding_action
- add_binding_signal
- add_controller
- add_css_class
- add_mnemonic_label
- add_shortcut
- add_tick_callback
- allocate
- allocate_size
- bind_template_callback_full
- bind_template_child_full
- can_focus
- can_target
- child_focus
- compute_bounds
- compute_expand
- compute_expand_internal
- compute_point
- compute_transform
- contains
- create_pango_context
- create_pango_layout
- css_changed
- css_classes
- css_name
- cursor
- destroy
- direction_changed
- dispose_template
- error_bell
- focus
- focus_on_click
- focusable
- get_accessible_role
- get_activate_signal
- get_allocated_baseline
- get_allocated_height
- get_allocated_width
- get_allocation
- get_ancestor
- get_baseline
- get_can_focus
- get_can_target
- get_child_visible
- get_clipboard
- get_color
- get_css_classes
- get_css_name
- get_cursor
- get_default_direction
- get_direction
- get_display
- get_first_child
- get_focus_child
- get_focus_on_click
- get_focusable
- get_font_map
- get_font_options
- get_frame_clock
- get_halign
- get_has_tooltip
- get_height
- get_hexpand
- get_hexpand_set
- get_last_child
- get_layout_manager
- get_layout_manager_type
- get_mapped
- get_margin_bottom
- get_margin_end
- get_margin_start
- get_margin_top
- get_name
- get_native
- get_next_sibling
- get_opacity
- get_overflow
- get_pango_context
- get_parent
- get_preferred_size
- get_prev_sibling
- get_primary_clipboard
- get_realized
- get_receives_default
- get_request_mode
- get_root
- get_scale_factor
- get_sensitive
- get_settings
- get_size
- get_size_request
- get_state_flags
- get_style_context
- get_template_child
- get_tooltip_markup
- get_tooltip_text
- get_valign
- get_vexpand
- get_vexpand_set
- get_visible
- get_width
- grab_focus
- halign
- has_css_class
- has_default
- has_focus
- has_tooltip
- has_visible_focus
- height_request
- hexpand
- hexpand_set
- hide
- in_destruction
- init_template
- insert_action_group
- insert_after
- insert_before
- install_action
- install_property_action
- is_ancestor
- is_drawable
- is_focus
- is_sensitive
- is_visible
- keynav_failed
- layout_manager
- list_mnemonic_labels
- map
- margin_bottom
- margin_end
- margin_start
- margin_top
- measure
- mnemonic_activate
- move_focus
- name
- observe_children
- observe_controllers
- opacity
- overflow
- parent
- pick
- query_action
- query_tooltip
- queue_allocate
- queue_draw
- queue_resize
- realize
- receives_default
- remove_controller
- remove_css_class
- remove_mnemonic_label
- remove_tick_callback
- root
- scale_factor
- sensitive
- set_accessible_role
- set_activate_signal
- set_activate_signal_from_name
- set_can_focus
- set_can_target
- set_child_visible
- set_css_classes
- set_css_name
- set_cursor
- set_cursor_from_name
- set_default_direction
- set_direction
- set_focus_child
- set_focus_on_click
- set_focusable
- set_font_map
- set_font_options
- set_halign
- set_has_tooltip
- set_hexpand
- set_hexpand_set
- set_layout_manager
- set_layout_manager_type
- set_margin_bottom
- set_margin_end
- set_margin_start
- set_margin_top
- set_name
- set_opacity
- set_overflow
- set_parent
- set_receives_default
- set_sensitive
- set_size_request
- set_state_flags
- set_template
- set_template_from_resource
- set_template_scope
- set_tooltip_markup
- set_tooltip_text
- set_valign
- set_vexpand
- set_vexpand_set
- set_visible
- should_layout
- show
- size_allocate
- snapshot
- snapshot_child
- state_flags_changed
- system_setting_changed
- tooltip_markup
- tooltip_text
- translate_coordinates
- trigger_tooltip_query
- unmap
- unparent
- unrealize
- unroot
- unset_state_flags
- valign
- vexpand
- vexpand_set
- visible
- width_request