44
44
#include "GHOST_SystemCocoa.h"
45
45
#include "GHOST_Debug.h"
47
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
48
/* Lion style fullscreen support when building with the 10.6 SDK */
50
NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7,
51
NSFullScreenWindowMask = 1 << 14
48
55
#pragma mark Cocoa window delegate object
49
/* live resize ugly patch
52
typedef struct bContext bContext;
54
extern int wm_window_timer(const bContext *C);
55
extern void wm_window_process_events(const bContext *C);
56
extern void wm_event_do_handlers(bContext *C);
57
extern void wm_event_do_notifiers(bContext *C);
58
extern void wm_draw_update(bContext *C);
60
57
@interface CocoaWindowDelegate : NSObject
118
115
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
121
/* Live resize ugly patch. Needed because live resize runs in a modal loop, not letting main loop run
118
/* Live resize, send event, gets handled in wm_window.c. Needed because live resize runs in a modal loop, not letting main loop run */
122
119
if ([[notification object] inLiveResize]) {
123
120
systemCocoa->dispatchEvents();
124
wm_window_timer(ghostC);
125
wm_event_do_handlers(ghostC);
126
wm_event_do_notifiers(ghostC);
127
wm_draw_update(ghostC);
131
124
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
276
269
// The trick to prevent Cocoa from complaining (beeping)
277
270
- (void)keyDown:(NSEvent *)event
272
systemCocoa->handleKeyEvent(event);
279
274
/* Start or continue composing? */
280
275
if ([[event characters] length] == 0 ||
281
276
[[event charactersIgnoringModifiers] length] == 0 ||
290
285
[self interpretKeyEvents:events]; // calls insertText
291
286
[events removeObject:event];
292
287
[events release];
298
#if MAC_OS_X_VERSION_MIN_REQUIRED <= 1040
299
//Cmd+key are handled differently before 10.5
300
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
302
NSString *chars = [theEvent charactersIgnoringModifiers];
304
if ([chars length] <1)
307
//Let cocoa handle menu shortcuts
308
switch ([chars characterAtIndex:0]) {
292
- (void)keyUp:(NSEvent *)event
294
systemCocoa->handleKeyEvent(event);
297
- (void)flagsChanged:(NSEvent *)event
299
systemCocoa->handleKeyEvent(event);
302
- (void)mouseDown:(NSEvent *)event
304
systemCocoa->handleMouseEvent(event);
307
- (void)mouseUp:(NSEvent *)event
309
systemCocoa->handleMouseEvent(event);
312
- (void)rightMouseDown:(NSEvent *)event
314
systemCocoa->handleMouseEvent(event);
317
- (void)rightMouseUp:(NSEvent *)event
319
systemCocoa->handleMouseEvent(event);
322
- (void)mouseMoved:(NSEvent *)event
324
systemCocoa->handleMouseEvent(event);
327
- (void)mouseDragged:(NSEvent *)event
329
systemCocoa->handleMouseEvent(event);
332
- (void)rightMouseDragged:(NSEvent *)event
334
systemCocoa->handleMouseEvent(event);
337
- (void)scrollWheel:(NSEvent *)event
339
systemCocoa->handleMouseEvent(event);
342
- (void)otherMouseDown:(NSEvent *)event
344
systemCocoa->handleMouseEvent(event);
347
- (void)otherMouseUp:(NSEvent *)event
349
systemCocoa->handleMouseEvent(event);
352
- (void)otherMouseDragged:(NSEvent *)event
354
systemCocoa->handleMouseEvent(event);
357
- (void)magnifyWithEvent:(NSEvent *)event
359
systemCocoa->handleMouseEvent(event);
362
- (void)rotateWithEvent:(NSEvent *)event
364
systemCocoa->handleMouseEvent(event);
367
- (void)beginGestureWithEvent:(NSEvent *)event
369
systemCocoa->handleMouseEvent(event);
372
- (void)endGestureWithEvent:(NSEvent *)event
374
systemCocoa->handleMouseEvent(event);
377
- (void)tabletPoint:(NSEvent *)event
379
systemCocoa->handleTabletEvent(event,[event type]);
382
- (void)tabletProximity:(NSEvent *)event
384
systemCocoa->handleTabletEvent(event,[event type]);
454
517
GHOST_TDrawingContextType type,
455
518
const bool stereoVisual, const GHOST_TUns16 numOfAASamples
457
GHOST_Window(width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, numOfAASamples),
520
GHOST_Window(width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, false, numOfAASamples),
458
521
m_customCursor(0)
460
523
NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
623
686
[m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
624
687
NSStringPboardType, NSTIFFPboardType, nil]];
689
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
690
if (state != GHOST_kWindowStateFullScreen) {
691
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
626
695
if (state == GHOST_kWindowStateFullScreen)
627
696
setState(GHOST_kWindowStateFullScreen);
845
914
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid");
846
915
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
847
916
GHOST_TWindowState state;
918
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
919
NSUInteger masks = [m_window styleMask];
921
if (masks & NSFullScreenWindowMask) {
922
// Lion style fullscreen
923
state = GHOST_kWindowStateFullScreen;
848
927
if (m_fullScreen) {
849
928
state = GHOST_kWindowStateFullScreen;
953
1032
[m_window zoom:nil];
956
case GHOST_kWindowStateFullScreen:
1035
case GHOST_kWindowStateFullScreen: {
1036
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1037
NSUInteger masks = [m_window styleMask];
1039
if (!m_fullScreen && !(masks & NSFullScreenWindowMask)) {
957
1041
if (!m_fullScreen) {
958
1043
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
960
1045
/* This status change needs to be done before Cocoa call to enter fullscreen mode
963
1048
m_fullScreen = true;
965
1050
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1051
/* Disable toggle for Lion style fullscreen */
1052
[m_window setCollectionBehavior:NSWindowCollectionBehaviorDefault];
1055
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
966
1056
//10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
967
//Hide menu & dock if needed
1057
//Hide menu & dock if on primary screen. else only menu
968
1058
if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) {
969
[NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];
1059
[NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
971
1061
//Make window borderless and enlarge it
972
1062
[m_window setStyleMask:NSBorderlessWindowMask];
1014
1105
case GHOST_kWindowStateNormal:
1016
1107
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1108
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1109
NSUInteger masks = [m_window styleMask];
1111
if (masks & NSFullScreenWindowMask) {
1112
// Lion style fullscreen
1113
[m_window toggleFullScreen:nil];
1017
1117
if (m_fullScreen) {
1018
1118
m_fullScreen = false;
1120
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1121
/* Enable toggle for into Lion style fullscreen */
1122
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1020
1125
//Exit fullscreen
1021
1126
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1022
1127
//Show again menu & dock if needed