예제 #1
0
static pascal OSStatus AutofireTabEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	#pragma unused (inHandlerRef, inUserData)
	
	OSStatus	result = eventNotHandledErr;
	HIViewRef	ctl;
	HIViewID	cid;
	SInt32		value;
	
	GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, nil, sizeof(ControlRef), nil, &ctl);
	GetControlID(ctl, &cid);
	value = GetControl32BitValue(ctl);
	
	if ((cid.id == 256) && (value != autofireLastTabIndex))
	{
		AutofireSelectTabPane(ctl, value);
		result = noErr;
	}    
	
	return result;
}
예제 #2
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);
	}
}