]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
26 #pragma interface "spinctlg.h"
29 class WXDLLEXPORT wxSpinButton
;
30 class WXDLLEXPORT wxTextCtrl
;
32 // ----------------------------------------------------------------------------
33 // wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxSpinCtrl
: public wxControl
39 wxSpinCtrl() { Init(); }
41 wxSpinCtrl(wxWindow
*parent
,
43 const wxString
& value
= wxEmptyString
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
46 long style
= wxSP_ARROW_KEYS
,
47 int min
= 0, int max
= 100, int initial
= 0,
48 const wxString
& name
= _T("wxSpinCtrl"))
51 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
54 bool Create(wxWindow
*parent
,
56 const wxString
& value
= wxEmptyString
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
59 long style
= wxSP_ARROW_KEYS
,
60 int min
= 0, int max
= 100, int initial
= 0,
61 const wxString
& name
= _T("wxSpinCtrl"));
63 virtual ~wxSpinCtrl();
66 void SetValue(int val
);
67 void SetValue(const wxString
& text
);
68 void SetRange(int min
, int max
);
69 void SetSelection(long from
, long to
);
76 // implementation from now on
78 // forward these functions to all subcontrols
79 virtual bool Enable(bool enable
= TRUE
);
80 virtual bool Show(bool show
= TRUE
);
82 // get the subcontrols
83 wxTextCtrl
*GetText() const { return m_text
; }
84 wxSpinButton
*GetSpinButton() const { return m_btn
; }
86 // set the value of the text (only)
87 void SetTextValue(int val
);
89 // put the numeric value of the string in the text ctrl into val and return
90 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
91 // number is out of range
92 bool GetTextValue(int *val
) const;
95 // override the base class virtuals involved into geometry calculations
96 virtual wxSize
DoGetBestSize() const;
97 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
99 // common part of all ctors
108 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
111 #else // !wxUSE_SPINBTN
113 // ----------------------------------------------------------------------------
114 // wxSpinCtrl is just a text control
115 // ----------------------------------------------------------------------------
117 #include "wx/textctrl.h"
119 class WXDLLEXPORT wxSpinCtrl
: public wxTextCtrl
122 wxSpinCtrl() { Init(); }
124 wxSpinCtrl(wxWindow
*parent
,
126 const wxString
& value
= wxEmptyString
,
127 const wxPoint
& pos
= wxDefaultPosition
,
128 const wxSize
& size
= wxDefaultSize
,
129 long style
= wxSP_ARROW_KEYS
,
130 int min
= 0, int max
= 100, int initial
= 0,
131 const wxString
& name
= _T("wxSpinCtrl"))
133 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
136 bool Create(wxWindow
*parent
,
138 const wxString
& value
= wxEmptyString
,
139 const wxPoint
& pos
= wxDefaultPosition
,
140 const wxSize
& size
= wxDefaultSize
,
141 long style
= wxSP_ARROW_KEYS
,
142 int min
= 0, int max
= 100, int initial
= 0,
143 const wxString
& name
= _T("wxSpinCtrl"))
147 bool ok
= wxTextCtrl::Create(parent
, id
, value
, pos
, size
, style
,
148 wxDefaultValidator
, name
);
155 int GetValue(int WXUNUSED(dummy
) = 1) const
158 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n
) != 1) )
164 int GetMin() const { return m_min
; }
165 int GetMax() const { return m_max
; }
168 void SetValue(const wxString
& value
) { wxTextCtrl::SetValue(value
); }
169 void SetValue(int val
) { wxString s
; s
<< val
; wxTextCtrl::SetValue(s
); }
170 void SetRange(int min
, int max
) { m_min
= min
; m_max
= max
; }
173 // initialize m_min/max with the default values
174 void Init() { SetRange(0, 100); }
180 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
183 #endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
185 #endif // _WX_GENERIC_SPINCTRL_H_