spinbutton: Make the entry gadget be the entry's gadget

This is a big and somewhat evil hack: We replace the entry's gadget's
node with the spinbutton's entry node.
This commit is contained in:
Benjamin Otte 2016-01-21 01:22:41 +01:00
parent c7c17abdb9
commit a6845091f9
5 changed files with 24 additions and 25 deletions

View File

@ -193,12 +193,14 @@ gtk_css_gadget_unset_node (GtkCssGadget *gadget)
}
}
static void
void
gtk_css_gadget_set_node (GtkCssGadget *gadget,
GtkCssNode *node)
{
GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
gtk_css_gadget_unset_node (gadget);
if (node != NULL)
priv->node = g_object_ref (node);
else

View File

@ -78,6 +78,8 @@ GtkCssNode * gtk_css_gadget_get_node (GtkCssGadget
GtkCssStyle * gtk_css_gadget_get_style (GtkCssGadget *gadget);
GtkWidget * gtk_css_gadget_get_owner (GtkCssGadget *gadget);
void gtk_css_gadget_set_node (GtkCssGadget *gadget,
GtkCssNode *node);
void gtk_css_gadget_set_visible (GtkCssGadget *gadget,
gboolean visible);
gboolean gtk_css_gadget_get_visible (GtkCssGadget *gadget);

View File

@ -6873,6 +6873,12 @@ _gtk_entry_get_im_context (GtkEntry *entry)
return entry->priv->im_context;
}
GtkCssGadget *
gtk_entry_get_gadget (GtkEntry *entry)
{
return entry->priv->gadget;
}
static gint
gtk_entry_find_position (GtkEntry *entry,
gint x)

View File

@ -23,6 +23,7 @@
#include <gtk/gtkliststore.h>
#include <gtk/gtkentrycompletion.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkcssgadgetprivate.h>
G_BEGIN_DECLS
@ -86,6 +87,7 @@ gchar* _gtk_entry_get_display_text (GtkEntry *entry,
void _gtk_entry_get_borders (GtkEntry *entry,
GtkBorder *borders);
GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry);
GtkCssGadget* gtk_entry_get_gadget (GtkEntry *entry);
void _gtk_entry_grab_focus (GtkEntry *entry,
gboolean select_all);

View File

@ -184,7 +184,6 @@ struct _GtkSpinButtonPrivate
GdkWindow *down_panel;
GdkWindow *up_panel;
GtkCssNode *entry_node;
GtkCssGadget *down_button;
GtkCssGadget *up_button;
@ -727,17 +726,6 @@ swipe_gesture_update (GtkGesture *gesture,
gtk_spin_button_real_spin (spin_button, -vel_y / 20);
}
static void
node_style_changed_cb (GtkCssNode *node,
GtkCssStyleChange *change,
GtkWidget *widget)
{
if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP))
gtk_widget_queue_resize (widget);
else
gtk_widget_queue_draw (widget);
}
static void
update_node_ordering (GtkSpinButton *spin_button)
{
@ -751,7 +739,7 @@ update_node_ordering (GtkSpinButton *spin_button)
{
if (gtk_widget_get_direction (GTK_WIDGET (spin_button)) == GTK_TEXT_DIR_LTR)
{
first = priv->entry_node;
first = gtk_css_gadget_get_node (gtk_entry_get_gadget (GTK_ENTRY (spin_button)));
middle = gtk_css_gadget_get_node (priv->down_button);
last = gtk_css_gadget_get_node (priv->up_button);
}
@ -759,13 +747,13 @@ update_node_ordering (GtkSpinButton *spin_button)
{
first = gtk_css_gadget_get_node (priv->up_button);
middle = gtk_css_gadget_get_node (priv->down_button);
last = priv->entry_node;
last = gtk_css_gadget_get_node (gtk_entry_get_gadget (GTK_ENTRY (spin_button)));
}
}
else
{
first = gtk_css_gadget_get_node (priv->up_button);
middle = priv->entry_node;
middle = gtk_css_gadget_get_node (gtk_entry_get_gadget (GTK_ENTRY (spin_button)));
last = gtk_css_gadget_get_node (priv->down_button);
}
@ -777,7 +765,7 @@ static void
gtk_spin_button_init (GtkSpinButton *spin_button)
{
GtkSpinButtonPrivate *priv;
GtkCssNode *widget_node;
GtkCssNode *widget_node, *entry_node;
spin_button->priv = gtk_spin_button_get_instance_private (spin_button);
priv = spin_button->priv;
@ -805,12 +793,12 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
widget_node = gtk_widget_get_css_node (GTK_WIDGET (spin_button));
priv->entry_node = gtk_css_node_new ();
gtk_css_node_set_name (priv->entry_node, I_("entry"));
gtk_css_node_set_parent (priv->entry_node, widget_node);
gtk_css_node_set_state (priv->entry_node, gtk_css_node_get_state (widget_node));
g_signal_connect_object (priv->entry_node, "style-changed", G_CALLBACK (node_style_changed_cb), spin_button, 0);
g_object_unref (priv->entry_node);
entry_node = gtk_css_node_new ();
gtk_css_node_set_name (entry_node, I_("entry"));
gtk_css_node_set_parent (entry_node, widget_node);
gtk_css_node_set_state (entry_node, gtk_css_node_get_state (widget_node));
gtk_css_gadget_set_node (gtk_entry_get_gadget (GTK_ENTRY (spin_button)), entry_node);
g_object_unref (entry_node);
priv->down_button = gtk_icon_helper_new_named ("button",
GTK_WIDGET (spin_button));
@ -1409,7 +1397,6 @@ gtk_spin_button_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state)
{
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = spin->priv;
if (!gtk_widget_is_sensitive (widget))
{
@ -1417,7 +1404,7 @@ gtk_spin_button_state_flags_changed (GtkWidget *widget,
gtk_widget_queue_draw (GTK_WIDGET (spin));
}
gtk_css_node_set_state (priv->entry_node, gtk_widget_get_state_flags (widget));
gtk_css_gadget_set_state (gtk_entry_get_gadget (GTK_ENTRY (widget)), gtk_widget_get_state_flags (widget));
update_node_state (spin);
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->state_flags_changed (widget, previous_state);