• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • java
kjavaappletwidget.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000 Richard Moore <rich@kde.org>
4  * 2000 Wynn Wilkes <wynnw@caldera.com>
5  *
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.
10  *
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.
15  *
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.
20  */
21 
22 #include "kjavaappletwidget.h"
23 #include "kjavaappletserver.h"
24 
25 #include <kwindowsystem.h>
26 #include <kdebug.h>
27 #include <klocale.h>
28 
29 #include <QtGui/QLabel>
30 
31 #ifndef Q_WS_X11
32 #define QXEmbed QWidget
33 #endif
34 
35 // For future expansion
36 class KJavaAppletWidgetPrivate
37 {
38 friend class KJavaAppletWidget;
39 private:
40  QLabel* tmplabel;
41 };
42 
43 int KJavaAppletWidget::appletCount = 0;
44 
45 KJavaAppletWidget::KJavaAppletWidget( QWidget* parent )
46  : QX11EmbedContainer ( parent ),
47  d(new KJavaAppletWidgetPrivate)
48 {
49  //setProtocol(QXEmbed::XPLAIN);
50 
51  m_applet = new KJavaApplet( this );
52 
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 );
58  d->tmplabel->show();
59 
60  m_swallowTitle.sprintf( "KJAS Applet - Ticket number %u", appletCount++ );
61  m_applet->setWindowName( m_swallowTitle );
62 }
63 
64 KJavaAppletWidget::~KJavaAppletWidget()
65 {
66  delete m_applet;
67  delete d;
68 }
69 
70 void KJavaAppletWidget::showApplet()
71 {
72 #ifdef Q_WS_X11
73  connect( KWindowSystem::self(), SIGNAL(windowAdded(WId)),
74  this, SLOT(setWindow(WId)) );
75 
76  KWindowSystem::doNotManage( m_swallowTitle );
77 
78  //Now we send applet info to the applet server
79  if ( !m_applet->isCreated() )
80  m_applet->create();
81 #endif
82 }
83 
84 void KJavaAppletWidget::setWindow( WId w )
85 {
86 #ifdef Q_WS_X11
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() )
91  {
92  kDebug(6100) << "swallowing our window: " << m_swallowTitle
93  << ", window id = " << w << endl;
94  delete d->tmplabel;
95  d->tmplabel = 0;
96 
97  // disconnect from KWM events
98  disconnect( KWindowSystem::self(), SIGNAL(windowAdded(WId)),
99  this, SLOT(setWindow(WId)) );
100 
101  embedClient( w );
102  setFocus();
103  }
104 #else
105  //TODO
106 #endif
107 }
108 
109 QSize KJavaAppletWidget::sizeHint() const
110 {
111  kDebug(6100) << "KJavaAppletWidget::sizeHint()";
112  QSize rval = QX11EmbedContainer::sizeHint();
113 
114  if( rval.width() == 0 || rval.height() == 0 )
115  {
116  if( width() != 0 && height() != 0 )
117  {
118  rval = QSize( width(), height() );
119  }
120  }
121 
122  kDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")";
123 
124  return rval;
125 }
126 
127 void KJavaAppletWidget::resize( int w, int h )
128 {
129  if( d->tmplabel )
130  {
131  d->tmplabel->resize( w, h );
132  m_applet->setSize( QSize( w, h ) );
133  }
134 
135  QX11EmbedContainer::resize( w, h );
136 }
137 
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());
144  showApplet();
145  }
146 }
147 
148 #include "kjavaappletwidget.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sun Apr 28 2013 14:30:09 by doxygen 1.8.1.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal