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