don't discard iframe children.
[kdelibs.git] / khtml / java / kjavaapplet.cpp
blob6a5498bf083529e4e441a92af24ee7449442b891
1 /* This file is part of the KDE project
3 * Copyright (C) 2000 Richard Moore <rich@kde.org>
4 * 2000 Wynn Wilkes <wynnw@caldera.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include "kjavaappletwidget.h"
23 #include "kjavaappletcontext.h"
25 #include <klocale.h>
26 #include <kdebug.h>
27 #include <kparts/browserextension.h>
31 class KJavaAppletPrivate
33 public:
34 bool reallyExists;
35 bool failed;
36 QString className;
37 QString appName;
38 QString baseURL;
39 QString codeBase;
40 QString archives;
41 QSize size;
42 QString windowName;
43 KJavaApplet::AppletState state;
45 KJavaAppletWidget* UIwidget;
49 KJavaApplet::KJavaApplet( KJavaAppletWidget* _parent,
50 KJavaAppletContext* _context )
51 : d(new KJavaAppletPrivate), params()
54 d->UIwidget = _parent;
55 d->state = UNKNOWN;
56 d->failed = false;
58 if( _context )
59 setAppletContext( _context );
61 d->reallyExists = false;
64 KJavaApplet::~KJavaApplet()
66 if ( d->reallyExists )
67 context->destroy( this );
69 delete d;
72 bool KJavaApplet::isCreated()
74 return d->reallyExists;
77 void KJavaApplet::setAppletContext( KJavaAppletContext* _context )
79 context = _context;
80 context->registerApplet( this );
83 void KJavaApplet::setAppletClass( const QString& _className )
85 d->className = _className;
88 QString& KJavaApplet::appletClass()
90 return d->className;
93 QString& KJavaApplet::parameter( const QString& name )
95 return params[ name ];
98 void KJavaApplet::setParameter( const QString& name, const QString& value )
100 params.insert( name, value );
103 QMap<QString,QString>& KJavaApplet::getParams()
105 return params;
108 void KJavaApplet::setBaseURL( const QString& baseURL )
110 d->baseURL = baseURL;
113 QString& KJavaApplet::baseURL()
115 return d->baseURL;
118 void KJavaApplet::setCodeBase( const QString& codeBase )
120 d->codeBase = codeBase;
123 QString& KJavaApplet::codeBase()
125 return d->codeBase;
128 void KJavaApplet::setSize( QSize size )
130 d->size = size;
133 QSize KJavaApplet::size()
135 return d->size;
138 void KJavaApplet::setArchives( const QString& _archives )
140 d->archives = _archives;
143 QString& KJavaApplet::archives()
145 return d->archives;
148 void KJavaApplet::resizeAppletWidget( int width, int height )
150 kDebug(6100) << "KJavaApplet, id = " << id << ", ::resizeAppletWidget to " << width << ", " << height;
152 QStringList sl;
153 sl.push_back( QString::number( 0 ) ); // applet itself has id 0
154 sl.push_back( QString( "eval" ) ); // evaluate next script
155 sl.push_back( QString::number( KParts::LiveConnectExtension::TypeString ) );
156 sl.push_back( QString( "this.setAttribute('WIDTH',%1);this.setAttribute('HEIGHT',%2)" ).arg( width ).arg( height ) );
157 jsData( sl );
160 void KJavaApplet::setAppletName( const QString& name )
162 d->appName = name;
165 void KJavaApplet::setWindowName( const QString& title )
167 d->windowName = title;
170 QString& KJavaApplet::getWindowName()
172 return d->windowName;
175 QString& KJavaApplet::appletName()
177 return d->appName;
180 void KJavaApplet::create( )
182 if ( !context->create( this ) )
183 setFailed();
184 d->reallyExists = true;
187 void KJavaApplet::init()
189 context->init( this );
192 void KJavaApplet::start()
194 context->start( this );
197 void KJavaApplet::stop()
199 context->stop( this );
202 int KJavaApplet::appletId()
204 return id;
207 void KJavaApplet::setAppletId( int _id )
209 id = _id;
212 void KJavaApplet::stateChange( const int newStateInt ) {
213 AppletState newState = (AppletState)newStateInt;
214 bool ok = false;
215 if (d->failed) {
216 return;
218 switch ( newState ) {
219 case CLASS_LOADED:
220 ok = (d->state == UNKNOWN);
221 break;
222 case INSTANCIATED:
223 if (ok) {
224 showStatus(i18n("Initializing Applet \"%1\"...", appletName()));
226 ok = (d->state == CLASS_LOADED);
227 break;
228 case INITIALIZED:
229 ok = (d->state == INSTANCIATED);
230 if (ok) {
231 showStatus(i18n("Starting Applet \"%1\"...", appletName()));
232 start();
234 break;
235 case STARTED:
236 ok = (d->state == INITIALIZED || d->state == STOPPED);
237 if (ok) {
238 showStatus(i18n("Applet \"%1\" started", appletName()));
240 break;
241 case STOPPED:
242 ok = (d->state == INITIALIZED || d->state == STARTED);
243 if (ok) {
244 showStatus(i18n("Applet \"%1\" stopped", appletName()));
246 break;
247 case DESTROYED:
248 ok = true;
249 break;
250 default:
251 break;
253 if (ok) {
254 d->state = newState;
255 } else {
256 kError(6100) << "KJavaApplet::stateChange : don't want to switch from state "
257 << d->state << " to " << newState << endl;
261 void KJavaApplet::showStatus(const QString &msg) {
262 QStringList args;
263 args << msg;
264 context->processCmd("showstatus", args);
267 void KJavaApplet::setFailed() {
268 d->failed = true;
271 bool KJavaApplet::isAlive() const {
272 return (
273 !d->failed
274 && d->state >= INSTANCIATED
275 && d->state < STOPPED
279 KJavaApplet::AppletState KJavaApplet::state() const {
280 return d->state;
283 bool KJavaApplet::failed() const {
284 return d->failed;
287 #include "kjavaapplet.moc"