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
;
33 wxPGWindowList( wxWindow
* a
)
38 wxPGWindowList( wxWindow
* a
, wxWindow
* b
)
45 // -----------------------------------------------------------------------
49 Base class for custom wxPropertyGrid editors.
52 - Names of builtin property editors are: TextCtrl, Choice,
53 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
54 editors include SpinCtrl and DatePickerCtrl, but using them requires
55 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
57 - Pointer to builtin editor is available as wxPGEditor_EditorName
58 (eg. wxPGEditor_TextCtrl).
60 - To add new editor you need to register it first using static function
61 wxPropertyGrid::RegisterEditorClass(), with code like this:
63 wxPGEditor *editorPointer = wxPropertyGrid::RegisterEditorClass(
64 new MyEditorClass(), "MyEditor");
66 After that, wxPropertyGrid will take ownership of the given object, but
67 you should still store editorPointer somewhere, so you can pass it to
68 wxPGProperty::SetEditor(), or return it from
69 wxPGEditor::DoGetEditorClass().
74 class WXDLLIMPEXP_PROPGRID wxPGEditor
: public wxObject
76 DECLARE_ABSTRACT_CLASS(wxPGEditor
)
87 virtual ~wxPGEditor();
90 Returns pointer to the name of the editor. For example,
91 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
92 your custom editor by string name, then you do not need to implement
95 virtual wxString
GetName() const;
98 Instantiates editor controls.
101 wxPropertyGrid to which the property belongs (use as parent for
104 Property for which this method is called.
106 Position, inside wxPropertyGrid, to create control(s) to.
108 Initial size for control(s).
111 - Primary control shall use id wxPG_SUBID1, and secondary (button)
112 control shall use wxPG_SUBID2.
113 - Unlike in previous version of wxPropertyGrid, it is no longer
114 necessary to call wxEvtHandler::Connect() for interesting editor
115 events. Instead, all events from control are now automatically
116 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
118 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
119 wxPGProperty
* property
,
121 const wxSize
& size
) const = 0;
123 /** Loads value from property to the control. */
124 virtual void UpdateControl( wxPGProperty
* property
,
125 wxWindow
* ctrl
) const = 0;
128 Used to get the renderer to draw the value with when the control is
131 Default implementation returns g_wxPGDefaultRenderer.
133 //virtual wxPGCellRenderer* GetCellRenderer() const;
135 /** Draws value for given property.
137 virtual void DrawValue( wxDC
& dc
,
139 wxPGProperty
* property
,
140 const wxString
& text
) const;
142 /** Handles events. Returns true if value in control was modified
143 (see wxPGProperty::OnEvent for more information).
145 @remarks wxPropertyGrid will automatically unfocus the editor when
146 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
147 property value being modified. This happens regardless of
148 editor type (ie. behavior is same for any wxTextCtrl and
149 wxComboBox based editor).
151 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
152 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
154 /** Returns value from control, via parameter 'variant'.
155 Usually ends up calling property's StringToValue or IntToValue.
156 Returns true if value was different.
158 virtual bool GetValueFromControl( wxVariant
& variant
,
159 wxPGProperty
* property
,
160 wxWindow
* ctrl
) const;
163 Sets new appearance for the control. Default implementation
164 sets foreground colour, background colour, font, plus text
165 for wxTextCtrl and wxComboCtrl.
168 New appearance to be applied.
171 Previously applied appearance. Used to detect which
172 control attributes need to be changed (e.g. so we only
173 change background colour if really needed).
176 @true if the new appearance represents an unspecified
179 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
180 wxPGProperty
* property
,
182 const wxPGCell
& appearance
,
183 const wxPGCell
& oldAppearance
,
184 bool unspecified
) const;
187 Sets value in control to unspecified.
189 virtual void SetValueToUnspecified( wxPGProperty
* property
,
190 wxWindow
* ctrl
) const;
192 /** Sets control's value specifically from string. */
193 virtual void SetControlStringValue( wxPGProperty
* property
,
195 const wxString
& txt
) const;
197 /** Sets control's value specifically from int (applies to choice etc.). */
198 virtual void SetControlIntValue( wxPGProperty
* property
,
202 /** Inserts item to existing control. Index -1 means appending.
203 Default implementation does nothing. Returns index of item added.
205 virtual int InsertItem( wxWindow
* ctrl
,
206 const wxString
& label
,
209 /** Deletes item from existing control.
210 Default implementation does nothing.
212 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
214 /** Extra processing when control gains focus. For example, wxTextCtrl
215 based controls should select all text.
217 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
219 /** Returns true if control itself can contain the custom image. Default is
222 virtual bool CanContainCustomImage() const;
225 // This member is public so scripting language bindings
226 // wrapper code can access it freely.
231 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
232 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
233 wxString CLASSNAME::GetName() const \
235 return wxS(#EDITOR); \
237 wxPGEditor* wxPGEditor_##EDITOR = NULL;
241 // Following are the built-in editor classes.
244 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
246 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
248 wxPGTextCtrlEditor() {}
249 virtual ~wxPGTextCtrlEditor();
251 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
252 wxPGProperty
* property
,
254 const wxSize
& size
) const;
255 virtual void UpdateControl( wxPGProperty
* property
,
256 wxWindow
* ctrl
) const;
257 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
258 wxPGProperty
* property
,
259 wxWindow
* primaryCtrl
,
260 wxEvent
& event
) const;
261 virtual bool GetValueFromControl( wxVariant
& variant
,
262 wxPGProperty
* property
,
263 wxWindow
* ctrl
) const;
265 virtual wxString
GetName() const;
267 //virtual wxPGCellRenderer* GetCellRenderer() const;
268 virtual void SetControlStringValue( wxPGProperty
* property
,
270 const wxString
& txt
) const;
271 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
273 // Provided so that, for example, ComboBox editor can use the same code
274 // (multiple inheritance would get way too messy).
275 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
276 wxPGProperty
* property
,
280 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
281 wxPGProperty
* property
,
287 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
289 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
291 wxPGChoiceEditor() {}
292 virtual ~wxPGChoiceEditor();
294 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
295 wxPGProperty
* property
,
297 const wxSize
& size
) const;
298 virtual void UpdateControl( wxPGProperty
* property
,
299 wxWindow
* ctrl
) const;
300 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
301 wxPGProperty
* property
,
302 wxWindow
* primaryCtrl
,
303 wxEvent
& event
) const;
304 virtual bool GetValueFromControl( wxVariant
& variant
,
305 wxPGProperty
* property
,
306 wxWindow
* ctrl
) const;
307 virtual void SetValueToUnspecified( wxPGProperty
* property
,
308 wxWindow
* ctrl
) const;
309 virtual wxString
GetName() const;
311 virtual void SetControlIntValue( wxPGProperty
* property
,
314 virtual void SetControlStringValue( wxPGProperty
* property
,
316 const wxString
& txt
) const;
318 virtual int InsertItem( wxWindow
* ctrl
,
319 const wxString
& label
,
321 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
322 virtual bool CanContainCustomImage() const;
324 // CreateControls calls this with CB_READONLY in extraStyle
325 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
326 wxPGProperty
* property
,
329 long extraStyle
) const;
334 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
336 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
338 wxPGComboBoxEditor() {}
339 virtual ~wxPGComboBoxEditor();
341 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
342 wxPGProperty
* property
,
344 const wxSize
& size
) const;
346 virtual wxString
GetName() const;
348 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
350 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
351 wxWindow
* ctrl
, wxEvent
& event
) const;
353 virtual bool GetValueFromControl( wxVariant
& variant
,
354 wxPGProperty
* property
,
355 wxWindow
* ctrl
) const;
357 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
362 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
365 wxPGChoiceAndButtonEditor() {}
366 virtual ~wxPGChoiceAndButtonEditor();
367 virtual wxString
GetName() const;
369 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
370 wxPGProperty
* property
,
372 const wxSize
& size
) const;
374 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
377 class WXDLLIMPEXP_PROPGRID
378 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
381 wxPGTextCtrlAndButtonEditor() {}
382 virtual ~wxPGTextCtrlAndButtonEditor();
383 virtual wxString
GetName() const;
385 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
386 wxPGProperty
* property
,
388 const wxSize
& size
) const;
390 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
394 #if wxPG_INCLUDE_CHECKBOX
397 // Use custom check box code instead of native control
398 // for cleaner (ie. more integrated) look.
400 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
402 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
404 wxPGCheckBoxEditor() {}
405 virtual ~wxPGCheckBoxEditor();
407 virtual wxString
GetName() const;
408 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
409 wxPGProperty
* property
,
411 const wxSize
& size
) const;
412 virtual void UpdateControl( wxPGProperty
* property
,
413 wxWindow
* ctrl
) const;
414 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
415 wxPGProperty
* property
,
416 wxWindow
* primaryCtrl
,
417 wxEvent
& event
) const;
418 virtual bool GetValueFromControl( wxVariant
& variant
,
419 wxPGProperty
* property
,
420 wxWindow
* ctrl
) const;
421 virtual void SetValueToUnspecified( wxPGProperty
* property
,
422 wxWindow
* ctrl
) const;
424 virtual void DrawValue( wxDC
& dc
,
426 wxPGProperty
* property
,
427 const wxString
& text
) const;
428 //virtual wxPGCellRenderer* GetCellRenderer() const;
430 virtual void SetControlIntValue( wxPGProperty
* property
,
438 // -----------------------------------------------------------------------
439 // Editor class registeration macro (mostly for internal use)
441 #define wxPGRegisterEditorClass(EDITOR) \
442 if ( wxPGEditor_##EDITOR == NULL ) \
444 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
445 new wxPG##EDITOR##Editor ); \
448 // -----------------------------------------------------------------------
450 /** @class wxPGEditorDialogAdapter
452 Derive a class from this to adapt an existing editor dialog or function to
453 be used when editor button of a property is pushed.
455 You only need to derive class and implement DoShowDialog() to create and
456 show the dialog, and finally submit the value returned by the dialog
462 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
464 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
466 wxPGEditorDialogAdapter()
472 virtual ~wxPGEditorDialogAdapter() { }
474 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
476 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
477 wxPGProperty
* property
) = 0;
479 void SetValue( wxVariant value
)
485 This method is typically only used if deriving class from existing
486 adapter with value conversion purposes.
488 wxVariant
& GetValue() { return m_value
; }
491 // This member is public so scripting language bindings
492 // wrapper code can access it freely.
499 // -----------------------------------------------------------------------
502 /** @class wxPGMultiButton
504 This class can be used to have multiple buttons in a property editor.
505 You will need to create a new property editor class, override
506 CreateControls, and have it return wxPGMultiButton instance in
507 wxPGWindowList::SetSecondary().
509 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
512 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
513 virtual ~wxPGMultiButton() {}
515 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
516 const wxWindow
* GetButton( unsigned int i
) const
517 { return (const wxWindow
*) m_buttons
[i
]; }
519 /** Utility function to be used in event handlers.
521 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
523 /** Returns number of buttons.
525 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
527 void Add( const wxString
& label
, int id
= -2 );
529 void Add( const wxBitmap
& bitmap
, int id
= -2 );
532 wxSize
GetPrimarySize() const
534 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
537 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
541 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
543 int GenId( int id
) const;
545 wxArrayPtrVoid m_buttons
;
546 wxSize m_fullEditorSize
;
550 // -----------------------------------------------------------------------
552 #endif // wxUSE_PROPGRID
554 #endif // _WX_PROPGRID_EDITORS_H_