diff options
author | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-03-25 18:16:13 +0100 |
---|---|---|
committer | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-03-25 18:16:13 +0100 |
commit | aae2c038fad7eaeda79b1d77840cbbecb99f268b (patch) | |
tree | a08e232df183263b3a82de60754cf16905b07b11 /vcl/aqua | |
parent | f099cd4586bf41f30dea8190dbd2bd7b4234cf60 (diff) |
vcl111: #i92094# use current event for GetPointerState
Diffstat (limited to 'vcl/aqua')
-rw-r--r-- | vcl/aqua/source/window/salframe.cxx | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/vcl/aqua/source/window/salframe.cxx b/vcl/aqua/source/window/salframe.cxx index 71c84ee0c2f1..413b5bcd5490 100644 --- a/vcl/aqua/source/window/salframe.cxx +++ b/vcl/aqua/source/window/salframe.cxx @@ -1352,40 +1352,81 @@ void AquaSalFrame::GetWorkArea( Rectangle& rRect ) SalPointerState AquaSalFrame::GetPointerState() { SalPointerState state; + state.mnState = 0; // get position NSPoint aPt = [mpWindow mouseLocationOutsideOfEventStream]; CocoaToVCL( aPt, false ); state.maPos = Point(static_cast<long>(aPt.x), static_cast<long>(aPt.y)); - // FIXME: replace Carbon by Cocoa - // Cocoa does not have an equivalent for GetCurrentEventButtonState - // and GetCurrentEventKeyModifiers. - // we could try to get away with tracking all events for modifierKeys - // and all mouse events for button state in VCL_NSApllication::sendEvent, - // but it is unclear whether this will get us the same result. - // leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now + NSEvent* pCur = [NSApp currentEvent]; + bool bMouseEvent = false; + if( pCur ) + { + bMouseEvent = true; + switch( [pCur type] ) + { + case NSLeftMouseDown: state.mnState |= MOUSE_LEFT; break; + case NSLeftMouseUp: break; + case NSRightMouseDown: state.mnState |= MOUSE_RIGHT; break; + case NSRightMouseUp: break; + case NSOtherMouseDown: state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break; + case NSOtherMouseUp: break; + case NSMouseMoved: break; + case NSLeftMouseDragged: state.mnState |= MOUSE_LEFT; break; + case NSRightMouseDragged: state.mnState |= MOUSE_RIGHT; break; + case NSOtherMouseDragged: state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break; + break; + default: + bMouseEvent = false; + break; + } + } + if( bMouseEvent ) + { + unsigned int nMask = (unsigned int)[pCur modifierFlags]; + if( (nMask & NSShiftKeyMask) != 0 ) + state.mnState |= KEY_SHIFT; + if( (nMask & NSControlKeyMask) != 0 ) + state.mnState |= KEY_MOD3; + if( (nMask & NSAlternateKeyMask) != 0 ) + state.mnState |= KEY_MOD2; + if( (nMask & NSCommandKeyMask) != 0 ) + state.mnState |= KEY_MOD1; + + } + else + { + // FIXME: replace Carbon by Cocoa + // Cocoa does not have an equivalent for GetCurrentEventButtonState + // and GetCurrentEventKeyModifiers. + // we could try to get away with tracking all events for modifierKeys + // and all mouse events for button state in VCL_NSApllication::sendEvent, + // but it is unclear whether this will get us the same result. + // leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now + + // fill in button state + UInt32 nState = GetCurrentEventButtonState(); + state.mnState = 0; + if( nState & 1 ) + state.mnState |= MOUSE_LEFT; // primary button + if( nState & 2 ) + state.mnState |= MOUSE_RIGHT; // secondary button + if( nState & 4 ) + state.mnState |= MOUSE_MIDDLE; // tertiary button + + // fill in modifier state + nState = GetCurrentEventKeyModifiers(); + if( nState & shiftKey ) + state.mnState |= KEY_SHIFT; + if( nState & controlKey ) + state.mnState |= KEY_MOD3; + if( nState & optionKey ) + state.mnState |= KEY_MOD2; + if( nState & cmdKey ) + state.mnState |= KEY_MOD1; + } - // fill in button state - UInt32 nState = GetCurrentEventButtonState(); - state.mnState = 0; - if( nState & 1 ) - state.mnState |= MOUSE_LEFT; // primary button - if( nState & 2 ) - state.mnState |= MOUSE_RIGHT; // secondary button - if( nState & 4 ) - state.mnState |= MOUSE_MIDDLE; // tertiary button - - // fill in modifier state - nState = GetCurrentEventKeyModifiers(); - if( nState & shiftKey ) - state.mnState |= KEY_SHIFT; - if( nState & controlKey ) - state.mnState |= KEY_MOD3; - if( nState & optionKey ) - state.mnState |= KEY_MOD2; - if( nState & cmdKey ) - state.mnState |= KEY_MOD1; return state; } |