summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoansmenu.h
Commit message (Collapse)AuthorAgeFilesLines
* macOS: Simplify Objective-C namespacingTor Arne Vestbø2019-10-151-12/+1
| | | | | | | | | | | | | | | | 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: Clean up codeGabriel de Dietrich2018-04-261-1/+1
| | | | | | | | | | | | 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>
* QCocoaNSMenuItem: Add default initializerGabriel de Dietrich2018-04-251-0/+1
| | | | | | | Just tidying code a bit. Change-Id: I492535094533ee307d757bfbbcb41376291f8878 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Cocoa Menus: Allow separators in app menuGabriel de Dietrich2018-04-191-0/+1
| | | | | | | | | | | | | We extend QCocoaNSMenuItem with separator items capabilities and use it as any other custom item in the app menu. Addition and removal of items in the app menu remains very basic because that menu doesn't exist as such. Instead, it's hinted through the QAction's menu role. Change-Id: Ia13bfcc008c75e49fd21705d2528da5a85ed1c73 Task-number: QTBUG-63756 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Cocoa Menus: Use the responder chain for menu items target/actionGabriel de Dietrich2018-04-191-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* QCocoaMenuItem: Make QCocoaNSMenu the item targetGabriel de Dietrich2018-03-071-2/+5
| | | | | | | | | | | | | | | | | Since we made the NSMenu delegate a singleton we could not rely on it to have enough information to implement worksWhenModal. At the same time as the delegate change, we derived NSMenu into QCocoaNSMenu. This allows us to extend the menu functionality and, in this case, serve as target for the Cocoa menu items. We also refactor setting the item's target/action. Manually tested against menurama and bigmenucreator tests, the test-case for QTBUG-17291, and the richtext/textedit example. Change-Id: I222241f71db82611711b23d4a8c6122a741370ae Task-number: QTBUG-66676 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QCocoaNSMenuDelegate: Improve key-equivalent logicGabriel de Dietrich2017-12-191-1/+3
| | | | | | | | | | | | | | | | | By using NSEvent.characters instead of NSEvent.charactersIgnoringModifiers, we may miss sending ShortcutOverride events. For example, when the user presses Cmd-Opt-o, characters will be "ø" (on a US keyboard layout) and therefore we'll be looking for the wrong key-equivalent among the menu items. We only fall back on the modified string when the search on the unmodified string fails. As and addendum, we also skip any submenu when doing the key search. This is not necessary since each menu delegate will get called eventually. Change-Id: Id793315293a02c99e99d793ad812cff7b4a47821 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* QCocoaMenu: Derive custom NSMenu class, make delegate a singletonGabriel de Dietrich2017-12-191-0/+84
Out of the box, this saves one delegate instance per NSMenu. It also weak-couples the NSMenu instance with its owning QCocoaMenu, making it safer to inspect from the menu delegate. In the future, this will be helpful for debugging by just overriding any NSMenu method. Change-Id: I7eb801009b97f6a8ee2003306c0e152621bbce54 Reviewed-by: Jake Petroules <jake.petroules@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>