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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #import "GdkQuartzView.h"
22 #include "gdkwindow-quartz.h"
23 #include "gdkprivate-quartz.h"
24 #include "gdkquartz.h"
26 @implementation GdkQuartzView
32 [self removeTrackingRect:trackingRect];
39 -(void)setGdkWindow:(GdkWindow *)window
44 -(GdkWindow *)gdkWindow
49 -(NSTrackingRectTag)trackingRect
61 if (GDK_WINDOW_DESTROYED (gdk_window))
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);
68 -(void)drawRect:(NSRect)rect
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;
76 cairo_region_t *region;
78 if (GDK_WINDOW_DESTROYED (gdk_window))
81 if (!(private->event_mask & GDK_EXPOSURE_MASK))
84 if (NSEqualRects (rect, NSZeroRect))
87 /* Clear our own bookkeeping of regions that need display */
88 if (impl->needs_display_region)
90 cairo_region_destroy (impl->needs_display_region);
91 impl->needs_display_region = NULL;
94 [self getRectsBeingDrawn:&drawn_rects count:&count];
95 region = cairo_region_create ();
97 for (i = 0; i < count; i++)
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;
104 cairo_region_union_rectangle (region, &gdk_rect);
107 impl->in_paint_rect_count++;
108 _gdk_window_process_updates_recurse (gdk_window, region);
109 impl->in_paint_rect_count--;
111 cairo_region_destroy (region);
113 if (needsInvalidateShadow)
115 [[self window] invalidateShadow];
116 needsInvalidateShadow = NO;
120 -(void)setNeedsInvalidateShadow:(BOOL)invalidate
122 needsInvalidateShadow = invalidate;
125 /* For information on setting up tracking rects properly, see here:
126 * http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf
128 -(void)updateTrackingRect
130 GdkWindowObject *private = GDK_WINDOW_OBJECT (gdk_window);
131 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
139 [self removeTrackingRect:trackingRect];
146 /* Note, if we want to set assumeInside we can use:
147 * NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect)
150 rect = [self bounds];
151 trackingRect = [self addTrackingRect:rect
156 if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
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.
162 _gdk_quartz_events_send_enter_notify_event (gdk_window);
166 -(void)viewDidMoveToWindow
168 if (![self window]) /* We are destroyed already */
171 [self updateTrackingRect];
174 -(void)viewWillMoveToWindow:(NSWindow *)newWindow
176 if (newWindow == nil && trackingRect)
178 [self removeTrackingRect:trackingRect];
183 -(void)setFrame:(NSRect)frame
185 [super setFrame:frame];
188 [self updateTrackingRect];