Fix 'mono' package typo
[mono.git] / bockbuild / mac-sdk / patches / gtk / 0051-nsview-factor-out-almost-all-code-from-the-overridde.patch
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
5  draw functions
6
7 ---
8  gtk/gtknsview.c |  151 +++++++++++++++++--------------------------------------
9  1 file changed, 47 insertions(+), 104 deletions(-)
10
11 diff --git a/gtk/gtknsview.c b/gtk/gtknsview.c
12 index 5e3aa59..b37b2fa 100644
13 --- a/gtk/gtknsview.c
14 +++ b/gtk/gtknsview.c
15 @@ -167,21 +167,19 @@ static void   gtk_ns_view_swizzle_draw_rect_recursive (NSView      *view,
16  }
17  @end
18
19 -@implementation NSView (myDrawRect)
20 -- (void) myDrawRect: (NSRect) dirtyRect
21 +static GtkNSView *
22 +get_associated_gtknsview (NSView *view)
23  {
24    GtkNSView *ns_view;
25 -  GtkWidget *viewport;
26 -  CGContextRef cg_context;
27
28 -  ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview");
29 +  ns_view = (GtkNSView *) objc_getAssociatedObject (view, "gtknsview");
30
31 -  if (! ns_view && ([self class] == [NSTextView class]))
32 +  if (! ns_view && ([view class] == [NSTextView class]))
33      {
34        /*  if it's not a GtkNSView, check if it's the NSWindow's cell
35         *  editor editing an NSTextField managed by a GtkNSView
36         */
37 -      GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (self, "gtkwindow");
38 +      GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (view, "gtkwindow");
39
40        if (GTK_IS_WINDOW (window))
41          {
42 @@ -192,15 +190,21 @@ static void   gtk_ns_view_swizzle_draw_rect_recursive (NSView      *view,
43          }
44      }
45
46 -  if (! ns_view ||
47 -      ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: self])
48 +  if (ns_view &&
49 +      ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: view])
50      {
51 -      [self myDrawRect: dirtyRect];
52 -      return;
53 +      return NULL;
54      }
55
56 -  cg_context = [[NSGraphicsContext currentContext] graphicsPort];
57 -  CGContextSaveGState (cg_context);
58 +  return ns_view;
59 +}
60 +
61 +static CGContextRef
62 +clip_to_parent_viewports (GtkNSView *ns_view,
63 +                          NSView    *view)
64 +{
65 +  CGContextRef cg_context = nil;
66 +  GtkWidget *viewport;
67
68    for (viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT);
69         viewport;
70 @@ -245,23 +249,44 @@ static void   gtk_ns_view_swizzle_draw_rect_recursive (NSView      *view,
71        rect.size.height = viewport_allocation.height;
72
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)
76          {
77            NSRect offset = NSMakeRect (0, 0, 0, 0);
78
79            offset = [ns_view->priv->view convertRect: offset
80 -                                           fromView: self];
81 +                                           fromView: view];
82
83            rect.origin.x -= offset.origin.x;
84            rect.origin.y -= offset.origin.y;
85          }
86
87 +      if (! cg_context)
88 +        {
89 +          cg_context = [[NSGraphicsContext currentContext] graphicsPort];
90 +          CGContextSaveGState (cg_context);
91 +        }
92 +
93        CGContextClipToRect (cg_context, rect);
94      }
95
96 +  return cg_context;
97 +}
98 +
99 +@implementation NSView (myDrawRect)
100 +- (void) myDrawRect: (NSRect) dirtyRect
101 +{
102 +  GtkNSView *ns_view;
103 +  CGContextRef cg_context = nil;
104 +
105 +  ns_view = get_associated_gtknsview (self);
106 +
107 +  if (ns_view)
108 +    cg_context = clip_to_parent_viewports (ns_view, self);
109 +
110    [self myDrawRect: dirtyRect];
111
112 -  CGContextRestoreGState (cg_context);
113 +  if (cg_context)
114 +    CGContextRestoreGState (cg_context);
115  }
116  @end
117
118 @@ -271,101 +296,19 @@ static void   gtk_ns_view_swizzle_draw_rect_recursive (NSView      *view,
119                             turnedOn: (BOOL) flag
120  {
121    GtkNSView *ns_view;
122 -  GtkWidget *viewport;
123 -  CGContextRef cg_context;
124 -
125 -  ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview");
126 -
127 -  if (! ns_view && ([self class] == [NSTextView class]))
128 -    {
129 -      /*  if it's not a GtkNSView, check if it's the NSWindow's cell
130 -       *  editor editing an NSTextField managed by a GtkNSView
131 -       */
132 -      GtkWindow *window = (GtkWindow *) objc_getAssociatedObject (self, "gtkwindow");
133 -
134 -      if (GTK_IS_WINDOW (window))
135 -        {
136 -          GtkWidget *focus = gtk_window_get_focus (window);
137 -
138 -          if (GTK_IS_NS_VIEW (focus))
139 -            ns_view = GTK_NS_VIEW (focus);
140 -        }
141 -    }
142 -
143 -  if (! ns_view ||
144 -      ns_view->priv->view != [ns_view->priv->view ancestorSharedWithView: self])
145 -    {
146 -      [self myDrawInsertionPointInRect: aRect
147 -                                 color: aColor
148 -                              turnedOn: flag];
149 -      return;
150 -    }
151 -
152 -  cg_context = [[NSGraphicsContext currentContext] graphicsPort];
153 -  CGContextSaveGState (cg_context);
154 -
155 -  for (viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT);
156 -       viewport;
157 -       viewport = gtk_widget_get_ancestor (gtk_widget_get_parent (viewport),
158 -                                           GTK_TYPE_VIEWPORT))
159 -    {
160 -      GdkWindow *window;
161 -      GtkAllocation viewport_allocation;
162 -      CGRect rect;
163 -
164 -      gtk_widget_get_allocation (viewport, &viewport_allocation);
165 -
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
170 -       */
171 -      window = gtk_widget_get_parent_window (viewport);
172 -
173 -      viewport_allocation.width = gdk_window_get_width (window);
174 -      viewport_allocation.height = gdk_window_get_height (window);
175 -
176 -      if (gtk_viewport_get_shadow_type (GTK_VIEWPORT (viewport)) != GTK_SHADOW_NONE)
177 -        {
178 -          GtkStyle *style = gtk_widget_get_style (viewport);
179 -
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;
184 -        }
185 -
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;;
192
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);
198
199 -      /*  need to translate rect if this is not the view itself but a subview  */
200 -      if (ns_view->priv->view != self)
201 -        {
202 -          NSRect offset = NSMakeRect (0, 0, 0, 0);
203 -
204 -          offset = [ns_view->priv->view convertRect: offset
205 -                                           fromView: self];
206 -
207 -          rect.origin.x -= offset.origin.x;
208 -          rect.origin.y -= offset.origin.y;
209 -        }
210 -
211 -      CGContextClipToRect (cg_context, rect);
212 -    }
213 +  if (ns_view)
214 +    cg_context = clip_to_parent_viewports (ns_view, self);
215
216    [self myDrawInsertionPointInRect: aRect
217                               color: aColor
218                            turnedOn: flag];
219
220 -  CGContextRestoreGState (cg_context);
221 +  if (cg_context)
222 +    CGContextRestoreGState (cg_context);
223  }
224  @end
225
226 --
227 1.7.10.2 (Apple Git-33)