tkMacMenus.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:8k
- /*
- * tkMacMenus.c --
- *
- * These calls set up and manage the menubar for the
- * Macintosh version of Tk.
- *
- * Copyright (c) 1995-1996 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tkMacMenus.c,v 1.8 2002/01/27 11:11:02 das Exp $
- */
- #include "tcl.h"
- #include "tclMacInt.h" /* Needed for FSpLocationFromPath */
- #include "tk.h"
- #include "tkInt.h"
- #include "tkMacInt.h"
- /*
- * The define Status defined by Xlib.h conflicts with the function Status
- * defined by Devices.h. We undefine it here to compile.
- */
- #undef Status
- #include <Devices.h>
- #include <Menus.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <StandardFile.h>
- #include <ToolUtils.h>
- #include <Balloons.h>
- #define kAppleMenu 256
- #define kAppleAboutItem 1
- #define kFileMenu 2
- #define kEditMenu 3
- #define kSourceItem 1
- #define kCloseItem 2
- #define kQuitItem 4
- #define EDIT_CUT 1
- #define EDIT_COPY 2
- #define EDIT_PASTE 3
- #define EDIT_CLEAR 4
- MenuHandle tkAppleMenu;
- MenuHandle tkFileMenu;
- MenuHandle tkEditMenu;
- static Tcl_Interp * gInterp; /* Interpreter for this application. */
- static void GenerateEditEvent _ANSI_ARGS_((int flag));
- static void SourceDialog _ANSI_ARGS_((void));
- /*
- *----------------------------------------------------------------------
- *
- * TkMacHandleMenuSelect --
- *
- * Handles events that occur in the Menu bar.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacHandleMenuSelect(
- long mResult,
- int optionKeyPressed)
- {
- short theItem = LoWord(mResult);
- short theMenu = HiWord(mResult);
- Str255 name;
- Tk_Window tkwin;
- Window window;
- TkDisplay *dispPtr;
- if (mResult == 0) {
- TkMacHandleTearoffMenu();
- TkMacClearMenubarActive();
- return;
- }
- switch (theMenu) {
-
- case kAppleMenu:
- switch (theItem) {
- case kAppleAboutItem:
- {
- Tcl_CmdInfo dummy;
-
- if (optionKeyPressed || gInterp == NULL ||
- Tcl_GetCommandInfo(gInterp,
- "tkAboutDialog", &dummy) == 0) {
- TkAboutDlg();
- } else {
- Tcl_Eval(gInterp, "tkAboutDialog");
- }
- break;
- }
- default:
- GetMenuItemText(tkAppleMenu, theItem, name);
- HiliteMenu(0);
- OpenDeskAcc(name);
- return;
- }
- break;
- case kFileMenu:
- switch (theItem) {
- case kSourceItem:
- /* TODO: source script */
- SourceDialog();
- break;
- case kCloseItem:
- /* Send close event */
- if (TkMacHaveAppearance() >= 0x110) {
- window = TkMacGetXWindow(FrontNonFloatingWindow());
- } else {
- window = TkMacGetXWindow(FrontWindow());
- }
- dispPtr = TkGetDisplayList();
- tkwin = Tk_IdToWindow(dispPtr->display, window);
- TkGenWMDestroyEvent(tkwin);
- break;
- case kQuitItem:
- /* Exit */
- if (optionKeyPressed || gInterp == NULL) {
- Tcl_Exit(0);
- } else {
- Tcl_Eval(gInterp, "exit");
- }
- break;
- }
- break;
- case kEditMenu:
- /*
- * This implementation just send keysyms
- * the Tk thinks are associated with function keys that
- * do Cut, Copy & Paste on a Sun keyboard.
- */
- GenerateEditEvent(theItem);
- break;
- default:
- TkMacDispatchMenuEvent(theMenu, theItem);
- TkMacClearMenubarActive();
- break;
- }
- /*
- * Finally we unhighlight the menu.
- */
- HiliteMenu(0);
- } /* TkMacHandleMenuSelect */
- /*
- *----------------------------------------------------------------------
- *
- * TkMacInitMenus --
- *
- * This procedure initializes the Macintosh menu bar.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacInitMenus(
- Tcl_Interp *interp)
- {
- gInterp = interp;
- /*
- * At this point, InitMenus() should have already been called.
- */
- if (TkMacUseMenuID(256) != TCL_OK) {
- panic("Menu ID 256 is already in use!");
- }
- tkAppleMenu = NewMenu(256, "p 24");
- if (tkAppleMenu == NULL) {
- panic("memory - menus");
- }
- InsertMenu(tkAppleMenu, 0);
- AppendMenu(tkAppleMenu, "pAbout Tcl & Tk