Cocoa platform plugin: Add support for up to 16 mouse buttons
authorRick Stockton <rickstockton@reno-computerhelp.com>
Thu, 8 Mar 2012 22:33:15 +0000 (14:33 -0800)
committerQt by Nokia <qt-info@nokia.com>
Tue, 13 Mar 2012 07:18:42 +0000 (08:18 +0100)
OS-X provides a buttonNumber within Event data for otherMouseDown:
and otherMouseUp: Events. Instead of mapping all occurences of these
event types to Qt::MiddleButton, this Update uses that data
to support a total of 16 mouse buttons.

Task-number: QTBUG-24702

Change-Id: I3cffb32498f98ea182509d7c42f3fc6634155ebb
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
src/plugins/platforms/cocoa/qnsview.mm

index 6206d53..4ab5e32 100644 (file)
@@ -336,7 +336,53 @@ static QTouchDevice *touchDevice = 0;
 
 - (void)otherMouseDown:(NSEvent *)theEvent
 {
-    m_buttons |= Qt::RightButton;
+    switch ([theEvent buttonNumber]) {
+        case 3:
+            m_buttons |= Qt::MiddleButton;
+            break;
+        case 4:
+            m_buttons |= Qt::ExtraButton1;  // AKA Qt::BackButton
+            break;
+        case 5:
+            m_buttons |= Qt::ExtraButton2;  // AKA Qt::ForwardButton
+            break;
+        case 6:
+            m_buttons |= Qt::ExtraButton3;
+            break;
+        case 7:
+            m_buttons |= Qt::ExtraButton4;
+            break;
+        case 8:
+            m_buttons |= Qt::ExtraButton5;
+            break;
+        case 9:
+            m_buttons |= Qt::ExtraButton6;
+            break;
+        case 10:
+            m_buttons |= Qt::ExtraButton7;
+            break;
+        case 11:
+            m_buttons |= Qt::ExtraButton8;
+            break;
+        case 12:
+            m_buttons |= Qt::ExtraButton9;
+            break;
+        case 13:
+            m_buttons |= Qt::ExtraButton10;
+            break;
+        case 14:
+            m_buttons |= Qt::ExtraButton11;
+            break;
+        case 15:
+            m_buttons |= Qt::ExtraButton12;
+            break;
+        case 16:
+            m_buttons |= Qt::ExtraButton13;
+            break;
+        default:
+            m_buttons |= Qt::MiddleButton;
+            break;
+    }
     [self handleMouseEvent:theEvent];
 }
 
@@ -349,7 +395,53 @@ static QTouchDevice *touchDevice = 0;
 
 - (void)otherMouseUp:(NSEvent *)theEvent
 {
-    m_buttons &= QFlag(~int(Qt::MiddleButton));
+    switch ([theEvent buttonNumber]) {
+        case 3:
+            m_buttons &= QFlag(~int(Qt::MiddleButton));
+            break;
+        case 4:
+            m_buttons &= QFlag(~int(Qt::ExtraButton1));  // AKA Qt::BackButton
+            break;
+        case 5:
+            m_buttons &= QFlag(~int(Qt::ExtraButton2));  // AKA Qt::ForwardButton
+            break;
+        case 6:
+            m_buttons &= QFlag(~int(Qt::ExtraButton3));
+            break;
+        case 7:
+            m_buttons &= QFlag(~int(Qt::ExtraButton4));
+            break;
+        case 8:
+            m_buttons &= QFlag(~int(Qt::ExtraButton5));
+            break;
+        case 9:
+            m_buttons &= QFlag(~int(Qt::ExtraButton6));
+            break;
+        case 10:
+            m_buttons &= QFlag(~int(Qt::ExtraButton7));
+            break;
+        case 11:
+            m_buttons &= QFlag(~int(Qt::ExtraButton8));
+            break;
+        case 12:
+            m_buttons &= QFlag(~int(Qt::ExtraButton9));
+            break;
+        case 13:
+            m_buttons &= QFlag(~int(Qt::ExtraButton10));
+            break;
+        case 14:
+            m_buttons &= QFlag(~int(Qt::ExtraButton11));
+            break;
+        case 15:
+            m_buttons &= QFlag(~int(Qt::ExtraButton12));
+            break;
+        case 16:
+            m_buttons &= QFlag(~int(Qt::ExtraButton13));
+            break;
+        default:
+            m_buttons &= QFlag(~int(Qt::MiddleButton));
+            break;
+    }
     [self handleMouseEvent:theEvent];
 }