X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/716cd4107bb8a5f37dea34507453be6870aaef3a..af01f1ba0d697c07173f436ab661b4c833258a91:/contrib/src/applet/appletwindow.cpp diff --git a/contrib/src/applet/appletwindow.cpp b/contrib/src/applet/appletwindow.cpp index 82c5f851ba..cd9cc4e7dc 100644 --- a/contrib/src/applet/appletwindow.cpp +++ b/contrib/src/applet/appletwindow.cpp @@ -28,19 +28,27 @@ // For compilers that support precompilation #include "wx/wxprec.h" +#include "wx/utils.h" +#include "wx/process.h" +#include "wx/spawnbrowser.h" #include "wx/html/forcelnk.h" +// crt +#ifdef __WXMSW__ +#include // spawnl() +#endif + // 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" - /*---------------------------- Global variables ---------------------------*/ wxHashTable wxHtmlAppletWindow::m_Cookies; @@ -75,26 +83,38 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( const wxPoint& pos, const wxSize& size, long style, - const wxString& name) - : wxHtmlWindow(parent,id,pos,size,style,name) + const wxString& name, + const wxPalette& globalPalette) + : wxHtmlWindow(parent,id,pos,size,style,name), m_globalPalette(globalPalette) { // 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; + + + // Set the key_type for applets + m_AppletList = wxAppletList(wxKEY_STRING); + // 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 + wxEchoPrep * echoPreprocessor = new wxEchoPrep(); // #echo preprocessor wxIfElsePrep * ifPreprocessor = new wxIfElsePrep(); @@ -111,6 +131,27 @@ wxHtmlAppletWindow::~wxHtmlAppletWindow() { } +#include "scitech.h" + +/**************************************************************************** +PARAMETERS: +dc - wxDC object to draw on + +REMARKS: +This function handles drawing the HTML applet window. Because the standard +wxWindows classes don't properly handle palette management, we add code +in here to properly select the global palette that we use for all drawing +into the DC before we allow the regular wxWindows code to finish the +drawing process. +****************************************************************************/ +void wxHtmlAppletWindow::OnDraw( + wxDC& dc) +{ + // TODO: Only do this for <= 8bpp modes! + dc.SetPalette(m_globalPalette); + wxHtmlWindow::OnDraw(dc); +} + /**************************************************************************** PARAMETERS: className - Name of the applet class to create an object for @@ -145,10 +186,51 @@ 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 ) +{ + // Dynamically create the class instance at runtime + wxClassInfo *info = wxClassInfo::FindClass(classId.c_str()); + if (!info) + return false; + wxObject *obj = info->CreateObject(); + if (!obj) + return false; + wxPlugIn *plugIn = wxDynamicCast(obj,wxPlugIn); + if (!plugIn) + return false; + if (!plugIn->Create(this)) { + delete plugIn; + return false; + } + return true; +} + /**************************************************************************** PARAMETERS: appletName - Name of the applet class to find @@ -204,25 +286,25 @@ 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('='); + // Launches the default Internet browser for the system. 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; + return wxSpawnBrowser(this, cmdValue.c_str()); } + + // Launches an external program on the system. if (!(cmd.CmpNoCase("?EXECUTE"))){ - wxMessageBox(cmdValue); - return true; + int code = spawnl( P_NOWAIT, cmdValue , NULL ); + return (!code); } + + // 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) { @@ -230,30 +312,36 @@ bool wxHtmlAppletWindow::LoadPage( } 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