diff options
Diffstat (limited to 'macosx/tkMacOSXMenus.c')
-rw-r--r-- | macosx/tkMacOSXMenus.c | 201 |
1 files changed, 102 insertions, 99 deletions
diff --git a/macosx/tkMacOSXMenus.c b/macosx/tkMacOSXMenus.c index f153ce6..e1b0446 100644 --- a/macosx/tkMacOSXMenus.c +++ b/macosx/tkMacOSXMenus.c @@ -1,17 +1,17 @@ /* * tkMacOSXMenus.c -- * - * These calls set up and manage the menubar for the - * Macintosh version of Tk. + * These calls set up and manage the menubar for the Macintosh version of + * Tk. * * Copyright (c) 1995-1996 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2001, Apple Computer, Inc. * Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net> * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXMenus.c,v 1.21 2007/12/13 15:27:10 dgp Exp $ + * RCS: @(#) $Id: tkMacOSXMenus.c,v 1.22 2008/10/05 18:22:21 dkf Exp $ */ #include "tkMacOSXPrivate.h" @@ -34,14 +34,13 @@ MenuRef tkAppleMenu; MenuRef tkFileMenu; MenuRef tkEditMenu; -static Tcl_Interp * gInterp = NULL; /* Standard menu interpreter. */ +static Tcl_Interp *gInterp = NULL; /* Standard menu interpreter. */ static EventHandlerRef menuEventHandlerRef = NULL; -static void GenerateEditEvent(int flag); -static Tcl_Obj* GetWidgetDemoPath(Tcl_Interp *interp); -static OSStatus MenuEventHandlerProc(EventHandlerCallRef callRef, - EventRef event, void *userData); - +static void GenerateEditEvent(int flag); +static Tcl_Obj * GetWidgetDemoPath(Tcl_Interp *interp); +static OSStatus MenuEventHandlerProc(EventHandlerCallRef callRef, + EventRef event, void *userData); /* *---------------------------------------------------------------------- @@ -59,11 +58,11 @@ static OSStatus MenuEventHandlerProc(EventHandlerCallRef callRef, *---------------------------------------------------------------------- */ -Tcl_Obj* +static Tcl_Obj * GetWidgetDemoPath( Tcl_Interp *interp) { - Tcl_Obj *libpath , *result = NULL; + Tcl_Obj *libpath, *result = NULL; libpath = Tcl_GetVar2Ex(gInterp, "tk_library", NULL, TCL_GLOBAL_ONLY); if (libpath) { @@ -102,6 +101,7 @@ TkMacOSXHandleMenuSelect( Tk_Window tkwin; Window window; TkDisplay *dispPtr; + Tcl_CmdInfo dummy; if (theItem == 0) { TkMacOSXClearMenubarActive(); @@ -109,89 +109,84 @@ TkMacOSXHandleMenuSelect( } switch (theMenu) { - case kAppleMenu: - switch (theItem) { - case kAppleAboutItem: - { - Tcl_CmdInfo dummy; - if (optionKeyPressed || gInterp == NULL || - Tcl_GetCommandInfo(gInterp, - "tkAboutDialog", &dummy) == 0) { - TkAboutDlg(); - } else { - if (Tcl_EvalEx(gInterp, "tkAboutDialog", -1, - TCL_EVAL_GLOBAL) != TCL_OK) { - Tcl_BackgroundError(gInterp); - } - Tcl_ResetResult(gInterp); - } - break; - } + case kAppleMenu: + switch (theItem) { + case kAppleAboutItem: + if (optionKeyPressed || gInterp == NULL || + Tcl_GetCommandInfo(gInterp, "tkAboutDialog", &dummy) == 0) { + TkAboutDlg(); + } else { + if (Tcl_EvalEx(gInterp, "tkAboutDialog", -1, + TCL_EVAL_GLOBAL) != TCL_OK) { + Tcl_BackgroundError(gInterp); + } + Tcl_ResetResult(gInterp); } break; - case kFileMenu: - switch (theItem) { - case kSourceItem: - if (gInterp) { - if(Tcl_EvalEx(gInterp, "tk_getOpenFile -filetypes {" - "{{TCL Scripts} {.tcl} TEXT} " - "{{Text Files} {} TEXT}}", -1, TCL_EVAL_GLOBAL) - == TCL_OK) { - Tcl_Obj *path = Tcl_GetObjResult(gInterp); - int len; - - Tcl_GetStringFromObj(path, &len); - if (len) { - Tcl_IncrRefCount(path); - if (Tcl_FSEvalFile(gInterp, path) - == TCL_ERROR) { - Tcl_BackgroundError(gInterp); - } - Tcl_DecrRefCount(path); - } - } - Tcl_ResetResult(gInterp); - } - break; - case kDemoItem: - if (gInterp) { - Tcl_Obj *path = GetWidgetDemoPath(gInterp); - - if (path) { - Tcl_IncrRefCount(path); - if (Tcl_FSEvalFile(gInterp, path) - == TCL_ERROR) { - Tcl_BackgroundError(gInterp); - } - Tcl_DecrRefCount(path); - Tcl_ResetResult(gInterp); + } + break; + case kFileMenu: + switch (theItem) { + case kSourceItem: + if (gInterp) { + if (Tcl_EvalEx(gInterp, "tk_getOpenFile -filetypes {" + "{{TCL Scripts} {.tcl} TEXT} {{Text Files} {} TEXT}}", + -1, TCL_EVAL_GLOBAL) == TCL_OK) { + Tcl_Obj *path = Tcl_GetObjResult(gInterp); + int len; + + Tcl_GetStringFromObj(path, &len); + if (len) { + Tcl_IncrRefCount(path); + if (Tcl_FSEvalFile(gInterp, path) == TCL_ERROR) { + Tcl_BackgroundError(gInterp); } + Tcl_DecrRefCount(path); } - break; - case kCloseItem: - /* Send close event */ - window = TkMacOSXGetXWindow(ActiveNonFloatingWindow()); - dispPtr = TkGetDisplayList(); - tkwin = Tk_IdToWindow(dispPtr->display, window); - TkGenWMDestroyEvent(tkwin); - break; + } + Tcl_ResetResult(gInterp); } break; - case kEditMenu: - /* - * This implementation just send the keysyms Tk thinks are - * associated with function keys that do Cut, Copy & Paste on - * a Sun keyboard. - */ - GenerateEditEvent(theItem); + case kDemoItem: + if (gInterp) { + Tcl_Obj *path = GetWidgetDemoPath(gInterp); + + if (path) { + Tcl_IncrRefCount(path); + if (Tcl_FSEvalFile(gInterp, path) == TCL_ERROR) { + Tcl_BackgroundError(gInterp); + } + Tcl_DecrRefCount(path); + Tcl_ResetResult(gInterp); + } + } break; - default: - TkMacOSXDispatchMenuEvent(theMenu, theItem); + case kCloseItem: + /* Send close event */ + window = TkMacOSXGetXWindow(ActiveNonFloatingWindow()); + dispPtr = TkGetDisplayList(); + tkwin = Tk_IdToWindow(dispPtr->display, window); + TkGenWMDestroyEvent(tkwin); break; + } + break; + case kEditMenu: + /* + * This implementation just send the keysyms Tk thinks are associated + * with function keys that do Cut, Copy & Paste on a Sun keyboard. + */ + + GenerateEditEvent(theItem); + break; + default: + TkMacOSXDispatchMenuEvent(theMenu, theItem); + break; } + /* * Finally we unhighlight the menu. */ + HiliteMenu(0); } @@ -327,6 +322,7 @@ TkMacOSXInitMenus( * kEventCommandUpdateStatus handler), unless the kHICommandPreferences * menu item has previously been enabled manually. [Bug 1481503] */ + EnableMenuCommand(NULL, kHICommandPreferences); DrawMenuBar(); @@ -338,8 +334,8 @@ TkMacOSXInitMenus( * * GenerateEditEvent -- * - * Takes an edit menu item and posts the corasponding a virtual - * event to Tk's event queue. + * Takes an edit menu item and posts the corasponding a virtual event to + * Tk's event queue. * * Results: * None. @@ -384,18 +380,25 @@ GenerateEditEvent( event.same_screen = true; switch (flag) { - case EDIT_CUT: - event.name = Tk_GetUid("Cut"); - break; - case EDIT_COPY: - event.name = Tk_GetUid("Copy"); - break; - case EDIT_PASTE: - event.name = Tk_GetUid("Paste"); - break; - case EDIT_CLEAR: - event.name = Tk_GetUid("Clear"); - break; + case EDIT_CUT: + event.name = Tk_GetUid("Cut"); + break; + case EDIT_COPY: + event.name = Tk_GetUid("Copy"); + break; + case EDIT_PASTE: + event.name = Tk_GetUid("Paste"); + break; + case EDIT_CLEAR: + event.name = Tk_GetUid("Clear"); + break; } Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL); } + +/* + * Local Variables: + * fill-column: 78 + * c-basic-offset: 4 + * End: + */ |