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