]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/spinctlg.h
moved wxUSE_CRASHREPORT checks to wx/msw/chkconf.h; added it to setup.h.in so that...
[wxWidgets.git] / include / wx / generic / spinctlg.h
CommitLineData
669a6e11
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/generic/spinctlg.h
3// Purpose: generic wxSpinCtrl class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 28.10.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
65571936 9// Licence: wxWindows licence
669a6e11
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_GENERIC_SPINCTRL_H_
13#define _WX_GENERIC_SPINCTRL_H_
14
1e6feb95
VZ
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// ----------------------------------------------------------------------------
22
739555e3 23#if wxUSE_SPINBTN
1e6feb95 24
b5dbe15d
VS
25class WXDLLIMPEXP_FWD_CORE wxSpinButton;
26class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
1e6feb95
VZ
27
28// ----------------------------------------------------------------------------
29// wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
30// ----------------------------------------------------------------------------
31
32class WXDLLEXPORT wxSpinCtrl : public wxControl
33{
34public:
35 wxSpinCtrl() { Init(); }
36
37 wxSpinCtrl(wxWindow *parent,
ca65c044 38 wxWindowID id = wxID_ANY,
1e6feb95
VZ
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"))
45 {
70c2fde3 46 Init();
1e6feb95
VZ
47 Create(parent, id, value, pos, size, style, min, max, initial, name);
48 }
49
50 bool Create(wxWindow *parent,
ca65c044 51 wxWindowID id = wxID_ANY,
1e6feb95
VZ
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"));
58
59 virtual ~wxSpinCtrl();
60
61 // operations
62 void SetValue(int val);
63 void SetValue(const wxString& text);
64 void SetRange(int min, int max);
739555e3 65 void SetSelection(long from, long to);
1e6feb95
VZ
66
67 // accessors
68 int GetValue() const;
69 int GetMin() const;
70 int GetMax() const;
71
72 // implementation from now on
73
74 // forward these functions to all subcontrols
ca65c044
WS
75 virtual bool Enable(bool enable = true);
76 virtual bool Show(bool show = true);
1e6feb95
VZ
77
78 // get the subcontrols
79 wxTextCtrl *GetText() const { return m_text; }
80 wxSpinButton *GetSpinButton() const { return m_btn; }
81
82 // set the value of the text (only)
83 void SetTextValue(int val);
84
85 // put the numeric value of the string in the text ctrl into val and return
ca65c044 86 // true or return false if the text ctrl doesn't contain a number or if the
1e6feb95
VZ
87 // number is out of range
88 bool GetTextValue(int *val) const;
89
90protected:
91 // override the base class virtuals involved into geometry calculations
dba00620 92 virtual wxSize DoGetBestSize() const;
1e6feb95
VZ
93 virtual void DoMoveWindow(int x, int y, int width, int height);
94
95 // common part of all ctors
96 void Init();
97
98private:
99 // the subcontrols
100 wxTextCtrl *m_text;
101 wxSpinButton *m_btn;
739555e3 102
6c0ba0d0
GD
103private:
104 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
1e6feb95
VZ
105};
106
107#else // !wxUSE_SPINBTN
669a6e11
VZ
108
109// ----------------------------------------------------------------------------
1e6feb95 110// wxSpinCtrl is just a text control
669a6e11
VZ
111// ----------------------------------------------------------------------------
112
1e6feb95
VZ
113#include "wx/textctrl.h"
114
669a6e11
VZ
115class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
116{
117public:
c71830c3
VZ
118 wxSpinCtrl() { Init(); }
119
120 wxSpinCtrl(wxWindow *parent,
ca65c044 121 wxWindowID id = wxID_ANY,
c71830c3
VZ
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"))
128 {
129 Create(parent, id, value, pos, size, style, min, max, initial, name);
130 }
131
132 bool Create(wxWindow *parent,
ca65c044 133 wxWindowID id = wxID_ANY,
c71830c3
VZ
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"))
140 {
c71830c3
VZ
141 SetRange(min, max);
142
2f5292c3
VZ
143 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
144 wxDefaultValidator, name);
6adaedf0 145 SetValue(initial);
2f5292c3
VZ
146
147 return ok;
c71830c3 148 }
669a6e11
VZ
149
150 // accessors
c71830c3 151 int GetValue(int WXUNUSED(dummy) = 1) const
669a6e11
VZ
152 {
153 int n;
154 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
155 n = INT_MIN;
156
157 return n;
158 }
159
160 int GetMin() const { return m_min; }
161 int GetMax() const { return m_max; }
162
163 // operations
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; }
167
168protected:
169 // initialize m_min/max with the default values
170 void Init() { SetRange(0, 100); }
171
172 int m_min;
173 int m_max;
5fde6fcc
GD
174
175private:
176 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
669a6e11
VZ
177};
178
1e6feb95
VZ
179#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
180
669a6e11
VZ
181#endif // _WX_GENERIC_SPINCTRL_H_
182