add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / combobox.ccg
1 // -*- c++ -*-
2 /* $Id: combobox.ccg,v 1.9 2006/05/10 20:59:27 murrayc Exp $ */
3
4 /* 
5  *
6  * Copyright 2003 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <gtkmm/liststore.h>
24 #include <gtkmm/cellrenderertext.h>
25 #include <gtkmm/treeview_private.h> //For SignalProxy_RowSeparator.
26 #include <gtk/gtkcombobox.h>
27 #include <gtk/gtkcelllayout.h>
28
29 namespace Gtk
30 {
31
32 void ComboBox::unset_active()
33 {
34   gtk_combo_box_set_active(gobj(), -1 /* see GTK+ docs */);
35 }
36
37 TreeModel::iterator ComboBox::get_active()
38 {
39   Gtk::TreeModel::iterator iter;
40
41   Glib::RefPtr<Gtk::TreeModel> model = get_model();
42   if(model)
43   {
44     gtk_combo_box_get_active_iter(gobj(), iter.gobj());
45
46     //It must be given the model, because the C++ wrapper has extra information.
47     iter.set_model_gobject(model->gobj());
48   }
49   
50   return iter;
51 }
52
53 TreeModel::const_iterator ComboBox::get_active() const
54 {
55   Gtk::TreeModel::iterator iter;
56
57   Glib::RefPtr<const Gtk::TreeModel> model = get_model();
58   if(model)
59   {
60     gtk_combo_box_get_active_iter(const_cast<GtkComboBox*>(gobj()), iter.gobj());
61
62     //It must be given the model, because the C++ wrapper has extra information.
63     iter.set_model_gobject(const_cast<GtkTreeModel*>(model->gobj()));
64   }
65
66   return iter;
67 }
68
69
70 void ComboBox::set_row_separator_func(const SlotRowSeparator& slot)
71 {
72   //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
73   //It will be deleted when SignalProxy_RowSeparator_gtk_callback_destroy() is called.
74   SlotRowSeparator* slot_copy = new SlotRowSeparator(slot);
75
76   gtk_combo_box_set_row_separator_func(gobj(),
77       &TreeView_Private::SignalProxy_RowSeparator_gtk_callback, slot_copy,
78       &TreeView_Private::SignalProxy_RowSeparator_gtk_callback_destroy);
79 }
80
81 void ComboBox::unset_row_separator_func()
82 {
83   gtk_combo_box_set_row_separator_func(gobj(), 0, 0, 0 /* See C docs. */);
84 }
85
86 } // namespace Gtk
87