[gtk+/wip/matthiasc/gadget] radiobutton: Port radio buttons to gadgets
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/gadget] radiobutton: Port radio buttons to gadgets
- Date: Fri, 4 Dec 2015 12:11:53 +0000 (UTC)
commit 6dd4d1800507433ee5d4e0c59a76c4fa90f287d6
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 4 07:08:52 2015 -0500
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.
gtk/gtkcheckbutton.c | 133 ++++++++++++++++++++++++--------------------------
gtk/gtkradiobutton.c | 54 --------------------
2 files changed, 64 insertions(+), 123 deletions(-)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 6de0509..3dd4a24 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -104,44 +104,42 @@ 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_get_content_size (GtkCssGadget *gadget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline,
- gpointer unused);
-static void gtk_check_button_allocate_contents (GtkCssGadget *gadget,
- const GtkAllocation *allocation,
- int baseline,
- GtkAllocation *out_clip,
- gpointer unused);
-static gboolean gtk_check_button_render_contents (GtkCssGadget *gadget,
- cairo_t *cr,
- int x,
- int y,
- int width,
- int height,
- gpointer data);
-static void gtk_check_button_get_check_size (GtkCssGadget *gadget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline,
- gpointer unused);
-static gboolean gtk_check_button_render_check (GtkCssGadget *gadget,
- cairo_t *cr,
- int x,
- int y,
- int width,
- int height,
- gpointer data);
+static void gtk_check_button_get_content_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline,
+ gpointer unused);
+static void gtk_check_button_allocate_contents (GtkCssGadget *gadget,
+ const GtkAllocation *allocation,
+ int baseline,
+ GtkAllocation *out_clip,
+ gpointer unused);
+static gboolean gtk_check_button_render_contents (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data);
+static void gtk_check_button_get_indicator_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline,
+ gpointer unused);
+static gboolean gtk_check_button_render_indicator (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data);
typedef struct {
GtkCssGadget *gadget;
@@ -189,8 +187,6 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
widget_class->draw = gtk_check_button_draw;
widget_class->state_flags_changed = gtk_check_button_state_flags_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"),
@@ -284,9 +280,9 @@ gtk_check_button_init (GtkCheckButton *check_button)
GTK_WIDGET (check_button),
priv->gadget,
NULL,
- gtk_check_button_get_check_size,
+ gtk_check_button_get_indicator_size,
NULL,
- gtk_check_button_render_check,
+ gtk_check_button_render_indicator,
NULL,
NULL);
}
@@ -510,14 +506,14 @@ gtk_check_button_get_content_size (GtkCssGadget *gadget,
}
static void
-gtk_check_button_get_check_size (GtkCssGadget *gadget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline,
- gpointer unused)
+gtk_check_button_get_indicator_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline,
+ gpointer unused)
{
GtkWidget *widget;
gint indicator_size;
@@ -733,46 +729,45 @@ 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,
- int x,
- int y,
- int width,
- int height,
- gpointer data)
+gtk_check_button_render_indicator (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data)
{
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;
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index 148038b..53191a4 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -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);
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]