]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/spinctlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/spinctlg.h
3 // Purpose: generic wxSpinCtrl class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_SPINCTRL_H_
13 #define _WX_GENERIC_SPINCTRL_H_
15 // ----------------------------------------------------------------------------
16 // wxSpinCtrl is a combination of wxSpinButton and wxTextCtrl, so if
17 // wxSpinButton is available, this is what we do - but if it isn't, we still
18 // define wxSpinCtrl class which then has the same appearance as wxTextCtrl but
19 // the different interface. This allows to write programs using wxSpinCtrl
20 // without tons of #ifdefs.
21 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxSpinButton
;
26 class WXDLLEXPORT wxTextCtrl
;
28 // ----------------------------------------------------------------------------
29 // wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
30 // ----------------------------------------------------------------------------
32 class WXDLLEXPORT wxSpinCtrl
: public wxControl
35 wxSpinCtrl() { Init(); }
37 wxSpinCtrl(wxWindow
*parent
,
38 wxWindowID id
= wxID_ANY
,
39 const wxString
& value
= wxEmptyString
,
40 const wxPoint
& pos
= wxDefaultPosition
,
41 const wxSize
& size
= wxDefaultSize
,
42 long style
= wxSP_ARROW_KEYS
,
43 int min
= 0, int max
= 100, int initial
= 0,
44 const wxString
& name
= _T("wxSpinCtrl"))
47 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
50 bool Create(wxWindow
*parent
,
51 wxWindowID id
= wxID_ANY
,
52 const wxString
& value
= wxEmptyString
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
55 long style
= wxSP_ARROW_KEYS
,
56 int min
= 0, int max
= 100, int initial
= 0,
57 const wxString
& name
= _T("wxSpinCtrl"));
59 virtual ~wxSpinCtrl();
62 void SetValue(int val
);
63 void SetValue(const wxString
& text
);
64 void SetRange(int min
, int max
);
65 void SetSelection(long from
, long to
);
72 // implementation from now on
74 // forward these functions to all subcontrols
75 virtual bool Enable(bool enable
= true);
76 virtual bool Show(bool show
= true);
78 // get the subcontrols
79 wxTextCtrl
*GetText() const { return m_text
; }
80 wxSpinButton
*GetSpinButton() const { return m_btn
; }
82 // set the value of the text (only)
83 void SetTextValue(int val
);
85 // put the numeric value of the string in the text ctrl into val and return
86 // true or return false if the text ctrl doesn't contain a number or if the
87 // number is out of range
88 bool GetTextValue(int *val
) const;
91 // override the base class virtuals involved into geometry calculations
92 virtual wxSize
DoGetBestSize() const;
93 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
95 // common part of all ctors
104 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
107 #else // !wxUSE_SPINBTN
109 // ----------------------------------------------------------------------------
110 // wxSpinCtrl is just a text control
111 // ----------------------------------------------------------------------------
113 #include "wx/textctrl.h"
115 class WXDLLEXPORT wxSpinCtrl
: public wxTextCtrl
118 wxSpinCtrl() { Init(); }
120 wxSpinCtrl(wxWindow
*parent
,
121 wxWindowID id
= wxID_ANY
,
122 const wxString
& value
= wxEmptyString
,
123 const wxPoint
& pos
= wxDefaultPosition
,
124 const wxSize
& size
= wxDefaultSize
,
125 long style
= wxSP_ARROW_KEYS
,
126 int min
= 0, int max
= 100, int initial
= 0,
127 const wxString
& name
= _T("wxSpinCtrl"))
129 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
132 bool Create(wxWindow
*parent
,
133 wxWindowID id
= wxID_ANY
,
134 const wxString
& value
= wxEmptyString
,
135 const wxPoint
& pos
= wxDefaultPosition
,
136 const wxSize
& size
= wxDefaultSize
,
137 long style
= wxSP_ARROW_KEYS
,
138 int min
= 0, int max
= 100, int initial
= 0,
139 const wxString
& name
= _T("wxSpinCtrl"))
143 bool ok
= wxTextCtrl::Create(parent
, id
, value
, pos
, size
, style
,
144 wxDefaultValidator
, name
);
151 int GetValue(int WXUNUSED(dummy
) = 1) const
154 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n
) != 1) )
160 int GetMin() const { return m_min
; }
161 int GetMax() const { return m_max
; }
164 void SetValue(const wxString
& value
) { wxTextCtrl::SetValue(value
); }
165 void SetValue(int val
) { wxString s
; s
<< val
; wxTextCtrl::SetValue(s
); }
166 void SetRange(int min
, int max
) { m_min
= min
; m_max
= max
; }
169 // initialize m_min/max with the default values
170 void Init() { SetRange(0, 100); }
176 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
179 #endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
181 #endif // _WX_GENERIC_SPINCTRL_H_