X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/716cd4107bb8a5f37dea34507453be6870aaef3a..ec75509f94fb11322c1c69056d1ec2af8f041fe2:/contrib/src/applet/appletwindow.cpp?ds=inline diff --git a/contrib/src/applet/appletwindow.cpp b/contrib/src/applet/appletwindow.cpp index 82c5f851ba..9329a0bb20 100644 --- a/contrib/src/applet/appletwindow.cpp +++ b/contrib/src/applet/appletwindow.cpp @@ -26,20 +26,32 @@ * ****************************************************************************/ -// For compilers that support precompilation -#include "wx/wxprec.h" -#include "wx/html/forcelnk.h" - // 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 // spawnl() +#endif /*---------------------------- Global variables ---------------------------*/ @@ -58,6 +70,9 @@ END_EVENT_TABLE() // Implement the class functions for wxHtmlAppletWindow IMPLEMENT_CLASS(wxHtmlAppletWindow, wxHtmlWindow); +// Implement the dynamic class so it can be constructed dynamically +IMPLEMENT_DYNAMIC_CLASS(VirtualData, wxObject); + // Define the wxAppletList implementation #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxAppletList); @@ -76,31 +91,33 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( const wxSize& size, long style, const wxString& name) - : wxHtmlWindow(parent,id,pos,size,style,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 - wxEchoPrep * echoPreprocessor = new wxEchoPrep(); // #echo preprocessor - wxIfElsePrep * ifPreprocessor = new wxIfElsePrep(); - + incPreprocessor->ChangeDirectory(m_FS); // give it access to our filesys object this->AddProcessor(incPreprocessor); - this->AddProcessor(echoPreprocessor); - this->AddProcessor(ifPreprocessor); + this->AddProcessor(new wxEchoPrep()); + this->AddProcessor(new wxIfElsePrep()); } /**************************************************************************** @@ -111,6 +128,18 @@ wxHtmlAppletWindow::~wxHtmlAppletWindow() { } +/**************************************************************************** +PARAMETERS: +dc - wxDC object to draw on + +REMARKS: +****************************************************************************/ +void wxHtmlAppletWindow::OnDraw( + wxDC& dc) +{ + wxHtmlWindow::OnDraw(dc); +} + /**************************************************************************** PARAMETERS: className - Name of the applet class to create an object for @@ -132,12 +161,7 @@ wxApplet *wxHtmlAppletWindow::CreateApplet( const wxSize& size) { // Dynamically create the class instance at runtime - wxClassInfo *info = wxClassInfo::FindClass(classId.c_str()); - if (!info) - return NULL; - wxObject *obj = info->CreateObject(); - if (!obj) - return NULL; + wxObject *obj = wxCreateDynamicObject(classId.c_str()); wxApplet *applet = wxDynamicCast(obj,wxApplet); if (!applet) return NULL; @@ -145,10 +169,50 @@ wxApplet *wxHtmlAppletWindow::CreateApplet( delete applet; return NULL; } - m_AppletList.Append(iName,applet); + 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 for + +RETURNS: +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 the +class name as a string. This allows instances of wxPlugIn classes to be +created dynamically based on string values embedded in the custom tags of an +HTML 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 find @@ -204,56 +268,110 @@ Remove an applet from the manager. Called during applet destruction bool wxHtmlAppletWindow::LoadPage( const wxString& link) { - wxString href(link); + wxString href(link); - // TODO: This needs to be made platform inde if possible. if (link.GetChar(0) == '?'){ wxString cmd = link.BeforeFirst('='); wxString cmdValue = link.AfterFirst('='); - if(!(cmd.CmpNoCase("?EXTERNAL"))){ -#ifdef __WINDOWS__ - ShellExecute(this ? (HWND)this->GetHWND() : NULL,NULL,cmdValue.c_str(),NULL,"",SW_SHOWNORMAL); -#else - #error Platform not implemented yet! -#endif - return true; + // Launches the default Internet browser for the system. + if(!(cmd.CmpNoCase("?EXTERNAL"))) { + return wxSpawnBrowser(this, cmdValue.c_str()); } - if (!(cmd.CmpNoCase("?EXECUTE"))){ - wxMessageBox(cmdValue); - return true; + + // 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"))){ - VirtualData& temp = *((VirtualData*)FindCookie(cmdValue)); - if (&temp) { - href = temp.GetHref(); + 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 - wxMessageBox("VIRTUAL LINK ERROR: " + cmdValue + " does not exist."); + wxLogError(_T("VIRTUAL LINK ERROR: '%s' does not exist."), cmdValue.c_str()); #endif return true; } } - } - // Make a copy of the current path the translate for