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
This commit is contained in:
Vadim Zeitlin
2000-04-12 00:11:36 +00:00
parent d7102a0b12
commit a3e29acf45
3 changed files with 49 additions and 3 deletions

View File

@@ -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)

View File

@@ -717,6 +717,7 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
if ( HasRange() )
{
Spin()->SetValue((int)m_valueOld);
Spin()->SetFocus();
}
else
{

View File

@@ -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
// ----------------------------------------------------------------------------