/* layoutiter.h
 *
 * Copyright 2001-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, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <pangomm/layoutline.h>
#include <pangomm/glyphitem.h>
#include <pango/pango-layout.h>

_DEFS(pangomm,pango)

namespace Pango
{

/** A Pango::LayoutIter can be used to iterate over the visual extents of a Pango::Layout.
 */
class PANGOMM_API LayoutIter
{
  _CLASS_BOXEDTYPE(LayoutIter, PangoLayoutIter, NONE, pango_layout_iter_copy, pango_layout_iter_free, PANGOMM_API)
  _IGNORE(pango_layout_iter_copy, pango_layout_iter_free)

public:

  _WRAP_METHOD(int get_index() const, pango_layout_iter_get_index)

  /** Gets the current run.
   *
   * When iterating by run, at the end of each line, there's a position with
   * a <tt>nullptr</tt> run, so this function can return an invalid GlyphItem.
   * The <tt>nullptr</tt> run at the end of each line ensures that all lines have
   * at least one run, even lines consisting of only a newline.
   *
   * @return The current run.
   */
  _WRAP_METHOD(GlyphItem get_run() const, pango_layout_iter_get_run_readonly)
  _IGNORE(pango_layout_iter_get_run)

  /** Gets the current line.
   *
   * Use the faster get_const_line() if you do not plan
   * to modify the contents of the line (glyphs, glyph widths, etc.).
   *
   * @return The current line.
   */
  _WRAP_METHOD(Glib::RefPtr<LayoutLine> get_line(), pango_layout_iter_get_line, refreturn)

  /** Gets the current line for read-only access.
   *
   * @return The current line, that should not be modified.
   */
  _WRAP_METHOD(Glib::RefPtr<const LayoutLine> get_line() const, pango_layout_iter_get_line_readonly, refreturn)

  /** Gets the current line for read-only access.
   *
   * This is a faster alternative to get_line(), but the user is not expected
   * to modify the contents of the line (glyphs, glyph widths, etc.).
   *
   * @newin{2,50}
   *
   * @return The current line, that should not be modified.
   */
  _WRAP_METHOD(Glib::RefPtr<const LayoutLine> get_const_line() const, pango_layout_iter_get_line_readonly, refreturn)

  _WRAP_METHOD(bool at_last_line() const, pango_layout_iter_at_last_line)

  _WRAP_METHOD(Glib::RefPtr<Layout> get_layout(), pango_layout_iter_get_layout, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Layout> get_layout() const, pango_layout_iter_get_layout, refreturn, constversion)

  _WRAP_METHOD(bool next_char(), pango_layout_iter_next_char)
  _WRAP_METHOD(bool next_cluster(), pango_layout_iter_next_cluster)
  _WRAP_METHOD(bool next_run(), pango_layout_iter_next_run)
  _WRAP_METHOD(bool next_line(), pango_layout_iter_next_line)

  /** Gets the extents of the current character, in layout coordinates (origin is the top left of the entire layout).
   * Only logical extents can sensibly be obtained for characters; ink extents make sense only down to the level of clusters.
   * @return The logical extents of the current character.
   */
  Rectangle get_char_extents() const;
  _IGNORE(pango_layout_iter_get_char_extents)

  _WRAP_METHOD(void get_cluster_extents(Rectangle& ink_rect, Rectangle& logical_rect) const, pango_layout_iter_get_cluster_extents)

  /** Gets the ink extents of the current cluster, in layout coordinates (origin is the top left of the entire layout).
   * @return The extents of the current cluster as drawn.
   */
  Rectangle get_cluster_ink_extents() const;

  /** Gets the logical extents of the current cluster, in layout coordinates (origin is the top left of the entire layout).
   * @return The logical extents of the current cluster.
   */
  Rectangle get_cluster_logical_extents() const;

  _WRAP_METHOD(void get_run_extents(Rectangle& ink_rect, Rectangle& logical_rect) const, pango_layout_iter_get_run_extents)

  /** Gets the ink extents of the current run in layout coordinates (origin is the top left of the entire layout).
   * @return The extents of the current run as drawn.
   */
  Rectangle get_run_ink_extents() const;

  /** Gets the logical extents of the current run in layout coordinates (origin is the top left of the entire layout).
   * @return The logical extents of the current run.
   */
  Rectangle get_run_logical_extents() const;

  _WRAP_METHOD(void get_line_extents(Rectangle& ink_rect, Rectangle& logical_rect) const,   pango_layout_iter_get_line_extents)

  /** Obtains the ink extents of the current line.
   * @return The extents of the current line as drawn.
   */
  Rectangle get_line_ink_extents() const;

  /** Obtains the logical extents of the current line.
   * @return The logical extents of the current line.
   */
  Rectangle get_line_logical_extents() const;

  _WRAP_METHOD(void get_line_yrange(int& y0, int& y1) const, pango_layout_iter_get_line_yrange)

  _WRAP_METHOD(void get_layout_extents(Rectangle& ink_rect, Rectangle& logical_rect) const, pango_layout_iter_get_layout_extents)

  /** Obtains the ink extents of the Pango::Layout being iterated over.
   * @return The extents of the layout as drawn.
   */
  Rectangle get_layout_ink_extents() const;

  /** Obtains the logical extents of the Pango::Layout being iterated over.
   * @return The logical extents of the layout.
   */
  Rectangle get_layout_logical_extents() const;

  _WRAP_METHOD(int get_baseline() const, pango_layout_iter_get_baseline)
};

} //namespace Pango
