Qt 4.8
Public Functions | Public Variables | List of all members
QMenuPrivate::QMacMenuPrivate Struct Reference

#include <qmenu_p.h>

Public Functions

void addAction (QAction *, QMacMenuAction *=0, QMenuPrivate *qmenu=0)
 
void addAction (QMacMenuAction *, QMacMenuAction *=0, QMenuPrivate *qmenu=0)
 
QMacMenuActionfindAction (QAction *a)
 
bool merged (const QAction *action) const
 
 QMacMenuPrivate ()
 
void removeAction (QMacMenuAction *)
 
void removeAction (QAction *a)
 
void syncAction (QMacMenuAction *)
 
void syncAction (QAction *a)
 
 ~QMacMenuPrivate ()
 

Public Variables

QList< QMacMenuAction * > actionItems
 
OSMenuRef menu
 

Detailed Description

Definition at line 307 of file qmenu_p.h.

Constructors and Destructors

◆ QMacMenuPrivate()

QMenuPrivate::QMacMenuPrivate::QMacMenuPrivate ( )

Definition at line 986 of file qmenu_mac.mm.

Referenced by QMenuPrivate::macMenu().

986  : menu(0)
987 {
988 }

◆ ~QMacMenuPrivate()

QMenuPrivate::QMacMenuPrivate::~QMacMenuPrivate ( )

Definition at line 990 of file qmenu_mac.mm.

991 {
992 #ifndef QT_MAC_USE_COCOA
994  QMacMenuAction *action = (*it);
995  RemoveMenuCommandProperty(action->menu, action->command, kMenuCreatorQt, kMenuPropertyQAction);
996  if (action->merged) {
997  QMenuMergeList *list = 0;
998  GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
999  sizeof(list), 0, &list);
1000  for(int i = 0; list && i < list->size(); ) {
1001  QMenuMergeItem item = list->at(i);
1002  if (item.action == action)
1003  list->removeAt(i);
1004  else
1005  ++i;
1006  }
1007  }
1008  delete action;
1009  }
1010  if (menu) {
1011  EventHandlerHash::iterator it = menu_eventHandlers_hash()->find(menu);
1012  while (it != menu_eventHandlers_hash()->end() && it.key() == menu) {
1013  RemoveEventHandler(it.value());
1014  ++it;
1015  }
1016  menu_eventHandlers_hash()->remove(menu);
1017  ReleaseMenu(menu);
1018  }
1019 #else
1021  while (actionItems.size()) {
1022  QMacMenuAction *action = actionItems.takeFirst();
1023  if (QMenuMergeList *list = mergeMenuItemsHash.value(action->menu)) {
1024  int i = 0;
1025  while (i < list->size()) {
1026  const QMenuMergeItem &item = list->at(i);
1027  if (item.action == action)
1028  list->removeAt(i);
1029  else
1030  ++i;
1031  }
1032  }
1033  delete action;
1034  }
1036  mergeMenuItemsHash.remove(menu);
1037  [menu release];
1038 #endif
1039 }
uint command
Definition: qmenu_p.h:102
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
#define it(className, varName)
QMacMenuAction * action
Definition: qmenu_p.h:121
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QList< QMacMenuAction * > actionItems
Definition: qmenu_p.h:308
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
static QHash< OSMenuRef, OSMenuRef > mergeMenuHash
Definition: qmenu_p.h:334
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
OSMenuRef menu
Definition: qmenu_p.h:109
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QHash< OSMenuRef, QMenuMergeList * > mergeMenuItemsHash
Definition: qmenu_p.h:335
static const KeyPair *const end
uchar merged
Definition: qmenu_p.h:107
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

Functions

◆ addAction() [1/2]

void QMenuPrivate::QMacMenuPrivate::addAction ( QAction a,
QMacMenuAction before = 0,
QMenuPrivate qmenu = 0 
)

Definition at line 1042 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::QMacMenuBarPrivate::addAction(), and QMenuPrivate::macMenu().

1043 {
1044  QMacMenuAction *action = new QMacMenuAction;
1045  action->action = a;
1046  action->ignore_accel = 0;
1047  action->merged = 0;
1048  action->menu = 0;
1049 #ifndef QT_MAC_USE_COCOA
1050  action->command = qt_mac_menu_static_cmd_id++;
1051 #endif
1052  addAction(action, before, qmenu);
1053 }
uchar ignore_accel
Definition: qmenu_p.h:106
uint command
Definition: qmenu_p.h:102
long ASN1_INTEGER_get ASN1_INTEGER * a
OSMenuRef menu
Definition: qmenu_p.h:109
QPointer< QAction > action
Definition: qmenu_p.h:108
void addAction(QAction *, QMacMenuAction *=0, QMenuPrivate *qmenu=0)
Definition: qmenu_mac.mm:1042
uchar merged
Definition: qmenu_p.h:107
static uint qt_mac_menu_static_cmd_id
Definition: qmenu_mac.mm:81

◆ addAction() [2/2]

void QMenuPrivate::QMacMenuPrivate::addAction ( QMacMenuAction action,
QMacMenuAction before = 0,
QMenuPrivate qmenu = 0 
)

Definition at line 1056 of file qmenu_mac.mm.

1057 {
1058 #ifdef QT_MAC_USE_COCOA
1060  Q_UNUSED(qmenu);
1061 #endif
1062  if (!action)
1063  return;
1064  int before_index = actionItems.indexOf(before);
1065  if (before_index < 0) {
1066  before = 0;
1067  before_index = actionItems.size();
1068  }
1069  actionItems.insert(before_index, action);
1070 
1071 #ifndef QT_MAC_USE_COCOA
1072  int index = qt_mac_menu_find_action(menu, action);
1073 #else
1074  [menu retain];
1075  [action->menu release];
1076 #endif
1077  action->menu = menu;
1078 
1079  /* When the action is considered a mergable action it
1080  will stay that way, until removed.. */
1081  if (!qt_mac_no_menubar_merge) {
1082 #ifndef QT_MAC_USE_COCOA
1083  MenuRef merge = 0;
1084  GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu,
1085  sizeof(merge), 0, &merge);
1086 #else
1088 #endif
1089  if (merge) {
1090 #ifndef QT_MAC_USE_COCOA
1091  if (MenuCommand cmd = qt_mac_menu_merge_action(merge, action)) {
1092  action->merged = 1;
1093  action->menu = merge;
1094  action->command = cmd;
1095  if (qt_mac_auto_apple_menu(cmd))
1096  index = 0; //no need
1097 
1098  QMenuMergeList *list = 0;
1099  if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
1100  sizeof(list), 0, &list) != noErr || !list) {
1101  list = new QMenuMergeList;
1102  SetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
1103  sizeof(list), &list);
1104  }
1105  list->append(QMenuMergeItem(cmd, action));
1106  }
1107 #else
1108  if (NSMenuItem *cmd = qt_mac_menu_merge_action(merge, action)) {
1109  action->merged = 1;
1110  [merge retain];
1111  [action->menu release];
1112  action->menu = merge;
1113  [cmd retain];
1114  [cmd setAction:@selector(qtDispatcherToQAction:)];
1115  [cmd setTarget:nil];
1116  [action->menuItem release];
1117  action->menuItem = cmd;
1118  QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge);
1119  if (!list) {
1120  list = new QMenuMergeList;
1121  QMenuPrivate::mergeMenuItemsHash.insert(merge, list);
1122  }
1123  list->append(QMenuMergeItem(cmd, action));
1124  }
1125 #endif
1126  }
1127  }
1128 
1129 #ifdef QT_MAC_USE_COCOA
1130  NSMenuItem *newItem = action->menuItem;
1131 #endif
1132  if (
1133 #ifndef QT_MAC_USE_COCOA
1134  index == -1
1135 #else
1136  newItem == 0
1137 #endif
1138  ) {
1139 #ifndef QT_MAC_USE_COCOA
1140  index = before_index;
1141  MenuItemAttributes attr = kMenuItemAttrAutoRepeat;
1142 #else
1143  newItem = createNSMenuItem(action->action->text());
1144  action->menuItem = newItem;
1145 #endif
1146  if (before) {
1147 #ifndef QT_MAC_USE_COCOA
1148  InsertMenuItemTextWithCFString(action->menu, 0, qMax(before_index, 0), attr, action->command);
1149 #else
1150  [menu insertItem:newItem atIndex:qMax(before_index, 0)];
1151 #endif
1152  } else {
1153 #ifndef QT_MAC_USE_COCOA
1154  // Append the menu item to the menu. If it is a kHICommandAbout or a kHICommandAboutQt append
1155  // a separator also (to get a separator above "Preferences"), but make sure that we don't
1156  // add separators between two "about" items.
1157 
1158  // Build a set of all commands that could possibly be before the separator.
1159  QSet<MenuCommand> mergedItems;
1160  mergedItems.insert(kHICommandAbout);
1161  mergedItems.insert(kHICommandAboutQt);
1162  mergedItems.insert(kHICommandCustomMerge);
1163 
1164  QMenuMergeList *list = 0;
1165  if (GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
1166  sizeof(list), 0, &list) == noErr && list) {
1167  for (int i = 0; i < list->size(); ++i) {
1168  MenuCommand command = list->at(i).command;
1169  if (command > kHICommandCustomMerge) {
1170  mergedItems.insert(command);
1171  }
1172  }
1173  }
1174 
1175  const int itemCount = CountMenuItems(action->menu);
1176  MenuItemAttributes testattr;
1177  GetMenuItemAttributes(action->menu, itemCount , &testattr);
1178  if (mergedItems.contains(action->command)
1179  && (testattr & kMenuItemAttrSeparator)) {
1180  InsertMenuItemTextWithCFString(action->menu, 0, qMax(itemCount - 1, 0), attr, action->command);
1181  index = itemCount;
1182  } else {
1183  MenuItemIndex tmpIndex;
1184  AppendMenuItemTextWithCFString(action->menu, 0, attr, action->command, &tmpIndex);
1185  index = tmpIndex;
1186  if (mergedItems.contains(action->command))
1187  AppendMenuItemTextWithCFString(action->menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex);
1188  }
1189 #else
1190  [menu addItem:newItem];
1191 #endif
1192  }
1193 
1194  QWidget *widget = qmenu ? qmenu->widgetItems.value(action->action) : 0;
1195  if (widget) {
1196 #ifndef QT_MAC_USE_COCOA
1197  ChangeMenuAttributes(action->menu, kMenuAttrDoNotCacheImage, 0);
1198  attr = kMenuItemAttrCustomDraw;
1199  SetMenuItemProperty(action->menu, index, kMenuCreatorQt, kMenuPropertyWidgetActionWidget,
1200  sizeof(QWidget *), &widget);
1201  HIViewRef content;
1202  HIMenuGetContentView(action->menu, kThemeMenuTypePullDown, &content);
1203 
1204  EventHandlerRef eventHandlerRef;
1205  InstallMenuEventHandler(action->menu, qt_mac_widget_in_menu_eventHandler,
1206  GetEventTypeCount(widget_in_menu_events),
1207  widget_in_menu_events, 0, &eventHandlerRef);
1208  menu_eventHandlers_hash()->insert(action->menu, eventHandlerRef);
1209 
1210  QWidget *menuWidget = 0;
1211  GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyWidgetMenu,
1212  sizeof(menuWidget), 0, &menuWidget);
1213  if(!menuWidget) {
1214  menuWidget = new QMacNativeWidget(content);
1215  SetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyWidgetMenu,
1216  sizeof(menuWidget), &menuWidget);
1217  menuWidget->show();
1218  }
1219  widget->setParent(menuWidget);
1220 #else
1221  QMacNativeWidget *container = new QMacNativeWidget(0);
1222  container->resize(widget->sizeHint());
1224  widget->setParent(container);
1225 
1226  NSView *containerView = qt_mac_nativeview_for(container);
1227  [containerView setAutoresizesSubviews:YES];
1228  [containerView setAutoresizingMask:NSViewWidthSizable];
1229  [qt_mac_nativeview_for(widget) setAutoresizingMask:NSViewWidthSizable];
1230 
1231  [newItem setView:containerView];
1232  container->show();
1233 #endif
1234  widget->show();
1235  }
1236 
1237  } else {
1238 #ifndef QT_MAC_USE_COCOA
1240 #else
1241  [newItem setEnabled:!QApplicationPrivate::modalState()];
1242 #endif
1243  }
1244 #ifndef QT_MAC_USE_COCOA
1245  SetMenuCommandProperty(action->menu, action->command, kMenuCreatorQt, kMenuPropertyQAction,
1246  sizeof(action), &action);
1247 #else
1248  [newItem setTag:long(static_cast<QAction *>(action->action))];
1249 #endif
1250  syncAction(action);
1251 }
uint command
Definition: qmenu_p.h:102
bool qt_mac_no_menubar_merge
Definition: qmenu_mac.mm:74
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
QPointer< QWidget > widget
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QList< QMacMenuAction * > actionItems
Definition: qmenu_p.h:308
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
static void qt_mac_command_set_enabled(MenuRef menu, UInt32 cmd, bool b)
Definition: qmenu_mac.mm:547
static QHash< OSMenuRef, OSMenuRef > mergeMenuHash
Definition: qmenu_p.h:334
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void NSMenuItem
Definition: qmenu_p.h:80
static MenuCommand qt_mac_menu_merge_action(MenuRef merge, QMacMenuAction *action)
Definition: qmenu_mac.mm:779
static EventTypeSpec widget_in_menu_events[]
Definition: qmenu_mac.mm:305
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool contains(const T &value) const
Definition: qset.h:91
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
QHash< QAction *, QWidget * > widgetItems
Definition: qmenu_p.h:195
OSMenuRef menu
Definition: qmenu_p.h:109
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
struct OpaqueControlRef * HIViewRef
void syncAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1271
const_iterator insert(const T &value)
Definition: qset.h:179
void show()
Shows the widget and its child widgets.
MenuRef OSMenuRef
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287
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...
Definition: qlist.h:847
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
OSViewRef qt_mac_nativeview_for(const QWidget *)
Definition: qwidget_mac.mm:419
struct OpaqueMenuRef * MenuRef
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
static QHash< OSMenuRef, QMenuMergeList * > mergeMenuItemsHash
Definition: qmenu_p.h:335
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
QPointer< QAction > action
Definition: qmenu_p.h:108
uchar merged
Definition: qmenu_p.h:107
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static OSStatus qt_mac_widget_in_menu_eventHandler(EventHandlerCallRef er, EventRef event, void *)
Definition: qmenu_mac.mm:312
QList< QMenuMergeItem > QMenuMergeList
Definition: qmenu_p.h:123
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static bool qt_mac_auto_apple_menu(MenuCommand cmd)
Definition: qmenu_mac.mm:563

◆ findAction()

QMacMenuAction* QMenuPrivate::QMacMenuPrivate::findAction ( QAction a)
inline

Definition at line 320 of file qmenu_p.h.

Referenced by QMenuBarPrivate::QMacMenuBarPrivate::addAction().

320  {
321  for(int i = 0; i < actionItems.size(); i++) {
322  QMacMenuAction *act = actionItems[i];
323  if(a == act->action)
324  return act;
325  }
326  return 0;
327  }
QList< QMacMenuAction * > actionItems
Definition: qmenu_p.h:308
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ merged()

bool QMenuPrivate::QMacMenuPrivate::merged ( const QAction action) const

Definition at line 2161 of file qmenu_mac.mm.

2162 {
2163 #ifndef QT_MAC_USE_COCOA
2164  MenuRef merge = 0;
2165  GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu,
2166  sizeof(merge), 0, &merge);
2167  if (merge) {
2168  QMenuMergeList *list = 0;
2169  if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
2170  sizeof(list), 0, &list) == noErr && list) {
2171  for(int i = 0; i < list->size(); ++i) {
2172  QMenuMergeItem item = list->at(i);
2173  if (item.action->action == action)
2174  return true;
2175  }
2176  }
2177  }
2178 #else
2179  if (OSMenuRef merge = mergeMenuHash.value(menu)) {
2180  if (QMenuMergeList *list = mergeMenuItemsHash.value(merge)) {
2181  for(int i = 0; i < list->size(); ++i) {
2182  const QMenuMergeItem &item = list->at(i);
2183  if (item.action->action == action)
2184  return true;
2185  }
2186  }
2187  }
2188 #endif
2189  return false;
2190 }
QMacMenuAction * action
Definition: qmenu_p.h:121
static QHash< OSMenuRef, OSMenuRef > mergeMenuHash
Definition: qmenu_p.h:334
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
MenuRef OSMenuRef
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
struct OpaqueMenuRef * MenuRef
static QHash< OSMenuRef, QMenuMergeList * > mergeMenuItemsHash
Definition: qmenu_p.h:335
QPointer< QAction > action
Definition: qmenu_p.h:108
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ removeAction() [1/2]

void QMenuPrivate::QMacMenuPrivate::removeAction ( QMacMenuAction action)

Definition at line 1491 of file qmenu_mac.mm.

1492 {
1493  if (!action)
1494  return;
1495 #ifndef QT_MAC_USE_COCOA
1496  if (action->command == kHICommandQuit || action->command == kHICommandPreferences)
1497  qt_mac_command_set_enabled(action->menu, action->command, false);
1498  else
1499  DeleteMenuItem(action->menu, qt_mac_menu_find_action(action->menu, action));
1500 #else
1502  if (action->merged) {
1503  if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->action) {
1504  QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
1505  [action->menuItem setEnabled:false];
1506  if (action->menuItem != [loader quitMenuItem]
1507  && action->menuItem != [loader preferencesMenuItem]) {
1508  [[action->menuItem menu] removeItem:action->menuItem];
1509  }
1510  if (QMenuMergeList *list = mergeMenuItemsHash.value(action->menu)) {
1511  int i = 0;
1512  while (i < list->size()) {
1513  const QMenuMergeItem &item = list->at(i);
1514  if (item.action == action)
1515  list->removeAt(i);
1516  else
1517  ++i;
1518  }
1519  }
1520  }
1521  } else {
1522  [[action->menuItem menu] removeItem:action->menuItem];
1523  }
1524 #endif
1525  actionItems.removeAll(action);
1526 }
uint command
Definition: qmenu_p.h:102
QMacMenuAction * action
Definition: qmenu_p.h:121
QList< QMacMenuAction * > actionItems
Definition: qmenu_p.h:308
static void qt_mac_command_set_enabled(MenuRef menu, UInt32 cmd, bool b)
Definition: qmenu_mac.mm:547
OSMenuRef menu
Definition: qmenu_p.h:109
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
static QHash< OSMenuRef, QMenuMergeList * > mergeMenuItemsHash
Definition: qmenu_p.h:335
QPointer< QAction > action
Definition: qmenu_p.h:108
uchar merged
Definition: qmenu_p.h:107
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ removeAction() [2/2]

void QMenuPrivate::QMacMenuPrivate::removeAction ( QAction a)
inline

Definition at line 319 of file qmenu_p.h.

Referenced by removeAction().

319 { removeAction(findAction(a)); }
QMacMenuAction * findAction(QAction *a)
Definition: qmenu_p.h:320
void removeAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1491

◆ syncAction() [1/2]

void QMenuPrivate::QMacMenuPrivate::syncAction ( QMacMenuAction action)

Definition at line 1271 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::QMacMenuBarPrivate::addAction(), and addAction().

1272 {
1273  if (!action)
1274  return;
1275 
1276 #ifndef QT_MAC_USE_COCOA
1277  const int index = qt_mac_menu_find_action(action->menu, action);
1278  if (index == -1)
1279  return;
1280 #else
1281  NSMenuItem *item = action->menuItem;
1282  if (!item)
1283  return;
1284 #endif
1285 
1286 #ifndef QT_MAC_USE_COCOA
1287  if (!action->action->isVisible()) {
1288  ChangeMenuItemAttributes(action->menu, index, kMenuItemAttrHidden, 0);
1289  return;
1290  }
1291  ChangeMenuItemAttributes(action->menu, index, 0, kMenuItemAttrHidden);
1292 #else
1294  NSMenu *menu = [item menu];
1295  bool actionVisible = action->action->isVisible();
1296  [item setHidden:!actionVisible];
1297  if (!actionVisible)
1298  return;
1299 #endif
1300 
1301 #ifndef QT_MAC_USE_COCOA
1302  if (action->action->isSeparator()) {
1303  ChangeMenuItemAttributes(action->menu, index, kMenuItemAttrSeparator, 0);
1304  return;
1305  }
1306  ChangeMenuItemAttributes(action->menu, index, 0, kMenuItemAttrSeparator);
1307 #else
1308  int itemIndex = [menu indexOfItem:item];
1309  Q_ASSERT(itemIndex != -1);
1310  if (action->action->isSeparator()) {
1311  action->menuItem = [NSMenuItem separatorItem];
1312  [action->menuItem retain];
1313  [menu insertItem: action->menuItem atIndex:itemIndex];
1314  [menu removeItem:item];
1315  [item release];
1316  item = action->menuItem;
1317  return;
1318  } else if ([item isSeparatorItem]) {
1319  // I'm no longer a separator...
1320  action->menuItem = createNSMenuItem(action->action->text());
1321  [menu insertItem:action->menuItem atIndex:itemIndex];
1322  [menu removeItem:item];
1323  [item release];
1324  item = action->menuItem;
1325  }
1326 #endif
1327 
1328  //find text (and accel)
1329  action->ignore_accel = 0;
1330  QString text = action->action->text();
1331  QKeySequence accel = action->action->shortcut();
1332  {
1333  int st = text.lastIndexOf(QLatin1Char('\t'));
1334  if (st != -1) {
1335  action->ignore_accel = 1;
1336  accel = QKeySequence(text.right(text.length()-(st+1)));
1337  text.remove(st, text.length()-st);
1338  }
1339  }
1340  {
1341  QString cmd_text = qt_mac_menu_merge_text(action);
1342  if (!cmd_text.isEmpty()) {
1343  text = cmd_text;
1344  accel = qt_mac_menu_merge_accel(action);
1345  }
1346  }
1347  // Show multiple key sequences as part of the menu text.
1348  if (accel.count() > 1)
1349  text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")");
1350 
1351  QString finalString = qt_mac_removeMnemonics(text);
1352 
1353 #ifndef QT_MAC_USE_COCOA
1354  MenuItemDataRec data;
1355  memset(&data, '\0', sizeof(data));
1356 
1357  //Carbon text
1358  data.whichData |= kMenuItemDataCFString;
1359  QCFString cfstring(finalString); // Hold the reference to the end of the function.
1360  data.cfText = cfstring;
1361 
1362  // Carbon enabled
1363  data.whichData |= kMenuItemDataEnabled;
1364  data.enabled = action->action->isEnabled();
1365  // Carbon icon
1366  data.whichData |= kMenuItemDataIconHandle;
1367  if (!action->action->icon().isNull()
1368  && action->action->isIconVisibleInMenu()) {
1369  data.iconType = kMenuIconRefType;
1370  data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(16, QIcon::Normal));
1371  } else {
1372  data.iconType = kMenuNoIcon;
1373  }
1374  if (action->action->font().resolve()) { // Carbon font
1375  if (action->action->font().bold())
1376  data.style |= bold;
1377  if (action->action->font().underline())
1378  data.style |= underline;
1379  if (action->action->font().italic())
1380  data.style |= italic;
1381  if (data.style)
1382  data.whichData |= kMenuItemDataStyle;
1383  data.whichData |= kMenuItemDataFontID;
1384  data.fontID = action->action->font().macFontID();
1385  }
1386 #else
1387  // Cocoa Font and title
1388  if (action->action->font().resolve()) {
1389  const QFont &actionFont = action->action->font();
1390  NSFont *customMenuFont = [NSFont fontWithName:qt_mac_QStringToNSString(actionFont.family())
1391  size:actionFont.pointSize()];
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];
1398  } else {
1399  [item setTitle: qt_mac_QStringToNSString(finalString)];
1400  }
1401 
1402  if (action->action->menuRole() == QAction::AboutRole || action->action->menuRole() == QAction::QuitRole)
1403  [item setTitle:qt_mac_QStringToNSString(text)];
1404  else
1405  [item setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(text))];
1406 
1407  // Cocoa Enabled
1408  [item setEnabled: action->action->isEnabled()];
1409 
1410  // Cocoa icon
1411  NSImage *nsimage = 0;
1412  if (!action->action->icon().isNull() && action->action->isIconVisibleInMenu()) {
1413  nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap(16, QIcon::Normal)));
1414  }
1415  [item setImage:nsimage];
1416  [nsimage release];
1417 #endif
1418 
1419  if (action->action->menu()) { //submenu
1420 #ifndef QT_MAC_USE_COCOA
1421  data.whichData |= kMenuItemDataSubmenuHandle;
1422  data.submenuHandle = action->action->menu()->macMenu();
1423  QWidget *caused = 0;
1424  GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused);
1425  SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
1426 #else
1427  NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu());
1428  if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) {
1429  // The menu is already a sub-menu of another one. Cocoa will throw an exception,
1430  // in such cases. For the time being, a new QMenu with same set of actions is the
1431  // only workaround.
1432  action->action->setEnabled(false);
1433  } else {
1434  [item setSubmenu:subMenu];
1435  }
1436  [item setAction:nil];
1437 #endif
1438  } else { //respect some other items
1439 #ifndef QT_MAC_USE_COCOA
1440  //shortcuts (say we are setting them all so that we can also clear them).
1441  data.whichData |= kMenuItemDataCmdKey;
1442  data.whichData |= kMenuItemDataCmdKeyModifiers;
1443  data.whichData |= kMenuItemDataCmdKeyGlyph;
1444  if (accel.count() == 1) {
1445  qt_mac_get_accel(accel[0], (quint32*)&data.cmdKeyModifiers, (quint32*)&data.cmdKeyGlyph);
1446  if (data.cmdKeyGlyph == 0)
1447  data.cmdKey = (UniChar)accel[0];
1448  }
1449 #else
1450  [item setSubmenu:0];
1451  if ([item action] == nil)
1452  [item setAction:@selector(qtDispatcherToQAction:)];
1453  // No key equivalent set for multiple key QKeySequence.
1454  if (accel.count() == 1) {
1455  [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)];
1456  [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)];
1457  } else {
1458  [item setKeyEquivalent:@""];
1459  [item setKeyEquivalentModifierMask:NSCommandKeyMask];
1460  }
1461 #endif
1462  }
1463 #ifndef QT_MAC_USE_COCOA
1464  //mark glyph
1465  data.whichData |= kMenuItemDataMark;
1466  if (action->action->isChecked()) {
1467 #if 0
1468  if (action->action->actionGroup() &&
1469  action->action->actionGroup()->isExclusive())
1470  data.mark = diamondMark;
1471  else
1472 #endif
1473  data.mark = checkMark;
1474  } else {
1475  data.mark = noMark;
1476  }
1477 
1478  //actually set it
1479  SetMenuItemData(action->menu, action->command, true, &data);
1480 
1481  // Free up memory
1482  if (data.iconHandle)
1483  ReleaseIconRef(IconRef(data.iconHandle));
1484 #else
1485  //mark glyph
1486  [item setState:action->action->isChecked() ? NSOnState : NSOffState];
1487 #endif
1488 }
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
Definition: qaction.cpp:839
uchar ignore_accel
Definition: qmenu_p.h:106
uint command
Definition: qmenu_p.h:102
static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action)
Definition: qmenu_mac.mm:955
bool isEnabled() const
Definition: qaction.cpp:1208
static QString qt_mac_menu_merge_text(QMacMenuAction *action)
Definition: qmenu_mac.mm:920
QKeySequence shortcut
the action&#39;s primary shortcut key
Definition: qaction.h:83
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
OSMenuRef macMenu(OSMenuRef merge=0)
Definition: qmenu_mac.mm:1610
NSUInteger keySequenceModifierMask(const QKeySequence &accel)
Definition: qmenu_mac.mm:1265
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void * qt_mac_create_nsimage(const QPixmap &pm)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
NSString * keySequenceToKeyEqivalent(const QKeySequence &accel)
Definition: qmenu_mac.mm:1254
IconRef qt_mac_create_iconref(const QPixmap &px)
QStringList keys
void setEnabled(bool)
Definition: qaction.cpp:1192
QString qt_mac_removeMnemonics(const QString &original)
MenuRole menuRole
the action&#39;s menu role
Definition: qaction.h:88
void NSMenuItem
Definition: qmenu_p.h:80
bool isVisible() const
Definition: qaction.cpp:1246
QWidgetData data
Definition: qwidget_p.h:755
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
bool isIconVisibleInMenu() const
Definition: qaction.cpp:1651
static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key)
Definition: qmenu_mac.mm:568
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
OSMenuRef menu
Definition: qmenu_p.h:109
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
QFont font
the action&#39;s font
Definition: qaction.h:81
QIcon icon
the action&#39;s icon
Definition: qaction.h:75
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.
Definition: qstring.cpp:3682
bool bold() const
Returns true if weight() is a value greater than QFont::Normal ; otherwise returns false...
Definition: qfont.h:348
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
#define st(var, type, card)
unsigned int quint32
Definition: qglobal.h:938
if(void) toggleToolbarShown
uint count() const
Returns the number of keys in the key sequence.
bool isChecked() const
Definition: qaction.cpp:1151
quint16 index
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.
Definition: qicon.cpp:693
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition: qfont.h:355
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981
QPointer< QAction > action
Definition: qmenu_p.h:108
QActionGroup * actionGroup() const
Returns the action group for this action.
Definition: qaction.cpp:747
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
quint32 macFontID() const
Returns an ATSUFontID.
Definition: qfont_mac.cpp:101
bool isExclusive() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define text
Definition: qobjectdefs.h:80
struct OpaqueIconRef * IconRef

◆ syncAction() [2/2]

void QMenuPrivate::QMacMenuPrivate::syncAction ( QAction a)
inline

Definition at line 317 of file qmenu_p.h.

Referenced by syncAction().

317 { syncAction(findAction(a)); }
void syncAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1271
QMacMenuAction * findAction(QAction *a)
Definition: qmenu_p.h:320

Properties

◆ actionItems

QList<QMacMenuAction*> QMenuPrivate::QMacMenuPrivate::actionItems

◆ menu

OSMenuRef QMenuPrivate::QMacMenuPrivate::menu

The documentation for this struct was generated from the following files: