]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/propgrid/editors.h
added wxXmlResource::FindXRCIDById() (#10026)
[wxWidgets.git] / interface / wx / propgrid / editors.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: editors.h
3// Purpose: interface of wxPropertyGrid editors
4// Author: wxWidgets team
de003797 5// RCS-ID: $Id$
1c4293cb
VZ
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9// -----------------------------------------------------------------------
10
7a344f1b
JS
11/**
12 @class wxPGEditor
1c4293cb
VZ
13
14 Base class for custom wxPropertyGrid editors.
15
16 @remarks
7a344f1b
JS
17 - Names of built-in property editors are: TextCtrl, Choice,
18 ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
19 editors include SpinCtrl and DatePickerCtrl, but using them requires
20 calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
1c4293cb 21
7a344f1b 22 - Pointer to built-in editor is available as wxPGEditor_EditorName
1c4293cb
VZ
23 (eg. wxPGEditor_TextCtrl).
24
7a344f1b
JS
25 - Before you start using new editor you just created, you need to register
26 it using static function
1c4293cb
VZ
27 wxPropertyGrid::RegisterEditorClass(), with code like this:
28 @code
29 wxPGEditor* editorPointer = wxPropertyGrid::RegisterEditorClass(new MyEditorClass(), "MyEditor");
30 @endcode
31 After that, wxPropertyGrid will take ownership of the given object, but
32 you should still store editorPointer somewhere, so you can pass it to
33 wxPGProperty::SetEditor(), or return it from wxPGEditor::DoGetEditorClass().
34
35 @library{wxpropgrid}
36 @category{propgrid}
37*/
38class wxPGEditor : public wxObject
39{
40public:
41
42 /** Constructor. */
43 wxPGEditor()
44 : wxObject()
45 {
46 m_clientData = NULL;
47 }
48
49 /** Destructor. */
50 virtual ~wxPGEditor();
51
7a344f1b
JS
52 /**
53 Returns pointer to the name of the editor. For example,
5a45dd6f
JS
54 wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
55 your custom editor by string name, then you do not need to implement
56 this function.
1c4293cb 57 */
5a45dd6f 58 virtual wxString GetName() const;
1c4293cb 59
7a344f1b
JS
60 /**
61 Instantiates editor controls.
62
1c4293cb 63 @param propgrid
7a344f1b
JS
64 wxPropertyGrid to which the property belongs (use as parent for control).
65
1c4293cb 66 @param property
7a344f1b
JS
67 Property for which this method is called.
68
1c4293cb 69 @param pos
7a344f1b
JS
70 Position, inside wxPropertyGrid, to create control(s) to.
71
1c4293cb 72 @param size
7a344f1b 73 Initial size for control(s).
1c4293cb
VZ
74
75 @remarks
76 - Primary control shall use id wxPG_SUBID1, and secondary (button) control
77 shall use wxPG_SUBID2.
d9fb481c 78 - Implementation shoud connect all necessary events to the
1c4293cb
VZ
79 wxPropertyGrid::OnCustomEditorEvent. For Example:
80 @code
81 // Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor
82 // control to the OnEvent.
7eaed395
JS
83 control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
84 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent),
85 NULL, propgrid);
1c4293cb 86 @endcode
d9fb481c
JS
87 OnCustomEditorEvent will then forward events, first to
88 wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
1c4293cb 89 */
7a344f1b
JS
90 virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid,
91 wxPGProperty* property,
92 const wxPoint& pos,
93 const wxSize& size ) const = 0;
1c4293cb
VZ
94
95 /** Loads value from property to the control. */
96 virtual void UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const = 0;
97
7a344f1b
JS
98 /**
99 Draws value for given property.
1c4293cb 100 */
7a344f1b
JS
101 virtual void DrawValue( wxDC& dc, const wxRect& rect,
102 wxPGProperty* property, const wxString& text ) const;
1c4293cb 103
7a344f1b
JS
104 /**
105 Handles events. Returns @true if value in control was modified
106 (see wxPGProperty::OnEvent() for more information).
0d4884cb
JS
107
108 @remarks wxPropertyGrid will automatically unfocus the editor when
109 wxEVT_COMMAND_TEXT_ENTER is received and when it results in
110 property value being modified. This happens regardless of
111 editor type (ie. behavior is same for any wxTextCtrl and
112 wxComboBox based editor).
1c4293cb
VZ
113 */
114 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
115 wxWindow* wnd_primary, wxEvent& event ) const = 0;
116
7a344f1b
JS
117 /**
118 Returns value from control, via parameter 'variant'.
119 Usually ends up calling property's StringToValue() or IntToValue().
120 Returns @true if value was different.
1c4293cb 121 */
7a344f1b
JS
122 virtual bool GetValueFromControl( wxVariant& variant, wxPGProperty* property,
123 wxWindow* ctrl ) const;
1c4293cb
VZ
124
125 /** Sets value in control to unspecified. */
7a344f1b
JS
126 virtual void SetValueToUnspecified( wxPGProperty* property,
127 wxWindow* ctrl ) const = 0;
1c4293cb
VZ
128
129 /** Sets control's value specifically from string. */
7a344f1b
JS
130 virtual void SetControlStringValue( wxPGProperty* property,
131 wxWindow* ctrl, const wxString& txt ) const;
1c4293cb
VZ
132
133 /** Sets control's value specifically from int (applies to choice etc.). */
7a344f1b
JS
134 virtual void SetControlIntValue( wxPGProperty* property,
135 wxWindow* ctrl, int value ) const;
1c4293cb 136
7a344f1b
JS
137 /**
138 Inserts item to existing control. Index -1 means end of list.
1c4293cb
VZ
139 Default implementation does nothing. Returns index of item added.
140 */
7a344f1b
JS
141 virtual int InsertItem( wxWindow* ctrl, const wxString& label,
142 int index ) const;
1c4293cb 143
7a344f1b
JS
144 /**
145 Deletes item from existing control.
1c4293cb
VZ
146 Default implementation does nothing.
147 */
148 virtual void DeleteItem( wxWindow* ctrl, int index ) const;
149
7a344f1b
JS
150 /**
151 Extra processing when control gains focus. For example, wxTextCtrl
1c4293cb
VZ
152 based controls should select all text.
153 */
154 virtual void OnFocus( wxPGProperty* property, wxWindow* wnd ) const;
155
7a344f1b
JS
156 /**
157 Returns @true if control itself can contain the custom image. Default
158 implementation returns @false.
1c4293cb
VZ
159 */
160 virtual bool CanContainCustomImage() const;
1c4293cb
VZ
161};
162
163// -----------------------------------------------------------------------
164
7a344f1b
JS
165/**
166 @class wxPGMultiButton
1c4293cb
VZ
167
168 This class can be used to have multiple buttons in a property editor.
169 You will need to create a new property editor class, override CreateControls,
170 and have it return wxPGMultiButton instance in wxPGWindowList::SetSecondary().
7a344f1b
JS
171
172 For instance, here we add three buttons to a TextCtrl editor:
1c4293cb
VZ
173
174 @code
175
176 #include <wx/propgrid/editors.h>
177
7a344f1b 178 class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor
1c4293cb 179 {
7a344f1b 180 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor)
1c4293cb 181 public:
7a344f1b
JS
182 wxSampleMultiButtonEditor() {}
183 virtual ~wxSampleMultiButtonEditor() {}
184
185 virtual wxString GetName() const { return "SampleMultiButtonEditor"; }
1c4293cb 186
7a344f1b
JS
187 virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid,
188 wxPGProperty* property,
189 const wxPoint& pos,
190 const wxSize& sz ) const;
1c4293cb
VZ
191 virtual bool OnEvent( wxPropertyGrid* propGrid,
192 wxPGProperty* property,
193 wxWindow* ctrl,
194 wxEvent& event ) const;
1c4293cb
VZ
195 };
196
7a344f1b 197 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor)
1c4293cb 198
7a344f1b
JS
199 wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid,
200 wxPGProperty* property,
201 const wxPoint& pos,
202 const wxSize& sz ) const
1c4293cb
VZ
203 {
204 // Create and populate buttons-subwindow
205 wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz );
206
207 // Add two regular buttons
208 buttons->Add( "..." );
209 buttons->Add( "A" );
210 // Add a bitmap button
211 buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) );
212
213 // Create the 'primary' editor control (textctrl in this case)
214 wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls
7a344f1b
JS
215 ( propGrid, property, pos,
216 buttons->GetPrimarySize() );
1c4293cb
VZ
217
218 // Finally, move buttons-subwindow to correct position and make sure
219 // returned wxPGWindowList contains our custom button list.
7a344f1b 220 buttons->Finalize(propGrid, pos);
1c4293cb
VZ
221
222 wndList.SetSecondary( buttons );
223 return wndList;
224 }
225
7a344f1b
JS
226 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid,
227 wxPGProperty* property,
228 wxWindow* ctrl,
229 wxEvent& event ) const
1c4293cb
VZ
230 {
231 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
232 {
233 wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
234
235 if ( event.GetId() == buttons->GetButtonId(0) )
236 {
237 // Do something when first button is pressed
238 return true;
239 }
240 if ( event.GetId() == buttons->GetButtonId(1) )
241 {
7a344f1b 242 // Do something when second button is pressed
1c4293cb
VZ
243 return true;
244 }
245 if ( event.GetId() == buttons->GetButtonId(2) )
246 {
7a344f1b 247 // Do something when third button is pressed
1c4293cb
VZ
248 return true;
249 }
250 }
251 return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
252 }
253
254 @endcode
255
256 Further to use this editor, code like this can be used:
257
258 @code
259
260 // Register editor class - needs only to be called once
7a344f1b
JS
261 wxPGEditor* multiButtonEditor = new wxSampleMultiButtonEditor();
262 wxPropertyGrid::RegisterEditorClass( multiButtonEditor );
1c4293cb
VZ
263
264 // Insert the property that will have multiple buttons
265 propGrid->Append( new wxLongStringProperty("MultipleButtons", wxPG_LABEL) );
266
267 // Change property to use editor created in the previous code segment
7a344f1b 268 propGrid->SetPropertyEditor( "MultipleButtons", multiButtonEditor );
1c4293cb
VZ
269
270 @endcode
271
272 @library{wxpropgrid}
273 @category{propgrid}
274*/
275class WXDLLIMPEXP_PROPGRID wxPGMultiButton : public wxWindow
276{
277public:
278
7a344f1b
JS
279 /**
280 Constructor.
281 */
1c4293cb
VZ
282 wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz );
283
7a344f1b
JS
284 /**
285 Destructor.
286 */
1c4293cb
VZ
287 virtual ~wxPGMultiButton() { }
288
7a344f1b
JS
289 /**
290 Adds new button, with given label.
291 */
292 void Add( const wxString& label, int id = -2 );
1c4293cb 293
7a344f1b
JS
294 /**
295 Adds new bitmap button.
1c4293cb 296 */
7a344f1b
JS
297 void Add( const wxBitmap& bitmap, int id = -2 );
298
299 /**
300 Call this in CreateControls() of your custom editor class
301 after all buttons have been added.
1c4293cb 302
7a344f1b
JS
303 @param propGrid
304 wxPropertyGrid given in CreateControls().
305
306 @param pos
307 wxPoint given in CreateControls().
1c4293cb 308 */
7a344f1b 309 void Finalize( wxPropertyGrid* propGrid, const wxPoint& pos );
1c4293cb 310
7a344f1b
JS
311 /**
312 Returns pointer to one of the buttons.
313 */
314 wxWindow* GetButton( unsigned int i );
1c4293cb 315
7a344f1b
JS
316 /**
317 Returns Id of one of the buttons. This is utility function to be
318 used in event handlers.
319 */
320 int GetButtonId( unsigned int i ) const;
1c4293cb 321
7a344f1b
JS
322 /**
323 Returns number of buttons.
324 */
68bcfd2c 325 unsigned int GetCount();
7a344f1b
JS
326
327 /**
328 Returns size of primary editor control, as appropriately
329 reduced by number of buttons present.
330 */
331 wxSize GetPrimarySize() const;
1c4293cb
VZ
332};
333
334// -----------------------------------------------------------------------