head	1.12;
access;
symbols
	core-8-5-9:1.11
	core-8-5-8:1.11
	macosx-cocoa-merge:1.11
	macosx-cocoa-premerge:1.11
	macosx-carbon-freeze:1.11
	core-8-5-7:1.11
	core-8-5-6:1.11
	core-8-6-b1:1.11
	core-8-6-a3:1.11
	core-8-5-5:1.11
	core-8-6-a2:1.11
	core-8-5-4:1.11
	core-8-5-3:1.11
	core-8-6-a1:1.11
	core-8-4-19:1.6.4.1
	core-8-5-branch:1.11.0.2
	core-8-5-2:1.11
	core-8-4-18:1.6.4.1
	core-8-5-1:1.11
	core-8-4-17:1.6.4.1
	core-8-5-0:1.11
	core-8-5-b3:1.10
	core-8-5-b2:1.10
	core-8-4-16:1.6.4.1
	core-8-5-b1:1.10
	core-stablilizer-merge:1.9
	core-stabilizer-branch:1.9.0.2
	core-stabilizer-merge:1.11
	core-8-4-15:1.6.4.1
	core-8-5-a6:1.9
	core-8-5-a5:1.8
	core-8-4-14:1.6.4.1
	core-8-5-a4:1.8
	core-8-4-13:1.6.4.1
	core-8-4-12:1.6.4.1
	core-8-4-11:1.6.4.1
	core-8-5-a3:1.7
	core-8-4-10:1.6.4.1
	core-8-4-9-branch:1.6.4.1.0.2
	core-8-5-a2:1.7
	core-8-4-9:1.6.4.1
	core-8-4-8:1.6.4.1
	core-8-4-7:1.6.4.1
	core-8-5-a1:1.7
	core-8-4-6:1.6.4.1
	core-8-4-5:1.6.4.1
	mistachkin-dev-branch:1.6.0.6
	core-8-4-4:1.6
	core-8-4-3:1.6
	core-8-4-branch:1.6.0.4
	core-8-4-2:1.6
	core-8-4-1:1.6
	core-8-3-5:1.4
	core-8-4-0:1.6
	macosx-8-4-merge-2002-08-31-trunk:1.6
	macosx-8-4-premerge-2002-08-31-branch:1.6
	macosx-8-4-premerge-2002-08-31-trunk:1.6
	macosx-8-4-merge-2002-08-30-branch:1.6
	macosx-8-4-merge-2002-08-30-trunk:1.6
	macosx-8-4-merge-2002-08-20-branch:1.6
	macosx-8-4-merge-2002-08-20-trunk:1.6
	core-8-4-b2:1.6
	core-8-4-b1:1.6
	macosx-premerge-6-9-02:1.6
	core-8-4-a4:1.6
	core-8-3-4:1.4
	macosx-8-4-branch:1.6.0.2
	macosx-8-4-branchpoint:1.6
	core-8-4-a3:1.6
	core-8-3-3:1.4
	dgp-privates-into-namespace:1.5.0.2
	tclpro-1-5-0:1.4
	core-8-4-win-speedup:1.4.0.4
	core-8-4-a2:1.4
	tclpro-1-4-1:1.4
	tclpro-1-4-0:1.4
	core-8-3-2:1.4
	ajuba-ajuba2-2-1-base:1.4
	ajuba-ajuba2-2-0:1.4
	core-8-4-a1:1.4
	core-8-3-1-branch:1.4.0.2
	core-8-3-1:1.4
	scriptics-sc-2-0-b5:1.4
	scriptics-sc-2-0-fixed:1.4
	scriptics-sc-2-0-b2:1.4
	scriptics-sc-2-0-b1:1.4
	core-8-3-0:1.4
	core-8-3-b2:1.4
	core-8-3-b1:1.4
	scriptics-sc-1-1:1.3.6.1
	scriptics-sc-1-1-b1:1.3.6.1
	core-8-2-3:1.3.6.1
	scriptics-sc-1-1-branch:1.3.6.1.0.4
	scriptics-sc-1-1-base:1.3.6.1
	scriptics-sc-1-0:1.3.6.1
	scriptics-sc-1-0-branch:1.3.6.1.0.2
	scriptics-sc-1-0-base:1.3.6.1
	core-8-2-2:1.3.6.1
	core-8-2-1:1.3.6.1
	scriptics-bc-1-0-b1:1.3.6.1
	core-8-2-1-branch:1.3.0.6
	scriptics-tclpro-1-3-0:1.3
	core-8-2-0:1.3
	core-8-2-b3-branch:1.3.0.4
	core-8-2-b3-base:1.3
	scriptics-tclpro-1-3-b4:1.3
	core-8-2-b2:1.3
	scriptics-tclpro-1-3-b3:1.3
	core-8-2-b1:1.3
	scriptics-tclpro-1-3-b2:1.3
	merge-to-mainline-5/21/99:1.3
	scriptics-tclpro-1-3-b2-branch:1.3.0.2
	core-8-1-1:1.3
	scriptics-tclpro-1-3-b1:1.3
	core-8-1-1-base:1.3
	core-8-1-0:1.3
	merge-to-mainline-4-29-99:1.3
	merge-to-mainline-4-23-99:1.3
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.2.0.6
	core-8-0-6-base:1.2
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.6
	core-8-1-b2:1.1.4.5
	dev-8-1-stubs-branch:1.1.4.4.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.1
	core-8-0-4:1.2
	core-8-1-a2:1.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.12
date	2010.01.13.23.08.11;	author nijtmans;	state Exp;
branches;
next	1.11;

1.11
date	2007.12.13.15.28.50;	author dgp;	state Exp;
branches;
next	1.10;

1.10
date	2007.09.07.00.34.58;	author dgp;	state Exp;
branches;
next	1.9;

1.9
date	2007.04.25.17.08.51;	author hobbs;	state Exp;
branches
	1.9.2.1;
next	1.8;

1.8
date	2005.11.13.21.00.17;	author dkf;	state Exp;
branches;
next	1.7;

1.7
date	2003.11.17.23.12.44;	author hobbs;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.21.14.07.33;	author tmh;	state Exp;
branches
	1.6.4.1;
next	1.5;

1.5
date	2000.11.22.01.49.38;	author ericm;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	99.09.21.06.43.01;	author hobbs;	state Exp;
branches
	1.4.4.1;
next	1.3;

1.3
date	99.04.16.01.51.47;	author stanton;	state Exp;
branches
	1.3.6.1;
next	1.2;

1.2
date	98.09.14.18.23.57;	author stanton;	state Exp;
branches;
next	1.1;

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

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

1.1.4.2
date	99.01.07.02.42.57;	author lfb;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	99.02.13.05.38.49;	author lfb;	state Exp;
branches;
next	1.1.4.4;

1.1.4.4
date	99.02.16.06.00.09;	author lfb;	state Exp;
branches
	1.1.4.4.2.1;
next	1.1.4.5;

1.1.4.5
date	99.03.10.07.13.51;	author stanton;	state Exp;
branches;
next	1.1.4.6;

1.1.4.6
date	99.04.06.00.35.28;	author lfb;	state Exp;
branches;
next	;

1.1.4.4.2.1
date	99.03.10.02.23.07;	author redman;	state Exp;
branches;
next	;

1.3.6.1
date	99.09.22.06.53.18;	author hobbs;	state Exp;
branches;
next	;

1.4.4.1
date	2002.04.02.20.58.02;	author hobbs;	state Exp;
branches;
next	;

1.5.2.1
date	2001.07.03.20.01.10;	author dgp;	state Exp;
branches;
next	;

1.6.4.1
date	2003.11.17.23.29.36;	author hobbs;	state Exp;
branches;
next	;

1.9.2.1
date	2007.09.07.01.25.40;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.12
log
@Eliminate tkpMenubuttonClass
make tkpButtonProcs CONST
fix gcc warnings: missing initializer
@
text
@/*
 * tkUnixMenubu.c --
 *
 *	This file implements the Unix specific portion of the menubutton
 *	widget.
 *
 * 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: tkUnixMenubu.c,v 1.11 2007/12/13 15:28:50 dgp Exp $
 */

#include "tkInt.h"
#include "tkMenubutton.h"


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateMenuButton --
 *
 *	Allocate a new TkMenuButton structure.
 *
 * Results:
 *	Returns a newly allocated TkMenuButton structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkMenuButton *
TkpCreateMenuButton(
    Tk_Window tkwin)
{
    return (TkMenuButton *)ckalloc(sizeof(TkMenuButton));
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayMenuButton --
 *
 *	This function is invoked to display a menubutton widget.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands are output to X to display the menubutton in its current
 *	mode.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayMenuButton(
    ClientData clientData)	/* Information about widget. */
{
    register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
    GC gc;
    Tk_3DBorder border;
    Pixmap pixmap;
    int x = 0;			/* Initialization needed only to stop compiler
				 * warning. */
    int y = 0;
    register Tk_Window tkwin = mbPtr->tkwin;
    int fullWidth, fullHeight;
    int textXOffset, textYOffset;
    int imageWidth, imageHeight;
    int imageXOffset, imageYOffset;
    int width = 0, height = 0;
				/* Image information that will be used to
				 * restrict disabled pixmap as well */
    int haveImage = 0, haveText = 0;

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

    if ((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL)) {
	gc = mbPtr->disabledGC;
	border = mbPtr->normalBorder;
    } else if ((mbPtr->state == STATE_ACTIVE)
	       && !Tk_StrictMotif(mbPtr->tkwin)) {
	gc = mbPtr->activeTextGC;
	border = mbPtr->activeBorder;
    } else {
	gc = mbPtr->normalTextGC;
	border = mbPtr->normalBorder;
    }

    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }
    imageWidth	= width;
    imageHeight = height;

    haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0);

    /*
     * In order to avoid screen flashes, this function redraws the menu 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(mbPtr->display, Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
    Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin),
	    Tk_Height(tkwin), 0, TK_RELIEF_FLAT);

    imageXOffset = 0;
    imageYOffset = 0;
    textXOffset = 0;
    textYOffset = 0;
    fullWidth = 0;
    fullHeight = 0;

    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {
	switch ((enum compound) mbPtr->compound) {
	case COMPOUND_TOP:
	case COMPOUND_BOTTOM:
	    /*
	     * Image is above or below text.
	     */

	    if (mbPtr->compound == COMPOUND_TOP) {
		textYOffset = height + mbPtr->padY;
	    } else {
		imageYOffset = mbPtr->textHeight + mbPtr->padY;
	    }
	    fullHeight = height + mbPtr->textHeight + mbPtr->padY;
	    fullWidth = (width > mbPtr->textWidth ? width : mbPtr->textWidth);
	    textXOffset = (fullWidth - mbPtr->textWidth)/2;
	    imageXOffset = (fullWidth - width)/2;
	    break;
	case COMPOUND_LEFT:
	case COMPOUND_RIGHT:
	    /*
	     * Image is left or right of text.
	     */

	    if (mbPtr->compound == COMPOUND_LEFT) {
		textXOffset = width + mbPtr->padX;
	    } else {
		imageXOffset = mbPtr->textWidth + mbPtr->padX;
	    }
	    fullWidth = mbPtr->textWidth + mbPtr->padX + width;
	    fullHeight = (height > mbPtr->textHeight ? height :
		    mbPtr->textHeight);
	    textYOffset = (fullHeight - mbPtr->textHeight)/2;
	    imageYOffset = (fullHeight - height)/2;
	    break;
	case COMPOUND_CENTER:
	    /*
	     * Image and text are superimposed.
	     */

	    fullWidth = (width > mbPtr->textWidth ? width : mbPtr->textWidth);
	    fullHeight = (height > mbPtr->textHeight ? height :
		    mbPtr->textHeight);
	    textXOffset = (fullWidth - mbPtr->textWidth)/2;
	    imageXOffset = (fullWidth - width)/2;
	    textYOffset = (fullHeight - mbPtr->textHeight)/2;
	    imageYOffset = (fullHeight - height)/2;
	    break;
	case COMPOUND_NONE:
	    break;
	}

	TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
		mbPtr->indicatorWidth + fullWidth, fullHeight, &x, &y);

	imageXOffset += x;
	imageYOffset += y;
	if (mbPtr->image != NULL) {
	    Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
		    imageXOffset, imageYOffset);
	} else if (mbPtr->bitmap != None) {
	    XSetClipOrigin(mbPtr->display, gc, imageXOffset, imageYOffset);
	    XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
		    gc, 0, 0, (unsigned) width, (unsigned) height,
		    imageXOffset, imageYOffset, 1);
	    XSetClipOrigin(mbPtr->display, gc, 0, 0);
	}

	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x + textXOffset, y + textYOffset, 0, -1);
	Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x + textXOffset, y + textYOffset, mbPtr->underline);
    } else if (haveImage) {
	TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
		width + mbPtr->indicatorWidth, height, &x, &y);
	imageXOffset += x;
	imageYOffset += y;
	if (mbPtr->image != NULL) {
	    Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
		    imageXOffset, imageYOffset);
	} else if (mbPtr->bitmap != None) {
	    XSetClipOrigin(mbPtr->display, gc, x, y);
	    XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
		    gc, 0, 0, (unsigned) width, (unsigned) height,
		    x, y, 1);
	    XSetClipOrigin(mbPtr->display, gc, 0, 0);
	}
    } else {
	TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
		mbPtr->textWidth + mbPtr->indicatorWidth,
		mbPtr->textHeight, &x, &y);
	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x + textXOffset, y + textYOffset, 0, -1);
	Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc,
		mbPtr->textLayout, x + textXOffset, y + textYOffset,
		mbPtr->underline);
    }

    /*
     * If the menu button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect.
     */

    if ((mbPtr->state == STATE_DISABLED)
	    && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) {
	/*
	 * Stipple the whole button if no disabledFg was specified, otherwise
	 * restrict stippling only to displayed image
	 */

	if (mbPtr->disabledFg == NULL) {
	    XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC,
		    mbPtr->inset, mbPtr->inset,
		    (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset),
		    (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset));
	} else {
	    XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC,
		    imageXOffset, imageYOffset,
		    (unsigned) imageWidth, (unsigned) imageHeight);
	}
    }

    /*
     * Draw the cascade indicator for the menu button on the right side of the
     * window, if desired.
     */

    if (mbPtr->indicatorOn) {
	int borderWidth;

	borderWidth = (mbPtr->indicatorHeight+1)/3;
	if (borderWidth < 1) {
	    borderWidth = 1;
	}
	/*y += mbPtr->textHeight / 2;*/
	Tk_Fill3DRectangle(tkwin, pixmap, border,
		Tk_Width(tkwin) - mbPtr->inset - mbPtr->indicatorWidth
		+ mbPtr->indicatorHeight,
		((int) (Tk_Height(tkwin) - mbPtr->indicatorHeight))/2,
		mbPtr->indicatorWidth - 2*mbPtr->indicatorHeight,
		mbPtr->indicatorHeight, borderWidth, TK_RELIEF_RAISED);
    }

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

    if (mbPtr->relief != TK_RELIEF_FLAT) {
	Tk_Draw3DRectangle(tkwin, pixmap, border,
		mbPtr->highlightWidth, mbPtr->highlightWidth,
		Tk_Width(tkwin) - 2*mbPtr->highlightWidth,
		Tk_Height(tkwin) - 2*mbPtr->highlightWidth,
		mbPtr->borderWidth, mbPtr->relief);
    }
    if (mbPtr->highlightWidth != 0) {
	GC gc;

	if (mbPtr->flags & GOT_FOCUS) {
	    gc = Tk_GCForColor(mbPtr->highlightColorPtr, pixmap);
	} else {
	    gc = Tk_GCForColor(mbPtr->highlightBgColorPtr, pixmap);
	}
	Tk_DrawFocusHighlight(tkwin, gc, mbPtr->highlightWidth, pixmap);
    }

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

    XCopyArea(mbPtr->display, pixmap, Tk_WindowId(tkwin),
	    mbPtr->normalTextGC, 0, 0, (unsigned) Tk_Width(tkwin),
	    (unsigned) Tk_Height(tkwin), 0, 0);
    Tk_FreePixmap(mbPtr->display, pixmap);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyMenuButton --
 *
 *	Free data structures associated with the menubutton control.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Restores the default control state.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyMenuButton(
    TkMenuButton *mbPtr)
{
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeMenuButtonGeometry --
 *
 *	After changes in a menu button's text or bitmap, this function
 *	recomputes the menu button's geometry and passes this information
 *	along to the geometry manager for the window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The menu button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeMenuButtonGeometry(
    TkMenuButton *mbPtr)	/* Widget record for menu button. */
{
    int width, height, mm, pixels;
    int	 avgWidth, txtWidth, txtHeight;
    int haveImage = 0, haveText = 0;
    Tk_FontMetrics fm;

    mbPtr->inset = mbPtr->highlightWidth + mbPtr->borderWidth;

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

    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }

    if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(mbPtr->textLayout);

	mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text,
		-1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth,
		&mbPtr->textHeight);
	txtWidth = mbPtr->textWidth;
	txtHeight = mbPtr->textHeight;
	avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(mbPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
    }

    /*
     * If the menubutton 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 menubutton has both text and an
     * image, because otherwise it is not really a compound menubutton.
     */

    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {
	switch ((enum compound) mbPtr->compound) {
	case COMPOUND_TOP:
	case COMPOUND_BOTTOM:
	    /*
	     * Image is above or below text.
	     */

	    height += txtHeight + mbPtr->padY;
	    width = (width > txtWidth ? width : txtWidth);
	    break;
	case COMPOUND_LEFT:
	case COMPOUND_RIGHT:
	    /*
	     * Image is left or right of text.
	     */

	    width += txtWidth + mbPtr->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 (mbPtr->width > 0) {
	    width = mbPtr->width;
	}
	if (mbPtr->height > 0) {
	    height = mbPtr->height;
	}
	width += 2*mbPtr->padX;
	height += 2*mbPtr->padY;
    } else {
	if (haveImage) {
	    if (mbPtr->width > 0) {
		width = mbPtr->width;
	    }
	    if (mbPtr->height > 0) {
		height = mbPtr->height;
	    }
	} else {
	    width = txtWidth;
	    height = txtHeight;
	    if (mbPtr->width > 0) {
		width = mbPtr->width * avgWidth;
	    }
	    if (mbPtr->height > 0) {
		height = mbPtr->height * fm.linespace;
	    }
	}
    }

    if (! haveImage) {
	width += 2*mbPtr->padX;
	height += 2*mbPtr->padY;
    }

    if (mbPtr->indicatorOn) {
	mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
	pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
	mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm);
	mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm)
		+ 2*mbPtr->indicatorHeight;
	width += mbPtr->indicatorWidth;
    } else {
	mbPtr->indicatorHeight = 0;
	mbPtr->indicatorWidth = 0;
    }

    Tk_GeometryRequest(mbPtr->tkwin, (int) (width + 2*mbPtr->inset),
	    (int) (height + 2*mbPtr->inset));
    Tk_SetInternalBorder(mbPtr->tkwin, mbPtr->inset);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.11
log
@merge stable branch onto HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.9.2.1 2007/09/07 01:25:40 dgp Exp $
a17 9
/*
 * The structure below defines menubutton class behavior by means of functions
 * that can be invoked from generic window code.
 */

Tk_ClassProcs tkpMenubuttonClass = {
    sizeof(Tk_ClassProcs),	/* size */
    TkMenuButtonWorldChanged,	/* worldChangedProc */
};
@


1.10
log
@header cleanup
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.9 2007/04/25 17:08:51 hobbs Exp $
@


1.9
log
@	* unix/tkUnixMenubu.c (TkpDisplayMenuButton): init width/height to 0
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.8 2005/11/13 21:00:17 dkf Exp $
d15 1
@


1.9.2.1
log
@merge updates from HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.9 2007/04/25 17:08:51 hobbs Exp $
a14 1
#include "tkInt.h"
@


1.8
log
@ANSIfy
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.7 2003/11/17 23:12:44 hobbs Exp $
d79 1
a79 1
    int width, height, fullWidth, fullHeight;
d83 1
@


1.7
log
@	* generic/tkMenubutton.h: fixed compound menubutton handling like
	* generic/tkMenubutton.c: *button corrections of 2003-04-25.
	* mac/tkMacMenubutton.c (TkpDisplayMenuButton):
	* unix/tkUnixMenubu.c (TkpDisplayMenuButton):
@
text
@d1 1
a1 1
/* 
d4 2
a5 2
 *	This file implements the Unix specific portion of the
 *	menubutton widget.
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.6 2001/05/21 14:07:33 tmh Exp $
d18 2
a19 2
 * The structure below defines menubutton class behavior by means of
 * procedures that can be invoked from generic window code.
d44 2
a45 2
TkpCreateMenuButton(tkwin)
    Tk_Window tkwin;
d55 1
a55 1
 *	This procedure is invoked to display a menubutton widget.
d61 2
a62 2
 *	Commands are output to X to display the menubutton in its
 *	current mode.
d68 2
a69 2
TkpDisplayMenuButton(clientData)
    ClientData clientData;	/* Information about widget. */
d75 2
a76 2
    int x = 0;			/* Initialization needed only to stop
				 * compiler warning. */
d82 3
a84 2
    int imageXOffset, imageYOffset; /* image information that will be used to
				     * restrict disabled pixmap as well */
d111 1
a111 1
    imageWidth  = width;
d117 4
a120 4
     * In order to avoid screen flashes, this procedure redraws
     * the menu 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.
d136 50
a185 45
        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                if (mbPtr->compound == COMPOUND_TOP) {
                    textYOffset = height + mbPtr->padY;
                } else {
                    imageYOffset = mbPtr->textHeight + mbPtr->padY;
                }
                fullHeight = height + mbPtr->textHeight + mbPtr->padY;
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                if (mbPtr->compound == COMPOUND_LEFT) {
                    textXOffset = width + mbPtr->padX;
                } else {
                    imageXOffset = mbPtr->textWidth + mbPtr->padX;
                }
                fullWidth = mbPtr->textWidth + mbPtr->padX + width;
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_CENTER: {
                /* Image and text are superimposed */
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_NONE: {break;}
        }
d187 1
a187 1
        TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
d198 1
a198 1
		    gc, 0, 0, (unsigned) width, (unsigned) height, 
d218 1
a218 1
		    gc, 0, 0, (unsigned) width, (unsigned) height, 
d226 1
a226 1
	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
d238 2
a239 2
    if ((mbPtr->state == STATE_DISABLED) 
            && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) {
d241 2
a242 2
	 * Stipple the whole button if no disabledFg was specified,
	 * otherwise restrict stippling only to displayed image
d244 1
d258 2
a259 2
     * Draw the cascade indicator for the menu button on the
     * right side of the window, if desired.
d279 3
a281 3
     * Draw the border and traversal highlight last.  This way, if the
     * menu button's contents overflow onto the border they'll be covered
     * up by the border.
d303 2
a304 2
     * Copy the information from the off-screen pixmap onto the screen,
     * then delete the pixmap.
d330 2
a331 2
TkpDestroyMenuButton(mbPtr)
    TkMenuButton *mbPtr;
d340 1
a340 1
 *	After changes in a menu button's text or bitmap, this procedure
d354 2
a355 2
TkpComputeMenuButtonGeometry(mbPtr)
    TkMenuButton *mbPtr;	/* Widget record for menu button. */
d358 1
a358 1
    int  avgWidth, txtWidth, txtHeight;
d386 3
a388 3
        avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(mbPtr->tkfont, &fm);
        haveText = (txtWidth != 0 && txtHeight != 0);
d393 3
a395 3
     * the new geometry is a combination of the image and text geometry.
     * We only honor the compound bit if the menubutton has both text and
     * an image, because otherwise it is not really a compound menubutton.
d399 38
a436 31
        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                height += txtHeight + mbPtr->padY;
                width = (width > txtWidth ? width : txtWidth);
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                width += txtWidth + mbPtr->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 (mbPtr->width > 0) {
            width = mbPtr->width;
        }
        if (mbPtr->height > 0) {
            height = mbPtr->height;
        }
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
d439 6
a444 6
            if (mbPtr->width > 0) {
                width = mbPtr->width;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height;
            }
d448 6
a453 6
            if (mbPtr->width > 0) {
                width = mbPtr->width * avgWidth;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height * fm.linespace;
            }
d458 2
a459 2
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
d463 6
a468 6
        mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
        pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
        mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm);
        mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm)
    	    + 2*mbPtr->indicatorHeight;
        width += mbPtr->indicatorWidth;
d470 2
a471 2
        mbPtr->indicatorHeight = 0;
        mbPtr->indicatorWidth = 0;
d478 8
@


1.6
log
@implement TIP11, -compound option for menubutton widget
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.5 2000/11/22 01:49:38 ericm Exp $
d80 4
a83 1
    int imageXOffset, imageYOffset, textXOffset, textYOffset;
d110 3
a134 1

d182 1
a182 2
                mbPtr->indicatorWidth + fullWidth, fullHeight,
		&x, &y);
d184 32
a215 17
        if (mbPtr->image != NULL) {
            Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                    x + imageXOffset, y + imageYOffset);
        }
        if (mbPtr->bitmap != None) {
            XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                    gc, 0, 0, (unsigned) width, (unsigned) height, 
		    x + imageXOffset, y + imageYOffset, 1);
        }
        if (haveText) {
            Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		    x  + textXOffset, y + textYOffset ,
                    0, -1);
            Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		    mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		    mbPtr->underline);
        }
d217 8
a224 22
       if (mbPtr->image != NULL) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                   x + imageXOffset, y + imageYOffset);
       } else if (mbPtr->bitmap != None) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                   gc, 0, 0, (unsigned) width, (unsigned) height, 
		   x + imageXOffset, y + imageYOffset, 1);
       } else {
           TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
                   mbPtr->textWidth + mbPtr->indicatorWidth,
                   mbPtr->textHeight, &x, &y);
           Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		   x  + textXOffset, y + textYOffset ,
                   0, -1);
           Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		   mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		   mbPtr->underline);
        }
d234 14
a247 4
	XFillRectangle(mbPtr->display, pixmap, mbPtr->disabledGC,
		mbPtr->inset, mbPtr->inset,
		(unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset),
		(unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset));
@


1.6.4.1
log
@	* generic/tkMenubutton.h: fixed compound menubutton handling like
	* generic/tkMenubutton.c: *button corrections of 2003-04-25.
	* mac/tkMacMenubutton.c (TkpDisplayMenuButton):
	* unix/tkUnixMenubu.c (TkpDisplayMenuButton):
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.7 2003/11/17 23:12:44 hobbs Exp $
d80 1
a80 4
    int textXOffset, textYOffset;
    int imageWidth, imageHeight;
    int imageXOffset, imageYOffset; /* image information that will be used to
				     * restrict disabled pixmap as well */
a106 3
    imageWidth  = width;
    imageHeight = height;

d129 1
d177 2
a178 1
		mbPtr->indicatorWidth + fullWidth, fullHeight, &x, &y);
d180 17
a196 32
	imageXOffset += x;
	imageYOffset += y;
	if (mbPtr->image != NULL) {
	    Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
		    imageXOffset, imageYOffset);
	} else if (mbPtr->bitmap != None) {
	    XSetClipOrigin(mbPtr->display, gc, imageXOffset, imageYOffset);
	    XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
		    gc, 0, 0, (unsigned) width, (unsigned) height, 
		    imageXOffset, imageYOffset, 1);
	    XSetClipOrigin(mbPtr->display, gc, 0, 0);
	}

	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x + textXOffset, y + textYOffset, 0, -1);
	Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x + textXOffset, y + textYOffset, mbPtr->underline);
    } else if (haveImage) {
	TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
		width + mbPtr->indicatorWidth, height, &x, &y);
	imageXOffset += x;
	imageYOffset += y;
	if (mbPtr->image != NULL) {
	    Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
		    imageXOffset, imageYOffset);
	} else if (mbPtr->bitmap != None) {
	    XSetClipOrigin(mbPtr->display, gc, x, y);
	    XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
		    gc, 0, 0, (unsigned) width, (unsigned) height, 
		    x, y, 1);
	    XSetClipOrigin(mbPtr->display, gc, 0, 0);
	}
d198 22
a219 8
	TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
		mbPtr->textWidth + mbPtr->indicatorWidth,
		mbPtr->textHeight, &x, &y);
	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		x + textXOffset, y + textYOffset, 0, -1);
	Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc,
		mbPtr->textLayout, x + textXOffset, y + textYOffset,
		mbPtr->underline);
d229 4
a232 14
	/*
	 * Stipple the whole button if no disabledFg was specified,
	 * otherwise restrict stippling only to displayed image
	 */
	if (mbPtr->disabledFg == NULL) {
	    XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC,
		    mbPtr->inset, mbPtr->inset,
		    (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset),
		    (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset));
	} else {
	    XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC,
		    imageXOffset, imageYOffset,
		    (unsigned) imageWidth, (unsigned) imageHeight);
	}
@


1.5
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: tkUnixMenubu.c,v 1.4 1999/09/21 06:43:01 hobbs Exp $
d77 1
a77 1
    int y;
d79 3
a81 1
    int width, height;
d100 9
d121 76
a196 20
    /*
     * Display image or bitmap or text for button.
     */

    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);

	imageOrBitmap:
	TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, 
		width + mbPtr->indicatorWidth, height, &x, &y);
	if (mbPtr->image != NULL) {
	    Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
		    x, y);
	} else {
	    XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
		    gc, 0, 0, (unsigned) width, (unsigned) height, x, y, 1);
	}
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	goto imageOrBitmap;
d198 22
a219 7
	TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
		mbPtr->textWidth + mbPtr->indicatorWidth,
		mbPtr->textHeight, &x, &y);
	Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, x, y,
		0, -1);
	Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout,
		x, y, mbPtr->underline);
d336 3
d341 7
d350 1
a350 6
	if (mbPtr->width > 0) {
	    width = mbPtr->width;
	}
	if (mbPtr->height > 0) {
	    height = mbPtr->height;
	}
d353 4
a356 7
	if (mbPtr->width > 0) {
	    width = mbPtr->width;
	}
	if (mbPtr->height > 0) {
	    height = mbPtr->height;
	}
    } else {
d358 1
d362 63
a424 4
	width = mbPtr->textWidth;
	height = mbPtr->textHeight;
	if (mbPtr->width > 0) {
	    width = mbPtr->width * Tk_TextWidth(mbPtr->tkfont, "0", 1);
d426 1
a426 2
	if (mbPtr->height > 0) {
	    Tk_FontMetrics fm;
d428 3
a430 5
	    Tk_GetFontMetrics(mbPtr->tkfont, &fm);
	    height = mbPtr->height * fm.linespace;
	}
	width += 2*mbPtr->padX;
	height += 2*mbPtr->padY;
d434 6
a439 6
	mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
	pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
	mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm);
	mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm)
		+ 2*mbPtr->indicatorHeight;
	width += mbPtr->indicatorWidth;
d441 2
a442 2
	mbPtr->indicatorHeight = 0;
	mbPtr->indicatorWidth = 0;
@


1.5.2.1
log
@        * Merged in updates from HEAD branch.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.6 2001/05/21 14:07:33 tmh Exp $
d77 1
a77 1
    int y = 0;
d79 1
a79 3
    int width, height, fullWidth, fullHeight;
    int imageXOffset, imageYOffset, textXOffset, textYOffset;
    int haveImage = 0, haveText = 0;
a97 9
    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }
    haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0);

d110 20
a129 76
    imageXOffset = 0;
    imageYOffset = 0;
    textXOffset = 0;
    textYOffset = 0;
    fullWidth = 0;
    fullHeight = 0;

    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {

        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                if (mbPtr->compound == COMPOUND_TOP) {
                    textYOffset = height + mbPtr->padY;
                } else {
                    imageYOffset = mbPtr->textHeight + mbPtr->padY;
                }
                fullHeight = height + mbPtr->textHeight + mbPtr->padY;
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                if (mbPtr->compound == COMPOUND_LEFT) {
                    textXOffset = width + mbPtr->padX;
                } else {
                    imageXOffset = mbPtr->textWidth + mbPtr->padX;
                }
                fullWidth = mbPtr->textWidth + mbPtr->padX + width;
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_CENTER: {
                /* Image and text are superimposed */
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_NONE: {break;}
        }

        TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                mbPtr->indicatorWidth + fullWidth, fullHeight,
		&x, &y);

        if (mbPtr->image != NULL) {
            Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                    x + imageXOffset, y + imageYOffset);
        }
        if (mbPtr->bitmap != None) {
            XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                    gc, 0, 0, (unsigned) width, (unsigned) height, 
		    x + imageXOffset, y + imageYOffset, 1);
        }
        if (haveText) {
            Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		    x  + textXOffset, y + textYOffset ,
                    0, -1);
            Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		    mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		    mbPtr->underline);
        }
d131 7
a137 22
       if (mbPtr->image != NULL) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                   x + imageXOffset, y + imageYOffset);
       } else if (mbPtr->bitmap != None) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                   gc, 0, 0, (unsigned) width, (unsigned) height, 
		   x + imageXOffset, y + imageYOffset, 1);
       } else {
           TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
                   mbPtr->textWidth + mbPtr->indicatorWidth,
                   mbPtr->textHeight, &x, &y);
           Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		   x  + textXOffset, y + textYOffset ,
                   0, -1);
           Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		   mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		   mbPtr->underline);
        }
a253 3
    int  avgWidth, txtWidth, txtHeight;
    int haveImage = 0, haveText = 0;
    Tk_FontMetrics fm;
a255 7

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

d258 6
a263 1
	haveImage = 1;
d266 7
a272 4
	haveImage = 1;
    }

    if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) {
a273 1

d277 7
a283 13
	txtWidth = mbPtr->textWidth;
	txtHeight = mbPtr->textHeight;
        avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(mbPtr->tkfont, &fm);
        haveText = (txtWidth != 0 && txtHeight != 0);
    }

    /*
     * If the menubutton 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 menubutton has both text and
     * an image, because otherwise it is not really a compound menubutton.
     */
d285 2
a286 49
    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                height += txtHeight + mbPtr->padY;
                width = (width > txtWidth ? width : txtWidth);
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                width += txtWidth + mbPtr->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 (mbPtr->width > 0) {
            width = mbPtr->width;
        }
        if (mbPtr->height > 0) {
            height = mbPtr->height;
        }
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
    } else {
	if (haveImage) {
            if (mbPtr->width > 0) {
                width = mbPtr->width;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height;
            }
	} else {
	    width = txtWidth;
	    height = txtHeight;
            if (mbPtr->width > 0) {
                width = mbPtr->width * avgWidth;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height * fm.linespace;
            }
d288 2
a289 5
    }

    if (! haveImage) {
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
d293 6
a298 6
        mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
        pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
        mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm);
        mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm)
    	    + 2*mbPtr->indicatorHeight;
        width += mbPtr->indicatorWidth;
d300 2
a301 2
        mbPtr->indicatorHeight = 0;
        mbPtr->indicatorWidth = 0;
@


1.4
log
@1999-09-16  Jeff Hobbs  <hobbs@@scriptics.com>

	* generic/tkFont.c: fixed processing of font options and error
	returned [Bug: 2075]

	* win/tkWinWm.c: fixed bug in 'wm deiconify' that raised the
	wrong toplevel, and changed it to not set focus on overridden
	toplevels

1999-09-15  Jeff Hobbs  <hobbs@@scriptics.com>

	* unix/aclocal.m4: added fix for FreeBSD-[1-2] recognition [Bug: 2070]
	and fix to AIX-* to get ldAix right [Bug: 2624], fixed AIX
	version check (readjust from 8-21 fix) and several other config
	fixes for AIX
	* mac/tkMacMenubutton.c:
	* unix/tkUnixMenubu.c: fixed permanently stippled menubutton image
	* win/tkWinButton.c: fixed possible pointer smash [Bug: 2733]

1999-09-14  Jeff Hobbs  <hobbs@@scriptics.com>

	* win/tkWinMenu.c: fix for stack overrun in GetTextFace [Bug: 909]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.3 1999/04/16 01:51:47 stanton Exp $
d22 3
a24 4
TkClassProcs tkpMenubuttonClass = {
    NULL,			/* createProc. */
    TkMenuButtonWorldChanged,	/* geometryProc. */
    NULL			/* modalProc. */
@


1.4.4.1
log
@sync with head
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.6 2001/05/21 14:07:33 tmh Exp $
d22 4
a25 3
Tk_ClassProcs tkpMenubuttonClass = {
    sizeof(Tk_ClassProcs),	/* size */
    TkMenuButtonWorldChanged,	/* worldChangedProc */
d78 1
a78 1
    int y = 0;
d80 1
a80 3
    int width, height, fullWidth, fullHeight;
    int imageXOffset, imageYOffset, textXOffset, textYOffset;
    int haveImage = 0, haveText = 0;
a98 9
    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }
    haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0);

d111 20
a130 76
    imageXOffset = 0;
    imageYOffset = 0;
    textXOffset = 0;
    textYOffset = 0;
    fullWidth = 0;
    fullHeight = 0;

    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {

        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                if (mbPtr->compound == COMPOUND_TOP) {
                    textYOffset = height + mbPtr->padY;
                } else {
                    imageYOffset = mbPtr->textHeight + mbPtr->padY;
                }
                fullHeight = height + mbPtr->textHeight + mbPtr->padY;
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                if (mbPtr->compound == COMPOUND_LEFT) {
                    textXOffset = width + mbPtr->padX;
                } else {
                    imageXOffset = mbPtr->textWidth + mbPtr->padX;
                }
                fullWidth = mbPtr->textWidth + mbPtr->padX + width;
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_CENTER: {
                /* Image and text are superimposed */
                fullWidth = (width > mbPtr->textWidth ? width :
                        mbPtr->textWidth);
                fullHeight = (height > mbPtr->textHeight ? height :
                        mbPtr->textHeight);
                textXOffset = (fullWidth - mbPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                textYOffset = (fullHeight - mbPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_NONE: {break;}
        }

        TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                mbPtr->indicatorWidth + fullWidth, fullHeight,
		&x, &y);

        if (mbPtr->image != NULL) {
            Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                    x + imageXOffset, y + imageYOffset);
        }
        if (mbPtr->bitmap != None) {
            XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                    gc, 0, 0, (unsigned) width, (unsigned) height, 
		    x + imageXOffset, y + imageYOffset, 1);
        }
        if (haveText) {
            Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		    x  + textXOffset, y + textYOffset ,
                    0, -1);
            Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		    mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		    mbPtr->underline);
        }
d132 7
a138 22
       if (mbPtr->image != NULL) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap,
                   x + imageXOffset, y + imageYOffset);
       } else if (mbPtr->bitmap != None) {
           TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0,
                   width + mbPtr->indicatorWidth, height, &x, &y);
           XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap,
                   gc, 0, 0, (unsigned) width, (unsigned) height, 
		   x + imageXOffset, y + imageYOffset, 1);
       } else {
           TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY,
                   mbPtr->textWidth + mbPtr->indicatorWidth,
                   mbPtr->textHeight, &x, &y);
           Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, 
		   x  + textXOffset, y + textYOffset ,
                   0, -1);
           Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, 
		   mbPtr->textLayout, x + textXOffset, y + textYOffset ,
		   mbPtr->underline);
        }
a254 3
    int  avgWidth, txtWidth, txtHeight;
    int haveImage = 0, haveText = 0;
    Tk_FontMetrics fm;
a256 7

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

d259 6
a264 1
	haveImage = 1;
d267 7
a273 4
	haveImage = 1;
    }

    if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) {
a274 1

d278 7
a284 13
	txtWidth = mbPtr->textWidth;
	txtHeight = mbPtr->textHeight;
        avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(mbPtr->tkfont, &fm);
        haveText = (txtWidth != 0 && txtHeight != 0);
    }

    /*
     * If the menubutton 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 menubutton has both text and
     * an image, because otherwise it is not really a compound menubutton.
     */
d286 2
a287 49
    if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        switch ((enum compound) mbPtr->compound) {
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /* Image is above or below text */
                height += txtHeight + mbPtr->padY;
                width = (width > txtWidth ? width : txtWidth);
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /* Image is left or right of text */
                width += txtWidth + mbPtr->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 (mbPtr->width > 0) {
            width = mbPtr->width;
        }
        if (mbPtr->height > 0) {
            height = mbPtr->height;
        }
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
    } else {
	if (haveImage) {
            if (mbPtr->width > 0) {
                width = mbPtr->width;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height;
            }
	} else {
	    width = txtWidth;
	    height = txtHeight;
            if (mbPtr->width > 0) {
                width = mbPtr->width * avgWidth;
            }
            if (mbPtr->height > 0) {
                height = mbPtr->height * fm.linespace;
            }
d289 2
a290 5
    }

    if (! haveImage) {
        width += 2*mbPtr->padX;
        height += 2*mbPtr->padY;
d294 6
a299 6
        mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin));
        pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin));
        mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm);
        mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm)
    	    + 2*mbPtr->indicatorHeight;
        width += mbPtr->indicatorWidth;
d301 2
a302 2
        mbPtr->indicatorHeight = 0;
        mbPtr->indicatorWidth = 0;
@


1.3
log
@* Merged 8.1 branch into the main trunk
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d146 2
a147 2
    if (((mbPtr->state == STATE_DISABLED) 
            && (mbPtr->disabledFg == NULL)) || (mbPtr->image != NULL)) {
@


1.3.6.1
log
@1999-09-21  Jeff Hobbs  <hobbs@@scriptics.com>

	* generic/tkFont.c: fixed processing of font options and error
	returned [Bug: 2075]

	* win/tkWinWm.c: fixed bug in 'wm deiconify' that raised the
	wrong toplevel, and changed it to not set focus on overridden
	toplevels

	* unix/aclocal.m4: added fix for FreeBSD-[1-2] recognition [Bug: 2070]
	and fix to AIX-* to get ldAix right [Bug: 2624], fixed AIX
	version check and several other config fixes for AIX

	* mac/tkMacMenubutton.c:
	* unix/tkUnixMenubu.c: fixed permanently stippled menubutton image
	* win/tkWinButton.c: fixed possible pointer smash [Bug: 2733]

	* win/tkWinMenu.c: fix for stack overrun in GetTextFace [Bug: 909]

	* unix/tkUnixDraw.c: fixed header style for TkpDrawHighlightBorder

	* generic/tkCanvas.c: fixed GC error (bg <> fg) in tkCanvas.c
	(from code added to support TkpDrawHighlightBorder) [Bug: 2676]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.3 1999/04/16 01:51:47 stanton Exp $
d146 2
a147 2
    if ((mbPtr->state == STATE_DISABLED) 
            && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) {
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d87 1
a87 1
    if ((mbPtr->state == tkDisabledUid) && (mbPtr->disabledFg != NULL)) {
d90 2
a91 1
    } else if ((mbPtr->state == tkActiveUid) && !Tk_StrictMotif(mbPtr->tkwin)) {
d146 2
a147 2
    if ((mbPtr->state == tkDisabledUid)
	    && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) {
d252 1
a252 1
    register TkMenuButton *mbPtr;	/* Widget record for menu button. */
@


1.1
log
@Initial revision
@
text
@d12 1
a12 1
 * SCCS: @@(#) tkUnixMenubu.c 1.9 97/05/23 16:25:01
@


1.1.4.1
log
@Merged 8.0.3 changes into 8.1
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.2 1998/09/14 18:23:57 stanton Exp $
@


1.1.4.2
log
@Removed perky gloabal Tk_Uids causing concurrency problems.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.1 1998/09/30 02:19:20 stanton Exp $
d87 1
a87 1
    if ((mbPtr->state == TK_STATE_DISABLED) && (mbPtr->disabledFg != NULL)) {
d90 1
a90 2
    } else if ((mbPtr->state == TK_STATE_ACTIVE) 
            && !Tk_StrictMotif(mbPtr->tkwin)) {
d145 1
a145 1
    if ((mbPtr->state == TK_STATE_DISABLED)
@


1.1.4.3
log
@Removed Tk_Uids from Menubutton widget.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.2 1999/01/07 02:42:57 lfb Exp $
d87 1
a87 2
    if ((mbPtr->state[0] == 'd') && (strcmp(mbPtr->state, "disabled") == 0)
            && (mbPtr->disabledFg != NULL)) {
d90 1
a90 2
    } else if ((mbPtr->state[0] == 'a') 
            && (strcmp(mbPtr->state, "active") == 0)
d146 1
a146 1
    if ((mbPtr->state[0] == 'd') && (strcmp(mbPtr->state, "disabled") ==0)
@


1.1.4.4
log
@Change defaults used by Menubuttons to reflect TK_OPTION interface.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.3 1999/02/13 05:38:49 lfb Exp $
d87 2
a88 1
    if (mbPtr->state == STATE_DISABLED && mbPtr->disabledFg != NULL) {
d91 3
a93 2
    } else if (mbPtr->state == STATE_ACTIVE 
	       && !Tk_StrictMotif(mbPtr->tkwin)) {
d148 2
a149 2
    if ((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL) 
	    || (mbPtr->image != NULL)) {
d254 1
a254 1
    TkMenuButton *mbPtr;	/* Widget record for menu button. */
@


1.1.4.5
log
@integrated stubs from development branch
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.4 1999/02/16 06:00:09 lfb Exp $
d146 1
a146 1
    if (((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL) )
@


1.1.4.6
log
@Fixed Bug #1703: menubutton uses same fg and bg when disabled.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.5 1999/03/10 07:13:51 stanton Exp $
d87 1
a87 1
    if ((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL)) {
d90 1
a90 1
    } else if ((mbPtr->state == STATE_ACTIVE)
d146 2
a147 2
    if (((mbPtr->state == STATE_DISABLED) 
            && (mbPtr->disabledFg == NULL)) || (mbPtr->image != NULL)) {
@


1.1.4.4.2.1
log
@merge 8.0.6 code for stubs into 8.1 for UNIX
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnixMenubu.c,v 1.1.4.4 1999/02/16 06:00:09 lfb Exp $
d146 1
a146 1
    if (((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL) )
@


