1 /*
2
3 This file is from Nitrogen, an X11 background setter.
4 Copyright (C) 2006 Dave Foster & Javeed Shaikh
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 */
21
22 #include "ImageCombo.h"
23
24 /**
25 * Constructor, initializes renderers, columns, etc
26 */
ImageCombo()27 ImageCombo::ImageCombo() {
28
29 // add tmcs to the record
30 this->colrecord.add( this->tmc_image );
31 this->colrecord.add( this->tmc_desc );
32 this->colrecord.add( this->tmc_data );
33
34 // init liststore
35 this->store = Gtk::ListStore::create( this->colrecord );
36 this->set_model( store );
37
38 this->pack_start( this->rend_img, FALSE );
39 this->pack_start( this->rend_text );
40
41 this->add_attribute( this->rend_text, "text", 1 );
42 this->add_attribute( this->rend_img, "pixbuf", 0 );
43
44 }
45
46 /**
47 * Do nothing!
48 */
~ImageCombo()49 ImageCombo::~ImageCombo() {
50
51 }
52
53 /**
54 * Adds a row to the combo box.
55 *
56 * @param img The pixbuf to show for this row
57 * @param desc The text label to display alongside it
58 * @param data Textual data to store in this row
59 * @param active Whether to set this row as active or not
60 */
add_image_row(Glib::RefPtr<Gdk::Pixbuf> img,Glib::ustring desc,Glib::ustring data,bool active)61 void ImageCombo::add_image_row(Glib::RefPtr<Gdk::Pixbuf> img, Glib::ustring desc, Glib::ustring data, bool active) {
62
63 Gtk::TreeModel::iterator iter = this->store->append ();
64 Gtk::TreeModel::Row row = *iter;
65
66 row[this->tmc_image] = img;
67 row[this->tmc_desc] = desc;
68 row[this->tmc_data] = data;
69
70 if ( active )
71 this->set_active(iter);
72 }
73
74 /**
75 * Returns the data field of the selected row.
76 *
77 * @return Exactly what I said above.
78 */
get_active_data()79 Glib::ustring ImageCombo::get_active_data() {
80 Gtk::TreeModel::Row arow = *(this->get_active());
81 return arow[this->tmc_data];
82 }
83
84 /**
85 * Selects the entry with the value specified.
86 *
87 * @param value The value to search for and select.
88 * @returns If the value was able to be set.
89 */
select_value(Glib::ustring value)90 bool ImageCombo::select_value(Glib::ustring value)
91 {
92 for (Gtk::TreeIter iter = store->children().begin(); iter != store->children().end(); iter++) {
93
94 if ( (*iter)[tmc_data] == value ) {
95 set_active(iter);
96 return true;
97 }
98 }
99
100 return false;
101 }
102