]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
wxSizeEvent now carries the total size, not just the client size
[wxWidgets.git] / src / msw / spinbutt.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
a23fd0e1 9// Licence: wxWindows license
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
a23fd0e1 33 #include "wx/wx.h"
2bda0e17
KB
34#endif
35
57c208c5
JS
36// Can't resolve reference to CreateUpDownControl in
37// TWIN32, but could probably use normal CreateWindow instead.
38
0e528b99
JS
39#if wxUSE_SPINBTN
40
c3cb82e1
JS
41#include "wx/spinbutt.h"
42
2fa7c206
JS
43IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
44
57c208c5 45#if defined(__WIN95__) && !defined(__TWIN32__)
2bda0e17 46
2bda0e17
KB
47#include "wx/msw/private.h"
48
ae090fdb 49#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
a23fd0e1 50 #include <commctrl.h>
2bda0e17
KB
51#endif
52
b782f2e0
VZ
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// wxWin macros
59// ----------------------------------------------------------------------------
60
9750fc42 61IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
2bda0e17 62
b782f2e0
VZ
63// ----------------------------------------------------------------------------
64// wxSpinButton
65// ----------------------------------------------------------------------------
66
31528cd3
VZ
67bool wxSpinButton::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxString& name)
2bda0e17 73{
b782f2e0
VZ
74 // basic initialization
75 InitBase();
2bda0e17 76
b782f2e0 77 m_windowId = (id == -1) ? NewControlId() : id;
2bda0e17 78
b782f2e0
VZ
79 m_backgroundColour = parent->GetBackgroundColour() ;
80 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17 81
b782f2e0 82 SetName(name);
2bda0e17 83
b782f2e0
VZ
84 int x = pos.x;
85 int y = pos.y;
86 int width = size.x;
87 int height = size.y;
2bda0e17 88
b782f2e0 89 m_windowStyle = style;
2bda0e17 90
b782f2e0 91 SetParent(parent);
2bda0e17 92
b782f2e0
VZ
93 // get the right size for the control
94 if ( width <= 0 || height <= 0 )
95 {
96 wxSize size = DoGetBestSize();
97 if ( width <= 0 )
98 width = size.x;
99 if ( height <= 0 )
100 height = size.y;
101 }
2bda0e17 102
b782f2e0
VZ
103 if ( x < 0 )
104 x = 0;
105 if ( y < 0 )
106 y = 0;
107
108 // translate the styles
f6bcfd97 109 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
882a8f40
VZ
110 UDS_NOTHOUSANDS | // never useful, sometimes harmful
111 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0 112
b0766406
JS
113 if ( m_windowStyle & wxCLIP_SIBLINGS )
114 wstyle |= WS_CLIPSIBLINGS;
b782f2e0
VZ
115 if ( m_windowStyle & wxSP_HORIZONTAL )
116 wstyle |= UDS_HORZ;
117 if ( m_windowStyle & wxSP_ARROW_KEYS )
118 wstyle |= UDS_ARROWKEYS;
119 if ( m_windowStyle & wxSP_WRAP )
120 wstyle |= UDS_WRAP;
121
122 // create the UpDown control.
123 m_hWnd = (WXHWND)CreateUpDownControl
124 (
125 wstyle,
126 x, y, width, height,
127 GetHwndOf(parent),
128 m_windowId,
129 wxGetInstance(),
130 NULL, // no buddy
131 m_max, m_min,
132 m_min // initial position
133 );
134
135 if ( !m_hWnd )
136 {
f6bcfd97 137 wxLogLastError(wxT("CreateUpDownControl"));
2bda0e17 138
b782f2e0
VZ
139 return FALSE;
140 }
2bda0e17 141
b782f2e0
VZ
142 if ( parent )
143 {
144 parent->AddChild(this);
145 }
31528cd3 146
b782f2e0 147 SubclassWin(m_hWnd);
2bda0e17 148
b782f2e0 149 return TRUE;
2bda0e17
KB
150}
151
a23fd0e1 152wxSpinButton::~wxSpinButton()
2bda0e17
KB
153{
154}
155
b782f2e0
VZ
156// ----------------------------------------------------------------------------
157// size calculation
158// ----------------------------------------------------------------------------
159
f68586e5 160wxSize wxSpinButton::DoGetBestSize() const
b782f2e0
VZ
161{
162 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
163 {
164 // vertical control
165 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
166 2*GetSystemMetrics(SM_CYVSCROLL));
167 }
168 else
169 {
170 // horizontal control
171 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
172 GetSystemMetrics(SM_CYHSCROLL));
173 }
174}
175
176// ----------------------------------------------------------------------------
2bda0e17 177// Attributes
b782f2e0 178// ----------------------------------------------------------------------------
2bda0e17 179
a23fd0e1 180int wxSpinButton::GetValue() const
2bda0e17 181{
0655ad29 182 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
183}
184
debe6624 185void wxSpinButton::SetValue(int val)
2bda0e17 186{
d1d7cdff 187 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
2bda0e17
KB
188}
189
debe6624 190void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 191{
31528cd3 192 wxSpinButtonBase::SetRange(minVal, maxVal);
d1d7cdff 193 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
3d7e30a4 194 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
2bda0e17
KB
195}
196
33ac7e6f 197bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
a23fd0e1 198 WXWORD pos, WXHWND control)
2bda0e17 199{
223d09f6 200 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
2bda0e17 201
0655ad29 202 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 203 {
0655ad29
VZ
204 // probable SB_ENDSCROLL - we don't react to it
205 return FALSE;
206 }
2bda0e17 207
0655ad29
VZ
208 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
209 event.SetPosition((short)pos); // cast is important for negative values!
210 event.SetEventObject(this);
2bda0e17 211
0655ad29
VZ
212 return GetEventHandler()->ProcessEvent(event);
213}
2bda0e17 214
33ac7e6f 215bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 216{
8a4df159 217#ifndef __GNUWIN32__
0cdf89ab 218#if defined(__BORLANDC__) || defined(__WATCOMC__)
83475efc 219 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
6474416b 220#elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
2996bcde 221 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
83475efc 222#else
0655ad29 223 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
83475efc 224#endif
2bda0e17 225
f6bcfd97
BP
226 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
227 return FALSE;
228
0655ad29
VZ
229 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
230 : wxEVT_SCROLL_LINEDOWN,
231 m_windowId);
232 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
233 event.SetEventObject(this);
2bda0e17 234
0655ad29 235 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 236
0655ad29 237 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 238
0655ad29 239 return processed;
b782f2e0 240#else // GnuWin32
8a4df159
RR
241 return FALSE;
242#endif
2bda0e17
KB
243}
244
33ac7e6f 245bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 246{
a23fd0e1
VZ
247 // No command messages
248 return FALSE;
2bda0e17
KB
249}
250
a23fd0e1 251#endif // __WIN95__
0e528b99
JS
252
253#endif
254 // wxUSE_SPINCTN
255