]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/gtk/spinctrl.h | |
3 | // Purpose: wxSpinCtrl class | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_GTK_SPINCTRL_H_ | |
12 | #define _WX_GTK_SPINCTRL_H_ | |
13 | ||
14 | //----------------------------------------------------------------------------- | |
15 | // wxSpinCtrlGTKBase - Base class for GTK versions of the wxSpinCtrl[Double] | |
16 | // | |
17 | // This class manages a double valued GTK spinctrl through the DoGet/SetXXX | |
18 | // functions that are made public as Get/SetXXX functions for int or double | |
19 | // for the wxSpinCtrl and wxSpinCtrlDouble classes respectively to avoid | |
20 | // function ambiguity. | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase : public wxSpinCtrlBase | |
24 | { | |
25 | public: | |
26 | bool Create(wxWindow *parent, | |
27 | wxWindowID id, | |
28 | const wxString& value, | |
29 | const wxPoint& pos, | |
30 | const wxSize& size, | |
31 | long style, | |
32 | double min, double max, double initial, | |
33 | double inc, | |
34 | const wxString& name); | |
35 | ||
36 | // wxSpinCtrl(Double) methods call DoXXX functions of the same name | |
37 | ||
38 | // accessors | |
39 | // T GetValue() const | |
40 | // T GetMin() const | |
41 | // T GetMax() const | |
42 | // T GetIncrement() const | |
43 | virtual bool GetSnapToTicks() const; | |
44 | ||
45 | // operations | |
46 | virtual void SetValue(const wxString& value); | |
47 | // void SetValue(T val) | |
48 | // void SetRange(T minVal, T maxVal) | |
49 | // void SetIncrement(T inc) | |
50 | void SetSnapToTicks( bool snap_to_ticks ); | |
51 | ||
52 | // Select text in the textctrl | |
53 | void SetSelection(long from, long to); | |
54 | ||
55 | static wxVisualAttributes | |
56 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
57 | ||
58 | // implementation | |
59 | void OnChar( wxKeyEvent &event ); | |
60 | ||
61 | protected: | |
62 | double DoGetValue() const; | |
63 | double DoGetMin() const; | |
64 | double DoGetMax() const; | |
65 | double DoGetIncrement() const; | |
66 | ||
67 | void DoSetValue(double val); | |
68 | void DoSetValue(const wxString& strValue); | |
69 | void DoSetRange(double min_val, double max_val); | |
70 | void DoSetIncrement(double inc); | |
71 | ||
72 | void GtkDisableEvents() const; | |
73 | void GtkEnableEvents() const; | |
74 | ||
75 | virtual wxSize DoGetBestSize() const; | |
76 | virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const; | |
77 | virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; | |
78 | ||
79 | // Widgets that use the style->base colour for the BG colour should | |
80 | // override this and return true. | |
81 | virtual bool UseGTKStyleBase() const { return true; } | |
82 | ||
83 | DECLARE_EVENT_TABLE() | |
84 | }; | |
85 | ||
86 | //----------------------------------------------------------------------------- | |
87 | // wxSpinCtrl - An integer valued spin control | |
88 | //----------------------------------------------------------------------------- | |
89 | ||
90 | class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGTKBase | |
91 | { | |
92 | public: | |
93 | wxSpinCtrl() { Init(); } | |
94 | wxSpinCtrl(wxWindow *parent, | |
95 | wxWindowID id = wxID_ANY, | |
96 | const wxString& value = wxEmptyString, | |
97 | const wxPoint& pos = wxDefaultPosition, | |
98 | const wxSize& size = wxDefaultSize, | |
99 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, | |
100 | int min = 0, int max = 100, int initial = 0, | |
101 | const wxString& name = wxS("wxSpinCtrl")) | |
102 | { | |
103 | Init(); | |
104 | ||
105 | Create(parent, id, value, pos, size, style, min, max, initial, name); | |
106 | } | |
107 | ||
108 | bool Create(wxWindow *parent, | |
109 | wxWindowID id = wxID_ANY, | |
110 | const wxString& value = wxEmptyString, | |
111 | const wxPoint& pos = wxDefaultPosition, | |
112 | const wxSize& size = wxDefaultSize, | |
113 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, | |
114 | int min = 0, int max = 100, int initial = 0, | |
115 | const wxString& name = wxS("wxSpinCtrl")) | |
116 | { | |
117 | return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size, | |
118 | style, min, max, initial, 1, name); | |
119 | } | |
120 | ||
121 | // accessors | |
122 | int GetValue() const { return int(DoGetValue()); } | |
123 | int GetMin() const { return int(DoGetMin()); } | |
124 | int GetMax() const { return int(DoGetMax()); } | |
125 | int GetIncrement() const { return int(DoGetIncrement()); } | |
126 | ||
127 | // operations | |
128 | void SetValue(const wxString& value) { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc | |
129 | void SetValue( int value ) { DoSetValue(value); } | |
130 | void SetRange( int minVal, int maxVal ) { DoSetRange(minVal, maxVal); } | |
131 | void SetIncrement(int inc) { DoSetIncrement(inc); } | |
132 | ||
133 | virtual int GetBase() const { return m_base; } | |
134 | virtual bool SetBase(int base); | |
135 | ||
136 | private: | |
137 | // Common part of all ctors. | |
138 | void Init() | |
139 | { | |
140 | m_base = 10; | |
141 | } | |
142 | ||
143 | int m_base; | |
144 | ||
145 | DECLARE_DYNAMIC_CLASS(wxSpinCtrl) | |
146 | }; | |
147 | ||
148 | //----------------------------------------------------------------------------- | |
149 | // wxSpinCtrlDouble - a double valued spin control | |
150 | //----------------------------------------------------------------------------- | |
151 | ||
152 | class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGTKBase | |
153 | { | |
154 | public: | |
155 | wxSpinCtrlDouble() {} | |
156 | wxSpinCtrlDouble(wxWindow *parent, | |
157 | wxWindowID id = wxID_ANY, | |
158 | const wxString& value = wxEmptyString, | |
159 | const wxPoint& pos = wxDefaultPosition, | |
160 | const wxSize& size = wxDefaultSize, | |
161 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, | |
162 | double min = 0, double max = 100, double initial = 0, | |
163 | double inc = 1, | |
164 | const wxString& name = wxS("wxSpinCtrlDouble")) | |
165 | { | |
166 | Create(parent, id, value, pos, size, style, | |
167 | min, max, initial, inc, name); | |
168 | } | |
169 | ||
170 | bool Create(wxWindow *parent, | |
171 | wxWindowID id = wxID_ANY, | |
172 | const wxString& value = wxEmptyString, | |
173 | const wxPoint& pos = wxDefaultPosition, | |
174 | const wxSize& size = wxDefaultSize, | |
175 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, | |
176 | double min = 0, double max = 100, double initial = 0, | |
177 | double inc = 1, | |
178 | const wxString& name = wxS("wxSpinCtrlDouble")) | |
179 | { | |
180 | return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size, | |
181 | style, min, max, initial, inc, name); | |
182 | } | |
183 | ||
184 | // accessors | |
185 | double GetValue() const { return DoGetValue(); } | |
186 | double GetMin() const { return DoGetMin(); } | |
187 | double GetMax() const { return DoGetMax(); } | |
188 | double GetIncrement() const { return DoGetIncrement(); } | |
189 | unsigned GetDigits() const; | |
190 | ||
191 | // operations | |
192 | void SetValue(const wxString& value) { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc | |
193 | void SetValue(double value) { DoSetValue(value); } | |
194 | void SetRange(double minVal, double maxVal) { DoSetRange(minVal, maxVal); } | |
195 | void SetIncrement(double inc) { DoSetIncrement(inc); } | |
196 | void SetDigits(unsigned digits); | |
197 | ||
198 | virtual int GetBase() const { return 10; } | |
199 | virtual bool SetBase(int WXUNUSED(base)) { return false; } | |
200 | ||
201 | DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble) | |
202 | }; | |
203 | ||
204 | #endif // _WX_GTK_SPINCTRL_H_ |