add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / gtkmm / treepath.cc
1 // Generated by gtkmmproc -- DO NOT MODIFY!
2
3
4 #include <gtkmm/treepath.h>
5 #include <gtkmm/private/treepath_p.h>
6
7 // -*- c++ -*-
8 /* $Id$ */
9
10 /* Copyright 1998-2002 The gtkmm Development Team
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Library General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with this library; if not, write to the Free
24  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #include <gtkmm/treemodel.h>
28 #include <glibmm/utility.h>
29 #include <gtk/gtktreemodel.h>
30 #include <gtk/gtktreednd.h>
31
32
33 namespace Gtk
34 {
35
36 TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
37 :
38   gobject_ (gtk_tree_path_new())
39 {
40   for(; n > 0; --n)
41     gtk_tree_path_append_index(gobject_, value);
42 }
43
44 TreePath::TreePath(const Glib::ustring& path)
45 :
46   gobject_ (gtk_tree_path_new_from_string(path.c_str()))
47 {}
48
49 TreePath::TreePath(const TreeModel::iterator& iter)
50 :
51   // The GtkTreePath* is always newly created.
52   gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())))
53 {}
54
55 TreePath& TreePath::operator=(const TreeModel::iterator& iter)
56 {
57   TreePath temp (iter);
58   swap(temp);
59   return *this;
60 }
61
62 void TreePath::clear()
63 {
64   TreePath empty_path;
65   swap(empty_path);
66 }
67
68 TreePath::size_type TreePath::size() const
69 {
70   return gtk_tree_path_get_depth(gobject_);
71 }
72
73 bool TreePath::empty() const
74 {
75   return (gtk_tree_path_get_depth(gobject_) == 0);
76 }
77
78 TreePath::reference TreePath::operator[](TreePath::size_type i)
79 {
80   int *const indices = gtk_tree_path_get_indices(gobject_);
81   return indices[i];
82 }
83
84 TreePath::const_reference TreePath::operator[](TreePath::size_type i) const
85 {
86   const int *const indices = gtk_tree_path_get_indices(gobject_);
87   return indices[i];
88 }
89
90 TreePath::iterator TreePath::begin()
91 {
92   return gtk_tree_path_get_indices(gobject_);
93 }
94
95 TreePath::iterator TreePath::end()
96 {
97   return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
98 }
99
100 TreePath::const_iterator TreePath::begin() const
101 {
102   return gtk_tree_path_get_indices(gobject_);
103 }
104
105 TreePath::const_iterator TreePath::end() const
106 {
107   return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
108 }
109
110 bool TreePath::get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr<TreeModel>& model, TreePath& path) //static 
111 {
112   GtkTreeModel* src_model = 0;
113   GtkTreePath* src_path = 0;
114   gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), &src_model, &src_path);
115
116   model = Glib::wrap(src_model, true /* take_copy=true */);
117   
118   //gtk_tree_get_row_drag_data gives us ownership of src_path.
119   path = Glib::wrap(src_path, false /* take_copy=false */);
120
121   return result;
122 }
123
124 bool TreePath::get_from_selection_data(const SelectionData& selection_data, TreePath& path) //static
125 {
126   GtkTreePath* src_path = 0;
127   gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), 0, &src_path);
128
129   //gtk_tree_get_row_drag_data gives us ownership of src_path.
130   path = Glib::wrap(src_path, false /* take_copy=false */);
131
132   return result;
133 }
134
135
136 bool TreePath::set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr<const TreeModel>& model) const
137 {
138   return gtk_tree_set_row_drag_data(selection_data.gobj(), const_cast<GtkTreeModel*>(model->gobj()), const_cast<GtkTreePath*>(gobj()));  
139 }
140
141 #ifndef GTKMM_DISABLE_DEPRECATED
142
143 Glib::ArrayHandle<int> TreePath::get_indices() const
144 {
145   // gtk_tree_path_get_indices() returns a pointer to an internal array,
146   // similar to std::string::data().  Thus the OWNERSHIP_NONE flag.
147
148   return Glib::ArrayHandle<int>(gtk_tree_path_get_indices(gobject_),
149                                 gtk_tree_path_get_depth(gobject_),
150                                 Glib::OWNERSHIP_NONE);
151 }
152 #endif // GTKMM_DISABLE_DEPRECATED
153
154   
155 } // namespace Gtk
156
157
158 namespace
159 {
160 } // anonymous namespace
161
162
163 namespace Glib
164 {
165
166 Gtk::TreePath wrap(GtkTreePath* object, bool take_copy)
167 {
168   return Gtk::TreePath(object, take_copy);
169 }
170
171 } // namespace Glib
172
173
174 namespace Gtk
175 {
176
177
178 // static
179 GType TreePath::get_type()
180 {
181   return gtk_tree_path_get_type();
182 }
183
184 TreePath::TreePath()
185 :
186   gobject_ (gtk_tree_path_new())
187 {}
188
189 TreePath::TreePath(const TreePath& other)
190 :
191   gobject_ ((other.gobject_) ? gtk_tree_path_copy(other.gobject_) : 0)
192 {}
193
194 TreePath::TreePath(GtkTreePath* gobject, bool make_a_copy)
195 :
196   // For BoxedType wrappers, make_a_copy is true by default.  The static
197   // BoxedType wrappers must always take a copy, thus make_a_copy = true
198   // ensures identical behaviour if the default argument is used.
199   gobject_ ((make_a_copy && gobject) ? gtk_tree_path_copy(gobject) : gobject)
200 {}
201
202 TreePath& TreePath::operator=(const TreePath& other)
203 {
204   TreePath temp (other);
205   swap(temp);
206   return *this;
207 }
208
209 TreePath::~TreePath()
210 {
211   if(gobject_)
212     gtk_tree_path_free(gobject_);
213 }
214
215 void TreePath::swap(TreePath& other)
216 {
217   GtkTreePath *const temp = gobject_;
218   gobject_ = other.gobject_;
219   other.gobject_ = temp;
220 }
221
222 GtkTreePath* TreePath::gobj_copy() const
223 {
224   return gtk_tree_path_copy(gobject_);
225 }
226
227
228 void TreePath::push_back(int index)
229 {
230 gtk_tree_path_append_index(gobj(), index); 
231 }
232
233 void TreePath::push_front(int index)
234 {
235 gtk_tree_path_prepend_index(gobj(), index); 
236 }
237
238 void TreePath::next()
239 {
240 gtk_tree_path_next(gobj()); 
241 }
242
243 bool TreePath::prev()
244 {
245   return gtk_tree_path_prev(gobj());
246 }
247
248 bool TreePath::up()
249 {
250   return gtk_tree_path_up(gobj());
251 }
252
253 void TreePath::down()
254 {
255 gtk_tree_path_down(gobj()); 
256 }
257
258 bool TreePath::is_ancestor(const TreePath& descendant) const
259 {
260   return gtk_tree_path_is_ancestor(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((descendant).gobj()));
261 }
262
263 bool TreePath::is_descendant(const TreePath& ancestor) const
264 {
265   return gtk_tree_path_is_descendant(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((ancestor).gobj()));
266 }
267
268 Glib::ustring TreePath::to_string() const
269 {
270   return Glib::convert_return_gchar_ptr_to_ustring(gtk_tree_path_to_string(const_cast<GtkTreePath*>(gobj())));
271 }
272
273
274 bool operator==(const TreePath& lhs, const TreePath& rhs)
275 {
276   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) == 0);
277 }
278
279 bool operator!=(const TreePath& lhs, const TreePath& rhs)
280 {
281   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) != 0);
282 }
283
284 bool operator<(const TreePath& lhs, const TreePath& rhs)
285 {
286   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) < 0);
287 }
288
289 bool operator>(const TreePath& lhs, const TreePath& rhs)
290 {
291   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) > 0);
292 }
293
294 bool operator<=(const TreePath& lhs, const TreePath& rhs)
295 {
296   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) <= 0);
297 }
298
299 bool operator>=(const TreePath& lhs, const TreePath& rhs)
300 {
301   return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) >= 0);
302 }
303
304
305 #ifndef GTKMM_DISABLE_DEPRECATED
306
307 void TreePath::append_index(int index)
308 {
309 gtk_tree_path_append_index(gobj(), index); 
310 }
311
312 #endif // GTKMM_DISABLE_DEPRECATED
313
314 #ifndef GTKMM_DISABLE_DEPRECATED
315
316 void TreePath::prepend_index(int index)
317 {
318 gtk_tree_path_prepend_index(gobj(), index); 
319 }
320
321 #endif // GTKMM_DISABLE_DEPRECATED
322
323 #ifndef GTKMM_DISABLE_DEPRECATED
324
325 int TreePath::get_depth() const
326 {
327   return gtk_tree_path_get_depth(const_cast<GtkTreePath*>(gobj()));
328 }
329
330 #endif // GTKMM_DISABLE_DEPRECATED
331
332
333 } // namespace Gtk
334
335