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 // -----------------------------------------------------------------------
20 // wxPGWindowList contains list of editor windows returned by CreateControls.
27 m_primary
= m_secondary
= NULL
;
30 void SetSecondary( wxWindow
* secondary
) { m_secondary
= secondary
; }
33 wxWindow
* m_secondary
;
35 wxPGWindowList( wxWindow
* a
)
40 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. behaviour 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 /** Returns value from control, via parameter 'variant'.
157 Usually ends up calling property's StringToValue or IntToValue.
158 Returns true if value was different.
160 virtual bool GetValueFromControl( wxVariant
& variant
,
161 wxPGProperty
* property
,
162 wxWindow
* ctrl
) const;
165 Sets new appearance for the control. Default implementation
166 sets foreground colour, background colour, font, plus text
167 for wxTextCtrl and wxComboCtrl.
170 New appearance to be applied.
173 Previously applied appearance. Used to detect which
174 control attributes need to be changed (e.g. so we only
175 change background colour if really needed).
178 @true if the new appearance represents an unspecified
181 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
182 wxPGProperty
* property
,
184 const wxPGCell
& appearance
,
185 const wxPGCell
& oldAppearance
,
186 bool unspecified
) const;
189 Sets value in control to unspecified.
191 virtual void SetValueToUnspecified( wxPGProperty
* property
,
192 wxWindow
* ctrl
) const;
194 /** Sets control's value specifically from string. */
195 virtual void SetControlStringValue( wxPGProperty
* property
,
197 const wxString
& txt
) const;
199 /** Sets control's value specifically from int (applies to choice etc.). */
200 virtual void SetControlIntValue( wxPGProperty
* property
,
204 /** Inserts item to existing control. Index -1 means appending.
205 Default implementation does nothing. Returns index of item added.
207 virtual int InsertItem( wxWindow
* ctrl
,
208 const wxString
& label
,
211 /** Deletes item from existing control.
212 Default implementation does nothing.
214 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
216 /** Extra processing when control gains focus. For example, wxTextCtrl
217 based controls should select all text.
219 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
221 /** Returns true if control itself can contain the custom image. Default is
224 virtual bool CanContainCustomImage() const;
227 // This member is public so scripting language bindings
228 // wrapper code can access it freely.
233 #define WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(EDITOR,CLASSNAME,BASECLASS) \
234 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, BASECLASS) \
235 wxString CLASSNAME::GetName() const \
237 return wxS(#EDITOR); \
239 wxPGEditor* wxPGEditor_##EDITOR = NULL;
243 // Following are the built-in editor classes.
246 class WXDLLIMPEXP_PROPGRID wxPGTextCtrlEditor
: public wxPGEditor
248 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlEditor
)
250 wxPGTextCtrlEditor() {}
251 virtual ~wxPGTextCtrlEditor();
253 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
254 wxPGProperty
* property
,
256 const wxSize
& size
) const;
257 virtual void UpdateControl( wxPGProperty
* property
,
258 wxWindow
* ctrl
) const;
259 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
260 wxPGProperty
* property
,
261 wxWindow
* primaryCtrl
,
262 wxEvent
& event
) const;
263 virtual bool GetValueFromControl( wxVariant
& variant
,
264 wxPGProperty
* property
,
265 wxWindow
* ctrl
) const;
267 virtual wxString
GetName() const;
269 //virtual wxPGCellRenderer* GetCellRenderer() const;
270 virtual void SetControlStringValue( wxPGProperty
* property
,
272 const wxString
& txt
) const;
273 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
275 // Provided so that, for example, ComboBox editor can use the same code
276 // (multiple inheritance would get way too messy).
277 static bool OnTextCtrlEvent( wxPropertyGrid
* propgrid
,
278 wxPGProperty
* property
,
282 static bool GetTextCtrlValueFromControl( wxVariant
& variant
,
283 wxPGProperty
* property
,
289 class WXDLLIMPEXP_PROPGRID wxPGChoiceEditor
: public wxPGEditor
291 DECLARE_DYNAMIC_CLASS(wxPGChoiceEditor
)
293 wxPGChoiceEditor() {}
294 virtual ~wxPGChoiceEditor();
296 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
297 wxPGProperty
* property
,
299 const wxSize
& size
) const;
300 virtual void UpdateControl( wxPGProperty
* property
,
301 wxWindow
* ctrl
) const;
302 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
303 wxPGProperty
* property
,
304 wxWindow
* primaryCtrl
,
305 wxEvent
& event
) const;
306 virtual bool GetValueFromControl( wxVariant
& variant
,
307 wxPGProperty
* property
,
308 wxWindow
* ctrl
) const;
309 virtual void SetValueToUnspecified( wxPGProperty
* property
,
310 wxWindow
* ctrl
) const;
311 virtual wxString
GetName() const;
313 virtual void SetControlIntValue( wxPGProperty
* property
,
316 virtual void SetControlStringValue( wxPGProperty
* property
,
318 const wxString
& txt
) const;
320 virtual int InsertItem( wxWindow
* ctrl
,
321 const wxString
& label
,
323 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
324 virtual bool CanContainCustomImage() const;
326 // CreateControls calls this with CB_READONLY in extraStyle
327 wxWindow
* CreateControlsBase( wxPropertyGrid
* propgrid
,
328 wxPGProperty
* property
,
331 long extraStyle
) const;
336 class WXDLLIMPEXP_PROPGRID wxPGComboBoxEditor
: public wxPGChoiceEditor
338 DECLARE_DYNAMIC_CLASS(wxPGComboBoxEditor
)
340 wxPGComboBoxEditor() {}
341 virtual ~wxPGComboBoxEditor();
343 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
344 wxPGProperty
* property
,
346 const wxSize
& size
) const;
348 virtual wxString
GetName() const;
350 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const;
352 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
353 wxWindow
* ctrl
, wxEvent
& event
) const;
355 virtual bool GetValueFromControl( wxVariant
& variant
,
356 wxPGProperty
* property
,
357 wxWindow
* ctrl
) const;
359 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
364 class WXDLLIMPEXP_PROPGRID wxPGChoiceAndButtonEditor
: public wxPGChoiceEditor
367 wxPGChoiceAndButtonEditor() {}
368 virtual ~wxPGChoiceAndButtonEditor();
369 virtual wxString
GetName() const;
371 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
372 wxPGProperty
* property
,
374 const wxSize
& size
) const;
376 DECLARE_DYNAMIC_CLASS(wxPGChoiceAndButtonEditor
)
379 class WXDLLIMPEXP_PROPGRID
380 wxPGTextCtrlAndButtonEditor
: public wxPGTextCtrlEditor
383 wxPGTextCtrlAndButtonEditor() {}
384 virtual ~wxPGTextCtrlAndButtonEditor();
385 virtual wxString
GetName() const;
387 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
388 wxPGProperty
* property
,
390 const wxSize
& size
) const;
392 DECLARE_DYNAMIC_CLASS(wxPGTextCtrlAndButtonEditor
)
396 #if wxPG_INCLUDE_CHECKBOX
399 // Use custom check box code instead of native control
400 // for cleaner (ie. more integrated) look.
402 class WXDLLIMPEXP_PROPGRID wxPGCheckBoxEditor
: public wxPGEditor
404 DECLARE_DYNAMIC_CLASS(wxPGCheckBoxEditor
)
406 wxPGCheckBoxEditor() {}
407 virtual ~wxPGCheckBoxEditor();
409 virtual wxString
GetName() const;
410 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
411 wxPGProperty
* property
,
413 const wxSize
& size
) const;
414 virtual void UpdateControl( wxPGProperty
* property
,
415 wxWindow
* ctrl
) const;
416 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
417 wxPGProperty
* property
,
418 wxWindow
* primaryCtrl
,
419 wxEvent
& event
) const;
420 virtual bool GetValueFromControl( wxVariant
& variant
,
421 wxPGProperty
* property
,
422 wxWindow
* ctrl
) const;
423 virtual void SetValueToUnspecified( wxPGProperty
* property
,
424 wxWindow
* ctrl
) const;
426 virtual void DrawValue( wxDC
& dc
,
428 wxPGProperty
* property
,
429 const wxString
& text
) const;
430 //virtual wxPGCellRenderer* GetCellRenderer() const;
432 virtual void SetControlIntValue( wxPGProperty
* property
,
440 // -----------------------------------------------------------------------
441 // Editor class registeration macro (mostly for internal use)
443 #define wxPGRegisterEditorClass(EDITOR) \
444 if ( wxPGEditor_##EDITOR == NULL ) \
446 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
447 new wxPG##EDITOR##Editor ); \
450 // -----------------------------------------------------------------------
452 /** @class wxPGEditorDialogAdapter
454 Derive a class from this to adapt an existing editor dialog or function to
455 be used when editor button of a property is pushed.
457 You only need to derive class and implement DoShowDialog() to create and
458 show the dialog, and finally submit the value returned by the dialog
464 class WXDLLIMPEXP_PROPGRID wxPGEditorDialogAdapter
: public wxObject
466 DECLARE_ABSTRACT_CLASS(wxPGEditorDialogAdapter
)
468 wxPGEditorDialogAdapter()
474 virtual ~wxPGEditorDialogAdapter() { }
476 bool ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
);
478 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
479 wxPGProperty
* property
) = 0;
481 void SetValue( wxVariant value
)
487 This method is typically only used if deriving class from existing
488 adapter with value conversion purposes.
490 wxVariant
& GetValue() { return m_value
; }
493 // This member is public so scripting language bindings
494 // wrapper code can access it freely.
501 // -----------------------------------------------------------------------
504 /** @class wxPGMultiButton
506 This class can be used to have multiple buttons in a property editor.
507 You will need to create a new property editor class, override
508 CreateControls, and have it return wxPGMultiButton instance in
509 wxPGWindowList::SetSecondary().
511 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
514 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
515 virtual ~wxPGMultiButton() {}
517 wxWindow
* GetButton( unsigned int i
) { return (wxWindow
*) m_buttons
[i
]; }
518 const wxWindow
* GetButton( unsigned int i
) const
519 { return (const wxWindow
*) m_buttons
[i
]; }
521 /** Utility function to be used in event handlers.
523 int GetButtonId( unsigned int i
) const { return GetButton(i
)->GetId(); }
525 /** Returns number of buttons.
527 unsigned int GetCount() const { return (unsigned int) m_buttons
.size(); }
529 void Add( const wxString
& label
, int id
= -2 );
531 void Add( const wxBitmap
& bitmap
, int id
= -2 );
534 wxSize
GetPrimarySize() const
536 return wxSize(m_fullEditorSize
.x
- m_buttonsWidth
, m_fullEditorSize
.y
);
539 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
543 void DoAddButton( wxWindow
* button
, const wxSize
& sz
);
545 int GenId( int id
) const;
547 wxArrayPtrVoid m_buttons
;
548 wxSize m_fullEditorSize
;
552 // -----------------------------------------------------------------------
554 #endif // wxUSE_PROPGRID
556 #endif // _WX_PROPGRID_EDITORS_H_