From a3e29acf4536e3e2c92ed012db5c7daff62bbebd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Apr 2000 00:11:36 +0000 Subject: [PATCH] 1. spin ctrl now generates char/key events 2. grid sets focus to the number editor git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7133 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/spinctrl.h | 13 ++++++++++--- src/generic/grid.cpp | 1 + src/msw/spinctrl.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index 9a160ff7aa..47eabec0c9 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -1,4 +1,4 @@ -///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// // Name: msw/spinctrl.h // Purpose: wxSpinCtrl class declaration for Win32 // Author: Vadim Zeitlin @@ -57,6 +57,8 @@ public: // implementation only from now on // ------------------------------- + virtual ~wxSpinCtrl(); + virtual void SetValue(int val) { wxSpinButton::SetValue(val); } virtual int GetValue() const; virtual bool SetFont(const wxFont &font); @@ -65,7 +67,10 @@ public: virtual bool Enable(bool enable = TRUE); virtual bool Show(bool show = TRUE); - virtual bool AcceptsFocus() const { return TRUE; } + // wxSpinButton doesn't accept focus, but we do + virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); } + + WXFARPROC GetBuddyWndProc() const { return m_oldBuddyWndProc; } protected: virtual void DoMoveWindow(int x, int y, int width, int height); @@ -74,7 +79,9 @@ protected: // the handler for wxSpinButton events void OnSpinChange(wxSpinEvent& event); - WXHWND m_hwndBuddy; + // the data for the "buddy" text ctrl + WXHWND m_hwndBuddy; + WXFARPROC m_oldBuddyWndProc; private: DECLARE_DYNAMIC_CLASS(wxSpinCtrl) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d41f45f4e4..6f9b958a4f 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -717,6 +717,7 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) if ( HasRange() ) { Spin()->SetValue((int)m_valueOld); + Spin()->SetFocus(); } else { diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 1a8d4c1016..eba7517d89 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -69,6 +69,32 @@ static const int MARGIN_BETWEEN = 1; // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// wnd proc for the buddy text ctrl +// ---------------------------------------------------------------------------- + +LRESULT APIENTRY _EXPORT wxBuddyTextWndProc(HWND hwnd, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + wxSpinCtrl *spin = (wxSpinCtrl *)::GetWindowLong(hwnd, GWL_USERDATA); + + // forward some messages (the key ones only so far) to the spin ctrl + switch ( message ) + { + case WM_CHAR: + case WM_DEADCHAR: + case WM_KEYUP: + case WM_KEYDOWN: + spin->MSWWindowProc(message, wParam, lParam); + break; + } + + return ::CallWindowProc(CASTWNDPROC spin->GetBuddyWndProc(), + hwnd, message, wParam, lParam); +} + // ---------------------------------------------------------------------------- // construction // ---------------------------------------------------------------------------- @@ -138,6 +164,11 @@ bool wxSpinCtrl::Create(wxWindow *parent, return FALSE; } + // subclass the text ctrl to be able to intercept some events + m_oldBuddyWndProc = (WXFARPROC)::GetWindowLong((HWND)m_hwndBuddy, GWL_WNDPROC); + ::SetWindowLong((HWND)m_hwndBuddy, GWL_USERDATA, (LONG)this); + ::SetWindowLong((HWND)m_hwndBuddy, GWL_WNDPROC, (LONG)wxBuddyTextWndProc); + // should have the same font as the other controls SetFont(GetParent()->GetFont()); @@ -167,6 +198,13 @@ bool wxSpinCtrl::Create(wxWindow *parent, return TRUE; } +wxSpinCtrl::~wxSpinCtrl() +{ + // destroy the buddy window because this pointer which wxBuddyTextWndProc + // uses will not soon be valid any more + ::DestroyWindow((HWND)m_hwndBuddy); +} + // ---------------------------------------------------------------------------- // wxTextCtrl-like methods // ----------------------------------------------------------------------------