Added some window style metadata
[wxWidgets.git] / src / msw / spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "spinbutt.h"
22 #pragma implementation "spinbutbase.h"
23 #endif
24
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 #ifndef WX_PRECOMP
33 #include "wx/app.h"
34 #endif
35
36 #if wxUSE_SPINBTN
37
38 #include "wx/spinbutt.h"
39
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
41
42 #if defined(__WIN95__)
43
44 #include "wx/msw/private.h"
45
46 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
47 #include <commctrl.h>
48 #endif
49
50 // ============================================================================
51 // implementation
52 // ============================================================================
53
54 // ----------------------------------------------------------------------------
55 // wxWin macros
56 // ----------------------------------------------------------------------------
57
58
59 #if wxUSE_EXTENDED_RTTI
60 WX_DEFINE_FLAGS( wxSpinButtonStyle )
61
62 WX_BEGIN_FLAGS( wxSpinButtonStyle )
63 // new style border flags, we put them first to
64 // use them for streaming out
65 WX_FLAGS_MEMBER(wxBORDER_SIMPLE)
66 WX_FLAGS_MEMBER(wxBORDER_SUNKEN)
67 WX_FLAGS_MEMBER(wxBORDER_DOUBLE)
68 WX_FLAGS_MEMBER(wxBORDER_RAISED)
69 WX_FLAGS_MEMBER(wxBORDER_STATIC)
70 WX_FLAGS_MEMBER(wxBORDER_NONE)
71
72 // old style border flags
73 WX_FLAGS_MEMBER(wxSIMPLE_BORDER)
74 WX_FLAGS_MEMBER(wxSUNKEN_BORDER)
75 WX_FLAGS_MEMBER(wxDOUBLE_BORDER)
76 WX_FLAGS_MEMBER(wxRAISED_BORDER)
77 WX_FLAGS_MEMBER(wxSTATIC_BORDER)
78 WX_FLAGS_MEMBER(wxNO_BORDER)
79
80 // standard window styles
81 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL)
82 WX_FLAGS_MEMBER(wxCLIP_CHILDREN)
83 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW)
84 WX_FLAGS_MEMBER(wxWANTS_CHARS)
85 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
86 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB )
87 WX_FLAGS_MEMBER(wxVSCROLL)
88 WX_FLAGS_MEMBER(wxHSCROLL)
89
90 WX_FLAGS_MEMBER(wxSP_HORIZONTAL)
91 WX_FLAGS_MEMBER(wxSP_VERTICAL)
92 WX_FLAGS_MEMBER(wxSP_ARROW_KEYS)
93 WX_FLAGS_MEMBER(wxSP_WRAP)
94
95 WX_END_FLAGS( wxSpinButtonStyle )
96
97 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h")
98
99 WX_BEGIN_PROPERTIES_TABLE(wxSpinButton)
100 WX_PROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
101 WX_PROPERTY( Min , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
102 WX_PROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
103 WX_PROPERTY_FLAGS( WindowStyle , wxSpinButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
104 /*
105 TODO PROPERTIES
106 style wxSP_VERTICAL | wxSP_ARROW_KEYS
107 */
108 WX_END_PROPERTIES_TABLE()
109
110 WX_BEGIN_HANDLERS_TABLE(wxSpinButton)
111 WX_END_HANDLERS_TABLE()
112
113 WX_CONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
114 #else
115 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
116 #endif
117
118
119
120 // ----------------------------------------------------------------------------
121 // wxSpinButton
122 // ----------------------------------------------------------------------------
123
124 bool wxSpinButton::Create(wxWindow *parent,
125 wxWindowID id,
126 const wxPoint& pos,
127 const wxSize& size,
128 long style,
129 const wxString& name)
130 {
131 // basic initialization
132 InitBase();
133
134 m_windowId = (id == -1) ? NewControlId() : id;
135
136 m_backgroundColour = parent->GetBackgroundColour() ;
137 m_foregroundColour = parent->GetForegroundColour() ;
138
139 SetName(name);
140
141 int x = pos.x;
142 int y = pos.y;
143 int width = size.x;
144 int height = size.y;
145
146 m_windowStyle = style;
147
148 SetParent(parent);
149
150 // get the right size for the control
151 if ( width <= 0 || height <= 0 )
152 {
153 wxSize size = DoGetBestSize();
154 if ( width <= 0 )
155 width = size.x;
156 if ( height <= 0 )
157 height = size.y;
158 }
159
160 if ( x < 0 )
161 x = 0;
162 if ( y < 0 )
163 y = 0;
164
165 // translate the styles
166 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
167 UDS_NOTHOUSANDS | // never useful, sometimes harmful
168 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
169
170 if ( m_windowStyle & wxCLIP_SIBLINGS )
171 wstyle |= WS_CLIPSIBLINGS;
172 if ( m_windowStyle & wxSP_HORIZONTAL )
173 wstyle |= UDS_HORZ;
174 if ( m_windowStyle & wxSP_ARROW_KEYS )
175 wstyle |= UDS_ARROWKEYS;
176 if ( m_windowStyle & wxSP_WRAP )
177 wstyle |= UDS_WRAP;
178
179 // create the UpDown control.
180 m_hWnd = (WXHWND)CreateUpDownControl
181 (
182 wstyle,
183 x, y, width, height,
184 GetHwndOf(parent),
185 m_windowId,
186 wxGetInstance(),
187 NULL, // no buddy
188 m_max, m_min,
189 m_min // initial position
190 );
191
192 if ( !m_hWnd )
193 {
194 wxLogLastError(wxT("CreateUpDownControl"));
195
196 return FALSE;
197 }
198
199 if ( parent )
200 {
201 parent->AddChild(this);
202 }
203
204 SubclassWin(m_hWnd);
205
206 return TRUE;
207 }
208
209 wxSpinButton::~wxSpinButton()
210 {
211 }
212
213 // ----------------------------------------------------------------------------
214 // size calculation
215 // ----------------------------------------------------------------------------
216
217 wxSize wxSpinButton::DoGetBestSize() const
218 {
219 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
220 {
221 // vertical control
222 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
223 2*GetSystemMetrics(SM_CYVSCROLL));
224 }
225 else
226 {
227 // horizontal control
228 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
229 GetSystemMetrics(SM_CYHSCROLL));
230 }
231 }
232
233 // ----------------------------------------------------------------------------
234 // Attributes
235 // ----------------------------------------------------------------------------
236
237 int wxSpinButton::GetValue() const
238 {
239 #ifdef UDM_GETPOS32
240 if ( wxTheApp->GetComCtl32Version() >= 580 )
241 {
242 // use the full 32 bit range if available
243 return ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
244 }
245 #endif // UDM_GETPOS32
246
247 // we're limited to 16 bit
248 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
249 }
250
251 void wxSpinButton::SetValue(int val)
252 {
253 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
254
255 #ifdef UDM_SETPOS32
256 if ( wxTheApp->GetComCtl32Version() >= 580 )
257 {
258 // use the full 32 bit range if available
259 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
260 }
261 else // we're limited to 16 bit
262 #endif // UDM_SETPOS32
263 {
264 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
265 }
266 }
267
268 void wxSpinButton::SetRange(int minVal, int maxVal)
269 {
270 wxSpinButtonBase::SetRange(minVal, maxVal);
271
272 #ifdef UDM_SETRANGE32
273 if ( wxTheApp->GetComCtl32Version() >= 471 )
274 {
275 // use the full 32 bit range if available
276 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
277 }
278 else // we're limited to 16 bit
279 #endif // UDM_SETRANGE32
280 {
281 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
282 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
283 }
284 }
285
286 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
287 WXWORD pos, WXHWND control)
288 {
289 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
290
291 if ( wParam != SB_THUMBPOSITION )
292 {
293 // probable SB_ENDSCROLL - we don't react to it
294 return FALSE;
295 }
296
297 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
298 event.SetPosition((short)pos); // cast is important for negative values!
299 event.SetEventObject(this);
300
301 return GetEventHandler()->ProcessEvent(event);
302 }
303
304 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
305 {
306 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
307
308 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
309 return FALSE;
310
311 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
312 : wxEVT_SCROLL_LINEDOWN,
313 m_windowId);
314 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
315 event.SetEventObject(this);
316
317 bool processed = GetEventHandler()->ProcessEvent(event);
318
319 *result = event.IsAllowed() ? 0 : 1;
320
321 return processed;
322 }
323
324 bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
325 {
326 // No command messages
327 return FALSE;
328 }
329
330 #endif // __WIN95__
331
332 #endif
333 // wxUSE_SPINCTN
334