summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixMenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tkUnixMenu.c')
-rw-r--r--unix/tkUnixMenu.c1042
1 files changed, 521 insertions, 521 deletions
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index 9189183..eceb5b2 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -1,17 +1,15 @@
-/*
+/*
* tkUnixMenu.c --
*
* This module implements the UNIX platform-specific features of menus.
*
* Copyright (c) 1996-1998 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 "tkPort.h"
#include "default.h"
-#include "tkInt.h"
#include "tkUnixInt.h"
#include "tkMenu.h"
@@ -29,64 +27,78 @@
#define ENTRY_HELP_MENU ENTRY_PLATFORM_FLAG1
/*
+ * Shared with button widget.
+ */
+
+MODULE_SCOPE void TkpDrawCheckIndicator(Tk_Window tkwin,
+ Display *display, Drawable d, int x, int y,
+ Tk_3DBorder bgBorder, XColor *indicatorColor,
+ XColor *selectColor, XColor *disColor, int on,
+ int disabled, int mode);
+/*
+ * Indicator Draw Modes
+ */
+
+#define CHECK_BUTTON 0
+#define CHECK_MENU 1
+#define RADIO_BUTTON 2
+#define RADIO_MENU 3
+
+/*
* Procedures used internally.
*/
-static void SetHelpMenu _ANSI_ARGS_((TkMenu *menuPtr));
-static void DrawMenuEntryAccelerator _ANSI_ARGS_((
- TkMenu *menuPtr, TkMenuEntry *mePtr,
- Drawable d, GC gc, Tk_Font tkfont,
- CONST Tk_FontMetrics *fmPtr,
+static void SetHelpMenu(TkMenu *menuPtr);
+static void DrawMenuEntryAccelerator(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
Tk_3DBorder activeBorder, int x, int y,
- int width, int height, int drawArrow));
-static void DrawMenuEntryBackground _ANSI_ARGS_((
- TkMenu *menuPtr, TkMenuEntry *mePtr,
- Drawable d, Tk_3DBorder activeBorder,
- Tk_3DBorder bgBorder, int x, int y,
- int width, int heigth));
-static void DrawMenuEntryIndicator _ANSI_ARGS_((
- TkMenu *menuPtr, TkMenuEntry *mePtr,
- Drawable d, GC gc, GC indicatorGC,
- Tk_Font tkfont,
- CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height));
-static void DrawMenuEntryLabel _ANSI_ARGS_((
- TkMenu * menuPtr, TkMenuEntry *mePtr, Drawable d,
- GC gc, Tk_Font tkfont,
+ int width, int height, int drawArrow);
+static void DrawMenuEntryBackground(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d,
+ Tk_3DBorder activeBorder, Tk_3DBorder bgBorder,
+ int x, int y, int width, int heigth);
+static void DrawMenuEntryIndicator(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d,
+ Tk_3DBorder border, XColor *indicatorColor,
+ XColor *disableColor, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int x, int y,
- int width, int height));
-static void DrawMenuSeparator _ANSI_ARGS_((TkMenu *menuPtr,
- TkMenuEntry *mePtr, Drawable d, GC gc,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int x, int y, int width, int height));
-static void DrawTearoffEntry _ANSI_ARGS_((TkMenu *menuPtr,
- TkMenuEntry *mePtr, Drawable d, GC gc,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int x, int y, int width, int height));
-static void DrawMenuUnderline _ANSI_ARGS_((TkMenu *menuPtr,
+ int width, int height);
+static void DrawMenuEntryLabel(TkMenu * menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height);
+static void DrawMenuSeparator(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height);
+static void DrawTearoffEntry(TkMenu *menuPtr,
TkMenuEntry *mePtr, Drawable d, GC gc,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, int x,
- int y, int width, int height));
-static void GetMenuAccelGeometry _ANSI_ARGS_((TkMenu *menuPtr,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height);
+static void DrawMenuUnderline(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Drawable d, GC gc,
+ Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
+ int x, int y, int width, int height);
+static void GetMenuAccelGeometry(TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int *widthPtr,
- int *heightPtr));
-static void GetMenuLabelGeometry _ANSI_ARGS_((TkMenuEntry *mePtr,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr));
-static void GetMenuIndicatorGeometry _ANSI_ARGS_((
- TkMenu *menuPtr, TkMenuEntry *mePtr,
- Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr));
-static void GetMenuSeparatorGeometry _ANSI_ARGS_((
- TkMenu *menuPtr, TkMenuEntry *mePtr,
+ int *heightPtr);
+static void GetMenuLabelGeometry(TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
- int *widthPtr, int *heightPtr));
-static void GetTearoffEntryGeometry _ANSI_ARGS_((TkMenu *menuPtr,
+ int *widthPtr, int *heightPtr);
+static void GetMenuIndicatorGeometry(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Tk_Font tkfont,
+ CONST Tk_FontMetrics *fmPtr,
+ int *widthPtr, int *heightPtr);
+static void GetMenuSeparatorGeometry(TkMenu *menuPtr,
+ TkMenuEntry *mePtr, Tk_Font tkfont,
+ CONST Tk_FontMetrics *fmPtr,
+ int *widthPtr, int *heightPtr);
+static void GetTearoffEntryGeometry(TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int *widthPtr,
- int *heightPtr));
-
+ int *heightPtr);
/*
*----------------------------------------------------------------------
@@ -100,15 +112,15 @@ static void GetTearoffEntryGeometry _ANSI_ARGS_((TkMenu *menuPtr,
* Standard TCL error.
*
* Side effects:
- * Allocates any platform specific allocations and places them
- * in the platformData field of the menuPtr.
+ * Allocates any platform specific allocations and places them in the
+ * platformData field of the menuPtr.
*
*----------------------------------------------------------------------
*/
int
-TkpNewMenu(menuPtr)
- TkMenu *menuPtr;
+TkpNewMenu(
+ TkMenu *menuPtr)
{
SetHelpMenu(menuPtr);
return TCL_OK;
@@ -119,8 +131,8 @@ TkpNewMenu(menuPtr)
*
* TkpDestroyMenu --
*
- * Destroys platform-specific menu structures. Called when the
- * generic menu structure is destroyed for the menu.
+ * Destroys platform-specific menu structures. Called when the generic
+ * menu structure is destroyed for the menu.
*
* Results:
* None.
@@ -132,8 +144,8 @@ TkpNewMenu(menuPtr)
*/
void
-TkpDestroyMenu(menuPtr)
- TkMenu *menuPtr;
+TkpDestroyMenu(
+ TkMenu *menuPtr)
{
/*
* Nothing to do.
@@ -145,8 +157,8 @@ TkpDestroyMenu(menuPtr)
*
* TkpDestroyMenuEntry --
*
- * Cleans up platform-specific menu entry items. Called when entry
- * is destroyed in the generic code.
+ * Cleans up platform-specific menu entry items. Called when entry is
+ * destroyed in the generic code.
*
* Results:
* None.
@@ -158,8 +170,8 @@ TkpDestroyMenu(menuPtr)
*/
void
-TkpDestroyMenuEntry(mEntryPtr)
- TkMenuEntry *mEntryPtr;
+TkpDestroyMenuEntry(
+ TkMenuEntry *mEntryPtr)
{
/*
* Nothing to do.
@@ -171,29 +183,28 @@ TkpDestroyMenuEntry(mEntryPtr)
*
* TkpConfigureMenuEntry --
*
- * Processes configuration options for menu entries. Called when
- * the generic options are processed for the menu.
+ * Processes configuration options for menu entries. Called when the
+ * generic options are processed for the menu.
*
* Results:
- * Returns standard TCL result. If TCL_ERROR is returned, then
- * the interp's result contains an error message.
+ * Returns standard TCL result. If TCL_ERROR is returned, then the
+ * interp's result contains an error message.
*
* Side effects:
- * Configuration information get set for mePtr; old resources
- * get freed, if any need it.
+ * Configuration information get set for mePtr; old resources get freed,
+ * if any need it.
*
*----------------------------------------------------------------------
*/
int
-TkpConfigureMenuEntry(mePtr)
- register TkMenuEntry *mePtr; /* Information about menu entry; may
- * or may not already have values for
- * some fields. */
+TkpConfigureMenuEntry(
+ register TkMenuEntry *mePtr)/* Information about menu entry; may or may
+ * not already have values for some fields. */
{
/*
- * If this is a cascade menu, and the child menu exists, check to
- * see if the child menu is a help menu.
+ * If this is a cascade menu, and the child menu exists, check to see if
+ * the child menu is a help menu.
*/
if ((mePtr->type == CASCADE_ENTRY) && (mePtr->namePtr != NULL)) {
@@ -214,9 +225,8 @@ TkpConfigureMenuEntry(mePtr)
* TkpMenuNewEntry --
*
* Called when a new entry is created in a menu. Fills in platform
- * specific data for the entry. The platformEntryData field
- * is used to store the indicator diameter for radio button
- * and check box entries.
+ * specific data for the entry. The platformEntryData field is used to
+ * store the indicator diameter for radio button and check box entries.
*
* Results:
* Standard TCL error.
@@ -228,8 +238,8 @@ TkpConfigureMenuEntry(mePtr)
*/
int
-TkpMenuNewEntry(mePtr)
- TkMenuEntry *mePtr;
+TkpMenuNewEntry(
+ TkMenuEntry *mePtr)
{
return TCL_OK;
}
@@ -251,9 +261,9 @@ TkpMenuNewEntry(mePtr)
*/
void
-TkpSetWindowMenuBar(tkwin, menuPtr)
- Tk_Window tkwin; /* The window we are setting */
- TkMenu *menuPtr; /* The menu we are setting */
+TkpSetWindowMenuBar(
+ Tk_Window tkwin, /* The window we are setting */
+ TkMenu *menuPtr) /* The menu we are setting */
{
if (menuPtr == NULL) {
TkUnixSetMenubar(tkwin, NULL);
@@ -267,9 +277,9 @@ TkpSetWindowMenuBar(tkwin, menuPtr)
*
* TkpSetMainMenuBar --
*
- * Called when a toplevel widget is brought to front. On the
- * Macintosh, sets up the menubar that goes accross the top
- * of the main monitor. On other platforms, nothing is necessary.
+ * Called when a toplevel widget is brought to front. On the Macintosh,
+ * sets up the menubar that goes accross the top of the main monitor. On
+ * other platforms, nothing is necessary.
*
* Results:
* None.
@@ -281,10 +291,10 @@ TkpSetWindowMenuBar(tkwin, menuPtr)
*/
void
-TkpSetMainMenubar(interp, tkwin, menuName)
- Tcl_Interp *interp;
- Tk_Window tkwin;
- char *menuName;
+TkpSetMainMenubar(
+ Tcl_Interp *interp,
+ Tk_Window tkwin,
+ char *menuName)
{
/*
* Nothing to do.
@@ -296,10 +306,9 @@ TkpSetMainMenubar(interp, tkwin, menuName)
*
* GetMenuIndicatorGeometry --
*
- * Fills out the geometry of the indicator in a menu item. Note
- * that the mePtr->height field must have already been filled in
- * by GetMenuLabelGeometry since this height depends on the label
- * height.
+ * Fills out the geometry of the indicator in a menu item. Note that the
+ * mePtr->height field must have already been filled in by
+ * GetMenuLabelGeometry since this height depends on the label height.
*
* Results:
* widthPtr and heightPtr point to the new geometry values.
@@ -311,13 +320,13 @@ TkpSetMainMenubar(interp, tkwin, menuName)
*/
static void
-GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
- TkMenu *menuPtr; /* The menu we are drawing. */
- TkMenuEntry *mePtr; /* The entry we are interested in. */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalculated metrics */
- int *widthPtr; /* The resulting width */
- int *heightPtr; /* The resulting height */
+GetMenuIndicatorGeometry(
+ TkMenu *menuPtr, /* The menu we are drawing. */
+ TkMenuEntry *mePtr, /* The entry we are interested in. */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated metrics */
+ int *widthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
if ((mePtr->type == CHECK_BUTTON_ENTRY)
|| (mePtr->type == RADIO_BUTTON_ENTRY)) {
@@ -326,22 +335,20 @@ GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*widthPtr = (14 * mePtr->height) / 10;
*heightPtr = mePtr->height;
if (mePtr->type == CHECK_BUTTON_ENTRY) {
- mePtr->platformEntryData =
- (TkMenuPlatformEntryData) ((65 * mePtr->height)
- / 100);
+ mePtr->platformEntryData = (TkMenuPlatformEntryData)
+ INT2PTR((65 * mePtr->height) / 100);
} else {
- mePtr->platformEntryData =
- (TkMenuPlatformEntryData) ((75 * mePtr->height)
- / 100);
- }
+ mePtr->platformEntryData = (TkMenuPlatformEntryData)
+ INT2PTR((75 * mePtr->height) / 100);
+ }
} else {
*widthPtr = *heightPtr = mePtr->height;
if (mePtr->type == CHECK_BUTTON_ENTRY) {
mePtr->platformEntryData = (TkMenuPlatformEntryData)
- ((80 * mePtr->height) / 100);
+ INT2PTR((80 * mePtr->height) / 100);
} else {
mePtr->platformEntryData = (TkMenuPlatformEntryData)
- mePtr->height;
+ INT2PTR(mePtr->height);
}
}
} else {
@@ -380,13 +387,13 @@ GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*/
static void
-GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
- TkMenu *menuPtr; /* The menu was are drawing */
- TkMenuEntry *mePtr; /* The entry we are getting the geometry for */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr;/* The precalculated font metrics */
- int *widthPtr; /* The width of the acclerator area */
- int *heightPtr; /* The height of the accelerator area */
+GetMenuAccelGeometry(
+ TkMenu *menuPtr, /* The menu was are drawing */
+ TkMenuEntry *mePtr, /* The entry we are getting the geometry for */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
+ int *widthPtr, /* The width of the acclerator area */
+ int *heightPtr) /* The height of the accelerator area */
{
*heightPtr = fmPtr->linespace;
if (mePtr->type == CASCADE_ENTRY) {
@@ -394,7 +401,7 @@ GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
} else if ((menuPtr->menuType != MENUBAR)
&& (mePtr->accelPtr != NULL)) {
char *accel = Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
-
+
*widthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
} else {
*widthPtr = 0;
@@ -412,24 +419,22 @@ GetMenuAccelGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder, bgBorder, x, y,
- width, height)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are drawing. */
- Drawable d; /* The drawable we are drawing into */
- Tk_3DBorder activeBorder; /* The border for an active item */
- Tk_3DBorder bgBorder; /* The background border */
- int x; /* Left coordinate of entry rect */
- int y; /* Right coordinate of entry rect */
- int width; /* Width of entry rect */
- int height; /* Height of entry rect */
+DrawMenuEntryBackground(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing. */
+ Drawable d, /* The drawable we are drawing into */
+ Tk_3DBorder activeBorder, /* The border for an active item */
+ Tk_3DBorder bgBorder, /* The background border */
+ int x, /* Left coordinate of entry rect */
+ int y, /* Right coordinate of entry rect */
+ int width, /* Width of entry rect */
+ int height) /* Height of entry rect */
{
if (mePtr->state == ENTRY_ACTIVE) {
int relief;
@@ -466,31 +471,29 @@ DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder, bgBorder, x, y,
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr, activeBorder,
- x, y, width, height, drawArrow)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are drawing */
- Drawable d; /* The drawable we are drawing into */
- GC gc; /* The precalculated gc to draw with */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalculated metrics */
- Tk_3DBorder activeBorder; /* The border for an active item */
- int x; /* Left coordinate of entry rect */
- int y; /* Top coordinate of entry rect */
- int width; /* Width of entry */
- int height; /* Height of entry */
- int drawArrow; /* Whether or not to draw arrow. */
+DrawMenuEntryAccelerator(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing into */
+ GC gc, /* The precalculated gc to draw with */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated metrics */
+ Tk_3DBorder activeBorder, /* The border for an active item */
+ int x, /* Left coordinate of entry rect */
+ int y, /* Top coordinate of entry rect */
+ int width, /* Width of entry */
+ int height, /* Height of entry */
+ int drawArrow) /* Whether or not to draw arrow. */
{
XPoint points[3];
int borderWidth, activeBorderWidth;
-
+
/*
* Draw accelerator or cascade arrow.
*/
@@ -519,7 +522,7 @@ DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr, activeBorder,
char *accel = Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
int left = x + mePtr->labelWidth + activeBorderWidth
+ mePtr->indicatorSpace;
-
+
if (menuPtr->menuType == MENUBAR) {
left += 5;
}
@@ -540,56 +543,45 @@ DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr, activeBorder,
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont, fmPtr,
- x, y, width, height)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are drawing */
- Drawable d; /* The drawable to draw into */
- GC gc; /* The gc to draw with */
- GC indicatorGC; /* The gc that indicators draw with */
- Tk_Font tkfont; /* The font to draw with */
- CONST Tk_FontMetrics *fmPtr; /* The font metrics of the font */
- int x; /* The left of the entry rect */
- int y; /* The top of the entry rect */
- int width; /* Width of menu entry */
- int height; /* Height of menu entry */
+DrawMenuEntryIndicator(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable to draw into */
+ Tk_3DBorder border, /* The background color */
+ XColor *indicatorColor, /* The color to draw indicators with */
+ XColor *disableColor, /* The color use use when disabled */
+ Tk_Font tkfont, /* The font to draw with */
+ CONST Tk_FontMetrics *fmPtr,/* The font metrics of the font */
+ int x, /* The left of the entry rect */
+ int y, /* The top of the entry rect */
+ int width, /* Width of menu entry */
+ int height) /* Height of menu entry */
{
/*
* Draw check-button indicator.
*/
if ((mePtr->type == CHECK_BUTTON_ENTRY) && mePtr->indicatorOn) {
- int dim, top, left;
- int activeBorderWidth;
- Tk_3DBorder border;
-
- dim = (int) mePtr->platformEntryData;
+ int top, left, activeBorderWidth;
+ int disabled = (mePtr->state == ENTRY_DISABLED);
+ XColor *bg;
+
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
menuPtr->activeBorderWidthPtr, &activeBorderWidth);
- left = x + activeBorderWidth + (mePtr->indicatorSpace - dim)/2;
- if (menuPtr->menuType == MENUBAR) {
- left += 5;
- }
- top = y + (height - dim)/2;
- border = Tk_Get3DBorderFromObj(menuPtr->tkwin,
- menuPtr->borderPtr);
- Tk_Fill3DRectangle(menuPtr->tkwin, d, border, left, top, dim,
- dim, DECORATION_BORDER_WIDTH, TK_RELIEF_SUNKEN);
- left += DECORATION_BORDER_WIDTH;
- top += DECORATION_BORDER_WIDTH;
- dim -= 2*DECORATION_BORDER_WIDTH;
- if ((dim > 0) && (mePtr->entryFlags
- & ENTRY_SELECTED)) {
- XFillRectangle(menuPtr->display, d, indicatorGC, left, top,
- (unsigned int) dim, (unsigned int) dim);
- }
+ bg = Tk_3DBorderColor(border);
+ top = y + height/2;
+ left = x + activeBorderWidth + DECORATION_BORDER_WIDTH
+ + mePtr->indicatorSpace/2;
+
+ TkpDrawCheckIndicator(menuPtr->tkwin, menuPtr->display, d, left, top,
+ border, indicatorColor, bg, disableColor,
+ (mePtr->entryFlags & ENTRY_SELECTED), disabled, CHECK_MENU);
}
/*
@@ -597,31 +589,20 @@ DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont, fmPtr,
*/
if ((mePtr->type == RADIO_BUTTON_ENTRY) && mePtr->indicatorOn) {
- XPoint points[4];
- int radius;
- Tk_3DBorder border;
-
- border = Tk_Get3DBorderFromObj(menuPtr->tkwin,
- menuPtr->borderPtr);
- radius = ((int) mePtr->platformEntryData)/2;
- points[0].x = x + (mePtr->indicatorSpace
- - (int) mePtr->platformEntryData)/2;
- points[0].y = y + (height)/2;
- points[1].x = points[0].x + radius;
- points[1].y = points[0].y + radius;
- points[2].x = points[1].x + radius;
- points[2].y = points[0].y;
- points[3].x = points[1].x;
- points[3].y = points[0].y - radius;
- if (mePtr->entryFlags & ENTRY_SELECTED) {
- XFillPolygon(menuPtr->display, d, indicatorGC, points, 4,
- Convex, CoordModeOrigin);
- } else {
- Tk_Fill3DPolygon(menuPtr->tkwin, d, border, points, 4,
- DECORATION_BORDER_WIDTH, TK_RELIEF_FLAT);
- }
- Tk_Draw3DPolygon(menuPtr->tkwin, d, border, points, 4,
- DECORATION_BORDER_WIDTH, TK_RELIEF_SUNKEN);
+ int top, left, activeBorderWidth;
+ int disabled = (mePtr->state == ENTRY_DISABLED);
+ XColor *bg;
+
+ Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
+ menuPtr->activeBorderWidthPtr, &activeBorderWidth);
+ bg = Tk_3DBorderColor(border);
+ top = y + height/2;
+ left = x + activeBorderWidth + DECORATION_BORDER_WIDTH
+ + mePtr->indicatorSpace/2;
+
+ TkpDrawCheckIndicator(menuPtr->tkwin, menuPtr->display, d, left, top,
+ border, indicatorColor, bg, disableColor,
+ (mePtr->entryFlags & ENTRY_SELECTED), disabled, RADIO_MENU);
}
}
@@ -636,24 +617,21 @@ DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont, fmPtr,
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are drawing */
- Drawable d; /* The drawable we are using */
- GC gc; /* The gc to draw into */
- Tk_Font tkfont; /* The font to draw with */
- CONST Tk_FontMetrics *fmPtr; /* The font metrics from the font */
- int x;
- int y;
- int width;
- int height;
+DrawMenuSeparator(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are using */
+ GC gc, /* The gc to draw into */
+ Tk_Font tkfont, /* The font to draw with */
+ CONST Tk_FontMetrics *fmPtr,/* The font metrics from the font */
+ int x, int y,
+ int width, int height)
{
XPoint points[2];
Tk_3DBorder border;
@@ -661,7 +639,7 @@ DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
if (menuPtr->menuType == MENUBAR) {
return;
}
-
+
points[0].x = x;
points[0].y = y + height/2;
points[1].x = width - 1;
@@ -682,29 +660,26 @@ DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
- TkMenu *menuPtr; /* The menu we are drawing. */
- TkMenuEntry *mePtr; /* The entry we are drawing. */
- Drawable d; /* What we are drawing into. */
- GC gc; /* The gc we are drawing into.*/
- Tk_Font tkfont; /* The precalculated font. */
- CONST Tk_FontMetrics *fmPtr;/* The precalculated font metrics. */
- int x; /* Left edge. */
- int y; /* Top edge. */
- int width; /* width of entry. */
- int height; /* height of entry. */
+DrawMenuEntryLabel(
+ TkMenu *menuPtr, /* The menu we are drawing. */
+ TkMenuEntry *mePtr, /* The entry we are drawing. */
+ Drawable d, /* What we are drawing into. */
+ GC gc, /* The gc we are drawing into.*/
+ Tk_Font tkfont, /* The precalculated font. */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics. */
+ int x, /* Left edge. */
+ int y, /* Top edge. */
+ int width, /* width of entry. */
+ int height) /* height of entry. */
{
- int indicatorSpace = mePtr->indicatorSpace;
- int activeBorderWidth;
- int leftEdge;
- int imageHeight, imageWidth;
+ int indicatorSpace = mePtr->indicatorSpace;
+ int activeBorderWidth, leftEdge, imageHeight, imageWidth;
int textHeight = 0, textWidth = 0; /* stop GCC warning */
int haveImage = 0, haveText = 0;
int imageXOffset = 0, imageYOffset = 0;
@@ -716,7 +691,7 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
if (menuPtr->menuType == MENUBAR) {
leftEdge += 5;
}
-
+
/*
* Work out what we will need to draw first.
*/
@@ -737,7 +712,7 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
haveText = 1;
}
}
-
+
/*
* Now work out what the relative positions are.
*/
@@ -745,55 +720,52 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
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: {
- /*
- * Position image in the indicator space to the left of the
- * entries, unless this entry is a radio|check button because
- * then the indicator space will be used.
- */
- textXOffset = imageWidth + 2;
- textYOffset = 0;
- imageXOffset = 0;
- imageYOffset = 0;
- if ((mePtr->type != CHECK_BUTTON_ENTRY)
- && (mePtr->type != RADIO_BUTTON_ENTRY)) {
- textXOffset -= indicatorSpace;
- if (textXOffset < 0) {
- textXOffset = 0;
- }
- imageXOffset = -indicatorSpace;
+ 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:
+ /*
+ * Position image in the indicator space to the left of the
+ * entries, unless this entry is a radio|check button because then
+ * the indicator space will be used.
+ */
+
+ textXOffset = imageWidth + 2;
+ textYOffset = 0;
+ imageXOffset = 0;
+ imageYOffset = 0;
+ if ((mePtr->type != CHECK_BUTTON_ENTRY)
+ && (mePtr->type != RADIO_BUTTON_ENTRY)) {
+ textXOffset -= indicatorSpace;
+ if (textXOffset < 0) {
+ textXOffset = 0;
}
- break;
+ imageXOffset = -indicatorSpace;
}
- 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;}
+ 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;
@@ -801,7 +773,7 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
imageXOffset = 0;
imageYOffset = 0;
}
-
+
/*
* Draw label and/or bitmap or image for entry.
*/
@@ -811,27 +783,30 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
&& (mePtr->entryFlags & ENTRY_SELECTED)) {
Tk_RedrawImage(mePtr->selectImage, 0, 0,
imageWidth, imageHeight, d, leftEdge + imageXOffset,
- (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset));
+ (int) (y + (mePtr->height-imageHeight)/2 + imageYOffset));
} else {
Tk_RedrawImage(mePtr->image, 0, 0, imageWidth,
imageHeight, d, leftEdge + imageXOffset,
- (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset));
+ (int) (y + (mePtr->height-imageHeight)/2 + imageYOffset));
}
} else if (mePtr->bitmapPtr != None) {
Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
- XCopyPlane(menuPtr->display, bitmap, d, gc, 0, 0,
- (unsigned) imageWidth, (unsigned) imageHeight,
+
+ 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) {
int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
+
if (mePtr->labelLength > 0) {
char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+
Tk_DrawChars(menuPtr->display, d, gc, tkfont, label,
- mePtr->labelLength, leftEdge + textXOffset,
+ mePtr->labelLength, leftEdge + textXOffset,
baseline + textYOffset);
- DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr,
+ DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr,
x + textXOffset, y + textYOffset,
width, height);
}
@@ -841,7 +816,7 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
if (menuPtr->disabledFgPtr == NULL) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,
(unsigned) width, (unsigned) height);
- } else if ((mePtr->image != NULL)
+ } else if ((mePtr->image != NULL)
&& (menuPtr->disabledImageGC != None)) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
leftEdge + imageXOffset,
@@ -856,40 +831,38 @@ DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
*
* DrawMenuUnderline --
*
- * On appropriate platforms, draw the underline character for the
- * menu.
+ * On appropriate platforms, draw the underline character for the menu.
*
* Results:
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
- TkMenu *menuPtr; /* The menu to draw into */
- TkMenuEntry *mePtr; /* The entry we are drawing */
- Drawable d; /* What we are drawing into */
- GC gc; /* The gc to draw into */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalculated font metrics */
- int x;
- int y;
- int width;
- int height;
+DrawMenuUnderline(
+ TkMenu *menuPtr, /* The menu to draw into */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* What we are drawing into */
+ GC gc, /* The gc to draw into */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
+ int x, int y,
+ int width, int height)
{
if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
int len;
- /* do the unicode call just to prevent overruns */
+ /*
+ * Do the unicode call just to prevent overruns.
+ */
+
Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
if (mePtr->underline < len) {
- int activeBorderWidth;
- int leftEdge;
+ int activeBorderWidth, leftEdge;
CONST char *label, *start, *end;
label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
@@ -927,11 +900,10 @@ DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
*/
int
-TkpPostMenu(interp, menuPtr, x, y)
- Tcl_Interp *interp;
- TkMenu *menuPtr;
- int x;
- int y;
+TkpPostMenu(
+ Tcl_Interp *interp,
+ TkMenu *menuPtr,
+ int x, int y)
{
return TkPostTearoffMenu(interp, menuPtr, x, y);
}
@@ -953,14 +925,13 @@ TkpPostMenu(interp, menuPtr, x, y)
*/
static void
-GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr,
- heightPtr)
- TkMenu *menuPtr; /* The menu we are measuring */
- TkMenuEntry *mePtr; /* The entry we are measuring */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalcualted font metrics */
- int *widthPtr; /* The resulting width */
- int *heightPtr; /* The resulting height */
+GetMenuSeparatorGeometry(
+ TkMenu *menuPtr, /* The menu we are measuring */
+ TkMenuEntry *mePtr, /* The entry we are measuring */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalcualted font metrics */
+ int *widthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
*widthPtr = 0;
*heightPtr = fmPtr->linespace;
@@ -983,13 +954,13 @@ GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr,
*/
static void
-GetTearoffEntryGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are measuring */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalculated font metrics */
- int *widthPtr; /* The resulting width */
- int *heightPtr; /* The resulting height */
+GetTearoffEntryGeometry(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are measuring */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
+ int *widthPtr, /* The resulting width */
+ int *heightPtr) /* The resulting height */
{
if (menuPtr->menuType != MASTER_MENU) {
*heightPtr = 0;
@@ -1005,38 +976,30 @@ GetTearoffEntryGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*
* TkpComputeMenubarGeometry --
*
- * This procedure is invoked to recompute the size and
- * layout of a menu that is a menubar clone.
+ * This procedure is invoked to recompute the size and layout of a menu
+ * that is a menubar clone.
*
* Results:
* None.
*
* Side effects:
- * Fields of menu entries are changed to reflect their
- * current positions, and the size of the menu window
- * itself may be changed.
+ * Fields of menu entries are changed to reflect their current positions,
+ * and the size of the menu window itself may be changed.
*
*--------------------------------------------------------------
*/
void
-TkpComputeMenubarGeometry(menuPtr)
- TkMenu *menuPtr; /* Structure describing menu. */
+TkpComputeMenubarGeometry(
+ TkMenu *menuPtr) /* Structure describing menu. */
{
- Tk_Font tkfont;
+ Tk_Font tkfont, menuFont;
Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
- int width, height;
- int i, j;
- int x, y, currentRowHeight, maxWidth;
- int maxWindowWidth;
- int lastRowBreak;
- int helpMenuIndex = -1;
+ int width, height, i, j, x, y, currentRowHeight, maxWidth;
+ int maxWindowWidth, lastRowBreak, lastEntry;
+ int borderWidth, activeBorderWidth, helpMenuIndex = -1;
TkMenuEntry *mePtr;
- int lastEntry;
- Tk_Font menuFont;
- int borderWidth;
- int activeBorderWidth;
-
+
if (menuPtr->tkwin == NULL) {
return;
}
@@ -1050,7 +1013,7 @@ TkpComputeMenubarGeometry(menuPtr)
height = 0;
} else {
int borderWidth;
-
+
maxWindowWidth = Tk_Width(menuPtr->tkwin);
if (maxWindowWidth == 1) {
maxWindowWidth = 0x7ffffff;
@@ -1060,19 +1023,19 @@ TkpComputeMenubarGeometry(menuPtr)
&borderWidth);
x = y = borderWidth;
lastRowBreak = 0;
-
+
/*
- * On the Mac especially, getting font metrics can be quite slow,
- * so we want to do it intelligently. We are going to precalculate
- * them and pass them down to all of the measureing and drawing
- * routines. We will measure the font metrics of the menu once,
- * and if an entry has a font set, we will measure it as we come
- * to it, and then we decide which set to give the geometry routines.
+ * On the Mac especially, getting font metrics can be quite slow, so
+ * we want to do it intelligently. We are going to precalculate them
+ * and pass them down to all of the measureing and drawing routines.
+ * We will measure the font metrics of the menu once, and if an entry
+ * has a font set, we will measure it as we come to it, and then we
+ * decide which set to give the geometry routines.
*/
menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
Tk_GetFontMetrics(menuFont, &menuMetrics);
-
+
for (i = 0; i < menuPtr->numEntries; i++) {
mePtr = menuPtr->entries[i];
mePtr->entryFlags &= ~ENTRY_LAST_COLUMN;
@@ -1088,11 +1051,10 @@ TkpComputeMenubarGeometry(menuPtr)
/*
* For every entry, we need to check to see whether or not we
* wrap. If we do wrap, then we have to adjust all of the previous
- * entries' height and y position, because when we see them
- * the first time, we don't know how big its neighbor might
- * be.
+ * entries' height and y position, because when we see them the
+ * first time, we don't know how big its neighbor might be.
*/
-
+
if ((mePtr->type == SEPARATOR_ENTRY)
|| (mePtr->type == TEAROFF_ENTRY)) {
mePtr->height = mePtr->width = 0;
@@ -1140,7 +1102,7 @@ TkpComputeMenubarGeometry(menuPtr)
if (mePtr->height > currentRowHeight) {
currentRowHeight = mePtr->height;
}
- }
+ }
}
lastEntry = menuPtr->numEntries - 1;
@@ -1161,7 +1123,7 @@ TkpComputeMenubarGeometry(menuPtr)
menuPtr->entries[j]->x = x;
x += menuPtr->entries[j]->width;
}
-
+
if (helpMenuIndex != -1) {
mePtr = menuPtr->entries[helpMenuIndex];
@@ -1177,11 +1139,11 @@ TkpComputeMenubarGeometry(menuPtr)
}
height = y + currentRowHeight + borderWidth;
}
- width = Tk_Width(menuPtr->tkwin);
+ width = Tk_Width(menuPtr->tkwin);
/*
- * The X server doesn't like zero dimensions, so round up to at least
- * 1 (a zero-sized menu should never really occur, anyway).
+ * The X server doesn't like zero dimensions, so round up to at least 1 (a
+ * zero-sized menu should never really occur, anyway).
*/
if (width <= 0) {
@@ -1205,24 +1167,21 @@ TkpComputeMenubarGeometry(menuPtr)
* None.
*
* Side effects:
- * Commands are output to X to display the menu in its
- * current mode.
+ * Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static void
-DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
- TkMenu *menuPtr; /* The menu we are drawing */
- TkMenuEntry *mePtr; /* The entry we are drawing */
- Drawable d; /* The drawable we are drawing into */
- GC gc; /* The gc we are drawing with */
- Tk_Font tkfont; /* The font we are drawing with */
- CONST Tk_FontMetrics *fmPtr; /* The metrics we are drawing with */
- int x;
- int y;
- int width;
- int height;
+DrawTearoffEntry(
+ TkMenu *menuPtr, /* The menu we are drawing */
+ TkMenuEntry *mePtr, /* The entry we are drawing */
+ Drawable d, /* The drawable we are drawing into */
+ GC gc, /* The gc we are drawing with */
+ Tk_Font tkfont, /* The font we are drawing with */
+ CONST Tk_FontMetrics *fmPtr,/* The metrics we are drawing with */
+ int x, int y,
+ int width, int height)
{
XPoint points[2];
int segmentWidth, maxX;
@@ -1231,12 +1190,12 @@ DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
if (menuPtr->menuType != MASTER_MENU) {
return;
}
-
+
points[0].x = x;
points[0].y = y + height/2;
points[1].y = points[0].y;
segmentWidth = 6;
- maxX = width - 1;
+ maxX = width - 1;
border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);
while (points[0].x < maxX) {
@@ -1255,24 +1214,25 @@ DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
*
* TkpInitializeMenuBindings --
*
- * For every interp, initializes the bindings for Windows
- * menus. Does nothing on Mac or XWindows.
+ * For every interp, initializes the bindings for Windows menus. Does
+ * nothing on Mac or XWindows.
*
* Results:
* None.
*
* Side effects:
- * C-level bindings are setup for the interp which will
- * handle Alt-key sequences for menus without beeping
- * or interfering with user-defined Alt-key bindings.
+ * C-level bindings are setup for the interp which will handle Alt-key
+ * sequences for menus without beeping or interfering with user-defined
+ * Alt-key bindings.
*
*--------------------------------------------------------------
*/
void
-TkpInitializeMenuBindings(interp, bindingTable)
- Tcl_Interp *interp; /* The interpreter to set. */
- Tk_BindingTable bindingTable; /* The table to add to. */
+TkpInitializeMenuBindings(
+ Tcl_Interp *interp, /* The interpreter to set. */
+ Tk_BindingTable bindingTable)
+ /* The table to add to. */
{
/*
* Nothing to do.
@@ -1284,9 +1244,9 @@ TkpInitializeMenuBindings(interp, bindingTable)
*
* SetHelpMenu --
*
- * Given a menu, check to see whether or not it is a help menu
- * cascade in a menubar. If it is, the entry that points to
- * this menu will be marked.
+ * Given a menu, check to see whether or not it is a help menu cascade in
+ * a menubar. If it is, the entry that points to this menu will be
+ * marked.
*
* RESULTS:
* None.
@@ -1298,10 +1258,22 @@ TkpInitializeMenuBindings(interp, bindingTable)
*/
static void
-SetHelpMenu(menuPtr)
- TkMenu *menuPtr; /* The menu we are checking */
+SetHelpMenu(
+ TkMenu *menuPtr) /* The menu we are checking */
{
TkMenuEntry *cascadeEntryPtr;
+ int useMotifHelp = 0;
+ const char *option = NULL;
+ if (menuPtr->tkwin) {
+ option = Tk_GetOption(menuPtr->tkwin, "useMotifHelp", "UseMotifHelp");
+ if (option != NULL) {
+ Tcl_GetBoolean(NULL, option, &useMotifHelp);
+ }
+ }
+
+ if (!useMotifHelp) {
+ return;
+ }
for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
cascadeEntryPtr != NULL;
@@ -1331,8 +1303,8 @@ SetHelpMenu(menuPtr)
*
* TkpDrawMenuEntry --
*
- * Draws the given menu entry at the given coordinates with the
- * given attributes.
+ * Draws the given menu entry at the given coordinates with the given
+ * attributes.
*
* Results:
* None.
@@ -1344,23 +1316,23 @@ SetHelpMenu(menuPtr)
*/
void
-TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
- strictMotif, drawArrow)
- TkMenuEntry *mePtr; /* The entry to draw */
- Drawable d; /* What to draw into */
- Tk_Font tkfont; /* Precalculated font for menu */
- CONST Tk_FontMetrics *menuMetricsPtr;
+TkpDrawMenuEntry(
+ TkMenuEntry *mePtr, /* The entry to draw */
+ Drawable d, /* What to draw into */
+ Tk_Font tkfont, /* Precalculated font for menu */
+ CONST Tk_FontMetrics *menuMetricsPtr,
/* Precalculated metrics for menu */
- int x; /* X-coordinate of topleft of entry */
- int y; /* Y-coordinate of topleft of entry */
- int width; /* Width of the entry rectangle */
- int height; /* Height of the current rectangle */
- int strictMotif; /* Boolean flag */
- int drawArrow; /* Whether or not to draw the cascade
+ int x, /* X-coordinate of topleft of entry */
+ int y, /* Y-coordinate of topleft of entry */
+ int width, /* Width of the entry rectangle */
+ int height, /* Height of the current rectangle */
+ int strictMotif, /* Boolean flag */
+ int drawArrow) /* Whether or not to draw the cascade
* arrow for cascade items. Only applies
* to Windows. */
{
GC gc, indicatorGC;
+ XColor *indicatorColor, *disableColor = NULL;
TkMenu *menuPtr = mePtr->menuPtr;
Tk_3DBorder bgBorder, activeBorder;
CONST Tk_FontMetrics *fmPtr;
@@ -1381,13 +1353,12 @@ TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
} else {
TkMenuEntry *cascadeEntryPtr;
int parentDisabled = 0;
-
+
for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
cascadeEntryPtr != NULL;
cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
if (cascadeEntryPtr->namePtr != NULL) {
- char *name = Tcl_GetStringFromObj(cascadeEntryPtr->namePtr,
- NULL);
+ char *name = Tcl_GetString(cascadeEntryPtr->namePtr);
if (strcmp(name, Tk_PathName(menuPtr->tkwin)) == 0) {
if (cascadeEntryPtr->state == ENTRY_DISABLED) {
@@ -1415,6 +1386,18 @@ TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
if (indicatorGC == NULL) {
indicatorGC = menuPtr->indicatorGC;
}
+ if (mePtr->indicatorFgPtr) {
+ indicatorColor = Tk_GetColorFromObj(menuPtr->tkwin,
+ mePtr->indicatorFgPtr);
+ } else {
+ indicatorColor = Tk_GetColorFromObj(menuPtr->tkwin,
+ menuPtr->indicatorFgPtr);
+ }
+
+ if (menuPtr->disabledFgPtr != NULL) {
+ disableColor = Tk_GetColorFromObj(menuPtr->tkwin,
+ menuPtr->disabledFgPtr);
+ }
bgBorder = Tk_Get3DBorderFromObj(menuPtr->tkwin,
(mePtr->borderPtr == NULL)
@@ -1436,16 +1419,16 @@ TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
}
/*
- * Need to draw the entire background, including padding. On Unix,
- * for menubars, we have to draw the rest of the entry taking
- * into account the padding.
+ * Need to draw the entire background, including padding. On Unix, for
+ * menubars, we have to draw the rest of the entry taking into account the
+ * padding.
*/
-
- DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder,
+
+ DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder,
bgBorder, x, y, width, height);
-
+
if (mePtr->type == SEPARATOR_ENTRY) {
- DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont,
+ DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont,
fmPtr, x, adjustedY, width, adjustedHeight);
} else if (mePtr->type == TEAROFF_ENTRY) {
DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
@@ -1456,8 +1439,12 @@ TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr,
activeBorder, x, adjustedY, width, adjustedHeight, drawArrow);
if (!mePtr->hideMargin) {
- DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont,
- fmPtr, x, adjustedY, width, adjustedHeight);
+ if (mePtr->state == ENTRY_ACTIVE) {
+ bgBorder = activeBorder;
+ }
+ DrawMenuEntryIndicator(menuPtr, mePtr, d, bgBorder, indicatorColor,
+ disableColor, tkfont, fmPtr, x, adjustedY, width,
+ adjustedHeight);
}
}
}
@@ -1480,22 +1467,21 @@ TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
*/
static void
-GetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr)
- TkMenuEntry *mePtr; /* The entry we are computing */
- Tk_Font tkfont; /* The precalculated font */
- CONST Tk_FontMetrics *fmPtr; /* The precalculated metrics */
- int *widthPtr; /* The resulting width of the label
- * portion */
- int *heightPtr; /* The resulting height of the label
- * portion */
+GetMenuLabelGeometry(
+ TkMenuEntry *mePtr, /* The entry we are computing */
+ Tk_Font tkfont, /* The precalculated font */
+ CONST Tk_FontMetrics *fmPtr,/* The precalculated metrics */
+ int *widthPtr, /* The resulting width of the label portion */
+ int *heightPtr) /* The resulting height of the label
+ * portion */
{
TkMenu *menuPtr = mePtr->menuPtr;
int haveImage = 0;
-
+
if (mePtr->image != NULL) {
Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr);
haveImage = 1;
- } else if (mePtr->bitmapPtr != NULL) {
+ } else if (mePtr->bitmapPtr != NULL) {
Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
Tk_SizeOfBitmap(menuPtr->display, bitmap, widthPtr, heightPtr);
haveImage = 1;
@@ -1503,54 +1489,71 @@ GetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*heightPtr = 0;
*widthPtr = 0;
}
-
+
if (haveImage && (mePtr->compound == COMPOUND_NONE)) {
- /* We don't care about the text in this case */
+ /*
+ * We don't care about the text in this case.
+ */
} else {
- /* Either it is compound or we don't have an image */
+ /*
+ * Either it is compound or we don't have an image.
+ */
+
if (mePtr->labelPtr != NULL) {
int textWidth;
char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
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_TOP:
+ case COMPOUND_BOTTOM:
+ if (textWidth > *widthPtr) {
+ *widthPtr = textWidth;
}
- case COMPOUND_LEFT:
- case COMPOUND_RIGHT: {
- if (fmPtr->linespace > *heightPtr) {
- *heightPtr = fmPtr->linespace;
- }
- /* Add text and padding */
- *widthPtr += textWidth + 2;
- break;
+
+ /*
+ * Add text and padding.
+ */
+
+ *heightPtr += fmPtr->linespace + 2;
+ break;
+ case COMPOUND_LEFT:
+ case COMPOUND_RIGHT:
+ if (fmPtr->linespace > *heightPtr) {
+ *heightPtr = fmPtr->linespace;
}
- case COMPOUND_CENTER: {
- if (fmPtr->linespace > *heightPtr) {
- *heightPtr = fmPtr->linespace;
- }
- if (textWidth > *widthPtr) {
- *widthPtr = textWidth;
- }
- break;
+
+ /*
+ * Add text and padding.
+ */
+
+ *widthPtr += textWidth + 2;
+ break;
+ case COMPOUND_CENTER:
+ if (fmPtr->linespace > *heightPtr) {
+ *heightPtr = fmPtr->linespace;
}
- case COMPOUND_NONE: {break;}
+ if (textWidth > *widthPtr) {
+ *widthPtr = textWidth;
+ }
+ break;
+ case COMPOUND_NONE:
+ break;
}
- } else {
- /* We don't have an image or we're not compound */
+ } else {
+ /*
+ * We don't have an image or we're not compound.
+ */
+
*heightPtr = fmPtr->linespace;
*widthPtr = textWidth;
}
} else {
- /* An empty entry still has this height */
+ /*
+ * An empty entry still has this height.
+ */
+
*heightPtr = fmPtr->linespace;
}
}
@@ -1562,33 +1565,30 @@ GetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*
* TkpComputeStandardMenuGeometry --
*
- * This procedure is invoked to recompute the size and
- * layout of a menu that is not a menubar clone.
+ * This procedure is invoked to recompute the size and layout of a menu
+ * that is not a menubar clone.
*
* Results:
* None.
*
* Side effects:
- * Fields of menu entries are changed to reflect their
- * current positions, and the size of the menu window
- * itself may be changed.
+ * Fields of menu entries are changed to reflect their current positions,
+ * and the size of the menu window itself may be changed.
*
*--------------------------------------------------------------
*/
void
TkpComputeStandardMenuGeometry(
- menuPtr) /* Structure describing menu. */
- TkMenu *menuPtr;
+ TkMenu *menuPtr) /* Structure describing menu. */
{
Tk_Font tkfont, menuFont;
Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
int x, y, height, width, indicatorSpace, labelWidth, accelWidth;
- int windowWidth, windowHeight, accelSpace;
- int i, j, lastColumnBreak = 0;
+ int windowWidth, windowHeight, accelSpace, i, j, lastColumnBreak = 0;
TkMenuEntry *mePtr;
int borderWidth, activeBorderWidth;
-
+
if (menuPtr->tkwin == NULL) {
return;
}
@@ -1602,14 +1602,13 @@ TkpComputeStandardMenuGeometry(
windowHeight = windowWidth = 0;
/*
- * On the Mac especially, getting font metrics can be quite slow,
- * so we want to do it intelligently. We are going to precalculate
- * them and pass them down to all of the measuring and drawing
- * routines. We will measure the font metrics of the menu once.
- * If an entry does not have its own font set, then we give
- * the geometry/drawing routines the menu's font and metrics.
- * If an entry has its own font, we will measure that font and
- * give all of the geometry/drawing the entry's font and metrics.
+ * On the Mac especially, getting font metrics can be quite slow, so we
+ * want to do it intelligently. We are going to precalculate them and pass
+ * them down to all of the measuring and drawing routines. We will measure
+ * the font metrics of the menu once. If an entry does not have its own
+ * font set, then we give the geometry/drawing routines the menu's font
+ * and metrics. If an entry has its own font, we will measure that font
+ * and give all of the geometry/drawing the entry's font and metrics.
*/
menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
@@ -1648,28 +1647,25 @@ TkpComputeStandardMenuGeometry(
}
if (mePtr->type == SEPARATOR_ENTRY) {
- GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont,
- fmPtr, &width, &height);
+ GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont, fmPtr,
+ &width, &height);
mePtr->height = height;
} else if (mePtr->type == TEAROFF_ENTRY) {
- GetTearoffEntryGeometry(menuPtr, mePtr, tkfont,
- fmPtr, &width, &height);
+ GetTearoffEntryGeometry(menuPtr, mePtr, tkfont, fmPtr,
+ &width, &height);
mePtr->height = height;
labelWidth = width;
} else {
-
/*
- * For each entry, compute the height required by that
- * particular entry, plus three widths: the width of the
- * label, the width to allow for an indicator to be displayed
- * to the left of the label (if any), and the width of the
- * accelerator to be displayed to the right of the label
- * (if any). These sizes depend, of course, on the type
- * of the entry.
+ * For each entry, compute the height required by that particular
+ * entry, plus three widths: the width of the label, the width to
+ * allow for an indicator to be displayed to the left of the label
+ * (if any), and the width of the accelerator to be displayed to
+ * the right of the label (if any). These sizes depend, of course,
+ * on the type of the entry.
*/
-
- GetMenuLabelGeometry(mePtr, tkfont, fmPtr, &width,
- &height);
+
+ GetMenuLabelGeometry(mePtr, tkfont, fmPtr, &width, &height);
mePtr->height = height;
if (!mePtr->hideMargin) {
width += MENU_MARGIN_WIDTH;
@@ -1677,7 +1673,7 @@ TkpComputeStandardMenuGeometry(
if (width > labelWidth) {
labelWidth = width;
}
-
+
GetMenuAccelGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
if (height > mePtr->height) {
@@ -1690,7 +1686,7 @@ TkpComputeStandardMenuGeometry(
accelWidth = width;
}
- GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont,
+ GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
if (height > mePtr->height) {
mePtr->height = height;
@@ -1725,12 +1721,11 @@ TkpComputeStandardMenuGeometry(
windowWidth = x + indicatorSpace + labelWidth + accelWidth
+ 2 * activeBorderWidth + 2 * borderWidth;
-
windowHeight += borderWidth;
-
+
/*
- * The X server doesn't like zero dimensions, so round up to at least
- * 1 (a zero-sized menu should never really occur, anyway).
+ * The X server doesn't like zero dimensions, so round up to at least 1 (a
+ * zero-sized menu should never really occur, anyway).
*/
if (windowWidth <= 0) {
@@ -1749,8 +1744,8 @@ TkpComputeStandardMenuGeometry(
* TkpMenuNotifyToplevelCreate --
*
* This routine reconfigures the menu and the clones indicated by
- * menuName becuase a toplevel has been created and any system
- * menus need to be created. Not applicable to UNIX.
+ * menuName becuase a toplevel has been created and any system menus need
+ * to be created. Not applicable to UNIX.
*
* Results:
* None.
@@ -1762,10 +1757,9 @@ TkpComputeStandardMenuGeometry(
*/
void
-TkpMenuNotifyToplevelCreate(interp, menuName)
- Tcl_Interp *interp; /* The interp the menu lives in. */
- char *menuName; /* The name of the menu to
- * reconfigure. */
+TkpMenuNotifyToplevelCreate(
+ Tcl_Interp *interp, /* The interp the menu lives in. */
+ char *menuName) /* The name of the menu to reconfigure. */
{
/*
* Nothing to do.
@@ -1789,7 +1783,7 @@ TkpMenuNotifyToplevelCreate(interp, menuName)
*/
void
-TkpMenuInit()
+TkpMenuInit(void)
{
/*
* Nothing to do.
@@ -1802,8 +1796,7 @@ TkpMenuInit()
*
* TkpMenuThreadInit --
*
- * Does platform-specific initialization of thread-specific
- * menu state.
+ * Does platform-specific initialization of thread-specific menu state.
*
* Results:
* None.
@@ -1815,10 +1808,17 @@ TkpMenuInit()
*/
void
-TkpMenuThreadInit()
+TkpMenuThreadInit(void)
{
/*
* Nothing to do.
*/
}
-
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */