forked from AuroraMiddleware/gtk
checkbutton: Modernize
Stop implementing GtkContainer, and just use a box layout instead of doing our own thing manually.
This commit is contained in:
parent
af6e0ee2b3
commit
183431c918
@ -37,6 +37,7 @@
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkradiobutton.h"
|
||||
#include "gtkbuiltiniconprivate.h"
|
||||
#include "gtkboxlayout.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -110,7 +111,7 @@ gtk_check_button_update_node_state (GtkWidget *widget)
|
||||
|
||||
static void
|
||||
gtk_check_button_state_flags_changed (GtkWidget *widget,
|
||||
GtkStateFlags previous_state_flags)
|
||||
GtkStateFlags previous_state_flags)
|
||||
{
|
||||
gtk_check_button_update_node_state (widget);
|
||||
|
||||
@ -127,121 +128,6 @@ gtk_check_button_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (gtk_check_button_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_add (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
_gtk_bin_set_child (GTK_BIN (container), widget);
|
||||
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
|
||||
gtk_widget_insert_after (widget, GTK_WIDGET (container), NULL);
|
||||
else
|
||||
gtk_widget_set_parent (widget, GTK_WIDGET (container));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_remove (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
_gtk_bin_set_child (GTK_BIN (container), NULL);
|
||||
gtk_widget_unparent (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
int for_size,
|
||||
int *minimum,
|
||||
int *natural,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
|
||||
GtkWidget *child;
|
||||
int indicator_min = 0;
|
||||
int indicator_nat = 0;
|
||||
int child_min = 0;
|
||||
int child_nat = 0;
|
||||
|
||||
|
||||
*minimum = 0;
|
||||
*natural = 0;
|
||||
|
||||
if (priv->draw_indicator)
|
||||
{
|
||||
gtk_widget_measure (priv->indicator_widget, orientation, for_size,
|
||||
&indicator_min, &indicator_nat, NULL, NULL);
|
||||
}
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
|
||||
if (child)
|
||||
{
|
||||
gtk_widget_measure (child, orientation, for_size,
|
||||
&child_min, &child_nat, minimum_baseline, natural_baseline);
|
||||
}
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
*minimum = indicator_min + child_min;
|
||||
*natural = indicator_nat + child_nat;
|
||||
}
|
||||
else /* VERTICAL */
|
||||
{
|
||||
*minimum = MAX (indicator_min, child_min);
|
||||
*natural = MAX (indicator_nat, child_nat);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_size_allocate (GtkWidget *widget,
|
||||
int width,
|
||||
int height,
|
||||
int baseline)
|
||||
{
|
||||
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
|
||||
GtkAllocation child_alloc = { 0 };
|
||||
GtkWidget *child;
|
||||
gboolean is_rtl = _gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
int x = 0;
|
||||
|
||||
if (priv->draw_indicator)
|
||||
{
|
||||
child_alloc.y = 0;
|
||||
child_alloc.height = height;
|
||||
|
||||
gtk_widget_measure (priv->indicator_widget, GTK_ORIENTATION_HORIZONTAL, -1,
|
||||
&child_alloc.width, NULL, NULL, NULL);
|
||||
|
||||
if (is_rtl)
|
||||
{
|
||||
x = 0;
|
||||
child_alloc.x = width - child_alloc.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = child_alloc.width;
|
||||
child_alloc.x = 0;
|
||||
}
|
||||
|
||||
gtk_widget_size_allocate (priv->indicator_widget, &child_alloc, baseline);
|
||||
}
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child)
|
||||
{
|
||||
child_alloc.x = x;
|
||||
child_alloc.y = 0;
|
||||
child_alloc.width = width - child_alloc.width; /* Indicator width */
|
||||
child_alloc.height = height;
|
||||
|
||||
gtk_widget_size_allocate (child, &child_alloc, baseline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
gtk_check_button_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
@ -285,45 +171,17 @@ gtk_check_button_get_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_direction_changed (GtkWidget *widget,
|
||||
GtkTextDirection previous_direction)
|
||||
{
|
||||
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
|
||||
|
||||
if (!priv->indicator_widget)
|
||||
return;
|
||||
|
||||
if (previous_direction == GTK_TEXT_DIR_LTR)
|
||||
{
|
||||
/* Now RTL -> Move the indicator to the right */
|
||||
gtk_widget_insert_before (priv->indicator_widget, widget, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Now LTR -> Move the indicator to the left */
|
||||
gtk_widget_insert_after (priv->indicator_widget, widget, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_check_button_class_init (GtkCheckButtonClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
|
||||
|
||||
object_class->finalize = gtk_check_button_finalize;
|
||||
object_class->set_property = gtk_check_button_set_property;
|
||||
object_class->get_property = gtk_check_button_get_property;
|
||||
|
||||
widget_class->measure = gtk_check_button_measure;
|
||||
widget_class->size_allocate = gtk_check_button_size_allocate;
|
||||
widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
|
||||
widget_class->direction_changed = gtk_check_button_direction_changed;
|
||||
|
||||
container_class->add = gtk_check_button_add;
|
||||
container_class->remove = gtk_check_button_remove;
|
||||
|
||||
props[PROP_DRAW_INDICATOR] =
|
||||
g_param_spec_boolean ("draw-indicator",
|
||||
@ -341,6 +199,7 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
|
||||
|
||||
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
|
||||
|
||||
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
||||
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CHECK_BOX);
|
||||
gtk_widget_class_set_css_name (widget_class, I_("checkbutton"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user