]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/spinctlg.h
corrected wxICON for Mac OS (Classic and X)
[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
9// Licence: wxWindows licence
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
23#if wxUSE_SPINBTN
24
fd88dcbc
GD
25#ifdef __GNUG__
26 #pragma interface "spinctlg.h"
27#endif
28
1e6feb95
VZ
29class WXDLLEXPORT wxSpinButton;
30class WXDLLEXPORT wxTextCtrl;
31
32// ----------------------------------------------------------------------------
33// wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
34// ----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxSpinCtrl : public wxControl
37{
38public:
39 wxSpinCtrl() { Init(); }
40
41 wxSpinCtrl(wxWindow *parent,
42 wxWindowID id = -1,
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"))
49 {
50 Create(parent, id, value, pos, size, style, min, max, initial, name);
51 }
52
53 bool Create(wxWindow *parent,
54 wxWindowID id = -1,
55 const wxString& value = wxEmptyString,
56 const wxPoint& pos = wxDefaultPosition,
57 const wxSize& size = wxDefaultSize,
58 long style = wxSP_ARROW_KEYS,
59 int min = 0, int max = 100, int initial = 0,
60 const wxString& name = _T("wxSpinCtrl"));
61
62 virtual ~wxSpinCtrl();
63
64 // operations
65 void SetValue(int val);
66 void SetValue(const wxString& text);
67 void SetRange(int min, int max);
68
69 // accessors
70 int GetValue() const;
71 int GetMin() const;
72 int GetMax() const;
73
74 // implementation from now on
75
76 // forward these functions to all subcontrols
77 virtual bool Enable(bool enable = TRUE);
78 virtual bool Show(bool show = TRUE);
79
80 // get the subcontrols
81 wxTextCtrl *GetText() const { return m_text; }
82 wxSpinButton *GetSpinButton() const { return m_btn; }
83
84 // set the value of the text (only)
85 void SetTextValue(int val);
86
87 // put the numeric value of the string in the text ctrl into val and return
88 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
89 // number is out of range
90 bool GetTextValue(int *val) const;
91
92protected:
93 // override the base class virtuals involved into geometry calculations
94 virtual wxSize DoGetBestClientSize() const;
95 virtual void DoMoveWindow(int x, int y, int width, int height);
96
97 // common part of all ctors
98 void Init();
99
100private:
101 // the subcontrols
102 wxTextCtrl *m_text;
103 wxSpinButton *m_btn;
104};
105
106#else // !wxUSE_SPINBTN
669a6e11
VZ
107
108// ----------------------------------------------------------------------------
1e6feb95 109// wxSpinCtrl is just a text control
669a6e11
VZ
110// ----------------------------------------------------------------------------
111
1e6feb95
VZ
112#include "wx/textctrl.h"
113
669a6e11
VZ
114class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
115{
116public:
c71830c3
VZ
117 wxSpinCtrl() { Init(); }
118
119 wxSpinCtrl(wxWindow *parent,
120 wxWindowID id = -1,
121 const wxString& value = wxEmptyString,
122 const wxPoint& pos = wxDefaultPosition,
123 const wxSize& size = wxDefaultSize,
124 long style = wxSP_ARROW_KEYS,
125 int min = 0, int max = 100, int initial = 0,
126 const wxString& name = _T("wxSpinCtrl"))
127 {
128 Create(parent, id, value, pos, size, style, min, max, initial, name);
129 }
130
131 bool Create(wxWindow *parent,
132 wxWindowID id = -1,
133 const wxString& value = wxEmptyString,
134 const wxPoint& pos = wxDefaultPosition,
135 const wxSize& size = wxDefaultSize,
136 long style = wxSP_ARROW_KEYS,
137 int min = 0, int max = 100, int initial = 0,
138 const wxString& name = _T("wxSpinCtrl"))
139 {
c71830c3
VZ
140 SetRange(min, max);
141
2f5292c3
VZ
142 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
143 wxDefaultValidator, name);
6adaedf0 144 SetValue(initial);
2f5292c3
VZ
145
146 return ok;
c71830c3 147 }
669a6e11
VZ
148
149 // accessors
c71830c3 150 int GetValue(int WXUNUSED(dummy) = 1) const
669a6e11
VZ
151 {
152 int n;
153 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
154 n = INT_MIN;
155
156 return n;
157 }
158
159 int GetMin() const { return m_min; }
160 int GetMax() const { return m_max; }
161
162 // operations
163 void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); }
164 void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); }
165 void SetRange(int min, int max) { m_min = min; m_max = max; }
166
167protected:
168 // initialize m_min/max with the default values
169 void Init() { SetRange(0, 100); }
170
171 int m_min;
172 int m_max;
5fde6fcc
GD
173
174private:
175 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
669a6e11
VZ
176};
177
1e6feb95
VZ
178#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
179
669a6e11
VZ
180#endif // _WX_GENERIC_SPINCTRL_H_
181