]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
288b12374e88d27fb1145d746d90c5a792c52ee4
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxSpinButton 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "spinbutt.h" 
  22     #pragma implementation "spinbutbase.h" 
  25 // For compilers that support precompilation, includes "wx.h". 
  26 #include "wx/wxprec.h" 
  36 // Can't resolve reference to CreateUpDownControl in 
  37 // TWIN32, but could probably use normal CreateWindow instead. 
  41 #if defined(__WIN95__) && !defined(__TWIN32__) 
  43 #include "wx/spinbutt.h" 
  44 #include "wx/msw/private.h" 
  46 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) 
  50 // ============================================================================ 
  52 // ============================================================================ 
  54 // ---------------------------------------------------------------------------- 
  56 // ---------------------------------------------------------------------------- 
  58 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
) 
  59 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
); 
  61 // ---------------------------------------------------------------------------- 
  63 // ---------------------------------------------------------------------------- 
  65 bool wxSpinButton::Create(wxWindow 
*parent
, 
  72     // basic initialization 
  75     m_windowId 
= (id 
== -1) ? NewControlId() : id
; 
  77     m_backgroundColour 
= parent
->GetBackgroundColour() ; 
  78     m_foregroundColour 
= parent
->GetForegroundColour() ; 
  87     m_windowStyle 
= style
; 
  91     // get the right size for the control 
  92     if ( width 
<= 0 || height 
<= 0 ) 
  94         wxSize size 
= DoGetBestSize(); 
 106     // translate the styles 
 107     DWORD wstyle 
= WS_VISIBLE 
| WS_CHILD 
| WS_TABSTOP 
| 
 108                    UDS_NOTHOUSANDS 
| // never useful, sometimes harmful 
 109                    UDS_SETBUDDYINT
;  // it doesn't harm if we don't have buddy 
 111     if ( m_windowStyle 
& wxSP_HORIZONTAL 
) 
 113     if ( m_windowStyle 
& wxSP_ARROW_KEYS 
) 
 114         wstyle 
|= UDS_ARROWKEYS
; 
 115     if ( m_windowStyle 
& wxSP_WRAP 
) 
 118     // create the UpDown control. 
 119     m_hWnd 
= (WXHWND
)CreateUpDownControl
 
 128                        m_min 
// initial position 
 133         wxLogLastError("CreateUpDownControl"); 
 140         parent
->AddChild(this); 
 148 wxSpinButton::~wxSpinButton() 
 152 // ---------------------------------------------------------------------------- 
 154 // ---------------------------------------------------------------------------- 
 156 wxSize 
wxSpinButton::DoGetBestSize() const 
 158     if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 ) 
 161         return wxSize(GetSystemMetrics(SM_CXVSCROLL
), 
 162                       2*GetSystemMetrics(SM_CYVSCROLL
)); 
 166         // horizontal control 
 167         return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
), 
 168                       GetSystemMetrics(SM_CYHSCROLL
)); 
 172 // ---------------------------------------------------------------------------- 
 174 // ---------------------------------------------------------------------------- 
 176 int wxSpinButton::GetValue() const 
 178     return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0)); 
 181 void wxSpinButton::SetValue(int val
) 
 183     ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0)); 
 186 void wxSpinButton::SetRange(int minVal
, int maxVal
) 
 188     wxSpinButtonBase::SetRange(minVal
, maxVal
); 
 189     ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0, 
 190                    (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
)); 
 193 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
, 
 194                                WXWORD pos
, WXHWND control
) 
 196     wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") ) 
 198     if ( wParam 
!= SB_THUMBPOSITION 
) 
 200         // probable SB_ENDSCROLL - we don't react to it 
 204     wxSpinEvent 
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
); 
 205     event
.SetPosition((short)pos
);    // cast is important for negative values! 
 206     event
.SetEventObject(this); 
 208     return GetEventHandler()->ProcessEvent(event
); 
 211 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM 
*result
) 
 214 #if defined(__BORLANDC__) || defined(__WATCOMC__) 
 215     LPNM_UPDOWN lpnmud 
= (LPNM_UPDOWN
)lParam
; 
 216 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020) 
 217     LPNM_UPDOWN lpnmud 
= (LPNM_UPDOWN
)lParam
; 
 219     LPNMUPDOWN lpnmud 
= (LPNMUPDOWN
)lParam
; 
 222     wxSpinEvent 
event(lpnmud
->iDelta 
> 0 ? wxEVT_SCROLL_LINEUP
 
 223                                          : wxEVT_SCROLL_LINEDOWN
, 
 225     event
.SetPosition(lpnmud
->iPos 
+ lpnmud
->iDelta
); 
 226     event
.SetEventObject(this); 
 228     bool processed 
= GetEventHandler()->ProcessEvent(event
); 
 230     *result 
= event
.IsAllowed() ? 0 : 1; 
 238 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
) 
 240     // No command messages