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