From f0756e95ee1b2b747fcdfcdd4a83c50a8662b142 Mon Sep 17 00:00:00 2001
From: Pat Thoyts <patthoyts@users.sourceforge.net>
Date: Sat, 2 Jan 2010 00:42:46 +0000
Subject: [PATCH 2/3] unix-menus: Remove special handling of .help menu.

Tk is the only toolkit to continue the Motif scheme of anchoring a Help
menu to the extreme right of the menubar. This patch disables the special
handling of the .help menu so that the help menu will be grouped with the
other menu items as is common with other toolkits.

The old behaviour can be restored by setting the option *Menu.useMotifHelp
to true or by calling 'tk::classic::restore menu'.

Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
---
 doc/menu.n           |   28 ++++++++++++++++------------
 library/obsolete.tcl |    1 +
 unix/tkUnixMenu.c    |   12 ++++++++++++
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/doc/menu.n b/doc/menu.n
index 3f6ef81..bf08d17 100644
--- a/doc/menu.n
+++ b/doc/menu.n
@@ -230,15 +230,16 @@ menubars, they may not be drawn with indicators on some platforms, due
 to system restrictions.
 .SS "SPECIAL MENUS IN MENUBARS"
 .PP
-Certain menus in a menubar will be treated specially.  On the Macintosh,
-access to the special Application and Help menus is provided. On Windows,
-access to the Windows System menu in each window is provided. On X Windows,
-a special right-justified help menu is provided. In all cases, these
-menus must be created with the command name of the menubar menu concatenated
-with the special name. So for a menubar named .menubar, on the Macintosh,
-the special menus would be .menubar.apple and .menubar.help; on Windows,
-the special menu would be .menubar.system; on X Windows, the help
-menu would be .menubar.help.
+Certain menus in a menubar will be treated specially.  On the
+Macintosh, access to the special Application and Help menus is
+provided. On Windows, access to the Windows System menu in each window
+is provided. On X Windows, a special right-justified help menu may be
+provided if Motif menu compatibility is enabled. In all cases, these
+menus must be created with the command name of the menubar menu
+concatenated with the special name. So for a menubar named .menubar,
+on the Macintosh, the special menus would be .menubar.apple and
+.menubar.help; on Windows, the special menu would be .menubar.system;
+on X Windows, the help menu would be .menubar.help.
 .PP
 When Tk sees a .menubar.apple menu on the Macintosh, that menu's contents
 make up the first items of the Application menu whenever the window
@@ -258,8 +259,11 @@ Alt+Spacebar.  Due to limitations in the Windows API, any font changes,
 colors, images, bitmaps, or tearoff images will not appear in the
 system menu.
 .PP
-When Tk see a Help menu on X Windows, the menu is moved to be last in
-the menubar and is right justified.
+When Tk sees a Help menu on X Windows and Motif menu compatibility is
+enabled the menu is moved to be last in the menubar and is right
+justified. Motif menu compatibility is enabled by setting the Tk option
+\fB*Menu.useMotifHelp\fR to true or by calling
+\fBtk::classic::restore menu\fR.
 .SH "CLONES"
 .PP
 When a menu is set as a menubar for a toplevel window, or when a menu
@@ -269,7 +273,7 @@ configuration of the original are reflected in the
 clone. Additionally, any cascades that are pointed to are also cloned
 so that menu traversal will work right. Clones are destroyed when
 either the tearoff or menubar goes away, or when the original menu is
-destroyed. 
+destroyed.
 .SH "WIDGET COMMAND"
 .PP
 The \fBmenu\fR command creates a new Tcl command whose
diff --git a/library/obsolete.tcl b/library/obsolete.tcl
index a7aef8c..72469c2 100644
--- a/library/obsolete.tcl
+++ b/library/obsolete.tcl
@@ -118,6 +118,7 @@ proc ::tk::classic::restore_menu {args} {
 	option add *Menu.activeBorderWidth	2 $prio; # 1
 	option add *Menu.borderWidth		2 $prio; # 1
         option add *Menu.clickToFocus		true $prio
+        option add *Menu.useMotifHelp		true $prio
     }
     if {[tk windowingsystem] ne "aqua"} {
 	option add *Menu.font		"TkDefaultFont" $prio; # "TkMenuFont"
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index f02a836..858083f 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -1264,6 +1264,18 @@ 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;
-- 
1.6.6

