Logo ROOT   6.08/07
Reference Guide
MenuLoader.mm
Go to the documentation of this file.
1 #include <cassert>
2 
3 #include <Cocoa/Cocoa.h>
4 
5 #include "CocoaConstants.h"
6 #include "MenuLoader.h"
7 #include "CocoaUtils.h"
8 
9 namespace ROOT {
10 namespace MacOSX {
11 namespace Details {
12 
13 //Fill ROOT's menu (standard Apple's menu at the top of desktop).
14 
15 void PopulateApplicationMenu(NSMenu *submenu);
16 void PopulateWindowMenu(NSMenu *submenu);
17 void PopulateHelpMenu(NSMenu *submenu);
18 
19 //Fill app's menu.
20 
21 //______________________________________________________________________________
23 {
24  const Util::AutoreleasePool pool;
25 
26  NSMenu * const mainMenu = [[NSMenu alloc] initWithTitle : @"NSMainMenu"];
27  const Util::NSScopeGuard<NSMenu> mainMenuGuard(mainMenu);
28 
29  // The strings in the menu bar come from the submenu titles,
30  // except for the application menu, whose title is ignored at runtime.
31  NSMenuItem *menuItem = [mainMenu addItemWithTitle : @"Apple" action : nil keyEquivalent:@""];
32  NSMenu *submenu = [[NSMenu alloc] initWithTitle : @"Apple"];
33  const Util::NSScopeGuard<NSMenu> submenuGuard1(submenu);
34 
35  PopulateApplicationMenu(submenu);
36  [mainMenu setSubmenu : submenu forItem : menuItem];
37 
38  menuItem = [mainMenu addItemWithTitle : @"Window" action : nil keyEquivalent : @""];
39  submenu = [[NSMenu alloc] initWithTitle : NSLocalizedString(@"Window", @"The Window menu")];
40  const Util::NSScopeGuard<NSMenu> submenuGuard2(submenu);
41  PopulateWindowMenu(submenu);
42  [mainMenu setSubmenu : submenu forItem : menuItem];
43  [NSApp setWindowsMenu : submenu];
44 
45  menuItem = [mainMenu addItemWithTitle:@"Help" action:NULL keyEquivalent:@""];
46  submenu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Help", @"The Help menu")];
47  const Util::NSScopeGuard<NSMenu> submenuGuard3(submenu);
48  PopulateHelpMenu(submenu);
49  [mainMenu setSubmenu : submenu forItem : menuItem];
50 
51  [NSApp setMainMenu : mainMenu];
52  [NSMenu setMenuBarVisible : YES];
53 }
54 
55 //______________________________________________________________________________
56 void PopulateApplicationMenu(NSMenu *aMenu)
57 {
58  assert(aMenu != nil && "PopulateApplicationMenu, aMenu parameter is nil");
59 
60  NSString * const applicationName = @"root";
61 
62  NSMenuItem *menuItem = [aMenu addItemWithTitle : [NSString stringWithFormat : @"%@ %@",
63  NSLocalizedString(@"About", nil), applicationName]
64  action : @selector(orderFrontStandardAboutPanel:) keyEquivalent : @""];
65  [menuItem setTarget : NSApp];
66  [aMenu addItem : [NSMenuItem separatorItem]];
67 
68  menuItem = [aMenu addItemWithTitle : [NSString stringWithFormat : @"%@ %@",
69  NSLocalizedString(@"Hide", nil), applicationName] action : @selector(hide:) keyEquivalent : @"h"];
70  [menuItem setTarget : NSApp];
71 
72  menuItem = [aMenu addItemWithTitle : NSLocalizedString(@"Hide Others", nil)
73  action : @selector(hideOtherApplications:) keyEquivalent : @"h"];
74  [menuItem setKeyEquivalentModifierMask : Details::kCommandKeyMask | Details::kAlternateKeyMask];
75  [menuItem setTarget : NSApp];
76 
77  menuItem = [aMenu addItemWithTitle : NSLocalizedString(@"Show All", nil)
78  action : @selector(unhideAllApplications:) keyEquivalent : @""];
79  [menuItem setTarget : NSApp];
80 
81  [aMenu addItem : [NSMenuItem separatorItem]];
82  menuItem = [aMenu addItemWithTitle : [NSString stringWithFormat : @"%@ %@",
83  NSLocalizedString(@"Quit", nil), applicationName] action : @selector(terminate:) keyEquivalent : @"q"];
84  [menuItem setTarget : NSApp];
85 }
86 
87 //______________________________________________________________________________
88 void PopulateWindowMenu(NSMenu *aMenu)
89 {
90  assert(aMenu != nil && "PopulateWindowMenu, aMenu parameter is nil");
91 
92  NSMenuItem *menuItem = [aMenu addItemWithTitle : NSLocalizedString(@"Minimize", nil)
93  action : @selector(performMinimize:) keyEquivalent : @"m"];
94  menuItem = [aMenu addItemWithTitle : NSLocalizedString(@"Zoom", nil)
95  action : @selector(performZoom:) keyEquivalent : @""];
96  [aMenu addItem : [NSMenuItem separatorItem]];
97  menuItem = [aMenu addItemWithTitle : NSLocalizedString(@"Bring All to Front", nil)
98  action : @selector(arrangeInFront:) keyEquivalent : @""];
99 }
100 
101 //______________________________________________________________________________
102 void PopulateHelpMenu(NSMenu *aMenu)
103 {
104  NSMenuItem * const menuItem = [aMenu addItemWithTitle : [NSString stringWithFormat : @"%@ %@", @"root",
105  NSLocalizedString(@"Help", nil)] action : @selector(showHelp:) keyEquivalent : @"?"];
106  [menuItem setTarget : NSApp];
107 }
108 
109 }//Detail
110 }//MacOSX
111 }//ROOT
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const NSUInteger kAlternateKeyMask
void PopulateApplicationMenu(NSMenu *submenu)
Definition: MenuLoader.mm:56
const NSUInteger kCommandKeyMask
void PopulateWindowMenu(NSMenu *submenu)
Definition: MenuLoader.mm:88
#define NULL
Definition: Rtypes.h:82
void PopulateHelpMenu(NSMenu *submenu)
Definition: MenuLoader.mm:102