1 From 478d022cd553d33de59ec8ce22605b14a3837264 Mon Sep 17 00:00:00 2001
2 From: Michael Natterer <mitch@gimp.org>
3 Date: Fri, 26 Apr 2013 15:50:14 +0200
4 Subject: [PATCH 51/68] nsview: factor out almost all code from the overridden
8 gtk/gtknsview.c | 151 +++++++++++++++++--------------------------------------
9 1 file changed, 47 insertions(+), 104 deletions(-)
11 diff --git a/gtk/gtknsview.c b/gtk/gtknsview.c
12 index 5e3aa59..b37b2fa 100644
15 @@ -167,21 +167,19 @@ static void gtk_ns_view_swizzle_draw_rect_recursive (NSView *view,
19 -@implementation NSView (myDrawRect)
20 -- (void) myDrawRect: (NSRect) dirtyRect
22 +get_associated_gtknsview (NSView *view)
25 - GtkWidget *viewport;
26 - CGContextRef cg_context;
28 - ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview");
29 + ns_view = (GtkNSView *) objc_getAssociatedObject (view, "gtknsview");
31 - if (! ns_view && ([self class] == [NSTextView class]))
32 + if (! ns_view && ([view class] == [NSTextView class]))
34 /* if it's not a GtkNSView, check if it's the NSWindow's cell
35 * editor editing an NSTextField managed by a GtkNSView
37 - GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (self, "gtkwindow");
38 + GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (view, "gtkwindow");
40 if (GTK_IS_WINDOW (window))
42 @@ -192,15 +190,21 @@ static void gtk_ns_view_swizzle_draw_rect_recursive (NSView *view,
47 - ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: self])
49 + ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: view])
51 - [self myDrawRect: dirtyRect];
56 - cg_context = [[NSGraphicsContext currentContext] graphicsPort];
57 - CGContextSaveGState (cg_context);
62 +clip_to_parent_viewports (GtkNSView *ns_view,
65 + CGContextRef cg_context = nil;
66 + GtkWidget *viewport;
68 for (viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT);
70 @@ -245,23 +249,44 @@ static void gtk_ns_view_swizzle_draw_rect_recursive (NSView *view,
71 rect.size.height = viewport_allocation.height;
73 /* need to translate rect if this is not the view itself but a subview */
74 - if (ns_view->priv->view != self)
75 + if (ns_view->priv->view != view)
77 NSRect offset = NSMakeRect (0, 0, 0, 0);
79 offset = [ns_view->priv->view convertRect: offset
83 rect.origin.x -= offset.origin.x;
84 rect.origin.y -= offset.origin.y;
89 + cg_context = [[NSGraphicsContext currentContext] graphicsPort];
90 + CGContextSaveGState (cg_context);
93 CGContextClipToRect (cg_context, rect);
99 +@implementation NSView (myDrawRect)
100 +- (void) myDrawRect: (NSRect) dirtyRect
102 + GtkNSView *ns_view;
103 + CGContextRef cg_context = nil;
105 + ns_view = get_associated_gtknsview (self);
108 + cg_context = clip_to_parent_viewports (ns_view, self);
110 [self myDrawRect: dirtyRect];
112 - CGContextRestoreGState (cg_context);
114 + CGContextRestoreGState (cg_context);
118 @@ -271,101 +296,19 @@ static void gtk_ns_view_swizzle_draw_rect_recursive (NSView *view,
119 turnedOn: (BOOL) flag
122 - GtkWidget *viewport;
123 - CGContextRef cg_context;
125 - ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview");
127 - if (! ns_view && ([self class] == [NSTextView class]))
129 - /* if it's not a GtkNSView, check if it's the NSWindow's cell
130 - * editor editing an NSTextField managed by a GtkNSView
132 - GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (self, "gtkwindow");
134 - if (GTK_IS_WINDOW (window))
136 - GtkWidget *focus = gtk_window_get_focus (window);
138 - if (GTK_IS_NS_VIEW (focus))
139 - ns_view = GTK_NS_VIEW (focus);
144 - ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: self])
146 - [self myDrawInsertionPointInRect: aRect
152 - cg_context = [[NSGraphicsContext currentContext] graphicsPort];
153 - CGContextSaveGState (cg_context);
155 - for (viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT);
157 - viewport = gtk_widget_get_ancestor (gtk_widget_get_parent (viewport),
158 - GTK_TYPE_VIEWPORT))
161 - GtkAllocation viewport_allocation;
164 - gtk_widget_get_allocation (viewport, &viewport_allocation);
166 - /* evil: don't clip to the viewport's width/height but to that
167 - * of its parent window, because we know we hacked an
168 - * overshoot_window into GtkScrolledWindow and need to restrict
169 - * rendering to its area
171 - window = gtk_widget_get_parent_window (viewport);
173 - viewport_allocation.width = gdk_window_get_width (window);
174 - viewport_allocation.height = gdk_window_get_height (window);
176 - if (gtk_viewport_get_shadow_type (GTK_VIEWPORT (viewport)) != GTK_SHADOW_NONE)
178 - GtkStyle *style = gtk_widget_get_style (viewport);
180 - viewport_allocation.x += style->xthickness;
181 - viewport_allocation.y += style->ythickness;
182 - viewport_allocation.width -= 2 * style->xthickness;
183 - viewport_allocation.height -= 2 * style->ythickness;
186 - gtk_widget_translate_coordinates (viewport, GTK_WIDGET (ns_view),
187 - viewport_allocation.x,
188 - viewport_allocation.y,
189 - &viewport_allocation.x,
190 - &viewport_allocation.y);
191 + CGContextRef cg_context = nil;;
193 - rect.origin.x = viewport_allocation.x;
194 - rect.origin.y = viewport_allocation.y;
195 - rect.size.width = viewport_allocation.width;
196 - rect.size.height = viewport_allocation.height;
197 + ns_view = get_associated_gtknsview (self);
199 - /* need to translate rect if this is not the view itself but a subview */
200 - if (ns_view->priv->view != self)
202 - NSRect offset = NSMakeRect (0, 0, 0, 0);
204 - offset = [ns_view->priv->view convertRect: offset
207 - rect.origin.x -= offset.origin.x;
208 - rect.origin.y -= offset.origin.y;
211 - CGContextClipToRect (cg_context, rect);
214 + cg_context = clip_to_parent_viewports (ns_view, self);
216 [self myDrawInsertionPointInRect: aRect
220 - CGContextRestoreGState (cg_context);
222 + CGContextRestoreGState (cg_context);
227 1.7.10.2 (Apple Git-33)