summaryrefslogtreecommitdiffstats
path: root/mac
diff options
context:
space:
mode:
authortmh <tmh>2001-05-21 14:07:32 (GMT)
committertmh <tmh>2001-05-21 14:07:32 (GMT)
commit29e6415ec425f744f1595e852af0c922a09258bb (patch)
tree20838e3aece8170aafef73f9007c1064480550df /mac
parent234f863650b0b7804c98c2994e07e9ef354b0e92 (diff)
downloadtk-29e6415ec425f744f1595e852af0c922a09258bb.zip
tk-29e6415ec425f744f1595e852af0c922a09258bb.tar.gz
tk-29e6415ec425f744f1595e852af0c922a09258bb.tar.bz2
implement TIP11, -compound option for menubutton widget
Diffstat (limited to 'mac')
-rw-r--r--mac/tkMacMenubutton.c118
1 files changed, 116 insertions, 2 deletions
diff --git a/mac/tkMacMenubutton.c b/mac/tkMacMenubutton.c
index 4c274e6..1acc521 100644
--- a/mac/tkMacMenubutton.c
+++ b/mac/tkMacMenubutton.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: tkMacMenubutton.c,v 1.7 2000/11/22 01:49:38 ericm Exp $
+ * RCS: @(#) $Id: tkMacMenubutton.c,v 1.8 2001/05/21 14:07:33 tmh Exp $
*/
#include "tkMenubutton.h"
@@ -92,7 +92,9 @@ TkpDisplayMenuButton(
* compiler warning. */
int y;
Tk_Window tkwin = mbPtr->tkwin;
- int width, height;
+ int width, height, fullWidth, fullHeight;
+ int imageXOffset, imageYOffset, textXOffset, textYOffset;
+ int haveImage = 0, haveText = 0;
MacMenuButton * macMBPtr = (MacMenuButton *) mbPtr;
GWorldPtr destPort;
CGrafPtr saveWorld;
@@ -119,6 +121,15 @@ TkpDisplayMenuButton(
}
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;
+ }
+ haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0);
+
/*
* In order to avoid screen flashes, this procedure redraws
* the menu button in a pixmap, then copies the pixmap to the
@@ -129,6 +140,108 @@ TkpDisplayMenuButton(
Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), 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);
+
+ if (mbPtr->image != NULL) {
+ Tk_RedrawImage(mbPtr->image, 0, 0, width, height, Tk_WindowId(tkwin),
+ x + imageXOffset, y + imageYOffset);
+ }
+ 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);
+ }
+ } 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);
+ }
+ }
+
+#if 0 /* this is the original code */
/*
* Display image or bitmap or text for button.
*/
@@ -156,6 +269,7 @@ TkpDisplayMenuButton(
Tk_DrawTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc,
mbPtr->textLayout, x, y, 0, -1);
}
+#endif
/*
* If the menu button is disabled with a stipple rather than a special