diff --git a/include/wx/msw/nonownedwnd.h b/include/wx/msw/nonownedwnd.h index 953077eeed..083f3fa1ab 100644 --- a/include/wx/msw/nonownedwnd.h +++ b/include/wx/msw/nonownedwnd.h @@ -24,6 +24,7 @@ public: virtual bool Reparent(wxWindowBase* newParent) wxOVERRIDE; virtual void InheritAttributes() wxOVERRIDE; + virtual bool IsThisEnabled() const wxOVERRIDE; protected: virtual bool DoClearShape() wxOVERRIDE; diff --git a/include/wx/window.h b/include/wx/window.h index de692b3708..ece8b65451 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -655,7 +655,7 @@ public: // state, i.e. the state in which the window would be if all its // parents were enabled (use IsEnabled() above to get the effective // window state) - bool IsThisEnabled() const { return m_isEnabled; } + virtual bool IsThisEnabled() const { return m_isEnabled; } // returns true if the window is visible, i.e. IsShown() returns true // if called on it and all its parents up to the first TLW diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index ae6cb4ae69..ff11192a33 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -221,6 +221,21 @@ void wxNonOwnedWindow::InheritAttributes() wxNonOwnedWindowBase::InheritAttributes(); } +bool wxNonOwnedWindow::IsThisEnabled() const +{ + // Under MSW we use the actual window state rather than the value of + // m_isEnabled because the latter might be out of sync for TLWs disabled + // by a native modal dialog being shown, as native functions such as + // ::MessageBox() etc just call ::EnableWindow() on them without updating + // m_isEnabled and we have no way to be notified about this. + // + // But we can only do this if the window had been already created, so test + // for this in order to return correct result if it was disabled after + // using default ctor but before calling Create(). + return m_hWnd ? !(::GetWindowLong(GetHwnd(), GWL_STYLE) & WS_DISABLED) + : m_isEnabled; +} + WXLRESULT wxNonOwnedWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXLRESULT rc = 0;