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