cocoa: Fix Mouse Event tracking of button status

Within qcocoahelpers, make function cocoaButton2QtButton() handle
all button numbers. Within qnsview, call the function in several
places (eliminating duplicate, inefficient code).

Task-number: QTBUG-28567

Change-Id: Ibae2ae4e8a881b825a8862afb82aa80437751111
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Rick Stockton <rickstockton@reno-computerhelp.com>
This commit is contained in:
Rick Stockton 2012-12-20 20:38:45 -08:00 committed by The Qt Project
parent 6f1f893493
commit f210a85934
2 changed files with 21 additions and 111 deletions

View File

@ -623,20 +623,17 @@ CGFloat qt_mac_get_scalefactor()
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
{ {
switch (buttonNum) { if (buttonNum == 0)
case 0:
return Qt::LeftButton; return Qt::LeftButton;
case 1: if (buttonNum == 1)
return Qt::RightButton; return Qt::RightButton;
case 2: if (buttonNum == 2)
return Qt::MidButton; return Qt::MiddleButton;
case 3: if (buttonNum >= 3 && buttonNum <= 31) { // handle XButton1 and higher via logical shift
return Qt::XButton1; return Qt::MouseButton(uint(Qt::MiddleButton) << (buttonNum - 3));
case 4:
return Qt::XButton2;
default:
return Qt::NoButton;
} }
// else error: buttonNum too high, or negative
return Qt::NoButton;
} }
bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) { bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {

View File

@ -403,14 +403,19 @@ static QTouchDevice *touchDevice = 0;
m_buttons |= Qt::LeftButton; m_buttons |= Qt::LeftButton;
break; break;
case NSLeftMouseUp: case NSLeftMouseUp:
m_buttons &= QFlag(~int(Qt::LeftButton)); m_buttons &= ~Qt::LeftButton;
break; break;
case NSRightMouseDown: case NSRightMouseDown:
m_buttons |= Qt::RightButton; m_buttons |= Qt::RightButton;
break; break;
case NSRightMouseUp: case NSRightMouseUp:
m_buttons &= QFlag(~int(Qt::RightButton)); m_buttons &= ~Qt::RightButton;
break; break;
case NSOtherMouseDown:
m_buttons |= cocoaButton2QtButton([theEvent buttonNumber]);
break;
case NSOtherMouseUp:
m_buttons &= ~cocoaButton2QtButton([theEvent buttonNumber]);
default: default:
break; break;
} }
@ -465,10 +470,10 @@ static QTouchDevice *touchDevice = 0;
- (void)mouseUp:(NSEvent *)theEvent - (void)mouseUp:(NSEvent *)theEvent
{ {
if (m_sendUpAsRightButton) { if (m_sendUpAsRightButton) {
m_buttons &= QFlag(~int(Qt::RightButton)); m_buttons &= ~Qt::RightButton;
m_sendUpAsRightButton = false; m_sendUpAsRightButton = false;
} else { } else {
m_buttons &= QFlag(~int(Qt::LeftButton)); m_buttons &= ~Qt::LeftButton;
} }
[self handleMouseEvent:theEvent]; [self handleMouseEvent:theEvent];
} }
@ -539,59 +544,13 @@ static QTouchDevice *touchDevice = 0;
- (void)rightMouseUp:(NSEvent *)theEvent - (void)rightMouseUp:(NSEvent *)theEvent
{ {
m_buttons &= QFlag(~int(Qt::RightButton)); m_buttons &= ~Qt::RightButton;
[self handleMouseEvent:theEvent]; [self handleMouseEvent:theEvent];
} }
- (void)otherMouseDown:(NSEvent *)theEvent - (void)otherMouseDown:(NSEvent *)theEvent
{ {
switch ([theEvent buttonNumber]) { m_buttons |= cocoaButton2QtButton([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]; [self handleMouseEvent:theEvent];
} }
@ -604,53 +563,7 @@ static QTouchDevice *touchDevice = 0;
- (void)otherMouseUp:(NSEvent *)theEvent - (void)otherMouseUp:(NSEvent *)theEvent
{ {
switch ([theEvent buttonNumber]) { m_buttons &= ~cocoaButton2QtButton([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]; [self handleMouseEvent:theEvent];
} }
@ -1242,7 +1155,7 @@ static QTouchDevice *touchDevice = 0;
// keep our state, and QGuiApplication state (buttons member) in-sync, // keep our state, and QGuiApplication state (buttons member) in-sync,
// or future mouse events will be processed incorrectly // or future mouse events will be processed incorrectly
m_buttons &= QFlag(~int(Qt::LeftButton)); m_buttons &= ~Qt::LeftButton;
NSPoint windowPoint = [self convertPoint: point fromView: nil]; NSPoint windowPoint = [self convertPoint: point fromView: nil];
QPoint qtWindowPoint(windowPoint.x, windowPoint.y); QPoint qtWindowPoint(windowPoint.x, windowPoint.y);