KHtml

kjavaappletwidget.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000 Richard Moore <[email protected]>
4  * 2000 Wynn Wilkes <[email protected]>
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 "kjavaappletviewer_debug.h"
27 #include <klocalizedstring.h>
28 
29 #include <QLabel>
30 
31 #include "../config-khtml.h"
32 
33 #if !HAVE_X11
34 #define QXEmbed QWidget
35 #endif
36 
37 // For future expansion
38 class KJavaAppletWidgetPrivate
39 {
40  friend class KJavaAppletWidget;
41 private:
42  QLabel *tmplabel;
43 };
44 
45 int KJavaAppletWidget::appletCount = 0;
46 
47 KJavaAppletWidget::KJavaAppletWidget(QWidget *parent)
48  : QX11EmbedContainer(parent),
49  d(new KJavaAppletWidgetPrivate)
50 {
51  //setProtocol(QXEmbed::XPLAIN);
52 
53  m_applet = new KJavaApplet(this);
54 
55  d->tmplabel = new QLabel(this);
56  d->tmplabel->setText(KJavaAppletServer::getAppletLabel());
57  d->tmplabel->setAlignment(Qt::AlignCenter);
58  d->tmplabel->setWordWrap(true);
59  d->tmplabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
60  d->tmplabel->show();
61 
62  m_swallowTitle = QStringLiteral("KJAS Applet - Ticket number %1").arg(appletCount++);
63  m_applet->setWindowName(m_swallowTitle);
64 }
65 
66 KJavaAppletWidget::~KJavaAppletWidget()
67 {
68  delete m_applet;
69  delete d;
70 }
71 
72 void KJavaAppletWidget::showApplet()
73 {
74 #if HAVE_X11
75  connect(KWindowSystem::self(), SIGNAL(windowAdded(WId)),
76  this, SLOT(setWindow(WId)));
77 
78  //Now we send applet info to the applet server
79  if (!m_applet->isCreated()) {
80  m_applet->create();
81  }
82 #endif
83 }
84 
85 void KJavaAppletWidget::setWindow(WId w)
86 {
87 #pragma message ("Revive QX11EmbedContainer")
88 #if 0
89  //make sure that this window has the right name, if so, embed it...
90  KWindowInfo w_info = KWindowSystem::windowInfo(w, NET::WMVisibleName | NET::WMName);
91  if (m_swallowTitle == w_info.name() ||
92  m_swallowTitle == w_info.visibleName()) {
94  // qCDebug(KJAVAAPPLETVIEWER_LOG) << "swallowing our window: " << m_swallowTitle
95  << ", window id = " << w;
96  delete d->tmplabel;
97  d->tmplabel = 0;
98 
99  // disconnect from KWM events
100  disconnect(KWindowSystem::self(), SIGNAL(windowAdded(WId)),
101  this, SLOT(setWindow(WId)));
102 
103  embedClient(w);
104  setFocus();
105  }
106 #else
107  //TODO
108 #endif
109 }
110 
111 QSize KJavaAppletWidget::sizeHint() const
112 {
113  // qCDebug(KJAVAAPPLETVIEWER_LOG) << "KJavaAppletWidget::sizeHint()";
114  QSize rval = QX11EmbedContainer::sizeHint();
115 
116  if (rval.width() == 0 || rval.height() == 0) {
117  if (width() != 0 && height() != 0) {
118  rval = QSize(width(), height());
119  }
120  }
121 
122  // qCDebug(KJAVAAPPLETVIEWER_LOG) << "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  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 {
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  }
145  showApplet();
146  }
147 }
148 
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWidget *widget)
SkipTaskbar
int width() const const
virtual QSize sizeHint() const const override
QString visibleName() const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
AlignCenter
int width() const const
QSize size() const const
static KWindowInfo windowInfo(WId win, NET::Properties properties, NET::Properties2 properties2=NET::Properties2())
void setFocus()
static void setState(WId win, NET::States state)
static KWindowSystem * self()
int height() const const
QString name() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:48:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.