28#include <wx/stc/stc.h>
29#include <wx/settings.h>
52 const wxEventType& aUpEvent,
const wxEventType& aDblClickEvent ) :
101 wxMouseState mouseState = wxGetMouseState();
106 return mouseState.LeftIsDown();
109 return mouseState.MiddleIsDown();
112 return mouseState.RightIsDown();
115 return mouseState.Aux1IsDown();
118 return mouseState.Aux2IsDown();
121 wxFAIL_MSG( wxT(
"unknown button" ) );
140 wxEVT_LEFT_UP, wxEVT_LEFT_DCLICK ) );
142 wxEVT_RIGHT_UP, wxEVT_RIGHT_DCLICK ) );
144 wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DCLICK ) );
146 wxEVT_AUX1_UP, wxEVT_AUX1_DCLICK ) );
148 wxEVT_AUX2_UP, wxEVT_AUX2_DCLICK ) );
163 int wxmods = aState->GetModifiers();
169 if( wxmods & wxMOD_ALTGR )
174 if( wxmods & wxMOD_CONTROL )
177 if( wxmods & wxMOD_ALT )
181 if( wxmods & wxMOD_SHIFT )
185 if( wxmods & wxMOD_META )
190 if( wxmods & wxMOD_WIN )
216 return abs( aOffset.
x ) > aDragMinX || abs( aOffset.
y ) > aDragMinY;
223 wxEventType type = aEvent.GetEventType();
224 std::optional<TOOL_EVENT> evt;
225 bool isClick =
false;
229 bool up =
false,
down =
false;
263 int args = st->
button | mods;
345 const std::vector<enum wxKeyCode> special_keys =
347 WXK_PAGEUP, WXK_PAGEDOWN,
348 WXK_NUMPAD_PAGEUP, WXK_NUMPAD_PAGEDOWN
361 static std::vector<enum wxKeyCode> special_keys =
363 WXK_CONTROL, WXK_RAW_CONTROL, WXK_SHIFT, WXK_ALT,
364#ifdef WXK_WINDOWS_LEFT
365 WXK_WINDOWS_LEFT, WXK_WINDOWS_RIGHT,
384 return type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_LEFT_DCLICK
385 || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || type == wxEVT_MIDDLE_DCLICK
386 || type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || type == wxEVT_RIGHT_DCLICK
387 || type == wxEVT_AUX1_DOWN || type == wxEVT_AUX1_UP || type == wxEVT_AUX1_DCLICK
388 || type == wxEVT_AUX2_DOWN || type == wxEVT_AUX2_UP || type == wxEVT_AUX2_DCLICK;
410 case WXK_NUMPAD_UP:
return WXK_UP;
411 case WXK_NUMPAD_DOWN:
return WXK_DOWN;
412 case WXK_NUMPAD_LEFT:
return WXK_LEFT;
413 case WXK_NUMPAD_RIGHT:
return WXK_RIGHT;
414 case WXK_NUMPAD_PAGEUP:
return WXK_PAGEUP;
415 case WXK_NUMPAD_PAGEDOWN:
return WXK_PAGEDOWN;
425 std::optional<TOOL_EVENT> evt;
426 int key = aKeyEvent->GetKeyCode();
427 int unicode_key = aKeyEvent->GetUnicodeKey();
442 if( aKeyEvent->GetEventType() == wxEVT_CHAR_HOOK )
459 if( unicode_key >=
'A' && unicode_key <=
'Z' && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
463 if( key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
475 switch( aKeyEvent->GetRawKeyCode() )
477 case 0x12: key =
'1';
break;
478 case 0x13: key =
'2';
break;
479 case 0x14: key =
'3';
break;
480 case 0x15: key =
'4';
break;
481 case 0x16: key =
'6';
break;
482 case 0x17: key =
'5';
break;
483 case 0x18: key =
'=';
break;
484 case 0x19: key =
'9';
break;
485 case 0x1A: key =
'7';
break;
486 case 0x1B: key =
'-';
break;
487 case 0x1C: key =
'8';
break;
488 case 0x1D: key =
'0';
break;
494 if( key == WXK_ESCAPE )
511 if( st->pressed && !st->GetState() )
519 st->dragging =
false;
526 int& aLastKey, wxLongLong& aLastTimeMs )
528 bool sameBurst = aKeyCode == aLastKey && ( aNowMs - aLastTimeMs ) <
AutoRepeatWindowMs;
531 aLastTimeMs = aNowMs;
533 return sameBurst && !aKeyIsDown;
546 int key = aKeyEvent.GetKeyCode();
547 bool keyIsDown = key >
MAX_MOUSE_BUTTON && wxGetKeyState(
static_cast<wxKeyCode
>( key ) );
556 bool buttonEvents =
false;
558 std::optional<TOOL_EVENT> evt;
559 bool keyIsEscape =
false;
560 bool keyIsSpecial =
false;
561 bool droppedStaleAutoRepeat =
false;
562 wxWindow* focus = wxWindow::FindFocus();
569 wxEventType type = aEvent.GetEventType();
572 && !wxGetKeyState(
static_cast<wxKeyCode
>(
m_lastKeyCode ) ) )
579 if( focus ==
nullptr )
581 wxWindow* holderWindow =
dynamic_cast<wxWindow*
>(
m_toolMgr->GetToolHolder() );
583#if defined( _WIN32 ) || defined( __WXGTK__ )
591 holderWindow->SetFocus();
598 &&
m_toolMgr->GetToolHolder()->GetToolCanvas()
599 && !
m_toolMgr->GetToolHolder()->GetToolCanvas()->HasFocus() )
601 m_toolMgr->GetToolHolder()->GetToolCanvas()->SetFocus();
607 if( type == wxEVT_MOTION
608 || type == wxEVT_MOUSEWHEEL
609 || type == wxEVT_MAGNIFY
615 wxMouseEvent* me =
static_cast<wxMouseEvent*
>( &aEvent );
622 const wxPoint eventPos = me->GetPosition();
628 pos =
m_toolMgr->GetViewControls()->GetMousePosition();
639 for(
unsigned int i = 0; i <
m_buttons.size(); i++ )
644 if( !buttonEvents && motion )
647 evt->SetMousePosition( pos );
656 if( !evt && me->GetWheelRotation() != 0 )
659 const bool shouldHandle = std::popcount( modBits ) > 1;
664 evt->SetParameter<
int>( me->GetWheelRotation() );
668 else if( type == wxEVT_CHAR_HOOK || type == wxEVT_CHAR )
670 wxKeyEvent* ke =
static_cast<wxKeyEvent*
>( &aEvent );
678 if( type == wxEVT_CHAR_HOOK && ke->GetModifiers() == wxMOD_SHIFT )
684 keyIsEscape = ( ke->GetKeyCode() == WXK_ESCAPE );
703 else if( ke->GetModifiers() == wxMOD_CONTROL && ke->GetKeyCode() ==
'C' )
719 droppedStaleAutoRepeat =
true;
722 if( evt && !evt->IsCancel() &&
m_toolMgr->GetViewControls() )
725 evt->SetHasPosition(
true );
728 else if( type == wxEVT_MENU_OPEN || type == wxEVT_MENU_CLOSE || type == wxEVT_MENU_HIGHLIGHT )
730 wxMenuEvent* tmp =
dynamic_cast<wxMenuEvent*
>( &aEvent );
740 wxMenuEvent& menuEvent = *tmp;
742#if wxCHECK_VERSION( 3, 2, 0 )
745 currentMenu->OnMenuEvent( menuEvent );
763 if( type == wxEVT_MENU_OPEN )
765 currentMenu =
dynamic_cast<ACTION_MENU*
>( menuEvent.GetMenu() );
770 else if( type == wxEVT_MENU_HIGHLIGHT )
775 else if( type == wxEVT_MENU_CLOSE )
780 currentMenu =
nullptr;
787 bool handled =
false;
791 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_DISPATCHER::DispatchWxEvent %s" ), evt->Format() );
793 handled =
m_toolMgr->ProcessEvent( *evt );
795 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_DISPATCHER::DispatchWxEvent - Handled: %s %s" ),
796 ( handled ? wxS(
"true" ) : wxS(
"false" ) ), evt->Format() );
821 if( ( !evt && !droppedStaleAutoRepeat ) || type == wxEVT_LEFT_DOWN )
829 if( ( type == wxEVT_CHAR || type == wxEVT_CHAR_HOOK )
833 && !droppedStaleAutoRepeat )
838 wxLogTrace(
kicadTraceToolStack,
"TOOL_DISPATCHER::DispatchWxEvent - Wx event skipped: %s",
839 ( aEvent.GetSkipped() ?
"true" :
"false" ) );
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
a few functions useful in geometry calculations.
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamp a vector to values that can be negated, respecting numeric limits of coordinates data type with...
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
void ignore_unused(const T &)
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsInputControlEditable(wxWindow *aControl)
Check if a input control has focus.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
WX_VIEW_CONTROLS class definition.