📄 emulator.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// Name: emulator.cpp// Purpose: Emulator wxWidgets sample// Author: Julian Smart// Modified by:// Created: 04/01/98// RCS-ID: $Id: emulator.cpp,v 1.16 2005/09/23 12:56:27 MR Exp $// Copyright: (c) Julian Smart// Licence: wxWindows licence/////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------// For compilers that support precompilation, includes "wx/wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__ #pragma hdrstop#endif// for all others, include the necessary headers (this file is usually all you// need because it includes almost all "standard" wxWidgets headers)#ifndef WX_PRECOMP #include "wx/wx.h"#endif#include "wx/confbase.h"#include "wx/fileconf.h"#include "wx/cmdline.h"#include "wx/image.h"#include "wx/file.h"#ifdef __WXX11__#include "wx/x11/reparent.h"#endif#include "emulator.h"// ----------------------------------------------------------------------------// resources// ----------------------------------------------------------------------------// the application icon (under Windows and OS/2 it is in resources)#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__) #include "emulator.xpm"#endif// ----------------------------------------------------------------------------// event tables and other macros for wxWidgets// ----------------------------------------------------------------------------// the event tables connect the wxWidgets events with the functions (event// handlers) which process them. It can be also done at run-time, but for the// simple menu events like this the static method is much simpler.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 wxWidgets 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. wxEmulatorApp and// not wxApp)IMPLEMENT_APP(wxEmulatorApp)static const wxCmdLineEntryDesc sg_cmdLineDesc[] ={ { wxCMD_LINE_OPTION, _T("u"), _T("use-display"), _T("display number to use (default 100)"), (wxCmdLineParamType)0, 0 }, { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("displays help on the command line parameters"), (wxCmdLineParamType)0, 0 }, { wxCMD_LINE_SWITCH, _T("v"), _T("version"), _T("print version"), (wxCmdLineParamType)0, 0 }, { wxCMD_LINE_PARAM, NULL, NULL, _T("config file 1"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, NULL, NULL, NULL, (wxCmdLineParamType)0, 0 }};// ============================================================================// implementation// ============================================================================// ----------------------------------------------------------------------------// the application class// ----------------------------------------------------------------------------wxEmulatorApp::wxEmulatorApp(){ m_xnestWindow = NULL; m_containerWindow = NULL; m_displayNumber = wxT("100"); m_xnestPID = 0;}// 'Main program' equivalent: the program execution "starts" herebool wxEmulatorApp::OnInit(){#if wxUSE_LOG wxLog::SetTimestamp(NULL);#endif // wxUSE_LOG wxInitAllImageHandlers(); wxString currentDir = wxGetCwd(); // Use argv to get current app directory m_appDir = wxFindAppPath(argv[0], currentDir, wxT("WXEMUDIR")); // If the development version, go up a directory.#ifdef __WXMSW__ 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 // Parse the command-line parameters and options wxCmdLineParser parser(sg_cmdLineDesc, argc, argv); int res; { wxLogNull log; res = parser.Parse(); } if (res == -1 || res > 0 || parser.Found(wxT("h"))) {#ifdef __X__ wxLog::SetActiveTarget(new wxLogStderr);#endif parser.Usage(); return false; } if (parser.Found(wxT("v"))) {#ifdef __X__ wxLog::SetActiveTarget(new wxLogStderr);#endif wxString msg; msg.Printf(wxT("wxWidgets PDA Emulator (c) Julian Smart, 2002 Version %.2f, %s"), wxEMULATOR_VERSION, __DATE__); wxLogMessage(msg); return false; } if (parser.Found(wxT("u"), & m_displayNumber)) { // Should only be number, so strip out anything before // and including a : character if (m_displayNumber.Find(wxT(':')) != -1) { m_displayNumber = m_displayNumber.AfterFirst(wxT(':')); } } if (parser.GetParamCount() == 0) { m_emulatorInfo.m_emulatorFilename = wxT("default.wxe"); } else if (parser.GetParamCount() > 0) { m_emulatorInfo.m_emulatorFilename = parser.GetParam(0); } // Load the emulation info if (!LoadEmulator(m_appDir)) { //wxMessageBox(wxT("Sorry, could not load this emulator. Please check bitmaps are valid.")); return false; } // create the main application window wxEmulatorFrame *frame = new wxEmulatorFrame(_T("wxEmulator"), wxPoint(50, 50), wxSize(450, 340));#if wxUSE_STATUSBAR frame->SetStatusText(m_emulatorInfo.m_emulatorTitle, 0); wxString sizeStr; sizeStr.Printf(wxT("Screen: %dx%d"), (int) m_emulatorInfo.m_emulatorScreenSize.x, (int) m_emulatorInfo.m_emulatorScreenSize.y); frame->SetStatusText(sizeStr, 1);#endif // wxUSE_STATUSBAR m_containerWindow = new wxEmulatorContainer(frame, wxID_ANY); frame->SetClientSize(m_emulatorInfo.m_emulatorDeviceSize.x, m_emulatorInfo.m_emulatorDeviceSize.y); // and show it (the frames, unlike simple controls, are not shown when // created initially) frame->Show(true);#ifdef __WXX11__ m_xnestWindow = new wxAdoptedWindow; wxString cmd; 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 m_xnestPID = wxExecute(cmd); if (0 == m_xnestPID) { frame->Destroy(); wxMessageBox(wxT("Sorry, could not run Xnest. Please check your PATH.")); return false; } wxReparenter reparenter; if (!reparenter.WaitAndReparent(m_containerWindow, m_xnestWindow, wxT("Xnest"))) { wxMessageBox(wxT("Sorry, could not reparent Xnest..")); frame->Destroy(); return false; }#endif m_containerWindow->DoResize(); // 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;}// Prepend the current program directory to the namewxString wxEmulatorApp::GetFullAppPath(const wxString& filename) const{ wxString path(m_appDir); if (path.Last() != '\\' && path.Last() != '/' && filename[0] != '\\' && filename[0] != '/')#ifdef __X__ path += '/';#else path += '\\';#endif path += filename; return path;}// Load the specified emulator.// For now, hard-wired. TODO: make this configurablebool wxEmulatorApp::LoadEmulator(const wxString& appDir){ // Load config file and bitmaps return m_emulatorInfo.Load(appDir);}// ----------------------------------------------------------------------------// main frame// ----------------------------------------------------------------------------// frame constructorwxEmulatorFrame::wxEmulatorFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(NULL, wxID_ANY, title, pos, size){ // set the frame icon SetIcon(wxICON(emulator));#if wxUSE_MENUS // create a menu bar wxMenu *menuFile = new wxMenu; // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(Emulator_About, _T("&About...\tF1"), _T("Show about dialog")); menuFile->Append(Emulator_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(menuFile, _T("&File")); menuBar->Append(helpMenu, _T("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar);#endif // wxUSE_MENUS#if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) CreateStatusBar(2);#endif // wxUSE_STATUSBAR}// event handlersvoid wxEmulatorFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){ // true is to force the frame to close Close(true);}void wxEmulatorFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -