]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
Added dummy DeleteChildren so the sample will at least link.
[wxWidgets.git] / src / msw / spinbutt.cpp
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
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
38 #endif
39
40 wxSpinButton::wxSpinButton(void)
41 {
42 m_min = 0;
43 m_max = 100;
44 }
45
46 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
47 long style, const wxString& name)
48 {
49 wxSystemSettings settings;
50 m_backgroundColour = parent->GetBackgroundColour() ;
51 m_foregroundColour = parent->GetForegroundColour() ;
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, m_min);
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
108 wxSpinButton::~wxSpinButton(void)
109 {
110 }
111
112 // Attributes
113 ////////////////////////////////////////////////////////////////////////////
114
115 int wxSpinButton::GetValue(void) const
116 {
117 return (int) ::SendMessage((HWND) GetHWND(), UDM_GETPOS, 0, 0);
118 }
119
120 void wxSpinButton::SetValue(int val)
121 {
122 ::SendMessage((HWND) GetHWND(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
123 }
124
125 void wxSpinButton::SetRange(int minVal, int maxVal)
126 {
127 m_min = minVal;
128 m_max = maxVal;
129 ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0,
130 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
131 }
132
133 void wxSpinButton::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control)
134 {
135 if (control)
136 {
137 wxSpinEvent event(wxEVT_NULL, m_windowId);
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
182 void wxSpinButton::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control)
183 {
184 if (control)
185 {
186 wxSpinEvent event(wxEVT_NULL, m_windowId);
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
231 bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
232 {
233 // No command messages
234 return FALSE;
235 }
236
237 bool wxSpinButton::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result)
238 {
239 NMHDR* hdr1 = (NMHDR*) lParam;
240 switch ( hdr1->code )
241 {
242 /* We don't process this message, currently */
243 case UDN_DELTAPOS:
244
245 default :
246 return wxControl::MSWNotify(wParam, lParam, result);
247 break;
248 }
249 /*
250 event.eventObject = this;
251 event.SetEventType(eventType);
252
253 if ( !GetEventHandler()->ProcessEvent(event) )
254 return FALSE;
255 */
256 return TRUE;
257 }
258
259 // Spin event
260 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
261
262 wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
263 wxScrollEvent(commandType, id)
264 {
265 }
266
267 #endif