]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
Dialog Editor corrections for latest wxWin changes; removed wxProp files
[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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx.h"
25#endif
26
27#if defined(__WIN95__)
28
29#include "wx/spinbutt.h"
30#include "wx/msw/private.h"
31
32#ifndef __GNUWIN32__
33#include <commctrl.h>
34#endif
35
36#if !USE_SHARED_LIBRARY
37IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
38#endif
39
40wxSpinButton::wxSpinButton(void)
41{
42 m_min = 0;
43 m_max = 100;
44}
45
debe6624
JS
46bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
47 long style, const wxString& name)
2bda0e17
KB
48{
49 wxSystemSettings settings;
fd71308f
JS
50 m_backgroundColour = parent->GetBackgroundColour() ;
51 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17
KB
52
53 SetName(name);
54
55 int x = pos.x;
56 int y = pos.y;
57 int width = size.x;
58 int height = size.y;
59
60 m_windowStyle = style;
61
62 SetParent(parent);
63
64 if (width <= 0)
65 width = 100;
66 if (height <= 0)
67 height = 30;
68 if (x < 0)
69 x = 0;
70 if (y < 0)
71 y = 0;
72
73 m_min = 0;
74 m_max = 100;
75
76 m_windowId = (id == -1) ? NewControlId() : id;
77
78 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
79
80 if ( m_windowStyle & wxSP_HORIZONTAL )
81 wstyle |= UDS_HORZ;
82 if ( m_windowStyle & wxSP_ARROW_KEYS )
83 wstyle |= UDS_ARROWKEYS;
84 if ( m_windowStyle & wxSP_WRAP )
85 wstyle |= UDS_WRAP;
86
87 // Create the ListView control.
88 HWND hWndListControl = CreateUpDownControl(wstyle,
89 x, y, width, height,
90 (HWND) parent->GetHWND(),
91 m_windowId,
92 wxGetInstance(),
93 0,
3d7e30a4 94 m_min, m_max, m_min);
2bda0e17
KB
95
96 m_hWnd = (WXHWND) hWndListControl;
97 if (parent) parent->AddChild(this);
98
99 // TODO: have this for all controls.
100 if ( !m_hWnd )
101 return FALSE;
102
103 SubclassWin((WXHWND) m_hWnd);
104
105 return TRUE;
106}
107
108wxSpinButton::~wxSpinButton(void)
109{
110}
111
112// Attributes
113////////////////////////////////////////////////////////////////////////////
114
115int wxSpinButton::GetValue(void) const
116{
117 return (int) ::SendMessage((HWND) GetHWND(), UDM_GETPOS, 0, 0);
118}
119
debe6624 120void wxSpinButton::SetValue(int val)
2bda0e17
KB
121{
122 ::SendMessage((HWND) GetHWND(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
123}
124
debe6624 125void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17
KB
126{
127 m_min = minVal;
128 m_max = maxVal;
3d7e30a4
VZ
129 ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0,
130 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
2bda0e17
KB
131}
132
debe6624 133void wxSpinButton::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control)
2bda0e17
KB
134{
135 if (control)
136 {
7798a18e 137 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17
KB
138 event.SetPosition(pos);
139 event.SetOrientation(wxVERTICAL);
140 event.SetEventObject( this );
141
142 switch ( wParam )
143 {
144 case SB_TOP:
145 event.m_eventType = wxEVT_SCROLL_TOP;
146 break;
147
148 case SB_BOTTOM:
149 event.m_eventType = wxEVT_SCROLL_BOTTOM;
150 break;
151
152 case SB_LINEUP:
153 event.m_eventType = wxEVT_SCROLL_LINEUP;
154 break;
155
156 case SB_LINEDOWN:
157 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
158 break;
159
160 case SB_PAGEUP:
161 event.m_eventType = wxEVT_SCROLL_PAGEUP;
162 break;
163
164 case SB_PAGEDOWN:
165 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
166 break;
167
168 case SB_THUMBTRACK:
169 case SB_THUMBPOSITION:
170 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
171 break;
172
173 default:
174 return;
175 break;
176 }
177 if (!GetEventHandler()->ProcessEvent(event))
178 Default();
179 }
180}
181
debe6624 182void wxSpinButton::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control)
2bda0e17
KB
183{
184 if (control)
185 {
7798a18e 186 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17
KB
187 event.SetPosition(pos);
188 event.SetOrientation(wxHORIZONTAL);
189 event.SetEventObject( this );
190
191 switch ( wParam )
192 {
193 case SB_TOP:
194 event.m_eventType = wxEVT_SCROLL_TOP;
195 break;
196
197 case SB_BOTTOM:
198 event.m_eventType = wxEVT_SCROLL_BOTTOM;
199 break;
200
201 case SB_LINEUP:
202 event.m_eventType = wxEVT_SCROLL_LINEUP;
203 break;
204
205 case SB_LINEDOWN:
206 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
207 break;
208
209 case SB_PAGEUP:
210 event.m_eventType = wxEVT_SCROLL_PAGEUP;
211 break;
212
213 case SB_PAGEDOWN:
214 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
215 break;
216
217 case SB_THUMBTRACK:
218 case SB_THUMBPOSITION:
219 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
220 break;
221
222 default:
223 return;
224 break;
225 }
226 if (!GetEventHandler()->ProcessEvent(event))
227 Default();
228 }
229}
230
debe6624 231bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17
KB
232{
233 // No command messages
234 return FALSE;
235}
236
fd3f686c 237bool wxSpinButton::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result)
2bda0e17
KB
238{
239 NMHDR* hdr1 = (NMHDR*) lParam;
240 switch ( hdr1->code )
241 {
fd3f686c 242 /* We don't process this message, currently */
2bda0e17 243 case UDN_DELTAPOS:
fd3f686c 244
2bda0e17 245 default :
fd3f686c 246 return wxControl::MSWNotify(wParam, lParam, result);
2bda0e17
KB
247 break;
248 }
249/*
250 event.eventObject = this;
251 event.SetEventType(eventType);
252
02800301 253 if ( !GetEventHandler()->ProcessEvent(event) )
2bda0e17
KB
254 return FALSE;
255*/
256 return TRUE;
257}
258
259// Spin event
260IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
261
7798a18e 262wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
2bda0e17
KB
263 wxScrollEvent(commandType, id)
264{
265}
266
267#endif