]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
wxLogDebug/Trace in release mode now don't give compiler warnings
[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;
50 m_backgroundColour = parent->GetDefaultBackgroundColour() ;
51 m_foregroundColour = parent->GetDefaultForegroundColour() ;
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,
94 m_min, m_max, 0);
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;
129 ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0, (LPARAM) MAKELONG((short) minVal, (short) maxVal));
130}
131
debe6624 132void wxSpinButton::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control)
2bda0e17
KB
133{
134 if (control)
135 {
7798a18e 136 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17
KB
137 event.SetPosition(pos);
138 event.SetOrientation(wxVERTICAL);
139 event.SetEventObject( this );
140
141 switch ( wParam )
142 {
143 case SB_TOP:
144 event.m_eventType = wxEVT_SCROLL_TOP;
145 break;
146
147 case SB_BOTTOM:
148 event.m_eventType = wxEVT_SCROLL_BOTTOM;
149 break;
150
151 case SB_LINEUP:
152 event.m_eventType = wxEVT_SCROLL_LINEUP;
153 break;
154
155 case SB_LINEDOWN:
156 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
157 break;
158
159 case SB_PAGEUP:
160 event.m_eventType = wxEVT_SCROLL_PAGEUP;
161 break;
162
163 case SB_PAGEDOWN:
164 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
165 break;
166
167 case SB_THUMBTRACK:
168 case SB_THUMBPOSITION:
169 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
170 break;
171
172 default:
173 return;
174 break;
175 }
176 if (!GetEventHandler()->ProcessEvent(event))
177 Default();
178 }
179}
180
debe6624 181void wxSpinButton::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control)
2bda0e17
KB
182{
183 if (control)
184 {
7798a18e 185 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17
KB
186 event.SetPosition(pos);
187 event.SetOrientation(wxHORIZONTAL);
188 event.SetEventObject( this );
189
190 switch ( wParam )
191 {
192 case SB_TOP:
193 event.m_eventType = wxEVT_SCROLL_TOP;
194 break;
195
196 case SB_BOTTOM:
197 event.m_eventType = wxEVT_SCROLL_BOTTOM;
198 break;
199
200 case SB_LINEUP:
201 event.m_eventType = wxEVT_SCROLL_LINEUP;
202 break;
203
204 case SB_LINEDOWN:
205 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
206 break;
207
208 case SB_PAGEUP:
209 event.m_eventType = wxEVT_SCROLL_PAGEUP;
210 break;
211
212 case SB_PAGEDOWN:
213 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
214 break;
215
216 case SB_THUMBTRACK:
217 case SB_THUMBPOSITION:
218 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
219 break;
220
221 default:
222 return;
223 break;
224 }
225 if (!GetEventHandler()->ProcessEvent(event))
226 Default();
227 }
228}
229
debe6624 230bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17
KB
231{
232 // No command messages
233 return FALSE;
234}
235
debe6624 236bool wxSpinButton::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17
KB
237{
238 NMHDR* hdr1 = (NMHDR*) lParam;
239 switch ( hdr1->code )
240 {
241/* We don't process this message, currently */
242 case UDN_DELTAPOS:
243 {
244 return wxControl::MSWNotify(wParam, lParam);
245 break;
246 }
247 default :
248 return wxControl::MSWNotify(wParam, lParam);
249 break;
250 }
251/*
252 event.eventObject = this;
253 event.SetEventType(eventType);
254
255 if ( !ProcessEvent(event) )
256 return FALSE;
257*/
258 return TRUE;
259}
260
261// Spin event
262IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
263
7798a18e 264wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
2bda0e17
KB
265 wxScrollEvent(commandType, id)
266{
267}
268
269#endif