From 8701dd7c848af2758caea9183b849f7888f7f006 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Mon, 28 Jan 2013 22:07:53 -0700 Subject: [PATCH] gtk: Update to Gtk+3.6. Separate GtkScrolledWindow and GtkScrolledView. Rename GtkScrollingWindow to GtkScrolledView and fix it to work with Gtk+3.6.0 (in Ubuntu 12.10). Create distinct classes for GtkScrolledWindow and GtkScrolledView. The former might be useful to someone else, and substituting the latter for the former just invites confusion. --- doc/gtk/gtk.texinfo | 23 +++ src/gtk/Makefile-fragment | 12 +- src/gtk/fix-demo.scm | 6 +- src/gtk/gtk-shim.h | 2 +- src/gtk/gtk-widget.scm | 16 +- src/gtk/gtk.cdecl | 4 +- src/gtk/gtk.pkg | 2 + ...ngwindow.c.stay => gtkscrolledview.c.stay} | 156 +++++------------- src/gtk/gtkscrolledview.h | 27 +++ src/gtk/gtkscrollingwindow.h | 27 --- 10 files changed, 121 insertions(+), 154 deletions(-) rename src/gtk/{gtkscrollingwindow.c.stay => gtkscrolledview.c.stay} (56%) create mode 100644 src/gtk/gtkscrolledview.h delete mode 100644 src/gtk/gtkscrollingwindow.h diff --git a/doc/gtk/gtk.texinfo b/doc/gtk/gtk.texinfo index ce619c088..7bde112e5 100644 --- a/doc/gtk/gtk.texinfo +++ b/doc/gtk/gtk.texinfo @@ -120,6 +120,7 @@ directory of your build tree. The code can be found in @file{gtk-ev.scm}. +@anchor{Fix Demo} @unnumberedsec Fix Demo The Gtk system provides a fixnum-centric canvas abstraction based on @@ -1607,6 +1608,28 @@ scrolled window is placed ``bottom left'', the scrollbars will appear above and to the right. @end deffn +@deffn Class +A direct subclass of gtk-scrolled-window representing a reference to a +GtkScrolledView. + +This specialization of GtkScrolledWindow overrides the widget geometry +protocol to work somewhat differently. + +A GtkScrolledWindow is used to squeeze an overly large widget into a +smaller space and allow the user to scroll it. The geometry +implementation ignores the natural size of the problem widget, +expecting @code{gtk_widget_set_size_request} to override its minimum +size. + +A GtkScrolledView is used to stick scrollbars on a viewport. Its +natural size is the natural size of the viewport, plus scrollbars, +frame, etc. Using @code{gtk_widget_set_size_request} is unnecessary +and interferes with resizing. The difference can be observed by +replacing @code{gtk-scrolled-view-new} with +@code{gtk-scrolled-window-new} in the fix layout demo. +See @bref{Fix Demo}. +@end deffn + @node Scheme Widget, Fix Layout, Gtk Scrolled Window, API Reference @section Scheme Widget diff --git a/src/gtk/Makefile-fragment b/src/gtk/Makefile-fragment index f0a80d50d..1bab067ee 100644 --- a/src/gtk/Makefile-fragment +++ b/src/gtk/Makefile-fragment @@ -59,15 +59,15 @@ install: | ../microcode/scheme --library ../lib --batch-mode` = "c"; \ then $(MAKE) install-liarc-bundle; fi -gtk-shim.so: gtk-shim.o gtkscrollingwindow.o scmwidget.o gtkio.o $(SHIM_LOADER) - $(LINK_SHIM) gtk-shim.o gtkscrollingwindow.o scmwidget.o gtkio.o \ +gtk-shim.so: gtk-shim.o gtkscrolledview.o scmwidget.o gtkio.o $(SHIM_LOADER) + $(LINK_SHIM) gtk-shim.o gtkscrolledview.o scmwidget.o gtkio.o \ `pkg-config --libs gtk+-3.0 gthread-2.0` $(SHIM_LIBS) -gtkscrollingwindow.o: gtkscrollingwindow.c gtkscrollingwindow.h - $(COMPILE_SHIM) `pkg-config --cflags gtk+-3.0` -c gtkscrollingwindow.c +gtkscrolledview.o: gtkscrolledview.c gtkscrolledview.h + $(COMPILE_SHIM) `pkg-config --cflags gtk+-3.0` -c gtkscrolledview.c -gtkscrollingwindow.c: gtkscrollingwindow.c.stay - cp -p gtkscrollingwindow.c.stay gtkscrollingwindow.c +gtkscrolledview.c: gtkscrolledview.c.stay + cp -p gtkscrolledview.c.stay gtkscrolledview.c scmwidget.o: scmwidget.c scmwidget.h $(COMPILE_SHIM) `pkg-config --cflags gtk+-3.0` -c scmwidget.c diff --git a/src/gtk/fix-demo.scm b/src/gtk/fix-demo.scm index ecfa7bcdb..22b7782cc 100644 --- a/src/gtk/fix-demo.scm +++ b/src/gtk/fix-demo.scm @@ -35,13 +35,13 @@ USA. w (lambda (w) (%trace ";closed "w"\n") 0)) (gtk-container-set-border-width w 5) w)) - (scroller1 (gtk-scrolled-window-new)) - (scroller2 (gtk-scrolled-window-new)) + (scroller1 (gtk-scrolled-view-new)) + (scroller2 (gtk-scrolled-view-new)) (layout1 (let ((l (make-demo-layout 200 200))) (gtk-widget-set-hexpand l #t) (gtk-widget-set-vexpand l #t) l)) - (layout2 (let ((l (make-demo-layout 200 200))) + (layout2 (let ((l (make-demo-layout 200 300))) (gtk-widget-set-hexpand l #t) (gtk-widget-set-vexpand l #t) l)) diff --git a/src/gtk/gtk-shim.h b/src/gtk/gtk-shim.h index 0fcb62276..3c337542f 100644 --- a/src/gtk/gtk-shim.h +++ b/src/gtk/gtk-shim.h @@ -30,7 +30,7 @@ USA. #include #include "scmwidget.h" -#include "gtkscrollingwindow.h" +#include "gtkscrolledview.h" typedef unsigned int uint; extern gboolean start_gtk (int *argc, char ***argv); diff --git a/src/gtk/gtk-widget.scm b/src/gtk/gtk-widget.scm index fbb4139a9..c6bd4f5b7 100644 --- a/src/gtk/gtk-widget.scm +++ b/src/gtk/gtk-widget.scm @@ -681,7 +681,7 @@ USA. (define (gtk-scrolled-window-new) (let* ((window (make-gtk-scrolled-window)) (alien (gobject-alien window))) - (C-call "gtk_scrolling_window_new" alien 0 0) + (C-call "gtk_scrolled_window_new" alien 0 0) (error-if-null alien "Could not create:" window) (C-call "g_object_ref_sink" alien alien) (set-gtk-widget-destroy-callback! window) @@ -716,6 +716,20 @@ USA. object "a symbol -- one of TOP-LEFT, BOTTOM-LEFT, TOP-RIGHT or BOTTOM-RIGHT" operator)))) + +(define-class ( (constructor ())) + ()) + +(define-guarantee gtk-scrolled-view "a ") + +(define (gtk-scrolled-view-new) + (let* ((window (make-gtk-scrolled-view)) + (alien (gobject-alien window))) + (C-call "gtk_scrolled_view_new" alien 0 0) + (error-if-null alien "Could not create:" window) + (C-call "g_object_ref_sink" alien alien) + (set-gtk-widget-destroy-callback! window) + window)) ;;; GtkPaneds diff --git a/src/gtk/gtk.cdecl b/src/gtk/gtk.cdecl index 1f56dfc83..1d2ab6c6d 100644 --- a/src/gtk/gtk.cdecl +++ b/src/gtk/gtk.cdecl @@ -99,8 +99,8 @@ USA. ;;; miscellaneous -(extern (* GtkWidget) ;gtkscrollingwindow.h - gtk_scrolling_window_new +(extern (* GtkWidget) ;gtkscrolledview.h + gtk_scrolled_view_new (hadjustment (* GtkAdjustment)) (vadjustment (* GtkAdjustment))) diff --git a/src/gtk/gtk.pkg b/src/gtk/gtk.pkg index 16dace01a..609815cd3 100644 --- a/src/gtk/gtk.pkg +++ b/src/gtk/gtk.pkg @@ -209,6 +209,8 @@ USA. gtk-scrolled-window? guarantee-gtk-scrolled-window gtk-scrolled-window-new gtk-scrolled-window-set-policy gtk-scrolled-window-set-placement + gtk-scrolled-view? + guarantee-gtk-scrolled-view gtk-scrolled-view-new gtk-paned? gtk-paned-new gtk-paned-pack1 gtk-paned-pack2 gtk-paned-get-child1 gtk-paned-get-child2) diff --git a/src/gtk/gtkscrollingwindow.c.stay b/src/gtk/gtkscrolledview.c.stay similarity index 56% rename from src/gtk/gtkscrollingwindow.c.stay rename to src/gtk/gtkscrolledview.c.stay index 38efa8ba0..0967c1f36 100644 --- a/src/gtk/gtkscrollingwindow.c.stay +++ b/src/gtk/gtkscrolledview.c.stay @@ -1,19 +1,19 @@ -#include "gtkscrollingwindow.h" +#include "gtkscrolledview.h" /** - * SECTION:gtkscrollingwindow + * SECTION:gtkscrolledview * @Short_description: Adds scrollbars to its child widget - * @Title: GtkScrollingWindow + * @Title: GtkScrolledView * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment * - * #GtkScrollingWindow is a #GtkBin subclass: it's a container that + * #GtkScrolledView is a #GtkBin subclass: it's a container that * accepts a single child widget (a GtkScrollable) and adds an * optional beveled frame and scrollbars. * * The position of the scrollbars is controlled by the scroll * adjustments. See #GtkAdjustment for the fields in an adjustment. * - * #GtkScrollingWindow is a #GtkScrolledWindow subclass that overrides + * #GtkScrolledView is a #GtkScrolledWindow subclass that overrides * the geometry protocol to work as follows: * * A scrolled window (GtkScrolledWindow) is about squeezing an overly @@ -21,11 +21,11 @@ * It ignores the natural size of the problem widget, expecting a * gtk_widget_set_size_request to override (squeeze) it. * - * A scrolling window (GtkScrollingWindow) is about sticking - * scrollbars on a viewport -- a GtkScrollable. Its natural size is - * the natural size of the viewport, scrollbars and frame (with - * spacing). Using gtk_widget_set_size_request interferes with the - * natural sizing (esp. shrinking of expandable viewports). + * A scrolled view (GtkScrolledView) is about sticking scrollbars on a + * viewport -- a GtkScrollable. Its natural size is the natural size + * of the viewport, scrollbars and frame (with spacing). Using + * gtk_widget_set_size_request interferes with the natural sizing + * (esp. shrinking of expandable viewports). */ struct _GtkScrolledWindowPrivate @@ -46,115 +46,45 @@ struct _GtkScrolledWindowPrivate gint min_content_width; gint min_content_height; - - /* Kinetic scrolling */ - GdkEvent *button_press_event; - GdkWindow *overshoot_window; - GdkDevice *drag_device; - guint kinetic_scrolling : 1; - guint capture_button_press : 1; - guint in_drag : 1; - guint last_button_event_valid : 1; - - guint release_timeout_id; - guint deceleration_id; - - gdouble last_button_event_x_root; - gdouble last_button_event_y_root; - - gdouble last_motion_event_x_root; - gdouble last_motion_event_y_root; - guint32 last_motion_event_time; - - gdouble x_velocity; - gdouble y_velocity; - - gdouble unclamped_hadj_value; - gdouble unclamped_vadj_value; }; -static void -gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window) -{ - GtkScrolledWindowPrivate *priv = scrolled_window->priv; - GtkSettings *settings; - - settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window)); - - if (priv->window_placement_set || settings == NULL) - priv->real_window_placement = priv->window_placement; - else - g_object_get (settings, - "gtk-scrolled-window-placement", - &priv->real_window_placement, - NULL); -} - -static void -gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window) -{ - GtkScrolledWindowPrivate *priv; - - scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window, - GTK_TYPE_SCROLLED_WINDOW, - GtkScrolledWindowPrivate); - - gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE); - gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE); - - priv->hscrollbar = NULL; - priv->vscrollbar = NULL; - priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC; - priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC; - priv->hscrollbar_visible = FALSE; - priv->vscrollbar_visible = FALSE; - priv->focus_out = FALSE; - priv->window_placement = GTK_CORNER_TOP_LEFT; - gtk_scrolled_window_update_real_placement (scrolled_window); - priv->min_content_width = -1; - priv->min_content_height = -1; - - gtk_scrolled_window_set_kinetic_scrolling (scrolled_window, TRUE); - gtk_scrolled_window_set_capture_button_press (scrolled_window, TRUE); -} - -static void gtk_scrolling_window_get_preferred_width (GtkWidget *widget, +static void gtk_scrolled_view_get_preferred_width (GtkWidget *widget, gint *minimum_size, gint *natural_size); -static void gtk_scrolling_window_get_preferred_height (GtkWidget *widget, +static void gtk_scrolled_view_get_preferred_height (GtkWidget *widget, gint *minimum_size, gint *natural_size); -static void gtk_scrolling_window_get_preferred_height_for_width (GtkWidget *layout, +static void gtk_scrolled_view_get_preferred_height_for_width (GtkWidget *layout, gint width, gint *minimum_height, gint *natural_height); -static void gtk_scrolling_window_get_preferred_width_for_height (GtkWidget *layout, +static void gtk_scrolled_view_get_preferred_width_for_height (GtkWidget *layout, gint width, gint *minimum_height, gint *natural_height); -G_DEFINE_TYPE (GtkScrollingWindow, gtk_scrolling_window, +G_DEFINE_TYPE (GtkScrolledView, gtk_scrolled_view, GTK_TYPE_SCROLLED_WINDOW) static void -gtk_scrolling_window_class_init (GtkScrollingWindowClass *class) +gtk_scrolled_view_class_init (GtkScrolledViewClass *class) { GtkWidgetClass *widget_class = (GtkWidgetClass*) class; - widget_class->get_preferred_width = gtk_scrolling_window_get_preferred_width; - widget_class->get_preferred_height = gtk_scrolling_window_get_preferred_height; - widget_class->get_preferred_height_for_width = gtk_scrolling_window_get_preferred_height_for_width; - widget_class->get_preferred_width_for_height = gtk_scrolling_window_get_preferred_width_for_height; + widget_class->get_preferred_width = gtk_scrolled_view_get_preferred_width; + widget_class->get_preferred_height = gtk_scrolled_view_get_preferred_height; + widget_class->get_preferred_height_for_width = gtk_scrolled_view_get_preferred_height_for_width; + widget_class->get_preferred_width_for_height = gtk_scrolled_view_get_preferred_width_for_height; } static void -gtk_scrolling_window_init (GtkScrollingWindow *scrolling_window) +gtk_scrolled_view_init (GtkScrolledView *scrolled_view) { - gtk_scrolled_window_init (GTK_SCROLLED_WINDOW (scrolling_window)); + g_assert (GTK_SCROLLED_WINDOW (scrolled_view) ->priv != NULL); } /** - * gtk_scrolling_window_new: + * gtk_scrolled_view_new: * @hadjustment: (allow-none): horizontal adjustment * @vadjustment: (allow-none): vertical adjustment * @@ -168,10 +98,10 @@ gtk_scrolling_window_init (GtkScrollingWindow *scrolling_window) * Returns: a new scrolling window */ GtkWidget* -gtk_scrolling_window_new (GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) +gtk_scrolled_view_new (GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment) { - GtkWidget *scrolling_window; + GtkWidget *scrolled_view; if (hadjustment) g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL); @@ -179,16 +109,14 @@ gtk_scrolling_window_new (GtkAdjustment *hadjustment, if (vadjustment) g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL); - scrolling_window = g_object_new (GTK_TYPE_SCROLLING_WINDOW, - "hadjustment", hadjustment, - "vadjustment", vadjustment, - NULL); + scrolled_view = g_object_new (GTK_TYPE_SCROLLED_VIEW, + "hadjustment", hadjustment, + "vadjustment", vadjustment, + NULL); - return scrolling_window; + return scrolled_view; } -extern gboolean ubuntu_overlay_scrollbar_get_enabled (void); - static gint gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window) { @@ -196,9 +124,6 @@ gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window) g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0); - if (ubuntu_overlay_scrollbar_get_enabled ()) - return 0; - class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window); if (class->scrollbar_spacing >= 0) @@ -216,7 +141,7 @@ gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window) } static void -gtk_scrolling_window_get_preferred_size (GtkWidget *widget, +gtk_scrolled_view_get_preferred_size (GtkWidget *widget, GtkOrientation orientation, gint *minimum_size, gint *natural_size) @@ -251,7 +176,10 @@ gtk_scrolling_window_get_preferred_size (GtkWidget *widget, } /* Add scrollbar size. */ - if (priv->vscrollbar_policy != GTK_POLICY_NEVER) + if ((orientation == GTK_ORIENTATION_VERTICAL + && priv->hscrollbar_policy != GTK_POLICY_NEVER) || + (orientation == GTK_ORIENTATION_HORIZONTAL + && priv->vscrollbar_policy != GTK_POLICY_NEVER)) { gint min, nat; gint space = gtk_scrolled_window_get_scrollbar_spacing (scrolled_window); @@ -298,23 +226,23 @@ gtk_scrolling_window_get_preferred_size (GtkWidget *widget, } static void -gtk_scrolling_window_get_preferred_width (GtkWidget *widget, +gtk_scrolled_view_get_preferred_width (GtkWidget *widget, gint *minimum_size, gint *natural_size) { - gtk_scrolling_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); + gtk_scrolled_view_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); } static void -gtk_scrolling_window_get_preferred_height (GtkWidget *widget, +gtk_scrolled_view_get_preferred_height (GtkWidget *widget, gint *minimum_size, gint *natural_size) { - gtk_scrolling_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); + gtk_scrolled_view_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); } static void -gtk_scrolling_window_get_preferred_height_for_width (GtkWidget *widget, +gtk_scrolled_view_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) @@ -325,7 +253,7 @@ gtk_scrolling_window_get_preferred_height_for_width (GtkWidget *widget, } static void -gtk_scrolling_window_get_preferred_width_for_height (GtkWidget *widget, +gtk_scrolled_view_get_preferred_width_for_height (GtkWidget *widget, gint height, gint *minimum_width, gint *natural_width) diff --git a/src/gtk/gtkscrolledview.h b/src/gtk/gtkscrolledview.h new file mode 100644 index 000000000..5508728f3 --- /dev/null +++ b/src/gtk/gtkscrolledview.h @@ -0,0 +1,27 @@ +#include + +#define GTK_TYPE_SCROLLED_VIEW (gtk_scrolled_view_get_type ()) +#define GTK_SCROLLED_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCROLLED_VIEW, GtkScrolledView)) +#define GTK_SCROLLED_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCROLLED_VIEW, GtkScrolledViewClass)) +#define GTK_IS_SCROLLED_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCROLLED_VIEW)) +#define GTK_IS_SCROLLED_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCROLLED_VIEW)) +#define GTK_SCROLLED_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SCROLLED_VIEW, GtkScrolledViewClass)) + + +typedef struct _GtkScrolledView GtkScrolledView; +typedef struct _GtkScrolledViewClass GtkScrolledViewClass; + +struct _GtkScrolledView +{ + GtkScrolledWindow scrolled; +}; + +struct _GtkScrolledViewClass +{ + GtkScrolledWindowClass parent_class; +}; + + +GType gtk_scrolled_view_get_type (void) G_GNUC_CONST; +GtkWidget* gtk_scrolled_view_new (GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); diff --git a/src/gtk/gtkscrollingwindow.h b/src/gtk/gtkscrollingwindow.h deleted file mode 100644 index 72fce3eac..000000000 --- a/src/gtk/gtkscrollingwindow.h +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#define GTK_TYPE_SCROLLING_WINDOW (gtk_scrolling_window_get_type ()) -#define GTK_SCROLLING_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SCROLLING_WINDOW, GtkScrollingWindow)) -#define GTK_SCROLLING_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCROLLING_WINDOW, GtkScrollingWindowClass)) -#define GTK_IS_SCROLLING_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SCROLLING_WINDOW)) -#define GTK_IS_SCROLLING_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCROLLING_WINDOW)) -#define GTK_SCROLLING_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SCROLLING_WINDOW, GtkScrollingWindowClass)) - - -typedef struct _GtkScrollingWindow GtkScrollingWindow; -typedef struct _GtkScrollingWindowClass GtkScrollingWindowClass; - -struct _GtkScrollingWindow -{ - GtkScrolledWindow scrolled; -}; - -struct _GtkScrollingWindowClass -{ - GtkScrolledWindowClass parent_class; -}; - - -GType gtk_scrolling_window_get_type (void) G_GNUC_CONST; -GtkWidget* gtk_scrolling_window_new (GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -- 2.25.1