\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}}
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}
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)
}
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) )
{
return;
}
+ int keycode = event.GetKeyCode();
+
if ( (comboStyle & wxCB_READONLY) ||
(keycode != WXK_RIGHT && keycode != WXK_LEFT) )
{
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
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())
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())
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: