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 if (!GDK_WINDOW_IS_MAPPED (gdk_window))
86 /* If the window is not yet mapped, clip_region_with_children
87 * will be empty causing the usual code below to draw nothing.
88 * To not see garbage on the screen, we draw an aesthetic color
89 * here. The garbage would be visible if any widget enabled
90 * the NSView's CALayer in order to add sublayers for custom
93 [NSGraphicsContext saveGraphicsState];
95 [[NSColor windowBackgroundColor] setFill];
96 [NSBezierPath fillRect:rect];
98 [NSGraphicsContext restoreGraphicsState];
103 /* Clear our own bookkeeping of regions that need display */
104 if (impl->needs_display_region)
106 cairo_region_destroy (impl->needs_display_region);
107 impl->needs_display_region = NULL;
110 [self getRectsBeingDrawn:&drawn_rects count:&count];
111 region = cairo_region_create ();
113 for (i = 0; i < count; i++)
115 gdk_rect.x = drawn_rects[i].origin.x;
116 gdk_rect.y = drawn_rects[i].origin.y;
117 gdk_rect.width = drawn_rects[i].size.width;
118 gdk_rect.height = drawn_rects[i].size.height;
120 cairo_region_union_rectangle (region, &gdk_rect);
123 impl->in_paint_rect_count++;
124 _gdk_window_process_updates_recurse (gdk_window, region);
125 impl->in_paint_rect_count--;
127 cairo_region_destroy (region);
129 if (needsInvalidateShadow)
131 [[self window] invalidateShadow];
132 needsInvalidateShadow = NO;
136 -(void)setNeedsInvalidateShadow:(BOOL)invalidate
138 needsInvalidateShadow = invalidate;
141 /* For information on setting up tracking rects properly, see here:
142 * http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf
144 -(void)updateTrackingRect
146 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl);
154 [self removeTrackingRect:trackingRect];
161 /* Note, if we want to set assumeInside we can use:
162 * NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect)
165 rect = [self bounds];
166 trackingRect = [self addTrackingRect:rect
172 -(void)viewDidMoveToWindow
174 if (![self window]) /* We are destroyed already */
177 [self updateTrackingRect];
180 -(void)viewWillMoveToWindow:(NSWindow *)newWindow
182 if (newWindow == nil && trackingRect)
184 [self removeTrackingRect:trackingRect];
189 -(void)setFrame:(NSRect)frame
191 [super setFrame:frame];
194 [self updateTrackingRect];