Code

New widget helperclass for Gtk:Entry
[inkscape.git] / src / ui / widget / combo-text.cpp
1 /* Glom
2  *
3  * Copyright (C) 2001-2004 Murray Cumming
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include "combo-text.h"
26 #include <gtk/gtkcombobox.h>
28 ComboText::ComboText()
29     : Gtk::ComboBox()
30 {
31     m_model = Gtk::ListStore::create(m_text_columns);
32     set_model(m_model);
33     pack_start(m_text_columns.m_column);
34 }
37 ComboText::~ComboText()
38 {
39   
40 }
42 void ComboText::append_text(const Glib::ustring& text)
43 {
44     gtk_combo_box_append_text(gobj(), text.c_str());
45 }
47 void ComboText::insert_text(int position, const Glib::ustring& text)
48 {
49     gtk_combo_box_insert_text(gobj(), position, text.c_str());
50 }
52 void ComboText::prepend_text(const Glib::ustring& text)
53 {
54     gtk_combo_box_prepend_text(gobj(), text.c_str());
55 }
57 Glib::ustring ComboText::get_active_text() const
58 {
59     Glib::ustring result;
61     //Get the active row:
62     Gtk::TreeModel::iterator active_row = get_active();
63     if(active_row)
64     {
65         Gtk::TreeModel::Row row = *active_row;
66         result = row[m_text_columns.m_column];
67     }
69     return result;
70 }
72 void ComboText::clear_text()
73 {
74     m_model->clear();
75 }
77 void ComboText::set_active_text(const Glib::ustring& text)
78 {
79     for(Gtk::TreeModel::iterator iter = m_model->children().begin(); iter != m_model->children().end(); ++iter)
80     {
81         Glib::ustring this_text = (*iter)[m_text_columns.m_column];
83         if(this_text == text)
84         {
85             set_active(iter);
86             return; //success
87         }
88     }
90     //Not found, so mark it as blank:
91     unset_active();
92 }