summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qmenu_mac.mm
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-07-16 14:59:15 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-07-24 09:43:23 (GMT)
commit777b93a0a48096e68124feec4c0e0cab3d60c36a (patch)
tree80ff05a695db37632d2c1cb213ce340d33cac2e8 /src/gui/widgets/qmenu_mac.mm
parentf04b5ea9e0f06904f15d93245ef597483ba9e790 (diff)
downloadQt-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/widgets/qmenu_mac.mm')
-rw-r--r--src/gui/widgets/qmenu_mac.mm81
1 files changed, 31 insertions, 50 deletions
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index 87f6f82..e6239f4 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -458,7 +458,8 @@ OSStatus qt_mac_menu_event(EventHandlerCallRef er, EventRef event, void *)
int merged = 0;
const QMenuPrivate::QMacMenuPrivate *mac_menu = qmenu->d_func()->mac_menu;
- for(int i = 0; i < mac_menu->actionItems.size(); ++i) {
+ const int ActionItemsCount = mac_menu->actionItems.size();
+ for(int i = 0; i < ActionItemsCount; ++i) {
QMacMenuAction *action = mac_menu->actionItems.at(i);
if (action->action->isSeparator()) {
bool hide = false;
@@ -972,7 +973,7 @@ void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !
/*****************************************************************************
QMenu bindings
*****************************************************************************/
-QMenuPrivate::QMacMenuPrivate::QMacMenuPrivate(QMenuPrivate *menu) : menu(0), qmenu(menu)
+QMenuPrivate::QMacMenuPrivate::QMacMenuPrivate() : menu(0)
{
}
@@ -1300,61 +1301,22 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action)
#else
int itemIndex = [menu indexOfItem:item];
Q_ASSERT(itemIndex != -1);
-
- // Separator handling: Menu items and separators can be added to a QMenu in
- // any order (for example, add all the separators first and then "fill inn"
- // the menu items). Create NSMenuItem seperatorItems for the Qt separators,
- // and make sure that there are no double separators and no seprators
- // at the top or bottom of the menu.
- bool itemIsSeparator = action->action->isSeparator();
- bool previousItemIsSeparator = false;
- if (itemIndex > 0) {
- if ([[menu itemAtIndex : itemIndex - 1] isSeparatorItem])
- previousItemIsSeparator = true;
- }
- bool nexItemIsSeparator = false;
- if (itemIndex > 0 && itemIndex < [menu numberOfItems] -1) {
- if ([[menu itemAtIndex : itemIndex + 1] isSeparatorItem])
- nexItemIsSeparator = true;
- }
- bool itemIsAtBottomOfMenu = (itemIndex == [menu numberOfItems] - 1);
- bool itemIsAtTopOfMenu = (itemIndex == 0);
-
-
- if (itemIsSeparator) {
- // Create separators items for actions that are now separators
+ if (action->action->isSeparator()) {
action->menuItem = [NSMenuItem separatorItem];
[action->menuItem retain];
-
- // Hide duplicate/top/bottom separators.
- if (qmenu->collapsibleSeparators && (previousItemIsSeparator || itemIsAtBottomOfMenu || itemIsAtTopOfMenu)) {
- [action->menuItem setHidden : true];
- }
-
[menu insertItem: action->menuItem atIndex:itemIndex];
[menu removeItem:item];
[item release];
item = action->menuItem;
return;
- } else {
- // Create standard menu items for actions that are no longer separators
- if ([item isSeparatorItem]) {
- action->menuItem = createNSMenuItem(action->action->text());
- [menu insertItem:action->menuItem atIndex:itemIndex];
- [menu removeItem:item];
- [item release];
- item = action->menuItem;
- }
-
- // Show separators that should now be visible since a non-separator
- // item (the current item) was added.
- if (previousItemIsSeparator) {
- [[menu itemAtIndex : itemIndex - 1] setHidden : false];
- } else if (itemIsAtTopOfMenu && nexItemIsSeparator) {
- [[menu itemAtIndex : itemIndex + 1] setHidden : false];
- }
+ } else if ([item isSeparatorItem]) {
+ // I'm no longer a separator...
+ action->menuItem = createNSMenuItem(action->action->text());
+ [menu insertItem:action->menuItem atIndex:itemIndex];
+ [menu removeItem:item];
+ [item release];
+ item = action->menuItem;
}
-
#endif
//find text (and accel)
@@ -1540,7 +1502,7 @@ QMenuPrivate::macMenu(OSMenuRef merge)
if (mac_menu && mac_menu->menu)
return mac_menu->menu;
if (!mac_menu)
- mac_menu = new QMacMenuPrivate(this);
+ mac_menu = new QMacMenuPrivate;
mac_menu->menu = qt_mac_create_menu(q);
if (merge) {
#ifndef QT_MAC_USE_COCOA
@@ -1552,12 +1514,31 @@ QMenuPrivate::macMenu(OSMenuRef merge)
QList<QAction*> items = q->actions();
for(int i = 0; i < items.count(); i++)
mac_menu->addAction(items[i], 0, this);
+ syncSeparatorsCollapsible(collapsibleSeparators);
return mac_menu->menu;
}
/*!
\internal
*/
+void
+QMenuPrivate::syncSeparatorsCollapsible(bool collapse)
+{
+#ifndef QT_MAC_USE_COCOA
+ if (collapse)
+ ChangeMenuAttributes(mac_menu->menu, kMenuAttrCondenseSeparators, 0);
+ else
+ ChangeMenuAttributes(mac_menu->menu, 0, kMenuAttrCondenseSeparators);
+#else
+ qt_mac_menu_collapseSeparators(mac_menu->menu, collapse);
+#endif
+}
+
+
+
+/*!
+ \internal
+*/
void QMenuPrivate::setMacMenuEnabled(bool enable)
{
if (!macMenu(0))