diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index 5b51317a67..6918bda9f1 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -170,15 +170,31 @@ void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry ) bool KIUI::IsInputControlFocused() { - wxWindow* focus = wxWindow::FindFocus(); + wxWindow* focus = wxWindow::FindFocus(); - wxTextEntry* textEntry = dynamic_cast( focus ); - wxStyledTextCtrl* styledText = dynamic_cast( focus ); - wxListBox* listBox = dynamic_cast( focus ); - wxDataViewCtrl* dataViewCtrl = dynamic_cast( focus ); - wxSearchCtrl* searchCtrl = dynamic_cast( focus ); + if( !focus ) + { + return false; + } - return ( textEntry || styledText || listBox || dataViewCtrl || searchCtrl ); + wxTextEntry* textEntry = dynamic_cast( focus ); + wxStyledTextCtrl* styledText = dynamic_cast( focus ); + wxListBox* listBox = dynamic_cast( focus ); + wxSearchCtrl* searchCtrl = dynamic_cast( focus ); + + // Data view control is annoying, the focus is on a "wxDataViewCtrlMainWindow" + // class that is not formerly exported via the header. + // However, we can test the parent is wxDataViewCtrl instead + wxDataViewCtrl* dataViewCtrl = nullptr; + + wxWindow* parent = focus->GetParent(); + + if( parent ) + { + dataViewCtrl = dynamic_cast( parent ); + } + + return ( textEntry || styledText || listBox || dataViewCtrl || searchCtrl || dataViewCtrl ); }