]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinbutt.cpp
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"
37 #include "wx/spinbutt.h"
39 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
41 // Can't resolve reference to CreateUpDownControl in
42 // TWIN32, but could probably use normal CreateWindow instead.
43 #if defined(__WIN95__) && !defined(__TWIN32__)
45 #include "wx/msw/private.h"
47 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
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
| /* WS_CLIPSIBLINGS | */
108 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
109 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
111 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
112 wstyle
|= WS_CLIPSIBLINGS
;
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
181 if ( wxTheApp
->GetComCtl32Version() >= 580 )
183 // use the full 32 bit range if available
184 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
186 #endif // UDM_GETPOS32
188 // we're limited to 16 bit
189 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
192 void wxSpinButton::SetValue(int val
)
194 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
197 if ( wxTheApp
->GetComCtl32Version() >= 580 )
199 // use the full 32 bit range if available
200 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
202 else // we're limited to 16 bit
203 #endif // UDM_SETPOS32
205 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
209 void wxSpinButton::SetRange(int minVal
, int maxVal
)
211 wxSpinButtonBase::SetRange(minVal
, maxVal
);
213 #ifdef UDM_SETRANGE32
214 if ( wxTheApp
->GetComCtl32Version() >= 471 )
216 // use the full 32 bit range if available
217 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
219 else // we're limited to 16 bit
220 #endif // UDM_SETRANGE32
222 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
223 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
227 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
228 WXWORD pos
, WXHWND control
)
230 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
232 if ( wParam
!= SB_THUMBPOSITION
)
234 // probable SB_ENDSCROLL - we don't react to it
238 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
239 event
.SetPosition((short)pos
); // cast is important for negative values!
240 event
.SetEventObject(this);
242 return GetEventHandler()->ProcessEvent(event
);
245 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
247 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
249 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
252 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
253 : wxEVT_SCROLL_LINEDOWN
,
255 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
256 event
.SetEventObject(this);
258 bool processed
= GetEventHandler()->ProcessEvent(event
);
260 *result
= event
.IsAllowed() ? 0 : 1;
265 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
267 // No command messages