Commit a3a9c61a authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Make GtkHandleBox use GtkStyleContext

parent 029fb53a
...@@ -136,8 +136,7 @@ static void gtk_handle_box_map (GtkWidget *widget); ...@@ -136,8 +136,7 @@ static void gtk_handle_box_map (GtkWidget *widget);
static void gtk_handle_box_unmap (GtkWidget *widget); static void gtk_handle_box_unmap (GtkWidget *widget);
static void gtk_handle_box_realize (GtkWidget *widget); static void gtk_handle_box_realize (GtkWidget *widget);
static void gtk_handle_box_unrealize (GtkWidget *widget); static void gtk_handle_box_unrealize (GtkWidget *widget);
static void gtk_handle_box_style_set (GtkWidget *widget, static void gtk_handle_box_style_updated (GtkWidget *widget);
GtkStyle *previous_style);
static void gtk_handle_box_size_request (GtkWidget *widget, static void gtk_handle_box_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_handle_box_get_preferred_width (GtkWidget *widget, static void gtk_handle_box_get_preferred_width (GtkWidget *widget,
...@@ -229,7 +228,7 @@ gtk_handle_box_class_init (GtkHandleBoxClass *class) ...@@ -229,7 +228,7 @@ gtk_handle_box_class_init (GtkHandleBoxClass *class)
widget_class->unmap = gtk_handle_box_unmap; widget_class->unmap = gtk_handle_box_unmap;
widget_class->realize = gtk_handle_box_realize; widget_class->realize = gtk_handle_box_realize;
widget_class->unrealize = gtk_handle_box_unrealize; widget_class->unrealize = gtk_handle_box_unrealize;
widget_class->style_set = gtk_handle_box_style_set; widget_class->style_updated = gtk_handle_box_style_updated;
widget_class->get_preferred_width = gtk_handle_box_get_preferred_width; widget_class->get_preferred_width = gtk_handle_box_get_preferred_width;
widget_class->get_preferred_height = gtk_handle_box_get_preferred_height; widget_class->get_preferred_height = gtk_handle_box_get_preferred_height;
widget_class->size_allocate = gtk_handle_box_size_allocate; widget_class->size_allocate = gtk_handle_box_size_allocate;
...@@ -269,6 +268,7 @@ static void ...@@ -269,6 +268,7 @@ static void
gtk_handle_box_init (GtkHandleBox *handle_box) gtk_handle_box_init (GtkHandleBox *handle_box)
{ {
GtkHandleBoxPrivate *priv; GtkHandleBoxPrivate *priv;
GtkStyleContext *context;
handle_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (handle_box, handle_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (handle_box,
GTK_TYPE_HANDLE_BOX, GTK_TYPE_HANDLE_BOX,
...@@ -286,6 +286,9 @@ gtk_handle_box_init (GtkHandleBox *handle_box) ...@@ -286,6 +286,9 @@ gtk_handle_box_init (GtkHandleBox *handle_box)
priv->in_drag = FALSE; priv->in_drag = FALSE;
priv->shrink_on_detach = TRUE; priv->shrink_on_detach = TRUE;
priv->snap_edge = -1; priv->snap_edge = -1;
context = gtk_widget_get_style_context (GTK_WIDGET (handle_box));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_DOCK);
} }
static void static void
...@@ -408,8 +411,8 @@ gtk_handle_box_realize (GtkWidget *widget) ...@@ -408,8 +411,8 @@ gtk_handle_box_realize (GtkWidget *widget)
GtkHandleBoxPrivate *priv = hb->priv; GtkHandleBoxPrivate *priv = hb->priv;
GtkAllocation allocation; GtkAllocation allocation;
GtkRequisition requisition; GtkRequisition requisition;
GtkStateType state; GtkStateFlags state;
GtkStyle *style; GtkStyleContext *context;
GtkWidget *child; GtkWidget *child;
GdkWindow *window; GdkWindow *window;
GdkWindowAttr attributes; GdkWindowAttr attributes;
...@@ -479,12 +482,12 @@ gtk_handle_box_realize (GtkWidget *widget) ...@@ -479,12 +482,12 @@ gtk_handle_box_realize (GtkWidget *widget)
gdk_window_set_decorations (priv->float_window, 0); gdk_window_set_decorations (priv->float_window, 0);
gdk_window_set_type_hint (priv->float_window, GDK_WINDOW_TYPE_HINT_TOOLBAR); gdk_window_set_type_hint (priv->float_window, GDK_WINDOW_TYPE_HINT_TOOLBAR);
gtk_widget_style_attach (widget); context = gtk_widget_get_style_context (widget);
style = gtk_widget_get_style (widget); state = gtk_widget_get_state_flags (widget);
state = gtk_widget_get_state (widget);
gtk_style_set_background (style, window, state); gtk_style_context_set_background (context, window);
gtk_style_set_background (style, priv->bin_window, state); gtk_style_context_set_background (context, priv->bin_window);
gtk_style_set_background (style, priv->float_window, state); gtk_style_context_set_background (context, priv->float_window);
} }
static void static void
...@@ -504,8 +507,7 @@ gtk_handle_box_unrealize (GtkWidget *widget) ...@@ -504,8 +507,7 @@ gtk_handle_box_unrealize (GtkWidget *widget)
} }
static void static void
gtk_handle_box_style_set (GtkWidget *widget, gtk_handle_box_style_updated (GtkWidget *widget)
GtkStyle *previous_style)
{ {
GtkHandleBox *hb = GTK_HANDLE_BOX (widget); GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
GtkHandleBoxPrivate *priv = hb->priv; GtkHandleBoxPrivate *priv = hb->priv;
...@@ -513,15 +515,20 @@ gtk_handle_box_style_set (GtkWidget *widget, ...@@ -513,15 +515,20 @@ gtk_handle_box_style_set (GtkWidget *widget,
if (gtk_widget_get_realized (widget) && if (gtk_widget_get_realized (widget) &&
gtk_widget_get_has_window (widget)) gtk_widget_get_has_window (widget))
{ {
GtkStateType state; GtkStateFlags state;
GtkStyle *style; GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_save (context);
gtk_style_context_set_state (context, state);
style = gtk_widget_get_style (widget); gtk_style_context_set_background (context, gtk_widget_get_window (widget));
state = gtk_widget_get_state (widget); gtk_style_context_set_background (context, priv->bin_window);
gtk_style_context_set_background (context, priv->float_window);
gtk_style_set_background (style, gtk_widget_get_window (widget), state); gtk_style_context_restore (context);
gtk_style_set_background (style, priv->bin_window, state);
gtk_style_set_background (style, priv->float_window, state);
} }
} }
...@@ -760,8 +767,8 @@ gtk_handle_box_draw_ghost (GtkHandleBox *hb, ...@@ -760,8 +767,8 @@ gtk_handle_box_draw_ghost (GtkHandleBox *hb,
cairo_t *cr) cairo_t *cr)
{ {
GtkWidget *widget = GTK_WIDGET (hb); GtkWidget *widget = GTK_WIDGET (hb);
GtkStateType state; GtkStateFlags state;
GtkStyle *style; GtkStyleContext *context;
GdkWindow *window; GdkWindow *window;
guint x; guint x;
guint y; guint y;
...@@ -791,36 +798,31 @@ gtk_handle_box_draw_ghost (GtkHandleBox *hb, ...@@ -791,36 +798,31 @@ gtk_handle_box_draw_ghost (GtkHandleBox *hb,
height = DRAG_HANDLE_SIZE; height = DRAG_HANDLE_SIZE;
} }
style = gtk_widget_get_style (widget); context = gtk_widget_get_style_context (widget);
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
state = gtk_widget_get_state (widget); state = gtk_widget_get_state_flags (widget);
gtk_paint_shadow (style, gtk_style_context_save (context);
cr, gtk_style_context_set_state (context, state);
state,
GTK_SHADOW_ETCHED_IN, gtk_render_background (context, cr, x, y, width, height);
widget, "handle", gtk_render_frame (context, cr, x, y, width, height);
x,
y, if (handle_position == GTK_POS_LEFT ||
width, handle_position == GTK_POS_RIGHT)
height); gtk_render_line (context, cr,
if (handle_position == GTK_POS_LEFT || handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0,
handle_position == GTK_POS_RIGHT) allocation_height / 2,
gtk_paint_hline (style, handle_position == GTK_POS_LEFT ? allocation_width : allocation_width - DRAG_HANDLE_SIZE,
cr, allocation_height / 2);
state, else
widget, "handlebox", gtk_render_line (context, cr,
handle_position == GTK_POS_LEFT ? DRAG_HANDLE_SIZE : 0, allocation_width / 2,
handle_position == GTK_POS_LEFT ? allocation_width : allocation_width - DRAG_HANDLE_SIZE, handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
allocation_height / 2); allocation_width / 2,
else handle_position == GTK_POS_TOP ? allocation_height : allocation_height - DRAG_HANDLE_SIZE);
gtk_paint_vline (style,
cr, gtk_style_context_restore (context);
state,
widget, "handlebox",
handle_position == GTK_POS_TOP ? DRAG_HANDLE_SIZE : 0,
handle_position == GTK_POS_TOP ? allocation_height : allocation_height - DRAG_HANDLE_SIZE,
allocation_width / 2);
} }
void void
...@@ -957,6 +959,8 @@ gtk_handle_box_paint (GtkWidget *widget, ...@@ -957,6 +959,8 @@ gtk_handle_box_paint (GtkWidget *widget,
GtkHandleBox *hb = GTK_HANDLE_BOX (widget); GtkHandleBox *hb = GTK_HANDLE_BOX (widget);
GtkHandleBoxPrivate *priv = hb->priv; GtkHandleBoxPrivate *priv = hb->priv;
GtkBin *bin = GTK_BIN (widget); GtkBin *bin = GTK_BIN (widget);
GtkStyleContext *context;
GtkStateFlags state;
GtkWidget *child; GtkWidget *child;
gint width, height; gint width, height;
GdkRectangle rect; GdkRectangle rect;
...@@ -968,12 +972,14 @@ gtk_handle_box_paint (GtkWidget *widget, ...@@ -968,12 +972,14 @@ gtk_handle_box_paint (GtkWidget *widget,
width = gdk_window_get_width (priv->bin_window); width = gdk_window_get_width (priv->bin_window);
height = gdk_window_get_height (priv->bin_window); height = gdk_window_get_height (priv->bin_window);
gtk_paint_box (gtk_widget_get_style (widget), context = gtk_widget_get_style_context (widget);
cr, state = gtk_widget_get_state_flags (widget);
gtk_widget_get_state (widget),
priv->shadow_type, gtk_style_context_save (context);
widget, "handlebox_bin", gtk_style_context_set_state (context, state);
0, 0, width, height);
gtk_render_background (context, cr, 0, 0, width, height);
gtk_render_frame (context, cr, 0, 0, width, height);
switch (handle_position) switch (handle_position)
{ {
...@@ -1010,15 +1016,14 @@ gtk_handle_box_paint (GtkWidget *widget, ...@@ -1010,15 +1016,14 @@ gtk_handle_box_paint (GtkWidget *widget,
break; break;
} }
gtk_paint_handle (gtk_widget_get_style (widget), cr, gtk_render_handle (context, cr,
GTK_STATE_NORMAL, GTK_SHADOW_OUT, rect.x, rect.y, rect.width, rect.height);
widget, "handlebox",
rect.x, rect.y, rect.width, rect.height,
handle_orientation);
child = gtk_bin_get_child (bin); child = gtk_bin_get_child (bin);
if (child != NULL && gtk_widget_get_visible (child)) if (child != NULL && gtk_widget_get_visible (child))
GTK_WIDGET_CLASS (gtk_handle_box_parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (gtk_handle_box_parent_class)->draw (widget, cr);
gtk_style_context_restore (context);
} }
static gboolean static gboolean
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment