4 * These calls set up and manage the menubar for the
5 * Macintosh version of Tk.
7 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 #include "tclMacInt.h" /* Needed for FSpLocationFromPath */
22 * The define Status defined by Xlib.h conflicts with the function Status
23 * defined by Devices.h. We undefine it here to compile.
30 #include <StandardFile.h>
31 #include <ToolUtils.h>
34 #define kAppleMenu 256
35 #define kAppleAboutItem 1
48 MenuHandle tkAppleMenu;
49 MenuHandle tkFileMenu;
50 MenuHandle tkEditMenu;
52 static Tcl_Interp * gInterp; /* Interpreter for this application. */
54 static void GenerateEditEvent _ANSI_ARGS_((int flag));
55 static void SourceDialog _ANSI_ARGS_((void));
58 *----------------------------------------------------------------------
60 * TkMacHandleMenuSelect --
62 * Handles events that occur in the Menu bar.
70 *----------------------------------------------------------------------
74 TkMacHandleMenuSelect(
78 short theItem = LoWord(mResult);
79 short theMenu = HiWord(mResult);
86 TkMacHandleTearoffMenu();
87 TkMacClearMenubarActive();
99 if (optionKeyPressed || gInterp == NULL ||
100 Tcl_GetCommandInfo(gInterp,
101 "tkAboutDialog", &dummy) == 0) {
104 Tcl_Eval(gInterp, "tkAboutDialog");
109 GetItem(tkAppleMenu, theItem, name);
118 /* TODO: source script */
122 /* Send close event */
123 if (TkMacHaveAppearance() >= 0x110) {
124 window = TkMacGetXWindow(FrontNonFloatingWindow());
126 window = TkMacGetXWindow(FrontWindow());
128 dispPtr = TkGetDisplayList();
129 tkwin = Tk_IdToWindow(dispPtr->display, window);
130 TkGenWMDestroyEvent(tkwin);
134 if (optionKeyPressed || gInterp == NULL) {
137 Tcl_Eval(gInterp, "exit");
144 * This implementation just send keysyms
145 * the Tk thinks are associated with function keys that
146 * do Cut, Copy & Paste on a Sun keyboard.
148 GenerateEditEvent(theItem);
151 TkMacDispatchMenuEvent(theMenu, theItem);
152 TkMacClearMenubarActive();
157 * Finally we unhighlight the menu.
160 } /* TkMacHandleMenuSelect */
163 *----------------------------------------------------------------------
167 * This procedure initializes the Macintosh menu bar.
175 *----------------------------------------------------------------------
185 * At this point, InitMenus() should have already been called.
188 if (TkMacUseMenuID(256) != TCL_OK) {
189 panic("Menu ID 256 is already in use!");
191 tkAppleMenu = NewMenu(256, "\p\024");
192 if (tkAppleMenu == NULL) {
193 panic("memory - menus");
195 InsertMenu(tkAppleMenu, 0);
196 AppendMenu(tkAppleMenu, "\pAbout Tcl & TkÉ");
197 AppendMenu(tkAppleMenu, "\p(-");
198 AddResMenu(tkAppleMenu, 'DRVR');
200 if (TkMacUseMenuID(kFileMenu) != TCL_OK) {
201 panic("Menu ID %d is already in use!", kFileMenu);
203 tkFileMenu = NewMenu(kFileMenu, "\pFile");
204 if (tkFileMenu == NULL) {
205 panic("memory - menus");
207 InsertMenu(tkFileMenu, 0);
208 AppendMenu(tkFileMenu, "\pSourceÉ");
209 AppendMenu(tkFileMenu, "\pClose/W");
210 AppendMenu(tkFileMenu, "\p(-");
211 AppendMenu(tkFileMenu, "\pQuit/Q");
213 if (TkMacUseMenuID(kEditMenu) != TCL_OK) {
214 panic("Menu ID %d is already in use!", kEditMenu);
216 tkEditMenu = NewMenu(kEditMenu, "\pEdit");
217 if (tkEditMenu == NULL) {
218 panic("memory - menus");
220 InsertMenu(tkEditMenu, 0);
221 AppendMenu(tkEditMenu, "\pCut/X");
222 AppendMenu(tkEditMenu, "\pCopy/C");
223 AppendMenu(tkEditMenu, "\pPaste/V");
224 AppendMenu(tkEditMenu, "\pClear");
225 if (TkMacUseMenuID(kHMHelpMenuID) != TCL_OK) {
226 panic("Help menu ID %s is already in use!", kHMHelpMenuID);
230 TkMacSetHelpMenuItemCount();
236 *----------------------------------------------------------------------
238 * GenerateEditEvent --
240 * Takes an edit menu item and posts the corasponding a virtual
241 * event to Tk's event queue.
247 * May place events of queue.
249 *----------------------------------------------------------------------
262 if (TkMacHaveAppearance() >= 0x110) {
263 window = TkMacGetXWindow(FrontNonFloatingWindow());
265 window = TkMacGetXWindow(FrontWindow());
267 dispPtr = TkGetDisplayList();
268 tkwin = Tk_IdToWindow(dispPtr->display, window);
269 tkwin = (Tk_Window) ((TkWindow *) tkwin)->dispPtr->focusPtr;
274 event.type = VirtualEvent;
275 event.serial = Tk_Display(tkwin)->request;
276 event.send_event = false;
277 event.display = Tk_Display(tkwin);
278 event.event = Tk_WindowId(tkwin);
279 event.root = XRootWindow(Tk_Display(tkwin), 0);
280 event.subwindow = None;
281 event.time = TkpGetMS();
284 tkwin = Tk_TopCoordsToWindow(tkwin, where.h, where.v,
286 LocalToGlobal(&where);
287 event.x_root = where.h;
288 event.y_root = where.v;
289 event.state = TkMacButtonKeyState();
290 event.same_screen = true;
294 event.name = Tk_GetUid("Cut");
298 event.name = Tk_GetUid("Copy");
302 event.name = Tk_GetUid("Paste");
306 event.name = Tk_GetUid("Clear");
309 Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
313 *----------------------------------------------------------------------
317 * Presents a dialog to the user for selecting a Tcl file. The
318 * selected file will be sourced into the main interpreter.
326 *----------------------------------------------------------------------
334 char openCmd[] = "tk_getOpenFile -filetypes {\
335 {{TCL Scripts} {.tcl} TEXT} {{Text Files} {} TEXT}}";
337 if (gInterp == NULL) {
341 if (Tcl_Eval(gInterp, openCmd) != TCL_OK) {
345 path = Tcl_GetStringResult(gInterp);
347 if (strlen(path) == 0) {
351 result = Tcl_EvalFile(gInterp, path);
352 if (result == TCL_ERROR) {
353 Tcl_BackgroundError(gInterp);