3
* Copyright (C) 2001-2004 Murray Cumming
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.
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.
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.
21
#include "combobox_locale.h"
22
#include <gtk/gtkcomboboxentry.h>
23
#include <glom/libglom/data_structure/iso_codes.h>
28
ComboBox_Locale::ComboBox_Locale(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& /* refGlade */)
29
: Gtk::ComboBox(cobject)
31
m_model = Gtk::ListStore::create(m_model_columns);
34
const IsoCodes::type_list_locales list_locales = IsoCodes::get_list_of_locales();
35
for(IsoCodes::type_list_locales::const_iterator iter = list_locales.begin(); iter != list_locales.end(); ++iter)
37
Gtk::TreeModel::iterator tree_iter = m_model->append();
38
Gtk::TreeModel::Row row = *tree_iter;
40
const IsoCodes::Locale& the_locale = *iter;
41
row[m_model_columns.m_identifier] = the_locale.m_identifier;
42
row[m_model_columns.m_name] = the_locale.m_name;
45
m_model->set_sort_column(m_model_columns.m_name, Gtk::SORT_ASCENDING);
49
//Do not show the non-human-readable ID: pack_start(m_model_columns.m_identifier);
52
//Create the cell renderer manually, so we can specify the alignment:
53
Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText());
54
cell->property_xalign() = 0.0f;
56
add_attribute(cell->property_text(), m_model_columns.m_name);
60
ComboBox_Locale::~ComboBox_Locale()
65
Glib::ustring ComboBox_Locale::get_selected_locale() const
67
Gtk::TreeModel::iterator iter = get_active();
70
Gtk::TreeModel::Row row = *iter;
71
return row[m_model_columns.m_identifier];
74
return Glib::ustring();
77
void ComboBox_Locale::set_selected_locale(const Glib::ustring& locale)
79
//Look for the row with this text, and activate it:
80
Glib::RefPtr<Gtk::TreeModel> model = get_model();
83
for(Gtk::TreeModel::iterator iter = model->children().begin(); iter != model->children().end(); ++iter)
85
const Glib::ustring& this_text = (*iter)[m_model_columns.m_identifier];
87
if(this_text == locale)
95
//Not found, so mark it as blank:
96
std::cerr << "ComboBox_Locale::set_selected_locale(): locale not found in list: " << locale << std::endl;