]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wincmn.cpp
Correct signature of HitTest()
[wxWidgets.git] / src / common / wincmn.cpp
index 8c393888f31b12c11ab58d9c817ddbb4e13d980e..a48533d9689d1448a0e2811879f689ea18e4902a 100644 (file)
@@ -318,23 +318,9 @@ wxWindowBase::~wxWindowBase()
 
     wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
 
-    // reset the top-level parent's default item if it is this widget
+    // notify the parent about this window destruction
     if ( m_parent )
-    {
-        wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this),
-                                              wxTopLevelWindow);
-
-        if ( tlw && tlw->GetDefaultItem() == this )
-            tlw->SetDefaultItem(NULL);
-        if ( tlw && tlw->GetTmpDefaultItem() == this )
-            tlw->SetTmpDefaultItem(NULL);
-    }
-
-    // reset the dangling pointer our parent window may keep to us
-    if ( m_parent )
-    {
         m_parent->RemoveChild(this);
-    }
 
 #if wxUSE_CARET
     delete m_caret;
@@ -497,7 +483,7 @@ wxSize wxWindowBase::DoGetBestSize() const
 
     if ( m_windowSizer )
     {
-        best = GetWindowSizeForVirtualSize(m_windowSizer->GetMinSize());
+        best = m_windowSizer->GetMinSize();
     }
 #if wxUSE_CONSTRAINTS
     else if ( m_constraints )
@@ -847,18 +833,55 @@ bool wxWindowBase::Show(bool show)
     }
 }
 
-bool wxWindowBase::Enable(bool enable)
+bool wxWindowBase::IsEnabled() const
 {
-    if ( enable != m_isEnabled )
-    {
-        m_isEnabled = enable;
+    return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
+}
 
-        return true;
-    }
-    else
+void wxWindowBase::NotifyWindowOnEnableChange(bool enabled)
+{
+#ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
+    DoEnable(enabled);
+#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
+
+    OnEnabled(enabled);
+
+    // If we are top-level then the logic doesn't apply - otherwise
+    // showing a modal dialog would result in total greying out (and ungreying
+    // out later) of everything which would be really ugly
+    if ( IsTopLevel() )
+        return;
+
+    for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
+          node;
+          node = node->GetNext() )
     {
+        wxWindowBase * const child = node->GetData();
+        if ( !child->IsTopLevel() && child->IsThisEnabled() )
+            child->NotifyWindowOnEnableChange(enabled);
+    }
+}
+
+bool wxWindowBase::Enable(bool enable)
+{
+    if ( enable == IsThisEnabled() )
         return false;
+
+    m_isEnabled = enable;
+
+#ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
+    DoEnable(enable);
+#else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
+    wxWindowBase * const parent = GetParent();
+    if( !IsTopLevel() && parent && !parent->IsEnabled() )
+    {
+        return true;
     }
+#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
+
+    NotifyWindowOnEnableChange(enable);
+
+    return true;
 }
 
 bool wxWindowBase::IsShownOnScreen() const
@@ -910,6 +933,8 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent)
         return false;
     }
 
+    const bool oldEnabledState = IsEnabled();
+
     // unlink this window from the existing parent.
     if ( oldParent )
     {
@@ -930,6 +955,14 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent)
         wxTopLevelWindows.Append((wxWindow *)this);
     }
 
+    // We need to notify window (and its subwindows) if by changing the parent
+    // we also change our enabled/disabled status.
+    const bool newEnabledState = IsEnabled();
+    if ( newEnabledState != oldEnabledState )
+    {
+        NotifyWindowOnEnableChange(newEnabledState);
+    }
+
     return true;
 }
 
@@ -2286,7 +2319,7 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
         msg.Printf(_T("wxWidgets Library (%s port)\n")
                    _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
                    _T("Runtime version of toolkit used is %d.%d.%s\n")
-                   _T("Copyright (c) 1995-2006 wxWidgets team"),
+                   _T("Copyright (c) 1995-2007 wxWidgets team"),
                    wxPlatformInfo::Get().GetPortIdName().c_str(),
                    wxMAJOR_VERSION,
                    wxMINOR_VERSION,
@@ -2315,9 +2348,9 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
         wxMessageBox(msg, _T("wxWidgets information"),
                      wxICON_INFORMATION | wxOK,
                      (wxWindow *)this);
+#endif // wxUSE_MSGDLG
     }
     else
-#endif // wxUSE_MSGDLG
     {
         event.Skip();
     }
@@ -2487,6 +2520,10 @@ static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
     event.SetEventObject(win);
     if ( !win->GetEventHandler()->ProcessEvent(event) )
     {
+        // windows must handle this event, otherwise the app wouldn't behave
+        // correctly if it loses capture unexpectedly; see the discussion here:
+        // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
+        // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
         wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
     }
 }
@@ -2589,17 +2626,18 @@ bool wxWindowBase::TryParent(wxEvent& event)
 // keyboard navigation
 // ----------------------------------------------------------------------------
 
-// Navigates in the specified direction.
-bool wxWindowBase::Navigate(int flags)
+// Navigates in the specified direction inside this window
+bool wxWindowBase::DoNavigateIn(int flags)
 {
+#ifdef wxHAS_NATIVE_TAB_TRAVERSAL
+    // native code doesn't process our wxNavigationKeyEvents anyhow
+    return false;
+#else // !wxHAS_NATIVE_TAB_TRAVERSAL
     wxNavigationKeyEvent eventNav;
     eventNav.SetFlags(flags);
-    eventNav.SetEventObject(this);
-    if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
-    {
-        return true;
-    }
-    return false;
+    eventNav.SetEventObject(FindFocus());
+    return GetEventHandler()->ProcessEvent(eventNav);
+#endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
 }
 
 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)