fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / java / kjavaappletwidget.cpp
blob7d433d41a65094b1b8424e557f56fa0e93f6fcdd
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 "kjavaappletserver.h"
25 #include <kwindowsystem.h>
26 #include <kdebug.h>
27 #include <klocale.h>
29 #include <QtGui/QLabel>
31 #ifndef Q_WS_X11
32 #define QXEmbed QWidget
33 #endif
35 // For future expansion
36 class KJavaAppletWidgetPrivate
38 friend class KJavaAppletWidget;
39 private:
40 QLabel* tmplabel;
43 int KJavaAppletWidget::appletCount = 0;
45 KJavaAppletWidget::KJavaAppletWidget( QWidget* parent )
46 : QX11EmbedContainer ( parent ),
47 d(new KJavaAppletWidgetPrivate)
49 //setProtocol(QXEmbed::XPLAIN);
51 m_applet = new KJavaApplet( this );
53 d->tmplabel = new QLabel( this );
54 d->tmplabel->setText( KJavaAppletServer::getAppletLabel() );
55 d->tmplabel->setAlignment( Qt::AlignCenter );
56 d->tmplabel->setWordWrap( true );
57 d->tmplabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
58 d->tmplabel->show();
60 m_swallowTitle.sprintf( "KJAS Applet - Ticket number %u", appletCount++ );
61 m_applet->setWindowName( m_swallowTitle );
64 KJavaAppletWidget::~KJavaAppletWidget()
66 delete m_applet;
67 delete d;
70 void KJavaAppletWidget::showApplet()
72 #ifdef Q_WS_X11
73 connect( KWindowSystem::self(), SIGNAL( windowAdded( WId ) ),
74 this, SLOT( setWindow( WId ) ) );
76 KWindowSystem::doNotManage( m_swallowTitle );
78 //Now we send applet info to the applet server
79 if ( !m_applet->isCreated() )
80 m_applet->create();
81 #endif
84 void KJavaAppletWidget::setWindow( WId w )
86 #ifdef Q_WS_X11
87 //make sure that this window has the right name, if so, embed it...
88 KWindowInfo w_info = KWindowSystem::windowInfo( w, NET::WMVisibleName | NET::WMName );
89 if ( m_swallowTitle == w_info.name() ||
90 m_swallowTitle == w_info.visibleName() )
92 kDebug(6100) << "swallowing our window: " << m_swallowTitle
93 << ", window id = " << w << endl;
94 delete d->tmplabel;
95 d->tmplabel = 0;
97 // disconnect from KWM events
98 disconnect( KWindowSystem::self(), SIGNAL( windowAdded( WId ) ),
99 this, SLOT( setWindow( WId ) ) );
101 embedClient( w );
102 setFocus();
104 #else
105 //TODO
106 #endif
109 QSize KJavaAppletWidget::sizeHint() const
111 kDebug(6100) << "KJavaAppletWidget::sizeHint()";
112 QSize rval = QX11EmbedContainer::sizeHint();
114 if( rval.width() == 0 || rval.height() == 0 )
116 if( width() != 0 && height() != 0 )
118 rval = QSize( width(), height() );
122 kDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")";
124 return rval;
127 void KJavaAppletWidget::resize( int w, int h )
129 if( d->tmplabel )
131 d->tmplabel->resize( w, h );
132 m_applet->setSize( QSize( w, h ) );
135 QX11EmbedContainer::resize( w, h );
138 void KJavaAppletWidget::showEvent (QShowEvent * e) {
139 QX11EmbedContainer::showEvent(e);
140 if (!applet()->isCreated() && !applet()->appletClass().isEmpty()) {
141 // delayed showApplet
142 if (applet()->size().width() <= 0)
143 applet()->setSize (sizeHint());
144 showApplet();
148 #include "kjavaappletwidget.moc"