3 #include "ConfigTreeCtrl.h"
4 #include "ValueListCtrl.h"
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
)
23 MainFrame::MainFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
24 : wxFrame((wxFrame
*)0, -1, title
, pos
, size
),
29 // Create a persistent heap based configuration
31 ACE_Configuration_Heap
* pHeapConfig
= new ACE_Configuration_Heap
;
33 m_pConfig
= pHeapConfig
;
36 SetIcon(wxICON(mondrian
));
39 m_pSplitter
= new wxSplitterWindow(this, -1);
40 wxSize
sz( m_pSplitter
->GetSize() );
41 sz
.SetWidth(sz
.GetWidth() / 2);
44 m_pListCtrl
= new ValueListCtrl(m_pSplitter
, -1, wxDefaultPosition
, sz
);
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
);
53 m_pSplitter
->SplitVertically(m_pTreeCtrl
, m_pListCtrl
);
54 m_pSplitter
->SetMinimumPaneSize(100);
55 m_pSplitter
->SetSashPosition(size
.GetWidth() / 3);
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");
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
82 SetStatusText("Ready");
83 #endif // wxUSE_STATUSBAR
87 MainFrame::~MainFrame()
93 MainFrame
* MainFrame::Instance()
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
115 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
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
)
130 ACE_Configuration_Heap
* pHeapConfig
= new ACE_Configuration_Heap
;
131 pHeapConfig
->open(Dlg
.GetFilename());
132 SetNewConfig(pHeapConfig
);
135 void MainFrame::OnFileNewTransientHeap(wxCommandEvent
& event
)
138 ACE_Configuration_Heap
* pHeapConfig
= new ACE_Configuration_Heap
;
140 SetNewConfig(pHeapConfig
);
143 void MainFrame::OnFileOpenPersistentHeap(wxCommandEvent
& event
)
145 wxFileDialog
Dlg(this, "Choose a file", "", "", "*.*", wxOPEN
);
146 if(Dlg
.ShowModal() != wxID_OK
)
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
)
164 HKEY Root
= ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE
, Dlg
.GetValue(), 0);
165 ACE_Configuration_Win32Registry
* pWin32Reg
= new ACE_Configuration_Win32Registry(Root
);;
167 SetNewConfig(pWin32Reg
);
171 void MainFrame::OnFileExport(wxCommandEvent
& event
)
173 wxFileDialog
Dlg(this, "Enter Filename:", "", "", "*.*",0);
174 if(Dlg
.ShowModal() != wxID_OK
)
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
)
188 m_pConfig
->import_config(Dlg
.GetFilename());
189 SetNewConfig(m_pConfig
);
192 void MainFrame::SetNewConfig(ACE_Configuration
* pConfig
)
195 m_pListCtrl
->ChangeConfig(pConfig
);
196 m_pTreeCtrl
->ChangeConfig(pConfig
);