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;
134 /** Loads value from property to the control. */
135 virtual void UpdateControl( wxPGProperty
* property
,
136 wxWindow
* ctrl
) const = 0;
139 Used to get the renderer to draw the value with when the control is
142 Default implementation returns g_wxPGDefaultRenderer.
144 //virtual wxPGCellRenderer* GetCellRenderer() const;
146 /** Draws value for given property.
148 virtual void DrawValue( wxDC
& dc
,
150 wxPGProperty
* property
,
151 const wxString
& text
) const;
153 /** Handles events. Returns true if value in control was modified
154 (see wxPGProperty::OnEvent for more information).
156 @remarks wxPropertyGrid will automatically unfocus the editor when
157 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
158 property value being modified. This happens regardless of
159 editor type (ie. behavior is same for any wxTextCtrl and
160 wxComboBox based editor).
162 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
163 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
165 #if !defined(SWIG) || defined(CREATE_VCW)
166 /** Returns value from control, via parameter 'variant'.
167 Usually ends up calling property's StringToValue or IntToValue.
168 Returns true if value was different.
170 virtual bool GetValueFromControl( wxVariant
& variant
,
171 wxPGProperty
* property
,
172 wxWindow
* ctrl
) const;
175 /** Sets value in control to unspecified. */
176 virtual void SetValueToUnspecified( wxPGProperty
* property
,
177 wxWindow
* ctrl
) const = 0;
179 /** Sets control's value specifically from string. */
180 virtual void SetControlStringValue( wxPGProperty
* property
,
182 const wxString
& txt
) const;
184 /** Sets control's value specifically from int (applies to choice etc.). */
185 virtual void SetControlIntValue( wxPGProperty
* property
,
189 /** Inserts item to existing control. Index -1 means appending.
190 Default implementation does nothing. Returns index of item added.
192 virtual int InsertItem( wxWindow
* ctrl
,
193 const wxString
& label
,
196 /** Deletes item from existing control.
197 Default implementation does nothing.
199 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
201 /** Extra processing when control gains focus. For example, wxTextCtrl
202 based controls should select all text.
204 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
206 /** Returns true if control itself can contain the custom image. Default is
209 virtual bool CanContainCustomImage() const;
212 // This member is public so scripting language bindings
213 // wrapper code can access it freely.
218 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
219 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
220 wxString CLASSNAME::GetName() const \
222 return wxS(#EDITOR); \
224 wxPGEditor* wxPGEditor_##EDITOR = (wxPGEditor*) NULL;
228 // Following are the built-in editor classes.
231 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
234 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
237 wxPGTextCtrlEditor() {}
238 virtual ~wxPGTextCtrlEditor();
240 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
241 wxPGProperty
* property
,
243 const wxSize
& size
) const;
244 virtual void UpdateControl( wxPGProperty
* property
,
245 wxWindow
* ctrl
) const;
246 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
247 wxPGProperty
* property
,
248 wxWindow
* primaryCtrl
,
249 wxEvent
& event
) const;
250 virtual bool GetValueFromControl( wxVariant
& variant
,
251 wxPGProperty
* property
,
252 wxWindow
* ctrl
) const;
253 virtual void SetValueToUnspecified( wxPGProperty
* property
,
254 wxWindow
* ctrl
) const;
256 virtual wxString
GetName() const;
258 //virtual wxPGCellRenderer* GetCellRenderer() const;
259 virtual void SetControlStringValue( wxPGProperty
* property
,
261 const wxString
& txt
) const;
262 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
264 // Provided so that, for example, ComboBox editor can use the same code
265 // (multiple inheritance would get way too messy).
266 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
267 wxPGProperty
* property
,
271 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
272 wxPGProperty
* property
,
278 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
281 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
284 wxPGChoiceEditor() {}
285 virtual ~wxPGChoiceEditor();
287 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
288 wxPGProperty
* property
,
290 const wxSize
& size
) const;
291 virtual void UpdateControl( wxPGProperty
* property
,
292 wxWindow
* ctrl
) const;
293 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
294 wxPGProperty
* property
,
295 wxWindow
* primaryCtrl
,
296 wxEvent
& event
) const;
297 virtual bool GetValueFromControl( wxVariant
& variant
,
298 wxPGProperty
* property
,
299 wxWindow
* ctrl
) const;
300 virtual void SetValueToUnspecified( wxPGProperty
* property
,
301 wxWindow
* ctrl
) const;
302 virtual wxString
GetName() const;
304 virtual void SetControlIntValue( wxPGProperty
* property
,
307 virtual void SetControlStringValue( wxPGProperty
* property
,
309 const wxString
& txt
) const;
311 virtual int InsertItem( wxWindow
* ctrl
,
312 const wxString
& label
,
314 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
315 virtual bool CanContainCustomImage() const;
317 // CreateControls calls this with CB_READONLY in extraStyle
318 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
319 wxPGProperty
* property
,
322 long extraStyle
) const;
327 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
330 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
333 wxPGComboBoxEditor() {}
334 virtual ~wxPGComboBoxEditor();
336 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
337 wxPGProperty
* property
,
339 const wxSize
& size
) const;
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 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
368 wxPGProperty
* property
,
370 const wxSize
& size
) const;
372 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
375 class WXDLLIMPEXP_PROPGRID
376 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
379 wxPGTextCtrlAndButtonEditor() {}
380 virtual ~wxPGTextCtrlAndButtonEditor();
381 virtual wxString
GetName() const;
383 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
384 wxPGProperty
* property
,
386 const wxSize
& size
) const;
388 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
394 #if wxPG_INCLUDE_CHECKBOX || defined(DOXYGEN)
397 // Use custom check box code instead of native control
398 // for cleaner (ie. more integrated) look.
400 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
403 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
406 wxPGCheckBoxEditor() {}
407 virtual ~wxPGCheckBoxEditor();
409 virtual wxString
GetName() const;
410 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
411 wxPGProperty
* property
,
413 const wxSize
& size
) const;
414 virtual void UpdateControl( wxPGProperty
* property
,
415 wxWindow
* ctrl
) const;
416 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
417 wxPGProperty
* property
,
418 wxWindow
* primaryCtrl
,
419 wxEvent
& event
) const;
420 virtual bool GetValueFromControl( wxVariant
& variant
,
421 wxPGProperty
* property
,
422 wxWindow
* ctrl
) const;
423 virtual void SetValueToUnspecified( wxPGProperty
* property
,
424 wxWindow
* ctrl
) const;
426 virtual void DrawValue( wxDC
& dc
,
428 wxPGProperty
* property
,
429 const wxString
& text
) const;
430 //virtual wxPGCellRenderer* GetCellRenderer() const;
432 virtual void SetControlIntValue( wxPGProperty
* property
,
440 // -----------------------------------------------------------------------
441 // Editor class registeration macro (mostly for internal use)
443 #define wxPGRegisterEditorClass(EDITOR) \
444 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
446 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
447 new wxPG##EDITOR##Editor ); \
450 // -----------------------------------------------------------------------
452 /** @class wxPGEditorDialogAdapter
454 Derive a class from this to adapt an existing editor dialog or function to
455 be used when editor button of a property is pushed.
457 You only need to derive class and implement DoShowDialog() to create and
458 show the dialog, and finally submit the value returned by the dialog
464 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
467 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
470 wxPGEditorDialogAdapter()
476 virtual ~wxPGEditorDialogAdapter() { }
478 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
480 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
481 wxPGProperty
* property
) = 0;
483 void SetValue( wxVariant value
)
489 This method is typically only used if deriving class from existing
490 adapter with value conversion purposes.
492 wxVariant
& GetValue() { return m_value
; }
495 // This member is public so scripting language bindings
496 // wrapper code can access it freely.
503 // -----------------------------------------------------------------------
506 /** @class wxPGMultiButton
508 This class can be used to have multiple buttons in a property editor.
509 You will need to create a new property editor class, override
510 CreateControls, and have it return wxPGMultiButton instance in
511 wxPGWindowList::SetSecondary().
513 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
516 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
518 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
519 const wxWindow
* GetButton( unsigned int i
) const
520 { return (const wxWindow
*) m_buttons
[i
]; }
522 /** Utility function to be used in event handlers.
524 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
526 /** Returns number of buttons.
528 int GetCount() const { return m_buttons
.Count(); }
530 void Add( const wxString
& label
, int id
= -2 );
532 void Add( const wxBitmap
& bitmap
, int id
= -2 );
535 wxSize
GetPrimarySize() const
537 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
540 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
545 int GenId( int id
) const;
547 wxArrayPtrVoid m_buttons
;
548 wxSize m_fullEditorSize
;
553 // -----------------------------------------------------------------------
555 #endif // wxUSE_PROPGRID
557 #endif // _WX_PROPGRID_EDITORS_H_