Class Region

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Region extends GObject

Region utility.

A GtkSourceRegion permits to store a group of subregions of a TextBuffer. GtkSourceRegion stores the subregions with pairs of TextMark's, so the region is still valid after insertions and deletions in the TextBuffer.

The TextMark for the start of a subregion has a left gravity, while the TextMark for the end of a subregion has a right gravity.

The typical use-case of GtkSourceRegion is to scan a TextBuffer chunk by chunk, not the whole buffer at once to not block the user interface. The GtkSourceRegion represents in that case the remaining region to scan. You can listen to the Gtk.TextBuffer::insert-text and Gtk.TextBuffer::delete-range signals to update the GtkSourceRegion accordingly.

To iterate through the subregions, you need to use a RegionIter, for example:

GtkSourceRegion *region;
GtkSourceRegionIter region_iter;

gtk_source_region_get_start_region_iter (region, &region_iter);

while (!gtk_source_region_iter_is_end (&region_iter))
{
        GtkTextIter subregion_start;
        GtkTextIter subregion_end;

        if (!gtk_source_region_iter_get_subregion (&region_iter,
                                                   &subregion_start,
                                                   &subregion_end))
        {
                break;
        }

        // Do something useful with the subregion.

        gtk_source_region_iter_next (&region_iter);
}
buffer: GtkSource.Buffer = GtkSource.Buffer()
region: GtkSource.Region = GtkSource.Region(buffer=buffer)
region_iter = region.get_start_region_iter()

while not region_iter.is_end():
    success, start, end = region_iter.get_subregion()
    if not success:
        break

    # Do something useful with the subregion

    region_iter.next()
  • Constructor Details

    • Region

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

      public Region(TextBuffer buffer)
    • Region

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

    • getType

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

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

      protected Region 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 GObject
      Returns:
      the instance as if it were its parent type
    • addRegion

      public void addRegion(@Nullable Region regionToAdd)

      Adds regionToAdd to region.

      regionToAdd is not modified.

      Parameters:
      regionToAdd - the GtkSourceRegion to add to region, or null.
    • addSubregion

      public void addSubregion(TextIter _start, TextIter _end)
      Adds the subregion delimited by _start and _end to region.
      Parameters:
      _start - the start of the subregion.
      _end - the end of the subregion.
    • getBounds

      public boolean getBounds(@Nullable TextIter start, @Nullable TextIter end)
      Gets the start and end bounds of the region.
      Parameters:
      start - iterator to initialize with the start of region, or null.
      end - iterator to initialize with the end of region, or null.
      Returns:
      true if start and end have been set successfully (if non-null), or false if the this Region is empty.
    • getBuffer

      public @Nullable TextBuffer getBuffer()
    • getStartRegionIter

      public void getStartRegionIter(RegionIter iter)

      Initializes a RegionIter to the first subregion of region.

      If this Region is empty, iter will be initialized to the end iterator.

      Parameters:
      iter - iterator to initialize to the first subregion.
    • intersectRegion

      public @Nullable Region intersectRegion(@Nullable Region region2)

      Returns the intersection between this Region and region2.

      this Region and region2 are not modified.

      Parameters:
      region2 - a GtkSourceRegion, or null.
      Returns:
      the intersection as a GtkSourceRegion object.
    • intersectSubregion

      public @Nullable Region intersectSubregion(TextIter _start, TextIter _end)

      Returns the intersection between this Region and the subregion delimited by _start and _end.

      this Region is not modified.

      Parameters:
      _start - the start of the subregion.
      _end - the end of the subregion.
      Returns:
      the intersection as a new GtkSourceRegion.
    • isEmpty

      public boolean isEmpty()

      Returns whether the this Region is empty.

      A null this Region is considered empty.

      Returns:
      whether the this Region is empty.
    • subtractRegion

      public void subtractRegion(@Nullable Region regionToSubtract)

      Subtracts regionToSubtract from region.

      regionToSubtract is not modified.

      Parameters:
      regionToSubtract - the GtkSourceRegion to subtract from region, or null.
    • subtractSubregion

      public void subtractSubregion(TextIter _start, TextIter _end)
      Subtracts the subregion delimited by _start and _end from region.
      Parameters:
      _start - the start of the subregion.
      _end - the end of the subregion.
    • toString

      public @Nullable String toString()

      Gets a string represention of region, for debugging purposes.

      The returned string contains the character offsets of the subregions. It doesn't include a newline character at the end of the string.

      Overrides:
      toString in class Object
      Returns:
      a string represention of region. Free with g_free() when no longer needed.
    • builder

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