]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/spinctrl.h
Refactor wxEventLoopSource-related code.
[wxWidgets.git] / include / wx / gtk / spinctrl.h
CommitLineData
738f9e5a
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinctrl.h
3// Purpose: wxSpinCtrl class
4// Author: Robert Roebling
5// Modified by:
6// RCS-ID: $Id$
7// Copyright: (c) Robert Roebling
65571936 8// Licence: wxWindows licence
738f9e5a
RR
9/////////////////////////////////////////////////////////////////////////////
10
0416c418
PC
11#ifndef _WX_GTK_SPINCTRL_H_
12#define _WX_GTK_SPINCTRL_H_
a075e27b 13
738f9e5a 14//-----------------------------------------------------------------------------
8cd6a9ad
VZ
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.
738f9e5a
RR
21//-----------------------------------------------------------------------------
22
8cd6a9ad 23class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase : public wxSpinCtrlBase
738f9e5a
RR
24{
25public:
8cd6a9ad 26 wxSpinCtrlGTKBase() : m_value(0) {}
738f9e5a
RR
27
28 bool Create(wxWindow *parent,
8cd6a9ad 29 wxWindowID id = wxID_ANY,
ce89fdd2 30 const wxString& value = wxEmptyString,
738f9e5a
RR
31 const wxPoint& pos = wxDefaultPosition,
32 const wxSize& size = wxDefaultSize,
99e788d5
VZ
33 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
34 double min = 0, double max = 100, double initial = 0,
35 double inc = 1,
9a83f860 36 const wxString& name = wxT("wxSpinCtrlGTKBase"));
738f9e5a 37
8cd6a9ad
VZ
38 // wxSpinCtrl(Double) methods call DoXXX functions of the same name
39
40 // accessors
41 // T GetValue() const
42 // T GetMin() const
43 // T GetMax() const
44 // T GetIncrement() const
45 virtual bool GetSnapToTicks() const;
ce89fdd2 46
8cd6a9ad
VZ
47 // operations
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 );
53
54 // Select text in the textctrl
55 void SetSelection(long from, long to);
738f9e5a 56
9d522606
RD
57 static wxVisualAttributes
58 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
8cd6a9ad 59
ce89fdd2 60 // implementation
da048e3d 61 void OnChar( wxKeyEvent &event );
8cd6a9ad
VZ
62
63 double m_value; // public for GTK callback function
738f9e5a 64
9d9b7755 65protected:
8cd6a9ad
VZ
66
67 double DoGetValue() const;
68 double DoGetMin() const;
69 double DoGetMax() const;
70 double DoGetIncrement() const;
71
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);
76
28529e37
RR
77 void GtkDisableEvents() const;
78 void GtkEnableEvents() const;
79
9d9b7755 80 virtual wxSize DoGetBestSize() const;
ef5c70f9 81 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
9d9b7755 82
9d522606
RD
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; }
86
738f9e5a 87private:
8cd6a9ad 88 DECLARE_DYNAMIC_CLASS(wxSpinCtrlGTKBase)
da048e3d 89 DECLARE_EVENT_TABLE()
738f9e5a
RR
90};
91
8cd6a9ad
VZ
92//-----------------------------------------------------------------------------
93// wxSpinCtrl - An integer valued spin control
94//-----------------------------------------------------------------------------
95
96class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGTKBase
97{
98public:
99 wxSpinCtrl() {}
100 wxSpinCtrl(wxWindow *parent,
101 wxWindowID id = wxID_ANY,
102 const wxString& value = wxEmptyString,
103 const wxPoint& pos = wxDefaultPosition,
104 const wxSize& size = wxDefaultSize,
99e788d5 105 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
8cd6a9ad 106 int min = 0, int max = 100, int initial = 0,
9a83f860 107 const wxString& name = wxT("wxSpinCtrl"))
8cd6a9ad
VZ
108 {
109 Create(parent, id, value, pos, size, style, min, max, initial, name);
110 }
111
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,
99e788d5 117 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
8cd6a9ad 118 int min = 0, int max = 100, int initial = 0,
9a83f860 119 const wxString& name = wxT("wxSpinCtrl"))
8cd6a9ad 120 {
99e788d5
VZ
121 return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
122 style, min, max, initial, 1, name);
8cd6a9ad
VZ
123 }
124
125 // accessors
674f0f27
RR
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() ); }
8cd6a9ad
VZ
130
131 // operations
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); }
136
137private:
138 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
139};
140
141//-----------------------------------------------------------------------------
142// wxSpinCtrlDouble - a double valued spin control
143//-----------------------------------------------------------------------------
144
145class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGTKBase
146{
147public:
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,
99e788d5
VZ
154 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
155 double min = 0, double max = 100, double initial = 0,
156 double inc = 1,
9a83f860 157 const wxString& name = wxT("wxSpinCtrlDouble"))
8cd6a9ad 158 {
99e788d5
VZ
159 Create(parent, id, value, pos, size, style,
160 min, max, initial, inc, name);
8cd6a9ad
VZ
161 }
162
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,
99e788d5
VZ
168 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
169 double min = 0, double max = 100, double initial = 0,
170 double inc = 1,
9a83f860 171 const wxString& name = wxT("wxSpinCtrlDouble"))
8cd6a9ad 172 {
99e788d5
VZ
173 return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
174 style, min, max, initial, inc, name);
8cd6a9ad
VZ
175 }
176
177 // accessors
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;
183
184 // operations
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);
190
191private:
192 DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble)
193};
194
0416c418 195#endif // _WX_GTK_SPINCTRL_H_