]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/panelg.cpp
Commited latest SciTech changes into CVS. This includes updates to the
[wxWidgets.git] / src / generic / panelg.cpp
index 2a91143d97638293a2045f0f7321136822d40408..7bded1cd15cd548c66a38cbd94ff13640afb8e15 100644 (file)
@@ -36,6 +36,9 @@
     #include "wx/log.h"
 #endif
 
+#include "wx/toolbar.h"
+#include "wx/statusbr.h"
+
 #include "wx/generic/panelg.h"
 
 // ----------------------------------------------------------------------------
@@ -71,15 +74,7 @@ bool wxPanel::Create(wxWindow *parent, wxWindowID id,
                      long style,
                      const wxString& name)
 {
-    bool ret = wxWindow::Create(parent, id, pos, size, style, name);
-
-    if ( ret )
-    {
-        SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
-        SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
-    }
-
-    return ret;
+    return wxWindow::Create(parent, id, pos, size, style, name);
 }
 
 // ----------------------------------------------------------------------------
@@ -121,14 +116,20 @@ void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event))
 
 void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
 {
+    // the event is propagated downwards if the event emitter was our parent
+    bool goingDown = event.GetEventObject() == GetParent();
+
     const wxWindowList& children = GetChildren();
 
     // there is not much to do if we don't have children and we're not
     // interested in "notebook page change" events here
     if ( !children.GetCount() || event.IsWindowChange() )
     {
+        // let the parent process it unless it already comes from our parent
+        // of we don't have any
         wxWindow *parent = GetParent();
-        if ( !parent || !parent->GetEventHandler()->ProcessEvent(event) )
+        if ( goingDown ||
+             !parent || !parent->GetEventHandler()->ProcessEvent(event) )
         {
             event.Skip();
         }
@@ -143,9 +144,6 @@ void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
     // next acceptable child
     wxWindowList::Node *node, *start_node;
 
-    // the event is propagated downwards if the event emitter was our parent
-    bool goingDown = event.GetEventObject() == GetParent();
-
     // we should start from the first/last control and not from the one which
     // had focus the last time if we're propagating the event downwards because
     // for our parent we look like a single control
@@ -286,6 +284,13 @@ void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
     event.Skip();
 }
 
+void wxPanel::RemoveChild(wxWindowBase *child)
+{
+    if ( child == m_winLastFocused )
+        m_winLastFocused = NULL;
+    wxWindow::RemoveChild(child);
+}
+
 void wxPanel::SetFocus()
 {
     wxLogTrace(_T("focus"), _T("SetFocus on wxPanel 0x%08x."), GetHandle());
@@ -337,39 +342,60 @@ void wxPanel::OnFocus(wxFocusEvent& event)
 
 bool wxPanel::SetFocusToChild()
 {
-    if ( m_winLastFocused )
+    return wxSetFocusToChild(this, &m_winLastFocused);
+}
+
+// ----------------------------------------------------------------------------
+// SetFocusToChild(): this function is used by wxPanel but also by wxFrame in
+// wxMSW, this is why it is outside of wxPanel class
+// ----------------------------------------------------------------------------
+
+bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused)
+{
+    wxCHECK_MSG( win, FALSE, _T("wxSetFocusToChild(): invalid window") );
+
+    if ( *childLastFocused )
     {
         // It might happen that the window got reparented or no longer accepts
         // the focus.
-        if ( (m_winLastFocused->GetParent() == this) &&
-             m_winLastFocused->AcceptsFocus() )
+        if ( (*childLastFocused)->GetParent() == win &&
+             (*childLastFocused)->AcceptsFocus() )
         {
             wxLogTrace(_T("focus"),
                        _T("SetFocusToChild() => last child (0x%08x)."),
-                       m_winLastFocused->GetHandle());
+                       (*childLastFocused)->GetHandle());
 
-            m_winLastFocused->SetFocus();
+            (*childLastFocused)->SetFocus();
             return TRUE;
         }
         else
         {
             // it doesn't count as such any more
-            m_winLastFocused = (wxWindow *)NULL;
+            *childLastFocused = (wxWindow *)NULL;
         }
     }
 
     // set the focus to the first child who wants it
-    wxWindowList::Node *node = GetChildren().GetFirst();
+    wxWindowList::Node *node = win->GetChildren().GetFirst();
     while ( node )
     {
         wxWindow *child = node->GetData();
-        if ( child->AcceptsFocus() )
+
+        if ( child->AcceptsFocus()
+             && !child->IsTopLevel()
+#if wxUSE_TOOLBAR
+             && !wxDynamicCast(child, wxToolBar)
+#endif // wxUSE_TOOLBAR
+#if wxUSE_STATUSBAR
+             && !wxDynamicCast(child, wxStatusBar)
+#endif // wxUSE_STATUSBAR
+           )
         {
             wxLogTrace(_T("focus"),
                        _T("SetFocusToChild() => first child (0x%08x)."),
                        child->GetHandle());
 
-            m_winLastFocused = child;  // should be redundant, but it is not
+            *childLastFocused = child;  // should be redundant, but it is not
             child->SetFocus();
             return TRUE;
         }