radiobutton: Port radio buttons to gadgets

This was already mostly done by inheritance from GtkCheckButton.
To complete it, stop using the draw_indicator vfunc for radio
buttons, and instead make the indicator gadget draw either a
check or radio.
This commit is contained in:
Matthias Clasen 2015-12-14 21:43:20 -05:00
parent 233179d374
commit a52c3a3db9
2 changed files with 12 additions and 71 deletions

View File

@ -104,8 +104,6 @@ static gboolean gtk_check_button_draw (GtkWidget *widget,
cairo_t *cr);
static void gtk_check_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr);
static void gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr);
static void gtk_check_button_measure (GtkCssGadget *gadget,
GtkOrientation orientation,
@ -215,8 +213,6 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
widget_class->direction_changed = gtk_check_button_direction_changed;
class->draw_indicator = gtk_real_check_button_draw_indicator;
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("indicator-size",
P_("Indicator Size"),
@ -787,27 +783,19 @@ gtk_check_button_draw (GtkWidget *widget,
return FALSE;
}
static void
gtk_check_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr)
{
GtkCheckButtonClass *class = GTK_CHECK_BUTTON_GET_CLASS (check_button);
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
if (class->draw_indicator)
class->draw_indicator (check_button, cr);
else
gtk_css_gadget_draw (priv->indicator_gadget, cr);
}
static void
gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
gtk_css_gadget_draw (priv->indicator_gadget, cr);
}
static gboolean
gtk_check_button_render_check (GtkCssGadget *gadget,
cairo_t *cr,
@ -820,13 +808,20 @@ gtk_check_button_render_check (GtkCssGadget *gadget,
GtkWidget *widget;
GtkStyleContext *context;
GtkCheckButtonPrivate *priv;
GtkCssNode *css_node;
widget = gtk_css_gadget_get_owner (gadget);
priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
context = gtk_widget_get_style_context (widget);
gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (priv->indicator_gadget));
gtk_render_check (context, cr, x, y, width, height);
css_node = gtk_css_gadget_get_node (priv->indicator_gadget);
gtk_style_context_save_to_node (context, css_node);
if (strcmp (gtk_css_node_get_name (css_node), "check") == 0)
gtk_render_check (context, cr, x, y, width, height);
else
gtk_render_option (context, cr, x, y, width, height);
gtk_style_context_restore (context);
return FALSE;

View File

@ -145,8 +145,6 @@ static void gtk_radio_button_destroy (GtkWidget *widget);
static gboolean gtk_radio_button_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_radio_button_clicked (GtkButton *button);
static void gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr);
static void gtk_radio_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
@ -165,13 +163,11 @@ gtk_radio_button_class_init (GtkRadioButtonClass *class)
{
GObjectClass *gobject_class;
GtkButtonClass *button_class;
GtkCheckButtonClass *check_button_class;
GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass*) class;
button_class = (GtkButtonClass*) class;
check_button_class = (GtkCheckButtonClass*) class;
gobject_class->set_property = gtk_radio_button_set_property;
gobject_class->get_property = gtk_radio_button_get_property;
@ -195,8 +191,6 @@ gtk_radio_button_class_init (GtkRadioButtonClass *class)
button_class->clicked = gtk_radio_button_clicked;
check_button_class->draw_indicator = gtk_radio_button_draw_indicator;
class->group_changed = NULL;
/**
@ -799,51 +793,3 @@ gtk_radio_button_clicked (GtkButton *button)
g_object_unref (button);
}
static void
gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
cairo_t *cr)
{
GtkAllocation allocation;
GtkWidget *widget;
GtkButton *button;
GtkStyleContext *context;
gint x, y;
gint indicator_size, indicator_spacing;
gint baseline;
guint border_width;
GtkCssNode *css_node;
widget = GTK_WIDGET (check_button);
button = GTK_BUTTON (check_button);
context = gtk_widget_get_style_context (widget);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
_gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
gtk_widget_get_allocation (widget, &allocation);
baseline = gtk_widget_get_allocated_baseline (widget);
x = indicator_spacing + border_width;
if (baseline == -1)
y = (allocation.height - indicator_size) / 2;
else
y = CLAMP (baseline - indicator_size * button->priv->baseline_align,
0, allocation.height - indicator_size);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x = allocation.width - (indicator_size + x);
css_node = gtk_check_button_get_indicator_node (check_button);
gtk_style_context_save_to_node (context, css_node);
gtk_render_background (context, cr,
border_width, border_width,
allocation.width - (2 * border_width),
allocation.height - (2 * border_width));
gtk_render_option (context, cr,
x, y, indicator_size, indicator_size);
gtk_style_context_restore (context);
}