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;
167 Sets new appearance for the control. Default implementation
168 sets foreground colour, background colour, font, plus text
169 for wxTextCtrl and wxComboCtrl.
172 New appearance to be applied.
175 Previously applied appearance. Used to detect which
176 control attributes need to be changed (e.g. so we only
177 change background colour if really needed).
180 @true if the new appearance represents an unspecified
183 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
184 wxPGProperty
* property
,
186 const wxPGCell
& appearance
,
187 const wxPGCell
& oldAppearance
,
188 bool unspecified
) const;
191 Sets value in control to unspecified.
193 virtual void SetValueToUnspecified( wxPGProperty
* property
,
194 wxWindow
* ctrl
) const;
196 /** Sets control's value specifically from string. */
197 virtual void SetControlStringValue( wxPGProperty
* property
,
199 const wxString
& txt
) const;
201 /** Sets control's value specifically from int (applies to choice etc.). */
202 virtual void SetControlIntValue( wxPGProperty
* property
,
206 /** Inserts item to existing control. Index -1 means appending.
207 Default implementation does nothing. Returns index of item added.
209 virtual int InsertItem( wxWindow
* ctrl
,
210 const wxString
& label
,
213 /** Deletes item from existing control.
214 Default implementation does nothing.
216 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
218 /** Extra processing when control gains focus. For example, wxTextCtrl
219 based controls should select all text.
221 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
223 /** Returns true if control itself can contain the custom image. Default is
226 virtual bool CanContainCustomImage() const;
229 // This member is public so scripting language bindings
230 // wrapper code can access it freely.
235 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
236 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
237 wxString CLASSNAME::GetName() const \
239 return wxS(#EDITOR); \
241 wxPGEditor* wxPGEditor_##EDITOR = NULL;
245 // Following are the built-in editor classes.
248 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
250 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
252 wxPGTextCtrlEditor() {}
253 virtual ~wxPGTextCtrlEditor();
255 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
256 wxPGProperty
* property
,
258 const wxSize
& size
) const;
259 virtual void UpdateControl( wxPGProperty
* property
,
260 wxWindow
* ctrl
) const;
261 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
262 wxPGProperty
* property
,
263 wxWindow
* primaryCtrl
,
264 wxEvent
& event
) const;
265 virtual bool GetValueFromControl( wxVariant
& variant
,
266 wxPGProperty
* property
,
267 wxWindow
* ctrl
) const;
269 virtual wxString
GetName() const;
271 //virtual wxPGCellRenderer* GetCellRenderer() const;
272 virtual void SetControlStringValue( wxPGProperty
* property
,
274 const wxString
& txt
) const;
275 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
277 // Provided so that, for example, ComboBox editor can use the same code
278 // (multiple inheritance would get way too messy).
279 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
280 wxPGProperty
* property
,
284 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
285 wxPGProperty
* property
,
291 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
293 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
295 wxPGChoiceEditor() {}
296 virtual ~wxPGChoiceEditor();
298 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
299 wxPGProperty
* property
,
301 const wxSize
& size
) const;
302 virtual void UpdateControl( wxPGProperty
* property
,
303 wxWindow
* ctrl
) const;
304 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
305 wxPGProperty
* property
,
306 wxWindow
* primaryCtrl
,
307 wxEvent
& event
) const;
308 virtual bool GetValueFromControl( wxVariant
& variant
,
309 wxPGProperty
* property
,
310 wxWindow
* ctrl
) const;
311 virtual void SetValueToUnspecified( wxPGProperty
* property
,
312 wxWindow
* ctrl
) const;
313 virtual wxString
GetName() const;
315 virtual void SetControlIntValue( wxPGProperty
* property
,
318 virtual void SetControlStringValue( wxPGProperty
* property
,
320 const wxString
& txt
) const;
322 virtual int InsertItem( wxWindow
* ctrl
,
323 const wxString
& label
,
325 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
326 virtual bool CanContainCustomImage() const;
328 // CreateControls calls this with CB_READONLY in extraStyle
329 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
330 wxPGProperty
* property
,
333 long extraStyle
) const;
338 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
340 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
342 wxPGComboBoxEditor() {}
343 virtual ~wxPGComboBoxEditor();
345 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
346 wxPGProperty
* property
,
348 const wxSize
& size
) const;
350 virtual wxString
GetName() const;
352 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
354 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
355 wxWindow
* ctrl
, wxEvent
& event
) const;
357 virtual bool GetValueFromControl( wxVariant
& variant
,
358 wxPGProperty
* property
,
359 wxWindow
* ctrl
) const;
361 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
366 // Exclude classes from being able to be derived from in wxPython bindings
369 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
372 wxPGChoiceAndButtonEditor() {}
373 virtual ~wxPGChoiceAndButtonEditor();
374 virtual wxString
GetName() const;
376 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
377 wxPGProperty
* property
,
379 const wxSize
& size
) const;
381 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
384 class WXDLLIMPEXP_PROPGRID
385 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
388 wxPGTextCtrlAndButtonEditor() {}
389 virtual ~wxPGTextCtrlAndButtonEditor();
390 virtual wxString
GetName() const;
392 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
393 wxPGProperty
* property
,
395 const wxSize
& size
) const;
397 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
403 #if wxPG_INCLUDE_CHECKBOX
406 // Use custom check box code instead of native control
407 // for cleaner (ie. more integrated) look.
409 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
411 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
413 wxPGCheckBoxEditor() {}
414 virtual ~wxPGCheckBoxEditor();
416 virtual wxString
GetName() const;
417 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
418 wxPGProperty
* property
,
420 const wxSize
& size
) const;
421 virtual void UpdateControl( wxPGProperty
* property
,
422 wxWindow
* ctrl
) const;
423 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
424 wxPGProperty
* property
,
425 wxWindow
* primaryCtrl
,
426 wxEvent
& event
) const;
427 virtual bool GetValueFromControl( wxVariant
& variant
,
428 wxPGProperty
* property
,
429 wxWindow
* ctrl
) const;
430 virtual void SetValueToUnspecified( wxPGProperty
* property
,
431 wxWindow
* ctrl
) const;
433 virtual void DrawValue( wxDC
& dc
,
435 wxPGProperty
* property
,
436 const wxString
& text
) const;
437 //virtual wxPGCellRenderer* GetCellRenderer() const;
439 virtual void SetControlIntValue( wxPGProperty
* property
,
447 // -----------------------------------------------------------------------
448 // Editor class registeration macro (mostly for internal use)
450 #define wxPGRegisterEditorClass(EDITOR) \
451 if ( wxPGEditor_##EDITOR == NULL ) \
453 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
454 new wxPG##EDITOR##Editor ); \
457 // -----------------------------------------------------------------------
459 /** @class wxPGEditorDialogAdapter
461 Derive a class from this to adapt an existing editor dialog or function to
462 be used when editor button of a property is pushed.
464 You only need to derive class and implement DoShowDialog() to create and
465 show the dialog, and finally submit the value returned by the dialog
471 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
473 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
475 wxPGEditorDialogAdapter()
481 virtual ~wxPGEditorDialogAdapter() { }
483 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
485 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
486 wxPGProperty
* property
) = 0;
488 void SetValue( wxVariant value
)
494 This method is typically only used if deriving class from existing
495 adapter with value conversion purposes.
497 wxVariant
& GetValue() { return m_value
; }
500 // This member is public so scripting language bindings
501 // wrapper code can access it freely.
508 // -----------------------------------------------------------------------
511 /** @class wxPGMultiButton
513 This class can be used to have multiple buttons in a property editor.
514 You will need to create a new property editor class, override
515 CreateControls, and have it return wxPGMultiButton instance in
516 wxPGWindowList::SetSecondary().
518 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
521 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
522 virtual ~wxPGMultiButton() {}
524 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
525 const wxWindow
* GetButton( unsigned int i
) const
526 { return (const wxWindow
*) m_buttons
[i
]; }
528 /** Utility function to be used in event handlers.
530 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
532 /** Returns number of buttons.
534 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
536 void Add( const wxString
& label
, int id
= -2 );
538 void Add( const wxBitmap
& bitmap
, int id
= -2 );
541 wxSize
GetPrimarySize() const
543 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
546 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
550 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
552 int GenId( int id
) const;
554 wxArrayPtrVoid m_buttons
;
555 wxSize m_fullEditorSize
;
559 // -----------------------------------------------------------------------
561 #endif // wxUSE_PROPGRID
563 #endif // _WX_PROPGRID_EDITORS_H_