/* gutterrenderer.h
 *
 * Copyright (C) 2010, 2011 Krzesimir Nowak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/// \file
/// \brief GutterRenderer class

#include <gtkmm/object.h>
#include <gtkmm/tooltip.h>
#include <gtksourceviewmm/view.h>

_DEFS(gtksourceviewmm,gtksourceview)
_PINCLUDE(gtkmm/private/object_p.h)

namespace Gsv
{

_WRAP_ENUM(GutterRendererState, GtkSourceGutterRendererState, s#^SOURCE_##)

_WRAP_ENUM(GutterRendererAlignmentMode, GtkSourceGutterRendererAlignmentMode, s#^SOURCE_##)

// TODO: write docs.
class GutterRenderer : public Gtk::Object
{
  _CLASS_GTKOBJECT(GutterRenderer, GtkSourceGutterRenderer, GTK_SOURCE_GUTTER_RENDERER, Gtk::Object, GInitiallyUnowned)
public:
#m4 _CONVERSION(`const Cairo::RefPtr<Cairo::Context>&', `cairo_t*', `(($3) ? ($3)->cobj() : 0)')
#m4 _CONVERSION(`Gtk::TextIter&',`GtkTextIter*',($3).gobj())
  _WRAP_METHOD(void begin(
                  const Cairo::RefPtr<Cairo::Context>& cr,
                  const Gdk::Rectangle& background_area,
                  const Gdk::Rectangle& cell_area,
                  Gtk::TextIter& start,
                  Gtk::TextIter& end), gtk_source_gutter_renderer_begin)

  _WRAP_METHOD(void draw(
                  const Cairo::RefPtr<Cairo::Context>& cr,
                  const Gdk::Rectangle& background_area,
                  const Gdk::Rectangle& cell_area,
                  Gtk::TextIter& start,
                  Gtk::TextIter& end,
                  GutterRendererState), gtk_source_gutter_renderer_draw)

  _WRAP_METHOD(void end(), gtk_source_gutter_renderer_end)

  _WRAP_METHOD(int get_size() const, gtk_source_gutter_renderer_get_size)

  _WRAP_METHOD(void set_size(int size), gtk_source_gutter_renderer_set_size)

  _WRAP_METHOD(bool get_visible() const, gtk_source_gutter_renderer_get_visible)

  _WRAP_METHOD(void set_visible(bool visible), gtk_source_gutter_renderer_set_visible)

// TODO: write padding class. krnowak

  _WRAP_METHOD(void get_padding(int& xpad, int& ypad) const, gtk_source_gutter_renderer_get_padding)

  _WRAP_METHOD(void set_padding(int xpad, int ypad), gtk_source_gutter_renderer_set_padding)

// TODO: write alignment class. krnowak

  _WRAP_METHOD(void get_alignment(float& xalign, float& yalign) const, gtk_source_gutter_renderer_get_alignment)

  _WRAP_METHOD(void set_alignment(float xalign, float yalign), gtk_source_gutter_renderer_set_alignment)

  _WRAP_METHOD(GutterRendererAlignmentMode get_alignment_mode() const, gtk_source_gutter_renderer_get_alignment_mode)

  _WRAP_METHOD(void set_alignment_mode(GutterRendererAlignmentMode mode), gtk_source_gutter_renderer_set_alignment_mode)

  _WRAP_METHOD(Gtk::TextWindowType get_window_type() const, gtk_source_gutter_renderer_get_window_type)

#m4 _CONVERSION(GtkTextView*, Gtk::TextView*, Glib::wrap($3))
  _WRAP_METHOD(Gtk::TextView* get_view(), gtk_source_gutter_renderer_get_view)

  _WRAP_METHOD(const Gtk::TextView* get_view() const, gtk_source_gutter_renderer_get_view, constversion)

// TODO: use std::pair? krnowak

#m4 _CONVERSION(`Gdk::RGBA&',`GdkRGBA*',`($3).gobj()')
  _WRAP_METHOD(bool get_background(Gdk::RGBA& color) const, gtk_source_gutter_renderer_get_background)

  bool is_background_set() const;

#m4 _CONVERSION(`const Gdk::RGBA&',`const GdkRGBA*',`($3).gobj()')
  _WRAP_METHOD(void set_background(const Gdk::RGBA& color), gtk_source_gutter_renderer_set_background)

  _IGNORE(gtk_source_gutter_renderer_activate, gtk_source_gutter_renderer_query_activatable, gtk_source_gutter_renderer_query_tooltip, gtk_source_gutter_renderer_query_data)

  _WRAP_METHOD(void queue_draw(), gtk_source_gutter_renderer_queue_draw)

  _WRAP_PROPERTY("visible", bool)
  _WRAP_PROPERTY("xpad", int)
  _WRAP_PROPERTY("ypad", int)
  _WRAP_PROPERTY("xalign", float)
  _WRAP_PROPERTY("yalign", float)
  _WRAP_PROPERTY("view", Gtk::TextView*)
  _WRAP_PROPERTY("alignment-mode", GutterRendererAlignmentMode)
  _WRAP_PROPERTY("window-type", Gtk::TextWindowType)
  _WRAP_PROPERTY("size", int)
  _WRAP_PROPERTY("background-rgba", Gdk::RGBA)
  _WRAP_PROPERTY("background-set", bool)

#m4 _CONVERSION(`GdkRectangle*',`const Gdk::Rectangle&',`Glib::wrap($3)')
#m4 _CONVERSION(`GtkTextIter*',`const Gtk::TextIter&',`Glib::wrap($3)')
#m4 _CONVERSION(`const Gtk::TextIter&',`GtkTextIter*',`const_cast<GtkTextIter*>(($3).gobj())')
#m4 _CONVERSION(`GtkTooltip*', `const Glib::RefPtr<Gtk::Tooltip>&', `Glib::wrap($3, true)')
#m4 _CONVERSION(`const Glib::RefPtr<Gtk::Tooltip>&',`GtkTooltip*',`const_cast<GtkTooltip*>(Glib::unwrap($3))')

  _WRAP_SIGNAL(bool query_tooltip(const Gtk::TextIter& iter,
                                  const Gdk::Rectangle& area,
                                  int x,
                                  int y,
                                  const Glib::RefPtr<Gtk::Tooltip>& tooltip), "query-tooltip")

  _WRAP_SIGNAL(void activate(const Gtk::TextIter& iter,
                             const Gdk::Rectangle& area,
                             GdkEvent* event), "activate")

  _WRAP_SIGNAL(void queue_draw(), "queue-draw")

  _WRAP_SIGNAL(void query_data(const Gtk::TextIter& start,
                               const Gtk::TextIter& end,
                               GutterRendererState state), "query-data")

  _WRAP_SIGNAL(bool query_activatable(const Gtk::TextIter& iter,
                                      const Gdk::Rectangle& area,
                                      GdkEvent* event), "query-activatable")

protected:
  _CTOR_DEFAULT()

#m4 _CONVERSION(`cairo_t*',`const Cairo::RefPtr<Cairo::Context>&',`Cairo::RefPtr<Cairo::Context>(new Cairo::Context($3, false))')
#m4 _CONVERSION(`GtkTextIter*',`Gtk::TextIter&',`Glib::wrap($3)')

  _WRAP_VFUNC(void begin(const Cairo::RefPtr<Cairo::Context>& cr,
                         const Gdk::Rectangle& background_area,
                         const Gdk::Rectangle& cell_area,
                         Gtk::TextIter& start,
                         Gtk::TextIter& end), begin)

  _WRAP_VFUNC(void draw(const Cairo::RefPtr<Cairo::Context>& cr,
                        const Gdk::Rectangle& background_area,
                        const Gdk::Rectangle& cell_area,
                        Gtk::TextIter& start,
                        Gtk::TextIter& end,
                        GutterRendererState), draw)

  _WRAP_VFUNC(void end(), end)

#m4 _CONVERSION(`Gtk::TextView*',`GtkTextView*',`Glib::unwrap($3)')
  _WRAP_VFUNC(void change_view(Gtk::TextView* old_view), change_view)

#m4 _CONVERSION(`GtkTextBuffer*',`const Glib::RefPtr<Gtk::TextBuffer>&',`Glib::wrap($3, true)')
#m4 _CONVERSION(`const Glib::RefPtr<Gtk::TextBuffer>&',`GtkTextBuffer*',`Glib::unwrap($3)')
  _WRAP_VFUNC(void change_buffer(const Glib::RefPtr<Gtk::TextBuffer>& old_buffer), change_buffer)

};

} // namespace Gsv


