1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinCtrl class
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_SPINCTRL_H_
12 #define _WX_GTK_SPINCTRL_H_
14 //-----------------------------------------------------------------------------
15 // wxSpinCtrlGTKBase - Base class for GTK versions of the wxSpinCtrl[Double]
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 //-----------------------------------------------------------------------------
23 class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase
: public wxSpinCtrlBase
26 wxSpinCtrlGTKBase() : m_value(0) {}
28 bool Create(wxWindow
*parent
,
29 wxWindowID id
= wxID_ANY
,
30 const wxString
& value
= wxEmptyString
,
31 const wxPoint
& pos
= wxDefaultPosition
,
32 const wxSize
& size
= wxDefaultSize
,
33 long style
= wxSP_ARROW_KEYS
,
34 double min
= 0, double max
= 100, double initial
= 0, double inc
= 1,
35 const wxString
& name
= _T("wxSpinCtrlGTKBase"));
37 // wxSpinCtrl(Double) methods call DoXXX functions of the same name
43 // T GetIncrement() const
44 virtual bool GetSnapToTicks() const;
47 virtual void SetValue(const wxString
& value
);
48 // void SetValue(T val)
49 // void SetRange(T minVal, T maxVal)
50 // void SetIncrement(T inc)
51 void SetSnapToTicks( bool snap_to_ticks
);
53 // Select text in the textctrl
54 void SetSelection(long from
, long to
);
56 static wxVisualAttributes
57 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
60 void OnChar( wxKeyEvent
&event
);
62 double m_value
; // public for GTK callback function
66 double DoGetValue() const;
67 double DoGetMin() const;
68 double DoGetMax() const;
69 double DoGetIncrement() const;
71 void DoSetValue(double val
);
72 void DoSetValue(const wxString
& strValue
);
73 void DoSetRange(double min_val
, double max_val
);
74 void DoSetIncrement(double inc
);
76 void GtkDisableEvents() const;
77 void GtkEnableEvents() const;
79 virtual wxSize
DoGetBestSize() const;
80 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
82 // Widgets that use the style->base colour for the BG colour should
83 // override this and return true.
84 virtual bool UseGTKStyleBase() const { return true; }
87 DECLARE_DYNAMIC_CLASS(wxSpinCtrlGTKBase
)
91 //-----------------------------------------------------------------------------
92 // wxSpinCtrl - An integer valued spin control
93 //-----------------------------------------------------------------------------
95 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxSpinCtrlGTKBase
99 wxSpinCtrl(wxWindow
*parent
,
100 wxWindowID id
= wxID_ANY
,
101 const wxString
& value
= wxEmptyString
,
102 const wxPoint
& pos
= wxDefaultPosition
,
103 const wxSize
& size
= wxDefaultSize
,
104 long style
= wxSP_ARROW_KEYS
,
105 int min
= 0, int max
= 100, int initial
= 0,
106 const wxString
& name
= _T("wxSpinCtrl"))
108 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
111 bool Create(wxWindow
*parent
,
112 wxWindowID id
= wxID_ANY
,
113 const wxString
& value
= wxEmptyString
,
114 const wxPoint
& pos
= wxDefaultPosition
,
115 const wxSize
& size
= wxDefaultSize
,
116 long style
= wxSP_ARROW_KEYS
,
117 int min
= 0, int max
= 100, int initial
= 0,
118 const wxString
& name
= _T("wxSpinCtrl"))
120 return wxSpinCtrlGTKBase::Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, 1, name
);
124 int GetValue() const { return int(DoGetValue() + 0.5); }
125 int GetMin() const { return int(DoGetMin() + 0.5); }
126 int GetMax() const { return int(DoGetMax() + 0.5); }
127 int GetIncrement() const { return int(DoGetIncrement() + 0.5); }
130 void SetValue(const wxString
& value
) { wxSpinCtrlGTKBase::SetValue(value
); } // visibility problem w/ gcc
131 void SetValue( int value
) { DoSetValue(value
); }
132 void SetRange( int minVal
, int maxVal
) { DoSetRange(minVal
, maxVal
); }
133 void SetIncrement( double inc
) { DoSetIncrement(inc
); }
136 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
139 //-----------------------------------------------------------------------------
140 // wxSpinCtrlDouble - a double valued spin control
141 //-----------------------------------------------------------------------------
143 class WXDLLIMPEXP_CORE wxSpinCtrlDouble
: public wxSpinCtrlGTKBase
146 wxSpinCtrlDouble() {}
147 wxSpinCtrlDouble(wxWindow
*parent
,
148 wxWindowID id
= wxID_ANY
,
149 const wxString
& value
= wxEmptyString
,
150 const wxPoint
& pos
= wxDefaultPosition
,
151 const wxSize
& size
= wxDefaultSize
,
152 long style
= wxSP_ARROW_KEYS
,
153 double min
= 0, double max
= 100, double initial
= 0, double inc
= 1,
154 const wxString
& name
= _T("wxSpinCtrlDouble"))
156 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, inc
, name
);
159 bool Create(wxWindow
*parent
,
160 wxWindowID id
= wxID_ANY
,
161 const wxString
& value
= wxEmptyString
,
162 const wxPoint
& pos
= wxDefaultPosition
,
163 const wxSize
& size
= wxDefaultSize
,
164 long style
= wxSP_ARROW_KEYS
,
165 double min
= 0, double max
= 100, double initial
= 0, double inc
= 1,
166 const wxString
& name
= _T("wxSpinCtrlDouble"))
168 return wxSpinCtrlGTKBase::Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, inc
, name
);
172 double GetValue() const { return DoGetValue(); }
173 double GetMin() const { return DoGetMin(); }
174 double GetMax() const { return DoGetMax(); }
175 double GetIncrement() const { return DoGetIncrement(); }
176 unsigned GetDigits() const;
179 void SetValue(const wxString
& value
) { wxSpinCtrlGTKBase::SetValue(value
); } // visibility problem w/ gcc
180 void SetValue(double value
) { DoSetValue(value
); }
181 void SetRange(double minVal
, double maxVal
) { DoSetRange(minVal
, maxVal
); }
182 void SetIncrement(double inc
) { DoSetIncrement(inc
); }
183 void SetDigits(unsigned digits
);
186 DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble
)
189 #endif // _WX_GTK_SPINCTRL_H_