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