[gnome-documents] lib: add GdStyledTextRenderer
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] lib: add GdStyledTextRenderer
- Date: Mon, 5 Mar 2012 22:21:05 +0000 (UTC)
commit 5e0cd356872a76df62d403e25f70d6a1ab2a8bbf
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Feb 27 14:50:33 2012 -0500
lib: add GdStyledTextRenderer
Just a GtkCellRendererText subclass to which you can add/remove style
classes.
src/Makefile-lib.am | 2 +
src/lib/gd-styled-text-renderer.c | 124 +++++++++++++++++++++++++++++++++++++
src/lib/gd-styled-text-renderer.h | 79 +++++++++++++++++++++++
3 files changed, 205 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile-lib.am b/src/Makefile-lib.am
index 0e8463b..761cffe 100644
--- a/src/Makefile-lib.am
+++ b/src/Makefile-lib.am
@@ -17,6 +17,7 @@ gdprivate_source_h = \
lib/gd-main-view.h \
lib/gd-margin-container.h \
lib/gd-pdf-loader.h \
+ lib/gd-styled-text-renderer.h \
lib/gd-tagged-entry.h \
lib/gd-two-lines-renderer.h \
$(NULL)
@@ -31,6 +32,7 @@ gdprivate_source_c = \
lib/gd-main-view.c \
lib/gd-margin-container.c \
lib/gd-pdf-loader.c \
+ lib/gd-styled-text-renderer.c \
lib/gd-tagged-entry.c \
lib/gd-two-lines-renderer.c \
$(NULL)
diff --git a/src/lib/gd-styled-text-renderer.c b/src/lib/gd-styled-text-renderer.c
new file mode 100644
index 0000000..f52090e
--- /dev/null
+++ b/src/lib/gd-styled-text-renderer.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents 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 General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#include "gd-styled-text-renderer.h"
+
+G_DEFINE_TYPE (GdStyledTextRenderer, gd_styled_text_renderer, GTK_TYPE_CELL_RENDERER_TEXT);
+
+struct _GdStyledTextRendererPrivate {
+ GList *style_classes;
+};
+
+static void
+gd_styled_text_renderer_render (GtkCellRenderer *cell,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+{
+ GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (cell);
+ GtkStyleContext *context;
+ const gchar *style_class;
+ GList *l;
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_save (context);
+
+ for (l = self->priv->style_classes; l != NULL; l = l->next)
+ {
+ style_class = l->data;
+ gtk_style_context_add_class (context, style_class);
+ }
+
+ GTK_CELL_RENDERER_CLASS (gd_styled_text_renderer_parent_class)->render
+ (cell, cr, widget,
+ background_area, cell_area, flags);
+
+ gtk_style_context_restore (context);
+}
+
+static void
+gd_styled_text_renderer_finalize (GObject *obj)
+{
+ GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (obj);
+
+ if (self->priv->style_classes != NULL)
+ {
+ g_list_free_full (self->priv->style_classes, g_free);
+ self->priv->style_classes = NULL;
+ }
+
+ G_OBJECT_CLASS (gd_styled_text_renderer_parent_class)->finalize (obj);
+}
+
+static void
+gd_styled_text_renderer_class_init (GdStyledTextRendererClass *klass)
+{
+ GtkCellRendererClass *crclass = GTK_CELL_RENDERER_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = gd_styled_text_renderer_finalize;
+ crclass->render = gd_styled_text_renderer_render;
+
+ g_type_class_add_private (klass, sizeof (GdStyledTextRendererPrivate));
+}
+
+static void
+gd_styled_text_renderer_init (GdStyledTextRenderer *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_STYLED_TEXT_RENDERER,
+ GdStyledTextRendererPrivate);
+}
+
+GtkCellRenderer *
+gd_styled_text_renderer_new (void)
+{
+ return g_object_new (GD_TYPE_STYLED_TEXT_RENDERER,
+ NULL);
+}
+
+void
+gd_styled_text_renderer_add_class (GdStyledTextRenderer *self,
+ const gchar *class)
+{
+ if (g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0))
+ return;
+
+ self->priv->style_classes = g_list_append (self->priv->style_classes, g_strdup (class));
+}
+
+void
+gd_styled_text_renderer_remove_class (GdStyledTextRenderer *self,
+ const gchar *class)
+{
+ GList *class_element;
+
+ class_element = g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0);
+
+ if (class_element == NULL)
+ return;
+
+ self->priv->style_classes = g_list_remove_link (self->priv->style_classes,
+ class_element);
+ g_free (class_element->data);
+ g_list_free_1 (class_element);
+}
diff --git a/src/lib/gd-styled-text-renderer.h b/src/lib/gd-styled-text-renderer.h
new file mode 100644
index 0000000..3dae0c1
--- /dev/null
+++ b/src/lib/gd-styled-text-renderer.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents 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 General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#ifndef _GD_STYLED_TEXT_RENDERER_H
+#define _GD_STYLED_TEXT_RENDERER_H
+
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_STYLED_TEXT_RENDERER gd_styled_text_renderer_get_type()
+
+#define GD_STYLED_TEXT_RENDERER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRenderer))
+
+#define GD_STYLED_TEXT_RENDERER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRendererClass))
+
+#define GD_IS_STYLED_TEXT_RENDERER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ GD_TYPE_STYLED_TEXT_RENDERER))
+
+#define GD_IS_STYLED_TEXT_RENDERER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ GD_TYPE_STYLED_TEXT_RENDERER))
+
+#define GD_STYLED_TEXT_RENDERER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRendererClass))
+
+typedef struct _GdStyledTextRenderer GdStyledTextRenderer;
+typedef struct _GdStyledTextRendererClass GdStyledTextRendererClass;
+typedef struct _GdStyledTextRendererPrivate GdStyledTextRendererPrivate;
+
+struct _GdStyledTextRenderer
+{
+ GtkCellRendererText parent;
+
+ GdStyledTextRendererPrivate *priv;
+};
+
+struct _GdStyledTextRendererClass
+{
+ GtkCellRendererTextClass parent_class;
+};
+
+GType gd_styled_text_renderer_get_type (void) G_GNUC_CONST;
+
+GtkCellRenderer *gd_styled_text_renderer_new (void);
+void gd_styled_text_renderer_add_class (GdStyledTextRenderer *self,
+ const gchar *class);
+void gd_styled_text_renderer_remove_class (GdStyledTextRenderer *self,
+ const gchar *class);
+
+G_END_DECLS
+
+#endif /* _GD_STYLED_TEXT_RENDERER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]