Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
AutoDialog.h
1 //
2 // AutoDialog.h
3 //
4 // Copyright (c) 2001-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef AUTODIALOGH
9 #define AUTODIALOGH
10 
11 #if wxUSE_VALIDATORS != 1
12 #error "wx was not configured with support for validators"
13 #endif
14 
15 #include <wx/valgen.h>
16 
17 #ifndef NUMERIC_VALIDATOR
18 #define NUMERIC_VALIDATOR
19 
20 class wxNumericValidator: public wxValidator
21 {
22 public:
23  wxNumericValidator(short *val);
24  wxNumericValidator(int *val);
25  wxNumericValidator(float *val, int digits = -1);
26  wxNumericValidator(double *val, int digits = -1);
27  wxNumericValidator(const wxNumericValidator& copyFrom);
28 
29  // Make a clone of this validator (or return NULL) - currently necessary
30  // if you're passing a reference to a validator.
31  // Another possibility is to always pass a pointer to a new validator
32  // (so the calling code can use a copy constructor of the relevant class).
33  virtual wxObject *Clone() const { return new wxNumericValidator(*this); }
34  bool Copy(const wxNumericValidator& val);
35 
36  // Called when the value in the window must be validated.
37  // This function can pop up an error message.
38  virtual bool Validate(wxWindow *WXUNUSED(parent)) { return TRUE; };
39 
40  // Called to transfer data to the window
41  virtual bool TransferToWindow();
42 
43  // Called to transfer data to the window
44  virtual bool TransferFromWindow();
45 
46  void Enable(bool bTrue) { m_bEnabled = bTrue; }
47 
48 protected:
49  void Initialize();
50 
51  short *m_pValShort;
52  int *m_pValInt;
53  float *m_pValFloat;
54  double *m_pValDouble;
55 
56  // For a floating-point value, specify the number of digits to display.
57  // A value of -1 means to use printf's default (6 digits for floats,
58  // more digits for doubles)
59  int m_iDigits;
60 
61  // You can disable these validators
62  bool m_bEnabled;
63 };
64 
65 #endif // NUMERIC_VALIDATOR
66 
67 
68 class AutoDialog : public wxDialog
69 {
70 public:
71  AutoDialog() {}
72  AutoDialog(wxWindow *parent, wxWindowID id,
73  const wxString& title,
74  const wxPoint& pos = wxDefaultPosition,
75  const wxSize& size = wxDefaultSize,
76  long style = wxDEFAULT_DIALOG_STYLE) :
77  wxDialog(parent, id, title, pos, size, style) {}
78 
79  void AddValidator(long id, wxString *sptr);
80  void AddValidator(long id, bool *bptr);
81  void AddValidator(long id, int *iptr);
82  wxNumericValidator *AddNumValidator(long id, short *sptr);
83  wxNumericValidator *AddNumValidator(long id, int *iptr);
84  wxNumericValidator *AddNumValidator(long id, float *fptr, int digits = -1);
85  wxNumericValidator *AddNumValidator(long id, double *dptr, int digits = -1);
86 };
87 
88 class AutoPanel : public wxPanel
89 {
90 public:
91  AutoPanel() {}
92  AutoPanel(wxWindow *parent, wxWindowID id,
93  const wxPoint& pos = wxDefaultPosition,
94  const wxSize& size = wxDefaultSize,
95  long style = wxDEFAULT_DIALOG_STYLE) :
96  wxPanel(parent, id, pos, size, style) {}
97 
98  void AddValidator(long id, wxString *sptr);
99  void AddValidator(long id, bool *bptr);
100  void AddValidator(long id, int *iptr);
101  wxNumericValidator *AddNumValidator(long id, int *iptr);
102  wxNumericValidator *AddNumValidator(long id, float *fptr, int digits = -1);
103  wxNumericValidator *AddNumValidator(long id, double *dptr, int digits = -1);
104 };
105 
106 // And forms of the methods which don't require subclassing from AutoDialog or AutoPanel
107 void AddValidator(wxWindow *parent, long id, wxString *sptr);
108 void AddValidator(wxWindow *parent, long id, bool *bptr);
109 void AddValidator(wxWindow *parent, long id, int *iptr);
110 wxNumericValidator *AddNumValidator(wxWindow *parent, long id, short *sptr);
111 wxNumericValidator *AddNumValidator(wxWindow *parent, long id, int *iptr);
112 wxNumericValidator *AddNumValidator(wxWindow *parent, long id, float *fptr, int digits = -1);
113 wxNumericValidator *AddNumValidator(wxWindow *parent, long id, double *dptr, int digits = -1);
114 
115 // And forms of the methods which take a pointer directly
116 void AddValidator(wxWindow *win, wxString *sptr);
117 void AddValidator(wxWindow *win, bool *bptr);
118 void AddValidator(wxWindow *win, int *iptr);
119 wxNumericValidator *AddNumValidator(wxWindow *win, short *sptr);
120 wxNumericValidator *AddNumValidator(wxWindow *win, int *iptr);
121 wxNumericValidator *AddNumValidator(wxWindow *win, float *fptr, int digits = -1);
122 wxNumericValidator *AddNumValidator(wxWindow *win, double *dptr, int digits = -1);
123 
124 #endif