Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

Gtk::TextView

class Gtk::TextView

The Gtk::TextView widget displays an associated Gtk::TextBuffer.

If you need a simple widget that can hold text, both for viewing and manipulating the text, this is the right widget to use.

There is also another one for Gtk::SourceView, which may add some specialized functions/methods.

Class Methods

Gtk::TextView.new(buffer = nil)
Creates a new Gtk::TextView widget displaying the buffer. One buffer can be shared among many widgets. buffer may be nil to create a default buffer.

Instance Methods

buffer
Returns the Gtk::TextBuffer being displayed by the Gtk::TextView.
buffer=(buffer)
Sets buffer as the buffer being displayed by the Gtk::TextView.
set_buffer(buffer)
Same as Gtk::TextView#buffer=.
scroll_to_mark(mark, within_margin, use_align, xalign, yalign)
Scrolls the Gtk::TextView so that mark is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is false, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this method is reduced by a margin of size within_margin.
  • mark: a Gtk::TextMark
  • within_margin: margin as a 0.0, 0.5 fraction of screen size
  • use_align: whether to use alignment arguments (if false, just get the mark onscreen)
  • xalign: horizontal alignment of mark within visible area.
  • yalign: vertical alignment of mark within visible area
  • Returns: self
scroll_to_iter(iter, within_margin, use_align, xalign, yalign)
Scrolls the Gtk::TextView so that iter is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is false, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this method is reduced by a margin of size within_margin. NOTE: This method uses the currently-computed height of the lines in the text buffer. Note that line heights are computed in an idle handler; so this method may not have the desired effect if it's called before the height computations. To avoid oddness, consider using Gtk::TextView#scroll_to_mark which saves a point to be scrolled to after line validation.
  • iter: a Gtk::TextIter
  • within_margin: margin as a 0.0, 0.5 fraction of screen size
  • use_align: whether to use alignment arguments (if false, just get the mark onscreen)
  • xalign: horizontal alignment of mark within visible area.
  • yalign: vertical alignment of mark within visible area
  • Returns: true if scrolling occurred
scroll_mark_onscreen(mark)
Scrolls the Gtk::TextView the minimum distance such that mark is contained within the visible area of the widget.
move_mark_onscreen(mark)
Moves a mark within the buffer so that it's located within the currently-visible text area.
  • mark: a Gtk::TextMark
  • Returns: true if the mark moved (wasn't already onscreen)
place_cursor_onscreen
Moves the cursor to the currently visible region of the buffer, if it isn't there already.
  • Returns: true if the cursor had to be moved.
visible_rect
Returns the currently-visible region of the buffer, in buffer coordinates. Convert to window coordinates with Gtk::TextView#buffer_to_window_coords.
get_iter_location(iter)
Gets a Gdk::Rectangle which roughly contains the character at iter. The Gdk::Rectangle position is in buffer coordinates; use Gtk::TextView#buffer_to_window_coords to convert these coordinates to coordinates for one of the windows in the text view.
  • iter : a GtkTextIter
  • Returns: a Gdk::Rectangle which is the bounds of the character at iter
get_line_at_y(y)
Gets the Gtk::TextIter at the start of the line containing the coordinate y. y is in buffer coordinates, convert from window coordinates with Gtk::TextView#window_to_buffer_coords. If non-nil, line_top will be the coordinate of the top edge of the line.
  • y : a y coordinate
  • Returns [target_iter, line_top]
    • target_iter : a Gtk::TextIter
    • line_top: top coordinate of the line
get_line_yrange(iter)
Gets the y coordinate of the top of the line containing iter, and the height of the line. The coordinate is a buffer coordinate; convert to window coordinates with Gtk::TextView#buffer_to_window_coords.
  • iter : a GtkTextIter
  • Returns: [y, height]
    • y: a y coordinate
    • height: a height
get_iter_at_location(x, y)
Retrieves the iterator at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates with Gtk::TextView#window_to_buffer_coords.
  • x: x position, in buffer coordinates
  • y: y position, in buffer coordinates
  • Returns: a Gtk::TextIter
get_iter_at_position(x, y)
Retrieves the iterator pointing to the character at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates with Gtk::TextView#window_to_buffer_coords. Note that this is diffferent from Gtk::TextView#get_iter_at_location, which returns cursor locations, i.e. positions between characters. Since 2.6
  • x: x position, in buffer coordinates
  • y: y position, in buffer coordinates
  • Returns: [iter, trailing]
buffer_to_window_coords(win_type, buffer_x, buffer_y)
Converts coordinate (buffer_x, buffer_y) to coordinates for the window win, and stores the result in (window_x, window_y). Note that you can't convert coordinates for a nonexisting window (see Gtk::TextView#set_border_window_size).
window_to_buffer_coords(win_type, window_x, window_y)
Converts coordinates on the window identified by win to buffer coordinates, storing the result in (buffer_x,buffer_y). Note that you can't convert coordinates for a nonexisting window (see Gtk::TextView#set_border_window_size).
get_window(win_type)
Retrieves the Gdk::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. Windows are nil and nonexistent if their width or height is 0, and are nonexistent before the widget has been realized.
get_window_type(window)
Usually used to find out which window an event corresponds to. If you connect to an event signal on Gtk::TextView, this method should be called on event.window to see which window it was.
get_border_window_size(type)
Gets the width of the specified border window. See Gtk::TextView#set_border_window_size.
  • type: window to return size from
  • Returns: width of window
set_border_window_size(type, size)
Sets the width of Gtk::TextView::WINDOW_LEFT or Gtk::TextView::WINDOW_RIGHT, or the height of Gtk::TextView::WINDOW_TOP or Gtk::TextView::WINDOW_BOTTOM. Automatically destroys the corresponding window if the size is set to 0, and creates the window if the size is set to non-zero. This method can only be used for the "border windows," it doesn't work with Gtk::TextView::WINDOW_WIDGET, Gtk::TextView::WINDOW_TEXT, or Gtk::TextView::WINDOW_PRIVATE.
  • type: GtkTextWindowType to affect
  • size: width or height of the window
  • Returns: self
forward_display_line(iter)
Moves the given iter forward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. Display lines are divided differently for each view, since they depend on the view's width; paragraphs are the same in all views, since they depend on the contents of the Gtk::TextBuffer.
  • iter: a Gtk::TextIter
  • Returns: true if iter was moved and is not on the end iterator
backward_display_line(iter)
Moves the given iter backward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. Display lines are divided differently for each view, since they depend on the view's width; paragraphs are the same in all views, since they depend on the contents of the Gtk::TextBuffer.
  • iter: a Gtk::TextIter
  • Returns: true if iter was moved and is not on the end iterator
forward_display_line_end(iter)
Moves the given iter forward to the next display line end. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. Display lines are divided differently for each view, since they depend on the view's width; paragraphs are the same in all views, since they depend on the contents of the Gtk::TextBuffer.
  • iter: a Gtk::TextIter
  • Returns: true if iter was moved and is not on the end iterator
backward_display_line_start(iter)
Moves the given iter backward to the next display line start. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. Display lines are divided differently for each view, since they depend on the view's width; paragraphs are the same in all views, since they depend on the contents of the Gtk::TextBuffer.
  • iter: a Gtk::TextIter
  • Returns: true if iter was moved and is not on the end iterator
starts_display_line(iter)
Determines whether iter is at the start of a display line. See Gtk::TextView#forward_display_line for an explanation of display lines vs. paragraphs.
  • iter: a Gtk::TextIter
  • Returns: true if iter begins a wrapped line
move_visually(iter, count)
Moves iter up or down by count display (wrapped) lines. See Gtk::TextView#forward_display_line for an explanation of display lines vs. paragraphs.
  • iter: a Gtk::TextIter
  • count: number of lines to move
  • Returns: true if iter moved and is not on the end iterator
add_child_at_anchor(child, anchor)
Adds a child widget in the text buffer, at the given anchor.
add_child_in_window(child, which_window, xpos, ypos)
Adds a child at fixed coordinates in one of the text widget's windows. The window must have nonzero size (see Gtk::TextView#set_border_window_size). Note that the child coordinates are given relative to the Gdk::Window in question, and that these coordinates have no sane relationship to scrolling. When placing a child in Gtk::TextView::WINDOW_WIDGET, scrolling is irrelevant, the child floats above all scrollable areas. But when placing a child in one of the scrollable windows (border windows or text window), you'll need to compute the child's correct position in buffer coordinates any time scrolling occurs or buffer changes occur, and then call Gtk::TextView#move_child to update the child's position. Unfortunately there's no good way to detect that scrolling has occurred, using the current API; a possible hack would be to update all child positions when the scroll adjustments change or the text buffer changes. See bug 64518 on bugzilla.gnome.org for status of fixing this issue.
  • child: a Gtk::Widget
  • which_window: which window the child should appear in
  • xpos: X position of child in window coordinates
  • ypos: Y position of child in window coordinates
  • Returns: self
move_child(child, xpos, ypos)
Updates the position of a child, as for Gtk::TextView#add_child_in_window.
  • child: child widget already added to the text view
  • xpos: new X position in window coordinates
  • ypos: new Y position in window coordinates
  • Returns: self
wrap_mode
Gets the line wrapping for the view.
wrap_mode=(wrap_mode)
Sets the line wrapping for the view.
set_wrap_mode(wrap_mode)
Same as Gtk::TextView#wrap_mode=.
editable?
Returns the default editability of the Gtk::TextView. Tags in the buffer may override this setting for some ranges of text.
  • Returns: whether text is editable by default
editable=(setting)
Sets the default editability of the Gtk::TextView. You can override this default setting with tags in the buffer, using the "editable" attribute of tags.
  • setting: true if it's editable
  • Returns: setting
set_editable
Same as Gtk::TextView#editable=.
  • setting: true if it's editable
  • Returns: self
cursor_visible?
Find out whether the cursor is being displayed.
  • Returns: true if the insertion mark is visible
cursor_visible=(setting)
Toggles whether the insertion point is displayed. A buffer with no editable text probably shouldn't have a visible cursor, so you may want to turn the cursor off.
  • setting: true if to show the insertion cursor
  • Returns: setting
set_cursor_visible(setting)
Same as Gtk::TextView#cursor_visible=.
  • setting: true if to show the insertion cursor
  • Returns: self
overwrite?
Returns whether the Gtk::TextView is in overwrite mode or not. Since 2.4
  • Returns: true if overwrite.
overwrite=(setting)
Changes the Gtk::TextView overwrite mode. Since 2.4
  • setting: true if overwrite.
  • Returns: setting
set_overwrite(setting)
Same as Gtk::TextView#overwrite=. Since 2.4
  • setting: true if overwrite.
  • Returns: self
pixels_above_lines
Gets the default number of pixels to put above paragraphs.
  • Returns: default number of pixels above paragraphs
pixels_above_lines=(pixels_above_lines)
Sets the default number of blank pixels above paragraphs in the Gtk::TextView. Tags in the buffer for the Gtk::TextView may override the defaults.
  • pixels_above_lines: pixels above paragraphs
  • Returns: pixels_above_lines
set_pixels_above_lines(pixels_above_lines)
Same as Gtk::TextView#pixels_above_lines=.
  • pixels_above_lines: pixels above paragraphs
  • Returns: self
pixels_below_lines
Gets the value set by Gtk::TextView#pixels_below_lines=.
  • Returns: default number of blank pixels below paragraphs
pixels_below_lines=(pixels below paragraphs)
Sets the default number of pixels of blank space to put below paragraphs in the Gtk::TextView. May be overridden by tags applied to the Gtk::TextView's buffer.
  • pixels_below_lines: pixels below paragraphs
  • Returns: pixels below paragraphs
set_pixels_below_lines(pixels_below_lines)
Same as Gtk::TextView#pixels_below_lines=.
  • pixels_below_lines: pixels below paragraphs
  • Returns: self
pixels_inside_wrap
Gets the value set by Gtk::TextView#pixels_inside_wrap=.
  • Returns: default number of pixels of blank space between wrapped lines
pixels_inside_wrap=(pixels_inside_wrap)
Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. May be overridden by tags in the Gtk::TextView's buffer.
  • pixels_inside_wrap: default number of pixels between wrapped lines
  • Returns: pixels_inside_wrap
set_pixels_inside_wrap(pixels_inside_wrap)
Same as Gtk::TextView#pixels_inside_wrap=.
  • pixels_inside_wrap: default number of pixels between wrapped lines
  • Returns: self
justification
Gets the default justification of paragraphs in the Gtk::TextView. Tags in the buffer may override the default.
  • Returns: default justification
justification=(justification)
Sets the default justification of text in the Gtk::TextView. Tags in the view's buffer may override the default.
  • justification: justification
  • Returns: justification
set_justification(justification)
Same as Gtk::TextView#justification=.
  • justification: justification
  • Returns: self
left_margin
Gets the default left margin size of paragraphs in the Gtk::TextView. Tags in the buffer may override the default.
  • Returns: left margin in pixels
left_margin=(left_margin)
Sets the default left margin for text in the Gtk::TextView. Tags in the buffer may override the default.
  • left_margin: left margin in pixels
  • Returns: left_margin
set_left_margin(left_margin)
Same as Gtk::TextView#left_margin=.
  • left_margin: left margin in pixels
  • Returns: self
right_margin
Gets the default right margin for text in the Gtk::TextView. Tags in the buffer may override the default.
  • Returns: right margin in pixels
right_margin=(right_margin)
Sets the default right margin for text in the Gtk::TextView. Tags in the buffer may override the default.
  • right_margin: right margin in pixels
  • Returns: right_margin
set_right_margin(right_margin)
Same as Gtk::TextView#right_margin=.
  • right_margin: right margin in pixels
  • Returns: self
indent
Gets the default indentation of paragraphs in the Gtk::TextView. Tags in the view's buffer may override the default. The indentation may be negative.
  • Returns: number of pixels of indentation
indent=(indent)
Sets the default indentation for paragraphs in the Gtk::TextView. Text that will be entered, will appear after this indentation given. The indent value may be obtained by using the method .indent - see above for a description. Note that tags in the buffer may override the default.
  • indent : indentation in pixels
  • Returns: indent
set_indent(indent)
Same as Gtk::TextView#indent=.
  • indent : indentation in pixels
  • Returns: self
tabs
Gets the default tabs for text_view. Tags in the buffer may override the defaults. The returned array will be nil if "standard" (8-space) tabs are used.
  • Returns: copy of default tab array, or nil if "standard" tabs are used
tabs=(tabs)
Sets the default tab stops for paragraphs in the Gtk::TextView. Tags in the buffer may override the default.
set_tabs(tabs)
Same as Gtk::TextView#tabs=.
accepts_tab?
Returns whether pressing the Tab key inserts a tab characters. See Gtk::TextView#accepts_tab=.
  • Returns: true if pressing the Tab key inserts a tab character, false if pressing the Tab key moves the keyboard focus. Since 2.4
accepts_tab=(accepts_tab)
Sets the behavior of the text widget when the Tab key is pressed. If accepts_tab is true a tab character is inserted. If accepts_tab is false the keyboard focus is moved to the next widget in the focus chain.
  • accepts_tab: true if pressing the Tab key should insert a tab character, false, if pressing the Tab key should move the keyboard focus. Since 2.4
  • Returns: accepts_tab
set_accepts_tab(accepts_tab)
Same as Gtk::TextView#accepts_tab=. Since 2.4
  • accepts_tab: true if pressing the Tab key should insert a tab character, false, if pressing the Tab key should move the keyboard focus. Since 2.4
  • Returns: self
default_attributes
Returns a copy of the default text attributes. These are the attributes used for text unless a tag overrides them. You'd typically pass the default attributes in to Gtk::TextIter#attributes in order to get the attributes in effect at a given text position.
backspace
Emits backspace signal.
  • Returns: self
copy_clipboard
Emits copy-clipboard signal.
  • Returns: self
cut_clipboard
Emits cut-clipboard signal.
  • Returns: self
delete_from_cursor(type, count)
Emits delete-from-cursor signal.
  • type: GtkDeleteType
  • count: the number of deletions to do
  • Returns: self
insert_at_cursor(str)
Emits insert-at-cursor signal.
  • str: a String
  • Returns: self
move_cursor(step, count, textend_selection)
Emits move-cursor signal.
  • step: GtkMovementStep
  • count: the number of step units to move (Integer)
  • extend_selection: true if the move should extend the selection, otherwise false
  • Returns: self
move_focus(type)
Emits move-focus signal.
move_viewport(step, arg2)
Emits move-viewport signal.
page_horizontally(arg1, arg2)
Emits page-horizontally signal.
  • arg1: Integer
  • arg2: true or false
  • Returns: self
paste_clipboard
Emits paste-clipboard signal.
  • Returns: self
select_all(setting)
Emits select-all signal.
  • setting: true or false
  • Returns: self
set_anchor
Emits set-anchor signal.
  • Returns: self
set_scroll_adjustments(adj1, adj2)
Emits set-scroll-adjustments signal.
toggle_overwrite
Emits toggle-overwrite signal.
  • Returns: self
ref_accessible
See Atk::Implementor#ref_accessible.
toggle_cursor_visible
The ::toggle-cursor-visible signal is a keybinding signal, which gets emitted to toggle the visibility of the cursor. The default binding for this signal in Gnome applications will be F7.
  • Returns: self
add_child
See Gtk::Buildable#add_child.
construct_child
See Gtk::Buildable#construct_child.
get_internal_child
See Gtk::Buildable#get_internal_child.
name
See Gtk::Buildable#name.
name=
See Gtk::Buildable#name=.
set_buildable_property
See Gtk::Buildable#set_buildable_property.
set_name
See Gtk::Buildable#set_name.
builder_name
See Gtk::Buildable#builder_name.
builder_name=
See Gtk::Buildable#builder_name=.
im_module
Gets the Which IM module should be used.
  • Returns: Which IM module should be used
im_module=(im_module)
Sets the Which IM module should be used.
  • im_module: Which IM module should be used
  • Returns: im_module
preedit_changed
  • Returns: self: FIXME
set_builder_name
See Gtk::Buildable#set_builder_name.
set_im_module(im_module)
Same as im_module=.
  • im_module: Which IM module should be used
  • Returns: self

Constants

GtkTextWindowType

WINDOW_PRIVATE
WINDOW_WIDGET
WINDOW_TEXT
WINDOW_LEFT
WINDOW_RIGHT
WINDOW_TOP
WINDOW_BOTTOM

Priority

PRIORITY_VALIDATE
The priority at which the text view validates onscreen lines in an idle job in the background(Gdk::PRIORITY_REDRAW + 5).

Properties

accepts-tab: true or false (Read/Write)
Whether Tab will result in a tab character being entered. Since 2.4
  • Default value: true
buffer: Gtk::TextBuffer (Read/Write)
The buffer which is displayed.
cursor-visible: true or false (Read/Write)
If the insertion cursor is shown
  • Default value: true
editable: true or false (Read/Write)
Whether the text can be modified by the user
  • Default value: true
indent: Integer (Read/Write)
Amount to indent the paragraph, in pixels
  • Allowed values: >= 0
  • Default value: 0
justification: Integer (Read/Write)
Left, right, or center justification
left-margin: Integer (Read/Write)
Width of the left margin in pixels
  • Allowed values: >= 0
  • Default value: 0
overwrite: true or false (Read/Write)
Whether entered text overwrites existing contents. Since 2.4
  • Default value: false
pixels-above-lines: Integer (Read/Write)
Pixels of blank space above paragraphs.
  • Allowed values: >= 0
  • Default value: 0
pixels-below-lines: Integer (Read/Write)
Pixels of blank space below paragraphs.
  • Allowed values: >= 0
  • Default value: 0
pixels-inside-wrap: Integer (Read/Write)
Pixels of blank space between wrapped lines in a paragraph.
  • Allowed values: >= 0
  • Default value: 0
right-margin: Integer (Read/Write)
Width of the right margin in pixels.
  • Allowed values: >= 0
  • Default value: 0
tabs: Pango::TabArray (Read/Write)
Custom tabs for this text
wrap-mode: ((<GtkWrapMode|Gtk::TextTag#GtkWrapMode>)) (Read/Write)
Whether to wrap lines never, at word boundaries, or at character boundaries
im-module: String (Read/Write)
Which IM module should be used

Style Properties

error-underline-color: Gdk::Color (Read)
Color with which to draw error-indication underlines

Signals

backspace: self
copy-clipboard: self
cut-clipboard: self
delete-from-cursor: self, type, arg2
insert-at-cursor: self, arg1
move-cursor: self, step, arg2, arg3
The ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement. Applications should not connect to it, but may emit it with GLib::Instantiatable#signal_emit if they need to control scrolling programmatically.
  • self: the Gtk::TextView
  • step: GtkMovementStep
  • count: the number of step units to move (Integer)
  • extend_selection: true if the move should extend the selection, otherwise false
move-focus: self, type
move-viewport: self, step, arg2
page-horizontally: self, arg1, arg2
paste-clipboard: self
preedit-changed: self, preedit

If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.

This signal is only emitted if the text at the given position is actually editable.

populate-popup: self, menu
select-all: self, arg1
set-anchor: self
set-scroll-adjustments: self, adj1, adj2
toggle-overwrite: self
toggle-cursor-visible: self

ChangeLog

  • 2005-06-17 Added GTK+-2.4/2.6 methods. - Masao
  • 2003-07-29 Added - Masao