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