]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/applet/appletwindow.cpp
Enabling the Pop Menu fix to peek at all the command messages. Required adding a...
[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*
8* ======================================================================
9* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
10* | |
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. |
18* | |
19* |If you received this code in error or you would like to report |
20* |improper use, please immediately contact SciTech Software, Inc. at |
21* |530-894-8400. |
22* | |
23* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
24* ======================================================================
25*
67fc151d
KB
26* Language: ANSI C++
27* Environment: Any
d9b91de7
KB
28*
29* Description: Main wxHtmlAppletWindow class implementation
30*
31****************************************************************************/
32
33// For compilers that support precompilation
34#include "wx/wxprec.h"
35
36// Include private headers
37#include "wx/applet/applet.h"
38
39/*------------------------- Implementation --------------------------------*/
40
41// Empty event handler. We include this event handler simply so that
42// sub-classes of wxApplet can reference wxApplet in the event tables
43// that they create as necessary.
44BEGIN_EVENT_TABLE(wxHtmlAppletWindow, wxHtmlWindow)
45END_EVENT_TABLE()
46
47// Implement the class functions for wxHtmlAppletWindow
48IMPLEMENT_CLASS(wxHtmlAppletWindow, wxHtmlWindow);
49
50// Define the wxAppletList implementation
51#include "wx/listimpl.cpp"
52WX_DEFINE_LIST(wxAppletList);
53
54/****************************************************************************
55REMARKS:
56Constructor for the applet window class.
57****************************************************************************/
58wxHtmlAppletWindow::wxHtmlAppletWindow(
67fc151d
KB
59 wxWindow *parent,
60 wxWindowID id,
61 const wxPoint& pos,
62 const wxSize& size,
63 long style,
64 const wxString& name)
65 : wxHtmlWindow(parent,id,pos,size,style,name)
d9b91de7 66{
67fc151d
KB
67 // Ensure all cookie data is destroyed when window is killed
68 m_Cookies.DeleteContents(true);
d9b91de7
KB
69}
70
71/****************************************************************************
72REMARKS:
73Destructor for the applet window class.
74****************************************************************************/
75wxHtmlAppletWindow::~wxHtmlAppletWindow()
76{
77}
78
79/****************************************************************************
80PARAMETERS:
67fc151d
KB
81className - Name of the applet class to create an object for
82size - Initial size of the applet to be created
d9b91de7
KB
83
84RETURNS:
85Pointer to the wxApplet created, or NULL if unable to create the applet.
86
87REMARKS:
88This function is used to create new wxApplet objects dynamically based on the
89class name as a string. This allows instances of wxApplet classes to be
90created dynamically based on string values embedded in the custom tags of an
91HTML page.
92****************************************************************************/
93wxApplet *wxHtmlAppletWindow::CreateApplet(
67fc151d
KB
94 const wxString& className,
95 const wxSize& size)
d9b91de7 96{
67fc151d
KB
97 // We presently only allow one applet per page of the same class!
98 if (m_AppletList.Find(className))
99 return NULL;
d9b91de7 100
67fc151d
KB
101 // Dynamically create the class instance at runtime
102 wxClassInfo *info = wxClassInfo::FindClass(className.c_str());
d9b91de7
KB
103 if (!info)
104 return NULL;
67fc151d
KB
105 wxObject *obj = info->CreateObject();
106 if (!obj)
107 return NULL;
d9b91de7 108 wxApplet *applet = wxDynamicCast(obj,wxApplet);
67fc151d
KB
109 if (!applet)
110 return NULL;
111 if (!applet->Create(this,size)) {
112 delete applet;
113 return NULL;
114 }
115 m_AppletList.Append(className,applet);
116 return applet;
d9b91de7
KB
117}
118
119/****************************************************************************
120PARAMETERS:
67fc151d 121appletName - Name of the applet class to find
d9b91de7
KB
122
123RETURNS:
124Pointer to the wxApplet found, or NULL if not found.
125
126REMARKS:
127Find an instance of an applet based on it's name
128****************************************************************************/
129wxApplet *wxHtmlAppletWindow::FindApplet(
67fc151d 130 const wxString& appletName)
d9b91de7 131{
67fc151d
KB
132 wxAppletList::Node *node = m_AppletList.Find(appletName);
133 if (!node)
134 return NULL;
135 return node->GetData();
136}
d9b91de7
KB
137
138/****************************************************************************
139PARAMETERS:
67fc151d 140applet - Pointer to the applet object to remove from the list
d9b91de7
KB
141
142RETURNS:
143True if the applet was found and removed, false if not. The applet itself
144is *not* destroyed!
145
146REMARKS:
147Remove an applet from the manager. Called during applet destruction
148****************************************************************************/
149bool wxHtmlAppletWindow::RemoveApplet(
67fc151d 150 const wxApplet *applet)
d9b91de7 151{
67fc151d
KB
152 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) {
153 if (node->GetData() == applet) {
154 m_AppletList.DeleteNode(node);
155 return true;
156 }
157 }
158 return false;
159}
d9b91de7
KB
160
161/****************************************************************************
162PARAMETERS:
67fc151d 163URL - New URL for the page to load
d9b91de7
KB
164
165RETURNS:
166True if page loaded successfully, false if not
167
168REMARKS:
169Remove an applet from the manager. Called during applet destruction
170****************************************************************************/
171bool wxHtmlAppletWindow::LoadPage(
67fc151d 172 const wxString& hRef)
d9b91de7 173{
67fc151d
KB
174 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
175 (node->GetData())->OnLinkClicked(hRef);
176 return wxHtmlWindow::LoadPage(hRef);
d9b91de7
KB
177}
178
179/****************************************************************************
180PARAMETERS:
67fc151d 181URL - String URL that we are navigating to
d9b91de7
KB
182
183REMARKS:
184Called when the user navigates to a new URL from the current page. We simply
185call the LoadPage function above to load the new page and display it.
186****************************************************************************/
187void wxHtmlAppletWindow::OnLinkClicked(
67fc151d 188 const wxHtmlLinkInfo& link)
d9b91de7 189{
67fc151d
KB
190 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
191 (node->GetData())->OnLinkClicked(link);
192 wxHtmlWindow::LoadPage(link.GetHref());
d9b91de7
KB
193}
194
195/****************************************************************************
196REMARKS:
197Called when the user navigates forward within the HTML history stack.
198We call all the applets in turn allowing them to handle the navigation
199command prior to being destructed when the current page is destroyed.
200****************************************************************************/
201bool wxHtmlAppletWindow::HistoryForward()
202{
67fc151d
KB
203 if (!HistoryCanForward())
204 return false;
205 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
206 (node->GetData())->OnHistoryForward();
207 return wxHtmlWindow::HistoryForward();
d9b91de7
KB
208}
209
210/****************************************************************************
211REMARKS:
212Called when the user navigates backwards within the HTML history stack.
213We call all the applets in turn allowing them to handle the navigation
214command prior to being destructed when the current page is destroyed.
215****************************************************************************/
216bool wxHtmlAppletWindow::HistoryBack()
217{
67fc151d
KB
218 if (!HistoryCanBack())
219 return false;
220 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext())
221 (node->GetData())->OnHistoryBack();
222 return wxHtmlWindow::HistoryBack();
d9b91de7
KB
223}
224
225/****************************************************************************
226PARAMETERS:
67fc151d 227msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
228
229REMARKS:
230This function is called by the wxApplet's when they need to send a message
231to all other applets on the current page. This is the primary form of
232communication between applets on the page if they need to inform each
233other of internal information.
234
235Note that the event handling terminates as soon as the first wxApplet
236handles the event. If the event should be handled by all wxApplet's,
237the event handlers for the applets should not reset the wxEvent::Skip()
238value (ie: by default it is true).
239****************************************************************************/
240void wxHtmlAppletWindow::SendMessage(
67fc151d
KB
241 wxEvent& msg)
242{
243 // Preset the skip flag
244 msg.Skip();
245
246 // Process all applets in turn and send them the message
247 for (wxAppletList::Node *node = m_AppletList.GetFirst(); node; node = node->GetNext()) {
248 (node->GetData())->OnMessage(msg);
249 if (!msg.GetSkipped())
250 break;
251 }
d9b91de7
KB
252}
253
254/****************************************************************************
255PARAMETERS:
67fc151d 256msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
257
258RETURNS:
67fc151d 259True if new cookie was added, false if cookie with same name already exists.
d9b91de7
KB
260
261REMARKS:
262This function is called by the wxApplet's when they need register a cookie
263of data in the applet window's cookie table. Cookies are arbitrary data
264objects that are references by unique name's by the wxApplet. These
265values can be used to store and retrieve data that needs to remain
266persisent across invocations of the wxApplet. Ie: The first time an
267applet is created it would use the cookie to store data to maintain
268it's present state so that if you navigated back to the same page
269is would be able to re-load the prior state as though the applet
270was never actually destructed.
271
272Note: If a cookie with the same name already exists, this function returns
67fc151d
KB
273 false. Hence if you wish to replace a cookie you should first call
274 UnRegisterCookie to ensure the cookie is deleted and then call this
275 function.
d9b91de7
KB
276****************************************************************************/
277bool wxHtmlAppletWindow::RegisterCookie(
67fc151d
KB
278 const wxString& name,
279 wxObject *cookie)
d9b91de7 280{
67fc151d
KB
281 // Fail if the named cookie already exists!
282 if (m_Cookies.Get(name))
283 return false;
284 m_Cookies.Put(name,cookie);
285 return true;
d9b91de7
KB
286}
287
288/****************************************************************************
289PARAMETERS:
67fc151d 290msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
291
292RETURNS:
293True if found and deleted, false if not found in table.
294
295REMARKS:
296This function is called by the wxApplet's when they need de-register a
297cookie of data in the applet window's cookie table. The data in the
298cookie itself is also deleted before it is removed from the table.
299****************************************************************************/
300bool wxHtmlAppletWindow::UnRegisterCookie(
67fc151d 301 const wxString& name)
d9b91de7 302{
67fc151d
KB
303 wxObject *data = m_Cookies.Delete(name);
304 if (data) {
305 delete data;
306 return true;
307 }
308 return false;
d9b91de7
KB
309}
310
311/****************************************************************************
312PARAMETERS:
67fc151d 313msg - wxEvent message to be sent to all wxApplets
d9b91de7
KB
314
315RETURNS:
316Pointer to the cookie data if found, NULL if not found.
317
318REMARKS:
319This function is called by the wxApplet's when they need to find a cookie
320of data given it's public name. If the cookie is not found, NULL is
321returned.
322****************************************************************************/
323wxObject *wxHtmlAppletWindow::FindCookie(
67fc151d 324 const wxString& name)
d9b91de7 325{
67fc151d 326 return m_Cookies.Get(name);
d9b91de7
KB
327}
328
329#include "wx/html/m_templ.h"
330
331/****************************************************************************
332REMARKS:
333Implementation for the <embed> HTML tag handler. This handler takes care
334of automatically constructing the wxApplet objects of the appropriate
335class based on the <embed> tag information.
336****************************************************************************/
337TAG_HANDLER_BEGIN(Embed, "EMBED")
338
339TAG_HANDLER_PROC(tag)
340{
67fc151d
KB
341 wxWindow *wnd;
342 wxHtmlAppletWindow *appletWindow;
343 wxApplet *applet;
344 int width, height;
345 int floatPercent = 0;
346
347 wnd = m_WParser->GetWindow();
348 if ((appletWindow = wxDynamicCast(wnd,wxHtmlAppletWindow)) != NULL) {
349 tag.ScanParam("WIDTH", "%i", &width);
350 tag.ScanParam("HEIGHT", "%i", &height);
351 if (tag.HasParam("FLOAT"))
352 tag.ScanParam("FLOAT", "%i", &floatPercent);
353 if (tag.HasParam("APPLET")) {
354 if ((applet = appletWindow->CreateApplet(tag.GetParam("APPLET"), wxSize(width, height))) != NULL) {
355 applet->Show(true);
356 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(applet,floatPercent));
357 }
358 }
359 else if (tag.HasParam("TEXT")) {
360 // TODO: Somehow get the text returned from this class displayed on the page!
361 }
362 }
363 return false;
d9b91de7
KB
364}
365
366TAG_HANDLER_END(Embed)
367
368TAGS_MODULE_BEGIN(Embed)
369 TAGS_MODULE_ADD(Embed)
370TAGS_MODULE_END(Embed)
371