summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/pango/pangomm/attriter.cc
blob: 71fa57052a92dd2112e47b638b6969ee059062dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Generated by gtkmmproc -- DO NOT MODIFY!

#include <pangomm/attriter.h>
#include <pangomm/private/attriter_p.h>

/*
 *
 * Copyright 1998-1999 The Gtk-- Development Team
 * Copyright 2001      Free Software Foundation
 *
 * 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.
 */

namespace Pango
{

AttrIter::AttrIter()
:
  gobject_(0)
{}

AttrIter::AttrIter(const AttrIter& src)
:
  gobject_(src.gobject_ ? pango_attr_iterator_copy(src.gobject_) : 0)
{}

AttrIter::AttrIter(PangoAttrIterator* castitem, bool take_copy)
{
  if(take_copy)
  {
    if(castitem)
      gobject_ = pango_attr_iterator_copy(castitem);
    else
      gobject_ = 0;
  }
  else
  {
    gobject_ = castitem;
  }
}

AttrIter::~AttrIter()
{
  if(gobject_)
     pango_attr_iterator_destroy(gobject_);
}

AttrIter& AttrIter::operator=(const AttrIter& src)
{
  PangoAttrIterator *const new_gobject = (src.gobject_ ? pango_attr_iterator_copy(src.gobject_) : 0);

  if(gobject_)
     pango_attr_iterator_destroy(gobject_);
  gobject_ = new_gobject;

  return *this;
}

AttrIter& AttrIter::operator++()
{
  next();
  return *this;
}

const AttrIter AttrIter::operator++(int)
{
  AttrIter previous(*this);
  next();
  return previous;
}

/* operator bool() cannot be implemented to work properly if a Pango::AttrIter is created
 * from an already invalid PangoAttrIterator* because there is no way to validate it.
 * Otherwise the iterator can only become invalid after some call to Pango::AttrIter::next()
 * in which case gobject_ is destroyed thus marking the iterator as invalid.
 */
AttrIter::operator bool() const
{
  return (gobject_ != 0);
}

bool AttrIter::next()
{
  if(!pango_attr_iterator_next(gobj()))
  {
    pango_attr_iterator_destroy(gobject_);
    gobject_ = 0; // Mark as invalid. There is no other way to determine whether the iterator is valid later.
    return false;
  }
  else
    return true;
}

FontDescription AttrIter::get_font_desc() const
{
  FontDescription desc;
  pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), 0, 0);

  // See pango ref docs for pango_attr_iterator_get_font.
  pango_font_description_set_family(desc.gobj(), pango_font_description_get_family(desc.gobj()));

  return desc;
}

Language AttrIter::get_language() const
{
  FontDescription desc;
  PangoLanguage* language = 0;

  pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), &language, 0);

  return Language(language, true);
}

SListHandle_Attribute AttrIter::get_extra_attrs() const
{
  FontDescription desc;
  GSList* extra_attrs = 0;

  pango_attr_iterator_get_font(const_cast<PangoAttrIterator*>(gobj()), desc.gobj(), 0, &extra_attrs);

  return SListHandle_Attribute(extra_attrs, Glib::OWNERSHIP_DEEP);
}

SListHandle_Attribute AttrIter::get_attrs() const
{
  GSList* attrs = pango_attr_iterator_get_attrs( const_cast<PangoAttrIterator*>(gobj()) );
  return SListHandle_Attribute(attrs, Glib::OWNERSHIP_DEEP);
}
   

} /* namespace Pango */


namespace Glib
{

Pango::AttrIter wrap(PangoAttrIterator* object, bool take_copy)
{
  return Pango::AttrIter(object, take_copy);
}

} /* namespace Glib */


namespace
{
} // anonymous namespace


namespace Pango
{


void AttrIter::get_range(int& start, int& end) const
{
  pango_attr_iterator_range(const_cast<PangoAttrIterator*>(gobj()), &start, &end);
}

Attribute AttrIter::get_attribute(AttrType type) const
{
  return Attribute((pango_attr_iterator_get(const_cast<PangoAttrIterator*>(gobj()), ((PangoAttrType)(type)))));
}


} // namespace Pango