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 bool wxAdvImageFileProperty
::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
331 wxASSERT( number
>= 0 );
332 return StringToValue( variant
, ms_choices
.GetLabel(number
), wxPG_FULL_VALUE
);
335 bool wxAdvImageFileProperty
::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* primary
,
338 if ( propgrid
->IsMainButtonEvent(event
) )
340 return wxFileProperty
::OnEvent(propgrid
,primary
,event
);
345 wxSize wxAdvImageFileProperty
::OnMeasureImage( int item
) const
348 return wxPG_DEFAULT_IMAGE_SIZE
;
350 return wxSize(PREF_THUMBNAIL_HEIGHT
,PREF_THUMBNAIL_HEIGHT
);
353 void wxAdvImageFileProperty
::LoadThumbnails( size_t index
)
355 wxMyImageInfo
& mii
= g_myImageArray
[index
];
357 if ( !mii
.m_pThumbnail2
)
360 if ( !m_pImage
|| !m_pImage
->Ok() ||
361 m_filename
!= mii
.m_path
366 m_pImage
= new wxImage( mii
.m_path
);
369 if ( m_pImage
&& m_pImage
->Ok() )
371 int im_wid
= m_pImage
->GetWidth();
372 int im_hei
= m_pImage
->GetHeight();
373 if ( im_hei
> PREF_THUMBNAIL_HEIGHT
)
376 im_wid
= (PREF_THUMBNAIL_HEIGHT
*m_pImage
->GetWidth())/m_pImage
->GetHeight();
377 im_hei
= PREF_THUMBNAIL_HEIGHT
;
380 m_pImage
->Rescale( im_wid
, im_hei
);
382 mii
.m_pThumbnail2
= new wxBitmap( *m_pImage
);
384 wxSize cis
= GetParentState()->GetGrid()->GetImageSize();
385 m_pImage
->Rescale ( cis
.x
, cis
.y
);
387 mii
.m_pThumbnail1
= new wxBitmap( *m_pImage
);
394 m_pImage
= (wxImage
*) NULL
;
399 void wxAdvImageFileProperty
::OnCustomPaint( wxDC
& dc
,
404 if ( pd
.m_choiceItem
>= 0 )
405 index
= pd
.m_choiceItem
;
407 //wxLogDebug(wxT("%i"),index);
411 LoadThumbnails(index
);
413 // Is this a measure item call?
417 //pd.m_drawnHeight = PREF_THUMBNAIL_HEIGHT;
418 wxBitmap
* pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail2
;
420 pd
.m_drawnHeight
= pBitmap
->GetHeight();
422 pd
.m_drawnHeight
= 16;
426 // Draw the thumbnail
430 if ( pd
.m_choiceItem
>= 0 )
431 pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail2
;
433 pBitmap
= (wxBitmap
*)g_myImageArray
[index
].m_pThumbnail1
;
437 dc
.DrawBitmap ( *pBitmap
, rect
.x
, rect
.y
, FALSE
);
439 // Tell the caller how wide we drew.
440 pd
.m_drawnWidth
= pBitmap
->GetWidth();
446 // No valid file - just draw a white box.
447 dc
.SetBrush ( *wxWHITE_BRUSH
);
448 dc
.DrawRectangle ( rect
);
452 // -----------------------------------------------------------------------
454 // -----------------------------------------------------------------------
456 // See propgridsample.h for wxVector3f class
458 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
460 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
461 wxVector3f
,const wxVector3f
&,TextCtrl
)
464 wxVectorProperty
::wxVectorProperty( const wxString
& label
,
465 const wxString
& name
,
466 const wxVector3f
& value
)
467 : wxPGProperty(label
,name
)
469 SetValue( WXVARIANT(value
) );
470 AddChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
471 AddChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
472 AddChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
475 wxVectorProperty
::~wxVectorProperty() { }
477 void wxVectorProperty
::RefreshChildren()
479 if ( !GetChildCount() ) return;
480 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
481 Item(0)->SetValue( vector
.x
);
482 Item(1)->SetValue( vector
.y
);
483 Item(2)->SetValue( vector
.z
);
486 void wxVectorProperty
::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
490 switch ( childIndex
)
492 case 0: vector
.x
= childValue
.GetDouble(); break;
493 case 1: vector
.y
= childValue
.GetDouble(); break;
494 case 2: vector
.z
= childValue
.GetDouble(); break;
500 // -----------------------------------------------------------------------
501 // wxTriangleProperty
502 // -----------------------------------------------------------------------
504 // See propgridsample.h for wxTriangle class
506 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
508 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
509 wxTriangle
,const wxTriangle
&,TextCtrl
)
512 wxTriangleProperty
::wxTriangleProperty( const wxString
& label
,
513 const wxString
& name
,
514 const wxTriangle
& value
)
515 : wxPGProperty(label
,name
)
517 SetValue( WXVARIANT(value
) );
518 AddChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
519 AddChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
520 AddChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
523 wxTriangleProperty
::~wxTriangleProperty() { }
525 void wxTriangleProperty
::RefreshChildren()
527 if ( !GetChildCount() ) return;
528 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
529 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
530 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
531 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
534 void wxTriangleProperty
::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
537 triangle
<< thisValue
;
538 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
539 switch ( childIndex
)
541 case 0: triangle
.a
= vector
; break;
542 case 1: triangle
.b
= vector
; break;
543 case 2: triangle
.c
= vector
; break;
545 thisValue
<< triangle
;
549 // -----------------------------------------------------------------------
550 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
551 // -----------------------------------------------------------------------
553 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
557 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
558 : wxPGEditorDialogAdapter(), m_choices(choices
)
562 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
563 wxPGProperty
* WXUNUSED(property
) )
565 wxString s
= ::wxGetSingleChoice(wxT("Message"),
567 m_choices
.GetLabels());
578 const wxPGChoices
& m_choices
;
582 class SingleChoiceProperty
: public wxStringProperty
586 SingleChoiceProperty( const wxString
& label
,
587 const wxString
& name
= wxPG_LABEL
,
588 const wxString
& value
= wxEmptyString
)
589 : wxStringProperty(label
, name
, value
)
592 m_choices
.Add(wxT("Cat"));
593 m_choices
.Add(wxT("Dog"));
594 m_choices
.Add(wxT("Gibbon"));
595 m_choices
.Add(wxT("Otter"));
598 // Set editor to have button
599 virtual const wxPGEditor
* DoGetEditorClass() const
601 return wxPG_EDITOR(TextCtrlAndButton
);
604 // Set what happens on button click
605 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
607 return new wxSingleChoiceDialogAdapter(m_choices
);
611 wxPGChoices m_choices
;
614 // -----------------------------------------------------------------------
616 // -----------------------------------------------------------------------
663 ID_SETSPINCTRLEDITOR
,
668 ID_ENABLECOMMONVALUES
,
675 // -----------------------------------------------------------------------
677 // -----------------------------------------------------------------------
679 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
680 EVT_IDLE(FormMain
::OnIdle
)
681 EVT_MOVE(FormMain
::OnMove
)
682 EVT_SIZE(FormMain
::OnResize
)
684 // This occurs when a property is selected
685 EVT_PG_SELECTED( PGID
, FormMain
::OnPropertyGridSelect
)
686 // This occurs when a property value changes
687 EVT_PG_CHANGED( PGID
, FormMain
::OnPropertyGridChange
)
688 // This occurs just prior a property value is changed
689 EVT_PG_CHANGING( PGID
, FormMain
::OnPropertyGridChanging
)
690 // This occurs when a mouse moves over another property
691 EVT_PG_HIGHLIGHTED( PGID
, FormMain
::OnPropertyGridHighlight
)
692 // This occurs when mouse is right-clicked.
693 EVT_PG_RIGHT_CLICK( PGID
, FormMain
::OnPropertyGridItemRightClick
)
694 // This occurs when mouse is double-clicked.
695 EVT_PG_DOUBLE_CLICK( PGID
, FormMain
::OnPropertyGridItemDoubleClick
)
696 // This occurs when propgridmanager's page changes.
697 EVT_PG_PAGE_CHANGED( PGID
, FormMain
::OnPropertyGridPageChange
)
698 // This occurs when property's editor button (if any) is clicked.
699 EVT_BUTTON( PGID
, FormMain
::OnPropertyGridButtonClick
)
701 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain
::OnPropertyGridItemCollapse
)
702 EVT_PG_ITEM_EXPANDED( PGID
, FormMain
::OnPropertyGridItemExpand
)
704 EVT_TEXT( PGID
, FormMain
::OnPropertyGridTextUpdate
)
707 // Rest of the events are not property grid specific
708 EVT_KEY_DOWN( FormMain
::OnPropertyGridKeyEvent
)
709 EVT_KEY_UP( FormMain
::OnPropertyGridKeyEvent
)
711 EVT_MENU( ID_APPENDPROP
, FormMain
::OnAppendPropClick
)
712 EVT_MENU( ID_APPENDCAT
, FormMain
::OnAppendCatClick
)
713 EVT_MENU( ID_INSERTPROP
, FormMain
::OnInsertPropClick
)
714 EVT_MENU( ID_INSERTCAT
, FormMain
::OnInsertCatClick
)
715 EVT_MENU( ID_DELETE
, FormMain
::OnDelPropClick
)
716 EVT_MENU( ID_DELETER
, FormMain
::OnDelPropRClick
)
717 EVT_MENU( ID_UNSPECIFY
, FormMain
::OnMisc
)
718 EVT_MENU( ID_DELETEALL
, FormMain
::OnClearClick
)
719 EVT_MENU( ID_ENABLE
, FormMain
::OnEnableDisable
)
720 EVT_MENU( ID_HIDE
, FormMain
::OnHideShow
)
721 EVT_MENU( ID_ITERATE1
, FormMain
::OnIterate1Click
)
722 EVT_MENU( ID_ITERATE2
, FormMain
::OnIterate2Click
)
723 EVT_MENU( ID_ITERATE3
, FormMain
::OnIterate3Click
)
724 EVT_MENU( ID_ITERATE4
, FormMain
::OnIterate4Click
)
725 EVT_MENU( ID_SETCOLOUR
, FormMain
::OnMisc
)
726 EVT_MENU( ID_CLEARMODIF
, FormMain
::OnClearModifyStatusClick
)
727 EVT_MENU( ID_FREEZE
, FormMain
::OnFreezeClick
)
728 EVT_MENU( ID_DUMPLIST
, FormMain
::OnDumpList
)
730 EVT_MENU( ID_COLOURSCHEME1
, FormMain
::OnColourScheme
)
731 EVT_MENU( ID_COLOURSCHEME2
, FormMain
::OnColourScheme
)
732 EVT_MENU( ID_COLOURSCHEME3
, FormMain
::OnColourScheme
)
733 EVT_MENU( ID_COLOURSCHEME4
, FormMain
::OnColourScheme
)
735 EVT_MENU( ID_ABOUT
, FormMain
::OnAbout
)
736 EVT_MENU( ID_QUIT
, FormMain
::OnCloseClick
)
738 EVT_MENU( ID_CATCOLOURS
, FormMain
::OnCatColours
)
739 EVT_MENU( ID_SETCOLUMNS
, FormMain
::OnSetColumns
)
740 EVT_MENU( ID_TESTXRC
, FormMain
::OnTestXRC
)
741 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain
::OnEnableCommonValues
)
742 EVT_MENU( ID_SELECTSTYLE
, FormMain
::OnSelectStyle
)
744 EVT_MENU( ID_STATICLAYOUT
, FormMain
::OnMisc
)
745 EVT_MENU( ID_CLEAR
, FormMain
::OnMisc
)
746 EVT_MENU( ID_COLLAPSE
, FormMain
::OnMisc
)
747 EVT_MENU( ID_COLLAPSEALL
, FormMain
::OnMisc
)
749 EVT_MENU( ID_POPULATE1
, FormMain
::OnPopulateClick
)
750 EVT_MENU( ID_POPULATE2
, FormMain
::OnPopulateClick
)
752 EVT_MENU( ID_GETVALUES
, FormMain
::OnMisc
)
753 EVT_MENU( ID_SETVALUES
, FormMain
::OnMisc
)
754 EVT_MENU( ID_SETVALUES2
, FormMain
::OnMisc
)
756 EVT_MENU( ID_FITCOLUMNS
, FormMain
::OnFitColumnsClick
)
758 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain
::OnChangeFlagsPropItemsClick
)
760 EVT_MENU( ID_RUNTESTFULL
, FormMain
::OnMisc
)
761 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain
::OnMisc
)
763 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain
::OnInsertChoice
)
764 EVT_MENU( ID_TESTDELETECHOICE
, FormMain
::OnDeleteChoice
)
766 EVT_MENU( ID_INSERTPAGE
, FormMain
::OnInsertPage
)
767 EVT_MENU( ID_REMOVEPAGE
, FormMain
::OnRemovePage
)
769 EVT_MENU( ID_SAVESTATE
, FormMain
::OnSaveState
)
770 EVT_MENU( ID_RESTORESTATE
, FormMain
::OnRestoreState
)
772 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain
::OnSetSpinCtrlEditorClick
)
773 EVT_MENU( ID_TESTREPLACE
, FormMain
::OnTestReplaceClick
)
774 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain
::OnSetPropertyValue
)
776 EVT_MENU( ID_RUNMINIMAL
, FormMain
::OnRunMinimalClick
)
778 EVT_CONTEXT_MENU( FormMain
::OnContextMenu
)
781 // -----------------------------------------------------------------------
783 void FormMain
::OnMove( wxMoveEvent
& event
)
785 if ( !m_pPropGridManager
)
787 // this check is here so the frame layout can be tested
788 // without creating propertygrid
793 // Update position properties
799 // Must check if properties exist (as they may be deleted).
801 // Using m_pPropGridManager, we can scan all pages automatically.
802 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
804 m_pPropGridManager
->SetPropertyValue( id
, x
);
806 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
808 m_pPropGridManager
->SetPropertyValue( id
, y
);
810 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
812 m_pPropGridManager
->SetPropertyValue( id
, wxPoint(x
,y
) );
814 // Should always call event.Skip() in frame's MoveEvent handler
818 // -----------------------------------------------------------------------
820 void FormMain
::OnResize( wxSizeEvent
& event
)
822 if ( !m_pPropGridManager
)
824 // this check is here so the frame layout can be tested
825 // without creating propertygrid
830 // Update size properties
837 // Must check if properties exist (as they may be deleted).
839 // Using m_pPropGridManager, we can scan all pages automatically.
840 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
841 if ( p
&& !p
->IsValueUnspecified() )
842 m_pPropGridManager
->SetPropertyValue( p
, w
);
844 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
845 if ( p
&& !p
->IsValueUnspecified() )
846 m_pPropGridManager
->SetPropertyValue( p
, h
);
848 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
850 m_pPropGridManager
->SetPropertyValue( id
, wxSize(w
,h
) );
852 // Should always call event.Skip() in frame's SizeEvent handler
856 // -----------------------------------------------------------------------
858 void FormMain
::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
860 wxPGProperty
* p
= event
.GetProperty();
862 if ( p
->GetName() == wxT("Font") )
865 wxMessageBox(wxString
::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
866 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
867 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
871 wxASSERT(event
.CanVeto());
875 // Since we ask a question, it is better if we omit any validation
877 event
.SetValidationFailureBehavior(0);
883 // Note how we use three types of value getting in this method:
884 // A) event.GetPropertyValueAsXXX
885 // B) event.GetPropertValue, and then variant's GetXXX
886 // C) grid's GetPropertyValueAsXXX(id)
888 void FormMain
::OnPropertyGridChange( wxPropertyGridEvent
& event
)
890 wxPGProperty
* property
= event
.GetProperty();
892 const wxString
& name
= property
->GetName();
893 wxVariant value
= property
->GetValue();
895 // Don't handle 'unspecified' values
896 if ( value
.IsNull() )
899 // Some settings are disabled outside Windows platform
900 if ( name
== wxT("X") )
901 SetSize ( m_pPropGridManager
->GetPropertyValueAsInt(property
), -1, -1, -1, wxSIZE_USE_EXISTING
);
902 else if ( name
== wxT("Y") )
903 // wxPGVariantToInt is safe long int value getter
904 SetSize ( -1, wxPGVariantToInt(value
), -1, -1, wxSIZE_USE_EXISTING
);
905 else if ( name
== wxT("Width") )
906 SetSize ( -1, -1, m_pPropGridManager
->GetPropertyValueAsInt(property
), -1, wxSIZE_USE_EXISTING
);
907 else if ( name
== wxT("Height") )
908 SetSize ( -1, -1, -1, wxPGVariantToInt(value
), wxSIZE_USE_EXISTING
);
909 else if ( name
== wxT("Label") )
911 SetTitle ( m_pPropGridManager
->GetPropertyValueAsString(property
) );
913 else if ( name
== wxT("Password") )
915 static int pwdMode
= 0;
917 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
923 if ( name
== wxT("Font") )
927 wxASSERT( font
.Ok() );
929 m_pPropGridManager
->SetFont( font
);
932 if ( name
== wxT("Margin Colour") )
934 wxColourPropertyValue cpv
;
936 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
938 else if ( name
== wxT("Cell Colour") )
940 wxColourPropertyValue cpv
;
942 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
944 else if ( name
== wxT("Line Colour") )
946 wxColourPropertyValue cpv
;
948 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
950 else if ( name
== wxT("Cell Text Colour") )
952 wxColourPropertyValue cpv
;
954 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
958 // -----------------------------------------------------------------------
960 void FormMain
::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
962 wxPGProperty
* property
= event
.GetProperty();
965 m_itemEnable
->Enable( TRUE
);
966 if ( property
->IsEnabled() )
967 m_itemEnable
->SetItemLabel( wxT("Disable") );
969 m_itemEnable
->SetItemLabel( wxT("Enable") );
973 m_itemEnable
->Enable( FALSE
);
977 wxPGProperty
* prop
= event
.GetProperty();
978 wxStatusBar
* sb
= GetStatusBar();
981 wxString
text(wxT("Selected: "));
982 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
983 sb
->SetStatusText ( text
);
988 // -----------------------------------------------------------------------
990 void FormMain
::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
993 wxStatusBar
* sb
= GetStatusBar();
994 wxString
text(wxT("Page Changed: "));
995 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
996 sb
->SetStatusText( text
);
1000 // -----------------------------------------------------------------------
1002 void FormMain
::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
1006 // -----------------------------------------------------------------------
1008 void FormMain
::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
1011 wxPGProperty
* prop
= event
.GetProperty();
1012 wxStatusBar
* sb
= GetStatusBar();
1015 wxString
text(wxT("Right-clicked: "));
1016 text
+= prop
->GetLabel();
1017 text
+= wxT(", name=");
1018 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1019 sb
->SetStatusText( text
);
1023 sb
->SetStatusText( wxEmptyString
);
1028 // -----------------------------------------------------------------------
1030 void FormMain
::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
1033 wxPGProperty
* prop
= event
.GetProperty();
1034 wxStatusBar
* sb
= GetStatusBar();
1037 wxString
text(wxT("Double-clicked: "));
1038 text
+= prop
->GetLabel();
1039 text
+= wxT(", name=");
1040 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1041 sb
->SetStatusText ( text
);
1045 sb
->SetStatusText ( wxEmptyString
);
1050 // -----------------------------------------------------------------------
1052 void FormMain
::OnPropertyGridButtonClick ( wxCommandEvent
& )
1055 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
1056 wxStatusBar
* sb
= GetStatusBar();
1059 wxString
text(wxT("Button clicked: "));
1060 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
1061 text
+= wxT(", name=");
1062 text
+= m_pPropGridManager
->GetPropertyName(prop
);
1063 sb
->SetStatusText( text
);
1067 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
1072 // -----------------------------------------------------------------------
1074 void FormMain
::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
1076 wxLogDebug(wxT("Item was Collapsed"));
1079 // -----------------------------------------------------------------------
1081 void FormMain
::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
1083 wxLogDebug(wxT("Item was Expanded"));
1086 // -----------------------------------------------------------------------
1088 // EVT_TEXT handling
1089 void FormMain
::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
1094 // -----------------------------------------------------------------------
1096 void FormMain
::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
1098 // Occurs on wxGTK mostly, but not wxMSW.
1101 // -----------------------------------------------------------------------
1103 void FormMain
::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
1105 // Uncomment following to allow property label modify in real-time
1106 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
1107 // if ( !p.IsOk() ) return;
1108 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
1111 // -----------------------------------------------------------------------
1113 static const wxChar
* _fs_windowstyle_labels
[] = {
1114 wxT("wxSIMPLE_BORDER"),
1115 wxT("wxDOUBLE_BORDER"),
1116 wxT("wxSUNKEN_BORDER"),
1117 wxT("wxRAISED_BORDER"),
1119 wxT("wxTRANSPARENT_WINDOW"),
1120 wxT("wxTAB_TRAVERSAL"),
1121 wxT("wxWANTS_CHARS"),
1122 #if wxNO_FULL_REPAINT_ON_RESIZE
1123 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
1126 wxT("wxALWAYS_SHOW_SB"),
1127 wxT("wxCLIP_CHILDREN"),
1128 #if wxFULL_REPAINT_ON_RESIZE
1129 wxT("wxFULL_REPAINT_ON_RESIZE"),
1131 (const wxChar
*) NULL
// terminator is always needed
1134 static const long _fs_windowstyle_values
[] = {
1140 wxTRANSPARENT_WINDOW
,
1143 #if wxNO_FULL_REPAINT_ON_RESIZE
1144 wxNO_FULL_REPAINT_ON_RESIZE
,
1149 #if wxFULL_REPAINT_ON_RESIZE
1150 wxFULL_REPAINT_ON_RESIZE
1154 static const wxChar
* _fs_framestyle_labels
[] = {
1159 wxT("wxSTAY_ON_TOP"),
1160 wxT("wxSYSTEM_MENU"),
1161 wxT("wxRESIZE_BORDER"),
1162 wxT("wxFRAME_TOOL_WINDOW"),
1163 wxT("wxFRAME_NO_TASKBAR"),
1164 wxT("wxFRAME_FLOAT_ON_PARENT"),
1165 wxT("wxFRAME_SHAPED"),
1166 (const wxChar
*) NULL
1169 static const long _fs_framestyle_values
[] = {
1177 wxFRAME_TOOL_WINDOW
,
1179 wxFRAME_FLOAT_ON_PARENT
,
1183 // -----------------------------------------------------------------------
1185 void FormMain
::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1187 wxMessageBox(wxT("Sorrt, not yet implemented"));
1190 void FormMain
::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1192 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
1194 prop
->EnableCommonValue();
1196 wxMessageBox(wxT("First select a property"));
1199 void FormMain
::PopulateWithStandardItems ()
1201 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1202 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1204 // Append is ideal way to add items to wxPropertyGrid.
1205 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1207 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1208 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1209 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1211 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1212 pg
->GetGrid()->GetMarginColour()) );
1214 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1215 pg
->GetGrid()->GetCellBackgroundColour()) );
1216 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1217 pg
->GetGrid()->GetCellTextColour()) );
1218 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1219 pg
->GetGrid()->GetLineColour()) );
1220 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1221 m_combinedFlags
, GetWindowStyle()) );
1223 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1225 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1227 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1228 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1230 // Let's demonstrate 'Units' attribute here
1232 // Note that we use many attribute constants instead of strings here
1233 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1234 // Using constant may reduce binary size.
1236 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1237 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1238 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1239 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1241 // Set value to unspecified so that InlineHelp attribute will be demonstrated
1242 pg
->SetPropertyValueUnspecified(wxT("Height"));
1243 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_INLINE_HELP
, wxT("Enter new height for window") );
1244 pg
->SetPropertyHelpString(wxT("Height"), wxT("This property uses attributes \"Units\" and \"InlineHelp\".") );
1246 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1247 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1248 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1249 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1251 pg
->SetPropertyValueUnspecified(wxT("Width"));
1252 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_INLINE_HELP
, wxT("Enter new width for window") );
1253 pg
->SetPropertyHelpString(wxT("Width"), wxT("This property uses attributes \"Units\" and \"InlineHelp\".") );
1255 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1256 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1257 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1259 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1260 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1261 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1263 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. Inorder to have label disabled as well, ")
1264 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1266 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1267 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1269 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1270 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1271 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1273 // Disable some of them
1274 pg
->DisableProperty( wxT("Operating System") );
1275 pg
->DisableProperty( wxT("User Id") );
1276 pg
->DisableProperty( wxT("User Name") );
1278 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1279 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1280 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1282 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1284 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1285 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1286 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1287 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1290 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1291 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1292 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1293 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1294 wxT("with custom action (dir dialog popup) defined.")
1297 pg
->Append( new wxAdvImageFileProperty(wxT("AdvImageFileProperty"),wxPG_LABEL
) );
1298 pg
->SetPropertyHelpString( wxT("AdvImageFileProperty"),
1299 wxT("This demonstrates wxAdvImageFileProperty class defined in this sample app. ")
1300 wxT("Button can be used to add new images to the popup list.")
1303 wxArrayDouble arrdbl
;
1310 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1311 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1312 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1313 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1314 wxT("It is an example of a custom list editor property.")
1317 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1318 wxT("Editing properties will have immediate effect on this window, ")
1319 wxT("and vice versa (atleast in most cases, that is).")
1321 pg
->SetPropertyHelpString( wxT("Information"),
1322 wxT("This property is read-only.") );
1324 pg
->SetPropertyReadOnly( wxT("Information"), true );
1327 // Set test information for cells in columns 3 and 4
1328 // (reserve column 2 for displaying units)
1329 wxPropertyGridIterator it
;
1330 wxBitmap bmp
= wxArtProvider
::GetBitmap(wxART_FOLDER
);
1332 for ( it
= pg
->GetGrid()->GetIterator();
1336 wxPGProperty
* p
= *it
;
1337 if ( p
->IsCategory() )
1340 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1341 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1345 // -----------------------------------------------------------------------
1347 void FormMain
::PopulateWithExamples ()
1349 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1350 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1353 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1354 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1357 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1359 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPG_EDITOR(SpinCtrl
) );
1360 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1361 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)10 ); // for reduced binary size.
1362 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1363 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1365 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1366 wxT("This is regular wxIntProperty, which editor has been ")
1367 wxT("changed to wxPG_EDITOR(SpinCtrl). Note however that ")
1368 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1369 wxT("needs to be called prior to using it."));
1373 // Add bool property
1374 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1376 // Add bool property with check box
1377 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1378 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1379 wxPG_BOOL_USE_CHECKBOX
,
1382 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1383 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1385 pid
= pg
->Append( new wxFloatProperty( wxT("FloatProperty"),
1389 // A string property that can be edited in a separate editor dialog.
1390 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1391 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1393 // A property that edits a wxArrayString.
1394 wxArrayString example_array
;
1395 example_array
.Add( wxT("String 1"));
1396 example_array
.Add( wxT("String 2"));
1397 example_array
.Add( wxT("String 3"));
1398 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1401 // Test adding same category multiple times ( should not actually create a new one )
1402 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1404 // A file selector property. Note that argument between name
1405 // and initial value is wildcard (format same as in wxFileDialog).
1406 wxPGProperty
* prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1409 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1410 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1411 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1414 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1415 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1419 // An image file property. Arguments are just like for FileProperty, but
1420 // wildcard is missing (it is autogenerated from supported image formats).
1421 // If you really need to override it, create property separately, and call
1422 // its SetWildcard method.
1423 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1426 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1427 //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false);
1428 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPG_EDITOR(ComboBox
) );
1429 pg
->GetProperty(wxT("ColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1430 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1431 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1432 wxT("editor of this property to wxPG_EDITOR(ComboBox)"));
1435 // This demonstrates using alternative editor for colour property
1436 // to trigger colour dialog directly from button.
1437 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1440 // wxEnumProperty does not store strings or even list of strings
1441 // ( so that's why they are static in function ).
1442 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1443 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1445 // this value array would be optional if values matched string indexes
1446 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1448 // note that the initial value (the last argument) is the actual value,
1449 // not index or anything like that. Thus, our value selects "Another Item".
1451 // 0 before value is number of items. If it is 0, like in our example,
1452 // number of items is calculated, and this requires that the string pointer
1453 // array is terminated with NULL.
1454 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1455 enum_prop_labels
, enum_prop_values
, 80 ) );
1459 // use basic table from our previous example
1460 // can also set/add wxArrayStrings and wxArrayInts directly.
1461 soc
.Set( enum_prop_labels
, enum_prop_values
);
1464 soc
.Add( wxT("Look, it continues"), 200 );
1465 soc
.Add( wxT("Even More"), 240 );
1466 soc
.Add( wxT("And More"), 280 );
1467 soc
.Add( wxT("True End of the List"), 320 );
1469 // Test custom colours ([] operator of wxPGChoices returns
1470 // references to wxPGChoiceEntry).
1471 soc
[1].SetFgCol(*wxRED
);
1472 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1473 soc
[2].SetFgCol(*wxGREEN
);
1474 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1475 soc
[3].SetFgCol(*wxBLUE
);
1476 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1477 soc
[4].SetBitmap(wxArtProvider
::GetBitmap(wxART_FOLDER
));
1479 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1483 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1485 // Add a second time to test that the caching works
1486 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1488 pg
->SetPropertyHelpString(wxT("EnumProperty 3"),
1489 wxT("Should have same choices as EnumProperty 2"));
1491 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1493 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1494 wxT("Should have same choices as EnumProperty 2"));
1496 pg
->Append( new wxEnumProperty(wxT("EnumProperty 5"),wxPG_LABEL
,
1498 pg
->GetProperty(wxT("EnumProperty 5"))->SetChoicesExclusive();
1499 pg
->GetProperty(wxT("EnumProperty 5"))->AddChoice(wxT("5th only"), 360);
1501 pg
->SetPropertyHelpString(wxT("EnumProperty 5"),
1502 wxT("Should have one extra item when compared to EnumProperty 4"));
1504 // Password property example.
1505 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1506 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1507 pg
->SetPropertyHelpString( wxT("Password"),
1508 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1510 // String editor with dir selector button. Uses wxEmptyString as name, which
1511 // is allowed (naturally, in this case property cannot be accessed by name).
1512 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1513 pg
->SetPropertyAttribute( wxT("DirProperty"),
1514 wxPG_DIR_DIALOG_MESSAGE
,
1515 wxT("This is a custom dir dialog message") );
1517 // Add string property - first arg is label, second name, and third initial value
1518 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1519 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1520 pg
->SetPropertyHelpString( wxT("StringProperty"),
1521 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1523 // Set value after limiting so that it will be applied
1524 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1527 // this value array would be optional if values matched string indexes
1528 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1530 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1531 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1534 // Multi choice dialog.
1535 wxArrayString tchoices
;
1536 tchoices
.Add(wxT("Cabbage"));
1537 tchoices
.Add(wxT("Carrot"));
1538 tchoices
.Add(wxT("Onion"));
1539 tchoices
.Add(wxT("Potato"));
1540 tchoices
.Add(wxT("Strawberry"));
1542 wxArrayString tchoicesValues
;
1543 tchoicesValues
.Add(wxT("Carrot"));
1544 tchoicesValues
.Add(wxT("Potato"));
1546 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1548 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1549 tchoices
, tchoicesValues
) );
1550 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1552 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1553 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1557 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1558 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1559 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1560 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1561 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1564 // wxEditEnumProperty
1566 eech
.Add(wxT("Choice 1"));
1567 eech
.Add(wxT("Choice 2"));
1568 eech
.Add(wxT("Choice 3"));
1569 pg
->Append( new wxEditEnumProperty(wxT("EditEnumProperty"), wxPG_LABEL
, eech
) ); // , wxT("Choice 2")
1572 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1573 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1577 // wxDateTimeProperty
1578 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime
::Now() ) );
1580 #if wxUSE_DATEPICKCTRL
1581 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1582 (long)(wxDP_DROPDOWN
| wxDP_SHOWCENTURY
) );
1584 pg
->SetPropertyHelpString( wxT("DateProperty"),
1585 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY).")
1586 wxT("Also note that wxPG_ALLOW_WXADV needs to be defined inorder to use wxDatePickerCtrl.") );
1592 // Add Triangle properties as both wxTriangleProperty and
1593 // a generic parent property (using wxStringProperty).
1595 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1597 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1598 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1599 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1600 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1602 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1604 pg
->SetPropertyHelpString( wxT("3D Object"),
1605 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1606 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1608 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1609 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1610 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1611 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1613 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1616 // This snippet is a doc sample test
1618 pid
= pg
->Append( new wxStringProperty(wxT("Car"),wxPG_LABEL
,wxT("<composed>")) );
1620 pg
->AppendIn( pid
, new wxStringProperty(wxT("Model"),
1622 wxT("Lamborghini Diablo SV")) );
1624 pg
->AppendIn( pid
, new wxIntProperty(wxT("Engine Size (cc)"),
1628 wxPGProperty
* speedId
= pg
->AppendIn( pid
, new wxStringProperty(wxT("Speeds"),wxPG_LABEL
,wxT("<composed>")) );
1629 pg
->AppendIn( speedId
, new wxIntProperty(wxT("Max. Speed (mph)"),wxPG_LABEL
,290) );
1630 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("0-100 mph (sec)"),wxPG_LABEL
,3.9) );
1631 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("1/4 mile (sec)"),wxPG_LABEL
,8.6) );
1633 pg
->AppendIn( pid
, new wxIntProperty(wxT("Price ($)"),
1637 // Make sure the child properties can be accessed correctly
1638 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1640 // Displayed value of "Car" property is now:
1641 // "Lamborghini Diablo SV; [300; 3.9; 8.6]; 300000"
1644 // Test wxSampleMultiButtonEditor
1645 wxPGRegisterEditorClass( SampleMultiButtonEditor
);
1646 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1647 pg
->SetPropertyEditor(wxT("MultipleButtons"), wxPG_EDITOR(SampleMultiButtonEditor
) );
1649 // Test SingleChoiceProperty
1650 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1654 // Test adding variable height bitmaps in wxPGChoices
1657 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1658 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1659 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1661 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1667 // Test how non-editable composite strings appear
1668 pid
= pg
->Append( new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>")) );
1669 pg
->SetPropertyReadOnly(pid
);
1671 pg
->AppendIn(pid
, new wxStringProperty(wxT("Latest Release"), wxPG_LABEL
, wxT("2.8.8")) );
1672 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Win API"), wxPG_LABEL
, true) );
1673 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1674 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1675 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1676 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1677 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1678 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1679 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1681 AddTestProperties(pg
);
1684 // -----------------------------------------------------------------------
1686 void FormMain
::PopulateWithLibraryConfig ()
1688 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1689 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1693 wxBitmap bmp
= wxArtProvider
::GetBitmap(wxART_REPORT_VIEW
);
1697 #define ADD_WX_LIB_CONF_GROUP(A) \
1698 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1699 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp );
1701 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1702 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1703 pg->DisableProperty(wxT(#A));
1705 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1706 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1708 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1709 ADD_WX_LIB_CONF( wxUSE_GUI
)
1711 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1712 #if defined(WXWIN_COMPATIBILITY_2_2)
1713 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1715 #if defined(WXWIN_COMPATIBILITY_2_4)
1716 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1718 #if defined(WXWIN_COMPATIBILITY_2_6)
1719 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1721 #if defined(WXWIN_COMPATIBILITY_2_8)
1722 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1724 #ifdef wxFONT_SIZE_COMPATIBILITY
1725 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1727 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1729 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1730 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1732 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1735 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1736 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1737 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1738 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1739 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1740 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1742 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1743 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1744 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1745 ADD_WX_LIB_CONF( wxUSE_WCHAR_T
)
1747 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1748 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1749 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1750 ADD_WX_LIB_CONF( wxUSE_STL
)
1751 ADD_WX_LIB_CONF( wxUSE_LOG
)
1752 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1753 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1754 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1755 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1756 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1757 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1758 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1760 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1761 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1762 ADD_WX_LIB_CONF( wxUSE_FILE
)
1763 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1764 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1765 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1766 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1767 ADD_WX_LIB_CONF( wxUSE_INTL
)
1768 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1769 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1770 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1771 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1772 #ifdef wxUSE_CONFIG_NATIVE
1773 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1775 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1777 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1778 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1779 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1780 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1781 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1782 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1783 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1784 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1785 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1786 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1787 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1788 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1789 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1790 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1791 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1792 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1793 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1794 ADD_WX_LIB_CONF( wxUSE_URL
)
1795 #ifdef wxUSE_URL_NATIVE
1796 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1798 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1800 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1801 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1802 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1804 ADD_WX_LIB_CONF( wxUSE_XRC
)
1806 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1808 ADD_WX_LIB_CONF( wxUSE_XML
)
1810 // Set them to use check box.
1811 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1816 // Handle events of the third page here.
1817 class wxMyPropertyGridPage
: public wxPropertyGridPage
1821 // Return false here to indicate unhandled events should be
1822 // propagated to manager's parent, as normal.
1823 virtual bool IsHandlingAllEvents() const { return false; }
1827 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1829 wxPGProperty
* property
)
1831 return wxPropertyGridPage
::DoInsert(parent
,index
,property
);
1834 void OnPropertySelect( wxPropertyGridEvent
& event
);
1835 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1836 void OnPropertyChange( wxPropertyGridEvent
& event
);
1837 void OnPageChange( wxPropertyGridEvent
& event
);
1840 DECLARE_EVENT_TABLE()
1844 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1845 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage
::OnPropertySelect
)
1846 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage
::OnPropertyChanging
)
1847 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage
::OnPropertyChange
)
1848 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage
::OnPageChange
)
1852 void wxMyPropertyGridPage
::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1854 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1857 void wxMyPropertyGridPage
::OnPropertyChange( wxPropertyGridEvent
& event
)
1859 wxPGProperty
* p
= event
.GetProperty();
1860 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1861 p
->GetName().c_str(),
1862 p
->GetDisplayedString().c_str());
1865 void wxMyPropertyGridPage
::OnPropertyChanging( wxPropertyGridEvent
& event
)
1867 wxPGProperty
* p
= event
.GetProperty();
1868 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1869 p
->GetName().c_str(),
1870 event
.GetValue().GetString().c_str());
1873 void wxMyPropertyGridPage
::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1875 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1879 class wxPGKeyHandler
: public wxEvtHandler
1883 void OnKeyEvent( wxKeyEvent
& event
)
1885 wxMessageBox(wxString
::Format(wxT("%i"),event
.GetKeyCode()));
1889 DECLARE_EVENT_TABLE()
1892 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1893 EVT_KEY_DOWN( wxPGKeyHandler
::OnKeyEvent
)
1897 // -----------------------------------------------------------------------
1899 void FormMain
::InitPanel()
1904 wxWindow
* panel
= new wxPanel(this,-1,wxPoint(0,0),wxSize(400,400));
1908 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1910 m_topSizer
= topSizer
;
1913 void FormMain
::FinalizePanel( bool wasCreated
)
1915 m_panel
->SetSizer( m_topSizer
);
1916 m_topSizer
->SetSizeHints( m_panel
);
1918 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1919 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1920 SetSizer( panelSizer
);
1921 panelSizer
->SetSizeHints( this );
1926 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_X
)/10)*4,
1927 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_Y
)/10)*8
1933 void FormMain
::PopulateGrid()
1935 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1936 pgman
->AddPage(wxT("Standard Items"));
1938 PopulateWithStandardItems();
1940 pgman
->AddPage(wxT("wxWidgets Library Config"));
1942 PopulateWithLibraryConfig();
1944 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1945 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1947 // Use wxMyPropertyGridPage (see above) to test the
1948 // custom wxPropertyGridPage feature.
1949 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1951 PopulateWithExamples();
1954 void FormMain
::CreateGrid( int style
, int extraStyle
)
1957 // This function (re)creates the property grid in our sample
1961 style
= // default style
1962 wxPG_BOLD_MODIFIED
|
1963 wxPG_SPLITTER_AUTO_CENTER
|
1965 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1967 //wxPG_HIDE_CATEGORIES |
1968 //wxPG_LIMITED_EDITING |
1973 if ( extraStyle
== -1 )
1974 // default extra style
1975 extraStyle
= wxPG_EX_MODE_BUTTONS
;
1976 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1977 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1978 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1979 //| wxPG_EX_HELP_AS_TOOLTIPS
1981 bool wasCreated
= m_panel ?
false : true;
1986 // This shows how to combine two static choice descriptors
1987 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1988 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1990 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1991 new wxPropertyGridManager(m_panel
,
1992 // Don't change this into wxID_ANY in the sample, or the
1993 // event handling will obviously be broken.
1999 m_propGrid
= pgman
->GetGrid();
2001 pgman
->SetExtraStyle(extraStyle
);
2003 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_BEEP
| wxPG_VFB_MARK_CELL
| wxPG_VFB_SHOW_MESSAGE
);
2005 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
2009 // Change some attributes in all properties
2010 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
2011 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
2013 //m_pPropGridManager->SetSplitterLeft(true);
2014 //m_pPropGridManager->SetSplitterPosition(137);
2017 // This would setup event handling without event table entries
2018 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
2019 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2020 &FormMain::OnPropertyGridSelect );
2021 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
2022 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2023 &FormMain::OnPropertyGridChange );
2026 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
2028 FinalizePanel(wasCreated
);
2031 // -----------------------------------------------------------------------
2033 FormMain
::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
2034 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
2035 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
2036 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
2042 // we need this in order to allow the about menu relocation, since ABOUT is
2043 // not the default id of the about menu
2044 wxApp
::s_macAboutMenuItemId
= ID_ABOUT
;
2048 // This is here to really test the wxImageFileProperty.
2049 wxInitAllImageHandlers();
2052 CreateGrid( // style
2053 wxPG_BOLD_MODIFIED
|
2054 wxPG_SPLITTER_AUTO_CENTER
|
2056 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2058 //wxPG_HIDE_CATEGORIES |
2059 //wxPG_LIMITED_EDITING |
2064 wxPG_EX_MODE_BUTTONS
2065 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2066 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2067 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2068 //| wxPG_EX_HELP_AS_TOOLTIPS
2071 // Register all editors (SpinCtrl etc.)
2072 m_pPropGridManager
->RegisterAdditionalEditors();
2076 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2077 wxMenu
*menuTry
= new wxMenu
;
2078 wxMenu
*menuTools1
= new wxMenu
;
2079 wxMenu
*menuTools2
= new wxMenu
;
2080 wxMenu
*menuHelp
= new wxMenu
;
2082 menuHelp
->Append(ID_ABOUT
, wxT("&About..."), wxT("Show about dialog") );
2084 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2085 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2086 menuTools1
->AppendSeparator();
2087 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2088 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2089 menuTools1
->AppendSeparator();
2090 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2091 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2092 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2093 menuTools1
->AppendSeparator();
2094 menuTools1
->Append(ID_SETCOLOUR
, wxT("Set Bg Colour") );
2095 menuTools1
->Append(ID_UNSPECIFY
, wxT("Set to Unspecified") );
2096 menuTools1
->Append(ID_CLEAR
, wxT("Set Value to Default") );
2097 menuTools1
->AppendSeparator();
2098 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2099 wxT("Toggles item's enabled state.") );
2100 m_itemEnable
->Enable( FALSE
);
2101 menuTools1
->Append(ID_HIDE
, wxT("Hide"), wxT("Shows or hides a property") );
2103 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2104 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2105 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2106 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2107 menuTools2
->AppendSeparator();
2108 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2109 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2110 menuTools2
->AppendSeparator();
2111 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2112 wxT("Disables painting, auto-sorting, etc.") );
2113 menuTools2
->AppendSeparator();
2114 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2115 menuTools2
->AppendSeparator();
2116 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2117 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2118 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).") );
2119 menuTools2
->AppendSeparator();
2120 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2121 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2122 menuTools2
->AppendSeparator();
2123 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2124 wxT("Enable values that are common to all properties, for selected property."));
2125 menuTools2
->AppendSeparator();
2126 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2127 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2128 menuTools2
->AppendSeparator();
2129 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2130 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2131 menuTools2
->AppendSeparator();
2132 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2133 menuTools2
->AppendSeparator();
2134 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2135 menuTools2
->AppendSeparator();
2136 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2137 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2138 menuTools2
->AppendSeparator();
2139 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2140 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2142 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2143 wxT("Select window style flags used by the grid."));
2144 menuTry
->AppendSeparator();
2145 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2146 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2147 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2148 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2149 menuTry
->AppendSeparator();
2150 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2151 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2152 menuTry
->AppendSeparator();
2153 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2154 wxT("Switches between user-modifiedable and static layouts.") );
2155 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2156 menuTry
->AppendSeparator();
2157 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2158 menuTry
->AppendSeparator();
2159 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2160 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2162 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2163 menuFile
->AppendSeparator();
2164 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2166 // Now append the freshly created menu to the menu bar...
2167 wxMenuBar
*menuBar
= new wxMenuBar();
2168 menuBar
->Append(menuFile
, wxT("&File") );
2169 menuBar
->Append(menuTry
, wxT("&Try These!") );
2170 menuBar
->Append(menuTools1
, wxT("&Basic") );
2171 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2172 menuBar
->Append(menuHelp
, wxT("&Help") );
2174 // ... and attach this menu bar to the frame
2175 SetMenuBar(menuBar
);
2178 // create a status bar
2180 SetStatusText(wxEmptyString
);
2181 #endif // wxUSE_STATUSBAR
2189 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2190 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2196 // Normally, wxPropertyGrid does not check whether item with identical
2197 // label already exists. However, since in this sample we use labels for
2198 // identifying properties, we have to be sure not to generate identical
2201 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2206 if ( pg
->GetPropertyByLabel( baselabel
) )
2211 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2212 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2218 baselabel
= newlabel
;
2222 // -----------------------------------------------------------------------
2224 void FormMain
::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2228 if ( !m_pPropGridManager
->GetChildrenCount() )
2230 wxMessageBox(wxT("No items to relate - first add some with Append."));
2234 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2237 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2240 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2242 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2244 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2245 m_pPropGridManager
->GetPropertyIndex(id
),
2246 new wxStringProperty(propLabel
) );
2250 // -----------------------------------------------------------------------
2252 void FormMain
::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2256 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2258 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2260 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2262 m_pPropGridManager
->Refresh();
2265 // -----------------------------------------------------------------------
2267 void FormMain
::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2269 m_pPropGridManager
->GetGrid()->Clear();
2272 // -----------------------------------------------------------------------
2274 void FormMain
::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2278 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2280 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2282 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2284 m_pPropGridManager
->Refresh();
2288 // -----------------------------------------------------------------------
2290 void FormMain
::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2294 if ( !m_pPropGridManager
->GetChildrenCount() )
2296 wxMessageBox(wxT("No items to relate - first add some with Append."));
2300 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2303 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2307 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2309 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2311 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2312 m_pPropGridManager
->GetPropertyIndex(id
),
2313 new wxPropertyCategory (propLabel
) );
2317 // -----------------------------------------------------------------------
2319 void FormMain
::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2321 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2324 wxMessageBox(wxT("First select a property."));
2328 m_pPropGridManager
->DeleteProperty( id
);
2331 // -----------------------------------------------------------------------
2333 void FormMain
::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2335 // Delete random property
2336 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2340 if ( !p
->IsCategory() )
2342 m_pPropGridManager
->DeleteProperty( p
);
2346 if ( !p
->GetChildCount() )
2349 int n
= rand() % ((int)p
->GetChildCount());
2355 // -----------------------------------------------------------------------
2357 void FormMain
::OnContextMenu( wxContextMenuEvent
& event
)
2359 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2360 event
.GetPosition().x
,event
.GetPosition().y
);
2365 // -----------------------------------------------------------------------
2367 void FormMain
::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2369 /*#ifdef __WXDEBUG__
2370 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2371 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2377 // -----------------------------------------------------------------------
2379 int IterateMessage( wxPGProperty
* prop
)
2383 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2384 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2386 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2389 // -----------------------------------------------------------------------
2391 void FormMain
::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2393 wxPropertyGridIterator it
;
2395 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2400 wxPGProperty
* p
= *it
;
2401 int res
= IterateMessage( p
);
2402 if ( res
== wxCANCEL
) break;
2406 // -----------------------------------------------------------------------
2408 void FormMain
::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2410 wxPropertyGridIterator it
;
2412 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2413 GetIterator( wxPG_ITERATE_VISIBLE
);
2417 wxPGProperty
* p
= *it
;
2419 int res
= IterateMessage( p
);
2420 if ( res
== wxCANCEL
) break;
2424 // -----------------------------------------------------------------------
2426 void FormMain
::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2428 // iterate over items in reverse order
2429 wxPropertyGridIterator it
;
2431 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2432 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2436 wxPGProperty
* p
= *it
;
2438 int res
= IterateMessage( p
);
2439 if ( res
== wxCANCEL
) break;
2443 // -----------------------------------------------------------------------
2445 void FormMain
::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2447 wxPropertyGridIterator it
;
2449 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2450 GetIterator( wxPG_ITERATE_CATEGORIES
);
2454 wxPGProperty
* p
= *it
;
2456 int res
= IterateMessage( p
);
2457 if ( res
== wxCANCEL
) break;
2461 // -----------------------------------------------------------------------
2463 void FormMain
::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2465 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2467 // Remove auto-centering
2468 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2470 // Grow manager size just prior fit - otherwise
2471 // column information may be lost.
2472 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2473 wxSize oldFullSize
= GetSize();
2474 SetSize(1000, oldFullSize
.y
);
2476 wxSize newSz
= page
->FitColumns();
2478 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2479 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2487 // -----------------------------------------------------------------------
2489 void FormMain
::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2491 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2493 wxPGChoices newChoices
;
2495 newChoices
.Add(wxT("Fast"),0x1);
2496 newChoices
.Add(wxT("Powerful"),0x2);
2497 newChoices
.Add(wxT("Safe"),0x4);
2498 newChoices
.Add(wxT("Sleek"),0x8);
2500 p
->SetChoices(newChoices
);
2503 // -----------------------------------------------------------------------
2505 void FormMain
::OnEnableDisable( wxCommandEvent
& )
2507 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2510 wxMessageBox(wxT("First select a property."));
2514 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2516 m_pPropGridManager
->DisableProperty ( id
);
2517 m_itemEnable
->SetItemLabel( wxT("Enable") );
2521 m_pPropGridManager
->EnableProperty ( id
);
2522 m_itemEnable
->SetItemLabel( wxT("Disable") );
2526 // -----------------------------------------------------------------------
2528 void FormMain
::OnHideShow( wxCommandEvent
& WXUNUSED(event
) )
2530 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2533 wxMessageBox(wxT("First select a property."));
2537 if ( m_pPropGridManager
->IsPropertyShown( id
) )
2539 m_pPropGridManager
->HideProperty( id
, true );
2540 m_itemEnable
->SetItemLabel( wxT("Show") );
2544 m_pPropGridManager
->HideProperty( id
, false );
2545 m_itemEnable
->SetItemLabel( wxT("Hide") );
2548 wxPropertyGridPage
* curPage
= m_pPropGridManager
->GetCurrentPage();
2550 // Check for bottomY precalculation validity
2551 unsigned int byPre
= curPage
->GetVirtualHeight();
2552 unsigned int byAct
= curPage
->GetActualVirtualHeight();
2554 if ( byPre
!= byAct
)
2556 wxLogDebug(wxT("VirtualHeight is %u, should be %u"), byPre
, byAct
);
2560 // -----------------------------------------------------------------------
2562 void FormMain
::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2564 m_pPropGridManager
->AddPage(wxT("New Page"));
2567 // -----------------------------------------------------------------------
2569 void FormMain
::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2571 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2574 // -----------------------------------------------------------------------
2576 void FormMain
::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2578 m_savedState
= m_pPropGridManager
->SaveEditableState();
2579 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2582 // -----------------------------------------------------------------------
2584 void FormMain
::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2586 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2589 // -----------------------------------------------------------------------
2591 void FormMain
::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2594 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2596 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPG_EDITOR(SpinCtrl
) );
2598 wxMessageBox(wxT("First select a property"));
2602 // -----------------------------------------------------------------------
2604 void FormMain
::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2606 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2609 wxPGChoices choices
;
2610 choices
.Add(wxT("Flag 0"),0x0001);
2611 choices
.Add(wxT("Flag 1"),0x0002);
2612 choices
.Add(wxT("Flag 2"),0x0004);
2613 choices
.Add(wxT("Flag 3"),0x0008);
2614 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2615 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2616 m_pPropGridManager
->SetPropertyAttribute( newId
,
2617 wxPG_BOOL_USE_CHECKBOX
,
2622 wxMessageBox(wxT("First select a property"));
2625 // -----------------------------------------------------------------------
2627 void FormMain
::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2629 m_pPropGridManager
->ClearModifiedStatus();
2632 // -----------------------------------------------------------------------
2634 // Freeze check-box checked?
2635 void FormMain
::OnFreezeClick( wxCommandEvent
& event
)
2637 if ( !m_pPropGridManager
) return;
2639 if ( event
.IsChecked() )
2641 if ( !m_pPropGridManager
->IsFrozen() )
2643 m_pPropGridManager
->Freeze();
2648 if ( m_pPropGridManager
->IsFrozen() )
2650 m_pPropGridManager
->Thaw();
2651 m_pPropGridManager
->Refresh();
2656 // -----------------------------------------------------------------------
2658 void FormMain
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2661 msg
.Printf( wxT("wxPropertyGrid Sample")
2663 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2677 wxT("Programmed by %s\n\n")
2678 wxT("Using %s\n\n"),
2679 wxT("Jaakko Salli"), wxVERSION_STRING
2682 wxMessageBox(msg
, _T("About"), wxOK
| wxICON_INFORMATION
, this);
2685 // -----------------------------------------------------------------------
2687 void FormMain
::OnColourScheme( wxCommandEvent
& event
)
2689 int id
= event
.GetId();
2690 if ( id
== ID_COLOURSCHEME1
)
2692 m_pPropGridManager
->GetGrid()->ResetColours();
2694 else if ( id
== ID_COLOURSCHEME2
)
2697 wxColour
my_grey_1(212,208,200);
2698 wxColour
my_grey_3(113,111,100);
2699 m_pPropGridManager
->Freeze();
2700 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2701 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2702 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2703 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2704 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2705 m_pPropGridManager
->Thaw();
2707 else if ( id
== ID_COLOURSCHEME3
)
2710 wxColour
my_grey_1(212,208,200);
2711 wxColour
my_grey_2(236,233,216);
2712 m_pPropGridManager
->Freeze();
2713 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2714 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2715 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2716 m_pPropGridManager
->Thaw();
2718 else if ( id
== ID_COLOURSCHEME4
)
2722 wxColour
my_grey_1(212,208,200);
2723 wxColour
my_grey_2(241,239,226);
2724 wxColour
my_grey_3(113,111,100);
2725 m_pPropGridManager
->Freeze();
2726 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2727 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2728 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2729 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2730 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2731 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2732 m_pPropGridManager
->Thaw();
2736 // -----------------------------------------------------------------------
2738 void FormMain
::OnCatColours( wxCommandEvent
& event
)
2740 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2741 m_pPropGridManager
->Freeze();
2743 if ( event
.IsChecked() )
2745 // Set custom colours.
2746 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2747 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2748 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2749 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2750 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2751 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2752 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2753 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2754 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2755 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2756 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2760 // Revert to original.
2761 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2762 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2763 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2764 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2766 m_pPropGridManager
->Thaw();
2767 m_pPropGridManager
->Refresh();
2770 // -----------------------------------------------------------------------
2772 #define ADD_FLAG(FLAG) \
2773 chs.Add(wxT(#FLAG)); \
2775 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2778 void FormMain
::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2787 unsigned int ind
= 0;
2788 int flags
= m_pPropGridManager
->GetWindowStyle();
2789 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2790 ADD_FLAG(wxPG_AUTO_SORT
)
2791 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2792 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2793 ADD_FLAG(wxPG_TOOLTIPS
)
2794 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2795 ADD_FLAG(wxPG_HIDE_MARGIN
)
2796 ADD_FLAG(wxPG_LIMITED_EDITING
)
2797 ADD_FLAG(wxPG_TOOLBAR
)
2798 ADD_FLAG(wxPG_DESCRIPTION
)
2799 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2800 wxT("wxPropertyGrid Window Style"), chs
);
2801 dlg
.SetSelections(sel
);
2802 if ( dlg
.ShowModal() == wxID_CANCEL
)
2806 sel
= dlg
.GetSelections();
2807 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2808 flags
|= vls
[sel
[ind
]];
2817 unsigned int ind
= 0;
2818 int flags
= m_pPropGridManager
->GetExtraStyle();
2819 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2820 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2821 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2822 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2823 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2824 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2825 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2826 ADD_FLAG(wxPG_EX_LEGACY_VALIDATORS
)
2827 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2828 wxT("wxPropertyGrid Extra Style"), chs
);
2829 dlg
.SetSelections(sel
);
2830 if ( dlg
.ShowModal() == wxID_CANCEL
)
2834 sel
= dlg
.GetSelections();
2835 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2836 flags
|= vls
[sel
[ind
]];
2841 CreateGrid( style
, extraStyle
);
2844 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2845 (wxSystemSettings
::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2850 // -----------------------------------------------------------------------
2852 void FormMain
::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2854 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2855 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2858 if ( colCount
>= 2 )
2860 m_pPropGridManager
->SetColumnCount(colCount
);
2864 // -----------------------------------------------------------------------
2866 void FormMain
::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2868 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2869 wxPGProperty
* selected
= pg
->GetSelection();
2873 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2874 pg
->SetPropertyValue( selected
, value
);
2878 // -----------------------------------------------------------------------
2880 void FormMain
::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2882 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2884 wxPGProperty
* selected
= pg
->GetSelection();
2885 const wxPGChoices
& choices
= selected
->GetChoices();
2887 // Insert new choice to the center of list
2889 if ( choices
.IsOk() )
2891 int pos
= choices
.GetCount() / 2;
2892 selected
->InsertChoice(wxT("New Choice"), pos
);
2896 ::wxMessageBox(wxT("First select a property with some choices."));
2900 // -----------------------------------------------------------------------
2902 void FormMain
::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2904 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2906 wxPGProperty
* selected
= pg
->GetSelection();
2907 const wxPGChoices
& choices
= selected
->GetChoices();
2909 // Deletes choice from the center of list
2911 if ( choices
.IsOk() )
2913 int pos
= choices
.GetCount() / 2;
2914 selected
->DeleteChoice(pos
);
2918 ::wxMessageBox(wxT("First select a property with some choices."));
2922 // -----------------------------------------------------------------------
2924 #include <wx/colordlg.h>
2926 void FormMain
::OnMisc ( wxCommandEvent
& event
)
2928 int id
= event
.GetId();
2929 if ( id
== ID_STATICLAYOUT
)
2931 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2932 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2933 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2935 else if ( id
== ID_CLEAR
)
2937 m_pPropGridManager
->ClearPropertyValue(m_pPropGridManager
->GetGrid()->GetSelection());
2939 else if ( id
== ID_COLLAPSEALL
)
2942 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2944 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2945 it
.GetProperty()->SetExpanded( false );
2949 else if ( id
== ID_GETVALUES
)
2951 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2952 m_pPropGridManager
->GetGrid()->GetRoot(),
2953 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2955 else if ( id
== ID_SETVALUES
)
2957 if ( m_storedValues
.GetType() == wxT("list") )
2959 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2962 wxMessageBox(wxT("First use Get Property Values."));
2964 else if ( id
== ID_SETVALUES2
)
2968 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2969 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2970 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2971 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2973 else if ( id
== ID_COLLAPSE
)
2975 // Collapses selected.
2976 wxPGProperty
* id
= m_pPropGridManager
->GetSelectedProperty();
2979 m_pPropGridManager
->Collapse(id
);
2982 else if ( id
== ID_RUNTESTFULL
)
2984 // Runs a regression test.
2987 else if ( id
== ID_RUNTESTPARTIAL
)
2989 // Runs a regression test.
2992 else if ( id
== ID_UNSPECIFY
)
2994 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
2997 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3000 else if ( id
== ID_SETCOLOUR
)
3002 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
3006 data
.SetChooseFull(true);
3008 for ( i
= 0; i
< 16; i
++)
3010 wxColour
colour(i
*16, i
*16, i
*16);
3011 data
.SetCustomColour(i
, colour
);
3014 wxColourDialog
dialog(this, &data
);
3015 if ( dialog
.ShowModal() == wxID_OK
)
3017 wxColourData retData
= dialog
.GetColourData();
3018 m_pPropGridManager
->GetGrid()->SetPropertyBackgroundColour(prop
,retData
.GetColour());
3024 // -----------------------------------------------------------------------
3026 void FormMain
::OnPopulateClick( wxCommandEvent
& event
)
3028 int id
= event
.GetId();
3029 m_propGrid
->Clear();
3030 m_propGrid
->Freeze();
3031 if ( id
== ID_POPULATE1
)
3033 PopulateWithStandardItems();
3035 else if ( id
== ID_POPULATE2
)
3037 PopulateWithLibraryConfig();
3042 // -----------------------------------------------------------------------
3044 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3046 void FormMain
::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3048 DisplayMinimalFrame(this);
3051 // -----------------------------------------------------------------------
3053 FormMain
::~FormMain()
3057 // -----------------------------------------------------------------------
3059 IMPLEMENT_APP(cxApplication
)
3061 bool cxApplication
::OnInit()
3064 //Locale.Init(wxLANGUAGE_FINNISH);
3066 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3070 // Parse command-line
3071 wxApp
& app
= wxGetApp();
3074 wxString s
= app
.argv
[1];
3075 if ( s
== wxT("--run-tests") )
3079 bool testResult
= frame
->RunTests(true);
3089 // -----------------------------------------------------------------------
3091 void FormMain
::OnIdle( wxIdleEvent
& event
)
3094 // This code is useful for debugging focus problems
3095 static wxWindow* last_focus = (wxWindow*) NULL;
3097 wxWindow* cur_focus = ::wxWindow::FindFocus();
3099 if ( cur_focus != last_focus )
3101 const wxChar* class_name = wxT("<none>");
3103 class_name = cur_focus->GetClassInfo()->GetClassName();
3104 last_focus = cur_focus;
3105 wxLogDebug( wxT("FOCUSED: %s %X"),
3107 (unsigned int)cur_focus);
3114 // -----------------------------------------------------------------------