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_
16 #pragma interface "propform.h"
24 //// Property form classes: for using an existing dialog or panel
27 #define wxID_PROP_REVERT 3100
28 #define wxID_PROP_UPDATE 3101
30 // Mediates between a physical panel and the property sheet
31 class WXDLLEXPORT wxPropertyFormView
: public wxPropertyView
33 DECLARE_DYNAMIC_CLASS(wxPropertyFormView
)
35 wxPropertyFormView(wxWindow
*propPanel
= NULL
, long flags
= 0);
36 ~wxPropertyFormView(void);
38 // Associates and shows the view
39 virtual void ShowView(wxPropertySheet
*propertySheet
, wxWindow
*panel
);
41 // Update this view of the viewed object, called e.g. by
43 virtual bool OnUpdateView(void);
45 // Transfer values from property sheet to dialog
46 virtual bool TransferToDialog(void);
48 // Transfer values from dialog to property sheet
49 virtual bool TransferToPropertySheet(void);
51 // Check that all the values are valid
52 virtual bool Check(void);
54 // Give each property in the sheet a panel item, by matching
55 // the name of the property to the name of the panel item.
56 // The user doesn't always want to call this; sometimes, it
57 // will have been done explicitly (e.g., no matching names).
58 virtual bool AssociateNames(void);
60 void OnOk(wxCommandEvent
& event
);
61 void OnCancel(wxCommandEvent
& event
);
62 void OnHelp(wxCommandEvent
& event
);
63 void OnUpdate(wxCommandEvent
& event
);
64 void OnRevert(wxCommandEvent
& event
);
66 virtual bool OnClose();
67 virtual void OnDoubleClick(wxControl
*item
);
69 // TODO: does OnCommand still get called...??? No,
70 // make ProcessEvent do it.
71 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
73 // Extend event processing to process OnCommand
74 virtual bool ProcessEvent(wxEvent
& event
);
76 inline virtual void AssociatePanel(wxWindow
*win
) { m_propertyWindow
= win
; }
77 inline virtual wxWindow
*GetPanel(void) const { return m_propertyWindow
; }
79 inline virtual void SetManagedWindow(wxWindow
*win
) { m_managedWindow
= win
; }
80 inline virtual wxWindow
*GetManagedWindow(void) const { return m_managedWindow
; }
82 inline virtual wxButton
*GetWindowCloseButton() const { return m_windowCloseButton
; }
83 inline virtual wxButton
*GetWindowCancelButton() const { return m_windowCancelButton
; }
84 inline virtual wxButton
*GetHelpButton() const { return m_windowHelpButton
; }
87 static bool sm_dialogCancelled
;
90 bool m_detailedEditing
; // E.g. using listbox for choices
92 wxWindow
* m_propertyWindow
; // Panel that the controls will appear on
93 wxWindow
* m_managedWindow
; // Frame or dialog
95 wxButton
* m_windowCloseButton
; // Or OK
96 wxButton
* m_windowCancelButton
;
97 wxButton
* m_windowHelpButton
;
104 * The type of validator used for forms (wxForm style but using an existing panel
106 * Classes derived from this know how to map from whatever widget they
107 * find themselves paired with, to the wxProperty and vice versa.
108 * Should the widget pointer be stored with the validator, or
109 * the wxProperty? If with the property, we don't have to supply
110 * a validator for every property. Otherwise, there ALWAYS needs
111 * to be a validator. On the other hand, not storing a wxWindow pointer
112 * in the wxProperty is more elegant. Perhaps.
113 * I think on balance, should put wxWindow pointer into wxProperty.
114 * After all, wxProperty will often be used to represent the data
115 * assocated with a window. It's that kinda thing.
118 class WXDLLEXPORT wxPropertyFormValidator
: public wxPropertyValidator
120 DECLARE_DYNAMIC_CLASS(wxPropertyFormValidator
)
123 wxPropertyFormValidator(long flags
= 0): wxPropertyValidator(flags
) { }
124 ~wxPropertyFormValidator(void) {}
126 // Called to check value is OK (e.g. when OK is pressed)
127 // Return FALSE if value didn't check out; signal to restore old value.
128 virtual bool OnCheckValue( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
129 wxWindow
*WXUNUSED(parentWindow
) ) { return TRUE
; }
131 // Does the transferance from the property editing area to the property itself.
132 // Called by the view, e.g. when closing the window.
133 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
) = 0;
135 // Called by the view to transfer the property to the window.
136 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
) = 0;
138 virtual void OnDoubleClick( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
139 wxWindow
*WXUNUSED(parentWindow
) ) { }
140 virtual void OnSetFocus( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
141 wxWindow
*WXUNUSED(parentWindow
) ) { }
142 virtual void OnKillFocus( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
143 wxWindow
*WXUNUSED(parentWindow
) ) { }
144 virtual void OnCommand( wxProperty
*WXUNUSED(property
), wxPropertyFormView
*WXUNUSED(view
),
145 wxWindow
*WXUNUSED(parentWindow
), wxCommandEvent
& WXUNUSED(event
) ) {}
147 // Virtual function hiding suppression
148 #if WXWIN_COMPATIBILITY_2
149 virtual void OnCommand(wxWindow
& win
,
150 wxCommandEvent
& event
)
151 { wxEvtHandler::OnCommand(win
, event
); }
156 * Some default validators
159 class WXDLLEXPORT wxRealFormValidator
: public wxPropertyFormValidator
161 DECLARE_DYNAMIC_CLASS(wxRealFormValidator
)
163 // 0.0, 0.0 means no range
164 wxRealFormValidator(float min
= 0.0, float max
= 0.0, long flags
= 0):wxPropertyFormValidator(flags
)
166 m_realMin
= min
; m_realMax
= max
;
168 ~wxRealFormValidator(void) {}
170 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
171 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
172 // Called by the view to transfer the property to the window.
173 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
180 class WXDLLEXPORT wxIntegerFormValidator
: public wxPropertyFormValidator
182 DECLARE_DYNAMIC_CLASS(wxIntegerFormValidator
)
184 // 0, 0 means no range
185 wxIntegerFormValidator(long min
= 0, long max
= 0, long flags
= 0):wxPropertyFormValidator(flags
)
187 m_integerMin
= min
; m_integerMax
= max
;
189 ~wxIntegerFormValidator(void) {}
191 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
192 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
193 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
200 class WXDLLEXPORT wxBoolFormValidator
: public wxPropertyFormValidator
202 DECLARE_DYNAMIC_CLASS(wxBoolFormValidator
)
205 wxBoolFormValidator(long flags
= 0):wxPropertyFormValidator(flags
)
208 ~wxBoolFormValidator(void) {}
210 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
211 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
212 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
215 class WXDLLEXPORT wxStringFormValidator
: public wxPropertyFormValidator
217 DECLARE_DYNAMIC_CLASS(wxStringFormValidator
)
219 wxStringFormValidator(wxStringList
*list
= NULL
, long flags
= 0);
221 ~wxStringFormValidator(void)
227 bool OnCheckValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
228 bool OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
229 bool OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*view
, wxWindow
*parentWindow
);
232 wxStringList
* m_strings
;
236 * A default dialog box class to use.
239 class WXDLLEXPORT wxPropertyFormDialog
: public wxDialog
242 wxPropertyFormDialog(wxPropertyFormView
*v
= NULL
,
243 wxWindow
*parent
= NULL
,
244 const wxString
& title
= wxEmptyString
,
245 const wxPoint
& pos
= wxDefaultPosition
,
246 const wxSize
& size
= wxDefaultSize
,
247 long style
= wxDEFAULT_DIALOG_STYLE
,
248 const wxString
& name
= _T("dialogBox"));
250 void OnCloseWindow(wxCloseEvent
& event
);
251 void OnDefaultAction(wxControl
*item
);
252 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
254 // Extend event processing to search the view's event table
255 virtual bool ProcessEvent(wxEvent
& event
);
258 wxPropertyFormView
* m_view
;
260 DECLARE_EVENT_TABLE()
261 DECLARE_CLASS(wxPropertyFormDialog
)
265 * A default panel class to use.
268 class WXDLLEXPORT wxPropertyFormPanel
: public wxPanel
271 wxPropertyFormPanel(wxPropertyFormView
*v
= NULL
,
272 wxWindow
*parent
= NULL
,
273 const wxPoint
& pos
= wxDefaultPosition
,
274 const wxSize
& size
= wxDefaultSize
,
276 const wxString
& name
= _T("panel"))
277 : wxPanel(parent
, -1, pos
, size
, style
, name
)
281 void OnDefaultAction(wxControl
*item
);
282 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
284 // Extend event processing to search the view's event table
285 virtual bool ProcessEvent(wxEvent
& event
);
286 void SetView(wxPropertyFormView
* view
) { m_view
= view
; }
287 wxPropertyFormView
* GetView() const { return m_view
; }
290 wxPropertyFormView
* m_view
;
292 DECLARE_CLASS(wxPropertyFormPanel
)
296 * A default frame class to use.
299 class WXDLLEXPORT wxPropertyFormFrame
: public wxFrame
302 wxPropertyFormFrame(wxPropertyFormView
*v
= NULL
,
303 wxFrame
*parent
= NULL
,
304 const wxString
& title
= wxEmptyString
,
305 const wxPoint
& pos
= wxDefaultPosition
,
306 const wxSize
& size
= wxDefaultSize
,
307 long style
= wxDEFAULT_FRAME_STYLE
,
308 const wxString
& name
= _T("frame"))
309 : wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
312 m_propertyPanel
= NULL
;
314 void OnCloseWindow(wxCloseEvent
& event
);
316 // Must call this to create panel and associate view
317 virtual bool Initialize(void);
318 virtual wxPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyFormView
*v
);
319 inline virtual wxPanel
*GetPropertyPanel(void) const { return m_propertyPanel
; }
322 wxPropertyFormView
* m_view
;
323 wxPanel
* m_propertyPanel
;
325 DECLARE_EVENT_TABLE()
326 DECLARE_CLASS(wxPropertyFormFrame
)