1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/editors.h
3 // Purpose: wxPropertyGrid editors
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROPGRID_EDITORS_H_
12 #define _WX_PROPGRID_EDITORS_H_
18 class WXDLLIMPEXP_FWD_PROPGRID wxPGCell
;
19 class WXDLLIMPEXP_FWD_PROPGRID wxPGProperty
;
20 class WXDLLIMPEXP_FWD_PROPGRID wxPropertyGrid
;
22 // -----------------------------------------------------------------------
23 // wxPGWindowList contains list of editor windows returned by CreateControls.
30 m_primary
= m_secondary
= NULL
;
33 void SetSecondary( wxWindow
* secondary
) { m_secondary
= secondary
; }
36 wxWindow
* m_secondary
;
38 wxPGWindowList( wxWindow
* a
)
43 wxPGWindowList( wxWindow
* a
, wxWindow
* b
)
50 // -----------------------------------------------------------------------
54 Base class for custom wxPropertyGrid editors.
57 - Names of builtin property editors are: TextCtrl, Choice,
58 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
59 editors include SpinCtrl and DatePickerCtrl, but using them requires
60 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
62 - Pointer to builtin editor is available as wxPGEditor_EditorName
63 (eg. wxPGEditor_TextCtrl).
65 - To add new editor you need to register it first using static function
66 wxPropertyGrid::RegisterEditorClass(), with code like this:
68 wxPGEditor *editorPointer = wxPropertyGrid::RegisterEditorClass(
69 new MyEditorClass(), "MyEditor");
71 After that, wxPropertyGrid will take ownership of the given object, but
72 you should still store editorPointer somewhere, so you can pass it to
73 wxPGProperty::SetEditor(), or return it from
74 wxPGEditor::DoGetEditorClass().
79 class WXDLLIMPEXP_PROPGRID wxPGEditor
: public wxObject
81 DECLARE_ABSTRACT_CLASS(wxPGEditor
)
92 virtual ~wxPGEditor();
95 Returns pointer to the name of the editor. For example,
96 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
97 your custom editor by string name, then you do not need to implement
100 virtual wxString
GetName() const;
103 Instantiates editor controls.
106 wxPropertyGrid to which the property belongs (use as parent for
109 Property for which this method is called.
111 Position, inside wxPropertyGrid, to create control(s) to.
113 Initial size for control(s).
116 - Primary control shall use id wxPG_SUBID1, and secondary (button)
117 control shall use wxPG_SUBID2.
118 - Unlike in previous version of wxPropertyGrid, it is no longer
119 necessary to call wxEvtHandler::Connect() for interesting editor
120 events. Instead, all events from control are now automatically
121 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
123 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
124 wxPGProperty
* property
,
126 const wxSize
& size
) const = 0;
128 /** Loads value from property to the control. */
129 virtual void UpdateControl( wxPGProperty
* property
,
130 wxWindow
* ctrl
) const = 0;
133 Used to get the renderer to draw the value with when the control is
136 Default implementation returns g_wxPGDefaultRenderer.
138 //virtual wxPGCellRenderer* GetCellRenderer() const;
140 /** Draws value for given property.
142 virtual void DrawValue( wxDC
& dc
,
144 wxPGProperty
* property
,
145 const wxString
& text
) const;
147 /** Handles events. Returns true if value in control was modified
148 (see wxPGProperty::OnEvent for more information).
150 @remarks wxPropertyGrid will automatically unfocus the editor when
151 wxEVT_TEXT_ENTER is received and when it results in
152 property value being modified. This happens regardless of
153 editor type (ie. behaviour is same for any wxTextCtrl and
154 wxComboBox based editor).
156 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
157 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
159 /** Returns value from control, via parameter 'variant'.
160 Usually ends up calling property's StringToValue or IntToValue.
161 Returns true if value was different.
163 virtual bool GetValueFromControl( wxVariant
& variant
,
164 wxPGProperty
* property
,
165 wxWindow
* ctrl
) const;
168 Sets new appearance for the control. Default implementation
169 sets foreground colour, background colour, font, plus text
170 for wxTextCtrl and wxComboCtrl.
173 New appearance to be applied.
176 Previously applied appearance. Used to detect which
177 control attributes need to be changed (e.g. so we only
178 change background colour if really needed).
181 @true if the new appearance represents an unspecified
184 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
185 wxPGProperty
* property
,
187 const wxPGCell
& appearance
,
188 const wxPGCell
& oldAppearance
,
189 bool unspecified
) const;
192 Sets value in control to unspecified.
194 virtual void SetValueToUnspecified( wxPGProperty
* property
,
195 wxWindow
* ctrl
) const;
197 /** Sets control's value specifically from string. */
198 virtual void SetControlStringValue( wxPGProperty
* property
,
200 const wxString
& txt
) const;
202 /** Sets control's value specifically from int (applies to choice etc.). */
203 virtual void SetControlIntValue( wxPGProperty
* property
,
207 /** Inserts item to existing control. Index -1 means appending.
208 Default implementation does nothing. Returns index of item added.
210 virtual int InsertItem( wxWindow
* ctrl
,
211 const wxString
& label
,
214 /** Deletes item from existing control.
215 Default implementation does nothing.
217 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
219 /** Extra processing when control gains focus. For example, wxTextCtrl
220 based controls should select all text.
222 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
224 /** Returns true if control itself can contain the custom image. Default is
227 virtual bool CanContainCustomImage() const;
230 // This member is public so scripting language bindings
231 // wrapper code can access it freely.
236 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
237 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
238 wxString CLASSNAME::GetName() const \
240 return wxS(#EDITOR); \
242 wxPGEditor* wxPGEditor_##EDITOR = NULL;
246 // Following are the built-in editor classes.
249 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
251 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
253 wxPGTextCtrlEditor() {}
254 virtual ~wxPGTextCtrlEditor();
256 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
257 wxPGProperty
* property
,
259 const wxSize
& size
) const;
260 virtual void UpdateControl( wxPGProperty
* property
,
261 wxWindow
* ctrl
) const;
262 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
263 wxPGProperty
* property
,
264 wxWindow
* primaryCtrl
,
265 wxEvent
& event
) const;
266 virtual bool GetValueFromControl( wxVariant
& variant
,
267 wxPGProperty
* property
,
268 wxWindow
* ctrl
) const;
270 virtual wxString
GetName() const;
272 //virtual wxPGCellRenderer* GetCellRenderer() const;
273 virtual void SetControlStringValue( wxPGProperty
* property
,
275 const wxString
& txt
) const;
276 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
278 // Provided so that, for example, ComboBox editor can use the same code
279 // (multiple inheritance would get way too messy).
280 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
281 wxPGProperty
* property
,
285 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
286 wxPGProperty
* property
,
292 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
294 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
296 wxPGChoiceEditor() {}
297 virtual ~wxPGChoiceEditor();
299 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
300 wxPGProperty
* property
,
302 const wxSize
& size
) const;
303 virtual void UpdateControl( wxPGProperty
* property
,
304 wxWindow
* ctrl
) const;
305 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
306 wxPGProperty
* property
,
307 wxWindow
* primaryCtrl
,
308 wxEvent
& event
) const;
309 virtual bool GetValueFromControl( wxVariant
& variant
,
310 wxPGProperty
* property
,
311 wxWindow
* ctrl
) const;
312 virtual void SetValueToUnspecified( wxPGProperty
* property
,
313 wxWindow
* ctrl
) const;
314 virtual wxString
GetName() const;
316 virtual void SetControlIntValue( wxPGProperty
* property
,
319 virtual void SetControlStringValue( wxPGProperty
* property
,
321 const wxString
& txt
) const;
323 virtual int InsertItem( wxWindow
* ctrl
,
324 const wxString
& label
,
326 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
327 virtual bool CanContainCustomImage() const;
329 // CreateControls calls this with CB_READONLY in extraStyle
330 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
331 wxPGProperty
* property
,
334 long extraStyle
) const;
339 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
341 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
343 wxPGComboBoxEditor() {}
344 virtual ~wxPGComboBoxEditor();
346 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
347 wxPGProperty
* property
,
349 const wxSize
& size
) const;
351 virtual wxString
GetName() const;
353 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
355 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
356 wxWindow
* ctrl
, wxEvent
& event
) const;
358 virtual bool GetValueFromControl( wxVariant
& variant
,
359 wxPGProperty
* property
,
360 wxWindow
* ctrl
) const;
362 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
367 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
370 wxPGChoiceAndButtonEditor() {}
371 virtual ~wxPGChoiceAndButtonEditor();
372 virtual wxString
GetName() const;
374 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
375 wxPGProperty
* property
,
377 const wxSize
& size
) const;
379 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
382 class WXDLLIMPEXP_PROPGRID
383 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
386 wxPGTextCtrlAndButtonEditor() {}
387 virtual ~wxPGTextCtrlAndButtonEditor();
388 virtual wxString
GetName() const;
390 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
391 wxPGProperty
* property
,
393 const wxSize
& size
) const;
395 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
399 #if wxPG_INCLUDE_CHECKBOX
402 // Use custom check box code instead of native control
403 // for cleaner (ie. more integrated) look.
405 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
407 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
409 wxPGCheckBoxEditor() {}
410 virtual ~wxPGCheckBoxEditor();
412 virtual wxString
GetName() const;
413 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
414 wxPGProperty
* property
,
416 const wxSize
& size
) const;
417 virtual void UpdateControl( wxPGProperty
* property
,
418 wxWindow
* ctrl
) const;
419 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
420 wxPGProperty
* property
,
421 wxWindow
* primaryCtrl
,
422 wxEvent
& event
) const;
423 virtual bool GetValueFromControl( wxVariant
& variant
,
424 wxPGProperty
* property
,
425 wxWindow
* ctrl
) const;
426 virtual void SetValueToUnspecified( wxPGProperty
* property
,
427 wxWindow
* ctrl
) const;
429 virtual void DrawValue( wxDC
& dc
,
431 wxPGProperty
* property
,
432 const wxString
& text
) const;
433 //virtual wxPGCellRenderer* GetCellRenderer() const;
435 virtual void SetControlIntValue( wxPGProperty
* property
,
443 // -----------------------------------------------------------------------
444 // Editor class registeration macro (mostly for internal use)
446 #define wxPGRegisterEditorClass(EDITOR) \
447 if ( wxPGEditor_##EDITOR == NULL ) \
449 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
450 new wxPG##EDITOR##Editor ); \
453 // -----------------------------------------------------------------------
455 /** @class wxPGEditorDialogAdapter
457 Derive a class from this to adapt an existing editor dialog or function to
458 be used when editor button of a property is pushed.
460 You only need to derive class and implement DoShowDialog() to create and
461 show the dialog, and finally submit the value returned by the dialog
467 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
469 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
471 wxPGEditorDialogAdapter()
477 virtual ~wxPGEditorDialogAdapter() { }
479 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
481 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
482 wxPGProperty
* property
) = 0;
484 void SetValue( wxVariant value
)
490 This method is typically only used if deriving class from existing
491 adapter with value conversion purposes.
493 wxVariant
& GetValue() { return m_value
; }
496 // This member is public so scripting language bindings
497 // wrapper code can access it freely.
504 // -----------------------------------------------------------------------
507 /** @class wxPGMultiButton
509 This class can be used to have multiple buttons in a property editor.
510 You will need to create a new property editor class, override
511 CreateControls, and have it return wxPGMultiButton instance in
512 wxPGWindowList::SetSecondary().
514 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
517 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
518 virtual ~wxPGMultiButton() {}
520 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
521 const wxWindow
* GetButton( unsigned int i
) const
522 { return (const wxWindow
*) m_buttons
[i
]; }
524 /** Utility function to be used in event handlers.
526 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
528 /** Returns number of buttons.
530 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
532 void Add( const wxString
& label
, int id
= -2 );
534 void Add( const wxBitmap
& bitmap
, int id
= -2 );
537 wxSize
GetPrimarySize() const
539 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
542 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
546 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
548 int GenId( int id
) const;
550 wxArrayPtrVoid m_buttons
;
551 wxSize m_fullEditorSize
;
555 // -----------------------------------------------------------------------
557 #endif // wxUSE_PROPGRID
559 #endif // _WX_PROPGRID_EDITORS_H_