Update propgrid minimal sample: Added wxEVT_PG_CHANGING handler and property value...
[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 void OnPropertyGridChanging(wxPropertyGridEvent& event);
23
24 private:
25 wxPropertyGrid* m_pg;
26 DECLARE_EVENT_TABLE()
27 };
28
29 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
30 EVT_MENU(wxID_HIGHEST+1, MyFrame::OnAction)
31 EVT_PG_CHANGED( -1, MyFrame::OnPropertyGridChange )
32 EVT_PG_CHANGING( -1, MyFrame::OnPropertyGridChanging )
33 END_EVENT_TABLE()
34
35 MyFrame::MyFrame(wxWindow* parent)
36 : wxFrame(parent, wxID_ANY, wxT("PropertyGrid Test"))
37 {
38 wxMenu *Menu = new wxMenu;
39 Menu->Append(wxID_HIGHEST+1, wxT("Action"));
40 wxMenuBar *MenuBar = new wxMenuBar();
41 MenuBar->Append(Menu, wxT("Action"));
42 SetMenuBar(MenuBar);
43
44 wxPropertyGrid *pg = new wxPropertyGrid(this,-1,wxDefaultPosition,wxSize(400,400),
45 wxPG_SPLITTER_AUTO_CENTER |
46 wxPG_BOLD_MODIFIED );
47 m_pg = pg;
48
49 pg->Append( new wxStringProperty("String Property", wxPG_LABEL) );
50 pg->Append( new wxIntProperty("Int Property", wxPG_LABEL) );
51 pg->Append( new wxBoolProperty("Bool Property", wxPG_LABEL) );
52
53 SetSize(400, 600);
54 }
55
56 void MyFrame::OnPropertyGridChange(wxPropertyGridEvent &event)
57 {
58 wxPGProperty* p = event.GetProperty();
59
60 if ( p )
61 wxLogDebug("OnPropertyGridChange(%s, value=%s)",
62 p->GetName().c_str(), p->GetValueAsString().c_str());
63 else
64 wxLogDebug("OnPropertyGridChange(NULL)");
65 }
66
67 void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent &event)
68 {
69 wxPGProperty* p = event.GetProperty();
70
71 wxLogDebug("OnPropertyGridChanging(%s)", p->GetName().c_str());
72 }
73
74 void MyFrame::OnAction(wxCommandEvent &)
75 {
76 }
77
78 // Called from propgridsample.cpp
79 //
80 void DisplayMinimalFrame(wxWindow* parent)
81 {
82 MyFrame *frame = new MyFrame(parent);
83 frame->Show(true);
84 }