1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/editors.h
3 // Purpose: wxPropertyGrid editors
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_EDITORS_H_
13 #define _WX_PROPGRID_EDITORS_H_
19 class WXDLLIMPEXP_FWD_PROPGRID wxPGCell
;
20 class WXDLLIMPEXP_FWD_PROPGRID wxPGProperty
;
21 class WXDLLIMPEXP_FWD_PROPGRID wxPropertyGrid
;
23 // -----------------------------------------------------------------------
24 // wxPGWindowList contains list of editor windows returned by CreateControls.
31 m_primary
= m_secondary
= NULL
;
34 void SetSecondary( wxWindow
* secondary
) { m_secondary
= secondary
; }
37 wxWindow
* m_secondary
;
39 wxPGWindowList( wxWindow
* a
)
44 wxPGWindowList( wxWindow
* a
, wxWindow
* b
)
51 // -----------------------------------------------------------------------
55 Base class for custom wxPropertyGrid editors.
58 - Names of builtin property editors are: TextCtrl, Choice,
59 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
60 editors include SpinCtrl and DatePickerCtrl, but using them requires
61 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
63 - Pointer to builtin editor is available as wxPGEditor_EditorName
64 (eg. wxPGEditor_TextCtrl).
66 - To add new editor you need to register it first using static function
67 wxPropertyGrid::RegisterEditorClass(), with code like this:
69 wxPGEditor *editorPointer = wxPropertyGrid::RegisterEditorClass(
70 new MyEditorClass(), "MyEditor");
72 After that, wxPropertyGrid will take ownership of the given object, but
73 you should still store editorPointer somewhere, so you can pass it to
74 wxPGProperty::SetEditor(), or return it from
75 wxPGEditor::DoGetEditorClass().
80 class WXDLLIMPEXP_PROPGRID wxPGEditor
: public wxObject
82 DECLARE_ABSTRACT_CLASS(wxPGEditor
)
93 virtual ~wxPGEditor();
96 Returns pointer to the name of the editor. For example,
97 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
98 your custom editor by string name, then you do not need to implement
101 virtual wxString
GetName() const;
104 Instantiates editor controls.
107 wxPropertyGrid to which the property belongs (use as parent for
110 Property for which this method is called.
112 Position, inside wxPropertyGrid, to create control(s) to.
114 Initial size for control(s).
117 - Primary control shall use id wxPG_SUBID1, and secondary (button)
118 control shall use wxPG_SUBID2.
119 - Unlike in previous version of wxPropertyGrid, it is no longer
120 necessary to call wxEvtHandler::Connect() for interesting editor
121 events. Instead, all events from control are now automatically
122 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
124 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
125 wxPGProperty
* property
,
127 const wxSize
& size
) const = 0;
129 /** Loads value from property to the control. */
130 virtual void UpdateControl( wxPGProperty
* property
,
131 wxWindow
* ctrl
) const = 0;
134 Used to get the renderer to draw the value with when the control is
137 Default implementation returns g_wxPGDefaultRenderer.
139 //virtual wxPGCellRenderer* GetCellRenderer() const;
141 /** Draws value for given property.
143 virtual void DrawValue( wxDC
& dc
,
145 wxPGProperty
* property
,
146 const wxString
& text
) const;
148 /** Handles events. Returns true if value in control was modified
149 (see wxPGProperty::OnEvent for more information).
151 @remarks wxPropertyGrid will automatically unfocus the editor when
152 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
153 property value being modified. This happens regardless of
154 editor type (ie. behaviour is same for any wxTextCtrl and
155 wxComboBox based editor).
157 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
158 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
160 /** Returns value from control, via parameter 'variant'.
161 Usually ends up calling property's StringToValue or IntToValue.
162 Returns true if value was different.
164 virtual bool GetValueFromControl( wxVariant
& variant
,
165 wxPGProperty
* property
,
166 wxWindow
* ctrl
) const;
169 Sets new appearance for the control. Default implementation
170 sets foreground colour, background colour, font, plus text
171 for wxTextCtrl and wxComboCtrl.
174 New appearance to be applied.
177 Previously applied appearance. Used to detect which
178 control attributes need to be changed (e.g. so we only
179 change background colour if really needed).
182 @true if the new appearance represents an unspecified
185 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
186 wxPGProperty
* property
,
188 const wxPGCell
& appearance
,
189 const wxPGCell
& oldAppearance
,
190 bool unspecified
) const;
193 Sets value in control to unspecified.
195 virtual void SetValueToUnspecified( wxPGProperty
* property
,
196 wxWindow
* ctrl
) const;
198 /** Sets control's value specifically from string. */
199 virtual void SetControlStringValue( wxPGProperty
* property
,
201 const wxString
& txt
) const;
203 /** Sets control's value specifically from int (applies to choice etc.). */
204 virtual void SetControlIntValue( wxPGProperty
* property
,
208 /** Inserts item to existing control. Index -1 means appending.
209 Default implementation does nothing. Returns index of item added.
211 virtual int InsertItem( wxWindow
* ctrl
,
212 const wxString
& label
,
215 /** Deletes item from existing control.
216 Default implementation does nothing.
218 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
220 /** Extra processing when control gains focus. For example, wxTextCtrl
221 based controls should select all text.
223 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
225 /** Returns true if control itself can contain the custom image. Default is
228 virtual bool CanContainCustomImage() const;
231 // This member is public so scripting language bindings
232 // wrapper code can access it freely.
237 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
238 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
239 wxString CLASSNAME::GetName() const \
241 return wxS(#EDITOR); \
243 wxPGEditor* wxPGEditor_##EDITOR = NULL;
247 // Following are the built-in editor classes.
250 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
252 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
254 wxPGTextCtrlEditor() {}
255 virtual ~wxPGTextCtrlEditor();
257 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
258 wxPGProperty
* property
,
260 const wxSize
& size
) const;
261 virtual void UpdateControl( wxPGProperty
* property
,
262 wxWindow
* ctrl
) const;
263 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
264 wxPGProperty
* property
,
265 wxWindow
* primaryCtrl
,
266 wxEvent
& event
) const;
267 virtual bool GetValueFromControl( wxVariant
& variant
,
268 wxPGProperty
* property
,
269 wxWindow
* ctrl
) const;
271 virtual wxString
GetName() const;
273 //virtual wxPGCellRenderer* GetCellRenderer() const;
274 virtual void SetControlStringValue( wxPGProperty
* property
,
276 const wxString
& txt
) const;
277 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
279 // Provided so that, for example, ComboBox editor can use the same code
280 // (multiple inheritance would get way too messy).
281 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
282 wxPGProperty
* property
,
286 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
287 wxPGProperty
* property
,
293 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
295 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
297 wxPGChoiceEditor() {}
298 virtual ~wxPGChoiceEditor();
300 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
301 wxPGProperty
* property
,
303 const wxSize
& size
) const;
304 virtual void UpdateControl( wxPGProperty
* property
,
305 wxWindow
* ctrl
) const;
306 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
307 wxPGProperty
* property
,
308 wxWindow
* primaryCtrl
,
309 wxEvent
& event
) const;
310 virtual bool GetValueFromControl( wxVariant
& variant
,
311 wxPGProperty
* property
,
312 wxWindow
* ctrl
) const;
313 virtual void SetValueToUnspecified( wxPGProperty
* property
,
314 wxWindow
* ctrl
) const;
315 virtual wxString
GetName() const;
317 virtual void SetControlIntValue( wxPGProperty
* property
,
320 virtual void SetControlStringValue( wxPGProperty
* property
,
322 const wxString
& txt
) const;
324 virtual int InsertItem( wxWindow
* ctrl
,
325 const wxString
& label
,
327 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
328 virtual bool CanContainCustomImage() const;
330 // CreateControls calls this with CB_READONLY in extraStyle
331 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
332 wxPGProperty
* property
,
335 long extraStyle
) const;
340 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
342 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
344 wxPGComboBoxEditor() {}
345 virtual ~wxPGComboBoxEditor();
347 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
348 wxPGProperty
* property
,
350 const wxSize
& size
) const;
352 virtual wxString
GetName() const;
354 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
356 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
357 wxWindow
* ctrl
, wxEvent
& event
) const;
359 virtual bool GetValueFromControl( wxVariant
& variant
,
360 wxPGProperty
* property
,
361 wxWindow
* ctrl
) const;
363 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
368 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
371 wxPGChoiceAndButtonEditor() {}
372 virtual ~wxPGChoiceAndButtonEditor();
373 virtual wxString
GetName() const;
375 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
376 wxPGProperty
* property
,
378 const wxSize
& size
) const;
380 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
383 class WXDLLIMPEXP_PROPGRID
384 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
387 wxPGTextCtrlAndButtonEditor() {}
388 virtual ~wxPGTextCtrlAndButtonEditor();
389 virtual wxString
GetName() const;
391 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
392 wxPGProperty
* property
,
394 const wxSize
& size
) const;
396 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
400 #if wxPG_INCLUDE_CHECKBOX
403 // Use custom check box code instead of native control
404 // for cleaner (ie. more integrated) look.
406 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
408 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
410 wxPGCheckBoxEditor() {}
411 virtual ~wxPGCheckBoxEditor();
413 virtual wxString
GetName() const;
414 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
415 wxPGProperty
* property
,
417 const wxSize
& size
) const;
418 virtual void UpdateControl( wxPGProperty
* property
,
419 wxWindow
* ctrl
) const;
420 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
421 wxPGProperty
* property
,
422 wxWindow
* primaryCtrl
,
423 wxEvent
& event
) const;
424 virtual bool GetValueFromControl( wxVariant
& variant
,
425 wxPGProperty
* property
,
426 wxWindow
* ctrl
) const;
427 virtual void SetValueToUnspecified( wxPGProperty
* property
,
428 wxWindow
* ctrl
) const;
430 virtual void DrawValue( wxDC
& dc
,
432 wxPGProperty
* property
,
433 const wxString
& text
) const;
434 //virtual wxPGCellRenderer* GetCellRenderer() const;
436 virtual void SetControlIntValue( wxPGProperty
* property
,
444 // -----------------------------------------------------------------------
445 // Editor class registeration macro (mostly for internal use)
447 #define wxPGRegisterEditorClass(EDITOR) \
448 if ( wxPGEditor_##EDITOR == NULL ) \
450 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
451 new wxPG##EDITOR##Editor ); \
454 // -----------------------------------------------------------------------
456 /** @class wxPGEditorDialogAdapter
458 Derive a class from this to adapt an existing editor dialog or function to
459 be used when editor button of a property is pushed.
461 You only need to derive class and implement DoShowDialog() to create and
462 show the dialog, and finally submit the value returned by the dialog
468 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
470 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
472 wxPGEditorDialogAdapter()
478 virtual ~wxPGEditorDialogAdapter() { }
480 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
482 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
483 wxPGProperty
* property
) = 0;
485 void SetValue( wxVariant value
)
491 This method is typically only used if deriving class from existing
492 adapter with value conversion purposes.
494 wxVariant
& GetValue() { return m_value
; }
497 // This member is public so scripting language bindings
498 // wrapper code can access it freely.
505 // -----------------------------------------------------------------------
508 /** @class wxPGMultiButton
510 This class can be used to have multiple buttons in a property editor.
511 You will need to create a new property editor class, override
512 CreateControls, and have it return wxPGMultiButton instance in
513 wxPGWindowList::SetSecondary().
515 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
518 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
519 virtual ~wxPGMultiButton() {}
521 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
522 const wxWindow
* GetButton( unsigned int i
) const
523 { return (const wxWindow
*) m_buttons
[i
]; }
525 /** Utility function to be used in event handlers.
527 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
529 /** Returns number of buttons.
531 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
533 void Add( const wxString
& label
, int id
= -2 );
535 void Add( const wxBitmap
& bitmap
, int id
= -2 );
538 wxSize
GetPrimarySize() const
540 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
543 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
547 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
549 int GenId( int id
) const;
551 wxArrayPtrVoid m_buttons
;
552 wxSize m_fullEditorSize
;
556 // -----------------------------------------------------------------------
558 #endif // wxUSE_PROPGRID
560 #endif // _WX_PROPGRID_EDITORS_H_