Contents

    Example:

Example:

(def-class
  (roos-doc (gtk-assoc "gtk-GtkTextIter")
            (sp "This class wraps GtkTextIter. gtk-text-iter's don't last long in general. Mostly they're only valid"
                "for one call to a function that uses gtk text iters. This is why two functions have been provided: "
                (s% 'with-constant-text-iter) " and " (s% 'with-constant-text-iter-range) ". These functions are called "
                "with one or two text iters and functions or a list of functions. Each function of the provided functions "
                "is called (a) with fresh made iter or iters (start end). Example")
            (sverb " (with-constant-text-iter iter (lambda (I) (-> (-> I buffer) text \"HI\")"
                   "                               (lambda (I) blabla))")
            (sverb " (with-constant-text-iter-range start end (list (lambda (s e) (-> buffer select s e))"
                   "                                                (lambda (s e) (-> buffer apply-tag t s e)))")
            (sp "A gtk text iter is always associated with a buffer.")
            (also)
            )
  (this (gtk-text-iter . args))
  (supers (mzgtk2-type (mzgtk2-text-iter-new)))
  ;;;;    private
  (private
   (define _buf #f)
   )
  ;;;;    public
  (public
   ((mzgtk2-twrap mzgtk2-wdoc) (offset      gtk-text-iter-set-offset       gtk-text-iter-get-offset) this)
   ((mzgtk2-twrap mzgtk2-wdoc) (line        gtk-text-iter-set-line         gtk-text-iter-get-line) this)
   ((mzgtk2-twrap mzgtk2-wdoc) (line-offset gtk-text-iter-set-line-offset  gtk-text-iter-get-line-offset) this)

   ((define (sp "returns #t, if " (s% "this iter") " is equal to " (s% "other-iter") ", #f otherwise."))
       (= other-iter)
         (numeric= (gtk-text-iter-compare this other-iter) 0))

   ((define (sp "returns #t, if " (s% "this iter") " is smaller than " (s% "other iter") ", #f otherwise."))
     (< other-iter)
       (numeric< (gtk-text-iter-compare this other-iter) 0))

   ((define (sp "returns #t, if " (s% "this iter") " is bigger than " (s% "other iter") ", #f otherwise."))
     (> other-iter)
       (numeric> (gtk-text-iter-compare this other-iter) 0))

   ((define (sp "returns #t, if " (s% "this iter") " is smaller than or equal to  " (s% "other iter") ", #f otherwise."))
     (<= other-iter)
       (numeric<= (gtk-text-iter-compare this other-iter) 0))

   ((define (sp "returns #t, if " (s% "this iter") " is bigger than or equal to  " (s% "other iter") ", #f otherwise."))
     (>= other-iter)
       (numeric>= (gtk-text-iter-compare this other-iter) 0))

   ((define (sp "returns #t, if " (s% "this iter") " represents the end of the text buffer it is associated with, #f otherwise."))
      (is-end?)
        (gtk-text-iter-is-end this))

   ((define (sp "returns #t, if " (s% "this iter") " represents the start of the text buffer it is associated with, #f otherwise."))
     (is-start?)
       (gtk-text-iter-is-start this))

   ((define (sp "returns the list of gtk-text-tags associated with the offset in the buffer, "(s% "this iter") " points to."))
     (tags) 
       (gtk-text-iter-get-tags this))

   ((define (sp "returns #t, if any tag toggles at the offset in the buffer, "(s% "this iter") " points to." 
                "Toggles means, is turned on or off."))
     (toggles-tag)
       (gtk-text-iter-toggles-tag this #f))
 
 
   ((define (sp "Forwards this iter with one character in the buffer; returns " (s% 'this)))
      (forward-char)
        (gtk-text-iter-forward-char this)
         this)
 
   ((define (sp "Forwards this iter with one character in the buffer; returns " (s% 'this)))
     (++)
       (gtk-text-iter-forward-char this)
       this)

   ((define (sp "Backwards this iter with one character in the buffer; returns " (s% 'this)))
     (backward-char)
       (gtk-text-iter-backward-char this)
       this)

   ((define (sp "Backwards this iter with one character in the buffer; returns " (s% 'this)))
     (--)
       (gtk-text-iter-backward-char this)
       this)

   ((define (sp "Copies " (s% 'this) " iter into a new iter. Returns the new iter."))
     (copy)
       (let ((i (gtk-text-iter 'buffer _buf 'offset (-> this offset))))
        i))

   ((define (sp "Calls func for each iter position from " (s% 'this) " until iter " (s% 'e) ". " (s% 'e) " must be a valid iter")
            (sp "func is called with " (s% 'this) ", the character offset in the buffer, represented by " (s% 'this) 
                " and the gtk-text-tags at " (s% 'this))
            (sp (s% 'this) " this is increased with one character at each call to func. Func must not invalidate " (s% 'this))
            (sp "return value is undefined."))
      (buffer-for-each e func)
        (do ((me (-> this get-cobj) (begin (gtk-text-iter-forward-char me) me))
             (end (-> e get-cobj)))
            ((numeric>= (gtk-text-iter-compare me end) 0) #t)
            (func this (gtk-text-iter-get-offset me) (gtk-text-iter-get-tags me))))

   ((define (sp "Calls func for each change in tags for iter position from " (s% 'this) " until iter " (s% 'e) ". " (s% 'e) " must be a valid iter")
            (sp "func is called with " (s% 'this) ", , the character offset in the buffer, represented by " (s% 'this)  
                ", the gtk-text-tags at " (s% 'this) ", and a status. "
                "this " (s% 'status) "is one of " (s% "'start") ", " (s% "'between") " and " (s% "'end"))
            (sitems 
             (s- (s% "'start") " is given as status, when func is called before the start of the iteration of func over all tags in the given range.")
             (s- (s% "'end") " is given, when func is called after the iteration has reached the end.")
             (s- (s% "'between") " is given, for all calls to func in between start and end."))
            (sp "The return value is undefined."))
    (buffer-for-all-tags e func)
        (let ((start-tags (gtk-text-iter-get-tags this))
              (end-tags   (gtk-text-iter-get-tags e)))
          (func this (-> this offset) start-tags 'start)
          (do ((me (-> this get-cobj) (begin (gtk-text-iter-forward-char me) me))
               (end (-> e get-cobj)))
              ((numeric>= (gtk-text-iter-compare me end) 0) #t)
              (if (gtk-text-iter-toggles-tag me #f)
                  (func this (gtk-text-iter-get-offset me) (gtk-text-iter-get-tags me) 'between)))
          (func e (-> e offset) end-tags 'end)))

   ((define (sp "Returns the gtk-text-buffer this iter is associated with."))
      (buffer) 
        _buf)
   )
   ;;;;    constructor
  ((constructor 
    (named-pars (par 'line      "Initializes this iter at the beginning of the given line number.")
                (par 'offset    "Initializes this iter at the given character offset.")
                (par 'buffer    "Associates this iter with the given " (s% 'gtk-text-buffer) ". This argument is mandatory.")
                (par 'position  "Positions this iter at the given position (" (s% "'start") " or " (s% "'end") ".")
                (par 'c-object  "Associates this ROOS Object with a given C variant of the text iter."))
    (sp "Line and offset can be combined to initialize the text iter at a given charactor offset in a given line."))
   (let ((_line   (=> 'line args #f))
         (_offset (=> 'offset args #f))
         (_buffer (=> 'buffer args #f))
         (_position (=> 'position args #f))
         (_c-object (=> 'c-object args #f)))

     (if (eq? _buffer #f)
         (error "gtk-text-iter must be initialized with a gtk-text-buffer")
         (begin
           (if (object? _buffer)
               (set! _buf _buffer)
               (set! _buf (gtk-text-buffer 'cwidget _buffer)))))

     (if (not (eq? _position #f))
         (if (eq? _position 'start)
             (gtk-text-buffer-get-start-iter _buf (-> this get-cobj))
             (gtk-text-buffer-get-end-iter _buf (-> this get-cobj)))
         (gtk-text-buffer-get-start-iter _buf (-> this get-cobj)))

     (if (not (eq? _c-object #f))
         (offset (gtk-text-iter-get-offset _c-object)))

     (if (and _line _offset)
         (begin
           (line        _line)
           (line-offset _offset))
         (begin
           (if _line
               (line _line))
           (if _offset
               (offset _offset)))))
   )
  )