]> git.saurik.com Git - wxWidgets.git/blob - samples/propgrid/propgrid_minimal.cpp
wxUSE_PROPGRID is now recognized by source and header files
[wxWidgets.git] / samples / propgrid / propgrid_minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/propgrid/propgrid_minimal.cpp
3 // Purpose: Minimal portion of wxPropertyGrid sample
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2008-08-23
7 // RCS-ID: $Id:
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wx.h"
13 #include "wx/propgrid/propgrid.h"
14
15 class MyFrame : public wxFrame
16 {
17 public:
18 MyFrame(wxWindow* parent);
19
20 void OnAction(wxCommandEvent& event);
21 void OnPropertyGridChange(wxPropertyGridEvent& event);
22
23 private:
24 wxPropertyGrid* m_pg;
25 DECLARE_EVENT_TABLE()
26 };
27
28 //
29 // Called from propgridsample.cpp
30 //
31 void DisplayMinimalFrame(wxWindow* parent)
32 {
33 MyFrame *frame = new MyFrame(parent);
34 frame->Show(true);
35 }
36
37 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
38 EVT_MENU(wxID_HIGHEST+1, MyFrame::OnAction)
39 EVT_PG_CHANGED( -1, MyFrame::OnPropertyGridChange )
40 END_EVENT_TABLE()
41
42 MyFrame::MyFrame(wxWindow* parent)
43 : wxFrame(parent, wxID_ANY, wxT("PropertyGrid Test"))
44 {
45 wxMenu *Menu = new wxMenu;
46 Menu->Append(wxID_HIGHEST+1, wxT("Action"));
47 wxMenuBar *MenuBar = new wxMenuBar();
48 MenuBar->Append(Menu, wxT("Action"));
49 SetMenuBar(MenuBar);
50
51 wxPropertyGrid *pg = new wxPropertyGrid(this,-1,wxDefaultPosition,wxSize(400,400),
52 wxPG_SPLITTER_AUTO_CENTER |
53 wxPG_BOLD_MODIFIED );
54 m_pg = pg;
55
56 for ( int i=0; i< 20; i++ )
57 pg->Append(new wxStringProperty(wxString::Format(wxT("Item %i"),i), wxPG_LABEL));
58
59 wxPGProperty* topId;
60 wxPGProperty* medId;
61 wxPGProperty* botId;
62
63 topId = pg->Append( new wxStringProperty(wxT("Top Item"), wxPG_LABEL, wxT("<composed>")) );
64 pg->LimitPropertyEditing(topId, true);
65 medId = pg->AppendIn( topId, new wxStringProperty(wxT("Medium Level Item A"), wxPG_LABEL, wxT("<composed>")) );
66 pg->LimitPropertyEditing(medId, true);
67 botId = pg->AppendIn( medId, new wxStringProperty(wxT("Position"), wxPG_LABEL, wxT("<composed>")) );
68 pg->LimitPropertyEditing(botId, true);
69 pg->AppendIn( botId, new wxFloatProperty(wxT("x"), wxPG_LABEL, 1.0) );
70 pg->AppendIn( botId, new wxFloatProperty(wxT("y"), wxPG_LABEL, 2.0) );
71 pg->AppendIn( botId, new wxFloatProperty(wxT("z"), wxPG_LABEL, 3.0) );
72 pg->AppendIn( medId, new wxStringProperty(wxT("Name"), wxPG_LABEL, wxT("name")) );
73 medId = pg->AppendIn( topId, new wxStringProperty(wxT("Medium Level Item B"), wxPG_LABEL, wxT("<composed>")) );
74 pg->LimitPropertyEditing(medId, true);
75 botId = pg->AppendIn( medId, new wxStringProperty(wxT("Position"), wxPG_LABEL, wxT("<composed>")) );
76 pg->LimitPropertyEditing(botId, true);
77 pg->AppendIn( botId, new wxFloatProperty(wxT("x"), wxPG_LABEL, 1.0) );
78 pg->AppendIn( botId, new wxFloatProperty(wxT("y"), wxPG_LABEL, 2.0) );
79 pg->AppendIn( botId, new wxFloatProperty(wxT("z"), wxPG_LABEL, 3.0) );
80 pg->AppendIn( medId, new wxStringProperty(wxT("Name"), wxPG_LABEL, wxT("name")) );
81 medId = pg->AppendIn( topId, new wxStringProperty(wxT("Medium Level Item C"), wxPG_LABEL, wxT("<composed>")) );
82 pg->LimitPropertyEditing(medId, true);
83 botId = pg->AppendIn( medId, new wxStringProperty(wxT("Position"), wxPG_LABEL, wxT("<composed>")) );
84 pg->LimitPropertyEditing(botId, true);
85 pg->AppendIn( botId, new wxFloatProperty(wxT("x"), wxPG_LABEL, 1.0) );
86 pg->AppendIn( botId, new wxFloatProperty(wxT("y"), wxPG_LABEL, 2.0) );
87 pg->AppendIn( botId, new wxFloatProperty(wxT("z"), wxPG_LABEL, 3.0) );
88 pg->AppendIn( medId, new wxStringProperty(wxT("Name"), wxPG_LABEL, wxT("name")) );
89
90 SetSize(400, 600);
91 }
92
93 void MyFrame::OnPropertyGridChange(wxPropertyGridEvent &event)
94 {
95 wxPGProperty* p = event.GetProperty();
96
97 wxLogDebug(wxT("OnPropertyGridChange(%s)"), p->GetName().c_str());
98
99 if ( p->GetBaseName() == wxT("x") )
100 {
101 wxLogDebug(wxT("double values=%.2f)"), m_pg->GetPropertyValueAsDouble(p));
102 }
103 }
104
105 void MyFrame::OnAction(wxCommandEvent &)
106 {
107 }