5 #define YUILogComponent "gtk" 6 #include <yui/Libyui_config.h> 10 #include "YGSelectionStore.h" 16 YGComboBox (YWidget *parent,
const std::string &label,
bool editable)
17 : YComboBox (NULL, label, editable),
19 GTK_TYPE_COMBO_BOX,
"has-entry", editable ? TRUE : FALSE, NULL),
22 const GType types[2] = { GDK_TYPE_PIXBUF, G_TYPE_STRING };
23 createStore (2, types);
24 gtk_combo_box_set_model (getComboBox(), getModel());
26 GtkCellRenderer* cell = gtk_cell_renderer_pixbuf_new();
27 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (getWidget()), cell, FALSE);
28 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (getWidget()), cell,
32 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (getWidget()), 1);
34 cell = gtk_cell_renderer_text_new();
35 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (getWidget()), cell, TRUE);
36 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (getWidget()), cell,
40 connect (getWidget(),
"changed", G_CALLBACK (selected_changed_cb),
this);
43 inline GtkComboBox *getComboBox()
44 {
return GTK_COMBO_BOX (getWidget()); }
47 {
return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (getWidget()))); }
51 void blockSelected() {}
53 void doAddItem (YItem *item)
57 setRowText (&iter, 0, item->iconName(), 1, item->label(),
this);
59 doSelectItem (item,
true);
62 void doSelectItem (YItem *item,
bool select)
67 getTreeIter (item, &iter);
68 gtk_combo_box_set_active_iter (getComboBox(), &iter);
72 void doDeselectAllItems()
75 gtk_combo_box_set_active (getComboBox(), -1);
78 YItem *doSelectedItem()
81 if (gtk_combo_box_get_active_iter (getComboBox(), &iter))
82 return getYItem (&iter);
88 virtual std::string text()
94 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (getWidget()));
95 return gtk_entry_get_text (GTK_ENTRY (entry));
98 if (gtk_combo_box_get_active_iter (getComboBox(), &iter))
99 gtk_tree_model_get (getModel(), &iter, 1, &str, -1);
102 std::string ret (str);
107 virtual void setText (
const std::string &value)
111 if (findLabel (1, value, &iter))
112 gtk_combo_box_set_active_iter (getComboBox(), &iter);
114 gtk_entry_set_text (getEntry(), value.c_str());
117 virtual void setInputMaxLength (
int length)
119 YComboBox::setInputMaxLength (length);
120 gtk_entry_set_width_chars (getEntry(), length);
123 virtual void setValidChars (
const std::string &validChars)
125 YComboBox::setValidChars (validChars);
126 YGUtils::setFilter (getEntry(), validChars);
130 static void selected_changed_cb (GtkComboBox *widget,
YGComboBox *pThis)
131 { pThis->emitEvent (YEvent::ValueChanged); }
133 YGLABEL_WIDGET_IMPL (YComboBox)
134 YGSELECTION_WIDGET_IMPL (YComboBox)
137 YComboBox *YGWidgetFactory::createComboBox (YWidget *parent,
const std::string &label,
bool editable)
139 return new YGComboBox (parent, label, editable);