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