📄 appletwindow.cpp
字号:
/****************************************************************************** wxWindows HTML Applet Package** Copyright (C) 1991-2001 SciTech Software, Inc.* All rights reserved.** ========================================================================** The contents of this file are subject to the wxWindows License* Version 3.0 (the "License"); you may not use this file except in* compliance with the License. You may obtain a copy of the License at* http://www.wxwindows.org/licence3.txt** Software distributed under the License is distributed on an* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** ========================================================================** Language: ANSI C++* Environment: Any** Description: Main wxHtmlAppletWindow class implementation*****************************************************************************/// Include private headers#include "wx/applet/applet.h"#include "wx/applet/window.h"#include "wx/applet/loadpage.h"#include "wx/applet/plugin.h"// Preprocessor Stuff#include "wx/applet/prepinclude.h"#include "wx/applet/prepecho.h"#include "wx/applet/prepifelse.h"// wxWindows headers// Kind of pointless to use precompiled headers when this is the only// file in this lib that would need them.#include "wx/defs.h"#include "wx/spawnbrowser.h"#include "wx/html/forcelnk.h"#include "wx/log.h"#include "wx/msgdlg.h"#include "wx/tbarbase.h"// crt#ifdef __WXMSW__#include <process.h> // spawnl()#endif/*---------------------------- Global variables ---------------------------*/wxHashTable wxHtmlAppletWindow::m_Cookies; /*------------------------- Implementation --------------------------------*/// Empty event handler. We include this event handler simply so that// sub-classes of wxApplet can reference wxApplet in the event tables// that they create as necessary.BEGIN_EVENT_TABLE(wxHtmlAppletWindow, wxHtmlWindow) EVT_LOAD_PAGE(wxHtmlAppletWindow::OnLoadPage) EVT_PAGE_LOADED(wxHtmlAppletWindow::OnPageLoaded)END_EVENT_TABLE()// Implement the class functions for wxHtmlAppletWindowIMPLEMENT_CLASS(wxHtmlAppletWindow, wxHtmlWindow)// Implement the dynamic class so it can be constructed dynamicallyIMPLEMENT_DYNAMIC_CLASS(VirtualData, wxObject) // Define the wxAppletList implementation#include "wx/listimpl.cpp"WX_DEFINE_LIST(wxAppletList)/****************************************************************************REMARKS:Constructor for the applet window class.****************************************************************************/wxHtmlAppletWindow::wxHtmlAppletWindow( wxWindow *parent, wxWindowID id, wxToolBarBase *navBar, int navBackId, int navForwardId, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxHtmlWindow(parent,id,pos,size,style,name), m_AppletList(wxKEY_STRING){ // Init our locks UnLock(); // setup client navbars if (navBar) { m_NavBarEnabled = true; m_NavBar = navBar; m_NavBackId = navBackId; m_NavForwardId = navForwardId; } else { m_NavBarEnabled = false; m_NavBar = NULL; } m_NavBackId = navBackId; m_NavForwardId = navForwardId; // Add HTML preprocessors // deleting preprocessors is done by the code within the window incPreprocessor = new wxIncludePrep(); // #include preprocessor incPreprocessor->ChangeDirectory(m_FS); // give it access to our filesys object this->AddProcessor(incPreprocessor); this->AddProcessor(new wxEchoPrep()); this->AddProcessor(new wxIfElsePrep());}/****************************************************************************REMARKS:Destructor for the applet window class.****************************************************************************/wxHtmlAppletWindow::~wxHtmlAppletWindow(){}/****************************************************************************PARAMETERS:dc - wxDC object to draw onREMARKS:****************************************************************************/void wxHtmlAppletWindow::OnDraw( wxDC& dc){ wxHtmlWindow::OnDraw(dc);}/****************************************************************************PARAMETERS:className - Name of the applet class to create an object forsize - Initial size of the applet to be createdRETURNS:Pointer to the wxApplet created, or NULL if unable to create the applet.REMARKS:This function is used to create new wxApplet objects dynamically based on theclass name as a string. This allows instances of wxApplet classes to becreated dynamically based on string values embedded in the custom tags of anHTML page.****************************************************************************/wxApplet *wxHtmlAppletWindow::CreateApplet( const wxString& classId, const wxString& iName, const wxHtmlTag& params, const wxSize& size){ // Dynamically create the class instance at runtime wxObject *obj = wxCreateDynamicObject(classId.c_str()); wxApplet *applet = wxDynamicCast(obj,wxApplet); if (!applet) return NULL; if (!applet->Create(this,params,size)) { delete applet; return NULL; } else { // do some fixups on the size if its screwed up wxSize nsize = applet->GetBestSize(); if (nsize.x < size.x) nsize.x = size.x; if (nsize.y < size.y) nsize.y = size.y; applet->SetSize(nsize); } m_AppletList.Append(iName,(wxObject*)applet); return applet;}/****************************************************************************PARAMETERS:classId - Name of the Plugin class to create an object forRETURNS:Pointer to the wxplugIn created, or NULL if unable to create the PlugIn.REMARKS:This function is used to create new wxPlugIn objects dynamically based on theclass name as a string. This allows instances of wxPlugIn classes to becreated dynamically based on string values embedded in the custom tags of anHTML page.****************************************************************************/bool wxHtmlAppletWindow::CreatePlugIn( const wxString& classId, const wxString& cmdLine){ // Dynamically create the class instance at runtime, execute it // and then destroy it. wxObject *obj = wxCreateDynamicObject(classId.c_str()); wxPlugIn *plugIn = wxDynamicCast(obj,wxPlugIn); if (!plugIn) return false; if (!plugIn->Create(this)) { delete plugIn; return false; } plugIn->Run(cmdLine); delete plugIn; return true;}/****************************************************************************PARAMETERS:appletName - Name of the applet class to findRETURNS:Pointer to the wxApplet found, or NULL if not found.REMARKS:Find an instance of an applet based on it's name****************************************************************************/wxApplet *wxHtmlAppletWindow::FindApplet( const wxString& appletName){ wxAppletList::Node *node = m_AppletList.Find(appletName); if (!node) return NULL; return node->GetData();}/****************************************************************************PARAMETERS:applet - Pointer to the applet object to remove from the listRETURNS:True if the applet was found and removed, false if not. The applet itselfis *not* destroyed!REMARKS:Remove an applet from the manager. Called during applet destruction****************************************************************************/bool wxHtmlAppletWindow::RemoveApplet( const wxApplet *applet){ for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) { if (node->GetData() == applet) { m_AppletList.DeleteNode(node); return true; } } return false;}/****************************************************************************PARAMETERS:URL - New URL for the page to loadRETURNS:True if page loaded successfully, false if notREMARKS:Remove an applet from the manager. Called during applet destruction****************************************************************************/bool wxHtmlAppletWindow::LoadPage( const wxString& link){ wxString href(link); if (link.GetChar(0) == '?'){ wxString cmd = link.BeforeFirst('='); wxString cmdValue = link.AfterFirst('='); // Launches the default Internet browser for the system. if(!(cmd.CmpNoCase("?EXTERNAL"))) { return wxSpawnBrowser(this, cmdValue.c_str()); } // Launches an external program on the system. if (!(cmd.CmpNoCase("?EXECUTE"))) { int waitflag = P_NOWAIT; bool ret; wxString currentdir; wxString filename, path, ext; // Parse the params sent to the execute command. For now the only // parm is "wait". wait will cause spawn wait, default is nowait. // Since we only need one param for now I am not going to make this // any smater then it needs to be. If we need more params later i'll // fix it. int i = cmdValue.Find('('); if (i != -1) { wxString param = cmdValue.AfterFirst('('); cmdValue.Truncate(i); if (!param.CmpNoCase("wait)")) waitflag = P_WAIT; } currentdir = wxGetCwd(); //we don't want to change the path of the virtual file system so we have to use these //functions rather than the filesystem wxSplitPath(cmdValue, &path, &filename, &ext); if (path.CmpNoCase("") != 0) wxSetWorkingDirectory(path); ret = !spawnl( waitflag, cmdValue , NULL ); //HACK should use wxExecute //ret = wxExecute(filename, bool sync = FALSE, wxProcess *callback = NULL) wxSetWorkingDirectory(currentdir); return ret; } // Looks for a href in a variable stored as a cookie. The href can be // changed on the fly. if (!(cmd.CmpNoCase("?VIRTUAL"))){ wxObject *obj = FindCookie(cmdValue); VirtualData *virtData = wxDynamicCast(obj,VirtualData); if (virtData) { // recurse and loadpage, just in case the link is like another // ? link return LoadPage(virtData->GetHref()); } else {#ifdef CHECKED wxLogError(_T("VIRTUAL LINK ERROR: '%s' does not exist."), cmdValue.c_str());#endif return true; } } // This launches a qlet - It is like an applet but is more generic in that it // can be of any wxWin type so it then has the freedom to do more stuff. if (!(cmd.CmpNoCase("?WXPLUGIN"))){ if (!cmdValue.IsNull()) { // TODO: We are going to need to add code to parse the command line // parameters string in here in the future... wxString cmdLine = link.AfterFirst('('); cmdLine = cmdLine.BeforeLast(')'); if (!CreatePlugIn(cmdValue,cmdLine)) {#ifdef CHECKED wxLogError(_T("Launch PlugIn ERROR: '%s' does not exist."), cmdValue.c_str());#endif } } return true; } // This used in a link or href will take you back in the history. if (!(cmd.CmpNoCase("?BACK"))){ HistoryBack(); return true; } // This used in a link or href will take you forward in the history if (!(cmd.CmpNoCase("?FORWARD"))){ HistoryForward(); return true; } } // Inform all the applets that the new page is being loaded for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) (node->GetData())->OnLinkClicked(wxHtmlLinkInfo(href)); Show(false); m_openedlast = href; bool stat = wxHtmlWindow::LoadPage(href); Show(true); // Enable/Dis the navbar tools if (m_NavBarEnabled) { m_NavBar->EnableTool(m_NavForwardId,HistoryCanForward()); m_NavBar->EnableTool(m_NavBackId,HistoryCanBack()); } return stat;}/****************************************************************************PARAMETERS:URL - String URL that we are navigating toREMARKS:Called when the user navigates to a new URL from the current page. We simplycall the LoadPage function above to load the new page and display it.****************************************************************************/void wxHtmlAppletWindow::OnLinkClicked( const wxHtmlLinkInfo& link){ LoadPage(link.GetHref());}/****************************************************************************REMARKS:Called when the user navigates forward within the HTML history stack.We call all the applets in turn allowing them to handle the navigationcommand prior to being destructed when the current page is destroyed.****************************************************************************/bool wxHtmlAppletWindow::HistoryForward(){ if (!HistoryCanForward()) return false; for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) (node->GetData())->OnHistoryForward(); return wxHtmlWindow::HistoryForward();}/****************************************************************************REMARKS:Called when the user navigates backwards within the HTML history stack.We call all the applets in turn allowing them to handle the navigationcommand prior to being destructed when the current page is destroyed.****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -