]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
fixed typo in last commit
[wxWidgets.git] / src / msw / spinbutt.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
2ab30ebf 2// Name: msw/spinbutt.cpp
2bda0e17
KB
3// Purpose: wxSpinButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
b782f2e0
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a23fd0e1 21 #pragma implementation "spinbutt.h"
3c1a88d8 22 #pragma implementation "spinbutbase.h"
2bda0e17
KB
23#endif
24
25// For compilers that support precompilation, includes "wx.h".
26#include "wx/wxprec.h"
27
28#ifdef __BORLANDC__
a23fd0e1 29 #pragma hdrstop
2bda0e17
KB
30#endif
31
32#ifndef WX_PRECOMP
3181cff4 33#include "wx/app.h"
2bda0e17
KB
34#endif
35
0e528b99
JS
36#if wxUSE_SPINBTN
37
c3cb82e1
JS
38#include "wx/spinbutt.h"
39
2fa7c206
JS
40IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
41
b39dbf34 42#if defined(__WIN95__)
2bda0e17 43
2bda0e17
KB
44#include "wx/msw/private.h"
45
b39dbf34 46#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
a23fd0e1 47 #include <commctrl.h>
2bda0e17
KB
48#endif
49
b782f2e0
VZ
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// wxWin macros
56// ----------------------------------------------------------------------------
57
2bda0e17 58
51741307 59#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
60WX_DEFINE_FLAGS( wxSpinButtonStyle )
61
3ff066a4 62wxBEGIN_FLAGS( wxSpinButtonStyle )
bc9fb572
JS
63 // new style border flags, we put them first to
64 // use them for streaming out
3ff066a4
SC
65 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
66 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
67 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
68 wxFLAGS_MEMBER(wxBORDER_RAISED)
69 wxFLAGS_MEMBER(wxBORDER_STATIC)
70 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 71
bc9fb572 72 // old style border flags
3ff066a4
SC
73 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
74 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
75 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
76 wxFLAGS_MEMBER(wxRAISED_BORDER)
77 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 78 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
79
80 // standard window styles
3ff066a4
SC
81 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
82 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
83 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
84 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 85 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
86 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
87 wxFLAGS_MEMBER(wxVSCROLL)
88 wxFLAGS_MEMBER(wxHSCROLL)
89
90 wxFLAGS_MEMBER(wxSP_HORIZONTAL)
91 wxFLAGS_MEMBER(wxSP_VERTICAL)
92 wxFLAGS_MEMBER(wxSP_ARROW_KEYS)
93 wxFLAGS_MEMBER(wxSP_WRAP)
94
95wxEND_FLAGS( wxSpinButtonStyle )
bc9fb572 96
51741307
SC
97IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h")
98
3ff066a4
SC
99wxBEGIN_PROPERTIES_TABLE(wxSpinButton)
100 wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxSpinEvent )
c5ca409b 101
d95de154
WS
102 wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
103 wxPROPERTY( Min , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
104 wxPROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247 105 wxPROPERTY_FLAGS( WindowStyle , wxSpinButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 106wxEND_PROPERTIES_TABLE()
51741307 107
3ff066a4
SC
108wxBEGIN_HANDLERS_TABLE(wxSpinButton)
109wxEND_HANDLERS_TABLE()
51741307 110
57f4f925 111wxCONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
51741307
SC
112#else
113IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
114#endif
115
116
066f1b7a 117
b782f2e0
VZ
118// ----------------------------------------------------------------------------
119// wxSpinButton
120// ----------------------------------------------------------------------------
121
31528cd3
VZ
122bool wxSpinButton::Create(wxWindow *parent,
123 wxWindowID id,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxString& name)
2bda0e17 128{
b782f2e0 129 // basic initialization
d95de154 130 m_windowId = (id == wxID_ANY) ? NewControlId() : id;
2bda0e17 131
b782f2e0 132 SetName(name);
2bda0e17 133
b782f2e0
VZ
134 int x = pos.x;
135 int y = pos.y;
136 int width = size.x;
137 int height = size.y;
2bda0e17 138
b782f2e0 139 m_windowStyle = style;
2bda0e17 140
b782f2e0 141 SetParent(parent);
2bda0e17 142
b782f2e0
VZ
143 // get the right size for the control
144 if ( width <= 0 || height <= 0 )
145 {
146 wxSize size = DoGetBestSize();
147 if ( width <= 0 )
148 width = size.x;
149 if ( height <= 0 )
150 height = size.y;
151 }
2bda0e17 152
b782f2e0
VZ
153 if ( x < 0 )
154 x = 0;
155 if ( y < 0 )
156 y = 0;
157
158 // translate the styles
f6bcfd97 159 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
882a8f40
VZ
160 UDS_NOTHOUSANDS | // never useful, sometimes harmful
161 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0 162
b0766406
JS
163 if ( m_windowStyle & wxCLIP_SIBLINGS )
164 wstyle |= WS_CLIPSIBLINGS;
b782f2e0
VZ
165 if ( m_windowStyle & wxSP_HORIZONTAL )
166 wstyle |= UDS_HORZ;
167 if ( m_windowStyle & wxSP_ARROW_KEYS )
168 wstyle |= UDS_ARROWKEYS;
169 if ( m_windowStyle & wxSP_WRAP )
170 wstyle |= UDS_WRAP;
171
172 // create the UpDown control.
173 m_hWnd = (WXHWND)CreateUpDownControl
174 (
175 wstyle,
176 x, y, width, height,
177 GetHwndOf(parent),
178 m_windowId,
179 wxGetInstance(),
180 NULL, // no buddy
181 m_max, m_min,
182 m_min // initial position
183 );
184
185 if ( !m_hWnd )
186 {
f6bcfd97 187 wxLogLastError(wxT("CreateUpDownControl"));
2bda0e17 188
d95de154 189 return false;
b782f2e0 190 }
2bda0e17 191
b782f2e0
VZ
192 if ( parent )
193 {
194 parent->AddChild(this);
195 }
31528cd3 196
b782f2e0 197 SubclassWin(m_hWnd);
2bda0e17 198
8d2e831b
RD
199 SetBestSize(size);
200
d95de154 201 return true;
2bda0e17
KB
202}
203
a23fd0e1 204wxSpinButton::~wxSpinButton()
2bda0e17
KB
205{
206}
207
b782f2e0
VZ
208// ----------------------------------------------------------------------------
209// size calculation
210// ----------------------------------------------------------------------------
211
f68586e5 212wxSize wxSpinButton::DoGetBestSize() const
b782f2e0 213{
d95de154 214 return GetBestSpinerSize( (GetWindowStyle() & wxSP_VERTICAL) != 0 );
b782f2e0
VZ
215}
216
217// ----------------------------------------------------------------------------
2bda0e17 218// Attributes
b782f2e0 219// ----------------------------------------------------------------------------
2bda0e17 220
a23fd0e1 221int wxSpinButton::GetValue() const
2bda0e17 222{
ad8ddd13 223 int n;
3d9fe7b2
VZ
224#ifdef UDM_GETPOS32
225 if ( wxTheApp->GetComCtl32Version() >= 580 )
226 {
227 // use the full 32 bit range if available
ad8ddd13 228 n = ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
3d9fe7b2 229 }
419c6f40 230 else
3d9fe7b2 231#endif // UDM_GETPOS32
419c6f40
WS
232 {
233 // we're limited to 16 bit
234 n = (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
235 }
3d9fe7b2 236
ad8ddd13
RR
237 if (n < m_min) n = m_min;
238 if (n > m_max) n = m_max;
419c6f40 239
ad8ddd13 240 return n;
2bda0e17
KB
241}
242
debe6624 243void wxSpinButton::SetValue(int val)
2bda0e17 244{
3d9fe7b2
VZ
245 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
246
247#ifdef UDM_SETPOS32
248 if ( wxTheApp->GetComCtl32Version() >= 580 )
249 {
250 // use the full 32 bit range if available
251 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
252 }
253 else // we're limited to 16 bit
254#endif // UDM_SETPOS32
255 {
256 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
257 }
2bda0e17
KB
258}
259
debe6624 260void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 261{
31528cd3 262 wxSpinButtonBase::SetRange(minVal, maxVal);
3d9fe7b2
VZ
263
264#ifdef UDM_SETRANGE32
265 if ( wxTheApp->GetComCtl32Version() >= 471 )
266 {
267 // use the full 32 bit range if available
268 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
269 }
270 else // we're limited to 16 bit
271#endif // UDM_SETRANGE32
272 {
273 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
274 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
275 }
2bda0e17
KB
276}
277
33ac7e6f 278bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
a23fd0e1 279 WXWORD pos, WXHWND control)
2bda0e17 280{
57f4f925 281 wxCHECK_MSG( control, false, wxT("scrolling what?") )
2bda0e17 282
0655ad29 283 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 284 {
0655ad29 285 // probable SB_ENDSCROLL - we don't react to it
d95de154 286 return false;
0655ad29 287 }
2bda0e17 288
0655ad29
VZ
289 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
290 event.SetPosition((short)pos); // cast is important for negative values!
291 event.SetEventObject(this);
2bda0e17 292
0655ad29
VZ
293 return GetEventHandler()->ProcessEvent(event);
294}
2bda0e17 295
33ac7e6f 296bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 297{
be519ffb 298 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
2bda0e17 299
f6bcfd97 300 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
d95de154 301 return false;
f6bcfd97 302
0655ad29
VZ
303 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
304 : wxEVT_SCROLL_LINEDOWN,
305 m_windowId);
306 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
307 event.SetEventObject(this);
2bda0e17 308
0655ad29 309 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 310
0655ad29 311 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 312
0655ad29 313 return processed;
2bda0e17
KB
314}
315
33ac7e6f 316bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 317{
a23fd0e1 318 // No command messages
d95de154 319 return false;
2bda0e17
KB
320}
321
a23fd0e1 322#endif // __WIN95__
0e528b99 323
d95de154 324#endif // wxUSE_SPINBTN