From 505710ca37aa323c286b1def350ee3e5d7887e5d Mon Sep 17 00:00:00 2001 From: Kendall Bennett Date: Fri, 7 Sep 2001 20:08:05 +0000 Subject: [PATCH] Merged in latest wxApplet code from SciTech Perforce tree. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/applet/plugin.h | 57 ++++++++ contrib/include/wx/applet/window.h | 22 ++++ contrib/src/applet/appletwindow.cpp | 197 ++++++++++++++++++++++++++-- contrib/src/applet/plugin.cpp | 60 +++++++++ contrib/src/applet/prepifelse.cpp | 27 +++- contrib/src/applet/prepinclude.cpp | 4 +- src/common/fs_zip.cpp | 42 +++--- 7 files changed, 367 insertions(+), 42 deletions(-) create mode 100644 contrib/include/wx/applet/plugin.h create mode 100644 contrib/src/applet/plugin.cpp diff --git a/contrib/include/wx/applet/plugin.h b/contrib/include/wx/applet/plugin.h new file mode 100644 index 0000000000..1aff089a25 --- /dev/null +++ b/contrib/include/wx/applet/plugin.h @@ -0,0 +1,57 @@ +/**************************************************************************** +* +* 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: Header file for the wxQlet class +* +****************************************************************************/ + +#ifndef __WX_PLUGIN_H +#define __WX_PLUGIN_H + +// Forward declaration +class wxHtmlAppletWindow; + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +Defines the abstract base class for wxQlet objects. +****************************************************************************/ +class wxPlugIn : public wxObject { +private: + DECLARE_ABSTRACT_CLASS(wxPlugIn); + + wxHtmlAppletWindow *m_parent; +public: + // Constructor (called during dynamic creation) + wxPlugIn() { m_parent = NULL; }; + + // Psuedo virtual constructor + virtual bool Create(wxHtmlAppletWindow *parent); + + // Virtual destructor + virtual ~wxPlugIn(); + }; +#endif // __WX_PLUGIN_H + diff --git a/contrib/include/wx/applet/window.h b/contrib/include/wx/applet/window.h index 470c1091c7..ec02e68b84 100644 --- a/contrib/include/wx/applet/window.h +++ b/contrib/include/wx/applet/window.h @@ -38,6 +38,7 @@ // Forward declare class wxApplet; +class wxQlet; class wxLoadPageEvent; class wxPageLoadedEvent; class wxIncludePrep; @@ -119,6 +120,9 @@ public: const wxHtmlTag ¶ms, const wxSize& size); + // Create an instance of an Qlet based on it's class name + bool CreatePlugIn(const wxString& classId ); + // Find an instance of an applet based on it's class name wxApplet *FindApplet(const wxString& className); @@ -186,6 +190,24 @@ public: }; +/**************************************************************************** +REMARKS: +Defines the class for wxHtmlAppletCell +***************************************************************************/ +class wxHtmlAppletCell : public wxHtmlCell +{ +public: + wxHtmlAppletCell(wxWindow *wnd, int w = 0); + ~wxHtmlAppletCell() { m_Wnd->Destroy(); } + virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); + virtual void DrawInvisible(wxDC& dc, int x, int y); + virtual void Layout(int w); + +protected: + wxWindow* m_Wnd; + // width float is used in adjustWidth (it is in percents) +}; + #endif // __WX_APPLET_WINDOW_H diff --git a/contrib/src/applet/appletwindow.cpp b/contrib/src/applet/appletwindow.cpp index ab460c0542..0ccbd0f27c 100644 --- a/contrib/src/applet/appletwindow.cpp +++ b/contrib/src/applet/appletwindow.cpp @@ -37,10 +37,14 @@ #include "wx/spawnbrowser.h" #include "wx/html/forcelnk.h" +// crt +#include // spawnl() + // 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" @@ -101,6 +105,9 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( // Set up docroot m_DocRoot = docroot; + // Set the key_type for applets + m_AppletList = wxAppletList(wxKEY_STRING); + // Add HTML preprocessors // deleting preprocessors is done by the code within the window @@ -157,10 +164,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 @@ -213,28 +261,41 @@ True if page loaded successfully, false if not REMARKS: Remove an applet from the manager. Called during applet destruction ****************************************************************************/ +#include "scitech" bool wxHtmlAppletWindow::LoadPage( const wxString& link) { - wxString href(link); + wxString href(link); + + // TODO: technically we allow no relative paths - // Check for abs path. If it is not then tack on the path - // supplied at creation. - if (!wxIsAbsolutePath(href)) - href = m_DocRoot + href; + // Check to see if it is a real url, if not it is a file + if (link.Mid(0, 5).CmpNoCase("http:") != 0) { + + // Check for abs path. If it is not then tack on the path + // supplied at creation. + // TODO: Abs paths are only used in testing (remove this) + if (link.GetChar(1) != ':') + href = m_DocRoot + href; + } - // 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"))){ return wxSpawnBrowser(this, cmdValue.c_str()); } + + // Launches an external program on the system. if (!(cmd.CmpNoCase("?EXECUTE"))){ - wxProcess *child = new AppletProcess(this); - wxExecute(cmdValue, false, child); - 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) { @@ -247,6 +308,19 @@ bool wxHtmlAppletWindow::LoadPage( 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("?WXAPPLET"))){ + if (!cmdValue.IsNull()){ + if (!CreatePlugIn(cmdValue)){ +#ifdef CHECKED + wxLogError(_T("Launch Applet ERROR: '%s' does not exist."), cmdValue.c_str()); +#endif + } + } + return true; + } } // Inform all the applets that the new page is being loaded @@ -528,8 +602,28 @@ TAG_HANDLER_PROC(tag) wnd = m_WParser->GetWindow(); if ((appletWindow = wxDynamicCast(wnd,wxHtmlAppletWindow)) != NULL){ - tag.ScanParam("WIDTH", "%i", &width); - tag.ScanParam("HEIGHT", "%i", &height); + wxSize size = wxDefaultSize; + int al; + if (tag.HasParam("WIDTH")) { + tag.GetParamAsInt("WIDTH", &width); + size.SetWidth(width); + } + + if (tag.HasParam("HEIGHT")) { + tag.GetParamAsInt("HEIGHT", &height); + size.SetHeight(height); + } + + al = wxHTML_ALIGN_BOTTOM; + if (tag.HasParam(wxT("ALIGN"))) { + wxString alstr = tag.GetParam(wxT("ALIGN")); + alstr.MakeUpper(); // for the case alignment was in ".." + if (alstr == wxT("TEXTTOP") || alstr == wxT("TOP")) + al = wxHTML_ALIGN_TOP; + else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER"))) + al = wxHTML_ALIGN_CENTER; + } + if (tag.HasParam("CLASSID")){ classId = tag.GetParam("CLASSID"); if ( classId.IsNull() || classId.Len() == 0 ){ @@ -545,9 +639,9 @@ TAG_HANDLER_PROC(tag) name = classId; // We got all the params and can now create the applet - if ((applet = appletWindow->CreateApplet(classId, name, tag , wxSize(width, height))) != NULL){ + if ((applet = appletWindow->CreateApplet(classId, name, tag , size)) != NULL){ applet->Show(true); - m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(applet,0)); + m_WParser->OpenContainer()->InsertCell(new wxHtmlAppletCell(applet,al)); } else wxMessageBox("wxApplet error: Could not create:" + classId + "," + name); @@ -570,6 +664,81 @@ TAGS_MODULE_BEGIN(wxApplet) TAGS_MODULE_ADD(wxApplet) TAGS_MODULE_END(wxApplet) +/********************************************************************************* +wxHtmlAppletCell +*********************************************************************************/ +wxHtmlAppletCell::wxHtmlAppletCell(wxWindow *wnd, int align) : wxHtmlCell() +{ + int sx, sy; + m_Wnd = wnd; + m_Wnd->GetSize(&sx, &sy); + m_Width = sx, m_Height = sy; + + switch (align) { + case wxHTML_ALIGN_TOP : + m_Descent = m_Height; + break; + case wxHTML_ALIGN_CENTER : + m_Descent = m_Height / 2; + break; + case wxHTML_ALIGN_BOTTOM : + default : + m_Descent = 0; + break; + } + + SetCanLiveOnPagebreak(FALSE); +} + + +void wxHtmlAppletCell::Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) +{ + int absx = 0, absy = 0, stx, sty; + wxHtmlCell *c = this; + + while (c) + { + absx += c->GetPosX(); + absy += c->GetPosY(); + c = c->GetParent(); + } + + ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); + m_Wnd->Move(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty); +} + + + +void wxHtmlAppletCell::DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) +{ + int absx = 0, absy = 0, stx, sty; + wxHtmlCell *c = this; + + while (c) + { + absx += c->GetPosX(); + absy += c->GetPosY(); + c = c->GetParent(); + } + + ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); + m_Wnd->Move(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty); +} + + + +void wxHtmlAppletCell::Layout(int w) +{ + int sx, sy; + m_Wnd->GetSize(&sx, &sy); + m_Width = sx, m_Height = sy; + + wxHtmlCell::Layout(w); +} + + + + // This is our little forcelink hack. FORCE_LINK(loadpage) diff --git a/contrib/src/applet/plugin.cpp b/contrib/src/applet/plugin.cpp new file mode 100644 index 0000000000..9802ce7991 --- /dev/null +++ b/contrib/src/applet/plugin.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +* +* 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 wxPlugIn class implementation +* +****************************************************************************/ + +// For compilers that support precompilation +#include "wx/wxprec.h" + +// Include private headers +#include "wx/applet/plugin.h" +#include "wx/applet/window.h" + +/*------------------------- Implementation --------------------------------*/ + +// Implement the abstract class functions +IMPLEMENT_ABSTRACT_CLASS(wxPlugIn, wxObject); + +/**************************************************************************** +REMARKS: +Psuedo virtual constructor for the wxPlugIn class. +****************************************************************************/ +bool wxPlugIn::Create( + wxHtmlAppletWindow *parent) +{ + m_parent = parent; + return true; +} + +/**************************************************************************** +REMARKS: +Destructor for the wxPlugIn class. +****************************************************************************/ +wxPlugIn::~wxPlugIn() +{ +} + + diff --git a/contrib/src/applet/prepifelse.cpp b/contrib/src/applet/prepifelse.cpp index cc209ce795..2880af3bef 100644 --- a/contrib/src/applet/prepifelse.cpp +++ b/contrib/src/applet/prepifelse.cpp @@ -86,14 +86,19 @@ wxString wxIfElsePrep::Process( { int b; char ft[] = " - int end, c, n; + bool notval = false; + int off = 0; + int end, c, n; wxString usecode, code; wxString cname; wxString tag; @@ -101,6 +106,15 @@ wxString wxIfElsePrep::Process( code = wxString(""); + if (output.Mid(b, strlen(ftnot) ).CmpNoCase(ftnot) == 0 ) { + notval = true; + off = 4; + } + else if (output.Mid(b, strlen(ftnot2) ).CmpNoCase(ftnot2) == 0 ) { + notval = true; + off = 1; + } + // grab the tag and get the name of the variable end = (output.Mid(b)).Find("-->"); if (end == -1) { @@ -118,10 +132,10 @@ wxString wxIfElsePrep::Process( n = c; // find the classname - c = (tag.Mid(8, n-8)).Find(" "); - if (c == -1) n -= 8; + c = (tag.Mid(8+off, n-(8+off))).Find(" "); + if (c == -1) n -= (8+off); else n = c; - cname = tag.Mid(8, n); + cname = tag.Mid(8+off, n); cname.Trim(false); c = cname.Find("\""); @@ -131,6 +145,7 @@ wxString wxIfElsePrep::Process( // Grab the value from the variable class identified by cname value = wxIfElseVariable::FindValue(cname); + if (notval) value = !value; // Find the end of the tag () and copy it all into the variable code end = ((output.Mid(b)).Lower()).Find(""); diff --git a/contrib/src/applet/prepinclude.cpp b/contrib/src/applet/prepinclude.cpp index 600bd30579..b9678148a7 100644 --- a/contrib/src/applet/prepinclude.cpp +++ b/contrib/src/applet/prepinclude.cpp @@ -92,11 +92,11 @@ wxString wxIncludePrep::Process( // remove the #include tag output.Remove(i, n+21+3); - wxFSFile * file = fs->OpenFile(fname); + wxFSFile * file = fs->OpenFile(DOC_ROOT + fname); if (!file) { #ifdef CHECKED - wxMessageBox(wxString("wxHTML #include error: File not Found ") + fname + wxString("."),"Error",wxICON_ERROR); + wxMessageBox(wxString("wxHTML #include error: File not Found ") + DOC_ROOT + fname + wxString("."),"Error",wxICON_ERROR); #endif delete file; continue; diff --git a/src/common/fs_zip.cpp b/src/common/fs_zip.cpp index cbef9152dd..97cfa0bb1b 100644 --- a/src/common/fs_zip.cpp +++ b/src/common/fs_zip.cpp @@ -57,7 +57,7 @@ wxZipFSHandler::wxZipFSHandler() : wxFileSystemHandler() wxZipFSHandler::~wxZipFSHandler() { - if (m_Archive) + if (m_Archive) unzClose((unzFile)m_Archive); if (m_DirsFound) delete m_DirsFound; @@ -68,7 +68,7 @@ wxZipFSHandler::~wxZipFSHandler() bool wxZipFSHandler::CanOpen(const wxString& location) { wxString p = GetProtocol(location); - return (p == wxT("zip")) && + return (p == wxT("zip")) && (GetProtocol(GetLeftLocation(location)) == wxT("file")); } @@ -81,14 +81,16 @@ wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& l wxString left = GetLeftLocation(location); wxInputStream *s; - if (GetProtocol(left) != wxT("file")) + if (GetProtocol(left) != wxT("file")) { wxLogError(_("ZIP handler currently supports only local files!")); return NULL; } + if (right.GetChar(0) == wxT('/')) right = right.Mid(1); + s = new wxZipInputStream(left, right); - if (s && (s->LastError() == wxStream_NOERROR)) + if (s && (s->LastError() == wxStream_NOERROR)) { return new wxFSFile(s, left + wxT("#zip:") + right, @@ -107,10 +109,10 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags) { wxString right = GetRightLocation(spec); wxString left = GetLeftLocation(spec); - + if (right.Last() == wxT('/')) right.RemoveLast(); - if (m_Archive) + if (m_Archive) { unzClose((unzFile)m_Archive); m_Archive = NULL; @@ -122,13 +124,13 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags) return wxEmptyString; } - switch (flags) + switch (flags) { - case wxFILE: + case wxFILE: m_AllowDirs = FALSE, m_AllowFiles = TRUE; break; - case wxDIR: + case wxDIR: m_AllowDirs = TRUE, m_AllowFiles = FALSE; break; - default: + default: m_AllowDirs = m_AllowFiles = TRUE; break; } @@ -137,14 +139,14 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags) m_Pattern = right.AfterLast(wxT('/')); m_BaseDir = right.BeforeLast(wxT('/')); - if (m_Archive) + if (m_Archive) { - if (unzGoToFirstFile((unzFile)m_Archive) != UNZ_OK) + if (unzGoToFirstFile((unzFile)m_Archive) != UNZ_OK) { unzClose((unzFile)m_Archive); - m_Archive = NULL; + m_Archive = NULL; } - else + else { if (m_AllowDirs) { @@ -182,7 +184,7 @@ wxString wxZipFSHandler::DoFind() if (m_AllowDirs) { - dir = namestr.BeforeLast(wxT('/')); + dir = namestr.BeforeLast(wxT('/')); while (!dir.IsEmpty()) { long key = 0; @@ -196,7 +198,7 @@ wxString wxZipFSHandler::DoFind() wxMatchWild(m_Pattern, filename, FALSE)) match = m_ZipFile + wxT("#zip:") + dir + wxT("/") + filename; } - else + else break; // already tranversed } } @@ -206,19 +208,19 @@ wxString wxZipFSHandler::DoFind() if (m_AllowFiles && !filename.IsEmpty() && m_BaseDir == dir && wxMatchWild(m_Pattern, filename, FALSE)) match = m_ZipFile + wxT("#zip:") + namestr; - - if (unzGoToNextFile((unzFile)m_Archive) != UNZ_OK) + + if (unzGoToNextFile((unzFile)m_Archive) != UNZ_OK) { unzClose((unzFile)m_Archive); m_Archive = NULL; break; } } - + return match; } -#endif +#endif //wxUSE_FILESYSTEM && wxUSE_FS_ZIP && wxUSE_ZIPSTREAM -- 2.45.2