]>
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"
36 // Include private headers
37 #include "wx/applet/applet.h"
39 /*------------------------- Implementation --------------------------------*/
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.
44 BEGIN_EVENT_TABLE(wxHtmlAppletWindow
, wxHtmlWindow
)
47 // Implement the class functions for wxHtmlAppletWindow
48 IMPLEMENT_CLASS(wxHtmlAppletWindow
, wxHtmlWindow
);
50 // Define the wxAppletList implementation
51 #include "wx/listimpl.cpp"
52 WX_DEFINE_LIST(wxAppletList
);
54 /****************************************************************************
56 Constructor for the applet window class.
57 ****************************************************************************/
58 wxHtmlAppletWindow::wxHtmlAppletWindow(
65 : wxHtmlWindow(parent
,id
,pos
,size
,style
,name
)
67 // Ensure all cookie data is destroyed when window is killed
68 m_Cookies
.DeleteContents(true);
71 /****************************************************************************
73 Destructor for the applet window class.
74 ****************************************************************************/
75 wxHtmlAppletWindow::~wxHtmlAppletWindow()
79 /****************************************************************************
81 className - Name of the applet class to create an object for
82 size - Initial size of the applet to be created
85 Pointer to the wxApplet created, or NULL if unable to create the applet.
88 This function is used to create new wxApplet objects dynamically based on the
89 class name as a string. This allows instances of wxApplet classes to be
90 created dynamically based on string values embedded in the custom tags of an
92 ****************************************************************************/
93 wxApplet
*wxHtmlAppletWindow::CreateApplet(
94 const wxString
& className
,
97 // We presently only allow one applet per page of the same class!
98 if (m_AppletList
.Find(className
))
101 // Dynamically create the class instance at runtime
102 wxClassInfo
*info
= wxClassInfo::FindClass(className
.c_str());
105 wxObject
*obj
= info
->CreateObject();
108 wxApplet
*applet
= wxDynamicCast(obj
,wxApplet
);
111 if (!applet
->Create(this,size
)) {
115 m_AppletList
.Append(className
,applet
);
119 /****************************************************************************
121 appletName - Name of the applet class to find
124 Pointer to the wxApplet found, or NULL if not found.
127 Find an instance of an applet based on it's name
128 ****************************************************************************/
129 wxApplet
*wxHtmlAppletWindow::FindApplet(
130 const wxString
& appletName
)
132 wxAppletList::Node
*node
= m_AppletList
.Find(appletName
);
135 return node
->GetData();
138 /****************************************************************************
140 applet - Pointer to the applet object to remove from the list
143 True if the applet was found and removed, false if not. The applet itself
147 Remove an applet from the manager. Called during applet destruction
148 ****************************************************************************/
149 bool wxHtmlAppletWindow::RemoveApplet(
150 const wxApplet
*applet
)
152 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext()) {
153 if (node
->GetData() == applet
) {
154 m_AppletList
.DeleteNode(node
);
161 /****************************************************************************
163 URL - New URL for the page to load
166 True if page loaded successfully, false if not
169 Remove an applet from the manager. Called during applet destruction
170 ****************************************************************************/
171 bool wxHtmlAppletWindow::LoadPage(
172 const wxString
& hRef
)
174 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
175 (node
->GetData())->OnLinkClicked(hRef
);
176 return wxHtmlWindow::LoadPage(hRef
);
179 /****************************************************************************
181 URL - String URL that we are navigating to
184 Called when the user navigates to a new URL from the current page. We simply
185 call the LoadPage function above to load the new page and display it.
186 ****************************************************************************/
187 void wxHtmlAppletWindow::OnLinkClicked(
188 const wxHtmlLinkInfo
& link
)
190 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
191 (node
->GetData())->OnLinkClicked(link
);
192 wxHtmlWindow::LoadPage(link
.GetHref());
195 /****************************************************************************
197 Called when the user navigates forward within the HTML history stack.
198 We call all the applets in turn allowing them to handle the navigation
199 command prior to being destructed when the current page is destroyed.
200 ****************************************************************************/
201 bool wxHtmlAppletWindow::HistoryForward()
203 if (!HistoryCanForward())
205 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
206 (node
->GetData())->OnHistoryForward();
207 return wxHtmlWindow::HistoryForward();
210 /****************************************************************************
212 Called when the user navigates backwards within the HTML history stack.
213 We call all the applets in turn allowing them to handle the navigation
214 command prior to being destructed when the current page is destroyed.
215 ****************************************************************************/
216 bool wxHtmlAppletWindow::HistoryBack()
218 if (!HistoryCanBack())
220 for (wxAppletList::Node
*node
= m_AppletList
.GetFirst(); node
; node
= node
->GetNext())
221 (node
->GetData())->OnHistoryBack();
222 return wxHtmlWindow::HistoryBack();
225 /****************************************************************************
227 msg - wxEvent message to be sent to all wxApplets
230 This function is called by the wxApplet's when they need to send a message
231 to all other applets on the current page. This is the primary form of
232 communication between applets on the page if they need to inform each
233 other of internal information.
235 Note that the event handling terminates as soon as the first wxApplet
236 handles the event. If the event should be handled by all wxApplet's,
237 the event handlers for the applets should not reset the wxEvent::Skip()
238 value (ie: by default it is true).
239 ****************************************************************************/
240 void wxHtmlAppletWindow::SendMessage(
243 // Preset the skip flag
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())
254 /****************************************************************************
256 msg - wxEvent message to be sent to all wxApplets
259 True if new cookie was added, false if cookie with same name already exists.
262 This function is called by the wxApplet's when they need register a cookie
263 of data in the applet window's cookie table. Cookies are arbitrary data
264 objects that are references by unique name's by the wxApplet. These
265 values can be used to store and retrieve data that needs to remain
266 persisent across invocations of the wxApplet. Ie: The first time an
267 applet is created it would use the cookie to store data to maintain
268 it's present state so that if you navigated back to the same page
269 is would be able to re-load the prior state as though the applet
270 was never actually destructed.
272 Note: If a cookie with the same name already exists, this function returns
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
276 ****************************************************************************/
277 bool wxHtmlAppletWindow::RegisterCookie(
278 const wxString
& name
,
281 // Fail if the named cookie already exists!
282 if (m_Cookies
.Get(name
))
284 m_Cookies
.Put(name
,cookie
);
288 /****************************************************************************
290 msg - wxEvent message to be sent to all wxApplets
293 True if found and deleted, false if not found in table.
296 This function is called by the wxApplet's when they need de-register a
297 cookie of data in the applet window's cookie table. The data in the
298 cookie itself is also deleted before it is removed from the table.
299 ****************************************************************************/
300 bool wxHtmlAppletWindow::UnRegisterCookie(
301 const wxString
& name
)
303 wxObject
*data
= m_Cookies
.Delete(name
);
311 /****************************************************************************
313 msg - wxEvent message to be sent to all wxApplets
316 Pointer to the cookie data if found, NULL if not found.
319 This function is called by the wxApplet's when they need to find a cookie
320 of data given it's public name. If the cookie is not found, NULL is
322 ****************************************************************************/
323 wxObject
*wxHtmlAppletWindow::FindCookie(
324 const wxString
& name
)
326 return m_Cookies
.Get(name
);
329 #include "wx/html/m_templ.h"
331 /****************************************************************************
333 Implementation for the <embed> HTML tag handler. This handler takes care
334 of automatically constructing the wxApplet objects of the appropriate
335 class based on the <embed> tag information.
336 ****************************************************************************/
337 TAG_HANDLER_BEGIN(Embed
, "EMBED")
339 TAG_HANDLER_PROC(tag
)
342 wxHtmlAppletWindow
*appletWindow
;
345 int floatPercent
= 0;
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
) {
356 m_WParser
->OpenContainer()->InsertCell(new wxHtmlWidgetCell(applet
,floatPercent
));
359 else if (tag
.HasParam("TEXT")) {
360 // TODO: Somehow get the text returned from this class displayed on the page!
366 TAG_HANDLER_END(Embed
)
368 TAGS_MODULE_BEGIN(Embed
)
369 TAGS_MODULE_ADD(Embed
)
370 TAGS_MODULE_END(Embed
)