1 /**
2 * \brief Simplified management of enumerations in the UI as combobox.
3 *
4 * Authors:
5 * Nicholas Bishop <nicholasbishop@gmail.com>
6 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
7 *
8 * Copyright (C) 2007 Authors
9 *
10 * Released under GNU GPL. Read the file 'COPYING' for more information.
11 */
13 #ifndef INKSCAPE_UI_WIDGET_COMBO_ENUMS_H
14 #define INKSCAPE_UI_WIDGET_COMBO_ENUMS_H
16 #include <gtkmm/combobox.h>
17 #include <gtkmm/liststore.h>
18 #include "util/enums.h"
20 namespace Inkscape {
21 namespace UI {
22 namespace Widget {
24 template<typename E> class ComboBoxEnum : public Gtk::ComboBox
25 {
26 public:
27 ComboBoxEnum(const Util::EnumDataConverter<E>& c)
28 : _converter(c)
29 {
30 _model = Gtk::ListStore::create(_columns);
31 set_model(_model);
33 pack_start(_columns.label);
35 // Initialize list
36 for(int i = 0; i < _converter.end; ++i) {
37 Gtk::TreeModel::Row row = *_model->append();
38 const Util::EnumData<E>* data = &_converter.data(i);
39 row[_columns.data] = data;
40 row[_columns.label] = _converter.get_label(data->id);
41 }
43 set_active(0);
44 }
46 const Util::EnumData<E>* get_active_data()
47 {
48 Gtk::TreeModel::iterator i = this->get_active();
49 if(i)
50 return (*i)[_columns.data];
51 return 0;
52 }
54 void add_row(const Glib::ustring& s)
55 {
56 Gtk::TreeModel::Row row = *_model->append();
57 row[_columns.data] = 0;
58 row[_columns.label] = s;
59 }
60 private:
61 class Columns : public Gtk::TreeModel::ColumnRecord
62 {
63 public:
64 Columns()
65 {
66 add(data);
67 add(label);
68 }
70 Gtk::TreeModelColumn<const Util::EnumData<E>*> data;
71 Gtk::TreeModelColumn<Glib::ustring> label;
72 };
74 Columns _columns;
75 Glib::RefPtr<Gtk::ListStore> _model;
76 const Util::EnumDataConverter<E>& _converter;
77 };
79 }
80 }
81 }
83 #endif
85 /*
86 Local Variables:
87 mode:c++
88 c-file-style:"stroustrup"
89 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
90 indent-tabs-mode:nil
91 fill-column:99
92 End:
93 */
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :