add more high-level event concepts, fixing native button number
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74169 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -53,7 +53,53 @@ CGEventType CGEventTypeForMouseButton(int button, bool isDown)
|
|||||||
return isDown ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
|
return isDown ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGEventType CGEventTypeForMouseDrag(int button)
|
||||||
|
{
|
||||||
|
switch ( button )
|
||||||
|
{
|
||||||
|
case wxMOUSE_BTN_LEFT:
|
||||||
|
return kCGEventLeftMouseDragged;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxMOUSE_BTN_RIGHT:
|
||||||
|
return kCGEventRightMouseDragged;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// All the other buttons use the constant OtherMouseDown but we still
|
||||||
|
// want to check for invalid parameters so assert first
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG("Unsupported button passed in.");
|
||||||
|
// fall back to the only known remaining case
|
||||||
|
|
||||||
|
case wxMOUSE_BTN_MIDDLE:
|
||||||
|
return kCGEventOtherMouseDragged;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CGMouseButton CGButtonForMouseButton(int button)
|
||||||
|
{
|
||||||
|
switch ( button )
|
||||||
|
{
|
||||||
|
case wxMOUSE_BTN_LEFT:
|
||||||
|
return kCGMouseButtonLeft;
|
||||||
|
|
||||||
|
case wxMOUSE_BTN_RIGHT:
|
||||||
|
return kCGMouseButtonRight;
|
||||||
|
|
||||||
|
// All the other buttons use the constant OtherMouseDown but we still
|
||||||
|
// want to check for invalid parameters so assert first
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG("Unsupported button passed in.");
|
||||||
|
// fall back to the only known remaining case
|
||||||
|
|
||||||
|
case wxMOUSE_BTN_MIDDLE:
|
||||||
|
return kCGMouseButtonCenter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CGPoint GetMousePosition()
|
CGPoint GetMousePosition()
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -72,7 +118,7 @@ bool wxUIActionSimulator::MouseDown(int button)
|
|||||||
{
|
{
|
||||||
CGEventType type = CGEventTypeForMouseButton(button, true);
|
CGEventType type = CGEventTypeForMouseButton(button, true);
|
||||||
wxCFRef<CGEventRef> event(
|
wxCFRef<CGEventRef> event(
|
||||||
CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
|
CGEventCreateMouseEvent(NULL, type, GetMousePosition(), CGButtonForMouseButton(button)));
|
||||||
|
|
||||||
if ( !event )
|
if ( !event )
|
||||||
return false;
|
return false;
|
||||||
@@ -86,35 +132,6 @@ bool wxUIActionSimulator::MouseDown(int button)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxUIActionSimulator::MouseDblClick(int button)
|
|
||||||
{
|
|
||||||
CGEventType downtype = CGEventTypeForMouseButton(button, true);
|
|
||||||
CGEventType uptype = CGEventTypeForMouseButton(button, false);
|
|
||||||
wxCFRef<CGEventRef> event(
|
|
||||||
CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), button));
|
|
||||||
|
|
||||||
if ( !event )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CGEventSetType(event,downtype);
|
|
||||||
CGEventPost(tap, event);
|
|
||||||
|
|
||||||
CGEventSetType(event, uptype);
|
|
||||||
CGEventPost(tap, event);
|
|
||||||
|
|
||||||
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
|
||||||
CGEventSetType(event, downtype);
|
|
||||||
CGEventPost(tap, event);
|
|
||||||
|
|
||||||
CGEventSetType(event, uptype);
|
|
||||||
CGEventPost(tap, event);
|
|
||||||
wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
|
|
||||||
if (loop)
|
|
||||||
loop->SetShouldWaitForEvent(true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxUIActionSimulator::MouseMove(long x, long y)
|
bool wxUIActionSimulator::MouseMove(long x, long y)
|
||||||
{
|
{
|
||||||
CGPoint pos;
|
CGPoint pos;
|
||||||
@@ -130,6 +147,7 @@ bool wxUIActionSimulator::MouseMove(long x, long y)
|
|||||||
|
|
||||||
CGEventSetType(event, type);
|
CGEventSetType(event, type);
|
||||||
CGEventPost(tap, event);
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
|
wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
|
||||||
if (loop)
|
if (loop)
|
||||||
loop->SetShouldWaitForEvent(true);
|
loop->SetShouldWaitForEvent(true);
|
||||||
@@ -141,7 +159,7 @@ bool wxUIActionSimulator::MouseUp(int button)
|
|||||||
{
|
{
|
||||||
CGEventType type = CGEventTypeForMouseButton(button, false);
|
CGEventType type = CGEventTypeForMouseButton(button, false);
|
||||||
wxCFRef<CGEventRef> event(
|
wxCFRef<CGEventRef> event(
|
||||||
CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
|
CGEventCreateMouseEvent(NULL, type, GetMousePosition(), CGButtonForMouseButton(button)));
|
||||||
|
|
||||||
if ( !event )
|
if ( !event )
|
||||||
return false;
|
return false;
|
||||||
@@ -155,6 +173,67 @@ bool wxUIActionSimulator::MouseUp(int button)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxUIActionSimulator::MouseDblClick(int button)
|
||||||
|
{
|
||||||
|
CGEventType downtype = CGEventTypeForMouseButton(button, true);
|
||||||
|
CGEventType uptype = CGEventTypeForMouseButton(button, false);
|
||||||
|
wxCFRef<CGEventRef> event(
|
||||||
|
CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
|
||||||
|
|
||||||
|
if ( !event )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CGEventSetType(event,downtype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
|
CGEventSetType(event, uptype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
|
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
||||||
|
CGEventSetType(event, downtype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
|
CGEventSetType(event, uptype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
|
||||||
|
if (loop)
|
||||||
|
loop->SetShouldWaitForEvent(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxUIActionSimulator::MouseClickAndDragTo(long x, long y, int button)
|
||||||
|
{
|
||||||
|
CGEventType downtype = CGEventTypeForMouseButton(button, true);
|
||||||
|
CGEventType uptype = CGEventTypeForMouseButton(button, false);
|
||||||
|
CGEventType dragtype = CGEventTypeForMouseDrag(button) ;
|
||||||
|
|
||||||
|
wxCFRef<CGEventRef> event(
|
||||||
|
CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
|
||||||
|
|
||||||
|
if ( !event )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CGEventSetType(event,downtype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
|
CGPoint pos;
|
||||||
|
pos.x = x;
|
||||||
|
pos.y = y;
|
||||||
|
|
||||||
|
CGEventSetType(event, dragtype);
|
||||||
|
CGEventSetLocation(event,pos);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
|
||||||
|
CGEventSetType(event, uptype);
|
||||||
|
CGEventPost(tap, event);
|
||||||
|
wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
|
||||||
|
if (loop)
|
||||||
|
loop->SetShouldWaitForEvent(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
|
wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user