From ac8d0c118b7403e2838e75124b442051299e6f6c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Sep 2003 19:54:51 +0000 Subject: [PATCH] added wxVALIDATOR_PARAM and use it to avoid warnings about unused validators when wxUSE_VALIDATORS==0 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23611 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/validate.h | 36 +++++++++++++++++------------ src/common/ctrlcmn.cpp | 2 +- src/common/wincmn.cpp | 4 ++-- src/generic/treectlg.cpp | 2 +- src/msw/bmpbuttn.cpp | 2 +- src/msw/control.cpp | 2 +- src/msw/dialog.cpp | 17 ++++---------- src/msw/evtloop.cpp | 49 +++++++++++++++++++++++++++++++++------- src/msw/gauge95.cpp | 2 +- src/msw/listbox.cpp | 2 +- src/msw/listctrl.cpp | 2 +- src/msw/scrolbar.cpp | 2 +- src/msw/slider95.cpp | 2 +- 13 files changed, 78 insertions(+), 46 deletions(-) diff --git a/include/wx/validate.h b/include/wx/validate.h index 90774c0788..1888c52eb1 100644 --- a/include/wx/validate.h +++ b/include/wx/validate.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: validate.h +// Name: wx/validate.h // Purpose: wxValidator class // Author: Julian Smart // Modified by: @@ -9,21 +9,16 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_VALIDATEH__ -#define _WX_VALIDATEH__ +#ifndef _WX_VALIDATE_H_ +#define _WX_VALIDATE_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "validate.h" #endif -#if defined(wxUSE_VALIDATORS) && !wxUSE_VALIDATORS - // wxWindows is compiled without support for wxValidator, but we still - // want to be able to pass wxDefaultValidator to the functions which take - // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS" - // everywhere - class WXDLLEXPORT wxValidator; - #define wxDefaultValidator (*((wxValidator *)NULL)) -#else // wxUSE_VALIDATORS +#include "wx/defs.h" + +#if wxUSE_VALIDATORS #include "wx/event.h" @@ -88,7 +83,20 @@ private: WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator; -#endif // wxUSE_VALIDATORS +#define wxVALIDATOR_PARAM(val) val + +#else // !wxUSE_VALIDATORS + // wxWindows is compiled without support for wxValidator, but we still + // want to be able to pass wxDefaultValidator to the functions which take + // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS" + // everywhere + class WXDLLEXPORT wxValidator; + #define wxDefaultValidator (*((wxValidator *)NULL)) + + // this macro allows to avoid warnings about unused parameters when + // wxUSE_VALIDATORS == 0 + #define wxVALIDATOR_PARAM(val) +#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS + +#endif // _WX_VALIDATE_H_ -#endif - // _WX_VALIDATEH__ diff --git a/src/common/ctrlcmn.cpp b/src/common/ctrlcmn.cpp index 6b834f3aba..468a4ac93b 100644 --- a/src/common/ctrlcmn.cpp +++ b/src/common/ctrlcmn.cpp @@ -55,7 +55,7 @@ bool wxControlBase::Create(wxWindow *parent, const wxPoint &pos, const wxSize &size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString &name) { bool ret = wxWindow::Create(parent, id, pos, size, style, name); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 7c03f1178d..dc4f307488 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -202,7 +202,7 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, const wxPoint& WXUNUSED(pos), const wxSize& WXUNUSED(size), long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { #if wxUSE_STATBOX @@ -2144,7 +2144,7 @@ void wxWindowBase::SendDestroyEvent() // event processing // ---------------------------------------------------------------------------- -bool wxWindowBase::TryValidator(wxEvent& event) +bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event)) { #if wxUSE_VALIDATORS // Can only use the validator of the window which diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index e82b05d4e6..a167bce9ae 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -747,7 +747,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, const wxPoint& pos, const wxSize& size, long style, - const wxValidator &validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name ) { #ifdef __WXMAC__ diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index d1c3785eea..e72d2dbb8d 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -103,7 +103,7 @@ bitmap "disabled" , bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { m_bmpNormal = bitmap; diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 71bc3e6f1e..4d4c0e159f 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -59,7 +59,7 @@ bool wxControl::Create(wxWindow *parent, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { if ( !wxWindow::Create(parent, id, pos, size, style, name) ) diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index 727670f33e..a6f5482069 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -40,6 +40,7 @@ #include "wx/msw/private.h" #include "wx/log.h" +#include "wx/evtloop.h" #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__) #include @@ -246,7 +247,7 @@ bool wxDialog::IsModal() const bool wxDialog::IsModalShowing() const { - return !!wxModalDialogs.Find(wxConstCast(this, wxDialog)); + return wxModalDialogs.Find(wxConstCast(this, wxDialog)) != NULL; } wxWindow *wxDialog::FindSuitableParent() const @@ -309,18 +310,8 @@ void wxDialog::DoShowModal() wxIsInOnIdleFlag = FALSE; // enter the modal loop - while ( IsModalShowing() ) - { -#if wxUSE_THREADS - wxMutexGuiLeaveOrEnter(); -#endif // wxUSE_THREADS - - while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) - ; - - // a message came or no more idle processing to do - wxTheApp->DoMessage(); - } + wxEventLoop evtLoop; + evtLoop.Run(); wxIsInOnIdleFlag = wasInOnIdle; diff --git a/src/msw/evtloop.cpp b/src/msw/evtloop.cpp index 94874f5da1..a36caa946d 100644 --- a/src/msw/evtloop.cpp +++ b/src/msw/evtloop.cpp @@ -96,13 +96,29 @@ void wxEventLoopImpl::ProcessMessage(MSG *msg) bool wxEventLoopImpl::PreProcessMessage(MSG *msg) { - HWND hWnd = msg->hwnd; - wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hWnd); + HWND hwnd = msg->hwnd; + wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hwnd); + + // this may happen if the event occured in a standard modeless dialog (the + // only example of which I know of is the find/replace dialog) - then call + // IsDialogMessage() to make TAB navigation in it work + if ( !wndThis ) + { + // we need to find the dialog containing this control as + // IsDialogMessage() just eats all the messages (i.e. returns TRUE for + // them) if we call it for the control itself + while ( hwnd && ::GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD ) + { + hwnd = ::GetParent(hwnd); + } + + return hwnd && ::IsDialogMessage(hwnd, msg) != 0; + } #if wxUSE_TOOLTIPS // we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to // popup the tooltip bubbles - if ( wndThis && (msg->message == WM_MOUSEMOVE) ) + if ( msg->message == WM_MOUSEMOVE ) { wxToolTip *tt = wndThis->GetToolTip(); if ( tt ) @@ -112,22 +128,39 @@ bool wxEventLoopImpl::PreProcessMessage(MSG *msg) } #endif // wxUSE_TOOLTIPS - // try translations first; find the youngest window with a translation - // table. + // allow the window to prevent certain messages from being + // translated/processed (this is currently used by wxTextCtrl to always + // grab Ctrl-C/V/X, even if they are also accelerators in some parent) + if ( !wndThis->MSWShouldPreProcessMessage((WXMSG *)msg) ) + { + return FALSE; + } + + // try translations first: the accelerators override everything wxWindow *wnd; + for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) { - if ( wnd->MSWTranslateMessage((WXMSG *)msg) ) + if ( wnd->MSWTranslateMessage((WXMSG *)msg)) return TRUE; + + // stop at first top level window, i.e. don't try to process the key + // strokes originating in a dialog using the accelerators of the parent + // frame - this doesn't make much sense + if ( wnd->IsTopLevel() ) + break; } - // Anyone for a non-translation message? Try youngest descendants first. - for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) + // now try the other hooks (kbd navigation is handled here): we start from + // wndThis->GetParent() because wndThis->MSWProcessMessage() was already + // called above + for ( wnd = wndThis->GetParent(); wnd; wnd = wnd->GetParent() ) { if ( wnd->MSWProcessMessage((WXMSG *)msg) ) return TRUE; } + // no special preprocessing for this message, dispatch it normally return FALSE; } diff --git a/src/msw/gauge95.cpp b/src/msw/gauge95.cpp index 554747d52a..421f8062d7 100644 --- a/src/msw/gauge95.cpp +++ b/src/msw/gauge95.cpp @@ -131,7 +131,7 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { SetName(name); diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 98517bd574..005756289e 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -161,7 +161,7 @@ bool wxListBox::Create(wxWindow *parent, const wxSize& size, int n, const wxString choices[], long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { m_noItems = 0; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 31f88779ca..98df698331 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -318,7 +318,7 @@ bool wxListCtrl::Create(wxWindow *parent, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { #if wxUSE_VALIDATORS diff --git a/src/msw/scrolbar.cpp b/src/msw/scrolbar.cpp index 6085e1efb6..5905800a43 100644 --- a/src/msw/scrolbar.cpp +++ b/src/msw/scrolbar.cpp @@ -89,7 +89,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { if (!parent) diff --git a/src/msw/slider95.cpp b/src/msw/slider95.cpp index 950348d781..7e02dd7f62 100644 --- a/src/msw/slider95.cpp +++ b/src/msw/slider95.cpp @@ -121,7 +121,7 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id, int value, int minValue, int maxValue, const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, + const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) -- 2.45.2