Fix 'mono' package typo
[mono.git] / bockbuild / mac-sdk / patches / gtk / 0044-gtknsview-clip-drawRect-to-a-parent-GtkViewport-s-wi.patch
1 From 08f7cca62c0a810d1bd5eaf52813b9ecb776478e Mon Sep 17 00:00:00 2001
2 From: Michael Natterer <mitch@gimp.org>
3 Date: Fri, 1 Mar 2013 12:39:41 +0100
4 Subject: [PATCH 44/68] gtknsview: clip drawRect to a parent GtkViewport's
5  window
6
7 not quite perfect yet, but getting there...
8 ---
9  gtk/gtknsview.c |  121 +++++++++++++++++++++++++++++++++++++++++++++++++------
10  1 file changed, 109 insertions(+), 12 deletions(-)
11
12 diff --git a/gtk/gtknsview.c b/gtk/gtknsview.c
13 index a19a94e..84d758f 100644
14 --- a/gtk/gtknsview.c
15 +++ b/gtk/gtknsview.c
16 @@ -28,6 +28,7 @@
17  #include <objc/runtime.h>
18
19  #include "gtknsview.h"
20 +#include "gtkviewport.h"
21  #include "gtkprivate.h"
22  #include "gtkintl.h"
23  #include "gtkalias.h"
24 @@ -52,6 +53,7 @@ struct _GtkNSViewPrivate
25                                        GTK_TYPE_NS_VIEW, GtkNSViewPrivate))
26
27
28 +static void       gtk_ns_view_constructed   (GObject        *object);
29  static void       gtk_ns_view_finalize      (GObject        *object);
30  static void       gtk_ns_view_set_property  (GObject        *object,
31                                               guint           prop_id,
32 @@ -89,7 +91,6 @@ static gboolean   gtk_ns_view_forward_event        (GtkWidget     *widget,
33
34  G_DEFINE_TYPE (GtkNSView, gtk_ns_view, GTK_TYPE_WIDGET)
35
36 -
37  static void
38  gtk_ns_view_class_init (GtkNSViewClass *klass)
39  {
40 @@ -98,6 +99,7 @@ gtk_ns_view_class_init (GtkNSViewClass *klass)
41
42    g_type_class_add_private (klass, sizeof (GtkNSViewPrivate));
43
44 +  object_class->constructed = gtk_ns_view_constructed;
45    object_class->finalize = gtk_ns_view_finalize;
46    object_class->set_property = gtk_ns_view_set_property;
47    object_class->get_property = gtk_ns_view_get_property;
48 @@ -136,6 +138,111 @@ gtk_ns_view_init (GtkNSView *ns_view)
49    gtk_widget_set_has_window (GTK_WIDGET (ns_view), FALSE);
50  }
51
52 +@implementation NSView (myDrawRect)
53 +- (void) myDrawRect: (NSRect) dirtyRect
54 +{
55 +  GtkNSView *ns_view;
56 +  GtkWidget *viewport;
57 +
58 +#if 0
59 +  g_printerr ("drawRect called\n");
60 +#endif
61 +
62 +  ns_view = (GtkNSView *) objc_getAssociatedObject (self, "gtknsview");
63 +
64 +  if (! ns_view)
65 +    {
66 +      [self myDrawRect: dirtyRect];
67 +      return;
68 +    }
69 +
70 +  viewport = gtk_widget_get_ancestor (GTK_WIDGET (ns_view), GTK_TYPE_VIEWPORT);
71 +
72 +  if (viewport)
73 +    {
74 +      CGContextRef cg_context = [[NSGraphicsContext currentContext] graphicsPort];
75 +      GtkAllocation viewport_allocation;
76 +      CGRect rect;
77 +
78 +#if 0
79 +      g_printerr ("drawRect called on gtknsview in gtkviewport\n");
80 +#endif
81 +
82 +      gtk_widget_get_allocation (viewport, &viewport_allocation);
83 +
84 +      if (gtk_viewport_get_shadow_type (GTK_VIEWPORT (viewport)) != GTK_SHADOW_NONE)
85 +        {
86 +          GtkStyle *style = gtk_widget_get_style (viewport);
87 +
88 +          viewport_allocation.x += style->xthickness;
89 +          viewport_allocation.y += style->ythickness;
90 +          viewport_allocation.width -= 2 * style->xthickness;
91 +          viewport_allocation.height -= 2 * style->ythickness;
92 +        }
93 +
94 +      gtk_widget_translate_coordinates (viewport, GTK_WIDGET (ns_view),
95 +                                        viewport_allocation.x,
96 +                                        viewport_allocation.y,
97 +                                        &viewport_allocation.x,
98 +                                        &viewport_allocation.y);
99 +
100 +      rect.origin.x = viewport_allocation.x;
101 +      rect.origin.y = viewport_allocation.y;
102 +      rect.size.width = viewport_allocation.width;
103 +      rect.size.height = viewport_allocation.height;
104 +
105 +      CGContextSaveGState (cg_context);
106 +      CGContextClipToRect (cg_context, rect);
107 +
108 +      [self myDrawRect: dirtyRect];
109 +
110 +      CGContextRestoreGState (cg_context);
111 +    }
112 +  else
113 +    {
114 +      [self myDrawRect: dirtyRect];
115 +    }
116 +}
117 +@end
118 +
119 +static void
120 +gtk_ns_view_constructed (GObject *object)
121 +{
122 +  GtkNSView *ns_view = GTK_NS_VIEW (object);
123 +  Method original_drawRect;
124 +  Method my_drawRect;
125 +
126 +  G_OBJECT_CLASS (gtk_ns_view_parent_class)->constructed (object);
127 +
128 +  gtk_widget_set_can_focus (GTK_WIDGET (ns_view),
129 +                            [ns_view->priv->view acceptsFirstResponder]);
130 +
131 +#if DEBUG_FOCUS
132 +  g_printerr ("%s can focus: %d\n",
133 +              class_getName ([ns_view->priv->view class]),
134 +              gtk_widget_get_can_focus (GTK_WIDGET (ns_view)));
135 +#endif
136 +
137 +  original_drawRect = class_getInstanceMethod ([ns_view->priv->view class],
138 +                                               @selector (drawRect:));
139 +  my_drawRect = class_getInstanceMethod ([ns_view->priv->view class],
140 +                                         @selector (myDrawRect:));
141 +
142 +  if (class_addMethod ([ns_view->priv->view class],
143 +                       @selector (myDrawRect:),
144 +                       method_getImplementation (original_drawRect),
145 +                       method_getTypeEncoding (original_drawRect)))
146 +    {
147 +      class_replaceMethod ([ns_view->priv->view class],
148 +                           @selector (drawRect:),
149 +                           method_getImplementation (my_drawRect),
150 +                           method_getTypeEncoding (my_drawRect));
151 +    }
152 +
153 +  objc_setAssociatedObject (ns_view->priv->view, "gtknsview", (id) ns_view,
154 +                            OBJC_ASSOCIATION_ASSIGN);
155 +}
156 +
157  static void
158  gtk_ns_view_finalize (GObject *object)
159  {
160 @@ -163,17 +270,7 @@ gtk_ns_view_set_property (GObject      *object,
161      case PROP_VIEW:
162        ns_view->priv->view = g_value_get_pointer (value);
163        if (ns_view->priv->view)
164 -        {
165 -          [ns_view->priv->view retain];
166 -          gtk_widget_set_can_focus (GTK_WIDGET (ns_view),
167 -                                    [ns_view->priv->view acceptsFirstResponder]);
168 -
169 -#if DEBUG_FOCUS
170 -          g_printerr ("%s can focus: %d\n",
171 -                      class_getName ([ns_view->priv->view class]),
172 -                      gtk_widget_get_can_focus (GTK_WIDGET (ns_view)));
173 -#endif
174 -        }
175 +        [ns_view->priv->view retain];
176        break;
177
178      default:
179 --
180 1.7.10.2 (Apple Git-33)