43 #ifdef QT_MAC_USE_COCOA 46 #include <private/qcocoamenuloader_mac_p.h> 47 #include <private/qapplication_p.h> 48 #include <private/qt_mac_p.h> 49 #include <private/qmenubar_p.h> 51 #include <private/qt_cocoa_helpers_mac_p.h> 56 #ifndef QT_NO_TRANSLATION 64 @implementation QT_MANGLE_NAMESPACE(QCocoaMenuLoader)
68 servicesItem = [[appMenu itemWithTitle:@"Services"] retain];
69 hideAllOthersItem = [[appMenu itemWithTitle:@"Hide Others"] retain];
70 showAllItem = [[appMenu itemWithTitle:@"Show All"] retain];
74 [quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
75 withString:const_cast<NSString *>(appName)]];
76 [hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
77 withString:const_cast<NSString *>(appName)]];
78 [aboutItem setTitle:[[aboutItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
79 withString:const_cast<NSString *>(appName)]];
83 [preferencesItem setEnabled:NO];
84 [preferencesItem setHidden:YES];
85 [aboutItem setEnabled:NO];
86 [aboutItem setHidden:YES];
89 - (void)ensureAppMenuInMenu:(NSMenu *)menu
95 NSMenu *mainMenu = [NSApp mainMenu];
96 if ([NSApp mainMenu] == menu)
103 int numItems = [mainMenu numberOfItems];
105 for (
int i = 0; i < numItems; ++i) {
107 if ([item submenu] == appMenu) {
108 oldAppMenuItem = item;
109 [oldAppMenuItem retain];
110 [mainMenu removeItemAtIndex:i];
115 if (oldAppMenuItem) {
116 [oldAppMenuItem setSubmenu:nil];
117 [oldAppMenuItem release];
119 action:nil keyEquivalent:@""];
120 [appMenuItem setSubmenu:appMenu];
121 [menu insertItem:appMenuItem atIndex:0];
125 - (void)removeActionsFromAppMenu
133 [servicesItem release];
134 [hideAllOthersItem release];
135 [showAllItem release];
137 [lastAppSpecificItem release];
145 return [[theMenu retain] autorelease];
148 - (NSMenu *)applicationMenu
150 return [[appMenu retain] autorelease];
155 return [[quitItem retain] autorelease];
160 return [[preferencesItem retain] autorelease];
165 return [[aboutItem retain] autorelease];
170 return [[aboutQtItem retain] autorelease];
175 return [[hideItem retain] autorelease];
185 if (lastAppSpecificItem == nil) {
186 location = [appMenu indexOfItem:aboutQtItem];
188 location = [appMenu indexOfItem:lastAppSpecificItem];
189 [lastAppSpecificItem release];
191 lastAppSpecificItem = item;
192 [appMenu insertItem:item atIndex:location + 1];
194 return [[item retain] autorelease];
197 - (BOOL) acceptsFirstResponder
202 - (void)terminate:(
id)sender
204 [NSApp terminate:sender];
207 - (void)orderFrontStandardAboutPanel:(
id)sender
209 [NSApp orderFrontStandardAboutPanel:sender];
212 - (void)hideOtherApplications:(
id)sender
214 [NSApp hideOtherApplications:sender];
217 - (void)unhideAllApplications:(
id)sender
219 [NSApp unhideAllApplications:sender];
222 - (void)hide:(
id)sender
227 - (void)qtUpdateMenubar
232 - (void)qtTranslateApplicationMenu
234 #ifndef QT_NO_TRANSLATION 235 [servicesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(0))];
236 [hideItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(1).arg(qAppName()))];
237 [hideAllOthersItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(2))];
238 [showAllItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(3))];
239 [preferencesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(4))];
240 [quitItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(5).arg(qAppName()))];
241 [aboutItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(6).arg(qAppName()))];
245 - (IBAction)qtDispatcherToQAction:(
id)sender
249 if (
QAction *action = reinterpret_cast<QAction *>([item tag])) {
251 }
else if (item == quitItem) {
259 - (void)orderFrontCharacterPalette:(
id)sender
261 [NSApp orderFrontCharacterPalette:sender];
264 - (BOOL)validateMenuItem:(
NSMenuItem*)menuItem
266 if ([menuItem action] ==
@selector(hide:)
267 || [menuItem action] ==
@selector(hideOtherApplications:)
268 || [menuItem action] ==
@selector(unhideAllApplications:)) {
269 return [NSApp validateMenuItem:menuItem];
271 return [menuItem isEnabled];
276 #endif // QT_MAC_USE_COCOA
#define QT_END_NAMESPACE
This macro expands to.
static CFStringRef toCFStringRef(const QString &str)
static QApplicationPrivate * instance()
The QString class provides a Unicode character string.
#define QT_FORWARD_DECLARE_CLASS(name)
#define QT_BEGIN_NAMESPACE
This macro expands to.
QString qt_mac_applicationmenu_string(int type)
em>Reimplemented Function
static QTestResult::TestLocation location
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
The QAction class provides an abstract user interface action that can be inserted into widgets...