| 1 |
/* GdkQuartzWindow.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 |
#include "config.h" |
| 20 |
#import "GdkQuartzNSWindow.h" |
| 21 |
#include "gdkquartzwindow.h" |
| 22 |
#include "gdkdnd-quartz.h" |
| 23 |
#include "gdkprivate-quartz.h" |
| 24 |
#include "gdkinternal-quartz.h" |
| 25 |
#include "gdkquartzdnd.h" |
| 26 |
|
| 27 |
@implementation GdkQuartzNSWindow |
| 28 |
|
| 29 |
- (void)windowWillClose:(NSNotification*)notification |
| 30 |
{ |
| 31 |
// Clears the delegate when window is going to be closed; since EL |
| 32 |
// Capitan it is possible that the methods of delegate would get |
| 33 |
// called after the window has been closed. |
| 34 |
[self setDelegate:nil]; |
| 35 |
} |
| 36 |
|
| 37 |
-(BOOL)windowShouldClose:(id)sender |
| 38 |
{ |
| 39 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 40 |
GdkEvent *event; |
| 41 |
|
| 42 |
event = gdk_event_new (GDK_DELETE); |
| 43 |
|
| 44 |
event->any.window = g_object_ref (window); |
| 45 |
event->any.send_event = FALSE; |
| 46 |
|
| 47 |
_gdk_event_queue_append (gdk_display_get_default (), event); |
| 48 |
|
| 49 |
return NO; |
| 50 |
} |
| 51 |
|
| 52 |
-(void)windowWillMiniaturize:(NSNotification *)aNotification |
| 53 |
{ |
| 54 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 55 |
|
| 56 |
_gdk_quartz_window_detach_from_parent (window); |
| 57 |
} |
| 58 |
|
| 59 |
-(void)windowDidMiniaturize:(NSNotification *)aNotification |
| 60 |
{ |
| 61 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 62 |
|
| 63 |
gdk_synthesize_window_state (window, 0, |
| 64 |
GDK_WINDOW_STATE_ICONIFIED); |
| 65 |
} |
| 66 |
|
| 67 |
-(void)windowDidDeminiaturize:(NSNotification *)aNotification |
| 68 |
{ |
| 69 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 70 |
|
| 71 |
_gdk_quartz_window_attach_to_parent (window); |
| 72 |
|
| 73 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0); |
| 74 |
} |
| 75 |
|
| 76 |
-(void)windowDidBecomeKey:(NSNotification *)aNotification |
| 77 |
{ |
| 78 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 79 |
|
| 80 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FOCUSED); |
| 81 |
_gdk_quartz_events_update_focus_window (window, TRUE); |
| 82 |
} |
| 83 |
|
| 84 |
-(void)windowDidResignKey:(NSNotification *)aNotification |
| 85 |
{ |
| 86 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 87 |
|
| 88 |
_gdk_quartz_events_update_focus_window (window, FALSE); |
| 89 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FOCUSED, 0); |
| 90 |
} |
| 91 |
|
| 92 |
-(void)windowDidBecomeMain:(NSNotification *)aNotification |
| 93 |
{ |
| 94 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 95 |
|
| 96 |
if (![self isVisible]) |
| 97 |
{ |
| 98 |
/* Note: This is a hack needed because for unknown reasons, hidden |
| 99 |
* windows get shown when clicking the dock icon when the application |
| 100 |
* is not already active. |
| 101 |
*/ |
| 102 |
[self orderOut:nil]; |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
_gdk_quartz_window_did_become_main (window); |
| 107 |
} |
| 108 |
|
| 109 |
-(void)windowDidResignMain:(NSNotification *)aNotification |
| 110 |
{ |
| 111 |
GdkWindow *window; |
| 112 |
|
| 113 |
window = [[self contentView] gdkWindow]; |
| 114 |
_gdk_quartz_window_did_resign_main (window); |
| 115 |
} |
| 116 |
|
| 117 |
/* Used in combination with NSLeftMouseUp in sendEvent to keep track |
| 118 |
* of when the window is being moved with the mouse. |
| 119 |
*/ |
| 120 |
-(void)windowWillMove:(NSNotification *)aNotification |
| 121 |
{ |
| 122 |
inMove = YES; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER |
| 127 |
#define NSLeftMouseUp NSEventTypeLeftMouseUp |
| 128 |
#define NSLeftMouseDragged NSEventTypeLeftMouseDragged |
| 129 |
#define NSMouseEntered NSEventTypeMouseEntered |
| 130 |
#endif |
| 131 |
|
| 132 |
-(void)sendEvent:(NSEvent *)event |
| 133 |
{ |
| 134 |
switch ([event type]) |
| 135 |
{ |
| 136 |
case NSLeftMouseUp: |
| 137 |
{ |
| 138 |
double time = ((double)[event timestamp]) * 1000.0; |
| 139 |
|
| 140 |
_gdk_quartz_events_break_all_grabs (time); |
| 141 |
inManualMove = NO; |
| 142 |
inManualResize = NO; |
| 143 |
inMove = NO; |
| 144 |
break; |
| 145 |
} |
| 146 |
|
| 147 |
case NSLeftMouseDragged: |
| 148 |
if ([self trackManualMove] || [self trackManualResize]) |
| 149 |
return; |
| 150 |
break; |
| 151 |
|
| 152 |
default: |
| 153 |
break; |
| 154 |
} |
| 155 |
|
| 156 |
[super sendEvent:event]; |
| 157 |
} |
| 158 |
|
| 159 |
-(BOOL)isInMove |
| 160 |
{ |
| 161 |
return inMove; |
| 162 |
} |
| 163 |
|
| 164 |
-(void)checkSendEnterNotify |
| 165 |
{ |
| 166 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 167 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 168 |
|
| 169 |
/* When a new window has been created, and the mouse |
| 170 |
* is in the window area, we will not receive an NSMouseEntered |
| 171 |
* event. Therefore, we synthesize an enter notify event manually. |
| 172 |
*/ |
| 173 |
if (!initialPositionKnown) |
| 174 |
{ |
| 175 |
initialPositionKnown = YES; |
| 176 |
|
| 177 |
if (NSPointInRect ([NSEvent mouseLocation], [self frame])) |
| 178 |
{ |
| 179 |
NSEvent *event; |
| 180 |
|
| 181 |
event = [NSEvent enterExitEventWithType: NSMouseEntered |
| 182 |
location: [self mouseLocationOutsideOfEventStream] |
| 183 |
modifierFlags: 0 |
| 184 |
timestamp: [[NSApp currentEvent] timestamp] |
| 185 |
windowNumber: [impl->toplevel windowNumber] |
| 186 |
context: NULL |
| 187 |
eventNumber: 0 |
| 188 |
trackingNumber: [impl->view trackingRect] |
| 189 |
userData: nil]; |
| 190 |
|
| 191 |
[NSApp postEvent:event atStart:NO]; |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
static void |
| 196 |
synthesize_configure_event(GdkWindow *window) |
| 197 |
{ |
| 198 |
GdkEvent *event = gdk_event_new (GDK_CONFIGURE); |
| 199 |
|
| 200 |
event->configure.window = g_object_ref (window); |
| 201 |
event->configure.x = window->x; |
| 202 |
event->configure.y = window->y; |
| 203 |
event->configure.width = window->width; |
| 204 |
event->configure.height = window->height; |
| 205 |
|
| 206 |
_gdk_event_queue_append (gdk_display_get_default (), event); |
| 207 |
} |
| 208 |
|
| 209 |
-(void)windowDidMove:(NSNotification *)aNotification |
| 210 |
{ |
| 211 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 212 |
gboolean maximized = gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED; |
| 213 |
|
| 214 |
/* In case the window is changed when maximized remove the maximized state */ |
| 215 |
if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, [self frame])) |
| 216 |
{ |
| 217 |
gdk_synthesize_window_state (window, |
| 218 |
GDK_WINDOW_STATE_MAXIMIZED, |
| 219 |
0); |
| 220 |
} |
| 221 |
|
| 222 |
_gdk_quartz_window_update_position (window); |
| 223 |
synthesize_configure_event(window); |
| 224 |
|
| 225 |
[self checkSendEnterNotify]; |
| 226 |
} |
| 227 |
|
| 228 |
-(void)windowDidResize:(NSNotification *)aNotification |
| 229 |
{ |
| 230 |
NSRect content_rect = [self contentRectForFrameRect:[self frame]]; |
| 231 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 232 |
gboolean maximized = gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED; |
| 233 |
/* Alignment to 4 pixels is on scaled pixels and these are unscaled pixels so divide by scale to compensate. */ |
| 234 |
const gint scale = gdk_window_get_scale_factor (window); |
| 235 |
const guint align = GDK_WINDOW_QUARTZ_ALIGNMENT / scale; |
| 236 |
|
| 237 |
/* see same in windowDidMove */ |
| 238 |
if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, [self frame])) |
| 239 |
{ |
| 240 |
gdk_synthesize_window_state (window, |
| 241 |
GDK_WINDOW_STATE_MAXIMIZED, |
| 242 |
0); |
| 243 |
} |
| 244 |
|
| 245 |
window->width = content_rect.size.width; |
| 246 |
window->height = content_rect.size.height; |
| 247 |
|
| 248 |
if(window->width % align) |
| 249 |
content_rect.size.width = window->width + align - window->width % align; |
| 250 |
|
| 251 |
content_rect.origin.x = 0; |
| 252 |
content_rect.origin.y = 0; |
| 253 |
|
| 254 |
[[self contentView] setFrame:content_rect]; |
| 255 |
/* Certain resize operations (e.g. going fullscreen), also move the |
| 256 |
* origin of the window. |
| 257 |
*/ |
| 258 |
_gdk_quartz_window_update_position (window); |
| 259 |
_gdk_window_update_size (window); |
| 260 |
synthesize_configure_event (window); |
| 261 |
|
| 262 |
[self checkSendEnterNotify]; |
| 263 |
} |
| 264 |
|
| 265 |
-(id)initWithContentRect:(NSRect)contentRect |
| 266 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200 |
| 267 |
styleMask:(NSUInteger)styleMask |
| 268 |
#else |
| 269 |
styleMask:(NSWindowStyleMask)styleMask |
| 270 |
#endif |
| 271 |
backing:(NSBackingStoreType)backingType |
| 272 |
defer:(BOOL)flag |
| 273 |
screen:(NSScreen *)screen |
| 274 |
{ |
| 275 |
self = [super initWithContentRect:contentRect |
| 276 |
styleMask:styleMask |
| 277 |
backing:backingType |
| 278 |
defer:flag |
| 279 |
screen:screen]; |
| 280 |
|
| 281 |
[self setAcceptsMouseMovedEvents:YES]; |
| 282 |
[self setDelegate:(id<NSWindowDelegate>)self]; |
| 283 |
[self setReleasedWhenClosed:YES]; |
| 284 |
|
| 285 |
return self; |
| 286 |
} |
| 287 |
|
| 288 |
-(BOOL)canBecomeMainWindow |
| 289 |
{ |
| 290 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 291 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 292 |
|
| 293 |
switch (impl->type_hint) |
| 294 |
{ |
| 295 |
case GDK_WINDOW_TYPE_HINT_NORMAL: |
| 296 |
case GDK_WINDOW_TYPE_HINT_DIALOG: |
| 297 |
return YES; |
| 298 |
|
| 299 |
case GDK_WINDOW_TYPE_HINT_MENU: |
| 300 |
case GDK_WINDOW_TYPE_HINT_TOOLBAR: |
| 301 |
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN: |
| 302 |
case GDK_WINDOW_TYPE_HINT_UTILITY: |
| 303 |
case GDK_WINDOW_TYPE_HINT_DOCK: |
| 304 |
case GDK_WINDOW_TYPE_HINT_DESKTOP: |
| 305 |
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: |
| 306 |
case GDK_WINDOW_TYPE_HINT_POPUP_MENU: |
| 307 |
case GDK_WINDOW_TYPE_HINT_TOOLTIP: |
| 308 |
case GDK_WINDOW_TYPE_HINT_NOTIFICATION: |
| 309 |
case GDK_WINDOW_TYPE_HINT_COMBO: |
| 310 |
case GDK_WINDOW_TYPE_HINT_DND: |
| 311 |
return NO; |
| 312 |
} |
| 313 |
|
| 314 |
return YES; |
| 315 |
} |
| 316 |
|
| 317 |
-(BOOL)canBecomeKeyWindow |
| 318 |
{ |
| 319 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 320 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 321 |
|
| 322 |
if (!window->accept_focus) |
| 323 |
return NO; |
| 324 |
|
| 325 |
/* Popup windows should not be able to get focused in the window |
| 326 |
* manager sense, it's only handled through grabs. |
| 327 |
*/ |
| 328 |
if (window->window_type == GDK_WINDOW_TEMP) |
| 329 |
return NO; |
| 330 |
|
| 331 |
switch (impl->type_hint) |
| 332 |
{ |
| 333 |
case GDK_WINDOW_TYPE_HINT_NORMAL: |
| 334 |
case GDK_WINDOW_TYPE_HINT_DIALOG: |
| 335 |
case GDK_WINDOW_TYPE_HINT_MENU: |
| 336 |
case GDK_WINDOW_TYPE_HINT_TOOLBAR: |
| 337 |
case GDK_WINDOW_TYPE_HINT_UTILITY: |
| 338 |
case GDK_WINDOW_TYPE_HINT_DOCK: |
| 339 |
case GDK_WINDOW_TYPE_HINT_DESKTOP: |
| 340 |
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: |
| 341 |
case GDK_WINDOW_TYPE_HINT_POPUP_MENU: |
| 342 |
case GDK_WINDOW_TYPE_HINT_COMBO: |
| 343 |
return YES; |
| 344 |
|
| 345 |
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN: |
| 346 |
case GDK_WINDOW_TYPE_HINT_TOOLTIP: |
| 347 |
case GDK_WINDOW_TYPE_HINT_NOTIFICATION: |
| 348 |
case GDK_WINDOW_TYPE_HINT_DND: |
| 349 |
return NO; |
| 350 |
} |
| 351 |
|
| 352 |
return YES; |
| 353 |
} |
| 354 |
|
| 355 |
- (void)showAndMakeKey:(BOOL)makeKey |
| 356 |
{ |
| 357 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 358 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 359 |
|
| 360 |
inShowOrHide = YES; |
| 361 |
|
| 362 |
if (makeKey) |
| 363 |
[impl->toplevel makeKeyAndOrderFront:impl->toplevel]; |
| 364 |
else |
| 365 |
[impl->toplevel orderFront:nil]; |
| 366 |
|
| 367 |
inShowOrHide = NO; |
| 368 |
|
| 369 |
[self checkSendEnterNotify]; |
| 370 |
} |
| 371 |
|
| 372 |
- (void)hide |
| 373 |
{ |
| 374 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 375 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 376 |
|
| 377 |
inShowOrHide = YES; |
| 378 |
[impl->toplevel orderOut:nil]; |
| 379 |
inShowOrHide = NO; |
| 380 |
|
| 381 |
initialPositionKnown = NO; |
| 382 |
} |
| 383 |
|
| 384 |
- (NSPoint)convertPointToScreen:(NSPoint)point |
| 385 |
{ |
| 386 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 |
| 387 |
if (gdk_quartz_osx_version () >= GDK_OSX_MOJAVE) |
| 388 |
return [super convertPointToScreen: point]; |
| 389 |
#endif |
| 390 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 |
| 391 |
if (gdk_quartz_osx_version () < GDK_OSX_LION) |
| 392 |
return [self convertBaseToScreen:point]; |
| 393 |
#endif |
| 394 |
{ |
| 395 |
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0); |
| 396 |
NSRect outrect = [self convertRectToScreen: inrect]; |
| 397 |
return outrect.origin; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
- (NSPoint)convertPointFromScreen:(NSPoint)point |
| 402 |
{ |
| 403 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 |
| 404 |
if (gdk_quartz_osx_version () >= GDK_OSX_MOJAVE) |
| 405 |
return [super convertPointFromScreen: point]; |
| 406 |
#endif |
| 407 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 |
| 408 |
if (gdk_quartz_osx_version () < GDK_OSX_LION) |
| 409 |
return [self convertScreenToBase:point]; |
| 410 |
#endif |
| 411 |
{ |
| 412 |
NSRect inrect = NSMakeRect (point.x, point.y, 0.0, 0.0); |
| 413 |
NSRect outrect = [self convertRectFromScreen: inrect]; |
| 414 |
return outrect.origin; |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
- (BOOL)trackManualMove |
| 419 |
{ |
| 420 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 421 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 422 |
NSPoint currentLocation; |
| 423 |
NSPoint newOrigin; |
| 424 |
NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; |
| 425 |
NSRect windowFrame = [self frame]; |
| 426 |
|
| 427 |
if (!inManualMove) |
| 428 |
return NO; |
| 429 |
|
| 430 |
currentLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]]; |
| 431 |
newOrigin.x = currentLocation.x - initialMoveLocation.x; |
| 432 |
newOrigin.y = currentLocation.y - initialMoveLocation.y; |
| 433 |
|
| 434 |
/* Clamp vertical position to below the menu bar. */ |
| 435 |
if (newOrigin.y + windowFrame.size.height - impl->shadow_top > screenFrame.origin.y + screenFrame.size.height) |
| 436 |
newOrigin.y = screenFrame.origin.y + screenFrame.size.height - windowFrame.size.height + impl->shadow_top; |
| 437 |
|
| 438 |
[self setFrameOrigin:newOrigin]; |
| 439 |
|
| 440 |
return YES; |
| 441 |
} |
| 442 |
|
| 443 |
/* Used by gdkevents-quartz.c to decide if our sendEvent() handler above |
| 444 |
* will see the event or if it will be subjected to standard processing |
| 445 |
* by GDK. |
| 446 |
*/ |
| 447 |
-(BOOL)isInManualResizeOrMove |
| 448 |
{ |
| 449 |
return inManualResize || inManualMove; |
| 450 |
} |
| 451 |
|
| 452 |
-(void)beginManualMove |
| 453 |
{ |
| 454 |
NSRect frame = [self frame]; |
| 455 |
|
| 456 |
if (inMove || inManualMove || inManualResize) |
| 457 |
return; |
| 458 |
|
| 459 |
inManualMove = YES; |
| 460 |
|
| 461 |
initialMoveLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]]; |
| 462 |
initialMoveLocation.x -= frame.origin.x; |
| 463 |
initialMoveLocation.y -= frame.origin.y; |
| 464 |
} |
| 465 |
|
| 466 |
- (BOOL)trackManualResize |
| 467 |
{ |
| 468 |
NSPoint mouse_location; |
| 469 |
NSRect new_frame; |
| 470 |
float mdx, mdy, dw, dh, dx, dy; |
| 471 |
NSSize min_size; |
| 472 |
|
| 473 |
if (!inManualResize || inTrackManualResize) |
| 474 |
return NO; |
| 475 |
|
| 476 |
inTrackManualResize = YES; |
| 477 |
mouse_location = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]]; |
| 478 |
mdx = initialResizeLocation.x - mouse_location.x; |
| 479 |
mdy = initialResizeLocation.y - mouse_location.y; |
| 480 |
|
| 481 |
/* Set how a mouse location delta translates to changes in width, |
| 482 |
* height and position. |
| 483 |
*/ |
| 484 |
dw = dh = dx = dy = 0.0; |
| 485 |
if (resizeEdge == GDK_WINDOW_EDGE_EAST || |
| 486 |
resizeEdge == GDK_WINDOW_EDGE_NORTH_EAST || |
| 487 |
resizeEdge == GDK_WINDOW_EDGE_SOUTH_EAST) |
| 488 |
{ |
| 489 |
dw = -1.0; |
| 490 |
} |
| 491 |
if (resizeEdge == GDK_WINDOW_EDGE_NORTH || |
| 492 |
resizeEdge == GDK_WINDOW_EDGE_NORTH_WEST || |
| 493 |
resizeEdge == GDK_WINDOW_EDGE_NORTH_EAST) |
| 494 |
{ |
| 495 |
dh = -1.0; |
| 496 |
} |
| 497 |
if (resizeEdge == GDK_WINDOW_EDGE_SOUTH || |
| 498 |
resizeEdge == GDK_WINDOW_EDGE_SOUTH_WEST || |
| 499 |
resizeEdge == GDK_WINDOW_EDGE_SOUTH_EAST) |
| 500 |
{ |
| 501 |
dh = 1.0; |
| 502 |
dy = -1.0; |
| 503 |
} |
| 504 |
if (resizeEdge == GDK_WINDOW_EDGE_WEST || |
| 505 |
resizeEdge == GDK_WINDOW_EDGE_NORTH_WEST || |
| 506 |
resizeEdge == GDK_WINDOW_EDGE_SOUTH_WEST) |
| 507 |
{ |
| 508 |
dw = 1.0; |
| 509 |
dx = -1.0; |
| 510 |
} |
| 511 |
|
| 512 |
/* Apply changes to the frame captured when we started resizing */ |
| 513 |
new_frame = initialResizeFrame; |
| 514 |
new_frame.origin.x += mdx * dx; |
| 515 |
new_frame.origin.y += mdy * dy; |
| 516 |
new_frame.size.width += mdx * dw; |
| 517 |
new_frame.size.height += mdy * dh; |
| 518 |
|
| 519 |
/* In case the resulting window would be too small reduce the |
| 520 |
* change to both size and position. |
| 521 |
*/ |
| 522 |
min_size = [self contentMinSize]; |
| 523 |
|
| 524 |
if (new_frame.size.width < min_size.width) |
| 525 |
{ |
| 526 |
if (dx) |
| 527 |
new_frame.origin.x -= min_size.width - new_frame.size.width; |
| 528 |
new_frame.size.width = min_size.width; |
| 529 |
} |
| 530 |
|
| 531 |
if (new_frame.size.height < min_size.height) |
| 532 |
{ |
| 533 |
if (dy) |
| 534 |
new_frame.origin.y -= min_size.height - new_frame.size.height; |
| 535 |
new_frame.size.height = min_size.height; |
| 536 |
} |
| 537 |
|
| 538 |
/* We could also apply aspect ratio: |
| 539 |
new_frame.size.height = new_frame.size.width / [self aspectRatio].width * [self aspectRatio].height; |
| 540 |
*/ |
| 541 |
|
| 542 |
[self setFrame:new_frame display:YES]; |
| 543 |
|
| 544 |
/* Let the resizing be handled by GTK+. */ |
| 545 |
if (g_main_context_pending (NULL)) |
| 546 |
g_main_context_iteration (NULL, FALSE); |
| 547 |
|
| 548 |
inTrackManualResize = NO; |
| 549 |
|
| 550 |
return YES; |
| 551 |
} |
| 552 |
|
| 553 |
-(void)beginManualResize:(GdkWindowEdge)edge |
| 554 |
{ |
| 555 |
if (inMove || inManualMove || inManualResize) |
| 556 |
return; |
| 557 |
|
| 558 |
inManualResize = YES; |
| 559 |
resizeEdge = edge; |
| 560 |
|
| 561 |
initialResizeFrame = [self frame]; |
| 562 |
initialResizeLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]]; |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
static GdkDragContext *current_context = NULL; |
| 568 |
|
| 569 |
static GdkDragAction |
| 570 |
drag_operation_to_drag_action (NSDragOperation operation) |
| 571 |
{ |
| 572 |
GdkDragAction result = 0; |
| 573 |
|
| 574 |
/* GDK and Quartz drag operations do not map 1:1. |
| 575 |
* This mapping represents about the best that we |
| 576 |
* can come up. |
| 577 |
* |
| 578 |
* Note that NSDragOperationPrivate and GDK_ACTION_PRIVATE |
| 579 |
* have almost opposite meanings: the GDK one means that the |
| 580 |
* destination is solely responsible for the action; the Quartz |
| 581 |
* one means that the source and destination will agree |
| 582 |
* privately on the action. NSOperationGeneric is close in meaning |
| 583 |
* to GDK_ACTION_PRIVATE but there is a problem: it will be |
| 584 |
* sent for any ordinary drag, and likely not understood |
| 585 |
* by any intra-widget drag (since the source & dest are the |
| 586 |
* same). |
| 587 |
*/ |
| 588 |
|
| 589 |
if (operation & NSDragOperationGeneric) |
| 590 |
result |= GDK_ACTION_MOVE; |
| 591 |
if (operation & NSDragOperationCopy) |
| 592 |
result |= GDK_ACTION_COPY; |
| 593 |
if (operation & NSDragOperationMove) |
| 594 |
result |= GDK_ACTION_MOVE; |
| 595 |
if (operation & NSDragOperationLink) |
| 596 |
result |= GDK_ACTION_LINK; |
| 597 |
|
| 598 |
return result; |
| 599 |
} |
| 600 |
|
| 601 |
static NSDragOperation |
| 602 |
drag_action_to_drag_operation (GdkDragAction action) |
| 603 |
{ |
| 604 |
NSDragOperation result = 0; |
| 605 |
|
| 606 |
if (action & GDK_ACTION_COPY) |
| 607 |
result |= NSDragOperationCopy; |
| 608 |
if (action & GDK_ACTION_LINK) |
| 609 |
result |= NSDragOperationLink; |
| 610 |
if (action & GDK_ACTION_MOVE) |
| 611 |
result |= NSDragOperationMove; |
| 612 |
|
| 613 |
return result; |
| 614 |
} |
| 615 |
|
| 616 |
static void |
| 617 |
update_context_from_dragging_info (id <NSDraggingInfo> sender) |
| 618 |
{ |
| 619 |
g_assert (current_context != NULL); |
| 620 |
|
| 621 |
GDK_QUARTZ_DRAG_CONTEXT (current_context)->dragging_info = sender; |
| 622 |
current_context->suggested_action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]); |
| 623 |
current_context->actions = current_context->suggested_action; |
| 624 |
} |
| 625 |
|
| 626 |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
| 627 |
{ |
| 628 |
GdkSeat *seat = NULL; |
| 629 |
GdkEvent *event; |
| 630 |
GdkWindow *window; |
| 631 |
|
| 632 |
if (current_context) |
| 633 |
g_object_unref (current_context); |
| 634 |
|
| 635 |
current_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT, NULL); |
| 636 |
update_context_from_dragging_info (sender); |
| 637 |
|
| 638 |
window = [[self contentView] gdkWindow]; |
| 639 |
|
| 640 |
current_context->display = gdk_window_get_display (window); |
| 641 |
|
| 642 |
seat = gdk_display_get_default_seat (gdk_display_get_default ()); |
| 643 |
gdk_drag_context_set_device (current_context, gdk_seat_get_pointer (seat)); |
| 644 |
event = gdk_event_new (GDK_DRAG_ENTER); |
| 645 |
event->dnd.window = g_object_ref (window); |
| 646 |
event->dnd.send_event = FALSE; |
| 647 |
event->dnd.context = g_object_ref (current_context); |
| 648 |
event->dnd.time = GDK_CURRENT_TIME; |
| 649 |
|
| 650 |
gdk_event_set_device (event, gdk_drag_context_get_device (current_context)); |
| 651 |
gdk_event_set_seat (event, gdk_device_get_seat (gdk_drag_context_get_device (current_context))); |
| 652 |
|
| 653 |
_gdk_event_emit (event); |
| 654 |
|
| 655 |
gdk_event_free (event); |
| 656 |
|
| 657 |
return NSDragOperationNone; |
| 658 |
} |
| 659 |
|
| 660 |
- (void)draggingEnded:(id <NSDraggingInfo>)sender |
| 661 |
{ |
| 662 |
/* leave a note for the source about what action was taken */ |
| 663 |
if (_gdk_quartz_drag_source_context && current_context) |
| 664 |
_gdk_quartz_drag_source_context->action = current_context->action; |
| 665 |
|
| 666 |
if (current_context) |
| 667 |
g_object_unref (current_context); |
| 668 |
current_context = NULL; |
| 669 |
} |
| 670 |
|
| 671 |
- (void)draggingExited:(id <NSDraggingInfo>)sender |
| 672 |
{ |
| 673 |
GdkEvent *event; |
| 674 |
|
| 675 |
event = gdk_event_new (GDK_DRAG_LEAVE); |
| 676 |
event->dnd.window = g_object_ref ([[self contentView] gdkWindow]); |
| 677 |
event->dnd.send_event = FALSE; |
| 678 |
event->dnd.context = g_object_ref (current_context); |
| 679 |
event->dnd.time = GDK_CURRENT_TIME; |
| 680 |
|
| 681 |
gdk_event_set_device (event, gdk_drag_context_get_device (current_context)); |
| 682 |
gdk_event_set_seat (event, gdk_device_get_seat (gdk_drag_context_get_device (current_context))); |
| 683 |
|
| 684 |
_gdk_event_emit (event); |
| 685 |
|
| 686 |
gdk_event_free (event); |
| 687 |
|
| 688 |
g_object_unref (current_context); |
| 689 |
current_context = NULL; |
| 690 |
} |
| 691 |
|
| 692 |
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender |
| 693 |
{ |
| 694 |
NSPoint point = [sender draggingLocation]; |
| 695 |
NSPoint screen_point = [self convertPointToScreen:point]; |
| 696 |
GdkEvent *event; |
| 697 |
int gx, gy; |
| 698 |
|
| 699 |
update_context_from_dragging_info (sender); |
| 700 |
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &gx, &gy); |
| 701 |
|
| 702 |
event = gdk_event_new (GDK_DRAG_MOTION); |
| 703 |
event->dnd.window = g_object_ref ([[self contentView] gdkWindow]); |
| 704 |
event->dnd.send_event = FALSE; |
| 705 |
event->dnd.context = g_object_ref (current_context); |
| 706 |
event->dnd.time = GDK_CURRENT_TIME; |
| 707 |
event->dnd.x_root = gx; |
| 708 |
event->dnd.y_root = gy; |
| 709 |
|
| 710 |
gdk_event_set_device (event, gdk_drag_context_get_device (current_context)); |
| 711 |
gdk_event_set_seat (event, gdk_device_get_seat (gdk_drag_context_get_device (current_context))); |
| 712 |
|
| 713 |
_gdk_event_emit (event); |
| 714 |
|
| 715 |
gdk_event_free (event); |
| 716 |
|
| 717 |
return drag_action_to_drag_operation (current_context->action); |
| 718 |
} |
| 719 |
|
| 720 |
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender |
| 721 |
{ |
| 722 |
NSPoint point = [sender draggingLocation]; |
| 723 |
NSPoint screen_point = [self convertPointToScreen:point]; |
| 724 |
GdkEvent *event; |
| 725 |
int gy, gx; |
| 726 |
|
| 727 |
update_context_from_dragging_info (sender); |
| 728 |
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &gx, &gy); |
| 729 |
|
| 730 |
event = gdk_event_new (GDK_DROP_START); |
| 731 |
event->dnd.window = g_object_ref ([[self contentView] gdkWindow]); |
| 732 |
event->dnd.send_event = FALSE; |
| 733 |
event->dnd.context = g_object_ref (current_context); |
| 734 |
event->dnd.time = GDK_CURRENT_TIME; |
| 735 |
event->dnd.x_root = gx; |
| 736 |
event->dnd.y_root = gy; |
| 737 |
|
| 738 |
gdk_event_set_device (event, gdk_drag_context_get_device (current_context)); |
| 739 |
gdk_event_set_seat (event, gdk_device_get_seat (gdk_drag_context_get_device (current_context))); |
| 740 |
|
| 741 |
_gdk_event_emit (event); |
| 742 |
|
| 743 |
gdk_event_free (event); |
| 744 |
|
| 745 |
g_object_unref (current_context); |
| 746 |
current_context = NULL; |
| 747 |
|
| 748 |
return YES; |
| 749 |
} |
| 750 |
|
| 751 |
- (BOOL)wantsPeriodicDraggingUpdates |
| 752 |
{ |
| 753 |
return NO; |
| 754 |
} |
| 755 |
|
| 756 |
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation |
| 757 |
{ |
| 758 |
GdkEvent *event; |
| 759 |
GdkScreen *screen; |
| 760 |
GdkDevice *device; |
| 761 |
|
| 762 |
g_assert (_gdk_quartz_drag_source_context != NULL); |
| 763 |
|
| 764 |
event = gdk_event_new (GDK_DROP_FINISHED); |
| 765 |
event->dnd.window = g_object_ref ([[self contentView] gdkWindow]); |
| 766 |
event->dnd.send_event = FALSE; |
| 767 |
event->dnd.context = g_object_ref (_gdk_quartz_drag_source_context); |
| 768 |
|
| 769 |
screen = gdk_window_get_screen (event->dnd.window); |
| 770 |
|
| 771 |
if (screen) |
| 772 |
{ |
| 773 |
GList* windows, *list; |
| 774 |
gint gx, gy; |
| 775 |
|
| 776 |
event->dnd.context->dest_window = NULL; |
| 777 |
|
| 778 |
windows = gdk_screen_get_toplevel_windows (screen); |
| 779 |
_gdk_quartz_window_nspoint_to_gdk_xy (aPoint, &gx, &gy); |
| 780 |
|
| 781 |
for (list = windows; list; list = list->next) |
| 782 |
{ |
| 783 |
GdkWindow* win = (GdkWindow*) list->data; |
| 784 |
gint wx, wy; |
| 785 |
gint ww, wh; |
| 786 |
|
| 787 |
gdk_window_get_root_origin (win, &wx, &wy); |
| 788 |
ww = gdk_window_get_width (win); |
| 789 |
wh = gdk_window_get_height (win); |
| 790 |
|
| 791 |
if (gx > wx && gy > wy && gx <= wx + ww && gy <= wy + wh) |
| 792 |
{ |
| 793 |
event->dnd.context->dest_window = g_object_ref (win); |
| 794 |
break; |
| 795 |
}} |
| 796 |
} |
| 797 |
|
| 798 |
device = gdk_drag_context_get_device (_gdk_quartz_drag_source_context); |
| 799 |
gdk_event_set_device (event, device); |
| 800 |
gdk_event_set_seat (event, gdk_device_get_seat (device)); |
| 801 |
|
| 802 |
_gdk_event_emit (event); |
| 803 |
|
| 804 |
gdk_event_free (event); |
| 805 |
|
| 806 |
_gdk_quartz_drag_source_context_destroy_gtk_only (); |
| 807 |
} |
| 808 |
|
| 809 |
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER |
| 810 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200 |
| 811 |
typedef enum |
| 812 |
{ |
| 813 |
GDK_QUARTZ_FULL_SCREEN_MASK = NSFullScreenWindowMask, |
| 814 |
} GdkQuartzFullScreen; |
| 815 |
#else |
| 816 |
typedef enum |
| 817 |
{ |
| 818 |
GDK_QUARTZ_FULL_SCREEN_MASK = NSWindowStyleMaskFullScreen, |
| 819 |
} GdkQuartzFullScreen; |
| 820 |
#endif |
| 821 |
- (void)setStyleMask:(NSUInteger)styleMask |
| 822 |
{ |
| 823 |
gboolean was_fullscreen; |
| 824 |
gboolean is_fullscreen; |
| 825 |
|
| 826 |
was_fullscreen = (([self styleMask] & GDK_QUARTZ_FULL_SCREEN_MASK) != 0); |
| 827 |
|
| 828 |
[super setStyleMask:styleMask]; |
| 829 |
|
| 830 |
is_fullscreen = (([self styleMask] & GDK_QUARTZ_FULL_SCREEN_MASK) != 0); |
| 831 |
|
| 832 |
if (was_fullscreen != is_fullscreen) |
| 833 |
_gdk_quartz_window_update_fullscreen_state ([[self contentView] gdkWindow]); |
| 834 |
} |
| 835 |
|
| 836 |
#endif |
| 837 |
|
| 838 |
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen |
| 839 |
{ |
| 840 |
NSRect rect; |
| 841 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 842 |
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl); |
| 843 |
|
| 844 |
/* Allow the window to move up "shadow_top" more than normally allowed |
| 845 |
* by the default impl. This makes it possible to move windows with |
| 846 |
* client side shadow right up to the screen's menu bar. */ |
| 847 |
rect = [super constrainFrameRect:frameRect toScreen:screen]; |
| 848 |
if (frameRect.origin.y > rect.origin.y) |
| 849 |
rect.origin.y = MIN (frameRect.origin.y, rect.origin.y + impl->shadow_top); |
| 850 |
|
| 851 |
return rect; |
| 852 |
} |
| 853 |
|
| 854 |
- (NSRect)windowWillUseStandardFrame:(NSWindow *)nsWindow |
| 855 |
defaultFrame:(NSRect)newFrame |
| 856 |
{ |
| 857 |
NSRect screenFrame = [[self screen] visibleFrame]; |
| 858 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 859 |
gboolean maximized = gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED; |
| 860 |
|
| 861 |
if (!maximized) |
| 862 |
return screenFrame; |
| 863 |
else |
| 864 |
return lastUnmaximizedFrame; |
| 865 |
} |
| 866 |
|
| 867 |
- (BOOL)windowShouldZoom:(NSWindow *)nsWindow |
| 868 |
toFrame:(NSRect)newFrame |
| 869 |
{ |
| 870 |
|
| 871 |
GdkWindow *window = [[self contentView] gdkWindow]; |
| 872 |
gboolean maximized = gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED; |
| 873 |
|
| 874 |
if (maximized) |
| 875 |
{ |
| 876 |
lastMaximizedFrame = newFrame; |
| 877 |
gdk_synthesize_window_state (window, |
| 878 |
GDK_WINDOW_STATE_MAXIMIZED, |
| 879 |
0); |
| 880 |
} |
| 881 |
else |
| 882 |
{ |
| 883 |
lastUnmaximizedFrame = [nsWindow frame]; |
| 884 |
gdk_synthesize_window_state (window, |
| 885 |
0, |
| 886 |
GDK_WINDOW_STATE_MAXIMIZED); |
| 887 |
} |
| 888 |
|
| 889 |
inMaximizeTransition = YES; |
| 890 |
return YES; |
| 891 |
} |
| 892 |
|
| 893 |
-(void)windowDidEndLiveResize:(NSNotification *)aNotification |
| 894 |
{ |
| 895 |
inMaximizeTransition = NO; |
| 896 |
} |
| 897 |
|
| 898 |
-(NSSize)window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize |
| 899 |
{ |
| 900 |
return [[window screen] frame].size; |
| 901 |
} |
| 902 |
|
| 903 |
-(void)windowWillEnterFullScreen:(NSNotification *)aNotification |
| 904 |
{ |
| 905 |
lastUnfullscreenFrame = [self frame]; |
| 906 |
} |
| 907 |
|
| 908 |
-(void)windowWillExitFullScreen:(NSNotification *)aNotification |
| 909 |
{ |
| 910 |
[self setFrame:lastUnfullscreenFrame display:YES]; |
| 911 |
} |
| 912 |
|
| 913 |
@end |