equal
deleted
inserted
replaced
44 #ifdef QT_MAC_USE_COCOA |
44 #ifdef QT_MAC_USE_COCOA |
45 #import <private/qcocoamenu_mac_p.h> |
45 #import <private/qcocoamenu_mac_p.h> |
46 #import <private/qcocoamenuloader_mac_p.h> |
46 #import <private/qcocoamenuloader_mac_p.h> |
47 #include <private/qt_cocoa_helpers_mac_p.h> |
47 #include <private/qt_cocoa_helpers_mac_p.h> |
48 #include <private/qapplication_p.h> |
48 #include <private/qapplication_p.h> |
|
49 #include <private/qaction_p.h> |
49 |
50 |
50 #include <QtGui/QMenu> |
51 #include <QtGui/QMenu> |
51 |
52 |
52 QT_FORWARD_DECLARE_CLASS(QAction) |
53 QT_FORWARD_DECLARE_CLASS(QAction) |
53 QT_FORWARD_DECLARE_CLASS(QWidget) |
54 QT_FORWARD_DECLARE_CLASS(QWidget) |
68 - (id)initWithQMenu:(QMenu*)menu |
69 - (id)initWithQMenu:(QMenu*)menu |
69 { |
70 { |
70 self = [super init]; |
71 self = [super init]; |
71 if (self) { |
72 if (self) { |
72 qmenu = menu; |
73 qmenu = menu; |
|
74 previousAction = 0; |
73 [self setAutoenablesItems:NO]; |
75 [self setAutoenablesItems:NO]; |
74 [self setDelegate:self]; |
76 [self setDelegate:self]; |
75 } |
77 } |
76 return self; |
78 return self; |
77 } |
79 } |
79 - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; |
81 - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; |
80 { |
82 { |
81 Q_UNUSED(menu); |
83 Q_UNUSED(menu); |
82 |
84 |
83 if (!item) { |
85 if (!item) { |
84 // ### According to the docs everything will be highlighted. Not sure what we should do in |
86 if (previousAction) { |
85 // Qt, so just return. |
87 qt_mac_clear_status_text(previousAction); |
|
88 previousAction = 0; |
|
89 } |
86 return; |
90 return; |
87 } |
91 } |
88 |
92 |
89 if (QAction *action = reinterpret_cast<QAction *>([item tag])) |
93 if (QAction *action = reinterpret_cast<QAction *>([item tag])) { |
|
94 QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu; |
|
95 previousAction = action; |
90 action->activate(QAction::Hover); |
96 action->activate(QAction::Hover); |
|
97 qt_mac_menu_emit_hovered(qtmenu, action); |
|
98 action->showStatusText(0); // 0 widget -> action's parent |
|
99 } |
91 } |
100 } |
92 |
101 |
93 - (void)menuWillOpen:(NSMenu*)menu; |
102 - (void)menuWillOpen:(NSMenu*)menu; |
94 { |
103 { |
95 while (QWidget *popup |
104 while (QWidget *popup |
98 QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu; |
107 QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu; |
99 qt_mac_emit_menuSignals(qtmenu, true); |
108 qt_mac_emit_menuSignals(qtmenu, true); |
100 qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible()); |
109 qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible()); |
101 } |
110 } |
102 |
111 |
103 - (void)menuWillClose:(NSMenu*)menu; |
112 - (void)menuDidClose:(NSMenu*)menu; |
104 { |
113 { |
105 qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, false); |
114 qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, false); |
|
115 if (previousAction) { |
|
116 qt_mac_clear_status_text(previousAction); |
|
117 previousAction = 0; |
|
118 } |
106 } |
119 } |
107 |
120 |
108 - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier |
121 - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier |
109 whichItem:(NSMenuItem**)outItem |
122 whichItem:(NSMenuItem**)outItem |
110 { |
123 { |
192 emit menu->aboutToHide(); |
205 emit menu->aboutToHide(); |
193 delta = -1; |
206 delta = -1; |
194 } |
207 } |
195 qt_mac_menus_open_count += delta; |
208 qt_mac_menus_open_count += delta; |
196 } |
209 } |
|
210 |
|
211 void qt_mac_clear_status_text(QAction *action) |
|
212 { |
|
213 action->d_func()->showStatusText(0, QString()); |
|
214 } |
|
215 |
|
216 void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action) |
|
217 { |
|
218 emit menu->hovered(action); |
|
219 } |
|
220 |
|
221 |
197 QT_END_NAMESPACE |
222 QT_END_NAMESPACE |
198 |
223 |
199 #endif |
224 #endif |