diff options
Diffstat (limited to 'unix/tkUnixMenubu.c')
-rw-r--r-- | unix/tkUnixMenubu.c | 326 |
1 files changed, 176 insertions, 150 deletions
diff --git a/unix/tkUnixMenubu.c b/unix/tkUnixMenubu.c index 35c7da8..48d3fb9 100644 --- a/unix/tkUnixMenubu.c +++ b/unix/tkUnixMenubu.c @@ -1,25 +1,28 @@ -/* +/* * tkUnixMenubu.c -- * - * This file implements the Unix specific portion of the - * menubutton widget. + * 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. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#include "tkInt.h" #include "tkMenubutton.h" /* - * The structure below defines menubutton class behavior by means of - * procedures that can be invoked from generic window code. + * 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 */ + NULL, + NULL }; /* @@ -39,8 +42,8 @@ Tk_ClassProcs tkpMenubuttonClass = { */ TkMenuButton * -TkpCreateMenuButton(tkwin) - Tk_Window tkwin; +TkpCreateMenuButton( + Tk_Window tkwin) { return (TkMenuButton *)ckalloc(sizeof(TkMenuButton)); } @@ -50,35 +53,37 @@ TkpCreateMenuButton(tkwin) * * TkpDisplayMenuButton -- * - * This procedure is invoked to display a menubutton widget. + * 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. + * Commands are output to X to display the menubutton in its current + * mode. * *---------------------------------------------------------------------- */ void -TkpDisplayMenuButton(clientData) - ClientData clientData; /* Information about widget. */ +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 x = 0; /* Initialization needed only to stop compiler + * warning. */ int y = 0; register Tk_Window tkwin = mbPtr->tkwin; - int width, height, fullWidth, fullHeight; + int fullWidth, fullHeight; int textXOffset, textYOffset; int imageWidth, imageHeight; - int imageXOffset, imageYOffset; /* image information that will be used to - * restrict disabled pixmap as well */ + 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; @@ -105,16 +110,16 @@ TkpDisplayMenuButton(clientData) Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); haveImage = 1; } - imageWidth = width; + imageWidth = width; imageHeight = height; 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 - * screen in a single operation. This means that there's no - * point in time where the on-sreen image has been cleared. + * 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), @@ -130,53 +135,58 @@ TkpDisplayMenuButton(clientData) 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, + 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; @@ -187,7 +197,7 @@ TkpDisplayMenuButton(clientData) } else if (mbPtr->bitmap != None) { XSetClipOrigin(mbPtr->display, gc, imageXOffset, imageYOffset); XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, - gc, 0, 0, (unsigned) width, (unsigned) height, + gc, 0, 0, (unsigned) width, (unsigned) height, imageXOffset, imageYOffset, 1); XSetClipOrigin(mbPtr->display, gc, 0, 0); } @@ -207,7 +217,7 @@ TkpDisplayMenuButton(clientData) } else if (mbPtr->bitmap != None) { XSetClipOrigin(mbPtr->display, gc, x, y); XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, - gc, 0, 0, (unsigned) width, (unsigned) height, + gc, 0, 0, (unsigned) width, (unsigned) height, x, y, 1); XSetClipOrigin(mbPtr->display, gc, 0, 0); } @@ -215,7 +225,7 @@ TkpDisplayMenuButton(clientData) TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY, mbPtr->textWidth + mbPtr->indicatorWidth, mbPtr->textHeight, &x, &y); - Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, + 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, @@ -227,12 +237,13 @@ TkpDisplayMenuButton(clientData) * foreground color, generate the stippled effect. */ - if ((mbPtr->state == STATE_DISABLED) - && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) { + 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 + * 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, @@ -246,8 +257,8 @@ TkpDisplayMenuButton(clientData) } /* - * Draw the cascade indicator for the menu button on the - * right side of the window, if desired. + * Draw the cascade indicator for the menu button on the right side of the + * window, if desired. */ if (mbPtr->indicatorOn) { @@ -267,9 +278,9 @@ TkpDisplayMenuButton(clientData) } /* - * 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. + * 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) { @@ -291,8 +302,8 @@ TkpDisplayMenuButton(clientData) } /* - * Copy the information from the off-screen pixmap onto the screen, - * then delete the pixmap. + * Copy the information from the off-screen pixmap onto the screen, then + * delete the pixmap. */ XCopyArea(mbPtr->display, pixmap, Tk_WindowId(tkwin), @@ -318,8 +329,8 @@ TkpDisplayMenuButton(clientData) */ void -TkpDestroyMenuButton(mbPtr) - TkMenuButton *mbPtr; +TkpDestroyMenuButton( + TkMenuButton *mbPtr) { } @@ -328,7 +339,7 @@ TkpDestroyMenuButton(mbPtr) * * TkpComputeMenuButtonGeometry -- * - * After changes in a menu button's text or bitmap, this procedure + * 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. * @@ -342,11 +353,11 @@ TkpDestroyMenuButton(mbPtr) */ void -TkpComputeMenuButtonGeometry(mbPtr) - TkMenuButton *mbPtr; /* Widget record for menu button. */ +TkpComputeMenuButtonGeometry( + TkMenuButton *mbPtr) /* Widget record for menu button. */ { int width, height, mm, pixels; - int avgWidth, txtWidth, txtHeight; + int avgWidth, txtWidth, txtHeight; int haveImage = 0, haveText = 0; Tk_FontMetrics fm; @@ -374,88 +385,103 @@ TkpComputeMenuButtonGeometry(mbPtr) &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); + 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. + * 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; + 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; - } + 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 (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; + 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; + 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; + 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: + */ |