diff options
author | tmh <tmh> | 2001-10-12 13:30:31 (GMT) |
---|---|---|
committer | tmh <tmh> | 2001-10-12 13:30:31 (GMT) |
commit | 343a12a735abd601b4cd5c087be337a51851adb6 (patch) | |
tree | f0a41bc451b44d520db4074ba5b826c8c8d8b723 /win | |
parent | 93e8dfc4adffc6846037794671ceec5d52fda96c (diff) | |
download | tk-343a12a735abd601b4cd5c087be337a51851adb6.zip tk-343a12a735abd601b4cd5c087be337a51851adb6.tar.gz tk-343a12a735abd601b4cd5c087be337a51851adb6.tar.bz2 |
implementation of TIP 63 (accepted) -compound option to menu items.macosx_8_4_branchpoint
Diffstat (limited to 'win')
-rw-r--r-- | win/makefile.vc | 11 | ||||
-rw-r--r-- | win/tkWinDefault.h | 3 | ||||
-rw-r--r-- | win/tkWinMenu.c | 168 | ||||
-rw-r--r-- | win/tkWinWm.c | 6 |
4 files changed, 157 insertions, 31 deletions
diff --git a/win/makefile.vc b/win/makefile.vc index 48fc1e0..efde149 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -7,7 +7,7 @@ # Copyright (c) 1998-2000 Ajuba Solutions. # Copyright (c) 2001 ActiveState Corporation. # -# RCS: @(#) $Id: makefile.vc,v 1.41 2001/10/01 21:04:37 hobbs Exp $ +# RCS: @(#) $Id: makefile.vc,v 1.42 2001/10/12 13:30:32 tmh Exp $ # Does not depend on the presence of any environment variables in # order to compile tcl; all needed information is derived from @@ -52,12 +52,12 @@ lib32 = "$(TOOLS32)\bin\Win64\lib.exe" !ELSE # Visual Studio 5 default -#TOOLS32 = C:\Progra~1\devstudio\vc -#TOOLS32_rc = C:\Progra~1\devstudio\sharedide +TOOLS32 = C:\Progra~1\devstudio\vc +TOOLS32_rc = C:\Progra~1\devstudio\sharedide # Visual Studio 6 default -TOOLS32 = C:\Progra~1\Microsoft Visual Studio\VC98 -TOOLS32_rc = C:\Progra~1\Microsoft Visual Studio\common\MSDev98 +#TOOLS32 = C:\Progra~1\Microsoft Visual Studio\VC98 +#TOOLS32_rc = C:\Progra~1\Microsoft Visual Studio\common\MSDev98 cc32 = "$(TOOLS32)\bin\cl.exe" link32 = "$(TOOLS32)\bin\link.exe" @@ -77,6 +77,7 @@ NODEBUG = 1 # uncomment the following two lines to compile with TCL_MEM_DEBUG #DEBUGDEFINES =-DTCL_MEM_DEBUG +#DEBUGDEFINES = -DTCL_MEM_DEBUG -DUSE_TCLALLOC=0 -DPURIFY ###################################################################### # Do not modify below this line diff --git a/win/tkWinDefault.h b/win/tkWinDefault.h index b1ea6cb..d1d1286 100644 --- a/win/tkWinDefault.h +++ b/win/tkWinDefault.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: tkWinDefault.h,v 1.10 2001/09/26 21:36:19 pspjuth Exp $ + * RCS: @(#) $Id: tkWinDefault.h,v 1.11 2001/10/12 13:30:32 tmh Exp $ */ #ifndef _TKWINDEFAULT @@ -250,6 +250,7 @@ #define DEF_MENU_ENTRY_BITMAP None #define DEF_MENU_ENTRY_COLUMN_BREAK "0" #define DEF_MENU_ENTRY_COMMAND (char *) NULL +#define DEF_MENU_ENTRY_COMPOUND "none" #define DEF_MENU_ENTRY_FG (char *) NULL #define DEF_MENU_ENTRY_FONT (char *) NULL #define DEF_MENU_ENTRY_HIDE_MARGIN "0" diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c index 3108ccc..f612690 100644 --- a/win/tkWinMenu.c +++ b/win/tkWinMenu.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: tkWinMenu.c,v 1.15 2001/09/21 21:34:10 hobbs Exp $ + * RCS: @(#) $Id: tkWinMenu.c,v 1.16 2001/10/12 13:30:32 tmh Exp $ */ #define OEMRESOURCE @@ -1889,7 +1889,6 @@ TkpInitializeMenuBindings(interp, bindingTable) * *---------------------------------------------------------------------- */ - static void DrawMenuEntryLabel( TkMenu *menuPtr, /* The menu we are drawing */ @@ -1903,46 +1902,122 @@ DrawMenuEntryLabel( int width, /* width of entry */ int height) /* height of entry */ { - int baseline; int indicatorSpace = mePtr->indicatorSpace; int activeBorderWidth; int leftEdge; int imageHeight, imageWidth; + int textHeight, textWidth; + int haveImage = 0, haveText = 0; + int imageXOffset = 0, imageYOffset = 0; + int textXOffset = 0, textYOffset = 0; Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin, menuPtr->activeBorderWidthPtr, &activeBorderWidth); leftEdge = x + indicatorSpace + activeBorderWidth; /* - * Draw label or bitmap or image for entry. + * Work out what we will need to draw first. */ - baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2; if (mePtr->image != NULL) { Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight); + haveImage = 1; + } else if (mePtr->bitmapPtr != NULL) { + Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr); + Tk_SizeOfBitmap(menuPtr->display, bitmap, &imageWidth, &imageHeight); + haveImage = 1; + } + if (!haveImage || (mePtr->compound != COMPOUND_NONE)) { + if (mePtr->labelLength > 0) { + char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL); + textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength); + textHeight = fmPtr->linespace; + haveText = 1; + } + } + + /* + * Now work out what the relative positions are. + */ + + if (haveImage && haveText) { + int fullWidth = (imageWidth > textWidth ? imageWidth : textWidth); + switch ((enum compound) mePtr->compound) { + case COMPOUND_TOP: { + textXOffset = (fullWidth - textWidth)/2; + textYOffset = imageHeight/2 + 2; + imageXOffset = (fullWidth - imageWidth)/2; + imageYOffset = -textHeight/2; + break; + } + case COMPOUND_BOTTOM: { + textXOffset = (fullWidth - textWidth)/2; + textYOffset = -imageHeight/2; + imageXOffset = (fullWidth - imageWidth)/2; + imageYOffset = textHeight/2 + 2; + break; + } + case COMPOUND_LEFT: { + textXOffset = imageWidth + 2; + textYOffset = 0; + imageXOffset = 0; + imageYOffset = 0; + break; + } + case COMPOUND_RIGHT: { + textXOffset = 0; + textYOffset = 0; + imageXOffset = textWidth + 2; + imageYOffset = 0; + break; + } + case COMPOUND_CENTER: { + textXOffset = (fullWidth - textWidth)/2; + textYOffset = 0; + imageXOffset = (fullWidth - imageWidth)/2; + imageYOffset = 0; + break; + } + case COMPOUND_NONE: {break;} + } + } else { + textXOffset = 0; + textYOffset = 0; + imageXOffset = 0; + imageYOffset = 0; + } + + /* + * Draw label and/or bitmap or image for entry. + */ + + if (mePtr->image != NULL) { if ((mePtr->selectImage != NULL) && (mePtr->entryFlags & ENTRY_SELECTED)) { Tk_RedrawImage(mePtr->selectImage, 0, 0, - imageWidth, imageHeight, d, leftEdge, - (int) (y + (mePtr->height - imageHeight)/2)); + imageWidth, imageHeight, d, leftEdge + imageXOffset, + (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset)); } else { Tk_RedrawImage(mePtr->image, 0, 0, imageWidth, - imageHeight, d, leftEdge, - (int) (y + (mePtr->height - imageHeight)/2)); + imageHeight, d, leftEdge + imageXOffset, + (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset)); } } else if (mePtr->bitmapPtr != NULL) { - int width, height; Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr); - Tk_SizeOfBitmap(menuPtr->display, bitmap, &width, &height); - XCopyPlane(menuPtr->display, bitmap, d, gc, 0, 0, (unsigned) width, - (unsigned) height, leftEdge, - (int) (y + (mePtr->height - height)/2), 1); - } else { + XCopyPlane(menuPtr->display, bitmap, d, gc, 0, 0, + (unsigned) imageWidth, (unsigned) imageHeight, + leftEdge + imageXOffset, + (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset), 1); + } + if ((mePtr->compound != COMPOUND_NONE) || !haveImage) { if (mePtr->labelLength > 0) { + int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2; char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL); Tk_DrawChars(menuPtr->display, d, gc, tkfont, label, - mePtr->labelLength, leftEdge, baseline); - DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, + mePtr->labelLength, leftEdge + textXOffset, + baseline + textYOffset); + DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, + x + textXOffset, y + textYOffset, width, height); } } @@ -1954,8 +2029,8 @@ DrawMenuEntryLabel( } else if ((mePtr->image != NULL) && (menuPtr->disabledImageGC != None)) { XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC, - leftEdge, - (int) (y + (mePtr->height - imageHeight)/2), + leftEdge + imageXOffset, + (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset), (unsigned) imageWidth, (unsigned) imageHeight); } } @@ -2237,21 +2312,68 @@ GetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr) * portion */ { TkMenu *menuPtr = mePtr->menuPtr; + int haveImage = 0, haveText = 0; if (mePtr->image != NULL) { Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr); + haveImage = 1; } else if (mePtr->bitmapPtr != NULL) { Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr); Tk_SizeOfBitmap(menuPtr->display, bitmap, widthPtr, heightPtr); + haveImage = 1; } else { - *heightPtr = fmPtr->linespace; + *heightPtr = 0; + *widthPtr = 0; + } + if (haveImage && (mePtr->compound == COMPOUND_NONE)) { + /* We don't care about the text in this case */ + } else { + /* Either it is compound or we don't have an image */ if (mePtr->labelPtr != NULL) { + int textWidth; char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL); - - *widthPtr = Tk_TextWidth(tkfont, label, mePtr->labelLength); + textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength); + + if ((mePtr->compound != COMPOUND_NONE) && haveImage) { + switch ((enum compound) mePtr->compound) { + case COMPOUND_TOP: + case COMPOUND_BOTTOM: { + if (textWidth > *widthPtr) { + *widthPtr = textWidth; + } + /* Add text and padding */ + *heightPtr += fmPtr->linespace + 2; + break; + } + case COMPOUND_LEFT: + case COMPOUND_RIGHT: { + if (fmPtr->linespace > *heightPtr) { + *heightPtr = fmPtr->linespace; + } + /* Add text and padding */ + *widthPtr += textWidth + 2; + break; + } + case COMPOUND_CENTER: { + if (fmPtr->linespace > *heightPtr) { + *heightPtr = fmPtr->linespace; + } + if (textWidth > *widthPtr) { + *widthPtr = textWidth; + } + break; + } + case COMPOUND_NONE: {break;} + } } else { - *widthPtr = 0; + /* We don't have an image or we're not compound */ + *heightPtr = fmPtr->linespace; + *widthPtr = textWidth; + } + } else { + /* An empty entry still has this height */ + *heightPtr = fmPtr->linespace; } } *heightPtr += 1; diff --git a/win/tkWinWm.c b/win/tkWinWm.c index 421c139..b2041c5 100644 --- a/win/tkWinWm.c +++ b/win/tkWinWm.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinWm.c,v 1.30 2001/09/21 20:38:35 hobbs Exp $ + * RCS: @(#) $Id: tkWinWm.c,v 1.31 2001/10/12 13:30:32 tmh Exp $ */ #include "tkWinInt.h" @@ -766,7 +766,7 @@ InitWm(void) * *---------------------------------------------------------------------- */ -int +static int WinSetIcon(interp, titlebaricon, tkw) Tcl_Interp *interp; WinIconPtr titlebaricon; @@ -1091,10 +1091,12 @@ BlockOfIconImagesPtr ReadIconFromICOFile(Tcl_Interp* interp, char* fileName){ } if (Tcl_SetChannelOption(interp, channel, "-translation", "binary") != TCL_OK) { + Tcl_Close(NULL, channel); return NULL; } if (Tcl_SetChannelOption(interp, channel, "-encoding", "binary") != TCL_OK) { + Tcl_Close(NULL, channel); return NULL; } /* Allocate memory for the resource structure */ |