<title>Evolution API Reference: libedataserverui, graphical utility library</title>
<xi:include href="xml/e-book-auth-util.xml"/>
<xi:include href="xml/e-categories-dialog.xml"/>
+ <xi:include href="xml/e-cell-renderer-color.xml"/>
<xi:include href="xml/e-contact-store.xml"/>
<xi:include href="xml/e-data-server-ui-marshal.xml"/>
<xi:include href="xml/e-destination-store.xml"/>
<SECTION>
+<FILE>e-cell-renderer-color</FILE>
+<TITLE>ECellRendererColor</TITLE>
+ECellRendererColor
+e_cell_renderer_color_new
+<SUBSECTION Standard>
+E_TYPE_CELL_RENDERER_COLOR
+E_CELL_RENDERER_COLOR
+E_CELL_RENDERER_COLOR_CLASS
+E_IS_CELL_RENDERER_COLOR
+E_IS_CELL_RENDERER_COLOR_CLASS
+E_CELL_RENDERER_COLOR_GET_CLASS
+ECellRendererColorClass
+<SUBSECTION Private>
+ECellRendererColorPrivate
+e_cell_renderer_color_get_type
+</SECTION>
+
+<SECTION>
<FILE>e-tree-model-generator</FILE>
<TITLE>ETreeModelGenerator</TITLE>
ETreeModelGeneratorGenerateFunc
+2007-11-02 Matthew Barnes <mbarnes@redhat.com>
+
+ ** Fixes bug #460649
+
+ * Makefile.am:
+ Add e-cell-renderer-color.[ch].
+
+ * e-cell-renderer-color.c:
+ * e-cell-renderer-color.h:
+ New GtkCellRenderer subclass by Milan Crha renders a solid color.
+
+ * e-source-combo-box.c:
+ Display the ESource's color next to its name.
+ Patch by Milan Crha and myself.
+
2007-11-01 Matthew Barnes <mbarnes@redhat.com>
** Fixes bug #488156
e-source-selector-dialog.c \
e-source-combo-box.c \
e-source-option-menu.c \
- e-tree-model-generator.c
+ e-tree-model-generator.c \
+ e-cell-renderer-color.c
libedataserverui_1_2_la_LIBADD = \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
e-source-selector-dialog.h \
e-source-combo-box.h \
e-source-option-menu.h \
- e-tree-model-generator.h
+ e-tree-model-generator.h \
+ e-cell-renderer-color.h
# Test programs
test_source_selector_SOURCES = test-source-selector.c
--- /dev/null
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-cell-renderer-color.c
+ *
+ * Copyright (C) 2007 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-cell-renderer-color.h"
+
+#include <string.h>
+#include <glib/gi18n-lib.h>
+
+#define E_CELL_RENDERER_COLOR_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorPrivate))
+
+enum {
+ PROP_0,
+ PROP_COLOR
+};
+
+struct _ECellRendererColorPrivate {
+ GdkColor *color;
+};
+
+static gpointer parent_class;
+
+G_DEFINE_TYPE (ECellRendererColor, e_cell_renderer_color, GTK_TYPE_CELL_RENDERER)
+
+static void
+cell_renderer_color_get_size (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GdkRectangle *cell_area,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height)
+{
+ gint color_width = 16;
+ gint color_height = 16;
+ gint calc_width;
+ gint calc_height;
+
+ calc_width = (gint) cell->xpad * 2 + color_width;
+ calc_height = (gint) cell->ypad * 2 + color_height;
+
+ if (cell_area && color_width > 0 && color_height > 0) {
+ if (x_offset) {
+ *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
+ (1.0 - cell->xalign) : cell->xalign) *
+ (cell_area->width - calc_width));
+ *x_offset = MAX (*x_offset, 0);
+ }
+
+ if (y_offset) {
+ *y_offset = (cell->yalign *
+ (cell_area->height - calc_height));
+ *y_offset = MAX (*y_offset, 0);
+ }
+ } else {
+ if (x_offset) *x_offset = 0;
+ if (y_offset) *y_offset = 0;
+ }
+
+ if (width)
+ *width = calc_width;
+
+ if (height)
+ *height = calc_height;
+}
+
+static void
+cell_renderer_color_render (GtkCellRenderer *cell,
+ GdkWindow *window,
+ GtkWidget *widget,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GdkRectangle *expose_area,
+ GtkCellRendererState flags)
+{
+ ECellRendererColorPrivate *priv;
+ GdkRectangle pix_rect;
+ GdkRectangle draw_rect;
+ GdkGC *gc;
+
+ priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (cell);
+
+ if (priv->color == NULL)
+ return;
+
+ cell_renderer_color_get_size (
+ cell, widget, cell_area,
+ &pix_rect.x, &pix_rect.y,
+ &pix_rect.width, &pix_rect.height);
+
+ pix_rect.x += cell_area->x + cell->xpad;
+ pix_rect.y += cell_area->y + cell->ypad;
+ pix_rect.width -= cell->xpad * 2;
+ pix_rect.height -= cell->ypad * 2;
+
+ if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect) ||
+ !gdk_rectangle_intersect (expose_area, &draw_rect, &draw_rect))
+ return;
+
+ gdk_colormap_alloc_color (
+ gdk_colormap_get_system(), priv->color, FALSE, TRUE);
+
+ gc = gdk_gc_new (window);
+ gdk_gc_set_foreground (gc, priv->color);
+ gdk_draw_rectangle (
+ window, gc, TRUE, pix_rect.x, pix_rect.y,
+ draw_rect.width, draw_rect.height);
+ g_object_unref (gc);
+}
+
+static void
+cell_renderer_color_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ECellRendererColorPrivate *priv;
+
+ priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_COLOR:
+ if (priv->color != NULL)
+ gdk_color_free (priv->color);
+ priv->color = g_value_dup_boxed (value);
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cell_renderer_color_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ECellRendererColorPrivate *priv;
+
+ priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_COLOR:
+ g_value_set_boxed (value, priv->color);
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cell_renderer_color_finalize (GObject *object)
+{
+ ECellRendererColorPrivate *priv;
+
+ priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
+
+ if (priv->color != NULL)
+ gdk_color_free (priv->color);
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+e_cell_renderer_color_class_init (ECellRendererColorClass *class)
+{
+ GObjectClass *object_class;
+ GtkCellRendererClass *cell_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (ECellRendererColor));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = cell_renderer_color_set_property;
+ object_class->get_property = cell_renderer_color_get_property;
+ object_class->finalize = cell_renderer_color_finalize;
+
+ cell_class = GTK_CELL_RENDERER_CLASS (class);
+ cell_class->get_size = cell_renderer_color_get_size;
+ cell_class->render = cell_renderer_color_render;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_COLOR,
+ g_param_spec_boxed (
+ "color",
+ _("Color Info"),
+ _("The color to render"),
+ GDK_TYPE_COLOR,
+ G_PARAM_READWRITE));
+}
+
+static void
+e_cell_renderer_color_init (ECellRendererColor *cellcolor)
+{
+ cellcolor->priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (cellcolor);
+
+ GTK_CELL_RENDERER (cellcolor)->xpad = 4;
+}
+
+GtkCellRenderer *
+e_cell_renderer_color_new (void)
+{
+ return g_object_new (E_TYPE_CELL_RENDERER_COLOR, NULL);
+}
--- /dev/null
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-cell-renderer-color.h
+ *
+ * Copyright (C) 2007 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _E_CELL_RENDERER_COLOR_H_
+#define _E_CELL_RENDERER_COLOR_H_
+
+
+#include <glib.h>
+#include <gtk/gtkcellrenderer.h>
+
+#define E_TYPE_CELL_RENDERER_COLOR \
+ (e_cell_renderer_color_get_type ())
+#define E_CELL_RENDERER_COLOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColor))
+#define E_CELL_RENDERER_COLOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorClass))
+#define E_IS_CELL_RENDERER_COLOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_CELL_RENDERER_COLOR))
+#define E_IS_CELL_RENDERER_COLOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE ((cls), E_TYPE_CELL_RENDERER_COLOR))
+#define E_CELL_RENDERER_COLOR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ECellRendererColor ECellRendererColor;
+typedef struct _ECellRendererColorClass ECellRendererColorClass;
+typedef struct _ECellRendererColorPrivate ECellRendererColorPrivate;
+
+struct _ECellRendererColor {
+ GtkCellRenderer parent;
+ ECellRendererColorPrivate *priv;
+};
+
+struct _ECellRendererColorClass {
+ GtkCellRendererClass parent_class;
+
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+};
+
+GType e_cell_renderer_color_get_type (void);
+GtkCellRenderer *e_cell_renderer_color_new (void);
+
+G_END_DECLS
+
+#endif /* _E_CELL_RENDERER_COLOR_H_ */
#endif
#include "e-source-combo-box.h"
+#include "e-cell-renderer-color.h"
#define E_SOURCE_COMBO_BOX_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
};
enum {
+ COLUMN_COLOR, /* GDK_TYPE_COLOR */
COLUMN_NAME, /* G_TYPE_STRING */
COLUMN_SENSITIVE, /* G_TYPE_BOOLEAN */
COLUMN_SOURCE, /* G_TYPE_OBJECT */
+ COLUMN_VISIBLE, /* G_TYPE_BOOLEAN */
NUM_COLUMNS
};
const gchar *name;
const gchar *uid;
gchar *indented_name;
+ gboolean visible = FALSE;
+ gboolean iter_valid;
priv = source_combo_box->priv;
g_hash_table_remove_all (priv->uid_index);
gtk_list_store_append (store, &iter);
gtk_list_store_set (
store, &iter,
+ COLUMN_COLOR, NULL,
COLUMN_NAME, name,
COLUMN_SENSITIVE, FALSE,
COLUMN_SOURCE, groups->data,
for (sources = e_source_group_peek_sources (groups->data);
sources != NULL; sources = sources->next) {
+ const gchar *color_spec;
+ GdkColor color;
name = e_source_peek_name (sources->data);
indented_name = g_strconcat (" ", name, NULL);
+
+ color_spec = e_source_peek_color_spec (sources->data);
+ if (color_spec != NULL) {
+ gdk_color_parse (color_spec, &color);
+ visible = TRUE;
+ }
+
gtk_list_store_append (store, &iter);
gtk_list_store_set (
store, &iter,
+ COLUMN_COLOR, color_spec ? &color : NULL,
COLUMN_NAME, indented_name,
COLUMN_SENSITIVE, TRUE,
COLUMN_SOURCE, sources->data,
-1);
- g_free (indented_name);
uid = e_source_peek_uid (sources->data);
path = gtk_tree_model_get_path (model, &iter);
priv->uid_index, g_strdup (uid),
gtk_tree_row_reference_new (model, path));
gtk_tree_path_free (path);
+
+ g_free (indented_name);
}
}
+
+ /* Set the visible column based on whether we've seen a color. */
+ iter_valid = gtk_tree_model_get_iter_first (model, &iter);
+ while (iter_valid) {
+ gtk_list_store_set (
+ store, &iter, COLUMN_VISIBLE, visible, -1);
+ iter_valid = gtk_tree_model_iter_next (model, &iter);
+ }
}
static GObject *
type, n_construct_properties, construct_properties);
store = gtk_list_store_new (
- NUM_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_OBJECT);
+ NUM_COLUMNS,
+ GDK_TYPE_COLOR, /* COLUMN_COLOR */
+ G_TYPE_STRING, /* COLUMN_NAME */
+ G_TYPE_BOOLEAN, /* COLUMN_SENSITIVE */
+ G_TYPE_OBJECT, /* COLUMN_SOURCE */
+ G_TYPE_BOOLEAN); /* COLUMN_VISIBLE */
gtk_combo_box_set_model (
GTK_COMBO_BOX (object), GTK_TREE_MODEL (store));
+ renderer = e_cell_renderer_color_new ();
+ gtk_cell_layout_pack_start (
+ GTK_CELL_LAYOUT (object), renderer, FALSE);
+ gtk_cell_layout_set_attributes (
+ GTK_CELL_LAYOUT (object), renderer,
+ "color", COLUMN_COLOR,
+ "sensitive", COLUMN_SENSITIVE,
+ "visible", COLUMN_VISIBLE,
+ NULL);
+
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (
GTK_CELL_LAYOUT (object), renderer, TRUE);
}
static void
-e_source_combo_box_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
+e_source_combo_box_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
ESourceComboBoxPrivate *priv;
}
static void
-e_source_combo_box_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+e_source_combo_box_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
ESourceComboBoxPrivate *priv;