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"));
1354 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1355 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1358 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1360 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPG_EDITOR(SpinCtrl
) );
1361 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1362 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)10 ); // for reduced binary size.
1363 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1364 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1366 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1367 wxT("This is regular wxIntProperty, which editor has been ")
1368 wxT("changed to wxPG_EDITOR(SpinCtrl). Note however that ")
1369 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1370 wxT("needs to be called prior to using it."));
1374 // Add bool property
1375 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1377 // Add bool property with check box
1378 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1379 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1380 wxPG_BOOL_USE_CHECKBOX
,
1383 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1384 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1386 pid
= pg
->Append( new wxFloatProperty( wxT("FloatProperty"),
1390 // A string property that can be edited in a separate editor dialog.
1391 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1392 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1394 // A property that edits a wxArrayString.
1395 wxArrayString example_array
;
1396 example_array
.Add( wxT("String 1"));
1397 example_array
.Add( wxT("String 2"));
1398 example_array
.Add( wxT("String 3"));
1399 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1402 // Test adding same category multiple times ( should not actually create a new one )
1403 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1405 // A file selector property. Note that argument between name
1406 // and initial value is wildcard (format same as in wxFileDialog).
1407 prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1410 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1411 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1412 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1415 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1416 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1420 // An image file property. Arguments are just like for FileProperty, but
1421 // wildcard is missing (it is autogenerated from supported image formats).
1422 // If you really need to override it, create property separately, and call
1423 // its SetWildcard method.
1424 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1427 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1428 //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false);
1429 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPG_EDITOR(ComboBox
) );
1430 pg
->GetProperty(wxT("ColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1431 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1432 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1433 wxT("editor of this property to wxPG_EDITOR(ComboBox)"));
1436 // This demonstrates using alternative editor for colour property
1437 // to trigger colour dialog directly from button.
1438 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1441 // wxEnumProperty does not store strings or even list of strings
1442 // ( so that's why they are static in function ).
1443 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1444 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1446 // this value array would be optional if values matched string indexes
1447 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1449 // note that the initial value (the last argument) is the actual value,
1450 // not index or anything like that. Thus, our value selects "Another Item".
1452 // 0 before value is number of items. If it is 0, like in our example,
1453 // number of items is calculated, and this requires that the string pointer
1454 // array is terminated with NULL.
1455 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1456 enum_prop_labels
, enum_prop_values
, 80 ) );
1460 // use basic table from our previous example
1461 // can also set/add wxArrayStrings and wxArrayInts directly.
1462 soc
.Set( enum_prop_labels
, enum_prop_values
);
1465 soc
.Add( wxT("Look, it continues"), 200 );
1466 soc
.Add( wxT("Even More"), 240 );
1467 soc
.Add( wxT("And More"), 280 );
1468 soc
.Add( wxT("True End of the List"), 320 );
1470 // Test custom colours ([] operator of wxPGChoices returns
1471 // references to wxPGChoiceEntry).
1472 soc
[1].SetFgCol(*wxRED
);
1473 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1474 soc
[2].SetFgCol(*wxGREEN
);
1475 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1476 soc
[3].SetFgCol(*wxBLUE
);
1477 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1478 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1480 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1484 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1486 // Add a second time to test that the caching works. Also use
1487 // short form of constructor list + SetChoices.
1488 prop
= new wxEnumProperty(wxT("EnumProperty 3"), wxPG_LABEL
);
1490 prop
->SetChoices(soc
);
1491 prop
->SetValue(360);
1492 pg
->SetPropertyHelpString(prop
,
1493 wxT("Should have same choices as EnumProperty 2"));
1495 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1497 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1498 wxT("Should have same choices as EnumProperty 2"));
1500 pg
->Append( new wxEnumProperty(wxT("EnumProperty 5"),wxPG_LABEL
,
1502 pg
->GetProperty(wxT("EnumProperty 5"))->SetChoicesExclusive();
1503 pg
->GetProperty(wxT("EnumProperty 5"))->AddChoice(wxT("5th only"), 360);
1505 pg
->SetPropertyHelpString(wxT("EnumProperty 5"),
1506 wxT("Should have one extra item when compared to EnumProperty 4"));
1508 // Password property example.
1509 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1510 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1511 pg
->SetPropertyHelpString( wxT("Password"),
1512 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1514 // String editor with dir selector button. Uses wxEmptyString as name, which
1515 // is allowed (naturally, in this case property cannot be accessed by name).
1516 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1517 pg
->SetPropertyAttribute( wxT("DirProperty"),
1518 wxPG_DIR_DIALOG_MESSAGE
,
1519 wxT("This is a custom dir dialog message") );
1521 // Add string property - first arg is label, second name, and third initial value
1522 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1523 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1524 pg
->SetPropertyHelpString( wxT("StringProperty"),
1525 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1527 // Set value after limiting so that it will be applied
1528 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1531 // this value array would be optional if values matched string indexes
1532 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1534 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1535 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1538 // Multi choice dialog.
1539 wxArrayString tchoices
;
1540 tchoices
.Add(wxT("Cabbage"));
1541 tchoices
.Add(wxT("Carrot"));
1542 tchoices
.Add(wxT("Onion"));
1543 tchoices
.Add(wxT("Potato"));
1544 tchoices
.Add(wxT("Strawberry"));
1546 wxArrayString tchoicesValues
;
1547 tchoicesValues
.Add(wxT("Carrot"));
1548 tchoicesValues
.Add(wxT("Potato"));
1550 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1552 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1553 tchoices
, tchoicesValues
) );
1554 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1556 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1557 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1561 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1562 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1563 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1564 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1565 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1568 // wxEditEnumProperty
1570 eech
.Add(wxT("Choice 1"));
1571 eech
.Add(wxT("Choice 2"));
1572 eech
.Add(wxT("Choice 3"));
1573 pg
->Append( new wxEditEnumProperty(wxT("EditEnumProperty"), wxPG_LABEL
, eech
) ); // , wxT("Choice 2")
1576 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1577 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1581 // wxDateTimeProperty
1582 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1584 #if wxUSE_DATEPICKCTRL
1585 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1586 (long)(wxDP_DROPDOWN
| wxDP_SHOWCENTURY
) );
1588 pg
->SetPropertyHelpString( wxT("DateProperty"),
1589 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY).")
1590 wxT("Also note that wxPG_ALLOW_WXADV needs to be defined inorder to use wxDatePickerCtrl.") );
1596 // Add Triangle properties as both wxTriangleProperty and
1597 // a generic parent property (using wxStringProperty).
1599 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1601 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1602 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1603 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1604 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1606 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1608 pg
->SetPropertyHelpString( wxT("3D Object"),
1609 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1610 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1612 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1613 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1614 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1615 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1617 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1620 // This snippet is a doc sample test
1622 pid
= pg
->Append( new wxStringProperty(wxT("Car"),wxPG_LABEL
,wxT("<composed>")) );
1624 pg
->AppendIn( pid
, new wxStringProperty(wxT("Model"),
1626 wxT("Lamborghini Diablo SV")) );
1628 pg
->AppendIn( pid
, new wxIntProperty(wxT("Engine Size (cc)"),
1632 wxPGProperty
* speedId
= pg
->AppendIn( pid
, new wxStringProperty(wxT("Speeds"),wxPG_LABEL
,wxT("<composed>")) );
1633 pg
->AppendIn( speedId
, new wxIntProperty(wxT("Max. Speed (mph)"),wxPG_LABEL
,290) );
1634 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("0-100 mph (sec)"),wxPG_LABEL
,3.9) );
1635 pg
->AppendIn( speedId
, new wxFloatProperty(wxT("1/4 mile (sec)"),wxPG_LABEL
,8.6) );
1637 pg
->AppendIn( pid
, new wxIntProperty(wxT("Price ($)"),
1641 // Make sure the child properties can be accessed correctly
1642 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1644 // Displayed value of "Car" property is now:
1645 // "Lamborghini Diablo SV; [300; 3.9; 8.6]; 300000"
1648 // Test wxSampleMultiButtonEditor
1649 wxPGRegisterEditorClass( SampleMultiButtonEditor
);
1650 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1651 pg
->SetPropertyEditor(wxT("MultipleButtons"), wxPG_EDITOR(SampleMultiButtonEditor
) );
1653 // Test SingleChoiceProperty
1654 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1658 // Test adding variable height bitmaps in wxPGChoices
1661 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1662 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1663 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1665 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1671 // Test how non-editable composite strings appear
1672 pid
= pg
->Append( new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>")) );
1673 pg
->SetPropertyReadOnly(pid
);
1675 pg
->AppendIn(pid
, new wxStringProperty(wxT("Latest Release"), wxPG_LABEL
, wxT("2.8.8")) );
1676 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Win API"), wxPG_LABEL
, true) );
1677 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1678 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1679 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1680 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1681 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1682 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1683 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1685 AddTestProperties(pg
);
1688 // -----------------------------------------------------------------------
1690 void FormMain::PopulateWithLibraryConfig ()
1692 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1693 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1697 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1701 #define ADD_WX_LIB_CONF_GROUP(A) \
1702 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1703 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp );
1705 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1706 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1707 pg->DisableProperty(wxT(#A));
1709 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1710 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1712 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1713 ADD_WX_LIB_CONF( wxUSE_GUI
)
1715 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1716 #if defined(WXWIN_COMPATIBILITY_2_2)
1717 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1719 #if defined(WXWIN_COMPATIBILITY_2_4)
1720 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1722 #if defined(WXWIN_COMPATIBILITY_2_6)
1723 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1725 #if defined(WXWIN_COMPATIBILITY_2_8)
1726 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1728 #ifdef wxFONT_SIZE_COMPATIBILITY
1729 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1731 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1733 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1734 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1736 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1739 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1740 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1741 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1742 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1743 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1744 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1746 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1747 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1748 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1749 ADD_WX_LIB_CONF( wxUSE_WCHAR_T
)
1751 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1752 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1753 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1754 ADD_WX_LIB_CONF( wxUSE_STL
)
1755 ADD_WX_LIB_CONF( wxUSE_LOG
)
1756 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1757 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1758 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1759 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1760 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1761 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1762 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1764 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1765 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1766 ADD_WX_LIB_CONF( wxUSE_FILE
)
1767 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1768 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1769 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1770 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1771 ADD_WX_LIB_CONF( wxUSE_INTL
)
1772 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1773 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1774 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1775 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1776 #ifdef wxUSE_CONFIG_NATIVE
1777 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1779 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1781 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1782 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1783 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1784 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1785 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1786 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1787 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1788 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1789 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1790 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1791 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1792 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1793 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1794 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1795 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1796 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1797 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1798 ADD_WX_LIB_CONF( wxUSE_URL
)
1799 #ifdef wxUSE_URL_NATIVE
1800 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1802 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1804 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1805 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1806 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1808 ADD_WX_LIB_CONF( wxUSE_XRC
)
1810 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1812 ADD_WX_LIB_CONF( wxUSE_XML
)
1814 // Set them to use check box.
1815 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1820 // Handle events of the third page here.
1821 class wxMyPropertyGridPage
: public wxPropertyGridPage
1825 // Return false here to indicate unhandled events should be
1826 // propagated to manager's parent, as normal.
1827 virtual bool IsHandlingAllEvents() const { return false; }
1831 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1833 wxPGProperty
* property
)
1835 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1838 void OnPropertySelect( wxPropertyGridEvent
& event
);
1839 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1840 void OnPropertyChange( wxPropertyGridEvent
& event
);
1841 void OnPageChange( wxPropertyGridEvent
& event
);
1844 DECLARE_EVENT_TABLE()
1848 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1849 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1850 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1851 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1852 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1856 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1858 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1861 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1863 wxPGProperty
* p
= event
.GetProperty();
1864 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1865 p
->GetName().c_str(),
1866 p
->GetDisplayedString().c_str());
1869 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1871 wxPGProperty
* p
= event
.GetProperty();
1872 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1873 p
->GetName().c_str(),
1874 event
.GetValue().GetString().c_str());
1877 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1879 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1883 class wxPGKeyHandler
: public wxEvtHandler
1887 void OnKeyEvent( wxKeyEvent
& event
)
1889 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1893 DECLARE_EVENT_TABLE()
1896 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1897 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1901 // -----------------------------------------------------------------------
1903 void FormMain::InitPanel()
1908 wxWindow
* panel
= new wxPanel(this,-1,wxPoint(0,0),wxSize(400,400));
1912 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1914 m_topSizer
= topSizer
;
1917 void FormMain::FinalizePanel( bool wasCreated
)
1919 m_panel
->SetSizer( m_topSizer
);
1920 m_topSizer
->SetSizeHints( m_panel
);
1922 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1923 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1924 SetSizer( panelSizer
);
1925 panelSizer
->SetSizeHints( this );
1930 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
1931 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
1937 void FormMain::PopulateGrid()
1939 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1940 pgman
->AddPage(wxT("Standard Items"));
1942 PopulateWithStandardItems();
1944 pgman
->AddPage(wxT("wxWidgets Library Config"));
1946 PopulateWithLibraryConfig();
1948 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1949 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1951 // Use wxMyPropertyGridPage (see above) to test the
1952 // custom wxPropertyGridPage feature.
1953 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1955 PopulateWithExamples();
1958 void FormMain::CreateGrid( int style
, int extraStyle
)
1961 // This function (re)creates the property grid in our sample
1965 style
= // default style
1966 wxPG_BOLD_MODIFIED
|
1967 wxPG_SPLITTER_AUTO_CENTER
|
1969 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1971 //wxPG_HIDE_CATEGORIES |
1972 //wxPG_LIMITED_EDITING |
1977 if ( extraStyle
== -1 )
1978 // default extra style
1979 extraStyle
= wxPG_EX_MODE_BUTTONS
;
1980 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1981 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1982 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1983 //| wxPG_EX_HELP_AS_TOOLTIPS
1985 bool wasCreated
= m_panel
? false : true;
1990 // This shows how to combine two static choice descriptors
1991 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1992 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1994 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1995 new wxPropertyGridManager(m_panel
,
1996 // Don't change this into wxID_ANY in the sample, or the
1997 // event handling will obviously be broken.
2003 m_propGrid
= pgman
->GetGrid();
2005 pgman
->SetExtraStyle(extraStyle
);
2007 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_BEEP
| wxPG_VFB_MARK_CELL
| wxPG_VFB_SHOW_MESSAGE
);
2009 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
2013 // Change some attributes in all properties
2014 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
2015 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
2017 //m_pPropGridManager->SetSplitterLeft(true);
2018 //m_pPropGridManager->SetSplitterPosition(137);
2021 // This would setup event handling without event table entries
2022 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
2023 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2024 &FormMain::OnPropertyGridSelect );
2025 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
2026 (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
2027 &FormMain::OnPropertyGridChange );
2030 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
2032 FinalizePanel(wasCreated
);
2035 // -----------------------------------------------------------------------
2037 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
2038 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
2039 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
2040 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
2046 // we need this in order to allow the about menu relocation, since ABOUT is
2047 // not the default id of the about menu
2048 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
2052 // This is here to really test the wxImageFileProperty.
2053 wxInitAllImageHandlers();
2056 CreateGrid( // style
2057 wxPG_BOLD_MODIFIED
|
2058 wxPG_SPLITTER_AUTO_CENTER
|
2060 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2062 //wxPG_HIDE_CATEGORIES |
2063 //wxPG_LIMITED_EDITING |
2068 wxPG_EX_MODE_BUTTONS
2069 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2070 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2071 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2072 //| wxPG_EX_HELP_AS_TOOLTIPS
2075 // Register all editors (SpinCtrl etc.)
2076 m_pPropGridManager
->RegisterAdditionalEditors();
2080 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2081 wxMenu
*menuTry
= new wxMenu
;
2082 wxMenu
*menuTools1
= new wxMenu
;
2083 wxMenu
*menuTools2
= new wxMenu
;
2084 wxMenu
*menuHelp
= new wxMenu
;
2086 menuHelp
->Append(ID_ABOUT
, wxT("&About..."), wxT("Show about dialog") );
2088 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2089 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2090 menuTools1
->AppendSeparator();
2091 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2092 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2093 menuTools1
->AppendSeparator();
2094 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2095 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2096 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2097 menuTools1
->AppendSeparator();
2098 menuTools1
->Append(ID_SETCOLOUR
, wxT("Set Bg Colour") );
2099 menuTools1
->Append(ID_UNSPECIFY
, wxT("Set to Unspecified") );
2100 menuTools1
->Append(ID_CLEAR
, wxT("Set Value to Default") );
2101 menuTools1
->AppendSeparator();
2102 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2103 wxT("Toggles item's enabled state.") );
2104 m_itemEnable
->Enable( FALSE
);
2105 menuTools1
->Append(ID_HIDE
, wxT("Hide"), wxT("Shows or hides a property") );
2107 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2108 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2109 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2110 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2111 menuTools2
->AppendSeparator();
2112 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2113 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2114 menuTools2
->AppendSeparator();
2115 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2116 wxT("Disables painting, auto-sorting, etc.") );
2117 menuTools2
->AppendSeparator();
2118 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2119 menuTools2
->AppendSeparator();
2120 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2121 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2122 menuTools2
->Append(ID_SETVALUES2
, wxT("Set Property Values 2"), wxT("Adds property values that should not initially be as items (so new items are created).") );
2123 menuTools2
->AppendSeparator();
2124 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2125 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2126 menuTools2
->AppendSeparator();
2127 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2128 wxT("Enable values that are common to all properties, for selected property."));
2129 menuTools2
->AppendSeparator();
2130 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2131 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2132 menuTools2
->AppendSeparator();
2133 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2134 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2135 menuTools2
->AppendSeparator();
2136 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2137 menuTools2
->AppendSeparator();
2138 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2139 menuTools2
->AppendSeparator();
2140 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2141 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2142 menuTools2
->AppendSeparator();
2143 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2144 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2146 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2147 wxT("Select window style flags used by the grid."));
2148 menuTry
->AppendSeparator();
2149 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2150 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2151 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2152 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2153 menuTry
->AppendSeparator();
2154 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2155 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2156 menuTry
->AppendSeparator();
2157 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2158 wxT("Switches between user-modifiedable and static layouts.") );
2159 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2160 menuTry
->AppendSeparator();
2161 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2162 menuTry
->AppendSeparator();
2163 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2164 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2166 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2167 menuFile
->AppendSeparator();
2168 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2170 // Now append the freshly created menu to the menu bar...
2171 wxMenuBar
*menuBar
= new wxMenuBar();
2172 menuBar
->Append(menuFile
, wxT("&File") );
2173 menuBar
->Append(menuTry
, wxT("&Try These!") );
2174 menuBar
->Append(menuTools1
, wxT("&Basic") );
2175 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2176 menuBar
->Append(menuHelp
, wxT("&Help") );
2178 // ... and attach this menu bar to the frame
2179 SetMenuBar(menuBar
);
2182 // create a status bar
2184 SetStatusText(wxEmptyString
);
2185 #endif // wxUSE_STATUSBAR
2193 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2194 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2200 // Normally, wxPropertyGrid does not check whether item with identical
2201 // label already exists. However, since in this sample we use labels for
2202 // identifying properties, we have to be sure not to generate identical
2205 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2210 if ( pg
->GetPropertyByLabel( baselabel
) )
2215 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2216 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2222 baselabel
= newlabel
;
2226 // -----------------------------------------------------------------------
2228 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2232 if ( !m_pPropGridManager
->GetChildrenCount() )
2234 wxMessageBox(wxT("No items to relate - first add some with Append."));
2238 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2241 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2244 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2246 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2248 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2249 m_pPropGridManager
->GetPropertyIndex(id
),
2250 new wxStringProperty(propLabel
) );
2254 // -----------------------------------------------------------------------
2256 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2260 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2262 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2264 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2266 m_pPropGridManager
->Refresh();
2269 // -----------------------------------------------------------------------
2271 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2273 m_pPropGridManager
->GetGrid()->Clear();
2276 // -----------------------------------------------------------------------
2278 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2282 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2284 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2286 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2288 m_pPropGridManager
->Refresh();
2292 // -----------------------------------------------------------------------
2294 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2298 if ( !m_pPropGridManager
->GetChildrenCount() )
2300 wxMessageBox(wxT("No items to relate - first add some with Append."));
2304 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2307 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2311 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2313 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2315 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2316 m_pPropGridManager
->GetPropertyIndex(id
),
2317 new wxPropertyCategory (propLabel
) );
2321 // -----------------------------------------------------------------------
2323 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2325 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2328 wxMessageBox(wxT("First select a property."));
2332 m_pPropGridManager
->DeleteProperty( id
);
2335 // -----------------------------------------------------------------------
2337 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2339 // Delete random property
2340 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2344 if ( !p
->IsCategory() )
2346 m_pPropGridManager
->DeleteProperty( p
);
2350 if ( !p
->GetChildCount() )
2353 int n
= rand() % ((int)p
->GetChildCount());
2359 // -----------------------------------------------------------------------
2361 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2363 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2364 event
.GetPosition().x
,event
.GetPosition().y
);
2369 // -----------------------------------------------------------------------
2371 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2373 /*#ifdef __WXDEBUG__
2374 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2375 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2381 // -----------------------------------------------------------------------
2383 int IterateMessage( wxPGProperty
* prop
)
2387 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2388 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2390 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2393 // -----------------------------------------------------------------------
2395 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2397 wxPropertyGridIterator it
;
2399 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2404 wxPGProperty
* p
= *it
;
2405 int res
= IterateMessage( p
);
2406 if ( res
== wxCANCEL
) break;
2410 // -----------------------------------------------------------------------
2412 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2414 wxPropertyGridIterator it
;
2416 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2417 GetIterator( wxPG_ITERATE_VISIBLE
);
2421 wxPGProperty
* p
= *it
;
2423 int res
= IterateMessage( p
);
2424 if ( res
== wxCANCEL
) break;
2428 // -----------------------------------------------------------------------
2430 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2432 // iterate over items in reverse order
2433 wxPropertyGridIterator it
;
2435 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2436 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2440 wxPGProperty
* p
= *it
;
2442 int res
= IterateMessage( p
);
2443 if ( res
== wxCANCEL
) break;
2447 // -----------------------------------------------------------------------
2449 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2451 wxPropertyGridIterator it
;
2453 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2454 GetIterator( wxPG_ITERATE_CATEGORIES
);
2458 wxPGProperty
* p
= *it
;
2460 int res
= IterateMessage( p
);
2461 if ( res
== wxCANCEL
) break;
2465 // -----------------------------------------------------------------------
2467 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2469 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2471 // Remove auto-centering
2472 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2474 // Grow manager size just prior fit - otherwise
2475 // column information may be lost.
2476 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2477 wxSize oldFullSize
= GetSize();
2478 SetSize(1000, oldFullSize
.y
);
2480 wxSize newSz
= page
->FitColumns();
2482 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2483 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2491 // -----------------------------------------------------------------------
2493 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2495 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2497 wxPGChoices newChoices
;
2499 newChoices
.Add(wxT("Fast"),0x1);
2500 newChoices
.Add(wxT("Powerful"),0x2);
2501 newChoices
.Add(wxT("Safe"),0x4);
2502 newChoices
.Add(wxT("Sleek"),0x8);
2504 p
->SetChoices(newChoices
);
2507 // -----------------------------------------------------------------------
2509 void FormMain::OnEnableDisable( wxCommandEvent
& )
2511 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2514 wxMessageBox(wxT("First select a property."));
2518 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2520 m_pPropGridManager
->DisableProperty ( id
);
2521 m_itemEnable
->SetItemLabel( wxT("Enable") );
2525 m_pPropGridManager
->EnableProperty ( id
);
2526 m_itemEnable
->SetItemLabel( wxT("Disable") );
2530 // -----------------------------------------------------------------------
2532 void FormMain::OnHideShow( wxCommandEvent
& WXUNUSED(event
) )
2534 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2537 wxMessageBox(wxT("First select a property."));
2541 if ( m_pPropGridManager
->IsPropertyShown( id
) )
2543 m_pPropGridManager
->HideProperty( id
, true );
2544 m_itemEnable
->SetItemLabel( wxT("Show") );
2548 m_pPropGridManager
->HideProperty( id
, false );
2549 m_itemEnable
->SetItemLabel( wxT("Hide") );
2552 wxPropertyGridPage
* curPage
= m_pPropGridManager
->GetCurrentPage();
2554 // Check for bottomY precalculation validity
2555 unsigned int byPre
= curPage
->GetVirtualHeight();
2556 unsigned int byAct
= curPage
->GetActualVirtualHeight();
2558 if ( byPre
!= byAct
)
2560 wxLogDebug(wxT("VirtualHeight is %u, should be %u"), byPre
, byAct
);
2564 // -----------------------------------------------------------------------
2566 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2568 m_pPropGridManager
->AddPage(wxT("New Page"));
2571 // -----------------------------------------------------------------------
2573 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2575 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2578 // -----------------------------------------------------------------------
2580 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2582 m_savedState
= m_pPropGridManager
->SaveEditableState();
2583 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2586 // -----------------------------------------------------------------------
2588 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2590 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2593 // -----------------------------------------------------------------------
2595 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2598 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2600 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPG_EDITOR(SpinCtrl
) );
2602 wxMessageBox(wxT("First select a property"));
2606 // -----------------------------------------------------------------------
2608 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2610 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelectedProperty();
2613 wxPGChoices choices
;
2614 choices
.Add(wxT("Flag 0"),0x0001);
2615 choices
.Add(wxT("Flag 1"),0x0002);
2616 choices
.Add(wxT("Flag 2"),0x0004);
2617 choices
.Add(wxT("Flag 3"),0x0008);
2618 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2619 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2620 m_pPropGridManager
->SetPropertyAttribute( newId
,
2621 wxPG_BOOL_USE_CHECKBOX
,
2626 wxMessageBox(wxT("First select a property"));
2629 // -----------------------------------------------------------------------
2631 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2633 m_pPropGridManager
->ClearModifiedStatus();
2636 // -----------------------------------------------------------------------
2638 // Freeze check-box checked?
2639 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2641 if ( !m_pPropGridManager
) return;
2643 if ( event
.IsChecked() )
2645 if ( !m_pPropGridManager
->IsFrozen() )
2647 m_pPropGridManager
->Freeze();
2652 if ( m_pPropGridManager
->IsFrozen() )
2654 m_pPropGridManager
->Thaw();
2655 m_pPropGridManager
->Refresh();
2660 // -----------------------------------------------------------------------
2662 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2665 msg
.Printf( wxT("wxPropertyGrid Sample")
2667 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2681 wxT("Programmed by %s\n\n")
2682 wxT("Using %s\n\n"),
2683 wxT("Jaakko Salli"), wxVERSION_STRING
2686 wxMessageBox(msg
, _T("About"), wxOK
| wxICON_INFORMATION
, this);
2689 // -----------------------------------------------------------------------
2691 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2693 int id
= event
.GetId();
2694 if ( id
== ID_COLOURSCHEME1
)
2696 m_pPropGridManager
->GetGrid()->ResetColours();
2698 else if ( id
== ID_COLOURSCHEME2
)
2701 wxColour
my_grey_1(212,208,200);
2702 wxColour
my_grey_3(113,111,100);
2703 m_pPropGridManager
->Freeze();
2704 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2705 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2706 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2707 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2708 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2709 m_pPropGridManager
->Thaw();
2711 else if ( id
== ID_COLOURSCHEME3
)
2714 wxColour
my_grey_1(212,208,200);
2715 wxColour
my_grey_2(236,233,216);
2716 m_pPropGridManager
->Freeze();
2717 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2718 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2719 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2720 m_pPropGridManager
->Thaw();
2722 else if ( id
== ID_COLOURSCHEME4
)
2726 wxColour
my_grey_1(212,208,200);
2727 wxColour
my_grey_2(241,239,226);
2728 wxColour
my_grey_3(113,111,100);
2729 m_pPropGridManager
->Freeze();
2730 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2731 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2732 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2733 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2734 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2735 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2736 m_pPropGridManager
->Thaw();
2740 // -----------------------------------------------------------------------
2742 void FormMain::OnCatColours( wxCommandEvent
& event
)
2744 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2745 m_pPropGridManager
->Freeze();
2747 if ( event
.IsChecked() )
2749 // Set custom colours.
2750 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2751 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2752 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2753 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2754 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2755 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2756 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2757 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2758 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2759 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2760 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2764 // Revert to original.
2765 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2766 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2767 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2768 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2770 m_pPropGridManager
->Thaw();
2771 m_pPropGridManager
->Refresh();
2774 // -----------------------------------------------------------------------
2776 #define ADD_FLAG(FLAG) \
2777 chs.Add(wxT(#FLAG)); \
2779 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2782 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2791 unsigned int ind
= 0;
2792 int flags
= m_pPropGridManager
->GetWindowStyle();
2793 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2794 ADD_FLAG(wxPG_AUTO_SORT
)
2795 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2796 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2797 ADD_FLAG(wxPG_TOOLTIPS
)
2798 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2799 ADD_FLAG(wxPG_HIDE_MARGIN
)
2800 ADD_FLAG(wxPG_LIMITED_EDITING
)
2801 ADD_FLAG(wxPG_TOOLBAR
)
2802 ADD_FLAG(wxPG_DESCRIPTION
)
2803 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2804 wxT("wxPropertyGrid Window Style"), chs
);
2805 dlg
.SetSelections(sel
);
2806 if ( dlg
.ShowModal() == wxID_CANCEL
)
2810 sel
= dlg
.GetSelections();
2811 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2812 flags
|= vls
[sel
[ind
]];
2821 unsigned int ind
= 0;
2822 int flags
= m_pPropGridManager
->GetExtraStyle();
2823 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2824 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2825 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2826 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2827 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2828 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2829 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2830 ADD_FLAG(wxPG_EX_LEGACY_VALIDATORS
)
2831 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2832 wxT("wxPropertyGrid Extra Style"), chs
);
2833 dlg
.SetSelections(sel
);
2834 if ( dlg
.ShowModal() == wxID_CANCEL
)
2838 sel
= dlg
.GetSelections();
2839 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2840 flags
|= vls
[sel
[ind
]];
2845 CreateGrid( style
, extraStyle
);
2848 (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2849 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8
2854 // -----------------------------------------------------------------------
2856 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2858 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2859 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2862 if ( colCount
>= 2 )
2864 m_pPropGridManager
->SetColumnCount(colCount
);
2868 // -----------------------------------------------------------------------
2870 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2872 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2873 wxPGProperty
* selected
= pg
->GetSelection();
2877 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2878 pg
->SetPropertyValue( selected
, value
);
2882 // -----------------------------------------------------------------------
2884 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2886 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2888 wxPGProperty
* selected
= pg
->GetSelection();
2889 const wxPGChoices
& choices
= selected
->GetChoices();
2891 // Insert new choice to the center of list
2893 if ( choices
.IsOk() )
2895 int pos
= choices
.GetCount() / 2;
2896 selected
->InsertChoice(wxT("New Choice"), pos
);
2900 ::wxMessageBox(wxT("First select a property with some choices."));
2904 // -----------------------------------------------------------------------
2906 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2908 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2910 wxPGProperty
* selected
= pg
->GetSelection();
2911 const wxPGChoices
& choices
= selected
->GetChoices();
2913 // Deletes choice from the center of list
2915 if ( choices
.IsOk() )
2917 int pos
= choices
.GetCount() / 2;
2918 selected
->DeleteChoice(pos
);
2922 ::wxMessageBox(wxT("First select a property with some choices."));
2926 // -----------------------------------------------------------------------
2928 #include <wx/colordlg.h>
2930 void FormMain::OnMisc ( wxCommandEvent
& event
)
2932 int id
= event
.GetId();
2933 if ( id
== ID_STATICLAYOUT
)
2935 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2936 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2937 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2939 else if ( id
== ID_CLEAR
)
2941 m_pPropGridManager
->ClearPropertyValue(m_pPropGridManager
->GetGrid()->GetSelection());
2943 else if ( id
== ID_COLLAPSEALL
)
2946 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2948 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2949 it
.GetProperty()->SetExpanded( false );
2953 else if ( id
== ID_GETVALUES
)
2955 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2956 m_pPropGridManager
->GetGrid()->GetRoot(),
2957 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2959 else if ( id
== ID_SETVALUES
)
2961 if ( m_storedValues
.GetType() == wxT("list") )
2963 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2966 wxMessageBox(wxT("First use Get Property Values."));
2968 else if ( id
== ID_SETVALUES2
)
2972 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2973 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2974 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2975 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2977 else if ( id
== ID_COLLAPSE
)
2979 // Collapses selected.
2980 wxPGProperty
* id
= m_pPropGridManager
->GetSelectedProperty();
2983 m_pPropGridManager
->Collapse(id
);
2986 else if ( id
== ID_RUNTESTFULL
)
2988 // Runs a regression test.
2991 else if ( id
== ID_RUNTESTPARTIAL
)
2993 // Runs a regression test.
2996 else if ( id
== ID_UNSPECIFY
)
2998 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
3001 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3004 else if ( id
== ID_SETCOLOUR
)
3006 wxPGProperty
* prop
= m_pPropGridManager
->GetSelectedProperty();
3010 data
.SetChooseFull(true);
3012 for ( i
= 0; i
< 16; i
++)
3014 wxColour
colour(i
*16, i
*16, i
*16);
3015 data
.SetCustomColour(i
, colour
);
3018 wxColourDialog
dialog(this, &data
);
3019 if ( dialog
.ShowModal() == wxID_OK
)
3021 wxColourData retData
= dialog
.GetColourData();
3022 m_pPropGridManager
->GetGrid()->SetPropertyBackgroundColour(prop
,retData
.GetColour());
3028 // -----------------------------------------------------------------------
3030 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3032 int id
= event
.GetId();
3033 m_propGrid
->Clear();
3034 m_propGrid
->Freeze();
3035 if ( id
== ID_POPULATE1
)
3037 PopulateWithStandardItems();
3039 else if ( id
== ID_POPULATE2
)
3041 PopulateWithLibraryConfig();
3046 // -----------------------------------------------------------------------
3048 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3050 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3052 DisplayMinimalFrame(this);
3055 // -----------------------------------------------------------------------
3057 FormMain::~FormMain()
3061 // -----------------------------------------------------------------------
3063 IMPLEMENT_APP(cxApplication
)
3065 bool cxApplication::OnInit()
3068 //Locale.Init(wxLANGUAGE_FINNISH);
3070 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3074 // Parse command-line
3075 wxApp
& app
= wxGetApp();
3078 wxString s
= app
.argv
[1];
3079 if ( s
== wxT("--run-tests") )
3083 bool testResult
= frame
->RunTests(true);
3093 // -----------------------------------------------------------------------
3095 void FormMain::OnIdle( wxIdleEvent
& event
)
3098 // This code is useful for debugging focus problems
3099 static wxWindow* last_focus = (wxWindow*) NULL;
3101 wxWindow* cur_focus = ::wxWindow::FindFocus();
3103 if ( cur_focus != last_focus )
3105 const wxChar* class_name = wxT("<none>");
3107 class_name = cur_focus->GetClassInfo()->GetClassName();
3108 last_focus = cur_focus;
3109 wxLogDebug( wxT("FOCUSED: %s %X"),
3111 (unsigned int)cur_focus);
3118 // -----------------------------------------------------------------------