]>
Commit | Line | Data |
---|---|---|
b782f2e0 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/spinctrl.cpp | |
3 | // Purpose: wxSpinCtrl class implementation for Win32 | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 22.07.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
b782f2e0 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
14f355c2 | 16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
b782f2e0 VZ |
17 | #pragma implementation "spinctrlbase.h" |
18 | #pragma implementation "spinctrl.h" | |
19 | #endif | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // headers | |
23 | // ---------------------------------------------------------------------------- | |
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/wx.h" | |
34 | #endif | |
35 | ||
0e528b99 JS |
36 | #if wxUSE_SPINCTRL |
37 | ||
b782f2e0 VZ |
38 | #if defined(__WIN95__) |
39 | ||
40 | #include "wx/spinctrl.h" | |
41 | #include "wx/msw/private.h" | |
42 | ||
b39dbf34 | 43 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) |
4c0a2c5c JS |
44 | #include <commctrl.h> |
45 | #endif | |
b782f2e0 | 46 | |
678cd6de VZ |
47 | #include <limits.h> // for INT_MIN |
48 | ||
b782f2e0 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
f0a126fe | 53 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
54 | WX_DEFINE_FLAGS( wxSpinCtrlStyle ) |
55 | ||
3ff066a4 | 56 | wxBEGIN_FLAGS( wxSpinCtrlStyle ) |
bc9fb572 JS |
57 | // new style border flags, we put them first to |
58 | // use them for streaming out | |
3ff066a4 SC |
59 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
60 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
61 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
62 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
63 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
64 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
bc9fb572 JS |
65 | |
66 | // old style border flags | |
3ff066a4 SC |
67 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
68 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
69 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
70 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
71 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 72 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
73 | |
74 | // standard window styles | |
3ff066a4 SC |
75 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
76 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
77 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
78 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 79 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
80 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
81 | wxFLAGS_MEMBER(wxVSCROLL) | |
82 | wxFLAGS_MEMBER(wxHSCROLL) | |
83 | ||
84 | wxFLAGS_MEMBER(wxSP_HORIZONTAL) | |
85 | wxFLAGS_MEMBER(wxSP_VERTICAL) | |
86 | wxFLAGS_MEMBER(wxSP_ARROW_KEYS) | |
87 | wxFLAGS_MEMBER(wxSP_WRAP) | |
88 | ||
89 | wxEND_FLAGS( wxSpinCtrlStyle ) | |
bc9fb572 | 90 | |
51741307 | 91 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinCtrl, wxControl,"wx/spinbut.h") |
9750fc42 | 92 | |
3ff066a4 SC |
93 | wxBEGIN_PROPERTIES_TABLE(wxSpinCtrl) |
94 | wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxSpinEvent ) | |
95 | wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SPINCTRL_UPDATED , wxCommandEvent ) | |
96 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) | |
97 | wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent ) | |
98 | ||
af498247 | 99 | wxPROPERTY( ValueString , wxString , SetValue , GetValue , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) ; |
3ff066a4 SC |
100 | wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
101 | wxPROPERTY( Min , int , SetMin, GetMin, 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) | |
102 | wxPROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 103 | wxPROPERTY_FLAGS( WindowStyle , wxSpinCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
066f1b7a SC |
104 | /* |
105 | TODO PROPERTIES | |
106 | style wxSP_ARROW_KEYS | |
066f1b7a | 107 | */ |
3ff066a4 | 108 | wxEND_PROPERTIES_TABLE() |
51741307 | 109 | |
3ff066a4 SC |
110 | wxBEGIN_HANDLERS_TABLE(wxSpinCtrl) |
111 | wxEND_HANDLERS_TABLE() | |
51741307 | 112 | |
3ff066a4 | 113 | wxCONSTRUCTOR_6( wxSpinCtrl , wxWindow* , Parent , wxWindowID , Id , wxString , ValueString , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
114 | #else |
115 | IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl) | |
116 | #endif | |
066f1b7a | 117 | |
9750fc42 | 118 | BEGIN_EVENT_TABLE(wxSpinCtrl, wxSpinButton) |
e3582f7f | 119 | EVT_CHAR(wxSpinCtrl::OnChar) |
c5c04fab VZ |
120 | |
121 | EVT_SET_FOCUS(wxSpinCtrl::OnSetFocus) | |
122 | ||
9750fc42 VZ |
123 | EVT_SPIN(-1, wxSpinCtrl::OnSpinChange) |
124 | END_EVENT_TABLE() | |
b782f2e0 | 125 | |
6fe19057 VZ |
126 | #define GetBuddyHwnd() (HWND)(m_hwndBuddy) |
127 | ||
b782f2e0 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | // constants | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
baccb514 VZ |
132 | // the margin between the up-down control and its buddy (can be arbitrary, |
133 | // choose what you like - or may be decide during run-time depending on the | |
134 | // font size?) | |
135 | static const int MARGIN_BETWEEN = 1; | |
b782f2e0 VZ |
136 | |
137 | // ============================================================================ | |
138 | // implementation | |
139 | // ============================================================================ | |
140 | ||
6fe19057 VZ |
141 | wxArraySpins wxSpinCtrl::ms_allSpins; |
142 | ||
f6bcfd97 BP |
143 | // ---------------------------------------------------------------------------- |
144 | // wnd proc for the buddy text ctrl | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
147 | LRESULT APIENTRY _EXPORT wxBuddyTextWndProc(HWND hwnd, | |
148 | UINT message, | |
149 | WPARAM wParam, | |
150 | LPARAM lParam) | |
151 | { | |
975b6bcf | 152 | wxSpinCtrl *spin = (wxSpinCtrl *)wxGetWindowUserData(hwnd); |
f6bcfd97 | 153 | |
93c4157c VZ |
154 | // forward some messages (the key and focus ones only so far) to |
155 | // the spin ctrl | |
f6bcfd97 BP |
156 | switch ( message ) |
157 | { | |
93c4157c | 158 | case WM_SETFOCUS: |
c5c04fab VZ |
159 | // if the focus comes from the spin control itself, don't set it |
160 | // back to it -- we don't want to go into an infinite loop | |
c140b7e7 | 161 | if ( (WXHWND)wParam == spin->GetHWND() ) |
c5c04fab VZ |
162 | break; |
163 | //else: fall through | |
164 | ||
93c4157c | 165 | case WM_KILLFOCUS: |
f6bcfd97 BP |
166 | case WM_CHAR: |
167 | case WM_DEADCHAR: | |
168 | case WM_KEYUP: | |
169 | case WM_KEYDOWN: | |
170 | spin->MSWWindowProc(message, wParam, lParam); | |
e3582f7f JS |
171 | |
172 | // The control may have been deleted at this point, so check. | |
975b6bcf | 173 | if ( !::IsWindow(hwnd) || wxGetWindowUserData(hwnd) != spin ) |
e3582f7f | 174 | return 0; |
f6bcfd97 | 175 | break; |
350ba193 VZ |
176 | |
177 | case WM_GETDLGCODE: | |
178 | // we want to get WXK_RETURN in order to generate the event for it | |
179 | return DLGC_WANTCHARS; | |
f6bcfd97 | 180 | } |
350ba193 | 181 | |
f6bcfd97 BP |
182 | return ::CallWindowProc(CASTWNDPROC spin->GetBuddyWndProc(), |
183 | hwnd, message, wParam, lParam); | |
184 | } | |
185 | ||
6fe19057 VZ |
186 | /* static */ |
187 | wxSpinCtrl *wxSpinCtrl::GetSpinForTextCtrl(WXHWND hwndBuddy) | |
188 | { | |
975b6bcf | 189 | wxSpinCtrl *spin = (wxSpinCtrl *)wxGetWindowUserData((HWND)hwndBuddy); |
6fe19057 VZ |
190 | |
191 | int i = ms_allSpins.Index(spin); | |
192 | ||
193 | if ( i == wxNOT_FOUND ) | |
194 | return NULL; | |
195 | ||
196 | // sanity check | |
197 | wxASSERT_MSG( spin->m_hwndBuddy == hwndBuddy, | |
198 | _T("wxSpinCtrl has incorrect buddy HWND!") ); | |
199 | ||
200 | return spin; | |
201 | } | |
202 | ||
203 | // process a WM_COMMAND generated by the buddy text control | |
204 | bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id)) | |
205 | { | |
e3582f7f | 206 | switch (cmd) |
6fe19057 | 207 | { |
e3582f7f JS |
208 | case EN_CHANGE: |
209 | { | |
210 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); | |
211 | event.SetEventObject(this); | |
212 | wxString val = wxGetWindowText(m_hwndBuddy); | |
213 | event.SetString(val); | |
214 | event.SetInt(GetValue()); | |
215 | return GetEventHandler()->ProcessEvent(event); | |
216 | } | |
217 | case EN_SETFOCUS: | |
218 | case EN_KILLFOCUS: | |
219 | { | |
220 | wxFocusEvent event(cmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS | |
221 | : wxEVT_SET_FOCUS, | |
222 | m_windowId); | |
223 | event.SetEventObject( this ); | |
224 | return GetEventHandler()->ProcessEvent(event); | |
225 | } | |
226 | default: | |
227 | break; | |
6fe19057 VZ |
228 | } |
229 | ||
230 | // not processed | |
231 | return FALSE; | |
232 | } | |
233 | ||
e3582f7f JS |
234 | void wxSpinCtrl::OnChar(wxKeyEvent& event) |
235 | { | |
77e00fe9 | 236 | switch ( event.GetKeyCode() ) |
e3582f7f JS |
237 | { |
238 | case WXK_RETURN: | |
239 | { | |
240 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
241 | InitCommandEvent(event); | |
242 | wxString val = wxGetWindowText(m_hwndBuddy); | |
243 | event.SetString(val); | |
244 | event.SetInt(GetValue()); | |
245 | if ( GetEventHandler()->ProcessEvent(event) ) | |
246 | return; | |
247 | break; | |
248 | } | |
249 | ||
250 | case WXK_TAB: | |
251 | // always produce navigation event - even if we process TAB | |
252 | // ourselves the fact that we got here means that the user code | |
253 | // decided to skip processing of this TAB - probably to let it | |
254 | // do its default job. | |
255 | { | |
256 | wxNavigationKeyEvent eventNav; | |
257 | eventNav.SetDirection(!event.ShiftDown()); | |
258 | eventNav.SetWindowChange(event.ControlDown()); | |
259 | eventNav.SetEventObject(this); | |
260 | ||
261 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) | |
262 | return; | |
263 | } | |
264 | break; | |
265 | } | |
266 | ||
267 | // no, we didn't process it | |
268 | event.Skip(); | |
269 | } | |
270 | ||
c5c04fab VZ |
271 | void wxSpinCtrl::OnSetFocus(wxFocusEvent& event) |
272 | { | |
273 | // when we get focus, give it to our buddy window as it needs it more than | |
274 | // we do | |
275 | ::SetFocus((HWND)m_hwndBuddy); | |
276 | ||
277 | event.Skip(); | |
278 | } | |
279 | ||
b782f2e0 VZ |
280 | // ---------------------------------------------------------------------------- |
281 | // construction | |
282 | // ---------------------------------------------------------------------------- | |
283 | ||
284 | bool wxSpinCtrl::Create(wxWindow *parent, | |
285 | wxWindowID id, | |
678cd6de | 286 | const wxString& value, |
b782f2e0 VZ |
287 | const wxPoint& pos, |
288 | const wxSize& size, | |
289 | long style, | |
290 | int min, int max, int initial, | |
291 | const wxString& name) | |
292 | { | |
293 | // before using DoGetBestSize(), have to set style to let the base class | |
294 | // know whether this is a horizontal or vertical control (we're always | |
295 | // vertical) | |
882a8f40 | 296 | style |= wxSP_VERTICAL; |
c76b1a30 JS |
297 | |
298 | if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT ) | |
5d72f195 RR |
299 | #ifdef __WXWINCE__ |
300 | style |= wxBORDER_SIMPLE; | |
301 | #else | |
c76b1a30 | 302 | style |= wxBORDER_SUNKEN; |
5d72f195 | 303 | #endif |
c76b1a30 | 304 | |
882a8f40 | 305 | SetWindowStyle(style); |
b782f2e0 | 306 | |
fe3d9123 JS |
307 | WXDWORD exStyle = 0; |
308 | WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; | |
309 | ||
b782f2e0 VZ |
310 | // calculate the sizes: the size given is the toal size for both controls |
311 | // and we need to fit them both in the given width (height is the same) | |
312 | wxSize sizeText(size), sizeBtn(size); | |
313 | sizeBtn.x = wxSpinButton::DoGetBestSize().x; | |
baccb514 VZ |
314 | if ( sizeText.x <= 0 ) |
315 | { | |
316 | // DEFAULT_ITEM_WIDTH is the default width for the text control | |
317 | sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; | |
318 | } | |
319 | ||
b782f2e0 VZ |
320 | sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; |
321 | if ( sizeText.x <= 0 ) | |
322 | { | |
323 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
324 | } | |
325 | ||
326 | wxPoint posBtn(pos); | |
327 | posBtn.x += sizeText.x + MARGIN_BETWEEN; | |
328 | ||
c5c04fab VZ |
329 | // we must create the text control before the spin button for the purpose |
330 | // of the dialog navigation: if there is a static text just before the spin | |
331 | // control, activating it by Alt-letter should give focus to the text | |
332 | // control, not the spin and the dialog navigation code will give focus to | |
333 | // the next control (at Windows level), not the one after it | |
b782f2e0 | 334 | |
c5c04fab | 335 | // create the text window |
b782f2e0 | 336 | |
b782f2e0 VZ |
337 | m_hwndBuddy = (WXHWND)::CreateWindowEx |
338 | ( | |
c5c04fab | 339 | exStyle, // sunken border |
baccb514 VZ |
340 | _T("EDIT"), // window class |
341 | NULL, // no window title | |
c5c04fab | 342 | msStyle, // style (will be shown later) |
baccb514 VZ |
343 | pos.x, pos.y, // position |
344 | 0, 0, // size (will be set later) | |
345 | GetHwndOf(parent), // parent | |
346 | (HMENU)-1, // control id | |
347 | wxGetInstance(), // app instance | |
348 | NULL // unused client data | |
b782f2e0 VZ |
349 | ); |
350 | ||
351 | if ( !m_hwndBuddy ) | |
352 | { | |
f6bcfd97 | 353 | wxLogLastError(wxT("CreateWindow(buddy text window)")); |
b782f2e0 VZ |
354 | |
355 | return FALSE; | |
356 | } | |
357 | ||
c5c04fab VZ |
358 | |
359 | // create the spin button | |
360 | if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) | |
361 | { | |
362 | return FALSE; | |
363 | } | |
364 | ||
365 | SetRange(min, max); | |
366 | SetValue(initial); | |
367 | ||
f6bcfd97 | 368 | // subclass the text ctrl to be able to intercept some events |
975b6bcf VZ |
369 | wxSetWindowUserData(GetBuddyHwnd(), this); |
370 | m_wndProcBuddy = (WXFARPROC)wxSetWindowProc(GetBuddyHwnd(), | |
371 | wxBuddyTextWndProc); | |
f6bcfd97 | 372 | |
b782f2e0 | 373 | // should have the same font as the other controls |
baccb514 VZ |
374 | SetFont(GetParent()->GetFont()); |
375 | ||
af905c94 JS |
376 | WXHANDLE hFont = GetFont().GetResourceHandle(); |
377 | (void)::SendMessage(GetBuddyHwnd(), WM_SETFONT, (WPARAM)hFont, TRUE); | |
378 | ||
baccb514 VZ |
379 | // set the size of the text window - can do it only now, because we |
380 | // couldn't call DoGetBestSize() before as font wasn't set | |
381 | if ( sizeText.y <= 0 ) | |
382 | { | |
882a8f40 VZ |
383 | int cx, cy; |
384 | wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); | |
385 | ||
386 | sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); | |
baccb514 VZ |
387 | } |
388 | ||
389 | DoMoveWindow(pos.x, pos.y, | |
390 | sizeText.x + sizeBtn.x + MARGIN_BETWEEN, sizeText.y); | |
391 | ||
6fe19057 | 392 | (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); |
b782f2e0 VZ |
393 | |
394 | // associate the text window with the spin button | |
baccb514 VZ |
395 | (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); |
396 | ||
678cd6de VZ |
397 | if ( !value.IsEmpty() ) |
398 | { | |
399 | SetValue(value); | |
400 | } | |
401 | ||
6fe19057 VZ |
402 | // do it after finishing with m_hwndBuddy creation to avoid generating |
403 | // initial wxEVT_COMMAND_TEXT_UPDATED message | |
404 | ms_allSpins.Add(this); | |
405 | ||
baccb514 VZ |
406 | return TRUE; |
407 | } | |
408 | ||
f6bcfd97 BP |
409 | wxSpinCtrl::~wxSpinCtrl() |
410 | { | |
6fe19057 VZ |
411 | ms_allSpins.Remove(this); |
412 | ||
5648c0ad JS |
413 | // This removes spurious memory leak reporting |
414 | if (ms_allSpins.GetCount() == 0) | |
415 | ms_allSpins.Clear(); | |
416 | ||
f6bcfd97 BP |
417 | // destroy the buddy window because this pointer which wxBuddyTextWndProc |
418 | // uses will not soon be valid any more | |
6fe19057 | 419 | ::DestroyWindow(GetBuddyHwnd()); |
f6bcfd97 BP |
420 | } |
421 | ||
678cd6de VZ |
422 | // ---------------------------------------------------------------------------- |
423 | // wxTextCtrl-like methods | |
424 | // ---------------------------------------------------------------------------- | |
425 | ||
426 | void wxSpinCtrl::SetValue(const wxString& text) | |
427 | { | |
6fe19057 | 428 | if ( !::SetWindowText(GetBuddyHwnd(), text.c_str()) ) |
678cd6de | 429 | { |
f6bcfd97 | 430 | wxLogLastError(wxT("SetWindowText(buddy)")); |
678cd6de VZ |
431 | } |
432 | } | |
433 | ||
434 | int wxSpinCtrl::GetValue() const | |
435 | { | |
436 | wxString val = wxGetWindowText(m_hwndBuddy); | |
437 | ||
438 | long n; | |
439 | if ( (wxSscanf(val, wxT("%lu"), &n) != 1) ) | |
440 | n = INT_MIN; | |
441 | ||
442 | return n; | |
443 | } | |
444 | ||
07901ec9 VZ |
445 | void wxSpinCtrl::SetSelection(long from, long to) |
446 | { | |
77ffb593 | 447 | // if from and to are both -1, it means (in wxWidgets) that all text should |
07901ec9 VZ |
448 | // be selected - translate into Windows convention |
449 | if ( (from == -1) && (to == -1) ) | |
450 | { | |
451 | from = 0; | |
452 | } | |
453 | ||
454 | ::SendMessage((HWND)m_hwndBuddy, EM_SETSEL, (WPARAM)from, (LPARAM)to); | |
455 | } | |
456 | ||
baccb514 | 457 | // ---------------------------------------------------------------------------- |
882a8f40 | 458 | // forward some methods to subcontrols |
baccb514 VZ |
459 | // ---------------------------------------------------------------------------- |
460 | ||
461 | bool wxSpinCtrl::SetFont(const wxFont& font) | |
462 | { | |
463 | if ( !wxWindowBase::SetFont(font) ) | |
464 | { | |
465 | // nothing to do | |
466 | return FALSE; | |
467 | } | |
468 | ||
469 | WXHANDLE hFont = GetFont().GetResourceHandle(); | |
6fe19057 | 470 | (void)::SendMessage(GetBuddyHwnd(), WM_SETFONT, (WPARAM)hFont, TRUE); |
b782f2e0 VZ |
471 | |
472 | return TRUE; | |
473 | } | |
474 | ||
882a8f40 VZ |
475 | bool wxSpinCtrl::Show(bool show) |
476 | { | |
477 | if ( !wxControl::Show(show) ) | |
478 | { | |
479 | return FALSE; | |
480 | } | |
481 | ||
6fe19057 | 482 | ::ShowWindow(GetBuddyHwnd(), show ? SW_SHOW : SW_HIDE); |
882a8f40 VZ |
483 | |
484 | return TRUE; | |
485 | } | |
486 | ||
487 | bool wxSpinCtrl::Enable(bool enable) | |
488 | { | |
489 | if ( !wxControl::Enable(enable) ) | |
490 | { | |
491 | return FALSE; | |
492 | } | |
493 | ||
6fe19057 | 494 | ::EnableWindow(GetBuddyHwnd(), enable); |
882a8f40 VZ |
495 | |
496 | return TRUE; | |
497 | } | |
498 | ||
8bf3196d GRG |
499 | void wxSpinCtrl::SetFocus() |
500 | { | |
6fe19057 | 501 | ::SetFocus(GetBuddyHwnd()); |
8bf3196d GRG |
502 | } |
503 | ||
9750fc42 VZ |
504 | // ---------------------------------------------------------------------------- |
505 | // event processing | |
506 | // ---------------------------------------------------------------------------- | |
507 | ||
508 | void wxSpinCtrl::OnSpinChange(wxSpinEvent& eventSpin) | |
509 | { | |
510 | wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId()); | |
511 | event.SetEventObject(this); | |
512 | event.SetInt(eventSpin.GetPosition()); | |
513 | ||
514 | (void)GetEventHandler()->ProcessEvent(event); | |
515 | ||
516 | if ( eventSpin.GetSkipped() ) | |
517 | { | |
518 | event.Skip(); | |
519 | } | |
520 | } | |
521 | ||
b782f2e0 VZ |
522 | // ---------------------------------------------------------------------------- |
523 | // size calculations | |
524 | // ---------------------------------------------------------------------------- | |
525 | ||
f68586e5 | 526 | wxSize wxSpinCtrl::DoGetBestSize() const |
baccb514 VZ |
527 | { |
528 | wxSize sizeBtn = wxSpinButton::DoGetBestSize(); | |
529 | sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; | |
530 | ||
531 | int y; | |
532 | wxGetCharSize(GetHWND(), NULL, &y, &GetFont()); | |
533 | y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y); | |
534 | ||
09f27917 JS |
535 | // JACS: we should always use the height calculated |
536 | // from above, because otherwise we'll get a spin control | |
537 | // that's too big. So never use the height calculated | |
538 | // from wxSpinButton::DoGetBestSize(). | |
539 | ||
540 | // if ( sizeBtn.y < y ) | |
baccb514 VZ |
541 | { |
542 | // make the text tall enough | |
543 | sizeBtn.y = y; | |
544 | } | |
545 | ||
546 | return sizeBtn; | |
547 | } | |
548 | ||
b782f2e0 VZ |
549 | void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) |
550 | { | |
baccb514 | 551 | int widthBtn = wxSpinButton::DoGetBestSize().x; |
b782f2e0 VZ |
552 | int widthText = width - widthBtn - MARGIN_BETWEEN; |
553 | if ( widthText <= 0 ) | |
554 | { | |
555 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
556 | } | |
557 | ||
6fe19057 | 558 | if ( !::MoveWindow(GetBuddyHwnd(), x, y, widthText, height, TRUE) ) |
b782f2e0 | 559 | { |
f6bcfd97 | 560 | wxLogLastError(wxT("MoveWindow(buddy)")); |
b782f2e0 VZ |
561 | } |
562 | ||
563 | x += widthText + MARGIN_BETWEEN; | |
564 | if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) ) | |
565 | { | |
f6bcfd97 | 566 | wxLogLastError(wxT("MoveWindow")); |
b782f2e0 VZ |
567 | } |
568 | } | |
569 | ||
f6bcfd97 BP |
570 | // get total size of the control |
571 | void wxSpinCtrl::DoGetSize(int *x, int *y) const | |
572 | { | |
573 | RECT spinrect, textrect, ctrlrect; | |
574 | GetWindowRect(GetHwnd(), &spinrect); | |
6fe19057 | 575 | GetWindowRect(GetBuddyHwnd(), &textrect); |
f6bcfd97 BP |
576 | UnionRect(&ctrlrect,&textrect, &spinrect); |
577 | ||
578 | if ( x ) | |
579 | *x = ctrlrect.right - ctrlrect.left; | |
580 | if ( y ) | |
581 | *y = ctrlrect.bottom - ctrlrect.top; | |
582 | } | |
583 | ||
584 | void wxSpinCtrl::DoGetPosition(int *x, int *y) const | |
585 | { | |
586 | // hack: pretend that our HWND is the text control just for a moment | |
587 | WXHWND hWnd = GetHWND(); | |
588 | wxConstCast(this, wxSpinCtrl)->m_hWnd = m_hwndBuddy; | |
589 | ||
590 | wxSpinButton::DoGetPosition(x, y); | |
591 | ||
592 | wxConstCast(this, wxSpinCtrl)->m_hWnd = hWnd; | |
593 | } | |
594 | ||
b782f2e0 | 595 | #endif // __WIN95__ |
0e528b99 JS |
596 | |
597 | #endif | |
598 | // wxUSE_SPINCTRL | |
599 |