TextView
Object Hierarchy:
Description:
[ CCode ( type_id = "gtk_text_view_get_type ()" ) ]
public class TextView : Container, Implementor, Buildable, Scrollable
public class TextView : Container, Implementor, Buildable, Scrollable
You may wish to begin by reading the [text widget conceptual overview](TextWidget.
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]
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.
Example: TextView:
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.TextView";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (400, 400);
// Box:
Gtk.Box box = new Gtk.Box (Gtk.Orientation.VERTICAL, 1);
this.add (box);
// A ScrolledWindow:
Gtk.ScrolledWindow scrolled = new Gtk.ScrolledWindow (null, null);
box.pack_start (scrolled, true, true, 0);
// The TextView:
Gtk.TextView view = new Gtk.TextView ();
view.set_wrap_mode (Gtk.WrapMode.WORD);
view.buffer.text = "Lorem Ipsum";
scrolled.add (view);
// A Button:
Gtk.Button button = new Gtk.Button.with_label ("Print content to stdout");
box.pack_start (button, false, true, 0);
button.clicked.connect (() => {
print (view.buffer.text);
print ("\n");
});
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}
valac --pkg gtk+-3.0 Gtk.TextView.vala
Namespace: Gtk
Package: gtk+-3.0
Content:
Properties:
- public bool accepts_tab { get; set; }
- public int bottom_margin { get; set; }
The bottom margin for text in the text view.
- public TextBuffer buffer { get; set; }
- public bool cursor_visible { get; set; }
- public bool editable { get; set; }
- public string im_module { owned get; set; }
Which IM (input method) module should be used for this text_view.
- public int indent { get; set; }
- public InputHints input_hints { get; set; }
Additional hints (beyond input_purpose) that allow input methods to fine-tune their behaviour.
- 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; }
- public bool overwrite { get; set; }
- public int pixels_above_lines { get; set; }
- public int pixels_below_lines { get; set; }
- public int pixels_inside_wrap { get; set; }
- public bool populate_all { get; set; }
If populate_all is true, the populate_popup signal is also emitted for touch popups.
- 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 TextView.
- public TextView.with_buffer (TextBuffer buffer)
Creates a new TextView 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_child_in_window (Widget child, TextWindowType which_window, int xpos, int ypos)
Adds a child at fixed coordinates in one of the text widget's windows.
- 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 coordinate (
buffer_x
,buffer_y
) to coordinates for the windowwin
, and stores the result in (window_x
,window_y
). - public virtual TextBuffer create_buffer ()
- public virtual void draw_layer (TextViewLayer layer, Context cr)
- 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 Tab key inserts a tab characters.
- public int get_border_window_size (TextWindowType type)
Gets the width of the specified border window.
- public int get_bottom_margin ()
Gets the bottom margin for text in the this .
- public unowned TextBuffer get_buffer ()
Returns the TextBuffer being displayed by this text view.
- public void get_cursor_locations (TextIter? iter, out Rectangle strong, out Rectangle @weak)
Given an
iter
within a text layout, determine the positions of the strong and weak cursors if the insertion point is at that iterator. - public bool get_cursor_visible ()
Find out whether the cursor should be displayed.
- public TextAttributes get_default_attributes ()
Obtains a copy of the default text attributes.
- public bool get_editable ()
Returns the default editability of the TextView.
- public unowned Adjustment get_hadjustment ()
Gets the horizontal-scrolling Adjustment.
- public int get_indent ()
Gets the default indentation of paragraphs in this.
- public InputHints get_input_hints ()
Gets the value of the input_hints property.
- public InputPurpose get_input_purpose ()
Gets the value of the input_purpose property.
- 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 TextIter 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 bool get_monospace ()
Gets the value of the monospace property.
- public bool get_overwrite ()
Returns whether the TextView 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 value set by set_pixels_below_lines.
- public int get_pixels_inside_wrap ()
Gets the value set by set_pixels_inside_wrap.
- public int get_right_margin ()
Gets the default right margin for text in this .
- 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 unowned Adjustment get_vadjustment ()
Gets the vertical-scrolling Adjustment.
- public void get_visible_rect (out Rectangle visible_rect)
Fills
visible_rect
with the currently-visible region of the buffer, in buffer coordinates. - public unowned Window? get_window (TextWindowType win)
Retrieves the Window corresponding to an area of the text view; possible windows include the overall widget window, child windows on the left, right, top, bottom, and the window that displays the text buffer.
- public TextWindowType get_window_type (Window window)
Usually used to find out which window an event corresponds to.
- public WrapMode get_wrap_mode ()
Gets the line wrapping for the view.
- public bool im_context_filter_keypress (EventKey event)
Allow the TextView input method to internally handle key press and release events.
- public void move_child (Widget child, int xpos, int ypos)
Updates the position of a child, as for add_child_in_window.
- 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 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, it it isn’t there already.
- public void reset_cursor_blink ()
Ensures that the cursor is shown (i.
- 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 Tab key is pressed.
- public void set_border_window_size (TextWindowType type, int size)
Sets the width of gtk_text_window_left or gtk_text_window_right, or the height of gtk_text_window_top or gtk_text_window_bottom.
- 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 TextView.
- 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 property, which allows input methods to fine-tune their behaviour.
- public void set_input_purpose (InputPurpose purpose)
Sets the input_purpose property which can be used by on-screen keyboards and other input methods to adjust their behaviour.
- 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 the monospace property, which indicates that the text view should use monospace fonts.
- public void set_overwrite (bool overwrite)
Changes the TextView 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 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, storing the result in (buffer_x
,buffer_y
).
Signals:
- public virtual signal void backspace ()
The backspace signal is a keybinding signal which gets emitted when the user asks for it.
- public virtual signal void copy_clipboard ()
The copy_clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
- public virtual signal void cut_clipboard ()
The cut_clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
- public virtual signal void delete_from_cursor (DeleteType type, int count)
The delete_from_cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
- public virtual signal bool extend_selection (TextExtendSelection granularity, TextIter location, TextIter start, TextIter end)
The extend_selection signal is emitted when the selection needs to be extended at
location
. - public virtual signal void insert_at_cursor (string str)
The insert_at_cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor.
- public virtual signal void insert_emoji ()
The insert_emoji signal is a keybinding signal which gets emitted to present the Emoji chooser for the
text_view
. - public virtual signal void move_cursor (MovementStep step, int count, bool extend_selection)
The move_cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement.
- public signal void move_viewport (ScrollStep step, int count)
The move_viewport signal is a keybinding signal which can be bound to key combinations to allow the user to move the viewport, i.
- public virtual signal void paste_clipboard ()
The paste_clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
- public virtual signal void populate_popup (Menu popup)
The populate_popup signal gets emitted before showing the context menu of the text view.
- public signal void preedit_changed (string preedit)
If an input method is used, the typed text will not immediately be committed to the buffer.
- public signal void select_all (bool select)
The select_all signal is a keybinding signal which gets emitted to select or unselect the complete contents of the text view.
- public virtual signal void set_anchor ()
The set_anchor signal is a keybinding signal which gets emitted when the user initiates setting the "anchor" mark.
- public signal void toggle_cursor_visible ()
The toggle_cursor_visible signal is a keybinding signal which gets emitted to toggle the cursor_visible property.
- public virtual signal void toggle_overwrite ()
The toggle_overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the text view.
Inherited Members:
All known members inherited from class Gtk.Container
All known members inherited from class Gtk.Widget
- accel_closures_changed
- activate
- add_accelerator
- add_device_events
- add_events
- add_mnemonic_label
- add_tick_callback
- adjust_baseline_allocation
- adjust_baseline_request
- adjust_size_allocation
- adjust_size_request
- app_paintable
- bind_template_callback_full
- bind_template_child_full
- button_press_event
- button_release_event
- can_activate_accel
- can_default
- can_focus
- child_focus
- child_notify
- class_path
- composite_child
- composited_changed
- compute_expand
- compute_expand_internal
- configure_event
- create_pango_context
- create_pango_layout
- damage_event
- delete_event
- destroy
- destroy_event
- destroyed
- device_is_shadowed
- direction_changed
- dispatch_child_properties_changed
- double_buffered
- drag_begin
- drag_data_delete
- drag_data_get
- drag_data_received
- drag_drop
- drag_end
- drag_failed
- drag_leave
- drag_motion
- draw
- draw_to_cairo_context
- ensure_style
- enter_notify_event
- error_bell
- event
- event_after
- events
- expand
- find_style_property
- focus
- focus_in_event
- focus_on_click
- focus_out_event
- freeze_child_notify
- get_accessible
- get_action_group
- get_allocated_baseline
- get_allocated_height
- get_allocated_size
- get_allocated_width
- get_allocation
- get_ancestor
- get_app_paintable
- get_can_default
- get_can_focus
- get_child_requisition
- get_child_visible
- get_clip
- get_clipboard
- get_composite_name
- get_css_name
- get_default_direction
- get_default_style
- get_device_enabled
- get_device_events
- get_direction
- get_display
- get_double_buffered
- get_events
- get_focus_on_click
- get_font_map
- get_font_options
- get_frame_clock
- get_halign
- get_has_tooltip
- get_has_window
- get_hexpand
- get_hexpand_set
- get_mapped
- get_margin_bottom
- get_margin_end
- get_margin_left
- get_margin_right
- get_margin_start
- get_margin_top
- get_modifier_mask
- get_modifier_style
- get_no_show_all
- get_opacity
- get_pango_context
- get_parent
- get_parent_window
- get_path
- get_pointer
- get_preferred_height
- get_preferred_height_and_baseline_for_width
- get_preferred_height_for_width
- get_preferred_height_for_width_internal
- get_preferred_height_internal
- get_preferred_size
- get_preferred_width
- get_preferred_width_for_height
- get_preferred_width_for_height_internal
- get_preferred_width_internal
- get_realized
- get_receives_default
- get_request_mode
- get_requisition
- get_root_window
- get_scale_factor
- get_screen
- get_sensitive
- get_settings
- get_size_request
- get_state
- get_state_flags
- get_style
- get_style_context
- get_support_multidevice
- get_template_child
- get_tooltip_markup
- get_tooltip_text
- get_tooltip_window
- get_toplevel
- get_valign
- get_valign_with_baseline
- get_vexpand
- get_vexpand_set
- get_visible
- get_visual
- get_window
- grab_broken_event
- grab_default
- grab_focus
- grab_notify
- halign
- has_default
- has_focus
- has_grab
- has_rc_style
- has_screen
- has_tooltip
- has_visible_focus
- height_request
- hexpand
- hexpand_set
- hide
- hide_on_delete
- hierarchy_changed
- in_destruction
- init_template
- input_shape_combine_region
- insert_action_group
- install_style_property
- install_style_property_parser
- intersect
- is_ancestor
- is_composited
- is_drawable
- is_focus
- is_sensitive
- is_toplevel
- is_visible
- key_press_event
- key_release_event
- keynav_failed
- leave_notify_event
- list_accel_closures
- list_action_prefixes
- list_mnemonic_labels
- list_style_properties
- map
- map_event
- margin
- margin_bottom
- margin_end
- margin_left
- margin_right
- margin_start
- margin_top
- mnemonic_activate
- modify_base
- modify_bg
- modify_cursor
- modify_fg
- modify_font
- modify_style
- modify_text
- motion_notify_event
- move_focus
- name
- no_show_all
- opacity
- override_background_color
- override_color
- override_cursor
- override_font
- override_symbolic_color
- parent
- parent_set
- path
- pop_composite_child
- popup_menu
- property_notify_event
- proximity_in_event
- proximity_out_event
- push_composite_child
- query_tooltip
- queue_allocate
- queue_compute_expand
- queue_draw
- queue_draw_area
- queue_draw_region
- queue_resize
- queue_resize_no_redraw
- realize
- receives_default
- region_intersect
- register_window
- remove_accelerator
- remove_mnemonic_label
- remove_tick_callback
- render_icon
- render_icon_pixbuf
- reparent
- reset_rc_styles
- reset_style
- scale_factor
- screen_changed
- scroll_event
- selection_clear_event
- selection_get
- selection_notify_event
- selection_received
- selection_request_event
- send_expose
- send_focus_change
- sensitive
- set_accel_path
- set_accessible_role
- set_accessible_type
- set_allocation
- set_app_paintable
- set_can_default
- set_can_focus
- set_child_visible
- set_clip
- set_composite_name
- set_connect_func
- set_css_name
- set_default_direction
- set_device_enabled
- set_device_events
- set_direction
- set_double_buffered
- set_events
- set_focus_on_click
- set_font_map
- set_font_options
- set_halign
- set_has_tooltip
- set_has_window
- set_hexpand
- set_hexpand_set
- set_mapped
- set_margin_bottom
- set_margin_end
- set_margin_left
- set_margin_right
- set_margin_start
- set_margin_top
- set_no_show_all
- set_opacity
- set_parent
- set_parent_window
- set_realized
- set_receives_default
- set_redraw_on_allocate
- set_sensitive
- set_size_request
- set_state
- set_state_flags
- set_style
- set_support_multidevice
- set_template
- set_template_from_resource
- set_tooltip_markup
- set_tooltip_text
- set_tooltip_window
- set_valign
- set_vexpand
- set_vexpand_set
- set_visible
- set_visual
- set_window
- shape_combine_region
- show
- show_all
- show_help
- show_now
- size_allocate
- size_allocate_with_baseline
- size_request
- state_changed
- state_flags_changed
- style
- style_attach
- style_get
- style_get_property
- style_get_valist
- style_set
- style_updated
- thaw_child_notify
- tooltip_markup
- tooltip_text
- touch_event
- translate_coordinates
- trigger_tooltip_query
- unmap
- unmap_event
- unparent
- unrealize
- unregister_window
- unset_state_flags
- valign
- vexpand
- vexpand_set
- visibility_notify_event
- visible
- width_request
- window_state_event
All known members inherited from class GLib.Object
All known members inherited from interface Atk.Implementor
All known members inherited from interface Gtk.Buildable
All known members inherited from interface Gtk.Scrollable