From ab0bb7104783da5155361e6fbd89ee14f25e2544 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 14 Mar 2013 20:10:51 +0100 Subject: [PATCH 46/68] gtk: implement clipping to multiple parent viewports in GtkNSView --- gtk/gtknsview.c | 51 +++++++++++---------------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/gtk/gtknsview.c b/gtk/gtknsview.c index db1da93..1e0b7e6 100644 --- a/gtk/gtknsview.c +++ b/gtk/gtknsview.c @@ -143,10 +143,7 @@ gtk_ns_view_init (GtkNSView *ns_view) { GtkNSView *ns_view; GtkWidget *viewport; - -#if 0 - g_printerr ("drawRect called\n"); -#endif + CGContextRef cg_context; ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview"); @@ -156,51 +153,30 @@ gtk_ns_view_init (GtkNSView *ns_view) return; } - viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT); + cg_context = [[NSGraphicsContext currentContext] graphicsPort]; + CGContextSaveGState (cg_context); - if (viewport) + for (viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT); + viewport; + viewport = gtk_widget_get_ancestor (gtk_widget_get_parent (viewport), + GTK_TYPE_VIEWPORT)) { GdkWindow *window; - CGContextRef cg_context = [[NSGraphicsContext currentContext] graphicsPort]; GtkAllocation viewport_allocation; CGRect rect; -#if 0 - g_printerr ("drawRect called on gtknsview in gtkviewport\n"); -#endif - gtk_widget_get_allocation (viewport, &viewport_allocation); -#if 0 - g_printerr ("viewport allocation: %d, %d (%d x %x)\n", - viewport_allocation.x, - viewport_allocation.y, - viewport_allocation.width, - viewport_allocation.height); -#endif - /* evil: don't clip to the viewport's width/height but to that * of its parent window, because we know we hacked an * overshoot_window into GtkScrolledWindow and need to restrict - * rendering in its area + * rendering to its area */ window = gtk_widget_get_parent_window (viewport); viewport_allocation.width = gdk_window_get_width (window); viewport_allocation.height = gdk_window_get_height (window); -#if 0 - { - gint x, y; - - gdk_window_get_position (window, &x, &y); - g_printerr ("viewport parent window at %d, %d (%x x %x)\n", - x, y, - gdk_window_get_width (window), - gdk_window_get_height (window)); - } -#endif - if (gtk_viewport_get_shadow_type (GTK_VIEWPORT (viewport)) != GTK_SHADOW_NONE) { GtkStyle *style = gtk_widget_get_style (viewport); @@ -222,17 +198,12 @@ gtk_ns_view_init (GtkNSView *ns_view) rect.size.width = viewport_allocation.width; rect.size.height = viewport_allocation.height; - CGContextSaveGState (cg_context); CGContextClipToRect (cg_context, rect); + } - [self myDrawRect: dirtyRect]; + [self myDrawRect: dirtyRect]; - CGContextRestoreGState (cg_context); - } - else - { - [self myDrawRect: dirtyRect]; - } + CGContextRestoreGState (cg_context); } @end -- 1.7.10.2 (Apple Git-33)