[gtkmm] Gtk::CellArea: Add foreach().



commit 160e860ac97acd3d57f8dceaa9abbf8974716a83
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Mar 25 23:57:56 2012 +0200

    Gtk::CellArea: Add foreach().
    
    * gtk/src/cellarea.[hg|ccg]: Wrap gtk_cell_area_foreach() and
    gtk_cell_area_foreach_alloc().

 ChangeLog            |    7 ++++++
 gtk/src/cellarea.ccg |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/src/cellarea.hg  |   51 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 113 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3644698..486d4ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,13 @@
 
 2012-03-25  Murray Cumming  <murrayc murrayc com>
 
+	Gtk::CellArea: Add foreach(). 
+
+	* gtk/src/cellarea.[hg|ccg]: Wrap gtk_cell_area_foreach() and 
+	gtk_cell_area_foreach_alloc().
+
+2012-03-25  Murray Cumming  <murrayc murrayc com>
+
 	Gdk::Device: Add list_axes().
 
 	* gdk/src/device.[hg|ccg]: Wrap gdk_device_list_axes().
diff --git a/gtk/src/cellarea.ccg b/gtk/src/cellarea.ccg
index 4e16c1a..ec8662b 100644
--- a/gtk/src/cellarea.ccg
+++ b/gtk/src/cellarea.ccg
@@ -18,8 +18,64 @@
 #include <gtk/gtk.h>
 
 
+namespace //anonymous namespace
+{
+
+static gboolean proxy_foreach_callback(GtkCellRenderer* cell, void* data)
+{
+  typedef Gtk::CellArea::SlotForeach SlotType;
+  SlotType& slot = *static_cast<SlotType*>(data);
+
+  try
+  {
+    return slot(Glib::wrap(cell));
+  }
+  catch(...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+
+  return FALSE;
+}
+
+static gboolean proxy_foreach_alloc_callback(GtkCellRenderer* cell, const GdkRectangle* cell_area, const GdkRectangle* cell_background, void* data)
+{
+  typedef Gtk::CellArea::SlotForeachAlloc SlotType;
+  SlotType& slot = *static_cast<SlotType*>(data);
+
+  try
+  {
+    return slot(Glib::wrap(cell), Glib::wrap(cell_area), Glib::wrap(cell_background));
+  }
+  catch(...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+
+  return FALSE;
+}
+
+
+} //anonymous namespace
+
+
+
 namespace Gtk
 {
+
+void CellArea::foreach(const SlotForeach& slot)
+{
+  SlotForeach slot_copy(slot);
+  gtk_cell_area_foreach(const_cast<GtkCellArea*>(gobj()), &proxy_foreach_callback, &slot_copy);
+}
+
+void CellArea::foreach(const Glib::RefPtr<CellAreaContext>& context, Widget* widget, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area, const SlotForeachAlloc& slot)
+{
+  SlotForeachAlloc slot_copy(slot);
+  gtk_cell_area_foreach_alloc(const_cast<GtkCellArea*>(gobj()), Glib::unwrap(context), Glib::unwrap(widget), cell_area.gobj(), background_area.gobj(), &proxy_foreach_alloc_callback, &slot_copy);
+}
+
+
 //These vfunc callbacks are custom implemented because we want the output
 //arguments of the C++ vfuncs to be int& (not int*), and the vfunc_callback
 //functions may be called from gtk+ with a NULL pointer.
@@ -207,5 +263,6 @@ void CellArea_Class::get_preferred_width_for_height_vfunc_callback(GtkCellArea*
     (*base->get_preferred_width_for_height)(self, context, widget, height, minimum_width, natural_width);
 }
 
+
 } //namespace Gtk
 
diff --git a/gtk/src/cellarea.hg b/gtk/src/cellarea.hg
index d415380..95c7c65 100644
--- a/gtk/src/cellarea.hg
+++ b/gtk/src/cellarea.hg
@@ -109,8 +109,55 @@ public:
   _WRAP_METHOD(void add(CellRenderer& renderer), gtk_cell_area_add)
   _WRAP_METHOD(void remove(CellRenderer& renderer), gtk_cell_area_remove)
   _WRAP_METHOD(bool has_renderer(CellRenderer& renderer), gtk_cell_area_has_renderer)
-  //TODO: _WRAP_METHOD(void foreach(GtkCellCallback callback, gpointer callback_data), gtk_cell_area_foreach)
-  //TODO: _WRAP_METHOD(void foreach_alloc(const Glib::RefPtr<CellAreaContext>& context,  Widget& widget, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area,  GtkCellAllocCallback  callback,  gpointer  callback_data), gtk_cell_area_foreach_alloc
+
+  /** For instance,
+   * bool on_foreach(Gtk::CellRenderer* renderer);
+   *
+   * @param renderer the cell renderer to operate on
+   * @returns true to stop iterating over cells.
+   *
+   * @newin{3,4}
+   */
+  typedef sigc::slot<bool, CellRenderer*> SlotForeach;
+
+  /** Calls the @a slot for every CellRenderer in the CellArea.
+   *
+   * @param slot The slot to call for every CellRenderer.
+   *
+   * @newin{3,4}
+   */
+  void foreach(const SlotForeach& slot);
+  _IGNORE(gtk_cell_area_foreach)
+
+
+  /** For instance,
+   * bool on_foreach(Gtk::CellRenderer* renderer, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area>);
+   *
+   * @param renderer the cell renderer to operate on
+   * @param  cell_area the area allocated to the @a renderer inside the rectangle provided to foreach().
+   * @@param cell_background The background area for the @a renderer inside the background area provided to foreach().
+   * @param slot The slot to call for every CellRenderer.
+   * @returns true to stop iterating over cells.
+   *
+   * @newin{3,4}
+   */
+  typedef sigc::slot<bool, CellRenderer*, const Gdk::Rectangle&, const Gdk::Rectangle&> SlotForeachAlloc;
+
+  /** Calls the @a slot for every CellRenderer in the CellArea
+   * with the allocated rectangle inside the @a cell_area rectangle.
+   *
+   * @param context The CellAreaContext for this row of data.
+   * @param widget The widget that the CellArea is rendering to.
+   * @param cell_area The widget-relative coordinates and size for the CellArea.
+   * @param background_area The widget-relative coordinates of the background area.
+   *
+   * @param slot The slot to call for every CellRenderer.
+   *
+   * @newin{3,4}
+   */
+  void foreach(const Glib::RefPtr<CellAreaContext>& context, Widget* widget, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area, const SlotForeachAlloc& slot);
+  _IGNORE(gtk_cell_area_foreach_alloc)
+
   _WRAP_METHOD(int event(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, GdkEvent* event, const Gdk::Rectangle& cell_area,  GtkCellRendererState  flags), gtk_cell_area_event)
   _WRAP_METHOD(void render(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const ::Cairo::RefPtr< ::Cairo::Context>& cr, const Gdk::Rectangle& background_area, const Gdk::Rectangle& cell_area, CellRendererState flags,  bool paint_focus), gtk_cell_area_render)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]