bool dialog_create_grid_mesh_run(int *xdiv,int *ydiv,int *zdiv) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}; // open the dialog dialog_open(&dialog_create_grid_mesh_wind,"GridMesh"); // install event handler event_upp=NewEventHandlerUPP(create_grid_mesh_event_proc); InstallWindowEventHandler(dialog_create_grid_mesh_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // setup controls dialog_set_int(dialog_create_grid_mesh_wind,kGridMeshXDivision,0,10); dialog_set_int(dialog_create_grid_mesh_wind,kGridMeshYDivision,0,10); dialog_set_int(dialog_create_grid_mesh_wind,kGridMeshZDivision,0,10); // show window ShowWindow(dialog_create_grid_mesh_wind); // modal window dialog_create_grid_mesh_cancel=FALSE; RunAppModalLoopForWindow(dialog_create_grid_mesh_wind); // get object name if (!dialog_create_grid_mesh_cancel) { *xdiv=dialog_get_int(dialog_create_grid_mesh_wind,kGridMeshXDivision,0); *ydiv=dialog_get_int(dialog_create_grid_mesh_wind,kGridMeshYDivision,0); *zdiv=dialog_get_int(dialog_create_grid_mesh_wind,kGridMeshZDivision,0); } // close window DisposeWindow(dialog_create_grid_mesh_wind); return(!dialog_create_grid_mesh_cancel); }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS was loaded"); return 0; } // initialize default output device if (!BASS_Init(-1,44100,0,NULL,NULL)) { Error("Can't initialize device"); return 0; } BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST,1); // enable playlist processing BASS_SetConfig(BASS_CONFIG_NET_PREBUF,0); // minimize automatic pre-buffering, so we can do it (and display it) instead BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,proxy); // setup proxy server location // Create Window and stuff err = CreateNibReference(CFSTR("netradio"), &nibRef); if (err) return err; err = CreateWindowFromNib(nibRef, CFSTR("Window"), &win); if (err) return err; DisposeNibReference(nibRef); int a; for (a=10;a<20;a++) SetupControlHandler(a,kEventControlHit,RadioEventHandler); SetupControlHandler(41,kEventControlHit,DirectEventHandler); { EventTypeSpec etype={'blah','blah'}; InstallApplicationEventHandler(NewEventHandlerUPP(CustomEventHandler),1,&etype,NULL,NULL); } ShowWindow(win); RunApplicationEventLoop(); BASS_Free(); return 0; }
KGlobalAccelImpl::KGlobalAccelImpl(GlobalShortcutsRegistry* owner) : m_owner(owner) , m_eventTarget(GetApplicationEventTarget()) , m_eventHandler(NewEventHandlerUPP(hotKeyEventHandler)) { m_eventType[0].eventClass = kEventClassKeyboard; m_eventType[0].eventKind = kEventHotKeyPressed; m_eventType[1].eventClass = kEventClassKeyboard; // only useful for testing, is not used because count passed in call to InstallEventHandler is 1 m_eventType[1].eventKind = kEventRawKeyDown; refs = new QMap<int, QList<EventHotKeyRef> >(); CFStringRef str = CFStringCreateWithCString(NULL, "AppleKeyboardPreferencesChangedNotification", kCFStringEncodingASCII); if (str) { CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), this, layoutChanged, str, NULL, CFNotificationSuspensionBehaviorHold); CFRelease(str); } else { kWarning(125) << "Couldn't create CFString to register for keyboard notifications"; } }
int install_app_launch_cb(void *user_data) { static int already_installed = 0; if(!already_installed){ EventHandlerUPP cb_upp; EventTypeSpec event_types[2] = { {kEventClassApplication, kEventAppTerminated}, {kEventClassApplication, kEventAppLaunchNotification}}; if((cb_upp = NewEventHandlerUPP(osx_launch_app_callback)) == NULL) return 1; InstallApplicationEventHandler(cb_upp, 2, event_types, user_data, NULL); already_installed = 1; } return 0; }
void palette_polygon_open(int x,int y) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassControl,kEventControlHit}, {kEventClassKeyboard,kEventRawKeyUp}}; // open the window dialog_open(&palette_poly_wind,"PolyPalette"); MoveWindow(palette_poly_wind,x,y,FALSE); // show palette ShowWindow(palette_poly_wind); // install event handler event_upp=NewEventHandlerUPP(palette_poly_event_proc); InstallWindowEventHandler(palette_poly_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); }
static OSStatus setupJoyConfig (OSType type) { OSStatus err = noErr; char elementName[256] = "----"; err = CreateWindowFromNib(nibRef, CFSTR("InputWindow"), &joyWin); if (err == noErr) { EventTypeSpec list[]={ { kEventClassCommand, kEventCommandProcess } }; EventHandlerRef ref; InstallWindowEventHandler (joyWin, NewEventHandlerUPP(joyWinproc), 1, list, (void *)joyWin, &ref); ShowSheetWindow(joyWin, soundWin); if (setJoypad(type, elementName)) { setTitle(type, elementName); } HideSheetWindow(joyWin); DisposeWindow(joyWin); } return(err); }
// --------------------------------------------------------------------------- OSXWindowImpl::OSXWindowImpl(Window* window) : WindowImpl(window) { OSStatus s; WindowClass wc = kDocumentWindowClass; WindowAttributes wa = 0 // |kWindowCompositingAttribute |kWindowStandardDocumentAttributes |kWindowStandardHandlerAttribute |kWindowLiveResizeAttribute ; mRect.left = 100; mRect.right = mRect.left + 256; mRect.top = 100; mRect.bottom = mRect.top + 256; s = CreateNewWindow(wc,wa,&mRect,&mWindowRef); check_noerr(s); EventTypeSpec typeList[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyUp }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged }, { kEventClassMouse, kEventMouseWheelMoved } }; int numTypes = sizeof(typeList)/sizeof(EventTypeSpec); EventHandlerUPP handlerUPP = NewEventHandlerUPP(OSXWindowImpl::memberDelegate); EventTargetRef theTarget; theTarget = GetWindowEventTarget(mWindowRef); InstallEventHandler( theTarget, handlerUPP, numTypes, typeList, this, NULL ); on_init(); }
//----------------------------------------------------------------------------- // wxDockTaskBarIcon ctor // // Initializes the dock implementation of wxTaskBarIcon. // // Here we create some Mac-specific event handlers and UPPs. //----------------------------------------------------------------------------- wxDockTaskBarIcon::wxDockTaskBarIcon(wxTaskBarIcon* parent) : wxTaskBarIconImpl(parent), m_eventHandlerRef(NULL), m_pMenu(NULL), m_theLastMenu(GetApplicationDockTileMenu()), m_iconAdded(false) { // register the events that will return the dock menu EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand }, { kEventClassApplication, kEventAppGetDockTileMenu } }; m_eventupp = NewEventHandlerUPP(wxDockEventHandler); wxASSERT(m_eventupp != NULL); OSStatus err = InstallApplicationEventHandler( m_eventupp, GetEventTypeCount(tbEventList), tbEventList, this, &m_eventHandlerRef); verify_noerr( err ); }
bool loadAboutWin() { IBNibRef nibFile; OSStatus iResult; EventTypeSpec pEvent; g_lpfnAboutProc = NewEventHandlerUPP(aboutEvtHandler); if (noErr != (iResult = CreateNibReference(CFSTR("AboutWin"), &nibFile))) { DisposeEventHandlerUPP(g_lpfnAboutProc); fprintf(stderr, "loadAboutWin() - CreateNibReference(AboutWin) failed, returning %lu!\n", (unsigned long) iResult); return false; } if (noErr != (iResult = CreateWindowFromNib(nibFile, CFSTR("FroggAboutWindow"), &g_refAboutWin))) { DisposeNibReference(nibFile); DisposeEventHandlerUPP(g_lpfnAboutProc); fprintf(stderr, "loadAboutWin() - CreateWindowFromNib(FroggAboutWindow) failed, returning %lu!\n", (unsigned long) iResult); return false; } DisposeNibReference(nibFile); pEvent.eventClass = kEventClassWindow; pEvent.eventKind = kEventWindowClose; if (noErr != (iResult = InstallWindowEventHandler(g_refAboutWin, g_lpfnAboutProc, 1, &pEvent, NULL, &g_refAboutHdlr))) { DisposeWindow(g_refAboutWin); DisposeEventHandlerUPP(g_lpfnAboutProc); fprintf(stderr, "loadAboutWin() - InstallWindowEventHandler() failed, returning %lu!\n", (unsigned long) iResult); return false; } g_bLoaded = true; return true; }
// Create, show and run modally our dialog window OSStatus CreateDialogWindow() { IBNibRef nibRef; EventTypeSpec dialogSpec = {kEventClassCommand, kEventCommandProcess }; WindowRef dialogWindow; EventHandlerUPP dialogUPP; OSStatus err = noErr; // Find the dialog nib err = CreateNibReference(CFSTR("dialog"), &nibRef); require_noerr( err, CantFindDialogNib ); // Load the window inside it err = CreateWindowFromNib(nibRef, CFSTR("dialog"), &dialogWindow); require_noerr( err, CantCreateDialogWindow ); // We don't need the nib reference anymore. DisposeNibReference(nibRef); // Install our event handler dialogUPP = NewEventHandlerUPP (DialogWindowEventHandler); err = InstallWindowEventHandler (dialogWindow, dialogUPP, 1, &dialogSpec, (void *) dialogWindow, NULL); require_noerr( err, CantInstallDialogHandler ); // Show the window ShowWindow( dialogWindow ); // Run modally RunAppModalLoopForWindow(dialogWindow); HideWindow(dialogWindow); DisposeWindow(dialogWindow); DisposeEventHandlerUPP(dialogUPP); CantFindDialogNib: CantCreateDialogWindow: CantInstallDialogHandler: return err; }
bool dialog_group_settings_run(group_type *group) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}; // open the dialog dialog_open(&dialog_group_settings_wind,"GroupSettings"); // set controls dialog_set_text(dialog_group_settings_wind,kGroupName,0,group->name); // show window ShowWindow(dialog_group_settings_wind); // install event handler event_upp=NewEventHandlerUPP(group_setting_event_proc); InstallWindowEventHandler(dialog_group_settings_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // modal window dialog_group_settings_cancel=FALSE; RunAppModalLoopForWindow(dialog_group_settings_wind); // dialog to data if (!dialog_group_settings_cancel) { dialog_get_text(dialog_group_settings_wind,kGroupName,0,group->name,name_str_len); } // close window DisposeWindow(dialog_group_settings_wind); return(!dialog_group_settings_cancel); }
void ui_main() { if( data.init_done ) return; data.init_done = 1; # if defined(NEKO_WINDOWS) { WNDCLASSEX wcl; HINSTANCE hinst = GetModuleHandle(NULL); memset(&wcl,0,sizeof(wcl)); wcl.cbSize = sizeof(WNDCLASSEX); wcl.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcl.lpfnWndProc = WindowProc; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = hinst; wcl.hIcon = NULL; wcl.hCursor = LoadCursor(NULL, IDC_ARROW); wcl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcl.lpszMenuName = ""; wcl.lpszClassName = CLASS_NAME; wcl.hIconSm = 0; RegisterClassEx(&wcl); } data.tid = GetCurrentThreadId(); data.wnd = CreateWindow(CLASS_NAME,"",0,0,0,0,0,NULL,NULL,NULL,NULL); # elif defined(NEKO_MAC) MPCreateTask(nothing,NULL,0,0,0,0,0,NULL); // creates a MPTask that will enable Carbon MT data.tid = pthread_self(); EventTypeSpec ets = { UIEvent, eCall }; InstallEventHandler(GetApplicationEventTarget(),NewEventHandlerUPP(handleEvents),1,&ets,0,0); # elif defined(NEKO_LINUX) g_thread_init(NULL); gdk_threads_init(); gtk_init(NULL,NULL); setlocale(LC_NUMERIC,"POSIX"); // prevent broking atof() data.tid = pthread_self(); pthread_mutex_init(&data.lock,NULL); # endif }
//--------------------------------------------------------------------------------------------- int main() { static const EventTypeSpec sApplicationEvents[] = {{ kEventClassCommand, kEventCommandProcess }}; OSErr err; if (!SystemVersionRequired(0x1020)) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("Need 10.2 or later!"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); return 0; } ProcessSerialNumber psn = {0, kCurrentProcess}; err = GetProcessBundleLocation(&psn, &gApplicationBundleFSRef); err = CreateNibReference(CFSTR("CarbonSketch"), &gOurNibRef ); require_noerr( err, CantGetNibRef ); err = SetMenuBarFromNib( gOurNibRef, CFSTR("MenuBar") ); require_noerr( err, SetMenuBarFromNib_FAILED ); AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, DoOpenApp, 0, false); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, DoOpenDocuments, 0, false); // AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, DoPrintDocuments, 0, false); InstallApplicationEventHandler( NewEventHandlerUPP(AppEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); RunApplicationEventLoop(); SetMenuBarFromNib_FAILED: DisposeNibReference(gOurNibRef); CantGetNibRef: return err; }
void WindowBase::EnableEvent() { OSXWindowData *windowData = new OSXWindowData; windowData->WindowBaseOwner = this; EventTypeSpec list[] = { { kEventClassWindow, kEventWindowShown }, { kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyUp }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp } }; windowData->WindowEventHandler = NewEventHandlerUPP(WindowEventHandler); PRCORE_ASSERT_EXCEPTION( noErr != InstallWindowEventHandler ( mWindowHandle, windowData->WindowEventHandler, GetEventTypeCount (list), list, (void*)windowData, &windowData->EventHandlerReference ) ); windowData->StartedApplicationLoop = false; windowData->EventMainLoopReference = NULL; SetWRefCon (mWindowHandle,(long)windowData); mIsEventEnable=true; }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); MakeWindow(nibRef); // don't need the nib reference anymore. DisposeNibReference(nibRef); const EventTypeSpec commandProcessEvents[] = { { kEventClassCommand, kEventCommandProcess } }; InstallAppleEventHandlers(); InstallApplicationEventHandler( NewEventHandlerUPP(CommandProcessEventHandler), GetEventTypeCount(commandProcessEvents), commandProcessEvents, NULL, NULL ); // Must initialize QuickTime first InitializeQuickTime (); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }
int main(int argc, char* argv[]) { IBNibRef nibRef; WindowRef window; OSStatus err; EventTypeSpec cmdEvent = {kEventClassCommand, kEventCommandProcess}; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); require_noerr( err, CantCreateWindow ); // We don't need the nib reference anymore. DisposeNibReference(nibRef); // The window was created hidden so show it. ShowWindow( window ); InstallApplicationEventHandler(NewEventHandlerUPP(appCommandHandler), GetEventTypeCount(cmdEvent), &cmdEvent, 0, NULL); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }
static OSStatus DoNewWindow( WindowRef *outWindow ) { OSStatus status; static EventHandlerUPP windowEventHandlerUPP; WindowRef window = NULL; const EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess } }; // Create a window. "MainWindow" is the name of the window object. This name is set in InterfaceBuilder when the nib is created. status = CreateWindowFromNib( gMainNibRef, CFSTR("MainWindow"), &window ); require_noerr( status, CantCreateWindow ); if ( windowEventHandlerUPP == NULL ) windowEventHandlerUPP = NewEventHandlerUPP( MainWindowEventHandler ); status = InstallWindowEventHandler( window, windowEventHandlerUPP, GetEventTypeCount(windowEvents), windowEvents, window, NULL ); require_noerr( status, CantInstallWindowEventHandler ); // The window was created hidden so show it if the window parameter is NULL, if it's not, it will be the responsibility of the caller to show it. if ( outWindow == NULL ) ShowWindow( window ); CantInstallWindowEventHandler: CantCreateWindow: if ( outWindow != NULL ) *outWindow = window; return( status ); }
//-------------------------------------------------------------------------------------------- int main( int argc, char *argv[] ) { OSStatus status; const EventTypeSpec commandProcessEvents[] = { { kEventClassCommand, kEventCommandProcess } }; status = CreateNibReference( CFSTR("main"), &gMainNibRef ); require_noerr( status, CantGetNibRef ); status = SetMenuBarFromNib( gMainNibRef, CFSTR("MenuBar") ); require_noerr( status, CantSetMenuBar ); InstallApplicationEventHandler( NewEventHandlerUPP(CommandProcessEventHandler), GetEventTypeCount(commandProcessEvents), commandProcessEvents, NULL, NULL ); NSApplicationLoad(); // Needed for Carbon based applications which call into Cocoa DoNewWindow( NULL ); RunApplicationEventLoop(); // In 10.4, RunApplicationEventLoop also handles our AutoRelease pool used in Cocoa. CantSetMenuBar: CantGetNibRef: return( status ); }
//----------------------------------------------------------------------------// bool MacCEGuiRendererSelector::invokeDialog() { loadDialogWindow(); int rendererCount = populateRendererMenu(); // 'cancel' if there are no renderers available if (rendererCount == 0) d_cancelled = true; // only bother with the dialog if there is a choice ;) else if (rendererCount > 1) { // set the event handling EventTypeSpec cmdEvt; cmdEvt.eventClass = kEventClassCommand; cmdEvt.eventKind = kEventCommandProcess; InstallEventHandler( GetWindowEventTarget(d_dialog), NewEventHandlerUPP(MacCEGuiRendererSelector::eventDispatcher), 1, &cmdEvt, this, 0); ShowWindow(d_dialog); RunApplicationEventLoop(); } SInt32 idx = HIViewGetValue(d_rendererPopup); DisposeWindow(d_dialog); // bail out if user cancelled dialog or if selected index is 0 if (d_cancelled || (idx == 0)) return false; // set the last selected renderer - i.e. the one we want to use. d_lastSelected = d_rendererTypes[idx - 1]; return true; }
static OSErr InitializeApplication( void ) { OSErr err; static const EventTypeSpec sApplicationEvents[] = { { kEventClassCommand, kEventCommandProcess } }; BlockZero( &g, sizeof(g) ); g.mainBundle = CFBundleGetMainBundle(); if ( g.mainBundle == NULL ) { err = -1; goto Bail; } if ( MPLibraryIsLoaded() == false ) { err = -1; goto Bail; } err = CreateNibReferenceWithCFBundle( g.mainBundle, CFSTR("main"), &g.mainNib ); if ( err != noErr ) goto Bail; if ( g.mainNib == NULL ) { err = -1; goto Bail; } err = SetMenuBarFromNib( g.mainNib, CFSTR("MenuBar") ); if ( err != noErr ) goto Bail; InstallApplicationEventHandler( NewEventHandlerUPP(AppEventEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); Bail: return( err ); }
OSStatus PickMonitor (DisplayIDType *inOutDisplayID, WindowRef parentWindow) { WindowRef theWindow; OSStatus status = noErr; static const ControlID kUserPane = { 'MONI', 1 }; // Fetch the dialog IBNibRef aslNib; CFBundleRef theBundle = CFBundleGetMainBundle(); status = CreateNibReferenceWithCFBundle(theBundle, CFSTR("ASLCore"), &aslNib); status = ::CreateWindowFromNib(aslNib, CFSTR( "Pick Monitor" ), &theWindow ); if (status != noErr) { assert(false); return userCanceledErr; } #if 0 // Put game name in window title. By default the title includes the token <<<kGameName>>>. Str255 windowTitle; GetWTitle(theWindow, windowTitle); FormatPStringWithGameName(windowTitle); SetWTitle(theWindow, windowTitle); #endif // Set up the controls ControlRef monitorPane; GetControlByID( theWindow, &kUserPane, &monitorPane ); assert(monitorPane); SetupPickMonitorPane(monitorPane, *inOutDisplayID); // Create our UPP and install the handler. EventTypeSpec cmdEvent = { kEventClassCommand, kEventCommandProcess }; EventHandlerUPP handler = NewEventHandlerUPP( PickMonitorHandler ); InstallWindowEventHandler( theWindow, handler, 1, &cmdEvent, theWindow, NULL ); // Show the window if (parentWindow) ShowSheetWindow( theWindow, parentWindow ); else ShowWindow( theWindow ); // Now we run modally. We will remain here until the PrefHandler // calls QuitAppModalLoopForWindow if the user clicks OK or // Cancel. RunAppModalLoopForWindow( theWindow ); // OK, we're done. Dispose of our window and our UPP. // We do the UPP last because DisposeWindow can send out // CarbonEvents, and we haven't explicitly removed our // handler. If we disposed the UPP, the Toolbox might try // to call it. That would be bad. TearDownPickMonitorPane(monitorPane); if (parentWindow) HideSheetWindow( theWindow ); DisposeWindow( theWindow ); DisposeEventHandlerUPP( handler ); // Return settings to caller if (sSelectedDevice != 0) { // Read back the controls DMGetDisplayIDByGDevice (sSelectedDevice, &*inOutDisplayID, true); return noErr; } else return userCanceledErr; }
COSXScreen::COSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor) : CPlatformScreen(events), m_events(events), MouseButtonEventMap(NumButtonIDs), m_isPrimary(isPrimary), m_isOnScreen(m_isPrimary), m_cursorPosValid(false), m_cursorHidden(false), m_dragNumButtonsDown(0), m_dragTimer(NULL), m_keyState(NULL), m_sequenceNumber(0), m_screensaver(NULL), m_screensaverNotify(false), m_ownClipboard(false), m_clipboardTimer(NULL), m_hiddenWindow(NULL), m_userInputWindow(NULL), m_switchEventHandlerRef(0), m_pmMutex(new CMutex), m_pmWatchThread(NULL), m_pmThreadReady(new CCondVar<bool>(m_pmMutex, false)), m_activeModifierHotKey(0), m_activeModifierHotKeyMask(0), m_lastSingleClick(0), m_lastDoubleClick(0), m_lastSingleClickXCursor(0), m_lastSingleClickYCursor(0), m_autoShowHideCursor(autoShowHideCursor), m_eventTapRLSR(nullptr), m_eventTapPort(nullptr), m_pmRootPort(0) { try { m_displayID = CGMainDisplayID(); updateScreenShape(m_displayID, 0); m_screensaver = new COSXScreenSaver(m_events, getEventTarget()); m_keyState = new COSXKeyState(m_events); // TODO: http://stackoverflow.com/questions/2950124/enable-access-for-assistive-device-programmatically if (m_isPrimary && !AXAPIEnabled()) throw XArch("system setting not enabled: \"Enable access for assistive devices\""); // install display manager notification handler #if defined(MAC_OS_X_VERSION_10_5) CGDisplayRegisterReconfigurationCallback(displayReconfigurationCallback, this); #else m_displayManagerNotificationUPP = NewDMExtendedNotificationUPP(displayManagerCallback); OSStatus err = GetCurrentProcess(&m_PSN); err = DMRegisterExtendedNotifyProc(m_displayManagerNotificationUPP, this, 0, &m_PSN); #endif // install fast user switching event handler EventTypeSpec switchEventTypes[2]; switchEventTypes[0].eventClass = kEventClassSystem; switchEventTypes[0].eventKind = kEventSystemUserSessionDeactivated; switchEventTypes[1].eventClass = kEventClassSystem; switchEventTypes[1].eventKind = kEventSystemUserSessionActivated; EventHandlerUPP switchEventHandler = NewEventHandlerUPP(userSwitchCallback); InstallApplicationEventHandler(switchEventHandler, 2, switchEventTypes, this, &m_switchEventHandlerRef); DisposeEventHandlerUPP(switchEventHandler); constructMouseButtonEventMap(); // watch for requests to sleep m_events->adoptHandler(m_events->forCOSXScreen().confirmSleep(), getEventTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleConfirmSleep)); // create thread for monitoring system power state. *m_pmThreadReady = false; LOG((CLOG_DEBUG "starting watchSystemPowerThread")); m_pmWatchThread = new CThread(new TMethodJob<COSXScreen> (this, &COSXScreen::watchSystemPowerThread)); } catch (...) { m_events->removeHandler(m_events->forCOSXScreen().confirmSleep(), getEventTarget()); if (m_switchEventHandlerRef != 0) { RemoveEventHandler(m_switchEventHandlerRef); } #if defined(MAC_OS_X_VERSION_10_5) CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this); #else if (m_displayManagerNotificationUPP != NULL) { DMRemoveExtendedNotifyProc(m_displayManagerNotificationUPP, NULL, &m_PSN, 0); } if (m_hiddenWindow) { ReleaseWindow(m_hiddenWindow); m_hiddenWindow = NULL; } if (m_userInputWindow) { ReleaseWindow(m_userInputWindow); m_userInputWindow = NULL; } #endif delete m_keyState; delete m_screensaver; throw; } // install event handlers m_events->adoptHandler(CEvent::kSystem, m_events->getSystemTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleSystemEvent)); // install the platform event queue m_events->adoptBuffer(new COSXEventQueueBuffer(m_events)); }
// -------------------------------------------------------------------------------------- void OpenPrefsDialog(void) { ListDefSpec listSpec; DialogRef dialog; WindowRef dialogWindow; EventTypeSpec dialogEvents[] = { {kEventClassControl, kEventControlHit} }; ControlID controlID = {kAppSignature, 0}; ControlRef control; EventTypeSpec listBoxControlEvents[] = { {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent} }; ListHandle iconList; Cell theCell; listSpec.defType = kListDefUserProcType; listSpec.u.userProc = NewListDefUPP(IconListDef); // this is automatically disposed // when the program exits RegisterListDefinition(kIconListLDEF, &listSpec); dialog = GetNewDialog(rPrefsDialog, NULL, kFirstWindowOfClass); if (dialog == NULL) ExitToShell(); SetPortDialogPort(dialog); dialogWindow = GetDialogWindow(dialog); // install window handlers ChangeWindowAttributes(dialogWindow, kWindowStandardHandlerAttribute, kWindowNoAttributes); gDialogEventHandler = NewEventHandlerUPP(dialogEventHandler); InstallWindowEventHandler(dialogWindow, gDialogEventHandler, GetEventTypeCount(dialogEvents), dialogEvents, (void *)dialog, NULL); GetDialogItemAsControl(dialog, kStdOkItemIndex, &control); // set control IDs to controlID.id = kStdOkItemIndex; // match dialog item SetControlID(control, &controlID); // indices which are SetWindowDefaultButton(dialogWindow, control); // not tracked by any // standard handlers GetDialogItemAsControl(dialog, kStdCancelItemIndex, &control); // also set the default controlID.id = kStdCancelItemIndex; // and cancel buttons (because Mac OS 8/9 SetControlID(control, &controlID); // under CarbonLib doesn't respect the SetWindowCancelButton(dialogWindow, control); // dialog's default and cancel buttons) GetDialogItemAsControl(dialog, iIconList, &control); controlID.id = iIconList; SetControlID(control, &controlID); /* We need to postprocess keyboard events on the icon list so that we can change panels after the user changes the selected cell by using the keyboard. */ gListBoxControlEventHandler = NewEventHandlerUPP(listBoxControlEventHandler); InstallControlEventHandler(control, gListBoxControlEventHandler, GetEventTypeCount(listBoxControlEvents), listBoxControlEvents, (void *)dialog, NULL); GetControlData(control, kControlEntireControl, kControlListBoxListHandleTag, sizeof(ListHandle), &iconList, NULL); AddRowsAndDataToIconList(iconList, rIconListIconBaseID); SetListSelectionFlags(iconList, lOnlyOne); SetPt(&theCell, 0, 0); LSetSelect(true, theCell, iconList); SetKeyboardFocus(dialogWindow, control, kControlFocusNextPart); gPanelNumber = 0; SetPrefsDialogHelpTags(dialog); DisableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog); ShowWindow(dialogWindow); } // OpenPrefsDialog
Boolean MCScreenDC::open() { owndnd = False; mouseMoveRgn = NewRgn(); SetRectRgn(mouseMoveRgn, 0, 0, 1, 1); //create a invisible window, and set port to this window //so that later on at the very first time MC select and set font //will only affect in this invisible window, not other apps on the desk top, // when MC is first started. The size of the window is random. // Rect invisibleWinRect; Rect invisibleWinRect; SetRect(&invisibleWinRect, 0, 0, 20, 20); invisibleWin = NewCWindow(nil, &invisibleWinRect, "\p", False, kUtilityWindowClass, (WindowRef)(-1L), False, 0); long response; if (Gestalt(gestaltSystemVersion, &response) == noErr) { if (response >= 0x1030 && response < 0x1040) MCantialiasedtextworkaround = True; else MCantialiasedtextworkaround = False; } SetGWorld(GetWindowPort(invisibleWin), GetMainDevice()); vis = new MCVisualInfo; devdepth = 32; black_pixel.red = black_pixel.green = black_pixel.blue = 0; //black pixel white_pixel.red = white_pixel.green = white_pixel.blue = 0xFFFF; //white pixel black_pixel.pixel = 0; white_pixel.pixel = 0xFFFFFF; redbits = greenbits = bluebits = 8; redshift = 16; greenshift = 8; blueshift = 0; vis->red_mask = 0x00FF0000; vis->green_mask = 0x0000FF00; vis->blue_mask = 0x000000FF; MCzerocolor = MCbrushcolor = white_pixel; alloccolor(MCbrushcolor); MCselectioncolor = MCpencolor = black_pixel; alloccolor(MCselectioncolor); alloccolor(MCpencolor); gray_pixel.red = gray_pixel.green = gray_pixel.blue = 0x8888; alloccolor(gray_pixel); background_pixel.red = background_pixel.green = background_pixel.blue = 0xffff; alloccolor(background_pixel); //query the system for the hilited text color, and set ours RGBColor hiliteRGB; LMGetHiliteRGB(&hiliteRGB); MChilitecolor.red = hiliteRGB.red; MChilitecolor.green = hiliteRGB.green; MChilitecolor.blue = hiliteRGB.blue; alloccolor(MChilitecolor); MCColor *syscolors = getaccentcolors(); if (syscolors != NULL) MCaccentcolor = syscolors[4]; else { MCaccentcolor.red = MCaccentcolor.green = 0x0000; MCaccentcolor.blue = 0x8080; } alloccolor(MCaccentcolor); grabbed = False; tripleclick = doubleclick = False; MCdoubletime = GetDblTime() * 1000 / 60; opened = True; mousewindow = new _Drawable; activewindow = new _Drawable; lastactivewindow = new _Drawable; mousewindow->type = activewindow->type = lastactivewindow->type = DC_WINDOW; mousewindow->handle.window = activewindow->handle.window = lastactivewindow->handle.window = 0; //get handle of application menu bar menuBar = GetMenuBar(); SetMenuBar(menuBar); //set menu bar as current menulist //create Apple menu appleMenu = NewMenu(mApple, "\p\024"); //menu title is an apple icon InsertMenuItem(appleMenu, "\pAbout...", 0); InsertMenu(appleMenu, 0); DrawMenuBar(); //draw the menu bar with the Apple menu usetemp = False; Handle tmem = Get1IndResource('TMEM', 1); if (tmem != NULL) { char *ptr = *tmem; if (*(ptr + 1)) usetemp = True; } MCtemplatescrollbar->alloccolors(); if (IsMacEmulatedLF()) // no AM MCtemplatebutton->allocicons(); // preallocate these because GetItemMark can't distinguish them submenuIDs[0] = 1; submenuIDs[checkMark] = 1; submenuIDs[diamondMark] = 1; MCcursors[PI_NONE] = nil; MCblinkrate = GetCaretTime() * 1000 / 60; MCDisplay const *t_displays; getdisplays(t_displays, false); MCwbr = t_displays[0] . workarea; //TSM - INIT TSM APPLICATION AND INSTALL REQUIRED APPLEVENT HANDLERS TSMPositionToOffsetUPP = NewAEEventHandlerUPP(TSMPositionToOffset); TSMOffsetToPositionUPP = NewAEEventHandlerUPP(TSMOffsetToPosition); TSMUpdateHandlerUPP = NewAEEventHandlerUPP(TSMUpdateHandler); TSMUnicodeNotFromInputUPP = NewAEEventHandlerUPP(TSMUnicodeNotFromInputHandler); AEInstallEventHandler(kTextServiceClass, kPos2Offset, TSMPositionToOffsetUPP, 0L , False); AEInstallEventHandler(kTextServiceClass, kOffset2Pos, TSMOffsetToPositionUPP, 0L , False); AEInstallEventHandler(kTextServiceClass, kUpdateActiveInputArea, TSMUpdateHandlerUPP, 0L , False); AEInstallEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod, TSMUnicodeNotFromInputUPP, 0L , False); openIME(); dragdropUPP = NewDragReceiveHandlerUPP(DragReceiveHandler); InstallReceiveHandler(dragdropUPP, NULL, NULL); dragmoveUPP = NewDragTrackingHandlerUPP(DragTrackingHandler); InstallTrackingHandler(dragmoveUPP, NULL, NULL); s_animation_current_time = s_animation_start_time = CFAbsoluteTimeGetCurrent(); //// Dock Menu Initialization EventTypeSpec t_menu_event_specs[1]; t_menu_event_specs[0] . eventClass = kEventClassMenu; t_menu_event_specs[0] . eventKind = kEventMenuPopulate; CreateNewMenu(0, 0, &f_icon_menu); s_icon_menu_event_handler_upp = NewEventHandlerUPP((EventHandlerProcPtr)handleiconmenuevent); InstallEventHandler(GetMenuEventTarget(f_icon_menu), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL); t_menu_event_specs[0] . eventClass = kEventClassCommand; t_menu_event_specs[0] . eventKind = kEventCommandProcess; InstallEventHandler(GetApplicationEventTarget(), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL); SetApplicationDockTileMenu(f_icon_menu); //// Color Profile Initialization CMGetDefaultProfileBySpace(cmRGBData, &m_dst_profile); CMProfileLocation t_location; t_location . locType = cmPathBasedProfile; strcpy(t_location . u . pathLoc . path, "/System/Library/ColorSync/Profiles/sRGB Profile.icc"); CMOpenProfile(&m_srgb_profile, &t_location); //// return True; }
// TODO Unfinished, issue #1309. static void process_apple_events_new() { OSStatus handler_install_status; OSStatus handler_remove_status; OSStatus event_received; EventTypeSpec event_types[1]; // List of event types to handle. EventHandlerUPP handler_open_doc; EventHandlerRef handler_ref; // Reference for later removing the event handler. EventRef event_ref; // Event that caused ReceiveNextEvent to return. OSType ev_class; UInt32 ev_kind; EventTimeout timeout = 3.0; // number of ticks (1/60th of a second) VS("LOADER: AppleEvent - processing...\n"); // Event types we are interested in. event_types[0].eventClass = kCoreEventClass; event_types[0].eventKind = kAEOpenDocuments; // Carbon Event Manager requires convert the function pointer to type EventHandlerUPP. // https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html handler_open_doc = NewEventHandlerUPP(do_filenames_conversion_to_argv); // Install the event handler. // InstallApplicationEventHandler is a macro for 'InstallEventHandler' where the event target // is Application. // We do not have any windows so having Application as event target should be fine. handler_install_status = InstallApplicationEventHandler(handler_open_doc, 1, event_types, NULL, &handler_ref); if (handler_install_status == noErr) { VS("LOADER: AppleEvent - installed handler.\n"); // TODO //ReceiveNextEvent(); //RunCurrentEventLoop(timeout); //RunApplicationEventLoop(); // Previous func WaitNextEvent() was deprecated and 32-bit only. // Func ReceiveNextEvent() is threadsafe and available even for 64-bit OS X. //gotEvent = WaitNextEvent(highLevelEventMask, &event, timeout, NULL); //event_received = ReceiveNextEvent(1, event_types, kEventDurationForever, true, &event_ref); //event_received = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &event_ref); // TODO //handler_remove_status = RemoveEventHandler(handler_ref); /* if (event_received == noErr) { VS("LOADER: AppleEvent - received event.\n"); ev_class = GetEventClass(event_ref); ev_kind = GetEventKind(event_ref); VS("LOADER: AppleEvent - event type: %u\n", ev_kind); //if (GetEventKind(event_ref) == kAEOpenDocuments) if (ev_class == kCoreEventClass) { VS("LOADER: AppleEvent - right class.\n"); } ReleaseEvent(event_ref); } else { VS("LOADER: AppleEvent - ERROR receiving events code: %d\n", event_received); }*/ } else { VS("LOADER: AppleEvent - ERROR installing handler.\n"); } // Remove handler_ref reference when we are done with EventHandlerUPP. // Carbon Event Manager does not do this automatically. DisposeEventHandlerUPP(handler_open_doc) }
void create_login (HWND hwnd, LPCSTR username, LPCSTR password, LPCSTR dsn, TLOGIN * log_t) { EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit }; RgnHandle cursorRgn = NULL; WindowRef wlogin; ControlRef control; ControlID controlID; EventRecord event; IBNibRef nibRef; OSStatus err; char msg[1024]; if (hwnd == NULL) return; /* Search the bundle for a .nib file named 'odbcadmin'. */ err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (CFSTR ("org.iodbc.drvproxy")), CFSTR ("login"), &nibRef); if (err == noErr) { /* Nib found ... so create the window */ CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wlogin); DisposeNibReference (nibRef); /* Set the title with the DSN */ if (dsn) { msg[0] = STRLEN ("Login for ") + STRLEN(dsn); sprintf (msg+1, "Login for %s", (char*)dsn); SetWTitle (wlogin, msg); } /* Set the control into the structure */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, LBUSER_CNTL, wlogin, log_t->username); GETCONTROLBYID (controlID, CNTL_SIGNATURE, LBPASS_CNTL, wlogin, log_t->password); log_t->user = log_t->pwd = NULL; log_t->mainwnd = wlogin; /* Install handlers for the finish button, the cancel */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, LBOK_CNTL, wlogin, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (login_ok_clicked), 1, &controlSpec, log_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, LBCANCEL_CNTL, wlogin, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (login_cancel_clicked), 1, &controlSpec, log_t, NULL); SetControlData (log_t->username, 0, kControlEditTextTextTag, username ? STRLEN (username) : STRLEN(""), (UInt8 *) username ? username : ""); SetControlData (log_t->password, 0, kControlEditTextPasswordTag, password ? STRLEN (password) : STRLEN(""), (UInt8 *) password ? password : ""); /* Show the window and run the loop */ AdvanceKeyboardFocus (wlogin); ShowWindow (wlogin); /* The main loop */ while (log_t->mainwnd) { switch (WaitNextEvent (everyEvent, &event, 60L, cursorRgn)) { }; } } else goto error; return; error: fprintf (stderr, "Can't load Window. Err: %d\n", (int) err); return; }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams ) { bool hasDepthBuffer; String title = name; size_t fsaa_samples = 0; int left = 0; int top = 0; int depth = 32; if( miscParams ) { NameValuePairList::const_iterator opt = NULL; // Full screen anti aliasing opt = miscParams->find( "FSAA" ); if( opt != miscParams->end() ) fsaa_samples = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "left" ); if( opt != miscParams->end() ) left = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "top" ); if( opt != miscParams->end() ) top = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "title" ); if( opt != miscParams->end() ) title = opt->second; opt = miscParams->find( "depthBuffer" ); if( opt != miscParams->end() ) hasDepthBuffer = StringConverter::parseBool( opt->second ); opt = miscParams->find( "colourDepth" ); if( opt != miscParams->end() ) depth = StringConverter::parseUnsignedInt( opt->second ); } if(fullScreen) { GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext *mainContext = (OSXContext*)rs->_getMainContext(); CGLContextObj share = NULL; if(mainContext == 0) { share = NULL; } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* aglShare = static_cast<OSXCarbonContext*>(mainContext); aglGetCGLContext(aglShare->getContext(), &((void*)share)); } else if(mainContext->getContextType() == "CGL") { OSXCGLContext* cglShare = static_cast<OSXCGLContext*>(mainContext); share = cglShare->getContext(); } // create the context createCGLFullscreen(width, height, depth, fsaa_samples, share); } else { int i = 0; AGLPixelFormat pixelFormat; GLint attribs[ 20 ]; attribs[ i++ ] = AGL_NO_RECOVERY; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_ACCELERATED; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_RGBA; attribs[ i++ ] = AGL_DOUBLEBUFFER; attribs[ i++ ] = AGL_ALPHA_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_STENCIL_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_DEPTH_SIZE; attribs[ i++ ] = depth; if(fsaa_samples > 1) { attribs[ i++ ] = AGL_MULTISAMPLE; attribs[ i++ ] = 1; attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB; attribs[ i++ ] = fsaa_samples; } attribs[ i++ ] = AGL_NONE; pixelFormat = aglChoosePixelFormat( NULL, 0, attribs ); // Create the AGLContext from our pixel format // Share it with main GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() ); if(mainContext == 0) { mAGLContext = aglCreateContext(pixelFormat, NULL); } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() ); AGLContext shared = context->getContext(); mAGLContext = aglCreateContext(pixelFormat, context->getContext()); } else { // If we do not have an AGL, we can not clone it using this window LogManager::getSingleton().logMessage( "Warning: You asked to create a second window, " "when the previous window was not of this type. OgreOSXCarbonWindow can only share " "with an AGL context."); } NameValuePairList::const_iterator opt = 0; if(miscParams) opt = miscParams->find("externalWindowHandle"); if(!miscParams || opt == miscParams->end()) { // create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = width; windowRect.bottom = height; // set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize" if (miscParams) { opt = miscParams->find("border"); if( opt != miscParams->end() ) { String borderType = opt->second; if( borderType == "none" ) windowAttrs = kWindowNoTitleBarAttribute; else if( borderType == "fixed" ) windowAttrs = kWindowStandardFloatingAttributes; } } windowAttrs |= kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowHideOnFullScreenAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow); // Color the window background black SetThemeWindowBackground (mWindow, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindow, titleRef ); // Center our window on the screen RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen ); // Get our view HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView ); // Set up our UPP for Window Events EventTypeSpec eventSpecs[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowShown}, {kEventClassWindow, kEventWindowHidden}, {kEventClassWindow, kEventWindowDragCompleted}, {kEventClassWindow, kEventWindowBoundsChanged}, {kEventClassWindow, kEventWindowExpanded}, {kEventClassWindow, kEventWindowCollapsed}, {kEventClassWindow, kEventWindowClosed}, {kEventClassWindow, kEventWindowClose} }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler); // Install the standard event handler for the window EventTargetRef target = GetWindowEventTarget(mWindow); InstallStandardEventHandler(target); // We also need to install the WindowEvent Handler, we pass along the window with our requests InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef); // Display and select our window ShowWindow(mWindow); SelectWindow(mWindow); // Add our window to the window event listener class WindowEventUtilities::_addRenderWindow(this); } else { // TODO: The Contol is going to report the incorrect location with a // Metalic / Textured window. The default windows work just fine. // First get the HIViewRef / ControlRef mView = (HIViewRef)StringConverter::parseUnsignedLong(opt->second); mWindow = GetControlOwner(mView); // Lets try hiding the HIView //HIViewSetVisible(mView, false); // Get the rect bounds ::Rect ctrlBounds; GetControlBounds(mView, &ctrlBounds); GLint bufferRect[4]; bufferRect[0] = ctrlBounds.left; // left edge bufferRect[1] = ctrlBounds.bottom; // bottom edge bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable (mAGLContext, AGL_BUFFER_RECT); mIsExternal = true; } // Set the drawable, and current context // If you do this last, there is a moment before the rendering window pops-up // This could go once inside each case above, before the window is displayed, // if desired. aglSetDrawable(mAGLContext, GetWindowPort(mWindow)); aglSetCurrentContext(mAGLContext); // Give a copy of our context to the render system mContext = new OSXCarbonContext(mAGLContext, pixelFormat); } mName = name; mWidth = width; mHeight = height; mActive = true; mClosed = false; mCreated = true; mIsFullScreen = fullScreen; }
OSStatus _Growl_ShowUpdatePromptForVersion(CFStringRef updateVersion) { OSStatus err = noErr; if (_checkOSXVersion()) { CFBundleRef bundle = CFBundleGetBundleWithIdentifier(GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER); if (!bundle) NSLog(CFSTR("GrowlInstallationPrompt: could not locate framework bundle (forget about installing Growl); had looked for bundle with identifier '%@'"), GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER); else { IBNibRef nib = NULL; err = CreateNibReferenceWithCFBundle(bundle, CFSTR("GrowlInstallationPrompt-Carbon"), &nib); if (err != noErr) { NSLog(CFSTR("GrowlInstallationPrompt: could not obtain nib: CreateNibReferenceWithCFBundle(%@, %@) returned %li"), bundle, CFSTR("GrowlInstallationPrompt-Carbon"), (long)err); } else { WindowRef window = NULL; err = CreateWindowFromNib(nib, CFSTR("Installation prompt"), &window); DisposeNibReference(nib); if (err != noErr) { NSLog(CFSTR("GrowlInstallationPrompt: could not obtain window from nib: CreateWindowFromNib(%p, %@) returned %li"), nib, CFSTR("Installation prompt"), (long)err); } else { OSStatus fillOutTextErr = _fillOutTextInWindow(window, (updateVersion != nil)); OSStatus fillOutIconErr = _fillOutIconInWindow(window); err = (fillOutTextErr != noErr) ? fillOutTextErr : (fillOutIconErr != noErr) ? fillOutIconErr : noErr; if (err == noErr) { if (updateVersion) { //store the update version on the window. updateVersion = CFRetain(updateVersion); err = SetWindowProperty(window, GROWL_SIGNATURE, GIPC_UPDATE_VERSION, sizeof(updateVersion), &updateVersion); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: SetWindowProperty returned %li"), (long)err); } EventHandlerUPP handlerUPP = NewEventHandlerUPP(_handleCommandInWindow); struct EventTypeSpec types[] = { { .eventClass = kEventClassCommand, .eventKind = kEventCommandProcess }, }; EventHandlerRef handler = NULL; err = InstallWindowEventHandler(window, handlerUPP, GetEventTypeCount(types), types, /*refcon*/ window, &handler); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: InstallWindowEventHandler returned %li"), (long)err); else { HIViewID chasingArrowsID = { GROWL_SIGNATURE, chasingArrowsIDNumber }; HIViewRef chasingArrows = NULL; //stop and hide the chasing arrows, until the user clicks Install. OSStatus chasingArrowsErr = HIViewFindByID(HIViewGetRoot(window), chasingArrowsID, &chasingArrows); if (chasingArrowsErr == noErr) { Boolean truth = false; SetControlData(chasingArrows, kControlEntireControl, kControlChasingArrowsAnimatingTag, sizeof(truth), &truth); HIViewSetVisible(chasingArrows, false); } SelectWindow(window); ShowWindow(window); err = RunAppModalLoopForWindow(window); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: RunAppModalLoopForWindow(%p) returned %li"), window, (long)err); RemoveEventHandler(handler); } DisposeEventHandlerUPP(handlerUPP); } ReleaseWindow(window); } } } }
int _glfwPlatformOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode, _GLFWhints* hints ) { OSStatus error; ProcessSerialNumber psn; unsigned int windowAttributes; // TO DO: Refactor this function! _glfwWin.WindowFunctions = ( _glfwWin.Fullscreen ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions ); // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( !_glfwWin.Fullscreen ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; if( hints->Stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, hints->AuxBuffers); _setAGLAttribute( AGL_RED_SIZE, redbits ); _setAGLAttribute( AGL_GREEN_SIZE, greenbits ); _setAGLAttribute( AGL_BLUE_SIZE, bluebits ); _setAGLAttribute( AGL_ALPHA_SIZE, alphabits ); _setAGLAttribute( AGL_DEPTH_SIZE, depthbits ); _setAGLAttribute( AGL_STENCIL_SIZE, stencilbits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, hints->AccumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, hints->AccumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, hints->AccumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, hints->AccumAlphaBits ); if( hints->Samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, hints->Samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( pixelFormat == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a pixel format\n" ); return GL_FALSE; } // store pixel format's values for _glfwPlatformGetWindowParam's use _getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated ); _getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits ); _getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits ); _getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits ); _getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits ); _getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits ); _getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits ); _getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits ); _getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits ); _getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits ); _getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits ); _getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers ); _getAGLAttribute( AGL_STEREO, _glfwWin.Stereo ); _getAGLAttribute( AGL_SAMPLES_ARB, _glfwWin.Samples ); _glfwWin.RefreshRate = hints->RefreshRate; // create AGL context _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL ); aglDestroyPixelFormat( pixelFormat ); if( _glfwWin.AGLContext == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create an OpenGL context\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if (_glfwLibrary.Unbundled) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't get its PSN\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } /* Keith Bauer 2007-07-12 - I don't believe this is desirable if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } */ } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute \ | kWindowCollapseBoxAttribute \ | kWindowStandardHandlerAttribute ); if( hints->WindowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.MacWindow ) ); if( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler ); error = InstallWindowEventHandler( _glfwWin.MacWindow, _glfwWin.WindowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't install window event handlers\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.MacWindow, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.AGLContext, GetWindowPort( _glfwWin.MacWindow ) ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't draw to the window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.AGLContext ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't make the OpenGL context current\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // show window ShowWindow( _glfwWin.MacWindow ); return GL_TRUE; } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; CGLPixelFormatObj CGLpfObj; long numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; GLint rgbaAccumDepth = 0; int rgbChannelDepth = 0; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( hints->Stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( hints->Samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)hints->Samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( hints->AccumRedBits \ + hints->AccumGreenBits \ + hints->AccumBlueBits \ + hints->AccumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphabits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)depthbits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)stencilbits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)hints->AuxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &CGLpfObj, &numCGLvs ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( CGLpfObj, NULL, &_glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAColorSize, &rgbColorDepth ); if( rgbColorDepth == 24 || rgbColorDepth == 32 ) { rgbChannelDepth = 8; } if( rgbColorDepth == 16 ) { rgbChannelDepth = 5; } // get pixel depth of accumulator - I haven't got the slightest idea // how this number conforms to any other channel depth than 8 bits, // so this might end up giving completely knackered results... (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAAccumSize, &rgbaAccumDepth ); if( rgbaAccumDepth == 32 ) { rgbaAccumDepth = 8; } // store values of pixel format for _glfwPlatformGetWindowParam's use _getCGLAttribute( kCGLPFAAccelerated, _glfwWin.Accelerated ); _getCGLAttribute( rgbChannelDepth, _glfwWin.RedBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.GreenBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.BlueBits ); _getCGLAttribute( kCGLPFAAlphaSize, _glfwWin.AlphaBits ); _getCGLAttribute( kCGLPFADepthSize, _glfwWin.DepthBits ); _getCGLAttribute( kCGLPFAStencilSize, _glfwWin.StencilBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumRedBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumGreenBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumBlueBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumAlphaBits ); _getCGLAttribute( kCGLPFAAuxBuffers, _glfwWin.AuxBuffers ); _getCGLAttribute( kCGLPFAStereo, _glfwWin.Stereo ); _glfwWin.RefreshRate = hints->RefreshRate; // destroy our pixel format (void)CGLDestroyPixelFormat( CGLpfObj ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, /* Check further to the right -> */ height, hints->RefreshRate, NULL, NULL ); if( optimalMode == NULL ) { return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } return GL_TRUE; } }
int main(int argc, char **argv) { // We assume that all the logs we're looking for reside on the current drive gDirUtilp->initAppDirs("SecondLife"); LLError::initForApplication( gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "")); // Rename current log file to ".old" std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log.old"); std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log"); LLFile::rename(log_file.c_str(), old_log_file.c_str()); // Set the log file to updater.log LLError::logToFile(log_file); ///////////////////////////////////////// // // Process command line arguments // gUpdateURL = NULL; gProductName = NULL; gBundleID = NULL; gDmgFile = NULL; gMarkerPath = NULL; parse_args(argc, argv); if ((gUpdateURL == NULL) && (gDmgFile == NULL)) { llinfos << "Usage: mac_updater -url <url> | -dmg <dmg file> [-name <product_name>] [-program <program_name>]" << llendl; exit(1); } else { llinfos << "Update url is: " << gUpdateURL << llendl; if (gProductName) { llinfos << "Product name is: " << gProductName << llendl; } else { gProductName = "Second Life"; } if (gBundleID) { llinfos << "Bundle ID is: " << gBundleID << llendl; } else { gBundleID = "com.secondlife.indra.viewer"; } } llinfos << "Starting " << gProductName << " Updater" << llendl; // Real UI... OSStatus err; IBNibRef nib = NULL; err = CreateNibReference(CFSTR("AutoUpdater"), &nib); char windowTitle[MAX_PATH]; /* Flawfinder: ignore */ snprintf(windowTitle, sizeof(windowTitle), "%s Updater", gProductName); CFStringRef windowTitleRef = NULL; windowTitleRef = CFStringCreateWithCString(NULL, windowTitle, kCFStringEncodingUTF8); if(err == noErr) { err = CreateWindowFromNib(nib, CFSTR("Updater"), &gWindow); } if (err == noErr) { err = SetWindowTitleWithCFString(gWindow, windowTitleRef); } CFRelease(windowTitleRef); if(err == noErr) { // Set up an event handler for the window. EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCustom, kEventCustomProgress }, { kEventClassCustom, kEventCustomDone } }; InstallStandardEventHandler(GetWindowEventTarget(gWindow)); InstallWindowEventHandler( gWindow, NewEventHandlerUPP(dialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, 0, &gEventHandler); } if(err == noErr) { ShowWindow(gWindow); SelectWindow(gWindow); } if(err == noErr) { pthread_create(&updatethread, NULL, &updatethreadproc, NULL); } if(err == noErr) { RunAppModalLoopForWindow(gWindow); } void *threadresult; pthread_join(updatethread, &threadresult); if(!gCancelled && (gFailure != noErr)) { // Something went wrong. Since we always just tell the user to download a new version, we don't really care what. AlertStdCFStringAlertParamRec params; SInt16 retval_mac = 1; DialogRef alert = NULL; OSStatus err; params.version = kStdCFStringAlertVersionOne; params.movable = false; params.helpButton = false; params.defaultText = (CFStringRef)kAlertDefaultOKText; params.cancelText = 0; params.otherText = 0; params.defaultButton = 1; params.cancelButton = 0; params.position = kWindowDefaultPosition; params.flags = 0; err = CreateStandardAlert( kAlertStopAlert, CFSTR("Error"), CFSTR("An error occurred while updating Second Life. Please download the latest version from www.secondlife.com."), ¶ms, &alert); if(err == noErr) { err = RunStandardAlert( alert, NULL, &retval_mac); } if(gMarkerPath != 0) { // Create a install fail marker that can be used by the viewer to // detect install problems. std::ofstream stream(gMarkerPath); if(stream) stream << -1; } exit(-1); } else { exit(0); } if(gWindow != NULL) { DisposeWindow(gWindow); } if(nib != NULL) { DisposeNibReference(nib); } return 0; }