summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-01-24 16:39:45 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-01-24 16:39:45 (GMT)
commit42281930a0d067addb1f42fa5a23013fb2269445 (patch)
tree10d62b51b5eb64ff379c1b3ee150270815ae75e8 /macosx
parentd0320c59a7fcac67833160ecaf102a864df31869 (diff)
downloadtk-42281930a0d067addb1f42fa5a23013fb2269445.zip
tk-42281930a0d067addb1f42fa5a23013fb2269445.tar.gz
tk-42281930a0d067addb1f42fa5a23013fb2269445.tar.bz2
Commiting HITheme implementation obuttons; deferring scrolling for now because no adequate solution, even using themed scrolling via ttk, exists
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXButton.c2044
-rw-r--r--macosx/tkMacOSXDraw.c22
-rw-r--r--macosx/tkMacOSXMenubutton.c994
-rw-r--r--macosx/tkMacOSXPrivate.h3
4 files changed, 1689 insertions, 1374 deletions
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index a84ac97..6cb4f56 100644
--- a/macosx/tkMacOSXButton.c
+++ b/macosx/tkMacOSXButton.c
@@ -5,12 +5,14 @@
* button widgets.
*
* Copyright (c) 1996-1997 by Sun Microsystems, Inc.
- * Copyright 2001-2009, Apple Inc.
- * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
- * Copyright 2014 Marc Culler.
+ * Copyright 2001, Apple Computer, Inc.
+ * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net>
+ * Copyright 2007 Revar Desmera.
+ * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
*/
#include "tkMacOSXPrivate.h"
@@ -18,189 +20,151 @@
#include "tkMacOSXFont.h"
#include "tkMacOSXDebug.h"
-/*
-#ifdef TK_MAC_DEBUG
-#define TK_MAC_DEBUG_BUTTON
-#endif
-*/
-static NSRect TkMacOSXGetButtonFrame(TkButton *butPtr);
+#define FIRST_DRAW 2
+#define ACTIVE 4
+
/*
- * A subclass of NSButton with sanity checking:
- * NSButtons created by Tk will have their tag set to a pointer to the TkButton
- * which manages the NSButton. This allows a TkNSButton to be aware of the
- * state of its Tk parent. This subclass overrides the drawRect method
- * so that it will not draw itself unless the NSButton frame matches
- * the frame which was installed by DisplayButton, and the TkButton is
- * mapped. Also, it will not draw anything if the widget is completely
- * outside of its container.
+ * Default insets for controls
*/
-@interface TkNSButton: NSButton
-- (void)drawRect:(NSRect)dirtyRect;
-@end
-
-@implementation TkNSButton
-
- - (void)drawRect:(NSRect)dirtyRect
- {
- NSInteger tag = [self tag];
- if ( tag != -1) {
- TkButton *butPtr = (TkButton *)tag;
- MacDrawable* macWin = (MacDrawable *)butPtr;
- NSRect Tkframe = TkMacOSXGetButtonFrame(butPtr);
- Tk_Window tkwin = butPtr->tkwin;
- /* Do not draw if the widget is misplaced or unmapped. */
- if ( NSIsEmptyRect(Tkframe) ||
- ! macWin->winPtr->flags & TK_MAPPED ||
- ! NSEqualRects(Tkframe, [self frame])
- ) {
- return;
- }
- /* Do not draw if the widget is completely outside of its parent, or within 20 pixels of the lower border; this prevents buttons from being drawn on peer widgets as scrolling occurs. */
- if (tkwin) {
- int parent_height = Tk_Height(Tk_Parent(tkwin));
- int widget_height = Tk_Height(tkwin);
- int y = Tk_Y(tkwin);
- if ( y > parent_height - 20 || y + widget_height < 0 ) {
- return;
- }
+#define DEF_INSET_LEFT 2
+#define DEF_INSET_RIGHT 2
+#define DEF_INSET_TOP 2
+#define DEF_INSET_BOTTOM 4
- /* Do not draw if the widget is completely outside of its parent, or within 20 pixels of the right border; this prevents buttons from being drawn on peer widgets as scrolling occurs. */
- int parent_width = Tk_Width(Tk_Parent(tkwin));
- int widget_width = Tk_Width(tkwin);
- int x = Tk_X(tkwin);
- if (x > parent_width - 20 || x < 0) {
- return;
- }
+/*
+ * Some defines used to control what type of control is drawn.
+ */
- }
- }
- [super drawRect:dirtyRect];
- }
+#define DRAW_LABEL 0 /* Labels are treated genericly. */
+#define DRAW_CONTROL 1 /* Draw using the Native control. */
+#define DRAW_CUSTOM 2 /* Make our own button drawing. */
+#define DRAW_BEVEL 3
-@end
+/*
+ * The delay in milliseconds between pulsing default button redraws.
+ */
+#define PULSE_TIMER_MSECS 62 /* Largest value that didn't look stuttery */
+/*
+ * Declaration of Mac specific button structure.
+ */
-typedef struct MacButton {
- TkButton info;
- TkNSButton *button;
- NSImage *image, *selectImage, *tristateImage;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- int fix;
-#endif
-} MacButton;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
+typedef struct {
+ int drawType;
+ Tk_3DBorder border;
+ int relief;
+ int offset; /* 0 means this is a normal widget. 1 means
+ * it is an image button, so we offset the
+ * image to make the button appear to move
+ * up and down as the relief changes. */
+ GC gc;
+ int hasImageOrBitmap;
+} DrawParams;
-int tkMacOSXUseCompatibilityMetrics = 1;
+typedef struct {
+ TkButton info; /* Generic button info */
+ int id;
+ int usingControl;
+ int useTkText;
+ int flags; /* Initialisation status */
+ ThemeButtonKind btnkind;
+ HIThemeButtonDrawInfo drawinfo;
+ HIThemeButtonDrawInfo lastdrawinfo;
+ DrawParams drawParams;
+ Tcl_TimerToken defaultPulseHandler;
+} MacButton;
/*
- * Use the following heuristic conversion constants to make NSButton-based
- * widget metrics match up with the old Carbon control buttons (for the
- * default Lucida Grande 13 font).
+ * Forward declarations for procedures defined later in this file:
*/
-#define NATIVE_BUTTON_INSET 2
-#define NATIVE_BUTTON_EXTRA_H 2
-
-typedef struct {
- int trimW, trimH, inset, shrinkH, offsetX, offsetY;
-} BoundsFix;
-
-#define fixForTypeStyle(type, style) ( \
- type == NSSwitchButton ? 0 : \
- type == NSRadioButton ? 1 : \
- style == NSRoundedBezelStyle ? 2 : \
- style == NSRegularSquareBezelStyle ? 3 : \
- style == NSShadowlessSquareBezelStyle ? 4 : \
- INT_MIN)
-
-static const BoundsFix boundsFixes[] = {
- [fixForTypeStyle(NSSwitchButton,0)] = { 2, 2, -1, 0, 2, 1 },
- [fixForTypeStyle(NSRadioButton,0)] = { 0, 2, -1, 0, 1, 1 },
- [fixForTypeStyle(0,NSRoundedBezelStyle)] = { 28, 16, -6, 0, 0, 3 },
- [fixForTypeStyle(0,NSRegularSquareBezelStyle)] = { 28, 15, -2, -1 },
- [fixForTypeStyle(0,NSShadowlessSquareBezelStyle)] = { 2, 2 },
-};
-#endif
+static void ButtonBackgroundDrawCB (const HIRect *btnbounds, MacButton *ptr,
+ SInt16 depth, Boolean isColorDev);
+static void ButtonContentDrawCB (const HIRect *bounds, ThemeButtonKind kind,
+ const HIThemeButtonDrawInfo *info, MacButton *ptr, SInt16 depth,
+ Boolean isColorDev);
+static void ButtonEventProc(ClientData clientData, XEvent *eventPtr);
+static void TkMacOSXComputeButtonParams (TkButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo* drawinfo);
+static int TkMacOSXComputeButtonDrawParams (TkButton * butPtr, DrawParams * dpPtr);
+static void TkMacOSXDrawButton (MacButton *butPtr,
+ GC gc, Pixmap pixmap);
+static void DrawButtonImageAndText(TkButton* butPtr);
+static void PulseDefaultButtonProc(ClientData clientData);
-static void DisplayNativeButton(TkButton *butPtr);
-static void ComputeNativeButtonGeometry(TkButton *butPtr);
-static void DisplayUnixButton(TkButton *butPtr);
-static void ComputeUnixButtonGeometry(TkButton *butPtr);
/*
* The class procedure table for the button widgets.
*/
-Tk_ClassProcs tkpButtonProcs = {
+const Tk_ClassProcs tkpButtonProcs = {
sizeof(Tk_ClassProcs), /* size */
TkButtonWorldChanged, /* worldChangedProc */
- NULL, /* createProc */
- NULL /* modalProc */
};
-
+static int bCount;
+
/*
*----------------------------------------------------------------------
*
- * TkpCreateButton --
+ * TkpButtonSetDefaults --
*
- * Allocate a new TkButton structure.
+ * This procedure is invoked before option tables are created for
+ * buttons. It modifies some of the default values to match the current
+ * values defined for this platform.
*
* Results:
- * Returns a newly allocated TkButton structure.
+ * Some of the default values in *specPtr are modified.
*
* Side effects:
- * Registers an event handler for the widget.
+ * Updates some of.
*
*----------------------------------------------------------------------
*/
-TkButton *
-TkpCreateButton(
- Tk_Window tkwin)
+void
+TkpButtonSetDefaults()
{
- MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
-
- macButtonPtr->button = nil;
- macButtonPtr->image = nil;
- macButtonPtr->selectImage = nil;
- macButtonPtr->tristateImage = nil;
-
- return (TkButton *) macButtonPtr;
+/*No-op.*/
}
+
/*
*----------------------------------------------------------------------
*
- * TkpDestroyButton --
+ * TkpCreateButton --
*
- * Free data structures associated with the button control.
+ * Allocate a new TkButton structure.
*
* Results:
- * None.
+ * Returns a newly allocated TkButton structure.
*
* Side effects:
- * Restores the default control state.
+ * Registers an event handler for the widget.
*
*----------------------------------------------------------------------
*/
-void
-TkpDestroyButton(
- TkButton *butPtr)
+TkButton *
+TkpCreateButton(
+ Tk_Window tkwin)
{
- MacButton *macButtonPtr = (MacButton *) butPtr;
- [macButtonPtr->button setTag:(NSInteger)-1];
+ MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
+
+ Tk_CreateEventHandler(tkwin, ActivateMask,
+ ButtonEventProc, (ClientData) macButtonPtr);
+ macButtonPtr->id = bCount++;
+ macButtonPtr->flags = FIRST_DRAW;
+ macButtonPtr->btnkind = kThemePushButton;
+ macButtonPtr->defaultPulseHandler = NULL;
+ bzero(&macButtonPtr->drawinfo, sizeof(macButtonPtr->drawinfo));
+ bzero(&macButtonPtr->lastdrawinfo, sizeof(macButtonPtr->lastdrawinfo));
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->button);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->image);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->selectImage);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->tristateImage);
+ return (TkButton *)macButtonPtr;
}
/*
@@ -225,63 +189,63 @@ void
TkpDisplayButton(
ClientData clientData) /* Information about widget. */
{
+ MacButton *macButtonPtr = (MacButton *) clientData;
TkButton *butPtr = (TkButton *) clientData;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ DrawParams* dpPtr = &macButtonPtr->drawParams;
+ int needhighlight = 0;
butPtr->flags &= ~REDRAW_PENDING;
- if (!butPtr->tkwin || !Tk_IsMapped(butPtr->tkwin)) {
+ if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
return;
}
+ pixmap = (Pixmap) Tk_WindowId(tkwin);
+ TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
- switch (butPtr->type) {
- case TYPE_LABEL:
- DisplayUnixButton(butPtr);
- break;
- case TYPE_BUTTON:
- case TYPE_CHECK_BUTTON:
- case TYPE_RADIO_BUTTON:
- DisplayNativeButton(butPtr);
- break;
+ if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr) ) {
+ macButtonPtr->useTkText = 0;
+ } else {
+ macButtonPtr->useTkText = 1;
}
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkpShiftButton --
- *
- * Moves the frame of an NSButton (or TkNSButton) and in case the tag is
- * set, also adjusts the xOff and yOff of the controlling TkButton's
- * MacDrawable. This is used to avoid jitter when scrolling.
- *
- * Results:
- * None
- *
- * Side effects:
- * Moves the NSbutton after adjusting the associated MacDrawable.
- *
- *----------------------------------------------------------------------
- */
-void
-TkpShiftButton(
- NSButton *button,
- NSPoint delta )
- {
- NSPoint origin = [button frame].origin;
- NSInteger tag = [button tag];
- if ( tag != -1) {
- TkButton* butPtr = (TkButton *)tag;
- TkWindow *winPtr = (TkWindow *) (butPtr->tkwin);
- if (winPtr) {
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- macWin->xOff += delta.x;
- macWin->yOff += delta.y;
- }
+
+
+ /*
+ * Set up clipping region. Make sure the we are using the port
+ * for this button, or we will set the wrong window's clip.
+ */
+
+ if (macButtonPtr->useTkText) {
+ if (butPtr->type == TYPE_BUTTON) {
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
+ } else {
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
}
- origin.x += delta.x;
- origin.y -= delta.y;
- [button setFrameOrigin:origin];
+
+ /* Display image or bitmap or text for labels or custom controls. */
+ DrawButtonImageAndText(butPtr);
+ needhighlight = 1;
+ } else {
+ /* Draw the native portion of the buttons. */
+ TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap);
+
+ /* Draw highlight border, if needed. */
+ if (butPtr->highlightWidth < 3) {
+ needhighlight = 1;
+ }
}
+ /* Draw highlight border, if needed. */
+ if (needhighlight) {
+ if ((butPtr->flags & GOT_FOCUS)) {
+ Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin),
+ butPtr->highlightWidth, TK_RELIEF_SOLID);
+ }
+ }
+}
/*
*----------------------------------------------------------------------
@@ -300,1015 +264,1017 @@ TkpShiftButton(
*
*----------------------------------------------------------------------
*/
-
+
void
TkpComputeButtonGeometry(
- register TkButton *butPtr) /* Button whose geometry may have changed. */
+ TkButton *butPtr) /* Button whose geometry may have changed. */
{
- MacButton *macButtonPtr = (MacButton *) butPtr;
+ int width, height, avgWidth, haveImage = 0, haveText = 0;
+ int txtWidth, txtHeight;
+ MacButton *mbPtr = (MacButton*)butPtr;
+ Tk_FontMetrics fm;
+ DrawParams drawParams;
- switch (butPtr->type) {
- case TYPE_LABEL:
- if (macButtonPtr->button && [macButtonPtr->button superview]) {
- [macButtonPtr->button removeFromSuperviewWithoutNeedingDisplay];
- }
- ComputeUnixButtonGeometry(butPtr);
+ /*
+ * First figure out the size of the contents of the button.
+ */
+
+ width = 0;
+ height = 0;
+ txtWidth = 0;
+ txtHeight = 0;
+ avgWidth = 0;
+
+ TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
+
+ butPtr->indicatorSpace = 0;
+ if (butPtr->image != NULL) {
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
+ } else if (butPtr->bitmap != None) {
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
+ }
+
+ /*Tk Aqua can't handle metrics for radiobuttons and checkbuttons with images unless they are set first. These are derived from experimentation.*/
+ if (haveImage && !haveText) {
+ switch (butPtr->type) {
+ case TYPE_RADIO_BUTTON:
+ width = butPtr->width;
+ width +=50;
break;
- case TYPE_BUTTON:
- case TYPE_CHECK_BUTTON:
+ case TYPE_CHECK_BUTTON:
+ width = butPtr->width;
+ width += 50;
+ break;
+ case TYPE_BUTTON:
+ width = butPtr->width;
+ width += 0;
+ break;
+ }
+ }
+
+ if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
+ Tk_FreeTextLayout(butPtr->textLayout);
+ butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
+ Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
+ butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
+
+ txtWidth = butPtr->textWidth;
+ txtHeight = butPtr->textHeight;
+ avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
+ Tk_GetFontMetrics(butPtr->tkfont, &fm);
+ haveText = (txtWidth != 0 && txtHeight != 0);
+ }
+
+ /*
+ * If the button is compound (ie, it shows both an image and text),
+ * the new geometry is a combination of the image and text geometry.
+ * We only honor the compound bit if the button has both text and an
+ * image, because otherwise it is not really a compound button.
+ */
+
+ if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM:
+ /*
+ * Image is above or below text.
+ */
+
+ height += txtHeight + butPtr->padY;
+ width = (width > txtWidth ? width : txtWidth);
+ break;
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT:
+ /*
+ * Image is left or right of text.
+ */
+
+ width += txtWidth + butPtr->padX;
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ case COMPOUND_CENTER:
+ /*
+ * Image and text are superimposed.
+ */
+
+ width = (width > txtWidth ? width : txtWidth);
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ case COMPOUND_NONE:
+ break;
+ }
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+
+ } else if (haveImage) {
+
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+
+ } else {
+ width = txtWidth;
+ height = txtHeight;
+
+ if (butPtr->width > 0) {
+ width = butPtr->width * avgWidth;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height * fm.linespace;
+ }
+ }
+
+ width += 2 * butPtr->padX;
+ height += 2 * butPtr->padY;
+
+
+ /* Need special handling for radiobuttons and checkbuttons: the text is drawn right on top of the button unless we expand the width. This is not perfect; some radiobuttons may render on top anyway. Need to find a better solution to calculate average text width.*/
+ switch (butPtr->type) {
case TYPE_RADIO_BUTTON:
- if (!macButtonPtr->button) {
- TkNSButton *button = [[TkNSButton alloc] initWithFrame:NSZeroRect];
- [button setTag:(NSInteger)butPtr];
- macButtonPtr->button = TkMacOSXMakeUncollectable(button);
+ width += 50;
+ break;
+ case TYPE_CHECK_BUTTON:
+ width += 50;
+ break;
+ }
+
+ /*
+ * Now figure out the size of the border decorations for the button.
+ */
+
+ if (butPtr->highlightWidth < 0) {
+ butPtr->highlightWidth = 0;
+ }
+
+ butPtr->inset = 0;
+ butPtr->inset += butPtr->highlightWidth;
+
+ if (TkMacOSXComputeButtonDrawParams(butPtr,&drawParams)) {
+
+
+ HIRect tmpRect;
+ HIRect contBounds;
+ int paddingx = 0;
+ int paddingy = 0;
+
+ tmpRect = CGRectMake(0, 0, width, height);
+
+
+ HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
+
+
+ /* If the content region has a minimum height, match it. */
+ if (height < contBounds.size.height) {
+ height = contBounds.size.height;
+ }
+
+ /* If the content region has a minimum width, match it. */
+ if (width < contBounds.size.width) {
+ width = contBounds.size.width;
+ }
+
+ /* Pad to fill difference between content bounds and button bounds. */
+ paddingx = tmpRect.origin.x - contBounds.origin.x;
+ paddingy = tmpRect.origin.y - contBounds.origin.y;
+ if (paddingx > 0) {
+ width += paddingx;
+ }
+ if (paddingy > 0) {
+ height += paddingy;
+ }
+
+ if (height < paddingx - 4) {
+ /* can't have buttons much shorter than button side diameter. */
+ height = paddingx - 4;
}
- ComputeNativeButtonGeometry(butPtr);
- break;
+
+ } else {
+ height += butPtr->borderWidth*2;
+ width += butPtr->borderWidth*2;
}
+
+ width += butPtr->inset*2;
+ height += butPtr->inset*2;
+
+ Tk_GeometryRequest(butPtr->tkwin, width, height);
+ Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
+
}
-
+
+/*
/*
*----------------------------------------------------------------------
*
- * TkpButtonSetDefaults --
+ * DrawButtonImageAndText --
*
- * This procedure is invoked before option tables are created for
- * buttons. It modifies some of the default values to match the current
- * values defined for this platform.
+ * Draws the image and text associated with a button or label.
*
* Results:
- * Some of the default values in *specPtr are modified.
+ * None.
*
* Side effects:
- * Updates some of.
+ * The image and text are drawn.
*
*----------------------------------------------------------------------
*/
-
-void
-TkpButtonSetDefaults()
+static void
+DrawButtonImageAndText(
+ TkButton* butPtr)
{
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (!tkMacOSXUseCompatibilityMetrics) {
- strcpy(tkDefButtonHighlightWidth, DEF_BUTTON_HIGHLIGHT_WIDTH_NOCM);
- strcpy(tkDefLabelHighlightWidth, DEF_BUTTON_HIGHLIGHT_WIDTH_NOCM);
- strcpy(tkDefButtonPadx, DEF_BUTTON_PADX_NOCM);
- strcpy(tkDefLabelPadx, DEF_BUTTON_PADX_NOCM);
- strcpy(tkDefButtonPady, DEF_BUTTON_PADY_NOCM);
- strcpy(tkDefLabelPady, DEF_BUTTON_PADY_NOCM);
+
+ MacButton *mbPtr = (MacButton*)butPtr;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ int haveImage = 0;
+ int haveText = 0;
+ int imageWidth = 0;
+ int imageHeight = 0;
+ int imageXOffset = 0;
+ int imageYOffset = 0;
+ int textXOffset = 0;
+ int textYOffset = 0;
+ int width = 0;
+ int height = 0;
+ int fullWidth = 0;
+ int fullHeight = 0;
+ int pressed = 0;
+
+
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
-#endif
-}
-#pragma mark -
-#pragma mark Native Buttons:
+ DrawParams* dpPtr = &mbPtr->drawParams;
+ pixmap = (Pixmap)Tk_WindowId(tkwin);
+
+ if (butPtr->image != None) {
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
+ } else if (butPtr->bitmap != None) {
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
+ }
+
+ imageWidth = width;
+ imageHeight = height;
+
+ if (mbPtr->drawinfo.state == kThemeStatePressed) {
+ /* Offset bitmaps by a bit when the button is pressed. */
+ pressed = 1;
+ }
+
+ haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
+ if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
+ int x;
+ int y;
+ textXOffset = 0;
+ textYOffset = 0;
+ fullWidth = 0;
+ fullHeight = 0;
+
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM: {
+ /* Image is above or below text */
+ if (butPtr->compound == COMPOUND_TOP) {
+ textYOffset = height + butPtr->padY;
+ } else {
+ imageYOffset = butPtr->textHeight + butPtr->padY;
+ }
+ fullHeight = height + butPtr->textHeight + butPtr->padY;
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ break;
+ }
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT: {
+ /*
+ * Image is left or right of text
+ */
+
+ if (butPtr->compound == COMPOUND_LEFT) {
+ textXOffset = width + butPtr->padX;
+ } else {
+ imageXOffset = butPtr->textWidth + butPtr->padX;
+ }
+ fullWidth = butPtr->textWidth + butPtr->padX + width;
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_CENTER: {
+ /*
+ * Image and text are superimposed
+ */
+
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_NONE: {break;}
+ }
+ TkComputeAnchor(butPtr->anchor, tkwin,
+ butPtr->padX + butPtr->borderWidth,
+ butPtr->padY + butPtr->borderWidth,
+ fullWidth, fullHeight, &x, &y);
+ if (dpPtr->relief == TK_RELIEF_SUNKEN) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ } else if (dpPtr->relief == TK_RELIEF_RAISED) {
+ x -= dpPtr->offset;
+ y -= dpPtr->offset;
+ }
+ if (pressed) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ }
+ imageXOffset += x;
+ imageYOffset += y;
+ textYOffset -= 1;
+
+ if (butPtr->image != NULL) {
+ if ((butPtr->selectImage != NULL) &&
+ (butPtr->flags & SELECTED)) {
+ Tk_RedrawImage(butPtr->selectImage, 0, 0,
+ width, height, pixmap, imageXOffset, imageYOffset);
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0,
+ width, height, pixmap, imageXOffset, imageYOffset);
+ } else {
+ Tk_RedrawImage(butPtr->image, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ }
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc,
+ imageXOffset, imageYOffset);
+ XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width, (unsigned int) height,
+ imageXOffset, imageYOffset, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+
+ Tk_DrawTextLayout(butPtr->display, pixmap,
+ dpPtr->gc, butPtr->textLayout,
+ x + textXOffset, y + textYOffset, 0, -1);
+ Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout,
+ x + textXOffset, y + textYOffset,
+ butPtr->underline);
+ } else {
+ if (haveImage) {
+ int x = 0;
+ int y;
+ TkComputeAnchor(butPtr->anchor, tkwin,
+ butPtr->padX + butPtr->borderWidth,
+ butPtr->padY + butPtr->borderWidth,
+ width, height, &x, &y);
+ if (dpPtr->relief == TK_RELIEF_SUNKEN) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ } else if (dpPtr->relief == TK_RELIEF_RAISED) {
+ x -= dpPtr->offset;
+ y -= dpPtr->offset;
+ }
+ if (pressed) {
+ x += dpPtr->offset;
+ y += dpPtr->offset;
+ }
+ imageXOffset += x;
+ imageYOffset += y;
+
+ if (butPtr->image != NULL) {
+
+ if ((butPtr->selectImage != NULL) &&
+ (butPtr->flags & SELECTED)) {
+ Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ } else if ((butPtr->tristateImage != NULL) &&
+ (butPtr->flags & TRISTATED)) {
+ Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ } else {
+ Tk_RedrawImage(butPtr->image, 0, 0, width, height,
+ pixmap, imageXOffset, imageYOffset);
+ }
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
+ XCopyPlane(butPtr->display, butPtr->bitmap,
+ pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width,
+ (unsigned int) height,
+ imageXOffset, imageYOffset, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+ } else {
+ /*Adequate padding / offset for text in various buttons.*/
+ int x = 0;
+ int y;
+ switch (butPtr->type) {
+ case TYPE_RADIO_BUTTON:
+ case TYPE_CHECK_BUTTON:
+ if (butPtr->indicatorOn) {
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
+ butPtr->textWidth, butPtr->textHeight, &x, &y);
+ Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout, x + 20, y, 0, -1);
+ } else {
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
+ butPtr->textWidth, butPtr->textHeight, &x, &y);
+ Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout, x, y, 0, -1);
+ }
+ break;
+ case TYPE_BUTTON:
+ case TYPE_LABEL:
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
+ butPtr->textWidth, butPtr->textHeight, &x, &y);
+ Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout, x, y, 0, -1);
+ y += butPtr->textHeight/2;
+ break;
+ }
+ }
+ }
+
+
+ /*
+ * If the button is disabled with a stipple rather than a special
+ * foreground color, generate the stippled effect. If the widget
+ * is selected and we use a different background color when selected,
+ * must temporarily modify the GC so the stippling is the right color.
+ */
+
+ if (mbPtr->useTkText) {
+ if ((butPtr->state == STATE_DISABLED)
+ && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
+ if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
+ && (butPtr->selectBorder != NULL)) {
+ XSetForeground(butPtr->display, butPtr->stippleGC,
+ Tk_3DBorderColor(butPtr->selectBorder)->pixel);
+ }
+ /*
+ * Stipple the whole button if no disabledFg was specified,
+ * otherwise restrict stippling only to displayed image
+ */
+ if (butPtr->disabledFg == NULL) {
+ XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC,
+ 0, 0, (unsigned) Tk_Width(tkwin),
+ (unsigned) Tk_Height(tkwin));
+ } else {
+ XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC,
+ imageXOffset, imageYOffset,
+ (unsigned) imageWidth, (unsigned) imageHeight);
+ }
+ if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
+ && (butPtr->selectBorder != NULL)
+ ) {
+ XSetForeground(butPtr->display, butPtr->stippleGC,
+ Tk_3DBorderColor(butPtr->normalBorder)->pixel);
+ }
+ }
+
+ /*
+ * Draw the border and traversal highlight last. This way, if the
+ * button's contents overflow they'll be covered up by the border.
+ */
+
+ if (dpPtr->relief != TK_RELIEF_FLAT) {
+ int inset = butPtr->highlightWidth;
+ Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
+ Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
+ butPtr->borderWidth, dpPtr->relief);
+ }
+ }
+
+ }
+
+
+
-
/*
*----------------------------------------------------------------------
*
- * TkMacOSXGetButtonFrame --
+ * TkpDestroyButton --
*
- * Computes a frame for an NSButton that will correspond to where
- * Tk thinks the button is located.
+ * Free data structures associated with the button control.
*
* Results:
- * Returns an NSRect describing a frame for an NSButton.
+ * None.
*
* Side effects:
- * None
+ * Restores the default control state.
*
*----------------------------------------------------------------------
*/
-NSRect TkMacOSXGetButtonFrame(
- TkButton *butPtr)
-{
- MacButton *macButtonPtr = (MacButton *) butPtr;
- Tk_Window tkwin = butPtr->tkwin;
- TkWindow *winPtr = (TkWindow *) tkwin;
- if (tkwin) {
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- NSView *view = TkMacOSXDrawableView(macWin);
- CGFloat viewHeight = [view bounds].size.height;
- NSRect frame = NSMakeRect(macWin->xOff, macWin->yOff,
- Tk_Width(tkwin), Tk_Height(tkwin));
-
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- BoundsFix boundsFix = boundsFixes[macButtonPtr->fix];
- frame = NSOffsetRect(frame, boundsFix.offsetX, boundsFix.offsetY);
- frame.size.height -= boundsFix.shrinkH + NATIVE_BUTTON_EXTRA_H;
- frame = NSInsetRect(frame, boundsFix.inset + NATIVE_BUTTON_INSET,
- boundsFix.inset + NATIVE_BUTTON_INSET);
- }
-#endif
- frame.origin.y = viewHeight - (frame.origin.y + frame.size.height);
- return frame;
- } else {
- return NSZeroRect;
+void
+TkpDestroyButton(
+ TkButton *butPtr)
+{
+ MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */
+ if (mbPtr->defaultPulseHandler) {
+ Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
}
}
/*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*
- * DisplayNativeButton --
+ * TkMacOSXDrawButton --
*
- * This procedure is invoked to display a button widget. It is
- * normally invoked as an idle handler.
+ * This function draws the tk button using Mac controls
+ * In addition, this code may apply custom colors passed
+ * in the TkButton.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Commands are output to X to display the button in its
- * current mode. The REDRAW_PENDING flag is cleared.
+ * The control is created, or reinitialised as needed
*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*/
static void
-DisplayNativeButton(
- TkButton *butPtr)
+TkMacOSXDrawButton(
+ MacButton *mbPtr, /* Mac button. */
+ 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 */
{
- MacButton *macButtonPtr = (MacButton *) butPtr;
- TkNSButton *button = macButtonPtr->button;
- Tk_Window tkwin = butPtr->tkwin;
- TkWindow *winPtr = (TkWindow *) tkwin;
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
+ TkButton * butPtr = ( TkButton *)mbPtr;
+ TkWindow * winPtr;
+ HIRect cntrRect;
TkMacOSXDrawingContext dc;
- NSView *view = TkMacOSXDrawableView(macWin);
- CGFloat viewHeight = [view bounds].size.height;
- CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
- .ty = viewHeight};
- NSRect frame;
- int enabled;
- NSCellStateValue state;
-
- if (!view ||
- !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
- return;
- }
- CGContextConcatCTM(dc.context, t);
+ DrawParams* dpPtr = &mbPtr->drawParams;
+ int useNewerHITools = 1;
+
+ winPtr = (TkWindow *)butPtr->tkwin;
- /*
- * We cannot change the background color of the button itself, only the
- * color of the background of its container.
- * 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.
- */
+ TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
+
+ cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, Tk_Width(butPtr->tkwin),Tk_Height(butPtr->tkwin));
+
+ cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset);
+
+ if (useNewerHITools == 1) {
+ HIRect contHIRec;
+ static HIThemeButtonDrawInfo hiinfo;
+
+ ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true);
+
+ if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
+ return;
+ }
+
+
+ if (mbPtr->btnkind == kThemePushButton) {
+ /*
+ * For some reason, pushbuttons get drawn a bit
+ * too low, normally. Correct for this.
+ */
+ if (cntrRect.size.height < 22) {
+ cntrRect.origin.y -= 1;
+ } else if (cntrRect.size.height < 23) {
+ cntrRect.origin.y -= 2;
+ }
+ }
+
+ hiinfo.version = 0;
+ hiinfo.state = mbPtr->drawinfo.state;
+ hiinfo.kind = mbPtr->btnkind;
+ hiinfo.value = mbPtr->drawinfo.value;
+ hiinfo.adornment = mbPtr->drawinfo.adornment;
+ hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
+ if (hiinfo.animation.time.start == 0) {
+ hiinfo.animation.time.start = hiinfo.animation.time.current;
+ }
+
+ HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, &contHIRec);
+
+ TkMacOSXRestoreDrawingContext(&dc);
+
+ ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo, (MacButton *)mbPtr, 32, true);
- Tk_Fill3DRectangle(tkwin, (Pixmap) macWin, butPtr->type == TYPE_BUTTON ?
- butPtr->highlightBorder : butPtr->normalBorder, 0, 0,
- Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
- if ([button superview] != view) {
- [view addSubview:button];
- }
- if (macButtonPtr->tristateImage) {
- NSImage *selectImage = macButtonPtr->selectImage ?
- macButtonPtr->selectImage : macButtonPtr->image;
- [button setImage:(butPtr->flags & TRISTATED ?
- selectImage : macButtonPtr->image)];
- [button setAlternateImage:(butPtr->flags & TRISTATED ?
- macButtonPtr->tristateImage : selectImage)];
- }
- if (butPtr->flags & SELECTED) {
- state = NSOnState;
- } else if (butPtr->flags & TRISTATED) {
- state = NSMixedState;
- } else {
- state = NSOffState;
- }
- [button setState:state];
- enabled = !(butPtr->state == STATE_DISABLED);
- [button setEnabled:enabled];
- if (enabled) {
- //[button highlight:(butPtr->state == STATE_ACTIVE)];
- //[cell setHighlighted:(butPtr->state == STATE_ACTIVE)];
- }
- if (butPtr->type == TYPE_BUTTON && butPtr->defaultState == STATE_ACTIVE) {
- //[[view window] setDefaultButtonCell:cell];
- [button setKeyEquivalent:@"\r"];
} else {
- [button setKeyEquivalent:@""];
+ if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
+ return;
+ }
+
+ TkMacOSXRestoreDrawingContext(&dc);
}
- frame = TkMacOSXGetButtonFrame(butPtr);
- [button setFrame:frame];
- [button displayRectIgnoringOpacity:[button bounds]];
- TkMacOSXRestoreDrawingContext(&dc);
-#ifdef TK_MAC_DEBUG_BUTTON
- TKLog(@"button %s frame %@ width %d height %d",
- ((TkWindow *)butPtr->tkwin)->pathName, NSStringFromRect(frame),
- Tk_Width(tkwin), Tk_Height(tkwin));
-#endif
+ mbPtr->lastdrawinfo = mbPtr->drawinfo;
}
/*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*
- * ComputeNativeButtonGeometry --
+ * ButtonBackgroundDrawCB --
*
- * After changes in a button's text or bitmap, this procedure
- * recomputes the button's geometry and passes this information
- * along to the geometry manager for the window.
+ * This function draws the background that
+ * lies under checkboxes and radiobuttons.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The button's window may change size.
+ * The background gets updated to the current color.
*
- *----------------------------------------------------------------------
+ *--------------------------------------------------------------
*/
-
static void
-ComputeNativeButtonGeometry(
- TkButton *butPtr) /* Button whose geometry may have changed. */
+ButtonBackgroundDrawCB (
+ const HIRect * btnbounds,
+ MacButton *ptr,
+ SInt16 depth,
+ Boolean isColorDev)
{
- MacButton *macButtonPtr = (MacButton *) butPtr;
- TkNSButton *button = macButtonPtr->button;
- NSButtonCell *cell = [button cell];
- NSButtonType type = -1;
- NSBezelStyle style = 0;
- NSInteger highlightsBy = 0, showsStateBy = 0;
- NSFont *font;
- NSRect bounds = NSZeroRect, titleRect = NSZeroRect;
- int haveImage = (butPtr->image || butPtr->bitmap != None), haveText = 0;
- int haveCompound = (butPtr->compound != COMPOUND_NONE);
- int width, height, border = 0;
+ MacButton* mbPtr = (MacButton*)ptr;
+ TkButton* butPtr = (TkButton*)mbPtr;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ int usehlborder = 0;
- butPtr->indicatorSpace = 0;
- butPtr->inset = 0;
- if (butPtr->highlightWidth < 0) {
- butPtr->highlightWidth = 0;
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
- switch (butPtr->type) {
- case TYPE_BUTTON:
- type = NSMomentaryPushInButton;
- if (!haveImage) {
- style = NSRoundedBezelStyle;
- butPtr->inset = butPtr->defaultState != STATE_DISABLED ?
- butPtr->highlightWidth : 0;
- [button setImage:nil];
- [button setImagePosition:NSNoImage];
- } else {
- style = NSShadowlessSquareBezelStyle;
- highlightsBy = butPtr->selectImage || butPtr->bitmap ?
- NSContentsCellMask : 0;
- border = butPtr->borderWidth;
- }
- break;
- case TYPE_RADIO_BUTTON:
- case TYPE_CHECK_BUTTON:
- if (!haveImage /*|| butPtr->indicatorOn*/) { // TODO: indicatorOn
- type = butPtr->type == TYPE_RADIO_BUTTON ?
- NSRadioButton : NSSwitchButton;
- butPtr->inset = /*butPtr->indicatorOn ? 0 :*/ butPtr->borderWidth;
- } else {
- type = NSPushOnPushOffButton;
- style = NSShadowlessSquareBezelStyle;
- highlightsBy = butPtr->selectImage || butPtr->bitmap ?
- NSContentsCellMask : 0;
- showsStateBy = butPtr->selectImage || butPtr->tristateImage ?
- NSContentsCellMask : 0;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- border = butPtr->borderWidth > 1 ? butPtr->borderWidth - 1 : 1;
- } else
-#endif
- {
- border = butPtr->borderWidth;
- }
- }
- break;
- }
- [button setButtonType:type];
- if (style) {
- [button setBezelStyle:style];
- }
- if (highlightsBy) {
- [cell setHighlightsBy:highlightsBy|[cell highlightsBy]];
- }
- if (showsStateBy) {
- [cell setShowsStateBy:showsStateBy|[cell showsStateBy]];
- }
-#if 0
- if (style == NSShadowlessSquareBezelStyle) {
- NSControlSize controlSize = NSRegularControlSize;
-
- if (butPtr->borderWidth <= 2) {
- controlSize = NSMiniControlSize;
- } else if (butPtr->borderWidth == 3) {
- controlSize = NSSmallControlSize;
- }
- [cell setControlSize:controlSize];
- }
-#endif
- [button setAllowsMixedState:YES];
-
- if (!haveImage || haveCompound) {
- int len;
- char *text = Tcl_GetStringFromObj(butPtr->textPtr, &len);
-
- if (len) {
- NSString *title = [[NSString alloc] initWithBytes:text length:len
- encoding:NSUTF8StringEncoding];
- [button setTitle:title];
- [title release];
- haveText = 1;
- }
+ pixmap = (Pixmap)Tk_WindowId(tkwin);
+
+ if (butPtr->type != TYPE_LABEL) {
+ switch (mbPtr->btnkind) {
+ case kThemeSmallBevelButton:
+ case kThemeBevelButton:
+ case kThemeRoundedBevelButton:
+ case kThemePushButton:
+ usehlborder = 1;
+ break;
+ }
}
- haveCompound = (haveCompound && haveImage && haveText);
- if (haveText) {
- NSTextAlignment alignment = NSNaturalTextAlignment;
-
- switch (butPtr->justify) {
- case TK_JUSTIFY_LEFT:
- alignment = NSLeftTextAlignment;
- break;
- case TK_JUSTIFY_RIGHT:
- alignment = NSRightTextAlignment;
- break;
- case TK_JUSTIFY_CENTER:
- alignment = NSCenterTextAlignment;
- break;
- }
- [button setAlignment:alignment];
+ if (usehlborder) {
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
} else {
- [button setTitle:@""];
- }
- font = TkMacOSXNSFontForFont(butPtr->tkfont);
- if (font) {
- [button setFont:font];
- }
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->image);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->selectImage);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->tristateImage);
- if (haveImage) {
- int width, height;
- NSImage *image, *selectImage = nil, *tristateImage = nil;
- NSCellImagePosition pos = NSImageOnly;
-
- if (butPtr->image) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- image = TkMacOSXGetNSImageWithTkImage(butPtr->display,
- butPtr->image, width, height);
- if (butPtr->selectImage) {
- selectImage = TkMacOSXGetNSImageWithTkImage(butPtr->display,
- butPtr->selectImage, width, height);
- }
- if (butPtr->tristateImage) {
- tristateImage = TkMacOSXGetNSImageWithTkImage(butPtr->display,
- butPtr->tristateImage, width, height);
- }
- } else {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- image = TkMacOSXGetNSImageWithBitmap(butPtr->display,
- butPtr->bitmap, butPtr->normalTextGC, width, height);
- selectImage = TkMacOSXGetNSImageWithBitmap(butPtr->display,
- butPtr->bitmap, butPtr->activeTextGC, width, height);
- }
- [button setImage:image];
- if (selectImage) {
- [button setAlternateImage:selectImage];
- }
- if (tristateImage) {
- macButtonPtr->image = TkMacOSXMakeUncollectableAndRetain(image);
- if (selectImage) {
- macButtonPtr->selectImage =
- TkMacOSXMakeUncollectableAndRetain(selectImage);
- }
- macButtonPtr->tristateImage =
- TkMacOSXMakeUncollectableAndRetain(tristateImage);
- }
- if (haveCompound) {
- switch ((enum compound) butPtr->compound) {
- case COMPOUND_TOP:
- pos = NSImageAbove;
- break;
- case COMPOUND_BOTTOM:
- pos = NSImageBelow;
- break;
- case COMPOUND_LEFT:
- pos = NSImageLeft;
- break;
- case COMPOUND_RIGHT:
- pos = NSImageRight;
- break;
- case COMPOUND_CENTER:
- pos = NSImageOverlaps;
- break;
- case COMPOUND_NONE:
- pos = NSImageOnly;
- break;
- }
- }
- [button setImagePosition:pos];
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
}
+}
+
+/*
+ *--------------------------------------------------------------
+ *
+ * ButtonContentDrawCB --
+ *
+ * This function draws the label and image for the button.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The content of the button gets updated.
+ *
+ *--------------------------------------------------------------
+ */
+static void
+ButtonContentDrawCB (
+ const HIRect * btnbounds,
+ ThemeButtonKind kind,
+ const HIThemeButtonDrawInfo *drawinfo,
+ MacButton *ptr,
+ SInt16 depth,
+ Boolean isColorDev)
+{
+ TkButton *butPtr = (TkButton *)ptr;
+ Tk_Window tkwin = butPtr->tkwin;
+ HIRect * bounds;
- // if font is too tall, we can't use the fixed-height rounded bezel
- if (!haveImage && haveText && style == NSRoundedBezelStyle) {
- Tk_FontMetrics fm;
- Tk_GetFontMetrics(butPtr->tkfont, &fm);
- if (fm.linespace > 18) {
- [button setBezelStyle:(style = NSRegularSquareBezelStyle)];
- }
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
+ MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tkwin);
- bounds.size = [cell cellSize];
- if (haveText) {
- titleRect = [cell titleRectForBounds:bounds];
- if (butPtr->wrapLength > 0 &&
- titleRect.size.width > butPtr->wrapLength) {
- if (style == NSRoundedBezelStyle) {
- [button setBezelStyle:(style = NSRegularSquareBezelStyle)];
- bounds.size = [cell cellSize];
- titleRect = [cell titleRectForBounds:bounds];
- }
- bounds.size.width -= titleRect.size.width - butPtr->wrapLength;
- bounds.size.height = 40000.0;
- [cell setWraps:YES];
- bounds.size = [cell cellSizeForBounds:bounds];
-#ifdef TK_MAC_DEBUG_BUTTON
- titleRect = [cell titleRectForBounds:bounds];
-#endif
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- bounds.size.height += 3;
- }
-#endif
- }
- }
- width = lround(bounds.size.width);
- height = lround(bounds.size.height);
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- macButtonPtr->fix = fixForTypeStyle(type, style);
- width -= boundsFixes[macButtonPtr->fix].trimW;
- height -= boundsFixes[macButtonPtr->fix].trimH;
- }
-#endif
+ /*Overlay Tk elements over button native region: drawing elements within button boundaries/native region causes unpredictable metrics.*/
+ DrawButtonImageAndText( butPtr);
+}
+
+/*
+ *--------------------------------------------------------------
+ *
+ * ButtonEventProc --
+ *
+ * This procedure is invoked by the Tk dispatcher for various
+ * events on buttons.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * When it gets exposed, it is redisplayed.
+ *
+ *--------------------------------------------------------------
+ */
- if (haveImage || haveCompound) {
- if (butPtr->width > 0) {
- width = butPtr->width;
- }
- if (butPtr->height > 0) {
- height = butPtr->height;
+static void
+ButtonEventProc(
+ ClientData clientData, /* Information about window. */
+ 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;
}
- } else {
- if (butPtr->width > 0) {
- int avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
- width = butPtr->width * avgWidth;
+ if (eventPtr->type == ActivateNotify) {
+ mbPtr->flags |= ACTIVE;
+ } else {
+ mbPtr->flags &= ~ACTIVE;
}
- if (butPtr->height > 0) {
- Tk_FontMetrics fm;
-
- Tk_GetFontMetrics(butPtr->tkfont, &fm);
- height = butPtr->height * fm.linespace;
+ if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
+ Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
+ buttonPtr->flags |= REDRAW_PENDING;
}
}
- if (!haveImage || haveCompound) {
- width += 2*butPtr->padX;
- height += 2*butPtr->padY;
- }
- if (haveImage) {
- width += 2*border;
- height += 2*border;
- }
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- width += 2*NATIVE_BUTTON_INSET;
- height += 2*NATIVE_BUTTON_INSET + NATIVE_BUTTON_EXTRA_H;
- }
-#endif
- Tk_GeometryRequest(butPtr->tkwin, width, height);
- Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
-#ifdef TK_MAC_DEBUG_BUTTON
- TKLog(@"button %s bounds %@ titleRect %@ width %d height %d inset %d borderWidth %d",
- ((TkWindow *)butPtr->tkwin)->pathName, NSStringFromRect(bounds),
- NSStringFromRect(titleRect), width, height, butPtr->inset,
- butPtr->borderWidth);
-#endif
}
-
-#pragma mark -
-#pragma mark Unix Buttons:
-
/*
*----------------------------------------------------------------------
*
- * DisplayUnixButton --
+ * TkMacOSXComputeButtonParams --
*
- * This procedure is invoked to display a button widget. It is
- * normally invoked as an idle handler.
+ * This procedure computes the various parameters used
+ * when creating a Carbon Appearance control.
+ * These are determined by the various tk button parameters
*
* Results:
* None.
*
* Side effects:
- * Commands are output to X to display the button in its
- * current mode. The REDRAW_PENDING flag is cleared.
+ * Sets the btnkind and drawinfo parameters
*
*----------------------------------------------------------------------
*/
-void
-DisplayUnixButton(
- TkButton *butPtr)
+static void
+TkMacOSXComputeButtonParams(
+ TkButton * butPtr,
+ ThemeButtonKind* btnkind,
+ HIThemeButtonDrawInfo *drawinfo)
{
- GC gc;
- Tk_3DBorder border;
- Pixmap pixmap;
- int x = 0; /* Initialization only needed to stop compiler
- * warning. */
- int y, relief;
- Tk_Window tkwin = butPtr->tkwin;
- int width = 0, height = 0, fullWidth, fullHeight;
- int textXOffset, textYOffset;
- int haveImage = 0, haveText = 0;
- int imageWidth, imageHeight;
- int imageXOffset = 0, imageYOffset = 0;
- /* image information that will be used to
- * restrict disabled pixmap as well */
-
- border = butPtr->normalBorder;
- if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
- gc = butPtr->disabledGC;
- } else if ((butPtr->state == STATE_ACTIVE)
- && !Tk_StrictMotif(butPtr->tkwin)) {
- gc = butPtr->activeTextGC;
- border = butPtr->activeBorder;
+ MacButton *mbPtr = (MacButton *)butPtr;
+
+ if (butPtr->borderWidth <= 2) {
+ *btnkind = kThemeSmallBevelButton;
+ } else if (butPtr->borderWidth == 3) {
+ *btnkind = kThemeBevelButton;
+ } else if (butPtr->borderWidth == 4) {
+ *btnkind = kThemeRoundedBevelButton;
} else {
- gc = butPtr->normalTextGC;
+ *btnkind = kThemePushButton;
}
- if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
- && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
- border = butPtr->selectBorder;
- }
-
- relief = butPtr->relief;
-
- pixmap = (Pixmap) Tk_WindowId(tkwin);
- Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin),
- Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
-
- /*
- * Display image or bitmap or text for button.
- */
-
- if (butPtr->image != NULL) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- haveImage = 1;
- } else if (butPtr->bitmap != None) {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- haveImage = 1;
- }
- imageWidth = width;
- imageHeight = height;
-
- haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
-
- if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
- textXOffset = 0;
- textYOffset = 0;
- fullWidth = 0;
- fullHeight = 0;
-
- switch ((enum compound) butPtr->compound) {
- case COMPOUND_TOP:
- case COMPOUND_BOTTOM:
- /*
- * Image is above or below text.
- */
-
- if (butPtr->compound == COMPOUND_TOP) {
- textYOffset = height + butPtr->padY;
- } else {
- imageYOffset = butPtr->textHeight + butPtr->padY;
- }
- fullHeight = height + butPtr->textHeight + butPtr->padY;
- fullWidth = (width > butPtr->textWidth ? width :
- butPtr->textWidth);
- textXOffset = (fullWidth - butPtr->textWidth)/2;
- imageXOffset = (fullWidth - width)/2;
- break;
- case COMPOUND_LEFT:
- case COMPOUND_RIGHT:
- /*
- * Image is left or right of text.
- */
-
- if (butPtr->compound == COMPOUND_LEFT) {
- textXOffset = width + butPtr->padX;
- } else {
- imageXOffset = butPtr->textWidth + butPtr->padX;
- }
- fullWidth = butPtr->textWidth + butPtr->padX + width;
- fullHeight = (height > butPtr->textHeight ? height :
- butPtr->textHeight);
- textYOffset = (fullHeight - butPtr->textHeight)/2;
- imageYOffset = (fullHeight - height)/2;
- break;
- case COMPOUND_CENTER:
- /*
- * Image and text are superimposed.
- */
-
- fullWidth = (width > butPtr->textWidth ? width :
- butPtr->textWidth);
- fullHeight = (height > butPtr->textHeight ? height :
- butPtr->textHeight);
- textXOffset = (fullWidth - butPtr->textWidth)/2;
- imageXOffset = (fullWidth - width)/2;
- textYOffset = (fullHeight - butPtr->textHeight)/2;
- imageYOffset = (fullHeight - height)/2;
- break;
- case COMPOUND_NONE:
- break;
- }
-
- TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
- fullWidth, fullHeight, &x, &y);
-
- imageXOffset += x;
- imageYOffset += y;
-
- if (butPtr->image != NULL) {
- /*
- * Do boundary clipping, so that Tk_RedrawImage is passed valid
- * coordinates. [Bug 979239]
- */
-
- if (imageXOffset < 0) {
- imageXOffset = 0;
- }
- if (imageYOffset < 0) {
- imageYOffset = 0;
- }
- if (width > Tk_Width(tkwin)) {
- width = Tk_Width(tkwin);
- }
- if (height > Tk_Height(tkwin)) {
- height = Tk_Height(tkwin);
- }
- if ((width + imageXOffset) > Tk_Width(tkwin)) {
- imageXOffset = Tk_Width(tkwin) - width;
- }
- if ((height + imageYOffset) > Tk_Height(tkwin)) {
- imageYOffset = Tk_Height(tkwin) - height;
- }
-
- if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
- Tk_RedrawImage(butPtr->selectImage, 0, 0,
- width, height, pixmap, imageXOffset, imageYOffset);
- } else if ((butPtr->tristateImage != NULL) && (butPtr->flags & TRISTATED)) {
- Tk_RedrawImage(butPtr->tristateImage, 0, 0,
- width, height, pixmap, imageXOffset, imageYOffset);
- } else {
- Tk_RedrawImage(butPtr->image, 0, 0, width,
- height, pixmap, imageXOffset, imageYOffset);
- }
- } else {
- XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset);
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc,
- 0, 0, (unsigned int) width, (unsigned int) height,
- imageXOffset, imageYOffset, 1);
- XSetClipOrigin(butPtr->display, gc, 0, 0);
- }
- Tk_DrawTextLayout(butPtr->display, pixmap, gc,
- butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1);
- Tk_UnderlineTextLayout(butPtr->display, pixmap, gc,
- butPtr->textLayout, x + textXOffset, y + textYOffset,
- butPtr->underline);
- y += fullHeight/2;
- } else {
- if (haveImage) {
- TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
- width, height, &x, &y);
- imageXOffset += x;
- imageYOffset += y;
- if (butPtr->image != NULL) {
- /*
- * Do boundary clipping, so that Tk_RedrawImage is passed
- * valid coordinates. [Bug 979239]
- */
-
- if (imageXOffset < 0) {
- imageXOffset = 0;
- }
- if (imageYOffset < 0) {
- imageYOffset = 0;
- }
- if (width > Tk_Width(tkwin)) {
- width = Tk_Width(tkwin);
- }
- if (height > Tk_Height(tkwin)) {
- height = Tk_Height(tkwin);
- }
- if ((width + imageXOffset) > Tk_Width(tkwin)) {
- imageXOffset = Tk_Width(tkwin) - width;
- }
- if ((height + imageYOffset) > Tk_Height(tkwin)) {
- imageYOffset = Tk_Height(tkwin) - height;
- }
-
- if ((butPtr->selectImage != NULL) &&
- (butPtr->flags & SELECTED)) {
- Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
- height, pixmap, imageXOffset, imageYOffset);
- } else if ((butPtr->tristateImage != NULL) &&
- (butPtr->flags & TRISTATED)) {
- Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
- height, pixmap, imageXOffset, imageYOffset);
+ if ((butPtr->image == None) && (butPtr->bitmap == None)) {
+ switch (butPtr->type) {
+ case TYPE_BUTTON:
+ *btnkind = kThemePushButton;
+ break;
+ case TYPE_RADIO_BUTTON:
+ if (butPtr->borderWidth <= 1) {
+ *btnkind = kThemeSmallRadioButton;
} else {
- Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap,
- imageXOffset, imageYOffset);
+ *btnkind = kThemeRadioButton;
}
- } else {
- XSetClipOrigin(butPtr->display, gc, x, y);
- XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
- (unsigned int) width, (unsigned int) height, x, y, 1);
- XSetClipOrigin(butPtr->display, gc, 0, 0);
- }
- y += height/2;
- } else {
- TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
- butPtr->textWidth, butPtr->textHeight, &x, &y);
-
- Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout,
- x, y, 0, -1);
- Tk_UnderlineTextLayout(butPtr->display, pixmap, gc,
- butPtr->textLayout, x, y, butPtr->underline);
- y += butPtr->textHeight/2;
+ break;
+ case TYPE_CHECK_BUTTON:
+ if (butPtr->borderWidth <= 1) {
+ *btnkind = kThemeSmallCheckBox;
+ } else {
+ *btnkind = kThemeCheckBox;
+ }
+ break;
}
}
- /*
- * If the button is disabled with a stipple rather than a special
- * foreground color, generate the stippled effect. If the widget is
- * selected and we use a different background color when selected, must
- * temporarily modify the GC so the stippling is the right color.
- */
-
- if ((butPtr->state == STATE_DISABLED)
- && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
- if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
- && (butPtr->selectBorder != NULL)) {
- XSetForeground(butPtr->display, butPtr->stippleGC,
- Tk_3DBorderColor(butPtr->selectBorder)->pixel);
- }
-
- /*
- * Stipple the whole button if no disabledFg was specified, otherwise
- * restrict stippling only to displayed image
- */
-
- if (butPtr->disabledFg == NULL) {
- XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, 0, 0,
- (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin));
- } else {
- XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC,
- imageXOffset, imageYOffset,
- (unsigned) imageWidth, (unsigned) imageHeight);
- }
- if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
- && (butPtr->selectBorder != NULL)) {
- XSetForeground(butPtr->display, butPtr->stippleGC,
- Tk_3DBorderColor(butPtr->normalBorder)->pixel);
- }
+ if (butPtr->indicatorOn) {
+ switch (butPtr->type) {
+ case TYPE_RADIO_BUTTON:
+ if (butPtr->borderWidth <= 1) {
+ *btnkind = kThemeSmallRadioButton;
+ } else {
+ *btnkind = kThemeRadioButton;
+ }
+ break;
+ case TYPE_CHECK_BUTTON:
+ if (butPtr->borderWidth <= 1) {
+ *btnkind = kThemeSmallCheckBox;
+ } else {
+ *btnkind = kThemeCheckBox;
+ }
+ break;
+ }
+ } else {
+ if (butPtr->type == TYPE_RADIO_BUTTON ||
+ butPtr->type == TYPE_CHECK_BUTTON
+ ) {
+ if (*btnkind == kThemePushButton) {
+ *btnkind = kThemeBevelButton;
+ }
+ }
}
- /*
- * Draw the border and traversal highlight last. This way, if the button's
- * contents overflow they'll be covered up by the border. This code is
- * complicated by the possible combinations of focus highlight and default
- * rings. We draw the focus and highlight rings using the highlight border
- * and highlight foreground color.
- */
-
- if (relief != TK_RELIEF_FLAT) {
- int inset = butPtr->highlightWidth;
-
- if (butPtr->defaultState == DEFAULT_ACTIVE) {
- /*
- * Draw the default ring with 2 pixels of space between the
- * default ring and the button and the default ring and the focus
- * ring. Note that we need to explicitly draw the space in the
- * highlightBorder color to ensure that we overwrite any overflow
- * text and/or a different button background color.
- */
-
- Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
- inset, Tk_Width(tkwin) - 2*inset,
- Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT);
- inset += 2;
- Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
- inset, Tk_Width(tkwin) - 2*inset,
- Tk_Height(tkwin) - 2*inset, 1, TK_RELIEF_SUNKEN);
- inset++;
- Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
- inset, Tk_Width(tkwin) - 2*inset,
- Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT);
-
- inset += 2;
- } else if (butPtr->defaultState == DEFAULT_NORMAL) {
- /*
- * Leave room for the default ring and write over any text or
- * background color.
- */
-
- Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0,
- 0, Tk_Width(tkwin), Tk_Height(tkwin), 5, TK_RELIEF_FLAT);
- inset += 5;
- }
-
- /*
- * Draw the button border.
- */
-
- Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset,
- Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
- butPtr->borderWidth, relief);
+ if (butPtr->flags & SELECTED) {
+ drawinfo->value = kThemeButtonOn;
+ } else if (butPtr->flags & TRISTATED) {
+ drawinfo->value = kThemeButtonMixed;
+ } else {
+ drawinfo->value = kThemeButtonOff;
}
- if (butPtr->highlightWidth > 0) {
- GC gc;
-
- if (butPtr->flags & GOT_FOCUS) {
- gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
- } else {
- gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
- pixmap);
+
+ if ((mbPtr->flags & FIRST_DRAW) != 0) {
+ mbPtr->flags &= ~FIRST_DRAW;
+ if (Tk_MacOSXIsAppInFront()) {
+ mbPtr->flags |= ACTIVE;
}
+ }
- /*
- * Make sure the focus ring shrink-wraps the actual button, not the
- * padding space left for a default ring.
- */
+ drawinfo->state = kThemeStateInactive;
+ if ((mbPtr->flags & ACTIVE) == 0) {
+ if (butPtr->state == STATE_DISABLED) {
+ drawinfo->state = kThemeStateUnavailableInactive;
+ } else {
+ drawinfo->state = kThemeStateInactive;
+ }
+ } else if (butPtr->state == STATE_DISABLED) {
+ drawinfo->state = kThemeStateUnavailable;
+ } else if (butPtr->state == STATE_ACTIVE) {
+ drawinfo->state = kThemeStatePressed;
+ } else {
+ drawinfo->state = kThemeStateActive;
+ }
- if (butPtr->defaultState == DEFAULT_NORMAL) {
- TkDrawInsetFocusHighlight(tkwin, gc, butPtr->highlightWidth,
- pixmap, 5);
- } else {
- Tk_DrawFocusHighlight(tkwin, gc, butPtr->highlightWidth, pixmap);
- }
+ drawinfo->adornment = kThemeAdornmentNone;
+ if (butPtr->defaultState == DEFAULT_ACTIVE) {
+ drawinfo->adornment |= kThemeAdornmentDefault;
+ if (!mbPtr->defaultPulseHandler) {
+ mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
+ PULSE_TIMER_MSECS, PulseDefaultButtonProc,
+ (ClientData) butPtr);
+ }
+ } else if (mbPtr->defaultPulseHandler) {
+ Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
+ }
+ if (butPtr->highlightWidth >= 3) {
+ if ((butPtr->flags & GOT_FOCUS)) {
+ drawinfo->adornment |= kThemeAdornmentFocus;
+ }
}
}
/*
*----------------------------------------------------------------------
*
- * ComputeUnixButtonGeometry --
+ * TkMacOSXComputeButtonDrawParams --
*
- * After changes in a button's text or bitmap, this procedure
- * recomputes the button's geometry and passes this information
- * along to the geometry manager for the window.
+ * This procedure computes the various parameters used
+ * when drawing a button
+ * These are determined by the various tk button parameters
*
* Results:
- * None.
+ * 1 if control will be used, 0 otherwise.
*
* Side effects:
- * The button's window may change size.
+ * Sets the button draw parameters
*
*----------------------------------------------------------------------
*/
-void
-ComputeUnixButtonGeometry(
- register TkButton *butPtr) /* Button whose geometry may have changed. */
+static int
+TkMacOSXComputeButtonDrawParams(
+ TkButton *butPtr,
+ DrawParams *dpPtr)
{
- int width, height, avgWidth, txtWidth, txtHeight;
- int haveImage = 0, haveText = 0;
- Tk_FontMetrics fm;
-
- butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth;
-
- /*
- * Leave room for the default ring if needed.
- */
-
- if (butPtr->defaultState != DEFAULT_DISABLED) {
- butPtr->inset += 5;
+ MacButton *mbPtr = (MacButton *)butPtr;
+
+ dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
+ || (butPtr->bitmap != None));
+
+ if (butPtr->type != TYPE_LABEL) {
+ dpPtr->offset = 0;
+ if (dpPtr->hasImageOrBitmap) {
+ switch (mbPtr->btnkind) {
+ case kThemeSmallBevelButton:
+ case kThemeBevelButton:
+ case kThemeRoundedBevelButton:
+ case kThemePushButton:
+ dpPtr->offset = 1;
+ break;
+ }
+ }
}
- butPtr->indicatorSpace = 0;
- width = 0;
- height = 0;
- txtWidth = 0;
- txtHeight = 0;
- avgWidth = 0;
- if (butPtr->image != NULL) {
- Tk_SizeOfImage(butPtr->image, &width, &height);
- haveImage = 1;
- } else if (butPtr->bitmap != None) {
- Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
- haveImage = 1;
+ dpPtr->border = butPtr->normalBorder;
+ if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
+ dpPtr->gc = butPtr->disabledGC;
+ } else if (butPtr->type == TYPE_BUTTON && butPtr->state == STATE_ACTIVE) {
+ dpPtr->gc = butPtr->activeTextGC;
+ dpPtr->border = butPtr->activeBorder;
+ } else {
+ dpPtr->gc = butPtr->normalTextGC;
}
- if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
- Tk_FreeTextLayout(butPtr->textLayout);
-
- butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
- Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
- butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
-
- txtWidth = butPtr->textWidth;
- txtHeight = butPtr->textHeight;
- avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
- Tk_GetFontMetrics(butPtr->tkfont, &fm);
- haveText = (txtWidth != 0 && txtHeight != 0);
+ if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
+ && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
+ dpPtr->border = butPtr->selectBorder;
}
/*
- * If the button is compound (i.e., it shows both an image and text), the
- * new geometry is a combination of the image and text geometry. We only
- * honor the compound bit if the button has both text and an image,
- * because otherwise it is not really a compound button.
+ * Override the relief specified for the button if this is a
+ * checkbutton or radiobutton and there's no indicator.
+ * However, don't do this in the presence of Appearance, since
+ * then the bevel button will take care of the relief.
*/
- if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
- switch ((enum compound) butPtr->compound) {
- case COMPOUND_TOP:
- case COMPOUND_BOTTOM:
- /*
- * Image is above or below text.
- */
+ dpPtr->relief = butPtr->relief;
- height += txtHeight + butPtr->padY;
- width = (width > txtWidth ? width : txtWidth);
- break;
- case COMPOUND_LEFT:
- case COMPOUND_RIGHT:
- /*
- * Image is left or right of text.
- */
-
- width += txtWidth + butPtr->padX;
- height = (height > txtHeight ? height : txtHeight);
- break;
- case COMPOUND_CENTER:
- /*
- * Image and text are superimposed.
- */
-
- width = (width > txtWidth ? width : txtWidth);
- height = (height > txtHeight ? height : txtHeight);
- break;
- case COMPOUND_NONE:
- break;
- }
- if (butPtr->width > 0) {
- width = butPtr->width;
- }
- if (butPtr->height > 0) {
- height = butPtr->height;
+ if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
+ if (!dpPtr->hasImageOrBitmap) {
+ dpPtr->relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
+ : TK_RELIEF_RAISED;
}
+ }
- width += 2*butPtr->padX;
- height += 2*butPtr->padY;
- } else {
- if (haveImage) {
- if (butPtr->width > 0) {
- width = butPtr->width;
- }
- if (butPtr->height > 0) {
- height = butPtr->height;
- }
- } else {
- width = txtWidth;
- height = txtHeight;
+ /*
+ * Determine the draw type
+ */
- if (butPtr->width > 0) {
- width = butPtr->width * avgWidth;
- }
- if (butPtr->height > 0) {
- height = butPtr->height * fm.linespace;
- }
+ if (butPtr->type == TYPE_LABEL) {
+ dpPtr->drawType = DRAW_LABEL;
+ } else if (butPtr->type == TYPE_BUTTON) {
+ if (!dpPtr->hasImageOrBitmap) {
+ dpPtr->drawType = DRAW_CONTROL;
+ } else {
+ dpPtr->drawType = DRAW_BEVEL;
}
+ } else if (butPtr->indicatorOn) {
+ dpPtr->drawType = DRAW_CONTROL;
+ } else if (dpPtr->hasImageOrBitmap) {
+ dpPtr->drawType = DRAW_BEVEL;
+ } else {
+ dpPtr->drawType = DRAW_CUSTOM;
}
- if (!haveImage) {
- width += 2*butPtr->padX;
- height += 2*butPtr->padY;
+ if ((dpPtr->drawType == DRAW_CONTROL) || (dpPtr->drawType == DRAW_BEVEL)) {
+ return 1;
+ } else {
+ return 0;
}
- Tk_GeometryRequest(butPtr->tkwin, (int) (width
- + 2*butPtr->inset), (int) (height + 2*butPtr->inset));
- Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}
-
/*
- * Local Variables:
- * mode: objc
- * c-basic-offset: 4
- * fill-column: 79
- * coding: utf-8
- * End:
+ *--------------------------------------------------------------
+ *
+ * PulseDefaultButtonProc --
+ *
+ * This function redraws the button on a timer, to pulse
+ * default buttons.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Sets a timer to run itself again.
+ *
+ *--------------------------------------------------------------
*/
+static void
+PulseDefaultButtonProc(ClientData clientData)
+{
+ MacButton *mbPtr = (MacButton *)clientData;
+ TkpDisplayButton(clientData);
+ mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
+ PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData);
+}
+
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index ecc6c0d..8fe9a95 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -101,13 +101,6 @@ TkMacOSXInitCGDrawing(
(char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
Tcl_ResetResult(interp);
}
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (Tcl_LinkVar(interp, "::tk::mac::useCompatibilityMetrics",
- (char *) &tkMacOSXUseCompatibilityMetrics, TCL_LINK_BOOLEAN)
- != TCL_OK) {
- Tcl_ResetResult(interp);
- }
-#endif
}
return TCL_OK;
}
@@ -1516,21 +1509,6 @@ TkScrollWindow(
/* Scroll the rectangle. */
[view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];
-
- /*
- * Adjust the positions of the button subwindows that meet the scroll
- * area.
- */
-
- for (NSView *subview in [view subviews] ) {
- if ( [subview isKindOfClass:[NSButton class]] == YES ) {
- NSRect subframe = [subview frame];
- if ( NSIntersectsRect(scrollSrc, subframe) ||
- NSIntersectsRect(scrollDst, subframe) ) {
- TkpShiftButton((NSButton *)subview, delta );
- }
- }
- }
/* Redisplay the scrolled area; hide to reduce flicker after removal of private API calls. */
[view setHidden:YES];
diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c
index abb2c6e..a1c3138 100644
--- a/macosx/tkMacOSXMenubutton.c
+++ b/macosx/tkMacOSXMenubutton.c
@@ -5,76 +5,71 @@
* menubutton widget.
*
* Copyright (c) 1996 by Sun Microsystems, Inc.
- * Copyright 2001-2009, Apple Inc.
- * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
+ * Copyright 2001, Apple Computer, Inc.
+ * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net>
+ * Copyright 2007 Revar Desmera.
+ * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
*/
#include "tkMacOSXPrivate.h"
+#include "tkMenu.h"
#include "tkMenubutton.h"
#include "tkMacOSXFont.h"
#include "tkMacOSXDebug.h"
-/*
-#ifdef TK_MAC_DEBUG
-#define TK_MAC_DEBUG_MENUBUTTON
-#endif
-*/
+#define FIRST_DRAW 2
+#define ACTIVE 4
-typedef struct MacMenuButton {
- TkMenuButton info;
- NSPopUpButton *button;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- int fix;
-#endif
-} MacMenuButton;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
+typedef struct {
+ Tk_3DBorder border;
+ int relief;
+ GC gc;
+ int hasImageOrBitmap;
+} DrawParams;
+
/*
- * Use the following heuristic conversion constants to make NSButton-based
- * widget metrics match up with the old Carbon control buttons (for the
- * default Lucida Grande 13 font).
- * TODO: provide a scriptable way to turn this off and use the raw NSButton
- * metrics (will also need dynamic adjustment of the default padding,
- * c.f. tkMacOSXDefault.h).
+ * Declaration of Mac specific button structure.
*/
-typedef struct {
- int trimW, trimH, inset, shrinkW, offsetX, offsetY;
-} BoundsFix;
-
-#define fixForStyle(style) ( \
- style == NSRoundedBezelStyle ? 1 : \
- style == NSRegularSquareBezelStyle ? 2 : \
- style == NSShadowlessSquareBezelStyle ? 3 : \
- INT_MIN)
-
-static const BoundsFix boundsFixes[] = {
- [fixForStyle(NSRoundedBezelStyle)] = { 14, 10, -2, -1},
- [fixForStyle(NSRegularSquareBezelStyle)] = { 6, 13, -2, 1, 1},
- [fixForStyle(NSShadowlessSquareBezelStyle)] = { 15, 0, 2 },
-};
-
-#endif
+typedef struct MacMenuButton {
+ TkMenuButton info; /* Generic button info. */
+ int flags;
+ ThemeButtonKind btnkind;
+ HIThemeButtonDrawInfo drawinfo;
+ HIThemeButtonDrawInfo lastdrawinfo;
+ DrawParams drawParams;
+} MacMenuButton;
/*
* Forward declarations for procedures defined later in this file:
*/
static void MenuButtonEventProc(ClientData clientData, XEvent *eventPtr);
+static void MenuButtonBackgroundDrawCB ( MacMenuButton *ptr, SInt16 depth, Boolean isColorDev);
+static void MenuButtonContentDrawCB ( ThemeButtonKind kind, const HIThemeButtonDrawInfo * info, MacMenuButton *ptr, SInt16 depth, Boolean isColorDev);
+static void MenuButtonEventProc ( ClientData clientData, XEvent *eventPtr);
+static void TkMacOSXComputeMenuButtonParams (TkMenuButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo* drawinfo);
+static int TkMacOSXComputeMenuButtonDrawParams (TkMenuButton * butPtr, DrawParams * dpPtr);
+static void TkMacOSXDrawMenuButton (MacMenuButton *butPtr,
+ GC gc, Pixmap pixmap);
+static void DrawMenuButtonImageAndText(TkMenuButton* butPtr);
/*
- * The structure below defines menubutton class behavior by means of functions
- * that can be invoked from generic window code.
+ * The structure below defines menubutton class behavior by means of
+ * procedures that can be invoked from generic window code.
*/
Tk_ClassProcs tkpMenubuttonClass = {
sizeof(Tk_ClassProcs), /* size */
TkMenuButtonWorldChanged, /* worldChangedProc */
};
+
/*
*----------------------------------------------------------------------
@@ -96,115 +91,94 @@ TkMenuButton *
TkpCreateMenuButton(
Tk_Window tkwin)
{
- MacMenuButton *macButtonPtr =
- (MacMenuButton *) ckalloc(sizeof(MacMenuButton));
-
- macButtonPtr->button = nil;
+ MacMenuButton *mbPtr = (MacMenuButton *) ckalloc(sizeof(MacMenuButton));
Tk_CreateEventHandler(tkwin, ActivateMask,
- MenuButtonEventProc, (ClientData) macButtonPtr);
- return (TkMenuButton *) macButtonPtr;
+ MenuButtonEventProc, (ClientData) mbPtr);
+ mbPtr->flags = FIRST_DRAW;
+ mbPtr->btnkind = kThemePopupButton;
+ bzero(&mbPtr->drawinfo, sizeof(mbPtr->drawinfo));
+ bzero(&mbPtr->lastdrawinfo, sizeof(mbPtr->lastdrawinfo));
+
+ return (TkMenuButton *) mbPtr;
}
/*
*----------------------------------------------------------------------
*
- * TkpDestroyMenuButton --
+ * TkpDisplayMenuButton --
*
- * Free data structures associated with the menubutton control.
+ * This procedure is invoked to display a menubutton widget.
*
* Results:
* None.
*
* Side effects:
- * Restores the default control state.
+ * Commands are output to X to display the menubutton in its
+ * current mode.
*
*----------------------------------------------------------------------
*/
void
-TkpDestroyMenuButton(
- TkMenuButton *mbPtr)
+TkpDisplayMenuButton(
+ ClientData clientData) /* Information about widget. */
{
- MacMenuButton *macButtonPtr = (MacMenuButton *) mbPtr;
- [macButtonPtr->button setTag:(NSInteger)-1];
+ MacMenuButton *mbPtr = (MacMenuButton *)clientData;
+ TkMenuButton *butPtr = (TkMenuButton *) clientData;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ DrawParams* dpPtr = &mbPtr->drawParams;
+
+ butPtr->flags &= ~REDRAW_PENDING;
+ if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
+ return;
+ }
+
+ pixmap = (Pixmap) Tk_WindowId(tkwin);
+
+ TkMacOSXComputeMenuButtonDrawParams(butPtr, dpPtr);
+
+ /*
+ * set up clipping region. Make sure the we are using the port
+ * for this button, or we will set the wrong window's clip.
+ */
+
+ TkMacOSXSetUpClippingRgn(pixmap);
- TkMacOSXMakeCollectableAndRelease(macButtonPtr->button);
+ /* Draw the native portion of the buttons. */
+ TkMacOSXDrawMenuButton(mbPtr, dpPtr->gc, pixmap);
+
+ /* Draw highlight border, if needed. */
+ if (butPtr->highlightWidth < 3) {
+ if ((butPtr->flags & GOT_FOCUS)) {
+ Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin),
+ butPtr->highlightWidth, TK_RELIEF_SOLID);
+ }
+ }
}
/*
*----------------------------------------------------------------------
*
- * TkpDisplayMenuButton --
+ * TkpDestroyMenuButton --
*
- * This function is invoked to display a menubutton widget.
+ * Free data structures associated with the menubutton control.
*
* Results:
* None.
*
* Side effects:
- * Commands are output to X to display the menubutton in its current
- * mode.
+ * Restores the default control state.
*
*----------------------------------------------------------------------
*/
void
-TkpDisplayMenuButton(
- ClientData clientData) /* Information about widget. */
+TkpDestroyMenuButton(
+ TkMenuButton *mbPtr)
{
- TkMenuButton *mbPtr = (TkMenuButton *) clientData;
- MacMenuButton *macButtonPtr = (MacMenuButton *) mbPtr;
- NSPopUpButton *button = macButtonPtr->button;
- Tk_Window tkwin = mbPtr->tkwin;
- TkWindow *winPtr = (TkWindow *) tkwin;
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- TkMacOSXDrawingContext dc;
- NSView *view = TkMacOSXDrawableView(macWin);
- CGFloat viewHeight = [view bounds].size.height;
- CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
- .ty = viewHeight};
- NSRect frame;
- int enabled;
-
- mbPtr->flags &= ~REDRAW_PENDING;
- if (!tkwin || !Tk_IsMapped(tkwin) || !view ||
- !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
- return;
- }
- CGContextConcatCTM(dc.context, t);
- Tk_Fill3DRectangle(tkwin, (Pixmap) macWin, mbPtr->normalBorder, 0, 0,
- Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
- if ([button superview] != view) {
- [view addSubview:button];
- }
- enabled = !(mbPtr->state == STATE_DISABLED);
- [button setEnabled:enabled];
- if (enabled) {
- [[button cell] setHighlighted:(mbPtr->state == STATE_ACTIVE)];
- }
- frame = NSMakeRect(macWin->xOff, macWin->yOff, Tk_Width(tkwin),
- Tk_Height(tkwin));
- frame = NSInsetRect(frame, mbPtr->inset, mbPtr->inset);
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- BoundsFix boundsFix = boundsFixes[macButtonPtr->fix];
- frame = NSOffsetRect(frame, boundsFix.offsetX, boundsFix.offsetY);
- frame.size.width -= boundsFix.shrinkW;
- frame = NSInsetRect(frame, boundsFix.inset, boundsFix.inset);
- }
-#endif
- frame.origin.y = viewHeight - (frame.origin.y + frame.size.height);
- if (!NSEqualRects(frame, [button frame])) {
- [button setFrame:frame];
- }
- [button displayRectIgnoringOpacity:[button bounds]];
- TkMacOSXRestoreDrawingContext(&dc);
-#ifdef TK_MAC_DEBUG_MENUBUTTON
- TKLog(@"menubutton %s frame %@ width %d height %d",
- ((TkWindow *)mbPtr->tkwin)->pathName, NSStringFromRect(frame),
- Tk_Width(tkwin), Tk_Height(tkwin));
-#endif
}
/*
@@ -212,7 +186,7 @@ TkpDisplayMenuButton(
*
* TkpComputeMenuButtonGeometry --
*
- * After changes in a menu button's text or bitmap, this function
+ * After changes in a menu button's text or bitmap, this procedure
* recomputes the menu button's geometry and passes this information
* along to the geometry manager for the window.
*
@@ -226,205 +200,508 @@ TkpDisplayMenuButton(
*/
void
-TkpComputeMenuButtonGeometry(
- TkMenuButton *mbPtr) /* Widget record for menu button. */
+TkpComputeMenuButtonGeometry(butPtr)
+ register TkMenuButton *butPtr; /* Widget record for menu button. */
{
- MacMenuButton *macButtonPtr = (MacMenuButton *) mbPtr;
- NSPopUpButton *button = macButtonPtr->button;
- NSPopUpButtonCell *cell;
- NSMenuItem *menuItem;
- NSBezelStyle style = NSRoundedBezelStyle;
- NSFont *font;
- NSRect bounds = NSZeroRect, titleRect = NSZeroRect;
- int haveImage = (mbPtr->image || mbPtr->bitmap != None), haveText = 0;
- int haveCompound = (mbPtr->compound != COMPOUND_NONE);
- int width, height;
-
- if (!button) {
- button = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:YES];
- macButtonPtr->button = TkMacOSXMakeUncollectable(button);
- cell = [button cell];
- [cell setUsesItemFromMenu:NO];
- menuItem = [[[NSMenuItem alloc] initWithTitle:@""
- action:NULL keyEquivalent:@""] autorelease];
- [cell setMenuItem:menuItem];
- } else {
- cell = [button cell];
- menuItem = [cell menuItem];
+ int width, height, avgWidth, haveImage = 0, haveText = 0;
+ MacMenuButton *mbPtr = (MacMenuButton*)butPtr;
+ int txtWidth, txtHeight;
+ Tk_FontMetrics fm;
+ DrawParams drawParams;
+ int paddingx = 0;
+ int paddingy = 0;
+
+ /*
+ * First figure out the size of the contents of the button.
+ */
+
+ width = 0;
+ height = 0;
+ txtWidth = 0;
+ txtHeight = 0;
+ avgWidth = 0;
+
+ TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
+
+ if (butPtr->image != NULL) {
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
+ } else if (butPtr->bitmap != None) {
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
}
- if (haveImage) {
- style = NSShadowlessSquareBezelStyle;
- } else if (!mbPtr->indicatorOn) {
- style = NSRegularSquareBezelStyle;
+
+ if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
+ Tk_FreeTextLayout(butPtr->textLayout);
+ butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
+ butPtr->text, -1, butPtr->wrapLength,
+ butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
+
+ txtWidth = butPtr->textWidth;
+ txtHeight = butPtr->textHeight;
+ avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
+ Tk_GetFontMetrics(butPtr->tkfont, &fm);
+ haveText = (txtWidth != 0 && txtHeight != 0);
}
- [button setBezelStyle:style];
- [cell setArrowPosition:(mbPtr->indicatorOn ? NSPopUpArrowAtBottom :
- NSPopUpNoArrow)];
-#if 0
- NSControlSize controlSize = NSRegularControlSize;
-
- if (mbPtr->borderWidth <= 2) {
- controlSize = NSMiniControlSize;
- } else if (mbPtr->borderWidth == 3) {
- controlSize = NSSmallControlSize;
+
+ /*
+ * If the button is compound (ie, it shows both an image and text),
+ * the new geometry is a combination of the image and text geometry.
+ * We only honor the compound bit if the button has both text and an
+ * image, because otherwise it is not really a compound button.
+ */
+
+ if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM: {
+ /*
+ * Image is above or below text
+ */
+
+ height += txtHeight + butPtr->padY;
+ width = (width > txtWidth ? width : txtWidth);
+ break;
+ }
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT: {
+ /*
+ * Image is left or right of text
+ */
+
+ width += txtWidth + butPtr->padX;
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ }
+ case COMPOUND_CENTER: {
+ /*
+ * Image and text are superimposed
+ */
+
+ width = (width > txtWidth ? width : txtWidth);
+ height = (height > txtHeight ? height : txtHeight);
+ break;
+ }
+ case COMPOUND_NONE: {break;}
+ }
+
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+
+ } else {
+ if (haveImage) {
+ if (butPtr->width > 0) {
+ width = butPtr->width;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height;
+ }
+ } else {
+ width = txtWidth;
+ height = txtHeight;
+ if (butPtr->width > 0) {
+ width = butPtr->width * avgWidth;
+ }
+ if (butPtr->height > 0) {
+ height = butPtr->height * fm.linespace;
+ }
+ }
}
- [cell setControlSize:controlSize];
-#endif
-
- if (mbPtr->text && *(mbPtr->text) && (!haveImage || haveCompound)) {
- NSString *title = [[NSString alloc] initWithUTF8String:mbPtr->text];
- [button setTitle:title];
- [title release];
- haveText = 1;
+ width += 2 * butPtr->padX - 2;
+ height += 2 * butPtr->padY - 2;
+
+ /*Add padding for button arrows.*/
+ width += 22;
+
+ /*
+ * Now figure out the size of the border decorations for the button.
+ */
+
+ if (butPtr->highlightWidth < 0) {
+ butPtr->highlightWidth = 0;
}
- haveCompound = (haveCompound && haveImage && haveText);
- if (haveText) {
- NSTextAlignment alignment = NSNaturalTextAlignment;
-
- switch (mbPtr->justify) {
- case TK_JUSTIFY_LEFT:
- alignment = NSLeftTextAlignment;
- break;
- case TK_JUSTIFY_RIGHT:
- alignment = NSRightTextAlignment;
- break;
- case TK_JUSTIFY_CENTER:
- alignment = NSCenterTextAlignment;
- break;
- }
- [button setAlignment:alignment];
- } else {
- [button setTitle:@""];
+ butPtr->inset = 0;
+ butPtr->inset += butPtr->highlightWidth;
+
+ TkMacOSXComputeMenuButtonDrawParams(butPtr,&drawParams);
+
+ HIRect tmpRect;
+ HIRect contBounds;
+
+ tmpRect = CGRectMake(0, 0, width, height);
+
+ HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
+
+
+
+ /* If the content region has a minimum height, match it. */
+ if (height < contBounds.size.height) {
+ height = contBounds.size.height;
+ }
+
+ /* If the content region has a minimum width, match it. */
+ if (width < contBounds.size.width) {
+ width = contBounds.size.width;
+ }
+
+ /* Pad to fill difference between content bounds and button bounds. */
+ paddingx = tmpRect.origin.x - contBounds.origin.x;
+ paddingy = tmpRect.origin.y - contBounds.origin.y;
+
+ if (paddingx > 0) {
+ width += paddingx;
}
- font = TkMacOSXNSFontForFont(mbPtr->tkfont);
- if (font) {
- [button setFont:font];
+ if (paddingy > 0) {
+ height += paddingy;
}
- if (haveImage) {
- int width, height;
- NSImage *image;
- NSCellImagePosition pos = NSImageOnly;
-
- if (mbPtr->image) {
- Tk_SizeOfImage(mbPtr->image, &width, &height);
- image = TkMacOSXGetNSImageWithTkImage(mbPtr->display,
- mbPtr->image, width, height);
- } else {
- Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
- image = TkMacOSXGetNSImageWithBitmap(mbPtr->display,
- mbPtr->bitmap, mbPtr->normalTextGC, width, height);
- }
- if (haveCompound) {
- switch ((enum compound) mbPtr->compound) {
- case COMPOUND_TOP:
- pos = NSImageAbove;
- break;
- case COMPOUND_BOTTOM:
- pos = NSImageBelow;
- break;
- case COMPOUND_LEFT:
- pos = NSImageLeft;
- break;
- case COMPOUND_RIGHT:
- pos = NSImageRight;
- break;
- case COMPOUND_CENTER:
- pos = NSImageOverlaps;
- break;
- case COMPOUND_NONE:
- pos = NSImageOnly;
- break;
- }
- }
- [button setImagePosition:pos];
- [menuItem setImage:image];
- bounds.size = cell ? [cell cellSize] : NSZeroSize;
- if (bounds.size.height < height + 8) { /* workaround AppKit sizing bug */
- bounds.size.height = height + 8;
- }
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (!mbPtr->indicatorOn && tkMacOSXUseCompatibilityMetrics) {
- bounds.size.width -= 16;
- }
-#endif
- } else {
- bounds.size = cell ? [cell cellSize] : NSZeroSize;
+
+ width += butPtr->inset*2;
+ height += butPtr->inset*2;
+
+
+ Tk_GeometryRequest(butPtr->tkwin, width, height);
+ Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * DrawMenuButtonImageAndText --
+ *
+ * Draws the image and text associated witha button or label.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The image and text are drawn.
+ *
+ *----------------------------------------------------------------------
+ */
+void
+DrawMenuButtonImageAndText(
+ TkMenuButton* butPtr)
+{
+ MacMenuButton *mbPtr = (MacMenuButton*)butPtr;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ int haveImage = 0;
+ int haveText = 0;
+ int imageWidth = 0;
+ int imageHeight = 0;
+ int imageXOffset = 0;
+ int imageYOffset = 0;
+ int textXOffset = 0;
+ int textYOffset = 0;
+ int width = 0;
+ int height = 0;
+ int fullWidth = 0;
+ int fullHeight = 0;
+ int pressed;
+
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
- if (haveText) {
- titleRect = cell ? [cell titleRectForBounds:bounds] : NSZeroRect;
- if (mbPtr->wrapLength > 0 &&
- titleRect.size.width > mbPtr->wrapLength) {
- if (style == NSRoundedBezelStyle) {
- [button setBezelStyle:(style = NSRegularSquareBezelStyle)];
- bounds.size = cell ? [cell cellSize] : NSZeroSize;
- titleRect = cell ? [cell titleRectForBounds:bounds] : NSZeroRect;
- }
- bounds.size.width -= titleRect.size.width - mbPtr->wrapLength;
- bounds.size.height = 40000.0;
- [cell setWraps:YES];
- bounds.size = cell ? [cell cellSizeForBounds:bounds] : NSZeroSize;
-#ifdef TK_MAC_DEBUG_MENUBUTTON
- titleRect = cell ? [cell titleRectForBounds:bounds] : NSZeroRect;
-#endif
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- bounds.size.height += 3;
- }
-#endif
- }
+
+ DrawParams* dpPtr = &mbPtr->drawParams;
+ pixmap = (Pixmap)Tk_WindowId(tkwin);
+
+
+ if (butPtr->image != None) {
+ Tk_SizeOfImage(butPtr->image, &width, &height);
+ haveImage = 1;
+ } else if (butPtr->bitmap != None) {
+ Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
+ haveImage = 1;
}
- width = lround(bounds.size.width);
- height = lround(bounds.size.height);
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
- if (tkMacOSXUseCompatibilityMetrics) {
- macButtonPtr->fix = fixForStyle(style);
- width -= boundsFixes[macButtonPtr->fix].trimW;
- height -= boundsFixes[macButtonPtr->fix].trimH;
+
+ imageWidth = width;
+ imageHeight = height;
+
+ if (mbPtr->drawinfo.state == kThemeStatePressed) {
+ /* Offset bitmaps by a bit when the button is pressed. */
+ pressed = 1;
}
-#endif
+
+ haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
+ if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
+ int x = 0;
+ int y = 0;
+ textXOffset = 0;
+ textYOffset = 0;
+ fullWidth = 0;
+ fullHeight = 0;
- if (haveImage || haveCompound) {
- if (mbPtr->width > 0) {
- width = mbPtr->width;
- }
- if (mbPtr->height > 0) {
- height = mbPtr->height;
+ switch ((enum compound) butPtr->compound) {
+ case COMPOUND_TOP:
+ case COMPOUND_BOTTOM: {
+ /* Image is above or below text */
+ if (butPtr->compound == COMPOUND_TOP) {
+ textYOffset = height + butPtr->padY;
+ } else {
+ imageYOffset = butPtr->textHeight + butPtr->padY;
+ }
+ fullHeight = height + butPtr->textHeight + butPtr->padY;
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ break;
+ }
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT: {
+ /*
+ * Image is left or right of text
+ */
+
+ if (butPtr->compound == COMPOUND_LEFT) {
+ textXOffset = width + butPtr->padX - 2;
+ } else {
+ imageXOffset = butPtr->textWidth + butPtr->padX;
+ }
+ fullWidth = butPtr->textWidth + butPtr->padX + width;
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_CENTER: {
+ /*
+ * Image and text are superimposed
+ */
+
+ fullWidth = (width > butPtr->textWidth ? width :
+ butPtr->textWidth);
+ fullHeight = (height > butPtr->textHeight ? height :
+ butPtr->textHeight);
+ textXOffset = (fullWidth - butPtr->textWidth)/2;
+ imageXOffset = (fullWidth - width)/2;
+ textYOffset = (fullHeight - butPtr->textHeight)/2;
+ imageYOffset = (fullHeight - height)/2;
+ break;
+ }
+ case COMPOUND_NONE: {break;}
}
+
+ TkComputeAnchor(butPtr->anchor, tkwin,
+ butPtr->padX + butPtr->borderWidth,
+ butPtr->padY + butPtr->borderWidth,
+ fullWidth, fullHeight, &x, &y);
+ imageXOffset += x;
+ imageYOffset += y;
+ textYOffset -= 1;
+
+ if (butPtr->image != NULL) {
+ Tk_RedrawImage(butPtr->image, 0, 0, width,
+ height, pixmap, imageXOffset, imageYOffset);
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc,
+ imageXOffset, imageYOffset);
+ XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width, (unsigned int) height,
+ imageXOffset, imageYOffset, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+
+ Tk_DrawTextLayout(butPtr->display, pixmap,
+ dpPtr->gc, butPtr->textLayout,
+ x + textXOffset, y + textYOffset, 0, -1);
+ Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout,
+ x + textXOffset, y + textYOffset,
+ butPtr->underline);
} else {
- if (mbPtr->width > 0) {
- int avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
- width = mbPtr->width * avgWidth;
+ if (haveImage) {
+ int x = 0;
+ int y;
+ TkComputeAnchor(butPtr->anchor, tkwin,
+ butPtr->padX + butPtr->borderWidth,
+ butPtr->padY + butPtr->borderWidth,
+ width, height, &x, &y);
+ imageXOffset += x;
+ imageYOffset += y;
+
+ if (butPtr->image != NULL) {
+ Tk_RedrawImage(butPtr->image, 0, 0, width, height,
+ pixmap, imageXOffset, imageYOffset);
+ } else {
+ XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
+ XCopyPlane(butPtr->display, butPtr->bitmap,
+ pixmap, dpPtr->gc,
+ 0, 0, (unsigned int) width,
+ (unsigned int) height,
+ imageXOffset, imageYOffset, 1);
+ XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
+ }
+ } else {
+ /*Move x back by six pixels to give the menubutton arrows room.*/
+ int x = 0;
+ int y;
+ textXOffset = 6;
+ TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
+ butPtr->textWidth, butPtr->textHeight, &x, &y);
+ Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
+ butPtr->textLayout, x - textXOffset, y, 0, -1);
+ y += butPtr->textHeight/2;
+ }
+ }
+}
+
+
+
+/*
+ *--------------------------------------------------------------
+ *
+ * TkMacOSXDrawMenuButton --
+ *
+ * This function draws the tk menubutton using Mac controls
+ * In addition, this code may apply custom colors passed
+ * in the TkMenubutton.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *--------------------------------------------------------------
+ */
+static void
+TkMacOSXDrawMenuButton(
+ MacMenuButton *mbPtr, /* Mac menubutton. */
+ 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 */
+
+{
+ TkMenuButton * butPtr = ( TkMenuButton *)mbPtr;
+ TkWindow * winPtr;
+ HIRect cntrRect;
+ TkMacOSXDrawingContext dc;
+ DrawParams* dpPtr = &mbPtr->drawParams;
+ int useNewerHITools = 1;
+
+ winPtr = (TkWindow *)butPtr->tkwin;
+
+ TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
+
+ cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, Tk_Width(butPtr->tkwin),Tk_Height(butPtr->tkwin));
+
+ cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset);
+
+
+ if (useNewerHITools == 1) {
+ HIRect hirec;
+ HIRect contHIRec;
+ static HIThemeButtonDrawInfo hiinfo;
+ Rect contRect;
+
+ MenuButtonBackgroundDrawCB((MacMenuButton*) mbPtr, 32, true);
+
+ if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
+ return;
}
- if (mbPtr->height > 0) {
- Tk_FontMetrics fm;
- Tk_GetFontMetrics(mbPtr->tkfont, &fm);
- height = mbPtr->height * fm.linespace;
+
+ hiinfo.version = 0;
+ hiinfo.state = mbPtr->drawinfo.state;
+ hiinfo.kind = mbPtr->btnkind;
+ hiinfo.value = mbPtr->drawinfo.value;
+ hiinfo.adornment = mbPtr->drawinfo.adornment;
+ hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
+ if (hiinfo.animation.time.start == 0) {
+ hiinfo.animation.time.start = hiinfo.animation.time.current;
+ }
+
+ HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, &contHIRec);
+
+ TkMacOSXRestoreDrawingContext(&dc);
+
+ MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo, (MacMenuButton *)mbPtr, 32, true);
+ } else {
+ if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
+ return;
}
+
+
+ TkMacOSXRestoreDrawingContext(&dc);
}
- if (!haveImage || haveCompound) {
- width += 2*mbPtr->padX;
- height += 2*mbPtr->padY;
- }
- if (mbPtr->highlightWidth < 0) {
- mbPtr->highlightWidth = 0;
+ mbPtr->lastdrawinfo = mbPtr->drawinfo;
+}
+
+/*
+ *--------------------------------------------------------------
+ *
+ * MenuButtonBackgroundDrawCB --
+ *
+ * This function draws the background that
+ * lies under checkboxes and radiobuttons.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The background gets updated to the current color.
+ *
+ *--------------------------------------------------------------
+ */
+static void
+MenuButtonBackgroundDrawCB (
+ MacMenuButton *ptr,
+ SInt16 depth,
+ Boolean isColorDev)
+{
+ TkMenuButton* butPtr = (TkMenuButton*)ptr;
+ Tk_Window tkwin = butPtr->tkwin;
+ Pixmap pixmap;
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
- if (haveImage) {
- mbPtr->inset = mbPtr->highlightWidth;
- width += 2*mbPtr->borderWidth;
- height += 2*mbPtr->borderWidth;
- } else {
- mbPtr->inset = mbPtr->highlightWidth + mbPtr->borderWidth;
+ pixmap = (Pixmap)Tk_WindowId(tkwin);
+
+ Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
+ Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
+}
+
+/*
+ *--------------------------------------------------------------
+ *
+ * MenuButtonContentDrawCB --
+ *
+ * This function draws the label and image for the button.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The content of the button gets updated.
+ *
+ *--------------------------------------------------------------
+ */
+static void
+MenuButtonContentDrawCB (
+ ThemeButtonKind kind,
+ const HIThemeButtonDrawInfo *drawinfo,
+ MacMenuButton *ptr,
+ SInt16 depth,
+ Boolean isColorDev)
+{
+ TkMenuButton *butPtr = (TkMenuButton *)ptr;
+ Tk_Window tkwin = butPtr->tkwin;
+ Rect bounds;
+
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
+ return;
}
- Tk_GeometryRequest(mbPtr->tkwin, width + 2 * mbPtr->inset,
- height + 2 * mbPtr->inset);
- Tk_SetInternalBorder(mbPtr->tkwin, mbPtr->inset);
-#ifdef TK_MAC_DEBUG_MENUBUTTON
- TKLog(@"menubutton %s bounds %@ titleRect %@ width %d height %d inset %d borderWidth %d",
- ((TkWindow *)mbPtr->tkwin)->pathName, NSStringFromRect(bounds),
- NSStringFromRect(titleRect), width, height, mbPtr->inset,
- mbPtr->borderWidth);
-#endif
+ MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tkwin);
+
+ DrawMenuButtonImageAndText( butPtr);
}
/*
@@ -439,7 +716,7 @@ TkpComputeMenuButtonGeometry(
* None.
*
* Side effects:
- * When activation state changes, it is redisplayed.
+ * When it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
@@ -449,27 +726,124 @@ MenuButtonEventProc(
ClientData clientData, /* Information about window. */
XEvent *eventPtr) /* Information about event. */
{
- TkMenuButton *mbPtr = (TkMenuButton *) clientData;
+ TkMenuButton *buttonPtr = (TkMenuButton *) clientData;
+ MacMenuButton *mbPtr = (MacMenuButton *) clientData;
- if (!mbPtr->tkwin || !Tk_IsMapped(mbPtr->tkwin)) {
- return;
+ 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(TkpDisplayMenuButton, (ClientData) buttonPtr);
+ buttonPtr->flags |= REDRAW_PENDING;
+ }
}
- switch (eventPtr->type) {
- case ActivateNotify:
- case DeactivateNotify:
- if (!(mbPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) mbPtr);
- mbPtr->flags |= REDRAW_PENDING;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TkMacOSXComputeMenuButtonParams --
+ *
+ * This procedure computes the various parameters used
+ * when creating a Carbon Appearance control.
+ * These are determined by the various tk button parameters
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Sets the btnkind and drawinfo parameters
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+TkMacOSXComputeMenuButtonParams(TkMenuButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo *drawinfo)
+{
+ MacMenuButton *mbPtr = (MacMenuButton *)butPtr;
+
+ if (butPtr->image || butPtr->bitmap) {
+ /* TODO: allow for Small and Mini menubuttons. */
+ *btnkind = kThemePopupButton;
+ } else {
+ if (!butPtr->text || !*butPtr->text) {
+ *btnkind = kThemeArrowButton;
+ } else {
+ *btnkind = kThemePopupButton;
+ }
+ }
+
+ drawinfo->value = kThemeButtonOff;
+
+ if ((mbPtr->flags & FIRST_DRAW) != 0) {
+ mbPtr->flags &= ~FIRST_DRAW;
+ if (Tk_MacOSXIsAppInFront()) {
+ mbPtr->flags |= ACTIVE;
}
- break;
}
+
+ drawinfo->state = kThemeStateInactive;
+ if ((mbPtr->flags & ACTIVE) == 0) {
+ if (butPtr->state == STATE_DISABLED) {
+ drawinfo->state = kThemeStateUnavailableInactive;
+ } else {
+ drawinfo->state = kThemeStateInactive;
+ }
+ } else if (butPtr->state == STATE_DISABLED) {
+ drawinfo->state = kThemeStateUnavailable;
+ } else {
+ drawinfo->state = kThemeStateActive;
+ }
+
+ drawinfo->adornment = kThemeAdornmentNone;
+ if (butPtr->highlightWidth >= 3) {
+ if ((butPtr->flags & GOT_FOCUS)) {
+ drawinfo->adornment |= kThemeAdornmentFocus;
+ }
+ }
+ drawinfo->adornment |= kThemeAdornmentArrowDoubleArrow;
}
/*
- * Local Variables:
- * mode: objc
- * c-basic-offset: 4
- * fill-column: 79
- * coding: utf-8
- * End:
+ *----------------------------------------------------------------------
+ *
+ * TkMacOSXComputeMenuButtonDrawParams --
+ *
+ * This procedure computes the various parameters used
+ * when drawing a button
+ * These are determined by the various tk button parameters
+ *
+ * Results:
+ * 1 if control will be used, 0 otherwise.
+ *
+ * Side effects:
+ * Sets the button draw parameters
+ *
+ *----------------------------------------------------------------------
*/
+
+static int
+TkMacOSXComputeMenuButtonDrawParams(TkMenuButton * butPtr, DrawParams * dpPtr)
+{
+ dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
+ || (butPtr->bitmap != None));
+ dpPtr->border = butPtr->normalBorder;
+ if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
+ dpPtr->gc = butPtr->disabledGC;
+ } else if (butPtr->state == STATE_ACTIVE) {
+ dpPtr->gc = butPtr->activeTextGC;
+ dpPtr->border = butPtr->activeBorder;
+ } else {
+ dpPtr->gc = butPtr->normalTextGC;
+ }
+
+ return 1;
+}
+
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index 4978611..18af42f 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -178,9 +178,6 @@ MODULE_SCOPE CGFloat tkMacOSXZeroScreenHeight;
MODULE_SCOPE CGFloat tkMacOSXZeroScreenTop;
MODULE_SCOPE int tkMacOSXGCEnabled;
MODULE_SCOPE long tkMacOSXMacOSXVersion;
-#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
-MODULE_SCOPE int tkMacOSXUseCompatibilityMetrics;
-#endif
/*
* Prototypes for TkMacOSXRegion.c.