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