kjavaappletwidget.cpp Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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( KJavaAppletContext* context,
    00043                    QWidget* parent, const char* name )
    00044    : QXEmbed ( parent, name)
    00045 {
    00046     setProtocol(QXEmbed::XPLAIN);
    00047
    00048     m_applet = new KJavaApplet( this );
    00049     d        = new KJavaAppletWidgetPrivate;
    00050     m_kwm    = new KWinModule( this );
    00051
    00052     m_applet->setAppletContext( context );
    00053
    00054     d->tmplabel = new QLabel( this );
    00055     d->tmplabel->setText( KJavaAppletServer::getAppletLabel() );
    00056     d->tmplabel->setAlignment( Qt::AlignCenter | Qt::WordBreak );
    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( QWidget* parent, const char* name )
    00065    : QXEmbed ( parent, name)
    00066 {
    00067     setProtocol(QXEmbed::XPLAIN);
    00068
    00069     m_applet = new KJavaApplet( this );
    00070     d        = new KJavaAppletWidgetPrivate;
    00071     m_kwm    = new KWinModule( this );
    00072
    00073     d->tmplabel = new QLabel( this );
    00074     d->tmplabel->setText( KJavaAppletServer::getAppletLabel() );
    00075     d->tmplabel->setAlignment( Qt::AlignCenter | Qt::WordBreak );
    00076     d->tmplabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
    00077     d->tmplabel->show();
    00078
    00079     m_swallowTitle.sprintf( "KJAS Applet - Ticket number %u", appletCount++ );
    00080     m_applet->setWindowName( m_swallowTitle );
    00081 }
    00082
    00083 KJavaAppletWidget::~KJavaAppletWidget()
    00084 {
    00085     delete m_applet;
    00086     delete d;
    00087 }
    00088
    00089 void KJavaAppletWidget::showApplet()
    00090 {
    00091     connect( m_kwm, SIGNAL( windowAdded( WId ) ),
    00092                  this,  SLOT( setWindow( WId ) ) );
    00093
    00094     m_kwm->doNotManage( m_swallowTitle );
    00095
    00096     //Now we send applet info to the applet server
    00097     if ( !m_applet->isCreated() )
    00098         m_applet->create();
    00099 }
    00100
    00101 void KJavaAppletWidget::setWindow( WId w )
    00102 {
    00103     //make sure that this window has the right name, if so, embed it...
    00104     KWin::Info w_info = KWin::info( w );
    00105     if ( m_swallowTitle == w_info.name ||
    00106          m_swallowTitle == w_info.visibleName )
    00107     {
    00108         kdDebug(6100) << "swallowing our window: " << m_swallowTitle
    00109                       << ", window id = " << w << endl;
    00110         delete d->tmplabel;
    00111         d->tmplabel = 0;
    00112
    00113         // disconnect from KWM events
    00114         disconnect( m_kwm, SIGNAL( windowAdded( WId ) ),
    00115                     this,  SLOT( setWindow( WId ) ) );
    00116
    00117
    00118         embed( w );
    00119         setFocus();
    00120     }
    00121 }
    00122
    00123 QSize KJavaAppletWidget::sizeHint() const
    00124 {
    00125     kdDebug(6100) << "KJavaAppletWidget::sizeHint()" << endl;
    00126     QSize rval = QXEmbed::sizeHint();
    00127
    00128     if( rval.width() == 0 || rval.height() == 0 )
    00129     {
    00130         if( width() != 0 && height() != 0 )
    00131         {
    00132             rval = QSize( width(), height() );
    00133         }
    00134     }
    00135
    00136     kdDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")" << endl;
    00137
    00138     return rval;
    00139 }
    00140
    00141 void KJavaAppletWidget::resize( int w, int h )
    00142 {
    00143     if( d->tmplabel )
    00144     {
    00145         d->tmplabel->resize( w, h );
    00146         m_applet->setSize( QSize( w, h ) );
    00147     }
    00148
    00149     QXEmbed::resize( w, h );
    00150 }
    00151
    00152 #include "kjavaappletwidget.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:11 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001