Ejemplo n.º 1
0
void palette_scenery_open(int x,int y)
{
	ControlID				ctrl_id;
	EventHandlerUPP			tab_event_upp;
	EventTypeSpec			tab_event_list[]={{kEventClassControl,kEventControlHit},
											  {kEventClassKeyboard,kEventRawKeyUp}};

		// open the window
		
	dialog_open(&palette_scenery_wind,"SceneryPalette");
	MoveWindow(palette_scenery_wind,x,y,FALSE);
	
		// setup the tabs
		
	dialog_set_tab(palette_scenery_wind,kSceneryTab,0,0,kSceneryTabCount);

	ctrl_id.signature=kSceneryTab;
	ctrl_id.id=0;
	GetControlByID(palette_scenery_wind,&ctrl_id,&palette_scenery_tab);
	
	tab_event_upp=NewEventHandlerUPP(palette_scenery_tab_proc);
	InstallControlEventHandler(palette_scenery_tab,tab_event_upp,GetEventTypeCount(tab_event_list),tab_event_list,palette_scenery_wind,NULL);

		// show palette
		
	ShowWindow(palette_scenery_wind);
}
Ejemplo n.º 2
0
static void HandleStartEvent(NavCBRecPtr callBackParms, CustomData *data)
{
   data->context = callBackParms->context;

   CreateUserPaneControl(callBackParms->window, &data->bounds, kControlSupportsEmbedding, &data->userpane);

   InstallControlEventHandler(data->userpane,
                              GetHandlePaneEventsUPP(),
                              GetEventTypeCount(namedAttrsList),
                              namedAttrsList,
                              data,
                              NULL);

   EmbedControl(data->choice, data->userpane);
   EmbedControl(data->button, data->userpane);
   
   NavCustomControl(callBackParms->context, kNavCtlAddControl, data->userpane);
   
   HandleAdjustRect(callBackParms, data);
   
   if (data && !(data->defaultLocation).IsEmpty())
   {
      // Set default location for the modern Navigation APIs
      // Apple Technical Q&A 1151
      FSSpec theFSSpec;
      wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec);
      AEDesc theLocation = {typeNull, NULL};
      if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
         ::NavCustomControl(callBackParms->context, kNavCtlSetLocation, (void *) &theLocation);
   }
}
Ejemplo n.º 3
0
static void makeNibWindow (IBNibRef nibRef) {
    OSStatus	err;
    short		i,j,l,k;
    EventHandlerRef	ref;
    ControlRef	targetCon[11], cref[3];
    
    err = CreateWindowFromNib(nibRef, CFSTR("SoundDialog"), &soundWin);
    if (err == noErr) {
    
        initSoundWindow();
        SetInitialTabState(soundWin, lastPaneSelected, kMaxNumTabs);
        
        EventTypeSpec	tabControlEvents[] ={ { kEventClassControl, kEventControlHit }};
        InstallControlEventHandler( getControlRefByID(kTabMasterSig,kTabMasterID,soundWin),  PrefsTabEventHandlerProc , GetEventTypeCount(tabControlEvents), tabControlEvents, soundWin, NULL );

        EventTypeSpec	sliderControlEvents[] ={
            { kEventClassControl, kEventControlDraw },
            { kEventClassControl, kEventControlValueFieldChanged }
        };
        for (i=0;i<5;i++) {
            targetCon[i] = getControlRefByID('vMix',i,soundWin);
        }
        for (j=0;j<6;j++) {
            targetCon[j+5] = getControlRefByID('vMix',10+j,soundWin);
        }
        for (l=0;l<11;l++) {
            InstallControlEventHandler( targetCon[l],  sliderEventHandlerProc , GetEventTypeCount(sliderControlEvents), sliderControlEvents, (void *)targetCon[l], NULL );
        }

        EventTypeSpec	list[]={ { kEventClassCommand, kEventCommandProcess },};
        InstallWindowEventHandler (soundWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)soundWin, &ref);
		
        EventTypeSpec	ctrllist[]={ { kEventClassControl, kEventControlClick } };
        for (k=0;k<3;k++) {
			cref[k] = getControlRefByID('BMP ', k, soundWin);
		}
		InstallControlEventHandler(cref[0], NewEventHandlerUPP(s26proc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[0], NULL);   
		InstallControlEventHandler(cref[1], NewEventHandlerUPP(s86proc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[1], NULL);   
		InstallControlEventHandler(cref[2], NewEventHandlerUPP(spbproc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref[2], NULL);   
		
        ShowSheetWindow(soundWin, hWndMain);
        
        err=RunAppModalLoopForWindow(soundWin);
    }
    return;
}
Ejemplo n.º 4
0
/*
	Handle the initialization event for a star-shaped frame.  This routine
	creates the content view, installs its event handler, and sets its
	initial location.
*/
OSStatus HandleStarFrameInitialize(
	EventHandlerCallRef inCallRef,
	EventRef inEvent,
	StarFrameData *frameData)
{
	OSStatus retVal = eventNotHandledErr;
	HIViewRef contentView;

	// The frame view must support embedding
	HIViewChangeFeatures(frameData->hiSelf, kHIViewAllowsSubviews, kHIViewIsOpaque);

	// Create the content view for the frame.
	retVal = HIObjectCreate(kHIViewClassID, NULL, (HIObjectRef *)&contentView);
	if(noErr == retVal && NULL != contentView) {
		HIViewChangeFeatures(contentView, kHIViewAllowsSubviews, kHIViewIsOpaque);
		SetControlID(contentView, &kHIViewWindowContentID);

		// content view must be visible.
		verify_noerr(HIViewSetVisible(contentView, true));

		// Make sure the content view is handling events
		verify_noerr(InstallControlEventHandler(
								contentView,
								gContentViewHandlerUPP,
								GetEventTypeCount(gContentViewHandledEvents),
								gContentViewHandledEvents,
								NULL,
								NULL));

		// set the location of the content view appropriately
		PositionContentViewWithMetrics(frameData->hiSelf, contentView);

		// add the content view as a subview of me.
		verify_noerr(HIViewAddSubview(frameData->hiSelf, contentView));

		retVal = noErr;
	}

	return retVal;
}
Ejemplo n.º 5
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
Ejemplo n.º 6
0
void MusicBoxDialog(void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	if (!cartOpen)
		return;

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

		actIcon = nil;

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

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

			CFRelease(iconURL);
		}

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

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

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

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

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

			// 107's enhanced SPC player

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

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

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

				SPCPlayFreeze();
			}
			else
				MusicBoxForceFreeze();

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

			ipng = nil;

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

				CFRelease(iurl);
			}

			imageView = nil;

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

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

				CGImageRelease(ipng);
			}

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

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

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

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

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

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

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

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

			MusicBoxInitIndicator();

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

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

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

			SaveWindowPosition(tWindowRef, kWindowMusicBox);

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

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

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

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

			ReleaseWindow(tWindowRef);

			so.stereo_switch = ~0;

			mbxFinished = true;

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

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

			Settings.OpenGLEnable = false;
		}

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

		DisposeNibReference(nibRef);
	}
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
void IGraphicsCarbon::CreateTextEntry(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam)
{
  ControlRef control = 0;

  if (!pControl || mTextEntryView || !mIsComposited) return;

  Rect r = { pTextRect->T, pTextRect->L, pTextRect->B, pTextRect->R };

  // these adjustments should make it the same as the cocoa one, i.e. the same size as the pTextRect, but with the extra blue rim often this is too small
  //Rect r = { pTextRect->T+4, pTextRect->L+3, pTextRect->B-3, pTextRect->R -3 };

  if (CreateEditUnicodeTextControl(NULL, &r, NULL, false, NULL, &control) != noErr) return;

  HIViewAddSubview(mView, control);

  const EventTypeSpec events[] =
  {
    { kEventClassKeyboard, kEventRawKeyDown },
    { kEventClassKeyboard, kEventRawKeyRepeat }
  };

  InstallControlEventHandler(control, TextEntryHandler, GetEventTypeCount(events), events, this, &mTextEntryHandler);
  mTextEntryView = control;

  if (pString[0] != '\0')
  {
    CFStringRef str = CFStringCreateWithCString(NULL, pString, kCFStringEncodingUTF8);

    if (str)
    {
      SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str), &str);
      CFRelease(str);
    }

    ControlEditTextSelectionRec sel;
    sel.selStart = 0;
    sel.selEnd = strlen(pString);
    SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSelectionTag, sizeof(sel), &sel);
  }

  int just = 0;

  switch ( pText->mAlign )
  {
    case IText::kAlignNear:
      just = teJustLeft;
      break;
    case IText::kAlignCenter:
      just = teCenter;
      break;
    case IText::kAlignFar:
      just = teJustRight;
      break;
    default:
      just = teCenter;
      break;
  }

  ControlFontStyleRec font = { kControlUseJustMask | kControlUseSizeMask | kControlUseFontMask, 0, pText->mSize, 0, 0, just, 0, 0 };
  CFStringRef str = CFStringCreateWithCString(NULL, pText->mFont, kCFStringEncodingUTF8);
  font.font = ATSFontFamilyFindFromName(str, kATSOptionFlagsDefault);

  SetControlData(mTextEntryView, kControlEditTextPart, kControlFontStyleTag, sizeof(font), &font);
  CFRelease(str);

  Boolean singleLineStyle = true;
  SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSingleLineTag, sizeof (Boolean), &singleLineStyle);

  HIViewSetVisible(mTextEntryView, true);
  HIViewAdvanceFocus(mTextEntryView, 0);
  SetKeyboardFocus(mWindow, mTextEntryView, kControlEditTextPart);
  SetUserFocusWindow(mWindow);

  mEdControl = pControl;
  mEdParam = pParam;
}
Ejemplo n.º 9
0
IGraphicsCarbon::IGraphicsCarbon(IGraphicsMac* pGraphicsMac,
                                 WindowRef pWindow,
                                 ControlRef pParentControl,
                                 short leftOffset,
                                 short topOffset)
  : mGraphicsMac(pGraphicsMac)
  , mWindow(pWindow)
  , mView(0)
  , mTimer(0)
  , mControlHandler(0)
  , mWindowHandler(0)
  , mCGC(0)
  , mTextEntryView(0)
  , mTextEntryHandler(0)
  , mEdControl(0)
  , mEdParam(0)
  , mPrevX(0)
  , mPrevY(0)
//, mRgn(NewRgn())
  , mLeftOffset(leftOffset)
  , mTopOffset(topOffset)
{
  TRACE;

  Rect r;   // Client.
  r.left = r.top = 0;
  r.right = pGraphicsMac->Width();
  r.bottom = pGraphicsMac->Height();

  WindowAttributes winAttrs = 0;
  GetWindowAttributes(pWindow, &winAttrs);
  mIsComposited = (winAttrs & kWindowCompositingAttribute);

  UInt32 features =  kControlSupportsFocus | kControlHandlesTracking | kControlSupportsEmbedding;

  if (mIsComposited)
  {
    features |= kHIViewIsOpaque | kHIViewFeatureDoesNotUseSpecialParts;
  }

  CreateUserPaneControl(pWindow, &r, features, &mView);

  const EventTypeSpec controlEvents[] =
  {
    { kEventClassControl, kEventControlDraw },
  };

  InstallControlEventHandler(mView, MainEventHandler, GetEventTypeCount(controlEvents), controlEvents, this, &mControlHandler);

  const EventTypeSpec windowEvents[] =
  {
    { kEventClassMouse, kEventMouseDown },
    { kEventClassMouse, kEventMouseUp },
    { kEventClassMouse, kEventMouseMoved },
    { kEventClassMouse, kEventMouseDragged },
    { kEventClassMouse, kEventMouseWheelMoved },

    { kEventClassKeyboard, kEventRawKeyDown },

    { kEventClassWindow, kEventWindowDeactivated }
  };

  InstallWindowEventHandler(mWindow, MainEventHandler, GetEventTypeCount(windowEvents), windowEvents, this, &mWindowHandler);

  double t = kEventDurationSecond / (double) pGraphicsMac->FPS();

  OSStatus s = InstallEventLoopTimer(GetMainEventLoop(), 0., t, TimerHandler, this, &mTimer);

  if (mIsComposited)
  {
    if (!pParentControl)
    {
      HIViewRef hvRoot = HIViewGetRoot(pWindow);
      s = HIViewFindByID(hvRoot, kHIViewWindowContentID, &pParentControl);
    }

    s = HIViewAddSubview(pParentControl, mView);
  }
  else
  {
    if (!pParentControl)
    {
      if (GetRootControl(pWindow, &pParentControl) != noErr)
      {
        CreateRootControl(pWindow, &pParentControl);
      }
    }
    s = EmbedControl(mView, pParentControl);
  }

  if (s == noErr)
  {
    SizeControl(mView, r.right, r.bottom);  // offset?
  }
}
Ejemplo n.º 10
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);
		}
	}
}
Ejemplo n.º 11
0
void SetupControlHandler(int id, DWORD event, EventHandlerProcPtr proc)
{
	EventTypeSpec etype={kEventClassControl,event};
	ControlRef cref=GetControl(id);
	InstallControlEventHandler(cref,NewEventHandlerUPP(proc),1,&etype,cref,NULL);
}
Ejemplo n.º 12
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);
	}
}
/*****************************************************
*
* Handle_WindowCommandProcess(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to handle of the events generated by the various controls of the HICustomView_Tester window
*
* 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_WindowCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status;
	HIViewRef customView = (HIViewRef)inUserData;
	
	// getting the command
	HICommandExtended aCommand;
	status = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(aCommand), NULL, &aCommand);
	require_noerr(status, ExitCommandProcess);
	status = eventNotHandledErr;

	// cheking that the command came from a control
	if ( ! (aCommand.attributes & kHICommandFromControl) ) goto ExitCommandProcess;

	switch (aCommand.commandID)
		{
		//
		// Asking for a refresh of the custom view
		//
		case 'SNDt':
			HIViewSetNeedsDisplay(customView, true);
			status = noErr;
			break;

		//
		// Setting the control value of the custom view
		//
		case 'SV00':
			SetControl32BitValue(customView, 0);
			status = noErr;
			break;
		case 'SV01':
			SetControl32BitValue(customView, 1);
			status = noErr;
			break;
		case 'SV17':
			SetControl32BitValue(customView, 17);
			status = noErr;
			break;
		case 'SVTH':
			SetControl32BitValue(customView, 1000);
			status = noErr;
			break;
		case 'SVet':
			{
			HIViewRef editText;
			HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText);
			char buffer[11];
			Size actualSize;
			GetControlData(editText, kControlEntireControl, kControlEditTextTextTag, 10, buffer, &actualSize);
			if (actualSize > 10) actualSize = 10;
			buffer[actualSize] = 0;
			SetControl32BitValue(customView, atoi(buffer));
			}
			status = noErr;
			break;

		//
		// Setting the state of the custom view
		//
		case 'CHlt':
			// setting the hilite to non-0 also stomps the previous hilite state if any
			// and we don't want that in our testing
			if (GetControl32BitValue(aCommand.source.control) == 1)
				HiliteControl(customView, 1);
			else
				HiliteControl(customView, 0);
			status = noErr;
			break;
		case 'CEnb':
			{
			HIViewRef hiliteControl;
			HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl);
			if (GetControl32BitValue(aCommand.source.control) == 1)
				EnableControl(customView);
			else
				DisableControl(customView);
			UInt16 prevHilite = GetControlHilite(customView);
			if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart))
				DisableControl(hiliteControl);
			else
				EnableControl(hiliteControl);
			HIViewSetNeedsDisplay(customView, true);
			}
			status = noErr;
			break;
		case 'CAct':
			{
			HIViewRef hiliteControl;
			HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl);
			if (GetControl32BitValue(aCommand.source.control) == 1)
				ActivateControl(customView);
			else
				DeactivateControl(customView);
			UInt16 prevHilite = GetControlHilite(customView);
			if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart))
				DisableControl(hiliteControl);
			else
				EnableControl(hiliteControl);
			HIViewSetNeedsDisplay(customView, true);
			}
			status = noErr;
			break;

		//
		// Testing the custom view in or as a scroller in a HIScrollView
		//
		case 'CTiS':
		case 'CTaS':
			if (GetControl32BitValue(aCommand.source.control) == 1)
				{
				// create a HIScrollView and install it where and as the custom view was
				HIViewRef scrollView;
				status = HIScrollViewCreate(kHIScrollViewValidOptions, &scrollView);
				require_noerr(status, ExitCommandProcess);
				
				HIRect frame;
				status = HIViewGetFrame(customView, &frame);
				require_noerr(status, ExitCommandProcess);
				status = HIViewSetFrame(scrollView, &frame);
				require_noerr(status, ExitCommandProcess);

				HIViewSetLayoutInfo(scrollView, &kBindToParentLayout);
				HIViewSetLayoutInfo(customView, &kNoBindLayout);
				
				status = HIViewAddSubview(HIViewGetSuperview(customView), scrollView);
				require_noerr(status, ExitCommandProcess);
				
				if (aCommand.commandID == 'CTiS')
					{
					// if we are testing the custom view in a scroller, we embed it in a scrolling User Pane
					// that we embed in the HIScrollView
					Rect boundsRect = {0, 0, 1000, 1000};
					HIViewRef userPane;
					status = CreateUserPaneControl(NULL, &boundsRect, kControlSupportsEmbedding, &userPane);
					require_noerr(status, ExitCommandProcess);
					
					EventTypeSpec userPaneEvents[] =
						{
							{kEventClassScrollable, kEventScrollableGetInfo},
							{kEventClassScrollable, kEventScrollableScrollTo}
						};
					InstallControlEventHandler(userPane, UserPaneHandler, 2, userPaneEvents, userPane, NULL);

					status = HIViewAddSubview(scrollView, userPane);
					require_noerr(status, ExitCommandProcess);
					status = HIViewAddSubview(userPane, customView);
					require_noerr(status, ExitCommandProcess);

					HIViewSetVisible(userPane, true);
					}
				else
					{
					// else we just embed the custom view directly in the HIScrollView
					status = HIViewAddSubview(scrollView, customView);
					require_noerr(status, ExitCommandProcess);
					}
				
				HIViewSetVisible(scrollView, true);
				
				// the 2 modes are not compatible so we disable the other check box
				HIViewRef otherCheckToDisable;
				if (aCommand.commandID == 'CTiS')
					HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToDisable);
				else
					HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToDisable);
				require_noerr(status, ExitCommandProcess);
				DisableControl(otherCheckToDisable);
				// if we reach here, status is already set to noErr so we don't set it again
				}
			else
				{
				// we remove the HIScrollView and set the custom view back to where and as it was
				HIViewRef scrollView;
				if (aCommand.commandID == 'CTiS')
					scrollView = HIViewGetSuperview(HIViewGetSuperview(customView));
				else
					scrollView = HIViewGetSuperview(customView);

				status = HIViewAddSubview(HIViewGetSuperview(scrollView), customView);
				require_noerr(status, ExitCommandProcess);

				HIRect frame;
				status = HIViewGetFrame(scrollView, &frame);
				require_noerr(status, ExitCommandProcess);
				status = HIViewSetFrame(customView, &frame);
				require_noerr(status, ExitCommandProcess);

				HIViewSetLayoutInfo(customView, &kBindToParentLayout);

				// by releasing the HIScrollView, we also release the scrolling User Pane if any
				// which was embedded inside
				CFRelease(scrollView);
				
				// we renable the other check box
				HIViewRef otherCheckToEnable;
				if (aCommand.commandID == 'CTiS')
					HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToEnable);
				else
					HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToEnable);
				require_noerr(status, ExitCommandProcess);
				EnableControl(otherCheckToEnable);
				// if we reach here, status is already set to noErr so we don't set it again
				}
			break;
		}

ExitCommandProcess:

	return status;
	}   // Handle_WindowCommandProcess
/*****************************************************
*
* 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
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
bool dialog_animation_settings_run(int animate_idx)
{
	int								i,pose_move_idx;
	ControlRef						ctrl;
	ControlID						ctrl_id;
	DataBrowserItemID				itemID;
	DataBrowserCallbacks			dbcall;
	DataBrowserItemDataUPP			pose_list_item_upp,particle_list_item_upp,ring_list_item_upp;
	DataBrowserItemNotificationUPP	pose_list_notify_upp,particle_list_notify_upp,ring_list_notify_upp;
	EventHandlerUPP					event_upp,tab_event_upp;
	EventLoopTimerRef				timer_event;
	EventLoopTimerUPP				timer_upp;
	EventTypeSpec					event_list[]={{kEventClassCommand,kEventProcessCommand}},
									tab_event_list[]={{kEventClassCommand,kEventProcessCommand},
													  {kEventClassControl,kEventControlHit}};
	
		// backup animation for cancel
		
	memmove(&animate_backup,&model.animates[animate_idx],sizeof(model_animate_type));
	
		// if there is no pose moves or new animation,
		// then we need to add a default pose
	
	pose_move_idx=0;
			
	if (model.animates[animate_idx].npose_move==0) {
		pose_move_idx=model_animate_pose_insert(&model,animate_idx,-1,0);
	}
	
		// open the dialog
		
	dialog_open(&dialog_animation_settings_wind,"AnimationSettings");
	
		// tab
		
	dialog_set_tab(dialog_animation_settings_wind,kAnimationPoseTab,0,0,kAnimationPoseTabCount);
	
	ctrl_id.signature=kAnimationPoseTab;
	ctrl_id.id=0;
	GetControlByID(dialog_animation_settings_wind,&ctrl_id,&ctrl);
	
	tab_event_upp=NewEventHandlerUPP(pose_move_setting_tab_proc);
	InstallControlEventHandler(ctrl,tab_event_upp,GetEventTypeCount(tab_event_list),tab_event_list,dialog_animation_settings_wind,NULL);

		// set pose list
		
	dialog_animate_idx=animate_idx;
	dialog_pose_move_idx=pose_move_idx;
		
	ctrl_id.signature=kAnimationPoseList;
	ctrl_id.id=0;
	GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_pose_move_list);
	
	dbcall.version=kDataBrowserLatestCallbacks;
	InitDataBrowserCallbacks(&dbcall);
	
	pose_list_item_upp=NewDataBrowserItemDataUPP(&pose_list_item_proc);
	dbcall.u.v1.itemDataCallback=pose_list_item_upp;

	pose_list_notify_upp=NewDataBrowserItemNotificationUPP(&pose_list_notify_proc);
	dbcall.u.v1.itemNotificationCallback=pose_list_notify_upp;
	
	SetDataBrowserCallbacks(dialog_pose_move_list,&dbcall);
	
	AddDataBrowserItems(dialog_pose_move_list,kDataBrowserNoItem,model.animates[dialog_animate_idx].npose_move,NULL,kDataBrowserItemNoProperty);
	
	dialog_pose_move_change_ok=FALSE;
	
	itemID=pose_move_idx+1;
	SetDataBrowserSelectedItems(dialog_pose_move_list,1,&itemID,kDataBrowserItemsAssign);
	
	dialog_pose_move_change_ok=TRUE;
	
		// setup particle list

	ctrl_id.signature=kAnimationParticleList;
	ctrl_id.id=0;
	GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_particle_list);
	
	dbcall.version=kDataBrowserLatestCallbacks;
	InitDataBrowserCallbacks(&dbcall);
	
	particle_list_item_upp=NewDataBrowserItemDataUPP(&particle_list_item_proc);
	dbcall.u.v1.itemDataCallback=particle_list_item_upp;

	particle_list_notify_upp=NewDataBrowserItemNotificationUPP(&particle_list_notify_proc);
	dbcall.u.v1.itemNotificationCallback=particle_list_notify_upp;
	
	SetDataBrowserCallbacks(dialog_particle_list,&dbcall);
	
		// setup ring list
		
	ctrl_id.signature=kAnimationRingList;
	ctrl_id.id=0;
	GetControlByID(dialog_animation_settings_wind,&ctrl_id,&dialog_ring_list);
	
	dbcall.version=kDataBrowserLatestCallbacks;
	InitDataBrowserCallbacks(&dbcall);
	
	ring_list_item_upp=NewDataBrowserItemDataUPP(&ring_list_item_proc);
	dbcall.u.v1.itemDataCallback=ring_list_item_upp;

	ring_list_notify_upp=NewDataBrowserItemNotificationUPP(&ring_list_notify_proc);
	dbcall.u.v1.itemNotificationCallback=ring_list_notify_upp;
	
	SetDataBrowserCallbacks(dialog_ring_list,&dbcall);

		// fill pose combo

	dialog_clear_combo(dialog_animation_settings_wind,kAnimationPosePose,0);
	
	for (i=0;i!=model.npose;i++) {
		dialog_add_combo_item(dialog_animation_settings_wind,kAnimationPosePose,0,model.poses[i].name,FOUR_CHAR_CODE('\?\?\?\?'));
	}
	
		// fill mesh combo (leave none in list)

	for (i=0;i!=model.nmesh;i++) {
		dialog_add_combo_item(dialog_animation_settings_wind,kAnimationMeshName,0,model.meshes[i].name,FOUR_CHAR_CODE('\?\?\?\?'));
	}
	
		// load setting data
		
	dialog_set_text(dialog_animation_settings_wind,kAnimationName,0,model.animates[animate_idx].name);
	dialog_set_boolean(dialog_animation_settings_wind,kAnimationLoop,0,model.animates[animate_idx].loop);
	dialog_set_focus(dialog_animation_settings_wind,kAnimationName,0);
	
		// load pose move data
		
	dialog_pose_move_settings_load();
	
	dialog_animation_settings_cancel=FALSE;

		// show window
	
	ShowWindow(dialog_animation_settings_wind);
	
		// install event handler
		
	event_upp=NewEventHandlerUPP(animation_settings_event_proc);
	InstallWindowEventHandler(dialog_animation_settings_wind,event_upp,GetEventTypeCount(event_list),event_list,NULL,NULL);
	
		// modal window and timer

	timer_upp=NewEventLoopTimerUPP(pose_move_timer);
	InstallEventLoopTimer(GetCurrentEventLoop(),0,0.01,timer_upp,NULL,&timer_event);
		
	RunAppModalLoopForWindow(dialog_animation_settings_wind);

	RemoveEventLoopTimer(timer_event);
	DisposeEventLoopTimerUPP(timer_upp);
	
		// dialog to data
		
	dialog_get_text(dialog_animation_settings_wind,kAnimationName,0,model.animates[animate_idx].name,name_str_len);
	model.animates[animate_idx].loop=dialog_get_boolean(dialog_animation_settings_wind,kAnimationLoop,0);
	
	dialog_pose_move_settings_save();

		// close window
		
	DisposeDataBrowserItemDataUPP(pose_list_item_upp);
	DisposeDataBrowserItemNotificationUPP(pose_list_notify_upp);
	
	DisposeDataBrowserItemDataUPP(particle_list_item_upp);
	DisposeDataBrowserItemNotificationUPP(particle_list_notify_upp);
	
	DisposeDataBrowserItemDataUPP(ring_list_item_upp);
	DisposeDataBrowserItemNotificationUPP(ring_list_notify_upp);
	
	DisposeWindow(dialog_animation_settings_wind);
	
		// if cancel, reset animation
		
	if (dialog_animation_settings_cancel) {
		memmove(&model.animates[animate_idx],&animate_backup,sizeof(model_animate_type));
	}
		
	reset_animate_list();
	
	return(!dialog_animation_settings_cancel);
}