Port GtkRange widgets to GtkStyleContext

This commit is contained in:
Carlos Garnacho 2010-12-13 13:43:52 +01:00
parent 3306305fe1
commit c64a1891f8
4 changed files with 230 additions and 206 deletions

View File

@ -214,12 +214,11 @@ static gboolean gtk_range_grab_broken (GtkWidget *widget,
GdkEventGrabBroken *event); GdkEventGrabBroken *event);
static void gtk_range_grab_notify (GtkWidget *widget, static void gtk_range_grab_notify (GtkWidget *widget,
gboolean was_grabbed); gboolean was_grabbed);
static void gtk_range_state_changed (GtkWidget *widget, static void gtk_range_state_flags_changed (GtkWidget *widget,
GtkStateType previous_state); GtkStateFlags previous_state);
static gboolean gtk_range_scroll_event (GtkWidget *widget, static gboolean gtk_range_scroll_event (GtkWidget *widget,
GdkEventScroll *event); GdkEventScroll *event);
static void gtk_range_style_set (GtkWidget *widget, static void gtk_range_style_updated (GtkWidget *widget);
GtkStyle *previous_style);
static void update_slider_position (GtkRange *range, static void update_slider_position (GtkRange *range,
gint mouse_x, gint mouse_x,
gint mouse_y); gint mouse_y);
@ -316,8 +315,8 @@ gtk_range_class_init (GtkRangeClass *class)
widget_class->leave_notify_event = gtk_range_leave_notify; widget_class->leave_notify_event = gtk_range_leave_notify;
widget_class->grab_broken_event = gtk_range_grab_broken; widget_class->grab_broken_event = gtk_range_grab_broken;
widget_class->grab_notify = gtk_range_grab_notify; widget_class->grab_notify = gtk_range_grab_notify;
widget_class->state_changed = gtk_range_state_changed; widget_class->state_flags_changed = gtk_range_state_flags_changed;
widget_class->style_set = gtk_range_style_set; widget_class->style_updated = gtk_range_style_updated;
widget_class->key_press_event = gtk_range_key_press; widget_class->key_press_event = gtk_range_key_press;
class->move_slider = gtk_range_move_slider; class->move_slider = gtk_range_move_slider;
@ -1044,9 +1043,12 @@ gtk_range_set_min_slider_size (GtkRange *range,
{ {
priv->min_slider_size = min_size; priv->min_slider_size = min_size;
priv->need_recalc = TRUE; if (gtk_widget_is_drawable (GTK_WIDGET (range)))
gtk_range_calc_layout (range, priv->adjustment->value); {
gtk_widget_queue_draw (GTK_WIDGET (range)); priv->need_recalc = TRUE;
gtk_range_calc_layout (range, priv->adjustment->value);
gtk_widget_queue_draw (GTK_WIDGET (range));
}
} }
} }
@ -1769,8 +1771,6 @@ gtk_range_realize (GtkWidget *widget)
priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget), priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask); &attributes, attributes_mask);
gdk_window_set_user_data (priv->event_window, range); gdk_window_set_user_data (priv->event_window, range);
gtk_widget_style_attach (widget);
} }
static void static void
@ -1813,81 +1813,74 @@ gtk_range_unmap (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget); GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
} }
static const gchar * static void
gtk_range_get_slider_detail (GtkRange *range) _gtk_range_update_context_for_stepper (GtkRange *range,
GtkStyleContext *context,
Stepper stepper)
{ {
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
const gchar *slider_detail; GtkJunctionSides sides = 0;
gboolean vertical, is_rtl;
if (priv->slider_detail_quark) vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
return g_quark_to_string (priv->slider_detail_quark); is_rtl = (gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail; /* Take junction sides from what's been
* previously set to the widget itself
*/
sides = gtk_style_context_get_junction_sides (context);
if (slider_detail && slider_detail[0] == 'X') if (vertical)
{ sides &= ~(GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM);
gchar *detail = g_strdup (slider_detail); else
sides &= ~(GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT);
detail[0] = priv->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
priv->slider_detail_quark = g_quark_from_string (detail);
g_free (detail);
return g_quark_to_string (priv->slider_detail_quark);
}
return slider_detail;
}
static const gchar *
gtk_range_get_stepper_detail (GtkRange *range,
Stepper stepper)
{
GtkRangePrivate *priv = range->priv;
const gchar *stepper_detail;
gchar *detail;
const gchar *position = NULL;
if (priv->stepper_detail_quark[stepper])
return g_quark_to_string (priv->stepper_detail_quark[stepper]);
stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
switch (stepper) switch (stepper)
{ {
case STEPPER_A: case STEPPER_A:
position = "_start"; if (vertical)
sides |= GTK_JUNCTION_BOTTOM;
else
sides |= (is_rtl) ? GTK_JUNCTION_LEFT : GTK_JUNCTION_RIGHT;
break; break;
case STEPPER_B: case STEPPER_B:
if (priv->has_stepper_a) if (priv->has_stepper_a)
position = "_start_inner"; {
if (vertical)
sides |= GTK_JUNCTION_TOP;
else
sides |= (is_rtl) ? GTK_JUNCTION_RIGHT : GTK_JUNCTION_LEFT;
}
if (vertical)
sides |= GTK_JUNCTION_BOTTOM;
else else
position = "_start"; sides |= (is_rtl) ? GTK_JUNCTION_LEFT : GTK_JUNCTION_RIGHT;
break; break;
case STEPPER_C: case STEPPER_C:
if (priv->has_stepper_d) if (priv->has_stepper_d)
position = "_end_inner"; {
if (vertical)
sides |= GTK_JUNCTION_BOTTOM;
else
sides |= (is_rtl) ? GTK_JUNCTION_LEFT : GTK_JUNCTION_RIGHT;
}
if (vertical)
sides |= GTK_JUNCTION_TOP;
else else
position = "_end"; sides |= (is_rtl) ? GTK_JUNCTION_RIGHT : GTK_JUNCTION_LEFT;
break; break;
case STEPPER_D: case STEPPER_D:
position = "_end"; if (vertical)
sides |= GTK_JUNCTION_TOP;
else
sides |= (is_rtl) ? GTK_JUNCTION_RIGHT : GTK_JUNCTION_LEFT;
break; break;
default:
g_assert_not_reached ();
} }
detail = g_strconcat (stepper_detail, position, NULL); gtk_style_context_set_junction_sides (context, sides);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
if (detail[0] == 'X')
detail[0] = priv->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
priv->stepper_detail_quark[stepper] = g_quark_from_string (detail);
g_free (detail);
return g_quark_to_string (priv->stepper_detail_quark[stepper]);
} }
static void static void
@ -1900,17 +1893,15 @@ draw_stepper (GtkRange *range,
{ {
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
GtkAllocation allocation; GtkAllocation allocation;
GtkStateType state_type; GtkStateFlags state = 0;
GtkShadowType shadow_type; GtkStyleContext *context;
GtkStyle *style;
GtkWidget *widget = GTK_WIDGET (range); GtkWidget *widget = GTK_WIDGET (range);
GdkWindow *window; GdkWindow *window;
gfloat arrow_scaling; gfloat arrow_scaling;
GdkRectangle *rect; GdkRectangle *rect;
gint arrow_x; gint arrow_x;
gint arrow_y; gint arrow_y;
gint arrow_width; gdouble arrow_size, angle;
gint arrow_height;
gboolean arrow_sensitive; gboolean arrow_sensitive;
switch (stepper) switch (stepper)
@ -1948,37 +1939,34 @@ draw_stepper (GtkRange *range,
} }
if (!gtk_widget_is_sensitive (GTK_WIDGET (range)) || !arrow_sensitive) if (!gtk_widget_is_sensitive (GTK_WIDGET (range)) || !arrow_sensitive)
state_type = GTK_STATE_INSENSITIVE; state = GTK_STATE_FLAG_INSENSITIVE;
else if (clicked)
state_type = GTK_STATE_ACTIVE;
else if (prelighted)
state_type = GTK_STATE_PRELIGHT;
else
state_type = GTK_STATE_NORMAL;
if (clicked && arrow_sensitive)
shadow_type = GTK_SHADOW_IN;
else else
shadow_type = GTK_SHADOW_OUT; {
if (clicked)
state |= GTK_STATE_FLAG_ACTIVE;
if (prelighted)
state |= GTK_STATE_FLAG_PRELIGHT;
}
style = gtk_widget_get_style (widget);
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
context = gtk_widget_get_style_context (widget);
gtk_paint_box (style, cr, gtk_style_context_save (context);
state_type, shadow_type, _gtk_range_update_context_for_stepper (range, context, stepper);
widget, gtk_style_context_set_state (context, state);
gtk_range_get_stepper_detail (range, stepper),
rect->x, gtk_render_background (context, cr,
rect->y, rect->x, rect->y,
rect->width, rect->width, rect->height);
rect->height); gtk_render_frame (context, cr,
rect->x, rect->y,
rect->width, rect->height);
gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL); gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
arrow_width = rect->width * arrow_scaling; arrow_size = MIN (rect->width, rect->height) * arrow_scaling;
arrow_height = rect->height * arrow_scaling; arrow_x = rect->x + (rect->width - arrow_size) / 2;
arrow_x = rect->x + (rect->width - arrow_width) / 2; arrow_y = rect->y + (rect->height - arrow_size) / 2;
arrow_y = rect->y + (rect->height - arrow_height) / 2;
if (clicked && arrow_sensitive) if (clicked && arrow_sensitive)
{ {
@ -1993,13 +1981,29 @@ draw_stepper (GtkRange *range,
arrow_y += arrow_displacement_y; arrow_y += arrow_displacement_y;
} }
gtk_paint_arrow (style, cr, switch (arrow_type)
state_type, shadow_type, {
widget, case GTK_ARROW_RIGHT:
gtk_range_get_stepper_detail (range, stepper), angle = G_PI / 2;
arrow_type, break;
TRUE, case GTK_ARROW_DOWN:
arrow_x, arrow_y, arrow_width, arrow_height); angle = G_PI;
break;
case GTK_ARROW_LEFT:
angle = 3 * (G_PI / 2);
break;
case GTK_ARROW_UP:
default:
angle = 0;
break;
}
gtk_render_arrow (context, cr,
angle,
arrow_x, arrow_y,
arrow_size);
gtk_style_context_restore (context);
} }
static gboolean static gboolean
@ -2009,15 +2013,15 @@ gtk_range_draw (GtkWidget *widget,
GtkRange *range = GTK_RANGE (widget); GtkRange *range = GTK_RANGE (widget);
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
gboolean sensitive; gboolean sensitive;
GtkStateType state; GtkStateFlags state = 0;
GtkShadowType shadow_type;
GtkStyle *style;
GdkWindow *window; GdkWindow *window;
gint focus_line_width = 0; gint focus_line_width = 0;
gint focus_padding = 0; gint focus_padding = 0;
gboolean touchscreen; gboolean touchscreen;
gboolean draw_trough = TRUE; gboolean draw_trough = TRUE;
GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
g_object_get (gtk_widget_get_settings (widget), g_object_get (gtk_widget_get_settings (widget),
"gtk-touchscreen-mode", &touchscreen, "gtk-touchscreen-mode", &touchscreen,
NULL); NULL);
@ -2026,7 +2030,6 @@ gtk_range_draw (GtkWidget *widget,
priv->adjustment->upper == priv->adjustment->lower) priv->adjustment->upper == priv->adjustment->lower)
draw_trough = FALSE; draw_trough = FALSE;
style = gtk_widget_get_style (widget);
if (gtk_widget_get_can_focus (GTK_WIDGET (range))) if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
gtk_widget_style_get (GTK_WIDGET (range), gtk_widget_style_get (GTK_WIDGET (range),
"focus-line-width", &focus_line_width, "focus-line-width", &focus_line_width,
@ -2072,6 +2075,11 @@ gtk_range_draw (GtkWidget *widget,
"stepper-spacing", &stepper_spacing, "stepper-spacing", &stepper_spacing,
NULL); NULL);
gtk_style_context_save (context);
if (!sensitive)
gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
if (stepper_spacing > 0) if (stepper_spacing > 0)
trough_under_steppers = FALSE; trough_under_steppers = FALSE;
@ -2117,6 +2125,9 @@ gtk_range_draw (GtkWidget *widget,
} }
} }
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
if (draw_trough) if (draw_trough)
{ {
gint trough_change_pos_x = width; gint trough_change_pos_x = width;
@ -2131,40 +2142,36 @@ gtk_range_draw (GtkWidget *widget,
priv->slider.height / 2 - priv->slider.height / 2 -
y); y);
gtk_paint_box (style, cr, /* FIXME: was trough-upper and trough-lower really used,
sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE, * in that case, it should still be exposed somehow.
GTK_SHADOW_IN, */
GTK_WIDGET (range), gtk_render_background (context, cr, x, y,
should_invert (range) ? "trough-upper" : "trough-lower", trough_change_pos_x,
x, y, trough_change_pos_y);
trough_change_pos_x, trough_change_pos_y);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
trough_change_pos_y = 0; trough_change_pos_y = 0;
else else
trough_change_pos_x = 0; trough_change_pos_x = 0;
gtk_paint_box (style, cr, gtk_render_background (context, cr,
sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE, x + trough_change_pos_x, y + trough_change_pos_y,
GTK_SHADOW_IN, width - trough_change_pos_x,
GTK_WIDGET (range), height - trough_change_pos_y);
should_invert (range) ? "trough-lower" : "trough-upper",
x + trough_change_pos_x, y + trough_change_pos_y, gtk_render_frame (context, cr,
width - trough_change_pos_x, x, y, width, height);
height - trough_change_pos_y);
} }
else else
{ {
gtk_paint_box (style, cr, gtk_render_background (context, cr,
sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE, x, y, width, height);
GTK_SHADOW_IN, gtk_render_frame (context, cr,
GTK_WIDGET (range), x, y, width, height);
"trough-upper",
x, y,
width,
height);
} }
gtk_style_context_restore (context);
if (priv->show_fill_level && if (priv->show_fill_level &&
priv->adjustment->upper - priv->adjustment->page_size - priv->adjustment->upper - priv->adjustment->page_size -
priv->adjustment->lower != 0) priv->adjustment->lower != 0)
@ -2176,6 +2183,9 @@ gtk_range_draw (GtkWidget *widget,
gint fill_height = height; gint fill_height = height;
gchar *fill_detail; gchar *fill_detail;
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
fill_level = CLAMP (fill_level, priv->adjustment->lower, fill_level = CLAMP (fill_level, priv->adjustment->lower,
priv->adjustment->upper - priv->adjustment->upper -
priv->adjustment->page_size); priv->adjustment->page_size);
@ -2214,40 +2224,40 @@ gtk_range_draw (GtkWidget *widget,
else else
fill_detail = "trough-fill-level"; fill_detail = "trough-fill-level";
gtk_paint_box (style, cr, gtk_render_activity (context, cr,
sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE, fill_x, fill_y,
GTK_SHADOW_OUT, fill_width, fill_height);
GTK_WIDGET (range), fill_detail,
fill_x, fill_y, gtk_style_context_restore (context);
fill_width, fill_height);
} }
gtk_style_context_restore (context);
if (sensitive && gtk_widget_has_focus (widget)) if (sensitive && gtk_widget_has_focus (widget))
gtk_paint_focus (style, cr, {
gtk_widget_get_state (widget), gtk_style_context_save (context);
widget, "trough", gtk_style_context_set_state (context,
priv->range_rect.x, gtk_widget_get_state_flags (widget));
priv->range_rect.y,
priv->range_rect.width, gtk_render_focus (context, cr,
priv->range_rect.height); priv->range_rect.x,
priv->range_rect.y,
priv->range_rect.width,
priv->range_rect.height);
gtk_style_context_restore (context);
}
} }
cairo_restore (cr); cairo_restore (cr);
shadow_type = GTK_SHADOW_OUT;
if (!sensitive) if (!sensitive)
state = GTK_STATE_INSENSITIVE; state = GTK_STATE_FLAG_INSENSITIVE;
else if (!touchscreen && priv->mouse_location == MOUSE_SLIDER) else if (!touchscreen && priv->mouse_location == MOUSE_SLIDER)
state = GTK_STATE_PRELIGHT; state = GTK_STATE_FLAG_PRELIGHT;
else
state = GTK_STATE_NORMAL;
if (priv->grab_location == MOUSE_SLIDER) if (priv->grab_location == MOUSE_SLIDER)
{ state |= GTK_STATE_FLAG_ACTIVE;
state = GTK_STATE_ACTIVE;
shadow_type = GTK_SHADOW_IN;
}
cairo_save (cr); cairo_save (cr);
gdk_cairo_rectangle (cr, &priv->slider); gdk_cairo_rectangle (cr, &priv->slider);
@ -2255,17 +2265,18 @@ gtk_range_draw (GtkWidget *widget,
if (draw_trough) if (draw_trough)
{ {
gtk_paint_slider (style, gtk_style_context_save (context);
cr, gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
state, gtk_style_context_set_state (context, state);
shadow_type,
widget, gtk_render_slider (context, cr,
gtk_range_get_slider_detail (range), priv->slider.x,
priv->slider.x, priv->slider.y,
priv->slider.y, priv->slider.width,
priv->slider.width, priv->slider.height,
priv->slider.height, priv->orientation);
priv->orientation);
gtk_style_context_restore (context);
} }
cairo_restore (cr); cairo_restore (cr);
@ -2867,8 +2878,8 @@ gtk_range_grab_notify (GtkWidget *widget,
} }
static void static void
gtk_range_state_changed (GtkWidget *widget, gtk_range_state_flags_changed (GtkWidget *widget,
GtkStateType previous_state) GtkStateFlags previous_state)
{ {
if (!gtk_widget_is_sensitive (widget)) if (!gtk_widget_is_sensitive (widget))
stop_scrolling (GTK_RANGE (widget)); stop_scrolling (GTK_RANGE (widget));
@ -2973,15 +2984,14 @@ gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
} }
static void static void
gtk_range_style_set (GtkWidget *widget, gtk_range_style_updated (GtkWidget *widget)
GtkStyle *previous_style)
{ {
GtkRange *range = GTK_RANGE (widget); GtkRange *range = GTK_RANGE (widget);
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
priv->need_recalc = TRUE; priv->need_recalc = TRUE;
GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style); GTK_WIDGET_CLASS (gtk_range_parent_class)->style_updated (widget);
} }
static void static void

View File

@ -127,8 +127,7 @@ static void gtk_scale_get_preferred_width (GtkWidget *widget,
static void gtk_scale_get_preferred_height (GtkWidget *widget, static void gtk_scale_get_preferred_height (GtkWidget *widget,
gint *minimum, gint *minimum,
gint *natural); gint *natural);
static void gtk_scale_style_set (GtkWidget *widget, static void gtk_scale_style_updated (GtkWidget *widget);
GtkStyle *previous);
static void gtk_scale_get_range_border (GtkRange *range, static void gtk_scale_get_range_border (GtkRange *range,
GtkBorder *border); GtkBorder *border);
static void gtk_scale_get_mark_label_size (GtkScale *scale, static void gtk_scale_get_mark_label_size (GtkScale *scale,
@ -204,7 +203,7 @@ gtk_scale_class_init (GtkScaleClass *class)
gobject_class->get_property = gtk_scale_get_property; gobject_class->get_property = gtk_scale_get_property;
gobject_class->finalize = gtk_scale_finalize; gobject_class->finalize = gtk_scale_finalize;
widget_class->style_set = gtk_scale_style_set; widget_class->style_updated = gtk_scale_style_updated;
widget_class->screen_changed = gtk_scale_screen_changed; widget_class->screen_changed = gtk_scale_screen_changed;
widget_class->draw = gtk_scale_draw; widget_class->draw = gtk_scale_draw;
widget_class->get_preferred_width = gtk_scale_get_preferred_width; widget_class->get_preferred_width = gtk_scale_get_preferred_width;
@ -430,6 +429,7 @@ gtk_scale_init (GtkScale *scale)
{ {
GtkScalePrivate *priv; GtkScalePrivate *priv;
GtkRange *range = GTK_RANGE (scale); GtkRange *range = GTK_RANGE (scale);
GtkStyleContext *context;
scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale, scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale,
GTK_TYPE_SCALE, GTK_TYPE_SCALE,
@ -449,6 +449,9 @@ gtk_scale_init (GtkScale *scale)
g_signal_connect (scale, "notify::orientation", g_signal_connect (scale, "notify::orientation",
G_CALLBACK (gtk_scale_orientation_notify), G_CALLBACK (gtk_scale_orientation_notify),
NULL); NULL);
context = gtk_widget_get_style_context (GTK_WIDGET (scale));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE);
} }
static void static void
@ -921,8 +924,7 @@ gtk_scale_get_mark_label_size (GtkScale *scale,
} }
static void static void
gtk_scale_style_set (GtkWidget *widget, gtk_scale_style_updated (GtkWidget *widget)
GtkStyle *previous)
{ {
gint slider_length; gint slider_length;
GtkRange *range; GtkRange *range;
@ -937,7 +939,7 @@ gtk_scale_style_set (GtkWidget *widget,
_gtk_scale_clear_layout (GTK_SCALE (widget)); _gtk_scale_clear_layout (GTK_SCALE (widget));
GTK_WIDGET_CLASS (gtk_scale_parent_class)->style_set (widget, previous); GTK_WIDGET_CLASS (gtk_scale_parent_class)->style_updated (widget);
} }
static void static void
@ -1032,8 +1034,8 @@ gtk_scale_draw (GtkWidget *widget,
GtkScale *scale = GTK_SCALE (widget); GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv; GtkScalePrivate *priv = scale->priv;
GtkRange *range = GTK_RANGE (scale); GtkRange *range = GTK_RANGE (scale);
GtkStateType state_type; GtkStateFlags state = 0;
GtkStyle *style; GtkStyleContext *context;
gint n_marks; gint n_marks;
gint *marks; gint *marks;
gint focus_padding; gint focus_padding;
@ -1041,7 +1043,7 @@ gtk_scale_draw (GtkWidget *widget,
gint value_spacing; gint value_spacing;
gint min_sep = 4; gint min_sep = 4;
style = gtk_widget_get_style (widget); context = gtk_widget_get_style_context (widget);
gtk_widget_style_get (widget, gtk_widget_style_get (widget,
"focus-padding", &focus_padding, "focus-padding", &focus_padding,
"slider-width", &slider_width, "slider-width", &slider_width,
@ -1053,9 +1055,8 @@ gtk_scale_draw (GtkWidget *widget,
*/ */
GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr);
state_type = GTK_STATE_NORMAL;
if (!gtk_widget_is_sensitive (widget)) if (!gtk_widget_is_sensitive (widget))
state_type = GTK_STATE_INSENSITIVE; state |= GTK_STATE_FLAG_INSENSITIVE;
if (priv->marks) if (priv->marks)
{ {
@ -1098,8 +1099,12 @@ gtk_scale_draw (GtkWidget *widget,
max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP, 0) - min_sep; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP, 0) - min_sep;
} }
gtk_paint_vline (style, cr, state_type, gtk_style_context_save (context);
widget, "scale-mark", y1, y2, x1); gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
gtk_style_context_set_state (context, state);
gtk_render_line (context, cr,
x1, y1, x1, y2);
if (mark->markup) if (mark->markup)
{ {
@ -1124,10 +1129,11 @@ gtk_scale_draw (GtkWidget *widget,
min_pos_after = x3 + logical_rect.width + min_sep; min_pos_after = x3 + logical_rect.width + min_sep;
} }
gtk_paint_layout (style, cr, state_type, gtk_render_layout (context, cr,
FALSE, widget, "scale-mark", x3, y3, layout);
x3, y3, layout);
} }
gtk_style_context_restore (context);
} }
else else
{ {
@ -1147,8 +1153,12 @@ gtk_scale_draw (GtkWidget *widget,
} }
y1 = marks[i]; y1 = marks[i];
gtk_paint_hline (style, cr, state_type, gtk_style_context_save (context);
widget, "range-mark", x1, x2, y1); gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
gtk_style_context_set_state (context, state);
gtk_render_line (context, cr,
x1, y1, x2, y1);
if (mark->markup) if (mark->markup)
{ {
@ -1173,10 +1183,11 @@ gtk_scale_draw (GtkWidget *widget,
min_pos_after = y3 + logical_rect.height + min_sep; min_pos_after = y3 + logical_rect.height + min_sep;
} }
gtk_paint_layout (style, cr, state_type, gtk_render_layout (context, cr,
FALSE, widget, "scale-mark", x3, y3, layout);
x3, y3, layout);
} }
gtk_style_context_restore (context);
} }
} }
@ -1197,17 +1208,10 @@ gtk_scale_draw (GtkWidget *widget,
gtk_scale_get_layout_offsets (scale, &x, &y); gtk_scale_get_layout_offsets (scale, &x, &y);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
gtk_paint_layout (style, gtk_render_layout (context, cr,
cr, x - allocation.x,
state_type, y - allocation.y,
FALSE, layout);
widget,
orientation == GTK_ORIENTATION_HORIZONTAL ?
"hscale" : "vscale",
x - allocation.x,
y - allocation.y,
layout);
} }
return FALSE; return FALSE;

View File

@ -56,8 +56,7 @@
*/ */
static void gtk_scrollbar_style_set (GtkWidget *widget, static void gtk_scrollbar_style_updated (GtkWidget *widget);
GtkStyle *previous);
G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE) G_DEFINE_TYPE (GtkScrollbar, gtk_scrollbar, GTK_TYPE_RANGE)
@ -66,9 +65,7 @@ gtk_scrollbar_class_init (GtkScrollbarClass *class)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
widget_class->style_set = gtk_scrollbar_style_set; widget_class->style_updated = gtk_scrollbar_style_updated;
GTK_RANGE_CLASS (class)->stepper_detail = "Xscrollbar";
gtk_widget_class_install_style_property (widget_class, gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("min-slider-length", g_param_spec_int ("min-slider-length",
@ -125,8 +122,7 @@ gtk_scrollbar_init (GtkScrollbar *scrollbar)
} }
static void static void
gtk_scrollbar_style_set (GtkWidget *widget, gtk_scrollbar_style_updated (GtkWidget *widget)
GtkStyle *previous)
{ {
GtkRange *range = GTK_RANGE (widget); GtkRange *range = GTK_RANGE (widget);
gint slider_length; gint slider_length;
@ -147,7 +143,7 @@ gtk_scrollbar_style_set (GtkWidget *widget,
_gtk_range_set_steppers (range, _gtk_range_set_steppers (range,
has_a, has_b, has_c, has_d); has_a, has_b, has_c, has_d);
GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_set (widget, previous); GTK_WIDGET_CLASS (gtk_scrollbar_parent_class)->style_updated (widget);
} }
/** /**

View File

@ -253,6 +253,13 @@ struct _GtkStyleContextClass
*/ */
#define GTK_STYLE_CLASS_SCROLLBAR "scrollbar" #define GTK_STYLE_CLASS_SCROLLBAR "scrollbar"
/**
* GTK_STYLE_CLASS_SCALE:
*
* A CSS class to match scale widgets.
*/
#define GTK_STYLE_CLASS_SCALE "scale"
/** /**
* GTK_STYLE_CLASS_HEADER: * GTK_STYLE_CLASS_HEADER:
* *
@ -295,6 +302,13 @@ struct _GtkStyleContextClass
*/ */
#define GTK_STYLE_CLASS_SPINNER "spinner" #define GTK_STYLE_CLASS_SPINNER "spinner"
/**
* GTK_STYLE_CLASS_MARK:
*
* A widget class defining marks in a widget, such as in scales
*/
#define GTK_STYLE_CLASS_MARK "mark"
/** /**
* GTK_STYLE_CLASS_NOTEBOOK: * GTK_STYLE_CLASS_NOTEBOOK:
* *