Qt 4.8
Typedefs | Enumerations | Functions | Variables
qmenu_mac.mm File Reference
#include "qmenu.h"
#include "qhash.h"
#include <qdebug.h>
#include "qapplication.h"
#include <private/qt_mac_p.h>
#include "qregexp.h"
#include "qmainwindow.h"
#include "qdockwidget.h"
#include "qtoolbar.h"
#include "qevent.h"
#include "qstyle.h"
#include "qwidgetaction.h"
#include "qmacnativewidget_mac.h"
#include <private/qapplication_p.h>
#include <private/qcocoaapplication_mac_p.h>
#include <private/qmenu_p.h>
#include <private/qmenubar_p.h>
#include <private/qcocoamenuloader_mac_p.h>
#include <private/qcocoamenu_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <Cocoa/Cocoa.h>

Go to the source code of this file.

Typedefs

typedef QMultiHash< OSMenuRef, EventHandlerRef > EventHandlerHash
 
typedef QHash< QWidget *, QMenuBar * > MenuBarHash
 

Enumerations

enum  {
  kMenuPropertyQAction = 'QAcT', kMenuPropertyQWidget = 'QWId', kMenuPropertyCausedQWidget = 'QCAU', kMenuPropertyMergeMenu = 'QApP',
  kMenuPropertyMergeList = 'QAmL', kMenuPropertyWidgetActionWidget = 'QWid', kMenuPropertyWidgetMenu = 'QWMe', kHICommandAboutQt = 'AOQT',
  kHICommandCustomMerge = 'AQt0'
}
 

Functions

static bool actualMenuItemVisibility (const QMenuBarPrivate::QMacMenuBarPrivate *mbp, const QMacMenuAction *action)
 
static void cancelAllMenuTracking ()
 
static quint32 constructModifierMask (quint32 accel_key)
 
static QMenuBarfindMenubarForWindow (QWidget *w)
 
static QWidgetfindWindowThatShouldDisplayMenubar ()
 
NSUInteger keySequenceModifierMask (const QKeySequence &accel)
 
NSString * keySequenceToKeyEqivalent (const QKeySequence &accel)
 
bool qt_mac_activate_action (MenuRef menu, uint command, QAction::ActionEvent action_e, bool by_accel)
 
static bool qt_mac_auto_apple_menu (MenuCommand cmd)
 
static void qt_mac_cleanup_menu_event ()
 
void qt_mac_clear_menubar ()
 
static void qt_mac_command_set_enabled (MenuRef menu, UInt32 cmd, bool b)
 
static int qt_mac_CountMenuItems (OSMenuRef menu)
 
IconRef qt_mac_create_iconref (const QPixmap &px)
 
static OSMenuRef qt_mac_create_menu (QWidget *w)
 
static void qt_mac_create_menu_event_handler ()
 
void qt_mac_dispose_rgn (RgnHandle r)
 
static void qt_mac_get_accel (quint32 accel_key, quint32 *modif, quint32 *key)
 
RgnHandle qt_mac_get_rgn ()
 
OSViewRef qt_mac_hiview_for (const QWidget *w)
 
HIViewRef qt_mac_hiview_for (OSWindowRef w)
 
static bool qt_mac_is_ancestor (QWidget *possibleAncestor, QWidget *child)
 
OSStatus qt_mac_menu_event (EventHandlerCallRef er, EventRef event, void *)
 
static int qt_mac_menu_find_action (MenuRef menu, MenuCommand cmd)
 
static int qt_mac_menu_find_action (MenuRef menu, QMacMenuAction *action)
 
static QKeySequence qt_mac_menu_merge_accel (QMacMenuAction *action)
 
static MenuCommand qt_mac_menu_merge_action (MenuRef merge, QMacMenuAction *action)
 
static QString qt_mac_menu_merge_text (QMacMenuAction *action)
 
bool qt_mac_menubar_is_open ()
 
void Q_GUI_EXPORT qt_mac_set_menubar_icons (bool b)
 
void Q_GUI_EXPORT qt_mac_set_menubar_merge (bool b)
 
static void qt_mac_set_modal_state (OSMenuRef menu, bool on)
 
void qt_mac_set_modal_state_helper_recursive (OSMenuRef menu, OSMenuRef merge, bool on)
 
void Q_GUI_EXPORT qt_mac_set_native_menubar (bool b)
 
static bool qt_mac_should_disable_menu (QMenuBar *menuBar)
 
bool qt_mac_watchingAboutToShow (QMenu *menu)
 
static OSStatus qt_mac_widget_in_menu_eventHandler (EventHandlerCallRef er, EventRef event, void *)
 
bool qt_sendSpontaneousEvent (QObject *, QEvent *)
 

Variables

static QMenuBarfallback = 0
 
const UInt32 kMenuCreatorQt = 'cute'
 
QWidgetmac_keyboard_grabber
 
static EventHandlerRef mac_menu_event_handler = 0
 
static EventHandlerUPP mac_menu_eventUPP = 0
 
static EventTypeSpec menu_events []
 
static EventTypeSpec menu_menu_events []
 
struct {
   bool   modal
 
   QPointer< QMenuBar >   qmenubar
 
qt_mac_current_menubar = { 0, false }
 
static uint qt_mac_menu_static_cmd_id = 'QT00'
 
int qt_mac_menus_open_count = 0
 
bool qt_mac_no_menubar_merge = false
 
bool qt_mac_quit_menu_item_enabled = true
 
static EventTypeSpec widget_in_menu_events []
 

Typedef Documentation

◆ EventHandlerHash

typedef QMultiHash<OSMenuRef, EventHandlerRef> EventHandlerHash

Definition at line 302 of file qmenu_mac.mm.

◆ MenuBarHash

Definition at line 1615 of file qmenu_mac.mm.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kMenuPropertyQAction 
kMenuPropertyQWidget 
kMenuPropertyCausedQWidget 
kMenuPropertyMergeMenu 
kMenuPropertyMergeList 
kMenuPropertyWidgetActionWidget 
kMenuPropertyWidgetMenu 
kHICommandAboutQt 
kHICommandCustomMerge 

Definition at line 83 of file qmenu_mac.mm.

Function Documentation

◆ actualMenuItemVisibility()

static bool actualMenuItemVisibility ( const QMenuBarPrivate::QMacMenuBarPrivate mbp,
const QMacMenuAction action 
)
static

Definition at line 194 of file qmenu_mac.mm.

Referenced by qt_mac_get_accel(), and QMenuBarPrivate::QMacMenuBarPrivate::syncAction().

196 {
197  bool visible = action->action->isVisible();
198  if (visible && action->action->text() == QString(QChar(0x14)))
199  return false;
200  if (visible && action->action->menu() && !action->action->menu()->actions().isEmpty() &&
201  !qt_mac_CountMenuItems(action->action->menu()->macMenu(mbp->apple_menu)) &&
202  !qt_mac_watchingAboutToShow(action->action->menu())) {
203  return false;
204  }
205  return visible;
206 }
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
OSMenuRef macMenu(OSMenuRef merge=0)
Definition: qmenu_mac.mm:1610
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool isVisible() const
Definition: qaction.cpp:1246
bool qt_mac_watchingAboutToShow(QMenu *menu)
Definition: qmenu_mac.mm:119
static int qt_mac_CountMenuItems(OSMenuRef menu)
Definition: qmenu_mac.mm:124
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ cancelAllMenuTracking()

static void cancelAllMenuTracking ( )
static

Definition at line 178 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macDestroyMenuBar(), and QMenuBarPrivate::macUpdateMenuBarImmediatly().

179 {
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];
187  }
188  }
189 #else
190  CancelMenuTracking(AcquireRootMenu(), true, 0);
191 #endif
192 }
void NSMenuItem
Definition: qmenu_p.h:80

◆ constructModifierMask()

static quint32 constructModifierMask ( quint32  accel_key)
static

Definition at line 145 of file qmenu_mac.mm.

Referenced by keySequenceModifierMask(), and qt_mac_get_accel().

146 {
147  quint32 ret = 0;
148  const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
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;
154  if (dontSwap) {
155  if ((accel_key & Qt::META) != Qt::META)
156  ret |= kMenuNoCommandModifier;
157  if ((accel_key & Qt::CTRL) == Qt::CTRL)
158  ret |= kMenuControlModifier;
159  } else {
160  if ((accel_key & Qt::CTRL) != Qt::CTRL)
161  ret |= kMenuNoCommandModifier;
162  if ((accel_key & Qt::META) == Qt::META)
163  ret |= kMenuControlModifier;
164  }
165 #else
166  if ((accel_key & Qt::CTRL) == Qt::CTRL)
167  ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask);
168  if ((accel_key & Qt::META) == Qt::META)
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;
174 #endif
175  return ret;
176 }
#define qApp
unsigned int quint32
Definition: qglobal.h:938

◆ findMenubarForWindow()

static QMenuBar* findMenubarForWindow ( QWidget w)
static

Definition at line 1989 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly().

1990 {
1991  QMenuBar *mb = 0;
1992  if (w) {
1993  mb = menubars()->value(w);
1994 #ifndef QT_NO_MAINWINDOW
1995  QDockWidget *dw = qobject_cast<QDockWidget *>(w);
1996  if (!mb && dw) {
1998  if (mw && (mb = menubars()->value(mw)))
1999  w = mw;
2000  }
2001 #endif
2002  while(w && !mb)
2003  mb = menubars()->value((w = w->parentWidget()));
2004  }
2005 
2006  if (!mb) {
2007  // We could not find a menu bar for the window. Lets
2008  // check if we have a global (parentless) menu bar instead:
2009  mb = fallback;
2010  }
2011 
2012  return mb;
2013 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
static QMenuBar * fallback
Definition: qmenu_mac.mm:1617

◆ findWindowThatShouldDisplayMenubar()

static QWidget* findWindowThatShouldDisplayMenubar ( )
static

Definition at line 1970 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly().

1971 {
1972  QWidget *w = qApp->activeWindow();
1973  if (!w) {
1974  // We have no active window on screen. Try to
1975  // find a window from the list of top levels:
1977  for(int i = 0; i < tlws.size(); ++i) {
1978  QWidget *tlw = tlws.at(i);
1979  if ((tlw->isVisible() && tlw->windowType() != Qt::Tool &&
1980  tlw->windowType() != Qt::Popup)) {
1981  w = tlw;
1982  break;
1983  }
1984  }
1985  }
1986  return w;
1987 }
bool isVisible() const
Definition: qwidget.h:1005
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ keySequenceModifierMask()

NSUInteger keySequenceModifierMask ( const QKeySequence accel)

Definition at line 1265 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

1266 {
1267  return constructModifierMask(accel[0]);
1268 }
static quint32 constructModifierMask(quint32 accel_key)
Definition: qmenu_mac.mm:145

◆ keySequenceToKeyEqivalent()

NSString* keySequenceToKeyEqivalent ( const QKeySequence accel)

Definition at line 1254 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

1255 {
1256  quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL));
1257  extern QChar qtKey2CocoaKey(Qt::Key key);
1258  QChar cocoa_key = qtKey2CocoaKey(Qt::Key(accel_key));
1259  if (cocoa_key.isNull())
1260  cocoa_key = QChar(accel_key).toLower().unicode();
1261  return [NSString stringWithCharacters:&cocoa_key.unicode() length:1];
1262 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int key
unsigned int quint32
Definition: qglobal.h:938
QChar qtKey2CocoaKey(Qt::Key key)
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239

◆ qt_mac_activate_action()

bool qt_mac_activate_action ( MenuRef  menu,
uint  command,
QAction::ActionEvent  action_e,
bool  by_accel 
)

Definition at line 209 of file qmenu_mac.mm.

Referenced by qt_mac_menu_event().

210 {
211  //fire event
212  QMacMenuAction *action = 0;
213  if (GetMenuCommandProperty(menu, command, kMenuCreatorQt, kMenuPropertyQAction, sizeof(action), 0, &action) != noErr) {
214  QMenuMergeList *list = 0;
215  GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
216  sizeof(list), 0, &list);
217  if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) {
218  MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu;
219  GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list);
220  if (list)
221  menu = apple_menu;
222  }
223  if (list) {
224  for(int i = 0; i < list->size(); ++i) {
225  QMenuMergeItem item = list->at(i);
226  if (item.command == command && item.action) {
227  action = item.action;
228  break;
229  }
230  }
231  }
232  if (!action)
233  return false;
234  }
235 
236  if (action_e == QAction::Trigger && by_accel && action->ignore_accel) //no, not a real accel (ie tab)
237  return false;
238 
239  // Unhighlight the highlighted menu item before triggering the action to
240  // prevent items from staying highlighted while a modal dialog is shown.
241  // This also fixed the problem that parentless modal dialogs leave
242  // the menu item highlighted (since the menu bar is cleared for these types of dialogs).
243  if (action_e == QAction::Trigger)
244  HiliteMenu(0);
245 
246  action->action->activate(action_e);
247 
248  //now walk up firing for each "caused" widget (like in the platform independent menu)
249  QWidget *caused = 0;
250  if (action_e == QAction::Hover && GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) {
251  MenuRef caused_menu = 0;
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();
256  else
257  caused_menu = 0;
258  while(caused_menu) {
259  //fire
260  QWidget *widget = 0;
261  GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget);
262  if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) {
263  action->action->showStatusText(widget);
264  emit qmenu->hovered(action->action);
265  } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) {
266  action->action->showStatusText(widget);
267  emit qmenubar->hovered(action->action);
268  break; //nothing more..
269  }
270 
271  //walk up
272  if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget,
273  sizeof(caused), 0, &caused) != noErr)
274  break;
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();
279  else
280  caused_menu = 0;
281  }
282  }
283  return true;
284 }
uchar ignore_accel
Definition: qmenu_p.h:106
QPointer< QWidget > widget
bool showStatusText(QWidget *widget=0)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent w...
Definition: qaction.cpp:1315
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Definition: qaction.cpp:1326
QMacMenuAction * action
Definition: qmenu_p.h:121
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
MenuCommand command
Definition: qmenu_p.h:116
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
static struct @304 qt_mac_current_menubar
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QPointer< QMenuBar > qmenubar
Definition: qmenu_mac.mm:98
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
struct OpaqueMenuRef * MenuRef
QPointer< QAction > action
Definition: qmenu_p.h:108
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void hovered(QAction *action)
This signal is emitted when a menu action is highlighted; action is the action that caused the event ...

◆ qt_mac_auto_apple_menu()

static bool qt_mac_auto_apple_menu ( MenuCommand  cmd)
static

Definition at line 563 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction().

564 {
565  return (cmd == kHICommandPreferences || cmd == kHICommandQuit);
566 }

◆ qt_mac_cleanup_menu_event()

static void qt_mac_cleanup_menu_event ( )
static

Definition at line 523 of file qmenu_mac.mm.

Referenced by qt_mac_create_menu_event_handler().

524 {
526  RemoveEventHandler(mac_menu_event_handler);
528  }
529  if (mac_menu_eventUPP) {
530  DisposeEventHandlerUPP(mac_menu_eventUPP);
531  mac_menu_eventUPP = 0;
532  }
533 }
static EventHandlerUPP mac_menu_eventUPP
Definition: qmenu_mac.mm:522
static EventHandlerRef mac_menu_event_handler
Definition: qmenu_mac.mm:521

◆ qt_mac_clear_menubar()

void qt_mac_clear_menubar ( )

Definition at line 2015 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly(), and QMenuBar::setNativeMenuBar().

2016 {
2018  return;
2019 
2020 #ifndef QT_MAC_USE_COCOA
2021  MenuRef clear_menu = 0;
2022  if (CreateNewMenu(0, 0, &clear_menu) == noErr) {
2023  SetRootMenu(clear_menu);
2024  ReleaseMenu(clear_menu);
2025  } else {
2026  qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__);
2027  }
2028  ClearMenuBar();
2029  qt_mac_command_set_enabled(0, kHICommandPreferences, false);
2030  InvalMenuBar();
2031 #else
2033  QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
2034  NSMenu *menu = [loader menu];
2035  [loader ensureAppMenuInMenu:menu];
2036  [NSApp setMainMenu:menu];
2037  const bool modal = qt_mac_should_disable_menu(0);
2038  if (qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal)
2039  qt_mac_set_modal_state(menu, modal);
2040  qt_mac_current_menubar.qmenubar = 0;
2041  qt_mac_current_menubar.modal = modal;
2042 #endif
2043 }
static bool qt_mac_should_disable_menu(QMenuBar *menuBar)
Definition: qmenu_mac.mm:1929
static void qt_mac_set_modal_state(OSMenuRef menu, bool on)
Definition: qmenu_mac.mm:701
static void qt_mac_command_set_enabled(MenuRef menu, UInt32 cmd, bool b)
Definition: qmenu_mac.mm:547
static struct @304 qt_mac_current_menubar
Q_CORE_EXPORT void qWarning(const char *,...)
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
struct OpaqueMenuRef * MenuRef
bool modal
Definition: qmenu_mac.mm:99
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.

◆ qt_mac_command_set_enabled()

static void qt_mac_command_set_enabled ( MenuRef  menu,
UInt32  cmd,
bool  b 
)
static

Definition at line 547 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction(), qt_mac_clear_menubar(), qt_mac_set_modal_state(), and QMenuPrivate::QMacMenuPrivate::removeAction().

548 {
549  if (cmd == kHICommandQuit)
551 
552  if (b) {
553  EnableMenuCommand(menu, cmd);
554  if (MenuRef dock_menu = GetApplicationDockTileMenu())
555  EnableMenuCommand(dock_menu, cmd);
556  } else {
557  DisableMenuCommand(menu, cmd);
558  if (MenuRef dock_menu = GetApplicationDockTileMenu())
559  DisableMenuCommand(dock_menu, cmd);
560  }
561 }
bool qt_mac_quit_menu_item_enabled
Definition: qmenu_mac.mm:75
struct OpaqueMenuRef * MenuRef

◆ qt_mac_CountMenuItems()

static int qt_mac_CountMenuItems ( OSMenuRef  menu)
static

Definition at line 124 of file qmenu_mac.mm.

Referenced by actualMenuItemVisibility().

125 {
126  if (menu) {
127 #ifndef QT_MAC_USE_COCOA
128  int ret = 0;
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)
134  continue;
135  ++ret;
136  }
137  return ret;
138 #else
139  return [menu numberOfItems];
140 #endif
141  }
142  return 0;
143 }

◆ qt_mac_create_iconref()

IconRef qt_mac_create_iconref ( const QPixmap px)

Definition at line 1109 of file qpixmap_mac.cpp.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

1110 {
1111  if (px.isNull())
1112  return 0;
1113 
1114  //create icon
1115  IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
1116  //create data
1117  {
1118  struct {
1119  OSType mac_type;
1120  int width, height, depth;
1121  bool mask;
1122  } images[] = {
1123  { kThumbnail32BitData, 128, 128, 32, false },
1124  { kThumbnail8BitMask, 128, 128, 8, true },
1125  { 0, 0, 0, 0, false } //end marker
1126  };
1127  for(int i = 0; images[i].mac_type; i++) {
1128  //get QPixmap data
1129  QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height);
1130 
1131  quint32 *sptr = (quint32 *) scaled_px.bits();
1132  quint32 *srow;
1133  uint sbpr = scaled_px.bytesPerLine();
1134 
1135  //get Handle data
1136  const int dbpr = images[i].width * (images[i].depth/8);
1137  Handle hdl = NewHandle(dbpr*images[i].height);
1138  if(!sptr) { //handle null pixmap
1139  memset((*hdl), '\0', dbpr*images[i].height);
1140  } else if(images[i].mask) {
1141  if(images[i].mac_type == kThumbnail8BitMask) {
1142  for(int y = 0, hindex = 0; y < images[i].height; ++y) {
1143  srow = sptr + (y * (sbpr/4));
1144  for(int x = 0; x < images[i].width; ++x)
1145  *((*hdl)+(hindex++)) = qAlpha(*(srow+x));
1146  }
1147  }
1148  } else {
1149  char *dest = (*hdl);
1150 #if defined(__i386__)
1151  if(images[i].depth == 32) {
1152  for(int y = 0; y < images[i].height; ++y) {
1153  uint *source = (uint*)((const uchar*)sptr+(sbpr*y));
1154  for(int x = 0; x < images[i].width; ++x, dest += 4)
1155  *((uint*)dest) = CFSwapInt32(*(source + x));
1156  }
1157  } else
1158 #endif
1159  {
1160  for(int y = 0; y < images[i].height; ++y)
1161  memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr);
1162  }
1163  }
1164 
1165  //set the family data to the Handle
1166  OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl);
1167  if(set != noErr)
1168  qWarning("%s: %d -- Unable to create icon data[%d]!! %ld",
1169  __FILE__, __LINE__, i, long(set));
1170  DisposeHandle(hdl);
1171  }
1172  }
1173 
1174  //acquire and cleanup
1175  IconRef ret;
1176  static int counter = 0;
1177  const OSType kQtCreator = 'CUTE';
1178  RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret);
1179  AcquireIconRef(ret);
1180  UnregisterIconRef(kQtCreator, (OSType)counter);
1181  DisposeHandle(reinterpret_cast<Handle>(iconFamily));
1182  counter++;
1183  return ret;
1184 
1185 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
signed long OSStatus
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
unsigned int quint32
Definition: qglobal.h:938
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
struct OpaqueIconRef * IconRef

◆ qt_mac_create_menu()

static OSMenuRef qt_mac_create_menu ( QWidget w)
static

Definition at line 2193 of file qmenu_mac.mm.

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

2194 {
2195  OSMenuRef ret;
2196 #ifndef QT_MAC_USE_COCOA
2197  ret = 0;
2198  if (CreateNewMenu(0, 0, &ret) == noErr) {
2200  SetMenuItemProperty(ret, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(w), &w);
2201 
2202  // kEventMenuMatchKey is only sent to the menu itself and not to
2203  // the application, install a separate handler for that event.
2204  EventHandlerRef eventHandlerRef;
2205  InstallMenuEventHandler(ret, qt_mac_menu_event,
2206  GetEventTypeCount(menu_menu_events),
2207  menu_menu_events, 0, &eventHandlerRef);
2208  menu_eventHandlers_hash()->insert(ret, eventHandlerRef);
2209  } else {
2210  qWarning("QMenu: Internal error");
2211  }
2212 #else
2213  if (QMenu *qmenu = qobject_cast<QMenu *>(w)){
2214  ret = [[QT_MANGLE_NAMESPACE(QCocoaMenu) alloc] initWithQMenu:qmenu];
2215  } else {
2216  ret = [[NSMenu alloc] init];
2217  }
2218 #endif
2219  return ret;
2220 }
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
static bool init
Q_CORE_EXPORT void qWarning(const char *,...)
MenuRef OSMenuRef
static EventTypeSpec menu_menu_events[]
Definition: qmenu_mac.mm:393
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
OSStatus qt_mac_menu_event(EventHandlerCallRef er, EventRef event, void *)
Definition: qmenu_mac.mm:397
static void qt_mac_create_menu_event_handler()
Definition: qmenu_mac.mm:534

◆ qt_mac_create_menu_event_handler()

static void qt_mac_create_menu_event_handler ( )
inlinestatic

Definition at line 534 of file qmenu_mac.mm.

Referenced by qt_mac_create_menu().

535 {
536  if (!mac_menu_event_handler) {
537  mac_menu_eventUPP = NewEventHandlerUPP(qt_mac_menu_event);
538  InstallEventHandler(GetApplicationEventTarget(), mac_menu_eventUPP,
539  GetEventTypeCount(menu_events), menu_events, 0,
542  }
543 }
static EventTypeSpec menu_events[]
Definition: qmenu_mac.mm:385
static void qt_mac_cleanup_menu_event()
Definition: qmenu_mac.mm:523
static EventHandlerUPP mac_menu_eventUPP
Definition: qmenu_mac.mm:522
static EventHandlerRef mac_menu_event_handler
Definition: qmenu_mac.mm:521
OSStatus qt_mac_menu_event(EventHandlerCallRef er, EventRef event, void *)
Definition: qmenu_mac.mm:397
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.

◆ qt_mac_dispose_rgn()

void qt_mac_dispose_rgn ( RgnHandle  r)

◆ qt_mac_get_accel()

static void qt_mac_get_accel ( quint32  accel_key,
quint32 modif,
quint32 key 
)
static

Definition at line 568 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

568  {
569  if (modif) {
570  *modif = constructModifierMask(accel_key);
571  }
572 
573  accel_key &= ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL);
574  if (key) {
575  *key = 0;
576  if (accel_key == Qt::Key_Return)
577  *key = kMenuReturnGlyph;
578  else if (accel_key == Qt::Key_Enter)
579  *key = kMenuEnterGlyph;
580  else if (accel_key == Qt::Key_Tab)
581  *key = kMenuTabRightGlyph;
582  else if (accel_key == Qt::Key_Backspace)
583  *key = kMenuDeleteLeftGlyph;
584  else if (accel_key == Qt::Key_Delete)
585  *key = kMenuDeleteRightGlyph;
586  else if (accel_key == Qt::Key_Escape)
587  *key = kMenuEscapeGlyph;
588  else if (accel_key == Qt::Key_PageUp)
589  *key = kMenuPageUpGlyph;
590  else if (accel_key == Qt::Key_PageDown)
591  *key = kMenuPageDownGlyph;
592  else if (accel_key == Qt::Key_Up)
593  *key = kMenuUpArrowGlyph;
594  else if (accel_key == Qt::Key_Down)
595  *key = kMenuDownArrowGlyph;
596  else if (accel_key == Qt::Key_Left)
597  *key = kMenuLeftArrowGlyph;
598  else if (accel_key == Qt::Key_Right)
599  *key = kMenuRightArrowGlyph;
600  else if (accel_key == Qt::Key_CapsLock)
601  *key = kMenuCapsLockGlyph;
602  else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15)
603  *key = (accel_key - Qt::Key_F1) + kMenuF1Glyph;
604  else if (accel_key == Qt::Key_Home)
605  *key = kMenuNorthwestArrowGlyph;
606  else if (accel_key == Qt::Key_End)
607  *key = kMenuSoutheastArrowGlyph;
608  }
609 }
static quint32 constructModifierMask(quint32 accel_key)
Definition: qmenu_mac.mm:145
int key

◆ qt_mac_get_rgn()

RgnHandle qt_mac_get_rgn ( )

◆ qt_mac_hiview_for() [1/2]

OSViewRef qt_mac_hiview_for ( const QWidget w)

◆ qt_mac_hiview_for() [2/2]

HIViewRef qt_mac_hiview_for ( OSWindowRef  w)

◆ qt_mac_is_ancestor()

static bool qt_mac_is_ancestor ( QWidget possibleAncestor,
QWidget child 
)
static

Definition at line 1910 of file qmenu_mac.mm.

Referenced by qt_mac_should_disable_menu().

1911 {
1912  if (!possibleAncestor)
1913  return false;
1914 
1915  QWidget * current = child->parentWidget();
1916  while (current != 0) {
1917  if (current == possibleAncestor)
1918  return true;
1919  current = current->parentWidget();
1920  }
1921  return false;
1922 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150

◆ qt_mac_menu_event()

OSStatus qt_mac_menu_event ( EventHandlerCallRef  er,
EventRef  event,
void *   
)

Definition at line 397 of file qmenu_mac.mm.

Referenced by qt_mac_create_menu(), and qt_mac_create_menu_event_handler().

398 {
399  QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
400 
401  bool handled_event = true;
402  UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
403  switch(eclass) {
404  case kEventClassCommand:
405  if (ekind == kEventCommandProcess) {
406  UInt32 context;
407  GetEventParameter(event, kEventParamMenuContext, typeUInt32,
408  0, sizeof(context), 0, &context);
409  HICommand cmd;
410  GetEventParameter(event, kEventParamDirectObject, typeHICommand,
411  0, sizeof(cmd), 0, &cmd);
412  if (!mac_keyboard_grabber && (context & kMenuContextKeyMatching)) {
413  QMacMenuAction *action = 0;
414  if (GetMenuCommandProperty(cmd.menu.menuRef, cmd.commandID, kMenuCreatorQt,
415  kMenuPropertyQAction, sizeof(action), 0, &action) == noErr) {
416  QWidget *widget = 0;
417  if (qApp->activePopupWidget())
418  widget = (qApp->activePopupWidget()->focusWidget() ?
419  qApp->activePopupWidget()->focusWidget() : qApp->activePopupWidget());
422  if (widget) {
423  int key = action->action->shortcut();
425  Qt::KeyboardModifiers(key & Qt::KeyboardModifierMask));
426  accel_ev.ignore();
427  qt_sendSpontaneousEvent(widget, &accel_ev);
428  if (accel_ev.isAccepted()) {
429  handled_event = false;
430  break;
431  }
432  }
433  }
434  }
435  handled_event = qt_mac_activate_action(cmd.menu.menuRef, cmd.commandID,
436  QAction::Trigger, context & kMenuContextKeyMatching);
437  }
438  break;
439  case kEventClassMenu: {
440  MenuRef menu;
441  GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu), NULL, &menu);
442  if (ekind == kEventMenuMatchKey) {
443  // Don't activate any actions if we are showing a native modal dialog,
444  // the key events should go to the dialog in this case.
446  return menuItemNotFoundErr;
447 
448  handled_event = false;
449  } else if (ekind == kEventMenuTargetItem) {
450  MenuCommand command;
451  GetEventParameter(event, kEventParamMenuCommand, typeMenuCommand,
452  0, sizeof(command), 0, &command);
453  handled_event = qt_mac_activate_action(menu, command, QAction::Hover, false);
454  } else if (ekind == kEventMenuOpening || ekind == kEventMenuClosed) {
455  qt_mac_menus_open_count += (ekind == kEventMenuOpening) ? 1 : -1;
456  MenuRef mr;
457  GetEventParameter(event, kEventParamDirectObject, typeMenuRef,
458  0, sizeof(mr), 0, &mr);
459 
460  QWidget *widget = 0;
461  if (GetMenuItemProperty(mr, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget) == noErr) {
462  if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) {
463  handled_event = true;
464  if (ekind == kEventMenuOpening) {
465  emit qmenu->aboutToShow();
466 
467  int merged = 0;
468  const QMenuPrivate::QMacMenuPrivate *mac_menu = qmenu->d_func()->mac_menu;
469  const int ActionItemsCount = mac_menu->actionItems.size();
470  for(int i = 0; i < ActionItemsCount; ++i) {
471  QMacMenuAction *action = mac_menu->actionItems.at(i);
472  if (action->action->isSeparator()) {
473  bool hide = false;
474  if(!action->action->isVisible()) {
475  hide = true;
476  } else if (merged && merged == i) {
477  hide = true;
478  } else {
479  for(int l = i+1; l < mac_menu->actionItems.size(); ++l) {
480  QMacMenuAction *action = mac_menu->actionItems.at(l);
481  if (action->merged) {
482  hide = true;
483  } else if (action->action->isSeparator()) {
484  if (hide)
485  break;
486  } else if (!action->merged) {
487  hide = false;
488  break;
489  }
490  }
491  }
492 
493  const int index = qt_mac_menu_find_action(mr, action);
494  if (hide) {
495  ++merged;
496  ChangeMenuItemAttributes(mr, index, kMenuItemAttrHidden, 0);
497  } else {
498  ChangeMenuItemAttributes(mr, index, 0, kMenuItemAttrHidden);
499  }
500  } else if (action->merged) {
501  ++merged;
502  }
503  }
504  } else {
505  emit qmenu->aboutToHide();
506  }
507  }
508  }
509  } else {
510  handled_event = false;
511  }
512  break; }
513  default:
514  handled_event = false;
515  break;
516  }
517  if (!handled_event) //let the event go through
518  return CallNextEventHandler(er, event);
519  return noErr; //we eat the event
520 }
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
Definition: qaction.cpp:839
The QKeyEvent class describes a key event.
Definition: qevent.h:224
EventRef event
QPointer< QWidget > widget
QKeySequence shortcut
the action&#39;s primary shortcut key
Definition: qaction.h:83
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QList< QMacMenuAction * > actionItems
Definition: qmenu_p.h:308
static QApplicationPrivate * instance()
static QWidget * focus_widget
bool isVisible() const
Definition: qaction.cpp:1246
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static bool native_modal_dialog_active
QFactoryLoader * l
struct OpaqueMenuRef * MenuRef
quint16 index
QWidget * mac_keyboard_grabber
Definition: qwidget_mac.mm:157
bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent action_e, bool by_accel)
Definition: qmenu_mac.mm:209
QPointer< QAction > action
Definition: qmenu_p.h:108
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
uchar merged
Definition: qmenu_p.h:107
int qt_mac_menus_open_count
Definition: qmenu_mac.mm:76

◆ qt_mac_menu_find_action() [1/2]

static int qt_mac_menu_find_action ( MenuRef  menu,
MenuCommand  cmd 
)
static

Definition at line 287 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction(), qt_mac_menu_event(), qt_mac_menu_find_action(), QMenuBarPrivate::QMacMenuBarPrivate::removeAction(), QMenuPrivate::QMacMenuPrivate::removeAction(), QMenuBarPrivate::QMacMenuBarPrivate::syncAction(), and QMenuPrivate::QMacMenuPrivate::syncAction().

288 {
289  MenuItemIndex ret_idx;
290  MenuRef ret_menu;
291  if (GetIndMenuItemWithCommandID(menu, cmd, 1, &ret_menu, &ret_idx) == noErr) {
292  if (ret_menu == menu)
293  return (int)ret_idx;
294  }
295  return -1;
296 }
struct OpaqueMenuRef * MenuRef

◆ qt_mac_menu_find_action() [2/2]

static int qt_mac_menu_find_action ( MenuRef  menu,
QMacMenuAction action 
)
static

Definition at line 297 of file qmenu_mac.mm.

298 {
299  return qt_mac_menu_find_action(menu, action->command);
300 }
uint command
Definition: qmenu_p.h:102
static int qt_mac_menu_find_action(MenuRef menu, MenuCommand cmd)
Definition: qmenu_mac.mm:287

◆ qt_mac_menu_merge_accel()

static QKeySequence qt_mac_menu_merge_accel ( QMacMenuAction action)
static

Definition at line 955 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

956 {
957  QKeySequence ret;
958 #ifdef QT_MAC_USE_COCOA
959  QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
960 #endif
962  ret = action->action->shortcut();
963 #ifndef QT_MAC_USE_COCOA
964  else if (action->command == kHICommandPreferences)
966  else if (action->command == kHICommandQuit)
968 #else
969  else if (action->menuItem == [loader preferencesMenuItem])
971  else if (action->menuItem == [loader quitMenuItem])
973 #endif
974  return ret;
975 }
uint command
Definition: qmenu_p.h:102
QKeySequence shortcut
the action&#39;s primary shortcut key
Definition: qaction.h:83
MenuRole menuRole
the action&#39;s menu role
Definition: qaction.h:88
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ qt_mac_menu_merge_action()

static MenuCommand qt_mac_menu_merge_action ( MenuRef  merge,
QMacMenuAction action 
)
static

Definition at line 779 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction().

783 {
784  if (qt_mac_no_menubar_merge || action->action->menu() || action->action->isSeparator()
785  || action->action->menuRole() == QAction::NoRole)
786  return 0;
787 
789  int st = t.lastIndexOf(QLatin1Char('\t'));
790  if (st != -1)
791  t.remove(st, t.length()-st);
792  t.replace(QRegExp(QString::fromLatin1("\\.*$")), QLatin1String("")); //no ellipses
793  //now the fun part
794 #ifndef QT_MAC_USE_COCOA
795  MenuCommand ret = 0;
796 #else
797  NSMenuItem *ret = 0;
798  QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
799 #endif
800  switch (action->action->menuRole()) {
801  case QAction::NoRole:
802  ret = 0;
803  break;
805 #ifndef QT_MAC_USE_COCOA
806  {
807  QMenuMergeList *list = 0;
808  if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
809  sizeof(list), 0, &list) == noErr && list) {
810  MenuCommand lastCustom = kHICommandCustomMerge;
811  for(int i = 0; i < list->size(); ++i) {
812  QMenuMergeItem item = list->at(i);
813  if (item.command == lastCustom)
814  ++lastCustom;
815  }
816  ret = lastCustom;
817  } else {
818  // The list hasn't been created, so, must be the first one.
819  ret = kHICommandCustomMerge;
820  }
821  }
822 #else
823  ret = [loader appSpecificMenuItem];
824 #endif
825  break;
826  case QAction::AboutRole:
827 #ifndef QT_MAC_USE_COCOA
828  ret = kHICommandAbout;
829 #else
830  ret = [loader aboutMenuItem];
831 #endif
832  break;
834 #ifndef QT_MAC_USE_COCOA
835  ret = kHICommandAboutQt;
836 #else
837  ret = [loader aboutQtMenuItem];
838 #endif
839  break;
840  case QAction::QuitRole:
841 #ifndef QT_MAC_USE_COCOA
842  ret = kHICommandQuit;
843 #else
844  ret = [loader quitMenuItem];
845 #endif
846  break;
848 #ifndef QT_MAC_USE_COCOA
849  ret = kHICommandPreferences;
850 #else
851  ret = [loader preferencesMenuItem];
852 #endif
853  break;
855  QString aboutString = QMenuBar::tr("About").toLower();
856  if (t.startsWith(aboutString) || t.endsWith(aboutString)) {
857  if (t.indexOf(QRegExp(QString::fromLatin1("qt$"), Qt::CaseInsensitive)) == -1) {
858 #ifndef QT_MAC_USE_COCOA
859  ret = kHICommandAbout;
860 #else
861  ret = [loader aboutMenuItem];
862 #endif
863  } else {
864 #ifndef QT_MAC_USE_COCOA
865  ret = kHICommandAboutQt;
866 #else
867  ret = [loader aboutQtMenuItem];
868 #endif
869  }
870  } else if (t.startsWith(QMenuBar::tr("Config").toLower())
871  || t.startsWith(QMenuBar::tr("Preference").toLower())
872  || t.startsWith(QMenuBar::tr("Options").toLower())
873  || t.startsWith(QMenuBar::tr("Setting").toLower())
874  || t.startsWith(QMenuBar::tr("Setup").toLower())) {
875 #ifndef QT_MAC_USE_COCOA
876  ret = kHICommandPreferences;
877 #else
878  ret = [loader preferencesMenuItem];
879 #endif
880  } else if (t.startsWith(QMenuBar::tr("Quit").toLower())
881  || t.startsWith(QMenuBar::tr("Exit").toLower())) {
882 #ifndef QT_MAC_USE_COCOA
883  ret = kHICommandQuit;
884 #else
885  ret = [loader quitMenuItem];
886 #endif
887  }
888  }
889  break;
890  }
891 
892 #ifndef QT_MAC_USE_COCOA
893  QMenuMergeList *list = 0;
894  if (GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
895  sizeof(list), 0, &list) == noErr && list) {
896  for(int i = 0; i < list->size(); ++i) {
897  QMenuMergeItem item = list->at(i);
898  if (item.command == ret && item.action)
899  return 0;
900  }
901  }
902 
903  QAction *cmd_action = 0;
904  if (GetMenuCommandProperty(merge, ret, kMenuCreatorQt, kMenuPropertyQAction,
905  sizeof(cmd_action), 0, &cmd_action) == noErr && cmd_action)
906  return 0; //already taken
907 #else
908  if (QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge)) {
909  for(int i = 0; i < list->size(); ++i) {
910  const QMenuMergeItem &item = list->at(i);
911  if (item.menuItem == ret && item.action)
912  return 0;
913  }
914  }
915 
916 #endif
917  return ret;
918 }
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
Definition: qaction.cpp:839
bool qt_mac_no_menubar_merge
Definition: qmenu_mac.mm:74
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QMacMenuAction * action
Definition: qmenu_p.h:121
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
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
MenuCommand command
Definition: qmenu_p.h:116
The QString class provides a Unicode character string.
Definition: qstring.h:83
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
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
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define st(var, type, card)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
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
QPointer< QAction > action
Definition: qmenu_p.h:108
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
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qt_mac_menu_merge_text()

static QString qt_mac_menu_merge_text ( QMacMenuAction action)
static

Definition at line 920 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::syncAction().

921 {
922  QString ret;
924 #ifdef QT_MAC_USE_COCOA
925  QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
926 #endif
928  ret = action->action->text();
929 #ifndef QT_MAC_USE_COCOA
930  else if (action->command == kHICommandAbout)
932  else if (action->command == kHICommandAboutQt)
933  ret = QMenuBar::tr("About Qt");
934  else if (action->command == kHICommandPreferences)
936  else if (action->command == kHICommandQuit)
938 #else
939  else if (action->menuItem == [loader aboutMenuItem]) {
941  } else if (action->menuItem == [loader aboutQtMenuItem]) {
942  if (action->action->text() == QString("About Qt"))
943  ret = QMenuBar::tr("About Qt");
944  else
945  ret = action->action->text();
946  } else if (action->menuItem == [loader preferencesMenuItem]) {
948  } else if (action->menuItem == [loader quitMenuItem]) {
950  }
951 #endif
952  return ret;
953 }
uint command
Definition: qmenu_p.h:102
int type
Definition: qmetatype.cpp:239
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString qAppName()
MenuRole menuRole
the action&#39;s menu role
Definition: qaction.h:88
QString qt_mac_applicationmenu_string(int type)
em>Reimplemented Function
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
QPointer< QAction > action
Definition: qmenu_p.h:108

◆ qt_mac_menubar_is_open()

bool qt_mac_menubar_is_open ( )

Definition at line 750 of file qmenu_mac.mm.

Referenced by QKeyMapperPrivate::translateKeyEvent().

751 {
752  return qt_mac_menus_open_count > 0;
753 }
int qt_mac_menus_open_count
Definition: qmenu_mac.mm:76

◆ qt_mac_set_menubar_icons()

void Q_GUI_EXPORT qt_mac_set_menubar_icons ( bool  b)

Definition at line 977 of file qmenu_mac.mm.

static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.

◆ qt_mac_set_menubar_merge()

void Q_GUI_EXPORT qt_mac_set_menubar_merge ( bool  b)

Definition at line 981 of file qmenu_mac.mm.

981 { qt_mac_no_menubar_merge = !b; }
bool qt_mac_no_menubar_merge
Definition: qmenu_mac.mm:74

◆ qt_mac_set_modal_state()

static void qt_mac_set_modal_state ( OSMenuRef  menu,
bool  on 
)
static

Definition at line 701 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly(), and qt_mac_clear_menubar().

702 {
703 #ifndef QT_MAC_USE_COCOA
704  OSMenuRef merge = 0;
705  GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeMenu,
706  sizeof(merge), 0, &merge);
707 
709 
710  UInt32 commands[] = { kHICommandQuit, kHICommandPreferences, kHICommandAbout, kHICommandAboutQt, 0 };
711  for(int c = 0; commands[c]; c++) {
712  bool enabled = !on;
713  if (enabled) {
714  QMacMenuAction *action = 0;
715  GetMenuCommandProperty(menu, commands[c], kMenuCreatorQt, kMenuPropertyQAction,
716  sizeof(action), 0, &action);
717  if (!action && merge) {
718  GetMenuCommandProperty(merge, commands[c], kMenuCreatorQt, kMenuPropertyQAction,
719  sizeof(action), 0, &action);
720  if (!action) {
721  QMenuMergeList *list = 0;
722  GetMenuItemProperty(merge, 0, kMenuCreatorQt, kMenuPropertyMergeList,
723  sizeof(list), 0, &list);
724  for(int i = 0; list && i < list->size(); ++i) {
725  QMenuMergeItem item = list->at(i);
726  if (item.command == commands[c] && item.action) {
727  action = item.action;
728  break;
729  }
730  }
731  }
732  }
733 
734  if (!action) {
735  if (commands[c] != kHICommandQuit)
736  enabled = false;
737  } else {
738  enabled = action->action ? action->action->isEnabled() : 0;
739  }
740  }
741  qt_mac_command_set_enabled(menu, commands[c], enabled);
742  }
743 #else
746  // I'm ignoring the special items now, since they should get handled via a syncAction()
747 #endif
748 }
bool isEnabled() const
Definition: qaction.cpp:1208
unsigned char c[8]
Definition: qnumeric_p.h:62
QMacMenuAction * action
Definition: qmenu_p.h:121
MenuCommand command
Definition: qmenu_p.h:116
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
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
QPointer< QAction > action
Definition: qmenu_p.h:108
#define enabled
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bool on)
Definition: qmenu_mac.mm:652

◆ qt_mac_set_modal_state_helper_recursive()

void qt_mac_set_modal_state_helper_recursive ( OSMenuRef  menu,
OSMenuRef  merge,
bool  on 
)

Definition at line 652 of file qmenu_mac.mm.

Referenced by qt_mac_set_modal_state().

653 {
654 #ifndef QT_MAC_USE_COCOA
655  for (int i = 0; i < CountMenuItems(menu); i++) {
656  OSMenuRef submenu;
657  GetMenuItemHierarchicalMenu(menu, i+1, &submenu);
658  if (submenu != merge) {
659  if (submenu)
660  qt_mac_set_modal_state_helper_recursive(submenu, merge, on);
661  if (on)
662  DisableMenuItem(submenu, 0);
663  else
664  EnableMenuItem(submenu, 0);
665  }
666  }
667 #else
668  bool modalWindowOnScreen = qApp->activeModalWidget() != 0;
669  for (NSMenuItem *item in [menu itemArray]) {
670  OSMenuRef submenu = [item submenu];
671  if (submenu != merge) {
672  if (submenu)
673  qt_mac_set_modal_state_helper_recursive(submenu, merge, on);
674  if (!on) {
675  // The item should follow what the QAction has.
676  if ([item tag]) {
677  QAction *action = reinterpret_cast<QAction *>([item tag]);
678  syncNSMenuItemEnabled(item, action->isEnabled());
679  } else {
680  syncNSMenuItemEnabled(item, YES);
681  }
682  // We sneak in some extra code here to handle a menu problem:
683  // If there is no window on screen, we cannot set 'nil' as
684  // menu item target, because then cocoa will disable the item
685  // (guess it assumes that there will be no first responder to
686  // catch the trigger anyway?) OTOH, If we have a modal window,
687  // then setting the menu loader as target will make cocoa not
688  // deliver the trigger because the loader is then seen as modally
689  // shaddowed). So either way there are shortcomings. Instead, we
690  // decide the target as late as possible:
691  [item setTarget:modalWindowOnScreen ? nil : getMenuLoader()];
692  } else {
693  syncNSMenuItemEnabled(item, NO);
694  }
695  }
696  }
697 #endif
698 }
bool isEnabled() const
Definition: qaction.cpp:1208
void NSMenuItem
Definition: qmenu_p.h:80
#define qApp
MenuRef OSMenuRef
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bool on)
Definition: qmenu_mac.mm:652

◆ qt_mac_set_native_menubar()

void Q_GUI_EXPORT qt_mac_set_native_menubar ( bool  b)

Definition at line 979 of file qmenu_mac.mm.

static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.

◆ qt_mac_should_disable_menu()

static bool qt_mac_should_disable_menu ( QMenuBar menuBar)
static

Definition at line 1929 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly(), and qt_mac_clear_menubar().

1930 {
1931  QWidget *modalWidget = qApp->activeModalWidget();
1932  if (!modalWidget)
1933  return false;
1934 
1935  if (menuBar && menuBar == menubars()->value(modalWidget))
1936  // The menu bar is owned by the modal widget.
1937  // In that case we should enable it:
1938  return false;
1939 
1940  // When there is an application modal window on screen, the entries of
1941  // the menubar should be disabled. The exception in Qt is that if the
1942  // modal window is the only window on screen, then we enable the menu bar.
1943  QWidget *w = modalWidget;
1945  while (w) {
1946  if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) {
1947  for (int i=0; i<topLevelWidgets.size(); ++i) {
1948  QWidget *top = topLevelWidgets.at(i);
1949  if (w != top && top->isVisible()) {
1950  // INVARIANT: we found another visible window
1951  // on screen other than our modalWidget. We therefore
1952  // disable the menu bar to follow normal modality logic:
1953  return true;
1954  }
1955  }
1956  // INVARIANT: We have only one window on screen that happends
1957  // to be application modal. We choose to enable the menu bar
1958  // in that case to e.g. enable the quit menu item.
1959  return false;
1960  }
1961  w = w->parentWidget();
1962  }
1963 
1964  // INVARIANT: modalWidget is window modal. Disable menu entries
1965  // if the menu bar belongs to an ancestor of modalWidget. If menuBar
1966  // is nil, we understand it as the default menu bar set by the nib:
1967  return menuBar ? qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget) : false;
1968 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
static QWidgetList topLevelWidgets()
bool isVisible() const
Definition: qwidget.h:1005
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::WindowModality windowModality
which windows are blocked by the modal widget
Definition: qwidget.h:156
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
static bool qt_mac_is_ancestor(QWidget *possibleAncestor, QWidget *child)
Definition: qmenu_mac.mm:1910
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qt_mac_watchingAboutToShow()

bool qt_mac_watchingAboutToShow ( QMenu menu)

Definition at line 119 of file qmenu_mac.mm.

Referenced by actualMenuItemVisibility().

120 {
121  return menu && menu->receivers(SIGNAL(aboutToShow()));
122 }
#define SIGNAL(a)
Definition: qobjectdefs.h:227
int receivers(const char *signal) const
Returns the number of receivers connected to the signal.
Definition: qobject.cpp:2406

◆ qt_mac_widget_in_menu_eventHandler()

static OSStatus qt_mac_widget_in_menu_eventHandler ( EventHandlerCallRef  er,
EventRef  event,
void *   
)
static

Definition at line 312 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction().

313 {
314  UInt32 ekind = GetEventKind(event);
315  UInt32 eclass = GetEventClass(event);
316  OSStatus result = eventNotHandledErr;
317  switch (eclass) {
318  case kEventClassMenu:
319  switch (ekind) {
320  default:
321  break;
322  case kEventMenuMeasureItemWidth: {
323  MenuItemIndex item;
324  GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex,
325  0, sizeof(item), 0, &item);
326  OSMenuRef menu;
327  GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu);
328  QWidget *widget;
329  if (GetMenuItemProperty(menu, item, kMenuCreatorQt, kMenuPropertyWidgetActionWidget,
330  sizeof(widget), 0, &widget) == noErr) {
331  short width = short(widget->sizeHint().width());
332  SetEventParameter(event, kEventParamMenuItemWidth, typeSInt16,
333  sizeof(short), &width);
334  result = noErr;
335  }
336  break; }
337  case kEventMenuMeasureItemHeight: {
338  MenuItemIndex item;
339  GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex,
340  0, sizeof(item), 0, &item);
341  OSMenuRef menu;
342  GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu);
343  QWidget *widget;
344  if (GetMenuItemProperty(menu, item, kMenuCreatorQt, kMenuPropertyWidgetActionWidget,
345  sizeof(widget), 0, &widget) == noErr && widget) {
346  short height = short(widget->sizeHint().height());
347  SetEventParameter(event, kEventParamMenuItemHeight, typeSInt16,
348  sizeof(short), &height);
349  result = noErr;
350  }
351  break; }
352  case kEventMenuDrawItem:
353  result = noErr;
354  break;
355  case kEventMenuCalculateSize: {
356  result = CallNextEventHandler(er, event);
357  if (result == noErr) {
358  OSMenuRef menu;
359  GetEventParameter(event, kEventParamDirectObject, typeMenuRef, 0, sizeof(menu), 0, &menu);
360  HIViewRef content;
361  HIMenuGetContentView(menu, kThemeMenuTypePullDown, &content);
362  UInt16 count = CountMenuItems(menu);
363  for (MenuItemIndex i = 1; i <= count; ++i) {
364  QWidget *widget;
365  if (GetMenuItemProperty(menu, i, kMenuCreatorQt, kMenuPropertyWidgetActionWidget,
366  sizeof(widget), 0, &widget) == noErr && widget) {
367  RgnHandle itemRgn = qt_mac_get_rgn();
368  GetControlRegion(content, i, itemRgn);
369 
370  Rect bounds;
371  GetRegionBounds( itemRgn, &bounds );
372  qt_mac_dispose_rgn(itemRgn);
373  widget->setGeometry(bounds.left, bounds.top,
374  bounds.right - bounds.left, bounds.bottom - bounds.top);
375  }
376  }
377  }
378  break; }
379  }
380  }
381  return result;
382 }
EventRef event
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int width() const
Returns the width.
Definition: qsize.h:126
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
struct OpaqueControlRef * HIViewRef
signed long OSStatus
struct OpaqueRgnHandle * RgnHandle
MenuRef OSMenuRef
void qt_mac_dispose_rgn(RgnHandle r)
RgnHandle qt_mac_get_rgn()
int height() const
Returns the height.
Definition: qsize.h:129
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195

◆ qt_sendSpontaneousEvent()

bool qt_sendSpontaneousEvent ( QObject ,
QEvent  
)

Definition at line 5779 of file qapplication.cpp.

Referenced by qt_mac_menu_event().

5780 {
5782 }
EventRef event
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)

Variable Documentation

◆ fallback

QMenuBar* fallback = 0
static

◆ kMenuCreatorQt

const UInt32 kMenuCreatorQt = 'cute'

◆ mac_keyboard_grabber

QWidget* mac_keyboard_grabber

Definition at line 157 of file qwidget_mac.mm.

Referenced by QWidget::keyboardGrabber().

◆ mac_menu_event_handler

EventHandlerRef mac_menu_event_handler = 0
static

Definition at line 521 of file qmenu_mac.mm.

Referenced by qt_mac_cleanup_menu_event(), and qt_mac_create_menu_event_handler().

◆ mac_menu_eventUPP

EventHandlerUPP mac_menu_eventUPP = 0
static

Definition at line 522 of file qmenu_mac.mm.

Referenced by qt_mac_cleanup_menu_event(), and qt_mac_create_menu_event_handler().

◆ menu_events

EventTypeSpec menu_events[]
static
Initial value:
= {
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassMenu, kEventMenuTargetItem },
{ kEventClassMenu, kEventMenuOpening },
{ kEventClassMenu, kEventMenuClosed }
}

Definition at line 385 of file qmenu_mac.mm.

Referenced by qt_mac_create_menu_event_handler().

◆ menu_menu_events

EventTypeSpec menu_menu_events[]
static
Initial value:
= {
{ kEventClassMenu, kEventMenuMatchKey }
}

Definition at line 393 of file qmenu_mac.mm.

Referenced by qt_mac_create_menu().

◆ modal

bool modal

◆ qmenubar

QPointer<QMenuBar> qmenubar

Definition at line 98 of file qmenu_mac.mm.

Referenced by QMenuPrivate::activateCausedStack(), and qt_mac_activate_action().

◆ qt_mac_current_menubar

struct { ... } qt_mac_current_menubar

◆ qt_mac_menu_static_cmd_id

uint qt_mac_menu_static_cmd_id = 'QT00'
static

◆ qt_mac_menus_open_count

int qt_mac_menus_open_count = 0

Definition at line 76 of file qmenu_mac.mm.

Referenced by qt_mac_menu_event(), and qt_mac_menubar_is_open().

◆ qt_mac_no_menubar_merge

bool qt_mac_no_menubar_merge = false

◆ qt_mac_quit_menu_item_enabled

bool qt_mac_quit_menu_item_enabled = true

◆ widget_in_menu_events

EventTypeSpec widget_in_menu_events[]
static
Initial value:
= {
{ kEventClassMenu, kEventMenuMeasureItemWidth },
{ kEventClassMenu, kEventMenuMeasureItemHeight },
{ kEventClassMenu, kEventMenuDrawItem },
{ kEventClassMenu, kEventMenuCalculateSize }
}

Definition at line 305 of file qmenu_mac.mm.

Referenced by QMenuPrivate::QMacMenuPrivate::addAction().