[go: up one dir, main page]

Menu

[r15]: / LaserTankApp.cpp  Maximize  Restore  History

Download this file

162 lines (137 with data), 5.8 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
/* LaserTankApp.cpp
**
** This file is part of wxLaserTank.
**
** Copyright © 2002, 2009 Gary Harris
**
** Based on LaserTank ver 4.1.2 by Jim Kindley.
**
** wxLaserTank 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; see the file docs\gpl.txt.
** If not, write to the Free Software Foundation, Inc.,
** 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Gary Harris
** garyjharris@sourceforge.net
*/
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support pre-compilation, includes "wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
// Include your minimal set of headers here, or wx.h
#include <wx/wx.h>
#endif
#include <wx/xrc/xmlres.h>
#include "wx/wxprec.h"
#include <wx/utils.h>
#include <wx/cmdline.h> // For command line processing.
#include <wx/fileconf.h>
#include <wx/stdpaths.h>
#include "LaserTankApp.h"
#include "LaserTankFrm.h"
#include "LT32l_us.h"
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. LaserTankApp and
// not wxApp)
//(*AppHeaders
//#include <wx/image.h>
//*)
IMPLEMENT_APP(LaserTankApp)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool LaserTankApp::OnInit()
{
// Get Command line stuff
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_PARAM, NULL, NULL, _T("level file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL},
{ wxCMD_LINE_NONE }
};
// Parse command line
wxString cmdFilename;
wxCmdLineParser cmdParser(cmdLineDesc, argc, argv);
cmdParser.Parse(false);
// Check for a level filename
wxFileName fName;
if (cmdParser.GetParamCount() > 0){
cmdFilename = cmdParser.GetParam(0);
// Under Windows when invoking via a document
// in Explorer, we are passed the short form.
// So normalize and make the long form.
fName.Assign(cmdFilename);
// Check file suffix and only accept level files.
if(fName.GetExt().CmpNoCase(wxT("lvl")) == 0){
fName.Normalize(wxPATH_NORM_LONG|wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_ABSOLUTE);
cmdFilename = fName.GetFullPath();
}
}
//**** Disable the default command line handling here as nothing else works.
// call the base class initialization method, currently it only parses a
// few common command-line options but it could be do more in the future
// if ( !wxApp::OnInit() )
// return false;
// Get the app. path.
wxStandardPathsBase& stdp = wxStandardPaths::Get();
wxString sAppPath = stdp.GetExecutablePath().BeforeLast(wxFileName::GetPathSeparator()) + wxFileName::GetPathSeparator();
// Get the saved window position co-ords.
wxFileConfig *pConfig = new wxFileConfig(wxEmptyString, wxEmptyString, sAppPath + INIFileName, wxEmptyString, wxCONFIG_USE_RELATIVE_PATH);
wxInt32 xp = pConfig->Read(cfgSCREEN + cfgXpos, 0L);
wxInt32 yp = pConfig->Read(cfgSCREEN + cfgYpos, 0L);
delete wxConfigBase::Set((wxConfigBase *) NULL);
// Localisation.
int lang = wxLocale::GetSystemLanguage();
m_locale.Init(lang);
wxLocale::AddCatalogLookupPathPrefix(wxT("./lang"));
m_locale.AddCatalog(wxT("wxlasertank"));
// create the main application window
LaserTankFrame *frame = new LaserTankFrame(LTG->App_Title(), wxPoint(xp, yp), wxSize(602, 370), cmdFilename, sAppPath);
// Check for multiple instances. Exit if already running.
const wxString name = wxString::Format(GetAppName() + wxT("-%s"), wxGetUserId().c_str());
m_checker = new wxSingleInstanceChecker(name);
if(m_checker->IsAnotherRunning()){
wxMessageDialog dialog(frame,
_("Another instance of the program is running, exiting.\n"),
LTG->txt007(),
wxOK|wxICON_ERROR);
dialog.ShowModal();
delete m_checker;
return false;
}
//SetClientSize and show it (the frames, unlike simple controls, are not shown when
// created initially)
frame->Show(true);
// Return the main frame window
SetTopWindow(frame);
// 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 LaserTankApp::OnExit()
{
wxDELETE(m_checker);
wxASSERT(!m_checker);
return 0;
}