[gtk+/wip/baedert/drawing: 105/396] viewport: Remove gadget
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing: 105/396] viewport: Remove gadget
- Date: Wed, 19 Jul 2017 11:19:10 +0000 (UTC)
commit e889d10866645d518d1fec2a613d90d515b05c13
Author: Timm Bäder <mail baedert org>
Date: Thu May 4 21:59:04 2017 +0200
viewport: Remove gadget
gtk/gtkviewport.c | 212 ++++++++++++++++++-----------------------------------
1 files changed, 71 insertions(+), 141 deletions(-)
---
diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c
index 730a8fd..586386f 100644
--- a/gtk/gtkviewport.c
+++ b/gtk/gtkviewport.c
@@ -27,7 +27,6 @@
#include "gtkviewport.h"
#include "gtkadjustment.h"
-#include "gtkcsscustomgadgetprivate.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
@@ -74,8 +73,6 @@ struct _GtkViewportPrivate
GdkWindow *bin_window;
- GtkCssGadget *gadget;
-
/* GtkScrollablePolicy needs to be checked when
* driving the scrollable adjustment values */
guint hscroll_policy : 1;
@@ -100,7 +97,6 @@ static void gtk_viewport_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void gtk_viewport_finalize (GObject *object);
static void gtk_viewport_destroy (GtkWidget *widget);
static void gtk_viewport_realize (GtkWidget *widget);
static void gtk_viewport_unrealize (GtkWidget *widget);
@@ -121,30 +117,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkViewport, gtk_viewport, GTK_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static void
-gtk_viewport_measure (GtkCssGadget *gadget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
- GtkWidget *child;
-
- *minimum = *natural = 0;
-
- child = gtk_bin_get_child (GTK_BIN (widget));
- if (child && gtk_widget_get_visible (child))
- gtk_widget_measure (child,
- orientation,
- for_size,
- minimum, natural,
- NULL, NULL);
-}
-
-static void
viewport_set_adjustment_values (GtkViewport *viewport,
GtkOrientation orientation)
{
@@ -159,8 +131,7 @@ viewport_set_adjustment_values (GtkViewport *viewport,
gdouble upper, value;
int viewport_size, other_viewport_size;
- gtk_css_gadget_get_content_allocation (viewport->priv->gadget,
- &view_allocation, NULL);
+ gtk_widget_get_content_allocation (GTK_WIDGET (viewport), &view_allocation);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
@@ -232,73 +203,7 @@ viewport_set_adjustment_values (GtkViewport *viewport,
}
static void
-gtk_viewport_allocate (GtkCssGadget *gadget,
- const GtkAllocation *allocation,
- int baseline,
- GtkAllocation *out_clip,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
- GtkViewport *viewport = GTK_VIEWPORT (widget);
- GtkViewportPrivate *priv = viewport->priv;
- GtkAdjustment *hadjustment = priv->hadjustment;
- GtkAdjustment *vadjustment = priv->vadjustment;
- GtkWidget *child;
-
- g_object_freeze_notify (G_OBJECT (hadjustment));
- g_object_freeze_notify (G_OBJECT (vadjustment));
-
- viewport_set_adjustment_values (viewport, GTK_ORIENTATION_HORIZONTAL);
- viewport_set_adjustment_values (viewport, GTK_ORIENTATION_VERTICAL);
-
- if (gtk_widget_get_realized (widget))
- {
- gdk_window_move_resize (priv->bin_window,
- allocation->x - gtk_adjustment_get_value (hadjustment),
- allocation->y - gtk_adjustment_get_value (vadjustment),
- gtk_adjustment_get_upper (hadjustment),
- gtk_adjustment_get_upper (vadjustment));
- }
-
- child = gtk_bin_get_child (GTK_BIN (widget));
- if (child && gtk_widget_get_visible (child))
- {
- GtkAllocation child_allocation;
-
- child_allocation.x = 0;
- child_allocation.y = 0;
- child_allocation.width = gtk_adjustment_get_upper (hadjustment);
- child_allocation.height = gtk_adjustment_get_upper (vadjustment);
-
- gtk_widget_size_allocate (child, &child_allocation);
- }
-
- g_object_thaw_notify (G_OBJECT (hadjustment));
- g_object_thaw_notify (G_OBJECT (vadjustment));
-}
-
-static gboolean
-gtk_viewport_render (GtkCssGadget *gadget,
- GtkSnapshot *snapshot,
- int x,
- int y,
- int width,
- int height,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
-
- gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT(x, y, width, height), "Viewport");
-
- GTK_WIDGET_CLASS (gtk_viewport_parent_class)->snapshot (widget, snapshot);
-
- gtk_snapshot_pop (snapshot);
-
- return FALSE;
-}
-
-static void
-gtk_viewport_measure_ (GtkWidget *widget,
+gtk_viewport_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
@@ -306,11 +211,17 @@ gtk_viewport_measure_ (GtkWidget *widget,
int *minimum_baseline,
int *natural_baseline)
{
- gtk_css_gadget_get_preferred_size (GTK_VIEWPORT (widget)->priv->gadget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
+ GtkWidget *child;
+
+ *minimum = *natural = 0;
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_measure (child,
+ orientation,
+ for_size,
+ minimum, natural,
+ NULL, NULL);
}
static void
@@ -326,14 +237,13 @@ gtk_viewport_class_init (GtkViewportClass *class)
gobject_class->set_property = gtk_viewport_set_property;
gobject_class->get_property = gtk_viewport_get_property;
- gobject_class->finalize = gtk_viewport_finalize;
widget_class->destroy = gtk_viewport_destroy;
widget_class->realize = gtk_viewport_realize;
widget_class->unrealize = gtk_viewport_unrealize;
widget_class->snapshot = gtk_viewport_snapshot;
widget_class->size_allocate = gtk_viewport_size_allocate;
- widget_class->measure = gtk_viewport_measure_;
+ widget_class->measure = gtk_viewport_measure;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_VIEWPORT);
@@ -437,7 +347,6 @@ gtk_viewport_init (GtkViewport *viewport)
{
GtkWidget *widget;
GtkViewportPrivate *priv;
- GtkCssNode *widget_node;
viewport->priv = gtk_viewport_get_instance_private (viewport);
priv = viewport->priv;
@@ -451,15 +360,8 @@ gtk_viewport_init (GtkViewport *viewport)
priv->hadjustment = NULL;
priv->vadjustment = NULL;
- widget_node = gtk_widget_get_css_node (widget);
- priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
- widget,
- gtk_viewport_measure,
- gtk_viewport_allocate,
- gtk_viewport_render,
- NULL, NULL);
-
- gtk_css_gadget_add_class (priv->gadget, GTK_STYLE_CLASS_FRAME);
+ gtk_style_context_add_class (gtk_widget_get_style_context (widget),
+ GTK_STYLE_CLASS_FRAME);
viewport_set_adjustment (viewport, GTK_ORIENTATION_HORIZONTAL, NULL);
viewport_set_adjustment (viewport, GTK_ORIENTATION_VERTICAL, NULL);
}
@@ -520,17 +422,6 @@ gtk_viewport_destroy (GtkWidget *widget)
}
static void
-gtk_viewport_finalize (GObject *object)
-{
- GtkViewport *viewport = GTK_VIEWPORT (object);
- GtkViewportPrivate *priv = viewport->priv;
-
- g_clear_object (&priv->gadget);
-
- G_OBJECT_CLASS (gtk_viewport_parent_class)->finalize (object);
-}
-
-static void
viewport_set_adjustment (GtkViewport *viewport,
GtkOrientation orientation,
GtkAdjustment *adjustment)
@@ -621,14 +512,13 @@ gtk_viewport_realize (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_viewport_parent_class)->realize (widget);
- gtk_css_gadget_get_content_allocation (priv->gadget,
- &view_allocation, NULL);
+ gtk_widget_get_content_allocation (widget, &view_allocation);
priv->bin_window = gdk_window_new_child (gtk_widget_get_window (widget),
GDK_ALL_EVENTS_MASK,
&(GdkRectangle) {
- - gtk_adjustment_get_value (hadjustment),
- - gtk_adjustment_get_value (vadjustment),
+ view_allocation.x - gtk_adjustment_get_value (hadjustment),
+ view_allocation.y - gtk_adjustment_get_value (vadjustment),
gtk_adjustment_get_upper (hadjustment),
gtk_adjustment_get_upper (vadjustment)});
gtk_widget_register_window (widget, priv->bin_window);
@@ -657,10 +547,23 @@ static void
gtk_viewport_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
- GtkViewport *viewport = GTK_VIEWPORT (widget);
- GtkViewportPrivate *priv = viewport->priv;
+ GtkAllocation content_allocation;
+ GtkAllocation widget_allocation;
+
+ gtk_widget_get_content_allocation (widget, &content_allocation);
+ gtk_widget_get_allocation (widget, &widget_allocation);
- gtk_css_gadget_snapshot (priv->gadget, snapshot);
+ gtk_snapshot_push_clip (snapshot,
+ &GRAPHENE_RECT_INIT(
+ content_allocation.x - widget_allocation.x,
+ content_allocation.y - widget_allocation.y,
+ content_allocation.width,
+ content_allocation.height),
+ "Viewport");
+
+ GTK_WIDGET_CLASS (gtk_viewport_parent_class)->snapshot (widget, snapshot);
+
+ gtk_snapshot_pop (snapshot);
}
static void
@@ -680,11 +583,14 @@ gtk_viewport_add (GtkContainer *container,
static void
gtk_viewport_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
GtkViewport *viewport = GTK_VIEWPORT (widget);
GtkViewportPrivate *priv = viewport->priv;
- GtkAllocation clip, content_allocation, widget_allocation;
+ GtkAllocation clip = *allocation, widget_allocation;
+ GtkAdjustment *hadjustment = priv->hadjustment;
+ GtkAdjustment *vadjustment = priv->vadjustment;
+ GtkWidget *child;
/* If our size changed, and we have a shadow, queue a redraw on widget->window to
* redraw the shadow correctly.
@@ -696,13 +602,37 @@ gtk_viewport_size_allocate (GtkWidget *widget,
widget_allocation.height != allocation->height))
gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE);
- gtk_widget_set_allocation (widget, allocation);
+ g_object_freeze_notify (G_OBJECT (hadjustment));
+ g_object_freeze_notify (G_OBJECT (vadjustment));
+
+ viewport_set_adjustment_values (viewport, GTK_ORIENTATION_HORIZONTAL);
+ viewport_set_adjustment_values (viewport, GTK_ORIENTATION_VERTICAL);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ gdk_window_move_resize (priv->bin_window,
+ allocation->x - gtk_adjustment_get_value (hadjustment),
+ allocation->y - gtk_adjustment_get_value (vadjustment),
+ gtk_adjustment_get_upper (hadjustment),
+ gtk_adjustment_get_upper (vadjustment));
+ }
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child && gtk_widget_get_visible (child))
+ {
+ GtkAllocation child_allocation;
+
+ child_allocation.x = 0;
+ child_allocation.y = 0;
+ child_allocation.width = gtk_adjustment_get_upper (hadjustment);
+ child_allocation.height = gtk_adjustment_get_upper (vadjustment);
+
+ gtk_widget_size_allocate (child, &child_allocation);
+ gtk_widget_get_clip (child, &clip);
+ }
- content_allocation = *allocation;
- gtk_css_gadget_allocate (priv->gadget,
- &content_allocation,
- gtk_widget_get_allocated_baseline (widget),
- &clip);
+ g_object_thaw_notify (G_OBJECT (hadjustment));
+ g_object_thaw_notify (G_OBJECT (vadjustment));
gtk_widget_set_clip (widget, &clip);
}
@@ -726,7 +656,7 @@ gtk_viewport_adjustment_value_changed (GtkAdjustment *adjustment,
gint old_x, old_y;
gint new_x, new_y;
- gtk_widget_get_allocation (GTK_WIDGET (viewport), &allocation);
+ gtk_widget_get_content_allocation (GTK_WIDGET (viewport), &allocation);
gdk_window_get_position (priv->bin_window, &old_x, &old_y);
new_x = - gtk_adjustment_get_value (hadjustment);
new_y = - gtk_adjustment_get_value (vadjustment);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]