• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.5 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  //Now we send applet info to the applet server
77  if ( !m_applet->isCreated() )
78  m_applet->create();
79 #endif
80 }
81 
82 void KJavaAppletWidget::setWindow( WId w )
83 {
84 #ifdef Q_WS_X11
85  //make sure that this window has the right name, if so, embed it...
86  KWindowInfo w_info = KWindowSystem::windowInfo( w, NET::WMVisibleName | NET::WMName );
87  if ( m_swallowTitle == w_info.name() ||
88  m_swallowTitle == w_info.visibleName() )
89  {
90  KWindowSystem::setState(w, NET::Hidden | NET::SkipTaskbar | NET::SkipPager);
91  kDebug(6100) << "swallowing our window: " << m_swallowTitle
92  << ", window id = " << w << endl;
93  delete d->tmplabel;
94  d->tmplabel = 0;
95 
96  // disconnect from KWM events
97  disconnect( KWindowSystem::self(), SIGNAL(windowAdded(WId)),
98  this, SLOT(setWindow(WId)) );
99 
100  embedClient( w );
101  setFocus();
102  }
103 #else
104  //TODO
105 #endif
106 }
107 
108 QSize KJavaAppletWidget::sizeHint() const
109 {
110  kDebug(6100) << "KJavaAppletWidget::sizeHint()";
111  QSize rval = QX11EmbedContainer::sizeHint();
112 
113  if( rval.width() == 0 || rval.height() == 0 )
114  {
115  if( width() != 0 && height() != 0 )
116  {
117  rval = QSize( width(), height() );
118  }
119  }
120 
121  kDebug(6100) << "returning: (" << rval.width() << ", " << rval.height() << ")";
122 
123  return rval;
124 }
125 
126 void KJavaAppletWidget::resize( int w, int h )
127 {
128  if( d->tmplabel )
129  {
130  d->tmplabel->resize( w, h );
131  m_applet->setSize( QSize( w, h ) );
132  }
133 
134  QX11EmbedContainer::resize( w, h );
135 }
136 
137 void KJavaAppletWidget::showEvent (QShowEvent * e) {
138  QX11EmbedContainer::showEvent(e);
139  if (!applet()->isCreated() && !applet()->appletClass().isEmpty()) {
140  // delayed showApplet
141  if (applet()->size().width() <= 0)
142  applet()->setSize (sizeHint());
143  showApplet();
144  }
145 }
146 
147 #include "kjavaappletwidget.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Sep 23 2014 10:01:09 by doxygen 1.8.3.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.11.5 API Reference

Skip menu "kdelibs-4.11.5 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