1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/editors.h
3 // Purpose: wxPropertyGrid editors
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_EDITORS_H_
13 #define _WX_PROPGRID_EDITORS_H_
17 // -----------------------------------------------------------------------
18 // wxPGWindowList contains list of editor windows returned by CreateControls.
25 m_primary
= m_secondary
= NULL
;
28 void SetSecondary( wxWindow
* secondary
) { m_secondary
= secondary
; }
31 wxWindow
* m_secondary
;
34 wxPGWindowList( wxWindow
* a
)
39 wxPGWindowList( wxWindow
* a
, wxWindow
* b
)
47 // -----------------------------------------------------------------------
51 Base class for custom wxPropertyGrid editors.
54 - Names of builtin property editors are: TextCtrl, Choice,
55 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
56 editors include SpinCtrl and DatePickerCtrl, but using them requires
57 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
59 - Pointer to builtin editor is available as wxPGEditor_EditorName
60 (eg. wxPGEditor_TextCtrl).
62 - To add new editor you need to register it first using static function
63 wxPropertyGrid::RegisterEditorClass(), with code like this:
65 wxPGEditor *editorPointer = wxPropertyGrid::RegisterEditorClass(
66 new MyEditorClass(), "MyEditor");
68 After that, wxPropertyGrid will take ownership of the given object, but
69 you should still store editorPointer somewhere, so you can pass it to
70 wxPGProperty::SetEditor(), or return it from
71 wxPGEditor::DoGetEditorClass().
76 class WXDLLIMPEXP_PROPGRID wxPGEditor
: public wxObject
79 DECLARE_ABSTRACT_CLASS(wxPGEditor
)
91 virtual ~wxPGEditor();
94 Returns pointer to the name of the editor. For example,
95 wxPGEditor_TextCtrl has name "TextCtrl". This method is autogenerated
98 virtual wxString
GetName() const = 0;
101 Instantiates editor controls.
104 wxPropertyGrid to which the property belongs (use as parent for
107 Property for which this method is called.
109 Position, inside wxPropertyGrid, to create control(s) to.
111 Initial size for control(s).
114 - Primary control shall use id wxPG_SUBID1, and secondary (button)
115 control shall use wxPG_SUBID2.
116 - Implementation shoud connect all necessary events to the
117 wxPropertyGrid::OnCustomEditorEvent. For Example:
119 // Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor
120 // control to the OnEvent.
121 control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
122 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent),
125 OnCustomEditorEvent will then forward events, first to
126 wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
128 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
129 wxPGProperty
* property
,
131 const wxSize
& size
) const = 0;
132 #define wxPG_DECLARE_CREATECONTROLS \
133 virtual wxPGWindowList \
134 CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property, \
135 const wxPoint& pos, const wxSize& sz ) const;
137 /** Loads value from property to the control. */
138 virtual void UpdateControl( wxPGProperty
* property
,
139 wxWindow
* ctrl
) const = 0;
142 Used to get the renderer to draw the value with when the control is
145 Default implementation returns g_wxPGDefaultRenderer.
147 //virtual wxPGCellRenderer* GetCellRenderer() const;
149 /** Draws value for given property.
151 virtual void DrawValue( wxDC
& dc
,
153 wxPGProperty
* property
,
154 const wxString
& text
) const;
156 /** Handles events. Returns true if value in control was modified
157 (see wxPGProperty::OnEvent for more information).
159 @remarks wxPropertyGrid will automatically unfocus the editor when
160 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
161 property value being modified. This happens regardless of
162 editor type (ie. behavior is same for any wxTextCtrl and
163 wxComboBox based editor).
165 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
166 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
168 #if !defined(SWIG) || defined(CREATE_VCW)
169 /** Returns value from control, via parameter 'variant'.
170 Usually ends up calling property's StringToValue or IntToValue.
171 Returns true if value was different.
173 virtual bool GetValueFromControl( wxVariant
& variant
,
174 wxPGProperty
* property
,
175 wxWindow
* ctrl
) const;
178 /** Sets value in control to unspecified. */
179 virtual void SetValueToUnspecified( wxPGProperty
* property
,
180 wxWindow
* ctrl
) const = 0;
182 /** Sets control's value specifically from string. */
183 virtual void SetControlStringValue( wxPGProperty
* property
,
185 const wxString
& txt
) const;
187 /** Sets control's value specifically from int (applies to choice etc.). */
188 virtual void SetControlIntValue( wxPGProperty
* property
,
192 /** Inserts item to existing control. Index -1 means appending.
193 Default implementation does nothing. Returns index of item added.
195 virtual int InsertItem( wxWindow
* ctrl
,
196 const wxString
& label
,
199 /** Deletes item from existing control.
200 Default implementation does nothing.
202 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
204 /** Extra processing when control gains focus. For example, wxTextCtrl
205 based controls should select all text.
207 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
209 /** Returns true if control itself can contain the custom image. Default is
212 virtual bool CanContainCustomImage() const;
215 // This member is public so scripting language bindings
216 // wrapper code can access it freely.
222 // Note that we don't use this macro in this file because
223 // otherwise doxygen gets confused.
225 #define WX_PG_DECLARE_EDITOR_CLASS(CLASSNAME) \
226 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
228 virtual wxString GetName() const; \
232 #define WX_PG_IMPLEMENT_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
233 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
234 wxString CLASSNAME::GetName() const \
236 return wxS(#EDITOR); \
238 wxPGEditor* wxPGEditor_##EDITOR = (wxPGEditor*) NULL; \
239 wxPGEditor* wxPGConstruct##EDITOR##EditorClass() \
241 wxASSERT( !wxPGEditor_##EDITOR ); \
242 return new CLASSNAME(); \
246 #define WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS() \
247 wxPG_DECLARE_CREATECONTROLS \
248 virtual void UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const; \
249 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property, \
250 wxWindow* primary, wxEvent& event ) const; \
251 virtual bool GetValueFromControl( wxVariant& variant, \
252 wxPGProperty* property, \
253 wxWindow* ctrl ) const; \
254 virtual void SetValueToUnspecified( wxPGProperty* property, \
255 wxWindow* ctrl ) const;
259 // Following are the built-in editor classes.
262 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
265 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
268 wxPGTextCtrlEditor() {}
269 virtual ~wxPGTextCtrlEditor();
271 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
272 virtual wxString
GetName() const;
274 //virtual wxPGCellRenderer* GetCellRenderer() const;
275 virtual void SetControlStringValue( wxPGProperty
* property
,
277 const wxString
& txt
) const;
278 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
280 // Provided so that, for example, ComboBox editor can use the same code
281 // (multiple inheritance would get way too messy).
282 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
283 wxPGProperty
* property
,
287 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
288 wxPGProperty
* property
,
294 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
297 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
300 wxPGChoiceEditor() {}
301 virtual ~wxPGChoiceEditor();
303 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
304 virtual wxString
GetName() const;
306 virtual void SetControlIntValue( wxPGProperty
* property
,
309 virtual void SetControlStringValue( wxPGProperty
* property
,
311 const wxString
& txt
) const;
313 virtual int InsertItem( wxWindow
* ctrl
,
314 const wxString
& label
,
316 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
317 virtual bool CanContainCustomImage() const;
319 // CreateControls calls this with CB_READONLY in extraStyle
320 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
321 wxPGProperty
* property
,
324 long extraStyle
) const;
329 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
332 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
335 wxPGComboBoxEditor() {}
336 virtual ~wxPGComboBoxEditor();
338 // Macro is used for convenience due to different signature with wxPython
339 wxPG_DECLARE_CREATECONTROLS
341 virtual wxString
GetName() const;
343 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
345 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
346 wxWindow
* ctrl
, wxEvent
& event
) const;
348 virtual bool GetValueFromControl( wxVariant
& variant
,
349 wxPGProperty
* property
,
350 wxWindow
* ctrl
) const;
352 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
357 // Exclude classes from being able to be derived from in wxPython bindings
360 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
363 wxPGChoiceAndButtonEditor() {}
364 virtual ~wxPGChoiceAndButtonEditor();
365 virtual wxString
GetName() const;
367 // Macro is used for convenience due to different signature with wxPython
368 wxPG_DECLARE_CREATECONTROLS
370 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
373 class WXDLLIMPEXP_PROPGRID
374 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
377 wxPGTextCtrlAndButtonEditor() {}
378 virtual ~wxPGTextCtrlAndButtonEditor();
379 virtual wxString
GetName() const;
380 wxPG_DECLARE_CREATECONTROLS
382 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
388 #if wxPG_INCLUDE_CHECKBOX || defined(DOXYGEN)
391 // Use custom check box code instead of native control
392 // for cleaner (ie. more integrated) look.
394 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
397 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
400 wxPGCheckBoxEditor() {}
401 virtual ~wxPGCheckBoxEditor();
403 virtual wxString
GetName() const;
404 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
406 virtual void DrawValue( wxDC
& dc
,
408 wxPGProperty
* property
,
409 const wxString
& text
) const;
410 //virtual wxPGCellRenderer* GetCellRenderer() const;
412 virtual void SetControlIntValue( wxPGProperty
* property
,
420 // -----------------------------------------------------------------------
421 // Editor class registeration macros
423 #define wxPGRegisterEditorClass(EDITOR) \
424 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
426 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
427 wxPGConstruct##EDITOR##EditorClass() ); \
430 // Use this in RegisterDefaultEditors.
431 #define wxPGRegisterDefaultEditorClass(EDITOR) \
432 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
434 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
435 wxPGConstruct##EDITOR##EditorClass(), true ); \
438 #define wxPG_INIT_REQUIRED_EDITOR(T) \
439 wxPGRegisterEditorClass(T)
442 // -----------------------------------------------------------------------
444 /** @class wxPGEditorDialogAdapter
446 Derive a class from this to adapt an existing editor dialog or function to
447 be used when editor button of a property is pushed.
449 You only need to derive class and implement DoShowDialog() to create and
450 show the dialog, and finally submit the value returned by the dialog
456 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
459 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
462 wxPGEditorDialogAdapter()
468 virtual ~wxPGEditorDialogAdapter() { }
470 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
472 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
473 wxPGProperty
* property
) = 0;
475 void SetValue( wxVariant value
)
481 This method is typically only used if deriving class from existing
482 adapter with value conversion purposes.
484 wxVariant
& GetValue() { return m_value
; }
487 // This member is public so scripting language bindings
488 // wrapper code can access it freely.
495 // -----------------------------------------------------------------------
498 /** @class wxPGMultiButton
500 This class can be used to have multiple buttons in a property editor.
501 You will need to create a new property editor class, override
502 CreateControls, and have it return wxPGMultiButton instance in
503 wxPGWindowList::SetSecondary().
505 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
508 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
510 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
511 const wxWindow
* GetButton( unsigned int i
) const
512 { return (const wxWindow
*) m_buttons
[i
]; }
514 /** Utility function to be used in event handlers.
516 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
518 /** Returns number of buttons.
520 int GetCount() const { return m_buttons
.Count(); }
522 void Add( const wxString
& label
, int id
= -2 );
524 void Add( const wxBitmap
& bitmap
, int id
= -2 );
527 wxSize
GetPrimarySize() const
529 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
532 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
537 int GenId( int id
) const;
539 wxArrayPtrVoid m_buttons
;
540 wxSize m_fullEditorSize
;
545 // -----------------------------------------------------------------------
547 #endif // wxUSE_PROPGRID
549 #endif // _WX_PROPGRID_EDITORS_H_