]>
Commit | Line | Data |
---|---|---|
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 | |
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, const wxWindowID id, const wxPoint& pos, const wxSize& size, | |
47 | const long style, const wxString& name) | |
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 | ||
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(const int val) | |
121 | { | |
122 | ::SendMessage((HWND) GetHWND(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0)); | |
123 | } | |
124 | ||
125 | void wxSpinButton::SetRange(const int minVal, const int maxVal) | |
126 | { | |
127 | m_min = minVal; | |
128 | m_max = maxVal; | |
129 | ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0, (LPARAM) MAKELONG((short) minVal, (short) maxVal)); | |
130 | } | |
131 | ||
132 | void wxSpinButton::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) | |
133 | { | |
134 | if (control) | |
135 | { | |
136 | wxSpinEvent event(0, m_windowId); | |
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 | ||
181 | void wxSpinButton::MSWOnHScroll( const WXWORD wParam, const WXWORD pos, const WXHWND control) | |
182 | { | |
183 | if (control) | |
184 | { | |
185 | wxSpinEvent event(0, m_windowId); | |
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 | ||
230 | bool wxSpinButton::MSWCommand(const WXUINT cmd, const WXWORD id) | |
231 | { | |
232 | // No command messages | |
233 | return FALSE; | |
234 | } | |
235 | ||
236 | bool wxSpinButton::MSWNotify(const WXWPARAM wParam, const WXLPARAM lParam) | |
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 | |
262 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) | |
263 | ||
264 | wxSpinEvent::wxSpinEvent(WXTYPE commandType, int id): | |
265 | wxScrollEvent(commandType, id) | |
266 | { | |
267 | } | |
268 | ||
269 | #endif |