Removed AdvImageFileProperty from the wxPropertyGrid sample. It was somewhat impracti...
[wxWidgets.git] / samples / propgrid / propgrid.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid sample
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2004-09-25
7 // RCS-ID: $Id$
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 //
13 //
14 // NOTES
15 //
16 // * Examples of custom property classes are in sampleprops.cpp.
17 //
18 // * Additional ones can be found below.
19 //
20 // * Currently there is no example of a custom property editor. However,
21 // SpinCtrl editor sample is well-commented. It can be found in
22 // src/propgrid/advprops.cpp.
23 //
24 // * To find code that populates the grid with properties, search for
25 // string "::Populate".
26 //
27 // * To find code that handles property grid changes, search for string
28 // "::OnPropertyGridChange".
29 //
30
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include "wx/wxprec.h"
33
34 #ifdef __BORLANDC__
35 #pragma hdrstop
36 #endif
37
38 // for all others, include the necessary headers (this file is usually all you
39 // need because it includes almost all "standard" wxWidgets headers)
40 #ifndef WX_PRECOMP
41 #include "wx/wx.h"
42 #endif
43
44 #if !wxUSE_PROPGRID
45 #error "Please set wxUSE_PROPGRID to 1 and rebuild the library."
46 #endif
47
48 #include <wx/numdlg.h>
49
50 // -----------------------------------------------------------------------
51
52
53 // Main propertygrid header.
54 #include <wx/propgrid/propgrid.h>
55
56 // Extra property classes.
57 #include <wx/propgrid/advprops.h>
58
59 // This defines wxPropertyGridManager.
60 #include <wx/propgrid/manager.h>
61
62 #include "propgrid.h"
63 #include "sampleprops.h"
64
65 #if wxUSE_DATEPICKCTRL
66 #include <wx/datectrl.h>
67 #endif
68
69 #include <wx/artprov.h>
70
71 #ifndef __WXMSW__
72 #include "../sample.xpm"
73 #endif
74
75 // -----------------------------------------------------------------------
76 // wxSampleMultiButtonEditor
77 // A sample editor class that has multiple buttons.
78 // -----------------------------------------------------------------------
79
80 class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor
81 {
82 DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor)
83 public:
84 wxSampleMultiButtonEditor() {}
85 virtual ~wxSampleMultiButtonEditor() {}
86
87 virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid,
88 wxPGProperty* property,
89 const wxPoint& pos,
90 const wxSize& sz ) const;
91 virtual bool OnEvent( wxPropertyGrid* propGrid,
92 wxPGProperty* property,
93 wxWindow* ctrl,
94 wxEvent& event ) const;
95 };
96
97 IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor)
98
99 wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid,
100 wxPGProperty* property,
101 const wxPoint& pos,
102 const wxSize& sz ) const
103 {
104 // Create and populate buttons-subwindow
105 wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz );
106
107 // Add two regular buttons
108 buttons->Add( "..." );
109 buttons->Add( "A" );
110 // Add a bitmap button
111 buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) );
112
113 // Create the 'primary' editor control (textctrl in this case)
114 wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls
115 ( propGrid, property, pos,
116 buttons->GetPrimarySize() );
117
118 // Finally, move buttons-subwindow to correct position and make sure
119 // returned wxPGWindowList contains our custom button list.
120 buttons->Finalize(propGrid, pos);
121
122 wndList.SetSecondary( buttons );
123 return wndList;
124 }
125
126 bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid,
127 wxPGProperty* property,
128 wxWindow* ctrl,
129 wxEvent& event ) const
130 {
131 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
132 {
133 wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
134
135 if ( event.GetId() == buttons->GetButtonId(0) )
136 {
137 // Do something when the first button is pressed
138 wxLogDebug("First button pressed");
139 return false; // Return false since value did not change
140 }
141 if ( event.GetId() == buttons->GetButtonId(1) )
142 {
143 // Do something when the second button is pressed
144 wxMessageBox("Second button pressed");
145 return false; // Return false since value did not change
146 }
147 if ( event.GetId() == buttons->GetButtonId(2) )
148 {
149 // Do something when the third button is pressed
150 wxMessageBox("Third button pressed");
151 return false; // Return false since value did not change
152 }
153 }
154 return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
155 }
156
157 // -----------------------------------------------------------------------
158 // Validator for wxValidator use sample
159 // -----------------------------------------------------------------------
160
161 #if wxUSE_VALIDATORS
162
163 // wxValidator for testing
164
165 class wxInvalidWordValidator : public wxValidator
166 {
167 public:
168
169 wxInvalidWordValidator( const wxString& invalidWord )
170 : wxValidator(), m_invalidWord(invalidWord)
171 {
172 }
173
174 virtual wxObject* Clone() const
175 {
176 return new wxInvalidWordValidator(m_invalidWord);
177 }
178
179 virtual bool Validate(wxWindow* WXUNUSED(parent))
180 {
181 wxTextCtrl* tc = wxDynamicCast(GetWindow(), wxTextCtrl);
182 wxCHECK_MSG(tc, true, wxT("validator window must be wxTextCtrl"));
183
184 wxString val = tc->GetValue();
185
186 if ( val.find(m_invalidWord) == wxString::npos )
187 return true;
188
189 ::wxMessageBox(wxString::Format(wxT("%s is not allowed word"),m_invalidWord.c_str()),
190 wxT("Validation Failure"));
191
192 return false;
193 }
194
195 private:
196 wxString m_invalidWord;
197 };
198
199 #endif // wxUSE_VALIDATORS
200
201 // -----------------------------------------------------------------------
202 // wxVectorProperty
203 // -----------------------------------------------------------------------
204
205 // See propgridsample.h for wxVector3f class
206
207 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f)
208
209 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty,wxPGProperty,
210 wxVector3f,const wxVector3f&,TextCtrl)
211
212
213 wxVectorProperty::wxVectorProperty( const wxString& label,
214 const wxString& name,
215 const wxVector3f& value )
216 : wxPGProperty(label,name)
217 {
218 SetValue( WXVARIANT(value) );
219 AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
220 AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
221 AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
222 }
223
224 wxVectorProperty::~wxVectorProperty() { }
225
226 void wxVectorProperty::RefreshChildren()
227 {
228 if ( !GetChildCount() ) return;
229 const wxVector3f& vector = wxVector3fRefFromVariant(m_value);
230 Item(0)->SetValue( vector.x );
231 Item(1)->SetValue( vector.y );
232 Item(2)->SetValue( vector.z );
233 }
234
235 wxVariant wxVectorProperty::ChildChanged( wxVariant& thisValue,
236 int childIndex,
237 wxVariant& childValue ) const
238 {
239 wxVector3f vector;
240 vector << thisValue;
241 switch ( childIndex )
242 {
243 case 0: vector.x = childValue.GetDouble(); break;
244 case 1: vector.y = childValue.GetDouble(); break;
245 case 2: vector.z = childValue.GetDouble(); break;
246 }
247 wxVariant newVariant;
248 newVariant << vector;
249 return newVariant;
250 }
251
252
253 // -----------------------------------------------------------------------
254 // wxTriangleProperty
255 // -----------------------------------------------------------------------
256
257 // See propgridsample.h for wxTriangle class
258
259 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle)
260
261 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty,wxPGProperty,
262 wxTriangle,const wxTriangle&,TextCtrl)
263
264
265 wxTriangleProperty::wxTriangleProperty( const wxString& label,
266 const wxString& name,
267 const wxTriangle& value)
268 : wxPGProperty(label,name)
269 {
270 SetValue( WXVARIANT(value) );
271 AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
272 AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
273 AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
274 }
275
276 wxTriangleProperty::~wxTriangleProperty() { }
277
278 void wxTriangleProperty::RefreshChildren()
279 {
280 if ( !GetChildCount() ) return;
281 const wxTriangle& triangle = wxTriangleRefFromVariant(m_value);
282 Item(0)->SetValue( WXVARIANT(triangle.a) );
283 Item(1)->SetValue( WXVARIANT(triangle.b) );
284 Item(2)->SetValue( WXVARIANT(triangle.c) );
285 }
286
287 wxVariant wxTriangleProperty::ChildChanged( wxVariant& thisValue,
288 int childIndex,
289 wxVariant& childValue ) const
290 {
291 wxTriangle triangle;
292 triangle << thisValue;
293 const wxVector3f& vector = wxVector3fRefFromVariant(childValue);
294 switch ( childIndex )
295 {
296 case 0: triangle.a = vector; break;
297 case 1: triangle.b = vector; break;
298 case 2: triangle.c = vector; break;
299 }
300 wxVariant newVariant;
301 newVariant << triangle;
302 return newVariant;
303 }
304
305
306 // -----------------------------------------------------------------------
307 // wxSingleChoiceDialogAdapter (wxPGEditorDialogAdapter sample)
308 // -----------------------------------------------------------------------
309
310 class wxSingleChoiceDialogAdapter : public wxPGEditorDialogAdapter
311 {
312 public:
313
314 wxSingleChoiceDialogAdapter( const wxPGChoices& choices )
315 : wxPGEditorDialogAdapter(), m_choices(choices)
316 {
317 }
318
319 virtual bool DoShowDialog( wxPropertyGrid* WXUNUSED(propGrid),
320 wxPGProperty* WXUNUSED(property) )
321 {
322 wxString s = ::wxGetSingleChoice(wxT("Message"),
323 wxT("Caption"),
324 m_choices.GetLabels());
325 if ( s.length() )
326 {
327 SetValue(s);
328 return true;
329 }
330
331 return false;
332 }
333
334 protected:
335 const wxPGChoices& m_choices;
336 };
337
338
339 class SingleChoiceProperty : public wxStringProperty
340 {
341 public:
342
343 SingleChoiceProperty( const wxString& label,
344 const wxString& name = wxPG_LABEL,
345 const wxString& value = wxEmptyString )
346 : wxStringProperty(label, name, value)
347 {
348 // Prepare choices
349 m_choices.Add(wxT("Cat"));
350 m_choices.Add(wxT("Dog"));
351 m_choices.Add(wxT("Gibbon"));
352 m_choices.Add(wxT("Otter"));
353 }
354
355 // Set editor to have button
356 virtual const wxPGEditor* DoGetEditorClass() const
357 {
358 return wxPGEditor_TextCtrlAndButton;
359 }
360
361 // Set what happens on button click
362 virtual wxPGEditorDialogAdapter* GetEditorDialog() const
363 {
364 return new wxSingleChoiceDialogAdapter(m_choices);
365 }
366
367 protected:
368 wxPGChoices m_choices;
369 };
370
371 // -----------------------------------------------------------------------
372 // Menu IDs
373 // -----------------------------------------------------------------------
374
375 enum
376 {
377 PGID = 1,
378 TCID,
379 ID_ABOUT,
380 ID_QUIT,
381 ID_APPENDPROP,
382 ID_APPENDCAT,
383 ID_INSERTPROP,
384 ID_INSERTCAT,
385 ID_ENABLE,
386 ID_SETREADONLY,
387 ID_HIDE,
388 ID_DELETE,
389 ID_DELETER,
390 ID_DELETEALL,
391 ID_UNSPECIFY,
392 ID_ITERATE1,
393 ID_ITERATE2,
394 ID_ITERATE3,
395 ID_ITERATE4,
396 ID_CLEARMODIF,
397 ID_FREEZE,
398 ID_DUMPLIST,
399 ID_COLOURSCHEME1,
400 ID_COLOURSCHEME2,
401 ID_COLOURSCHEME3,
402 ID_CATCOLOURS,
403 ID_SETBGCOLOUR,
404 ID_SETBGCOLOURRECUR,
405 ID_STATICLAYOUT,
406 ID_POPULATE1,
407 ID_POPULATE2,
408 ID_COLLAPSE,
409 ID_COLLAPSEALL,
410 ID_GETVALUES,
411 ID_SETVALUES,
412 ID_SETVALUES2,
413 ID_RUNTESTFULL,
414 ID_RUNTESTPARTIAL,
415 ID_FITCOLUMNS,
416 ID_CHANGEFLAGSITEMS,
417 ID_TESTINSERTCHOICE,
418 ID_TESTDELETECHOICE,
419 ID_INSERTPAGE,
420 ID_REMOVEPAGE,
421 ID_SETSPINCTRLEDITOR,
422 ID_SETPROPERTYVALUE,
423 ID_TESTREPLACE,
424 ID_SETCOLUMNS,
425 ID_TESTXRC,
426 ID_ENABLECOMMONVALUES,
427 ID_SELECTSTYLE,
428 ID_SAVESTATE,
429 ID_RESTORESTATE,
430 ID_RUNMINIMAL,
431 ID_ENABLELABELEDITING,
432 ID_VETOCOLDRAG,
433 ID_SHOWHEADER,
434 ID_ONEXTENDEDKEYNAV
435 };
436
437 // -----------------------------------------------------------------------
438 // Event table
439 // -----------------------------------------------------------------------
440
441 BEGIN_EVENT_TABLE(FormMain, wxFrame)
442 EVT_IDLE(FormMain::OnIdle)
443 EVT_MOVE(FormMain::OnMove)
444 EVT_SIZE(FormMain::OnResize)
445
446 // This occurs when a property is selected
447 EVT_PG_SELECTED( PGID, FormMain::OnPropertyGridSelect )
448 // This occurs when a property value changes
449 EVT_PG_CHANGED( PGID, FormMain::OnPropertyGridChange )
450 // This occurs just prior a property value is changed
451 EVT_PG_CHANGING( PGID, FormMain::OnPropertyGridChanging )
452 // This occurs when a mouse moves over another property
453 EVT_PG_HIGHLIGHTED( PGID, FormMain::OnPropertyGridHighlight )
454 // This occurs when mouse is right-clicked.
455 EVT_PG_RIGHT_CLICK( PGID, FormMain::OnPropertyGridItemRightClick )
456 // This occurs when mouse is double-clicked.
457 EVT_PG_DOUBLE_CLICK( PGID, FormMain::OnPropertyGridItemDoubleClick )
458 // This occurs when propgridmanager's page changes.
459 EVT_PG_PAGE_CHANGED( PGID, FormMain::OnPropertyGridPageChange )
460 // This occurs when user starts editing a property label
461 EVT_PG_LABEL_EDIT_BEGIN( PGID,
462 FormMain::OnPropertyGridLabelEditBegin )
463 // This occurs when user stops editing a property label
464 EVT_PG_LABEL_EDIT_ENDING( PGID,
465 FormMain::OnPropertyGridLabelEditEnding )
466 // This occurs when property's editor button (if any) is clicked.
467 EVT_BUTTON( PGID, FormMain::OnPropertyGridButtonClick )
468
469 EVT_PG_ITEM_COLLAPSED( PGID, FormMain::OnPropertyGridItemCollapse )
470 EVT_PG_ITEM_EXPANDED( PGID, FormMain::OnPropertyGridItemExpand )
471
472 EVT_PG_COL_BEGIN_DRAG( PGID, FormMain::OnPropertyGridColBeginDrag )
473 EVT_PG_COL_DRAGGING( PGID, FormMain::OnPropertyGridColDragging )
474 EVT_PG_COL_END_DRAG( PGID, FormMain::OnPropertyGridColEndDrag )
475
476 EVT_TEXT( PGID, FormMain::OnPropertyGridTextUpdate )
477
478 //
479 // Rest of the events are not property grid specific
480 EVT_KEY_DOWN( FormMain::OnPropertyGridKeyEvent )
481 EVT_KEY_UP( FormMain::OnPropertyGridKeyEvent )
482
483 EVT_MENU( ID_APPENDPROP, FormMain::OnAppendPropClick )
484 EVT_MENU( ID_APPENDCAT, FormMain::OnAppendCatClick )
485 EVT_MENU( ID_INSERTPROP, FormMain::OnInsertPropClick )
486 EVT_MENU( ID_INSERTCAT, FormMain::OnInsertCatClick )
487 EVT_MENU( ID_DELETE, FormMain::OnDelPropClick )
488 EVT_MENU( ID_DELETER, FormMain::OnDelPropRClick )
489 EVT_MENU( ID_UNSPECIFY, FormMain::OnMisc )
490 EVT_MENU( ID_DELETEALL, FormMain::OnClearClick )
491 EVT_MENU( ID_ENABLE, FormMain::OnEnableDisable )
492 EVT_MENU( ID_SETREADONLY, FormMain::OnSetReadOnly )
493 EVT_MENU( ID_HIDE, FormMain::OnHide )
494
495 EVT_MENU( ID_ITERATE1, FormMain::OnIterate1Click )
496 EVT_MENU( ID_ITERATE2, FormMain::OnIterate2Click )
497 EVT_MENU( ID_ITERATE3, FormMain::OnIterate3Click )
498 EVT_MENU( ID_ITERATE4, FormMain::OnIterate4Click )
499 EVT_MENU( ID_ONEXTENDEDKEYNAV, FormMain::OnExtendedKeyNav )
500 EVT_MENU( ID_SETBGCOLOUR, FormMain::OnSetBackgroundColour )
501 EVT_MENU( ID_SETBGCOLOURRECUR, FormMain::OnSetBackgroundColour )
502 EVT_MENU( ID_CLEARMODIF, FormMain::OnClearModifyStatusClick )
503 EVT_MENU( ID_FREEZE, FormMain::OnFreezeClick )
504 EVT_MENU( ID_ENABLELABELEDITING, FormMain::OnEnableLabelEditing )
505 EVT_MENU( ID_SHOWHEADER, FormMain::OnShowHeader )
506 EVT_MENU( ID_DUMPLIST, FormMain::OnDumpList )
507
508 EVT_MENU( ID_COLOURSCHEME1, FormMain::OnColourScheme )
509 EVT_MENU( ID_COLOURSCHEME2, FormMain::OnColourScheme )
510 EVT_MENU( ID_COLOURSCHEME3, FormMain::OnColourScheme )
511 EVT_MENU( ID_COLOURSCHEME4, FormMain::OnColourScheme )
512
513 EVT_MENU( ID_ABOUT, FormMain::OnAbout )
514 EVT_MENU( ID_QUIT, FormMain::OnCloseClick )
515
516 EVT_MENU( ID_CATCOLOURS, FormMain::OnCatColours )
517 EVT_MENU( ID_SETCOLUMNS, FormMain::OnSetColumns )
518 EVT_MENU( ID_TESTXRC, FormMain::OnTestXRC )
519 EVT_MENU( ID_ENABLECOMMONVALUES, FormMain::OnEnableCommonValues )
520 EVT_MENU( ID_SELECTSTYLE, FormMain::OnSelectStyle )
521
522 EVT_MENU( ID_STATICLAYOUT, FormMain::OnMisc )
523 EVT_MENU( ID_COLLAPSE, FormMain::OnMisc )
524 EVT_MENU( ID_COLLAPSEALL, FormMain::OnMisc )
525
526 EVT_MENU( ID_POPULATE1, FormMain::OnPopulateClick )
527 EVT_MENU( ID_POPULATE2, FormMain::OnPopulateClick )
528
529 EVT_MENU( ID_GETVALUES, FormMain::OnMisc )
530 EVT_MENU( ID_SETVALUES, FormMain::OnMisc )
531 EVT_MENU( ID_SETVALUES2, FormMain::OnMisc )
532
533 EVT_MENU( ID_FITCOLUMNS, FormMain::OnFitColumnsClick )
534
535 EVT_MENU( ID_CHANGEFLAGSITEMS, FormMain::OnChangeFlagsPropItemsClick )
536
537 EVT_MENU( ID_RUNTESTFULL, FormMain::OnMisc )
538 EVT_MENU( ID_RUNTESTPARTIAL, FormMain::OnMisc )
539
540 EVT_MENU( ID_TESTINSERTCHOICE, FormMain::OnInsertChoice )
541 EVT_MENU( ID_TESTDELETECHOICE, FormMain::OnDeleteChoice )
542
543 EVT_MENU( ID_INSERTPAGE, FormMain::OnInsertPage )
544 EVT_MENU( ID_REMOVEPAGE, FormMain::OnRemovePage )
545
546 EVT_MENU( ID_SAVESTATE, FormMain::OnSaveState )
547 EVT_MENU( ID_RESTORESTATE, FormMain::OnRestoreState )
548
549 EVT_MENU( ID_SETSPINCTRLEDITOR, FormMain::OnSetSpinCtrlEditorClick )
550 EVT_MENU( ID_TESTREPLACE, FormMain::OnTestReplaceClick )
551 EVT_MENU( ID_SETPROPERTYVALUE, FormMain::OnSetPropertyValue )
552
553 EVT_MENU( ID_RUNMINIMAL, FormMain::OnRunMinimalClick )
554
555 EVT_CONTEXT_MENU( FormMain::OnContextMenu )
556 END_EVENT_TABLE()
557
558 // -----------------------------------------------------------------------
559
560 void FormMain::OnMove( wxMoveEvent& event )
561 {
562 if ( !m_pPropGridManager )
563 {
564 // this check is here so the frame layout can be tested
565 // without creating propertygrid
566 event.Skip();
567 return;
568 }
569
570 // Update position properties
571 int x, y;
572 GetPosition(&x,&y);
573
574 wxPGProperty* id;
575
576 // Must check if properties exist (as they may be deleted).
577
578 // Using m_pPropGridManager, we can scan all pages automatically.
579 id = m_pPropGridManager->GetPropertyByName( wxT("X") );
580 if ( id )
581 m_pPropGridManager->SetPropertyValue( id, x );
582
583 id = m_pPropGridManager->GetPropertyByName( wxT("Y") );
584 if ( id )
585 m_pPropGridManager->SetPropertyValue( id, y );
586
587 id = m_pPropGridManager->GetPropertyByName( wxT("Position") );
588 if ( id )
589 m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxPoint(x,y)) );
590
591 // Should always call event.Skip() in frame's MoveEvent handler
592 event.Skip();
593 }
594
595 // -----------------------------------------------------------------------
596
597 void FormMain::OnResize( wxSizeEvent& event )
598 {
599 if ( !m_pPropGridManager )
600 {
601 // this check is here so the frame layout can be tested
602 // without creating propertygrid
603 event.Skip();
604 return;
605 }
606
607 // Update size properties
608 int w, h;
609 GetSize(&w,&h);
610
611 wxPGProperty* id;
612 wxPGProperty* p;
613
614 // Must check if properties exist (as they may be deleted).
615
616 // Using m_pPropGridManager, we can scan all pages automatically.
617 p = m_pPropGridManager->GetPropertyByName( wxT("Width") );
618 if ( p && !p->IsValueUnspecified() )
619 m_pPropGridManager->SetPropertyValue( p, w );
620
621 p = m_pPropGridManager->GetPropertyByName( wxT("Height") );
622 if ( p && !p->IsValueUnspecified() )
623 m_pPropGridManager->SetPropertyValue( p, h );
624
625 id = m_pPropGridManager->GetPropertyByName ( wxT("Size") );
626 if ( id )
627 m_pPropGridManager->SetPropertyValue( id, WXVARIANT(wxSize(w,h)) );
628
629 // Should always call event.Skip() in frame's SizeEvent handler
630 event.Skip();
631 }
632
633 // -----------------------------------------------------------------------
634
635 void FormMain::OnPropertyGridChanging( wxPropertyGridEvent& event )
636 {
637 wxPGProperty* p = event.GetProperty();
638
639 if ( p->GetName() == wxT("Font") )
640 {
641 int res =
642 wxMessageBox(wxString::Format(wxT("'%s' is about to change (to variant of type '%s')\n\nAllow or deny?"),
643 p->GetName().c_str(),event.GetValue().GetType().c_str()),
644 wxT("Testing wxEVT_PG_CHANGING"), wxYES_NO, m_pPropGridManager);
645
646 if ( res == wxNO )
647 {
648 wxASSERT(event.CanVeto());
649
650 event.Veto();
651
652 // Since we ask a question, it is better if we omit any validation
653 // failure behavior.
654 event.SetValidationFailureBehavior(0);
655 }
656 }
657 }
658
659 //
660 // Note how we use three types of value getting in this method:
661 // A) event.GetPropertyValueAsXXX
662 // B) event.GetPropertValue, and then variant's GetXXX
663 // C) grid's GetPropertyValueAsXXX(id)
664 //
665 void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event )
666 {
667 wxPGProperty* property = event.GetProperty();
668
669 const wxString& name = property->GetName();
670
671 // Properties store values internally as wxVariants, but it is preferred
672 // to use the more modern wxAny at the interface level
673 wxAny value = property->GetValue();
674
675 // Don't handle 'unspecified' values
676 if ( value.IsNull() )
677 return;
678
679 //
680 // FIXME-VC6: In order to compile on Visual C++ 6.0, wxANY_AS()
681 // macro is used. Unless you want to support this old
682 // compiler in your own code, you can use the more
683 // nicer form value.As<FOO>() instead of
684 // wxANY_AS(value, FOO).
685 //
686
687 // Some settings are disabled outside Windows platform
688 if ( name == wxT("X") )
689 SetSize( wxANY_AS(value, int), -1, -1, -1, wxSIZE_USE_EXISTING );
690 else if ( name == wxT("Y") )
691 // wxPGVariantToInt is safe long int value getter
692 SetSize ( -1, wxANY_AS(value, int), -1, -1, wxSIZE_USE_EXISTING );
693 else if ( name == wxT("Width") )
694 SetSize ( -1, -1, wxANY_AS(value, int), -1, wxSIZE_USE_EXISTING );
695 else if ( name == wxT("Height") )
696 SetSize ( -1, -1, -1, wxANY_AS(value, int), wxSIZE_USE_EXISTING );
697 else if ( name == wxT("Label") )
698 {
699 SetTitle( wxANY_AS(value, wxString) );
700 }
701 else if ( name == wxT("Password") )
702 {
703 static int pwdMode = 0;
704
705 //m_pPropGridManager->SetPropertyAttribute(property, wxPG_STRING_PASSWORD, (long)pwdMode);
706
707 pwdMode++;
708 pwdMode &= 1;
709 }
710 else
711 if ( name == wxT("Font") )
712 {
713 wxFont font = wxANY_AS(value, wxFont);
714 wxASSERT( font.Ok() );
715
716 m_pPropGridManager->SetFont( font );
717 }
718 else
719 if ( name == wxT("Margin Colour") )
720 {
721 wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
722 m_pPropGridManager->GetGrid()->SetMarginColour( cpv.m_colour );
723 }
724 else if ( name == wxT("Cell Colour") )
725 {
726 wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
727 m_pPropGridManager->GetGrid()->SetCellBackgroundColour( cpv.m_colour );
728 }
729 else if ( name == wxT("Line Colour") )
730 {
731 wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
732 m_pPropGridManager->GetGrid()->SetLineColour( cpv.m_colour );
733 }
734 else if ( name == wxT("Cell Text Colour") )
735 {
736 wxColourPropertyValue cpv = wxANY_AS(value, wxColourPropertyValue);
737 m_pPropGridManager->GetGrid()->SetCellTextColour( cpv.m_colour );
738 }
739 }
740
741 // -----------------------------------------------------------------------
742
743 void FormMain::OnPropertyGridSelect( wxPropertyGridEvent& event )
744 {
745 wxPGProperty* property = event.GetProperty();
746 if ( property )
747 {
748 m_itemEnable->Enable( TRUE );
749 if ( property->IsEnabled() )
750 m_itemEnable->SetItemLabel( wxT("Disable") );
751 else
752 m_itemEnable->SetItemLabel( wxT("Enable") );
753 }
754 else
755 {
756 m_itemEnable->Enable( FALSE );
757 }
758
759 #if wxUSE_STATUSBAR
760 wxPGProperty* prop = event.GetProperty();
761 wxStatusBar* sb = GetStatusBar();
762 if ( prop )
763 {
764 wxString text(wxT("Selected: "));
765 text += m_pPropGridManager->GetPropertyLabel( prop );
766 sb->SetStatusText ( text );
767 }
768 #endif
769 }
770
771 // -----------------------------------------------------------------------
772
773 void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent& WXUNUSED(event) )
774 {
775 #if wxUSE_STATUSBAR
776 wxStatusBar* sb = GetStatusBar();
777 wxString text(wxT("Page Changed: "));
778 text += m_pPropGridManager->GetPageName(m_pPropGridManager->GetSelectedPage());
779 sb->SetStatusText( text );
780 #endif
781 }
782
783 // -----------------------------------------------------------------------
784
785 void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event )
786 {
787 wxLogMessage("wxPG_EVT_LABEL_EDIT_BEGIN(%s)",
788 event.GetProperty()->GetLabel().c_str());
789 }
790
791 // -----------------------------------------------------------------------
792
793 void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event )
794 {
795 wxLogMessage("wxPG_EVT_LABEL_EDIT_ENDING(%s)",
796 event.GetProperty()->GetLabel().c_str());
797 }
798
799 // -----------------------------------------------------------------------
800
801 void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent& WXUNUSED(event) )
802 {
803 }
804
805 // -----------------------------------------------------------------------
806
807 void FormMain::OnPropertyGridItemRightClick( wxPropertyGridEvent& event )
808 {
809 #if wxUSE_STATUSBAR
810 wxPGProperty* prop = event.GetProperty();
811 wxStatusBar* sb = GetStatusBar();
812 if ( prop )
813 {
814 wxString text(wxT("Right-clicked: "));
815 text += prop->GetLabel();
816 text += wxT(", name=");
817 text += m_pPropGridManager->GetPropertyName(prop);
818 sb->SetStatusText( text );
819 }
820 else
821 {
822 sb->SetStatusText( wxEmptyString );
823 }
824 #endif
825 }
826
827 // -----------------------------------------------------------------------
828
829 void FormMain::OnPropertyGridItemDoubleClick( wxPropertyGridEvent& event )
830 {
831 #if wxUSE_STATUSBAR
832 wxPGProperty* prop = event.GetProperty();
833 wxStatusBar* sb = GetStatusBar();
834 if ( prop )
835 {
836 wxString text(wxT("Double-clicked: "));
837 text += prop->GetLabel();
838 text += wxT(", name=");
839 text += m_pPropGridManager->GetPropertyName(prop);
840 sb->SetStatusText ( text );
841 }
842 else
843 {
844 sb->SetStatusText ( wxEmptyString );
845 }
846 #endif
847 }
848
849 // -----------------------------------------------------------------------
850
851 void FormMain::OnPropertyGridButtonClick ( wxCommandEvent& )
852 {
853 #if wxUSE_STATUSBAR
854 wxPGProperty* prop = m_pPropGridManager->GetSelection();
855 wxStatusBar* sb = GetStatusBar();
856 if ( prop )
857 {
858 wxString text(wxT("Button clicked: "));
859 text += m_pPropGridManager->GetPropertyLabel(prop);
860 text += wxT(", name=");
861 text += m_pPropGridManager->GetPropertyName(prop);
862 sb->SetStatusText( text );
863 }
864 else
865 {
866 ::wxMessageBox(wxT("SHOULD NOT HAPPEN!!!"));
867 }
868 #endif
869 }
870
871 // -----------------------------------------------------------------------
872
873 void FormMain::OnPropertyGridItemCollapse( wxPropertyGridEvent& )
874 {
875 wxLogMessage(wxT("Item was Collapsed"));
876 }
877
878 // -----------------------------------------------------------------------
879
880 void FormMain::OnPropertyGridItemExpand( wxPropertyGridEvent& )
881 {
882 wxLogMessage(wxT("Item was Expanded"));
883 }
884
885 // -----------------------------------------------------------------------
886
887 void FormMain::OnPropertyGridColBeginDrag( wxPropertyGridEvent& event )
888 {
889 if ( m_itemVetoDragging->IsChecked() )
890 {
891 wxLogMessage("Splitter %i resize was vetoed", event.GetColumn());
892 event.Veto();
893 }
894 else
895 {
896 wxLogMessage("Splitter %i resize began", event.GetColumn());
897 }
898 }
899
900 // -----------------------------------------------------------------------
901
902 void FormMain::OnPropertyGridColDragging( wxPropertyGridEvent& event )
903 {
904 wxUnusedVar(event);
905 // For now, let's not spam the log output
906 //wxLogMessage("Splitter %i is being resized", event.GetColumn());
907 }
908
909 // -----------------------------------------------------------------------
910
911 void FormMain::OnPropertyGridColEndDrag( wxPropertyGridEvent& event )
912 {
913 wxLogMessage("Splitter %i resize ended", event.GetColumn());
914 }
915
916 // -----------------------------------------------------------------------
917
918 // EVT_TEXT handling
919 void FormMain::OnPropertyGridTextUpdate( wxCommandEvent& event )
920 {
921 event.Skip();
922 }
923
924 // -----------------------------------------------------------------------
925
926 void FormMain::OnPropertyGridKeyEvent( wxKeyEvent& WXUNUSED(event) )
927 {
928 // Occurs on wxGTK mostly, but not wxMSW.
929 }
930
931 // -----------------------------------------------------------------------
932
933 void FormMain::OnLabelTextChange( wxCommandEvent& WXUNUSED(event) )
934 {
935 // Uncomment following to allow property label modify in real-time
936 // wxPGProperty& p = m_pPropGridManager->GetGrid()->GetSelection();
937 // if ( !p.IsOk() ) return;
938 // m_pPropGridManager->SetPropertyLabel( p, m_tcPropLabel->DoGetValue() );
939 }
940
941 // -----------------------------------------------------------------------
942
943 static const wxChar* _fs_windowstyle_labels[] = {
944 wxT("wxSIMPLE_BORDER"),
945 wxT("wxDOUBLE_BORDER"),
946 wxT("wxSUNKEN_BORDER"),
947 wxT("wxRAISED_BORDER"),
948 wxT("wxNO_BORDER"),
949 wxT("wxTRANSPARENT_WINDOW"),
950 wxT("wxTAB_TRAVERSAL"),
951 wxT("wxWANTS_CHARS"),
952 #if wxNO_FULL_REPAINT_ON_RESIZE
953 wxT("wxNO_FULL_REPAINT_ON_RESIZE"),
954 #endif
955 wxT("wxVSCROLL"),
956 wxT("wxALWAYS_SHOW_SB"),
957 wxT("wxCLIP_CHILDREN"),
958 #if wxFULL_REPAINT_ON_RESIZE
959 wxT("wxFULL_REPAINT_ON_RESIZE"),
960 #endif
961 (const wxChar*) NULL // terminator is always needed
962 };
963
964 static const long _fs_windowstyle_values[] = {
965 wxSIMPLE_BORDER,
966 wxDOUBLE_BORDER,
967 wxSUNKEN_BORDER,
968 wxRAISED_BORDER,
969 wxNO_BORDER,
970 wxTRANSPARENT_WINDOW,
971 wxTAB_TRAVERSAL,
972 wxWANTS_CHARS,
973 #if wxNO_FULL_REPAINT_ON_RESIZE
974 wxNO_FULL_REPAINT_ON_RESIZE,
975 #endif
976 wxVSCROLL,
977 wxALWAYS_SHOW_SB,
978 wxCLIP_CHILDREN,
979 #if wxFULL_REPAINT_ON_RESIZE
980 wxFULL_REPAINT_ON_RESIZE
981 #endif
982 };
983
984 static const wxChar* _fs_framestyle_labels[] = {
985 wxT("wxCAPTION"),
986 wxT("wxMINIMIZE"),
987 wxT("wxMAXIMIZE"),
988 wxT("wxCLOSE_BOX"),
989 wxT("wxSTAY_ON_TOP"),
990 wxT("wxSYSTEM_MENU"),
991 wxT("wxRESIZE_BORDER"),
992 wxT("wxFRAME_TOOL_WINDOW"),
993 wxT("wxFRAME_NO_TASKBAR"),
994 wxT("wxFRAME_FLOAT_ON_PARENT"),
995 wxT("wxFRAME_SHAPED"),
996 (const wxChar*) NULL
997 };
998
999 static const long _fs_framestyle_values[] = {
1000 wxCAPTION,
1001 wxMINIMIZE,
1002 wxMAXIMIZE,
1003 wxCLOSE_BOX,
1004 wxSTAY_ON_TOP,
1005 wxSYSTEM_MENU,
1006 wxRESIZE_BORDER,
1007 wxFRAME_TOOL_WINDOW,
1008 wxFRAME_NO_TASKBAR,
1009 wxFRAME_FLOAT_ON_PARENT,
1010 wxFRAME_SHAPED
1011 };
1012
1013 // -----------------------------------------------------------------------
1014
1015 void FormMain::OnTestXRC(wxCommandEvent& WXUNUSED(event))
1016 {
1017 wxMessageBox(wxT("Sorrt, not yet implemented"));
1018 }
1019
1020 void FormMain::OnEnableCommonValues(wxCommandEvent& WXUNUSED(event))
1021 {
1022 wxPGProperty* prop = m_pPropGridManager->GetSelection();
1023 if ( prop )
1024 prop->EnableCommonValue();
1025 else
1026 wxMessageBox(wxT("First select a property"));
1027 }
1028
1029 void FormMain::PopulateWithStandardItems ()
1030 {
1031 wxPropertyGridManager* pgman = m_pPropGridManager;
1032 wxPropertyGridPage* pg = pgman->GetPage(wxT("Standard Items"));
1033
1034 // Append is ideal way to add items to wxPropertyGrid.
1035 pg->Append( new wxPropertyCategory(wxT("Appearance"),wxPG_LABEL) );
1036
1037 pg->Append( new wxStringProperty(wxT("Label"),wxPG_LABEL,GetTitle()) );
1038 pg->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL) );
1039 pg->SetPropertyHelpString ( wxT("Font"), wxT("Editing this will change font used in the property grid.") );
1040
1041 pg->Append( new wxSystemColourProperty(wxT("Margin Colour"),wxPG_LABEL,
1042 pg->GetGrid()->GetMarginColour()) );
1043
1044 pg->Append( new wxSystemColourProperty(wxT("Cell Colour"),wxPG_LABEL,
1045 pg->GetGrid()->GetCellBackgroundColour()) );
1046 pg->Append( new wxSystemColourProperty(wxT("Cell Text Colour"),wxPG_LABEL,
1047 pg->GetGrid()->GetCellTextColour()) );
1048 pg->Append( new wxSystemColourProperty(wxT("Line Colour"),wxPG_LABEL,
1049 pg->GetGrid()->GetLineColour()) );
1050 pg->Append( new wxFlagsProperty(wxT("Window Styles"),wxPG_LABEL,
1051 m_combinedFlags, GetWindowStyle()) );
1052
1053 //pg->SetPropertyAttribute(wxT("Window Styles"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1054
1055 pg->Append( new wxCursorProperty(wxT("Cursor"),wxPG_LABEL) );
1056
1057 pg->Append( new wxPropertyCategory(wxT("Position"),wxT("PositionCategory")) );
1058 pg->SetPropertyHelpString( wxT("PositionCategory"), wxT("Change in items in this category will cause respective changes in frame.") );
1059
1060 // Let's demonstrate 'Units' attribute here
1061
1062 // Note that we use many attribute constants instead of strings here
1063 // (for instance, wxPG_ATTR_MIN, instead of wxT("min")).
1064 // Using constant may reduce binary size.
1065
1066 pg->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL,480) );
1067 pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MIN, (long)10 );
1068 pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_MAX, (long)2048 );
1069 pg->SetPropertyAttribute(wxT("Height"), wxPG_ATTR_UNITS, wxT("Pixels") );
1070
1071 // Set value to unspecified so that Hint attribute will be demonstrated
1072 pg->SetPropertyValueUnspecified("Height");
1073 pg->SetPropertyAttribute("Height", wxPG_ATTR_HINT,
1074 "Enter new height for window" );
1075
1076 // Difference between hint and help string is that the hint is shown in
1077 // an empty value cell, while help string is shown either in the
1078 // description text box, as a tool tip, or on the status bar.
1079 pg->SetPropertyHelpString("Height",
1080 "This property uses attributes \"Units\" and \"Hint\"." );
1081
1082 pg->Append( new wxIntProperty(wxT("Width"),wxPG_LABEL,640) );
1083 pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MIN, (long)10 );
1084 pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_MAX, (long)2048 );
1085 pg->SetPropertyAttribute(wxT("Width"), wxPG_ATTR_UNITS, wxT("Pixels") );
1086
1087 pg->SetPropertyValueUnspecified(wxT("Width"));
1088 pg->SetPropertyAttribute("Width", wxPG_ATTR_HINT,
1089 "Enter new width for window" );
1090 pg->SetPropertyHelpString("Width",
1091 "This property uses attributes \"Units\" and \"Hint\"." );
1092
1093 pg->Append( new wxIntProperty(wxT("X"),wxPG_LABEL,10) );
1094 pg->SetPropertyAttribute(wxT("X"), wxPG_ATTR_UNITS, wxT("Pixels") );
1095 pg->SetPropertyHelpString(wxT("X"), wxT("This property uses \"Units\" attribute.") );
1096
1097 pg->Append( new wxIntProperty(wxT("Y"),wxPG_LABEL,10) );
1098 pg->SetPropertyAttribute(wxT("Y"), wxPG_ATTR_UNITS, wxT("Pixels") );
1099 pg->SetPropertyHelpString(wxT("Y"), wxT("This property uses \"Units\" attribute.") );
1100
1101 const wxChar* disabledHelpString = wxT("This property is simply disabled. Inorder to have label disabled as well, ")
1102 wxT("you need to set wxPG_EX_GREY_LABEL_WHEN_DISABLED using SetExtraStyle.");
1103
1104 pg->Append( new wxPropertyCategory(wxT("Environment"),wxPG_LABEL) );
1105 pg->Append( new wxStringProperty(wxT("Operating System"),wxPG_LABEL,::wxGetOsDescription()) );
1106
1107 pg->Append( new wxStringProperty(wxT("User Id"),wxPG_LABEL,::wxGetUserId()) );
1108 pg->Append( new wxDirProperty(wxT("User Home"),wxPG_LABEL,::wxGetUserHome()) );
1109 pg->Append( new wxStringProperty(wxT("User Name"),wxPG_LABEL,::wxGetUserName()) );
1110
1111 // Disable some of them
1112 pg->DisableProperty( wxT("Operating System") );
1113 pg->DisableProperty( wxT("User Id") );
1114 pg->DisableProperty( wxT("User Name") );
1115
1116 pg->SetPropertyHelpString( wxT("Operating System"), disabledHelpString );
1117 pg->SetPropertyHelpString( wxT("User Id"), disabledHelpString );
1118 pg->SetPropertyHelpString( wxT("User Name"), disabledHelpString );
1119
1120 pg->Append( new wxPropertyCategory(wxT("More Examples"),wxPG_LABEL) );
1121
1122 pg->Append( new wxFontDataProperty( wxT("FontDataProperty"), wxPG_LABEL) );
1123 pg->SetPropertyHelpString( wxT("FontDataProperty"),
1124 wxT("This demonstrates wxFontDataProperty class defined in this sample app. ")
1125 wxT("It is exactly like wxFontProperty from the library, but also has colour sub-property.")
1126 );
1127
1128 pg->Append( new wxDirsProperty(wxT("DirsProperty"),wxPG_LABEL) );
1129 pg->SetPropertyHelpString( wxT("DirsProperty"),
1130 wxT("This demonstrates wxDirsProperty class defined in this sample app. ")
1131 wxT("It is built with WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR macro, ")
1132 wxT("with custom action (dir dialog popup) defined.")
1133 );
1134
1135 wxArrayDouble arrdbl;
1136 arrdbl.Add(-1.0);
1137 arrdbl.Add(-0.5);
1138 arrdbl.Add(0.0);
1139 arrdbl.Add(0.5);
1140 arrdbl.Add(1.0);
1141
1142 pg->Append( new wxArrayDoubleProperty(wxT("ArrayDoubleProperty"),wxPG_LABEL,arrdbl) );
1143 //pg->SetPropertyAttribute(wxT("ArrayDoubleProperty"),wxPG_FLOAT_PRECISION,(long)2);
1144 pg->SetPropertyHelpString( wxT("ArrayDoubleProperty"),
1145 wxT("This demonstrates wxArrayDoubleProperty class defined in this sample app. ")
1146 wxT("It is an example of a custom list editor property.")
1147 );
1148
1149 pg->Append( new wxLongStringProperty(wxT("Information"),wxPG_LABEL,
1150 wxT("Editing properties will have immediate effect on this window, ")
1151 wxT("and vice versa (atleast in most cases, that is).")
1152 ) );
1153 pg->SetPropertyHelpString( wxT("Information"),
1154 wxT("This property is read-only.") );
1155
1156 pg->SetPropertyReadOnly( wxT("Information"), true );
1157
1158 //
1159 // Set test information for cells in columns 3 and 4
1160 // (reserve column 2 for displaying units)
1161 wxPropertyGridIterator it;
1162 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_FOLDER);
1163
1164 for ( it = pg->GetGrid()->GetIterator();
1165 !it.AtEnd();
1166 it++ )
1167 {
1168 wxPGProperty* p = *it;
1169 if ( p->IsCategory() )
1170 continue;
1171
1172 pg->SetPropertyCell( p, 3, wxT("Cell 3"), bmp );
1173 pg->SetPropertyCell( p, 4, wxT("Cell 4"), wxNullBitmap, *wxWHITE, *wxBLACK );
1174 }
1175 }
1176
1177 // -----------------------------------------------------------------------
1178
1179 void FormMain::PopulateWithExamples ()
1180 {
1181 wxPropertyGridManager* pgman = m_pPropGridManager;
1182 wxPropertyGridPage* pg = pgman->GetPage(wxT("Examples"));
1183 wxPGProperty* pid;
1184 wxPGProperty* prop;
1185
1186 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1187 //pg->SetPropertyHelpString ( wxT("Examples"), wxT("This category has example of (almost) every built-in property class.") );
1188
1189 #if wxUSE_SPINBTN
1190 pg->Append( new wxIntProperty ( wxT("SpinCtrl"), wxPG_LABEL, 0 ) );
1191
1192 pg->SetPropertyEditor( wxT("SpinCtrl"), wxPGEditor_SpinCtrl );
1193 pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MIN, (long)-10 ); // Use constants instead of string
1194 pg->SetPropertyAttribute( wxT("SpinCtrl"), wxPG_ATTR_MAX, (long)16384 ); // for reduced binary size.
1195 pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Step"), (long)2 );
1196 pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("MotionSpin"), true );
1197 //pg->SetPropertyAttribute( wxT("SpinCtrl"), wxT("Wrap"), true );
1198
1199 pg->SetPropertyHelpString( wxT("SpinCtrl"),
1200 wxT("This is regular wxIntProperty, which editor has been ")
1201 wxT("changed to wxPGEditor_SpinCtrl. Note however that ")
1202 wxT("static wxPropertyGrid::RegisterAdditionalEditors() ")
1203 wxT("needs to be called prior to using it."));
1204
1205 #endif
1206
1207 // Add bool property
1208 pg->Append( new wxBoolProperty( wxT("BoolProperty"), wxPG_LABEL, false ) );
1209
1210 // Add bool property with check box
1211 pg->Append( new wxBoolProperty( wxT("BoolProperty with CheckBox"), wxPG_LABEL, false ) );
1212 pg->SetPropertyAttribute( wxT("BoolProperty with CheckBox"),
1213 wxPG_BOOL_USE_CHECKBOX,
1214 true );
1215
1216 pg->SetPropertyHelpString( wxT("BoolProperty with CheckBox"),
1217 wxT("Property attribute wxPG_BOOL_USE_CHECKBOX has been set to true.") );
1218
1219 prop = pg->Append( new wxFloatProperty("FloatProperty",
1220 wxPG_LABEL,
1221 1234500.23) );
1222 prop->SetAttribute("Min", -100.12);
1223
1224 // A string property that can be edited in a separate editor dialog.
1225 pg->Append( new wxLongStringProperty( wxT("LongStringProperty"), wxT("LongStringProp"),
1226 wxT("This is much longer string than the first one. Edit it by clicking the button.") ) );
1227
1228 // A property that edits a wxArrayString.
1229 wxArrayString example_array;
1230 example_array.Add( wxT("String 1"));
1231 example_array.Add( wxT("String 2"));
1232 example_array.Add( wxT("String 3"));
1233 pg->Append( new wxArrayStringProperty( wxT("ArrayStringProperty"), wxPG_LABEL,
1234 example_array) );
1235
1236 // Test adding same category multiple times ( should not actually create a new one )
1237 //pg->Append( new wxPropertyCategory(wxT("Examples (low priority)"),wxT("Examples")) );
1238
1239 // A file selector property. Note that argument between name
1240 // and initial value is wildcard (format same as in wxFileDialog).
1241 prop = new wxFileProperty( wxT("FileProperty"), wxT("TextFile") );
1242 pg->Append( prop );
1243
1244 prop->SetAttribute(wxPG_FILE_WILDCARD,wxT("Text Files (*.txt)|*.txt"));
1245 prop->SetAttribute(wxPG_FILE_DIALOG_TITLE,wxT("Custom File Dialog Title"));
1246 prop->SetAttribute(wxPG_FILE_SHOW_FULL_PATH,false);
1247
1248 #ifdef __WXMSW__
1249 prop->SetAttribute(wxPG_FILE_SHOW_RELATIVE_PATH,wxT("C:\\Windows"));
1250 pg->SetPropertyValue(prop,wxT("C:\\Windows\\System32\\msvcrt71.dll"));
1251 #endif
1252
1253 #if wxUSE_IMAGE
1254 // An image file property. Arguments are just like for FileProperty, but
1255 // wildcard is missing (it is autogenerated from supported image formats).
1256 // If you really need to override it, create property separately, and call
1257 // its SetWildcard method.
1258 pg->Append( new wxImageFileProperty( wxT("ImageFile"), wxPG_LABEL ) );
1259 #endif
1260
1261 pid = pg->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL,*wxRED) );
1262 //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false);
1263 pg->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox );
1264 pg->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true);
1265 pg->SetPropertyHelpString( wxT("ColourProperty"),
1266 wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ")
1267 wxT("editor of this property to wxPGEditor_ComboBox)"));
1268
1269 //
1270 // This demonstrates using alternative editor for colour property
1271 // to trigger colour dialog directly from button.
1272 pg->Append( new wxColourProperty(wxT("ColourProperty2"),wxPG_LABEL,*wxGREEN) );
1273
1274 //
1275 // wxEnumProperty does not store strings or even list of strings
1276 // ( so that's why they are static in function ).
1277 static const wxChar* enum_prop_labels[] = { wxT("One Item"),
1278 wxT("Another Item"), wxT("One More"), wxT("This Is Last"), NULL };
1279
1280 // this value array would be optional if values matched string indexes
1281 static long enum_prop_values[] = { 40, 80, 120, 160 };
1282
1283 // note that the initial value (the last argument) is the actual value,
1284 // not index or anything like that. Thus, our value selects "Another Item".
1285 //
1286 // 0 before value is number of items. If it is 0, like in our example,
1287 // number of items is calculated, and this requires that the string pointer
1288 // array is terminated with NULL.
1289 pg->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL,
1290 enum_prop_labels, enum_prop_values, 80 ) );
1291
1292 wxPGChoices soc;
1293
1294 // use basic table from our previous example
1295 // can also set/add wxArrayStrings and wxArrayInts directly.
1296 soc.Set( enum_prop_labels, enum_prop_values );
1297
1298 // add extra items
1299 soc.Add( wxT("Look, it continues"), 200 );
1300 soc.Add( wxT("Even More"), 240 );
1301 soc.Add( wxT("And More"), 280 );
1302 soc.Add( "", 300 );
1303 soc.Add( wxT("True End of the List"), 320 );
1304
1305 // Test custom colours ([] operator of wxPGChoices returns
1306 // references to wxPGChoiceEntry).
1307 soc[1].SetFgCol(*wxRED);
1308 soc[1].SetBgCol(*wxLIGHT_GREY);
1309 soc[2].SetFgCol(*wxGREEN);
1310 soc[2].SetBgCol(*wxLIGHT_GREY);
1311 soc[3].SetFgCol(*wxBLUE);
1312 soc[3].SetBgCol(*wxLIGHT_GREY);
1313 soc[4].SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER));
1314
1315 pg->Append( new wxEnumProperty(wxT("EnumProperty 2"),
1316 wxPG_LABEL,
1317 soc,
1318 240) );
1319 pg->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360);
1320
1321 // Here we only display the original 'soc' choices
1322 pg->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL,
1323 soc, 240 ) );
1324
1325 // Test Hint attribute in EnumProperty
1326 pg->GetProperty("EnumProperty 3")->SetAttribute("Hint", "Dummy Hint");
1327
1328 pg->SetPropertyHelpString("EnumProperty 3",
1329 "This property uses \"Hint\" attribute.");
1330
1331 // 'soc' plus one exclusive extra choice "4th only"
1332 pg->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL,
1333 soc, 240 ) );
1334 pg->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360);
1335
1336 pg->SetPropertyHelpString(wxT("EnumProperty 4"),
1337 wxT("Should have one extra item when compared to EnumProperty 3"));
1338
1339 // Password property example.
1340 pg->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL, wxT("password")) );
1341 pg->SetPropertyAttribute( wxT("Password"), wxPG_STRING_PASSWORD, true );
1342 pg->SetPropertyHelpString( wxT("Password"),
1343 wxT("Has attribute wxPG_STRING_PASSWORD set to true") );
1344
1345 // String editor with dir selector button. Uses wxEmptyString as name, which
1346 // is allowed (naturally, in this case property cannot be accessed by name).
1347 pg->Append( new wxDirProperty( wxT("DirProperty"), wxPG_LABEL, ::wxGetUserHome()) );
1348 pg->SetPropertyAttribute( wxT("DirProperty"),
1349 wxPG_DIR_DIALOG_MESSAGE,
1350 wxT("This is a custom dir dialog message") );
1351
1352 // Add string property - first arg is label, second name, and third initial value
1353 pg->Append( new wxStringProperty ( wxT("StringProperty"), wxPG_LABEL ) );
1354 pg->SetPropertyMaxLength( wxT("StringProperty"), 6 );
1355 pg->SetPropertyHelpString( wxT("StringProperty"),
1356 wxT("Max length of this text has been limited to 6, using wxPropertyGrid::SetPropertyMaxLength.") );
1357
1358 // Set value after limiting so that it will be applied
1359 pg->SetPropertyValue( wxT("StringProperty"), wxT("some text") );
1360
1361 //
1362 // Demonstrate "AutoComplete" attribute
1363 pg->Append( new wxStringProperty( "StringProperty AutoComplete",
1364 wxPG_LABEL ) );
1365
1366 wxArrayString autoCompleteStrings;
1367 autoCompleteStrings.Add("One choice");
1368 autoCompleteStrings.Add("Another choice");
1369 autoCompleteStrings.Add("Another choice, yeah");
1370 autoCompleteStrings.Add("Yet another choice");
1371 autoCompleteStrings.Add("Yet another choice, bear with me");
1372 pg->SetPropertyAttribute( "StringProperty AutoComplete",
1373 "AutoComplete",
1374 autoCompleteStrings );
1375
1376 pg->SetPropertyHelpString( "StringProperty AutoComplete",
1377 "AutoComplete attribute has been set for this property "
1378 "(try writing something beginning with 'a', 'o' or 'y').");
1379
1380 // Add string property with arbitrarily wide bitmap in front of it. We
1381 // intentionally lower-than-typical row height here so that the ugly
1382 // scaling code wont't be run.
1383 pg->Append( new wxStringProperty( wxT("StringPropertyWithBitmap"),
1384 wxPG_LABEL,
1385 wxT("Test Text")) );
1386 wxBitmap myTestBitmap(60, 15, 32);
1387 wxMemoryDC mdc;
1388 mdc.SelectObject(myTestBitmap);
1389 mdc.Clear();
1390 mdc.SetPen(*wxBLACK);
1391 mdc.DrawLine(0, 0, 60, 15);
1392 mdc.SelectObject(wxNullBitmap);
1393 pg->SetPropertyImage( wxT("StringPropertyWithBitmap"), myTestBitmap );
1394
1395
1396 // this value array would be optional if values matched string indexes
1397 //long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX, wxMAXIMIZE_BOX };
1398
1399 //pg->Append( wxFlagsProperty(wxT("Example of FlagsProperty"),wxT("FlagsProp"),
1400 // flags_prop_labels, flags_prop_values, 0, GetWindowStyle() ) );
1401
1402
1403 // Multi choice dialog.
1404 wxArrayString tchoices;
1405 tchoices.Add(wxT("Cabbage"));
1406 tchoices.Add(wxT("Carrot"));
1407 tchoices.Add(wxT("Onion"));
1408 tchoices.Add(wxT("Potato"));
1409 tchoices.Add(wxT("Strawberry"));
1410
1411 wxArrayString tchoicesValues;
1412 tchoicesValues.Add(wxT("Carrot"));
1413 tchoicesValues.Add(wxT("Potato"));
1414
1415 pg->Append( new wxEnumProperty(wxT("EnumProperty X"),wxPG_LABEL, tchoices ) );
1416
1417 pg->Append( new wxMultiChoiceProperty( wxT("MultiChoiceProperty"), wxPG_LABEL,
1418 tchoices, tchoicesValues ) );
1419 pg->SetPropertyAttribute( wxT("MultiChoiceProperty"), wxT("UserStringMode"), true );
1420
1421 pg->Append( new wxSizeProperty( wxT("SizeProperty"), wxT("Size"), GetSize() ) );
1422 pg->Append( new wxPointProperty( wxT("PointProperty"), wxT("Position"), GetPosition() ) );
1423
1424 // UInt samples
1425 pg->Append( new wxUIntProperty( wxT("UIntProperty"), wxPG_LABEL, wxULongLong(wxULL(0xFEEEFEEEFEEE))));
1426 pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1427 pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_HEX );
1428 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_PREFIX, wxPG_PREFIX_NONE );
1429 //pg->SetPropertyAttribute( wxT("UIntProperty"), wxPG_UINT_BASE, wxPG_BASE_OCT );
1430
1431 //
1432 // wxEditEnumProperty
1433 wxPGChoices eech;
1434 eech.Add(wxT("Choice 1"));
1435 eech.Add(wxT("Choice 2"));
1436 eech.Add(wxT("Choice 3"));
1437 pg->Append( new wxEditEnumProperty("EditEnumProperty",
1438 wxPG_LABEL,
1439 eech,
1440 "Choice not in the list") );
1441
1442 // Test Hint attribute in EditEnumProperty
1443 pg->GetProperty("EditEnumProperty")->SetAttribute("Hint", "Dummy Hint");
1444
1445 //wxString v_;
1446 //wxTextValidator validator1(wxFILTER_NUMERIC,&v_);
1447 //pg->SetPropertyValidator( wxT("EditEnumProperty"), validator1 );
1448
1449 #if wxUSE_DATETIME
1450 //
1451 // wxDateTimeProperty
1452 pg->Append( new wxDateProperty(wxT("DateProperty"), wxPG_LABEL, wxDateTime::Now() ) );
1453
1454 #if wxUSE_DATEPICKCTRL
1455 pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE,
1456 (long)(wxDP_DROPDOWN |
1457 wxDP_SHOWCENTURY |
1458 wxDP_ALLOWNONE) );
1459
1460 pg->SetPropertyHelpString( wxT("DateProperty"),
1461 wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
1462 wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
1463 #endif
1464
1465 #endif
1466
1467 //
1468 // Add Triangle properties as both wxTriangleProperty and
1469 // a generic parent property (using wxStringProperty).
1470 //
1471 wxPGProperty* topId = pg->Append( new wxStringProperty(wxT("3D Object"), wxPG_LABEL, wxT("<composed>")) );
1472
1473 pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 1"), wxT("Triangle 1"), wxT("<composed>")) );
1474 pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
1475 pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
1476 pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
1477
1478 pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 2"), wxT("Triangle 2") ) );
1479
1480 pg->SetPropertyHelpString( wxT("3D Object"),
1481 wxT("3D Object is wxStringProperty with value \"<composed>\". Two of its children are similar wxStringProperties with ")
1482 wxT("three wxVectorProperty children, and other two are custom wxTriangleProperties.") );
1483
1484 pid = pg->AppendIn( topId, new wxStringProperty(wxT("Triangle 3"), wxT("Triangle 3"), wxT("<composed>")) );
1485 pg->AppendIn( pid, new wxVectorProperty( wxT("A"), wxPG_LABEL ) );
1486 pg->AppendIn( pid, new wxVectorProperty( wxT("B"), wxPG_LABEL ) );
1487 pg->AppendIn( pid, new wxVectorProperty( wxT("C"), wxPG_LABEL ) );
1488
1489 pg->AppendIn( topId, new wxTriangleProperty( wxT("Triangle 4"), wxT("Triangle 4") ) );
1490
1491 //
1492 // This snippet is a doc sample test
1493 //
1494 wxPGProperty* carProp = pg->Append(new wxStringProperty(wxT("Car"),
1495 wxPG_LABEL,
1496 wxT("<composed>")));
1497
1498 pg->AppendIn(carProp, new wxStringProperty(wxT("Model"),
1499 wxPG_LABEL,
1500 wxT("Lamborghini Diablo SV")));
1501
1502 pg->AppendIn(carProp, new wxIntProperty(wxT("Engine Size (cc)"),
1503 wxPG_LABEL,
1504 5707) );
1505
1506 wxPGProperty* speedsProp = pg->AppendIn(carProp,
1507 new wxStringProperty(wxT("Speeds"),
1508 wxPG_LABEL,
1509 wxT("<composed>")));
1510
1511 pg->AppendIn( speedsProp, new wxIntProperty(wxT("Max. Speed (mph)"),
1512 wxPG_LABEL,290) );
1513 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("0-100 mph (sec)"),
1514 wxPG_LABEL,3.9) );
1515 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("1/4 mile (sec)"),
1516 wxPG_LABEL,8.6) );
1517
1518 // This is how child property can be referred to by name
1519 pg->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
1520
1521 pg->AppendIn(carProp, new wxIntProperty(wxT("Price ($)"),
1522 wxPG_LABEL,
1523 300000) );
1524
1525 pg->AppendIn(carProp, new wxBoolProperty(wxT("Convertible"),
1526 wxPG_LABEL,
1527 false) );
1528
1529 // Displayed value of "Car" property is now very close to this:
1530 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
1531
1532 //
1533 // Test wxSampleMultiButtonEditor
1534 pg->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL) );
1535 pg->SetPropertyEditor(wxT("MultipleButtons"), m_pSampleMultiButtonEditor );
1536
1537 // Test SingleChoiceProperty
1538 pg->Append( new SingleChoiceProperty(wxT("SingleChoiceProperty")) );
1539
1540
1541 //
1542 // Test adding variable height bitmaps in wxPGChoices
1543 wxPGChoices bc;
1544
1545 bc.Add(wxT("Wee"), wxBitmap(16, 16));
1546 bc.Add(wxT("Not so wee"), wxBitmap(32, 32));
1547 bc.Add(wxT("Friggin' huge"), wxBitmap(64, 64));
1548
1549 pg->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
1550 wxPG_LABEL,
1551 bc,
1552 0) );
1553
1554 //
1555 // Test how non-editable composite strings appear
1556 pid = new wxStringProperty(wxT("wxWidgets Traits"), wxPG_LABEL, wxT("<composed>"));
1557 pg->SetPropertyReadOnly(pid);
1558
1559 //
1560 // For testing purposes, combine two methods of adding children
1561 //
1562
1563 pid->AppendChild( new wxStringProperty(wxT("Latest Release"),
1564 wxPG_LABEL,
1565 wxT("2.8.10")));
1566 pid->AppendChild( new wxBoolProperty(wxT("Win API"),
1567 wxPG_LABEL,
1568 true) );
1569
1570 pg->Append( pid );
1571
1572 pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) );
1573 pg->AppendIn(pid, new wxBoolProperty(wxT("Cocoa"), wxPG_LABEL, true) );
1574 pg->AppendIn(pid, new wxBoolProperty(wxT("BeOS"), wxPG_LABEL, false) );
1575 pg->AppendIn(pid, new wxStringProperty(wxT("SVN Trunk Version"), wxPG_LABEL, wxT("2.9.0")) );
1576 pg->AppendIn(pid, new wxBoolProperty(wxT("GTK+"), wxPG_LABEL, true) );
1577 pg->AppendIn(pid, new wxBoolProperty(wxT("Sky OS"), wxPG_LABEL, false) );
1578 pg->AppendIn(pid, new wxBoolProperty(wxT("QT"), wxPG_LABEL, false) );
1579
1580 AddTestProperties(pg);
1581 }
1582
1583 // -----------------------------------------------------------------------
1584
1585 void FormMain::PopulateWithLibraryConfig ()
1586 {
1587 wxPropertyGridManager* pgman = m_pPropGridManager;
1588 wxPropertyGridPage* pg = pgman->GetPage(wxT("wxWidgets Library Config"));
1589
1590 // Set custom column proportions (here in the sample app we need
1591 // to check if the grid has wxPG_SPLITTER_AUTO_CENTER style. You usually
1592 // need not to do it in your application).
1593 if ( pgman->HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
1594 {
1595 pg->SetColumnProportion(0, 3);
1596 pg->SetColumnProportion(1, 1);
1597 }
1598
1599 wxPGProperty* cat;
1600
1601 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_REPORT_VIEW);
1602
1603 wxPGProperty* pid;
1604
1605 wxFont italicFont = pgman->GetGrid()->GetCaptionFont();
1606 italicFont.SetStyle(wxFONTSTYLE_ITALIC);
1607
1608 wxString italicFontHelp = "Font of this property's wxPGCell has "
1609 "been modified. Obtain property's cell "
1610 "with wxPGProperty::"
1611 "GetOrCreateCell(column).";
1612
1613 #define ADD_WX_LIB_CONF_GROUP(A) \
1614 cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
1615 pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
1616 cat->GetCell(0).SetFont(italicFont); \
1617 cat->SetHelpString(italicFontHelp);
1618
1619 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
1620 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
1621 pg->DisableProperty(wxT(#A));
1622
1623 pid = pg->Append( new wxPropertyCategory( wxT("wxWidgets Library Configuration") ) );
1624 pg->SetPropertyCell( pid, 0, wxPG_LABEL, bmp );
1625
1626 // Both of following lines would set a label for the second column
1627 pg->SetPropertyCell( pid, 1, "Is Enabled" );
1628 pid->SetValue("Is Enabled");
1629
1630 ADD_WX_LIB_CONF_GROUP(wxT("Global Settings"))
1631 ADD_WX_LIB_CONF( wxUSE_GUI )
1632
1633 ADD_WX_LIB_CONF_GROUP(wxT("Compatibility Settings"))
1634 #if defined(WXWIN_COMPATIBILITY_2_2)
1635 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_2 )
1636 #endif
1637 #if defined(WXWIN_COMPATIBILITY_2_4)
1638 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_4 )
1639 #endif
1640 #if defined(WXWIN_COMPATIBILITY_2_6)
1641 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_6 )
1642 #endif
1643 #if defined(WXWIN_COMPATIBILITY_2_8)
1644 ADD_WX_LIB_CONF( WXWIN_COMPATIBILITY_2_8 )
1645 #endif
1646 #ifdef wxFONT_SIZE_COMPATIBILITY
1647 ADD_WX_LIB_CONF( wxFONT_SIZE_COMPATIBILITY )
1648 #else
1649 ADD_WX_LIB_CONF_NODEF ( wxFONT_SIZE_COMPATIBILITY )
1650 #endif
1651 #ifdef wxDIALOG_UNIT_COMPATIBILITY
1652 ADD_WX_LIB_CONF( wxDIALOG_UNIT_COMPATIBILITY )
1653 #else
1654 ADD_WX_LIB_CONF_NODEF ( wxDIALOG_UNIT_COMPATIBILITY )
1655 #endif
1656
1657 ADD_WX_LIB_CONF_GROUP(wxT("Debugging Settings"))
1658 ADD_WX_LIB_CONF( wxUSE_DEBUG_CONTEXT )
1659 ADD_WX_LIB_CONF( wxUSE_MEMORY_TRACING )
1660 ADD_WX_LIB_CONF( wxUSE_GLOBAL_MEMORY_OPERATORS )
1661 ADD_WX_LIB_CONF( wxUSE_DEBUG_NEW_ALWAYS )
1662 ADD_WX_LIB_CONF( wxUSE_ON_FATAL_EXCEPTION )
1663
1664 ADD_WX_LIB_CONF_GROUP(wxT("Unicode Support"))
1665 ADD_WX_LIB_CONF( wxUSE_UNICODE )
1666 ADD_WX_LIB_CONF( wxUSE_UNICODE_MSLU )
1667
1668 ADD_WX_LIB_CONF_GROUP(wxT("Global Features"))
1669 ADD_WX_LIB_CONF( wxUSE_EXCEPTIONS )
1670 ADD_WX_LIB_CONF( wxUSE_EXTENDED_RTTI )
1671 ADD_WX_LIB_CONF( wxUSE_STL )
1672 ADD_WX_LIB_CONF( wxUSE_LOG )
1673 ADD_WX_LIB_CONF( wxUSE_LOGWINDOW )
1674 ADD_WX_LIB_CONF( wxUSE_LOGGUI )
1675 ADD_WX_LIB_CONF( wxUSE_LOG_DIALOG )
1676 ADD_WX_LIB_CONF( wxUSE_CMDLINE_PARSER )
1677 ADD_WX_LIB_CONF( wxUSE_THREADS )
1678 ADD_WX_LIB_CONF( wxUSE_STREAMS )
1679 ADD_WX_LIB_CONF( wxUSE_STD_IOSTREAM )
1680
1681 ADD_WX_LIB_CONF_GROUP(wxT("Non-GUI Features"))
1682 ADD_WX_LIB_CONF( wxUSE_LONGLONG )
1683 ADD_WX_LIB_CONF( wxUSE_FILE )
1684 ADD_WX_LIB_CONF( wxUSE_FFILE )
1685 ADD_WX_LIB_CONF( wxUSE_FSVOLUME )
1686 ADD_WX_LIB_CONF( wxUSE_TEXTBUFFER )
1687 ADD_WX_LIB_CONF( wxUSE_TEXTFILE )
1688 ADD_WX_LIB_CONF( wxUSE_INTL )
1689 ADD_WX_LIB_CONF( wxUSE_DATETIME )
1690 ADD_WX_LIB_CONF( wxUSE_TIMER )
1691 ADD_WX_LIB_CONF( wxUSE_STOPWATCH )
1692 ADD_WX_LIB_CONF( wxUSE_CONFIG )
1693 #ifdef wxUSE_CONFIG_NATIVE
1694 ADD_WX_LIB_CONF( wxUSE_CONFIG_NATIVE )
1695 #else
1696 ADD_WX_LIB_CONF_NODEF ( wxUSE_CONFIG_NATIVE )
1697 #endif
1698 ADD_WX_LIB_CONF( wxUSE_DIALUP_MANAGER )
1699 ADD_WX_LIB_CONF( wxUSE_DYNLIB_CLASS )
1700 ADD_WX_LIB_CONF( wxUSE_DYNAMIC_LOADER )
1701 ADD_WX_LIB_CONF( wxUSE_SOCKETS )
1702 ADD_WX_LIB_CONF( wxUSE_FILESYSTEM )
1703 ADD_WX_LIB_CONF( wxUSE_FS_ZIP )
1704 ADD_WX_LIB_CONF( wxUSE_FS_INET )
1705 ADD_WX_LIB_CONF( wxUSE_ZIPSTREAM )
1706 ADD_WX_LIB_CONF( wxUSE_ZLIB )
1707 ADD_WX_LIB_CONF( wxUSE_APPLE_IEEE )
1708 ADD_WX_LIB_CONF( wxUSE_JOYSTICK )
1709 ADD_WX_LIB_CONF( wxUSE_FONTMAP )
1710 ADD_WX_LIB_CONF( wxUSE_MIMETYPE )
1711 ADD_WX_LIB_CONF( wxUSE_PROTOCOL )
1712 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FILE )
1713 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_FTP )
1714 ADD_WX_LIB_CONF( wxUSE_PROTOCOL_HTTP )
1715 ADD_WX_LIB_CONF( wxUSE_URL )
1716 #ifdef wxUSE_URL_NATIVE
1717 ADD_WX_LIB_CONF( wxUSE_URL_NATIVE )
1718 #else
1719 ADD_WX_LIB_CONF_NODEF ( wxUSE_URL_NATIVE )
1720 #endif
1721 ADD_WX_LIB_CONF( wxUSE_REGEX )
1722 ADD_WX_LIB_CONF( wxUSE_SYSTEM_OPTIONS )
1723 ADD_WX_LIB_CONF( wxUSE_SOUND )
1724 #ifdef wxUSE_XRC
1725 ADD_WX_LIB_CONF( wxUSE_XRC )
1726 #else
1727 ADD_WX_LIB_CONF_NODEF ( wxUSE_XRC )
1728 #endif
1729 ADD_WX_LIB_CONF( wxUSE_XML )
1730
1731 // Set them to use check box.
1732 pg->SetPropertyAttribute(pid,wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
1733 }
1734
1735
1736 //
1737 // Handle events of the third page here.
1738 class wxMyPropertyGridPage : public wxPropertyGridPage
1739 {
1740 public:
1741
1742 // Return false here to indicate unhandled events should be
1743 // propagated to manager's parent, as normal.
1744 virtual bool IsHandlingAllEvents() const { return false; }
1745
1746 protected:
1747
1748 virtual wxPGProperty* DoInsert( wxPGProperty* parent,
1749 int index,
1750 wxPGProperty* property )
1751 {
1752 return wxPropertyGridPage::DoInsert(parent,index,property);
1753 }
1754
1755 void OnPropertySelect( wxPropertyGridEvent& event );
1756 void OnPropertyChanging( wxPropertyGridEvent& event );
1757 void OnPropertyChange( wxPropertyGridEvent& event );
1758 void OnPageChange( wxPropertyGridEvent& event );
1759
1760 private:
1761 DECLARE_EVENT_TABLE()
1762 };
1763
1764
1765 BEGIN_EVENT_TABLE(wxMyPropertyGridPage, wxPropertyGridPage)
1766 EVT_PG_SELECTED( wxID_ANY, wxMyPropertyGridPage::OnPropertySelect )
1767 EVT_PG_CHANGING( wxID_ANY, wxMyPropertyGridPage::OnPropertyChanging )
1768 EVT_PG_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPropertyChange )
1769 EVT_PG_PAGE_CHANGED( wxID_ANY, wxMyPropertyGridPage::OnPageChange )
1770 END_EVENT_TABLE()
1771
1772
1773 void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent& WXUNUSED(event) )
1774 {
1775 wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertySelect()"));
1776 }
1777
1778 void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent& event )
1779 {
1780 wxPGProperty* p = event.GetProperty();
1781 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"),
1782 p->GetName().c_str(),
1783 p->GetDisplayedString().c_str());
1784 }
1785
1786 void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent& event )
1787 {
1788 wxPGProperty* p = event.GetProperty();
1789 wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"),
1790 p->GetName().c_str(),
1791 event.GetValue().GetString().c_str());
1792 }
1793
1794 void wxMyPropertyGridPage::OnPageChange( wxPropertyGridEvent& WXUNUSED(event) )
1795 {
1796 wxLogDebug(wxT("wxMyPropertyGridPage::OnPageChange()"));
1797 }
1798
1799
1800 class wxPGKeyHandler : public wxEvtHandler
1801 {
1802 public:
1803
1804 void OnKeyEvent( wxKeyEvent& event )
1805 {
1806 wxMessageBox(wxString::Format(wxT("%i"),event.GetKeyCode()));
1807 event.Skip();
1808 }
1809 private:
1810 DECLARE_EVENT_TABLE()
1811 };
1812
1813 BEGIN_EVENT_TABLE(wxPGKeyHandler,wxEvtHandler)
1814 EVT_KEY_DOWN( wxPGKeyHandler::OnKeyEvent )
1815 END_EVENT_TABLE()
1816
1817
1818 // -----------------------------------------------------------------------
1819
1820 void FormMain::InitPanel()
1821 {
1822 if ( m_panel )
1823 m_panel->Destroy();
1824
1825 wxWindow* panel = new wxPanel(this, wxID_ANY,
1826 wxPoint(0, 0), wxSize(400, 400),
1827 wxTAB_TRAVERSAL);
1828 m_panel = panel;
1829
1830 // Column
1831 wxBoxSizer* topSizer = new wxBoxSizer ( wxVERTICAL );
1832
1833 m_topSizer = topSizer;
1834 }
1835
1836 void FormMain::FinalizePanel( bool wasCreated )
1837 {
1838 // Button for tab traversal testing
1839 m_topSizer->Add( new wxButton(m_panel, wxID_ANY,
1840 wxS("Should be able to move here with Tab")),
1841 0, wxEXPAND );
1842
1843 m_panel->SetSizer( m_topSizer );
1844 m_topSizer->SetSizeHints( m_panel );
1845
1846 wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
1847 panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE );
1848
1849 SetSizer( panelSizer );
1850 panelSizer->SetSizeHints( this );
1851
1852 if ( wasCreated )
1853 FinalizeFramePosition();
1854 }
1855
1856 void FormMain::PopulateGrid()
1857 {
1858 wxPropertyGridManager* pgman = m_pPropGridManager;
1859 pgman->AddPage(wxT("Standard Items"));
1860
1861 PopulateWithStandardItems();
1862
1863 pgman->AddPage(wxT("wxWidgets Library Config"));
1864
1865 PopulateWithLibraryConfig();
1866
1867 wxPropertyGridPage* myPage = new wxMyPropertyGridPage();
1868 myPage->Append( new wxIntProperty ( wxT("IntProperty"), wxPG_LABEL, 12345678 ) );
1869
1870 // Use wxMyPropertyGridPage (see above) to test the
1871 // custom wxPropertyGridPage feature.
1872 pgman->AddPage(wxT("Examples"),wxNullBitmap,myPage);
1873
1874 PopulateWithExamples();
1875 }
1876
1877 void FormMain::CreateGrid( int style, int extraStyle )
1878 {
1879 //
1880 // This function (re)creates the property grid in our sample
1881 //
1882
1883 if ( style == -1 )
1884 style = // default style
1885 wxPG_BOLD_MODIFIED |
1886 wxPG_SPLITTER_AUTO_CENTER |
1887 wxPG_AUTO_SORT |
1888 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1889 //wxPG_TOOLTIPS |
1890 //wxPG_HIDE_CATEGORIES |
1891 //wxPG_LIMITED_EDITING |
1892 wxPG_TOOLBAR |
1893 wxPG_DESCRIPTION;
1894
1895 if ( extraStyle == -1 )
1896 // default extra style
1897 extraStyle = wxPG_EX_MODE_BUTTONS |
1898 wxPG_EX_MULTIPLE_SELECTION;
1899 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
1900 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
1901 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
1902 //| wxPG_EX_HELP_AS_TOOLTIPS
1903
1904 bool wasCreated = m_panel ? false : true;
1905
1906 InitPanel();
1907
1908 //
1909 // This shows how to combine two static choice descriptors
1910 m_combinedFlags.Add( _fs_windowstyle_labels, _fs_windowstyle_values );
1911 m_combinedFlags.Add( _fs_framestyle_labels, _fs_framestyle_values );
1912
1913 wxPropertyGridManager* pgman = m_pPropGridManager =
1914 new wxPropertyGridManager(m_panel,
1915 // Don't change this into wxID_ANY in the sample, or the
1916 // event handling will obviously be broken.
1917 PGID, /*wxID_ANY*/
1918 wxDefaultPosition,
1919 wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
1920 // But calling SetInitialSize in manager changes the code
1921 // order to the grid gets created immediately, before SetExtraStyle
1922 // is called.
1923 style );
1924
1925 m_propGrid = pgman->GetGrid();
1926
1927 pgman->SetExtraStyle(extraStyle);
1928
1929 // This is the default validation failure behavior
1930 m_pPropGridManager->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL |
1931 wxPG_VFB_SHOW_MESSAGEBOX );
1932
1933 m_pPropGridManager->GetGrid()->SetVerticalSpacing( 2 );
1934
1935 //
1936 // Set somewhat different unspecified value appearance
1937 wxPGCell cell;
1938 cell.SetText("Unspecified");
1939 cell.SetFgCol(*wxLIGHT_GREY);
1940 m_propGrid->SetUnspecifiedValueAppearance(cell);
1941
1942 PopulateGrid();
1943
1944 // Change some attributes in all properties
1945 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true);
1946 //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX,true);
1947
1948 //m_pPropGridManager->SetSplitterLeft(true);
1949 //m_pPropGridManager->SetSplitterPosition(137);
1950
1951 /*
1952 // This would setup event handling without event table entries
1953 Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED,
1954 wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) );
1955 Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED,
1956 wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) );
1957 */
1958
1959 m_topSizer->Add( m_pPropGridManager, 1, wxEXPAND );
1960
1961 FinalizePanel(wasCreated);
1962 }
1963
1964 // -----------------------------------------------------------------------
1965
1966 FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size) :
1967 wxFrame((wxFrame *)NULL, -1, title, pos, size,
1968 (wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCAPTION|
1969 wxTAB_TRAVERSAL|wxCLOSE_BOX|wxNO_FULL_REPAINT_ON_RESIZE) )
1970 {
1971 SetIcon(wxICON(sample));
1972
1973 m_propGrid = NULL;
1974 m_panel = NULL;
1975
1976 #ifdef __WXMAC__
1977 // we need this in order to allow the about menu relocation, since ABOUT is
1978 // not the default id of the about menu
1979 wxApp::s_macAboutMenuItemId = ID_ABOUT;
1980 #endif
1981
1982 #if wxUSE_IMAGE
1983 // This is here to really test the wxImageFileProperty.
1984 wxInitAllImageHandlers();
1985 #endif
1986
1987 // Register all editors (SpinCtrl etc.)
1988 m_pPropGridManager->RegisterAdditionalEditors();
1989
1990 // Register our sample custom editors
1991 m_pSampleMultiButtonEditor =
1992 wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
1993
1994 CreateGrid( // style
1995 wxPG_BOLD_MODIFIED |
1996 wxPG_SPLITTER_AUTO_CENTER |
1997 wxPG_AUTO_SORT |
1998 //wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
1999 //wxPG_TOOLTIPS |
2000 //wxPG_HIDE_CATEGORIES |
2001 //wxPG_LIMITED_EDITING |
2002 wxPG_TOOLBAR |
2003 wxPG_DESCRIPTION,
2004 // extra style
2005 wxPG_EX_MODE_BUTTONS |
2006 wxPG_EX_MULTIPLE_SELECTION
2007 //| wxPG_EX_AUTO_UNSPECIFIED_VALUES
2008 //| wxPG_EX_GREY_LABEL_WHEN_DISABLED
2009 //| wxPG_EX_NATIVE_DOUBLE_BUFFERING
2010 //| wxPG_EX_HELP_AS_TOOLTIPS
2011 );
2012
2013 //
2014 // Create menubar
2015 wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
2016 wxMenu *menuTry = new wxMenu;
2017 wxMenu *menuTools1 = new wxMenu;
2018 wxMenu *menuTools2 = new wxMenu;
2019 wxMenu *menuHelp = new wxMenu;
2020
2021 menuHelp->Append(ID_ABOUT, wxT("&About..."), wxT("Show about dialog") );
2022
2023 menuTools1->Append(ID_APPENDPROP, wxT("Append New Property") );
2024 menuTools1->Append(ID_APPENDCAT, wxT("Append New Category\tCtrl-S") );
2025 menuTools1->AppendSeparator();
2026 menuTools1->Append(ID_INSERTPROP, wxT("Insert New Property\tCtrl-Q") );
2027 menuTools1->Append(ID_INSERTCAT, wxT("Insert New Category\tCtrl-W") );
2028 menuTools1->AppendSeparator();
2029 menuTools1->Append(ID_DELETE, wxT("Delete Selected") );
2030 menuTools1->Append(ID_DELETER, wxT("Delete Random") );
2031 menuTools1->Append(ID_DELETEALL, wxT("Delete All") );
2032 menuTools1->AppendSeparator();
2033 menuTools1->Append(ID_SETBGCOLOUR, wxT("Set Bg Colour") );
2034 menuTools1->Append(ID_SETBGCOLOURRECUR, wxT("Set Bg Colour (Recursively)") );
2035 menuTools1->Append(ID_UNSPECIFY, "Set Value to Unspecified");
2036 menuTools1->AppendSeparator();
2037 m_itemEnable = menuTools1->Append(ID_ENABLE, wxT("Enable"),
2038 wxT("Toggles item's enabled state.") );
2039 m_itemEnable->Enable( FALSE );
2040 menuTools1->Append(ID_HIDE, "Hide", "Hides a property" );
2041 menuTools1->Append(ID_SETREADONLY, "Set as Read-Only",
2042 "Set property as read-only" );
2043
2044 menuTools2->Append(ID_ITERATE1, wxT("Iterate Over Properties") );
2045 menuTools2->Append(ID_ITERATE2, wxT("Iterate Over Visible Items") );
2046 menuTools2->Append(ID_ITERATE3, wxT("Reverse Iterate Over Properties") );
2047 menuTools2->Append(ID_ITERATE4, wxT("Iterate Over Categories") );
2048 menuTools2->AppendSeparator();
2049 menuTools2->Append(ID_ONEXTENDEDKEYNAV, "Extend Keyboard Navigation",
2050 "This will set Enter to navigate to next property, "
2051 "and allows arrow keys to navigate even when in "
2052 "editor control.");
2053 menuTools2->AppendSeparator();
2054 menuTools2->Append(ID_SETPROPERTYVALUE, wxT("Set Property Value") );
2055 menuTools2->Append(ID_CLEARMODIF, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
2056 menuTools2->AppendSeparator();
2057 m_itemFreeze = menuTools2->AppendCheckItem(ID_FREEZE, wxT("Freeze"),
2058 wxT("Disables painting, auto-sorting, etc.") );
2059 menuTools2->AppendSeparator();
2060 menuTools2->Append(ID_DUMPLIST, wxT("Display Values as wxVariant List"), wxT("Tests GetAllValues method and wxVariant conversion.") );
2061 menuTools2->AppendSeparator();
2062 menuTools2->Append(ID_GETVALUES, wxT("Get Property Values"), wxT("Stores all property values.") );
2063 menuTools2->Append(ID_SETVALUES, wxT("Set Property Values"), wxT("Reverts property values to those last stored.") );
2064 menuTools2->Append(ID_SETVALUES2, wxT("Set Property Values 2"), wxT("Adds property values that should not initially be as items (so new items are created).") );
2065 menuTools2->AppendSeparator();
2066 menuTools2->Append(ID_SAVESTATE, wxT("Save Editable State") );
2067 menuTools2->Append(ID_RESTORESTATE, wxT("Restore Editable State") );
2068 menuTools2->AppendSeparator();
2069 menuTools2->Append(ID_ENABLECOMMONVALUES, wxT("Enable Common Value"),
2070 wxT("Enable values that are common to all properties, for selected property."));
2071 menuTools2->AppendSeparator();
2072 menuTools2->Append(ID_COLLAPSE, wxT("Collapse Selected") );
2073 menuTools2->Append(ID_COLLAPSEALL, wxT("Collapse All") );
2074 menuTools2->AppendSeparator();
2075 menuTools2->Append(ID_INSERTPAGE, wxT("Add Page") );
2076 menuTools2->Append(ID_REMOVEPAGE, wxT("Remove Page") );
2077 menuTools2->AppendSeparator();
2078 menuTools2->Append(ID_FITCOLUMNS, wxT("Fit Columns") );
2079 m_itemVetoDragging =
2080 menuTools2->AppendCheckItem(ID_VETOCOLDRAG,
2081 "Veto Column Dragging");
2082 menuTools2->AppendSeparator();
2083 menuTools2->Append(ID_CHANGEFLAGSITEMS, wxT("Change Children of FlagsProp") );
2084 menuTools2->AppendSeparator();
2085 menuTools2->Append(ID_TESTINSERTCHOICE, wxT("Test InsertPropertyChoice") );
2086 menuTools2->Append(ID_TESTDELETECHOICE, wxT("Test DeletePropertyChoice") );
2087 menuTools2->AppendSeparator();
2088 menuTools2->Append(ID_SETSPINCTRLEDITOR, wxT("Use SpinCtrl Editor") );
2089 menuTools2->Append(ID_TESTREPLACE, wxT("Test ReplaceProperty") );
2090
2091 menuTry->Append(ID_SELECTSTYLE, wxT("Set Window Style"),
2092 wxT("Select window style flags used by the grid."));
2093 menuTry->Append(ID_ENABLELABELEDITING, "Enable label editing",
2094 "This calls wxPropertyGrid::MakeColumnEditable(0)");
2095 menuTry->AppendCheckItem(ID_SHOWHEADER,
2096 "Enable header",
2097 "This calls wxPropertyGridManager::ShowHeader()");
2098 menuTry->AppendSeparator();
2099 menuTry->AppendRadioItem( ID_COLOURSCHEME1, wxT("Standard Colour Scheme") );
2100 menuTry->AppendRadioItem( ID_COLOURSCHEME2, wxT("White Colour Scheme") );
2101 menuTry->AppendRadioItem( ID_COLOURSCHEME3, wxT(".NET Colour Scheme") );
2102 menuTry->AppendRadioItem( ID_COLOURSCHEME4, wxT("Cream Colour Scheme") );
2103 menuTry->AppendSeparator();
2104 m_itemCatColours = menuTry->AppendCheckItem(ID_CATCOLOURS, wxT("Category Specific Colours"),
2105 wxT("Switches between category-specific cell colours and default scheme (actually done using SetPropertyTextColour and SetPropertyBackgroundColour).") );
2106 menuTry->AppendSeparator();
2107 menuTry->AppendCheckItem(ID_STATICLAYOUT, wxT("Static Layout"),
2108 wxT("Switches between user-modifiedable and static layouts.") );
2109 menuTry->Append(ID_SETCOLUMNS, wxT("Set Number of Columns") );
2110 menuTry->AppendSeparator();
2111 menuTry->Append(ID_TESTXRC, wxT("Display XRC sample") );
2112 menuTry->AppendSeparator();
2113 menuTry->Append(ID_RUNTESTFULL, wxT("Run Tests (full)") );
2114 menuTry->Append(ID_RUNTESTPARTIAL, wxT("Run Tests (fast)") );
2115
2116 menuFile->Append(ID_RUNMINIMAL, wxT("Run Minimal Sample") );
2117 menuFile->AppendSeparator();
2118 menuFile->Append(ID_QUIT, wxT("E&xit\tAlt-X"), wxT("Quit this program") );
2119
2120 // Now append the freshly created menu to the menu bar...
2121 wxMenuBar *menuBar = new wxMenuBar();
2122 menuBar->Append(menuFile, wxT("&File") );
2123 menuBar->Append(menuTry, wxT("&Try These!") );
2124 menuBar->Append(menuTools1, wxT("&Basic") );
2125 menuBar->Append(menuTools2, wxT("&Advanced") );
2126 menuBar->Append(menuHelp, wxT("&Help") );
2127
2128 // ... and attach this menu bar to the frame
2129 SetMenuBar(menuBar);
2130
2131 #if wxUSE_STATUSBAR
2132 // create a status bar
2133 CreateStatusBar(1);
2134 SetStatusText(wxEmptyString);
2135 #endif // wxUSE_STATUSBAR
2136
2137 FinalizeFramePosition();
2138
2139 #if wxUSE_LOGWINDOW
2140 // Create log window
2141 m_logWindow = new wxLogWindow(this, "Log Messages", false);
2142 m_logWindow->GetFrame()->Move(GetPosition().x + GetSize().x + 10,
2143 GetPosition().y);
2144 m_logWindow->Show();
2145 #endif
2146 }
2147
2148 void FormMain::FinalizeFramePosition()
2149 {
2150 wxSize frameSize((wxSystemSettings::GetMetric(wxSYS_SCREEN_X)/10)*4,
2151 (wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)/10)*8);
2152
2153 if ( frameSize.x > 500 )
2154 frameSize.x = 500;
2155
2156 SetSize(frameSize);
2157
2158 Centre();
2159 }
2160
2161 //
2162 // Normally, wxPropertyGrid does not check whether item with identical
2163 // label already exists. However, since in this sample we use labels for
2164 // identifying properties, we have to be sure not to generate identical
2165 // labels.
2166 //
2167 void GenerateUniquePropertyLabel( wxPropertyGridManager* pg, wxString& baselabel )
2168 {
2169 int count = -1;
2170 wxString newlabel;
2171
2172 if ( pg->GetPropertyByLabel( baselabel ) )
2173 {
2174 for (;;)
2175 {
2176 count++;
2177 newlabel.Printf(wxT("%s%i"),baselabel.c_str(),count);
2178 if ( !pg->GetPropertyByLabel( newlabel ) ) break;
2179 }
2180 }
2181
2182 if ( count >= 0 )
2183 {
2184 baselabel = newlabel;
2185 }
2186 }
2187
2188 // -----------------------------------------------------------------------
2189
2190 void FormMain::OnInsertPropClick( wxCommandEvent& WXUNUSED(event) )
2191 {
2192 wxString propLabel;
2193
2194 if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
2195 {
2196 wxMessageBox(wxT("No items to relate - first add some with Append."));
2197 return;
2198 }
2199
2200 wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
2201 if ( !id )
2202 {
2203 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2204 return;
2205 }
2206 if ( propLabel.Len() < 1 ) propLabel = wxT("Property");
2207
2208 GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
2209
2210 m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id),
2211 id->GetIndexInParent(),
2212 new wxStringProperty(propLabel) );
2213
2214 }
2215
2216 // -----------------------------------------------------------------------
2217
2218 void FormMain::OnAppendPropClick( wxCommandEvent& WXUNUSED(event) )
2219 {
2220 wxString propLabel;
2221
2222 if ( propLabel.Len() < 1 ) propLabel = wxT("Property");
2223
2224 GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
2225
2226 m_pPropGridManager->Append( new wxStringProperty(propLabel) );
2227
2228 m_pPropGridManager->Refresh();
2229 }
2230
2231 // -----------------------------------------------------------------------
2232
2233 void FormMain::OnClearClick( wxCommandEvent& WXUNUSED(event) )
2234 {
2235 m_pPropGridManager->GetGrid()->Clear();
2236 }
2237
2238 // -----------------------------------------------------------------------
2239
2240 void FormMain::OnAppendCatClick( wxCommandEvent& WXUNUSED(event) )
2241 {
2242 wxString propLabel;
2243
2244 if ( propLabel.Len() < 1 ) propLabel = wxT("Category");
2245
2246 GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
2247
2248 m_pPropGridManager->Append( new wxPropertyCategory (propLabel) );
2249
2250 m_pPropGridManager->Refresh();
2251
2252 }
2253
2254 // -----------------------------------------------------------------------
2255
2256 void FormMain::OnInsertCatClick( wxCommandEvent& WXUNUSED(event) )
2257 {
2258 wxString propLabel;
2259
2260 if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
2261 {
2262 wxMessageBox(wxT("No items to relate - first add some with Append."));
2263 return;
2264 }
2265
2266 wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
2267 if ( !id )
2268 {
2269 wxMessageBox(wxT("First select a property - new one will be inserted right before that."));
2270 return;
2271 }
2272
2273 if ( propLabel.Len() < 1 ) propLabel = wxT("Category");
2274
2275 GenerateUniquePropertyLabel( m_pPropGridManager, propLabel );
2276
2277 m_pPropGridManager->Insert( m_pPropGridManager->GetPropertyParent(id),
2278 id->GetIndexInParent(),
2279 new wxPropertyCategory (propLabel) );
2280 }
2281
2282 // -----------------------------------------------------------------------
2283
2284 void FormMain::OnDelPropClick( wxCommandEvent& WXUNUSED(event) )
2285 {
2286 wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
2287 if ( !id )
2288 {
2289 wxMessageBox(wxT("First select a property."));
2290 return;
2291 }
2292
2293 m_pPropGridManager->DeleteProperty( id );
2294 }
2295
2296 // -----------------------------------------------------------------------
2297
2298 void FormMain::OnDelPropRClick( wxCommandEvent& WXUNUSED(event) )
2299 {
2300 // Delete random property
2301 wxPGProperty* p = m_pPropGridManager->GetGrid()->GetRoot();
2302
2303 for (;;)
2304 {
2305 if ( !p->IsCategory() )
2306 {
2307 m_pPropGridManager->DeleteProperty( p );
2308 break;
2309 }
2310
2311 if ( !p->GetChildCount() )
2312 break;
2313
2314 int n = rand() % ((int)p->GetChildCount());
2315
2316 p = p->Item(n);
2317 }
2318 }
2319
2320 // -----------------------------------------------------------------------
2321
2322 void FormMain::OnContextMenu( wxContextMenuEvent& event )
2323 {
2324 wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"),
2325 event.GetPosition().x,event.GetPosition().y);
2326
2327 wxUnusedVar(event);
2328
2329 //event.Skip();
2330 }
2331
2332 // -----------------------------------------------------------------------
2333
2334 void FormMain::OnCloseClick( wxCommandEvent& WXUNUSED(event) )
2335 {
2336 /*#ifdef __WXDEBUG__
2337 m_pPropGridManager->GetGrid()->DumpAllocatedChoiceSets();
2338 wxLogDebug(wxT("\\-> Don't worry, this is perfectly normal in this sample."));
2339 #endif*/
2340
2341 Close(false);
2342 }
2343
2344 // -----------------------------------------------------------------------
2345
2346 int IterateMessage( wxPGProperty* prop )
2347 {
2348 wxString s;
2349
2350 s.Printf( wxT("\"%s\" class = %s, valuetype = %s"), prop->GetLabel().c_str(),
2351 prop->GetClassInfo()->GetClassName(), prop->GetValueType().c_str() );
2352
2353 return wxMessageBox( s, wxT("Iterating... (press CANCEL to end)"), wxOK|wxCANCEL );
2354 }
2355
2356 // -----------------------------------------------------------------------
2357
2358 void FormMain::OnIterate1Click( wxCommandEvent& WXUNUSED(event) )
2359 {
2360 wxPropertyGridIterator it;
2361
2362 for ( it = m_pPropGridManager->GetCurrentPage()->
2363 GetIterator();
2364 !it.AtEnd();
2365 it++ )
2366 {
2367 wxPGProperty* p = *it;
2368 int res = IterateMessage( p );
2369 if ( res == wxCANCEL ) break;
2370 }
2371 }
2372
2373 // -----------------------------------------------------------------------
2374
2375 void FormMain::OnIterate2Click( wxCommandEvent& WXUNUSED(event) )
2376 {
2377 wxPropertyGridIterator it;
2378
2379 for ( it = m_pPropGridManager->GetCurrentPage()->
2380 GetIterator( wxPG_ITERATE_VISIBLE );
2381 !it.AtEnd();
2382 it++ )
2383 {
2384 wxPGProperty* p = *it;
2385
2386 int res = IterateMessage( p );
2387 if ( res == wxCANCEL ) break;
2388 }
2389 }
2390
2391 // -----------------------------------------------------------------------
2392
2393 void FormMain::OnIterate3Click( wxCommandEvent& WXUNUSED(event) )
2394 {
2395 // iterate over items in reverse order
2396 wxPropertyGridIterator it;
2397
2398 for ( it = m_pPropGridManager->GetCurrentPage()->
2399 GetIterator( wxPG_ITERATE_DEFAULT, wxBOTTOM );
2400 !it.AtEnd();
2401 it-- )
2402 {
2403 wxPGProperty* p = *it;
2404
2405 int res = IterateMessage( p );
2406 if ( res == wxCANCEL ) break;
2407 }
2408 }
2409
2410 // -----------------------------------------------------------------------
2411
2412 void FormMain::OnIterate4Click( wxCommandEvent& WXUNUSED(event) )
2413 {
2414 wxPropertyGridIterator it;
2415
2416 for ( it = m_pPropGridManager->GetCurrentPage()->
2417 GetIterator( wxPG_ITERATE_CATEGORIES );
2418 !it.AtEnd();
2419 it++ )
2420 {
2421 wxPGProperty* p = *it;
2422
2423 int res = IterateMessage( p );
2424 if ( res == wxCANCEL ) break;
2425 }
2426 }
2427
2428 // -----------------------------------------------------------------------
2429
2430 void FormMain::OnExtendedKeyNav( wxCommandEvent& WXUNUSED(event) )
2431 {
2432 // Use AddActionTrigger() and DedicateKey() to set up Enter,
2433 // Up, and Down keys for navigating between properties.
2434 wxPropertyGrid* propGrid = m_pPropGridManager->GetGrid();
2435
2436 propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
2437 WXK_RETURN);
2438 propGrid->DedicateKey(WXK_RETURN);
2439
2440 // Up and Down keys are alredy associated with navigation,
2441 // but we must also prevent them from being eaten by
2442 // editor controls.
2443 propGrid->DedicateKey(WXK_UP);
2444 propGrid->DedicateKey(WXK_DOWN);
2445 }
2446
2447 // -----------------------------------------------------------------------
2448
2449 void FormMain::OnFitColumnsClick( wxCommandEvent& WXUNUSED(event) )
2450 {
2451 wxPropertyGridPage* page = m_pPropGridManager->GetCurrentPage();
2452
2453 // Remove auto-centering
2454 m_pPropGridManager->SetWindowStyle( m_pPropGridManager->GetWindowStyle() & ~wxPG_SPLITTER_AUTO_CENTER);
2455
2456 // Grow manager size just prior fit - otherwise
2457 // column information may be lost.
2458 wxSize oldGridSize = m_pPropGridManager->GetGrid()->GetClientSize();
2459 wxSize oldFullSize = GetSize();
2460 SetSize(1000, oldFullSize.y);
2461
2462 wxSize newSz = page->FitColumns();
2463
2464 int dx = oldFullSize.x - oldGridSize.x;
2465 int dy = oldFullSize.y - oldGridSize.y;
2466
2467 newSz.x += dx;
2468 newSz.y += dy;
2469
2470 SetSize(newSz);
2471 }
2472
2473 // -----------------------------------------------------------------------
2474
2475 void FormMain::OnChangeFlagsPropItemsClick( wxCommandEvent& WXUNUSED(event) )
2476 {
2477 wxPGProperty* p = m_pPropGridManager->GetPropertyByName(wxT("Window Styles"));
2478
2479 wxPGChoices newChoices;
2480
2481 newChoices.Add(wxT("Fast"),0x1);
2482 newChoices.Add(wxT("Powerful"),0x2);
2483 newChoices.Add(wxT("Safe"),0x4);
2484 newChoices.Add(wxT("Sleek"),0x8);
2485
2486 p->SetChoices(newChoices);
2487 }
2488
2489 // -----------------------------------------------------------------------
2490
2491 void FormMain::OnEnableDisable( wxCommandEvent& )
2492 {
2493 wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
2494 if ( !id )
2495 {
2496 wxMessageBox(wxT("First select a property."));
2497 return;
2498 }
2499
2500 if ( m_pPropGridManager->IsPropertyEnabled( id ) )
2501 {
2502 m_pPropGridManager->DisableProperty ( id );
2503 m_itemEnable->SetItemLabel( wxT("Enable") );
2504 }
2505 else
2506 {
2507 m_pPropGridManager->EnableProperty ( id );
2508 m_itemEnable->SetItemLabel( wxT("Disable") );
2509 }
2510 }
2511
2512 // -----------------------------------------------------------------------
2513
2514 void FormMain::OnSetReadOnly( wxCommandEvent& WXUNUSED(event) )
2515 {
2516 wxPGProperty* p = m_pPropGridManager->GetGrid()->GetSelection();
2517 if ( !p )
2518 {
2519 wxMessageBox(wxT("First select a property."));
2520 return;
2521 }
2522 m_pPropGridManager->SetPropertyReadOnly(p);
2523 }
2524
2525 // -----------------------------------------------------------------------
2526
2527 void FormMain::OnHide( wxCommandEvent& WXUNUSED(event) )
2528 {
2529 wxPGProperty* id = m_pPropGridManager->GetGrid()->GetSelection();
2530 if ( !id )
2531 {
2532 wxMessageBox(wxT("First select a property."));
2533 return;
2534 }
2535
2536 m_pPropGridManager->HideProperty( id, true );
2537 }
2538
2539 // -----------------------------------------------------------------------
2540
2541 #include "wx/colordlg.h"
2542
2543 void
2544 FormMain::OnSetBackgroundColour( wxCommandEvent& event )
2545 {
2546 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2547 wxPGProperty* prop = pg->GetSelection();
2548 if ( !prop )
2549 {
2550 wxMessageBox(wxT("First select a property."));
2551 return;
2552 }
2553
2554 wxColour col = ::wxGetColourFromUser(this, *wxWHITE, "Choose colour");
2555
2556 if ( col.IsOk() )
2557 {
2558 bool recursively = (event.GetId()==ID_SETBGCOLOURRECUR) ? true : false;
2559 pg->SetPropertyBackgroundColour(prop, col, recursively);
2560 }
2561 }
2562
2563 // -----------------------------------------------------------------------
2564
2565 void FormMain::OnInsertPage( wxCommandEvent& WXUNUSED(event) )
2566 {
2567 m_pPropGridManager->AddPage(wxT("New Page"));
2568 }
2569
2570 // -----------------------------------------------------------------------
2571
2572 void FormMain::OnRemovePage( wxCommandEvent& WXUNUSED(event) )
2573 {
2574 m_pPropGridManager->RemovePage(m_pPropGridManager->GetSelectedPage());
2575 }
2576
2577 // -----------------------------------------------------------------------
2578
2579 void FormMain::OnSaveState( wxCommandEvent& WXUNUSED(event) )
2580 {
2581 m_savedState = m_pPropGridManager->SaveEditableState();
2582 wxLogDebug(wxT("Saved editable state string: \"%s\""), m_savedState.c_str());
2583 }
2584
2585 // -----------------------------------------------------------------------
2586
2587 void FormMain::OnRestoreState( wxCommandEvent& WXUNUSED(event) )
2588 {
2589 m_pPropGridManager->RestoreEditableState(m_savedState);
2590 }
2591
2592 // -----------------------------------------------------------------------
2593
2594 void FormMain::OnSetSpinCtrlEditorClick( wxCommandEvent& WXUNUSED(event) )
2595 {
2596 #if wxUSE_SPINBTN
2597 wxPGProperty* pgId = m_pPropGridManager->GetSelection();
2598 if ( pgId )
2599 m_pPropGridManager->SetPropertyEditor( pgId, wxPGEditor_SpinCtrl );
2600 else
2601 wxMessageBox(wxT("First select a property"));
2602 #endif
2603 }
2604
2605 // -----------------------------------------------------------------------
2606
2607 void FormMain::OnTestReplaceClick( wxCommandEvent& WXUNUSED(event) )
2608 {
2609 wxPGProperty* pgId = m_pPropGridManager->GetSelection();
2610 if ( pgId )
2611 {
2612 wxPGChoices choices;
2613 choices.Add(wxT("Flag 0"),0x0001);
2614 choices.Add(wxT("Flag 1"),0x0002);
2615 choices.Add(wxT("Flag 2"),0x0004);
2616 choices.Add(wxT("Flag 3"),0x0008);
2617 wxPGProperty* newId = m_pPropGridManager->ReplaceProperty( pgId,
2618 new wxFlagsProperty(wxT("ReplaceFlagsProperty"), wxPG_LABEL, choices, 0x0003) );
2619 m_pPropGridManager->SetPropertyAttribute( newId,
2620 wxPG_BOOL_USE_CHECKBOX,
2621 true,
2622 wxPG_RECURSE );
2623 }
2624 else
2625 wxMessageBox(wxT("First select a property"));
2626 }
2627
2628 // -----------------------------------------------------------------------
2629
2630 void FormMain::OnClearModifyStatusClick( wxCommandEvent& WXUNUSED(event) )
2631 {
2632 m_pPropGridManager->ClearModifiedStatus();
2633 }
2634
2635 // -----------------------------------------------------------------------
2636
2637 // Freeze check-box checked?
2638 void FormMain::OnFreezeClick( wxCommandEvent& event )
2639 {
2640 if ( !m_pPropGridManager ) return;
2641
2642 if ( event.IsChecked() )
2643 {
2644 if ( !m_pPropGridManager->IsFrozen() )
2645 {
2646 m_pPropGridManager->Freeze();
2647 }
2648 }
2649 else
2650 {
2651 if ( m_pPropGridManager->IsFrozen() )
2652 {
2653 m_pPropGridManager->Thaw();
2654 m_pPropGridManager->Refresh();
2655 }
2656 }
2657 }
2658
2659 // -----------------------------------------------------------------------
2660
2661 void FormMain::OnEnableLabelEditing( wxCommandEvent& WXUNUSED(event) )
2662 {
2663 m_propGrid->MakeColumnEditable(0);
2664 }
2665
2666 // -----------------------------------------------------------------------
2667
2668 void FormMain::OnShowHeader( wxCommandEvent& event )
2669 {
2670 m_pPropGridManager->ShowHeader(event.IsChecked());
2671 m_pPropGridManager->SetColumnTitle(2, _("Units"));
2672 }
2673
2674 // -----------------------------------------------------------------------
2675
2676 void FormMain::OnAbout(wxCommandEvent& WXUNUSED(event))
2677 {
2678 wxString msg;
2679 msg.Printf( wxT("wxPropertyGrid Sample")
2680 #if wxUSE_UNICODE
2681 #if defined(wxUSE_UNICODE_UTF8) && wxUSE_UNICODE_UTF8
2682 wxT(" <utf-8>")
2683 #else
2684 wxT(" <unicode>")
2685 #endif
2686 #else
2687 wxT(" <ansi>")
2688 #endif
2689 #ifdef __WXDEBUG__
2690 wxT(" <debug>")
2691 #else
2692 wxT(" <release>")
2693 #endif
2694 wxT("\n\n")
2695 wxT("Programmed by %s\n\n")
2696 wxT("Using %s\n\n"),
2697 wxT("Jaakko Salli"), wxVERSION_STRING
2698 );
2699
2700 wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this);
2701 }
2702
2703 // -----------------------------------------------------------------------
2704
2705 void FormMain::OnColourScheme( wxCommandEvent& event )
2706 {
2707 int id = event.GetId();
2708 if ( id == ID_COLOURSCHEME1 )
2709 {
2710 m_pPropGridManager->GetGrid()->ResetColours();
2711 }
2712 else if ( id == ID_COLOURSCHEME2 )
2713 {
2714 // white
2715 wxColour my_grey_1(212,208,200);
2716 wxColour my_grey_3(113,111,100);
2717 m_pPropGridManager->Freeze();
2718 m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE );
2719 m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE );
2720 m_pPropGridManager->GetGrid()->SetCellBackgroundColour( *wxWHITE );
2721 m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 );
2722 m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 ); //wxColour(160,160,160)
2723 m_pPropGridManager->Thaw();
2724 }
2725 else if ( id == ID_COLOURSCHEME3 )
2726 {
2727 // .NET
2728 wxColour my_grey_1(212,208,200);
2729 wxColour my_grey_2(236,233,216);
2730 m_pPropGridManager->Freeze();
2731 m_pPropGridManager->GetGrid()->SetMarginColour( my_grey_1 );
2732 m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( my_grey_1 );
2733 m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 );
2734 m_pPropGridManager->Thaw();
2735 }
2736 else if ( id == ID_COLOURSCHEME4 )
2737 {
2738 // cream
2739
2740 wxColour my_grey_1(212,208,200);
2741 wxColour my_grey_2(241,239,226);
2742 wxColour my_grey_3(113,111,100);
2743 m_pPropGridManager->Freeze();
2744 m_pPropGridManager->GetGrid()->SetMarginColour( *wxWHITE );
2745 m_pPropGridManager->GetGrid()->SetCaptionBackgroundColour( *wxWHITE );
2746 m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 );
2747 m_pPropGridManager->GetGrid()->SetCellBackgroundColour( my_grey_2 );
2748 m_pPropGridManager->GetGrid()->SetCellTextColour( my_grey_3 );
2749 m_pPropGridManager->GetGrid()->SetLineColour( my_grey_1 );
2750 m_pPropGridManager->Thaw();
2751 }
2752 }
2753
2754 // -----------------------------------------------------------------------
2755
2756 void FormMain::OnCatColours( wxCommandEvent& event )
2757 {
2758 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2759 m_pPropGridManager->Freeze();
2760
2761 if ( event.IsChecked() )
2762 {
2763 // Set custom colours.
2764 pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,0), false );
2765 pg->SetPropertyBackgroundColour( wxT("Appearance"), wxColour(255,255,183) );
2766 pg->SetPropertyTextColour( wxT("Appearance"), wxColour(255,0,183) );
2767 pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(0,255,0), false );
2768 pg->SetPropertyBackgroundColour( wxT("PositionCategory"), wxColour(255,226,190) );
2769 pg->SetPropertyTextColour( wxT("PositionCategory"), wxColour(255,0,190) );
2770 pg->SetPropertyTextColour( wxT("Environment"), wxColour(0,0,255), false );
2771 pg->SetPropertyBackgroundColour( wxT("Environment"), wxColour(208,240,175) );
2772 pg->SetPropertyTextColour( wxT("Environment"), wxColour(255,255,255) );
2773 pg->SetPropertyBackgroundColour( wxT("More Examples"), wxColour(172,237,255) );
2774 pg->SetPropertyTextColour( wxT("More Examples"), wxColour(172,0,255) );
2775 }
2776 else
2777 {
2778 // Revert to original.
2779 pg->SetPropertyColoursToDefault( wxT("Appearance") );
2780 pg->SetPropertyColoursToDefault( wxT("PositionCategory") );
2781 pg->SetPropertyColoursToDefault( wxT("Environment") );
2782 pg->SetPropertyColoursToDefault( wxT("More Examples") );
2783 }
2784 m_pPropGridManager->Thaw();
2785 m_pPropGridManager->Refresh();
2786 }
2787
2788 // -----------------------------------------------------------------------
2789
2790 #define ADD_FLAG(FLAG) \
2791 chs.Add(wxT(#FLAG)); \
2792 vls.Add(FLAG); \
2793 if ( (flags & FLAG) == FLAG ) sel.Add(ind); \
2794 ind++;
2795
2796 void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) )
2797 {
2798 int style = 0;
2799 int extraStyle = 0;
2800
2801 {
2802 wxArrayString chs;
2803 wxArrayInt vls;
2804 wxArrayInt sel;
2805 unsigned int ind = 0;
2806 int flags = m_pPropGridManager->GetWindowStyle();
2807 ADD_FLAG(wxPG_HIDE_CATEGORIES)
2808 ADD_FLAG(wxPG_AUTO_SORT)
2809 ADD_FLAG(wxPG_BOLD_MODIFIED)
2810 ADD_FLAG(wxPG_SPLITTER_AUTO_CENTER)
2811 ADD_FLAG(wxPG_TOOLTIPS)
2812 ADD_FLAG(wxPG_STATIC_SPLITTER)
2813 ADD_FLAG(wxPG_HIDE_MARGIN)
2814 ADD_FLAG(wxPG_LIMITED_EDITING)
2815 ADD_FLAG(wxPG_TOOLBAR)
2816 ADD_FLAG(wxPG_DESCRIPTION)
2817 ADD_FLAG(wxPG_NO_INTERNAL_BORDER)
2818 wxMultiChoiceDialog dlg( this, wxT("Select window styles to use"),
2819 wxT("wxPropertyGrid Window Style"), chs );
2820 dlg.SetSelections(sel);
2821 if ( dlg.ShowModal() == wxID_CANCEL )
2822 return;
2823
2824 flags = 0;
2825 sel = dlg.GetSelections();
2826 for ( ind = 0; ind < sel.size(); ind++ )
2827 flags |= vls[sel[ind]];
2828
2829 style = flags;
2830 }
2831
2832 {
2833 wxArrayString chs;
2834 wxArrayInt vls;
2835 wxArrayInt sel;
2836 unsigned int ind = 0;
2837 int flags = m_pPropGridManager->GetExtraStyle();
2838 ADD_FLAG(wxPG_EX_INIT_NOCAT)
2839 ADD_FLAG(wxPG_EX_NO_FLAT_TOOLBAR)
2840 ADD_FLAG(wxPG_EX_MODE_BUTTONS)
2841 ADD_FLAG(wxPG_EX_HELP_AS_TOOLTIPS)
2842 ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING)
2843 ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES)
2844 ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES)
2845 ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS)
2846 ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION)
2847 ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING)
2848 ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER)
2849 ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR)
2850 wxMultiChoiceDialog dlg( this, wxT("Select extra window styles to use"),
2851 wxT("wxPropertyGrid Extra Style"), chs );
2852 dlg.SetSelections(sel);
2853 if ( dlg.ShowModal() == wxID_CANCEL )
2854 return;
2855
2856 flags = 0;
2857 sel = dlg.GetSelections();
2858 for ( ind = 0; ind < sel.size(); ind++ )
2859 flags |= vls[sel[ind]];
2860
2861 extraStyle = flags;
2862 }
2863
2864 CreateGrid( style, extraStyle );
2865
2866 FinalizeFramePosition();
2867 }
2868
2869 // -----------------------------------------------------------------------
2870
2871 void FormMain::OnSetColumns( wxCommandEvent& WXUNUSED(event) )
2872 {
2873 long colCount = ::wxGetNumberFromUser(wxT("Enter number of columns (2-20)."),wxT("Columns:"),
2874 wxT("Change Columns"),m_pPropGridManager->GetColumnCount(),
2875 2,20);
2876
2877 if ( colCount >= 2 )
2878 {
2879 m_pPropGridManager->SetColumnCount(colCount);
2880 }
2881 }
2882
2883 // -----------------------------------------------------------------------
2884
2885 void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) )
2886 {
2887 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2888 wxPGProperty* selected = pg->GetSelection();
2889
2890 if ( selected )
2891 {
2892 wxString value = ::wxGetTextFromUser( wxT("Enter new value:") );
2893 pg->SetPropertyValue( selected, value );
2894 }
2895 }
2896
2897 // -----------------------------------------------------------------------
2898
2899 void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) )
2900 {
2901 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2902
2903 wxPGProperty* selected = pg->GetSelection();
2904 const wxPGChoices& choices = selected->GetChoices();
2905
2906 // Insert new choice to the center of list
2907
2908 if ( choices.IsOk() )
2909 {
2910 int pos = choices.GetCount() / 2;
2911 selected->InsertChoice(wxT("New Choice"), pos);
2912 }
2913 else
2914 {
2915 ::wxMessageBox(wxT("First select a property with some choices."));
2916 }
2917 }
2918
2919 // -----------------------------------------------------------------------
2920
2921 void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) )
2922 {
2923 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2924
2925 wxPGProperty* selected = pg->GetSelection();
2926 const wxPGChoices& choices = selected->GetChoices();
2927
2928 // Deletes choice from the center of list
2929
2930 if ( choices.IsOk() )
2931 {
2932 int pos = choices.GetCount() / 2;
2933 selected->DeleteChoice(pos);
2934 }
2935 else
2936 {
2937 ::wxMessageBox(wxT("First select a property with some choices."));
2938 }
2939 }
2940
2941 // -----------------------------------------------------------------------
2942
2943 #include <wx/colordlg.h>
2944
2945 void FormMain::OnMisc ( wxCommandEvent& event )
2946 {
2947 int id = event.GetId();
2948 if ( id == ID_STATICLAYOUT )
2949 {
2950 long wsf = m_pPropGridManager->GetWindowStyleFlag();
2951 if ( event.IsChecked() ) m_pPropGridManager->SetWindowStyleFlag( wsf|wxPG_STATIC_LAYOUT );
2952 else m_pPropGridManager->SetWindowStyleFlag( wsf&~(wxPG_STATIC_LAYOUT) );
2953 }
2954 else if ( id == ID_COLLAPSEALL )
2955 {
2956 wxPGVIterator it;
2957 wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
2958
2959 for ( it = pg->GetVIterator( wxPG_ITERATE_ALL ); !it.AtEnd(); it.Next() )
2960 it.GetProperty()->SetExpanded( false );
2961
2962 pg->RefreshGrid();
2963 }
2964 else if ( id == ID_GETVALUES )
2965 {
2966 m_storedValues = m_pPropGridManager->GetGrid()->GetPropertyValues(wxT("Test"),
2967 m_pPropGridManager->GetGrid()->GetRoot(),
2968 wxPG_KEEP_STRUCTURE|wxPG_INC_ATTRIBUTES);
2969 }
2970 else if ( id == ID_SETVALUES )
2971 {
2972 if ( m_storedValues.GetType() == wxT("list") )
2973 {
2974 m_pPropGridManager->GetGrid()->SetPropertyValues(m_storedValues);
2975 }
2976 else
2977 wxMessageBox(wxT("First use Get Property Values."));
2978 }
2979 else if ( id == ID_SETVALUES2 )
2980 {
2981 wxVariant list;
2982 list.NullList();
2983 list.Append( wxVariant((long)1234,wxT("VariantLong")) );
2984 list.Append( wxVariant((bool)TRUE,wxT("VariantBool")) );
2985 list.Append( wxVariant(wxT("Test Text"),wxT("VariantString")) );
2986 m_pPropGridManager->GetGrid()->SetPropertyValues(list);
2987 }
2988 else if ( id == ID_COLLAPSE )
2989 {
2990 // Collapses selected.
2991 wxPGProperty* id = m_pPropGridManager->GetSelection();
2992 if ( id )
2993 {
2994 m_pPropGridManager->Collapse(id);
2995 }
2996 }
2997 else if ( id == ID_RUNTESTFULL )
2998 {
2999 // Runs a regression test.
3000 RunTests(true);
3001 }
3002 else if ( id == ID_RUNTESTPARTIAL )
3003 {
3004 // Runs a regression test.
3005 RunTests(false);
3006 }
3007 else if ( id == ID_UNSPECIFY )
3008 {
3009 wxPGProperty* prop = m_pPropGridManager->GetSelection();
3010 if ( prop )
3011 {
3012 m_pPropGridManager->SetPropertyValueUnspecified(prop);
3013 prop->RefreshEditor();
3014 }
3015 }
3016 }
3017
3018 // -----------------------------------------------------------------------
3019
3020 void FormMain::OnPopulateClick( wxCommandEvent& event )
3021 {
3022 int id = event.GetId();
3023 m_propGrid->Clear();
3024 m_propGrid->Freeze();
3025 if ( id == ID_POPULATE1 )
3026 {
3027 PopulateWithStandardItems();
3028 }
3029 else if ( id == ID_POPULATE2 )
3030 {
3031 PopulateWithLibraryConfig();
3032 }
3033 m_propGrid->Thaw();
3034 }
3035
3036 // -----------------------------------------------------------------------
3037
3038 void DisplayMinimalFrame(wxWindow* parent); // in minimal.cpp
3039
3040 void FormMain::OnRunMinimalClick( wxCommandEvent& WXUNUSED(event) )
3041 {
3042 DisplayMinimalFrame(this);
3043 }
3044
3045 // -----------------------------------------------------------------------
3046
3047 FormMain::~FormMain()
3048 {
3049 }
3050
3051 // -----------------------------------------------------------------------
3052
3053 IMPLEMENT_APP(cxApplication)
3054
3055 bool cxApplication::OnInit()
3056 {
3057 //wxLocale Locale;
3058 //Locale.Init(wxLANGUAGE_FINNISH);
3059
3060 FormMain* frame = Form1 = new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) );
3061 frame->Show(true);
3062
3063 //
3064 // Parse command-line
3065 wxApp& app = wxGetApp();
3066 if ( app.argc > 1 )
3067 {
3068 wxString s = app.argv[1];
3069 if ( s == wxT("--run-tests") )
3070 {
3071 //
3072 // Run tests
3073 bool testResult = frame->RunTests(true);
3074
3075 if ( testResult )
3076 return false;
3077 }
3078 }
3079
3080 return true;
3081 }
3082
3083 // -----------------------------------------------------------------------
3084
3085 void FormMain::OnIdle( wxIdleEvent& event )
3086 {
3087 /*
3088 // This code is useful for debugging focus problems
3089 static wxWindow* last_focus = (wxWindow*) NULL;
3090
3091 wxWindow* cur_focus = ::wxWindow::FindFocus();
3092
3093 if ( cur_focus != last_focus )
3094 {
3095 const wxChar* class_name = wxT("<none>");
3096 if ( cur_focus )
3097 class_name = cur_focus->GetClassInfo()->GetClassName();
3098 last_focus = cur_focus;
3099 wxLogDebug( wxT("FOCUSED: %s %X"),
3100 class_name,
3101 (unsigned int)cur_focus);
3102 }
3103 */
3104
3105 event.Skip();
3106 }
3107
3108 // -----------------------------------------------------------------------