X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d1b327e1f98b997a36866f96efe3768302eb4e88..a7b1654d9d1df37d98a542a8e720e91f9e83640b:/utils/emulator/src/emulator.cpp diff --git a/utils/emulator/src/emulator.cpp b/utils/emulator/src/emulator.cpp index ccc15aa3ea..f7eb9459aa 100644 --- a/utils/emulator/src/emulator.cpp +++ b/utils/emulator/src/emulator.cpp @@ -37,6 +37,7 @@ #include "wx/confbase.h" #include "wx/fileconf.h" #include "wx/cmdline.h" +#include "wx/image.h" #ifdef __WXX11__ #include "wx/x11/reparent.h" @@ -63,6 +64,7 @@ BEGIN_EVENT_TABLE(wxEmulatorFrame, wxFrame) EVT_MENU(Emulator_Quit, wxEmulatorFrame::OnQuit) EVT_MENU(Emulator_About, wxEmulatorFrame::OnAbout) + EVT_CLOSE(wxEmulatorFrame::OnCloseWindow) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWindows to create @@ -74,12 +76,12 @@ IMPLEMENT_APP(wxEmulatorApp) static const wxCmdLineEntryDesc sg_cmdLineDesc[] = { - { wxCMD_LINE_OPTION, "u", "use-display", "display number to use (default 100)" }, + { wxCMD_LINE_OPTION, _T("u"), _T("use-display"), _T("display number to use (default 100)") }, - { wxCMD_LINE_SWITCH, "h", "help", "displays help on the command line parameters" }, - { wxCMD_LINE_SWITCH, "v", "version", "print version" }, + { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("displays help on the command line parameters") }, + { wxCMD_LINE_SWITCH, _T("v"), _T("version"), _T("print version") }, - { wxCMD_LINE_PARAM, NULL, NULL, "config file 1", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_PARAM, NULL, NULL, _T("config file 1"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE } }; @@ -98,11 +100,14 @@ wxEmulatorApp::wxEmulatorApp() m_xnestWindow = NULL; m_containerWindow = NULL; m_displayNumber = wxT("100"); + m_xnestPID = 0; + } // 'Main program' equivalent: the program execution "starts" here bool wxEmulatorApp::OnInit() { + wxLog::SetTimestamp(NULL); wxInitAllImageHandlers(); wxString currentDir = wxGetCwd(); @@ -112,10 +117,10 @@ bool wxEmulatorApp::OnInit() // If the development version, go up a directory. #ifdef __WXMSW__ - if ((m_appDir.Right(5).CmpNoCase("DEBUG") == 0) || - (m_appDir.Right(11).CmpNoCase("DEBUGSTABLE") == 0) || - (m_appDir.Right(7).CmpNoCase("RELEASE") == 0) || - (m_appDir.Right(13).CmpNoCase("RELEASESTABLE") == 0) + if ((m_appDir.Right(5).CmpNoCase(_T("DEBUG")) == 0) || + (m_appDir.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) || + (m_appDir.Right(7).CmpNoCase(_T("RELEASE")) == 0) || + (m_appDir.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ) m_appDir = wxPathOnly(m_appDir); #endif @@ -194,13 +199,14 @@ bool wxEmulatorApp::OnInit() m_xnestWindow = new wxAdoptedWindow; wxString cmd; - cmd.Printf(wxT("Xnest %s -geometry %dx%d"), + cmd.Printf(wxT("Xnest :%s -geometry %dx%d"), m_displayNumber.c_str(), (int) m_emulatorInfo.m_emulatorScreenSize.x, (int) m_emulatorInfo.m_emulatorScreenSize.y); - // Asynchronously executes Xnest - if (0 == wxExecute(cmd)) + // Asynchronously executes Xnest + m_xnestPID = wxExecute(cmd); + if (0 == m_xnestPID) { frame->Destroy(); wxMessageBox(wxT("Sorry, could not run Xnest. Please check your PATH.")); @@ -301,6 +307,22 @@ void wxEmulatorFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxMessageBox(msg, _T("About wxEmulator"), wxOK | wxICON_INFORMATION, this); } +void wxEmulatorFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +{ +#ifdef __WXX11__ + if (wxGetApp().m_xnestWindow) + { + wxGetApp().m_xnestWindow->SetHandle((WXWindow) NULL); + } +#endif + this->Destroy(); + if (wxGetApp().m_xnestPID > 0) + { + wxKill(wxGetApp().m_xnestPID); + wxGetApp().m_xnestPID = 0; + } +} + IMPLEMENT_CLASS(wxEmulatorContainer, wxWindow) BEGIN_EVENT_TABLE(wxEmulatorContainer, wxWindow) @@ -314,7 +336,7 @@ wxEmulatorContainer::wxEmulatorContainer(wxWindow* parent, wxWindowID id): { } -void wxEmulatorContainer::OnSize(wxSizeEvent& event) +void wxEmulatorContainer::OnSize(wxSizeEvent& WXUNUSED(event)) { DoResize(); } @@ -322,7 +344,11 @@ void wxEmulatorContainer::OnSize(wxSizeEvent& event) void wxEmulatorContainer::DoResize() { wxSize sz = GetClientSize(); - if (wxGetApp().m_xnestWindow) + if (wxGetApp().m_xnestWindow +#ifdef __WXX11__ + && wxGetApp().m_xnestWindow->GetMainWindow() +#endif + ) { int deviceWidth = wxGetApp().m_emulatorInfo.m_emulatorDeviceSize.x; int deviceHeight = wxGetApp().m_emulatorInfo.m_emulatorDeviceSize.y; @@ -338,7 +364,7 @@ void wxEmulatorContainer::DoResize() Refresh(); } -void wxEmulatorContainer::OnPaint(wxPaintEvent& event) +void wxEmulatorContainer::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); @@ -462,8 +488,8 @@ bool wxEmulatorInfo::Load(const wxString& appDir) return FALSE; } - int type = wxDetermineImageType(m_emulatorBackgroundBitmapName); - if (type == -1) + wxBitmapType type = wxDetermineImageType(m_emulatorBackgroundBitmapName); + if (type == wxBITMAP_TYPE_INVALID) return FALSE; if (!m_emulatorBackgroundBitmap.LoadFile(m_emulatorBackgroundBitmapName, type)) @@ -480,27 +506,27 @@ bool wxEmulatorInfo::Load(const wxString& appDir) } // Returns the image type, or -1, determined from the extension. -int wxDetermineImageType(const wxString& filename) +wxBitmapType wxDetermineImageType(const wxString& filename) { wxString path, name, ext; wxSplitPath(filename, & path, & name, & ext); ext.MakeLower(); - if (ext == "jpg" || ext == "jpeg") + if (ext == _T("jpg") || ext == _T("jpeg")) return wxBITMAP_TYPE_JPEG; - else if (ext == "gif") + if (ext == _T("gif")) return wxBITMAP_TYPE_GIF; - else if (ext == "bmp") + if (ext == _T("bmp")) return wxBITMAP_TYPE_BMP; - else if (ext == "png") + if (ext == _T("png")) return wxBITMAP_TYPE_PNG; - else if (ext == "pcx") + if (ext == _T("pcx")) return wxBITMAP_TYPE_PCX; - else if (ext == "tif" || ext == "tiff") + if (ext == _T("tif") || ext == _T("tiff")) return wxBITMAP_TYPE_TIF; - else - return -1; + + return wxBITMAP_TYPE_INVALID; } // Convert a colour to a 6-digit hex string @@ -552,7 +578,7 @@ wxString wxFindAppPath(const wxString& argv0, const wxString& cwd, const wxStrin { // Is it a relative path? wxString currentDir(cwd); - if (currentDir.Last() != wxFILE_SEP_PATH) + if (!wxEndsWithPathSeparator(currentDir)) currentDir += wxFILE_SEP_PATH; str = currentDir + argv0;