summaryrefslogtreecommitdiff
path: root/examples/ConfigViewer/MainFrame.cpp
blob: ace1c1c5e5237229cd85fa157fa56d4a7e6f4638 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// $Id$
#include "stdafx.h"
#include "MainFrame.h"
#include "ConfigTreeCtrl.h"
#include "ValueListCtrl.h"

// Singleton
MainFrame* MainFrame::m_pInstance = 0;

// IDs for the controls and the menu commands

BEGIN_EVENT_TABLE(MainFrame, wxFrame)
    EVT_MENU(FILE_NEW_PERSISTENT_HEAP, MainFrame::OnFileNewPersistentHeap)
    EVT_MENU(FILE_NEW_TRANSIENT_HEAP, MainFrame::OnFileNewTransientHeap)
    EVT_MENU(FILE_OPEN_PERSISTENT_HEAP, MainFrame::OnFileOpenPersistentHeap)
    EVT_MENU(FILE_OPEN_REGISTRY, MainFrame::OnFileOpenRegistry)
    EVT_MENU(FILE_EXPORT, MainFrame::OnFileExport)
    EVT_MENU(FILE_IMPORT, MainFrame::OnFileImport)
    EVT_MENU(QUIT,  MainFrame::OnQuit)
    EVT_MENU(ABOUT, MainFrame::OnAbout)
END_EVENT_TABLE()

// frame constructor
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size),
  m_pConfig(0)
{
  m_pInstance = this;

  // Create a persistent heap based configuration
  
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open();
  m_pConfig = pHeapConfig;

  // set the frame icon
  SetIcon(wxICON(mondrian));

  // Create Splitter
  m_pSplitter = new wxSplitterWindow(this, -1);
  wxSize sz( m_pSplitter->GetSize() );
  sz.SetWidth(sz.GetWidth() / 2);
  
  // List Control
  m_pListCtrl = new ValueListCtrl(m_pSplitter, -1, wxDefaultPosition, sz);

  // Tree Control
  m_pTreeCtrl = new ConfigTreeCtrl(m_pSplitter, FRAME_TREE, wxDefaultPosition, sz, 
                  wxTR_EDIT_LABELS | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT);
  m_pTreeCtrl->SetpListCtrl(m_pListCtrl);


  // Setup splitter
  m_pSplitter->SplitVertically(m_pTreeCtrl, m_pListCtrl);
  m_pSplitter->SetMinimumPaneSize(100);
  m_pSplitter->SetSashPosition(size.GetWidth() / 3);
  
  // create a menu bar
  wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
  menuFile->Append(FILE_NEW_PERSISTENT_HEAP, "New Persistent Heap", "Create a new persistent heap");
  menuFile->Append(FILE_NEW_TRANSIENT_HEAP, "New Transient Heap", "Create a new transient heap");
  menuFile->Append(FILE_OPEN_PERSISTENT_HEAP, "Open Persistent Heap", "Open Persistent Heap");
#if defined (ACE_WIN32)
  menuFile->Append(FILE_OPEN_REGISTRY, "Open Win32 Registry", "Open Win32 Registry");
#endif
  menuFile->AppendSeparator();
  menuFile->Append(FILE_IMPORT, "Import from INI file", "Import from INI file");
  menuFile->Append(FILE_EXPORT, "Export to INI file", "Export to INI file");
  menuFile->AppendSeparator();
  menuFile->Append(ABOUT, "&About...\tCtrl-A", "Show about dialog");
  menuFile->AppendSeparator();
  menuFile->Append(QUIT, "E&xit\tAlt-X", "Quit this program");

  // now append the freshly created menu to the menu bar...
  wxMenuBar *menuBar = new wxMenuBar();
  menuBar->Append(menuFile, "&File");

  // ... and attach this menu bar to the frame
  SetMenuBar(menuBar);

#if wxUSE_STATUSBAR
  CreateStatusBar(2);
  SetStatusText("Ready");
#endif // wxUSE_STATUSBAR
}


MainFrame::~MainFrame()
{
  delete m_pConfig;
  m_pInstance = 0;
}

MainFrame* MainFrame::Instance()
{
  assert(m_pInstance);
  return m_pInstance;
}


// event handlers

void MainFrame::OnSize(wxSizeEvent& event)
{
  wxLayoutAlgorithm layout;
  layout.LayoutFrame(this, m_pListCtrl);
}


void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
  // TRUE is to force the frame to close
  Close(TRUE);
}

void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
  wxString msg;
  msg.Printf( _T("Configuration Viewer v1.0\nWritten by Chris Hafey (chris@stentorsoft.com)\n"));
  wxMessageBox(msg, "About", wxOK | wxICON_INFORMATION, this);
}

void MainFrame::OnFileNewPersistentHeap(wxCommandEvent& event)
{
  wxFileDialog Dlg(this, "Enter Filename:", "", "", "*.*", 0);
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  delete m_pConfig;
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open(Dlg.GetFilename());
  SetNewConfig(pHeapConfig);
}

void MainFrame::OnFileNewTransientHeap(wxCommandEvent& event)
{
  delete m_pConfig;
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open();
  SetNewConfig(pHeapConfig);
}

void MainFrame::OnFileOpenPersistentHeap(wxCommandEvent& event)
{
  wxFileDialog Dlg(this, "Choose a file", "", "", "*.*", wxOPEN);
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  delete m_pConfig;
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open(Dlg.GetFilename());
  SetNewConfig(pHeapConfig);
}

void MainFrame::OnFileOpenRegistry(wxCommandEvent& event)
{
#if defined (ACE_WIN32)
  wxTextEntryDialog Dlg(this, "Enter Root:");
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  HKEY Root = ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE, Dlg.GetValue(), 0);
  ACE_Configuration_Win32Registry* pWin32Reg = new ACE_Configuration_Win32Registry(Root);;
  delete m_pConfig;
  SetNewConfig(pWin32Reg);
#endif
}

void MainFrame::OnFileExport(wxCommandEvent& event)
{
  wxFileDialog Dlg(this, "Enter Filename:", "", "", "*.*",0);
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  m_pConfig->export_config(Dlg.GetFilename());
}

void MainFrame::OnFileImport(wxCommandEvent& event)
{
  wxFileDialog Dlg(this, "Choose a file", "", "", "*.*", wxOPEN);
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  m_pConfig->import_config(Dlg.GetFilename());
  SetNewConfig(m_pConfig);
}

void MainFrame::SetNewConfig(ACE_Configuration* pConfig)
{
  m_pConfig = pConfig;
  m_pListCtrl->ChangeConfig(pConfig);
  m_pTreeCtrl->ChangeConfig(pConfig);
}