[pangomm] LayoutIter: Wrap this as a boxed type, which needs less code.



commit 828501a70f78fe88391944034b4a166a631e3daf
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Jan 8 15:18:53 2011 +0100

    LayoutIter: Wrap this as a boxed type, which needs less code.
    
    	* pango/src/layoutiter.[hg|ccg]: PangoLayoutIter became a boxed type at some
    	point, with a pango_layout_iter_copy() function, so we can now wrap it
    	normally without so much hand-coding. This also adds a copy constructor.
    	* pango/src/layout.ccg: get_iter(): Use the LayoutIter copy constructor
    	instead of the crappy old assign_gobj() function. Also deprecate this
    	method, adding a get_iter(void), now that the copy constructor allows us to
    	use LayoutIter as a return type.

 ChangeLog                |   12 ++++++++++++
 pango/src/layout.ccg     |   11 ++++++++++-
 pango/src/layout.hg      |   10 ++++++++++
 pango/src/layoutiter.ccg |   22 +++-------------------
 pango/src/layoutiter.hg  |   27 +++++++--------------------
 5 files changed, 42 insertions(+), 40 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cc80c74..fbe95a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2011-01-08  Murray Cumming  <murrayc murrayc com>
 
+	LayoutIter: Wrap this as a boxed type, which needs less code.
+	
+	* pango/src/layoutiter.[hg|ccg]: PangoLayoutIter became a boxed type at some 
+	point, with a pango_layout_iter_copy() function, so we can now wrap it 
+	normally without so much hand-coding. This also adds a copy constructor.
+	* pango/src/layout.ccg: get_iter(): Use the LayoutIter copy constructor 
+	instead of the crappy old assign_gobj() function. Also deprecate this 
+	method, adding a get_iter(void), now that the copy constructor allows us to 
+	use LayoutIter as a return type. 
+	
+2011-01-08  Murray Cumming  <murrayc murrayc com>
+
 	Improve the generated API documentation.
 
 	* pango/src/pango_methods.defs: Regenerated with h2defs.py
diff --git a/pango/src/layout.ccg b/pango/src/layout.ccg
index 3bea5f0..9f4cd27 100644
--- a/pango/src/layout.ccg
+++ b/pango/src/layout.ccg
@@ -116,9 +116,18 @@ Rectangle Layout::get_pixel_logical_extents() const
 
 void Layout::get_iter(LayoutIter& iter)
 {
-  iter.assign_gobj(pango_layout_get_iter(gobj()));
+  PangoLayoutIter* cobject = pango_layout_get_iter(gobj());
+  iter = Glib::wrap(cobject, false /* don't take_copy */);
 }
 
+_DEPRECATE_IFDEF_START
+LayoutIter Layout::get_iter()
+{
+  PangoLayoutIter* cobject = pango_layout_get_iter(gobj());
+  return Glib::wrap(cobject, false /* don't take_copy */);
+}
+_DEPRECATE_IFDEF_END
+
 void Layout::unset_font_description()
 {
   pango_layout_set_font_description(gobj(), 0);
diff --git a/pango/src/layout.hg b/pango/src/layout.hg
index 3a77dfc..bdd2192 100644
--- a/pango/src/layout.hg
+++ b/pango/src/layout.hg
@@ -233,10 +233,20 @@ public:
   _WRAP_METHOD(SListHandle_LayoutLine get_lines(), pango_layout_get_lines)
   _WRAP_METHOD(SListHandle_ConstLayoutLine get_lines() const, pango_layout_get_lines_readonly)
   
+_DEPRECATE_IFDEF_START
   /** Gets an iterator to iterate over the visual extents of the layout.
    * @param iter Location to store the iterator.
+   *
+   * @deprecated Use the get_iter() that returns the LayoutIter instead of 
+   * using an output parameter.
    */
   void get_iter(LayoutIter& iter);
+_DEPRECATE_IFDEF_END
+  
+  /** Gets an iterator to iterate over the visual extents of the layout.
+   * @result The iterator.
+   */
+  LayoutIter get_iter();
 
 
   /** Adds the text in this LayoutLine to the current path in the
diff --git a/pango/src/layoutiter.ccg b/pango/src/layoutiter.ccg
index 7fb2eb6..82dafd2 100644
--- a/pango/src/layoutiter.ccg
+++ b/pango/src/layoutiter.ccg
@@ -25,26 +25,10 @@
 namespace Pango
 {
 
-LayoutIter::LayoutIter()
-:
-  gobject_ (0)
-{}
-
-LayoutIter::~LayoutIter()
+void LayoutIter::assign_gobj(PangoLayoutIter* /* src */)
 {
-  if(gobject_)
-    pango_layout_iter_free(gobject_);
-}
-
-void LayoutIter::assign_gobj(PangoLayoutIter* src)
-{
-  if(src != gobject_)
-  {
-    if(gobject_)
-      pango_layout_iter_free(gobject_);
-
-    gobject_ = src;
-  }
+  //We don't actually use this anymore, and it was only ever for internal use.
+  //We just have not removed it completely to avoid appearing to break the ABI.
 }
 
 Rectangle LayoutIter::get_char_extents() const
diff --git a/pango/src/layoutiter.hg b/pango/src/layoutiter.hg
index 739b248..1099b8e 100644
--- a/pango/src/layoutiter.hg
+++ b/pango/src/layoutiter.hg
@@ -32,14 +32,10 @@ namespace Pango
  */
 class LayoutIter
 {
-  _CLASS_GENERIC(LayoutIter, PangoLayoutIter)
-  _IGNORE(pango_layout_iter_free, pango_layout_iter_get_char_extents)
+  _CLASS_BOXEDTYPE(LayoutIter, PangoLayoutIter, NONE, pango_layout_iter_copy, pango_layout_iter_free)
+  _IGNORE(pango_layout_iter_copy, pango_layout_iter_free)
 
 public:
-  // There's no other ctor, and the default ctor creates an invalid object.
-  // Therefore, Pango::LayoutIter is usable only as output argument.
-  LayoutIter();
-  ~LayoutIter();
 
   _WRAP_METHOD(int get_index() const, pango_layout_iter_get_index)
   _WRAP_METHOD(LayoutRun get_run() const, pango_layout_iter_get_run)
@@ -64,6 +60,7 @@ public:
    * @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)
 
@@ -89,7 +86,7 @@ public:
    */
   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)
+  _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.
@@ -117,22 +114,12 @@ public:
 
   _WRAP_METHOD(int get_baseline() const, pango_layout_iter_get_baseline)
 
-  /// Provides access to the underlying C GObject.  
-  PangoLayoutIter*       gobj()       { return gobject_; }
-  /// Provides access to the underlying C GObject.
-  const PangoLayoutIter* gobj() const { return gobject_; }
-
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
+  /** @deprecated Use the copy constructor instead.
+   * This was only ever for internal use anyway.
+   */
   void assign_gobj(PangoLayoutIter* src);
 #endif
-
-protected:
-  PangoLayoutIter* gobject_;
-
-private:
-  // noncopyable
-  LayoutIter(const LayoutIter&);
-  LayoutIter& operator=(const LayoutIter&);
 };
 
 } //namespace Pango



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