[go: up one dir, main page]

Menu

[r3]: / filou / src / Filou.cpp  Maximize  Restore  History

Download this file

329 lines (277 with data), 8.5 kB

  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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/***************************************************************************
* Copyright (C) 2004 by Gerhard W. Gruber *
* sparhawk@gmx.at *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/***************************************************************************
*
* PROJECT: FILOU
* $Source: /cvsroot/desktoptools/filou/src/Filou.cpp,v $
* $Revision: 1.4 $
* $Date: 2004/08/23 19:00:11 $
* $Author: lightweave $
* $Name: $
*
* $Log: Filou.cpp,v $
* Revision 1.4 2004/08/23 19:00:11 lightweave
* Added PluginList dialog
*
* Revision 1.3 2004/08/22 20:50:01 lightweave
* Added AttachPlugin Dialog
*
* Revision 1.2 2004/08/22 19:11:37 lightweave
* Added binary plugin
*
* Revision 1.1.1.1 2004/08/21 17:00:11 lightweave
* Initial release
*
*
***************************************************************************/
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#define STR_IMPORT
#define MAIN
#include "FilouGlobals.h"
#include "Filou.h"
#include "profile.h"
#include "HexPlugin.h"
#include "BinPlugin.h"
#ifdef __WXGTK__
#include "mondrian.xpm"
#endif
CGlobalSettings *g_Global;
// `Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
COptions o;
o.m_Hide = false;
if(argc > 1)
{
if(argv[1][0] == '-')
{
if(argv[1][1] == 'h')
o.m_Hide = true;
}
}
// Create the main application window
MyFrame *frame = new MyFrame(wxString(APPLICATION_NAME_STR) + " / " + wxString(APPLICATION_VERSION_STR),
wxDefaultPosition, wxDefaultSize);
// Show it and tell the application that it's our main window
// @@@ what does it do exactly, in fact? is it necessary here?
frame->Show(TRUE);
SetTopWindow(frame);
if(argc > 1)
frame->OpenFile(wxString(argv[1]));
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned FALSE here, the
// application would exit immediately.
return TRUE;
}
int MyApp::OnExit()
{
return wxApp::OnExit();
}
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(FM_FILE_OPEN, MyFrame::OnOpen)
EVT_MENU(FM_FILE_CLOSE, MyFrame::OnClose)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxMDIParentFrame((wxMDIParentFrame *)NULL, -1, title, pos, size, wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxSYSTEM_MENU|wxCAPTION|wxTHICK_FRAME)
{
m_Global.m_Frame = this;
m_Global.m_StatusBar = &m_StatusBar;
g_Global = &m_Global;
m_ActiveFrame = NULL;
// Now we dynamically connect the event handler for the last opened files menu.
AdjustEventHandler(FM_FILE_LIST, FM_FILE_LIST+g_Global->m_MaxFiles,
FM_FILE_LIST, FM_FILE_LIST+g_Global->m_MaxFiles,
(wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)&MyFrame::OnMostRecentFile);
// set the frame icon
SetIcon(wxICON(mondrian));
CreateMenu();
ScanPlugIns();
}
MyFrame::~MyFrame()
{
int i, n;
n = g_Global->m_PluginInfo.GetCount();
for(i = 0; i < n; i++)
{
delete g_Global->m_PluginInfo[i]->m_DefaultObject;
delete g_Global->m_PluginInfo[i];
}
}
void MyFrame::CreateMenu(void)
{
wxMenuBar *mb = new wxMenuBar;
wxMenu *m;
m = new wxMenu;
m->Append(FM_FILE_OPEN, FILE_OPEN_STR, FILE_OPEN_TIP_STR);
m->Append(FM_FILE_MANAGE_PLUGIN, FILE_MANAGE_PLUGIN_STR);
m->Append(FM_FILE_CLOSE, FILE_CLOSE_STR);
m->AppendSeparator();
m->Append(FM_FILE_SPLIT, FILE_SPLIT_WINDOW_STR);
m->AppendSeparator();
m->Append(FM_FILE_EXIT, FILE_EXIT_STR);
m->AppendSeparator();
mb->Append(m, FILE_MENU_STR);
SetMenuBar(mb);
UpdateMostRecentFile();
}
void MyFrame::UpdateMostRecentFile(void)
{
wxMenuBar *mb;
wxMenu *m;
wxMenuItem *mi;
int i, n;
mb = GetMenuBar();
m = mb->GetMenu(0);
// Remove all files from the most recent file list
i = 0;
while(1)
{
if((mi = m->FindItem(FM_FILE_LIST+i)) != NULL)
{
m->Remove(FM_FILE_LIST+i);
delete mi;
}
else
break;
i++;
}
n = g_Global->m_LastFile.GetCount();
for(i = 0; i < n; i++)
m->Append(FM_FILE_LIST+i, *(g_Global->m_LastFile[i]));
}
void MyFrame::OnSize(wxSizeEvent& event)
{
int w, h;
GetClientSize(&w, &h);
GetClientWindow()->SetSize(0, 0, w, h);
// FIXME: On wxX11, we need the MDI frame to process this
// event, but on other platforms this should not
// be done.
#ifdef __WXUNIVERSAL__
event.Skip();
#endif
}
void MyFrame::OnOpen(wxCommandEvent &ev)
{
wxFileDialog dlg(this, CHOOSE_FILE_STR, m_CurPathLeft);
wxString fn;
if(dlg.ShowModal() == wxID_OK)
{
fn = dlg.GetFilename();
m_CurPathLeft = dlg.GetDirectory()+g_Global->m_Slash;
fn = m_CurPathLeft+fn;
OpenFile(fn);
}
}
void MyFrame::OnClose(wxCommandEvent &event)
{
int i, n;
bool DeleteIt;
CViewerFrame *vf = NULL;
if((vf = static_cast<CViewerFrame *>(event.GetClientData())) == NULL)
{
vf = static_cast<CViewerFrame *>(GetActiveChild());
DeleteIt = true;
}
else
DeleteIt = false;
n = m_Frame.GetCount();
for(i = 0; i < n; i++)
{
if(vf == m_Frame[i])
{
m_Frame.RemoveAt(i);
if(DeleteIt == true)
delete vf;
break;
}
}
}
void MyFrame::OnMostRecentFile(wxCommandEvent &ev)
{
int id = ev.GetId()-FM_FILE_LIST;
wxString fn;
// If the file is coming from the Most Recently Opened list
// we check if the file could be successfully opened. If not
// we remove it from the list. Otherwise we add it again, to
// make sure it is at the top.
fn = *g_Global->m_LastFile[id];
OpenFile(fn);
}
void MyFrame::AdjustEventHandler(int OldId, int OldIdLast,
int NewId, int NewIdLast,
wxObjectEventFunction func)
{
Disconnect(OldId, OldIdLast, wxEVT_COMMAND_MENU_SELECTED);
Connect(NewId, NewIdLast, wxEVT_COMMAND_MENU_SELECTED, func);
}
bool MyFrame::OpenFile(wxString &fn)
{
bool rc = true;
int i, n;
CViewerFrame *vf = new CViewerFrame(this, -1, fn);
vf->Show(true);
vf->SetTitle(fn);
if((rc = vf->OpenFile(fn)) == true)
{
g_Global->AddFile(fn);
m_Frame.Add(vf);
m_ActiveFrame = vf;
}
else
{
g_Global->RemoveFile(fn);
delete vf;
vf = NULL;
}
// Now we have to update all file menus for all frames so they show the same
// MostRecentFile list.
UpdateMostRecentFile();
n = m_Frame.GetCount();
for(i = 0; i < n; i++)
{
vf = m_Frame[i];
vf->UpdateMostRecentFile();
}
return(rc);
}
void MyFrame::ScanPlugIns(void)
{
CPlugin *p;
CPlugin::SPluginInfo *pin;
// Register the hex plugin
p = new CHexPlugin;
pin = new CPlugin::SPluginInfo;
pin->m_DefaultObject = p;
p->GetPluginId(pin);
g_Global->m_PluginInfo.Add(pin);
// Register the binary plugin
p = new CBinPlugin;
pin = new CPlugin::SPluginInfo;
pin->m_DefaultObject = p;
p->GetPluginId(pin);
g_Global->m_PluginInfo.Add(pin);
}