X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/38caaa61b154f60871cb6ec82040362762dd2dba..65d48d095fb1390edd46f682c864320d7b9626e3:/contrib/src/applet/appletwindow.cpp diff --git a/contrib/src/applet/appletwindow.cpp b/contrib/src/applet/appletwindow.cpp index b7effb3bd0..cd9cc4e7dc 100644 --- a/contrib/src/applet/appletwindow.cpp +++ b/contrib/src/applet/appletwindow.cpp @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* 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 @@ -32,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; @@ -79,31 +83,44 @@ 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) { - //setup client navbars + // 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; } - //Add HTML preprocessors + 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(); this->AddProcessor(incPreprocessor); this->AddProcessor(echoPreprocessor); this->AddProcessor(ifPreprocessor); - - } /**************************************************************************** @@ -114,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 @@ -148,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 @@ -207,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) { @@ -233,32 +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; } } - } - // Grab the directory from the string for use in the include preprocessor - // make sure we get either type of / or \. - int ch = link.Find('\\', true); - if (ch == -1) ch = link.Find('/', true); - if (ch != -1) { - wxFileSystem fs; - wxString tmp = link.Mid(0, ch+1); - fs.ChangePathTo(incPreprocessor->GetDirectory(), true); - fs.ChangePathTo(tmp, true); - incPreprocessor->ChangeDirectory(fs.GetPath()); + // 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 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) (node->GetData())->OnLinkClicked(wxHtmlLinkInfo(href)); + Show(false); + bool stat = wxHtmlWindow::LoadPage(href); + Show(true); // Enable/Dis the navbar tools - if (m_NavBar) { + if (m_NavBarEnabled) { m_NavBar->EnableTool(m_NavForwardId,HistoryCanForward()); m_NavBar->EnableTool(m_NavBackId,HistoryCanBack()); } @@ -313,6 +396,37 @@ bool wxHtmlAppletWindow::HistoryBack() return wxHtmlWindow::HistoryBack(); } +/**************************************************************************** +REMARKS: +This function is used to disable the navigation bars. If you want to +toggle to the navbars off you must call this function. +****************************************************************************/ +void wxHtmlAppletWindow::DisableNavBar() +{ + m_NavBarEnabled = false; +} + +/**************************************************************************** +REMARKS: +This function is used to enable the nav bars. If you toggle the nav bars on +you must call this function. +****************************************************************************/ +void wxHtmlAppletWindow::EnableNavBar() +{ + m_NavBarEnabled = true; +} + +/**************************************************************************** +REMARKS: +This function is used to set the nav bar to a new nav bar if you deleted the +one that you were useing. Usally this happens when you toggle a nav bar +on or off. +****************************************************************************/ +void wxHtmlAppletWindow::SetNavBar(wxToolBarBase *navBar) +{ + m_NavBar = navBar; +} + /**************************************************************************** PARAMETERS: msg - wxEvent message to be sent to all wxApplets @@ -431,10 +545,17 @@ need to change the page for the current window to a new window. void wxHtmlAppletWindow::OnLoadPage( wxLoadPageEvent &event) { - if (event.GetHtmlWindow() == this){ - if (LoadPage(event.GetHRef())){ - wxPageLoadedEvent evt; + // Test the mutex lock. + if (!(IsLocked())){ + Lock(); + if (event.GetHtmlWindow() == this){ + if (LoadPage(event.GetHRef())){ + // wxPageLoadedEvent evt; + // NOTE: This is reserved for later use as we might need to send + // page loaded events to applets. + } } + UnLock(); } } @@ -452,6 +573,23 @@ void wxHtmlAppletWindow::OnPageLoaded( Enable(true); } +/**************************************************************************** +PARAMETERS: +none + +REMARKS: +This function tries to lock the mutex. If it can't, returns +immediately with false. +***************************************************************************/ +bool wxHtmlAppletWindow::TryLock() +{ + if (!m_mutexLock) { + m_mutexLock = true; + return true; + } + return false; +} + /**************************************************************************** PARAMETERS: name - name of the last applet that changed the data in this object @@ -471,6 +609,30 @@ VirtualData::VirtualData( m_href = href; } +/**************************************************************************** +PARAMETERS: +REMARKS: +VirtualData is used to store information on the virtual links. +****************************************************************************/ +VirtualData::VirtualData() +{ + m_name.Empty(); + m_group.Empty(); + m_href.Empty(); +} + +/**************************************************************************** +PARAMETERS: +REMARKS: +****************************************************************************/ +void AppletProcess::OnTerminate( + int, + int ) +{ + // we're not needed any more + delete this; +} + #include "wx/html/m_templ.h" /**************************************************************************** @@ -493,8 +655,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 ){ @@ -510,9 +692,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); @@ -535,6 +717,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)