[Xfce4-commits] <xfce4-panel:nick/gtk3> Separator: ported to GTK3
Andrzej
noreply at xfce.org
Thu Apr 11 01:26:01 CEST 2013
Updating branch refs/heads/nick/gtk3
to 2458b1e07c3aebdb086644976d9cbf2f20833b1d (commit)
from b20dbb269408fb97a98de5d62b66bb8da9e08ddc (commit)
commit 2458b1e07c3aebdb086644976d9cbf2f20833b1d
Author: Andrzej <ndrwrdck at gmail.com>
Date: Thu Apr 11 00:17:00 2013 +0100
Separator: ported to GTK3
"Dots" style separator disabled for now (not ported yet).
plugins/separator/separator.c | 99 ++++++++++++++++++++++------------------
1 files changed, 54 insertions(+), 45 deletions(-)
diff --git a/plugins/separator/separator.c b/plugins/separator/separator.c
index cf809ab..daced70 100644
--- a/plugins/separator/separator.c
+++ b/plugins/separator/separator.c
@@ -37,6 +37,7 @@
#define SEPARATOR_OFFSET (0.15)
#define SEPARATOR_SIZE (8)
#define DOTS_SIZE (6)
+#define HANDLE_SIZE (4)
@@ -48,8 +49,8 @@ static void separator_plugin_set_property (GObject
guint prop_id,
const GValue *value,
GParamSpec *pspec);
-static gboolean separator_plugin_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
+static gboolean separator_plugin_draw (GtkWidget *widget,
+ cairo_t *cr);
static void separator_plugin_construct (XfcePanelPlugin *panel_plugin);
static gboolean separator_plugin_size_changed (XfcePanelPlugin *panel_plugin,
gint size);
@@ -123,7 +124,7 @@ separator_plugin_class_init (SeparatorPluginClass *klass)
gobject_class->get_property = separator_plugin_get_property;
widget_class = GTK_WIDGET_CLASS (klass);
- widget_class->expose_event = separator_plugin_expose_event;
+ widget_class->draw = separator_plugin_draw;
plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
plugin_class->construct = separator_plugin_construct;
@@ -220,17 +221,22 @@ separator_plugin_set_property (GObject *object,
static gboolean
-separator_plugin_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
+separator_plugin_draw (GtkWidget *widget,
+ cairo_t *cr)
{
- SeparatorPlugin *plugin = XFCE_SEPARATOR_PLUGIN (widget);
- GtkAllocation *alloc = &(widget->allocation);
- GdkBitmap *bmap;
- GdkGC *gc;
- GtkStateType state = GTK_WIDGET_STATE (widget);
- gint x, y, w, h;
- gint rows, cols;
- guint i;
+ SeparatorPlugin *plugin = XFCE_SEPARATOR_PLUGIN (widget);
+ GtkAllocation alloc;
+ gint x, y, w, h;
+ gint rows, cols;
+ guint i;
+ GtkStyleContext *ctx;
+ GdkRGBA fg_rgba;
+
+ gtk_widget_get_allocation (widget, &alloc);
+
+ ctx = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (ctx, gtk_widget_get_state_flags (widget), &fg_rgba);
+ gdk_cairo_set_source_rgba (cr, &fg_rgba);
switch (plugin->style)
{
@@ -240,63 +246,65 @@ separator_plugin_expose_event (GtkWidget *widget,
break;
case SEPARATOR_PLUGIN_STYLE_SEPARATOR:
+
if (xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin)) ==
GTK_ORIENTATION_HORIZONTAL)
{
- gtk_paint_vline (widget->style,
- widget->window,
- state,
- &(event->area),
- widget, "separator",
- alloc->y + alloc->height * SEPARATOR_OFFSET,
- alloc->y + alloc->height * (1.00 - SEPARATOR_OFFSET),
- alloc->x + alloc->width / 2 - 1);
+ gtk_render_line (ctx, cr,
+ (gdouble) (alloc.width - 1.0) / 2.0,
+ (gdouble) alloc.height * SEPARATOR_OFFSET,
+ (gdouble) (alloc.width - 1.0) / 2.0,
+ (gdouble) alloc.height * (1.0 - SEPARATOR_OFFSET));
}
else
{
- gtk_paint_hline (widget->style,
- widget->window,
- state,
- &(event->area),
- widget, "separator",
- alloc->x + alloc->width * SEPARATOR_OFFSET,
- alloc->x + alloc->width * (1.00 - SEPARATOR_OFFSET),
- alloc->y + alloc->height / 2 - 1);
+ gtk_render_line (ctx, cr,
+ (gdouble) alloc.width * SEPARATOR_OFFSET,
+ (gdouble) (alloc.height - 1.0) / 2.0,
+ (gdouble) alloc.width * (1.0 - SEPARATOR_OFFSET),
+ (gdouble) (alloc.height - 1.0) / 2.0);
}
break;
case SEPARATOR_PLUGIN_STYLE_HANDLE:
- gtk_paint_handle (widget->style,
- widget->window,
- state,
- GTK_SHADOW_NONE,
- &(event->area),
- widget, "handlebox",
- alloc->x, alloc->y,
- alloc->width,
- alloc->height,
- xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin)) ==
- GTK_ORIENTATION_HORIZONTAL ? GTK_ORIENTATION_VERTICAL
- : GTK_ORIENTATION_HORIZONTAL);
+ if (xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin)) ==
+ GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_render_handle (ctx, cr,
+ (gdouble) (alloc.width - HANDLE_SIZE) / 2.0,
+ (gdouble) alloc.height * SEPARATOR_OFFSET,
+ (gdouble) HANDLE_SIZE,
+ (gdouble) alloc.height * (1.0 - 2.0 * SEPARATOR_OFFSET));
+ }
+ else
+ {
+ gtk_render_handle (ctx, cr,
+ (gdouble) alloc.width * SEPARATOR_OFFSET,
+ (gdouble) (alloc.height - HANDLE_SIZE) / 2.0,
+ (gdouble) alloc.width * (1.0 - 2.0 * SEPARATOR_OFFSET),
+ (gdouble) HANDLE_SIZE);
+ }
break;
+ /* temporarily disabled */
+#if 0
case SEPARATOR_PLUGIN_STYLE_DOTS:
if (xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin)) ==
GTK_ORIENTATION_HORIZONTAL)
{
- rows = MAX (alloc->height / DOTS_SIZE, 1);
+ rows = MAX (alloc.height / DOTS_SIZE, 1);
w = DOTS_SIZE;
h = rows * DOTS_SIZE;
}
else
{
- cols = MAX (alloc->width / DOTS_SIZE, 1);
+ cols = MAX (alloc.width / DOTS_SIZE, 1);
h = DOTS_SIZE;
w = cols * DOTS_SIZE;
}
- x = alloc->x + (alloc->width - w) / 2;
- y = alloc->y + (alloc->height - h) / 2;
+ x = alloc.x + (alloc.width - w) / 2;
+ y = alloc.y + (alloc.height - h) / 2;
for (i = 0; i < G_N_ELEMENTS (bits); i++)
{
@@ -327,6 +335,7 @@ separator_plugin_expose_event (GtkWidget *widget,
gdk_gc_set_clip_rectangle (gc, NULL);
}
break;
+#endif
}
return FALSE;
More information about the Xfce4-commits
mailing list