summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXButton.c
diff options
context:
space:
mode:
authordas <das>2007-11-09 06:26:53 (GMT)
committerdas <das>2007-11-09 06:26:53 (GMT)
commitb0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846 (patch)
tree40938979466c8caac1c03c907753bc43175304bd /macosx/tkMacOSXButton.c
parent455d9dc4b8b50ed064729851295535018eb99449 (diff)
downloadtk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.zip
tk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.tar.gz
tk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.tar.bz2
Backport from HEAD of Aqua changes from 2007-10-12 to 2007-11-09
Diffstat (limited to 'macosx/tkMacOSXButton.c')
-rw-r--r--macosx/tkMacOSXButton.c181
1 files changed, 114 insertions, 67 deletions
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index edd641a..c3205b5 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.2.2.18 2007/06/29 03:22:00 das Exp $
+ * RCS: @(#) $Id: tkMacOSXButton.c,v 1.2.2.19 2007/11/09 06:26:54 das Exp $
*/
#include "tkMacOSXPrivate.h"
@@ -21,6 +21,12 @@
#define DEFAULT_USE_TK_TEXT 0
+#define CONTROL_INITIALIZED 1
+#define FIRST_DRAW 2
+#define ACTIVE 4
+
+#define MAX_VALUE 1
+
/*
* Default insets for controls
*/
@@ -80,8 +86,6 @@ typedef struct {
* The following are used to store the image content for
* beveled buttons, i.e. buttons with images.
*/
- CCTabHandle tabHandle;
- Pixmap picPixmap;
ControlButtonContentInfo bevelButtonContent;
OpenCPicParams picParams;
} MacButton;
@@ -90,7 +94,6 @@ typedef struct {
* Forward declarations for procedures defined later in this file:
*/
-
static OSStatus SetUserPaneDrawProc(ControlRef control,
ControlUserPaneDrawProcPtr upp);
static OSStatus SetUserPaneSetUpSpecialBackgroundProc(ControlRef control,
@@ -120,7 +123,6 @@ Tk_ClassProcs tkpButtonProcs = {
static int bCount;
-int tkPictureIsOpen;
/*
*----------------------------------------------------------------------
@@ -154,16 +156,8 @@ TkpCreateButton(
macButtonPtr->control = NULL;
macButtonPtr->controlTitle[0] = 0;
macButtonPtr->controlTitle[1] = 0;
- macButtonPtr->picParams.version = -2;
- macButtonPtr->picParams.hRes = 0x00480000;
- macButtonPtr->picParams.vRes = 0x00480000;
- macButtonPtr->picParams.srcRect.top = 0;
- macButtonPtr->picParams.srcRect.left = 0;
- macButtonPtr->picParams.reserved1 = 0;
- macButtonPtr->picParams.reserved2 = 0;
- macButtonPtr->bevelButtonContent.contentType = kControlContentPictHandle;
bzero(&macButtonPtr->params, sizeof(macButtonPtr->params));
- bzero(&macButtonPtr->fontStyle,sizeof(macButtonPtr->fontStyle));
+ bzero(&macButtonPtr->fontStyle, sizeof(macButtonPtr->fontStyle));
return (TkButton *)macButtonPtr;
}
@@ -190,7 +184,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;
@@ -208,7 +202,6 @@ TkpDisplayButton(
if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
return;
}
-
pixmap = (Pixmap) Tk_WindowId(tkwin);
wasUsingControl = macButtonPtr->usingControl;
@@ -372,6 +365,12 @@ TkpDisplayButton(
if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
pixmap, imageXOffset, imageYOffset);
+#if 0
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height,
+ pixmap, imageXOffset, imageYOffset);
+#endif
} else {
Tk_RedrawImage(butPtr->image, 0, 0, width, height,
pixmap, imageXOffset, imageYOffset);
@@ -415,6 +414,12 @@ TkpDisplayButton(
if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
pixmap, imageXOffset, imageYOffset);
+#if 0
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height,
+ pixmap, imageXOffset, imageYOffset);
+#endif
} else {
Tk_RedrawImage(butPtr->image, 0, 0, width, height,
pixmap, imageXOffset, imageYOffset);
@@ -714,7 +719,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 {
@@ -831,7 +836,10 @@ TkMacOSXInitControl(
return 1;
}
- mbPtr->flags |= (1 + 2);
+ mbPtr->flags |= (CONTROL_INITIALIZED | FIRST_DRAW);
+ if (IsWindowActive(mbPtr->windowRef)) {
+ mbPtr->flags |= ACTIVE;
+ }
return 0;
}
@@ -865,6 +873,8 @@ TkMacOSXDrawControl(
TkButton *butPtr = (TkButton *) mbPtr;
TkWindow *winPtr;
Rect paneRect, cntrRect;
+ int active, enabled;
+ int rebuild;
winPtr = (TkWindow *) butPtr->tkwin;
@@ -890,12 +900,17 @@ TkMacOSXDrawControl(
* The control has been previously initialised.
* It may need to be re-initialised
*/
-
+#ifdef TK_REBUILD_TOPLEVEL
+ rebuild = (winPtr->flags & TK_REBUILD_TOPLEVEL);
+ winPtr->flags &= ~TK_REBUILD_TOPLEVEL;
+#else
+ rebuild = 0;
+#endif
if (mbPtr->flags) {
MacControlParams params;
TkMacOSXComputeControlParams(butPtr, &params);
- if (bcmp(&params, &mbPtr->params, sizeof(params))) {
+ if (rebuild || bcmp(&params, &mbPtr->params, sizeof(params))) {
/*
* The type of control has changed.
* Clean it up and clear the flag.
@@ -909,7 +924,7 @@ TkMacOSXDrawControl(
mbPtr->flags = 0;
}
}
- if (!(mbPtr->flags & 1)) {
+ if (!(mbPtr->flags & CONTROL_INITIALIZED)) {
if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap, &paneRect,
&cntrRect)) {
return;
@@ -933,7 +948,7 @@ TkMacOSXDrawControl(
len = 0;
controlTitle[0] = 0;
}
- if (bcmp(mbPtr->controlTitle, controlTitle, len+1)) {
+ if (rebuild || bcmp(mbPtr->controlTitle, controlTitle, len+1)) {
CFStringRef cf = CFStringCreateWithCString(NULL,
(char*) controlTitle, kCFStringEncodingUTF8);
@@ -961,20 +976,31 @@ TkMacOSXDrawControl(
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);
}
- 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);
@@ -991,6 +1017,8 @@ TkMacOSXDrawControl(
break;
}
}
+ } else {
+ HiliteControl(mbPtr->control, kControlNoPart);
}
}
UpdateControlColors(mbPtr);
@@ -1007,17 +1035,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);
+ }
}
}
@@ -1052,9 +1083,7 @@ SetupBevelButton(
int height, width;
ControlButtonGraphicAlignment theAlignment;
CGrafPtr savePort;
- Boolean portChanged;
-
- portChanged = QDSwapPort(destPort, &savePort);
+ Boolean portChanged = false;
if (butPtr->image != None) {
Tk_SizeOfImage(butPtr->image, &width, &height);
@@ -1069,27 +1098,38 @@ SetupBevelButton(
height = butPtr->height;
}
- mbPtr->picParams.srcRect.right = width;
- mbPtr->picParams.srcRect.bottom = height;
-
- /*
- * Set the flag to circumvent clipping and bounds problems with OS 10.0.4
- */
-
- 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);
+#if 0
+ } else if (butPtr->tristateImage != NULL && (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height, pixmap, 0,
+ 0);
+#endif
} else if (butPtr->image != NULL) {
Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0);
} else {
@@ -1098,11 +1138,16 @@ SetupBevelButton(
height, 0, 0, 1);
}
- ClosePicture();
- tkPictureIsOpen = 0;
-
+ {
+ ClosePicture();
+ tkPictureIsOpen = 0;
+ if (portChanged) {
+ QDSwapPort(savePort, NULL);
+ }
+ }
ChkErr(SetControlData, controlHandle, kControlButtonPart,
- kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo),
+ kControlBevelButtonContentTag,
+ sizeof(ControlButtonContentInfo),
(char *) &mbPtr->bevelButtonContent);
if (butPtr->anchor == TK_ANCHOR_N) {
@@ -1124,7 +1169,6 @@ SetupBevelButton(
} else if (butPtr->anchor == TK_ANCHOR_CENTER) {
theAlignment = kControlBevelButtonAlignCenter;
}
-
ChkErr(SetControlData, controlHandle, kControlButtonPart,
kControlBevelButtonGraphicAlignTag,
sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment);
@@ -1146,9 +1190,6 @@ SetupBevelButton(
kControlBevelButtonTextPlaceTag,
sizeof(ControlButtonTextPlacement), (char *) &thePlacement);
}
- if (portChanged) {
- QDSwapPort(savePort, NULL);
- }
}
/*
@@ -1350,12 +1391,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;
@@ -1419,13 +1466,13 @@ TkMacOSXComputeControlParams(
|| (butPtr->indicatorOn)) {
paramsPtr->initialValue = 1;
paramsPtr->minValue = 0;
- paramsPtr->maxValue = 1;
+ paramsPtr->maxValue = MAX_VALUE;
paramsPtr->procID = kControlRadioButtonProc;
} else {
paramsPtr->initialValue = 0;
paramsPtr->minValue = kControlBehaviorOffsetContents |
kControlBehaviorSticky | kControlContentPictHandle;
- paramsPtr->maxValue = 1;
+ paramsPtr->maxValue = MAX_VALUE;
if (butPtr->borderWidth <= 2) {
paramsPtr->procID = kControlBevelButtonSmallBevelProc;
} else if (butPtr->borderWidth == 3) {
@@ -1441,13 +1488,13 @@ TkMacOSXComputeControlParams(
|| (butPtr->indicatorOn)) {
paramsPtr->initialValue = 1;
paramsPtr->minValue = 0;
- paramsPtr->maxValue = 1;
+ paramsPtr->maxValue = MAX_VALUE;
paramsPtr->procID = kControlCheckBoxProc;
} else {
paramsPtr->initialValue = 0;
paramsPtr->minValue = kControlBehaviorOffsetContents |
kControlBehaviorSticky | kControlContentPictHandle;
- paramsPtr->maxValue = 1;
+ paramsPtr->maxValue = MAX_VALUE;
if (butPtr->borderWidth <= 2) {
paramsPtr->procID = kControlBevelButtonSmallBevelProc;
} else if (butPtr->borderWidth == 3) {