diff options
author | Denis Gorodnichev <[email protected]> | 2014-07-24 10:37:41 +0400 |
---|---|---|
committer | infirit <[email protected]> | 2014-11-25 18:06:24 +0100 |
commit | b25395fab6fe9ee38bc0cd359941d0a825d88451 (patch) | |
tree | e7b6720a543a00495fae1dd1423d652056bedb03 /src/ui/theme.c | |
parent | b8d8e52f0effbf76ff909f88932098d4daf4336e (diff) | |
download | marco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.bz2 marco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.xz |
merge metacity(gtk3) changes
merge metacity(gtk3) changes
fix warnings
clean up unused variables
replace UNUSED_VARIABLE by G_GNUC_UNUSED
Diffstat (limited to 'src/ui/theme.c')
-rw-r--r-- | src/ui/theme.c | 511 |
1 files changed, 360 insertions, 151 deletions
diff --git a/src/ui/theme.c b/src/ui/theme.c index 2e13fd25..a7dc8d08 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -63,6 +63,23 @@ #define __USE_XOPEN #include <math.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#define MATE_DESKTOP_USE_UNSTABLE_API +#include <libmate-desktop/mate-desktop-utils.h> +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +#define GDK_COLOR_RGBA(color) \ + ((guint32) (0xff | \ + ((int)((color).red * 255) << 24) | \ + ((int)((color).green * 255) << 16) | \ + ((int)((color).blue * 255) << 8))) + +#define GDK_COLOR_RGB(color) \ + ((guint32) (((int)((color).red * 255) << 16) | \ + ((int)((color).green * 255) << 8) | \ + ((int)((color).blue * 255)))) +#else #define GDK_COLOR_RGBA(color) \ ((guint32) (0xff | \ (((color).red / 256) << 24) | \ @@ -73,6 +90,7 @@ ((guint32) ((((color).red / 256) << 16) | \ (((color).green / 256) << 8) | \ (((color).blue / 256)))) +#endif #define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255)) @@ -80,9 +98,15 @@ #define CLAMP_UCHAR(v) ((guchar) (CLAMP (((int)v), (int)0, (int)255))) #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) +#if GTK_CHECK_VERSION (3, 0, 0) +static void gtk_style_shade (GdkRGBA *a, + GdkRGBA *b, + gdouble k); +#else static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k); +#endif static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b); @@ -95,9 +119,15 @@ static void hls_to_rgb (gdouble *h, */ static MetaTheme *meta_current_theme = NULL; +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf * +colorize_pixbuf (GdkPixbuf *orig, + GdkRGBA *new_color) +#else static GdkPixbuf * colorize_pixbuf (GdkPixbuf *orig, GdkColor *new_color) +#endif { GdkPixbuf *pixbuf; double intensity; @@ -140,16 +170,28 @@ colorize_pixbuf (GdkPixbuf *orig, if (intensity <= 0.5) { /* Go from black at intensity = 0.0 to new_color at intensity = 0.5 */ +#if GTK_CHECK_VERSION (3, 0, 0) + dr = new_color->red * intensity * 2.0; + dg = new_color->green * intensity * 2.0; + db = new_color->blue * intensity * 2.0; +#else dr = (new_color->red * intensity * 2.0) / 65535.0; dg = (new_color->green * intensity * 2.0) / 65535.0; db = (new_color->blue * intensity * 2.0) / 65535.0; +#endif } else { /* Go from new_color at intensity = 0.5 to white at intensity = 1.0 */ +#if GTK_CHECK_VERSION (3, 0, 0) + dr = new_color->red + (1.0 - new_color->red) * (intensity - 0.5) * 2.0; + dg = new_color->green + (1.0 - new_color->green) * (intensity - 0.5) * 2.0; + db = new_color->blue + (1.0 - new_color->blue) * (intensity - 0.5) * 2.0; +#else dr = (new_color->red + (65535 - new_color->red) * (intensity - 0.5) * 2.0) / 65535.0; dg = (new_color->green + (65535 - new_color->green) * (intensity - 0.5) * 2.0) / 65535.0; db = (new_color->blue + (65535 - new_color->blue) * (intensity - 0.5) * 2.0) / 65535.0; +#endif } dest[0] = CLAMP_UCHAR (255 * dr); @@ -173,6 +215,19 @@ colorize_pixbuf (GdkPixbuf *orig, return pixbuf; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +color_composite (const GdkRGBA *bg, + const GdkRGBA *fg, + double alpha, + GdkRGBA *color) +{ + *color = *bg; + color->red = color->red + (fg->red - color->red) * alpha; + color->green = color->green + (fg->green - color->green) * alpha; + color->blue = color->blue + (fg->blue - color->blue) * alpha; +} +#else static void color_composite (const GdkColor *bg, const GdkColor *fg, @@ -187,6 +242,7 @@ color_composite (const GdkColor *bg, color->green = color->green + (((fg->green - color->green) * alpha + 0x8000) >> 16); color->blue = color->blue + (((fg->blue - color->blue) * alpha + 0x8000) >> 16); } +#endif /** * Sets all the fields of a border to dummy values. @@ -939,7 +995,6 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout, else g_memmove (&(rect->clickable), &(rect->visible), sizeof(rect->clickable)); - x = rect->visible.x + rect->visible.width + layout->button_border.right; if (left_buttons_has_spacer[i]) x += (button_width * 0.75); @@ -1015,14 +1070,26 @@ meta_gradient_spec_free (MetaGradientSpec *spec) g_free (spec); } +#if GTK_CHECK_VERSION (3, 0, 0) +GdkPixbuf* +meta_gradient_spec_render (const MetaGradientSpec *spec, + GtkStyleContext *style, + int width, + int height) +#else GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *spec, - GtkWidget *widget, + GtkStyle *style, int width, int height) +#endif { int n_colors; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *colors; +#else GdkColor *colors; +#endif GSList *tmp; int i; GdkPixbuf *pixbuf; @@ -1032,13 +1099,17 @@ meta_gradient_spec_render (const MetaGradientSpec *spec, if (n_colors == 0) return NULL; +#if GTK_CHECK_VERSION (3, 0, 0) + colors = g_new (GdkRGBA, n_colors); +#else colors = g_new (GdkColor, n_colors); +#endif i = 0; tmp = spec->color_specs; while (tmp != NULL) { - meta_color_spec_render (tmp->data, widget, &colors[i]); + meta_color_spec_render (tmp->data, style, &colors[i]); tmp = tmp->next; ++i; @@ -1178,7 +1249,11 @@ meta_color_spec_new_from_string (const char *str, const char *bracket; const char *end_bracket; char *tmp; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif MetaGtkColorComponent component; bracket = str; @@ -1371,7 +1446,11 @@ meta_color_spec_new_from_string (const char *str, { spec = meta_color_spec_new (META_COLOR_SPEC_BASIC); +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gdk_rgba_parse (&spec->data.basic.color, str)) +#else if (!gdk_color_parse (str, &spec->data.basic.color)) +#endif { g_set_error (err, META_THEME_ERROR, META_THEME_ERROR_FAILED, @@ -1387,9 +1466,15 @@ meta_color_spec_new_from_string (const char *str, return spec; } +#if GTK_CHECK_VERSION (3, 0, 0) +MetaColorSpec* +meta_color_spec_new_gtk (MetaGtkColorComponent component, + GtkStateFlags state) +#else MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component, GtkStateType state) +#endif { MetaColorSpec *spec; @@ -1401,18 +1486,111 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component, return spec; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +meta_set_color_from_style (GdkRGBA *color, + GtkStyleContext *context, + GtkStateFlags state, + MetaGtkColorComponent component) +{ + GdkRGBA other; + + switch (component) + { + case META_GTK_COLOR_BG: + case META_GTK_COLOR_BASE: + gtk_style_context_get_background_color (context, state, color); + break; + case META_GTK_COLOR_FG: + case META_GTK_COLOR_TEXT: + gtk_style_context_get_color (context, state, color); + break; + case META_GTK_COLOR_TEXT_AA: + gtk_style_context_get_color (context, state, color); + meta_set_color_from_style (&other, context, state, META_GTK_COLOR_BASE); + + color->red = (color->red + other.red) / 2; + color->green = (color->green + other.green) / 2; + color->blue = (color->blue + other.blue) / 2; + break; + case META_GTK_COLOR_MID: + mate_desktop_gtk_style_get_light_color (context, state, color); + mate_desktop_gtk_style_get_dark_color (context, state, &other); + + color->red = (color->red + other.red) / 2; + color->green = (color->green + other.green) / 2; + color->blue = (color->blue + other.blue) / 2; + break; + case META_GTK_COLOR_LIGHT: + mate_desktop_gtk_style_get_light_color (context, state, color); + break; + case META_GTK_COLOR_DARK: + mate_desktop_gtk_style_get_dark_color (context, state, color); + break; + case META_GTK_COLOR_LAST: + g_assert_not_reached (); + break; + } +} +#else +static void +meta_set_color_from_style (GdkColor *color, + GtkStyle *widget_style, + GtkStateType state, + MetaGtkColorComponent component) +{ + switch (component) + { + case META_GTK_COLOR_BG: + *color = widget_style->bg[state]; + break; + case META_GTK_COLOR_FG: + *color = widget_style->fg[state]; + break; + case META_GTK_COLOR_BASE: + *color = widget_style->base[state]; + break; + case META_GTK_COLOR_TEXT: + *color = widget_style->text[state]; + break; + case META_GTK_COLOR_LIGHT: + *color = widget_style->light[state]; + break; + case META_GTK_COLOR_DARK: + *color = widget_style->dark[state]; + break; + case META_GTK_COLOR_MID: + *color = widget_style->mid[state]; + break; + case META_GTK_COLOR_TEXT_AA: + *color = widget_style->text_aa[state]; + break; + case META_GTK_COLOR_LAST: + g_assert_not_reached (); + break; + } +} +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +void +meta_color_spec_render (MetaColorSpec *spec, + GtkStyleContext *style, + GdkRGBA *color) +#else void meta_color_spec_render (MetaColorSpec *spec, - GtkWidget *widget, + GtkStyle *style, GdkColor *color) +#endif { - GtkStyle *widget_style; - g_return_if_fail (spec != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - widget_style = gtk_widget_get_style (widget); - g_return_if_fail (widget_style != NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + g_return_if_fail (GTK_IS_STYLE_CONTEXT (style)); +#else + g_return_if_fail (style != NULL); +#endif switch (spec->type) { @@ -1421,44 +1599,22 @@ meta_color_spec_render (MetaColorSpec *spec, break; case META_COLOR_SPEC_GTK: - switch (spec->data.gtk.component) - { - case META_GTK_COLOR_BG: - *color = widget_style->bg[spec->data.gtk.state]; - break; - case META_GTK_COLOR_FG: - *color = widget_style->fg[spec->data.gtk.state]; - break; - case META_GTK_COLOR_BASE: - *color = widget_style->base[spec->data.gtk.state]; - break; - case META_GTK_COLOR_TEXT: - *color = widget_style->text[spec->data.gtk.state]; - break; - case META_GTK_COLOR_LIGHT: - *color = widget_style->light[spec->data.gtk.state]; - break; - case META_GTK_COLOR_DARK: - *color = widget_style->dark[spec->data.gtk.state]; - break; - case META_GTK_COLOR_MID: - *color = widget_style->mid[spec->data.gtk.state]; - break; - case META_GTK_COLOR_TEXT_AA: - *color = widget_style->text_aa[spec->data.gtk.state]; - break; - case META_GTK_COLOR_LAST: - g_assert_not_reached (); - break; - } + meta_set_color_from_style (color, + style, + spec->data.gtk.state, + spec->data.gtk.component); break; case META_COLOR_SPEC_BLEND: { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA bg, fg; +#else GdkColor bg, fg; +#endif - meta_color_spec_render (spec->data.blend.background, widget, &bg); - meta_color_spec_render (spec->data.blend.foreground, widget, &fg); + meta_color_spec_render (spec->data.blend.background, style, &bg); + meta_color_spec_render (spec->data.blend.foreground, style, &fg); color_composite (&bg, &fg, spec->data.blend.alpha, &spec->data.blend.color); @@ -1469,7 +1625,7 @@ meta_color_spec_render (MetaColorSpec *spec, case META_COLOR_SPEC_SHADE: { - meta_color_spec_render (spec->data.shade.base, widget, + meta_color_spec_render (spec->data.shade.base, style, &spec->data.shade.color); gtk_style_shade (&spec->data.shade.color, @@ -3215,7 +3371,11 @@ scale_and_alpha_pixbuf (GdkPixbuf *src, static GdkPixbuf* draw_op_as_pixbuf (const MetaDrawOp *op, - GtkWidget *widget, +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style, +#else + GtkStyle *style, +#endif const MetaDrawInfo *info, int width, int height) @@ -3236,10 +3396,14 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_RECTANGLE: if (op->data.rectangle.filled) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif meta_color_spec_render (op->data.rectangle.color_spec, - widget, + style, &color); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, @@ -3258,12 +3422,16 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_TINT: { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif guint32 rgba; gboolean has_alpha; meta_color_spec_render (op->data.rectangle.color_spec, - widget, + style, &color); has_alpha = @@ -3306,7 +3474,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_GRADIENT: { pixbuf = meta_gradient_spec_render (op->data.gradient.gradient_spec, - widget, width, height); + style, width, height); pixbuf = apply_alpha (pixbuf, op->data.gradient.alpha_spec, @@ -3319,10 +3487,14 @@ draw_op_as_pixbuf (const MetaDrawOp *op, { if (op->data.image.colorize_spec) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif meta_color_spec_render (op->data.image.colorize_spec, - widget, &color); + style, &color); if (op->data.image.colorize_cache_pixbuf == NULL || op->data.image.colorize_cache_pixel != GDK_COLOR_RGB (color)) @@ -3430,31 +3602,6 @@ fill_env (MetaPositionExprEnv *env, env->theme = meta_current_theme; } -#if GTK_CHECK_VERSION (3, 0, 0) -static GtkStateFlags -state_flags_from_gtk_state (GtkStateType state) -{ - switch (state) - { - case GTK_STATE_NORMAL: - return 0; - case GTK_STATE_PRELIGHT: - return GTK_STATE_FLAG_PRELIGHT; - case GTK_STATE_ACTIVE: - return GTK_STATE_FLAG_ACTIVE; - case GTK_STATE_SELECTED: - return GTK_STATE_FLAG_SELECTED; - case GTK_STATE_INSENSITIVE: - return GTK_STATE_FLAG_INSENSITIVE; - case GTK_STATE_INCONSISTENT: - return GTK_STATE_FLAG_INCONSISTENT; - case GTK_STATE_FOCUSED: - return GTK_STATE_FLAG_FOCUSED; - } - return 0; -} -#endif - /* This code was originally rendering anti-aliased using X primitives, and * now has been switched to draw anti-aliased using cairo. In general, the * closest correspondence between X rendering and cairo rendering is given @@ -3470,13 +3617,9 @@ static void meta_draw_op_draw_with_env (const MetaDrawOp *op, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -3484,12 +3627,15 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, MetaRectangle rect, MetaPositionExprEnv *env) { - GdkColor color; - #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); - gtk_style_context_save(style_gtk); + GdkRGBA color; + + cairo_save (cr); + gtk_style_context_save (style_gtk); #else + GdkColor color; + GtkStyle *style_gtk = gtk_widget_get_style (widget); + cairo_t *cr; cr = gdk_cairo_create (drawable); #endif @@ -3510,8 +3656,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int x1, x2, y1, y2; - meta_color_spec_render (op->data.line.color_spec, widget, &color); + meta_color_spec_render (op->data.line.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif if (op->data.line.width > 0) cairo_set_line_width (cr, op->data.line.width); @@ -3598,8 +3748,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int rx, ry, rwidth, rheight; - meta_color_spec_render (op->data.rectangle.color_spec, widget, &color); + meta_color_spec_render (op->data.rectangle.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.rectangle.x, env); ry = parse_y_position_unchecked (op->data.rectangle.y, env); @@ -3628,8 +3782,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, double start_angle, end_angle; double center_x, center_y; - meta_color_spec_render (op->data.arc.color_spec, widget, &color); + meta_color_spec_render (op->data.arc.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.arc.x, env); ry = parse_y_position_unchecked (op->data.arc.y, env); @@ -3683,8 +3841,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, if (!needs_alpha) { - meta_color_spec_render (op->data.tint.color_spec, widget, &color); + meta_color_spec_render (op->data.tint.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif cairo_rectangle (cr, rx, ry, rwidth, rheight); cairo_fill (cr); @@ -3693,7 +3855,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { GdkPixbuf *pixbuf; - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3717,7 +3879,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.gradient.width, env); rheight = parse_size_unchecked (op->data.gradient.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3744,7 +3906,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.image.width, env); rheight = parse_size_unchecked (op->data.image.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3791,8 +3953,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, return; } - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_arrow.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_arrow.state); gtk_render_arrow (style_gtk, cr, angle, rx, ry, size); #else @@ -3821,8 +3982,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rheight = parse_size_unchecked (op->data.gtk_box.height, env); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_box.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_box.state); gtk_render_background (style_gtk, cr, rx, ry, rwidth, rheight); gtk_render_frame (style_gtk, cr, rx, ry, rwidth, rheight); #else @@ -3847,8 +4007,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, ry2 = parse_y_position_unchecked (op->data.gtk_vline.y2, env); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_vline.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_vline.state); gtk_render_line (style_gtk, cr, rx, ry1, rx, ry2); #else gtk_paint_vline (style_gtk, @@ -3870,7 +4029,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.icon.width, env); rheight = parse_size_unchecked (op->data.icon.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3891,8 +4050,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int rx, ry; - meta_color_spec_render (op->data.title.color_spec, widget, &color); + meta_color_spec_render (op->data.title.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.title.x, env); ry = parse_y_position_unchecked (op->data.title.y, env); @@ -3908,6 +4071,20 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, cairo_pattern_t *linpat; linpat = cairo_pattern_create_linear (rx, ry, text_space, env->title_height); +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_pattern_add_color_stop_rgba (linpat, 0, color.red, + color.green, + color.blue, + color.alpha); + cairo_pattern_add_color_stop_rgba (linpat, startalpha, + color.red, + color.green, + color.blue, + color.alpha); + cairo_pattern_add_color_stop_rgba (linpat, 1, color.red, + color.green, + color.blue, 0); +#else cairo_pattern_add_color_stop_rgb (linpat, 0, color.red/65535.0, color.green/65535.0, color.blue/65535.0); @@ -3918,10 +4095,15 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, cairo_pattern_add_color_stop_rgba (linpat, 1, color.red/65535.0, color.green/65535.0, color.blue/65535.0, 0); +#endif cairo_set_source(cr, linpat); cairo_pattern_destroy(linpat); } else { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif } cairo_move_to (cr, rx, ry); @@ -3939,10 +4121,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, d_rect.height = parse_size_unchecked (op->data.op_list.height, env); meta_draw_op_list_draw_with_style (op->data.op_list.op_list, - style_gtk, widget, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, clip, #endif info, d_rect); @@ -3986,7 +4169,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, while (tile.y < (ry + rheight)) { meta_draw_op_list_draw_with_style (op->data.tile.op_list, - style_gtk, widget, cr, info, + style_gtk, cr, info, tile); tile.y += tile.height; @@ -4023,7 +4206,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, while (tile.y < (ry + rheight)) { meta_draw_op_list_draw_with_style (op->data.tile.op_list, - style_gtk, widget, drawable, &new_clip, info, +#if GTK_CHECK_VERSION (3, 0, 0) + style_gtk, drawable, &new_clip, info, +#else + widget, drawable, &new_clip, info, +#endif tile); tile.y += tile.height; @@ -4047,11 +4234,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, void meta_draw_op_draw_with_style (const MetaDrawOp *op, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -4060,16 +4247,14 @@ meta_draw_op_draw_with_style (const MetaDrawOp *op, { MetaPositionExprEnv env; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - fill_env (&env, info, logical_region); - meta_draw_op_draw_with_env (op, style_gtk, widget, + meta_draw_op_draw_with_env (op, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, clip, #endif info, logical_region, @@ -4089,10 +4274,12 @@ meta_draw_op_draw (const MetaDrawOp *op, const MetaDrawInfo *info, MetaRectangle logical_region) { - meta_draw_op_draw_with_style (op, gtk_widget_get_style (widget), widget, + meta_draw_op_draw_with_style (op, #if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_get_style_context (widget), cr, #else + widget, drawable, clip, #endif info, logical_region); @@ -4147,11 +4334,11 @@ meta_draw_op_list_unref (MetaDrawOpList *op_list) void meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -4167,10 +4354,6 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, #endif MetaPositionExprEnv env; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - if (op_list->n_ops == 0) return; @@ -4189,7 +4372,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, */ #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); + cairo_save (cr); #else if (clip) { @@ -4226,10 +4409,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, } else if (gdk_cairo_get_clip_rectangle (cr, NULL)) { - meta_draw_op_draw_with_env (op, - style_gtk, widget, cr, info, - rect, - &env); + meta_draw_op_draw_with_env (op, style_gtk, cr, info, rect, &env); } #else @@ -4247,7 +4427,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, active_clip.height > 0) { meta_draw_op_draw_with_env (op, - style_gtk, widget, drawable, &active_clip, info, + widget, drawable, &active_clip, info, rect, &env); } @@ -4255,7 +4435,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, } #if GTK_CHECK_VERSION(3, 0, 0) - cairo_restore(cr); + cairo_restore (cr); #endif } @@ -4272,10 +4452,12 @@ meta_draw_op_list_draw (const MetaDrawOpList *op_list, MetaRectangle rect) { - meta_draw_op_list_draw_with_style (op_list, gtk_widget_get_style (widget), widget, + meta_draw_op_list_draw_with_style (op_list, #if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_get_style_context (widget), cr, #else + widget, drawable, clip, #endif info, rect); @@ -4644,13 +4826,9 @@ void meta_frame_style_draw_with_style (MetaFrameStyle *style, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, int x_offset, int y_offset, @@ -4676,10 +4854,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, PangoRectangle extents; MetaDrawInfo draw_info; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - titlebar_rect.x = 0; titlebar_rect.y = 0; titlebar_rect.width = fgeom->width; @@ -4831,7 +5005,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, style_gtk, - widget, cr, &draw_info, m_rect); @@ -4870,7 +5043,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, MetaRectangle m_rect; m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, - style_gtk, widget, drawable, &combined_clip, @@ -4916,7 +5088,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, meta_draw_op_list_draw_with_style (op_list, style_gtk, - widget, cr, &draw_info, m_rect); @@ -4978,7 +5149,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, - style_gtk, widget, drawable, &combined_clip, @@ -5031,13 +5201,9 @@ meta_frame_style_draw (MetaFrameStyle *style, meta_frame_style_draw_with_style (style, #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_get_style_context (widget), - #else - gtk_widget_get_style (widget), - #endif - widget, - #if GTK_CHECK_VERSION(3, 0, 0) cr, #else + widget, drawable, x_offset, y_offset, clip, #endif fgeom, client_width, client_height, @@ -5636,13 +5802,9 @@ void meta_theme_draw_frame_with_style (MetaTheme *theme, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, int x_offset, @@ -5679,11 +5841,11 @@ meta_theme_draw_frame_with_style (MetaTheme *theme, theme); meta_frame_style_draw_with_style (style, - style_gtk, - widget, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, x_offset, y_offset, clip, #endif &fgeom, @@ -5719,13 +5881,9 @@ meta_theme_draw_frame (MetaTheme *theme, meta_theme_draw_frame_with_style (theme, #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_get_style_context (widget), - #else - gtk_widget_get_style (widget), - #endif - widget, - #if GTK_CHECK_VERSION(3, 0, 0) cr, #else + widget, drawable, clip, x_offset, y_offset, #endif type, flags, client_width, client_height, @@ -6128,7 +6286,14 @@ meta_gtk_widget_get_font_desc (GtkWidget *widget, g_return_val_if_fail (gtk_widget_get_realized (widget), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style = gtk_widget_get_style_context (widget); + GtkStateFlags state = gtk_widget_get_state_flags (widget); + gtk_style_context_get(style, state, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL); + font_desc = pango_font_description_copy (font_desc); +#else font_desc = pango_font_description_copy (gtk_widget_get_style (widget)->font_desc); +#endif if (override) pango_font_description_merge (font_desc, override, TRUE); @@ -6596,6 +6761,30 @@ meta_gradient_type_to_string (MetaGradientType type) return "<unknown>"; } +#if GTK_CHECK_VERSION (3, 0, 0) +GtkStateFlags +meta_gtk_state_from_string (const char *str) +{ + if (g_ascii_strcasecmp ("normal", str) == 0) + return GTK_STATE_FLAG_NORMAL; + else if (g_ascii_strcasecmp ("prelight", str) == 0) + return GTK_STATE_FLAG_PRELIGHT; + else if (g_ascii_strcasecmp ("active", str) == 0) + return GTK_STATE_FLAG_ACTIVE; + else if (g_ascii_strcasecmp ("selected", str) == 0) + return GTK_STATE_FLAG_SELECTED; + else if (g_ascii_strcasecmp ("insensitive", str) == 0) + return GTK_STATE_FLAG_INSENSITIVE; + else if (g_ascii_strcasecmp ("inconsistent", str) == 0) + return GTK_STATE_FLAG_INCONSISTENT; + else if (g_ascii_strcasecmp ("focused", str) == 0) + return GTK_STATE_FLAG_FOCUSED; + else if (g_ascii_strcasecmp ("backdrop", str) == 0) + return GTK_STATE_FLAG_BACKDROP; + else + return -1; /* hack */ +} +#else GtkStateType meta_gtk_state_from_string (const char *str) { @@ -6632,6 +6821,7 @@ meta_gtk_state_to_string (GtkStateType state) return "<unknown>"; } +#endif GtkShadowType meta_gtk_shadow_from_string (const char *str) @@ -6755,18 +6945,31 @@ meta_image_fill_type_to_string (MetaImageFillType fill_type) * \param b [out] the resulting colour * \param k amount to scale lightness and saturation by */ +#if GTK_CHECK_VERSION (3, 0, 0) +static void +gtk_style_shade (GdkRGBA *a, + GdkRGBA *b, + gdouble k) +#else static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k) +#endif { gdouble red; gdouble green; gdouble blue; +#if GTK_CHECK_VERSION (3, 0, 0) + red = a->red; + green = a->green; + blue = a->blue; +#else red = (gdouble) a->red / 65535.0; green = (gdouble) a->green / 65535.0; blue = (gdouble) a->blue / 65535.0; +#endif rgb_to_hls (&red, &green, &blue); @@ -6784,9 +6987,15 @@ gtk_style_shade (GdkColor *a, hls_to_rgb (&red, &green, &blue); +#if GTK_CHECK_VERSION (3, 0, 0) + b->red = red; + b->green = green; + b->blue = blue; +#else b->red = red * 65535.0; b->green = green * 65535.0; b->blue = blue * 65535.0; +#endif } /** |