-wxWindow::~wxWindow(void)
-{
- m_isBeingDeleted = TRUE;
-
- // JACS - if behaviour is odd, restore this
- // to the start of ~wxWindow. Vadim has changed
- // it to nearer the end. Unsure of side-effects
- // e.g. when deleting associated global data.
- // Restore old Window proc, if required
-// UnsubclassWin();
-
- // Have to delete constraints/sizer FIRST otherwise
- // sizers may try to look at deleted windows as they
- // delete themselves.
-#if USE_CONSTRAINTS
- DeleteRelatedConstraints();
- if (m_constraints)
- {
- // This removes any dangling pointers to this window
- // in other windows' constraintsInvolvedIn lists.
- UnsetConstraints(m_constraints);
- delete m_constraints;
- m_constraints = NULL;
- }
- if (m_windowSizer)
- {
- delete m_windowSizer;
- m_windowSizer = NULL;
- }
- // If this is a child of a sizer, remove self from parent
- if (m_sizerParent)
- m_sizerParent->RemoveChild((wxWindow *)this);
+wxWindow::~wxWindow()
+{
+ // Remove potential dangling pointer
+ if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel)))
+ {
+ wxPanel* panel = (wxPanel*) GetParent();
+ if (panel->GetLastFocus() == this)
+ panel->SetLastFocus((wxWindow*) NULL);
+ }
+
+ m_isBeingDeleted = TRUE;
+
+ // first of all, delete the things on which nothing else depends
+
+#if wxUSE_TOOLTIPS
+ wxDELETE(m_tooltip);
+#endif
+
+ // JACS - if behaviour is odd, restore this
+ // to the start of ~wxWindow. Vadim has changed
+ // it to nearer the end. Unsure of side-effects
+ // e.g. when deleting associated global data.
+ // Restore old Window proc, if required
+ // UnsubclassWin();
+
+ // Have to delete constraints/sizer FIRST otherwise
+ // sizers may try to look at deleted windows as they
+ // delete themselves.
+#if wxUSE_CONSTRAINTS
+ DeleteRelatedConstraints();
+
+ if (m_constraints)
+ {
+ // This removes any dangling pointers to this window
+ // in other windows' constraintsInvolvedIn lists.
+ UnsetConstraints(m_constraints);
+ delete m_constraints;
+ m_constraints = NULL;
+ }
+
+ wxDELETE(m_windowSizer);
+
+ // If this is a child of a sizer, remove self from parent
+ if (m_sizerParent)
+ m_sizerParent->RemoveChild((wxWindow *)this);