2 /* $Id: combo.ccg,v 1.2 2003/10/17 16:18:24 murrayc Exp $ */
6 * Copyright 1998-2002 The gtkmm Development Team
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.
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.
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.
23 //These were deprecated between 1.2 and 2.0:
24 #include <gtk/gtklistitem.h>
25 #include <gtk/gtklist.h>
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>
38 namespace ComboDropDown_Helpers
41 ComboDropDownList::iterator ComboDropDownList::insert(ComboDropDownList::iterator position, const Element& item)
46 pos = g_list_position(glist(), position.node_);
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);
54 void ComboDropDownList::remove(const_reference child)
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);
62 ComboDropDownList::iterator ComboDropDownList::erase(iterator position)
64 //Check that it is a valid iterator, to a real item:
65 if ( !position.node_|| (position == end()) )
68 //Get an iterator the the next item, to return:
69 iterator next = position;
72 //Use GTK+ C function to remove it, by providing the GtkWidget*:
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);
81 } // namespace ComboList_Helpers
83 ComboDropDown::ComboDropDownList& ComboDropDown::children()
85 children_proxy_ = ComboDropDownList(gobj());
86 return children_proxy_;
89 const ComboDropDown::ComboDropDownList& ComboDropDown::children() const
91 children_proxy_ = ComboDropDownList(const_cast<GtkList*>(gobj()));
92 return children_proxy_;
101 void Combo::remove_item_string(Gtk::Item& item)
103 gtk_combo_set_item_string(gobj(), item.gobj(), 0);
106 Glib::ListHandle<Glib::ustring> Combo::get_popdown_strings() const
108 GList* popdown_strings = 0;
110 GList *const list_children =
111 gtk_container_get_children(reinterpret_cast<GtkContainer*>(gobj()->list));
113 for(const GList* node = list_children; node != 0; node = node->next)
115 GtkLabel *const label = reinterpret_cast<GtkLabel*>(
116 gtk_bin_get_child(static_cast<GtkBin*>(node->data)));
118 popdown_strings = g_list_prepend(
119 popdown_strings, const_cast<char*>(gtk_label_get_text(label)));
122 g_list_free(list_children);
123 popdown_strings = g_list_reverse(popdown_strings);
125 return Glib::ListHandle<Glib::ustring>(popdown_strings, Glib::OWNERSHIP_SHALLOW);