]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/applet/appletwindow.cpp
Only support detection of "near the edge" coordinates, if dragging grid lines
[wxWidgets.git] / contrib / src / applet / appletwindow.cpp
CommitLineData
d9b91de7
KB
1/****************************************************************************
2*
67fc151d 3* wxWindows HTML Applet Package
d9b91de7
KB
4*
5* Copyright (C) 1991-2001 SciTech Software, Inc.
6* All rights reserved.
7*
19193a2c
KB
8* ========================================================================
9*
10* The contents of this file are subject to the wxWindows License
11* Version 3.0 (the "License"); you may not use this file except in
12* compliance with the License. You may obtain a copy of the License at
13* http://www.wxwindows.org/licence3.txt
14*
15* Software distributed under the License is distributed on an
16* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17* implied. See the License for the specific language governing
18* rights and limitations under the License.
19*
20* ========================================================================
d9b91de7 21*
67fc151d
KB
22* Language: ANSI C++
23* Environment: Any
d9b91de7
KB
24*
25* Description: Main wxHtmlAppletWindow class implementation
26*
27****************************************************************************/
28
d9b91de7
KB
29// Include private headers
30#include "wx/applet/applet.h"
38caaa61
KB
31#include "wx/applet/window.h"
32#include "wx/applet/loadpage.h"
505710ca 33#include "wx/applet/plugin.h"
d9b91de7 34
38caaa61
KB
35// Preprocessor Stuff
36#include "wx/applet/prepinclude.h"
37#include "wx/applet/prepecho.h"
38#include "wx/applet/prepifelse.h"
39
574c939e
KB
40// wxWindows headers
41
42// Kind of pointless to use precompiled headers when this is the only
43// file in this lib that would need them.
44#include "wx/defs.h"
45#include "wx/spawnbrowser.h"
46#include "wx/html/forcelnk.h"
47#include "wx/log.h"
48#include "wx/msgdlg.h"
49#include "wx/tbarbase.h"
50
51// crt
52#ifdef __WXMSW__
53#include <process.h> // spawnl()
54#endif
55
38caaa61
KB
56/*---------------------------- Global variables ---------------------------*/
57
58wxHashTable wxHtmlAppletWindow::m_Cookies;
59
d9b91de7
KB
60/*------------------------- Implementation --------------------------------*/
61
62// Empty event handler. We include this event handler simply so that
63// sub-classes of wxApplet can reference wxApplet in the event tables
64// that they create as necessary.
65BEGIN_EVENT_TABLE(wxHtmlAppletWindow, wxHtmlWindow)
38caaa61
KB
66 EVT_LOAD_PAGE(wxHtmlAppletWindow::OnLoadPage)
67 EVT_PAGE_LOADED(wxHtmlAppletWindow::OnPageLoaded)
d9b91de7
KB
68END_EVENT_TABLE()
69
70// Implement the class functions for wxHtmlAppletWindow
412e0d47 71IMPLEMENT_CLASS(wxHtmlAppletWindow, wxHtmlWindow)
d9b91de7 72
574c939e 73// Implement the dynamic class so it can be constructed dynamically
412e0d47 74IMPLEMENT_DYNAMIC_CLASS(VirtualData, wxObject)
574c939e 75
d9b91de7
KB
76// Define the wxAppletList implementation
77#include "wx/listimpl.cpp"
412e0d47 78WX_DEFINE_LIST(wxAppletList)
d9b91de7
KB
79
80/****************************************************************************
81REMARKS:
82Constructor for the applet window class.
83****************************************************************************/
84wxHtmlAppletWindow::wxHtmlAppletWindow(
67fc151d
KB
85 wxWindow *parent,
86 wxWindowID id,
38caaa61
KB
87 wxToolBarBase *navBar,
88 int navBackId,
89 int navForwardId,
67fc151d
KB
90 const wxPoint& pos,
91 const wxSize& size,
92 long style,
574c939e
KB
93 const wxString& name)
94 : wxHtmlWindow(parent,id,pos,size,style,name), m_AppletList(wxKEY_STRING)
d9b91de7 95{
716cd410
KB
96 // Init our locks
97 UnLock();
98
99 // setup client navbars
38caaa61 100 if (navBar) {
19193a2c 101 m_NavBarEnabled = true;
38caaa61
KB
102 m_NavBar = navBar;
103 m_NavBackId = navBackId;
104 m_NavForwardId = navForwardId;
105 }
106 else {
19193a2c 107 m_NavBarEnabled = false;
38caaa61
KB
108 m_NavBar = NULL;
109 }
110
19193a2c
KB
111 m_NavBackId = navBackId;
112 m_NavForwardId = navForwardId;
113
716cd410 114 // Add HTML preprocessors
38caaa61 115 // deleting preprocessors is done by the code within the window
38caaa61 116 incPreprocessor = new wxIncludePrep(); // #include preprocessor
19193a2c 117 incPreprocessor->ChangeDirectory(m_FS); // give it access to our filesys object
38caaa61 118 this->AddProcessor(incPreprocessor);
574c939e
KB
119 this->AddProcessor(new wxEchoPrep());
120 this->AddProcessor(new wxIfElsePrep());
d9b91de7
KB
121}
122
123/****************************************************************************
124REMARKS:
125Destructor for the applet window class.
126****************************************************************************/
127wxHtmlAppletWindow::~wxHtmlAppletWindow()
128{
129}
130
19193a2c
KB
131/****************************************************************************
132PARAMETERS:
133dc - wxDC object to draw on
134
135REMARKS:
19193a2c
KB
136****************************************************************************/
137void wxHtmlAppletWindow::OnDraw(
138 wxDC& dc)
139{
19193a2c
KB
140 wxHtmlWindow::OnDraw(dc);
141}
142
d9b91de7
KB
143/****************************************************************************
144PARAMETERS:
67fc151d
KB
145className - Name of the applet class to create an object for
146size - Initial size of the applet to be created
d9b91de7
KB
147
148RETURNS:
149Pointer to the wxApplet created, or NULL if unable to create the applet.
150
151REMARKS:
152This function is used to create new wxApplet objects dynamically based on the
153class name as a string. This allows instances of wxApplet classes to be
154created dynamically based on string values embedded in the custom tags of an
155HTML page.
156****************************************************************************/
157wxApplet *wxHtmlAppletWindow::CreateApplet(
38caaa61
KB
158 const wxString& classId,
159 const wxString& iName,
160 const wxHtmlTag& params,
67fc151d 161 const wxSize& size)
d9b91de7 162{
67fc151d 163 // Dynamically create the class instance at runtime
574c939e 164 wxObject *obj = wxCreateDynamicObject(classId.c_str());
d9b91de7 165 wxApplet *applet = wxDynamicCast(obj,wxApplet);
67fc151d
KB
166 if (!applet)
167 return NULL;
38caaa61 168 if (!applet->Create(this,params,size)) {
67fc151d
KB
169 delete applet;
170 return NULL;
171 }
505710ca
KB
172 else {
173 // do some fixups on the size if its screwed up
174 wxSize nsize = applet->GetBestSize();
175 if (nsize.x < size.x) nsize.x = size.x;
176 if (nsize.y < size.y) nsize.y = size.y;
177 applet->SetSize(nsize);
178 }
179
180 m_AppletList.Append(iName,(wxObject*)applet);
67fc151d 181 return applet;
d9b91de7
KB
182}
183
505710ca
KB
184/****************************************************************************
185PARAMETERS:
186classId - Name of the Plugin class to create an object for
187
188RETURNS:
189Pointer to the wxplugIn created, or NULL if unable to create the PlugIn.
190
191REMARKS:
192This function is used to create new wxPlugIn objects dynamically based on the
193class name as a string. This allows instances of wxPlugIn classes to be
194created dynamically based on string values embedded in the custom tags of an
195HTML page.
196****************************************************************************/
197bool wxHtmlAppletWindow::CreatePlugIn(
574c939e
KB
198 const wxString& classId,
199 const wxString& cmdLine)
505710ca 200{
574c939e
KB
201 // Dynamically create the class instance at runtime, execute it
202 // and then destroy it.
203 wxObject *obj = wxCreateDynamicObject(classId.c_str());
505710ca
KB
204 wxPlugIn *plugIn = wxDynamicCast(obj,wxPlugIn);
205 if (!plugIn)
206 return false;
207 if (!plugIn->Create(this)) {
208 delete plugIn;
209 return false;
210 }
574c939e
KB
211 plugIn->Run(cmdLine);
212 delete plugIn;
505710ca
KB
213 return true;
214}
215
d9b91de7
KB
216/****************************************************************************
217PARAMETERS:
67fc151d 218appletName - Name of the applet class to find
d9b91de7
KB
219
220RETURNS:
221Pointer to the wxApplet found, or NULL if not found.
222
223REMARKS:
224Find an instance of an applet based on it's name
225****************************************************************************/
226wxApplet *wxHtmlAppletWindow::FindApplet(
67fc151d 227 const wxString& appletName)
d9b91de7 228{
67fc151d
KB
229 wxAppletList::Node *node = m_AppletList.Find(appletName);
230 if (!node)
231 return NULL;
232 return node->GetData();
38caaa61 233}
d9b91de7
KB
234
235/****************************************************************************
236PARAMETERS:
67fc151d 237applet - Pointer to the applet object to remove from the list
d9b91de7
KB
238
239RETURNS:
240True if the applet was found and removed, false if not. The applet itself
241is *not* destroyed!
242
243REMARKS:
244Remove an applet from the manager. Called during applet destruction
245****************************************************************************/
246bool wxHtmlAppletWindow::RemoveApplet(
67fc151d 247 const wxApplet *applet)
d9b91de7 248{
67fc151d
KB
249 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) {
250 if (node->GetData() == applet) {
251 m_AppletList.DeleteNode(node);
252 return true;
253 }
254 }
255 return false;
38caaa61 256}
d9b91de7
KB
257
258/****************************************************************************
259PARAMETERS:
67fc151d 260URL - New URL for the page to load
d9b91de7
KB
261
262RETURNS:
263True if page loaded successfully, false if not
264
265REMARKS:
266Remove an applet from the manager. Called during applet destruction
267****************************************************************************/
268bool wxHtmlAppletWindow::LoadPage(
38caaa61 269 const wxString& link)
d9b91de7 270{
505710ca
KB
271 wxString href(link);
272
38caaa61
KB
273 if (link.GetChar(0) == '?'){
274 wxString cmd = link.BeforeFirst('=');
275 wxString cmdValue = link.AfterFirst('=');
505710ca
KB
276
277 // Launches the default Internet browser for the system.
574c939e 278 if(!(cmd.CmpNoCase("?EXTERNAL"))) {
d699f48b 279 return wxSpawnBrowser(this, cmdValue.c_str());
38caaa61 280 }
505710ca
KB
281
282 // Launches an external program on the system.
574c939e
KB
283 if (!(cmd.CmpNoCase("?EXECUTE"))) {
284 int waitflag = P_NOWAIT;
285 bool ret;
286 wxString currentdir;
287 wxString filename, path, ext;
288
289 // Parse the params sent to the execute command. For now the only
290 // parm is "wait". wait will cause spawn wait, default is nowait.
291 // Since we only need one param for now I am not going to make this
292 // any smater then it needs to be. If we need more params later i'll
293 // fix it.
294 int i = cmdValue.Find('(');
295 if (i != -1) {
296 wxString param = cmdValue.AfterFirst('(');
297 cmdValue.Truncate(i);
298 if (!param.CmpNoCase("wait)"))
299 waitflag = P_WAIT;
300 }
301
302 currentdir = wxGetCwd();
303 //we don't want to change the path of the virtual file system so we have to use these
304 //functions rather than the filesystem
305 wxSplitPath(cmdValue, &path, &filename, &ext);
306 if (path.CmpNoCase("") != 0) wxSetWorkingDirectory(path);
307
308 ret = !spawnl( waitflag, cmdValue , NULL );
309 //HACK should use wxExecute
310 //ret = wxExecute(filename, bool sync = FALSE, wxProcess *callback = NULL)
311 wxSetWorkingDirectory(currentdir);
312
313 return ret;
38caaa61 314 }
505710ca
KB
315
316 // Looks for a href in a variable stored as a cookie. The href can be
317 // changed on the fly.
38caaa61 318 if (!(cmd.CmpNoCase("?VIRTUAL"))){
574c939e
KB
319 wxObject *obj = FindCookie(cmdValue);
320 VirtualData *virtData = wxDynamicCast(obj,VirtualData);
321 if (virtData) {
322 // recurse and loadpage, just in case the link is like another
323 // ? link
324 return LoadPage(virtData->GetHref());
38caaa61
KB
325 }
326 else {
327#ifdef CHECKED
d699f48b 328 wxLogError(_T("VIRTUAL LINK ERROR: '%s' does not exist."), cmdValue.c_str());
38caaa61
KB
329#endif
330 return true;
331 }
332 }
505710ca
KB
333
334 // This launches a qlet - It is like an applet but is more generic in that it
335 // can be of any wxWin type so it then has the freedom to do more stuff.
574c939e
KB
336 if (!(cmd.CmpNoCase("?WXPLUGIN"))){
337 if (!cmdValue.IsNull()) {
338 // TODO: We are going to need to add code to parse the command line
339 // parameters string in here in the future...
340 wxString cmdLine = link.AfterFirst('(');
341 cmdLine = cmdLine.BeforeLast(')');
342 if (!CreatePlugIn(cmdValue,cmdLine)) {
505710ca 343#ifdef CHECKED
574c939e 344 wxLogError(_T("Launch PlugIn ERROR: '%s' does not exist."), cmdValue.c_str());
505710ca
KB
345#endif
346 }
347 }
348 return true;
349 }
574c939e
KB
350
351 // This used in a link or href will take you back in the history.
352 if (!(cmd.CmpNoCase("?BACK"))){
353 HistoryBack();
354 return true;
355 }
356
357 // This used in a link or href will take you forward in the history
358 if (!(cmd.CmpNoCase("?FORWARD"))){
359 HistoryForward();
360 return true;
361 }
38caaa61
KB
362 }
363
38caaa61 364 // Inform all the applets that the new page is being loaded
67fc151d 365 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
38caaa61 366 (node->GetData())->OnLinkClicked(wxHtmlLinkInfo(href));
d699f48b 367 Show(false);
19193a2c 368
574c939e 369 m_openedlast = href;
38caaa61 370 bool stat = wxHtmlWindow::LoadPage(href);
d699f48b 371 Show(true);
716cd410 372
38caaa61 373 // Enable/Dis the navbar tools
19193a2c 374 if (m_NavBarEnabled) {
38caaa61
KB
375 m_NavBar->EnableTool(m_NavForwardId,HistoryCanForward());
376 m_NavBar->EnableTool(m_NavBackId,HistoryCanBack());
377 }
378 return stat;
d9b91de7
KB
379}
380
381/****************************************************************************
382PARAMETERS:
67fc151d 383URL - String URL that we are navigating to
d9b91de7
KB
384
385REMARKS:
386Called when the user navigates to a new URL from the current page. We simply
387call the LoadPage function above to load the new page and display it.
388****************************************************************************/
389void wxHtmlAppletWindow::OnLinkClicked(
67fc151d 390 const wxHtmlLinkInfo& link)
d9b91de7 391{
38caaa61 392 LoadPage(link.GetHref());
d9b91de7
KB
393}
394
395/****************************************************************************
396REMARKS:
397Called when the user navigates forward within the HTML history stack.
398We call all the applets in turn allowing them to handle the navigation
399command prior to being destructed when the current page is destroyed.
400****************************************************************************/
401bool wxHtmlAppletWindow::HistoryForward()
402{
38caaa61 403 if (!HistoryCanForward())
67fc151d 404 return false;
38caaa61 405
67fc151d
KB
406 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
407 (node->GetData())->OnHistoryForward();
38caaa61 408
67fc151d 409 return wxHtmlWindow::HistoryForward();
d9b91de7
KB
410}
411
412/****************************************************************************
413REMARKS:
414Called when the user navigates backwards within the HTML history stack.
415We call all the applets in turn allowing them to handle the navigation
416command prior to being destructed when the current page is destroyed.
417****************************************************************************/
418bool wxHtmlAppletWindow::HistoryBack()
419{
38caaa61 420 if (!HistoryCanBack())
67fc151d 421 return false;
38caaa61 422
67fc151d
KB
423 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
424 (node->GetData())->OnHistoryBack();
38caaa61 425
67fc151d 426 return wxHtmlWindow::HistoryBack();
d9b91de7
KB
427}
428
19193a2c
KB
429/****************************************************************************
430REMARKS:
431This function is used to disable the navigation bars. If you want to
432toggle to the navbars off you must call this function.
433****************************************************************************/
434void wxHtmlAppletWindow::DisableNavBar()
435{
436 m_NavBarEnabled = false;
437}
438
439/****************************************************************************
440REMARKS:
441This function is used to enable the nav bars. If you toggle the nav bars on
442you must call this function.
443****************************************************************************/
444void wxHtmlAppletWindow::EnableNavBar()
445{
446 m_NavBarEnabled = true;
447}
448
449/****************************************************************************
450REMARKS:
451This function is used to set the nav bar to a new nav bar if you deleted the
452one that you were useing. Usally this happens when you toggle a nav bar
453on or off.
454****************************************************************************/
455void wxHtmlAppletWindow::SetNavBar(wxToolBarBase *navBar)
456{
457 m_NavBar = navBar;
458}
459
d9b91de7
KB
460/****************************************************************************
461PARAMETERS:
67fc151d 462msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
463
464REMARKS:
465This function is called by the wxApplet's when they need to send a message
466to all other applets on the current page. This is the primary form of
467communication between applets on the page if they need to inform each
468other of internal information.
469
d9b91de7 470****************************************************************************/
574c939e
KB
471void wxHtmlAppletWindow::SendAppletMessage(
472 wxAppletEvent& msg)
38caaa61 473{
574c939e
KB
474 // TODO: make a named target for messages, only send a message to the correct
475 // named applet
38caaa61 476
67fc151d
KB
477 // Process all applets in turn and send them the message
478 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) {
479 (node->GetData())->OnMessage(msg);
67fc151d 480 }
d9b91de7
KB
481}
482
483/****************************************************************************
484PARAMETERS:
38caaa61
KB
485name - Uniq wxString used as hash key
486cookie - wxObject data returned when name is found.
d9b91de7
KB
487
488RETURNS:
67fc151d 489True if new cookie was added, false if cookie with same name already exists.
d9b91de7
KB
490
491REMARKS:
492This function is called by the wxApplet's when they need register a cookie
493of data in the applet window's cookie table. Cookies are arbitrary data
494objects that are references by unique name's by the wxApplet. These
495values can be used to store and retrieve data that needs to remain
496persisent across invocations of the wxApplet. Ie: The first time an
497applet is created it would use the cookie to store data to maintain
498it's present state so that if you navigated back to the same page
499is would be able to re-load the prior state as though the applet
500was never actually destructed.
501
502Note: If a cookie with the same name already exists, this function returns
67fc151d
KB
503 false. Hence if you wish to replace a cookie you should first call
504 UnRegisterCookie to ensure the cookie is deleted and then call this
505 function.
d9b91de7
KB
506****************************************************************************/
507bool wxHtmlAppletWindow::RegisterCookie(
67fc151d
KB
508 const wxString& name,
509 wxObject *cookie)
d9b91de7 510{
67fc151d
KB
511 // Fail if the named cookie already exists!
512 if (m_Cookies.Get(name))
513 return false;
38caaa61 514 m_Cookies.Put(name,cookie);
67fc151d 515 return true;
d9b91de7
KB
516}
517
518/****************************************************************************
519PARAMETERS:
38caaa61 520name - wxString uniq haskey used to remove item from hash
d9b91de7
KB
521
522RETURNS:
523True if found and deleted, false if not found in table.
524
525REMARKS:
526This function is called by the wxApplet's when they need de-register a
527cookie of data in the applet window's cookie table. The data in the
528cookie itself is also deleted before it is removed from the table.
529****************************************************************************/
530bool wxHtmlAppletWindow::UnRegisterCookie(
67fc151d 531 const wxString& name)
d9b91de7 532{
67fc151d
KB
533 wxObject *data = m_Cookies.Delete(name);
534 if (data) {
535 delete data;
536 return true;
537 }
538 return false;
d9b91de7
KB
539}
540
541/****************************************************************************
542PARAMETERS:
67fc151d 543msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
544
545RETURNS:
546Pointer to the cookie data if found, NULL if not found.
547
548REMARKS:
549This function is called by the wxApplet's when they need to find a cookie
550of data given it's public name. If the cookie is not found, NULL is
551returned.
552****************************************************************************/
553wxObject *wxHtmlAppletWindow::FindCookie(
67fc151d 554 const wxString& name)
d9b91de7 555{
67fc151d 556 return m_Cookies.Get(name);
d9b91de7
KB
557}
558
38caaa61
KB
559/****************************************************************************
560PARAMETERS:
561event - Event to handle
562
563REMARKS:
564This function handles delayed LoadPage events posted from applets that
565need to change the page for the current window to a new window.
566****************************************************************************/
567void wxHtmlAppletWindow::OnLoadPage(
568 wxLoadPageEvent &event)
569{
d699f48b 570 // Test the mutex lock.
574c939e 571 if (!(IsLocked())) {
d699f48b 572 Lock();
574c939e
KB
573 if (event.GetHtmlWindow() == this) {
574 if (LoadPage(event.GetHRef())) {
716cd410
KB
575 // wxPageLoadedEvent evt;
576 // NOTE: This is reserved for later use as we might need to send
577 // page loaded events to applets.
578 }
38caaa61 579 }
716cd410 580 UnLock();
38caaa61
KB
581 }
582}
583
584/****************************************************************************
585PARAMETERS:
586event - Event to handle
587
588REMARKS:
589This function handles delayed LoadPage events posted from applets that
590need to change the page for the current window to a new window.
591****************************************************************************/
592void wxHtmlAppletWindow::OnPageLoaded(
593 wxPageLoadedEvent &)
594{
595 Enable(true);
596}
597
716cd410
KB
598/****************************************************************************
599PARAMETERS:
600none
601
602REMARKS:
603This function tries to lock the mutex. If it can't, returns
604immediately with false.
605***************************************************************************/
606bool wxHtmlAppletWindow::TryLock()
607{
608 if (!m_mutexLock) {
609 m_mutexLock = true;
610 return true;
611 }
612 return false;
613}
614
38caaa61
KB
615/****************************************************************************
616PARAMETERS:
617name - name of the last applet that changed the data in this object
618group - name of the group the allplet belongs to.
619href - webpage to go to.
620
621REMARKS:
622VirtualData is used to store information on the virtual links.
623****************************************************************************/
624VirtualData::VirtualData(
625 wxString& name,
626 wxString& group,
574c939e
KB
627 wxString& href,
628 wxString& plugin )
38caaa61
KB
629{
630 m_name = name;
631 m_group = group;
632 m_href = href;
574c939e 633 m_plugIn = plugin;
38caaa61
KB
634}
635
19193a2c
KB
636/****************************************************************************
637PARAMETERS:
638REMARKS:
639VirtualData is used to store information on the virtual links.
640****************************************************************************/
641VirtualData::VirtualData()
642{
643 m_name.Empty();
644 m_group.Empty();
645 m_href.Empty();
646}
647
d9b91de7
KB
648#include "wx/html/m_templ.h"
649
650/****************************************************************************
651REMARKS:
652Implementation for the <embed> HTML tag handler. This handler takes care
653of automatically constructing the wxApplet objects of the appropriate
654class based on the <embed> tag information.
655****************************************************************************/
38caaa61 656TAG_HANDLER_BEGIN(wxApplet, "WXAPPLET")
d9b91de7
KB
657
658TAG_HANDLER_PROC(tag)
659{
38caaa61
KB
660 wxWindow *wnd;
661 wxHtmlAppletWindow *appletWindow;
662 wxApplet *applet;
663 wxString classId;
664 wxString name;
665 int width, height;
666
574c939e 667 // Get access to our wxHtmlAppletWindow class
38caaa61 668 wnd = m_WParser->GetWindow();
574c939e
KB
669 if ((appletWindow = wxDynamicCast(wnd,wxHtmlAppletWindow)) == NULL)
670 return false;
38caaa61 671
574c939e
KB
672 // Parse the applet dimensions from the tag
673 wxSize size = wxDefaultSize;
674 int al;
675 if (tag.HasParam("WIDTH")) {
676 tag.GetParamAsInt("WIDTH", &width);
677 size.SetWidth(width);
678 }
679 if (tag.HasParam("HEIGHT")) {
680 tag.GetParamAsInt("HEIGHT", &height);
681 size.SetHeight(height);
682 }
505710ca 683
574c939e
KB
684 // Parse the applet alignment from the tag
685 al = wxHTML_ALIGN_BOTTOM;
686 if (tag.HasParam(wxT("ALIGN"))) {
687 wxString alstr = tag.GetParam(wxT("ALIGN"));
688 alstr.MakeUpper(); // for the case alignment was in ".."
689 if (alstr == wxT("TEXTTOP") || alstr == wxT("TOP"))
690 al = wxHTML_ALIGN_TOP;
691 else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
692 al = wxHTML_ALIGN_CENTER;
693 }
505710ca 694
574c939e
KB
695 // Create the applet based on it's class
696 if (tag.HasParam("CLASSID")) {
697 classId = tag.GetParam("CLASSID");
698 if (classId.IsNull() || classId.Len() == 0) {
699 wxMessageBox("wxApplet tag error: CLASSID is NULL or empty.","Error",wxICON_ERROR);
38caaa61 700 return false;
67fc151d 701 }
574c939e
KB
702 if (tag.HasParam("NAME"))
703 name = tag.GetParam("NAME");
704
705 // If the name is NULL or len is zero then we assume that the html guy
706 // didn't include the name param which is optional.
707 if (name.IsNull() || name.Len() == 0)
708 name = classId;
709
710 // We got all the params and can now create the applet
711 if ((applet = appletWindow->CreateApplet(classId, name, tag , size)) != NULL) {
712 applet->Show(true);
713 m_WParser->OpenContainer()->InsertCell(new wxHtmlAppletCell(applet,al));
714 }
715 else
716 wxMessageBox("wxApplet error: Could not create:" + classId + "," + name);
717 }
718 else {
719 wxMessageBox("wxApplet tag error: Can not find CLASSID param.","Error",wxICON_ERROR);
720 return false;
67fc151d 721 }
38caaa61 722
574c939e
KB
723 // Add more param parsing here. If or when spec changes.
724 // For now we'll ignore any other params those HTML guys
725 // might put in our tag.
726 return true;
d9b91de7
KB
727}
728
38caaa61
KB
729TAG_HANDLER_END(wxApplet)
730
731TAGS_MODULE_BEGIN(wxApplet)
732 TAGS_MODULE_ADD(wxApplet)
733TAGS_MODULE_END(wxApplet)
d9b91de7 734
574c939e
KB
735/****************************************************************************
736REMARKS:
737Constructor for the HTML cell class to store our wxApplet windows in
738the HTML page to be rendered by wxHTML.
739****************************************************************************/
740wxHtmlAppletCell::wxHtmlAppletCell(
741 wxWindow *wnd,
742 int align)
743 : wxHtmlCell()
505710ca
KB
744{
745 int sx, sy;
746 m_Wnd = wnd;
747 m_Wnd->GetSize(&sx, &sy);
748 m_Width = sx, m_Height = sy;
505710ca
KB
749 switch (align) {
750 case wxHTML_ALIGN_TOP :
751 m_Descent = m_Height;
752 break;
753 case wxHTML_ALIGN_CENTER :
754 m_Descent = m_Height / 2;
755 break;
756 case wxHTML_ALIGN_BOTTOM :
757 default :
758 m_Descent = 0;
759 break;
760 }
505710ca
KB
761 SetCanLiveOnPagebreak(FALSE);
762}
763
574c939e
KB
764/****************************************************************************
765REMARKS:
766Implementation for the HTML cell class to store our wxApplet windows in
767the HTML page to be rendered by wxHTML.
768****************************************************************************/
769wxHtmlAppletCell::~wxHtmlAppletCell()
770{
771 delete m_Wnd;
772}
505710ca 773
574c939e
KB
774/****************************************************************************
775REMARKS:
776Code to draw the html applet cell
777****************************************************************************/
778void wxHtmlAppletCell::Draw(
779 wxDC& WXUNUSED(dc),
780 int WXUNUSED(x),
781 int WXUNUSED(y),
782 int WXUNUSED(view_y1),
783 int WXUNUSED(view_y2))
505710ca 784{
574c939e
KB
785 int absx = 0, absy = 0, stx, sty;
786 wxHtmlCell *c = this;
505710ca 787
574c939e 788 while (c) {
505710ca
KB
789 absx += c->GetPosX();
790 absy += c->GetPosY();
791 c = c->GetParent();
574c939e 792 }
505710ca
KB
793 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
794 m_Wnd->Move(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty);
795}
796
574c939e
KB
797/****************************************************************************
798REMARKS:
799Code to draw the html applet cell invisibly
800****************************************************************************/
801void wxHtmlAppletCell::DrawInvisible(
802 wxDC& WXUNUSED(dc),
803 int WXUNUSED(x),
804 int WXUNUSED(y))
505710ca 805{
574c939e
KB
806 int absx = 0, absy = 0, stx, sty;
807 wxHtmlCell *c = this;
505710ca 808
574c939e 809 while (c) {
505710ca
KB
810 absx += c->GetPosX();
811 absy += c->GetPosY();
812 c = c->GetParent();
574c939e 813 }
505710ca
KB
814 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
815 m_Wnd->Move(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty);
816}
817
574c939e
KB
818/****************************************************************************
819REMARKS:
820Code to layout the html applet cell.
821****************************************************************************/
822void wxHtmlAppletCell::Layout(
823 int w)
505710ca
KB
824{
825 int sx, sy;
826 m_Wnd->GetSize(&sx, &sy);
827 m_Width = sx, m_Height = sy;
505710ca
KB
828 wxHtmlCell::Layout(w);
829}
830
38caaa61
KB
831// This is our little forcelink hack.
832FORCE_LINK(loadpage)
d9b91de7 833