rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[ardour.git] / libs / gtkmm2 / gtk / src / combo.ccg
1 // -*- c++ -*-
2 /* $Id: combo.ccg,v 1.2 2003/10/17 16:18:24 murrayc Exp $ */
3
4 /* 
5  *
6  * Copyright 1998-2002 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 //These were deprecated between 1.2 and 2.0:
24 #include <gtk/gtklistitem.h>
25 #include <gtk/gtklist.h>
26
27 #include <gtk/gtkcombo.h>
28 #include <gtk/gtklabel.h>
29 #include <gtkmm/entry.h>
30 #include <gtkmm/button.h>
31 #include <gtkmm/scrolledwindow.h>
32 #include <gtkmm/window.h>
33 #include <gtkmm/item.h>
34
35 namespace Gtk
36 {
37
38 namespace ComboDropDown_Helpers
39 {
40
41 ComboDropDownList::iterator ComboDropDownList::insert(ComboDropDownList::iterator position, const Element& item)
42 {
43   int pos = -1;
44
45   if(position.node_)
46     pos = g_list_position(glist(), position.node_);
47
48   // gtk+ inserts the GList node allocated by g_list_append into the list as is!
49   gtk_list_insert_items((GtkList*)gparent(), g_list_append(0, const_cast<GtkWidget*>(item.Widget::gobj())), pos);
50
51   return --position;
52 }
53
54 void ComboDropDownList::remove(const_reference child)
55 {
56   GList child_list;
57   child_list.data = (gpointer)child.gobj();
58   child_list.next = child_list.prev = 0;
59   gtk_list_remove_items(GTK_LIST(gparent_), &child_list);
60 }
61
62 ComboDropDownList::iterator ComboDropDownList::erase(iterator position)
63 {
64   //Check that it is a valid iterator, to a real item:
65   if ( !position.node_|| (position == end()) )
66     return end();
67
68   //Get an iterator the the next item, to return:
69   iterator next = position;
70   next++;
71
72   //Use GTK+ C function to remove it, by providing the GtkWidget*:
73   GList child_list;
74   child_list.data = (gpointer)position->gobj();
75   child_list.next = child_list.prev = 0;
76   gtk_list_remove_items(GTK_LIST(gparent_), &child_list);
77
78   return next;
79 }
80
81 } // namespace ComboList_Helpers
82
83 ComboDropDown::ComboDropDownList& ComboDropDown::children()
84 {
85   children_proxy_ = ComboDropDownList(gobj());
86   return children_proxy_;
87 }
88
89 const ComboDropDown::ComboDropDownList& ComboDropDown::children() const
90 {
91   children_proxy_ = ComboDropDownList(const_cast<GtkList*>(gobj()));
92   return children_proxy_;
93 }
94
95 } // namespace Gtk
96
97
98 namespace Gtk
99 {
100
101 void Combo::remove_item_string(Gtk::Item& item)
102 {
103   gtk_combo_set_item_string(gobj(), item.gobj(), 0);
104 }
105
106 Glib::ListHandle<Glib::ustring> Combo::get_popdown_strings() const
107 {
108   GList* popdown_strings = 0;
109
110   GList *const list_children =
111       gtk_container_get_children(reinterpret_cast<GtkContainer*>(gobj()->list));
112
113   for(const GList* node = list_children; node != 0; node = node->next)
114   {
115     GtkLabel *const label = reinterpret_cast<GtkLabel*>(
116         gtk_bin_get_child(static_cast<GtkBin*>(node->data)));
117
118     popdown_strings = g_list_prepend(
119         popdown_strings, const_cast<char*>(gtk_label_get_text(label)));
120   }
121
122   g_list_free(list_children);
123   popdown_strings = g_list_reverse(popdown_strings);
124
125   return Glib::ListHandle<Glib::ustring>(popdown_strings, Glib::OWNERSHIP_SHALLOW);
126 }
127
128 } // namespace Gtk
129