2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
static void ComboButton_change(ComboButton* self) {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(!self->p.locked) {
|
|
|
|
self->state.selection = gtk_combo_box_get_active(GTK_COMBO_BOX(self->p.gtkWidget));
|
2011-09-05 03:48:23 +00:00
|
|
|
if(self->onChange) self->onChange();
|
|
|
|
}
|
2011-02-24 09:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-05 09:21:30 +00:00
|
|
|
void pComboButton::append(string text) {
|
2011-02-24 09:27:21 +00:00
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text);
|
2013-11-28 10:29:01 +00:00
|
|
|
if(itemCounter++ == 0) comboButton.setSelection(0);
|
2011-02-24 09:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
Size pComboButton::minimumSize() {
|
2011-03-22 12:56:49 +00:00
|
|
|
unsigned maximumWidth = 0;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& item : comboButton.state.text) maximumWidth = max(maximumWidth, pFont::size(widget.state.font, item).width);
|
2011-03-22 12:56:49 +00:00
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
Size size = pFont::size(widget.state.font, " ");
|
|
|
|
return {maximumWidth + 44, size.height + 12};
|
2011-03-22 12:56:49 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::remove(unsigned selection) {
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = true;
|
2013-11-28 10:29:01 +00:00
|
|
|
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), selection);
|
|
|
|
itemCounter--;
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = false;
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
//when removing the actively selected item, reset the selection to the first entry
|
|
|
|
if(selection == comboButton.state.selection) comboButton.setSelection(0);
|
2012-06-25 12:49:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::reset() {
|
2011-02-24 09:27:21 +00:00
|
|
|
locked = true;
|
2011-08-06 14:03:52 +00:00
|
|
|
gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(gtkWidget))));
|
2011-02-24 09:27:21 +00:00
|
|
|
itemCounter = 0;
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::setSelection(unsigned selection) {
|
|
|
|
locked = true;
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), selection);
|
|
|
|
locked = false;
|
2011-02-24 09:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::setText(unsigned selection, string text) {
|
2011-02-24 09:27:21 +00:00
|
|
|
locked = true;
|
2013-11-28 10:29:01 +00:00
|
|
|
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), selection);
|
|
|
|
gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkWidget), selection, text);
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), comboButton.state.selection);
|
2011-02-24 09:27:21 +00:00
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::constructor() {
|
2011-02-24 09:27:21 +00:00
|
|
|
itemCounter = 0;
|
|
|
|
gtkWidget = gtk_combo_box_new_text();
|
2013-03-15 13:11:33 +00:00
|
|
|
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboButton_change), (gpointer)&comboButton);
|
2011-09-05 03:48:23 +00:00
|
|
|
|
|
|
|
locked = true;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& text : comboButton.state.text) append(text);
|
2011-09-05 03:48:23 +00:00
|
|
|
locked = false;
|
2013-03-15 13:11:33 +00:00
|
|
|
setSelection(comboButton.state.selection);
|
2011-09-05 03:48:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::destructor() {
|
2011-09-05 03:48:23 +00:00
|
|
|
gtk_widget_destroy(gtkWidget);
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::orphan() {
|
2011-09-05 03:48:23 +00:00
|
|
|
destructor();
|
|
|
|
constructor();
|
2011-02-24 09:27:21 +00:00
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
}
|