]>
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 | |
a23fd0e1 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
b782f2e0 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
a23fd0e1 | 21 | #pragma implementation "spinbutt.h" |
3c1a88d8 | 22 | #pragma implementation "spinbutbase.h" |
2bda0e17 KB |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
a23fd0e1 | 29 | #pragma hdrstop |
2bda0e17 KB |
30 | #endif |
31 | ||
32 | #ifndef WX_PRECOMP | |
a23fd0e1 | 33 | #include "wx/wx.h" |
2bda0e17 KB |
34 | #endif |
35 | ||
57c208c5 JS |
36 | // Can't resolve reference to CreateUpDownControl in |
37 | // TWIN32, but could probably use normal CreateWindow instead. | |
38 | ||
0e528b99 JS |
39 | #if wxUSE_SPINBTN |
40 | ||
57c208c5 | 41 | #if defined(__WIN95__) && !defined(__TWIN32__) |
2bda0e17 KB |
42 | |
43 | #include "wx/spinbutt.h" | |
44 | #include "wx/msw/private.h" | |
45 | ||
65fd5cb0 | 46 | #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS) |
a23fd0e1 | 47 | #include <commctrl.h> |
2bda0e17 KB |
48 | #endif |
49 | ||
b782f2e0 VZ |
50 | // ============================================================================ |
51 | // implementation | |
52 | // ============================================================================ | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxWin macros | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
9750fc42 VZ |
58 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
59 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); | |
2bda0e17 | 60 | |
b782f2e0 VZ |
61 | // ---------------------------------------------------------------------------- |
62 | // wxSpinButton | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
31528cd3 VZ |
65 | bool wxSpinButton::Create(wxWindow *parent, |
66 | wxWindowID id, | |
67 | const wxPoint& pos, | |
68 | const wxSize& size, | |
69 | long style, | |
70 | const wxString& name) | |
2bda0e17 | 71 | { |
b782f2e0 VZ |
72 | // basic initialization |
73 | InitBase(); | |
2bda0e17 | 74 | |
b782f2e0 | 75 | m_windowId = (id == -1) ? NewControlId() : id; |
2bda0e17 | 76 | |
b782f2e0 VZ |
77 | m_backgroundColour = parent->GetBackgroundColour() ; |
78 | m_foregroundColour = parent->GetForegroundColour() ; | |
2bda0e17 | 79 | |
b782f2e0 | 80 | SetName(name); |
2bda0e17 | 81 | |
b782f2e0 VZ |
82 | int x = pos.x; |
83 | int y = pos.y; | |
84 | int width = size.x; | |
85 | int height = size.y; | |
2bda0e17 | 86 | |
b782f2e0 | 87 | m_windowStyle = style; |
2bda0e17 | 88 | |
b782f2e0 | 89 | SetParent(parent); |
2bda0e17 | 90 | |
b782f2e0 VZ |
91 | // get the right size for the control |
92 | if ( width <= 0 || height <= 0 ) | |
93 | { | |
94 | wxSize size = DoGetBestSize(); | |
95 | if ( width <= 0 ) | |
96 | width = size.x; | |
97 | if ( height <= 0 ) | |
98 | height = size.y; | |
99 | } | |
2bda0e17 | 100 | |
b782f2e0 VZ |
101 | if ( x < 0 ) |
102 | x = 0; | |
103 | if ( y < 0 ) | |
104 | y = 0; | |
105 | ||
106 | // translate the styles | |
107 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | | |
882a8f40 VZ |
108 | UDS_NOTHOUSANDS | // never useful, sometimes harmful |
109 | UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy | |
b782f2e0 VZ |
110 | |
111 | if ( m_windowStyle & wxSP_HORIZONTAL ) | |
112 | wstyle |= UDS_HORZ; | |
113 | if ( m_windowStyle & wxSP_ARROW_KEYS ) | |
114 | wstyle |= UDS_ARROWKEYS; | |
115 | if ( m_windowStyle & wxSP_WRAP ) | |
116 | wstyle |= UDS_WRAP; | |
117 | ||
118 | // create the UpDown control. | |
119 | m_hWnd = (WXHWND)CreateUpDownControl | |
120 | ( | |
121 | wstyle, | |
122 | x, y, width, height, | |
123 | GetHwndOf(parent), | |
124 | m_windowId, | |
125 | wxGetInstance(), | |
126 | NULL, // no buddy | |
127 | m_max, m_min, | |
128 | m_min // initial position | |
129 | ); | |
130 | ||
131 | if ( !m_hWnd ) | |
132 | { | |
133 | wxLogLastError("CreateUpDownControl"); | |
2bda0e17 | 134 | |
b782f2e0 VZ |
135 | return FALSE; |
136 | } | |
2bda0e17 | 137 | |
b782f2e0 VZ |
138 | if ( parent ) |
139 | { | |
140 | parent->AddChild(this); | |
141 | } | |
31528cd3 | 142 | |
b782f2e0 | 143 | SubclassWin(m_hWnd); |
2bda0e17 | 144 | |
b782f2e0 | 145 | return TRUE; |
2bda0e17 KB |
146 | } |
147 | ||
a23fd0e1 | 148 | wxSpinButton::~wxSpinButton() |
2bda0e17 KB |
149 | { |
150 | } | |
151 | ||
b782f2e0 VZ |
152 | // ---------------------------------------------------------------------------- |
153 | // size calculation | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
f68586e5 | 156 | wxSize wxSpinButton::DoGetBestSize() const |
b782f2e0 VZ |
157 | { |
158 | if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) | |
159 | { | |
160 | // vertical control | |
161 | return wxSize(GetSystemMetrics(SM_CXVSCROLL), | |
162 | 2*GetSystemMetrics(SM_CYVSCROLL)); | |
163 | } | |
164 | else | |
165 | { | |
166 | // horizontal control | |
167 | return wxSize(2*GetSystemMetrics(SM_CXHSCROLL), | |
168 | GetSystemMetrics(SM_CYHSCROLL)); | |
169 | } | |
170 | } | |
171 | ||
172 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 173 | // Attributes |
b782f2e0 | 174 | // ---------------------------------------------------------------------------- |
2bda0e17 | 175 | |
a23fd0e1 | 176 | int wxSpinButton::GetValue() const |
2bda0e17 | 177 | { |
0655ad29 | 178 | return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0)); |
2bda0e17 KB |
179 | } |
180 | ||
debe6624 | 181 | void wxSpinButton::SetValue(int val) |
2bda0e17 | 182 | { |
d1d7cdff | 183 | ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0)); |
2bda0e17 KB |
184 | } |
185 | ||
debe6624 | 186 | void wxSpinButton::SetRange(int minVal, int maxVal) |
2bda0e17 | 187 | { |
31528cd3 | 188 | wxSpinButtonBase::SetRange(minVal, maxVal); |
d1d7cdff | 189 | ::SendMessage(GetHwnd(), UDM_SETRANGE, 0, |
3d7e30a4 | 190 | (LPARAM) MAKELONG((short)maxVal, (short)minVal)); |
2bda0e17 KB |
191 | } |
192 | ||
a23fd0e1 VZ |
193 | bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam, |
194 | WXWORD pos, WXHWND control) | |
2bda0e17 | 195 | { |
223d09f6 | 196 | wxCHECK_MSG( control, FALSE, wxT("scrolling what?") ) |
2bda0e17 | 197 | |
0655ad29 | 198 | if ( wParam != SB_THUMBPOSITION ) |
a23fd0e1 | 199 | { |
0655ad29 VZ |
200 | // probable SB_ENDSCROLL - we don't react to it |
201 | return FALSE; | |
202 | } | |
2bda0e17 | 203 | |
0655ad29 VZ |
204 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); |
205 | event.SetPosition((short)pos); // cast is important for negative values! | |
206 | event.SetEventObject(this); | |
2bda0e17 | 207 | |
0655ad29 VZ |
208 | return GetEventHandler()->ProcessEvent(event); |
209 | } | |
2bda0e17 | 210 | |
0655ad29 VZ |
211 | bool wxSpinButton::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
212 | { | |
8a4df159 | 213 | #ifndef __GNUWIN32__ |
0cdf89ab | 214 | #if defined(__BORLANDC__) || defined(__WATCOMC__) |
83475efc | 215 | LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam; |
6474416b | 216 | #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020) |
2996bcde | 217 | LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam; |
83475efc | 218 | #else |
0655ad29 | 219 | LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam; |
83475efc | 220 | #endif |
2bda0e17 | 221 | |
0655ad29 VZ |
222 | wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP |
223 | : wxEVT_SCROLL_LINEDOWN, | |
224 | m_windowId); | |
225 | event.SetPosition(lpnmud->iPos + lpnmud->iDelta); | |
226 | event.SetEventObject(this); | |
2bda0e17 | 227 | |
0655ad29 | 228 | bool processed = GetEventHandler()->ProcessEvent(event); |
2bda0e17 | 229 | |
0655ad29 | 230 | *result = event.IsAllowed() ? 0 : 1; |
2bda0e17 | 231 | |
0655ad29 | 232 | return processed; |
b782f2e0 | 233 | #else // GnuWin32 |
8a4df159 RR |
234 | return FALSE; |
235 | #endif | |
2bda0e17 KB |
236 | } |
237 | ||
debe6624 | 238 | bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id) |
2bda0e17 | 239 | { |
a23fd0e1 VZ |
240 | // No command messages |
241 | return FALSE; | |
2bda0e17 KB |
242 | } |
243 | ||
a23fd0e1 | 244 | #endif // __WIN95__ |
0e528b99 JS |
245 | |
246 | #endif | |
247 | // wxUSE_SPINCTN | |
248 |