bool CARBON_GUI::init_controls() { int i; for(i=0;i<MAIN_CONTROLS_NUM;i++) { err = GetControlByID(window,&mainControlsID[i],&mainControls[i]); if(err != noErr) { // printf("%d - %d - %d \n",i,mainControlsID[i].id,err); msg->error("Can't get control for button %d (%d)",i,err); } } /* By default start with live output enabled */ jmix->set_lineout(true); SetControlValue(mainControls[SNDOUT_BUT],1); /* install main event handler+ */ err = InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(events), events, this, NULL); if(err != noErr) msg->error("Can't install main eventHandler"); /* install main command handler */ err = InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowCommandHandler), GetEventTypeCount(commands), commands, this, NULL); if(err != noErr) msg->error("Can't install main commandHandler"); }
void QuartzWindow::init_events() { _my_event_handler_upp = NewEventHandlerUPP(::handle_event); OSStatus e = InstallWindowEventHandler(my_window(), _my_event_handler_upp, 0, NULL, this, &_my_event_handler); if (e != noErr) fatal1("could not install event handler: %d\n", e); _my_spy_event_handler_upp = NewEventHandlerUPP(::handle_spy_event); e = InstallWindowEventHandler(my_window(), _my_spy_event_handler_upp, 0, NULL, this, &_my_spy_event_handler); if (e != noErr) fatal1("could not install spy event handler: %d\n", e); }
/* initialize the status window (used to show console messages in the graphic environment */ void CARBON_GUI::setupStatusWindow() { OSStatus err=CreateWindowFromNib(nibRef,CFSTR("StatusWindow"),&statusWindow); if(err!=noErr) msg->error("Can't create status window (%d)!!",err); //SetDrawerParent(statusWindow,window); //SetDrawerPreferredEdge(statusWindow,kWindowEdgeBottom); //SetDrawerOffsets(statusWindow,20,20); /* install an eventHandler to intercept close requests */ err = InstallWindowEventHandler (statusWindow, NewEventHandlerUPP (StatusWindowEventHandler), GetEventTypeCount(statusEvents), statusEvents, this, NULL); if(err != noErr) msg->error("Can't install status window eventHandler"); /* and then install a command handler (to handle "clear" requests) */ err=InstallWindowEventHandler(statusWindow,NewEventHandlerUPP(StatusWindowCommandHandler), GetEventTypeCount(commands),commands,this,NULL); /* obtain an HIViewRef for the status text box ... we have to use it * to setup various properties and to obain a TXNObject needed to manage its content */ const ControlID txtid={ CARBON_GUI_APP_SIGNATURE, STATUS_TEXT_ID }; err= HIViewFindByID(HIViewGetRoot(statusWindow), txtid, &statusTextView); if(err!=noErr) return;// msg->warning("Can't get textView for status window (%d)!!",err); statusText = HITextViewGetTXNObject(statusTextView); if(!statusText) { msg->error("Can't get statusText object from status window!!"); } // TXNControlTag iControlTags[1] = { kTXNAutoScrollBehaviorTag }; // TXNControlData iControlData[1] = { kTXNAutoScrollNever }; //kTXNAutoScrollWhenInsertionVisible }; // err = TXNSetTXNObjectControls(statusText,false,1,iControlTags,iControlData); //TextViewSetObjectControlData //TextViewSetObjectControlData(statusText,kTXNAutoScrollBehaviorTag,kUn kTXNAutoScrollWhenInsertionVisible) /* setup status text font size and color */ // Create type attribute data structure UInt32 fontSize = 10 << 16; // needs to be in Fixed format TXNAttributeData fsData,fcData; fsData.dataValue=fontSize; fcData.dataPtr=(void *)&black; TXNTypeAttributes attributes[] = { //{ kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize, bold }, { kTXNQDFontColorAttribute, kTXNQDFontColorAttributeSize,fcData}, //&lgrey }, { kTXNQDFontSizeAttribute, kTXNFontSizeAttributeSize,fsData } }; err= TXNSetTypeAttributes( statusText, 2, attributes, kTXNStartOffset,kTXNEndOffset ); /* block user input in the statusText box */ TXNControlTag tags[] = { kTXNNoUserIOTag }; TXNControlData vals[] = { kTXNReadOnly }; err=TXNSetTXNObjectControls(statusText,false,1,tags,vals); if(err!=noErr) msg->error("Can't set statusText properties (%d)!!",err); // TXNSetScrollbarState(statusText,kScrollBarsAlwaysActive); //struct TXNBackground bg = { kTXNBackgroundTypeRGB, black }; //TXNSetBackground(statusText,&bg); }
static OSStatus InstallWindowEventHandlers( WindowRef windowRef ) { static const EventTypeSpec inputEventSpec[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } }; static const EventTypeSpec windowEventSpec[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged } }; static const EventTypeSpec viewEventSpec[] = { { kEventClassControl, kEventControlDraw } }; OSStatus err; DrawContextStruct *newContext; // allocate a new draw context newContext = calloc( 1, sizeof( DrawContextStruct ) ); require_action( newContext != NULL, InstallWindowEventHandlers_err, err = paramErr ); HIViewFindByID(HIViewGetRoot(windowRef), myHIViewID, &newContext->viewRef); newContext->windowRef = windowRef; // install a key event handler err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleKeyEvent ), GetEventTypeCount( inputEventSpec ), inputEventSpec, (void *) newContext, NULL ); require_noerr( err, InstallWindowEventHandlersEvent_err ); // install a general window event handler err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleWindowEvent ), GetEventTypeCount( windowEventSpec ), windowEventSpec, (void *) newContext, NULL ); require_noerr( err, InstallWindowEventHandlersEvent_err ); // install handler for the HI view err = HIViewInstallEventHandler( newContext->viewRef, NewEventHandlerUPP( HandleViewEvent ), GetEventTypeCount( viewEventSpec ), viewEventSpec, (void *) newContext, NULL); require_noerr( err, InstallWindowEventHandlersEvent_err ); // also, set the context as the window refcon SetWRefCon( windowRef, (SRefCon) newContext ); return noErr; InstallWindowEventHandlersEvent_err: // make sure that if we're bailing to get rid of the allocated buffer free( newContext ); InstallWindowEventHandlers_err: return err; }
OPL_Dialog::OPL_Dialog(CFStringRef resname): m_window(0), m_status(true) { OSStatus err; static EventTypeSpec dialog_events[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassWindow, kEventWindowClose }, { kEventClassControl, kEventControlHit }, }; // create and show preferences dialog err = CreateWindowFromNib(g_main_nib, resname, &m_window); require_noerr(err, error); static EventHandlerUPP g_eventHandlerUPP = NULL; if (g_eventHandlerUPP == NULL) g_eventHandlerUPP = NewEventHandlerUPP(eventHandler); // install control event handler err = InstallWindowEventHandler(getWindow(), g_eventHandlerUPP, GetEventTypeCount(dialog_events), dialog_events, this, NULL); require_noerr(err, error); error: /* do nothing */; }
// Creates an overlay window which will move with its parent. This technique is typical for doing things like drawing on top of movies, // creating selection rectangles, drawing on top of GL windows, etc. static void CreateOverlayWindow( WindowRef window ) { OSStatus err; Rect windowRect; WindowStorage *windowStorage = (WindowStorage*) GetWRefCon( window ); WindowAttributes overlayAttributes = kWindowNoShadowAttribute | kWindowIgnoreClicksAttribute | kWindowNoActivatesAttribute | kWindowStandardHandlerAttribute; static EventHandlerUPP overlayWindowEventHandlerUPP; const EventTypeSpec windowEvents[] = { { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassWindow, kEventWindowShown }, { kEventClassWindow, kEventWindowClose } }; SetPortWindowPort( window ); GetWindowPortBounds( window, &windowRect ); LocalToGlobalRect( &windowRect ); // Window to be size of window it lies on err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &windowRect, &windowStorage->overlayWindow ); if ( err != noErr ) goto Bail; SetWindowGroup( windowStorage->overlayWindow, GetWindowGroup(window) ); // Put them in the same group so that their window layers are consistent if ( overlayWindowEventHandlerUPP == NULL ) overlayWindowEventHandlerUPP = NewEventHandlerUPP( OverlayWindowEventHandlerProc ); err = InstallWindowEventHandler( windowStorage->overlayWindow, overlayWindowEventHandlerUPP, GetEventTypeCount(windowEvents), windowEvents, windowStorage, NULL ); ShowWindow( windowStorage->overlayWindow ); Bail: return; }
static void DisplaySimpleWindow( void ) { OSErr err; WindowRef window; WindowStorage *windowStorage; WindowGroupRef windowGroup; static EventHandlerUPP simpleWindowEventHandlerUPP; const EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassWindow, kEventWindowClickContentRgn }, { kEventClassWindow, kEventWindowBoundsChanging }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassWindow, kEventWindowClose } }; err = CreateWindowFromNib( g.mainNib, CFSTR("MainWindow"), &window ); if ( (err != noErr) || (window == NULL) ) goto Bail; if ( simpleWindowEventHandlerUPP == NULL ) simpleWindowEventHandlerUPP = NewEventHandlerUPP( SimpleWindowEventHandlerProc ); err = InstallWindowEventHandler( window, simpleWindowEventHandlerUPP, GetEventTypeCount(windowEvents), windowEvents, window, NULL ); windowStorage = (WindowStorage*) NewPtrClear( sizeof(WindowStorage) ); SetWRefCon( window, (long) windowStorage ); err = CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &windowGroup ); if ( err == noErr ) err = SetWindowGroupParent( windowGroup, g.windowGroups[1] ); // Default group if ( err == noErr ) err = SetWindowGroup( window, windowGroup ); ShowWindow( window ); Bail: return; }
OSStatus TabbedWindow::RegisterWindowCarbonEventhandler() { OSStatus status = paramErr; WindowRef window = this->GetWindow(); static const EventTypeSpec windowEvents[] = { { kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventControlHit }, { kEventClassControl, kEventControlHit }, { kEventClassCommand, kEventProcessCommand }, { kEventClassMenu, kEventMenuOpening } }; // install the window event handler if( window != NULL ) { status = InstallWindowEventHandler( window, NewEventHandlerUPP(EventHandlerProc), GetEventTypeCount( windowEvents ), windowEvents, this, &fHandler ); } return status; }
bool AquaGui::createWindow(const char* title, int width, int height) { CFStringRef windowTitle = NULL; OSStatus result; Rect theBounds = {0, 0, 0, 0}; EventTypeSpec eventType; // Specifier for event type EventHandlerUPP handlerUPP; // Pointer to event handler routine _width = width; _height = height; SetRect(&theBounds, 0, 0, width, height); OSStatus status = CreateNewWindow ( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &theBounds, &myWindow); windowTitle = CFStringCreateWithCString(NULL, title, NULL); result = SetWindowTitleWithCFString(myWindow, windowTitle); if(windowTitle != NULL)CFRelease(windowTitle); createMenu(); eventType.eventClass = kEventClassWindow; // Set event class eventType.eventKind = kEventWindowClose; // Set event kind handlerUPP = NewEventHandlerUPP(DoWindowClose); // Point to handler InstallWindowEventHandler (myWindow, handlerUPP, // Install handler 1, &eventType, NULL, NULL); assert(_glue.prepDrawingArea(_width, _height, GetWindowPort(myWindow))); return true; }
PreferencesDialog::PreferencesDialog(WindowRef windowRef, WindowRef mainWindowRef) : preferencesWindow(windowRef), mainWindow(mainWindowRef), m_dataBase(NULL), m_dataBaseCopy(NULL), midiin(NULL) { EventTypeSpec eventSpec[] = {{kEventClassCommand,kEventCommandProcess}, {kEventClassControl, kEventControlHit}, {kEventClassWindow, kEventWindowClose}}; InstallWindowEventHandler(windowRef, NewEventHandlerUPP(WindowEventHandler), sizeof(eventSpec)/sizeof(EventTypeSpec), (EventTypeSpec*)&eventSpec, (void*)this, NULL); // Create RtMidi instance for querying device information try { midiin = new RtMidiIn(); } catch (RtMidiError &error) { error.printMessage(); midiin = NULL; } initDataBase(); }
static void Initialize( void ) { EventLoopTimerRef timerRef; EventTypeSpec eventTypeSpec = { kEventClassWindow, kEventWindowClose }; Rect bounds; WindowRef window; InitCursor(); // Create a window and install an event handler to handle the close button. SetRect( &bounds, 50, 50, 600, 200 ); CreateNewWindow( kDocumentWindowClass, kWindowCloseBoxAttribute + kWindowStandardHandlerAttribute, &bounds, &window ); SetWTitle( window, "\pPlugIn Host -- Close Window To Quit" ); InstallWindowEventHandler( window, NewEventHandlerUPP( MyCloseHandler ), 1, &eventTypeSpec, NULL, NULL ); // Create a timer to handle ball-drawing in the window. InstallEventLoopTimer( GetCurrentEventLoop(), kEventDurationSecond, kEventDurationSecond, NewEventLoopTimerUPP( MyTimerHandler ), window, &timerRef ); ShowWindow( window ); }
void MakeWindow(IBNibRef nibRef) { WindowRef window; OSStatus err; EventHandlerRef ref; EventTypeSpec winEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassMovieExtractState, kEventKQueue } }; err = CreateWindowFromNib(nibRef, CFSTR("Window"), &window); mWindow = window; mWinEventHandler = NewEventHandlerUPP(WindowEventHandler); err = InstallWindowEventHandler(window, mWinEventHandler, GetEventTypeCount( winEvents ), winEvents, 0, &ref); ControlRef control; err = GetControlByID( window, &kPlayBtnID, &control ); mButtonRef = control; err = GetControlByID( window, &kMovNameTxtID, &control ); mMovNameRef = control; ShowWindow(window); }
void Shell::EventLoop(ShellIdleFunction idle_function) { OSStatus error; error = InstallApplicationEventHandler(NewEventHandlerUPP(InputMacOSX::EventHandler), GetEventTypeCount(INPUT_EVENTS), INPUT_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for input events, error: %d.", error); error = InstallWindowEventHandler(window, NewEventHandlerUPP(EventHandler), GetEventTypeCount(WINDOW_EVENTS), WINDOW_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for window events, error: %d.", error); EventLoopTimerRef timer; error = InstallEventLoopIdleTimer(GetMainEventLoop(), // inEventLoop 0, // inFireDelay 5 * kEventDurationMillisecond, // inInterval (200 Hz) NewEventLoopIdleTimerUPP(IdleTimerCallback), // inTimerProc (void*) idle_function, // inTimerData, &timer // outTimer ); if (error != noErr) DisplayError("Unable to install Carbon event loop timer, error: %d.", error); RunApplicationEventLoop(); }
bool8 NPServerDialog (void) { OSStatus err; IBNibRef nibRef; npserver.dialogcancel = true; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { WindowRef tWindowRef; err = CreateWindowFromNib(nibRef, CFSTR("ClientList"), &tWindowRef); if (err == noErr) { EventHandlerRef eref; EventLoopTimerRef tref; EventHandlerUPP eventUPP; EventLoopTimerUPP timerUPP; EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; HIViewRef ctl; HIViewID cid = { 'Chse', 0 }; npserver.dialogprocess = kNPSDialogInit; eventUPP = NewEventHandlerUPP(NPServerDialogEventHandler); err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref); timerUPP = NewEventLoopTimerUPP(NPServerDialogTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) tWindowRef, &tref); HIViewFindByID(HIViewGetRoot(tWindowRef), cid, &ctl); HIViewSetVisible(ctl, false); MoveWindowPosition(tWindowRef, kWindowServer, false); ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowServer); err = RemoveEventLoopTimer(tref); DisposeEventLoopTimerUPP(timerUPP); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eventUPP); CFRelease(tWindowRef); } DisposeNibReference(nibRef); } return (!npserver.dialogcancel); }
bool LLCrashLoggerMac::init(void) { bool ok = LLCrashLogger::init(); if(!ok) return false; if(mCrashBehavior != CRASH_BEHAVIOR_ASK) return true; // Real UI... OSStatus err; err = CreateNibReference(CFSTR("CrashReporter"), &nib); if(err == noErr) { err = CreateWindowFromNib(nib, CFSTR("CrashReporter"), &gWindow); } if(err == noErr) { // Set focus to the edit text area ControlRef textField = NULL; ControlID id; id.signature = 'text'; id.id = 0; // Don't set err if any of this fails, since it's non-critical. if(GetControlByID(gWindow, &id, &textField) == noErr) { SetKeyboardFocus(gWindow, textField, kControlFocusNextPart); } } if(err == noErr) { ShowWindow(gWindow); } if(err == noErr) { // Set up an event handler for the window. EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess } }; InstallWindowEventHandler( gWindow, NewEventHandlerUPP(dialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, 0, &gEventHandler); } return true; }
void dialog_preference_run(void) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}; // open the dialog dialog_open(&dialog_preference_wind,"Preferences"); // set controls dialog_set_text(dialog_preference_wind,kPrefEngineName,0,setup.engine_name); dialog_set_combo(dialog_preference_wind,kPrefMipMapMode,0,setup.mipmap_mode); dialog_set_boolean(dialog_preference_wind,kPrefAutoTexture,0,setup.auto_texture); dialog_set_int(dialog_preference_wind,kPrefDuplicateOffset,0,setup.duplicate_offset); dialog_set_color(dialog_preference_wind,kPrefBackgroundColor,0,&setup.col.background); dialog_set_color(dialog_preference_wind,kPrefLineColor,0,&setup.col.mesh_line); dialog_set_color(dialog_preference_wind,kPrefMeshSelColor,0,&setup.col.mesh_sel); dialog_set_color(dialog_preference_wind,kPrefPolySelColor,0,&setup.col.poly_sel); // show window ShowWindow(dialog_preference_wind); // install event handler event_upp=NewEventHandlerUPP(preference_event_proc); InstallWindowEventHandler(dialog_preference_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // modal window dialog_preference_cancel=FALSE; RunAppModalLoopForWindow(dialog_preference_wind); // dialog to data if (!dialog_preference_cancel) { dialog_get_text(dialog_preference_wind,kPrefEngineName,0,setup.engine_name,256); setup.mipmap_mode=dialog_get_combo(dialog_preference_wind,kPrefMipMapMode,0); setup.auto_texture=dialog_get_boolean(dialog_preference_wind,kPrefAutoTexture,0); setup.duplicate_offset=dialog_get_int(dialog_preference_wind,kPrefDuplicateOffset,0); dialog_get_color(dialog_preference_wind,kPrefBackgroundColor,0,&setup.col.background); dialog_get_color(dialog_preference_wind,kPrefLineColor,0,&setup.col.mesh_line); dialog_get_color(dialog_preference_wind,kPrefMeshSelColor,0,&setup.col.mesh_sel); dialog_get_color(dialog_preference_wind,kPrefPolySelColor,0,&setup.col.poly_sel); setup_xml_write(); } // close window DisposeWindow(dialog_preference_wind); }
void MacOSXLoop::registerWindow( GenericWindow &rGenWin, WindowRef win ) { // Create the event handler EventTypeSpec evList[] = { { kEventClassWindow, kEventWindowUpdate }, { kEventClassMouse, kEventMouseMoved } }; EventHandlerUPP handler = NewEventHandlerUPP( WinEventHandler ); InstallWindowEventHandler( win, handler, GetEventTypeCount( evList ), evList, &rGenWin, NULL ); }
void* CContextOSX::CreateMainWindow(SSize /*Size*/, tint32 /*iWindowsOnly_MenuResourceID = -1*/, tint32 /*iWindowsOnly_IconResourceID = -1*/) { gpMainContext = this; IBNibRef sNibRef; OSStatus err; static const EventTypeSpec kAppEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kCoreEventClass, kAEOpenDocuments } }; // 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"), &sNibRef ); // 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( sNibRef, CFSTR("MenuBar") ); // require_noerr( err, CantSetMenuBar ); // Install our handler for common commands on the application target // InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), // GetEventTypeCount( kAppEvents ), kAppEvents, // 0, NULL ); WindowRef gpWindow; err = CreateWindowFromNib( sNibRef, CFSTR("MainWindow"), &gpWindow ); // Position new windows in a staggered arrangement on the main screen RepositionWindow( gpWindow, NULL, kWindowCascadeOnMainScreen ); // The window was created hidden, so show it // ShowWindow( gpWindow ); ::InvalMenuBar(); ::DrawMenuBar(); // Install application event handler InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), GetEventTypeCount( kAppEvents ), kAppEvents, this, NULL ); InstallWindowEventHandler(gpWindow, GetWindowEventHandlerUPP(), GetEventTypeCount(kWindowEvents), kWindowEvents, gpWindow, NULL); return (void*)gpWindow; }
/* * initialize controls for the vumeter window */ void CARBON_GUI::setupVumeters() { /* instance vumeters window that will be used later if user request it */ OSStatus err=CreateWindowFromNib(nibRef, CFSTR("VumeterWindow"),&vumeterWindow); // SetDrawerParent(vumeterWindow,window); // SetDrawerPreferredEdge(vumeterWindow,kWindowEdgeTop); // SetDrawerOffsets(vumeterWindow,20,20); if(err!=noErr) msg->error("Can't create vumeter window"); /* install vmeter event handler+ */ err = InstallWindowEventHandler (vumeterWindow, NewEventHandlerUPP (VumeterWindowEventHandler), GetEventTypeCount(vumeterEvents), vumeterEvents, this, NULL); if(err != noErr) msg->error("Can't install vumeter eventHandler"); }
//------------------------------------------------------------------------------------- // Prompt //------------------------------------------------------------------------------------- // Put up a modal panel and request some text. // CFStringRef Prompt( CFStringRef inPrompt, CFStringRef inDefaultText ) { IBNibRef nibRef; OSStatus err; WindowRef window; EventTypeSpec kEvents[] = { { kEventClassCommand, kEventCommandProcess } }; PanelInfo info; HIViewRef view; info.window = window; info.string = NULL; err = CreateNibReference( CFSTR( "main" ), &nibRef ); require_noerr( err, CantGetNibRef ); err = CreateWindowFromNib( nibRef, CFSTR( "Prompt" ), &window ); require_noerr( err, CantCreateWindow ); DisposeNibReference( nibRef ); if ( inPrompt ) { HIViewFindByID( HIViewGetRoot( window ), kPromptLabelID, &view ); SetControlData( view, 0, kControlStaticTextCFStringTag, sizeof( CFStringRef ), &inPrompt ); } HIViewFindByID( HIViewGetRoot( window ), kTextFieldID, &view ); if ( inDefaultText ) SetControlData( view, 0, kControlEditTextCFStringTag, sizeof( CFStringRef ), &inDefaultText ); SetKeyboardFocus( window, view, kControlFocusNextPart ); InstallWindowEventHandler( window, InputPanelHandler, GetEventTypeCount( kEvents ), kEvents, &info, NULL ); ShowWindow( window ); info.window = window; RunAppModalLoopForWindow( window ); DisposeWindow( window ); CantCreateWindow: CantGetNibRef: return info.string; }
bool dialog_play_blend_animation_run(void) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}; // open the dialog dialog_open(&dialog_play_blend_animation_wind,"BlendAnimation"); // set controls dialog_set_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate1,0,play_animate_blend_idx[0],FALSE); dialog_set_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate2,0,play_animate_blend_idx[1],TRUE); dialog_set_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate3,0,play_animate_blend_idx[2],TRUE); dialog_set_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate4,0,play_animate_blend_idx[3],TRUE); // show window ShowWindow(dialog_play_blend_animation_wind); // install event handler event_upp=NewEventHandlerUPP(play_blend_animation_event_proc); InstallWindowEventHandler(dialog_play_blend_animation_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // modal window dialog_play_blend_animation_cancel=FALSE; RunAppModalLoopForWindow(dialog_play_blend_animation_wind); // dialog to data if (!dialog_play_blend_animation_cancel) { // get play animations play_animate_blend_idx[0]=dialog_get_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate1,0,FALSE); play_animate_blend_idx[1]=dialog_get_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate2,0,TRUE); play_animate_blend_idx[2]=dialog_get_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate3,0,TRUE); play_animate_blend_idx[3]=dialog_get_animate_combo(dialog_play_blend_animation_wind,kBlendAnimate4,0,TRUE); } // close window DisposeWindow(dialog_play_blend_animation_wind); return(!dialog_play_blend_animation_cancel); }
static void makeNibWindow (IBNibRef nibRef) { OSStatus err; short i,j,l,k; EventHandlerRef ref; ControlRef targetCon[11], cref[3]; err = CreateWindowFromNib(nibRef, CFSTR("SoundDialog"), &soundWin); if (err == noErr) { initSoundWindow(); SetInitialTabState(soundWin, lastPaneSelected, kMaxNumTabs); EventTypeSpec tabControlEvents[] ={ { kEventClassControl, kEventControlHit }}; InstallControlEventHandler( getControlRefByID(kTabMasterSig,kTabMasterID,soundWin), PrefsTabEventHandlerProc , GetEventTypeCount(tabControlEvents), tabControlEvents, soundWin, NULL ); EventTypeSpec sliderControlEvents[] ={ { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlValueFieldChanged } }; for (i=0;i<5;i++) { targetCon[i] = getControlRefByID('vMix',i,soundWin); } for (j=0;j<6;j++) { targetCon[j+5] = getControlRefByID('vMix',10+j,soundWin); } for (l=0;l<11;l++) { InstallControlEventHandler( targetCon[l], sliderEventHandlerProc , GetEventTypeCount(sliderControlEvents), sliderControlEvents, (void *)targetCon[l], NULL ); } EventTypeSpec list[]={ { kEventClassCommand, kEventCommandProcess },}; InstallWindowEventHandler (soundWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)soundWin, &ref); EventTypeSpec ctrllist[]={ { kEventClassControl, kEventControlClick } }; for (k=0;k<3;k++) { cref[k] = getControlRefByID('BMP ', k, soundWin); } InstallControlEventHandler(cref[0], NewEventHandlerUPP(s26proc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[0], NULL); InstallControlEventHandler(cref[1], NewEventHandlerUPP(s86proc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[1], NULL); InstallControlEventHandler(cref[2], NewEventHandlerUPP(spbproc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[2], NULL); ShowSheetWindow(soundWin, hWndMain); err=RunAppModalLoopForWindow(soundWin); } return; }
bool dialog_mesh_info_run(model_mesh_type *mesh) { EventHandlerUPP event_upp; EventTypeSpec event_list[]={{kEventClassCommand,kEventProcessCommand}}; // open the dialog dialog_open(&dialog_mesh_info_wind,"MeshInfo"); // setup the controls dialog_set_text(dialog_mesh_info_wind,kMeshInfoName,0,mesh->name); dialog_set_boolean(dialog_mesh_info_wind,kMeshNoLighting,0,mesh->no_lighting); dialog_set_boolean(dialog_mesh_info_wind,kMeshAdditive,0,mesh->blend_add); dialog_set_boolean(dialog_mesh_info_wind,kMeshTintable,0,mesh->tintable); // show window ShowWindow(dialog_mesh_info_wind); // install event handler event_upp=NewEventHandlerUPP(mesh_info_event_proc); InstallWindowEventHandler(dialog_mesh_info_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL); // modal window dialog_cancel=FALSE; dialog_set_focus(dialog_mesh_info_wind,'name',0); RunAppModalLoopForWindow(dialog_mesh_info_wind); if (!dialog_cancel) { dialog_get_text(dialog_mesh_info_wind,kMeshInfoName,0,mesh->name,name_str_len); mesh->no_lighting=dialog_get_boolean(dialog_mesh_info_wind,kMeshNoLighting,0); mesh->blend_add=dialog_get_boolean(dialog_mesh_info_wind,kMeshAdditive,0); mesh->tintable=dialog_get_boolean(dialog_mesh_info_wind,kMeshTintable,0); } // close window DisposeWindow(dialog_mesh_info_wind); return(!dialog_cancel); }
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); }
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); }
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* CContextOSX::CreateExtraWindow(void* pszResName, SSize /*Size*/, tbool) { IBNibRef sNibRef; 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"), &sNibRef ); // 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( sNibRef, CFSTR("MenuBar") ); // require_noerr( err, CantSetMenuBar ); // Install our handler for common commands on the application target // InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), // GetEventTypeCount( kAppEvents ), kAppEvents, // 0, NULL ); WindowRef pWindow; err = CreateWindowFromNib(sNibRef, (CFStringRef)pszResName, &pWindow ); // Position new windows in a staggered arrangement on the main screen // RepositionWindow( pWindow, NULL, kWindowCascadeOnMainScreen ); // The window was created hidden, so show it // ShowWindow( pWindow ); // HideWindow(pWindow); ::InvalMenuBar(); ::DrawMenuBar(); InstallWindowEventHandler(pWindow, GetWindowEventHandlerUPP(), GetEventTypeCount(kWindowEvents), kWindowEvents, pWindow, NULL); return (void*)pWindow; }