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