diff options
Diffstat (limited to 'macosx/tkMacOSXButton.c')
-rw-r--r-- | macosx/tkMacOSXButton.c | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 6d89667..f134e56 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXButton.c,v 1.29 2007/10/15 20:52:47 hobbs Exp $ + * RCS: @(#) $Id: tkMacOSXButton.c,v 1.30 2007/11/08 14:25:59 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -21,6 +21,10 @@ #define DEFAULT_USE_TK_TEXT 0 +#define CONTROL_INITIALIZED 1 +#define FIRST_DRAW 2 +#define ACTIVE 4 + /* * Default insets for controls */ @@ -88,7 +92,6 @@ typedef struct { * Forward declarations for procedures defined later in this file: */ - static OSStatus SetUserPaneDrawProc(ControlRef control, ControlUserPaneDrawProcPtr upp); static OSStatus SetUserPaneSetUpSpecialBackgroundProc(ControlRef control, @@ -118,7 +121,6 @@ Tk_ClassProcs tkpButtonProcs = { static int bCount; -int tkPictureIsOpen; /* *---------------------------------------------------------------------- @@ -153,7 +155,7 @@ TkpCreateButton( macButtonPtr->controlTitle[0] = 0; macButtonPtr->controlTitle[1] = 0; bzero(&macButtonPtr->params, sizeof(macButtonPtr->params)); - bzero(&macButtonPtr->fontStyle,sizeof(macButtonPtr->fontStyle)); + bzero(&macButtonPtr->fontStyle, sizeof(macButtonPtr->fontStyle)); return (TkButton *)macButtonPtr; } @@ -180,7 +182,7 @@ void TkpDisplayButton( ClientData clientData) /* Information about widget. */ { - MacButton *macButtonPtr = (MacButton *)clientData; + MacButton *macButtonPtr = (MacButton *) clientData; TkButton *butPtr = (TkButton *) clientData; Tk_Window tkwin = butPtr->tkwin; CGrafPtr destPort, savePort; @@ -198,7 +200,6 @@ TkpDisplayButton( if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } - pixmap = (Pixmap) Tk_WindowId(tkwin); wasUsingControl = macButtonPtr->usingControl; @@ -712,7 +713,7 @@ TkpComputeButtonGeometry( } } - if (TkMacOSXComputeDrawParams(butPtr,&drawParams)) { + if (TkMacOSXComputeDrawParams(butPtr, &drawParams)) { xInset = butPtr->indicatorSpace + DEF_INSET_LEFT + DEF_INSET_RIGHT; yInset = DEF_INSET_TOP + DEF_INSET_BOTTOM; } else { @@ -829,7 +830,10 @@ TkMacOSXInitControl( return 1; } - mbPtr->flags |= (1 + 2); + mbPtr->flags |= (CONTROL_INITIALIZED | FIRST_DRAW); + if (IsWindowActive(mbPtr->windowRef)) { + mbPtr->flags |= ACTIVE; + } return 0; } @@ -863,6 +867,7 @@ TkMacOSXDrawControl( TkButton *butPtr = (TkButton *) mbPtr; TkWindow *winPtr; Rect paneRect, cntrRect; + int active, enabled; int rebuild; winPtr = (TkWindow *) butPtr->tkwin; @@ -913,7 +918,7 @@ TkMacOSXDrawControl( mbPtr->flags = 0; } } - if (!(mbPtr->flags & 1)) { + if (!(mbPtr->flags & CONTROL_INITIALIZED)) { if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap, &paneRect, &cntrRect)) { return; @@ -971,16 +976,23 @@ TkMacOSXDrawControl( SetControlValue(mbPtr->control, 0); } - if (!Tk_MacOSXIsAppInFront() || butPtr->state == STATE_DISABLED) { - HiliteControl(mbPtr->control, kControlInactivePart); - } else { - /* - * Use NoPart for normal and to ensure correct direct transition from - * disabled to active -state. [Bug 706446] - */ - - HiliteControl(mbPtr->control, kControlNoPart); - + 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); @@ -997,6 +1009,8 @@ TkMacOSXDrawControl( break; } } + } else { + HiliteControl(mbPtr->control, kControlNoPart); } } UpdateControlColors(mbPtr); @@ -1013,17 +1027,20 @@ TkMacOSXDrawControl( kControlPushButtonDefaultTag, sizeof(isDefault), &isDefault); } - if (mbPtr->flags & 2) { + if (mbPtr->flags & FIRST_DRAW) { ShowControl(mbPtr->userPane); ShowControl(mbPtr->control); - mbPtr->flags ^= 2; + mbPtr->flags ^= FIRST_DRAW; } else { SetControlVisibility(mbPtr->control, true, true); Draw1Control(mbPtr->userPane); } if (mbPtr->params.isBevel) { - KillPicture(mbPtr->bevelButtonContent.u.picture); + if (mbPtr->bevelButtonContent.contentType == + kControlContentPictHandle) { + KillPicture(mbPtr->bevelButtonContent.u.picture); + } } } @@ -1073,28 +1090,30 @@ SetupBevelButton( height = butPtr->height; } - portChanged = QDSwapPort(destPort, &savePort); - mbPtr->picParams.version = -2; - mbPtr->picParams.hRes = 0x00480000; - mbPtr->picParams.vRes = 0x00480000; - mbPtr->picParams.srcRect.top = 0; - mbPtr->picParams.srcRect.left = 0; - mbPtr->picParams.srcRect.right = width; - mbPtr->picParams.srcRect.bottom = height; - mbPtr->picParams.reserved1 = 0; - mbPtr->picParams.reserved2 = 0; - mbPtr->bevelButtonContent.contentType = kControlContentPictHandle; - mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams); - if (!mbPtr->bevelButtonContent.u.picture) { - TkMacOSXDbgMsg("OpenCPicture failed"); - } - tkPictureIsOpen = 1; + { + portChanged = QDSwapPort(destPort, &savePort); + mbPtr->picParams.version = -2; + mbPtr->picParams.hRes = 0x00480000; + mbPtr->picParams.vRes = 0x00480000; + mbPtr->picParams.srcRect.top = 0; + mbPtr->picParams.srcRect.left = 0; + mbPtr->picParams.srcRect.bottom = height; + mbPtr->picParams.srcRect.right = width; + mbPtr->picParams.reserved1 = 0; + mbPtr->picParams.reserved2 = 0; + mbPtr->bevelButtonContent.contentType = kControlContentPictHandle; + mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams); + if (!mbPtr->bevelButtonContent.u.picture) { + TkMacOSXDbgMsg("OpenCPicture failed"); + } + tkPictureIsOpen = 1; - /* - * 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. - */ + /* + * 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); @@ -1109,10 +1128,12 @@ SetupBevelButton( height, 0, 0, 1); } - ClosePicture(); - tkPictureIsOpen = 0; - if (portChanged) { - QDSwapPort(savePort, NULL); + { + ClosePicture(); + tkPictureIsOpen = 0; + if (portChanged) { + QDSwapPort(savePort, NULL); + } } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonContentTag, @@ -1360,12 +1381,18 @@ ButtonEventProc( XEvent *eventPtr) /* Information about event. */ { TkButton *buttonPtr = (TkButton *) clientData; + MacButton *mbPtr = (MacButton *) clientData; if (eventPtr->type == ActivateNotify || eventPtr->type == DeactivateNotify) { if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) { return; } + if (eventPtr->type == ActivateNotify) { + mbPtr->flags |= ACTIVE; + } else { + mbPtr->flags &= ~ACTIVE; + } if ((buttonPtr->flags & REDRAW_PENDING) == 0) { Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr); buttonPtr->flags |= REDRAW_PENDING; |