26
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file ghost/intern/GHOST_SystemCarbon.cpp
31
* $Id: GHOST_SystemCarbon.cpp 30004 2010-07-05 19:59:37Z damien78 $
32
35
* Copyright (C) 2001 NaN Technologies B.V.
33
36
* @author Maarten Gribnau
34
37
* @date May 7, 2001
43
46
#include "GHOST_EventButton.h"
44
47
#include "GHOST_EventCursor.h"
45
48
#include "GHOST_EventWheel.h"
49
#ifdef WITH_INPUT_NDOF
46
50
#include "GHOST_EventNDOF.h"
48
53
#include "GHOST_TimerManager.h"
49
54
#include "GHOST_TimerTask.h"
387
392
void GHOST_SystemCarbon::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const
389
394
BitMap screenBits;
390
Rect bnds = GetQDGlobalsScreenBits(&screenBits)->bounds;
395
Rect bnds = GetQDGlobalsScreenBits(&screenBits)->bounds;
391
396
width = bnds.right - bnds.left;
392
397
height = bnds.bottom - bnds.top;
406
411
const GHOST_TEmbedderWindowID parentWindow
409
GHOST_IWindow* window = 0;
414
GHOST_IWindow* window = 0;
411
416
window = new GHOST_WindowCarbon (title, left, top, width, height, state, type);
414
if (window->getValid()) {
415
// Store the pointer to the window
416
GHOST_ASSERT(m_windowManager, "m_windowManager not initialized");
417
m_windowManager->addWindow(window);
418
m_windowManager->setActiveWindow(window);
419
pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));
419
if (window->getValid()) {
420
// Store the pointer to the window
421
GHOST_ASSERT(m_windowManager, "m_windowManager not initialized");
422
m_windowManager->addWindow(window);
423
m_windowManager->setActiveWindow(window);
424
pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));
422
427
GHOST_PRINT("GHOST_SystemCarbon::createWindow(): window invalid\n");
428
433
GHOST_PRINT("GHOST_SystemCarbon::createWindow(): could not create window\n");
433
438
GHOST_TSuccess GHOST_SystemCarbon::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window, const bool stereoVisual)
516
521
} while (waitForEvent && !anyProcessed);
522
527
GHOST_TSuccess GHOST_SystemCarbon::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const
525
// Get the position of the mouse in the active port
526
::GetGlobalMouse(&mouseLoc);
527
// Convert the coordinates to screen coordinates
528
x = (GHOST_TInt32)mouseLoc.h;
529
y = (GHOST_TInt32)mouseLoc.v;
530
return GHOST_kSuccess;
530
// Get the position of the mouse in the active port
531
::GetGlobalMouse(&mouseLoc);
532
// Convert the coordinates to screen coordinates
533
x = (GHOST_TInt32)mouseLoc.h;
534
y = (GHOST_TInt32)mouseLoc.v;
535
return GHOST_kSuccess;
545
550
// this call below sends event, but empties other events (like shift)
546
551
// CGPostMouseEvent(CGPointMake(xf, yf), TRUE, 1, FALSE, 0);
548
return GHOST_kSuccess;
553
return GHOST_kSuccess;
552
557
GHOST_TSuccess GHOST_SystemCarbon::getModifierKeys(GHOST_ModifierKeys& keys) const
554
UInt32 modifiers = ::GetCurrentKeyModifiers();
559
UInt32 modifiers = ::GetCurrentKeyModifiers();
556
keys.set(GHOST_kModifierKeyCommand, (modifiers & cmdKey) ? true : false);
557
keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & optionKey) ? true : false);
558
keys.set(GHOST_kModifierKeyLeftShift, (modifiers & shiftKey) ? true : false);
559
keys.set(GHOST_kModifierKeyLeftControl, (modifiers & controlKey) ? true : false);
561
keys.set(GHOST_kModifierKeyOS, (modifiers & cmdKey) ? true : false);
562
keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & optionKey) ? true : false);
563
keys.set(GHOST_kModifierKeyLeftShift, (modifiers & shiftKey) ? true : false);
564
keys.set(GHOST_kModifierKeyLeftControl, (modifiers & controlKey) ? true : false);
561
return GHOST_kSuccess;
566
return GHOST_kSuccess;
564
/* XXX, incorrect for multibutton mice */
569
/* XXX, incorrect for multibutton mice */
565
570
GHOST_TSuccess GHOST_SystemCarbon::getButtons(GHOST_Buttons& buttons) const
567
Boolean theOnlyButtonIsDown = ::Button();
569
buttons.set(GHOST_kButtonMaskLeft, theOnlyButtonIsDown);
570
return GHOST_kSuccess;
572
Boolean theOnlyButtonIsDown = ::Button();
574
buttons.set(GHOST_kButtonMaskLeft, theOnlyButtonIsDown);
575
return GHOST_kSuccess;
573
578
#define FIRSTFILEBUFLG 512
574
579
static bool g_hasFirstFile = false;
575
580
static char g_firstFileBuf[512];
577
extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) {
582
extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
578
584
if (g_hasFirstFile) {
579
585
strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1);
580
586
buf[FIRSTFILEBUFLG - 1] = '\0';
653
659
GHOST_TSuccess GHOST_SystemCarbon::init()
656
GHOST_TSuccess success = GHOST_System::init();
662
GHOST_TSuccess success = GHOST_System::init();
659
* Initialize the cursor to the standard arrow shape (so that we can change it later on).
660
* This initializes the cursor's visibility counter to 0.
665
* Initialize the cursor to the standard arrow shape (so that we can change it later on).
666
* This initializes the cursor's visibility counter to 0.
664
670
MenuRef windMenu;
665
671
::CreateStandardWindowMenu(0, &windMenu);
666
672
::InsertMenu(windMenu, 0);
669
::InstallApplicationEventHandler(sEventHandlerProc, GetEventTypeCount(kEvents), kEvents, this, &m_handler);
675
::InstallApplicationEventHandler(sEventHandlerProc, GetEventTypeCount(kEvents), kEvents, this, &m_handler);
671
677
::AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, sAEHandlerLaunch, (SInt32) this, false);
672
678
::AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, sAEHandlerOpenDocs, (SInt32) this, false);
673
679
::AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, sAEHandlerPrintDocs, (SInt32) this, false);
674
680
::AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, sAEHandlerQuit, (SInt32) this, false);
681
687
GHOST_TSuccess GHOST_SystemCarbon::exit()
683
return GHOST_System::exit();
689
return GHOST_System::exit();
853
859
::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos);
854
860
pushEvent(new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, mousePos.h, mousePos.v));
859
865
case kEventMouseWheelMoved:
925
931
type = GHOST_kEventKeyUp;
927
pushEvent( new GHOST_EventKey( getMilliSeconds(), type, window, key, ascii) );
933
pushEvent( new GHOST_EventKey( getMilliSeconds(), type, window, key, ascii, NULL) );
941
947
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & optionKey)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );
943
949
if ((modifiers & cmdKey) != (m_modifierMask & cmdKey)) {
944
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & cmdKey)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );
950
pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & cmdKey)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyOS) );
947
953
m_modifierMask = modifiers;
1089
1095
::HiliteMenu(0);
1094
1100
OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)
1096
1102
GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) userData;
1097
OSStatus err = eventNotHandledErr;
1103
OSStatus err = eventNotHandledErr;
1098
1104
GHOST_IWindow* window;
1105
#ifdef WITH_INPUT_NDOF
1099
1106
GHOST_TEventNDOFData data;
1102
switch (::GetEventClass(event))
1110
switch (::GetEventClass(event))
1104
1112
case kEventClassAppleEvent:
1105
1113
EventRecord eventrec;
1106
1114
if (ConvertEventRefToEventRecord(event, &eventrec)) {
1107
1115
err = AEProcessAppleEvent(&eventrec);
1110
case kEventClassMouse:
1111
err = sys->handleMouseEvent(event);
1118
case kEventClassMouse:
1119
err = sys->handleMouseEvent(event);
1113
1121
case kEventClassWindow:
1114
1122
err = sys->handleWindowEvent(event);
1116
1124
case kEventClassKeyboard:
1117
1125
err = sys->handleKeyEvent(event);
1119
case kEventClassBlender :
1127
case kEventClassBlender :
1128
#ifdef WITH_INPUT_NDOF
1120
1129
window = sys->m_windowManager->getActiveWindow();
1121
1130
sys->m_ndofManager->GHOST_NDOFGetDatas(data);
1122
1131
kind = ::GetEventKind(event);
1214
1224
CFRelease(textData);
1219
const GHOST_TUns8* GHOST_SystemCarbon::getSystemDir() const
1221
return (GHOST_TUns8*)"/Library/Application Support";
1224
const GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
1226
static char usrPath[256] = "";
1227
char* env = getenv("HOME");
1230
strncpy(usrPath, env, 245);
1232
strcat(usrPath, "/Library/Application Support");
1233
return (GHOST_TUns8*) usrPath;
1239
const GHOST_TUns8* GHOST_SystemCarbon::getBinaryDir() const
1242
CFStringRef pathStr;
1243
static char path[256];
1244
CFBundleRef mainBundle = CFBundleGetMainBundle();
1246
bundleURL = CFBundleCopyBundleURL(mainBundle);
1247
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
1248
CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII);
1250
CFRelease(bundleURL);
1251
return (GHOST_TUns8*)path;