Beispiel #1
0
/*****************************************************
*
* DisplaySimpleWindow ( void ) 
*
* Purpose:  Called to create a new window in response to a kHICommandNew event.  Here we create a window, set up the MyMPTaskInfo structure,
*			and create an MP thread to monitor our specified directories.
*
*/
static	void	DisplaySimpleWindow( void )
{
	OSStatus				err;
	OSStatus				err1;
	WindowRef				window;
	ControlRef				control;
	MPTaskID				mpTaskID;
	MyMPTaskInfo			*mpTaskInfo;
	FSRef					fsRef;
	char					path[MAXPATHLEN];
	DialogRef				alertDialog;
	static	EventHandlerUPP	mpWindowEventHandlerUPP;
	SInt32					i			= -1;
	const EventTypeSpec	windowEvents[]	=   {
												{ kEventClassCommand, kEventCommandProcess },
												{ kEventClassMP, kEventKQueue },
												{ kEventClassWindow, kEventWindowClose }
											};
	
	err	= CreateWindowFromNib( g.mainNib, CFSTR("MainWindow"), &window );
	if ( (err != noErr) || (window == NULL) )	goto Bail;
	
	if ( mpWindowEventHandlerUPP == NULL ) mpWindowEventHandlerUPP	= NewEventHandlerUPP( MPWindowEventHandlerProc );	//  MPWindowEventHandlerProc handles events for this window
	err = InstallWindowEventHandler( window, mpWindowEventHandlerUPP, GetEventTypeCount(windowEvents), windowEvents, window, NULL );

	//  Display the directories we are going to watch in the static text fields.  In this sample we hard code the values to a few specific locations
	err = FSFindFolder( kUserDomain, kDesktopFolderType, kDontCreateFolder, &fsRef );								//  Watch the Desktop folder
	err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN );
	if ( (err == noErr) && (err1 == noErr) )
		SetControlCString( window, 'STxt', ++i, path );
	
	err = FSFindFolder( kUserDomain, kDocumentsFolderType, kDontCreateFolder, &fsRef );								//  Watch the Documents folder
	err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN );
	if ( (err == noErr) && (err1 == noErr) )
		SetControlCString( window, 'STxt', ++i, path );
	
	err = FSFindFolder( kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &fsRef );							//  Watch the Users folder
	err1 = FSRefMakePath( &fsRef, (UInt8 *)path, MAXPATHLEN );
	if ( (err == noErr) && (err1 == noErr) )
		SetControlCString( window, 'STxt', ++i, path );
	
	mpTaskInfo	= (MyMPTaskInfo*) NewPtrClear( sizeof(MyMPTaskInfo) );
	SetWRefCon( window, (long) mpTaskInfo );
	for ( mpTaskInfo->count = 0 ; mpTaskInfo->count < kMaxFoldersToWatch ; mpTaskInfo->count++ )
	{
		GetControlCString( window, 'STxt', mpTaskInfo->count, mpTaskInfo->path[mpTaskInfo->count] );				//  This code pretty much just reads back the strings we set above
		if ( mpTaskInfo->path[mpTaskInfo->count][0] == '\0' )   break;

		//  We initialize a number of values which are not be safe to retrieve from an MP thread.
		GetControlBySigAndID( window, 'Date', mpTaskInfo->count, &mpTaskInfo->mpControlInfo[mpTaskInfo->count].dateControl );
		GetControlBySigAndID( window, 'STxt', mpTaskInfo->count, &control );
		mpTaskInfo->mpControlInfo[mpTaskInfo->count].eventTarget = GetControlEventTarget( control );
	}
	if ( mpTaskInfo->count < 1 )
	{
		DisposePtr( (Ptr) mpTaskInfo );
		goto Bail;
	}
	
	//  Create our MP thread and pass in mpTaskInfo.  MyMPTask is responsible for watching the passed in directories, and posting notifications of changes.
	err	= MPCreateTask( MyMPTask, (void *) mpTaskInfo, 0, NULL, 0, 0, kNilOptions, &mpTaskID );
	if ( err != noErr )																								//  Alert if an error occured
	{
		CreateStandardAlert( kAlertStopAlert, CFSTR("MPCreateTask returned an error! Will not create window."), NULL, NULL, &alertDialog );
		RunStandardAlert( alertDialog, NULL, NULL );
		goto Bail;
	}
	
	ShowWindow( window );

Bail:
	return;
}
Beispiel #2
0
OSStatus DisplayReleaseNotes(void)
{
	OSStatus err;
	IBNibRef nib = NULL;
	WindowRef window = NULL;
	
	err = CreateNibReference(CFSTR("SecondLife"), &nib);
	
	if(err == noErr)
	{
		CreateWindowFromNib(nib, CFSTR("Release Notes"), &window);
	}
		
	if(err == noErr)
	{
		// Get the text view control
		HIViewRef textView;
		ControlID id;

		id.signature = 'text';
		id.id = 0;

		LLString releaseNotesText;
		
		_read_file_into_string(releaseNotesText, "releasenotes.txt");		// Flawfinder: ignore

		err = HIViewFindByID(HIViewGetRoot(window), id, &textView);
		
		if(err == noErr)
		{
			// Convert from the encoding used in the release notes.
			CFStringRef str = CFStringCreateWithBytes(
				NULL, 
				(const UInt8*)releaseNotesText.c_str(), 
				releaseNotesText.size(), 
				kCFStringEncodingWindowsLatin1, 		// This matches the way the Windows version displays the release notes.
				FALSE);
			
			if(str != NULL)
			{
				int size = CFStringGetLength(str);

				if(size > 0)
				{
					UniChar *chars = new UniChar[size + 1];
					CFStringGetCharacters(str, CFRangeMake(0, size), chars);
				
					err = TXNSetData(HITextViewGetTXNObject(textView), kTXNUnicodeTextData, chars, size * sizeof(UniChar), kTXNStartOffset, kTXNStartOffset);
					
					delete[] chars;
				}
				
				CFRelease(str);
			}
			else
			{
				// Creating the string failed.  Probably an encoding problem.  Display SOMETHING...
				err = TXNSetData(HITextViewGetTXNObject(textView), kTXNTextData, releaseNotesText.c_str(), releaseNotesText.size(), kTXNStartOffset, kTXNStartOffset);
			}
		}
		
		// Set the selection to the beginning of the text and scroll it into view.
		if(err == noErr)
		{
			err = TXNSetSelection(HITextViewGetTXNObject(textView), kTXNStartOffset, kTXNStartOffset);
		}
		
		if(err == noErr)
		{
			// This function returns void.
			TXNShowSelection(HITextViewGetTXNObject(textView), false);
		}
	}

	if(err == noErr)
	{
		ShowWindow(window);
	}

	if(err == noErr)
	{
		// Set up an event handler for the window.
		EventHandlerRef handler = NULL;
		EventTypeSpec handlerEvents[] = 
		{
			{ kEventClassCommand, kEventCommandProcess }
		};

		InstallWindowEventHandler(
				window, 
				NewEventHandlerUPP(simpleDialogHandler), 
				GetEventTypeCount (handlerEvents), 
				handlerEvents, 
				(void*)window, 
				&handler);
	}
			
	if(err == noErr)
	{
		RunAppModalLoopForWindow(window);
	}
			
	if(window != NULL)
	{
		DisposeWindow(window);
	}
	
	if(nib != NULL)
	{
		DisposeNibReference(nib);
	}

	return(err);
}
Beispiel #3
0
LPSTR create_keyval (WindowRef wnd, LPCSTR attrs, BOOL *verify_conn)
{
  EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit };
  RgnHandle cursorRgn = NULL;
  TKEYVAL keyval_t;
  ControlID controlID;
  WindowRef wkeyval;
  ControlRef control;
  EventRecord event;
  IBNibRef nibRef;
  OSStatus err;

  /* Search the bundle for a .nib file named 'odbcadmin'. */
  err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (
          CFSTR ("org.iodbc.adm")), CFSTR ("keyval"), &nibRef);
  if (err == noErr)
    {
      /* Nib found ... so create the window */
      CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wkeyval);
      DisposeNibReference (nibRef);

      /* Install handlers for the finish button, the cancel */
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVERIFYCONN_CNTL, wkeyval,
	  keyval_t.verify_conn_cb);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSLIST_CNTL, wkeyval,
	  keyval_t.key_list);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSKEYWORD_CNTL, wkeyval,
	  keyval_t.key_entry);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVALUE_CNTL, wkeyval,
	  keyval_t.value_entry);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSUPDATE_CNTL, wkeyval,
	  keyval_t.bupdate);

      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSADD_CNTL, wkeyval,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (keyval_add_clicked), 1, &controlSpec,
	  &keyval_t, NULL);
      InstallEventHandler (GetControlEventTarget (keyval_t.bupdate),
	  NewEventHandlerUPP (keyval_update_clicked), 1, &controlSpec,
	  &keyval_t, NULL);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSOK_CNTL, wkeyval,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (keyval_ok_clicked), 1, &controlSpec,
	  &keyval_t, NULL);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSCANCEL_CNTL, wkeyval,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (keyval_cancel_clicked), 1, &controlSpec,
	  &keyval_t, NULL);

      /* Parse the attributes line */
      keyval_t.mainwnd = wkeyval;
      addkeywords_to_list (keyval_t.key_list, attrs, &keyval_t);

      AdvanceKeyboardFocus (wkeyval);
      /* Show the window and run the loop */
      DeactivateControl (keyval_t.bupdate);
      KEYVAL = &keyval_t;
      ShowSheetWindow(wkeyval, wnd);
      /* The main loop */
      while (keyval_t.mainwnd)
        WaitNextEvent (everyEvent, &event, 60L, cursorRgn);

      if (keyval_t.connstr)
        *verify_conn = keyval_t.verify_conn;
    }
  else
    goto error;

  return keyval_t.connstr;

error:
  fprintf (stderr, "Can't load Window. Err: %d\n", (int) err);
  return keyval_t.connstr;
}
Beispiel #4
0
LPSTR create_gensetup (HWND hwnd, LPCSTR dsn,
    LPCSTR attrs, BOOL add, BOOL *verify_conn)
{
  EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit };
  RgnHandle cursorRgn = NULL;
  TGENSETUP gensetup_t;
  ControlID controlID;
  WindowRef wgensetup;
  ControlRef control;
  EventRecord event;
  IBNibRef nibRef;
  OSStatus err;
  char msg[1024];

  gensetup_t.verify_conn = true;
  /* Search the bundle for a .nib file named 'odbcadmin'. */
  /* Search the bundle for a .nib file named 'odbcadmin'. */
  err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (
          CFSTR ("org.iodbc.adm")), CFSTR ("gensetup"), &nibRef);
  if (err == noErr)
    {
      /* Nib found ... so create the window */
      CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wgensetup);
      DisposeNibReference (nibRef);
      /* Set the title with the DSN */
      if (dsn)
        {
          msg[0] = STRLEN ("Setup of ") + STRLEN(dsn);
          sprintf (msg+1, "Setup of %s", (char*)dsn);
          SetWTitle (wgensetup, msg);
	}
      /* Install handlers for the finish button, the cancel */
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSDSN_CNTL, wgensetup,
	  gensetup_t.dsn_entry);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVERIFYCONN_CNTL, wgensetup,
	  gensetup_t.verify_conn_cb);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSLIST_CNTL, wgensetup,
	  gensetup_t.key_list);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSKEYWORD_CNTL, wgensetup,
	  gensetup_t.key_entry);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVALUE_CNTL, wgensetup,
	  gensetup_t.value_entry);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSUPDATE_CNTL, wgensetup,
	  gensetup_t.bupdate);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSADD_CNTL, wgensetup,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (gensetup_add_clicked), 1, &controlSpec,
	  &gensetup_t, NULL);
      InstallEventHandler (GetControlEventTarget (gensetup_t.bupdate),
	  NewEventHandlerUPP (gensetup_update_clicked), 1, &controlSpec,
	  &gensetup_t, NULL);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSOK_CNTL, wgensetup,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (gensetup_ok_clicked), 1, &controlSpec,
	  &gensetup_t, NULL);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSCANCEL_CNTL, wgensetup,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (gensetup_cancel_clicked), 1, &controlSpec,
	  &gensetup_t, NULL);
      /* Parse the attributes line */
      gensetup_t.mainwnd = wgensetup;
      parse_attribute_line (&gensetup_t, dsn, attrs, add);
      AdvanceKeyboardFocus (wgensetup);
      /* Show the window and run the loop */
      DeactivateControl (gensetup_t.bupdate);
      DSNSETUP = &gensetup_t;
      ShowWindow (wgensetup);
      /* The main loop */
      while (gensetup_t.mainwnd)
	{
	  switch (WaitNextEvent (everyEvent, &event, 60L, cursorRgn))
	    {
	    };
	}
      *verify_conn = gensetup_t.verify_conn;
    }
  else
    goto error;

  return gensetup_t.connstr;

error:
  fprintf (stderr, "Can't load Window. Err: %d\n", (int) err);
  return gensetup_t.connstr;
}
Beispiel #5
0
static WindowRef DrawDialogTheMacOSXWay(void)
{
	// Create a window. "DLOG:257" is the name of the window object. This name is set in 
	// InterfaceBuilder when the resource file is imported.
	
	OSStatus status = noErr;
	IBNibRef nibRef;
	WindowRef window  = NULL;
	
	static HIObjectClassRef	theClass;
	if (theClass == NULL)
	{
		static EventTypeSpec kFactoryEvents[] =
	{
				{ kEventClassHIObject, kEventHIObjectConstruct },
				{ kEventClassHIObject, kEventHIObjectInitialize },
				{ kEventClassHIObject, kEventHIObjectDestruct },
				{ kEventClassControl, kEventControlHitTest },
				{ kEventClassControl, kEventControlTrack },
				{ kEventClassControl, kEventControlBoundsChanged },
				{ kEventClassControl, kEventControlDraw }
	};
		HIObjectRegisterSubclass(kCustomSpotViewClassID, kHIViewClassID, 0, CustomSpotViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass);
	}
	
	status = CreateNibReference(CFSTR("main"), &nibRef);
	require_noerr(status, CantGetNibRef);
	
	status = CreateWindowFromNib(nibRef, CFSTR("DLOG:257"), &window);
	require_noerr(status, CantCreateWindow);
	
	// Let's react to User's commands.
	EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess};
	InstallEventHandler(GetWindowEventTarget(window), MacOSXDialogCommandProcess, 1, &eventTypeCP, window, NULL);
	
	// we still assign the key filter on our edit text box so that only digits can be entered
	HIViewID hidnst = {0, 9};
	HIViewRef numEditText;
	HIViewFindByID(HIViewGetRoot(window), hidnst, &numEditText);
	ControlKeyFilterUPP keyFilter = MyEditKeyFilter;
	SetControlData(numEditText, kControlEntireControl, kControlEditTextKeyFilterTag, sizeof(keyFilter), &keyFilter);
	SetKeyboardFocus(window, numEditText, kControlFocusNextPart);
	
	// we still set the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work
	// and still associate the previous edit text box with the scroll bar so it gets updated
	HIViewID hidsb = {0, 14};
	HIViewRef scrollBar;
	HIViewFindByID(HIViewGetRoot(window), hidsb, &scrollBar);
	SetControlAction(scrollBar, ScrollBar32BitActionProc);
	SetControlReference(scrollBar, (SInt32)numEditText);
	
	// Move it!
	MoveWindow(window, 854, 271, false);
	
	// and use the replacement for ModalDialog
	// one good thing is that our behaviors are no longer half-done at the dialog level
	// and half-done at the control level, they are all handled by the view handlers
	ShowWindow(window);
	
CantCreateWindow:
CantGetNibRef:
		return (window);
}
Beispiel #6
0
BOOL create_confirm_Internal (HWND hwnd,
    SQLPOINTER dsn,
    SQLPOINTER text,
    SQLCHAR waMode)
{
  EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit };
  RgnHandle cursorRgn = NULL;
  ControlID controlID;
  ControlRef control;
  WindowRef wconfirm;
  TCONFIRM confirm_t;
  EventRecord event;
  IBNibRef nibRef;
  CFStringRef msg;
  OSStatus err;

  /* Search the bundle for a .nib file named 'odbcadmin'. */
  err =
      CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (CFSTR
	("org.iodbc.drvproxy")), CFSTR ("confirmation"), &nibRef);
  if (err == noErr)
    {
      /* Nib found ... so create the window */
      CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wconfirm);
      DisposeNibReference (nibRef);
      /* Set the title with the DSN name */
      if (dsn)
	{
          if (waMode == 'A')
            msg = CFStringCreateWithBytes (NULL, (unsigned char*)dsn, STRLEN(dsn), 
              kCFStringEncodingUTF8, false);
          else
            msg = convert_wchar_to_CFString((wchar_t*)dsn);
          SetWindowTitleWithCFString (wconfirm, msg);
          CFRelease(msg);
	}
      /* Install handlers for the finish button, the cancel */
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFYES_CNTL, wconfirm,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (confirmadm_yes_clicked), 1, &controlSpec,
	  &confirm_t, NULL);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFNO_CNTL, wconfirm,
	  control);
      InstallEventHandler (GetControlEventTarget (control),
	  NewEventHandlerUPP (confirmadm_no_clicked), 1, &controlSpec,
	  &confirm_t, NULL);
      /* Change the static field with the message */
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFTEXT_CNTL, wconfirm,
	  control);
      if (waMode == 'A')
        SetControlData (control, 0, kControlEditTextTextTag, STRLEN (text), text);
      else
        {
          msg = convert_wchar_to_CFString((wchar_t*)text);
          SetControlData (control, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &msg);
          CFRelease(msg);
        }
      DrawOneControl (control);
      confirm_t.yes_no = FALSE;
      confirm_t.mainwnd = wconfirm;
      /* Show the window and run the loop */
      ShowWindow (wconfirm);
      /* The main loop */
      while (confirm_t.mainwnd)
	WaitNextEvent (everyEvent, &event, 60L, cursorRgn);
    }
  else
    goto error;

  return confirm_t.yes_no;

error:
  fprintf (stderr, "Can't load Window. Err: %d\n", (int) err);
  return confirm_t.yes_no;
}
Beispiel #7
0
bool8 NPClientDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	npclient.dialogcancel = true;
	npclient.dialogsheet  = false;
	npclient.configsaved  = false;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		err = CreateWindowFromNib(nibRef, CFSTR("Connect"), &mRef);
		if (err == noErr)
		{
			err = CreateWindowFromNib(nibRef, CFSTR("PlayerList"), &sRef);
			if (err == noErr)
			{
				EventHandlerRef		eref, seref;
				EventLoopTimerRef	tref;
				EventHandlerUPP		eventUPP, sheetUPP;
				EventLoopTimerUPP	timerUPP;
				EventTypeSpec		windowEvents[] = { { kEventClassCommand, kEventCommandProcess      },
													   { kEventClassCommand, kEventCommandUpdateStatus } };
				CFStringRef			ref;
				HIViewRef			ctl, root;
				HIViewID			cid;

				npclient.dialogprocess = kNPCDialogInit;

				eventUPP = NewEventHandlerUPP(NPClientDialogEventHandler);
				err = InstallWindowEventHandler(mRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) mRef, &eref);

				timerUPP = NewEventLoopTimerUPP(NPClientDialogTimerHandler);
				err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) mRef, &tref);

				sheetUPP = NewEventHandlerUPP(NPClientSheetEventHandler);
				err = InstallWindowEventHandler(sRef, sheetUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) sRef, &seref);

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

				cid.signature = 'CHAS';
				HIViewFindByID(root, cid, &ctl);
				HIViewSetVisible(ctl, false);

				cid.signature = 'SVIP';
				HIViewFindByID(root, cid, &ctl);
				SetEditTextCStr(ctl, npServerIP, false);

				cid.signature = 'CLNM';
				HIViewFindByID(root, cid, &ctl);
				ref = CFStringCreateWithCString(kCFAllocatorDefault, npName, kCFStringEncodingUTF8);
				if (ref)
				{
					SetEditTextCFString(ctl, ref, false);
					CFRelease(ref);
				}
				else
					SetEditTextCFString(ctl, CFSTR("unknown"), false);

				MoveWindowPosition(mRef, kWindowClient, false);
				ShowWindow(mRef);
				err = HIViewAdvanceFocus(root, 0);
				err = RunAppModalLoopForWindow(mRef);
				HideWindow(mRef);
				SaveWindowPosition(mRef, kWindowClient);

				err = RemoveEventHandler(seref);
				DisposeEventHandlerUPP(sheetUPP);

				err = RemoveEventLoopTimer(tref);
				DisposeEventLoopTimerUPP(timerUPP);

				err = RemoveEventHandler(eref);
				DisposeEventHandlerUPP(eventUPP);

				CFRelease(sRef);
			}

			CFRelease(mRef);
		}

		DisposeNibReference(nibRef);
	}

	return (!npclient.dialogcancel);
}
Beispiel #8
0
void AboutDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

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

		err = CreateWindowFromNib(nibRef, CFSTR("About"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		eref;
			EventHandlerUPP		eventUPP;
			EventTypeSpec		windowEvents[] = { { kEventClassWindow,  kEventWindowClose         },
												   { kEventClassCommand, kEventCommandUpdateStatus } };
			ControlFontStyleRec	frec;
			HIViewRef			ctl, root;
			HIViewID			cid;
			char				text[32];

			err = ChangeWindowAttributes(tWindowRef, kWindowNoAttributes, kWindowInWindowMenuAttribute);

			if (systemVersion >= 0x1040)
				frec.font = FMGetFontFromATSFontRef(ATSFontFindFromName(CFSTR("Lucida Grande"), kATSOptionFlagsDefault));
		#ifdef MAC_PANTHER_SUPPORT
			else
				frec.font = kThemeSystemFont;
		#endif
			frec.just = teCenter;

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

			cid.signature = 'VERS';
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "Version %s (%s)", VERSION, MAC_VERSION);
			SetStaticTextCStr(ctl, text, false);
			frec.flags = kControlUseFontMask | kControlUseSizeMask | kControlUseJustMask;
			frec.size  = 10;
			err = SetControlFontStyle(ctl, &frec);

			cid.signature = 'NAME';
			HIViewFindByID(root, cid, &ctl);
			frec.flags = kControlUseFontMask | kControlUseSizeMask | kControlUseFaceMask | kControlUseJustMask;
			frec.size  = 14;
			frec.style = 1;
			err = SetControlFontStyle(ctl, &frec);

			eventUPP = NewEventHandlerUPP(DefaultEventHandler);
			err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref);

			MoveWindowPosition(tWindowRef, kWindowAbout, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowAbout);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eventUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}
}
Beispiel #9
0
void ConfigureAutofire (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

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

		err = CreateWindowFromNib(nibRef, CFSTR("AutoFire"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		wRef, tRef;
			EventHandlerUPP		wUPP, tUPP;
			EventTypeSpec		wEvent[] = { { kEventClassWindow,  kEventWindowClose         },
											 { kEventClassCommand, kEventCommandProcess      },
											 { kEventClassCommand, kEventCommandUpdateStatus } },
								tEvent[] = { { kEventClassControl, kEventControlHit          } };
			ControlActionUPP	actionUPP;
			HIViewRef			ctl, root;
			HIViewID			cid;

			root = HIViewGetRoot(tWindowRef);

			wUPP = NewEventHandlerUPP(AutofireWindowEventHandler);
			err = InstallWindowEventHandler(tWindowRef, wUPP, GetEventTypeCount(wEvent), wEvent, (void *) tWindowRef, &wRef);

			cid.signature = 'Ftab';
			cid.id = 256;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, autofireLastTabIndex);
			AutofireSelectTabPane(ctl, autofireLastTabIndex);
			tUPP = NewEventHandlerUPP(AutofireTabEventHandler);
			err = InstallControlEventHandler(ctl, tUPP, GetEventTypeCount(tEvent), tEvent, 0, &tRef);

			actionUPP = NewControlActionUPP(AutofireSliderActionProc);

			for (int player = 0; player < 2; player++)
			{
				AutofireSetAllIconImages(player + 1, root);
				AutofireReadAllSettings(player + 1, root);

				cid.id = player + 1;
				cid.signature = 'Slid';
				HIViewFindByID(root, cid, &ctl);
				SetControlAction(ctl, actionUPP);
			}

			MoveWindowPosition(tWindowRef, kWindowAutoFire, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowAutoFire);

			for (int player = 0; player < 2; player++)
				AutofireWriteAllSettings(player + 1, root);

			autofire = (autofireRec[0].buttonMask || autofireRec[1].buttonMask) ? true : false;

			err = RemoveEventHandler(tRef);
			DisposeEventHandlerUPP(tUPP);

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

			DisposeControlActionUPP(actionUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}
}
Beispiel #10
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");

	/////////////////////////////////////////
	//
	// Process command line arguments
	//
	gUpdateURL  = NULL;
	gProductName = NULL;
	parse_args(argc, argv);
	if (!gUpdateURL)
	{
		llinfos << "Usage: mac_updater -url <url> [-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";
		}
	}
	
	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);
	}
		
	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);
		}

	}
	
	// Don't dispose of things, just exit.  This keeps the update thread from potentially getting hosed.
	exit(0);

	if(gWindow != NULL)
	{
		DisposeWindow(gWindow);
	}
	
	if(nib != NULL)
	{
		DisposeNibReference(nib);
	}
	
	return 0;
}
Beispiel #11
0
void RomInfoDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	if (!cartOpen)
		return;

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

		err = CreateWindowFromNib(nibRef, CFSTR("RomInfo"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef	eref;
			EventHandlerUPP	eventUPP;
			EventTypeSpec	windowEvents[] = { { kEventClassWindow,  kEventWindowClose         },
											   { kEventClassCommand, kEventCommandProcess      },
											   { kEventClassCommand, kEventCommandUpdateStatus } };
			CFStringRef		sref;
			HIViewRef		ctl, root;
			HIViewID		cid;
			char			text[256];

			eventUPP = NewEventHandlerUPP(RomInfoEventHandler);
			err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref);

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

			cid.signature = 'Name';	// Cart Name
			HIViewFindByID(root, cid, &ctl);

			strcpy(text, Memory.RawROMName);
			sref = CopyFixNameStrings(text, Memory.ROMRegion);
			if (!sref)
				SetStaticTextCFString(ctl, CFSTR("unknown"), false);
			else
			{
				SetStaticTextCFString(ctl, sref, false);
				CFRelease(sref);
			}

			cid.signature = 'Code';	// Game Code
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.ROMId);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Cont';	// Contents
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.KartContents());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Map ';	// ROM Map
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.MapType());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Spee';	// ROM Speed
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%02X (%s)", Memory.ROMSpeed, ((Memory.ROMSpeed & 0x10) != 0) ? "FastROM" : "SlowROM");
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Type';	// ROM Type
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%02X", Memory.ROMType);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'SizC';	// Actual ROM Size
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%dMbits", Memory.CalculatedSize / 0x20000);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'SizH';	// ROM Size written in info block
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.Size());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'SRAM';	// SRAM Size
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.StaticRAMSize());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'SumC';	// Actual checksum
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%04X", Memory.CalculatedChecksum);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'SumH';	// Checksum written in info block
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%04X", Memory.ROMChecksum);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'ComH';	// Checksum complement written in info block : SumH + ComH = 0xFFFF
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%04X", Memory.ROMComplementChecksum);
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Outp';	// Video output (NTSC or PAL)
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", (Memory.ROMRegion > 12 || Memory.ROMRegion < 2) ? "NTSC 60Hz" : "PAL 50Hz");
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Vers';	// Revision
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.Revision());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Lice';	// Licensee
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.PublishingCompany());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'Regi';	// Region
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "%s", Memory.Country());
			SetStaticTextCStr(ctl, text, false);

			cid.signature = 'CRC ';	// CRC32
			HIViewFindByID(root, cid, &ctl);
			sprintf(text, "0x%08X", Memory.ROMCRC32);
			SetStaticTextCStr(ctl, text, false);

			MoveWindowPosition(tWindowRef, kWindowRomInfo, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowRomInfo);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eventUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}
}
Beispiel #12
0
bool loadInfoWin()
{
    IBNibRef nibFile;
    OSStatus iResult;
    EventTypeSpec pEvent;

    g_lpfnGSIDProc = NewDataBrowserItemDataUPP(infoGSID);
    g_lpfnInfoProc = NewEventHandlerUPP(infoEvtHandler);

    if (noErr != (iResult = CreateNibReference(CFSTR("InfoWin"), &nibFile)))
    {
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - CreateNibReference(InfoWin) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    if (noErr != (iResult = CreateWindowFromNib(nibFile, CFSTR("FroggInfoWindow"), &g_refInfoWin)))
    {
        DisposeNibReference(nibFile);
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - CreateWindowFromNib(FroggInfoWindow) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    DisposeNibReference(nibFile);

    pEvent.eventClass = kEventClassWindow;
    pEvent.eventKind = kEventWindowClose;

    if (noErr != (iResult = InstallWindowEventHandler(g_refInfoWin, g_lpfnInfoProc, 1, &pEvent, NULL, &g_refInfoHdlr)))
    {
        DisposeWindow(g_refInfoWin);
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - InstallWindowEventHandler() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    DataBrowserCallbacks dbc;
    ControlRef cRef;
    ControlID cID;

    cID.signature = FOUR_CHAR_CODE('tags');
    cID.id = 16;
    if (noErr != (iResult = GetControlByID(g_refInfoWin, &cID, &cRef)))
    {
        RemoveEventHandler(g_refInfoHdlr);
        DisposeWindow(g_refInfoWin);
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - GetControlByID() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    dbc.version = kDataBrowserLatestCallbacks;

    if (noErr != (iResult = InitDataBrowserCallbacks(&dbc)))
    {
        RemoveEventHandler(g_refInfoHdlr);
        DisposeWindow(g_refInfoWin);
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - InitDataBrwoserCallbacks() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }
    
    dbc.u.v1.itemDataCallback = g_lpfnGSIDProc;

    if (noErr != (iResult = SetDataBrowserCallbacks(cRef, &dbc)))
    {
        RemoveEventHandler(g_refInfoHdlr);
        DisposeWindow(g_refInfoWin);
        DisposeEventHandlerUPP(g_lpfnInfoProc);
        DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);
        fprintf(stderr, "loadInfoWin() - SetDataBrowserCallbacks() failed, returning %lu!\n", (unsigned long) iResult);
        return false;        
    }
    
    g_bLoaded = true;

    return true;
}
/*****************************************************
*
* Do_NewWindow() 
*
* Purpose:  called to create a new window that has been constructed with Interface Builder
*
* Inputs:   none
*
* Returns:  OSStatus			- error code (0 == no error) 
*/
OSStatus Do_NewWindow(void)
	{
	OSStatus status;
	static IBNibRef gIBNibRef = NULL;
	WindowRef aWindowRef = NULL;
	CFStringRef theTitle = NULL;
	CFMutableStringRef theNewTitle = NULL;
	
	if (gIBNibRef == NULL)
		{
		// 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"), &gIBNibRef);
		require_noerr(status, CantGetNibRef);
		}
	require(gIBNibRef != NULL, CantGetNibRef);
	
	// Create a window. "MainWindow" is the name of the window object. This name is set in 
	// InterfaceBuilder when the nib is created.
	status = CreateWindowFromNib(gIBNibRef, CFSTR("MainWindow"), &aWindowRef);
	require_noerr(status, CantCreateWindow);
	require(NULL != aWindowRef, CantCreateWindow);
	
	// Grab the title of the window and add the window count to it
	status = CopyWindowTitleAsCFString(aWindowRef, &theTitle);
	require_noerr(status, CantGetSetTitle);
	
	theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle);
	require(NULL != theNewTitle, CantGetSetTitle);
	
	CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount);
	status = SetWindowTitleWithCFString(aWindowRef, theNewTitle);
	require_noerr(status, CantGetSetTitle);
	
	// Create the custom view to be tested and embed it in our group box control 
	HIViewRef groupBox;
	status = HIViewFindByID(HIViewGetRoot(aWindowRef), kGroupBoxID, &groupBox);
	require_noerr(status, CantFindGroupBox);
	require(groupBox != NULL, CantFindGroupBox);
	
	HIViewRef customView;
	status = HICreateCustomView(NULL, &customView);
	require_noerr(status, CantCreateCustom);
	require(customView != NULL, CantCreateCustom);
	
	HIRect groupBoxBounds;
	HIViewGetBounds(groupBox, &groupBoxBounds);
	groupBoxBounds.origin.x += 20;
	groupBoxBounds.origin.y += 34;
	groupBoxBounds.size.width -= 40;
	groupBoxBounds.size.height -= 54;
	HIViewSetFrame(customView, &groupBoxBounds);
	
	HIViewSetLayoutInfo(customView, &kBindToParentLayout);
	
	status = HIViewAddSubview(groupBox, customView);
	require_noerr(status, CantAddSubview);

	HIViewSetVisible(customView, true);
	
	// Let's react to User's commands.
	EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess};
	status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)customView, NULL);
	require_noerr(status, CantInstallEventHandler);
	
	// Let's update our static text field whenever the value or hilite of our tested custom view changes
	EventTypeSpec eventTypeCVFC[] =
		{
			{kEventClassControl, kEventControlValueFieldChanged},
			{kEventClassControl, kEventControlHiliteChanged}
		};
	status = InstallControlEventHandler(customView, Handle_ControlValueFieldOrHiliteChanged, 2, eventTypeCVFC, (void *)customView, NULL);
	require_noerr(status, CantInstallEventHandler);

	// We accept only numbers in our Edit text control
	HIViewRef editText;
	HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText);

#ifdef MAC_OS_X_VERSION_10_4
	// in Tiger, only 1 event handler is necessary for the key filtering
	EventTypeSpec eventTypeTSCIR = {kEventClassTextField, kEventTextShouldChangeInRange};
	status = InstallControlEventHandler(editText, Handle_TextShouldChangeInRange, 1, &eventTypeTSCIR, (void *)editText, NULL);
	require_noerr(status, CantInstallEventHandler);
#else
	// pre-Tiger, we need a different event handler and a validation proc to handle pastes and drops.
	ControlEditTextValidationUPP textValidation = MyValidationProc;
	SetControlData(editText, kControlEntireControl, kControlEditTextValidationProcTag, sizeof(textValidation), &textValidation);

	EventTypeSpec eventTypeTIUFKE = {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent};
	status = InstallControlEventHandler(editText, Handle_TextInputEvent, 1, &eventTypeTIUFKE, (void *)editText, NULL);
	require_noerr(status, CantInstallEventHandler);
#endif

	// Finishing the custom view setup
	SetControl32BitMinimum(customView, 0);
	SetControl32BitMaximum(customView, 36);
	SetControl32BitValue(customView, 2);

	// We want window and thus our custom view to be able to respond to drops
	status = SetAutomaticControlDragTrackingEnabledForWindow(aWindowRef, true);
	require_noerr(status, SetAutomaticControlDragTrackingEnabledForWindow);

	ShowWindow(aWindowRef);
	SetWindowModified(aWindowRef, false);

SetAutomaticControlDragTrackingEnabledForWindow:
SetControlDragTrackingEnabled:
CantAddSubview:
CantCreateCustom:
CantFindGroupBox:
CantInstallEventHandler:
CantGetSetTitle:
CantAllocateWindowData:
CantCreateWindow:
CantGetNibRef:

	if (theTitle != NULL) CFRelease(theTitle);
	if (theNewTitle != NULL) CFRelease(theNewTitle);
	
	return status;
	}   // Do_NewWindow
Beispiel #14
0
int main(int argc, char *argv[])
{
    OSStatus            err;
    int                 argIndex;
    Boolean             delay;
    Boolean             waitForWindowServerSession;
    Boolean             forceShow;
    Boolean             cleanExit;
    IBNibRef            nibRef;
    WindowRef           window;
    
    // Initialise our ASL state.

    gASLClient = asl_open(NULL, "PreLoginAgents", 0);
    assert(gASLClient != NULL);
    
    (void) asl_set_filter(gASLClient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_INFO));
    
    gASLMessage = asl_new(ASL_TYPE_MSG);
    assert(gASLMessage != NULL);

    (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Start");

    // Parse our arguments.  We support arguments that allow you to turn off 
    // various special cases within the code.  This makes it easy to test whether 
    // the special cases are still required.
    
    delay = false;
    waitForWindowServerSession = false;
    forceShow = true;
    cleanExit = true;
    for (argIndex = 1; argIndex < argc; argIndex++) {
        if ( strcasecmp(argv[argIndex], "--nodelay") == 0 ) {
            delay = false;
        } else if ( strcasecmp(argv[argIndex], "--delay") == 0 ) {
            delay = true;
        } else if ( strcasecmp(argv[argIndex], "--nowait") == 0 ) {
            waitForWindowServerSession = false;
        } else if ( strcasecmp(argv[argIndex], "--wait") == 0 ) {
            waitForWindowServerSession = true;
        } else if ( strcasecmp(argv[argIndex], "--noforce") == 0 ) {
            forceShow = false;
        } else if ( strcasecmp(argv[argIndex], "--force") == 0 ) {
            forceShow = true;
        } else if ( strcasecmp(argv[argIndex], "--nocleanexit") == 0 ) {
            cleanExit = false;
        } else if ( strcasecmp(argv[argIndex], "--cleanexit") == 0 ) {
            cleanExit = true;
        } else {
            (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Unrecognised argument '%s'", argv[argIndex]);
        }
    }

    // Handle various options.
    
    if (waitForWindowServerSession) {
        WaitForWindowServerSession();
    } else {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not waiting for CGSessionCopyCurrentDictionary");
    }
    
    if (delay) {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Delaying");
        
        sleep(3);
    } else {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not delaying");
    }
    
    // Set up our UI.
    
    err = CreateNibReference(CFSTR("main"), &nibRef);
    assert(err == noErr);

    err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
    assert(err == noErr);

    DisposeNibReference(nibRef);

    // We have to set kHIWindowBitCanBeVisibleWithoutLogin to let the 
    // system know that we're not accidentally trying to display a window 
    // pre-login.
    //
    // Also, window is a utility window and, by default, these have the 
    // kWindowHideOnSuspendAttribute attribute set.  As our application is a 
    // UI element which never activates, and we want our panel to show regardless, 
    // we must clear kWindowHideOnSuspendAttribute.
    
    static const int    kAttributesToSet[] = {
        kHIWindowBitCanBeVisibleWithoutLogin, 
        0
    };
    static const int    kAttributesToClear[] = {
        kHIWindowBitHideOnSuspend, 
        0
    };
    err = HIWindowChangeAttributes(
        window,
        kAttributesToSet,
        kAttributesToClear
    );
    assert(err == noErr);

    // Due to a problem with the relationship between the UI frameworks and the 
    // window server <rdar://problem/5136400>, ShowWindow is not sufficient to 
    // show the window.  We also have to use BringToFront.
    
    ShowWindow(window);
    if (forceShow) {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Showing window with extreme prejudice");
        BringToFront(window);
    } else {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Showing window normally");
    }

    // Set up our SIGTERM handler.
    
    if (cleanExit) {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Installing SIGTERM handler");
        InstallHandleSIGTERMFromRunLoop();
    } else {
        (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not installing SIGTERM handler");
    }

    // Go go gadget Carbon!

    (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "RunApplicationEventLoop");
    RunApplicationEventLoop();

    (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Stop");
    
    return EXIT_SUCCESS;
}
Beispiel #15
0
/* Constructor for CARBON_GUI class. */
CARBON_GUI::CARBON_GUI(int argc, char **argv, Stream_mixer *mix) 
 : GUI(argc,argv,mix) 
{
	/* initialization stuff */
  	jmix = mix;
	memset(myLcd,0,sizeof(myLcd));
	memset(myPos,0,sizeof(myPos));
	vumeter=0;
	vuband=0;
	selectedChannel=NULL;
	memset(channel,0,sizeof(channel));
	playlistManager=new PlaylistManager();
	msgList=new Linklist();
	
	/* init mutex used when accessing the statusbox buffer ...
	 * this is needed because other threads can try to write status messages concurrently
	 */
	if(pthread_mutex_init(&_statusLock,NULL) == -1) {
		error("error initializing POSIX thread mutex creating a new CarbonChannel");
		QuitApplicationEventLoop();
	}
	
	// Create a Nib reference 
    err = CreateNibReference(CFSTR("main"), &nibRef);
	if(err != noErr) error("Can't get NIB reference to obtain gui controls!!");
    
	// Create the MainWindow using nib resource file
    err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
	if(err != noErr) {
		error("Can't create MainWindow!!");
		QuitApplicationEventLoop();
	}
	else {
		msg = new CarbonMessage(nibRef);
		/* make the main window also the frontmost one */
		BringToFront(window);
		init_controls();
		
		/* now create the menu to use for the menubar ... it's stored in nib */
		err=CreateMenuFromNib(nibRef,CFSTR("MenuBar"),&mainMenu);
		if(err!=noErr) {
			msg->error("Can't create main menu (%d)!!",err);
		}
		
		/* install vumeter controls */
		setupVumeters();
		/* and the status box */
		setupStatusWindow();
		
		bufferInspector = new BufferInspector(window,nibRef,jmix);
		
		/* now we have to group windows together so if all are visible they will also be layered together */
		err=CreateWindowGroup(kWindowGroupAttrLayerTogether,&mainGroup);
		err=SetWindowGroup(window,mainGroup);
		err=SetWindowGroup(vumeterWindow,mainGroup);
		err=SetWindowGroup(statusWindow,mainGroup);
		err=SetWindowGroup(bufferInspector->window,mainGroup);
		SetWindowGroupOwner(mainGroup,window);
		/* let's create a channel window for each active input channel */
		unsigned int i;
		bool cc=false;
		for (i=0;i<MAX_CHANNELS;i++) {
			strcpy(ch_lcd[i],"00:00:00");
			if(jmix->chan[i]) { 
					CarbonChannel *newChan = new CarbonChannel(jmix,this,nibRef,i);
					channel[i] = newChan;
				/*	
					if(i > 0) {
						RepositionWindow(channel[i]->window,channel[i-1]->window,kWindowCascadeOnParentWindow);
					}
					else {
						RepositionWindow(channel[i],window,kWindowCascadeOnParentWindow);
					}
				*/
					cc=true;
			}
			else {
				channel[i] = NULL;
			}
		}
		/* Ok, once MainWindow has been created and we have instantiated all acrive input channels,
		* we need an instance of CarbonStream to control the stream option window */
		streamHandler = new CarbonStream(jmix,window,nibRef);
		/* by default we want at leat one active channel */
		if(!cc) new_channel();
	
		aboutWindow = new AboutWindow(window,nibRef);
		
		// The window was created hidden so show it.
		ShowWindow( window );
	}
}
Beispiel #16
0
int main()
{
    IBNibRef 		nibRef;
    WindowRef 		window;
    OSStatus		err;
	MenuDefSpec		defSpec;
	MenuRef			menu;
	SInt32			gestaltResult;

    // 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 );
    
    // Add a Quit item if we're not running on X
    Gestalt( gestaltMenuMgrAttr, &gestaltResult );
    if ( ( gestaltResult & gestaltMenuMgrAquaLayoutMask ) == 0 )
    {
    	MenuRef rootMenu = AcquireRootMenu();
    	MenuItemIndex item;
    	
    	GetMenuItemHierarchicalMenu( rootMenu, 2, &menu );
    	AppendMenuItemTextWithCFString( menu, CFSTR("Quit"), 0, kHICommandQuit, &item );
    	SetMenuItemCommandKey( menu, item, false, 'Q' );
    	
    	ReleaseMenu( rootMenu );
    }
    
	defSpec.defType = kMenuDefProcPtr;
	defSpec.u.defProc = NewMenuDefUPP( SampleMDEF );
	
	// Create a standard menu
	CreateNewMenu( 200, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Sample") );
	InsertMenu( menu, 0 );
	AddSampleItems( menu );
	
	// Create a custom menu
	CreateCustomMenu( &defSpec, 201, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Sample [Custom]") );
	InsertMenu( menu, 0 );
	AddSampleItems( menu );
	
	// Create a standard menu
	CreateNewMenu( 202, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Shell") );
	InsertMenu( menu, 0 );
	AddShellItems( menu );
	
	// Create a custom menu
	CreateCustomMenu( &defSpec, 203, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Shell [Custom]") );
	InsertMenu( menu, 0 );
	AddShellItems( menu );
	
	// Create a standard menu
	CreateNewMenu( 204, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Fonts") );
	InsertMenu( menu, 0 );
	CreateStandardFontMenu( menu, 0, 0, 0, NULL );
	
	// Create a custom menu
	CreateCustomMenu( &defSpec, 205, 0, &menu );
	SetMenuTitleWithCFString( menu, CFSTR("Fonts [Custom]") );
	InsertMenu( menu, 0 );
	CreateStandardFontMenu( menu, 0, 0, 0, NULL );
	
    // 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 );
    
    // Call the event loop
    RunApplicationEventLoop();

CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
	return err;
}
Beispiel #17
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;
}
Beispiel #18
0
int main(int argc, char* argv[])
{
	IBNibRef nibRef;
	OSStatus err;
	glob_t g;
    
	// 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;
	}

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

	DataBrowserCallbacks dbc;
	dbc.version=kDataBrowserLatestCallbacks;
	InitDataBrowserCallbacks(&dbc);
	dbc.u.v1.itemDataCallback=MyDataBrowserItemDataCallback;
	ControlRef list=GetControl(20);
	SetDataBrowserCallbacks(list,&dbc);

	{ // look for plugins (in the executable directory)
		char path[300];
		DWORD l=sizeof(path);
		_NSGetExecutablePath(path,&l);
		strcpy(strrchr(path,'/')+1,"libbass*.dylib");
		if (!glob(path,0,0,&g)) {
			int a;
			for (a=0;a<g.gl_pathc;a++) {
				if (BASS_PluginLoad(g.gl_pathv[a],0)) { // plugin loaded,  add it to the list...
					char *p=strrchr(g.gl_pathv[a],'/')+1;
					AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&p,kDataBrowserItemNoProperty);
				}
			}
		}
		DWORD c;
		GetDataBrowserItemCount(list,kDataBrowserNoItem,FALSE,kDataBrowserItemNoState,(DataBrowserItemState*)&c);
		if (!c) { // no plugins...
			static const char *noplugins="no plugins - visit the BASS webpage to get some";
			AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&noplugins,kDataBrowserItemNoProperty);
		}
	}

	SetupControlHandler(10,kEventControlHit,OpenEventHandler);
	SetControlAction(GetControl(12),NewControlActionUPP(PosEventHandler));

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

	ShowWindow(win);
	RunApplicationEventLoop();

	globfree(&g);

	// "free" the output device and all plugins
	BASS_Free();
	BASS_PluginFree(0);

    return 0; 
}
static OSStatus SetupUserInterface(void)
	// Create a user interface from our NIB.
{
	OSStatus 	err;
	IBNibRef 	nibRef;
	Handle		menuBar;

	nibRef  = NULL;
	menuBar = NULL;
		
	err = CreateNibReference(CFSTR("LoginItemsAETest"), &nibRef);
	if (err == noErr) {
		err = CreateMenuBarFromNib(nibRef, CFSTR("MenuBar"), &menuBar);
	}
	if (err == noErr) {
		SetMenuBar(menuBar);
	}
	if (err == noErr) {
		err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &gMainWindow);
	}
	if (err == noErr) {
		ControlID theID;

		theID.signature = 'HDCB';
		theID.id = 0;	

		err = GetControlByID(gMainWindow, &theID, &gAddHiddenControl);
	}

	// Find and set up the data browser control.
	
	if (err == noErr) {
		ControlID theID;

		theID.signature = 'DATA';
		theID.id = 0;	

		err = GetControlByID(gMainWindow, &theID, &gDataControl);
	}
	if (err == noErr) {
		DataBrowserCallbacks callbacks;
		
		callbacks.version = kDataBrowserLatestCallbacks;
		err = InitDataBrowserCallbacks(&callbacks);

		if (err == noErr) {
			callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DataBrowserDataCallback);

			err = SetDataBrowserCallbacks(gDataControl, &callbacks);
		}
	}
	if (err == noErr) {
		DoRefresh();
	}
	
	if (err == noErr) {
		ShowWindow(gMainWindow);
	}
  	
	if (nibRef != NULL) {
		DisposeNibReference(nibRef);
	}
	if (menuBar != NULL) {
		DisposeHandle(menuBar);
	}
	return err;
}
Beispiel #20
0
void ConfigureExtraOptions (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

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

		err = CreateWindowFromNib(nibRef, CFSTR("ExtraOptions"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef	eref;
			EventHandlerUPP	eventUPP;
			EventTypeSpec	windowEvents[] = { { kEventClassWindow,  kEventWindowClose         },
											   { kEventClassCommand, kEventCommandUpdateStatus } };
			HIViewRef		ctl, root;
			HIViewID		cid;

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

			cid.signature = 'BMrk';
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, extraOptions.benchmark);

			cid.signature = 'NoTR';
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, extraOptions.glForceNoTextureRectangle);

			cid.signature = 'CSAp';
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, extraOptions.glUseClientStrageApple);

			cid.signature = 'AGPT';
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, extraOptions.glUseTexturePriority);

			cid.signature = 'Hint';
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, extraOptions.glStorageHint);

			eventUPP = NewEventHandlerUPP(DefaultEventHandler);
			err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref);

			MoveWindowPosition(tWindowRef, kWindowExtra, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowExtra);

			cid.signature = 'BMrk';
			HIViewFindByID(root, cid, &ctl);
			extraOptions.benchmark = GetControl32BitValue(ctl) ? true : false;

			cid.signature = 'NoTR';
			HIViewFindByID(root, cid, &ctl);
			extraOptions.glForceNoTextureRectangle = GetControl32BitValue(ctl) ? true : false;

			cid.signature = 'CSAp';
			HIViewFindByID(root, cid, &ctl);
			extraOptions.glUseClientStrageApple = GetControl32BitValue(ctl) ? true : false;

			cid.signature = 'AGPT';
			HIViewFindByID(root, cid, &ctl);
			extraOptions.glUseTexturePriority = GetControl32BitValue(ctl) ? true : false;

			cid.signature = 'Hint';
			HIViewFindByID(root, cid, &ctl);
			extraOptions.glStorageHint = GetControl32BitValue(ctl);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eventUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}
}
Beispiel #21
0
void ConfigureCheat (void)
{
	if (!cartOpen)
		return;

	OSStatus	err;
	IBNibRef	nibRef;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		err = CreateWindowFromNib(nibRef, CFSTR("CheatEntry"), &wRef);
		if (err == noErr)
		{
			DataBrowserCallbacks	callbacks;
			EventHandlerRef			eref;
			EventHandlerUPP			eUPP;
			EventTypeSpec			events[] = { { kEventClassCommand, kEventCommandProcess      },
												 { kEventClassCommand, kEventCommandUpdateStatus },
												 { kEventClassWindow,  kEventWindowClose         } };
			HIViewRef				ctl, root;
			HIViewID				cid;

			root = HIViewGetRoot(wRef);
			cid.id = 0;
			cid.signature = kDataBrowser;
			HIViewFindByID(root, cid, &dbRef);

		#ifdef MAC_PANTHER_SUPPORT
			if (systemVersion < 0x1040)
			{
				HISize	minSize;
				Rect	rct;

				GetWindowBounds(wRef, kWindowContentRgn, &rct);
				minSize.width  = (float) (rct.right  - rct.left);
				minSize.height = (float) (rct.bottom - rct.top );
				err = SetWindowResizeLimits(wRef, &minSize, NULL);
			}
		#endif

			callbacks.version = kDataBrowserLatestCallbacks;
			err = InitDataBrowserCallbacks(&callbacks);
			callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DBClientDataCallback);
			callbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP(DBCompareCallBack);
			callbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(DBItemNotificationCallBack);
			err = SetDataBrowserCallbacks(dbRef, &callbacks);

			if (systemVersion >= 0x1040)
				err = DataBrowserChangeAttributes(dbRef, kDataBrowserAttributeListViewAlternatingRowColors, kDataBrowserAttributeNone);

			InitCheatItems();
			ImportCheatItems();

			DataBrowserItemID	*id;

			id = new DataBrowserItemID[MAC_MAX_CHEATS];
			if (!id)
				QuitWithFatalError(0, "cheat 01");

			numofcheats = 0;

			for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
			{
				if (citem[i].valid)
				{
					id[numofcheats] = citem[i].id;
					numofcheats++;
				}
			}

			if (numofcheats)
				err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, numofcheats, id, kDataBrowserItemNoProperty);

			delete [] id;

			cid.signature = kNewButton;
			HIViewFindByID(root, cid, &ctl);
			if (numofcheats == MAC_MAX_CHEATS)
				err = DeactivateControl(ctl);
			else
				err = ActivateControl(ctl);

			cid.signature = kAllButton;
			HIViewFindByID(root, cid, &ctl);
			if (numofcheats == 0)
				err = DeactivateControl(ctl);
			else
				err = ActivateControl(ctl);

			cid.signature = kDelButton;
			HIViewFindByID(root, cid, &ctl);
			err = DeactivateControl(ctl);

			eUPP = NewEventHandlerUPP(CheatEventHandler);
			err = InstallWindowEventHandler(wRef, eUPP, GetEventTypeCount(events), events, (void *) wRef, &eref);

			err = SetKeyboardFocus(wRef, dbRef, kControlFocusNextPart);

			MoveWindowPosition(wRef, kWindowCheatEntry, true);
			ShowWindow(wRef);
			err = RunAppModalLoopForWindow(wRef);
			HideWindow(wRef);
			SaveWindowPosition(wRef, kWindowCheatEntry);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eUPP);

			DisposeDataBrowserItemNotificationUPP(callbacks.u.v1.itemNotificationCallback);
			DisposeDataBrowserItemCompareUPP(callbacks.u.v1.itemCompareCallback);
			DisposeDataBrowserItemDataUPP(callbacks.u.v1.itemDataCallback);

			CFRelease(wRef);

			DetachCheatItems();
		}

		DisposeNibReference(nibRef);
	}
}
Beispiel #22
0
void ConfigurePreferences (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		WindowRef	tWindowRef;
		SInt32		oldVolume;
		uint32		oldPlaybackRate, oldInputRate, oldInterval, oldBufferSize;
		bool8		oldSynchronize, old16BitPlayback, oldStereo, oldReverseStereo, oldLagEnable;

		oldSynchronize   = Settings.SoundSync;
		old16BitPlayback = Settings.SixteenBitSound;
		oldStereo        = Settings.Stereo;
		oldReverseStereo = Settings.ReverseStereo;
		oldPlaybackRate  = Settings.SoundPlaybackRate;
		oldInputRate     = Settings.SoundInputRate;
		oldInterval      = macSoundInterval_ms;
		oldBufferSize    = macSoundBuffer_ms;
		oldLagEnable     = macSoundLagEnable;
		oldVolume        = macSoundVolume;

		if (cartOpen)
			DeinitGameWindow();

		S9xGraphicsDeinit();

		err = CreateWindowFromNib(nibRef, CFSTR("Preferences"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerUPP		tUPP, iUPP, aUPP, pUPP;
			EventHandlerRef		tRef, iRef, aRef, pRef;
			EventTypeSpec		tEvents[] = { { kEventClassControl, kEventControlHit          } },
								iEvents[] = { { kEventClassControl, kEventControlClick        } },
								aEvents[] = { { kEventClassControl, kEventControlClick        } },
								pEvents[] = { { kEventClassWindow,  kEventWindowClose         },
											  { kEventClassCommand, kEventCommandProcess      },
											  { kEventClassCommand, kEventCommandUpdateStatus } };
			ControlActionUPP	arrowsUPP, sliderUPP;
			HIViewRef			ctl, root;
			HIViewID			cid;
			MenuRef				menu;
			char				num[16];

			root = HIViewGetRoot(tWindowRef);

			cid.signature = 'tabs';
			cid.id = 128;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, lastTabIndex);
			SelectTabPane(ctl, lastTabIndex);
			tUPP = NewEventHandlerUPP(TabEventHandler);
			err = InstallControlEventHandler(ctl, tUPP, GetEventTypeCount(tEvents), tEvents, 0, &tRef);

			cid.signature = 'snd_';
			cid.id = iNibSInputRateText;
			HIViewFindByID(root, cid, &ctl);
			iUPP = NewEventHandlerUPP(InputRateTextEventHandler);
			err = InstallControlEventHandler(ctl, iUPP, GetEventTypeCount(iEvents), iEvents, 0, &iRef);

			cid.signature = 'grap';
			cid.id = iNibGAspectRatioText;
			HIViewFindByID(root, cid, &ctl);
			aUPP = NewEventHandlerUPP(AspectRatioTextEventHandler);
			err = InstallControlEventHandler(ctl, aUPP, GetEventTypeCount(aEvents), aEvents, 0, &aRef);

			pUPP = NewEventHandlerUPP(PreferencesEventHandler);
			err = InstallWindowEventHandler(tWindowRef, pUPP, GetEventTypeCount(pEvents), pEvents, (void *) tWindowRef, &pRef);

			sliderUPP = NewControlActionUPP(InputRateSliderActionProc);
			arrowsUPP = NewControlActionUPP(LittleArrowsActionProc);

			cid.signature = 'grap';

			cid.id = iNibGFullScreen;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, fullscreen);

			cid.id = iNibGSwitchResolution;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, autoRes);

			cid.id = iNibGShowFrameRate;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.DisplayFrameRate);

			cid.id = iNibGTransparency;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.Transparency);

			cid.id = iNibGGL32bit;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, gl32bit);

			cid.id = iNibGGLStretch;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, glstretch);

			cid.id = iNibGVideoMode;
			HIViewFindByID(root, cid, &ctl);
			switch (videoMode)
			{
				case VIDEOMODE_BLOCKY:
					SetControl32BitValue(ctl, iOpenGLBlocky);
					break;

				case VIDEOMODE_TV:
					SetControl32BitValue(ctl, iOpenGLTVMode);
					break;

				case VIDEOMODE_SMOOTH:
					SetControl32BitValue(ctl, iOpenGLSmoothMode);
					break;

				case VIDEOMODE_BLEND:
					SetControl32BitValue(ctl, iOpenGLBlendMode);
					break;

				case VIDEOMODE_SUPEREAGLE:
					SetControl32BitValue(ctl, iOpenGLEagleMode);
					break;

				case VIDEOMODE_2XSAI:
					SetControl32BitValue(ctl, iOpenGL2xSAIMode);
					break;

				case VIDEOMODE_SUPER2XSAI:
					SetControl32BitValue(ctl, iOpenGLSuper2xSAIMode);
					break;

				case VIDEOMODE_EPX:
					SetControl32BitValue(ctl, iOpenGLEPXMode);
					break;

				case VIDEOMODE_HQ2X:
					SetControl32BitValue(ctl, iOpenGLHQ2xMode);
					break;

				case VIDEOMODE_HQ3X:
					SetControl32BitValue(ctl, iOpenGLHQ3xMode);
					break;

				case VIDEOMODE_HQ4X:
					SetControl32BitValue(ctl, iOpenGLHQ4xMode);
					break;

				case VIDEOMODE_NTSC_C:
					SetControl32BitValue(ctl, iOpenGLNTSC_CMode);
					break;

				case VIDEOMODE_NTSC_S:
					SetControl32BitValue(ctl, iOpenGLNTSC_SMode);
					break;

				case VIDEOMODE_NTSC_R:
					SetControl32BitValue(ctl, iOpenGLNTSC_RMode);
					break;

				case VIDEOMODE_NTSC_M:
					SetControl32BitValue(ctl, iOpenGLNTSC_MMode);
					break;

				case VIDEOMODE_NTSC_TV_C:
					SetControl32BitValue(ctl, iOpenGLNTSC_TV_CMode);
					break;

				case VIDEOMODE_NTSC_TV_S:
					SetControl32BitValue(ctl, iOpenGLNTSC_TV_SMode);
					break;

				case VIDEOMODE_NTSC_TV_R:
					SetControl32BitValue(ctl, iOpenGLNTSC_TV_RMode);
					break;

				case VIDEOMODE_NTSC_TV_M:
					SetControl32BitValue(ctl, iOpenGLNTSC_TV_MMode);
					break;
			}

			cid.id = iNibGDirectMP;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, multiprocessor);

			cid.id = iNibGGLVSync;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, vsync);

			cid.id = iNibGDrawOverscan;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, drawoverscan);

			cid.id = iNibGScreenCurvature;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, screencurvature);

			cid.id = iNibGCurvatureWarp;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macCurvatureWarp);
			if (!screencurvature)
				DeactivateControl(ctl);

			cid.id = iNibGAspectRatio;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macAspectRatio);
			if (!glstretch)
				DeactivateControl(ctl);

			cid.id = iNibGCIFilterEnable;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, ciFilterEnable);
			if (systemVersion < 0x1040)
				DisableControl(ctl);

			if (systemVersion < 0x1040)
			{
				cid.id = iNibGCoreImageFilter;
				HIViewFindByID(root, cid, &ctl);
				DisableControl(ctl);
			}

			cid.signature = 'snd_';

			cid.id = iNibSSynchronize;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.SoundSync);

			cid.id = iNibS16BitPlayback;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.SixteenBitSound);
			DeactivateControl(ctl);

			cid.id = iNibSStereo;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.Stereo);
			DeactivateControl(ctl);

			cid.id = iNibSReverseStereo;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.ReverseStereo);
			DeactivateControl(ctl);

			cid.id = iNibSPlaybackRate;
			HIViewFindByID(root, cid, &ctl);
			switch (Settings.SoundPlaybackRate)
			{
				case 48000:
					SetControl32BitValue(ctl, 1);
					break;

				case 44100:
					SetControl32BitValue(ctl, 2);
					break;

				case 35000:
					SetControl32BitValue(ctl, 3);
					break;

				case 32000:
					SetControl32BitValue(ctl, 4);
					break;

				case 30000:
					SetControl32BitValue(ctl, 5);
					break;

				case 22050:
					SetControl32BitValue(ctl, 6);
					break;

				case 16000:
					SetControl32BitValue(ctl, 7);
					break;

				case 11025:
					SetControl32BitValue(ctl, 8);
					break;

				case 8000:
					SetControl32BitValue(ctl, 9);
					break;
			}

			cid.id = iNibSInputRate;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.SoundInputRate);
			SetControlAction(ctl, sliderUPP);

			cid.id = iNibSInputRateText;
			HIViewFindByID(root, cid, &ctl);
			sprintf(num, "%d", Settings.SoundInputRate);
			SetStaticTextCStr(ctl, num, false);

			cid.id = iNibSInterval;
			HIViewFindByID(root, cid, &ctl);
			switch (macSoundInterval_ms)
			{
				case 8:
					SetControl32BitValue(ctl, 1);
					break;

				case 16:
					SetControl32BitValue(ctl, 2);
					break;

				case 32:
					SetControl32BitValue(ctl, 3);
					break;

				case 64:
					SetControl32BitValue(ctl, 4);
					break;

				case 0:
				default:
					SetControl32BitValue(ctl, 6);
					break;
			}

			cid.id = iNibSBufferSize;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macSoundBuffer_ms / 20);

			cid.id = iNibSAllowLag;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macSoundLagEnable);
			DeactivateControl(ctl);

			cid.id = iNibSVolume;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macSoundVolume);

			cid.signature = 'othe';

			cid.id = iNibOSaveFolder;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, saveInROMFolder + 1);
			err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL);
			if (saveFolderPath)
			{
				CFURLRef	url;
				CFStringRef	ref;

				url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, saveFolderPath, kCFURLPOSIXPathStyle, true);
				ref = CFURLCopyLastPathComponent(url);
				err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref);
				CFRelease(ref);
				CFRelease(url);
				EnableMenuItem(menu, iNibSaveFolderNameMenuItem);
			}
			else
			{
				CFStringRef	ref;

				ref = CFCopyLocalizedString(CFSTR("NoneSelected"), "NoneSelected");
				err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref);
				CFRelease(ref);
				DisableMenuItem(menu, iNibSaveFolderNameMenuItem);
			}

			cid.id = iNibOAutoSaveInterval;
			HIViewFindByID(root, cid, &ctl);
			sprintf(num, "%d", Settings.AutoSaveDelay);
			SetEditTextCStr(ctl, num, false);

			cid.signature = 'msc2';

			cid.id = iNibMCPUCycles;
			HIViewFindByID(root, cid, &ctl);
			sprintf(num, "%" PRIi32, Settings.HDMATimingHack);
			SetEditTextCStr(ctl, num, false);

			cid.id = iNibMTurboSkipArrows;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macFastForwardRate);
			SetControlAction(ctl, arrowsUPP);

			cid.id = iNibMTurboSkipText;
			HIViewFindByID(root, cid, &ctl);
			sprintf(num, "%d", macFastForwardRate);
			SetStaticTextCStr(ctl, num, false);

			cid.id = iNibMFrameSkip;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, macFrameSkip + 2);

			cid.id = iNibMAllowInvalidVRAMAccess;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, !Settings.BlockInvalidVRAMAccessMaster);

			cid.id = iNibMAllowSpecificGameHacks;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, !Settings.DisableGameSpecificHacks);

			cid.signature = 'osx_';

			cid.id = iNibXStartOpenDialog;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, startopendlog);

			cid.id = iNibXShowTimeInFrz;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, showtimeinfrz);

			cid.id = iNibXMusicBoxMode;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, musicboxmode);

			cid.id = iNibXEnableToggle;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, enabletoggle);

			cid.id = iNibXSaveWindowPos;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, savewindowpos);

			cid.id = iNibXUseIPSPatch;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, !Settings.NoPatch);

			cid.id = iNibXOnScreenInfo;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, onscreeninfo);

			cid.id = iNibXInactiveMode;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, inactiveMode);

			cid.id = iNibXBSXBootup;
			HIViewFindByID(root, cid, &ctl);
			SetControl32BitValue(ctl, Settings.BSXBootup);

			MoveWindowPosition(tWindowRef, kWindowPreferences, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowPreferences);

			cid.signature = 'grap';

			cid.id = iNibGFullScreen;
			HIViewFindByID(root, cid, &ctl);
			fullscreen = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGSwitchResolution;
			HIViewFindByID(root, cid, &ctl);
			autoRes = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGShowFrameRate;
			HIViewFindByID(root, cid, &ctl);
			Settings.DisplayFrameRate = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGTransparency;
			HIViewFindByID(root, cid, &ctl);
			Settings.Transparency = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGGL32bit;
			HIViewFindByID(root, cid, &ctl);
			gl32bit = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGGLStretch;
			HIViewFindByID(root, cid, &ctl);
			glstretch = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGVideoMode;
			HIViewFindByID(root, cid, &ctl);
			switch (GetControl32BitValue(ctl))
			{
				case iOpenGLBlocky:
					drawingMethod = kDrawingOpenGL;
					videoMode = VIDEOMODE_BLOCKY;
					break;

				case iOpenGLTVMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_TV;
					break;

				case iOpenGLSmoothMode:
					drawingMethod = kDrawingOpenGL;
					videoMode = VIDEOMODE_SMOOTH;
					break;

				case iOpenGLBlendMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_BLEND;
					break;

				case iOpenGLEagleMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_SUPEREAGLE;
					break;

				case iOpenGL2xSAIMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_2XSAI;
					break;

				case iOpenGLSuper2xSAIMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_SUPER2XSAI;
					break;

				case iOpenGLEPXMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_EPX;
					break;

				case iOpenGLHQ2xMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_HQ2X;
					break;

				case iOpenGLHQ3xMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_HQ3X;
					break;

				case iOpenGLHQ4xMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_HQ4X;
					break;

				case iOpenGLNTSC_CMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_C;
					S9xBlitNTSCFilterSet(&snes_ntsc_composite);
					break;

				case iOpenGLNTSC_SMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_S;
					S9xBlitNTSCFilterSet(&snes_ntsc_svideo);
					break;

				case iOpenGLNTSC_RMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_R;
					S9xBlitNTSCFilterSet(&snes_ntsc_rgb);
					break;

				case iOpenGLNTSC_MMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_M;
					S9xBlitNTSCFilterSet(&snes_ntsc_monochrome);
					break;

				case iOpenGLNTSC_TV_CMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_TV_C;
					S9xBlitNTSCFilterSet(&snes_ntsc_composite);
					break;

				case iOpenGLNTSC_TV_SMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_TV_S;
					S9xBlitNTSCFilterSet(&snes_ntsc_svideo);
					break;

				case iOpenGLNTSC_TV_RMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_TV_R;
					S9xBlitNTSCFilterSet(&snes_ntsc_rgb);
					break;

				case iOpenGLNTSC_TV_MMode:
					drawingMethod = kDrawingBlitGL;
					videoMode = VIDEOMODE_NTSC_TV_M;
					S9xBlitNTSCFilterSet(&snes_ntsc_monochrome);
					break;
			}

			cid.id = iNibGDirectMP;
			HIViewFindByID(root, cid, &ctl);
			multiprocessor = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGGLVSync;
			HIViewFindByID(root, cid, &ctl);
			vsync = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGDrawOverscan;
			HIViewFindByID(root, cid, &ctl);
			drawoverscan = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGScreenCurvature;
			HIViewFindByID(root, cid, &ctl);
			screencurvature = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibGCurvatureWarp;
			HIViewFindByID(root, cid, &ctl);
			macCurvatureWarp = GetControl32BitValue(ctl);

			cid.id = iNibGAspectRatio;
			HIViewFindByID(root, cid, &ctl);
			macAspectRatio = GetControl32BitValue(ctl);

			cid.id = iNibGCIFilterEnable;
			HIViewFindByID(root, cid, &ctl);
			ciFilterEnable = GetControl32BitValue(ctl) ? true : false;

			cid.signature = 'snd_';

			cid.id = iNibSSynchronize;
			HIViewFindByID(root, cid, &ctl);
			Settings.SoundSync = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibS16BitPlayback;
			HIViewFindByID(root, cid, &ctl);
			Settings.SixteenBitSound = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibSStereo;
			HIViewFindByID(root, cid, &ctl);
			Settings.Stereo = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibSReverseStereo;
			HIViewFindByID(root, cid, &ctl);
			Settings.ReverseStereo = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibSPlaybackRate;
			HIViewFindByID(root, cid, &ctl);
			switch (GetControl32BitValue(ctl))
			{
				case 1:
					Settings.SoundPlaybackRate = 48000;
					break;

				case 2:
					Settings.SoundPlaybackRate = 44100;
					break;

				case 3:
					Settings.SoundPlaybackRate = 35000;
					break;

				case 4:
					Settings.SoundPlaybackRate = 32000;
					break;

				case 5:
					Settings.SoundPlaybackRate = 30000;
					break;

				case 6:
					Settings.SoundPlaybackRate = 22050;
					break;

				case 7:
					Settings.SoundPlaybackRate = 16000;
					break;

				case 8:
					Settings.SoundPlaybackRate = 11025;
					break;

				case 9:
					Settings.SoundPlaybackRate = 8000;
					break;
			}

			cid.id = iNibSInputRate;
			HIViewFindByID(root, cid, &ctl);
			Settings.SoundInputRate = GetControl32BitValue(ctl);

			cid.id = iNibSInterval;
			HIViewFindByID(root, cid, &ctl);
			switch (GetControl32BitValue(ctl))
			{
				case 1:
					macSoundInterval_ms = 8;
					break;

				case 2:
					macSoundInterval_ms = 16;
					break;

				case 3:
					macSoundInterval_ms = 32;
					break;

				case 4:
					macSoundInterval_ms = 64;
					break;

				case 6:
				default:
					macSoundInterval_ms = 0;
					break;
			}

			cid.id = iNibSBufferSize;
			HIViewFindByID(root, cid, &ctl);
			macSoundBuffer_ms = GetControl32BitValue(ctl) * 20;

			cid.id = iNibSAllowLag;
			HIViewFindByID(root, cid, &ctl);
			macSoundLagEnable = GetControl32BitValue(ctl);

			cid.id = iNibSVolume;
			HIViewFindByID(root, cid, &ctl);
			macSoundVolume = GetControl32BitValue(ctl);

			cid.signature = 'othe';

			cid.id = iNibOSaveFolder;
			HIViewFindByID(root, cid, &ctl);
			saveInROMFolder = GetControl32BitValue(ctl) - 1;

			cid.id = iNibOAutoSaveInterval;
			HIViewFindByID(root, cid, &ctl);
			GetEditTextCStr(ctl, num);
			Settings.AutoSaveDelay = atoi(num);

			cid.signature = 'msc2';

			cid.id = iNibMCPUCycles;
			HIViewFindByID(root, cid, &ctl);
			GetEditTextCStr(ctl, num);
			Settings.HDMATimingHack = atoi(num);
			if ((Settings.HDMATimingHack <= 0) || (Settings.HDMATimingHack >= 200))
				Settings.HDMATimingHack = 100;

			cid.id = iNibMTurboSkipArrows;
			HIViewFindByID(root, cid, &ctl);
			macFastForwardRate = GetControl32BitValue(ctl);

			cid.id = iNibMFrameSkip;
			HIViewFindByID(root, cid, &ctl);
			macFrameSkip = GetControl32BitValue(ctl) - 2;

			cid.id = iNibMAllowInvalidVRAMAccess;
			HIViewFindByID(root, cid, &ctl);
			Settings.BlockInvalidVRAMAccessMaster = GetControl32BitValue(ctl) ? false : true;

			cid.id = iNibMAllowSpecificGameHacks;
			HIViewFindByID(root, cid, &ctl);
			Settings.DisableGameSpecificHacks = GetControl32BitValue(ctl) ? false : true;

			cid.signature = 'osx_';

			cid.id = iNibXStartOpenDialog;
			HIViewFindByID(root, cid, &ctl);
			startopendlog = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibXShowTimeInFrz;
			HIViewFindByID(root, cid, &ctl);
			showtimeinfrz = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibXMusicBoxMode;
			HIViewFindByID(root, cid, &ctl);
			musicboxmode = GetControl32BitValue(ctl);

			cid.id = iNibXEnableToggle;
			HIViewFindByID(root, cid, &ctl);
			enabletoggle = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibXSaveWindowPos;
			HIViewFindByID(root, cid, &ctl);
			savewindowpos = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibXUseIPSPatch;
			HIViewFindByID(root, cid, &ctl);
			Settings.NoPatch = GetControl32BitValue(ctl) ? false : true;

			cid.id = iNibXOnScreenInfo;
			HIViewFindByID(root, cid, &ctl);
			onscreeninfo = GetControl32BitValue(ctl) ? true : false;

			cid.id = iNibXInactiveMode;
			HIViewFindByID(root, cid, &ctl);
			inactiveMode = GetControl32BitValue(ctl);

			cid.id = iNibXBSXBootup;
			HIViewFindByID(root, cid, &ctl);
			Settings.BSXBootup = GetControl32BitValue(ctl) ? true : false;

			DisposeControlActionUPP(arrowsUPP);
			DisposeControlActionUPP(sliderUPP);

			err = RemoveEventHandler(pRef);
			DisposeEventHandlerUPP(pUPP);

			err = RemoveEventHandler(aRef);
			DisposeEventHandlerUPP(aUPP);

			err = RemoveEventHandler(iRef);
			DisposeEventHandlerUPP(iUPP);

			err = RemoveEventHandler(tRef);
			DisposeEventHandlerUPP(tUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);

		S9xGraphicsInit();

		if (((oldSynchronize   != Settings.SoundSync        ) ||
			 (old16BitPlayback != Settings.SixteenBitSound  ) ||
			 (oldStereo        != Settings.Stereo           ) ||
			 (oldReverseStereo != Settings.ReverseStereo    ) ||
			 (oldPlaybackRate  != Settings.SoundPlaybackRate) ||
			 (oldInputRate     != Settings.SoundInputRate   ) ||
			 (oldInterval      != macSoundInterval_ms       ) ||
			 (oldBufferSize    != macSoundBuffer_ms         ) ||
			 (oldLagEnable     != macSoundLagEnable         ) ||
			 (oldVolume        != macSoundVolume            )) && cartOpen)
			SNES9X_InitSound();

		if (!fullscreen && cartOpen)
		{
			InitGameWindow();
			ShowWindow(gWindow);
		}

		if (cartOpen)
		{
			FSRef	ref;

			err = FSPathMakeRef((unsigned char *) Memory.ROMFilename, &ref, NULL);
			if (err == noErr)
				CheckSaveFolder(&ref);
		}
	}
}
Beispiel #23
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);
}
Beispiel #24
0
void
create_driverchooser (HWND hwnd, TDRIVERCHOOSER * choose_t)
{
  EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit };
  RgnHandle cursorRgn = NULL;
  WindowRef wdrvchooser;
  ControlID controlID;
  EventRecord event;
  IBNibRef nibRef;
  OSStatus err;

  if (hwnd == NULL)
    return;

  /* Search the bundle for a .nib file named 'odbcadmin'. */
  err =
      CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (CFSTR
	("org.iodbc.adm")), CFSTR ("odbcdriver"), &nibRef);
  if (err == noErr)
    {
      /* Nib found ... so create the window */
      CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wdrvchooser);
      DisposeNibReference (nibRef);
      /* Set the control into the structure */
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCLIST_CNTL, wdrvchooser,
	  choose_t->driverlist);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCFINISH_CNTL, wdrvchooser,
	  choose_t->b_add);
      GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCCANCEL_CNTL, wdrvchooser,
          choose_t->b_remove);
      choose_t->driver = NULL;
      choose_t->mainwnd = wdrvchooser;
      /* Install handlers for the finish button, the cancel */
      InstallEventHandler (GetControlEventTarget (choose_t->b_add),
	  NewEventHandlerUPP (driverchooser_ok_clicked), 1, &controlSpec,
	  choose_t, NULL);
      InstallEventHandler (GetControlEventTarget (choose_t->b_remove),
	  NewEventHandlerUPP (driverchooser_cancel_clicked), 1, &controlSpec,
	  choose_t, NULL);
      Drivers_nrows = 0;
      adddrivers_to_list (choose_t->driverlist, choose_t->mainwnd, TRUE);

      /* Show the window and run the loop */
      choose_t->b_configure = NULL;
      DRIVERCHOOSER = choose_t;
      DeactivateControl (DRIVERCHOOSER->b_add);
      ShowWindow (wdrvchooser);

      /* The main loop */
      while (choose_t->mainwnd)
	WaitNextEvent (everyEvent, &event, 60L, cursorRgn);
    }
  else
    goto error;

  return;

error:
  choose_t->driver = NULL;
  fprintf (stderr, "Can't load Window. Err: %d\n", (int) err);
  return;
}
Beispiel #25
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);
	}
}
Beispiel #26
0
bool loadPlayerWin(bool bInitMetal)
{
    ControlID cID;
    ControlRef cRef, cRef2;
    IBNibRef nibFile;
    OSStatus iResult;
    EventTypeSpec pEvent;

    g_lpfnVolumeProc = NewControlActionUPP(playerVolHandler);
    g_lpfnPlayerProc = NewEventHandlerUPP(playerEvtHandler);

    if (noErr != (iResult = CreateNibReference(CFSTR("PlayerWin"), &nibFile)))
    {
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - CreateNibReference(PlayerWin) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    if (noErr != (iResult = CreateWindowFromNib(nibFile, CFSTR("FroggPlayerWindow"), &g_refPlayerWin)))
    {
        DisposeNibReference(nibFile);
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - CreateWindowFromNib(FroggPlayerWindow) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    DisposeNibReference(nibFile);

	if (bInitMetal)
	{
		if (noErr != (iResult = ChangeWindowAttributes(g_refPlayerWin, kWindowMetalAttribute, 0)))
		{
			DisposeWindow(g_refPlayerWin);
			DisposeEventHandlerUPP(g_lpfnPlayerProc);
			DisposeControlActionUPP(g_lpfnVolumeProc);
			fprintf(stderr, "loadPlayerWin() - ChangeWindowAttributes() failed, returning %lu!\n", (unsigned long) iResult);
			return false;
		}
	}

    pEvent.eventClass = kEventClassWindow;
    pEvent.eventKind = kEventWindowClose;

    if (noErr != (iResult = InstallWindowEventHandler(g_refPlayerWin, g_lpfnPlayerProc, 1, &pEvent, NULL, &g_refPlayerHdlr)))
    {
        DisposeWindow(g_refPlayerWin);
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - InstallWindowEventHandler() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    cID.signature = FOUR_CHAR_CODE('volu');
    cID.id = 6;
    if (noErr != (iResult = GetControlByID(g_refPlayerWin, &cID, &cRef)))
    {
        RemoveEventHandler(g_refPlayerHdlr);
        DisposeWindow(g_refPlayerWin);
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - GetControlByID() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    SetControlAction(cRef, g_lpfnVolumeProc);

    cID.signature = FOUR_CHAR_CODE('fpos');
    cID.id = 7;
    if (noErr != (iResult = GetControlByID(g_refPlayerWin, &cID, &cRef2)))
    {
        RemoveEventHandler(g_refPlayerHdlr);
        DisposeWindow(g_refPlayerWin);
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - GetControlByID() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    pEvent.eventClass = kEventClassControl;
    pEvent.eventKind = kEventControlClick;

    if (noErr != (iResult = InstallControlEventHandler(cRef2, g_lpfnPlayerProc, 1, &pEvent, NULL, &g_refSeekHdlr)))
    {
        SetControlAction(cRef, (ControlActionUPP) -1);
        RemoveEventHandler(g_refPlayerHdlr);
        DisposeWindow(g_refPlayerWin);
        DisposeEventHandlerUPP(g_lpfnPlayerProc);
        DisposeControlActionUPP(g_lpfnVolumeProc);
        fprintf(stderr, "loadPlayerWin() - InstallWindowEventHandler() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    setPlayerWinVolSlider(getSavedVolumePos());

    g_bLoaded = true;

    return true;
}