1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 // * Examples of custom property classes are in sampleprops.cpp.
18 // * Additional ones can be found below.
20 // * Currently there is no example of a custom property editor. However,
21 // SpinCtrl editor sample is well-commented. It can be found in
22 // src/propgrid/advprops.cpp.
24 // * To find code that populates the grid with properties, search for
25 // string "::Populate".
27 // * To find code that handles property grid changes, search for string
28 // "::OnPropertyGridChange".
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include "wx/wxprec.h"
38 // for all others, include the necessary headers (this file is usually all you
39 // need because it includes almost all "standard" wxWidgets headers)
45 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
48 #include <wx/numdlg.h>
50 // -----------------------------------------------------------------------
53 // Main propertygrid header.
54 #include <wx/propgrid/propgrid.h>
56 // Extra property classes.
57 #include <wx/propgrid/advprops.h>
59 // This defines wxPropertyGridManager.
60 #include <wx/propgrid/manager.h>
63 #include "sampleprops.h"
65 #if wxUSE_DATEPICKCTRL
66 #include <wx/datectrl.h>
69 #include <wx/artprov.h>
72 #include "../sample.xpm"
75 // -----------------------------------------------------------------------
76 // wxSampleMultiButtonEditor
77 // A sample editor class that has multiple buttons.
78 // -----------------------------------------------------------------------
80 class wxSampleMultiButtonEditor
: public wxPGTextCtrlEditor
82 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor
)
84 wxSampleMultiButtonEditor() {}
85 virtual ~wxSampleMultiButtonEditor() {}
87 virtual wxPGWindowList
CreateControls( wxPropertyGrid
* propGrid
,
88 wxPGProperty
* property
,
90 const wxSize
& sz
) const;
91 virtual bool OnEvent( wxPropertyGrid
* propGrid
,
92 wxPGProperty
* property
,
94 wxEvent
& event
) const;
97 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor
, wxPGTextCtrlEditor
)
99 wxPGWindowList
wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
100 wxPGProperty
* property
,
102 const wxSize
& sz
) const
104 // Create and populate buttons-subwindow
105 wxPGMultiButton
* buttons
= new wxPGMultiButton( propGrid
, sz
);
107 // Add two regular buttons
108 buttons
->Add( "..." );
110 // Add a bitmap button
111 buttons
->Add( wxArtProvider::GetBitmap(wxART_FOLDER
) );
113 // Create the 'primary' editor control (textctrl in this case)
114 wxPGWindowList wndList
= wxPGTextCtrlEditor::CreateControls
115 ( propGrid
, property
, pos
,
116 buttons
->GetPrimarySize() );
118 // Finally, move buttons-subwindow to correct position and make sure
119 // returned wxPGWindowList contains our custom button list.
120 buttons
->Finalize(propGrid
, pos
);
122 wndList
.SetSecondary( buttons
);
126 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid
* propGrid
,
127 wxPGProperty
* property
,
129 wxEvent
& event
) const
131 if ( event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
133 wxPGMultiButton
* buttons
= (wxPGMultiButton
*) propGrid
->GetEditorControlSecondary();
135 if ( event
.GetId() == buttons
->GetButtonId(0) )
137 // Do something when the first button is pressed
138 wxLogDebug("First button pressed");
139 return false; // Return false since value did not change
141 if ( event
.GetId() == buttons
->GetButtonId(1) )
143 // Do something when the second button is pressed
144 wxMessageBox("Second button pressed");
145 return false; // Return false since value did not change
147 if ( event
.GetId() == buttons
->GetButtonId(2) )
149 // Do something when the third button is pressed
150 wxMessageBox("Third button pressed");
151 return false; // Return false since value did not change
154 return wxPGTextCtrlEditor::OnEvent(propGrid
, property
, ctrl
, event
);
157 // -----------------------------------------------------------------------
158 // Validator for wxValidator use sample
159 // -----------------------------------------------------------------------
163 // wxValidator for testing
165 class wxInvalidWordValidator
: public wxValidator
169 wxInvalidWordValidator( const wxString
& invalidWord
)
170 : wxValidator(), m_invalidWord(invalidWord
)
174 virtual wxObject
* Clone() const
176 return new wxInvalidWordValidator(m_invalidWord
);
179 virtual bool Validate(wxWindow
* WXUNUSED(parent
))
181 wxTextCtrl
* tc
= wxDynamicCast(GetWindow(), wxTextCtrl
);
182 wxCHECK_MSG(tc
, true, wxT("validator window must be wxTextCtrl"));
184 wxString val
= tc
->GetValue();
186 if ( val
.find(m_invalidWord
) == wxString::npos
)
189 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord
.c_str()),
190 wxT("Validation Failure"));
196 wxString m_invalidWord
;
199 #endif // wxUSE_VALIDATORS
201 // -----------------------------------------------------------------------
203 // -----------------------------------------------------------------------
205 // See propgridsample.h for wxVector3f class
207 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
209 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
210 wxVector3f
,const wxVector3f
&,TextCtrl
)
213 wxVectorProperty::wxVectorProperty( const wxString
& label
,
214 const wxString
& name
,
215 const wxVector3f
& value
)
216 : wxPGProperty(label
,name
)
218 SetValue( WXVARIANT(value
) );
219 AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
220 AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
221 AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
224 wxVectorProperty::~wxVectorProperty() { }
226 void wxVectorProperty::RefreshChildren()
228 if ( !GetChildCount() ) return;
229 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
230 Item(0)->SetValue( vector
.x
);
231 Item(1)->SetValue( vector
.y
);
232 Item(2)->SetValue( vector
.z
);
235 wxVariant
wxVectorProperty::ChildChanged( wxVariant
& thisValue
,
237 wxVariant
& childValue
) const
241 switch ( childIndex
)
243 case 0: vector
.x
= childValue
.GetDouble(); break;
244 case 1: vector
.y
= childValue
.GetDouble(); break;
245 case 2: vector
.z
= childValue
.GetDouble(); break;
247 wxVariant newVariant
;
248 newVariant
<< vector
;
253 // -----------------------------------------------------------------------
254 // wxTriangleProperty
255 // -----------------------------------------------------------------------
257 // See propgridsample.h for wxTriangle class
259 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
261 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
262 wxTriangle
,const wxTriangle
&,TextCtrl
)
265 wxTriangleProperty::wxTriangleProperty( const wxString
& label
,
266 const wxString
& name
,
267 const wxTriangle
& value
)
268 : wxPGProperty(label
,name
)
270 SetValue( WXVARIANT(value
) );
271 AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
272 AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
273 AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
276 wxTriangleProperty::~wxTriangleProperty() { }
278 void wxTriangleProperty::RefreshChildren()
280 if ( !GetChildCount() ) return;
281 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
282 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
283 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
284 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
287 wxVariant
wxTriangleProperty::ChildChanged( wxVariant
& thisValue
,
289 wxVariant
& childValue
) const
292 triangle
<< thisValue
;
293 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
294 switch ( childIndex
)
296 case 0: triangle
.a
= vector
; break;
297 case 1: triangle
.b
= vector
; break;
298 case 2: triangle
.c
= vector
; break;
300 wxVariant newVariant
;
301 newVariant
<< triangle
;
306 // -----------------------------------------------------------------------
307 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
308 // -----------------------------------------------------------------------
310 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
314 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
315 : wxPGEditorDialogAdapter(), m_choices(choices
)
319 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
320 wxPGProperty
* WXUNUSED(property
) )
322 wxString s
= ::wxGetSingleChoice(wxT("Message"),
324 m_choices
.GetLabels());
335 const wxPGChoices
& m_choices
;
339 class SingleChoiceProperty
: public wxStringProperty
343 SingleChoiceProperty( const wxString
& label
,
344 const wxString
& name
= wxPG_LABEL
,
345 const wxString
& value
= wxEmptyString
)
346 : wxStringProperty(label
, name
, value
)
349 m_choices
.Add(wxT("Cat"));
350 m_choices
.Add(wxT("Dog"));
351 m_choices
.Add(wxT("Gibbon"));
352 m_choices
.Add(wxT("Otter"));
355 // Set editor to have button
356 virtual const wxPGEditor
* DoGetEditorClass() const
358 return wxPGEditor_TextCtrlAndButton
;
361 // Set what happens on button click
362 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
364 return new wxSingleChoiceDialogAdapter(m_choices
);
368 wxPGChoices m_choices
;
371 // -----------------------------------------------------------------------
373 // -----------------------------------------------------------------------
421 ID_SETSPINCTRLEDITOR
,
426 ID_ENABLECOMMONVALUES
,
431 ID_ENABLELABELEDITING
,
437 // -----------------------------------------------------------------------
439 // -----------------------------------------------------------------------
441 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
442 EVT_IDLE(FormMain::OnIdle
)
443 EVT_MOVE(FormMain::OnMove
)
444 EVT_SIZE(FormMain::OnResize
)
446 // This occurs when a property is selected
447 EVT_PG_SELECTED( PGID
, FormMain::OnPropertyGridSelect
)
448 // This occurs when a property value changes
449 EVT_PG_CHANGED( PGID
, FormMain::OnPropertyGridChange
)
450 // This occurs just prior a property value is changed
451 EVT_PG_CHANGING( PGID
, FormMain::OnPropertyGridChanging
)
452 // This occurs when a mouse moves over another property
453 EVT_PG_HIGHLIGHTED( PGID
, FormMain::OnPropertyGridHighlight
)
454 // This occurs when mouse is right-clicked.
455 EVT_PG_RIGHT_CLICK( PGID
, FormMain::OnPropertyGridItemRightClick
)
456 // This occurs when mouse is double-clicked.
457 EVT_PG_DOUBLE_CLICK( PGID
, FormMain::OnPropertyGridItemDoubleClick
)
458 // This occurs when propgridmanager's page changes.
459 EVT_PG_PAGE_CHANGED( PGID
, FormMain::OnPropertyGridPageChange
)
460 // This occurs when user starts editing a property label
461 EVT_PG_LABEL_EDIT_BEGIN( PGID
,
462 FormMain::OnPropertyGridLabelEditBegin
)
463 // This occurs when user stops editing a property label
464 EVT_PG_LABEL_EDIT_ENDING( PGID
,
465 FormMain::OnPropertyGridLabelEditEnding
)
466 // This occurs when property's editor button (if any) is clicked.
467 EVT_BUTTON( PGID
, FormMain::OnPropertyGridButtonClick
)
469 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain::OnPropertyGridItemCollapse
)
470 EVT_PG_ITEM_EXPANDED( PGID
, FormMain::OnPropertyGridItemExpand
)
472 EVT_PG_COL_BEGIN_DRAG( PGID
, FormMain::OnPropertyGridColBeginDrag
)
473 EVT_PG_COL_DRAGGING( PGID
, FormMain::OnPropertyGridColDragging
)
474 EVT_PG_COL_END_DRAG( PGID
, FormMain::OnPropertyGridColEndDrag
)
476 EVT_TEXT( PGID
, FormMain::OnPropertyGridTextUpdate
)
479 // Rest of the events are not property grid specific
480 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent
)
481 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent
)
483 EVT_MENU( ID_APPENDPROP
, FormMain::OnAppendPropClick
)
484 EVT_MENU( ID_APPENDCAT
, FormMain::OnAppendCatClick
)
485 EVT_MENU( ID_INSERTPROP
, FormMain::OnInsertPropClick
)
486 EVT_MENU( ID_INSERTCAT
, FormMain::OnInsertCatClick
)
487 EVT_MENU( ID_DELETE
, FormMain::OnDelPropClick
)
488 EVT_MENU( ID_DELETER
, FormMain::OnDelPropRClick
)
489 EVT_MENU( ID_UNSPECIFY
, FormMain::OnMisc
)
490 EVT_MENU( ID_DELETEALL
, FormMain::OnClearClick
)
491 EVT_MENU( ID_ENABLE
, FormMain::OnEnableDisable
)
492 EVT_MENU( ID_SETREADONLY
, FormMain::OnSetReadOnly
)
493 EVT_MENU( ID_HIDE
, FormMain::OnHide
)
495 EVT_MENU( ID_ITERATE1
, FormMain::OnIterate1Click
)
496 EVT_MENU( ID_ITERATE2
, FormMain::OnIterate2Click
)
497 EVT_MENU( ID_ITERATE3
, FormMain::OnIterate3Click
)
498 EVT_MENU( ID_ITERATE4
, FormMain::OnIterate4Click
)
499 EVT_MENU( ID_ONEXTENDEDKEYNAV
, FormMain::OnExtendedKeyNav
)
500 EVT_MENU( ID_SETBGCOLOUR
, FormMain::OnSetBackgroundColour
)
501 EVT_MENU( ID_SETBGCOLOURRECUR
, FormMain::OnSetBackgroundColour
)
502 EVT_MENU( ID_CLEARMODIF
, FormMain::OnClearModifyStatusClick
)
503 EVT_MENU( ID_FREEZE
, FormMain::OnFreezeClick
)
504 EVT_MENU( ID_ENABLELABELEDITING
, FormMain::OnEnableLabelEditing
)
505 EVT_MENU( ID_SHOWHEADER
, FormMain::OnShowHeader
)
506 EVT_MENU( ID_DUMPLIST
, FormMain::OnDumpList
)
508 EVT_MENU( ID_COLOURSCHEME1
, FormMain::OnColourScheme
)
509 EVT_MENU( ID_COLOURSCHEME2
, FormMain::OnColourScheme
)
510 EVT_MENU( ID_COLOURSCHEME3
, FormMain::OnColourScheme
)
511 EVT_MENU( ID_COLOURSCHEME4
, FormMain::OnColourScheme
)
513 EVT_MENU( ID_ABOUT
, FormMain::OnAbout
)
514 EVT_MENU( ID_QUIT
, FormMain::OnCloseClick
)
516 EVT_MENU( ID_CATCOLOURS
, FormMain::OnCatColours
)
517 EVT_MENU( ID_SETCOLUMNS
, FormMain::OnSetColumns
)
518 EVT_MENU( ID_TESTXRC
, FormMain::OnTestXRC
)
519 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain::OnEnableCommonValues
)
520 EVT_MENU( ID_SELECTSTYLE
, FormMain::OnSelectStyle
)
522 EVT_MENU( ID_STATICLAYOUT
, FormMain::OnMisc
)
523 EVT_MENU( ID_COLLAPSE
, FormMain::OnMisc
)
524 EVT_MENU( ID_COLLAPSEALL
, FormMain::OnMisc
)
526 EVT_MENU( ID_POPULATE1
, FormMain::OnPopulateClick
)
527 EVT_MENU( ID_POPULATE2
, FormMain::OnPopulateClick
)
529 EVT_MENU( ID_GETVALUES
, FormMain::OnMisc
)
530 EVT_MENU( ID_SETVALUES
, FormMain::OnMisc
)
531 EVT_MENU( ID_SETVALUES2
, FormMain::OnMisc
)
533 EVT_MENU( ID_FITCOLUMNS
, FormMain::OnFitColumnsClick
)
535 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain::OnChangeFlagsPropItemsClick
)
537 EVT_MENU( ID_RUNTESTFULL
, FormMain::OnMisc
)
538 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain::OnMisc
)
540 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain::OnInsertChoice
)
541 EVT_MENU( ID_TESTDELETECHOICE
, FormMain::OnDeleteChoice
)
543 EVT_MENU( ID_INSERTPAGE
, FormMain::OnInsertPage
)
544 EVT_MENU( ID_REMOVEPAGE
, FormMain::OnRemovePage
)
546 EVT_MENU( ID_SAVESTATE
, FormMain::OnSaveState
)
547 EVT_MENU( ID_RESTORESTATE
, FormMain::OnRestoreState
)
549 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain::OnSetSpinCtrlEditorClick
)
550 EVT_MENU( ID_TESTREPLACE
, FormMain::OnTestReplaceClick
)
551 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain::OnSetPropertyValue
)
553 EVT_MENU( ID_RUNMINIMAL
, FormMain::OnRunMinimalClick
)
555 EVT_CONTEXT_MENU( FormMain::OnContextMenu
)
558 // -----------------------------------------------------------------------
560 void FormMain::OnMove( wxMoveEvent
& event
)
562 if ( !m_pPropGridManager
)
564 // this check is here so the frame layout can be tested
565 // without creating propertygrid
570 // Update position properties
576 // Must check if properties exist (as they may be deleted).
578 // Using m_pPropGridManager, we can scan all pages automatically.
579 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
581 m_pPropGridManager
->SetPropertyValue( id
, x
);
583 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
585 m_pPropGridManager
->SetPropertyValue( id
, y
);
587 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
589 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxPoint(x
,y
)) );
591 // Should always call event.Skip() in frame's MoveEvent handler
595 // -----------------------------------------------------------------------
597 void FormMain::OnResize( wxSizeEvent
& event
)
599 if ( !m_pPropGridManager
)
601 // this check is here so the frame layout can be tested
602 // without creating propertygrid
607 // Update size properties
614 // Must check if properties exist (as they may be deleted).
616 // Using m_pPropGridManager, we can scan all pages automatically.
617 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
618 if ( p
&& !p
->IsValueUnspecified() )
619 m_pPropGridManager
->SetPropertyValue( p
, w
);
621 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
622 if ( p
&& !p
->IsValueUnspecified() )
623 m_pPropGridManager
->SetPropertyValue( p
, h
);
625 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
627 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxSize(w
,h
)) );
629 // Should always call event.Skip() in frame's SizeEvent handler
633 // -----------------------------------------------------------------------
635 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
637 wxPGProperty
* p
= event
.GetProperty();
639 if ( p
->GetName() == wxT("Font") )
642 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
643 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
644 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
648 wxASSERT(event
.CanVeto());
652 // Since we ask a question, it is better if we omit any validation
653 // failure behaviour.
654 event
.SetValidationFailureBehavior(0);
660 // Note how we use three types of value getting in this method:
661 // A) event.GetPropertyValueAsXXX
662 // B) event.GetPropertValue, and then variant's GetXXX
663 // C) grid's GetPropertyValueAsXXX(id)
665 void FormMain::OnPropertyGridChange( wxPropertyGridEvent
& event
)
667 wxPGProperty
* property
= event
.GetProperty();
669 const wxString
& name
= property
->GetName();
671 // Properties store values internally as wxVariants, but it is preferred
672 // to use the more modern wxAny at the interface level
673 wxAny value
= property
->GetValue();
675 // Don't handle 'unspecified' values
676 if ( value
.IsNull() )
680 // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
681 // macro is used. Unless you want to support this old
682 // compiler in your own code, you can use the more
683 // nicer form value.As<FOO>() instead of
684 // wxANY_AS(value, FOO).
687 // Some settings are disabled outside Windows platform
688 if ( name
== wxT("X") )
689 SetSize( wxANY_AS(value
, int), -1, -1, -1, wxSIZE_USE_EXISTING
);
690 else if ( name
== wxT("Y") )
691 // wxPGVariantToInt is safe long int value getter
692 SetSize ( -1, wxANY_AS(value
, int), -1, -1, wxSIZE_USE_EXISTING
);
693 else if ( name
== wxT("Width") )
694 SetSize ( -1, -1, wxANY_AS(value
, int), -1, wxSIZE_USE_EXISTING
);
695 else if ( name
== wxT("Height") )
696 SetSize ( -1, -1, -1, wxANY_AS(value
, int), wxSIZE_USE_EXISTING
);
697 else if ( name
== wxT("Label") )
699 SetTitle( wxANY_AS(value
, wxString
) );
701 else if ( name
== wxT("Password") )
703 static int pwdMode
= 0;
705 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
711 if ( name
== wxT("Font") )
713 wxFont font
= wxANY_AS(value
, wxFont
);
714 wxASSERT( font
.Ok() );
716 m_pPropGridManager
->SetFont( font
);
719 if ( name
== wxT("Margin Colour") )
721 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
722 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
724 else if ( name
== wxT("Cell Colour") )
726 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
727 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
729 else if ( name
== wxT("Line Colour") )
731 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
732 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
734 else if ( name
== wxT("Cell Text Colour") )
736 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
737 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
741 // -----------------------------------------------------------------------
743 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
745 wxPGProperty
* property
= event
.GetProperty();
748 m_itemEnable
->Enable( TRUE
);
749 if ( property
->IsEnabled() )
750 m_itemEnable
->SetItemLabel( wxT("Disable") );
752 m_itemEnable
->SetItemLabel( wxT("Enable") );
756 m_itemEnable
->Enable( FALSE
);
760 wxPGProperty
* prop
= event
.GetProperty();
761 wxStatusBar
* sb
= GetStatusBar();
764 wxString
text(wxT("Selected: "));
765 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
766 sb
->SetStatusText ( text
);
771 // -----------------------------------------------------------------------
773 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
776 wxStatusBar
* sb
= GetStatusBar();
777 wxString
text(wxT("Page Changed: "));
778 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
779 sb
->SetStatusText( text
);
783 // -----------------------------------------------------------------------
785 void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent
& event
)
787 wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
788 event
.GetProperty()->GetLabel().c_str());
791 // -----------------------------------------------------------------------
793 void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent
& event
)
795 wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
796 event
.GetProperty()->GetLabel().c_str());
799 // -----------------------------------------------------------------------
801 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
805 // -----------------------------------------------------------------------
807 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
810 wxPGProperty
* prop
= event
.GetProperty();
811 wxStatusBar
* sb
= GetStatusBar();
814 wxString
text(wxT("Right-clicked: "));
815 text
+= prop
->GetLabel();
816 text
+= wxT(", name=");
817 text
+= m_pPropGridManager
->GetPropertyName(prop
);
818 sb
->SetStatusText( text
);
822 sb
->SetStatusText( wxEmptyString
);
827 // -----------------------------------------------------------------------
829 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
832 wxPGProperty
* prop
= event
.GetProperty();
833 wxStatusBar
* sb
= GetStatusBar();
836 wxString
text(wxT("Double-clicked: "));
837 text
+= prop
->GetLabel();
838 text
+= wxT(", name=");
839 text
+= m_pPropGridManager
->GetPropertyName(prop
);
840 sb
->SetStatusText ( text
);
844 sb
->SetStatusText ( wxEmptyString
);
849 // -----------------------------------------------------------------------
851 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent
& )
854 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
855 wxStatusBar
* sb
= GetStatusBar();
858 wxString
text(wxT("Button clicked: "));
859 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
860 text
+= wxT(", name=");
861 text
+= m_pPropGridManager
->GetPropertyName(prop
);
862 sb
->SetStatusText( text
);
866 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
871 // -----------------------------------------------------------------------
873 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
875 wxLogMessage(wxT("Item was Collapsed"));
878 // -----------------------------------------------------------------------
880 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
882 wxLogMessage(wxT("Item was Expanded"));
885 // -----------------------------------------------------------------------
887 void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent
& event
)
889 if ( m_itemVetoDragging
->IsChecked() )
891 wxLogMessage("Splitter %i resize was vetoed", event
.GetColumn());
896 wxLogMessage("Splitter %i resize began", event
.GetColumn());
900 // -----------------------------------------------------------------------
902 void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent
& event
)
905 // For now, let's not spam the log output
906 //wxLogMessage("Splitter %i is being resized", event.GetColumn());
909 // -----------------------------------------------------------------------
911 void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent
& event
)
913 wxLogMessage("Splitter %i resize ended", event
.GetColumn());
916 // -----------------------------------------------------------------------
919 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
924 // -----------------------------------------------------------------------
926 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
928 // Occurs on wxGTK mostly, but not wxMSW.
931 // -----------------------------------------------------------------------
933 void FormMain::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
935 // Uncomment following to allow property label modify in real-time
936 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
937 // if ( !p.IsOk() ) return;
938 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
941 // -----------------------------------------------------------------------
943 static const wxChar
* _fs_windowstyle_labels
[] = {
944 wxT("wxSIMPLE_BORDER"),
945 wxT("wxDOUBLE_BORDER"),
946 wxT("wxSUNKEN_BORDER"),
947 wxT("wxRAISED_BORDER"),
949 wxT("wxTRANSPARENT_WINDOW"),
950 wxT("wxTAB_TRAVERSAL"),
951 wxT("wxWANTS_CHARS"),
952 #if wxNO_FULL_REPAINT_ON_RESIZE
953 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
956 wxT("wxALWAYS_SHOW_SB"),
957 wxT("wxCLIP_CHILDREN"),
958 #if wxFULL_REPAINT_ON_RESIZE
959 wxT("wxFULL_REPAINT_ON_RESIZE"),
961 (const wxChar
*) NULL
// terminator is always needed
964 static const long _fs_windowstyle_values
[] = {
970 wxTRANSPARENT_WINDOW
,
973 #if wxNO_FULL_REPAINT_ON_RESIZE
974 wxNO_FULL_REPAINT_ON_RESIZE
,
979 #if wxFULL_REPAINT_ON_RESIZE
980 wxFULL_REPAINT_ON_RESIZE
984 static const wxChar
* _fs_framestyle_labels
[] = {
989 wxT("wxSTAY_ON_TOP"),
990 wxT("wxSYSTEM_MENU"),
991 wxT("wxRESIZE_BORDER"),
992 wxT("wxFRAME_TOOL_WINDOW"),
993 wxT("wxFRAME_NO_TASKBAR"),
994 wxT("wxFRAME_FLOAT_ON_PARENT"),
995 wxT("wxFRAME_SHAPED"),
999 static const long _fs_framestyle_values
[] = {
1007 wxFRAME_TOOL_WINDOW
,
1009 wxFRAME_FLOAT_ON_PARENT
,
1013 // -----------------------------------------------------------------------
1015 void FormMain::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1017 wxMessageBox(wxT("Sorrt, not yet implemented"));
1020 void FormMain::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1022 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
1024 prop
->EnableCommonValue();
1026 wxMessageBox(wxT("First select a property"));
1029 void FormMain::PopulateWithStandardItems ()
1031 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1032 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1034 // Append is ideal way to add items to wxPropertyGrid.
1035 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1037 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1038 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1039 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1041 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1042 pg
->GetGrid()->GetMarginColour()) );
1044 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1045 pg
->GetGrid()->GetCellBackgroundColour()) );
1046 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1047 pg
->GetGrid()->GetCellTextColour()) );
1048 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1049 pg
->GetGrid()->GetLineColour()) );
1050 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1051 m_combinedFlags
, GetWindowStyle()) );
1053 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1055 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1057 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1058 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1060 // Let's demonstrate 'Units' attribute here
1062 // Note that we use many attribute constants instead of strings here
1063 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1064 // Using constant may reduce binary size.
1066 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1067 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1068 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1069 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1071 // Set value to unspecified so that Hint attribute will be demonstrated
1072 pg
->SetPropertyValueUnspecified("Height");
1073 pg
->SetPropertyAttribute("Height", wxPG_ATTR_HINT
,
1074 "Enter new height for window" );
1076 // Difference between hint and help string is that the hint is shown in
1077 // an empty value cell, while help string is shown either in the
1078 // description text box, as a tool tip, or on the status bar.
1079 pg
->SetPropertyHelpString("Height",
1080 "This property uses attributes \"Units\" and \"Hint\"." );
1082 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1083 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1084 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1085 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1087 pg
->SetPropertyValueUnspecified(wxT("Width"));
1088 pg
->SetPropertyAttribute("Width", wxPG_ATTR_HINT
,
1089 "Enter new width for window" );
1090 pg
->SetPropertyHelpString("Width",
1091 "This property uses attributes \"Units\" and \"Hint\"." );
1093 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1094 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1095 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1097 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1098 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1099 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1101 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. In order to have label disabled as well, ")
1102 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1104 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1105 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1107 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1108 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1109 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1111 // Disable some of them
1112 pg
->DisableProperty( wxT("Operating System") );
1113 pg
->DisableProperty( wxT("User Id") );
1114 pg
->DisableProperty( wxT("User Name") );
1116 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1117 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1118 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1120 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1122 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1123 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1124 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1125 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1128 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1129 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1130 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1131 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1132 wxT("with custom action (dir dialog popup) defined.")
1135 wxArrayDouble arrdbl
;
1142 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1143 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1144 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1145 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1146 wxT("It is an example of a custom list editor property.")
1149 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1150 wxT("Editing properties will have immediate effect on this window, ")
1151 wxT("and vice versa (atleast in most cases, that is).")
1153 pg
->SetPropertyHelpString( wxT("Information"),
1154 wxT("This property is read-only.") );
1156 pg
->SetPropertyReadOnly( wxT("Information"), true );
1159 // Set test information for cells in columns 3 and 4
1160 // (reserve column 2 for displaying units)
1161 wxPropertyGridIterator it
;
1162 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_FOLDER
);
1164 for ( it
= pg
->GetGrid()->GetIterator();
1168 wxPGProperty
* p
= *it
;
1169 if ( p
->IsCategory() )
1172 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1173 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1177 // -----------------------------------------------------------------------
1179 void FormMain::PopulateWithExamples ()
1181 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1182 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1186 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1187 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1190 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1192 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl
);
1193 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1194 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)16384 ); // for reduced binary size.
1195 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1196 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
1197 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1199 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1200 wxT("This is regular wxIntProperty, which editor has been ")
1201 wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
1202 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1203 wxT("needs to be called prior to using it."));
1207 // Add bool property
1208 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1210 // Add bool property with check box
1211 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1212 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1213 wxPG_BOOL_USE_CHECKBOX
,
1216 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1217 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1219 prop
= pg
->Append( new wxFloatProperty("FloatProperty",
1222 prop
->SetAttribute("Min", -100.12);
1224 // A string property that can be edited in a separate editor dialog.
1225 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1226 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1228 // A property that edits a wxArrayString.
1229 wxArrayString example_array
;
1230 example_array
.Add( wxT("String 1"));
1231 example_array
.Add( wxT("String 2"));
1232 example_array
.Add( wxT("String 3"));
1233 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1236 // Test adding same category multiple times ( should not actually create a new one )
1237 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1239 // A file selector property. Note that argument between name
1240 // and initial value is wildcard (format same as in wxFileDialog).
1241 prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1244 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1245 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1246 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1249 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1250 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1254 // An image file property. Arguments are just like for FileProperty, but
1255 // wildcard is missing (it is autogenerated from supported image formats).
1256 // If you really need to override it, create property separately, and call
1257 // its SetWildcard method.
1258 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1261 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1262 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox
);
1263 pg
->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
1264 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1265 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1266 wxT("editor of this property to wxPGEditor_ComboBox)"));
1268 pid
= pg
->Append( new wxColourProperty("ColourPropertyWithAlpha",
1270 wxColour(15, 200, 95, 128)) );
1271 pg
->SetPropertyAttribute("ColourPropertyWithAlpha", "HasAlpha", true);
1272 pg
->SetPropertyHelpString("ColourPropertyWithAlpha",
1273 "Attribute \"HasAlpha\" is set to true for this property.");
1276 // This demonstrates using alternative editor for colour property
1277 // to trigger colour dialog directly from button.
1278 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1281 // wxEnumProperty does not store strings or even list of strings
1282 // ( so that's why they are static in function ).
1283 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1284 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1286 // this value array would be optional if values matched string indexes
1287 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1289 // note that the initial value (the last argument) is the actual value,
1290 // not index or anything like that. Thus, our value selects "Another Item".
1292 // 0 before value is number of items. If it is 0, like in our example,
1293 // number of items is calculated, and this requires that the string pointer
1294 // array is terminated with NULL.
1295 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1296 enum_prop_labels
, enum_prop_values
, 80 ) );
1300 // use basic table from our previous example
1301 // can also set/add wxArrayStrings and wxArrayInts directly.
1302 soc
.Set( enum_prop_labels
, enum_prop_values
);
1305 soc
.Add( wxT("Look, it continues"), 200 );
1306 soc
.Add( wxT("Even More"), 240 );
1307 soc
.Add( wxT("And More"), 280 );
1309 soc
.Add( wxT("True End of the List"), 320 );
1311 // Test custom colours ([] operator of wxPGChoices returns
1312 // references to wxPGChoiceEntry).
1313 soc
[1].SetFgCol(*wxRED
);
1314 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1315 soc
[2].SetFgCol(*wxGREEN
);
1316 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1317 soc
[3].SetFgCol(*wxBLUE
);
1318 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1319 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1321 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1325 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1327 // Here we only display the original 'soc' choices
1328 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1331 // Test Hint attribute in EnumProperty
1332 pg
->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
1334 pg
->SetPropertyHelpString("EnumProperty 3",
1335 "This property uses \"Hint\" attribute.");
1337 // 'soc' plus one exclusive extra choice "4th only"
1338 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1340 pg
->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
1342 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1343 wxT("Should have one extra item when compared to EnumProperty 3"));
1345 // Password property example.
1346 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1347 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1348 pg
->SetPropertyHelpString( wxT("Password"),
1349 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1351 // String editor with dir selector button. Uses wxEmptyString as name, which
1352 // is allowed (naturally, in this case property cannot be accessed by name).
1353 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1354 pg
->SetPropertyAttribute( wxT("DirProperty"),
1355 wxPG_DIR_DIALOG_MESSAGE
,
1356 wxT("This is a custom dir dialog message") );
1358 // Add string property - first arg is label, second name, and third initial value
1359 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1360 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1361 pg
->SetPropertyHelpString( wxT("StringProperty"),
1362 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1364 // Set value after limiting so that it will be applied
1365 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1368 // Demonstrate "AutoComplete" attribute
1369 pg
->Append( new wxStringProperty( "StringProperty AutoComplete",
1372 wxArrayString autoCompleteStrings
;
1373 autoCompleteStrings
.Add("One choice");
1374 autoCompleteStrings
.Add("Another choice");
1375 autoCompleteStrings
.Add("Another choice, yeah");
1376 autoCompleteStrings
.Add("Yet another choice");
1377 autoCompleteStrings
.Add("Yet another choice, bear with me");
1378 pg
->SetPropertyAttribute( "StringProperty AutoComplete",
1380 autoCompleteStrings
);
1382 pg
->SetPropertyHelpString( "StringProperty AutoComplete",
1383 "AutoComplete attribute has been set for this property "
1384 "(try writing something beginning with 'a', 'o' or 'y').");
1386 // Add string property with arbitrarily wide bitmap in front of it. We
1387 // intentionally lower-than-typical row height here so that the ugly
1388 // scaling code wont't be run.
1389 pg
->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
1391 wxT("Test Text")) );
1392 wxBitmap
myTestBitmap(60, 15, 32);
1394 mdc
.SelectObject(myTestBitmap
);
1396 mdc
.SetPen(*wxBLACK
);
1397 mdc
.DrawLine(0, 0, 60, 15);
1398 mdc
.SelectObject(wxNullBitmap
);
1399 pg
->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap
);
1402 // this value array would be optional if values matched string indexes
1403 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1405 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1406 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1409 // Multi choice dialog.
1410 wxArrayString tchoices
;
1411 tchoices
.Add(wxT("Cabbage"));
1412 tchoices
.Add(wxT("Carrot"));
1413 tchoices
.Add(wxT("Onion"));
1414 tchoices
.Add(wxT("Potato"));
1415 tchoices
.Add(wxT("Strawberry"));
1417 wxArrayString tchoicesValues
;
1418 tchoicesValues
.Add(wxT("Carrot"));
1419 tchoicesValues
.Add(wxT("Potato"));
1421 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1423 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1424 tchoices
, tchoicesValues
) );
1425 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1427 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1428 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1431 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1432 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1433 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1434 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1435 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1438 // wxEditEnumProperty
1440 eech
.Add(wxT("Choice 1"));
1441 eech
.Add(wxT("Choice 2"));
1442 eech
.Add(wxT("Choice 3"));
1443 pg
->Append( new wxEditEnumProperty("EditEnumProperty",
1446 "Choice not in the list") );
1448 // Test Hint attribute in EditEnumProperty
1449 pg
->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
1452 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1453 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1457 // wxDateTimeProperty
1458 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1460 #if wxUSE_DATEPICKCTRL
1461 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1462 (long)(wxDP_DROPDOWN
|
1466 pg
->SetPropertyHelpString( wxT("DateProperty"),
1467 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
1468 wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
1474 // Add Triangle properties as both wxTriangleProperty and
1475 // a generic parent property (using wxStringProperty).
1477 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1479 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1480 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1481 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1482 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1484 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1486 pg
->SetPropertyHelpString( wxT("3D Object"),
1487 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1488 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1490 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1491 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1492 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1493 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1495 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1498 // This snippet is a doc sample test
1500 wxPGProperty
* carProp
= pg
->Append(new wxStringProperty(wxT("Car"),
1502 wxT("<composed>")));
1504 pg
->AppendIn(carProp
, new wxStringProperty(wxT("Model"),
1506 wxT("Lamborghini Diablo SV")));
1508 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Engine Size (cc)"),
1512 wxPGProperty
* speedsProp
= pg
->AppendIn(carProp
,
1513 new wxStringProperty(wxT("Speeds"),
1515 wxT("<composed>")));
1517 pg
->AppendIn( speedsProp
, new wxIntProperty(wxT("Max. Speed (mph)"),
1519 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("0-100 mph (sec)"),
1521 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("1/4 mile (sec)"),
1524 // This is how child property can be referred to by name
1525 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1527 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Price ($)"),
1531 pg
->AppendIn(carProp
, new wxBoolProperty(wxT("Convertible"),
1535 // Displayed value of "Car" property is now very close to this:
1536 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
1539 // Test wxSampleMultiButtonEditor
1540 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1541 pg
->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor
);
1543 // Test SingleChoiceProperty
1544 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1548 // Test adding variable height bitmaps in wxPGChoices
1551 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1552 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1553 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1555 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1561 // Test how non-editable composite strings appear
1562 pid
= new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>"));
1563 pg
->SetPropertyReadOnly(pid
);
1566 // For testing purposes, combine two methods of adding children
1569 pid
->AppendChild( new wxStringProperty(wxT("Latest Release"),
1572 pid
->AppendChild( new wxBoolProperty(wxT("Win API"),
1578 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1579 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1580 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1581 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1582 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1583 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1584 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1586 AddTestProperties(pg
);
1589 // -----------------------------------------------------------------------
1591 void FormMain::PopulateWithLibraryConfig ()
1593 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1594 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1596 // Set custom column proportions (here in the sample app we need
1597 // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
1598 // need not to do it in your application).
1599 if ( pgman
->HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
1601 pg
->SetColumnProportion(0, 3);
1602 pg
->SetColumnProportion(1, 1);
1607 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1611 wxFont italicFont
= pgman
->GetGrid()->GetCaptionFont();
1612 italicFont
.SetStyle(wxFONTSTYLE_ITALIC
);
1614 wxString italicFontHelp
= "Font of this property's wxPGCell has "
1615 "been modified. Obtain property's cell "
1616 "with wxPGProperty::"
1617 "GetOrCreateCell(column).";
1619 #define ADD_WX_LIB_CONF_GROUP(A) \
1620 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1621 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
1622 cat->GetCell(0).SetFont(italicFont); \
1623 cat->SetHelpString(italicFontHelp);
1625 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1626 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1627 pg->DisableProperty(wxT(#A));
1629 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1630 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1632 // Both of following lines would set a label for the second column
1633 pg
->SetPropertyCell( pid
, 1, "Is Enabled" );
1634 pid
->SetValue("Is Enabled");
1636 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1637 ADD_WX_LIB_CONF( wxUSE_GUI
)
1639 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1640 #if defined(WXWIN_COMPATIBILITY_2_2)
1641 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1643 #if defined(WXWIN_COMPATIBILITY_2_4)
1644 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1646 #if defined(WXWIN_COMPATIBILITY_2_6)
1647 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1649 #if defined(WXWIN_COMPATIBILITY_2_8)
1650 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1652 #ifdef wxFONT_SIZE_COMPATIBILITY
1653 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1655 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1657 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1658 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1660 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1663 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1664 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1665 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1666 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1667 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1668 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1670 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1671 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1672 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1674 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1675 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1676 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1677 ADD_WX_LIB_CONF( wxUSE_STL
)
1678 ADD_WX_LIB_CONF( wxUSE_LOG
)
1679 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1680 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1681 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1682 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1683 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1684 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1685 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1687 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1688 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1689 ADD_WX_LIB_CONF( wxUSE_FILE
)
1690 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1691 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1692 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1693 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1694 ADD_WX_LIB_CONF( wxUSE_INTL
)
1695 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1696 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1697 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1698 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1699 #ifdef wxUSE_CONFIG_NATIVE
1700 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1702 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1704 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1705 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1706 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1707 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1708 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1709 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1710 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1711 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1712 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1713 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1714 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1715 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1716 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1717 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1718 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1719 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1720 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1721 ADD_WX_LIB_CONF( wxUSE_URL
)
1722 #ifdef wxUSE_URL_NATIVE
1723 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1725 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1727 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1728 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1729 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1731 ADD_WX_LIB_CONF( wxUSE_XRC
)
1733 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1735 ADD_WX_LIB_CONF( wxUSE_XML
)
1737 // Set them to use check box.
1738 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1743 // Handle events of the third page here.
1744 class wxMyPropertyGridPage
: public wxPropertyGridPage
1748 // Return false here to indicate unhandled events should be
1749 // propagated to manager's parent, as normal.
1750 virtual bool IsHandlingAllEvents() const { return false; }
1754 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1756 wxPGProperty
* property
)
1758 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1761 void OnPropertySelect( wxPropertyGridEvent
& event
);
1762 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1763 void OnPropertyChange( wxPropertyGridEvent
& event
);
1764 void OnPageChange( wxPropertyGridEvent
& event
);
1767 DECLARE_EVENT_TABLE()
1771 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1772 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1773 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1774 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1775 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1779 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1781 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1784 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1786 wxPGProperty
* p
= event
.GetProperty();
1787 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1788 p
->GetName().c_str(),
1789 p
->GetDisplayedString().c_str());
1792 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1794 wxPGProperty
* p
= event
.GetProperty();
1795 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1796 p
->GetName().c_str(),
1797 event
.GetValue().GetString().c_str());
1800 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1802 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1806 class wxPGKeyHandler
: public wxEvtHandler
1810 void OnKeyEvent( wxKeyEvent
& event
)
1812 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1816 DECLARE_EVENT_TABLE()
1819 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1820 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1824 // -----------------------------------------------------------------------
1826 void FormMain::InitPanel()
1831 wxWindow
* panel
= new wxPanel(this, wxID_ANY
,
1832 wxPoint(0, 0), wxSize(400, 400),
1837 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1839 m_topSizer
= topSizer
;
1842 void FormMain::FinalizePanel( bool wasCreated
)
1844 // Button for tab traversal testing
1845 m_topSizer
->Add( new wxButton(m_panel
, wxID_ANY
,
1846 wxS("Should be able to move here with Tab")),
1849 m_panel
->SetSizer( m_topSizer
);
1850 m_topSizer
->SetSizeHints( m_panel
);
1852 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1853 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1855 SetSizer( panelSizer
);
1856 panelSizer
->SetSizeHints( this );
1859 FinalizeFramePosition();
1862 void FormMain::PopulateGrid()
1864 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1865 pgman
->AddPage(wxT("Standard Items"));
1867 PopulateWithStandardItems();
1869 pgman
->AddPage(wxT("wxWidgets Library Config"));
1871 PopulateWithLibraryConfig();
1873 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1874 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1876 // Use wxMyPropertyGridPage (see above) to test the
1877 // custom wxPropertyGridPage feature.
1878 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1880 PopulateWithExamples();
1883 void FormMain::CreateGrid( int style
, int extraStyle
)
1886 // This function (re)creates the property grid in our sample
1890 style
= // default style
1891 wxPG_BOLD_MODIFIED
|
1892 wxPG_SPLITTER_AUTO_CENTER
|
1894 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1896 //wxPG_HIDE_CATEGORIES |
1897 //wxPG_LIMITED_EDITING |
1901 if ( extraStyle
== -1 )
1902 // default extra style
1903 extraStyle
= wxPG_EX_MODE_BUTTONS
|
1904 wxPG_EX_MULTIPLE_SELECTION
;
1905 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1906 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1907 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1908 //| wxPG_EX_HELP_AS_TOOLTIPS
1910 bool wasCreated
= m_panel
? false : true;
1915 // This shows how to combine two static choice descriptors
1916 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1917 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1919 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1920 new wxPropertyGridManager(m_panel
,
1921 // Don't change this into wxID_ANY in the sample, or the
1922 // event handling will obviously be broken.
1925 wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
1926 // But calling SetInitialSize in manager changes the code
1927 // order to the grid gets created immediately, before SetExtraStyle
1931 m_propGrid
= pgman
->GetGrid();
1933 pgman
->SetExtraStyle(extraStyle
);
1935 // This is the default validation failure behaviour
1936 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL
|
1937 wxPG_VFB_SHOW_MESSAGEBOX
);
1939 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
1942 // Set somewhat different unspecified value appearance
1944 cell
.SetText("Unspecified");
1945 cell
.SetFgCol(*wxLIGHT_GREY
);
1946 m_propGrid
->SetUnspecifiedValueAppearance(cell
);
1950 // Change some attributes in all properties
1951 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
1952 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
1954 //m_pPropGridManager->SetSplitterLeft(true);
1955 //m_pPropGridManager->SetSplitterPosition(137);
1958 // This would setup event handling without event table entries
1959 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
1960 wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
1961 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
1962 wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
1965 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
1967 FinalizePanel(wasCreated
);
1970 // -----------------------------------------------------------------------
1972 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
1973 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
1974 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
1975 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
1977 SetIcon(wxICON(sample
));
1983 // we need this in order to allow the about menu relocation, since ABOUT is
1984 // not the default id of the about menu
1985 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
1989 // This is here to really test the wxImageFileProperty.
1990 wxInitAllImageHandlers();
1993 // Register all editors (SpinCtrl etc.)
1994 m_pPropGridManager
->RegisterAdditionalEditors();
1996 // Register our sample custom editors
1997 m_pSampleMultiButtonEditor
=
1998 wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
2000 CreateGrid( // style
2001 wxPG_BOLD_MODIFIED
|
2002 wxPG_SPLITTER_AUTO_CENTER
|
2004 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2006 //wxPG_HIDE_CATEGORIES |
2007 //wxPG_LIMITED_EDITING |
2011 wxPG_EX_MODE_BUTTONS
|
2012 wxPG_EX_MULTIPLE_SELECTION
2013 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2014 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2015 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2016 //| wxPG_EX_HELP_AS_TOOLTIPS
2021 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2022 wxMenu
*menuTry
= new wxMenu
;
2023 wxMenu
*menuTools1
= new wxMenu
;
2024 wxMenu
*menuTools2
= new wxMenu
;
2025 wxMenu
*menuHelp
= new wxMenu
;
2027 menuHelp
->Append(ID_ABOUT
, wxT("&About..."), wxT("Show about dialog") );
2029 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2030 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2031 menuTools1
->AppendSeparator();
2032 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2033 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2034 menuTools1
->AppendSeparator();
2035 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2036 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2037 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2038 menuTools1
->AppendSeparator();
2039 menuTools1
->Append(ID_SETBGCOLOUR
, wxT("Set Bg Colour") );
2040 menuTools1
->Append(ID_SETBGCOLOURRECUR
, wxT("Set Bg Colour (Recursively)") );
2041 menuTools1
->Append(ID_UNSPECIFY
, "Set Value to Unspecified");
2042 menuTools1
->AppendSeparator();
2043 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2044 wxT("Toggles item's enabled state.") );
2045 m_itemEnable
->Enable( FALSE
);
2046 menuTools1
->Append(ID_HIDE
, "Hide", "Hides a property" );
2047 menuTools1
->Append(ID_SETREADONLY
, "Set as Read-Only",
2048 "Set property as read-only" );
2050 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2051 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2052 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2053 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2054 menuTools2
->AppendSeparator();
2055 menuTools2
->Append(ID_ONEXTENDEDKEYNAV
, "Extend Keyboard Navigation",
2056 "This will set Enter to navigate to next property, "
2057 "and allows arrow keys to navigate even when in "
2059 menuTools2
->AppendSeparator();
2060 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2061 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2062 menuTools2
->AppendSeparator();
2063 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2064 wxT("Disables painting, auto-sorting, etc.") );
2065 menuTools2
->AppendSeparator();
2066 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2067 menuTools2
->AppendSeparator();
2068 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2069 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2070 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).") );
2071 menuTools2
->AppendSeparator();
2072 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2073 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2074 menuTools2
->AppendSeparator();
2075 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2076 wxT("Enable values that are common to all properties, for selected property."));
2077 menuTools2
->AppendSeparator();
2078 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2079 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2080 menuTools2
->AppendSeparator();
2081 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2082 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2083 menuTools2
->AppendSeparator();
2084 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2085 m_itemVetoDragging
=
2086 menuTools2
->AppendCheckItem(ID_VETOCOLDRAG
,
2087 "Veto Column Dragging");
2088 menuTools2
->AppendSeparator();
2089 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2090 menuTools2
->AppendSeparator();
2091 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2092 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2093 menuTools2
->AppendSeparator();
2094 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2095 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2097 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2098 wxT("Select window style flags used by the grid."));
2099 menuTry
->Append(ID_ENABLELABELEDITING
, "Enable label editing",
2100 "This calls wxPropertyGrid::MakeColumnEditable(0)");
2101 menuTry
->AppendCheckItem(ID_SHOWHEADER
,
2103 "This calls wxPropertyGridManager::ShowHeader()");
2104 menuTry
->AppendSeparator();
2105 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2106 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2107 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2108 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2109 menuTry
->AppendSeparator();
2110 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2111 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2112 menuTry
->AppendSeparator();
2113 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2114 wxT("Switches between user-modifiedable and static layouts.") );
2115 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2116 menuTry
->AppendSeparator();
2117 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2118 menuTry
->AppendSeparator();
2119 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2120 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2122 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2123 menuFile
->AppendSeparator();
2124 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2126 // Now append the freshly created menu to the menu bar...
2127 wxMenuBar
*menuBar
= new wxMenuBar();
2128 menuBar
->Append(menuFile
, wxT("&File") );
2129 menuBar
->Append(menuTry
, wxT("&Try These!") );
2130 menuBar
->Append(menuTools1
, wxT("&Basic") );
2131 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2132 menuBar
->Append(menuHelp
, wxT("&Help") );
2134 // ... and attach this menu bar to the frame
2135 SetMenuBar(menuBar
);
2138 // create a status bar
2140 SetStatusText(wxEmptyString
);
2141 #endif // wxUSE_STATUSBAR
2143 FinalizeFramePosition();
2146 // Create log window
2147 m_logWindow
= new wxLogWindow(this, "Log Messages", false);
2148 m_logWindow
->GetFrame()->Move(GetPosition().x
+ GetSize().x
+ 10,
2150 m_logWindow
->Show();
2154 void FormMain::FinalizeFramePosition()
2156 wxSize
frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2157 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8);
2159 if ( frameSize
.x
> 500 )
2168 // Normally, wxPropertyGrid does not check whether item with identical
2169 // label already exists. However, since in this sample we use labels for
2170 // identifying properties, we have to be sure not to generate identical
2173 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2178 if ( pg
->GetPropertyByLabel( baselabel
) )
2183 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2184 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2190 baselabel
= newlabel
;
2194 // -----------------------------------------------------------------------
2196 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2200 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2202 wxMessageBox(wxT("No items to relate - first add some with Append."));
2206 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2209 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2212 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2214 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2216 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2217 id
->GetIndexInParent(),
2218 new wxStringProperty(propLabel
) );
2222 // -----------------------------------------------------------------------
2224 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2228 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2230 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2232 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2234 m_pPropGridManager
->Refresh();
2237 // -----------------------------------------------------------------------
2239 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2241 m_pPropGridManager
->GetGrid()->Clear();
2244 // -----------------------------------------------------------------------
2246 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2250 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2252 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2254 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2256 m_pPropGridManager
->Refresh();
2260 // -----------------------------------------------------------------------
2262 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2266 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2268 wxMessageBox(wxT("No items to relate - first add some with Append."));
2272 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2275 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2279 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2281 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2283 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2284 id
->GetIndexInParent(),
2285 new wxPropertyCategory (propLabel
) );
2288 // -----------------------------------------------------------------------
2290 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2292 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2295 wxMessageBox(wxT("First select a property."));
2299 m_pPropGridManager
->DeleteProperty( id
);
2302 // -----------------------------------------------------------------------
2304 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2306 // Delete random property
2307 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2311 if ( !p
->IsCategory() )
2313 m_pPropGridManager
->DeleteProperty( p
);
2317 if ( !p
->GetChildCount() )
2320 int n
= rand() % ((int)p
->GetChildCount());
2326 // -----------------------------------------------------------------------
2328 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2330 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2331 event
.GetPosition().x
,event
.GetPosition().y
);
2338 // -----------------------------------------------------------------------
2340 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2342 /*#ifdef __WXDEBUG__
2343 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2344 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2350 // -----------------------------------------------------------------------
2352 int IterateMessage( wxPGProperty
* prop
)
2356 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2357 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2359 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2362 // -----------------------------------------------------------------------
2364 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2366 wxPropertyGridIterator it
;
2368 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2373 wxPGProperty
* p
= *it
;
2374 int res
= IterateMessage( p
);
2375 if ( res
== wxCANCEL
) break;
2379 // -----------------------------------------------------------------------
2381 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2383 wxPropertyGridIterator it
;
2385 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2386 GetIterator( wxPG_ITERATE_VISIBLE
);
2390 wxPGProperty
* p
= *it
;
2392 int res
= IterateMessage( p
);
2393 if ( res
== wxCANCEL
) break;
2397 // -----------------------------------------------------------------------
2399 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2401 // iterate over items in reverse order
2402 wxPropertyGridIterator it
;
2404 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2405 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2409 wxPGProperty
* p
= *it
;
2411 int res
= IterateMessage( p
);
2412 if ( res
== wxCANCEL
) break;
2416 // -----------------------------------------------------------------------
2418 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2420 wxPropertyGridIterator it
;
2422 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2423 GetIterator( wxPG_ITERATE_CATEGORIES
);
2427 wxPGProperty
* p
= *it
;
2429 int res
= IterateMessage( p
);
2430 if ( res
== wxCANCEL
) break;
2434 // -----------------------------------------------------------------------
2436 void FormMain::OnExtendedKeyNav( wxCommandEvent
& WXUNUSED(event
) )
2438 // Use AddActionTrigger() and DedicateKey() to set up Enter,
2439 // Up, and Down keys for navigating between properties.
2440 wxPropertyGrid
* propGrid
= m_pPropGridManager
->GetGrid();
2442 propGrid
->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY
,
2444 propGrid
->DedicateKey(WXK_RETURN
);
2446 // Up and Down keys are alredy associated with navigation,
2447 // but we must also prevent them from being eaten by
2449 propGrid
->DedicateKey(WXK_UP
);
2450 propGrid
->DedicateKey(WXK_DOWN
);
2453 // -----------------------------------------------------------------------
2455 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2457 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2459 // Remove auto-centering
2460 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2462 // Grow manager size just prior fit - otherwise
2463 // column information may be lost.
2464 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2465 wxSize oldFullSize
= GetSize();
2466 SetSize(1000, oldFullSize
.y
);
2468 wxSize newSz
= page
->FitColumns();
2470 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2471 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2479 // -----------------------------------------------------------------------
2481 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2483 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2485 wxPGChoices newChoices
;
2487 newChoices
.Add(wxT("Fast"),0x1);
2488 newChoices
.Add(wxT("Powerful"),0x2);
2489 newChoices
.Add(wxT("Safe"),0x4);
2490 newChoices
.Add(wxT("Sleek"),0x8);
2492 p
->SetChoices(newChoices
);
2495 // -----------------------------------------------------------------------
2497 void FormMain::OnEnableDisable( wxCommandEvent
& )
2499 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2502 wxMessageBox(wxT("First select a property."));
2506 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2508 m_pPropGridManager
->DisableProperty ( id
);
2509 m_itemEnable
->SetItemLabel( wxT("Enable") );
2513 m_pPropGridManager
->EnableProperty ( id
);
2514 m_itemEnable
->SetItemLabel( wxT("Disable") );
2518 // -----------------------------------------------------------------------
2520 void FormMain::OnSetReadOnly( wxCommandEvent
& WXUNUSED(event
) )
2522 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetSelection();
2525 wxMessageBox(wxT("First select a property."));
2528 m_pPropGridManager
->SetPropertyReadOnly(p
);
2531 // -----------------------------------------------------------------------
2533 void FormMain::OnHide( wxCommandEvent
& WXUNUSED(event
) )
2535 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2538 wxMessageBox(wxT("First select a property."));
2542 m_pPropGridManager
->HideProperty( id
, true );
2545 // -----------------------------------------------------------------------
2547 #include "wx/colordlg.h"
2550 FormMain::OnSetBackgroundColour( wxCommandEvent
& event
)
2552 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2553 wxPGProperty
* prop
= pg
->GetSelection();
2556 wxMessageBox(wxT("First select a property."));
2560 wxColour col
= ::wxGetColourFromUser(this, *wxWHITE
, "Choose colour");
2564 bool recursively
= (event
.GetId()==ID_SETBGCOLOURRECUR
) ? true : false;
2565 pg
->SetPropertyBackgroundColour(prop
, col
, recursively
);
2569 // -----------------------------------------------------------------------
2571 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2573 m_pPropGridManager
->AddPage(wxT("New Page"));
2576 // -----------------------------------------------------------------------
2578 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2580 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2583 // -----------------------------------------------------------------------
2585 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2587 m_savedState
= m_pPropGridManager
->SaveEditableState();
2588 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2591 // -----------------------------------------------------------------------
2593 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2595 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2598 // -----------------------------------------------------------------------
2600 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2603 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2605 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPGEditor_SpinCtrl
);
2607 wxMessageBox(wxT("First select a property"));
2611 // -----------------------------------------------------------------------
2613 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2615 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2618 wxPGChoices choices
;
2619 choices
.Add(wxT("Flag 0"),0x0001);
2620 choices
.Add(wxT("Flag 1"),0x0002);
2621 choices
.Add(wxT("Flag 2"),0x0004);
2622 choices
.Add(wxT("Flag 3"),0x0008);
2623 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2624 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2625 m_pPropGridManager
->SetPropertyAttribute( newId
,
2626 wxPG_BOOL_USE_CHECKBOX
,
2631 wxMessageBox(wxT("First select a property"));
2634 // -----------------------------------------------------------------------
2636 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2638 m_pPropGridManager
->ClearModifiedStatus();
2641 // -----------------------------------------------------------------------
2643 // Freeze check-box checked?
2644 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2646 if ( !m_pPropGridManager
) return;
2648 if ( event
.IsChecked() )
2650 if ( !m_pPropGridManager
->IsFrozen() )
2652 m_pPropGridManager
->Freeze();
2657 if ( m_pPropGridManager
->IsFrozen() )
2659 m_pPropGridManager
->Thaw();
2660 m_pPropGridManager
->Refresh();
2665 // -----------------------------------------------------------------------
2667 void FormMain::OnEnableLabelEditing( wxCommandEvent
& WXUNUSED(event
) )
2669 m_propGrid
->MakeColumnEditable(0);
2672 // -----------------------------------------------------------------------
2674 void FormMain::OnShowHeader( wxCommandEvent
& event
)
2676 m_pPropGridManager
->ShowHeader(event
.IsChecked());
2677 m_pPropGridManager
->SetColumnTitle(2, _("Units"));
2680 // -----------------------------------------------------------------------
2682 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2685 msg
.Printf( wxT("wxPropertyGrid Sample")
2687 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2701 wxT("Programmed by %s\n\n")
2702 wxT("Using %s\n\n"),
2703 wxT("Jaakko Salli"), wxVERSION_STRING
2706 wxMessageBox(msg
, wxT("About"), wxOK
| wxICON_INFORMATION
, this);
2709 // -----------------------------------------------------------------------
2711 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2713 int id
= event
.GetId();
2714 if ( id
== ID_COLOURSCHEME1
)
2716 m_pPropGridManager
->GetGrid()->ResetColours();
2718 else if ( id
== ID_COLOURSCHEME2
)
2721 wxColour
my_grey_1(212,208,200);
2722 wxColour
my_grey_3(113,111,100);
2723 m_pPropGridManager
->Freeze();
2724 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2725 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2726 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2727 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2728 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2729 m_pPropGridManager
->Thaw();
2731 else if ( id
== ID_COLOURSCHEME3
)
2734 wxColour
my_grey_1(212,208,200);
2735 wxColour
my_grey_2(236,233,216);
2736 m_pPropGridManager
->Freeze();
2737 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2738 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2739 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2740 m_pPropGridManager
->Thaw();
2742 else if ( id
== ID_COLOURSCHEME4
)
2746 wxColour
my_grey_1(212,208,200);
2747 wxColour
my_grey_2(241,239,226);
2748 wxColour
my_grey_3(113,111,100);
2749 m_pPropGridManager
->Freeze();
2750 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2751 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2752 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2753 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2754 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2755 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2756 m_pPropGridManager
->Thaw();
2760 // -----------------------------------------------------------------------
2762 void FormMain::OnCatColours( wxCommandEvent
& event
)
2764 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2765 m_pPropGridManager
->Freeze();
2767 if ( event
.IsChecked() )
2769 // Set custom colours.
2770 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2771 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2772 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2773 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2774 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2775 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2776 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2777 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2778 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2779 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2780 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2784 // Revert to original.
2785 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2786 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2787 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2788 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2790 m_pPropGridManager
->Thaw();
2791 m_pPropGridManager
->Refresh();
2794 // -----------------------------------------------------------------------
2796 #define ADD_FLAG(FLAG) \
2797 chs.Add(wxT(#FLAG)); \
2799 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2802 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2811 unsigned int ind
= 0;
2812 int flags
= m_pPropGridManager
->GetWindowStyle();
2813 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2814 ADD_FLAG(wxPG_AUTO_SORT
)
2815 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2816 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2817 ADD_FLAG(wxPG_TOOLTIPS
)
2818 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2819 ADD_FLAG(wxPG_HIDE_MARGIN
)
2820 ADD_FLAG(wxPG_LIMITED_EDITING
)
2821 ADD_FLAG(wxPG_TOOLBAR
)
2822 ADD_FLAG(wxPG_DESCRIPTION
)
2823 ADD_FLAG(wxPG_NO_INTERNAL_BORDER
)
2824 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2825 wxT("wxPropertyGrid Window Style"), chs
);
2826 dlg
.SetSelections(sel
);
2827 if ( dlg
.ShowModal() == wxID_CANCEL
)
2831 sel
= dlg
.GetSelections();
2832 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2833 flags
|= vls
[sel
[ind
]];
2842 unsigned int ind
= 0;
2843 int flags
= m_pPropGridManager
->GetExtraStyle();
2844 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2845 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2846 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2847 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2848 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2849 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2850 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2851 ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS
)
2852 ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION
)
2853 ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING
)
2854 ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER
)
2855 ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR
)
2856 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2857 wxT("wxPropertyGrid Extra Style"), chs
);
2858 dlg
.SetSelections(sel
);
2859 if ( dlg
.ShowModal() == wxID_CANCEL
)
2863 sel
= dlg
.GetSelections();
2864 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2865 flags
|= vls
[sel
[ind
]];
2870 CreateGrid( style
, extraStyle
);
2872 FinalizeFramePosition();
2875 // -----------------------------------------------------------------------
2877 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2879 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2880 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2883 if ( colCount
>= 2 )
2885 m_pPropGridManager
->SetColumnCount(colCount
);
2889 // -----------------------------------------------------------------------
2891 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2893 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2894 wxPGProperty
* selected
= pg
->GetSelection();
2898 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2899 pg
->SetPropertyValue( selected
, value
);
2903 // -----------------------------------------------------------------------
2905 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2907 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2909 wxPGProperty
* selected
= pg
->GetSelection();
2910 const wxPGChoices
& choices
= selected
->GetChoices();
2912 // Insert new choice to the center of list
2914 if ( choices
.IsOk() )
2916 int pos
= choices
.GetCount() / 2;
2917 selected
->InsertChoice(wxT("New Choice"), pos
);
2921 ::wxMessageBox(wxT("First select a property with some choices."));
2925 // -----------------------------------------------------------------------
2927 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2929 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2931 wxPGProperty
* selected
= pg
->GetSelection();
2932 const wxPGChoices
& choices
= selected
->GetChoices();
2934 // Deletes choice from the center of list
2936 if ( choices
.IsOk() )
2938 int pos
= choices
.GetCount() / 2;
2939 selected
->DeleteChoice(pos
);
2943 ::wxMessageBox(wxT("First select a property with some choices."));
2947 // -----------------------------------------------------------------------
2949 #include <wx/colordlg.h>
2951 void FormMain::OnMisc ( wxCommandEvent
& event
)
2953 int id
= event
.GetId();
2954 if ( id
== ID_STATICLAYOUT
)
2956 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2957 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2958 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2960 else if ( id
== ID_COLLAPSEALL
)
2963 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2965 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2966 it
.GetProperty()->SetExpanded( false );
2970 else if ( id
== ID_GETVALUES
)
2972 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2973 m_pPropGridManager
->GetGrid()->GetRoot(),
2974 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2976 else if ( id
== ID_SETVALUES
)
2978 if ( m_storedValues
.GetType() == wxT("list") )
2980 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2983 wxMessageBox(wxT("First use Get Property Values."));
2985 else if ( id
== ID_SETVALUES2
)
2989 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2990 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2991 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2992 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
2994 else if ( id
== ID_COLLAPSE
)
2996 // Collapses selected.
2997 wxPGProperty
* id
= m_pPropGridManager
->GetSelection();
3000 m_pPropGridManager
->Collapse(id
);
3003 else if ( id
== ID_RUNTESTFULL
)
3005 // Runs a regression test.
3008 else if ( id
== ID_RUNTESTPARTIAL
)
3010 // Runs a regression test.
3013 else if ( id
== ID_UNSPECIFY
)
3015 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
3018 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3019 prop
->RefreshEditor();
3024 // -----------------------------------------------------------------------
3026 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3028 int id
= event
.GetId();
3029 m_propGrid
->Clear();
3030 m_propGrid
->Freeze();
3031 if ( id
== ID_POPULATE1
)
3033 PopulateWithStandardItems();
3035 else if ( id
== ID_POPULATE2
)
3037 PopulateWithLibraryConfig();
3042 // -----------------------------------------------------------------------
3044 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3046 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3048 DisplayMinimalFrame(this);
3051 // -----------------------------------------------------------------------
3053 FormMain::~FormMain()
3057 // -----------------------------------------------------------------------
3059 IMPLEMENT_APP(cxApplication
)
3061 bool cxApplication::OnInit()
3064 //Locale.Init(wxLANGUAGE_FINNISH);
3066 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3070 // Parse command-line
3071 wxApp
& app
= wxGetApp();
3074 wxString s
= app
.argv
[1];
3075 if ( s
== wxT("--run-tests") )
3079 bool testResult
= frame
->RunTests(true);
3089 // -----------------------------------------------------------------------
3091 void FormMain::OnIdle( wxIdleEvent
& event
)
3094 // This code is useful for debugging focus problems
3095 static wxWindow* last_focus = (wxWindow*) NULL;
3097 wxWindow* cur_focus = ::wxWindow::FindFocus();
3099 if ( cur_focus != last_focus )
3101 const wxChar* class_name = wxT("<none>");
3103 class_name = cur_focus->GetClassInfo()->GetClassName();
3104 last_focus = cur_focus;
3105 wxLogDebug( wxT("FOCUSED: %s %X"),
3107 (unsigned int)cur_focus);
3114 // -----------------------------------------------------------------------