Qt 4.8
Public Functions | Public Variables | List of all members
QMenuBarPrivate::QMacMenuBarPrivate Struct Reference

#include <qmenubar_p.h>

Public Functions

void addAction (QAction *, QAction *=0)
 
void addAction (QMacMenuAction *, QMacMenuAction *=0)
 
QMacMenuActionfindAction (QAction *a)
 
 QMacMenuBarPrivate ()
 
void removeAction (QMacMenuAction *)
 
void removeAction (QAction *a)
 
void syncAction (QMacMenuAction *)
 
void syncAction (QAction *a)
 
 ~QMacMenuBarPrivate ()
 

Public Variables

QList< QMacMenuAction * > actionItems
 
OSMenuRef apple_menu
 
OSMenuRef menu
 

Detailed Description

Definition at line 195 of file qmenubar_p.h.

Constructors and Destructors

◆ QMacMenuBarPrivate()

QMenuBarPrivate::QMacMenuBarPrivate::QMacMenuBarPrivate ( )

Definition at line 1618 of file qmenu_mac.mm.

1618  : menu(0), apple_menu(0)
1619 {
1620 }

◆ ~QMacMenuBarPrivate()

QMenuBarPrivate::QMacMenuBarPrivate::~QMacMenuBarPrivate ( )

Definition at line 1622 of file qmenu_mac.mm.

1623 {
1625  delete (*it);
1626 #ifndef QT_MAC_USE_COCOA
1627  if (apple_menu) {
1628  QMenuMergeList *list = 0;
1629  GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
1630  sizeof(list), 0, &list);
1631  if (list) {
1632  RemoveMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList);
1633  delete list;
1634  }
1635  ReleaseMenu(apple_menu);
1636  }
1637  if (menu)
1638  ReleaseMenu(menu);
1639 #else
1640  [apple_menu release];
1641  [menu release];
1642 #endif
1643 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QList< QMacMenuAction * > actionItems
Definition: qmenubar_p.h:196
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
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

Functions

◆ addAction() [1/2]

void QMenuBarPrivate::QMacMenuBarPrivate::addAction ( QAction a,
QAction before = 0 
)

Definition at line 1646 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macMenu().

1647 {
1648  if (a->isSeparator() || !menu)
1649  return;
1650  QMacMenuAction *action = new QMacMenuAction;
1651  action->action = a;
1652  action->ignore_accel = 1;
1653 #ifndef QT_MAC_USE_COCOA
1654  action->command = qt_mac_menu_static_cmd_id++;
1655 #endif
1656  addAction(action, findAction(before));
1657 }
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
long ASN1_INTEGER_get ASN1_INTEGER * a
void addAction(QAction *, QAction *=0)
Definition: qmenu_mac.mm:1646
QPointer< QAction > action
Definition: qmenu_p.h:108
QMacMenuAction * findAction(QAction *a)
Definition: qmenubar_p.h:207
static uint qt_mac_menu_static_cmd_id
Definition: qmenu_mac.mm:81

◆ addAction() [2/2]

void QMenuBarPrivate::QMacMenuBarPrivate::addAction ( QMacMenuAction action,
QMacMenuAction before = 0 
)

Definition at line 1660 of file qmenu_mac.mm.

1661 {
1662  if (!action || !menu)
1663  return;
1664 
1665  int before_index = actionItems.indexOf(before);
1666  if (before_index < 0) {
1667  before = 0;
1668  before_index = actionItems.size();
1669  }
1670  actionItems.insert(before_index, action);
1671 
1672  MenuItemIndex index = actionItems.size()-1;
1673 
1674  action->menu = menu;
1675 #ifdef QT_MAC_USE_COCOA
1677  [action->menu retain];
1678  NSMenuItem *newItem = createNSMenuItem(action->action->text());
1679  action->menuItem = newItem;
1680 #endif
1681  if (before) {
1682 #ifndef QT_MAC_USE_COCOA
1683  InsertMenuItemTextWithCFString(action->menu, 0, qMax(1, before_index+1), 0, action->command);
1684 #else
1685  [menu insertItem:newItem atIndex:qMax(1, before_index + 1)];
1686 #endif
1687  index = before_index;
1688  } else {
1689 #ifndef QT_MAC_USE_COCOA
1690  AppendMenuItemTextWithCFString(action->menu, 0, 0, action->command, &index);
1691 #else
1692  [menu addItem:newItem];
1693 #endif
1694  }
1695 #ifndef QT_MAC_USE_COCOA
1696  SetMenuItemProperty(action->menu, index, kMenuCreatorQt, kMenuPropertyQAction, sizeof(action),
1697  &action);
1698 #else
1699  [newItem setTag:long(static_cast<QAction *>(action->action))];
1700 #endif
1701  syncAction(action);
1702 }
uint command
Definition: qmenu_p.h:102
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void NSMenuItem
Definition: qmenu_p.h:80
QList< QMacMenuAction * > actionItems
Definition: qmenubar_p.h:196
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
OSMenuRef menu
Definition: qmenu_p.h:109
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
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
void syncAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1705
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ findAction()

QMacMenuAction* QMenuBarPrivate::QMacMenuBarPrivate::findAction ( QAction a)
inline

Definition at line 207 of file qmenubar_p.h.

Referenced by removeAction(), QMenuBarPrivate::QWceMenuBarPrivate::removeAction(), syncAction(), and QMenuBarPrivate::QWceMenuBarPrivate::syncAction().

207  {
208  for(int i = 0; i < actionItems.size(); i++) {
209  QMacMenuAction *act = actionItems[i];
210  if(a == act->action)
211  return act;
212  }
213  return 0;
214  }
QList< QMacMenuAction * > actionItems
Definition: qmenubar_p.h:196
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ removeAction() [1/2]

void QMenuBarPrivate::QMacMenuBarPrivate::removeAction ( QMacMenuAction action)

Definition at line 1766 of file qmenu_mac.mm.

Referenced by syncAction(), and QMenuBarPrivate::QWceMenuBarPrivate::syncAction().

1767 {
1768  if (!action || !menu)
1769  return;
1770 #ifndef QT_MAC_USE_COCOA
1771  DeleteMenuItem(action->menu, qt_mac_menu_find_action(action->menu, action));
1772 #else
1774  [action->menu removeItem:action->menuItem];
1775 #endif
1776  actionItems.removeAll(action);
1777 }
QList< QMacMenuAction * > actionItems
Definition: qmenubar_p.h:196
OSMenuRef menu
Definition: qmenu_p.h:109
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287
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 QMenuBarPrivate::QMacMenuBarPrivate::removeAction ( QAction a)
inline

Definition at line 206 of file qmenubar_p.h.

Referenced by removeAction().

206 { removeAction(findAction(a)); }
void removeAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1766
QMacMenuAction * findAction(QAction *a)
Definition: qmenubar_p.h:207

◆ syncAction() [1/2]

void QMenuBarPrivate::QMacMenuBarPrivate::syncAction ( QMacMenuAction action)

Definition at line 1705 of file qmenu_mac.mm.

1706 {
1707  if (!action || !menu)
1708  return;
1709 #ifndef QT_MAC_USE_COCOA
1710  const int index = qt_mac_menu_find_action(action->menu, action);
1711 #else
1713  NSMenuItem *item = action->menuItem;
1714 #endif
1715 
1716  OSMenuRef submenu = 0;
1717  bool release_submenu = false;
1718  if (action->action->menu()) {
1719  if ((submenu = action->action->menu()->macMenu(apple_menu))) {
1720 #ifndef QT_MAC_USE_COCOA
1721  QWidget *caused = 0;
1722  GetMenuItemProperty(action->menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(caused), 0, &caused);
1723  SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused);
1724 #else
1725  if ([submenu supermenu] && [submenu supermenu] != [item menu])
1726  return;
1727  else
1728  [item setSubmenu:submenu];
1729 #endif
1730  }
1731 #ifndef QT_MAC_USE_COCOA
1732  } else { // create a submenu to act as menu
1733  release_submenu = true;
1734  CreateNewMenu(0, 0, &submenu);
1735 #endif
1736  }
1737 
1738  if (submenu) {
1739  bool visible = actualMenuItemVisibility(this, action);
1740 #ifndef QT_MAC_USE_COCOA
1741  SetMenuItemHierarchicalMenu(action->menu, index, submenu);
1742  SetMenuTitleWithCFString(submenu, QCFString(qt_mac_removeMnemonics(action->action->text())));
1743  if (visible)
1744  ChangeMenuAttributes(submenu, 0, kMenuAttrHidden);
1745  else
1746  ChangeMenuAttributes(submenu, kMenuAttrHidden, 0);
1747 #else
1748  [item setSubmenu: submenu];
1749  [submenu setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(action->action->text()))];
1750  syncNSMenuItemVisiblity(item, visible);
1751  syncNSMenuItemEnabled(item, action->action->isEnabled());
1752 #endif
1753  if (release_submenu) { //no pointers to it
1754 #ifndef QT_MAC_USE_COCOA
1755  ReleaseMenu(submenu);
1756 #else
1757  [submenu release];
1758 #endif
1759  }
1760  } else {
1761  qWarning("QMenu: No OSMenuRef created for popup menu");
1762  }
1763 }
static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp, const QMacMenuAction *action)
Definition: qmenu_mac.mm:194
bool isEnabled() const
Definition: qaction.cpp:1208
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
QString qt_mac_removeMnemonics(const QString &original)
void NSMenuItem
Definition: qmenu_p.h:80
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
OSMenuRef menu
Definition: qmenu_p.h:109
Q_CORE_EXPORT void qWarning(const char *,...)
MenuRef OSMenuRef
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
quint16 index
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ syncAction() [2/2]

void QMenuBarPrivate::QMacMenuBarPrivate::syncAction ( QAction a)
inline

Definition at line 204 of file qmenubar_p.h.

Referenced by syncAction().

204 { syncAction(findAction(a)); }
void syncAction(QMacMenuAction *)
Definition: qmenu_mac.mm:1705
QMacMenuAction * findAction(QAction *a)
Definition: qmenubar_p.h:207

Properties

◆ actionItems

QList<QMacMenuAction*> QMenuBarPrivate::QMacMenuBarPrivate::actionItems

Definition at line 196 of file qmenubar_p.h.

Referenced by qt_mac_get_accel().

◆ apple_menu

OSMenuRef QMenuBarPrivate::QMacMenuBarPrivate::apple_menu

Definition at line 197 of file qmenubar_p.h.

Referenced by actualMenuItemVisibility(), and QMenuBarPrivate::macMenu().

◆ menu

OSMenuRef QMenuBarPrivate::QMacMenuBarPrivate::menu

Definition at line 197 of file qmenubar_p.h.

Referenced by QMenuBarPrivate::macMenu().


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