]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/gtk/spinctrl.h
added wxDC::GetHDC() for backwards compatibility with the existing wxMSW code
[wxWidgets.git] / include / wx / gtk / spinctrl.h
... / ...
CommitLineData
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
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
23class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase : public wxSpinCtrlBase
24{
25public:
26 wxSpinCtrlGTKBase() : m_value(0) {}
27
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"));
36
37 // wxSpinCtrl(Double) methods call DoXXX functions of the same name
38
39 // accessors
40 // T GetValue() const
41 // T GetMin() const
42 // T GetMax() const
43 // T GetIncrement() const
44 virtual bool GetSnapToTicks() const;
45
46 // operations
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 );
52
53 // Select text in the textctrl
54 void SetSelection(long from, long to);
55
56 static wxVisualAttributes
57 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
58
59 // implementation
60 void OnChar( wxKeyEvent &event );
61
62 double m_value; // public for GTK callback function
63
64protected:
65
66 double DoGetValue() const;
67 double DoGetMin() const;
68 double DoGetMax() const;
69 double DoGetIncrement() const;
70
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);
75
76 void GtkDisableEvents() const;
77 void GtkEnableEvents() const;
78
79 virtual wxSize DoGetBestSize() const;
80 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
81
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; }
85
86private:
87 DECLARE_DYNAMIC_CLASS(wxSpinCtrlGTKBase)
88 DECLARE_EVENT_TABLE()
89};
90
91//-----------------------------------------------------------------------------
92// wxSpinCtrl - An integer valued spin control
93//-----------------------------------------------------------------------------
94
95class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGTKBase
96{
97public:
98 wxSpinCtrl() {}
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"))
107 {
108 Create(parent, id, value, pos, size, style, min, max, initial, name);
109 }
110
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"))
119 {
120 return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size, style, min, max, initial, 1, name);
121 }
122
123 // accessors
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); }
128
129 // operations
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); }
134
135private:
136 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
137};
138
139//-----------------------------------------------------------------------------
140// wxSpinCtrlDouble - a double valued spin control
141//-----------------------------------------------------------------------------
142
143class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGTKBase
144{
145public:
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"))
155 {
156 Create(parent, id, value, pos, size, style, min, max, initial, inc, name);
157 }
158
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"))
167 {
168 return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size, style, min, max, initial, inc, name);
169 }
170
171 // accessors
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;
177
178 // operations
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);
184
185private:
186 DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble)
187};
188
189#endif // _WX_GTK_SPINCTRL_H_