add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / treemodelsort.ccg
1 // -*- c++ -*-
2 /* $Id: treemodelsort.ccg,v 1.2 2003/11/04 18:11:36 murrayc Exp $ */
3
4 /* Copyright 1998-2002 The gtkmm Development Team
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 #include <gtk/gtktreemodelsort.h>
22
23
24 typedef Gtk::TreeModel::Path Path; //So that the generated method implemenations can use this a return type.
25
26 namespace Gtk
27 {
28
29 TreeModel::iterator TreeModelSort::convert_child_iter_to_iter(const iterator& child_iter) const
30 {
31   TreeIter sorted_iter (const_cast<TreeModelSort*>(this));
32
33   gtk_tree_model_sort_convert_child_iter_to_iter(
34       const_cast<GtkTreeModelSort*>(gobj()), sorted_iter.gobj(),
35       const_cast<GtkTreeIter*>(child_iter.gobj()));
36
37   return sorted_iter;
38 }
39
40 TreeModel::iterator TreeModelSort::convert_iter_to_child_iter(const iterator& sorted_iter) const
41 {
42   GtkTreeModel *const child_model = gtk_tree_model_sort_get_model(const_cast<GtkTreeModelSort*>(gobj()));
43
44   TreeIter child_iter (dynamic_cast<TreeModel*>(Glib::wrap_auto((GObject*) child_model, false)));
45
46   gtk_tree_model_sort_convert_iter_to_child_iter(
47       const_cast<GtkTreeModelSort*>(gobj()), child_iter.gobj(),
48       const_cast<GtkTreeIter*>(sorted_iter.gobj()));
49
50   return child_iter;
51 }
52
53 void TreeModelSort::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
54 {
55   // Avoid two extra ref/unref cycles -- we don't store the child
56   // model pointer anywhere, so it's OK to do this _internally_.
57
58   TreeModel *const child_model = dynamic_cast<TreeModel*>(
59       Glib::wrap_auto((GObject*) gtk_tree_model_sort_get_model(gobj()), false));
60
61   TreeIter child_iter (child_model);
62
63   gtk_tree_model_sort_convert_iter_to_child_iter(
64       gobj(), child_iter.gobj(), const_cast<GtkTreeIter*>(row.gobj()));
65
66   child_model->set_value_impl(child_iter, column, value);
67 }
68
69 } // namespace Gtk
70