head	1.22;
access;
symbols
	core-8-4-19:1.17.2.3
	core-8-4-18:1.17.2.3
	core-8-4-17:1.17.2.3
	core-8-4-16:1.17.2.3
	core-8-4-15:1.17.2.3
	core-8-4-14:1.17.2.3
	core-8-4-13:1.17.2.3
	core-8-4-12:1.17.2.3
	core-8-4-11:1.17.2.3
	core-8-4-10:1.17.2.3
	core-8-4-9-branch:1.17.2.3.0.2
	core-8-4-9:1.17.2.3
	core-8-4-8:1.17.2.3
	core-8-4-7:1.17.2.2
	core-8-5-a1:1.21
	core-8-4-6:1.17.2.2
	core-8-4-5:1.17.2.2
	mistachkin-dev-branch:1.18.0.2
	core-8-4-4:1.17.2.1
	core-8-4-3:1.17.2.1
	core-8-4-branch:1.17.0.2
	core-8-4-2:1.17
	core-8-4-1:1.17
	core-8-3-5:1.10.2.1
	core-8-4-0:1.17
	macosx-8-4-merge-2002-08-31-trunk:1.17
	macosx-8-4-premerge-2002-08-31-branch:1.14.4.3
	macosx-8-4-premerge-2002-08-31-trunk:1.17
	macosx-8-4-merge-2002-08-30-branch:1.14.4.3
	macosx-8-4-merge-2002-08-30-trunk:1.17
	macosx-8-4-merge-2002-08-20-branch:1.14.4.2
	macosx-8-4-merge-2002-08-20-trunk:1.16
	core-8-4-b2:1.16
	core-8-4-b1:1.16
	macosx-premerge-6-9-02:1.14.4.1
	core-8-4-a4:1.15
	core-8-3-4:1.10.2.1
	macosx-8-4-branch:1.14.0.4
	macosx-8-4-branchpoint:1.14
	core-8-4-a3:1.14
	core-8-3-3:1.10.2.1
	dgp-privates-into-namespace:1.14.0.2
	tclpro-1-5-0:1.10
	core-8-4-win-speedup:1.13.0.2
	core-8-4-a2:1.13
	tclpro-1-4-1:1.10
	tclpro-1-4-0:1.10
	core-8-3-2:1.10
	ajuba-ajuba2-2-1-base:1.10
	ajuba-ajuba2-2-0:1.10
	core-8-4-a1:1.13
	core-8-3-1-branch:1.10.0.2
	core-8-3-1:1.10
	scriptics-sc-2-0-b5:1.9
	scriptics-sc-2-0-fixed:1.9
	scriptics-sc-2-0-b2:1.9
	scriptics-sc-2-0-b1:1.9
	core-8-3-0:1.9
	core-8-3-b2:1.7
	core-8-3-b1:1.7
	scriptics-sc-1-1:1.7
	scriptics-sc-1-1-b1:1.7
	core-8-2-3:1.7
	scriptics-sc-1-1-branch:1.7.0.8
	scriptics-sc-1-1-base:1.7
	scriptics-sc-1-0:1.7
	scriptics-sc-1-0-branch:1.7.0.6
	scriptics-sc-1-0-base:1.7
	core-8-2-2:1.7
	core-8-2-1:1.7
	scriptics-bc-1-0-b1:1.7
	core-8-2-1-branch:1.7.0.4
	scriptics-tclpro-1-3-0:1.7
	core-8-2-0:1.7
	core-8-2-b3-branch:1.7.0.2
	core-8-2-b3-base:1.7
	scriptics-tclpro-1-3-b4:1.6
	core-8-2-b2:1.6
	scriptics-tclpro-1-3-b3:1.6
	core-8-2-b1:1.6
	scriptics-tclpro-1-3-b2:1.5
	merge-to-mainline-5/21/99:1.5
	scriptics-tclpro-1-3-b2-branch:1.5.0.2
	core-8-1-1:1.5
	scriptics-tclpro-1-3-b1:1.5
	core-8-1-1-base:1.5
	core-8-1-0:1.5
	merge-to-mainline-4-29-99:1.5
	merge-to-mainline-4-23-99:1.5
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.4.0.2
	core-8-0-6-base:1.4
	core-8-0-5:1.3.2.1
	core-8-1-b3:1.1.4.2
	core-8-1-b2:1.1.4.2
	dev-8-1-stubs-branch:1.1.4.2.0.2
	dev-stubs-branch:1.3.0.4
	scriptics-tclpro-1-2:1.3
	scriptics-tclpro-1-2-b2:1.3
	core-8-1-merge-2/10/99:1.3
	core-8-0-5-branch:1.3.0.2
	core-8-0-5-base:1.3
	scriptics-tclpro-1-2-b1:1.3
	scriptics-tclpro-1-2-a1:1.3
	core-8-1-b1:1.1.4.2
	core-8-0-4:1.3
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.3;
locks; strict;
comment	@ * @;


1.22
date	2004.03.17.18.15.45;	author das;	state dead;
branches;
next	1.21;

1.21
date	2004.01.13.02.06.01;	author davygrvy;	state Exp;
branches;
next	1.20;

1.20
date	2003.12.21.23.50.13;	author davygrvy;	state Exp;
branches;
next	1.19;

1.19
date	2003.10.10.20.19.51;	author hobbs;	state Exp;
branches;
next	1.18;

1.18
date	2003.04.26.02.59.20;	author hobbs;	state Exp;
branches;
next	1.17;

1.17
date	2002.08.28.01.08.06;	author drh;	state Exp;
branches
	1.17.2.1;
next	1.16;

1.16
date	2002.06.17.10.54.29;	author drh;	state Exp;
branches;
next	1.15;

1.15
date	2001.11.23.02.05.37;	author das;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.22.01.49.38;	author ericm;	state Exp;
branches
	1.14.4.1;
next	1.13;

1.13
date	2000.05.17.21.17.21;	author ericm;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2000.05.13.00.39.08;	author ericm;	state Exp;
branches;
next	1.11;

1.11
date	2000.05.10.00.09.39;	author ericm;	state Exp;
branches;
next	1.10;

1.10
date	2000.04.17.02.16.36;	author jingham;	state Exp;
branches
	1.10.2.1;
next	1.9;

1.9
date	2000.02.10.08.51.43;	author jingham;	state Exp;
branches;
next	1.8;

1.8
date	2000.02.10.08.49.29;	author jingham;	state Exp;
branches;
next	1.7;

1.7
date	99.08.07.18.53.23;	author jingham;	state Exp;
branches;
next	1.6;

1.6
date	99.05.22.06.32.26;	author jingham;	state Exp;
branches;
next	1.5;

1.5
date	99.04.16.01.51.29;	author stanton;	state Exp;
branches;
next	1.4;

1.4
date	99.04.16.01.25.54;	author stanton;	state Exp;
branches;
next	1.3;

1.3
date	98.09.14.18.23.34;	author stanton;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	98.07.06.23.00.35;	author welch;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.09.57.00;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.25.37;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.18.02;	author stanton;	state Exp;
branches;
next	;

1.3.2.1
date	99.03.22.06.43.17;	author jingham;	state Exp;
branches;
next	;

1.10.2.1
date	2001.04.04.21.39.48;	author hobbs;	state Exp;
branches;
next	;

1.13.2.1
date	2002.04.02.20.57.54;	author hobbs;	state Exp;
branches;
next	;

1.14.4.1
date	2002.02.05.02.25.16;	author wolfsuit;	state Exp;
branches;
next	1.14.4.2;

1.14.4.2
date	2002.08.20.20.27.10;	author das;	state Exp;
branches;
next	1.14.4.3;

1.14.4.3
date	2002.08.30.15.36.13;	author das;	state Exp;
branches;
next	;

1.17.2.1
date	2003.04.26.02.53.47;	author hobbs;	state Exp;
branches;
next	1.17.2.2;

1.17.2.2
date	2003.10.10.20.20.47;	author hobbs;	state Exp;
branches;
next	1.17.2.3;

1.17.2.3
date	2004.10.27.00.37.38;	author davygrvy;	state Exp;
branches;
next	;


desc
@@


1.22
log
@Removed support for Mac OS Classic platform [Patch 918139]
@
text
@/* 
 * tkMacButton.c --
 *
 *	This file implements the Macintosh specific portion of the
 *	button widgets.
 *
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id: tkMacButton.c,v 1.21 2004/01/13 02:06:01 davygrvy Exp $
 */

#include "tkButton.h"
#include "tkMacInt.h"
#include <Controls.h>
#include <ControlDefinitions.h>
#include <LowMem.h>
#include <Appearance.h>


#include <ToolUtils.h>

/*
 * Some defines used to control what type of control is drawn.
 */

#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

/*
 * The following structures are used to draw our controls.  Rather than
 * having many Mac controls we just use one control of each type and
 * reuse them for all Tk widgets.  When the windowRef variable is NULL
 * it means none of the data structures have been allocated.
 */

static WindowRef windowRef = NULL;
static CWindowRecord windowRecord;
static ControlRef buttonHandle;
static ControlRef checkHandle;
static ControlRef radioHandle;
static ControlRef smallBevelHandle;
static ControlRef smallStickyBevelHandle;
static ControlRef medBevelHandle;
static ControlRef medStickyBevelHandle;
static ControlRef largeBevelHandle;
static ControlRef largeStickyBevelHandle;

/*
 * These are used to store the image content for
 * beveled buttons - i.e. buttons with images.
 */
 
static ControlButtonContentInfo bevelButtonContent;
static OpenCPicParams picParams;

static CCTabHandle buttonTabHandle;
static CCTabHandle checkTabHandle;
static CCTabHandle radioTabHandle;
static PixMapHandle oldPixPtr;

/*
 * These functions are used when Appearance is present.
 * By embedding all our controls in a userPane control,
 * we can color the background of the text in radiobuttons
 * and checkbuttons.  Thanks to Peter Gontier of Apple DTS
 * for help on this one.
 */

static ControlRef userPaneHandle;
static RGBColor gUserPaneBackground = { ~0, ~0, ~0};
static pascal OSErr SetUserPaneDrawProc(ControlRef control,
	ControlUserPaneDrawProcPtr upp);
static pascal OSErr SetUserPaneSetUpSpecialBackgroundProc(ControlRef control,
	ControlUserPaneBackgroundProcPtr upp);
static pascal void UserPaneDraw(ControlRef control, ControlPartCode cpc);
static pascal void UserPaneBackgroundProc(ControlHandle,
	ControlBackgroundPtr info);

/*
 * Forward declarations for procedures defined later in this file:
 */

static void		ButtonEventProc _ANSI_ARGS_((
			    ClientData clientData, XEvent *eventPtr));
static int	UpdateControlColors _ANSI_ARGS_((TkButton *butPtr,
	ControlRef controlHandle, CCTabHandle ccTabHandle,
	RGBColor *saveColorPtr));
static void	DrawBufferedControl _ANSI_ARGS_((TkButton *butPtr,
	GWorldPtr destPort, GC gc, Pixmap pixmap));
static void	InitSampleControls();
static void	SetupBevelButton _ANSI_ARGS_((TkButton *butPtr,
	ControlRef controlHandle, 
	GWorldPtr destPort, GC gc, Pixmap pixmap));
static void	ChangeBackgroundWindowColor _ANSI_ARGS_((
    WindowRef macintoshWindow, RGBColor rgbColor,
    RGBColor *oldColor));
static void	ButtonExitProc _ANSI_ARGS_((ClientData clientData));

/*
 * The class procedure table for the button widgets.
 */

Tk_ClassProcs tkpButtonProcs = { 
    sizeof(Tk_ClassProcs),	/* size */
    TkButtonWorldChanged,	/* worldChangedProc */
};

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateButton --
 *
 *	Allocate a new TkButton structure.
 *
 * Results:
 *	Returns a newly allocated TkButton structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkButton *
TkpCreateButton(
    Tk_Window tkwin)
{
    TkButton *buttonPtr;
    buttonPtr = (TkButton *) ckalloc(sizeof(TkButton));
    Tk_CreateEventHandler(tkwin, ActivateMask,
	    ButtonEventProc, (ClientData) buttonPtr);
    return buttonPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayButton --
 *
 *	This procedure is invoked to display a button widget.  It is
 *	normally invoked as an idle handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands are output to X to display the button in its
 *	current mode.  The REDRAW_PENDING flag is cleared.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayButton(
    ClientData clientData)	/* Information about widget. */
{
    TkButton *butPtr = (TkButton *) clientData;
    Pixmap pixmap;
    GC gc;
    Tk_3DBorder border;
    int x = 0;			/* Initialization only needed to stop
				 * compiler warning. */
    int y, relief;
    register Tk_Window tkwin = butPtr->tkwin;
    int width, height, fullWidth, fullHeight;
    int textXOffset, textYOffset;
    int haveImage = 0, haveText = 0;
    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. */
    int hasImageOrBitmap;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    int drawType, borderWidth;
    int imageWidth, imageHeight;
    int imageXOffset = 0, imageYOffset = 0; /* image information that will
					     * be used to restrict disabled
					     * pixmap as well */

    GetGWorld(&saveWorld, &saveDevice);

    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    /*
     * In order to avoid screen flashes, this procedure redraws
     * the button in a pixmap, then copies the pixmap to the
     * screen in a single operation.  This means that there's no
     * point in time where the on-sreen image has been cleared.
     */

    pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));

    hasImageOrBitmap = ((butPtr->image != NULL) || (butPtr->bitmap != None));
    offset = (butPtr->type == TYPE_BUTTON) && hasImageOrBitmap;

    border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
	gc = butPtr->disabledGC;
    } else if ((butPtr->type == TYPE_BUTTON)
	    && (butPtr->state == STATE_ACTIVE)) {
	gc = butPtr->activeTextGC;
	border = butPtr->activeBorder;
    } else {
	gc = butPtr->normalTextGC;
    }
    
    if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
	    && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
	border = butPtr->selectBorder;
    }

    /*
     * 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.
     */

    relief = butPtr->relief;

    if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) { 
	if (!TkMacHaveAppearance() || !hasImageOrBitmap) {
	    if (butPtr->flags & SELECTED) {
		relief = TK_RELIEF_SUNKEN;
	    } else if (butPtr->overRelief != relief) {
		relief = butPtr->offRelief;
	    }
	}
    }

    /*
     * See the comment in UpdateControlColors as to why we use the 
     * highlightbackground for the border of Macintosh buttons.
     */
     
    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);
    }
   
    if (butPtr->type == TYPE_LABEL) {
	drawType = DRAW_LABEL;
    } else if (butPtr->type == TYPE_BUTTON) {
	if (!hasImageOrBitmap) {
	    drawType = DRAW_CONTROL;
	} else if (butPtr->image != None) {
	    drawType = DRAW_BEVEL;
	} else {
	    /*
	     * TO DO - The current way the we draw bitmaps (XCopyPlane)
	     * uses CopyDeepMask in this one case.  The Picture recording 
	     * does not record this call, and so we can't use the
	     * Appearance bevel button here.  The only case that would
	     * exercise this is if you use a bitmap, with
	     * -data & -mask specified.	 We should probably draw the 
	     * appearance button and overprint the image in this case.
	     * This just punts and draws the old-style, ugly, button.
	     */
	     
	    if (gc->clip_mask == 0) {
		drawType = DRAW_BEVEL;
	    } else {
		TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
		if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
			(clipPtr->value.pixmap != butPtr->bitmap)) {
		    drawType = DRAW_CUSTOM;
		} else {
		    drawType = DRAW_BEVEL;
		}
	    }
	}
    } else {
	if (butPtr->indicatorOn) {
	    drawType = DRAW_CONTROL;
	} else if (hasImageOrBitmap) {
	    if (gc->clip_mask == 0) {
		drawType = DRAW_BEVEL;
	    } else {
		TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
		if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
			(clipPtr->value.pixmap != butPtr->bitmap)) {
		    drawType = DRAW_CUSTOM;
		} else {
		    drawType = DRAW_BEVEL;
		}
	    }
	} else {
	    drawType = DRAW_CUSTOM;
	}
    }

    /*
     * Draw the native portion of the buttons.	Start by creating the control
     * if it doesn't already exist.  Then configure the Macintosh control from
     * the Tk info.  Finally, we call Draw1Control to draw to the screen.
     */

    if ((drawType == DRAW_CONTROL) || 
	    ((drawType == DRAW_BEVEL) && TkMacHaveAppearance())) {
	borderWidth = 0;
	
	/*
	 * This part uses Macintosh rather than Tk calls to draw
	 * to the screen.  Make sure the ports etc. are set correctly.
	 */
	
	destPort = TkMacGetDrawablePort(pixmap);
	SetGWorld(destPort, NULL);
	DrawBufferedControl(butPtr, destPort, gc, pixmap);
    }

    if ((drawType == DRAW_CUSTOM) || (drawType == DRAW_LABEL)) {
	borderWidth = butPtr->borderWidth;
    }

    /*
     * Display image or bitmap or text for button.  This has
     * already been done under Appearance with the Bevel
     * button types.
     */

    if ((drawType == DRAW_BEVEL) && TkMacHaveAppearance()) {
	/* Empty Body */
    } else {
	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;

	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,
		    butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y);
	    
	    x += butPtr->indicatorSpace;
	    
	    x += offset;
	    y += offset;
	    if (relief == TK_RELIEF_RAISED) {
		x -= offset;
		y -= offset;
	    } else if (relief == TK_RELIEF_SUNKEN) {
		x += offset;
		y += 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 {
		    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,
			butPtr->indicatorSpace + width, height, &x, &y);
		x += butPtr->indicatorSpace;
		
		x += offset;
		y += offset;
		if (relief == TK_RELIEF_RAISED) {
		    x -= offset;
		    y -= offset;
		} else if (relief == TK_RELIEF_SUNKEN) {
		    x += offset;
		    y += 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 {
			Tk_RedrawImage(butPtr->image, 0, 0, width, height,
				pixmap, imageXOffset, imageYOffset);
		    }
		} 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->indicatorSpace + butPtr->textWidth,
			butPtr->textHeight, &x, &y);
		
		x += butPtr->indicatorSpace;
		
		Tk_DrawTextLayout(butPtr->display, pixmap, gc,
			butPtr->textLayout, x, y, 0, -1);
		y += butPtr->textHeight/2;
	    }
	}
    }

    /*
     * 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);
	}
    }

    /*
     * Draw the border and traversal highlight last.  This way, if the
     * button's contents overflow they'll be covered up by the border.
     */

    if (relief != TK_RELIEF_FLAT) {
	int inset = butPtr->highlightWidth;
	Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset,
		Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
		butPtr->borderWidth, relief);
    }

    /*
     * Copy the information from the off-screen pixmap onto the screen,
     * then delete the pixmap.
     */

    XCopyArea(butPtr->display, pixmap, Tk_WindowId(tkwin),
	    butPtr->copyGC, 0, 0, (unsigned) Tk_Width(tkwin),
	    (unsigned) Tk_Height(tkwin), 0, 0);
    Tk_FreePixmap(butPtr->display, pixmap);

    SetGWorld(saveWorld, saveDevice);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeButtonGeometry --
 *
 *	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.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeButtonGeometry(
    TkButton *butPtr)	/* Button whose geometry may have changed. */
{
    int width, height, avgWidth, haveImage = 0, haveText = 0;
    int txtWidth, txtHeight;
    Tk_FontMetrics fm;

    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;

    /*
     * First figure out the size of the contents of the button.
     */
     
    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;
    }

    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;
	}

	if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
	    butPtr->indicatorSpace = height;
	    if (butPtr->type == TYPE_CHECK_BUTTON) {
		butPtr->indicatorDiameter = (65*height)/100;
	    } else {
		butPtr->indicatorDiameter = (75*height)/100;
	    }
	}

	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;
	    }
	    if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
		butPtr->indicatorSpace = height;
		if (butPtr->type == TYPE_CHECK_BUTTON) {
		    butPtr->indicatorDiameter = (65*height)/100;
		} else {
		    butPtr->indicatorDiameter = (75*height)/100;
		}
	    }
	} else {
	    width = txtWidth;
	    height = txtHeight;
	    if (butPtr->width > 0) {
		width = butPtr->width * avgWidth;
	    }
	    if (butPtr->height > 0) {
		height = butPtr->height * fm.linespace;
	    }
	    if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
		butPtr->indicatorDiameter = fm.linespace;
		if (butPtr->type == TYPE_CHECK_BUTTON) {
		    butPtr->indicatorDiameter =
			(80*butPtr->indicatorDiameter)/100;
		}
		butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
	    }
	}
    }

    /*
     * Now figure out the size of the border decorations for the button.
     */
     
    if (butPtr->highlightWidth < 0) {
	butPtr->highlightWidth = 0;
    }
    
    /*
     * The width and height calculation for Appearance buttons with images & 
     * non-Appearance buttons with images is different.	 In the latter case, 
     * we add the borderwidth to the inset, since we are going to stamp a
     * 3-D border over the image.  In the former, we add it to the height,
     * directly, since Appearance will draw the border as part of our control.
     *
     * When issuing the geometry request, add extra space for the indicator,
     * if any, and for the border and padding, plus if this is an image two 
     * extra pixels so the display can be offset by 1 pixel in either
     * direction for the raised or lowered effect.
     *
     * The highlight width corresponds to the default ring on the Macintosh.
     * As such, the highlight width is only added if the button is the default
     * button.	The actual width of the default ring is one less than the
     * highlight width as there is also one pixel of spacing.
     * Appearance buttons with images do not have a highlight ring, because the 
     * Bevel button type does not support one.
     */

    if ((butPtr->image == None) && (butPtr->bitmap == None)) {
	width += 2*butPtr->padX;
	height += 2*butPtr->padY;
    }
    
    if ((butPtr->type == TYPE_BUTTON)) {
	if ((butPtr->image == None) && (butPtr->bitmap == None)) {
	    butPtr->inset = 0;
	    if (butPtr->defaultState != STATE_DISABLED) {
		butPtr->inset += butPtr->highlightWidth;
	    }
	} else if (TkMacHaveAppearance()) {
	    butPtr->inset = 0;
	    width += (2 * butPtr->borderWidth + 4);
	    height += (2 * butPtr->borderWidth + 4);
	} else {
	    butPtr->inset = butPtr->borderWidth;
	    width += 2;
	    height += 2;
	    if (butPtr->defaultState != STATE_DISABLED) {
		butPtr->inset += butPtr->highlightWidth;
	    }
	}
    } else if ((butPtr->type != TYPE_LABEL)) {
	if (butPtr->indicatorOn) {
	    butPtr->inset = 0;
	} else {
	    /*
	     * Under Appearance, the Checkbutton or radiobutton with an image
	     * is represented by a BevelButton with the Sticky defProc...  
	     * So we must set its height in the same way as the Button 
	     * with an image or bitmap.
	     */
	    if (((butPtr->image != None) || (butPtr->bitmap != None))
		    && TkMacHaveAppearance()) {
		int border;
		butPtr->inset = 0;
		if ( butPtr->borderWidth <= 2 ) {
		    border = 6;
		}  else {
		    border = 2 * butPtr->borderWidth + 2;
		}	       
		width += border;
		height += border;
	    } else {
		butPtr->inset = butPtr->borderWidth;
	    }	
	}	
    } else {
	butPtr->inset = butPtr->borderWidth;
    }



    Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace
	    + 2*butPtr->inset), (int) (height + 2*butPtr->inset));
    Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyButton --
 *
 *	Free data structures associated with the button control.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Restores the default control state.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyButton(
    TkButton *butPtr)
{
    /* Do nothing. */
}

/*
 *--------------------------------------------------------------
 *
 * DrawBufferedControl --
 *
 *	This function uses a dummy Macintosh window to allow
 *	drawing Mac controls to any GWorld (including off-screen
 *	bitmaps).  In addition, this code may apply custom
 *	colors passed in the TkButton.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Control is to the GWorld.  Static state created on
 *	first invocation of this routine.
 *
 *--------------------------------------------------------------
 */

static void
DrawBufferedControl(
    TkButton *butPtr,		/* Tk button. */
    GWorldPtr destPort,		/* Off screen GWorld. */
    GC gc,			/* The GC we are drawing into - needed for
				 * the bevel button */
    Pixmap pixmap		/* The pixmap we are drawing into - needed
				   for the bevel button */
    )		
{
    ControlRef controlHandle;
    CCTabHandle ccTabHandle;
    int windowColorChanged = false;
    RGBColor saveBackColor;
    int isBevel = 0;
   
    if (windowRef == NULL) {
	InitSampleControls();
    }
    
    /*
     * Now swap in the passed in GWorld for the portBits of our fake
     * window.	We also adjust various fields in the WindowRecord to make
     * the system think this is a normal window.
     * Note, we can use DrawControlInCurrentPort under Appearance, so we don't
     * need to swap pixmaps.
     */
    
    if (!TkMacHaveAppearance()) {
	((CWindowPeek) windowRef)->port.portPixMap = destPort->portPixMap;
    }
    
    ((CWindowPeek) windowRef)->port.portRect = destPort->portRect;
    RectRgn(((CWindowPeek) windowRef)->port.visRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->strucRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->updateRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->contRgn, &destPort->portRect);
    PortChanged(windowRef);
    
    /*
     * Set up control in hidden window to match what we need
     * to draw in the buffered window.	
     */
     
    isBevel = 0;   
    switch (butPtr->type) {
	case TYPE_BUTTON:
	    if (TkMacHaveAppearance()) {
		if ((butPtr->image == None) && (butPtr->bitmap == None)) {
		    controlHandle = buttonHandle;
		    ccTabHandle = buttonTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medBevelHandle;
		    } else {
			controlHandle = largeBevelHandle;
		    }
		    ccTabHandle = buttonTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = buttonHandle;
		ccTabHandle = buttonTabHandle;
	    }
	    break;
	case TYPE_RADIO_BUTTON:
	    if (TkMacHaveAppearance()) {
		if (((butPtr->image == None) && (butPtr->bitmap == None))
			|| (butPtr->indicatorOn)) {
		    controlHandle = radioHandle;
		    ccTabHandle = radioTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallStickyBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medStickyBevelHandle;
		    } else {
			controlHandle = largeStickyBevelHandle;
		    }
		    ccTabHandle = radioTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = radioHandle;
		ccTabHandle = radioTabHandle;
	    }	       
	    break;
	case TYPE_CHECK_BUTTON:
	    if (TkMacHaveAppearance()) {
		if (((butPtr->image == None) && (butPtr->bitmap == None))
			|| (butPtr->indicatorOn)) {
		    controlHandle = checkHandle;
		    ccTabHandle = checkTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallStickyBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medStickyBevelHandle;
		    } else {
			controlHandle = largeStickyBevelHandle;
		    }
		    ccTabHandle = checkTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = checkHandle;
		ccTabHandle = checkTabHandle;
	    }	       
	    break;
    }
    
    (**controlHandle).contrlRect.left = butPtr->inset;
    (**controlHandle).contrlRect.top = butPtr->inset;
    (**controlHandle).contrlRect.right = Tk_Width(butPtr->tkwin) 
	- butPtr->inset;
    (**controlHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin) 
	- butPtr->inset;
	    
    /*
     * Setting the control visibility by hand does not 
     * seem to work under Appearance. 
     */
     
    if (TkMacHaveAppearance()) {
	SetControlVisibility(controlHandle, true, false);      
	(**userPaneHandle).contrlRect.left = 0;
	(**userPaneHandle).contrlRect.top = 0;
	(**userPaneHandle).contrlRect.right = Tk_Width(butPtr->tkwin);
	(**userPaneHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin);
    } else {	  
	(**controlHandle).contrlVis = 255;
    }	  
    
		
    
    if (butPtr->flags & SELECTED) {
	(**controlHandle).contrlValue = 1;
    } else {
	(**controlHandle).contrlValue = 0;
    }
    
    if (!tkMacAppInFront || butPtr->state == STATE_DISABLED) {
	(**controlHandle).contrlHilite = kControlInactivePart;
    } else if (butPtr->state == STATE_ACTIVE) {
	if (isBevel) {
	    (**controlHandle).contrlHilite = kControlButtonPart;
	} else {
	    switch (butPtr->type) {
		case TYPE_BUTTON:
		    (**controlHandle).contrlHilite = kControlButtonPart;
		    break;
		case TYPE_RADIO_BUTTON:
		    (**controlHandle).contrlHilite = kControlRadioButtonPart;
		    break;
		case TYPE_CHECK_BUTTON:
		    (**controlHandle).contrlHilite = kControlCheckBoxPart;
		    break;
	    }
	}
    } else {
	(**controlHandle).contrlHilite = kControlNoPart;
    }
    /*
     * Before we draw the control we must add the hidden window back to the
     * main window list.  Otherwise, radiobuttons and checkbuttons will draw
     * incorrectly.  I don't really know why - but clearly the control draw
     * proc needs to have the controls window in the window list.  This is not
     * necessary under Appearance, and will have to go when we Carbonize Tk...
     */
    if (!TkMacHaveAppearance()) {
        ((CWindowPeek) windowRef)->nextWindow = (CWindowPeek) LMGetWindowList();
        LMSetWindowList(windowRef);
    }

    /*
     * Now we can set the port to our doctered up window.  We next need
     * to muck with the colors for the port & window to draw the control
     * with the proper Tk colors.  If we need to we also draw a default
     * ring for buttons.
     * Under Appearance, we draw the control directly into destPort, and
     * just set the default control data.
     */

    if (TkMacHaveAppearance()) {
	SetPort((GrafPort *) destPort);
    } else {
	SetPort(windowRef);
    }

    windowColorChanged = UpdateControlColors(butPtr, controlHandle, 
	    ccTabHandle, &saveBackColor);
	
    if ((butPtr->type == TYPE_BUTTON) && TkMacHaveAppearance()) {
	Boolean isDefault;
	
	if (butPtr->defaultState == STATE_ACTIVE) {
	    isDefault = true;
	} else {
	    isDefault = false;
	}
	SetControlData(controlHandle, kControlNoPart, 
		kControlPushButtonDefaultTag,
		sizeof(isDefault), (Ptr) &isDefault);			
    }

    if (TkMacHaveAppearance()) {
	DrawControlInCurrentPort(userPaneHandle);
    } else {
	Draw1Control(controlHandle);
    }

    if (!TkMacHaveAppearance() &&
	    (butPtr->type == TYPE_BUTTON) && 
	    (butPtr->defaultState == STATE_ACTIVE)) {
	Rect box = (**controlHandle).contrlRect;
	RGBColor rgbColor;

	TkSetMacColor(butPtr->highlightColorPtr->pixel, &rgbColor);
	RGBForeColor(&rgbColor);
	PenSize(butPtr->highlightWidth - 1, butPtr->highlightWidth - 1);
	InsetRect(&box, -butPtr->highlightWidth, -butPtr->highlightWidth);
	FrameRoundRect(&box, 16, 16);
    }
    
    if (windowColorChanged) {
	RGBColor dummyColor;
	ChangeBackgroundWindowColor(windowRef, saveBackColor, &dummyColor);
    }
    
    /*
     * Clean up: remove the hidden window from the main window list, and
     * hide the control we drew.  
     */

    if (TkMacHaveAppearance()) {
	SetControlVisibility(controlHandle, false, false);
	if (isBevel) {
	    KillPicture(bevelButtonContent.u.picture);
	}     
    } else {	  
	(**controlHandle).contrlVis = 0;
    }	  
    if (!TkMacHaveAppearance()) {    
        LMSetWindowList((WindowRef) ((CWindowPeek) windowRef)->nextWindow);
    }
}

/*
 *--------------------------------------------------------------
 *
 * InitSampleControls --
 *
 *	This function initializes a dummy Macintosh window and
 *	sample controls to allow drawing Mac controls to any GWorld 
 *	(including off-screen bitmaps).	 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Controls & a window are created.
 *
 *--------------------------------------------------------------
 */

static void
InitSampleControls()
{
    Rect geometry = {0, 0, 10, 10};
    CWindowPeek windowList;
    GWorldPtr frontWin = NULL;
    TkMacWindowList *winListPtr;

    /*
     * Create a dummy window that we can draw to.  We will
     * actually replace this window's bitmap with the one
     * we want to draw to at a later time.  This window and
     * the data structures attached to it are only deallocated
     * on exit of the application.
     */

    /* 
     * This is a bit of a hack...  The problem is that under appearance,
     * taking a window out of the window list causes instability, so we can't 
     * do that.  OTOH, we need to make sure that this window is NEVER the front
     * window, or we may inadvertently send keystrokes to it...
     * So we put it BEHIND ".", and then we won't ever be able to destroy
     * ALL the windows that are above it.
     */
      
    for (winListPtr = tkMacWindowListPtr; winListPtr != NULL; 
            winListPtr = winListPtr->nextPtr) {
        frontWin = ((MacDrawable *) tkMacWindowListPtr->winPtr->privatePtr)->portPtr;
        if (strcmp(tkMacWindowListPtr->winPtr->pathName, ".") == 0) {
            break;
        }
    }
    
    windowRef = NewCWindow(NULL, &geometry, "\pempty", false, 
	    zoomDocProc, (WindowRef) frontWin, true, 0);
    if (windowRef == NULL) {
	Tcl_Panic("Can't allocate buffer window.");
    }
	
    /*
     * Now add the three standard controls to hidden window.  We
     * only create one of each and reuse them for every widget in
     * Tk.
     * Under Appearance, we have to embed the controls in a UserPane
     * control, so that we can color the background text in 
     * radiobuttons and checkbuttons.
     */
	
    SetPort(windowRef);
	
    if (TkMacHaveAppearance()) {
	    
	OSErr err;
	ControlRef dontCare;
	    
 	/* 
 	 * Adding UserPaneBackgroundProcs to the root control does
	 * not seem to work, so we have to add another UserPane to 
	 * the root control.
	 */
	     
	err = CreateRootControl(windowRef, &dontCare);
	if (err != noErr) {
	    Tcl_Panic("Can't create root control in DrawBufferedControl");
	}
	    
	userPaneHandle = NewControl(windowRef, &geometry, "\p",
		true, kControlSupportsEmbedding|kControlHasSpecialBackground, 
		0, 1, kControlUserPaneProc, (SInt32) 0);
	SetUserPaneSetUpSpecialBackgroundProc(userPaneHandle,
		UserPaneBackgroundProc);
	SetUserPaneDrawProc(userPaneHandle, UserPaneDraw);

	buttonHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlPushButtonProc, (SInt32) 0);
	EmbedControl(buttonHandle, userPaneHandle);
	checkHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 0);
	EmbedControl(checkHandle, userPaneHandle);
	radioHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlRadioButtonProc, (SInt32) 0);
	EmbedControl(radioHandle, userPaneHandle);
	smallBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonSmallBevelProc, (SInt32) 0);
	EmbedControl(smallBevelHandle, userPaneHandle);
	medBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonNormalBevelProc, (SInt32) 0);
	EmbedControl(medBevelHandle, userPaneHandle);
	largeBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonLargeBevelProc, (SInt32) 0);
	EmbedControl(largeBevelHandle, userPaneHandle);
	bevelButtonContent.contentType = kControlContentPictHandle;
	smallStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonSmallBevelProc, (SInt32) 0);
	EmbedControl(smallStickyBevelHandle, userPaneHandle);
	medStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonNormalBevelProc, (SInt32) 0);
	EmbedControl(medStickyBevelHandle, userPaneHandle);
	largeStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonLargeBevelProc, (SInt32) 0);
	EmbedControl(largeStickyBevelHandle, userPaneHandle);
    
	picParams.version = -2;
	picParams.hRes = 0x00480000;
	picParams.vRes = 0x00480000;
	picParams.srcRect.top = 0;
	picParams.srcRect.left = 0;
    
	((CWindowPeek) windowRef)->visible = true;
    } else {
	buttonHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, pushButProc, (SInt32) 0);
	checkHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, checkBoxProc, (SInt32) 0);
	radioHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, radioButProc, (SInt32) 0);
	((CWindowPeek) windowRef)->visible = true;

	buttonTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	checkTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	radioTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
    }

    /*
     * Remove our window from the window list.	This way our
     * applications and others will not be confused that this
     * window exists - but no one knows about it.
     * I actually don't see the point of doing this, and it causes Floating
     * Window support to crash under Appearance, so I just leave it out.
     * Note that we have to do without this under Carbon, since you can't
     * go poking at the window list...
     */

    if (!TkMacHaveAppearance()) {
        windowList = (CWindowPeek) LMGetWindowList();
        if (windowList == (CWindowPeek) windowRef) {
	    LMSetWindowList((WindowRef) windowList->nextWindow);
        } else {
	    while ((windowList != NULL) 
		    && (windowList->nextWindow != (CWindowPeek) windowRef)) {
	        windowList = windowList->nextWindow;
	    }
	    if (windowList != NULL) {
	        windowList->nextWindow = windowList->nextWindow->nextWindow;
	    }
        }
        ((CWindowPeek) windowRef)->nextWindow = NULL;
    }

    /* 
     * Create an exit handler to clean up this mess if we our
     * unloaded etc.  We need to remember the windows portPixMap
     * so it isn't leaked.
     *
     * TODO: The ButtonExitProc doesn't currently work and the
     * code it includes will crash the Mac on exit from Tk.
	 
     oldPixPtr = ((CWindowPeek) windowRef)->port.portPixMap;
     TkCreateExitHandler(ButtonExitProc, (ClientData) NULL);
    */

}

/*
 *--------------------------------------------------------------
 *
 * SetupBevelButton --
 *
 *	Sets up the Bevel Button with image by copying the
 *	source image onto the PicHandle for the button.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The image or bitmap for the button is copied over to a picture.
 *
 *--------------------------------------------------------------
 */
void
SetupBevelButton(
    TkButton *butPtr,		/* Tk button. */
    ControlRef controlHandle,	 /* The control to set this picture to */
    GWorldPtr destPort,		/* Off screen GWorld. */
    GC gc,			/* The GC we are drawing into - needed for
				 * the bevel button */
    Pixmap pixmap		/* The pixmap we are drawing into - needed
				   for the bevel button */
    )
{
    int height, width;
    ControlButtonGraphicAlignment theAlignment;
    
    SetPort((GrafPtr) destPort);

    if (butPtr->image != None) {
	Tk_SizeOfImage(butPtr->image, 
		&width, &height);
    } else {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, 
		&width, &height);
    }
	    
    if ((butPtr->width > 0) && (butPtr->width < width)) {
	width = butPtr->width;
    }
    if ((butPtr->height > 0) && (butPtr->height < height)) {
	height = butPtr->height;
    }
    
    picParams.srcRect.right = width;
    picParams.srcRect.bottom = height;
    
    bevelButtonContent.u.picture = OpenCPicture(&picParams);
    
    /*
     * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
     * which does not get recorded in the picture.  So the bitmap code
     * will fail in that case.
     */
     
    if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
	Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
		pixmap, 0, 0);
    } else if (butPtr->image != NULL) {
	Tk_RedrawImage(butPtr->image, 0, 0, width, 
		height, pixmap, 0, 0);
    } else {			
	XSetClipOrigin(butPtr->display, gc, 0, 0);
	XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
		(unsigned int) width, (unsigned int) height, 0, 0, 1);
    }
    
    ClosePicture();
    
    SetControlData(controlHandle, kControlButtonPart,
	    kControlBevelButtonContentTag,
	    sizeof(ControlButtonContentInfo),
	    (char *) &bevelButtonContent);
	    
    if (butPtr->anchor == TK_ANCHOR_N) {
	theAlignment = kControlBevelButtonAlignTop;
    } else if (butPtr->anchor == TK_ANCHOR_NE) { 
	theAlignment = kControlBevelButtonAlignTopRight;
    } else if (butPtr->anchor == TK_ANCHOR_E) { 
	theAlignment = kControlBevelButtonAlignRight;
    } else if (butPtr->anchor == TK_ANCHOR_SE) {
	theAlignment = kControlBevelButtonAlignBottomRight;
    } else if (butPtr->anchor == TK_ANCHOR_S) {
	theAlignment = kControlBevelButtonAlignBottom;
    } else if (butPtr->anchor == TK_ANCHOR_SW) {
	theAlignment = kControlBevelButtonAlignBottomLeft;
    } else if (butPtr->anchor == TK_ANCHOR_W) {
	theAlignment = kControlBevelButtonAlignLeft;
    } else if (butPtr->anchor == TK_ANCHOR_NW) {
	theAlignment = kControlBevelButtonAlignTopLeft;
    } else if (butPtr->anchor == TK_ANCHOR_CENTER) {
	theAlignment = kControlBevelButtonAlignCenter;
    }

    SetControlData(controlHandle, kControlButtonPart,
	    kControlBevelButtonGraphicAlignTag,
	    sizeof(ControlButtonGraphicAlignment),
	    (char *) &theAlignment);

}

/*
 *--------------------------------------------------------------
 *
 * SetUserPaneDrawProc --
 *
 *	Utility function to add a UserPaneDrawProc
 *	to a userPane control.	From MoreControls code
 *	from Apple DTS.
 *
 * Results:
 *	MacOS system error.
 *
 * Side effects:
 *	The user pane gets a new UserPaneDrawProc.
 *
 *--------------------------------------------------------------
 */
pascal OSErr SetUserPaneDrawProc (
    ControlRef control,
    ControlUserPaneDrawProcPtr upp)
{
    ControlUserPaneDrawUPP myControlUserPaneDrawUPP;
    myControlUserPaneDrawUPP = NewControlUserPaneDrawProc(upp);	
    return SetControlData (control, 
	    kControlNoPart, kControlUserPaneDrawProcTag, 
	    sizeof(myControlUserPaneDrawUPP), 
	    (Ptr) &myControlUserPaneDrawUPP);
}

/*
 *--------------------------------------------------------------
 *
 * SetUserPaneSetUpSpecialBackgroundProc --
 *
 *	Utility function to add a UserPaneBackgroundProc
 *	to a userPane control
 *
 * Results:
 *	MacOS system error.
 *
 * Side effects:
 *	The user pane gets a new UserPaneBackgroundProc.
 *
 *--------------------------------------------------------------
 */
pascal OSErr
SetUserPaneSetUpSpecialBackgroundProc(
    ControlRef control, 
    ControlUserPaneBackgroundProcPtr upp)
{
    ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP;
    myControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundProc(upp);
    return SetControlData (control, kControlNoPart, 
	    kControlUserPaneBackgroundProcTag, 
	    sizeof(myControlUserPaneBackgroundUPP), 
	    (Ptr) &myControlUserPaneBackgroundUPP);
}

/*
 *--------------------------------------------------------------
 *
 * UserPaneDraw --
 *
 *	This function draws the background of the user pane that will 
 *	lie under checkboxes and radiobuttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The user pane gets updated to the current color.
 *
 *--------------------------------------------------------------
 */
pascal void
UserPaneDraw(
    ControlRef control,
    ControlPartCode cpc)
{
    Rect contrlRect = (**control).contrlRect;
    RGBBackColor (&gUserPaneBackground);
    EraseRect (&contrlRect);
}

/*
 *--------------------------------------------------------------
 *
 * UserPaneBackgroundProc --
 *
 *	This function sets up the background of the user pane that will 
 *	lie under checkboxes and radiobuttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The user pane background gets set to the current color.
 *
 *--------------------------------------------------------------
 */

pascal void
UserPaneBackgroundProc(
    ControlHandle,
    ControlBackgroundPtr info)
{
    if (info->colorDevice) {
	RGBBackColor (&gUserPaneBackground);
    }
}

/*
 *--------------------------------------------------------------
 *
 * UpdateControlColors --
 *
 *	This function will review the colors used to display
 *	a Macintosh button.  If any non-standard colors are
 *	used we create a custom palette for the button, populate
 *	with the colors for the button and install the palette.
 *
 *	Under Appearance, we just set the pointer that will be
 *	used by the UserPaneDrawProc.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The Macintosh control may get a custom palette installed.
 *
 *--------------------------------------------------------------
 */

static int
UpdateControlColors(
    TkButton *butPtr,
    ControlRef controlHandle,
    CCTabHandle ccTabHandle,
    RGBColor *saveColorPtr)
{
    XColor *xcolor;
    
    /*
     * Under Appearance we cannot change the background of the
     * button itself.  However, the color we are setting is the color
     *	of the containing userPane.  This will be the color that peeks 
     * around the rounded corners of the button.  
     * We make this the highlightbackground rather than the background,
     * because if you color the background of a frame containing a
     * button, you usually also color the highlightbackground as well,
     * or you will get a thin grey ring around the button.
     */
      
    if (TkMacHaveAppearance() && (butPtr->type == TYPE_BUTTON)) {
	xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
    } else {
	xcolor = Tk_3DBorderColor(butPtr->normalBorder);
    }
    if (TkMacHaveAppearance()) {
	TkSetMacColor(xcolor->pixel, &gUserPaneBackground);
    } else {
	(**ccTabHandle).ccSeed = 0;
	(**ccTabHandle).ccRider = 0;
	(**ccTabHandle).ctSize = 3;
	(**ccTabHandle).ctTable[0].value = cBodyColor;
	TkSetMacColor(xcolor->pixel,
		&(**ccTabHandle).ctTable[0].rgb);
	(**ccTabHandle).ctTable[1].value = cTextColor;
	TkSetMacColor(butPtr->normalFg->pixel,
		&(**ccTabHandle).ctTable[1].rgb);
	(**ccTabHandle).ctTable[2].value = cFrameColor;
	TkSetMacColor(butPtr->highlightColorPtr->pixel,
		&(**ccTabHandle).ctTable[2].rgb);
	SetControlColor(controlHandle, ccTabHandle);
	
	if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && 
		((butPtr->type == TYPE_CHECK_BUTTON) ||
			(butPtr->type == TYPE_RADIO_BUTTON))) {
	    RGBColor newColor;
	
	    if (TkSetMacColor(xcolor->pixel, &newColor)) {
	    ChangeBackgroundWindowColor((**controlHandle).contrlOwner,
		    newColor, saveColorPtr);
            }
	    return true;
	}
    }
    
    return false;
}

/*
 *--------------------------------------------------------------
 *
 * ChangeBackgroundWindowColor --
 *
 *	This procedure will change the background color entry
 *	in the Window's colortable.  The system isn't notified
 *	of the change.	This call should only be used to fool
 *	the drawing routines for checkboxes and radiobuttons.
 *	Any change should be temporary and be reverted after
 *	the widget is drawn.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The Window's color table will be adjusted.
 *
 *--------------------------------------------------------------
 */

static void
ChangeBackgroundWindowColor(
    WindowRef macintoshWindow,	/* A Mac window whose color to change. */
    RGBColor rgbColor,		/* The new RGB Color for the background. */
    RGBColor *oldColor)		/* The old color of the background. */
{
    AuxWinHandle auxWinHandle;
    WCTabHandle winCTabHandle;
    short ctIndex;
    ColorSpecPtr rgbScan;
	
    GetAuxWin(macintoshWindow, &auxWinHandle);
    winCTabHandle = (WCTabHandle) ((**auxWinHandle).awCTable);

    /*
     * Scan through the color table until we find the content
     * (background) color for the window.  Don't tell the system
     * about the change - it will generate damage and we will get
     * into an infinite loop.
     */

    ctIndex = (**winCTabHandle).ctSize;
    while (ctIndex > -1) {
	rgbScan = ctIndex + (**winCTabHandle).ctTable;

	if (rgbScan->value == wContentColor) {
	    *oldColor = rgbScan->rgb;
	    rgbScan->rgb = rgbColor;
	    break;
	}
	ctIndex--;
    }
}

/*
 *--------------------------------------------------------------
 *
 * 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.
 *
 *--------------------------------------------------------------
 */

static void
ButtonEventProc(
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkButton *buttonPtr = (TkButton *) clientData;

    if (eventPtr->type == ActivateNotify
            || eventPtr->type == DeactivateNotify) {
        if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
	    return;
        }
        if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
	    Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
	    buttonPtr->flags |= REDRAW_PENDING;
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ButtonExitProc --
 *
 *	This procedure is invoked just before the application exits.
 *	It frees all of the control handles, our dummy window, etc.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory is freed.
 *
 *----------------------------------------------------------------------
 */

static void
ButtonExitProc(clientData)
    ClientData clientData;		/* Not used. */
{
    Rect pixRect = {0, 0, 10, 10};
    Rect rgnRect = {0, 0, 0, 0};

    /*
     * Restore our dummy window to it's origional state by putting it
     * back in the window list and restoring it's bits.	 The destroy
     * the controls and window.
     */
 
    ((CWindowPeek) windowRef)->nextWindow = (CWindowPeek) LMGetWindowList();
    LMSetWindowList(windowRef);
    ((CWindowPeek) windowRef)->port.portPixMap = oldPixPtr;
    ((CWindowPeek) windowRef)->port.portRect = pixRect;
    RectRgn(((CWindowPeek) windowRef)->port.visRgn, &rgnRect);
    RectRgn(((CWindowPeek) windowRef)->strucRgn, &rgnRect);
    RectRgn(((CWindowPeek) windowRef)->updateRgn, &rgnRect);
    RectRgn(((CWindowPeek) windowRef)->contRgn, &rgnRect);
    PortChanged(windowRef);

    DisposeControl(buttonHandle);
    DisposeControl(checkHandle);
    DisposeControl(radioHandle);
    DisposeWindow(windowRef);
    windowRef = NULL;
}
@


1.21
log
@	* generic/tk3d.c:	All uses of 'panic' (the macro) changed
	* generic/tkBind.c:	to 'Tcl_Panic' (the function).  The #define
	* generic/tkBitmap.c:	of panic in tcl.h clearly states it is
	* generic/tkCanvArc.c:	deprecated in the comments.
	* generic/tkCanvBmap.c: [Tcl Patch 865264]
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkColor.c:
	* generic/tkConfig.c:
	* generic/tkCursor.c:
	* generic/tkError.c:
	* generic/tkEvent.c:
	* generic/tkFocus.c:
	* generic/tkFont.c:
	* generic/tkFrame.c:
	* generic/tkGC.c:
	* generic/tkGrid.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkImgUtil.c:
	* generic/tkMenu.c:
	* generic/tkObj.c:
	* generic/tkPack.c:
	* generic/tkPlace.c:
	* generic/tkRectOval.c:
	* generic/tkSelect.c:
	* generic/tkText.c:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkTextMark.c:
	* generic/tkTextWind.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* mac/tkMacAppInit.c:
	* mac/tkMacAppearanceStubs.c:
	* mac/tkMacButton.c:
	* mac/tkMacDraw.c:
	* mac/tkMacEmbed.c:
	* mac/tkMacFont.c:
	* mac/tkMacInit.c:
	* mac/tkMacMenus.c:
	* mac/tkMacPort.h:
	* mac/tkMacSubwindows.c:
	* mac/tkMacWm.c:
	* mac/tkMacXStubs.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXPort.h:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnix3d.c:
	* unix/tkUnixColor.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixEvent.c:
	* unix/tkUnixFocus.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixWm.c:
	* win/tkWin3d.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinDialog.c:
	* win/tkWinDraw.c:
	* win/tkWinEmbed.c:
	* win/tkWinFont.c:
	* win/tkWinPixmap.c:
	* win/tkWinPointer.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.20 2003/12/21 23:50:13 davygrvy Exp $
@


1.20
log
@	* generic/tkEvent.c:  Added three new functions: TkCreateExitHandler,
	* generic/tkInt.h:    TkDeleteExitHandler, and TkFinalize.  This adds
	* generic/tkMenu.c:   an insertion point so Tk's exit handlers can be
	* generic/tkWindow.c: called on their own from tk85.dll's DllMain
	* mac/tkMacButton.c:  for DLL_PROCESS_DETACH.  These are private to
	* unix/tkUnixEvent.c: the binary and not exported.  It is possible
	* win/tkWin32Dll.c:   the Windows OS can unload Tk _prior_ to Tcl
	* win/tkWinEmbed.c:   under some conditions such as ExitProcess().
	* win/tkWinMenu.c:    This avoids a dangling pointer problem when Tcl
	* win/tkWinX.c:	      does Tcl_Finalize after Tk has been unloaded.
	* win/winMain.c:      DllMain's DLL_PROCESS_DETACH now protected with
			      SEH as DeleteWindowsExitProc is causing an
			      exception of its own under some teardown
			      conditions.  AT&T assembly syntax has not been
			      added for MinGW yet.  [Tcl Patch 858493]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.19 2003/10/10 20:19:51 hobbs Exp $
d1132 1
a1132 1
	panic("Can't allocate buffer window.");
d1159 1
a1159 1
	    panic("Can't create root control in DrawBufferedControl");
@


1.19
log
@	* mac/tkMacButton.c (TkpDisplayButton):
	* macosx/tkMacOSXButton.c (TkpDisplayButton):
	* unix/tkUnixButton.c (TkpDisplayButton): correct imageYOffset for
	buttons with just images.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.18 2003/04/26 02:59:20 hobbs Exp $
d1275 1
a1275 1
     Tcl_CreateExitHandler(ButtonExitProc, (ClientData) NULL);
@


1.18
log
@	* generic/tkButton.h:                         Rewrote the handling
	* generic/tkButton.c (TkButtonWorldChanged):  of compound *buttons
	* mac/tkMacButton.c (TkpDisplayButton):       to correctly display
	* macosx/tkMacOSXButton.c (TkpDisplayButton): mixture of disabledfg,
	* unix/tkUnixButton.c (TkpDisplayButton):     selectcolor, indicator,
	* win/tkWinButton.c (TkpDisplayButton):       etc.  *buttons will
	now only stipple the image, unless no disabledfg is given, in which
	case it will stipple the whole button.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.17.2.1 2003/04/26 02:53:47 hobbs Exp $
d458 1
a458 1
		imageXOffset += y;
d463 1
a463 1
				height,	pixmap, x, y);
d466 1
a466 1
				pixmap, x, y);
@


1.17
log
@Fix for bug #582457: make radio and checkbuttons work like Windows when
-relief is sunken, -offrelief is flat, and -overrelief is raised.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.16 2002/06/17 10:54:29 drh Exp $
d171 1
a171 1
    int imageXOffset, imageYOffset, textXOffset, textYOffset;
d182 4
d346 3
a349 1

a350 2
	    imageXOffset = 0;
	    imageYOffset = 0;
d416 2
a417 1
	    
d422 1
a422 2
			    width, height, pixmap, x + imageXOffset,
			    y + imageYOffset);
d425 1
a425 2
			    height, pixmap, x + imageXOffset,
			    y + imageYOffset);
d428 2
a429 2
		XSetClipOrigin(butPtr->display, gc, x + imageXOffset,
			y + imageYOffset);
d431 2
a432 3
			0, 0, (unsigned int) width,
			(unsigned int) height, x + imageXOffset,
			y + imageYOffset, 1);
d457 2
d495 1
a495 1
     * must temporarily modify the GC.
d502 1
a502 1
	    XSetForeground(butPtr->display, butPtr->disabledGC,
d505 12
a516 4
	XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC,
		butPtr->inset, butPtr->inset,
		(unsigned) (Tk_Width(tkwin) - 2*butPtr->inset),
		(unsigned) (Tk_Height(tkwin) - 2*butPtr->inset));
d519 1
a519 1
	    XSetForeground(butPtr->display, butPtr->disabledGC,
@


1.17.2.1
log
@	* generic/tkButton.h:                         Rewrote the handling
	* generic/tkButton.c (TkButtonWorldChanged):  of compound *buttons
	* mac/tkMacButton.c (TkpDisplayButton):       to correctly display
	* macosx/tkMacOSXButton.c (TkpDisplayButton): mixture of disabledfg,
	* unix/tkUnixButton.c (TkpDisplayButton):     selectcolor, indicator,
	* win/tkWinButton.c (TkpDisplayButton):       etc.  *buttons will
	now only stipple the image, unless no disabledfg is given, in which
	case it will stipple the whole button.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.17 2002/08/28 01:08:06 drh Exp $
d171 1
a171 1
    int textXOffset, textYOffset;
a181 4
    int imageWidth, imageHeight;
    int imageXOffset = 0, imageYOffset = 0; /* image information that will
					     * be used to restrict disabled
					     * pixmap as well */
d342 1
a342 2
	imageWidth  = width;
	imageHeight = height;
a343 1
	haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
d345 2
d412 1
a412 2
	    imageXOffset += x;
	    imageYOffset += y;
d417 2
a418 1
			    width, height, pixmap, imageXOffset, imageYOffset);
d421 2
a422 1
			    height, pixmap, imageXOffset, imageYOffset);
d425 2
a426 2
		XSetClipOrigin(butPtr->display, gc,
			imageXOffset, imageYOffset);
d428 3
a430 2
			0, 0, (unsigned int) width, (unsigned int) height,
			imageXOffset, imageYOffset, 1);
a454 2
		imageXOffset += x;
		imageXOffset += y;
d491 1
a491 1
     * must temporarily modify the GC so the stippling is the right color.
d498 1
a498 1
	    XSetForeground(butPtr->display, butPtr->stippleGC,
d501 4
a504 12
	/*
	 * 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);
	}
d507 1
a507 1
	    XSetForeground(butPtr->display, butPtr->stippleGC,
@


1.17.2.2
log
@	* mac/tkMacButton.c (TkpDisplayButton):
	* macosx/tkMacOSXButton.c (TkpDisplayButton):
	* unix/tkUnixButton.c (TkpDisplayButton): correct imageYOffset for
	buttons with just images.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.17.2.1 2003/04/26 02:53:47 hobbs Exp $
d458 1
a458 1
		imageYOffset += y;
d463 1
a463 1
				height,	pixmap, imageXOffset, imageYOffset);
d466 1
a466 1
				pixmap, imageXOffset, imageYOffset);
@


1.17.2.3
log
@* generic/tkInt.h:	Backport of shutdown safety mods from the HEAD
* generic/tkMenu.c:	dating from 2003-12-21
* generic/tkUtil.c:
* generic/tkWindow.c:
* mac/tkMacButton.c:
* unix/tkUnixEvent.c:
* win/tkWin32Dll.c:
* win/tkWinEmbed.c:
* win/tkWinMenu.c:
* win/tkWinX.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.17.2.2 2003/10/10 20:20:47 hobbs Exp $
d1275 1
a1275 1
     TkCreateExitHandler(ButtonExitProc, (ClientData) NULL);
@


1.16
log
@Initial implementation of TIP #82: added the -offrelief option to
checkbutton and radiobutton to allow those widgets to have a
MS-Office look and feel.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.15 2001/11/23 02:05:37 das Exp $
d230 5
a234 2
	    relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
		: butPtr->offRelief;
@


1.15
log
@	**  upport to 8.4 of mac code changes for 8.3.3 & various new
	**  changes for 8.4, some already backported to 8.3.4 (patch #435660)

	see ChangeLog for details
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.14 2000/11/22 01:49:38 ericm Exp $
d231 1
a231 1
		: TK_RELIEF_RAISED;
@


1.14
log
@	Overall change:  Implemented TIP 5, which exports
	TkClassProcs/TkSetClassProcs as Tk_ClassProcs/Tk_SetClassProcs,
	adding a size field to Tk_ClassProcs to allow for future
	expansion, and renaming the geometryProc to worldChangedProc,
	which is more in keeping with the actual use of the callback.

	See ChangeLog for details.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.13 2000/05/17 21:17:21 ericm Exp $
d18 1
d556 1
a556 1
    int width, height, avgWidth, haveImage = 0;
d560 6
a577 6

    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;
@


1.14.4.1
log
@Merge with current TOT
Added support for the wm stackorder command
Fixed crash when selecting Menu items in the Application menu that we didn't
put there.
Added first bits of the use of CG for low-level drawing.  The line-drawing works,
the rest doesn't yet.  You have to set the file static useCGDrawing to 1 and
rebuild to activate this code.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.14 2000/11/22 01:49:38 ericm Exp $
a17 1
#include <ControlDefinitions.h>
d555 1
a555 1
    int width, height, avgWidth, haveImage = 0, haveText = 0;
a558 6
    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;

d571 6
@


1.14.4.2
log
@merged with trunk at tag macosx-8-4-merge-2002-08-20-trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d231 1
a231 1
		: butPtr->offRelief;
@


1.14.4.3
log
@merged with trunk at tag macosx-8-4-merge-2002-08-30-trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.14.4.2 2002/08/20 20:27:10 das Exp $
d230 2
a231 5
	    if (butPtr->flags & SELECTED) {
		relief = TK_RELIEF_SUNKEN;
	    } else if (butPtr->overRelief != relief) {
		relief = butPtr->offRelief;
	    }
@


1.13
log
@* doc/SetOptions.3: Added information about TK_OPTION_NULL_OK with
TK_OPTION_RELIEF.

* win/tkWinButton.c: Removed bits about TK_RELIEF_LINK.

* tests/button.test: Added tests for -overrelief; removed tests
for -relief link.

* mac/tkMacButton.c: Removed bits about TK_RELIEF_LINK.

* generic/tkOldConfig.c: Removed bits about TK_RELIEF_LINK.

* generic/tkConfig.c: Removed bits about TK_RELIEF_LINK; added
support for TK_OPTION_NULL_OK for TK_OPTION_RELIEF.

* library/button.tcl: Added binding support for -overrelief.

* generic/tk3d.c (Tk_GetRelief): Added branch for TK_RELIEF_NULL.

* generic/tkButton.c: Added -overrelief option; removed
Enter/Leave EventProc masks and handlers.

* generic/tk.h: Added TK_RELIEF_NULL definition, removed
TK_RELIEF_LINK.

* mac/tkMacDefault.h (DEF_BUTTON_OVER_RELIEF):
* win/tkWinDefault.h (DEF_BUTTON_OVER_RELIEF):
* unix/tkUnixDefault.h (DEF_BUTTON_OVER_RELIEF): Added default
value for the -overrelief option.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.12 2000/05/13 00:39:08 ericm Exp $
d107 3
a109 4
TkClassProcs tkpButtonProcs = { 
    NULL,			/* createProc. */
    TkButtonWorldChanged,	/* geometryProc. */
    NULL			/* modalProc. */
@


1.13.2.1
log
@sync with head
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.15 2001/11/23 02:05:37 das Exp $
a17 1
#include <ControlDefinitions.h>
d107 4
a110 3
Tk_ClassProcs tkpButtonProcs = { 
    sizeof(Tk_ClassProcs),	/* size */
    TkButtonWorldChanged,	/* worldChangedProc */
d556 1
a556 1
    int width, height, avgWidth, haveImage = 0, haveText = 0;
a559 6
    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;

d572 6
@


1.12
log
@* unix/tkUnixButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
* mac/tkMacButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
* win/tkWinButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
Added code for drawing compound buttons.

* tests/button.test: Added configuration tests for -repeatdelay,
-repeatinterval, -compound.

* library/button.tcl: Added support for -repeatedelay,
-repeatinterval options.

* generic/tkOldConfig.c: Changed handling of link relief so that
proper error messages are used.

* generic/tkButton.h: Added -compound, -repeatdelay,
-repeatinterval options.

* generic/tkButton.c: Added event watchers for enter/leave events,
for link relief support.

* generic/tk3d.c: Changed handling of link relief so that proper
error messages are used.

* generic/tk.h: Changed values of
TK_OPTION_LINK_OK/TK_CONFIG_LINK_OK for link relief support.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.11 2000/05/10 00:09:39 ericm Exp $
a234 13
    /*
     * LINK relief means that the button has a raised relief when it is
     * active, and a flat relief otherwise (like toolbar buttons).  It
     * is supported for true buttons only.
     */

    if ((butPtr->type == TYPE_BUTTON) && butPtr->relief == TK_RELIEF_LINK) {
	if ((butPtr->flags & MOUSE_IN_BUTTON) == MOUSE_IN_BUTTON) {
	    relief = TK_RELIEF_RAISED;
	} else {
	    relief = TK_RELIEF_FLAT;
	}
    }
@


1.11
log
@	* doc/button.n: Added documentation for link relief.

	* tests/button.test: Added tests for link relief for buttons.

	* generic/tk.h (TK_CONFIG_LINK_OK): Added definition of
	TK_RELIEF_LINK, TK_OPTION_LINK_OK and TK_CONFIG_LINK_OK. [RFE: 4348]

	* generic/tk3d.c: Added support for link relief. [RFE: 4348]

	* mac/tkMacButton.c (TkpDisplayButton):
	* unix/tkUnixButton.c (TkpDisplayButton): Added support for link
	relief. [RFE: 4348]

	* generic/tkOldConfig.c (Tk_ConfigureWidget):
	* generic/tkConfig.c (DoObjConfig): Added understanding of link
	relief, which is allowed only for widgets that have
	TK_OPTION_LINK_OK or TK_CONFIG_LINK_OK set for the "-relief"
	option. [RFE: 4348]

	* generic/tkButton.c: Added TK_OPTION_LINK_OK to "-relief" option
	for buttons. [RFE: 4348]

	* win/tkWinWm.c (EX_TRANSIENT_STYLE): Removed WS_EX_TOOLWINDOW
	style bit, so that transient windows have full-size titlebars
	(like the tk_getOpenFile dialog).

	* win/tkWinMenu.c (GetMenuSeparatorGeometry): Tweaked height
	requested for separator bars to be (linespace - (2*descent))
	instead of just (linespace); this makes the separator occupy a
	more correct amount of vertical space. [Bug: 5303].
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.10 2000/04/17 02:16:36 jingham Exp $
d170 3
a172 1
    int width, height;
d242 1
a242 1
	if (butPtr->state == STATE_ACTIVE) {
d344 69
a412 14
    } else if (butPtr->image != None) {
	Tk_SizeOfImage(butPtr->image, &width, &height);

	imageOrBitmap:
	TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
		butPtr->indicatorSpace + width, height, &x, &y);
	x += butPtr->indicatorSpace;

	x += offset;
	y += offset;
	if (relief == TK_RELIEF_RAISED) {
	    x -= offset;
	    y -= offset;
	} else if (relief == TK_RELIEF_SUNKEN) {
d415 19
a433 5
	}
	if (butPtr->image != NULL) {
	    if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
		Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
			pixmap, x, y);
d435 7
a441 2
		Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap,
			x, y);
d443 7
d451 43
a493 4
	    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);
a494 14
	y += height/2;
    } else if (butPtr->bitmap != None) {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
	goto imageOrBitmap;
    } else {
	TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
		butPtr->indicatorSpace + butPtr->textWidth, butPtr->textHeight,
		&x, &y);

	x += butPtr->indicatorSpace;

	Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout,
		x, y, 0, -1);
	y += butPtr->textHeight/2;
d569 2
a570 1
    int width, height, avgWidth;
a572 1

d580 56
a635 1
	imageOrBitmap:
d642 1
a650 8
    } else if (butPtr->bitmap != None) {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
	goto imageOrBitmap;
    } else {
	Tk_FreeTextLayout(butPtr->textLayout);
	butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
d652 2
a653 4
	width = butPtr->textWidth;
	height = butPtr->textHeight;
	avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(butPtr->tkfont, &fm);
d655 32
a686 10
	if (butPtr->width > 0) {
	    width = butPtr->width * avgWidth;
	}
	if (butPtr->height > 0) {
	    height = butPtr->height * fm.linespace;
	}
	if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
	    butPtr->indicatorDiameter = fm.linespace;
	    if (butPtr->type == TYPE_CHECK_BUTTON) {
		butPtr->indicatorDiameter = (80*butPtr->indicatorDiameter)/100;
a687 1
	    butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
@


1.10
log
@Hide button window BEHIND all the others in the application
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.9 2000/02/10 08:51:43 jingham Exp $
d233 13
@


1.10.2.1
log
@	* generic/tkInt.decls: removed superfluous declarations.
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkMain.c: include unistd.h for mac.
	* generic/tkPointer.c: include tkMacInt.h for mac.
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* mac/MW_TkHeader.pch:
	* mac/MW_TkOldImgHeader.h:
	* mac/MW_TkTestHeader.pch:
	* mac/tclets.r:
	* mac/tkMac.h:
	* mac/tkMacAppearanceStubs.c:
	* mac/tkMacApplication.r:
	* mac/tkMacButton.c:
	* mac/tkMacDialog.c: support for -filetypes
	* mac/tkMacFont.c:
	* mac/tkMacInt.h:
	* mac/tkMacLibrary.r:
	* mac/tkMacMDEF.r:
	* mac/tkMacMenu.c:
	* mac/tkMacMenus.c:
	* mac/tkMacPort.h:
	* mac/tkMacResource.r:
	* mac/tkMacScrlbr.c: improved scrollbar code
	* mac/tkMacWindowMgr.c: added control of floating windows
	* mac/tkMacWm.c: improved use of precompiled headers, better
	support for Appearance Manager, change copyrights, resource files,
	use DLLIMPORT/DLLEXPORT, comment corrections.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.10 2000/04/17 02:16:36 jingham Exp $
a17 1
#include <ControlDefinitions.h>
@


1.9
log
@Fix up debugging detritus in previous checkin.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.8 2000/02/10 08:49:29 jingham Exp $
d87 2
d133 5
a137 1
    return (TkButton *) ckalloc(sizeof(TkButton));
d782 3
a784 1
    if (butPtr->state == STATE_ACTIVE) {
a799 2
    } else if (butPtr->state == STATE_DISABLED) {
	(**controlHandle).contrlHilite = kControlInactivePart;
d911 2
d922 17
d940 1
a940 1
	    zoomDocProc, (WindowRef) -1, true, 0);
d1437 36
@


1.8
log
@Stop hiding the buffer window used for off-screen drawing from the window list.  This doesn't really buy us much, and crashes the newest Appearance manager.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.7 1999/08/07 18:53:23 jingham Exp $
d877 3
a879 3
#if 0    
    LMSetWindowList((WindowRef) ((CWindowPeek) windowRef)->nextWindow);
#endif
@


1.7
log
@Check the return from Tk_MacGetColor before  changing the color
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.6 1999/05/22 06:32:26 jingham Exp $
d174 1
a174 1
    
d642 1
a642 1
    
a796 1

d801 2
a802 1
     * proc needs to have the controls window in the window list.
d804 4
a807 3

    ((CWindowPeek) windowRef)->nextWindow = (CWindowPeek) LMGetWindowList();
    LMSetWindowList(windowRef);
d823 1
a823 1
    
d877 1
d879 1
d1029 4
d1035 14
a1048 11
    windowList = (CWindowPeek) LMGetWindowList();
    if (windowList == (CWindowPeek) windowRef) {
	LMSetWindowList((WindowRef) windowList->nextWindow);
    } else {
	while ((windowList != NULL) 
		&& (windowList->nextWindow != (CWindowPeek) windowRef)) {
	    windowList = windowList->nextWindow;
	}
	if (windowList != NULL) {
	    windowList->nextWindow = windowList->nextWindow->nextWindow;
	}
a1049 1
    ((CWindowPeek) windowRef)->nextWindow = NULL;
@


1.6
log
@Changes needed to get Tk8.1 to compile with stubs on the Mac
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.5 1999/04/16 01:51:29 stanton Exp $
d933 2
a934 1
	/* Adding UserPaneBackgroundProcs to the root control does
d1340 1
a1340 1
	    TkSetMacColor(xcolor->pixel, &newColor);
d1343 1
@


1.5
log
@* Merged 8.1 branch into the main trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d474 1
a474 1
		Tcl_GetString(butPtr->text), -1, butPtr->wrapLength,
@


1.4
log
@* Merged changes from 8.0.5:
    - Updated for Mac release
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.3 1998/09/14 18:23:34 stanton Exp $
d31 1
a31 1
#define DRAW_BEVEL      3
d88 2
a89 2
			    ControlRef controlHandle, CCTabHandle ccTabHandle,
			    RGBColor *saveColorPtr));
d91 1
a91 1
		    GWorldPtr destPort, GC gc, Pixmap pixmap));
d94 2
a95 2
		    ControlRef controlHandle, 
		    GWorldPtr destPort, GC gc, Pixmap pixmap));
d97 2
a98 2
			    WindowRef macintoshWindow, RGBColor rgbColor,
			    RGBColor *oldColor));
d196 1
a196 1
    if ((butPtr->state == tkDisabledUid) && (butPtr->disabledFg != NULL)) {
d199 1
a199 1
	    && (butPtr->state == tkActiveUid)) {
d206 1
a206 1
    if ((butPtr->flags & SELECTED) && (butPtr->state != tkActiveUid)
d221 1
a221 1
        if (!TkMacHaveAppearance() || !hasImageOrBitmap) {
d223 2
a224 2
		    : TK_RELIEF_RAISED;
        }
d233 2
a234 2
        Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
	        Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
d236 2
a237 2
    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
	    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
d254 1
a254 1
	     * -data & -mask specified.  We should probably draw the 
d260 1
a260 1
	        drawType = DRAW_BEVEL;
d262 7
a268 7
	        TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
	        if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
	            (clipPtr->value.pixmap != butPtr->bitmap)) {
	            drawType = DRAW_CUSTOM;
	        } else {
	            drawType = DRAW_BEVEL;
	        }
d276 1
a276 1
	        drawType = DRAW_BEVEL;
d278 7
a284 7
	        TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
	        if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
	            (clipPtr->value.pixmap != butPtr->bitmap)) {
	            drawType = DRAW_CUSTOM;
	        } else {
	            drawType = DRAW_BEVEL;
	        }
d292 1
a292 1
     * Draw the native portion of the buttons.  Start by creating the control
d298 1
a298 1
            ((drawType == DRAW_BEVEL) && TkMacHaveAppearance())) {
d322 1
a322 1
        /* Empty Body */
d372 1
a372 1
     * foreground color, generate the stippled effect.  If the widget
d377 1
a377 1
    if ((butPtr->state == tkDisabledUid)
d474 1
a474 1
		butPtr->text, -1, butPtr->wrapLength,
d507 1
a507 1
     * non-Appearance buttons with images is different.  In the latter case, 
d519 1
a519 1
     * button.  The actual width of the default ring is one less than the
d531 6
a536 1
        if ((butPtr->image == None) && (butPtr->bitmap == None)) {
d538 2
a539 7
            if (butPtr->defaultState != tkDisabledUid) {
                butPtr->inset += butPtr->highlightWidth;
            }
        } else if (TkMacHaveAppearance()) {
                butPtr->inset = 0;
                width += (2 * butPtr->borderWidth + 4);
                height += (2 * butPtr->borderWidth + 4);
d541 7
a547 7
            butPtr->inset = butPtr->borderWidth;
	width += 2;
	height += 2;
            if (butPtr->defaultState != tkDisabledUid) {
                butPtr->inset += butPtr->highlightWidth;
            }
        }
d549 1
a549 1
        if (butPtr->indicatorOn) {
d552 21
a572 21
	/*
	 * Under Appearance, the Checkbutton or radiobutton with an image
	 * is represented by a BevelButton with the Sticky defProc...  
	 * So we must set its height in the same way as the Button 
	 * with an image or bitmap.
	 */
            if (((butPtr->image != None) || (butPtr->bitmap != None))
                    && TkMacHaveAppearance()) {
                int border;
                butPtr->inset = 0;
                if ( butPtr->borderWidth <= 2 ) {
                    border = 6;
                }  else {
                    border = 2 * butPtr->borderWidth + 2;
                }              
                width += border;
                height += border;
            } else {
 	        butPtr->inset = butPtr->borderWidth;
            }   
        }	
d632 1
a632 1
    				 * the bevel button */
d634 1
a634 1
                                   for the bevel button */
d644 1
a644 1
        InitSampleControls();
d649 1
a649 1
     * window.  We also adjust various fields in the WindowRecord to make
d656 1
a656 1
        ((CWindowPeek) windowRef)->port.portPixMap = destPort->portPixMap;
d668 1
a668 1
     * to draw in the buffered window.  
d674 17
a690 17
            if (TkMacHaveAppearance()) {
	        if ((butPtr->image == None) && (butPtr->bitmap == None)) {
	            controlHandle = buttonHandle;
	            ccTabHandle = buttonTabHandle;
	        } else {
	            if (butPtr->borderWidth <= 2) {
                        controlHandle = smallBevelHandle;
                    } else if (butPtr->borderWidth == 3) {
                        controlHandle = medBevelHandle;
                    } else {
                        controlHandle = largeBevelHandle;
                    }
                    ccTabHandle = buttonTabHandle;
                    SetupBevelButton(butPtr, controlHandle, destPort, 
                            gc, pixmap);
	            isBevel = 1;	        
	        }
d692 2
a693 2
	        controlHandle = buttonHandle;
	        ccTabHandle = buttonTabHandle;
d698 17
a714 17
	        if (((butPtr->image == None) && (butPtr->bitmap == None))
	                || (butPtr->indicatorOn)) {
	            controlHandle = radioHandle;
	            ccTabHandle = radioTabHandle;
	        } else {
	            if (butPtr->borderWidth <= 2) {
                        controlHandle = smallStickyBevelHandle;
                    } else if (butPtr->borderWidth == 3) {
                        controlHandle = medStickyBevelHandle;
                    } else {
                        controlHandle = largeStickyBevelHandle;
                    }
	            ccTabHandle = radioTabHandle;
                    SetupBevelButton(butPtr, controlHandle, destPort, 
                            gc, pixmap);
	            isBevel = 1;	        
	        }
d716 3
a718 3
	        controlHandle = radioHandle;
	        ccTabHandle = radioTabHandle;
            }	       
d722 17
a738 17
	        if (((butPtr->image == None) && (butPtr->bitmap == None))
	                || (butPtr->indicatorOn)) {
	            controlHandle = checkHandle;
	            ccTabHandle = checkTabHandle;
	        } else {
	            if (butPtr->borderWidth <= 2) {
                        controlHandle = smallStickyBevelHandle;
                    } else if (butPtr->borderWidth == 3) {
                        controlHandle = medStickyBevelHandle;
                    } else {
                        controlHandle = largeStickyBevelHandle;
                    }
	            ccTabHandle = checkTabHandle;
                    SetupBevelButton(butPtr, controlHandle, destPort, 
                            gc, pixmap);
	            isBevel = 1;	        
	        }
d740 3
a742 3
	        controlHandle = checkHandle;
	        ccTabHandle = checkTabHandle;
            }	       
d749 1
a749 1
	    - butPtr->inset;
d751 1
a751 1
	    - butPtr->inset;
d759 8
a766 8
        SetControlVisibility(controlHandle, true, false);      
        (**userPaneHandle).contrlRect.left = 0;
        (**userPaneHandle).contrlRect.top = 0;
        (**userPaneHandle).contrlRect.right = Tk_Width(butPtr->tkwin);
        (**userPaneHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin);
    } else {      
        (**controlHandle).contrlVis = 255;
    }     
d768 1
a768 1
	        
d776 4
a779 4
    if (butPtr->state == tkActiveUid) {
        if (isBevel) {
            (**controlHandle).contrlHilite = kControlButtonPart;
        } else {
d781 1
a781 1
	        case TYPE_BUTTON:
d784 1
a784 1
	        case TYPE_RADIO_BUTTON:
d787 1
a787 1
	        case TYPE_CHECK_BUTTON:
d792 1
a792 1
    } else if (butPtr->state == tkDisabledUid) {
d818 1
a818 1
        SetPort((GrafPort *) destPort);
d820 1
a820 1
        SetPort(windowRef);
d824 1
a824 1
	ccTabHandle, &saveBackColor);
d827 3
a829 3
        Boolean isDefault;
        
        if (butPtr->defaultState == tkActiveUid) {
d835 2
a836 2
	        kControlPushButtonDefaultTag,
	        sizeof(isDefault), (Ptr) &isDefault);	            	
d840 1
a840 1
        DrawControlInCurrentPort(userPaneHandle);
d842 1
a842 1
        Draw1Control(controlHandle);
d846 2
a847 2
            (butPtr->type == TYPE_BUTTON) && 
	    (butPtr->defaultState == tkActiveUid)) {
d869 7
a875 7
        SetControlVisibility(controlHandle, false, false);
        if (isBevel) {
            KillPicture(bevelButtonContent.u.picture);
        }     
    } else {      
        (**controlHandle).contrlVis = 0;
    }     
d885 2
a886 2
 *      sample controls to allow drawing Mac controls to any GWorld 
 *      (including off-screen bitmaps).  
d910 1
a910 1
	
d912 1
a912 1
	zoomDocProc, (WindowRef) -1, true, 0);
d929 9
a937 9
        OSErr err;
 	ControlRef dontCare;
 	    
 	/* 
 	 * Adding UserPaneBackgroundProcs to the root control does
 	 * not seem to work, so we have to add another UserPane to 
 	 * the root control.
 	 */
 	     
d945 1
a945 1
	        0, 1, kControlUserPaneProc, (SInt32) 0);
d951 1
a951 1
	        false, 1, 0, 1, kControlPushButtonProc, (SInt32) 0);
d953 2
a954 2
	        checkHandle = NewControl(windowRef, &geometry, "\p",
	        false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 0);
d956 2
a957 2
	        radioHandle = NewControl(windowRef, &geometry, "\p",
	        false, 1, 0, 1, kControlRadioButtonProc, (SInt32) 0);
d959 46
a1004 40
        smallBevelHandle = NewControl(windowRef, &geometry, "\p",
                false, 0, 0, 
	        kControlBehaviorOffsetContents << 16 | kControlContentPictHandle, 
	        kControlBevelButtonSmallBevelProc, (SInt32) 0);
        EmbedControl(smallBevelHandle, userPaneHandle);
        medBevelHandle = NewControl(windowRef, &geometry, "\p",
                false, 0, 0, 
	        kControlBehaviorOffsetContents << 16 | kControlContentPictHandle, 
	        kControlBevelButtonNormalBevelProc, (SInt32) 0);
        EmbedControl(medBevelHandle, userPaneHandle);
        largeBevelHandle = NewControl(windowRef, &geometry, "\p",
                false, 0, 0, 
	        kControlBehaviorOffsetContents << 16 | kControlContentPictHandle, 
	        kControlBevelButtonLargeBevelProc, (SInt32) 0);
        EmbedControl(largeBevelHandle, userPaneHandle);
        bevelButtonContent.contentType = kControlContentPictHandle;
        smallStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
	        false, 0, 0, 
	        (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 
	        | kControlContentPictHandle, 
	        kControlBevelButtonSmallBevelProc, (SInt32) 0);
        EmbedControl(smallStickyBevelHandle, userPaneHandle);
        medStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
	        false, 0, 0, 
	        (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 
	        | kControlContentPictHandle, 
	        kControlBevelButtonNormalBevelProc, (SInt32) 0);
        EmbedControl(medStickyBevelHandle, userPaneHandle);
        largeStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
	        false, 0, 0, 
	        (kControlBehaviorOffsetContents | kControlBehaviorSticky) << 16 
	        | kControlContentPictHandle, 
	        kControlBevelButtonLargeBevelProc, (SInt32) 0);
        EmbedControl(largeStickyBevelHandle, userPaneHandle);
    
        picParams.version = -2;
        picParams.hRes = 0x00480000;
        picParams.vRes = 0x00480000;
        picParams.srcRect.top = 0;
        picParams.srcRect.left = 0;
d1022 2
a1023 2
     * Remove our window from the window list.  This way our
     * applications ad others will not be confused that this
d1049 3
a1051 3
	 oldPixPtr = ((CWindowPeek) windowRef)->port.portPixMap;
	 Tcl_CreateExitHandler(ButtonExitProc, (ClientData) NULL);
     */  
d1074 1
a1074 1
    ControlRef controlHandle,    /* The control to set this picture to */
d1077 1
a1077 1
    				 * the bevel button */
d1079 1
a1079 1
                                   for the bevel button */
d1088 2
a1089 2
        Tk_SizeOfImage(butPtr->image, 
                &width, &height);
d1091 2
a1092 2
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, 
                &width, &height);
d1094 1
a1094 1
            
d1114 2
a1115 2
        Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
	        pixmap, 0, 0);
d1117 6
a1122 6
        Tk_RedrawImage(butPtr->image, 0, 0, width, 
            height, pixmap, 0, 0);
    } else {	                
        XSetClipOrigin(butPtr->display, gc, 0, 0);
        XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
                (unsigned int) width, (unsigned int) height, 0, 0, 1);
d1128 4
a1131 4
            kControlBevelButtonContentTag,
            sizeof(ControlButtonContentInfo),
            (char *) &bevelButtonContent);
            
d1133 17
a1149 17
            theAlignment = kControlBevelButtonAlignTop;
     } else if (butPtr->anchor == TK_ANCHOR_NE) { 
            theAlignment = kControlBevelButtonAlignTopRight;
     } else if (butPtr->anchor == TK_ANCHOR_E) { 
            theAlignment = kControlBevelButtonAlignRight;
     } else if (butPtr->anchor == TK_ANCHOR_SE) {
            theAlignment = kControlBevelButtonAlignBottomRight;
     } else if (butPtr->anchor == TK_ANCHOR_S) {
            theAlignment = kControlBevelButtonAlignBottom;
     } else if (butPtr->anchor == TK_ANCHOR_SW) {
            theAlignment = kControlBevelButtonAlignBottomLeft;
     } else if (butPtr->anchor == TK_ANCHOR_W) {
            theAlignment = kControlBevelButtonAlignLeft;
     } else if (butPtr->anchor == TK_ANCHOR_NW) {
            theAlignment = kControlBevelButtonAlignTopLeft;
     } else if (butPtr->anchor == TK_ANCHOR_CENTER) {
            theAlignment = kControlBevelButtonAlignCenter;
d1153 3
a1155 3
            kControlBevelButtonGraphicAlignTag,
            sizeof(ControlButtonGraphicAlignment),
            (char *) &theAlignment);
d1165 2
a1166 2
 *      to a userPane control.  From MoreControls code
 *      from Apple DTS.
d1177 2
a1178 2
        ControlRef control,
        ControlUserPaneDrawProcPtr upp)
d1183 3
a1185 3
	        kControlNoPart, kControlUserPaneDrawProcTag, 
	        sizeof(myControlUserPaneDrawUPP), 
	        (Ptr) &myControlUserPaneDrawUPP);
d1194 1
a1194 1
 *      to a userPane control
d1212 3
a1214 3
                kControlUserPaneBackgroundProcTag, 
	        sizeof(myControlUserPaneBackgroundUPP), 
	        (Ptr) &myControlUserPaneBackgroundUPP);
d1223 1
a1223 1
 *      lie under checkboxes and radiobuttons.
d1238 3
a1240 3
	Rect contrlRect = (**control).contrlRect;
	RGBBackColor (&gUserPaneBackground);
	EraseRect (&contrlRect);
d1249 1
a1249 1
 *      lie under checkboxes and radiobuttons.
d1266 1
a1266 1
        RGBBackColor (&gUserPaneBackground);
d1280 2
a1281 2
 *      Under Appearance, we just set the pointer that will be
 *      used by the UserPaneDrawProc.
d1304 1
a1304 1
     *  of the containing userPane.  This will be the color that peeks 
d1313 1
a1313 1
        xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
d1315 1
a1315 1
        xcolor = Tk_3DBorderColor(butPtr->normalBorder);
d1318 1
a1318 1
         TkSetMacColor(xcolor->pixel, &gUserPaneBackground);
d1321 4
a1324 4
        (**ccTabHandle).ccRider = 0;
        (**ccTabHandle).ctSize = 3;
        (**ccTabHandle).ctTable[0].value = cBodyColor;
        TkSetMacColor(xcolor->pixel,
d1326 2
a1327 2
        (**ccTabHandle).ctTable[1].value = cTextColor;
        TkSetMacColor(butPtr->normalFg->pixel,
d1329 2
a1330 2
        (**ccTabHandle).ctTable[2].value = cFrameColor;
        TkSetMacColor(butPtr->highlightColorPtr->pixel,
d1332 5
a1336 5
        SetControlColor(controlHandle, ccTabHandle);
        
        if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && 
	        ((butPtr->type == TYPE_CHECK_BUTTON) ||
		(butPtr->type == TYPE_RADIO_BUTTON))) {
d1339 3
a1341 4
	    if (TkSetMacColor(xcolor->pixel, &newColor)) {
	        ChangeBackgroundWindowColor((**controlHandle).contrlOwner,
		        newColor, saveColorPtr);
            }
d1343 1
a1343 1
        }
d1356 1
a1356 1
 *	of the change.  This call should only be used to fool
d1430 1
a1430 1
     * back in the window list and restoring it's bits.  The destroy
@


1.3
log
@Replaced SCCS strings, fixed binary files
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d900 2
a901 2
	Rect geometry = {0, 0, 10, 10};
	CWindowPeek windowList;
d903 7
a909 7
	/*
	 * Create a dummy window that we can draw to.  We will
	 * actually replace this window's bitmap with the one
	 * we want to draw to at a later time.  This window and
	 * the data structures attached to it are only deallocated
	 * on exit of the application.
	 */
d911 5
a915 5
	windowRef = NewCWindow(NULL, &geometry, "\pempty", false, 
	    zoomDocProc, (WindowRef) -1, true, 0);
	if (windowRef == NULL) {
	    panic("Can't allocate buffer window.");
	}
d917 8
a924 8
	/*
	 * Now add the three standard controls to hidden window.  We
	 * only create one of each and reuse them for every widget in
	 * Tk.
	 * Under Appearance, we have to embed the controls in a UserPane
	 * control, so that we can color the background text in 
	 * radiobuttons and checkbuttons.
	 */
d926 1
a926 1
	SetPort(windowRef);
d928 3
a930 4
        if (TkMacHaveAppearance()) {
            
 	    OSErr err;
 	    ControlRef dontCare;
d932 5
a936 4
 	    /* Adding UserPaneBackgroundProcs to the root control does
 	     * not seem to work, so we have to add another UserPane to 
 	     * the root control.
 	     */
d938 4
a941 4
	    err = CreateRootControl(windowRef, &dontCare);
	    if (err != noErr) {
	        panic("Can't create root control in DrawBufferedControl");
	    }
d943 1
a943 1
	    userPaneHandle = NewControl(windowRef, &geometry, "\p",
d946 3
a948 3
	    SetUserPaneSetUpSpecialBackgroundProc(userPaneHandle,
		    UserPaneBackgroundProc);
	    SetUserPaneDrawProc(userPaneHandle, UserPaneDraw);
d950 1
a950 1
	    buttonHandle = NewControl(windowRef, &geometry, "\p",
d952 5
a956 5
	    EmbedControl(buttonHandle, userPaneHandle);
	    checkHandle = NewControl(windowRef, &geometry, "\p",
	    false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 0);
	    EmbedControl(checkHandle, userPaneHandle);
	    radioHandle = NewControl(windowRef, &geometry, "\p",
d958 1
a958 1
	    EmbedControl(radioHandle, userPaneHandle);
d1000 2
a1001 2
	    ((CWindowPeek) windowRef)->visible = true;
        } else {
d1013 1
a1013 1
        }
d1015 5
a1019 5
	/*
	 * Remove our window from the window list.  This way our
	 * applications and others will not be confused that this
	 * window exists - but no one knows about it.
	 */
d1021 10
a1030 11
	windowList = (CWindowPeek) LMGetWindowList();
	if (windowList == (CWindowPeek) windowRef) {
	    LMSetWindowList((WindowRef) windowList->nextWindow);
	} else {
	    while ((windowList != NULL) 
		    && (windowList->nextWindow != (CWindowPeek) windowRef)) {
		windowList = windowList->nextWindow;
	    }
	    if (windowList != NULL) {
		windowList->nextWindow = windowList->nextWindow->nextWindow;
	    }
d1032 2
a1033 1
	((CWindowPeek) windowRef)->nextWindow = NULL;
d1035 7
a1041 7
	/* 
	 * Create an exit handler to clean up this mess if we our
	 * unloaded etc.  We need to remember the windows portPixMap
	 * so it isn't leaked.
	 *
	 * TODO: The ButtonExitProc doesn't currently work and the
	 * code it includes will crash the Mac on exit from Tk.
d1045 1
a1045 1
	 */
d1309 1
a1309 1
    xcolor = Tk_3DBorderColor(butPtr->normalBorder);
d1313 14
a1326 14
     } else {
    (**ccTabHandle).ccSeed = 0;
    (**ccTabHandle).ccRider = 0;
    (**ccTabHandle).ctSize = 3;
    (**ccTabHandle).ctTable[0].value = cBodyColor;
    TkSetMacColor(xcolor->pixel,
	&(**ccTabHandle).ctTable[0].rgb);
    (**ccTabHandle).ctTable[1].value = cTextColor;
    TkSetMacColor(butPtr->normalFg->pixel,
	&(**ccTabHandle).ctTable[1].rgb);
    (**ccTabHandle).ctTable[2].value = cFrameColor;
    TkSetMacColor(butPtr->highlightColorPtr->pixel,
	&(**ccTabHandle).ctTable[2].rgb);
    SetControlColor(controlHandle, ccTabHandle);
d1328 4
a1331 4
    if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && 
	    ((butPtr->type == TYPE_CHECK_BUTTON) ||
		    (butPtr->type == TYPE_RADIO_BUTTON))) {
	RGBColor newColor;
d1333 6
a1338 5
	TkSetMacColor(xcolor->pixel, &newColor);
	ChangeBackgroundWindowColor((**controlHandle).contrlOwner,
		newColor, saveColorPtr);
	return true;
    }
@


1.3.2.1
log
@Mostly fixed formatting that had gotten wrong somehow.  Also always make sure to check the result of TkMacGetColor, and don't set the color if it comes back false.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.3 1998/09/14 18:23:34 stanton Exp $
d900 2
a901 2
    Rect geometry = {0, 0, 10, 10};
    CWindowPeek windowList;
d903 7
a909 7
    /*
     * Create a dummy window that we can draw to.  We will
     * actually replace this window's bitmap with the one
     * we want to draw to at a later time.  This window and
     * the data structures attached to it are only deallocated
     * on exit of the application.
     */
d911 5
a915 5
    windowRef = NewCWindow(NULL, &geometry, "\pempty", false, 
	zoomDocProc, (WindowRef) -1, true, 0);
    if (windowRef == NULL) {
	panic("Can't allocate buffer window.");
    }
d917 8
a924 8
    /*
     * Now add the three standard controls to hidden window.  We
     * only create one of each and reuse them for every widget in
     * Tk.
     * Under Appearance, we have to embed the controls in a UserPane
     * control, so that we can color the background text in 
     * radiobuttons and checkbuttons.
     */
d926 1
a926 1
    SetPort(windowRef);
d928 4
a931 3
    if (TkMacHaveAppearance()) {
        OSErr err;
 	ControlRef dontCare;
d933 4
a936 5
 	/* 
 	 * Adding UserPaneBackgroundProcs to the root control does
 	 * not seem to work, so we have to add another UserPane to 
 	 * the root control.
 	 */
d938 4
a941 4
	err = CreateRootControl(windowRef, &dontCare);
	if (err != noErr) {
	    panic("Can't create root control in DrawBufferedControl");
	}
d943 1
a943 1
	userPaneHandle = NewControl(windowRef, &geometry, "\p",
d946 3
a948 3
	SetUserPaneSetUpSpecialBackgroundProc(userPaneHandle,
		UserPaneBackgroundProc);
	SetUserPaneDrawProc(userPaneHandle, UserPaneDraw);
d950 1
a950 1
	buttonHandle = NewControl(windowRef, &geometry, "\p",
d952 5
a956 5
	EmbedControl(buttonHandle, userPaneHandle);
	        checkHandle = NewControl(windowRef, &geometry, "\p",
	        false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 0);
	EmbedControl(checkHandle, userPaneHandle);
	        radioHandle = NewControl(windowRef, &geometry, "\p",
d958 1
a958 1
	EmbedControl(radioHandle, userPaneHandle);
d1000 2
a1001 2
	((CWindowPeek) windowRef)->visible = true;
    } else {
d1013 1
a1013 1
    }
d1015 5
a1019 5
    /*
     * Remove our window from the window list.  This way our
     * applications ad others will not be confused that this
     * window exists - but no one knows about it.
     */
d1021 11
a1031 10
    windowList = (CWindowPeek) LMGetWindowList();
    if (windowList == (CWindowPeek) windowRef) {
	LMSetWindowList((WindowRef) windowList->nextWindow);
    } else {
	while ((windowList != NULL) 
		&& (windowList->nextWindow != (CWindowPeek) windowRef)) {
	    windowList = windowList->nextWindow;
	}
	if (windowList != NULL) {
	    windowList->nextWindow = windowList->nextWindow->nextWindow;
d1033 1
a1033 2
    }
    ((CWindowPeek) windowRef)->nextWindow = NULL;
d1035 7
a1041 7
    /* 
     * Create an exit handler to clean up this mess if we our
     * unloaded etc.  We need to remember the windows portPixMap
     * so it isn't leaked.
     *
     * TODO: The ButtonExitProc doesn't currently work and the
     * code it includes will crash the Mac on exit from Tk.
d1045 1
a1045 1
     */  
d1309 1
a1309 1
        xcolor = Tk_3DBorderColor(butPtr->normalBorder);
d1313 14
a1326 14
    } else {
	(**ccTabHandle).ccSeed = 0;
        (**ccTabHandle).ccRider = 0;
        (**ccTabHandle).ctSize = 3;
        (**ccTabHandle).ctTable[0].value = cBodyColor;
        TkSetMacColor(xcolor->pixel,
		&(**ccTabHandle).ctTable[0].rgb);
        (**ccTabHandle).ctTable[1].value = cTextColor;
        TkSetMacColor(butPtr->normalFg->pixel,
		&(**ccTabHandle).ctTable[1].rgb);
        (**ccTabHandle).ctTable[2].value = cFrameColor;
        TkSetMacColor(butPtr->highlightColorPtr->pixel,
		&(**ccTabHandle).ctTable[2].rgb);
        SetControlColor(controlHandle, ccTabHandle);
d1328 4
a1331 4
        if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && 
	        ((butPtr->type == TYPE_CHECK_BUTTON) ||
		(butPtr->type == TYPE_RADIO_BUTTON))) {
	    RGBColor newColor;
d1333 5
a1337 6
	    if (TkSetMacColor(xcolor->pixel, &newColor)) {
	        ChangeBackgroundWindowColor((**controlHandle).contrlOwner,
		        newColor, saveColorPtr);
            }
	    return true;
        }
@


1.2
log
@Mac updates for 8.0.3-2
@
text
@d12 1
a12 1
 * SCCS: @@(#) tkMacButton.c 1.18 97/11/20 18:27:21
@


1.1
log
@Initial revision
@
text
@d19 1
d21 3
d31 1
d45 15
d66 18
d87 1
a87 1
static int		UpdateControlColors _ANSI_ARGS_((TkButton *butPtr,
d90 7
a96 3
static void		DrawBufferedControl _ANSI_ARGS_((TkButton *butPtr,
			    GWorldPtr destPort));
static void		ChangeBackgroundWindowColor _ANSI_ARGS_((
d99 1
a99 1
static void		ButtonExitProc _ANSI_ARGS_((ClientData clientData));
d169 1
d182 13
d198 2
a199 1
    } else if ((butPtr->type == TYPE_BUTTON) && (butPtr->state == tkActiveUid)) {
d205 1
d214 2
d219 6
a224 3
    if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
	relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
		: TK_RELIEF_RAISED;
a226 3
    offset = ((butPtr->type == TYPE_BUTTON) && 
	((butPtr->image != NULL) || (butPtr->bitmap != None)));

d228 2
a229 4
     * In order to avoid screen flashes, this procedure redraws
     * the button in a pixmap, then copies the pixmap to the
     * screen in a single operation.  This means that there's no
     * point in time where the on-sreen image has been cleared.
d231 5
a235 3

    pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
d238 1
a238 1

d243 1
a243 1
	if ((butPtr->image == None) && (butPtr->bitmap == None)) {
d245 2
d248 22
a269 1
	    drawType = DRAW_CUSTOM;
d274 12
d297 2
a298 1
    if (drawType == DRAW_CONTROL) {
d308 1
a308 1
	DrawBufferedControl(butPtr, destPort);
d316 3
a318 1
     * Display image or bitmap or text for button.
d321 3
a323 1
    if (butPtr->image != None) {
a444 11
    if (butPtr->highlightWidth < 0) {
	butPtr->highlightWidth = 0;
    }
    if ((butPtr->type == TYPE_BUTTON) && (butPtr->image == None)
	    && (butPtr->bitmap == None)) {
	butPtr->inset = 0;
    } else if ((butPtr->type != TYPE_LABEL) && butPtr->indicatorOn) {
	butPtr->inset = 0;
    } else {
	butPtr->inset = butPtr->borderWidth;
    }
d447 1
a447 4
     * The highlight width corresponds to the default ring on the Macintosh.
     * As such, the highlight width is only added if the button is the default
     * button.  The actual width of the default ring is one less than the
     * highlight width as there is also one pixel of spacing.
d449 1
a449 4

    if (butPtr->defaultState != tkDisabledUid) {
	butPtr->inset += butPtr->highlightWidth;
    }
d474 2
a475 2
		butPtr->text, -1, butPtr->wrapLength, butPtr->justify, 0,
		&butPtr->textWidth, &butPtr->textHeight);
d498 14
d516 7
d525 1
a525 1
    if ((butPtr->image == NULL) && (butPtr->bitmap == None)) {
d529 13
a541 2
    if ((butPtr->type == TYPE_BUTTON) && 
	((butPtr->image != NULL) || (butPtr->bitmap != None))) {
d544 31
d576 3
d630 6
a635 1
    GWorldPtr destPort)		/* Off screen GWorld. */
d641 156
d798 102
a899 1
    if (windowRef == NULL) {
d905 1
a905 1
	 * actually replace this windows bitmap with a the one
d921 3
d927 75
d1013 1
d1046 32
a1077 1
    }
d1079 1
a1079 4
    /*
     * Set up control in hidden window to match what we need
     * to draw in the buffered window.
     */
d1081 6
a1086 13
    switch (butPtr->type) {
	case TYPE_BUTTON:
	    controlHandle = buttonHandle;
	    ccTabHandle = buttonTabHandle;
	    break;
	case TYPE_RADIO_BUTTON:
	    controlHandle = radioHandle;
	    ccTabHandle = radioTabHandle;
	    break;
	case TYPE_CHECK_BUTTON:
	    controlHandle = checkHandle;
	    ccTabHandle = checkTabHandle;
	    break;
d1088 3
a1090 8
    (**controlHandle).contrlRect.left = butPtr->inset;
    (**controlHandle).contrlRect.top = butPtr->inset;
    (**controlHandle).contrlRect.right = Tk_Width(butPtr->tkwin) 
	    - butPtr->inset;
    (**controlHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin) 
	    - butPtr->inset;
    if ((**controlHandle).contrlVis != 255) {
	(**controlHandle).contrlVis = 255;
d1092 2
a1093 4
    if (butPtr->flags & SELECTED) {
	(**controlHandle).contrlValue = 1;
    } else {
	(**controlHandle).contrlValue = 0;
d1095 6
a1100 18
    if (butPtr->state == tkActiveUid) {
	switch (butPtr->type) {
	    case TYPE_BUTTON:
		(**controlHandle).contrlHilite = kControlButtonPart;
		break;
	    case TYPE_RADIO_BUTTON:
		(**controlHandle).contrlHilite = kControlRadioButtonPart;
		break;
	    case TYPE_CHECK_BUTTON:
		(**controlHandle).contrlHilite = kControlCheckBoxPart;
		break;
	}
    } else if (butPtr->state == tkDisabledUid) {
	(**controlHandle).contrlHilite = kControlInactivePart;
    } else {
	(**controlHandle).contrlHilite = kControlNoPart;
    }

d1102 3
a1104 3
     * Now swap in the passed in GWorld for the portBits of our fake
     * window.  We also adjust various fields in the WindowRecord to make
     * the system think this is a normal window.
d1106 12
a1117 8

    ((CWindowPeek) windowRef)->port.portPixMap = destPort->portPixMap;
    ((CWindowPeek) windowRef)->port.portRect = destPort->portRect;
    RectRgn(((CWindowPeek) windowRef)->port.visRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->strucRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->updateRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->contRgn, &destPort->portRect);
    PortChanged(windowRef);
d1119 26
a1144 6
    /*
     * Before we draw the control we must add the hidden window back to the
     * main window list.  Otherwise, radiobuttons and checkbuttons will draw
     * incorrectly.  I don't really know why - but clearly the control draw
     * proc needs to have the controls window in the window list.
     */
d1146 4
a1149 2
    ((CWindowPeek) windowRef)->nextWindow = (CWindowPeek) LMGetWindowList();
    LMSetWindowList(windowRef);
d1151 102
a1252 6
    /*
     * Now we can set the port to our doctered up window.  We next need
     * to muck with the colors for the port & window to draw the control
     * with the proper Tk colors.  If we need to we also draw a default
     * ring for buttons.
     */
d1254 7
a1260 14
    SetPort(windowRef);
    windowColorChanged = UpdateControlColors(butPtr, controlHandle, 
	ccTabHandle, &saveBackColor);
    Draw1Control(controlHandle);
    if ((butPtr->type == TYPE_BUTTON) && 
	    (butPtr->defaultState == tkActiveUid)) {
	Rect box = (**controlHandle).contrlRect;
	RGBColor rgbColor;

	TkSetMacColor(butPtr->highlightColorPtr->pixel, &rgbColor);
	RGBForeColor(&rgbColor);
	PenSize(butPtr->highlightWidth - 1, butPtr->highlightWidth - 1);
	InsetRect(&box, -butPtr->highlightWidth, -butPtr->highlightWidth);
	FrameRoundRect(&box, 16, 16);
a1261 10
    if (windowColorChanged) {
	RGBColor dummyColor;
	ChangeBackgroundWindowColor(windowRef, saveBackColor, &dummyColor);
    }
    
    /*
     * Clean up: remove the hidden window from the main window list.
     */

    LMSetWindowList((WindowRef) ((CWindowPeek) windowRef)->nextWindow);
d1274 3
d1295 14
d1310 4
a1313 1

d1338 1
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d5 1
a5 1
 *	button widgets. 
d12 1
a12 1
 * SCCS: @@(#) tkMacButton.c 1.20 98/02/18 10:48:42
a18 1
#include <Appearance.h>
a45 18
 * These functions are used when Appearance is present.
 * By embedding all our controls in a userPane control,
 * we can color the background of the text in radiobuttons
 * and checkbuttons.  Thanks to Peter Gontier of Apple DTS
 * for help on this one.
 */

static ControlRef userPaneHandle;
static RGBColor gUserPaneBackground = { ~0, ~0, ~0};
static pascal OSErr SetUserPaneDrawProc(ControlRef control,
	ControlUserPaneDrawProcPtr upp);
static pascal OSErr SetUserPaneSetUpSpecialBackgroundProc(ControlRef control,
	ControlUserPaneBackgroundProcPtr upp);
static pascal void UserPaneDraw(ControlRef control, ControlPartCode cpc);
static pascal void UserPaneBackgroundProc(ControlHandle,
	ControlBackgroundPtr info);

/*
d49 9
a57 9
static int	UpdateControlColors _ANSI_ARGS_((TkButton *butPtr,
		    ControlRef controlHandle, CCTabHandle ccTabHandle,
		    RGBColor *saveColorPtr));
static void	DrawBufferedControl _ANSI_ARGS_((TkButton *butPtr,
		    GWorldPtr destPort));
static void	ChangeBackgroundWindowColor _ANSI_ARGS_((
		    WindowRef macintoshWindow, RGBColor rgbColor,
		    RGBColor *oldColor));
static void	ButtonExitProc _ANSI_ARGS_((ClientData clientData));
d140 1
a140 1
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
d142 1
a142 2
    } else if ((butPtr->type == TYPE_BUTTON)
	    && (butPtr->state == STATE_ACTIVE)) {
d148 1
a148 1
    if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
d176 3
a178 12
    /*
     * See the comment in UpdateControlColors as to why we use the 
     * highlightbackground for the border of Macintosh buttons.
     */
     
    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);
    }
d277 1
a277 1
    if ((butPtr->state == STATE_DISABLED)
d364 1
a364 1
    if (butPtr->defaultState != DEFAULT_DISABLED) {
d391 2
a392 2
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
d494 1
a494 1
	 * actually replace this window's bitmap with the one
d499 2
a500 2
	 
        windowRef = NewCWindow(NULL, &geometry, "\pempty", false, 
d505 1
a505 1
            
a509 3
	 * Under Appearance, we have to embed the controls in a UserPane
	 * control, so that we can color the background text in 
	 * radiobuttons and checkbuttons.
d513 11
a523 46
	
        if (TkMacHaveAppearance()) {
            
 	    OSErr err;
 	    ControlRef dontCare;
 	    
 	    /* Adding UserPaneBackgroundProcs to the root control does
 	     * not seem to work, so we have to add another UserPane to 
 	     * the root control.
 	     */
 	     
	    err = CreateRootControl(windowRef, &dontCare);
	    if (err != noErr) {
	        panic("Can't create root control in DrawBufferedControl");
	    }
	    
	    userPaneHandle = NewControl(windowRef, &geometry, "\p",
		true, kControlSupportsEmbedding|kControlHasSpecialBackground, 
		0, 1, kControlUserPaneProc, (SInt32) 5);
	    SetUserPaneSetUpSpecialBackgroundProc(userPaneHandle,
		    UserPaneBackgroundProc);
	    SetUserPaneDrawProc(userPaneHandle, UserPaneDraw);

	    buttonHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlPushButtonProc, (SInt32) 6);
	    EmbedControl(buttonHandle, userPaneHandle);
	    checkHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 7);
	    EmbedControl(checkHandle, userPaneHandle);
	    radioHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlRadioButtonProc, (SInt32) 8);
	    EmbedControl(radioHandle, userPaneHandle);
	    ((CWindowPeek) windowRef)->visible = true;
        } else {
	    buttonHandle = NewControl(windowRef, &geometry, "\p",
	            false, 1, 0, 1, pushButProc, (SInt32) 0);
	    checkHandle = NewControl(windowRef, &geometry, "\p",
	            false, 1, 0, 1, checkBoxProc, (SInt32) 0);
	    radioHandle = NewControl(windowRef, &geometry, "\p",
	            false, 1, 0, 1, radioButProc, (SInt32) 0);
	    ((CWindowPeek) windowRef)->visible = true;

	    buttonTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	    checkTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	    radioTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
        }
a558 19
     * Now swap in the passed in GWorld for the portBits of our fake
     * window.  We also adjust various fields in the WindowRecord to make
     * the system think this is a normal window.
     * Note, we can use DrawControlInCurrentPort under Appearance, so we don't
     * need to swap pixmaps.
     */
    
    if (!TkMacHaveAppearance()) {
        ((CWindowPeek) windowRef)->port.portPixMap = destPort->portPixMap;
    }
    
    ((CWindowPeek) windowRef)->port.portRect = destPort->portRect;
    RectRgn(((CWindowPeek) windowRef)->port.visRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->strucRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->updateRgn, &destPort->portRect);
    RectRgn(((CWindowPeek) windowRef)->contRgn, &destPort->portRect);
    PortChanged(windowRef);
    
    /*
d560 1
a560 1
     * to draw in the buffered window.  
d562 1
a562 1
   
a576 1
    
d583 3
a585 18
	    
    /*
     * Setting the control visibility by hand does not 
     * seem to work under Appearance. 
     */
     
    if (TkMacHaveAppearance()) {
        SetControlVisibility(controlHandle, true, false);      
        (**userPaneHandle).contrlRect.left = 0;
        (**userPaneHandle).contrlRect.top = 0;
        (**userPaneHandle).contrlRect.right = Tk_Width(butPtr->tkwin);
        (**userPaneHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin);
    } else {      
        (**controlHandle).contrlVis = 255;
    }     
    
	        
    
d591 1
a591 2
    
    if (butPtr->state == STATE_ACTIVE) {
d603 1
a603 1
    } else if (butPtr->state == STATE_DISABLED) {
d610 14
a637 2
     * Under Appearance, we draw the control directly into destPort, and
     * just set the default control data.
d640 1
a640 6
    if (TkMacHaveAppearance()) {
        SetPort((GrafPort *) destPort);
    } else {
        SetPort(windowRef);
    }
    
d643 3
a645 23
	
    if ((butPtr->type == TYPE_BUTTON) && TkMacHaveAppearance()) {
        Boolean isDefault;
        
        if (butPtr->defaultState == DEFAULT_ACTIVE) {
	    isDefault = true;
	} else {
	    isDefault = false;
	}
	SetControlData(controlHandle, kControlNoPart, 
	        kControlPushButtonDefaultTag,
	        sizeof(isDefault), (Ptr) &isDefault);	
    }

    if (TkMacHaveAppearance()) {
        DrawControlInCurrentPort(userPaneHandle);
    } else {
        Draw1Control(controlHandle);
    }

    if (!TkMacHaveAppearance() &&
            (butPtr->type == TYPE_BUTTON) && 
	    (butPtr->defaultState == DEFAULT_ACTIVE)) {
a654 1
    
d661 1
a661 2
     * Clean up: remove the hidden window from the main window list, and
     * hide the control we drew.  
a663 5
    if (TkMacHaveAppearance()) {
        SetControlVisibility(controlHandle, false, false);      
    } else {      
        (**controlHandle).contrlVis = 0;
    }     
a669 111
 * SetUserPaneDrawProc --
 *
 *	Utility function to add a UserPaneDrawProc
 *      to a userPane control.  From MoreControls code
 *      from Apple DTS.
 *
 * Results:
 *	MacOS system error.
 *
 * Side effects:
 *	The user pane gets a new UserPaneDrawProc.
 *
 *--------------------------------------------------------------
 */
pascal OSErr SetUserPaneDrawProc (
        ControlRef control,
        ControlUserPaneDrawProcPtr upp)
{
    ControlUserPaneDrawUPP myControlUserPaneDrawUPP;
    myControlUserPaneDrawUPP = NewControlUserPaneDrawProc(upp);	
    return SetControlData (control, 
	        kControlNoPart, kControlUserPaneDrawProcTag, 
	        sizeof(myControlUserPaneDrawUPP), 
	        (Ptr) &myControlUserPaneDrawUPP);
}

/*
 *--------------------------------------------------------------
 *
 * SetUserPaneSetUpSpecialBackgroundProc --
 *
 *	Utility function to add a UserPaneBackgroundProc
 *      to a userPane control
 *
 * Results:
 *	MacOS system error.
 *
 * Side effects:
 *	The user pane gets a new UserPaneBackgroundProc.
 *
 *--------------------------------------------------------------
 */
pascal OSErr
SetUserPaneSetUpSpecialBackgroundProc(
    ControlRef control, 
    ControlUserPaneBackgroundProcPtr upp)
{
    ControlUserPaneBackgroundUPP myControlUserPaneBackgroundUPP;
    myControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundProc(upp);
    return SetControlData (control, kControlNoPart, 
                kControlUserPaneBackgroundProcTag, 
	        sizeof(myControlUserPaneBackgroundUPP), 
	        (Ptr) &myControlUserPaneBackgroundUPP);
}

/*
 *--------------------------------------------------------------
 *
 * UserPaneDraw --
 *
 *	This function draws the background of the user pane that will 
 *      lie under checkboxes and radiobuttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The user pane gets updated to the current color.
 *
 *--------------------------------------------------------------
 */
pascal void
UserPaneDraw(
    ControlRef control,
    ControlPartCode cpc)
{
	Rect contrlRect = (**control).contrlRect;
	RGBBackColor (&gUserPaneBackground);
	EraseRect (&contrlRect);
}

/*
 *--------------------------------------------------------------
 *
 * UserPaneBackgroundProc --
 *
 *	This function sets up the background of the user pane that will 
 *      lie under checkboxes and radiobuttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The user pane background gets set to the current color.
 *
 *--------------------------------------------------------------
 */

pascal void
UserPaneBackgroundProc(
    ControlHandle,
    ControlBackgroundPtr info)
{
    if (info->colorDevice) {
        RGBBackColor (&gUserPaneBackground);
    }
}

/*
 *--------------------------------------------------------------
 *
a676 3
 *      Under Appearance, we just set the pointer that will be
 *      used by the UserPaneDrawProc.
 *
d695 20
a714 36
    /*
     * Under Appearance we cannot change the background of the
     * button itself.  However, the color we are setting is the color
     *  of the containing userPane.  This will be the color that peeks 
     * around the rounded corners of the button.  
     * We make this the highlightbackground rather than the background,
     * because if you color the background of a frame containing a
     * button, you usually also color the highlightbackground as well,
     * or you will get a thin grey ring around the button.
     */
      
    if (TkMacHaveAppearance() && (butPtr->type == TYPE_BUTTON)) {
        xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
    } else {
        xcolor = Tk_3DBorderColor(butPtr->normalBorder);
    }
    if (TkMacHaveAppearance()) {
         TkSetMacColor(xcolor->pixel, &gUserPaneBackground);
     } else {
        (**ccTabHandle).ccSeed = 0;
        (**ccTabHandle).ccRider = 0;
        (**ccTabHandle).ctSize = 3;
        (**ccTabHandle).ctTable[0].value = cBodyColor;
        TkSetMacColor(xcolor->pixel,
	    &(**ccTabHandle).ctTable[0].rgb);
        (**ccTabHandle).ctTable[1].value = cTextColor;    
        TkSetMacColor(butPtr->normalFg->pixel,
	    &(**ccTabHandle).ctTable[1].rgb);
        (**ccTabHandle).ctTable[2].value = cFrameColor;
        TkSetMacColor(butPtr->highlightColorPtr->pixel,
	    &(**ccTabHandle).ctTable[2].rgb);
        SetControlColor(controlHandle, ccTabHandle);
        if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) &&
            ((butPtr->type == TYPE_CHECK_BUTTON) ||
    		    (butPtr->type == TYPE_RADIO_BUTTON))) {
    	    RGBColor newColor;
d716 4
a719 5
	    TkSetMacColor(xcolor->pixel, &newColor);
	    ChangeBackgroundWindowColor((**controlHandle).contrlOwner,
		    newColor, saveColorPtr);
            return true;
	}
d721 1
a721 1
            
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d5 1
a5 1
 *	button widgets.
d12 1
a12 1
 * RCS: @@(#) $Id: tkMacButton.c,v 1.3 1998/09/14 18:23:34 stanton Exp $
a20 3

#include <ToolUtils.h>

a27 1
#define DRAW_BEVEL	3
a40 15
static ControlRef smallBevelHandle;
static ControlRef smallStickyBevelHandle;
static ControlRef medBevelHandle;
static ControlRef medStickyBevelHandle;
static ControlRef largeBevelHandle;
static ControlRef largeStickyBevelHandle;

/*
 * These are used to store the image content for
 * beveled buttons - i.e. buttons with images.
 */
 
static ControlButtonContentInfo bevelButtonContent;
static OpenCPicParams picParams;

d69 2
a70 2
	ControlRef controlHandle, CCTabHandle ccTabHandle,
	RGBColor *saveColorPtr));
d72 1
a72 5
	GWorldPtr destPort, GC gc, Pixmap pixmap));
static void	InitSampleControls();
static void	SetupBevelButton _ANSI_ARGS_((TkButton *butPtr,
	ControlRef controlHandle, 
	GWorldPtr destPort, GC gc, Pixmap pixmap));
d74 2
a75 2
    WindowRef macintoshWindow, RGBColor rgbColor,
    RGBColor *oldColor));
a145 1
    int hasImageOrBitmap;
a157 13
    /*
     * In order to avoid screen flashes, this procedure redraws
     * the button in a pixmap, then copies the pixmap to the
     * screen in a single operation.  This means that there's no
     * point in time where the on-sreen image has been cleared.
     */

    pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));

    hasImageOrBitmap = ((butPtr->image != NULL) || (butPtr->bitmap != None));
    offset = (butPtr->type == TYPE_BUTTON) && hasImageOrBitmap;

a167 1
    
a175 2
     * However, don't do this in the presence of Appearance, since
     * then the bevel button will take care of the relief.
d179 2
a180 4

    if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) { 
	if (!TkMacHaveAppearance() || !hasImageOrBitmap) {
	    relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
a181 1
	}
d184 12
d202 2
a203 2
	Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
		Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
d205 2
a206 2
	Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
		Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
d212 1
a212 1
	if (!hasImageOrBitmap) {
a213 2
	} else if (butPtr->image != None) {
	    drawType = DRAW_BEVEL;
d215 1
a215 22
	    /*
	     * TO DO - The current way the we draw bitmaps (XCopyPlane)
	     * uses CopyDeepMask in this one case.  The Picture recording 
	     * does not record this call, and so we can't use the
	     * Appearance bevel button here.  The only case that would
	     * exercise this is if you use a bitmap, with
	     * -data & -mask specified.	 We should probably draw the 
	     * appearance button and overprint the image in this case.
	     * This just punts and draws the old-style, ugly, button.
	     */
	     
	    if (gc->clip_mask == 0) {
		drawType = DRAW_BEVEL;
	    } else {
		TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
		if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
			(clipPtr->value.pixmap != butPtr->bitmap)) {
		    drawType = DRAW_CUSTOM;
		} else {
		    drawType = DRAW_BEVEL;
		}
	    }
a219 12
	} else if (hasImageOrBitmap) {
	    if (gc->clip_mask == 0) {
		drawType = DRAW_BEVEL;
	    } else {
		TkpClipMask *clipPtr = (TkpClipMask*) gc->clip_mask;
		if ((clipPtr->type == TKP_CLIP_PIXMAP) &&
			(clipPtr->value.pixmap != butPtr->bitmap)) {
		    drawType = DRAW_CUSTOM;
		} else {
		    drawType = DRAW_BEVEL;
		}
	    }
d226 1
a226 1
     * Draw the native portion of the buttons.	Start by creating the control
d231 1
a231 2
    if ((drawType == DRAW_CONTROL) || 
	    ((drawType == DRAW_BEVEL) && TkMacHaveAppearance())) {
d241 1
a241 1
	DrawBufferedControl(butPtr, destPort, gc, pixmap);
d249 1
a249 3
     * Display image or bitmap or text for button.  This has
     * already been done under Appearance with the Bevel
     * button types.
d252 1
a252 3
    if ((drawType == DRAW_BEVEL) && TkMacHaveAppearance()) {
	/* Empty Body */
    } else if (butPtr->image != None) {
d301 1
a301 1
     * foreground color, generate the stippled effect.	If the widget
d374 11
d387 4
a390 1
     * First figure out the size of the contents of the button.
d392 4
a395 1
     
d420 1
a420 1
		Tcl_GetString(butPtr->text), -1, butPtr->wrapLength,
a443 14
     * Now figure out the size of the border decorations for the button.
     */
     
    if (butPtr->highlightWidth < 0) {
	butPtr->highlightWidth = 0;
    }
    
    /*
     * The width and height calculation for Appearance buttons with images & 
     * non-Appearance buttons with images is different.	 In the latter case, 
     * we add the borderwidth to the inset, since we are going to stamp a
     * 3-D border over the image.  In the former, we add it to the height,
     * directly, since Appearance will draw the border as part of our control.
     *
a447 7
     *
     * The highlight width corresponds to the default ring on the Macintosh.
     * As such, the highlight width is only added if the button is the default
     * button.	The actual width of the default ring is one less than the
     * highlight width as there is also one pixel of spacing.
     * Appearance buttons with images do not have a highlight ring, because the 
     * Bevel button type does not support one.
d450 1
a450 1
    if ((butPtr->image == None) && (butPtr->bitmap == None)) {
d454 4
a457 46
    
    if ((butPtr->type == TYPE_BUTTON)) {
	if ((butPtr->image == None) && (butPtr->bitmap == None)) {
	    butPtr->inset = 0;
	    if (butPtr->defaultState != STATE_DISABLED) {
		butPtr->inset += butPtr->highlightWidth;
	    }
	} else if (TkMacHaveAppearance()) {
	    butPtr->inset = 0;
	    width += (2 * butPtr->borderWidth + 4);
	    height += (2 * butPtr->borderWidth + 4);
	} else {
	    butPtr->inset = butPtr->borderWidth;
	    width += 2;
	    height += 2;
	    if (butPtr->defaultState != STATE_DISABLED) {
		butPtr->inset += butPtr->highlightWidth;
	    }
	}
    } else if ((butPtr->type != TYPE_LABEL)) {
	if (butPtr->indicatorOn) {
	    butPtr->inset = 0;
	} else {
	    /*
	     * Under Appearance, the Checkbutton or radiobutton with an image
	     * is represented by a BevelButton with the Sticky defProc...  
	     * So we must set its height in the same way as the Button 
	     * with an image or bitmap.
	     */
	    if (((butPtr->image != None) || (butPtr->bitmap != None))
		    && TkMacHaveAppearance()) {
		int border;
		butPtr->inset = 0;
		if ( butPtr->borderWidth <= 2 ) {
		    border = 6;
		}  else {
		    border = 2 * butPtr->borderWidth + 2;
		}	       
		width += border;
		height += border;
	    } else {
		butPtr->inset = butPtr->borderWidth;
	    }	
	}	
    } else {
	butPtr->inset = butPtr->borderWidth;
a458 3



d510 1
a510 6
    GWorldPtr destPort,		/* Off screen GWorld. */
    GC gc,			/* The GC we are drawing into - needed for
				 * the bevel button */
    Pixmap pixmap		/* The pixmap we are drawing into - needed
				   for the bevel button */
    )		
d516 1
a516 2
    int isBevel = 0;
    
d518 105
a622 1
	InitSampleControls();
d627 1
a627 1
     * window.	We also adjust various fields in the WindowRecord to make
d634 1
a634 1
	((CWindowPeek) windowRef)->port.portPixMap = destPort->portPixMap;
d646 1
a646 1
     * to draw in the buffered window.	
d648 1
a648 2
     
    isBevel = 0;   
d651 2
a652 21
	    if (TkMacHaveAppearance()) {
		if ((butPtr->image == None) && (butPtr->bitmap == None)) {
		    controlHandle = buttonHandle;
		    ccTabHandle = buttonTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medBevelHandle;
		    } else {
			controlHandle = largeBevelHandle;
		    }
		    ccTabHandle = buttonTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = buttonHandle;
		ccTabHandle = buttonTabHandle;
	    }
d655 2
a656 22
	    if (TkMacHaveAppearance()) {
		if (((butPtr->image == None) && (butPtr->bitmap == None))
			|| (butPtr->indicatorOn)) {
		    controlHandle = radioHandle;
		    ccTabHandle = radioTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallStickyBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medStickyBevelHandle;
		    } else {
			controlHandle = largeStickyBevelHandle;
		    }
		    ccTabHandle = radioTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = radioHandle;
		ccTabHandle = radioTabHandle;
	    }	       
d659 2
a660 22
	    if (TkMacHaveAppearance()) {
		if (((butPtr->image == None) && (butPtr->bitmap == None))
			|| (butPtr->indicatorOn)) {
		    controlHandle = checkHandle;
		    ccTabHandle = checkTabHandle;
		} else {
		    if (butPtr->borderWidth <= 2) {
			controlHandle = smallStickyBevelHandle;
		    } else if (butPtr->borderWidth == 3) {
			controlHandle = medStickyBevelHandle;
		    } else {
			controlHandle = largeStickyBevelHandle;
		    }
		    ccTabHandle = checkTabHandle;
		    SetupBevelButton(butPtr, controlHandle, destPort, 
			    gc, pixmap);
		    isBevel = 1;		
		}
	    } else {
		controlHandle = checkHandle;
		ccTabHandle = checkTabHandle;
	    }	       
d667 1
a667 1
	- butPtr->inset;
d669 1
a669 1
	- butPtr->inset;
d677 8
a684 8
	SetControlVisibility(controlHandle, true, false);      
	(**userPaneHandle).contrlRect.left = 0;
	(**userPaneHandle).contrlRect.top = 0;
	(**userPaneHandle).contrlRect.right = Tk_Width(butPtr->tkwin);
	(**userPaneHandle).contrlRect.bottom = Tk_Height(butPtr->tkwin);
    } else {	  
	(**controlHandle).contrlVis = 255;
    }	  
d686 1
a686 1
		
d695 10
a704 14
	if (isBevel) {
	    (**controlHandle).contrlHilite = kControlButtonPart;
	} else {
	    switch (butPtr->type) {
		case TYPE_BUTTON:
		    (**controlHandle).contrlHilite = kControlButtonPart;
		    break;
		case TYPE_RADIO_BUTTON:
		    (**controlHandle).contrlHilite = kControlRadioButtonPart;
		    break;
		case TYPE_CHECK_BUTTON:
		    (**controlHandle).contrlHilite = kControlCheckBoxPart;
		    break;
	    }
d732 1
a732 1
	SetPort((GrafPort *) destPort);
d734 1
a734 1
	SetPort(windowRef);
d738 1
a738 1
	    ccTabHandle, &saveBackColor);
d741 3
a743 3
	Boolean isDefault;
	
	if (butPtr->defaultState == STATE_ACTIVE) {
d749 2
a750 2
		kControlPushButtonDefaultTag,
		sizeof(isDefault), (Ptr) &isDefault);			
d754 1
a754 1
	DrawControlInCurrentPort(userPaneHandle);
d756 1
a756 1
	Draw1Control(controlHandle);
d760 2
a761 2
	    (butPtr->type == TYPE_BUTTON) && 
	    (butPtr->defaultState == STATE_ACTIVE)) {
d783 4
a786 7
	SetControlVisibility(controlHandle, false, false);
	if (isBevel) {
	    KillPicture(bevelButtonContent.u.picture);
	}     
    } else {	  
	(**controlHandle).contrlVis = 0;
    }	  
a792 280
 * InitSampleControls --
 *
 *	This function initializes a dummy Macintosh window and
 *	sample controls to allow drawing Mac controls to any GWorld 
 *	(including off-screen bitmaps).	 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Controls & a window are created.
 *
 *--------------------------------------------------------------
 */

static void
InitSampleControls()
{
    Rect geometry = {0, 0, 10, 10};
    CWindowPeek windowList;

    /*
     * Create a dummy window that we can draw to.  We will
     * actually replace this window's bitmap with the one
     * we want to draw to at a later time.  This window and
     * the data structures attached to it are only deallocated
     * on exit of the application.
     */

    windowRef = NewCWindow(NULL, &geometry, "\pempty", false, 
	    zoomDocProc, (WindowRef) -1, true, 0);
    if (windowRef == NULL) {
	panic("Can't allocate buffer window.");
    }
	
    /*
     * Now add the three standard controls to hidden window.  We
     * only create one of each and reuse them for every widget in
     * Tk.
     * Under Appearance, we have to embed the controls in a UserPane
     * control, so that we can color the background text in 
     * radiobuttons and checkbuttons.
     */
	
    SetPort(windowRef);
	
    if (TkMacHaveAppearance()) {
	    
	OSErr err;
	ControlRef dontCare;
	    
	/* Adding UserPaneBackgroundProcs to the root control does
	 * not seem to work, so we have to add another UserPane to 
	 * the root control.
	 */
	     
	err = CreateRootControl(windowRef, &dontCare);
	if (err != noErr) {
	    panic("Can't create root control in DrawBufferedControl");
	}
	    
	userPaneHandle = NewControl(windowRef, &geometry, "\p",
		true, kControlSupportsEmbedding|kControlHasSpecialBackground, 
		0, 1, kControlUserPaneProc, (SInt32) 0);
	SetUserPaneSetUpSpecialBackgroundProc(userPaneHandle,
		UserPaneBackgroundProc);
	SetUserPaneDrawProc(userPaneHandle, UserPaneDraw);

	buttonHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlPushButtonProc, (SInt32) 0);
	EmbedControl(buttonHandle, userPaneHandle);
	checkHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlCheckBoxProc, (SInt32) 0);
	EmbedControl(checkHandle, userPaneHandle);
	radioHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, kControlRadioButtonProc, (SInt32) 0);
	EmbedControl(radioHandle, userPaneHandle);
	smallBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonSmallBevelProc, (SInt32) 0);
	EmbedControl(smallBevelHandle, userPaneHandle);
	medBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonNormalBevelProc, (SInt32) 0);
	EmbedControl(medBevelHandle, userPaneHandle);
	largeBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		kControlBehaviorOffsetContents << 16
		| kControlContentPictHandle, 
		kControlBevelButtonLargeBevelProc, (SInt32) 0);
	EmbedControl(largeBevelHandle, userPaneHandle);
	bevelButtonContent.contentType = kControlContentPictHandle;
	smallStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonSmallBevelProc, (SInt32) 0);
	EmbedControl(smallStickyBevelHandle, userPaneHandle);
	medStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonNormalBevelProc, (SInt32) 0);
	EmbedControl(medStickyBevelHandle, userPaneHandle);
	largeStickyBevelHandle = NewControl(windowRef, &geometry, "\p",
		false, 0, 0, 
		(kControlBehaviorOffsetContents
			| kControlBehaviorSticky) << 16 
		| kControlContentPictHandle, 
		kControlBevelButtonLargeBevelProc, (SInt32) 0);
	EmbedControl(largeStickyBevelHandle, userPaneHandle);
    
	picParams.version = -2;
	picParams.hRes = 0x00480000;
	picParams.vRes = 0x00480000;
	picParams.srcRect.top = 0;
	picParams.srcRect.left = 0;
    
	((CWindowPeek) windowRef)->visible = true;
    } else {
	buttonHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, pushButProc, (SInt32) 0);
	checkHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, checkBoxProc, (SInt32) 0);
	radioHandle = NewControl(windowRef, &geometry, "\p",
		false, 1, 0, 1, radioButProc, (SInt32) 0);
	((CWindowPeek) windowRef)->visible = true;

	buttonTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	checkTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
	radioTabHandle = (CCTabHandle) NewHandle(sizeof(CtlCTab));
    }

    /*
     * Remove our window from the window list.	This way our
     * applications and others will not be confused that this
     * window exists - but no one knows about it.
     */

    windowList = (CWindowPeek) LMGetWindowList();
    if (windowList == (CWindowPeek) windowRef) {
	LMSetWindowList((WindowRef) windowList->nextWindow);
    } else {
	while ((windowList != NULL) 
		&& (windowList->nextWindow != (CWindowPeek) windowRef)) {
	    windowList = windowList->nextWindow;
	}
	if (windowList != NULL) {
	    windowList->nextWindow = windowList->nextWindow->nextWindow;
	}
    }
    ((CWindowPeek) windowRef)->nextWindow = NULL;

    /* 
     * Create an exit handler to clean up this mess if we our
     * unloaded etc.  We need to remember the windows portPixMap
     * so it isn't leaked.
     *
     * TODO: The ButtonExitProc doesn't currently work and the
     * code it includes will crash the Mac on exit from Tk.
	 
     oldPixPtr = ((CWindowPeek) windowRef)->port.portPixMap;
     Tcl_CreateExitHandler(ButtonExitProc, (ClientData) NULL);
    */

}

/*
 *--------------------------------------------------------------
 *
 * SetupBevelButton --
 *
 *	Sets up the Bevel Button with image by copying the
 *	source image onto the PicHandle for the button.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The image or bitmap for the button is copied over to a picture.
 *
 *--------------------------------------------------------------
 */
void
SetupBevelButton(
    TkButton *butPtr,		/* Tk button. */
    ControlRef controlHandle,	 /* The control to set this picture to */
    GWorldPtr destPort,		/* Off screen GWorld. */
    GC gc,			/* The GC we are drawing into - needed for
				 * the bevel button */
    Pixmap pixmap		/* The pixmap we are drawing into - needed
				   for the bevel button */
    )
{
    int height, width;
    ControlButtonGraphicAlignment theAlignment;
    
    SetPort((GrafPtr) destPort);

    if (butPtr->image != None) {
	Tk_SizeOfImage(butPtr->image, 
		&width, &height);
    } else {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, 
		&width, &height);
    }
	    
    if ((butPtr->width > 0) && (butPtr->width < width)) {
	width = butPtr->width;
    }
    if ((butPtr->height > 0) && (butPtr->height < height)) {
	height = butPtr->height;
    }
    
    picParams.srcRect.right = width;
    picParams.srcRect.bottom = height;
    
    bevelButtonContent.u.picture = OpenCPicture(&picParams);
    
    /*
     * TO DO - There is one case where XCopyPlane calls CopyDeepMask,
     * which does not get recorded in the picture.  So the bitmap code
     * will fail in that case.
     */
     
    if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
	Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height,
		pixmap, 0, 0);
    } else if (butPtr->image != NULL) {
	Tk_RedrawImage(butPtr->image, 0, 0, width, 
		height, pixmap, 0, 0);
    } else {			
	XSetClipOrigin(butPtr->display, gc, 0, 0);
	XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
		(unsigned int) width, (unsigned int) height, 0, 0, 1);
    }
    
    ClosePicture();
    
    SetControlData(controlHandle, kControlButtonPart,
	    kControlBevelButtonContentTag,
	    sizeof(ControlButtonContentInfo),
	    (char *) &bevelButtonContent);
	    
    if (butPtr->anchor == TK_ANCHOR_N) {
	theAlignment = kControlBevelButtonAlignTop;
    } else if (butPtr->anchor == TK_ANCHOR_NE) { 
	theAlignment = kControlBevelButtonAlignTopRight;
    } else if (butPtr->anchor == TK_ANCHOR_E) { 
	theAlignment = kControlBevelButtonAlignRight;
    } else if (butPtr->anchor == TK_ANCHOR_SE) {
	theAlignment = kControlBevelButtonAlignBottomRight;
    } else if (butPtr->anchor == TK_ANCHOR_S) {
	theAlignment = kControlBevelButtonAlignBottom;
    } else if (butPtr->anchor == TK_ANCHOR_SW) {
	theAlignment = kControlBevelButtonAlignBottomLeft;
    } else if (butPtr->anchor == TK_ANCHOR_W) {
	theAlignment = kControlBevelButtonAlignLeft;
    } else if (butPtr->anchor == TK_ANCHOR_NW) {
	theAlignment = kControlBevelButtonAlignTopLeft;
    } else if (butPtr->anchor == TK_ANCHOR_CENTER) {
	theAlignment = kControlBevelButtonAlignCenter;
    }

    SetControlData(controlHandle, kControlButtonPart,
	    kControlBevelButtonGraphicAlignTag,
	    sizeof(ControlButtonGraphicAlignment),
	    (char *) &theAlignment);

}

/*
 *--------------------------------------------------------------
 *
d796 2
a797 2
 *	to a userPane control.	From MoreControls code
 *	from Apple DTS.
d808 2
a809 2
    ControlRef control,
    ControlUserPaneDrawProcPtr upp)
d814 3
a816 3
	    kControlNoPart, kControlUserPaneDrawProcTag, 
	    sizeof(myControlUserPaneDrawUPP), 
	    (Ptr) &myControlUserPaneDrawUPP);
d825 1
a825 1
 *	to a userPane control
d843 3
a845 3
	    kControlUserPaneBackgroundProcTag, 
	    sizeof(myControlUserPaneBackgroundUPP), 
	    (Ptr) &myControlUserPaneBackgroundUPP);
d854 1
a854 1
 *	lie under checkboxes and radiobuttons.
d869 3
a871 3
    Rect contrlRect = (**control).contrlRect;
    RGBBackColor (&gUserPaneBackground);
    EraseRect (&contrlRect);
d880 1
a880 1
 *	lie under checkboxes and radiobuttons.
d897 1
a897 1
	RGBBackColor (&gUserPaneBackground);
d911 2
a912 2
 *	Under Appearance, we just set the pointer that will be
 *	used by the UserPaneDrawProc.
d935 1
a935 1
     *	of the containing userPane.  This will be the color that peeks 
d944 1
a944 1
	xcolor = Tk_3DBorderColor(butPtr->highlightBorder);
d946 1
a946 1
	xcolor = Tk_3DBorderColor(butPtr->normalBorder);
d949 19
a967 20
	TkSetMacColor(xcolor->pixel, &gUserPaneBackground);
    } else {
	(**ccTabHandle).ccSeed = 0;
	(**ccTabHandle).ccRider = 0;
	(**ccTabHandle).ctSize = 3;
	(**ccTabHandle).ctTable[0].value = cBodyColor;
	TkSetMacColor(xcolor->pixel,
		&(**ccTabHandle).ctTable[0].rgb);
	(**ccTabHandle).ctTable[1].value = cTextColor;
	TkSetMacColor(butPtr->normalFg->pixel,
		&(**ccTabHandle).ctTable[1].rgb);
	(**ccTabHandle).ctTable[2].value = cFrameColor;
	TkSetMacColor(butPtr->highlightColorPtr->pixel,
		&(**ccTabHandle).ctTable[2].rgb);
	SetControlColor(controlHandle, ccTabHandle);
	
	if (((xcolor->pixel >> 24) != CONTROL_BODY_PIXEL) && 
		((butPtr->type == TYPE_CHECK_BUTTON) ||
			(butPtr->type == TYPE_RADIO_BUTTON))) {
	    RGBColor newColor;
d972 1
a972 1
	    return true;
d975 1
a975 1
    
d986 1
a986 1
 *	of the change.	This call should only be used to fool
d1060 1
a1060 1
     * back in the window list and restoring it's bits.	 The destroy
@


