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