static OSStatus MyMTViewRegister(CFStringRef myClassID) { OSStatus err = noErr; static HIObjectClassRef sMyViewClassRef = NULL; if ( sMyViewClassRef == NULL ) { EventTypeSpec eventList[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlTrack }, }; err = HIObjectRegisterSubclass( myClassID, kHIViewClassID, // base class ID 0, // option bits MTViewHandler, // construct proc GetEventTypeCount( eventList ), eventList, NULL, // construct data &sMyViewClassRef ); } return err; }
OSStatus HIOpenGLViewRegister () { OSStatus err = noErr; static HIObjectClassRef sHIOpenGLViewClassRef = nil; if (sHIOpenGLViewClassRef == nil) { EventTypeSpec eventList[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlInitialize }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlHiliteChanged }, { kEventClassControl, kEventControlBoundsChanged }, { kEventClassControl, kEventControlOwningWindowChanged } }; err = HIObjectRegisterSubclass(kHIOpenGLViewClassID, kHIViewClassID, nil, HIOpenGLViewEventProc, GetEventTypeCount(eventList), eventList, nil, &sHIOpenGLViewClassRef); } return err; }
void HIRevolutionStackViewRegister(void) { static HIObjectClassRef s_class = NULL; OSStatus t_status; t_status = noErr; if (s_class == NULL) { EventTypeSpec t_events[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlInitialize }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlGetPartRegion }, { kEventClassControl, kEventControlHiliteChanged }, { kEventClassControl, kEventControlActivate }, { kEventClassControl, kEventControlDeactivate }, { 'revo', 'rlnk' } }; t_status = HIObjectRegisterSubclass(kHIRevolutionStackViewClassID, kHIViewClassID, NULL, HIRevolutionStackViewHandler, sizeof(t_events) / sizeof(EventTypeSpec), t_events, NULL, &s_class); } }
//----------------------------------------------------------------------------- // RegisterCustomToolbarItemClass //----------------------------------------------------------------------------- // Our class registration call. We take care to only register once. We call this // in our CreateCustomToolbarItem call below to make sure our class is in place // before trying to instantiate an object of the class. // void RegisterCustomToolbarItemClass() { static bool sRegistered; if ( !sRegistered ) { HIObjectRegisterSubclass( kCustomToolbarItemClassID, kHIToolbarItemClassID, 0, CustomToolbarItemHandler, GetEventTypeCount( kEvents ), kEvents, 0, NULL ); sRegistered = true; } }
// ----------------------------------------------------------------------------- // HITestViewRegister // ----------------------------------------------------------------------------- // Register this class with the HIObject registry, notifying it of which // events we will be interested. // // This API can be called multiple times, but will only register once. // OSStatus HITestViewRegister() { OSStatus err = noErr; static HIObjectClassRef sHITestViewClassRef = NULL; if ( sHITestViewClassRef == NULL ) { EventTypeSpec eventList[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlActivate }, { kEventClassControl, kEventControlDeactivate }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlHiliteChanged }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlInitialize }, #if CUSTOM_TRACK { kEventClassControl, kEventControlTrack }, #endif { kEventClassControl, kEventControlValueFieldChanged } }; err = HIObjectRegisterSubclass( kHITestViewClassID, // class ID kHIViewClassID, // base class ID 0, // option bits HITestViewHandler, // construct proc GetEventTypeCount( eventList ), eventList, NULL, // construct data, &sHITestViewClassRef ); } return err; }
/*----------------------------------------------------------------------------------------------------------*/ CFStringRef GetScrollingTextBoxClass() { // following code is pretty much boiler plate. static HIObjectClassRef theClass; if (theClass == NULL) { static EventTypeSpec kFactoryEvents[] = { // the next 3 messages are boiler plate { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, // the next 2 messages are Scroll specific { kEventClassScrollable, kEventScrollableGetInfo }, { kEventClassScrollable, kEventScrollableScrollTo }, // the next message is Control specific { kEventClassControl, kEventControlInitialize }, { kEventClassControl, kEventControlBoundsChanged }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlSetData }, }; HIObjectRegisterSubclass(kScrollingTextBoxClassID, kHIViewClassID, 0, ScrollingTextViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass); } return kScrollingTextBoxClassID; }
/* The public routine exported from this file that creates a star-shaped frame view suitable for the given menuType. */ OSStatus CreateStarFrame(MenuRef inMenu, ThemeMenuType menuType, HIViewRef *outFrameView) { OSStatus errStatus = noErr; static bool isRegistered = false; // Register the StarMenuFrame subclass if necessary if(!isRegistered) { verify_noerr( HIObjectRegisterSubclass ( kStarFrameClassID, kHIViewClassID, kNilOptions, StarFrameEventHandler, GetEventTypeCount( gStarFrameHandledEvents ), gStarFrameHandledEvents, NULL, &gStarFrameClassRef)); isRegistered = true; } // Create an instance of the StarMenuFrame EventRef initEvent = NULL; errStatus = CreateEvent(NULL, kEventClassHIObject, kEventHIObjectInitialize, 0, 0, &initEvent ); if(noErr == errStatus && initEvent) { // store the initialization parameters in the event SetEventParameter( initEvent, kEventParamMenuRef, typeMenuRef, sizeof(inMenu), &inMenu); SetEventParameter( initEvent, kEventParamMenuType, typeThemeMenuType, sizeof(menuType), &menuType); verify_noerr(errStatus = HIObjectCreate(kStarFrameClassID, initEvent, (HIObjectRef *) outFrameView)); ReleaseEvent(initEvent); initEvent = nil; } return errStatus; }
/***************************************************** * * GetHICustomViewClass() * * Purpose: Registers our custom HICustomView view class and installs the appropriate handlers * * Inputs: none * * Returns: our class ID as a CFStringRef */ CFStringRef GetHICustomViewClass(void) { // following code is pretty much boiler plate. static HIObjectClassRef theClass; if (theClass == NULL) { static EventTypeSpec kFactoryEvents[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlDraw }, { kEventClassControl, kEventControlValueFieldChanged }, { kEventClassControl, kEventControlHiliteChanged } }; OSStatus status = HIObjectRegisterSubclass(kHICustomViewClass, kHIViewClassID, 0, Internal_HICustomViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass); verify_noerr(status); } return kHICustomViewClass; } // GetHICustomViewClass
static WindowRef DrawDialogTheMacOSXWay(void) { // Create a window. "DLOG:257" is the name of the window object. This name is set in // InterfaceBuilder when the resource file is imported. OSStatus status = noErr; IBNibRef nibRef; WindowRef window = NULL; static HIObjectClassRef theClass; if (theClass == NULL) { static EventTypeSpec kFactoryEvents[] = { { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlTrack }, { kEventClassControl, kEventControlBoundsChanged }, { kEventClassControl, kEventControlDraw } }; HIObjectRegisterSubclass(kCustomSpotViewClassID, kHIViewClassID, 0, CustomSpotViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass); } status = CreateNibReference(CFSTR("main"), &nibRef); require_noerr(status, CantGetNibRef); status = CreateWindowFromNib(nibRef, CFSTR("DLOG:257"), &window); require_noerr(status, CantCreateWindow); // Let's react to User's commands. EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; InstallEventHandler(GetWindowEventTarget(window), MacOSXDialogCommandProcess, 1, &eventTypeCP, window, NULL); // we still assign the key filter on our edit text box so that only digits can be entered HIViewID hidnst = {0, 9}; HIViewRef numEditText; HIViewFindByID(HIViewGetRoot(window), hidnst, &numEditText); ControlKeyFilterUPP keyFilter = MyEditKeyFilter; SetControlData(numEditText, kControlEntireControl, kControlEditTextKeyFilterTag, sizeof(keyFilter), &keyFilter); SetKeyboardFocus(window, numEditText, kControlFocusNextPart); // we still set the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work // and still associate the previous edit text box with the scroll bar so it gets updated HIViewID hidsb = {0, 14}; HIViewRef scrollBar; HIViewFindByID(HIViewGetRoot(window), hidsb, &scrollBar); SetControlAction(scrollBar, ScrollBar32BitActionProc); SetControlReference(scrollBar, (SInt32)numEditText); // Move it! MoveWindow(window, 854, 271, false); // and use the replacement for ModalDialog // one good thing is that our behaviors are no longer half-done at the dialog level // and half-done at the control level, they are all handled by the view handlers ShowWindow(window); CantCreateWindow: CantGetNibRef: return (window); }