[gdl] Use GtkStyleContext. Fixes bug #649258
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdl] Use GtkStyleContext. Fixes bug #649258
- Date: Tue, 3 May 2011 11:26:52 +0000 (UTC)
commit eb163b0a77922a1c0a2a37c0bc0acac0f7553fbe
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue May 3 12:50:18 2011 +0200
Use GtkStyleContext. Fixes bug #649258
gdl/gdl-dock-item.c | 43 ++++++++++++++++++++++---------------------
gdl/gdl-dock-item.h | 9 ++++++---
gdl/gdl-dock-notebook.c | 29 +++++++++++++++--------------
gdl/gdl-dock-notebook.h | 7 +++++--
gdl/gdl-switcher.c | 27 +++++++++++++++++----------
gdl/gdl-switcher.h | 9 ++++++---
6 files changed, 71 insertions(+), 53 deletions(-)
---
diff --git a/gdl/gdl-dock-item.c b/gdl/gdl-dock-item.c
index 7c3473c..1eb67bf 100644
--- a/gdl/gdl-dock-item.c
+++ b/gdl/gdl-dock-item.c
@@ -187,6 +187,10 @@ struct _GdlDockItemPrivate {
gint start_x, start_y;
};
+struct _GdlDockItemClassPrivate {
+ GtkCssProvider *css;
+};
+
/* FIXME: implement the rest of the behaviors */
#define SPLIT_RATIO 0.4
@@ -194,18 +198,21 @@ struct _GdlDockItemPrivate {
/* ----- Private functions ----- */
-G_DEFINE_TYPE (GdlDockItem, gdl_dock_item, GDL_TYPE_DOCK_OBJECT);
+G_DEFINE_TYPE_WITH_CODE (GdlDockItem, gdl_dock_item, GDL_TYPE_DOCK_OBJECT,
+ g_type_add_class_private (g_define_type_id, sizeof (GdlDockItemClassPrivate)))
static void
gdl_dock_item_class_init (GdlDockItemClass *klass)
{
- static gboolean style_initialized = FALSE;
-
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GdlDockObjectClass *dock_object_class;
-
+ static const gchar style[] =
+ "* {\n"
+ "padding: 0;\n"
+ "}";
+
object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
container_class = GTK_CONTAINER_CLASS (klass);
@@ -239,6 +246,12 @@ gdl_dock_item_class_init (GdlDockItemClass *klass)
dock_object_class->dock_request = gdl_dock_item_dock_request;
dock_object_class->dock = gdl_dock_item_dock;
+ klass->has_grip = TRUE;
+ klass->dock_drag_begin = NULL;
+ klass->dock_drag_motion = NULL;
+ klass->dock_drag_end = NULL;
+ klass->set_orientation = gdl_dock_item_real_set_orientation;
+
/* properties */
/**
@@ -383,25 +396,13 @@ gdl_dock_item_class_init (GdlDockItemClass *klass)
G_TYPE_NONE,
0);
- klass->has_grip = TRUE;
- klass->dock_drag_begin = NULL;
- klass->dock_drag_motion = NULL;
- klass->dock_drag_end = NULL;
- klass->set_orientation = gdl_dock_item_real_set_orientation;
+ g_type_class_add_private (object_class, sizeof (GdlDockItemPrivate));
- if (!style_initialized)
- {
- style_initialized = TRUE;
- gtk_rc_parse_string (
- "style \"gdl-dock-item-default\" {\n"
- "xthickness = 0\n"
- "ythickness = 0\n"
- "}\n"
- "class \"GdlDockItem\" "
- "style : gtk \"gdl-dock-item-default\"\n");
- }
+ /* set the style */
+ klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GDL_TYPE_DOCK_ITEM, GdlDockItemClassPrivate);
- g_type_class_add_private (object_class, sizeof (GdlDockItemPrivate));
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, style, -1, NULL);
}
static void
diff --git a/gdl/gdl-dock-item.h b/gdl/gdl-dock-item.h
index 9f699c0..b96d8b6 100644
--- a/gdl/gdl-dock-item.h
+++ b/gdl/gdl-dock-item.h
@@ -96,9 +96,10 @@ typedef enum {
GDL_DOCK_USER_ACTION = 1 << (GDL_DOCK_OBJECT_FLAGS_SHIFT + 3)
} GdlDockItemFlags;
-typedef struct _GdlDockItem GdlDockItem;
-typedef struct _GdlDockItemClass GdlDockItemClass;
-typedef struct _GdlDockItemPrivate GdlDockItemPrivate;
+typedef struct _GdlDockItem GdlDockItem;
+typedef struct _GdlDockItemPrivate GdlDockItemPrivate;
+typedef struct _GdlDockItemClass GdlDockItemClass;
+typedef struct _GdlDockItemClassPrivate GdlDockItemClassPrivate;
struct _GdlDockItem {
GdlDockObject object;
@@ -118,6 +119,8 @@ struct _GdlDockItem {
struct _GdlDockItemClass {
GdlDockObjectClass parent_class;
+ GdlDockItemClassPrivate *priv;
+
gboolean has_grip;
/* virtuals */
diff --git a/gdl/gdl-dock-notebook.c b/gdl/gdl-dock-notebook.c
index b6fbb24..81ba6f5 100644
--- a/gdl/gdl-dock-notebook.c
+++ b/gdl/gdl-dock-notebook.c
@@ -80,6 +80,10 @@ static gboolean gdl_dock_notebook_reorder (GdlDockObject *object,
/* Class variables and definitions */
+struct _GdlDockNotebookClassPrivate {
+ GtkCssProvider *css;
+};
+
enum {
PROP_0,
PROP_PAGE
@@ -88,18 +92,21 @@ enum {
/* ----- Private functions ----- */
-G_DEFINE_TYPE (GdlDockNotebook, gdl_dock_notebook, GDL_TYPE_DOCK_ITEM);
+G_DEFINE_TYPE_WITH_CODE (GdlDockNotebook, gdl_dock_notebook, GDL_TYPE_DOCK_ITEM,
+ g_type_add_class_private (g_define_type_id, sizeof (GdlDockNotebookClassPrivate)))
static void
gdl_dock_notebook_class_init (GdlDockNotebookClass *klass)
{
- static gboolean style_initialized = FALSE;
-
GObjectClass *g_object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GdlDockObjectClass *object_class;
GdlDockItemClass *item_class;
+ static const gchar notebook_style[] =
+ "* {\n"
+ "padding: 2;\n"
+ "}";
g_object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
@@ -134,17 +141,11 @@ gdl_dock_notebook_class_init (GdlDockNotebookClass *klass)
G_PARAM_READWRITE |
GDL_DOCK_PARAM_EXPORT | GDL_DOCK_PARAM_AFTER));
- if (!style_initialized) {
- style_initialized = TRUE;
-
- gtk_rc_parse_string (
- "style \"gdl-dock-notebook-default\" {\n"
- "xthickness = 2\n"
- "ythickness = 2\n"
- "}\n"
- "widget_class \"*.GtkNotebook.GdlDockItem\" "
- "style : gtk \"gdl-dock-notebook-default\"\n");
- }
+ /* set the style */
+ klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GDL_TYPE_DOCK_NOTEBOOK, GdlDockNotebookClassPrivate);
+
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, notebook_style, -1, NULL);
}
static void
diff --git a/gdl/gdl-dock-notebook.h b/gdl/gdl-dock-notebook.h
index 285a3f6..1d8e38c 100644
--- a/gdl/gdl-dock-notebook.h
+++ b/gdl/gdl-dock-notebook.h
@@ -35,8 +35,9 @@ G_BEGIN_DECLS
#define GDL_DOCK_NOTEBOOK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_DOCK_NOTEBOOK, GdlDockNotebookClass))
/* data types & structures */
-typedef struct _GdlDockNotebook GdlDockNotebook;
-typedef struct _GdlDockNotebookClass GdlDockNotebookClass;
+typedef struct _GdlDockNotebook GdlDockNotebook;
+typedef struct _GdlDockNotebookClass GdlDockNotebookClass;
+typedef struct _GdlDockNotebookClassPrivate GdlDockNotebookClassPrivate;
struct _GdlDockNotebook {
GdlDockItem item;
@@ -44,6 +45,8 @@ struct _GdlDockNotebook {
struct _GdlDockNotebookClass {
GdlDockItemClass parent_class;
+
+ GdlDockNotebookClassPrivate *priv;
};
diff --git a/gdl/gdl-switcher.c b/gdl/gdl-switcher.c
index 62ce36a..623d437 100644
--- a/gdl/gdl-switcher.c
+++ b/gdl/gdl-switcher.c
@@ -87,7 +87,12 @@ struct _GdlSwitcherPrivate {
gboolean in_toggle;
};
-G_DEFINE_TYPE (GdlSwitcher, gdl_switcher, GTK_TYPE_NOTEBOOK)
+struct _GdlSwitcherClassPrivate {
+ GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GdlSwitcher, gdl_switcher, GTK_TYPE_NOTEBOOK,
+ g_type_add_class_private (g_define_type_id, sizeof (GdlSwitcherClassPrivate)))
#define INTERNAL_MODE(switcher) (switcher->priv->switcher_style == \
GDL_SWITCHER_STYLE_TOOLBAR ? switcher->priv->toolbar_style : \
@@ -746,6 +751,12 @@ gdl_switcher_class_init (GdlSwitcherClass *klass)
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ static const gchar button_style[] =
+ "* {\n"
+ "-GtkWidget-focus-line-width : 1;\n"
+ "-GtkWidget-focus-padding : 1;\n"
+ "padding: 0;\n"
+ "}";
container_class->forall = gdl_switcher_forall;
container_class->remove = gdl_switcher_remove;
@@ -771,14 +782,11 @@ gdl_switcher_class_init (GdlSwitcherClass *klass)
g_type_class_add_private (object_class, sizeof (GdlSwitcherPrivate));
- gtk_rc_parse_string ("style \"gdl-button-style\"\n"
- "{\n"
- "GtkWidget::focus-padding = 1\n"
- "GtkWidget::focus-line-width = 1\n"
- "xthickness = 0\n"
- "ythickness = 0\n"
- "}\n"
- "widget \"*.gdl-button\" style \"gdl-button-style\"");
+ /* set the style */
+ klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GDL_TYPE_SWITCHER, GdlSwitcherClassPrivate);
+
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
}
static void
@@ -829,7 +837,6 @@ gdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
GtkWidget *arrow;
button_widget = gtk_toggle_button_new ();
- gtk_widget_set_name (button_widget, "gdl-button");
gtk_button_set_relief (GTK_BUTTON(button_widget), GTK_RELIEF_HALF);
if (switcher->priv->show)
gtk_widget_show (button_widget);
diff --git a/gdl/gdl-switcher.h b/gdl/gdl-switcher.h
index 9fcf13e..3924d5d 100644
--- a/gdl/gdl-switcher.h
+++ b/gdl/gdl-switcher.h
@@ -37,9 +37,10 @@ G_BEGIN_DECLS
#define GDL_IS_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_SWITCHER))
#define GDL_IS_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GDL_TYPE_SWITCHER))
-typedef struct _GdlSwitcher GdlSwitcher;
-typedef struct _GdlSwitcherPrivate GdlSwitcherPrivate;
-typedef struct _GdlSwitcherClass GdlSwitcherClass;
+typedef struct _GdlSwitcher GdlSwitcher;
+typedef struct _GdlSwitcherPrivate GdlSwitcherPrivate;
+typedef struct _GdlSwitcherClass GdlSwitcherClass;
+typedef struct _GdlSwitcherClassPrivate GdlSwitcherClassPrivate;
struct _GdlSwitcher {
GtkNotebook parent;
@@ -49,6 +50,8 @@ struct _GdlSwitcher {
struct _GdlSwitcherClass {
GtkNotebookClass parent_class;
+
+ GdlSwitcherClassPrivate *priv;
};
GType gdl_switcher_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]