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
78 DECLARE_ABSTRACT_CLASS(wxPGEditor
)
89 virtual ~wxPGEditor();
92 Returns pointer to the name of the editor. For example,
93 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
94 your custom editor by string name, then you do not need to implement
97 virtual wxString
GetName() const;
100 Instantiates editor controls.
103 wxPropertyGrid to which the property belongs (use as parent for
106 Property for which this method is called.
108 Position, inside wxPropertyGrid, to create control(s) to.
110 Initial size for control(s).
113 - Primary control shall use id wxPG_SUBID1, and secondary (button)
114 control shall use wxPG_SUBID2.
115 - Unlike in previous version of wxPropertyGrid, it is no longer
116 necessary to call wxEvtHandler::Connect() for interesting editor
117 events. Instead, all events from control are now automatically
118 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
120 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
121 wxPGProperty
* property
,
123 const wxSize
& size
) const = 0;
125 /** Loads value from property to the control. */
126 virtual void UpdateControl( wxPGProperty
* property
,
127 wxWindow
* ctrl
) const = 0;
130 Used to get the renderer to draw the value with when the control is
133 Default implementation returns g_wxPGDefaultRenderer.
135 //virtual wxPGCellRenderer* GetCellRenderer() const;
137 /** Draws value for given property.
139 virtual void DrawValue( wxDC
& dc
,
141 wxPGProperty
* property
,
142 const wxString
& text
) const;
144 /** Handles events. Returns true if value in control was modified
145 (see wxPGProperty::OnEvent for more information).
147 @remarks wxPropertyGrid will automatically unfocus the editor when
148 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
149 property value being modified. This happens regardless of
150 editor type (ie. behavior is same for any wxTextCtrl and
151 wxComboBox based editor).
153 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
154 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
156 #if !defined(SWIG) || defined(CREATE_VCW)
157 /** Returns value from control, via parameter 'variant'.
158 Usually ends up calling property's StringToValue or IntToValue.
159 Returns true if value was different.
161 virtual bool GetValueFromControl( wxVariant
& variant
,
162 wxPGProperty
* property
,
163 wxWindow
* ctrl
) const;
166 /** Sets value in control to unspecified. */
167 virtual void SetValueToUnspecified( wxPGProperty
* property
,
168 wxWindow
* ctrl
) const = 0;
170 /** Sets control's value specifically from string. */
171 virtual void SetControlStringValue( wxPGProperty
* property
,
173 const wxString
& txt
) const;
175 /** Sets control's value specifically from int (applies to choice etc.). */
176 virtual void SetControlIntValue( wxPGProperty
* property
,
180 /** Inserts item to existing control. Index -1 means appending.
181 Default implementation does nothing. Returns index of item added.
183 virtual int InsertItem( wxWindow
* ctrl
,
184 const wxString
& label
,
187 /** Deletes item from existing control.
188 Default implementation does nothing.
190 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
192 /** Extra processing when control gains focus. For example, wxTextCtrl
193 based controls should select all text.
195 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
197 /** Returns true if control itself can contain the custom image. Default is
200 virtual bool CanContainCustomImage() const;
203 // This member is public so scripting language bindings
204 // wrapper code can access it freely.
209 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
210 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
211 wxString CLASSNAME::GetName() const \
213 return wxS(#EDITOR); \
215 wxPGEditor* wxPGEditor_##EDITOR = NULL;
219 // Following are the built-in editor classes.
222 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
224 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
226 wxPGTextCtrlEditor() {}
227 virtual ~wxPGTextCtrlEditor();
229 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
230 wxPGProperty
* property
,
232 const wxSize
& size
) const;
233 virtual void UpdateControl( wxPGProperty
* property
,
234 wxWindow
* ctrl
) const;
235 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
236 wxPGProperty
* property
,
237 wxWindow
* primaryCtrl
,
238 wxEvent
& event
) const;
239 virtual bool GetValueFromControl( wxVariant
& variant
,
240 wxPGProperty
* property
,
241 wxWindow
* ctrl
) const;
242 virtual void SetValueToUnspecified( wxPGProperty
* property
,
243 wxWindow
* ctrl
) const;
245 virtual wxString
GetName() const;
247 //virtual wxPGCellRenderer* GetCellRenderer() const;
248 virtual void SetControlStringValue( wxPGProperty
* property
,
250 const wxString
& txt
) const;
251 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
253 // Provided so that, for example, ComboBox editor can use the same code
254 // (multiple inheritance would get way too messy).
255 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
256 wxPGProperty
* property
,
260 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
261 wxPGProperty
* property
,
267 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
269 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
271 wxPGChoiceEditor() {}
272 virtual ~wxPGChoiceEditor();
274 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
275 wxPGProperty
* property
,
277 const wxSize
& size
) const;
278 virtual void UpdateControl( wxPGProperty
* property
,
279 wxWindow
* ctrl
) const;
280 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
281 wxPGProperty
* property
,
282 wxWindow
* primaryCtrl
,
283 wxEvent
& event
) const;
284 virtual bool GetValueFromControl( wxVariant
& variant
,
285 wxPGProperty
* property
,
286 wxWindow
* ctrl
) const;
287 virtual void SetValueToUnspecified( wxPGProperty
* property
,
288 wxWindow
* ctrl
) const;
289 virtual wxString
GetName() const;
291 virtual void SetControlIntValue( wxPGProperty
* property
,
294 virtual void SetControlStringValue( wxPGProperty
* property
,
296 const wxString
& txt
) const;
298 virtual int InsertItem( wxWindow
* ctrl
,
299 const wxString
& label
,
301 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
302 virtual bool CanContainCustomImage() const;
304 // CreateControls calls this with CB_READONLY in extraStyle
305 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
306 wxPGProperty
* property
,
309 long extraStyle
) const;
314 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
316 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
318 wxPGComboBoxEditor() {}
319 virtual ~wxPGComboBoxEditor();
321 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
322 wxPGProperty
* property
,
324 const wxSize
& size
) const;
326 virtual wxString
GetName() const;
328 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
330 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
331 wxWindow
* ctrl
, wxEvent
& event
) const;
333 virtual bool GetValueFromControl( wxVariant
& variant
,
334 wxPGProperty
* property
,
335 wxWindow
* ctrl
) const;
337 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
342 // Exclude classes from being able to be derived from in wxPython bindings
345 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
348 wxPGChoiceAndButtonEditor() {}
349 virtual ~wxPGChoiceAndButtonEditor();
350 virtual wxString
GetName() const;
352 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
353 wxPGProperty
* property
,
355 const wxSize
& size
) const;
357 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
360 class WXDLLIMPEXP_PROPGRID
361 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
364 wxPGTextCtrlAndButtonEditor() {}
365 virtual ~wxPGTextCtrlAndButtonEditor();
366 virtual wxString
GetName() const;
368 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
369 wxPGProperty
* property
,
371 const wxSize
& size
) const;
373 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
379 #if wxPG_INCLUDE_CHECKBOX
382 // Use custom check box code instead of native control
383 // for cleaner (ie. more integrated) look.
385 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
387 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
389 wxPGCheckBoxEditor() {}
390 virtual ~wxPGCheckBoxEditor();
392 virtual wxString
GetName() const;
393 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
394 wxPGProperty
* property
,
396 const wxSize
& size
) const;
397 virtual void UpdateControl( wxPGProperty
* property
,
398 wxWindow
* ctrl
) const;
399 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
400 wxPGProperty
* property
,
401 wxWindow
* primaryCtrl
,
402 wxEvent
& event
) const;
403 virtual bool GetValueFromControl( wxVariant
& variant
,
404 wxPGProperty
* property
,
405 wxWindow
* ctrl
) const;
406 virtual void SetValueToUnspecified( wxPGProperty
* property
,
407 wxWindow
* ctrl
) const;
409 virtual void DrawValue( wxDC
& dc
,
411 wxPGProperty
* property
,
412 const wxString
& text
) const;
413 //virtual wxPGCellRenderer* GetCellRenderer() const;
415 virtual void SetControlIntValue( wxPGProperty
* property
,
423 // -----------------------------------------------------------------------
424 // Editor class registeration macro (mostly for internal use)
426 #define wxPGRegisterEditorClass(EDITOR) \
427 if ( wxPGEditor_##EDITOR == NULL ) \
429 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
430 new wxPG##EDITOR##Editor ); \
433 // -----------------------------------------------------------------------
435 /** @class wxPGEditorDialogAdapter
437 Derive a class from this to adapt an existing editor dialog or function to
438 be used when editor button of a property is pushed.
440 You only need to derive class and implement DoShowDialog() to create and
441 show the dialog, and finally submit the value returned by the dialog
447 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
449 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
451 wxPGEditorDialogAdapter()
457 virtual ~wxPGEditorDialogAdapter() { }
459 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
461 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
462 wxPGProperty
* property
) = 0;
464 void SetValue( wxVariant value
)
470 This method is typically only used if deriving class from existing
471 adapter with value conversion purposes.
473 wxVariant
& GetValue() { return m_value
; }
476 // This member is public so scripting language bindings
477 // wrapper code can access it freely.
484 // -----------------------------------------------------------------------
487 /** @class wxPGMultiButton
489 This class can be used to have multiple buttons in a property editor.
490 You will need to create a new property editor class, override
491 CreateControls, and have it return wxPGMultiButton instance in
492 wxPGWindowList::SetSecondary().
494 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
497 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
498 virtual ~wxPGMultiButton() {}
500 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
501 const wxWindow
* GetButton( unsigned int i
) const
502 { return (const wxWindow
*) m_buttons
[i
]; }
504 /** Utility function to be used in event handlers.
506 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
508 /** Returns number of buttons.
510 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
512 void Add( const wxString
& label
, int id
= -2 );
514 void Add( const wxBitmap
& bitmap
, int id
= -2 );
517 wxSize
GetPrimarySize() const
519 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
522 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
526 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
528 int GenId( int id
) const;
530 wxArrayPtrVoid m_buttons
;
531 wxSize m_fullEditorSize
;
535 // -----------------------------------------------------------------------
537 #endif // wxUSE_PROPGRID
539 #endif // _WX_PROPGRID_EDITORS_H_