]> Pileus Git - ~andy/gtk/blob - gdk/quartz/GdkQuartzView.c
Change FSF Address
[~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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #import "GdkQuartzView.h"
20 #include "gdkquartzwindow.h"
21 #include "gdkprivate-quartz.h"
22 #include "gdkquartz.h"
23
24 @implementation GdkQuartzView
25
26 -(void)dealloc
27 {
28   if (trackingRect)
29     {
30       [self removeTrackingRect:trackingRect];
31       trackingRect = 0;
32     }
33
34   [super dealloc];
35 }
36
37 -(void)setGdkWindow:(GdkWindow *)window
38 {
39   gdk_window = window;
40 }
41
42 -(GdkWindow *)gdkWindow
43 {
44   return gdk_window;
45 }
46
47 -(NSTrackingRectTag)trackingRect
48 {
49   return trackingRect;
50 }
51
52 -(BOOL)isFlipped
53 {
54   return YES;
55 }
56
57 -(BOOL)isOpaque
58 {
59   if (GDK_WINDOW_DESTROYED (gdk_window))
60     return YES;
61
62   /* A view is opaque if its GdkWindow doesn't have the RGBA visual */
63   return gdk_window_get_visual (gdk_window) != gdk_screen_get_rgba_visual (_gdk_screen);
64 }
65
66 -(void)drawRect:(NSRect)rect 
67 {
68   GdkRectangle gdk_rect;
69   GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl);
70   const NSRect *drawn_rects;
71   NSInteger count;
72   int i;
73   cairo_region_t *region;
74
75   if (GDK_WINDOW_DESTROYED (gdk_window))
76     return;
77
78   if (!(gdk_window->event_mask & GDK_EXPOSURE_MASK))
79     return;
80
81   if (NSEqualRects (rect, NSZeroRect))
82     return;
83
84   /* Clear our own bookkeeping of regions that need display */
85   if (impl->needs_display_region)
86     {
87       cairo_region_destroy (impl->needs_display_region);
88       impl->needs_display_region = NULL;
89     }
90
91   [self getRectsBeingDrawn:&drawn_rects count:&count];
92   region = cairo_region_create ();
93   
94   for (i = 0; i < count; i++)
95     {
96       gdk_rect.x = drawn_rects[i].origin.x;
97       gdk_rect.y = drawn_rects[i].origin.y;
98       gdk_rect.width = drawn_rects[i].size.width;
99       gdk_rect.height = drawn_rects[i].size.height;
100
101       cairo_region_union_rectangle (region, &gdk_rect);
102     }
103
104   impl->in_paint_rect_count++;
105   _gdk_window_process_updates_recurse (gdk_window, region);
106   impl->in_paint_rect_count--;
107
108   cairo_region_destroy (region);
109
110   if (needsInvalidateShadow)
111     {
112       [[self window] invalidateShadow];
113       needsInvalidateShadow = NO;
114     }
115 }
116
117 -(void)setNeedsInvalidateShadow:(BOOL)invalidate
118 {
119   needsInvalidateShadow = invalidate;
120 }
121
122 /* For information on setting up tracking rects properly, see here:
123  * http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf
124  */
125 -(void)updateTrackingRect
126 {
127   GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl);
128   NSRect rect;
129
130   if (!impl->toplevel)
131     return;
132
133   if (trackingRect)
134     {
135       [self removeTrackingRect:trackingRect];
136       trackingRect = 0;
137     }
138
139   if (!impl->toplevel)
140     return;
141
142   /* Note, if we want to set assumeInside we can use:
143    * NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect)
144    */
145
146   rect = [self bounds];
147   trackingRect = [self addTrackingRect:rect
148                                  owner:self
149                               userData:nil
150                           assumeInside:NO];
151
152   if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
153     {
154       /* When a new window (and thus view) has been created, and the mouse
155        * is in the window area, we will not receive an NSMouseEntered
156        * event.  Therefore, we synthesize an enter notify event manually.
157        */
158       _gdk_quartz_events_send_enter_notify_event (gdk_window);
159     }
160 }
161
162 -(void)viewDidMoveToWindow
163 {
164   if (![self window]) /* We are destroyed already */
165       return;
166
167   [self updateTrackingRect];
168 }
169
170 -(void)viewWillMoveToWindow:(NSWindow *)newWindow
171 {
172   if (newWindow == nil && trackingRect)
173     {
174       [self removeTrackingRect:trackingRect];
175       trackingRect = 0;
176     }
177 }
178
179 -(void)setFrame:(NSRect)frame
180 {
181   [super setFrame:frame];
182
183   if ([self window])
184     [self updateTrackingRect];
185 }
186
187 @end