]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
Set missing Language: headers in PO files.
[wxWidgets.git] / src / msw / spinbutt.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/msw/spinbutt.cpp
2bda0e17
KB
3// Purpose: wxSpinButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
6c9a19aa 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
b782f2e0
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2bda0e17
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
a23fd0e1 23 #pragma hdrstop
2bda0e17
KB
24#endif
25
26#ifndef WX_PRECOMP
57bd4c60 27 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
670f9935 28 #include "wx/app.h"
2bda0e17
KB
29#endif
30
0e528b99
JS
31#if wxUSE_SPINBTN
32
c3cb82e1
JS
33#include "wx/spinbutt.h"
34
2bda0e17 35#include "wx/msw/private.h"
2bda0e17 36
0aed4008
VZ
37#ifndef UDM_SETRANGE32
38 #define UDM_SETRANGE32 (WM_USER+111)
39#endif
40
41#ifndef UDM_SETPOS32
42 #define UDM_SETPOS32 (WM_USER+113)
43 #define UDM_GETPOS32 (WM_USER+114)
44#endif
45
b782f2e0
VZ
46// ============================================================================
47// implementation
48// ============================================================================
49
50// ----------------------------------------------------------------------------
51// wxWin macros
52// ----------------------------------------------------------------------------
53
b782f2e0
VZ
54// ----------------------------------------------------------------------------
55// wxSpinButton
56// ----------------------------------------------------------------------------
57
31528cd3
VZ
58bool wxSpinButton::Create(wxWindow *parent,
59 wxWindowID id,
60 const wxPoint& pos,
61 const wxSize& size,
62 long style,
63 const wxString& name)
2bda0e17 64{
b782f2e0 65 // basic initialization
d95de154 66 m_windowId = (id == wxID_ANY) ? NewControlId() : id;
2bda0e17 67
b782f2e0 68 SetName(name);
2bda0e17 69
b782f2e0
VZ
70 int x = pos.x;
71 int y = pos.y;
72 int width = size.x;
73 int height = size.y;
2bda0e17 74
b782f2e0 75 m_windowStyle = style;
2bda0e17 76
b782f2e0 77 SetParent(parent);
2bda0e17 78
b782f2e0
VZ
79 // get the right size for the control
80 if ( width <= 0 || height <= 0 )
81 {
82 wxSize size = DoGetBestSize();
83 if ( width <= 0 )
84 width = size.x;
85 if ( height <= 0 )
86 height = size.y;
87 }
2bda0e17 88
b782f2e0
VZ
89 if ( x < 0 )
90 x = 0;
91 if ( y < 0 )
92 y = 0;
93
94 // translate the styles
f6bcfd97 95 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
882a8f40
VZ
96 UDS_NOTHOUSANDS | // never useful, sometimes harmful
97 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0 98
b0766406
JS
99 if ( m_windowStyle & wxCLIP_SIBLINGS )
100 wstyle |= WS_CLIPSIBLINGS;
b782f2e0
VZ
101 if ( m_windowStyle & wxSP_HORIZONTAL )
102 wstyle |= UDS_HORZ;
103 if ( m_windowStyle & wxSP_ARROW_KEYS )
104 wstyle |= UDS_ARROWKEYS;
105 if ( m_windowStyle & wxSP_WRAP )
106 wstyle |= UDS_WRAP;
107
108 // create the UpDown control.
109 m_hWnd = (WXHWND)CreateUpDownControl
110 (
111 wstyle,
112 x, y, width, height,
113 GetHwndOf(parent),
114 m_windowId,
115 wxGetInstance(),
116 NULL, // no buddy
117 m_max, m_min,
118 m_min // initial position
119 );
120
121 if ( !m_hWnd )
122 {
f6bcfd97 123 wxLogLastError(wxT("CreateUpDownControl"));
2bda0e17 124
d95de154 125 return false;
b782f2e0 126 }
2bda0e17 127
b782f2e0
VZ
128 if ( parent )
129 {
130 parent->AddChild(this);
131 }
31528cd3 132
b782f2e0 133 SubclassWin(m_hWnd);
2bda0e17 134
170acdc9 135 SetInitialSize(size);
8d2e831b 136
d95de154 137 return true;
2bda0e17
KB
138}
139
a23fd0e1 140wxSpinButton::~wxSpinButton()
2bda0e17
KB
141{
142}
143
b782f2e0
VZ
144// ----------------------------------------------------------------------------
145// size calculation
146// ----------------------------------------------------------------------------
147
f68586e5 148wxSize wxSpinButton::DoGetBestSize() const
b782f2e0 149{
5aaabb37 150 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL) != 0 );
b782f2e0
VZ
151}
152
153// ----------------------------------------------------------------------------
2bda0e17 154// Attributes
b782f2e0 155// ----------------------------------------------------------------------------
2bda0e17 156
a23fd0e1 157int wxSpinButton::GetValue() const
2bda0e17 158{
ad8ddd13 159 int n;
3d9fe7b2 160#ifdef UDM_GETPOS32
5625d0d4 161 if ( wxApp::GetComCtl32Version() >= 580 )
3d9fe7b2
VZ
162 {
163 // use the full 32 bit range if available
ad8ddd13 164 n = ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
3d9fe7b2 165 }
419c6f40 166 else
3d9fe7b2 167#endif // UDM_GETPOS32
419c6f40
WS
168 {
169 // we're limited to 16 bit
170 n = (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
171 }
3d9fe7b2 172
ad8ddd13
RR
173 if (n < m_min) n = m_min;
174 if (n > m_max) n = m_max;
419c6f40 175
ad8ddd13 176 return n;
2bda0e17
KB
177}
178
debe6624 179void wxSpinButton::SetValue(int val)
2bda0e17 180{
3d9fe7b2
VZ
181 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
182
183#ifdef UDM_SETPOS32
5625d0d4 184 if ( wxApp::GetComCtl32Version() >= 580 )
3d9fe7b2
VZ
185 {
186 // use the full 32 bit range if available
187 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
188 }
189 else // we're limited to 16 bit
190#endif // UDM_SETPOS32
191 {
192 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
193 }
2bda0e17
KB
194}
195
1e8dba5e 196void wxSpinButton::NormalizeValue()
f4322df6 197{
1e8dba5e
RR
198 SetValue( GetValue() );
199}
200
debe6624 201void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 202{
93232499
VZ
203 const bool hadRange = m_min < m_max;
204
31528cd3 205 wxSpinButtonBase::SetRange(minVal, maxVal);
3d9fe7b2
VZ
206
207#ifdef UDM_SETRANGE32
2a1f999f 208 if ( wxApp::GetComCtl32Version() >= 471 )
3d9fe7b2
VZ
209 {
210 // use the full 32 bit range if available
211 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
212 }
213 else // we're limited to 16 bit
214#endif // UDM_SETRANGE32
215 {
216 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
217 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
218 }
93232499
VZ
219
220 // the current value might be out of the new range, force it to be in it
221 NormalizeValue();
222
223 // if range was valid but becomes degenerated (min == max) now or vice
224 // versa then the spin buttons are automatically disabled/enabled back
225 // but don't update themselves for some reason, so do it manually
226 if ( hadRange != (m_min < m_max) )
227 {
228 // update the visual state of the button
229 Refresh();
230 }
2bda0e17
KB
231}
232
33ac7e6f 233bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
63420bcc 234 WXWORD WXUNUSED(pos), WXHWND control)
2bda0e17 235{
637b7e4f 236 wxCHECK_MSG( control, false, wxT("scrolling what?") );
2bda0e17 237
0655ad29 238 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 239 {
0655ad29 240 // probable SB_ENDSCROLL - we don't react to it
d95de154 241 return false;
0655ad29 242 }
2bda0e17 243
0655ad29 244 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
63420bcc
VZ
245 // We can't use 16 bit position provided in this message for spin buttons
246 // using 32 bit range.
247 event.SetPosition(GetValue());
0655ad29 248 event.SetEventObject(this);
2bda0e17 249
937013e0 250 return HandleWindowEvent(event);
0655ad29 251}
2bda0e17 252
33ac7e6f 253bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 254{
be519ffb 255 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
2bda0e17 256
f6bcfd97 257 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
d95de154 258 return false;
f6bcfd97 259
0655ad29
VZ
260 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
261 : wxEVT_SCROLL_LINEDOWN,
262 m_windowId);
263 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
264 event.SetEventObject(this);
2bda0e17 265
937013e0 266 bool processed = HandleWindowEvent(event);
2bda0e17 267
0655ad29 268 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 269
0655ad29 270 return processed;
2bda0e17
KB
271}
272
33ac7e6f 273bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 274{
a23fd0e1 275 // No command messages
d95de154 276 return false;
2bda0e17
KB
277}
278
d95de154 279#endif // wxUSE_SPINBTN