]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxWindow::HandleAsNavigationKey() helper for handling (not only) TAB key in...
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 12 Feb 2008 20:13:22 +0000 (20:13 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 12 Feb 2008 20:13:22 +0000 (20:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51741 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/window.tex
include/wx/window.h
src/common/combocmn.cpp
src/common/wincmn.cpp
src/generic/datavgen.cpp
src/generic/listctrl.cpp
src/generic/vlbox.cpp

index 5e3731fe2b540047c24261440ba525caef43444a..ed85d9d0decf5bdac6feacaf8ed1c1fc9bc01191 100644 (file)
@@ -1534,6 +1534,24 @@ Returns the value previously passed to
 \helpref{wxWindow::SetWindowVariant}{wxwindowsetwindowvariant}.
 
 
+\membersection{wxWindow::HandleAsNavigationKey}\label{wxwindowhandleasnavigationkey}
+
+\func{bool}{HandleAsNavigationKey}{\param{const wxKeyEvent\&}{ event}}
+
+This function will generate the appropriate call to
+\helpref{Navigate}{wxwindownavigate} if the key event is one normally used for
+keyboard navigation and return \true in this case.
+
+\wxheading{Return value}
+
+Returns \true if the key pressed was for navigation and was handled, \false
+otherwise.
+
+\wxheading{See also}
+
+\helpref{Navigate}{wxwindownavigate}
+
+
 \membersection{wxWindow::HandleWindowEvent}\label{wxwindowhandlewindowevent}
 
 \func{bool}{HandleWindowEvent}{\param{wxEvent\& }{event}}
@@ -1952,7 +1970,8 @@ changed.
 You may wish to call this from a text control custom keypress handler to do the default
 navigation behaviour for the tab key, since the standard default behaviour for
 a multiline text control with the wxTE\_PROCESS\_TAB style is to insert a tab
-and not navigate to the next control. See also \helpref{wxNavigationKeyEvent}{wxnavigationkeyevent}.
+and not navigate to the next control. See also \helpref{wxNavigationKeyEvent}{wxnavigationkeyevent} and
+\helpref{HandleAsNavigationKey}{wxwindowhandleasnavigationkey}.
 
 
 \membersection{wxWindow::NavigateIn}\label{wxwindownavigatein}
index 4451f8f50d44dd74273417c10a974d9bf7e6c1e9..218e2ce79edf8674d4bcc7d2b3f4835b07b8d9e1 100644 (file)
@@ -680,6 +680,11 @@ public:
     bool Navigate(int flags = wxNavigationKeyEvent::IsForward)
         { return m_parent && ((wxWindowBase *)m_parent)->DoNavigateIn(flags); }
 
+    // this function will generate the appropriate call to Navigate() if the
+    // key event is one normally used for keyboard navigation and return true
+    // in this case
+    bool HandleAsNavigationKey(const wxKeyEvent& event);
+
         // move this window just before/after the specified one in tab order
         // (the other window must be our sibling!)
     void MoveBeforeInTabOrder(wxWindow *win)
index 8fb796c2ccaa3761846f249699c53cc5215bad84..6ed975c8a863cc4e491d2b7f9ad9e5158a5c4244 100644 (file)
@@ -1651,22 +1651,8 @@ void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
     }
     else // no popup
     {
-        int keycode = event.GetKeyCode();
-
-        if ( keycode == WXK_TAB )
-        {
-            wxNavigationKeyEvent evt;
-
-            wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
-
-            evt.SetFlags(wxNavigationKeyEvent::FromTab|
-                         (!event.ShiftDown() ? wxNavigationKeyEvent::IsForward
-                                             : wxNavigationKeyEvent::IsBackward));
-            evt.SetEventObject(mainCtrl);
-            evt.SetCurrentFocus(mainCtrl);
-            mainCtrl->GetParent()->GetEventHandler()->AddPendingEvent(evt);
+        if ( HandleAsNavigationKey(event) )
             return;
-        }
 
         if ( IsKeyPopupToggle(event) )
         {
@@ -1683,6 +1669,8 @@ void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
             return;
         }
 
+        int keycode = event.GetKeyCode();
+
         if ( (comboStyle & wxCB_READONLY) ||
              (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
         {
index 0c2f15dc96f56319a12de22eb4475865b2375ec6..00c3b8934126a24bf29a943125336a88c907a3b0 100644 (file)
@@ -2700,12 +2700,33 @@ bool wxWindowBase::DoNavigateIn(int flags)
     return false;
 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
     wxNavigationKeyEvent eventNav;
+    wxWindow *focused = FindFocus();
+    eventNav.SetCurrentFocus(focused);
+    eventNav.SetEventObject(focused);
     eventNav.SetFlags(flags);
-    eventNav.SetEventObject(FindFocus());
     return GetEventHandler()->ProcessEvent(eventNav);
 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
 }
 
+bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent& event)
+{
+    if ( event.GetKeyCode() != WXK_TAB )
+        return false;
+
+    int flags = wxNavigationKeyEvent::FromTab;
+
+    if ( event.ShiftDown() )
+        flags |= wxNavigationKeyEvent::IsBackward;
+    else
+        flags |= wxNavigationKeyEvent::IsForward;
+
+    if ( event.ControlDown() )
+        flags |= wxNavigationKeyEvent::WinChange;
+
+    Navigate(flags);
+    return true;
+}
+
 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move)
 {
     // check that we're not a top level window
index 1a442101fc5adea9ac728bd50687b00e5b60ceb6..9fcf58d70bcb5886c23804775cac0d1af333ee76 100644 (file)
@@ -3395,16 +3395,8 @@ void wxDataViewMainWindow::DestroyTree()
 
 void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
 {
-    if (event.GetKeyCode() == WXK_TAB)
-    {
-        wxNavigationKeyEvent nevent;
-        nevent.SetWindowChange( event.ControlDown() );
-        nevent.SetDirection( !event.ShiftDown() );
-        nevent.SetEventObject( GetParent()->GetParent() );
-        nevent.SetCurrentFocus( m_parent );
-        if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
-            return;
-    }
+    if ( HandleAsNavigationKey(event) )
+        return;
 
     // no item -> nothing to do
     if (!HasCurrentRow())
index e8cfa298625f92e603b623fa2d64912939dd1adc..d58f84467e61fcf01a9839dafa46d508b13ffc65 100644 (file)
@@ -3456,16 +3456,8 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
     ke.SetEventObject( parent );
     if (parent->GetEventHandler()->ProcessEvent( ke )) return;
 
-    if (event.GetKeyCode() == WXK_TAB)
-    {
-        wxNavigationKeyEvent nevent;
-        nevent.SetWindowChange( event.ControlDown() );
-        nevent.SetDirection( !event.ShiftDown() );
-        nevent.SetEventObject( GetParent()->GetParent() );
-        nevent.SetCurrentFocus( m_parent );
-        if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
-            return;
-    }
+    if ( HandleAsNavigationKey(event) )
+        return;
 
     // no item -> nothing to do
     if (!HasCurrent())
index 747d82825164302617dd0b084ee45c1e62f54fea..d75fc4f1304c25db1fc5e9d73b8b90d8df0935c0 100644 (file)
@@ -602,13 +602,7 @@ void wxVListBox::OnKeyDown(wxKeyEvent& event)
         case WXK_TAB:
             // Since we are using wxWANTS_CHARS we need to send navigation
             // events for the tabs on MSW
-            {
-                wxNavigationKeyEvent ne;
-                ne.SetDirection(!event.ShiftDown());
-                ne.SetCurrentFocus(this);
-                ne.SetEventObject(this);
-                GetParent()->GetEventHandler()->ProcessEvent(ne);
-            }
+            HandleAsNavigationKey(event);
             // fall through to default
 #endif
         default: