summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnsview_menus.mm
Commit message (Collapse)AuthorAgeFilesLines
* macOS: Clean up header includes to use quotes or brackets as appropriateTor Arne Vestbø2020-04-151-5/+5
| | | | | | | | The includes can be sorted and unified even more, but that's left for another rainy day. Change-Id: I4d5670d6d8389f69d2631b83b8f421d1f685a0f9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Mac: disable application menu items during modal sessionVolker Hilsheimer2020-01-241-1/+2
| | | | | | | | | | | The default menu items in the application menu are not part of a traversable menu object hierarchy, so we never find a menubar. Since that is only the case for those items, we can disable them during any modal session. Change-Id: Ie8d8db274176237de664c6e5ebfe5015e13800e4 Fixes: QTBUG-80273 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Simplify Objective-C namespacingTor Arne Vestbø2019-10-151-2/+2
| | | | | | | | | | | | | | | | We only need to use the QT_MANGLE_NAMESPACE macro when declaring the interface of the class. As long as we couple that with an alias declaration using QT_NAMESPACE_ALIAS_OBJC_CLASS, any further uses of the class name can be un-namespaced, including declaring categories on the class. The only snag with QT_NAMESPACE_ALIAS_OBJC_CLASS is that it can only be used once per class and translation unit, so forward declarations get hairy, but we can avoid that by just including the headers instead. Change-Id: I333bcd18fe1e18d81fbd560b0941c98b1c32460e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Cocoa Menus: Add support for menu items in window-less appsGabriel de Dietrich2018-05-231-13/+3
| | | | | | | | | | | | | | | | | Since we moved the menu items validation and target/action to QNSView (thus relying on the responder chain), we need to take care of case when the applications that doesn't have any window open. By adding similar methods to QCocoaApplicationDelegate, the last responder, we ensure the menu items will be validated and will trigger properly. This is particularly necessary for dock menu items, which live separately from any top-level widget. Dock menu added to Menurama which won't quit when its last window is closed. This way we can test that dock menu items will trigger in the absence of any window. Change-Id: I56d864eb9da1f8dd5adb2a3b6c3dd5304c723117 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Cocoa Menus: Clean up codeGabriel de Dietrich2018-04-261-6/+8
| | | | | | | | | | | | In this edition: * Use Objective-C properties where appropriate. * Use recently introduced qt_objc_cast(). * Remove uses of foreach. * Update copyright headers. Change-Id: I2a07a7b6cab27b833e4deaeedf9563463ff55914 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Cocoa Menus: Use the responder chain for menu items target/actionGabriel de Dietrich2018-04-191-0/+141
We start by setting the menu item target to nil. Then, -[qt_itemFired:] action is now in QNSView, which itself is naturally inserted in the responder chain. This removes the need to track and change the menu item's target/action when we're displaying a native dialog. Part of this is possible because we now derive our own QCocoaNSMenuItem class from NSMenuItem. We use -[respondsToSelector:] to decide whether the QNSView in the responder chain should respond to cut:, copy:, etc. And we only return YES when the view is first responder. The invocation to these action is forwarded to the same views' -[qt_itemFired:]. Message forwarding is done via forwardInvocation:, but experiments have shown that it can be done by the sole means of respondsToSelector: and direct invocation from cut:, copy:, etc. See the usage of the macro QT_COCOA_DYNAMIC_MENU_ITEM_ACTION. Menu validation also happens in QNSView and looks for modal windows. Therefore, -[worksWhenModal] is no longer necessary. Also, since the target is no longer set, the logic as documented in NSMenuItem.target won't work anymore. Most items from QCocoaMenuLoader also become QCocoaNSMenuItem and get the same target/action, which removes a bit of duplicated (and outdated) code. A particular case is the Quit item, which gets the terminate: action set until an actual menu item is added. Tested with texedit and standard dialogs examples together with menus, menurama and bigmenucreator manual tests. We also renamed some functions and variables to reflect common naming practices. Change-Id: I9b51d3be3467a666d8c3dcf8585edbc821e0282e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>