Remove ancient/unused flowcanvas and libglademm from repository.
[ardour.git] / libs / gtkmm2 / pango / src / attriter.ccg
1 /*
2  *
3  * Copyright 1998-1999 The Gtk-- Development Team
4  * Copyright 2001      Free Software Foundation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 namespace Pango
22 {
23
24 AttrIter::AttrIter()
25 :
26   gobject_(0)
27 {}
28
29 AttrIter::AttrIter(const AttrIter& src)
30 :
31   gobject_(src.gobject_ ? pango_attr_iterator_copy(src.gobject_) : 0)
32 {}
33
34 AttrIter::AttrIter(PangoAttrIterator* castitem, bool take_copy)
35 {
36   if(take_copy)
37   {
38     if(castitem)
39       gobject_ = pango_attr_iterator_copy(castitem);
40     else
41       gobject_ = 0;
42   }
43   else
44   {
45     gobject_ = castitem;
46   }
47 }
48
49 AttrIter::~AttrIter()
50 {
51   if(gobject_)
52      pango_attr_iterator_destroy(gobject_);
53 }
54
55 AttrIter& AttrIter::operator=(const AttrIter& src)
56 {
57   PangoAttrIterator *const new_gobject = (src.gobject_ ? pango_attr_iterator_copy(src.gobject_) : 0);
58
59   if(gobject_)
60      pango_attr_iterator_destroy(gobject_);
61   gobject_ = new_gobject;
62
63   return *this;
64 }
65
66 AttrIter& AttrIter::operator++()
67 {
68   next();
69   return *this;
70 }
71
72 const AttrIter AttrIter::operator++(int)
73 {
74   AttrIter previous(*this);
75   next();
76   return previous;
77 }
78
79 /* operator bool() cannot be implemented to work properly if a Pango::AttrIter is created
80  * from an already invalid PangoAttrIterator* because there is no way to validate it.
81  * Otherwise the iterator can only become invalid after some call to Pango::AttrIter::next()
82  * in which case gobject_ is destroyed thus marking the iterator as invalid.
83  */
84 AttrIter::operator bool() const
85 {
86   return (gobject_ != 0);
87 }
88
89 bool AttrIter::next()
90 {
91   if(!pango_attr_iterator_next(gobj()))
92   {
93     pango_attr_iterator_destroy(gobject_);
94     gobject_ = 0; // Mark as invalid. There is no other way to determine whether the iterator is valid later.
95     return false;
96   }
97   else
98     return true;
99 }
100
101 FontDescription AttrIter::get_font_desc() const
102 {
103   FontDescription desc;
104   pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), 0, 0);
105
106   // See pango ref docs for pango_attr_iterator_get_font.
107   pango_font_description_set_family(desc.gobj(), pango_font_description_get_family(desc.gobj()));
108
109   return desc;
110 }
111
112 Language AttrIter::get_language() const
113 {
114   FontDescription desc;
115   PangoLanguage* language = 0;
116
117   pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), &language, 0);
118
119   return Language(language, true);
120 }
121
122 SListHandle_Attribute AttrIter::get_extra_attrs() const
123 {
124   FontDescription desc;
125   GSList* extra_attrs = 0;
126
127   pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), 0, &extra_attrs);
128
129   return SListHandle_Attribute(extra_attrs, Glib::OWNERSHIP_DEEP);
130 }
131
132 SListHandle_Attribute AttrIter::get_attrs() const
133 {
134   GSList* attrs = pango_attr_iterator_get_attrs( const_cast<PangoAttrIterator*>(gobj()) );
135   return SListHandle_Attribute(attrs, Glib::OWNERSHIP_DEEP);
136 }
137    
138
139 } /* namespace Pango */
140
141
142 namespace Glib
143 {
144
145 Pango::AttrIter wrap(PangoAttrIterator* object, bool take_copy)
146 {
147   return Pango::AttrIter(object, take_copy);
148 }
149
150 } /* namespace Glib */
151