From b75dcdb46cce1e2dc864e361902b293f7103a5e3 Mon Sep 17 00:00:00 2001 From: infirit Date: Sun, 23 Nov 2014 07:11:25 +0100 Subject: panel-frame: Port to GtkStyleContext and Fix padding handling Based on gnome-panel commits: 8e36c34e6f356b0f49a044a5b54125dce4661f7c 45c30bc316db49b52bcacabcaa2e7977b63318cc From: Carlos Garcia Campos --- mate-panel/panel-frame.c | 195 ++++++++++++++++++++++++++++++----------------- 1 file changed, 123 insertions(+), 72 deletions(-) diff --git a/mate-panel/panel-frame.c b/mate-panel/panel-frame.c index 224a00b8..e84fc60e 100644 --- a/mate-panel/panel-frame.c +++ b/mate-panel/panel-frame.c @@ -41,13 +41,15 @@ panel_frame_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) { - PanelFrame *frame = (PanelFrame *) widget; - GtkBin *bin = (GtkBin *) widget; - GtkStyle *style; - GtkWidget *child; - int border_width; - - style = gtk_widget_get_style (widget); + PanelFrame *frame = (PanelFrame *) widget; + GtkBin *bin = (GtkBin *) widget; + GtkStyleContext *context; + GtkWidget *child; + GtkBorder padding; + int border_width; + + context = gtk_widget_get_style_context (widget); + gtk_style_context_get_padding (context, gtk_widget_get_state_flags (widget), &padding); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); *minimal_width = 1; @@ -61,12 +63,13 @@ panel_frame_get_preferred_width (GtkWidget *widget, *natural_width += border_width; if (frame->edges & PANEL_EDGE_LEFT) { - *minimal_width += style->ythickness; - *natural_width += style->ythickness; + *minimal_width += padding.left; + *natural_width += padding.left; } + if (frame->edges & PANEL_EDGE_RIGHT) { - *minimal_width += style->ythickness; - *natural_width += style->ythickness; + *minimal_width += padding.right; + *natural_width += padding.right; } } @@ -75,14 +78,15 @@ panel_frame_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) { - PanelFrame *frame = (PanelFrame *) widget; - GtkBin *bin = (GtkBin *) widget; - GtkStyle *style; - GtkWidget *child; - int border_width; + PanelFrame *frame = (PanelFrame *) widget; + GtkBin *bin = (GtkBin *) widget; + GtkStyleContext *context; + GtkWidget *child; + GtkBorder padding; + int border_width; - style = gtk_widget_get_style (widget); - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + context = gtk_widget_get_style_context (widget); + gtk_style_context_get_padding (context, gtk_widget_get_state_flags (widget), &padding); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); *minimal_height = 1; *natural_height = 1; @@ -94,14 +98,14 @@ panel_frame_get_preferred_height (GtkWidget *widget, *minimal_height += border_width; *natural_height += border_width; - if (frame->edges & PANEL_EDGE_TOP) { - *minimal_height += style->xthickness; - *natural_height += style->xthickness; + *minimal_height += padding.top; + *natural_height += padding.top; } + if (frame->edges & PANEL_EDGE_BOTTOM) { - *minimal_height += style->xthickness; - *natural_height += style->xthickness; + *minimal_height += padding.bottom; + *natural_height += padding.bottom; } } @@ -144,17 +148,27 @@ static void panel_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { - PanelFrame *frame = (PanelFrame *) widget; - GtkBin *bin = (GtkBin *) widget; - GtkStyle *style; - GtkAllocation child_allocation; - GtkAllocation child_allocation_current; - GtkWidget *child; - int border_width; + PanelFrame *frame = (PanelFrame *) widget; + GtkBin *bin = (GtkBin *) widget; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *context; + GtkBorder padding; +#else + GtkStyle *style; +#endif + GtkAllocation child_allocation; + GtkAllocation child_allocation_current; + GtkWidget *child; + int border_width; gtk_widget_set_allocation (widget, allocation); +#if GTK_CHECK_VERSION (3, 0, 0) + context = gtk_widget_get_style_context (widget); + gtk_style_context_get_padding (context, gtk_widget_get_state_flags (widget), &padding); +#else style = gtk_widget_get_style (widget); +#endif border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); child_allocation.x = allocation->x + border_width; @@ -163,20 +177,38 @@ panel_frame_size_allocate (GtkWidget *widget, child_allocation.height = allocation->height - 2 * border_width; if (frame->edges & PANEL_EDGE_LEFT) { +#if GTK_CHECK_VERSION (3, 0, 0) + child_allocation.x += padding.left; + child_allocation.width -= padding.left; +#else child_allocation.x += style->xthickness; child_allocation.width -= style->xthickness; +#endif } if (frame->edges & PANEL_EDGE_TOP) { +#if GTK_CHECK_VERSION (3, 0, 0) + child_allocation.y += padding.top; + child_allocation.height -= padding.top; +#else child_allocation.y += style->ythickness; child_allocation.height -= style->ythickness; +#endif } if (frame->edges & PANEL_EDGE_RIGHT) +#if GTK_CHECK_VERSION (3, 0, 0) + child_allocation.width -= padding.left; +#else child_allocation.width -= style->xthickness; +#endif if (frame->edges & PANEL_EDGE_BOTTOM) +#if GTK_CHECK_VERSION (3, 0, 0) + child_allocation.height -= padding.top; +#else child_allocation.height -= style->ythickness; +#endif child = gtk_bin_get_child (bin); gtk_widget_get_allocation (child, &child_allocation_current); @@ -199,122 +231,141 @@ panel_frame_draw (GtkWidget *widget, #endif PanelFrameEdge edges) { - GdkWindow *window; - GtkStyle *style; - GtkStateType state; + PanelFrame *frame = (PanelFrame *) widget; + GdkWindow *window; #if GTK_CHECK_VERSION (3, 0, 0) - GdkColor *dark, *light, *black; + GtkStyleContext *context; + GtkStateFlags state; + GdkRGBA bg, dark, light; + GtkSymbolicColor *c1, *c2; + GtkBorder padding; #else - GtkAllocation allocation; - GdkGC *dark, *light, *black; + GtkStyle *style; + GtkStateType state; + GtkAllocation allocation; + GdkGC *dark, *light, *black; + int xthickness, ythickness; #endif - int x, y, width, height; - int xthickness, ythickness; + int x, y, width, height; + if (edges == PANEL_EDGE_NONE) return; window = gtk_widget_get_window (widget); - style = gtk_widget_get_style (widget); - state = gtk_widget_get_state (widget); #if GTK_CHECK_VERSION (3, 0, 0) - x = 0; - y = 0; + context = gtk_widget_get_style_context (widget); + state = gtk_widget_get_state_flags (widget); + width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); + + gtk_style_context_get_background_color (context, state, &bg); + + c1 = gtk_symbolic_color_new_literal (&bg); + + c2 = gtk_symbolic_color_new_shade (c1, 0.7); + gtk_symbolic_color_resolve (c2, NULL, &dark); + gtk_symbolic_color_unref (c2); + + c2 = gtk_symbolic_color_new_shade (c1, 1.3); + gtk_symbolic_color_resolve (c2, NULL, &light); + gtk_symbolic_color_unref (c2); + + gtk_symbolic_color_unref (c1); + + gtk_style_context_get_padding (context, state, &padding); #else + style = gtk_widget_get_style (widget); + state = gtk_widget_get_state (widget); + gtk_widget_get_allocation (widget, &allocation); x = allocation.x; y = allocation.y; width = allocation.width; height = allocation.height; -#endif -#if GTK_CHECK_VERSION (3, 0, 0) - dark = &style->dark [state]; - light = &style->light [state]; - black = &style->black; -#else dark = style->dark_gc [state]; light = style->light_gc [state]; black = style->black_gc; -#endif xthickness = style->xthickness; ythickness = style->ythickness; - +#endif /* Copied from gtk_default_draw_shadow() */ + x = y = 0; + #if GTK_CHECK_VERSION (3, 0, 0) cairo_set_line_width (cr, 1); - if (edges & PANEL_EDGE_BOTTOM && ythickness > 0) { - if (ythickness > 1) { - gdk_cairo_set_source_color (cr, dark); + if (frame->edges & PANEL_EDGE_BOTTOM && padding.bottom > 0) { + if (padding.bottom > 1) { + gdk_cairo_set_source_rgba (cr, &dark); cairo_move_to (cr, x + .5, y + height - 2 + .5); cairo_line_to (cr, x + width - 1 - .5, y + height - 2 + .5); cairo_stroke (cr); - gdk_cairo_set_source_color (cr, black); + cairo_set_source_rgb (cr, 0., 0., 0.); cairo_move_to (cr, x + .5, y + height - 1 - .5); cairo_line_to (cr, x + width - 1 - .5, y + height - 1 - .5); cairo_stroke (cr); } else { - gdk_cairo_set_source_color (cr, dark); + gdk_cairo_set_source_rgba (cr, &dark); cairo_move_to (cr, x + .5, y + height - 1 - .5); cairo_line_to (cr, x + width - 1 - .5, y + height - 1 - .5); cairo_stroke (cr); } } - if (edges & PANEL_EDGE_RIGHT && xthickness > 0) { - if (xthickness > 1) { - gdk_cairo_set_source_color (cr, dark); + if (frame->edges & PANEL_EDGE_RIGHT && padding.right > 0) { + if (padding.right > 1) { + gdk_cairo_set_source_rgba (cr, &dark); cairo_move_to (cr, x + width - 2 - .5, y + .5); cairo_line_to (cr, x + width - 2 - .5, y + height - 1 - .5); cairo_stroke (cr); - gdk_cairo_set_source_color (cr, black); + cairo_set_source_rgb (cr, 0., 0., 0.); cairo_move_to (cr, x + width - 1 - .5, y + .5); cairo_line_to (cr, x + width - 1 - .5, y + height - 1 - .5); cairo_stroke (cr); } else { - gdk_cairo_set_source_color (cr, dark); + gdk_cairo_set_source_rgba (cr, &dark); cairo_move_to (cr, x + width - 1 - .5, y + .5); cairo_line_to (cr, x + width - 1 - .5, y + height - 1 - .5); cairo_stroke (cr); } } - if (edges & PANEL_EDGE_TOP && ythickness > 0) { - gdk_cairo_set_source_color (cr, light); + if (frame->edges & PANEL_EDGE_TOP && padding.top > 0) { + gdk_cairo_set_source_rgba (cr, &light); cairo_move_to (cr, x + .5, y + .5); cairo_line_to (cr, x + width - 1 - .5, y + .5); cairo_stroke (cr); - if (ythickness > 1) { - gdk_cairo_set_source_color (cr, &style->bg [state]); + if (padding.top > 1) { + gdk_cairo_set_source_rgba (cr, &bg); cairo_move_to (cr, x + .5, y + 1 + .5); cairo_line_to (cr, x + width - 1 - .5, y + 1 + .5); cairo_stroke (cr); } } - if (edges & PANEL_EDGE_LEFT && xthickness > 0) { - gdk_cairo_set_source_color (cr, light); + if (frame->edges & PANEL_EDGE_LEFT && padding.left > 0) { + gdk_cairo_set_source_rgba (cr, &light); cairo_move_to (cr, x + .5, y + .5); cairo_line_to (cr, x + .5, y + height - 1 - .5); cairo_stroke (cr); - if (xthickness > 1) { - gdk_cairo_set_source_color (cr, &style->bg [state]); + if (padding.left > 1) { + gdk_cairo_set_source_rgba (cr, &bg); cairo_move_to (cr, x + 1 + .5, y + .5); cairo_line_to (cr, x + 1 + .5, y + height - 1 - .5); cairo_stroke (cr); } } #else - if (edges & PANEL_EDGE_BOTTOM && ythickness > 0) { + if (frame->edges & PANEL_EDGE_BOTTOM && ythickness > 0) { if (ythickness > 1) { gdk_draw_line (window, dark, x, y + height - 2, @@ -328,7 +379,7 @@ panel_frame_draw (GtkWidget *widget, x + width - 1, y + height - 1); } - if (edges & PANEL_EDGE_RIGHT && xthickness > 0) { + if (frame->edges & PANEL_EDGE_RIGHT && xthickness > 0) { if (xthickness > 1) { gdk_draw_line (window, dark, x + width - 2, y, @@ -343,7 +394,7 @@ panel_frame_draw (GtkWidget *widget, x + width - 1, y + height - 1); } - if (edges & PANEL_EDGE_TOP && ythickness > 0) { + if (frame->edges & PANEL_EDGE_TOP && ythickness > 0) { gdk_draw_line (window, light, x, y, x + width - 1, y); @@ -353,7 +404,7 @@ panel_frame_draw (GtkWidget *widget, x, y + 1, x + width - 1, y + 1); } - if (edges & PANEL_EDGE_LEFT && xthickness > 0) { + if (frame->edges & PANEL_EDGE_LEFT && xthickness > 0) { gdk_draw_line (window, light, x, y, x, y + height - 1); -- cgit v1.2.1