/* Copyright (C) 1998-2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

_CONFIGINCLUDE(gtkmmconfig.h)

#include <glibmm/object.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gtk
{

class GTKMM_API TextBuffer;
class GTKMM_API TextIter;
class GTKMM_API TextConstIter;

/** Typedefed as Gtk::TextBuffer::Mark. A position in the buffer, preserved across buffer modifications.
 *
 * A Mark is like a bookmark in a text buffer; it preserves a position in the text.  Unlike iterators, marks remain valid across buffer mutations, because
 * their behavior is defined when text is inserted or deleted. When text containing a mark is deleted, the mark remains in
 * the position originally occupied by the deleted text. When text is inserted at a mark, a mark with left gravity will be
 * moved to the beginning of the newly-inserted text, and a mark with right gravity will be moved to the end.
 * The standard text cursor in left-to-right languages is a mark with right gravity, because it stays to the right of inserted
 * text.
 *
 * Like tags, marks can be either named or anonymous. There are two marks built-in to Gtk::TextBuffer; these are named "insert" and
 * "selection_bound" and refer to the insertion point and the boundary of the selection which is not the insertion point,
 * respectively. If no text is selected, these two marks will be in the same position. You can manipulate what is selected and
 * where the cursor appears by moving these marks around.
 *
 * "left" and "right" here refer to logical direction (left is the toward the start of the buffer); in some languages such as
 * Hebrew the logically-leftmost text is not actually on the left when displayed.
 *
 * You can convert the mark to an @link Gtk::TextIter iterator@endlink or
 * a @link Gtk::TextConstIter const_iterator@endlink using Gtk::TextBuffer::get_iter_at_mark().
 *
 * Marks can be deleted from the buffer at any time with Gtk::TextBuffer::delete_mark(). Once deleted from the buffer, a mark is essentially useless.
 *
 * Marks optionally have names; these can be convenient to avoid passing the Gtk::TextBuffer::Mark object around.
 *
 * Marks are typically created using the Gtk::TextBuffer::create_mark() function.
 *
 * @ingroup TextView
 */
class GTKMM_API TextMark : public Glib::Object
{
  _CLASS_GOBJECT(TextMark, GtkTextMark, GTK_TEXT_MARK, Glib::Object, GObject, , , GTKMM_API)
protected:

  /** Creates an anoymous text mark. Add it to a buffer using Gtk::TextBuffer::add_mark().
   * If a mark has left
   * gravity, and text is inserted at the mark's current location, the mark
   * will be moved to the left of the newly-inserted text. If the mark has
   * right gravity (@a left_gravity = false), the mark will end up on the
   * right of newly-inserted text. The standard left-to-right cursor is a
   * mark with right gravity (when you type, the cursor stays on the right
   * side of the text you're typing).
   *
   * @param left_gravity Whether the mark should have left gravity.
   */
  explicit TextMark(bool left_gravity = true);

  /** Creates a text mark. Add it to a buffer using Gtk::TextBuffer::add_mark().
   * The mark can be retrieved by name using Gtk::TextBuffer::get_mark(). If a mark has left
   * gravity, and text is inserted at the mark's current location, the mark
   * will be moved to the left of the newly-inserted text. If the mark has
   * right gravity (@a left_gravity = false), the mark will end up on the
   * right of newly-inserted text. The standard left-to-right cursor is a
   * mark with right gravity (when you type, the cursor stays on the right
   * side of the text you're typing).
   *
   * @param name mark name.
   * @param left_gravity Whether the mark should have left gravity.
   */
  _WRAP_CTOR(TextMark(const Glib::ustring& name, bool left_gravity = true), gtk_text_mark_new)

public:

  /** Creates an anoymous text mark. Add it to a buffer using Gtk::TextBuffer::add_mark().
   * If a mark has left
   * gravity, and text is inserted at the mark's current location, the mark
   * will be moved to the left of the newly-inserted text. If the mark has
   * right gravity (@a left_gravity = false), the mark will end up on the
   * right of newly-inserted text. The standard left-to-right cursor is a
   * mark with right gravity (when you type, the cursor stays on the right
   * side of the text you're typing).
   *
   * @param left_gravity Whether the mark should have left gravity.
   * @result A RefPtr to a new text mark.
   */
  _WRAP_CREATE(bool left_gravity = true)

/** Creates a text mark. Add it to a buffer using Gtk::TextBuffer::add_mark().
   * The mark can be retrieved by name using Gtk::TextBuffer::get_mark(). If a mark has left
   * gravity, and text is inserted at the mark's current location, the mark
   * will be moved to the left of the newly-inserted text. If the mark has
   * right gravity (@a left_gravity = false), the mark will end up on the
   * right of newly-inserted text. The standard left-to-right cursor is a
   * mark with right gravity (when you type, the cursor stays on the right
   * side of the text you're typing).
   *
   * @param name mark name.
   * @param left_gravity Whether the mark should have left gravity.
   * @result A RefPtr to a new text mark.
   */
  _WRAP_CREATE(const Glib::ustring& name, bool left_gravity = true)

  _WRAP_METHOD(void set_visible(bool setting = true), gtk_text_mark_set_visible)
  _WRAP_METHOD(bool get_visible() const, gtk_text_mark_get_visible)
  _WRAP_METHOD(Glib::ustring get_name() const, gtk_text_mark_get_name)
  _WRAP_METHOD(bool get_deleted() const, gtk_text_mark_get_deleted)
  _WRAP_METHOD(Glib::RefPtr<TextBuffer> get_buffer(), gtk_text_mark_get_buffer, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TextBuffer> get_buffer() const, gtk_text_mark_get_buffer, refreturn, constversion)
  _WRAP_METHOD(bool get_left_gravity() const, gtk_text_mark_get_left_gravity)

  TextIter get_iter();
  TextConstIter get_iter() const;

  _WRAP_PROPERTY("name", Glib::ustring)
  _WRAP_PROPERTY("left-gravity", bool)
};

} //namespace Gtk
