+ gint req_height;
+ gint down_panel_width, down_panel_height;
+ gint up_panel_width, up_panel_height;
+ GtkStyleContext *context;
+ GtkBorder border;
+
+ gtk_widget_get_allocation (widget, &spin_allocation);
+ gtk_widget_get_preferred_size (widget, &requisition, NULL);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (spin_button));
+ gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &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);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
+
+ /* both panels have the same size, and they're as tall as the entry allocation,
+ * excluding margins
+ */
+ allocation.height = MIN (req_height, spin_allocation.height) - border.top - border.bottom;
+ allocation.y = spin_allocation.y + border.top + (spin_allocation.height - req_height) / 2;
+ down_allocation = up_allocation = allocation;
+
+ down_allocation.width = down_panel_width;
+ up_allocation.width = up_panel_width;
+
+ /* invert x axis allocation for RTL */
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ {
+ up_allocation.x = spin_allocation.x + border.left;
+ down_allocation.x = up_allocation.x + up_panel_width;
+ }
+ else
+ {
+ up_allocation.x = spin_allocation.x + spin_allocation.width - up_panel_width - border.right;
+ down_allocation.x = up_allocation.x - down_panel_width;
+ }
+ }
+ else
+ {
+ /* both panels have the same size, and they're as wide as the entry allocation */
+ allocation.width = spin_allocation.width;
+ allocation.x = spin_allocation.x;
+ down_allocation = up_allocation = allocation;
+
+ down_allocation.height = down_panel_height;
+ up_allocation.height = up_panel_height;
+
+ up_allocation.y = spin_allocation.y;
+ down_allocation.y = spin_allocation.y + spin_allocation.height - down_allocation.height;
+ }
+
+ if (down_allocation_out)
+ *down_allocation_out = down_allocation;
+ if (up_allocation_out)
+ *up_allocation_out = up_allocation;
+}
+
+static void
+gtk_spin_button_panel_draw (GtkSpinButton *spin_button,
+ cairo_t *cr,
+ GdkWindow *panel)
+{
+ GtkSpinButtonPrivate *priv = spin_button->priv;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkWidget *widget;
+ gdouble width, height, x, y;
+ gint icon_width, icon_height;
+ GtkIconHelper *icon_helper;
+
+ widget = GTK_WIDGET (spin_button);
+
+ cairo_save (cr);
+ gtk_cairo_transform_to_window (cr, widget, panel);
+
+ context = gtk_spin_button_panel_get_context (spin_button, panel);
+ state = gtk_spin_button_panel_get_state (spin_button, panel);
+ gtk_style_context_set_state (context, state);
+
+ height = gdk_window_get_height (panel);
+ width = gdk_window_get_width (panel);
+
+ icon_helper = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_use_fallback (icon_helper, TRUE);
+
+ if (panel == priv->down_panel)
+ _gtk_icon_helper_set_icon_name (icon_helper, "list-remove-symbolic", GTK_ICON_SIZE_MENU);
+ else
+ _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);
+
+ g_object_unref (icon_helper);
+ g_object_unref (context);
+}
+
+static void
+gtk_spin_button_realize (GtkWidget *widget)
+{
+ GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
+ GtkSpinButtonPrivate *priv = spin_button->priv;
+ GtkAllocation down_allocation, up_allocation;