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