1 //////////////////////////////////////////////////////////////////////////// 2 // Name: msw/spinctrl.h 3 // Purpose: wxSpinCtrl class declaration for Win32 4 // Author: Vadim Zeitlin 5 // Modified by: 6 // Created: 22.07.99 7 // RCS-ID: $Id: spinctrl.h 53135 2008-04-12 02:31:04Z VZ $ 8 // Copyright: (c) Vadim Zeitlin 9 // Licence: wxWindows licence 10 ///////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_MSW_SPINCTRL_H_ 13 #define _WX_MSW_SPINCTRL_H_ 14 15 #include "wx/spinbutt.h" // the base class 16 17 #if wxUSE_SPINCTRL 18 19 #include "wx/dynarray.h" 20 21 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; 22 WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl *, wxArraySpins); 23 24 // ---------------------------------------------------------------------------- 25 // Under Win32, wxSpinCtrl is a wxSpinButton with a buddy (as MSDN docs call 26 // it) text window whose contents is automatically updated when the spin 27 // control is clicked. 28 // ---------------------------------------------------------------------------- 29 30 class WXDLLEXPORT wxSpinCtrl : public wxSpinButton 31 { 32 public: wxSpinCtrl()33 wxSpinCtrl() { } 34 35 wxSpinCtrl(wxWindow *parent, 36 wxWindowID id = wxID_ANY, 37 const wxString& value = wxEmptyString, 38 const wxPoint& pos = wxDefaultPosition, 39 const wxSize& size = wxDefaultSize, 40 long style = wxSP_ARROW_KEYS, 41 int min = 0, int max = 100, int initial = 0, 42 const wxString& name = _T("wxSpinCtrl")) 43 { 44 Create(parent, id, value, pos, size, style, min, max, initial, name); 45 } 46 47 bool Create(wxWindow *parent, 48 wxWindowID id = wxID_ANY, 49 const wxString& value = wxEmptyString, 50 const wxPoint& pos = wxDefaultPosition, 51 const wxSize& size = wxDefaultSize, 52 long style = wxSP_ARROW_KEYS, 53 int min = 0, int max = 100, int initial = 0, 54 const wxString& name = _T("wxSpinCtrl")); 55 56 // a wxTextCtrl-like method (but we can't have GetValue returning wxString 57 // because the base class already has one returning int!) 58 void SetValue(const wxString& text); 59 60 // another wxTextCtrl-like method 61 void SetSelection(long from, long to); 62 63 // implementation only from now on 64 // ------------------------------- 65 66 virtual ~wxSpinCtrl(); 67 68 virtual void SetValue(int val); 69 virtual int GetValue() const; 70 virtual bool SetFont(const wxFont &font); 71 virtual void SetFocus(); 72 73 virtual bool Enable(bool enable = true); 74 virtual bool Show(bool show = true); 75 76 virtual bool Reparent(wxWindowBase *newParent); 77 78 // wxSpinButton doesn't accept focus, but we do AcceptsFocus()79 virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); } 80 81 // for internal use only 82 83 // get the subclassed window proc of the buddy text GetBuddyWndProc()84 WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; } 85 86 // return the spinctrl object whose buddy is the given window or NULL 87 static wxSpinCtrl *GetSpinForTextCtrl(WXHWND hwndBuddy); 88 89 // process a WM_COMMAND generated by the buddy text control 90 bool ProcessTextCommand(WXWORD cmd, WXWORD id); 91 92 protected: 93 virtual void DoGetPosition(int *x, int *y) const; 94 virtual void DoMoveWindow(int x, int y, int width, int height); 95 virtual wxSize DoGetBestSize() const; 96 virtual void DoGetSize(int *width, int *height) const; 97 #if wxABI_VERSION >= 20808 98 virtual void DoGetClientSize(int *x, int *y) const; 99 #endif 100 101 #if wxUSE_TOOLTIPS 102 virtual void DoSetToolTip( wxToolTip *tip ); 103 #endif // wxUSE_TOOLTIPS 104 105 // the handler for wxSpinButton events 106 void OnSpinChange(wxSpinEvent& event); 107 108 // handle processing of special keys 109 void OnChar(wxKeyEvent& event); 110 void OnSetFocus(wxFocusEvent& event); 111 void OnKillFocus(wxFocusEvent& event); 112 113 // generate spin control update event with the given value 114 void SendSpinUpdate(int value); 115 116 // called to ensure that the value is in the correct range 117 virtual void NormalizeValue(); 118 119 120 // the value of the control before the latest change (which might not have 121 // changed anything in fact -- this is why we need this field) 122 int m_oldValue; 123 124 // the data for the "buddy" text ctrl 125 WXHWND m_hwndBuddy; 126 WXFARPROC m_wndProcBuddy; 127 128 // all existing wxSpinCtrls - this allows to find the one corresponding to 129 // the given buddy window in GetSpinForTextCtrl() 130 static wxArraySpins ms_allSpins; 131 132 private: 133 DECLARE_DYNAMIC_CLASS(wxSpinCtrl) 134 DECLARE_EVENT_TABLE() 135 DECLARE_NO_COPY_CLASS(wxSpinCtrl) 136 }; 137 138 #endif // wxUSE_SPINCTRL 139 140 #endif // _WX_MSW_SPINCTRL_H_ 141 142 143