1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 // * Examples of custom property classes are in sampleprops.cpp.
18 // * Additional ones can be found below.
20 // * Currently there is no example of a custom property editor. However,
21 // SpinCtrl editor sample is well-commented. It can be found in
22 // contrib/src/propgrid/advprops.cpp.
24 // * To find code that populates the grid with properties, search for
25 // string "::Populate".
27 // * To find code that handles property grid changes, search for string
28 // "::OnPropertyGridChange".
30 // * At the end of file there is example code for using the owner-drawn combo
31 // box independently outside the wxPropertyGrid.
35 // For compilers that support precompilation, includes "wx/wx.h".
36 #include "wx/wxprec.h"
42 // for all others, include the necessary headers (this file is usually all you
43 // need because it includes almost all "standard" wxWidgets headers)
49 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
52 #include <wx/numdlg.h>
54 // -----------------------------------------------------------------------
57 // Main propertygrid header.
58 #include <wx/propgrid/propgrid.h>
60 // Extra property classes.
61 #include <wx/propgrid/advprops.h>
63 // This defines wxPropertyGridManager.
64 #include <wx/propgrid/manager.h>
67 #include "sampleprops.h"
69 #if wxUSE_DATEPICKCTRL
70 #include <wx/datectrl.h>
73 #include <wx/artprov.h>
76 // -----------------------------------------------------------------------
77 // wxSampleMultiButtonEditor
78 // A sample editor class that has multiple buttons.
79 // -----------------------------------------------------------------------
81 class wxSampleMultiButtonEditor
: public wxPGTextCtrlEditor
83 WX_PG_DECLARE_EDITOR_CLASS(wxSampleMultiButtonEditor
)
85 wxSampleMultiButtonEditor() {}
86 virtual ~wxSampleMultiButtonEditor() {}
88 wxPG_DECLARE_CREATECONTROLS
89 virtual bool OnEvent( wxPropertyGrid
* propGrid
,
90 wxPGProperty
* property
,
92 wxEvent
& event
) const;
96 WX_PG_IMPLEMENT_EDITOR_CLASS(SampleMultiButtonEditor
,wxSampleMultiButtonEditor
,
100 wxPGWindowList
wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
101 wxPGProperty
* property
,
103 const wxSize
& sz
) const
105 // Create and populate buttons-subwindow
106 wxPGMultiButton
* buttons
= new wxPGMultiButton( propGrid
, sz
);
108 buttons
->Add( "..." );
111 buttons
->Add( wxArtProvider::GetBitmap(wxART_FOLDER
) );
114 // Create the 'primary' editor control (textctrl in this case)
115 wxPGWindowList wndList
= wxPGTextCtrlEditor::CreateControls
116 ( propGrid
, property
, pos
, buttons
->GetPrimarySize() );
118 // Finally, move buttons-subwindow to correct position and make sure
119 // returned wxPGWindowList contains our custom button list.
120 buttons
->FinalizePosition(pos
);
122 wndList
.SetSecondary( buttons
);
126 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid
* propGrid
,
127 wxPGProperty
* property
,
129 wxEvent
& event
) const
131 if ( event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
133 wxPGMultiButton
* buttons
= (wxPGMultiButton
*) propGrid
->GetEditorControlSecondary();
135 if ( event
.GetId() == buttons
->GetButtonId(1) )
137 wxMessageBox(wxT("Second button was pressed"));
140 if ( event
.GetId() == buttons
->GetButtonId(2) )
142 wxMessageBox(wxT("Third button was pressed"));
146 return wxPGTextCtrlEditor::OnEvent(propGrid
, property
, ctrl
, event
);
149 // -----------------------------------------------------------------------
150 // Validator for wxValidator use sample
151 // -----------------------------------------------------------------------
155 // wxValidator for testing
157 class wxInvalidWordValidator
: public wxValidator
161 wxInvalidWordValidator( const wxString
& invalidWord
)
162 : wxValidator(), m_invalidWord(invalidWord
)
166 virtual wxObject
* Clone() const
168 return new wxInvalidWordValidator(m_invalidWord
);
171 virtual bool Validate(wxWindow
* WXUNUSED(parent
))
173 wxTextCtrl
* tc
= wxDynamicCast(GetWindow(), wxTextCtrl
);
174 wxCHECK_MSG(tc
, true, wxT("validator window must be wxTextCtrl"));
176 wxString val
= tc
->GetValue();
178 if ( val
.find(m_invalidWord
) == wxString::npos
)
181 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord
.c_str()),
182 wxT("Validation Failure"));
188 wxString m_invalidWord
;
191 #endif // wxUSE_VALIDATORS
193 // -----------------------------------------------------------------------
194 // AdvImageFile Property
195 // -----------------------------------------------------------------------
199 WX_DECLARE_OBJARRAY(wxMyImageInfo
, wxArrayMyImageInfo
);
205 wxBitmap
* m_pThumbnail1
; // smaller thumbnail
206 wxBitmap
* m_pThumbnail2
; // larger thumbnail
208 wxMyImageInfo ( const wxString
& str
)
211 m_pThumbnail1
= (wxBitmap
*) NULL
;
212 m_pThumbnail2
= (wxBitmap
*) NULL
;
214 virtual ~wxMyImageInfo()
217 delete m_pThumbnail1
;
219 delete m_pThumbnail2
;
225 #include <wx/arrimpl.cpp>
226 WX_DEFINE_OBJARRAY(wxArrayMyImageInfo
);
228 wxArrayMyImageInfo g_myImageArray
;
231 // Preferred thumbnail height.
232 #define PREF_THUMBNAIL_HEIGHT 64
235 wxPGChoices
wxAdvImageFileProperty::ms_choices
;
237 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxAdvImageFileProperty
,wxFileProperty
,
238 wxString
,const wxString
&,ChoiceAndButton
)
241 wxAdvImageFileProperty::wxAdvImageFileProperty( const wxString
& label
,
242 const wxString
& name
,
243 const wxString
& value
)
244 : wxFileProperty(label
,name
,value
)
246 m_wildcard
= wxPGGetDefaultImageWildcard();
250 m_pImage
= (wxImage
*) NULL
;
253 m_flags
&= ~(wxPG_PROP_SHOW_FULL_FILENAME
);
256 wxAdvImageFileProperty::~wxAdvImageFileProperty ()
262 m_pImage
= (wxImage
*) NULL
;
266 void wxAdvImageFileProperty::OnSetValue()
268 wxFileProperty::OnSetValue();
274 m_pImage
= (wxImage
*) NULL
;
277 wxString imagename
= GetValueAsString(0);
279 if ( imagename
.length() )
281 size_t prevCount
= g_myImageArray
.GetCount();
282 int index
= ms_choices
.Index(imagename
);
284 // If not in table, add now.
285 if ( index
== wxNOT_FOUND
)
287 ms_choices
.Add( imagename
);
288 g_myImageArray
.Add( new wxMyImageInfo( m_filename
.GetFullPath() ) );
290 index
= g_myImageArray
.GetCount() - 1;
293 // If no thumbnail ready, then need to load image.
294 if ( !g_myImageArray
[index
].m_pThumbnail2
)
296 // Load if file exists.
297 if ( m_filename
.FileExists() )
298 m_pImage
= new wxImage( m_filename
.GetFullPath() );
303 wxPropertyGrid
* pg
= GetGrid();
304 wxWindow
* control
= pg
->GetEditorControl();
306 if ( pg
->GetSelection() == this && control
)
308 wxString name
= GetValueAsString(0);
310 if ( g_myImageArray
.GetCount() != prevCount
)
312 wxASSERT( g_myImageArray
.GetCount() == (prevCount
+1) );
314 // Add to the control's array.
315 // (should be added to own array earlier)
318 GetEditorClass()->InsertItem(control
, name
, -1);
322 GetEditorClass()->UpdateControl(this, control
);
329 int wxAdvImageFileProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
332 choiceinfo
->m_choices
= &ms_choices
;
337 bool wxAdvImageFileProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
339 wxASSERT( number
>= 0 );
340 return StringToValue( variant
, ms_choices
.GetLabel(number
), wxPG_FULL_VALUE
);
343 bool wxAdvImageFileProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* primary
,
346 if ( propgrid
->IsMainButtonEvent(event
) )
348 return wxFileProperty::OnEvent(propgrid
,primary
,event
);
353 wxSize
wxAdvImageFileProperty::OnMeasureImage( int item
) const
356 return wxPG_DEFAULT_IMAGE_SIZE
;
358 return wxSize(PREF_THUMBNAIL_HEIGHT
,PREF_THUMBNAIL_HEIGHT
);
361 void wxAdvImageFileProperty::LoadThumbnails( size_t index
)
363 wxMyImageInfo
& mii
= g_myImageArray
[index
];
365 if ( !mii
.m_pThumbnail2
)
368 if ( !m_pImage
|| !m_pImage
->Ok() ||
369 m_filename
!= mii
.m_path
374 m_pImage
= new wxImage( mii
.m_path
);
377 if ( m_pImage
&& m_pImage
->Ok() )
379 int im_wid
= m_pImage
->GetWidth();
380 int im_hei
= m_pImage
->GetHeight();
381 if ( im_hei
> PREF_THUMBNAIL_HEIGHT
)
384 im_wid
= (PREF_THUMBNAIL_HEIGHT
*m_pImage
->GetWidth())/m_pImage
->GetHeight();
385 im_hei
= PREF_THUMBNAIL_HEIGHT
;
388 m_pImage
->Rescale( im_wid
, im_hei
);
390 mii
.m_pThumbnail2
= new wxBitmap( *m_pImage
);
392 wxSize cis
= GetParentState()->GetGrid()->GetImageSize();
393 m_pImage
->Rescale ( cis
.x
, cis
.y
);
395 mii
.m_pThumbnail1
= new wxBitmap( *m_pImage
);
402 m_pImage
= (wxImage
*) NULL
;
407 void wxAdvImageFileProperty::OnCustomPaint( wxDC
& dc
,
412 if ( pd
.m_choiceItem
>= 0 )
413 index
= pd
.m_choiceItem
;
415 //wxLogDebug(wxT("%i"),index);
419 LoadThumbnails(index
);
421 // Is this a measure item call?
425 //pd.m_drawnHeight = PREF_THUMBNAIL_HEIGHT;
426 wxBitmap
* pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail2
;
428 pd
.m_drawnHeight
= pBitmap
->GetHeight();
430 pd
.m_drawnHeight
= 16;
434 // Draw the thumbnail
438 if ( pd
.m_choiceItem
>= 0 )
439 pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail2
;
441 pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail1
;
445 dc
.DrawBitmap ( *pBitmap
, rect
.x
, rect
.y
, FALSE
);
447 // Tell the caller how wide we drew.
448 pd
.m_drawnWidth
= pBitmap
->GetWidth();
454 // No valid file - just draw a white box.
455 dc
.SetBrush ( *wxWHITE_BRUSH
);
456 dc
.DrawRectangle ( rect
);
460 // -----------------------------------------------------------------------
462 // -----------------------------------------------------------------------
464 // See propgridsample.h for wxVector3f class
466 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
468 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
469 wxVector3f
,const wxVector3f
&,TextCtrl
)
472 wxVectorProperty::wxVectorProperty( const wxString
& label
,
473 const wxString
& name
,
474 const wxVector3f
& value
)
475 : wxPGProperty(label
,name
)
477 SetValue( WXVARIANT(value
) );
478 AddChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
479 AddChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
480 AddChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
483 wxVectorProperty::~wxVectorProperty() { }
485 void wxVectorProperty::RefreshChildren()
487 if ( !GetChildCount() ) return;
488 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
489 Item(0)->SetValue( vector
.x
);
490 Item(1)->SetValue( vector
.y
);
491 Item(2)->SetValue( vector
.z
);
494 void wxVectorProperty::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
498 switch ( childIndex
)
500 case 0: vector
.x
= childValue
.GetDouble(); break;
501 case 1: vector
.y
= childValue
.GetDouble(); break;
502 case 2: vector
.z
= childValue
.GetDouble(); break;
508 // -----------------------------------------------------------------------
509 // wxTriangleProperty
510 // -----------------------------------------------------------------------
512 // See propgridsample.h for wxTriangle class
514 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
516 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
517 wxTriangle
,const wxTriangle
&,TextCtrl
)
520 wxTriangleProperty::wxTriangleProperty( const wxString
& label
,
521 const wxString
& name
,
522 const wxTriangle
& value
)
523 : wxPGProperty(label
,name
)
525 SetValue( WXVARIANT(value
) );
526 AddChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
527 AddChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
528 AddChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
531 wxTriangleProperty::~wxTriangleProperty() { }
533 void wxTriangleProperty::RefreshChildren()
535 if ( !GetChildCount() ) return;
536 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
537 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
538 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
539 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
542 void wxTriangleProperty::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
545 triangle
<< thisValue
;
546 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
547 switch ( childIndex
)
549 case 0: triangle
.a
= vector
; break;
550 case 1: triangle
.b
= vector
; break;
551 case 2: triangle
.c
= vector
; break;
553 thisValue
<< triangle
;
557 // -----------------------------------------------------------------------
558 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
559 // -----------------------------------------------------------------------
561 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
565 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
566 : wxPGEditorDialogAdapter(), m_choices(choices
)
570 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
571 wxPGProperty
* WXUNUSED(property
) )
573 wxString s
= ::wxGetSingleChoice(wxT("Message"),
575 m_choices
.GetLabels());
586 const wxPGChoices
& m_choices
;
590 class SingleChoiceProperty
: public wxStringProperty
594 SingleChoiceProperty( const wxString
& label
,
595 const wxString
& name
= wxPG_LABEL
,
596 const wxString
& value
= wxEmptyString
)
597 : wxStringProperty(label
, name
, value
)
600 m_choices
.Add(wxT("Cat"));
601 m_choices
.Add(wxT("Dog"));
602 m_choices
.Add(wxT("Gibbon"));
603 m_choices
.Add(wxT("Otter"));
606 // Set editor to have button
607 virtual const wxPGEditor
* DoGetEditorClass() const
609 return wxPG_EDITOR(TextCtrlAndButton
);
612 // Set what happens on button click
613 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
615 return new wxSingleChoiceDialogAdapter(m_choices
);
619 wxPGChoices m_choices
;
622 // -----------------------------------------------------------------------
624 // -----------------------------------------------------------------------
671 ID_SETSPINCTRLEDITOR
,
676 ID_ENABLECOMMONVALUES
,
683 // -----------------------------------------------------------------------
685 // -----------------------------------------------------------------------
687 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
688 EVT_IDLE(FormMain::OnIdle
)
689 EVT_MOVE(FormMain::OnMove
)
690 EVT_SIZE(FormMain::OnResize
)
692 // This occurs when a property is selected
693 EVT_PG_SELECTED( PGID
, FormMain::OnPropertyGridSelect
)
694 // This occurs when a property value changes
695 EVT_PG_CHANGED( PGID
, FormMain::OnPropertyGridChange
)
696 // This occurs just prior a property value is changed
697 EVT_PG_CHANGING( PGID
, FormMain::OnPropertyGridChanging
)
698 // This occurs when a mouse moves over another property
699 EVT_PG_HIGHLIGHTED( PGID
, FormMain::OnPropertyGridHighlight
)
700 // This occurs when mouse is right-clicked.
701 EVT_PG_RIGHT_CLICK( PGID
, FormMain::OnPropertyGridItemRightClick
)
702 // This occurs when mouse is double-clicked.
703 EVT_PG_DOUBLE_CLICK( PGID
, FormMain::OnPropertyGridItemDoubleClick
)
704 // This occurs when propgridmanager's page changes.
705 EVT_PG_PAGE_CHANGED( PGID
, FormMain::OnPropertyGridPageChange
)
706 // This occurs when property's editor button (if any) is clicked.
707 EVT_BUTTON( PGID
, FormMain::OnPropertyGridButtonClick
)
709 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain::OnPropertyGridItemCollapse
)
710 EVT_PG_ITEM_EXPANDED( PGID
, FormMain::OnPropertyGridItemExpand
)
712 EVT_TEXT( PGID
, FormMain::OnPropertyGridTextUpdate
)
715 // Rest of the events are not property grid specific
716 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent
)
717 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent
)
719 EVT_MENU( ID_APPENDPROP
, FormMain::OnAppendPropClick
)
720 EVT_MENU( ID_APPENDCAT
, FormMain::OnAppendCatClick
)
721 EVT_MENU( ID_INSERTPROP
, FormMain::OnInsertPropClick
)
722 EVT_MENU( ID_INSERTCAT
, FormMain::OnInsertCatClick
)
723 EVT_MENU( ID_DELETE
, FormMain::OnDelPropClick
)
724 EVT_MENU( ID_DELETER
, FormMain::OnDelPropRClick
)
725 EVT_MENU( ID_UNSPECIFY
, FormMain::OnMisc
)
726 EVT_MENU( ID_DELETEALL
, FormMain::OnClearClick
)
727 EVT_MENU( ID_ENABLE
, FormMain::OnEnableDisable
)
728 EVT_MENU( ID_HIDE
, FormMain::OnHideShow
)
729 EVT_MENU( ID_ITERATE1
, FormMain::OnIterate1Click
)
730 EVT_MENU( ID_ITERATE2
, FormMain::OnIterate2Click
)
731 EVT_MENU( ID_ITERATE3
, FormMain::OnIterate3Click
)
732 EVT_MENU( ID_ITERATE4
, FormMain::OnIterate4Click
)
733 EVT_MENU( ID_SETCOLOUR
, FormMain::OnMisc
)
734 EVT_MENU( ID_CLEARMODIF
, FormMain::OnClearModifyStatusClick
)
735 EVT_MENU( ID_FREEZE
, FormMain::OnFreezeClick
)
736 EVT_MENU( ID_DUMPLIST
, FormMain::OnDumpList
)
738 EVT_MENU( ID_COLOURSCHEME1
, FormMain::OnColourScheme
)
739 EVT_MENU( ID_COLOURSCHEME2
, FormMain::OnColourScheme
)
740 EVT_MENU( ID_COLOURSCHEME3
, FormMain::OnColourScheme
)
741 EVT_MENU( ID_COLOURSCHEME4
, FormMain::OnColourScheme
)
743 EVT_MENU( ID_ABOUT
, FormMain::OnAbout
)
744 EVT_MENU( ID_QUIT
, FormMain::OnCloseClick
)
746 EVT_MENU( ID_CATCOLOURS
, FormMain::OnCatColours
)
747 EVT_MENU( ID_SETCOLUMNS
, FormMain::OnSetColumns
)
748 EVT_MENU( ID_TESTXRC
, FormMain::OnTestXRC
)
749 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain::OnEnableCommonValues
)
750 EVT_MENU( ID_SELECTSTYLE
, FormMain::OnSelectStyle
)
752 EVT_MENU( ID_STATICLAYOUT
, FormMain::OnMisc
)
753 EVT_MENU( ID_CLEAR
, FormMain::OnMisc
)
754 EVT_MENU( ID_COLLAPSE
, FormMain::OnMisc
)
755 EVT_MENU( ID_COLLAPSEALL
, FormMain::OnMisc
)
757 EVT_MENU( ID_POPULATE1
, FormMain::OnPopulateClick
)
758 EVT_MENU( ID_POPULATE2
, FormMain::OnPopulateClick
)
760 EVT_MENU( ID_GETVALUES
, FormMain::OnMisc
)
761 EVT_MENU( ID_SETVALUES
, FormMain::OnMisc
)
762 EVT_MENU( ID_SETVALUES2
, FormMain::OnMisc
)
764 EVT_MENU( ID_FITCOLUMNS
, FormMain::OnFitColumnsClick
)
766 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain::OnChangeFlagsPropItemsClick
)
768 EVT_MENU( ID_RUNTESTFULL
, FormMain::OnMisc
)
769 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain::OnMisc
)
771 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain::OnInsertChoice
)
772 EVT_MENU( ID_TESTDELETECHOICE
, FormMain::OnDeleteChoice
)
774 EVT_MENU( ID_INSERTPAGE
, FormMain::OnInsertPage
)
775 EVT_MENU( ID_REMOVEPAGE
, FormMain::OnRemovePage
)
777 EVT_MENU( ID_SAVESTATE
, FormMain::OnSaveState
)
778 EVT_MENU( ID_RESTORESTATE
, FormMain::OnRestoreState
)
780 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain::OnSetSpinCtrlEditorClick
)
781 EVT_MENU( ID_TESTREPLACE
, FormMain::OnTestReplaceClick
)
782 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain::OnSetPropertyValue
)
784 EVT_MENU( ID_RUNMINIMAL
, FormMain::OnRunMinimalClick
)
786 EVT_CONTEXT_MENU( FormMain::OnContextMenu
)
789 // -----------------------------------------------------------------------
791 void FormMain::OnMove( wxMoveEvent
& event
)
793 if ( !m_pPropGridManager
)
795 // this check is here so the frame layout can be tested
796 // without creating propertygrid
801 // Update position properties
807 // Must check if properties exist (as they may be deleted).
809 // Using m_pPropGridManager, we can scan all pages automatically.
810 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
812 m_pPropGridManager
->SetPropertyValue( id
, x
);
814 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
816 m_pPropGridManager
->SetPropertyValue( id
, y
);
818 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
820 m_pPropGridManager
->SetPropertyValue( id
, wxPoint(x
,y
) );
822 // Should always call event.Skip() in frame's MoveEvent handler
826 // -----------------------------------------------------------------------
828 void FormMain::OnResize( wxSizeEvent
& event
)
830 if ( !m_pPropGridManager
)
832 // this check is here so the frame layout can be tested
833 // without creating propertygrid
838 // Update size properties
845 // Must check if properties exist (as they may be deleted).
847 // Using m_pPropGridManager, we can scan all pages automatically.
848 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
849 if ( p
&& !p
->IsValueUnspecified() )
850 m_pPropGridManager
->SetPropertyValue( p
, w
);
852 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
853 if ( p
&& !p
->IsValueUnspecified() )
854 m_pPropGridManager
->SetPropertyValue( p
, h
);
856 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
858 m_pPropGridManager
->SetPropertyValue( id
, wxSize(w
,h
) );
860 // Should always call event.Skip() in frame's SizeEvent handler
864 // -----------------------------------------------------------------------
866 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
868 wxPGProperty
* p
= event
.GetProperty();
870 if ( p
->GetName() == wxT("Font") )
873 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
874 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
875 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
879 wxASSERT(event
.CanVeto());
883 // Since we ask a question, it is better if we omit any validation
885 event
.SetValidationFailureBehavior(0);
891 // Note how we use three types of value getting in this method:
892 // A) event.GetPropertyValueAsXXX
893 // B) event.GetPropertValue, and then variant's GetXXX
894 // C) grid's GetPropertyValueAsXXX(id)
896 void FormMain::OnPropertyGridChange( wxPropertyGridEvent
& event
)
898 wxPGProperty
* property
= event
.GetProperty();
900 const wxString
& name
= property
->GetName();
901 wxVariant value
= property
->GetValue();
903 // Don't handle 'unspecified' values
904 if ( value
.IsNull() )
907 // Some settings are disabled outside Windows platform
908 if ( name
== wxT("X") )
909 SetSize ( m_pPropGridManager
->GetPropertyValueAsInt(property
), -1, -1, -1, wxSIZE_USE_EXISTING
);
910 else if ( name
== wxT("Y") )
911 // wxPGVariantToInt is safe long int value getter
912 SetSize ( -1, wxPGVariantToInt(value
), -1, -1, wxSIZE_USE_EXISTING
);
913 else if ( name
== wxT("Width") )
914 SetSize ( -1, -1, m_pPropGridManager
->GetPropertyValueAsInt(property
), -1, wxSIZE_USE_EXISTING
);
915 else if ( name
== wxT("Height") )
916 SetSize ( -1, -1, -1, wxPGVariantToInt(value
), wxSIZE_USE_EXISTING
);
917 else if ( name
== wxT("Label") )
919 SetTitle ( m_pPropGridManager
->GetPropertyValueAsString(property
) );
921 else if ( name
== wxT("Password") )
923 static int pwdMode
= 0;
925 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
931 if ( name
== wxT("Font") )
935 wxASSERT( font
.Ok() );
937 m_pPropGridManager
->SetFont( font
);
940 if ( name
== wxT("Margin Colour") )
942 wxColourPropertyValue cpv
;
944 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
946 else if ( name
== wxT("Cell Colour") )
948 wxColourPropertyValue cpv
;
950 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
952 else if ( name
== wxT("Line Colour") )
954 wxColourPropertyValue cpv
;
956 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
958 else if ( name
== wxT("Cell Text Colour") )
960 wxColourPropertyValue cpv
;
962 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
966 // -----------------------------------------------------------------------
968 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
970 wxPGProperty
* property
= event
.GetProperty();
973 m_itemEnable
->Enable( TRUE
);
974 if ( property
->IsEnabled() )
975 m_itemEnable
->SetItemLabel( wxT("Disable") );
977 m_itemEnable
->SetItemLabel( wxT("Enable") );
981 m_itemEnable
->Enable( FALSE
);
985 wxPGProperty
* prop
= event
.GetProperty();
986 wxStatusBar
* sb
= GetStatusBar();
989 wxString
text(wxT("Selected: "));
990 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
991 sb
->SetStatusText ( text
);
996 // -----------------------------------------------------------------------
998 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1001 wxStatusBar
* sb
= GetStatusBar();
1002 wxString
text(wxT("Page Changed: "));
1003 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
1004 sb
->SetStatusText( text
);
1008 // -----------------------------------------------------------------------
1010 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
1014 // -----------------------------------------------------------------------
1016 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
1019 wxPGProperty
* prop
= event
.GetProperty();
1020 wxStatusBar
* sb
= GetStatusBar();
1023 wxString
text(wxT("Right-clicked: "));
1024 text
+= prop
->GetLabel();
1025 text
+= wxT(", name=");
1026 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1027 sb
->SetStatusText( text
);
1031 sb
->SetStatusText( wxEmptyString
);
1036 // -----------------------------------------------------------------------
1038 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
1041 wxPGProperty
* prop
= event
.GetProperty();
1042 wxStatusBar
* sb
= GetStatusBar();
1045 wxString
text(wxT("Double-clicked: "));
1046 text
+= prop
->GetLabel();
1047 text
+= wxT(", name=");
1048 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1049 sb
->SetStatusText ( text
);
1053 sb
->SetStatusText ( wxEmptyString
);
1058 // -----------------------------------------------------------------------
1060 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent
& )
1063 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
1064 wxStatusBar
* sb
= GetStatusBar();
1067 wxString
text(wxT("Button clicked: "));
1068 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
1069 text
+= wxT(", name=");
1070 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1071 sb
->SetStatusText( text
);
1075 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
1080 // -----------------------------------------------------------------------
1082 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
1084 wxLogDebug(wxT("Item was Collapsed"));
1087 // -----------------------------------------------------------------------
1089 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
1091 wxLogDebug(wxT("Item was Expanded"));
1094 // -----------------------------------------------------------------------
1096 // EVT_TEXT handling
1097 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
1102 // -----------------------------------------------------------------------
1104 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
1106 // Occurs on wxGTK mostly, but not wxMSW.
1109 // -----------------------------------------------------------------------
1111 void FormMain::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
1113 // Uncomment following to allow property label modify in real-time
1114 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
1115 // if ( !p.IsOk() ) return;
1116 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
1119 // -----------------------------------------------------------------------
1121 static const wxChar
* _fs_windowstyle_labels
[] = {
1122 wxT("wxSIMPLE_BORDER"),
1123 wxT("wxDOUBLE_BORDER"),
1124 wxT("wxSUNKEN_BORDER"),
1125 wxT("wxRAISED_BORDER"),
1127 wxT("wxTRANSPARENT_WINDOW"),
1128 wxT("wxTAB_TRAVERSAL"),
1129 wxT("wxWANTS_CHARS"),
1130 #if wxNO_FULL_REPAINT_ON_RESIZE
1131 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
1134 wxT("wxALWAYS_SHOW_SB"),
1135 wxT("wxCLIP_CHILDREN"),
1136 #if wxFULL_REPAINT_ON_RESIZE
1137 wxT("wxFULL_REPAINT_ON_RESIZE"),
1139 (const wxChar
*) NULL
// terminator is always needed
1142 static const long _fs_windowstyle_values
[] = {
1148 wxTRANSPARENT_WINDOW
,
1151 #if wxNO_FULL_REPAINT_ON_RESIZE
1152 wxNO_FULL_REPAINT_ON_RESIZE
,
1157 #if wxFULL_REPAINT_ON_RESIZE
1158 wxFULL_REPAINT_ON_RESIZE
1162 static const wxChar
* _fs_framestyle_labels
[] = {
1167 wxT("wxSTAY_ON_TOP"),
1168 wxT("wxSYSTEM_MENU"),
1169 wxT("wxRESIZE_BORDER"),
1170 wxT("wxFRAME_TOOL_WINDOW"),
1171 wxT("wxFRAME_NO_TASKBAR"),
1172 wxT("wxFRAME_FLOAT_ON_PARENT"),
1173 wxT("wxFRAME_SHAPED"),
1174 (const wxChar
*) NULL
1177 static const long _fs_framestyle_values
[] = {
1185 wxFRAME_TOOL_WINDOW
,
1187 wxFRAME_FLOAT_ON_PARENT
,
1191 // -----------------------------------------------------------------------
1193 void FormMain::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1195 wxMessageBox(wxT("Sorrt, not yet implemented"));
1198 void FormMain::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1200 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
1202 prop
->EnableCommonValue();
1204 wxMessageBox(wxT("First select a property"));
1207 void FormMain::PopulateWithStandardItems ()
1209 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1210 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1212 // Append is ideal way to add items to wxPropertyGrid.
1213 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1215 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1216 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1217 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1219 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1220 pg
->GetGrid()->GetMarginColour()) );
1222 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1223 pg
->GetGrid()->GetCellBackgroundColour()) );
1224 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1225 pg
->GetGrid()->GetCellTextColour()) );
1226 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1227 pg
->GetGrid()->GetLineColour()) );
1228 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1229 m_combinedFlags
, GetWindowStyle()) );
1231 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1233 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1235 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1236 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1238 // Let's demonstrate 'Units' attribute here
1240 // Note that we use many attribute constants instead of strings here
1241 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1242 // Using constant may reduce binary size.
1244 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1245 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1246 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1247 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1249 // Set value to unspecified so that InlineHelp attribute will be demonstrated
1250 pg
->SetPropertyValueUnspecified(wxT("Height"));
1251 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_INLINE_HELP
, wxT("Enter new height for window") );
1252 pg
->SetPropertyHelpString(wxT("Height"), wxT("This property uses attributes \"Units\" and \"InlineHelp\".") );
1254 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1255 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1256 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1257 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1259 pg
->SetPropertyValueUnspecified(wxT("Width"));
1260 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_INLINE_HELP
, wxT("Enter new width for window") );
1261 pg
->SetPropertyHelpString(wxT("Width"), wxT("This property uses attributes \"Units\" and \"InlineHelp\".") );
1263 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1264 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1265 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1267 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1268 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1269 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1271 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. Inorder to have label disabled as well, ")
1272 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1274 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1275 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1277 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1278 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1279 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1281 // Disable some of them
1282 pg
->DisableProperty( wxT("Operating System") );
1283 pg
->DisableProperty( wxT("User Id") );
1284 pg
->DisableProperty( wxT("User Name") );
1286 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1287 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1288 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1290 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1292 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1293 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1294 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1295 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1298 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1299 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1300 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1301 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1302 wxT("with custom action (dir dialog popup) defined.")
1305 pg
->Append( new wxAdvImageFileProperty(wxT("AdvImageFileProperty"),wxPG_LABEL
) );
1306 pg
->SetPropertyHelpString( wxT("AdvImageFileProperty"),
1307 wxT("This demonstrates wxAdvImageFileProperty class defined in this sample app. ")
1308 wxT("Button can be used to add new images to the popup list.")
1311 wxArrayDouble arrdbl
;
1318 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1319 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1320 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1321 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1322 wxT("It is an example of a custom list editor property.")
1325 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1326 wxT("Editing properties will have immediate effect on this window, ")
1327 wxT("and vice versa (atleast in most cases, that is).")
1329 pg
->SetPropertyHelpString( wxT("Information"),
1330 wxT("This property is read-only.") );
1332 pg
->SetPropertyReadOnly( wxT("Information"), true );
1335 // Set test information for cells in columns 3 and 4
1336 // (reserve column 2 for displaying units)
1337 wxPropertyGridIterator it
;
1338 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_FOLDER
);
1340 for ( it
= pg
->GetGrid()->GetIterator();
1344 wxPGProperty
* p
= *it
;
1345 if ( p
->IsCategory() )
1348 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1349 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1353 // -----------------------------------------------------------------------
1355 void FormMain::PopulateWithExamples ()
1357 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1358 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1361 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1362 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1365 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1367 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPG_EDITOR(SpinCtrl
) );
1368 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1369 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)10 ); // for reduced binary size.
1370 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1371 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1373 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1374 wxT("This is regular wxIntProperty, which editor has been ")
1375 wxT("changed to wxPG_EDITOR(SpinCtrl). Note however that ")
1376 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1377 wxT("needs to be called prior to using it."));
1381 // Add bool property
1382 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1384 // Add bool property with check box
1385 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1386 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1387 wxPG_BOOL_USE_CHECKBOX
,
1390 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1391 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1393 pid
= pg
->Append( new wxFloatProperty( wxT("FloatProperty"),
1397 // A string property that can be edited in a separate editor dialog.
1398 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1399 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1401 // A property that edits a wxArrayString.
1402 wxArrayString example_array
;
1403 example_array
.Add( wxT("String 1"));
1404 example_array
.Add( wxT("String 2"));
1405 example_array
.Add( wxT("String 3"));
1406 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1409 // Test adding same category multiple times ( should not actually create a new one )
1410 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1412 // A file selector property. Note that argument between name
1413 // and initial value is wildcard (format same as in wxFileDialog).
1414 wxPGProperty
* prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1417 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1418 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1419 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1422 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1423 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1427 // An image file property. Arguments are just like for FileProperty, but
1428 // wildcard is missing (it is autogenerated from supported image formats).
1429 // If you really need to override it, create property separately, and call
1430 // its SetWildcard method.
1431 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1434 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1435 //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false);
1436 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPG_EDITOR(ComboBox
) );
1437 pg
->GetProperty(wxT("ColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1438 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1439 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1440 wxT("editor of this property to wxPG_EDITOR(ComboBox)"));
1443 // This demonstrates using alternative editor for colour property
1444 // to trigger colour dialog directly from button.
1445 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1448 // wxEnumProperty does not store strings or even list of strings
1449 // ( so that's why they are static in function ).
1450 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1451 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1453 // this value array would be optional if values matched string indexes
1454 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1456 // note that the initial value (the last argument) is the actual value,
1457 // not index or anything like that. Thus, our value selects "Another Item".
1459 // 0 before value is number of items. If it is 0, like in our example,
1460 // number of items is calculated, and this requires that the string pointer
1461 // array is terminated with NULL.
1462 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1463 enum_prop_labels
, enum_prop_values
, 80 ) );
1467 // use basic table from our previous example
1468 // can also set/add wxArrayStrings and wxArrayInts directly.
1469 soc
.Set( enum_prop_labels
, enum_prop_values
);
1472 soc
.Add( wxT("Look, it continues"), 200 );
1473 soc
.Add( wxT("Even More"), 240 );
1474 soc
.Add( wxT("And More"), 280 );
1475 soc
.Add( wxT("True End of the List"), 320 );
1477 // Test custom colours ([] operator of wxPGChoices returns
1478 // references to wxPGChoiceEntry).
1479 soc
[1].SetFgCol(*wxRED
);
1480 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1481 soc
[2].SetFgCol(*wxGREEN
);
1482 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1483 soc
[3].SetFgCol(*wxBLUE
);
1484 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1485 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1487 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1491 pg
->AddPropertyChoice(wxT("EnumProperty 2"),wxT("Testing Extra"),360);
1493 // Add a second time to test that the caching works
1494 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1496 pg
->SetPropertyHelpString(wxT("EnumProperty 3"),
1497 wxT("Should have same choices as EnumProperty 2"));
1499 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1501 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1502 wxT("Should have same choices as EnumProperty 2"));
1504 pg
->Append( new wxEnumProperty(wxT("EnumProperty 5"),wxPG_LABEL
,
1506 pg
->SetPropertyChoicesExclusive(wxT("EnumProperty 5"));
1507 pg
->AddPropertyChoice(wxT("EnumProperty 5"),wxT("5th only"),360);
1508 pg
->SetPropertyHelpString(wxT("EnumProperty 5"),
1509 wxT("Should have one extra item when compared to EnumProperty 4"));
1511 // Password property example.
1512 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1513 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1514 pg
->SetPropertyHelpString( wxT("Password"),
1515 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1517 // String editor with dir selector button. Uses wxEmptyString as name, which
1518 // is allowed (naturally, in this case property cannot be accessed by name).
1519 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1520 pg
->SetPropertyAttribute( wxT("DirProperty"),
1521 wxPG_DIR_DIALOG_MESSAGE
,
1522 wxT("This is a custom dir dialog message") );
1524 // Add string property - first arg is label, second name, and third initial value
1525 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1526 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1527 pg
->SetPropertyHelpString( wxT("StringProperty"),
1528 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1530 // Set value after limiting so that it will be applied
1531 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1534 // this value array would be optional if values matched string indexes
1535 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1537 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1538 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1541 // Multi choice dialog.
1542 wxArrayString tchoices
;
1543 tchoices
.Add(wxT("Cabbage"));
1544 tchoices
.Add(wxT("Carrot"));
1545 tchoices
.Add(wxT("Onion"));
1546 tchoices
.Add(wxT("Potato"));
1547 tchoices
.Add(wxT("Strawberry"));
1549 wxArrayString tchoicesValues
;
1550 tchoicesValues
.Add(wxT("Carrot"));
1551 tchoicesValues
.Add(wxT("Potato"));
1553 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1555 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1556 tchoices
, tchoicesValues
) );
1557 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1559 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1560 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1564 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1565 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1566 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1567 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1568 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1571 // wxEditEnumProperty
1573 eech
.Add(wxT("Choice 1"));
1574 eech
.Add(wxT("Choice 2"));
1575 eech
.Add(wxT("Choice 3"));
1576 pg
->Append( new wxEditEnumProperty(wxT("EditEnumProperty"), wxPG_LABEL
, eech
) ); // , wxT("Choice 2")
1579 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1580 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1584 // wxDateTimeProperty
1585 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1587 #if wxUSE_DATEPICKCTRL
1588 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1589 (long)(wxDP_DROPDOWN
| wxDP_SHOWCENTURY
) );
1591 pg
->SetPropertyHelpString( wxT("DateProperty"),
1592 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY).")
1593 wxT("Also note that wxPG_ALLOW_WXADV needs to be defined inorder to use wxDatePickerCtrl.") );
1599 // Add Triangle properties as both wxTriangleProperty and
1600 // a generic parent property (using wxStringProperty).
1602 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1604 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1605 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1606 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1607 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1609 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1611 pg
->SetPropertyHelpString( wxT("3D Object"),
1612 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1613 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1615 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1616 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1617 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1618 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1620 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1623 // This snippet is a doc sample test
1625 pid
= pg
->Append( new wxStringProperty(wxT("Car"),wxPG_LABEL
,wxT("<composed>")) );
1627 pg
->AppendIn( pid
, new wxStringProperty(wxT("Model"),
1629 wxT("Lamborghini Diablo SV")) );
1631 pg
->AppendIn( pid
, new wxIntProperty(wxT("Engine Size (cc)"),
1635 wxPGProperty
* speedId
= pg
->AppendIn( pid
, new wxStringProperty(wxT("Speeds"),wxPG_LABEL
,wxT("<composed>")) );
1636 pg
->AppendIn( speedId
, new wxIntProperty(wxT("Max. Speed (mph)"),wxPG_LABEL
,290) );
1637 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("0-100 mph (sec)"),wxPG_LABEL
,3.9) );
1638 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("1/4 mile (sec)"),wxPG_LABEL
,8.6) );
1640 pg
->AppendIn( pid
, new wxIntProperty(wxT("Price ($)"),
1644 // Make sure the child properties can be accessed correctly
1645 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1647 // Displayed value of "Car" property is now:
1648 // "Lamborghini Diablo SV; [300; 3.9; 8.6]; 300000"
1651 // Test wxSampleMultiButtonEditor
1652 wxPGRegisterEditorClass( SampleMultiButtonEditor
);
1653 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1654 pg
->SetPropertyEditor(wxT("MultipleButtons"), wxPG_EDITOR(SampleMultiButtonEditor
) );
1656 // Test SingleChoiceProperty
1657 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1661 // Test adding variable height bitmaps in wxPGChoices
1664 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1665 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1666 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1668 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1674 // Test how non-editable composite strings appear
1675 pid
= pg
->Append( new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>")) );
1676 pg
->SetPropertyReadOnly(pid
);
1678 pg
->AppendIn(pid
, new wxStringProperty(wxT("Latest Release"), wxPG_LABEL
, wxT("2.8.8")) );
1679 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Win API"), wxPG_LABEL
, true) );
1680 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1681 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1682 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1683 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1684 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1685 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1686 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1688 AddTestProperties(pg
);
1691 // -----------------------------------------------------------------------
1693 void FormMain::PopulateWithLibraryConfig ()
1695 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1696 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1700 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1704 #define ADD_WX_LIB_CONF_GROUP(A) \
1705 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1706 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp );
1708 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1709 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1710 pg->DisableProperty(wxT(#A));
1712 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1713 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1715 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1716 ADD_WX_LIB_CONF( wxUSE_GUI
)
1718 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1719 #if defined(WXWIN_COMPATIBILITY_2_2)
1720 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1722 #if defined(WXWIN_COMPATIBILITY_2_4)
1723 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1725 #if defined(WXWIN_COMPATIBILITY_2_6)
1726 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1728 #if defined(WXWIN_COMPATIBILITY_2_8)
1729 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1731 #ifdef wxFONT_SIZE_COMPATIBILITY
1732 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1734 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1736 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1737 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1739 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1742 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1743 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1744 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1745 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1746 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1747 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1749 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1750 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1751 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1752 ADD_WX_LIB_CONF( wxUSE_WCHAR_T
)
1754 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1755 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1756 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1757 ADD_WX_LIB_CONF( wxUSE_STL
)
1758 ADD_WX_LIB_CONF( wxUSE_LOG
)
1759 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1760 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1761 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1762 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1763 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1764 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1765 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1767 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1768 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1769 ADD_WX_LIB_CONF( wxUSE_FILE
)
1770 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1771 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1772 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1773 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1774 ADD_WX_LIB_CONF( wxUSE_INTL
)
1775 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1776 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1777 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1778 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1779 #ifdef wxUSE_CONFIG_NATIVE
1780 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1782 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1784 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1785 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1786 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1787 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1788 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1789 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1790 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1791 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1792 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1793 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1794 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1795 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1796 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1797 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1798 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1799 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1800 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1801 ADD_WX_LIB_CONF( wxUSE_URL
)
1802 #ifdef wxUSE_URL_NATIVE
1803 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1805 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1807 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1808 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1809 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1811 ADD_WX_LIB_CONF( wxUSE_XRC
)
1813 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1815 ADD_WX_LIB_CONF( wxUSE_XML
)
1817 // Set them to use check box.
1818 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1823 // Handle events of the third page here.
1824 class wxMyPropertyGridPage
: public wxPropertyGridPage
1828 // Return false here to indicate unhandled events should be
1829 // propagated to manager's parent, as normal.
1830 virtual bool IsHandlingAllEvents() const { return false; }
1834 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1836 wxPGProperty
* property
)
1838 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1841 void OnPropertySelect( wxPropertyGridEvent
& event
);
1842 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1843 void OnPropertyChange( wxPropertyGridEvent
& event
);
1844 void OnPageChange( wxPropertyGridEvent
& event
);
1847 DECLARE_EVENT_TABLE()
1851 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1852 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1853 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1854 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1855 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1859 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1861 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1864 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1866 wxPGProperty
* p
= event
.GetProperty();
1867 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1868 p
->GetName().c_str(),
1869 p
->GetDisplayedString().c_str());
1872 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1874 wxPGProperty
* p
= event
.GetProperty();
1875 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1876 p
->GetName().c_str(),
1877 event
.GetValue().GetString().c_str());
1880 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1882 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1886 class wxPGKeyHandler
: public wxEvtHandler
1890 void OnKeyEvent( wxKeyEvent
& event
)
1892 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1896 DECLARE_EVENT_TABLE()
1899 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1900 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1904 // -----------------------------------------------------------------------
1906 void FormMain::InitPanel()
1911 wxWindow
* panel
= new wxPanel(this,-1,wxPoint(0,0),wxSize(400,400));
1915 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1917 m_topSizer
= topSizer
;
1920 void FormMain::FinalizePanel( bool wasCreated
)
1922 m_panel
->SetSizer( m_topSizer
);
1923 m_topSizer
->SetSizeHints( m_panel
);
1925 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1926 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1927 SetSizer( panelSizer
);
1928 panelSizer
->SetSizeHints( this );
1933 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
1934 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
1940 void FormMain::PopulateGrid()
1942 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1943 pgman
->AddPage(wxT("Standard Items"));
1945 PopulateWithStandardItems();
1947 pgman
->AddPage(wxT("wxWidgets Library Config"));
1949 PopulateWithLibraryConfig();
1951 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1952 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1954 // Use wxMyPropertyGridPage (see above) to test the
1955 // custom wxPropertyGridPage feature.
1956 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1958 PopulateWithExamples();
1961 void FormMain::CreateGrid( int style
, int extraStyle
)
1964 // This function (re)creates the property grid in our sample
1968 style
= // default style
1969 wxPG_BOLD_MODIFIED
|
1970 wxPG_SPLITTER_AUTO_CENTER
|
1972 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1974 //wxPG_HIDE_CATEGORIES |
1975 //wxPG_LIMITED_EDITING |
1980 if ( extraStyle
== -1 )
1981 // default extra style
1982 extraStyle
= wxPG_EX_MODE_BUTTONS
;
1983 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1984 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1985 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1986 //| wxPG_EX_HELP_AS_TOOLTIPS
1988 bool wasCreated
= m_panel
? false : true;
1993 // This shows how to combine two static choice descriptors
1994 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1995 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1997 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1998 new wxPropertyGridManager(m_panel
,
1999 // Don't change this into wxID_ANY in the sample, or the
2000 // event handling will obviously be broken.
2006 m_propGrid
= pgman
->GetGrid();
2008 pgman
->SetExtraStyle(extraStyle
);
2010 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_BEEP
| wxPG_VFB_MARK_CELL
| wxPG_VFB_SHOW_MESSAGE
);
2012 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
2016 // Change some attributes in all properties
2017 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
2018 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
2020 //m_pPropGridManager->SetSplitterLeft(true);
2021 //m_pPropGridManager->SetSplitterPosition(137);
2024 // This would setup event handling without event table entries
2025 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
2026 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2027 &FormMain::OnPropertyGridSelect );
2028 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
2029 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2030 &FormMain::OnPropertyGridChange );
2033 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
2035 FinalizePanel(wasCreated
);
2038 // -----------------------------------------------------------------------
2040 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
2041 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
2042 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
2043 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
2049 // we need this in order to allow the about menu relocation, since ABOUT is
2050 // not the default id of the about menu
2051 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
2055 // This is here to really test the wxImageFileProperty.
2056 wxInitAllImageHandlers();
2059 CreateGrid( // style
2060 wxPG_BOLD_MODIFIED
|
2061 wxPG_SPLITTER_AUTO_CENTER
|
2063 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2065 //wxPG_HIDE_CATEGORIES |
2066 //wxPG_LIMITED_EDITING |
2071 wxPG_EX_MODE_BUTTONS
2072 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2073 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2074 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2075 //| wxPG_EX_HELP_AS_TOOLTIPS
2078 // Register all editors (SpinCtrl etc.)
2079 m_pPropGridManager
->RegisterAdditionalEditors();
2083 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2084 wxMenu
*menuTry
= new wxMenu
;
2085 wxMenu
*menuTools1
= new wxMenu
;
2086 wxMenu
*menuTools2
= new wxMenu
;
2087 wxMenu
*menuHelp
= new wxMenu
;
2089 menuHelp
->Append(ID_ABOUT
, wxT("&About..."), wxT("Show about dialog") );
2091 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2092 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2093 menuTools1
->AppendSeparator();
2094 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2095 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2096 menuTools1
->AppendSeparator();
2097 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2098 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2099 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2100 menuTools1
->AppendSeparator();
2101 menuTools1
->Append(ID_SETCOLOUR
, wxT("Set Bg Colour") );
2102 menuTools1
->Append(ID_UNSPECIFY
, wxT("Set to Unspecified") );
2103 menuTools1
->Append(ID_CLEAR
, wxT("Set Value to Default") );
2104 menuTools1
->AppendSeparator();
2105 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2106 wxT("Toggles item's enabled state.") );
2107 m_itemEnable
->Enable( FALSE
);
2108 menuTools1
->Append(ID_HIDE
, wxT("Hide"), wxT("Shows or hides a property") );
2110 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2111 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2112 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2113 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2114 menuTools2
->AppendSeparator();
2115 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2116 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2117 menuTools2
->AppendSeparator();
2118 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2119 wxT("Disables painting, auto-sorting, etc.") );
2120 menuTools2
->AppendSeparator();
2121 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2122 menuTools2
->AppendSeparator();
2123 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2124 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2125 menuTools2
->Append(ID_SETVALUES2
, wxT("Set Property Values 2"), wxT("Adds property values that should not initially be as items (so new items are created).") );
2126 menuTools2
->AppendSeparator();
2127 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2128 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2129 menuTools2
->AppendSeparator();
2130 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2131 wxT("Enable values that are common to all properties, for selected property."));
2132 menuTools2
->AppendSeparator();
2133 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2134 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2135 menuTools2
->AppendSeparator();
2136 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2137 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2138 menuTools2
->AppendSeparator();
2139 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2140 menuTools2
->AppendSeparator();
2141 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2142 menuTools2
->AppendSeparator();
2143 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2144 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2145 menuTools2
->AppendSeparator();
2146 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2147 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2149 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2150 wxT("Select window style flags used by the grid."));
2151 menuTry
->AppendSeparator();
2152 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2153 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2154 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2155 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2156 menuTry
->AppendSeparator();
2157 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2158 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2159 menuTry
->AppendSeparator();
2160 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2161 wxT("Switches between user-modifiedable and static layouts.") );
2162 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2163 menuTry
->AppendSeparator();
2164 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2165 menuTry
->AppendSeparator();
2166 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2167 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2169 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2170 menuFile
->AppendSeparator();
2171 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2173 // Now append the freshly created menu to the menu bar...
2174 wxMenuBar
*menuBar
= new wxMenuBar();
2175 menuBar
->Append(menuFile
, wxT("&File") );
2176 menuBar
->Append(menuTry
, wxT("&Try These!") );
2177 menuBar
->Append(menuTools1
, wxT("&Basic") );
2178 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2179 menuBar
->Append(menuHelp
, wxT("&Help") );
2181 // ... and attach this menu bar to the frame
2182 SetMenuBar(menuBar
);
2185 // create a status bar
2187 SetStatusText(wxEmptyString
);
2188 #endif // wxUSE_STATUSBAR
2196 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2197 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2203 // Normally, wxPropertyGrid does not check whether item with identical
2204 // label already exists. However, since in this sample we use labels for
2205 // identifying properties, we have to be sure not to generate identical
2208 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2213 if ( pg
->GetPropertyByLabel( baselabel
) )
2218 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2219 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2225 baselabel
= newlabel
;
2229 // -----------------------------------------------------------------------
2231 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2235 if ( !m_pPropGridManager
->GetChildrenCount() )
2237 wxMessageBox(wxT("No items to relate - first add some with Append."));
2241 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2244 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2247 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2249 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2251 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2252 m_pPropGridManager
->GetPropertyIndex(id
),
2253 new wxStringProperty(propLabel
) );
2257 // -----------------------------------------------------------------------
2259 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2263 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2265 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2267 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2269 m_pPropGridManager
->Refresh();
2272 // -----------------------------------------------------------------------
2274 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2276 m_pPropGridManager
->GetGrid()->Clear();
2279 // -----------------------------------------------------------------------
2281 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2285 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2287 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2289 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2291 m_pPropGridManager
->Refresh();
2295 // -----------------------------------------------------------------------
2297 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2301 if ( !m_pPropGridManager
->GetChildrenCount() )
2303 wxMessageBox(wxT("No items to relate - first add some with Append."));
2307 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2310 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2314 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2316 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2318 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2319 m_pPropGridManager
->GetPropertyIndex(id
),
2320 new wxPropertyCategory (propLabel
) );
2324 // -----------------------------------------------------------------------
2326 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2328 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2331 wxMessageBox(wxT("First select a property."));
2335 m_pPropGridManager
->DeleteProperty( id
);
2338 // -----------------------------------------------------------------------
2340 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2342 // Delete random property
2343 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2347 if ( !p
->IsCategory() )
2349 m_pPropGridManager
->DeleteProperty( p
);
2353 if ( !p
->GetChildCount() )
2356 int n
= rand() % ((int)p
->GetChildCount());
2362 // -----------------------------------------------------------------------
2364 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2366 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2367 event
.GetPosition().x
,event
.GetPosition().y
);
2372 // -----------------------------------------------------------------------
2374 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2376 /*#ifdef __WXDEBUG__
2377 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2378 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2384 // -----------------------------------------------------------------------
2386 int IterateMessage( wxPGProperty
* prop
)
2390 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2391 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2393 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2396 // -----------------------------------------------------------------------
2398 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2400 wxPropertyGridIterator it
;
2402 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2407 wxPGProperty
* p
= *it
;
2408 int res
= IterateMessage( p
);
2409 if ( res
== wxCANCEL
) break;
2413 // -----------------------------------------------------------------------
2415 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2417 wxPropertyGridIterator it
;
2419 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2420 GetIterator( wxPG_ITERATE_VISIBLE
);
2424 wxPGProperty
* p
= *it
;
2426 int res
= IterateMessage( p
);
2427 if ( res
== wxCANCEL
) break;
2431 // -----------------------------------------------------------------------
2433 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2435 // iterate over items in reverse order
2436 wxPropertyGridIterator it
;
2438 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2439 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2443 wxPGProperty
* p
= *it
;
2445 int res
= IterateMessage( p
);
2446 if ( res
== wxCANCEL
) break;
2450 // -----------------------------------------------------------------------
2452 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2454 wxPropertyGridIterator it
;
2456 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2457 GetIterator( wxPG_ITERATE_CATEGORIES
);
2461 wxPGProperty
* p
= *it
;
2463 int res
= IterateMessage( p
);
2464 if ( res
== wxCANCEL
) break;
2468 // -----------------------------------------------------------------------
2470 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2472 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2474 // Remove auto-centering
2475 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2477 // Grow manager size just prior fit - otherwise
2478 // column information may be lost.
2479 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2480 wxSize oldFullSize
= GetSize();
2481 SetSize(1000, oldFullSize
.y
);
2483 wxSize newSz
= page
->FitColumns();
2485 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2486 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2494 // -----------------------------------------------------------------------
2496 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2499 wxPGProperty
* id
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2501 wxPGChoices newChoices
;
2503 newChoices
.Add(wxT("Fast"),0x1);
2504 newChoices
.Add(wxT("Powerful"),0x2);
2505 newChoices
.Add(wxT("Safe"),0x4);
2506 newChoices
.Add(wxT("Sleek"),0x8);
2508 m_pPropGridManager
->SetPropertyChoices(id
,newChoices
);
2509 //m_pPropGridManager->ReplaceProperty(wxT("Window Styles"),
2510 // wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL,newChoices));
2513 // -----------------------------------------------------------------------
2515 void FormMain::OnEnableDisable( wxCommandEvent
& )
2517 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2520 wxMessageBox(wxT("First select a property."));
2524 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2526 m_pPropGridManager
->DisableProperty ( id
);
2527 m_itemEnable
->SetItemLabel( wxT("Enable") );
2531 m_pPropGridManager
->EnableProperty ( id
);
2532 m_itemEnable
->SetItemLabel( wxT("Disable") );
2536 // -----------------------------------------------------------------------
2538 void FormMain::OnHideShow( wxCommandEvent
& WXUNUSED(event
) )
2540 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2543 wxMessageBox(wxT("First select a property."));
2547 if ( m_pPropGridManager
->IsPropertyShown( id
) )
2549 m_pPropGridManager
->HideProperty( id
, true );
2550 m_itemEnable
->SetItemLabel( wxT("Show") );
2554 m_pPropGridManager
->HideProperty( id
, false );
2555 m_itemEnable
->SetItemLabel( wxT("Hide") );
2558 wxPropertyGridPage
* curPage
= m_pPropGridManager
->GetCurrentPage();
2560 // Check for bottomY precalculation validity
2561 unsigned int byPre
= curPage
->GetVirtualHeight();
2562 unsigned int byAct
= curPage
->GetActualVirtualHeight();
2564 if ( byPre
!= byAct
)
2566 wxLogDebug(wxT("VirtualHeight is %u, should be %u"), byPre
, byAct
);
2570 // -----------------------------------------------------------------------
2572 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2574 m_pPropGridManager
->AddPage(wxT("New Page"));
2577 // -----------------------------------------------------------------------
2579 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2581 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2584 // -----------------------------------------------------------------------
2586 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2588 m_savedState
= m_pPropGridManager
->SaveEditableState();
2589 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2592 // -----------------------------------------------------------------------
2594 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2596 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2599 // -----------------------------------------------------------------------
2601 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2604 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2606 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPG_EDITOR(SpinCtrl
) );
2608 wxMessageBox(wxT("First select a property"));
2612 // -----------------------------------------------------------------------
2614 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2616 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2619 wxPGChoices choices
;
2620 choices
.Add(wxT("Flag 0"),0x0001);
2621 choices
.Add(wxT("Flag 1"),0x0002);
2622 choices
.Add(wxT("Flag 2"),0x0004);
2623 choices
.Add(wxT("Flag 3"),0x0008);
2624 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2625 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2626 m_pPropGridManager
->SetPropertyAttribute( newId
,
2627 wxPG_BOOL_USE_CHECKBOX
,
2632 wxMessageBox(wxT("First select a property"));
2635 // -----------------------------------------------------------------------
2637 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2639 m_pPropGridManager
->ClearModifiedStatus();
2642 // -----------------------------------------------------------------------
2644 // Freeze check-box checked?
2645 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2647 if ( !m_pPropGridManager
) return;
2649 if ( event
.IsChecked() )
2651 if ( !m_pPropGridManager
->IsFrozen() )
2653 m_pPropGridManager
->Freeze();
2658 if ( m_pPropGridManager
->IsFrozen() )
2660 m_pPropGridManager
->Thaw();
2661 m_pPropGridManager
->Refresh();
2666 // -----------------------------------------------------------------------
2668 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2671 msg
.Printf( wxT("wxPropertyGrid Sample")
2673 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2687 wxT("Programmed by %s\n\n")
2688 wxT("Using %s\n\n"),
2689 wxT("Jaakko Salli"), wxVERSION_STRING
2692 wxMessageBox(msg
, _T("About"), wxOK
| wxICON_INFORMATION
, this);
2695 // -----------------------------------------------------------------------
2697 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2699 int id
= event
.GetId();
2700 if ( id
== ID_COLOURSCHEME1
)
2702 m_pPropGridManager
->GetGrid()->ResetColours();
2704 else if ( id
== ID_COLOURSCHEME2
)
2707 wxColour
my_grey_1(212,208,200);
2708 wxColour
my_grey_3(113,111,100);
2709 m_pPropGridManager
->Freeze();
2710 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2711 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2712 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2713 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2714 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2715 m_pPropGridManager
->Thaw();
2717 else if ( id
== ID_COLOURSCHEME3
)
2720 wxColour
my_grey_1(212,208,200);
2721 wxColour
my_grey_2(236,233,216);
2722 m_pPropGridManager
->Freeze();
2723 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2724 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2725 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2726 m_pPropGridManager
->Thaw();
2728 else if ( id
== ID_COLOURSCHEME4
)
2732 wxColour
my_grey_1(212,208,200);
2733 wxColour
my_grey_2(241,239,226);
2734 wxColour
my_grey_3(113,111,100);
2735 m_pPropGridManager
->Freeze();
2736 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2737 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2738 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2739 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2740 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2741 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2742 m_pPropGridManager
->Thaw();
2746 // -----------------------------------------------------------------------
2748 void FormMain::OnCatColours( wxCommandEvent
& event
)
2750 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2751 m_pPropGridManager
->Freeze();
2753 if ( event
.IsChecked() )
2755 // Set custom colours.
2756 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2757 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2758 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2759 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2760 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2761 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2762 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2763 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2764 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2765 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2766 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2770 // Revert to original.
2771 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2772 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2773 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2774 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2776 m_pPropGridManager
->Thaw();
2777 m_pPropGridManager
->Refresh();
2780 // -----------------------------------------------------------------------
2782 #define ADD_FLAG(FLAG) \
2783 chs.Add(wxT(#FLAG)); \
2785 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2788 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2797 unsigned int ind
= 0;
2798 int flags
= m_pPropGridManager
->GetWindowStyle();
2799 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2800 ADD_FLAG(wxPG_AUTO_SORT
)
2801 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2802 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2803 ADD_FLAG(wxPG_TOOLTIPS
)
2804 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2805 ADD_FLAG(wxPG_HIDE_MARGIN
)
2806 ADD_FLAG(wxPG_LIMITED_EDITING
)
2807 ADD_FLAG(wxPG_TOOLBAR
)
2808 ADD_FLAG(wxPG_DESCRIPTION
)
2809 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2810 wxT("wxPropertyGrid Window Style"), chs
);
2811 dlg
.SetSelections(sel
);
2812 if ( dlg
.ShowModal() == wxID_CANCEL
)
2816 sel
= dlg
.GetSelections();
2817 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2818 flags
|= vls
[sel
[ind
]];
2827 unsigned int ind
= 0;
2828 int flags
= m_pPropGridManager
->GetExtraStyle();
2829 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2830 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2831 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2832 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2833 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2834 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2835 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2836 ADD_FLAG(wxPG_EX_LEGACY_VALIDATORS
)
2837 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2838 wxT("wxPropertyGrid Extra Style"), chs
);
2839 dlg
.SetSelections(sel
);
2840 if ( dlg
.ShowModal() == wxID_CANCEL
)
2844 sel
= dlg
.GetSelections();
2845 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2846 flags
|= vls
[sel
[ind
]];
2851 CreateGrid( style
, extraStyle
);
2854 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2855 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2860 // -----------------------------------------------------------------------
2862 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2864 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2865 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2868 if ( colCount
>= 2 )
2870 m_pPropGridManager
->SetColumnCount(colCount
);
2874 // -----------------------------------------------------------------------
2876 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2878 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2879 wxPGProperty
* selected
= pg
->GetSelection();
2883 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2884 pg
->SetPropertyValue( selected
, value
);
2888 // -----------------------------------------------------------------------
2890 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2892 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2894 wxPGProperty
* selected
= pg
->GetSelection();
2895 wxPGChoices
& choices
= pg
->GetPropertyChoices(selected
);
2897 // Insert new choice to the center of list
2899 if ( choices
.IsOk() )
2901 int pos
= choices
.GetCount() / 2;
2902 pg
->InsertPropertyChoice(selected
,wxT("New Choice"),pos
);
2906 ::wxMessageBox(wxT("First select a property with some choices."));
2910 // -----------------------------------------------------------------------
2912 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2914 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2916 wxPGProperty
* selected
= pg
->GetSelection();
2917 wxPGChoices
& choices
= pg
->GetPropertyChoices(selected
);
2919 // Deletes choice from the center of list
2921 if ( choices
.IsOk() )
2923 int pos
= choices
.GetCount() / 2;
2924 pg
->DeletePropertyChoice(selected
,pos
);
2928 ::wxMessageBox(wxT("First select a property with some choices."));
2932 // -----------------------------------------------------------------------
2934 #include <wx/colordlg.h>
2936 void FormMain::OnMisc ( wxCommandEvent
& event
)
2938 int id
= event
.GetId();
2939 if ( id
== ID_STATICLAYOUT
)
2941 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2942 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2943 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2945 else if ( id
== ID_CLEAR
)
2947 m_pPropGridManager
->ClearPropertyValue(m_pPropGridManager
->GetGrid()->GetSelection());
2949 else if ( id
== ID_COLLAPSEALL
)
2952 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2954 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2955 it
.GetProperty()->SetExpanded( false );
2959 else if ( id
== ID_GETVALUES
)
2961 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2962 m_pPropGridManager
->GetGrid()->GetRoot(),
2963 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2965 else if ( id
== ID_SETVALUES
)
2967 if ( m_storedValues
.GetType() == wxT("list") )
2969 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2972 wxMessageBox(wxT("First use Get Property Values."));
2974 else if ( id
== ID_SETVALUES2
)
2978 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2979 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2980 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2981 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2983 else if ( id
== ID_COLLAPSE
)
2985 // Collapses selected.
2986 wxPGProperty
* id
= m_pPropGridManager
->GetSelectedProperty();
2989 m_pPropGridManager
->Collapse(id
);
2992 else if ( id
== ID_RUNTESTFULL
)
2994 // Runs a regression test.
2997 else if ( id
== ID_RUNTESTPARTIAL
)
2999 // Runs a regression test.
3002 else if ( id
== ID_UNSPECIFY
)
3004 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
3007 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3010 else if ( id
== ID_SETCOLOUR
)
3012 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
3016 data
.SetChooseFull(true);
3018 for ( i
= 0; i
< 16; i
++)
3020 wxColour
colour(i
*16, i
*16, i
*16);
3021 data
.SetCustomColour(i
, colour
);
3024 wxColourDialog
dialog(this, &data
);
3025 if ( dialog
.ShowModal() == wxID_OK
)
3027 wxColourData retData
= dialog
.GetColourData();
3028 m_pPropGridManager
->GetGrid()->SetPropertyBackgroundColour(prop
,retData
.GetColour());
3034 // -----------------------------------------------------------------------
3036 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3038 int id
= event
.GetId();
3039 m_propGrid
->Clear();
3040 m_propGrid
->Freeze();
3041 if ( id
== ID_POPULATE1
)
3043 PopulateWithStandardItems();
3045 else if ( id
== ID_POPULATE2
)
3047 PopulateWithLibraryConfig();
3052 // -----------------------------------------------------------------------
3054 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3056 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3058 DisplayMinimalFrame(this);
3061 // -----------------------------------------------------------------------
3063 FormMain::~FormMain()
3067 // -----------------------------------------------------------------------
3069 IMPLEMENT_APP(cxApplication
)
3071 bool cxApplication::OnInit()
3074 //Locale.Init(wxLANGUAGE_FINNISH);
3076 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3080 // Parse command-line
3081 wxApp
& app
= wxGetApp();
3084 wxString s
= app
.argv
[1];
3085 if ( s
== wxT("--run-tests") )
3089 bool testResult
= frame
->RunTests(true);
3099 // -----------------------------------------------------------------------
3101 void FormMain::OnIdle( wxIdleEvent
& event
)
3104 // This code is useful for debugging focus problems
3105 static wxWindow* last_focus = (wxWindow*) NULL;
3107 wxWindow* cur_focus = ::wxWindow::FindFocus();
3109 if ( cur_focus != last_focus )
3111 const wxChar* class_name = wxT("<none>");
3113 class_name = cur_focus->GetClassInfo()->GetClassName();
3114 last_focus = cur_focus;
3115 wxLogDebug( wxT("FOCUSED: %s %X"),
3117 (unsigned int)cur_focus);
3124 // -----------------------------------------------------------------------