Next: , Previous: GtkTextTagTable, Up: Top


31 GtkTextView

Widget that displays a

31.1 Overview

You may wish to begin by reading the text widget conceptual overview which gives an overview of all the objects and data types related to the text widget and how they work together.

31.2 Usage

— Class: <gtk-text-view>

Derives from <gtk-container>.

This class defines the following slots:

pixels-above-lines
Pixels of blank space above paragraphs
pixels-below-lines
Pixels of blank space below paragraphs
pixels-inside-wrap
Pixels of blank space between wrapped lines in a paragraph
editable
Whether the text can be modified by the user
wrap-mode
Whether to wrap lines never, at word boundaries, or at character boundaries
justification
Left, right, or center justification
left-margin
Width of the left margin in pixels
right-margin
Width of the right margin in pixels
indent
Amount to indent the paragraph, in pixels
tabs
Custom tabs for this text
cursor-visible
If the insertion cursor is shown
buffer
The buffer which is displayed
overwrite
Whether entered text overwrites existing contents
accepts-tab
Whether Tab will result in a tab character being entered
— Signal on <gtk-text-view>: move-cursor (arg0 <gtk-movement-step>) (arg1 <gint>) (arg2 <gboolean>)

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 g-signal-emit-by-name if they need to control scrolling programmatically.

— Signal on <gtk-text-view>: copy-clipboard
— Signal on <gtk-text-view>: populate-popup (arg0 <gtk-menu>)
— Signal on <gtk-text-view>: insert-at-cursor (arg0 <gchararray>)
— Signal on <gtk-text-view>: delete-from-cursor (arg0 <gtk-delete-type>) (arg1 <gint>)
— Signal on <gtk-text-view>: backspace
— Signal on <gtk-text-view>: cut-clipboard
— Signal on <gtk-text-view>: paste-clipboard
— Signal on <gtk-text-view>: toggle-overwrite
— Signal on <gtk-text-view>: set-scroll-adjustments (arg0 <gtk-adjustment>) (arg1 <gtk-adjustment>)
— Signal on <gtk-text-view>: select-all (arg0 <gboolean>)
— Signal on <gtk-text-view>: page-horizontally (arg0 <gint>) (arg1 <gboolean>)
— Signal on <gtk-text-view>: move-viewport (arg0 <gtk-scroll-step>) (arg1 <gint>)
— Signal on <gtk-text-view>: set-anchor
— Signal on <gtk-text-view>: toggle-cursor-visible

undocumented

— Class: <gtk-text-child-anchor>

Derives from <gobject>.

This class defines no direct slots.

— Function: gtk-text-view-new-with-buffer (buffer <gtk-text-buffer>) ⇒  (ret <gtk-widget>)

Creates a new <gtk-text-view> widget displaying the buffer buffer. One buffer can be shared among many widgets. buffer may be NULL to create a default buffer, in which case this function is equivalent to gtk-text-view-new. The text view adds its own reference count to the buffer; it does not take over an existing reference.

buffer
a <gtk-text-buffer>
ret
a new <gtk-text-view>.
— Function: gtk-text-view-set-buffer (self <gtk-text-view>) (buffer <gtk-text-buffer>)
— Method: set-buffer

Sets buffer as the buffer being displayed by text-view. The previous buffer displayed by the text view is unreferenced, and a reference is added to buffer. If you owned a reference to buffer before passing it to this function, you must remove that reference yourself; <gtk-text-view> will not "adopt" it.

text-view
a <gtk-text-view>
buffer
a <gtk-text-buffer>
— Function: gtk-text-view-get-buffer (self <gtk-text-view>) ⇒  (ret <gtk-text-buffer>)
— Method: get-buffer

Returns the <gtk-text-buffer> being displayed by this text view. The reference count on the buffer is not incremented; the caller of this function won't own a new reference.

text-view
a <gtk-text-view>
ret
a <gtk-text-buffer>
— Function: gtk-text-view-scroll-to-mark (self <gtk-text-view>) (mark <gtk-text-mark>) (within_margin double) (use_align bool) (xalign double) (yalign double)
— Method: scroll-to-mark

Scrolls text-view 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 ‘#f’, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of size within-margin.

text-view
a <gtk-text-view>
mark
a <gtk-text-mark>
within-margin
margin as a [0.0,0.5) fraction of screen size
use-align
whether to use alignment arguments (if ‘#f’, just get the mark onscreen)
xalign
horizontal alignment of mark within visible area.
yalign
vertical alignment of mark within visible area
— Function: gtk-text-view-scroll-to-iter (self <gtk-text-view>) (iter <gtk-text-iter>) (within_margin double) (use_align bool) (xalign double) (yalign double) ⇒  (ret bool)
— Method: scroll-to-iter

Scrolls text-view 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 ‘#f’, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of size within-margin. NOTE: This function uses the currently-computed height of the lines in the text buffer. Note that line heights are computed in an idle handler; so this function may not have the desired effect if it's called before the height computations. To avoid oddness, consider using gtk-text-view-scroll-to-mark which saves a point to be scrolled to after line validation.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
within-margin
margin as a [0.0,0.5) fraction of screen size
use-align
whether to use alignment arguments (if ‘#f’, just get the mark onscreen)
xalign
horizontal alignment of mark within visible area.
yalign
vertical alignment of mark within visible area
ret
#t’ if scrolling occurred
— Function: gtk-text-view-scroll-mark-onscreen (self <gtk-text-view>) (mark <gtk-text-mark>)
— Method: scroll-mark-onscreen

Scrolls text-view the minimum distance such that mark is contained within the visible area of the widget.

text-view
a <gtk-text-view>
mark
a mark in the buffer for text-view
— Function: gtk-text-view-move-mark-onscreen (self <gtk-text-view>) (mark <gtk-text-mark>) ⇒  (ret bool)
— Method: move-mark-onscreen

Moves a mark within the buffer so that it's located within the currently-visible text area.

text-view
a <gtk-text-view>
mark
a <gtk-text-mark>
ret
#t’ if the mark moved (wasn't already onscreen)
— Function: gtk-text-view-place-cursor-onscreen (self <gtk-text-view>) ⇒  (ret bool)
— Method: place-cursor-onscreen

Moves the cursor to the currently visible region of the buffer, it it isn't there already.

text-view
a <gtk-text-view>
ret
TRUE if the cursor had to be moved.
— Function: gtk-text-view-get-visible-rect (self <gtk-text-view>) (visible_rect <gdk-rectangle>)
— Method: get-visible-rect

Fills visible-rect with the currently-visible region of the buffer, in buffer coordinates. Convert to window coordinates with gtk-text-view-buffer-to-window-coords.

text-view
a <gtk-text-view>
visible-rect
rectangle to fill
— Function: gtk-text-view-get-iter-location (self <gtk-text-view>) (iter <gtk-text-iter>) (location <gdk-rectangle>)
— Method: get-iter-location

Gets a rectangle which roughly contains the character at iter. The rectangle position is in buffer coordinates; use gtk-text-view-buffer-to-window-coords to convert these coordinates to coordinates for one of the windows in the text view.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
location
bounds of the character at iter
— Function: gtk-text-view-get-line-at-y (self <gtk-text-view>) (target_iter <gtk-text-iter>) (int) ⇒  (line_top int)
— Method: get-line-at-y

Gets the <gtk-text-iter> at the start of the line containing the coordinate y. y is in buffer coordinates, convert from window coordinates with gtk-text-view-window-to-buffer-coords. If non-‘#f’, line-top will be filled with the coordinate of the top edge of the line.

text-view
a <gtk-text-view>
target-iter
a <gtk-text-iter>
y
a y coordinate
line-top
return location for top coordinate of the line
— Function: gtk-text-view-get-line-yrange (self <gtk-text-view>) (iter <gtk-text-iter>) ⇒  (int) (height int)
— Method: get-line-yrange

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-text-view-buffer-to-window-coords.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
y
return location for a y coordinate
height
return location for a height
— Function: gtk-text-view-get-iter-at-location (self <gtk-text-view>) (iter <gtk-text-iter>) (int) (int)
— Method: get-iter-at-location

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-text-view-window-to-buffer-coords.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
x
x position, in buffer coordinates
y
y position, in buffer coordinates
— Function: gtk-text-view-get-window (self <gtk-text-view>) (win <gtk-text-window-type>) ⇒  (ret <gdk-window>)
— Method: get-window

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 ‘#f’ and nonexistent if their width or height is 0, and are nonexistent before the widget has been realized.

text-view
a <gtk-text-view>
win
window to get
ret
a <gdk-window>, or ‘#f
— Function: gtk-text-view-get-window-type (self <gtk-text-view>) (window <gdk-window>) ⇒  (ret <gtk-text-window-type>)
— Method: get-window-type

Usually used to find out which window an event corresponds to. If you connect to an event signal on text-view, this function should be called on ‘event->window’ to see which window it was.

text-view
a <gtk-text-view>
window
a window type
ret
the window type.
— Function: gtk-text-view-forward-display-line (self <gtk-text-view>) (iter <gtk-text-iter>) ⇒  (ret bool)
— Method: forward-display-line

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-text-buffer>.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
ret
#t’ if iter was moved and is not on the end iterator
— Function: gtk-text-view-backward-display-line (self <gtk-text-view>) (iter <gtk-text-iter>) ⇒  (ret bool)
— Method: backward-display-line

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-text-buffer>.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
ret
#t’ if iter was moved and is not on the end iterator
— Function: gtk-text-view-starts-display-line (self <gtk-text-view>) (iter <gtk-text-iter>) ⇒  (ret bool)
— Method: starts-display-line

Determines whether iter is at the start of a display line. See gtk-text-view-forward-display-line for an explanation of display lines vs. paragraphs.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
ret
#t’ if iter begins a wrapped line
— Function: gtk-text-view-move-visually (self <gtk-text-view>) (iter <gtk-text-iter>) (count int) ⇒  (ret bool)
— Method: move-visually

Move the iterator a given number of characters visually, treating it as the strong cursor position. If count is positive, then the new strong cursor position will be count positions to the right of the old cursor position. If count is negative then the new strong cursor position will be count positions to the left of the old cursor position.

In the presence of bidirection text, the correspondence between logical and visual order will depend on the direction of the current run, and there may be jumps when the cursor is moved off of the end of a run.

text-view
a <gtk-text-view>
iter
a <gtk-text-iter>
count
number of characters to move (negative moves left, positive moves right)
ret
#t’ if iter moved and is not on the end iterator
— Function: gtk-text-view-add-child-at-anchor (self <gtk-text-view>) (child <gtk-widget>) (anchor <gtk-text-child-anchor>)
— Method: add-child-at-anchor

Adds a child widget in the text buffer, at the given anchor.

text-view
a <gtk-text-view>
child
a <gtk-widget>
anchor
a <gtk-text-child-anchor> in the <gtk-text-buffer> for text-view
— Function: gtk-text-child-anchor-new ⇒  (ret <gtk-text-child-anchor>)

Creates a new <gtk-text-child-anchor>. Usually you would then insert it into a <gtk-text-buffer> with gtk-text-buffer-insert-child-anchor. To perform the creation and insertion in one step, use the convenience function gtk-text-buffer-create-child-anchor.

ret
a new <gtk-text-child-anchor>
— Function: gtk-text-child-anchor-get-widgets (self <gtk-text-child-anchor>) ⇒  (ret glist-of)
— Method: get-widgets

Gets a list of all widgets anchored at this child anchor. The returned list should be freed with g-list-free.

anchor
a <gtk-text-child-anchor>
ret
list of widgets anchored at anchor
— Function: gtk-text-child-anchor-get-deleted (self <gtk-text-child-anchor>) ⇒  (ret bool)
— Method: get-deleted

Determines whether a child anchor has been deleted from the buffer. Keep in mind that the child anchor will be unreferenced when removed from the buffer, so you need to hold your own reference (with g-object-ref) if you plan to use this function &#x2014; otherwise all deleted child anchors will also be finalized.

anchor
a <gtk-text-child-anchor>
ret
#t’ if the child anchor has been deleted from its buffer
— Function: gtk-text-view-add-child-in-window (self <gtk-text-view>) (child <gtk-widget>) (which_window <gtk-text-window-type>) (xpos int) (ypos int)
— Method: add-child-in-window

Adds a child at fixed coordinates in one of the text widget's windows. The window must have nonzero size (see gtk-text-view-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-text-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-text-view-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.

text-view
a <gtk-text-view>
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
— Function: gtk-text-view-move-child (self <gtk-text-view>) (child <gtk-widget>) (xpos int) (ypos int)
— Method: move-child

Updates the position of a child, as for gtk-text-view-add-child-in-window.

text-view
a <gtk-text-view>
child
child widget already added to the text view
xpos
new X position in window coordinates
ypos
new Y position in window coordinates
— Function: gtk-text-view-set-wrap-mode (self <gtk-text-view>) (wrap_mode <gtk-wrap-mode>)
— Method: set-wrap-mode

Sets the line wrapping for the view.

text-view
a <gtk-text-view>
wrap-mode
a <gtk-wrap-mode>
— Function: gtk-text-view-get-wrap-mode (self <gtk-text-view>) ⇒  (ret <gtk-wrap-mode>)
— Method: get-wrap-mode

Gets the line wrapping for the view.

text-view
a <gtk-text-view>
ret
the line wrap setting
— Function: gtk-text-view-set-editable (self <gtk-text-view>) (setting bool)
— Method: set-editable

Sets the default editability of the <gtk-text-view>. You can override this default setting with tags in the buffer, using the "editable" attribute of tags.

text-view
a <gtk-text-view>
setting
whether it's editable
— Function: gtk-text-view-get-editable (self <gtk-text-view>) ⇒  (ret bool)
— Method: get-editable

Returns the default editability of the <gtk-text-view>. Tags in the buffer may override this setting for some ranges of text.

text-view
a <gtk-text-view>
ret
whether text is editable by default
— Function: gtk-text-view-set-cursor-visible (self <gtk-text-view>) (setting bool)
— Method: set-cursor-visible

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.

text-view
a <gtk-text-view>
setting
whether to show the insertion cursor
— Function: gtk-text-view-get-cursor-visible (self <gtk-text-view>) ⇒  (ret bool)
— Method: get-cursor-visible

Find out whether the cursor is being displayed.

text-view
a <gtk-text-view>
ret
whether the insertion mark is visible
— Function: gtk-text-view-set-overwrite (self <gtk-text-view>) (overwrite bool)
— Method: set-overwrite

Changes the <gtk-text-view> overwrite mode.

text-view
a <gtk-text-view>
overwrite
#t’ to turn on overwrite mode, ‘#f’ to turn it off

Since 2.4

— Function: gtk-text-view-get-overwrite (self <gtk-text-view>) ⇒  (ret bool)
— Method: get-overwrite

Returns whether the <gtk-text-view> is in overwrite mode or not.

text-view
a <gtk-text-view>
ret
whether text-view is in overwrite mode or not.

Since 2.4

— Function: gtk-text-view-set-justification (self <gtk-text-view>) (justification <gtk-justification>)
— Method: set-justification

Sets the default justification of text in text-view. Tags in the view's buffer may override the default.

text-view
a <gtk-text-view>
justification
justification
— Function: gtk-text-view-get-justification (self <gtk-text-view>) ⇒  (ret <gtk-justification>)
— Method: get-justification

Gets the default justification of paragraphs in text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
ret
default justification
— Function: gtk-text-view-set-left-margin (self <gtk-text-view>) (left_margin int)
— Method: set-left-margin

Sets the default left margin for text in text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
left-margin
left margin in pixels
— Function: gtk-text-view-get-left-margin (self <gtk-text-view>) ⇒  (ret int)
— Method: get-left-margin

Gets the default left margin size of paragraphs in the text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
ret
left margin in pixels
— Function: gtk-text-view-set-right-margin (self <gtk-text-view>) (right_margin int)
— Method: set-right-margin

Sets the default right margin for text in the text view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
right-margin
right margin in pixels
— Function: gtk-text-view-get-right-margin (self <gtk-text-view>) ⇒  (ret int)
— Method: get-right-margin

Gets the default right margin for text in text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
ret
right margin in pixels
— Function: gtk-text-view-set-indent (self <gtk-text-view>) (indent int)
— Method: set-indent

Sets the default indentation for paragraphs in text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
indent
indentation in pixels
— Function: gtk-text-view-get-indent (self <gtk-text-view>) ⇒  (ret int)
— Method: get-indent

Gets the default indentation of paragraphs in text-view. Tags in the view's buffer may override the default. The indentation may be negative.

text-view
a <gtk-text-view>
ret
number of pixels of indentation
— Function: gtk-text-view-set-tabs (self <gtk-text-view>) (tabs <pango-tab-array>)
— Method: set-tabs

Sets the default tab stops for paragraphs in text-view. Tags in the buffer may override the default.

text-view
a <gtk-text-view>
tabs
tabs as a <pango-tab-array>
— Function: gtk-text-view-get-tabs (self <gtk-text-view>) ⇒  (ret <pango-tab-array>)
— Method: get-tabs

Gets the default tabs for text-view. Tags in the buffer may override the defaults. The returned array will be ‘#f’ if "standard" (8-space) tabs are used. Free the return value with pango-tab-array-free.

text-view
a <gtk-text-view>
ret
copy of default tab array, or ‘#f’ if "standard" tabs are used; must be freed with pango-tab-array-free.
— Function: gtk-text-view-set-accepts-tab (self <gtk-text-view>) (accepts_tab bool)
— Method: set-accepts-tab

Sets the behavior of the text widget when the Tab key is pressed. If accepts-tab is ‘#t’ a tab character is inserted. If accepts-tab is ‘#f’ the keyboard focus is moved to the next widget in the focus chain.

text-view
A <gtk-text-view>
accepts-tab
#t’ if pressing the Tab key should insert a tab character, ‘#f’, if pressing the Tab key should move the keyboard focus.

Since 2.4

— Function: gtk-text-view-get-accepts-tab (self <gtk-text-view>) ⇒  (ret bool)
— Method: get-accepts-tab

Returns whether pressing the Tab key inserts a tab characters. gtk-text-view-set-accepts-tab.

text-view
A <gtk-text-view>
ret
#t’ if pressing the Tab key inserts a tab character, ‘#f’ if pressing the Tab key moves the keyboard focus.

Since 2.4