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