int init_macintosh( void)
{
	static int initdone = 0;
	Handle menuBar;
	long attributes;

	/* semaphore required for preemptive threads */
	if( initdone) return initdone == 1;
	initdone = -1;

	/* should I check for MLNK resource too as launch-filtering is done based on it? */
	/* too late--since I'm running there likely wasn't a problem (this time anyway). */
	
	menuBar = GetNewMBar(rMenuBar);
	if( menuBar){
		SetMenuBar(menuBar);
		DisposeHandle(menuBar);
	}else{
		MenuHandle am, fm, em;
		am = NewMenu( mApple, (unsigned char*)"\001\024");
		fm = NewMenu( mFile, (unsigned char*)"\004File");
		em = NewMenu( mEdit, (unsigned char*)"\004Edit");
		if( !am || !fm || !em) return 0;
		AppendMenu( am, (unsigned char*)"\022About MathLink\252\311;-");
                DisableMenuItem(am, 0);
		InsertMenu( am, 0);
		AppendMenu( fm, (unsigned char*)"\006Quit/Q");
		InsertMenu( fm, 0);
		AppendMenu( em, (unsigned char*)"\043Undo/Z;-;Cut/X;Copy/C;Paste/V;Clear");
                DisableMenuItem(em, 0);
		InsertMenu( em, 0);
	}

	AppendResMenu( GetMenuHandle(mApple), 'DRVR');
	set_about_item();
	DrawMenuBar();
	about_filter_upp =  NewModalFilterUPP( about_filter);
	outline_hook_upp = NewUserItemUPP( outline_hook);
	if( Gestalt( gestaltAppleEventsAttr, &attributes) == noErr
	&& ((1 << gestaltAppleEventsPresent) & attributes)){
		handle_core_ae_upp = NewAEEventHandlerUPP( handle_core_ae);
		(void) AEInstallEventHandler( kCoreEventClass, typeWildCard, handle_core_ae_upp, 0, false);
	}else{
		return 0; /* this may be too strong since I am, after all, running. */
	}

	initdone = 1;
	return initdone == 1;
}
示例#2
0
// --------------------------------------------------------------------------------------
void  OpenPrefsDialog(void)
{
	DialogRef dialog;
	WindowRef dialogWindow;
	ControlRef control;
	ListHandle iconList;
	Cell theCell;
	
	dialog = GetNewDialog(rPrefsDialogPlatinum, NULL, kFirstWindowOfClass);
	if (dialog == NULL)
		ExitToShell();
	SetPortDialogPort(dialog);
	dialogWindow = GetDialogWindow(dialog);
	
	SetDialogDefaultItem(dialog, kStdOkItemIndex);
	SetDialogCancelItem(dialog, kStdCancelItemIndex);
	
	GetDialogItemAsControl(dialog, iIconList, &control);
	GetControlData(control, kControlEntireControl, kControlListBoxListHandleTag, 
					sizeof(ListHandle), &iconList, NULL);
 	
	AddRowsAndDataToIconList(iconList, rIconListIconBaseID);
	(*iconList)->selFlags = lOnlyOne;
	
	SetPt(&theCell, 0, 0);
	LSetSelect(true, theCell, iconList);
	SetKeyboardFocus(dialogWindow, control, kControlFocusNextPart);
	gPanelNumber = 0;
		
	DisableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog);
	ShowWindow(dialogWindow);
} // OpenPrefsDialog
示例#3
0
/*****************************************************
*
* Handle_CommandUpdateStatus(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to update status of the commands, enabling or disabling the menu items
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*			inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_CommandUpdateStatus(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
	OSStatus status = eventNotHandledErr;
	
	HICommand aCommand;
	GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand);
	
	WindowRef aWindowRef = GetFrontWindowOfClass(kDocumentWindowClass, true);
		
	if (aWindowRef == NULL)
	{
		switch (aCommand.commandID)
		{
			case kHICommandClose:
				DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
		}
	}
	else
	{
		switch (aCommand.commandID)
		{
			case kHICommandClose:
				EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
		}
	}

	return status;
}   // Handle_CommandUpdateStatus
示例#4
0
文件: uma.cpp 项目: beanhome/dev
void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
{
    if ( enable )
        EnableMenuItem( inMenu , inItem ) ;
    else
        DisableMenuItem( inMenu , inItem ) ;
}
示例#5
0
/* ------- Miscellaneous Menu Commands -------------- */
void set_menu_enabled(
	short menu_id,
	short item,
	NMBoolean enabled)
{
#if defined(OP_PLATFORM_MAC_CFM) || defined(OP_PLATFORM_MAC_MACHO)
	MenuHandle menu= GetMenuHandle(menu_id);

#ifndef OP_PLATFORM_MAC_CARBON_FLAG
	if (enabled)
	{
		EnableItem(menu, item);
	} else {
		DisableItem(menu, item);
	}
#else
	if (enabled) {
		EnableMenuItem(menu, item);
	} else {
		DisableMenuItem(menu, item);
	}
#endif // OP_PLATFORM_MAC_CARBON_FLAG

#elif defined(OP_PLATFORM_WINDOWS)
	HMENU menu= GetMenu(screen_window);

	op_assert(menu);
	EnableMenuItem(menu, MAKE_MENU_COMMAND(menu_id, item), 
		enabled ? MF_ENABLED : MF_GRAYED);
#endif

	return;
}
示例#6
0
    void Enable( bool enable )
    {
        MenuItemIndex i = FindMenuItemIndex() ;
        if ( i > 0 )
        {

            if ( GetWXPeer()->GetId() == wxApp::s_macPreferencesMenuItemId)
            {
                if ( enable )
                    EnableMenuCommand( NULL , kHICommandPreferences ) ;
                else
                    DisableMenuCommand( NULL , kHICommandPreferences ) ;
            }
            else if ( GetWXPeer()->GetId() == wxApp::s_macExitMenuItemId)
            {
                if ( enable )
                    EnableMenuCommand( NULL , kHICommandQuit ) ;
                else
                    DisableMenuCommand( NULL , kHICommandQuit ) ;
            }

            if ( enable )
                EnableMenuItem(m_parentMenuRef , i);
            else
                DisableMenuItem(m_parentMenuRef , i);

            if ( GetWXPeer()->IsSubMenu() )
            {
                UMAEnableMenuItem( GetWXPeer()->GetSubMenu()->GetHMenu() , 0 , enable ) ;
            }
        }
    }
示例#7
0
void PopupMenu::enableItem(S32 pos, bool enable)
{
   pos++; // adjust torque -> mac menu index.
   if(enable)
      EnableMenuItem(mData->mMenu, pos);
   else
      DisableMenuItem(mData->mMenu, pos);
}
示例#8
0
int
TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
    HICommand	    command;
    int 	    menuContext;
    OSStatus	    status;

    switch (eventPtr->eKind) {
	case kEventCommandProcess:
	case kEventCommandUpdateStatus:
	    break;
	default:
	    return 0;
	    break;
    }
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamDirectObject,
	    typeHICommand, NULL, 
	    sizeof(command), NULL,
	    &command);
    if (status == noErr && (command.attributes & kHICommandFromMenu)) {
	if (eventPtr->eKind == kEventCommandProcess) {
	    status = GetEventParameter(eventPtr->eventRef, 
		    kEventParamMenuContext,
		    typeUInt32, NULL, 
		    sizeof(menuContext), NULL,
		    &menuContext);
	    if (status == noErr && (menuContext & kMenuContextMenuBar) &&
		    (menuContext & kMenuContextMenuBarTracking)) {
		TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
			command.menu.menuItemIndex,
			GetCurrentEventKeyModifiers() & optionKey);
		return 1;
	    }
	} else {
	    Tcl_CmdInfo dummy;
	    if (command.commandID == kHICommandPreferences && eventPtr->interp) {
		if (Tcl_GetCommandInfo(eventPtr->interp, 
			"::tk::mac::ShowPreferences", &dummy)) {
		    if (!IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			EnableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		} else {
		    if (IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			DisableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		}
		return 1;
	    }
	}
    }
    return 0;
}
示例#9
0
文件: Menus.c 项目: alx741/vexedit
/*** SMART ENABLE MENU ITEM ***/
static OSStatus _enableMenuItem( MenuRef menu, short item, short ok )
{
//	Code to simplify enabling/disabling menu items.
	if( ok )
		EnableMenuItem( menu, item );
	else
		DisableMenuItem( menu, item );

	if( item == 0 )
		DrawMenuBar();

	return noErr;
}
示例#10
0
// --------------------------------------------------------------------------------------
void ClosePrefsWindow(WindowRef prefsWindow)
{
    ListHandle iconList;

    HideWindow(prefsWindow);
    DisableMenuItem(GetMenuRef(mFile), iClose);

    GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);
    ReleaseIconListIcons(iconList);
    LDispose(iconList);
#if TARGET_API_MAC_CARBON
    DisposeListDefUPP(gIconListDef);
    DisposeEventHandlerUPP(gWindowEventHandler);
    DisposePrefsWindowHelpTags();
#endif
    DisposeWindow(prefsWindow);

    EnableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow);
}
示例#11
0
// --------------------------------------------------------------------------------------
void  HandleActivate(WindowRef window, Boolean activate)
{
    ControlRef rootControl;
    ListHandle iconList;
    SInt16 pixelDepth;
    Boolean isColorDevice;

    GetRootControl(window, &rootControl);
    GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList);

    SetPortWindowPort(window);
    GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice);

    if (activate)
    {
        SetThemeTextColor(kThemeTextColorModelessDialogActive, pixelDepth, isColorDevice);
        ActivateControl(rootControl);

        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        LActivate(true, iconList);
        RedrawPrefsWindowList(window);	// redraw the list with the active appearance
        drawFrameAndFocus(iconList, true, window);

        EnableMenuItem(GetMenuRef(mFile), iClose);
    }
    else	// deactivate
    {
        SetThemeTextColor(kThemeTextColorModelessDialogInactive, pixelDepth, isColorDevice);
        DeactivateControl(rootControl);

        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        LActivate(false, iconList);
        RedrawPrefsWindowList(window);	// redraw the  list with the inactive appearance
        drawFrameAndFocus(iconList, false, window);

        DisableMenuItem(GetMenuRef(mFile), iClose);
    }
}
EXPORT(sqInt) primitiveDisableMenuItem(void) {
	MenuHandle menuHandle;
	sqInt menuHandleOop;
	sqInt anInteger;
	sqInt _return_value;

	menuHandleOop = interpreterProxy->stackValue(1);
	anInteger = interpreterProxy->stackIntegerValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop)));
	if (!(ioCheckMenuHandle(menuHandle))) {
		_return_value = interpreterProxy->success(0);
		if (interpreterProxy->failed()) {
			return null;
		}
		interpreterProxy->popthenPush(3, _return_value);
		return null;
	}
	DisableMenuItem(menuHandle,anInteger);
	return null;
}
示例#13
0
// --------------------------------------------------------------------------------------
void  OpenPrefsDialog(void)
{
	ListDefSpec listSpec;
	DialogRef dialog;
	WindowRef dialogWindow;
	EventTypeSpec dialogEvents[] = {
									{kEventClassControl, kEventControlHit}
	                               };
	ControlID controlID = {kAppSignature, 0};
	ControlRef control;
	EventTypeSpec listBoxControlEvents[] = {
											{kEventClassTextInput, 
												kEventTextInputUnicodeForKeyEvent}
	                                       };
	ListHandle iconList;
	Cell theCell;
	
	listSpec.defType = kListDefUserProcType;
	listSpec.u.userProc = NewListDefUPP(IconListDef);	// this is automatically disposed 
														// when the program exits
	RegisterListDefinition(kIconListLDEF, &listSpec);
	
	dialog = GetNewDialog(rPrefsDialog, NULL, kFirstWindowOfClass);
	if (dialog == NULL)
		ExitToShell();
	SetPortDialogPort(dialog);
	dialogWindow = GetDialogWindow(dialog);
																// install window handlers
	ChangeWindowAttributes(dialogWindow, kWindowStandardHandlerAttribute, kWindowNoAttributes);
	gDialogEventHandler = NewEventHandlerUPP(dialogEventHandler);
	InstallWindowEventHandler(dialogWindow, gDialogEventHandler, 
								GetEventTypeCount(dialogEvents), dialogEvents, (void *)dialog, 
								NULL);
	
	GetDialogItemAsControl(dialog, kStdOkItemIndex, &control);		// set control IDs to 
	controlID.id = kStdOkItemIndex;									// match dialog item 
	SetControlID(control, &controlID);								// indices which are 
	SetWindowDefaultButton(dialogWindow, control);					// not tracked by any 
																	// standard handlers
	GetDialogItemAsControl(dialog, kStdCancelItemIndex, &control);	// also set the default 
	controlID.id = kStdCancelItemIndex;				// and cancel buttons (because Mac OS 8/9 
	SetControlID(control, &controlID);				// under CarbonLib doesn't respect the 
	SetWindowCancelButton(dialogWindow, control);	// dialog's default and cancel buttons)
	
	GetDialogItemAsControl(dialog, iIconList, &control);
	controlID.id = iIconList;
	SetControlID(control, &controlID);
		/* We need to postprocess keyboard events on the icon list so that we can change 
		   panels after the user changes the selected cell by using the keyboard. */
	gListBoxControlEventHandler = NewEventHandlerUPP(listBoxControlEventHandler);
	InstallControlEventHandler(control, gListBoxControlEventHandler, 
								GetEventTypeCount(listBoxControlEvents), listBoxControlEvents, 
								(void *)dialog, NULL);
	
	GetControlData(control, kControlEntireControl, kControlListBoxListHandleTag, 
					sizeof(ListHandle), &iconList, NULL);
 	
	AddRowsAndDataToIconList(iconList, rIconListIconBaseID);
	SetListSelectionFlags(iconList, lOnlyOne);
	
	SetPt(&theCell, 0, 0);
	LSetSelect(true, theCell, iconList);
	SetKeyboardFocus(dialogWindow, control, kControlFocusNextPart);
	gPanelNumber = 0;
	
	SetPrefsDialogHelpTags(dialog);
	
	DisableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog);
	ShowWindow(dialogWindow);
} // OpenPrefsDialog
示例#14
0
/*****************************************************
*
* Handle_CommandUpdateStatus(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to update status of the commands, enabling or disabling the menu items
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*				inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_CommandUpdateStatus(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status = eventNotHandledErr;
	
	HICommand aCommand;
	GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand);
	
	// Do we have a front window containing a HIATSUIView?
	WindowRef frontWindow;
	HIViewRef atsuiView;
	Get_FrontWindowAndATSUIView(&frontWindow, &atsuiView, false);
	
	// Do we have some selected text?
	Boolean textSelected = false;
	if (atsuiView != NULL)
		{
		UniCharArrayOffset start, end;
		HIATSUIViewGetSelection(atsuiView, &start, &end);
		textSelected = (start != end);
		}

	if (frontWindow == NULL)
		{
		// no window, let's disable all relevant menu items
		switch (aCommand.commandID)
			{
			case kHICommandSelectAll:
			case kHICommandCopy:
			case kHICommandClose:
				DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			}
		}
	else
		{
		switch (aCommand.commandID)
			{
			// the "Copy" menu item is enabled only is some text is selected
			case kHICommandCopy:
				if (textSelected)
					EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				else
					DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			
			// the "Select All" menu item is enabled only if there is a HIATSUIView in the front window
			case kHICommandSelectAll:
				if (atsuiView != NULL)
					EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				else
					DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			
			// the "Close" menu item is enabled only if there is a window
			case kHICommandClose:
				EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			}
		}
	
	// let's adjust the "Show/Hide Fonts" menu item title depending on the visibility of the Standard Font panel
	if (aCommand.commandID == kHICommandShowHideFontPanel)
		{
		CFStringRef menuItemString;
		if (FPIsFontPanelVisible())
			menuItemString = CFCopyLocalizedString( CFSTR("Hide Fonts"), CFSTR("") );
		else
			menuItemString = CFCopyLocalizedString( CFSTR("Show Fonts"), CFSTR("") );
		SetMenuItemTextWithCFString(aCommand.menu.menuRef, aCommand.menu.menuItemIndex, menuItemString);
		CFRelease(menuItemString);
		}

	return status;
	}   // Handle_CommandUpdateStatus
	/* YASTControlCarbonEventHandler defines the main entry point for all
	of the carbon event handlers installed for the YASTControl. */
static pascal OSStatus YASTControlCarbonEventHandler(
									EventHandlerCallRef myHandler,
									EventRef event,
									void* userData) {
	#pragma unused ( myHandler )
    OSStatus err, returnedResult;
	YASTControlVarsPtr varsp;
	UInt32 eclass, ekind;
		/* set up locals */
	eclass = GetEventClass(event);
	ekind = GetEventKind(event);
	varsp = (YASTControlVarsPtr) userData;
	returnedResult = eventNotHandledErr;
		/* dispatch the event by class*/
	switch (eclass) {
	
		case kEventClassWindow:
			if ( ekind == kEventWindowCursorChange ) {
				Point where;
				UInt32 modifiers;
				Boolean cursorWasSet;
					/* get the mouse position */
				err = GetEventParameter( event, kEventParamMouseLocation, 
						typeQDPoint,  NULL, sizeof(where), NULL, &where);
				if (err == noErr) {
					err = GetEventParameter( event, kEventParamKeyModifiers, 
							typeUInt32,  NULL, sizeof(modifiers), NULL, &modifiers);
					if (err == noErr) {
						SetPort(varsp->fGrafPtr);
						GlobalToLocal(&where);
						if (PtInRect(where, &varsp->fRBounds)) {
							err = HandleControlSetCursor( varsp->fControl, where, modifiers, &cursorWasSet);
							if (err != noErr) cursorWasSet = false;
							if ( ! cursorWasSet ) InitCursor();
							returnedResult = noErr;
						}
					}
				}
			}
			break;
	
		case kEventClassMouse:
				/* handle mouse downs in the control, but only if the
				control is in focus. */
			if ( ekind == kEventMouseDown ) {
				EventRecord outEvent;
				if ( varsp->fInFocus ) {
					if (ConvertEventRefToEventRecord( event, &outEvent)) {
						TXNClick( varsp->fTXNObject,  &outEvent);
					}
					returnedResult = noErr;
				}
			}
			break;

		case kEventClassTextInput:
			if ( ekind == kEventUnicodeForKeyEvent
			&& varsp->fTabMovesFocus) {
				UniChar mUnicodeText[8];
				UInt32 bytecount, nchars;
					/* get the character */
				err = GetEventParameter(event, kEventParamTextInputSendText, 
							typeUnicodeText, NULL, sizeof(mUnicodeText),
							&bytecount, (char*) mUnicodeText);
				if ((err == noErr)
				&& (bytecount >= sizeof(UniChar))) {
					nchars = ( bytecount / sizeof(UniChar) );
						/* if it's not the tab key, forget it... */
					if ( mUnicodeText[0] == '\t' ) {
						EventRef rawKeyEvent;
						Boolean shiftDown;
							/* is the shift key held down? */
						shiftDown = false;
						err = GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, 
									typeEventRef, NULL, sizeof(rawKeyEvent), NULL, &rawKeyEvent);
						if (err == noErr) {
							UInt32 modifiers;
							err = GetEventParameter(rawKeyEvent, kEventParamKeyModifiers, 
									typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
							if (err == noErr) {
								shiftDown = ( (modifiers & shiftKey) != 0 );
							}
						}
							/* advance the keyboard focus, backwards if shift is down */
						if (shiftDown)
							ReverseKeyboardFocus( varsp->fWindow );
						else AdvanceKeyboardFocus( varsp->fWindow );
							/* noErr lets the CEM know we handled the event */
						returnedResult = noErr;
					}
				}
			}
			break;

		case kEventClassControl:
			switch (ekind) {

				case kEventControlSetFocusPart:
					{	ControlPartCode thePart;
						err = GetEventParameter(event, kEventParamControlPart, 
							typeControlPartCode, NULL, sizeof(thePart), NULL, &thePart);
						if (err == noErr) {
							switch (thePart) {
								default:
								case kControlFocusNoPart: /* turn off focus */
									if ( varsp->fInFocus ) {
										TXNFocus( varsp->fTXNObject, false);
										varsp->fInFocus = false;
									}
									thePart = kControlFocusNoPart;
									break;
								case kYASTControlOnlyPart: /* turn on focus */
									if ( !  varsp->fInFocus ) {
										TXNFocus( varsp->fTXNObject, true);
										varsp->fInFocus = true;
									}
									thePart = kYASTControlOnlyPart;
									break;
								case kControlFocusPrevPart: /* toggle focus on/off */
								case kControlFocusNextPart:
									varsp->fInFocus = ! varsp->fInFocus;
									TXNFocus( varsp->fTXNObject, varsp->fInFocus);
									thePart = (varsp->fInFocus ? kYASTControlOnlyPart : kControlFocusNoPart);
									break;
							}
							SetPort(varsp->fGrafPtr);
								/* calculate the next highlight state */
							SetTextActivation(varsp, varsp->fIsActive && varsp->fInFocus);
								/* redraw the text fram and focus rectangle to indicate the
								new focus state */
							DrawThemeEditTextFrame(&varsp->fRTextOutline,
								varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
							RedrawFocusOutline(varsp);
						}
							/* pass back the foocus part code */
						err = SetEventParameter( event, kEventParamControlPart,
								typeControlPartCode, sizeof(thePart), &thePart);
						returnedResult = err;
					}
					break;

				case kEventControlHitTest:
						/* this event does not necessairly mean that a mouse click
						has occured.  Here we are simply testing to see if a particular
						point is located inside of the control.  More complicated controls
						would return different part codes for different parts of
						themselves;  but, since YASTControls only advertise one part, the
						hit test here is more or less a boolean test. */
					{	ControlPartCode thePart;
						Point where;
						err = GetEventParameter(event, kEventParamMouseLocation, 
							typeQDPoint, NULL, sizeof(where), NULL, &where);
						if (err == noErr) {
							if (PtInRect(where, &varsp->fRTextArea)) {
								thePart = kYASTControlOnlyPart;
							} else thePart = 0;
							err = SetEventParameter( event, kEventParamControlPart,
										typeControlPartCode, sizeof(thePart), &thePart);
						}
						returnedResult = err;
					}
					break;

				case kEventControlClick:
						/* here we handle focus switching on the control.  Actual tracking
						of mouse down events in the control is performed in the kEventClassMouse
						mouse down handler above. */
					if ( ! varsp->fInFocus ) {
						SetKeyboardFocus(varsp->fWindow, varsp->fControl, kYASTControlOnlyPart);
						returnedResult = noErr;
					}
					break;
					
				case kEventControlBoundsChanged:
						/* we moved, or switched size - recalculate our rectangles */
					{	Rect bounds;
						err = GetEventParameter(event, kEventParamCurrentBounds, 
							typeQDRectangle, NULL, sizeof(bounds), NULL, &bounds);
						if (err == noErr) {
							YASTControlCalculateBounds(varsp, &bounds);
							TXNSetFrameBounds( varsp->fTXNObject,
								varsp->fRTextArea.top, varsp->fRTextArea.left,
								varsp->fRTextArea.bottom, varsp->fRTextArea.right,
								varsp->fTXNFrameID);
						}
					}
					break;
						
				case kEventControlActivate:
				case kEventControlDeactivate:
					{	SetPort(varsp->fGrafPtr);
						varsp->fIsActive = (ekind == kEventControlActivate);
						SetTextActivation(varsp, varsp->fIsActive && varsp->fInFocus);
							/* redraw the frame */
						DrawThemeEditTextFrame(&varsp->fRTextOutline,
							varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
						RedrawFocusOutline(varsp);
						returnedResult = noErr;
					}
					break;
					
				case kEventControlDraw:
						/* redraw the control */
					SetPort(varsp->fGrafPtr);
						/* update the text region */
					TXNDraw(varsp->fTXNObject, NULL);
						/* restore the drawing environment */
						/* draw the text frame and focus frame (if necessary) */
					DrawThemeEditTextFrame(&varsp->fRTextOutline,
						varsp->fIsActive ? kThemeStateActive: kThemeStateInactive);
					RedrawFocusOutline(varsp);
					returnedResult = noErr;
					break;
					
				case kEventControlSetCursor:
						/* cursor adjustment */
					{	SetPortWindowPort(varsp->fWindow);
						TXNAdjustCursor( varsp->fTXNObject, varsp->fRTextOutlineRegion);
						returnedResult = noErr;
					}
					break;
					
				case kEventControlDispose:
						/* RemoveEventHandler(varsp->fControlEvents); -- this call has been
						left out on purpose because it will be called automatically when the
						control is disposed. */
					RemoveEventHandler(varsp->fWindowEvents);
					TXNDeleteObject(varsp->fTXNObject);
					DisposeRgn(varsp->fRTextOutlineRegion);
					free(varsp);
						/* returnedResult = noErr; -- this has been left out on purpose
						because we want the dispatching to continue and dispose of the control */
					break;
					
				case kEventControlSetData:
					{	ResType inTagName;
						Size inBufferSize;
						void * inBuffer;
						err = GetEventParameter( event, kEventParamControlDataTag, typeEnumeration, 
							NULL, sizeof(inTagName), NULL, &inTagName);
						if (err == noErr) {
							err = GetEventParameter( event, kEventParamControlDataBuffer, typePtr, 
								NULL, sizeof(inBuffer), NULL, &inBuffer);
							if (err == noErr) {
								err = GetEventParameter( event, kEventParamControlDataBufferSize, typeLongInteger, 
									NULL, sizeof(inBufferSize), NULL, &inBufferSize);
								if (err == noErr) {
									err = YASTControlSetData(varsp, inTagName, inBuffer, inBufferSize);
								}
							}
						}
						returnedResult = err;
					}
					break;
					
				case kEventControlGetData:
					{	ResType inTagName;
						Size inBufferSize, outBufferSize;
						void * inBuffer;
						err = GetEventParameter( event, kEventParamControlDataTag, typeEnumeration, 
							NULL, sizeof(inTagName), NULL, &inTagName);
						if (err == noErr) {
							err = GetEventParameter( event, kEventParamControlDataBuffer, typePtr, 
								NULL, sizeof(inBuffer), NULL, &inBuffer);
							if (err == noErr) {
								err = GetEventParameter( event, kEventParamControlDataBufferSize, typeLongInteger, 
									NULL, sizeof(inBufferSize), NULL, &inBufferSize);
								if (err == noErr) {
									err = YASTControlGetData(varsp, inTagName, inBuffer, inBufferSize, &outBufferSize);
									if (err == noErr) {
										err = SetEventParameter( event, kEventParamControlDataBufferSize,
													typeLongInteger, sizeof(outBufferSize), &outBufferSize);
									}
								}
							}
						}
						returnedResult = err;
					}
					break;
					
			}
			break;
		case kEventClassCommand:
			if ( ekind == kEventProcessCommand ) {
				HICommand command;
				err = GetEventParameter( event, kEventParamDirectObject,
										typeHICommand, NULL, sizeof(command), NULL, &command);
				if (err == noErr) {
					switch (command.commandID) {
						case kHICommandUndo:
							TXNUndo(varsp->fTXNObject);
							returnedResult = noErr;
							break;
						case kHICommandRedo:
							TXNRedo(varsp->fTXNObject);
							returnedResult = noErr;
							break;
						case kHICommandCut:
							ClearCurrentScrap();
							err = TXNCut(varsp->fTXNObject); 
							if (err == noErr)
								err = TXNConvertToPublicScrap();
							returnedResult = err;
							break;
						case kHICommandCopy:
							ClearCurrentScrap();
							err = TXNCopy(varsp->fTXNObject);
							if (err == noErr)
								err = TXNConvertToPublicScrap();
							returnedResult = err;
							break;
						case kHICommandPaste:
							err = TXNConvertFromPublicScrap();
							if (err == noErr)
								err = TXNPaste(varsp->fTXNObject);
							returnedResult = err;
							break;
						case kHICommandClear:
							err = TXNClear(varsp->fTXNObject);
							returnedResult = err;
							break;
						case kHICommandSelectAll:
							err = TXNSetSelection(varsp->fTXNObject, kTXNStartOffset, kTXNEndOffset);
							returnedResult = err;
							break;
					}
				}
			} else if ( ekind == kEventCommandUpdateStatus ) {
				HICommand command;
				TXNOffset oStartOffset, oEndOffset;
				TXNActionKey oActionKey;

				err = GetEventParameter( event, kEventParamDirectObject, typeHICommand, 
										NULL, sizeof(command), NULL, &command);
				
				if ((err == noErr)
				&& ((command.attributes & kHICommandFromMenu) != 0)) {
					switch (command.commandID) {
						case kHICommandUndo:
							if (TXNCanUndo(varsp->fTXNObject, &oActionKey)) {
								EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */
								EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							} else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							returnedResult = noErr;
							break;
						case kHICommandRedo:
							if (TXNCanRedo(varsp->fTXNObject, &oActionKey)) {
								EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */
								EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							} else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							returnedResult = noErr;
							break;
						case kHICommandCut:
						case kHICommandCopy:
						case kHICommandClear:
							TXNGetSelection(varsp->fTXNObject, &oStartOffset, &oEndOffset);
							if (oStartOffset != oEndOffset) {
								EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */
								EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							} else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							returnedResult = noErr;
							break;
						case kHICommandPaste:
							if (TXNIsScrapPastable()) {
								EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */
								EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							} else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							returnedResult = noErr;
							break;
						case kHICommandSelectAll:
							if(TXNDataSize(varsp->fTXNObject) > 0) {
								EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */
								EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							} else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex);
							returnedResult = noErr;
							break;
					}
				}
			}
			break;
	}
    return returnedResult;
}
示例#16
0
文件: tkMacOSXMenus.c 项目: das/tcltk
void
TkMacOSXInitMenus(
    Tcl_Interp *interp)
{
    OSStatus err;
    EventHandlerUPP menuEventHandlerUPP;
    const EventTypeSpec menuEventTypes[] = {
	{kEventClassMenu, kEventMenuEnableItems},
    };

    gInterp = interp;
    if (TkMacOSXUseMenuID(kAppleMenu) != TCL_OK) {
	Tcl_Panic("Menu ID %d is already in use!", kAppleMenu);
    }
    err = ChkErr(CreateNewMenu, kAppleMenu, kMenuAttrDoNotUseUserCommandKeys,
	    &tkAppleMenu);
    if (err != noErr) {
	Tcl_Panic("CreateNewMenu failed !");
    }
    SetMenuTitle(tkAppleMenu, "\p\024");
    InsertMenu(tkAppleMenu, 0);
    AppendMenu(tkAppleMenu, "\pAbout Tcl & Tk\xc9");
    AppendMenu(tkAppleMenu, "\p(-");

    if (TkMacOSXUseMenuID(kFileMenu) != TCL_OK) {
	Tcl_Panic("Menu ID %d is already in use!", kFileMenu);
    }
    err = ChkErr(CreateNewMenu, kFileMenu, kMenuAttrDoNotUseUserCommandKeys,
	    &tkFileMenu);
    if (err != noErr) {
	Tcl_Panic("CreateNewMenu failed !");
    }
    SetMenuTitle(tkFileMenu, "\pFile");
    InsertMenu(tkFileMenu, 0);
    InsertMenuItem(tkFileMenu, "\pSource\xc9", kSourceItem - 1);
    InsertMenuItem(tkFileMenu, "\pRun Widget Demo", kDemoItem - 1);
    InsertMenuItem(tkFileMenu, "\pClose/W", kCloseItem - 1);
    DisableMenuItem(tkFileMenu, kDemoItem);
    menuEventHandlerUPP = NewEventHandlerUPP(MenuEventHandlerProc);
    ChkErr(InstallEventHandler, GetMenuEventTarget(tkFileMenu),
	    menuEventHandlerUPP, GetEventTypeCount(menuEventTypes),
	    menuEventTypes, NULL, &menuEventHandlerRef);
    DisposeEventHandlerUPP(menuEventHandlerUPP);

    if (TkMacOSXUseMenuID(kEditMenu) != TCL_OK) {
	Tcl_Panic("Menu ID %d is already in use!", kEditMenu);
    }
    err = ChkErr(CreateNewMenu, kEditMenu, kMenuAttrDoNotUseUserCommandKeys,
	    &tkEditMenu);
    if (err != noErr) {
	Tcl_Panic("CreateNewMenu failed !");
    }
    SetMenuTitle(tkEditMenu, "\pEdit");
    InsertMenu(tkEditMenu, 0);
    AppendMenu(tkEditMenu, "\pCut/X");
    AppendMenu(tkEditMenu, "\pCopy/C");
    AppendMenu(tkEditMenu, "\pPaste/V");
    AppendMenu(tkEditMenu, "\pClear");
    if (TkMacOSXUseMenuID(kHMHelpMenuID) != TCL_OK) {
	Tcl_Panic("Help menu ID %s is already in use!", kHMHelpMenuID);
    }

    /*
     * Workaround a Carbon bug with kHICommandPreferences: the first call to
     * IsMenuKeyEvent returns false for the preferences menu item key shorcut
     * event (even if the corresponding menu item is dynamically enabled by a
     * kEventCommandUpdateStatus handler), unless the kHICommandPreferences
     * menu item has previously been enabled manually. [Bug 1481503]
     */

    EnableMenuCommand(NULL, kHICommandPreferences);

    DrawMenuBar();
    return;
}
示例#17
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);
		}
	}
}
示例#18
0
static pascal OSStatus PreferencesEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	OSStatus	err, result = eventNotHandledErr;
	WindowRef	tWindowRef = (WindowRef) inUserData;

	switch (GetEventClass(inEvent))
	{
		case kEventClassWindow:
		{
			switch (GetEventKind(inEvent))
			{
				case kEventWindowClose:
				{
					QuitAppModalLoopForWindow(tWindowRef);
					result = noErr;
					break;
				}
			}

			break;
		}

		case kEventClassCommand:
		{
			switch (GetEventKind(inEvent))
			{
				HICommand	tHICommand;

				case kEventCommandUpdateStatus:
				{
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
					if (err == noErr && tHICommand.commandID == 'clos')
					{
						UpdateMenuCommandStatus(true);
						result = noErr;
					}

					break;
				}

				case kEventCommandProcess:
				{
					HIViewRef	ctl, root;
					HIViewID	cid;
					SInt32		value;
					FSRef		ref;
					bool8		r;

					root = HIViewGetRoot(tWindowRef);

					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
					if (err == noErr)
					{
						switch (tHICommand.commandID)
						{
							case 'S_EF':
							{
								HideWindow(tWindowRef);
								ConfigureSoundEffects();
								ShowWindow(tWindowRef);

								result = noErr;
								break;
							}

							case 'G_FL':
							{
								if (systemVersion >= 0x1040)
								{
									HideWindow(tWindowRef);
									ConfigureCoreImageFilter();
									ShowWindow(tWindowRef);
								}

								result = noErr;
								break;
							}

							case 'G__7':
							{
								cid.signature = 'grap';
								cid.id = iNibGGLStretch;
								HIViewFindByID(root, cid, &ctl);
								value = GetControl32BitValue(ctl);

								cid.id = iNibGAspectRatio;
								HIViewFindByID(root, cid, &ctl);
								if (value)
									ActivateControl(ctl);
								else
									DeactivateControl(ctl);

								result = noErr;
								break;
							}

							case 'G_13':
							{
								cid.signature = 'grap';
								cid.id = iNibGScreenCurvature;
								HIViewFindByID(root, cid, &ctl);
								value = GetControl32BitValue(ctl);

								cid.id = iNibGCurvatureWarp;
								HIViewFindByID(root, cid, &ctl);
								if (value)
									ActivateControl(ctl);
								else
									DeactivateControl(ctl);

								result = noErr;
								break;
							}

							case 'S__3':
							{
								cid.signature = 'snd_';
								cid.id = iNibSStereo;
								HIViewFindByID(root, cid, &ctl);
								value = GetControl32BitValue(ctl);

								cid.id = iNibSReverseStereo;
								HIViewFindByID(root, cid, &ctl);
								if (value)
									ActivateControl(ctl);
								else
									DeactivateControl(ctl);

								result = noErr;
								break;
							}

							case 'F_FL':
							{
								UInt32	modifierkey;

								err = GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifierkey);
								if (err == noErr)
								{
									if (modifierkey & optionKey)
									{
										CFStringRef	str;
										MenuRef		menu;

										str = CFCopyLocalizedString(CFSTR("NoneSelected"), "NoneSelected");

										cid.signature = 'othe';
										cid.id = iNibOSaveFolder;
										HIViewFindByID(root, cid, &ctl);
										SetControl32BitValue(ctl, 3);
										err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL);
										err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, str);
										DisableMenuItem(menu, iNibSaveFolderNameMenuItem);
										HIViewSetNeedsDisplay(ctl, true);

										CFRelease(str);

										if (saveFolderPath)
											CFRelease(saveFolderPath);
										saveFolderPath = NULL;
									}
									else
										r = NavBeginChooseFolderSheet(tWindowRef);
								}

								result = noErr;
								break;
							}

							case 'NvDn':
							{
								r = NavEndChooseFolderSheet(&ref);
								if (r)
								{
									CFStringRef	str;
									CFURLRef	url;
									MenuRef		menu;

									url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref);
									str = CFURLCopyLastPathComponent(url);

									cid.signature = 'othe';
									cid.id = iNibOSaveFolder;
									HIViewFindByID(root, cid, &ctl);
									SetControl32BitValue(ctl, iNibSaveFolderNameMenuItem);
									err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL);
									err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, str);
									EnableMenuItem(menu, iNibSaveFolderNameMenuItem);
									HIViewSetNeedsDisplay(ctl, true);

									CFRelease(str);

									str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
									if (saveFolderPath)
										CFRelease(saveFolderPath);
									saveFolderPath = str;

									CFRelease(url);
								}

								result = noErr;
								break;
							}
						}
					}

					break;
				}
			}

			break;
		}
	}

	return (result);
}
示例#19
0
// --------------------------------------------------------------------------------------
void OpenPrefsWindow(void)
{
    OSStatus error;
    SInt16 windowResourceID, visibleUserPaneResourceID, invisibleUserPaneResourceID, pixelDepth;
    WindowRef window;
    ControlRef containerControl, embeddedControl;
    short iconListBottom;
    Rect iconListRect;
    Boolean isColorDevice;
    ListHandle iconList;
    EventTypeSpec windowEvents[] = {
        {kEventClassWindow, kEventWindowActivated},
        {kEventClassWindow, kEventWindowDeactivated},
        {kEventClassWindow, kEventWindowHandleContentClick},
        {kEventClassWindow, kEventWindowGetMinimumSize},
        {kEventClassWindow, kEventWindowResizeCompleted},
        {kEventClassWindow, kEventWindowClose},
        {kEventClassWindow, kEventWindowDrawContent},
        {kEventClassWindow, kEventWindowContextualMenuSelect},
        {kEventClassControl, kEventControlClick},
        {kEventClassMouse, kEventMouseWheelMoved},
        {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}
    };

    if (!RunningInMacOSX())
    {
        windowResourceID = rPrefsWindowPlatinum;
        visibleUserPaneResourceID = cPlatinumWindowUserPaneVisible;
        invisibleUserPaneResourceID = cPlatinumWindowUserPaneInvisible;

        gPrefsWindowHeight = kPrefsWindowPlatinumHeight;
        gPrefsWindowWidth = kPrefsWindowPlatinumWidth;
        gMinimumSpacing = kPlatinumMinimumSpacing;
        gWindowEdgeSpacing = kPlatinumWindowEdgeSpacing;
    }
    else
    {
        windowResourceID = rPrefsWindowAqua;
        visibleUserPaneResourceID = cAquaWindowUserPaneVisible;
        invisibleUserPaneResourceID = cAquaWindowUserPaneInvisible;

        gPrefsWindowHeight = kPrefsWindowAquaHeight;
        gPrefsWindowWidth = kPrefsWindowAquaWidth;
        gMinimumSpacing = kAquaMinimumSpacing;
        gWindowEdgeSpacing = kAquaWindowEdgeSpacing;
    }

    error = CreateWindowFromResource(windowResourceID, &window);
    if (error != noErr)
        ExitToShell();
    RepositionWindow(window, NULL, kWindowCascadeOnMainScreen);		// CreateWindowFromResource
    // doesn't call this for you like GetNewCWindow does
#if TARGET_API_MAC_CARBON	// we would just set the standard handler attribute in the Carbon 
    // Platinum 'wind' resource but that makes it not work under CarbonLib for some reason
    ChangeWindowAttributes(window, kWindowStandardHandlerAttribute, kWindowNoAttributes);
#endif

    SetPortWindowPort(window);

    SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundActive, true);

    CreateRootControl(window, &containerControl);

    /* Get each user pane and embed each preference panel's controls (for the
       demonstration there is only some static text identifying each panel number).
       We could just as easily have used AutoEmbedControl but why make the system
       figure out which control to use as the embedder when we already know? */
    containerControl = GetNewControl(visibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 1");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 2");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 3");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 4");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 5");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 6");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 7");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 8");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 9");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 8,
                   "Panel 10");

    gPanelNumber = 1;

    GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice);	// draw the list with a
    SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);	// white background
    // get the bottom-most
    iconListBottom = gPrefsWindowHeight - gWindowEdgeSpacing;	// coordinate we can use
    iconListBottom -= (gPrefsWindowHeight - gWindowEdgeSpacing - gWindowEdgeSpacing) %
                      kCellHeight;	// then subtract out the partial cell height that would
    // be drawn on the bottom so that it's not actually drawn
    SetRect(&iconListRect, gWindowEdgeSpacing, gWindowEdgeSpacing,
            gWindowEdgeSpacing + kListWidth, iconListBottom);
    iconList = createIconList(window, iconListRect);
    SetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), &iconList);

#if TARGET_API_MAC_OS8
    CalculateBalloonHelpRects(window);
#else
    gWindowEventHandler = NewEventHandlerUPP(windowEventHandler);
    InstallWindowEventHandler(window, gWindowEventHandler, GetEventTypeCount(windowEvents),
                              windowEvents, NULL, NULL);
    InstallPrefsWindowHelpTags(window);
#endif

    DisableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow);
    EnableMenuItem(GetMenuRef(mFile), iClose);

    ShowWindow(window);
} // OpenPrefsWindow