talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit e342a1632a128138f4f986a6b0be71eb2ec449ca
parent 914c2e3b3ac39e68ed9f120e6f4f720fd1b8acec
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Sat,  3 Nov 2018 19:10:24 +0100

Added colorlabel_get/set_combobox_colormenu_active().

Diffstat:
Msrc/gtk/colorlabel.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/gtk/colorlabel.h | 10++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/gtk/colorlabel.c b/src/gtk/colorlabel.c @@ -512,3 +512,49 @@ void colorlabel_refill_combobox_colormenu(GtkComboBox *combobox) -1); } } + +gint colorlabel_get_combobox_colormenu_active(GtkComboBox *combobox) +{ + gint value; + GtkTreeIter iter; + GtkTreeModel *model; + + cm_return_val_if_fail(combobox != NULL, 0); + + if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combobox), &iter)) + return 0; + + model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)); + gtk_tree_model_get(model, &iter, + COLORMENU_COL_ID, &value, + -1); + + return value + 1; +} + +void colorlabel_set_combobox_colormenu_active(GtkComboBox *combobox, + gint color) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint id; + + cm_return_if_fail(combobox != NULL); + + model = gtk_combo_box_get_model(combobox); + cm_return_if_fail(model != NULL); + + if (!gtk_tree_model_get_iter_first(model, &iter)) + return; + + do { + gtk_tree_model_get(model, &iter, + COLORMENU_COL_ID, &id, + -1); + + if (id == color - 1) + break; + } while (gtk_tree_model_iter_next(model, &iter)); + + gtk_combo_box_set_active_iter(combobox, &iter); +} diff --git a/src/gtk/colorlabel.h b/src/gtk/colorlabel.h @@ -59,4 +59,14 @@ GtkWidget *colorlabel_create_combobox_colormenu(void); * colors, change. */ void colorlabel_refill_combobox_colormenu(GtkComboBox *combobox); +/* Returns index of selected color in the colormenu combobox. + * 0 if "none" is selected, and 1-16 for colors 0-15. */ +gint colorlabel_get_combobox_colormenu_active(GtkComboBox *combobox); + +/* Select specified color entry in the colormenu combobox. + * The color parameter corresponds to return value of + * colorlabel_get_combobox_colormenu_active(). */ +void colorlabel_set_combobox_colormenu_active(GtkComboBox *combobox, + gint color); + #endif /* COLORLABEL_H__ */