[Commits] [SCM] claws branch, gtk3, updated. 3.16.0-445-gf4fd5a6
ticho at claws-mail.org
ticho at claws-mail.org
Sat Nov 3 18:48:12 CET 2018
The branch, gtk3 has been updated
via f4fd5a6ccc3f0e419b43d9282af6157f90d68c52 (commit)
from 25fc65e755ad2b04cd35a55286265dffd2ab927b (commit)
Summary of changes:
src/gtk/colorlabel.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/gtk/colorlabel.h | 16 ++++++++
2 files changed, 126 insertions(+)
- Log -----------------------------------------------------------------
commit f4fd5a6ccc3f0e419b43d9282af6157f90d68c52
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Sat Nov 3 18:39:24 2018 +0100
New color selection menu, based on GtkComboBox.
diff --git a/src/gtk/colorlabel.c b/src/gtk/colorlabel.c
index b1a5c4e..c509c28 100644
--- a/src/gtk/colorlabel.c
+++ b/src/gtk/colorlabel.c
@@ -220,6 +220,25 @@ static GtkWidget *colorlabel_create_color_widget(GdkRGBA *color)
return widget;
}
+static GdkPixbuf *colorlabel_create_colormenu_pixbuf(GdkRGBA *color)
+{
+ GdkPixbuf *pixbuf;
+ guint32 pixel = 0;
+
+ cm_return_val_if_fail(color != NULL, NULL);
+
+ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
+ LABEL_COLOR_WIDTH - 2, LABEL_COLOR_HEIGHT - 4);
+
+ /* "pixel" needs to be set to 0xrrggbb00 */
+ pixel += (guint32)(color->red * 255) << 24;
+ pixel += (guint32)(color->green * 255) << 16;
+ pixel += (guint32)(color->blue * 255) << 8;
+ gdk_pixbuf_fill(pixbuf, pixel);
+
+ return pixbuf;
+}
+
/* XXX: colorlabel_recreate_XXX are there to make sure everything
* is initialized ok, without having to call a global _xxx_init_
* function */
@@ -402,3 +421,94 @@ guint colorlabel_get_color_menu_active_item(GtkWidget *menu)
(g_object_get_data(G_OBJECT(menuitem), "color"));
return color;
}
+
+static gboolean colormenu_separator_func(GtkTreeModel *model,
+ GtkTreeIter *iter, gpointer data)
+{
+ gchar *txt;
+
+ gtk_tree_model_get(model, iter, COLORMENU_COL_TEXT, &txt, -1);
+
+ if (txt == NULL)
+ return TRUE;
+
+ return FALSE;
+}
+
+GtkWidget *colorlabel_create_combobox_colormenu()
+{
+ GtkWidget *combobox;
+ GtkListStore *store;
+ GtkCellRenderer *renderer;
+
+ store = gtk_list_store_new(3,
+ GDK_TYPE_PIXBUF,
+ G_TYPE_STRING,
+ G_TYPE_INT);
+ combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
+
+ gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combobox),
+ (GtkTreeViewRowSeparatorFunc)colormenu_separator_func,
+ NULL, NULL);
+
+ renderer = gtk_cell_renderer_pixbuf_new();
+ gtk_cell_renderer_set_padding(renderer, 2, 0);
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox),
+ renderer, FALSE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox),
+ renderer,
+ "pixbuf", COLORMENU_COL_PIXBUF,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox),
+ renderer, TRUE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox),
+ renderer,
+ "text", COLORMENU_COL_TEXT,
+ NULL);
+
+ colorlabel_refill_combobox_colormenu(GTK_COMBO_BOX(combobox));
+
+ return combobox;
+}
+
+void colorlabel_refill_combobox_colormenu(GtkComboBox *combobox)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+ gint i;
+
+ cm_return_if_fail(combobox != NULL);
+
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(combobox));
+
+ cm_return_if_fail(store != NULL);
+
+ gtk_list_store_clear(store);
+
+ /* "None" */
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ COLORMENU_COL_PIXBUF, NULL,
+ COLORMENU_COL_TEXT, _("None"),
+ COLORMENU_COL_ID, -1,
+ -1);
+ /* Separator */
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ COLORMENU_COL_PIXBUF, NULL,
+ COLORMENU_COL_TEXT, NULL,
+ COLORMENU_COL_ID, -1,
+ -1);
+
+ /* Menu items for individual colors */
+ for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ COLORMENU_COL_PIXBUF, colorlabel_create_colormenu_pixbuf(&label_colors[0][i].color),
+ COLORMENU_COL_TEXT, label_colors[0][i].label,
+ COLORMENU_COL_ID, i,
+ -1);
+ }
+}
diff --git a/src/gtk/colorlabel.h b/src/gtk/colorlabel.h
index d28deef..e593a46 100644
--- a/src/gtk/colorlabel.h
+++ b/src/gtk/colorlabel.h
@@ -30,6 +30,14 @@
#define SUMMARY_COLORMENU 1
#define NUM_MENUS 2
+/* Columns for model used in GtkComboBox color menu */
+typedef enum {
+ COLORMENU_COL_PIXBUF,
+ COLORMENU_COL_TEXT,
+ COLORMENU_COL_ID,
+ NUM_COLORMENU_COLS
+} ColorMenuColumn;
+
void colorlabel_update_colortable_from_prefs(void);
gint colorlabel_get_color_count (void);
GdkRGBA colorlabel_get_color (gint color_index);
@@ -43,4 +51,12 @@ GtkWidget *colorlabel_create_check_color_menu_item
GtkWidget *colorlabel_create_color_menu (void);
guint colorlabel_get_color_menu_active_item (GtkWidget *menu);
+/* Creates a GtkComboBox with selection of configured colors */
+GtkWidget *colorlabel_create_combobox_colormenu(void);
+
+/* Resets contents of an existing combobox with matching
+ * model. Can be useful after prefs, and therefore configured
+ * colors, change. */
+void colorlabel_refill_combobox_colormenu(GtkComboBox *combobox);
+
#endif /* COLORLABEL_H__ */
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list