]> git.saurik.com Git - wxWidgets.git/commitdiff
it is not possible to show/hide the window from the UpdateUI event handler; refactore...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Feb 2006 16:32:50 +0000 (16:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Feb 2006 16:32:50 +0000 (16:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37536 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/upduievt.tex
include/wx/checkbox.h
include/wx/control.h
include/wx/event.h
include/wx/richtext/richtextctrl.h
src/common/ctrlcmn.cpp
src/common/textcmn.cpp
src/common/toplvcmn.cpp
src/common/wincmn.cpp
src/richtext/richtextctrl.cpp

index d4673f24f54e840b3382234ae01d0ae69e777836..aea947ee533244f943cb7e2b5152e3f597150dcb 100644 (file)
@@ -27,7 +27,7 @@ functions that take a wxUpdateUIEvent argument.
 \wxheading{Remarks}
 
 Without update UI events, an application has to work hard to check/uncheck, enable/disable,
-and set the text for elements such as menu items and toolbar buttons.
+show/hide, and set the text for elements such as menu items and toolbar buttons.
 The code for doing this has to be mixed up with the code that is invoked when
 an action is invoked for a menu item or button.
 
@@ -116,6 +116,12 @@ Check or uncheck the UI element.
 
 Enable or disable the UI element.
 
+\membersection{wxUpdateUIEvent::Show}\label{wxupdateuieventshow}
+
+\func{void}{Show}{\param{bool}{ show}}
+
+Show or hide the UI element.
+
 \membersection{wxUpdateUIEvent::GetChecked}\label{wxupdateuieventgetchecked}
 
 \constfunc{bool}{GetChecked}{\void}
@@ -128,6 +134,12 @@ Returns true if the UI element should be checked.
 
 Returns true if the UI element should be enabled.
 
+\membersection{wxUpdateUIEvent::GetShown}\label{wxupdateuieventgetshown}
+
+\constfunc{bool}{GetShown}{\void}
+
+Returns true if the UI element should be shown.
+
 \membersection{wxUpdateUIEvent::GetSetChecked}\label{wxupdateuieventgetsetchecked}
 
 \constfunc{bool}{GetSetChecked}{\void}
@@ -140,6 +152,12 @@ Returns true if the application has called \helpref{wxUpdateUIEvent::Check}{wxup
 
 Returns true if the application has called \helpref{wxUpdateUIEvent::Enable}{wxupdateuieventenable}. For wxWidgets internal use only.
 
+\membersection{wxUpdateUIEvent::GetSetShown}\label{wxupdateuieventgetsetshown}
+
+\constfunc{bool}{GetSetShown}{\void}
+
+Returns true if the application has called \helpref{wxUpdateUIEvent::Show}{wxupdateuieventshow}. For wxWidgets internal use only.
+
 \membersection{wxUpdateUIEvent::GetSetText}\label{wxupdateuieventgetsettext}
 
 \constfunc{bool}{GetSetText}{\void}
index 8eea49bcaba0015c4b02b900b0d6c3d3ba135f41..930d3d8e71b905fcb9dc7efb75ca26d5f85599ee 100644 (file)
@@ -108,6 +108,13 @@ public:
 
     virtual bool HasTransparentBackground() { return true; }
 
+    // wxCheckBox-specific processing after processing the update event
+    virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
+    {
+        if ( event.GetSetChecked() )
+            SetValue(event.GetChecked());
+    }
+
 protected:
     virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
 
index 8d83d135645baa06993fb2bb6a62ff5993f595a9..c5b425e7e8da9132a284fac6c375b209d24e84d8 100644 (file)
@@ -62,6 +62,9 @@ public:
     virtual void SetLabel( const wxString &label );
     virtual bool SetFont(const wxFont& font);
 
+    // wxControl-specific processing after processing the update event
+    virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
+
     // Reserved for future use
     virtual void ReservedControlFunc1() {}
     virtual void ReservedControlFunc2() {}
index 7a25b6a4e0cbb873e616be3988f356417d7cdd76..be29607ecb3d9010324a7e288200355d106acf17 100644 (file)
@@ -1667,7 +1667,9 @@ public:
     {
         m_checked =
         m_enabled =
+        m_shown =
         m_setEnabled =
+        m_setShown =
         m_setText =
         m_setChecked = false;
     }
@@ -1675,7 +1677,9 @@ public:
         : wxCommandEvent(event),
           m_checked(event.m_checked),
           m_enabled(event.m_enabled),
+          m_shown(event.m_shown),
           m_setEnabled(event.m_setEnabled),
+          m_setShown(event.m_setShown),
           m_setText(event.m_setText),
           m_setChecked(event.m_setChecked),
           m_text(event.m_text)
@@ -1683,13 +1687,16 @@ public:
 
     bool GetChecked() const { return m_checked; }
     bool GetEnabled() const { return m_enabled; }
+    bool GetShown() const { return m_shown; }
     wxString GetText() const { return m_text; }
     bool GetSetText() const { return m_setText; }
     bool GetSetChecked() const { return m_setChecked; }
     bool GetSetEnabled() const { return m_setEnabled; }
+    bool GetSetShown() const { return m_setShown; }
 
     void Check(bool check) { m_checked = check; m_setChecked = true; }
     void Enable(bool enable) { m_enabled = enable; m_setEnabled = true; }
+    void Show(bool show) { m_shown = show; m_setShown = true; }
     void SetText(const wxString& text) { m_text = text; m_setText = true; }
 
     // Sets the interval between updates in milliseconds.
@@ -1719,7 +1726,9 @@ public:
 protected:
     bool          m_checked;
     bool          m_enabled;
+    bool          m_shown;
     bool          m_setEnabled;
+    bool          m_setShown;
     bool          m_setText;
     bool          m_setChecked;
     wxString      m_text;
index e9425ea376e960b7b94031c9532d5edadb7ae643..43f1ad5149609f069998a5375bbae78fba9905c7 100644 (file)
@@ -607,7 +607,10 @@ public:
     void InitCommandEvent(wxCommandEvent& event) const;
 
     /// do the window-specific processing after processing the update event
+    //  (duplicated code from wxTextCtrlBase)
+#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
     virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
+#endif
 
     /// Should we inherit colours?
     virtual bool ShouldInheritColours() const { return false; }
index ece152edaa8a3a7330432c06b8fd4871e3bbe1ff..380ff6ab5ba4810213922262b03048e2dad50297 100644 (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
 // ----------------------------------------------------------------------------
index 7d3c268389f1f0d1dde3f03af6ff4e7f94ef7077..a88d7f210badcae76697e5ad88c122274fa34d9b 100644 (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() )
index f69ac1e02154c459284b2264b37cac58746dd24a..c519fbc7c9005e0c8fdfc28c2a347a2ae1725643 100644 (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() )
index 19ee280fe2c129fce33df5e1560fd073594b17b0..7b458dca638c885bbfdb2fc8bdaeed5ba1bb4596 100644 (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
index 80d59be6ff5bc7400d298e774edf9540d1ac8ed5..04712e599178cee6241d5ef1a86b97bfbd7100ba 100644 (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