+wxSpinCtrl* wxSpinCtrl::GetSpinForTextCtrl(
+ WXHWND hWndBuddy
+)
+{
+ wxSpinCtrl* pSpin = (wxSpinCtrl *)::WinQueryWindowULong( (HWND)hWndBuddy
+ ,QWL_USER
+ );
+ int i = m_svAllSpins.Index(pSpin);
+
+ if (i == wxNOT_FOUND)
+ return NULL;
+
+ // sanity check
+ wxASSERT_MSG( pSpin->m_hWndBuddy == hWndBuddy,
+ _T("wxSpinCtrl has incorrect buddy HWND!") );
+
+ return pSpin;
+} // end of wxSpinCtrl::GetSpinForTextCtrl
+
+int wxSpinCtrl::GetValue() const
+{
+ long lVal = 0L;
+ char zVal[10];
+
+ ::WinSendMsg( GetHwnd()
+ ,SPBM_QUERYVALUE
+ ,MPFROMP(zVal)
+ ,MPFROM2SHORT( (USHORT)10
+ ,SPBQ_UPDATEIFVALID
+ )
+ );
+ lVal = atol(zVal);
+ return (int)lVal;
+} // end of wxSpinCtrl::GetValue
+
+void wxSpinCtrl::OnChar (
+ wxKeyEvent& rEvent
+)
+{
+ switch (rEvent.GetKeyCode())
+ {
+ case WXK_RETURN:
+ {
+ wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_ENTER
+ ,m_windowId
+ );
+ wxString sVal = wxGetWindowText(m_hWndBuddy);
+
+ InitCommandEvent(vEvent);
+ vEvent.SetString(sVal);
+ vEvent.SetInt(GetValue());
+ if (GetEventHandler()->ProcessEvent(vEvent))
+ return;
+ 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.
+ //
+ {
+ wxNavigationKeyEvent vEventNav;
+
+ vEventNav.SetDirection(!rEvent.ShiftDown());
+ vEventNav.SetWindowChange(rEvent.ControlDown());
+ vEventNav.SetEventObject(this);
+ if (GetParent()->GetEventHandler()->ProcessEvent(vEventNav))
+ return;
+ }
+ break;