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