1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
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 // 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".
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include "wx/wxprec.h"
38 // for all others, include the necessary headers (this file is usually all you
39 // need because it includes almost all "standard" wxWidgets headers)
45 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
48 #include <wx/numdlg.h>
50 // -----------------------------------------------------------------------
53 // Main propertygrid header.
54 #include <wx/propgrid/propgrid.h>
56 // Extra property classes.
57 #include <wx/propgrid/advprops.h>
59 // This defines wxPropertyGridManager.
60 #include <wx/propgrid/manager.h>
63 #include "sampleprops.h"
65 #if wxUSE_DATEPICKCTRL
66 #include <wx/datectrl.h>
69 #include <wx/artprov.h>
72 #include "../sample.xpm"
75 // -----------------------------------------------------------------------
76 // wxSampleMultiButtonEditor
77 // A sample editor class that has multiple buttons.
78 // -----------------------------------------------------------------------
80 class wxSampleMultiButtonEditor
: public wxPGTextCtrlEditor
82 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor
)
84 wxSampleMultiButtonEditor() {}
85 virtual ~wxSampleMultiButtonEditor() {}
87 virtual wxPGWindowList
CreateControls( wxPropertyGrid
* propGrid
,
88 wxPGProperty
* property
,
90 const wxSize
& sz
) const;
91 virtual bool OnEvent( wxPropertyGrid
* propGrid
,
92 wxPGProperty
* property
,
94 wxEvent
& event
) const;
97 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor
, wxPGTextCtrlEditor
)
99 wxPGWindowList
wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
100 wxPGProperty
* property
,
102 const wxSize
& sz
) const
104 // Create and populate buttons-subwindow
105 wxPGMultiButton
* buttons
= new wxPGMultiButton( propGrid
, sz
);
107 // Add two regular buttons
108 buttons
->Add( "..." );
110 // Add a bitmap button
111 buttons
->Add( wxArtProvider::GetBitmap(wxART_FOLDER
) );
113 // Create the 'primary' editor control (textctrl in this case)
114 wxPGWindowList wndList
= wxPGTextCtrlEditor::CreateControls
115 ( propGrid
, property
, pos
,
116 buttons
->GetPrimarySize() );
118 // Finally, move buttons-subwindow to correct position and make sure
119 // returned wxPGWindowList contains our custom button list.
120 buttons
->Finalize(propGrid
, 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(0) )
137 // Do something when the first button is pressed
138 wxLogDebug("First button pressed");
139 return false; // Return false since value did not change
141 if ( event
.GetId() == buttons
->GetButtonId(1) )
143 // Do something when the second button is pressed
144 wxMessageBox("Second button pressed");
145 return false; // Return false since value did not change
147 if ( event
.GetId() == buttons
->GetButtonId(2) )
149 // Do something when the third button is pressed
150 wxMessageBox("Third button pressed");
151 return false; // Return false since value did not change
154 return wxPGTextCtrlEditor::OnEvent(propGrid
, property
, ctrl
, event
);
157 // -----------------------------------------------------------------------
158 // Validator for wxValidator use sample
159 // -----------------------------------------------------------------------
163 // wxValidator for testing
165 class wxInvalidWordValidator
: public wxValidator
169 wxInvalidWordValidator( const wxString
& invalidWord
)
170 : wxValidator(), m_invalidWord(invalidWord
)
174 virtual wxObject
* Clone() const
176 return new wxInvalidWordValidator(m_invalidWord
);
179 virtual bool Validate(wxWindow
* WXUNUSED(parent
))
181 wxTextCtrl
* tc
= wxDynamicCast(GetWindow(), wxTextCtrl
);
182 wxCHECK_MSG(tc
, true, wxT("validator window must be wxTextCtrl"));
184 wxString val
= tc
->GetValue();
186 if ( val
.find(m_invalidWord
) == wxString::npos
)
189 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord
.c_str()),
190 wxT("Validation Failure"));
196 wxString m_invalidWord
;
199 #endif // wxUSE_VALIDATORS
201 // -----------------------------------------------------------------------
203 // -----------------------------------------------------------------------
205 // See propgridsample.h for wxVector3f class
207 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
209 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
210 wxVector3f
,const wxVector3f
&,TextCtrl
)
213 wxVectorProperty::wxVectorProperty( const wxString
& label
,
214 const wxString
& name
,
215 const wxVector3f
& value
)
216 : wxPGProperty(label
,name
)
218 SetValue( WXVARIANT(value
) );
219 AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
220 AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
221 AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
224 wxVectorProperty::~wxVectorProperty() { }
226 void wxVectorProperty::RefreshChildren()
228 if ( !GetChildCount() ) return;
229 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
230 Item(0)->SetValue( vector
.x
);
231 Item(1)->SetValue( vector
.y
);
232 Item(2)->SetValue( vector
.z
);
235 wxVariant
wxVectorProperty::ChildChanged( wxVariant
& thisValue
,
237 wxVariant
& childValue
) const
241 switch ( childIndex
)
243 case 0: vector
.x
= childValue
.GetDouble(); break;
244 case 1: vector
.y
= childValue
.GetDouble(); break;
245 case 2: vector
.z
= childValue
.GetDouble(); break;
247 wxVariant newVariant
;
248 newVariant
<< vector
;
253 // -----------------------------------------------------------------------
254 // wxTriangleProperty
255 // -----------------------------------------------------------------------
257 // See propgridsample.h for wxTriangle class
259 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
261 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
262 wxTriangle
,const wxTriangle
&,TextCtrl
)
265 wxTriangleProperty::wxTriangleProperty( const wxString
& label
,
266 const wxString
& name
,
267 const wxTriangle
& value
)
268 : wxPGProperty(label
,name
)
270 SetValue( WXVARIANT(value
) );
271 AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
272 AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
273 AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
276 wxTriangleProperty::~wxTriangleProperty() { }
278 void wxTriangleProperty::RefreshChildren()
280 if ( !GetChildCount() ) return;
281 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
282 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
283 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
284 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
287 wxVariant
wxTriangleProperty::ChildChanged( wxVariant
& thisValue
,
289 wxVariant
& childValue
) const
292 triangle
<< thisValue
;
293 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
294 switch ( childIndex
)
296 case 0: triangle
.a
= vector
; break;
297 case 1: triangle
.b
= vector
; break;
298 case 2: triangle
.c
= vector
; break;
300 wxVariant newVariant
;
301 newVariant
<< triangle
;
306 // -----------------------------------------------------------------------
307 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
308 // -----------------------------------------------------------------------
310 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
314 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
315 : wxPGEditorDialogAdapter(), m_choices(choices
)
319 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
320 wxPGProperty
* WXUNUSED(property
) )
322 wxString s
= ::wxGetSingleChoice(wxT("Message"),
324 m_choices
.GetLabels());
335 const wxPGChoices
& m_choices
;
339 class SingleChoiceProperty
: public wxStringProperty
343 SingleChoiceProperty( const wxString
& label
,
344 const wxString
& name
= wxPG_LABEL
,
345 const wxString
& value
= wxEmptyString
)
346 : wxStringProperty(label
, name
, value
)
349 m_choices
.Add(wxT("Cat"));
350 m_choices
.Add(wxT("Dog"));
351 m_choices
.Add(wxT("Gibbon"));
352 m_choices
.Add(wxT("Otter"));
355 // Set editor to have button
356 virtual const wxPGEditor
* DoGetEditorClass() const
358 return wxPGEditor_TextCtrlAndButton
;
361 // Set what happens on button click
362 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
364 return new wxSingleChoiceDialogAdapter(m_choices
);
368 wxPGChoices m_choices
;
371 // -----------------------------------------------------------------------
373 // -----------------------------------------------------------------------
421 ID_SETSPINCTRLEDITOR
,
426 ID_ENABLECOMMONVALUES
,
431 ID_ENABLELABELEDITING
,
437 // -----------------------------------------------------------------------
439 // -----------------------------------------------------------------------
441 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
442 EVT_IDLE(FormMain::OnIdle
)
443 EVT_MOVE(FormMain::OnMove
)
444 EVT_SIZE(FormMain::OnResize
)
446 // This occurs when a property is selected
447 EVT_PG_SELECTED( PGID
, FormMain::OnPropertyGridSelect
)
448 // This occurs when a property value changes
449 EVT_PG_CHANGED( PGID
, FormMain::OnPropertyGridChange
)
450 // This occurs just prior a property value is changed
451 EVT_PG_CHANGING( PGID
, FormMain::OnPropertyGridChanging
)
452 // This occurs when a mouse moves over another property
453 EVT_PG_HIGHLIGHTED( PGID
, FormMain::OnPropertyGridHighlight
)
454 // This occurs when mouse is right-clicked.
455 EVT_PG_RIGHT_CLICK( PGID
, FormMain::OnPropertyGridItemRightClick
)
456 // This occurs when mouse is double-clicked.
457 EVT_PG_DOUBLE_CLICK( PGID
, FormMain::OnPropertyGridItemDoubleClick
)
458 // This occurs when propgridmanager's page changes.
459 EVT_PG_PAGE_CHANGED( PGID
, FormMain::OnPropertyGridPageChange
)
460 // This occurs when user starts editing a property label
461 EVT_PG_LABEL_EDIT_BEGIN( PGID
,
462 FormMain::OnPropertyGridLabelEditBegin
)
463 // This occurs when user stops editing a property label
464 EVT_PG_LABEL_EDIT_ENDING( PGID
,
465 FormMain::OnPropertyGridLabelEditEnding
)
466 // This occurs when property's editor button (if any) is clicked.
467 EVT_BUTTON( PGID
, FormMain::OnPropertyGridButtonClick
)
469 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain::OnPropertyGridItemCollapse
)
470 EVT_PG_ITEM_EXPANDED( PGID
, FormMain::OnPropertyGridItemExpand
)
472 EVT_PG_COL_BEGIN_DRAG( PGID
, FormMain::OnPropertyGridColBeginDrag
)
473 EVT_PG_COL_DRAGGING( PGID
, FormMain::OnPropertyGridColDragging
)
474 EVT_PG_COL_END_DRAG( PGID
, FormMain::OnPropertyGridColEndDrag
)
476 EVT_TEXT( PGID
, FormMain::OnPropertyGridTextUpdate
)
479 // Rest of the events are not property grid specific
480 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent
)
481 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent
)
483 EVT_MENU( ID_APPENDPROP
, FormMain::OnAppendPropClick
)
484 EVT_MENU( ID_APPENDCAT
, FormMain::OnAppendCatClick
)
485 EVT_MENU( ID_INSERTPROP
, FormMain::OnInsertPropClick
)
486 EVT_MENU( ID_INSERTCAT
, FormMain::OnInsertCatClick
)
487 EVT_MENU( ID_DELETE
, FormMain::OnDelPropClick
)
488 EVT_MENU( ID_DELETER
, FormMain::OnDelPropRClick
)
489 EVT_MENU( ID_UNSPECIFY
, FormMain::OnMisc
)
490 EVT_MENU( ID_DELETEALL
, FormMain::OnClearClick
)
491 EVT_MENU( ID_ENABLE
, FormMain::OnEnableDisable
)
492 EVT_MENU( ID_SETREADONLY
, FormMain::OnSetReadOnly
)
493 EVT_MENU( ID_HIDE
, FormMain::OnHide
)
495 EVT_MENU( ID_ITERATE1
, FormMain::OnIterate1Click
)
496 EVT_MENU( ID_ITERATE2
, FormMain::OnIterate2Click
)
497 EVT_MENU( ID_ITERATE3
, FormMain::OnIterate3Click
)
498 EVT_MENU( ID_ITERATE4
, FormMain::OnIterate4Click
)
499 EVT_MENU( ID_ONEXTENDEDKEYNAV
, FormMain::OnExtendedKeyNav
)
500 EVT_MENU( ID_SETBGCOLOUR
, FormMain::OnSetBackgroundColour
)
501 EVT_MENU( ID_SETBGCOLOURRECUR
, FormMain::OnSetBackgroundColour
)
502 EVT_MENU( ID_CLEARMODIF
, FormMain::OnClearModifyStatusClick
)
503 EVT_MENU( ID_FREEZE
, FormMain::OnFreezeClick
)
504 EVT_MENU( ID_ENABLELABELEDITING
, FormMain::OnEnableLabelEditing
)
505 EVT_MENU( ID_SHOWHEADER
, FormMain::OnShowHeader
)
506 EVT_MENU( ID_DUMPLIST
, FormMain::OnDumpList
)
508 EVT_MENU( ID_COLOURSCHEME1
, FormMain::OnColourScheme
)
509 EVT_MENU( ID_COLOURSCHEME2
, FormMain::OnColourScheme
)
510 EVT_MENU( ID_COLOURSCHEME3
, FormMain::OnColourScheme
)
511 EVT_MENU( ID_COLOURSCHEME4
, FormMain::OnColourScheme
)
513 EVT_MENU( ID_ABOUT
, FormMain::OnAbout
)
514 EVT_MENU( ID_QUIT
, FormMain::OnCloseClick
)
516 EVT_MENU( ID_CATCOLOURS
, FormMain::OnCatColours
)
517 EVT_MENU( ID_SETCOLUMNS
, FormMain::OnSetColumns
)
518 EVT_MENU( ID_TESTXRC
, FormMain::OnTestXRC
)
519 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain::OnEnableCommonValues
)
520 EVT_MENU( ID_SELECTSTYLE
, FormMain::OnSelectStyle
)
522 EVT_MENU( ID_STATICLAYOUT
, FormMain::OnMisc
)
523 EVT_MENU( ID_COLLAPSE
, FormMain::OnMisc
)
524 EVT_MENU( ID_COLLAPSEALL
, FormMain::OnMisc
)
526 EVT_MENU( ID_POPULATE1
, FormMain::OnPopulateClick
)
527 EVT_MENU( ID_POPULATE2
, FormMain::OnPopulateClick
)
529 EVT_MENU( ID_GETVALUES
, FormMain::OnMisc
)
530 EVT_MENU( ID_SETVALUES
, FormMain::OnMisc
)
531 EVT_MENU( ID_SETVALUES2
, FormMain::OnMisc
)
533 EVT_MENU( ID_FITCOLUMNS
, FormMain::OnFitColumnsClick
)
535 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain::OnChangeFlagsPropItemsClick
)
537 EVT_MENU( ID_RUNTESTFULL
, FormMain::OnMisc
)
538 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain::OnMisc
)
540 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain::OnInsertChoice
)
541 EVT_MENU( ID_TESTDELETECHOICE
, FormMain::OnDeleteChoice
)
543 EVT_MENU( ID_INSERTPAGE
, FormMain::OnInsertPage
)
544 EVT_MENU( ID_REMOVEPAGE
, FormMain::OnRemovePage
)
546 EVT_MENU( ID_SAVESTATE
, FormMain::OnSaveState
)
547 EVT_MENU( ID_RESTORESTATE
, FormMain::OnRestoreState
)
549 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain::OnSetSpinCtrlEditorClick
)
550 EVT_MENU( ID_TESTREPLACE
, FormMain::OnTestReplaceClick
)
551 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain::OnSetPropertyValue
)
553 EVT_MENU( ID_RUNMINIMAL
, FormMain::OnRunMinimalClick
)
555 EVT_CONTEXT_MENU( FormMain::OnContextMenu
)
558 // -----------------------------------------------------------------------
560 void FormMain::OnMove( wxMoveEvent
& event
)
562 if ( !m_pPropGridManager
)
564 // this check is here so the frame layout can be tested
565 // without creating propertygrid
570 // Update position properties
576 // Must check if properties exist (as they may be deleted).
578 // Using m_pPropGridManager, we can scan all pages automatically.
579 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
581 m_pPropGridManager
->SetPropertyValue( id
, x
);
583 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
585 m_pPropGridManager
->SetPropertyValue( id
, y
);
587 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
589 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxPoint(x
,y
)) );
591 // Should always call event.Skip() in frame's MoveEvent handler
595 // -----------------------------------------------------------------------
597 void FormMain::OnResize( wxSizeEvent
& event
)
599 if ( !m_pPropGridManager
)
601 // this check is here so the frame layout can be tested
602 // without creating propertygrid
607 // Update size properties
614 // Must check if properties exist (as they may be deleted).
616 // Using m_pPropGridManager, we can scan all pages automatically.
617 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
618 if ( p
&& !p
->IsValueUnspecified() )
619 m_pPropGridManager
->SetPropertyValue( p
, w
);
621 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
622 if ( p
&& !p
->IsValueUnspecified() )
623 m_pPropGridManager
->SetPropertyValue( p
, h
);
625 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
627 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxSize(w
,h
)) );
629 // Should always call event.Skip() in frame's SizeEvent handler
633 // -----------------------------------------------------------------------
635 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
637 wxPGProperty
* p
= event
.GetProperty();
639 if ( p
->GetName() == wxT("Font") )
642 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
643 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
644 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
648 wxASSERT(event
.CanVeto());
652 // Since we ask a question, it is better if we omit any validation
654 event
.SetValidationFailureBehavior(0);
660 // Note how we use three types of value getting in this method:
661 // A) event.GetPropertyValueAsXXX
662 // B) event.GetPropertValue, and then variant's GetXXX
663 // C) grid's GetPropertyValueAsXXX(id)
665 void FormMain::OnPropertyGridChange( wxPropertyGridEvent
& event
)
667 wxPGProperty
* property
= event
.GetProperty();
669 const wxString
& name
= property
->GetName();
671 // Properties store values internally as wxVariants, but it is preferred
672 // to use the more modern wxAny at the interface level
673 wxAny value
= property
->GetValue();
675 // Don't handle 'unspecified' values
676 if ( value
.IsNull() )
680 // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
681 // macro is used. Unless you want to support this old
682 // compiler in your own code, you can use the more
683 // nicer form value.As<FOO>() instead of
684 // wxANY_AS(value, FOO).
687 // Some settings are disabled outside Windows platform
688 if ( name
== wxT("X") )
689 SetSize( wxANY_AS(value
, int), -1, -1, -1, wxSIZE_USE_EXISTING
);
690 else if ( name
== wxT("Y") )
691 // wxPGVariantToInt is safe long int value getter
692 SetSize ( -1, wxANY_AS(value
, int), -1, -1, wxSIZE_USE_EXISTING
);
693 else if ( name
== wxT("Width") )
694 SetSize ( -1, -1, wxANY_AS(value
, int), -1, wxSIZE_USE_EXISTING
);
695 else if ( name
== wxT("Height") )
696 SetSize ( -1, -1, -1, wxANY_AS(value
, int), wxSIZE_USE_EXISTING
);
697 else if ( name
== wxT("Label") )
699 SetTitle( wxANY_AS(value
, wxString
) );
701 else if ( name
== wxT("Password") )
703 static int pwdMode
= 0;
705 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
711 if ( name
== wxT("Font") )
713 wxFont font
= wxANY_AS(value
, wxFont
);
714 wxASSERT( font
.Ok() );
716 m_pPropGridManager
->SetFont( font
);
719 if ( name
== wxT("Margin Colour") )
721 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
722 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
724 else if ( name
== wxT("Cell Colour") )
726 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
727 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
729 else if ( name
== wxT("Line Colour") )
731 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
732 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
734 else if ( name
== wxT("Cell Text Colour") )
736 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
737 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
741 // -----------------------------------------------------------------------
743 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
745 wxPGProperty
* property
= event
.GetProperty();
748 m_itemEnable
->Enable( TRUE
);
749 if ( property
->IsEnabled() )
750 m_itemEnable
->SetItemLabel( wxT("Disable") );
752 m_itemEnable
->SetItemLabel( wxT("Enable") );
756 m_itemEnable
->Enable( FALSE
);
760 wxPGProperty
* prop
= event
.GetProperty();
761 wxStatusBar
* sb
= GetStatusBar();
764 wxString
text(wxT("Selected: "));
765 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
766 sb
->SetStatusText ( text
);
771 // -----------------------------------------------------------------------
773 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
776 wxStatusBar
* sb
= GetStatusBar();
777 wxString
text(wxT("Page Changed: "));
778 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
779 sb
->SetStatusText( text
);
783 // -----------------------------------------------------------------------
785 void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent
& event
)
787 wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
788 event
.GetProperty()->GetLabel().c_str());
791 // -----------------------------------------------------------------------
793 void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent
& event
)
795 wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
796 event
.GetProperty()->GetLabel().c_str());
799 // -----------------------------------------------------------------------
801 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
805 // -----------------------------------------------------------------------
807 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
810 wxPGProperty
* prop
= event
.GetProperty();
811 wxStatusBar
* sb
= GetStatusBar();
814 wxString
text(wxT("Right-clicked: "));
815 text
+= prop
->GetLabel();
816 text
+= wxT(", name=");
817 text
+= m_pPropGridManager
->GetPropertyName(prop
);
818 sb
->SetStatusText( text
);
822 sb
->SetStatusText( wxEmptyString
);
827 // -----------------------------------------------------------------------
829 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
832 wxPGProperty
* prop
= event
.GetProperty();
833 wxStatusBar
* sb
= GetStatusBar();
836 wxString
text(wxT("Double-clicked: "));
837 text
+= prop
->GetLabel();
838 text
+= wxT(", name=");
839 text
+= m_pPropGridManager
->GetPropertyName(prop
);
840 sb
->SetStatusText ( text
);
844 sb
->SetStatusText ( wxEmptyString
);
849 // -----------------------------------------------------------------------
851 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent
& )
854 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
855 wxStatusBar
* sb
= GetStatusBar();
858 wxString
text(wxT("Button clicked: "));
859 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
860 text
+= wxT(", name=");
861 text
+= m_pPropGridManager
->GetPropertyName(prop
);
862 sb
->SetStatusText( text
);
866 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
871 // -----------------------------------------------------------------------
873 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
875 wxLogMessage(wxT("Item was Collapsed"));
878 // -----------------------------------------------------------------------
880 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
882 wxLogMessage(wxT("Item was Expanded"));
885 // -----------------------------------------------------------------------
887 void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent
& event
)
889 if ( m_itemVetoDragging
->IsChecked() )
891 wxLogMessage("Splitter %i resize was vetoed", event
.GetColumn());
896 wxLogMessage("Splitter %i resize began", event
.GetColumn());
900 // -----------------------------------------------------------------------
902 void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent
& event
)
905 // For now, let's not spam the log output
906 //wxLogMessage("Splitter %i is being resized", event.GetColumn());
909 // -----------------------------------------------------------------------
911 void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent
& event
)
913 wxLogMessage("Splitter %i resize ended", event
.GetColumn());
916 // -----------------------------------------------------------------------
919 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
924 // -----------------------------------------------------------------------
926 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
928 // Occurs on wxGTK mostly, but not wxMSW.
931 // -----------------------------------------------------------------------
933 void FormMain::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
935 // Uncomment following to allow property label modify in real-time
936 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
937 // if ( !p.IsOk() ) return;
938 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
941 // -----------------------------------------------------------------------
943 static const wxChar
* _fs_windowstyle_labels
[] = {
944 wxT("wxSIMPLE_BORDER"),
945 wxT("wxDOUBLE_BORDER"),
946 wxT("wxSUNKEN_BORDER"),
947 wxT("wxRAISED_BORDER"),
949 wxT("wxTRANSPARENT_WINDOW"),
950 wxT("wxTAB_TRAVERSAL"),
951 wxT("wxWANTS_CHARS"),
952 #if wxNO_FULL_REPAINT_ON_RESIZE
953 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
956 wxT("wxALWAYS_SHOW_SB"),
957 wxT("wxCLIP_CHILDREN"),
958 #if wxFULL_REPAINT_ON_RESIZE
959 wxT("wxFULL_REPAINT_ON_RESIZE"),
961 (const wxChar
*) NULL
// terminator is always needed
964 static const long _fs_windowstyle_values
[] = {
970 wxTRANSPARENT_WINDOW
,
973 #if wxNO_FULL_REPAINT_ON_RESIZE
974 wxNO_FULL_REPAINT_ON_RESIZE
,
979 #if wxFULL_REPAINT_ON_RESIZE
980 wxFULL_REPAINT_ON_RESIZE
984 static const wxChar
* _fs_framestyle_labels
[] = {
989 wxT("wxSTAY_ON_TOP"),
990 wxT("wxSYSTEM_MENU"),
991 wxT("wxRESIZE_BORDER"),
992 wxT("wxFRAME_TOOL_WINDOW"),
993 wxT("wxFRAME_NO_TASKBAR"),
994 wxT("wxFRAME_FLOAT_ON_PARENT"),
995 wxT("wxFRAME_SHAPED"),
999 static const long _fs_framestyle_values
[] = {
1007 wxFRAME_TOOL_WINDOW
,
1009 wxFRAME_FLOAT_ON_PARENT
,
1013 // -----------------------------------------------------------------------
1015 void FormMain::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1017 wxMessageBox(wxT("Sorrt, not yet implemented"));
1020 void FormMain::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1022 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
1024 prop
->EnableCommonValue();
1026 wxMessageBox(wxT("First select a property"));
1029 void FormMain::PopulateWithStandardItems ()
1031 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1032 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1034 // Append is ideal way to add items to wxPropertyGrid.
1035 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1037 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1038 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1039 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1041 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1042 pg
->GetGrid()->GetMarginColour()) );
1044 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1045 pg
->GetGrid()->GetCellBackgroundColour()) );
1046 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1047 pg
->GetGrid()->GetCellTextColour()) );
1048 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1049 pg
->GetGrid()->GetLineColour()) );
1050 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1051 m_combinedFlags
, GetWindowStyle()) );
1053 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1055 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1057 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1058 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1060 // Let's demonstrate 'Units' attribute here
1062 // Note that we use many attribute constants instead of strings here
1063 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1064 // Using constant may reduce binary size.
1066 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1067 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1068 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1069 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1071 // Set value to unspecified so that Hint attribute will be demonstrated
1072 pg
->SetPropertyValueUnspecified("Height");
1073 pg
->SetPropertyAttribute("Height", wxPG_ATTR_HINT
,
1074 "Enter new height for window" );
1076 // Difference between hint and help string is that the hint is shown in
1077 // an empty value cell, while help string is shown either in the
1078 // description text box, as a tool tip, or on the status bar.
1079 pg
->SetPropertyHelpString("Height",
1080 "This property uses attributes \"Units\" and \"Hint\"." );
1082 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1083 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1084 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1085 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1087 pg
->SetPropertyValueUnspecified(wxT("Width"));
1088 pg
->SetPropertyAttribute("Width", wxPG_ATTR_HINT
,
1089 "Enter new width for window" );
1090 pg
->SetPropertyHelpString("Width",
1091 "This property uses attributes \"Units\" and \"Hint\"." );
1093 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1094 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1095 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1097 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1098 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1099 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1101 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. Inorder to have label disabled as well, ")
1102 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1104 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1105 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1107 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1108 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1109 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1111 // Disable some of them
1112 pg
->DisableProperty( wxT("Operating System") );
1113 pg
->DisableProperty( wxT("User Id") );
1114 pg
->DisableProperty( wxT("User Name") );
1116 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1117 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1118 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1120 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1122 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1123 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1124 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1125 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1128 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1129 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1130 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1131 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1132 wxT("with custom action (dir dialog popup) defined.")
1135 wxArrayDouble arrdbl
;
1142 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1143 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1144 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1145 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1146 wxT("It is an example of a custom list editor property.")
1149 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1150 wxT("Editing properties will have immediate effect on this window, ")
1151 wxT("and vice versa (atleast in most cases, that is).")
1153 pg
->SetPropertyHelpString( wxT("Information"),
1154 wxT("This property is read-only.") );
1156 pg
->SetPropertyReadOnly( wxT("Information"), true );
1159 // Set test information for cells in columns 3 and 4
1160 // (reserve column 2 for displaying units)
1161 wxPropertyGridIterator it
;
1162 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_FOLDER
);
1164 for ( it
= pg
->GetGrid()->GetIterator();
1168 wxPGProperty
* p
= *it
;
1169 if ( p
->IsCategory() )
1172 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1173 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1177 // -----------------------------------------------------------------------
1179 void FormMain::PopulateWithExamples ()
1181 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1182 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1186 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1187 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1190 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1192 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl
);
1193 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1194 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)16384 ); // for reduced binary size.
1195 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1196 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
1197 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1199 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1200 wxT("This is regular wxIntProperty, which editor has been ")
1201 wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
1202 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1203 wxT("needs to be called prior to using it."));
1207 // Add bool property
1208 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1210 // Add bool property with check box
1211 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1212 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1213 wxPG_BOOL_USE_CHECKBOX
,
1216 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1217 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1219 prop
= pg
->Append( new wxFloatProperty("FloatProperty",
1222 prop
->SetAttribute("Min", -100.12);
1224 // A string property that can be edited in a separate editor dialog.
1225 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1226 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1228 // A property that edits a wxArrayString.
1229 wxArrayString example_array
;
1230 example_array
.Add( wxT("String 1"));
1231 example_array
.Add( wxT("String 2"));
1232 example_array
.Add( wxT("String 3"));
1233 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1236 // Test adding same category multiple times ( should not actually create a new one )
1237 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1239 // A file selector property. Note that argument between name
1240 // and initial value is wildcard (format same as in wxFileDialog).
1241 prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1244 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1245 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1246 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1249 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1250 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1254 // An image file property. Arguments are just like for FileProperty, but
1255 // wildcard is missing (it is autogenerated from supported image formats).
1256 // If you really need to override it, create property separately, and call
1257 // its SetWildcard method.
1258 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1261 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1262 //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false);
1263 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox
);
1264 pg
->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
1265 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1266 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1267 wxT("editor of this property to wxPGEditor_ComboBox)"));
1270 // This demonstrates using alternative editor for colour property
1271 // to trigger colour dialog directly from button.
1272 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1275 // wxEnumProperty does not store strings or even list of strings
1276 // ( so that's why they are static in function ).
1277 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1278 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1280 // this value array would be optional if values matched string indexes
1281 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1283 // note that the initial value (the last argument) is the actual value,
1284 // not index or anything like that. Thus, our value selects "Another Item".
1286 // 0 before value is number of items. If it is 0, like in our example,
1287 // number of items is calculated, and this requires that the string pointer
1288 // array is terminated with NULL.
1289 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1290 enum_prop_labels
, enum_prop_values
, 80 ) );
1294 // use basic table from our previous example
1295 // can also set/add wxArrayStrings and wxArrayInts directly.
1296 soc
.Set( enum_prop_labels
, enum_prop_values
);
1299 soc
.Add( wxT("Look, it continues"), 200 );
1300 soc
.Add( wxT("Even More"), 240 );
1301 soc
.Add( wxT("And More"), 280 );
1303 soc
.Add( wxT("True End of the List"), 320 );
1305 // Test custom colours ([] operator of wxPGChoices returns
1306 // references to wxPGChoiceEntry).
1307 soc
[1].SetFgCol(*wxRED
);
1308 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1309 soc
[2].SetFgCol(*wxGREEN
);
1310 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1311 soc
[3].SetFgCol(*wxBLUE
);
1312 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1313 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1315 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1319 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1321 // Here we only display the original 'soc' choices
1322 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1325 // Test Hint attribute in EnumProperty
1326 pg
->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
1328 pg
->SetPropertyHelpString("EnumProperty 3",
1329 "This property uses \"Hint\" attribute.");
1331 // 'soc' plus one exclusive extra choice "4th only"
1332 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1334 pg
->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
1336 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1337 wxT("Should have one extra item when compared to EnumProperty 3"));
1339 // Password property example.
1340 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1341 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1342 pg
->SetPropertyHelpString( wxT("Password"),
1343 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1345 // String editor with dir selector button. Uses wxEmptyString as name, which
1346 // is allowed (naturally, in this case property cannot be accessed by name).
1347 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1348 pg
->SetPropertyAttribute( wxT("DirProperty"),
1349 wxPG_DIR_DIALOG_MESSAGE
,
1350 wxT("This is a custom dir dialog message") );
1352 // Add string property - first arg is label, second name, and third initial value
1353 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1354 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1355 pg
->SetPropertyHelpString( wxT("StringProperty"),
1356 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1358 // Set value after limiting so that it will be applied
1359 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1362 // Demonstrate "AutoComplete" attribute
1363 pg
->Append( new wxStringProperty( "StringProperty AutoComplete",
1366 wxArrayString autoCompleteStrings
;
1367 autoCompleteStrings
.Add("One choice");
1368 autoCompleteStrings
.Add("Another choice");
1369 autoCompleteStrings
.Add("Another choice, yeah");
1370 autoCompleteStrings
.Add("Yet another choice");
1371 autoCompleteStrings
.Add("Yet another choice, bear with me");
1372 pg
->SetPropertyAttribute( "StringProperty AutoComplete",
1374 autoCompleteStrings
);
1376 pg
->SetPropertyHelpString( "StringProperty AutoComplete",
1377 "AutoComplete attribute has been set for this property "
1378 "(try writing something beginning with 'a', 'o' or 'y').");
1380 // Add string property with arbitrarily wide bitmap in front of it. We
1381 // intentionally lower-than-typical row height here so that the ugly
1382 // scaling code wont't be run.
1383 pg
->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
1385 wxT("Test Text")) );
1386 wxBitmap
myTestBitmap(60, 15, 32);
1388 mdc
.SelectObject(myTestBitmap
);
1390 mdc
.SetPen(*wxBLACK
);
1391 mdc
.DrawLine(0, 0, 60, 15);
1392 mdc
.SelectObject(wxNullBitmap
);
1393 pg
->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap
);
1396 // this value array would be optional if values matched string indexes
1397 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1399 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1400 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1403 // Multi choice dialog.
1404 wxArrayString tchoices
;
1405 tchoices
.Add(wxT("Cabbage"));
1406 tchoices
.Add(wxT("Carrot"));
1407 tchoices
.Add(wxT("Onion"));
1408 tchoices
.Add(wxT("Potato"));
1409 tchoices
.Add(wxT("Strawberry"));
1411 wxArrayString tchoicesValues
;
1412 tchoicesValues
.Add(wxT("Carrot"));
1413 tchoicesValues
.Add(wxT("Potato"));
1415 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1417 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1418 tchoices
, tchoicesValues
) );
1419 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1421 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1422 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1425 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1426 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1427 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1428 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1429 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1432 // wxEditEnumProperty
1434 eech
.Add(wxT("Choice 1"));
1435 eech
.Add(wxT("Choice 2"));
1436 eech
.Add(wxT("Choice 3"));
1437 pg
->Append( new wxEditEnumProperty("EditEnumProperty",
1440 "Choice not in the list") );
1442 // Test Hint attribute in EditEnumProperty
1443 pg
->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
1446 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1447 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1451 // wxDateTimeProperty
1452 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1454 #if wxUSE_DATEPICKCTRL
1455 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1456 (long)(wxDP_DROPDOWN
|
1460 pg
->SetPropertyHelpString( wxT("DateProperty"),
1461 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
1462 wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
1468 // Add Triangle properties as both wxTriangleProperty and
1469 // a generic parent property (using wxStringProperty).
1471 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1473 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1474 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1475 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1476 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1478 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1480 pg
->SetPropertyHelpString( wxT("3D Object"),
1481 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1482 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1484 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1485 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1486 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1487 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1489 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1492 // This snippet is a doc sample test
1494 wxPGProperty
* carProp
= pg
->Append(new wxStringProperty(wxT("Car"),
1496 wxT("<composed>")));
1498 pg
->AppendIn(carProp
, new wxStringProperty(wxT("Model"),
1500 wxT("Lamborghini Diablo SV")));
1502 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Engine Size (cc)"),
1506 wxPGProperty
* speedsProp
= pg
->AppendIn(carProp
,
1507 new wxStringProperty(wxT("Speeds"),
1509 wxT("<composed>")));
1511 pg
->AppendIn( speedsProp
, new wxIntProperty(wxT("Max. Speed (mph)"),
1513 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("0-100 mph (sec)"),
1515 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("1/4 mile (sec)"),
1518 // This is how child property can be referred to by name
1519 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1521 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Price ($)"),
1525 pg
->AppendIn(carProp
, new wxBoolProperty(wxT("Convertible"),
1529 // Displayed value of "Car" property is now very close to this:
1530 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
1533 // Test wxSampleMultiButtonEditor
1534 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1535 pg
->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor
);
1537 // Test SingleChoiceProperty
1538 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1542 // Test adding variable height bitmaps in wxPGChoices
1545 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1546 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1547 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1549 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1555 // Test how non-editable composite strings appear
1556 pid
= new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>"));
1557 pg
->SetPropertyReadOnly(pid
);
1560 // For testing purposes, combine two methods of adding children
1563 pid
->AppendChild( new wxStringProperty(wxT("Latest Release"),
1566 pid
->AppendChild( new wxBoolProperty(wxT("Win API"),
1572 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1573 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1574 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1575 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1576 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1577 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1578 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1580 AddTestProperties(pg
);
1583 // -----------------------------------------------------------------------
1585 void FormMain::PopulateWithLibraryConfig ()
1587 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1588 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1590 // Set custom column proportions (here in the sample app we need
1591 // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
1592 // need not to do it in your application).
1593 if ( pgman
->HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
1595 pg
->SetColumnProportion(0, 3);
1596 pg
->SetColumnProportion(1, 1);
1601 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1605 wxFont italicFont
= pgman
->GetGrid()->GetCaptionFont();
1606 italicFont
.SetStyle(wxFONTSTYLE_ITALIC
);
1608 wxString italicFontHelp
= "Font of this property's wxPGCell has "
1609 "been modified. Obtain property's cell "
1610 "with wxPGProperty::"
1611 "GetOrCreateCell(column).";
1613 #define ADD_WX_LIB_CONF_GROUP(A) \
1614 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1615 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
1616 cat->GetCell(0).SetFont(italicFont); \
1617 cat->SetHelpString(italicFontHelp);
1619 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1620 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1621 pg->DisableProperty(wxT(#A));
1623 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1624 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1626 // Both of following lines would set a label for the second column
1627 pg
->SetPropertyCell( pid
, 1, "Is Enabled" );
1628 pid
->SetValue("Is Enabled");
1630 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1631 ADD_WX_LIB_CONF( wxUSE_GUI
)
1633 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1634 #if defined(WXWIN_COMPATIBILITY_2_2)
1635 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1637 #if defined(WXWIN_COMPATIBILITY_2_4)
1638 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1640 #if defined(WXWIN_COMPATIBILITY_2_6)
1641 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1643 #if defined(WXWIN_COMPATIBILITY_2_8)
1644 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1646 #ifdef wxFONT_SIZE_COMPATIBILITY
1647 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1649 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1651 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1652 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1654 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1657 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1658 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1659 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1660 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1661 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1662 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1664 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1665 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1666 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1668 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1669 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1670 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1671 ADD_WX_LIB_CONF( wxUSE_STL
)
1672 ADD_WX_LIB_CONF( wxUSE_LOG
)
1673 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1674 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1675 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1676 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1677 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1678 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1679 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1681 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1682 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1683 ADD_WX_LIB_CONF( wxUSE_FILE
)
1684 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1685 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1686 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1687 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1688 ADD_WX_LIB_CONF( wxUSE_INTL
)
1689 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1690 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1691 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1692 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1693 #ifdef wxUSE_CONFIG_NATIVE
1694 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1696 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1698 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1699 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1700 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1701 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1702 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1703 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1704 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1705 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1706 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1707 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1708 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1709 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1710 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1711 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1712 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1713 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1714 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1715 ADD_WX_LIB_CONF( wxUSE_URL
)
1716 #ifdef wxUSE_URL_NATIVE
1717 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1719 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1721 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1722 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1723 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1725 ADD_WX_LIB_CONF( wxUSE_XRC
)
1727 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1729 ADD_WX_LIB_CONF( wxUSE_XML
)
1731 // Set them to use check box.
1732 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1737 // Handle events of the third page here.
1738 class wxMyPropertyGridPage
: public wxPropertyGridPage
1742 // Return false here to indicate unhandled events should be
1743 // propagated to manager's parent, as normal.
1744 virtual bool IsHandlingAllEvents() const { return false; }
1748 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1750 wxPGProperty
* property
)
1752 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1755 void OnPropertySelect( wxPropertyGridEvent
& event
);
1756 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1757 void OnPropertyChange( wxPropertyGridEvent
& event
);
1758 void OnPageChange( wxPropertyGridEvent
& event
);
1761 DECLARE_EVENT_TABLE()
1765 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1766 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1767 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1768 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1769 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1773 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1775 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1778 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1780 wxPGProperty
* p
= event
.GetProperty();
1781 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1782 p
->GetName().c_str(),
1783 p
->GetDisplayedString().c_str());
1786 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1788 wxPGProperty
* p
= event
.GetProperty();
1789 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1790 p
->GetName().c_str(),
1791 event
.GetValue().GetString().c_str());
1794 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1796 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1800 class wxPGKeyHandler
: public wxEvtHandler
1804 void OnKeyEvent( wxKeyEvent
& event
)
1806 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1810 DECLARE_EVENT_TABLE()
1813 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1814 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1818 // -----------------------------------------------------------------------
1820 void FormMain::InitPanel()
1825 wxWindow
* panel
= new wxPanel(this, wxID_ANY
,
1826 wxPoint(0, 0), wxSize(400, 400),
1831 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1833 m_topSizer
= topSizer
;
1836 void FormMain::FinalizePanel( bool wasCreated
)
1838 // Button for tab traversal testing
1839 m_topSizer
->Add( new wxButton(m_panel
, wxID_ANY
,
1840 wxS("Should be able to move here with Tab")),
1843 m_panel
->SetSizer( m_topSizer
);
1844 m_topSizer
->SetSizeHints( m_panel
);
1846 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1847 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1849 SetSizer( panelSizer
);
1850 panelSizer
->SetSizeHints( this );
1853 FinalizeFramePosition();
1856 void FormMain::PopulateGrid()
1858 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1859 pgman
->AddPage(wxT("Standard Items"));
1861 PopulateWithStandardItems();
1863 pgman
->AddPage(wxT("wxWidgets Library Config"));
1865 PopulateWithLibraryConfig();
1867 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1868 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1870 // Use wxMyPropertyGridPage (see above) to test the
1871 // custom wxPropertyGridPage feature.
1872 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1874 PopulateWithExamples();
1877 void FormMain::CreateGrid( int style
, int extraStyle
)
1880 // This function (re)creates the property grid in our sample
1884 style
= // default style
1885 wxPG_BOLD_MODIFIED
|
1886 wxPG_SPLITTER_AUTO_CENTER
|
1888 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1890 //wxPG_HIDE_CATEGORIES |
1891 //wxPG_LIMITED_EDITING |
1895 if ( extraStyle
== -1 )
1896 // default extra style
1897 extraStyle
= wxPG_EX_MODE_BUTTONS
|
1898 wxPG_EX_MULTIPLE_SELECTION
;
1899 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1900 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1901 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1902 //| wxPG_EX_HELP_AS_TOOLTIPS
1904 bool wasCreated
= m_panel
? false : true;
1909 // This shows how to combine two static choice descriptors
1910 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1911 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1913 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1914 new wxPropertyGridManager(m_panel
,
1915 // Don't change this into wxID_ANY in the sample, or the
1916 // event handling will obviously be broken.
1919 wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
1920 // But calling SetInitialSize in manager changes the code
1921 // order to the grid gets created immediately, before SetExtraStyle
1925 m_propGrid
= pgman
->GetGrid();
1927 pgman
->SetExtraStyle(extraStyle
);
1929 // This is the default validation failure behavior
1930 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL
|
1931 wxPG_VFB_SHOW_MESSAGEBOX
);
1933 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
1936 // Set somewhat different unspecified value appearance
1938 cell
.SetText("Unspecified");
1939 cell
.SetFgCol(*wxLIGHT_GREY
);
1940 m_propGrid
->SetUnspecifiedValueAppearance(cell
);
1944 // Change some attributes in all properties
1945 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
1946 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
1948 //m_pPropGridManager->SetSplitterLeft(true);
1949 //m_pPropGridManager->SetSplitterPosition(137);
1952 // This would setup event handling without event table entries
1953 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
1954 wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
1955 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
1956 wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
1959 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
1961 FinalizePanel(wasCreated
);
1964 // -----------------------------------------------------------------------
1966 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
1967 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
1968 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
1969 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
1971 SetIcon(wxICON(sample
));
1977 // we need this in order to allow the about menu relocation, since ABOUT is
1978 // not the default id of the about menu
1979 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
1983 // This is here to really test the wxImageFileProperty.
1984 wxInitAllImageHandlers();
1987 // Register all editors (SpinCtrl etc.)
1988 m_pPropGridManager
->RegisterAdditionalEditors();
1990 // Register our sample custom editors
1991 m_pSampleMultiButtonEditor
=
1992 wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
1994 CreateGrid( // style
1995 wxPG_BOLD_MODIFIED
|
1996 wxPG_SPLITTER_AUTO_CENTER
|
1998 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2000 //wxPG_HIDE_CATEGORIES |
2001 //wxPG_LIMITED_EDITING |
2005 wxPG_EX_MODE_BUTTONS
|
2006 wxPG_EX_MULTIPLE_SELECTION
2007 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2008 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2009 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2010 //| wxPG_EX_HELP_AS_TOOLTIPS
2015 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2016 wxMenu
*menuTry
= new wxMenu
;
2017 wxMenu
*menuTools1
= new wxMenu
;
2018 wxMenu
*menuTools2
= new wxMenu
;
2019 wxMenu
*menuHelp
= new wxMenu
;
2021 menuHelp
->Append(ID_ABOUT
, wxT("&About..."), wxT("Show about dialog") );
2023 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2024 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2025 menuTools1
->AppendSeparator();
2026 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2027 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2028 menuTools1
->AppendSeparator();
2029 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2030 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2031 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2032 menuTools1
->AppendSeparator();
2033 menuTools1
->Append(ID_SETBGCOLOUR
, wxT("Set Bg Colour") );
2034 menuTools1
->Append(ID_SETBGCOLOURRECUR
, wxT("Set Bg Colour (Recursively)") );
2035 menuTools1
->Append(ID_UNSPECIFY
, "Set Value to Unspecified");
2036 menuTools1
->AppendSeparator();
2037 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2038 wxT("Toggles item's enabled state.") );
2039 m_itemEnable
->Enable( FALSE
);
2040 menuTools1
->Append(ID_HIDE
, "Hide", "Hides a property" );
2041 menuTools1
->Append(ID_SETREADONLY
, "Set as Read-Only",
2042 "Set property as read-only" );
2044 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2045 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2046 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2047 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2048 menuTools2
->AppendSeparator();
2049 menuTools2
->Append(ID_ONEXTENDEDKEYNAV
, "Extend Keyboard Navigation",
2050 "This will set Enter to navigate to next property, "
2051 "and allows arrow keys to navigate even when in "
2053 menuTools2
->AppendSeparator();
2054 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2055 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2056 menuTools2
->AppendSeparator();
2057 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2058 wxT("Disables painting, auto-sorting, etc.") );
2059 menuTools2
->AppendSeparator();
2060 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2061 menuTools2
->AppendSeparator();
2062 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2063 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2064 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).") );
2065 menuTools2
->AppendSeparator();
2066 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2067 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2068 menuTools2
->AppendSeparator();
2069 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2070 wxT("Enable values that are common to all properties, for selected property."));
2071 menuTools2
->AppendSeparator();
2072 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2073 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2074 menuTools2
->AppendSeparator();
2075 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2076 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2077 menuTools2
->AppendSeparator();
2078 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2079 m_itemVetoDragging
=
2080 menuTools2
->AppendCheckItem(ID_VETOCOLDRAG
,
2081 "Veto Column Dragging");
2082 menuTools2
->AppendSeparator();
2083 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2084 menuTools2
->AppendSeparator();
2085 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2086 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2087 menuTools2
->AppendSeparator();
2088 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2089 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2091 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2092 wxT("Select window style flags used by the grid."));
2093 menuTry
->Append(ID_ENABLELABELEDITING
, "Enable label editing",
2094 "This calls wxPropertyGrid::MakeColumnEditable(0)");
2095 menuTry
->AppendCheckItem(ID_SHOWHEADER
,
2097 "This calls wxPropertyGridManager::ShowHeader()");
2098 menuTry
->AppendSeparator();
2099 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2100 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2101 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2102 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2103 menuTry
->AppendSeparator();
2104 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2105 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2106 menuTry
->AppendSeparator();
2107 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2108 wxT("Switches between user-modifiedable and static layouts.") );
2109 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2110 menuTry
->AppendSeparator();
2111 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2112 menuTry
->AppendSeparator();
2113 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2114 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2116 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2117 menuFile
->AppendSeparator();
2118 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2120 // Now append the freshly created menu to the menu bar...
2121 wxMenuBar
*menuBar
= new wxMenuBar();
2122 menuBar
->Append(menuFile
, wxT("&File") );
2123 menuBar
->Append(menuTry
, wxT("&Try These!") );
2124 menuBar
->Append(menuTools1
, wxT("&Basic") );
2125 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2126 menuBar
->Append(menuHelp
, wxT("&Help") );
2128 // ... and attach this menu bar to the frame
2129 SetMenuBar(menuBar
);
2132 // create a status bar
2134 SetStatusText(wxEmptyString
);
2135 #endif // wxUSE_STATUSBAR
2137 FinalizeFramePosition();
2140 // Create log window
2141 m_logWindow
= new wxLogWindow(this, "Log Messages", false);
2142 m_logWindow
->GetFrame()->Move(GetPosition().x
+ GetSize().x
+ 10,
2144 m_logWindow
->Show();
2148 void FormMain::FinalizeFramePosition()
2150 wxSize
frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2151 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8);
2153 if ( frameSize
.x
> 500 )
2162 // Normally, wxPropertyGrid does not check whether item with identical
2163 // label already exists. However, since in this sample we use labels for
2164 // identifying properties, we have to be sure not to generate identical
2167 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2172 if ( pg
->GetPropertyByLabel( baselabel
) )
2177 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2178 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2184 baselabel
= newlabel
;
2188 // -----------------------------------------------------------------------
2190 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2194 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2196 wxMessageBox(wxT("No items to relate - first add some with Append."));
2200 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2203 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2206 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2208 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2210 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2211 id
->GetIndexInParent(),
2212 new wxStringProperty(propLabel
) );
2216 // -----------------------------------------------------------------------
2218 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2222 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2224 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2226 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2228 m_pPropGridManager
->Refresh();
2231 // -----------------------------------------------------------------------
2233 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2235 m_pPropGridManager
->GetGrid()->Clear();
2238 // -----------------------------------------------------------------------
2240 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2244 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2246 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2248 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2250 m_pPropGridManager
->Refresh();
2254 // -----------------------------------------------------------------------
2256 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2260 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2262 wxMessageBox(wxT("No items to relate - first add some with Append."));
2266 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2269 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2273 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2275 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2277 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2278 id
->GetIndexInParent(),
2279 new wxPropertyCategory (propLabel
) );
2282 // -----------------------------------------------------------------------
2284 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2286 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2289 wxMessageBox(wxT("First select a property."));
2293 m_pPropGridManager
->DeleteProperty( id
);
2296 // -----------------------------------------------------------------------
2298 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2300 // Delete random property
2301 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2305 if ( !p
->IsCategory() )
2307 m_pPropGridManager
->DeleteProperty( p
);
2311 if ( !p
->GetChildCount() )
2314 int n
= rand() % ((int)p
->GetChildCount());
2320 // -----------------------------------------------------------------------
2322 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2324 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2325 event
.GetPosition().x
,event
.GetPosition().y
);
2332 // -----------------------------------------------------------------------
2334 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2336 /*#ifdef __WXDEBUG__
2337 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2338 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2344 // -----------------------------------------------------------------------
2346 int IterateMessage( wxPGProperty
* prop
)
2350 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2351 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2353 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2356 // -----------------------------------------------------------------------
2358 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2360 wxPropertyGridIterator it
;
2362 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2367 wxPGProperty
* p
= *it
;
2368 int res
= IterateMessage( p
);
2369 if ( res
== wxCANCEL
) break;
2373 // -----------------------------------------------------------------------
2375 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2377 wxPropertyGridIterator it
;
2379 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2380 GetIterator( wxPG_ITERATE_VISIBLE
);
2384 wxPGProperty
* p
= *it
;
2386 int res
= IterateMessage( p
);
2387 if ( res
== wxCANCEL
) break;
2391 // -----------------------------------------------------------------------
2393 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2395 // iterate over items in reverse order
2396 wxPropertyGridIterator it
;
2398 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2399 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2403 wxPGProperty
* p
= *it
;
2405 int res
= IterateMessage( p
);
2406 if ( res
== wxCANCEL
) break;
2410 // -----------------------------------------------------------------------
2412 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2414 wxPropertyGridIterator it
;
2416 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2417 GetIterator( wxPG_ITERATE_CATEGORIES
);
2421 wxPGProperty
* p
= *it
;
2423 int res
= IterateMessage( p
);
2424 if ( res
== wxCANCEL
) break;
2428 // -----------------------------------------------------------------------
2430 void FormMain::OnExtendedKeyNav( wxCommandEvent
& WXUNUSED(event
) )
2432 // Use AddActionTrigger() and DedicateKey() to set up Enter,
2433 // Up, and Down keys for navigating between properties.
2434 wxPropertyGrid
* propGrid
= m_pPropGridManager
->GetGrid();
2436 propGrid
->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY
,
2438 propGrid
->DedicateKey(WXK_RETURN
);
2440 // Up and Down keys are alredy associated with navigation,
2441 // but we must also prevent them from being eaten by
2443 propGrid
->DedicateKey(WXK_UP
);
2444 propGrid
->DedicateKey(WXK_DOWN
);
2447 // -----------------------------------------------------------------------
2449 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2451 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2453 // Remove auto-centering
2454 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2456 // Grow manager size just prior fit - otherwise
2457 // column information may be lost.
2458 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2459 wxSize oldFullSize
= GetSize();
2460 SetSize(1000, oldFullSize
.y
);
2462 wxSize newSz
= page
->FitColumns();
2464 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2465 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2473 // -----------------------------------------------------------------------
2475 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2477 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2479 wxPGChoices newChoices
;
2481 newChoices
.Add(wxT("Fast"),0x1);
2482 newChoices
.Add(wxT("Powerful"),0x2);
2483 newChoices
.Add(wxT("Safe"),0x4);
2484 newChoices
.Add(wxT("Sleek"),0x8);
2486 p
->SetChoices(newChoices
);
2489 // -----------------------------------------------------------------------
2491 void FormMain::OnEnableDisable( wxCommandEvent
& )
2493 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2496 wxMessageBox(wxT("First select a property."));
2500 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2502 m_pPropGridManager
->DisableProperty ( id
);
2503 m_itemEnable
->SetItemLabel( wxT("Enable") );
2507 m_pPropGridManager
->EnableProperty ( id
);
2508 m_itemEnable
->SetItemLabel( wxT("Disable") );
2512 // -----------------------------------------------------------------------
2514 void FormMain::OnSetReadOnly( wxCommandEvent
& WXUNUSED(event
) )
2516 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetSelection();
2519 wxMessageBox(wxT("First select a property."));
2522 m_pPropGridManager
->SetPropertyReadOnly(p
);
2525 // -----------------------------------------------------------------------
2527 void FormMain::OnHide( wxCommandEvent
& WXUNUSED(event
) )
2529 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2532 wxMessageBox(wxT("First select a property."));
2536 m_pPropGridManager
->HideProperty( id
, true );
2539 // -----------------------------------------------------------------------
2541 #include "wx/colordlg.h"
2544 FormMain::OnSetBackgroundColour( wxCommandEvent
& event
)
2546 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2547 wxPGProperty
* prop
= pg
->GetSelection();
2550 wxMessageBox(wxT("First select a property."));
2554 wxColour col
= ::wxGetColourFromUser(this, *wxWHITE
, "Choose colour");
2558 bool recursively
= (event
.GetId()==ID_SETBGCOLOURRECUR
) ? true : false;
2559 pg
->SetPropertyBackgroundColour(prop
, col
, recursively
);
2563 // -----------------------------------------------------------------------
2565 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2567 m_pPropGridManager
->AddPage(wxT("New Page"));
2570 // -----------------------------------------------------------------------
2572 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2574 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2577 // -----------------------------------------------------------------------
2579 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2581 m_savedState
= m_pPropGridManager
->SaveEditableState();
2582 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2585 // -----------------------------------------------------------------------
2587 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2589 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2592 // -----------------------------------------------------------------------
2594 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2597 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2599 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPGEditor_SpinCtrl
);
2601 wxMessageBox(wxT("First select a property"));
2605 // -----------------------------------------------------------------------
2607 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2609 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2612 wxPGChoices choices
;
2613 choices
.Add(wxT("Flag 0"),0x0001);
2614 choices
.Add(wxT("Flag 1"),0x0002);
2615 choices
.Add(wxT("Flag 2"),0x0004);
2616 choices
.Add(wxT("Flag 3"),0x0008);
2617 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2618 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2619 m_pPropGridManager
->SetPropertyAttribute( newId
,
2620 wxPG_BOOL_USE_CHECKBOX
,
2625 wxMessageBox(wxT("First select a property"));
2628 // -----------------------------------------------------------------------
2630 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2632 m_pPropGridManager
->ClearModifiedStatus();
2635 // -----------------------------------------------------------------------
2637 // Freeze check-box checked?
2638 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2640 if ( !m_pPropGridManager
) return;
2642 if ( event
.IsChecked() )
2644 if ( !m_pPropGridManager
->IsFrozen() )
2646 m_pPropGridManager
->Freeze();
2651 if ( m_pPropGridManager
->IsFrozen() )
2653 m_pPropGridManager
->Thaw();
2654 m_pPropGridManager
->Refresh();
2659 // -----------------------------------------------------------------------
2661 void FormMain::OnEnableLabelEditing( wxCommandEvent
& WXUNUSED(event
) )
2663 m_propGrid
->MakeColumnEditable(0);
2666 // -----------------------------------------------------------------------
2668 void FormMain::OnShowHeader( wxCommandEvent
& event
)
2670 m_pPropGridManager
->ShowHeader(event
.IsChecked());
2671 m_pPropGridManager
->SetColumnTitle(2, _("Units"));
2674 // -----------------------------------------------------------------------
2676 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2679 msg
.Printf( wxT("wxPropertyGrid Sample")
2681 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2695 wxT("Programmed by %s\n\n")
2696 wxT("Using %s\n\n"),
2697 wxT("Jaakko Salli"), wxVERSION_STRING
2700 wxMessageBox(msg
, wxT("About"), wxOK
| wxICON_INFORMATION
, this);
2703 // -----------------------------------------------------------------------
2705 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2707 int id
= event
.GetId();
2708 if ( id
== ID_COLOURSCHEME1
)
2710 m_pPropGridManager
->GetGrid()->ResetColours();
2712 else if ( id
== ID_COLOURSCHEME2
)
2715 wxColour
my_grey_1(212,208,200);
2716 wxColour
my_grey_3(113,111,100);
2717 m_pPropGridManager
->Freeze();
2718 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2719 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2720 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2721 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2722 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2723 m_pPropGridManager
->Thaw();
2725 else if ( id
== ID_COLOURSCHEME3
)
2728 wxColour
my_grey_1(212,208,200);
2729 wxColour
my_grey_2(236,233,216);
2730 m_pPropGridManager
->Freeze();
2731 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2732 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2733 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2734 m_pPropGridManager
->Thaw();
2736 else if ( id
== ID_COLOURSCHEME4
)
2740 wxColour
my_grey_1(212,208,200);
2741 wxColour
my_grey_2(241,239,226);
2742 wxColour
my_grey_3(113,111,100);
2743 m_pPropGridManager
->Freeze();
2744 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2745 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2746 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2747 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2748 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2749 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2750 m_pPropGridManager
->Thaw();
2754 // -----------------------------------------------------------------------
2756 void FormMain::OnCatColours( wxCommandEvent
& event
)
2758 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2759 m_pPropGridManager
->Freeze();
2761 if ( event
.IsChecked() )
2763 // Set custom colours.
2764 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2765 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2766 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2767 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2768 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2769 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2770 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2771 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2772 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2773 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2774 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2778 // Revert to original.
2779 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2780 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2781 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2782 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2784 m_pPropGridManager
->Thaw();
2785 m_pPropGridManager
->Refresh();
2788 // -----------------------------------------------------------------------
2790 #define ADD_FLAG(FLAG) \
2791 chs.Add(wxT(#FLAG)); \
2793 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2796 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2805 unsigned int ind
= 0;
2806 int flags
= m_pPropGridManager
->GetWindowStyle();
2807 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2808 ADD_FLAG(wxPG_AUTO_SORT
)
2809 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2810 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2811 ADD_FLAG(wxPG_TOOLTIPS
)
2812 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2813 ADD_FLAG(wxPG_HIDE_MARGIN
)
2814 ADD_FLAG(wxPG_LIMITED_EDITING
)
2815 ADD_FLAG(wxPG_TOOLBAR
)
2816 ADD_FLAG(wxPG_DESCRIPTION
)
2817 ADD_FLAG(wxPG_NO_INTERNAL_BORDER
)
2818 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2819 wxT("wxPropertyGrid Window Style"), chs
);
2820 dlg
.SetSelections(sel
);
2821 if ( dlg
.ShowModal() == wxID_CANCEL
)
2825 sel
= dlg
.GetSelections();
2826 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2827 flags
|= vls
[sel
[ind
]];
2836 unsigned int ind
= 0;
2837 int flags
= m_pPropGridManager
->GetExtraStyle();
2838 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2839 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2840 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2841 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2842 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2843 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2844 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2845 ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS
)
2846 ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION
)
2847 ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING
)
2848 ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER
)
2849 ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR
)
2850 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2851 wxT("wxPropertyGrid Extra Style"), chs
);
2852 dlg
.SetSelections(sel
);
2853 if ( dlg
.ShowModal() == wxID_CANCEL
)
2857 sel
= dlg
.GetSelections();
2858 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2859 flags
|= vls
[sel
[ind
]];
2864 CreateGrid( style
, extraStyle
);
2866 FinalizeFramePosition();
2869 // -----------------------------------------------------------------------
2871 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2873 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2874 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2877 if ( colCount
>= 2 )
2879 m_pPropGridManager
->SetColumnCount(colCount
);
2883 // -----------------------------------------------------------------------
2885 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2887 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2888 wxPGProperty
* selected
= pg
->GetSelection();
2892 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2893 pg
->SetPropertyValue( selected
, value
);
2897 // -----------------------------------------------------------------------
2899 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2901 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2903 wxPGProperty
* selected
= pg
->GetSelection();
2904 const wxPGChoices
& choices
= selected
->GetChoices();
2906 // Insert new choice to the center of list
2908 if ( choices
.IsOk() )
2910 int pos
= choices
.GetCount() / 2;
2911 selected
->InsertChoice(wxT("New Choice"), pos
);
2915 ::wxMessageBox(wxT("First select a property with some choices."));
2919 // -----------------------------------------------------------------------
2921 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2923 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2925 wxPGProperty
* selected
= pg
->GetSelection();
2926 const wxPGChoices
& choices
= selected
->GetChoices();
2928 // Deletes choice from the center of list
2930 if ( choices
.IsOk() )
2932 int pos
= choices
.GetCount() / 2;
2933 selected
->DeleteChoice(pos
);
2937 ::wxMessageBox(wxT("First select a property with some choices."));
2941 // -----------------------------------------------------------------------
2943 #include <wx/colordlg.h>
2945 void FormMain::OnMisc ( wxCommandEvent
& event
)
2947 int id
= event
.GetId();
2948 if ( id
== ID_STATICLAYOUT
)
2950 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2951 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2952 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2954 else if ( id
== ID_COLLAPSEALL
)
2957 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2959 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2960 it
.GetProperty()->SetExpanded( false );
2964 else if ( id
== ID_GETVALUES
)
2966 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2967 m_pPropGridManager
->GetGrid()->GetRoot(),
2968 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2970 else if ( id
== ID_SETVALUES
)
2972 if ( m_storedValues
.GetType() == wxT("list") )
2974 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2977 wxMessageBox(wxT("First use Get Property Values."));
2979 else if ( id
== ID_SETVALUES2
)
2983 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2984 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2985 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2986 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2988 else if ( id
== ID_COLLAPSE
)
2990 // Collapses selected.
2991 wxPGProperty
* id
= m_pPropGridManager
->GetSelection();
2994 m_pPropGridManager
->Collapse(id
);
2997 else if ( id
== ID_RUNTESTFULL
)
2999 // Runs a regression test.
3002 else if ( id
== ID_RUNTESTPARTIAL
)
3004 // Runs a regression test.
3007 else if ( id
== ID_UNSPECIFY
)
3009 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
3012 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3013 prop
->RefreshEditor();
3018 // -----------------------------------------------------------------------
3020 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3022 int id
= event
.GetId();
3023 m_propGrid
->Clear();
3024 m_propGrid
->Freeze();
3025 if ( id
== ID_POPULATE1
)
3027 PopulateWithStandardItems();
3029 else if ( id
== ID_POPULATE2
)
3031 PopulateWithLibraryConfig();
3036 // -----------------------------------------------------------------------
3038 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3040 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3042 DisplayMinimalFrame(this);
3045 // -----------------------------------------------------------------------
3047 FormMain::~FormMain()
3051 // -----------------------------------------------------------------------
3053 IMPLEMENT_APP(cxApplication
)
3055 bool cxApplication::OnInit()
3058 //Locale.Init(wxLANGUAGE_FINNISH);
3060 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3064 // Parse command-line
3065 wxApp
& app
= wxGetApp();
3068 wxString s
= app
.argv
[1];
3069 if ( s
== wxT("--run-tests") )
3073 bool testResult
= frame
->RunTests(true);
3083 // -----------------------------------------------------------------------
3085 void FormMain::OnIdle( wxIdleEvent
& event
)
3088 // This code is useful for debugging focus problems
3089 static wxWindow* last_focus = (wxWindow*) NULL;
3091 wxWindow* cur_focus = ::wxWindow::FindFocus();
3093 if ( cur_focus != last_focus )
3095 const wxChar* class_name = wxT("<none>");
3097 class_name = cur_focus->GetClassInfo()->GetClassName();
3098 last_focus = cur_focus;
3099 wxLogDebug( wxT("FOCUSED: %s %X"),
3101 (unsigned int)cur_focus);
3108 // -----------------------------------------------------------------------