void TActiveScroller::DisableScroller() { if (disabled) return; disabled=true; #if TARGET_API_MAC_CARBON==1 wasScrollHilight=GetControlHilite(scrollBar); #else wasScrollHilight=(**scrollBar).contrlHilite; #endif if (wasScrollHilight!=kControlInactivePart) HiliteControl(scrollBar,kControlInactivePart); }
OSStatus HIOpenGLViewEventControlDraw (EventHandlerCallRef, EventRef, HIOpenGLViewData* inData) { // We don't always know the control bounds at construction time, so // we wait until the first time we draw to set up the OpenGL context. AGLContext context = HIOpenGLViewGetContext(inData); HIRect bounds; OSStatus err = HIViewGetBounds(inData->mControl, &bounds); if (err != noErr) return err; double w = bounds.size.width; double h = bounds.size.height; double alpha = (GetControlHilite(inData->mControl) == kControlNoPart) ? 1.0 : 0.5; aglSetCurrentContext(context); aglUpdateContext(context); glClearColor(1.0, 1.0, 1.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); glEnable(GL_SMOOTH); glEnable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); GLint r[4]; glGetIntegerv(GL_VIEWPORT, r); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, r[2] - r[0], 0, r[3] - r[1]); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBegin(GL_QUADS); glColor4f(1.0, 0.0, 0.0, alpha); glVertex3f(0.0, h, 0.0); glColor4f(1.0, 1.0, 0.0, alpha); glVertex3f(w, h, 0.0); glColor4f(0.0, 0.0, 1.0, alpha); glVertex3f(w, 0.0, 0.0); glColor4f(0.0, 1.0, 0.0, alpha); glVertex3f(0.0, 0.0, 0.0); glEnd(); aglSwapBuffers(context); return noErr; }
void TActiveScroller::EnableScroller() { UInt8 temp; if (!disabled) return; disabled=false; #if TARGET_API_MAC_CARBON==1 temp=GetControlHilite(scrollBar); #else temp=(**scrollBar).contrlHilite; #endif if (wasScrollHilight!=temp) HiliteControl(scrollBar,wasScrollHilight); }
// ----------------------------------------------------------------------------- // HITestViewDraw // ----------------------------------------------------------------------------- // Here's the fun stuff. Draw a red box when not hilighted, a blue box // when hilighted. // OSStatus HITestViewDraw( EventRef inEvent, HITestViewData* inData ) { OSStatus err; HIRect bounds; CGContextRef context; float red, green, blue; err = GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof( CGContextRef ), NULL, &context ); require_noerr( err, ParameterMissing ); err = HIViewGetBounds( inData->view, &bounds ); red = inData->red; green = inData->green; blue = inData->blue; switch ( GetControlHilite( inData->view ) ) { case kControlNoPart: CGContextSetRGBFillColor( context, red, green, blue, 0.25 ); CGContextSetRGBStrokeColor( context, red, green, blue, 1 ); break; // Handle synthetic highlights, too case kControlInactivePart: case kControlDisabledPart: CGContextSetRGBFillColor( context, red, green, blue, 0.10 ); CGContextSetRGBStrokeColor( context, red, green, blue, 0.10 ); break; default: CGContextSetRGBFillColor( context, 0, 0, 1, 0.25 ); CGContextSetRGBStrokeColor( context, 0, 0, 1, 1 ); break; } CGContextFillRect( context, bounds ); CGContextStrokeRect( context, bounds ); ParameterMissing: return err; }
/***************************************************** * * Handle_ControlValueFieldOrHiliteChanged(inHandlerCallRef, inEvent, inUserData) * * Purpose: called to handle the change of the value or hilite of our custom view, we update the static text field * * 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_ControlValueFieldOrHiliteChanged(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { OSStatus status; HIViewRef customView = (HIViewRef)inUserData; // Finding our static text control HIViewRef statText; status = HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kStaticTextID, &statText); require_noerr(status, ExitValueFieldChanged); // Grabbing the fields that we are interested in CFStringRef theCFString = CFStringCreateWithFormat(NULL, NULL, CFSTR("Value: %ld, Min: %ld, Max: %ld, Hilite: %d"), GetControl32BitValue(customView), GetControl32BitMinimum(customView), GetControl32BitMaximum(customView), GetControlHilite(customView)); require(theCFString != NULL, ExitValueFieldChanged); // Setting the text in the control #ifdef MAC_OS_X_VERSION_10_4 status = HIViewSetText(statText, theCFString); #else status = SetControlData(statText, kControlEntireControl, kControlStaticTextCFStringTag, sizeof(theCFString), &theCFString); #endif require_noerr(status, ExitValueFieldChanged); CFRelease(theCFString); ExitValueFieldChanged: if (status == noErr) status = eventNotHandledErr; return status; } // Handle_ControlValueFieldOrHiliteChanged
/***************************************************** * * 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