]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/spinctrl.h
still overriding the escape key
[wxWidgets.git] / include / wx / mac / carbon / spinctrl.h
CommitLineData
8cf73271
SC
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
8cf73271
SC
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
23#if wxUSE_SPINBTN
24
29c731ca
KH
25#include "wx/containr.h"
26
8cf73271
SC
27class WXDLLEXPORT wxSpinButton;
28class WXDLLEXPORT wxTextCtrl;
29
30// ----------------------------------------------------------------------------
31// wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
32// ----------------------------------------------------------------------------
33
34class WXDLLEXPORT wxSpinCtrl : public wxControl
35{
36public:
37 wxSpinCtrl() { Init(); }
38
39 wxSpinCtrl(wxWindow *parent,
40 wxWindowID id = -1,
41 const wxString& value = wxEmptyString,
42 const wxPoint& pos = wxDefaultPosition,
43 const wxSize& size = wxDefaultSize,
44 long style = wxSP_ARROW_KEYS,
45 int min = 0, int max = 100, int initial = 0,
46 const wxString& name = _T("wxSpinCtrl"))
47 {
48 Init();
49 Create(parent, id, value, pos, size, style, min, max, initial, name);
50 }
51
52 bool Create(wxWindow *parent,
53 wxWindowID id = -1,
54 const wxString& value = wxEmptyString,
55 const wxPoint& pos = wxDefaultPosition,
56 const wxSize& size = wxDefaultSize,
57 long style = wxSP_ARROW_KEYS,
58 int min = 0, int max = 100, int initial = 0,
59 const wxString& name = _T("wxSpinCtrl"));
60
61 // wxTextCtrl-like method
62 void SetSelection(long from, long to);
63
64 virtual ~wxSpinCtrl();
65
66 // operations
67 void SetValue(int val);
68 void SetValue(const wxString& text);
69 void SetRange(int min, int max);
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
79 virtual bool Enable(bool enable = TRUE);
80 virtual bool Show(bool show = TRUE);
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
90 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
91 // number is out of range
92 bool GetTextValue(int *val) const;
93
1de43645
SC
94 WX_DECLARE_CONTROL_CONTAINER();
95
8cf73271
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;
108
109private:
1de43645 110 DECLARE_EVENT_TABLE()
8cf73271
SC
111 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
112};
113
114#else // !wxUSE_SPINBTN
115
116// ----------------------------------------------------------------------------
117// wxSpinCtrl is just a text control
118// ----------------------------------------------------------------------------
119
120#include "wx/textctrl.h"
121
122class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
123{
124public:
125 wxSpinCtrl() { Init(); }
126
127 wxSpinCtrl(wxWindow *parent,
128 wxWindowID id = -1,
129 const wxString& value = wxEmptyString,
130 const wxPoint& pos = wxDefaultPosition,
131 const wxSize& size = wxDefaultSize,
132 long style = wxSP_ARROW_KEYS,
133 int min = 0, int max = 100, int initial = 0,
134 const wxString& name = _T("wxSpinCtrl"))
135 {
136 Create(parent, id, value, pos, size, style, min, max, initial, name);
137 }
138
139 bool Create(wxWindow *parent,
140 wxWindowID id = -1,
141 const wxString& value = wxEmptyString,
142 const wxPoint& pos = wxDefaultPosition,
143 const wxSize& size = wxDefaultSize,
144 long style = wxSP_ARROW_KEYS,
145 int min = 0, int max = 100, int initial = 0,
146 const wxString& name = _T("wxSpinCtrl"))
147 {
148 SetRange(min, max);
149
150 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
151 wxDefaultValidator, name);
152 SetValue(initial);
153
154 return ok;
155 }
156
157 // accessors
158 int GetValue(int WXUNUSED(dummy) = 1) const
159 {
160 int n;
161 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
162 n = INT_MIN;
163
164 return n;
165 }
166
167 int GetMin() const { return m_min; }
168 int GetMax() const { return m_max; }
169
170 // operations
171 void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); }
172 void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); }
173 void SetRange(int min, int max) { m_min = min; m_max = max; }
174
175protected:
176 // initialize m_min/max with the default values
177 void Init() { SetRange(0, 100); }
178
179 int m_min;
180 int m_max;
181
182private:
183 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
184};
185
186#endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
187
188#endif // _WX_MAC_SPINCTRL_H_
189