44 #ifdef QT_MAC_USE_COCOA 45 #import <private/qcocoamenu_mac_p.h> 46 #import <private/qcocoamenuloader_mac_p.h> 47 #import <private/qcocoaapplication_mac_p.h> 48 #include <private/qt_cocoa_helpers_mac_p.h> 49 #include <private/qapplication_p.h> 50 #include <private/qaction_p.h> 51 #include <private/qcocoaapplication_mac_p.h> 53 #include <QtGui/QMenu> 65 extern NSString *qt_mac_removePrivateUnicode(NSString*
string);
70 @implementation QT_MANGLE_NAMESPACE(QCocoaMenu)
72 - (id)initWithQMenu:(
QMenu*)menu
78 [
self setAutoenablesItems:NO];
79 [
self setDelegate:self];
84 - (void)menu:(NSMenu*)menu willHighlightItem:(
NSMenuItem*)item
90 qt_mac_clear_status_text(previousAction);
96 if (
QAction *action = reinterpret_cast<QAction *>([item tag])) {
98 previousAction = action;
100 qt_mac_menu_emit_hovered(qtmenu, action);
101 action->showStatusText(0);
105 - (void)menuWillOpen:(NSMenu*)menu
111 qt_mac_emit_menuSignals(qtmenu,
true);
115 - (void)menuDidClose:(NSMenu*)menu
118 if (previousAction) {
119 qt_mac_clear_status_text(previousAction);
124 - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier
128 if (![item isEnabled] || [item isHidden] || [item isSeparatorItem])
130 if ([item hasSubmenu]) {
131 if ([
self hasShortcut:[item submenu]
133 forModifiers:modifier whichItem:outItem]) {
139 NSString *menuKey = [item keyEquivalent];
140 if (menuKey && NSOrderedSame == [menuKey
compare:key]
141 && (modifier == [item keyEquivalentModifierMask])) {
152 - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(
id *)target action:(
SEL *)action
163 NSString *characters = qt_mac_removePrivateUnicode([event characters]);
164 if ([
self hasShortcut:menu
167 forModifiers:([event modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask))
168 whichItem:&whichItem]) {
171 if (whichItem && [whichItem tag]) {
172 qaction =
reinterpret_cast<QAction *
>([whichItem tag]);
174 if (
qApp->activePopupWidget())
175 widget = (
qApp->activePopupWidget()->focusWidget() ?
176 qApp->activePopupWidget()->focusWidget() :
qApp->activePopupWidget());
181 widget =
qApp->activeWindow();
182 if (qaction && widget) {
188 if (accel_ev.isAccepted()) {
199 - (NSInteger)indexOfItemWithTarget:(
id)anObject andAction:(
SEL)actionSelector
201 NSInteger
index = [
super indexOfItemWithTarget:anObject andAction:actionSelector];
202 static SEL selForOFCP = NSSelectorFromString(
@"orderFrontCharacterPalette:");
203 if (index == -1 && selForOFCP == actionSelector) {
205 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)];
206 return [
super indexOfItemWithTarget:loader andAction:actionSelector];
216 void qt_mac_emit_menuSignals(
QMenu *menu,
bool show)
228 qt_mac_menus_open_count += delta;
231 void qt_mac_clear_status_text(
QAction *action)
236 void qt_mac_menu_emit_hovered(
QMenu *menu,
QAction *action)
The QApplication class manages the GUI application's control flow and main settings.
The QKeyEvent class describes a key event.
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
QKeySequence shortcut
the action's primary shortcut key
bool showStatusText(QWidget *widget=0)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent w...
The QString class provides a Unicode character string.
The QObject class is the base class of all Qt objects.
static QWidget * focus_widget
#define QT_FORWARD_DECLARE_CLASS(name)
#define QT_BEGIN_NAMESPACE
This macro expands to.
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
bool qt_dispatchKeyEvent(void *keyEvent, QWidget *widgetToGetEvent)
The QCoreApplication class provides an event loop for console Qt applications.
static QWidget * activePopupWidget()
Returns the active popup widget.
#define QT_MANGLE_NAMESPACE(name)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
The QEvent class is the base class of all event classes.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
The QAction class provides an abstract user interface action that can be inserted into widgets...