Ejemplo n.º 1
0
// --------------------------------------------------------------------------------------
static void initialize(void)
{
	OSStatus status;
	IBNibRef nib;
	OSErr error;
	
	RegisterAppearanceClient();

	status = CreateNibReference(CFSTR("ExamplePrefs"), &nib);
	if (status != noErr)
		ExitToShell();
	
	status = SetMenuBarFromNib(nib, CFSTR("MenuBar"));
	if (status != noErr)
		ExitToShell();
	
	DisposeNibReference(nib);
	
	DrawMenuBar();
	
		// do non time sensitive initialization after we get the application event loop going
	gOpenAppAEHandler = NewAEEventHandlerUPP(openApplicationAEHandler);
	error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOpenAppAEHandler, 0, 
									false);
	if (error != noErr)
		ExitToShell();
	
		/* If we supported them, we would install open documents and print documents 
		   handlers here and we would do most of the same initialization stuff that we 
		   do in the open application handler */
}
Ejemplo n.º 2
0
/* destructor for the CARBON_GUI class 
 * here we destroy all other used objects and 
 */
CARBON_GUI::~CARBON_GUI() 
{ 
    /* Destroy used objects */
	delete streamHandler;
	delete playlistManager;
	delete aboutWindow;
	pthread_mutex_destroy(&_statusLock);
	if(msgList) {
		while(msgList->len()) {
			Entry *e = msgList->begin();
			void *val = e->get_value();
			if(val) 
				free(val);
			delete e;
		}
		delete msgList;
	}
	/* delete all input channels */
	for (int i=0;i<MAX_CHANNELS;i++) 
		if(channel[i]) delete channel[i];
	DisposeWindow(statusWindow);
	DisposeWindow(vumeterWindow);
	DisposeMenu(mainMenu);
	// We don't need the nib reference anymore.
	DisposeNibReference(nibRef);
}
Ejemplo n.º 3
0
TabbedWindow::TabbedWindow( void )
{
    OSStatus status;
    IBNibRef nibRef;
    fWindowRef = NULL;
    
    static const ControlID tabControlID = 
        { kMasterTabControlSignature, kMasterTabControlID };

    // Create a Nib reference passing the name of the nib file (without the .nib
    // extension) CreateNibReference only searches into the application bundle.
    status = CreateNibReference( CFSTR("main"), &nibRef );
    require_noerr( status, TabbedWindow_err );
	
    // Then create a window & set menubar based on Nib.
    status = CreateWindowFromNib( nibRef, CFSTR("MainWindow"), &fWindowRef );
    require_noerr( status, TabbedWindow_err );
    status = SetMenuBarFromNib( nibRef, CFSTR( "MenuBar" ) );
    require_noerr( status, TabbedWindow_err );

    // finsihed with the nib reference
    DisposeNibReference(nibRef);
    
    // what events will this window handle?
    status = this->RegisterWindowCarbonEventhandler();
    require_noerr( status, TabbedWindow_err );
    
    // start with current tab pane set to NULL.
    fCurrentTabPane = NULL;
    
    // start with all panes disabled
    this->DisableAllPanes();
    
    // Get a reference to the tab control in the window
    status = GetControlByID( fWindowRef, &tabControlID, &fTabControlRef );
    //check_noerr( status );
    
    // put event handlers on it
    status = InstallStandardEventHandler( GetControlEventTarget( fTabControlRef ) );
    check_noerr( status );
    
    // Switch to the tab content indicated by current value of the tab control
    if( status == noErr )
        status = this->SwitchTabPane( fTabControlRef );
    
    // show the new window
    ShowWindow( fWindowRef );
	
TabbedWindow_err:

    #if DEBUG_ERROR_LOGS
    if( status != noErr )
    {
        SysBeep(10);
        std::cout << "Error in TabbedWindow constructor:" << status << std::endl;
    }
    #endif

    return;
}
Ejemplo n.º 4
0
  for_each(BumpTopCommand* option, ordered_context_menu_items) {
    err = InsertMenuItemTextWithCFString(carbon_context_menu,
                                         CFStringFromQString(option->name()),
                                         menu_size,   // MenuItemIndex inAfterItem
                                         option->isSeparator() ? kMenuItemAttrSeparator : 0,  // MenuItemAttributes inAttributes
                                         0);  // MenuCommand inCommandID
    if (option->has_subcommands()) {
      QStringList subcommand_names = option->subcommand_names(actors);
      err = CreateNibReference(CFSTR("ContextMenu"), &nib_ref);
      MenuRef carbon_context_sub_menu;
      err = CreateMenuFromNib(nib_ref, CFSTR("ItemContextMenu"), &carbon_context_sub_menu);
      err = ChangeMenuAttributes(carbon_context_sub_menu, kMenuAttrCondenseSeparators, NULL);
      DisposeNibReference(nib_ref);


      int sub_menu_size = 0;
      for_each(QString subcommand, subcommand_names) {
        err = InsertMenuItemTextWithCFString(carbon_context_sub_menu,
                                             CFStringFromQString(subcommand),
                                             sub_menu_size,   // MenuItemIndex inAfterItem
                                             subcommand == "" ? kMenuItemAttrSeparator : 0,  // MenuItemAttributes inAttributes
                                             0); // MenuCommand inCommandID

        CGImageRef icon = option->iconForSubcommand(actors, sub_menu_size);
        if (icon) {
          err = SetMenuItemIconHandle (carbon_context_sub_menu,
                                       sub_menu_size+1,
                                       kMenuCGImageRefType,
                                       (Handle) icon);
          CGImageRelease(icon);
        }
        sub_menu_size++;

      }
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
{
    IBNibRef 		nibRef;
    WindowRef 		window;
    HIViewRef		textView;
	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 );
    
    // Then create a window. "MainDocumentWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    err = CreateWindowFromNib(nibRef, CFSTR("MainDocumentWindow"), &window);
    require_noerr( err, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);

	// Make the window's content area transparent
	err = MakeWindowTransparent(window);
    require_noerr( err, CantMakeWindowTransparent );

	// Get a reference to the TextView in the main window
	err = HIViewFindByID(HIViewGetRoot(window), gTextViewID, &textView);
	require_noerr( err, CantGetTextView );

	// Install our default options in the TextView
	err = MySetTextViewOptions(textView);
	require_noerr( err, CantSetTextViewOptions );

	// Make the TextView partially transparent
	err = TextViewSetAlpha(textView, 0.25);
	require_noerr( err, CantSetTextViewOptions );
	
    // The window was created hidden so show it.
    ShowWindow( window );

    // Call the event loop
    RunApplicationEventLoop();

CantSetTextViewOptions:
CantGetTextView:
CantMakeWindowTransparent:
CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
	return err;
}
Ejemplo n.º 7
0
/*****************************************************
*
* main (argc, argv) 
*
* Purpose:  main program entry point
*
* Inputs:   argc     - the number of elements in the argv array
*			argv     - an array of pointers to the parameters to this application
*
* Returns:  int      - error code (0 == no error) 
*/
int main(int argc, char* argv[])
{
	OSStatus status;
	
	// Can we run this particular demo application?
	long response;
	status = Gestalt(gestaltSystemVersion, &response);
	Boolean ok = ((status == noErr) && (response >= 0x00001040));
	if (!ok)
	{
		DialogRef theAlert;
		CreateStandardAlert(kAlertStopAlert, CFSTR("Mac OS X 10.4 (minimum) is required for this application"), NULL, NULL, &theAlert);
		RunStandardAlert(theAlert, NULL, NULL);
		ExitToShell();
	}
	
	// Create a Nib reference passing the name of the nib file (without the .nib extension)
	// CreateNibReference only searches into the application bundle.
	IBNibRef nibRef;
	status = CreateNibReference(CFSTR("main"), &nibRef);
	require_noerr(status, CreateNibReference);
	
	// 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.
	status = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
	require_noerr(status, SetMenuBarFromNib);
	
	// We no longer need this Nib reference
	DisposeNibReference(nibRef);
	
	// Enabling Preferences menu item
	EnableMenuCommand(NULL, kHICommandPreferences);
	
	// Let's react to User's commands.
	Install_AppleEventHandlers();
	
	EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess};
	status = InstallEventHandler(GetApplicationEventTarget(), Handle_CommandProcess, 1, &eventTypeCP, NULL, NULL);
	require_noerr(status, InstallEventHandler);
	
	EventTypeSpec eventTypeCUS = {kEventClassCommand, kEventCommandUpdateStatus};
	status = InstallEventHandler(GetApplicationEventTarget(), Handle_CommandUpdateStatus, 1, &eventTypeCUS, NULL, NULL);
	require_noerr(status, InstallEventHandler);
	
	// Call the event loop
	RunApplicationEventLoop();
	
InstallEventHandler:
SetMenuBarFromNib:
CreateNibReference:

	return status;
}   // main
Ejemplo n.º 8
0
void initSoundOpt( void ) {
    OSStatus	err;

    err = CreateNibReference(CFSTR("np2"), &nibRef);
    if (err ==noErr ) {
        makeNibWindow (nibRef);
        DisposeNibReference ( nibRef);
    }
    else {
         return;
    }
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
int main(int argc, char* argv[])
{
	IBNibRef 		nibRef;
	OSStatus		err;
	
	InitCursor();

	// check the correct BASS was loaded
	if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS.DLL was loaded (2.4 is required)");
		return 0;
	}

	// check the correct BASS_FX was loaded
	if (HIWORD(BASS_FX_GetVersion())!=BASSVERSION) {
		Error("An incorrect version of BASS_FX.DLL was loaded (2.4 is required)");
		return 0;
	}

	// initialize default output device
	if(!BASS_Init(-1,44100,0,NULL,NULL)) {
		Error("Can't initialize device");
		return 0;
	}

	// Create Window and Stuff
	err = CreateNibReference(CFSTR("reverse"), &nibRef);
	if (err) return err;
	err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &win);
	if (err) return err;
	DisposeNibReference(nibRef);

	SetupControlHandler(10,kEventControlHit,OpenEventHandler);
	SetControlAction(GetControl(11),NewControlActionUPP(VolEventHandler));
	SetControlAction(GetControl(13),NewControlActionUPP(TempoEventHandler));
	SetControlAction(GetControl(15),NewControlActionUPP(PosEventHandler));
	SetupControlHandler(16,kEventControlHit,DirEventHandler);

	EventLoopTimerRef timer;
	InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/2,TimerProc,0,&timer);

	// The window was created hidden so show it.
	ShowWindow(win);
    
	// Call the event loop
	RunApplicationEventLoop();
   
	// Close output
	BASS_Free();

	return 0;
}
Ejemplo n.º 11
0
//-------------------------------------------------------------------------------------
//	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;
}
Ejemplo n.º 12
0
int main( void )
{
	OSErr	err;
	
	err	= InitializeApplication();
	if ( err != noErr )	goto Bail;
	
	SendCommandProcessEvent( kHICommandNew );							//	Send a kHICommandNew to ourselves to create a default new window
	
	RunApplicationEventLoop();

Bail:	
	if ( g.mainNib != NULL )	DisposeNibReference( g.mainNib );
	if ( g.mainBundle != NULL )	CFRelease( g.mainBundle );
	return( noErr );
}
Ejemplo n.º 13
0
// Create a new demo window
OSStatus
NewWindow()
{
    IBNibRef nibRef;
    WindowRef window;
	EventTypeSpec commandEventType = {kEventClassWindow, kEventWindowFocusAcquired};
    OSStatus status = noErr;

    // Create a Nib reference passing the name of the nib file (without the .nib extension)
    // CreateNibReference only searches into the application bundle.
	status = CreateNibReference(CFSTR("main"), &nibRef);
    require_noerr( status, CantGetNibRef );
    
    // Then create a window. "MainWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    status = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
    require_noerr( status, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);
	
	// Let's customize the HITextView in that window
	status = SetUpTheTextView( window );	
	check_noerr( status );

    // The window was created hidden so show it.
    ShowWindow( window );

	// by default, focus the HITextView at start
	status = TextViewFocusInWindow( window );
    require_noerr( status, CantFocusTextView );

	// set up the control state from the state of the text view
	status = UpdateControlsFromTextViewWindow( window );
    require_noerr( status, CantSetControlState );

	// Install a handler to update the UI when this window comes to the front
	status = InstallEventHandler(GetWindowEventTarget(window), NewEventHandlerUPP(WindowFocusAcquired), 1, &commandEventType, NULL, NULL);
    require_noerr( status, CantInstallWindowEventHandler );
	
CantFocusTextView:
CantSetControlState:
CantInstallWindowEventHandler:
CantCreateWindow:
CantGetNibRef:
	return status;
}
Ejemplo n.º 14
0
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; 
}
Ejemplo n.º 15
0
//---------------------------------------------------------------------
// Creates one of our simple document windows and returns a ref to it.
//
WindowRef MyCreateNewDocumentWindow(void)
{
    IBNibRef nib;
    WindowRef window = NULL;
	OSStatus status;

    // Create one of our special main document windows
    status = CreateNibReference(CFSTR("main"), &nib);
	require_noerr( status, CantGetNIBRef );
    status = CreateWindowFromNib(nib, CFSTR("MainDocumentWindow"), &window);
	require_noerr( status, CantCreateWindow );

	// Set its default options
	status = MySetTextViewOptions(GetTextViewFromWindow(window));
	check_noerr( status );

	// Make the window transparent
	status = MakeWindowTransparent(window);
	check_noerr( status );

	// Make the TextView partially transparent
	status = TextViewSetAlpha(GetTextViewFromWindow(window), 0.25);
	check_noerr( status );

	// Initialize the window title and proxy icon
	status = SetWindowTitleWithCFString(window, CFSTR("Untitled"));
	check_noerr( status );
	status = SetWindowProxyCreatorAndType(window, kUnknownType, kUnknownType, kOnSystemDisk);
	check_noerr( status );

	// Show the window
    ShowWindow(window);

	// Cleanup
CantGetViewRef:
CantCreateWindow:
    DisposeNibReference(nib);
CantGetNIBRef:
	return window;
}
// 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;
}
Ejemplo n.º 17
0
int main(int argc, char* argv[])
{
    IBNibRef 		nibRef;
    WindowRef 		window;
    
    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 );
    
    // 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 );
	
	// Run the sample code
	err = RunRoundTripFlatteningSample( window );
	check_noerr( err );
    
    // Call the event loop
    RunApplicationEventLoop();

CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
	return err;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
//---------------------------------------------------------------------------------------------
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;
}
Ejemplo n.º 20
0
Archivo: main.c Proyecto: eross/misc
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;
}
Ejemplo n.º 21
0
bool LLCrashLoggerMac::mainLoop()
{
	OSStatus err = noErr;
				
	if(err == noErr && mCrashBehavior == CRASH_BEHAVIOR_ASK)
	{
		RunAppModalLoopForWindow(gWindow);
	}
	else if (mCrashBehavior == CRASH_BEHAVIOR_ALWAYS_SEND)
	{
		gSendReport = true;
	}
	
	if(gRememberChoice)
	{
		if(gSendReport) saveCrashBehaviorSetting(CRASH_BEHAVIOR_ALWAYS_SEND);
		else saveCrashBehaviorSetting(CRASH_BEHAVIOR_NEVER_SEND);
	}
	
	if(gSendReport)
	{
		setUserText(gUserNotes);
		sendCrashLogs();
	}		
	
	if(gWindow != NULL)
	{
		DisposeWindow(gWindow);
	}
	
	if(nib != NULL)
	{
		DisposeNibReference(nib);
	}
	
	return true;
}
Ejemplo n.º 22
0
/*****************************************************
*
* Routine:	main (argc, argv)*
* Purpose:	main program entry point
*
* Inputs:	argc	 - the number of elements in the argv array
*			argv	 - an array of pointers to the parameters to this application
*
* Returns:	int		 - error code (0 == no error)
*/
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);
	
	// A bit of an explanation...
	WindowRef window;
	CreateWindowFromNib(nibRef, CFSTR("Explain"), &window);
	ShowWindow(window);
	
	// We don't need the nib reference anymore.
	DisposeNibReference(nibRef);
	
	// Let's react to User's commands.
	EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess};
	InstallEventHandler(GetApplicationEventTarget(), CommandProcess, 1, &eventTypeCP, NULL, NULL);
	
	// And start our dialogs
	StartTheDialogs();
	
	// Call the event loop
	RunApplicationEventLoop();
	
CantSetMenuBar:
CantGetNibRef:
		return err;
}
Ejemplo n.º 23
0
int
main(int argc, char* argv[])
{
    #pragma unused(argc)
    #pragma unused(argv)
    
    IBNibRef  nibRef;
    OSStatus  err;    
    
    err = CreateNibReference(CFSTR("main"), &nibRef);
    assert(err == noErr);
    
    err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
    assert(err == noErr);
    
    DisposeNibReference(nibRef);
    
    err = MyChooseFolder();
    if (err == noErr) {
        RunApplicationEventLoop();
    }
    
    return err;
}
Ejemplo n.º 24
0
void init_apple_menu(const char* product)
{
	// Load up a proper menu bar.
	{
		OSStatus err;
		IBNibRef nib = NULL;
		// NOTE: DO NOT translate or brand this string.  It's an internal name in the .nib file, and MUST match exactly.
		err = CreateNibReference(CFSTR("SecondLife"), &nib);
		
		if(err == noErr)
		{
			// NOTE: DO NOT translate or brand this string.  It's an internal name in the .nib file, and MUST match exactly.
			SetMenuBarFromNib(nib, CFSTR("MenuBar"));
		}

		if(nib != NULL)
		{
			DisposeNibReference(nib);
		}
	}
	
	// Install a handler for 'gurl' AppleEvents.  This is how secondlife:// URLs get passed to the viewer.
	
	if(AEInstallEventHandler('GURL', 'GURL', NewAEEventHandlerUPP(AEGURLHandler),0, false) != noErr)
	{
		// Couldn't install AppleEvent handler.  This error shouldn't be fatal.
		llinfos << "Couldn't install 'GURL' AppleEvent handler.  Continuing..." << llendl;
	}

	// Install a handler for 'quit' AppleEvents.  This makes quitting the application from the dock work.
	if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(AEQuitHandler),0, false) != noErr)
	{
		// Couldn't install AppleEvent handler.  This error shouldn't be fatal.
		llinfos << "Couldn't install Quit AppleEvent handler.  Continuing..." << llendl;
	}
}
//----------------------------------------------------------------------------//
void MacCEGuiRendererSelector::loadDialogWindow()
{
    // get our framework bundle from the app
    CFBundleRef helperFwk =
        CFBundleGetBundleWithIdentifier(
            CFSTR("net.sourceforge.crayzedsgui.CEGUISampleHelper"));

    if (helperFwk)
    {
        IBNibRef nib;
        if (!CreateNibReferenceWithCFBundle(helperFwk,
                                            CFSTR("RendererSelector"), &nib))
        {
            CreateWindowFromNib(nib, CFSTR("RendererSelector"), &d_dialog);
            DisposeNibReference (nib);

            // find popup button in the window
            const HIViewID rendererPopupID = {'PBTN', 0};
            HIViewFindByID(HIViewGetRoot(d_dialog),
                           rendererPopupID,
                           &d_rendererPopup);
        }
    }    
}
Ejemplo n.º 26
0
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;
}
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);
				}
			}
		}
	}
Ejemplo n.º 28
0
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."),
				&params,
				&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;
}
Ejemplo n.º 29
0
void MusicBoxDialog(void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	if (!cartOpen)
		return;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		CFURLRef	iconURL;
		FSRef		iconFSRef;
		IconRef		actIcon;
		WindowRef	tWindowRef;

		actIcon = nil;

		if (musicboxmode == kMBXSoundEmulation)
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil);
		else
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil);

		if (iconURL)
		{
			if (CFURLGetFSRef(iconURL, &iconFSRef))
				err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon);

			CFRelease(iconURL);
		}

		err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		mboxRef, paneRef;
			EventHandlerUPP		mboxUPP, paneUPP;
			EventLoopTimerRef	timeRef;
			EventLoopTimerUPP	timeUPP;
			EventTypeSpec		mboxEvents[] = { { kEventClassCommand, kEventCommandProcess      },
												 { kEventClassCommand, kEventCommandUpdateStatus } },
								paneEvents[] = { { kEventClassControl, kEventControlDraw         } };
			CFStringRef			sref;
			CGDataProviderRef	prov;
			CGImageRef			ipng;
			CFURLRef			iurl;
			HIViewRef			ctl, root, paneView, imageView, contentView;
			HIViewID			cid;
			HIRect				bounds;
			Rect				windowRect, barRect;
			char				drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];

			mboxPause = false;
			mbxFinished = false;
			showIndicator = false;
			so.stereo_switch = ~0;

			for (int i = 0; i < MAC_MAX_PLAYERS; i++)
				controlPad[i] = 0;

			switch (drawingMethod)
			{
				case kDrawingOpenGL:
					Settings.OpenGLEnable = true;
					break;

				case kDrawingDirect:
				case kDrawingBlitGL:
					Settings.OpenGLEnable = false;
			}

			// 107's enhanced SPC player

			root = HIViewGetRoot(tWindowRef);
			cid.id = 0;

			if (musicboxmode == kMBXSoundEmulation)
			{
				cid.signature = 'HEAD';
				HIViewFindByID(root, cid, &ctl);
				EnableControl(ctl);

				StoredAPU          = new SAPU;
				StoredAPURegisters = new SAPURegisters;
				StoredSoundData    = new SSoundData;
				StoredIAPURAM      = new uint8 [0x10000];

				SPCPlayFreeze();
			}
			else
				MusicBoxForceFreeze();

			cid.signature = 'Kart';
			HIViewFindByID(root, cid, &ctl);
			SetStaticTextTrunc(ctl, truncEnd, false);
			_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
			sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING);
			if (sref)
			{
				SetStaticTextCFString(ctl, sref, false);
				CFRelease(sref);
			}

			ipng = nil;

			iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil);
			if (iurl)
			{
				prov = CGDataProviderCreateWithURL(iurl);
				if (prov)
				{
					ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault);
					CGDataProviderRelease(prov);
				}

				CFRelease(iurl);
			}

			imageView = nil;

			if (ipng)
			{
				HIViewFindByID(root, kHIViewWindowContentID, &contentView);

				err = HIImageViewCreate(ipng, &imageView);
				if (err == noErr)
				{
					bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng));
					HIViewSetFrame(imageView, &bounds);
					HIImageViewSetOpaque(imageView, false);
					HIViewSetVisible(imageView, true);
					HIViewAddSubview(contentView, imageView);
					cid.signature = 'iMaG';
					SetControlID(imageView, &cid);
				}

				CGImageRelease(ipng);
			}

			cid.signature = 'Pane';
			HIViewFindByID(root, cid, &paneView);
			HIViewGetBounds(paneView, &bounds);
			mbxViewWidth  = bounds.size.width;
			mbxViewHeight = bounds.size.height;
			mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0;
			mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0;

			if (imageView)
			{
				HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView);
				HIViewAddSubview(imageView, paneView);
			}

			cid.signature = 'Tr_i';
			HIViewFindByID(root, cid, &ctl);
			HIViewGetFrame(ctl, &bounds);
			GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect);
			mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top);

			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			mbxOpenedHeight = windowRect.bottom - windowRect.top;

			windowRect.bottom = windowRect.top + mbxClosedHeight;
			SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);

			paneUPP = NewEventHandlerUPP(IndicatorEventHandler);
			err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef);

			mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler);
			err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef);

			timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler);
			err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef);

			MusicBoxInitIndicator();

			stopNow = false;
			MacStartSound();
			pthread_create(&mbxThread, nil, SoundTask, nil);

			MoveWindowPosition(tWindowRef, kWindowMusicBox, true);
			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			if (windowRect.bottom - windowRect.top > mbxClosedHeight)
			{
				showIndicator = true;
				SetControl32BitValue(ctl, 1);	// Tr_i
			}

			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);

			SaveWindowPosition(tWindowRef, kWindowMusicBox);

			stopNow = true;
			pthread_join(mbxThread, nil);
			MacStopSound();

			err = RemoveEventLoopTimer(timeRef);
			DisposeEventLoopTimerUPP(timeUPP);

			err = RemoveEventHandler(mboxRef);
			DisposeEventHandlerUPP(mboxUPP);

			err = RemoveEventHandler(paneRef);
			DisposeEventHandlerUPP(paneUPP);

			ReleaseWindow(tWindowRef);

			so.stereo_switch = ~0;

			mbxFinished = true;

			if (musicboxmode == kMBXSoundEmulation)
			{
 				SPCPlayDefrost();

				delete    StoredAPU;
				delete    StoredAPURegisters;
				delete    StoredSoundData;
				delete [] StoredIAPURAM;
			}
			else
				MusicBoxForceDefrost();

			Settings.OpenGLEnable = false;
		}

		if (actIcon)
			err = UnregisterIconRef('~9X~', 'micn');

		DisposeNibReference(nibRef);
	}
}
Ejemplo n.º 30
0
Boolean MultiCartDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	multiCartDragHilite = -1;
	multiCartDialogResult = false;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		WindowRef	window;

		err = CreateWindowFromNib(nibRef, CFSTR("MultiCart"), &window);
		if (err == noErr)
		{
			static int	index[2] = { 0, 1 };

			EventHandlerRef	wRef, cRef[2];
			EventHandlerUPP	wUPP, cUPP[2];
			EventTypeSpec	wEvent[] = { { kEventClassCommand, kEventCommandProcess      },
										 { kEventClassCommand, kEventCommandUpdateStatus } },
							cEvent[] = { { kEventClassControl, kEventControlDraw         },
										 { kEventClassControl, kEventControlDragEnter    },
										 { kEventClassControl, kEventControlDragWithin   },
										 { kEventClassControl, kEventControlDragLeave    },
										 { kEventClassControl, kEventControlDragReceive  } };
			HIViewRef		ctl, root, pane[2];
			HIViewID		cid;

			root = HIViewGetRoot(window);

			wUPP = NewEventHandlerUPP(MultiCartEventHandler);
			err = InstallWindowEventHandler(window, wUPP, GetEventTypeCount(wEvent), wEvent, (void *) window, &wRef);
			err = SetAutomaticControlDragTrackingEnabledForWindow(window, true);

			for (int i = 0; i < 2; i++)
			{
				cid.id = i;

				cid.signature = 'MPan';
				HIViewFindByID(root, cid, &pane[i]);
				cUPP[i] = NewEventHandlerUPP(MultiCartPaneEventHandler);
				err = InstallControlEventHandler(pane[i], cUPP[i], GetEventTypeCount(cEvent), cEvent, (void *) &index[i], &cRef[i]);
				err = SetControlDragTrackingEnabled(pane[i], true);

				cid.signature = 'MNAM';
				HIViewFindByID(root, cid, &ctl);
				SetStaticTextTrunc(ctl, truncEnd, false);
				if (multiCartPath[i])
				{
					CFStringRef	str;
					CFURLRef	url;

					url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, multiCartPath[i], kCFURLPOSIXPathStyle, false);
					str = CFURLCopyLastPathComponent(url);
					SetStaticTextCFString(ctl, str, false);
					CFRelease(str);
					CFRelease(url);
				}
				else
					SetStaticTextCFString(ctl, CFSTR(""), false);
			}

			MoveWindowPosition(window, kWindowMultiCart, false);
			ShowWindow(window);
			err = RunAppModalLoopForWindow(window);
			HideWindow(window);
			SaveWindowPosition(window, kWindowMultiCart);

			for (int i = 0; i < 2; i++)
			{
				err = RemoveEventHandler(cRef[i]);
				DisposeEventHandlerUPP(cUPP[i]);
			}

			err = RemoveEventHandler(wRef);
			DisposeEventHandlerUPP(wUPP);

			CFRelease(window);
		}

		DisposeNibReference(nibRef);
	}

	return (multiCartDialogResult);
}