Class TextView

All Implemented Interfaces:
Accessible, AccessibleText, Buildable, ConstraintTarget, Scrollable, Proxy
Direct Known Subclasses:
View

@Generated("org.javagi.JavaGI") public class TextView extends Widget implements Accessible, AccessibleText, Buildable, ConstraintTarget, Scrollable

Displays the contents of a TextBuffer.

An example GtkTextView

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

Shortcuts and Gestures

GtkTextView supports the following keyboard shortcuts:

  • Shift+F10 or Menu opens the context menu.
  • Ctrl+Z undoes the last modification.
  • Ctrl+Y or Ctrl+Shift+Z redoes the last undone modification.
  • Clear clears the content.

Additionally, the following signals have default keybindings:

  • Gtk.TextView::backspace
  • Gtk.TextView::copy-clipboard
  • Gtk.TextView::cut-clipboard
  • Gtk.TextView::delete-from-cursor
  • Gtk.TextView::insert-emoji
  • Gtk.TextView::move-cursor
  • Gtk.TextView::paste-clipboard
  • Gtk.TextView::select-all
  • Gtk.TextView::toggle-cursor-visible
  • Gtk.TextView::toggle-overwrite

Actions

GtkTextView defines a set of built-in actions:

  • clipboard.copy copies the contents to the clipboard.
  • clipboard.cut copies the contents to the clipboard and deletes it from the widget.
  • clipboard.paste inserts the contents of the clipboard into the widget.
  • menu.popup opens the context menu.
  • misc.insert-emoji opens the Emoji chooser.
  • selection.delete deletes the current selection.
  • selection.select-all selects all of the widgets content.
  • text.redo redoes the last change to the contents.
  • text.undo undoes the last change to the contents.
  • text.clear clears the content.

CSS nodes

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.

Accessibility

GtkTextView uses the Gtk.AccessibleRole.text_box role.

  • Constructor Details

    • TextView

      public TextView(MemorySegment address)
      Create a TextView instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • TextView

      public TextView()
      Create a new TextView.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the TextView class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected TextView asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • withBuffer

      public static TextView withBuffer(TextBuffer 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 TextView(). The text view adds its own reference count to the buffer; it does not take over an existing reference.

      Parameters:
      buffer - a GtkTextBuffer
      Returns:
      a new GtkTextView.
    • addChildAtAnchor

      public void addChildAtAnchor(Widget child, TextChildAnchor anchor)
      Adds a child widget in the text buffer, at the given anchor.
      Parameters:
      child - a GtkWidget
      anchor - a GtkTextChildAnchor in the GtkTextBuffer for this TextView
    • addOverlay

      public void addOverlay(Widget 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 getIterLocation(TextIter, Rectangle) 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.

      Parameters:
      child - a GtkWidget
      xpos - X position of child in window coordinates
      ypos - Y position of child in window coordinates
    • backwardDisplayLine

      public boolean backwardDisplayLine(TextIter 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.

      Parameters:
      iter - a GtkTextIter
      Returns:
      true if iter was moved and is not on the end iterator
    • backwardDisplayLineStart

      public boolean backwardDisplayLineStart(TextIter 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.

      Parameters:
      iter - a GtkTextIter
      Returns:
      true if iter was moved and is not on the end iterator
    • bufferToWindowCoords

      public void bufferToWindowCoords(TextWindowType win, int bufferX, int bufferY, @Nullable Out<Integer> windowX, @Nullable Out<Integer> windowY)
      Converts buffer coordinates to window coordinates.
      Parameters:
      win - a GtkTextWindowType
      bufferX - buffer x coordinate
      bufferY - buffer y coordinate
      windowX - window x coordinate return location
      windowY - window y coordinate return location
    • forwardDisplayLine

      public boolean forwardDisplayLine(TextIter 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.

      Parameters:
      iter - a GtkTextIter
      Returns:
      true if iter was moved and is not on the end iterator
    • forwardDisplayLineEnd

      public boolean forwardDisplayLineEnd(TextIter 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.

      Parameters:
      iter - a GtkTextIter
      Returns:
      true if iter was moved and is not on the end iterator
    • getAcceptsTab

      public boolean getAcceptsTab()

      Returns whether pressing the Tab key inserts a tab characters.

      See setAcceptsTab(boolean).

      Returns:
      true if pressing the Tab key inserts a tab character, false if pressing the Tab key moves the keyboard focus.
    • getBottomMargin

      public int getBottomMargin()
      Gets the bottom margin for text in the textView.
      Returns:
      bottom margin in pixels
    • getBuffer

      public TextBuffer getBuffer()

      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.

      Returns:
      a GtkTextBuffer
    • getCursorLocations

      public void getCursorLocations(@Nullable TextIter iter, @Nullable Rectangle strong, @Nullable Rectangle weak)

      Determine the positions of the strong and weak cursors if the insertion point is at iter.

      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 bufferToWindowCoords(TextWindowType, int, int, Out, Out) to convert these coordinates to coordinates for one of the windows in the text view.

      Parameters:
      iter - a GtkTextIter
      strong - location to store the strong cursor position
      weak - location to store the weak cursor position
    • getCursorVisible

      public boolean getCursorVisible()
      Find out whether the cursor should be displayed.
      Returns:
      whether the insertion mark is visible
    • getEditable

      public boolean getEditable()

      Returns the default editability of the GtkTextView.

      Tags in the buffer may override this setting for some ranges of text.

      Returns:
      whether text is editable by default
    • getExtraMenu

      public @Nullable MenuModel getExtraMenu()
      Gets the menu model that gets added to the context menu or null if none has been set.
      Returns:
      the menu model
    • getGutter

      public @Nullable Widget getGutter(TextWindowType win)

      Gets a GtkWidget that has previously been set as gutter.

      See setGutter(TextWindowType, Widget).

      win must be one of TextWindowType.LEFT, TextWindowType.RIGHT, TextWindowType.TOP, or TextWindowType.BOTTOM.

      Parameters:
      win - a GtkTextWindowType
      Returns:
      a GtkWidget
    • getIndent

      public int getIndent()

      Gets the default indentation of paragraphs in textView.

      Tags in the view’s buffer may override the default. The indentation may be negative.

      Returns:
      number of pixels of indentation
    • getInputHints

      public Set<InputHints> getInputHints()
      Gets the input-hints of the GtkTextView.
      Returns:
      the input hints
    • getInputPurpose

      public InputPurpose getInputPurpose()
      Gets the input-purpose of the GtkTextView.
      Returns:
      the input purpose
    • getIterAtLocation

      public boolean getIterAtLocation(TextIter 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 windowToBufferCoords(TextWindowType, int, int, Out, Out).

      Parameters:
      iter - a GtkTextIter
      x - x position, in buffer coordinates
      y - y position, in buffer coordinates
      Returns:
      true if the position is over text
    • getIterAtPosition

      public boolean getIterAtPosition(TextIter iter, @Nullable Out<Integer> 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 windowToBufferCoords(TextWindowType, int, int, Out, Out).

      Note that this is different from getIterAtLocation(TextIter, int, int), which returns cursor locations, i.e. positions between characters.

      Parameters:
      iter - a GtkTextIter
      trailing - if non-null, location to store an integer indicating where in the grapheme the user clicked. It will either be zero, or the number of characters in the grapheme. 0 represents the trailing edge of the grapheme.
      x - x position, in buffer coordinates
      y - y position, in buffer coordinates
      Returns:
      true if the position is over text
    • getIterLocation

      public void getIterLocation(TextIter iter, Rectangle location)

      Gets a rectangle which roughly contains the character at iter.

      The rectangle position is in buffer coordinates; use bufferToWindowCoords(TextWindowType, int, int, Out, Out) to convert these coordinates to coordinates for one of the windows in the text view.

      Parameters:
      iter - a GtkTextIter
      location - bounds of the character at iter
    • getJustification

      public Justification getJustification()

      Gets the default justification of paragraphs in textView.

      Tags in the buffer may override the default.

      Returns:
      default justification
    • getLeftMargin

      public int getLeftMargin()

      Gets the default left margin size of paragraphs in the textView.

      Tags in the buffer may override the default.

      Returns:
      left margin in pixels
    • getLineAtY

      public void getLineAtY(TextIter targetIter, int y, Out<Integer> lineTop)

      Gets the GtkTextIter at the start of the line containing the coordinate y.

      y is in buffer coordinates, convert from window coordinates with windowToBufferCoords(TextWindowType, int, int, Out, Out). If non-null, lineTop will be filled with the coordinate of the top edge of the line.

      Parameters:
      targetIter - a GtkTextIter
      y - a y coordinate
      lineTop - return location for top coordinate of the line
    • getLineYrange

      public void getLineYrange(TextIter iter, Out<Integer> y, Out<Integer> 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 bufferToWindowCoords(TextWindowType, int, int, Out, Out).

      Parameters:
      iter - a GtkTextIter
      y - return location for a y coordinate
      height - return location for a height
    • getLtrContext

      public Context getLtrContext()

      Gets the PangoContext that is used for rendering LTR directed text layouts.

      The context may be replaced when CSS changes occur.

      Returns:
      a PangoContext
      Since:
      4.4
    • getMonospace

      public boolean getMonospace()
      Gets whether the GtkTextView uses monospace styling.
      Returns:
      true if monospace fonts are desired
    • getOverwrite

      public boolean getOverwrite()
      Returns whether the GtkTextView is in overwrite mode or not.
      Returns:
      whether this TextView is in overwrite mode or not.
    • getPixelsAboveLines

      public int getPixelsAboveLines()

      Gets the default number of pixels to put above paragraphs.

      Adding this function with getPixelsBelowLines() is equal to the line space between each paragraph.

      Returns:
      default number of pixels above paragraphs
    • getPixelsBelowLines

      public int getPixelsBelowLines()

      Gets the default number of pixels to put below paragraphs.

      The line space is the sum of the value returned by this function and the value returned by getPixelsAboveLines().

      Returns:
      default number of blank pixels below paragraphs
    • getPixelsInsideWrap

      public int getPixelsInsideWrap()
      Gets the default number of pixels to put between wrapped lines inside a paragraph.
      Returns:
      default number of pixels of blank space between wrapped lines
    • getRightMargin

      public int getRightMargin()

      Gets the default right margin for text in textView.

      Tags in the buffer may override the default.

      Returns:
      right margin in pixels
    • getRtlContext

      public Context getRtlContext()

      Gets the PangoContext that is used for rendering RTL directed text layouts.

      The context may be replaced when CSS changes occur.

      Returns:
      a PangoContext
      Since:
      4.4
    • getTabs

      public @Nullable TabArray getTabs()

      Gets the default tabs for textView.

      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 TabArray#free.

      Returns:
      copy of default tab array, or null if standard tabs are used; must be freed with TabArray#free.
    • getTopMargin

      public int getTopMargin()
      Gets the top margin for text in the textView.
      Returns:
      top margin in pixels
    • getVisibleOffset

      public void getVisibleOffset(@Nullable Out<Double> xOffset, @Nullable Out<Double> yOffset)

      Gets the X,Y offset in buffer coordinates of the top-left corner of the textview's text contents.

      This allows for more-precise positioning than what is provided by getVisibleRect(Rectangle) as you can discover what device pixel is being quantized for text positioning.

      You might want this when making ulterior widgets align with quantized device pixels of the textview contents such as line numbers.

      Parameters:
      xOffset - a location for the X offset
      yOffset - a location for the Y offset
      Since:
      4.18
    • getVisibleRect

      public void getVisibleRect(Rectangle visibleRect)

      Fills visibleRect with the currently-visible region of the buffer, in buffer coordinates.

      Convert to window coordinates with bufferToWindowCoords(TextWindowType, int, int, Out, Out).

      Parameters:
      visibleRect - rectangle to fill
    • getWrapMode

      public WrapMode getWrapMode()
      Gets the line wrapping for the view.
      Returns:
      the line wrap setting
    • imContextFilterKeypress

      public boolean imContextFilterKeypress(Event 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 IMContext.filterKeypress(Event).

      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.

      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);
      }
      
      Parameters:
      event - the key event
      Returns:
      true if the input method handled the key event.
    • moveMarkOnscreen

      public boolean moveMarkOnscreen(TextMark mark)
      Moves a mark within the buffer so that it's located within the currently-visible text area.
      Parameters:
      mark - a GtkTextMark
      Returns:
      true if the mark moved (wasn’t already onscreen)
    • moveOverlay

      public void moveOverlay(Widget child, int xpos, int ypos)

      Updates the position of a child.

      See addOverlay(Widget, int, int).

      Parameters:
      child - a widget already added with addOverlay(Widget, int, int)
      xpos - new X position in buffer coordinates
      ypos - new Y position in buffer coordinates
    • moveVisually

      public boolean moveVisually(TextIter 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.

      Parameters:
      iter - a GtkTextIter
      count - number of characters to move (negative moves left, positive moves right)
      Returns:
      true if iter moved and is not on the end iterator
    • placeCursorOnscreen

      public boolean placeCursorOnscreen()
      Moves the cursor to the currently visible region of the buffer.
      Returns:
      true if the cursor had to be moved.
    • remove

      public void remove(Widget child)
      Removes a child widget from textView.
      Parameters:
      child - the child to remove
    • resetCursorBlink

      public void resetCursorBlink()

      Ensures that the cursor is shown.

      This also 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).

    • resetImContext

      public void resetImContext()

      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.

    • scrollMarkOnscreen

      public void scrollMarkOnscreen(TextMark mark)
      Scrolls this TextView the minimum distance such that mark is contained within the visible area of the widget.
      Parameters:
      mark - a mark in the buffer for this TextView
    • scrollToIter

      public boolean scrollToIter(TextIter iter, double withinMargin, boolean useAlign, double xalign, double yalign)

      Scrolls this 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 useAlign 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 withinMargin.

      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 scrollToMark(TextMark, double, boolean, double, double) which saves a point to be scrolled to after line validation.

      Parameters:
      iter - a GtkTextIter
      withinMargin - margin as a [0.0,0.5) fraction of screen size
      useAlign - 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
    • scrollToMark

      public void scrollToMark(TextMark mark, double withinMargin, boolean useAlign, double xalign, double yalign)

      Scrolls this 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 useAlign 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 withinMargin.

      Parameters:
      mark - a GtkTextMark
      withinMargin - margin as a [0.0,0.5) fraction of screen size
      useAlign - 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
    • setAcceptsTab

      public void setAcceptsTab(boolean acceptsTab)

      Sets the behavior of the text widget when the Tab key is pressed.

      If acceptsTab is true, a tab character is inserted. If acceptsTab is false the keyboard focus is moved to the next widget in the focus chain.

      Focus can always be moved using Ctrl+Tab.

      Parameters:
      acceptsTab - true if pressing the Tab key should insert a tab character, false, if pressing the Tab key should move the keyboard focus.
    • setBottomMargin

      public void setBottomMargin(int bottomMargin)

      Sets the bottom margin for text in textView.

      Note that this function is confusingly named. In CSS terms, the value set here is padding.

      Parameters:
      bottomMargin - bottom margin in pixels
    • setBuffer

      public void setBuffer(@Nullable TextBuffer buffer)

      Sets buffer as the buffer being displayed by textView.

      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.

      Parameters:
      buffer - a GtkTextBuffer
    • setCursorVisible

      public void setCursorVisible(boolean 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.Settings:gtk-keynav-use-caret setting.

      Parameters:
      setting - whether to show the insertion cursor
    • setEditable

      public void setEditable(boolean 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.

      Parameters:
      setting - whether it’s editable
    • setExtraMenu

      public void setExtraMenu(@Nullable MenuModel model)

      Sets a menu model to add when constructing the context menu for textView.

      You can pass null to remove a previously set extra menu.

      Parameters:
      model - a GMenuModel
    • setGutter

      public void setGutter(TextWindowType win, @Nullable Widget widget)

      Places widget into the gutter specified by win.

      win must be one of TextWindowType.LEFT, TextWindowType.RIGHT, TextWindowType.TOP, or TextWindowType.BOTTOM.

      Parameters:
      win - a GtkTextWindowType
      widget - a GtkWidget
    • setIndent

      public void setIndent(int indent)

      Sets the default indentation for paragraphs in textView.

      Tags in the buffer may override the default.

      Parameters:
      indent - indentation in pixels
    • setInputHints

      public void setInputHints(Set<InputHints> hints)

      Sets the input-hints of the GtkTextView.

      The input-hints allow input methods to fine-tune their behaviour.

      Parameters:
      hints - the hints
    • setInputHints

      public void setInputHints(InputHints... hints)

      Sets the input-hints of the GtkTextView.

      The input-hints allow input methods to fine-tune their behaviour.

      Parameters:
      hints - the hints
    • setInputPurpose

      public void setInputPurpose(InputPurpose purpose)

      Sets the input-purpose of the GtkTextView.

      The input-purpose can be used by on-screen keyboards and other input methods to adjust their behaviour.

      Parameters:
      purpose - the purpose
    • setJustification

      public void setJustification(Justification justification)

      Sets the default justification of text in textView.

      Tags in the view’s buffer may override the default.

      Parameters:
      justification - justification
    • setLeftMargin

      public void setLeftMargin(int leftMargin)

      Sets the default left margin for text in textView.

      Tags in the buffer may override the default.

      Note that this function is confusingly named. In CSS terms, the value set here is padding.

      Parameters:
      leftMargin - left margin in pixels
    • setMonospace

      public void setMonospace(boolean monospace)
      Sets whether the GtkTextView should display text in monospace styling.
      Parameters:
      monospace - true to request monospace styling
    • setOverwrite

      public void setOverwrite(boolean overwrite)
      Changes the GtkTextView overwrite mode.
      Parameters:
      overwrite - true to turn on overwrite mode, false to turn it off
    • setPixelsAboveLines

      public void setPixelsAboveLines(int pixelsAboveLines)

      Sets the default number of blank pixels above paragraphs in textView.

      Tags in the buffer for this TextView may override the defaults.

      Parameters:
      pixelsAboveLines - pixels above paragraphs
    • setPixelsBelowLines

      public void setPixelsBelowLines(int pixelsBelowLines)

      Sets the default number of pixels of blank space to put below paragraphs in textView.

      May be overridden by tags applied to textView’s buffer.

      Parameters:
      pixelsBelowLines - pixels below paragraphs
    • setPixelsInsideWrap

      public void setPixelsInsideWrap(int pixelsInsideWrap)

      Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph.

      May be overridden by tags in textView’s buffer.

      Parameters:
      pixelsInsideWrap - default number of pixels between wrapped lines
    • setRightMargin

      public void setRightMargin(int rightMargin)

      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.

      Parameters:
      rightMargin - right margin in pixels
    • setTabs

      public void setTabs(TabArray tabs)

      Sets the default tab stops for paragraphs in textView.

      Tags in the buffer may override the default.

      Parameters:
      tabs - tabs as a PangoTabArray
    • setTopMargin

      public void setTopMargin(int topMargin)

      Sets the top margin for text in textView.

      Note that this function is confusingly named. In CSS terms, the value set here is padding.

      Parameters:
      topMargin - top margin in pixels
    • setWrapMode

      public void setWrapMode(WrapMode wrapMode)
      Sets the line wrapping for the view.
      Parameters:
      wrapMode - a GtkWrapMode
    • startsDisplayLine

      public boolean startsDisplayLine(TextIter iter)

      Determines whether iter is at the start of a display line.

      See forwardDisplayLine(TextIter) for an explanation of display lines vs. paragraphs.

      Parameters:
      iter - a GtkTextIter
      Returns:
      true if iter begins a wrapped line
    • windowToBufferCoords

      public void windowToBufferCoords(TextWindowType win, int windowX, int windowY, @Nullable Out<Integer> bufferX, @Nullable Out<Integer> bufferY)
      Converts coordinates on the window identified by win to buffer coordinates.
      Parameters:
      win - a GtkTextWindowType
      windowX - window x coordinate
      windowY - window y coordinate
      bufferX - buffer x coordinate return location
      bufferY - buffer y coordinate return location
    • backspace

      protected void backspace()
      The class handler for the GtkTextView::backspace keybinding signal.
    • copyClipboard

      protected void copyClipboard()
      The class handler for the GtkTextView::copy-clipboard keybinding signal.
    • createBuffer

      protected TextBuffer createBuffer()
      The create_buffer vfunc is called to create a GtkTextBuffer for the text view. The default implementation is to just call gtk_text_buffer_new().
    • cutClipboard

      protected void cutClipboard()
      The class handler for the GtkTextView::cut-clipboard keybinding signal
    • deleteFromCursor

      protected void deleteFromCursor(DeleteType type, int count)
      The class handler for the GtkTextView::delete-from-cursor keybinding signal.
    • extendSelection

      protected boolean extendSelection(TextExtendSelection granularity, TextIter location, TextIter start, TextIter end)
      The class handler for the GtkTextView::extend-selection signal.
    • insertAtCursor

      protected void insertAtCursor(String str)
      The class handler for the GtkTextView::insert-at-cursor keybinding signal.
    • insertEmoji

      protected void insertEmoji()
      The class handler for the GtkTextView::insert-emoji signal.
    • moveCursor

      protected void moveCursor(MovementStep step, int count, boolean extendSelection)
      The class handler for the GtkTextView::move-cursor keybinding signal.
    • pasteClipboard

      protected void pasteClipboard()
      The class handler for the GtkTextView::paste-clipboard keybinding signal.
    • setAnchor

      protected void setAnchor()
      The class handler for the GtkTextView::set-anchor keybinding signal.
    • snapshotLayer

      protected void snapshotLayer(TextViewLayer layer, Snapshot snapshot)
      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 TextViewLayer.BELOW_TEXT and TextViewLayer.ABOVE_TEXT layers the drawing is done in the buffer coordinate space.
    • toggleOverwrite

      protected void toggleOverwrite()
      The class handler for the GtkTextView::toggle-overwrite keybinding signal.
    • onBackspace

      Gets emitted when the user asks for it.

      The ::backspace signal is a keybinding signal.

      The default bindings for this signal are Backspace and Shift+Backspace.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitBackspace

      public void emitBackspace()
      Emits the "backspace" signal. See onBackspace(TextView.BackspaceCallback).
    • onCopyClipboard

      Gets emitted to copy the selection to the clipboard.

      The ::copy-clipboard signal is a keybinding signal.

      The default bindings for this signal are Ctrl+c and Ctrl+Insert.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCopyClipboard

      public void emitCopyClipboard()
      Emits the "copy-clipboard" signal. See onCopyClipboard(TextView.CopyClipboardCallback).
    • onCutClipboard

      Gets emitted to cut the selection to the clipboard.

      The ::cut-clipboard signal is a keybinding signal.

      The default bindings for this signal are Ctrl+x and Shift+Delete.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCutClipboard

      public void emitCutClipboard()
      Emits the "cut-clipboard" signal. See onCutClipboard(TextView.CutClipboardCallback).
    • onDeleteFromCursor

      Gets emitted when the user initiates a text deletion.

      The ::delete-from-cursor signal is a keybinding signal.

      If the type is DeleteType.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:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDeleteFromCursor

      public void emitDeleteFromCursor(DeleteType type, int count)
      Emits the "delete-from-cursor" signal. See onDeleteFromCursor(TextView.DeleteFromCursorCallback).
    • onExtendSelection

      Emitted when the selection needs to be extended at location.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitExtendSelection

      public boolean emitExtendSelection(TextExtendSelection granularity, @Nullable TextIter location, @Nullable TextIter start, @Nullable TextIter end)
      Emits the "extend-selection" signal. See onExtendSelection(TextView.ExtendSelectionCallback).
    • onInsertAtCursor

      Gets emitted when the user initiates the insertion of a fixed string at the cursor.

      The ::insert-at-cursor signal is a keybinding signal.

      This signal has no default bindings.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsertAtCursor

      public void emitInsertAtCursor(String string)
      Emits the "insert-at-cursor" signal. See onInsertAtCursor(TextView.InsertAtCursorCallback).
    • onInsertEmoji

      Gets emitted to present the Emoji chooser for the textView.

      The ::insert-emoji signal is a keybinding signal.

      The default bindings for this signal are Ctrl+. and Ctrl+;

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsertEmoji

      public void emitInsertEmoji()
      Emits the "insert-emoji" signal. See onInsertEmoji(TextView.InsertEmojiCallback).
    • onMoveCursor

      Gets emitted when the user initiates a cursor movement.

      The ::move-cursor signal is a keybinding signal. If the cursor is not visible in textView, 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 it does not. There are too many key combinations to list them all here.

      • , , , move by individual characters/lines
      • Ctrl+, etc. move by words/paragraphs
      • Home and End move to the ends of the buffer
      • PgUp and PgDn move vertically by pages
      • Ctrl+PgUp and Ctrl+PgDn move horizontally by pages
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMoveCursor

      public void emitMoveCursor(MovementStep step, int count, boolean extendSelection)
      Emits the "move-cursor" signal. See onMoveCursor(TextView.MoveCursorCallback).
    • onMoveViewport

      Gets emitted to move the viewport.

      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:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMoveViewport

      public void emitMoveViewport(ScrollStep step, int count)
      Emits the "move-viewport" signal. See onMoveViewport(TextView.MoveViewportCallback).
    • onPasteClipboard

      Gets emitted to paste the contents of the clipboard into the text view.

      The ::paste-clipboard signal is a keybinding signal.

      The default bindings for this signal are Ctrl+v and Shift+Insert.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPasteClipboard

      public void emitPasteClipboard()
      Emits the "paste-clipboard" signal. See onPasteClipboard(TextView.PasteClipboardCallback).
    • onPreeditChanged

      Emitted when preedit text of the active IM changes.

      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:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPreeditChanged

      public void emitPreeditChanged(String preedit)
      Emits the "preedit-changed" signal. See onPreeditChanged(TextView.PreeditChangedCallback).
    • onSelectAll

      Gets emitted to select or unselect the complete contents of the text view.

      The ::select-all signal is a keybinding signal.

      The default bindings for this signal are Ctrl+a and Ctrl+/ for selecting and Shift+Ctrl+a and Ctrl+\ for unselecting.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSelectAll

      public void emitSelectAll(boolean select)
      Emits the "select-all" signal. See onSelectAll(TextView.SelectAllCallback).
    • onSetAnchor

      Gets emitted when the user initiates settings the "anchor" mark.

      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:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSetAnchor

      public void emitSetAnchor()
      Emits the "set-anchor" signal. See onSetAnchor(TextView.SetAnchorCallback).
    • onToggleCursorVisible

      Gets emitted to toggle the cursor-visible property.

      The ::toggle-cursor-visible signal is a keybinding signal.

      The default binding for this signal is F7.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitToggleCursorVisible

      public void emitToggleCursorVisible()
      Emits the "toggle-cursor-visible" signal. See onToggleCursorVisible(TextView.ToggleCursorVisibleCallback).
    • onToggleOverwrite

      Gets emitted to toggle the overwrite mode of the text view.

      The ::toggle-overwrite signal is a keybinding signal.

      The default binding for this signal is Insert.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitToggleOverwrite

      public void emitToggleOverwrite()
      Emits the "toggle-overwrite" signal. See onToggleOverwrite(TextView.ToggleOverwriteCallback).
    • builder

      public static TextView.Builder<? extends TextView.Builder> builder()
      A TextView.Builder object constructs a TextView with the specified properties. Use the various set...() methods to set properties, and finish construction with TextView.Builder.build().
      Returns:
      the builder object