From fdca68a6708f970cdff275d1dafc1622e23dc4f8 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 17 May 2001 10:58:05 +0000 Subject: [PATCH 1/1] Implemented OnParentEnable to allow widgets to reset their colours after a wxWindow::Enable call git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10193 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/textctrl.h | 5 +++++ include/wx/gtk/window.h | 5 +++++ include/wx/gtk1/textctrl.h | 5 +++++ include/wx/gtk1/window.h | 5 +++++ src/gtk/textctrl.cpp | 33 ++++++++++++++++++++------------- src/gtk/window.cpp | 27 ++++++++++++++++++--------- src/gtk1/textctrl.cpp | 33 ++++++++++++++++++++------------- src/gtk1/window.cpp | 27 ++++++++++++++++++--------- 8 files changed, 96 insertions(+), 44 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index ebc4c18d4a..0a529c6a27 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -143,6 +143,11 @@ public: void SetModified() { m_modified = TRUE; } + // wxGTK-specific: called recursively by Enable, + // to give widgets an oppprtunity to correct their colours after they + // have been changed by Enable + virtual void OnParentEnable( bool enable ) ; + protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 914a9a045a..187c9e34cb 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -114,6 +114,11 @@ public: /* For compatibility across platforms (not in event table) */ void OnIdle(wxIdleEvent& WXUNUSED(event)) {}; + // wxGTK-specific: called recursively by Enable, + // to give widgets an oppprtunity to correct their colours after they + // have been changed by Enable + virtual void OnParentEnable( bool WXUNUSED(enable) ) {}; + /* used by all window classes in the widget creation process */ bool PreCreation( wxWindow *parent, const wxPoint &pos, const wxSize &size ); void PostCreation(); diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index ebc4c18d4a..0a529c6a27 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -143,6 +143,11 @@ public: void SetModified() { m_modified = TRUE; } + // wxGTK-specific: called recursively by Enable, + // to give widgets an oppprtunity to correct their colours after they + // have been changed by Enable + virtual void OnParentEnable( bool enable ) ; + protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 914a9a045a..187c9e34cb 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -114,6 +114,11 @@ public: /* For compatibility across platforms (not in event table) */ void OnIdle(wxIdleEvent& WXUNUSED(event)) {}; + // wxGTK-specific: called recursively by Enable, + // to give widgets an oppprtunity to correct their colours after they + // have been changed by Enable + virtual void OnParentEnable( bool WXUNUSED(enable) ) {}; + /* used by all window classes in the widget creation process */ bool PreCreation( wxWindow *parent, const wxPoint &pos, const wxSize &size ); void PostCreation(); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 91caedb0d7..fb8a8e6fce 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -757,19 +757,6 @@ bool wxTextCtrl::Enable( bool enable ) { gtk_text_set_editable( GTK_TEXT(m_text), enable ); - // If we have a custom background colour, we use this colour in both - // disabled and enabled mode, or we end up with a different colour under the - // text. - wxColour oldColour = GetBackgroundColour(); - if (oldColour.Ok()) - { - // Need to set twice or it'll optimize the useful stuff out - if (oldColour == * wxWHITE) - SetBackgroundColour(*wxBLACK); - else - SetBackgroundColour(*wxWHITE); - SetBackgroundColour(oldColour); - } } else { @@ -779,6 +766,26 @@ bool wxTextCtrl::Enable( bool enable ) return TRUE; } +// wxGTK-specific: called recursively by Enable, +// to give widgets an oppprtunity to correct their colours after they +// have been changed by Enable +void wxTextCtrl::OnParentEnable( bool enable ) +{ + // If we have a custom background colour, we use this colour in both + // disabled and enabled mode, or we end up with a different colour under the + // text. + wxColour oldColour = GetBackgroundColour(); + if (oldColour.Ok()) + { + // Need to set twice or it'll optimize the useful stuff out + if (oldColour == * wxWHITE) + SetBackgroundColour(*wxBLACK); + else + SetBackgroundColour(*wxWHITE); + SetBackgroundColour(oldColour); + } +} + void wxTextCtrl::DiscardEdits() { m_modified = FALSE; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 8adc34fead..0feff90ecb 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2934,6 +2934,23 @@ bool wxWindow::Show( bool show ) return TRUE; } +static void wxWindowNotifyEnable(wxWindow* win, bool enable) +{ + win->OnParentEnable(enable); + + // Recurse, so that children have the opportunity to Do The Right Thing + // and reset colours that have been messed up by a parent's (really ancestor's) + // Enable call + for ( wxWindowList::Node *node = win->GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *child = node->GetData(); + if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame))) + wxWindowNotifyEnable(child, enable); + } +} + bool wxWindow::Enable( bool enable ) { wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); @@ -2948,15 +2965,7 @@ bool wxWindow::Enable( bool enable ) if ( m_wxwindow ) gtk_widget_set_sensitive( m_wxwindow, enable ); - // Recurse, so that children have the opportunity to Do The Right Thing. - for ( wxWindowList::Node *node = GetChildren().GetFirst(); - node; - node = node->GetNext() ) - { - wxWindow *child = node->GetData(); - if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame))) - child->Enable(enable); - } + wxWindowNotifyEnable(this, enable); return TRUE; } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 91caedb0d7..fb8a8e6fce 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -757,19 +757,6 @@ bool wxTextCtrl::Enable( bool enable ) { gtk_text_set_editable( GTK_TEXT(m_text), enable ); - // If we have a custom background colour, we use this colour in both - // disabled and enabled mode, or we end up with a different colour under the - // text. - wxColour oldColour = GetBackgroundColour(); - if (oldColour.Ok()) - { - // Need to set twice or it'll optimize the useful stuff out - if (oldColour == * wxWHITE) - SetBackgroundColour(*wxBLACK); - else - SetBackgroundColour(*wxWHITE); - SetBackgroundColour(oldColour); - } } else { @@ -779,6 +766,26 @@ bool wxTextCtrl::Enable( bool enable ) return TRUE; } +// wxGTK-specific: called recursively by Enable, +// to give widgets an oppprtunity to correct their colours after they +// have been changed by Enable +void wxTextCtrl::OnParentEnable( bool enable ) +{ + // If we have a custom background colour, we use this colour in both + // disabled and enabled mode, or we end up with a different colour under the + // text. + wxColour oldColour = GetBackgroundColour(); + if (oldColour.Ok()) + { + // Need to set twice or it'll optimize the useful stuff out + if (oldColour == * wxWHITE) + SetBackgroundColour(*wxBLACK); + else + SetBackgroundColour(*wxWHITE); + SetBackgroundColour(oldColour); + } +} + void wxTextCtrl::DiscardEdits() { m_modified = FALSE; diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 8adc34fead..0feff90ecb 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2934,6 +2934,23 @@ bool wxWindow::Show( bool show ) return TRUE; } +static void wxWindowNotifyEnable(wxWindow* win, bool enable) +{ + win->OnParentEnable(enable); + + // Recurse, so that children have the opportunity to Do The Right Thing + // and reset colours that have been messed up by a parent's (really ancestor's) + // Enable call + for ( wxWindowList::Node *node = win->GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *child = node->GetData(); + if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame))) + wxWindowNotifyEnable(child, enable); + } +} + bool wxWindow::Enable( bool enable ) { wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); @@ -2948,15 +2965,7 @@ bool wxWindow::Enable( bool enable ) if ( m_wxwindow ) gtk_widget_set_sensitive( m_wxwindow, enable ); - // Recurse, so that children have the opportunity to Do The Right Thing. - for ( wxWindowList::Node *node = GetChildren().GetFirst(); - node; - node = node->GetNext() ) - { - wxWindow *child = node->GetData(); - if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame))) - child->Enable(enable); - } + wxWindowNotifyEnable(this, enable); return TRUE; } -- 2.47.2