UI_Camera::UI_Camera(Base_Camera* camera) : cWidgetBase(0), Camera(0){ Self_Counter+=1; assert(Self_Counter==1); Set_Camera(camera); SetControlBounds(MY_UI::Utilities::Rect(0, 0, MAX_WINDOWSIZE, MAX_WINDOWSIZE)); SetClientBounds(MY_UI::Utilities::Rect(0, 0, MAX_WINDOWSIZE, MAX_WINDOWSIZE)); SetDraggable(true); SetName("UI_Camera"); MY_UI::GetApplicationLayer()->SetCamera(this); }
MY_UI::Controls::Simple_Window::Simple_Window(cWidgetBase* parent) : cWidgetBase(parent) { SetName("Simple Window"); SetControlBounds(Utilities::Rect(0, 0, 100, 100)); SetClientBounds(Utilities::Rect(0, 0, 100, 100)); auto skin = MY_UI::Internal::WidgetSkin; // setting the controls to NULL means that they will not be inserted in the children array Background = new Image(this); Background->Add_Texture(skin->Window_Without_Focus);// take a copy of the UI skin for the texture Background->Add_Texture(skin->Window_With_Focus);// take a copy of the UI skin for the texture Background->Set_ShownImage(0); Background->SetName("Background"); Background->SetImageBorderSize(1,1); Background->SetBorderDrawn(true); DeCouple(Background); SetDraggable(true); OnLeftDrag.Add(std::bind( &MY_UI::Controls::Simple_Window::Dragging, this)); SetSize(100, 100); }
MY_UI::Controls::Window::Window(cWidgetBase* parent): cWidgetBase(parent) { // manually set the starting size of the window SetControlBounds(Utilities::Rect(0, 0, 100, 100)); TitleBar = new Titlebar(this); Utilities::Point titlebarsize = TitleBar->GetSize(); SetClientBounds(Utilities::Rect(0, titlebarsize.y, 100, 100)); TitleBar->Bar->OnLeftDrag.Add(std::bind(&MY_UI::Controls::Window::Dragging, this)); TitleBar->Bar->OnLeftDoubleClick.Add(std::bind(&MY_UI::Controls::Window::Maximize, this)); TitleBar->Close_Button->OnLeftClicked.Add(std::bind(&MY_UI::Controls::Window::Close, this)); TitleBar->Maximize_Button->OnLeftClicked.Add(std::bind( &MY_UI::Controls::Window::Maximize, this)); TitleBar->Minimize_Button->OnLeftClicked.Add(std::bind(&MY_UI::Controls::Window::Minimize, this)); SimpleWindow = new Simple_Window(this); DeCouple(SimpleWindow); SetMinSize(titlebarsize.x, titlebarsize.y); SetSize(100, 100); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // AUDiskStreamingCheckbox::AUDiskStreamingCheckbox // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AUDiskStreamingCheckbox::AUDiskStreamingCheckbox (AUCarbonViewBase *inBase, Point inLocation, int inRightEdge, ControlFontStyleRec & inFontStyle) : AUPropertyControl (inBase) { Rect r; r.top = inLocation.v; r.bottom = r.top + 16; r.left = inLocation.h; r.right = r.left + inRightEdge; verify_noerr(CreateCheckBoxControl(mView->GetCarbonWindow(), &r, CFSTR("Disk Streaming"), 0, true, &mControl)); verify_noerr (SetControlFontStyle (mControl, &inFontStyle)); ControlSize smallSize = kControlSizeSmall; verify_noerr (SetControlData (mControl, kControlEntireControl, kControlSizeTag, sizeof (ControlSize), &smallSize)); SInt16 baseLineOffset; verify_noerr (GetBestControlRect (mControl, &r, &baseLineOffset)); r.bottom += baseLineOffset; SInt16 difference = (r.left + inRightEdge) - r.right; r.right += difference; r.left += difference; SetControlBounds (mControl, &r); EmbedControl(mControl); verify_noerr (AudioUnitAddPropertyListener(mView->GetEditAudioUnit(), kMusicDeviceProperty_StreamFromDisk, DiskStreamingListener, this)); UInt32 value; UInt32 size = sizeof(value); verify_noerr (AudioUnitGetProperty (mView->GetEditAudioUnit(), kMusicDeviceProperty_StreamFromDisk, kAudioUnitScope_Global, 0, &value, &size)); HandlePropertyChange (value); RegisterEvents(); }
Boolean AUCarbonViewControl::SizeControlToFit(ControlRef inControl, SInt16 *outWidth, SInt16 *outHeight) { #if !__LP64__ if (inControl == 0) return false; Boolean bValue = false; // this only works on text controls -- returns an error for other controls, but doesn't do anything, // so the error is irrelevant SetControlData(inControl, kControlEntireControl, 'stim' /* kControlStaticTextIsMultilineTag */, sizeof(Boolean), &bValue); SInt16 baseLineOffset; Rect bestRect; OSErr err = GetBestControlRect(inControl, &bestRect, &baseLineOffset); if (err != noErr) return false; int width = (bestRect.right - bestRect.left) + 1; int height = (bestRect.bottom - bestRect.top) + 1; Rect boundsRect; GetControlBounds (inControl, &boundsRect); Rect newRect; newRect.top = boundsRect.top; newRect.bottom = newRect.top + height; newRect.left = boundsRect.left; newRect.right = newRect.left + width; SetControlBounds (inControl, &newRect); if (outWidth) *outWidth = width; if (outHeight) *outHeight = height; #endif return true; }
void MCStack::syncscroll(void) { // If we have no window, no need to adjust the HIView. if (window == nil) return; // And tweak the HIView's location... ControlRef t_root_control; GetRootControl((WindowPtr)window -> handle . window, &t_root_control); ControlRef t_subcontrol; if (GetIndexedSubControl(t_root_control, 1, &t_subcontrol) == noErr) { Rect t_bounds; t_bounds . left = 0; t_bounds . top = -m_scroll; t_bounds . right = rect . width; t_bounds . bottom = rect . height; SetControlBounds(t_subcontrol, &t_bounds); } // MW-2011-11-30: [[ Bug 9887 ]] Make sure all the player objects on this // stack are adjusted as appropriate. for(MCPlayer *t_player = MCplayers; t_player != nil; t_player = t_player -> getnextplayer()) if (!t_player -> isbuffering() && t_player -> getstack() == this) t_player -> setrect(t_player -> getrect()); // MW-2012-10-08: [[ Bug 10442 ]] Set the scroll window property so revBrowser // works properly. SetWindowProperty((WindowPtr)window -> handle . window, 'revo', 'scrl', 4, &m_scroll); // Now send a sync event so revBrowser picks it up. EventRef t_event; CreateEvent(NULL, 'revo', 'sync', GetCurrentEventTime(), 0, &t_event); SendEventToEventTarget(t_event, GetWindowEventTarget((WindowPtr)window -> handle . window)); ReleaseEvent(t_event); }
void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { TkMenuButton *butPtr = (TkMenuButton *) clientData; Tk_Window tkwin = butPtr->tkwin; TkWindow * winPtr; Pixmap pixmap; MacMenuButton * mbPtr = (MacMenuButton *) butPtr; GWorldPtr dstPort; CGrafPtr saveWorld; GDHandle saveDevice; int hasImageOrBitmap = 0; int width, height; int err; ControlButtonGraphicAlignment theAlignment; Rect paneRect, cntrRect; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } pixmap = ( Pixmap )Tk_WindowId(tkwin); GetGWorld(&saveWorld, &saveDevice); dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); SetGWorld(dstPort, NULL); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); winPtr=(TkWindow *)butPtr->tkwin; paneRect.left=winPtr->privatePtr->xOff; paneRect.top=winPtr->privatePtr->yOff; paneRect.right=paneRect.left+Tk_Width(butPtr->tkwin)-1; paneRect.bottom=paneRect.top+Tk_Height(butPtr->tkwin)-1; cntrRect=paneRect; cntrRect.left+=butPtr->inset; cntrRect.top+=butPtr->inset; cntrRect.right-=butPtr->inset; cntrRect.bottom-=butPtr->inset; if (mbPtr->userPane) { MenuButtonControlParams params; bzero(¶ms, sizeof(params)); ComputeMenuButtonControlParams(butPtr, ¶ms ); if (bcmp(¶ms,&mbPtr->params,sizeof(params))) { if (mbPtr->userPane) { DisposeControl(mbPtr->userPane); mbPtr->userPane = NULL; mbPtr->control = NULL; } } } if (!mbPtr->userPane) { if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect ) ) { fprintf(stderr,"Init Control failed\n" ); return; } } SetControlBounds(mbPtr->userPane,&paneRect); SetControlBounds(mbPtr->control,&cntrRect); /* * We need to cache the title and its style */ if (!(mbPtr->flags&2)) { ControlTitleParams titleParams; int titleChanged; int styleChanged; ComputeControlTitleParams(butPtr,&titleParams); CompareControlTitleParams(&titleParams,&mbPtr->titleParams, &titleChanged,&styleChanged); if (titleChanged) { CFStringRef cf; cf = CFStringCreateWithCString(NULL, titleParams.title, kCFStringEncodingUTF8); if (hasImageOrBitmap) { SetControlTitleWithCFString(mbPtr->control, cf); } else { SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf); } CFRelease(cf); bcopy(titleParams.title,mbPtr->titleParams.title,titleParams.len+1); mbPtr->titleParams.len = titleParams.len; } if ((titleChanged||styleChanged) && titleParams .len) { if (hasImageOrBitmap) { if ((err=SetControlFontStyle(mbPtr->control,&titleParams.style))!=noErr) { fprintf(stderr,"SetControlFontStyle failed %d\n", err); return; } } bcopy(&titleParams.style,&mbPtr->titleParams.style,sizeof(titleParams.style)); } } if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); hasImageOrBitmap = 1; } else if (butPtr->bitmap != None) { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); hasImageOrBitmap = 1; } if (hasImageOrBitmap) { mbPtr->picParams.srcRect.right = width; mbPtr->picParams.srcRect.bottom = height; /* Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */ tkPictureIsOpen = 1; if (!(mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams)) ) { fprintf(stderr,"OpenCPicture failed\n"); } /* * TO DO - There is one case where XCopyPlane calls CopyDeepMask, * which does not get recorded in the picture. So the bitmap code * will fail in that case. */ if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0, (unsigned int) width, (unsigned int) height, 0, 0, 1); } ClosePicture(); tkPictureIsOpen = 0; if ( (err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &mbPtr->bevelButtonContent)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err ); } switch (butPtr->anchor) { case TK_ANCHOR_N: theAlignment = kControlBevelButtonAlignTop; break; case TK_ANCHOR_NE: theAlignment = kControlBevelButtonAlignTopRight; break; case TK_ANCHOR_E: theAlignment = kControlBevelButtonAlignRight; break; case TK_ANCHOR_SE: theAlignment = kControlBevelButtonAlignBottomRight; break; case TK_ANCHOR_S: theAlignment = kControlBevelButtonAlignBottom; break; case TK_ANCHOR_SW: theAlignment = kControlBevelButtonAlignBottomLeft; break; case TK_ANCHOR_W: theAlignment = kControlBevelButtonAlignLeft; break; case TK_ANCHOR_NW: theAlignment = kControlBevelButtonAlignTopLeft; break; case TK_ANCHOR_CENTER: theAlignment = kControlBevelButtonAlignCenter; break; } if ((err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err ); } } if (butPtr->flags & GOT_FOCUS) { HiliteControl(mbPtr->control,kControlButtonPart); } else { HiliteControl(mbPtr->control,kControlNoPart); } UpdateControlColors(mbPtr); if (mbPtr->flags&2) { ShowControl(mbPtr->control); ShowControl(mbPtr->userPane); mbPtr->flags ^= 2; } else { Draw1Control(mbPtr->userPane); SetControlVisibility(mbPtr->control, true, true); } if (hasImageOrBitmap) { KillPicture(mbPtr->bevelButtonContent.u.picture); } SetGWorld(saveWorld, saveDevice); }
MY_UI::Controls::Tab_Control::Tab_Control(cWidgetBase* parent) :cWidgetBase(parent) { SetControlBounds(Utilities::Rect(0, 0, 100, 100)); auto skin = MY_UI::Internal::WidgetSkin; SetClientBounds(Utilities::Rect(0, static_cast<int>(skin->Tab_Hovered.height), 100, 100 - static_cast<int>(skin->Tab_Hovered.height))); CurrentPage=-1; }
MY_UI::Controls::Titlebar::Titlebar(cWidgetBase* parent) : cWidgetBase(parent) { auto skin = MY_UI::Internal::WidgetSkin; // set the client portion of the window Title = new Text(this); Title->SetPos(5, 2); Title->SetFontSize(20); SetTitle("Window Label"); int height = max(Title->GetSize().top, static_cast<int>(skin->WindowBar_Without_Focus.height)); int width = max(Title->GetSize().left, static_cast<int>(skin->WindowBar_Without_Focus.width)); SetControlBounds(Utilities::Rect(0, 0, width, height) ); SetClientBounds(Utilities::Rect(0, 0, width, height) ); SetMinSize(width, height); // the code below might be a little verbose, but it allows greater flexibility in case I change the size of things or their positions Close_Button = new Button(this); Close_Button->ClearImages(); Close_Button->Set_UnPressed_Texture(skin->Close_Window_Button);// take a copy of the UI skin for the texture Close_Button->Set_Pressed_Texture(skin->Close_Window_Button_Pressed);// take a copy of the UI skin for the texture Close_Button->SetSize(static_cast<int>(skin->Close_Window_Button.width), static_cast<int>(skin->Close_Window_Button.height)); Utilities::Point po = GetSize(); Close_Button->SetPopup("Close_Button"); Close_Button->SetPos(po.x - static_cast<int>(skin->Close_Window_Button.width - 6.0f) , 4); Close_Button->SetName("Close_Button"); Close_Button->SetImageBorderSize(2, 2); Maximize_Button = new Button(this); Maximize_Button->ClearImages(); Maximize_Button->Set_UnPressed_Texture(skin->Maximize_Window_Button);// take a copy of the UI skin for the texture Maximize_Button->Set_Pressed_Texture(skin->Maximize_Window_Button_Pressed);// take a copy of the UI skin for the texture po = Close_Button->GetPos(); Maximize_Button->SetPos(po.x - static_cast<int>(skin->Maximize_Window_Button.width - 4.0f ) , 4); Maximize_Button->SetSize(static_cast<int>(skin->Maximize_Window_Button.width), static_cast<int>(skin->Maximize_Window_Button.height)); Maximize_Button->SetPopup("Maximize_Button"); Maximize_Button->SetName("Maximize_Button"); Maximize_Button->SetImageBorderSize(2, 2); Minimize_Button = new Button(this); Minimize_Button->ClearImages(); Minimize_Button->Set_UnPressed_Texture(skin->Minimize_Window_Button);// take a copy of the UI skin for the texture Minimize_Button->Set_Pressed_Texture(skin->Minimize_Window_Button_Pressed);// take a copy of the UI skin for the texture po = Maximize_Button->GetPos(); Minimize_Button->SetPos(po.x - static_cast<int>(skin->Minimize_Window_Button.width - 4.0f) , 4); Minimize_Button->SetSize(static_cast<int>(skin->Minimize_Window_Button.width), static_cast<int>(skin->Minimize_Window_Button.height)); Minimize_Button->SetPopup("Minimize_Button"); Minimize_Button->SetName("Minimize_Button"); Minimize_Button->SetImageBorderSize(2, 2); Bar = new Button(this); Bar->ClearImages(); Bar->Set_UnPressed_Texture(skin->WindowBar_Without_Focus);// take a copy of the UI skin for the texture Bar->Set_Selected_Texture(skin->WindowBar_With_Focus);// take a copy of the UI skin for the texture Bar->Set_Hovered_Texture(skin->WindowBar_With_Focus); Bar->SetSize(static_cast<int>(skin->WindowBar_Without_Focus.width), static_cast<int>(skin->WindowBar_Without_Focus.height)); Bar->SetName("Bar"); Bar->SetDraggable(true); Bar->SetSize(static_cast<int>(skin->WindowBar_Without_Focus.width), Title->GetSize().top); Bar->SetImageBorderSize(1, 1); SetSize(width, height); }
void TkpDisplayScale( ClientData clientData) /* Widget record for scale. */ { TkScale *scalePtr = (TkScale *) clientData; Tk_Window tkwin = scalePtr->tkwin; Tcl_Interp *interp = scalePtr->interp; int result; char string[TCL_DOUBLE_SPACE]; MacScale *macScalePtr = (MacScale *) clientData; Rect r; WindowRef windowRef; CGrafPtr destPort, savePort; Boolean portChanged; MacDrawable *macDraw; SInt32 initialValue, minValue, maxValue; UInt16 numTicks; #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("TkpDisplayScale"); #endif scalePtr->flags &= ~REDRAW_PENDING; if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) { goto done; } /* * Invoke the scale's command if needed. */ Tcl_Preserve((ClientData) scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { Tcl_Preserve((ClientData) interp); sprintf(string, scalePtr->format, scalePtr->value); result = Tcl_VarEval(interp, scalePtr->command, " ", string, NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundError(interp); } Tcl_Release((ClientData) interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { Tcl_Release((ClientData) scalePtr); return; } Tcl_Release((ClientData) scalePtr); /* * Now handle the part of redisplay that is the same for * horizontal and vertical scales: border and traversal * highlight. */ if (scalePtr->highlightWidth != 0) { GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin)); Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, Tk_WindowId(tkwin)); } Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scalePtr->bgBorder, scalePtr->highlightWidth, scalePtr->highlightWidth, Tk_Width(tkwin) - 2*scalePtr->highlightWidth, Tk_Height(tkwin) - 2*scalePtr->highlightWidth, scalePtr->borderWidth, scalePtr->relief); /* * Set up port for drawing Macintosh control. */ macDraw = (MacDrawable *) Tk_WindowId(tkwin); destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin)); portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); /* * Create Macintosh control. */ #define MAC_OSX_SCROLL_WIDTH 10 if (scalePtr->orient == ORIENT_HORIZONTAL) { int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + scalePtr->inset; r.top = macDraw->yOff + offset; r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset; r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2; } else { int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + offset; r.top = macDraw->yOff + scalePtr->inset; r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2; r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset; } if (macScalePtr->scaleHandle == NULL) { #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("Initialising scale"); #endif initialValue = scalePtr->value; if (scalePtr->orient == ORIENT_HORIZONTAL) { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } else { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } if (scalePtr->tickInterval == 0) { numTicks = 0; } else { numTicks = (maxValue - minValue)/scalePtr->tickInterval; } CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue, kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc, &(macScalePtr->scaleHandle)); SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr); if (IsWindowActive(windowRef)) { macScalePtr->flags |= ACTIVE; } } else { SetControlBounds(macScalePtr->scaleHandle, &r); SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value); SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue); SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue); } /* * Finally draw the control. */ SetControlVisibility(macScalePtr->scaleHandle,true,true); HiliteControl(macScalePtr->scaleHandle,0); Draw1Control(macScalePtr->scaleHandle); if (portChanged) { QDSwapPort(savePort, NULL); } done: scalePtr->flags &= ~REDRAW_ALL; }
//----------------------------------------------------------------------------------- static OSStatus MTViewHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) { OSStatus err = eventNotHandledErr; HIPoint where; ControlPartCode part; UInt32 eventClass = GetEventClass( inEvent ); UInt32 eventKind = GetEventKind( inEvent ); MTViewData* data = (MTViewData*)inUserData; // pointless for the kEventHIObjectConstruct event switch ( eventClass ) { case kEventClassHIObject: switch ( eventKind ) { case kEventHIObjectConstruct: { data = (MTViewData*)malloc(sizeof(MTViewData)); err = GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef*), NULL, &data->theView ); require_noerr( err, ParameterMissing ); SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(MTViewData), &data ); } break; case kEventHIObjectInitialize: err = CallNextEventHandler( inCallRef, inEvent ); if ( err == noErr ) { Rect bounds; // Extract the bounds from the initialization event that we set up err = GetEventParameter(inEvent, kCanvasBoundsParam, typeQDRectangle, NULL, sizeof(Rect), NULL, &bounds); require_noerr(err, ParameterMissing); SetControlBounds(data->theView, &bounds); // Also initialize our MTViewData data->theImage = LoadImageFromMainBundle(CFSTR("Peter.png")); data->thePath = NULL; } break; case kEventHIObjectDestruct: free(inUserData); break; } break; // kEventClassHIObject case kEventClassControl: switch ( eventKind ) { case kEventControlDraw: { CGContextRef ctx; GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx ); // CallNextEventHandler(inCallRef, inEvent); // Erase old content DrawTheMTView(ctx, data); err = noErr; } break; case kEventControlHitTest: GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &where); part = kControlContentMetaPart; SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(ControlPartCode), &part); err = noErr; break; case kEventControlTrack: DoTheTracking(inEvent, data); break; } break; // kEventClassControl } ParameterMissing: return err; }
static void TkMacOSXDrawControl( MacButton *mbPtr, /* Mac button. */ GWorldPtr destPort, /* Off screen GWorld. */ GC gc, /* The GC we are drawing into - needed for the * bevel button */ Pixmap pixmap) /* The pixmap we are drawing into - needed for * the bevel button */ { TkButton *butPtr = (TkButton *) mbPtr; TkWindow *winPtr; Rect paneRect, cntrRect; int active, enabled; int rebuild; winPtr = (TkWindow *) butPtr->tkwin; paneRect.left = winPtr->privatePtr->xOff; paneRect.top = winPtr->privatePtr->yOff; paneRect.right = paneRect.left + Tk_Width(butPtr->tkwin); paneRect.bottom = paneRect.top + Tk_Height(butPtr->tkwin); cntrRect = paneRect; /* cntrRect.left += butPtr->inset; cntrRect.top += butPtr->inset; cntrRect.right -= butPtr->inset; cntrRect.bottom -= butPtr->inset; */ cntrRect.left += DEF_INSET_LEFT; cntrRect.top += DEF_INSET_TOP; cntrRect.right -= DEF_INSET_RIGHT; cntrRect.bottom -= DEF_INSET_BOTTOM; /* * The control has been previously initialised. * It may need to be re-initialised */ #if 0 rebuild = (winPtr->flags & TK_REBUILD_TOPLEVEL); winPtr->flags &= ~TK_REBUILD_TOPLEVEL; #else rebuild = 0; #endif if (mbPtr->flags) { MacControlParams params; TkMacOSXComputeControlParams(butPtr, ¶ms); if (rebuild || bcmp(¶ms, &mbPtr->params, sizeof(params))) { /* * The type of control has changed. * Clean it up and clear the flag. */ if (mbPtr->userPane) { DisposeControl(mbPtr->userPane); mbPtr->userPane = NULL; mbPtr->control = NULL; } mbPtr->flags = 0; } } if (!(mbPtr->flags & CONTROL_INITIALIZED)) { if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap, &paneRect, &cntrRect)) { return; } } SetControlBounds(mbPtr->userPane, &paneRect); SetControlBounds(mbPtr->control, &cntrRect); if (!mbPtr->useTkText) { Str255 controlTitle; ControlFontStyleRec fontStyle; Tk_Font font; int len; if (((mbPtr->info.image == NULL) && (mbPtr->info.bitmap == None)) || (mbPtr->info.compound != COMPOUND_NONE)) { len = TkFontGetFirstTextLayout(butPtr->textLayout, &font, (char*) controlTitle); controlTitle[len] = 0; } else { len = 0; controlTitle[0] = 0; } if (rebuild || bcmp(mbPtr->controlTitle, controlTitle, len+1)) { CFStringRef cf = CFStringCreateWithCString(NULL, (char*) controlTitle, kCFStringEncodingUTF8); if (cf != NULL) { SetControlTitleWithCFString(mbPtr->control, cf); CFRelease(cf); } bcopy(controlTitle, mbPtr->controlTitle, len+1); } if (len) { TkMacOSXInitControlFontStyle(font, &fontStyle); if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) { ChkErr(SetControlFontStyle, mbPtr->control, &fontStyle); bcopy(&fontStyle, &mbPtr->fontStyle, sizeof(fontStyle)); } } } if (mbPtr->params.isBevel) { /* * Initialiase the image/button parameters. */ SetupBevelButton(mbPtr, mbPtr->control, destPort, gc, pixmap); } if (butPtr->flags & SELECTED) { SetControlValue(mbPtr->control, 1); #if 0 } else if (butPtr->flags & TRISTATED) { SetControlValue(mbPtr->control, 2); #endif } else { SetControlValue(mbPtr->control, 0); } active = ((mbPtr->flags & ACTIVE) != 0); if (active != IsControlActive(mbPtr->control)) { if (active) { ChkErr(ActivateControl, mbPtr->control); } else { ChkErr(DeactivateControl, mbPtr->control); } } enabled = !(butPtr->state == STATE_DISABLED); if (enabled != IsControlEnabled(mbPtr->control)) { if (enabled) { ChkErr(EnableControl, mbPtr->control); } else { ChkErr(DisableControl, mbPtr->control); } } if (active && enabled) { if (butPtr->state == STATE_ACTIVE) { if (mbPtr->params.isBevel) { HiliteControl(mbPtr->control, kControlButtonPart); } else { switch (butPtr->type) { case TYPE_BUTTON: HiliteControl(mbPtr->control, kControlButtonPart); break; case TYPE_RADIO_BUTTON: HiliteControl(mbPtr->control, kControlRadioButtonPart); break; case TYPE_CHECK_BUTTON: HiliteControl(mbPtr->control, kControlCheckBoxPart); break; } } } else { HiliteControl(mbPtr->control, kControlNoPart); } } UpdateControlColors(mbPtr); if (butPtr->type == TYPE_BUTTON && !mbPtr->params.isBevel) { Boolean isDefault; if (butPtr->defaultState == STATE_ACTIVE) { isDefault = true; } else { isDefault = false; } ChkErr(SetControlData, mbPtr->control, kControlNoPart, kControlPushButtonDefaultTag, sizeof(isDefault), &isDefault); } if (mbPtr->flags & FIRST_DRAW) { ShowControl(mbPtr->userPane); ShowControl(mbPtr->control); mbPtr->flags ^= FIRST_DRAW; } else { SetControlVisibility(mbPtr->control, true, true); Draw1Control(mbPtr->userPane); } if (mbPtr->params.isBevel) { if (mbPtr->bevelButtonContent.contentType == kControlContentPictHandle) { KillPicture(mbPtr->bevelButtonContent.u.picture); } } }
OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p_event, void *p_data) { OSStatus t_status; t_status = eventNotHandledErr; UInt32 t_event_class; t_event_class = GetEventClass(p_event); UInt32 t_event_kind; t_event_kind = GetEventKind(p_event); HIRevolutionStackViewData *t_context; t_context = (HIRevolutionStackViewData *)p_data; switch(t_event_class) { case 'revo': switch(t_event_kind) { case 'rlnk': GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); break; } break; case kEventClassHIObject: switch(t_event_kind) { case kEventHIObjectConstruct: { HIRevolutionStackViewData *t_data; t_data = new HIRevolutionStackViewData; t_data -> stack = NULL; GetEventParameter(p_event, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef), NULL, (HIObjectRef *)&t_data -> view); SetEventParameter(p_event, kEventParamHIObjectInstance, typeVoidPtr, sizeof(HIRevolutionStackViewData *), &t_data); t_status = noErr; } break; case kEventHIObjectInitialize: { GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); Rect t_bounds; t_bounds . left = 0; // MW-2011-09-12: [[ MacScroll ]] Make sure the top of the HIView takes into // account the scroll. t_bounds . top = -t_context -> stack -> getscroll(); t_bounds . right = t_context -> stack -> getrect() . width; t_bounds . bottom = t_context -> stack -> getrect() . height; SetControlBounds((ControlRef)t_context -> view, &t_bounds); t_status = noErr; } break; case kEventHIObjectDestruct: { delete t_context; t_status = noErr; } break; } break; case kEventClassControl: switch(t_event_kind) { case kEventControlInitialize: { t_status = noErr; } break; case kEventControlDraw: { CGContextRef t_graphics; GetEventParameter(p_event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &t_graphics); RgnHandle t_dirty_rgn; GetEventParameter(p_event, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_dirty_rgn); if (t_context -> stack != NULL) { // Compute the clip region for players. RgnHandle t_clip_rgn, t_rect_rgn; t_clip_rgn = NULL; t_rect_rgn = NULL; for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) { MCRectangle t_rect; Rect t_mac_rect; t_rect = t_player -> getactiverect(); if (t_clip_rgn == NULL) { t_clip_rgn = NewRgn(); CopyRgn((RgnHandle)t_dirty_rgn, t_clip_rgn); t_rect_rgn = NewRgn(); } SetRect(&t_mac_rect, t_rect . x, t_rect . y, t_rect . x + t_rect . width, t_rect . y + t_rect . height); RectRgn(t_rect_rgn, &t_mac_rect); DiffRgn(t_clip_rgn, t_rect_rgn, t_clip_rgn); } // We don't need the rect rgn anymore. if (t_rect_rgn != NULL) DisposeRgn(t_rect_rgn); // If the clip region is non-nil, then apply it. if (t_clip_rgn != NULL) { // As we can't clip to empty path, if the region is empty, we set the context // to nil. if (!EmptyRgn(t_clip_rgn)) { HIShapeRef t_shape; t_shape = HIShapeCreateWithQDRgn(t_clip_rgn); HIShapeReplacePathInCGContext(t_shape, t_graphics); CGContextClip(t_graphics); CFRelease(t_shape); } else t_graphics = nil; DisposeRgn(t_clip_rgn); } // If the graphics context is non-nil (i.e. we aren't completely occluded) then // draw something. if (t_graphics != nil) { // HIView gives us a context in top-left origin mode which isn't so good // for our CG rendering so, revert back to bottom-left. CGContextScaleCTM(t_graphics, 1.0, -1.0); CGContextTranslateCTM(t_graphics, 0.0, -t_context -> stack -> getcurcard() -> getrect() . height); // Save the context state CGContextSaveGState(t_graphics); // If we don't have an update pixmap, then use redrawwindow. if (s_update_pixmap == nil) { MCMacStackSurface t_surface(t_context -> stack, (MCRegionRef)t_dirty_rgn, t_graphics); t_context -> stack -> redrawwindow(&t_surface, (MCRegionRef)t_dirty_rgn); } else { int32_t t_height; t_height = t_context -> stack -> getcurcard() -> getrect() . height; MCRectangle t_rect; t_rect = MCRegionGetBoundingBox((MCRegionRef)t_dirty_rgn); CGRect t_area; t_area = CGRectMake(t_rect . x, t_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height); CGContextClearRect(t_graphics, t_area); void *t_bits; uint32_t t_stride; MCscreen -> lockpixmap(s_update_pixmap, t_bits, t_stride); MCMacRenderBitsToCG(t_graphics, t_area, t_bits, t_stride, t_context -> stack -> getwindowshape() != nil ? true : false); MCscreen -> unlockpixmap(s_update_pixmap, t_bits, t_stride); } // Restore the context state CGContextRestoreGState(t_graphics); } // MW-2011-11-23: [[ Bug ]] Force a redraw of the players on the stack // after we've drawn the rest of the content. This ensures players // which are just appearing don't disappear behind said content. for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) MCDoAction((MovieController)t_player -> getMovieController(), mcActionDraw, t_context -> stack -> getqtwindow()); } t_status = noErr; } break; case kEventControlHitTest: break; case kEventControlGetPartRegion: { ControlPartCode t_part; GetEventParameter(p_event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &t_part); RgnHandle t_region; GetEventParameter(p_event, kEventParamControlRegion, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_region); } break; case kEventControlHiliteChanged: break; case kEventControlActivate: break; case kEventControlDeactivate: break; } break; } return t_status; }