summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-23 14:29:26 +0100
committerinfirit <[email protected]>2014-11-23 14:29:26 +0100
commitc354cea0424964e496601074a7678995750fa275 (patch)
tree8b55e3dacebfd7479f0f5bf402732863a2db74ec
parent2a5cd7714b342b840b0d96c03eb8b94816b1cf87 (diff)
downloadmate-panel-c354cea0424964e496601074a7678995750fa275.tar.bz2
mate-panel-c354cea0424964e496601074a7678995750fa275.tar.xz
Gtk3: clock: Port to GtkStyleContext
Based on gnome-panel commit: c28ed51852a629884ce9ad8acc7924680c35854c From: Germán Póo-Caamaño <[email protected]>
-rw-r--r--applets/clock/clock.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 4d897656..4e56192d 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -262,27 +262,44 @@ static int
calculate_minimum_width (GtkWidget *widget,
const gchar *text)
{
- PangoContext *context;
+ PangoContext *pango_context;
PangoLayout *layout;
int width, height;
int focus_width = 0;
int focus_pad = 0;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *style_context;
+ GtkStateFlags state;
+ GtkBorder padding;
+#endif
- context = gtk_widget_get_pango_context (widget);
+ pango_context = gtk_widget_get_pango_context (widget);
- layout = pango_layout_new (context);
+ layout = pango_layout_new (pango_context);
pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
pango_layout_set_text (layout, text, -1);
pango_layout_get_pixel_size (layout, &width, &height);
g_object_unref (G_OBJECT (layout));
layout = NULL;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ state = gtk_widget_get_state_flags (widget);
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_padding (style_context, state, &padding);
+ gtk_style_context_get_style (style_context,
+ "focus-line-width", &focus_width,
+ "focus-padding", &focus_pad,
+ NULL);
+
+width += 2 * (focus_width + focus_pad) + padding.left + padding.right;
+#else
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
width += 2 * (focus_width + focus_pad + gtk_widget_get_style (widget)->xthickness);
+#endif
return width;
}
@@ -374,8 +391,15 @@ static int
calculate_minimum_height (GtkWidget *widget,
MatePanelAppletOrient orientation)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *style_context;
+ GtkStateFlags state;
+ GtkBorder padding;
+ const PangoFontDescription *font_desc;
+#else
GtkStyle *style;
- PangoContext *context;
+#endif
+ PangoContext *pango_context;
PangoFontMetrics *metrics;
int focus_width = 0;
int focus_pad = 0;
@@ -383,30 +407,57 @@ calculate_minimum_height (GtkWidget *widget,
int descent;
int thickness;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ state = gtk_widget_get_state_flags (widget);
+ style_context = gtk_widget_get_style_context (widget);
+ font_desc = gtk_style_context_get_font (style_context, state);
+
+ pango_context = gtk_widget_get_pango_context (widget);
+ metrics = pango_context_get_metrics (pango_context,
+ font_desc,
+ pango_context_get_language (pango_context));
+#else
style = gtk_widget_get_style (widget);
- context = gtk_widget_get_pango_context (widget);
- metrics = pango_context_get_metrics (context,
+ pango_context = gtk_widget_get_pango_context (widget);
+ metrics = pango_context_get_metrics (pango_context,
style->font_desc,
- pango_context_get_language (context));
+ pango_context_get_language (pango_context));
+#endif
ascent = pango_font_metrics_get_ascent (metrics);
descent = pango_font_metrics_get_descent (metrics);
pango_font_metrics_unref (metrics);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_style_context_get_padding (style_context, state, &padding);
+ gtk_style_context_get_style (style_context,
+ "focus-line-width", &focus_width,
+ "focus-padding", &focus_pad,
+ NULL);
+#else
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
+#endif
if (orientation == MATE_PANEL_APPLET_ORIENT_UP
|| orientation == MATE_PANEL_APPLET_ORIENT_DOWN) {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ thickness = padding.top + padding.bottom;
+#else
thickness = style->ythickness;
+#endif
} else {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ thickness = padding.left + padding.right;
+#else
thickness = style->xthickness;
+#endif
}
- return PANGO_PIXELS (ascent + descent) + 2 * (focus_width + focus_pad + thickness);
+ return PANGO_PIXELS (ascent + descent) + 2 * (focus_width + focus_pad) + thickness;
}
static gboolean