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". If you dont' need to access
96 your custom editor by string name, then you do not need to implement
99 virtual wxString
GetName() const;
102 Instantiates editor controls.
105 wxPropertyGrid to which the property belongs (use as parent for
108 Property for which this method is called.
110 Position, inside wxPropertyGrid, to create control(s) to.
112 Initial size for control(s).
115 - Primary control shall use id wxPG_SUBID1, and secondary (button)
116 control shall use wxPG_SUBID2.
117 - Implementation shoud connect all necessary events to the
118 wxPropertyGrid::OnCustomEditorEvent. For Example:
120 // Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor
121 // control to the OnEvent.
122 control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
123 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent),
126 OnCustomEditorEvent will then forward events, first to
127 wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
129 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
130 wxPGProperty
* property
,
132 const wxSize
& size
) const = 0;
133 #define wxPG_DECLARE_CREATECONTROLS \
134 virtual wxPGWindowList \
135 CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property, \
136 const wxPoint& pos, const wxSize& sz ) const;
138 /** Loads value from property to the control. */
139 virtual void UpdateControl( wxPGProperty
* property
,
140 wxWindow
* ctrl
) const = 0;
143 Used to get the renderer to draw the value with when the control is
146 Default implementation returns g_wxPGDefaultRenderer.
148 //virtual wxPGCellRenderer* GetCellRenderer() const;
150 /** Draws value for given property.
152 virtual void DrawValue( wxDC
& dc
,
154 wxPGProperty
* property
,
155 const wxString
& text
) const;
157 /** Handles events. Returns true if value in control was modified
158 (see wxPGProperty::OnEvent for more information).
160 @remarks wxPropertyGrid will automatically unfocus the editor when
161 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
162 property value being modified. This happens regardless of
163 editor type (ie. behavior is same for any wxTextCtrl and
164 wxComboBox based editor).
166 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
167 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
169 #if !defined(SWIG) || defined(CREATE_VCW)
170 /** Returns value from control, via parameter 'variant'.
171 Usually ends up calling property's StringToValue or IntToValue.
172 Returns true if value was different.
174 virtual bool GetValueFromControl( wxVariant
& variant
,
175 wxPGProperty
* property
,
176 wxWindow
* ctrl
) const;
179 /** Sets value in control to unspecified. */
180 virtual void SetValueToUnspecified( wxPGProperty
* property
,
181 wxWindow
* ctrl
) const = 0;
183 /** Sets control's value specifically from string. */
184 virtual void SetControlStringValue( wxPGProperty
* property
,
186 const wxString
& txt
) const;
188 /** Sets control's value specifically from int (applies to choice etc.). */
189 virtual void SetControlIntValue( wxPGProperty
* property
,
193 /** Inserts item to existing control. Index -1 means appending.
194 Default implementation does nothing. Returns index of item added.
196 virtual int InsertItem( wxWindow
* ctrl
,
197 const wxString
& label
,
200 /** Deletes item from existing control.
201 Default implementation does nothing.
203 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
205 /** Extra processing when control gains focus. For example, wxTextCtrl
206 based controls should select all text.
208 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
210 /** Returns true if control itself can contain the custom image. Default is
213 virtual bool CanContainCustomImage() const;
216 // This member is public so scripting language bindings
217 // wrapper code can access it freely.
223 // Note that we don't use this macro in this file because
224 // otherwise doxygen gets confused.
226 #define WX_PG_DECLARE_EDITOR_CLASS(CLASSNAME) \
227 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
229 virtual wxString GetName() const; \
233 #define WX_PG_IMPLEMENT_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
234 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
235 wxString CLASSNAME::GetName() const \
237 return wxS(#EDITOR); \
239 wxPGEditor* wxPGEditor_##EDITOR = (wxPGEditor*) NULL; \
240 wxPGEditor* wxPGConstruct##EDITOR##EditorClass() \
242 wxASSERT( !wxPGEditor_##EDITOR ); \
243 return new CLASSNAME(); \
247 #define WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS() \
248 wxPG_DECLARE_CREATECONTROLS \
249 virtual void UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const; \
250 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property, \
251 wxWindow* primary, wxEvent& event ) const; \
252 virtual bool GetValueFromControl( wxVariant& variant, \
253 wxPGProperty* property, \
254 wxWindow* ctrl ) const; \
255 virtual void SetValueToUnspecified( wxPGProperty* property, \
256 wxWindow* ctrl ) const;
260 // Following are the built-in editor classes.
263 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
266 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
269 wxPGTextCtrlEditor() {}
270 virtual ~wxPGTextCtrlEditor();
272 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
273 virtual wxString
GetName() const;
275 //virtual wxPGCellRenderer* GetCellRenderer() const;
276 virtual void SetControlStringValue( wxPGProperty
* property
,
278 const wxString
& txt
) const;
279 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
281 // Provided so that, for example, ComboBox editor can use the same code
282 // (multiple inheritance would get way too messy).
283 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
284 wxPGProperty
* property
,
288 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
289 wxPGProperty
* property
,
295 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
298 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
301 wxPGChoiceEditor() {}
302 virtual ~wxPGChoiceEditor();
304 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
305 virtual wxString
GetName() const;
307 virtual void SetControlIntValue( wxPGProperty
* property
,
310 virtual void SetControlStringValue( wxPGProperty
* property
,
312 const wxString
& txt
) const;
314 virtual int InsertItem( wxWindow
* ctrl
,
315 const wxString
& label
,
317 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
318 virtual bool CanContainCustomImage() const;
320 // CreateControls calls this with CB_READONLY in extraStyle
321 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
322 wxPGProperty
* property
,
325 long extraStyle
) const;
330 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
333 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
336 wxPGComboBoxEditor() {}
337 virtual ~wxPGComboBoxEditor();
339 // Macro is used for convenience due to different signature with wxPython
340 wxPG_DECLARE_CREATECONTROLS
342 virtual wxString
GetName() const;
344 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
346 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
347 wxWindow
* ctrl
, wxEvent
& event
) const;
349 virtual bool GetValueFromControl( wxVariant
& variant
,
350 wxPGProperty
* property
,
351 wxWindow
* ctrl
) const;
353 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
358 // Exclude classes from being able to be derived from in wxPython bindings
361 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
364 wxPGChoiceAndButtonEditor() {}
365 virtual ~wxPGChoiceAndButtonEditor();
366 virtual wxString
GetName() const;
368 // Macro is used for convenience due to different signature with wxPython
369 wxPG_DECLARE_CREATECONTROLS
371 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
374 class WXDLLIMPEXP_PROPGRID
375 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
378 wxPGTextCtrlAndButtonEditor() {}
379 virtual ~wxPGTextCtrlAndButtonEditor();
380 virtual wxString
GetName() const;
381 wxPG_DECLARE_CREATECONTROLS
383 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
389 #if wxPG_INCLUDE_CHECKBOX || defined(DOXYGEN)
392 // Use custom check box code instead of native control
393 // for cleaner (ie. more integrated) look.
395 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
398 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
401 wxPGCheckBoxEditor() {}
402 virtual ~wxPGCheckBoxEditor();
404 virtual wxString
GetName() const;
405 WX_PG_IMPLEMENT_EDITOR_CLASS_STD_METHODS()
407 virtual void DrawValue( wxDC
& dc
,
409 wxPGProperty
* property
,
410 const wxString
& text
) const;
411 //virtual wxPGCellRenderer* GetCellRenderer() const;
413 virtual void SetControlIntValue( wxPGProperty
* property
,
421 // -----------------------------------------------------------------------
422 // Editor class registeration macros
424 #define wxPGRegisterEditorClass(EDITOR) \
425 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
427 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
428 wxPGConstruct##EDITOR##EditorClass() ); \
431 // Use this in RegisterDefaultEditors.
432 #define wxPGRegisterDefaultEditorClass(EDITOR) \
433 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
435 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
436 wxPGConstruct##EDITOR##EditorClass(), true ); \
439 #define wxPG_INIT_REQUIRED_EDITOR(T) \
440 wxPGRegisterEditorClass(T)
443 // -----------------------------------------------------------------------
445 /** @class wxPGEditorDialogAdapter
447 Derive a class from this to adapt an existing editor dialog or function to
448 be used when editor button of a property is pushed.
450 You only need to derive class and implement DoShowDialog() to create and
451 show the dialog, and finally submit the value returned by the dialog
457 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
460 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
463 wxPGEditorDialogAdapter()
469 virtual ~wxPGEditorDialogAdapter() { }
471 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
473 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
474 wxPGProperty
* property
) = 0;
476 void SetValue( wxVariant value
)
482 This method is typically only used if deriving class from existing
483 adapter with value conversion purposes.
485 wxVariant
& GetValue() { return m_value
; }
488 // This member is public so scripting language bindings
489 // wrapper code can access it freely.
496 // -----------------------------------------------------------------------
499 /** @class wxPGMultiButton
501 This class can be used to have multiple buttons in a property editor.
502 You will need to create a new property editor class, override
503 CreateControls, and have it return wxPGMultiButton instance in
504 wxPGWindowList::SetSecondary().
506 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
509 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
511 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
512 const wxWindow
* GetButton( unsigned int i
) const
513 { return (const wxWindow
*) m_buttons
[i
]; }
515 /** Utility function to be used in event handlers.
517 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
519 /** Returns number of buttons.
521 int GetCount() const { return m_buttons
.Count(); }
523 void Add( const wxString
& label
, int id
= -2 );
525 void Add( const wxBitmap
& bitmap
, int id
= -2 );
528 wxSize
GetPrimarySize() const
530 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
533 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
538 int GenId( int id
) const;
540 wxArrayPtrVoid m_buttons
;
541 wxSize m_fullEditorSize
;
546 // -----------------------------------------------------------------------
548 #endif // wxUSE_PROPGRID
550 #endif // _WX_PROPGRID_EDITORS_H_