1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of a Qt Solutions component.
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21
** the names of its contributors may be used to endorse or promote
22
** products derived from this software without specific prior written
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37
****************************************************************************/
40
#include <QtGui/QX11EmbedWidget>
42
#include "qtbrowserplugin.h"
43
#include "qtbrowserplugin_p.h"
49
static bool ownsqapp = false;
50
static QMap<QtNPInstance*, QX11EmbedWidget*> clients;
52
extern "C" bool qtns_event(QtNPInstance *, NPEvent *)
57
extern "C" void qtns_initialize(QtNPInstance* This)
62
static char **argv = {0};
64
// Workaround to avoid re-initilaziation of glib
65
char* envvar = qstrdup("QT_NO_THREADED_GLIB=1");
66
// Unavoidable memory leak; the variable must survive plugin unloading
69
(void)new QApplication(argc, argv);
71
if (!clients.contains(This)) {
72
QX11EmbedWidget* client = new QX11EmbedWidget;
73
QHBoxLayout* layout = new QHBoxLayout(client);
75
clients.insert(This, client);
79
extern "C" void qtns_destroy(QtNPInstance* This)
81
QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
82
if (it == clients.end())
88
extern "C" void qtns_shutdown()
90
if (clients.count() > 0) {
91
QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.begin();
92
while (it != clients.end()) {
102
// check if qApp still runs widgets (in other DLLs)
103
QWidgetList widgets = qApp->allWidgets();
104
int count = widgets.count();
105
for (int w = 0; w < widgets.count(); ++w) {
106
// ignore all Qt generated widgets
107
QWidget *widget = widgets.at(w);
108
if (widget->windowFlags() & Qt::Desktop)
111
if (count) // qApp still used
118
extern "C" void qtns_embed(QtNPInstance *This)
120
Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
122
QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
123
if (it == clients.end())
125
QX11EmbedWidget* client = it.value();
126
This->qt.widget->setParent(client);
127
client->layout()->addWidget(This->qt.widget);
128
client->embedInto(This->window);
132
extern "C" void qtns_setGeometry(QtNPInstance *This, const QRect &rect, const QRect &)
134
Q_ASSERT(qobject_cast<QWidget*>(This->qt.object));
136
QMap<QtNPInstance*, QX11EmbedWidget*>::iterator it = clients.find(This);
137
if (it == clients.end())
139
QX11EmbedWidget* client = it.value();
140
client->setGeometry(QRect(0, 0, rect.width(), rect.height()));
144
extern "C" void qtns_print(QtNPInstance * This, NPPrint *printInfo)
146
NPWindow* printWindow = &(printInfo->print.embedPrint.window);
147
void* platformPrint = printInfo->print.embedPrint.platformPrint;