| 1 |
/* GdkQuartzView.m |
| 2 |
* |
| 3 |
* Copyright (C) 2005-2007 Imendio AB |
| 4 |
* Copyright (C) 2011 Hiroyuki Yamamoto |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <AvailabilityMacros.h> |
| 21 |
#include "config.h" |
| 22 |
#import "GdkQuartzView.h" |
| 23 |
#include "gdkquartzwindow.h" |
| 24 |
#include "gdkprivate-quartz.h" |
| 25 |
#include "gdkquartz.h" |
| 26 |
#include "gdkinternal-quartz.h" |
| 27 |
#include <cairo/cairo-quartz.h> |
| 28 |
#import <AppKit/AppKit.h> |
| 29 |
#import <IOSurface/IOSurface.h> |
| 30 |
|
| 31 |
@implementation GdkQuartzView |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
-(id)initWithFrame: (NSRect)frameRect |
| 36 |
{ |
| 37 |
if ((self = [super initWithFrame: frameRect])) |
| 38 |
{ |
| 39 |
pb_props = @{ |
| 40 |
(id)kCVPixelBufferIOSurfaceCoreAnimationCompatibilityKey: @1, |
| 41 |
(id)kCVPixelBufferBytesPerRowAlignmentKey: @64, |
| 42 |
}; |
| 43 |
[pb_props retain]; |
| 44 |
cfpb_props = (__bridge CFDictionaryRef)pb_props; |
| 45 |
|
| 46 |
markedRange = NSMakeRange (NSNotFound, 0); |
| 47 |
selectedRange = NSMakeRange (0, 0); |
| 48 |
} |
| 49 |
|
| 50 |
[self setValue: @(YES) forKey: @"postsFrameChangedNotifications"]; |
| 51 |
|
| 52 |
return self; |
| 53 |
} |
| 54 |
|
| 55 |
-(BOOL)acceptsFirstResponder |
| 56 |
{ |
| 57 |
GDK_NOTE (EVENTS, g_message ("acceptsFirstResponder")); |
| 58 |
return YES; |
| 59 |
} |
| 60 |
|
| 61 |
-(BOOL)becomeFirstResponder |
| 62 |
{ |
| 63 |
GDK_NOTE (EVENTS, g_message ("becomeFirstResponder")); |
| 64 |
return YES; |
| 65 |
} |
| 66 |
|
| 67 |
-(BOOL)resignFirstResponder |
| 68 |
{ |
| 69 |
GDK_NOTE (EVENTS, g_message ("resignFirstResponder")); |
| 70 |
return YES; |
| 71 |
} |
| 72 |
|
| 73 |
-(void) keyDown: (NSEvent *) theEvent |
| 74 |
{ |
| 75 |
/* NOTE: When user press Cmd+A, interpretKeyEvents: will call noop: |
| 76 |
method. When user press and hold A to show the accented char window, |
| 77 |
it consumed repeating key down events for key 'A' do NOT call |
| 78 |
any other method. We use this behavior to determine if this key |
| 79 |
down event is filtered by interpretKeyEvents. |
| 80 |
*/ |
| 81 |
|
| 82 |
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, |
| 83 |
GUINT_TO_POINTER (GIC_FILTER_FILTERED)); |
| 84 |
|
| 85 |
GDK_NOTE (EVENTS, g_message ("keyDown")); |
| 86 |
[self interpretKeyEvents: [NSArray arrayWithObject: theEvent]]; |
| 87 |
} |
| 88 |
|
| 89 |
-(void)flagsChanged: (NSEvent *) theEvent |
| 90 |
{ |
| 91 |
} |
| 92 |
|
| 93 |
-(NSUInteger)characterIndexForPoint: (NSPoint)aPoint |
| 94 |
{ |
| 95 |
GDK_NOTE (EVENTS, g_message ("characterIndexForPoint")); |
| 96 |
return 0; |
| 97 |
} |
| 98 |
|
| 99 |
-(NSRect)firstRectForCharacterRange: (NSRange)aRange actualRange: (NSRangePointer)actualRange |
| 100 |
{ |
| 101 |
GDK_NOTE (EVENTS, g_message ("firstRectForCharacterRange")); |
| 102 |
gint ns_x, ns_y; |
| 103 |
GdkRectangle *rect; |
| 104 |
|
| 105 |
rect = g_object_get_data (G_OBJECT (gdk_window), GIC_CURSOR_RECT); |
| 106 |
if (rect) |
| 107 |
{ |
| 108 |
_gdk_quartz_window_gdk_xy_to_xy (rect->x, rect->y + rect->height, |
| 109 |
&ns_x, &ns_y); |
| 110 |
|
| 111 |
return NSMakeRect (ns_x, ns_y, rect->width, rect->height); |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
return NSMakeRect (0, 0, 0, 0); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
-(NSArray *)validAttributesForMarkedText |
| 120 |
{ |
| 121 |
GDK_NOTE (EVENTS, g_message ("validAttributesForMarkedText")); |
| 122 |
return [NSArray arrayWithObjects: NSUnderlineStyleAttributeName, nil]; |
| 123 |
} |
| 124 |
|
| 125 |
-(NSAttributedString *)attributedSubstringForProposedRange: (NSRange)aRange actualRange: (NSRangePointer)actualRange |
| 126 |
{ |
| 127 |
GDK_NOTE (EVENTS, g_message ("attributedSubstringForProposedRange")); |
| 128 |
return nil; |
| 129 |
} |
| 130 |
|
| 131 |
-(BOOL)hasMarkedText |
| 132 |
{ |
| 133 |
GDK_NOTE (EVENTS, g_message ("hasMarkedText")); |
| 134 |
return markedRange.location != NSNotFound && markedRange.length != 0; |
| 135 |
} |
| 136 |
|
| 137 |
-(NSRange)markedRange |
| 138 |
{ |
| 139 |
GDK_NOTE (EVENTS, g_message ("markedRange")); |
| 140 |
return markedRange; |
| 141 |
} |
| 142 |
|
| 143 |
-(NSRange)selectedRange |
| 144 |
{ |
| 145 |
GDK_NOTE (EVENTS, g_message ("selectedRange")); |
| 146 |
return selectedRange; |
| 147 |
} |
| 148 |
|
| 149 |
-(void)unmarkText |
| 150 |
{ |
| 151 |
GDK_NOTE (EVENTS, g_message ("unmarkText")); |
| 152 |
selectedRange = NSMakeRange (0, 0); |
| 153 |
markedRange = NSMakeRange (NSNotFound, 0); |
| 154 |
|
| 155 |
g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, NULL, g_free); |
| 156 |
} |
| 157 |
|
| 158 |
-(void)setMarkedText: (id)aString selectedRange: (NSRange)newSelection replacementRange: (NSRange)replacementRange |
| 159 |
{ |
| 160 |
GDK_NOTE (EVENTS, g_message ("setMarkedText")); |
| 161 |
const char *str; |
| 162 |
|
| 163 |
if (replacementRange.location == NSNotFound) |
| 164 |
{ |
| 165 |
markedRange = NSMakeRange (newSelection.location, [aString length]); |
| 166 |
selectedRange = NSMakeRange (newSelection.location, newSelection.length); |
| 167 |
} |
| 168 |
else { |
| 169 |
markedRange = NSMakeRange (replacementRange.location, [aString length]); |
| 170 |
selectedRange = NSMakeRange (replacementRange.location + newSelection.location, newSelection.length); |
| 171 |
} |
| 172 |
|
| 173 |
if ([aString isKindOfClass: [NSAttributedString class]]) |
| 174 |
{ |
| 175 |
str = [[aString string] UTF8String]; |
| 176 |
} |
| 177 |
else { |
| 178 |
str = [aString UTF8String]; |
| 179 |
} |
| 180 |
|
| 181 |
g_object_set_data_full (G_OBJECT (gdk_window), TIC_MARKED_TEXT, g_strdup (str), g_free); |
| 182 |
g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_POS, |
| 183 |
GUINT_TO_POINTER (selectedRange.location)); |
| 184 |
g_object_set_data (G_OBJECT (gdk_window), TIC_SELECTED_LEN, |
| 185 |
GUINT_TO_POINTER (selectedRange.length)); |
| 186 |
|
| 187 |
GDK_NOTE (EVENTS, g_message ("setMarkedText: set %s (%p, nsview %p): %s", |
| 188 |
TIC_MARKED_TEXT, gdk_window, self, |
| 189 |
str ? str : "(empty)")); |
| 190 |
|
| 191 |
/* handle text input changes by mouse events */ |
| 192 |
if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (gdk_window), |
| 193 |
TIC_IN_KEY_DOWN))) |
| 194 |
{ |
| 195 |
_gdk_quartz_synthesize_null_key_event(gdk_window); |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
-(void)doCommandBySelector: (SEL)aSelector |
| 200 |
{ |
| 201 |
GDK_NOTE (EVENTS, g_message ("doCommandBySelector %s", [NSStringFromSelector (aSelector) UTF8String])); |
| 202 |
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, |
| 203 |
GUINT_TO_POINTER (GIC_FILTER_PASSTHRU)); |
| 204 |
} |
| 205 |
|
| 206 |
-(void)insertText: (id)aString replacementRange: (NSRange)replacementRange |
| 207 |
{ |
| 208 |
GDK_NOTE (EVENTS, g_message ("insertText")); |
| 209 |
const char *str; |
| 210 |
NSString *string; |
| 211 |
|
| 212 |
if ([self hasMarkedText]) |
| 213 |
[self unmarkText]; |
| 214 |
|
| 215 |
if ([aString isKindOfClass: [NSAttributedString class]]) |
| 216 |
string = [aString string]; |
| 217 |
else |
| 218 |
string = aString; |
| 219 |
|
| 220 |
NSCharacterSet *ctrlChars = [NSCharacterSet controlCharacterSet]; |
| 221 |
NSCharacterSet *wsnlChars = [NSCharacterSet whitespaceAndNewlineCharacterSet]; |
| 222 |
if ([string rangeOfCharacterFromSet:ctrlChars].length && |
| 223 |
[string rangeOfCharacterFromSet:wsnlChars].length == 0) |
| 224 |
{ |
| 225 |
/* discard invalid text input with Chinese input methods */ |
| 226 |
str = ""; |
| 227 |
[self unmarkText]; |
| 228 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 |
| 229 |
NSInputManager *currentInputManager = [NSInputManager currentInputManager]; |
| 230 |
[currentInputManager markedTextAbandoned:self]; |
| 231 |
#else |
| 232 |
[[NSTextInputContext currentInputContext] discardMarkedText]; |
| 233 |
#endif |
| 234 |
} |
| 235 |
else |
| 236 |
{ |
| 237 |
str = [string UTF8String]; |
| 238 |
selectedRange = NSMakeRange ([string length], 0); |
| 239 |
} |
| 240 |
|
| 241 |
if (replacementRange.length > 0) |
| 242 |
{ |
| 243 |
g_object_set_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT_REPLACE_LEN, |
| 244 |
GINT_TO_POINTER (replacementRange.length)); |
| 245 |
} |
| 246 |
|
| 247 |
g_object_set_data_full (G_OBJECT (gdk_window), TIC_INSERT_TEXT, g_strdup (str), g_free); |
| 248 |
GDK_NOTE (EVENTS, g_message ("insertText: set %s (%p, nsview %p): %s", |
| 249 |
TIC_INSERT_TEXT, gdk_window, self, |
| 250 |
str ? str : "(empty)")); |
| 251 |
|
| 252 |
g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, |
| 253 |
GUINT_TO_POINTER (GIC_FILTER_FILTERED)); |
| 254 |
|
| 255 |
/* handle text input changes by mouse events */ |
| 256 |
if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (gdk_window), |
| 257 |
TIC_IN_KEY_DOWN))) |
| 258 |
{ |
| 259 |
_gdk_quartz_synthesize_null_key_event(gdk_window); |
| 260 |
} |
| 261 |
} |
| 262 |
/* --------------------------------------------------------------- */ |
| 263 |
|
| 264 |
-(void)dealloc |
| 265 |
{ |
| 266 |
if (trackingRect) |
| 267 |
{ |
| 268 |
[self removeTrackingRect: trackingRect]; |
| 269 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10500 |
| 270 |
[(NSTrackingArea*)trackingRect release]; |
| 271 |
#endif |
| 272 |
trackingRect = 0; |
| 273 |
} |
| 274 |
|
| 275 |
if (pixels) |
| 276 |
{ |
| 277 |
CVPixelBufferRelease (pixels); |
| 278 |
} |
| 279 |
|
| 280 |
[pb_props release]; |
| 281 |
[super dealloc]; |
| 282 |
} |
| 283 |
|
| 284 |
-(void)setGdkWindow: (GdkWindow *)window |
| 285 |
{ |
| 286 |
gdk_window = window; |
| 287 |
} |
| 288 |
|
| 289 |
-(GdkWindow *)gdkWindow |
| 290 |
{ |
| 291 |
return gdk_window; |
| 292 |
} |
| 293 |
|
| 294 |
-(NSTrackingRectTag)trackingRect |
| 295 |
{ |
| 296 |
return trackingRect; |
| 297 |
} |
| 298 |
|
| 299 |
-(BOOL)isFlipped |
| 300 |
{ |
| 301 |
return NO; |
| 302 |
} |
| 303 |
|
| 304 |
-(BOOL)isOpaque |
| 305 |
{ |
| 306 |
if (GDK_WINDOW_DESTROYED (gdk_window)) |
| 307 |
return YES; |
| 308 |
|
| 309 |
/* A view is opaque if its GdkWindow doesn't have the RGBA visual */ |
| 310 |
return gdk_window_get_visual (gdk_window) != |
| 311 |
gdk_screen_get_rgba_visual (_gdk_screen); |
| 312 |
} |
| 313 |
|
| 314 |
- (void) viewWillDraw |
| 315 |
{ |
| 316 |
/* MacOS 11 (Big Sur) has added a new, dynamic "accent" as default. |
| 317 |
* This uses a 10-bit colorspace so every GIMP drawing operation |
| 318 |
* has the additional cost of an 8-bit (ARGB) to 10-bit conversion. |
| 319 |
* Let's disable this mode to regain the lost performance. |
| 320 |
*/ |
| 321 |
if(gdk_quartz_osx_version() >= GDK_OSX_BIGSUR) |
| 322 |
{ |
| 323 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 |
| 324 |
CALayer* layer = self.layer; |
| 325 |
layer.contentsFormat = kCAContentsFormatRGBA8Uint; |
| 326 |
#endif |
| 327 |
} |
| 328 |
|
| 329 |
[super viewWillDraw]; |
| 330 |
} |
| 331 |
|
| 332 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10900 |
| 333 |
-(BOOL)wantsUpdateLayer |
| 334 |
{ |
| 335 |
return YES; |
| 336 |
} |
| 337 |
#endif |
| 338 |
|
| 339 |
-(BOOL)wantsLayer |
| 340 |
{ |
| 341 |
return YES; |
| 342 |
} |
| 343 |
|
| 344 |
static void |
| 345 |
cairo_rect_from_nsrect (cairo_rectangle_int_t *rect, NSRect *nsrect) |
| 346 |
{ |
| 347 |
rect->x = (int)nsrect->origin.x; |
| 348 |
rect->y = (int)nsrect->origin.y; |
| 349 |
rect->width = (int)nsrect->size.width; |
| 350 |
rect->height = (int)nsrect->size.height; |
| 351 |
} |
| 352 |
|
| 353 |
static cairo_status_t |
| 354 |
copy_rectangle_argb32 (cairo_surface_t *dest, cairo_surface_t *source, |
| 355 |
cairo_region_t *region) |
| 356 |
{ |
| 357 |
cairo_surface_t *source_img, *dest_img; |
| 358 |
cairo_status_t status; |
| 359 |
cairo_format_t format; |
| 360 |
int height, width, stride; |
| 361 |
cairo_rectangle_int_t extents; |
| 362 |
|
| 363 |
cairo_region_get_extents (region, &extents); |
| 364 |
source_img = cairo_surface_map_to_image (source, &extents); |
| 365 |
status = cairo_surface_status (source_img); |
| 366 |
|
| 367 |
if (status) |
| 368 |
{ |
| 369 |
g_warning ("Failed to map source image surface, %d %d %d %d on %d %d: %s\n", |
| 370 |
extents.x, extents.y, extents.width, extents.height, |
| 371 |
cairo_image_surface_get_width (source), |
| 372 |
cairo_image_surface_get_height (source), |
| 373 |
cairo_status_to_string (status)); |
| 374 |
return status; |
| 375 |
} |
| 376 |
|
| 377 |
format = cairo_image_surface_get_format (source_img); |
| 378 |
dest_img = cairo_surface_map_to_image (dest, &extents); |
| 379 |
status = cairo_surface_status (dest_img); |
| 380 |
|
| 381 |
if (status) |
| 382 |
{ |
| 383 |
g_warning ("Failed to map destination image surface, %d %d %d %d on %d %d: %s\n", |
| 384 |
extents.x, extents.y, extents.width, extents.height, |
| 385 |
cairo_image_surface_get_width (dest), |
| 386 |
cairo_image_surface_get_height (dest), |
| 387 |
cairo_status_to_string (status)); |
| 388 |
goto CLEANUP; |
| 389 |
} |
| 390 |
|
| 391 |
width = cairo_image_surface_get_width (source_img); |
| 392 |
stride = cairo_format_stride_for_width (format, width); |
| 393 |
height = cairo_image_surface_get_height (source_img); |
| 394 |
memcpy (cairo_image_surface_get_data (dest_img), |
| 395 |
cairo_image_surface_get_data (source_img), |
| 396 |
stride * height); |
| 397 |
cairo_surface_unmap_image (dest, dest_img); |
| 398 |
|
| 399 |
CLEANUP: |
| 400 |
cairo_surface_unmap_image (source, source_img); |
| 401 |
return status; |
| 402 |
} |
| 403 |
|
| 404 |
-(void)updateLayer |
| 405 |
{ |
| 406 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl); |
| 407 |
cairo_rectangle_int_t impl_rect = {0, 0, 0, 0}; |
| 408 |
CGRect layer_bounds = [self.layer bounds]; |
| 409 |
CGRect backing_bounds = [self convertRectToBacking: layer_bounds]; |
| 410 |
cairo_rectangle_int_t bounds_rect; |
| 411 |
cairo_region_t *bounds_region; |
| 412 |
cairo_surface_t *cvpb_surface; |
| 413 |
|
| 414 |
if (GDK_WINDOW_DESTROYED (gdk_window)) |
| 415 |
return; |
| 416 |
|
| 417 |
++impl->in_paint_rect_count; |
| 418 |
|
| 419 |
if (impl->needs_display_region) |
| 420 |
{ |
| 421 |
cairo_region_t *region = impl->needs_display_region; |
| 422 |
_gdk_window_process_updates_recurse (gdk_window, region); |
| 423 |
cairo_region_destroy (region); |
| 424 |
impl->needs_display_region = NULL; |
| 425 |
} |
| 426 |
else |
| 427 |
{ |
| 428 |
cairo_rectangle_int_t bounds; |
| 429 |
cairo_region_t *region; |
| 430 |
|
| 431 |
cairo_rect_from_nsrect (&bounds, &layer_bounds); |
| 432 |
region = cairo_region_create_rectangle(&bounds); |
| 433 |
_gdk_window_process_updates_recurse (gdk_window, region); |
| 434 |
cairo_region_destroy (region); |
| 435 |
} |
| 436 |
|
| 437 |
if (!impl || !impl->cairo_surface) |
| 438 |
return; |
| 439 |
|
| 440 |
CVPixelBufferLockBaseAddress (pixels, 0); |
| 441 |
cvpb_surface = |
| 442 |
cairo_image_surface_create_for_data (CVPixelBufferGetBaseAddress (pixels), |
| 443 |
CAIRO_FORMAT_ARGB32, |
| 444 |
(int)CVPixelBufferGetWidth (pixels), |
| 445 |
(int)CVPixelBufferGetHeight (pixels), |
| 446 |
(int)CVPixelBufferGetBytesPerRow (pixels)); |
| 447 |
|
| 448 |
|
| 449 |
cairo_rect_from_nsrect (&bounds_rect, &backing_bounds); |
| 450 |
bounds_region = cairo_region_create_rectangle (&bounds_rect); |
| 451 |
|
| 452 |
impl_rect.width = cairo_image_surface_get_width (impl->cairo_surface); |
| 453 |
impl_rect.height = cairo_image_surface_get_height (impl->cairo_surface); |
| 454 |
|
| 455 |
cairo_region_intersect_rectangle (bounds_region, &impl_rect); |
| 456 |
copy_rectangle_argb32 (cvpb_surface, impl->cairo_surface, bounds_region); |
| 457 |
|
| 458 |
cairo_surface_destroy (cvpb_surface); |
| 459 |
cairo_region_destroy (bounds_region); |
| 460 |
_gdk_quartz_unref_cairo_surface (gdk_window); // reffed in gdk_window_impl_quartz_begin_paint |
| 461 |
CVPixelBufferUnlockBaseAddress (pixels, 0); |
| 462 |
|
| 463 |
--impl->in_paint_rect_count; |
| 464 |
|
| 465 |
self.layer.contents = NULL; |
| 466 |
self.layer.contents = (id)CVPixelBufferGetIOSurface (pixels); |
| 467 |
} |
| 468 |
|
| 469 |
-(void)setNeedsInvalidateShadow: (BOOL)invalidate |
| 470 |
{ |
| 471 |
needsInvalidateShadow = invalidate; |
| 472 |
} |
| 473 |
|
| 474 |
/* For information on setting up tracking rects properly, see here: |
| 475 |
* http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventOverview.pdf |
| 476 |
*/ |
| 477 |
-(void)updateTrackingRect |
| 478 |
{ |
| 479 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (gdk_window->impl); |
| 480 |
NSRect rect; |
| 481 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10500 |
| 482 |
NSTrackingArea *trackingArea; |
| 483 |
#endif |
| 484 |
|
| 485 |
if (!impl || !impl->toplevel) |
| 486 |
return; |
| 487 |
|
| 488 |
if (trackingRect) |
| 489 |
{ |
| 490 |
[self removeTrackingRect: trackingRect]; |
| 491 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10500 |
| 492 |
[(NSTrackingArea*)trackingRect release]; |
| 493 |
#endif |
| 494 |
trackingRect = 0; |
| 495 |
} |
| 496 |
|
| 497 |
if (!impl->toplevel) |
| 498 |
return; |
| 499 |
|
| 500 |
/* Note, if we want to set assumeInside we can use: |
| 501 |
* NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect) |
| 502 |
*/ |
| 503 |
|
| 504 |
rect = [self bounds]; |
| 505 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10500 |
| 506 |
trackingArea = [[NSTrackingArea alloc] initWithRect: rect |
| 507 |
options: NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag |
| 508 |
owner: self |
| 509 |
userInfo: nil]; |
| 510 |
[self addTrackingArea: trackingArea]; |
| 511 |
trackingRect = (NSInteger)trackingArea; |
| 512 |
#else |
| 513 |
trackingRect = [self addTrackingRect: rect |
| 514 |
owner: self |
| 515 |
userData: nil |
| 516 |
assumeInside: NO]; |
| 517 |
#endif |
| 518 |
} |
| 519 |
|
| 520 |
-(void)viewDidMoveToWindow |
| 521 |
{ |
| 522 |
if (![self window]) /* We are destroyed already */ |
| 523 |
return; |
| 524 |
|
| 525 |
[self updateTrackingRect]; |
| 526 |
} |
| 527 |
|
| 528 |
-(void)viewWillMoveToWindow: (NSWindow *)newWindow |
| 529 |
{ |
| 530 |
if (newWindow == nil && trackingRect) |
| 531 |
{ |
| 532 |
[self removeTrackingRect: trackingRect]; |
| 533 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10500 |
| 534 |
[(NSTrackingArea*)trackingRect release]; |
| 535 |
#endif |
| 536 |
trackingRect = 0; |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
-(void)createBackingStoreWithWidth: (CGFloat) width andHeight: (CGFloat) height |
| 541 |
{ |
| 542 |
IOSurfaceRef surface; |
| 543 |
|
| 544 |
g_return_if_fail (width && height); |
| 545 |
|
| 546 |
CVPixelBufferRelease (pixels); |
| 547 |
CVPixelBufferCreate (NULL, width, height, |
| 548 |
kCVPixelFormatType_32BGRA, |
| 549 |
cfpb_props, &pixels); |
| 550 |
|
| 551 |
surface = CVPixelBufferGetIOSurface (pixels); |
| 552 |
IOSurfaceSetValue(surface, CFSTR("IOSurfaceColorSpace"), |
| 553 |
kCGColorSpaceSRGB); |
| 554 |
} |
| 555 |
|
| 556 |
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 10700 |
| 557 |
-(BOOL)layer:(CALayer*) layer shouldInheritContentsScale: (CGFloat)scale fromWindow: (NSWindow *) window |
| 558 |
{ |
| 559 |
if (layer == self.layer && window == self.window) |
| 560 |
{ |
| 561 |
_gdk_quartz_unref_cairo_surface (gdk_window); |
| 562 |
[self setNeedsDisplay: YES]; |
| 563 |
} |
| 564 |
return YES; |
| 565 |
} |
| 566 |
#endif |
| 567 |
|
| 568 |
-(void)setFrame: (NSRect)frame |
| 569 |
{ |
| 570 |
if (GDK_WINDOW_DESTROYED (gdk_window)) |
| 571 |
return; |
| 572 |
|
| 573 |
_gdk_quartz_unref_cairo_surface (gdk_window); |
| 574 |
[super setFrame: frame]; |
| 575 |
|
| 576 |
if ([self window]) |
| 577 |
[self updateTrackingRect]; |
| 578 |
} |
| 579 |
|
| 580 |
@end |