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