Debian Codegraph @

3rdparty/wxThings/wx/things/spinctld.h

raw symbols SCIP
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: spinctld.h
3 // Purpose: A double valued spin control, compatible with wxSpinCtrl
4 // Author: John Labenski
5 // Created: 11/05/02
6 // Copyright: John Labenski, 2002
7 // License: wxWidgets
8 /////////////////////////////////////////////////////////////////////////////
9
10 /*
11 wxSpinCtrlDbl is a double valued wxSpinCtrl using non native (wxWidgets) widgets
12
13 It consists of a wxSpinButton and a wxTextCtrl on a wxControl and can be used
14 as a drop in replacement for the wxSpinCtrl. It's been tested in GTK and MSW
15 and should work with MAC, but you may need to fix the sizing perhaps. It
16 will not work in Motif as there is no wxSpinButton in Motif.
17
18 Differences to wxSpinCtrl:
19
20 It remembers the initial value as a default value, call SetDefaultValue,
21 or press <ESC> to return to it
22
23 Shift + Arrow = *2 increment value
24 Ctrl + Arrow = *10 increment value
25 Alt + Arrow = *100 increment value
26 combinations of Shift, Ctrl, Alt increment by the product of the factors
27
28 PgUp & PgDn = *10 increment * the product of the Shift, Ctrl, Alt factors
29
30 <SPACE> sets the control's value to the it's last valid state
31
32 SetDigits controls the format of the text, # decimal places
33 exponential uses the %.Xle format otherwise %.Xlf, where places = X
34 for arbitray formats subclass control and override SyncSpinToText()
35 for proper behavior when a user types in a value
36 */
37
38 #ifndef __wxSPINCTRLDBL_H__
39 #define __wxSPINCTRLDBL_H__
40
41 #include "wx/spinbutt.h"
42 #include "wx/spinctrl.h" // for EVT_SPINCTRL
43 #include "wx/things/thingdef.h"
44
45 class WXDLLEXPORT wxTextCtrl;
46 class WXDLLIMPEXP_THINGS wxSpinCtrlDblTextCtrl;
47
48 enum
49 {
50 wxSPINCTRLDBL_AUTODIGITS = -1 // try to autocalc the # of digits
51 };
52
53 class WXDLLIMPEXP_THINGS wxSpinCtrlDbl: public wxControl
54 {
55 public:
56 wxSpinCtrlDbl() : wxControl() { Init(); }
57
58 // Native constructor - note &parent, this is to avoid ambiguity
59 wxSpinCtrlDbl( wxWindow &parent, wxWindowID id,
60 const wxString &value = wxEmptyString,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxSize(95,-1),
63 long style = 0,
64 double min = 0.0, double max = 100.0,
65 double initial = 0.0,
66 double increment = 1.0, int digits = wxSPINCTRLDBL_AUTODIGITS,
67 const wxString& name = _T("wxSpinCtrlDbl") )
68 {
69 Init();
70 Create(&parent, id, value, pos, size, style,
71 min, max, initial, increment, digits, name);
72 }
73
74 // wxSpinCtrl compatibility, call SetIncrement(increment,digits) after
75 wxSpinCtrlDbl( wxWindow *parent, wxWindowID id = wxID_ANY,
76 const wxString &value = wxEmptyString,
77 const wxPoint& pos = wxDefaultPosition,
78 const wxSize& size = wxSize(95,-1),
79 long style = 0,
80 int min = 0, int max = 100,
81 int initial = 0,
82 const wxString& name = _T("wxSpinCtrlDbl") )
83 {
84 Init();
85 Create(parent, id, value, pos, size, style,
86 (double)min, (double)max, (double)initial, 1.0, -1, name);
87 }
88
89 bool Create( wxWindow *parent,
90 wxWindowID id = wxID_ANY,
91 const wxString &value = wxEmptyString,
92 const wxPoint& pos = wxDefaultPosition,
93 const wxSize& size = wxSize(100,-1),
94 long style = 0,
95 double min = 0.0, double max = 100.0,
96 double initial = 0.0,
97 double increment = 1.0, int digits = wxSPINCTRLDBL_AUTODIGITS,
98 const wxString& name = _T("wxSpinCtrlDbl") );
99
100 virtual ~wxSpinCtrlDbl();
101
102 // -----------------------------------------------------------------------
103 // Public (normal usage) functions
104
105 enum formatType
106 {
107 lf_fmt, // %lf
108 le_fmt, // %le
109 lg_fmt // %lg
110 };
111
112 virtual void SetValue( double value );
113 void SetValue( double value, double min, double max, double increment,
114 int digits = wxSPINCTRLDBL_AUTODIGITS, formatType fmt = lg_fmt )
115 { SetRange(min, max); SetIncrement(increment); SetDigits(digits, fmt); SetValue(value); }
116 // Set the value as text, if force then set text as is
117 virtual void SetValue( const wxString& text, bool force );
118 // Set the allowed range, if max_val < min_val then no range and all vals allowed.
119 void SetRange( double min_val, double max_val );
120 // Set the increment to use when the spin button or arrow keys pressed.
121 void SetIncrement( double increment );
122 void SetIncrement( double increment, int digits, formatType fmt = lg_fmt )
123 { SetIncrement(increment); SetDigits(digits, fmt); }
124 // Set the number of digits to show, use wxSPINCTRLDBL_AUTODIGITS
125 // or specify exact number to show i.e. %.[digits]lf
126 // The format type is used to create an appropriate format string.
127 void SetDigits( int digits = wxSPINCTRLDBL_AUTODIGITS, formatType fmt = lg_fmt );
128 // Set the format string to use, ie. format="%.2lf" for .01
129 void SetFormat( const wxString& format );
130 // Set the control the the default value.
131 virtual void SetDefaultValue() { SetValue( m_default_value ); }
132 // Set the value of the default value, default is the inital value.
133 void SetDefaultValue( double default_value );
134 // Force the value to always be divisible by the increment, initially off.
135 // This uses the default_value as the basis, you'll get strange results
136 // for very large differences between the current value and default value
137 // when the increment is very small.
138 void SetSnapToTicks(bool forceTicks);
139
140 double GetValue() const { return m_value; }
141 double GetMin() const { return m_min; }
142 double GetMax() const { return m_max; }
143 virtual bool HasRange() const { return m_max >= m_min; }
144 virtual bool InRange(double value) const { return !HasRange() || ((value >= m_min) && (value <= m_max)); }
145 double GetIncrement() const { return m_increment; }
146 int GetDigits() const { return m_digits; }
147 wxString GetFormat() const { return m_textFormat; }
148 double GetDefaultValue() const { return m_default_value; }
149 bool GetSnapToTicks() const { return m_snap_ticks; }
150
151 bool IsDefaultValue() const { return (m_value == m_default_value); }
152
153 virtual bool SetFont( const wxFont &font );
154 wxFont GetFont() const;
155
156 virtual bool SetBackgroundColour(const wxColour& colour);
157 wxColour GetBackgroundColour() const;
158
159 virtual bool SetForegroundColour(const wxColour& colour);
160 wxColour GetForegroundColour() const;
161
162 // for setting... stuff
163 wxTextCtrl *GetTextCtrl() { return (wxTextCtrl*)m_textCtrl; }
164
165 protected:
166 void OnSpinUp( wxSpinEvent &event );
167 void OnSpinDown( wxSpinEvent &event );
168 void OnTextEnter( wxCommandEvent &event );
169 void OnText( wxCommandEvent &event );
170 // the textctrl is subclassed to get at pgup/dn and then sent here
171 void OnChar( wxKeyEvent &event );
172
173 virtual void SyncSpinToText(bool send_event = true, bool force_valid = true);
174
175 void DoSendEvent(); // send an event based on current state
176
177 virtual void DoSetSize(int x, int y, int width, int height,
178 int sizeFlags = wxSIZE_AUTO);
179
180 virtual wxSize DoGetBestSize() const;
181 virtual void DoSetToolTip( wxToolTip *tip );
182
183 void OnFocus( wxFocusEvent& event ); // pass focus to textctrl, for wxTAB_TRAVERSAL
184 void OnKillFocus( wxFocusEvent &event );
185
186 wxSpinButton *m_spinButton;
187 wxSpinCtrlDblTextCtrl *m_textCtrl;
188
189 double m_min; // min allowed value
190 double m_max; // max allowed value
191 double m_value; // current value
192 double m_default_value; // initial value, or SetDefaultValue(value)
193 double m_increment; // how much to to add per spin
194 int m_digits; // number of digits displayed after decimal point
195 bool m_snap_ticks; // value is divisible by increment
196 wxString m_textFormat; // used as wxString.Printf(m_textFormat.c_str(), m_value);
197
198 private:
199 friend class wxSpinCtrlDblTextCtrl;
200
201 void Init();
202 DECLARE_DYNAMIC_CLASS(wxSpinCtrlDbl)
203 DECLARE_EVENT_TABLE()
204 };
205
206 #endif // __wxSPINCTRLDBL_H__