]> Pileus Git - ~andy/gtk/blob - gdk/quartz/GdkQuartzView.c
s/GdkRegion/cairo_region_t/ in all of gtk
[~andy/gtk] / gdk / quartz / GdkQuartzView.c
1 /* GdkQuartzView.m
2  *
3  * Copyright (C) 2005-2007 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #import "GdkQuartzView.h"
22 #include "gdkwindow-quartz.h"
23 #include "gdkprivate-quartz.h"
24 #include "gdkquartz.h"
25
26 @implementation GdkQuartzView
27
28 -(void)dealloc
29 {
30   if (trackingRect)
31     {
32       [self removeTrackingRect:trackingRect];
33       trackingRect = 0;
34     }
35
36   [super dealloc];
37 }
38
39 -(void)setGdkWindow:(GdkWindow *)window
40 {
41   gdk_window = window;
42 }
43
44 -(GdkWindow *)gdkWindow
45 {
46   return gdk_window;
47 }
48
49 -(NSTrackingRectTag)trackingRect
50 {
51   return trackingRect;
52 }
53
54 -(BOOL)isFlipped
55 {
56   return YES;
57 }
58
59 -(BOOL)isOpaque
60 {
61   if (GDK_WINDOW_DESTROYED (gdk_window))
62     return YES;
63
64   /* A view is opaque if its GdkWindow doesn't have the RGBA colormap */
65   return gdk_drawable_get_colormap (gdk_window) != gdk_screen_get_rgba_colormap (_gdk_screen);
66 }
67
68 -(void)drawRect:(NSRect)rect 
69 {
70   GdkRectangle gdk_rect;
71   GdkWindowObject *private = GDK_WINDOW_OBJECT (gdk_window);
72   GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
73   const NSRect *drawn_rects;
74   NSInteger count;
75   int i;
76   cairo_region_t *region;
77
78   if (GDK_WINDOW_DESTROYED (gdk_window))
79     return;
80
81   if (!(private->event_mask & GDK_EXPOSURE_MASK))
82     return;
83
84   if (NSEqualRects (rect, NSZeroRect))
85     return;
86
87   /* Clear our own bookkeeping of regions that need display */
88   if (impl->needs_display_region)
89     {
90       cairo_region_destroy (impl->needs_display_region);
91       impl->needs_display_region = NULL;
92     }
93
94   [self getRectsBeingDrawn:&drawn_rects count:&count];
95   region = cairo_region_create ();
96   
97   for (i = 0; i < count; i++)
98     {
99       gdk_rect.x = drawn_rects[i].origin.x;
100       gdk_rect.y = drawn_rects[i].origin.y;
101       gdk_rect.width = drawn_rects[i].size.width;
102       gdk_rect.height = drawn_rects[i].size.height;
103
104       cairo_region_union_rectangle (region, &gdk_rect);
105     }
106
107   impl->in_paint_rect_count++;
108   _gdk_window_process_updates_recurse (gdk_window, region);
109   impl->in_paint_rect_count--;
110
111   cairo_region_destroy (region);
112
113   if (needsInvalidateShadow)
114     {
115       [[self window] invalidateShadow];
116       needsInvalidateShadow = NO;
117     }
118 }
119
120 -(void)setNeedsInvalidateShadow:(BOOL)invalidate
121 {
122   needsInvalidateShadow = invalidate;
123 }
124
125 /* For information on setting up tracking rects properly, see here:
126  * http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf
127  */
128 -(void)updateTrackingRect
129 {
130   GdkWindowObject *private = GDK_WINDOW_OBJECT (gdk_window);
131   GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
132   NSRect rect;
133
134   if (!impl->toplevel)
135     return;
136
137   if (trackingRect)
138     {
139       [self removeTrackingRect:trackingRect];
140       trackingRect = 0;
141     }
142
143   if (!impl->toplevel)
144     return;
145
146   /* Note, if we want to set assumeInside we can use:
147    * NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect)
148    */
149
150   rect = [self bounds];
151   trackingRect = [self addTrackingRect:rect
152                                  owner:self
153                               userData:nil
154                           assumeInside:NO];
155
156   if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
157     {
158       /* When a new window (and thus view) has been created, and the mouse
159        * is in the window area, we will not receive an NSMouseEntered
160        * event.  Therefore, we synthesize an enter notify event manually.
161        */
162       _gdk_quartz_events_send_enter_notify_event (gdk_window);
163     }
164 }
165
166 -(void)viewDidMoveToWindow
167 {
168   if (![self window]) /* We are destroyed already */
169       return;
170
171   [self updateTrackingRect];
172 }
173
174 -(void)viewWillMoveToWindow:(NSWindow *)newWindow
175 {
176   if (newWindow == nil && trackingRect)
177     {
178       [self removeTrackingRect:trackingRect];
179       trackingRect = 0;
180     }
181 }
182
183 -(void)setFrame:(NSRect)frame
184 {
185   [super setFrame:frame];
186
187   if ([self window])
188     [self updateTrackingRect];
189 }
190
191 @end