| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kjavaappletwidget.cpp

    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., 59 Temple Place - Suite 330,
    00019  * Boston, MA 02111-1307, USA.
    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 // For future expansion
    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     //Now we send applet info to the applet server
    00075     if ( !m_applet->isCreated() )
    00076         m_applet->create();
    00077 }
    00078
    00079 void KJavaAppletWidget::setWindow( WId w )
    00080 {
    00081     //make sure that this window has the right name, if so, embed it...
    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         // disconnect from KWM events
    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         // delayed showApplet
    00134         if (applet()->size().width() <= 0)
    00135             applet()->setSize (sizeHint());
    00136         showApplet();
    00137     }
    00138 }
    00139
    00140 #include "kjavaappletwidget.moc"

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:16 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003