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