| Description: |
The application menu created by the MacOS X system
provides (amongst others) "Preferences..." and "Quit" items
that should be used by applications in preference to
application-specific menus. For a Tcl/Tk application based
on the Wish Shell bundle, it is convenient to allow these
menu items to be handled by scripted procedures.
In Tk 8.4.9, the Quit menu item is handled by evaluating the
"exit" command. The following amended procedure from
tkMacOSXHLEvents.c first checks if there is a user-defined
command "::tk::mac::Quit", which is evaluated in
preference to "exit". This allows an application-specifc
script to be run prior to application shutdown. (This might,
for example, prompt users to save modified documents.)
Note that on other platforms, the standard application
shutdown is peformed using the Exit item on the File menu,
which is, of course, defined by the application.
static int
ReallyKillMe(Tcl_Event *eventPtr, int flags)
{
Tcl_CmdInfo dummy;
Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
/*
* Look for user-defined handler in ::tk::mac::Quit
* or default to "exit"
*/
if (interp != NULL) {
if (Tcl_GetCommandInfo(interp, "::tk::mac::Quit",
&dummy) != 0) {
Tcl_GlobalEval(interp, "::tk::mac::Quit");
} else {
Tcl_GlobalEval(interp, "exit");
}
}
return 1;
}
Handling the "Preferences..." menu item, on the other hand,
is at present already partially implemented. The menu item
is disabled by default, but if it is enabled (see below) by the
user, the user-defined procedure
::tk::mac::ShowPreferences is invoked.
To enable the "Preferences..." menu item, it is necessary to
add a call to the command:
EnableMenuCommand(NULL, kHICommandPreferences);
Ideally, a Tcl/Tk script should have access to this command,
such as through a procedure called e.g.
::tk::mac::EnablePreferencesMenuItem This access would
complete the implementation of the Tcl/Tk script-level
handling of the application menu.
|