46 #include <private/qt_mac_p.h> 56 #include <private/qapplication_p.h> 57 #include <private/qcocoaapplication_mac_p.h> 58 #include <private/qmenu_p.h> 59 #include <private/qmenubar_p.h> 60 #include <private/qcocoamenuloader_mac_p.h> 61 #include <private/qcocoamenu_mac_p.h> 62 #include <private/qt_cocoa_helpers_mac_p.h> 63 #include <Cocoa/Cocoa.h> 80 #ifndef QT_MAC_USE_COCOA 127 #ifndef QT_MAC_USE_COCOA 129 const int items = CountMenuItems(menu);
130 for(
int i = 0; i < items; i++) {
131 MenuItemAttributes attr;
132 if (GetMenuItemAttributes(menu, i+1, &attr) == noErr &&
133 attr & kMenuItemAttrHidden)
139 return [menu numberOfItems];
149 #ifndef QT_MAC_USE_COCOA 150 if ((accel_key &
Qt::ALT) == Qt::ALT)
151 ret |= kMenuOptionModifier;
152 if ((accel_key &
Qt::SHIFT) == Qt::SHIFT)
153 ret |= kMenuShiftModifier;
155 if ((accel_key &
Qt::META) != Qt::META)
156 ret |= kMenuNoCommandModifier;
157 if ((accel_key &
Qt::CTRL) == Qt::CTRL)
158 ret |= kMenuControlModifier;
160 if ((accel_key &
Qt::CTRL) != Qt::CTRL)
161 ret |= kMenuNoCommandModifier;
162 if ((accel_key &
Qt::META) == Qt::META)
163 ret |= kMenuControlModifier;
166 if ((accel_key &
Qt::CTRL) == Qt::CTRL)
167 ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask);
169 ret |= (dontSwap ? NSCommandKeyMask : NSControlKeyMask);
170 if ((accel_key & Qt::ALT) ==
Qt::ALT)
171 ret |= NSAlternateKeyMask;
172 if ((accel_key & Qt::SHIFT) ==
Qt::SHIFT)
173 ret |= NSShiftKeyMask;
180 #ifdef QT_MAC_USE_COCOA 182 NSMenu *mainMenu = [NSApp mainMenu];
183 [mainMenu cancelTracking];
184 for (
NSMenuItem *item in [mainMenu itemArray]) {
185 if ([item submenu]) {
186 [[item submenu] cancelTracking];
190 CancelMenuTracking(AcquireRootMenu(),
true, 0);
208 #ifndef QT_MAC_USE_COCOA 216 sizeof(list), 0, &list);
224 for(
int i = 0; i < list->
size(); ++i) {
252 if (
QMenu *qmenu2 = qobject_cast<QMenu*>(caused))
253 caused_menu = qmenu2->macMenu();
254 else if (
QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused))
255 caused_menu = qmenubar2->macMenu();
262 if (
QMenu *qmenu = qobject_cast<QMenu*>(widget)) {
273 sizeof(caused), 0, &caused) != noErr)
275 if (
QMenu *qmenu2 = qobject_cast<QMenu*>(caused))
276 caused_menu = qmenu2->macMenu();
277 else if (
QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused))
278 caused_menu = qmenubar2->macMenu();
289 MenuItemIndex ret_idx;
291 if (GetIndMenuItemWithCommandID(menu, cmd, 1, &ret_menu, &ret_idx) == noErr) {
292 if (ret_menu == menu)
306 { kEventClassMenu, kEventMenuMeasureItemWidth },
307 { kEventClassMenu, kEventMenuMeasureItemHeight },
308 { kEventClassMenu, kEventMenuDrawItem },
309 { kEventClassMenu, kEventMenuCalculateSize }
314 UInt32 ekind = GetEventKind(event);
315 UInt32 eclass = GetEventClass(event);
316 OSStatus result = eventNotHandledErr;
318 case kEventClassMenu:
322 case kEventMenuMeasureItemWidth: {
324 GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex,
325 0,
sizeof(item), 0, &item);
327 GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0,
sizeof(menu), 0, &menu);
330 sizeof(widget), 0, &widget) == noErr) {
332 SetEventParameter(event, kEventParamMenuItemWidth, typeSInt16,
333 sizeof(
short), &width);
337 case kEventMenuMeasureItemHeight: {
339 GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex,
340 0,
sizeof(item), 0, &item);
342 GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0,
sizeof(menu), 0, &menu);
345 sizeof(widget), 0, &widget) == noErr && widget) {
347 SetEventParameter(event, kEventParamMenuItemHeight, typeSInt16,
348 sizeof(
short), &height);
352 case kEventMenuDrawItem:
355 case kEventMenuCalculateSize: {
356 result = CallNextEventHandler(er, event);
357 if (result == noErr) {
359 GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0,
sizeof(menu), 0, &menu);
361 HIMenuGetContentView(menu, kThemeMenuTypePullDown, &content);
362 UInt16 count = CountMenuItems(menu);
363 for (MenuItemIndex i = 1; i <= count; ++i) {
366 sizeof(widget), 0, &widget) == noErr && widget) {
368 GetControlRegion(content, i, itemRgn);
371 GetRegionBounds( itemRgn, &bounds );
374 bounds.right - bounds.left, bounds.bottom - bounds.top);
386 { kEventClassCommand, kEventCommandProcess },
387 { kEventClassMenu, kEventMenuTargetItem },
388 { kEventClassMenu, kEventMenuOpening },
389 { kEventClassMenu, kEventMenuClosed }
394 { kEventClassMenu, kEventMenuMatchKey }
401 bool handled_event =
true;
402 UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
404 case kEventClassCommand:
405 if (ekind == kEventCommandProcess) {
407 GetEventParameter(event, kEventParamMenuContext, typeUInt32,
408 0,
sizeof(context), 0, &context);
410 GetEventParameter(event, kEventParamDirectObject, typeHICommand,
411 0,
sizeof(cmd), 0, &cmd);
412 if (!mac_keyboard_grabber && (context & kMenuContextKeyMatching)) {
414 if (GetMenuCommandProperty(cmd.menu.menuRef, cmd.commandID,
kMenuCreatorQt,
417 if (
qApp->activePopupWidget())
418 widget = (
qApp->activePopupWidget()->focusWidget() ?
419 qApp->activePopupWidget()->focusWidget() :
qApp->activePopupWidget());
429 handled_event =
false;
439 case kEventClassMenu: {
441 GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL,
sizeof(menu), NULL, &menu);
442 if (ekind == kEventMenuMatchKey) {
446 return menuItemNotFoundErr;
448 handled_event =
false;
449 }
else if (ekind == kEventMenuTargetItem) {
451 GetEventParameter(event, kEventParamMenuCommand, typeMenuCommand,
452 0,
sizeof(command), 0, &command);
454 }
else if (ekind == kEventMenuOpening || ekind == kEventMenuClosed) {
457 GetEventParameter(event, kEventParamDirectObject, typeMenuRef,
458 0,
sizeof(mr), 0, &mr);
462 if (
QMenu *qmenu = qobject_cast<QMenu*>(widget)) {
463 handled_event =
true;
464 if (ekind == kEventMenuOpening) {
465 emit qmenu->aboutToShow();
470 for(
int i = 0; i < ActionItemsCount; ++i) {
476 }
else if (merged && merged == i) {
486 }
else if (!action->
merged) {
496 ChangeMenuItemAttributes(mr, index, kMenuItemAttrHidden, 0);
498 ChangeMenuItemAttributes(mr, index, 0, kMenuItemAttrHidden);
500 }
else if (action->
merged) {
505 emit qmenu->aboutToHide();
510 handled_event =
false;
514 handled_event =
false;
518 return CallNextEventHandler(er, event);
549 if (cmd == kHICommandQuit)
553 EnableMenuCommand(menu, cmd);
554 if (
MenuRef dock_menu = GetApplicationDockTileMenu())
555 EnableMenuCommand(dock_menu, cmd);
557 DisableMenuCommand(menu, cmd);
558 if (
MenuRef dock_menu = GetApplicationDockTileMenu())
559 DisableMenuCommand(dock_menu, cmd);
565 return (cmd == kHICommandPreferences || cmd == kHICommandQuit);
577 *key = kMenuReturnGlyph;
579 *key = kMenuEnterGlyph;
581 *key = kMenuTabRightGlyph;
583 *key = kMenuDeleteLeftGlyph;
585 *key = kMenuDeleteRightGlyph;
587 *key = kMenuEscapeGlyph;
589 *key = kMenuPageUpGlyph;
591 *key = kMenuPageDownGlyph;
593 *key = kMenuUpArrowGlyph;
595 *key = kMenuDownArrowGlyph;
597 *key = kMenuLeftArrowGlyph;
599 *key = kMenuRightArrowGlyph;
601 *key = kMenuCapsLockGlyph;
603 *key = (accel_key -
Qt::Key_F1) + kMenuF1Glyph;
605 *key = kMenuNorthwestArrowGlyph;
607 *key = kMenuSoutheastArrowGlyph;
611 static inline void syncNSMenuItemVisiblity(
NSMenuItem *menuItem,
bool actionVisibility)
613 [menuItem setHidden:NO];
614 [menuItem setHidden:YES];
615 [menuItem setHidden:!actionVisibility];
620 [menuItem setEnabled:NO];
621 [menuItem setEnabled:YES];
628 for (
int i = 0; i < menubarActions.
size(); ++i) {
642 initWithTitle:qt_mac_QStringToNSString(title)
643 action:
@selector(qtDispatcherToQAction:) keyEquivalent:
@""];
644 [item setTarget:nil];
654 #ifndef QT_MAC_USE_COCOA 655 for (
int i = 0; i < CountMenuItems(menu); i++) {
657 GetMenuItemHierarchicalMenu(menu, i+1, &submenu);
658 if (submenu != merge) {
662 DisableMenuItem(submenu, 0);
664 EnableMenuItem(submenu, 0);
668 bool modalWindowOnScreen =
qApp->activeModalWidget() != 0;
671 if (submenu != merge) {
678 syncNSMenuItemEnabled(item, action->
isEnabled());
680 syncNSMenuItemEnabled(item, YES);
691 [item setTarget:modalWindowOnScreen ? nil : getMenuLoader()];
693 syncNSMenuItemEnabled(item, NO);
703 #ifndef QT_MAC_USE_COCOA 706 sizeof(merge), 0, &merge);
710 UInt32 commands[] = { kHICommandQuit, kHICommandPreferences, kHICommandAbout,
kHICommandAboutQt, 0 };
711 for(
int c = 0; commands[
c];
c++) {
716 sizeof(action), 0, &action);
717 if (!action && merge) {
719 sizeof(action), 0, &action);
723 sizeof(list), 0, &list);
724 for(
int i = 0; list && i < list->
size(); ++i) {
735 if (commands[c] != kHICommandQuit)
757 #ifdef QT_MAC_USE_COCOA 767 [menuItem setHidden:YES];
769 && menuItem != [getMenuLoader() quitMenuItem]) {
770 [menuItem setHidden:YES];
772 [menuItem setTag:nil];
778 #ifndef QT_MAC_USE_COCOA 794 #ifndef QT_MAC_USE_COCOA 805 #ifndef QT_MAC_USE_COCOA 809 sizeof(list), 0, &list) == noErr && list) {
811 for(
int i = 0; i < list->
size(); ++i) {
813 if (item.
command == lastCustom)
823 ret = [loader appSpecificMenuItem];
827 #ifndef QT_MAC_USE_COCOA 828 ret = kHICommandAbout;
830 ret = [loader aboutMenuItem];
834 #ifndef QT_MAC_USE_COCOA 837 ret = [loader aboutQtMenuItem];
841 #ifndef QT_MAC_USE_COCOA 842 ret = kHICommandQuit;
844 ret = [loader quitMenuItem];
848 #ifndef QT_MAC_USE_COCOA 849 ret = kHICommandPreferences;
851 ret = [loader preferencesMenuItem];
858 #ifndef QT_MAC_USE_COCOA 859 ret = kHICommandAbout;
861 ret = [loader aboutMenuItem];
864 #ifndef QT_MAC_USE_COCOA 867 ret = [loader aboutQtMenuItem];
875 #ifndef QT_MAC_USE_COCOA 876 ret = kHICommandPreferences;
878 ret = [loader preferencesMenuItem];
882 #ifndef QT_MAC_USE_COCOA 883 ret = kHICommandQuit;
885 ret = [loader quitMenuItem];
892 #ifndef QT_MAC_USE_COCOA 895 sizeof(list), 0, &list) == noErr && list) {
896 for(
int i = 0; i < list->
size(); ++i) {
905 sizeof(cmd_action), 0, &cmd_action) == noErr && cmd_action)
909 for(
int i = 0; i < list->
size(); ++i) {
911 if (item.menuItem == ret && item.
action)
924 #ifdef QT_MAC_USE_COCOA 929 #ifndef QT_MAC_USE_COCOA 930 else if (action->
command == kHICommandAbout)
934 else if (action->
command == kHICommandPreferences)
936 else if (action->
command == kHICommandQuit)
939 else if (action->menuItem == [loader aboutMenuItem]) {
941 }
else if (action->menuItem == [loader aboutQtMenuItem]) {
946 }
else if (action->menuItem == [loader preferencesMenuItem]) {
948 }
else if (action->menuItem == [loader quitMenuItem]) {
958 #ifdef QT_MAC_USE_COCOA 963 #ifndef QT_MAC_USE_COCOA 964 else if (action->
command == kHICommandPreferences)
966 else if (action->
command == kHICommandQuit)
969 else if (action->menuItem == [loader preferencesMenuItem])
971 else if (action->menuItem == [loader quitMenuItem])
992 #ifndef QT_MAC_USE_COCOA 999 sizeof(list), 0, &list);
1000 for(
int i = 0; list && i < list->
size(); ) {
1002 if (item.
action == action)
1012 while (it != menu_eventHandlers_hash()->
end() && it.
key() ==
menu) {
1013 RemoveEventHandler(it.
value());
1016 menu_eventHandlers_hash()->remove(
menu);
1025 while (i < list->size()) {
1027 if (item.
action == action)
1049 #ifndef QT_MAC_USE_COCOA 1058 #ifdef QT_MAC_USE_COCOA 1065 if (before_index < 0) {
1071 #ifndef QT_MAC_USE_COCOA 1075 [action->
menu release];
1082 #ifndef QT_MAC_USE_COCOA 1085 sizeof(merge), 0, &merge);
1090 #ifndef QT_MAC_USE_COCOA 1093 action->
menu = merge;
1100 sizeof(list), 0, &list) != noErr || !list) {
1103 sizeof(list), &list);
1111 [action->
menu release];
1112 action->
menu = merge;
1114 [cmd setAction:
@selector(qtDispatcherToQAction:)];
1115 [cmd setTarget:nil];
1116 [action->menuItem release];
1117 action->menuItem = cmd;
1129 #ifdef QT_MAC_USE_COCOA 1133 #ifndef QT_MAC_USE_COCOA
1139 #ifndef QT_MAC_USE_COCOA 1140 index = before_index;
1141 MenuItemAttributes attr = kMenuItemAttrAutoRepeat;
1143 newItem = createNSMenuItem(action->
action->
text());
1144 action->menuItem = newItem;
1147 #ifndef QT_MAC_USE_COCOA 1148 InsertMenuItemTextWithCFString(action->
menu, 0,
qMax(before_index, 0), attr, action->
command);
1150 [
menu insertItem:newItem atIndex:
qMax(before_index, 0)];
1153 #ifndef QT_MAC_USE_COCOA 1160 mergedItems.
insert(kHICommandAbout);
1166 sizeof(list), 0, &list) == noErr && list) {
1167 for (
int i = 0; i < list->
size(); ++i) {
1168 MenuCommand command = list->
at(i).command;
1170 mergedItems.
insert(command);
1175 const int itemCount = CountMenuItems(action->
menu);
1176 MenuItemAttributes testattr;
1177 GetMenuItemAttributes(action->
menu, itemCount , &testattr);
1179 && (testattr & kMenuItemAttrSeparator)) {
1180 InsertMenuItemTextWithCFString(action->
menu, 0,
qMax(itemCount - 1, 0), attr, action->
command);
1183 MenuItemIndex tmpIndex;
1184 AppendMenuItemTextWithCFString(action->
menu, 0, attr, action->
command, &tmpIndex);
1187 AppendMenuItemTextWithCFString(action->
menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex);
1190 [
menu addItem:newItem];
1196 #ifndef QT_MAC_USE_COCOA 1197 ChangeMenuAttributes(action->
menu, kMenuAttrDoNotCacheImage, 0);
1198 attr = kMenuItemAttrCustomDraw;
1202 HIMenuGetContentView(action->
menu, kThemeMenuTypePullDown, &content);
1204 EventHandlerRef eventHandlerRef;
1208 menu_eventHandlers_hash()->insert(action->
menu, eventHandlerRef);
1212 sizeof(menuWidget), 0, &menuWidget);
1216 sizeof(menuWidget), &menuWidget);
1227 [containerView setAutoresizesSubviews:YES];
1228 [containerView setAutoresizingMask:NSViewWidthSizable];
1231 [newItem setView:containerView];
1238 #ifndef QT_MAC_USE_COCOA 1244 #ifndef QT_MAC_USE_COCOA 1246 sizeof(action), &action);
1248 [newItem setTag:long(static_cast<QAction *>(action->
action))];
1261 return [NSString stringWithCharacters:&cocoa_key.
unicode() length:1];
1276 #ifndef QT_MAC_USE_COCOA 1286 #ifndef QT_MAC_USE_COCOA 1288 ChangeMenuItemAttributes(action->
menu, index, kMenuItemAttrHidden, 0);
1291 ChangeMenuItemAttributes(action->
menu, index, 0, kMenuItemAttrHidden);
1296 [item setHidden:!actionVisible];
1301 #ifndef QT_MAC_USE_COCOA 1303 ChangeMenuItemAttributes(action->
menu, index, kMenuItemAttrSeparator, 0);
1306 ChangeMenuItemAttributes(action->
menu, index, 0, kMenuItemAttrSeparator);
1308 int itemIndex = [menu indexOfItem:item];
1311 action->menuItem = [
NSMenuItem separatorItem];
1312 [action->menuItem retain];
1313 [menu insertItem: action->menuItem atIndex:itemIndex];
1314 [menu removeItem:item];
1316 item = action->menuItem;
1318 }
else if ([item isSeparatorItem]) {
1320 action->menuItem = createNSMenuItem(action->
action->
text());
1321 [menu insertItem:action->menuItem atIndex:itemIndex];
1322 [menu removeItem:item];
1324 item = action->menuItem;
1348 if (accel.
count() > 1)
1353 #ifndef QT_MAC_USE_COCOA 1354 MenuItemDataRec
data;
1355 memset(&data,
'\0',
sizeof(data));
1358 data.whichData |= kMenuItemDataCFString;
1360 data.cfText = cfstring;
1363 data.whichData |= kMenuItemDataEnabled;
1366 data.whichData |= kMenuItemDataIconHandle;
1369 data.iconType = kMenuIconRefType;
1372 data.iconType = kMenuNoIcon;
1378 data.style |= underline;
1380 data.style |= italic;
1382 data.whichData |= kMenuItemDataStyle;
1383 data.whichData |= kMenuItemDataFontID;
1390 NSFont *customMenuFont = [NSFont fontWithName:qt_mac_QStringToNSString(actionFont.
family())
1392 NSArray *
keys = [NSArray arrayWithObjects:NSFontAttributeName, nil];
1393 NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil];
1394 NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:
keys];
1395 NSAttributedString *str = [[[NSAttributedString alloc] initWithString:qt_mac_QStringToNSString(finalString)
1396 attributes:attributes] autorelease];
1397 [item setAttributedTitle: str];
1399 [item setTitle: qt_mac_QStringToNSString(finalString)];
1403 [item setTitle:qt_mac_QStringToNSString(text)];
1411 NSImage *nsimage = 0;
1415 [item setImage:nsimage];
1420 #ifndef QT_MAC_USE_COCOA 1421 data.whichData |= kMenuItemDataSubmenuHandle;
1428 if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) {
1434 [item setSubmenu:subMenu];
1436 [item setAction:nil];
1439 #ifndef QT_MAC_USE_COCOA 1441 data.whichData |= kMenuItemDataCmdKey;
1442 data.whichData |= kMenuItemDataCmdKeyModifiers;
1443 data.whichData |= kMenuItemDataCmdKeyGlyph;
1444 if (accel.
count() == 1) {
1446 if (data.cmdKeyGlyph == 0)
1447 data.cmdKey = (UniChar)accel[0];
1450 [item setSubmenu:0];
1451 if ([item action] == nil)
1452 [item setAction:
@selector(qtDispatcherToQAction:)];
1454 if (accel.
count() == 1) {
1458 [item setKeyEquivalent:
@""];
1459 [item setKeyEquivalentModifierMask:NSCommandKeyMask];
1463 #ifndef QT_MAC_USE_COCOA 1465 data.whichData |= kMenuItemDataMark;
1470 data.mark = diamondMark;
1473 data.mark = checkMark;
1479 SetMenuItemData(action->
menu, action->
command,
true, &data);
1482 if (data.iconHandle)
1483 ReleaseIconRef(
IconRef(data.iconHandle));
1495 #ifndef QT_MAC_USE_COCOA 1496 if (action->
command == kHICommandQuit || action->
command == kHICommandPreferences)
1503 if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->
action) {
1505 [action->menuItem setEnabled:
false];
1506 if (action->menuItem != [loader quitMenuItem]
1507 && action->menuItem != [loader preferencesMenuItem]) {
1508 [[action->menuItem
menu] removeItem:action->menuItem];
1512 while (i < list->size()) {
1514 if (item.
action == action)
1522 [[action->menuItem
menu] removeItem:action->menuItem];
1539 #ifndef QT_MAC_USE_COCOA 1546 for(
int i = 0; i < items.
count(); i++)
1558 #ifndef QT_MAC_USE_COCOA 1560 ChangeMenuAttributes(
mac_menu->
menu, kMenuAttrCondenseSeparators, 0);
1562 ChangeMenuAttributes(
mac_menu->
menu, 0, kMenuAttrCondenseSeparators);
1564 qt_mac_menu_collapseSeparators(
mac_menu->
menu, collapse);
1570 #ifndef QT_MAC_USE_COCOA 1626 #ifndef QT_MAC_USE_COCOA 1630 sizeof(list), 0, &list);
1635 ReleaseMenu(apple_menu);
1640 [apple_menu release];
1653 #ifndef QT_MAC_USE_COCOA 1662 if (!action || !
menu)
1666 if (before_index < 0) {
1675 #ifdef QT_MAC_USE_COCOA 1677 [action->
menu retain];
1679 action->menuItem = newItem;
1682 #ifndef QT_MAC_USE_COCOA 1683 InsertMenuItemTextWithCFString(action->
menu, 0,
qMax(1, before_index+1), 0, action->
command);
1685 [
menu insertItem:newItem atIndex:
qMax(1, before_index + 1)];
1687 index = before_index;
1689 #ifndef QT_MAC_USE_COCOA 1690 AppendMenuItemTextWithCFString(action->
menu, 0, 0, action->
command, &index);
1692 [
menu addItem:newItem];
1695 #ifndef QT_MAC_USE_COCOA 1699 [newItem setTag:long(static_cast<QAction *>(action->
action))];
1707 if (!action || !
menu)
1709 #ifndef QT_MAC_USE_COCOA 1717 bool release_submenu =
false;
1720 #ifndef QT_MAC_USE_COCOA 1725 if ([submenu supermenu] && [submenu supermenu] != [item
menu])
1728 [item setSubmenu:submenu];
1731 #ifndef QT_MAC_USE_COCOA 1733 release_submenu =
true;
1734 CreateNewMenu(0, 0, &submenu);
1740 #ifndef QT_MAC_USE_COCOA 1741 SetMenuItemHierarchicalMenu(action->
menu, index, submenu);
1744 ChangeMenuAttributes(submenu, 0, kMenuAttrHidden);
1746 ChangeMenuAttributes(submenu, kMenuAttrHidden, 0);
1748 [item setSubmenu: submenu];
1750 syncNSMenuItemVisiblity(item, visible);
1753 if (release_submenu) {
1754 #ifndef QT_MAC_USE_COCOA 1755 ReleaseMenu(submenu);
1761 qWarning(
"QMenu: No OSMenuRef created for popup menu");
1768 if (!action || !
menu)
1770 #ifndef QT_MAC_USE_COCOA 1774 [action->
menu removeItem:action->menuItem];
1786 return menubars()->contains(widget->
window());
1793 static int dontUseNativeMenuBar = -1;
1798 bool qt_mac_no_native_menubar = !q->isNativeMenuBar();
1799 if (qt_mac_no_native_menubar ==
false && dontUseNativeMenuBar < 0) {
1805 bool environmentSaysNo = !
qgetenv(
"QT_MAC_NO_NATIVE_MENUBAR").
isEmpty();
1806 dontUseNativeMenuBar = isPlugin || environmentSaysNo;
1808 qt_mac_no_native_menubar = !q->isNativeMenuBar();
1810 if (qt_mac_no_native_menubar ==
false) {
1817 }
else if (parent && parent->
isWindow()) {
1818 menubars()->insert(q->window(), q);
1832 menubars()->remove(tlw);
1836 #ifdef QT_MAC_USE_COCOA 1838 [loader removeActionsFromAppMenu];
1850 if (!q->isNativeMenuBar() || !mac_menubar) {
1852 }
else if (!mac_menubar->
menu) {
1854 #ifdef QT_MAC_USE_COCOA 1855 [mac_menubar->
menu setAutoenablesItems:NO];
1857 ProcessSerialNumber mine, front;
1858 if (GetCurrentProcess(&mine) == noErr && GetFrontProcess(&front) == noErr) {
1861 #ifndef QT_MAC_USE_COCOA 1862 MenuItemIndex
index;
1863 AppendMenuItemTextWithCFString(mac_menubar->
menu, 0, 0, 0, &index);
1866 SetMenuItemHierarchicalMenu(mac_menubar->
menu, index, mac_menubar->
apple_menu);
1871 [apple_menuItem setSubmenu:mac_menubar->
menu];
1872 [mac_menubar->
apple_menu addItem:apple_menuItem];
1873 [apple_menuItem release];
1877 #ifndef QT_MAC_USE_COCOA 1885 for(
int i = 0; i < items.
count(); i++)
1889 return mac_menubar->
menu;
1912 if (!possibleAncestor)
1916 while (current != 0) {
1917 if (current == possibleAncestor)
1935 if (menuBar && menuBar == menubars()->value(modalWidget))
1947 for (
int i=0; i<topLevelWidgets.
size(); ++i) {
1977 for(
int i = 0; i < tlws.
size(); ++i) {
1993 mb = menubars()->value(w);
1994 #ifndef QT_NO_MAINWINDOW 1998 if (mw && (mb = menubars()->value(mw)))
2020 #ifndef QT_MAC_USE_COCOA 2022 if (CreateNewMenu(0, 0, &clear_menu) == noErr) {
2023 SetRootMenu(clear_menu);
2024 ReleaseMenu(clear_menu);
2026 qWarning(
"QMenu: Internal error at %s:%d", __FILE__, __LINE__);
2035 [loader ensureAppMenuInMenu:
menu];
2036 [NSApp setMainMenu:
menu];
2057 #ifdef QT_MAC_USE_COCOA 2059 qt_cocoaPostMessage(getMenuLoader(),
@selector(qtUpdateMenubar));
2080 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
2081 qt_mac_app_fullscreen =
true;
2087 SetSystemUIMode(kUIModeAllHidden, 0);
2088 qt_mac_app_fullscreen =
true;
2094 #ifdef QT_MAC_USE_COCOA 2098 #ifndef QT_MAC_USE_COCOA 2102 [loader ensureAppMenuInMenu:
menu];
2103 [NSApp setMainMenu:
menu];
2104 syncMenuBarItemsVisiblity(mb->d_func()->mac_menubar);
2109 const int mergeListSize = mergeList->size();
2111 for (
int i = 0; i < mergeListSize; ++i) {
2116 [mergeItem.menuItem setTag:
reinterpret_cast<long>(
2138 #ifndef QT_MAC_USE_COCOA 2142 [loader ensureAppMenuInMenu:
menu];
2143 [NSApp setMainMenu:
menu];
2163 #ifndef QT_MAC_USE_COCOA 2166 sizeof(merge), 0, &merge);
2170 sizeof(list), 0, &list) == noErr && list) {
2171 for(
int i = 0; i < list->
size(); ++i) {
2181 for(
int i = 0; i < list->size(); ++i) {
2196 #ifndef QT_MAC_USE_COCOA 2198 if (CreateNewMenu(0, 0, &ret) == noErr) {
2204 EventHandlerRef eventHandlerRef;
2208 menu_eventHandlers_hash()->insert(ret, eventHandlerRef);
2213 if (
QMenu *qmenu = qobject_cast<QMenu *>(w)){
2216 ret = [[NSMenu alloc]
init];
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
T qobject_cast(QObject *object)
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QWidgetList topLevelWidgets()
The QKeyEvent class describes a key event.
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
int remove(const Key &key)
Removes all the items that have the key from the hash.
QKeySequence shortcut
the action's primary shortcut key
The QRegExp class provides pattern matching using regular expressions.
bool showStatusText(QWidget *widget=0)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent w...
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false...
#define it(className, varName)
bool underline() const
Returns true if underline has been set; otherwise returns false.
ActionEvent
This enum type is used when calling QAction::activate()
QString & replace(int i, int len, QChar after)
int length() const
Returns the number of characters in this string.
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
QString text
the action's descriptive text
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void insert(int i, const T &t)
Inserts value at index position i in the list.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QApplicationPrivate * instance()
void * qt_mac_create_nsimage(const QPixmap &pm)
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
T & value() const
Returns a modifiable reference to the current item's value.
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
The QObject class is the base class of all Qt objects.
The QChar class provides a 16-bit Unicode character.
const T value(const Key &key) const
Returns the value associated with the key.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
QString qt_mac_removeMnemonics(const QString &original)
MenuRole menuRole
the action's menu role
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static QWidget * focus_widget
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
int width() const
Returns the width.
void append(const T &t)
Inserts value at the end of the list.
bool isIconVisibleInMenu() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
QString qt_mac_applicationmenu_string(int type)
em>Reimplemented Function
bool contains(const T &value) const
T takeFirst()
Removes the first item in the list and returns it.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
const T & at(int i) const
Returns the item at index position i in the list.
struct OpaqueControlRef * HIViewRef
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
QFont font
the action's font
Q_CORE_EXPORT void qWarning(const char *,...)
QIcon icon
the action's icon
const_iterator insert(const T &value)
int receivers(const char *signal) const
Returns the number of receivers connected to the signal.
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString toString(SequenceFormat format=PortableText) const
Return a string representation of the key sequence, based on format.
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
const Key & key() const
Returns the current item's key as a const reference.
struct OpaqueRgnHandle * RgnHandle
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
struct OpaqueEventRef * EventRef
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
bool bold() const
Returns true if weight() is a value greater than QFont::Normal ; otherwise returns false...
QMenu * menu() const
Returns the menu contained by this action.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
The QKeySequence class encapsulates a key sequence as used by shortcuts.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
The QFont class specifies a font used for drawing text.
static QCoreApplication * instance()
Returns a pointer to the application's QCoreApplication (or QApplication) instance.
#define QT_MANGLE_NAMESPACE(name)
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QString family() const
Returns the requested font family name, i.e.
bool qt_mac_app_fullscreen
#define st(var, type, card)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
The QMainWindow class provides a main application window.
int size() const
Returns the number of items in the list.
int height() const
Returns the height.
if(void) toggleToolbarShown
static bool native_modal_dialog_active
OSViewRef qt_mac_nativeview_for(const QWidget *)
uint count() const
Returns the number of keys in the key sequence.
QChar qtKey2CocoaKey(Qt::Key key)
struct OpaqueMenuRef * MenuRef
MenuRole
This enum describes how an action should be moved into the application menu on Mac OS X...
The QPixmap class is an off-screen image representation that can be used as a paint device...
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
int pointSize() const
Returns the point size of the font.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
QActionGroup * actionGroup() const
Returns the action group for this action.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
static const KeyPair *const end
The QEvent class is the base class of all event classes.
quint32 macFontID() const
Returns an ATSUFontID.
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
The QAction class provides an abstract user interface action that can be inserted into widgets...
void qt_event_request_menubarupdate()
struct OpaqueIconRef * IconRef
The QList class is a template class that provides lists.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
void removeAt(int i)
Removes the item at index position i.