KHTML
kjavaappletwidget.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2000 Richard Moore <rich@kde.org> 00004 * 2000 Wynn Wilkes <wynnw@caldera.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "kjavaappletwidget.h" 00023 #include "kjavaappletserver.h" 00024 00025 #include <kwindowsystem.h> 00026 #include <kdebug.h> 00027 #include <klocale.h> 00028 00029 #include <QtGui/QLabel> 00030 00031 #ifndef Q_WS_X11 00032 #define QXEmbed QWidget 00033 #endif 00034 00035 // For future expansion 00036 class KJavaAppletWidgetPrivate 00037 { 00038 friend class KJavaAppletWidget; 00039 private: 00040 QLabel* tmplabel; 00041 }; 00042 00043 int KJavaAppletWidget::appletCount = 0; 00044 00045 KJavaAppletWidget::KJavaAppletWidget( QWidget* parent ) 00046 : QX11EmbedContainer ( parent ), 00047 d(new KJavaAppletWidgetPrivate) 00048 { 00049 //setProtocol(QXEmbed::XPLAIN); 00050 00051 m_applet = new KJavaApplet( this ); 00052 00053 d->tmplabel = new QLabel( this ); 00054 d->tmplabel->setText( KJavaAppletServer::getAppletLabel() ); 00055 d->tmplabel->setAlignment( Qt::AlignCenter ); 00056 d->tmplabel->setWordWrap( true ); 00057 d->tmplabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); 00058 d->tmplabel->show(); 00059 00060 m_swallowTitle.sprintf( "KJAS Applet - Ticket number %u", appletCount++ ); 00061 m_applet->setWindowName( m_swallowTitle ); 00062 } 00063 00064 KJavaAppletWidget::~KJavaAppletWidget() 00065 { 00066 delete m_applet; 00067 delete d; 00068 } 00069 00070 void KJavaAppletWidget::showApplet() 00071 { 00072 #ifdef Q_WS_X11 00073 connect( KWindowSystem::self(), SIGNAL( windowAdded( WId ) ), 00074 this, SLOT( setWindow( WId ) ) ); 00075 00076 KWindowSystem::doNotManage( m_swallowTitle ); 00077 00078 //Now we send applet info to the applet server 00079 if ( !m_applet->isCreated() ) 00080 m_applet->create(); 00081 #endif 00082 } 00083 00084 void KJavaAppletWidget::setWindow( WId w ) 00085 { 00086 #ifdef Q_WS_X11 00087 //make sure that this window has the right name, if so, embed it... 00088 KWindowInfo w_info = KWindowSystem::windowInfo( w, NET::WMVisibleName | NET::WMName ); 00089 if ( m_swallowTitle == w_info.name() || 00090 m_swallowTitle == w_info.visibleName() ) 00091 { 00092 kDebug(6100) << "swallowing our window: " << m_swallowTitle 00093 << ", window id = " << w << endl; 00094 delete d->tmplabel; 00095 d->tmplabel = 0; 00096 00097 // disconnect from KWM events 00098 disconnect( KWindowSystem::self(), SIGNAL( windowAdded( WId ) ), 00099 this, SLOT( setWindow( WId ) ) ); 00100 00101 embedClient( w ); 00102 setFocus(); 00103 } 00104 #else 00105 //TODO 00106 #endif 00107 } 00108 00109 QSize KJavaAppletWidget::sizeHint() const 00110 { 00111 kDebug(6100) << "KJavaAppletWidget::sizeHint()"; 00112 QSize rval = QX11EmbedContainer::sizeHint(); 00113 00114 if( rval.width() == 0 || rval.height() == 0 ) 00115 { 00116 if( width() != 0 && height() != 0 ) 00117 { 00118 rval = QSize( width(), height() ); 00119 } 00120 } 00121 00122 kDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")"; 00123 00124 return rval; 00125 } 00126 00127 void KJavaAppletWidget::resize( int w, int h ) 00128 { 00129 if( d->tmplabel ) 00130 { 00131 d->tmplabel->resize( w, h ); 00132 m_applet->setSize( QSize( w, h ) ); 00133 } 00134 00135 QX11EmbedContainer::resize( w, h ); 00136 } 00137 00138 void KJavaAppletWidget::showEvent (QShowEvent * e) { 00139 QX11EmbedContainer::showEvent(e); 00140 if (!applet()->isCreated() && !applet()->appletClass().isEmpty()) { 00141 // delayed showApplet 00142 if (applet()->size().width() <= 0) 00143 applet()->setSize (sizeHint()); 00144 showApplet(); 00145 } 00146 } 00147 00148 #include "kjavaappletwidget.moc"
KDE 4.6 API Reference