]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/panelg.cpp
Doc/distribution script mods
[wxWidgets.git] / src / generic / panelg.cpp
index e586d96323877082490a3317f2da152e6c190e2d..346a2c82e6a13f080d276105143999c7900b5a1d 100644 (file)
@@ -36,6 +36,9 @@
     #include "wx/log.h"
 #endif
 
+#include "wx/toolbar.h"
+#include "wx/statusbr.h"
+
 #include "wx/generic/panelg.h"
 
 // ----------------------------------------------------------------------------
@@ -121,12 +124,20 @@ void wxPanel::OnSize(wxSizeEvent& WXUNUSED(event))
 
 void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
 {
-    // there is not much to do if we have only one child (or not at all) and
-    // we're not interested in "notebook page change" events here
-    if ( (GetChildren().GetCount() < 2) || event.IsWindowChange() )
+    // 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();
         }
@@ -141,11 +152,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();
-
-    const wxWindowList& children = GetChildren();
-
     // 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
@@ -227,14 +233,9 @@ void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
                     if ( focussed_child_of_parent->IsTopLevel() )
                         break;
 
-                    // is the parent a panel?
-                    wxPanel *panel = wxDynamicCast(parent, wxPanel);
-                    if (panel)
-                    {
-                        event.SetCurrentFocus( focussed_child_of_parent );
-                        if (parent->GetEventHandler()->ProcessEvent( event ))
-                            return;
-                    }
+                    event.SetCurrentFocus( focussed_child_of_parent );
+                    if (parent->GetEventHandler()->ProcessEvent( event ))
+                        return;
 
                     focussed_child_of_parent = parent;
                 }
@@ -279,6 +280,7 @@ void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
             }
             //else: the child manages its focus itself
 
+            event.Skip( FALSE );
             return;
         }
 
@@ -318,10 +320,8 @@ void wxPanel::SetFocus()
     //     think my addition to OnNavigationKey() above takes care of it.
     //     Keeping #ifdef __WXGTK__ for now, but please try removing it and see
     //     what happens.
-
-#ifdef __WXGTK__
-    m_winLastFocused = (wxWindow *)NULL;
-#endif // 0
+    //
+    // RR: Removed for now. Let's see what happens..
 
     if ( !SetFocusToChild() )
     {
@@ -331,7 +331,7 @@ void wxPanel::SetFocus()
 
 void wxPanel::OnFocus(wxFocusEvent& event)
 {
-    wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x."), GetHandle());
+    wxLogTrace(_T("focus"), _T("OnFocus on wxPanel 0x%08x, name: %s"), GetHandle(), GetName().c_str() );
 
     // If the panel gets the focus *by way of getting clicked on*
     // we move the focus to either the last window that had the
@@ -343,39 +343,58 @@ 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)
+{
+    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;
         }