Widget that displays a
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.
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
<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.
<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 togtk-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>
.
<gtk-text-view>
) (buffer <gtk-text-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>
<gtk-text-view>
) ⇒ (ret <gtk-text-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>
<gtk-text-view>
) (mark <gtk-text-mark>
) (within_margin double
) (use_align bool
) (xalign double
) (yalign double
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) (within_margin double
) (use_align bool
) (xalign double
) (yalign double
) ⇒ (ret bool
)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 usinggtk-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
<gtk-text-view>
) (mark <gtk-text-mark>
)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
<gtk-text-view>
) (mark <gtk-text-mark>
) ⇒ (ret bool
)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)
<gtk-text-view>
) ⇒ (ret bool
)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.
<gtk-text-view>
) (visible_rect <gdk-rectangle>
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) (location <gdk-rectangle>
)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
<gtk-text-view>
) (target_iter <gtk-text-iter>
) (y int
) ⇒ (line_top int
)Gets the
<gtk-text-iter>
at the start of the line containing the coordinate y. y is in buffer coordinates, convert from window coordinates withgtk-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
<gtk-text-view>
) (iter <gtk-text-iter>
) ⇒ (y int
) (height int
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) (x int
) (y int
)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
<gtk-text-view>
) (win <gtk-text-window-type>
) ⇒ (ret <gdk-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
’
<gtk-text-view>
) (window <gdk-window>
) ⇒ (ret <gtk-text-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.
<gtk-text-view>
) (iter <gtk-text-iter>
) ⇒ (ret bool
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) ⇒ (ret bool
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) ⇒ (ret bool
)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
<gtk-text-view>
) (iter <gtk-text-iter>
) (count int
) ⇒ (ret bool
)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
<gtk-text-view>
) (child <gtk-widget>
) (anchor <gtk-text-child-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
<gtk-text-child-anchor>
)Creates a new
<gtk-text-child-anchor>
. Usually you would then insert it into a<gtk-text-buffer>
withgtk-text-buffer-insert-child-anchor
. To perform the creation and insertion in one step, use the convenience functiongtk-text-buffer-create-child-anchor
.
- ret
- a new
<gtk-text-child-anchor>
<gtk-text-child-anchor>
) ⇒ (ret glist-of
)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
<gtk-text-child-anchor>
) ⇒ (ret bool
)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 — 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
<gtk-text-view>
) (child <gtk-widget>
) (which_window <gtk-text-window-type>
) (xpos int
) (ypos int
)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 callgtk-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
<gtk-text-view>
) (child <gtk-widget>
) (xpos int
) (ypos int
)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
<gtk-text-view>
) (wrap_mode <gtk-wrap-mode>
)Sets the line wrapping for the view.
- text-view
- a
<gtk-text-view>
- wrap-mode
- a
<gtk-wrap-mode>
<gtk-text-view>
) ⇒ (ret <gtk-wrap-mode>
)Gets the line wrapping for the view.
- text-view
- a
<gtk-text-view>
- ret
- the line wrap setting
<gtk-text-view>
) (setting bool
)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
<gtk-text-view>
) ⇒ (ret bool
)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
<gtk-text-view>
) (setting bool
)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
<gtk-text-view>
) ⇒ (ret bool
)Find out whether the cursor is being displayed.
- text-view
- a
<gtk-text-view>
- ret
- whether the insertion mark is visible
<gtk-text-view>
) (overwrite bool
)Changes the
<gtk-text-view>
overwrite mode.
- text-view
- a
<gtk-text-view>
- overwrite
- ‘
#t
’ to turn on overwrite mode, ‘#f
’ to turn it offSince 2.4
<gtk-text-view>
) ⇒ (ret bool
)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
<gtk-text-view>
) (justification <gtk-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
<gtk-text-view>
) ⇒ (ret <gtk-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
<gtk-text-view>
) (left_margin int
)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
<gtk-text-view>
) ⇒ (ret int
)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
<gtk-text-view>
) (right_margin int
)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
<gtk-text-view>
) ⇒ (ret int
)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
<gtk-text-view>
) (indent int
)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
<gtk-text-view>
) ⇒ (ret int
)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
<gtk-text-view>
) (tabs <pango-tab-array>
)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>
<gtk-text-view>
) ⇒ (ret <pango-tab-array>
)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 withpango-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 withpango-tab-array-free
.
<gtk-text-view>
) (accepts_tab bool
)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
<gtk-text-view>
) ⇒ (ret bool
)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