]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
undid WS_EX_CONTROLPARENT change -- I recall now why we can't use it
[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{
3d9fe7b2
VZ
182#ifdef UDM_GETPOS32
183 if ( wxTheApp->GetComCtl32Version() >= 580 )
184 {
185 // use the full 32 bit range if available
186 return ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
187 }
188#endif // UDM_GETPOS32
189
190 // we're limited to 16 bit
0655ad29 191 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
192}
193
debe6624 194void wxSpinButton::SetValue(int val)
2bda0e17 195{
3d9fe7b2
VZ
196 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
197
198#ifdef UDM_SETPOS32
199 if ( wxTheApp->GetComCtl32Version() >= 580 )
200 {
201 // use the full 32 bit range if available
202 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
203 }
204 else // we're limited to 16 bit
205#endif // UDM_SETPOS32
206 {
207 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
208 }
2bda0e17
KB
209}
210
debe6624 211void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 212{
31528cd3 213 wxSpinButtonBase::SetRange(minVal, maxVal);
3d9fe7b2
VZ
214
215#ifdef UDM_SETRANGE32
216 if ( wxTheApp->GetComCtl32Version() >= 471 )
217 {
218 // use the full 32 bit range if available
219 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
220 }
221 else // we're limited to 16 bit
222#endif // UDM_SETRANGE32
223 {
224 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
225 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
226 }
2bda0e17
KB
227}
228
33ac7e6f 229bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
a23fd0e1 230 WXWORD pos, WXHWND control)
2bda0e17 231{
223d09f6 232 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
2bda0e17 233
0655ad29 234 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 235 {
0655ad29
VZ
236 // probable SB_ENDSCROLL - we don't react to it
237 return FALSE;
238 }
2bda0e17 239
0655ad29
VZ
240 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
241 event.SetPosition((short)pos); // cast is important for negative values!
242 event.SetEventObject(this);
2bda0e17 243
0655ad29
VZ
244 return GetEventHandler()->ProcessEvent(event);
245}
2bda0e17 246
33ac7e6f 247bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 248{
83475efc 249 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
2bda0e17 250
f6bcfd97
BP
251 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
252 return FALSE;
253
0655ad29
VZ
254 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
255 : wxEVT_SCROLL_LINEDOWN,
256 m_windowId);
257 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
258 event.SetEventObject(this);
2bda0e17 259
0655ad29 260 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 261
0655ad29 262 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 263
0655ad29 264 return processed;
2bda0e17
KB
265}
266
33ac7e6f 267bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 268{
a23fd0e1
VZ
269 // No command messages
270 return FALSE;
2bda0e17
KB
271}
272
a23fd0e1 273#endif // __WIN95__
0e528b99
JS
274
275#endif
276 // wxUSE_SPINCTN
277