Top |
Functions
Properties
gboolean | accepts-tab | Read / Write |
int | bottom-margin | Read / Write |
GtkTextBuffer * | buffer | Read / Write |
gboolean | cursor-visible | Read / Write |
gboolean | editable | Read / Write |
GMenuModel * | extra-menu | Read / Write |
char * | im-module | Read / Write |
int | indent | Read / Write |
GtkInputHints | input-hints | Read / Write |
GtkInputPurpose | input-purpose | Read / Write |
GtkJustification | justification | Read / Write |
int | left-margin | Read / Write |
gboolean | monospace | Read / Write |
gboolean | overwrite | Read / Write |
int | pixels-above-lines | Read / Write |
int | pixels-below-lines | Read / Write |
int | pixels-inside-wrap | Read / Write |
int | right-margin | Read / Write |
PangoTabArray * | tabs | Read / Write |
int | top-margin | Read / Write |
GtkWrapMode | wrap-mode | Read / Write |
Signals
void | backspace | Action |
void | copy-clipboard | Action |
void | cut-clipboard | Action |
void | delete-from-cursor | Action |
gboolean | extend-selection | Run Last |
void | insert-at-cursor | Action |
void | insert-emoji | Action |
void | move-cursor | Action |
void | move-viewport | Action |
void | paste-clipboard | Action |
void | preedit-changed | Action |
void | select-all | Action |
void | set-anchor | Action |
void | toggle-cursor-visible | Action |
void | toggle-overwrite | Action |
Actions
menu.popup | ||
text.redo | ||
text.undo | ||
misc.insert-emoji | ||
selection.select-all | ||
selection.delete | ||
clipboard.paste | ||
clipboard.copy | ||
clipboard.cut |
Types and Values
struct | GtkTextView |
struct | GtkTextViewClass |
enum | GtkTextViewLayer |
enum | GtkTextWindowType |
enum | GtkTextExtendSelection |
enum | GtkWrapMode |
struct | GtkTextChildAnchor |
#define | GTK_TEXT_VIEW_PRIORITY_VALIDATE |
Object Hierarchy
GObject ├── GInitiallyUnowned │ ╰── GtkWidget │ ╰── GtkTextView ╰── GtkTextChildAnchor
Implemented Interfaces
GtkTextView implements GtkAccessible, GtkBuildable, GtkConstraintTarget and GtkScrollable.
Description
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.
CSS nodes
1 2 3 4 5 6 7 8 |
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.
Functions
gtk_text_view_new ()
GtkWidget *
gtk_text_view_new (void
);
Creates a new GtkTextView. If you don’t call gtk_text_view_set_buffer()
before using the text view, an empty default buffer will be created
for you. Get the buffer with gtk_text_view_get_buffer()
. If you want
to specify your own buffer, consider gtk_text_view_new_with_buffer()
.
gtk_text_view_new_with_buffer ()
GtkWidget *
gtk_text_view_new_with_buffer (GtkTextBuffer *buffer
);
Creates a new GtkTextView 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.
gtk_text_view_set_buffer ()
void gtk_text_view_set_buffer (GtkTextView *text_view
,GtkTextBuffer *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; GtkTextView
will not “adopt” it.
gtk_text_view_get_buffer ()
GtkTextBuffer *
gtk_text_view_get_buffer (GtkTextView *text_view
);
Returns the GtkTextBuffer 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.
gtk_text_view_scroll_to_mark ()
void gtk_text_view_scroll_to_mark (GtkTextView *text_view
,GtkTextMark *mark
,double within_margin
,gboolean use_align
,double xalign
,double yalign
);
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 FALSE
, 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
.
gtk_text_view_scroll_to_iter ()
gboolean gtk_text_view_scroll_to_iter (GtkTextView *text_view
,GtkTextIter *iter
,double within_margin
,gboolean use_align
,double xalign
,double yalign
);
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 FALSE
, 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 that this function uses the currently-computed height of the
lines in the text buffer. 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.
gtk_text_view_scroll_mark_onscreen ()
void gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view
,GtkTextMark *mark
);
Scrolls text_view
the minimum distance such that mark
is contained
within the visible area of the widget.
gtk_text_view_move_mark_onscreen ()
gboolean gtk_text_view_move_mark_onscreen (GtkTextView *text_view
,GtkTextMark *mark
);
Moves a mark within the buffer so that it's located within the currently-visible text area.
gtk_text_view_place_cursor_onscreen ()
gboolean
gtk_text_view_place_cursor_onscreen (GtkTextView *text_view
);
Moves the cursor to the currently visible region of the buffer, if it isn’t there already.
gtk_text_view_get_visible_rect ()
void gtk_text_view_get_visible_rect (GtkTextView *text_view
,GdkRectangle *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()
.
gtk_text_view_get_iter_location ()
void gtk_text_view_get_iter_location (GtkTextView *text_view
,const GtkTextIter *iter
,GdkRectangle *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.
gtk_text_view_get_cursor_locations ()
void gtk_text_view_get_cursor_locations (GtkTextView *text_view
,const GtkTextIter *iter
,GdkRectangle *strong
,GdkRectangle *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. The position of each cursor is stored as a zero-width
rectangle. The strong cursor location is the location where
characters of the directionality equal to the base direction of the
paragraph are inserted. The weak cursor location is the location
where characters of the directionality opposite to the base
direction of the paragraph are inserted.
If iter
is NULL
, the actual cursor position is used.
Note that if iter
happens to be the actual cursor position, and
there is currently an IM preedit sequence being entered, the
returned locations will be adjusted to account for the preedit
cursor’s offset within the preedit sequence.
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.
Parameters
text_view |
||
iter |
a GtkTextIter. |
[allow-none] |
strong |
location to store the strong
cursor position (may be |
[out][allow-none] |
weak |
location to store the weak
cursor position (may be |
[out][allow-none] |
gtk_text_view_get_line_at_y ()
void gtk_text_view_get_line_at_y (GtkTextView *text_view
,GtkTextIter *target_iter
,int y
,int *line_top
);
Gets the GtkTextIter 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-NULL
, line_top
will be filled with the coordinate of the top
edge of the line.
Parameters
text_view |
||
target_iter |
a GtkTextIter. |
[out] |
y |
a y coordinate |
|
line_top |
return location for top coordinate of the line. |
[out] |
gtk_text_view_get_line_yrange ()
void gtk_text_view_get_line_yrange (GtkTextView *text_view
,const GtkTextIter *iter
,int *y
,int *height
);
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()
.
gtk_text_view_get_iter_at_location ()
gboolean gtk_text_view_get_iter_at_location (GtkTextView *text_view
,GtkTextIter *iter
,int x
,int 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_text_view_window_to_buffer_coords()
.
Parameters
text_view |
||
iter |
a GtkTextIter. |
[out] |
x |
x position, in buffer coordinates |
|
y |
y position, in buffer coordinates |
gtk_text_view_get_iter_at_position ()
gboolean gtk_text_view_get_iter_at_position (GtkTextView *text_view
,GtkTextIter *iter
,int *trailing
,int x
,int 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_text_view_window_to_buffer_coords()
.
Note that this is different from gtk_text_view_get_iter_at_location()
,
which returns cursor locations, i.e. positions between
characters.
Parameters
text_view |
||
iter |
a GtkTextIter. |
[out] |
trailing |
if non- |
[out][allow-none] |
x |
x position, in buffer coordinates |
|
y |
y position, in buffer coordinates |
gtk_text_view_buffer_to_window_coords ()
void gtk_text_view_buffer_to_window_coords (GtkTextView *text_view
,GtkTextWindowType win
,int buffer_x
,int buffer_y
,int *window_x
,int *window_y
);
Converts coordinate (buffer_x
, buffer_y
) to coordinates for the window
win
, and stores the result in (window_x
, window_y
).
gtk_text_view_window_to_buffer_coords ()
void gtk_text_view_window_to_buffer_coords (GtkTextView *text_view
,GtkTextWindowType win
,int window_x
,int window_y
,int *buffer_x
,int *buffer_y
);
Converts coordinates on the window identified by win
to buffer
coordinates, storing the result in (buffer_x
,buffer_y
).
gtk_text_view_forward_display_line ()
gboolean gtk_text_view_forward_display_line (GtkTextView *text_view
,GtkTextIter *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 GtkTextBuffer.
gtk_text_view_backward_display_line ()
gboolean gtk_text_view_backward_display_line (GtkTextView *text_view
,GtkTextIter *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 GtkTextBuffer.
gtk_text_view_forward_display_line_end ()
gboolean gtk_text_view_forward_display_line_end (GtkTextView *text_view
,GtkTextIter *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 GtkTextBuffer.
gtk_text_view_backward_display_line_start ()
gboolean gtk_text_view_backward_display_line_start (GtkTextView *text_view
,GtkTextIter *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 GtkTextBuffer.
gtk_text_view_starts_display_line ()
gboolean gtk_text_view_starts_display_line (GtkTextView *text_view
,const GtkTextIter *iter
);
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.
gtk_text_view_move_visually ()
gboolean gtk_text_view_move_visually (GtkTextView *text_view
,GtkTextIter *iter
,int count
);
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 bi-directional 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.
gtk_text_view_add_child_at_anchor ()
void gtk_text_view_add_child_at_anchor (GtkTextView *text_view
,GtkWidget *child
,GtkTextChildAnchor *anchor
);
Adds a child widget in the text buffer, at the given anchor
.
gtk_text_view_remove ()
void gtk_text_view_remove (GtkTextView *text_view
,GtkWidget *child
);
Removes a child widget from text_view
.
gtk_text_child_anchor_new ()
GtkTextChildAnchor *
gtk_text_child_anchor_new (void
);
Creates a new GtkTextChildAnchor. Usually you would then insert
it into a GtkTextBuffer 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()
.
gtk_text_child_anchor_get_widgets ()
GtkWidget ** gtk_text_child_anchor_get_widgets (GtkTextChildAnchor *anchor
,guint *out_len
);
Gets a list of all widgets anchored at this child anchor.
The order in which the widgets are returned is not defined.
gtk_text_child_anchor_get_deleted ()
gboolean
gtk_text_child_anchor_get_deleted (GtkTextChildAnchor *anchor
);
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.
gtk_text_view_get_gutter ()
GtkWidget * gtk_text_view_get_gutter (GtkTextView *text_view
,GtkTextWindowType win
);
Gets a GtkWidget that has previously been set with
gtk_text_view_set_gutter()
.
win
must be one of GTK_TEXT_WINDOW_LEFT
, GTK_TEXT_WINDOW_RIGHT
,
GTK_TEXT_WINDOW_TOP
, or GTK_TEXT_WINDOW_BOTTOM
.
gtk_text_view_set_gutter ()
void gtk_text_view_set_gutter (GtkTextView *text_view
,GtkTextWindowType win
,GtkWidget *widget
);
Places widget
into the gutter specified by win
.
win
must be one of GTK_TEXT_WINDOW_LEFT
, GTK_TEXT_WINDOW_RIGHT
,
GTK_TEXT_WINDOW_TOP
, or GTK_TEXT_WINDOW_BOTTOM
.
gtk_text_view_add_overlay ()
void gtk_text_view_add_overlay (GtkTextView *text_view
,GtkWidget *child
,int xpos
,int ypos
);
Adds child
at a fixed coordinate in the GtkTextView's text window. The
xpos
and ypos
must be in buffer coordinates (see
gtk_text_view_get_iter_location()
to convert to buffer coordinates).
child
will scroll with the text view.
If instead you want a widget that will not move with the GtkTextView contents see GtkOverlay.
gtk_text_view_move_overlay ()
void gtk_text_view_move_overlay (GtkTextView *text_view
,GtkWidget *child
,int xpos
,int ypos
);
Updates the position of a child, as for gtk_text_view_add_overlay()
.
Parameters
text_view |
||
child |
a widget already added with |
|
xpos |
new X position in buffer coordinates |
|
ypos |
new Y position in buffer coordinates |
gtk_text_view_set_wrap_mode ()
void gtk_text_view_set_wrap_mode (GtkTextView *text_view
,GtkWrapMode wrap_mode
);
Sets the line wrapping for the view.
gtk_text_view_get_wrap_mode ()
GtkWrapMode
gtk_text_view_get_wrap_mode (GtkTextView *text_view
);
Gets the line wrapping for the view.
gtk_text_view_set_editable ()
void gtk_text_view_set_editable (GtkTextView *text_view
,gboolean setting
);
Sets the default editability of the GtkTextView. You can override this default setting with tags in the buffer, using the “editable” attribute of tags.
gtk_text_view_get_editable ()
gboolean
gtk_text_view_get_editable (GtkTextView *text_view
);
Returns the default editability of the GtkTextView. Tags in the buffer may override this setting for some ranges of text.
gtk_text_view_set_cursor_visible ()
void gtk_text_view_set_cursor_visible (GtkTextView *text_view
,gboolean setting
);
Toggles whether the insertion point should be displayed. A buffer with no editable text probably shouldn’t have a visible cursor, so you may want to turn the cursor off.
Note that this property may be overridden by the “gtk-keynav-use-caret” settings.
gtk_text_view_get_cursor_visible ()
gboolean
gtk_text_view_get_cursor_visible (GtkTextView *text_view
);
Find out whether the cursor should be displayed.
gtk_text_view_reset_cursor_blink ()
void
gtk_text_view_reset_cursor_blink (GtkTextView *text_view
);
Ensures that the cursor is shown (i.e. not in an 'off' blink interval) and resets the time that it will stay blinking (or visible, in case blinking is disabled).
This function should be called in response to user input (e.g. from derived classes that override the textview's event handlers).
gtk_text_view_set_overwrite ()
void gtk_text_view_set_overwrite (GtkTextView *text_view
,gboolean overwrite
);
Changes the GtkTextView overwrite mode.
gtk_text_view_get_overwrite ()
gboolean
gtk_text_view_get_overwrite (GtkTextView *text_view
);
Returns whether the GtkTextView is in overwrite mode or not.
gtk_text_view_set_pixels_above_lines ()
void gtk_text_view_set_pixels_above_lines (GtkTextView *text_view
,int pixels_above_lines
);
Sets the default number of blank pixels above paragraphs in text_view
.
Tags in the buffer for text_view
may override the defaults.
gtk_text_view_get_pixels_above_lines ()
int
gtk_text_view_get_pixels_above_lines (GtkTextView *text_view
);
Gets the default number of pixels to put above paragraphs.
Adding this function with gtk_text_view_get_pixels_below_lines()
is equal to the line space between each paragraph.
gtk_text_view_set_pixels_below_lines ()
void gtk_text_view_set_pixels_below_lines (GtkTextView *text_view
,int pixels_below_lines
);
Sets the default number of pixels of blank space
to put below paragraphs in text_view
. May be overridden
by tags applied to text_view
’s buffer.
gtk_text_view_get_pixels_below_lines ()
int
gtk_text_view_get_pixels_below_lines (GtkTextView *text_view
);
Gets the value set by gtk_text_view_set_pixels_below_lines()
.
The line space is the sum of the value returned by this function and the
value returned by gtk_text_view_get_pixels_above_lines()
.
gtk_text_view_set_pixels_inside_wrap ()
void gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view
,int 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 text_view
’s buffer.
gtk_text_view_get_pixels_inside_wrap ()
int
gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view
);
Gets the value set by gtk_text_view_set_pixels_inside_wrap()
.
gtk_text_view_set_justification ()
void gtk_text_view_set_justification (GtkTextView *text_view
,GtkJustification justification
);
Sets the default justification of text in text_view
.
Tags in the view’s buffer may override the default.
gtk_text_view_get_justification ()
GtkJustification
gtk_text_view_get_justification (GtkTextView *text_view
);
Gets the default justification of paragraphs in text_view
.
Tags in the buffer may override the default.
gtk_text_view_set_left_margin ()
void gtk_text_view_set_left_margin (GtkTextView *text_view
,int left_margin
);
Sets the default left margin for text in text_view
.
Tags in the buffer may override the default.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
gtk_text_view_get_left_margin ()
int
gtk_text_view_get_left_margin (GtkTextView *text_view
);
Gets the default left margin size of paragraphs in the text_view
.
Tags in the buffer may override the default.
gtk_text_view_set_right_margin ()
void gtk_text_view_set_right_margin (GtkTextView *text_view
,int right_margin
);
Sets the default right margin for text in the text view. Tags in the buffer may override the default.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
gtk_text_view_get_right_margin ()
int
gtk_text_view_get_right_margin (GtkTextView *text_view
);
Gets the default right margin for text in text_view
. Tags
in the buffer may override the default.
gtk_text_view_set_top_margin ()
void gtk_text_view_set_top_margin (GtkTextView *text_view
,int top_margin
);
Sets the top margin for text in text_view
.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
gtk_text_view_get_top_margin ()
int
gtk_text_view_get_top_margin (GtkTextView *text_view
);
Gets the top margin for text in the text_view
.
gtk_text_view_set_bottom_margin ()
void gtk_text_view_set_bottom_margin (GtkTextView *text_view
,int bottom_margin
);
Sets the bottom margin for text in text_view
.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
gtk_text_view_get_bottom_margin ()
int
gtk_text_view_get_bottom_margin (GtkTextView *text_view
);
Gets the bottom margin for text in the text_view
.
gtk_text_view_set_indent ()
void gtk_text_view_set_indent (GtkTextView *text_view
,int indent
);
Sets the default indentation for paragraphs in text_view
.
Tags in the buffer may override the default.
gtk_text_view_get_indent ()
int
gtk_text_view_get_indent (GtkTextView *text_view
);
Gets the default indentation of paragraphs in text_view
.
Tags in the view’s buffer may override the default.
The indentation may be negative.
gtk_text_view_set_tabs ()
void gtk_text_view_set_tabs (GtkTextView *text_view
,PangoTabArray *tabs
);
Sets the default tab stops for paragraphs in text_view
.
Tags in the buffer may override the default.
gtk_text_view_get_tabs ()
PangoTabArray *
gtk_text_view_get_tabs (GtkTextView *text_view
);
Gets the default tabs for text_view
. Tags in the buffer may
override the defaults. The returned array will be NULL
if
“standard” (8-space) tabs are used. Free the return value
with pango_tab_array_free()
.
Returns
copy of default tab array, or NULL
if
“standard" tabs are used; must be freed with pango_tab_array_free()
.
[nullable][transfer full]
gtk_text_view_set_accepts_tab ()
void gtk_text_view_set_accepts_tab (GtkTextView *text_view
,gboolean 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.
gtk_text_view_get_accepts_tab ()
gboolean
gtk_text_view_get_accepts_tab (GtkTextView *text_view
);
Returns whether pressing the Tab key inserts a tab characters.
gtk_text_view_set_accepts_tab()
.
gtk_text_view_im_context_filter_keypress ()
gboolean gtk_text_view_im_context_filter_keypress (GtkTextView *text_view
,GdkEvent *event
);
Allow the GtkTextView input method to internally handle key press
and release events. If this function returns TRUE
, then no further
processing should be done for this key event. See
gtk_im_context_filter_keypress()
.
Note that you are expected to call this function from your handler when overriding key event handling. This is needed in the case when you need to insert your own key handling between the input method and the default key event handling of the GtkTextView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
static gboolean gtk_foo_bar_key_press_event (GtkWidget *widget, GdkEvent *event) { guint keyval; gdk_event_get_keyval ((GdkEvent*)event, &keyval); if (keyval == GDK_KEY_Return || keyval == GDK_KEY_KP_Enter) { if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (widget), event)) return TRUE; } // Do some stuff return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event); } |
gtk_text_view_reset_im_context ()
void
gtk_text_view_reset_im_context (GtkTextView *text_view
);
Reset the input method context of the text view if needed.
This can be necessary in the case where modifying the buffer would confuse on-going input method behavior.
gtk_text_view_set_input_purpose ()
void gtk_text_view_set_input_purpose (GtkTextView *text_view
,GtkInputPurpose purpose
);
Sets the “input-purpose” property which can be used by on-screen keyboards and other input methods to adjust their behaviour.
gtk_text_view_get_input_purpose ()
GtkInputPurpose
gtk_text_view_get_input_purpose (GtkTextView *text_view
);
Gets the value of the “input-purpose” property.
gtk_text_view_set_input_hints ()
void gtk_text_view_set_input_hints (GtkTextView *text_view
,GtkInputHints hints
);
Sets the “input-hints” property, which allows input methods to fine-tune their behaviour.
gtk_text_view_get_input_hints ()
GtkInputHints
gtk_text_view_get_input_hints (GtkTextView *text_view
);
Gets the value of the “input-hints” property.
gtk_text_view_set_monospace ()
void gtk_text_view_set_monospace (GtkTextView *text_view
,gboolean monospace
);
Sets the “monospace” property, which indicates that the text view should use monospace fonts.
gtk_text_view_get_monospace ()
gboolean
gtk_text_view_get_monospace (GtkTextView *text_view
);
Gets the value of the “monospace” property.
Return: TRUE
if monospace fonts are desired
gtk_text_view_set_extra_menu ()
void gtk_text_view_set_extra_menu (GtkTextView *text_view
,GMenuModel *model
);
Sets a menu model to add when constructing
the context menu for text_view
. You can pass
NULL
to remove a previously set extra menu.
gtk_text_view_get_extra_menu ()
GMenuModel *
gtk_text_view_get_extra_menu (GtkTextView *text_view
);
Gets the menu model set with gtk_text_view_set_extra_menu()
or NULL
if none has been set.
Types and Values
struct GtkTextViewClass
struct GtkTextViewClass { GtkWidgetClass parent_class; void (* move_cursor) (GtkTextView *text_view, GtkMovementStep step, int count, gboolean extend_selection); void (* set_anchor) (GtkTextView *text_view); void (* insert_at_cursor) (GtkTextView *text_view, const char *str); void (* delete_from_cursor) (GtkTextView *text_view, GtkDeleteType type, int count); void (* backspace) (GtkTextView *text_view); void (* cut_clipboard) (GtkTextView *text_view); void (* copy_clipboard) (GtkTextView *text_view); void (* paste_clipboard) (GtkTextView *text_view); void (* toggle_overwrite) (GtkTextView *text_view); GtkTextBuffer * (* create_buffer) (GtkTextView *text_view); void (* snapshot_layer) (GtkTextView *text_view, GtkTextViewLayer layer, GtkSnapshot *snapshot); gboolean (* extend_selection) (GtkTextView *text_view, GtkTextExtendSelection granularity, const GtkTextIter *location, GtkTextIter *start, GtkTextIter *end); void (* insert_emoji) (GtkTextView *text_view); };
Members
The class handler for the “move-cursor” keybinding signal. |
||
The class handler for the “set-anchor” keybinding signal. |
||
The class handler for the “insert-at-cursor” keybinding signal. |
||
The class handler for the “delete-from-cursor” keybinding signal. |
||
The class handler for the “backspace” keybinding signal. |
||
The class handler for the “cut-clipboard” keybinding signal |
||
The class handler for the “copy-clipboard” keybinding signal. |
||
The class handler for the “paste-clipboard” keybinding signal. |
||
The class handler for the “toggle-overwrite” keybinding signal. |
||
The create_buffer vfunc is called to create a GtkTextBuffer
for the text view. The default implementation is to just call
|
||
The snapshot_layer vfunc is called before and after the text
view is drawing its own text. Applications can override this vfunc
in a subclass to draw customized content underneath or above the
text. In the |
||
The class handler for the “extend-selection” signal. |
||
The class handler for the “insert-emoji” signal. |
enum GtkTextViewLayer
Used to reference the layers of GtkTextView for the purpose of customized drawing with the ::snapshot_layer vfunc.
enum GtkTextExtendSelection
Granularity types that extend the text selection. Use the “extend-selection” signal to customize the selection.
enum GtkWrapMode
Describes a type of line wrapping.
Members
do not wrap lines; just make the text area wider |
||
wrap text, breaking lines anywhere the cursor can
appear (between characters, usually - if you want to be technical,
between graphemes, see |
||
wrap text, breaking lines in between words |
||
wrap text, breaking lines in between words, or if that is not enough, also between graphemes |
struct GtkTextChildAnchor
struct GtkTextChildAnchor;
A GtkTextChildAnchor is a spot in the buffer where child widgets can be “anchored” (inserted inline, as if they were characters). The anchor can have multiple widgets anchored, to allow for multiple views.
Property Details
The “accepts-tab”
property
“accepts-tab” gboolean
Whether Tab will result in a tab character being entered.
Owner: GtkTextView
Flags: Read / Write
Default value: TRUE
The “bottom-margin”
property
“bottom-margin” int
The bottom margin for text in the text view.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don't confuse this property with “margin-bottom”.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “buffer”
property
“buffer” GtkTextBuffer *
The buffer which is displayed.
Owner: GtkTextView
Flags: Read / Write
The “cursor-visible”
property
“cursor-visible” gboolean
If the insertion cursor is shown.
Owner: GtkTextView
Flags: Read / Write
Default value: TRUE
The “editable”
property
“editable” gboolean
Whether the text can be modified by the user.
Owner: GtkTextView
Flags: Read / Write
Default value: TRUE
The “extra-menu”
property
“extra-menu” GMenuModel *
Menu model to append to the context menu.
Owner: GtkTextView
Flags: Read / Write
The “im-module”
property
“im-module” char *
Which IM (input method) module should be used for this text_view. See GtkIMContext.
Setting this to a non-NULL
value overrides the
system-wide IM module setting. See the GtkSettings
“gtk-im-module” property.
Owner: GtkTextView
Flags: Read / Write
Default value: NULL
The “indent”
property
“indent” int
Amount to indent the paragraph, in pixels.
Owner: GtkTextView
Flags: Read / Write
Default value: 0
The “input-hints”
property
“input-hints” GtkInputHints
Additional hints (beyond “input-purpose”) that allow input methods to fine-tune their behaviour.
Owner: GtkTextView
Flags: Read / Write
The “input-purpose”
property
“input-purpose” GtkInputPurpose
The purpose of this text field.
This property can be used by on-screen keyboards and other input methods to adjust their behaviour.
Owner: GtkTextView
Flags: Read / Write
Default value: GTK_INPUT_PURPOSE_FREE_FORM
The “justification”
property
“justification” GtkJustification
Left, right, or center justification.
Owner: GtkTextView
Flags: Read / Write
Default value: GTK_JUSTIFY_LEFT
The “left-margin”
property
“left-margin” int
The default left margin for text in the text view. Tags in the buffer may override the default.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “monospace”
property
“monospace” gboolean
If TRUE
, set the .monospace style class on the
text view to indicate that a monospace font is desired.
Owner: GtkTextView
Flags: Read / Write
Default value: FALSE
The “overwrite”
property
“overwrite” gboolean
Whether entered text overwrites existing contents.
Owner: GtkTextView
Flags: Read / Write
Default value: FALSE
The “pixels-above-lines”
property
“pixels-above-lines” int
Pixels of blank space above paragraphs.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “pixels-below-lines”
property
“pixels-below-lines” int
Pixels of blank space below paragraphs.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “pixels-inside-wrap”
property
“pixels-inside-wrap” int
Pixels of blank space between wrapped lines in a paragraph.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “right-margin”
property
“right-margin” int
The default right margin for text in the text view. Tags in the buffer may override the default.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “tabs”
property
“tabs” PangoTabArray *
Custom tabs for this text.
Owner: GtkTextView
Flags: Read / Write
The “top-margin”
property
“top-margin” int
The top margin for text in the text view.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don't confuse this property with “margin-top”.
Owner: GtkTextView
Flags: Read / Write
Allowed values: >= 0
Default value: 0
The “wrap-mode”
property
“wrap-mode” GtkWrapMode
Whether to wrap lines never, at word boundaries, or at character boundaries.
Owner: GtkTextView
Flags: Read / Write
Default value: GTK_WRAP_NONE
Signal Details
The “backspace”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::backspace signal is a keybinding signal which gets emitted when the user asks for it.
The default bindings for this signal are Backspace and Shift-Backspace.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “copy-clipboard”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
The default bindings for this signal are Ctrl-c and Ctrl-Insert.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “cut-clipboard”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
The default bindings for this signal are Ctrl-x and Shift-Delete.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “delete-from-cursor”
signal
void user_function (GtkTextView *text_view, GtkDeleteType type, int count, gpointer user_data)
The ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
If the type
is GTK_DELETE_CHARS
, GTK+ deletes the selection
if there is one, otherwise it deletes the requested number
of characters.
The default bindings for this signal are Delete for deleting a character, Ctrl-Delete for deleting a word and Ctrl-Backspace for deleting a word backwards.
Parameters
text_view |
the object which received the signal |
|
type |
the granularity of the deletion, as a GtkDeleteType |
|
count |
the number of |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “extend-selection”
signal
gboolean user_function (GtkTextView *text_view, GtkTextExtendSelection granularity, GtkTextIter *location, GtkTextIter *start, GtkTextIter *end, gpointer user_data)
The ::extend-selection signal is emitted when the selection needs to be
extended at location
.
Parameters
text_view |
the object which received the signal |
|
granularity |
the granularity type |
|
location |
the location where to extend the selection |
|
start |
where the selection should start |
|
end |
where the selection should end |
|
user_data |
user data set when the signal handler was connected. |
Returns
GDK_EVENT_STOP
to stop other handlers from being invoked for the
event. GDK_EVENT_PROPAGATE
to propagate the event further.
Flags: Run Last
The “insert-at-cursor”
signal
void user_function (GtkTextView *text_view, char *string, gpointer user_data)
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.
This signal has no default bindings.
Parameters
text_view |
the object which received the signal |
|
string |
the string to insert |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “insert-emoji”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::insert-emoji signal is a
keybinding signal
which gets emitted to present the Emoji chooser for the text_view
.
The default bindings for this signal are Ctrl-. and Ctrl-;
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “move-cursor”
signal
void user_function (GtkTextView *text_view, GtkMovementStep step, int count, gboolean extend_selection, gpointer user_data)
The ::move-cursor signal is a
keybinding signal
which gets emitted when the user initiates a cursor movement.
If the cursor is not visible in text_view
, this signal causes
the viewport to be moved instead.
Applications should not connect to it, but may emit it with
g_signal_emit_by_name()
if they need to control the cursor
programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.
Arrow keys move by individual characters/lines
Ctrl-arrow key combinations move by words/paragraphs
Home/End keys move to the ends of the buffer
PageUp/PageDown keys move vertically by pages
Ctrl-PageUp/PageDown keys move horizontally by pages
Parameters
text_view |
the object which received the signal |
|
step |
the granularity of the move, as a GtkMovementStep |
|
count |
the number of |
|
extend_selection |
|
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “move-viewport”
signal
void user_function (GtkTextView *text_view, GtkScrollStep step, int count, gpointer user_data)
The ::move-viewport signal is a keybinding signal which can be bound to key combinations to allow the user to move the viewport, i.e. change what part of the text view is visible in a containing scrolled window.
There are no default bindings for this signal.
Parameters
text_view |
the object which received the signal |
|
step |
the granularity of the movement, as a GtkScrollStep |
|
count |
the number of |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “paste-clipboard”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
The default bindings for this signal are Ctrl-v and Shift-Insert.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “preedit-changed”
signal
void user_function (GtkTextView *text_view, char *preedit, gpointer user_data)
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.
Parameters
text_view |
the object which received the signal |
|
preedit |
the current preedit string |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “select-all”
signal
void user_function (GtkTextView *text_view, gboolean select, gpointer user_data)
The ::select-all signal is a keybinding signal which gets emitted to select or unselect the complete contents of the text view.
The default bindings for this signal are Ctrl-a and Ctrl-/ for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
Parameters
text_view |
the object which received the signal |
|
select |
|
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “set-anchor”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::set-anchor signal is a keybinding signal which gets emitted when the user initiates setting the "anchor" mark. The "anchor" mark gets placed at the same position as the "insert" mark.
This signal has no default bindings.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “toggle-cursor-visible”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::toggle-cursor-visible signal is a keybinding signal which gets emitted to toggle the “cursor-visible” property.
The default binding for this signal is F7.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action
The “toggle-overwrite”
signal
void user_function (GtkTextView *text_view, gpointer user_data)
The ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the text view.
The default bindings for this signal is Insert.
Parameters
text_view |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action