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 - Unlike in previous version of wxPropertyGrid, it is no longer
118 necessary to call wxEvtHandler::Connect() for interesting editor
119 events. Instead, all events from control are now automatically
120 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
122 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
123 wxPGProperty
* property
,
125 const wxSize
& size
) const = 0;
127 /** Loads value from property to the control. */
128 virtual void UpdateControl( wxPGProperty
* property
,
129 wxWindow
* ctrl
) const = 0;
132 Used to get the renderer to draw the value with when the control is
135 Default implementation returns g_wxPGDefaultRenderer.
137 //virtual wxPGCellRenderer* GetCellRenderer() const;
139 /** Draws value for given property.
141 virtual void DrawValue( wxDC
& dc
,
143 wxPGProperty
* property
,
144 const wxString
& text
) const;
146 /** Handles events. Returns true if value in control was modified
147 (see wxPGProperty::OnEvent for more information).
149 @remarks wxPropertyGrid will automatically unfocus the editor when
150 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
151 property value being modified. This happens regardless of
152 editor type (ie. behavior is same for any wxTextCtrl and
153 wxComboBox based editor).
155 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
156 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
158 #if !defined(SWIG) || defined(CREATE_VCW)
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 value in control to unspecified. */
169 virtual void SetValueToUnspecified( wxPGProperty
* property
,
170 wxWindow
* ctrl
) const = 0;
172 /** Sets control's value specifically from string. */
173 virtual void SetControlStringValue( wxPGProperty
* property
,
175 const wxString
& txt
) const;
177 /** Sets control's value specifically from int (applies to choice etc.). */
178 virtual void SetControlIntValue( wxPGProperty
* property
,
182 /** Inserts item to existing control. Index -1 means appending.
183 Default implementation does nothing. Returns index of item added.
185 virtual int InsertItem( wxWindow
* ctrl
,
186 const wxString
& label
,
189 /** Deletes item from existing control.
190 Default implementation does nothing.
192 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
194 /** Extra processing when control gains focus. For example, wxTextCtrl
195 based controls should select all text.
197 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
199 /** Returns true if control itself can contain the custom image. Default is
202 virtual bool CanContainCustomImage() const;
205 // This member is public so scripting language bindings
206 // wrapper code can access it freely.
211 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
212 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
213 wxString CLASSNAME::GetName() const \
215 return wxS(#EDITOR); \
217 wxPGEditor* wxPGEditor_##EDITOR = NULL;
221 // Following are the built-in editor classes.
224 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
227 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
230 wxPGTextCtrlEditor() {}
231 virtual ~wxPGTextCtrlEditor();
233 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
234 wxPGProperty
* property
,
236 const wxSize
& size
) const;
237 virtual void UpdateControl( wxPGProperty
* property
,
238 wxWindow
* ctrl
) const;
239 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
240 wxPGProperty
* property
,
241 wxWindow
* primaryCtrl
,
242 wxEvent
& event
) const;
243 virtual bool GetValueFromControl( wxVariant
& variant
,
244 wxPGProperty
* property
,
245 wxWindow
* ctrl
) const;
246 virtual void SetValueToUnspecified( wxPGProperty
* property
,
247 wxWindow
* ctrl
) const;
249 virtual wxString
GetName() const;
251 //virtual wxPGCellRenderer* GetCellRenderer() const;
252 virtual void SetControlStringValue( wxPGProperty
* property
,
254 const wxString
& txt
) const;
255 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
257 // Provided so that, for example, ComboBox editor can use the same code
258 // (multiple inheritance would get way too messy).
259 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
260 wxPGProperty
* property
,
264 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
265 wxPGProperty
* property
,
271 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
274 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
277 wxPGChoiceEditor() {}
278 virtual ~wxPGChoiceEditor();
280 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
281 wxPGProperty
* property
,
283 const wxSize
& size
) const;
284 virtual void UpdateControl( wxPGProperty
* property
,
285 wxWindow
* ctrl
) const;
286 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
287 wxPGProperty
* property
,
288 wxWindow
* primaryCtrl
,
289 wxEvent
& event
) const;
290 virtual bool GetValueFromControl( wxVariant
& variant
,
291 wxPGProperty
* property
,
292 wxWindow
* ctrl
) const;
293 virtual void SetValueToUnspecified( wxPGProperty
* property
,
294 wxWindow
* ctrl
) const;
295 virtual wxString
GetName() const;
297 virtual void SetControlIntValue( wxPGProperty
* property
,
300 virtual void SetControlStringValue( wxPGProperty
* property
,
302 const wxString
& txt
) const;
304 virtual int InsertItem( wxWindow
* ctrl
,
305 const wxString
& label
,
307 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
308 virtual bool CanContainCustomImage() const;
310 // CreateControls calls this with CB_READONLY in extraStyle
311 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
312 wxPGProperty
* property
,
315 long extraStyle
) const;
320 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
323 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
326 wxPGComboBoxEditor() {}
327 virtual ~wxPGComboBoxEditor();
329 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
330 wxPGProperty
* property
,
332 const wxSize
& size
) const;
334 virtual wxString
GetName() const;
336 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
338 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
339 wxWindow
* ctrl
, wxEvent
& event
) const;
341 virtual bool GetValueFromControl( wxVariant
& variant
,
342 wxPGProperty
* property
,
343 wxWindow
* ctrl
) const;
345 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
350 // Exclude classes from being able to be derived from in wxPython bindings
353 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
356 wxPGChoiceAndButtonEditor() {}
357 virtual ~wxPGChoiceAndButtonEditor();
358 virtual wxString
GetName() const;
360 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
361 wxPGProperty
* property
,
363 const wxSize
& size
) const;
365 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
368 class WXDLLIMPEXP_PROPGRID
369 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
372 wxPGTextCtrlAndButtonEditor() {}
373 virtual ~wxPGTextCtrlAndButtonEditor();
374 virtual wxString
GetName() const;
376 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
377 wxPGProperty
* property
,
379 const wxSize
& size
) const;
381 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
387 #if wxPG_INCLUDE_CHECKBOX
390 // Use custom check box code instead of native control
391 // for cleaner (ie. more integrated) look.
393 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
396 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
399 wxPGCheckBoxEditor() {}
400 virtual ~wxPGCheckBoxEditor();
402 virtual wxString
GetName() const;
403 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
404 wxPGProperty
* property
,
406 const wxSize
& size
) const;
407 virtual void UpdateControl( wxPGProperty
* property
,
408 wxWindow
* ctrl
) const;
409 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
410 wxPGProperty
* property
,
411 wxWindow
* primaryCtrl
,
412 wxEvent
& event
) const;
413 virtual bool GetValueFromControl( wxVariant
& variant
,
414 wxPGProperty
* property
,
415 wxWindow
* ctrl
) const;
416 virtual void SetValueToUnspecified( wxPGProperty
* property
,
417 wxWindow
* ctrl
) const;
419 virtual void DrawValue( wxDC
& dc
,
421 wxPGProperty
* property
,
422 const wxString
& text
) const;
423 //virtual wxPGCellRenderer* GetCellRenderer() const;
425 virtual void SetControlIntValue( wxPGProperty
* property
,
433 // -----------------------------------------------------------------------
434 // Editor class registeration macro (mostly for internal use)
436 #define wxPGRegisterEditorClass(EDITOR) \
437 if ( wxPGEditor_##EDITOR == NULL ) \
439 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
440 new wxPG##EDITOR##Editor ); \
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 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
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
);
537 int GenId( int id
) const;
539 wxArrayPtrVoid m_buttons
;
540 wxSize m_fullEditorSize
;
544 // -----------------------------------------------------------------------
546 #endif // wxUSE_PROPGRID
548 #endif // _WX_PROPGRID_EDITORS_H_