]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: samples/propgrid/propgrid.cpp | |
3 | // Purpose: wxPropertyGrid sample | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2004-09-25 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // | |
13 | // | |
14 | // NOTES | |
15 | // | |
16 | // * Examples of custom property classes are in sampleprops.cpp. | |
17 | // | |
18 | // * Additional ones can be found below. | |
19 | // | |
20 | // * Currently there is no example of a custom property editor. However, | |
21 | // SpinCtrl editor sample is well-commented. It can be found in | |
22 | // src/propgrid/advprops.cpp. | |
23 | // | |
24 | // * To find code that populates the grid with properties, search for | |
25 | // string "::Populate". | |
26 | // | |
27 | // * To find code that handles property grid changes, search for string | |
28 | // "::OnPropertyGridChange". | |
29 | // | |
30 | ||
31 | // For compilers that support precompilation, includes "wx/wx.h". | |
32 | #include "wx/wxprec.h" | |
33 | ||
34 | #ifdef __BORLANDC__ | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
38 | // for all others, include the necessary headers (this file is usually all you | |
39 | // need because it includes almost all "standard" wxWidgets headers) | |
40 | #ifndef WX_PRECOMP | |
41 | #include "wx/wx.h" | |
42 | #endif | |
43 | ||
44 | #if !wxUSE_PROPGRID | |
45 | #error "Please set wxUSE_PROPGRID to 1 and rebuild the library." | |
46 | #endif | |
47 | ||
48 | #include <wx/numdlg.h> | |
49 | ||
50 | // ----------------------------------------------------------------------- | |
51 | ||
52 | ||
53 | // Main propertygrid header. | |
54 | #include <wx/propgrid/propgrid.h> | |
55 | ||
56 | // Extra property classes. | |
57 | #include <wx/propgrid/advprops.h> | |
58 | ||
59 | // This defines wxPropertyGridManager. | |
60 | #include <wx/propgrid/manager.h> | |
61 | ||
62 | #include "propgrid.h" | |
63 | #include "sampleprops.h" | |
64 | ||
65 | #if wxUSE_DATEPICKCTRL | |
66 | #include <wx/datectrl.h> | |
67 | #endif | |
68 | ||
69 | #include <wx/artprov.h> | |
70 | ||
71 | #ifndef __WXMSW__ | |
72 | #include "../sample.xpm" | |
73 | #endif | |
74 | ||
75 | // ----------------------------------------------------------------------- | |
76 | // wxSampleMultiButtonEditor | |
77 | // A sample editor class that has multiple buttons. | |
78 | // ----------------------------------------------------------------------- | |
79 | ||
80 | class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor | |
81 | { | |
82 | DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor) | |
83 | public: | |
84 | wxSampleMultiButtonEditor() {} | |
85 | virtual ~wxSampleMultiButtonEditor() {} | |
86 | ||
87 | virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid, | |
88 | wxPGProperty* property, | |
89 | const wxPoint& pos, | |
90 | const wxSize& sz ) const; | |
91 | virtual bool OnEvent( wxPropertyGrid* propGrid, | |
92 | wxPGProperty* property, | |
93 | wxWindow* ctrl, | |
94 | wxEvent& event ) const; | |
95 | }; | |
96 | ||
97 | IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor) | |
98 | ||
99 | wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid, | |
100 | wxPGProperty* property, | |
101 | const wxPoint& pos, | |
102 | const wxSize& sz ) const | |
103 | { | |
104 | // Create and populate buttons-subwindow | |
105 | wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz ); | |
106 | ||
107 | // Add two regular buttons | |
108 | buttons->Add( "..." ); | |
109 | buttons->Add( "A" ); | |
110 | // Add a bitmap button | |
111 | buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) ); | |
112 | ||
113 | // Create the 'primary' editor control (textctrl in this case) | |
114 | wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls | |
115 | ( propGrid, property, pos, | |
116 | buttons->GetPrimarySize() ); | |
117 | ||
118 | // Finally, move buttons-subwindow to correct position and make sure | |
119 | // returned wxPGWindowList contains our custom button list. | |
120 | buttons->Finalize(propGrid, pos); | |
121 | ||
122 | wndList.SetSecondary( buttons ); | |
123 | return wndList; | |
124 | } | |
125 | ||
126 | bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid, | |
127 | wxPGProperty* property, | |
128 | wxWindow* ctrl, | |
129 | wxEvent& event ) const | |
130 | { | |
131 | if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) | |
132 | { | |
133 | wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary(); | |
134 | ||
135 | if ( event.GetId() == buttons->GetButtonId(0) ) | |
136 | { | |
137 | // Do something when the first button is pressed | |
138 | wxLogDebug("First button pressed"); | |
139 | return false; // Return false since value did not change | |
140 | } | |
141 | if ( event.GetId() == buttons->GetButtonId(1) ) | |
142 | { | |
143 | // Do something when the second button is pressed | |
144 | wxMessageBox("Second button pressed"); | |
145 | return false; // Return false since value did not change | |
146 | } | |
147 | if ( event.GetId() == buttons->GetButtonId(2) ) | |
148 | { | |
149 | // Do something when the third button is pressed | |
150 | wxMessageBox("Third button pressed"); | |
151 | return false; // Return false since value did not change | |
152 | } | |
153 | } | |
154 | return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event); | |
155 | } | |
156 | ||
157 | // ----------------------------------------------------------------------- | |
158 | // Validator for wxValidator use sample | |
159 | // ----------------------------------------------------------------------- | |
160 | ||
161 | #if wxUSE_VALIDATORS | |
162 | ||
163 | // wxValidator for testing | |
164 | ||
165 | class wxInvalidWordValidator : public wxValidator | |
166 | { | |
167 | public: | |
168 | ||
169 | wxInvalidWordValidator( const wxString& invalidWord ) | |
170 | : wxValidator(), m_invalidWord(invalidWord) | |
171 | { | |
172 | } | |
173 | ||
174 | virtual wxObject* Clone() const | |
175 | { | |
176 | return new wxInvalidWordValidator(m_invalidWord); | |
177 | } | |
178 | ||
179 | virtual bool Validate(wxWindow* WXUNUSED(parent)) | |
180 | { | |
181 | wxTextCtrl* tc = wxDynamicCast(GetWindow(), wxTextCtrl); | |
182 | wxCHECK_MSG(tc, true, wxT("validator window must be wxTextCtrl")); | |
183 | ||
184 | wxString val = tc->GetValue(); | |
185 | ||
186 | if ( val.find(m_invalidWord) == wxString::npos ) | |
187 | return true; | |
188 | ||
189 | ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord.c_str()), | |
190 | wxT("Validation Failure")); | |
191 | ||
192 | return false; | |
193 | } | |
194 | ||
195 | private: | |
196 | wxString m_invalidWord; | |
197 | }; | |
198 | ||
199 | #endif // wxUSE_VALIDATORS | |
200 | ||
201 | // ----------------------------------------------------------------------- | |
202 | // wxVectorProperty | |
203 | // ----------------------------------------------------------------------- | |
204 | ||
205 | // See propgridsample.h for wxVector3f class | |
206 | ||
207 | WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f) | |
208 | ||
209 | WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty,wxPGProperty, | |
210 | wxVector3f,const wxVector3f&,TextCtrl) | |
211 | ||
212 | ||
213 | wxVectorProperty::wxVectorProperty( const wxString& label, | |
214 | const wxString& name, | |
215 | const wxVector3f& value ) | |
216 | : wxPGProperty(label,name) | |
217 | { | |
218 | SetValue( WXVARIANT(value) ); | |
219 | AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) ); | |
220 | AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) ); | |
221 | AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) ); | |
222 | } | |
223 | ||
224 | wxVectorProperty::~wxVectorProperty() { } | |
225 | ||
226 | void wxVectorProperty::RefreshChildren() | |
227 | { | |
228 | if ( !GetChildCount() ) return; | |
229 | const wxVector3f& vector = wxVector3fRefFromVariant(m_value); | |
230 | Item(0)->SetValue( vector.x ); | |
231 | Item(1)->SetValue( vector.y ); | |
232 | Item(2)->SetValue( vector.z ); | |
233 | } | |
234 | ||
235 | wxVariant wxVectorProperty::ChildChanged( wxVariant& thisValue, | |
236 | int childIndex, | |
237 | wxVariant& childValue ) const | |
238 | { | |
239 | wxVector3f vector; | |
240 | vector << thisValue; | |
241 | switch ( childIndex ) | |
242 | { | |
243 | case 0: vector.x = childValue.GetDouble(); break; | |
244 | case 1: vector.y = childValue.GetDouble(); break; | |
245 | case 2: vector.z = childValue.GetDouble(); break; | |
246 | } | |
247 | wxVariant newVariant; | |
248 | newVariant << vector; | |
249 | return newVariant; | |
250 | } | |
251 | ||
252 | ||
253 | // ----------------------------------------------------------------------- | |
254 | // wxTriangleProperty | |
255 | // ----------------------------------------------------------------------- | |
256 | ||
257 | // See propgridsample.h for wxTriangle class | |
258 | ||
259 | WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle) | |
260 | ||
261 | WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty,wxPGProperty, | |
262 | wxTriangle,const wxTriangle&,TextCtrl) | |
263 | ||
264 | ||
265 | wxTriangleProperty::wxTriangleProperty( const wxString& label, | |
266 | const wxString& name, | |
267 | const wxTriangle& value) | |
268 | : wxPGProperty(label,name) | |
269 | { | |
270 | SetValue( WXVARIANT(value) ); | |
271 | AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) ); | |
272 | AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) ); | |
273 | AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) ); | |
274 | } | |
275 | ||
276 | wxTriangleProperty::~wxTriangleProperty() { } | |
277 | ||
278 | void wxTriangleProperty::RefreshChildren() | |
279 | { | |
280 | if ( !GetChildCount() ) return; | |
281 | const wxTriangle& triangle = wxTriangleRefFromVariant(m_value); | |
282 | Item(0)->SetValue( WXVARIANT(triangle.a) ); | |
283 | Item(1)->SetValue( WXVARIANT(triangle.b) ); | |
284 | Item(2)->SetValue( WXVARIANT(triangle.c) ); | |
285 | } | |
286 | ||
287 | wxVariant wxTriangleProperty::ChildChanged( wxVariant& thisValue, | |
288 | int childIndex, | |
289 | wxVariant& childValue ) const | |
290 | { | |
291 | wxTriangle triangle; | |
292 | triangle << thisValue; | |
293 | const wxVector3f& vector = wxVector3fRefFromVariant(childValue); | |
294 | switch ( childIndex ) | |
295 | { | |
296 | case 0: triangle.a = vector; break; | |
297 | case 1: triangle.b = vector; break; | |
298 | case 2: triangle.c = vector; break; | |
299 | } | |
300 | wxVariant newVariant; | |
301 | newVariant << triangle; | |
302 | return newVariant; | |
303 | } | |
304 | ||
305 | ||
306 | // ----------------------------------------------------------------------- | |
307 | // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample) | |
308 | // ----------------------------------------------------------------------- | |
309 | ||
310 | class wxSingleChoiceDialogAdapter : public wxPGEditorDialogAdapter | |
311 | { | |
312 | public: | |
313 | ||
314 | wxSingleChoiceDialogAdapter( const wxPGChoices& choices ) | |
315 | : wxPGEditorDialogAdapter(), m_choices(choices) | |
316 | { | |
317 | } | |
318 | ||
319 | virtual bool DoShowDialog( wxPropertyGrid* WXUNUSED(propGrid), | |
320 | wxPGProperty* WXUNUSED(property) ) | |
321 | { | |
322 | wxString s = ::wxGetSingleChoice(wxT("Message"), | |
323 | wxT("Caption"), | |
324 | m_choices.GetLabels()); | |
325 | if ( s.length() ) | |
326 | { | |
327 | SetValue(s); | |
328 | return true; | |
329 | } | |
330 | ||
331 | return false; | |
332 | } | |
333 | ||
334 | protected: | |
335 | const wxPGChoices& m_choices; | |
336 | }; | |
337 | ||
338 | ||
339 | class SingleChoiceProperty : public wxStringProperty | |
340 | { | |
341 | public: | |
342 | ||
343 | SingleChoiceProperty( const wxString& label, | |
344 | const wxString& name = wxPG_LABEL, | |
345 | const wxString& value = wxEmptyString ) | |
346 | : wxStringProperty(label, name, value) | |
347 | { | |
348 | // Prepare choices | |
349 | m_choices.Add(wxT("Cat")); | |
350 | m_choices.Add(wxT("Dog")); | |
351 | m_choices.Add(wxT("Gibbon")); | |
352 | m_choices.Add(wxT("Otter")); | |
353 | } | |
354 | ||
355 | // Set editor to have button | |
356 | virtual const wxPGEditor* DoGetEditorClass() const | |
357 | { | |
358 | return wxPGEditor_TextCtrlAndButton; | |
359 | } | |
360 | ||
361 | // Set what happens on button click | |
362 | virtual wxPGEditorDialogAdapter* GetEditorDialog() const | |
363 | { | |
364 | return new wxSingleChoiceDialogAdapter(m_choices); | |
365 | } | |
366 | ||
367 | protected: | |
368 | wxPGChoices m_choices; | |
369 | }; | |
370 | ||
371 | // ----------------------------------------------------------------------- | |
372 | // Menu IDs | |
373 | // ----------------------------------------------------------------------- | |
374 | ||
375 | enum | |
376 | { | |
377 | PGID = 1, | |
378 | TCID, | |
379 | ID_ABOUT, | |
380 | ID_QUIT, | |
381 | ID_APPENDPROP, | |
382 | ID_APPENDCAT, | |
383 | ID_INSERTPROP, | |
384 | ID_INSERTCAT, | |
385 | ID_ENABLE, | |
386 | ID_SETREADONLY, | |
387 | ID_HIDE, | |
388 | ID_DELETE, | |
389 | ID_DELETER, | |
390 | ID_DELETEALL, | |
391 | ID_UNSPECIFY, | |
392 | ID_ITERATE1, | |
393 | ID_ITERATE2, | |
394 | ID_ITERATE3, | |
395 | ID_ITERATE4, | |
396 | ID_CLEARMODIF, | |
397 | ID_FREEZE, | |
398 | ID_DUMPLIST, | |
399 | ID_COLOURSCHEME1, | |
400 | ID_COLOURSCHEME2, | |
401 | ID_COLOURSCHEME3, | |
402 | ID_CATCOLOURS, | |
403 | ID_SETBGCOLOUR, | |
404 | ID_SETBGCOLOURRECUR, | |
405 | ID_STATICLAYOUT, | |
406 | ID_POPULATE1, | |
407 | ID_POPULATE2, | |
408 | ID_COLLAPSE, | |
409 | ID_COLLAPSEALL, | |
410 | ID_GETVALUES, | |
411 | ID_SETVALUES, | |
412 | ID_SETVALUES2, | |
413 | ID_RUNTESTFULL, | |
414 | ID_RUNTESTPARTIAL, | |
415 | ID_FITCOLUMNS, | |
416 | ID_CHANGEFLAGSITEMS, | |
417 | ID_TESTINSERTCHOICE, | |
418 | ID_TESTDELETECHOICE, | |
419 | ID_INSERTPAGE, | |
420 | ID_REMOVEPAGE, | |
421 | ID_SETSPINCTRLEDITOR, | |
422 | ID_SETPROPERTYVALUE, | |
423 | ID_TESTREPLACE, | |
424 | ID_SETCOLUMNS, | |
425 | ID_TESTXRC, | |
426 | ID_ENABLECOMMONVALUES, | |
427 | ID_SELECTSTYLE, | |
428 | ID_SAVESTATE, | |
429 | ID_RESTORESTATE, | |
430 | ID_RUNMINIMAL, | |
431 | ID_ENABLELABELEDITING, | |
432 | ID_VETOCOLDRAG, | |
433 | ID_SHOWHEADER, | |
434 | ID_ONEXTENDEDKEYNAV | |
435 | }; | |
436 | ||
437 | // ----------------------------------------------------------------------- | |
438 | // Event table | |
439 | // ----------------------------------------------------------------------- | |
440 | ||
441 | BEGIN_EVENT_TABLE(FormMain, wxFrame) | |
442 | EVT_IDLE(FormMain::OnIdle) | |
443 | EVT_MOVE(FormMain::OnMove) | |
444 | EVT_SIZE(FormMain::OnResize) | |
445 | ||
446 | // This occurs when a property is selected | |
447 | EVT_PG_SELECTED( PGID, FormMain::OnPropertyGridSelect ) | |
448 | // This occurs when a property value changes | |
449 | EVT_PG_CHANGED( PGID, FormMain::OnPropertyGridChange ) | |
450 | // This occurs just prior a property value is changed | |
451 | EVT_PG_CHANGING( PGID, FormMain::OnPropertyGridChanging ) | |
452 | // This occurs when a mouse moves over another property | |
453 | EVT_PG_HIGHLIGHTED( PGID, FormMain::OnPropertyGridHighlight ) | |
454 | // This occurs when mouse is right-clicked. | |
455 | EVT_PG_RIGHT_CLICK( PGID, FormMain::OnPropertyGridItemRightClick ) | |
456 | // This occurs when mouse is double-clicked. | |
457 | EVT_PG_DOUBLE_CLICK( PGID, FormMain::OnPropertyGridItemDoubleClick ) | |
458 | // This occurs when propgridmanager's page changes. | |
459 | EVT_PG_PAGE_CHANGED( PGID, FormMain::OnPropertyGridPageChange ) | |
460 | // This occurs when user starts editing a property label | |
461 | EVT_PG_LABEL_EDIT_BEGIN( PGID, | |
462 | FormMain::OnPropertyGridLabelEditBegin ) | |
463 | // This occurs when user stops editing a property label | |
464 | EVT_PG_LABEL_EDIT_ENDING( PGID, | |
465 | FormMain::OnPropertyGridLabelEditEnding ) | |
466 | // This occurs when property's editor button (if any) is clicked. | |
467 | EVT_BUTTON( PGID, FormMain::OnPropertyGridButtonClick ) | |
468 | ||
469 | EVT_PG_ITEM_COLLAPSED( PGID, FormMain::OnPropertyGridItemCollapse ) | |
470 | EVT_PG_ITEM_EXPANDED( PGID, FormMain::OnPropertyGridItemExpand ) | |
471 | ||
472 | EVT_PG_COL_BEGIN_DRAG( PGID, FormMain::OnPropertyGridColBeginDrag ) | |
473 | EVT_PG_COL_DRAGGING( PGID, FormMain::OnPropertyGridColDragging ) | |
474 | EVT_PG_COL_END_DRAG( PGID, FormMain::OnPropertyGridColEndDrag ) | |
475 | ||
476 | EVT_TEXT( PGID, FormMain::OnPropertyGridTextUpdate ) | |
477 | ||
478 | // | |
479 | // Rest of the events are not property grid specific | |
480 | EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent ) | |
481 | EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent ) | |
482 | ||
483 | EVT_MENU( ID_APPENDPROP, FormMain::OnAppendPropClick ) | |
484 | EVT_MENU( ID_APPENDCAT, FormMain::OnAppendCatClick ) | |
485 | EVT_MENU( ID_INSERTPROP, FormMain::OnInsertPropClick ) | |
486 | EVT_MENU( ID_INSERTCAT, FormMain::OnInsertCatClick ) | |
487 | EVT_MENU( ID_DELETE, FormMain::OnDelPropClick ) | |
488 | EVT_MENU( ID_DELETER, FormMain::OnDelPropRClick ) | |
489 | EVT_MENU( ID_UNSPECIFY, FormMain::OnMisc ) | |
490 | EVT_MENU( ID_DELETEALL, FormMain::OnClearClick ) | |
491 | EVT_MENU( ID_ENABLE, FormMain::OnEnableDisable ) | |
492 | EVT_MENU( ID_SETREADONLY, FormMain::OnSetReadOnly ) | |
493 | EVT_MENU( ID_HIDE, FormMain::OnHide ) | |
494 | ||
495 | EVT_MENU( ID_ITERATE1, FormMain::OnIterate1Click ) | |
496 | EVT_MENU( ID_ITERATE2, FormMain::OnIterate2Click ) | |
497 | EVT_MENU( ID_ITERATE3, FormMain::OnIterate3Click ) | |
498 | EVT_MENU( ID_ITERATE4, FormMain::OnIterate4Click ) | |
499 | EVT_MENU( ID_ONEXTENDEDKEYNAV, FormMain::OnExtendedKeyNav ) | |
500 | EVT_MENU( ID_SETBGCOLOUR, FormMain::OnSetBackgroundColour ) | |
501 | EVT_MENU( ID_SETBGCOLOURRECUR, FormMain::OnSetBackgroundColour ) | |
502 | EVT_MENU( ID_CLEARMODIF, FormMain::OnClearModifyStatusClick ) | |
503 | EVT_MENU( ID_FREEZE, FormMain::OnFreezeClick ) | |
504 | EVT_MENU( ID_ENABLELABELEDITING, FormMain::OnEnableLabelEditing ) | |
505 | EVT_MENU( ID_SHOWHEADER, FormMain::OnShowHeader ) | |
506 | EVT_MENU( ID_DUMPLIST, FormMain::OnDumpList ) | |
507 | ||
508 | EVT_MENU( ID_COLOURSCHEME1, FormMain::OnColourScheme ) | |
509 | EVT_MENU( ID_COLOURSCHEME2, FormMain::OnColourScheme ) | |
510 | EVT_MENU( ID_COLOURSCHEME3, FormMain::OnColourScheme ) | |
511 | EVT_MENU( ID_COLOURSCHEME4, FormMain::OnColourScheme ) | |
512 | ||
513 | EVT_MENU( ID_ABOUT, FormMain::OnAbout ) | |
514 | EVT_MENU( ID_QUIT, FormMain::OnCloseClick ) | |
515 | ||
516 | EVT_MENU( ID_CATCOLOURS, FormMain::OnCatColours ) | |
517 | EVT_MENU( ID_SETCOLUMNS, FormMain::OnSetColumns ) | |
518 | EVT_MENU( ID_TESTXRC, FormMain::OnTestXRC ) | |
519 | EVT_MENU( ID_ENABLECOMMONVALUES, FormMain::OnEnableCommonValues ) | |
520 | EVT_MENU( ID_SELECTSTYLE, FormMain::OnSelectStyle ) | |
521 | ||
522 | EVT_MENU( ID_STATICLAYOUT, FormMain::OnMisc ) | |
523 | EVT_MENU( ID_COLLAPSE, FormMain::OnMisc ) | |
524 | EVT_MENU( ID_COLLAPSEALL, FormMain::OnMisc ) | |
525 | ||
526 | EVT_MENU( ID_POPULATE1, FormMain::OnPopulateClick ) | |
527 | EVT_MENU( ID_POPULATE2, FormMain::OnPopulateClick ) | |
528 | ||
529 | EVT_MENU( ID_GETVALUES, FormMain::OnMisc ) | |
530 | EVT_MENU( ID_SETVALUES, FormMain::OnMisc ) | |
531 | EVT_MENU( ID_SETVALUES2, FormMain::OnMisc ) | |
532 | ||
533 | EVT_MENU( ID_FITCOLUMNS, FormMain::OnFitColumnsClick ) | |
534 | ||
535 | EVT_MENU( ID_CHANGEFLAGSITEMS, FormMain::OnChangeFlagsPropItemsClick ) | |
536 | ||
537 | EVT_MENU( ID_RUNTESTFULL, FormMain::OnMisc ) | |
538 | EVT_MENU( ID_RUNTESTPARTIAL, FormMain::OnMisc ) | |
539 | ||
540 | EVT_MENU( ID_TESTINSERTCHOICE, FormMain::OnInsertChoice ) | |
541 | EVT_MENU( ID_TESTDELETECHOICE, FormMain::OnDeleteChoice ) | |
542 | ||
543 | EVT_MENU( ID_INSERTPAGE, FormMain::OnInsertPage ) | |
544 | EVT_MENU( ID_REMOVEPAGE, FormMain::OnRemovePage ) | |
545 | ||
546 | EVT_MENU( ID_SAVESTATE, FormMain::OnSaveState ) | |
547 | EVT_MENU( ID_RESTORESTATE, FormMain::OnRestoreState ) | |
548 | ||
549 | EVT_MENU( ID_SETSPINCTRLEDITOR, FormMain::OnSetSpinCtrlEditorClick ) | |
550 | EVT_MENU( ID_TESTREPLACE, FormMain::OnTestReplaceClick ) | |
551 | EVT_MENU( ID_SETPROPERTYVALUE, FormMain::OnSetPropertyValue ) | |
552 | ||
553 | EVT_MENU( ID_RUNMINIMAL, FormMain::OnRunMinimalClick ) | |
554 | ||
555 | EVT_CONTEXT_MENU( FormMain::OnContextMenu ) | |
556 | END_EVENT_TABLE() | |
557 | ||
558 | // ----------------------------------------------------------------------- | |
559 | ||
560 | void FormMain::OnMove( wxMoveEvent& event ) | |
561 | { | |
562 | if ( !m_pPropGridManager ) | |
563 | { | |
564 | // this check is here so the frame layout can be tested | |
565 | // without creating propertygrid | |
566 | event.Skip(); | |
567 | return; | |
568 | } | |
569 | ||
570 | // Update position properties | |
571 | int x, y; | |
572 | GetPosition(&x,&y); | |
573 | ||
574 | wxPGProperty* id; | |
575 | ||
576 | // Must check if properties exist (as they may be deleted). | |
577 | ||
578 | // Using m_pPropGridManager, we can scan all pages automatically. | |
579 | id = m_pPropGridManager->GetPropertyByName( wxT("X") ); | |
580 | if ( id ) | |
581 | m_pPropGridManager->SetPropertyValue( id, x ); | |
582 | ||
583 | id = m_pPropGridManager->GetPropertyByName( wxT("Y") ); | |
584 | if ( id ) | |
585 | m_pPropGridManager->SetPropertyValue( id, y ); | |
586 | ||
587 | id = m_pPropGridManager->GetPropertyByName( wxT("Position") ); | |
588 | if ( id ) | |
589 | m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxPoint(x,y)) ); | |
590 | ||
591 | // Should always call event.Skip() in frame's MoveEvent handler | |
592 | event.Skip(); | |
593 | } | |
594 | ||
595 | // ----------------------------------------------------------------------- | |
596 | ||
597 | void FormMain::OnResize( wxSizeEvent& event ) | |
598 | { | |
599 | if ( !m_pPropGridManager ) | |
600 | { | |
601 | // this check is here so the frame layout can be tested | |
602 | // without creating propertygrid | |
603 | event.Skip(); | |
604 | return; | |
605 | } | |
606 | ||
607 | // Update size properties | |
608 | int w, h; | |
609 | GetSize(&w,&h); | |
610 | ||
611 | wxPGProperty* id; | |
612 | wxPGProperty* p; | |
613 | ||
614 | // Must check if properties exist (as they may be deleted). | |
615 | ||
616 | // Using m_pPropGridManager, we can scan all pages automatically. | |
617 | p = m_pPropGridManager->GetPropertyByName( wxT("Width") ); | |
618 | if ( p && !p->IsValueUnspecified() ) | |
619 | m_pPropGridManager->SetPropertyValue( p, w ); | |
620 | ||
621 | p = m_pPropGridManager->GetPropertyByName( wxT("Height") ); | |
622 | if ( p && !p->IsValueUnspecified() ) | |
623 | m_pPropGridManager->SetPropertyValue( p, h ); | |
624 | ||
625 | id = m_pPropGridManager->GetPropertyByName ( wxT("Size") ); | |
626 | if ( id ) | |
627 | m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxSize(w,h)) ); | |
628 | ||
629 | // Should always call event.Skip() in frame's SizeEvent handler | |
630 | event.Skip(); | |
631 | } | |
632 | ||
633 | // ----------------------------------------------------------------------- | |
634 | ||
635 | void FormMain::OnPropertyGridChanging( wxPropertyGridEvent& event ) | |
636 | { | |
637 | wxPGProperty* p = event.GetProperty(); | |
638 | ||
639 | if ( p->GetName() == wxT("Font") ) | |
640 | { | |
641 | int res = | |
642 | wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"), | |
643 | p->GetName().c_str(),event.GetValue().GetType().c_str()), | |
644 | wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO, m_pPropGridManager); | |
645 | ||
646 | if ( res == wxNO ) | |
647 | { | |
648 | wxASSERT(event.CanVeto()); | |
649 | ||
650 | event.Veto(); | |
651 | ||
652 | // Since we ask a question, it is better if we omit any validation | |
653 | // failure behavior. | |
654 | event.SetValidationFailureBehavior(0); | |
655 | } | |
656 | } | |
657 | } | |
658 | ||
659 | // | |
660 | // Note how we use three types of value getting in this method: | |
661 | // A) event.GetPropertyValueAsXXX | |
662 | // B) event.GetPropertValue, and then variant's GetXXX | |
663 | // C) grid's GetPropertyValueAsXXX(id) | |
664 | // | |
665 | void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event ) | |
666 | { | |
667 | wxPGProperty* property = event.GetProperty(); | |
668 | ||
669 | const wxString& name = property->GetName(); | |
670 | ||
671 | // Properties store values internally as wxVariants, but it is preferred | |
672 | // to use the more modern wxAny at the interface level | |
673 | wxAny value = property->GetValue(); | |
674 | ||
675 | // Don't handle 'unspecified' values | |
676 | if ( value.IsNull() ) | |
677 | return; | |
678 | ||
679 | // | |
680 | // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS() | |
681 | // macro is used. Unless you want to support this old | |
682 | // compiler in your own code, you can use the more | |
683 | // nicer form value.As<FOO>() instead of | |
684 | // wxANY_AS(value, FOO). | |
685 | // | |
686 | ||
687 | // Some settings are disabled outside Windows platform | |
688 | if ( name == wxT("X") ) | |
689 | SetSize( wxANY_AS(value, int), -1, -1, -1, wxSIZE_USE_EXISTING ); | |
690 | else if ( name == wxT("Y") ) | |
691 | // wxPGVariantToInt is safe long int value getter | |
692 | SetSize ( -1, wxANY_AS(value, int), -1, -1, wxSIZE_USE_EXISTING ); | |
693 | else if ( name == wxT("Width") ) | |
694 | SetSize ( -1, -1, wxANY_AS(value, int), -1, wxSIZE_USE_EXISTING ); | |
695 | else if ( name == wxT("Height") ) | |
696 | SetSize ( -1, -1, -1, wxANY_AS(value, int), wxSIZE_USE_EXISTING ); | |
697 | else if ( name == wxT("Label") ) | |
698 | { | |
699 | SetTitle( wxANY_AS(value, wxString) ); | |
700 | } | |
701 | else if ( name == wxT("Password") ) | |
702 | { | |
703 | static int pwdMode = 0; | |
704 | ||
705 | //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode); | |
706 | ||
707 | pwdMode++; | |
708 | pwdMode &= 1; | |
709 | } | |
710 | else | |
711 | if ( name == wxT("Font") ) | |
712 | { | |
713 | wxFont font = wxANY_AS(value, wxFont); | |
714 | wxASSERT( font.Ok() ); | |
715 | ||
716 | m_pPropGridManager->SetFont( font ); | |
717 | } | |
718 | else | |
719 | if ( name == wxT("Margin Colour") ) | |
720 | { | |
721 | wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue); | |
722 | m_pPropGridManager->GetGrid()->SetMarginColour( cpv.m_colour ); | |
723 | } | |
724 | else if ( name == wxT("Cell Colour") ) | |
725 | { | |
726 | wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue); | |
727 | m_pPropGridManager->GetGrid()->SetCellBackgroundColour( cpv.m_colour ); | |
728 | } | |
729 | else if ( name == wxT("Line Colour") ) | |
730 | { | |
731 | wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue); | |
732 | m_pPropGridManager->GetGrid()->SetLineColour( cpv.m_colour ); | |
733 | } | |
734 | else if ( name == wxT("Cell Text Colour") ) | |
735 | { | |
736 | wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue); | |
737 | m_pPropGridManager->GetGrid()->SetCellTextColour( cpv.m_colour ); | |
738 | } | |
739 | } | |
740 | ||
741 | // ----------------------------------------------------------------------- | |
742 | ||
743 | void FormMain::OnPropertyGridSelect( wxPropertyGridEvent& event ) | |
744 | { | |
745 | wxPGProperty* property = event.GetProperty(); | |
746 | if ( property ) | |
747 | { | |
748 | m_itemEnable->Enable( TRUE ); | |
749 | if ( property->IsEnabled() ) | |
750 | m_itemEnable->SetItemLabel( wxT("Disable") ); | |
751 | else | |
752 | m_itemEnable->SetItemLabel( wxT("Enable") ); | |
753 | } | |
754 | else | |
755 | { | |
756 | m_itemEnable->Enable( FALSE ); | |
757 | } | |
758 | ||
759 | #if wxUSE_STATUSBAR | |
760 | wxPGProperty* prop = event.GetProperty(); | |
761 | wxStatusBar* sb = GetStatusBar(); | |
762 | if ( prop ) | |
763 | { | |
764 | wxString text(wxT("Selected: ")); | |
765 | text += m_pPropGridManager->GetPropertyLabel( prop ); | |
766 | sb->SetStatusText ( text ); | |
767 | } | |
768 | #endif | |
769 | } | |
770 | ||
771 | // ----------------------------------------------------------------------- | |
772 | ||
773 | void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent& WXUNUSED(event) ) | |
774 | { | |
775 | #if wxUSE_STATUSBAR | |
776 | wxStatusBar* sb = GetStatusBar(); | |
777 | wxString text(wxT("Page Changed: ")); | |
778 | text += m_pPropGridManager->GetPageName(m_pPropGridManager->GetSelectedPage()); | |
779 | sb->SetStatusText( text ); | |
780 | #endif | |
781 | } | |
782 | ||
783 | // ----------------------------------------------------------------------- | |
784 | ||
785 | void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event ) | |
786 | { | |
787 | wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)", | |
788 | event.GetProperty()->GetLabel().c_str()); | |
789 | } | |
790 | ||
791 | // ----------------------------------------------------------------------- | |
792 | ||
793 | void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event ) | |
794 | { | |
795 | wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)", | |
796 | event.GetProperty()->GetLabel().c_str()); | |
797 | } | |
798 | ||
799 | // ----------------------------------------------------------------------- | |
800 | ||
801 | void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent& WXUNUSED(event) ) | |
802 | { | |
803 | } | |
804 | ||
805 | // ----------------------------------------------------------------------- | |
806 | ||
807 | void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent& event ) | |
808 | { | |
809 | #if wxUSE_STATUSBAR | |
810 | wxPGProperty* prop = event.GetProperty(); | |
811 | wxStatusBar* sb = GetStatusBar(); | |
812 | if ( prop ) | |
813 | { | |
814 | wxString text(wxT("Right-clicked: ")); | |
815 | text += prop->GetLabel(); | |
816 | text += wxT(", name="); | |
817 | text += m_pPropGridManager->GetPropertyName(prop); | |
818 | sb->SetStatusText( text ); | |
819 | } | |
820 | else | |
821 | { | |
822 | sb->SetStatusText( wxEmptyString ); | |
823 | } | |
824 | #endif | |
825 | } | |
826 | ||
827 | // ----------------------------------------------------------------------- | |
828 | ||
829 | void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent& event ) | |
830 | { | |
831 | #if wxUSE_STATUSBAR | |
832 | wxPGProperty* prop = event.GetProperty(); | |
833 | wxStatusBar* sb = GetStatusBar(); | |
834 | if ( prop ) | |
835 | { | |
836 | wxString text(wxT("Double-clicked: ")); | |
837 | text += prop->GetLabel(); | |
838 | text += wxT(", name="); | |
839 | text += m_pPropGridManager->GetPropertyName(prop); | |
840 | sb->SetStatusText ( text ); | |
841 | } | |
842 | else | |
843 | { | |
844 | sb->SetStatusText ( wxEmptyString ); | |
845 | } | |
846 | #endif | |
847 | } | |
848 | ||
849 | // ----------------------------------------------------------------------- | |
850 | ||
851 | void FormMain::OnPropertyGridButtonClick ( wxCommandEvent& ) | |
852 | { | |
853 | #if wxUSE_STATUSBAR | |
854 | wxPGProperty* prop = m_pPropGridManager->GetSelection(); | |
855 | wxStatusBar* sb = GetStatusBar(); | |
856 | if ( prop ) | |
857 | { | |
858 | wxString text(wxT("Button clicked: ")); | |
859 | text += m_pPropGridManager->GetPropertyLabel(prop); | |
860 | text += wxT(", name="); | |
861 | text += m_pPropGridManager->GetPropertyName(prop); | |
862 | sb->SetStatusText( text ); | |
863 | } | |
864 | else | |
865 | { | |
866 | ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!")); | |
867 | } | |
868 | #endif | |
869 | } | |
870 | ||
871 | // ----------------------------------------------------------------------- | |
872 | ||
873 | void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent& ) | |
874 | { | |
875 | wxLogMessage(wxT("Item was Collapsed")); | |
876 | } | |
877 | ||
878 | // ----------------------------------------------------------------------- | |
879 | ||
880 | void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent& ) | |
881 | { | |
882 | wxLogMessage(wxT("Item was Expanded")); | |
883 | } | |
884 | ||
885 | // ----------------------------------------------------------------------- | |
886 | ||
887 | void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent& event ) | |
888 | { | |
889 | if ( m_itemVetoDragging->IsChecked() ) | |
890 | { | |
891 | wxLogMessage("Splitter %i resize was vetoed", event.GetColumn()); | |
892 | event.Veto(); | |
893 | } | |
894 | else | |
895 | { | |
896 | wxLogMessage("Splitter %i resize began", event.GetColumn()); | |
897 | } | |
898 | } | |
899 | ||
900 | // ----------------------------------------------------------------------- | |
901 | ||
902 | void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent& event ) | |
903 | { | |
904 | wxUnusedVar(event); | |
905 | // For now, let's not spam the log output | |
906 | //wxLogMessage("Splitter %i is being resized", event.GetColumn()); | |
907 | } | |
908 | ||
909 | // ----------------------------------------------------------------------- | |
910 | ||
911 | void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent& event ) | |
912 | { | |
913 | wxLogMessage("Splitter %i resize ended", event.GetColumn()); | |
914 | } | |
915 | ||
916 | // ----------------------------------------------------------------------- | |
917 | ||
918 | // EVT_TEXT handling | |
919 | void FormMain::OnPropertyGridTextUpdate( wxCommandEvent& event ) | |
920 | { | |
921 | event.Skip(); | |
922 | } | |
923 | ||
924 | // ----------------------------------------------------------------------- | |
925 | ||
926 | void FormMain::OnPropertyGridKeyEvent( wxKeyEvent& WXUNUSED(event) ) | |
927 | { | |
928 | // Occurs on wxGTK mostly, but not wxMSW. | |
929 | } | |
930 | ||
931 | // ----------------------------------------------------------------------- | |
932 | ||
933 | void FormMain::OnLabelTextChange( wxCommandEvent& WXUNUSED(event) ) | |
934 | { | |
935 | // Uncomment following to allow property label modify in real-time | |
936 | // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection(); | |
937 | // if ( !p.IsOk() ) return; | |
938 | // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() ); | |
939 | } | |
940 | ||
941 | // ----------------------------------------------------------------------- | |
942 | ||
943 | static const wxChar* _fs_windowstyle_labels[] = { | |
944 | wxT("wxSIMPLE_BORDER"), | |
945 | wxT("wxDOUBLE_BORDER"), | |
946 | wxT("wxSUNKEN_BORDER"), | |
947 | wxT("wxRAISED_BORDER"), | |
948 | wxT("wxNO_BORDER"), | |
949 | wxT("wxTRANSPARENT_WINDOW"), | |
950 | wxT("wxTAB_TRAVERSAL"), | |
951 | wxT("wxWANTS_CHARS"), | |
952 | #if wxNO_FULL_REPAINT_ON_RESIZE | |
953 | wxT("wxNO_FULL_REPAINT_ON_RESIZE"), | |
954 | #endif | |
955 | wxT("wxVSCROLL"), | |
956 | wxT("wxALWAYS_SHOW_SB"), | |
957 | wxT("wxCLIP_CHILDREN"), | |
958 | #if wxFULL_REPAINT_ON_RESIZE | |
959 | wxT("wxFULL_REPAINT_ON_RESIZE"), | |
960 | #endif | |
961 | (const wxChar*) NULL // terminator is always needed | |
962 | }; | |
963 | ||
964 | static const long _fs_windowstyle_values[] = { | |
965 | wxSIMPLE_BORDER, | |
966 | wxDOUBLE_BORDER, | |
967 | wxSUNKEN_BORDER, | |
968 | wxRAISED_BORDER, | |
969 | wxNO_BORDER, | |
970 | wxTRANSPARENT_WINDOW, | |
971 | wxTAB_TRAVERSAL, | |
972 | wxWANTS_CHARS, | |
973 | #if wxNO_FULL_REPAINT_ON_RESIZE | |
974 | wxNO_FULL_REPAINT_ON_RESIZE, | |
975 | #endif | |
976 | wxVSCROLL, | |
977 | wxALWAYS_SHOW_SB, | |
978 | wxCLIP_CHILDREN, | |
979 | #if wxFULL_REPAINT_ON_RESIZE | |
980 | wxFULL_REPAINT_ON_RESIZE | |
981 | #endif | |
982 | }; | |
983 | ||
984 | static const wxChar* _fs_framestyle_labels[] = { | |
985 | wxT("wxCAPTION"), | |
986 | wxT("wxMINIMIZE"), | |
987 | wxT("wxMAXIMIZE"), | |
988 | wxT("wxCLOSE_BOX"), | |
989 | wxT("wxSTAY_ON_TOP"), | |
990 | wxT("wxSYSTEM_MENU"), | |
991 | wxT("wxRESIZE_BORDER"), | |
992 | wxT("wxFRAME_TOOL_WINDOW"), | |
993 | wxT("wxFRAME_NO_TASKBAR"), | |
994 | wxT("wxFRAME_FLOAT_ON_PARENT"), | |
995 | wxT("wxFRAME_SHAPED"), | |
996 | (const wxChar*) NULL | |
997 | }; | |
998 | ||
999 | static const long _fs_framestyle_values[] = { | |
1000 | wxCAPTION, | |
1001 | wxMINIMIZE, | |
1002 | wxMAXIMIZE, | |
1003 | wxCLOSE_BOX, | |
1004 | wxSTAY_ON_TOP, | |
1005 | wxSYSTEM_MENU, | |
1006 | wxRESIZE_BORDER, | |
1007 | wxFRAME_TOOL_WINDOW, | |
1008 | wxFRAME_NO_TASKBAR, | |
1009 | wxFRAME_FLOAT_ON_PARENT, | |
1010 | wxFRAME_SHAPED | |
1011 | }; | |
1012 | ||
1013 | // ----------------------------------------------------------------------- | |
1014 | ||
1015 | void FormMain::OnTestXRC(wxCommandEvent& WXUNUSED(event)) | |
1016 | { | |
1017 | wxMessageBox(wxT("Sorrt, not yet implemented")); | |
1018 | } | |
1019 | ||
1020 | void FormMain::OnEnableCommonValues(wxCommandEvent& WXUNUSED(event)) | |
1021 | { | |
1022 | wxPGProperty* prop = m_pPropGridManager->GetSelection(); | |
1023 | if ( prop ) | |
1024 | prop->EnableCommonValue(); | |
1025 | else | |
1026 | wxMessageBox(wxT("First select a property")); | |
1027 | } | |
1028 | ||
1029 | void FormMain::PopulateWithStandardItems () | |
1030 | { | |
1031 | wxPropertyGridManager* pgman = m_pPropGridManager; | |
1032 | wxPropertyGridPage* pg = pgman->GetPage(wxT("Standard Items")); | |
1033 | ||
1034 | // Append is ideal way to add items to wxPropertyGrid. | |
1035 | pg->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL) ); | |
1036 | ||
1037 | pg->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL,GetTitle()) ); | |
1038 | pg->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL) ); | |
1039 | pg->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") ); | |
1040 | ||
1041 | pg->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL, | |
1042 | pg->GetGrid()->GetMarginColour()) ); | |
1043 | ||
1044 | pg->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL, | |
1045 | pg->GetGrid()->GetCellBackgroundColour()) ); | |
1046 | pg->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL, | |
1047 | pg->GetGrid()->GetCellTextColour()) ); | |
1048 | pg->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL, | |
1049 | pg->GetGrid()->GetLineColour()) ); | |
1050 | pg->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL, | |
1051 | m_combinedFlags, GetWindowStyle()) ); | |
1052 | ||
1053 | //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE); | |
1054 | ||
1055 | pg->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL) ); | |
1056 | ||
1057 | pg->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) ); | |
1058 | pg->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") ); | |
1059 | ||
1060 | // Let's demonstrate 'Units' attribute here | |
1061 | ||
1062 | // Note that we use many attribute constants instead of strings here | |
1063 | // (for instance, wxPG_ATTR_MIN, instead of wxT("min")). | |
1064 | // Using constant may reduce binary size. | |
1065 | ||
1066 | pg->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL,480) ); | |
1067 | pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN, (long)10 ); | |
1068 | pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX, (long)2048 ); | |
1069 | pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS, wxT("Pixels") ); | |
1070 | ||
1071 | // Set value to unspecified so that Hint attribute will be demonstrated | |
1072 | pg->SetPropertyValueUnspecified("Height"); | |
1073 | pg->SetPropertyAttribute("Height", wxPG_ATTR_HINT, | |
1074 | "Enter new height for window" ); | |
1075 | ||
1076 | // Difference between hint and help string is that the hint is shown in | |
1077 | // an empty value cell, while help string is shown either in the | |
1078 | // description text box, as a tool tip, or on the status bar. | |
1079 | pg->SetPropertyHelpString("Height", | |
1080 | "This property uses attributes \"Units\" and \"Hint\"." ); | |
1081 | ||
1082 | pg->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL,640) ); | |
1083 | pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN, (long)10 ); | |
1084 | pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX, (long)2048 ); | |
1085 | pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS, wxT("Pixels") ); | |
1086 | ||
1087 | pg->SetPropertyValueUnspecified(wxT("Width")); | |
1088 | pg->SetPropertyAttribute("Width", wxPG_ATTR_HINT, | |
1089 | "Enter new width for window" ); | |
1090 | pg->SetPropertyHelpString("Width", | |
1091 | "This property uses attributes \"Units\" and \"Hint\"." ); | |
1092 | ||
1093 | pg->Append( new wxIntProperty(wxT("X"),wxPG_LABEL,10) ); | |
1094 | pg->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS, wxT("Pixels") ); | |
1095 | pg->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") ); | |
1096 | ||
1097 | pg->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL,10) ); | |
1098 | pg->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS, wxT("Pixels") ); | |
1099 | pg->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") ); | |
1100 | ||
1101 | const wxChar* disabledHelpString = wxT("This property is simply disabled. Inorder to have label disabled as well, ") | |
1102 | wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle."); | |
1103 | ||
1104 | pg->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL) ); | |
1105 | pg->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL,::wxGetOsDescription()) ); | |
1106 | ||
1107 | pg->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL,::wxGetUserId()) ); | |
1108 | pg->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL,::wxGetUserHome()) ); | |
1109 | pg->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL,::wxGetUserName()) ); | |
1110 | ||
1111 | // Disable some of them | |
1112 | pg->DisableProperty( wxT("Operating System") ); | |
1113 | pg->DisableProperty( wxT("User Id") ); | |
1114 | pg->DisableProperty( wxT("User Name") ); | |
1115 | ||
1116 | pg->SetPropertyHelpString( wxT("Operating System"), disabledHelpString ); | |
1117 | pg->SetPropertyHelpString( wxT("User Id"), disabledHelpString ); | |
1118 | pg->SetPropertyHelpString( wxT("User Name"), disabledHelpString ); | |
1119 | ||
1120 | pg->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL) ); | |
1121 | ||
1122 | pg->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL) ); | |
1123 | pg->SetPropertyHelpString( wxT("FontDataProperty"), | |
1124 | wxT("This demonstrates wxFontDataProperty class defined in this sample app. ") | |
1125 | wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.") | |
1126 | ); | |
1127 | ||
1128 | pg->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL) ); | |
1129 | pg->SetPropertyHelpString( wxT("DirsProperty"), | |
1130 | wxT("This demonstrates wxDirsProperty class defined in this sample app. ") | |
1131 | wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ") | |
1132 | wxT("with custom action (dir dialog popup) defined.") | |
1133 | ); | |
1134 | ||
1135 | wxArrayDouble arrdbl; | |
1136 | arrdbl.Add(-1.0); | |
1137 | arrdbl.Add(-0.5); | |
1138 | arrdbl.Add(0.0); | |
1139 | arrdbl.Add(0.5); | |
1140 | arrdbl.Add(1.0); | |
1141 | ||
1142 | pg->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL,arrdbl) ); | |
1143 | //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2); | |
1144 | pg->SetPropertyHelpString( wxT("ArrayDoubleProperty"), | |
1145 | wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ") | |
1146 | wxT("It is an example of a custom list editor property.") | |
1147 | ); | |
1148 | ||
1149 | pg->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL, | |
1150 | wxT("Editing properties will have immediate effect on this window, ") | |
1151 | wxT("and vice versa (atleast in most cases, that is).") | |
1152 | ) ); | |
1153 | pg->SetPropertyHelpString( wxT("Information"), | |
1154 | wxT("This property is read-only.") ); | |
1155 | ||
1156 | pg->SetPropertyReadOnly( wxT("Information"), true ); | |
1157 | ||
1158 | // | |
1159 | // Set test information for cells in columns 3 and 4 | |
1160 | // (reserve column 2 for displaying units) | |
1161 | wxPropertyGridIterator it; | |
1162 | wxBitmap bmp = wxArtProvider::GetBitmap(wxART_FOLDER); | |
1163 | ||
1164 | for ( it = pg->GetGrid()->GetIterator(); | |
1165 | !it.AtEnd(); | |
1166 | it++ ) | |
1167 | { | |
1168 | wxPGProperty* p = *it; | |
1169 | if ( p->IsCategory() ) | |
1170 | continue; | |
1171 | ||
1172 | pg->SetPropertyCell( p, 3, wxT("Cell 3"), bmp ); | |
1173 | pg->SetPropertyCell( p, 4, wxT("Cell 4"), wxNullBitmap, *wxWHITE, *wxBLACK ); | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | // ----------------------------------------------------------------------- | |
1178 | ||
1179 | void FormMain::PopulateWithExamples () | |
1180 | { | |
1181 | wxPropertyGridManager* pgman = m_pPropGridManager; | |
1182 | wxPropertyGridPage* pg = pgman->GetPage(wxT("Examples")); | |
1183 | wxPGProperty* pid; | |
1184 | wxPGProperty* prop; | |
1185 | ||
1186 | //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) ); | |
1187 | //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") ); | |
1188 | ||
1189 | #if wxUSE_SPINBTN | |
1190 | pg->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL, 0 ) ); | |
1191 | ||
1192 | pg->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl ); | |
1193 | pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN, (long)-10 ); // Use constants instead of string | |
1194 | pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX, (long)16384 ); // for reduced binary size. | |
1195 | pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 ); | |
1196 | pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true ); | |
1197 | //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true ); | |
1198 | ||
1199 | pg->SetPropertyHelpString( wxT("SpinCtrl"), | |
1200 | wxT("This is regular wxIntProperty, which editor has been ") | |
1201 | wxT("changed to wxPGEditor_SpinCtrl. Note however that ") | |
1202 | wxT("static wxPropertyGrid::RegisterAdditionalEditors() ") | |
1203 | wxT("needs to be called prior to using it.")); | |
1204 | ||
1205 | #endif | |
1206 | ||
1207 | // Add bool property | |
1208 | pg->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL, false ) ); | |
1209 | ||
1210 | // Add bool property with check box | |
1211 | pg->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL, false ) ); | |
1212 | pg->SetPropertyAttribute( wxT("BoolProperty with CheckBox"), | |
1213 | wxPG_BOOL_USE_CHECKBOX, | |
1214 | true ); | |
1215 | ||
1216 | pg->SetPropertyHelpString( wxT("BoolProperty with CheckBox"), | |
1217 | wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") ); | |
1218 | ||
1219 | prop = pg->Append( new wxFloatProperty("FloatProperty", | |
1220 | wxPG_LABEL, | |
1221 | 1234500.23) ); | |
1222 | prop->SetAttribute("Min", -100.12); | |
1223 | ||
1224 | // A string property that can be edited in a separate editor dialog. | |
1225 | pg->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"), | |
1226 | wxT("This is much longer string than the first one. Edit it by clicking the button.") ) ); | |
1227 | ||
1228 | // A property that edits a wxArrayString. | |
1229 | wxArrayString example_array; | |
1230 | example_array.Add( wxT("String 1")); | |
1231 | example_array.Add( wxT("String 2")); | |
1232 | example_array.Add( wxT("String 3")); | |
1233 | pg->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL, | |
1234 | example_array) ); | |
1235 | ||
1236 | // Test adding same category multiple times ( should not actually create a new one ) | |
1237 | //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) ); | |
1238 | ||
1239 | // A file selector property. Note that argument between name | |
1240 | // and initial value is wildcard (format same as in wxFileDialog). | |
1241 | prop = new wxFileProperty( wxT("FileProperty"), wxT("TextFile") ); | |
1242 | pg->Append( prop ); | |
1243 | ||
1244 | prop->SetAttribute(wxPG_FILE_WILDCARD,wxT("Text Files (*.txt)|*.txt")); | |
1245 | prop->SetAttribute(wxPG_FILE_DIALOG_TITLE,wxT("Custom File Dialog Title")); | |
1246 | prop->SetAttribute(wxPG_FILE_SHOW_FULL_PATH,false); | |
1247 | ||
1248 | #ifdef __WXMSW__ | |
1249 | prop->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH,wxT("C:\\Windows")); | |
1250 | pg->SetPropertyValue(prop,wxT("C:\\Windows\\System32\\msvcrt71.dll")); | |
1251 | #endif | |
1252 | ||
1253 | #if wxUSE_IMAGE | |
1254 | // An image file property. Arguments are just like for FileProperty, but | |
1255 | // wildcard is missing (it is autogenerated from supported image formats). | |
1256 | // If you really need to override it, create property separately, and call | |
1257 | // its SetWildcard method. | |
1258 | pg->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL ) ); | |
1259 | #endif | |
1260 | ||
1261 | pid = pg->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL,*wxRED) ); | |
1262 | pg->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox ); | |
1263 | pg->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true); | |
1264 | pg->SetPropertyHelpString( wxT("ColourProperty"), | |
1265 | wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ") | |
1266 | wxT("editor of this property to wxPGEditor_ComboBox)")); | |
1267 | ||
1268 | pid = pg->Append( new wxColourProperty("ColourPropertyWithAlpha", | |
1269 | wxPG_LABEL, | |
1270 | wxColour(15, 200, 95, 128)) ); | |
1271 | pg->SetPropertyAttribute("ColourPropertyWithAlpha", "HasAlpha", true); | |
1272 | pg->SetPropertyHelpString("ColourPropertyWithAlpha", | |
1273 | "Attribute \"HasAlpha\" is set to true for this property."); | |
1274 | ||
1275 | // | |
1276 | // This demonstrates using alternative editor for colour property | |
1277 | // to trigger colour dialog directly from button. | |
1278 | pg->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL,*wxGREEN) ); | |
1279 | ||
1280 | // | |
1281 | // wxEnumProperty does not store strings or even list of strings | |
1282 | // ( so that's why they are static in function ). | |
1283 | static const wxChar* enum_prop_labels[] = { wxT("One Item"), | |
1284 | wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL }; | |
1285 | ||
1286 | // this value array would be optional if values matched string indexes | |
1287 | static long enum_prop_values[] = { 40, 80, 120, 160 }; | |
1288 | ||
1289 | // note that the initial value (the last argument) is the actual value, | |
1290 | // not index or anything like that. Thus, our value selects "Another Item". | |
1291 | // | |
1292 | // 0 before value is number of items. If it is 0, like in our example, | |
1293 | // number of items is calculated, and this requires that the string pointer | |
1294 | // array is terminated with NULL. | |
1295 | pg->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL, | |
1296 | enum_prop_labels, enum_prop_values, 80 ) ); | |
1297 | ||
1298 | wxPGChoices soc; | |
1299 | ||
1300 | // use basic table from our previous example | |
1301 | // can also set/add wxArrayStrings and wxArrayInts directly. | |
1302 | soc.Set( enum_prop_labels, enum_prop_values ); | |
1303 | ||
1304 | // add extra items | |
1305 | soc.Add( wxT("Look, it continues"), 200 ); | |
1306 | soc.Add( wxT("Even More"), 240 ); | |
1307 | soc.Add( wxT("And More"), 280 ); | |
1308 | soc.Add( "", 300 ); | |
1309 | soc.Add( wxT("True End of the List"), 320 ); | |
1310 | ||
1311 | // Test custom colours ([] operator of wxPGChoices returns | |
1312 | // references to wxPGChoiceEntry). | |
1313 | soc[1].SetFgCol(*wxRED); | |
1314 | soc[1].SetBgCol(*wxLIGHT_GREY); | |
1315 | soc[2].SetFgCol(*wxGREEN); | |
1316 | soc[2].SetBgCol(*wxLIGHT_GREY); | |
1317 | soc[3].SetFgCol(*wxBLUE); | |
1318 | soc[3].SetBgCol(*wxLIGHT_GREY); | |
1319 | soc[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER)); | |
1320 | ||
1321 | pg->Append( new wxEnumProperty(wxT("EnumProperty 2"), | |
1322 | wxPG_LABEL, | |
1323 | soc, | |
1324 | 240) ); | |
1325 | pg->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360); | |
1326 | ||
1327 | // Here we only display the original 'soc' choices | |
1328 | pg->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL, | |
1329 | soc, 240 ) ); | |
1330 | ||
1331 | // Test Hint attribute in EnumProperty | |
1332 | pg->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint"); | |
1333 | ||
1334 | pg->SetPropertyHelpString("EnumProperty 3", | |
1335 | "This property uses \"Hint\" attribute."); | |
1336 | ||
1337 | // 'soc' plus one exclusive extra choice "4th only" | |
1338 | pg->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL, | |
1339 | soc, 240 ) ); | |
1340 | pg->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360); | |
1341 | ||
1342 | pg->SetPropertyHelpString(wxT("EnumProperty 4"), | |
1343 | wxT("Should have one extra item when compared to EnumProperty 3")); | |
1344 | ||
1345 | // Password property example. | |
1346 | pg->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL, wxT("password")) ); | |
1347 | pg->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD, true ); | |
1348 | pg->SetPropertyHelpString( wxT("Password"), | |
1349 | wxT("Has attribute wxPG_STRING_PASSWORD set to true") ); | |
1350 | ||
1351 | // String editor with dir selector button. Uses wxEmptyString as name, which | |
1352 | // is allowed (naturally, in this case property cannot be accessed by name). | |
1353 | pg->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL, ::wxGetUserHome()) ); | |
1354 | pg->SetPropertyAttribute( wxT("DirProperty"), | |
1355 | wxPG_DIR_DIALOG_MESSAGE, | |
1356 | wxT("This is a custom dir dialog message") ); | |
1357 | ||
1358 | // Add string property - first arg is label, second name, and third initial value | |
1359 | pg->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL ) ); | |
1360 | pg->SetPropertyMaxLength( wxT("StringProperty"), 6 ); | |
1361 | pg->SetPropertyHelpString( wxT("StringProperty"), | |
1362 | wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") ); | |
1363 | ||
1364 | // Set value after limiting so that it will be applied | |
1365 | pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") ); | |
1366 | ||
1367 | // | |
1368 | // Demonstrate "AutoComplete" attribute | |
1369 | pg->Append( new wxStringProperty( "StringProperty AutoComplete", | |
1370 | wxPG_LABEL ) ); | |
1371 | ||
1372 | wxArrayString autoCompleteStrings; | |
1373 | autoCompleteStrings.Add("One choice"); | |
1374 | autoCompleteStrings.Add("Another choice"); | |
1375 | autoCompleteStrings.Add("Another choice, yeah"); | |
1376 | autoCompleteStrings.Add("Yet another choice"); | |
1377 | autoCompleteStrings.Add("Yet another choice, bear with me"); | |
1378 | pg->SetPropertyAttribute( "StringProperty AutoComplete", | |
1379 | "AutoComplete", | |
1380 | autoCompleteStrings ); | |
1381 | ||
1382 | pg->SetPropertyHelpString( "StringProperty AutoComplete", | |
1383 | "AutoComplete attribute has been set for this property " | |
1384 | "(try writing something beginning with 'a', 'o' or 'y')."); | |
1385 | ||
1386 | // Add string property with arbitrarily wide bitmap in front of it. We | |
1387 | // intentionally lower-than-typical row height here so that the ugly | |
1388 | // scaling code wont't be run. | |
1389 | pg->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"), | |
1390 | wxPG_LABEL, | |
1391 | wxT("Test Text")) ); | |
1392 | wxBitmap myTestBitmap(60, 15, 32); | |
1393 | wxMemoryDC mdc; | |
1394 | mdc.SelectObject(myTestBitmap); | |
1395 | mdc.Clear(); | |
1396 | mdc.SetPen(*wxBLACK); | |
1397 | mdc.DrawLine(0, 0, 60, 15); | |
1398 | mdc.SelectObject(wxNullBitmap); | |
1399 | pg->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap ); | |
1400 | ||
1401 | ||
1402 | // this value array would be optional if values matched string indexes | |
1403 | //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX }; | |
1404 | ||
1405 | //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"), | |
1406 | // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) ); | |
1407 | ||
1408 | ||
1409 | // Multi choice dialog. | |
1410 | wxArrayString tchoices; | |
1411 | tchoices.Add(wxT("Cabbage")); | |
1412 | tchoices.Add(wxT("Carrot")); | |
1413 | tchoices.Add(wxT("Onion")); | |
1414 | tchoices.Add(wxT("Potato")); | |
1415 | tchoices.Add(wxT("Strawberry")); | |
1416 | ||
1417 | wxArrayString tchoicesValues; | |
1418 | tchoicesValues.Add(wxT("Carrot")); | |
1419 | tchoicesValues.Add(wxT("Potato")); | |
1420 | ||
1421 | pg->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL, tchoices ) ); | |
1422 | ||
1423 | pg->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL, | |
1424 | tchoices, tchoicesValues ) ); | |
1425 | pg->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true ); | |
1426 | ||
1427 | pg->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) ); | |
1428 | pg->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) ); | |
1429 | ||
1430 | // UInt samples | |
1431 | pg->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL, wxULongLong(wxULL(0xFEEEFEEEFEEE)))); | |
1432 | pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE ); | |
1433 | pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_HEX ); | |
1434 | //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE ); | |
1435 | //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT ); | |
1436 | ||
1437 | // | |
1438 | // wxEditEnumProperty | |
1439 | wxPGChoices eech; | |
1440 | eech.Add(wxT("Choice 1")); | |
1441 | eech.Add(wxT("Choice 2")); | |
1442 | eech.Add(wxT("Choice 3")); | |
1443 | pg->Append( new wxEditEnumProperty("EditEnumProperty", | |
1444 | wxPG_LABEL, | |
1445 | eech, | |
1446 | "Choice not in the list") ); | |
1447 | ||
1448 | // Test Hint attribute in EditEnumProperty | |
1449 | pg->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint"); | |
1450 | ||
1451 | //wxString v_; | |
1452 | //wxTextValidator validator1(wxFILTER_NUMERIC,&v_); | |
1453 | //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 ); | |
1454 | ||
1455 | #if wxUSE_DATETIME | |
1456 | // | |
1457 | // wxDateTimeProperty | |
1458 | pg->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL, wxDateTime::Now() ) ); | |
1459 | ||
1460 | #if wxUSE_DATEPICKCTRL | |
1461 | pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE, | |
1462 | (long)(wxDP_DROPDOWN | | |
1463 | wxDP_SHOWCENTURY | | |
1464 | wxDP_ALLOWNONE) ); | |
1465 | ||
1466 | pg->SetPropertyHelpString( wxT("DateProperty"), | |
1467 | wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)") | |
1468 | wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") ); | |
1469 | #endif | |
1470 | ||
1471 | #endif | |
1472 | ||
1473 | // | |
1474 | // Add Triangle properties as both wxTriangleProperty and | |
1475 | // a generic parent property (using wxStringProperty). | |
1476 | // | |
1477 | wxPGProperty* topId = pg->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL, wxT("<composed>")) ); | |
1478 | ||
1479 | pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) ); | |
1480 | pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) ); | |
1481 | pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) ); | |
1482 | pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) ); | |
1483 | ||
1484 | pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) ); | |
1485 | ||
1486 | pg->SetPropertyHelpString( wxT("3D Object"), | |
1487 | wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ") | |
1488 | wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") ); | |
1489 | ||
1490 | pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) ); | |
1491 | pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) ); | |
1492 | pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) ); | |
1493 | pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) ); | |
1494 | ||
1495 | pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) ); | |
1496 | ||
1497 | // | |
1498 | // This snippet is a doc sample test | |
1499 | // | |
1500 | wxPGProperty* carProp = pg->Append(new wxStringProperty(wxT("Car"), | |
1501 | wxPG_LABEL, | |
1502 | wxT("<composed>"))); | |
1503 | ||
1504 | pg->AppendIn(carProp, new wxStringProperty(wxT("Model"), | |
1505 | wxPG_LABEL, | |
1506 | wxT("Lamborghini Diablo SV"))); | |
1507 | ||
1508 | pg->AppendIn(carProp, new wxIntProperty(wxT("Engine Size (cc)"), | |
1509 | wxPG_LABEL, | |
1510 | 5707) ); | |
1511 | ||
1512 | wxPGProperty* speedsProp = pg->AppendIn(carProp, | |
1513 | new wxStringProperty(wxT("Speeds"), | |
1514 | wxPG_LABEL, | |
1515 | wxT("<composed>"))); | |
1516 | ||
1517 | pg->AppendIn( speedsProp, new wxIntProperty(wxT("Max. Speed (mph)"), | |
1518 | wxPG_LABEL,290) ); | |
1519 | pg->AppendIn( speedsProp, new wxFloatProperty(wxT("0-100 mph (sec)"), | |
1520 | wxPG_LABEL,3.9) ); | |
1521 | pg->AppendIn( speedsProp, new wxFloatProperty(wxT("1/4 mile (sec)"), | |
1522 | wxPG_LABEL,8.6) ); | |
1523 | ||
1524 | // This is how child property can be referred to by name | |
1525 | pg->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 ); | |
1526 | ||
1527 | pg->AppendIn(carProp, new wxIntProperty(wxT("Price ($)"), | |
1528 | wxPG_LABEL, | |
1529 | 300000) ); | |
1530 | ||
1531 | pg->AppendIn(carProp, new wxBoolProperty(wxT("Convertible"), | |
1532 | wxPG_LABEL, | |
1533 | false) ); | |
1534 | ||
1535 | // Displayed value of "Car" property is now very close to this: | |
1536 | // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000" | |
1537 | ||
1538 | // | |
1539 | // Test wxSampleMultiButtonEditor | |
1540 | pg->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL) ); | |
1541 | pg->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor ); | |
1542 | ||
1543 | // Test SingleChoiceProperty | |
1544 | pg->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) ); | |
1545 | ||
1546 | ||
1547 | // | |
1548 | // Test adding variable height bitmaps in wxPGChoices | |
1549 | wxPGChoices bc; | |
1550 | ||
1551 | bc.Add(wxT("Wee"), wxBitmap(16, 16)); | |
1552 | bc.Add(wxT("Not so wee"), wxBitmap(32, 32)); | |
1553 | bc.Add(wxT("Friggin' huge"), wxBitmap(64, 64)); | |
1554 | ||
1555 | pg->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"), | |
1556 | wxPG_LABEL, | |
1557 | bc, | |
1558 | 0) ); | |
1559 | ||
1560 | // | |
1561 | // Test how non-editable composite strings appear | |
1562 | pid = new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL, wxT("<composed>")); | |
1563 | pg->SetPropertyReadOnly(pid); | |
1564 | ||
1565 | // | |
1566 | // For testing purposes, combine two methods of adding children | |
1567 | // | |
1568 | ||
1569 | pid->AppendChild( new wxStringProperty(wxT("Latest Release"), | |
1570 | wxPG_LABEL, | |
1571 | wxT("2.8.10"))); | |
1572 | pid->AppendChild( new wxBoolProperty(wxT("Win API"), | |
1573 | wxPG_LABEL, | |
1574 | true) ); | |
1575 | ||
1576 | pg->Append( pid ); | |
1577 | ||
1578 | pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) ); | |
1579 | pg->AppendIn(pid, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL, true) ); | |
1580 | pg->AppendIn(pid, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL, false) ); | |
1581 | pg->AppendIn(pid, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL, wxT("2.9.0")) ); | |
1582 | pg->AppendIn(pid, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL, true) ); | |
1583 | pg->AppendIn(pid, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL, false) ); | |
1584 | pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) ); | |
1585 | ||
1586 | AddTestProperties(pg); | |
1587 | } | |
1588 | ||
1589 | // ----------------------------------------------------------------------- | |
1590 | ||
1591 | void FormMain::PopulateWithLibraryConfig () | |
1592 | { | |
1593 | wxPropertyGridManager* pgman = m_pPropGridManager; | |
1594 | wxPropertyGridPage* pg = pgman->GetPage(wxT("wxWidgets Library Config")); | |
1595 | ||
1596 | // Set custom column proportions (here in the sample app we need | |
1597 | // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually | |
1598 | // need not to do it in your application). | |
1599 | if ( pgman->HasFlag(wxPG_SPLITTER_AUTO_CENTER) ) | |
1600 | { | |
1601 | pg->SetColumnProportion(0, 3); | |
1602 | pg->SetColumnProportion(1, 1); | |
1603 | } | |
1604 | ||
1605 | wxPGProperty* cat; | |
1606 | ||
1607 | wxBitmap bmp = wxArtProvider::GetBitmap(wxART_REPORT_VIEW); | |
1608 | ||
1609 | wxPGProperty* pid; | |
1610 | ||
1611 | wxFont italicFont = pgman->GetGrid()->GetCaptionFont(); | |
1612 | italicFont.SetStyle(wxFONTSTYLE_ITALIC); | |
1613 | ||
1614 | wxString italicFontHelp = "Font of this property's wxPGCell has " | |
1615 | "been modified. Obtain property's cell " | |
1616 | "with wxPGProperty::" | |
1617 | "GetOrCreateCell(column)."; | |
1618 | ||
1619 | #define ADD_WX_LIB_CONF_GROUP(A) \ | |
1620 | cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \ | |
1621 | pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \ | |
1622 | cat->GetCell(0).SetFont(italicFont); \ | |
1623 | cat->SetHelpString(italicFontHelp); | |
1624 | ||
1625 | #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false))); | |
1626 | #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \ | |
1627 | pg->DisableProperty(wxT(#A)); | |
1628 | ||
1629 | pid = pg->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) ); | |
1630 | pg->SetPropertyCell( pid, 0, wxPG_LABEL, bmp ); | |
1631 | ||
1632 | // Both of following lines would set a label for the second column | |
1633 | pg->SetPropertyCell( pid, 1, "Is Enabled" ); | |
1634 | pid->SetValue("Is Enabled"); | |
1635 | ||
1636 | ADD_WX_LIB_CONF_GROUP(wxT("Global Settings")) | |
1637 | ADD_WX_LIB_CONF( wxUSE_GUI ) | |
1638 | ||
1639 | ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings")) | |
1640 | #if defined(WXWIN_COMPATIBILITY_2_2) | |
1641 | ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2 ) | |
1642 | #endif | |
1643 | #if defined(WXWIN_COMPATIBILITY_2_4) | |
1644 | ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4 ) | |
1645 | #endif | |
1646 | #if defined(WXWIN_COMPATIBILITY_2_6) | |
1647 | ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6 ) | |
1648 | #endif | |
1649 | #if defined(WXWIN_COMPATIBILITY_2_8) | |
1650 | ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8 ) | |
1651 | #endif | |
1652 | #ifdef wxFONT_SIZE_COMPATIBILITY | |
1653 | ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY ) | |
1654 | #else | |
1655 | ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY ) | |
1656 | #endif | |
1657 | #ifdef wxDIALOG_UNIT_COMPATIBILITY | |
1658 | ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY ) | |
1659 | #else | |
1660 | ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY ) | |
1661 | #endif | |
1662 | ||
1663 | ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings")) | |
1664 | ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT ) | |
1665 | ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING ) | |
1666 | ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS ) | |
1667 | ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS ) | |
1668 | ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION ) | |
1669 | ||
1670 | ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support")) | |
1671 | ADD_WX_LIB_CONF( wxUSE_UNICODE ) | |
1672 | ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU ) | |
1673 | ||
1674 | ADD_WX_LIB_CONF_GROUP(wxT("Global Features")) | |
1675 | ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS ) | |
1676 | ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI ) | |
1677 | ADD_WX_LIB_CONF( wxUSE_STL ) | |
1678 | ADD_WX_LIB_CONF( wxUSE_LOG ) | |
1679 | ADD_WX_LIB_CONF( wxUSE_LOGWINDOW ) | |
1680 | ADD_WX_LIB_CONF( wxUSE_LOGGUI ) | |
1681 | ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG ) | |
1682 | ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER ) | |
1683 | ADD_WX_LIB_CONF( wxUSE_THREADS ) | |
1684 | ADD_WX_LIB_CONF( wxUSE_STREAMS ) | |
1685 | ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM ) | |
1686 | ||
1687 | ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features")) | |
1688 | ADD_WX_LIB_CONF( wxUSE_LONGLONG ) | |
1689 | ADD_WX_LIB_CONF( wxUSE_FILE ) | |
1690 | ADD_WX_LIB_CONF( wxUSE_FFILE ) | |
1691 | ADD_WX_LIB_CONF( wxUSE_FSVOLUME ) | |
1692 | ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER ) | |
1693 | ADD_WX_LIB_CONF( wxUSE_TEXTFILE ) | |
1694 | ADD_WX_LIB_CONF( wxUSE_INTL ) | |
1695 | ADD_WX_LIB_CONF( wxUSE_DATETIME ) | |
1696 | ADD_WX_LIB_CONF( wxUSE_TIMER ) | |
1697 | ADD_WX_LIB_CONF( wxUSE_STOPWATCH ) | |
1698 | ADD_WX_LIB_CONF( wxUSE_CONFIG ) | |
1699 | #ifdef wxUSE_CONFIG_NATIVE | |
1700 | ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE ) | |
1701 | #else | |
1702 | ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE ) | |
1703 | #endif | |
1704 | ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER ) | |
1705 | ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS ) | |
1706 | ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER ) | |
1707 | ADD_WX_LIB_CONF( wxUSE_SOCKETS ) | |
1708 | ADD_WX_LIB_CONF( wxUSE_FILESYSTEM ) | |
1709 | ADD_WX_LIB_CONF( wxUSE_FS_ZIP ) | |
1710 | ADD_WX_LIB_CONF( wxUSE_FS_INET ) | |
1711 | ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM ) | |
1712 | ADD_WX_LIB_CONF( wxUSE_ZLIB ) | |
1713 | ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE ) | |
1714 | ADD_WX_LIB_CONF( wxUSE_JOYSTICK ) | |
1715 | ADD_WX_LIB_CONF( wxUSE_FONTMAP ) | |
1716 | ADD_WX_LIB_CONF( wxUSE_MIMETYPE ) | |
1717 | ADD_WX_LIB_CONF( wxUSE_PROTOCOL ) | |
1718 | ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE ) | |
1719 | ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP ) | |
1720 | ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP ) | |
1721 | ADD_WX_LIB_CONF( wxUSE_URL ) | |
1722 | #ifdef wxUSE_URL_NATIVE | |
1723 | ADD_WX_LIB_CONF( wxUSE_URL_NATIVE ) | |
1724 | #else | |
1725 | ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE ) | |
1726 | #endif | |
1727 | ADD_WX_LIB_CONF( wxUSE_REGEX ) | |
1728 | ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS ) | |
1729 | ADD_WX_LIB_CONF( wxUSE_SOUND ) | |
1730 | #ifdef wxUSE_XRC | |
1731 | ADD_WX_LIB_CONF( wxUSE_XRC ) | |
1732 | #else | |
1733 | ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC ) | |
1734 | #endif | |
1735 | ADD_WX_LIB_CONF( wxUSE_XML ) | |
1736 | ||
1737 | // Set them to use check box. | |
1738 | pg->SetPropertyAttribute(pid,wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE); | |
1739 | } | |
1740 | ||
1741 | ||
1742 | // | |
1743 | // Handle events of the third page here. | |
1744 | class wxMyPropertyGridPage : public wxPropertyGridPage | |
1745 | { | |
1746 | public: | |
1747 | ||
1748 | // Return false here to indicate unhandled events should be | |
1749 | // propagated to manager's parent, as normal. | |
1750 | virtual bool IsHandlingAllEvents() const { return false; } | |
1751 | ||
1752 | protected: | |
1753 | ||
1754 | virtual wxPGProperty* DoInsert( wxPGProperty* parent, | |
1755 | int index, | |
1756 | wxPGProperty* property ) | |
1757 | { | |
1758 | return wxPropertyGridPage::DoInsert(parent,index,property); | |
1759 | } | |
1760 | ||
1761 | void OnPropertySelect( wxPropertyGridEvent& event ); | |
1762 | void OnPropertyChanging( wxPropertyGridEvent& event ); | |
1763 | void OnPropertyChange( wxPropertyGridEvent& event ); | |
1764 | void OnPageChange( wxPropertyGridEvent& event ); | |
1765 | ||
1766 | private: | |
1767 | DECLARE_EVENT_TABLE() | |
1768 | }; | |
1769 | ||
1770 | ||
1771 | BEGIN_EVENT_TABLE(wxMyPropertyGridPage, wxPropertyGridPage) | |
1772 | EVT_PG_SELECTED( wxID_ANY, wxMyPropertyGridPage::OnPropertySelect ) | |
1773 | EVT_PG_CHANGING( wxID_ANY, wxMyPropertyGridPage::OnPropertyChanging ) | |
1774 | EVT_PG_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPropertyChange ) | |
1775 | EVT_PG_PAGE_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPageChange ) | |
1776 | END_EVENT_TABLE() | |
1777 | ||
1778 | ||
1779 | void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent& WXUNUSED(event) ) | |
1780 | { | |
1781 | wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()")); | |
1782 | } | |
1783 | ||
1784 | void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent& event ) | |
1785 | { | |
1786 | wxPGProperty* p = event.GetProperty(); | |
1787 | wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"), | |
1788 | p->GetName().c_str(), | |
1789 | p->GetDisplayedString().c_str()); | |
1790 | } | |
1791 | ||
1792 | void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent& event ) | |
1793 | { | |
1794 | wxPGProperty* p = event.GetProperty(); | |
1795 | wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"), | |
1796 | p->GetName().c_str(), | |
1797 | event.GetValue().GetString().c_str()); | |
1798 | } | |
1799 | ||
1800 | void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent& WXUNUSED(event) ) | |
1801 | { | |
1802 | wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()")); | |
1803 | } | |
1804 | ||
1805 | ||
1806 | class wxPGKeyHandler : public wxEvtHandler | |
1807 | { | |
1808 | public: | |
1809 | ||
1810 | void OnKeyEvent( wxKeyEvent& event ) | |
1811 | { | |
1812 | wxMessageBox(wxString::Format(wxT("%i"),event.GetKeyCode())); | |
1813 | event.Skip(); | |
1814 | } | |
1815 | private: | |
1816 | DECLARE_EVENT_TABLE() | |
1817 | }; | |
1818 | ||
1819 | BEGIN_EVENT_TABLE(wxPGKeyHandler,wxEvtHandler) | |
1820 | EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent ) | |
1821 | END_EVENT_TABLE() | |
1822 | ||
1823 | ||
1824 | // ----------------------------------------------------------------------- | |
1825 | ||
1826 | void FormMain::InitPanel() | |
1827 | { | |
1828 | if ( m_panel ) | |
1829 | m_panel->Destroy(); | |
1830 | ||
1831 | wxWindow* panel = new wxPanel(this, wxID_ANY, | |
1832 | wxPoint(0, 0), wxSize(400, 400), | |
1833 | wxTAB_TRAVERSAL); | |
1834 | m_panel = panel; | |
1835 | ||
1836 | // Column | |
1837 | wxBoxSizer* topSizer = new wxBoxSizer ( wxVERTICAL ); | |
1838 | ||
1839 | m_topSizer = topSizer; | |
1840 | } | |
1841 | ||
1842 | void FormMain::FinalizePanel( bool wasCreated ) | |
1843 | { | |
1844 | // Button for tab traversal testing | |
1845 | m_topSizer->Add( new wxButton(m_panel, wxID_ANY, | |
1846 | wxS("Should be able to move here with Tab")), | |
1847 | 0, wxEXPAND ); | |
1848 | ||
1849 | m_panel->SetSizer( m_topSizer ); | |
1850 | m_topSizer->SetSizeHints( m_panel ); | |
1851 | ||
1852 | wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL ); | |
1853 | panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE ); | |
1854 | ||
1855 | SetSizer( panelSizer ); | |
1856 | panelSizer->SetSizeHints( this ); | |
1857 | ||
1858 | if ( wasCreated ) | |
1859 | FinalizeFramePosition(); | |
1860 | } | |
1861 | ||
1862 | void FormMain::PopulateGrid() | |
1863 | { | |
1864 | wxPropertyGridManager* pgman = m_pPropGridManager; | |
1865 | pgman->AddPage(wxT("Standard Items")); | |
1866 | ||
1867 | PopulateWithStandardItems(); | |
1868 | ||
1869 | pgman->AddPage(wxT("wxWidgets Library Config")); | |
1870 | ||
1871 | PopulateWithLibraryConfig(); | |
1872 | ||
1873 | wxPropertyGridPage* myPage = new wxMyPropertyGridPage(); | |
1874 | myPage->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL, 12345678 ) ); | |
1875 | ||
1876 | // Use wxMyPropertyGridPage (see above) to test the | |
1877 | // custom wxPropertyGridPage feature. | |
1878 | pgman->AddPage(wxT("Examples"),wxNullBitmap,myPage); | |
1879 | ||
1880 | PopulateWithExamples(); | |
1881 | } | |
1882 | ||
1883 | void FormMain::CreateGrid( int style, int extraStyle ) | |
1884 | { | |
1885 | // | |
1886 | // This function (re)creates the property grid in our sample | |
1887 | // | |
1888 | ||
1889 | if ( style == -1 ) | |
1890 | style = // default style | |
1891 | wxPG_BOLD_MODIFIED | | |
1892 | wxPG_SPLITTER_AUTO_CENTER | | |
1893 | wxPG_AUTO_SORT | | |
1894 | //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER | | |
1895 | //wxPG_TOOLTIPS | | |
1896 | //wxPG_HIDE_CATEGORIES | | |
1897 | //wxPG_LIMITED_EDITING | | |
1898 | wxPG_TOOLBAR | | |
1899 | wxPG_DESCRIPTION; | |
1900 | ||
1901 | if ( extraStyle == -1 ) | |
1902 | // default extra style | |
1903 | extraStyle = wxPG_EX_MODE_BUTTONS | | |
1904 | wxPG_EX_MULTIPLE_SELECTION; | |
1905 | //| wxPG_EX_AUTO_UNSPECIFIED_VALUES | |
1906 | //| wxPG_EX_GREY_LABEL_WHEN_DISABLED | |
1907 | //| wxPG_EX_NATIVE_DOUBLE_BUFFERING | |
1908 | //| wxPG_EX_HELP_AS_TOOLTIPS | |
1909 | ||
1910 | bool wasCreated = m_panel ? false : true; | |
1911 | ||
1912 | InitPanel(); | |
1913 | ||
1914 | // | |
1915 | // This shows how to combine two static choice descriptors | |
1916 | m_combinedFlags.Add( _fs_windowstyle_labels, _fs_windowstyle_values ); | |
1917 | m_combinedFlags.Add( _fs_framestyle_labels, _fs_framestyle_values ); | |
1918 | ||
1919 | wxPropertyGridManager* pgman = m_pPropGridManager = | |
1920 | new wxPropertyGridManager(m_panel, | |
1921 | // Don't change this into wxID_ANY in the sample, or the | |
1922 | // event handling will obviously be broken. | |
1923 | PGID, /*wxID_ANY*/ | |
1924 | wxDefaultPosition, | |
1925 | wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid. | |
1926 | // But calling SetInitialSize in manager changes the code | |
1927 | // order to the grid gets created immediately, before SetExtraStyle | |
1928 | // is called. | |
1929 | style ); | |
1930 | ||
1931 | m_propGrid = pgman->GetGrid(); | |
1932 | ||
1933 | pgman->SetExtraStyle(extraStyle); | |
1934 | ||
1935 | // This is the default validation failure behavior | |
1936 | m_pPropGridManager->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL | | |
1937 | wxPG_VFB_SHOW_MESSAGEBOX ); | |
1938 | ||
1939 | m_pPropGridManager->GetGrid()->SetVerticalSpacing( 2 ); | |
1940 | ||
1941 | // | |
1942 | // Set somewhat different unspecified value appearance | |
1943 | wxPGCell cell; | |
1944 | cell.SetText("Unspecified"); | |
1945 | cell.SetFgCol(*wxLIGHT_GREY); | |
1946 | m_propGrid->SetUnspecifiedValueAppearance(cell); | |
1947 | ||
1948 | PopulateGrid(); | |
1949 | ||
1950 | // Change some attributes in all properties | |
1951 | //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true); | |
1952 | //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true); | |
1953 | ||
1954 | //m_pPropGridManager->SetSplitterLeft(true); | |
1955 | //m_pPropGridManager->SetSplitterPosition(137); | |
1956 | ||
1957 | /* | |
1958 | // This would setup event handling without event table entries | |
1959 | Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED, | |
1960 | wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) ); | |
1961 | Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED, | |
1962 | wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) ); | |
1963 | */ | |
1964 | ||
1965 | m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND ); | |
1966 | ||
1967 | FinalizePanel(wasCreated); | |
1968 | } | |
1969 | ||
1970 | // ----------------------------------------------------------------------- | |
1971 | ||
1972 | FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size) : | |
1973 | wxFrame((wxFrame *)NULL, -1, title, pos, size, | |
1974 | (wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCAPTION| | |
1975 | wxTAB_TRAVERSAL|wxCLOSE_BOX|wxNO_FULL_REPAINT_ON_RESIZE) ) | |
1976 | { | |
1977 | SetIcon(wxICON(sample)); | |
1978 | ||
1979 | m_propGrid = NULL; | |
1980 | m_panel = NULL; | |
1981 | ||
1982 | #ifdef __WXMAC__ | |
1983 | // we need this in order to allow the about menu relocation, since ABOUT is | |
1984 | // not the default id of the about menu | |
1985 | wxApp::s_macAboutMenuItemId = ID_ABOUT; | |
1986 | #endif | |
1987 | ||
1988 | #if wxUSE_IMAGE | |
1989 | // This is here to really test the wxImageFileProperty. | |
1990 | wxInitAllImageHandlers(); | |
1991 | #endif | |
1992 | ||
1993 | // Register all editors (SpinCtrl etc.) | |
1994 | m_pPropGridManager->RegisterAdditionalEditors(); | |
1995 | ||
1996 | // Register our sample custom editors | |
1997 | m_pSampleMultiButtonEditor = | |
1998 | wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor()); | |
1999 | ||
2000 | CreateGrid( // style | |
2001 | wxPG_BOLD_MODIFIED | | |
2002 | wxPG_SPLITTER_AUTO_CENTER | | |
2003 | wxPG_AUTO_SORT | | |
2004 | //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER | | |
2005 | //wxPG_TOOLTIPS | | |
2006 | //wxPG_HIDE_CATEGORIES | | |
2007 | //wxPG_LIMITED_EDITING | | |
2008 | wxPG_TOOLBAR | | |
2009 | wxPG_DESCRIPTION, | |
2010 | // extra style | |
2011 | wxPG_EX_MODE_BUTTONS | | |
2012 | wxPG_EX_MULTIPLE_SELECTION | |
2013 | //| wxPG_EX_AUTO_UNSPECIFIED_VALUES | |
2014 | //| wxPG_EX_GREY_LABEL_WHEN_DISABLED | |
2015 | //| wxPG_EX_NATIVE_DOUBLE_BUFFERING | |
2016 | //| wxPG_EX_HELP_AS_TOOLTIPS | |
2017 | ); | |
2018 | ||
2019 | // | |
2020 | // Create menubar | |
2021 | wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF); | |
2022 | wxMenu *menuTry = new wxMenu; | |
2023 | wxMenu *menuTools1 = new wxMenu; | |
2024 | wxMenu *menuTools2 = new wxMenu; | |
2025 | wxMenu *menuHelp = new wxMenu; | |
2026 | ||
2027 | menuHelp->Append(ID_ABOUT, wxT("&About..."), wxT("Show about dialog") ); | |
2028 | ||
2029 | menuTools1->Append(ID_APPENDPROP, wxT("Append New Property") ); | |
2030 | menuTools1->Append(ID_APPENDCAT, wxT("Append New Category\tCtrl-S") ); | |
2031 | menuTools1->AppendSeparator(); | |
2032 | menuTools1->Append(ID_INSERTPROP, wxT("Insert New Property\tCtrl-Q") ); | |
2033 | menuTools1->Append(ID_INSERTCAT, wxT("Insert New Category\tCtrl-W") ); | |
2034 | menuTools1->AppendSeparator(); | |
2035 | menuTools1->Append(ID_DELETE, wxT("Delete Selected") ); | |
2036 | menuTools1->Append(ID_DELETER, wxT("Delete Random") ); | |
2037 | menuTools1->Append(ID_DELETEALL, wxT("Delete All") ); | |
2038 | menuTools1->AppendSeparator(); | |
2039 | menuTools1->Append(ID_SETBGCOLOUR, wxT("Set Bg Colour") ); | |
2040 | menuTools1->Append(ID_SETBGCOLOURRECUR, wxT("Set Bg Colour (Recursively)") ); | |
2041 | menuTools1->Append(ID_UNSPECIFY, "Set Value to Unspecified"); | |
2042 | menuTools1->AppendSeparator(); | |
2043 | m_itemEnable = menuTools1->Append(ID_ENABLE, wxT("Enable"), | |
2044 | wxT("Toggles item's enabled state.") ); | |
2045 | m_itemEnable->Enable( FALSE ); | |
2046 | menuTools1->Append(ID_HIDE, "Hide", "Hides a property" ); | |
2047 | menuTools1->Append(ID_SETREADONLY, "Set as Read-Only", | |
2048 | "Set property as read-only" ); | |
2049 | ||
2050 | menuTools2->Append(ID_ITERATE1, wxT("Iterate Over Properties") ); | |
2051 | menuTools2->Append(ID_ITERATE2, wxT("Iterate Over Visible Items") ); | |
2052 | menuTools2->Append(ID_ITERATE3, wxT("Reverse Iterate Over Properties") ); | |
2053 | menuTools2->Append(ID_ITERATE4, wxT("Iterate Over Categories") ); | |
2054 | menuTools2->AppendSeparator(); | |
2055 | menuTools2->Append(ID_ONEXTENDEDKEYNAV, "Extend Keyboard Navigation", | |
2056 | "This will set Enter to navigate to next property, " | |
2057 | "and allows arrow keys to navigate even when in " | |
2058 | "editor control."); | |
2059 | menuTools2->AppendSeparator(); | |
2060 | menuTools2->Append(ID_SETPROPERTYVALUE, wxT("Set Property Value") ); | |
2061 | menuTools2->Append(ID_CLEARMODIF, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") ); | |
2062 | menuTools2->AppendSeparator(); | |
2063 | m_itemFreeze = menuTools2->AppendCheckItem(ID_FREEZE, wxT("Freeze"), | |
2064 | wxT("Disables painting, auto-sorting, etc.") ); | |
2065 | menuTools2->AppendSeparator(); | |
2066 | menuTools2->Append(ID_DUMPLIST, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") ); | |
2067 | menuTools2->AppendSeparator(); | |
2068 | menuTools2->Append(ID_GETVALUES, wxT("Get Property Values"), wxT("Stores all property values.") ); | |
2069 | menuTools2->Append(ID_SETVALUES, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") ); | |
2070 | menuTools2->Append(ID_SETVALUES2, wxT("Set Property Values 2"), wxT("Adds property values that should not initially be as items (so new items are created).") ); | |
2071 | menuTools2->AppendSeparator(); | |
2072 | menuTools2->Append(ID_SAVESTATE, wxT("Save Editable State") ); | |
2073 | menuTools2->Append(ID_RESTORESTATE, wxT("Restore Editable State") ); | |
2074 | menuTools2->AppendSeparator(); | |
2075 | menuTools2->Append(ID_ENABLECOMMONVALUES, wxT("Enable Common Value"), | |
2076 | wxT("Enable values that are common to all properties, for selected property.")); | |
2077 | menuTools2->AppendSeparator(); | |
2078 | menuTools2->Append(ID_COLLAPSE, wxT("Collapse Selected") ); | |
2079 | menuTools2->Append(ID_COLLAPSEALL, wxT("Collapse All") ); | |
2080 | menuTools2->AppendSeparator(); | |
2081 | menuTools2->Append(ID_INSERTPAGE, wxT("Add Page") ); | |
2082 | menuTools2->Append(ID_REMOVEPAGE, wxT("Remove Page") ); | |
2083 | menuTools2->AppendSeparator(); | |
2084 | menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") ); | |
2085 | m_itemVetoDragging = | |
2086 | menuTools2->AppendCheckItem(ID_VETOCOLDRAG, | |
2087 | "Veto Column Dragging"); | |
2088 | menuTools2->AppendSeparator(); | |
2089 | menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") ); | |
2090 | menuTools2->AppendSeparator(); | |
2091 | menuTools2->Append(ID_TESTINSERTCHOICE, wxT("Test InsertPropertyChoice") ); | |
2092 | menuTools2->Append(ID_TESTDELETECHOICE, wxT("Test DeletePropertyChoice") ); | |
2093 | menuTools2->AppendSeparator(); | |
2094 | menuTools2->Append(ID_SETSPINCTRLEDITOR, wxT("Use SpinCtrl Editor") ); | |
2095 | menuTools2->Append(ID_TESTREPLACE, wxT("Test ReplaceProperty") ); | |
2096 | ||
2097 | menuTry->Append(ID_SELECTSTYLE, wxT("Set Window Style"), | |
2098 | wxT("Select window style flags used by the grid.")); | |
2099 | menuTry->Append(ID_ENABLELABELEDITING, "Enable label editing", | |
2100 | "This calls wxPropertyGrid::MakeColumnEditable(0)"); | |
2101 | menuTry->AppendCheckItem(ID_SHOWHEADER, | |
2102 | "Enable header", | |
2103 | "This calls wxPropertyGridManager::ShowHeader()"); | |
2104 | menuTry->AppendSeparator(); | |
2105 | menuTry->AppendRadioItem( ID_COLOURSCHEME1, wxT("Standard Colour Scheme") ); | |
2106 | menuTry->AppendRadioItem( ID_COLOURSCHEME2, wxT("White Colour Scheme") ); | |
2107 | menuTry->AppendRadioItem( ID_COLOURSCHEME3, wxT(".NET Colour Scheme") ); | |
2108 | menuTry->AppendRadioItem( ID_COLOURSCHEME4, wxT("Cream Colour Scheme") ); | |
2109 | menuTry->AppendSeparator(); | |
2110 | m_itemCatColours = menuTry->AppendCheckItem(ID_CATCOLOURS, wxT("Category Specific Colours"), | |
2111 | wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") ); | |
2112 | menuTry->AppendSeparator(); | |
2113 | menuTry->AppendCheckItem(ID_STATICLAYOUT, wxT("Static Layout"), | |
2114 | wxT("Switches between user-modifiedable and static layouts.") ); | |
2115 | menuTry->Append(ID_SETCOLUMNS, wxT("Set Number of Columns") ); | |
2116 | menuTry->AppendSeparator(); | |
2117 | menuTry->Append(ID_TESTXRC, wxT("Display XRC sample") ); | |
2118 | menuTry->AppendSeparator(); | |
2119 | menuTry->Append(ID_RUNTESTFULL, wxT("Run Tests (full)") ); | |
2120 | menuTry->Append(ID_RUNTESTPARTIAL, wxT("Run Tests (fast)") ); | |
2121 | ||
2122 | menuFile->Append(ID_RUNMINIMAL, wxT("Run Minimal Sample") ); | |
2123 | menuFile->AppendSeparator(); | |
2124 | menuFile->Append(ID_QUIT, wxT("E&xit\tAlt-X"), wxT("Quit this program") ); | |
2125 | ||
2126 | // Now append the freshly created menu to the menu bar... | |
2127 | wxMenuBar *menuBar = new wxMenuBar(); | |
2128 | menuBar->Append(menuFile, wxT("&File") ); | |
2129 | menuBar->Append(menuTry, wxT("&Try These!") ); | |
2130 | menuBar->Append(menuTools1, wxT("&Basic") ); | |
2131 | menuBar->Append(menuTools2, wxT("&Advanced") ); | |
2132 | menuBar->Append(menuHelp, wxT("&Help") ); | |
2133 | ||
2134 | // ... and attach this menu bar to the frame | |
2135 | SetMenuBar(menuBar); | |
2136 | ||
2137 | #if wxUSE_STATUSBAR | |
2138 | // create a status bar | |
2139 | CreateStatusBar(1); | |
2140 | SetStatusText(wxEmptyString); | |
2141 | #endif // wxUSE_STATUSBAR | |
2142 | ||
2143 | FinalizeFramePosition(); | |
2144 | ||
2145 | #if wxUSE_LOGWINDOW | |
2146 | // Create log window | |
2147 | m_logWindow = new wxLogWindow(this, "Log Messages", false); | |
2148 | m_logWindow->GetFrame()->Move(GetPosition().x + GetSize().x + 10, | |
2149 | GetPosition().y); | |
2150 | m_logWindow->Show(); | |
2151 | #endif | |
2152 | } | |
2153 | ||
2154 | void FormMain::FinalizeFramePosition() | |
2155 | { | |
2156 | wxSize frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X)/10)*4, | |
2157 | (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)/10)*8); | |
2158 | ||
2159 | if ( frameSize.x > 500 ) | |
2160 | frameSize.x = 500; | |
2161 | ||
2162 | SetSize(frameSize); | |
2163 | ||
2164 | Centre(); | |
2165 | } | |
2166 | ||
2167 | // | |
2168 | // Normally, wxPropertyGrid does not check whether item with identical | |
2169 | // label already exists. However, since in this sample we use labels for | |
2170 | // identifying properties, we have to be sure not to generate identical | |
2171 | // labels. | |
2172 | // | |
2173 | void GenerateUniquePropertyLabel( wxPropertyGridManager* pg, wxString& baselabel ) | |
2174 | { | |
2175 | int count = -1; | |
2176 | wxString newlabel; | |
2177 | ||
2178 | if ( pg->GetPropertyByLabel( baselabel ) ) | |
2179 | { | |
2180 | for (;;) | |
2181 | { | |
2182 | count++; | |
2183 | newlabel.Printf(wxT("%s%i"),baselabel.c_str(),count); | |
2184 | if ( !pg->GetPropertyByLabel( newlabel ) ) break; | |
2185 | } | |
2186 | } | |
2187 | ||
2188 | if ( count >= 0 ) | |
2189 | { | |
2190 | baselabel = newlabel; | |
2191 | } | |
2192 | } | |
2193 | ||
2194 | // ----------------------------------------------------------------------- | |
2195 | ||
2196 | void FormMain::OnInsertPropClick( wxCommandEvent& WXUNUSED(event) ) | |
2197 | { | |
2198 | wxString propLabel; | |
2199 | ||
2200 | if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() ) | |
2201 | { | |
2202 | wxMessageBox(wxT("No items to relate - first add some with Append.")); | |
2203 | return; | |
2204 | } | |
2205 | ||
2206 | wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection(); | |
2207 | if ( !id ) | |
2208 | { | |
2209 | wxMessageBox(wxT("First select a property - new one will be inserted right before that.")); | |
2210 | return; | |
2211 | } | |
2212 | if ( propLabel.Len() < 1 ) propLabel = wxT("Property"); | |
2213 | ||
2214 | GenerateUniquePropertyLabel( m_pPropGridManager, propLabel ); | |
2215 | ||
2216 | m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id), | |
2217 | id->GetIndexInParent(), | |
2218 | new wxStringProperty(propLabel) ); | |
2219 | ||
2220 | } | |
2221 | ||
2222 | // ----------------------------------------------------------------------- | |
2223 | ||
2224 | void FormMain::OnAppendPropClick( wxCommandEvent& WXUNUSED(event) ) | |
2225 | { | |
2226 | wxString propLabel; | |
2227 | ||
2228 | if ( propLabel.Len() < 1 ) propLabel = wxT("Property"); | |
2229 | ||
2230 | GenerateUniquePropertyLabel( m_pPropGridManager, propLabel ); | |
2231 | ||
2232 | m_pPropGridManager->Append( new wxStringProperty(propLabel) ); | |
2233 | ||
2234 | m_pPropGridManager->Refresh(); | |
2235 | } | |
2236 | ||
2237 | // ----------------------------------------------------------------------- | |
2238 | ||
2239 | void FormMain::OnClearClick( wxCommandEvent& WXUNUSED(event) ) | |
2240 | { | |
2241 | m_pPropGridManager->GetGrid()->Clear(); | |
2242 | } | |
2243 | ||
2244 | // ----------------------------------------------------------------------- | |
2245 | ||
2246 | void FormMain::OnAppendCatClick( wxCommandEvent& WXUNUSED(event) ) | |
2247 | { | |
2248 | wxString propLabel; | |
2249 | ||
2250 | if ( propLabel.Len() < 1 ) propLabel = wxT("Category"); | |
2251 | ||
2252 | GenerateUniquePropertyLabel( m_pPropGridManager, propLabel ); | |
2253 | ||
2254 | m_pPropGridManager->Append( new wxPropertyCategory (propLabel) ); | |
2255 | ||
2256 | m_pPropGridManager->Refresh(); | |
2257 | ||
2258 | } | |
2259 | ||
2260 | // ----------------------------------------------------------------------- | |
2261 | ||
2262 | void FormMain::OnInsertCatClick( wxCommandEvent& WXUNUSED(event) ) | |
2263 | { | |
2264 | wxString propLabel; | |
2265 | ||
2266 | if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() ) | |
2267 | { | |
2268 | wxMessageBox(wxT("No items to relate - first add some with Append.")); | |
2269 | return; | |
2270 | } | |
2271 | ||
2272 | wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection(); | |
2273 | if ( !id ) | |
2274 | { | |
2275 | wxMessageBox(wxT("First select a property - new one will be inserted right before that.")); | |
2276 | return; | |
2277 | } | |
2278 | ||
2279 | if ( propLabel.Len() < 1 ) propLabel = wxT("Category"); | |
2280 | ||
2281 | GenerateUniquePropertyLabel( m_pPropGridManager, propLabel ); | |
2282 | ||
2283 | m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id), | |
2284 | id->GetIndexInParent(), | |
2285 | new wxPropertyCategory (propLabel) ); | |
2286 | } | |
2287 | ||
2288 | // ----------------------------------------------------------------------- | |
2289 | ||
2290 | void FormMain::OnDelPropClick( wxCommandEvent& WXUNUSED(event) ) | |
2291 | { | |
2292 | wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection(); | |
2293 | if ( !id ) | |
2294 | { | |
2295 | wxMessageBox(wxT("First select a property.")); | |
2296 | return; | |
2297 | } | |
2298 | ||
2299 | m_pPropGridManager->DeleteProperty( id ); | |
2300 | } | |
2301 | ||
2302 | // ----------------------------------------------------------------------- | |
2303 | ||
2304 | void FormMain::OnDelPropRClick( wxCommandEvent& WXUNUSED(event) ) | |
2305 | { | |
2306 | // Delete random property | |
2307 | wxPGProperty* p = m_pPropGridManager->GetGrid()->GetRoot(); | |
2308 | ||
2309 | for (;;) | |
2310 | { | |
2311 | if ( !p->IsCategory() ) | |
2312 | { | |
2313 | m_pPropGridManager->DeleteProperty( p ); | |
2314 | break; | |
2315 | } | |
2316 | ||
2317 | if ( !p->GetChildCount() ) | |
2318 | break; | |
2319 | ||
2320 | int n = rand() % ((int)p->GetChildCount()); | |
2321 | ||
2322 | p = p->Item(n); | |
2323 | } | |
2324 | } | |
2325 | ||
2326 | // ----------------------------------------------------------------------- | |
2327 | ||
2328 | void FormMain::OnContextMenu( wxContextMenuEvent& event ) | |
2329 | { | |
2330 | wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"), | |
2331 | event.GetPosition().x,event.GetPosition().y); | |
2332 | ||
2333 | wxUnusedVar(event); | |
2334 | ||
2335 | //event.Skip(); | |
2336 | } | |
2337 | ||
2338 | // ----------------------------------------------------------------------- | |
2339 | ||
2340 | void FormMain::OnCloseClick( wxCommandEvent& WXUNUSED(event) ) | |
2341 | { | |
2342 | /*#ifdef __WXDEBUG__ | |
2343 | m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets(); | |
2344 | wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample.")); | |
2345 | #endif*/ | |
2346 | ||
2347 | Close(false); | |
2348 | } | |
2349 | ||
2350 | // ----------------------------------------------------------------------- | |
2351 | ||
2352 | int IterateMessage( wxPGProperty* prop ) | |
2353 | { | |
2354 | wxString s; | |
2355 | ||
2356 | s.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop->GetLabel().c_str(), | |
2357 | prop->GetClassInfo()->GetClassName(), prop->GetValueType().c_str() ); | |
2358 | ||
2359 | return wxMessageBox( s, wxT("Iterating... (press CANCEL to end)"), wxOK|wxCANCEL ); | |
2360 | } | |
2361 | ||
2362 | // ----------------------------------------------------------------------- | |
2363 | ||
2364 | void FormMain::OnIterate1Click( wxCommandEvent& WXUNUSED(event) ) | |
2365 | { | |
2366 | wxPropertyGridIterator it; | |
2367 | ||
2368 | for ( it = m_pPropGridManager->GetCurrentPage()-> | |
2369 | GetIterator(); | |
2370 | !it.AtEnd(); | |
2371 | it++ ) | |
2372 | { | |
2373 | wxPGProperty* p = *it; | |
2374 | int res = IterateMessage( p ); | |
2375 | if ( res == wxCANCEL ) break; | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | // ----------------------------------------------------------------------- | |
2380 | ||
2381 | void FormMain::OnIterate2Click( wxCommandEvent& WXUNUSED(event) ) | |
2382 | { | |
2383 | wxPropertyGridIterator it; | |
2384 | ||
2385 | for ( it = m_pPropGridManager->GetCurrentPage()-> | |
2386 | GetIterator( wxPG_ITERATE_VISIBLE ); | |
2387 | !it.AtEnd(); | |
2388 | it++ ) | |
2389 | { | |
2390 | wxPGProperty* p = *it; | |
2391 | ||
2392 | int res = IterateMessage( p ); | |
2393 | if ( res == wxCANCEL ) break; | |
2394 | } | |
2395 | } | |
2396 | ||
2397 | // ----------------------------------------------------------------------- | |
2398 | ||
2399 | void FormMain::OnIterate3Click( wxCommandEvent& WXUNUSED(event) ) | |
2400 | { | |
2401 | // iterate over items in reverse order | |
2402 | wxPropertyGridIterator it; | |
2403 | ||
2404 | for ( it = m_pPropGridManager->GetCurrentPage()-> | |
2405 | GetIterator( wxPG_ITERATE_DEFAULT, wxBOTTOM ); | |
2406 | !it.AtEnd(); | |
2407 | it-- ) | |
2408 | { | |
2409 | wxPGProperty* p = *it; | |
2410 | ||
2411 | int res = IterateMessage( p ); | |
2412 | if ( res == wxCANCEL ) break; | |
2413 | } | |
2414 | } | |
2415 | ||
2416 | // ----------------------------------------------------------------------- | |
2417 | ||
2418 | void FormMain::OnIterate4Click( wxCommandEvent& WXUNUSED(event) ) | |
2419 | { | |
2420 | wxPropertyGridIterator it; | |
2421 | ||
2422 | for ( it = m_pPropGridManager->GetCurrentPage()-> | |
2423 | GetIterator( wxPG_ITERATE_CATEGORIES ); | |
2424 | !it.AtEnd(); | |
2425 | it++ ) | |
2426 | { | |
2427 | wxPGProperty* p = *it; | |
2428 | ||
2429 | int res = IterateMessage( p ); | |
2430 | if ( res == wxCANCEL ) break; | |
2431 | } | |
2432 | } | |
2433 | ||
2434 | // ----------------------------------------------------------------------- | |
2435 | ||
2436 | void FormMain::OnExtendedKeyNav( wxCommandEvent& WXUNUSED(event) ) | |
2437 | { | |
2438 | // Use AddActionTrigger() and DedicateKey() to set up Enter, | |
2439 | // Up, and Down keys for navigating between properties. | |
2440 | wxPropertyGrid* propGrid = m_pPropGridManager->GetGrid(); | |
2441 | ||
2442 | propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY, | |
2443 | WXK_RETURN); | |
2444 | propGrid->DedicateKey(WXK_RETURN); | |
2445 | ||
2446 | // Up and Down keys are alredy associated with navigation, | |
2447 | // but we must also prevent them from being eaten by | |
2448 | // editor controls. | |
2449 | propGrid->DedicateKey(WXK_UP); | |
2450 | propGrid->DedicateKey(WXK_DOWN); | |
2451 | } | |
2452 | ||
2453 | // ----------------------------------------------------------------------- | |
2454 | ||
2455 | void FormMain::OnFitColumnsClick( wxCommandEvent& WXUNUSED(event) ) | |
2456 | { | |
2457 | wxPropertyGridPage* page = m_pPropGridManager->GetCurrentPage(); | |
2458 | ||
2459 | // Remove auto-centering | |
2460 | m_pPropGridManager->SetWindowStyle( m_pPropGridManager->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER); | |
2461 | ||
2462 | // Grow manager size just prior fit - otherwise | |
2463 | // column information may be lost. | |
2464 | wxSize oldGridSize = m_pPropGridManager->GetGrid()->GetClientSize(); | |
2465 | wxSize oldFullSize = GetSize(); | |
2466 | SetSize(1000, oldFullSize.y); | |
2467 | ||
2468 | wxSize newSz = page->FitColumns(); | |
2469 | ||
2470 | int dx = oldFullSize.x - oldGridSize.x; | |
2471 | int dy = oldFullSize.y - oldGridSize.y; | |
2472 | ||
2473 | newSz.x += dx; | |
2474 | newSz.y += dy; | |
2475 | ||
2476 | SetSize(newSz); | |
2477 | } | |
2478 | ||
2479 | // ----------------------------------------------------------------------- | |
2480 | ||
2481 | void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent& WXUNUSED(event) ) | |
2482 | { | |
2483 | wxPGProperty* p = m_pPropGridManager->GetPropertyByName(wxT("Window Styles")); | |
2484 | ||
2485 | wxPGChoices newChoices; | |
2486 | ||
2487 | newChoices.Add(wxT("Fast"),0x1); | |
2488 | newChoices.Add(wxT("Powerful"),0x2); | |
2489 | newChoices.Add(wxT("Safe"),0x4); | |
2490 | newChoices.Add(wxT("Sleek"),0x8); | |
2491 | ||
2492 | p->SetChoices(newChoices); | |
2493 | } | |
2494 | ||
2495 | // ----------------------------------------------------------------------- | |
2496 | ||
2497 | void FormMain::OnEnableDisable( wxCommandEvent& ) | |
2498 | { | |
2499 | wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection(); | |
2500 | if ( !id ) | |
2501 | { | |
2502 | wxMessageBox(wxT("First select a property.")); | |
2503 | return; | |
2504 | } | |
2505 | ||
2506 | if ( m_pPropGridManager->IsPropertyEnabled( id ) ) | |
2507 | { | |
2508 | m_pPropGridManager->DisableProperty ( id ); | |
2509 | m_itemEnable->SetItemLabel( wxT("Enable") ); | |
2510 | } | |
2511 | else | |
2512 | { | |
2513 | m_pPropGridManager->EnableProperty ( id ); | |
2514 | m_itemEnable->SetItemLabel( wxT("Disable") ); | |
2515 | } | |
2516 | } | |
2517 | ||
2518 | // ----------------------------------------------------------------------- | |
2519 | ||
2520 | void FormMain::OnSetReadOnly( wxCommandEvent& WXUNUSED(event) ) | |
2521 | { | |
2522 | wxPGProperty* p = m_pPropGridManager->GetGrid()->GetSelection(); | |
2523 | if ( !p ) | |
2524 | { | |
2525 | wxMessageBox(wxT("First select a property.")); | |
2526 | return; | |
2527 | } | |
2528 | m_pPropGridManager->SetPropertyReadOnly(p); | |
2529 | } | |
2530 | ||
2531 | // ----------------------------------------------------------------------- | |
2532 | ||
2533 | void FormMain::OnHide( wxCommandEvent& WXUNUSED(event) ) | |
2534 | { | |
2535 | wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection(); | |
2536 | if ( !id ) | |
2537 | { | |
2538 | wxMessageBox(wxT("First select a property.")); | |
2539 | return; | |
2540 | } | |
2541 | ||
2542 | m_pPropGridManager->HideProperty( id, true ); | |
2543 | } | |
2544 | ||
2545 | // ----------------------------------------------------------------------- | |
2546 | ||
2547 | #include "wx/colordlg.h" | |
2548 | ||
2549 | void | |
2550 | FormMain::OnSetBackgroundColour( wxCommandEvent& event ) | |
2551 | { | |
2552 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2553 | wxPGProperty* prop = pg->GetSelection(); | |
2554 | if ( !prop ) | |
2555 | { | |
2556 | wxMessageBox(wxT("First select a property.")); | |
2557 | return; | |
2558 | } | |
2559 | ||
2560 | wxColour col = ::wxGetColourFromUser(this, *wxWHITE, "Choose colour"); | |
2561 | ||
2562 | if ( col.IsOk() ) | |
2563 | { | |
2564 | bool recursively = (event.GetId()==ID_SETBGCOLOURRECUR) ? true : false; | |
2565 | pg->SetPropertyBackgroundColour(prop, col, recursively); | |
2566 | } | |
2567 | } | |
2568 | ||
2569 | // ----------------------------------------------------------------------- | |
2570 | ||
2571 | void FormMain::OnInsertPage( wxCommandEvent& WXUNUSED(event) ) | |
2572 | { | |
2573 | m_pPropGridManager->AddPage(wxT("New Page")); | |
2574 | } | |
2575 | ||
2576 | // ----------------------------------------------------------------------- | |
2577 | ||
2578 | void FormMain::OnRemovePage( wxCommandEvent& WXUNUSED(event) ) | |
2579 | { | |
2580 | m_pPropGridManager->RemovePage(m_pPropGridManager->GetSelectedPage()); | |
2581 | } | |
2582 | ||
2583 | // ----------------------------------------------------------------------- | |
2584 | ||
2585 | void FormMain::OnSaveState( wxCommandEvent& WXUNUSED(event) ) | |
2586 | { | |
2587 | m_savedState = m_pPropGridManager->SaveEditableState(); | |
2588 | wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState.c_str()); | |
2589 | } | |
2590 | ||
2591 | // ----------------------------------------------------------------------- | |
2592 | ||
2593 | void FormMain::OnRestoreState( wxCommandEvent& WXUNUSED(event) ) | |
2594 | { | |
2595 | m_pPropGridManager->RestoreEditableState(m_savedState); | |
2596 | } | |
2597 | ||
2598 | // ----------------------------------------------------------------------- | |
2599 | ||
2600 | void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent& WXUNUSED(event) ) | |
2601 | { | |
2602 | #if wxUSE_SPINBTN | |
2603 | wxPGProperty* pgId = m_pPropGridManager->GetSelection(); | |
2604 | if ( pgId ) | |
2605 | m_pPropGridManager->SetPropertyEditor( pgId, wxPGEditor_SpinCtrl ); | |
2606 | else | |
2607 | wxMessageBox(wxT("First select a property")); | |
2608 | #endif | |
2609 | } | |
2610 | ||
2611 | // ----------------------------------------------------------------------- | |
2612 | ||
2613 | void FormMain::OnTestReplaceClick( wxCommandEvent& WXUNUSED(event) ) | |
2614 | { | |
2615 | wxPGProperty* pgId = m_pPropGridManager->GetSelection(); | |
2616 | if ( pgId ) | |
2617 | { | |
2618 | wxPGChoices choices; | |
2619 | choices.Add(wxT("Flag 0"),0x0001); | |
2620 | choices.Add(wxT("Flag 1"),0x0002); | |
2621 | choices.Add(wxT("Flag 2"),0x0004); | |
2622 | choices.Add(wxT("Flag 3"),0x0008); | |
2623 | wxPGProperty* newId = m_pPropGridManager->ReplaceProperty( pgId, | |
2624 | new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL, choices, 0x0003) ); | |
2625 | m_pPropGridManager->SetPropertyAttribute( newId, | |
2626 | wxPG_BOOL_USE_CHECKBOX, | |
2627 | true, | |
2628 | wxPG_RECURSE ); | |
2629 | } | |
2630 | else | |
2631 | wxMessageBox(wxT("First select a property")); | |
2632 | } | |
2633 | ||
2634 | // ----------------------------------------------------------------------- | |
2635 | ||
2636 | void FormMain::OnClearModifyStatusClick( wxCommandEvent& WXUNUSED(event) ) | |
2637 | { | |
2638 | m_pPropGridManager->ClearModifiedStatus(); | |
2639 | } | |
2640 | ||
2641 | // ----------------------------------------------------------------------- | |
2642 | ||
2643 | // Freeze check-box checked? | |
2644 | void FormMain::OnFreezeClick( wxCommandEvent& event ) | |
2645 | { | |
2646 | if ( !m_pPropGridManager ) return; | |
2647 | ||
2648 | if ( event.IsChecked() ) | |
2649 | { | |
2650 | if ( !m_pPropGridManager->IsFrozen() ) | |
2651 | { | |
2652 | m_pPropGridManager->Freeze(); | |
2653 | } | |
2654 | } | |
2655 | else | |
2656 | { | |
2657 | if ( m_pPropGridManager->IsFrozen() ) | |
2658 | { | |
2659 | m_pPropGridManager->Thaw(); | |
2660 | m_pPropGridManager->Refresh(); | |
2661 | } | |
2662 | } | |
2663 | } | |
2664 | ||
2665 | // ----------------------------------------------------------------------- | |
2666 | ||
2667 | void FormMain::OnEnableLabelEditing( wxCommandEvent& WXUNUSED(event) ) | |
2668 | { | |
2669 | m_propGrid->MakeColumnEditable(0); | |
2670 | } | |
2671 | ||
2672 | // ----------------------------------------------------------------------- | |
2673 | ||
2674 | void FormMain::OnShowHeader( wxCommandEvent& event ) | |
2675 | { | |
2676 | m_pPropGridManager->ShowHeader(event.IsChecked()); | |
2677 | m_pPropGridManager->SetColumnTitle(2, _("Units")); | |
2678 | } | |
2679 | ||
2680 | // ----------------------------------------------------------------------- | |
2681 | ||
2682 | void FormMain::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
2683 | { | |
2684 | wxString msg; | |
2685 | msg.Printf( wxT("wxPropertyGrid Sample") | |
2686 | #if wxUSE_UNICODE | |
2687 | #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8 | |
2688 | wxT(" <utf-8>") | |
2689 | #else | |
2690 | wxT(" <unicode>") | |
2691 | #endif | |
2692 | #else | |
2693 | wxT(" <ansi>") | |
2694 | #endif | |
2695 | #ifdef __WXDEBUG__ | |
2696 | wxT(" <debug>") | |
2697 | #else | |
2698 | wxT(" <release>") | |
2699 | #endif | |
2700 | wxT("\n\n") | |
2701 | wxT("Programmed by %s\n\n") | |
2702 | wxT("Using %s\n\n"), | |
2703 | wxT("Jaakko Salli"), wxVERSION_STRING | |
2704 | ); | |
2705 | ||
2706 | wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); | |
2707 | } | |
2708 | ||
2709 | // ----------------------------------------------------------------------- | |
2710 | ||
2711 | void FormMain::OnColourScheme( wxCommandEvent& event ) | |
2712 | { | |
2713 | int id = event.GetId(); | |
2714 | if ( id == ID_COLOURSCHEME1 ) | |
2715 | { | |
2716 | m_pPropGridManager->GetGrid()->ResetColours(); | |
2717 | } | |
2718 | else if ( id == ID_COLOURSCHEME2 ) | |
2719 | { | |
2720 | // white | |
2721 | wxColour my_grey_1(212,208,200); | |
2722 | wxColour my_grey_3(113,111,100); | |
2723 | m_pPropGridManager->Freeze(); | |
2724 | m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE ); | |
2725 | m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE ); | |
2726 | m_pPropGridManager->GetGrid()->SetCellBackgroundColour( *wxWHITE ); | |
2727 | m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 ); | |
2728 | m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 ); //wxColour(160,160,160) | |
2729 | m_pPropGridManager->Thaw(); | |
2730 | } | |
2731 | else if ( id == ID_COLOURSCHEME3 ) | |
2732 | { | |
2733 | // .NET | |
2734 | wxColour my_grey_1(212,208,200); | |
2735 | wxColour my_grey_2(236,233,216); | |
2736 | m_pPropGridManager->Freeze(); | |
2737 | m_pPropGridManager->GetGrid()->SetMarginColour( my_grey_1 ); | |
2738 | m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( my_grey_1 ); | |
2739 | m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 ); | |
2740 | m_pPropGridManager->Thaw(); | |
2741 | } | |
2742 | else if ( id == ID_COLOURSCHEME4 ) | |
2743 | { | |
2744 | // cream | |
2745 | ||
2746 | wxColour my_grey_1(212,208,200); | |
2747 | wxColour my_grey_2(241,239,226); | |
2748 | wxColour my_grey_3(113,111,100); | |
2749 | m_pPropGridManager->Freeze(); | |
2750 | m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE ); | |
2751 | m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE ); | |
2752 | m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 ); | |
2753 | m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 ); | |
2754 | m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 ); | |
2755 | m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 ); | |
2756 | m_pPropGridManager->Thaw(); | |
2757 | } | |
2758 | } | |
2759 | ||
2760 | // ----------------------------------------------------------------------- | |
2761 | ||
2762 | void FormMain::OnCatColours( wxCommandEvent& event ) | |
2763 | { | |
2764 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2765 | m_pPropGridManager->Freeze(); | |
2766 | ||
2767 | if ( event.IsChecked() ) | |
2768 | { | |
2769 | // Set custom colours. | |
2770 | pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false ); | |
2771 | pg->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) ); | |
2772 | pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) ); | |
2773 | pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false ); | |
2774 | pg->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) ); | |
2775 | pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) ); | |
2776 | pg->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false ); | |
2777 | pg->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) ); | |
2778 | pg->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) ); | |
2779 | pg->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) ); | |
2780 | pg->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) ); | |
2781 | } | |
2782 | else | |
2783 | { | |
2784 | // Revert to original. | |
2785 | pg->SetPropertyColoursToDefault( wxT("Appearance") ); | |
2786 | pg->SetPropertyColoursToDefault( wxT("PositionCategory") ); | |
2787 | pg->SetPropertyColoursToDefault( wxT("Environment") ); | |
2788 | pg->SetPropertyColoursToDefault( wxT("More Examples") ); | |
2789 | } | |
2790 | m_pPropGridManager->Thaw(); | |
2791 | m_pPropGridManager->Refresh(); | |
2792 | } | |
2793 | ||
2794 | // ----------------------------------------------------------------------- | |
2795 | ||
2796 | #define ADD_FLAG(FLAG) \ | |
2797 | chs.Add(wxT(#FLAG)); \ | |
2798 | vls.Add(FLAG); \ | |
2799 | if ( (flags & FLAG) == FLAG ) sel.Add(ind); \ | |
2800 | ind++; | |
2801 | ||
2802 | void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) ) | |
2803 | { | |
2804 | int style = 0; | |
2805 | int extraStyle = 0; | |
2806 | ||
2807 | { | |
2808 | wxArrayString chs; | |
2809 | wxArrayInt vls; | |
2810 | wxArrayInt sel; | |
2811 | unsigned int ind = 0; | |
2812 | int flags = m_pPropGridManager->GetWindowStyle(); | |
2813 | ADD_FLAG(wxPG_HIDE_CATEGORIES) | |
2814 | ADD_FLAG(wxPG_AUTO_SORT) | |
2815 | ADD_FLAG(wxPG_BOLD_MODIFIED) | |
2816 | ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER) | |
2817 | ADD_FLAG(wxPG_TOOLTIPS) | |
2818 | ADD_FLAG(wxPG_STATIC_SPLITTER) | |
2819 | ADD_FLAG(wxPG_HIDE_MARGIN) | |
2820 | ADD_FLAG(wxPG_LIMITED_EDITING) | |
2821 | ADD_FLAG(wxPG_TOOLBAR) | |
2822 | ADD_FLAG(wxPG_DESCRIPTION) | |
2823 | ADD_FLAG(wxPG_NO_INTERNAL_BORDER) | |
2824 | wxMultiChoiceDialog dlg( this, wxT("Select window styles to use"), | |
2825 | wxT("wxPropertyGrid Window Style"), chs ); | |
2826 | dlg.SetSelections(sel); | |
2827 | if ( dlg.ShowModal() == wxID_CANCEL ) | |
2828 | return; | |
2829 | ||
2830 | flags = 0; | |
2831 | sel = dlg.GetSelections(); | |
2832 | for ( ind = 0; ind < sel.size(); ind++ ) | |
2833 | flags |= vls[sel[ind]]; | |
2834 | ||
2835 | style = flags; | |
2836 | } | |
2837 | ||
2838 | { | |
2839 | wxArrayString chs; | |
2840 | wxArrayInt vls; | |
2841 | wxArrayInt sel; | |
2842 | unsigned int ind = 0; | |
2843 | int flags = m_pPropGridManager->GetExtraStyle(); | |
2844 | ADD_FLAG(wxPG_EX_INIT_NOCAT) | |
2845 | ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR) | |
2846 | ADD_FLAG(wxPG_EX_MODE_BUTTONS) | |
2847 | ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS) | |
2848 | ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING) | |
2849 | ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES) | |
2850 | ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES) | |
2851 | ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS) | |
2852 | ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION) | |
2853 | ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING) | |
2854 | ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER) | |
2855 | ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR) | |
2856 | wxMultiChoiceDialog dlg( this, wxT("Select extra window styles to use"), | |
2857 | wxT("wxPropertyGrid Extra Style"), chs ); | |
2858 | dlg.SetSelections(sel); | |
2859 | if ( dlg.ShowModal() == wxID_CANCEL ) | |
2860 | return; | |
2861 | ||
2862 | flags = 0; | |
2863 | sel = dlg.GetSelections(); | |
2864 | for ( ind = 0; ind < sel.size(); ind++ ) | |
2865 | flags |= vls[sel[ind]]; | |
2866 | ||
2867 | extraStyle = flags; | |
2868 | } | |
2869 | ||
2870 | CreateGrid( style, extraStyle ); | |
2871 | ||
2872 | FinalizeFramePosition(); | |
2873 | } | |
2874 | ||
2875 | // ----------------------------------------------------------------------- | |
2876 | ||
2877 | void FormMain::OnSetColumns( wxCommandEvent& WXUNUSED(event) ) | |
2878 | { | |
2879 | long colCount = ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"), | |
2880 | wxT("Change Columns"),m_pPropGridManager->GetColumnCount(), | |
2881 | 2,20); | |
2882 | ||
2883 | if ( colCount >= 2 ) | |
2884 | { | |
2885 | m_pPropGridManager->SetColumnCount(colCount); | |
2886 | } | |
2887 | } | |
2888 | ||
2889 | // ----------------------------------------------------------------------- | |
2890 | ||
2891 | void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) ) | |
2892 | { | |
2893 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2894 | wxPGProperty* selected = pg->GetSelection(); | |
2895 | ||
2896 | if ( selected ) | |
2897 | { | |
2898 | wxString value = ::wxGetTextFromUser( wxT("Enter new value:") ); | |
2899 | pg->SetPropertyValue( selected, value ); | |
2900 | } | |
2901 | } | |
2902 | ||
2903 | // ----------------------------------------------------------------------- | |
2904 | ||
2905 | void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) | |
2906 | { | |
2907 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2908 | ||
2909 | wxPGProperty* selected = pg->GetSelection(); | |
2910 | const wxPGChoices& choices = selected->GetChoices(); | |
2911 | ||
2912 | // Insert new choice to the center of list | |
2913 | ||
2914 | if ( choices.IsOk() ) | |
2915 | { | |
2916 | int pos = choices.GetCount() / 2; | |
2917 | selected->InsertChoice(wxT("New Choice"), pos); | |
2918 | } | |
2919 | else | |
2920 | { | |
2921 | ::wxMessageBox(wxT("First select a property with some choices.")); | |
2922 | } | |
2923 | } | |
2924 | ||
2925 | // ----------------------------------------------------------------------- | |
2926 | ||
2927 | void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) ) | |
2928 | { | |
2929 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2930 | ||
2931 | wxPGProperty* selected = pg->GetSelection(); | |
2932 | const wxPGChoices& choices = selected->GetChoices(); | |
2933 | ||
2934 | // Deletes choice from the center of list | |
2935 | ||
2936 | if ( choices.IsOk() ) | |
2937 | { | |
2938 | int pos = choices.GetCount() / 2; | |
2939 | selected->DeleteChoice(pos); | |
2940 | } | |
2941 | else | |
2942 | { | |
2943 | ::wxMessageBox(wxT("First select a property with some choices.")); | |
2944 | } | |
2945 | } | |
2946 | ||
2947 | // ----------------------------------------------------------------------- | |
2948 | ||
2949 | #include <wx/colordlg.h> | |
2950 | ||
2951 | void FormMain::OnMisc ( wxCommandEvent& event ) | |
2952 | { | |
2953 | int id = event.GetId(); | |
2954 | if ( id == ID_STATICLAYOUT ) | |
2955 | { | |
2956 | long wsf = m_pPropGridManager->GetWindowStyleFlag(); | |
2957 | if ( event.IsChecked() ) m_pPropGridManager->SetWindowStyleFlag( wsf|wxPG_STATIC_LAYOUT ); | |
2958 | else m_pPropGridManager->SetWindowStyleFlag( wsf&~(wxPG_STATIC_LAYOUT) ); | |
2959 | } | |
2960 | else if ( id == ID_COLLAPSEALL ) | |
2961 | { | |
2962 | wxPGVIterator it; | |
2963 | wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); | |
2964 | ||
2965 | for ( it = pg->GetVIterator( wxPG_ITERATE_ALL ); !it.AtEnd(); it.Next() ) | |
2966 | it.GetProperty()->SetExpanded( false ); | |
2967 | ||
2968 | pg->RefreshGrid(); | |
2969 | } | |
2970 | else if ( id == ID_GETVALUES ) | |
2971 | { | |
2972 | m_storedValues = m_pPropGridManager->GetGrid()->GetPropertyValues(wxT("Test"), | |
2973 | m_pPropGridManager->GetGrid()->GetRoot(), | |
2974 | wxPG_KEEP_STRUCTURE|wxPG_INC_ATTRIBUTES); | |
2975 | } | |
2976 | else if ( id == ID_SETVALUES ) | |
2977 | { | |
2978 | if ( m_storedValues.GetType() == wxT("list") ) | |
2979 | { | |
2980 | m_pPropGridManager->GetGrid()->SetPropertyValues(m_storedValues); | |
2981 | } | |
2982 | else | |
2983 | wxMessageBox(wxT("First use Get Property Values.")); | |
2984 | } | |
2985 | else if ( id == ID_SETVALUES2 ) | |
2986 | { | |
2987 | wxVariant list; | |
2988 | list.NullList(); | |
2989 | list.Append( wxVariant((long)1234,wxT("VariantLong")) ); | |
2990 | list.Append( wxVariant((bool)TRUE,wxT("VariantBool")) ); | |
2991 | list.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) ); | |
2992 | m_pPropGridManager->GetGrid()->SetPropertyValues(list); | |
2993 | } | |
2994 | else if ( id == ID_COLLAPSE ) | |
2995 | { | |
2996 | // Collapses selected. | |
2997 | wxPGProperty* id = m_pPropGridManager->GetSelection(); | |
2998 | if ( id ) | |
2999 | { | |
3000 | m_pPropGridManager->Collapse(id); | |
3001 | } | |
3002 | } | |
3003 | else if ( id == ID_RUNTESTFULL ) | |
3004 | { | |
3005 | // Runs a regression test. | |
3006 | RunTests(true); | |
3007 | } | |
3008 | else if ( id == ID_RUNTESTPARTIAL ) | |
3009 | { | |
3010 | // Runs a regression test. | |
3011 | RunTests(false); | |
3012 | } | |
3013 | else if ( id == ID_UNSPECIFY ) | |
3014 | { | |
3015 | wxPGProperty* prop = m_pPropGridManager->GetSelection(); | |
3016 | if ( prop ) | |
3017 | { | |
3018 | m_pPropGridManager->SetPropertyValueUnspecified(prop); | |
3019 | prop->RefreshEditor(); | |
3020 | } | |
3021 | } | |
3022 | } | |
3023 | ||
3024 | // ----------------------------------------------------------------------- | |
3025 | ||
3026 | void FormMain::OnPopulateClick( wxCommandEvent& event ) | |
3027 | { | |
3028 | int id = event.GetId(); | |
3029 | m_propGrid->Clear(); | |
3030 | m_propGrid->Freeze(); | |
3031 | if ( id == ID_POPULATE1 ) | |
3032 | { | |
3033 | PopulateWithStandardItems(); | |
3034 | } | |
3035 | else if ( id == ID_POPULATE2 ) | |
3036 | { | |
3037 | PopulateWithLibraryConfig(); | |
3038 | } | |
3039 | m_propGrid->Thaw(); | |
3040 | } | |
3041 | ||
3042 | // ----------------------------------------------------------------------- | |
3043 | ||
3044 | void DisplayMinimalFrame(wxWindow* parent); // in minimal.cpp | |
3045 | ||
3046 | void FormMain::OnRunMinimalClick( wxCommandEvent& WXUNUSED(event) ) | |
3047 | { | |
3048 | DisplayMinimalFrame(this); | |
3049 | } | |
3050 | ||
3051 | // ----------------------------------------------------------------------- | |
3052 | ||
3053 | FormMain::~FormMain() | |
3054 | { | |
3055 | } | |
3056 | ||
3057 | // ----------------------------------------------------------------------- | |
3058 | ||
3059 | IMPLEMENT_APP(cxApplication) | |
3060 | ||
3061 | bool cxApplication::OnInit() | |
3062 | { | |
3063 | //wxLocale Locale; | |
3064 | //Locale.Init(wxLANGUAGE_FINNISH); | |
3065 | ||
3066 | FormMain* frame = Form1 = new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) ); | |
3067 | frame->Show(true); | |
3068 | ||
3069 | // | |
3070 | // Parse command-line | |
3071 | wxApp& app = wxGetApp(); | |
3072 | if ( app.argc > 1 ) | |
3073 | { | |
3074 | wxString s = app.argv[1]; | |
3075 | if ( s == wxT("--run-tests") ) | |
3076 | { | |
3077 | // | |
3078 | // Run tests | |
3079 | bool testResult = frame->RunTests(true); | |
3080 | ||
3081 | if ( testResult ) | |
3082 | return false; | |
3083 | } | |
3084 | } | |
3085 | ||
3086 | return true; | |
3087 | } | |
3088 | ||
3089 | // ----------------------------------------------------------------------- | |
3090 | ||
3091 | void FormMain::OnIdle( wxIdleEvent& event ) | |
3092 | { | |
3093 | /* | |
3094 | // This code is useful for debugging focus problems | |
3095 | static wxWindow* last_focus = (wxWindow*) NULL; | |
3096 | ||
3097 | wxWindow* cur_focus = ::wxWindow::FindFocus(); | |
3098 | ||
3099 | if ( cur_focus != last_focus ) | |
3100 | { | |
3101 | const wxChar* class_name = wxT("<none>"); | |
3102 | if ( cur_focus ) | |
3103 | class_name = cur_focus->GetClassInfo()->GetClassName(); | |
3104 | last_focus = cur_focus; | |
3105 | wxLogDebug( wxT("FOCUSED: %s %X"), | |
3106 | class_name, | |
3107 | (unsigned int)cur_focus); | |
3108 | } | |
3109 | */ | |
3110 | ||
3111 | event.Skip(); | |
3112 | } | |
3113 | ||
3114 | // ----------------------------------------------------------------------- |