File: validate.h

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (194 lines) | stat: -rw-r--r-- 4,846 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
/////////////////////////////////////////////////////////////////////////////
// Name:        validate.h
// Purpose:     wxWidgets validation sample
// Author:      Julian Smart
// Modified by:
// Created:     04/01/98
// Copyright:   (c) Julian Smart
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#include "wx/app.h"
#include "wx/combobox.h"
#include "wx/dialog.h"
#include "wx/dynarray.h"
#include "wx/frame.h"
#include "wx/listbox.h"
#include "wx/string.h"

// Define a new application type
class MyApp : public wxApp
{
public:
    bool OnInit() wxOVERRIDE;
};

// Define a new frame type
class MyFrame : public wxFrame
{
public:
    MyFrame(wxFrame *frame, const wxString&title, int x, int y, int w, int h);

    void OnQuit(wxCommandEvent& event);
    void OnTestDialog(wxCommandEvent& event);
    void OnToggleBell(wxCommandEvent& event);

private:
    wxListBox *m_listbox;
    bool m_silent;

    wxDECLARE_EVENT_TABLE();
};

class MyDialog : public wxDialog
{
public:
    MyDialog(wxWindow *parent, const wxString& title,
            const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize,
            const long style = wxDEFAULT_DIALOG_STYLE);

    void OnChangeValidator(wxCommandEvent& event);

    wxTextCtrl *m_text;
    wxComboBox *m_combobox;

    wxTextCtrl *m_numericTextInt;
    wxTextCtrl *m_numericTextDouble;
};

// ----------------------------------------------------------------------------
// TextValidatorDialog
// ----------------------------------------------------------------------------
class TextValidatorDialog : public wxDialog
{
public:
    TextValidatorDialog(wxWindow *parent, wxTextCtrl* txtCtrl);

    void OnUpdateUI(wxUpdateUIEvent& event);
    void OnChecked(wxCommandEvent& event);
    void OnKillFocus( wxFocusEvent &event );

    void ApplyValidator();

private:
    // Special validator for our checkboxes
    class StyleValidator : public wxValidator
    {
    public:
        StyleValidator(long* style) { m_style = style; }

        virtual bool Validate(wxWindow *WXUNUSED(parent)) wxOVERRIDE { return true; }
        virtual wxObject* Clone() const wxOVERRIDE { return new StyleValidator(*this); }

        // Called to transfer data to the window
        virtual bool TransferToWindow() wxOVERRIDE;

        // Called to transfer data from the window
        virtual bool TransferFromWindow() wxOVERRIDE;

    private:
        long* m_style;
    };

private:
    bool HasFlag(wxTextValidatorStyle style) const
    {
        return (m_validatorStyle & style) != 0;
    }

    enum
    {
        // CheckBoxes Ids (should be in sync with wxTextValidatorStyle)
        Id_None = wxID_HIGHEST,
        Id_Empty,
        Id_Ascii,
        Id_Alpha,
        Id_Alphanumeric,
        Id_Digits,
        Id_Numeric,
        Id_IncludeList,
        Id_IncludeCharList,
        Id_ExcludeList,
        Id_ExcludeCharList,
        Id_Xdigits,
        Id_Space,

        // TextCtrls Ids
        Id_IncludeListTxt,
        Id_IncludeCharListTxt,
        Id_ExcludeListTxt,
        Id_ExcludeCharListTxt,
    };

    wxTextCtrl* const m_txtCtrl;

    bool m_noValidation;
    long m_validatorStyle;

    wxString        m_charIncludes;
    wxString        m_charExcludes;
    wxArrayString   m_includes;
    wxArrayString   m_excludes;
};

class MyData
{
public:
    MyData();

    // These data members are designed for transfer to and from
    // controls, via validators. For instance, a text control's
    // transferred value is a string:
    wxString m_string, m_string2;

    // Listboxes may permit multiple selections, so their state
    // is transferred to an integer-array class.
    wxArrayInt m_listbox_choices;

    // Comboboxes differ from listboxes--validators transfer
    // the string entered in the combobox's text-edit field.
    wxString m_combobox_choice;

    // variables handled by wxNumericTextValidator
    int m_intValue;
    unsigned short m_smallIntValue;
    double m_doubleValue;
    float m_percentValue;

    bool m_checkbox_state;
    int m_radiobox_choice;
};

class MyComboBoxValidator : public wxValidator
{
public:
    MyComboBoxValidator(wxString* var) { m_var=var; }

    virtual bool Validate(wxWindow* parent) wxOVERRIDE;
    virtual wxObject* Clone() const wxOVERRIDE { return new MyComboBoxValidator(*this); }

    // Called to transfer data to the window
    virtual bool TransferToWindow() wxOVERRIDE;

    // Called to transfer data from the window
    virtual bool TransferFromWindow() wxOVERRIDE;

protected:
    wxString* m_var;
};

enum
{
    VALIDATE_DIALOG_ID = wxID_HIGHEST,

    VALIDATE_TEST_DIALOG,
    VALIDATE_TOGGLE_BELL,

    VALIDATE_TEXT,
    VALIDATE_TEXT2,
    VALIDATE_LIST,
    VALIDATE_CHECK,
    VALIDATE_COMBO,
    VALIDATE_RADIO
};