1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property form classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPFORM_H_
13 #define _WX_PROPFORM_H_
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "propform.h"
24 class WXDLLEXPORT wxPropertyFormView
;
27 //// Property form classes: for using an existing dialog or panel
30 #define wxID_PROP_REVERT 3100
31 #define wxID_PROP_UPDATE 3101
33 // Mediates between a physical panel and the property sheet
34 class WXDLLEXPORT wxPropertyFormView
: public wxPropertyView
36 DECLARE_DYNAMIC_CLASS(wxPropertyFormView
)
38 wxPropertyFormView(wxWindow
*propPanel
= NULL
, long flags
= 0);
39 ~wxPropertyFormView(void);
41 // Associates and shows the view
42 virtual void ShowView(wxPropertySheet
*propertySheet
, wxWindow
*panel
);
44 // Update this view of the viewed object, called e.g. by
46 virtual bool OnUpdateView(void);
48 // Transfer values from property sheet to dialog
49 virtual bool TransferToDialog(void);
51 // Transfer values from dialog to property sheet
52 virtual bool TransferToPropertySheet(void);
54 // Check that all the values are valid
55 virtual bool Check(void);
57 // Give each property in the sheet a panel item, by matching
58 // the name of the property to the name of the panel item.
59 // The user doesn't always want to call this; sometimes, it
60 // will have been done explicitly (e.g., no matching names).
61 virtual bool AssociateNames(void);
63 void OnOk(wxCommandEvent
& event
);
64 void OnCancel(wxCommandEvent
& event
);
65 void OnHelp(wxCommandEvent
& event
);
66 void OnUpdate(wxCommandEvent
& event
);
67 void OnRevert(wxCommandEvent
& event
);
69 virtual bool OnClose();
70 virtual void OnDoubleClick(wxControl
*item
);
72 // TODO: does OnCommand still get called...??? No,
73 // make ProcessEvent do it.
74 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
76 // Extend event processing to process OnCommand
77 virtual bool ProcessEvent(wxEvent
& event
);
79 inline virtual void AssociatePanel(wxWindow
*win
) { m_propertyWindow
= win
; }
80 inline virtual wxWindow
*GetPanel(void) const { return m_propertyWindow
; }
82 inline virtual void SetManagedWindow(wxWindow
*win
) { m_managedWindow
= win
; }
83 inline virtual wxWindow
*GetManagedWindow(void) const { return m_managedWindow
; }
85 inline virtual wxButton
*GetWindowCloseButton() const { return m_windowCloseButton
; }
86 inline virtual wxButton
*GetWindowCancelButton() const { return m_windowCancelButton
; }
87 inline virtual wxButton
*GetHelpButton() const { return m_windowHelpButton
; }
90 static bool sm_dialogCancelled
;
93 bool m_detailedEditing
; // E.g. using listbox for choices
95 wxWindow
* m_propertyWindow
; // Panel that the controls will appear on
96 wxWindow
* m_managedWindow
; // Frame or dialog
98 wxButton
* m_windowCloseButton
; // Or OK
99 wxButton
* m_windowCancelButton
;
100 wxButton
* m_windowHelpButton
;
102 DECLARE_EVENT_TABLE()
107 * The type of validator used for forms (wxForm style but using an existing panel
109 * Classes derived from this know how to map from whatever widget they
110 * find themselves paired with, to the wxProperty and vice versa.
111 * Should the widget pointer be stored with the validator, or
112 * the wxProperty? If with the property, we don't have to supply
113 * a validator for every property. Otherwise, there ALWAYS needs
114 * to be a validator. On the other hand, not storing a wxWindow pointer
115 * in the wxProperty is more elegant. Perhaps.
116 * I think on balance, should put wxWindow pointer into wxProperty.
117 * After all, wxProperty will often be used to represent the data
118 * assocated with a window. It's that kinda thing.
121 class WXDLLEXPORT wxPropertyFormValidator
: public wxPropertyValidator
123 DECLARE_DYNAMIC_CLASS(wxPropertyFormValidator
)
126 wxPropertyFormValidator(long flags
= 0): wxPropertyValidator(flags
) { }
127 ~wxPropertyFormValidator(void) {}
129 // Called to check value is OK (e.g. when OK is pressed)
130 // Return FALSE if value didn't check out; signal to restore old value.
131 virtual bool OnCheckValue( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
132 wxWindow
*WXUNUSED(parentWindow
) ) { return TRUE
; }
134 // Does the transferance from the property editing area to the property itself.
135 // Called by the view, e.g. when closing the window.
136 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
) = 0;
138 // Called by the view to transfer the property to the window.
139 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
) = 0;
141 virtual void OnDoubleClick( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
142 wxWindow
*WXUNUSED(parentWindow
) ) { }
143 virtual void OnSetFocus( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
144 wxWindow
*WXUNUSED(parentWindow
) ) { }
145 virtual void OnKillFocus( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
146 wxWindow
*WXUNUSED(parentWindow
) ) { }
147 virtual void OnCommand( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
148 wxWindow
*WXUNUSED(parentWindow
), wxCommandEvent
& WXUNUSED(event
) ) {}
150 // Virtual function hiding suppression
151 #if WXWIN_COMPATIBILITY_2
152 virtual void OnCommand(wxWindow
& win
,
153 wxCommandEvent
& event
)
154 { wxEvtHandler::OnCommand(win
, event
); }
159 * Some default validators
162 class WXDLLEXPORT wxRealFormValidator
: public wxPropertyFormValidator
164 DECLARE_DYNAMIC_CLASS(wxRealFormValidator
)
166 // 0.0, 0.0 means no range
167 wxRealFormValidator(float min
= 0.0, float max
= 0.0, long flags
= 0):wxPropertyFormValidator(flags
)
169 m_realMin
= min
; m_realMax
= max
;
171 ~wxRealFormValidator(void) {}
173 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
174 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
175 // Called by the view to transfer the property to the window.
176 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
183 class WXDLLEXPORT wxIntegerFormValidator
: public wxPropertyFormValidator
185 DECLARE_DYNAMIC_CLASS(wxIntegerFormValidator
)
187 // 0, 0 means no range
188 wxIntegerFormValidator(long min
= 0, long max
= 0, long flags
= 0):wxPropertyFormValidator(flags
)
190 m_integerMin
= min
; m_integerMax
= max
;
192 ~wxIntegerFormValidator(void) {}
194 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
195 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
196 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
203 class WXDLLEXPORT wxBoolFormValidator
: public wxPropertyFormValidator
205 DECLARE_DYNAMIC_CLASS(wxBoolFormValidator
)
208 wxBoolFormValidator(long flags
= 0):wxPropertyFormValidator(flags
)
211 ~wxBoolFormValidator(void) {}
213 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
214 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
215 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
218 class WXDLLEXPORT wxStringFormValidator
: public wxPropertyFormValidator
220 DECLARE_DYNAMIC_CLASS(wxStringFormValidator
)
222 wxStringFormValidator(wxStringList
*list
= NULL
, long flags
= 0);
224 ~wxStringFormValidator(void)
230 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
231 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
232 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
235 wxStringList
* m_strings
;
239 * A default dialog box class to use.
242 class WXDLLEXPORT wxPropertyFormDialog
: public wxDialog
245 wxPropertyFormDialog(wxPropertyFormView
*v
= NULL
,
246 wxWindow
*parent
= NULL
,
247 const wxString
& title
= wxEmptyString
,
248 const wxPoint
& pos
= wxDefaultPosition
,
249 const wxSize
& size
= wxDefaultSize
,
250 long style
= wxDEFAULT_DIALOG_STYLE
,
251 const wxString
& name
= _T("dialogBox"));
253 void OnCloseWindow(wxCloseEvent
& event
);
254 void OnDefaultAction(wxControl
*item
);
255 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
257 // Extend event processing to search the view's event table
258 virtual bool ProcessEvent(wxEvent
& event
);
261 wxPropertyFormView
* m_view
;
263 DECLARE_EVENT_TABLE()
264 DECLARE_CLASS(wxPropertyFormDialog
)
268 * A default panel class to use.
271 class WXDLLEXPORT wxPropertyFormPanel
: public wxPanel
274 wxPropertyFormPanel(wxPropertyFormView
*v
= NULL
,
275 wxWindow
*parent
= NULL
,
276 const wxPoint
& pos
= wxDefaultPosition
,
277 const wxSize
& size
= wxDefaultSize
,
279 const wxString
& name
= _T("panel"))
280 : wxPanel(parent
, -1, pos
, size
, style
, name
)
284 void OnDefaultAction(wxControl
*item
);
285 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
287 // Extend event processing to search the view's event table
288 virtual bool ProcessEvent(wxEvent
& event
);
289 void SetView(wxPropertyFormView
* view
) { m_view
= view
; }
290 wxPropertyFormView
* GetView() const { return m_view
; }
293 wxPropertyFormView
* m_view
;
295 DECLARE_CLASS(wxPropertyFormPanel
)
299 * A default frame class to use.
302 class WXDLLEXPORT wxPropertyFormFrame
: public wxFrame
305 wxPropertyFormFrame(wxPropertyFormView
*v
= NULL
,
306 wxFrame
*parent
= NULL
,
307 const wxString
& title
= wxEmptyString
,
308 const wxPoint
& pos
= wxDefaultPosition
,
309 const wxSize
& size
= wxDefaultSize
,
310 long style
= wxDEFAULT_FRAME_STYLE
,
311 const wxString
& name
= _T("frame"))
312 : wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
315 m_propertyPanel
= NULL
;
317 void OnCloseWindow(wxCloseEvent
& event
);
319 // Must call this to create panel and associate view
320 virtual bool Initialize(void);
321 virtual wxPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyFormView
*v
);
322 inline virtual wxPanel
*GetPropertyPanel(void) const { return m_propertyPanel
; }
325 wxPropertyFormView
* m_view
;
326 wxPanel
* m_propertyPanel
;
328 DECLARE_EVENT_TABLE()
329 DECLARE_CLASS(wxPropertyFormFrame
)