3 * Copyright (C) 2005-2007 Imendio AB
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.
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.
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/>.
19 #import "GdkQuartzView.h"
20 #include "gdkquartzwindow.h"
21 #include "gdkprivate-quartz.h"
22 #include "gdkquartz.h"
24 @implementation GdkQuartzView
30 [self removeTrackingRect:trackingRect];
37 -(void)setGdkWindow:(GdkWindow *)window
42 -(GdkWindow *)gdkWindow
47 -(NSTrackingRectTag)trackingRect
59 if (GDK_WINDOW_DESTROYED (gdk_window))
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);
66 -(void)drawRect:(NSRect)rect
68 GdkRectangle gdk_rect;
69 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl);
70 const NSRect *drawn_rects;
73 cairo_region_t *region;
75 if (GDK_WINDOW_DESTROYED (gdk_window))
78 if (!(gdk_window->event_mask & GDK_EXPOSURE_MASK))
81 if (NSEqualRects (rect, NSZeroRect))
84 /* Clear our own bookkeeping of regions that need display */
85 if (impl->needs_display_region)
87 cairo_region_destroy (impl->needs_display_region);
88 impl->needs_display_region = NULL;
91 [self getRectsBeingDrawn:&drawn_rects count:&count];
92 region = cairo_region_create ();
94 for (i = 0; i < count; i++)
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;
101 cairo_region_union_rectangle (region, &gdk_rect);
104 impl->in_paint_rect_count++;
105 _gdk_window_process_updates_recurse (gdk_window, region);
106 impl->in_paint_rect_count--;
108 cairo_region_destroy (region);
110 if (needsInvalidateShadow)
112 [[self window] invalidateShadow];
113 needsInvalidateShadow = NO;
117 -(void)setNeedsInvalidateShadow:(BOOL)invalidate
119 needsInvalidateShadow = invalidate;
122 /* For information on setting up tracking rects properly, see here:
123 * http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf
125 -(void)updateTrackingRect
127 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl);
135 [self removeTrackingRect:trackingRect];
142 /* Note, if we want to set assumeInside we can use:
143 * NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect)
146 rect = [self bounds];
147 trackingRect = [self addTrackingRect:rect
152 if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
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.
158 _gdk_quartz_events_send_enter_notify_event (gdk_window);
162 -(void)viewDidMoveToWindow
164 if (![self window]) /* We are destroyed already */
167 [self updateTrackingRect];
170 -(void)viewWillMoveToWindow:(NSWindow *)newWindow
172 if (newWindow == nil && trackingRect)
174 [self removeTrackingRect:trackingRect];
179 -(void)setFrame:(NSRect)frame
181 [super setFrame:frame];
184 [self updateTrackingRect];