]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxComboPopup::DestroyPopup(), which responsibility is to call Destroy() for...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 31 Mar 2011 17:22:51 +0000 (17:22 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 31 Mar 2011 17:22:51 +0000 (17:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67365 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/combo.h
interface/wx/combo.h
src/common/combocmn.cpp

index cb13398fba760728632d8f3875e0d5a765890d66..2196b4e5cb2ac9a6552f95afe6d071d14f88544c 100644 (file)
@@ -767,6 +767,13 @@ public:
     // Return true for success.
     virtual bool Create(wxWindow* parent) = 0;
 
     // Return true for success.
     virtual bool Create(wxWindow* parent) = 0;
 
+    // Calls Destroy() for the popup control (i.e. one returned by
+    // GetControl()) and makes sure that 'this' is deleted at the end.
+    // Default implementation works for both cases where popup control
+    // class is multiple inherited or created on heap as a separate
+    // object.
+    virtual void DestroyPopup();
+
     // We must have an associated control which is subclassed by the combobox.
     virtual wxWindow *GetControl() = 0;
 
     // We must have an associated control which is subclassed by the combobox.
     virtual wxWindow *GetControl() = 0;
 
index 6b7291eca415229c25eadea8d5e28973131c7514..00ba186a5fd8e4a300abacf90651ce59de401886 100644 (file)
@@ -36,6 +36,14 @@ public:
     */
     virtual bool Create(wxWindow* parent) = 0;
 
     */
     virtual bool Create(wxWindow* parent) = 0;
 
+    /**
+        You only need to implement this member function if you create
+        your popup class in non-standard way. The default implementation can
+        handle both multiple-inherited popup control (as seen in wxComboCtrl
+        samples) and one allocated separately in heap.
+    */
+    virtual void DestroyPopup();
+
     /**
         Utility function that hides the popup.
     */
     /**
         Utility function that hides the popup.
     */
index e0a3db75c6c8d8a488474f868ad628b209305146..bf1ad43c3ab7b82528fcdf0eb8425bc66d12e428 100644 (file)
@@ -674,6 +674,34 @@ void wxComboPopup::Dismiss()
     m_combo->HidePopup(true);
 }
 
     m_combo->HidePopup(true);
 }
 
+void wxComboPopup::DestroyPopup()
+{
+    // Here we make sure that the popup control's Destroy() gets called.
+    // This is necessary for the wxPersistentWindow to work properly.
+    wxWindow* popupCtrl = GetControl();
+    if ( popupCtrl )
+    {
+        // While all wxComboCtrl examples have m_popupInterface and
+        // popupCtrl as the same class (that will be deleted via the
+        // Destroy() call below), it is technically still possible to
+        // have implementations where they are in fact not same
+        // multiple-inherited class. Here we use C++ RTTI to check for
+        // this rare case.
+      #ifndef wxNO_RTTI
+        // It is probably better to delete m_popupInterface first, so
+        // that it retains access to its popup control window.
+        if ( dynamic_cast<void*>(this) !=
+             dynamic_cast<void*>(popupCtrl) )
+            delete this;
+      #endif
+        popupCtrl->Destroy();
+    }
+    else
+    {
+        delete this;
+    }
+}
+
 // ----------------------------------------------------------------------------
 // input handling
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // input handling
 // ----------------------------------------------------------------------------
@@ -2091,30 +2119,8 @@ void wxComboCtrlBase::DestroyPopup()
 
     if ( m_popupInterface )
     {
 
     if ( m_popupInterface )
     {
-        // Here we make sure that the popup control's Destroy() gets called.
-        // This is necessary for the wxPersistentWindow to work properly.
-        wxWindow* popupCtrl = m_popupInterface->GetControl();
-        if ( popupCtrl )
-        {
-            // While all wxComboCtrl examples have m_popupInterface and
-            // popupCtrl as the same class (that will be deleted via the
-            // Destroy() call below), it is technically still possible to
-            // have implementations where they are in fact not same
-            // multiple-inherited class. Here we use C++ RTTI to check for
-            // this rare case.
-          #ifndef wxNO_RTTI
-            // It is probably better to delete m_popupInterface first, so
-            // that it retains access to its popup control window.
-            if ( dynamic_cast<void*>(m_popupInterface) !=
-                 dynamic_cast<void*>(popupCtrl) )
-                delete m_popupInterface;
-          #endif
-            popupCtrl->Destroy();
-        }
-        else
-        {
-            delete m_popupInterface;
-        }
+        // NB: DestroyPopup() performs 'delete this'.
+        m_popupInterface->DestroyPopup();
         m_popupInterface = NULL;
     }
 
         m_popupInterface = NULL;
     }