GtkMenuBar: Use GtkStyleContext for rendering.

This commit is contained in:
Carlos Garnacho
2010-11-21 19:38:52 +01:00
parent 0df9c70200
commit 6fff76568c

View File

@ -214,9 +214,14 @@ gtk_menu_bar_class_init (GtkMenuBarClass *class)
static void static void
gtk_menu_bar_init (GtkMenuBar *menu_bar) gtk_menu_bar_init (GtkMenuBar *menu_bar)
{ {
GtkStyleContext *context;
menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar, menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar,
GTK_TYPE_MENU_BAR, GTK_TYPE_MENU_BAR,
GtkMenuBarPrivate); GtkMenuBarPrivate);
context = gtk_widget_get_style_context (GTK_WIDGET (menu_bar));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
} }
GtkWidget* GtkWidget*
@ -345,11 +350,17 @@ gtk_menu_bar_size_request (GtkWidget *widget,
if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE) if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
{ {
GtkStyle *style; GtkStyleContext *context;
gint border_width;
style = gtk_widget_get_style (widget); context = gtk_widget_get_style_context (widget);
requisition->width += style->xthickness * 2;
requisition->height += style->ythickness * 2; gtk_style_context_get (context, 0,
"border-width", &border_width,
NULL);
requisition->width += border_width * 2;
requisition->height += border_width * 2;
} }
} }
} }
@ -424,11 +435,16 @@ gtk_menu_bar_size_allocate (GtkWidget *widget,
if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE) if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
{ {
GtkStyle *style; GtkStyleContext *context;
gint border_width;
style = gtk_widget_get_style (widget); context = gtk_widget_get_style_context (widget);
child_allocation.x += style->xthickness; gtk_style_context_get (context, 0,
child_allocation.y += style->ythickness; "border-width", &border_width,
NULL);
child_allocation.x += border_width;
child_allocation.y += border_width;
} }
if (priv->pack_direction == GTK_PACK_DIRECTION_LTR || if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
@ -539,18 +555,26 @@ static gint
gtk_menu_bar_draw (GtkWidget *widget, gtk_menu_bar_draw (GtkWidget *widget,
cairo_t *cr) cairo_t *cr)
{ {
GtkStyleContext *context;
GtkStateFlags state;
int border; int border;
border = gtk_container_get_border_width (GTK_CONTAINER (widget)); border = gtk_container_get_border_width (GTK_CONTAINER (widget));
context = gtk_widget_get_style_context (widget);
gtk_paint_box (gtk_widget_get_style (widget), state = gtk_widget_get_state_flags (widget);
cr, gtk_style_context_set_state (context, state);
gtk_widget_get_state (widget),
get_shadow_type (GTK_MENU_BAR (widget)), if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
widget, "menubar", gtk_render_background (context, cr,
border, border, border, border,
gtk_widget_get_allocated_width (widget) - border * 2, gtk_widget_get_allocated_width (widget) - border * 2,
gtk_widget_get_allocated_height (widget) - border * 2); gtk_widget_get_allocated_height (widget) - border * 2);
gtk_render_frame (context, cr,
border, border,
gtk_widget_get_allocated_width (widget) - border * 2,
gtk_widget_get_allocated_height (widget) - border * 2);
GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);