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