From 5f6cfda79ff6d1ddc0b1b88c0ba9a69c4dd1f3f3 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 15 Jun 2004 14:03:06 +0000 Subject: [PATCH] With wxTE_PROCESS_TAB, tabs are now inserted in the text control by default. The new Navigate function can be used to do navigation programmatically. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27807 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 ++++ docs/latex/wx/window.tex | 20 ++++++++++++++++++++ include/wx/window.h | 3 +++ src/common/wincmn.cpp | 18 ++++++++++++++++++ src/mac/carbon/textctrl.cpp | 15 ++------------- src/mac/classic/textctrl.cpp | 15 ++------------- src/msw/textctrl.cpp | 25 ++++++++++++------------- 7 files changed, 61 insertions(+), 39 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 6a0e2c0e39..b8ffe74ebc 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -111,6 +111,10 @@ All (GUI): is discouraged - Added ..._CMD_... variants for wxGrid event table entry macros taking window identifiers +- Added wxWindowBase::Navigate for programmatic navigation to the next + control. +- On most platforms, wxTextCtrl::OnChar now inserts a tab character if + wxTE_PROCESS_TAB is set, or navigates to the next control if not. Unix: diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 69b5779362..24cb671966 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -1448,6 +1448,26 @@ implements the following methods:\par \end{twocollist}} } +\membersection{wxWindow::Navigate}\label{wxwindownavigate} + +\func{bool}{Navigate}{\param{bool}{ direction = true}, \param{bool}{ windowChange = false}} + +Does keyboard navigation from this window to another, by sending +a wxNavigationKeyEvent. + +\wxheading{Parameters} + +\docparam{direction}{{\tt true} to navigate forwards, {\tt false} to navigate backwards.} + +\docparam{windowChange}{{\tt true} if the navigation is a window change.} + +\wxheading{Remarks} + +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. + %% VZ: wxWindow::OnXXX() functions should not be documented but I'm leaving %% the old docs here in case we want to move any still needed bits to %% the right location (i.e. probably the corresponding events docs) diff --git a/include/wx/window.h b/include/wx/window.h index 96385dd616..3370fa75b2 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -489,6 +489,9 @@ public: // set this child as temporary default virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win)) { } + // Navigates in the specified direction by sending a wxNavigationKeyEvent + virtual bool Navigate(bool direction = true, bool windowChange = false); + // parent/children relations // ------------------------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index d39583bbb8..382bcbec6d 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2400,6 +2400,24 @@ bool wxWindowBase::TryParent(wxEvent& event) return wxEvtHandler::TryParent(event); } +// ---------------------------------------------------------------------------- +// navigation +// ---------------------------------------------------------------------------- + +// Navigates in the specified direction. +bool wxWindowBase::Navigate(bool direction, bool windowChange) +{ + wxNavigationKeyEvent eventNav; + eventNav.SetDirection(direction); + eventNav.SetWindowChange(windowChange); + eventNav.SetEventObject(this); + if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) + { + return true; + } + return false; +} + // ---------------------------------------------------------------------------- // global functions // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 6217f191c6..eec92c414c 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -1985,21 +1985,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) break; case WXK_TAB: - // always produce navigation event - even if we process TAB - // ourselves the fact that we got here means that the user code - // decided to skip processing of this TAB - probably to let it - // do its default job. + if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { - wxNavigationKeyEvent eventNav; - eventNav.SetDirection(!event.ShiftDown()); - eventNav.SetWindowChange(event.ControlDown()); - eventNav.SetEventObject(this); - - if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) + if (Navigate(!event.ShiftDown(), event.ControlDown())) return; - - event.Skip() ; - return; } break; } diff --git a/src/mac/classic/textctrl.cpp b/src/mac/classic/textctrl.cpp index fb63ab3786..3819c0cd2e 100644 --- a/src/mac/classic/textctrl.cpp +++ b/src/mac/classic/textctrl.cpp @@ -1649,21 +1649,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) break; case WXK_TAB: - // always produce navigation event - even if we process TAB - // ourselves the fact that we got here means that the user code - // decided to skip processing of this TAB - probably to let it - // do its default job. + if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { - wxNavigationKeyEvent eventNav; - eventNav.SetDirection(!event.ShiftDown()); - eventNav.SetWindowChange(event.ControlDown()); - eventNav.SetEventObject(this); - - if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) + if (Navigate(!event.ShiftDown(), event.ControlDown())) return; - - event.Skip() ; - return; } break; } diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 5f85cb94b0..82cc0b8e3a 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -1689,11 +1689,6 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) break; case WXK_TAB: - // always produce navigation event -- even if we process TAB - // ourselves the fact that we got here means that the user code - // decided to skip processing of this TAB -- probably to let it - // do its default job. - // ok, so this is getting absolutely ridiculous but I don't see // any other way to fix this bug: when a multiline text control is // inside a wxFrame, we need to generate the navigation event as @@ -1708,15 +1703,19 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // the right thing to do would, of course, be to understand what // the hell is IsDialogMessage() doing but this is beyond my feeble // forces at the moment unfortunately - if ( FindFocus() == this ) + if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { - wxNavigationKeyEvent eventNav; - eventNav.SetDirection(!event.ShiftDown()); - eventNav.SetWindowChange(event.ControlDown()); - eventNav.SetEventObject(this); - - if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) - return; + if ( FindFocus() == this ) + { + if (Navigate(!event.ShiftDown(), event.ControlDown())) + return; + } + } + else + { + // Insert tab since calling the default Windows handler + // doesn't seem to do it + WriteText(wxT("\t")); } break; } -- 2.47.2