[gtk+/wip/otte/gadget: 8/8] spinbutton: Port the buttons to gadgets
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/gadget: 8/8] spinbutton: Port the buttons to gadgets
- Date: Sat, 21 Nov 2015 05:16:39 +0000 (UTC)
commit 73460cd728aaf67f02d5ffc1137390d22e0bfbc7
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 20 01:17:06 2015 +0100
spinbutton: Port the buttons to gadgets
gtk/gtkspinbutton.c | 253 ++++++++++++++++++++++++++-------------------------
1 files changed, 131 insertions(+), 122 deletions(-)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 8b5f60d..cde2e5a 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -37,6 +37,8 @@
#include "gtkadjustment.h"
#include "gtkbindings.h"
+#include "gtkcssgadgetprivate.h"
+#include "gtkcsscustomgadgetprivate.h"
#include "gtkentryprivate.h"
#include "gtkiconhelperprivate.h"
#include "gtkicontheme.h"
@@ -183,8 +185,8 @@ struct _GtkSpinButtonPrivate
GdkWindow *up_panel;
GtkCssNode *entry_node;
- GtkCssNode *down_node;
- GtkCssNode *up_node;
+ GtkCssGadget *down_button;
+ GtkCssGadget *up_button;
GdkWindow *click_child;
GdkWindow *in_child;
@@ -762,21 +764,21 @@ update_node_ordering (GtkSpinButton *spin_button)
if (gtk_widget_get_direction (GTK_WIDGET (spin_button)) == GTK_TEXT_DIR_LTR)
{
first = priv->entry_node;
- middle = priv->down_node;
- last = priv->up_node;
+ middle = gtk_css_gadget_get_node (priv->down_button);
+ last = gtk_css_gadget_get_node (priv->up_button);
}
else
{
- first = priv->up_node;
- middle = priv->down_node;
+ first = gtk_css_gadget_get_node (priv->up_button);
+ middle = gtk_css_gadget_get_node (priv->down_button);
last = priv->entry_node;
}
}
else
{
- first = priv->up_node;
+ first = gtk_css_gadget_get_node (priv->up_button);
middle = priv->entry_node;
- last = priv->down_node;
+ last = gtk_css_gadget_get_node (priv->down_button);
}
gtk_css_node_insert_before (widget_node, first, middle);
@@ -784,6 +786,79 @@ update_node_ordering (GtkSpinButton *spin_button)
}
static void
+gtk_spin_button_get_panel_size (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum,
+ gint *natural,
+ gint *minimum_baseline,
+ gint *natural_baseline,
+ gpointer unused)
+{
+ gint icon_size, w, h;
+
+ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
+ icon_size = MAX (w, h);
+
+ *minimum = icon_size;
+ *natural = icon_size;
+ if (minimum_baseline)
+ *minimum_baseline = -1;
+ if (natural_baseline)
+ *natural_baseline = -1;
+}
+
+static gboolean
+gtk_spin_button_draw_panel (GtkCssGadget *gadget,
+ cairo_t *cr,
+ int x,
+ int y,
+ int width,
+ int height,
+ gpointer data)
+{
+ GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
+ GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
+ GtkSpinButtonPrivate *priv = spin_button->priv;
+ GtkStyleContext *context;
+ gint icon_width, icon_height;
+ GtkIconHelper *icon_helper;
+
+ context = gtk_widget_get_style_context (widget);
+
+ cairo_save (cr);
+
+ icon_helper = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_window (icon_helper, gtk_widget_get_window (widget));
+ _gtk_icon_helper_set_use_fallback (icon_helper, TRUE);
+
+ if (gadget == priv->down_button)
+ {
+ gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (priv->down_button));
+ _gtk_icon_helper_set_icon_name (icon_helper, "list-remove-symbolic", GTK_ICON_SIZE_MENU);
+ }
+ else
+ {
+ gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (priv->up_button));
+ _gtk_icon_helper_set_icon_name (icon_helper, "list-add-symbolic", GTK_ICON_SIZE_MENU);
+ }
+
+ _gtk_icon_helper_get_size (icon_helper, context, &icon_width, &icon_height);
+
+ x += floor ((width - icon_width) / 2.0);
+ y += floor ((height - icon_height) / 2.0);
+
+ _gtk_icon_helper_draw (icon_helper, context, cr, x, y);
+ cairo_restore (cr);
+
+ gtk_style_context_restore (context);
+
+ g_object_unref (icon_helper);
+
+ return FALSE;
+}
+
+static void
gtk_spin_button_init (GtkSpinButton *spin_button)
{
GtkSpinButtonPrivate *priv;
@@ -822,21 +897,31 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
g_signal_connect_object (priv->entry_node, "style-changed", G_CALLBACK (node_style_changed_cb),
spin_button, 0);
g_object_unref (priv->entry_node);
- priv->down_node = gtk_css_node_new ();
- gtk_css_node_set_name (priv->down_node, I_("button"));
- gtk_css_node_set_parent (priv->down_node, widget_node);
- gtk_css_node_add_class (priv->down_node, g_quark_from_static_string ("down"));
- gtk_css_node_set_state (priv->down_node, gtk_css_node_get_state (widget_node));
- g_signal_connect_object (priv->down_node, "style-changed", G_CALLBACK (node_style_changed_cb),
spin_button, 0);
- g_object_unref (priv->down_node);
-
- priv->up_node = gtk_css_node_new ();
- gtk_css_node_set_name (priv->up_node, I_("button"));
- gtk_css_node_set_parent (priv->up_node, widget_node);
- gtk_css_node_add_class (priv->up_node, g_quark_from_static_string ("up"));
- gtk_css_node_set_state (priv->up_node, gtk_css_node_get_state (widget_node));
- g_signal_connect_object (priv->up_node, "style-changed", G_CALLBACK (node_style_changed_cb), spin_button,
0);
- g_object_unref (priv->up_node);
+ priv->down_button = gtk_css_custom_gadget_new ("button",
+ GTK_WIDGET (spin_button),
+ NULL,
+ NULL,
+ gtk_spin_button_get_panel_size,
+ NULL,
+ gtk_spin_button_draw_panel,
+ NULL,
+ NULL);
+ gtk_css_gadget_add_class (priv->down_button, "down");
+ gtk_css_node_set_parent (gtk_css_gadget_get_node (priv->down_button), widget_node);
+ gtk_css_node_set_state (gtk_css_gadget_get_node (priv->down_button), gtk_css_node_get_state (widget_node));
+
+ priv->up_button = gtk_css_custom_gadget_new ("button",
+ GTK_WIDGET (spin_button),
+ NULL,
+ NULL,
+ gtk_spin_button_get_panel_size,
+ NULL,
+ gtk_spin_button_draw_panel,
+ NULL,
+ NULL);
+ gtk_css_gadget_add_class (priv->up_button, "up");
+ gtk_css_node_set_parent (gtk_css_gadget_get_node (priv->down_button), widget_node);
+ gtk_css_node_set_state (gtk_css_gadget_get_node (priv->down_button), gtk_css_node_get_state (widget_node));
gtk_spin_button_set_adjustment (spin_button, NULL);
@@ -966,47 +1051,13 @@ update_node_state (GtkSpinButton *spin_button)
{
GtkSpinButtonPrivate *priv = spin_button->priv;
- gtk_css_node_set_state (priv->up_node,
+ gtk_css_node_set_state (gtk_css_gadget_get_node (priv->up_button),
gtk_spin_button_panel_get_state (spin_button, UP_PANEL));
- gtk_css_node_set_state (priv->down_node,
+ gtk_css_node_set_state (gtk_css_gadget_get_node (priv->down_button),
gtk_spin_button_panel_get_state (spin_button, DOWN_PANEL));
}
static void
-gtk_spin_button_panel_get_size (GtkSpinButton *spin_button,
- GdkWindow *panel,
- gint *width,
- gint *height)
-{
- GtkSpinButtonPrivate *priv = spin_button->priv;
- GtkBorder button_padding, button_border;
- GtkStyleContext *context;
- gint icon_size, w, h;
-
- gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
- icon_size = MAX (w, h);
-
- context = gtk_widget_get_style_context (GTK_WIDGET (spin_button));
- if (panel == priv->up_panel)
- gtk_style_context_save_to_node (context, priv->up_node);
- else
- gtk_style_context_save_to_node (context, priv->down_node);
-
- gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &button_padding);
- gtk_style_context_get_border (context, gtk_style_context_get_state (context), &button_border);
-
- gtk_style_context_restore (context);
-
- if (width)
- *width = icon_size + button_padding.left + button_padding.right +
- button_border.left + button_border.right;
-
- if (height)
- *height = icon_size + button_padding.top + button_padding.bottom +
- button_border.top + button_border.bottom;
-}
-
-static void
gtk_spin_button_panel_get_allocations (GtkSpinButton *spin_button,
GtkAllocation *down_allocation_out,
GtkAllocation *up_allocation_out)
@@ -1029,8 +1080,10 @@ gtk_spin_button_panel_get_allocations (GtkSpinButton *spin_button,
state = gtk_style_context_get_state (context);
gtk_style_context_get_border (context, state, &border);
- gtk_spin_button_panel_get_size (spin_button, priv->down_panel, &down_panel_width, &down_panel_height);
- gtk_spin_button_panel_get_size (spin_button, priv->up_panel, &up_panel_width, &up_panel_height);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_HORIZONTAL, -1, &down_panel_width,
NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_VERTICAL, -1, &down_panel_height,
NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_HORIZONTAL, -1, &up_panel_width, NULL,
NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_VERTICAL, -1, &up_panel_height, NULL,
NULL, NULL);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
@@ -1079,58 +1132,6 @@ gtk_spin_button_panel_get_allocations (GtkSpinButton *spin_button,
}
static void
-gtk_spin_button_panel_draw (GtkSpinButton *spin_button,
- cairo_t *cr,
- GdkWindow *panel)
-{
- GtkSpinButtonPrivate *priv = spin_button->priv;
- GtkStyleContext *context;
- GtkWidget *widget;
- gdouble width, height, x, y;
- gint icon_width, icon_height;
- GtkIconHelper *icon_helper;
-
- widget = GTK_WIDGET (spin_button);
- context = gtk_widget_get_style_context (widget);
-
- cairo_save (cr);
- gtk_cairo_transform_to_window (cr, widget, panel);
-
- height = gdk_window_get_height (panel);
- width = gdk_window_get_width (panel);
-
- icon_helper = _gtk_icon_helper_new ();
- _gtk_icon_helper_set_window (icon_helper, panel);
- _gtk_icon_helper_set_use_fallback (icon_helper, TRUE);
-
- if (panel == priv->down_panel)
- {
- gtk_style_context_save_to_node (context, priv->down_node);
- _gtk_icon_helper_set_icon_name (icon_helper, "list-remove-symbolic", GTK_ICON_SIZE_MENU);
- }
- else
- {
- gtk_style_context_save_to_node (context, priv->up_node);
- _gtk_icon_helper_set_icon_name (icon_helper, "list-add-symbolic", GTK_ICON_SIZE_MENU);
- }
-
- _gtk_icon_helper_get_size (icon_helper, context, &icon_width, &icon_height);
-
- gtk_render_background (context, cr, 0, 0, width, height);
- gtk_render_frame (context, cr, 0, 0, width, height);
-
- x = floor ((width - icon_width) / 2.0);
- y = floor ((height - icon_height) / 2.0);
-
- _gtk_icon_helper_draw (icon_helper, context, cr, x, y);
- cairo_restore (cr);
-
- gtk_style_context_restore (context);
-
- g_object_unref (icon_helper);
-}
-
-static void
gtk_spin_button_realize (GtkWidget *widget)
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
@@ -1342,8 +1343,8 @@ gtk_spin_button_get_preferred_width (GtkWidget *widget,
gint down_panel_width;
gint up_panel_width;
- gtk_spin_button_panel_get_size (spin_button, priv->down_panel, &down_panel_width, NULL);
- gtk_spin_button_panel_get_size (spin_button, priv->up_panel, &up_panel_width, NULL);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_HORIZONTAL, -1,
&down_panel_width, NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_HORIZONTAL, -1, &up_panel_width,
NULL, NULL, NULL);
*minimum += up_panel_width + down_panel_width;
*natural += up_panel_width + down_panel_width;
@@ -1371,8 +1372,8 @@ gtk_spin_button_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
gint down_panel_height;
gint up_panel_height;
- gtk_spin_button_panel_get_size (spin_button, priv->down_panel, NULL, &down_panel_height);
- gtk_spin_button_panel_get_size (spin_button, priv->up_panel, NULL, &up_panel_height);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_VERTICAL, -1,
&down_panel_height, NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_VERTICAL, -1, &up_panel_height,
NULL, NULL, NULL);
*minimum += up_panel_height + down_panel_height;
*natural += up_panel_height + down_panel_height;
@@ -1399,6 +1400,7 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = spin->priv;
GtkAllocation down_panel_allocation, up_panel_allocation;
+ GtkAllocation down_clip, up_clip, clip;
gtk_widget_set_allocation (widget, allocation);
@@ -1406,6 +1408,9 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
gtk_spin_button_panel_get_allocations (spin, &down_panel_allocation, &up_panel_allocation);
+ gtk_css_gadget_allocate (priv->down_button, &down_panel_allocation, -1, &down_clip);
+ gtk_css_gadget_allocate (priv->up_button, &up_panel_allocation, -1, &up_clip);
+
if (gtk_widget_get_realized (widget))
{
gdk_window_move_resize (priv->down_panel,
@@ -1421,7 +1426,9 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
up_panel_allocation.height);
}
- gtk_widget_queue_draw (GTK_WIDGET (spin));
+ gdk_rectangle_union (&down_clip, &up_clip, &clip);
+
+ _gtk_widget_set_simple_clip (widget, &clip);
}
static gint
@@ -1434,8 +1441,8 @@ gtk_spin_button_draw (GtkWidget *widget,
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->draw (widget, cr);
/* Draw the buttons */
- gtk_spin_button_panel_draw (spin, cr, priv->down_panel);
- gtk_spin_button_panel_draw (spin, cr, priv->up_panel);
+ gtk_css_gadget_draw (priv->down_button, cr);
+ gtk_css_gadget_draw (priv->up_button, cr);
return FALSE;
}
@@ -1917,8 +1924,10 @@ gtk_spin_button_get_text_area_size (GtkEntry *entry,
GTK_ENTRY_CLASS (gtk_spin_button_parent_class)->get_text_area_size (entry, x, y, width, height);
- gtk_spin_button_panel_get_size (GTK_SPIN_BUTTON (entry), priv->up_panel, &up_panel_width,
&up_panel_height);
- gtk_spin_button_panel_get_size (GTK_SPIN_BUTTON (entry), priv->down_panel, &down_panel_width,
&down_panel_height);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_HORIZONTAL, -1, &down_panel_width,
NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->down_button, GTK_ORIENTATION_VERTICAL, -1, &down_panel_height,
NULL, NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_HORIZONTAL, -1, &up_panel_width, NULL,
NULL, NULL);
+ gtk_css_gadget_get_preferred_size (priv->up_button, GTK_ORIENTATION_VERTICAL, -1, &up_panel_height, NULL,
NULL, NULL);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]