]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
Added m_isOpened variable to simulate opening/closing
[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 #ifdef __GNUG__
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 // Can't resolve reference to CreateUpDownControl in
43 // TWIN32, but could probably use normal CreateWindow instead.
44 #if defined(__WIN95__) && !defined(__TWIN32__)
45
46 #include "wx/msw/private.h"
47
48 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
49 #include <commctrl.h>
50 #endif
51
52 // ============================================================================
53 // implementation
54 // ============================================================================
55
56 // ----------------------------------------------------------------------------
57 // wxWin macros
58 // ----------------------------------------------------------------------------
59
60 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
61
62 // ----------------------------------------------------------------------------
63 // wxSpinButton
64 // ----------------------------------------------------------------------------
65
66 bool wxSpinButton::Create(wxWindow *parent,
67 wxWindowID id,
68 const wxPoint& pos,
69 const wxSize& size,
70 long style,
71 const wxString& name)
72 {
73 // basic initialization
74 InitBase();
75
76 m_windowId = (id == -1) ? NewControlId() : id;
77
78 m_backgroundColour = parent->GetBackgroundColour() ;
79 m_foregroundColour = parent->GetForegroundColour() ;
80
81 SetName(name);
82
83 int x = pos.x;
84 int y = pos.y;
85 int width = size.x;
86 int height = size.y;
87
88 m_windowStyle = style;
89
90 SetParent(parent);
91
92 // get the right size for the control
93 if ( width <= 0 || height <= 0 )
94 {
95 wxSize size = DoGetBestSize();
96 if ( width <= 0 )
97 width = size.x;
98 if ( height <= 0 )
99 height = size.y;
100 }
101
102 if ( x < 0 )
103 x = 0;
104 if ( y < 0 )
105 y = 0;
106
107 // translate the styles
108 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
109 UDS_NOTHOUSANDS | // never useful, sometimes harmful
110 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
111
112 if ( m_windowStyle & wxCLIP_SIBLINGS )
113 wstyle |= WS_CLIPSIBLINGS;
114 if ( m_windowStyle & wxSP_HORIZONTAL )
115 wstyle |= UDS_HORZ;
116 if ( m_windowStyle & wxSP_ARROW_KEYS )
117 wstyle |= UDS_ARROWKEYS;
118 if ( m_windowStyle & wxSP_WRAP )
119 wstyle |= UDS_WRAP;
120
121 // create the UpDown control.
122 m_hWnd = (WXHWND)CreateUpDownControl
123 (
124 wstyle,
125 x, y, width, height,
126 GetHwndOf(parent),
127 m_windowId,
128 wxGetInstance(),
129 NULL, // no buddy
130 m_max, m_min,
131 m_min // initial position
132 );
133
134 if ( !m_hWnd )
135 {
136 wxLogLastError(wxT("CreateUpDownControl"));
137
138 return FALSE;
139 }
140
141 if ( parent )
142 {
143 parent->AddChild(this);
144 }
145
146 SubclassWin(m_hWnd);
147
148 return TRUE;
149 }
150
151 wxSpinButton::~wxSpinButton()
152 {
153 }
154
155 // ----------------------------------------------------------------------------
156 // size calculation
157 // ----------------------------------------------------------------------------
158
159 wxSize wxSpinButton::DoGetBestSize() const
160 {
161 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
162 {
163 // vertical control
164 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
165 2*GetSystemMetrics(SM_CYVSCROLL));
166 }
167 else
168 {
169 // horizontal control
170 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
171 GetSystemMetrics(SM_CYHSCROLL));
172 }
173 }
174
175 // ----------------------------------------------------------------------------
176 // Attributes
177 // ----------------------------------------------------------------------------
178
179 int wxSpinButton::GetValue() const
180 {
181 #ifdef UDM_GETPOS32
182 if ( wxTheApp->GetComCtl32Version() >= 580 )
183 {
184 // use the full 32 bit range if available
185 return ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
186 }
187 #endif // UDM_GETPOS32
188
189 // we're limited to 16 bit
190 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
191 }
192
193 void wxSpinButton::SetValue(int val)
194 {
195 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
196
197 #ifdef UDM_SETPOS32
198 if ( wxTheApp->GetComCtl32Version() >= 580 )
199 {
200 // use the full 32 bit range if available
201 ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val);
202 }
203 else // we're limited to 16 bit
204 #endif // UDM_SETPOS32
205 {
206 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0));
207 }
208 }
209
210 void wxSpinButton::SetRange(int minVal, int maxVal)
211 {
212 wxSpinButtonBase::SetRange(minVal, maxVal);
213
214 #ifdef UDM_SETRANGE32
215 if ( wxTheApp->GetComCtl32Version() >= 471 )
216 {
217 // use the full 32 bit range if available
218 ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal);
219 }
220 else // we're limited to 16 bit
221 #endif // UDM_SETRANGE32
222 {
223 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
224 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
225 }
226 }
227
228 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
229 WXWORD pos, WXHWND control)
230 {
231 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
232
233 if ( wParam != SB_THUMBPOSITION )
234 {
235 // probable SB_ENDSCROLL - we don't react to it
236 return FALSE;
237 }
238
239 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
240 event.SetPosition((short)pos); // cast is important for negative values!
241 event.SetEventObject(this);
242
243 return GetEventHandler()->ProcessEvent(event);
244 }
245
246 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
247 {
248 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
249
250 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
251 return FALSE;
252
253 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
254 : wxEVT_SCROLL_LINEDOWN,
255 m_windowId);
256 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
257 event.SetEventObject(this);
258
259 bool processed = GetEventHandler()->ProcessEvent(event);
260
261 *result = event.IsAllowed() ? 0 : 1;
262
263 return processed;
264 }
265
266 bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
267 {
268 // No command messages
269 return FALSE;
270 }
271
272 #endif // __WIN95__
273
274 #endif
275 // wxUSE_SPINCTN
276