From 3d4310e751a063d749094f93cefd45289e283509 Mon Sep 17 00:00:00 2001 From: hobbs Date: Mon, 17 Nov 2003 23:12:43 +0000 Subject: * 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): --- ChangeLog | 7 ++++ generic/tkMenubutton.c | 37 ++++++++++++----- generic/tkMenubutton.h | 11 ++--- mac/tkMacMenubutton.c | 98 ++++++++++++++++++++++++------------------- unix/tkUnixMenubu.c | 111 ++++++++++++++++++++++++++++--------------------- 5 files changed, 155 insertions(+), 109 deletions(-) diff --git a/ChangeLog b/ChangeLog index e697084..a9662ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-11-17 Jeff Hobbs + + * 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): + 2003-11-16 Don Porter * win/makefile.vc: Restored consistency of pkgIndex.tcl file diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c index 0d22be5..504495a 100644 --- a/generic/tkMenubutton.c +++ b/generic/tkMenubutton.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMenubutton.c,v 1.12 2002/08/05 04:30:40 dgp Exp $ + * RCS: @(#) $Id: tkMenubutton.c,v 1.13 2003/11/17 23:12:44 hobbs Exp $ */ #include "tkMenubutton.h" @@ -276,6 +276,7 @@ Tk_MenubuttonObjCmd(clientData, interp, objc, objv) mbPtr->activeTextGC = None; mbPtr->gray = None; mbPtr->disabledGC = None; + mbPtr->stippleGC = None; mbPtr->leftBearing = 0; mbPtr->rightBearing = 0; mbPtr->widthString = NULL; @@ -451,14 +452,16 @@ DestroyMenuButton(memPtr) if (mbPtr->disabledGC != None) { Tk_FreeGC(mbPtr->display, mbPtr->disabledGC); } + if (mbPtr->stippleGC != None) { + Tk_FreeGC(mbPtr->display, mbPtr->stippleGC); + } if (mbPtr->gray != None) { Tk_FreeBitmap(mbPtr->display, mbPtr->gray); } if (mbPtr->textLayout != NULL) { Tk_FreeTextLayout(mbPtr->textLayout); } - Tk_FreeConfigOptions((char *) mbPtr, mbPtr->optionTable, - mbPtr->tkwin); + Tk_FreeConfigOptions((char *) mbPtr, mbPtr->optionTable, mbPtr->tkwin); mbPtr->tkwin = NULL; Tcl_EventuallyFree((ClientData) mbPtr, TCL_DYNAMIC); } @@ -702,7 +705,6 @@ TkMenuButtonWorldChanged(instanceData) } mbPtr->normalTextGC = gc; - gcValues.font = Tk_FontId(mbPtr->tkfont); gcValues.foreground = mbPtr->activeFg->pixel; gcValues.background = Tk_3DBorderColor(mbPtr->activeBorder)->pixel; mask = GCForeground | GCBackground | GCFont; @@ -712,23 +714,36 @@ TkMenuButtonWorldChanged(instanceData) } mbPtr->activeTextGC = gc; - gcValues.font = Tk_FontId(mbPtr->tkfont); gcValues.background = Tk_3DBorderColor(mbPtr->normalBorder)->pixel; - if ((mbPtr->disabledFg != NULL) && (mbPtr->imageString == NULL)) { - gcValues.foreground = mbPtr->disabledFg->pixel; - mask = GCForeground | GCBackground | GCFont; - } else { + + /* + * Create the GC that can be used for stippling + */ + + if (mbPtr->stippleGC == None) { gcValues.foreground = gcValues.background; mask = GCForeground; if (mbPtr->gray == None) { - mbPtr->gray = Tk_GetBitmap(NULL, mbPtr->tkwin, - Tk_GetUid("gray50")); + mbPtr->gray = Tk_GetBitmap(NULL, mbPtr->tkwin, "gray50"); } if (mbPtr->gray != None) { gcValues.fill_style = FillStippled; gcValues.stipple = mbPtr->gray; mask |= GCFillStyle | GCStipple; } + mbPtr->stippleGC = Tk_GetGC(mbPtr->tkwin, mask, &gcValues); + } + + /* + * Allocate the disabled graphics context, for drawing text in + * its disabled state. + */ + + mask = GCForeground | GCBackground | GCFont; + if (mbPtr->disabledFg != NULL) { + gcValues.foreground = mbPtr->disabledFg->pixel; + } else { + gcValues.foreground = gcValues.background; } gc = Tk_GetGC(mbPtr->tkwin, mask, &gcValues); if (mbPtr->disabledGC != None) { diff --git a/generic/tkMenubutton.h b/generic/tkMenubutton.h index 332d770..d41e64e 100644 --- a/generic/tkMenubutton.h +++ b/generic/tkMenubutton.h @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMenubutton.h,v 1.8 2001/10/12 13:30:31 tmh Exp $ + * RCS: @(#) $Id: tkMenubutton.h,v 1.9 2003/11/17 23:12:44 hobbs Exp $ */ #ifndef _TKMENUBUTTON @@ -124,12 +124,9 @@ typedef struct { * means use normalTextGC). */ Pixmap gray; /* Pixmap for displaying disabled text/icon if * disabledFg is NULL. */ - GC disabledGC; /* Used to produce disabled effect. If - * disabledFg isn't NULL, this GC is used to - * draw button text or icon. Otherwise - * text or icon is drawn with normalGC and - * this GC is used to stipple background - * across it. */ + GC disabledGC; /* Used to produce disabled effect for text. */ + GC stippleGC; /* Used to produce disabled stipple effect + * for images when disabled. */ int leftBearing; /* Distance from text origin to leftmost drawn * pixel (positive means to right). */ int rightBearing; /* Amount text sticks right from its origin. */ diff --git a/mac/tkMacMenubutton.c b/mac/tkMacMenubutton.c index 7cdb16a..07a4c43 100644 --- a/mac/tkMacMenubutton.c +++ b/mac/tkMacMenubutton.c @@ -9,17 +9,17 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacMenubutton.c,v 1.9 2001/10/12 13:30:31 tmh Exp $ + * RCS: @(#) $Id: tkMacMenubutton.c,v 1.10 2003/11/17 23:12:44 hobbs Exp $ */ #include "tkMenubutton.h" #include "tkMacInt.h" #include -#define kShadowOffset (3) /* amount to offset shadow from frame */ -#define kTriangleWidth (11) /* width of the triangle */ -#define kTriangleHeight (6) /* height of the triangle */ -#define kTriangleMargin (5) /* margin around triangle */ +#define kShadowOffset (3) /* amount to offset shadow from frame */ +#define kTriangleWidth (11) /* width of the triangle */ +#define kTriangleHeight (6) /* height of the triangle */ +#define kTriangleMargin (5) /* margin around triangle */ /* * Declaration of Unix specific button structure. @@ -93,6 +93,7 @@ TkpDisplayMenuButton( int y; Tk_Window tkwin = mbPtr->tkwin; int width, height, fullWidth, fullHeight; + int imageWidth, imageHeight; int imageXOffset, imageYOffset, textXOffset, textYOffset; int haveImage = 0, haveText = 0; MacMenuButton * macMBPtr = (MacMenuButton *) mbPtr; @@ -128,6 +129,9 @@ TkpDisplayMenuButton( Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); haveImage = 1; } + imageWidth = width; + imageHeight = height; + haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0); /* @@ -199,46 +203,44 @@ TkpDisplayMenuButton( mbPtr->indicatorWidth + fullWidth, fullHeight, &x, &y); + imageXOffset += x; + imageYOffset += y; if (mbPtr->image != NULL) { Tk_RedrawImage(mbPtr->image, 0, 0, width, height, Tk_WindowId(tkwin), - x + imageXOffset, y + imageYOffset); - } - if (mbPtr->bitmap != None) { + imageXOffset, imageYOffset); + } else if (mbPtr->bitmap != None) { XCopyPlane(mbPtr->display, mbPtr->bitmap, Tk_WindowId(tkwin), gc, 0, 0, (unsigned) width, (unsigned) height, - x + imageXOffset, y + imageYOffset, 1); - } - if (haveText) { - Tk_DrawTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, - mbPtr->textLayout, x + textXOffset, y + textYOffset , - 0, -1); - Tk_UnderlineTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, - mbPtr->textLayout, x + textXOffset, y + textYOffset , - mbPtr->underline); + imageXOffset, imageYOffset, 1); } + + Tk_DrawTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, + mbPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); + Tk_UnderlineTextLayout(mbPtr->display, Tk_WindowId(tkwin), 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, Tk_WindowId(tkwin), + imageXOffset, imageYOffset); + } else if (mbPtr->bitmap != None) { + XCopyPlane(mbPtr->display, mbPtr->bitmap, Tk_WindowId(tkwin), + gc, 0, 0, (unsigned) width, (unsigned) height, + x, y, 1); + } } else { - if (mbPtr->image != NULL) { - TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, - width + mbPtr->indicatorWidth, height, &x, &y); - Tk_RedrawImage(mbPtr->image, 0, 0, width, height, Tk_WindowId(tkwin), - 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, Tk_WindowId(tkwin), - 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, Tk_WindowId(tkwin), gc, - mbPtr->textLayout, x + textXOffset, y + textYOffset, - 0, -1); - Tk_UnderlineTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, - mbPtr->textLayout, x + textXOffset, y + textYOffset , - mbPtr->underline); - } + TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY, + mbPtr->textWidth + mbPtr->indicatorWidth, + mbPtr->textHeight, &x, &y); + Tk_DrawTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, + mbPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); + Tk_UnderlineTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, + mbPtr->textLayout, x + textXOffset, y + textYOffset, + mbPtr->underline); } #if 0 /* this is the original code */ @@ -278,10 +280,20 @@ TkpDisplayMenuButton( if ((mbPtr->state == STATE_DISABLED) && ((mbPtr->disabledFg != NULL) || (mbPtr->image != NULL))) { - XFillRectangle(mbPtr->display, Tk_WindowId(tkwin), - mbPtr->disabledGC, mbPtr->inset, mbPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); + /* + * Stipple the whole button if no disabledFg was specified, + * otherwise restrict stippling only to displayed image + */ + if (mbPtr->disabledFg == NULL) { + XFillRectangle(mbPtr->display, Tk_WindowId(tkwin), + mbPtr->stippleGC, mbPtr->inset, mbPtr->inset, + (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), + (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); + } else { + XFillRectangle(mbPtr->display, Tk_WindowId(tkwin), + mbPtr->stippleGC, imageXOffset, imageYOffset, + (unsigned) imageWidth, (unsigned) imageHeight); + } } /* diff --git a/unix/tkUnixMenubu.c b/unix/tkUnixMenubu.c index 186bd75..cdcc31c 100644 --- a/unix/tkUnixMenubu.c +++ b/unix/tkUnixMenubu.c @@ -9,7 +9,7 @@ * 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.6 2001/05/21 14:07:33 tmh Exp $ + * RCS: @(#) $Id: tkUnixMenubu.c,v 1.7 2003/11/17 23:12:44 hobbs Exp $ */ #include "tkMenubutton.h" @@ -77,7 +77,10 @@ TkpDisplayMenuButton(clientData) int y = 0; register Tk_Window tkwin = mbPtr->tkwin; int width, height, fullWidth, fullHeight; - int imageXOffset, imageYOffset, textXOffset, textYOffset; + int textXOffset, textYOffset; + int imageWidth, imageHeight; + int imageXOffset, imageYOffset; /* image information that will be used to + * restrict disabled pixmap as well */ int haveImage = 0, haveText = 0; mbPtr->flags &= ~REDRAW_PENDING; @@ -104,6 +107,9 @@ TkpDisplayMenuButton(clientData) Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); haveImage = 1; } + imageWidth = width; + imageHeight = height; + haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0); /* @@ -126,7 +132,6 @@ TkpDisplayMenuButton(clientData) fullHeight = 0; if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) { - switch ((enum compound) mbPtr->compound) { case COMPOUND_TOP: case COMPOUND_BOTTOM: { @@ -174,49 +179,49 @@ TkpDisplayMenuButton(clientData) } TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, - mbPtr->indicatorWidth + fullWidth, fullHeight, - &x, &y); + 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); + } - 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); - } + 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 { - 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); - } + 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); } /* @@ -226,10 +231,20 @@ TkpDisplayMenuButton(clientData) if ((mbPtr->state == STATE_DISABLED) && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) { - XFillRectangle(mbPtr->display, pixmap, mbPtr->disabledGC, - mbPtr->inset, mbPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); + /* + * 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); + } } /* -- cgit v0.12