1 ////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/spinctrl.h
3 // Purpose: wxSpinCtrl class declaration for Win32
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSW_SPINCTRL_H_
13 #define _WX_MSW_SPINCTRL_H_
15 #include "wx/spinbutt.h" // the base class
19 #include "wx/dynarray.h"
21 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
22 WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl
*, wxArraySpins
);
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 // ----------------------------------------------------------------------------
30 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxSpinButton
33 wxSpinCtrl() { Init(); }
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
| wxALIGN_RIGHT
,
41 int min
= 0, int max
= 100, int initial
= 0,
42 const wxString
& name
= wxT("wxSpinCtrl"))
46 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
49 bool Create(wxWindow
*parent
,
50 wxWindowID id
= wxID_ANY
,
51 const wxString
& value
= wxEmptyString
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
54 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
55 int min
= 0, int max
= 100, int initial
= 0,
56 const wxString
& name
= wxT("wxSpinCtrl"));
58 // a wxTextCtrl-like method (but we can't have GetValue returning wxString
59 // because the base class already has one returning int!)
60 void SetValue(const wxString
& text
);
62 // another wxTextCtrl-like method
63 void SetSelection(long from
, long to
);
65 // implementation only from now on
66 // -------------------------------
68 virtual ~wxSpinCtrl();
70 virtual void SetValue(int val
);
71 virtual int GetValue() const;
72 virtual void SetRange(int minVal
, int maxVal
);
73 virtual bool SetFont(const wxFont
&font
);
74 virtual void SetFocus();
76 virtual bool Enable(bool enable
= true);
77 virtual bool Show(bool show
= true);
79 virtual bool Reparent(wxWindowBase
*newParent
);
81 // wxSpinButton doesn't accept focus, but we do
82 virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
84 // we're like wxTextCtrl and not (default) wxButton
85 virtual wxVisualAttributes
GetDefaultAttributes() const
87 return GetClassDefaultAttributes(GetWindowVariant());
90 static wxVisualAttributes
91 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
93 return GetCompositeControlsDefaultAttributes(variant
);
96 // for internal use only
98 // get the subclassed window proc of the buddy text
99 WXFARPROC
GetBuddyWndProc() const { return m_wndProcBuddy
; }
101 // return the spinctrl object whose buddy is the given window or NULL
102 static wxSpinCtrl
*GetSpinForTextCtrl(WXHWND hwndBuddy
);
104 // process a WM_COMMAND generated by the buddy text control
105 bool ProcessTextCommand(WXWORD cmd
, WXWORD id
);
107 // recognize buddy window as part of this control at wx level
108 virtual bool ContainsHWND(WXHWND hWnd
) const { return hWnd
== m_hwndBuddy
; }
111 virtual void DoGetPosition(int *x
, int *y
) const;
112 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
113 virtual wxSize
DoGetBestSize() const;
114 virtual void DoGetSize(int *width
, int *height
) const;
115 virtual void DoGetClientSize(int *x
, int *y
) const;
117 virtual void DoSetToolTip( wxToolTip
*tip
);
118 #endif // wxUSE_TOOLTIPS
120 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
121 virtual bool MSWOnScroll(int orientation
, WXWORD wParam
,
122 WXWORD pos
, WXHWND control
);
124 // handle processing of special keys
125 void OnChar(wxKeyEvent
& event
);
126 void OnSetFocus(wxFocusEvent
& event
);
127 void OnKillFocus(wxFocusEvent
& event
);
129 // generate spin control update event with the given value
130 void SendSpinUpdate(int value
);
132 // called to ensure that the value is in the correct range
133 virtual void NormalizeValue();
136 // the value of the control before the latest change (which might not have
137 // changed anything in fact -- this is why we need this field)
140 // the data for the "buddy" text ctrl
142 WXFARPROC m_wndProcBuddy
;
144 // Block text update event after SetValue()
148 // Common part of all ctors.
151 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
152 DECLARE_EVENT_TABLE()
153 wxDECLARE_NO_COPY_CLASS(wxSpinCtrl
);
156 #endif // wxUSE_SPINCTRL
158 #endif // _WX_MSW_SPINCTRL_H_