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