2011-02-27 09:11:01 +00:00
|
|
|
static void ComboBox_change(ComboBox *self) {
|
2012-04-24 13:13:42 +00:00
|
|
|
if(self->p.locked == false) {
|
|
|
|
self->state.selection = self->selection();
|
|
|
|
if(self->onChange) self->onChange();
|
|
|
|
}
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::append(const string &text) {
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text);
|
|
|
|
if(itemCounter++ == 0) setSelection(0);
|
|
|
|
}
|
|
|
|
|
2011-04-30 13:12:15 +00:00
|
|
|
Geometry pComboBox::minimumGeometry() {
|
|
|
|
unsigned maximumWidth = 0;
|
2012-04-24 13:13:42 +00:00
|
|
|
for(auto &item : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(widget.state.font, item).width);
|
2011-04-30 13:12:15 +00:00
|
|
|
|
2012-04-24 13:13:42 +00:00
|
|
|
Geometry geometry = pFont::geometry(widget.state.font, " ");
|
2011-08-20 14:40:44 +00:00
|
|
|
return { 0, 0, maximumWidth + 44, geometry.height + 12 };
|
2011-04-30 13:12:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 12:49:39 +00:00
|
|
|
void pComboBox::modify(unsigned row, const string &text) {
|
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row);
|
|
|
|
gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkWidget), row, text);
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), position);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::remove(unsigned row) {
|
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row);
|
|
|
|
if(position == row) gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), 0);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2011-02-27 09:11:01 +00:00
|
|
|
void pComboBox::reset() {
|
|
|
|
locked = true;
|
2011-08-20 14:40:44 +00:00
|
|
|
gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(gtkWidget))));
|
2011-02-27 09:11:01 +00:00
|
|
|
itemCounter = 0;
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned pComboBox::selection() {
|
|
|
|
return gtk_combo_box_get_active(GTK_COMBO_BOX(gtkWidget));
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::setSelection(unsigned row) {
|
|
|
|
locked = true;
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), row);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::constructor() {
|
|
|
|
itemCounter = 0;
|
|
|
|
gtkWidget = gtk_combo_box_new_text();
|
|
|
|
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox);
|
2012-04-24 13:13:42 +00:00
|
|
|
|
|
|
|
locked = true;
|
|
|
|
for(auto &text : comboBox.state.text) append(text);
|
|
|
|
locked = false;
|
|
|
|
setSelection(comboBox.state.selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::destructor() {
|
|
|
|
gtk_widget_destroy(gtkWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|