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>
29 #include <QtGui/QLabel>
32 #define QXEmbed QWidget
35 // For future expansion
36 class KJavaAppletWidgetPrivate
38 friend class KJavaAppletWidget
;
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
);
60 m_swallowTitle
.sprintf( "KJAS Applet - Ticket number %u", appletCount
++ );
61 m_applet
->setWindowName( m_swallowTitle
);
64 KJavaAppletWidget::~KJavaAppletWidget()
70 void KJavaAppletWidget::showApplet()
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() )
84 void KJavaAppletWidget::setWindow( WId w
)
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
;
97 // disconnect from KWM events
98 disconnect( KWindowSystem::self(), SIGNAL( windowAdded( WId
) ),
99 this, SLOT( setWindow( WId
) ) );
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() << ")";
127 void KJavaAppletWidget::resize( int w
, int h
)
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());
148 #include "kjavaappletwidget.moc"