1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPropertyGrid editors
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
13 Base class for custom wxPropertyGrid editors.
16 - Names of built-in property editors are: TextCtrl, Choice,
17 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
18 editors include SpinCtrl and DatePickerCtrl, but using them requires
19 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
21 - Pointer to built-in editor is available as wxPGEditor_EditorName
22 (eg. wxPGEditor_TextCtrl).
24 - Before you start using new editor you just created, you need to register
25 it using static function
26 wxPropertyGrid::RegisterEditorClass(), with code like this:
28 wxPGEditor* editorPointer = wxPropertyGrid::RegisterEditorClass(new MyEditorClass(), "MyEditor");
30 After that, wxPropertyGrid will take ownership of the given object, but
31 you should still store editorPointer somewhere, so you can pass it to
32 wxPGProperty::SetEditor(), or return it from wxPGEditor::DoGetEditorClass().
37 class wxPGEditor
: public wxObject
45 virtual ~wxPGEditor();
48 Returns pointer to the name of the editor. For example,
49 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
50 your custom editor by string name, then you do not need to implement
53 virtual wxString
GetName() const;
56 Instantiates editor controls.
59 wxPropertyGrid to which the property belongs (use as parent for control).
62 Property for which this method is called.
65 Position, inside wxPropertyGrid, to create control(s) to.
68 Initial size for control(s).
71 - Primary control shall use id wxPG_SUBID1, and secondary (button) control
72 shall use wxPG_SUBID2.
73 - Unlike in previous version of wxPropertyGrid, it is no longer
74 necessary to call wxEvtHandler::Connect() for interesting editor
75 events. Instead, all events from control are now automatically
76 forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
78 virtual wxPGWindowList
CreateControls( wxPropertyGrid
* propgrid
,
79 wxPGProperty
* property
,
81 const wxSize
& size
) const = 0;
83 /** Loads value from property to the control. */
84 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const = 0;
87 Draws value for given property.
89 virtual void DrawValue( wxDC
& dc
, const wxRect
& rect
,
90 wxPGProperty
* property
, const wxString
& text
) const;
93 Handles events. Returns @true if value in control was modified
94 (see wxPGProperty::OnEvent() for more information).
96 @remarks wxPropertyGrid will automatically unfocus the editor when
97 @c wxEVT_COMMAND_TEXT_ENTER is received and when it results in
98 property value being modified. This happens regardless of
99 editor type (ie. behaviour is same for any wxTextCtrl and
100 wxComboBox based editor).
102 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
103 wxWindow
* wnd_primary
, wxEvent
& event
) const = 0;
106 Returns value from control, via parameter 'variant'.
107 Usually ends up calling property's StringToValue() or IntToValue().
108 Returns @true if value was different.
110 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
,
111 wxWindow
* ctrl
) const;
113 /** Sets value in control to unspecified. */
114 virtual void SetValueToUnspecified( wxPGProperty
* property
,
115 wxWindow
* ctrl
) const = 0;
118 Called by property grid to set new appearance for the control.
119 Default implementation sets foreground colour, background colour,
120 font, plus text for wxTextCtrl and wxComboCtrl.
122 The parameter @a appearance represents the new appearance to be applied.
124 The parameter @a oldAppearance is the previously applied appearance.
125 Used to detect which control attributes need to be changed (e.g. so we only
126 change background colour if really needed).
128 Finally, the parameter @a unspecified if @true tells this function that
129 the new appearance represents an unspecified property value.
131 virtual void SetControlAppearance( wxPropertyGrid
* pg
,
132 wxPGProperty
* property
,
134 const wxPGCell
& appearance
,
135 const wxPGCell
& oldAppearance
,
136 bool unspecified
) const;
138 /** Sets control's value specifically from string. */
139 virtual void SetControlStringValue( wxPGProperty
* property
,
140 wxWindow
* ctrl
, const wxString
& txt
) const;
142 /** Sets control's value specifically from int (applies to choice etc.). */
143 virtual void SetControlIntValue( wxPGProperty
* property
,
144 wxWindow
* ctrl
, int value
) const;
147 Inserts item to existing control. Index -1 means end of list.
148 Default implementation does nothing. Returns index of item added.
150 virtual int InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const;
153 Deletes item from existing control.
154 Default implementation does nothing.
156 virtual void DeleteItem( wxWindow
* ctrl
, int index
) const;
159 Extra processing when control gains focus.
160 For example, wxTextCtrl based controls should select all text.
162 virtual void OnFocus( wxPGProperty
* property
, wxWindow
* wnd
) const;
165 Returns @true if control itself can contain the custom image.
166 Default implementation returns @false.
168 virtual bool CanContainCustomImage() const;
174 @class wxPGMultiButton
176 This class can be used to have multiple buttons in a property editor.
177 You will need to create a new property editor class, override CreateControls,
178 and have it return wxPGMultiButton instance in wxPGWindowList::SetSecondary().
180 For instance, here we add three buttons to a TextCtrl editor:
183 #include <wx/propgrid/editors.h>
185 class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor
187 wxDECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor);
190 wxSampleMultiButtonEditor() {}
191 virtual ~wxSampleMultiButtonEditor() {}
193 virtual wxString GetName() const { return "SampleMultiButtonEditor"; }
195 virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid,
196 wxPGProperty* property,
198 const wxSize& sz ) const;
199 virtual bool OnEvent( wxPropertyGrid* propGrid,
200 wxPGProperty* property,
202 wxEvent& event ) const;
205 wxIMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor);
207 wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid,
208 wxPGProperty* property,
210 const wxSize& sz ) const
212 // Create and populate buttons-subwindow
213 wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz );
215 // Add two regular buttons
216 buttons->Add( "..." );
218 // Add a bitmap button
219 buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) );
221 // Create the 'primary' editor control (textctrl in this case)
222 wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls
223 ( propGrid, property, pos,
224 buttons->GetPrimarySize() );
226 // Finally, move buttons-subwindow to correct position and make sure
227 // returned wxPGWindowList contains our custom button list.
228 buttons->Finalize(propGrid, pos);
230 wndList.SetSecondary( buttons );
234 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid,
235 wxPGProperty* property,
237 wxEvent& event ) const
239 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
241 wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
243 if ( event.GetId() == buttons->GetButtonId(0) )
245 // Do something when the first button is pressed
246 // Return true if the action modified the value in editor.
249 if ( event.GetId() == buttons->GetButtonId(1) )
251 // Do something when the second button is pressed
254 if ( event.GetId() == buttons->GetButtonId(2) )
256 // Do something when the third button is pressed
260 return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
264 Further to use this editor, code like this can be used:
267 // Register editor class - needs only to be called once
268 wxPGEditor* multiButtonEditor = new wxSampleMultiButtonEditor();
269 wxPropertyGrid::RegisterEditorClass( multiButtonEditor );
271 // Insert the property that will have multiple buttons
272 propGrid->Append( new wxLongStringProperty("MultipleButtons", wxPG_LABEL) );
274 // Change property to use editor created in the previous code segment
275 propGrid->SetPropertyEditor( "MultipleButtons", multiButtonEditor );
281 class WXDLLIMPEXP_PROPGRID wxPGMultiButton
: public wxWindow
287 wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
);
292 virtual ~wxPGMultiButton() { }
295 Adds new button, with given label.
297 void Add( const wxString
& label
, int id
= -2 );
300 Adds new bitmap button.
302 void Add( const wxBitmap
& bitmap
, int id
= -2 );
305 Call this in CreateControls() of your custom editor class
306 after all buttons have been added.
309 wxPropertyGrid given in CreateControls().
312 wxPoint given in CreateControls().
314 void Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
);
317 Returns pointer to one of the buttons.
319 wxWindow
* GetButton( unsigned int i
);
322 Returns Id of one of the buttons.
323 This is utility function to be used in event handlers.
325 int GetButtonId( unsigned int i
) const;
328 Returns number of buttons.
330 unsigned int GetCount();
333 Returns size of primary editor control, as appropriately
334 reduced by number of buttons present.
336 wxSize
GetPrimarySize() const;