Try and cleanup the input focus/key event a little
This commit is contained in:
parent
b0c07a28b3
commit
1fb42c5e43
|
@ -520,17 +520,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
|
||||||
|
|
||||||
keyIsEscape = ( ke->GetKeyCode() == WXK_ESCAPE );
|
keyIsEscape = ( ke->GetKeyCode() == WXK_ESCAPE );
|
||||||
|
|
||||||
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
|
if( KIUI::IsInputControlFocused( focus ) )
|
||||||
wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( focus );
|
|
||||||
|
|
||||||
if( KIUI::IsInputControlFocused() )
|
|
||||||
{
|
{
|
||||||
bool enabled = true;
|
bool enabled = KIUI::IsInputControlEditable( focus );
|
||||||
|
|
||||||
if( textEntry )
|
|
||||||
enabled = textEntry->IsEditable();
|
|
||||||
else if( styledText )
|
|
||||||
enabled = styledText->IsEditable();
|
|
||||||
|
|
||||||
// Never process key events for tools when a text entry has focus
|
// Never process key events for tools when a text entry has focus
|
||||||
if( enabled )
|
if( enabled )
|
||||||
|
|
|
@ -168,26 +168,29 @@ void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIUI::IsInputControlFocused()
|
bool KIUI::IsInputControlFocused( wxWindow* aFocus )
|
||||||
{
|
{
|
||||||
wxWindow* focus = wxWindow::FindFocus();
|
if( aFocus == nullptr )
|
||||||
|
{
|
||||||
|
aFocus = wxWindow::FindFocus();
|
||||||
|
}
|
||||||
|
|
||||||
if( !focus )
|
if( !aFocus )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
|
||||||
wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( focus );
|
wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
|
||||||
wxListBox* listBox = dynamic_cast<wxListBox*>( focus );
|
wxListBox* listBox = dynamic_cast<wxListBox*>( aFocus );
|
||||||
wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( focus );
|
wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
|
||||||
|
|
||||||
// Data view control is annoying, the focus is on a "wxDataViewCtrlMainWindow"
|
// Data view control is annoying, the focus is on a "wxDataViewCtrlMainWindow"
|
||||||
// class that is not formerly exported via the header.
|
// class that is not formerly exported via the header.
|
||||||
// However, we can test the parent is wxDataViewCtrl instead
|
// However, we can test the parent is wxDataViewCtrl instead
|
||||||
wxDataViewCtrl* dataViewCtrl = nullptr;
|
wxDataViewCtrl* dataViewCtrl = nullptr;
|
||||||
|
|
||||||
wxWindow* parent = focus->GetParent();
|
wxWindow* parent = aFocus->GetParent();
|
||||||
|
|
||||||
if( parent )
|
if( parent )
|
||||||
{
|
{
|
||||||
|
@ -198,6 +201,24 @@ bool KIUI::IsInputControlFocused()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool KIUI::IsInputControlEditable( wxWindow* aFocus )
|
||||||
|
{
|
||||||
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
|
||||||
|
wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
|
||||||
|
wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
|
||||||
|
wxListBox* listBox = dynamic_cast<wxListBox*>( aFocus );
|
||||||
|
|
||||||
|
if( textEntry )
|
||||||
|
return textEntry->IsEditable();
|
||||||
|
else if( styledText )
|
||||||
|
return styledText->IsEditable();
|
||||||
|
else if( searchCtrl )
|
||||||
|
return searchCtrl->IsEditable();
|
||||||
|
|
||||||
|
return true; // Must return true if we can't determine the state, intentionally true for non inputs as well
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIUI::IsModalDialogFocused()
|
bool KIUI::IsModalDialogFocused()
|
||||||
{
|
{
|
||||||
return Pgm().m_ModalDialogCount > 0;
|
return Pgm().m_ModalDialogCount > 0;
|
||||||
|
|
|
@ -76,8 +76,19 @@ void SelectReferenceNumber( wxTextEntry* aTextEntry );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a input control has focus
|
* Checks if a input control has focus
|
||||||
|
*
|
||||||
|
* @param aFocus Control that has focus, if null, wxWidgets will be queried
|
||||||
*/
|
*/
|
||||||
bool IsInputControlFocused();
|
bool IsInputControlFocused( wxWindow* aFocus = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a input control has focus
|
||||||
|
*
|
||||||
|
* @param aFocus Control that test if editable
|
||||||
|
*
|
||||||
|
* @return True if control is input and editable OR control is not a input. False if control is input and not editable.
|
||||||
|
*/
|
||||||
|
bool IsInputControlEditable( wxWindow* aControl );
|
||||||
|
|
||||||
bool IsModalDialogFocused();
|
bool IsModalDialogFocused();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue