diff options
author | Norwegian Rock Cat <qt-info@nokia.com> | 2009-07-16 14:59:15 (GMT) |
---|---|---|
committer | Norwegian Rock Cat <qt-info@nokia.com> | 2009-07-24 09:43:23 (GMT) |
commit | 777b93a0a48096e68124feec4c0e0cab3d60c36a (patch) | |
tree | 80ff05a695db37632d2c1cb213ce340d33cac2e8 /src/gui/kernel/qt_cocoa_helpers_mac.mm | |
parent | f04b5ea9e0f06904f15d93245ef597483ba9e790 (diff) | |
download | Qt-777b93a0a48096e68124feec4c0e0cab3d60c36a.zip Qt-777b93a0a48096e68124feec4c0e0cab3d60c36a.tar.gz Qt-777b93a0a48096e68124feec4c0e0cab3d60c36a.tar.bz2 |
Get collapsible menus working correctly.
There was an attempt to do this earlier, but it was a bit more complex
than it needed to be. We now do the update on show in Cocoa. Carbon
actually does it all for us, we just need to flip the bit. We may do the
updates to often, but it's better than not enough.
Task-Id: 195445
Reviewed-by: Denis
Diffstat (limited to 'src/gui/kernel/qt_cocoa_helpers_mac.mm')
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac.mm | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 223e36b..3d4164a 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -74,6 +74,7 @@ ****************************************************************************/ #include <private/qcore_mac_p.h> +#include <qaction.h> #include <qwidget.h> #include <qdesktopwidget.h> #include <qevent.h> @@ -1193,4 +1194,32 @@ void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayI } } +void qt_mac_menu_collapseSeparators(void */*NSMenu **/ theMenu, bool collapse) +{ + OSMenuRef menu = static_cast<OSMenuRef>(theMenu); + if (collapse) { + bool previousIsSeparator = true; // setting to true kills all the separators placed at the top. + NSMenuItem *previousItem = nil; + for (NSMenuItem *item in [menu itemArray]) { + if ([item isSeparatorItem]) { + [item setHidden:previousIsSeparator]; + } + + if (![item isHidden]) { + previousItem = item; + previousIsSeparator = ([previousItem isSeparatorItem]); + } + } + + // We now need to check the final item since we don't want any separators at the end of the list. + if (previousItem && previousIsSeparator) + [previousItem setHidden:YES]; + } else { + for (NSMenuItem *item in [menu itemArray]) { + if (QAction *action = reinterpret_cast<QAction *>([item tag])) + [item setHidden:!action->isVisible()]; + } + } +} + QT_END_NAMESPACE |