summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXMenu.c
diff options
context:
space:
mode:
authordas <das>2003-05-13 02:42:57 (GMT)
committerdas <das>2003-05-13 02:42:57 (GMT)
commitda1bf4fb459b1e4f5e1be8a76e14029d4a9d331b (patch)
treededfb9313098f6f370b756eefb7f3817c98756c5 /macosx/tkMacOSXMenu.c
parent996aa5aa5d6fca18e46c0f25c7f25589a1d85003 (diff)
downloadtk-da1bf4fb459b1e4f5e1be8a76e14029d4a9d331b.zip
tk-da1bf4fb459b1e4f5e1be8a76e14029d4a9d331b.tar.gz
tk-da1bf4fb459b1e4f5e1be8a76e14029d4a9d331b.tar.bz2
backport of Mac OS X specific changes on trunk since 8.4.2:
* macosx/tkMacOSXClipboard.c (TkSelGetSelection): Convert '\r' to '\n' on the way into Tcl. (ingham) * macosx/tkMacOSXMenu.c (EventuallyInvokeMenu): New function, used to invoke menu commands at idle time. (TkMacOSXDispatchMenuEvent): Don't immediately dispatch menu commands, wait till the idle loop to do so. This is more like what is done on Windows, and avoids the crash from destroying a menu in it's command. (ingham) * macosx/tkMacOSXHLEvents.c (ReallyKillMe): Don't force the shell to exit. According to the OS X HI guidelines, it should be possible to cancel an attempt to quit, and if we force the kill, here, it would not be possible to implement this. (ingham) * macosx/tkMacOSXApplication.r (removed): * macosx/tkMacOSXLibrary.r (removed): * macosx/tkMacOSXResource.r (removed): * macosx/Wish.pbproj/project.pbxproj: * macosx/tkAboutDlg.r: updated copyrights, cleaned up about box, removed obsolete unused resource files. (steffen)
Diffstat (limited to 'macosx/tkMacOSXMenu.c')
-rw-r--r--macosx/tkMacOSXMenu.c84
1 files changed, 61 insertions, 23 deletions
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index d92a8fb..6bf92f2 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.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: tkMacOSXMenu.c,v 1.6 2003/02/19 19:27:48 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.6.2.1 2003/05/13 02:42:57 das Exp $
*/
#include "tkMacOSXInt.h"
#include "tkMenuButton.h"
@@ -180,10 +180,6 @@ static Tk_Window currentMenuBarOwner;
static char elipsisString[TCL_UTF_MAX + 1];
/* The UTF representation of the elipsis (...)
* character. */
-static int helpItemCount; /* The number of items in the help menu.
- * -1 means that the help menu is
- * unavailable. This does not include
- * the automatically generated separator. */
static int inPostMenu; /* We cannot be re-entrant like X
* windows. */
static short lastMenuID; /* To pass to NewMenu; need to figure out
@@ -204,6 +200,11 @@ static struct TearoffSelect {
* when we are in this menu */
} tearoffStruct;
+struct MenuCommandHandlerData { /* This is the ClientData we pass to */
+ TkMenu *menuPtr; /* Tcl_DoWhenIdle to move handling */
+ int index; /* menu commands to the event loop. */
+};
+
static RgnHandle totalMenuRgn = NULL;
/* Used to update windows which have been
* obscured by menus. */
@@ -261,6 +262,7 @@ 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 EventuallyInvokeMenu (ClientData data);
static void GetEntryText _ANSI_ARGS_((TkMenuEntry *mePtr,
Tcl_DString *dStringPtr));
static void GetMenuAccelGeometry _ANSI_ARGS_((TkMenu *menuPtr,
@@ -640,8 +642,8 @@ TkpDestroyMenu(
&& (helpMenuHdl != NULL)) {
int i, count = CountMenuItems(helpMenuHdl);
- for (i = helpItemCount; i <= count; i++) {
- DeleteMenuItem(helpMenuHdl, helpItemCount);
+ for (i = helpIndex; i <= count; i++) {
+ DeleteMenuItem(helpMenuHdl, helpIndex);
}
}
currentHelpMenuID = 0;
@@ -1036,7 +1038,8 @@ ReconfigureIndividualMenu(
* be the help menu. */
int base) /* The last index that we do not want
* touched. 0 for normal menus;
- * helpMenuItemCount for help menus. */
+ * # of system help menu items
+ * for help menus. */
{
int count;
int index;
@@ -1290,7 +1293,8 @@ ReconfigureMacintoshMenu(
MenuItemIndex helpIndex;
HMGetHelpMenu(&helpMenuHdl,&helpIndex);
if (helpMenuHdl != NULL) {
- ReconfigureIndividualMenu(menuPtr, helpMenuHdl, helpItemCount);
+ ReconfigureIndividualMenu(menuPtr, helpMenuHdl,
+ helpIndex - 1);
}
}
@@ -2074,6 +2078,35 @@ TkpSetWindowMenuBar(
}
}
+static void
+/*
+ *----------------------------------------------------------------------
+ *
+ * EventuallyInvokeMenu --
+ *
+ * This IdleTime callback actually invokes the menu command
+ * scheduled in TkMacOSXDispatchMenuEvent.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Commands get executed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+EventuallyInvokeMenu (ClientData data)
+{
+ struct MenuCommandHandlerData *realData
+ = (struct MenuCommandHandlerData *) data;
+
+ Tcl_Release(realData->menuPtr->interp);
+ Tcl_Release(realData->menuPtr);
+ TkInvokeMenu(realData->menuPtr->interp, realData->menuPtr,
+ realData->index);
+}
+
/*
*----------------------------------------------------------------------
*
@@ -2086,7 +2119,7 @@ TkpSetWindowMenuBar(
* None.
*
* Side effects:
- * Commands get executed.
+ * Commands for the event are scheduled for execution at idle time.
*
*----------------------------------------------------------------------
*/
@@ -2109,7 +2142,10 @@ TkMacOSXDispatchMenuEvent(
helpMenuName);
ckfree(helpMenuName);
if ((helpMenuRef != NULL) && (helpMenuRef->menuPtr != NULL)) {
- int newIndex = index - helpItemCount - 1;
+ MenuRef outHelpMenu;
+ MenuItemIndex itemIndex;
+ HMGetHelpMenu(&outHelpMenu, &itemIndex);
+ int newIndex = index - itemIndex;
result = TkInvokeMenu(currentMenuBarInterp,
helpMenuRef->menuPtr, newIndex);
}
@@ -2126,7 +2162,16 @@ TkMacOSXDispatchMenuEvent(
GetMenuItemText(GetMenuHandle(menuID), index, itemText);
result = TCL_OK;
} else {
- result = TkInvokeMenu(menuPtr->interp, menuPtr, index - 1);
+ struct MenuCommandHandlerData *data
+ = (struct MenuCommandHandlerData *)
+ ckalloc(sizeof(struct MenuCommandHandlerData));
+ Tcl_Preserve(menuPtr->interp);
+ Tcl_Preserve(menuPtr);
+ data->menuPtr = menuPtr;
+ data->index = index - 1;
+ Tcl_DoWhenIdle (EventuallyInvokeMenu,
+ (ClientData) data);
+ /* result = TkInvokeMenu(menuPtr->interp, menuPtr, index - 1); */
}
} else {
return TCL_ERROR;
@@ -2881,12 +2926,15 @@ DrawTearoffEntry(
* Has to be called after the first call to InsertMenu. Sets
* up the global variable for the number of items in the
* unmodified help menu.
+ * NB. Nobody uses this any more, since you can get the number
+ * of system help items from HMGetHelpMenu trivially.
+ * But it is in the stubs table...
*
* Results:
* None.
*
* Side effects:
- * Sets the global helpItemCount.
+ * Nothing.
*
*----------------------------------------------------------------------
*/
@@ -2894,16 +2942,6 @@ DrawTearoffEntry(
void
TkMacOSXSetHelpMenuItemCount()
{
- MenuRef helpMenuHandle;
- MenuItemIndex itemIndex;
-
- if ((HMGetHelpMenu(&helpMenuHandle,&itemIndex) != noErr)
- || (helpMenuHandle == NULL)) {
- helpItemCount = -1;
- } else {
- helpItemCount = CountMenuItems(helpMenuHandle);
- DeleteMenuItem(helpMenuHandle, helpItemCount);
- }
}
/*