propgrid_minimal.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // Copyright: (c) Jaakko Salli
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #include "wx/wx.h"
  11. #include "wx/propgrid/propgrid.h"
  12. #include "wx/propgrid/advprops.h"
  13. class MyFrame : public wxFrame
  14. {
  15. public:
  16. MyFrame(wxWindow* parent);
  17. void OnAction(wxCommandEvent& event);
  18. void OnPropertyGridChange(wxPropertyGridEvent& event);
  19. void OnPropertyGridChanging(wxPropertyGridEvent& event);
  20. private:
  21. wxPropertyGrid* m_pg;
  22. wxDECLARE_EVENT_TABLE();
  23. };
  24. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  25. EVT_MENU(wxID_HIGHEST+1, MyFrame::OnAction)
  26. EVT_PG_CHANGED( -1, MyFrame::OnPropertyGridChange )
  27. EVT_PG_CHANGING( -1, MyFrame::OnPropertyGridChanging )
  28. wxEND_EVENT_TABLE()
  29. MyFrame::MyFrame(wxWindow* parent)
  30. : wxFrame(parent, wxID_ANY, wxT("PropertyGrid Test"))
  31. {
  32. wxMenu *Menu = new wxMenu;
  33. Menu->Append(wxID_HIGHEST+1, wxT("Action"));
  34. wxMenuBar *MenuBar = new wxMenuBar();
  35. MenuBar->Append(Menu, wxT("Action"));
  36. SetMenuBar(MenuBar);
  37. wxPropertyGrid *pg = new wxPropertyGrid(this,-1,wxDefaultPosition,wxSize(400,400),
  38. wxPG_SPLITTER_AUTO_CENTER |
  39. wxPG_BOLD_MODIFIED );
  40. m_pg = pg;
  41. pg->Append( new wxStringProperty("String Property", wxPG_LABEL) );
  42. pg->Append( new wxIntProperty("Int Property", wxPG_LABEL) );
  43. pg->Append( new wxBoolProperty("Bool Property", wxPG_LABEL) );
  44. SetSize(400, 600);
  45. }
  46. void MyFrame::OnPropertyGridChange(wxPropertyGridEvent &event)
  47. {
  48. wxPGProperty* p = event.GetProperty();
  49. if ( p )
  50. {
  51. wxLogVerbose("OnPropertyGridChange(%s, value=%s)",
  52. p->GetName().c_str(), p->GetValueAsString().c_str());
  53. }
  54. else
  55. {
  56. wxLogVerbose("OnPropertyGridChange(NULL)");
  57. }
  58. }
  59. void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent &event)
  60. {
  61. wxPGProperty* p = event.GetProperty();
  62. wxLogVerbose("OnPropertyGridChanging(%s)", p->GetName().c_str());
  63. }
  64. void MyFrame::OnAction(wxCommandEvent &)
  65. {
  66. }
  67. // Called from propgridsample.cpp
  68. //
  69. void DisplayMinimalFrame(wxWindow* parent)
  70. {
  71. MyFrame *frame = new MyFrame(parent);
  72. frame->Show(true);
  73. }