]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/spinctrl.h
Add wxDataViewListCtrl::GetItemCount().
[wxWidgets.git] / include / wx / osx / spinctrl.h
CommitLineData
6762286d 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/osx/spinctrl.h
6762286d
SC
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_MAC_SPINCTRL_H_
13#define _WX_MAC_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
f1ddb476 23#if wxUSE_SPINBTN
6762286d
SC
24
25#include "wx/containr.h"
26
27class WXDLLIMPEXP_FWD_CORE wxSpinButton;
28class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
29class WXDLLIMPEXP_FWD_CORE wxSpinCtrlText;
30class WXDLLIMPEXP_FWD_CORE wxSpinCtrlButton;
31
32// ----------------------------------------------------------------------------
33// wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
34// ----------------------------------------------------------------------------
35
90230407 36class WXDLLIMPEXP_CORE wxSpinCtrl : public wxNavigationEnabled<wxControl>
6762286d
SC
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,
f1ddb476 46 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
6762286d 47 int min = 0, int max = 100, int initial = 0,
9a83f860 48 const wxString& name = wxT("wxSpinCtrl"))
6762286d
SC
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,
f1ddb476 59 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
6762286d 60 int min = 0, int max = 100, int initial = 0,
9a83f860 61 const wxString& name = wxT("wxSpinCtrl"));
6762286d
SC
62
63 // wxTextCtrl-like method
64 void SetSelection(long from, long to);
65
66 virtual ~wxSpinCtrl();
67
68 // operations
69 void SetValue(int val);
70 void SetValue(const wxString& text);
71 void SetRange(int min, int max);
72
73 // accessors
74 int GetValue() const;
75 int GetMin() const;
76 int GetMax() const;
77
78 // implementation from now on
79
80 // forward these functions to all subcontrols
8e6efd1f
PC
81 virtual bool Enable(bool enable = true);
82 virtual bool Show(bool show = true);
6762286d
SC
83
84 // get the subcontrols
85 wxTextCtrl *GetText() const { return m_text; }
86 wxSpinButton *GetSpinButton() const { return m_btn; }
87
88 // set the value of the text (only)
89 void SetTextValue(int val);
90
91 // put the numeric value of the string in the text ctrl into val and return
92 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
93 // number is out of range
94 bool GetTextValue(int *val) const;
95
6762286d
SC
96protected:
97 // override the base class virtuals involved into geometry calculations
98 virtual wxSize DoGetBestSize() const;
99 virtual void DoMoveWindow(int x, int y, int width, int height);
100
101 // common part of all ctors
102 void Init();
103
104private:
105 // the subcontrols
106 wxTextCtrl *m_text;
107 wxSpinButton *m_btn;
f1ddb476 108
6762286d
SC
109 friend class wxSpinCtrlText;
110 friend class wxSpinCtrlButton;
f1ddb476 111
6762286d
SC
112 int m_oldValue;
113private:
6762286d
SC
114 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
115};
116
117#else // !wxUSE_SPINBTN
118
119// ----------------------------------------------------------------------------
120// wxSpinCtrl is just a text control
121// ----------------------------------------------------------------------------
122
123#include "wx/textctrl.h"
124
125class WXDLLIMPEXP_CORE wxSpinCtrl : public wxTextCtrl
126{
127public:
128 wxSpinCtrl() { Init(); }
129
130 wxSpinCtrl(wxWindow *parent,
131 wxWindowID id = -1,
132 const wxString& value = wxEmptyString,
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
f1ddb476 135 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
6762286d 136 int min = 0, int max = 100, int initial = 0,
9a83f860 137 const wxString& name = wxT("wxSpinCtrl"))
6762286d
SC
138 {
139 Create(parent, id, value, pos, size, style, min, max, initial, name);
140 }
141
142 bool Create(wxWindow *parent,
143 wxWindowID id = -1,
144 const wxString& value = wxEmptyString,
145 const wxPoint& pos = wxDefaultPosition,
146 const wxSize& size = wxDefaultSize,
f1ddb476 147 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
6762286d 148 int min = 0, int max = 100, int initial = 0,
9a83f860 149 const wxString& name = wxT("wxSpinCtrl"))
6762286d
SC
150 {
151 SetRange(min, max);
152
153 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
154 wxDefaultValidator, name);
155 SetValue(initial);
156
157 return ok;
158 }
159
160 // accessors
161 int GetValue(int WXUNUSED(dummy) = 1) const
162 {
163 int n;
164 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
165 n = INT_MIN;
166
167 return n;
168 }
169
170 int GetMin() const { return m_min; }
171 int GetMax() const { return m_max; }
172
173 // operations
174 void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); }
175 void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); }
176 void SetRange(int min, int max) { m_min = min; m_max = max; }
177
178protected:
179 // initialize m_min/max with the default values
180 void Init() { SetRange(0, 100); }
181
182 int m_min;
183 int m_max;
184
185private:
186 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
187};
188
189#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
190
191#endif // _WX_MAC_SPINCTRL_H_
192