combobox: Put the button in a box

This is so we can put the entry into the box in the next commit.
This commit is contained in:
Benjamin Otte 2016-03-01 18:29:22 +01:00
parent 04d9577cb7
commit c3d3bf61e4
2 changed files with 28 additions and 20 deletions

View File

@ -124,6 +124,7 @@ struct _GtkComboBoxPrivate
GtkWidget *cell_view; GtkWidget *cell_view;
GtkWidget *box;
GtkWidget *button; GtkWidget *button;
GtkWidget *arrow; GtkWidget *arrow;
@ -480,7 +481,7 @@ gtk_combo_box_real_get_width (GtkWidget *widget,
else else
gtk_widget_get_preferred_width (child, &child_min, &child_nat); gtk_widget_get_preferred_width (child, &child_min, &child_nat);
gtk_widget_get_preferred_width (priv->button, gtk_widget_get_preferred_width (priv->box,
&but_min, &but_nat); &but_min, &but_nat);
*minimum_size = child_min + but_min; *minimum_size = child_min + but_min;
@ -503,14 +504,14 @@ gtk_combo_box_real_get_height (GtkWidget *widget,
if (child == priv->cell_view) if (child == priv->cell_view)
{ {
gtk_widget_get_preferred_height_for_width (priv->button, gtk_widget_get_preferred_height_for_width (priv->box,
avail_size, avail_size,
&min_height, &nat_height); &min_height, &nat_height);
} }
else else
{ {
gtk_widget_get_preferred_width (priv->button, &but_width, NULL); gtk_widget_get_preferred_width (priv->box, &but_width, NULL);
gtk_widget_get_preferred_height_for_width (priv->button, gtk_widget_get_preferred_height_for_width (priv->box,
but_width, but_width,
&but_height, NULL); &but_height, NULL);
@ -564,13 +565,13 @@ gtk_combo_box_allocate (GtkCssGadget *gadget,
if (child_widget == priv->cell_view) if (child_widget == priv->cell_view)
{ {
child = *allocation; child = *allocation;
gtk_widget_size_allocate (priv->button, &child); gtk_widget_size_allocate (priv->box, &child);
} }
else else
{ {
GtkAllocation button_allocation; GtkAllocation button_allocation;
gtk_widget_get_preferred_size (priv->button, gtk_widget_get_preferred_size (priv->box,
&req, NULL); &req, NULL);
if (is_rtl) if (is_rtl)
@ -584,7 +585,7 @@ gtk_combo_box_allocate (GtkCssGadget *gadget,
button_allocation.height = allocation->height; button_allocation.height = allocation->height;
button_allocation.height = MAX (1, button_allocation.height); button_allocation.height = MAX (1, button_allocation.height);
gtk_widget_size_allocate (priv->button, gtk_widget_size_allocate (priv->box,
&button_allocation); &button_allocation);
if (is_rtl) if (is_rtl)
@ -652,7 +653,7 @@ gtk_combo_box_render (GtkCssGadget *gadget,
GtkWidget *child; GtkWidget *child;
gtk_container_propagate_draw (GTK_CONTAINER (widget), gtk_container_propagate_draw (GTK_CONTAINER (widget),
priv->button, cr); priv->box, cr);
child = gtk_bin_get_child (GTK_BIN (widget)); child = gtk_bin_get_child (GTK_BIN (widget));
@ -1370,6 +1371,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
GTK_PARAM_READABLE|G_PARAM_DEPRECATED)); GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkcombobox.ui"); gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkcombobox.ui");
gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, box);
gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, button); gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, button);
gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, arrow); gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, arrow);
gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_button_toggled); gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_button_toggled);
@ -2723,8 +2725,8 @@ gtk_combo_box_forall (GtkContainer *container,
if (include_internals) if (include_internals)
{ {
if (priv->button) if (priv->box)
(* callback) (priv->button, callback_data); (* callback) (priv->box, callback_data);
} }
child = gtk_bin_get_child (GTK_BIN (container)); child = gtk_bin_get_child (GTK_BIN (container));
@ -4391,12 +4393,13 @@ gtk_combo_box_destroy (GtkWidget *widget)
priv->popup_idle_id = 0; priv->popup_idle_id = 0;
} }
if (priv->button) if (priv->box)
{ {
/* destroy things (unparent will kill the latest ref from us) /* destroy things (unparent will kill the latest ref from us)
* last unref on button will destroy the arrow * last unref on button will destroy the arrow
*/ */
gtk_widget_unparent (priv->button); gtk_widget_unparent (priv->box);
priv->box = NULL;
priv->button = NULL; priv->button = NULL;
priv->arrow = NULL; priv->arrow = NULL;
if (priv->cell_view) if (priv->cell_view)

View File

@ -3,20 +3,25 @@
<!-- interface-requires gtk+ 3.10 --> <!-- interface-requires gtk+ 3.10 -->
<template class="GtkComboBox" parent="GtkBin"> <template class="GtkComboBox" parent="GtkBin">
<child> <child>
<object class="GtkToggleButton" id="button"> <object class="GtkBox" id="box">
<property name="visible">1</property> <property name="visible">1</property>
<signal name="toggled" handler="gtk_combo_box_button_toggled" swapped="no"/>
<child> <child>
<object class="GtkBox"> <object class="GtkToggleButton" id="button">
<property name="visible">1</property> <property name="visible">1</property>
<signal name="toggled" handler="gtk_combo_box_button_toggled" swapped="no"/>
<child> <child>
<object class="GtkIcon" id="arrow"> <object class="GtkBox">
<property name="visible">1</property> <property name="visible">1</property>
<property name="css_name">arrow</property> <child>
<object class="GtkIcon" id="arrow">
<property name="visible">1</property>
<property name="css_name">arrow</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object> </object>
<packing>
<property name="pack_type">end</property>
</packing>
</child> </child>
</object> </object>
</child> </child>