File: spinctrl.h

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (262 lines) | stat: -rw-r--r-- 9,431 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/gtk/spinctrl.h
// Purpose:     wxSpinCtrl class
// Author:      Robert Roebling
// Modified by:
// Copyright:   (c) Robert Roebling
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_GTK_SPINCTRL_H_
#define _WX_GTK_SPINCTRL_H_

//-----------------------------------------------------------------------------
// wxSpinCtrlGTKBase - Base class for GTK versions of the wxSpinCtrl[Double]
//
// This class manages a double valued GTK spinctrl through the DoGet/SetXXX
// functions that are made public as Get/SetXXX functions for int or double
// for the wxSpinCtrl and wxSpinCtrlDouble classes respectively to avoid
// function ambiguity.
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase : public wxSpinCtrlBase
{
public:
    bool Create(wxWindow *parent,
                wxWindowID id,
                const wxString& value,
                const wxPoint& pos,
                const wxSize& size,
                long style,
                double min, double max, double initial,
                double inc,
                const wxString& name);

    // wxSpinCtrl(Double) methods call DoXXX functions of the same name

    // accessors
    virtual wxString GetTextValue() const wxOVERRIDE;
    // T GetValue() const
    // T GetMin() const
    // T GetMax() const
    // T GetIncrement() const
    virtual bool GetSnapToTicks() const wxOVERRIDE;

    // operations
    virtual void SetValue(const wxString& value) wxOVERRIDE;
    // void SetValue(T val)
    // void SetRange(T minVal, T maxVal)
    // void SetIncrement(T inc)
    void SetSnapToTicks( bool snap_to_ticks ) wxOVERRIDE;

    // Select text in the textctrl
    void SetSelection(long from, long to) wxOVERRIDE;

    static wxVisualAttributes
    GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);

    // implementation
    void OnChar( wxKeyEvent &event );


    // These values map to the possible return values of "input" GTK signal but
    // are more readable and type-safe.
    enum GTKInputResult
    {
        GTKInput_Error = -1,
        GTKInput_Default,
        GTKInput_Converted
    };

    virtual GTKInputResult GTKInput(double* value) const = 0;
    virtual bool GTKOutput(wxString* text) const = 0;

    virtual void GTKValueChanged() = 0;
    void GTKTextChanged();

protected:
    wxSpinCtrlGTKBase();
    ~wxSpinCtrlGTKBase();

    double DoGetValue() const;
    double DoGetMin() const;
    double DoGetMax() const;
    double DoGetIncrement() const;

    void DoSetValue(double val);
    void DoSetValue(const wxString& strValue);
    void DoSetRange(double min_val, double max_val);
    void DoSetIncrement(double inc);

    void GtkDisableEvents();
    void GtkEnableEvents();

    // Update the width of the entry field to fit the current range (and also
    // base or number of digits depending on the derived class).
    virtual void GtkSetEntryWidth() = 0;

    virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE;
    virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;

    // Widgets that use the style->base colour for the BG colour should
    // override this and return true.
    virtual bool UseGTKStyleBase() const wxOVERRIDE { return true; }

    // Set m_textOverride to use the given text instead of the numeric value.
    void GTKSetTextOverride(const wxString& text);

    // Reset the override and changing the value to correspond to the
    // previously overridden numeric value.
    void GTKResetTextOverride();

    // Just reset the override, without touching the value, returning true if
    // we did it. In most cases, the function above should be used instead.
    bool GTKResetTextOverrideOnly();

private:
    // This function does _not_ take into account m_textOverride, so it is
    // private and normally shouldn't be used -- use DoGetValue() instead.
    double GTKGetValue() const;

    // Non-null when the text value is different from the numeric value.
    class wxSpinCtrlGTKTextOverride* m_textOverride;


    friend class wxSpinCtrlEventDisabler;

    wxDECLARE_EVENT_TABLE();
};

//-----------------------------------------------------------------------------
// wxSpinCtrl - An integer valued spin control
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGTKBase
{
public:
    wxSpinCtrl() { Init(); }
    wxSpinCtrl(wxWindow *parent,
               wxWindowID id = wxID_ANY,
               const wxString& value = wxEmptyString,
               const wxPoint& pos = wxDefaultPosition,
               const wxSize& size = wxDefaultSize,
               long style = wxSP_ARROW_KEYS,
               int min = 0, int max = 100, int initial = 0,
               const wxString& name = wxS("wxSpinCtrl"))
    {
        Init();

        Create(parent, id, value, pos, size, style, min, max, initial, name);
    }

    bool Create(wxWindow *parent,
                wxWindowID id = wxID_ANY,
                const wxString& value = wxEmptyString,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = wxSP_ARROW_KEYS,
                int min = 0, int max = 100, int initial = 0,
                const wxString& name = wxS("wxSpinCtrl"))
    {
        return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
                                         style, min, max, initial, 1, name);
    }

    // accessors
    int GetValue() const { return int(DoGetValue()); }
    int GetMin() const { return int(DoGetMin()); }
    int GetMax() const { return int(DoGetMax()); }
    int GetIncrement() const { return int(DoGetIncrement()); }

    // operations
    void SetValue(const wxString& value) wxOVERRIDE    { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc
    void SetValue( int value )              { DoSetValue(value); }
    void SetRange( int minVal, int maxVal ) { DoSetRange(minVal, maxVal); }
    void SetIncrement(int inc) { DoSetIncrement(inc); }

    virtual int GetBase() const wxOVERRIDE { return m_base; }
    virtual bool SetBase(int base) wxOVERRIDE;

    virtual GTKInputResult GTKInput(double* value) const wxOVERRIDE;
    virtual bool GTKOutput(wxString* text) const wxOVERRIDE;
    virtual void GTKValueChanged() wxOVERRIDE;

protected:
    virtual void GtkSetEntryWidth() wxOVERRIDE;

private:
    // Common part of all ctors.
    void Init()
    {
        m_base = 10;
    }

    int m_base;

    wxDECLARE_DYNAMIC_CLASS(wxSpinCtrl);
};

//-----------------------------------------------------------------------------
// wxSpinCtrlDouble - a double valued spin control
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGTKBase
{
public:
    wxSpinCtrlDouble() {}
    wxSpinCtrlDouble(wxWindow *parent,
                     wxWindowID id = wxID_ANY,
                     const wxString& value = wxEmptyString,
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& size = wxDefaultSize,
                     long style = wxSP_ARROW_KEYS,
                     double min = 0, double max = 100, double initial = 0,
                     double inc = 1,
                     const wxString& name = wxS("wxSpinCtrlDouble"))
    {
        Create(parent, id, value, pos, size, style,
               min, max, initial, inc, name);
    }

    bool Create(wxWindow *parent,
                wxWindowID id = wxID_ANY,
                const wxString& value = wxEmptyString,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = wxSP_ARROW_KEYS,
                double min = 0, double max = 100, double initial = 0,
                double inc = 1,
                const wxString& name = wxS("wxSpinCtrlDouble"))
    {
        return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
                                         style, min, max, initial, inc, name);
    }

    // accessors
    double GetValue() const     { return DoGetValue(); }
    double GetMin() const       { return DoGetMin(); }
    double GetMax() const       { return DoGetMax(); }
    double GetIncrement() const { return DoGetIncrement(); }
    unsigned GetDigits() const;

    // operations
    void SetValue(const wxString& value) wxOVERRIDE        { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc
    void SetValue(double value)                 { DoSetValue(value); }
    void SetRange(double minVal, double maxVal) { DoSetRange(minVal, maxVal); }
    void SetIncrement(double inc);
    void SetDigits(unsigned digits);

    virtual int GetBase() const wxOVERRIDE { return 10; }
    virtual bool SetBase(int WXUNUSED(base)) wxOVERRIDE { return false; }

    virtual GTKInputResult GTKInput(double* value) const wxOVERRIDE;
    virtual bool GTKOutput(wxString* text) const wxOVERRIDE;
    virtual void GTKValueChanged() wxOVERRIDE;

protected:
    virtual void GtkSetEntryWidth() wxOVERRIDE;

    wxDECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble);
};

#endif // _WX_GTK_SPINCTRL_H_