KHTML
kjavaappletwidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kjavaappletwidget.h"
00023 #include "kjavaappletserver.h"
00024
00025 #include <kwin.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028
00029 #include <qlabel.h>
00030
00031
00032
00033 class KJavaAppletWidgetPrivate
00034 {
00035 friend class KJavaAppletWidget;
00036 private:
00037 QLabel* tmplabel;
00038 };
00039
00040 int KJavaAppletWidget::appletCount = 0;
00041
00042 KJavaAppletWidget::KJavaAppletWidget( QWidget* parent, const char* name )
00043 : QXEmbed ( parent, name)
00044 {
00045 setProtocol(QXEmbed::XPLAIN);
00046
00047 m_applet = new KJavaApplet( this );
00048 d = new KJavaAppletWidgetPrivate;
00049 m_kwm = new KWinModule( this );
00050
00051 d->tmplabel = new QLabel( this );
00052 d->tmplabel->setText( KJavaAppletServer::getAppletLabel() );
00053 d->tmplabel->setAlignment( Qt::AlignCenter | Qt::WordBreak );
00054 d->tmplabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00055 d->tmplabel->show();
00056
00057 m_swallowTitle.sprintf( "KJAS Applet - Ticket number %u", appletCount++ );
00058 m_applet->setWindowName( m_swallowTitle );
00059 }
00060
00061 KJavaAppletWidget::~KJavaAppletWidget()
00062 {
00063 delete m_applet;
00064 delete d;
00065 }
00066
00067 void KJavaAppletWidget::showApplet()
00068 {
00069 connect( m_kwm, SIGNAL( windowAdded( WId ) ),
00070 this, SLOT( setWindow( WId ) ) );
00071
00072 m_kwm->doNotManage( m_swallowTitle );
00073
00074
00075 if ( !m_applet->isCreated() )
00076 m_applet->create();
00077 }
00078
00079 void KJavaAppletWidget::setWindow( WId w )
00080 {
00081
00082 KWin::WindowInfo w_info = KWin::windowInfo( w );
00083 if ( m_swallowTitle == w_info.name() ||
00084 m_swallowTitle == w_info.visibleName() )
00085 {
00086 kdDebug(6100) << "swallowing our window: " << m_swallowTitle
00087 << ", window id = " << w << endl;
00088 delete d->tmplabel;
00089 d->tmplabel = 0;
00090
00091
00092 disconnect( m_kwm, SIGNAL( windowAdded( WId ) ),
00093 this, SLOT( setWindow( WId ) ) );
00094
00095
00096 embed( w );
00097 setFocus();
00098 }
00099 }
00100
00101 QSize KJavaAppletWidget::sizeHint() const
00102 {
00103 kdDebug(6100) << "KJavaAppletWidget::sizeHint()" << endl;
00104 QSize rval = QXEmbed::sizeHint();
00105
00106 if( rval.width() == 0 || rval.height() == 0 )
00107 {
00108 if( width() != 0 && height() != 0 )
00109 {
00110 rval = QSize( width(), height() );
00111 }
00112 }
00113
00114 kdDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")" << endl;
00115
00116 return rval;
00117 }
00118
00119 void KJavaAppletWidget::resize( int w, int h )
00120 {
00121 if( d->tmplabel )
00122 {
00123 d->tmplabel->resize( w, h );
00124 m_applet->setSize( QSize( w, h ) );
00125 }
00126
00127 QXEmbed::resize( w, h );
00128 }
00129
00130 void KJavaAppletWidget::showEvent (QShowEvent * e) {
00131 QXEmbed::showEvent(e);
00132 if (!applet()->isCreated() && !applet()->appletClass().isEmpty()) {
00133
00134 if (applet()->size().width() <= 0)
00135 applet()->setSize (sizeHint());
00136 showApplet();
00137 }
00138 }
00139
00140 #include "kjavaappletwidget.moc"