📄 tkmacbutton.c
字号:
false, 0, 0, kControlBehaviorOffsetContents << 16 | kControlContentPictHandle, kControlBevelButtonNormalBevelProc, (SInt32) 0); EmbedControl(medBevelHandle, userPaneHandle); largeBevelHandle = NewControl(windowRef, &geometry, "\p", false, 0, 0, kControlBehaviorOffsetContents << 16 | kControlContentPictHandle, kControlBevelButtonLargeBevelProc, (SInt32) 0); EmbedControl(largeBevelHandle, userPaneHandle); bevelButtonContent.contentType = kControlContentPictHandle; smallStickyBevelHandle = NewControl(windowRef, &geometry, "\p", false, 0, 0, (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 | kControlContentPictHandle, kControlBevelButtonSmallBevelProc, (SInt32) 0); EmbedControl(smallStickyBevelHandle, userPaneHandle); medStickyBevelHandle = NewControl(windowRef, &geometry, "\p", false, 0, 0, (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 | kControlContentPictHandle, kControlBevelButtonNormalBevelProc, (SInt32) 0); EmbedControl(medStickyBevelHandle, userPaneHandle); largeStickyBevelHandle = NewControl(windowRef, &geometry, "\p", false, 0, 0, (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 | kControlContentPictHandle, kControlBevelButtonLargeBevelProc, (SInt32) 0); EmbedControl(largeStickyBevelHandle, userPaneHandle); picParams.version = -2; picParams.hRes = 0x00480000; picParams.vRes = 0x00480000; picParams.srcRect.top = 0; picParams.srcRect.left = 0; ((CWindowPeek) windowRef)->visible = true; } else { buttonHandle = NewControl(windowRef, &geometry, "\p", false, 1, 0, 1, pushButProc, (SInt32) 0); checkHandle = NewControl(windowRef, &geometry, "\p", false, 1, 0, 1, checkBoxProc, (SInt32) 0); radioHandle = NewControl(windowRef, &geometry, "\p", false, 1, 0, 1, radioButProc, (SInt32) 0); ((CWindowPeek) windowRef)->visible = true; buttonTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab)); checkTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab)); radioTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab)); } /* * Remove our window from the window list. This way our * applications and others will not be confused that this * window exists - but no one knows about it. */ windowList = (CWindowPeek) LMGetWindowList(); if (windowList == (CWindowPeek) windowRef) { LMSetWindowList((WindowRef) windowList->nextWindow); } else { while ((windowList != NULL) && (windowList->nextWindow != (CWindowPeek) windowRef)) { windowList = windowList->nextWindow; } if (windowList != NULL) { windowList->nextWindow = windowList->nextWindow->nextWindow; } } ((CWindowPeek) windowRef)->nextWindow = NULL; /* * Create an exit handler to clean up this mess if we our * unloaded etc. We need to remember the windows portPixMap * so it isn't leaked. * * TODO: The ButtonExitProc doesn't currently work and the * code it includes will crash the Mac on exit from Tk. oldPixPtr = ((CWindowPeek) windowRef)->port.portPixMap; Tcl_CreateExitHandler(ButtonExitProc, (ClientData) NULL); */}/* *-------------------------------------------------------------- * * SetupBevelButton -- * * Sets up the Bevel Button with image by copying the * source image onto the PicHandle for the button. * * Results: * None * * Side effects: * The image or bitmap for the button is copied over to a picture. * *-------------------------------------------------------------- */voidSetupBevelButton( TkButton *butPtr, /* Tk button. */ ControlRef controlHandle, /* The control to set this picture to */ 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 */ ){ int height, width; ControlButtonGraphicAlignment theAlignment; SetPort((GrafPtr) destPort); if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); } else { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); } if ((butPtr->width > 0) && (butPtr->width < width)) { width = butPtr->width; } if ((butPtr->height > 0) && (butPtr->height < height)) { height = butPtr->height; } picParams.srcRect.right = width; picParams.srcRect.bottom = height; bevelButtonContent.u.picture = OpenCPicture(&picParams); /* * 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->selectImage != NULL) && (butPtr->flags & SELECTED)) { Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height, pixmap, 0, 0); } else if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XSetClipOrigin(butPtr->display, gc, 0, 0); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, (unsigned int) width, (unsigned int) height, 0, 0, 1); } ClosePicture(); SetControlData(controlHandle, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &bevelButtonContent); if (butPtr->anchor == TK_ANCHOR_N) { theAlignment = kControlBevelButtonAlignTop; } else if (butPtr->anchor == TK_ANCHOR_NE) { theAlignment = kControlBevelButtonAlignTopRight; } else if (butPtr->anchor == TK_ANCHOR_E) { theAlignment = kControlBevelButtonAlignRight; } else if (butPtr->anchor == TK_ANCHOR_SE) { theAlignment = kControlBevelButtonAlignBottomRight; } else if (butPtr->anchor == TK_ANCHOR_S) { theAlignment = kControlBevelButtonAlignBottom; } else if (butPtr->anchor == TK_ANCHOR_SW) { theAlignment = kControlBevelButtonAlignBottomLeft; } else if (butPtr->anchor == TK_ANCHOR_W) { theAlignment = kControlBevelButtonAlignLeft; } else if (butPtr->anchor == TK_ANCHOR_NW) { theAlignment = kControlBevelButtonAlignTopLeft; } else if (butPtr->anchor == TK_ANCHOR_CENTER) { theAlignment = kControlBevelButtonAlignCenter; } SetControlData(controlHandle, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment);}/* *-------------------------------------------------------------- * * SetUserPaneDrawProc -- * * Utility function to add a UserPaneDrawProc * to a userPane control. From MoreControls code * from Apple DTS. * * Results: * MacOS system error. * * Side effects: * The user pane gets a new UserPaneDrawProc. * *-------------------------------------------------------------- */pascal OSErr SetUserPaneDrawProc ( ControlRef control, ControlUserPaneDrawProcPtr upp){ ControlUserPaneDrawUPP myControlUserPaneDrawUPP; myControlUserPaneDrawUPP = NewControlUserPaneDrawProc(upp); return SetControlData (control, kControlNoPart, kControlUserPaneDrawProcTag, sizeof(myControlUserPaneDrawUPP), (Ptr) &myControlUserPaneDrawUPP);}/* *-------------------------------------------------------------- * * SetUserPaneSetUpSpecialBackgroundProc -- * * Utility function to add a UserPaneBackgroundProc * to a userPane control * * Results: * MacOS system error. * * Side effects: * The user pane gets a new UserPaneBackgroundProc. * *-------------------------------------------------------------- */pascal OSErrSetUserPaneSetUpSpecialBackgroundProc( ControlRef control, ControlUserPaneBackgroundProcPtr upp){ ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP; myControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundProc(upp); return SetControlData (control, kControlNoPart, kControlUserPaneBackgroundProcTag, sizeof(myControlUserPaneBackgroundUPP), (Ptr) &myControlUserPaneBackgroundUPP);}/* *-------------------------------------------------------------- * * UserPaneDraw -- * * This function draws the background of the user pane that will * lie under checkboxes and radiobuttons. * * Results: * None. * * Side effects: * The user pane gets updated to the current color. * *-------------------------------------------------------------- */pascal voidUserPaneDraw( ControlRef control, ControlPartCode cpc){ Rect contrlRect = (**control).contrlRect; RGBBackColor (&gUserPaneBackground); EraseRect (&contrlRect);}/* *-------------------------------------------------------------- * * UserPaneBackgroundProc -- * * This function sets up the background of the user pane that will * lie under checkboxes and radiobuttons. * * Results: * None. * * Side effects: * The user pane background gets set to the current color. * *-------------------------------------------------------------- */pascal voidUserPaneBackgroundProc( ControlHandle, ControlBackgroundPtr info){ if (info->colorDevice) { RGBBackColor (&gUserPaneBackground); }}/* *-------------------------------------------------------------- * * UpdateControlColors -- * * This function will review the colors used to display * a Macintosh button. If any non-standard colors are * used we create a custom palette for the button, populate * with the colors for the button and install the palette. * * Under Appearance, we just set the pointer that will be * used by the UserPaneDrawProc. * * Results: * None. * * Side effects: * The Macintosh control may get a custom palette installed. * *-------------------------------------------------------------- */static intUpdateControlColors( TkButton *butPtr, ControlRef controlHandle, CCTabHandle ccTabHandle, RGBColor *saveColorPtr){ XColor *xcolor; /* * Under Appearance we cannot change the background of the * button itself. However, the color we are setting is the color * of the containing userPane. This will be the color that peeks * around the rounded corners of the button. * We make this the highlightbackground rather than the background, * because if you color the background of a frame containing a * button, you usually also color the highlightbackground as well, * or you will get a thin grey ring around the button. */ if (TkMacHaveAppearance() && (butPtr->type == TYPE_BUTTON)) { xcolor = Tk_3DBorderColor(butPtr->highlightBorder); } else { xcolor = Tk_3DBorderColor(butPtr->normalBorder); } if (TkMacHaveAppearance()) { TkSetMacColor(xcolor->pixel, &gUserPaneBackground); } else { (**ccTabHandle).ccSeed = 0; (**ccTabHandle).ccRider = 0; (**ccTabHandle).ctSize = 3; (**ccTabHandle).ctTable[0].value = cBodyColor; TkSetMacColor(xcolor->pixel, &(**ccTabHandle).ctTable[0].rgb); (**ccTabHandle).ctTable[1].value = cTextColor; TkSetMacColor(butPtr->normalFg->pixel, &(**ccTabHandle).ctTable[1].rgb); (**ccTabHandle).ctTable[2].value = cFrameColor; TkSetMacColor(butPtr->highlightColorPtr->pixel, &(**ccTabHandle).ctTable[2].rgb); SetControlColor(controlHandle, ccTabHandle); if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && ((butPtr->type == TYPE_CHECK_BUTTON) || (butPtr->type == TYPE_RADIO_BUTTON))) { RGBColor newColor; TkSetMacColor(xcolor->pixel, &newColor); ChangeBackgroundWindowColor((**controlHandle).contrlOwner, newColor, saveColorPtr); return true; } } return false;}/* *-------------------------------------------------------------- * * ChangeBackgroundWindowColor -- * * This procedure will change the background color entry * in the Window's colortable. The system isn't notified * of the change. This call should only be used to fool * the drawing routines for checkboxes and radiobuttons. * Any change should be temporary and be reverted after * the widget is drawn. * * Results: * None. * * Side effects: * The Window's color table will be adjusted. * *-------------------------------------------------------------- */static voidChangeBackgroundWindowColor( WindowRef macintoshWindow, /* A Mac window whose color to change. */ RGBColor rgbColor, /* The new RGB Color for the background. */ RGBColor *oldColor) /* The old color of the background. */{ AuxWinHandle auxWinHandle; WCTabHandle winCTabHandle; short ctIndex; ColorSpecPtr rgbScan; GetAuxWin(macintoshWindow, &auxWinHandle); winCTabHandle = (WCTabHandle) ((**auxWinHandle).awCTable); /* * Scan through the color table until we find the content * (background) color for the window. Don't tell the system * about the change - it will generate damage and we will get * into an infinite loop. */ ctIndex = (**winCTabHandle).ctSize; while (ctIndex > -1) { rgbScan = ctIndex + (**winCTabHandle).ctTable; if (rgbScan->value == wContentColor) { *oldColor = rgbScan->rgb; rgbScan->rgb = rgbColor; break; } ctIndex--; }}/* *---------------------------------------------------------------------- * * ButtonExitProc -- * * This procedure is invoked just before the application exits. * It frees all of the control handles, our dummy window, etc. * * Results: * None. * * Side effects: * Memory is freed. * *---------------------------------------------------------------------- */static voidButtonExitProc(clientData) ClientData clientData; /* Not used. */{ Rect pixRect = {0, 0, 10, 10}; Rect rgnRect = {0, 0, 0, 0}; /* * Restore our dummy window to it's origional state by putting it * back in the window list and restoring it's bits. The destroy * the controls and window. */ ((CWindowPeek) windowRef)->nextWindow = (CWindowPeek) LMGetWindowList(); LMSetWindowList(windowRef); ((CWindowPeek) windowRef)->port.portPixMap = oldPixPtr; ((CWindowPeek) windowRef)->port.portRect = pixRect; RectRgn(((CWindowPeek) windowRef)->port.visRgn, &rgnRect); RectRgn(((CWindowPeek) windowRef)->strucRgn, &rgnRect); RectRgn(((CWindowPeek) windowRef)->updateRgn, &rgnRect); RectRgn(((CWindowPeek) windowRef)->contRgn, &rgnRect); PortChanged(windowRef); DisposeControl(buttonHandle); DisposeControl(checkHandle); DisposeControl(radioHandle); DisposeWindow(windowRef); windowRef = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -