forked from AuroraMiddleware/gtk
GtkCheckButton: Use GtkStyleContext for rendering.
This commit is contained in:
parent
04783534ed
commit
7478a77b04
@ -93,9 +93,18 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
|
|||||||
static void
|
static void
|
||||||
gtk_check_button_init (GtkCheckButton *check_button)
|
gtk_check_button_init (GtkCheckButton *check_button)
|
||||||
{
|
{
|
||||||
|
GtkStyleContext *context;
|
||||||
|
|
||||||
gtk_widget_set_has_window (GTK_WIDGET (check_button), FALSE);
|
gtk_widget_set_has_window (GTK_WIDGET (check_button), FALSE);
|
||||||
gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
|
gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
|
||||||
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
||||||
|
|
||||||
|
/* Remove the "button" class added in GtkButton constructor,
|
||||||
|
* since this widget implementation doesn't look like a button
|
||||||
|
* at all.
|
||||||
|
*/
|
||||||
|
context = gtk_widget_get_style_context (GTK_WIDGET (check_button));
|
||||||
|
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
@ -155,34 +164,33 @@ gtk_check_button_paint (GtkWidget *widget,
|
|||||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
||||||
if (gtk_widget_has_focus (widget))
|
if (gtk_widget_has_focus (widget))
|
||||||
{
|
{
|
||||||
GtkStateType state = gtk_widget_get_state (widget);
|
|
||||||
GtkStyle *style = gtk_widget_get_style (widget);
|
|
||||||
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
|
||||||
|
GtkStyleContext *context;
|
||||||
|
GtkStateFlags state;
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
state = gtk_widget_get_state_flags (widget);
|
||||||
|
|
||||||
|
gtk_style_context_set_state (context, state);
|
||||||
|
|
||||||
if (interior_focus && child && gtk_widget_get_visible (child))
|
if (interior_focus && child && gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
GtkAllocation child_allocation;
|
GtkAllocation child_allocation;
|
||||||
|
|
||||||
gtk_widget_get_allocation (child, &child_allocation);
|
gtk_widget_get_allocation (child, &child_allocation);
|
||||||
gtk_paint_focus (style, cr, state,
|
gtk_render_focus (context, cr,
|
||||||
widget, "checkbutton",
|
child_allocation.x - allocation.x - focus_width - focus_pad,
|
||||||
child_allocation.x - allocation.x - focus_width - focus_pad,
|
child_allocation.y - allocation.y - focus_width - focus_pad,
|
||||||
child_allocation.y - allocation.y - focus_width - focus_pad,
|
child_allocation.width + 2 * (focus_width + focus_pad),
|
||||||
child_allocation.width + 2 * (focus_width + focus_pad),
|
child_allocation.height + 2 * (focus_width + focus_pad));
|
||||||
child_allocation.height + 2 * (focus_width + focus_pad));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
gtk_render_focus (context, cr,
|
||||||
gtk_paint_focus (style, cr, state,
|
border_width, border_width,
|
||||||
widget, "checkbutton",
|
allocation.width - 2 * border_width,
|
||||||
border_width,
|
allocation.height - 2 * border_width);
|
||||||
border_width,
|
|
||||||
allocation.width - 2 * border_width,
|
|
||||||
allocation.height - 2 * border_width);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,8 +416,7 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
|
|||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
GtkButton *button;
|
GtkButton *button;
|
||||||
GtkToggleButton *toggle_button;
|
GtkToggleButton *toggle_button;
|
||||||
GtkStateType state_type;
|
GtkStateFlags state = 0;
|
||||||
GtkShadowType shadow_type;
|
|
||||||
gint x, y;
|
gint x, y;
|
||||||
gint indicator_size;
|
gint indicator_size;
|
||||||
gint indicator_spacing;
|
gint indicator_spacing;
|
||||||
@ -418,16 +425,14 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
|
|||||||
guint border_width;
|
guint border_width;
|
||||||
gboolean interior_focus;
|
gboolean interior_focus;
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GtkStyle *style;
|
GtkStyleContext *context;
|
||||||
GdkWindow *window;
|
|
||||||
|
|
||||||
widget = GTK_WIDGET (check_button);
|
widget = GTK_WIDGET (check_button);
|
||||||
button = GTK_BUTTON (check_button);
|
button = GTK_BUTTON (check_button);
|
||||||
toggle_button = GTK_TOGGLE_BUTTON (check_button);
|
toggle_button = GTK_TOGGLE_BUTTON (check_button);
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
style = gtk_widget_get_style (widget);
|
context = gtk_widget_get_style_context (widget);
|
||||||
window = gtk_widget_get_window (widget);
|
|
||||||
|
|
||||||
gtk_widget_style_get (widget,
|
gtk_widget_style_get (widget,
|
||||||
"interior-focus", &interior_focus,
|
"interior-focus", &interior_focus,
|
||||||
@ -447,37 +452,34 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
|
|||||||
x += focus_width + focus_pad;
|
x += focus_width + focus_pad;
|
||||||
|
|
||||||
if (gtk_toggle_button_get_inconsistent (toggle_button))
|
if (gtk_toggle_button_get_inconsistent (toggle_button))
|
||||||
shadow_type = GTK_SHADOW_ETCHED_IN;
|
state |= GTK_STATE_FLAG_INCONSISTENT;
|
||||||
else if (gtk_toggle_button_get_active (toggle_button))
|
else if (gtk_toggle_button_get_active (toggle_button))
|
||||||
shadow_type = GTK_SHADOW_IN;
|
state |= GTK_STATE_FLAG_ACTIVE;
|
||||||
else
|
|
||||||
shadow_type = GTK_SHADOW_OUT;
|
|
||||||
|
|
||||||
if (button->priv->activate_timeout || (button->priv->button_down && button->priv->in_button))
|
if (button->priv->activate_timeout || (button->priv->button_down && button->priv->in_button))
|
||||||
state_type = GTK_STATE_ACTIVE;
|
state |= GTK_STATE_FLAG_SELECTED;
|
||||||
else if (button->priv->in_button)
|
|
||||||
state_type = GTK_STATE_PRELIGHT;
|
if (button->priv->in_button)
|
||||||
|
state |= GTK_STATE_FLAG_PRELIGHT;
|
||||||
else if (!gtk_widget_is_sensitive (widget))
|
else if (!gtk_widget_is_sensitive (widget))
|
||||||
state_type = GTK_STATE_INSENSITIVE;
|
state |= GTK_STATE_FLAG_INSENSITIVE;
|
||||||
else
|
|
||||||
state_type = GTK_STATE_NORMAL;
|
|
||||||
|
|
||||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||||
x = allocation.width - (indicator_size + x);
|
x = allocation.width - (indicator_size + x);
|
||||||
|
|
||||||
if (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_PRELIGHT)
|
gtk_style_context_set_state (context, state);
|
||||||
{
|
|
||||||
|
|
||||||
gtk_paint_flat_box (style, cr, GTK_STATE_PRELIGHT,
|
if (state & GTK_STATE_FLAG_PRELIGHT)
|
||||||
GTK_SHADOW_ETCHED_OUT,
|
gtk_render_background (context, cr,
|
||||||
widget, "checkbutton",
|
border_width, border_width,
|
||||||
border_width, border_width,
|
allocation.width - (2 * border_width),
|
||||||
allocation.width - (2 * border_width),
|
allocation.height - (2 * border_width));
|
||||||
allocation.height - (2 * border_width));
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_paint_check (style, cr,
|
gtk_style_context_save (context);
|
||||||
state_type, shadow_type,
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
|
||||||
widget, "checkbutton",
|
|
||||||
x, y, indicator_size, indicator_size);
|
gtk_render_check (context, cr,
|
||||||
|
x, y, indicator_size, indicator_size);
|
||||||
|
|
||||||
|
gtk_style_context_restore (context);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user