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