diff options
author | hobbs <hobbs@noemail.net> | 2003-04-26 02:59:18 (GMT) |
---|---|---|
committer | hobbs <hobbs@noemail.net> | 2003-04-26 02:59:18 (GMT) |
commit | c693b7ffb71f6d8dff81a25c6c0f8dff937859d7 (patch) | |
tree | 566771aaa15411ffcc5ed06c7d1055c573128211 | |
parent | 6d0f80f42b127461746da9bd8d8cd9486fa67cb0 (diff) | |
download | tk-c693b7ffb71f6d8dff81a25c6c0f8dff937859d7.zip tk-c693b7ffb71f6d8dff81a25c6c0f8dff937859d7.tar.gz tk-c693b7ffb71f6d8dff81a25c6c0f8dff937859d7.tar.bz2 |
* 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.
FossilOrigin-Name: 73a68cb246afc06ae2a91782ef3cf9f5854d1674
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | generic/tkButton.c | 34 | ||||
-rw-r--r-- | generic/tkButton.h | 12 | ||||
-rw-r--r-- | mac/tkMacButton.c | 56 | ||||
-rw-r--r-- | macosx/tkMacOSXButton.c | 97 | ||||
-rw-r--r-- | unix/tkUnixButton.c | 63 | ||||
-rw-r--r-- | win/tkWinButton.c | 73 |
7 files changed, 205 insertions, 139 deletions
@@ -1,5 +1,14 @@ 2003-04-25 Jeff Hobbs <jeffh@ActiveState.com> + * 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. + * library/bgerror.tcl: make bgerror dialog topmost on Windows to prevent it being covered by other windows. diff --git a/generic/tkButton.c b/generic/tkButton.c index 07e226b..640921f 100644 --- a/generic/tkButton.c +++ b/generic/tkButton.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkButton.c,v 1.20 2002/08/08 09:35:34 hobbs Exp $ + * RCS: @(#) $Id: tkButton.c,v 1.21 2003/04/26 02:59:20 hobbs Exp $ */ #include "tkButton.h" @@ -699,6 +699,7 @@ ButtonCreate(clientData, interp, objc, objv, type) butPtr->normalTextGC = None; butPtr->activeTextGC = None; butPtr->disabledGC = None; + butPtr->stippleGC = None; butPtr->gray = None; butPtr->copyGC = None; butPtr->widthPtr = NULL; @@ -980,6 +981,9 @@ DestroyButton(butPtr) if (butPtr->disabledGC != None) { Tk_FreeGC(butPtr->display, butPtr->disabledGC); } + if (butPtr->stippleGC != None) { + Tk_FreeGC(butPtr->display, butPtr->stippleGC); + } if (butPtr->gray != None) { Tk_FreeBitmap(butPtr->display, butPtr->gray); } @@ -1337,20 +1341,15 @@ TkButtonWorldChanged(instanceData) butPtr->activeTextGC = newGC; } + gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel; + /* - * Allocate the disabled graphics context, for drawing the widget in - * its disabled state + * Create the GC that can be used for stippling */ - gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel; - if ((butPtr->disabledFg != NULL) && (butPtr->imagePtr == NULL)) { - gcValues.foreground = butPtr->disabledFg->pixel; - mask = GCForeground | GCBackground | GCFont; - } else { + + if (butPtr->stippleGC == None) { gcValues.foreground = gcValues.background; mask = GCForeground; - if (butPtr->compound != COMPOUND_NONE) { - mask |= GCFont; - } if (butPtr->gray == None) { butPtr->gray = Tk_GetBitmap(NULL, butPtr->tkwin, "gray50"); } @@ -1359,6 +1358,19 @@ TkButtonWorldChanged(instanceData) gcValues.stipple = butPtr->gray; mask |= GCFillStyle | GCStipple; } + butPtr->stippleGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues); + } + + /* + * Allocate the disabled graphics context, for drawing text in + * its disabled state. + */ + + mask = GCForeground | GCBackground | GCFont; + if (butPtr->disabledFg != NULL) { + gcValues.foreground = butPtr->disabledFg->pixel; + } else { + gcValues.foreground = gcValues.background; } newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues); if (butPtr->disabledGC != None) { diff --git a/generic/tkButton.h b/generic/tkButton.h index be195c6..d3f7cfa 100644 --- a/generic/tkButton.h +++ b/generic/tkButton.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: tkButton.h,v 1.9 2002/06/17 10:54:29 drh Exp $ + * RCS: @(#) $Id: tkButton.h,v 1.10 2003/04/26 02:59:20 hobbs Exp $ */ #ifndef _TKBUTTON @@ -159,12 +159,10 @@ typedef struct { * screen. */ GC activeTextGC; /* GC for drawing text in active mode (NULL * means use normalTextGC). */ - 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. For labels this is None. */ + GC disabledGC; /* Used to produce disabled effect for text + * and check/radio marks. */ + GC stippleGC; /* Used to produce disabled stipple effect + * for images when disabled. */ Pixmap gray; /* Pixmap for displaying disabled text if * disabledFg is NULL. */ GC copyGC; /* Used for copying information from an diff --git a/mac/tkMacButton.c b/mac/tkMacButton.c index 2c11dba..95fd029 100644 --- a/mac/tkMacButton.c +++ b/mac/tkMacButton.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: tkMacButton.c,v 1.17 2002/08/28 01:08:06 drh Exp $ + * RCS: @(#) $Id: tkMacButton.c,v 1.18 2003/04/26 02:59:20 hobbs Exp $ */ #include "tkButton.h" @@ -168,7 +168,7 @@ TkpDisplayButton( int y, relief; register Tk_Window tkwin = butPtr->tkwin; int width, height, fullWidth, fullHeight; - int imageXOffset, imageYOffset, textXOffset, textYOffset; + 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 @@ -179,6 +179,10 @@ TkpDisplayButton( 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); @@ -339,11 +343,11 @@ TkpDisplayButton( Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); haveImage = 1; } - haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); + imageWidth = width; + imageHeight = height; + haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { - imageXOffset = 0; - imageYOffset = 0; textXOffset = 0; textYOffset = 0; fullWidth = 0; @@ -409,25 +413,23 @@ TkpDisplayButton( 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, x + imageXOffset, - y + imageYOffset); + width, height, pixmap, imageXOffset, imageYOffset); } else { Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, x + imageXOffset, - y + imageYOffset); + height, pixmap, imageXOffset, imageYOffset); } } else { - XSetClipOrigin(butPtr->display, gc, x + imageXOffset, - y + imageYOffset); + XSetClipOrigin(butPtr->display, gc, + imageXOffset, imageYOffset); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, - 0, 0, (unsigned int) width, - (unsigned int) height, x + imageXOffset, - y + imageYOffset, 1); + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); XSetClipOrigin(butPtr->display, gc, 0, 0); } @@ -452,6 +454,8 @@ TkpDisplayButton( x += offset; y += offset; } + imageXOffset += x; + imageXOffset += y; if (butPtr->image != NULL) { if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { @@ -488,23 +492,31 @@ TkpDisplayButton( * 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. + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->selectBorder)->pixel); } - XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC, - butPtr->inset, butPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*butPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*butPtr->inset)); + /* + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->normalBorder)->pixel); } } diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 6314535..deddfa6 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.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: tkMacOSXButton.c,v 1.2 2002/08/31 06:12:29 das Exp $ + * RCS: @(#) $Id: tkMacOSXButton.c,v 1.3 2003/04/26 02:59:20 hobbs Exp $ */ #include "tkButton.h" @@ -33,10 +33,10 @@ * 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 +#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 /* * Declaration of Mac specific button structure. @@ -47,18 +47,18 @@ typedef struct { SInt16 minValue; SInt16 maxValue; SInt16 procID; - int isBevel; + int isBevel; } MacControlParams; typedef struct { int drawType; Tk_3DBorder border; int relief; - int offset; /* 0 means this is a normal widget. 1 means - * it is an image button, so we offset the - * image to make the button appear to move - * up and down as the relief changes. */ - GC gc; + int offset; /* 0 means this is a normal widget. 1 means + * it is an image button, so we offset the + * image to make the button appear to move + * up and down as the relief changes. */ + GC gc; int hasImageOrBitmap; } DrawParams; @@ -201,12 +201,16 @@ TkpDisplayButton( * compiler warning. */ int y; int width, height, fullWidth, fullHeight; - int imageXOffset, imageYOffset, textXOffset, textYOffset; + int textXOffset, textYOffset; int haveImage = 0, haveText = 0; GWorldPtr destPort; int borderWidth; Pixmap pixmap; int wasUsingControl; + int imageWidth, imageHeight; + int imageXOffset = 0, imageYOffset = 0; /* image information that will + * be used to restrict disabled + * pixmap as well */ DrawParams drawParams, * dpPtr = &drawParams; butPtr->flags &= ~REDRAW_PENDING; @@ -291,10 +295,11 @@ TkpDisplayButton( 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) { - imageXOffset = 0; - imageYOffset = 0; textXOffset = 0; textYOffset = 0; fullWidth = 0; @@ -366,29 +371,27 @@ TkpDisplayButton( x += dpPtr->offset; y += dpPtr->offset; } - + imageXOffset += x; + imageYOffset += y; if (butPtr->image != NULL) { if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { Tk_RedrawImage(butPtr->selectImage, 0, 0, - width, height, pixmap, x + imageXOffset, - y + imageYOffset); + width, height, pixmap, imageXOffset, imageYOffset); } else { Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, x + imageXOffset, - y + imageYOffset); + height, pixmap, imageXOffset, imageYOffset); } } else { - XSetClipOrigin(butPtr->display, dpPtr->gc, x + imageXOffset, - y + imageYOffset); + XSetClipOrigin(butPtr->display, dpPtr->gc, + imageXOffset, imageYOffset); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc, - 0, 0, (unsigned int) width, - (unsigned int) height, x + imageXOffset, - y + imageYOffset, 1); + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } - - if (macButtonPtr->useTkText ) { + + if (macButtonPtr->useTkText) { Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); @@ -403,7 +406,7 @@ TkpDisplayButton( TkComputeAnchor(butPtr->anchor, tkwin, 0, 0, butPtr->indicatorSpace + width, height, &x, &y); x += butPtr->indicatorSpace; - + x += dpPtr->offset; y += dpPtr->offset; if (dpPtr->relief == TK_RELIEF_RAISED) { @@ -413,17 +416,18 @@ TkpDisplayButton( x += dpPtr->offset; y += dpPtr->offset; } + imageXOffset += x; + imageXOffset += y; if (butPtr->image != NULL) { if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { Tk_RedrawImage(butPtr->selectImage, 0, 0, width, - height, pixmap, x, y); + height, pixmap, x, y); } else { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, x, y); } } else { - XSetClipOrigin(butPtr->display, dpPtr->gc, x, y); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc, @@ -453,28 +457,37 @@ TkpDisplayButton( * 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. + * must temporarily modify the GC so the stippling is the right color. */ if (macButtonPtr->useTkText) { if ((butPtr->state == STATE_DISABLED) && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) { if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn - && (butPtr->selectBorder != NULL)) { - XSetForeground(butPtr->display, butPtr->disabledGC, - Tk_3DBorderColor(butPtr->selectBorder)->pixel); + && (butPtr->selectBorder != NULL)) { + XSetForeground(butPtr->display, butPtr->stippledGC, + Tk_3DBorderColor(butPtr->selectBorder)->pixel); } - XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC, - butPtr->inset, butPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*butPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*butPtr->inset)); + /* + * 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->disabledGC, - Tk_3DBorderColor(butPtr->normalBorder)->pixel); - } + && (butPtr->selectBorder != NULL)) { + XSetForeground(butPtr->display, butPtr->stippledGC, + 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. diff --git a/unix/tkUnixButton.c b/unix/tkUnixButton.c index ae2feae..35f6adf 100644 --- a/unix/tkUnixButton.c +++ b/unix/tkUnixButton.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: tkUnixButton.c,v 1.12 2003/04/25 20:03:43 hobbs Exp $ + * RCS: @(#) $Id: tkUnixButton.c,v 1.13 2003/04/26 02:59:20 hobbs Exp $ */ #include "tkButton.h" @@ -86,12 +86,16 @@ TkpDisplayButton(clientData) int y, relief; Tk_Window tkwin = butPtr->tkwin; int width, height, fullWidth, fullHeight; - int imageXOffset, imageYOffset, textXOffset, textYOffset; + int textXOffset, textYOffset; int haveImage = 0, haveText = 0; int offset; /* 1 means this is a button widget, so we * offset the text to make the button appear * to move up and down as the relief changes. */ + int imageWidth, imageHeight; + int imageXOffset = 0, imageYOffset = 0; /* image information that will + * be used to restrict disabled + * pixmap as well */ butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { @@ -176,11 +180,12 @@ TkpDisplayButton(clientData) 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) { - imageXOffset = 0; - imageYOffset = 0; textXOffset = 0; textYOffset = 0; fullWidth = 0; @@ -246,33 +251,29 @@ TkpDisplayButton(clientData) 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, x + imageXOffset, - y + imageYOffset); + width, height, pixmap, imageXOffset, imageYOffset); } else { Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, x + imageXOffset, y + imageYOffset); + height, pixmap, imageXOffset, imageYOffset); } } else { - XSetClipOrigin(butPtr->display, gc, x + imageXOffset, - y + imageYOffset); + XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, - 0, 0, (unsigned int) width, - (unsigned int) height, x + imageXOffset, - y + imageYOffset, 1); + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); XSetClipOrigin(butPtr->display, gc, 0, 0); } - /* - * Use normalTextGC in this case since we have both text and image, - * the whole button will later be stippled 50% grey. - */ - Tk_DrawTextLayout(butPtr->display, pixmap, butPtr->normalTextGC, + Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); - Tk_UnderlineTextLayout(butPtr->display, pixmap, butPtr->normalTextGC, + Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, x + textXOffset, y + textYOffset, butPtr->underline); y += fullHeight/2; @@ -291,6 +292,8 @@ TkpDisplayButton(clientData) x += offset; y += offset; } + imageXOffset += x; + imageXOffset += y; if (butPtr->image != NULL) { if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { @@ -427,23 +430,31 @@ TkpDisplayButton(clientData) * 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. + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->selectBorder)->pixel); } - XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC, - butPtr->inset, butPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*butPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*butPtr->inset)); + /* + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->normalBorder)->pixel); } } diff --git a/win/tkWinButton.c b/win/tkWinButton.c index 5552b1e..2a9ddda 100644 --- a/win/tkWinButton.c +++ b/win/tkWinButton.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: tkWinButton.c,v 1.21 2003/04/25 20:03:44 hobbs Exp $ + * RCS: @(#) $Id: tkWinButton.c,v 1.22 2003/04/26 02:59:20 hobbs Exp $ */ #define OEMRESOURCE @@ -355,6 +355,10 @@ TkpDisplayButton(clientData) * move up and down as the relief changes. */ int textXOffset = 0, textYOffset = 0; /* text offsets for use with * compound buttons and focus ring */ + int imageWidth, imageHeight; + int imageXOffset = 0, imageYOffset = 0; /* image information that will + * be used to restrict disabled + * pixmap as well */ DWORD *boxesPalette; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) @@ -459,15 +463,13 @@ TkpDisplayButton(clientData) 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) { - int imageXOffset, imageYOffset, fullWidth, fullHeight; - imageXOffset = 0; - imageYOffset = 0; - fullWidth = 0; - fullHeight = 0; + int fullWidth = 0, fullHeight = 0; switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: @@ -522,33 +524,27 @@ TkpDisplayButton(clientData) 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, x + imageXOffset, - y + imageYOffset); + width, height, pixmap, imageXOffset, imageYOffset); } else { - Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, x + imageXOffset, y + imageYOffset); + Tk_RedrawImage(butPtr->image, 0, 0, + width, height, pixmap, imageXOffset, imageYOffset); } } else { - XSetClipOrigin(butPtr->display, gc, x + imageXOffset, - y + imageYOffset); + XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, - 0, 0, (unsigned int) width, - (unsigned int) height, x + imageXOffset, - y + imageYOffset, 1); + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); XSetClipOrigin(butPtr->display, gc, 0, 0); } - /* - * Use normalTextGC in this case since we have both text and image, - * the whole button will later be stippled 50% grey. - */ - Tk_DrawTextLayout(butPtr->display, pixmap, butPtr->normalTextGC, + Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); - Tk_UnderlineTextLayout(butPtr->display, pixmap, butPtr->normalTextGC, + Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, x + textXOffset, y + textYOffset, butPtr->underline); height = fullHeight; @@ -563,6 +559,8 @@ TkpDisplayButton(clientData) x += offset; y += offset; } + imageXOffset += x; + imageXOffset += y; if (butPtr->image != NULL) { if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { @@ -578,7 +576,6 @@ TkpDisplayButton(clientData) (unsigned int) width, (unsigned int) height, x, y, 1); XSetClipOrigin(butPtr->display, gc, 0, 0); } - } else { TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, butPtr->indicatorSpace + butPtr->textWidth, @@ -656,7 +653,13 @@ TkpDisplayButton(clientData) * be placed into the palette. */ - boxesPalette[PAL_CHECK] = FlipColor(gc->foreground); + if ((butPtr->state == STATE_DISABLED) + && (butPtr->disabledFg == NULL)) { + boxesPalette[PAL_CHECK] = FlipColor(TkWinGetBorderPixels(tkwin, + border, TK_3D_DARK_GC)); + } else { + boxesPalette[PAL_CHECK] = FlipColor(gc->foreground); + } boxesPalette[PAL_TOP_OUTER] = FlipColor(TkWinGetBorderPixels(tkwin, border, TK_3D_DARK_GC)); boxesPalette[PAL_TOP_INNER] = FlipColor(TkWinGetBorderPixels(tkwin, @@ -689,23 +692,31 @@ TkpDisplayButton(clientData) * 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. + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->selectBorder)->pixel); } - XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC, - butPtr->inset, butPtr->inset, - (unsigned) (Tk_Width(tkwin) - 2*butPtr->inset), - (unsigned) (Tk_Height(tkwin) - 2*butPtr->inset)); + /* + * 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->disabledGC, + XSetForeground(butPtr->display, butPtr->stippleGC, Tk_3DBorderColor(butPtr->normalBorder)->pixel); } } |