]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
Moved wxToolBarSimple to deprecated library
[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
JS
8// Copyright: (c) Julian Smart
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
SC
59#if wxUSE_EXTENDED_RTTI
60IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h")
61
62WX_BEGIN_PROPERTIES_TABLE(wxSpinButton)
63 WX_PROPERTY( Value , int , SetValue, GetValue, 0 )
64 WX_PROPERTY( Min , int , SetMin, GetMin, 0 )
65 WX_PROPERTY( Max , int , SetMax, GetMax, 0 )
066f1b7a
SC
66/*
67 TODO PROPERTIES
066f1b7a 68 style wxSP_VERTICAL | wxSP_ARROW_KEYS
066f1b7a 69*/
51741307
SC
70WX_END_PROPERTIES_TABLE()
71
72WX_BEGIN_HANDLERS_TABLE(wxSpinButton)
73WX_END_HANDLERS_TABLE()
74
75WX_CONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
76#else
77IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
78#endif
79
80
066f1b7a 81
b782f2e0
VZ
82// ----------------------------------------------------------------------------
83// wxSpinButton
84// ----------------------------------------------------------------------------
85
31528cd3
VZ
86bool wxSpinButton::Create(wxWindow *parent,
87 wxWindowID id,
88 const wxPoint& pos,
89 const wxSize& size,
90 long style,
91 const wxString& name)
2bda0e17 92{
b782f2e0
VZ
93 // basic initialization
94 InitBase();
2bda0e17 95
b782f2e0 96 m_windowId = (id == -1) ? NewControlId() : id;
2bda0e17 97
b782f2e0
VZ
98 m_backgroundColour = parent->GetBackgroundColour() ;
99 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17 100
b782f2e0 101 SetName(name);
2bda0e17 102
b782f2e0
VZ
103 int x = pos.x;
104 int y = pos.y;
105 int width = size.x;
106 int height = size.y;
2bda0e17 107
b782f2e0 108 m_windowStyle = style;
2bda0e17 109
b782f2e0 110 SetParent(parent);
2bda0e17 111
b782f2e0
VZ
112 // get the right size for the control
113 if ( width <= 0 || height <= 0 )
114 {
115 wxSize size = DoGetBestSize();
116 if ( width <= 0 )
117 width = size.x;
118 if ( height <= 0 )
119 height = size.y;
120 }
2bda0e17 121
b782f2e0
VZ
122 if ( x < 0 )
123 x = 0;
124 if ( y < 0 )
125 y = 0;
126
127 // translate the styles
f6bcfd97 128 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
882a8f40
VZ
129 UDS_NOTHOUSANDS | // never useful, sometimes harmful
130 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0 131
b0766406
JS
132 if ( m_windowStyle & wxCLIP_SIBLINGS )
133 wstyle |= WS_CLIPSIBLINGS;
b782f2e0
VZ
134 if ( m_windowStyle & wxSP_HORIZONTAL )
135 wstyle |= UDS_HORZ;
136 if ( m_windowStyle & wxSP_ARROW_KEYS )
137 wstyle |= UDS_ARROWKEYS;
138 if ( m_windowStyle & wxSP_WRAP )
139 wstyle |= UDS_WRAP;
140
141 // create the UpDown control.
142 m_hWnd = (WXHWND)CreateUpDownControl
143 (
144 wstyle,
145 x, y, width, height,
146 GetHwndOf(parent),
147 m_windowId,
148 wxGetInstance(),
149 NULL, // no buddy
150 m_max, m_min,
151 m_min // initial position
152 );
153
154 if ( !m_hWnd )
155 {
f6bcfd97 156 wxLogLastError(wxT("CreateUpDownControl"));
2bda0e17 157
b782f2e0
VZ
158 return FALSE;
159 }
2bda0e17 160
b782f2e0
VZ
161 if ( parent )
162 {
163 parent->AddChild(this);
164 }
31528cd3 165
b782f2e0 166 SubclassWin(m_hWnd);
2bda0e17 167
b782f2e0 168 return TRUE;
2bda0e17
KB
169}
170
a23fd0e1 171wxSpinButton::~wxSpinButton()
2bda0e17
KB
172{
173}
174
b782f2e0
VZ
175// ----------------------------------------------------------------------------
176// size calculation
177// ----------------------------------------------------------------------------
178
f68586e5 179wxSize wxSpinButton::DoGetBestSize() const
b782f2e0
VZ
180{
181 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
182 {
183 // vertical control
184 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
185 2*GetSystemMetrics(SM_CYVSCROLL));
186 }
187 else
188 {
189 // horizontal control
190 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
191 GetSystemMetrics(SM_CYHSCROLL));
192 }
193}
194
195// ----------------------------------------------------------------------------
2bda0e17 196// Attributes
b782f2e0 197// ----------------------------------------------------------------------------
2bda0e17 198
a23fd0e1 199int wxSpinButton::GetValue() const
2bda0e17 200{
3d9fe7b2
VZ
201#ifdef UDM_GETPOS32
202 if ( wxTheApp->GetComCtl32Version() >= 580 )
203 {
204 // use the full 32 bit range if available
205 return ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
206 }
207#endif // UDM_GETPOS32
208
209 // we're limited to 16 bit
0655ad29 210 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
211}
212
debe6624 213void wxSpinButton::SetValue(int val)
2bda0e17 214{
3d9fe7b2
VZ
215 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
216
217#ifdef UDM_SETPOS32
218 if ( wxTheApp->GetComCtl32Version() >= 580 )
219 {
220 // use the full 32 bit range if available
221 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
222 }
223 else // we're limited to 16 bit
224#endif // UDM_SETPOS32
225 {
226 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
227 }
2bda0e17
KB
228}
229
debe6624 230void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 231{
31528cd3 232 wxSpinButtonBase::SetRange(minVal, maxVal);
3d9fe7b2
VZ
233
234#ifdef UDM_SETRANGE32
235 if ( wxTheApp->GetComCtl32Version() >= 471 )
236 {
237 // use the full 32 bit range if available
238 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
239 }
240 else // we're limited to 16 bit
241#endif // UDM_SETRANGE32
242 {
243 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
244 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
245 }
2bda0e17
KB
246}
247
33ac7e6f 248bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
a23fd0e1 249 WXWORD pos, WXHWND control)
2bda0e17 250{
223d09f6 251 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
2bda0e17 252
0655ad29 253 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 254 {
0655ad29
VZ
255 // probable SB_ENDSCROLL - we don't react to it
256 return FALSE;
257 }
2bda0e17 258
0655ad29
VZ
259 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
260 event.SetPosition((short)pos); // cast is important for negative values!
261 event.SetEventObject(this);
2bda0e17 262
0655ad29
VZ
263 return GetEventHandler()->ProcessEvent(event);
264}
2bda0e17 265
33ac7e6f 266bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 267{
be519ffb 268 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
2bda0e17 269
f6bcfd97
BP
270 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
271 return FALSE;
272
0655ad29
VZ
273 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
274 : wxEVT_SCROLL_LINEDOWN,
275 m_windowId);
276 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
277 event.SetEventObject(this);
2bda0e17 278
0655ad29 279 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 280
0655ad29 281 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 282
0655ad29 283 return processed;
2bda0e17
KB
284}
285
33ac7e6f 286bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 287{
a23fd0e1
VZ
288 // No command messages
289 return FALSE;
2bda0e17
KB
290}
291
a23fd0e1 292#endif // __WIN95__
0e528b99
JS
293
294#endif
295 // wxUSE_SPINCTN
296