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