1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 // * Examples of custom property classes are in sampleprops.cpp.
17 // * Additional ones can be found below.
19 // * Currently there is no example of a custom property editor. However,
20 // SpinCtrl editor sample is well-commented. It can be found in
21 // src/propgrid/advprops.cpp.
23 // * To find code that populates the grid with properties, search for
24 // string "::Populate".
26 // * To find code that handles property grid changes, search for string
27 // "::OnPropertyGridChange".
30 // For compilers that support precompilation, includes "wx/wx.h".
31 #include "wx/wxprec.h"
37 // for all others, include the necessary headers (this file is usually all you
38 // need because it includes almost all "standard" wxWidgets headers)
44 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
47 #include <wx/numdlg.h>
49 // -----------------------------------------------------------------------
52 // Main propertygrid header.
53 #include <wx/propgrid/propgrid.h>
55 // Extra property classes.
56 #include <wx/propgrid/advprops.h>
58 // This defines wxPropertyGridManager.
59 #include <wx/propgrid/manager.h>
62 #include "sampleprops.h"
64 #if wxUSE_DATEPICKCTRL
65 #include <wx/datectrl.h>
68 #include <wx/artprov.h>
70 #ifndef wxHAS_IMAGES_IN_RESOURCES
71 #include "../sample.xpm"
74 #include <wx/popupwin.h>
76 // -----------------------------------------------------------------------
77 // wxSampleMultiButtonEditor
78 // A sample editor class that has multiple buttons.
79 // -----------------------------------------------------------------------
81 class wxSampleMultiButtonEditor
: public wxPGTextCtrlEditor
83 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor
)
85 wxSampleMultiButtonEditor() {}
86 virtual ~wxSampleMultiButtonEditor() {}
88 virtual wxPGWindowList
CreateControls( wxPropertyGrid
* propGrid
,
89 wxPGProperty
* property
,
91 const wxSize
& sz
) const;
92 virtual bool OnEvent( wxPropertyGrid
* propGrid
,
93 wxPGProperty
* property
,
95 wxEvent
& event
) const;
98 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor
, wxPGTextCtrlEditor
)
100 wxPGWindowList
wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
101 wxPGProperty
* property
,
103 const wxSize
& sz
) const
105 // Create and populate buttons-subwindow
106 wxPGMultiButton
* buttons
= new wxPGMultiButton( propGrid
, sz
);
108 // Add two regular buttons
109 buttons
->Add( "..." );
111 // Add a bitmap button
112 buttons
->Add( wxArtProvider::GetBitmap(wxART_FOLDER
) );
114 // Create the 'primary' editor control (textctrl in this case)
115 wxPGWindowList wndList
= wxPGTextCtrlEditor::CreateControls
116 ( propGrid
, property
, pos
,
117 buttons
->GetPrimarySize() );
119 // Finally, move buttons-subwindow to correct position and make sure
120 // returned wxPGWindowList contains our custom button list.
121 buttons
->Finalize(propGrid
, pos
);
123 wndList
.SetSecondary( buttons
);
127 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid
* propGrid
,
128 wxPGProperty
* property
,
130 wxEvent
& event
) const
132 if ( event
.GetEventType() == wxEVT_BUTTON
)
134 wxPGMultiButton
* buttons
= (wxPGMultiButton
*) propGrid
->GetEditorControlSecondary();
136 if ( event
.GetId() == buttons
->GetButtonId(0) )
138 // Do something when the first button is pressed
139 wxLogDebug("First button pressed");
140 return false; // Return false since value did not change
142 if ( event
.GetId() == buttons
->GetButtonId(1) )
144 // Do something when the second button is pressed
145 wxMessageBox("Second button pressed");
146 return false; // Return false since value did not change
148 if ( event
.GetId() == buttons
->GetButtonId(2) )
150 // Do something when the third button is pressed
151 wxMessageBox("Third button pressed");
152 return false; // Return false since value did not change
155 return wxPGTextCtrlEditor::OnEvent(propGrid
, property
, ctrl
, event
);
158 // -----------------------------------------------------------------------
159 // Validator for wxValidator use sample
160 // -----------------------------------------------------------------------
164 // wxValidator for testing
166 class wxInvalidWordValidator
: public wxValidator
170 wxInvalidWordValidator( const wxString
& invalidWord
)
171 : wxValidator(), m_invalidWord(invalidWord
)
175 virtual wxObject
* Clone() const
177 return new wxInvalidWordValidator(m_invalidWord
);
180 virtual bool Validate(wxWindow
* WXUNUSED(parent
))
182 wxTextCtrl
* tc
= wxDynamicCast(GetWindow(), wxTextCtrl
);
183 wxCHECK_MSG(tc
, true, wxT("validator window must be wxTextCtrl"));
185 wxString val
= tc
->GetValue();
187 if ( val
.find(m_invalidWord
) == wxString::npos
)
190 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord
.c_str()),
191 wxT("Validation Failure"));
197 wxString m_invalidWord
;
200 #endif // wxUSE_VALIDATORS
202 // -----------------------------------------------------------------------
204 // -----------------------------------------------------------------------
206 // See propgridsample.h for wxVector3f class
208 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f
)
210 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty
,wxPGProperty
,
211 wxVector3f
,const wxVector3f
&,TextCtrl
)
214 wxVectorProperty::wxVectorProperty( const wxString
& label
,
215 const wxString
& name
,
216 const wxVector3f
& value
)
217 : wxPGProperty(label
,name
)
219 SetValue( WXVARIANT(value
) );
220 AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL
,value
.x
) );
221 AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL
,value
.y
) );
222 AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL
,value
.z
) );
225 wxVectorProperty::~wxVectorProperty() { }
227 void wxVectorProperty::RefreshChildren()
229 if ( !GetChildCount() ) return;
230 const wxVector3f
& vector
= wxVector3fRefFromVariant(m_value
);
231 Item(0)->SetValue( vector
.x
);
232 Item(1)->SetValue( vector
.y
);
233 Item(2)->SetValue( vector
.z
);
236 wxVariant
wxVectorProperty::ChildChanged( wxVariant
& thisValue
,
238 wxVariant
& childValue
) const
242 switch ( childIndex
)
244 case 0: vector
.x
= childValue
.GetDouble(); break;
245 case 1: vector
.y
= childValue
.GetDouble(); break;
246 case 2: vector
.z
= childValue
.GetDouble(); break;
248 wxVariant newVariant
;
249 newVariant
<< vector
;
254 // -----------------------------------------------------------------------
255 // wxTriangleProperty
256 // -----------------------------------------------------------------------
258 // See propgridsample.h for wxTriangle class
260 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle
)
262 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty
,wxPGProperty
,
263 wxTriangle
,const wxTriangle
&,TextCtrl
)
266 wxTriangleProperty::wxTriangleProperty( const wxString
& label
,
267 const wxString
& name
,
268 const wxTriangle
& value
)
269 : wxPGProperty(label
,name
)
271 SetValue( WXVARIANT(value
) );
272 AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL
,value
.a
) );
273 AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL
,value
.b
) );
274 AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL
,value
.c
) );
277 wxTriangleProperty::~wxTriangleProperty() { }
279 void wxTriangleProperty::RefreshChildren()
281 if ( !GetChildCount() ) return;
282 const wxTriangle
& triangle
= wxTriangleRefFromVariant(m_value
);
283 Item(0)->SetValue( WXVARIANT(triangle
.a
) );
284 Item(1)->SetValue( WXVARIANT(triangle
.b
) );
285 Item(2)->SetValue( WXVARIANT(triangle
.c
) );
288 wxVariant
wxTriangleProperty::ChildChanged( wxVariant
& thisValue
,
290 wxVariant
& childValue
) const
293 triangle
<< thisValue
;
294 const wxVector3f
& vector
= wxVector3fRefFromVariant(childValue
);
295 switch ( childIndex
)
297 case 0: triangle
.a
= vector
; break;
298 case 1: triangle
.b
= vector
; break;
299 case 2: triangle
.c
= vector
; break;
301 wxVariant newVariant
;
302 newVariant
<< triangle
;
307 // -----------------------------------------------------------------------
308 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
309 // -----------------------------------------------------------------------
311 class wxSingleChoiceDialogAdapter
: public wxPGEditorDialogAdapter
315 wxSingleChoiceDialogAdapter( const wxPGChoices
& choices
)
316 : wxPGEditorDialogAdapter(), m_choices(choices
)
320 virtual bool DoShowDialog( wxPropertyGrid
* WXUNUSED(propGrid
),
321 wxPGProperty
* WXUNUSED(property
) )
323 wxString s
= ::wxGetSingleChoice(wxT("Message"),
325 m_choices
.GetLabels());
336 const wxPGChoices
& m_choices
;
340 class SingleChoiceProperty
: public wxStringProperty
344 SingleChoiceProperty( const wxString
& label
,
345 const wxString
& name
= wxPG_LABEL
,
346 const wxString
& value
= wxEmptyString
)
347 : wxStringProperty(label
, name
, value
)
350 m_choices
.Add(wxT("Cat"));
351 m_choices
.Add(wxT("Dog"));
352 m_choices
.Add(wxT("Gibbon"));
353 m_choices
.Add(wxT("Otter"));
356 // Set editor to have button
357 virtual const wxPGEditor
* DoGetEditorClass() const
359 return wxPGEditor_TextCtrlAndButton
;
362 // Set what happens on button click
363 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const
365 return new wxSingleChoiceDialogAdapter(m_choices
);
369 wxPGChoices m_choices
;
372 // -----------------------------------------------------------------------
374 // -----------------------------------------------------------------------
422 ID_SETSPINCTRLEDITOR
,
427 ID_ENABLECOMMONVALUES
,
432 ID_ENABLELABELEDITING
,
440 // -----------------------------------------------------------------------
442 // -----------------------------------------------------------------------
444 BEGIN_EVENT_TABLE(FormMain
, wxFrame
)
445 EVT_IDLE(FormMain::OnIdle
)
446 EVT_MOVE(FormMain::OnMove
)
447 EVT_SIZE(FormMain::OnResize
)
449 // This occurs when a property is selected
450 EVT_PG_SELECTED( PGID
, FormMain::OnPropertyGridSelect
)
451 // This occurs when a property value changes
452 EVT_PG_CHANGED( PGID
, FormMain::OnPropertyGridChange
)
453 // This occurs just prior a property value is changed
454 EVT_PG_CHANGING( PGID
, FormMain::OnPropertyGridChanging
)
455 // This occurs when a mouse moves over another property
456 EVT_PG_HIGHLIGHTED( PGID
, FormMain::OnPropertyGridHighlight
)
457 // This occurs when mouse is right-clicked.
458 EVT_PG_RIGHT_CLICK( PGID
, FormMain::OnPropertyGridItemRightClick
)
459 // This occurs when mouse is double-clicked.
460 EVT_PG_DOUBLE_CLICK( PGID
, FormMain::OnPropertyGridItemDoubleClick
)
461 // This occurs when propgridmanager's page changes.
462 EVT_PG_PAGE_CHANGED( PGID
, FormMain::OnPropertyGridPageChange
)
463 // This occurs when user starts editing a property label
464 EVT_PG_LABEL_EDIT_BEGIN( PGID
,
465 FormMain::OnPropertyGridLabelEditBegin
)
466 // This occurs when user stops editing a property label
467 EVT_PG_LABEL_EDIT_ENDING( PGID
,
468 FormMain::OnPropertyGridLabelEditEnding
)
469 // This occurs when property's editor button (if any) is clicked.
470 EVT_BUTTON( PGID
, FormMain::OnPropertyGridButtonClick
)
472 EVT_PG_ITEM_COLLAPSED( PGID
, FormMain::OnPropertyGridItemCollapse
)
473 EVT_PG_ITEM_EXPANDED( PGID
, FormMain::OnPropertyGridItemExpand
)
475 EVT_PG_COL_BEGIN_DRAG( PGID
, FormMain::OnPropertyGridColBeginDrag
)
476 EVT_PG_COL_DRAGGING( PGID
, FormMain::OnPropertyGridColDragging
)
477 EVT_PG_COL_END_DRAG( PGID
, FormMain::OnPropertyGridColEndDrag
)
479 EVT_TEXT( PGID
, FormMain::OnPropertyGridTextUpdate
)
482 // Rest of the events are not property grid specific
483 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent
)
484 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent
)
486 EVT_MENU( ID_APPENDPROP
, FormMain::OnAppendPropClick
)
487 EVT_MENU( ID_APPENDCAT
, FormMain::OnAppendCatClick
)
488 EVT_MENU( ID_INSERTPROP
, FormMain::OnInsertPropClick
)
489 EVT_MENU( ID_INSERTCAT
, FormMain::OnInsertCatClick
)
490 EVT_MENU( ID_DELETE
, FormMain::OnDelPropClick
)
491 EVT_MENU( ID_DELETER
, FormMain::OnDelPropRClick
)
492 EVT_MENU( ID_UNSPECIFY
, FormMain::OnMisc
)
493 EVT_MENU( ID_DELETEALL
, FormMain::OnClearClick
)
494 EVT_MENU( ID_ENABLE
, FormMain::OnEnableDisable
)
495 EVT_MENU( ID_SETREADONLY
, FormMain::OnSetReadOnly
)
496 EVT_MENU( ID_HIDE
, FormMain::OnHide
)
498 EVT_MENU( ID_ITERATE1
, FormMain::OnIterate1Click
)
499 EVT_MENU( ID_ITERATE2
, FormMain::OnIterate2Click
)
500 EVT_MENU( ID_ITERATE3
, FormMain::OnIterate3Click
)
501 EVT_MENU( ID_ITERATE4
, FormMain::OnIterate4Click
)
502 EVT_MENU( ID_ONEXTENDEDKEYNAV
, FormMain::OnExtendedKeyNav
)
503 EVT_MENU( ID_SETBGCOLOUR
, FormMain::OnSetBackgroundColour
)
504 EVT_MENU( ID_SETBGCOLOURRECUR
, FormMain::OnSetBackgroundColour
)
505 EVT_MENU( ID_CLEARMODIF
, FormMain::OnClearModifyStatusClick
)
506 EVT_MENU( ID_FREEZE
, FormMain::OnFreezeClick
)
507 EVT_MENU( ID_ENABLELABELEDITING
, FormMain::OnEnableLabelEditing
)
508 EVT_MENU( ID_SHOWHEADER
, FormMain::OnShowHeader
)
509 EVT_MENU( ID_DUMPLIST
, FormMain::OnDumpList
)
511 EVT_MENU( ID_COLOURSCHEME1
, FormMain::OnColourScheme
)
512 EVT_MENU( ID_COLOURSCHEME2
, FormMain::OnColourScheme
)
513 EVT_MENU( ID_COLOURSCHEME3
, FormMain::OnColourScheme
)
514 EVT_MENU( ID_COLOURSCHEME4
, FormMain::OnColourScheme
)
516 EVT_MENU( ID_ABOUT
, FormMain::OnAbout
)
517 EVT_MENU( ID_QUIT
, FormMain::OnCloseClick
)
519 EVT_MENU( ID_CATCOLOURS
, FormMain::OnCatColours
)
520 EVT_MENU( ID_SETCOLUMNS
, FormMain::OnSetColumns
)
521 EVT_MENU( ID_TESTXRC
, FormMain::OnTestXRC
)
522 EVT_MENU( ID_ENABLECOMMONVALUES
, FormMain::OnEnableCommonValues
)
523 EVT_MENU( ID_SELECTSTYLE
, FormMain::OnSelectStyle
)
525 EVT_MENU( ID_STATICLAYOUT
, FormMain::OnMisc
)
526 EVT_MENU( ID_COLLAPSE
, FormMain::OnMisc
)
527 EVT_MENU( ID_COLLAPSEALL
, FormMain::OnMisc
)
529 EVT_MENU( ID_POPULATE1
, FormMain::OnPopulateClick
)
530 EVT_MENU( ID_POPULATE2
, FormMain::OnPopulateClick
)
532 EVT_MENU( ID_GETVALUES
, FormMain::OnMisc
)
533 EVT_MENU( ID_SETVALUES
, FormMain::OnMisc
)
534 EVT_MENU( ID_SETVALUES2
, FormMain::OnMisc
)
536 EVT_MENU( ID_FITCOLUMNS
, FormMain::OnFitColumnsClick
)
538 EVT_MENU( ID_CHANGEFLAGSITEMS
, FormMain::OnChangeFlagsPropItemsClick
)
540 EVT_MENU( ID_RUNTESTFULL
, FormMain::OnMisc
)
541 EVT_MENU( ID_RUNTESTPARTIAL
, FormMain::OnMisc
)
543 EVT_MENU( ID_TESTINSERTCHOICE
, FormMain::OnInsertChoice
)
544 EVT_MENU( ID_TESTDELETECHOICE
, FormMain::OnDeleteChoice
)
546 EVT_MENU( ID_INSERTPAGE
, FormMain::OnInsertPage
)
547 EVT_MENU( ID_REMOVEPAGE
, FormMain::OnRemovePage
)
549 EVT_MENU( ID_SAVESTATE
, FormMain::OnSaveState
)
550 EVT_MENU( ID_RESTORESTATE
, FormMain::OnRestoreState
)
552 EVT_MENU( ID_SETSPINCTRLEDITOR
, FormMain::OnSetSpinCtrlEditorClick
)
553 EVT_MENU( ID_TESTREPLACE
, FormMain::OnTestReplaceClick
)
554 EVT_MENU( ID_SETPROPERTYVALUE
, FormMain::OnSetPropertyValue
)
556 EVT_MENU( ID_RUNMINIMAL
, FormMain::OnRunMinimalClick
)
558 EVT_CONTEXT_MENU( FormMain::OnContextMenu
)
559 EVT_BUTTON(ID_SHOWPOPUP
, FormMain::OnShowPopup
)
562 // -----------------------------------------------------------------------
564 void FormMain::OnMove( wxMoveEvent
& event
)
566 if ( !m_pPropGridManager
)
568 // this check is here so the frame layout can be tested
569 // without creating propertygrid
574 // Update position properties
580 // Must check if properties exist (as they may be deleted).
582 // Using m_pPropGridManager, we can scan all pages automatically.
583 id
= m_pPropGridManager
->GetPropertyByName( wxT("X") );
585 m_pPropGridManager
->SetPropertyValue( id
, x
);
587 id
= m_pPropGridManager
->GetPropertyByName( wxT("Y") );
589 m_pPropGridManager
->SetPropertyValue( id
, y
);
591 id
= m_pPropGridManager
->GetPropertyByName( wxT("Position") );
593 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxPoint(x
,y
)) );
595 // Should always call event.Skip() in frame's MoveEvent handler
599 // -----------------------------------------------------------------------
601 void FormMain::OnResize( wxSizeEvent
& event
)
603 if ( !m_pPropGridManager
)
605 // this check is here so the frame layout can be tested
606 // without creating propertygrid
611 // Update size properties
618 // Must check if properties exist (as they may be deleted).
620 // Using m_pPropGridManager, we can scan all pages automatically.
621 p
= m_pPropGridManager
->GetPropertyByName( wxT("Width") );
622 if ( p
&& !p
->IsValueUnspecified() )
623 m_pPropGridManager
->SetPropertyValue( p
, w
);
625 p
= m_pPropGridManager
->GetPropertyByName( wxT("Height") );
626 if ( p
&& !p
->IsValueUnspecified() )
627 m_pPropGridManager
->SetPropertyValue( p
, h
);
629 id
= m_pPropGridManager
->GetPropertyByName ( wxT("Size") );
631 m_pPropGridManager
->SetPropertyValue( id
, WXVARIANT(wxSize(w
,h
)) );
633 // Should always call event.Skip() in frame's SizeEvent handler
637 // -----------------------------------------------------------------------
639 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent
& event
)
641 wxPGProperty
* p
= event
.GetProperty();
643 if ( p
->GetName() == wxT("Font") )
646 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
647 p
->GetName().c_str(),event
.GetValue().GetType().c_str()),
648 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO
, m_pPropGridManager
);
652 wxASSERT(event
.CanVeto());
656 // Since we ask a question, it is better if we omit any validation
657 // failure behaviour.
658 event
.SetValidationFailureBehavior(0);
664 // Note how we use three types of value getting in this method:
665 // A) event.GetPropertyValueAsXXX
666 // B) event.GetPropertValue, and then variant's GetXXX
667 // C) grid's GetPropertyValueAsXXX(id)
669 void FormMain::OnPropertyGridChange( wxPropertyGridEvent
& event
)
671 wxPGProperty
* property
= event
.GetProperty();
673 const wxString
& name
= property
->GetName();
675 // Properties store values internally as wxVariants, but it is preferred
676 // to use the more modern wxAny at the interface level
677 wxAny value
= property
->GetValue();
679 // Don't handle 'unspecified' values
680 if ( value
.IsNull() )
684 // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
685 // macro is used. Unless you want to support this old
686 // compiler in your own code, you can use the more
687 // nicer form value.As<FOO>() instead of
688 // wxANY_AS(value, FOO).
691 // Some settings are disabled outside Windows platform
692 if ( name
== wxT("X") )
693 SetSize( wxANY_AS(value
, int), -1, -1, -1, wxSIZE_USE_EXISTING
);
694 else if ( name
== wxT("Y") )
695 // wxPGVariantToInt is safe long int value getter
696 SetSize ( -1, wxANY_AS(value
, int), -1, -1, wxSIZE_USE_EXISTING
);
697 else if ( name
== wxT("Width") )
698 SetSize ( -1, -1, wxANY_AS(value
, int), -1, wxSIZE_USE_EXISTING
);
699 else if ( name
== wxT("Height") )
700 SetSize ( -1, -1, -1, wxANY_AS(value
, int), wxSIZE_USE_EXISTING
);
701 else if ( name
== wxT("Label") )
703 SetTitle( wxANY_AS(value
, wxString
) );
705 else if ( name
== wxT("Password") )
707 static int pwdMode
= 0;
709 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
715 if ( name
== wxT("Font") )
717 wxFont font
= wxANY_AS(value
, wxFont
);
718 wxASSERT( font
.IsOk() );
720 m_pPropGridManager
->SetFont( font
);
723 if ( name
== wxT("Margin Colour") )
725 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
726 m_pPropGridManager
->GetGrid()->SetMarginColour( cpv
.m_colour
);
728 else if ( name
== wxT("Cell Colour") )
730 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
731 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( cpv
.m_colour
);
733 else if ( name
== wxT("Line Colour") )
735 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
736 m_pPropGridManager
->GetGrid()->SetLineColour( cpv
.m_colour
);
738 else if ( name
== wxT("Cell Text Colour") )
740 wxColourPropertyValue cpv
= wxANY_AS(value
, wxColourPropertyValue
);
741 m_pPropGridManager
->GetGrid()->SetCellTextColour( cpv
.m_colour
);
745 // -----------------------------------------------------------------------
747 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
749 wxPGProperty
* property
= event
.GetProperty();
752 m_itemEnable
->Enable( TRUE
);
753 if ( property
->IsEnabled() )
754 m_itemEnable
->SetItemLabel( wxT("Disable") );
756 m_itemEnable
->SetItemLabel( wxT("Enable") );
760 m_itemEnable
->Enable( FALSE
);
764 wxPGProperty
* prop
= event
.GetProperty();
765 wxStatusBar
* sb
= GetStatusBar();
768 wxString
text(wxT("Selected: "));
769 text
+= m_pPropGridManager
->GetPropertyLabel( prop
);
770 sb
->SetStatusText ( text
);
775 // -----------------------------------------------------------------------
777 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
780 wxStatusBar
* sb
= GetStatusBar();
781 wxString
text(wxT("Page Changed: "));
782 text
+= m_pPropGridManager
->GetPageName(m_pPropGridManager
->GetSelectedPage());
783 sb
->SetStatusText( text
);
787 // -----------------------------------------------------------------------
789 void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent
& event
)
791 wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
792 event
.GetProperty()->GetLabel().c_str());
795 // -----------------------------------------------------------------------
797 void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent
& event
)
799 wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
800 event
.GetProperty()->GetLabel().c_str());
803 // -----------------------------------------------------------------------
805 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent
& WXUNUSED(event
) )
809 // -----------------------------------------------------------------------
811 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent
& event
)
814 wxPGProperty
* prop
= event
.GetProperty();
815 wxStatusBar
* sb
= GetStatusBar();
818 wxString
text(wxT("Right-clicked: "));
819 text
+= prop
->GetLabel();
820 text
+= wxT(", name=");
821 text
+= m_pPropGridManager
->GetPropertyName(prop
);
822 sb
->SetStatusText( text
);
826 sb
->SetStatusText( wxEmptyString
);
831 // -----------------------------------------------------------------------
833 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent
& event
)
836 wxPGProperty
* prop
= event
.GetProperty();
837 wxStatusBar
* sb
= GetStatusBar();
840 wxString
text(wxT("Double-clicked: "));
841 text
+= prop
->GetLabel();
842 text
+= wxT(", name=");
843 text
+= m_pPropGridManager
->GetPropertyName(prop
);
844 sb
->SetStatusText ( text
);
848 sb
->SetStatusText ( wxEmptyString
);
853 // -----------------------------------------------------------------------
855 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent
& )
858 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
859 wxStatusBar
* sb
= GetStatusBar();
862 wxString
text(wxT("Button clicked: "));
863 text
+= m_pPropGridManager
->GetPropertyLabel(prop
);
864 text
+= wxT(", name=");
865 text
+= m_pPropGridManager
->GetPropertyName(prop
);
866 sb
->SetStatusText( text
);
870 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
875 // -----------------------------------------------------------------------
877 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent
& )
879 wxLogMessage(wxT("Item was Collapsed"));
882 // -----------------------------------------------------------------------
884 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent
& )
886 wxLogMessage(wxT("Item was Expanded"));
889 // -----------------------------------------------------------------------
891 void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent
& event
)
893 if ( m_itemVetoDragging
->IsChecked() )
895 wxLogMessage("Splitter %i resize was vetoed", event
.GetColumn());
900 wxLogMessage("Splitter %i resize began", event
.GetColumn());
904 // -----------------------------------------------------------------------
906 void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent
& event
)
909 // For now, let's not spam the log output
910 //wxLogMessage("Splitter %i is being resized", event.GetColumn());
913 // -----------------------------------------------------------------------
915 void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent
& event
)
917 wxLogMessage("Splitter %i resize ended", event
.GetColumn());
920 // -----------------------------------------------------------------------
923 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent
& event
)
928 // -----------------------------------------------------------------------
930 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent
& WXUNUSED(event
) )
932 // Occurs on wxGTK mostly, but not wxMSW.
935 // -----------------------------------------------------------------------
937 void FormMain::OnLabelTextChange( wxCommandEvent
& WXUNUSED(event
) )
939 // Uncomment following to allow property label modify in real-time
940 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
941 // if ( !p.IsOk() ) return;
942 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
945 // -----------------------------------------------------------------------
947 static const wxChar
* _fs_windowstyle_labels
[] = {
948 wxT("wxSIMPLE_BORDER"),
949 wxT("wxDOUBLE_BORDER"),
950 wxT("wxSUNKEN_BORDER"),
951 wxT("wxRAISED_BORDER"),
953 wxT("wxTRANSPARENT_WINDOW"),
954 wxT("wxTAB_TRAVERSAL"),
955 wxT("wxWANTS_CHARS"),
956 #if wxNO_FULL_REPAINT_ON_RESIZE
957 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
960 wxT("wxALWAYS_SHOW_SB"),
961 wxT("wxCLIP_CHILDREN"),
962 #if wxFULL_REPAINT_ON_RESIZE
963 wxT("wxFULL_REPAINT_ON_RESIZE"),
965 (const wxChar
*) NULL
// terminator is always needed
968 static const long _fs_windowstyle_values
[] = {
974 wxTRANSPARENT_WINDOW
,
977 #if wxNO_FULL_REPAINT_ON_RESIZE
978 wxNO_FULL_REPAINT_ON_RESIZE
,
983 #if wxFULL_REPAINT_ON_RESIZE
984 wxFULL_REPAINT_ON_RESIZE
988 static const wxChar
* _fs_framestyle_labels
[] = {
993 wxT("wxSTAY_ON_TOP"),
994 wxT("wxSYSTEM_MENU"),
995 wxT("wxRESIZE_BORDER"),
996 wxT("wxFRAME_TOOL_WINDOW"),
997 wxT("wxFRAME_NO_TASKBAR"),
998 wxT("wxFRAME_FLOAT_ON_PARENT"),
999 wxT("wxFRAME_SHAPED"),
1000 (const wxChar
*) NULL
1003 static const long _fs_framestyle_values
[] = {
1011 wxFRAME_TOOL_WINDOW
,
1013 wxFRAME_FLOAT_ON_PARENT
,
1017 // -----------------------------------------------------------------------
1019 void FormMain::OnTestXRC(wxCommandEvent
& WXUNUSED(event
))
1021 wxMessageBox(wxT("Sorrt, not yet implemented"));
1024 void FormMain::OnEnableCommonValues(wxCommandEvent
& WXUNUSED(event
))
1026 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
1028 prop
->EnableCommonValue();
1030 wxMessageBox(wxT("First select a property"));
1033 void FormMain::PopulateWithStandardItems ()
1035 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1036 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Standard Items"));
1038 // Append is ideal way to add items to wxPropertyGrid.
1039 pg
->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL
) );
1041 pg
->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL
,GetTitle()) );
1042 pg
->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL
) );
1043 pg
->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1045 pg
->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL
,
1046 pg
->GetGrid()->GetMarginColour()) );
1048 pg
->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
,
1049 pg
->GetGrid()->GetCellBackgroundColour()) );
1050 pg
->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL
,
1051 pg
->GetGrid()->GetCellTextColour()) );
1052 pg
->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL
,
1053 pg
->GetGrid()->GetLineColour()) );
1054 pg
->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL
,
1055 m_combinedFlags
, GetWindowStyle()) );
1057 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1059 pg
->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL
) );
1061 pg
->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1062 pg
->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1064 // Let's demonstrate 'Units' attribute here
1066 // Note that we use many attribute constants instead of strings here
1067 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1068 // Using constant may reduce binary size.
1070 pg
->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL
,480) );
1071 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN
, (long)10 );
1072 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX
, (long)2048 );
1073 pg
->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1075 // Set value to unspecified so that Hint attribute will be demonstrated
1076 pg
->SetPropertyValueUnspecified("Height");
1077 pg
->SetPropertyAttribute("Height", wxPG_ATTR_HINT
,
1078 "Enter new height for window" );
1080 // Difference between hint and help string is that the hint is shown in
1081 // an empty value cell, while help string is shown either in the
1082 // description text box, as a tool tip, or on the status bar.
1083 pg
->SetPropertyHelpString("Height",
1084 "This property uses attributes \"Units\" and \"Hint\"." );
1086 pg
->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL
,640) );
1087 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN
, (long)10 );
1088 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX
, (long)2048 );
1089 pg
->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1091 pg
->SetPropertyValueUnspecified(wxT("Width"));
1092 pg
->SetPropertyAttribute("Width", wxPG_ATTR_HINT
,
1093 "Enter new width for window" );
1094 pg
->SetPropertyHelpString("Width",
1095 "This property uses attributes \"Units\" and \"Hint\"." );
1097 pg
->Append( new wxIntProperty(wxT("X"),wxPG_LABEL
,10) );
1098 pg
->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1099 pg
->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1101 pg
->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL
,10) );
1102 pg
->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS
, wxT("Pixels") );
1103 pg
->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1105 const wxChar
* disabledHelpString
= wxT("This property is simply disabled. In order to have label disabled as well, ")
1106 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1108 pg
->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL
) );
1109 pg
->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL
,::wxGetOsDescription()) );
1111 pg
->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL
,::wxGetUserId()) );
1112 pg
->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL
,::wxGetUserHome()) );
1113 pg
->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL
,::wxGetUserName()) );
1115 // Disable some of them
1116 pg
->DisableProperty( wxT("Operating System") );
1117 pg
->DisableProperty( wxT("User Id") );
1118 pg
->DisableProperty( wxT("User Name") );
1120 pg
->SetPropertyHelpString( wxT("Operating System"), disabledHelpString
);
1121 pg
->SetPropertyHelpString( wxT("User Id"), disabledHelpString
);
1122 pg
->SetPropertyHelpString( wxT("User Name"), disabledHelpString
);
1124 pg
->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL
) );
1126 pg
->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL
) );
1127 pg
->SetPropertyHelpString( wxT("FontDataProperty"),
1128 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1129 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1132 pg
->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL
) );
1133 pg
->SetPropertyHelpString( wxT("DirsProperty"),
1134 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1135 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1136 wxT("with custom action (dir dialog popup) defined.")
1139 wxArrayDouble arrdbl
;
1146 pg
->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
1147 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1148 pg
->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1149 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1150 wxT("It is an example of a custom list editor property.")
1153 pg
->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL
,
1154 wxT("Editing properties will have immediate effect on this window, ")
1155 wxT("and vice versa (atleast in most cases, that is).")
1157 pg
->SetPropertyHelpString( wxT("Information"),
1158 wxT("This property is read-only.") );
1160 pg
->SetPropertyReadOnly( wxT("Information"), true );
1163 // Set test information for cells in columns 3 and 4
1164 // (reserve column 2 for displaying units)
1165 wxPropertyGridIterator it
;
1166 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_FOLDER
);
1168 for ( it
= pg
->GetGrid()->GetIterator();
1172 wxPGProperty
* p
= *it
;
1173 if ( p
->IsCategory() )
1176 pg
->SetPropertyCell( p
, 3, wxT("Cell 3"), bmp
);
1177 pg
->SetPropertyCell( p
, 4, wxT("Cell 4"), wxNullBitmap
, *wxWHITE
, *wxBLACK
);
1181 // -----------------------------------------------------------------------
1183 void FormMain::PopulateWithExamples ()
1185 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1186 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("Examples"));
1190 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1191 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1194 pg
->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL
, 0 ) );
1196 pg
->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl
);
1197 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN
, (long)-10 ); // Use constants instead of string
1198 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX
, (long)16384 ); // for reduced binary size.
1199 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1200 pg
->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
1201 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1203 pg
->SetPropertyHelpString( wxT("SpinCtrl"),
1204 wxT("This is regular wxIntProperty, which editor has been ")
1205 wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
1206 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1207 wxT("needs to be called prior to using it."));
1211 // Add bool property
1212 pg
->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL
, false ) );
1214 // Add bool property with check box
1215 pg
->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL
, false ) );
1216 pg
->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1217 wxPG_BOOL_USE_CHECKBOX
,
1220 pg
->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1221 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1223 prop
= pg
->Append( new wxFloatProperty("FloatProperty",
1226 prop
->SetAttribute("Min", -100.12);
1228 // A string property that can be edited in a separate editor dialog.
1229 pg
->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1230 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1232 // A property that edits a wxArrayString.
1233 wxArrayString example_array
;
1234 example_array
.Add( wxT("String 1"));
1235 example_array
.Add( wxT("String 2"));
1236 example_array
.Add( wxT("String 3"));
1237 pg
->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL
,
1240 // Test adding same category multiple times ( should not actually create a new one )
1241 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1243 // A file selector property. Note that argument between name
1244 // and initial value is wildcard (format same as in wxFileDialog).
1245 prop
= new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1248 prop
->SetAttribute(wxPG_FILE_WILDCARD
,wxT("Text Files (*.txt)|*.txt"));
1249 prop
->SetAttribute(wxPG_FILE_DIALOG_TITLE
,wxT("Custom File Dialog Title"));
1250 prop
->SetAttribute(wxPG_FILE_SHOW_FULL_PATH
,false);
1253 prop
->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH
,wxT("C:\\Windows"));
1254 pg
->SetPropertyValue(prop
,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1258 // An image file property. Arguments are just like for FileProperty, but
1259 // wildcard is missing (it is autogenerated from supported image formats).
1260 // If you really need to override it, create property separately, and call
1261 // its SetWildcard method.
1262 pg
->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL
) );
1265 pid
= pg
->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL
,*wxRED
) );
1266 pg
->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox
);
1267 pg
->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
1268 pg
->SetPropertyHelpString( wxT("ColourProperty"),
1269 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1270 wxT("editor of this property to wxPGEditor_ComboBox)"));
1272 pid
= pg
->Append( new wxColourProperty("ColourPropertyWithAlpha",
1274 wxColour(15, 200, 95, 128)) );
1275 pg
->SetPropertyAttribute("ColourPropertyWithAlpha", "HasAlpha", true);
1276 pg
->SetPropertyHelpString("ColourPropertyWithAlpha",
1277 "Attribute \"HasAlpha\" is set to true for this property.");
1280 // This demonstrates using alternative editor for colour property
1281 // to trigger colour dialog directly from button.
1282 pg
->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL
,*wxGREEN
) );
1285 // wxEnumProperty does not store strings or even list of strings
1286 // ( so that's why they are static in function ).
1287 static const wxChar
* enum_prop_labels
[] = { wxT("One Item"),
1288 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL
};
1290 // this value array would be optional if values matched string indexes
1291 static long enum_prop_values
[] = { 40, 80, 120, 160 };
1293 // note that the initial value (the last argument) is the actual value,
1294 // not index or anything like that. Thus, our value selects "Another Item".
1296 // 0 before value is number of items. If it is 0, like in our example,
1297 // number of items is calculated, and this requires that the string pointer
1298 // array is terminated with NULL.
1299 pg
->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL
,
1300 enum_prop_labels
, enum_prop_values
, 80 ) );
1304 // use basic table from our previous example
1305 // can also set/add wxArrayStrings and wxArrayInts directly.
1306 soc
.Set( enum_prop_labels
, enum_prop_values
);
1309 soc
.Add( wxT("Look, it continues"), 200 );
1310 soc
.Add( wxT("Even More"), 240 );
1311 soc
.Add( wxT("And More"), 280 );
1313 soc
.Add( wxT("True End of the List"), 320 );
1315 // Test custom colours ([] operator of wxPGChoices returns
1316 // references to wxPGChoiceEntry).
1317 soc
[1].SetFgCol(*wxRED
);
1318 soc
[1].SetBgCol(*wxLIGHT_GREY
);
1319 soc
[2].SetFgCol(*wxGREEN
);
1320 soc
[2].SetBgCol(*wxLIGHT_GREY
);
1321 soc
[3].SetFgCol(*wxBLUE
);
1322 soc
[3].SetBgCol(*wxLIGHT_GREY
);
1323 soc
[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER
));
1325 pg
->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1329 pg
->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1331 // Here we only display the original 'soc' choices
1332 pg
->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL
,
1335 // Test Hint attribute in EnumProperty
1336 pg
->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
1338 pg
->SetPropertyHelpString("EnumProperty 3",
1339 "This property uses \"Hint\" attribute.");
1341 // 'soc' plus one exclusive extra choice "4th only"
1342 pg
->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL
,
1344 pg
->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
1346 pg
->SetPropertyHelpString(wxT("EnumProperty 4"),
1347 wxT("Should have one extra item when compared to EnumProperty 3"));
1349 // Password property example.
1350 pg
->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL
, wxT("password")) );
1351 pg
->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD
, true );
1352 pg
->SetPropertyHelpString( wxT("Password"),
1353 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1355 // String editor with dir selector button. Uses wxEmptyString as name, which
1356 // is allowed (naturally, in this case property cannot be accessed by name).
1357 pg
->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL
, ::wxGetUserHome()) );
1358 pg
->SetPropertyAttribute( wxT("DirProperty"),
1359 wxPG_DIR_DIALOG_MESSAGE
,
1360 wxT("This is a custom dir dialog message") );
1362 // Add string property - first arg is label, second name, and third initial value
1363 pg
->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL
) );
1364 pg
->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1365 pg
->SetPropertyHelpString( wxT("StringProperty"),
1366 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1368 // Set value after limiting so that it will be applied
1369 pg
->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1372 // Demonstrate "AutoComplete" attribute
1373 pg
->Append( new wxStringProperty( "StringProperty AutoComplete",
1376 wxArrayString autoCompleteStrings
;
1377 autoCompleteStrings
.Add("One choice");
1378 autoCompleteStrings
.Add("Another choice");
1379 autoCompleteStrings
.Add("Another choice, yeah");
1380 autoCompleteStrings
.Add("Yet another choice");
1381 autoCompleteStrings
.Add("Yet another choice, bear with me");
1382 pg
->SetPropertyAttribute( "StringProperty AutoComplete",
1384 autoCompleteStrings
);
1386 pg
->SetPropertyHelpString( "StringProperty AutoComplete",
1387 "AutoComplete attribute has been set for this property "
1388 "(try writing something beginning with 'a', 'o' or 'y').");
1390 // Add string property with arbitrarily wide bitmap in front of it. We
1391 // intentionally lower-than-typical row height here so that the ugly
1392 // scaling code wont't be run.
1393 pg
->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
1395 wxT("Test Text")) );
1396 wxBitmap
myTestBitmap(60, 15, 32);
1398 mdc
.SelectObject(myTestBitmap
);
1400 mdc
.SetPen(*wxBLACK
);
1401 mdc
.DrawLine(0, 0, 60, 15);
1402 mdc
.SelectObject(wxNullBitmap
);
1403 pg
->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap
);
1406 // this value array would be optional if values matched string indexes
1407 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1409 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1410 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1413 // Multi choice dialog.
1414 wxArrayString tchoices
;
1415 tchoices
.Add(wxT("Cabbage"));
1416 tchoices
.Add(wxT("Carrot"));
1417 tchoices
.Add(wxT("Onion"));
1418 tchoices
.Add(wxT("Potato"));
1419 tchoices
.Add(wxT("Strawberry"));
1421 wxArrayString tchoicesValues
;
1422 tchoicesValues
.Add(wxT("Carrot"));
1423 tchoicesValues
.Add(wxT("Potato"));
1425 pg
->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL
, tchoices
) );
1427 pg
->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL
,
1428 tchoices
, tchoicesValues
) );
1429 pg
->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1431 pg
->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1432 pg
->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1435 pg
->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL
, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1436 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX
, wxPG_PREFIX_NONE
);
1437 pg
->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE
, wxPG_BASE_HEX
);
1438 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1439 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1442 // wxEditEnumProperty
1444 eech
.Add(wxT("Choice 1"));
1445 eech
.Add(wxT("Choice 2"));
1446 eech
.Add(wxT("Choice 3"));
1447 pg
->Append( new wxEditEnumProperty("EditEnumProperty",
1450 "Choice not in the list") );
1452 // Test Hint attribute in EditEnumProperty
1453 pg
->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
1456 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1457 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1461 // wxDateTimeProperty
1462 pg
->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL
, wxDateTime::Now() ) );
1464 #if wxUSE_DATEPICKCTRL
1465 pg
->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE
,
1466 (long)(wxDP_DROPDOWN
|
1470 pg
->SetPropertyHelpString( wxT("DateProperty"),
1471 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
1472 wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
1478 // Add Triangle properties as both wxTriangleProperty and
1479 // a generic parent property (using wxStringProperty).
1481 wxPGProperty
* topId
= pg
->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL
, wxT("<composed>")) );
1483 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1484 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1485 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1486 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1488 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1490 pg
->SetPropertyHelpString( wxT("3D Object"),
1491 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1492 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1494 pid
= pg
->AppendIn( topId
, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1495 pg
->AppendIn( pid
, new wxVectorProperty( wxT("A"), wxPG_LABEL
) );
1496 pg
->AppendIn( pid
, new wxVectorProperty( wxT("B"), wxPG_LABEL
) );
1497 pg
->AppendIn( pid
, new wxVectorProperty( wxT("C"), wxPG_LABEL
) );
1499 pg
->AppendIn( topId
, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1502 // This snippet is a doc sample test
1504 wxPGProperty
* carProp
= pg
->Append(new wxStringProperty(wxT("Car"),
1506 wxT("<composed>")));
1508 pg
->AppendIn(carProp
, new wxStringProperty(wxT("Model"),
1510 wxT("Lamborghini Diablo SV")));
1512 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Engine Size (cc)"),
1516 wxPGProperty
* speedsProp
= pg
->AppendIn(carProp
,
1517 new wxStringProperty(wxT("Speeds"),
1519 wxT("<composed>")));
1521 pg
->AppendIn( speedsProp
, new wxIntProperty(wxT("Max. Speed (mph)"),
1523 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("0-100 mph (sec)"),
1525 pg
->AppendIn( speedsProp
, new wxFloatProperty(wxT("1/4 mile (sec)"),
1528 // This is how child property can be referred to by name
1529 pg
->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1531 pg
->AppendIn(carProp
, new wxIntProperty(wxT("Price ($)"),
1535 pg
->AppendIn(carProp
, new wxBoolProperty(wxT("Convertible"),
1539 // Displayed value of "Car" property is now very close to this:
1540 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
1543 // Test wxSampleMultiButtonEditor
1544 pg
->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL
) );
1545 pg
->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor
);
1547 // Test SingleChoiceProperty
1548 pg
->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1552 // Test adding variable height bitmaps in wxPGChoices
1555 bc
.Add(wxT("Wee"), wxBitmap(16, 16));
1556 bc
.Add(wxT("Not so wee"), wxBitmap(32, 32));
1557 bc
.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1559 pg
->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1565 // Test how non-editable composite strings appear
1566 pid
= new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL
, wxT("<composed>"));
1567 pg
->SetPropertyReadOnly(pid
);
1570 // For testing purposes, combine two methods of adding children
1573 pid
->AppendChild( new wxStringProperty(wxT("Latest Release"),
1576 pid
->AppendChild( new wxBoolProperty(wxT("Win API"),
1582 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1583 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL
, true) );
1584 pg
->AppendIn(pid
, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL
, false) );
1585 pg
->AppendIn(pid
, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL
, wxT("2.9.0")) );
1586 pg
->AppendIn(pid
, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL
, true) );
1587 pg
->AppendIn(pid
, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL
, false) );
1588 pg
->AppendIn(pid
, new wxBoolProperty(wxT("QT"), wxPG_LABEL
, false) );
1590 AddTestProperties(pg
);
1593 // -----------------------------------------------------------------------
1595 void FormMain::PopulateWithLibraryConfig ()
1597 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1598 wxPropertyGridPage
* pg
= pgman
->GetPage(wxT("wxWidgets Library Config"));
1600 // Set custom column proportions (here in the sample app we need
1601 // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
1602 // need not to do it in your application).
1603 if ( pgman
->HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
1605 pg
->SetColumnProportion(0, 3);
1606 pg
->SetColumnProportion(1, 1);
1611 wxBitmap bmp
= wxArtProvider::GetBitmap(wxART_REPORT_VIEW
);
1615 wxFont italicFont
= pgman
->GetGrid()->GetCaptionFont();
1616 italicFont
.SetStyle(wxFONTSTYLE_ITALIC
);
1618 wxString italicFontHelp
= "Font of this property's wxPGCell has "
1619 "been modified. Obtain property's cell "
1620 "with wxPGProperty::"
1621 "GetOrCreateCell(column).";
1623 #define ADD_WX_LIB_CONF_GROUP(A) \
1624 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1625 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
1626 cat->GetCell(0).SetFont(italicFont); \
1627 cat->SetHelpString(italicFontHelp);
1629 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1630 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1631 pg->DisableProperty(wxT(#A));
1633 pid
= pg
->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1634 pg
->SetPropertyCell( pid
, 0, wxPG_LABEL
, bmp
);
1636 // Both of following lines would set a label for the second column
1637 pg
->SetPropertyCell( pid
, 1, "Is Enabled" );
1638 pid
->SetValue("Is Enabled");
1640 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1641 ADD_WX_LIB_CONF( wxUSE_GUI
)
1643 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1644 #if defined(WXWIN_COMPATIBILITY_2_2)
1645 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2
)
1647 #if defined(WXWIN_COMPATIBILITY_2_4)
1648 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4
)
1650 #if defined(WXWIN_COMPATIBILITY_2_6)
1651 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6
)
1653 #if defined(WXWIN_COMPATIBILITY_2_8)
1654 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8
)
1656 #ifdef wxFONT_SIZE_COMPATIBILITY
1657 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY
)
1659 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY
)
1661 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1662 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY
)
1664 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY
)
1667 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1668 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT
)
1669 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING
)
1670 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS
)
1671 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS
)
1672 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION
)
1674 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1675 ADD_WX_LIB_CONF( wxUSE_UNICODE
)
1676 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU
)
1678 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1679 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS
)
1680 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI
)
1681 ADD_WX_LIB_CONF( wxUSE_STL
)
1682 ADD_WX_LIB_CONF( wxUSE_LOG
)
1683 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW
)
1684 ADD_WX_LIB_CONF( wxUSE_LOGGUI
)
1685 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG
)
1686 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER
)
1687 ADD_WX_LIB_CONF( wxUSE_THREADS
)
1688 ADD_WX_LIB_CONF( wxUSE_STREAMS
)
1689 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM
)
1691 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1692 ADD_WX_LIB_CONF( wxUSE_LONGLONG
)
1693 ADD_WX_LIB_CONF( wxUSE_FILE
)
1694 ADD_WX_LIB_CONF( wxUSE_FFILE
)
1695 ADD_WX_LIB_CONF( wxUSE_FSVOLUME
)
1696 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER
)
1697 ADD_WX_LIB_CONF( wxUSE_TEXTFILE
)
1698 ADD_WX_LIB_CONF( wxUSE_INTL
)
1699 ADD_WX_LIB_CONF( wxUSE_DATETIME
)
1700 ADD_WX_LIB_CONF( wxUSE_TIMER
)
1701 ADD_WX_LIB_CONF( wxUSE_STOPWATCH
)
1702 ADD_WX_LIB_CONF( wxUSE_CONFIG
)
1703 #ifdef wxUSE_CONFIG_NATIVE
1704 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE
)
1706 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE
)
1708 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER
)
1709 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS
)
1710 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER
)
1711 ADD_WX_LIB_CONF( wxUSE_SOCKETS
)
1712 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM
)
1713 ADD_WX_LIB_CONF( wxUSE_FS_ZIP
)
1714 ADD_WX_LIB_CONF( wxUSE_FS_INET
)
1715 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM
)
1716 ADD_WX_LIB_CONF( wxUSE_ZLIB
)
1717 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE
)
1718 ADD_WX_LIB_CONF( wxUSE_JOYSTICK
)
1719 ADD_WX_LIB_CONF( wxUSE_FONTMAP
)
1720 ADD_WX_LIB_CONF( wxUSE_MIMETYPE
)
1721 ADD_WX_LIB_CONF( wxUSE_PROTOCOL
)
1722 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE
)
1723 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP
)
1724 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP
)
1725 ADD_WX_LIB_CONF( wxUSE_URL
)
1726 #ifdef wxUSE_URL_NATIVE
1727 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE
)
1729 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE
)
1731 ADD_WX_LIB_CONF( wxUSE_REGEX
)
1732 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS
)
1733 ADD_WX_LIB_CONF( wxUSE_SOUND
)
1735 ADD_WX_LIB_CONF( wxUSE_XRC
)
1737 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC
)
1739 ADD_WX_LIB_CONF( wxUSE_XML
)
1741 // Set them to use check box.
1742 pg
->SetPropertyAttribute(pid
,wxPG_BOOL_USE_CHECKBOX
,true,wxPG_RECURSE
);
1747 // Handle events of the third page here.
1748 class wxMyPropertyGridPage
: public wxPropertyGridPage
1752 // Return false here to indicate unhandled events should be
1753 // propagated to manager's parent, as normal.
1754 virtual bool IsHandlingAllEvents() const { return false; }
1758 virtual wxPGProperty
* DoInsert( wxPGProperty
* parent
,
1760 wxPGProperty
* property
)
1762 return wxPropertyGridPage::DoInsert(parent
,index
,property
);
1765 void OnPropertySelect( wxPropertyGridEvent
& event
);
1766 void OnPropertyChanging( wxPropertyGridEvent
& event
);
1767 void OnPropertyChange( wxPropertyGridEvent
& event
);
1768 void OnPageChange( wxPropertyGridEvent
& event
);
1771 DECLARE_EVENT_TABLE()
1775 BEGIN_EVENT_TABLE(wxMyPropertyGridPage
, wxPropertyGridPage
)
1776 EVT_PG_SELECTED( wxID_ANY
, wxMyPropertyGridPage::OnPropertySelect
)
1777 EVT_PG_CHANGING( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChanging
)
1778 EVT_PG_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPropertyChange
)
1779 EVT_PG_PAGE_CHANGED( wxID_ANY
, wxMyPropertyGridPage::OnPageChange
)
1783 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent
& WXUNUSED(event
) )
1785 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1788 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent
& event
)
1790 wxPGProperty
* p
= event
.GetProperty();
1791 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1792 p
->GetName().c_str(),
1793 p
->GetDisplayedString().c_str());
1796 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent
& event
)
1798 wxPGProperty
* p
= event
.GetProperty();
1799 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1800 p
->GetName().c_str(),
1801 event
.GetValue().GetString().c_str());
1804 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent
& WXUNUSED(event
) )
1806 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1810 class wxPGKeyHandler
: public wxEvtHandler
1814 void OnKeyEvent( wxKeyEvent
& event
)
1816 wxMessageBox(wxString::Format(wxT("%i"),event
.GetKeyCode()));
1820 DECLARE_EVENT_TABLE()
1823 BEGIN_EVENT_TABLE(wxPGKeyHandler
,wxEvtHandler
)
1824 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent
)
1828 // -----------------------------------------------------------------------
1830 void FormMain::InitPanel()
1835 wxWindow
* panel
= new wxPanel(this, wxID_ANY
,
1836 wxPoint(0, 0), wxSize(400, 400),
1841 wxBoxSizer
* topSizer
= new wxBoxSizer ( wxVERTICAL
);
1843 m_topSizer
= topSizer
;
1846 void FormMain::FinalizePanel( bool wasCreated
)
1848 // Button for tab traversal testing
1849 m_topSizer
->Add( new wxButton(m_panel
, wxID_ANY
,
1850 wxS("Should be able to move here with Tab")),
1852 m_topSizer
->Add( new wxButton(m_panel
, ID_SHOWPOPUP
,
1856 m_panel
->SetSizer( m_topSizer
);
1857 m_topSizer
->SetSizeHints( m_panel
);
1859 wxBoxSizer
* panelSizer
= new wxBoxSizer( wxHORIZONTAL
);
1860 panelSizer
->Add( m_panel
, 1, wxEXPAND
|wxFIXED_MINSIZE
);
1862 SetSizer( panelSizer
);
1863 panelSizer
->SetSizeHints( this );
1866 FinalizeFramePosition();
1869 void FormMain::PopulateGrid()
1871 wxPropertyGridManager
* pgman
= m_pPropGridManager
;
1872 pgman
->AddPage(wxT("Standard Items"));
1874 PopulateWithStandardItems();
1876 pgman
->AddPage(wxT("wxWidgets Library Config"));
1878 PopulateWithLibraryConfig();
1880 wxPropertyGridPage
* myPage
= new wxMyPropertyGridPage();
1881 myPage
->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL
, 12345678 ) );
1883 // Use wxMyPropertyGridPage (see above) to test the
1884 // custom wxPropertyGridPage feature.
1885 pgman
->AddPage(wxT("Examples"),wxNullBitmap
,myPage
);
1887 PopulateWithExamples();
1890 void FormMain::CreateGrid( int style
, int extraStyle
)
1893 // This function (re)creates the property grid in our sample
1897 style
= // default style
1898 wxPG_BOLD_MODIFIED
|
1899 wxPG_SPLITTER_AUTO_CENTER
|
1901 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1903 //wxPG_HIDE_CATEGORIES |
1904 //wxPG_LIMITED_EDITING |
1908 if ( extraStyle
== -1 )
1909 // default extra style
1910 extraStyle
= wxPG_EX_MODE_BUTTONS
|
1911 wxPG_EX_MULTIPLE_SELECTION
;
1912 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1913 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1914 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1915 //| wxPG_EX_HELP_AS_TOOLTIPS
1917 bool wasCreated
= m_panel
? false : true;
1922 // This shows how to combine two static choice descriptors
1923 m_combinedFlags
.Add( _fs_windowstyle_labels
, _fs_windowstyle_values
);
1924 m_combinedFlags
.Add( _fs_framestyle_labels
, _fs_framestyle_values
);
1926 wxPropertyGridManager
* pgman
= m_pPropGridManager
=
1927 new wxPropertyGridManager(m_panel
,
1928 // Don't change this into wxID_ANY in the sample, or the
1929 // event handling will obviously be broken.
1932 wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
1933 // But calling SetInitialSize in manager changes the code
1934 // order to the grid gets created immediately, before SetExtraStyle
1938 m_propGrid
= pgman
->GetGrid();
1940 pgman
->SetExtraStyle(extraStyle
);
1942 // This is the default validation failure behaviour
1943 m_pPropGridManager
->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL
|
1944 wxPG_VFB_SHOW_MESSAGEBOX
);
1946 m_pPropGridManager
->GetGrid()->SetVerticalSpacing( 2 );
1949 // Set somewhat different unspecified value appearance
1951 cell
.SetText("Unspecified");
1952 cell
.SetFgCol(*wxLIGHT_GREY
);
1953 m_propGrid
->SetUnspecifiedValueAppearance(cell
);
1957 // Change some attributes in all properties
1958 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
1959 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
1961 //m_pPropGridManager->SetSplitterLeft(true);
1962 //m_pPropGridManager->SetSplitterPosition(137);
1965 // This would setup event handling without event table entries
1966 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
1967 wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
1968 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
1969 wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
1972 m_topSizer
->Add( m_pPropGridManager
, 1, wxEXPAND
);
1974 FinalizePanel(wasCreated
);
1977 // -----------------------------------------------------------------------
1979 FormMain::FormMain(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
1980 wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
1981 (wxMINIMIZE_BOX
|wxMAXIMIZE_BOX
|wxRESIZE_BORDER
|wxSYSTEM_MENU
|wxCAPTION
|
1982 wxTAB_TRAVERSAL
|wxCLOSE_BOX
|wxNO_FULL_REPAINT_ON_RESIZE
) )
1984 SetIcon(wxICON(sample
));
1990 // we need this in order to allow the about menu relocation, since ABOUT is
1991 // not the default id of the about menu
1992 wxApp::s_macAboutMenuItemId
= ID_ABOUT
;
1996 // This is here to really test the wxImageFileProperty.
1997 wxInitAllImageHandlers();
2000 // Register all editors (SpinCtrl etc.)
2001 m_pPropGridManager
->RegisterAdditionalEditors();
2003 // Register our sample custom editors
2004 m_pSampleMultiButtonEditor
=
2005 wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
2007 CreateGrid( // style
2008 wxPG_BOLD_MODIFIED
|
2009 wxPG_SPLITTER_AUTO_CENTER
|
2011 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
2013 //wxPG_HIDE_CATEGORIES |
2014 //wxPG_LIMITED_EDITING |
2018 wxPG_EX_MODE_BUTTONS
|
2019 wxPG_EX_MULTIPLE_SELECTION
2020 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2021 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2022 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2023 //| wxPG_EX_HELP_AS_TOOLTIPS
2028 wxMenu
*menuFile
= new wxMenu(wxEmptyString
, wxMENU_TEAROFF
);
2029 wxMenu
*menuTry
= new wxMenu
;
2030 wxMenu
*menuTools1
= new wxMenu
;
2031 wxMenu
*menuTools2
= new wxMenu
;
2032 wxMenu
*menuHelp
= new wxMenu
;
2034 menuHelp
->Append(ID_ABOUT
, wxT("&About"), wxT("Show about dialog") );
2036 menuTools1
->Append(ID_APPENDPROP
, wxT("Append New Property") );
2037 menuTools1
->Append(ID_APPENDCAT
, wxT("Append New Category\tCtrl-S") );
2038 menuTools1
->AppendSeparator();
2039 menuTools1
->Append(ID_INSERTPROP
, wxT("Insert New Property\tCtrl-Q") );
2040 menuTools1
->Append(ID_INSERTCAT
, wxT("Insert New Category\tCtrl-W") );
2041 menuTools1
->AppendSeparator();
2042 menuTools1
->Append(ID_DELETE
, wxT("Delete Selected") );
2043 menuTools1
->Append(ID_DELETER
, wxT("Delete Random") );
2044 menuTools1
->Append(ID_DELETEALL
, wxT("Delete All") );
2045 menuTools1
->AppendSeparator();
2046 menuTools1
->Append(ID_SETBGCOLOUR
, wxT("Set Bg Colour") );
2047 menuTools1
->Append(ID_SETBGCOLOURRECUR
, wxT("Set Bg Colour (Recursively)") );
2048 menuTools1
->Append(ID_UNSPECIFY
, "Set Value to Unspecified");
2049 menuTools1
->AppendSeparator();
2050 m_itemEnable
= menuTools1
->Append(ID_ENABLE
, wxT("Enable"),
2051 wxT("Toggles item's enabled state.") );
2052 m_itemEnable
->Enable( FALSE
);
2053 menuTools1
->Append(ID_HIDE
, "Hide", "Hides a property" );
2054 menuTools1
->Append(ID_SETREADONLY
, "Set as Read-Only",
2055 "Set property as read-only" );
2057 menuTools2
->Append(ID_ITERATE1
, wxT("Iterate Over Properties") );
2058 menuTools2
->Append(ID_ITERATE2
, wxT("Iterate Over Visible Items") );
2059 menuTools2
->Append(ID_ITERATE3
, wxT("Reverse Iterate Over Properties") );
2060 menuTools2
->Append(ID_ITERATE4
, wxT("Iterate Over Categories") );
2061 menuTools2
->AppendSeparator();
2062 menuTools2
->Append(ID_ONEXTENDEDKEYNAV
, "Extend Keyboard Navigation",
2063 "This will set Enter to navigate to next property, "
2064 "and allows arrow keys to navigate even when in "
2066 menuTools2
->AppendSeparator();
2067 menuTools2
->Append(ID_SETPROPERTYVALUE
, wxT("Set Property Value") );
2068 menuTools2
->Append(ID_CLEARMODIF
, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2069 menuTools2
->AppendSeparator();
2070 m_itemFreeze
= menuTools2
->AppendCheckItem(ID_FREEZE
, wxT("Freeze"),
2071 wxT("Disables painting, auto-sorting, etc.") );
2072 menuTools2
->AppendSeparator();
2073 menuTools2
->Append(ID_DUMPLIST
, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2074 menuTools2
->AppendSeparator();
2075 menuTools2
->Append(ID_GETVALUES
, wxT("Get Property Values"), wxT("Stores all property values.") );
2076 menuTools2
->Append(ID_SETVALUES
, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2077 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).") );
2078 menuTools2
->AppendSeparator();
2079 menuTools2
->Append(ID_SAVESTATE
, wxT("Save Editable State") );
2080 menuTools2
->Append(ID_RESTORESTATE
, wxT("Restore Editable State") );
2081 menuTools2
->AppendSeparator();
2082 menuTools2
->Append(ID_ENABLECOMMONVALUES
, wxT("Enable Common Value"),
2083 wxT("Enable values that are common to all properties, for selected property."));
2084 menuTools2
->AppendSeparator();
2085 menuTools2
->Append(ID_COLLAPSE
, wxT("Collapse Selected") );
2086 menuTools2
->Append(ID_COLLAPSEALL
, wxT("Collapse All") );
2087 menuTools2
->AppendSeparator();
2088 menuTools2
->Append(ID_INSERTPAGE
, wxT("Add Page") );
2089 menuTools2
->Append(ID_REMOVEPAGE
, wxT("Remove Page") );
2090 menuTools2
->AppendSeparator();
2091 menuTools2
->Append(ID_FITCOLUMNS
, wxT("Fit Columns") );
2092 m_itemVetoDragging
=
2093 menuTools2
->AppendCheckItem(ID_VETOCOLDRAG
,
2094 "Veto Column Dragging");
2095 menuTools2
->AppendSeparator();
2096 menuTools2
->Append(ID_CHANGEFLAGSITEMS
, wxT("Change Children of FlagsProp") );
2097 menuTools2
->AppendSeparator();
2098 menuTools2
->Append(ID_TESTINSERTCHOICE
, wxT("Test InsertPropertyChoice") );
2099 menuTools2
->Append(ID_TESTDELETECHOICE
, wxT("Test DeletePropertyChoice") );
2100 menuTools2
->AppendSeparator();
2101 menuTools2
->Append(ID_SETSPINCTRLEDITOR
, wxT("Use SpinCtrl Editor") );
2102 menuTools2
->Append(ID_TESTREPLACE
, wxT("Test ReplaceProperty") );
2104 menuTry
->Append(ID_SELECTSTYLE
, wxT("Set Window Style"),
2105 wxT("Select window style flags used by the grid."));
2106 menuTry
->Append(ID_ENABLELABELEDITING
, "Enable label editing",
2107 "This calls wxPropertyGrid::MakeColumnEditable(0)");
2108 menuTry
->AppendCheckItem(ID_SHOWHEADER
,
2110 "This calls wxPropertyGridManager::ShowHeader()");
2111 menuTry
->AppendSeparator();
2112 menuTry
->AppendRadioItem( ID_COLOURSCHEME1
, wxT("Standard Colour Scheme") );
2113 menuTry
->AppendRadioItem( ID_COLOURSCHEME2
, wxT("White Colour Scheme") );
2114 menuTry
->AppendRadioItem( ID_COLOURSCHEME3
, wxT(".NET Colour Scheme") );
2115 menuTry
->AppendRadioItem( ID_COLOURSCHEME4
, wxT("Cream Colour Scheme") );
2116 menuTry
->AppendSeparator();
2117 m_itemCatColours
= menuTry
->AppendCheckItem(ID_CATCOLOURS
, wxT("Category Specific Colours"),
2118 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2119 menuTry
->AppendSeparator();
2120 menuTry
->AppendCheckItem(ID_STATICLAYOUT
, wxT("Static Layout"),
2121 wxT("Switches between user-modifiedable and static layouts.") );
2122 menuTry
->Append(ID_SETCOLUMNS
, wxT("Set Number of Columns") );
2123 menuTry
->AppendSeparator();
2124 menuTry
->Append(ID_TESTXRC
, wxT("Display XRC sample") );
2125 menuTry
->AppendSeparator();
2126 menuTry
->Append(ID_RUNTESTFULL
, wxT("Run Tests (full)") );
2127 menuTry
->Append(ID_RUNTESTPARTIAL
, wxT("Run Tests (fast)") );
2129 menuFile
->Append(ID_RUNMINIMAL
, wxT("Run Minimal Sample") );
2130 menuFile
->AppendSeparator();
2131 menuFile
->Append(ID_QUIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2133 // Now append the freshly created menu to the menu bar...
2134 wxMenuBar
*menuBar
= new wxMenuBar();
2135 menuBar
->Append(menuFile
, wxT("&File") );
2136 menuBar
->Append(menuTry
, wxT("&Try These!") );
2137 menuBar
->Append(menuTools1
, wxT("&Basic") );
2138 menuBar
->Append(menuTools2
, wxT("&Advanced") );
2139 menuBar
->Append(menuHelp
, wxT("&Help") );
2141 // ... and attach this menu bar to the frame
2142 SetMenuBar(menuBar
);
2145 // create a status bar
2147 SetStatusText(wxEmptyString
);
2148 #endif // wxUSE_STATUSBAR
2150 FinalizeFramePosition();
2153 // Create log window
2154 m_logWindow
= new wxLogWindow(this, "Log Messages", false);
2155 m_logWindow
->GetFrame()->Move(GetPosition().x
+ GetSize().x
+ 10,
2157 m_logWindow
->Show();
2161 void FormMain::FinalizeFramePosition()
2163 wxSize
frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X
)/10)*4,
2164 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
)/10)*8);
2166 if ( frameSize
.x
> 500 )
2175 // Normally, wxPropertyGrid does not check whether item with identical
2176 // label already exists. However, since in this sample we use labels for
2177 // identifying properties, we have to be sure not to generate identical
2180 void GenerateUniquePropertyLabel( wxPropertyGridManager
* pg
, wxString
& baselabel
)
2185 if ( pg
->GetPropertyByLabel( baselabel
) )
2190 newlabel
.Printf(wxT("%s%i"),baselabel
.c_str(),count
);
2191 if ( !pg
->GetPropertyByLabel( newlabel
) ) break;
2197 baselabel
= newlabel
;
2201 // -----------------------------------------------------------------------
2203 void FormMain::OnInsertPropClick( wxCommandEvent
& WXUNUSED(event
) )
2207 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2209 wxMessageBox(wxT("No items to relate - first add some with Append."));
2213 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2216 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2219 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2221 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2223 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2224 id
->GetIndexInParent(),
2225 new wxStringProperty(propLabel
) );
2229 // -----------------------------------------------------------------------
2231 void FormMain::OnAppendPropClick( wxCommandEvent
& WXUNUSED(event
) )
2235 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Property");
2237 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2239 m_pPropGridManager
->Append( new wxStringProperty(propLabel
) );
2241 m_pPropGridManager
->Refresh();
2244 // -----------------------------------------------------------------------
2246 void FormMain::OnClearClick( wxCommandEvent
& WXUNUSED(event
) )
2248 m_pPropGridManager
->GetGrid()->Clear();
2251 // -----------------------------------------------------------------------
2253 void FormMain::OnAppendCatClick( wxCommandEvent
& WXUNUSED(event
) )
2257 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2259 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2261 m_pPropGridManager
->Append( new wxPropertyCategory (propLabel
) );
2263 m_pPropGridManager
->Refresh();
2267 // -----------------------------------------------------------------------
2269 void FormMain::OnInsertCatClick( wxCommandEvent
& WXUNUSED(event
) )
2273 if ( !m_pPropGridManager
->GetGrid()->GetRoot()->GetChildCount() )
2275 wxMessageBox(wxT("No items to relate - first add some with Append."));
2279 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2282 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2286 if ( propLabel
.Len() < 1 ) propLabel
= wxT("Category");
2288 GenerateUniquePropertyLabel( m_pPropGridManager
, propLabel
);
2290 m_pPropGridManager
->Insert( m_pPropGridManager
->GetPropertyParent(id
),
2291 id
->GetIndexInParent(),
2292 new wxPropertyCategory (propLabel
) );
2295 // -----------------------------------------------------------------------
2297 void FormMain::OnDelPropClick( wxCommandEvent
& WXUNUSED(event
) )
2299 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2302 wxMessageBox(wxT("First select a property."));
2306 m_pPropGridManager
->DeleteProperty( id
);
2309 // -----------------------------------------------------------------------
2311 void FormMain::OnDelPropRClick( wxCommandEvent
& WXUNUSED(event
) )
2313 // Delete random property
2314 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetRoot();
2318 if ( !p
->IsCategory() )
2320 m_pPropGridManager
->DeleteProperty( p
);
2324 if ( !p
->GetChildCount() )
2327 int n
= rand() % ((int)p
->GetChildCount());
2333 // -----------------------------------------------------------------------
2335 void FormMain::OnContextMenu( wxContextMenuEvent
& event
)
2337 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2338 event
.GetPosition().x
,event
.GetPosition().y
);
2345 // -----------------------------------------------------------------------
2347 void FormMain::OnCloseClick( wxCommandEvent
& WXUNUSED(event
) )
2349 /*#ifdef __WXDEBUG__
2350 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2351 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2357 // -----------------------------------------------------------------------
2359 int IterateMessage( wxPGProperty
* prop
)
2363 s
.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop
->GetLabel().c_str(),
2364 prop
->GetClassInfo()->GetClassName(), prop
->GetValueType().c_str() );
2366 return wxMessageBox( s
, wxT("Iterating... (press CANCEL to end)"), wxOK
|wxCANCEL
);
2369 // -----------------------------------------------------------------------
2371 void FormMain::OnIterate1Click( wxCommandEvent
& WXUNUSED(event
) )
2373 wxPropertyGridIterator it
;
2375 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2380 wxPGProperty
* p
= *it
;
2381 int res
= IterateMessage( p
);
2382 if ( res
== wxCANCEL
) break;
2386 // -----------------------------------------------------------------------
2388 void FormMain::OnIterate2Click( wxCommandEvent
& WXUNUSED(event
) )
2390 wxPropertyGridIterator it
;
2392 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2393 GetIterator( wxPG_ITERATE_VISIBLE
);
2397 wxPGProperty
* p
= *it
;
2399 int res
= IterateMessage( p
);
2400 if ( res
== wxCANCEL
) break;
2404 // -----------------------------------------------------------------------
2406 void FormMain::OnIterate3Click( wxCommandEvent
& WXUNUSED(event
) )
2408 // iterate over items in reverse order
2409 wxPropertyGridIterator it
;
2411 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2412 GetIterator( wxPG_ITERATE_DEFAULT
, wxBOTTOM
);
2416 wxPGProperty
* p
= *it
;
2418 int res
= IterateMessage( p
);
2419 if ( res
== wxCANCEL
) break;
2423 // -----------------------------------------------------------------------
2425 void FormMain::OnIterate4Click( wxCommandEvent
& WXUNUSED(event
) )
2427 wxPropertyGridIterator it
;
2429 for ( it
= m_pPropGridManager
->GetCurrentPage()->
2430 GetIterator( wxPG_ITERATE_CATEGORIES
);
2434 wxPGProperty
* p
= *it
;
2436 int res
= IterateMessage( p
);
2437 if ( res
== wxCANCEL
) break;
2441 // -----------------------------------------------------------------------
2443 void FormMain::OnExtendedKeyNav( wxCommandEvent
& WXUNUSED(event
) )
2445 // Use AddActionTrigger() and DedicateKey() to set up Enter,
2446 // Up, and Down keys for navigating between properties.
2447 wxPropertyGrid
* propGrid
= m_pPropGridManager
->GetGrid();
2449 propGrid
->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY
,
2451 propGrid
->DedicateKey(WXK_RETURN
);
2453 // Up and Down keys are alredy associated with navigation,
2454 // but we must also prevent them from being eaten by
2456 propGrid
->DedicateKey(WXK_UP
);
2457 propGrid
->DedicateKey(WXK_DOWN
);
2460 // -----------------------------------------------------------------------
2462 void FormMain::OnFitColumnsClick( wxCommandEvent
& WXUNUSED(event
) )
2464 wxPropertyGridPage
* page
= m_pPropGridManager
->GetCurrentPage();
2466 // Remove auto-centering
2467 m_pPropGridManager
->SetWindowStyle( m_pPropGridManager
->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER
);
2469 // Grow manager size just prior fit - otherwise
2470 // column information may be lost.
2471 wxSize oldGridSize
= m_pPropGridManager
->GetGrid()->GetClientSize();
2472 wxSize oldFullSize
= GetSize();
2473 SetSize(1000, oldFullSize
.y
);
2475 wxSize newSz
= page
->FitColumns();
2477 int dx
= oldFullSize
.x
- oldGridSize
.x
;
2478 int dy
= oldFullSize
.y
- oldGridSize
.y
;
2486 // -----------------------------------------------------------------------
2488 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent
& WXUNUSED(event
) )
2490 wxPGProperty
* p
= m_pPropGridManager
->GetPropertyByName(wxT("Window Styles"));
2492 wxPGChoices newChoices
;
2494 newChoices
.Add(wxT("Fast"),0x1);
2495 newChoices
.Add(wxT("Powerful"),0x2);
2496 newChoices
.Add(wxT("Safe"),0x4);
2497 newChoices
.Add(wxT("Sleek"),0x8);
2499 p
->SetChoices(newChoices
);
2502 // -----------------------------------------------------------------------
2504 void FormMain::OnEnableDisable( wxCommandEvent
& )
2506 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2509 wxMessageBox(wxT("First select a property."));
2513 if ( m_pPropGridManager
->IsPropertyEnabled( id
) )
2515 m_pPropGridManager
->DisableProperty ( id
);
2516 m_itemEnable
->SetItemLabel( wxT("Enable") );
2520 m_pPropGridManager
->EnableProperty ( id
);
2521 m_itemEnable
->SetItemLabel( wxT("Disable") );
2525 // -----------------------------------------------------------------------
2527 void FormMain::OnSetReadOnly( wxCommandEvent
& WXUNUSED(event
) )
2529 wxPGProperty
* p
= m_pPropGridManager
->GetGrid()->GetSelection();
2532 wxMessageBox(wxT("First select a property."));
2535 m_pPropGridManager
->SetPropertyReadOnly(p
);
2538 // -----------------------------------------------------------------------
2540 void FormMain::OnHide( wxCommandEvent
& WXUNUSED(event
) )
2542 wxPGProperty
* id
= m_pPropGridManager
->GetGrid()->GetSelection();
2545 wxMessageBox(wxT("First select a property."));
2549 m_pPropGridManager
->HideProperty( id
, true );
2552 // -----------------------------------------------------------------------
2554 #include "wx/colordlg.h"
2557 FormMain::OnSetBackgroundColour( wxCommandEvent
& event
)
2559 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2560 wxPGProperty
* prop
= pg
->GetSelection();
2563 wxMessageBox(wxT("First select a property."));
2567 wxColour col
= ::wxGetColourFromUser(this, *wxWHITE
, "Choose colour");
2571 bool recursively
= (event
.GetId()==ID_SETBGCOLOURRECUR
) ? true : false;
2572 pg
->SetPropertyBackgroundColour(prop
, col
, recursively
);
2576 // -----------------------------------------------------------------------
2578 void FormMain::OnInsertPage( wxCommandEvent
& WXUNUSED(event
) )
2580 m_pPropGridManager
->AddPage(wxT("New Page"));
2583 // -----------------------------------------------------------------------
2585 void FormMain::OnRemovePage( wxCommandEvent
& WXUNUSED(event
) )
2587 m_pPropGridManager
->RemovePage(m_pPropGridManager
->GetSelectedPage());
2590 // -----------------------------------------------------------------------
2592 void FormMain::OnSaveState( wxCommandEvent
& WXUNUSED(event
) )
2594 m_savedState
= m_pPropGridManager
->SaveEditableState();
2595 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState
.c_str());
2598 // -----------------------------------------------------------------------
2600 void FormMain::OnRestoreState( wxCommandEvent
& WXUNUSED(event
) )
2602 m_pPropGridManager
->RestoreEditableState(m_savedState
);
2605 // -----------------------------------------------------------------------
2607 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent
& WXUNUSED(event
) )
2610 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2612 m_pPropGridManager
->SetPropertyEditor( pgId
, wxPGEditor_SpinCtrl
);
2614 wxMessageBox(wxT("First select a property"));
2618 // -----------------------------------------------------------------------
2620 void FormMain::OnTestReplaceClick( wxCommandEvent
& WXUNUSED(event
) )
2622 wxPGProperty
* pgId
= m_pPropGridManager
->GetSelection();
2625 wxPGChoices choices
;
2626 choices
.Add(wxT("Flag 0"),0x0001);
2627 choices
.Add(wxT("Flag 1"),0x0002);
2628 choices
.Add(wxT("Flag 2"),0x0004);
2629 choices
.Add(wxT("Flag 3"),0x0008);
2630 wxPGProperty
* newId
= m_pPropGridManager
->ReplaceProperty( pgId
,
2631 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL
, choices
, 0x0003) );
2632 m_pPropGridManager
->SetPropertyAttribute( newId
,
2633 wxPG_BOOL_USE_CHECKBOX
,
2638 wxMessageBox(wxT("First select a property"));
2641 // -----------------------------------------------------------------------
2643 void FormMain::OnClearModifyStatusClick( wxCommandEvent
& WXUNUSED(event
) )
2645 m_pPropGridManager
->ClearModifiedStatus();
2648 // -----------------------------------------------------------------------
2650 // Freeze check-box checked?
2651 void FormMain::OnFreezeClick( wxCommandEvent
& event
)
2653 if ( !m_pPropGridManager
) return;
2655 if ( event
.IsChecked() )
2657 if ( !m_pPropGridManager
->IsFrozen() )
2659 m_pPropGridManager
->Freeze();
2664 if ( m_pPropGridManager
->IsFrozen() )
2666 m_pPropGridManager
->Thaw();
2667 m_pPropGridManager
->Refresh();
2672 // -----------------------------------------------------------------------
2674 void FormMain::OnEnableLabelEditing( wxCommandEvent
& WXUNUSED(event
) )
2676 m_propGrid
->MakeColumnEditable(0);
2679 // -----------------------------------------------------------------------
2681 void FormMain::OnShowHeader( wxCommandEvent
& event
)
2683 m_pPropGridManager
->ShowHeader(event
.IsChecked());
2684 m_pPropGridManager
->SetColumnTitle(2, _("Units"));
2687 // -----------------------------------------------------------------------
2689 void FormMain::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2692 msg
.Printf( wxT("wxPropertyGrid Sample")
2694 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2708 wxT("Programmed by %s\n\n")
2709 wxT("Using %s\n\n"),
2710 wxT("Jaakko Salli"), wxVERSION_STRING
2713 wxMessageBox(msg
, wxT("About"), wxOK
| wxICON_INFORMATION
, this);
2716 // -----------------------------------------------------------------------
2718 void FormMain::OnColourScheme( wxCommandEvent
& event
)
2720 int id
= event
.GetId();
2721 if ( id
== ID_COLOURSCHEME1
)
2723 m_pPropGridManager
->GetGrid()->ResetColours();
2725 else if ( id
== ID_COLOURSCHEME2
)
2728 wxColour
my_grey_1(212,208,200);
2729 wxColour
my_grey_3(113,111,100);
2730 m_pPropGridManager
->Freeze();
2731 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2732 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2733 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( *wxWHITE
);
2734 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2735 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
); //wxColour(160,160,160)
2736 m_pPropGridManager
->Thaw();
2738 else if ( id
== ID_COLOURSCHEME3
)
2741 wxColour
my_grey_1(212,208,200);
2742 wxColour
my_grey_2(236,233,216);
2743 m_pPropGridManager
->Freeze();
2744 m_pPropGridManager
->GetGrid()->SetMarginColour( my_grey_1
);
2745 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( my_grey_1
);
2746 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2747 m_pPropGridManager
->Thaw();
2749 else if ( id
== ID_COLOURSCHEME4
)
2753 wxColour
my_grey_1(212,208,200);
2754 wxColour
my_grey_2(241,239,226);
2755 wxColour
my_grey_3(113,111,100);
2756 m_pPropGridManager
->Freeze();
2757 m_pPropGridManager
->GetGrid()->SetMarginColour( *wxWHITE
);
2758 m_pPropGridManager
->GetGrid()->SetCaptionBackgroundColour( *wxWHITE
);
2759 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2760 m_pPropGridManager
->GetGrid()->SetCellBackgroundColour( my_grey_2
);
2761 m_pPropGridManager
->GetGrid()->SetCellTextColour( my_grey_3
);
2762 m_pPropGridManager
->GetGrid()->SetLineColour( my_grey_1
);
2763 m_pPropGridManager
->Thaw();
2767 // -----------------------------------------------------------------------
2769 void FormMain::OnCatColours( wxCommandEvent
& event
)
2771 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2772 m_pPropGridManager
->Freeze();
2774 if ( event
.IsChecked() )
2776 // Set custom colours.
2777 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2778 pg
->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2779 pg
->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2780 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2781 pg
->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2782 pg
->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2783 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2784 pg
->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2785 pg
->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2786 pg
->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2787 pg
->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2791 // Revert to original.
2792 pg
->SetPropertyColoursToDefault( wxT("Appearance") );
2793 pg
->SetPropertyColoursToDefault( wxT("PositionCategory") );
2794 pg
->SetPropertyColoursToDefault( wxT("Environment") );
2795 pg
->SetPropertyColoursToDefault( wxT("More Examples") );
2797 m_pPropGridManager
->Thaw();
2798 m_pPropGridManager
->Refresh();
2801 // -----------------------------------------------------------------------
2803 #define ADD_FLAG(FLAG) \
2804 chs.Add(wxT(#FLAG)); \
2806 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2809 void FormMain::OnSelectStyle( wxCommandEvent
& WXUNUSED(event
) )
2818 unsigned int ind
= 0;
2819 int flags
= m_pPropGridManager
->GetWindowStyle();
2820 ADD_FLAG(wxPG_HIDE_CATEGORIES
)
2821 ADD_FLAG(wxPG_AUTO_SORT
)
2822 ADD_FLAG(wxPG_BOLD_MODIFIED
)
2823 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER
)
2824 ADD_FLAG(wxPG_TOOLTIPS
)
2825 ADD_FLAG(wxPG_STATIC_SPLITTER
)
2826 ADD_FLAG(wxPG_HIDE_MARGIN
)
2827 ADD_FLAG(wxPG_LIMITED_EDITING
)
2828 ADD_FLAG(wxPG_TOOLBAR
)
2829 ADD_FLAG(wxPG_DESCRIPTION
)
2830 ADD_FLAG(wxPG_NO_INTERNAL_BORDER
)
2831 wxMultiChoiceDialog
dlg( this, wxT("Select window styles to use"),
2832 wxT("wxPropertyGrid Window Style"), chs
);
2833 dlg
.SetSelections(sel
);
2834 if ( dlg
.ShowModal() == wxID_CANCEL
)
2838 sel
= dlg
.GetSelections();
2839 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2840 flags
|= vls
[sel
[ind
]];
2849 unsigned int ind
= 0;
2850 int flags
= m_pPropGridManager
->GetExtraStyle();
2851 ADD_FLAG(wxPG_EX_INIT_NOCAT
)
2852 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR
)
2853 ADD_FLAG(wxPG_EX_MODE_BUTTONS
)
2854 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS
)
2855 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
2856 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES
)
2857 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES
)
2858 ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS
)
2859 ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION
)
2860 ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING
)
2861 ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER
)
2862 ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR
)
2863 wxMultiChoiceDialog
dlg( this, wxT("Select extra window styles to use"),
2864 wxT("wxPropertyGrid Extra Style"), chs
);
2865 dlg
.SetSelections(sel
);
2866 if ( dlg
.ShowModal() == wxID_CANCEL
)
2870 sel
= dlg
.GetSelections();
2871 for ( ind
= 0; ind
< sel
.size(); ind
++ )
2872 flags
|= vls
[sel
[ind
]];
2877 CreateGrid( style
, extraStyle
);
2879 FinalizeFramePosition();
2882 // -----------------------------------------------------------------------
2884 void FormMain::OnSetColumns( wxCommandEvent
& WXUNUSED(event
) )
2886 long colCount
= ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2887 wxT("Change Columns"),m_pPropGridManager
->GetColumnCount(),
2890 if ( colCount
>= 2 )
2892 m_pPropGridManager
->SetColumnCount(colCount
);
2896 // -----------------------------------------------------------------------
2898 void FormMain::OnSetPropertyValue( wxCommandEvent
& WXUNUSED(event
) )
2900 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2901 wxPGProperty
* selected
= pg
->GetSelection();
2905 wxString value
= ::wxGetTextFromUser( wxT("Enter new value:") );
2906 pg
->SetPropertyValue( selected
, value
);
2910 // -----------------------------------------------------------------------
2912 void FormMain::OnInsertChoice( wxCommandEvent
& WXUNUSED(event
) )
2914 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2916 wxPGProperty
* selected
= pg
->GetSelection();
2917 const wxPGChoices
& choices
= selected
->GetChoices();
2919 // Insert new choice to the center of list
2921 if ( choices
.IsOk() )
2923 int pos
= choices
.GetCount() / 2;
2924 selected
->InsertChoice(wxT("New Choice"), pos
);
2928 ::wxMessageBox(wxT("First select a property with some choices."));
2932 // -----------------------------------------------------------------------
2934 void FormMain::OnDeleteChoice( wxCommandEvent
& WXUNUSED(event
) )
2936 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2938 wxPGProperty
* selected
= pg
->GetSelection();
2939 const wxPGChoices
& choices
= selected
->GetChoices();
2941 // Deletes choice from the center of list
2943 if ( choices
.IsOk() )
2945 int pos
= choices
.GetCount() / 2;
2946 selected
->DeleteChoice(pos
);
2950 ::wxMessageBox(wxT("First select a property with some choices."));
2954 // -----------------------------------------------------------------------
2956 #include <wx/colordlg.h>
2958 void FormMain::OnMisc ( wxCommandEvent
& event
)
2960 int id
= event
.GetId();
2961 if ( id
== ID_STATICLAYOUT
)
2963 long wsf
= m_pPropGridManager
->GetWindowStyleFlag();
2964 if ( event
.IsChecked() ) m_pPropGridManager
->SetWindowStyleFlag( wsf
|wxPG_STATIC_LAYOUT
);
2965 else m_pPropGridManager
->SetWindowStyleFlag( wsf
&~(wxPG_STATIC_LAYOUT
) );
2967 else if ( id
== ID_COLLAPSEALL
)
2970 wxPropertyGrid
* pg
= m_pPropGridManager
->GetGrid();
2972 for ( it
= pg
->GetVIterator( wxPG_ITERATE_ALL
); !it
.AtEnd(); it
.Next() )
2973 it
.GetProperty()->SetExpanded( false );
2977 else if ( id
== ID_GETVALUES
)
2979 m_storedValues
= m_pPropGridManager
->GetGrid()->GetPropertyValues(wxT("Test"),
2980 m_pPropGridManager
->GetGrid()->GetRoot(),
2981 wxPG_KEEP_STRUCTURE
|wxPG_INC_ATTRIBUTES
);
2983 else if ( id
== ID_SETVALUES
)
2985 if ( m_storedValues
.GetType() == wxT("list") )
2987 m_pPropGridManager
->GetGrid()->SetPropertyValues(m_storedValues
);
2990 wxMessageBox(wxT("First use Get Property Values."));
2992 else if ( id
== ID_SETVALUES2
)
2996 list
.Append( wxVariant((long)1234,wxT("VariantLong")) );
2997 list
.Append( wxVariant((bool)TRUE
,wxT("VariantBool")) );
2998 list
.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2999 m_pPropGridManager
->GetGrid()->SetPropertyValues(list
);
3001 else if ( id
== ID_COLLAPSE
)
3003 // Collapses selected.
3004 wxPGProperty
* id
= m_pPropGridManager
->GetSelection();
3007 m_pPropGridManager
->Collapse(id
);
3010 else if ( id
== ID_RUNTESTFULL
)
3012 // Runs a regression test.
3015 else if ( id
== ID_RUNTESTPARTIAL
)
3017 // Runs a regression test.
3020 else if ( id
== ID_UNSPECIFY
)
3022 wxPGProperty
* prop
= m_pPropGridManager
->GetSelection();
3025 m_pPropGridManager
->SetPropertyValueUnspecified(prop
);
3026 prop
->RefreshEditor();
3031 // -----------------------------------------------------------------------
3033 void FormMain::OnPopulateClick( wxCommandEvent
& event
)
3035 int id
= event
.GetId();
3036 m_propGrid
->Clear();
3037 m_propGrid
->Freeze();
3038 if ( id
== ID_POPULATE1
)
3040 PopulateWithStandardItems();
3042 else if ( id
== ID_POPULATE2
)
3044 PopulateWithLibraryConfig();
3049 // -----------------------------------------------------------------------
3051 void DisplayMinimalFrame(wxWindow
* parent
); // in minimal.cpp
3053 void FormMain::OnRunMinimalClick( wxCommandEvent
& WXUNUSED(event
) )
3055 DisplayMinimalFrame(this);
3058 // -----------------------------------------------------------------------
3060 FormMain::~FormMain()
3064 // -----------------------------------------------------------------------
3066 IMPLEMENT_APP(cxApplication
)
3068 bool cxApplication::OnInit()
3071 //Locale.Init(wxLANGUAGE_FINNISH);
3073 FormMain
* frame
= Form1
= new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3077 // Parse command-line
3078 wxApp
& app
= wxGetApp();
3081 wxString s
= app
.argv
[1];
3082 if ( s
== wxT("--run-tests") )
3086 bool testResult
= frame
->RunTests(true);
3096 // -----------------------------------------------------------------------
3098 void FormMain::OnIdle( wxIdleEvent
& event
)
3101 // This code is useful for debugging focus problems
3102 static wxWindow* last_focus = (wxWindow*) NULL;
3104 wxWindow* cur_focus = ::wxWindow::FindFocus();
3106 if ( cur_focus != last_focus )
3108 const wxChar* class_name = wxT("<none>");
3110 class_name = cur_focus->GetClassInfo()->GetClassName();
3111 last_focus = cur_focus;
3112 wxLogDebug( wxT("FOCUSED: %s %X"),
3114 (unsigned int)cur_focus);
3121 // -----------------------------------------------------------------------
3124 wxPGProperty
* GetRealRoot(wxPropertyGrid
*grid
)
3126 wxPGProperty
*property
= grid
->GetRoot();
3127 return property
? grid
->GetFirstChild(property
) : NULL
;
3130 void GetColumnWidths(wxClientDC
&dc
, wxPropertyGrid
*grid
, wxPGProperty
*root
, int width
[3])
3132 wxPropertyGridPageState
*state
= grid
->GetState();
3137 int minWidths
[3] = { state
->GetColumnMinWidth(0),
3138 state
->GetColumnMinWidth(1),
3139 state
->GetColumnMinWidth(2) };
3141 for (ii
= 0; ii
< root
->GetChildCount(); ++ii
)
3143 wxPGProperty
* p
= root
->Item(ii
);
3145 width
[0] = wxMax(width
[0], state
->GetColumnFullWidth(dc
, p
, 0));
3146 width
[1] = wxMax(width
[1], state
->GetColumnFullWidth(dc
, p
, 1));
3147 width
[2] = wxMax(width
[2], state
->GetColumnFullWidth(dc
, p
, 2));
3149 for (ii
= 0; ii
< root
->GetChildCount(); ++ii
)
3151 wxPGProperty
* p
= root
->Item(ii
);
3152 if (p
->IsExpanded())
3155 GetColumnWidths(dc
, grid
, p
, w
);
3156 width
[0] = wxMax(width
[0], w
[0]);
3157 width
[1] = wxMax(width
[1], w
[1]);
3158 width
[2] = wxMax(width
[2], w
[2]);
3162 width
[0] = wxMax(width
[0], minWidths
[0]);
3163 width
[1] = wxMax(width
[1], minWidths
[1]);
3164 width
[2] = wxMax(width
[2], minWidths
[2]);
3167 void GetColumnWidths(wxPropertyGrid
*grid
, wxPGProperty
*root
, int width
[3])
3169 wxClientDC
dc(grid
);
3170 dc
.SetFont(grid
->GetFont());
3171 GetColumnWidths(dc
, grid
, root
, width
);
3174 void SetMinSize(wxPropertyGrid
*grid
)
3176 wxPGProperty
*p
= GetRealRoot(grid
);
3177 wxPGProperty
*first
= grid
->wxPropertyGridInterface::GetFirst(wxPG_ITERATE_ALL
);
3178 wxPGProperty
*last
= grid
->GetLastItem(wxPG_ITERATE_DEFAULT
);
3179 wxRect rect
= grid
->GetPropertyRect(first
, last
);
3180 int height
= rect
.height
+ 2 * grid
->GetVerticalSpacing();
3182 // add some height when the root item is collapsed,
3183 // this is needed to prevent the vertical scroll from showing
3184 if (!grid
->IsPropertyExpanded(p
))
3185 height
+= 2 * grid
->GetVerticalSpacing();
3188 GetColumnWidths(grid
, grid
->GetRoot(), width
);
3189 rect
.width
= width
[0]+width
[1]+width
[2];
3191 int minWidth
= (wxSystemSettings::GetMetric(wxSYS_SCREEN_X
, grid
->GetParent())*3)/2;
3192 int minHeight
= (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
, grid
->GetParent())*3)/2;
3194 wxSize
size(wxMin(minWidth
, rect
.width
+ grid
->GetMarginWidth()), wxMin(minHeight
, height
));
3195 grid
->SetMinSize(size
);
3198 proportions
[0] = static_cast<int>(floor((double)width
[0]/size
.x
*100.0+0.5));
3199 proportions
[1] = static_cast<int>(floor((double)width
[1]/size
.x
*100.0+0.5));
3200 proportions
[2]= wxMax(100 - proportions
[0] - proportions
[1], 0);
3201 grid
->SetColumnProportion(0, proportions
[0]);
3202 grid
->SetColumnProportion(1, proportions
[1]);
3203 grid
->SetColumnProportion(2, proportions
[2]);
3204 grid
->ResetColumnSizes(true);
3207 struct PropertyGridPopup
: wxPopupWindow
3209 wxScrolledWindow
*m_panel
;
3210 wxPropertyGrid
*m_grid
;
3211 wxBoxSizer
*m_sizer
;
3213 PropertyGridPopup(wxWindow
*parent
) : wxPopupWindow(parent
, wxBORDER_NONE
|wxWANTS_CHARS
)
3215 m_panel
= new wxScrolledWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(200, 200));
3216 m_grid
= new wxPropertyGrid(m_panel
, ID_POPUPGRID
, wxDefaultPosition
, wxSize(400,400), wxPG_SPLITTER_AUTO_CENTER
);
3217 m_grid
->SetExtraStyle(wxPG_EX_DISABLE_TLP_TRACKING
/*| wxPG_EX_HELP_AS_TOOLTIPS*/);
3218 m_grid
->SetColumnCount(3);
3220 wxPGProperty
*prop
=m_grid
->Append(new wxStringProperty("test_name", wxPG_LABEL
, "test_value"));
3221 m_grid
->SetPropertyAttribute(prop
, wxT("Units"), "type");
3222 wxPGProperty
*prop1
= m_grid
->AppendIn(prop
, new wxStringProperty("sub_name1", wxPG_LABEL
, "sub_value1"));
3224 m_grid
->AppendIn(prop1
, new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL
, m_grid
->GetGrid()->GetCellBackgroundColour()));
3225 wxPGProperty
*prop2
= m_grid
->AppendIn(prop
, new wxStringProperty("sub_name2", wxPG_LABEL
, "sub_value2"));
3226 m_grid
->AppendIn(prop2
, new wxStringProperty("sub_name21", wxPG_LABEL
, "sub_value21"));
3228 wxArrayDouble arrdbl
;
3229 arrdbl
.Add(-1.0); arrdbl
.Add(-0.5); arrdbl
.Add(0.0); arrdbl
.Add(0.5); arrdbl
.Add(1.0);
3230 m_grid
->AppendIn(prop
, new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL
,arrdbl
) );
3231 m_grid
->AppendIn(prop
, new wxFontProperty(wxT("Font"),wxPG_LABEL
));
3232 m_grid
->AppendIn(prop2
, new wxStringProperty("sub_name22", wxPG_LABEL
, "sub_value22"));
3233 m_grid
->AppendIn(prop2
, new wxStringProperty("sub_name23", wxPG_LABEL
, "sub_value23"));
3234 prop2
->SetExpanded(false);
3236 ::SetMinSize(m_grid
);
3238 m_sizer
= new wxBoxSizer( wxVERTICAL
);
3239 m_sizer
->Add(m_grid
, 0, wxALL
| wxEXPAND
, 0);
3240 m_panel
->SetAutoLayout(true);
3241 m_panel
->SetSizer(m_sizer
);
3242 m_sizer
->Fit(m_panel
);
3246 void OnCollapse(wxPropertyGridEvent
& WXUNUSED(event
))
3248 wxLogMessage("OnCollapse");
3252 void OnExpand(wxPropertyGridEvent
& WXUNUSED(event
))
3254 wxLogMessage("OnExpand");
3260 ::SetMinSize(m_grid
);
3261 m_sizer
->Fit(m_panel
);
3262 wxPoint pos
= GetScreenPosition();
3263 wxSize size
= m_panel
->GetScreenRect().GetSize();
3264 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
3267 DECLARE_CLASS(PropertyGridPopup
)
3268 DECLARE_EVENT_TABLE()
3271 IMPLEMENT_CLASS(PropertyGridPopup
, wxPopupWindow
)
3272 BEGIN_EVENT_TABLE(PropertyGridPopup
, wxPopupWindow
)
3273 EVT_PG_ITEM_COLLAPSED(ID_POPUPGRID
, PropertyGridPopup::OnCollapse
)
3274 EVT_PG_ITEM_EXPANDED(ID_POPUPGRID
, PropertyGridPopup::OnExpand
)
3278 void FormMain::OnShowPopup(wxCommandEvent
& WXUNUSED(event
))
3280 static PropertyGridPopup
*popup
= NULL
;
3287 popup
= new PropertyGridPopup(this);
3288 wxPoint pt
= wxGetMousePosition();
3289 popup
->Position(pt
, wxSize(0, 0));