[goocanvasmm] Replace use of *ListHandle with std::vector<>, as in gtkmm.



commit 5878cb395fc5df941292f31fbf59c7e62ec0360f
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jan 28 23:31:55 2011 +0100

    Replace use of *ListHandle with std::vector<>, as in gtkmm.
    
    * goocanvas/src/canvas.hg:
    * goocanvas/src/item.[hg|ccg]: However, the vfunc implemenations here need
    some attention to make sure that we are not doing awful things with memory.

 ChangeLog               |    8 ++++++++
 goocanvas/src/canvas.hg |   15 +++++++--------
 goocanvas/src/item.ccg  |   27 ++++++++++++++++++---------
 goocanvas/src/item.hg   |   20 +++++++++++---------
 4 files changed, 44 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d0dbcee..9d3623e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-28  Murray Cumming  <murrayc murrayc com>
+
+	Replace use of *ListHandle with std::vector<>, as in gtkmm.
+
+	* goocanvas/src/canvas.hg:
+	* goocanvas/src/item.[hg|ccg]: However, the vfunc implemenations here need 
+	some attention to make sure that we are not doing awful things with memory.
+
 1.90.2:
 
 2011-01-05  Murray Cumming  <murrayc murrayc com>
diff --git a/goocanvas/src/canvas.hg b/goocanvas/src/canvas.hg
index 7074858..b344629 100644
--- a/goocanvas/src/canvas.hg
+++ b/goocanvas/src/canvas.hg
@@ -68,14 +68,13 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Item> get_item_at(double x, double y, bool is_pointer_event), goo_canvas_get_item_at, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const Item> get_item_at(double x, double y, bool is_pointer_event) const, goo_canvas_get_item_at, constversion)
 
-#define(`__FL2H_SHALLOW',`$`'2($`'3, Glib::OWNERSHIP_SHALLOW)')
-#_CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<Item> >', __FL2H_SHALLOW)
-#_CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<const Item> >', __FL2H_SHALLOW)
-
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<Item> > get_items_at(double x, double y, bool is_pointer_event), goo_canvas_get_items_at)
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<const Item> > get_items_at(double x, double y, bool is_pointer_event) const, goo_canvas_get_items_at)
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers), goo_canvas_get_items_in_area)
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<const Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers) const, goo_canvas_get_items_in_area)
+#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Item> >',`Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
+#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Item> >',`Glib::ListHandler<Glib::RefPtr<const Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
+
+  _WRAP_METHOD(std::vector< Glib::RefPtr<Item> > get_items_at(double x, double y, bool is_pointer_event), goo_canvas_get_items_at)
+  _WRAP_METHOD(std::vector< Glib::RefPtr<const Item> > get_items_at(double x, double y, bool is_pointer_event) const, goo_canvas_get_items_at)
+  _WRAP_METHOD(std::vector< Glib::RefPtr<Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers), goo_canvas_get_items_in_area)
+  _WRAP_METHOD(std::vector< Glib::RefPtr<const Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers) const, goo_canvas_get_items_in_area)
 
   _WRAP_METHOD(double get_scale() const, goo_canvas_get_scale)
   _WRAP_METHOD(void set_scale(double scale), goo_canvas_set_scale)
diff --git a/goocanvas/src/item.ccg b/goocanvas/src/item.ccg
index 97f9085..a1fd028 100644
--- a/goocanvas/src/item.ccg
+++ b/goocanvas/src/item.ccg
@@ -107,7 +107,7 @@ void Item::get_bounds_vfunc(Bounds& bounds) const
 // parameter and return value. In C, this function is supposed to prepend
 // new entries to the given list and return the new list head. In C++, we
 // cannot emulate this behaviour since it is not possible to prepend items to
-// a Glib::ListHandle<>. Thus, we always create a new list to return, and
+// a std::vector<>. Thus, we always create a new vector to return, and
 // free the one passed in.
 GList* Item_Class::get_items_at_vfunc_callback(GooCanvasItem* self, gdouble x, gdouble y, cairo_t* cr, gboolean is_pointer_event, gboolean parent_is_visible, GList* found_items)
 {
@@ -127,7 +127,10 @@ GList* Item_Class::get_items_at_vfunc_callback(GooCanvasItem* self, gdouble x, g
     #endif //GLIBMM_EXCEPTIONS_ENABLED
       // Call the virtual member method, which derived classes might override.
       Bounds cpp_bounds;
-      Glib::ListHandle<Glib::RefPtr<Item> > retval(obj->get_items_at_vfunc(x, y, Cairo::RefPtr<Cairo::Context>(new Cairo::Context(cr, false /* has_reference */)), is_pointer_event == TRUE, parent_is_visible == TRUE, Glib::ListHandle<Glib::RefPtr<Item> >(found_items, Glib::OWNERSHIP_NONE)));
+      
+      const std::vector<Glib::RefPtr<Item> > vec_found_items = 
+        Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector(found_items, Glib::OWNERSHIP_NONE);
+      std::vector<Glib::RefPtr<Item> > retval(obj->get_items_at_vfunc(x, y, Cairo::RefPtr<Cairo::Context>(new Cairo::Context(cr, false /* has_reference */)), is_pointer_event == TRUE, parent_is_visible == TRUE, vec_found_items));
       // retval will free the list on destruction, and we can't change the
       // ownership here, so we have to copy the list.
       return g_list_copy(retval.data());
@@ -154,7 +157,7 @@ g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Ge
   return 0;
 }
 
-Glib::ListHandle<Glib::RefPtr<Item> > Item::get_items_at_vfunc(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool is_parent_visible, const Glib::ListHandle<Glib::RefPtr<Item> >& found_items)
+std::vector<Glib::RefPtr<Item> > Item::get_items_at_vfunc(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool is_parent_visible, const std::vector<Glib::RefPtr<Item> >& found_items)
 {
   //Call the default C implementation:
 
@@ -170,19 +173,25 @@ Glib::ListHandle<Glib::RefPtr<Item> > Item::get_items_at_vfunc(double x, double
   // something which, when converting to ListHandle, has always shallow
   // ownership.
   if(base && base->get_items_at)
-    return Glib::ListHandle<Glib::RefPtr<Item> >((*base->get_items_at)(const_cast<GooCanvasItem*>(gobj()), x, y, context->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(is_parent_visible), found_items.data()), Glib::OWNERSHIP_SHALLOW);
+  {
+    GList* glist_found_items = Glib::ListHandler<Glib::RefPtr<Item> >::vector_to_list(found_items).data();
+
+    GList* cresult = (*base->get_items_at)(const_cast<GooCanvasItem*>(gobj()), x, y, context->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(is_parent_visible), glist_found_items);
+    g_list_free(glist_found_items); //TODO: Is this right?
+    return Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector(cresult, Glib::OWNERSHIP_SHALLOW);
+  }
   
-  return Glib::ListHandle<Glib::RefPtr<Item> >(NULL, Glib::OWNERSHIP_SHALLOW);
+  return std::vector<Glib::RefPtr<Item> >();
 }
 
-Glib::ListHandle< Glib::RefPtr<Item> > Item::get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible)
+std::vector< Glib::RefPtr<Item> > Item::get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible)
 {
-  return Glib::ListHandle< Glib::RefPtr<Item> >(goo_canvas_item_get_items_at(gobj(), x, y, (context)->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(parent_is_visible), NULL), Glib::OWNERSHIP_SHALLOW);
+  return Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector(goo_canvas_item_get_items_at(gobj(), x, y, (context)->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(parent_is_visible), NULL), Glib::OWNERSHIP_SHALLOW);
 }
 
-Glib::ListHandle< Glib::RefPtr<const Item> > Item::get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible) const
+std::vector< Glib::RefPtr<const Item> > Item::get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible) const
 {
-  return Glib::ListHandle< Glib::RefPtr<const Item> >(goo_canvas_item_get_items_at(const_cast<GooCanvasItem*>(gobj()), x, y, (context)->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(parent_is_visible), NULL), Glib::OWNERSHIP_SHALLOW);
+  return Glib::ListHandler<Glib::RefPtr<const Item> >::list_to_vector(goo_canvas_item_get_items_at(const_cast<GooCanvasItem*>(gobj()), x, y, (context)->cobj(), static_cast<int>(is_pointer_event), static_cast<int>(parent_is_visible), NULL), Glib::OWNERSHIP_SHALLOW);
 }
 
 } //namespace Goocanvas
diff --git a/goocanvas/src/item.hg b/goocanvas/src/item.hg
index e76a8c0..d46f52b 100644
--- a/goocanvas/src/item.hg
+++ b/goocanvas/src/item.hg
@@ -104,16 +104,18 @@ public:
 
   // Note the semantics of the C version: The returned list is the same as the
   // one fed into the function, with possibly some elements added to the head.
-#m4 _CONVERSION(`const Glib::ListHandle< Glib::RefPtr<Item> >&', `GList*', `g_list_copy(($3).data())')
-#m4 _CONVERSION(`const Glib::ListHandle< Glib::RefPtr<const Item> >&', `GList*', `g_list_copy(($3).data())')
-#m4 _CONVERSION(`GList*', `Glib::ListHandle< Glib::RefPtr<Item> >', `$2($3, Glib::OWNERSHIP_SHALLOW)')
-#m4 _CONVERSION(`GList*', `Glib::ListHandle< Glib::RefPtr<const Item> >', `$2($3, Glib::OWNERSHIP_SHALLOW)')
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible, const Glib::ListHandle< Glib::RefPtr<Item> >& found_items), goo_canvas_item_get_items_at)
-  _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<const Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible, const Glib::ListHandle< Glib::RefPtr<const Item> >& found_items) const, goo_canvas_item_get_items_at)
+#m4 _CONVERSION(`const std::vector< Glib::RefPtr<Item> >&',`GList*',`g_list_copy(Glib::ListHandler<Glib::RefPtr<Item> >::vector_to_list($3).data())')
+#m4 _CONVERSION(`const std::vector< Glib::RefPtr<const Item> >&',`GList*',`g_list_copy(Glib::ListHandler<Glib::RefPtr<const Item> >::vector_to_list($3).data())')
+
+#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Item> >',`Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
+#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Item> >',`Glib::ListHandler<Glib::RefPtr<const Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
+
+  _WRAP_METHOD(std::vector< Glib::RefPtr<Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible, const std::vector< Glib::RefPtr<Item> >& found_items), goo_canvas_item_get_items_at)
+  _WRAP_METHOD(std::vector< Glib::RefPtr<const Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible, const std::vector< Glib::RefPtr<const Item> >& found_items) const, goo_canvas_item_get_items_at)
 
   // Use this if you don't have a list already:
-  Glib::ListHandle< Glib::RefPtr<Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible);
-  Glib::ListHandle< Glib::RefPtr<const Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible) const;
+  std::vector< Glib::RefPtr<Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible);
+  std::vector< Glib::RefPtr<const Item> > get_items_at(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool parent_is_visible) const;
 
   //TODO: Use Cairo::RefPtr?
   _WRAP_METHOD(bool get_transform(Cairo::Matrix* matrix), goo_canvas_item_get_transform)
@@ -205,7 +207,7 @@ protected:
 #ifdef GLIBMM_VFUNCS_ENABLED
   // Hand code, since Bounds can only copy a GooCanvasBounds* but not ref one.
   virtual void get_bounds_vfunc(Bounds& bounds) const;
-  virtual Glib::ListHandle<Glib::RefPtr<Item> > get_items_at_vfunc(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool is_parent_visible, const Glib::ListHandle<Glib::RefPtr<Item> >& found_items);
+  virtual std::vector<Glib::RefPtr<Item> > get_items_at_vfunc(double x, double y, const Cairo::RefPtr<Cairo::Context>& context, bool is_pointer_event, bool is_parent_visible, const std::vector<Glib::RefPtr<Item> >& found_items);
 #endif
 
 #m4begin



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