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
| wxALIGN_RIGHT
,
34 double min
= 0, double max
= 100, double initial
= 0,
36 const wxString
& name
= _T("wxSpinCtrlGTKBase"));
38 // wxSpinCtrl(Double) methods call DoXXX functions of the same name
44 // T GetIncrement() const
45 virtual bool GetSnapToTicks() const;
48 virtual void SetValue(const wxString
& value
);
49 // void SetValue(T val)
50 // void SetRange(T minVal, T maxVal)
51 // void SetIncrement(T inc)
52 void SetSnapToTicks( bool snap_to_ticks
);
54 // Select text in the textctrl
55 void SetSelection(long from
, long to
);
57 static wxVisualAttributes
58 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
61 void OnChar( wxKeyEvent
&event
);
63 double m_value
; // public for GTK callback function
67 double DoGetValue() const;
68 double DoGetMin() const;
69 double DoGetMax() const;
70 double DoGetIncrement() const;
72 void DoSetValue(double val
);
73 void DoSetValue(const wxString
& strValue
);
74 void DoSetRange(double min_val
, double max_val
);
75 void DoSetIncrement(double inc
);
77 void GtkDisableEvents() const;
78 void GtkEnableEvents() const;
80 virtual wxSize
DoGetBestSize() const;
81 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
83 // Widgets that use the style->base colour for the BG colour should
84 // override this and return true.
85 virtual bool UseGTKStyleBase() const { return true; }
88 DECLARE_DYNAMIC_CLASS(wxSpinCtrlGTKBase
)
92 //-----------------------------------------------------------------------------
93 // wxSpinCtrl - An integer valued spin control
94 //-----------------------------------------------------------------------------
96 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxSpinCtrlGTKBase
100 wxSpinCtrl(wxWindow
*parent
,
101 wxWindowID id
= wxID_ANY
,
102 const wxString
& value
= wxEmptyString
,
103 const wxPoint
& pos
= wxDefaultPosition
,
104 const wxSize
& size
= wxDefaultSize
,
105 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
106 int min
= 0, int max
= 100, int initial
= 0,
107 const wxString
& name
= _T("wxSpinCtrl"))
109 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
112 bool Create(wxWindow
*parent
,
113 wxWindowID id
= wxID_ANY
,
114 const wxString
& value
= wxEmptyString
,
115 const wxPoint
& pos
= wxDefaultPosition
,
116 const wxSize
& size
= wxDefaultSize
,
117 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
118 int min
= 0, int max
= 100, int initial
= 0,
119 const wxString
& name
= _T("wxSpinCtrl"))
121 return wxSpinCtrlGTKBase::Create(parent
, id
, value
, pos
, size
,
122 style
, min
, max
, initial
, 1, name
);
126 int GetValue() const { return wxRound( DoGetValue() ); }
127 int GetMin() const { return wxRound( DoGetMin() ); }
128 int GetMax() const { return wxRound( DoGetMax() ); }
129 int GetIncrement() const { return wxRound( DoGetIncrement() ); }
132 void SetValue(const wxString
& value
) { wxSpinCtrlGTKBase::SetValue(value
); } // visibility problem w/ gcc
133 void SetValue( int value
) { DoSetValue(value
); }
134 void SetRange( int minVal
, int maxVal
) { DoSetRange(minVal
, maxVal
); }
135 void SetIncrement( double inc
) { DoSetIncrement(inc
); }
138 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
141 //-----------------------------------------------------------------------------
142 // wxSpinCtrlDouble - a double valued spin control
143 //-----------------------------------------------------------------------------
145 class WXDLLIMPEXP_CORE wxSpinCtrlDouble
: public wxSpinCtrlGTKBase
148 wxSpinCtrlDouble() {}
149 wxSpinCtrlDouble(wxWindow
*parent
,
150 wxWindowID id
= wxID_ANY
,
151 const wxString
& value
= wxEmptyString
,
152 const wxPoint
& pos
= wxDefaultPosition
,
153 const wxSize
& size
= wxDefaultSize
,
154 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
155 double min
= 0, double max
= 100, double initial
= 0,
157 const wxString
& name
= _T("wxSpinCtrlDouble"))
159 Create(parent
, id
, value
, pos
, size
, style
,
160 min
, max
, initial
, inc
, name
);
163 bool Create(wxWindow
*parent
,
164 wxWindowID id
= wxID_ANY
,
165 const wxString
& value
= wxEmptyString
,
166 const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
,
168 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
169 double min
= 0, double max
= 100, double initial
= 0,
171 const wxString
& name
= _T("wxSpinCtrlDouble"))
173 return wxSpinCtrlGTKBase::Create(parent
, id
, value
, pos
, size
,
174 style
, min
, max
, initial
, inc
, name
);
178 double GetValue() const { return DoGetValue(); }
179 double GetMin() const { return DoGetMin(); }
180 double GetMax() const { return DoGetMax(); }
181 double GetIncrement() const { return DoGetIncrement(); }
182 unsigned GetDigits() const;
185 void SetValue(const wxString
& value
) { wxSpinCtrlGTKBase::SetValue(value
); } // visibility problem w/ gcc
186 void SetValue(double value
) { DoSetValue(value
); }
187 void SetRange(double minVal
, double maxVal
) { DoSetRange(minVal
, maxVal
); }
188 void SetIncrement(double inc
) { DoSetIncrement(inc
); }
189 void SetDigits(unsigned digits
);
192 DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble
)
195 #endif // _WX_GTK_SPINCTRL_H_