it is not possible to show/hide the window from the UpdateUI event handler; refactored the code by moving control-specific parts into the derived classes (patch 1338350)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37536 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-02-12 16:32:50 +00:00
parent 27237c3708
commit a3a4105df6
10 changed files with 84 additions and 40 deletions

View File

@@ -124,6 +124,32 @@ bool wxControlBase::SetFont(const wxFont& font)
return wxWindow::SetFont(font);
}
// wxControl-specific processing after processing the update event
void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
// call inherited
wxWindowBase::DoUpdateWindowUI(event);
// update label
if ( event.GetSetText() )
{
if ( event.GetText() != GetLabel() )
SetLabel(event.GetText());
}
// Unfortunately we don't yet have common base class for
// wxRadioButton, so we handle updates of radiobuttons here.
// TODO: If once wxRadioButtonBase will exist, move this code there.
#if wxUSE_RADIOBTN
if ( event.GetSetChecked() )
{
wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
if ( radiobtn )
radiobtn->SetValue(event.GetChecked());
}
#endif // wxUSE_RADIOBTN
}
// ----------------------------------------------------------------------------
// wxStaticBitmap
// ----------------------------------------------------------------------------

View File

@@ -471,9 +471,12 @@ wxString wxTextCtrlBase::GetRange(long from, long to) const
// do the window-specific processing after processing the update event
void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
if ( event.GetSetEnabled() )
Enable(event.GetEnabled());
// call inherited, but skip the wxControl's version, and call directly the
// wxWindow's one instead, because the only reason why we are overriding this
// function is that we want to use SetValue() instead of wxControl::SetLabel()
wxWindowBase::DoUpdateWindowUI(event);
// update text
if ( event.GetSetText() )
{
if ( event.GetText() != GetValue() )

View File

@@ -288,9 +288,12 @@ bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
// do the window-specific processing after processing the update event
void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
if ( event.GetSetEnabled() )
Enable(event.GetEnabled());
// call inherited, but skip the wxControl's version, and call directly the
// wxWindow's one instead, because the only reason why we are overriding this
// function is that we want to use SetTitle() instead of wxControl::SetLabel()
wxWindowBase::DoUpdateWindowUI(event);
// update title
if ( event.GetSetText() )
{
if ( event.GetText() != GetTitle() )

View File

@@ -1992,44 +1992,13 @@ void wxWindowBase::UpdateWindowUI(long flags)
}
// do the window-specific processing after processing the update event
// TODO: take specific knowledge out of this function and
// put in each control's base class. Unfortunately we don't
// yet have base implementation files for wxCheckBox and wxRadioButton.
void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
if ( event.GetSetEnabled() )
Enable(event.GetEnabled());
#if wxUSE_CONTROLS
if ( event.GetSetText() )
{
wxControl *control = wxDynamicCastThis(wxControl);
if ( control )
{
if ( event.GetText() != control->GetLabel() )
control->SetLabel(event.GetText());
}
}
#endif // wxUSE_CONTROLS
if ( event.GetSetChecked() )
{
#if wxUSE_CHECKBOX
wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
if ( checkbox )
{
checkbox->SetValue(event.GetChecked());
}
#endif // wxUSE_CHECKBOX
#if wxUSE_RADIOBTN
wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
if ( radiobtn )
{
radiobtn->SetValue(event.GetChecked());
}
#endif // wxUSE_RADIOBTN
}
if ( event.GetSetShown() )
Show(event.GetShown());
}
#if 0

View File

@@ -1581,17 +1581,20 @@ wxString wxRichTextCtrl::GetStringSelection() const
}
// do the window-specific processing after processing the update event
#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
void wxRichTextCtrl::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
if ( event.GetSetEnabled() )
Enable(event.GetEnabled());
// call inherited
wxWindowBase::DoUpdateWindowUI(event);
// update text
if ( event.GetSetText() )
{
if ( event.GetText() != GetValue() )
SetValue(event.GetText());
}
}
#endif // !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
// ----------------------------------------------------------------------------
// hit testing