1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 // * Examples of custom property classes are in sampleprops.cpp.
17 // * Additional ones can be found below.
19 // * Currently there is no example of a custom property editor. However,
20 // SpinCtrl editor sample is well-commented. It can be found in
21 // src/propgrid/advprops.cpp.
23 // * To find code that populates the grid with properties, search for
24 // string "::Populate".
26 // * To find code that handles property grid changes, search for string
27 // "::OnPropertyGridChange".
30 // For compilers that support precompilation, includes "wx/wx.h".
31 #include "wx/wxprec.h"
37 // for all others, include the necessary headers (this file is usually all you
38 // need because it includes almost all "standard" wxWidgets headers)
44 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
47 #include <wx/numdlg.h>
49 // -----------------------------------------------------------------------
52 // Main propertygrid header.
53 #include <wx/propgrid/propgrid.h>
55 // Extra property classes.
56 #include <wx/propgrid/advprops.h>
58 // This defines wxPropertyGridManager.
59 #include <wx/propgrid/manager.h>
62 #include "sampleprops.h"
64 #if wxUSE_DATEPICKCTRL
65 #include <wx/datectrl.h>
68 #include <wx/artprov.h>
70 #ifndef wxHAS_IMAGES_IN_RESOURCES
71 #include "../sample.xpm"
74 // -----------------------------------------------------------------------
75 // wxSampleMultiButtonEditor
76 // A sample editor class that has multiple buttons.
77 // -----------------------------------------------------------------------
79 class wxSampleMultiButtonEditor
: public wxPGTextCtrlEditor
81 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor
)
83 wxSampleMultiButtonEditor() {}
84 virtual ~wxSampleMultiButtonEditor() {}
86 virtual wxPGWindowList
CreateControls( wxPropertyGrid
* propGrid
,
87 wxPGProperty
* property
,
89 const wxSize
& sz
) const;
90 virtual bool OnEvent( wxPropertyGrid
* propGrid
,
91 wxPGProperty
* property
,
93 wxEvent
& event
) const;
96 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor
, wxPGTextCtrlEditor
)
98 wxPGWindowList
wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
99 wxPGProperty
* property
,
101 const wxSize
& sz
) const
103 // Create and populate buttons-subwindow
104 wxPGMultiButton
* buttons
= new wxPGMultiButton( propGrid
, sz
);
106 // Add two regular buttons
107 buttons
->Add( "..." );
109 // Add a bitmap button
110 buttons
->Add( wxArtProvider::GetBitmap(wxART_FOLDER
) );
112 // Create the 'primary' editor control (textctrl in this case)
113 wxPGWindowList wndList
= wxPGTextCtrlEditor::CreateControls
114 ( propGrid
, property
, pos
,
115 buttons
->GetPrimarySize() );
117 // Finally, move buttons-subwindow to correct position and make sure
118 // returned wxPGWindowList contains our custom button list.
119 buttons
->Finalize(propGrid
, pos
);
121 wndList
.SetSecondary( buttons
);
125 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid
* propGrid
,
126 wxPGProperty
* property
,
128 wxEvent
& event
) const
130 if ( event
.GetEventType() == wxEVT_BUTTON
)
132 wxPGMultiButton
* buttons
= (wxPGMultiButton
*) propGrid
->GetEditorControlSecondary();
134 if ( event
.GetId() == buttons
->GetButtonId(0) )
136 // Do something when the first button is pressed
137 wxLogDebug("First button pressed");
138 return false; // Return false since value did not change
140 if ( event
.GetId() == buttons
->GetButtonId(1) )
142 // Do something when the second button is pressed
143 wxMessageBox("Second button pressed");
144 return false; // Return false since value did not change
146 if ( event
.GetId() == buttons
->GetButtonId(2) )
148 // Do something when the third button is pressed
149 wxMessageBox("Third button pressed");
150 return false; // Return false since value did not change
153 return wxPGTextCtrlEditor::OnEvent(propGrid
, property
, ctrl
, event
);
156 // -----------------------------------------------------------------------
157 // Validator for wxValidator use sample
158 // -----------------------------------------------------------------------
162 // wxValidator for testing
164 class wxInvalidWordValidator
: public wxValidator
168 wxInvalidWordValidator( const wxString
& invalidWord
)
169 : wxValidator(), m_invalidWord(invalidWord
)
173 virtual wxObject
* Clone() const
175 return new wxInvalidWordValidator(m_invalidWord
);
178 virtual bool Validate(wxWindow
* WXUNUSED(parent
))
180 wxTextCtrl
* tc
= wxDynamicCast(GetWindow(), wxTextCtrl
);
181 wxCHECK_MSG(tc
, true, wxT("validator window must be wxTextCtrl"));
183 wxString val
= tc
->GetValue();
185 if ( val
.find(m_invalidWord
) == wxString::npos
)
188 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord
.c_str()),
189 wxT("Validation Failure"));
195 wxString m_invalidWord
;
198 #endif // wxUSE_VALIDATORS
200 // -----------------------------------------------------------------------
202 // -----------------------------------------------------------------------
204 // See propgridsample.h for wxVector3f class
206 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
208 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
209 wxVector3f
,const wxVector3f
&,TextCtrl
)
212 wxVectorProperty::wxVectorProperty( const wxString
& label
,
213 const wxString
& name
,
214 const wxVector3f
& value
)
215 : wxPGProperty(label
,name
)
217 SetValue( WXVARIANT(value
) );
218 AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
219 AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
220 AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
223 wxVectorProperty::~wxVectorProperty() { }
225 void wxVectorProperty::RefreshChildren()
227 if ( !GetChildCount() ) return;
228 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
229 Item(0)->SetValue( vector
.x
);
230 Item(1)->SetValue( vector
.y
);
231 Item(2)->SetValue( vector
.z
);
234 wxVariant
wxVectorProperty::ChildChanged( wxVariant
& thisValue
,
236 wxVariant
& childValue
) const
240 switch ( childIndex
)
242 case 0: vector
.x
= childValue
.GetDouble(); break;
243 case 1: vector
.y
= childValue
.GetDouble(); break;
244 case 2: vector
.z
= childValue
.GetDouble(); break;
246 wxVariant newVariant
;
247 newVariant
<< vector
;
252 // -----------------------------------------------------------------------
253 // wxTriangleProperty
254 // -----------------------------------------------------------------------
256 // See propgridsample.h for wxTriangle class
258 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
260 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
261 wxTriangle
,const wxTriangle
&,TextCtrl
)
264 wxTriangleProperty::wxTriangleProperty( const wxString
& label
,
265 const wxString
& name
,
266 const wxTriangle
& value
)
267 : wxPGProperty(label
,name
)
269 SetValue( WXVARIANT(value
) );
270 AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
271 AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
272 AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
275 wxTriangleProperty::~wxTriangleProperty() { }
277 void wxTriangleProperty::RefreshChildren()
279 if ( !GetChildCount() ) return;
280 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
281 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
282 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
283 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
286 wxVariant
wxTriangleProperty::ChildChanged( wxVariant
& thisValue
,
288 wxVariant
& childValue
) const
291 triangle
<< thisValue
;
292 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
293 switch ( childIndex
)
295 case 0: triangle
.a
= vector
; break;
296 case 1: triangle
.b
= vector
; break;
297 case 2: triangle
.c
= vector
; break;
299 wxVariant newVariant
;
300 newVariant
<< triangle
;
305 // -----------------------------------------------------------------------
306 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
307 // -----------------------------------------------------------------------
309 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
313 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
314 : wxPGEditorDialogAdapter(), m_choices(choices
)
318 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
319 wxPGProperty
* WXUNUSED(property
) )
321 wxString s
= ::wxGetSingleChoice(wxT("Message"),
323 m_choices
.GetLabels());
334 const wxPGChoices
& m_choices
;
338 class SingleChoiceProperty
: public wxStringProperty
342 SingleChoiceProperty( const wxString
& label
,
343 const wxString
& name
= wxPG_LABEL
,
344 const wxString
& value
= wxEmptyString
)
345 : wxStringProperty(label
, name
, value
)
348 m_choices
.Add(wxT("Cat"));
349 m_choices
.Add(wxT("Dog"));
350 m_choices
.Add(wxT("Gibbon"));
351 m_choices
.Add(wxT("Otter"));
354 // Set editor to have button
355 virtual const wxPGEditor
* DoGetEditorClass() const
357 return wxPGEditor_TextCtrlAndButton
;
360 // Set what happens on button click
361 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
363 return new wxSingleChoiceDialogAdapter(m_choices
);
367 wxPGChoices m_choices
;
370 // -----------------------------------------------------------------------
372 // -----------------------------------------------------------------------
420 ID_SETSPINCTRLEDITOR
,
425 ID_ENABLECOMMONVALUES
,
430 ID_ENABLELABELEDITING
,
436 // -----------------------------------------------------------------------
438 // -----------------------------------------------------------------------
440 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
441 EVT_IDLE(FormMain::OnIdle
)
442 EVT_MOVE(FormMain::OnMove
)
443 EVT_SIZE(FormMain::OnResize
)
445 // This occurs when a property is selected
446 EVT_PG_SELECTED( PGID
, FormMain::OnPropertyGridSelect
)
447 // This occurs when a property value changes
448 EVT_PG_CHANGED( PGID
, FormMain::OnPropertyGridChange
)
449 // This occurs just prior a property value is changed
450 EVT_PG_CHANGING( PGID
, FormMain::OnPropertyGridChanging
)
451 // This occurs when a mouse moves over another property
452 EVT_PG_HIGHLIGHTED( PGID
, FormMain::OnPropertyGridHighlight
)
453 // This occurs when mouse is right-clicked.
454 EVT_PG_RIGHT_CLICK( PGID
, FormMain::OnPropertyGridItemRightClick
)
455 // This occurs when mouse is double-clicked.
456 EVT_PG_DOUBLE_CLICK( PGID
, FormMain::OnPropertyGridItemDoubleClick
)
457 // This occurs when propgridmanager's page changes.
458 EVT_PG_PAGE_CHANGED( PGID
, FormMain::OnPropertyGridPageChange
)
459 // This occurs when user starts editing a property label
460 EVT_PG_LABEL_EDIT_BEGIN( PGID
,
461 FormMain::OnPropertyGridLabelEditBegin
)
462 // This occurs when user stops editing a property label
463 EVT_PG_LABEL_EDIT_ENDING( PGID
,
464 FormMain::OnPropertyGridLabelEditEnding
)
465 // This occurs when property's editor button (if any) is clicked.
466 EVT_BUTTON( PGID
, FormMain::OnPropertyGridButtonClick
)
468 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain::OnPropertyGridItemCollapse
)
469 EVT_PG_ITEM_EXPANDED( PGID
, FormMain::OnPropertyGridItemExpand
)
471 EVT_PG_COL_BEGIN_DRAG( PGID
, FormMain::OnPropertyGridColBeginDrag
)
472 EVT_PG_COL_DRAGGING( PGID
, FormMain::OnPropertyGridColDragging
)
473 EVT_PG_COL_END_DRAG( PGID
, FormMain::OnPropertyGridColEndDrag
)
475 EVT_TEXT( PGID
, FormMain::OnPropertyGridTextUpdate
)
478 // Rest of the events are not property grid specific
479 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent
)
480 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent
)
482 EVT_MENU( ID_APPENDPROP
, FormMain::OnAppendPropClick
)
483 EVT_MENU( ID_APPENDCAT
, FormMain::OnAppendCatClick
)
484 EVT_MENU( ID_INSERTPROP
, FormMain::OnInsertPropClick
)
485 EVT_MENU( ID_INSERTCAT
, FormMain::OnInsertCatClick
)
486 EVT_MENU( ID_DELETE
, FormMain::OnDelPropClick
)
487 EVT_MENU( ID_DELETER
, FormMain::OnDelPropRClick
)
488 EVT_MENU( ID_UNSPECIFY
, FormMain::OnMisc
)
489 EVT_MENU( ID_DELETEALL
, FormMain::OnClearClick
)
490 EVT_MENU( ID_ENABLE
, FormMain::OnEnableDisable
)
491 EVT_MENU( ID_SETREADONLY
, FormMain::OnSetReadOnly
)
492 EVT_MENU( ID_HIDE
, FormMain::OnHide
)
494 EVT_MENU( ID_ITERATE1
, FormMain::OnIterate1Click
)
495 EVT_MENU( ID_ITERATE2
, FormMain::OnIterate2Click
)
496 EVT_MENU( ID_ITERATE3
, FormMain::OnIterate3Click
)
497 EVT_MENU( ID_ITERATE4
, FormMain::OnIterate4Click
)
498 EVT_MENU( ID_ONEXTENDEDKEYNAV
, FormMain::OnExtendedKeyNav
)
499 EVT_MENU( ID_SETBGCOLOUR
, FormMain::OnSetBackgroundColour
)
500 EVT_MENU( ID_SETBGCOLOURRECUR
, FormMain::OnSetBackgroundColour
)
501 EVT_MENU( ID_CLEARMODIF
, FormMain::OnClearModifyStatusClick
)
502 EVT_MENU( ID_FREEZE
, FormMain::OnFreezeClick
)
503 EVT_MENU( ID_ENABLELABELEDITING
, FormMain::OnEnableLabelEditing
)
504 EVT_MENU( ID_SHOWHEADER
, FormMain::OnShowHeader
)
505 EVT_MENU( ID_DUMPLIST
, FormMain::OnDumpList
)
507 EVT_MENU( ID_COLOURSCHEME1
, FormMain::OnColourScheme
)
508 EVT_MENU( ID_COLOURSCHEME2
, FormMain::OnColourScheme
)
509 EVT_MENU( ID_COLOURSCHEME3
, FormMain::OnColourScheme
)
510 EVT_MENU( ID_COLOURSCHEME4
, FormMain::OnColourScheme
)
512 EVT_MENU( ID_ABOUT
, FormMain::OnAbout
)
513 EVT_MENU( ID_QUIT
, FormMain::OnCloseClick
)
515 EVT_MENU( ID_CATCOLOURS
, FormMain::OnCatColours
)
516 EVT_MENU( ID_SETCOLUMNS
, FormMain::OnSetColumns
)
517 EVT_MENU( ID_TESTXRC
, FormMain::OnTestXRC
)
518 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain::OnEnableCommonValues
)
519 EVT_MENU( ID_SELECTSTYLE
, FormMain::OnSelectStyle
)
521 EVT_MENU( ID_STATICLAYOUT
, FormMain::OnMisc
)
522 EVT_MENU( ID_COLLAPSE
, FormMain::OnMisc
)
523 EVT_MENU( ID_COLLAPSEALL
, FormMain::OnMisc
)
525 EVT_MENU( ID_POPULATE1
, FormMain::OnPopulateClick
)
526 EVT_MENU( ID_POPULATE2
, FormMain::OnPopulateClick
)
528 EVT_MENU( ID_GETVALUES
, FormMain::OnMisc
)
529 EVT_MENU( ID_SETVALUES
, FormMain::OnMisc
)
530 EVT_MENU( ID_SETVALUES2
, FormMain::OnMisc
)
532 EVT_MENU( ID_FITCOLUMNS
, FormMain::OnFitColumnsClick
)
534 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain::OnChangeFlagsPropItemsClick
)
536 EVT_MENU( ID_RUNTESTFULL
, FormMain::OnMisc
)
537 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain::OnMisc
)
539 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain::OnInsertChoice
)
540 EVT_MENU( ID_TESTDELETECHOICE
, FormMain::OnDeleteChoice
)
542 EVT_MENU( ID_INSERTPAGE
, FormMain::OnInsertPage
)
543 EVT_MENU( ID_REMOVEPAGE
, FormMain::OnRemovePage
)
545 EVT_MENU( ID_SAVESTATE
, FormMain::OnSaveState
)
546 EVT_MENU( ID_RESTORESTATE
, FormMain::OnRestoreState
)
548 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain::OnSetSpinCtrlEditorClick
)
549 EVT_MENU( ID_TESTREPLACE
, FormMain::OnTestReplaceClick
)
550 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain::OnSetPropertyValue
)
552 EVT_MENU( ID_RUNMINIMAL
, FormMain::OnRunMinimalClick
)
554 EVT_CONTEXT_MENU( FormMain::OnContextMenu
)
557 // -----------------------------------------------------------------------
559 void FormMain::OnMove( wxMoveEvent
& event
)
561 if ( !m_pPropGridManager
)
563 // this check is here so the frame layout can be tested
564 // without creating propertygrid
569 // Update position properties
575 // Must check if properties exist (as they may be deleted).
577 // Using m_pPropGridManager, we can scan all pages automatically.
578 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
580 m_pPropGridManager
->SetPropertyValue( id
, x
);
582 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
584 m_pPropGridManager
->SetPropertyValue( id
, y
);
586 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
588 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxPoint(x
,y
)) );
590 // Should always call event.Skip() in frame's MoveEvent handler
594 // -----------------------------------------------------------------------
596 void FormMain::OnResize( wxSizeEvent
& event
)
598 if ( !m_pPropGridManager
)
600 // this check is here so the frame layout can be tested
601 // without creating propertygrid
606 // Update size properties
613 // Must check if properties exist (as they may be deleted).
615 // Using m_pPropGridManager, we can scan all pages automatically.
616 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
617 if ( p
&& !p
->IsValueUnspecified() )
618 m_pPropGridManager
->SetPropertyValue( p
, w
);
620 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
621 if ( p
&& !p
->IsValueUnspecified() )
622 m_pPropGridManager
->SetPropertyValue( p
, h
);
624 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
626 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxSize(w
,h
)) );
628 // Should always call event.Skip() in frame's SizeEvent handler
632 // -----------------------------------------------------------------------
634 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
636 wxPGProperty
* p
= event
.GetProperty();
638 if ( p
->GetName() == wxT("Font") )
641 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
642 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
643 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
647 wxASSERT(event
.CanVeto());
651 // Since we ask a question, it is better if we omit any validation
652 // failure behaviour.
653 event
.SetValidationFailureBehavior(0);
659 // Note how we use three types of value getting in this method:
660 // A) event.GetPropertyValueAsXXX
661 // B) event.GetPropertValue, and then variant's GetXXX
662 // C) grid's GetPropertyValueAsXXX(id)
664 void FormMain::OnPropertyGridChange( wxPropertyGridEvent
& event
)
666 wxPGProperty
* property
= event
.GetProperty();
668 const wxString
& name
= property
->GetName();
670 // Properties store values internally as wxVariants, but it is preferred
671 // to use the more modern wxAny at the interface level
672 wxAny value
= property
->GetValue();
674 // Don't handle 'unspecified' values
675 if ( value
.IsNull() )
679 // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
680 // macro is used. Unless you want to support this old
681 // compiler in your own code, you can use the more
682 // nicer form value.As<FOO>() instead of
683 // wxANY_AS(value, FOO).
686 // Some settings are disabled outside Windows platform
687 if ( name
== wxT("X") )
688 SetSize( wxANY_AS(value
, int), -1, -1, -1, wxSIZE_USE_EXISTING
);
689 else if ( name
== wxT("Y") )
690 // wxPGVariantToInt is safe long int value getter
691 SetSize ( -1, wxANY_AS(value
, int), -1, -1, wxSIZE_USE_EXISTING
);
692 else if ( name
== wxT("Width") )
693 SetSize ( -1, -1, wxANY_AS(value
, int), -1, wxSIZE_USE_EXISTING
);
694 else if ( name
== wxT("Height") )
695 SetSize ( -1, -1, -1, wxANY_AS(value
, int), wxSIZE_USE_EXISTING
);
696 else if ( name
== wxT("Label") )
698 SetTitle( wxANY_AS(value
, wxString
) );
700 else if ( name
== wxT("Password") )
702 static int pwdMode
= 0;
704 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
710 if ( name
== wxT("Font") )
712 wxFont font
= wxANY_AS(value
, wxFont
);
713 wxASSERT( font
.IsOk() );
715 m_pPropGridManager
->SetFont( font
);
718 if ( name
== wxT("Margin Colour") )
720 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
721 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
723 else if ( name
== wxT("Cell Colour") )
725 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
726 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
728 else if ( name
== wxT("Line Colour") )
730 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
731 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
733 else if ( name
== wxT("Cell Text Colour") )
735 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
736 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
740 // -----------------------------------------------------------------------
742 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
744 wxPGProperty
* property
= event
.GetProperty();
747 m_itemEnable
->Enable( TRUE
);
748 if ( property
->IsEnabled() )
749 m_itemEnable
->SetItemLabel( wxT("Disable") );
751 m_itemEnable
->SetItemLabel( wxT("Enable") );
755 m_itemEnable
->Enable( FALSE
);
759 wxPGProperty
* prop
= event
.GetProperty();
760 wxStatusBar
* sb
= GetStatusBar();
763 wxString
text(wxT("Selected: "));
764 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
765 sb
->SetStatusText ( text
);
770 // -----------------------------------------------------------------------
772 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
775 wxStatusBar
* sb
= GetStatusBar();
776 wxString
text(wxT("Page Changed: "));
777 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
778 sb
->SetStatusText( text
);
782 // -----------------------------------------------------------------------
784 void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent
& event
)
786 wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
787 event
.GetProperty()->GetLabel().c_str());
790 // -----------------------------------------------------------------------
792 void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent
& event
)
794 wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
795 event
.GetProperty()->GetLabel().c_str());
798 // -----------------------------------------------------------------------
800 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
804 // -----------------------------------------------------------------------
806 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
809 wxPGProperty
* prop
= event
.GetProperty();
810 wxStatusBar
* sb
= GetStatusBar();
813 wxString
text(wxT("Right-clicked: "));
814 text
+= prop
->GetLabel();
815 text
+= wxT(", name=");
816 text
+= m_pPropGridManager
->GetPropertyName(prop
);
817 sb
->SetStatusText( text
);
821 sb
->SetStatusText( wxEmptyString
);
826 // -----------------------------------------------------------------------
828 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
831 wxPGProperty
* prop
= event
.GetProperty();
832 wxStatusBar
* sb
= GetStatusBar();
835 wxString
text(wxT("Double-clicked: "));
836 text
+= prop
->GetLabel();
837 text
+= wxT(", name=");
838 text
+= m_pPropGridManager
->GetPropertyName(prop
);
839 sb
->SetStatusText ( text
);
843 sb
->SetStatusText ( wxEmptyString
);
848 // -----------------------------------------------------------------------
850 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent
& )
853 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
854 wxStatusBar
* sb
= GetStatusBar();
857 wxString
text(wxT("Button clicked: "));
858 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
859 text
+= wxT(", name=");
860 text
+= m_pPropGridManager
->GetPropertyName(prop
);
861 sb
->SetStatusText( text
);
865 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
870 // -----------------------------------------------------------------------
872 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
874 wxLogMessage(wxT("Item was Collapsed"));
877 // -----------------------------------------------------------------------
879 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
881 wxLogMessage(wxT("Item was Expanded"));
884 // -----------------------------------------------------------------------
886 void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent
& event
)
888 if ( m_itemVetoDragging
->IsChecked() )
890 wxLogMessage("Splitter %i resize was vetoed", event
.GetColumn());
895 wxLogMessage("Splitter %i resize began", event
.GetColumn());
899 // -----------------------------------------------------------------------
901 void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent
& event
)
904 // For now, let's not spam the log output
905 //wxLogMessage("Splitter %i is being resized", event.GetColumn());
908 // -----------------------------------------------------------------------
910 void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent
& event
)
912 wxLogMessage("Splitter %i resize ended", event
.GetColumn());
915 // -----------------------------------------------------------------------
918 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
923 // -----------------------------------------------------------------------
925 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
927 // Occurs on wxGTK mostly, but not wxMSW.
930 // -----------------------------------------------------------------------
932 void FormMain::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
934 // Uncomment following to allow property label modify in real-time
935 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
936 // if ( !p.IsOk() ) return;
937 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
940 // -----------------------------------------------------------------------
942 static const wxChar
* _fs_windowstyle_labels
[] = {
943 wxT("wxSIMPLE_BORDER"),
944 wxT("wxDOUBLE_BORDER"),
945 wxT("wxSUNKEN_BORDER"),
946 wxT("wxRAISED_BORDER"),
948 wxT("wxTRANSPARENT_WINDOW"),
949 wxT("wxTAB_TRAVERSAL"),
950 wxT("wxWANTS_CHARS"),
951 #if wxNO_FULL_REPAINT_ON_RESIZE
952 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
955 wxT("wxALWAYS_SHOW_SB"),
956 wxT("wxCLIP_CHILDREN"),
957 #if wxFULL_REPAINT_ON_RESIZE
958 wxT("wxFULL_REPAINT_ON_RESIZE"),
960 (const wxChar
*) NULL
// terminator is always needed
963 static const long _fs_windowstyle_values
[] = {
969 wxTRANSPARENT_WINDOW
,
972 #if wxNO_FULL_REPAINT_ON_RESIZE
973 wxNO_FULL_REPAINT_ON_RESIZE
,
978 #if wxFULL_REPAINT_ON_RESIZE
979 wxFULL_REPAINT_ON_RESIZE
983 static const wxChar
* _fs_framestyle_labels
[] = {
988 wxT("wxSTAY_ON_TOP"),
989 wxT("wxSYSTEM_MENU"),
990 wxT("wxRESIZE_BORDER"),
991 wxT("wxFRAME_TOOL_WINDOW"),
992 wxT("wxFRAME_NO_TASKBAR"),
993 wxT("wxFRAME_FLOAT_ON_PARENT"),
994 wxT("wxFRAME_SHAPED"),
998 static const long _fs_framestyle_values
[] = {
1006 wxFRAME_TOOL_WINDOW
,
1008 wxFRAME_FLOAT_ON_PARENT
,
1012 // -----------------------------------------------------------------------
1014 void FormMain::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1016 wxMessageBox(wxT("Sorrt, not yet implemented"));
1019 void FormMain::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1021 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
1023 prop
->EnableCommonValue();
1025 wxMessageBox(wxT("First select a property"));
1028 void FormMain::PopulateWithStandardItems ()
1030 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1031 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1033 // Append is ideal way to add items to wxPropertyGrid.
1034 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1036 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1037 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1038 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1040 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1041 pg
->GetGrid()->GetMarginColour()) );
1043 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1044 pg
->GetGrid()->GetCellBackgroundColour()) );
1045 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1046 pg
->GetGrid()->GetCellTextColour()) );
1047 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1048 pg
->GetGrid()->GetLineColour()) );
1049 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1050 m_combinedFlags
, GetWindowStyle()) );
1052 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1054 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1056 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1057 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1059 // Let's demonstrate 'Units' attribute here
1061 // Note that we use many attribute constants instead of strings here
1062 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1063 // Using constant may reduce binary size.
1065 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1066 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1067 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1068 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1070 // Set value to unspecified so that Hint attribute will be demonstrated
1071 pg
->SetPropertyValueUnspecified("Height");
1072 pg
->SetPropertyAttribute("Height", wxPG_ATTR_HINT
,
1073 "Enter new height for window" );
1075 // Difference between hint and help string is that the hint is shown in
1076 // an empty value cell, while help string is shown either in the
1077 // description text box, as a tool tip, or on the status bar.
1078 pg
->SetPropertyHelpString("Height",
1079 "This property uses attributes \"Units\" and \"Hint\"." );
1081 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1082 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1083 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1084 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1086 pg
->SetPropertyValueUnspecified(wxT("Width"));
1087 pg
->SetPropertyAttribute("Width", wxPG_ATTR_HINT
,
1088 "Enter new width for window" );
1089 pg
->SetPropertyHelpString("Width",
1090 "This property uses attributes \"Units\" and \"Hint\"." );
1092 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1093 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1094 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1096 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1097 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1098 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1100 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. In order to have label disabled as well, ")
1101 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1103 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1104 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1106 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1107 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1108 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1110 // Disable some of them
1111 pg
->DisableProperty( wxT("Operating System") );
1112 pg
->DisableProperty( wxT("User Id") );
1113 pg
->DisableProperty( wxT("User Name") );
1115 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1116 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1117 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1119 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1121 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1122 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1123 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1124 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1127 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1128 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1129 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1130 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1131 wxT("with custom action (dir dialog popup) defined.")
1134 wxArrayDouble arrdbl
;
1141 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1142 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1143 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1144 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1145 wxT("It is an example of a custom list editor property.")
1148 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1149 wxT("Editing properties will have immediate effect on this window, ")
1150 wxT("and vice versa (atleast in most cases, that is).")
1152 pg
->SetPropertyHelpString( wxT("Information"),
1153 wxT("This property is read-only.") );
1155 pg
->SetPropertyReadOnly( wxT("Information"), true );
1158 // Set test information for cells in columns 3 and 4
1159 // (reserve column 2 for displaying units)
1160 wxPropertyGridIterator it
;
1161 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_FOLDER
);
1163 for ( it
= pg
->GetGrid()->GetIterator();
1167 wxPGProperty
* p
= *it
;
1168 if ( p
->IsCategory() )
1171 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1172 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1176 // -----------------------------------------------------------------------
1178 void FormMain::PopulateWithExamples ()
1180 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1181 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1185 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1186 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1189 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1191 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl
);
1192 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1193 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)16384 ); // for reduced binary size.
1194 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1195 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
1196 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1198 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1199 wxT("This is regular wxIntProperty, which editor has been ")
1200 wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
1201 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1202 wxT("needs to be called prior to using it."));
1206 // Add bool property
1207 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1209 // Add bool property with check box
1210 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1211 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1212 wxPG_BOOL_USE_CHECKBOX
,
1215 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1216 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1218 prop
= pg
->Append( new wxFloatProperty("FloatProperty",
1221 prop
->SetAttribute("Min", -100.12);
1223 // A string property that can be edited in a separate editor dialog.
1224 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1225 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1227 // A property that edits a wxArrayString.
1228 wxArrayString example_array
;
1229 example_array
.Add( wxT("String 1"));
1230 example_array
.Add( wxT("String 2"));
1231 example_array
.Add( wxT("String 3"));
1232 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1235 // Test adding same category multiple times ( should not actually create a new one )
1236 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1238 // A file selector property. Note that argument between name
1239 // and initial value is wildcard (format same as in wxFileDialog).
1240 prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1243 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1244 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1245 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1248 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1249 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1253 // An image file property. Arguments are just like for FileProperty, but
1254 // wildcard is missing (it is autogenerated from supported image formats).
1255 // If you really need to override it, create property separately, and call
1256 // its SetWildcard method.
1257 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1260 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1261 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox
);
1262 pg
->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
1263 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1264 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1265 wxT("editor of this property to wxPGEditor_ComboBox)"));
1267 pid
= pg
->Append( new wxColourProperty("ColourPropertyWithAlpha",
1269 wxColour(15, 200, 95, 128)) );
1270 pg
->SetPropertyAttribute("ColourPropertyWithAlpha", "HasAlpha", true);
1271 pg
->SetPropertyHelpString("ColourPropertyWithAlpha",
1272 "Attribute \"HasAlpha\" is set to true for this property.");
1275 // This demonstrates using alternative editor for colour property
1276 // to trigger colour dialog directly from button.
1277 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1280 // wxEnumProperty does not store strings or even list of strings
1281 // ( so that's why they are static in function ).
1282 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1283 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1285 // this value array would be optional if values matched string indexes
1286 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1288 // note that the initial value (the last argument) is the actual value,
1289 // not index or anything like that. Thus, our value selects "Another Item".
1291 // 0 before value is number of items. If it is 0, like in our example,
1292 // number of items is calculated, and this requires that the string pointer
1293 // array is terminated with NULL.
1294 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1295 enum_prop_labels
, enum_prop_values
, 80 ) );
1299 // use basic table from our previous example
1300 // can also set/add wxArrayStrings and wxArrayInts directly.
1301 soc
.Set( enum_prop_labels
, enum_prop_values
);
1304 soc
.Add( wxT("Look, it continues"), 200 );
1305 soc
.Add( wxT("Even More"), 240 );
1306 soc
.Add( wxT("And More"), 280 );
1308 soc
.Add( wxT("True End of the List"), 320 );
1310 // Test custom colours ([] operator of wxPGChoices returns
1311 // references to wxPGChoiceEntry).
1312 soc
[1].SetFgCol(*wxRED
);
1313 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1314 soc
[2].SetFgCol(*wxGREEN
);
1315 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1316 soc
[3].SetFgCol(*wxBLUE
);
1317 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1318 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1320 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1324 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1326 // Here we only display the original 'soc' choices
1327 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1330 // Test Hint attribute in EnumProperty
1331 pg
->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
1333 pg
->SetPropertyHelpString("EnumProperty 3",
1334 "This property uses \"Hint\" attribute.");
1336 // 'soc' plus one exclusive extra choice "4th only"
1337 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1339 pg
->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
1341 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1342 wxT("Should have one extra item when compared to EnumProperty 3"));
1344 // Password property example.
1345 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1346 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1347 pg
->SetPropertyHelpString( wxT("Password"),
1348 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1350 // String editor with dir selector button. Uses wxEmptyString as name, which
1351 // is allowed (naturally, in this case property cannot be accessed by name).
1352 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1353 pg
->SetPropertyAttribute( wxT("DirProperty"),
1354 wxPG_DIR_DIALOG_MESSAGE
,
1355 wxT("This is a custom dir dialog message") );
1357 // Add string property - first arg is label, second name, and third initial value
1358 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1359 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1360 pg
->SetPropertyHelpString( wxT("StringProperty"),
1361 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1363 // Set value after limiting so that it will be applied
1364 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1367 // Demonstrate "AutoComplete" attribute
1368 pg
->Append( new wxStringProperty( "StringProperty AutoComplete",
1371 wxArrayString autoCompleteStrings
;
1372 autoCompleteStrings
.Add("One choice");
1373 autoCompleteStrings
.Add("Another choice");
1374 autoCompleteStrings
.Add("Another choice, yeah");
1375 autoCompleteStrings
.Add("Yet another choice");
1376 autoCompleteStrings
.Add("Yet another choice, bear with me");
1377 pg
->SetPropertyAttribute( "StringProperty AutoComplete",
1379 autoCompleteStrings
);
1381 pg
->SetPropertyHelpString( "StringProperty AutoComplete",
1382 "AutoComplete attribute has been set for this property "
1383 "(try writing something beginning with 'a', 'o' or 'y').");
1385 // Add string property with arbitrarily wide bitmap in front of it. We
1386 // intentionally lower-than-typical row height here so that the ugly
1387 // scaling code wont't be run.
1388 pg
->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
1390 wxT("Test Text")) );
1391 wxBitmap
myTestBitmap(60, 15, 32);
1393 mdc
.SelectObject(myTestBitmap
);
1395 mdc
.SetPen(*wxBLACK
);
1396 mdc
.DrawLine(0, 0, 60, 15);
1397 mdc
.SelectObject(wxNullBitmap
);
1398 pg
->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap
);
1401 // this value array would be optional if values matched string indexes
1402 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1404 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1405 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1408 // Multi choice dialog.
1409 wxArrayString tchoices
;
1410 tchoices
.Add(wxT("Cabbage"));
1411 tchoices
.Add(wxT("Carrot"));
1412 tchoices
.Add(wxT("Onion"));
1413 tchoices
.Add(wxT("Potato"));
1414 tchoices
.Add(wxT("Strawberry"));
1416 wxArrayString tchoicesValues
;
1417 tchoicesValues
.Add(wxT("Carrot"));
1418 tchoicesValues
.Add(wxT("Potato"));
1420 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1422 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1423 tchoices
, tchoicesValues
) );
1424 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1426 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1427 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1430 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1431 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1432 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1433 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1434 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1437 // wxEditEnumProperty
1439 eech
.Add(wxT("Choice 1"));
1440 eech
.Add(wxT("Choice 2"));
1441 eech
.Add(wxT("Choice 3"));
1442 pg
->Append( new wxEditEnumProperty("EditEnumProperty",
1445 "Choice not in the list") );
1447 // Test Hint attribute in EditEnumProperty
1448 pg
->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
1451 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1452 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1456 // wxDateTimeProperty
1457 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1459 #if wxUSE_DATEPICKCTRL
1460 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1461 (long)(wxDP_DROPDOWN
|
1465 pg
->SetPropertyHelpString( wxT("DateProperty"),
1466 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
1467 wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
1473 // Add Triangle properties as both wxTriangleProperty and
1474 // a generic parent property (using wxStringProperty).
1476 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1478 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1479 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1480 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1481 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1483 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1485 pg
->SetPropertyHelpString( wxT("3D Object"),
1486 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1487 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1489 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1490 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1491 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1492 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1494 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1497 // This snippet is a doc sample test
1499 wxPGProperty
* carProp
= pg
->Append(new wxStringProperty(wxT("Car"),
1501 wxT("<composed>")));
1503 pg
->AppendIn(carProp
, new wxStringProperty(wxT("Model"),
1505 wxT("Lamborghini Diablo SV")));
1507 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Engine Size (cc)"),
1511 wxPGProperty
* speedsProp
= pg
->AppendIn(carProp
,
1512 new wxStringProperty(wxT("Speeds"),
1514 wxT("<composed>")));
1516 pg
->AppendIn( speedsProp
, new wxIntProperty(wxT("Max. Speed (mph)"),
1518 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("0-100 mph (sec)"),
1520 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("1/4 mile (sec)"),
1523 // This is how child property can be referred to by name
1524 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1526 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Price ($)"),
1530 pg
->AppendIn(carProp
, new wxBoolProperty(wxT("Convertible"),
1534 // Displayed value of "Car" property is now very close to this:
1535 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
1538 // Test wxSampleMultiButtonEditor
1539 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1540 pg
->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor
);
1542 // Test SingleChoiceProperty
1543 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1547 // Test adding variable height bitmaps in wxPGChoices
1550 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1551 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1552 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1554 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1560 // Test how non-editable composite strings appear
1561 pid
= new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>"));
1562 pg
->SetPropertyReadOnly(pid
);
1565 // For testing purposes, combine two methods of adding children
1568 pid
->AppendChild( new wxStringProperty(wxT("Latest Release"),
1571 pid
->AppendChild( new wxBoolProperty(wxT("Win API"),
1577 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1578 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1579 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1580 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1581 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1582 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1583 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1585 AddTestProperties(pg
);
1588 // -----------------------------------------------------------------------
1590 void FormMain::PopulateWithLibraryConfig ()
1592 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1593 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1595 // Set custom column proportions (here in the sample app we need
1596 // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
1597 // need not to do it in your application).
1598 if ( pgman
->HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
1600 pg
->SetColumnProportion(0, 3);
1601 pg
->SetColumnProportion(1, 1);
1606 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1610 wxFont italicFont
= pgman
->GetGrid()->GetCaptionFont();
1611 italicFont
.SetStyle(wxFONTSTYLE_ITALIC
);
1613 wxString italicFontHelp
= "Font of this property's wxPGCell has "
1614 "been modified. Obtain property's cell "
1615 "with wxPGProperty::"
1616 "GetOrCreateCell(column).";
1618 #define ADD_WX_LIB_CONF_GROUP(A) \
1619 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1620 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
1621 cat->GetCell(0).SetFont(italicFont); \
1622 cat->SetHelpString(italicFontHelp);
1624 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1625 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1626 pg->DisableProperty(wxT(#A));
1628 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1629 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1631 // Both of following lines would set a label for the second column
1632 pg
->SetPropertyCell( pid
, 1, "Is Enabled" );
1633 pid
->SetValue("Is Enabled");
1635 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1636 ADD_WX_LIB_CONF( wxUSE_GUI
)
1638 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1639 #if defined(WXWIN_COMPATIBILITY_2_2)
1640 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1642 #if defined(WXWIN_COMPATIBILITY_2_4)
1643 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1645 #if defined(WXWIN_COMPATIBILITY_2_6)
1646 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1648 #if defined(WXWIN_COMPATIBILITY_2_8)
1649 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1651 #ifdef wxFONT_SIZE_COMPATIBILITY
1652 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1654 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1656 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1657 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1659 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1662 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1663 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1664 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1665 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1666 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1667 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1669 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1670 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1671 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1673 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1674 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1675 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1676 ADD_WX_LIB_CONF( wxUSE_STL
)
1677 ADD_WX_LIB_CONF( wxUSE_LOG
)
1678 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1679 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1680 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1681 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1682 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1683 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1684 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1686 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1687 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1688 ADD_WX_LIB_CONF( wxUSE_FILE
)
1689 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1690 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1691 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1692 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1693 ADD_WX_LIB_CONF( wxUSE_INTL
)
1694 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1695 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1696 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1697 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1698 #ifdef wxUSE_CONFIG_NATIVE
1699 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1701 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1703 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1704 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1705 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1706 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1707 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1708 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1709 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1710 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1711 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1712 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1713 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1714 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1715 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1716 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1717 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1718 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1719 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1720 ADD_WX_LIB_CONF( wxUSE_URL
)
1721 #ifdef wxUSE_URL_NATIVE
1722 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1724 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1726 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1727 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1728 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1730 ADD_WX_LIB_CONF( wxUSE_XRC
)
1732 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1734 ADD_WX_LIB_CONF( wxUSE_XML
)
1736 // Set them to use check box.
1737 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1742 // Handle events of the third page here.
1743 class wxMyPropertyGridPage
: public wxPropertyGridPage
1747 // Return false here to indicate unhandled events should be
1748 // propagated to manager's parent, as normal.
1749 virtual bool IsHandlingAllEvents() const { return false; }
1753 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1755 wxPGProperty
* property
)
1757 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1760 void OnPropertySelect( wxPropertyGridEvent
& event
);
1761 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1762 void OnPropertyChange( wxPropertyGridEvent
& event
);
1763 void OnPageChange( wxPropertyGridEvent
& event
);
1766 DECLARE_EVENT_TABLE()
1770 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1771 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1772 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1773 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1774 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1778 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1780 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1783 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1785 wxPGProperty
* p
= event
.GetProperty();
1786 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1787 p
->GetName().c_str(),
1788 p
->GetDisplayedString().c_str());
1791 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1793 wxPGProperty
* p
= event
.GetProperty();
1794 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1795 p
->GetName().c_str(),
1796 event
.GetValue().GetString().c_str());
1799 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1801 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1805 class wxPGKeyHandler
: public wxEvtHandler
1809 void OnKeyEvent( wxKeyEvent
& event
)
1811 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1815 DECLARE_EVENT_TABLE()
1818 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1819 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1823 // -----------------------------------------------------------------------
1825 void FormMain::InitPanel()
1830 wxWindow
* panel
= new wxPanel(this, wxID_ANY
,
1831 wxPoint(0, 0), wxSize(400, 400),
1836 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1838 m_topSizer
= topSizer
;
1841 void FormMain::FinalizePanel( bool wasCreated
)
1843 // Button for tab traversal testing
1844 m_topSizer
->Add( new wxButton(m_panel
, wxID_ANY
,
1845 wxS("Should be able to move here with Tab")),
1848 m_panel
->SetSizer( m_topSizer
);
1849 m_topSizer
->SetSizeHints( m_panel
);
1851 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1852 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1854 SetSizer( panelSizer
);
1855 panelSizer
->SetSizeHints( this );
1858 FinalizeFramePosition();
1861 void FormMain::PopulateGrid()
1863 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1864 pgman
->AddPage(wxT("Standard Items"));
1866 PopulateWithStandardItems();
1868 pgman
->AddPage(wxT("wxWidgets Library Config"));
1870 PopulateWithLibraryConfig();
1872 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1873 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1875 // Use wxMyPropertyGridPage (see above) to test the
1876 // custom wxPropertyGridPage feature.
1877 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1879 PopulateWithExamples();
1882 void FormMain::CreateGrid( int style
, int extraStyle
)
1885 // This function (re)creates the property grid in our sample
1889 style
= // default style
1890 wxPG_BOLD_MODIFIED
|
1891 wxPG_SPLITTER_AUTO_CENTER
|
1893 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1895 //wxPG_HIDE_CATEGORIES |
1896 //wxPG_LIMITED_EDITING |
1900 if ( extraStyle
== -1 )
1901 // default extra style
1902 extraStyle
= wxPG_EX_MODE_BUTTONS
|
1903 wxPG_EX_MULTIPLE_SELECTION
;
1904 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1905 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1906 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1907 //| wxPG_EX_HELP_AS_TOOLTIPS
1909 bool wasCreated
= m_panel
? false : true;
1914 // This shows how to combine two static choice descriptors
1915 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1916 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1918 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1919 new wxPropertyGridManager(m_panel
,
1920 // Don't change this into wxID_ANY in the sample, or the
1921 // event handling will obviously be broken.
1924 wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
1925 // But calling SetInitialSize in manager changes the code
1926 // order to the grid gets created immediately, before SetExtraStyle
1930 m_propGrid
= pgman
->GetGrid();
1932 pgman
->SetExtraStyle(extraStyle
);
1934 // This is the default validation failure behaviour
1935 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL
|
1936 wxPG_VFB_SHOW_MESSAGEBOX
);
1938 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
1941 // Set somewhat different unspecified value appearance
1943 cell
.SetText("Unspecified");
1944 cell
.SetFgCol(*wxLIGHT_GREY
);
1945 m_propGrid
->SetUnspecifiedValueAppearance(cell
);
1949 // Change some attributes in all properties
1950 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
1951 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
1953 //m_pPropGridManager->SetSplitterLeft(true);
1954 //m_pPropGridManager->SetSplitterPosition(137);
1957 // This would setup event handling without event table entries
1958 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
1959 wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
1960 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
1961 wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
1964 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
1966 FinalizePanel(wasCreated
);
1969 // -----------------------------------------------------------------------
1971 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
1972 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
1973 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
1974 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
1976 SetIcon(wxICON(sample
));
1982 // we need this in order to allow the about menu relocation, since ABOUT is
1983 // not the default id of the about menu
1984 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
1988 // This is here to really test the wxImageFileProperty.
1989 wxInitAllImageHandlers();
1992 // Register all editors (SpinCtrl etc.)
1993 m_pPropGridManager
->RegisterAdditionalEditors();
1995 // Register our sample custom editors
1996 m_pSampleMultiButtonEditor
=
1997 wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
1999 CreateGrid( // style
2000 wxPG_BOLD_MODIFIED
|
2001 wxPG_SPLITTER_AUTO_CENTER
|
2003 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2005 //wxPG_HIDE_CATEGORIES |
2006 //wxPG_LIMITED_EDITING |
2010 wxPG_EX_MODE_BUTTONS
|
2011 wxPG_EX_MULTIPLE_SELECTION
2012 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2013 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2014 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2015 //| wxPG_EX_HELP_AS_TOOLTIPS
2020 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2021 wxMenu
*menuTry
= new wxMenu
;
2022 wxMenu
*menuTools1
= new wxMenu
;
2023 wxMenu
*menuTools2
= new wxMenu
;
2024 wxMenu
*menuHelp
= new wxMenu
;
2026 menuHelp
->Append(ID_ABOUT
, wxT("&About"), wxT("Show about dialog") );
2028 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2029 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2030 menuTools1
->AppendSeparator();
2031 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2032 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2033 menuTools1
->AppendSeparator();
2034 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2035 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2036 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2037 menuTools1
->AppendSeparator();
2038 menuTools1
->Append(ID_SETBGCOLOUR
, wxT("Set Bg Colour") );
2039 menuTools1
->Append(ID_SETBGCOLOURRECUR
, wxT("Set Bg Colour (Recursively)") );
2040 menuTools1
->Append(ID_UNSPECIFY
, "Set Value to Unspecified");
2041 menuTools1
->AppendSeparator();
2042 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2043 wxT("Toggles item's enabled state.") );
2044 m_itemEnable
->Enable( FALSE
);
2045 menuTools1
->Append(ID_HIDE
, "Hide", "Hides a property" );
2046 menuTools1
->Append(ID_SETREADONLY
, "Set as Read-Only",
2047 "Set property as read-only" );
2049 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2050 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2051 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2052 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2053 menuTools2
->AppendSeparator();
2054 menuTools2
->Append(ID_ONEXTENDEDKEYNAV
, "Extend Keyboard Navigation",
2055 "This will set Enter to navigate to next property, "
2056 "and allows arrow keys to navigate even when in "
2058 menuTools2
->AppendSeparator();
2059 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2060 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2061 menuTools2
->AppendSeparator();
2062 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2063 wxT("Disables painting, auto-sorting, etc.") );
2064 menuTools2
->AppendSeparator();
2065 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2066 menuTools2
->AppendSeparator();
2067 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2068 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2069 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).") );
2070 menuTools2
->AppendSeparator();
2071 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2072 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2073 menuTools2
->AppendSeparator();
2074 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2075 wxT("Enable values that are common to all properties, for selected property."));
2076 menuTools2
->AppendSeparator();
2077 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2078 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2079 menuTools2
->AppendSeparator();
2080 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2081 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2082 menuTools2
->AppendSeparator();
2083 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2084 m_itemVetoDragging
=
2085 menuTools2
->AppendCheckItem(ID_VETOCOLDRAG
,
2086 "Veto Column Dragging");
2087 menuTools2
->AppendSeparator();
2088 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2089 menuTools2
->AppendSeparator();
2090 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2091 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2092 menuTools2
->AppendSeparator();
2093 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2094 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2096 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2097 wxT("Select window style flags used by the grid."));
2098 menuTry
->Append(ID_ENABLELABELEDITING
, "Enable label editing",
2099 "This calls wxPropertyGrid::MakeColumnEditable(0)");
2100 menuTry
->AppendCheckItem(ID_SHOWHEADER
,
2102 "This calls wxPropertyGridManager::ShowHeader()");
2103 menuTry
->AppendSeparator();
2104 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2105 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2106 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2107 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2108 menuTry
->AppendSeparator();
2109 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2110 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2111 menuTry
->AppendSeparator();
2112 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2113 wxT("Switches between user-modifiedable and static layouts.") );
2114 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2115 menuTry
->AppendSeparator();
2116 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2117 menuTry
->AppendSeparator();
2118 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2119 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2121 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2122 menuFile
->AppendSeparator();
2123 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2125 // Now append the freshly created menu to the menu bar...
2126 wxMenuBar
*menuBar
= new wxMenuBar();
2127 menuBar
->Append(menuFile
, wxT("&File") );
2128 menuBar
->Append(menuTry
, wxT("&Try These!") );
2129 menuBar
->Append(menuTools1
, wxT("&Basic") );
2130 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2131 menuBar
->Append(menuHelp
, wxT("&Help") );
2133 // ... and attach this menu bar to the frame
2134 SetMenuBar(menuBar
);
2137 // create a status bar
2139 SetStatusText(wxEmptyString
);
2140 #endif // wxUSE_STATUSBAR
2142 FinalizeFramePosition();
2145 // Create log window
2146 m_logWindow
= new wxLogWindow(this, "Log Messages", false);
2147 m_logWindow
->GetFrame()->Move(GetPosition().x
+ GetSize().x
+ 10,
2149 m_logWindow
->Show();
2153 void FormMain::FinalizeFramePosition()
2155 wxSize
frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2156 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8);
2158 if ( frameSize
.x
> 500 )
2167 // Normally, wxPropertyGrid does not check whether item with identical
2168 // label already exists. However, since in this sample we use labels for
2169 // identifying properties, we have to be sure not to generate identical
2172 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2177 if ( pg
->GetPropertyByLabel( baselabel
) )
2182 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2183 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2189 baselabel
= newlabel
;
2193 // -----------------------------------------------------------------------
2195 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2199 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2201 wxMessageBox(wxT("No items to relate - first add some with Append."));
2205 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2208 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2211 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2213 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2215 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2216 id
->GetIndexInParent(),
2217 new wxStringProperty(propLabel
) );
2221 // -----------------------------------------------------------------------
2223 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2227 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2229 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2231 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2233 m_pPropGridManager
->Refresh();
2236 // -----------------------------------------------------------------------
2238 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2240 m_pPropGridManager
->GetGrid()->Clear();
2243 // -----------------------------------------------------------------------
2245 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2249 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2251 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2253 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2255 m_pPropGridManager
->Refresh();
2259 // -----------------------------------------------------------------------
2261 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2265 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2267 wxMessageBox(wxT("No items to relate - first add some with Append."));
2271 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2274 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2278 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2280 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2282 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2283 id
->GetIndexInParent(),
2284 new wxPropertyCategory (propLabel
) );
2287 // -----------------------------------------------------------------------
2289 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2291 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2294 wxMessageBox(wxT("First select a property."));
2298 m_pPropGridManager
->DeleteProperty( id
);
2301 // -----------------------------------------------------------------------
2303 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2305 // Delete random property
2306 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2310 if ( !p
->IsCategory() )
2312 m_pPropGridManager
->DeleteProperty( p
);
2316 if ( !p
->GetChildCount() )
2319 int n
= rand() % ((int)p
->GetChildCount());
2325 // -----------------------------------------------------------------------
2327 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2329 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2330 event
.GetPosition().x
,event
.GetPosition().y
);
2337 // -----------------------------------------------------------------------
2339 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2341 /*#ifdef __WXDEBUG__
2342 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2343 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2349 // -----------------------------------------------------------------------
2351 int IterateMessage( wxPGProperty
* prop
)
2355 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2356 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2358 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2361 // -----------------------------------------------------------------------
2363 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2365 wxPropertyGridIterator it
;
2367 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2372 wxPGProperty
* p
= *it
;
2373 int res
= IterateMessage( p
);
2374 if ( res
== wxCANCEL
) break;
2378 // -----------------------------------------------------------------------
2380 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2382 wxPropertyGridIterator it
;
2384 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2385 GetIterator( wxPG_ITERATE_VISIBLE
);
2389 wxPGProperty
* p
= *it
;
2391 int res
= IterateMessage( p
);
2392 if ( res
== wxCANCEL
) break;
2396 // -----------------------------------------------------------------------
2398 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2400 // iterate over items in reverse order
2401 wxPropertyGridIterator it
;
2403 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2404 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2408 wxPGProperty
* p
= *it
;
2410 int res
= IterateMessage( p
);
2411 if ( res
== wxCANCEL
) break;
2415 // -----------------------------------------------------------------------
2417 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2419 wxPropertyGridIterator it
;
2421 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2422 GetIterator( wxPG_ITERATE_CATEGORIES
);
2426 wxPGProperty
* p
= *it
;
2428 int res
= IterateMessage( p
);
2429 if ( res
== wxCANCEL
) break;
2433 // -----------------------------------------------------------------------
2435 void FormMain::OnExtendedKeyNav( wxCommandEvent
& WXUNUSED(event
) )
2437 // Use AddActionTrigger() and DedicateKey() to set up Enter,
2438 // Up, and Down keys for navigating between properties.
2439 wxPropertyGrid
* propGrid
= m_pPropGridManager
->GetGrid();
2441 propGrid
->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY
,
2443 propGrid
->DedicateKey(WXK_RETURN
);
2445 // Up and Down keys are alredy associated with navigation,
2446 // but we must also prevent them from being eaten by
2448 propGrid
->DedicateKey(WXK_UP
);
2449 propGrid
->DedicateKey(WXK_DOWN
);
2452 // -----------------------------------------------------------------------
2454 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2456 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2458 // Remove auto-centering
2459 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2461 // Grow manager size just prior fit - otherwise
2462 // column information may be lost.
2463 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2464 wxSize oldFullSize
= GetSize();
2465 SetSize(1000, oldFullSize
.y
);
2467 wxSize newSz
= page
->FitColumns();
2469 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2470 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2478 // -----------------------------------------------------------------------
2480 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2482 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2484 wxPGChoices newChoices
;
2486 newChoices
.Add(wxT("Fast"),0x1);
2487 newChoices
.Add(wxT("Powerful"),0x2);
2488 newChoices
.Add(wxT("Safe"),0x4);
2489 newChoices
.Add(wxT("Sleek"),0x8);
2491 p
->SetChoices(newChoices
);
2494 // -----------------------------------------------------------------------
2496 void FormMain::OnEnableDisable( wxCommandEvent
& )
2498 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2501 wxMessageBox(wxT("First select a property."));
2505 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2507 m_pPropGridManager
->DisableProperty ( id
);
2508 m_itemEnable
->SetItemLabel( wxT("Enable") );
2512 m_pPropGridManager
->EnableProperty ( id
);
2513 m_itemEnable
->SetItemLabel( wxT("Disable") );
2517 // -----------------------------------------------------------------------
2519 void FormMain::OnSetReadOnly( wxCommandEvent
& WXUNUSED(event
) )
2521 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetSelection();
2524 wxMessageBox(wxT("First select a property."));
2527 m_pPropGridManager
->SetPropertyReadOnly(p
);
2530 // -----------------------------------------------------------------------
2532 void FormMain::OnHide( wxCommandEvent
& WXUNUSED(event
) )
2534 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2537 wxMessageBox(wxT("First select a property."));
2541 m_pPropGridManager
->HideProperty( id
, true );
2544 // -----------------------------------------------------------------------
2546 #include "wx/colordlg.h"
2549 FormMain::OnSetBackgroundColour( wxCommandEvent
& event
)
2551 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2552 wxPGProperty
* prop
= pg
->GetSelection();
2555 wxMessageBox(wxT("First select a property."));
2559 wxColour col
= ::wxGetColourFromUser(this, *wxWHITE
, "Choose colour");
2563 bool recursively
= (event
.GetId()==ID_SETBGCOLOURRECUR
) ? true : false;
2564 pg
->SetPropertyBackgroundColour(prop
, col
, recursively
);
2568 // -----------------------------------------------------------------------
2570 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2572 m_pPropGridManager
->AddPage(wxT("New Page"));
2575 // -----------------------------------------------------------------------
2577 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2579 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2582 // -----------------------------------------------------------------------
2584 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2586 m_savedState
= m_pPropGridManager
->SaveEditableState();
2587 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2590 // -----------------------------------------------------------------------
2592 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2594 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2597 // -----------------------------------------------------------------------
2599 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2602 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2604 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPGEditor_SpinCtrl
);
2606 wxMessageBox(wxT("First select a property"));
2610 // -----------------------------------------------------------------------
2612 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2614 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2617 wxPGChoices choices
;
2618 choices
.Add(wxT("Flag 0"),0x0001);
2619 choices
.Add(wxT("Flag 1"),0x0002);
2620 choices
.Add(wxT("Flag 2"),0x0004);
2621 choices
.Add(wxT("Flag 3"),0x0008);
2622 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2623 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2624 m_pPropGridManager
->SetPropertyAttribute( newId
,
2625 wxPG_BOOL_USE_CHECKBOX
,
2630 wxMessageBox(wxT("First select a property"));
2633 // -----------------------------------------------------------------------
2635 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2637 m_pPropGridManager
->ClearModifiedStatus();
2640 // -----------------------------------------------------------------------
2642 // Freeze check-box checked?
2643 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2645 if ( !m_pPropGridManager
) return;
2647 if ( event
.IsChecked() )
2649 if ( !m_pPropGridManager
->IsFrozen() )
2651 m_pPropGridManager
->Freeze();
2656 if ( m_pPropGridManager
->IsFrozen() )
2658 m_pPropGridManager
->Thaw();
2659 m_pPropGridManager
->Refresh();
2664 // -----------------------------------------------------------------------
2666 void FormMain::OnEnableLabelEditing( wxCommandEvent
& WXUNUSED(event
) )
2668 m_propGrid
->MakeColumnEditable(0);
2671 // -----------------------------------------------------------------------
2673 void FormMain::OnShowHeader( wxCommandEvent
& event
)
2675 m_pPropGridManager
->ShowHeader(event
.IsChecked());
2676 m_pPropGridManager
->SetColumnTitle(2, _("Units"));
2679 // -----------------------------------------------------------------------
2681 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2684 msg
.Printf( wxT("wxPropertyGrid Sample")
2686 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2700 wxT("Programmed by %s\n\n")
2701 wxT("Using %s\n\n"),
2702 wxT("Jaakko Salli"), wxVERSION_STRING
2705 wxMessageBox(msg
, wxT("About"), wxOK
| wxICON_INFORMATION
, this);
2708 // -----------------------------------------------------------------------
2710 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2712 int id
= event
.GetId();
2713 if ( id
== ID_COLOURSCHEME1
)
2715 m_pPropGridManager
->GetGrid()->ResetColours();
2717 else if ( id
== ID_COLOURSCHEME2
)
2720 wxColour
my_grey_1(212,208,200);
2721 wxColour
my_grey_3(113,111,100);
2722 m_pPropGridManager
->Freeze();
2723 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2724 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2725 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2726 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2727 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2728 m_pPropGridManager
->Thaw();
2730 else if ( id
== ID_COLOURSCHEME3
)
2733 wxColour
my_grey_1(212,208,200);
2734 wxColour
my_grey_2(236,233,216);
2735 m_pPropGridManager
->Freeze();
2736 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2737 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2738 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2739 m_pPropGridManager
->Thaw();
2741 else if ( id
== ID_COLOURSCHEME4
)
2745 wxColour
my_grey_1(212,208,200);
2746 wxColour
my_grey_2(241,239,226);
2747 wxColour
my_grey_3(113,111,100);
2748 m_pPropGridManager
->Freeze();
2749 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2750 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2751 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2752 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2753 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2754 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2755 m_pPropGridManager
->Thaw();
2759 // -----------------------------------------------------------------------
2761 void FormMain::OnCatColours( wxCommandEvent
& event
)
2763 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2764 m_pPropGridManager
->Freeze();
2766 if ( event
.IsChecked() )
2768 // Set custom colours.
2769 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2770 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2771 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2772 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2773 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2774 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2775 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2776 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2777 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2778 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2779 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2783 // Revert to original.
2784 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2785 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2786 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2787 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2789 m_pPropGridManager
->Thaw();
2790 m_pPropGridManager
->Refresh();
2793 // -----------------------------------------------------------------------
2795 #define ADD_FLAG(FLAG) \
2796 chs.Add(wxT(#FLAG)); \
2798 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2801 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2810 unsigned int ind
= 0;
2811 int flags
= m_pPropGridManager
->GetWindowStyle();
2812 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2813 ADD_FLAG(wxPG_AUTO_SORT
)
2814 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2815 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2816 ADD_FLAG(wxPG_TOOLTIPS
)
2817 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2818 ADD_FLAG(wxPG_HIDE_MARGIN
)
2819 ADD_FLAG(wxPG_LIMITED_EDITING
)
2820 ADD_FLAG(wxPG_TOOLBAR
)
2821 ADD_FLAG(wxPG_DESCRIPTION
)
2822 ADD_FLAG(wxPG_NO_INTERNAL_BORDER
)
2823 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2824 wxT("wxPropertyGrid Window Style"), chs
);
2825 dlg
.SetSelections(sel
);
2826 if ( dlg
.ShowModal() == wxID_CANCEL
)
2830 sel
= dlg
.GetSelections();
2831 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2832 flags
|= vls
[sel
[ind
]];
2841 unsigned int ind
= 0;
2842 int flags
= m_pPropGridManager
->GetExtraStyle();
2843 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2844 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2845 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2846 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2847 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2848 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2849 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2850 ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS
)
2851 ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION
)
2852 ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING
)
2853 ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER
)
2854 ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR
)
2855 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2856 wxT("wxPropertyGrid Extra Style"), chs
);
2857 dlg
.SetSelections(sel
);
2858 if ( dlg
.ShowModal() == wxID_CANCEL
)
2862 sel
= dlg
.GetSelections();
2863 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2864 flags
|= vls
[sel
[ind
]];
2869 CreateGrid( style
, extraStyle
);
2871 FinalizeFramePosition();
2874 // -----------------------------------------------------------------------
2876 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2878 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2879 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2882 if ( colCount
>= 2 )
2884 m_pPropGridManager
->SetColumnCount(colCount
);
2888 // -----------------------------------------------------------------------
2890 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2892 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2893 wxPGProperty
* selected
= pg
->GetSelection();
2897 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2898 pg
->SetPropertyValue( selected
, value
);
2902 // -----------------------------------------------------------------------
2904 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2906 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2908 wxPGProperty
* selected
= pg
->GetSelection();
2909 const wxPGChoices
& choices
= selected
->GetChoices();
2911 // Insert new choice to the center of list
2913 if ( choices
.IsOk() )
2915 int pos
= choices
.GetCount() / 2;
2916 selected
->InsertChoice(wxT("New Choice"), pos
);
2920 ::wxMessageBox(wxT("First select a property with some choices."));
2924 // -----------------------------------------------------------------------
2926 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2928 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2930 wxPGProperty
* selected
= pg
->GetSelection();
2931 const wxPGChoices
& choices
= selected
->GetChoices();
2933 // Deletes choice from the center of list
2935 if ( choices
.IsOk() )
2937 int pos
= choices
.GetCount() / 2;
2938 selected
->DeleteChoice(pos
);
2942 ::wxMessageBox(wxT("First select a property with some choices."));
2946 // -----------------------------------------------------------------------
2948 #include <wx/colordlg.h>
2950 void FormMain::OnMisc ( wxCommandEvent
& event
)
2952 int id
= event
.GetId();
2953 if ( id
== ID_STATICLAYOUT
)
2955 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2956 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2957 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2959 else if ( id
== ID_COLLAPSEALL
)
2962 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2964 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2965 it
.GetProperty()->SetExpanded( false );
2969 else if ( id
== ID_GETVALUES
)
2971 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2972 m_pPropGridManager
->GetGrid()->GetRoot(),
2973 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2975 else if ( id
== ID_SETVALUES
)
2977 if ( m_storedValues
.GetType() == wxT("list") )
2979 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2982 wxMessageBox(wxT("First use Get Property Values."));
2984 else if ( id
== ID_SETVALUES2
)
2988 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2989 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2990 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2991 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2993 else if ( id
== ID_COLLAPSE
)
2995 // Collapses selected.
2996 wxPGProperty
* id
= m_pPropGridManager
->GetSelection();
2999 m_pPropGridManager
->Collapse(id
);
3002 else if ( id
== ID_RUNTESTFULL
)
3004 // Runs a regression test.
3007 else if ( id
== ID_RUNTESTPARTIAL
)
3009 // Runs a regression test.
3012 else if ( id
== ID_UNSPECIFY
)
3014 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
3017 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3018 prop
->RefreshEditor();
3023 // -----------------------------------------------------------------------
3025 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3027 int id
= event
.GetId();
3028 m_propGrid
->Clear();
3029 m_propGrid
->Freeze();
3030 if ( id
== ID_POPULATE1
)
3032 PopulateWithStandardItems();
3034 else if ( id
== ID_POPULATE2
)
3036 PopulateWithLibraryConfig();
3041 // -----------------------------------------------------------------------
3043 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3045 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3047 DisplayMinimalFrame(this);
3050 // -----------------------------------------------------------------------
3052 FormMain::~FormMain()
3056 // -----------------------------------------------------------------------
3058 IMPLEMENT_APP(cxApplication
)
3060 bool cxApplication::OnInit()
3063 //Locale.Init(wxLANGUAGE_FINNISH);
3065 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3069 // Parse command-line
3070 wxApp
& app
= wxGetApp();
3073 wxString s
= app
.argv
[1];
3074 if ( s
== wxT("--run-tests") )
3078 bool testResult
= frame
->RunTests(true);
3088 // -----------------------------------------------------------------------
3090 void FormMain::OnIdle( wxIdleEvent
& event
)
3093 // This code is useful for debugging focus problems
3094 static wxWindow* last_focus = (wxWindow*) NULL;
3096 wxWindow* cur_focus = ::wxWindow::FindFocus();
3098 if ( cur_focus != last_focus )
3100 const wxChar* class_name = wxT("<none>");
3102 class_name = cur_focus->GetClassInfo()->GetClassName();
3103 last_focus = cur_focus;
3104 wxLogDebug( wxT("FOCUSED: %s %X"),
3106 (unsigned int)cur_focus);
3113 // -----------------------------------------------------------------------