]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/spinctlg.h
fix ifdef - its libpng not pnglib :)
[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
12028905 25#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
fd88dcbc
GD
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,
ca65c044 42 wxWindowID id = wxID_ANY,
1e6feb95
VZ
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 {
70c2fde3 50 Init();
1e6feb95
VZ
51 Create(parent, id, value, pos, size, style, min, max, initial, name);
52 }
53
54 bool Create(wxWindow *parent,
ca65c044 55 wxWindowID id = wxID_ANY,
1e6feb95
VZ
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);
739555e3 69 void SetSelection(long from, long to);
1e6feb95
VZ
70
71 // accessors
72 int GetValue() const;
73 int GetMin() const;
74 int GetMax() const;
75
76 // implementation from now on
77
78 // forward these functions to all subcontrols
ca65c044
WS
79 virtual bool Enable(bool enable = true);
80 virtual bool Show(bool show = true);
1e6feb95
VZ
81
82 // get the subcontrols
83 wxTextCtrl *GetText() const { return m_text; }
84 wxSpinButton *GetSpinButton() const { return m_btn; }
85
86 // set the value of the text (only)
87 void SetTextValue(int val);
88
89 // put the numeric value of the string in the text ctrl into val and return
ca65c044 90 // true or return false if the text ctrl doesn't contain a number or if the
1e6feb95
VZ
91 // number is out of range
92 bool GetTextValue(int *val) const;
93
94protected:
95 // override the base class virtuals involved into geometry calculations
dba00620 96 virtual wxSize DoGetBestSize() const;
1e6feb95
VZ
97 virtual void DoMoveWindow(int x, int y, int width, int height);
98
99 // common part of all ctors
100 void Init();
101
102private:
103 // the subcontrols
104 wxTextCtrl *m_text;
105 wxSpinButton *m_btn;
739555e3 106
6c0ba0d0
GD
107private:
108 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
1e6feb95
VZ
109};
110
111#else // !wxUSE_SPINBTN
669a6e11
VZ
112
113// ----------------------------------------------------------------------------
1e6feb95 114// wxSpinCtrl is just a text control
669a6e11
VZ
115// ----------------------------------------------------------------------------
116
1e6feb95
VZ
117#include "wx/textctrl.h"
118
669a6e11
VZ
119class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
120{
121public:
c71830c3
VZ
122 wxSpinCtrl() { Init(); }
123
124 wxSpinCtrl(wxWindow *parent,
ca65c044 125 wxWindowID id = wxID_ANY,
c71830c3
VZ
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"))
132 {
133 Create(parent, id, value, pos, size, style, min, max, initial, name);
134 }
135
136 bool Create(wxWindow *parent,
ca65c044 137 wxWindowID id = wxID_ANY,
c71830c3
VZ
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"))
144 {
c71830c3
VZ
145 SetRange(min, max);
146
2f5292c3
VZ
147 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
148 wxDefaultValidator, name);
6adaedf0 149 SetValue(initial);
2f5292c3
VZ
150
151 return ok;
c71830c3 152 }
669a6e11
VZ
153
154 // accessors
c71830c3 155 int GetValue(int WXUNUSED(dummy) = 1) const
669a6e11
VZ
156 {
157 int n;
158 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
159 n = INT_MIN;
160
161 return n;
162 }
163
164 int GetMin() const { return m_min; }
165 int GetMax() const { return m_max; }
166
167 // operations
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; }
171
172protected:
173 // initialize m_min/max with the default values
174 void Init() { SetRange(0, 100); }
175
176 int m_min;
177 int m_max;
5fde6fcc
GD
178
179private:
180 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
669a6e11
VZ
181};
182
1e6feb95
VZ
183#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
184
669a6e11
VZ
185#endif // _WX_GENERIC_SPINCTRL_H_
186