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