Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / ConfigViewer / MainFrame.cpp
blob7c3b7aeb714c6943da55a4962b7955dd288245f3
1 #include "stdafx.h"
2 #include "MainFrame.h"
3 #include "ConfigTreeCtrl.h"
4 #include "ValueListCtrl.h"
6 // Singleton
7 MainFrame* MainFrame::m_pInstance = 0;
9 // IDs for the controls and the menu commands
11 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
12 EVT_MENU(FILE_NEW_PERSISTENT_HEAP, MainFrame::OnFileNewPersistentHeap)
13 EVT_MENU(FILE_NEW_TRANSIENT_HEAP, MainFrame::OnFileNewTransientHeap)
14 EVT_MENU(FILE_OPEN_PERSISTENT_HEAP, MainFrame::OnFileOpenPersistentHeap)
15 EVT_MENU(FILE_OPEN_REGISTRY, MainFrame::OnFileOpenRegistry)
16 EVT_MENU(FILE_EXPORT, MainFrame::OnFileExport)
17 EVT_MENU(FILE_IMPORT, MainFrame::OnFileImport)
18 EVT_MENU(QUIT, MainFrame::OnQuit)
19 EVT_MENU(ABOUT, MainFrame::OnAbout)
20 END_EVENT_TABLE()
22 // frame constructor
23 MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
24 : wxFrame((wxFrame *)0, -1, title, pos, size),
25 m_pConfig(0)
27 m_pInstance = this;
29 // Create a persistent heap based configuration
31 ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
32 pHeapConfig->open();
33 m_pConfig = pHeapConfig;
35 // set the frame icon
36 SetIcon(wxICON(mondrian));
38 // Create Splitter
39 m_pSplitter = new wxSplitterWindow(this, -1);
40 wxSize sz( m_pSplitter->GetSize() );
41 sz.SetWidth(sz.GetWidth() / 2);
43 // List Control
44 m_pListCtrl = new ValueListCtrl(m_pSplitter, -1, wxDefaultPosition, sz);
46 // Tree Control
47 m_pTreeCtrl = new ConfigTreeCtrl(m_pSplitter, FRAME_TREE, wxDefaultPosition, sz,
48 wxTR_EDIT_LABELS | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT);
49 m_pTreeCtrl->SetpListCtrl(m_pListCtrl);
52 // Setup splitter
53 m_pSplitter->SplitVertically(m_pTreeCtrl, m_pListCtrl);
54 m_pSplitter->SetMinimumPaneSize(100);
55 m_pSplitter->SetSashPosition(size.GetWidth() / 3);
57 // create a menu bar
58 wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
59 menuFile->Append(FILE_NEW_PERSISTENT_HEAP, "New Persistent Heap", "Create a new persistent heap");
60 menuFile->Append(FILE_NEW_TRANSIENT_HEAP, "New Transient Heap", "Create a new transient heap");
61 menuFile->Append(FILE_OPEN_PERSISTENT_HEAP, "Open Persistent Heap", "Open Persistent Heap");
62 #if defined (ACE_WIN32)
63 menuFile->Append(FILE_OPEN_REGISTRY, "Open Win32 Registry", "Open Win32 Registry");
64 #endif
65 menuFile->AppendSeparator();
66 menuFile->Append(FILE_IMPORT, "Import from INI file", "Import from INI file");
67 menuFile->Append(FILE_EXPORT, "Export to INI file", "Export to INI file");
68 menuFile->AppendSeparator();
69 menuFile->Append(ABOUT, "&About...\tCtrl-A", "Show about dialog");
70 menuFile->AppendSeparator();
71 menuFile->Append(QUIT, "E&xit\tAlt-X", "Quit this program");
73 // now append the freshly created menu to the menu bar...
74 wxMenuBar *menuBar = new wxMenuBar();
75 menuBar->Append(menuFile, "&File");
77 // ... and attach this menu bar to the frame
78 SetMenuBar(menuBar);
80 #if wxUSE_STATUSBAR
81 CreateStatusBar(2);
82 SetStatusText("Ready");
83 #endif // wxUSE_STATUSBAR
87 MainFrame::~MainFrame()
89 delete m_pConfig;
90 m_pInstance = 0;
93 MainFrame* MainFrame::Instance()
95 assert(m_pInstance);
96 return m_pInstance;
100 // event handlers
102 void MainFrame::OnSize(wxSizeEvent& event)
104 wxLayoutAlgorithm layout;
105 layout.LayoutFrame(this, m_pListCtrl);
109 void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
111 // TRUE is to force the frame to close
112 Close(TRUE);
115 void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
117 wxString msg;
118 msg.Printf( _T("Configuration Viewer v1.0\nWritten by Chris Hafey (chris@stentorsoft.com)\n"));
119 wxMessageBox(msg, "About", wxOK | wxICON_INFORMATION, this);
122 void MainFrame::OnFileNewPersistentHeap(wxCommandEvent& event)
124 wxFileDialog Dlg(this, "Enter Filename:", "", "", "*.*", 0);
125 if(Dlg.ShowModal() != wxID_OK)
127 return;
129 delete m_pConfig;
130 ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
131 pHeapConfig->open(Dlg.GetFilename());
132 SetNewConfig(pHeapConfig);
135 void MainFrame::OnFileNewTransientHeap(wxCommandEvent& event)
137 delete m_pConfig;
138 ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
139 pHeapConfig->open();
140 SetNewConfig(pHeapConfig);
143 void MainFrame::OnFileOpenPersistentHeap(wxCommandEvent& event)
145 wxFileDialog Dlg(this, "Choose a file", "", "", "*.*", wxOPEN);
146 if(Dlg.ShowModal() != wxID_OK)
148 return;
150 delete m_pConfig;
151 ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
152 pHeapConfig->open(Dlg.GetFilename());
153 SetNewConfig(pHeapConfig);
156 void MainFrame::OnFileOpenRegistry(wxCommandEvent& event)
158 #if defined (ACE_WIN32)
159 wxTextEntryDialog Dlg(this, "Enter Root:");
160 if(Dlg.ShowModal() != wxID_OK)
162 return;
164 HKEY Root = ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE, Dlg.GetValue(), 0);
165 ACE_Configuration_Win32Registry* pWin32Reg = new ACE_Configuration_Win32Registry(Root);;
166 delete m_pConfig;
167 SetNewConfig(pWin32Reg);
168 #endif
171 void MainFrame::OnFileExport(wxCommandEvent& event)
173 wxFileDialog Dlg(this, "Enter Filename:", "", "", "*.*",0);
174 if(Dlg.ShowModal() != wxID_OK)
176 return;
178 m_pConfig->export_config(Dlg.GetFilename());
181 void MainFrame::OnFileImport(wxCommandEvent& event)
183 wxFileDialog Dlg(this, "Choose a file", "", "", "*.*", wxOPEN);
184 if(Dlg.ShowModal() != wxID_OK)
186 return;
188 m_pConfig->import_config(Dlg.GetFilename());
189 SetNewConfig(m_pConfig);
192 void MainFrame::SetNewConfig(ACE_Configuration* pConfig)
194 m_pConfig = pConfig;
195 m_pListCtrl->ChangeConfig(pConfig);
196 m_pTreeCtrl->ChangeConfig(pConfig);