]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
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 #include "wx/spinbutt.h"
43 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
45 #if defined(__WIN95__) && !defined(__TWIN32__)
47 #include "wx/msw/private.h"
49 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 bool wxSpinButton::Create(wxWindow
*parent
,
74 // basic initialization
77 m_windowId
= (id
== -1) ? NewControlId() : id
;
79 m_backgroundColour
= parent
->GetBackgroundColour() ;
80 m_foregroundColour
= parent
->GetForegroundColour() ;
89 m_windowStyle
= style
;
93 // get the right size for the control
94 if ( width
<= 0 || height
<= 0 )
96 wxSize size
= DoGetBestSize();
108 // translate the styles
109 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
110 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
111 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
113 if ( m_windowStyle
& wxSP_HORIZONTAL
)
115 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
116 wstyle
|= UDS_ARROWKEYS
;
117 if ( m_windowStyle
& wxSP_WRAP
)
120 // create the UpDown control.
121 m_hWnd
= (WXHWND
)CreateUpDownControl
130 m_min
// initial position
135 wxLogLastError(wxT("CreateUpDownControl"));
142 parent
->AddChild(this);
150 wxSpinButton::~wxSpinButton()
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 wxSize
wxSpinButton::DoGetBestSize() const
160 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
163 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
164 2*GetSystemMetrics(SM_CYVSCROLL
));
168 // horizontal control
169 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
170 GetSystemMetrics(SM_CYHSCROLL
));
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 int wxSpinButton::GetValue() const
180 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
183 void wxSpinButton::SetValue(int val
)
185 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, (LPARAM
) MAKELONG((short) val
, 0));
188 void wxSpinButton::SetRange(int minVal
, int maxVal
)
190 wxSpinButtonBase::SetRange(minVal
, maxVal
);
191 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
192 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
195 bool wxSpinButton::MSWOnScroll(int orientation
, WXWORD wParam
,
196 WXWORD pos
, WXHWND control
)
198 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
200 if ( wParam
!= SB_THUMBPOSITION
)
202 // probable SB_ENDSCROLL - we don't react to it
206 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
207 event
.SetPosition((short)pos
); // cast is important for negative values!
208 event
.SetEventObject(this);
210 return GetEventHandler()->ProcessEvent(event
);
213 bool wxSpinButton::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
216 #if defined(__BORLANDC__) || defined(__WATCOMC__)
217 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
218 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
219 LPNM_UPDOWN lpnmud
= (LPNM_UPDOWN
)lParam
;
221 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
224 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
227 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
228 : wxEVT_SCROLL_LINEDOWN
,
230 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
231 event
.SetEventObject(this);
233 bool processed
= GetEventHandler()->ProcessEvent(event
);
235 *result
= event
.IsAllowed() ? 0 : 1;
243 bool wxSpinButton::MSWCommand(WXUINT cmd
, WXWORD id
)
245 // No command messages