]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/appletwindow.cpp
1 /****************************************************************************
3 * wxWindows HTML Applet Package
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ======================================================================
9 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
11 * |This copyrighted computer code is a proprietary trade secret of |
12 * |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 |
13 * |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, |
14 * |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS |
15 * |STRICTLY PROHIBITED BY LAW. Unless you have current, express |
16 * |written authorization from SciTech to possess or use this code, you |
17 * |may be subject to civil and/or criminal penalties. |
19 * |If you received this code in error or you would like to report |
20 * |improper use, please immediately contact SciTech Software, Inc. at |
23 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
24 * ======================================================================
29 * Description: Main wxHtmlAppletWindow class implementation
31 ****************************************************************************/
33 // For compilers that support precompilation
34 #include "wx/wxprec.h"
35 #include "wx/html/forcelnk.h"
37 // Include private headers
38 #include "wx/applet/applet.h"
39 #include "wx/applet/window.h"
40 #include "wx/applet/loadpage.h"
43 #include "wx/applet/prepinclude.h"
44 #include "wx/applet/prepecho.h"
45 #include "wx/applet/prepifelse.h"
48 /*---------------------------- Global variables ---------------------------*/
50 wxHashTable
wxHtmlAppletWindow::m_Cookies
;
52 /*------------------------- Implementation --------------------------------*/
54 // Empty event handler. We include this event handler simply so that
55 // sub-classes of wxApplet can reference wxApplet in the event tables
56 // that they create as necessary.
57 BEGIN_EVENT_TABLE(wxHtmlAppletWindow
, wxHtmlWindow
)
58 EVT_LOAD_PAGE(wxHtmlAppletWindow::OnLoadPage
)
59 EVT_PAGE_LOADED(wxHtmlAppletWindow::OnPageLoaded
)
62 // Implement the class functions for wxHtmlAppletWindow
63 IMPLEMENT_CLASS(wxHtmlAppletWindow
, wxHtmlWindow
);
65 // Define the wxAppletList implementation
66 #include "wx/listimpl.cpp"
67 WX_DEFINE_LIST(wxAppletList
);
69 /****************************************************************************
71 Constructor for the applet window class.
72 ****************************************************************************/
73 wxHtmlAppletWindow::wxHtmlAppletWindow(
76 wxToolBarBase
*navBar
,
83 : wxHtmlWindow(parent
,id
,pos
,size
,style
,name
)
85 //setup client navbars
88 m_NavBackId
= navBackId
;
89 m_NavForwardId
= navForwardId
;
95 //Add HTML preprocessors
96 // deleting preprocessors is done by the code within the window
98 incPreprocessor
= new wxIncludePrep(); // #include preprocessor
99 wxEchoPrep
* echoPreprocessor
= new wxEchoPrep(); // #echo preprocessor
100 wxIfElsePrep
* ifPreprocessor
= new wxIfElsePrep();
102 this->AddProcessor(incPreprocessor
);
103 this->AddProcessor(echoPreprocessor
);
104 this->AddProcessor(ifPreprocessor
);
109 /****************************************************************************
111 Destructor for the applet window class.
112 ****************************************************************************/
113 wxHtmlAppletWindow::~wxHtmlAppletWindow()
117 /****************************************************************************
119 className - Name of the applet class to create an object for
120 size - Initial size of the applet to be created
123 Pointer to the wxApplet created, or NULL if unable to create the applet.
126 This function is used to create new wxApplet objects dynamically based on the
127 class name as a string. This allows instances of wxApplet classes to be
128 created dynamically based on string values embedded in the custom tags of an
130 ****************************************************************************/
131 wxApplet
*wxHtmlAppletWindow::CreateApplet(
132 const wxString
& classId
,
133 const wxString
& iName
,
134 const wxHtmlTag
& params
,
137 // Dynamically create the class instance at runtime
138 wxClassInfo
*info
= wxClassInfo::FindClass(classId
.c_str());
141 wxObject
*obj
= info
->CreateObject();
144 wxApplet
*applet
= wxDynamicCast(obj
,wxApplet
);
147 if (!applet
->Create(this,params
,size
)) {
151 m_AppletList
.Append(iName
,applet
);
155 /****************************************************************************
157 appletName - Name of the applet class to find
160 Pointer to the wxApplet found, or NULL if not found.
163 Find an instance of an applet based on it's name
164 ****************************************************************************/
165 wxApplet
*wxHtmlAppletWindow::FindApplet(
166 const wxString
& appletName
)
168 wxAppletList::Node
*node
= m_AppletList
.Find(appletName
);
171 return node
->GetData();
174 /****************************************************************************
176 applet - Pointer to the applet object to remove from the list
179 True if the applet was found and removed, false if not. The applet itself
183 Remove an applet from the manager. Called during applet destruction
184 ****************************************************************************/
185 bool wxHtmlAppletWindow::RemoveApplet(
186 const wxApplet
*applet
)
188 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext()) {
189 if (node
->GetData() == applet
) {
190 m_AppletList
.DeleteNode(node
);
197 /****************************************************************************
199 URL - New URL for the page to load
202 True if page loaded successfully, false if not
205 Remove an applet from the manager. Called during applet destruction
206 ****************************************************************************/
207 bool wxHtmlAppletWindow::LoadPage(
208 const wxString
& link
)
212 // TODO: This needs to be made platform inde if possible.
213 if (link
.GetChar(0) == '?'){
214 wxString cmd
= link
.BeforeFirst('=');
215 wxString cmdValue
= link
.AfterFirst('=');
217 if(!(cmd
.CmpNoCase("?EXTERNAL"))){
219 ShellExecute(this ? (HWND
)this->GetHWND() : NULL
,NULL
,cmdValue
.c_str(),NULL
,"",SW_SHOWNORMAL
);
221 #error Platform not implemented yet!
225 if (!(cmd
.CmpNoCase("?EXECUTE"))){
226 wxMessageBox(cmdValue
);
229 if (!(cmd
.CmpNoCase("?VIRTUAL"))){
230 VirtualData
& temp
= *((VirtualData
*)FindCookie(cmdValue
));
232 href
= temp
.GetHref();
236 wxMessageBox("VIRTUAL LINK ERROR: " + cmdValue
+ " does not exist.");
243 // Grab the directory from the string for use in the include preprocessor
244 // make sure we get either type of / or \.
245 int ch
= link
.Find('\\', true);
246 if (ch
== -1) ch
= link
.Find('/', true);
249 wxString tmp
= link
.Mid(0, ch
+1);
250 fs
.ChangePathTo(incPreprocessor
->GetDirectory(), true);
251 fs
.ChangePathTo(tmp
, true);
252 incPreprocessor
->ChangeDirectory(fs
.GetPath());
255 // Inform all the applets that the new page is being loaded
256 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
257 (node
->GetData())->OnLinkClicked(wxHtmlLinkInfo(href
));
258 bool stat
= wxHtmlWindow::LoadPage(href
);
260 // Enable/Dis the navbar tools
262 m_NavBar
->EnableTool(m_NavForwardId
,HistoryCanForward());
263 m_NavBar
->EnableTool(m_NavBackId
,HistoryCanBack());
268 /****************************************************************************
270 URL - String URL that we are navigating to
273 Called when the user navigates to a new URL from the current page. We simply
274 call the LoadPage function above to load the new page and display it.
275 ****************************************************************************/
276 void wxHtmlAppletWindow::OnLinkClicked(
277 const wxHtmlLinkInfo
& link
)
279 LoadPage(link
.GetHref());
282 /****************************************************************************
284 Called when the user navigates forward within the HTML history stack.
285 We call all the applets in turn allowing them to handle the navigation
286 command prior to being destructed when the current page is destroyed.
287 ****************************************************************************/
288 bool wxHtmlAppletWindow::HistoryForward()
290 if (!HistoryCanForward())
293 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
294 (node
->GetData())->OnHistoryForward();
296 return wxHtmlWindow::HistoryForward();
299 /****************************************************************************
301 Called when the user navigates backwards within the HTML history stack.
302 We call all the applets in turn allowing them to handle the navigation
303 command prior to being destructed when the current page is destroyed.
304 ****************************************************************************/
305 bool wxHtmlAppletWindow::HistoryBack()
307 if (!HistoryCanBack())
310 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
311 (node
->GetData())->OnHistoryBack();
313 return wxHtmlWindow::HistoryBack();
316 /****************************************************************************
318 msg - wxEvent message to be sent to all wxApplets
321 This function is called by the wxApplet's when they need to send a message
322 to all other applets on the current page. This is the primary form of
323 communication between applets on the page if they need to inform each
324 other of internal information.
326 Note that the event handling terminates as soon as the first wxApplet
327 handles the event. If the event should be handled by all wxApplet's,
328 the event handlers for the applets should not reset the wxEvent::Skip()
329 value (ie: by default it is true).
330 ****************************************************************************/
331 void wxHtmlAppletWindow::SendMessage(
334 // Preset the skip flag
337 // Process all applets in turn and send them the message
338 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext()) {
339 (node
->GetData())->OnMessage(msg
);
340 if (!msg
.GetSkipped()){
341 wxMessageBox("BREAK");
347 /****************************************************************************
349 name - Uniq wxString used as hash key
350 cookie - wxObject data returned when name is found.
353 True if new cookie was added, false if cookie with same name already exists.
356 This function is called by the wxApplet's when they need register a cookie
357 of data in the applet window's cookie table. Cookies are arbitrary data
358 objects that are references by unique name's by the wxApplet. These
359 values can be used to store and retrieve data that needs to remain
360 persisent across invocations of the wxApplet. Ie: The first time an
361 applet is created it would use the cookie to store data to maintain
362 it's present state so that if you navigated back to the same page
363 is would be able to re-load the prior state as though the applet
364 was never actually destructed.
366 Note: If a cookie with the same name already exists, this function returns
367 false. Hence if you wish to replace a cookie you should first call
368 UnRegisterCookie to ensure the cookie is deleted and then call this
370 ****************************************************************************/
371 bool wxHtmlAppletWindow::RegisterCookie(
372 const wxString
& name
,
375 // Fail if the named cookie already exists!
376 if (m_Cookies
.Get(name
))
378 m_Cookies
.Put(name
,cookie
);
382 /****************************************************************************
384 name - wxString uniq haskey used to remove item from hash
387 True if found and deleted, false if not found in table.
390 This function is called by the wxApplet's when they need de-register a
391 cookie of data in the applet window's cookie table. The data in the
392 cookie itself is also deleted before it is removed from the table.
393 ****************************************************************************/
394 bool wxHtmlAppletWindow::UnRegisterCookie(
395 const wxString
& name
)
397 wxObject
*data
= m_Cookies
.Delete(name
);
405 /****************************************************************************
407 msg - wxEvent message to be sent to all wxApplets
410 Pointer to the cookie data if found, NULL if not found.
413 This function is called by the wxApplet's when they need to find a cookie
414 of data given it's public name. If the cookie is not found, NULL is
416 ****************************************************************************/
417 wxObject
*wxHtmlAppletWindow::FindCookie(
418 const wxString
& name
)
420 return m_Cookies
.Get(name
);
423 /****************************************************************************
425 event - Event to handle
428 This function handles delayed LoadPage events posted from applets that
429 need to change the page for the current window to a new window.
430 ****************************************************************************/
431 void wxHtmlAppletWindow::OnLoadPage(
432 wxLoadPageEvent
&event
)
434 if (event
.GetHtmlWindow() == this){
435 if (LoadPage(event
.GetHRef())){
436 wxPageLoadedEvent evt
;
441 /****************************************************************************
443 event - Event to handle
446 This function handles delayed LoadPage events posted from applets that
447 need to change the page for the current window to a new window.
448 ****************************************************************************/
449 void wxHtmlAppletWindow::OnPageLoaded(
455 /****************************************************************************
457 name - name of the last applet that changed the data in this object
458 group - name of the group the allplet belongs to.
459 href - webpage to go to.
462 VirtualData is used to store information on the virtual links.
463 ****************************************************************************/
464 VirtualData::VirtualData(
474 #include "wx/html/m_templ.h"
476 /****************************************************************************
478 Implementation for the <embed> HTML tag handler. This handler takes care
479 of automatically constructing the wxApplet objects of the appropriate
480 class based on the <embed> tag information.
481 ****************************************************************************/
482 TAG_HANDLER_BEGIN(wxApplet
, "WXAPPLET")
484 TAG_HANDLER_PROC(tag
)
487 wxHtmlAppletWindow
*appletWindow
;
493 wnd
= m_WParser
->GetWindow();
495 if ((appletWindow
= wxDynamicCast(wnd
,wxHtmlAppletWindow
)) != NULL
){
496 tag
.ScanParam("WIDTH", "%i", &width
);
497 tag
.ScanParam("HEIGHT", "%i", &height
);
498 if (tag
.HasParam("CLASSID")){
499 classId
= tag
.GetParam("CLASSID");
500 if ( classId
.IsNull() || classId
.Len() == 0 ){
501 wxMessageBox("wxApplet tag error: CLASSID is NULL or empty.","Error",wxICON_ERROR
);
504 if (tag
.HasParam("NAME"))
505 name
= tag
.GetParam("NAME");
507 // If the name is NULL or len is zero then we assume that the html guy
508 // didn't include the name param which is optional.
509 if ( name
.IsNull() || name
.Len() == 0 )
512 // We got all the params and can now create the applet
513 if ((applet
= appletWindow
->CreateApplet(classId
, name
, tag
, wxSize(width
, height
))) != NULL
){
515 m_WParser
->OpenContainer()->InsertCell(new wxHtmlWidgetCell(applet
,0));
518 wxMessageBox("wxApplet error: Could not create:" + classId
+ "," + name
);
521 wxMessageBox("wxApplet tag error: Can not find CLASSID param.","Error",wxICON_ERROR
);
524 //Add more param parsing here. If or when spec changes.
525 //For now we'll ignore any other params those HTML guys
526 //might put in our tag.
532 TAG_HANDLER_END(wxApplet
)
534 TAGS_MODULE_BEGIN(wxApplet
)
535 TAGS_MODULE_ADD(wxApplet
)
536 TAGS_MODULE_END(wxApplet
)
538 // This is our little forcelink hack.