diff options
Diffstat (limited to 'src')
135 files changed, 3 insertions, 53009 deletions
diff --git a/src/gui/dialogs/qprintdialog_qws.cpp b/src/gui/dialogs/qprintdialog_qws.cpp deleted file mode 100644 index 373b986f0b..0000000000 --- a/src/gui/dialogs/qprintdialog_qws.cpp +++ /dev/null @@ -1,567 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" - -#include <private/qabstractprintdialog_p.h> -#include "qprintdialog.h" - -#ifndef QT_NO_PRINTDIALOG - -#include "qapplication.h" -#include "qbuttongroup.h" -#include "qradiobutton.h" -#include "qcombobox.h" -#include "qspinbox.h" -#include "qprinter.h" -#include "qlineedit.h" -#include "qdir.h" -#include "qmessagebox.h" -#include "qinputdialog.h" -#include "qlayout.h" -#include "qlabel.h" - -#include "qlibrary.h" - -#ifndef QT_NO_NIS - -#ifndef BOOL_DEFINED -#define BOOL_DEFINED -#endif - -#include <rpcsvc/ypclnt.h> -#include <rpcsvc/yp_prot.h> - -#endif //QT_NO_NIS - -#include <ctype.h> -#include <stdlib.h> - -#include <qdebug.h> - -QT_BEGIN_NAMESPACE - -typedef void (*QPrintDialogCreator)(QPrintDialog *parent); -Q_GUI_EXPORT QPrintDialogCreator _qt_print_dialog_creator; - -class QPrintDialogPrivate : public QAbstractPrintDialogPrivate -{ - Q_DECLARE_PUBLIC(QPrintDialog) -public: - QButtonGroup *printerOrFile; - bool outputToFile; - QRadioButton *printToPrinterButton; - QRadioButton *printToFileButton; - QLineEdit *fileName; - - QButtonGroup *colorMode; - QRadioButton *printColor; - QRadioButton *printGray; - QPrinter::ColorMode colorMode2; - - QComboBox *orientationCombo, *sizeCombo; - QPrinter::PaperSize pageSize; - QPrinter::Orientation orientation; - - QSpinBox *copies; - int numCopies; - QPrinter::PaperSize indexToPaperSize[QPrinter::NPaperSize]; - - QComboBox *rangeCombo; - QSpinBox *firstPage; - QSpinBox *lastPage; - - QComboBox *pageOrderCombo; - QPrinter::PageOrder pageOrder2; - - QString faxNum; - - void init(); - - void _q_okClicked(); - void _q_printerOrFileSelected(QAbstractButton *b); - void _q_paperSizeSelected(int); - void _q_orientSelected(int); - void _q_pageOrderSelected(int); - void _q_colorModeSelected(QAbstractButton *); - void _q_setNumCopies(int); - void _q_printRangeSelected(int); - void _q_setFirstPage(int); - void _q_setLastPage(int); - void _q_fileNameEditChanged(const QString &text); - - void setupDestination(); - void setupPrinterSettings(); - void setupPaper(); - void setupOptions(); - - void setPrinter(QPrinter *p, bool pickUpSettings); -}; - -static void isc(QPrintDialogPrivate *d, const QString & text, - QPrinter::PaperSize ps); - -void QPrintDialogPrivate::_q_okClicked() -{ - Q_Q(QPrintDialog); -#ifndef QT_NO_MESSAGEBOX - if (outputToFile && fileName->isModified() && QFileInfo(fileName->text()).exists()) { - int confirm = QMessageBox::warning( - q, QPrintDialog::tr("File exists"), - QPrintDialog::tr("<qt>Do you want to overwrite it?</qt>"), - QMessageBox::Yes, QMessageBox::No); - if (confirm == QMessageBox::No) - return; - } -#endif // QT_NO_MESSAGEBOX - - lastPage->interpretText(); - firstPage->interpretText(); - copies->interpretText(); - if (outputToFile) { - printer->setOutputFileName(fileName->text()); - } - printer->setOrientation(orientation); - printer->setPaperSize(pageSize); - printer->setPageOrder(pageOrder2); - printer->setColorMode(colorMode2); - printer->setCopyCount(numCopies); - - switch ((rangeCombo->itemData(rangeCombo->currentIndex())).toInt()){ - case (int)QPrintDialog::AllPages: - q->setPrintRange(QPrintDialog::AllPages); - q->setFromTo(0, 0); - break; - case (int)QPrintDialog::Selection: - q->setPrintRange(QPrintDialog::Selection); - q->setFromTo(0, 0); - break; - case (int)QPrintDialog::PageRange: - q->setPrintRange(QPrintDialog::PageRange); - q->setFromTo(firstPage->value(), lastPage->value()); - break; - case (int)QPrintDialog::CurrentPage: - q->setPrintRange(QPrintDialog::CurrentPage); - q->setFromTo(0, 0); - break; - } - q->accept(); -} - -void QPrintDialogPrivate::_q_printerOrFileSelected(QAbstractButton *b) -{ - outputToFile = (b == printToFileButton); - if (outputToFile) { - _q_fileNameEditChanged(fileName->text()); - if (!fileName->isModified() && fileName->text().isEmpty()) { - QString file = "print.tiff"; - fileName->setText(file); - fileName->setCursorPosition(file.length()); - fileName->selectAll(); - fileName->setModified(true); // confirm overwrite when OK clicked - - } - fileName->setEnabled(true); - fileName->setFocus(); - } else { - fileName->setText(QString()); - if (fileName->isEnabled()) - fileName->setEnabled(false); - } -} - -void QPrintDialogPrivate::_q_paperSizeSelected(int id) -{ - if (id < QPrinter::NPaperSize) - pageSize = QPrinter::PaperSize(indexToPaperSize[id]); -} - -void QPrintDialogPrivate::_q_orientSelected(int id) -{ - orientation = (QPrinter::Orientation)id; -} - -void QPrintDialogPrivate::_q_pageOrderSelected(int id) -{ - pageOrder2 = (QPrinter::PageOrder)id; -} - -void QPrintDialogPrivate::_q_colorModeSelected(QAbstractButton *b) -{ - colorMode2 = (b == printColor) ? QPrinter::Color : QPrinter::GrayScale; -} - -void QPrintDialogPrivate::_q_setNumCopies(int copies) -{ - numCopies = copies; -} - -void QPrintDialogPrivate::_q_printRangeSelected(int id) -{ - bool enable = (rangeCombo->itemData(id).toInt() == (int)QPrintDialog::PageRange); - firstPage->setEnabled(enable); - lastPage->setEnabled(enable); -} - -void QPrintDialogPrivate::_q_setFirstPage(int fp) -{ - Q_Q(QPrintDialog); - if (printer) { - lastPage->setMinimum(fp); - lastPage->setMaximum(qMax(fp, q->maxPage())); - } -} - -void QPrintDialogPrivate::_q_setLastPage(int lp) -{ - Q_Q(QPrintDialog); - if (printer) { - firstPage->setMinimum(qMin(lp, q->minPage())); - firstPage->setMaximum(lp); - } -} - -void QPrintDialogPrivate::_q_fileNameEditChanged(const QString &text) -{ - Q_UNUSED(text); -} - -void QPrintDialogPrivate::setupDestination() -{ - Q_Q(QPrintDialog); - - // print destinations - printerOrFile = new QButtonGroup(q); - QObject::connect(printerOrFile, SIGNAL(buttonClicked(QAbstractButton*)), - q, SLOT(_q_printerOrFileSelected(QAbstractButton*))); - - printToPrinterButton = q->findChild<QRadioButton *>("printToPrinterButton"); - printerOrFile->addButton(printToPrinterButton); - printToFileButton = q->findChild<QRadioButton *>("printToFileButton"); - printerOrFile->addButton(printToFileButton); - - // file name - fileName = q->findChild<QLineEdit *>("fileName"); - QObject::connect(fileName, SIGNAL(textChanged(QString)), - q, SLOT(_q_fileNameEditChanged(QString))); - - outputToFile = false; -} - -void QPrintDialogPrivate::setupPrinterSettings() -{ - Q_Q(QPrintDialog); - - // color mode - colorMode = new QButtonGroup(q); - QObject::connect(colorMode, SIGNAL(buttonClicked(QAbstractButton*)), - q, SLOT(_q_colorModeSelected(QAbstractButton*))); - - printColor = q->findChild<QRadioButton *>("printColor"); - colorMode->addButton(printColor); - printGray = q->findChild<QRadioButton *>("printGray"); - colorMode->addButton(printGray); -} - -void isc(QPrintDialogPrivate *ptr, const QString & text, QPrinter::PaperSize ps) -{ - if (ptr && !text.isEmpty() && ps < QPrinter::NPaperSize) { - ptr->sizeCombo->addItem(text); - int index = ptr->sizeCombo->count()-1; - if (index >= 0 && index < QPrinter::NPaperSize) - ptr->indexToPaperSize[index] = ps; - } -} - -void QPrintDialogPrivate::setupPaper() -{ - Q_Q(QPrintDialog); - - pageSize = QPrinter::A4; - - // paper orientation - orientationCombo = q->findChild<QComboBox *>("orientationCombo"); - orientation = QPrinter::Portrait; - QObject::connect(orientationCombo, SIGNAL(activated(int)), - q, SLOT(_q_orientSelected(int))); - - // paper size - sizeCombo = q->findChild<QComboBox *>("sizeCombo"); - - int n; - for(n=0; n<QPrinter::NPaperSize; n++) - indexToPaperSize[n] = QPrinter::A4; - - isc(this, QPrintDialog::tr("A0 (841 x 1189 mm)"), QPrinter::A0); - isc(this, QPrintDialog::tr("A1 (594 x 841 mm)"), QPrinter::A1); - isc(this, QPrintDialog::tr("A2 (420 x 594 mm)"), QPrinter::A2); - isc(this, QPrintDialog::tr("A3 (297 x 420 mm)"), QPrinter::A3); - isc(this, QPrintDialog::tr("A4 (210 x 297 mm, 8.26 x 11.7 inches)"), QPrinter::A4); - isc(this, QPrintDialog::tr("A5 (148 x 210 mm)"), QPrinter::A5); - isc(this, QPrintDialog::tr("A6 (105 x 148 mm)"), QPrinter::A6); - isc(this, QPrintDialog::tr("A7 (74 x 105 mm)"), QPrinter::A7); - isc(this, QPrintDialog::tr("A8 (52 x 74 mm)"), QPrinter::A8); - isc(this, QPrintDialog::tr("A9 (37 x 52 mm)"), QPrinter::A9); - isc(this, QPrintDialog::tr("B0 (1000 x 1414 mm)"), QPrinter::B0); - isc(this, QPrintDialog::tr("B1 (707 x 1000 mm)"), QPrinter::B1); - isc(this, QPrintDialog::tr("B2 (500 x 707 mm)"), QPrinter::B2); - isc(this, QPrintDialog::tr("B3 (353 x 500 mm)"), QPrinter::B3); - isc(this, QPrintDialog::tr("B4 (250 x 353 mm)"), QPrinter::B4); - isc(this, QPrintDialog::tr("B5 (176 x 250 mm, 6.93 x 9.84 inches)"), QPrinter::B5); - isc(this, QPrintDialog::tr("B6 (125 x 176 mm)"), QPrinter::B6); - isc(this, QPrintDialog::tr("B7 (88 x 125 mm)"), QPrinter::B7); - isc(this, QPrintDialog::tr("B8 (62 x 88 mm)"), QPrinter::B8); - isc(this, QPrintDialog::tr("B9 (44 x 62 mm)"), QPrinter::B9); - isc(this, QPrintDialog::tr("B10 (31 x 44 mm)"), QPrinter::B10); - isc(this, QPrintDialog::tr("C5E (163 x 229 mm)"), QPrinter::C5E); - isc(this, QPrintDialog::tr("DLE (110 x 220 mm)"), QPrinter::DLE); - isc(this, QPrintDialog::tr("Executive (7.5 x 10 inches, 191 x 254 mm)"), QPrinter::Executive); - isc(this, QPrintDialog::tr("Folio (210 x 330 mm)"), QPrinter::Folio); - isc(this, QPrintDialog::tr("Ledger (432 x 279 mm)"), QPrinter::Ledger); - isc(this, QPrintDialog::tr("Legal (8.5 x 14 inches, 216 x 356 mm)"), QPrinter::Legal); - isc(this, QPrintDialog::tr("Letter (8.5 x 11 inches, 216 x 279 mm)"), QPrinter::Letter); - isc(this, QPrintDialog::tr("Tabloid (279 x 432 mm)"), QPrinter::Tabloid); - isc(this, QPrintDialog::tr("US Common #10 Envelope (105 x 241 mm)"), QPrinter::Comm10E); - - QObject::connect(sizeCombo, SIGNAL(activated(int)), - q, SLOT(_q_paperSizeSelected(int))); -} - -void QPrintDialogPrivate::setupOptions() -{ - Q_Q(QPrintDialog); - - // no. of copies - copies = q->findChild<QSpinBox *>("copies"); - QObject::connect(copies, SIGNAL(valueChanged(int)), - q, SLOT(_q_setNumCopies(int))); - - // print range - rangeCombo = q->findChild<QComboBox *>("rangeCombo"); - rangeCombo->addItem(QPrintDialog::tr("Print all"), QPrintDialog::AllPages); - rangeCombo->addItem(QPrintDialog::tr("Print selection"), QPrintDialog::Selection); - rangeCombo->addItem(QPrintDialog::tr("Print range"), QPrintDialog::PageRange); - rangeCombo->addItem(QPrintDialog::tr("Print current page"), QPrintDialog::CurrentPage); - QObject::connect(rangeCombo, SIGNAL(activated(int)), - q, SLOT(_q_printRangeSelected(int))); - - // page range - firstPage = q->findChild<QSpinBox *>("firstPage"); - firstPage->setRange(1, 9999); - firstPage->setValue(1); - QObject::connect(firstPage, SIGNAL(valueChanged(int)), - q, SLOT(_q_setFirstPage(int))); - - lastPage = q->findChild<QSpinBox *>("lastPage"); - lastPage->setRange(1, 9999); - lastPage->setValue(1); - QObject::connect(lastPage, SIGNAL(valueChanged(int)), - q, SLOT(_q_setLastPage(int))); - - // print order - pageOrderCombo = q->findChild<QComboBox *>("pageOrderCombo"); - QObject::connect(pageOrderCombo, SIGNAL(activated(int)), - q, SLOT(_q_pageOrderSelected(int))); -} - -bool QPrintDialog::eventFilter(QObject *o, QEvent *e) -{ - Q_UNUSED(o); - - Q_D(QPrintDialog); - switch (e->type()){ - case QEvent::KeyPress: - switch (static_cast<QKeyEvent*>(e)->key()) { - case Qt::Key_Back: - d->_q_okClicked(); - return true; - } - break; - default: - break; - } - return false; -} - -QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) - : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent) -{ - d_func()->init(); -} - -QPrintDialog::QPrintDialog(QWidget *parent) - : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent) -{ - d_func()->init(); -} - -QPrintDialog::~QPrintDialog() -{ -} - -void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) -{ - Q_Q(QPrintDialog); - printer = p; - - if (p && pickUpSettings) { - // top to bottom in the old dialog. - // printer or file - outputToFile = !p->outputFileName().isEmpty() && q->isOptionEnabled(QPrintDialog::PrintToFile); - if (outputToFile) - printToFileButton->setChecked(true); - else - printToPrinterButton->setChecked(true); - fileName->setEnabled(outputToFile); - - // file name - if (q->isOptionEnabled(QPrintDialog::PrintToFile)) { - fileName->setText(p->outputFileName()); - fileName->setModified(!fileName->text().isEmpty()); - } else { - printToFileButton->setEnabled(false); - } - - // orientation - orientationCombo->setCurrentIndex((int)p->orientation()); - _q_orientSelected(p->orientation()); - - // page size - int n = 0; - while (n < QPrinter::NPaperSize && - indexToPaperSize[n] != p->pageSize()) - n++; - sizeCombo->setCurrentIndex(n); - _q_paperSizeSelected(n); - - // page order - pageOrder2 = p->pageOrder(); - pageOrderCombo->setCurrentIndex((int)pageOrder2); - - // color mode - colorMode2 = p->colorMode(); - if (colorMode2 == QPrinter::Color) - printColor->setChecked(true); - else - printGray->setChecked(true); - - // number of copies - copies->setValue(p->copyCount()); - _q_setNumCopies(p->copyCount()); - } - - if (p) { - if (!q->isOptionEnabled(QPrintDialog::PrintSelection) - && rangeCombo->findData(QPrintDialog::Selection) > 0) - rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::Selection)); - if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) - && rangeCombo->findData(QPrintDialog::PageRange) > 0) - rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::PageRange)); - if (!q->isOptionEnabled(QPrintDialog::PrintCurrentPage) - && rangeCombo->findData(QPrintDialog::CurrentPage) > 0) - rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::CurrentPage)); - - switch (q->printRange()) { - case QPrintDialog::AllPages: - rangeCombo->setCurrentIndex((int)(QPrintDialog::AllPages)); - break; - case QPrintDialog::Selection: - rangeCombo->setCurrentIndex((int)(QPrintDialog::Selection)); - break; - case QPrintDialog::PageRange: - rangeCombo->setCurrentIndex((int)(QPrintDialog::PageRange)); - break; - case QPrintDialog::CurrentPage: - rangeCombo->setCurrentIndex((int)(QPrintDialog::CurrentPage)); - break; - } - } - - if (p && q->maxPage()) { - int from = q->minPage(); - int to = q->maxPage(); - if (q->printRange() == QPrintDialog::PageRange) { - from = q->fromPage(); - to = q->toPage(); - } - firstPage->setRange(q->minPage(), to); - lastPage->setRange(from, q->maxPage()); - firstPage->setValue(from); - lastPage->setValue(to); - } -} - -int QPrintDialog::exec() -{ - Q_D(QPrintDialog); - d->setPrinter(d->printer, true); - return QDialog::exec(); -} - -void QPrintDialogPrivate::init() -{ - Q_Q(QPrintDialog); - numCopies = 1; - - if (_qt_print_dialog_creator) - (*_qt_print_dialog_creator)(q); - - setupDestination(); - setupPrinterSettings(); - setupPaper(); - setupOptions(); - - setPrinter(printer, true); - - q->installEventFilter(q); -} - -void QPrintDialog::setVisible(bool visible) -{ - QAbstractPrintDialog::setVisible(visible); -} - -QT_END_NAMESPACE - -#include "moc_qprintdialog.cpp" -#include "qrc_qprintdialog.cpp" - -#endif // QT_NO_PRINTDIALOG diff --git a/src/gui/egl/qegl_qws.cpp b/src/gui/egl/qegl_qws.cpp deleted file mode 100644 index 181a9f2c63..0000000000 --- a/src/gui/egl/qegl_qws.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qpaintdevice.h> -#include <QtGui/qpixmap.h> -#include <QtGui/qwidget.h> - -#include "qegl_p.h" -#include "qeglcontext_p.h" - -#if !defined(QT_NO_EGL) - -#include <qscreen_qws.h> -#include <qscreenproxy_qws.h> -#include <qapplication.h> -#include <qdesktopwidget.h> - -QT_BEGIN_NAMESPACE - -static QScreen *screenForDevice(QPaintDevice *device) -{ - QScreen *screen = qt_screen; - if (!screen) - return 0; - if (screen->classId() == QScreen::MultiClass) { - int screenNumber; - if (device && device->devType() == QInternal::Widget) - screenNumber = qApp->desktop()->screenNumber(static_cast<QWidget *>(device)); - else - screenNumber = 0; - screen = screen->subScreens()[screenNumber]; - } - while (screen->classId() == QScreen::ProxyClass || - screen->classId() == QScreen::TransformedClass) { - screen = static_cast<QProxyScreen *>(screen)->screen(); - } - return screen; -} - -// Set pixel format and other properties based on a paint device. -void QEglProperties::setPaintDeviceFormat(QPaintDevice *dev) -{ - if (!dev) - return; - - // Find the QGLScreen for this paint device. - QScreen *screen = screenForDevice(dev); - if (!screen) - return; - int devType = dev->devType(); - if (devType == QInternal::Image) - setPixelFormat(static_cast<QImage *>(dev)->format()); - else - setPixelFormat(screen->pixelFormat()); -} - -EGLNativeDisplayType QEgl::nativeDisplay() -{ - return EGLNativeDisplayType(EGL_DEFAULT_DISPLAY); -} - -EGLNativeWindowType QEgl::nativeWindow(QWidget* widget) -{ - return (EGLNativeWindowType)(widget->winId()); // Might work -} - -EGLNativePixmapType QEgl::nativePixmap(QPixmap*) -{ - qWarning("QEgl: EGL pixmap surfaces not supported on QWS"); - return (EGLNativePixmapType)0; -} - - -QT_END_NAMESPACE - -#endif // !QT_NO_EGL diff --git a/src/gui/embedded/qcopchannel_qws.cpp b/src/gui/embedded/qcopchannel_qws.cpp deleted file mode 100644 index 703debc69c..0000000000 --- a/src/gui/embedded/qcopchannel_qws.cpp +++ /dev/null @@ -1,608 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcopchannel_qws.h" - -#ifndef QT_NO_COP - -#include "qwsdisplay_qws.h" -#include "qwscommand_qws_p.h" -#include "qwindowsystem_qws.h" -#include "qwindowsystem_p.h" -#include "qlist.h" -#include "qmap.h" -#include "qdatastream.h" -#include "qpointer.h" -#include "qmutex.h" - -#include "qdebug.h" - -QT_BEGIN_NAMESPACE - -typedef QMap<QString, QList<QWSClient*> > QCopServerMap; -static QCopServerMap *qcopServerMap = 0; - -class QCopServerRegexp -{ -public: - QCopServerRegexp( const QString& channel, QWSClient *client ); - QCopServerRegexp( const QCopServerRegexp& other ); - - QString channel; - QWSClient *client; - QRegExp regexp; -}; - -QCopServerRegexp::QCopServerRegexp( const QString& channel, QWSClient *client ) -{ - this->channel = channel; - this->client = client; - this->regexp = QRegExp( channel, Qt::CaseSensitive, QRegExp::Wildcard ); -} - -QCopServerRegexp::QCopServerRegexp( const QCopServerRegexp& other ) -{ - channel = other.channel; - client = other.client; - regexp = other.regexp; -} - -typedef QList<QCopServerRegexp> QCopServerRegexpList; -static QCopServerRegexpList *qcopServerRegexpList = 0; - -typedef QMap<QString, QList< QPointer<QCopChannel> > > QCopClientMap; -static QCopClientMap *qcopClientMap = 0; - -Q_GLOBAL_STATIC(QMutex, qcopClientMapMutex) - -// Determine if a channel name contains wildcard characters. -static bool containsWildcards( const QString& channel ) -{ - return channel.contains(QLatin1Char('*')); -} - -class QCopChannelPrivate -{ -public: - QString channel; -}; - -/*! - \class QCopChannel - \ingroup qws - - \brief The QCopChannel class provides communication capabilities - between clients in \l{Qt for Embedded Linux}. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - The Qt COmmunication Protocol (QCOP) is a many-to-many protocol - for transferring messages across registered channels. A channel is - registered by name, and anyone who wants to can listen to the - channel as well as send messages through it. The QCOP protocol - allows clients to communicate both within the same address space - and between different processes. - - To send messages to a given channel, QCopChannel provides the - static send() function. Using this function alone, the messages - are queued until Qt re-enters the event loop. To immediately flush - all queued messages to the registered listeners, call the static - flush() function. - - To listen to the traffic on a given channel, you typically - instantiate a QCopChannel object for the given channel and connect - to its received() signal that is emitted whenever there is - incoming data. Use the static isRegistered() function to query - the server for the existence of a given channel. QCopChannel - provides the channel() function returning the name of this - QCopChannel object's channel. - - In additon, QCopChannel provides the virtual receive() function - that can be reimplemented to filter the incoming messages and - data. The default implementation simply emits the received() - signal. - - \sa QWSServer, QWSClient, {Qt for Embedded Linux Architecture} -*/ - -/*! - Constructs a QCopChannel object for the specified \a channel, with - the given \a parent. Once created, the channel is registered by - the server. - - \sa isRegistered(), channel() -*/ - -QCopChannel::QCopChannel(const QString& channel, QObject *parent) : - QObject(parent) -{ - init(channel); -} - -#ifdef QT3_SUPPORT -/*! - Use the two argument overload instead, and call the - QObject::setObjectName() function to \a name the instance. -*/ -QCopChannel::QCopChannel(const QString& channel, QObject *parent, const char *name) : - QObject(parent) -{ - setObjectName(QString::fromAscii(name)); - init(channel); -} -#endif - -void QCopChannel::init(const QString& channel) -{ - d = new QCopChannelPrivate; - d->channel = channel; - - if (!qt_fbdpy) { - qFatal("QCopChannel: Must construct a QApplication " - "before QCopChannel"); - return; - } - - { - QMutexLocker locker(qcopClientMapMutex()); - - if (!qcopClientMap) - qcopClientMap = new QCopClientMap; - - // do we need a new channel list ? - QCopClientMap::Iterator it = qcopClientMap->find(channel); - if (it != qcopClientMap->end()) { - it.value().append(this); - return; - } - - it = qcopClientMap->insert(channel, QList< QPointer<QCopChannel> >()); - it.value().append(QPointer<QCopChannel>(this)); - } - - // inform server about this channel - qt_fbdpy->registerChannel(channel); -} - -/*! - \internal - - Resend all channel registrations - */ -void QCopChannel::reregisterAll() -{ - if(qcopClientMap) - for(QCopClientMap::Iterator iter = qcopClientMap->begin(); - iter != qcopClientMap->end(); - ++iter) - qt_fbdpy->registerChannel(iter.key()); -} - -/*! - Destroys this QCopChannel object. - - The server is notified that this particular listener has closed - its connection. The server will keep the channel open until the - last registered listener detaches. - - \sa isRegistered(), channel() -*/ - -QCopChannel::~QCopChannel() -{ - QMutexLocker locker(qcopClientMapMutex()); - QCopClientMap::Iterator it = qcopClientMap->find(d->channel); - Q_ASSERT(it != qcopClientMap->end()); - it.value().removeAll(this); - // still any clients connected locally ? - if (it.value().isEmpty()) { - QByteArray data; - QDataStream s(&data, QIODevice::WriteOnly); - s << d->channel; - if (qt_fbdpy) - send(QLatin1String(""), QLatin1String("detach()"), data); - qcopClientMap->remove(d->channel); - } - - delete d; -} - -/*! - Returns the name of this object's channel. - - \sa isRegistered() -*/ - -QString QCopChannel::channel() const -{ - return d->channel; -} - -/*! - \fn void QCopChannel::receive(const QString& message, const QByteArray &data) - - Processes the incoming \a message and \a data. - - This function is called by the server when this object's channel - receives new messages. Note that the default implementation simply - emits the received() signal; reimplement this function to process - the incoming \a message and \a data. - - Note that the format of the given \a data has to be well defined - in order to extract the information it contains. In addition, it - is recommended to use the DCOP convention. This is not a - requirement, but you must ensure that the sender and receiver - agree on the argument types. For example: - - \snippet doc/src/snippets/code/src_gui_embedded_qcopchannel_qws.cpp 0 - - The above code assumes that the \c message is a DCOP-style - function signature and the \c data contains the function's - arguments. - - \sa send(), channel(), received() - */ -void QCopChannel::receive(const QString& msg, const QByteArray &data) -{ - emit received(msg, data); -} - -/*! - \fn void QCopChannel::received(const QString& message, const QByteArray &data) - - This signal is emitted whenever this object's channel receives new - messages (i.e., it is emitted by the receive() function), passing - the incoming \a message and \a data as parameters. - - \sa receive(), channel() -*/ - -/*! - Queries the server for the existence of the given \a channel. Returns true - if the channel is registered; otherwise returns false. - - \sa channel(), send() -*/ - -bool QCopChannel::isRegistered(const QString& channel) -{ - QByteArray data; - QDataStream s(&data, QIODevice::WriteOnly); - s << channel; - if (!send(QLatin1String(""), QLatin1String("isRegistered()"), data)) - return false; - - QWSQCopMessageEvent *e = qt_fbdpy->waitForQCopResponse(); - bool known = e->message == "known"; - delete e; - return known; -} - -/*! - \fn bool QCopChannel::send(const QString& channel, const QString& message) - \overload -*/ - -bool QCopChannel::send(const QString& channel, const QString& msg) -{ - QByteArray data; - return send(channel, msg, data); -} - -/*! - \fn bool QCopChannel::send(const QString& channel, const QString& message, - const QByteArray &data) - - Sends the given \a message on the specified \a channel with the - given \a data. The message will be distributed to all clients - subscribed to the channel. Returns true if the message is sent - successfully; otherwise returns false. - - It is recommended to use the DCOP convention. This is not a - requirement, but you must ensure that the sender and receiver - agree on the argument types. - - Note that QDataStream provides a convenient way to fill the byte - array with auxiliary data. For example: - - \snippet doc/src/snippets/code/src_gui_embedded_qcopchannel_qws.cpp 1 - - In the code above the channel is \c "System/Shell". The \c message - is an arbitrary string, but in the example we've used the DCOP - convention of passing a function signature. Such a signature is - formatted as \c "functionname(types)" where \c types is a list of - zero or more comma-separated type names, with no whitespace, no - consts and no pointer or reference marks, i.e. no "*" or "&". - - \sa receive(), isRegistered() -*/ - -bool QCopChannel::send(const QString& channel, const QString& msg, - const QByteArray &data) -{ - if (!qt_fbdpy) { - qFatal("QCopChannel::send: Must construct a QApplication " - "before using QCopChannel"); - return false; - } - - qt_fbdpy->sendMessage(channel, msg, data); - - return true; -} - -/*! - \since 4.2 - - Flushes all queued messages to the registered listeners. - - Note that this function returns false if no QApplication has been - constructed, otherwise it returns true. - - \sa send() - -*/ -bool QCopChannel::flush() -{ - if (!qt_fbdpy) { - qFatal("QCopChannel::flush: Must construct a QApplication " - "before using QCopChannel"); - return false; - } - - qt_fbdpy->flushCommands(); - - return true; -} - -class QWSServerSignalBridge : public QObject { - Q_OBJECT - -public: - void emitNewChannel(const QString& channel); - void emitRemovedChannel(const QString& channel); - - signals: - void newChannel(const QString& channel); - void removedChannel(const QString& channel); -}; - -void QWSServerSignalBridge::emitNewChannel(const QString& channel){ - emit newChannel(channel); -} - -void QWSServerSignalBridge::emitRemovedChannel(const QString& channel) { - emit removedChannel(channel); -} - -/*! - \internal - Server side: subscribe client \a cl on channel \a ch. -*/ - -void QCopChannel::registerChannel(const QString& ch, QWSClient *cl) -{ - if (!qcopServerMap) - qcopServerMap = new QCopServerMap; - - // do we need a new channel list ? - QCopServerMap::Iterator it = qcopServerMap->find(ch); - if (it == qcopServerMap->end()) - it = qcopServerMap->insert(ch, QList<QWSClient*>()); - - // If the channel name contains wildcard characters, then we also - // register it on the server regexp matching list. - if (containsWildcards( ch )) { - QCopServerRegexp item(ch, cl); - if (!qcopServerRegexpList) - qcopServerRegexpList = new QCopServerRegexpList; - qcopServerRegexpList->append( item ); - } - - // If this is the first client in the channel, announce the channel as being created. - if (it.value().count() == 0) { - QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge(); - connect(qwsBridge, SIGNAL(newChannel(QString)), qwsServer, SIGNAL(newChannel(QString))); - qwsBridge->emitNewChannel(ch); - delete qwsBridge; - } - - it.value().append(cl); -} - -/*! - \internal - Server side: unsubscribe \a cl from all channels. -*/ - -void QCopChannel::detach(QWSClient *cl) -{ - if (!qcopServerMap) - return; - - QCopServerMap::Iterator it = qcopServerMap->begin(); - for (; it != qcopServerMap->end(); ++it) { - if (it.value().contains(cl)) { - it.value().removeAll(cl); - // If this was the last client in the channel, announce the channel as dead. - if (it.value().count() == 0) { - QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge(); - connect(qwsBridge, SIGNAL(removedChannel(QString)), qwsServer, SIGNAL(removedChannel(QString))); - qwsBridge->emitRemovedChannel(it.key()); - delete qwsBridge; - } - } - } - - if (!qcopServerRegexpList) - return; - - QCopServerRegexpList::Iterator it2 = qcopServerRegexpList->begin(); - while(it2 != qcopServerRegexpList->end()) { - if ((*it2).client == cl) - it2 = qcopServerRegexpList->erase(it2); - else - ++it2; - } -} - -/*! - \internal - Server side: transmit the message to all clients registered to the - specified channel. -*/ - -void QCopChannel::answer(QWSClient *cl, const QString& ch, - const QString& msg, const QByteArray &data) -{ - // internal commands - if (ch.isEmpty()) { - if (msg == QLatin1String("isRegistered()")) { - QString c; - QDataStream s(data); - s >> c; - bool known = qcopServerMap && qcopServerMap->contains(c) - && !((*qcopServerMap)[c]).isEmpty(); - // Yes, it's a typo, it's not user-visible, and we choose not to fix it for compatibility - QLatin1String ans = QLatin1String(known ? "known" : "unknown"); - QWSServerPrivate::sendQCopEvent(cl, QLatin1String(""), - ans, data, true); - return; - } else if (msg == QLatin1String("detach()")) { - QString c; - QDataStream s(data); - s >> c; - Q_ASSERT(qcopServerMap); - QCopServerMap::Iterator it = qcopServerMap->find(c); - if (it != qcopServerMap->end()) { - //Q_ASSERT(it.value().contains(cl)); - it.value().removeAll(cl); - if (it.value().isEmpty()) { - // If this was the last client in the channel, announce the channel as dead - QWSServerSignalBridge* qwsBridge = new QWSServerSignalBridge(); - connect(qwsBridge, SIGNAL(removedChannel(QString)), qwsServer, SIGNAL(removedChannel(QString))); - qwsBridge->emitRemovedChannel(it.key()); - delete qwsBridge; - qcopServerMap->erase(it); - } - } - if (qcopServerRegexpList && containsWildcards(c)) { - // Remove references to a wildcarded channel. - QCopServerRegexpList::Iterator it - = qcopServerRegexpList->begin(); - while(it != qcopServerRegexpList->end()) { - if ((*it).client == cl && (*it).channel == c) - it = qcopServerRegexpList->erase(it); - else - ++it; - } - } - return; - } - qWarning("QCopChannel: unknown internal command %s", qPrintable(msg)); - QWSServerPrivate::sendQCopEvent(cl, QLatin1String(""), - QLatin1String("bad"), data); - return; - } - - if (qcopServerMap) { - QList<QWSClient*> clist = qcopServerMap->value(ch); - for (int i=0; i < clist.size(); ++i) { - QWSClient *c = clist.at(i); - QWSServerPrivate::sendQCopEvent(c, ch, msg, data); - } - } - - if(qcopServerRegexpList && !containsWildcards(ch)) { - // Search for wildcard matches and forward the message on. - QCopServerRegexpList::ConstIterator it = qcopServerRegexpList->constBegin(); - for (; it != qcopServerRegexpList->constEnd(); ++it) { - if ((*it).regexp.exactMatch(ch)) { - QByteArray newData; - { - QDataStream stream - (&newData, QIODevice::WriteOnly | QIODevice::Append); - stream << ch; - stream << msg; - stream << data; - // Stream is flushed and closed at this point. - } - QWSServerPrivate::sendQCopEvent - ((*it).client, (*it).channel, - QLatin1String("forwardedMessage(QString,QString,QByteArray)"), - newData); - } - } - } -} - -/*! - \internal - Client side: distribute received event to the QCop instance managing the - channel. -*/ -void QCopChannel::sendLocally(const QString& ch, const QString& msg, - const QByteArray &data) -{ - Q_ASSERT(qcopClientMap); - - // filter out internal events - if (ch.isEmpty()) - return; - - // feed local clients with received data - QList< QPointer<QCopChannel> > clients; - { - QMutexLocker locker(qcopClientMapMutex()); - clients = (*qcopClientMap)[ch]; - } - for (int i = 0; i < clients.size(); ++i) { - QCopChannel *channel = (QCopChannel *)clients.at(i); - if ( channel ) - channel->receive(msg, data); - } -} - -QT_END_NAMESPACE - -#include "qcopchannel_qws.moc" - -#endif diff --git a/src/gui/embedded/qcopchannel_qws.h b/src/gui/embedded/qcopchannel_qws.h deleted file mode 100644 index 5f018662c7..0000000000 --- a/src/gui/embedded/qcopchannel_qws.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QCOPCHANNEL_QWS_H -#define QCOPCHANNEL_QWS_H - -#include <QtCore/qobject.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_COP - -class QWSClient; -class QCopChannelPrivate; - -class Q_GUI_EXPORT QCopChannel : public QObject -{ - Q_OBJECT -public: - explicit QCopChannel(const QString& channel, QObject *parent=0); -#ifdef QT3_SUPPORT - QT3_SUPPORT_CONSTRUCTOR QCopChannel(const QString& channel, QObject *parent, const char *name); -#endif - virtual ~QCopChannel(); - - QString channel() const; - - static bool isRegistered(const QString& channel); - static bool send(const QString& channel, const QString& msg); - static bool send(const QString& channel, const QString& msg, - const QByteArray &data); - - static bool flush(); - - static void sendLocally( const QString& ch, const QString& msg, - const QByteArray &data); - static void reregisterAll(); - - virtual void receive(const QString& msg, const QByteArray &data); - -Q_SIGNALS: - void received(const QString& msg, const QByteArray &data); - -private: - void init(const QString& channel); - - // server side - static void registerChannel(const QString& ch, QWSClient *cl); - static void detach(QWSClient *cl); - static void answer(QWSClient *cl, const QString& ch, - const QString& msg, const QByteArray &data); - // client side - QCopChannelPrivate* d; - - friend class QWSServer; - friend class QWSServerPrivate; - friend class QApplication; -}; - -#endif // QT_NO_COP - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QCOPCHANNEL_QWS_H diff --git a/src/gui/embedded/qdecoration_qws.cpp b/src/gui/embedded/qdecoration_qws.cpp deleted file mode 100644 index 7e93407c08..0000000000 --- a/src/gui/embedded/qdecoration_qws.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdecoration_qws.h" - -#include "qapplication.h" -#include "qdrawutil.h" -#include "qpainter.h" -#include "qregion.h" -#include "qwhatsthis.h" - -#include "qmenu.h" -#include "private/qwidget_p.h" -#include "qwsmanager_qws.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QDecoration - \ingroup qws - - \brief The QDecoration class is a base class for window - decorations in Qt for Embedded Linux - - Note that this class is non-portable and only available in - \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides window management of top level windows - and several ready made decorations (i.e., \c Default, \c Styled - and \c Windows). Custom decorations can be implemented by - subclassing the QDecoration class and creating a decoration plugin - (derived from QDecorationPlugin). The default - implementation of the QDecorationFactory class will automatically - detect the plugin, and load the decoration into the application at - run-time using Qt's \l {How to Create Qt Plugins}{plugin - system}. To actually apply a decoration, use the - QApplication::qwsSetDecoration() function. - - When creating a custom decoration, implement the paint() function - to paint the border and title decoration, and the region() - function to return the regions the decoration - occupies. Reimplement the regionClicked() and - regionDoubleClicked() functions to respond to mouse clicks (the - default implementations responds to (single) clicks on items in a - widget's system menu and double clicks on a widget's title). - - QDecoration provides the DecorationRegion enum that describes the - various regions of the window decoration, and the regionAt() - function to determine the region containing a given point. The - QDecoration class also provides the DecorationState enum - describing the state of a given region, e.g. whether it is active - or not. - - In addition, it is possible to build the system menu for a given - top level widget using the buildSysMenu() function; whenever an - action in this menu is triggered, the menuTriggered() function is - called automatically. - - Finally, the QDecoration class provides a couple of static - functions, startMove() and startResize(), which start a move or - resize action by making the appropriate decoration region active - and grabbing the mouse input. - - \sa QDecorationFactory, QDecorationPlugin, {Qt for Embedded Linux - Architecture} -*/ - -/*! - \fn QDecoration::QDecoration() - - Constructs a decoration object. -*/ - -/*! - \fn QDecoration::~QDecoration() - - Destroys this decoration object. -*/ - -/*! - \enum QDecoration::DecorationRegion - - This enum describes the various regions of the window decoration. - - \value All The entire region used by the window decoration. - - \value Top The top border used to vertically resize the window. - \value Bottom The bottom border used to vertically resize the window. - \value Left The left border used to horizontally resize the window. - \value Right The right border used to horizontally resize the window. - \value TopLeft The top-left corner of the window used to resize the - window both horizontally and vertically. - \value TopRight The top-right corner of the window used to resize the - window both horizontally and vertically. - \value BottomLeft The bottom-left corner of the window used to resize the - window both horizontally and vertically. - \value BottomRight The bottom-right corner of the window used to resize the - window both horizontally and vertically. - \value Borders All the regions used to describe the window's borders. - - \value Title The region containing the window title, used - to move the window by dragging with the mouse cursor. - \value Close The region occupied by the close button. Clicking in this - region closes the window. - \value Minimize The region occupied by the minimize button. Clicking in - this region minimizes the window. - \value Maximize The region occupied by the maximize button. Clicking in - this region maximizes the window. - \value Normalize The region occupied by a button used to restore a window's - normal size. Clicking in this region restores a maximized - window to its previous size. The region used for this - button is often also the Maximize region. - \value Menu The region occupied by the window's menu button. Clicking - in this region opens the window operations (system) menu. - \value Help The region occupied by the window's help button. Clicking - in this region causes the context-sensitive help function - to be enabled. - \value Resize The region used to resize the window. - \value Move The region used to move the window. - \value None No region. - - \sa region(), regionAt(), DecorationState -*/ - -/*! - \enum QDecoration::DecorationState - - This enum describes the various states of a decoration region. - - \value Normal The region is active - \value Disabled The region is inactive. - \value Hover The cursor is hovering over the region. - \value Pressed The region is pressed. - - \sa paint(), DecorationRegion -*/ - -/*! - \fn QRegion QDecoration::region(const QWidget *widget, const QRect & rectangle, int decorationRegion) - - Implement this function to return the region specified by \a - decorationRegion for the given top level \a widget. - - The \a rectangle parameter specifies the rectangle the decoration - is wrapped around. The \a decorationRegion is a bitmask of the - values described by the DecorationRegion enum. - - \sa regionAt(), paint() -*/ - -/*! - \fn QRegion QDecoration::region(const QWidget *widget, int decorationRegion) - \overload -*/ - -/*! - \fn bool QDecoration::paint(QPainter *painter, const QWidget *widget, int decorationRegion, - DecorationState state) - - Implement this function to paint the border and title decoration - for the specified top level \a widget using the given \a painter - and decoration \a state. The specified \a decorationRegion is a - bitmask of the values described by the DecorationRegion enum. - - Note that \l{Qt for Embedded Linux} expects this function to return true if - any of the widget's decorations are repainted; otherwise it should - return false. - - \sa region() -*/ - -/*! - \fn int QDecoration::regionAt(const QWidget *widget, const QPoint &point) - - Returns the type of the first region of the specified top level \a - widget containing the given \a point. - - The return value is one of the DecorationRegion enum's values. Use - the region() function to retrieve the actual region. If none of - the widget's regions contain the point, this function returns \l - None. - - \sa region() -*/ -int QDecoration::regionAt(const QWidget *w, const QPoint &point) -{ - int regions[] = { - TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight, // Borders first - Menu, Title, Help, Minimize, Normalize, Maximize, Close, // then buttons - None - }; - -// char *regions_str[] = { -// "TopLeft", "Top", "TopRight", "Left", "Right", "BottomLeft", "Bottom", "BottomRight", -// "Menu", "Title", "Help", "Minimize", "Normalize", "Maximize", "Close", -// "None" -// }; - - // First check to see if within all regions at all - QRegion reg = region(w, w->geometry(), All); - if (!reg.contains(point)) { - return None; - } - - int i = 0; - while (regions[i]) { - reg = region(w, w->geometry(), regions[i]); - if (reg.contains(point)) { -// qDebug("In region %s", regions_str[i]); - return regions[i]; - } - ++i; - } - return None; -} - -#ifndef QT_NO_MENU -/*! - Builds the system menu for the given top level \a widget, adding - \gui Restore, \gui Move, \gui Size, \gui Minimize, \gui Maximize - and \gui Close actions to the given \a menu. - - \sa menuTriggered() -*/ -void QDecoration::buildSysMenu(QWidget *widget, QMenu *menu) -{ - QDecorationAction *act = new QDecorationAction(QLatin1String("Restore"), - menu, Maximize); - act->setEnabled(widget->windowState() & Qt::WindowMaximized); - menu->addAction(act); - act = new QDecorationAction(QLatin1String("Move"), menu, Move); - act->setEnabled(!(widget->windowState() & Qt::WindowMaximized)); - menu->addAction(act); - menu->addAction(new QDecorationAction(QLatin1String("Size"), menu, Resize)); - act = new QDecorationAction(QLatin1String("Minimize"), menu, Minimize); - menu->addAction(act); - act = new QDecorationAction(QLatin1String("Maximize"), menu, Maximize); - act->setDisabled(widget->windowState() & Qt::WindowMaximized); - menu->addAction(act); - menu->addSeparator(); - menu->addAction(new QDecorationAction(QLatin1String("Close"), menu, Close)); -} - -/*! - This function is called whenever an action in a top level widget's - menu is triggered, and simply calls the regionClicked() function - passing the \a widget and \a action parameters as arguments. - - \sa buildSysMenu() -*/ -void QDecoration::menuTriggered(QWidget *widget, QAction *action) -{ - QDecorationAction *decAction = static_cast<QDecorationAction *>(action); - regionClicked(widget, decAction->reg); -} -#endif // QT_NO_MENU - -/*! - \fn void QDecoration::regionClicked(QWidget *widget, int region) - - Handles the event that the specified \a region in the given top - level \a widget is activated by a single click (the \a region - parameter is described using the DecorationRegion enum). - - This function is called whenever a region in a top level widget is - clicked; the default implementation responds to clicks on items in - the system menu, performing the requested actions. - - \sa regionDoubleClicked(), region() -*/ -void QDecoration::regionClicked(QWidget *widget, int reg) -{ - switch(reg) { - case Move: - startMove(widget); - break; - case Resize: - startResize(widget); - break; - case Help: -#ifndef QT_NO_WHATSTHIS - if (QWhatsThis::inWhatsThisMode()) - QWhatsThis::leaveWhatsThisMode(); - else - QWhatsThis::enterWhatsThisMode(); -#endif - break; - case Close: - widget->close(); - break; - case Normalize: - widget->showNormal(); - break; - case Maximize: - if (widget->windowState() & Qt::WindowMaximized) - widget->showNormal(); - else - widget->showMaximized(); - break; - } -} - -/*! - \fn void QDecoration::regionDoubleClicked(QWidget *widget, int region) - - Handles the event that the specified \a region in the given top - level \a widget is activated by a double click (the region - parameter is described using the DecorationRegion enum). - - This function is called whenever a region in a top level widget is - double clicked; the default implementation responds to a double - click on the widget's title, toggling its size between the maximum - and its normal size. - - \sa regionClicked(), region() -*/ -void QDecoration::regionDoubleClicked(QWidget *widget, int reg) -{ - switch(reg) - { - case Title: { - if (widget->windowState() & Qt::WindowMaximized) - widget->showNormal(); - else - widget->showMaximized(); - break; - } - } -} - -/*! - Starts to move the given top level \a widget by making its \l - Title region active and grabbing the mouse input. - - \sa startResize() -*/ -void QDecoration::startMove(QWidget *widget) -{ -#ifdef QT_NO_QWS_MANAGER - Q_UNUSED(widget); -#else - QWSManager *manager = widget->d_func()->topData()->qwsManager; - if (manager) - manager->startMove(); -#endif -} - -/*! - Starts to resize the given top level \a widget by making its \l - BottomRight region active and grabbing the mouse input. - - \sa startMove() -*/ -void QDecoration::startResize(QWidget *widget) -{ -#ifdef QT_NO_QWS_MANAGER - Q_UNUSED(widget); -#else - QWSManager *manager = widget->d_func()->topData()->qwsManager; - if (manager) - manager->startResize(); -#endif -} - - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecoration_qws.h b/src/gui/embedded/qdecoration_qws.h deleted file mode 100644 index 979e15f07d..0000000000 --- a/src/gui/embedded/qdecoration_qws.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATION_QWS_H -#define QDECORATION_QWS_H - -#include <QtGui/qregion.h> -#include <QtGui/qwidget.h> -#include <QtGui/qaction.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QPopupMenu; -class QMenu; - -#ifndef QT_NO_ACTION -class QDecorationAction : public QAction -{ -public: - QDecorationAction(const QString &text, QObject* parent, int region) - : QAction(text, parent), reg(region) {} - int reg; -}; -#endif // QT_NO_ACTION - -/* - Implements decoration styles -*/ -class Q_GUI_EXPORT QDecoration -{ -public: - QDecoration() {} - virtual ~QDecoration() {} - - /* AABBBBBBBBBBCC Items in DecorationRegion: - AijjjjjjjklmnC - A C A = TopLeft B = Top C = TopRight - D E D = Left E = Right - D E F = BottomLeft H = Bottom G = BottomRight - F G i = Menu j = Title k = Help - FFHHHHHHHHHHGG l = Minimize m = Maximize n = Close - - */ - - enum DecorationRegion { - None = 0x0000000000, All = 0x7fffffff, - TopLeft = 0x0000000001, Top = 0x0000000002, TopRight = 0x0000000004, - Left = 0x0000000008, Right = 0x0000000010, - BottomLeft = 0x0000000020, Bottom = 0x0000000040, BottomRight = 0x0000000080, - Borders = 0x00000000ff, - Menu = 0x0000000100, Title = 0x0000000200, Help = 0x0000000400, - Minimize = 0x0000000800, Maximize = 0x0000001000, Normalize = 0x0000002000, - Close = 0x0000004000, Move = 0x0000008000, Resize = 0x0000010000 - }; - - enum DecorationState { Normal = 0x04, Disabled = 0x08, Hover = 0x01, Pressed = 0x02 }; - - virtual QRegion region(const QWidget *w, const QRect &rect, int decorationRegion = All ) = 0; - QRegion region(const QWidget *w, int decorationRegion = All ) - { return region(w, w->rect(), decorationRegion); } - virtual int regionAt(const QWidget *w, const QPoint &point); - - virtual void regionClicked(QWidget *widget, int region); - virtual void regionDoubleClicked(QWidget *widget, int region); -#ifndef QT_NO_MENU - virtual void buildSysMenu(QWidget *widget, QMenu *menu); - void menuTriggered(QWidget *widget, QAction *action); -#endif - - static void startMove(QWidget *widget); - static void startResize(QWidget *widget); - - virtual bool paint(QPainter *p, const QWidget *w, int decorationRegion = All, - DecorationState state = Normal) = 0; - -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECORATION_QWS_H diff --git a/src/gui/embedded/qdecorationdefault_qws.cpp b/src/gui/embedded/qdecorationdefault_qws.cpp deleted file mode 100644 index b87ac3223d..0000000000 --- a/src/gui/embedded/qdecorationdefault_qws.cpp +++ /dev/null @@ -1,803 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qapplication.h> -#include <qwidget.h> -#include <qpainter.h> -#include <qpaintengine.h> -#include <qdrawutil.h> -#include "qdecorationdefault_qws.h" - -QT_BEGIN_NAMESPACE - -#if !defined(QT_NO_QWS_DECORATION_DEFAULT) || defined(QT_PLUGIN) - -QPixmap *QDecorationDefault::staticHelpPixmap = 0; -QPixmap *QDecorationDefault::staticMenuPixmap = 0; -QPixmap *QDecorationDefault::staticClosePixmap = 0; -QPixmap *QDecorationDefault::staticMinimizePixmap = 0; -QPixmap *QDecorationDefault::staticMaximizePixmap = 0; -QPixmap *QDecorationDefault::staticNormalizePixmap = 0; - -#ifndef QT_NO_IMAGEFORMAT_XPM - -/* XPM */ -static const char * const default_menu_xpm[] = { -/* width height ncolors chars_per_pixel */ -"16 16 11 1", -/* colors */ -" c #000000", -". c #336600", -"X c #666600", -"o c #99CC00", -"O c #999933", -"+ c #333300", -"@ c #669900", -"# c #999900", -"$ c #336633", -"% c #666633", -"& c #99CC33", -/* pixels */ -"oooooooooooooooo", -"oooooooooooooooo", -"ooooo#.++X#ooooo", -"ooooX Xoooo", -"oooX XO#% X&oo", -"oo# Ooo&@O Ooo", -"oo. Xoo#+ @X Xoo", -"oo+ OoO+ +O# +oo", -"oo+ #O+ +## +oo", -"oo. %@ ++ +. Xoo", -"oo# O@OO+ #oo", -"oooX X##$ Ooo", -"ooooX Xoo", -"oooo&OX++X#OXooo", -"oooooooooooooooo", -"oooooooooooooooo" -}; - -static const char * const default_help_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #707070", -" ", -" ", -" ...... ", -" ..XXXXXX ", -" .XX .XX ", -" .XX .XX ", -" ..XX ", -" ..XX ", -" ..XX ", -" .XX ", -" .XX ", -" .. ", -" .XX ", -" .XX ", -" ", -" "}; - -static const char * const default_close_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #707070", -" ", -" ", -" .X .X ", -" .XX .XX ", -" .XX .XX ", -" .XX .XX ", -" .XX.XX ", -" .XXX ", -" .XXX ", -" .XX.XX ", -" .XX .XX ", -" .XX .XX ", -" .XX .XX ", -" .X .X ", -" ", -" "}; - -static const char * const default_maximize_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #707070", -" ", -" ", -" ........... ", -" .XXXXXXXXXX ", -" .X .X ", -" .X .X ", -" .X .X ", -" .X .X ", -" .X .X ", -" .X .X ", -" .X .X ", -" .X........X ", -" .XXXXXXXXXX ", -" ", -" ", -" "}; - -static const char * const default_minimize_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #707070", -" ", -" ", -" ", -" ", -" ", -" ", -" ... ", -" . X ", -" .XX ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; - -static const char * const default_normalize_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #707070", -" ", -" ", -" ........ ", -" .XXXXXXXX ", -" .X .X ", -" .X .X ", -" ....X... .X ", -" .XXXXXXXX .X ", -" .X .XXXX ", -" .X .X ", -" .X .X ", -" .X......X ", -" .XXXXXXXX ", -" ", -" ", -" "}; - -#endif // QT_NO_IMAGEFORMAT_XPM - -/*! - \class QDecorationDefault - \since 4.4 - \ingroup qws - \brief The QDecorationDefault class is a base class providing default window decorations. - - See the documentation for class QDecoration for a detailed - description. This subclass of QDecoration provides standard - icons for the decoration regions. - - Note that this class is non-portable and only available in - \l{Qt for Embedded Linux}. - */ - -/*! - Default constructor. - */ -QDecorationDefault::QDecorationDefault() - : QDecoration() -{ - menu_width = 20; - help_width = 20; - close_width = 20; - minimize_width = 20; - maximize_width = 20; - normalize_width = 20; -} - -/*! - The constructor deletes the static pixmaps. - */ -QDecorationDefault::~QDecorationDefault() -{ - delete staticMenuPixmap; - delete staticClosePixmap; - delete staticMinimizePixmap; - delete staticMaximizePixmap; - delete staticNormalizePixmap; - - // This makes it safe to delete and then create a QDecorationDefault - staticMenuPixmap = 0; - staticClosePixmap = 0; - staticMinimizePixmap = 0; - staticMaximizePixmap = 0; - staticNormalizePixmap = 0; -} - -/*! - \fn const char **QDecorationDefault::xpmForRegion(int region) - - Returns a pointer to the X pixmap for the icon specified by - \a region. An X pixmap is an ASCII-text-based image. The value - of \a region must be one of a subset of the values of enum - DecorationRegion. The supported values are \e Help, \e Menu, - \e Close, \e Minimize, \e Maximize, and \e Normalize. Other - values of \a region cause zero to be returned. - - \sa QDecoration::DecorationRegion - */ -const char **QDecorationDefault::xpmForRegion(int reg) -{ -#ifdef QT_NO_IMAGEFORMAT_XPM - Q_UNUSED(reg); -#else - switch(reg) - { - case Help: - return (const char **)default_help_xpm; - case Menu: - return (const char **)default_menu_xpm; - case Close: - return (const char **)default_close_xpm; - case Minimize: - return (const char **)default_minimize_xpm; - case Maximize: - return (const char **)default_maximize_xpm; - case Normalize: - return (const char **)default_normalize_xpm; - } -#endif - return 0; -} - -/*! - \fn QPixmap QDecorationDefault::pixmapFor(const QWidget *widget, - int decorationRegion, int &xoff, int &yoff) - - Returns a pointer to the QPixmap for the widget specified by \a widget and - \a decorationRegion. The returned QPixmap is constructed from the default - X pixmap obtained from xpmForRegion(). - - \a xoff and \a yoff specify the offset for the pixmap. - - The value of \a decorationRegion must be one of a subset of the values - of enum DecorationRegion. The supported values are \e Help, - \e Menu, \e Close, \e Minimize, \e Maximize, and \e Normalize. - Other values of \a decorationRegion return 0. - - \sa QDecoration::DecorationRegion -*/ -QPixmap QDecorationDefault::pixmapFor(const QWidget *widget, - int decorationRegion, - int &xoff, - int &/*yoff*/) -{ -#ifdef QT_NO_IMAGEFORMAT_XPM - Q_UNUSED(widget); - Q_UNUSED(decorationRegion); - Q_UNUSED(xoff); - return QPixmap(); -#else - static const char **staticHelpPixmapXPM = 0; - static const char **staticMenuPixmapXPM = 0; - static const char **staticClosePixmapXPM = 0; - static const char **staticMinimizePixmapXPM = 0; - static const char **staticMaximizePixmapXPM = 0; - static const char **staticNormalizePixmapXPM = 0; - const char **xpm; - - // Why don't we just use/extend the enum type... - - if (staticHelpPixmapXPM != (xpm = xpmForRegion(Help)) || !staticHelpPixmap) { - staticHelpPixmapXPM = xpm; - staticHelpPixmap = new QPixmap(xpm); - } - if (staticMenuPixmapXPM != (xpm = xpmForRegion(Menu)) || !staticMenuPixmap) { - staticMenuPixmapXPM = xpm; - staticMenuPixmap = new QPixmap(xpm); - } - if (staticClosePixmapXPM != (xpm = xpmForRegion(Close)) || !staticClosePixmap) { - staticClosePixmapXPM = xpm; - staticClosePixmap = new QPixmap(xpm); - } - if (staticMinimizePixmapXPM != (xpm = xpmForRegion(Minimize)) || !staticMinimizePixmap) { - staticMinimizePixmapXPM = xpm; - staticMinimizePixmap = new QPixmap(xpm); - } - if (staticMaximizePixmapXPM != (xpm = xpmForRegion(Maximize)) || !staticMaximizePixmap) { - staticMaximizePixmapXPM = xpm; - staticMaximizePixmap = new QPixmap(xpm); - } - if (staticNormalizePixmapXPM != (xpm = xpmForRegion(Normalize)) || !staticNormalizePixmap) { - staticNormalizePixmapXPM = xpm; - staticNormalizePixmap = new QPixmap(xpm); - } - - const QPixmap *pm = 0; - - switch (decorationRegion) { - case Help: - pm = staticHelpPixmap; - break; - case Menu: - if (!widget->windowIcon().isNull()) - return widget->windowIcon().pixmap(16,16); //##### QIcon::pixmap() needs a size !!!!!!" - if (!pm) { - xoff = 1; - pm = staticMenuPixmap; - } - break; - case Close: - pm = staticClosePixmap; - break; - case Maximize: - pm = staticMaximizePixmap; - break; - case Normalize: - pm = staticNormalizePixmap; - break; - case Minimize: - pm = staticMinimizePixmap; - break; - default: - break; - } - return *pm; -#endif -} - -/*! - \fn int QDecorationDefault::titleBarHeight(const QWidget *widget) - - Returns the title bar height in pixels for the given \a widget. It is the - greater of 20, or the sum of the application font's line spacing value - plus a border width fudge factor. -*/ -int QDecorationDefault::titleBarHeight(const QWidget *) -{ - return qMax(20, QApplication::fontMetrics().height() + BORDER_WIDTH); -} - -/*! - Returns the region specified by \a decorationRegion for the - top-level \a widget. \a rect specifies the rectangle the decoration - wraps. The value of \a decorationRegion is a combination of the - bitmask values of enum DecorationRegion. - */ -QRegion QDecorationDefault::region(const QWidget *widget, - const QRect &rect, - int decorationRegion) -{ - Qt::WindowFlags flags = widget->windowFlags(); - bool hasBorder = !widget->isMaximized(); - bool hasTitle = flags & Qt::WindowTitleHint; - bool hasSysMenu = flags & Qt::WindowSystemMenuHint; - bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint; - bool hasMinimize = flags & Qt::WindowMinimizeButtonHint; - bool hasMaximize = flags & Qt::WindowMaximizeButtonHint; - int state = widget->windowState(); - bool isMinimized = state & Qt::WindowMinimized; - bool isMaximized = state & Qt::WindowMaximized; - - int titleHeight = hasTitle ? titleBarHeight(widget) : 0; - int bw = hasBorder ? BORDER_WIDTH : 0; - int bbw = hasBorder ? BOTTOM_BORDER_WIDTH : 0; - - QRegion region; - switch (decorationRegion) { - case All: { - QRect r(rect.left() - bw, - rect.top() - titleHeight - bw, - rect.width() + 2 * bw, - rect.height() + titleHeight + bw + bbw); - region = r; - region -= rect; - } - break; - - case Title: { - QRect r(rect.left() - + (hasSysMenu ? menu_width : 0), - rect.top() - titleHeight, - rect.width() - - (hasSysMenu ? menu_width : 0) - - close_width - - (hasMaximize ? maximize_width : 0) - - (hasMinimize ? minimize_width : 0) - - (hasContextHelp ? help_width : 0), - - titleHeight); - if (r.width() > 0) - region = r; - } - break; - - case Top: { - QRect r(rect.left() + CORNER_GRAB, - rect.top() - titleHeight - bw, - rect.width() - 2 * CORNER_GRAB, - bw); - region = r; - } - break; - - case Left: { - QRect r(rect.left() - bw, - rect.top() - titleHeight + CORNER_GRAB, - bw, - rect.height() + titleHeight - 2 * CORNER_GRAB); - region = r; - } - break; - - case Right: { - QRect r(rect.right() + 1, - rect.top() - titleHeight + CORNER_GRAB, - bw, - rect.height() + titleHeight - 2 * CORNER_GRAB); - region = r; - } - break; - - case Bottom: { - QRect r(rect.left() + CORNER_GRAB, - rect.bottom() + 1, - rect.width() - 2 * CORNER_GRAB, - bw); - region = r; - } - break; - - case TopLeft: { - QRect r1(rect.left() - bw, - rect.top() - bw - titleHeight, - CORNER_GRAB + bw, - bw); - - QRect r2(rect.left() - bw, - rect.top() - bw - titleHeight, - bw, - CORNER_GRAB + bw); - - region = QRegion(r1) + r2; - } - break; - - case TopRight: { - QRect r1(rect.right() - CORNER_GRAB, - rect.top() - bw - titleHeight, - CORNER_GRAB + bw, - bw); - - QRect r2(rect.right() + 1, - rect.top() - bw - titleHeight, - bw, - CORNER_GRAB + bw); - - region = QRegion(r1) + r2; - } - break; - - case BottomLeft: { - QRect r1(rect.left() - bw, - rect.bottom() + 1, - CORNER_GRAB + bw, - bw); - - QRect r2(rect.left() - bw, - rect.bottom() - CORNER_GRAB, - bw, - CORNER_GRAB + bw); - region = QRegion(r1) + r2; - } - break; - - case BottomRight: { - QRect r1(rect.right() - CORNER_GRAB, - rect.bottom() + 1, - CORNER_GRAB + bw, - bw); - - QRect r2(rect.right() + 1, - rect.bottom() - CORNER_GRAB, - bw, - CORNER_GRAB + bw); - region = QRegion(r1) + r2; - } - break; - - case Menu: { - if (hasSysMenu) { - region = QRect(rect.left(), rect.top() - titleHeight, - menu_width, titleHeight); - } - } - break; - - case Help: { - if (hasContextHelp) { - QRect r(rect.right() - - close_width - - (hasMaximize ? maximize_width : 0) - - (hasMinimize ? minimize_width : 0) - - help_width + 1, rect.top() - titleHeight, - help_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - - case Minimize: { - if (hasMinimize && !isMinimized) { - QRect r(rect.right() - close_width - - (hasMaximize ? maximize_width : 0) - - minimize_width + 1, rect.top() - titleHeight, - minimize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Maximize: { - if (hasMaximize && !isMaximized) { - QRect r(rect.right() - close_width - maximize_width + 1, - rect.top() - titleHeight, maximize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Normalize: { - if (hasMinimize && isMinimized) { - QRect r(rect.right() - close_width - - (hasMaximize ? maximize_width : 0) - - minimize_width + 1, rect.top() - titleHeight, - minimize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } else if (hasMaximize && isMaximized) { - QRect r(rect.right() - close_width - maximize_width + 1, - rect.top() - titleHeight, maximize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Close: { - QRect r(rect.right() - close_width + 1, rect.top() - titleHeight, - close_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - break; - - default: { - int i = 1; - while (i) { - if (i & decorationRegion) - region += this->region(widget, rect, i); - i <<= 1; - } - } - break; - } - - return region; -} - -/*! - Paints the border and title decoration for the top-level \a widget - using the \a painter provided and the decoration \a state. The value - of \a decorationRegion is a combination of the bitmask values of - enum DecorationRegion. - - Note that Qt for Embedded Linux expects this function to return true if any of - the widget's decorations are repainted; otherwise it returns false. - */ -bool QDecorationDefault::paint(QPainter *painter, - const QWidget *widget, - int decorationRegion, - DecorationState state) -{ - if (decorationRegion == None) - return false; - - const QRect titleRect = QDecoration::region(widget, Title).boundingRect(); - const QPalette pal = QApplication::palette(); - int titleHeight = titleRect.height(); - int titleWidth = titleRect.width(); - QRegion oldClipRegion = painter->clipRegion(); - - - Qt::WindowFlags flags = widget->windowFlags(); - bool hasBorder = !widget->isMaximized(); - bool hasTitle = flags & Qt::WindowTitleHint; - bool hasSysMenu = flags & Qt::WindowSystemMenuHint; - bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint; - bool hasMinimize = flags & Qt::WindowMinimizeButtonHint; - bool hasMaximize = flags & Qt::WindowMaximizeButtonHint; - - bool paintAll = (decorationRegion == int(All)); - bool handled = false; - - bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - - if ((paintAll || decorationRegion & Borders) && state == Normal && hasBorder) { - if (hasTitle) { // reduce flicker - QRect rect(widget->rect()); - QRect r(rect.left(), rect.top() - titleHeight, - rect.width(), titleHeight); - painter->setClipRegion(oldClipRegion - r); - } - QRect br = QDecoration::region(widget).boundingRect(); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_Source); - qDrawWinPanel(painter, br.x(), br.y(), br.width(), - br.height(), pal, false, - &pal.brush(QPalette::Window)); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_SourceOver); - handled |= true; - } - - if ((paintAll || decorationRegion & Title && titleWidth > 0) && state == Normal && hasTitle) { - painter->setClipRegion(oldClipRegion); - QBrush titleBrush; - QPen titlePen; - - if (widget == qApp->activeWindow()) { - titleBrush = pal.brush(QPalette::Highlight); - titlePen = pal.color(QPalette::HighlightedText); - } else { - titleBrush = pal.brush(QPalette::Window); - titlePen = pal.color(QPalette::Text); - } - - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_Source); - qDrawShadePanel(painter, - titleRect.x(), titleRect.y(), titleRect.width(), titleRect.height(), - pal, true, 1, &titleBrush); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_SourceOver); - - painter->setPen(titlePen); - painter->drawText(titleRect.x() + 4, titleRect.y(), - titleRect.width() - 8, titleRect.height(), - Qt::AlignVCenter, windowTitleFor(widget)); - handled |= true; - } - - if (state != Hover) { - painter->setClipRegion(oldClipRegion); - if ((paintAll || decorationRegion & Menu) && hasSysMenu) { - paintButton(painter, widget, Menu, state, pal); - handled |= true; - } - - if ((paintAll || decorationRegion & Help) && hasContextHelp) { - paintButton(painter, widget, Help, state, pal); - handled |= true; - } - - if ((paintAll || decorationRegion & Minimize) && hasMinimize) { - paintButton(painter, widget, Minimize, state, pal); - handled |= true; - } - - if ((paintAll || decorationRegion & Maximize) && hasMaximize) { - paintButton(painter, widget, - ((widget->windowState() & Qt::WindowMaximized)? Normalize : Maximize), - state, pal); - handled |= true; - } - - if (paintAll || decorationRegion & Close) { - paintButton(painter, widget, Close, state, pal); - handled |= true; - } - } - return handled; -} - -/*! - \fn void QDecorationDefault::paintButton(QPainter *painter, const - QWidget *widget, int buttonRegion, DecorationState state, - const QPalette &palette) - - Paints a region of the top-level \a widget. The region is - painted in the specified decoration \a state using the - \a painter and \a palette provided. The region to be painted is specified - by \a buttonRegion, which is a combination of the bitmask values of - DecorationRegion. If the value of \a buttonRegion is one of \e Help, - \e Menu, \e Close, \e Minimize, \e Maximize, and \e Normalize, the - button pixmap for that region is painted. - - \sa pixmapFor() - */ -void QDecorationDefault::paintButton(QPainter *painter, - const QWidget *widget, - int buttonRegion, - DecorationState state, - const QPalette &pal) -{ - int xoff = 2; - int yoff = 2; - - const QPixmap pm = pixmapFor(widget, buttonRegion, xoff, yoff); - QRect brect(QDecoration::region(widget, buttonRegion).boundingRect()); - bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - - if (state & QDecoration::Pressed) { - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_Source); - qDrawWinPanel(painter, brect, pal, true, &pal.brush(QPalette::Window)); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_SourceOver); - ++xoff; - ++yoff; - } else { - painter->fillRect(brect, pal.brush(QPalette::Window)); - } - - if (!pm.isNull()) - painter->drawPixmap(brect.x() + xoff, brect.y() + yoff, pm); -} - -extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); - -/*! - \internal - */ -QString QDecorationDefault::windowTitleFor(const QWidget *widget) const -{ - return qt_setWindowTitle_helperHelper(widget->windowTitle(), widget); -} - -#endif // QT_NO_QWS_DECORATION_DEFAULT - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecorationdefault_qws.h b/src/gui/embedded/qdecorationdefault_qws.h deleted file mode 100644 index a166220913..0000000000 --- a/src/gui/embedded/qdecorationdefault_qws.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATIONDEFAULT_QWS_H -#define QDECORATIONDEFAULT_QWS_H - -#include <QtGui/qdecoration_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if !defined(QT_NO_QWS_DECORATION_DEFAULT) || defined(QT_PLUGIN) - -#define CORNER_GRAB 16 -#define BORDER_WIDTH 4 -#define BOTTOM_BORDER_WIDTH BORDER_WIDTH - -class Q_GUI_EXPORT QDecorationDefault : public QDecoration -{ -public: - QDecorationDefault(); - virtual ~QDecorationDefault(); - - virtual QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion = All); - virtual bool paint(QPainter *painter, const QWidget *widget, int decorationRegion = All, - DecorationState state = Normal); - -protected: - virtual int titleBarHeight(const QWidget *widget); - - virtual void paintButton(QPainter *painter, const QWidget *widget, int buttonRegion, - DecorationState state, const QPalette &pal); - virtual QPixmap pixmapFor(const QWidget *widget, int decorationRegion, int &xoff, int &yoff); - virtual const char **xpmForRegion(int region); - - QString windowTitleFor(const QWidget *widget) const; - - int menu_width; - int help_width; - int close_width; - int minimize_width; - int maximize_width; - int normalize_width; - -private: - static QPixmap *staticHelpPixmap; - static QPixmap *staticMenuPixmap; - static QPixmap *staticClosePixmap; - static QPixmap *staticMinimizePixmap; - static QPixmap *staticMaximizePixmap; - static QPixmap *staticNormalizePixmap; - -}; - - -QT_END_NAMESPACE -#endif // QT_NO_QWS_DECORATION_DEFAULT -QT_END_HEADER - -#endif // QDECORATIONDEFAULT_QWS_H diff --git a/src/gui/embedded/qdecorationfactory_qws.cpp b/src/gui/embedded/qdecorationfactory_qws.cpp deleted file mode 100644 index 2cae140ac0..0000000000 --- a/src/gui/embedded/qdecorationfactory_qws.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdecorationfactory_qws.h" -#include "qdecorationplugin_qws.h" -#include "private/qfactoryloader_p.h" -#include "qmutex.h" - -#include "qapplication.h" -#include "qdecorationdefault_qws.h" -#include "qdecorationwindows_qws.h" -#include "qdecorationstyled_qws.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_LIBRARY -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QDecorationFactoryInterface_iid, - QLatin1String("/decorations"), Qt::CaseInsensitive)) -#endif - - - -/*! - \class QDecorationFactory - \ingroup qws - \ingroup appearance - - \brief The QDecorationFactory class creates window decorations in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QDecorationFactory is used to detect and instantiate the available - decorations, allowing \l{Qt for Embedded Linux} to load the preferred - decoration into the application at runtime. The create() function - returns a QDecoration object representing the decoration - identified by a given key. The valid keys (i.e. the supported - decorations) can be retrieved using the keys() function. - - \l{Qt for Embedded Linux} provides three built-in decorations: \c Default, - \c Styled and \c Windows. In addition, custom decorations can be - added using Qt's \l {How to Create Qt Plugins}{plugin mechanism}, - i.e. by subclassing the QDecoration class and creating a mouse - driver plugin (QDecorationPlugin). - - \sa QDecoration, QDecorationPlugin -*/ - -/*! - Creates the decoration specified by the given \a key. Note that - the keys are case-insensitive. - - \sa keys() -*/ - -QDecoration *QDecorationFactory::create(const QString& key) -{ - QDecoration *ret = 0; - QString decoration = key.toLower(); -#ifndef QT_NO_QWS_DECORATION_DEFAULT - if (decoration == QLatin1String("default")) - ret = new QDecorationDefault; - else -#endif -#ifndef QT_NO_QWS_DECORATION_WINDOWS - if (decoration == QLatin1String("windows")) - ret = new QDecorationWindows; - else -#endif -#ifndef QT_NO_QWS_DECORATION_STYLED - if (decoration == QLatin1String("styled")) - ret = new QDecorationStyled; - else -#endif - { } // Keep these here - they make the #ifdefery above work -#ifndef QT_NO_LIBRARY - if (!ret) { - if (QDecorationFactoryInterface *factory = qobject_cast<QDecorationFactoryInterface*>(loader()->instance(decoration))) { - ret = factory->create(decoration); - } - } -#endif - return ret; -} - -/*! - Returns the list of valid keys, i.e., the available decorations. - - \sa create() -*/ -QStringList QDecorationFactory::keys() -{ - QStringList list; -#ifndef QT_NO_QWS_DECORATION_STYLED - list << QLatin1String("Styled"); -#endif -#ifndef QT_NO_QWS_DECORATION_DEFAULT - list << QLatin1String("Default"); -#endif -#ifndef QT_NO_QWS_DECORATION_WINDOWS - list << QLatin1String("Windows"); -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - QStringList plugins = loader()->keys(); - for (int i = 0; i < plugins.size(); ++i) { - if (!list.contains(plugins.at(i))) - list += plugins.at(i); - } -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - - return list; -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecorationfactory_qws.h b/src/gui/embedded/qdecorationfactory_qws.h deleted file mode 100644 index c5995eeb02..0000000000 --- a/src/gui/embedded/qdecorationfactory_qws.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATIONFACTORY_QWS_H -#define QDECORATIONFACTORY_QWS_H - -#include <QtCore/qstringlist.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QDecoration; - -class Q_GUI_EXPORT QDecorationFactory -{ -public: - static QStringList keys(); - static QDecoration *create(const QString&); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECORATIONFACTORY_QWS_H diff --git a/src/gui/embedded/qdecorationplugin_qws.cpp b/src/gui/embedded/qdecorationplugin_qws.cpp deleted file mode 100644 index 869243151f..0000000000 --- a/src/gui/embedded/qdecorationplugin_qws.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdecorationplugin_qws.h" -#include "qdecoration_qws.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QDecorationPlugin - \ingroup qws - \ingroup plugins - - \brief The QDecorationPlugin class is an abstract base class for - window decoration plugins in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides three ready-made decoration styles: \c - Default, \c Styled and \c Windows. Custom decorations can be - implemented by subclassing the QDecoration class and creating a - decoration plugin. - - A decoration plugin can be created by subclassing - QDecorationPlugin and implementing the pure virtual keys() and - create() functions. By exporting the derived class using the - Q_EXPORT_PLUGIN2() macro, the default implementation of the - QDecorationFactory class will automatically detect the plugin and - load the driver into the application at run-time. See \l{How to - Create Qt Plugins} for details. - - To actually apply a decoration, use the - QApplication::qwsSetDecoration() function. - - \sa QDecoration, QDecorationFactory -*/ - -/*! - \fn QStringList QDecorationPlugin::keys() const - - Returns the list of valid keys, i.e., the decorations supported by - this plugin. - - \sa create() -*/ - -/*! - \fn QDecoration *QDecorationPlugin::create(const QString &key) - - Creates a decoration matching the given \a key. Note that keys are - case-insensitive. - - \sa keys() -*/ - -/*! - Constructs a decoration plugin with the given \a parent. - - Note that this constructor is invoked automatically by the - Q_EXPORT_PLUGIN2() macro, so there is no need for calling it - explicitly. -*/ -QDecorationPlugin::QDecorationPlugin(QObject *parent) - : QObject(parent) -{ -} - -/*! - Destroys the decoration plugin. - - Note that Qt destroys a plugin automatically when it is no longer - used, so there is no need for calling the destructor explicitly. -*/ -QDecorationPlugin::~QDecorationPlugin() -{ -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecorationplugin_qws.h b/src/gui/embedded/qdecorationplugin_qws.h deleted file mode 100644 index 4fa97f36f1..0000000000 --- a/src/gui/embedded/qdecorationplugin_qws.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATIONPLUGIN_QWS_H -#define QDECORATIONPLUGIN_QWS_H - -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QDecoration; - -struct Q_GUI_EXPORT QDecorationFactoryInterface : public QFactoryInterface -{ - virtual QDecoration *create(const QString &key) = 0; -}; - -#define QDecorationFactoryInterface_iid "com.trolltech.Qt.QDecorationFactoryInterface" -Q_DECLARE_INTERFACE(QDecorationFactoryInterface, QDecorationFactoryInterface_iid) - -class Q_GUI_EXPORT QDecorationPlugin : public QObject, public QDecorationFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QDecorationFactoryInterface:QFactoryInterface) - public: - explicit QDecorationPlugin(QObject *parent = 0); - ~QDecorationPlugin(); - - virtual QStringList keys() const = 0; - virtual QDecoration *create(const QString &key) = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECORATIONPLUGIN_QWS_H diff --git a/src/gui/embedded/qdecorationstyled_qws.cpp b/src/gui/embedded/qdecorationstyled_qws.cpp deleted file mode 100644 index 40da4c2583..0000000000 --- a/src/gui/embedded/qdecorationstyled_qws.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qapplication.h> -#include <qwidget.h> -#include <qpainter.h> -#include <qdrawutil.h> -#include "qdecorationstyled_qws.h" -#include "qstyle.h" -#include "qstyleoption.h" -#include "qpaintengine.h" - -QT_BEGIN_NAMESPACE - -#if !defined(QT_NO_QWS_DECORATION_STYLED) || defined(QT_PLUGIN) - -QDecorationStyled::QDecorationStyled() - : QDecorationDefault() -{ -} - -QDecorationStyled::~QDecorationStyled() -{ -} - -int QDecorationStyled::titleBarHeight(const QWidget *widget) -{ - QStyleOptionTitleBar opt; - opt.subControls = QStyle::SC_TitleBarLabel - | QStyle::SC_TitleBarSysMenu - | QStyle::SC_TitleBarNormalButton - | QStyle::SC_TitleBarContextHelpButton - | QStyle::SC_TitleBarMinButton - | QStyle::SC_TitleBarMaxButton - | QStyle::SC_TitleBarCloseButton; - opt.titleBarFlags = widget->windowFlags(); - opt.direction = QApplication::layoutDirection(); - opt.text = windowTitleFor(widget); - opt.icon = widget->windowIcon(); - opt.rect = widget->rect(); - - QStyle *style = QApplication::style(); - if (!style) - return 18; - - return style->pixelMetric(QStyle::PM_TitleBarHeight, &opt, 0); -} - -bool QDecorationStyled::paint(QPainter *painter, const QWidget *widget, int decorationRegion, - DecorationState state) -{ - if (decorationRegion == None) - return false; - - bool isActive = (widget == qApp->activeWindow()); - QPalette pal = qApp->palette(); - //ideally, the difference between Active and Inactive should be enough, so we shouldn't need to test this - if (!isActive) { - //pal.setCurrentColorGroup(QPalette::Disabled); //Can't do this either, because of palette limitations - //copied from Q3TitleBar: - pal.setColor(QPalette::Inactive, QPalette::Highlight, - pal.color(QPalette::Inactive, QPalette::Dark)); - pal.setColor(QPalette::Inactive, QPalette::Base, - pal.color(QPalette::Inactive, QPalette::Dark)); - pal.setColor(QPalette::Inactive, QPalette::HighlightedText, - pal.color(QPalette::Inactive, QPalette::Window)); - } - - Qt::WindowFlags flags = widget->windowFlags(); - bool hasBorder = !widget->isMaximized(); - bool hasTitle = flags & Qt::WindowTitleHint; - bool hasSysMenu = flags & Qt::WindowSystemMenuHint; - bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint; - bool hasMinimize = flags & Qt::WindowMinimizeButtonHint; - bool hasMaximize = flags & Qt::WindowMaximizeButtonHint; - - bool paintAll = (DecorationRegion(decorationRegion) == All); - bool handled = false; - - QStyle *style = QApplication::style(); - - // In the case of a borderless title bar, the title bar must be expanded one - // borderWidth to the left, right and up. - bool noTitleBorder = style->styleHint(QStyle::SH_TitleBar_NoBorder, 0, widget); - int borderWidth = style->pixelMetric(QStyle::PM_MDIFrameWidth, 0, 0); - int titleHeight = titleBarHeight(widget) + (noTitleBorder ? borderWidth : 0); - int titleExtra = noTitleBorder ? borderWidth : 0; - - if ((paintAll || decorationRegion & Borders) && state == Normal && hasBorder) { - QRegion newClip = painter->clipRegion(); - if (hasTitle) { // reduce flicker - QRect rect(widget->rect()); - QRect r(rect.left() - titleExtra, rect.top() - titleHeight, - rect.width() + 2 * titleExtra, titleHeight); - newClip -= r; - } - if (!newClip.isEmpty()) { - QRect br = QDecoration::region(widget).boundingRect(); - painter->save(); - painter->setClipRegion(newClip); - - QStyleOptionFrame opt; - opt.palette = pal; - opt.rect = br; - opt.lineWidth = borderWidth; - - if (isActive) - opt.state |= QStyle::State_Active; - bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_Source); - painter->fillRect(br, pal.window()); - if (porterDuff) - painter->setCompositionMode(QPainter::CompositionMode_SourceOver); - style->drawPrimitive(QStyle::PE_FrameWindow, &opt, painter, 0); - painter->restore(); - - decorationRegion &= (~Borders); - handled |= true; - } - } - - if (hasTitle) { - painter->save(); - - QStyleOptionTitleBar opt; - opt.subControls = (decorationRegion & Title - ? QStyle::SC_TitleBarLabel : QStyle::SubControl(0)) - | (decorationRegion & Menu - ? QStyle::SC_TitleBarSysMenu : QStyle::SubControl(0)) - | (decorationRegion & Help - ? QStyle::SC_TitleBarContextHelpButton : QStyle::SubControl(0)) - | (decorationRegion & Minimize - ? QStyle::SC_TitleBarMinButton : QStyle::SubControl(0)) - | (decorationRegion & Maximize - ? QStyle::SC_TitleBarMaxButton : QStyle::SubControl(0)) - | (decorationRegion & (Minimize | Maximize) - ? QStyle::SC_TitleBarNormalButton : QStyle::SubControl(0)) - | (decorationRegion & Close - ? QStyle::SC_TitleBarCloseButton : QStyle::SubControl(0)); - opt.titleBarFlags = widget->windowFlags(); - opt.titleBarState = widget->windowState(); - if (isActive) - opt.titleBarState |= QStyle::State_Active; - opt.text = windowTitleFor(widget); - opt.icon = widget->windowIcon(); - opt.palette = pal; - opt.rect = QRect(widget->rect().x() - titleExtra, -titleHeight, - widget->rect().width() + 2 * titleExtra, titleHeight); - - if (paintAll) { - painter->setClipRegion(opt.rect); - } else { - const QRect widgetRect = widget->rect(); - QRegion newClip = opt.rect; - if (!(decorationRegion & Menu) && hasSysMenu) - newClip -= region(widget, widgetRect, Menu); - if (!(decorationRegion & Title) && hasTitle) - newClip -= region(widget, widgetRect, Title); - if (!(decorationRegion & Help) && hasContextHelp) - newClip -= region(widget, widgetRect, Help); - if (!(decorationRegion & Minimize) && hasMinimize) - newClip -= region(widget, widgetRect, Minimize); - if (!(decorationRegion & Maximize) && hasMaximize) - newClip -= region(widget, widgetRect, Maximize); - if (!(decorationRegion & (Minimize | Maximize)) && (hasMaximize | hasMinimize)) - newClip -= region(widget, widgetRect, Normal); - if (!(decorationRegion & Close)) - newClip -= region(widget, widgetRect, Close); - painter->setClipRegion(newClip); - } - - if (state == Pressed) - opt.activeSubControls = opt.subControls; - - style->drawComplexControl(QStyle::CC_TitleBar, &opt, painter, 0); - painter->restore(); - - decorationRegion &= ~(Title | Menu | Help | Normalize | Minimize | Maximize | Close); - handled |= true; - } - - return handled; -} - -QRegion QDecorationStyled::region(const QWidget *widget, const QRect &rect, int decorationRegion) -{ - QStyle *style = QApplication::style(); - - // In the case of a borderless title bar, the title bar must be expanded one - // borderWidth to the left, right and up. - bool noTitleBorder = style->styleHint(QStyle::SH_TitleBar_NoBorder, 0, widget); - int borderWidth = style->pixelMetric(QStyle::PM_MDIFrameWidth, 0, 0); - int titleHeight = titleBarHeight(widget) + (noTitleBorder ? borderWidth : 0); - int titleExtra = noTitleBorder ? borderWidth : 0; - - QRect inside = QRect(rect.x() - titleExtra, rect.top() - titleHeight, - rect.width() + 2 * titleExtra, titleHeight); - - Qt::WindowFlags flags = widget->windowFlags(); - bool hasSysMenu = flags & Qt::WindowSystemMenuHint; - bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint; - bool hasMinimize = flags & Qt::WindowMinimizeButtonHint; - bool hasMaximize = flags & Qt::WindowMaximizeButtonHint; - - QStyleOptionTitleBar opt; - opt.subControls = QStyle::SC_TitleBarLabel - | QStyle::SC_TitleBarSysMenu - | QStyle::SC_TitleBarNormalButton - | QStyle::SC_TitleBarMinButton - | QStyle::SC_TitleBarMaxButton - | QStyle::SC_TitleBarCloseButton; - opt.titleBarFlags = widget->windowFlags(); - opt.direction = QApplication::layoutDirection(); - opt.text = windowTitleFor(widget); - opt.icon = widget->windowIcon(); - opt.rect = inside; - - QRegion region; - switch (decorationRegion) { - case Title: - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarLabel, 0); - break; - case Menu: - if (hasSysMenu) - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarSysMenu, 0); - break; - case Help: - if (hasContextHelp) - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarContextHelpButton, - 0); - break; - case Normalize: - if (hasMaximize | hasMinimize) - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarNormalButton, - 0); - break; - case Minimize: - if (hasMinimize) - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarMinButton, - 0); - break; - case Maximize: - if (hasMaximize) - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarMaxButton, - 0); - break; - case Close: - region = style->subControlRect(QStyle::CC_TitleBar, &opt, - QStyle::SC_TitleBarCloseButton, 0); - break; - - default: - region = QDecorationDefault::region(widget, rect, decorationRegion); - } - - opt.rect = QRect(rect.x() - titleExtra, rect.top() - titleHeight, - rect.width() + 2 * titleExtra, - rect.height() + titleHeight + titleExtra); - - QStyleHintReturnMask mask; - style->styleHint(QStyle::SH_WindowFrame_Mask, &opt, 0, &mask); - - return (mask.region.isEmpty() ? region : (region & mask.region)); -} - -#endif // QT_NO_QWS_DECORATION_STYLED - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecorationstyled_qws.h b/src/gui/embedded/qdecorationstyled_qws.h deleted file mode 100644 index ed697c0cd2..0000000000 --- a/src/gui/embedded/qdecorationstyled_qws.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATIONSTYLED_QWS_H -#define QDECORATIONSTYLED_QWS_H - -#include <QtGui/qdecorationdefault_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if !defined(QT_NO_QWS_DECORATION_STYLED) || defined(QT_PLUGIN) - -class Q_GUI_EXPORT QDecorationStyled : public QDecorationDefault -{ -public: - QDecorationStyled(); - virtual ~QDecorationStyled(); - - QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion = All); - bool paint(QPainter *painter, const QWidget *widget, int decorationRegion = All, - DecorationState state = Normal); - int titleBarHeight(const QWidget *widget); -}; - -#endif // QT_NO_QWS_DECORATION_STYLED - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECORATIONSTYLED_QWS_H diff --git a/src/gui/embedded/qdecorationwindows_qws.cpp b/src/gui/embedded/qdecorationwindows_qws.cpp deleted file mode 100644 index 51d57d7203..0000000000 --- a/src/gui/embedded/qdecorationwindows_qws.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qapplication.h> -#include <qwidget.h> -#include <qpainter.h> -#include <qdrawutil.h> -#include "qdecorationwindows_qws.h" - -QT_BEGIN_NAMESPACE - -#if !defined(QT_NO_QWS_DECORATION_WINDOWS) || defined(QT_PLUGIN) - -#ifndef QT_NO_IMAGEFORMAT_XPM - -/* XPM */ -static const char * const win_close_xpm[] = { -"16 16 4 1", -" s None c None", -". c #000000", -"X c #FFFFFF", -"Y c #707070", -" ", -" ", -" ", -" Y. .Y ", -" .. .. ", -" .. .. ", -" .YY. ", -" Y..Y ", -" .YY. ", -" .. .. ", -" .. .. ", -" Y. .Y ", -" ", -" ", -" ", -" "}; - -static const char * const win_help_xpm[] = { -"16 16 3 1", -" s None c None", -". c #ffffff", -"X c #000000", -" ", -" ", -" ", -" XXXXXX ", -" XX XX ", -" XX XX ", -" XX ", -" XX ", -" XX ", -" XX ", -" ", -" XX ", -" XX ", -" ", -" ", -" "}; - -static const char * const win_maximize_xpm[] = { -"16 16 4 1", -" s None c None", -". c #000000", -"X c #FFFFFF", -"Y c #707070", -" ", -" ", -" ", -" .......... ", -" .......... ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" .......... ", -" ", -" ", -" ", -" "}; - -static const char * const win_minimize_xpm[] = { -"16 16 4 1", -" s None c None", -". c #000000", -"X c #FFFFFF", -"Y c #707070", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ........ ", -" ........ ", -" ", -" ", -" ", -" "}; - -static const char * const win_normalize_xpm[] = { -"16 16 4 1", -" s None c None", -". c #000000", -"X c #FFFFFF", -"Y c #707070", -" ", -" ", -" ......... ", -" ......... ", -" . . ", -" . . ", -" ......... . ", -" ......... . ", -" . . . ", -" . .... ", -" . . ", -" . . ", -" ......... ", -" ", -" ", -" "}; - -#endif // QT_NO_IMAGEFORMAT_XPM - - -QDecorationWindows::QDecorationWindows() - : QDecorationDefault() -{ - menu_width = 16; - help_width = 18; - minimize_width = 18; - maximize_width = 18; - close_width = 18; -} - -QDecorationWindows::~QDecorationWindows() -{ -} - -const char **QDecorationWindows::xpmForRegion(int reg) -{ -#ifdef QT_NO_IMAGEFORMAT_XPM - Q_UNUSED(reg); -#else - switch(reg) - { - case Close: - return (const char **)win_close_xpm; - case Help: - return (const char **)win_help_xpm; - case Minimize: - return (const char **)win_minimize_xpm; - case Maximize: - return (const char **)win_maximize_xpm; - case Normalize: - return (const char **)win_normalize_xpm; - default: - return QDecorationDefault::xpmForRegion(reg); - } -#endif - return 0; -} - -QRegion QDecorationWindows::region(const QWidget *widget, const QRect &rect, int type) -{ - Qt::WindowFlags flags = widget->windowFlags(); - bool hasTitle = flags & Qt::WindowTitleHint; - bool hasSysMenu = flags & Qt::WindowSystemMenuHint; - bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint; - bool hasMinimize = flags & Qt::WindowMinimizeButtonHint; - bool hasMaximize = flags & Qt::WindowMaximizeButtonHint; - const QFontMetrics fontMetrics = QApplication::fontMetrics(); - int titleHeight = hasTitle ? qMax(20, fontMetrics.height()) : 0; - int state = widget->windowState(); - bool isMinimized = state & Qt::WindowMinimized; - bool isMaximized = state & Qt::WindowMaximized; - - QRegion region; - switch (type) { - case Menu: { - if (hasSysMenu) { - region = QRect(rect.left() + 2, rect.top() - titleHeight, - menu_width, titleHeight); - } - } - break; - - case Title: { - QRect r(rect.left() - + (hasSysMenu ? menu_width + 4: 0), - rect.top() - titleHeight, - rect.width() - - (hasSysMenu ? menu_width : 0) - - close_width - - (hasMaximize ? maximize_width : 0) - - (hasMinimize ? minimize_width : 0) - - (hasContextHelp ? help_width : 0) - - 3, - titleHeight); - if (r.width() > 0) - region = r; - } - break; - case Help: { - if (hasContextHelp) { - QRect r(rect.right() - - close_width - - (hasMaximize ? maximize_width : 0) - - (hasMinimize ? minimize_width : 0) - - help_width - 3, rect.top() - titleHeight, - help_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Minimize: { - if (hasMinimize && !isMinimized) { - QRect r(rect.right() - close_width - - (hasMaximize ? maximize_width : 0) - - minimize_width - 3, rect.top() - titleHeight, - minimize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Maximize: { - if (hasMaximize && !isMaximized) { - QRect r(rect.right() - close_width - maximize_width - 3, - rect.top() - titleHeight, maximize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Normalize: { - if (hasMinimize && isMinimized) { - QRect r(rect.right() - close_width - - (hasMaximize ? maximize_width : 0) - - minimize_width - 3, rect.top() - titleHeight, - minimize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } else if (hasMaximize && isMaximized) { - QRect r(rect.right() - close_width - maximize_width - 3, - rect.top() - titleHeight, maximize_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - } - break; - - case Close: { - QRect r(rect.right() - close_width - 1, rect.top() - titleHeight, - close_width, titleHeight); - if (r.left() > rect.left() + titleHeight) - region = r; - } - break; - - default: - region = QDecorationDefault::region(widget, rect, type); - break; - } - - return region; -} - -bool QDecorationWindows::paint(QPainter *painter, const QWidget *widget, int decorationRegion, - DecorationState state) -{ - if (decorationRegion == None) - return false; - - const QRect titleRect = QDecoration::region(widget, Title).boundingRect(); - const QPalette pal = QApplication::palette(); - QRegion oldClipRegion = painter->clipRegion(); - - bool paintAll = (decorationRegion == int(All)); - if ((paintAll || decorationRegion & Title && titleRect.width() > 0) && state == Normal - && (widget->windowFlags() & Qt::WindowTitleHint) ) { - painter->setClipRegion(oldClipRegion); - QColor fromBrush, toBrush; - QPen titlePen; - - if (widget == qApp->activeWindow() || qApp->activeWindow() == qApp->activePopupWidget()) { - fromBrush = pal.color(QPalette::Highlight); - titlePen = pal.color(QPalette::HighlightedText); - } else { - fromBrush = pal.color(QPalette::Window); - titlePen = pal.color(QPalette::Text); - } - toBrush = fromBrush.lighter(300); - - painter->setPen(Qt::NoPen); - QPoint p1(titleRect.x(), titleRect.y() + titleRect.height()/2); - QPoint p2(titleRect.right(), titleRect.y() + titleRect.height()/2); - QLinearGradient lg(p1, p2); - lg.setColorAt(0, fromBrush); - lg.setColorAt(1, toBrush); - painter->fillRect(titleRect, lg); - - painter->setPen(titlePen); - painter->drawText(titleRect, Qt::AlignVCenter, windowTitleFor(widget)); - decorationRegion ^= Title; - } - - return QDecorationDefault::paint(painter, widget, decorationRegion, state); -} - -void QDecorationWindows::paintButton(QPainter *painter, const QWidget *widget, int buttonRegion, - DecorationState state, const QPalette &pal) -{ - QBrush fromBrush, toBrush; - QPen titlePen; - - if (widget == qApp->activeWindow() || qApp->activeWindow() == qApp->activePopupWidget()) { - fromBrush = pal.brush(QPalette::Highlight); - titlePen = pal.color(QPalette::HighlightedText); - } else { - fromBrush = pal.brush(QPalette::Window); - titlePen = pal.color(QPalette::Text); - } - toBrush = fromBrush.color().lighter(300); - - QRect brect(QDecoration::region(widget, buttonRegion).boundingRect()); - if (buttonRegion != Close && buttonRegion != Menu) - painter->fillRect(brect, toBrush); - else - painter->fillRect(brect.x() - 2, brect.y(), brect.width() + 4, brect.height(), - buttonRegion == Menu ? fromBrush : toBrush); - - int xoff = 1; - int yoff = 2; - const QPixmap pm = pixmapFor(widget, buttonRegion, xoff, yoff); - if (buttonRegion != Menu) { - if (state & Normal) { - qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(), - brect.height() - 4, pal, false, &pal.brush(QPalette::Window)); - } else if (state & Pressed) { - qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(), - brect.height() - 4, pal, true, &pal.brush(QPalette::Window)); - ++xoff; - ++yoff; - } - } else { - xoff = 0; - yoff = 2; - } - - if (!pm.isNull()) - painter->drawPixmap(brect.x() + xoff, brect.y() + yoff, pm); -} - -#endif // QT_NO_QWS_DECORATION_WINDOWS || QT_PLUGIN - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdecorationwindows_qws.h b/src/gui/embedded/qdecorationwindows_qws.h deleted file mode 100644 index 44213e6680..0000000000 --- a/src/gui/embedded/qdecorationwindows_qws.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECORATIONWINDOWS_QWS_H -#define QDECORATIONWINDOWS_QWS_H - -#include <QtGui/qdecorationdefault_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if !defined(QT_NO_QWS_DECORATION_WINDOWS) || defined(QT_PLUGIN) - -class Q_GUI_EXPORT QDecorationWindows : public QDecorationDefault -{ -public: - QDecorationWindows(); - virtual ~QDecorationWindows(); - - QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion = All); - bool paint(QPainter *painter, const QWidget *widget, int decorationRegion = All, - DecorationState state = Normal); - -protected: - void paintButton(QPainter *painter, const QWidget *widget, int buttonRegion, - DecorationState state, const QPalette &pal); - const char **xpmForRegion(int reg); -}; - -#endif // QT_NO_QWS_DECORATION_WINDOWS - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECORATIONWINDOWS_QWS_H diff --git a/src/gui/embedded/qdirectpainter_qws.cpp b/src/gui/embedded/qdirectpainter_qws.cpp deleted file mode 100644 index 47369947da..0000000000 --- a/src/gui/embedded/qdirectpainter_qws.cpp +++ /dev/null @@ -1,682 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdirectpainter_qws.h" - -#include "qscreen_qws.h" -#include "private/qobject_p.h" -#include "private/qapplication_p.h" -#include "qwsdisplay_qws.h" -#include "qwidget.h" -#include "qimage.h" -#include <qwsevent_qws.h> -#include <private/qwindowsurface_qws_p.h> -#include <private/qwsdisplay_qws_p.h> - -QT_BEGIN_NAMESPACE - -#ifdef Q_WS_QWS -#ifndef QT_NO_DIRECTPAINTER - -/*! - \class QDirectPainter - \ingroup painting - \ingroup qws - - \brief The QDirectPainter class provides direct access to the - underlying hardware in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QDirectPainter allows a client application to reserve a region of - the framebuffer and render directly onto the screen. There are two - ways of using the QDirectPainter class: You can either reserve a - region using the provided static functions, or you can instantiate - an object and make use of its more dynamic API. - - \tableofcontents - - \section1 Dynamic Allocation - - By instantiating a QDirectPainter object using the default - QDirectPainter::NonReserved surface flag, the client application - only gets some control over the reserved region, i.e., it can - still render directly onto the screen but the allocated region may - change (for example, if a window with a higher focus requests - parts of the same region). The currently allocated region can be - retrieved using the allocatedRegion() function, while the - requestedRegion() function returns the originally reserved - region. - - - \section1 Static Allocation - - - Using the static approach, the client application gets complete - control over the reserved region, i.e., the affected region will - never be modified by the screen driver. - - To create a static region, pass the QDirectPainter::Reserved - surface flag to the constructor. After the reserved region is - reported through regionChanged(), the allocated region will not - change, unless setRegion() is called. - - If QDirectPainter::ReservedSynchronous is passed to the - constructor, calls to setRegion() will block until the region is - reserved, meaning that allocatedRegion() will be available immediately. - Note that in the current version setRegion() will cause the application - event loop to be entered, potentially causing reentrancy issues. - - \section1 Rendering - - To draw on a given region, the application must first get hold of - a pointer to the framebuffer. In most cases, this pointer can be - retrieved using the QDirectPainter::frameBuffer() function. But - note that if the current screen has subscreens, you must query the - screen driver instead to identify the correct subscreen. A pointer - to the current screen driver can always be retrieved using the - static QScreen::instance() function. Then use QScreen's \l - {QScreen::}{subScreenIndexAt()} and \l {QScreen::}{subScreens()} - functions to access the correct subscreen, and the subscreen's \l - {QScreen::}{base()} function to retrieve a pointer to the - framebuffer. - - Depending on the hardware, it might be necessary to lock the - framebuffer for exclusive use while writing to it. This is - possible using the lock() and unlock() functions. Note that - calling lock() will prevent all other applications from working - until unlock() is called. - - In addition, QDirectPainter provides several functions returning - information about the framebuffer: the linestep() function returns - the length (in bytes) of each scanline of the framebuffer while - the screenDepth(), screenWidth() and screenHeight() function - return the screen metrics. - - \sa QScreen, QWSEmbedWidget, {Qt for Embedded Linux Architecture} -*/ - -/*! - \enum QDirectPainter::SurfaceFlag - - This enum describes the behavior of the region reserved by this - QDirectPainter object. - - \value NonReserved The allocated region may change, e.g., if a - window with a higher focus requests parts of the same region. See - also \l {Dynamic Allocation}. - - \value Reserved The allocated region will never change. See also - \l {Static Allocation}. - - \value ReservedSynchronous The allocated region will never change and - each function that changes the allocated region will be blocking. - - \sa allocatedRegion() -*/ - -/*! - \fn QRegion QDirectPainter::region() - \obsolete - - Use QDirectPainter::allocatedRegion() instead. -*/ - -static inline QScreen *getPrimaryScreen() -{ - QScreen *screen = QScreen::instance(); - if (!screen->base()) { - QList<QScreen*> subScreens = screen->subScreens(); - if (subScreens.size() < 1) - return 0; - screen = subScreens.at(0); - } - return screen; -} - -static inline QSize screenS() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return QSize(); - return QSize(screen->width(), screen->height()); -} - -static inline QSize devS() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return QSize(); - return QSize(screen->deviceWidth(), screen->deviceHeight()); -} - - -class QDirectPainterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDirectPainter); -public: - - QDirectPainterPrivate() : surface(0), seenRegion(false) {} - - ~QDirectPainterPrivate() { - if (QPaintDevice::qwsDisplay()) { // make sure not in QApplication destructor - qApp->d_func()->directPainters->remove(surface->windowId()); - surface->setGeometry(QRect()); - } - delete surface; - } - - QWSDirectPainterSurface *surface; - QRegion requested_region; - - static QDirectPainter *staticPainter; - bool seenRegion; -}; - -QDirectPainter *QDirectPainterPrivate::staticPainter = 0; - -void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type) -{ - QDirectPainterPrivate *d = dp->d_func(); - - QRegion r = alloc; - QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize screenSize(screen->width(), screen->height()); - r = screen->mapToDevice(r, screenSize); - } - if (type == QWSRegionEvent::Allocation) { - d->surface->setClipRegion(alloc); - d->seenRegion = true; - if (dp != QDirectPainterPrivate::staticPainter) { - if (!d->surface->flushingRegionEvents) // recursion guard - dp->regionChanged(r); - } - } -} - -#ifndef QT_NO_QWSEMBEDWIDGET -void qt_directpainter_embedevent(QDirectPainter *dp, const QWSEmbedEvent *event) -{ - if (event->type | QWSEmbedEvent::Region) { - QScreen *screen = dp->d_func()->surface->screen(); - QRegion r = event->region; - if (screen->isTransformed()) { - const QSize screenSize(screen->width(), screen->height()); - r = screen->mapToDevice(r, screenSize); - } - dp->setRegion(r); - } -} -#endif - -/*! - Constructs a QDirectPainter object with the given \a parent and - surface \a flag. -*/ -QDirectPainter::QDirectPainter(QObject *parent, SurfaceFlag flag) - :QObject(*new QDirectPainterPrivate, parent) -{ - Q_D(QDirectPainter); - d->surface = new QWSDirectPainterSurface(true, flag); - - if (flag != NonReserved) - d->surface->setReserved(); - - QApplicationPrivate *ad = qApp->d_func(); - if (!ad->directPainters) - ad->directPainters = new QMap<WId, QDirectPainter*>; - ad->directPainters->insert(d->surface->windowId(), this); -} - -/*! - Destroys this QDirectPainter object, releasing the reserved region. - - \sa allocatedRegion() -*/ -QDirectPainter::~QDirectPainter() -{ - /* should not be necessary - if (this == QDirectPainterPrivate::staticPainter) - QDirectPainterPrivate::staticPainter = 0; - */ -} - -/*! - \fn void QDirectPainter::setGeometry(const QRect &rectangle) - \since 4.2 - - Request to reserve the given \a rectangle of the framebuffer. - - Note that the actually allocated region might differ from the - requested one, e.g., if the given region overlaps with the - region of another QDirectPainter object. - - \sa geometry(), allocatedRegion(), setRegion() -*/ -void QDirectPainter::setGeometry(const QRect &rect) -{ - setRegion(rect); -} - -/*! - \since 4.2 - - Returns the bounding rectangle of the requested region. - - \sa setGeometry(), requestedRegion() -*/ -QRect QDirectPainter::geometry() const -{ - Q_D(const QDirectPainter); - return d->requested_region.boundingRect(); -} - -/*! - \since 4.2 - - Requests to reserve the given \a region of the framebuffer. - - Note that the actually allocated region might differ from the - requested one, e.g., if the given region overlaps with the region - of another QDirectPainter object. - - \sa requestedRegion(), allocatedRegion(), {Dynamic Allocation} -*/ -void QDirectPainter::setRegion(const QRegion ®ion) -{ - Q_D(QDirectPainter); - d->requested_region = region; - - const QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize devSize(screen->deviceWidth(), screen->deviceHeight()); - const QRegion r = screen->mapFromDevice(region, devSize); - d->surface->setRegion(r); - } else { - d->surface->setRegion(region); - } -} - -/*! - \since 4.2 - - Returns the region requested by this QDirectPainter. - - Note that if the QDirectPainter::Reserved flag is set, the region - returned by this function will always be equivalent to the region - returned by the allocatedRegion() function. Otherwise they might - differ (see \l {Dynamic Allocation} for details). - - \sa geometry(), setRegion(), allocatedRegion() -*/ -QRegion QDirectPainter::requestedRegion() const -{ - Q_D(const QDirectPainter); - return d->requested_region; -} - -/*! - \since 4.2 - - Returns the currently reserved region. - - Note that if the QDirectPainter::Reserved flag is set, the region - returned by this function will always be equivalent to the region - returned by the requestedRegion() function. Otherwise they might - differ (see \l {Dynamic Allocation} for details). - - \sa requestedRegion(), geometry() -*/ -QRegion QDirectPainter::allocatedRegion() const -{ - Q_D(const QDirectPainter); - const QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize screenSize(screen->width(), screen->height()); - return screen->mapToDevice(d->surface->region(), screenSize); - } else { - return d->surface->region(); - } -} - -/*! - \since 4.2 - - Returns the window system identifier of the widget. -*/ -WId QDirectPainter::winId() const -{ - Q_D(const QDirectPainter); - return d->surface->windowId(); -} - -/*! - \fn void QDirectPainter::regionChanged(const QRegion &newRegion) - \since 4.2 - - This function is called when the allocated region changes. - - This function is not called for region changes that happen while the - startPainting() function is executing. - - Note that the given region, \a newRegion, is not guaranteed to be correct at the - time you access the display. To prevent reentrancy problems you should - always call startPainting() before updating the display and then use - allocatedRegion() to retrieve the correct region. - - \sa allocatedRegion(), startPainting(), {Dynamic Allocation} -*/ -void QDirectPainter::regionChanged(const QRegion ®ion) -{ - Q_UNUSED(region); -} - -/*! - \since 4.2 - - Call this function before you start updating the pixels in the - allocated region. The hardware will be notified, if necessary, - that you are about to start painting operations. - - Set \a lockDisplay if you want startPainting() and endPainting() - to lock() and unlock() the display automatically. - - Note that for a NonReserved direct painter, you must call - allocatedRegion() after calling this function, since the allocated - region is only guaranteed to be correct after this function has - returned. - - The regionChanged() function will not be called between startPainting() - and endPainting(). - - \sa endPainting(), flush() -*/ -void QDirectPainter::startPainting(bool lockDisplay) -{ - Q_D(QDirectPainter); - d->surface->setLocking(lockDisplay); - - const QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize devSize(screen->deviceWidth(), screen->deviceHeight()); - const QRegion r = screen->mapFromDevice(d->surface->region(), devSize); - d->surface->beginPaint(r); - } else { - d->surface->beginPaint(d->surface->region()); - } -} - -/*! - \since 4.2 - - Call this function when you are done updating the screen. It will - notify the hardware, if necessary, that your painting operations - have ended. -*/ -void QDirectPainter::endPainting() -{ - Q_D(QDirectPainter); - - const QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize devSize(screen->deviceWidth(), screen->deviceHeight()); - const QRegion r = screen->mapFromDevice(d->surface->region(), devSize); - d->surface->endPaint(r); - } else { - d->surface->endPaint(d->surface->region()); - } -} - -/*! - \since 4.3 - \overload - - This function will automatically call flush() to flush the - \a region to the display before notifying the hardware, if - necessary, that painting operations have ended. -*/ -void QDirectPainter::endPainting(const QRegion ®ion) -{ - endPainting(); - flush(region); -} - -/*! - \since 4.3 - - Flushes the \a region onto the screen. -*/ -void QDirectPainter::flush(const QRegion ®ion) -{ - Q_D(QDirectPainter); - - const QScreen *screen = d->surface->screen(); - if (screen->isTransformed()) { - const QSize devSize(screen->deviceWidth(), screen->deviceHeight()); - const QRegion r = screen->mapFromDevice(region, devSize); - d->surface->flush(0, r, QPoint()); - } else { - d->surface->flush(0, region, QPoint()); - } -} - -/*! - \since 4.2 - - Raises the reserved region to the top of the widget stack. - - After this call the reserved region will be visually in front of - any overlapping widgets. - - \sa lower(), requestedRegion() -*/ -void QDirectPainter::raise() -{ - QWidget::qwsDisplay()->setAltitude(winId(),QWSChangeAltitudeCommand::Raise); -} - -/*! - \since 4.2 - - Lowers the reserved region to the bottom of the widget stack. - - After this call the reserved region will be visually behind (and - therefore obscured by) any overlapping widgets. - - \sa raise(), requestedRegion() -*/ -void QDirectPainter::lower() -{ - QWidget::qwsDisplay()->setAltitude(winId(),QWSChangeAltitudeCommand::Lower); -} - - -/*! - \fn QRegion QDirectPainter::reserveRegion(const QRegion ®ion) - - Attempts to reserve the \a region and returns the region that is - actually reserved. - - This function also releases the previously reserved region if - any. If not released explicitly, the region will be released on - application exit. - - \sa allocatedRegion(), {Static Allocation} - - \obsolete - - Construct a QDirectPainter using QDirectPainter::ReservedSynchronous instead. -*/ -QRegion QDirectPainter::reserveRegion(const QRegion ®) -{ - if (!QDirectPainterPrivate::staticPainter) - QDirectPainterPrivate::staticPainter = new QDirectPainter(qApp, ReservedSynchronous); - - QDirectPainter *dp = QDirectPainterPrivate::staticPainter; - dp->setRegion(reg); - - return dp->allocatedRegion(); -} - -/*! - Returns a pointer to the beginning of the display memory. - - Note that it is the application's responsibility to limit itself - to modifying only the reserved region. - - Do not use this pointer if the current screen has subscreens, - query the screen driver instead: A pointer to the current screen - driver can always be retrieved using the static - QScreen::instance() function. Then use QScreen's \l - {QScreen::}{subScreenIndexAt()} and \l {QScreen::}{subScreens()} - functions to access the correct subscreen, and the subscreen's \l - {QScreen::}{base()} function to retrieve a pointer to the - framebuffer. - - \sa requestedRegion(), allocatedRegion(), linestep() -*/ -uchar* QDirectPainter::frameBuffer() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return 0; - return screen->base(); -} - -/*! - \since 4.2 - - Returns the reserved region. - - \sa reserveRegion(), frameBuffer() - - \obsolete - - Use allocatedRegion() instead. -*/ -QRegion QDirectPainter::reservedRegion() -{ - return QDirectPainterPrivate::staticPainter - ? QDirectPainterPrivate::staticPainter->allocatedRegion() : QRegion(); -} - -/*! - Returns the bit depth of the display. - - \sa screenHeight(), screenWidth() -*/ -int QDirectPainter::screenDepth() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return 0; - return screen->depth(); -} - -/*! - Returns the width of the display in pixels. - - \sa screenHeight(), screenDepth() -*/ -int QDirectPainter::screenWidth() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return 0; - return screen->deviceWidth(); -} - -/*! - Returns the height of the display in pixels. - - \sa screenWidth(), screenDepth() -*/ -int QDirectPainter::screenHeight() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return 0; - return screen->deviceHeight(); -} - -/*! - Returns the length (in bytes) of each scanline of the framebuffer. - - \sa frameBuffer() -*/ -int QDirectPainter::linestep() -{ - QScreen *screen = getPrimaryScreen(); - if (!screen) - return 0; - return screen->linestep(); -} - - -/*! - Locks access to the framebuffer. - - Note that calling this function will prevent all other - applications from updating the display until unlock() is called. - - \sa unlock() -*/ -void QDirectPainter::lock() -{ - QWSDisplay::grab(true); -} -/*! - Unlocks the lock on the framebuffer (set using the lock() - function), allowing other applications to access the screen. - - \sa lock() - */ -void QDirectPainter::unlock() -{ - QWSDisplay::ungrab(); -} - -#endif //QT_NO_DIRECTPAINTER - -#endif - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qdirectpainter_qws.h b/src/gui/embedded/qdirectpainter_qws.h deleted file mode 100644 index 47cc721d49..0000000000 --- a/src/gui/embedded/qdirectpainter_qws.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDIRECTPAINTER_QWS_H -#define QDIRECTPAINTER_QWS_H - -#include <QtCore/qobject.h> -#include <QtGui/qregion.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_DIRECTPAINTER -class QDirectPainterPrivate; -class QWSEmbedEvent; - -class Q_GUI_EXPORT QDirectPainter : public QObject { - Q_OBJECT - Q_DECLARE_PRIVATE(QDirectPainter) -public: - - enum SurfaceFlag { NonReserved = 0, - Reserved = 1, - ReservedSynchronous = 3 }; - - explicit QDirectPainter(QObject *parentObject = 0, SurfaceFlag flag = NonReserved); - ~QDirectPainter(); - - void setRegion(const QRegion&); - QRegion requestedRegion() const; - QRegion allocatedRegion() const; - - void setGeometry(const QRect&); - QRect geometry() const; - - WId winId() const; - virtual void regionChanged(const QRegion &exposedRegion); - - void startPainting(bool lockDisplay = true); - void endPainting(); - void endPainting(const QRegion ®ion); - void flush(const QRegion ®ion); - - void raise(); - void lower(); - - - static QRegion reserveRegion(const QRegion&); - static QRegion reservedRegion(); - static QRegion region() { return reservedRegion(); } - - static uchar* frameBuffer(); - static int screenDepth(); - static int screenWidth(); - static int screenHeight(); - static int linestep(); - - static void lock(); - static void unlock(); -private: - friend void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type); - friend void qt_directpainter_embedevent(QDirectPainter*, const QWSEmbedEvent*); -}; - -#endif - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDIRECTPAINTER_QWS_H diff --git a/src/gui/embedded/qkbd_defaultmap_qws_p.h b/src/gui/embedded/qkbd_defaultmap_qws_p.h deleted file mode 100644 index 017f56deb6..0000000000 --- a/src/gui/embedded/qkbd_defaultmap_qws_p.h +++ /dev/null @@ -1,806 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSKEYBOARDHANDLER_DEFAULTMAP_H -#define QWSKEYBOARDHANDLER_DEFAULTMAP_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -// no QT_BEGIN_NAMESPACE, since we include it internally... - -const QWSKeyboard::Mapping QWSKbPrivate::s_keymap_default[] = { - { 1, 0xffff, 0x01000000, 0x00, 0x00, 0x0000 }, - { 2, 0x0031, 0x00000031, 0x00, 0x00, 0x0000 }, - { 2, 0x0021, 0x00000021, 0x01, 0x00, 0x0000 }, - { 3, 0x0032, 0x00000032, 0x00, 0x00, 0x0000 }, - { 3, 0x0040, 0x00000040, 0x01, 0x00, 0x0000 }, - { 3, 0x0040, 0x00000040, 0x02, 0x00, 0x0000 }, - { 4, 0x0033, 0x00000033, 0x00, 0x00, 0x0000 }, - { 4, 0x0023, 0x00000023, 0x01, 0x00, 0x0000 }, - { 4, 0xffff, 0x01000000, 0x04, 0x00, 0x0000 }, - { 5, 0x0034, 0x00000034, 0x00, 0x00, 0x0000 }, - { 5, 0x0024, 0x00000024, 0x01, 0x00, 0x0000 }, - { 5, 0x0024, 0x00000024, 0x02, 0x00, 0x0000 }, - { 5, 0x005c, 0x0400005c, 0x04, 0x00, 0x0000 }, - { 6, 0x0035, 0x00000035, 0x00, 0x00, 0x0000 }, - { 6, 0x0025, 0x00000025, 0x01, 0x00, 0x0000 }, - { 6, 0x005d, 0x0400005d, 0x04, 0x00, 0x0000 }, - { 7, 0x0036, 0x00000036, 0x00, 0x00, 0x0000 }, - { 7, 0x005e, 0x0000005e, 0x01, 0x00, 0x0000 }, - { 7, 0x005e, 0x01001252, 0x02, 0x01, 0x0000 }, - { 7, 0x005e, 0x0400005e, 0x04, 0x00, 0x0000 }, - { 8, 0x0037, 0x00000037, 0x00, 0x00, 0x0000 }, - { 8, 0x0026, 0x00000026, 0x01, 0x00, 0x0000 }, - { 8, 0x007b, 0x0000007b, 0x02, 0x00, 0x0000 }, - { 8, 0x005f, 0x0400005f, 0x04, 0x00, 0x0000 }, - { 9, 0x0038, 0x00000038, 0x00, 0x00, 0x0000 }, - { 9, 0x002a, 0x0000002a, 0x01, 0x00, 0x0000 }, - { 9, 0x005b, 0x0000005b, 0x02, 0x00, 0x0000 }, - { 9, 0xffff, 0x01000003, 0x04, 0x00, 0x0000 }, - { 10, 0x0039, 0x00000039, 0x00, 0x00, 0x0000 }, - { 10, 0x0028, 0x00000028, 0x01, 0x00, 0x0000 }, - { 10, 0x005d, 0x0000005d, 0x02, 0x00, 0x0000 }, - { 11, 0x0030, 0x00000030, 0x00, 0x00, 0x0000 }, - { 11, 0x0029, 0x00000029, 0x01, 0x00, 0x0000 }, - { 11, 0x007d, 0x0000007d, 0x02, 0x00, 0x0000 }, - { 12, 0x002d, 0x0000002d, 0x00, 0x00, 0x0000 }, - { 12, 0x005f, 0x0000005f, 0x01, 0x00, 0x0000 }, - { 12, 0x005c, 0x0000005c, 0x02, 0x00, 0x0000 }, - { 12, 0x005f, 0x0400005f, 0x04, 0x00, 0x0000 }, - { 12, 0x005f, 0x0400005f, 0x05, 0x00, 0x0000 }, - { 13, 0x003d, 0x0000003d, 0x00, 0x00, 0x0000 }, - { 13, 0x002b, 0x0000002b, 0x01, 0x00, 0x0000 }, - { 14, 0xffff, 0x01000003, 0x00, 0x00, 0x0000 }, - { 14, 0xffff, 0x01000000, 0x0c, 0x08, 0x0300 }, - { 15, 0xffff, 0x01000001, 0x00, 0x00, 0x0000 }, - { 16, 0x0071, 0x00000051, 0x00, 0x00, 0x0000 }, - { 16, 0x0051, 0x00000051, 0x01, 0x00, 0x0000 }, - { 16, 0x0071, 0x00000051, 0x02, 0x00, 0x0000 }, - { 16, 0x0051, 0x00000051, 0x03, 0x00, 0x0000 }, - { 16, 0x0071, 0x04000051, 0x04, 0x00, 0x0000 }, - { 16, 0x0071, 0x04000051, 0x05, 0x00, 0x0000 }, - { 16, 0x0071, 0x04000051, 0x06, 0x00, 0x0000 }, - { 16, 0x0071, 0x04000051, 0x07, 0x00, 0x0000 }, - { 16, 0x0071, 0x08000051, 0x08, 0x00, 0x0000 }, - { 16, 0x0071, 0x08000051, 0x09, 0x00, 0x0000 }, - { 16, 0x0071, 0x08000051, 0x0a, 0x00, 0x0000 }, - { 16, 0x0071, 0x08000051, 0x0b, 0x00, 0x0000 }, - { 16, 0x0071, 0x0c000051, 0x0c, 0x00, 0x0000 }, - { 16, 0x0071, 0x0c000051, 0x0d, 0x00, 0x0000 }, - { 16, 0x0071, 0x0c000051, 0x0e, 0x00, 0x0000 }, - { 16, 0x0071, 0x0c000051, 0x0f, 0x00, 0x0000 }, - { 17, 0x0077, 0x00000057, 0x00, 0x00, 0x0000 }, - { 17, 0x0057, 0x00000057, 0x01, 0x00, 0x0000 }, - { 17, 0x0077, 0x00000057, 0x02, 0x00, 0x0000 }, - { 17, 0x0057, 0x00000057, 0x03, 0x00, 0x0000 }, - { 17, 0x0077, 0x04000057, 0x04, 0x00, 0x0000 }, - { 17, 0x0077, 0x04000057, 0x05, 0x00, 0x0000 }, - { 17, 0x0077, 0x04000057, 0x06, 0x00, 0x0000 }, - { 17, 0x0077, 0x04000057, 0x07, 0x00, 0x0000 }, - { 17, 0x0077, 0x08000057, 0x08, 0x00, 0x0000 }, - { 17, 0x0077, 0x08000057, 0x09, 0x00, 0x0000 }, - { 17, 0x0077, 0x08000057, 0x0a, 0x00, 0x0000 }, - { 17, 0x0077, 0x08000057, 0x0b, 0x00, 0x0000 }, - { 17, 0x0077, 0x0c000057, 0x0c, 0x00, 0x0000 }, - { 17, 0x0077, 0x0c000057, 0x0d, 0x00, 0x0000 }, - { 17, 0x0077, 0x0c000057, 0x0e, 0x00, 0x0000 }, - { 17, 0x0077, 0x0c000057, 0x0f, 0x00, 0x0000 }, - { 18, 0x0065, 0x00000045, 0x00, 0x00, 0x0000 }, - { 18, 0x0045, 0x00000045, 0x01, 0x00, 0x0000 }, - { 18, 0x0065, 0x00000045, 0x02, 0x00, 0x0000 }, - { 18, 0x0045, 0x00000045, 0x03, 0x00, 0x0000 }, - { 18, 0x0065, 0x04000045, 0x04, 0x00, 0x0000 }, - { 18, 0x0065, 0x04000045, 0x05, 0x00, 0x0000 }, - { 18, 0x0065, 0x04000045, 0x06, 0x00, 0x0000 }, - { 18, 0x0065, 0x04000045, 0x07, 0x00, 0x0000 }, - { 18, 0x0065, 0x08000045, 0x08, 0x00, 0x0000 }, - { 18, 0x0065, 0x08000045, 0x09, 0x00, 0x0000 }, - { 18, 0x0065, 0x08000045, 0x0a, 0x00, 0x0000 }, - { 18, 0x0065, 0x08000045, 0x0b, 0x00, 0x0000 }, - { 18, 0x0065, 0x0c000045, 0x0c, 0x00, 0x0000 }, - { 18, 0x0065, 0x0c000045, 0x0d, 0x00, 0x0000 }, - { 18, 0x0065, 0x0c000045, 0x0e, 0x00, 0x0000 }, - { 18, 0x0065, 0x0c000045, 0x0f, 0x00, 0x0000 }, - { 19, 0x0072, 0x00000052, 0x00, 0x00, 0x0000 }, - { 19, 0x0052, 0x00000052, 0x01, 0x00, 0x0000 }, - { 19, 0x0072, 0x00000052, 0x02, 0x00, 0x0000 }, - { 19, 0x0052, 0x00000052, 0x03, 0x00, 0x0000 }, - { 19, 0x0072, 0x04000052, 0x04, 0x00, 0x0000 }, - { 19, 0x0072, 0x04000052, 0x05, 0x00, 0x0000 }, - { 19, 0x0072, 0x04000052, 0x06, 0x00, 0x0000 }, - { 19, 0x0072, 0x04000052, 0x07, 0x00, 0x0000 }, - { 19, 0x0072, 0x08000052, 0x08, 0x00, 0x0000 }, - { 19, 0x0072, 0x08000052, 0x09, 0x00, 0x0000 }, - { 19, 0x0072, 0x08000052, 0x0a, 0x00, 0x0000 }, - { 19, 0x0072, 0x08000052, 0x0b, 0x00, 0x0000 }, - { 19, 0x0072, 0x0c000052, 0x0c, 0x00, 0x0000 }, - { 19, 0x0072, 0x0c000052, 0x0d, 0x00, 0x0000 }, - { 19, 0x0072, 0x0c000052, 0x0e, 0x00, 0x0000 }, - { 19, 0x0072, 0x0c000052, 0x0f, 0x00, 0x0000 }, - { 20, 0x0074, 0x00000054, 0x00, 0x00, 0x0000 }, - { 20, 0x0054, 0x00000054, 0x01, 0x00, 0x0000 }, - { 20, 0x0074, 0x00000054, 0x02, 0x00, 0x0000 }, - { 20, 0x0054, 0x00000054, 0x03, 0x00, 0x0000 }, - { 20, 0x0074, 0x04000054, 0x04, 0x00, 0x0000 }, - { 20, 0x0074, 0x04000054, 0x05, 0x00, 0x0000 }, - { 20, 0x0074, 0x04000054, 0x06, 0x00, 0x0000 }, - { 20, 0x0074, 0x04000054, 0x07, 0x00, 0x0000 }, - { 20, 0x0074, 0x08000054, 0x08, 0x00, 0x0000 }, - { 20, 0x0074, 0x08000054, 0x09, 0x00, 0x0000 }, - { 20, 0x0074, 0x08000054, 0x0a, 0x00, 0x0000 }, - { 20, 0x0074, 0x08000054, 0x0b, 0x00, 0x0000 }, - { 20, 0x0074, 0x0c000054, 0x0c, 0x00, 0x0000 }, - { 20, 0x0074, 0x0c000054, 0x0d, 0x00, 0x0000 }, - { 20, 0x0074, 0x0c000054, 0x0e, 0x00, 0x0000 }, - { 20, 0x0074, 0x0c000054, 0x0f, 0x00, 0x0000 }, - { 21, 0x0079, 0x00000059, 0x00, 0x00, 0x0000 }, - { 21, 0x0059, 0x00000059, 0x01, 0x00, 0x0000 }, - { 21, 0x0079, 0x00000059, 0x02, 0x00, 0x0000 }, - { 21, 0x0059, 0x00000059, 0x03, 0x00, 0x0000 }, - { 21, 0x0079, 0x04000059, 0x04, 0x00, 0x0000 }, - { 21, 0x0079, 0x04000059, 0x05, 0x00, 0x0000 }, - { 21, 0x0079, 0x04000059, 0x06, 0x00, 0x0000 }, - { 21, 0x0079, 0x04000059, 0x07, 0x00, 0x0000 }, - { 21, 0x0079, 0x08000059, 0x08, 0x00, 0x0000 }, - { 21, 0x0079, 0x08000059, 0x09, 0x00, 0x0000 }, - { 21, 0x0079, 0x08000059, 0x0a, 0x00, 0x0000 }, - { 21, 0x0079, 0x08000059, 0x0b, 0x00, 0x0000 }, - { 21, 0x0079, 0x0c000059, 0x0c, 0x00, 0x0000 }, - { 21, 0x0079, 0x0c000059, 0x0d, 0x00, 0x0000 }, - { 21, 0x0079, 0x0c000059, 0x0e, 0x00, 0x0000 }, - { 21, 0x0079, 0x0c000059, 0x0f, 0x00, 0x0000 }, - { 22, 0x0075, 0x00000055, 0x00, 0x00, 0x0000 }, - { 22, 0x0055, 0x00000055, 0x01, 0x00, 0x0000 }, - { 22, 0x0075, 0x00000055, 0x02, 0x00, 0x0000 }, - { 22, 0x0055, 0x00000055, 0x03, 0x00, 0x0000 }, - { 22, 0x0075, 0x04000055, 0x04, 0x00, 0x0000 }, - { 22, 0x0075, 0x04000055, 0x05, 0x00, 0x0000 }, - { 22, 0x0075, 0x04000055, 0x06, 0x00, 0x0000 }, - { 22, 0x0075, 0x04000055, 0x07, 0x00, 0x0000 }, - { 22, 0x0075, 0x08000055, 0x08, 0x00, 0x0000 }, - { 22, 0x0075, 0x08000055, 0x09, 0x00, 0x0000 }, - { 22, 0x0075, 0x08000055, 0x0a, 0x00, 0x0000 }, - { 22, 0x0075, 0x08000055, 0x0b, 0x00, 0x0000 }, - { 22, 0x0075, 0x0c000055, 0x0c, 0x00, 0x0000 }, - { 22, 0x0075, 0x0c000055, 0x0d, 0x00, 0x0000 }, - { 22, 0x0075, 0x0c000055, 0x0e, 0x00, 0x0000 }, - { 22, 0x0075, 0x0c000055, 0x0f, 0x00, 0x0000 }, - { 23, 0x0069, 0x00000049, 0x00, 0x00, 0x0000 }, - { 23, 0x0049, 0x00000049, 0x01, 0x00, 0x0000 }, - { 23, 0x0069, 0x00000049, 0x02, 0x00, 0x0000 }, - { 23, 0x0049, 0x00000049, 0x03, 0x00, 0x0000 }, - { 23, 0x0069, 0x04000049, 0x04, 0x00, 0x0000 }, - { 23, 0x0069, 0x04000049, 0x05, 0x00, 0x0000 }, - { 23, 0x0069, 0x04000049, 0x06, 0x00, 0x0000 }, - { 23, 0x0069, 0x04000049, 0x07, 0x00, 0x0000 }, - { 23, 0x0069, 0x08000049, 0x08, 0x00, 0x0000 }, - { 23, 0x0069, 0x08000049, 0x09, 0x00, 0x0000 }, - { 23, 0x0069, 0x08000049, 0x0a, 0x00, 0x0000 }, - { 23, 0x0069, 0x08000049, 0x0b, 0x00, 0x0000 }, - { 23, 0x0069, 0x0c000049, 0x0c, 0x00, 0x0000 }, - { 23, 0x0069, 0x0c000049, 0x0d, 0x00, 0x0000 }, - { 23, 0x0069, 0x0c000049, 0x0e, 0x00, 0x0000 }, - { 23, 0x0069, 0x0c000049, 0x0f, 0x00, 0x0000 }, - { 24, 0x006f, 0x0000004f, 0x00, 0x00, 0x0000 }, - { 24, 0x004f, 0x0000004f, 0x01, 0x00, 0x0000 }, - { 24, 0x006f, 0x0000004f, 0x02, 0x00, 0x0000 }, - { 24, 0x004f, 0x0000004f, 0x03, 0x00, 0x0000 }, - { 24, 0x006f, 0x0400004f, 0x04, 0x00, 0x0000 }, - { 24, 0x006f, 0x0400004f, 0x05, 0x00, 0x0000 }, - { 24, 0x006f, 0x0400004f, 0x06, 0x00, 0x0000 }, - { 24, 0x006f, 0x0400004f, 0x07, 0x00, 0x0000 }, - { 24, 0x006f, 0x0800004f, 0x08, 0x00, 0x0000 }, - { 24, 0x006f, 0x0800004f, 0x09, 0x00, 0x0000 }, - { 24, 0x006f, 0x0800004f, 0x0a, 0x00, 0x0000 }, - { 24, 0x006f, 0x0800004f, 0x0b, 0x00, 0x0000 }, - { 24, 0x006f, 0x0c00004f, 0x0c, 0x00, 0x0000 }, - { 24, 0x006f, 0x0c00004f, 0x0d, 0x00, 0x0000 }, - { 24, 0x006f, 0x0c00004f, 0x0e, 0x00, 0x0000 }, - { 24, 0x006f, 0x0c00004f, 0x0f, 0x00, 0x0000 }, - { 25, 0x0070, 0x00000050, 0x00, 0x00, 0x0000 }, - { 25, 0x0050, 0x00000050, 0x01, 0x00, 0x0000 }, - { 25, 0x0070, 0x00000050, 0x02, 0x00, 0x0000 }, - { 25, 0x0050, 0x00000050, 0x03, 0x00, 0x0000 }, - { 25, 0x0070, 0x04000050, 0x04, 0x00, 0x0000 }, - { 25, 0x0070, 0x04000050, 0x05, 0x00, 0x0000 }, - { 25, 0x0070, 0x04000050, 0x06, 0x00, 0x0000 }, - { 25, 0x0070, 0x04000050, 0x07, 0x00, 0x0000 }, - { 25, 0x0070, 0x08000050, 0x08, 0x00, 0x0000 }, - { 25, 0x0070, 0x08000050, 0x09, 0x00, 0x0000 }, - { 25, 0x0070, 0x08000050, 0x0a, 0x00, 0x0000 }, - { 25, 0x0070, 0x08000050, 0x0b, 0x00, 0x0000 }, - { 25, 0x0070, 0x0c000050, 0x0c, 0x00, 0x0000 }, - { 25, 0x0070, 0x0c000050, 0x0d, 0x00, 0x0000 }, - { 25, 0x0070, 0x0c000050, 0x0e, 0x00, 0x0000 }, - { 25, 0x0070, 0x0c000050, 0x0f, 0x00, 0x0000 }, - { 26, 0x005b, 0x0000005b, 0x00, 0x00, 0x0000 }, - { 26, 0x007b, 0x0000007b, 0x01, 0x00, 0x0000 }, - { 26, 0xffff, 0x01000000, 0x04, 0x00, 0x0000 }, - { 27, 0x005d, 0x0000005d, 0x00, 0x00, 0x0000 }, - { 27, 0x007d, 0x0000007d, 0x01, 0x00, 0x0000 }, - { 27, 0x007e, 0x0000007e, 0x02, 0x00, 0x0000 }, - { 27, 0x005d, 0x0400005d, 0x04, 0x00, 0x0000 }, - { 28, 0xffff, 0x01000004, 0x00, 0x00, 0x0000 }, - { 28, 0x006d, 0x0c00004d, 0x08, 0x00, 0x0000 }, - { 29, 0xffff, 0x01000021, 0x00, 0x04, 0x0004 }, - { 30, 0x0061, 0x00000041, 0x00, 0x00, 0x0000 }, - { 30, 0x0041, 0x00000041, 0x01, 0x00, 0x0000 }, - { 30, 0x0061, 0x00000041, 0x02, 0x00, 0x0000 }, - { 30, 0x0041, 0x00000041, 0x03, 0x00, 0x0000 }, - { 30, 0x0061, 0x04000041, 0x04, 0x00, 0x0000 }, - { 30, 0x0061, 0x04000041, 0x05, 0x00, 0x0000 }, - { 30, 0x0061, 0x04000041, 0x06, 0x00, 0x0000 }, - { 30, 0x0061, 0x04000041, 0x07, 0x00, 0x0000 }, - { 30, 0x0061, 0x08000041, 0x08, 0x00, 0x0000 }, - { 30, 0x0061, 0x08000041, 0x09, 0x00, 0x0000 }, - { 30, 0x0061, 0x08000041, 0x0a, 0x00, 0x0000 }, - { 30, 0x0061, 0x08000041, 0x0b, 0x00, 0x0000 }, - { 30, 0x0061, 0x0c000041, 0x0c, 0x00, 0x0000 }, - { 30, 0x0061, 0x0c000041, 0x0d, 0x00, 0x0000 }, - { 30, 0x0061, 0x0c000041, 0x0e, 0x00, 0x0000 }, - { 30, 0x0061, 0x0c000041, 0x0f, 0x00, 0x0000 }, - { 31, 0x0073, 0x00000053, 0x00, 0x00, 0x0000 }, - { 31, 0x0053, 0x00000053, 0x01, 0x00, 0x0000 }, - { 31, 0x0073, 0x00000053, 0x02, 0x00, 0x0000 }, - { 31, 0x0053, 0x00000053, 0x03, 0x00, 0x0000 }, - { 31, 0x0073, 0x04000053, 0x04, 0x00, 0x0000 }, - { 31, 0x0073, 0x04000053, 0x05, 0x00, 0x0000 }, - { 31, 0x0073, 0x04000053, 0x06, 0x00, 0x0000 }, - { 31, 0x0073, 0x04000053, 0x07, 0x00, 0x0000 }, - { 31, 0x0073, 0x08000053, 0x08, 0x00, 0x0000 }, - { 31, 0x0073, 0x08000053, 0x09, 0x00, 0x0000 }, - { 31, 0x0073, 0x08000053, 0x0a, 0x00, 0x0000 }, - { 31, 0x0073, 0x08000053, 0x0b, 0x00, 0x0000 }, - { 31, 0x0073, 0x0c000053, 0x0c, 0x00, 0x0000 }, - { 31, 0x0073, 0x0c000053, 0x0d, 0x00, 0x0000 }, - { 31, 0x0073, 0x0c000053, 0x0e, 0x00, 0x0000 }, - { 31, 0x0073, 0x0c000053, 0x0f, 0x00, 0x0000 }, - { 32, 0x0064, 0x00000044, 0x00, 0x00, 0x0000 }, - { 32, 0x0044, 0x00000044, 0x01, 0x00, 0x0000 }, - { 32, 0x0064, 0x00000044, 0x02, 0x00, 0x0000 }, - { 32, 0x0044, 0x00000044, 0x03, 0x00, 0x0000 }, - { 32, 0x0064, 0x04000044, 0x04, 0x00, 0x0000 }, - { 32, 0x0064, 0x04000044, 0x05, 0x00, 0x0000 }, - { 32, 0x0064, 0x04000044, 0x06, 0x00, 0x0000 }, - { 32, 0x0064, 0x04000044, 0x07, 0x00, 0x0000 }, - { 32, 0x0064, 0x08000044, 0x08, 0x00, 0x0000 }, - { 32, 0x0064, 0x08000044, 0x09, 0x00, 0x0000 }, - { 32, 0x0064, 0x08000044, 0x0a, 0x00, 0x0000 }, - { 32, 0x0064, 0x08000044, 0x0b, 0x00, 0x0000 }, - { 32, 0x0064, 0x0c000044, 0x0c, 0x00, 0x0000 }, - { 32, 0x0064, 0x0c000044, 0x0d, 0x00, 0x0000 }, - { 32, 0x0064, 0x0c000044, 0x0e, 0x00, 0x0000 }, - { 32, 0x0064, 0x0c000044, 0x0f, 0x00, 0x0000 }, - { 33, 0x0066, 0x00000046, 0x00, 0x00, 0x0000 }, - { 33, 0x0046, 0x00000046, 0x01, 0x00, 0x0000 }, - { 33, 0x0066, 0x00000046, 0x02, 0x00, 0x0000 }, - { 33, 0x0046, 0x00000046, 0x03, 0x00, 0x0000 }, - { 33, 0x0066, 0x04000046, 0x04, 0x00, 0x0000 }, - { 33, 0x0066, 0x04000046, 0x05, 0x00, 0x0000 }, - { 33, 0x0066, 0x04000046, 0x06, 0x00, 0x0000 }, - { 33, 0x0066, 0x04000046, 0x07, 0x00, 0x0000 }, - { 33, 0x0066, 0x08000046, 0x08, 0x00, 0x0000 }, - { 33, 0x0066, 0x08000046, 0x09, 0x00, 0x0000 }, - { 33, 0x0066, 0x08000046, 0x0a, 0x00, 0x0000 }, - { 33, 0x0066, 0x08000046, 0x0b, 0x00, 0x0000 }, - { 33, 0x0066, 0x0c000046, 0x0c, 0x00, 0x0000 }, - { 33, 0x0066, 0x0c000046, 0x0d, 0x00, 0x0000 }, - { 33, 0x0066, 0x0c000046, 0x0e, 0x00, 0x0000 }, - { 33, 0x0066, 0x0c000046, 0x0f, 0x00, 0x0000 }, - { 34, 0x0067, 0x00000047, 0x00, 0x00, 0x0000 }, - { 34, 0x0047, 0x00000047, 0x01, 0x00, 0x0000 }, - { 34, 0x0067, 0x00000047, 0x02, 0x00, 0x0000 }, - { 34, 0x0047, 0x00000047, 0x03, 0x00, 0x0000 }, - { 34, 0x0067, 0x04000047, 0x04, 0x00, 0x0000 }, - { 34, 0x0067, 0x04000047, 0x05, 0x00, 0x0000 }, - { 34, 0x0067, 0x04000047, 0x06, 0x00, 0x0000 }, - { 34, 0x0067, 0x04000047, 0x07, 0x00, 0x0000 }, - { 34, 0x0067, 0x08000047, 0x08, 0x00, 0x0000 }, - { 34, 0x0067, 0x08000047, 0x09, 0x00, 0x0000 }, - { 34, 0x0067, 0x08000047, 0x0a, 0x00, 0x0000 }, - { 34, 0x0067, 0x08000047, 0x0b, 0x00, 0x0000 }, - { 34, 0x0067, 0x0c000047, 0x0c, 0x00, 0x0000 }, - { 34, 0x0067, 0x0c000047, 0x0d, 0x00, 0x0000 }, - { 34, 0x0067, 0x0c000047, 0x0e, 0x00, 0x0000 }, - { 34, 0x0067, 0x0c000047, 0x0f, 0x00, 0x0000 }, - { 35, 0x0068, 0x00000048, 0x00, 0x00, 0x0000 }, - { 35, 0x0048, 0x00000048, 0x01, 0x00, 0x0000 }, - { 35, 0x0068, 0x00000048, 0x02, 0x00, 0x0000 }, - { 35, 0x0048, 0x00000048, 0x03, 0x00, 0x0000 }, - { 35, 0x0068, 0x04000048, 0x04, 0x00, 0x0000 }, - { 35, 0x0068, 0x04000048, 0x05, 0x00, 0x0000 }, - { 35, 0x0068, 0x04000048, 0x06, 0x00, 0x0000 }, - { 35, 0x0068, 0x04000048, 0x07, 0x00, 0x0000 }, - { 35, 0x0068, 0x08000048, 0x08, 0x00, 0x0000 }, - { 35, 0x0068, 0x08000048, 0x09, 0x00, 0x0000 }, - { 35, 0x0068, 0x08000048, 0x0a, 0x00, 0x0000 }, - { 35, 0x0068, 0x08000048, 0x0b, 0x00, 0x0000 }, - { 35, 0x0068, 0x0c000048, 0x0c, 0x00, 0x0000 }, - { 35, 0x0068, 0x0c000048, 0x0d, 0x00, 0x0000 }, - { 35, 0x0068, 0x0c000048, 0x0e, 0x00, 0x0000 }, - { 35, 0x0068, 0x0c000048, 0x0f, 0x00, 0x0000 }, - { 36, 0x006a, 0x0000004a, 0x00, 0x00, 0x0000 }, - { 36, 0x004a, 0x0000004a, 0x01, 0x00, 0x0000 }, - { 36, 0x006a, 0x0000004a, 0x02, 0x00, 0x0000 }, - { 36, 0x004a, 0x0000004a, 0x03, 0x00, 0x0000 }, - { 36, 0x006a, 0x0400004a, 0x04, 0x00, 0x0000 }, - { 36, 0x006a, 0x0400004a, 0x05, 0x00, 0x0000 }, - { 36, 0x006a, 0x0400004a, 0x06, 0x00, 0x0000 }, - { 36, 0x006a, 0x0400004a, 0x07, 0x00, 0x0000 }, - { 36, 0x006a, 0x0800004a, 0x08, 0x00, 0x0000 }, - { 36, 0x006a, 0x0800004a, 0x09, 0x00, 0x0000 }, - { 36, 0x006a, 0x0800004a, 0x0a, 0x00, 0x0000 }, - { 36, 0x006a, 0x0800004a, 0x0b, 0x00, 0x0000 }, - { 36, 0x006a, 0x0c00004a, 0x0c, 0x00, 0x0000 }, - { 36, 0x006a, 0x0c00004a, 0x0d, 0x00, 0x0000 }, - { 36, 0x006a, 0x0c00004a, 0x0e, 0x00, 0x0000 }, - { 36, 0x006a, 0x0c00004a, 0x0f, 0x00, 0x0000 }, - { 37, 0x006b, 0x0000004b, 0x00, 0x00, 0x0000 }, - { 37, 0x004b, 0x0000004b, 0x01, 0x00, 0x0000 }, - { 37, 0x006b, 0x0000004b, 0x02, 0x00, 0x0000 }, - { 37, 0x004b, 0x0000004b, 0x03, 0x00, 0x0000 }, - { 37, 0x006b, 0x0400004b, 0x04, 0x00, 0x0000 }, - { 37, 0x006b, 0x0400004b, 0x05, 0x00, 0x0000 }, - { 37, 0x006b, 0x0400004b, 0x06, 0x00, 0x0000 }, - { 37, 0x006b, 0x0400004b, 0x07, 0x00, 0x0000 }, - { 37, 0x006b, 0x0800004b, 0x08, 0x00, 0x0000 }, - { 37, 0x006b, 0x0800004b, 0x09, 0x00, 0x0000 }, - { 37, 0x006b, 0x0800004b, 0x0a, 0x00, 0x0000 }, - { 37, 0x006b, 0x0800004b, 0x0b, 0x00, 0x0000 }, - { 37, 0x006b, 0x0c00004b, 0x0c, 0x00, 0x0000 }, - { 37, 0x006b, 0x0c00004b, 0x0d, 0x00, 0x0000 }, - { 37, 0x006b, 0x0c00004b, 0x0e, 0x00, 0x0000 }, - { 37, 0x006b, 0x0c00004b, 0x0f, 0x00, 0x0000 }, - { 38, 0x006c, 0x0000004c, 0x00, 0x00, 0x0000 }, - { 38, 0x004c, 0x0000004c, 0x01, 0x00, 0x0000 }, - { 38, 0x006c, 0x0000004c, 0x02, 0x00, 0x0000 }, - { 38, 0x004c, 0x0000004c, 0x03, 0x00, 0x0000 }, - { 38, 0x006c, 0x0400004c, 0x04, 0x00, 0x0000 }, - { 38, 0x006c, 0x0400004c, 0x05, 0x00, 0x0000 }, - { 38, 0x006c, 0x0400004c, 0x06, 0x00, 0x0000 }, - { 38, 0x006c, 0x0400004c, 0x07, 0x00, 0x0000 }, - { 38, 0x006c, 0x0800004c, 0x08, 0x00, 0x0000 }, - { 38, 0x006c, 0x0800004c, 0x09, 0x00, 0x0000 }, - { 38, 0x006c, 0x0800004c, 0x0a, 0x00, 0x0000 }, - { 38, 0x006c, 0x0800004c, 0x0b, 0x00, 0x0000 }, - { 38, 0x006c, 0x0c00004c, 0x0c, 0x00, 0x0000 }, - { 38, 0x006c, 0x0c00004c, 0x0d, 0x00, 0x0000 }, - { 38, 0x006c, 0x0c00004c, 0x0e, 0x00, 0x0000 }, - { 38, 0x006c, 0x0c00004c, 0x0f, 0x00, 0x0000 }, - { 39, 0x003b, 0x0000003b, 0x00, 0x00, 0x0000 }, - { 39, 0x003a, 0x0000003a, 0x01, 0x00, 0x0000 }, - { 40, 0x0027, 0x00000027, 0x00, 0x00, 0x0000 }, - { 40, 0x0022, 0x00000022, 0x01, 0x00, 0x0000 }, - { 40, 0x0027, 0x01001251, 0x02, 0x01, 0x0000 }, - { 40, 0x0022, 0x01001257, 0x03, 0x01, 0x0000 }, - { 40, 0x0067, 0x04000047, 0x04, 0x00, 0x0000 }, - { 41, 0x0060, 0x00000060, 0x00, 0x00, 0x0000 }, - { 41, 0x007e, 0x0000007e, 0x01, 0x00, 0x0000 }, - { 41, 0x0060, 0x01001250, 0x02, 0x01, 0x0000 }, - { 41, 0x007e, 0x01001253, 0x03, 0x01, 0x0000 }, - { 42, 0xffff, 0x01000020, 0x00, 0x04, 0x0001 }, - { 43, 0x005c, 0x0000005c, 0x00, 0x00, 0x0000 }, - { 43, 0x007c, 0x0000007c, 0x01, 0x00, 0x0000 }, - { 43, 0x005c, 0x0400005c, 0x04, 0x00, 0x0000 }, - { 44, 0x007a, 0x0000005a, 0x00, 0x00, 0x0000 }, - { 44, 0x005a, 0x0000005a, 0x01, 0x00, 0x0000 }, - { 44, 0x007a, 0x0000005a, 0x02, 0x00, 0x0000 }, - { 44, 0x005a, 0x0000005a, 0x03, 0x00, 0x0000 }, - { 44, 0x007a, 0x0400005a, 0x04, 0x00, 0x0000 }, - { 44, 0x007a, 0x0400005a, 0x05, 0x00, 0x0000 }, - { 44, 0x007a, 0x0400005a, 0x06, 0x00, 0x0000 }, - { 44, 0x007a, 0x0400005a, 0x07, 0x00, 0x0000 }, - { 44, 0x007a, 0x0800005a, 0x08, 0x00, 0x0000 }, - { 44, 0x007a, 0x0800005a, 0x09, 0x00, 0x0000 }, - { 44, 0x007a, 0x0800005a, 0x0a, 0x00, 0x0000 }, - { 44, 0x007a, 0x0800005a, 0x0b, 0x00, 0x0000 }, - { 44, 0x007a, 0x0c00005a, 0x0c, 0x00, 0x0000 }, - { 44, 0x007a, 0x0c00005a, 0x0d, 0x00, 0x0000 }, - { 44, 0x007a, 0x0c00005a, 0x0e, 0x00, 0x0000 }, - { 44, 0x007a, 0x0c00005a, 0x0f, 0x00, 0x0000 }, - { 45, 0x0078, 0x00000058, 0x00, 0x00, 0x0000 }, - { 45, 0x0058, 0x00000058, 0x01, 0x00, 0x0000 }, - { 45, 0x0078, 0x00000058, 0x02, 0x00, 0x0000 }, - { 45, 0x0058, 0x00000058, 0x03, 0x00, 0x0000 }, - { 45, 0x0078, 0x04000058, 0x04, 0x00, 0x0000 }, - { 45, 0x0078, 0x04000058, 0x05, 0x00, 0x0000 }, - { 45, 0x0078, 0x04000058, 0x06, 0x00, 0x0000 }, - { 45, 0x0078, 0x04000058, 0x07, 0x00, 0x0000 }, - { 45, 0x0078, 0x08000058, 0x08, 0x00, 0x0000 }, - { 45, 0x0078, 0x08000058, 0x09, 0x00, 0x0000 }, - { 45, 0x0078, 0x08000058, 0x0a, 0x00, 0x0000 }, - { 45, 0x0078, 0x08000058, 0x0b, 0x00, 0x0000 }, - { 45, 0x0078, 0x0c000058, 0x0c, 0x00, 0x0000 }, - { 45, 0x0078, 0x0c000058, 0x0d, 0x00, 0x0000 }, - { 45, 0x0078, 0x0c000058, 0x0e, 0x00, 0x0000 }, - { 45, 0x0078, 0x0c000058, 0x0f, 0x00, 0x0000 }, - { 46, 0x0063, 0x00000043, 0x00, 0x00, 0x0000 }, - { 46, 0x0043, 0x00000043, 0x01, 0x00, 0x0000 }, - { 46, 0x0063, 0x00000043, 0x02, 0x00, 0x0000 }, - { 46, 0x0043, 0x00000043, 0x03, 0x00, 0x0000 }, - { 46, 0x0063, 0x04000043, 0x04, 0x00, 0x0000 }, - { 46, 0x0063, 0x04000043, 0x05, 0x00, 0x0000 }, - { 46, 0x0063, 0x04000043, 0x06, 0x00, 0x0000 }, - { 46, 0x0063, 0x04000043, 0x07, 0x00, 0x0000 }, - { 46, 0x0063, 0x08000043, 0x08, 0x00, 0x0000 }, - { 46, 0x0063, 0x08000043, 0x09, 0x00, 0x0000 }, - { 46, 0x0063, 0x08000043, 0x0a, 0x00, 0x0000 }, - { 46, 0x0063, 0x08000043, 0x0b, 0x00, 0x0000 }, - { 46, 0x0063, 0x0c000043, 0x0c, 0x00, 0x0000 }, - { 46, 0x0063, 0x0c000043, 0x0d, 0x00, 0x0000 }, - { 46, 0x0063, 0x0c000043, 0x0e, 0x00, 0x0000 }, - { 46, 0x0063, 0x0c000043, 0x0f, 0x00, 0x0000 }, - { 47, 0x0076, 0x00000056, 0x00, 0x00, 0x0000 }, - { 47, 0x0056, 0x00000056, 0x01, 0x00, 0x0000 }, - { 47, 0x0076, 0x00000056, 0x02, 0x00, 0x0000 }, - { 47, 0x0056, 0x00000056, 0x03, 0x00, 0x0000 }, - { 47, 0x0076, 0x04000056, 0x04, 0x00, 0x0000 }, - { 47, 0x0076, 0x04000056, 0x05, 0x00, 0x0000 }, - { 47, 0x0076, 0x04000056, 0x06, 0x00, 0x0000 }, - { 47, 0x0076, 0x04000056, 0x07, 0x00, 0x0000 }, - { 47, 0x0076, 0x08000056, 0x08, 0x00, 0x0000 }, - { 47, 0x0076, 0x08000056, 0x09, 0x00, 0x0000 }, - { 47, 0x0076, 0x08000056, 0x0a, 0x00, 0x0000 }, - { 47, 0x0076, 0x08000056, 0x0b, 0x00, 0x0000 }, - { 47, 0x0076, 0x0c000056, 0x0c, 0x00, 0x0000 }, - { 47, 0x0076, 0x0c000056, 0x0d, 0x00, 0x0000 }, - { 47, 0x0076, 0x0c000056, 0x0e, 0x00, 0x0000 }, - { 47, 0x0076, 0x0c000056, 0x0f, 0x00, 0x0000 }, - { 48, 0x0062, 0x00000042, 0x00, 0x00, 0x0000 }, - { 48, 0x0042, 0x00000042, 0x01, 0x00, 0x0000 }, - { 48, 0x0062, 0x00000042, 0x02, 0x00, 0x0000 }, - { 48, 0x0042, 0x00000042, 0x03, 0x00, 0x0000 }, - { 48, 0x0062, 0x04000042, 0x04, 0x00, 0x0000 }, - { 48, 0x0062, 0x04000042, 0x05, 0x00, 0x0000 }, - { 48, 0x0062, 0x04000042, 0x06, 0x00, 0x0000 }, - { 48, 0x0062, 0x04000042, 0x07, 0x00, 0x0000 }, - { 48, 0x0062, 0x08000042, 0x08, 0x00, 0x0000 }, - { 48, 0x0062, 0x08000042, 0x09, 0x00, 0x0000 }, - { 48, 0x0062, 0x08000042, 0x0a, 0x00, 0x0000 }, - { 48, 0x0062, 0x08000042, 0x0b, 0x00, 0x0000 }, - { 48, 0x0062, 0x0c000042, 0x0c, 0x00, 0x0000 }, - { 48, 0x0062, 0x0c000042, 0x0d, 0x00, 0x0000 }, - { 48, 0x0062, 0x0c000042, 0x0e, 0x00, 0x0000 }, - { 48, 0x0062, 0x0c000042, 0x0f, 0x00, 0x0000 }, - { 49, 0x006e, 0x0000004e, 0x00, 0x00, 0x0000 }, - { 49, 0x004e, 0x0000004e, 0x01, 0x00, 0x0000 }, - { 49, 0x006e, 0x0000004e, 0x02, 0x00, 0x0000 }, - { 49, 0x004e, 0x0000004e, 0x03, 0x00, 0x0000 }, - { 49, 0x006e, 0x0400004e, 0x04, 0x00, 0x0000 }, - { 49, 0x006e, 0x0400004e, 0x05, 0x00, 0x0000 }, - { 49, 0x006e, 0x0400004e, 0x06, 0x00, 0x0000 }, - { 49, 0x006e, 0x0400004e, 0x07, 0x00, 0x0000 }, - { 49, 0x006e, 0x0800004e, 0x08, 0x00, 0x0000 }, - { 49, 0x006e, 0x0800004e, 0x09, 0x00, 0x0000 }, - { 49, 0x006e, 0x0800004e, 0x0a, 0x00, 0x0000 }, - { 49, 0x006e, 0x0800004e, 0x0b, 0x00, 0x0000 }, - { 49, 0x006e, 0x0c00004e, 0x0c, 0x00, 0x0000 }, - { 49, 0x006e, 0x0c00004e, 0x0d, 0x00, 0x0000 }, - { 49, 0x006e, 0x0c00004e, 0x0e, 0x00, 0x0000 }, - { 49, 0x006e, 0x0c00004e, 0x0f, 0x00, 0x0000 }, - { 50, 0x006d, 0x0000004d, 0x00, 0x00, 0x0000 }, - { 50, 0x004d, 0x0000004d, 0x01, 0x00, 0x0000 }, - { 50, 0x006d, 0x0000004d, 0x02, 0x00, 0x0000 }, - { 50, 0x004d, 0x0000004d, 0x03, 0x00, 0x0000 }, - { 50, 0x006d, 0x0400004d, 0x04, 0x00, 0x0000 }, - { 50, 0x006d, 0x0400004d, 0x05, 0x00, 0x0000 }, - { 50, 0x006d, 0x0400004d, 0x06, 0x00, 0x0000 }, - { 50, 0x006d, 0x0400004d, 0x07, 0x00, 0x0000 }, - { 50, 0x006d, 0x0800004d, 0x08, 0x00, 0x0000 }, - { 50, 0x006d, 0x0800004d, 0x09, 0x00, 0x0000 }, - { 50, 0x006d, 0x0800004d, 0x0a, 0x00, 0x0000 }, - { 50, 0x006d, 0x0800004d, 0x0b, 0x00, 0x0000 }, - { 50, 0x006d, 0x0c00004d, 0x0c, 0x00, 0x0000 }, - { 50, 0x006d, 0x0c00004d, 0x0d, 0x00, 0x0000 }, - { 50, 0x006d, 0x0c00004d, 0x0e, 0x00, 0x0000 }, - { 50, 0x006d, 0x0c00004d, 0x0f, 0x00, 0x0000 }, - { 51, 0x002c, 0x0000002c, 0x00, 0x00, 0x0000 }, - { 51, 0x003c, 0x0000003c, 0x01, 0x00, 0x0000 }, - { 51, 0x002c, 0x0100125b, 0x02, 0x01, 0x0000 }, - { 52, 0x002e, 0x0000002e, 0x00, 0x00, 0x0000 }, - { 52, 0x003e, 0x0000003e, 0x01, 0x00, 0x0000 }, - { 52, 0xffff, 0x01001120, 0x02, 0x00, 0x0000 }, - { 53, 0x002f, 0x0000002f, 0x00, 0x00, 0x0000 }, - { 53, 0x003f, 0x0000003f, 0x01, 0x00, 0x0000 }, - { 53, 0xffff, 0x01000003, 0x04, 0x00, 0x0000 }, - { 54, 0xffff, 0x01000020, 0x00, 0x04, 0x0001 }, - { 55, 0x002a, 0x2000002a, 0x00, 0x00, 0x0000 }, - { 56, 0xffff, 0x01000023, 0x00, 0x04, 0x0008 }, - { 57, 0x0020, 0x00000020, 0x00, 0x00, 0x0000 }, - { 58, 0xffff, 0x01000024, 0x00, 0x00, 0x0000 }, - { 59, 0xffff, 0x01000030, 0x00, 0x00, 0x0000 }, - { 59, 0xffff, 0x0100003c, 0x01, 0x00, 0x0000 }, - { 59, 0xffff, 0x01000048, 0x04, 0x00, 0x0000 }, - { 59, 0xffff, 0x01000000, 0x0c, 0x08, 0x0100 }, - { 60, 0xffff, 0x01000031, 0x00, 0x00, 0x0000 }, - { 60, 0xffff, 0x0100003d, 0x01, 0x00, 0x0000 }, - { 60, 0xffff, 0x01000049, 0x04, 0x00, 0x0000 }, - { 60, 0xffff, 0x01000000, 0x0c, 0x08, 0x0101 }, - { 61, 0xffff, 0x01000032, 0x00, 0x00, 0x0000 }, - { 61, 0xffff, 0x0100003e, 0x01, 0x00, 0x0000 }, - { 61, 0xffff, 0x0100004a, 0x04, 0x00, 0x0000 }, - { 61, 0xffff, 0x01000000, 0x0c, 0x08, 0x0102 }, - { 62, 0xffff, 0x01000033, 0x00, 0x00, 0x0000 }, - { 62, 0xffff, 0x0100003f, 0x01, 0x00, 0x0000 }, - { 62, 0xffff, 0x0100004b, 0x04, 0x00, 0x0000 }, - { 62, 0xffff, 0x01000000, 0x0c, 0x08, 0x0103 }, - { 63, 0xffff, 0x01000034, 0x00, 0x00, 0x0000 }, - { 63, 0xffff, 0x01000040, 0x01, 0x00, 0x0000 }, - { 63, 0xffff, 0x0100004c, 0x04, 0x00, 0x0000 }, - { 63, 0xffff, 0x01000000, 0x0c, 0x08, 0x0104 }, - { 64, 0xffff, 0x01000035, 0x00, 0x00, 0x0000 }, - { 64, 0xffff, 0x01000041, 0x01, 0x00, 0x0000 }, - { 64, 0xffff, 0x0100004d, 0x04, 0x00, 0x0000 }, - { 64, 0xffff, 0x01000000, 0x0c, 0x08, 0x0105 }, - { 65, 0xffff, 0x01000036, 0x00, 0x00, 0x0000 }, - { 65, 0xffff, 0x01000042, 0x01, 0x00, 0x0000 }, - { 65, 0xffff, 0x0100004e, 0x04, 0x00, 0x0000 }, - { 65, 0xffff, 0x01000000, 0x0c, 0x08, 0x0106 }, - { 66, 0xffff, 0x01000037, 0x00, 0x00, 0x0000 }, - { 66, 0xffff, 0x01000043, 0x01, 0x00, 0x0000 }, - { 66, 0xffff, 0x0100004f, 0x04, 0x00, 0x0000 }, - { 66, 0xffff, 0x01000000, 0x0c, 0x08, 0x0107 }, - { 67, 0xffff, 0x01000038, 0x00, 0x00, 0x0000 }, - { 67, 0xffff, 0x01000044, 0x01, 0x00, 0x0000 }, - { 67, 0xffff, 0x01000050, 0x04, 0x00, 0x0000 }, - { 67, 0xffff, 0x01000000, 0x0c, 0x08, 0x0108 }, - { 68, 0xffff, 0x01000039, 0x00, 0x00, 0x0000 }, - { 68, 0xffff, 0x01000045, 0x01, 0x00, 0x0000 }, - { 68, 0xffff, 0x01000051, 0x04, 0x00, 0x0000 }, - { 68, 0xffff, 0x01000000, 0x0c, 0x08, 0x0109 }, - { 69, 0xffff, 0x01000025, 0x00, 0x00, 0x0000 }, - { 70, 0xffff, 0x01000026, 0x00, 0x00, 0x0000 }, - { 70, 0xffff, 0x01000026, 0x08, 0x00, 0x0000 }, - { 71, 0x0037, 0x20000037, 0x00, 0x00, 0x0000 }, - { 72, 0x0038, 0x20000038, 0x00, 0x00, 0x0000 }, - { 73, 0x0039, 0x20000039, 0x00, 0x00, 0x0000 }, - { 74, 0x002d, 0x2000002d, 0x00, 0x00, 0x0000 }, - { 75, 0x0034, 0x20000034, 0x00, 0x00, 0x0000 }, - { 76, 0x0035, 0x20000035, 0x00, 0x00, 0x0000 }, - { 77, 0x0036, 0x20000036, 0x00, 0x00, 0x0000 }, - { 78, 0x002b, 0x2000002b, 0x00, 0x00, 0x0000 }, - { 79, 0x0031, 0x20000031, 0x00, 0x00, 0x0000 }, - { 80, 0x0032, 0x20000032, 0x00, 0x00, 0x0000 }, - { 81, 0x0033, 0x20000033, 0x00, 0x00, 0x0000 }, - { 82, 0x0030, 0x20000030, 0x00, 0x00, 0x0000 }, - { 83, 0x002e, 0x2000002e, 0x00, 0x00, 0x0000 }, - { 83, 0xffff, 0x01000000, 0x06, 0x08, 0x0200 }, - { 83, 0xffff, 0x01000000, 0x0c, 0x08, 0x0200 }, - { 86, 0x003c, 0x0000003c, 0x00, 0x00, 0x0000 }, - { 86, 0x003e, 0x0000003e, 0x01, 0x00, 0x0000 }, - { 86, 0x007c, 0x0000007c, 0x02, 0x00, 0x0000 }, - { 87, 0xffff, 0x0100003a, 0x00, 0x00, 0x0000 }, - { 87, 0xffff, 0x01000046, 0x01, 0x00, 0x0000 }, - { 87, 0xffff, 0x01000052, 0x04, 0x00, 0x0000 }, - { 87, 0xffff, 0x01000000, 0x0c, 0x08, 0x010a }, - { 88, 0xffff, 0x0100003b, 0x00, 0x00, 0x0000 }, - { 88, 0xffff, 0x01000047, 0x01, 0x00, 0x0000 }, - { 88, 0xffff, 0x01000000, 0x0c, 0x08, 0x010b }, - { 96, 0xffff, 0x21000005, 0x00, 0x00, 0x0000 }, - { 97, 0xffff, 0x01000021, 0x00, 0x04, 0x0004 }, - { 98, 0x002f, 0x2000002f, 0x00, 0x00, 0x0000 }, - { 99, 0x005c, 0x0400005c, 0x00, 0x00, 0x0000 }, - { 100, 0xffff, 0x01001103, 0x00, 0x04, 0x0002 }, - { 102, 0xffff, 0x01000010, 0x00, 0x00, 0x0000 }, - { 103, 0xffff, 0x01000013, 0x00, 0x00, 0x0000 }, - { 104, 0xffff, 0x01000016, 0x00, 0x00, 0x0000 }, - { 105, 0xffff, 0x01000012, 0x00, 0x00, 0x0000 }, - { 105, 0xffff, 0x01000000, 0x0c, 0x08, 0x0180 }, - { 106, 0xffff, 0x01000014, 0x00, 0x00, 0x0000 }, - { 106, 0xffff, 0x01000000, 0x0c, 0x08, 0x0181 }, - { 107, 0xffff, 0x01000011, 0x00, 0x00, 0x0000 }, - { 108, 0xffff, 0x01000015, 0x00, 0x00, 0x0000 }, - { 109, 0xffff, 0x01000017, 0x00, 0x00, 0x0000 }, - { 110, 0xffff, 0x01000006, 0x00, 0x00, 0x0000 }, - { 111, 0xffff, 0x01000007, 0x00, 0x00, 0x0000 }, - { 111, 0xffff, 0x01000000, 0x06, 0x08, 0x0200 }, - { 111, 0xffff, 0x01000000, 0x0c, 0x08, 0x0200 }, - { 113, 0xffff, 0x01000071, 0x00, 0x00, 0x0000 }, - { 114, 0xffff, 0x01000070, 0x00, 0x00, 0x0000 }, - { 115, 0xffff, 0x01000072, 0x00, 0x00, 0x0000 }, - { 116, 0xffff, 0x0100010b, 0x00, 0x00, 0x0000 }, - { 119, 0xffff, 0x01000008, 0x00, 0x00, 0x0000 }, - { 138, 0xffff, 0x01000058, 0x00, 0x00, 0x0000 }, - { 139, 0xffff, 0x01000055, 0x00, 0x00, 0x0000 }, - { 152, 0xffff, 0x010000ba, 0x00, 0x00, 0x0000 }, - -}; - -const QWSKeyboard::Composing QWSKbPrivate::s_keycompose_default[] = { - { 0x0060, 0x0041, 0x00c0 }, - { 0x0060, 0x0061, 0x00e0 }, - { 0x0027, 0x0041, 0x00c1 }, - { 0x0027, 0x0061, 0x00e1 }, - { 0x005e, 0x0041, 0x00c2 }, - { 0x005e, 0x0061, 0x00e2 }, - { 0x007e, 0x0041, 0x00c3 }, - { 0x007e, 0x0061, 0x00e3 }, - { 0x0022, 0x0041, 0x00c4 }, - { 0x0022, 0x0061, 0x00e4 }, - { 0x002d, 0x0061, 0x00aa }, - { 0x002d, 0x0041, 0x00aa }, - { 0x004f, 0x0041, 0x00c5 }, - { 0x006f, 0x0061, 0x00e5 }, - { 0x0030, 0x0041, 0x00c5 }, - { 0x0030, 0x0061, 0x00e5 }, - { 0x0041, 0x0041, 0x00c5 }, - { 0x0061, 0x0061, 0x00e5 }, - { 0x00b0, 0x0041, 0x00c5 }, - { 0x00b0, 0x0061, 0x00e5 }, - { 0x0041, 0x0045, 0x00c6 }, - { 0x0061, 0x0065, 0x00e6 }, - { 0x002c, 0x0043, 0x00c7 }, - { 0x002c, 0x0063, 0x00e7 }, - { 0x005e, 0x0043, 0x00c7 }, - { 0x005e, 0x0063, 0x00e7 }, - { 0x0060, 0x0045, 0x00c8 }, - { 0x0060, 0x0065, 0x00e8 }, - { 0x0027, 0x0045, 0x00c9 }, - { 0x0027, 0x0065, 0x00e9 }, - { 0x005e, 0x0045, 0x00ca }, - { 0x005e, 0x0065, 0x00ea }, - { 0x0022, 0x0045, 0x00cb }, - { 0x0022, 0x0065, 0x00eb }, - { 0x0060, 0x0049, 0x00cc }, - { 0x0060, 0x0069, 0x00ec }, - { 0x0027, 0x0049, 0x00cd }, - { 0x0027, 0x0069, 0x00ed }, - { 0x005e, 0x0049, 0x00ce }, - { 0x005e, 0x0069, 0x00ee }, - { 0x0022, 0x0049, 0x00cf }, - { 0x0022, 0x0069, 0x00ef }, - { 0x002d, 0x0044, 0x00d0 }, - { 0x002d, 0x0064, 0x00f0 }, - { 0x005e, 0x0044, 0x00d0 }, - { 0x005e, 0x0064, 0x00f0 }, - { 0x007e, 0x004e, 0x00d1 }, - { 0x007e, 0x006e, 0x00f1 }, - { 0x005e, 0x004e, 0x00d1 }, - { 0x005e, 0x006e, 0x00f1 }, - { 0x0060, 0x004f, 0x00d2 }, - { 0x0060, 0x006f, 0x00f2 }, - { 0x0027, 0x004f, 0x00d3 }, - { 0x0027, 0x006f, 0x00f3 }, - { 0x005e, 0x004f, 0x00d4 }, - { 0x005e, 0x006f, 0x00f4 }, - { 0x007e, 0x004f, 0x00d5 }, - { 0x007e, 0x006f, 0x00f5 }, - { 0x0022, 0x004f, 0x00d6 }, - { 0x0022, 0x006f, 0x00f6 }, - { 0x002f, 0x004f, 0x00d8 }, - { 0x002f, 0x006f, 0x00f8 }, - { 0x002d, 0x006f, 0x00ba }, - { 0x002d, 0x004f, 0x00ba }, - { 0x0060, 0x0055, 0x00d9 }, - { 0x0060, 0x0075, 0x00f9 }, - { 0x0027, 0x0055, 0x00da }, - { 0x0027, 0x0075, 0x00fa }, - { 0x005e, 0x0055, 0x00db }, - { 0x005e, 0x0075, 0x00fb }, - { 0x0022, 0x0055, 0x00dc }, - { 0x0022, 0x0075, 0x00fc }, - { 0x0027, 0x0059, 0x00dd }, - { 0x0027, 0x0079, 0x00fd }, - { 0x0054, 0x0048, 0x00de }, - { 0x0074, 0x0068, 0x00fe }, - { 0x0073, 0x0073, 0x00df }, - { 0x0022, 0x0079, 0x00ff }, - { 0x0073, 0x007a, 0x00df }, - { 0x006e, 0x006e, 0x00f1 }, - { 0x006e, 0x0068, 0x00f1 }, - { 0x004e, 0x0059, 0x00d1 }, - { 0x004e, 0x004e, 0x00d1 }, - { 0x004e, 0x0048, 0x00d1 }, - { 0x004e, 0x0079, 0x00d1 }, - { 0x004e, 0x006e, 0x00d1 }, - { 0x004e, 0x0068, 0x00d1 }, - { 0x002d, 0x004c, 0x00a3 }, - { 0x003c, 0x003c, 0x00ab }, - { 0x003e, 0x003e, 0x00bb }, - { 0x003f, 0x003f, 0x00bf }, - { 0x005e, 0x003f, 0x00bf }, - { 0x0021, 0x0021, 0x00a1 }, - { 0x005e, 0x0021, 0x00a1 }, - { 0x005e, 0x0031, 0x00b9 }, - { 0x005e, 0x0032, 0x00b2 }, - { 0x005e, 0x0033, 0x00b3 }, - { 0x002b, 0x002d, 0x00b1 }, - { 0x0063, 0x003d, 0x00a2 }, - { 0x0063, 0x002f, 0x00a2 }, - { 0x002f, 0x0063, 0x00a2 }, - { 0x002d, 0x0063, 0x00a2 }, - { 0x002d, 0x0043, 0x00a2 }, - { 0x004c, 0x003d, 0x00a3 }, - { 0x002d, 0x004c, 0x00a3 }, - { 0x002d, 0x006c, 0x00a3 }, - { 0x005e, 0x002a, 0x00d7 }, - { 0x005e, 0x0078, 0x00d7 }, - { 0x0078, 0x0078, 0x00d7 }, - { 0x005e, 0x002e, 0x00b7 }, - { 0x002e, 0x002e, 0x00b7 }, - { 0x005e, 0x002f, 0x00f7 }, - { 0x005e, 0x003a, 0x00f7 }, - { 0x002d, 0x003a, 0x00f7 }, - { 0x003a, 0x002d, 0x00f7 }, - { 0x0059, 0x003d, 0x00a5 }, - { 0x002d, 0x0059, 0x00a5 }, - { 0x002d, 0x006c, 0x00a5 }, - { 0x0028, 0x0063, 0x00a9 }, - { 0x0022, 0x0063, 0x00a9 }, - { 0x002d, 0x0061, 0x00aa }, - { 0x002d, 0x0041, 0x00aa }, - { 0x002d, 0x006f, 0x00ba }, - { 0x002d, 0x004f, 0x00ba }, - { 0x0028, 0x0072, 0x00ae }, - { 0x0022, 0x0072, 0x00ae }, - { 0x006d, 0x0075, 0x00b5 }, - { 0x0031, 0x0034, 0x0152 }, - { 0x0031, 0x0032, 0x0153 }, - { 0x0033, 0x0034, 0x0178 }, - { 0x0065, 0x003d, 0x20ac }, - { 0x002d, 0x0065, 0x20ac }, - { 0x002d, 0x0045, 0x20ac }, - { 0x0076, 0x0053, 0x0160 }, - { 0x005e, 0x0053, 0x0160 }, - { 0x0076, 0x0073, 0x0161 }, - { 0x005e, 0x0073, 0x0161 }, - { 0x0076, 0x005a, 0x017d }, - { 0x005e, 0x005a, 0x017d }, - { 0x0076, 0x007a, 0x017e }, - { 0x005e, 0x007a, 0x017e }, - { 0x004f, 0x0045, 0x0152 }, - { 0x004f, 0x0065, 0x0152 }, - { 0x006f, 0x0065, 0x0153 }, - { 0x0022, 0x0059, 0x0178 }, - { 0x0069, 0x006a, 0x00ff }, - { 0x0049, 0x004a, 0x0178 }, -}; - -#endif diff --git a/src/gui/embedded/qkbd_qws.cpp b/src/gui/embedded/qkbd_qws.cpp deleted file mode 100644 index 9d2c6e86d8..0000000000 --- a/src/gui/embedded/qkbd_qws.cpp +++ /dev/null @@ -1,693 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbd_qws.h" -#include "qkbd_qws_p.h" - -#ifndef QT_NO_QWS_KEYBOARD - -#include <QFile> -#include <QDataStream> -#include <QStringList> - -#ifdef Q_WS_QWS -#include "qwindowsystem_qws.h" -#include "qscreen_qws.h" -#endif - -#ifdef Q_WS_QPA -#include <QWindowSystemInterface> -#include <QKeyEvent> -#endif - -#include "qtimer.h" -#include <stdlib.h> - -//#define QT_DEBUG_KEYMAP - - -QT_BEGIN_NAMESPACE - -class QWSKbPrivate : public QObject -{ - Q_OBJECT -public: - QWSKbPrivate(QWSKeyboardHandler *h, const QString &device) - : m_handler(h), m_modifiers(0), m_composing(0), m_dead_unicode(0xffff), - m_no_zap(false), m_do_compose(false), - m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0) - { - m_ar_timer = new QTimer(this); - m_ar_timer->setSingleShot(true); - connect(m_ar_timer, SIGNAL(timeout()), SLOT(autoRepeat())); - m_ar_delay = 400; - m_ar_period = 80; - - memset(m_locks, 0, sizeof(m_locks)); - - QString keymap; - QStringList args = device.split(QLatin1Char(':')); - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("keymap="))) - keymap = arg.mid(7); - else if (arg == QLatin1String("disable-zap")) - m_no_zap = true; - else if (arg == QLatin1String("enable-compose")) - m_do_compose = true; - else if (arg.startsWith(QLatin1String("repeat-delay="))) - m_ar_delay = arg.mid(13).toInt(); - else if (arg.startsWith(QLatin1String("repeat-rate="))) - m_ar_period = arg.mid(12).toInt(); - } - - if (keymap.isEmpty() || !loadKeymap(keymap)) - unloadKeymap(); - } - - ~QWSKbPrivate() - { - unloadKeymap(); - } - - void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod) - { - m_ar_unicode = uni; - m_ar_keycode = code; - m_ar_modifier = mod; - m_ar_timer->start(m_ar_delay); - } - - void endAutoRepeat() - { - m_ar_timer->stop(); - } - - static Qt::KeyboardModifiers toQtModifiers(quint8 mod) - { - Qt::KeyboardModifiers qtmod = Qt::NoModifier; - - if (mod & (QWSKeyboard::ModShift | QWSKeyboard::ModShiftL | QWSKeyboard::ModShiftR)) - qtmod |= Qt::ShiftModifier; - if (mod & (QWSKeyboard::ModControl | QWSKeyboard::ModCtrlL | QWSKeyboard::ModCtrlR)) - qtmod |= Qt::ControlModifier; - if (mod & QWSKeyboard::ModAlt) - qtmod |= Qt::AltModifier; - - return qtmod; - } - - void unloadKeymap(); - bool loadKeymap(const QString &file); - -private slots: - void autoRepeat() - { - m_handler->processKeyEvent(m_ar_unicode, m_ar_keycode, m_ar_modifier, false, true); - m_handler->processKeyEvent(m_ar_unicode, m_ar_keycode, m_ar_modifier, true, true); - m_ar_timer->start(m_ar_period); - } - -private: - QWSKeyboardHandler *m_handler; - - // auto repeat simulation - int m_ar_unicode; - int m_ar_keycode; - Qt::KeyboardModifiers m_ar_modifier; - int m_ar_delay; - int m_ar_period; - QTimer *m_ar_timer; - - // keymap handling - quint8 m_modifiers; - quint8 m_locks[3]; - int m_composing; - quint16 m_dead_unicode; - - bool m_no_zap; - bool m_do_compose; - - const QWSKeyboard::Mapping *m_keymap; - int m_keymap_size; - const QWSKeyboard::Composing *m_keycompose; - int m_keycompose_size; - - static const QWSKeyboard::Mapping s_keymap_default[]; - static const QWSKeyboard::Composing s_keycompose_default[]; - - friend class QWSKeyboardHandler; -}; - -// simple builtin US keymap -#include "qkbd_defaultmap_qws_p.h" - -// the unloadKeymap() function needs to be AFTER the defaultmap include, -// since the sizeof(s_keymap_default) wouldn't work otherwise. - -void QWSKbPrivate::unloadKeymap() -{ - if (m_keymap && m_keymap != s_keymap_default) - delete [] m_keymap; - if (m_keycompose && m_keycompose != s_keycompose_default) - delete [] m_keycompose; - - m_keymap = s_keymap_default; - m_keymap_size = sizeof(s_keymap_default) / sizeof(s_keymap_default[0]); - m_keycompose = s_keycompose_default; - m_keycompose_size = sizeof(s_keycompose_default) / sizeof(s_keycompose_default[0]); - - // reset state, so we could switch keymaps at runtime - m_modifiers = 0; - memset(m_locks, 0, sizeof(m_locks)); - m_composing = 0; - m_dead_unicode = 0xffff; -} - -bool QWSKbPrivate::loadKeymap(const QString &file) -{ - QFile f(file); - - if (!f.open(QIODevice::ReadOnly)) { - qWarning("Could not open keymap file '%s'", qPrintable(file)); - return false; - } - - // .qmap files have a very simple structure: - // quint32 magic (QWSKeyboard::FileMagic) - // quint32 version (1) - // quint32 keymap_size (# of struct QWSKeyboard::Mappings) - // quint32 keycompose_size (# of struct QWSKeyboard::Composings) - // all QWSKeyboard::Mappings via QDataStream::operator(<<|>>) - // all QWSKeyboard::Composings via QDataStream::operator(<<|>>) - - quint32 qmap_magic, qmap_version, qmap_keymap_size, qmap_keycompose_size; - - QDataStream ds(&f); - - ds >> qmap_magic >> qmap_version >> qmap_keymap_size >> qmap_keycompose_size; - - if (ds.status() != QDataStream::Ok || qmap_magic != QWSKeyboard::FileMagic || qmap_version != 1 || qmap_keymap_size == 0) { - qWarning("'%s' is ot a valid.qmap keymap file.", qPrintable(file)); - return false; - } - - QWSKeyboard::Mapping *qmap_keymap = new QWSKeyboard::Mapping[qmap_keymap_size]; - QWSKeyboard::Composing *qmap_keycompose = qmap_keycompose_size ? new QWSKeyboard::Composing[qmap_keycompose_size] : 0; - - for (quint32 i = 0; i < qmap_keymap_size; ++i) - ds >> qmap_keymap[i]; - for (quint32 i = 0; i < qmap_keycompose_size; ++i) - ds >> qmap_keycompose[i]; - - if (ds.status() != QDataStream::Ok) { - delete [] qmap_keymap; - delete [] qmap_keycompose; - - qWarning("Keymap file '%s' can not be loaded.", qPrintable(file)); - return false; - } - - // unload currently active and clear state - unloadKeymap(); - - m_keymap = qmap_keymap; - m_keymap_size = qmap_keymap_size; - m_keycompose = qmap_keycompose; - m_keycompose_size = qmap_keycompose_size; - - m_do_compose = true; - - return true; -} - - -/*! - \class QWSKeyboardHandler - \ingroup qws - - \brief The QWSKeyboardHandler class is a base class for keyboard - drivers in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several keyboard - protocols, see the \l{Qt for Embedded Linux Character Input}{character - input} documentation for details. Custom keyboard drivers can be - implemented by subclassing the QWSKeyboardHandler class and - creating a keyboard driver plugin (derived from - QKbdDriverPlugin). The default implementation of the - QKbdDriverFactory class will automatically detect the plugin, and - load the driver into the server application at run-time using Qt's - \l{How to Create Qt Plugins}{plugin system}. - - The keyboard driver receives keyboard events from the system - device and encapsulates each event with an instance of the - QWSEvent class which it then passes to the server application (the - server is responsible for propagating the event to the appropriate - client). To receive keyboard events, a QWSKeyboardHandler object - will usually create a QSocketNotifier object for the given - device. The QSocketNotifier class provides support for monitoring - activity on a file descriptor. When the socket notifier receives - data, it will call the keyboard driver's processKeyEvent() - function to send the event to the \l{Qt for Embedded Linux} server - application for relaying to clients. - - - QWSKeyboardHandler also provides functions to control - auto-repetion of key sequences, beginAutoRepeat() and - endAutoRepeat(), and the transformDirKey() function enabling - transformation of arrow keys according to the display orientation. - - \sa QKbdDriverPlugin, QKbdDriverFactory, {Qt for Embedded Linux Character Input} -*/ - - -/*! - Constructs a keyboard driver. The \a device argument is passed by the - QWS_KEYBOARD environment variable. - - Call the QWSServer::setKeyboardHandler() function to make the - newly created keyboard driver, the primary driver. Note that the - primary driver is controlled by the system, i.e., the system will - delete it upon exit. -*/ -QWSKeyboardHandler::QWSKeyboardHandler(const QString &device) -{ - d = new QWSKbPrivate(this, device); -} - -/*! - \overload -*/ -QWSKeyboardHandler::QWSKeyboardHandler() -{ - d = new QWSKbPrivate(this, QString()); -} - - - -/*! - Destroys this keyboard driver. - - Do not call this function if this driver is the primary keyboard - handler, i.e., if QWSServer::setKeyboardHandler() function has - been called passing this driver as argument. The primary keyboard - driver is deleted by the system. -*/ -QWSKeyboardHandler::~QWSKeyboardHandler() -{ - delete d; -} - - -/*! - Sends a key event to the \l{Qt for Embedded Linux} server application. - - The key event is identified by its \a unicode value and the \a - keycode, \a modifiers, \a isPress and \a autoRepeat parameters. - - The \a keycode parameter is the Qt keycode value as defined by the - Qt::Key enum. The \a modifiers is an OR combination of - Qt::KeyboardModifier values, indicating whether \gui - Shift/Alt/Ctrl keys are pressed. The \a isPress parameter is true - if the event is a key press event and \a autoRepeat is true if the - event is caused by an auto-repeat mechanism and not an actual key - press. - - Note that this function does not handle key mapping. Please use - processKeycode() if you need that functionality. - - \sa processKeycode(), beginAutoRepeat(), endAutoRepeat(), transformDirKey() -*/ -void QWSKeyboardHandler::processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat) -{ -#if defined(Q_WS_QWS) - qwsServer->processKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); -#elif defined(Q_WS_QPA) - QEvent::Type type = isPress ? QEvent::KeyPress : QEvent::KeyRelease; - QString str; - if (unicode != 0xffff) - str = QString(unicode); - QWindowSystemInterface::handleKeyEvent(0, type, keycode, modifiers, str); -#endif -} - -/*! - \fn int QWSKeyboardHandler::transformDirKey(int keycode) - - Transforms the arrow key specified by the given \a keycode, to the - orientation of the display and returns the transformed keycode. - - The \a keycode is a Qt::Key value. The values identifying arrow - keys are: - - \list - \o Qt::Key_Left - \o Qt::Key_Up - \o Qt::Key_Right - \o Qt::Key_Down - \endlist - - \sa processKeyEvent() - */ -int QWSKeyboardHandler::transformDirKey(int key) -{ -#ifdef Q_WS_QWS - static int dir_keyrot = -1; - if (dir_keyrot < 0) { - // get the rotation - switch (qgetenv("QWS_CURSOR_ROTATION").toInt()) { - case 90: dir_keyrot = 1; break; - case 180: dir_keyrot = 2; break; - case 270: dir_keyrot = 3; break; - default: dir_keyrot = 0; break; - } - } - int xf = qt_screen->transformOrientation() + dir_keyrot; - return (key-Qt::Key_Left+xf)%4+Qt::Key_Left; -#else - return 0; -#endif -} - -/*! - \fn void QWSKeyboardHandler::beginAutoRepeat(int unicode, int keycode, Qt::KeyboardModifiers modifier) - - Begins auto-repeating the specified key press; after a short delay - the key press is sent periodically until the endAutoRepeat() - function is called. - - The key press is specified by its \a unicode, \a keycode and \a - modifier state. - - \sa endAutoRepeat(), processKeyEvent() -*/ -void QWSKeyboardHandler::beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod) -{ - d->beginAutoRepeat(uni, code, mod); -} - -/*! - Stops auto-repeating a key press. - - \sa beginAutoRepeat(), processKeyEvent() -*/ -void QWSKeyboardHandler::endAutoRepeat() -{ - d->endAutoRepeat(); -} - -/*! - \enum QWSKeyboardHandler::KeycodeAction - - This enum describes the various special actions that actual - QWSKeyboardHandler implementations have to take care of. - - \value None No further action required. - - \value CapsLockOn Set the state of the Caps lock LED to on. - \value CapsLockOff Set the state of the Caps lock LED to off. - \value NumLockOn Set the state of the Num lock LED to on. - \value NumLockOff Set the state of the Num lock LED to off. - \value ScrollLockOn Set the state of the Scroll lock LED to on. - \value ScrollLockOff Set the state of the Scroll lock LED to off. - - \value PreviousConsole Switch to the previous virtual console (by - default Ctrl+Alt+Left on Linux). - \value NextConsole Switch to the next virtual console (by default - Ctrl+Alt+Right on Linux). - \value SwitchConsoleFirst Switch to the first virtual console (0). - \value SwitchConsoleLast Switch to the last virtual console (255). - \value SwitchConsoleMask If the KeyAction value is between SwitchConsoleFirst - and SwitchConsoleLast, you can use this mask to get - the specific virtual console number to switch to. - - \value Reboot Reboot the machine - this is ignored in both the TTY and - LinuxInput handlers though (by default Ctrl+Alt+Del on Linux). - - \sa processKeycode() -*/ - -/*! - \fn QWSKeyboardHandler::KeycodeAction QWSKeyboardHandler::processKeycode(quint16 keycode, bool isPress, bool autoRepeat) - - \since 4.6 - - Maps \a keycode according to a keymap and sends that key event to the - \l{Qt for Embedded Linux} server application. - - Please see the \l{Qt for Embedded Linux Character Input} and the \l - {kmap2qmap} documentations for a description on how to create and use - keymap files. - - The key event is identified by its \a keycode value and the \a isPress - and \a autoRepeat parameters. - - The \a keycode parameter is \bold NOT the Qt keycode value as defined by - the Qt::Key enum. This functions expects a standard Linux 16 bit kernel - keycode as it is used in the Linux Input Event sub-system. This - \a keycode is transformed to a Qt::Key code by using either a - compiled-in US keyboard layout or by dynamically loading a keymap at - startup which can be specified via the QWS_KEYBOARD environment - variable. - - The \a isPress parameter is true if the event is a key press event and - \a autoRepeat is true if the event is caused by an auto-repeat mechanism - and not an actual key press. - - The return value indicates if the actual QWSKeyboardHandler - implementation needs to take care of a special action, like console - switching or LED handling. - - If standard Linux console keymaps are used, \a keycode must be one of the - standardized values defined in \c /usr/include/linux/input.h - - \sa processKeyEvent(), KeycodeAction -*/ - -QWSKeyboardHandler::KeycodeAction QWSKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat) -{ - KeycodeAction result = None; - bool first_press = pressed && !autorepeat; - - const QWSKeyboard::Mapping *map_plain = 0; - const QWSKeyboard::Mapping *map_withmod = 0; - - // get a specific and plain mapping for the keycode and the current modifiers - for (int i = 0; i < d->m_keymap_size && !(map_plain && map_withmod); ++i) { - const QWSKeyboard::Mapping *m = d->m_keymap + i; - if (m->keycode == keycode) { - if (m->modifiers == 0) - map_plain = m; - - quint8 testmods = d->m_modifiers; - if (d->m_locks[0] /*CapsLock*/ && (m->flags & QWSKeyboard::IsLetter)) - testmods ^= QWSKeyboard::ModShift; - if (m->modifiers == testmods) - map_withmod = m; - } - } - -#ifdef QT_DEBUG_KEYMAP - qWarning("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", \ - keycode, d->m_modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, \ - map_plain ? map_plain - d->m_keymap : -1, \ - map_withmod ? map_withmod - d->m_keymap : -1, \ - d->m_keymap_size); -#endif - - const QWSKeyboard::Mapping *it = map_withmod ? map_withmod : map_plain; - - if (!it) { -#ifdef QT_DEBUG_KEYMAP - // we couldn't even find a plain mapping - qWarning("Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, d->m_modifiers); -#endif - return result; - } - - bool skip = false; - quint16 unicode = it->unicode; - quint32 qtcode = it->qtcode; - - if ((it->flags & QWSKeyboard::IsModifier) && it->special) { - // this is a modifier, i.e. Shift, Alt, ... - if (pressed) - d->m_modifiers |= quint8(it->special); - else - d->m_modifiers &= ~quint8(it->special); - } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) { - // (Caps|Num|Scroll)Lock - if (first_press) { - quint8 &lock = d->m_locks[qtcode - Qt::Key_CapsLock]; - lock ^= 1; - - switch (qtcode) { - case Qt::Key_CapsLock : result = lock ? CapsLockOn : CapsLockOff; break; - case Qt::Key_NumLock : result = lock ? NumLockOn : NumLockOff; break; - case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break; - default : break; - } - } - } else if ((it->flags & QWSKeyboard::IsSystem) && it->special && first_press) { - switch (it->special) { - case QWSKeyboard::SystemReboot: - result = Reboot; - break; - - case QWSKeyboard::SystemZap: - if (!d->m_no_zap) - qApp->quit(); - break; - - case QWSKeyboard::SystemConsolePrevious: - result = PreviousConsole; - break; - - case QWSKeyboard::SystemConsoleNext: - result = NextConsole; - break; - - default: - if (it->special >= QWSKeyboard::SystemConsoleFirst && - it->special <= QWSKeyboard::SystemConsoleLast) { - result = KeycodeAction(SwitchConsoleFirst + ((it->special & QWSKeyboard::SystemConsoleMask) & SwitchConsoleMask)); - } - break; - } - - skip = true; // no need to tell QWS about it - } else if ((qtcode == Qt::Key_Multi_key) && d->m_do_compose) { - // the Compose key was pressed - if (first_press) - d->m_composing = 2; - skip = true; - } else if ((it->flags & QWSKeyboard::IsDead) && d->m_do_compose) { - // a Dead key was pressed - if (first_press && d->m_composing == 1 && d->m_dead_unicode == unicode) { // twice - d->m_composing = 0; - qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead... - } else if (first_press && unicode != 0xffff) { - d->m_dead_unicode = unicode; - d->m_composing = 1; - skip = true; - } else { - skip = true; - } - } - - if (!skip) { - // a normal key was pressed - const int modmask = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier; - - // we couldn't find a specific mapping for the current modifiers, - // or that mapping didn't have special modifiers: - // so just report the plain mapping with additional modifiers. - if ((it == map_plain && it != map_withmod) || - (map_withmod && !(map_withmod->qtcode & modmask))) { - qtcode |= QWSKbPrivate::toQtModifiers(d->m_modifiers); - } - - if (d->m_composing == 2 && first_press && !(it->flags & QWSKeyboard::IsModifier)) { - // the last key press was the Compose key - if (unicode != 0xffff) { - int idx = 0; - // check if this code is in the compose table at all - for ( ; idx < d->m_keycompose_size; ++idx) { - if (d->m_keycompose[idx].first == unicode) - break; - } - if (idx < d->m_keycompose_size) { - // found it -> simulate a Dead key press - d->m_dead_unicode = unicode; - unicode = 0xffff; - d->m_composing = 1; - skip = true; - } else { - d->m_composing = 0; - } - } else { - d->m_composing = 0; - } - } else if (d->m_composing == 1 && first_press && !(it->flags & QWSKeyboard::IsModifier)) { - // the last key press was a Dead key - bool valid = false; - if (unicode != 0xffff) { - int idx = 0; - // check if this code is in the compose table at all - for ( ; idx < d->m_keycompose_size; ++idx) { - if (d->m_keycompose[idx].first == d->m_dead_unicode && d->m_keycompose[idx].second == unicode) - break; - } - if (idx < d->m_keycompose_size) { - quint16 composed = d->m_keycompose[idx].result; - if (composed != 0xffff) { - unicode = composed; - qtcode = Qt::Key_unknown; - valid = true; - } - } - } - if (!valid) { - unicode = d->m_dead_unicode; - qtcode = Qt::Key_unknown; - } - d->m_composing = 0; - } - - if (!skip) { -#ifdef QT_DEBUG_KEYMAP - qWarning("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask)); -#endif - - // send the result to the QWS server - processKeyEvent(unicode, qtcode & ~modmask, Qt::KeyboardModifiers(qtcode & modmask), pressed, autorepeat); - } - } - return result; -} - -QT_END_NAMESPACE - -#include "qkbd_qws.moc" - -#endif // QT_NO_QWS_KEYBOARD diff --git a/src/gui/embedded/qkbd_qws.h b/src/gui/embedded/qkbd_qws.h deleted file mode 100644 index 712b9007c7..0000000000 --- a/src/gui/embedded/qkbd_qws.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBD_QWS_H -#define QKBD_QWS_H - -#include <QtGui/qapplication.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -class QWSKbPrivate; - -class Q_GUI_EXPORT QWSKeyboardHandler -{ -public: - QWSKeyboardHandler(); - QWSKeyboardHandler(const QString &device); - virtual ~QWSKeyboardHandler(); - - virtual void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat); - - enum KeycodeAction { - None = 0, - - CapsLockOff = 0x01000000, - CapsLockOn = 0x01000001, - NumLockOff = 0x02000000, - NumLockOn = 0x02000001, - ScrollLockOff = 0x03000000, - ScrollLockOn = 0x03000001, - - Reboot = 0x04000000, - - PreviousConsole = 0x05000000, - NextConsole = 0x05000001, - SwitchConsoleFirst = 0x06000000, - SwitchConsoleLast = 0x0600007f, - SwitchConsoleMask = 0x0000007f, - }; - - KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat); - -protected: - int transformDirKey(int key); - void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod); - void endAutoRepeat(); - -private: - QWSKbPrivate *d; -}; - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBD_QWS_H diff --git a/src/gui/embedded/qkbd_qws_p.h b/src/gui/embedded/qkbd_qws_p.h deleted file mode 100644 index be260e3273..0000000000 --- a/src/gui/embedded/qkbd_qws_p.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSKEYBOARD_P_H -#define QWSKEYBOARD_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QDataStream> - -QT_BEGIN_NAMESPACE - -namespace QWSKeyboard { - const quint32 FileMagic = 0x514d4150; // 'QMAP' - - struct Mapping { - quint16 keycode; - quint16 unicode; - quint32 qtcode; - quint8 modifiers; - quint8 flags; - quint16 special; - - }; - - enum Flags { - IsDead = 0x01, - IsLetter = 0x02, - IsModifier = 0x04, - IsSystem = 0x08, - }; - - enum System { - SystemConsoleFirst = 0x0100, - SystemConsoleMask = 0x007f, - SystemConsoleLast = 0x017f, - SystemConsolePrevious = 0x0180, - SystemConsoleNext = 0x0181, - SystemReboot = 0x0200, - SystemZap = 0x0300, - }; - - struct Composing { - quint16 first; - quint16 second; - quint16 result; - }; - - enum Modifiers { - ModPlain = 0x00, - ModShift = 0x01, - ModAltGr = 0x02, - ModControl = 0x04, - ModAlt = 0x08, - ModShiftL = 0x10, - ModShiftR = 0x20, - ModCtrlL = 0x40, - ModCtrlR = 0x80, - // ModCapsShift = 0x100, // not supported! - }; -}; - -#ifndef QT_NO_DATASTREAM -inline QDataStream &operator>>(QDataStream &ds, QWSKeyboard::Mapping &m) -{ - return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special; -} - -inline QDataStream &operator<<(QDataStream &ds, const QWSKeyboard::Mapping &m) -{ - return ds << m.keycode << m.unicode << m.qtcode << m.modifiers << m.flags << m.special; -} - -inline QDataStream &operator>>(QDataStream &ds, QWSKeyboard::Composing &c) -{ - return ds >> c.first >> c.second >> c.result; -} - -inline QDataStream &operator<<(QDataStream &ds, const QWSKeyboard::Composing &c) -{ - return ds << c.first << c.second << c.result; -} -#endif // QT_NO_DATASTREAM - -QT_END_NAMESPACE - -#endif // QWSKEYBOARD_H diff --git a/src/gui/embedded/qkbddriverfactory_qws.cpp b/src/gui/embedded/qkbddriverfactory_qws.cpp deleted file mode 100644 index 45825e52ea..0000000000 --- a/src/gui/embedded/qkbddriverfactory_qws.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbddriverfactory_qws.h" - -#ifndef QT_NO_QWS_KEYBOARD - -#include "qapplication.h" -#include "qkbdtty_qws.h" -#include "qkbdlinuxinput_qws.h" -#include "qkbdum_qws.h" -#include "qkbdvfb_qws.h" -#include "qkbdqnx_qws.h" -#include "qkbdintegrity_qws.h" -#include <stdlib.h> -#include "private/qfactoryloader_p.h" -#include "qkbddriverplugin_qws.h" - -QT_BEGIN_NAMESPACE - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QWSKeyboardHandlerFactoryInterface_iid, - QLatin1String("/kbddrivers"), Qt::CaseInsensitive)) - -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - -/*! - \class QKbdDriverFactory - \ingroup qws - - \brief The QKbdDriverFactory class creates keyboard drivers in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QKbdDriverFactory is used to detect and instantiate the available - keyboard drivers, allowing \l{Qt for Embedded Linux} to load the preferred - driver into the server application at runtime. The create() - function returns a QWSKeyboardHandler object representing the - keyboard driver identified by a given key. The valid keys - (i.e. the supported drivers) can be retrieved using the keys() - function. - - \l{Qt for Embedded Linux} provides several built-in keyboard drivers. In - addition, custom keyboard drivers can be added using Qt's plugin - mechanism, i.e. by subclassing the QWSKeyboardHandler class and - creating a keyboard driver plugin (QKbdDriverPlugin). See the - \l{Qt for Embedded Linux Character Input}{character input} documentation - for details. - - \sa QWSKeyboardHandler, QKbdDriverPlugin -*/ - -/*! - Creates the keyboard driver specified by the given \a key, using - the display specified by the given \a device. - - Note that the keys are case-insensitive. - - \sa keys() -*/ -QWSKeyboardHandler *QKbdDriverFactory::create(const QString& key, const QString& device) -{ - QString driver = key.toLower(); -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_KBD_QNX) - if (driver == QLatin1String("qnx") || driver.isEmpty()) - return new QWSQnxKeyboardHandler(device); -#endif -#if defined(Q_OS_INTEGRITY) - if (driver == QLatin1String("integrity") || driver.isEmpty()) - return new QWSIntKeyboardHandler(device); -#endif -#ifndef QT_NO_QWS_KEYBOARD -# ifndef QT_NO_QWS_KBD_TTY - if (driver == QLatin1String("tty") || driver.isEmpty()) - return new QWSTtyKeyboardHandler(device); -# endif -# ifndef QT_NO_QWS_KBD_LINUXINPUT - if (driver == QLatin1String("linuxinput") || \ - driver == QLatin1String("usb") || \ - driver == QLatin1String("linuxis")) - return new QWSLinuxInputKeyboardHandler(device); -# endif -# ifndef QT_NO_QWS_KBD_UM - if (driver == QLatin1String("um") || driver == QLatin1String("qvfbkeyboard")) - return new QWSUmKeyboardHandler(device); -# endif -# ifndef QT_NO_QWS_KBD_QVFB - if (driver == QLatin1String("qvfbkbd") - || driver == QLatin1String("qvfbkeyboard") - || driver == QLatin1String("qvfb")) - return new QVFbKeyboardHandler(device); -# endif -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - if (QWSKeyboardHandlerFactoryInterface *factory = qobject_cast<QWSKeyboardHandlerFactoryInterface*>(loader()->instance(driver))) - return factory->create(driver, device); -#endif -#endif - return 0; -} - -/*! - Returns the list of valid keys, i.e. the available keyboard - drivers. - - \sa create() -*/ -QStringList QKbdDriverFactory::keys() -{ - QStringList list; - -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_KBD_QNX) - list << QLatin1String("QNX"); -#endif -#if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_KBD_INTEGRITY) - list << QLatin1String("INTEGRITY"); -#endif -#ifndef QT_NO_QWS_KBD_TTY - list << QLatin1String("TTY"); -#endif -#ifndef QT_NO_QWS_KBD_LINUXINPUT - list << QLatin1String("LinuxInput"); -#endif -#ifndef QT_NO_QWS_KBD_UM - list << QLatin1String("UM"); -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - QStringList plugins = loader()->keys(); - for (int i = 0; i < plugins.size(); ++i) { - if (!list.contains(plugins.at(i))) - list += plugins.at(i); - } -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - - return list; -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_KEYBOARD diff --git a/src/gui/embedded/qkbddriverfactory_qws.h b/src/gui/embedded/qkbddriverfactory_qws.h deleted file mode 100644 index ffb768b01f..0000000000 --- a/src/gui/embedded/qkbddriverfactory_qws.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDDRIVERFACTORY_QWS_H -#define QKBDDRIVERFACTORY_QWS_H - -#include <QtCore/qstringlist.h> - -#ifndef QT_NO_QWS_KEYBOARD - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QString; -class QWSKeyboardHandler; - -class Q_GUI_EXPORT QKbdDriverFactory -{ -public: - static QStringList keys(); - static QWSKeyboardHandler *create(const QString&, const QString&); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_QWS_KEYBOARD -#endif // QKBDDRIVERFACTORY_QWS_H diff --git a/src/gui/embedded/qkbddriverplugin_qws.cpp b/src/gui/embedded/qkbddriverplugin_qws.cpp deleted file mode 100644 index 569cb425c9..0000000000 --- a/src/gui/embedded/qkbddriverplugin_qws.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbddriverplugin_qws.h" - -#ifndef QT_NO_LIBRARY - -#include "qkbd_qws.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QKbdDriverPlugin - \ingroup plugins - \ingroup qws - - \brief The QKbdDriverPlugin class is an abstract base class for - keyboard driver plugins in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several keyboard - protocols, see the \l{Qt for Embedded Linux Character Input}{character - input} documentation for details. Custom keyboard drivers can be - implemented by subclassing the QWSKeyboardHandler class and - creating a keyboard driver plugin. - - A keyboard driver plugin can be created by subclassing - QKbdDriverPlugin and reimplementing the pure virtual keys() and - create() functions. By exporting the derived class using the - Q_EXPORT_PLUGIN2() macro, the default implementation of the - QKbdDriverFactory class will automatically detect the plugin and - load the driver into the server application at run-time. See - \l{How to Create Qt Plugins} for details. - - \sa QKbdDriverFactory, QWSKeyboardHandler -*/ - -/*! - \fn QStringList QKbdDriverPlugin::keys() const - - Implement this function to return the list of valid keys, i.e. the - keyboard drivers supported by this plugin. - - \l{Qt for Embedded Linux} provides ready-made drivers for several keyboard - protocols, see the \l{Qt for Embedded Linux Character Input}{character - input} documentation for details. - - \sa create() -*/ - -/*! - Constructs a keyboard driver plugin with the given \a parent. - - Note that this constructor is invoked automatically by the - Q_EXPORT_PLUGIN2() macro, so there is no need for calling it - explicitly. -*/ -QKbdDriverPlugin::QKbdDriverPlugin(QObject *parent) - : QObject(parent) -{ -} - -/*! - Destroys the keyboard driver plugin. - - Note that Qt destroys a plugin automatically when it is no longer - used, so there is no need for calling the destructor explicitly. -*/ -QKbdDriverPlugin::~QKbdDriverPlugin() -{ -} - -/*! - \fn QScreen *QKbdDriverPlugin::create(const QString &key, const QString &device) - - Implement this function to create a driver matching the type - specified by the given \a key and \a device parameters. Note that - keys are case-insensitive. - - \sa keys() -*/ - -QT_END_NAMESPACE - -#endif // QT_NO_LIBRARY diff --git a/src/gui/embedded/qkbddriverplugin_qws.h b/src/gui/embedded/qkbddriverplugin_qws.h deleted file mode 100644 index 2bb111cbea..0000000000 --- a/src/gui/embedded/qkbddriverplugin_qws.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDDRIVERPLUGIN_QWS_H -#define QKBDDRIVERPLUGIN_QWS_H - -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_LIBRARY - -class QWSKeyboardHandler; - -struct Q_GUI_EXPORT QWSKeyboardHandlerFactoryInterface : public QFactoryInterface -{ - virtual QWSKeyboardHandler* create(const QString &name, const QString &device) = 0; -}; - -#define QWSKeyboardHandlerFactoryInterface_iid "com.trolltech.Qt.QWSKeyboardHandlerFactoryInterface" -Q_DECLARE_INTERFACE(QWSKeyboardHandlerFactoryInterface, QWSKeyboardHandlerFactoryInterface_iid) - -class Q_GUI_EXPORT QKbdDriverPlugin : public QObject, public QWSKeyboardHandlerFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QWSKeyboardHandlerFactoryInterface:QFactoryInterface) -public: - explicit QKbdDriverPlugin(QObject *parent = 0); - ~QKbdDriverPlugin(); - - virtual QStringList keys() const = 0; - virtual QWSKeyboardHandler* create(const QString& driver, const QString &device) = 0; -}; - -#endif // QT_NO_LIBRARY - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDDRIVERPLUGIN_QWS_H diff --git a/src/gui/embedded/qkbdintegrity_qws.cpp b/src/gui/embedded/qkbdintegrity_qws.cpp deleted file mode 100644 index b2df4226a8..0000000000 --- a/src/gui/embedded/qkbdintegrity_qws.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_INTEGRITY) - -#include "qkbdintegrity_qws.h" -#include <qwindowsystem_qws.h> -#include <qapplication.h> -#include <qtimer.h> -#include <qthread.h> - -#include <INTEGRITY.h> - - -//=========================================================================== - -QT_BEGIN_NAMESPACE - -// -// INTEGRITY keyboard -// - -class QIntKeyboardListenThread; - -class QWSIntKbPrivate : public QObject -{ - Q_OBJECT - friend class QIntKeyboardListenThread; -public: - QWSIntKbPrivate(QWSKeyboardHandler *, const QString &device); - ~QWSIntKbPrivate(); - void dataReady(int amount) { emit kbdDataAvailable(amount); } - uint8_t scancodebuf[32 /* USB_SCANCODE_BUF_LEN */ ]; - uint8_t rxpost; - uint8_t rxack; - -Q_SIGNALS: - void kbdDataAvailable(int amount); - -private Q_SLOTS: - void readKeyboardData(int amount); - -private: - QWSKeyboardHandler *handler; - QIntKeyboardListenThread *kbdthread; -}; -class QIntKeyboardListenThread : public QThread -{ -protected: - QWSIntKbPrivate *imp; - bool loop; -public: - QIntKeyboardListenThread(QWSIntKbPrivate *im) : QThread(), imp(im) {}; - ~QIntKeyboardListenThread() {}; - void run(); - void stoploop() { loop = false; }; -}; - - -QWSIntKeyboardHandler::QWSIntKeyboardHandler(const QString &device) - : QWSKeyboardHandler(device) -{ - d = new QWSIntKbPrivate(this, device); -} - -QWSIntKeyboardHandler::~QWSIntKeyboardHandler() -{ - delete d; -} - -//void QWSIntKeyboardHandler::processKeyEvent(int keycode, bool isPress, -// bool autoRepeat) -//{ -// QWSKeyboardHandler::processKeyEvent(keycode, isPress, autoRepeat); -//} - -void QIntKeyboardListenThread::run(void) -{ - Error E; - Buffer b; - Connection kbdc; - bool waitforresource = true; - do { - E = RequestResource((Object*)&kbdc, - "USBKeyboardClient", "!systempassword"); - if (E == Success) { - loop = false; - } else { - E = RequestResource((Object*)&kbdc, - "KeyboardClient", "!systempassword"); - if (E == Success) { - waitforresource = false; - } - } - if (waitforresource) - ::sleep(1); - } while (loop && waitforresource); - if (!loop) - return; - b.BufferType = DataBuffer | LastBuffer; - b.Length = sizeof(imp->scancodebuf); - b.TheAddress = (Address)imp->scancodebuf; - do { - b.Transferred = 0; - b.TheAddress = (Address)imp->scancodebuf + imp->rxpost; - CheckSuccess(SynchronousReceive(kbdc, &b)); - imp->rxpost += b.Transferred; - if (imp->rxpost >= 32 /* USB_SCANCODE_BUF_LEN */) - imp->rxpost = 0; - if (imp->rxpost == (imp->rxack + b.Transferred) % 32 /* USB_SCANCODE_BUF_LEN */) { - imp->kbdDataAvailable(b.Transferred); - } - } while (loop); -} - -void QWSIntKbPrivate::readKeyboardData(int amount) -{ - uint16_t keycode; - do { - if (scancodebuf[rxack] == 0xe0) { - keycode = scancodebuf[rxack] << 8; - rxack++; - if (rxack >= 32 /* USB_SCANCODE_BUF_LEN */) - rxack = 0; - } else { - keycode = 0; - } - - handler->processKeycode(keycode + (scancodebuf[rxack] & 0x7f), - (scancodebuf[rxack] & 0x80) == 0, - scancodebuf[rxack] == 2); - rxack++; - if (rxack >= 32 /* USB_SCANCODE_BUF_LEN */) - rxack = 0; - } while (rxack != rxpost); -} - -QWSIntKbPrivate::QWSIntKbPrivate(QWSKeyboardHandler *h, const QString &device) : handler(h) -{ - connect(this, SIGNAL(kbdDataAvailable(int)), this, SLOT(readKeyboardData(int))); - this->handler = handler; - rxack = rxpost = 0; - kbdthread = new QIntKeyboardListenThread(this); - kbdthread->start(); -} - -QWSIntKbPrivate::~QWSIntKbPrivate() -{ - kbdthread->stoploop(); - kbdthread->wait(); - delete kbdthread; -} - - -QT_END_NAMESPACE - -#include "qkbdintegrity_qws.moc" - -#endif // QT_NO_QWS_KEYBOARD || QT_NO_QWS_KBD_TTY diff --git a/src/gui/embedded/qkbdintegrity_qws.h b/src/gui/embedded/qkbdintegrity_qws.h deleted file mode 100644 index f9ae4e3250..0000000000 --- a/src/gui/embedded/qkbdintegrity_qws.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDINTEGRITY_QWS_H -#define QKBDINTEGRITY_QWS_H - -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -#ifndef QT_NO_QWS_KBD_INTEGRITY - -class QSocketNotifier; -class QWSIntKbPrivate; - -class QWSIntKeyboardHandler : public QWSKeyboardHandler -{ -public: - explicit QWSIntKeyboardHandler(const QString&); - virtual ~QWSIntKeyboardHandler(); - -//protected: -// virtual void processKeyEvent(int keycode, bool isPress, bool autoRepeat); - -private: - QWSIntKbPrivate *d; -}; - -#endif // QT_NO_QWS_KBD_INTEGRITY - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDINTEGRITY_QWS_H diff --git a/src/gui/embedded/qkbdlinuxinput_qws.cpp b/src/gui/embedded/qkbdlinuxinput_qws.cpp deleted file mode 100644 index 71910b41e7..0000000000 --- a/src/gui/embedded/qkbdlinuxinput_qws.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbdlinuxinput_qws.h" - -#ifndef QT_NO_QWS_KEYBOARD - -#include <QSocketNotifier> -#include <QStringList> - -#include <qplatformdefs.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <errno.h> -#include <termios.h> - -#include <linux/kd.h> -#include <linux/input.h> - -QT_BEGIN_NAMESPACE - - -class QWSLinuxInputKbPrivate : public QObject -{ - Q_OBJECT -public: - QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *, const QString &); - ~QWSLinuxInputKbPrivate(); - -private: - void switchLed(int, bool); - -private Q_SLOTS: - void readKeycode(); - -private: - QWSLinuxInputKeyboardHandler *m_handler; - int m_fd; - int m_tty_fd; - struct termios m_tty_attr; - int m_orig_kbmode; -}; - -QWSLinuxInputKeyboardHandler::QWSLinuxInputKeyboardHandler(const QString &device) - : QWSKeyboardHandler(device) -{ - d = new QWSLinuxInputKbPrivate(this, device); -} - -QWSLinuxInputKeyboardHandler::~QWSLinuxInputKeyboardHandler() -{ - delete d; -} - -bool QWSLinuxInputKeyboardHandler::filterInputEvent(quint16 &, qint32 &) -{ - return false; -} - -QWSLinuxInputKbPrivate::QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *h, const QString &device) - : m_handler(h), m_fd(-1), m_tty_fd(-1), m_orig_kbmode(K_XLATE) -{ - setObjectName(QLatin1String("LinuxInputSubsystem Keyboard Handler")); - - QString dev = QLatin1String("/dev/input/event1"); - int repeat_delay = -1; - int repeat_rate = -1; - - QStringList args = device.split(QLatin1Char(':')); - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("repeat-delay="))) - repeat_delay = arg.mid(13).toInt(); - else if (arg.startsWith(QLatin1String("repeat-rate="))) - repeat_rate = arg.mid(12).toInt(); - else if (arg.startsWith(QLatin1String("/dev/"))) - dev = arg; - } - - m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0); - if (m_fd >= 0) { - if (repeat_delay > 0 && repeat_rate > 0) { - int kbdrep[2] = { repeat_delay, repeat_rate }; - ::ioctl(m_fd, EVIOCSREP, kbdrep); - } - - QSocketNotifier *notifier; - notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); - connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode())); - - // play nice in case we are started from a shell (e.g. for debugging) - m_tty_fd = isatty(0) ? 0 : -1; - - if (m_tty_fd >= 0) { - // save tty config for restore. - tcgetattr(m_tty_fd, &m_tty_attr); - - struct ::termios termdata; - tcgetattr(m_tty_fd, &termdata); - - // record the original mode so we can restore it again in the destructor. - ::ioctl(m_tty_fd, KDGKBMODE, &m_orig_kbmode); - - // setting this translation mode is even needed in INPUT mode to prevent - // the shell from also interpreting codes, if the process has a tty - // attached: e.g. Ctrl+C wouldn't copy, but kill the application. - ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW); - - // set the tty layer to pass-through - termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); - termdata.c_oflag = 0; - termdata.c_cflag = CREAD | CS8; - termdata.c_lflag = 0; - termdata.c_cc[VTIME]=0; - termdata.c_cc[VMIN]=1; - cfsetispeed(&termdata, 9600); - cfsetospeed(&termdata, 9600); - tcsetattr(m_tty_fd, TCSANOW, &termdata); - } - } else { - qWarning("Cannot open keyboard input device '%s': %s", qPrintable(dev), strerror(errno)); - return; - } -} - -QWSLinuxInputKbPrivate::~QWSLinuxInputKbPrivate() -{ - if (m_tty_fd >= 0) { - ::ioctl(m_tty_fd, KDSKBMODE, m_orig_kbmode); - tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr); - } - if (m_fd >= 0) - QT_CLOSE(m_fd); -} - -void QWSLinuxInputKbPrivate::switchLed(int led, bool state) -{ - struct ::input_event led_ie; - ::gettimeofday(&led_ie.time, 0); - led_ie.type = EV_LED; - led_ie.code = led; - led_ie.value = state; - - QT_WRITE(m_fd, &led_ie, sizeof(led_ie)); -} - -void QWSLinuxInputKbPrivate::readKeycode() -{ - struct ::input_event buffer[32]; - int n = 0; - - forever { - n = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); - - if (n == 0) { - qWarning("Got EOF from the input device."); - return; - } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) { - qWarning("Could not read from input device: %s", strerror(errno)); - return; - } else if (n % sizeof(buffer[0]) == 0) { - break; - } - } - - n /= sizeof(buffer[0]); - - for (int i = 0; i < n; ++i) { - if (buffer[i].type != EV_KEY) - continue; - - quint16 code = buffer[i].code; - qint32 value = buffer[i].value; - - if (m_handler->filterInputEvent(code, value)) - continue; - - QWSKeyboardHandler::KeycodeAction ka; - ka = m_handler->processKeycode(code, value != 0, value == 2); - - switch (ka) { - case QWSKeyboardHandler::CapsLockOn: - case QWSKeyboardHandler::CapsLockOff: - switchLed(LED_CAPSL, ka == QWSKeyboardHandler::CapsLockOn); - break; - - case QWSKeyboardHandler::NumLockOn: - case QWSKeyboardHandler::NumLockOff: - switchLed(LED_NUML, ka == QWSKeyboardHandler::NumLockOn); - break; - - case QWSKeyboardHandler::ScrollLockOn: - case QWSKeyboardHandler::ScrollLockOff: - switchLed(LED_SCROLLL, ka == QWSKeyboardHandler::ScrollLockOn); - break; - - default: - // ignore console switching and reboot - break; - } - } -} - -QT_END_NAMESPACE - -#include "qkbdlinuxinput_qws.moc" - -#endif // QT_NO_QWS_KEYBOARD diff --git a/src/gui/embedded/qkbdlinuxinput_qws.h b/src/gui/embedded/qkbdlinuxinput_qws.h deleted file mode 100644 index 4cd45de854..0000000000 --- a/src/gui/embedded/qkbdlinuxinput_qws.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDLINUXINPUT_QWS_H -#define QKBDLINUXINPUT_QWS_H - -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -#ifndef QT_NO_QWS_KBD_LINUXINPUT - -class QWSLinuxInputKbPrivate; - -class QWSLinuxInputKeyboardHandler : public QWSKeyboardHandler -{ -public: - QWSLinuxInputKeyboardHandler(const QString&); - virtual ~QWSLinuxInputKeyboardHandler(); - - virtual bool filterInputEvent(quint16 &input_code, qint32 &input_value); - -private: - QWSLinuxInputKbPrivate *d; -}; - -#endif // QT_NO_QWS_KBD_LINUXINPUT - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDLINUXINPUT_QWS_H diff --git a/src/gui/embedded/qkbdqnx_qws.cpp b/src/gui/embedded/qkbdqnx_qws.cpp deleted file mode 100644 index 87e658d35a..0000000000 --- a/src/gui/embedded/qkbdqnx_qws.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbdqnx_qws.h" -#include "QtCore/qsocketnotifier.h" -#include "QtCore/qdebug.h" - -#include <sys/dcmd_input.h> -#include <photon/keycodes.h> - -#include "qplatformdefs.h" -#include <errno.h> - - -QT_BEGIN_NAMESPACE - -/*! - \class QWSQnxKeyboardHandler - \preliminary - \ingroup qws - \since 4.6 - \internal - - \brief The QWSQnxKeyboardHandler class implements a keyboard driver - for the QNX \c{devi-hid} input manager. - - To be able to compile this mouse handler, \l{Qt for Embedded Linux} - must be configured with the \c -qt-kbd-qnx option, see the - \l{Qt for Embedded Linux Character Input} documentation for details. - - In order to use this keyboard handler, the \c{devi-hid} input manager - must be set up and run with the resource manager interface (option \c{-r}). - Also, Photon must not be running. - - Example invocation from command line: \c{/usr/photon/bin/devi-hid -Pr kbd mouse} - Note that after running \c{devi-hid}, you will not be able to use the local - shell anymore. It is suggested to run the command in a shell scrip, that launches - a Qt application after invocation of \c{devi-hid}. - - To make \l{Qt for Embedded Linux} explicitly choose the qnx keyboard - handler, set the QWS_KEYBOARD environment variable to \c{qnx}. By default, - the first keyboard device (\c{/dev/devi/keyboard0}) is used. To override, pass a device - name as the first and only parameter, for example - \c{QWS_KEYBOARD=qnx:/dev/devi/keyboard1; export QWS_KEYBOARD}. - - \sa {Qt for Embedded Linux Character Input}, {Qt for Embedded Linux} -*/ - -/*! - Constructs a keyboard handler for the specified \a device, defaulting to - \c{/dev/devi/keyboard0}. - - Note that you should never instanciate this class, instead let QKbdDriverFactory - handle the keyboard handlers. - - \sa QKbdDriverFactory - */ -QWSQnxKeyboardHandler::QWSQnxKeyboardHandler(const QString &device) -{ - // open the keyboard device - keyboardFD = QT_OPEN(device.isEmpty() ? "/dev/devi/keyboard0" : device.toLatin1().constData(), - QT_OPEN_RDONLY); - if (keyboardFD == -1) { - qErrnoWarning(errno, "QWSQnxKeyboardHandler: Unable to open device"); - return; - } - - // create a socket notifier so we'll wake up whenever keyboard input is detected. - QSocketNotifier *notifier = new QSocketNotifier(keyboardFD, QSocketNotifier::Read, this); - connect(notifier, SIGNAL(activated(int)), SLOT(socketActivated())); - - qDebug() << "QWSQnxKeyboardHandler: connected."; - -} - -/*! - Destroys this keyboard handler and closes the connection to the keyboard device. - */ -QWSQnxKeyboardHandler::~QWSQnxKeyboardHandler() -{ - QT_CLOSE(keyboardFD); -} - -/*! \internal - Translates the QNX keyboard events to Qt keyboard events - */ -void QWSQnxKeyboardHandler::socketActivated() -{ - _keyboard_packet packet; - - // read one keyboard event - int bytesRead = QT_READ(keyboardFD, &packet, sizeof(_keyboard_packet)); - if (bytesRead == -1) { - qErrnoWarning(errno, "QWSQnxKeyboardHandler::socketActivated(): Unable to read data."); - return; - } - - // the bytes read must be the size of a keyboard packet - Q_ASSERT(bytesRead == sizeof(_keyboard_packet)); - -#if 0 - qDebug() << "keyboard got scancode" - << hex << packet.data.modifiers - << packet.data.flags - << packet.data.key_cap - << packet.data.key_sym - << packet.data.key_scan; -#endif - - // QNX is nice enough to translate the raw keyboard data into a QNX data structure - // Now we just have to translate it into a format Qt understands. - - // figure out whether it's a press - bool isPress = packet.data.key_cap & KEY_DOWN; - // figure out whether the key is still pressed and the key event is repeated - bool isRepeat = packet.data.key_cap & KEY_REPEAT; - - Qt::Key key = Qt::Key_unknown; - int unicode = 0xffff; - - // TODO - this switch is not complete! - switch (packet.data.key_scan) { - case KEYCODE_SPACE: key = Qt::Key_Space; unicode = 0x20; break; - case KEYCODE_F1: key = Qt::Key_F1; break; - case KEYCODE_F2: key = Qt::Key_F2; break; - case KEYCODE_F3: key = Qt::Key_F3; break; - case KEYCODE_F4: key = Qt::Key_F4; break; - case KEYCODE_F5: key = Qt::Key_F5; break; - case KEYCODE_F6: key = Qt::Key_F6; break; - case KEYCODE_F7: key = Qt::Key_F7; break; - case KEYCODE_F8: key = Qt::Key_F8; break; - case KEYCODE_F9: key = Qt::Key_F9; break; - case KEYCODE_F10: key = Qt::Key_F10; break; - case KEYCODE_F11: key = Qt::Key_F11; break; - case KEYCODE_F12: key = Qt::Key_F12; break; - case KEYCODE_BACKSPACE: key = Qt::Key_Backspace; break; - case KEYCODE_TAB: key = Qt::Key_Tab; break; - case KEYCODE_RETURN: key = Qt::Key_Return; break; - case KEYCODE_KP_ENTER: key = Qt::Key_Enter; break; - case KEYCODE_UP: - case KEYCODE_KP_UP: - key = Qt::Key_Up; break; - case KEYCODE_DOWN: - case KEYCODE_KP_DOWN: - key = Qt::Key_Down; break; - case KEYCODE_LEFT: - case KEYCODE_KP_LEFT: - key = Qt::Key_Left; break; - case KEYCODE_RIGHT: - case KEYCODE_KP_RIGHT: - key = Qt::Key_Right; break; - case KEYCODE_HOME: - case KEYCODE_KP_HOME: - key = Qt::Key_Home; break; - case KEYCODE_END: - case KEYCODE_KP_END: - key = Qt::Key_End; break; - case KEYCODE_PG_UP: - case KEYCODE_KP_PG_UP: - key = Qt::Key_PageUp; break; - case KEYCODE_PG_DOWN: - case KEYCODE_KP_PG_DOWN: - key = Qt::Key_PageDown; break; - case KEYCODE_INSERT: - case KEYCODE_KP_INSERT: - key = Qt::Key_Insert; break; - case KEYCODE_DELETE: - case KEYCODE_KP_DELETE: - key = Qt::Key_Delete; break; - case KEYCODE_ESCAPE: - key = Qt::Key_Escape; break; - default: // none of the above, try the key_scan directly - unicode = packet.data.key_scan; - break; - } - - // figure out the modifiers that are currently pressed - Qt::KeyboardModifiers modifiers = Qt::NoModifier; - if (packet.data.flags & KEYMOD_SHIFT) - modifiers |= Qt::ShiftModifier; - if (packet.data.flags & KEYMOD_CTRL) - modifiers |= Qt::ControlModifier; - if (packet.data.flags & KEYMOD_ALT) - modifiers |= Qt::AltModifier; - - // if the unicode value is not ascii, we ignore it. - // TODO - do a complete mapping between all QNX scan codes and Qt codes - if (unicode != 0xffff && !isascii(unicode)) - return; // unprintable character - - // call processKeyEvent. This is where all the magic happens to insert a - // key event into Qt's event loop. - // Note that for repeated key events, isPress must be true - // (on QNX, isPress is not set when the key event is repeated). - processKeyEvent(unicode, key, modifiers, isPress || isRepeat, isRepeat); -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qkbdqnx_qws.h b/src/gui/embedded/qkbdqnx_qws.h deleted file mode 100644 index 1615a42fd7..0000000000 --- a/src/gui/embedded/qkbdqnx_qws.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDQNX_QWS_H -#define QKBDQNX_QWS_H - -#include <QtGui/qapplication.h> -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_QNX) - -class Q_GUI_EXPORT QWSQnxKeyboardHandler : public QObject, public QWSKeyboardHandler -{ - Q_OBJECT -public: - QWSQnxKeyboardHandler(const QString &device); - ~QWSQnxKeyboardHandler(); - -private Q_SLOTS: - void socketActivated(); - -private: - int keyboardFD; -}; - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDQNX_QWS_H diff --git a/src/gui/embedded/qkbdtty_qws.cpp b/src/gui/embedded/qkbdtty_qws.cpp deleted file mode 100644 index c4b7df2d9b..0000000000 --- a/src/gui/embedded/qkbdtty_qws.cpp +++ /dev/null @@ -1,353 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbdtty_qws.h" - -#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_TTY) - -#include <QSocketNotifier> -#include <QStringList> - -#include <qplatformdefs.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <errno.h> -#include <termios.h> - -#if defined Q_OS_LINUX -# include <linux/kd.h> -# include <linux/vt.h> //TODO: move vt handling somewhere else (QLinuxFbScreen?) - -# include "qscreen_qws.h" -# include "qwindowsystem_qws.h" -# include "qapplication.h" -# include "private/qwindowsurface_qws_p.h" -# include "private/qwssignalhandler_p.h" - -# define VTACQSIG SIGUSR1 -# define VTRELSIG SIGUSR2 -#endif - - -QT_BEGIN_NAMESPACE - -class QWSTtyKbPrivate : public QObject -{ - Q_OBJECT -public: - QWSTtyKbPrivate(QWSTtyKeyboardHandler *handler, const QString &device); - ~QWSTtyKbPrivate(); - -private: - void switchLed(char, bool); - void switchConsole(int vt); - -private Q_SLOTS: - void readKeycode(); - void handleConsoleSwitch(int sig); - -private: - QWSTtyKeyboardHandler *m_handler; - int m_tty_fd; - struct termios m_tty_attr; - char m_last_keycode; - int m_vt_qws; - int m_orig_kbmode; -}; - - -QWSTtyKeyboardHandler::QWSTtyKeyboardHandler(const QString &device) - : QWSKeyboardHandler(device) -{ - d = new QWSTtyKbPrivate(this, device); -} - -QWSTtyKeyboardHandler::~QWSTtyKeyboardHandler() -{ - delete d; -} - -bool QWSTtyKeyboardHandler::filterKeycode(char &) -{ - return false; -} - -QWSTtyKbPrivate::QWSTtyKbPrivate(QWSTtyKeyboardHandler *h, const QString &device) - : m_handler(h), m_tty_fd(-1), m_last_keycode(0), m_vt_qws(0), m_orig_kbmode(K_XLATE) -{ - setObjectName(QLatin1String("TTY Keyboard Handler")); -#ifndef QT_NO_QWS_SIGNALHANDLER - QWSSignalHandler::instance()->addObject(this); -#endif - - QString dev = QLatin1String("/dev/tty0"); - int repeat_delay = -1; - int repeat_rate = -1; - - QStringList args = device.split(QLatin1Char(':')); - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("repeat-delay="))) - repeat_delay = arg.mid(13).toInt(); - else if (arg.startsWith(QLatin1String("repeat-rate="))) - repeat_rate = arg.mid(12).toInt(); - else if (arg.startsWith(QLatin1String("/dev/"))) - dev = arg; - } - - m_tty_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0); - if (m_tty_fd >= 0) { - if (repeat_delay > 0 && repeat_rate > 0) { -#if defined(Q_OS_LINUX) - struct ::kbd_repeat kbdrep = { repeat_delay, repeat_rate }; - ::ioctl(m_tty_fd, KDKBDREP, &kbdrep); -#endif - } - - QSocketNotifier *notifier; - notifier = new QSocketNotifier(m_tty_fd, QSocketNotifier::Read, this); - connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode())); - - // save tty config for restore. - tcgetattr(m_tty_fd, &m_tty_attr); - - struct ::termios termdata; - tcgetattr(m_tty_fd, &termdata); - -#if defined(Q_OS_LINUX) - // record the original mode so we can restore it again in the destructor. - ::ioctl(m_tty_fd, KDGKBMODE, &m_orig_kbmode); - - // PLEASE NOTE: - // the tty keycode interface can only report keycodes 0x01 .. 0x7f - // KEY_MAX is however defined to 0x1ff. In practice this is sufficient - // for a PC style keyboard though. - // we don't support K_RAW anymore - if you need that, you have to add - // a scan- to keycode converter yourself. - ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW); -#endif - - // set the tty layer to pass-through - termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); - termdata.c_oflag = 0; - termdata.c_cflag = CREAD | CS8; - termdata.c_lflag = 0; - termdata.c_cc[VTIME]=0; - termdata.c_cc[VMIN]=1; - cfsetispeed(&termdata, 9600); - cfsetospeed(&termdata, 9600); - tcsetattr(m_tty_fd, TCSANOW, &termdata); - -#if defined(Q_OS_LINUX) - // VT switching is handled via unix signals - connect(QApplication::instance(), SIGNAL(unixSignal(int)), this, SLOT(handleConsoleSwitch(int))); - QApplication::instance()->watchUnixSignal(VTACQSIG, true); - QApplication::instance()->watchUnixSignal(VTRELSIG, true); - - struct ::vt_mode vtMode; - if (::ioctl(m_tty_fd, VT_GETMODE, &vtMode) == 0) { - vtMode.mode = VT_PROCESS; - vtMode.relsig = VTRELSIG; - vtMode.acqsig = VTACQSIG; - - if (::ioctl(m_tty_fd, VT_SETMODE, &vtMode) == 0) { - struct ::vt_stat vtStat; - ::memset(&vtStat, 0, sizeof(vtStat)); - - if (::ioctl(m_tty_fd, VT_GETSTATE, &vtStat) == 0 ) { - m_vt_qws = vtStat.v_active; - } - } - } - - if (!m_vt_qws) - qWarning("Could not initialize virtual console switching"); -#endif - } else { - qWarning("Cannot open input device '%s': %s", qPrintable(dev), strerror(errno)); - return; - } - -} - -QWSTtyKbPrivate::~QWSTtyKbPrivate() -{ - if (m_tty_fd >= 0) { -#if defined(Q_OS_LINUX) - ::ioctl(m_tty_fd, KDSKBMODE, m_orig_kbmode); -#endif - tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr); - QT_CLOSE(m_tty_fd); - } -} - - - -void QWSTtyKbPrivate::switchLed(char led, bool state) -{ -#if defined(Q_OS_LINUX) - char ledstate; - - ::ioctl(m_tty_fd, KDGETLED, &ledstate); - if (state) - ledstate |= led; - else - ledstate &= ~led; - ::ioctl(m_tty_fd, KDSETLED, ledstate); -#endif -} - -void QWSTtyKbPrivate::readKeycode() -{ - char buffer[32]; - int n = 0; - - forever { - n = QT_READ(m_tty_fd, buffer + n, 32 - n); - - if (n == 0) { - qWarning("Got EOF from the input device."); - return; - } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) { - qWarning("Could not read from input device: %s", strerror(errno)); - return; - } else { - break; - } - } - - for (int i = 0; i < n; ++i) { - if (m_handler->filterKeycode(buffer[i])) - continue; - - QWSKeyboardHandler::KeycodeAction ka; - ka = m_handler->processKeycode(buffer[i] & 0x7f, (buffer[i] & 0x80) == 0x00, buffer[i] == m_last_keycode); - m_last_keycode = buffer[i]; - - switch (ka) { - case QWSKeyboardHandler::CapsLockOn: - case QWSKeyboardHandler::CapsLockOff: - switchLed(LED_CAP, ka == QWSKeyboardHandler::CapsLockOn); - break; - - case QWSKeyboardHandler::NumLockOn: - case QWSKeyboardHandler::NumLockOff: - switchLed(LED_NUM, ka == QWSKeyboardHandler::NumLockOn); - break; - - case QWSKeyboardHandler::ScrollLockOn: - case QWSKeyboardHandler::ScrollLockOff: - switchLed(LED_SCR, ka == QWSKeyboardHandler::ScrollLockOn); - break; - - case QWSKeyboardHandler::PreviousConsole: - switchConsole(qBound(1, m_vt_qws - 1, 10)); - break; - - case QWSKeyboardHandler::NextConsole: - switchConsole(qBound(1, m_vt_qws + 1, 10)); - break; - - default: - if (ka >= QWSKeyboardHandler::SwitchConsoleFirst && - ka <= QWSKeyboardHandler::SwitchConsoleLast) { - switchConsole(1 + (ka & QWSKeyboardHandler::SwitchConsoleMask)); - } - //ignore reboot - break; - } - } -} - - -void QWSTtyKbPrivate::switchConsole(int vt) -{ -#if defined(Q_OS_LINUX) - if (m_vt_qws && vt && (m_tty_fd >= 0 )) - ::ioctl(m_tty_fd, VT_ACTIVATE, vt); -#endif -} - -void QWSTtyKbPrivate::handleConsoleSwitch(int sig) -{ -#if defined(Q_OS_LINUX) - // received a notification from the kernel that the current VT is - // changing: either enable or disable QWS painting accordingly. - - if (sig == VTACQSIG) { - if (::ioctl(m_tty_fd, VT_RELDISP, VT_ACKACQ) == 0) { - qwsServer->enablePainting(true); - qt_screen->restore(); - qwsServer->resumeMouse(); - qwsServer->refresh(); - } - } else if (sig == VTRELSIG) { - qwsServer->enablePainting(false); - - // Check for reserved surfaces which might still do painting - bool allWindowsHidden = true; - const QList<QWSWindow*> windows = QWSServer::instance()->clientWindows(); - for (int i = 0; i < windows.size(); ++i) { - const QWSWindow *w = windows.at(i); - QWSWindowSurface *s = w->windowSurface(); - if (s && s->isRegionReserved() && !w->allocatedRegion().isEmpty()) { - allWindowsHidden = false; - break; - } - } - - if (!allWindowsHidden) { - ::ioctl(m_tty_fd, VT_RELDISP, 0); // abort console switch - qwsServer->enablePainting(true); - } else if (::ioctl(m_tty_fd, VT_RELDISP, 1) == 0) { - qt_screen->save(); - qwsServer->suspendMouse(); - } else { - qwsServer->enablePainting(true); - } - } -#endif -} - -QT_END_NAMESPACE - -#include "qkbdtty_qws.moc" - -#endif // QT_NO_QWS_KEYBOARD || QT_NO_QWS_KBD_TTY diff --git a/src/gui/embedded/qkbdtty_qws.h b/src/gui/embedded/qkbdtty_qws.h deleted file mode 100644 index 373342b87b..0000000000 --- a/src/gui/embedded/qkbdtty_qws.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDTTY_QWS_H -#define QKBDTTY_QWS_H - -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -#ifndef QT_NO_QWS_KBD_TTY - -class QWSTtyKbPrivate; - -class QWSTtyKeyboardHandler : public QWSKeyboardHandler -{ -public: - explicit QWSTtyKeyboardHandler(const QString&); - virtual ~QWSTtyKeyboardHandler(); - - virtual bool filterKeycode(char &code); - -private: - QWSTtyKbPrivate *d; -}; - -#endif // QT_NO_QWS_KBD_TTY - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDTTY_QWS_H diff --git a/src/gui/embedded/qkbdum_qws.cpp b/src/gui/embedded/qkbdum_qws.cpp deleted file mode 100644 index cfdaa2eed1..0000000000 --- a/src/gui/embedded/qkbdum_qws.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkbdum_qws.h" -#include "qvfbhdr.h" - -#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_UM) - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <qstring.h> -#include <qwindowsystem_qws.h> -#include <qsocketnotifier.h> -#include "qplatformdefs.h" - -QT_BEGIN_NAMESPACE - -class QWSUmKeyboardHandlerPrivate : public QObject -{ - Q_OBJECT - -public: - QWSUmKeyboardHandlerPrivate(const QString&); - ~QWSUmKeyboardHandlerPrivate(); - -private slots: - void readKeyboardData(); - -private: - int kbdFD; - int kbdIdx; - const int kbdBufferLen; - unsigned char *kbdBuffer; - QSocketNotifier *notifier; -}; - -QWSUmKeyboardHandlerPrivate::QWSUmKeyboardHandlerPrivate(const QString &device) - : kbdFD(-1), kbdIdx(0), kbdBufferLen(sizeof(QVFbKeyData)*5) -{ - kbdBuffer = new unsigned char [kbdBufferLen]; - - if ((kbdFD = QT_OPEN((const char *)device.toLocal8Bit(), O_RDONLY | O_NDELAY, 0)) < 0) { - qDebug("Cannot open %s (%s)", (const char *)device.toLocal8Bit(), - strerror(errno)); - } else { - // Clear pending input - char buf[2]; - while (QT_READ(kbdFD, buf, 1) > 0) { } - - notifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this); - connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData())); - } -} - -QWSUmKeyboardHandlerPrivate::~QWSUmKeyboardHandlerPrivate() -{ - if (kbdFD >= 0) - QT_CLOSE(kbdFD); - delete [] kbdBuffer; -} - - -void QWSUmKeyboardHandlerPrivate::readKeyboardData() -{ - int n; - do { - n = QT_READ(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx); - if (n > 0) - kbdIdx += n; - } while (n > 0); - - int idx = 0; - while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) { - QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx); - // Qtopia Key filters must still work. - QWSServer::processKeyEvent(kd->unicode, kd->keycode, kd->modifiers, kd->press, kd->repeat); - idx += sizeof(QVFbKeyData); - } - - int surplus = kbdIdx - idx; - for (int i = 0; i < surplus; i++) - kbdBuffer[i] = kbdBuffer[idx+i]; - kbdIdx = surplus; -} - -QWSUmKeyboardHandler::QWSUmKeyboardHandler(const QString &device) - : QWSKeyboardHandler() -{ - d = new QWSUmKeyboardHandlerPrivate(device); -} - -QWSUmKeyboardHandler::~QWSUmKeyboardHandler() -{ - delete d; -} - -QT_END_NAMESPACE - -#include "qkbdum_qws.moc" - -#endif // QT_NO_QWS_KEYBOARD && QT_NO_QWS_KBD_UM diff --git a/src/gui/embedded/qkbdum_qws.h b/src/gui/embedded/qkbdum_qws.h deleted file mode 100644 index fd21c4875a..0000000000 --- a/src/gui/embedded/qkbdum_qws.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDUM_QWS_H -#define QKBDUM_QWS_H - -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -#ifndef QT_NO_QWS_KBD_UM - -class QWSUmKeyboardHandlerPrivate; - -class QWSUmKeyboardHandler : public QWSKeyboardHandler -{ -public: - QWSUmKeyboardHandler(const QString &); - virtual ~QWSUmKeyboardHandler(); - -private: - - QWSUmKeyboardHandlerPrivate *d; -}; -#endif // QT_NO_QWS_KBD_UM - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDUM_QWS_H diff --git a/src/gui/embedded/qkbdvfb_qws.cpp b/src/gui/embedded/qkbdvfb_qws.cpp deleted file mode 100644 index a626ef5e13..0000000000 --- a/src/gui/embedded/qkbdvfb_qws.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <qvfbhdr.h> -#include <qkbdvfb_qws.h> - -#ifndef QT_NO_QWS_KEYBOARD -#ifndef QT_NO_QWS_KBD_QVFB - -#include <qwindowsystem_qws.h> -#include <qsocketnotifier.h> -#include <qapplication.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -QT_BEGIN_NAMESPACE - -QVFbKeyboardHandler::QVFbKeyboardHandler(const QString &device) - : QObject() -{ - terminalName = device; - if (terminalName.isEmpty()) - terminalName = QLatin1String("/dev/vkdb"); - kbdFD = -1; - kbdIdx = 0; - kbdBufferLen = sizeof(QVFbKeyData) * 5; - kbdBuffer = new unsigned char [kbdBufferLen]; - - if ((kbdFD = QT_OPEN(terminalName.toLatin1().constData(), O_RDONLY | O_NDELAY)) < 0) { - qWarning("Cannot open %s (%s)", terminalName.toLatin1().constData(), - strerror(errno)); - } else { - // Clear pending input - char buf[2]; - while (QT_READ(kbdFD, buf, 1) > 0) { } - - notifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this); - connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData())); - } -} - -QVFbKeyboardHandler::~QVFbKeyboardHandler() -{ - if (kbdFD >= 0) - QT_CLOSE(kbdFD); - delete [] kbdBuffer; -} - - -void QVFbKeyboardHandler::readKeyboardData() -{ - int n; - do { - n = QT_READ(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx); - if (n > 0) - kbdIdx += n; - } while (n > 0); - - int idx = 0; - while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) { - QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx); - if (kd->unicode == 0 && kd->keycode == 0 && kd->modifiers == 0 && kd->press) { - // magic exit key - qWarning("Instructed to quit by Virtual Keyboard"); - qApp->quit(); - } - QWSServer::processKeyEvent(kd->unicode ? kd->unicode : 0xffff, kd->keycode, kd->modifiers, kd->press, kd->repeat); - idx += sizeof(QVFbKeyData); - } - - int surplus = kbdIdx - idx; - for (int i = 0; i < surplus; i++) - kbdBuffer[i] = kbdBuffer[idx+i]; - kbdIdx = surplus; -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_KBD_QVFB -#endif // QT_NO_QWS_KEYBOARD diff --git a/src/gui/embedded/qkbdvfb_qws.h b/src/gui/embedded/qkbdvfb_qws.h deleted file mode 100644 index c99a6df006..0000000000 --- a/src/gui/embedded/qkbdvfb_qws.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QKBDVFB_QWS_H -#define QKBDVFB_QWS_H - -#include <QtGui/qkbd_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_KEYBOARD - -#ifndef QT_NO_QWS_KBD_QVFB - -class QSocketNotifier; - -class QVFbKeyboardHandler : public QObject, public QWSKeyboardHandler -{ - Q_OBJECT -public: - QVFbKeyboardHandler(const QString &device); - virtual ~QVFbKeyboardHandler(); - -private Q_SLOTS: - void readKeyboardData(); - -private: - QString terminalName; - int kbdFD; - int kbdIdx; - int kbdBufferLen; - unsigned char *kbdBuffer; - QSocketNotifier *notifier; -}; - -#endif // QT_NO_QWS_KBD_QVFB - -#endif // QT_NO_QWS_KEYBOARD - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QKBDVFB_QWS_H diff --git a/src/gui/embedded/qmouse_qws.cpp b/src/gui/embedded/qmouse_qws.cpp deleted file mode 100644 index c373b916ca..0000000000 --- a/src/gui/embedded/qmouse_qws.cpp +++ /dev/null @@ -1,653 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmouse_qws.h" -#include "qwindowsystem_qws.h" -#include "qscreen_qws.h" -#include "qapplication.h" -#include "qtextstream.h" -#include "qfile.h" -#include "qdebug.h" -#include "qscreen_qws.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QWSPointerCalibrationData - \ingroup qws - - \brief The QWSPointerCalibrationData class is a container for - mouse calibration data in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QWSPointerCalibrationData stores device and screen coordinates in - the devPoints and screenPoints variables, respectively. - - A calibration program should create a QWSPointerCalibrationData - object, fill the devPoints and screenPoints variables with its - device and screen coordinates, and pass the object to the mouse - driver using the QWSMouseHandler::calibrate() function. - - \sa QWSCalibratedMouseHandler, {Mouse Calibration Example} -*/ - -/*! - \variable QWSPointerCalibrationData::devPoints - \brief the raw device coordinates for each value of the Location enum. -*/ - -/*! - \variable QWSPointerCalibrationData::screenPoints - \brief the logical screen coordinates for each value of the Location enum. -*/ - -/*! - \enum QWSPointerCalibrationData::Location - - This enum describes the various logical positions that can be - specified by the devPoints and screenPoints variables. - - \value TopLeft Index of the top left corner of the screen. - \value BottomLeft Index of the bottom left corner of the screen. - \value BottomRight Index of the bottom right corner of the screen. - \value TopRight Index of the top right corner of the screen. - \value Center Index of the center of the screen. - \value LastLocation Last index in the pointer arrays. -*/ - -class QWSMouseHandlerPrivate -{ -public: - QWSMouseHandlerPrivate() : screen(qt_screen) {} - - const QScreen *screen; -}; - -/*! - \class QWSMouseHandler - \ingroup qws - - \brief The QWSMouseHandler class is a base class for mouse drivers in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several mouse - protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer - handling} documentation for details. Custom mouse drivers can be - implemented by subclassing the QWSMouseHandler class and creating - a mouse driver plugin (derived from QMouseDriverPlugin). - The default implementation of the QMouseDriverFactory class - will automatically detect the plugin, and load the driver into the - server application at run-time using Qt's \l {How to Create Qt - Plugins}{plugin system}. - - The mouse driver receives mouse events from the system device and - encapsulates each event with an instance of the QWSEvent class - which it then passes to the server application (the server is - responsible for propagating the event to the appropriate - client). To receive mouse events, a QWSMouseHandler object will - usually create a QSocketNotifier object for the given device. The - QSocketNotifier class provides support for monitoring activity on - a file descriptor. When the socket notifier receives data, it will - call the mouse driver's mouseChanged() function to send the event - to the \l{Qt for Embedded Linux} server application for relaying to - clients. - - If you are creating a driver for a device that needs calibration - or noise reduction, such as a touchscreen, use the - QWSCalibratedMouseHandler subclass instead to take advantage of - the calibrate() and clearCalibration() functions. The \l - {qws/mousecalibration}{Mouse Calibration} - demonstrates how to write a simple program using the mechanisms - provided by the QWSMouseHandler class to calibrate a mouse driver. - - Note that when deriving from the QWSMouseHandler class, the - resume() and suspend() functions must be reimplemented to control - the flow of mouse input, i.e., the default implementation does - nothing. Reimplementations of these functions typically call the - QSocketNotifier::setEnabled() function to enable or disable the - socket notifier, respectively. - - In addition, QWSMouseHandler provides the setScreen() function - that allows you to specify a screen for your mouse driver and the - limitToScreen() function that ensures that a given position is - within this screen's boundaries (changing the position if - necessary). Finally, QWSMouseHandler provides the pos() function - returning the current mouse position. - - \sa QMouseDriverPlugin, QMouseDriverFactory, {Qt for Embedded Linux Pointer - Handling} -*/ - - -/*! - \fn void QWSMouseHandler::suspend() - - Implement this function to suspend reading and handling of mouse - events, e.g., call the QSocketNotifier::setEnabled() function to - disable the socket notifier. - - \sa resume() -*/ - -/*! - \fn void QWSMouseHandler::resume() - - Implement this function to resume reading and handling mouse - events, e.g., call the QSocketNotifier::setEnabled() function to - enable the socket notifier. - - \sa suspend() -*/ - -/*! - \fn const QPoint &QWSMouseHandler::pos() const - - Returns the current mouse position. - - \sa mouseChanged(), limitToScreen() -*/ - -/*! - Constructs a mouse driver. The \a driver and \a device arguments - are passed by the QWS_MOUSE_PROTO environment variable. - - Call the QWSServer::setMouseHandler() function to make the newly - created mouse driver, the primary driver. Note that the primary - driver is controlled by the system, i.e., the system will delete - it upon exit. -*/ -QWSMouseHandler::QWSMouseHandler(const QString &, const QString &) - : mousePos(QWSServer::mousePosition), d_ptr(new QWSMouseHandlerPrivate) -{ -} - -/*! - Destroys this mouse driver. - - Do not call this function if this driver is the primary mouse - driver, i.e., if QWSServer::setMouseHandler() function has been - called passing this driver as argument. The primary mouse - driver is deleted by the system. -*/ -QWSMouseHandler::~QWSMouseHandler() -{ - delete d_ptr; -} - -/*! - Ensures that the given \a position is within the screen's - boundaries, changing the \a position if necessary. - - \sa pos(), setScreen() -*/ - -void QWSMouseHandler::limitToScreen(QPoint &position) -{ - position.setX(qMin(d_ptr->screen->deviceWidth() - 1, qMax(0, position.x()))); - position.setY(qMin(d_ptr->screen->deviceHeight() - 1, qMax(0, position.y()))); -} - -/*! - \since 4.2 - - Sets the screen for this mouse driver to be the given \a screen. - - \sa limitToScreen() -*/ -void QWSMouseHandler::setScreen(const QScreen *screen) -{ - d_ptr->screen = (screen ? screen : qt_screen); -} - -/*! - Notifies the system of a new mouse event. - - This function updates the current mouse position and sends the - event to the \l{Qt for Embedded Linux} server application for - delivery to the correct widget. Note that a custom mouse driver must call - this function whenever it wants to deliver a new mouse event. - - The given \a position is the global position of the mouse cursor. - The \a state parameter is a bitmask of the Qt::MouseButton enum's - values, indicating which mouse buttons are pressed. The \a wheel - parameter is the delta value of the mouse wheel as returned by - QWheelEvent::delta(). - - \sa pos() -*/ -void QWSMouseHandler::mouseChanged(const QPoint &position, int state, int wheel) -{ - mousePos = position + d_ptr->screen->offset(); - QWSServer::sendMouseEvent(mousePos, state, wheel); -} - -/*! - \fn QWSMouseHandler::clearCalibration() - - This virtual function allows subclasses of QWSMouseHandler to - clear the calibration information. Note that the default - implementation does nothing. - - \sa QWSCalibratedMouseHandler::clearCalibration(), calibrate() -*/ - -/*! - \fn QWSMouseHandler::calibrate(const QWSPointerCalibrationData *data) - - This virtual function allows subclasses of QWSMouseHandler to set - the calibration information passed in the given \a data. Note that - the default implementation does nothing. - - \sa QWSCalibratedMouseHandler::calibrate(), clearCalibration() -*/ - -/*! \fn QWSMouseHandler::getCalibration(QWSPointerCalibrationData *data) const - This virtual function allows subclasses of QWSMouseHandler - to fill in the device coordinates in \a data with values - that correspond to screen coordinates that are already in - \a data. Note that the default implementation does nothing. - */ - -/*! - \class QWSCalibratedMouseHandler - \ingroup qws - - \brief The QWSCalibratedMouseHandler class provides mouse - calibration and noise reduction in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several mouse - protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer - handling} documentation for details. In general, custom mouse - drivers can be implemented by subclassing the QWSMouseHandler - class. But when the system device does not have a fixed mapping - between device and screen coordinates and/or produces noisy events - (e.g., a touchscreen), you should derive from the - QWSCalibratedMouseHandler class instead to take advantage of its - calibration functionality. As always, you must also create a mouse - driver plugin (derived from QMouseDriverPlugin); - the implementation of the QMouseDriverFactory class will then - automatically detect the plugin, and load the driver into the - server application at run-time using Qt's - \l{How to Create Qt Plugins}{plugin system}. - - QWSCalibratedMouseHandler provides an implementation of the - calibrate() function to update the calibration parameters based on - coordinate mapping of the given calibration data. The calibration - data is represented by an QWSPointerCalibrationData object. The - linear transformation between device coordinates and screen - coordinates is performed by calling the transform() function - explicitly on the points passed to the - QWSMouseHandler::mouseChanged() function. Use the - clearCalibration() function to make the mouse driver return mouse - events in raw device coordinates and not in screen coordinates. - - The calibration parameters are recalculated whenever calibrate() - is called, and they can be stored using the writeCalibration() - function. Previously written parameters can be retrieved at any - time using the readCalibration() function (calibration parameters - are always read when the class is instantiated). Note that the - calibration parameters is written to and read from the file - currently specified by the POINTERCAL_FILE environment variable; - the default file is \c /etc/pointercal. - - To achieve noise reduction, QWSCalibratedMouseHandler provides the - sendFiltered() function. Use this function instead of - mouseChanged() whenever a mouse event occurs. The filter's size - can be manipulated using the setFilterSize() function. - - \sa QWSMouseHandler, QWSPointerCalibrationData, - {Mouse Calibration Example} -*/ - - -/*! - \internal - */ - -QWSCalibratedMouseHandler::QWSCalibratedMouseHandler(const QString &, const QString &) - : samples(5), currSample(0), numSamples(0) -{ - clearCalibration(); - readCalibration(); -} - -/*! - Fills \a cd with the device coordinates corresponding to the given - screen coordinates. - - \internal -*/ -void QWSCalibratedMouseHandler::getCalibration(QWSPointerCalibrationData *cd) const -{ - const qint64 scale = qint64(a) * qint64(e) - qint64(b) * qint64(d); - const qint64 xOff = qint64(b) * qint64(f) - qint64(c) * qint64(e); - const qint64 yOff = qint64(c) * qint64(d) - qint64(a) * qint64(f); - for (int i = 0; i <= QWSPointerCalibrationData::LastLocation; ++i) { - const qint64 sX = cd->screenPoints[i].x(); - const qint64 sY = cd->screenPoints[i].y(); - const qint64 dX = (s*(e*sX - b*sY) + xOff) / scale; - const qint64 dY = (s*(a*sY - d*sX) + yOff) / scale; - cd->devPoints[i] = QPoint(dX, dY); - } -} - -/*! - Clears the current calibration, i.e., makes the mouse - driver return mouse events in raw device coordinates instead of - screen coordinates. - - \sa calibrate() -*/ -void QWSCalibratedMouseHandler::clearCalibration() -{ - a = 1; - b = 0; - c = 0; - d = 0; - e = 1; - f = 0; - s = 1; -} - - -/*! - Saves the current calibration parameters in \c /etc/pointercal - (separated by whitespace and in alphabetical order). - - You can override the default \c /etc/pointercal by specifying - another file using the POINTERCAL_FILE environment variable. - - \sa readCalibration() -*/ -void QWSCalibratedMouseHandler::writeCalibration() -{ - QString calFile; - calFile = QString::fromLocal8Bit(qgetenv("POINTERCAL_FILE")); - if (calFile.isEmpty()) - calFile = QLatin1String("/etc/pointercal"); - -#ifndef QT_NO_TEXTSTREAM - QFile file(calFile); - if (file.open(QIODevice::WriteOnly)) { - QTextStream t(&file); - t << a << ' ' << b << ' ' << c << ' '; - t << d << ' ' << e << ' ' << f << ' ' << s << endl; - } else -#endif - { - qCritical("QWSCalibratedMouseHandler::writeCalibration: " - "Could not save calibration into %s", qPrintable(calFile)); - } -} - -/*! - Reads previously written calibration parameters which are stored - in \c /etc/pointercal (separated by whitespace and in alphabetical - order). - - You can override the default \c /etc/pointercal by specifying - another file using the POINTERCAL_FILE environment variable. - - - \sa writeCalibration() -*/ -void QWSCalibratedMouseHandler::readCalibration() -{ - QString calFile = QString::fromLocal8Bit(qgetenv("POINTERCAL_FILE")); - if (calFile.isEmpty()) - calFile = QLatin1String("/etc/pointercal"); - -#ifndef QT_NO_TEXTSTREAM - QFile file(calFile); - if (file.open(QIODevice::ReadOnly)) { - QTextStream t(&file); - t >> a >> b >> c >> d >> e >> f >> s; - if (s == 0 || t.status() != QTextStream::Ok) { - qCritical("Corrupt calibration data"); - clearCalibration(); - } - } else -#endif - { - qDebug() << "Could not read calibration:" <<calFile; - } -} - -static int ilog2(quint32 n) -{ - int result = 0; - - if (n & 0xffff0000) { - n >>= 16; - result += 16; - } - if (n & 0xff00) { - n >>= 8; - result += 8;} - if (n & 0xf0) { - n >>= 4; - result += 4; - } - if (n & 0xc) { - n >>= 2; - result += 2; - } - if (n & 0x2) - result += 1; - - return result; -} - -/*! - Updates the calibration parameters based on coordinate mapping of - the given \a data. - - Create an instance of the QWSPointerCalibrationData class, fill in - the device and screen coordinates and pass that object to the mouse - driver using this function. - - \sa clearCalibration(), transform() -*/ -void QWSCalibratedMouseHandler::calibrate(const QWSPointerCalibrationData *data) -{ - // Algorithm derived from - // "How To Calibrate Touch Screens" by Carlos E. Vidales, - // printed in Embedded Systems Programming, Vol. 15 no 6, June 2002 - // URL: http://www.embedded.com/showArticle.jhtml?articleID=9900629 - - const QPoint pd0 = data->devPoints[QWSPointerCalibrationData::TopLeft]; - const QPoint pd1 = data->devPoints[QWSPointerCalibrationData::TopRight]; - const QPoint pd2 = data->devPoints[QWSPointerCalibrationData::BottomRight]; - const QPoint p0 = data->screenPoints[QWSPointerCalibrationData::TopLeft]; - const QPoint p1 = data->screenPoints[QWSPointerCalibrationData::TopRight]; - const QPoint p2 = data->screenPoints[QWSPointerCalibrationData::BottomRight]; - - const qint64 xd0 = pd0.x(); - const qint64 xd1 = pd1.x(); - const qint64 xd2 = pd2.x(); - const qint64 yd0 = pd0.y(); - const qint64 yd1 = pd1.y(); - const qint64 yd2 = pd2.y(); - const qint64 x0 = p0.x(); - const qint64 x1 = p1.x(); - const qint64 x2 = p2.x(); - const qint64 y0 = p0.y(); - const qint64 y1 = p1.y(); - const qint64 y2 = p2.y(); - - qint64 scale = ((xd0 - xd2)*(yd1 - yd2) - (xd1 - xd2)*(yd0 - yd2)); - int shift = 0; - qint64 absScale = qAbs(scale); - // use maximum 16 bit precision to reduce risk of integer overflow - if (absScale > (1 << 16)) { - shift = ilog2(absScale >> 16) + 1; - scale >>= shift; - } - - s = scale; - a = ((x0 - x2)*(yd1 - yd2) - (x1 - x2)*(yd0 - yd2)) >> shift; - b = ((xd0 - xd2)*(x1 - x2) - (x0 - x2)*(xd1 - xd2)) >> shift; - c = (yd0*(xd2*x1 - xd1*x2) + yd1*(xd0*x2 - xd2*x0) + yd2*(xd1*x0 - xd0*x1)) >> shift; - d = ((y0 - y2)*(yd1 - yd2) - (y1 - y2)*(yd0 - yd2)) >> shift; - e = ((xd0 - xd2)*(y1 - y2) - (y0 - y2)*(xd1 - xd2)) >> shift; - f = (yd0*(xd2*y1 - xd1*y2) + yd1*(xd0*y2 - xd2*y0) + yd2*(xd1*y0 - xd0*y1)) >> shift; - - writeCalibration(); -} - -/*! - Transforms the given \a position from device coordinates to screen - coordinates, and returns the transformed position. - - This function is typically called explicitly on the points passed - to the QWSMouseHandler::mouseChanged() function. - - This implementation is a linear transformation using 7 parameters - (\c a, \c b, \c c, \c d, \c e, \c f and \c s) to transform the - device coordinates (\c Xd, \c Yd) into screen coordinates (\c Xs, - \c Ys) using the following equations: - - \snippet doc/src/snippets/code/src_gui_embedded_qmouse_qws.cpp 0 - - \sa mouseChanged() -*/ -QPoint QWSCalibratedMouseHandler::transform(const QPoint &position) -{ - QPoint tp; - - tp.setX((a * position.x() + b * position.y() + c) / s); - tp.setY((d * position.x() + e * position.y() + f) / s); - - return tp; -} - -/*! - Sets the size of the filter used in noise reduction to the given - \a size. - - The sendFiltered() function reduces noice by calculating an - average position from a collection of mouse event positions. The - filter size determines the number of positions that forms the - basis for these calculations. - - \sa sendFiltered() -*/ -void QWSCalibratedMouseHandler::setFilterSize(int size) -{ - samples.resize(qMax(1, size)); - numSamples = 0; - currSample = 0; -} - -/*! - \fn bool QWSCalibratedMouseHandler::sendFiltered(const QPoint &position, int state) - - Notifies the system of a new mouse event \e after applying a noise - reduction filter. Returns true if the filtering process is - successful; otherwise returns false. Note that if the filtering - process failes, the system is not notified about the event. - - The given \a position is the global position of the mouse. The \a - state parameter is a bitmask of the Qt::MouseButton enum's values - indicating which mouse buttons are pressed. - - The noice is reduced by calculating an average position from a - collection of mouse event positions and then calling the - mouseChanged() function with the new position. The number of - positions that is used is determined by the filter size. - - \sa mouseChanged(), setFilterSize() -*/ -bool QWSCalibratedMouseHandler::sendFiltered(const QPoint &position, int button) -{ - if (!button) { - if (numSamples >= samples.count()) - mouseChanged(transform(position), 0); - currSample = 0; - numSamples = 0; - return true; - } - - bool sent = false; - samples[currSample] = position; - numSamples++; - if (numSamples >= samples.count()) { - - int ignore = -1; - if (samples.count() > 2) { // throw away the "worst" sample - int maxd = 0; - for (int i = 0; i < samples.count(); i++) { - int d = (mousePos - samples[i]).manhattanLength(); - if (d > maxd) { - maxd = d; - ignore = i; - } - } - } - - // average the rest - QPoint pos(0, 0); - int numAveraged = 0; - for (int i = 0; i < samples.count(); i++) { - if (ignore == i) - continue; - pos += samples[i]; - ++numAveraged; - } - if (numAveraged) - pos /= numAveraged; - - mouseChanged(transform(pos), button); - sent = true; - } - currSample++; - if (currSample >= samples.count()) - currSample = 0; - - return sent; -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qmouse_qws.h b/src/gui/embedded/qmouse_qws.h deleted file mode 100644 index 8f2cbe5fc2..0000000000 --- a/src/gui/embedded/qmouse_qws.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSE_QWS_H -#define QMOUSE_QWS_H - -#include <QtCore/qobject.h> -#include <QtGui/qpolygon.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QWSMouseHandlerPrivate; -class QScreen; - -class Q_GUI_EXPORT QWSPointerCalibrationData -{ -public: - enum Location { TopLeft = 0, BottomLeft = 1, BottomRight = 2, TopRight = 3, - Center = 4, LastLocation = Center }; - QPoint devPoints[5]; - QPoint screenPoints[5]; -}; - -class Q_GUI_EXPORT QWSMouseHandler -{ -public: - explicit QWSMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - virtual ~QWSMouseHandler(); - - virtual void clearCalibration() {} - virtual void calibrate(const QWSPointerCalibrationData *) {} - virtual void getCalibration(QWSPointerCalibrationData *) const {} - - virtual void resume() = 0; - virtual void suspend() = 0; - - void limitToScreen(QPoint &pt); - void mouseChanged(const QPoint& pos, int bstate, int wheel = 0); - const QPoint &pos() const { return mousePos; } - - void setScreen(const QScreen *screen); - -protected: - QPoint &mousePos; - QWSMouseHandlerPrivate *d_ptr; -}; - - -class Q_GUI_EXPORT QWSCalibratedMouseHandler : public QWSMouseHandler -{ -public: - explicit QWSCalibratedMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - - virtual void clearCalibration(); - virtual void calibrate(const QWSPointerCalibrationData *); - virtual void getCalibration(QWSPointerCalibrationData *) const; - -protected: - bool sendFiltered(const QPoint &, int button); - QPoint transform(const QPoint &); - - void readCalibration(); - void writeCalibration(); - void setFilterSize(int); - -private: - int a, b, c; - int d, e, f; - int s; - QPolygon samples; - int currSample; - int numSamples; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSE_QWS_H diff --git a/src/gui/embedded/qmousedriverfactory_qws.cpp b/src/gui/embedded/qmousedriverfactory_qws.cpp deleted file mode 100644 index f67284d6d5..0000000000 --- a/src/gui/embedded/qmousedriverfactory_qws.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmousedriverfactory_qws.h" - -#include "qapplication.h" -#include "qmousepc_qws.h" -#include "qmouselinuxtp_qws.h" -#include "qmouselinuxinput_qws.h" -#include "qmousevfb_qws.h" -#include "qmousetslib_qws.h" -#include "qmouseqnx_qws.h" -#include "qmouseintegrity_qws.h" -#include <stdlib.h> -#include "private/qfactoryloader_p.h" -#include "qmousedriverplugin_qws.h" -#include "qdebug.h" - -QT_BEGIN_NAMESPACE - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QWSMouseHandlerFactoryInterface_iid, - QLatin1String("/mousedrivers"), Qt::CaseInsensitive)) - -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - -/*! - \class QMouseDriverFactory - \ingroup qws - - \brief The QMouseDriverFactory class creates mouse drivers in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QMouseDriverFactory is used to detect and instantiate the - available mouse drivers, allowing \l{Qt for Embedded Linux} to load the - preferred driver into the server application at runtime. The - create() function returns a QWSMouseHandler object representing - the mouse driver identified by a given key. The valid keys - (i.e. the supported drivers) can be retrieved using the keys() - function. - - \l{Qt for Embedded Linux} provides several built-in mouse drivers. In - addition, custom mouse drivers can be added using Qt's plugin - mechanism, i.e. by subclassing the QWSMouseHandler class and - creating a mouse driver plugin (QMouseDriverPlugin). See the - \l{Qt for Embedded Linux Pointer Handling}{pointer handling} - documentation for details. - - \sa QWSMouseHandler, QMouseDriverPlugin -*/ - -/*! - Creates the mouse driver specified by the given \a key, using the - display specified by the given \a device. - - Note that the keys are case-insensitive. - - \sa keys() -*/ -QWSMouseHandler *QMouseDriverFactory::create(const QString& key, const QString &device) -{ - QString driver = key.toLower(); -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_MOUSE_QNX) - if (driver == QLatin1String("qnx") || driver.isEmpty()) - return new QQnxMouseHandler(key, device); -#endif -#if defined(Q_OS_INTEGRITY) && !defined(QT_NO_MOUSE_INTEGRITY) - if (driver == QLatin1String("integrity") || driver.isEmpty()) - return new QIntMouseHandler(key, device); -#endif -#ifndef QT_NO_QWS_MOUSE_LINUXTP - if (driver == QLatin1String("linuxtp") || driver.isEmpty()) - return new QWSLinuxTPMouseHandler(key, device); -#endif -#ifndef QT_NO_QWS_MOUSE_PC - if (driver == QLatin1String("auto") - || driver == QLatin1String("intellimouse") - || driver == QLatin1String("microsoft") - || driver == QLatin1String("mousesystems") - || driver == QLatin1String("mouseman") - || driver.isEmpty()) { - return new QWSPcMouseHandler(key, device); - } -#endif -#ifndef QT_NO_QWS_MOUSE_TSLIB - if (driver == QLatin1String("tslib") || driver.isEmpty()) - return new QWSTslibMouseHandler(key, device); -#endif -# ifndef QT_NO_QWS_MOUSE_LINUXINPUT - if (driver == QLatin1String("linuxinput") || \ - driver == QLatin1String("usb") || \ - driver == QLatin1String("linuxis")) - return new QWSLinuxInputMouseHandler(device); -# endif -#ifndef QT_NO_QWS_MOUSE_QVFB - if (driver == QLatin1String("qvfbmouse") || driver == QLatin1String("qvfb")) - return new QVFbMouseHandler(key, device); -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - if (QWSMouseHandlerFactoryInterface *factory = qobject_cast<QWSMouseHandlerFactoryInterface*>(loader()->instance(driver))) - return factory->create(driver, device); -#endif -#endif - return 0; -} - -/*! - Returns the list of valid keys, i.e. the available mouse drivers. - - \sa create() -*/ -QStringList QMouseDriverFactory::keys() -{ - QStringList list; - -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_MOUSE_QNX) - list << QLatin1String("QNX"); -#endif -#if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_MOUSE_INTEGRITY) - list << QLatin1String("INTEGRITY"); -#endif -#ifndef QT_NO_QWS_MOUSE_LINUXTP - list << QLatin1String("LinuxTP"); -#endif -#ifndef QT_NO_QWS_MOUSE_PC - list << QLatin1String("Auto") - << QLatin1String("IntelliMouse") - << QLatin1String("Microsoft") - << QLatin1String("MouseSystems") - << QLatin1String("MouseMan"); -#endif -#ifndef QT_NO_QWS_MOUSE_TSLIB - list << QLatin1String("Tslib"); -#endif -#ifndef QT_NO_QWS_MOUSE_LINUXINPUT - list << QLatin1String("LinuxInput"); -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - QStringList plugins = loader()->keys(); - for (int i = 0; i < plugins.size(); ++i) { - if (!list.contains(plugins.at(i))) - list += plugins.at(i); - } -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - return list; -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qmousedriverfactory_qws.h b/src/gui/embedded/qmousedriverfactory_qws.h deleted file mode 100644 index 0eac39a758..0000000000 --- a/src/gui/embedded/qmousedriverfactory_qws.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSEDRIVERFACTORY_QWS_H -#define QMOUSEDRIVERFACTORY_QWS_H - -#include <QtCore/qstringlist.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QString; -class QWSMouseHandler; - -class Q_GUI_EXPORT QMouseDriverFactory -{ -public: - static QStringList keys(); - static QWSMouseHandler *create(const QString&, const QString &); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSEDRIVERFACTORY_QWS_H diff --git a/src/gui/embedded/qmousedriverplugin_qws.cpp b/src/gui/embedded/qmousedriverplugin_qws.cpp deleted file mode 100644 index 4fae54b6b7..0000000000 --- a/src/gui/embedded/qmousedriverplugin_qws.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmousedriverplugin_qws.h" - -#ifndef QT_NO_LIBRARY - -#include "qmouse_qws.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QMouseDriverPlugin - \ingroup plugins - \ingroup qws - - \brief The QMouseDriverPlugin class is an abstract base class for - mouse driver plugins in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several mouse - protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer - handling} documentation for details. Custom mouse drivers can be - implemented by subclassing the QWSMouseHandler class and creating - a mouse driver plugin. - - A mouse driver plugin can be created by subclassing - QMouseDriverPlugin and reimplementing the pure virtual keys() and - create() functions. By exporting the derived class using the - Q_EXPORT_PLUGIN2() macro, The default implementation of the - QMouseDriverFactory class will automatically detect the plugin and - load the driver into the server application at run-time. See \l - {How to Create Qt Plugins} for details. - - \sa QWSMouseHandler, QMouseDriverFactory -*/ - -/*! - \fn QStringList QMouseDriverPlugin::keys() const - - Implement this function to return the list of valid keys, i.e. the - mouse drivers supported by this plugin. - - \l{Qt for Embedded Linux} provides ready-made drivers for several mouse - protocols, see the \l {Qt for Embedded Linux Pointer Handling}{pointer - handling} documentation for details. - - \sa create() -*/ - -/*! - Constructs a mouse driver plugin with the given \a parent. - - Note that this constructor is invoked automatically by the - Q_EXPORT_PLUGIN2() macro, so there is no need for calling it - explicitly. -*/ -QMouseDriverPlugin::QMouseDriverPlugin(QObject *parent) - : QObject(parent) -{ -} - -/*! - Destroys the mouse driver plugin. - - Note that Qt destroys a plugin automatically when it is no longer - used, so there is no need for calling the destructor explicitly. -*/ -QMouseDriverPlugin::~QMouseDriverPlugin() -{ -} - -/*! - \fn QScreen* QMouseDriverPlugin::create(const QString &key, const QString& device) - - Implement this function to create a driver matching the type - specified by the given \a key and \a device parameters. Note that - keys are case-insensitive. - - \sa keys() -*/ - -QT_END_NAMESPACE - -#endif // QT_NO_LIBRARY diff --git a/src/gui/embedded/qmousedriverplugin_qws.h b/src/gui/embedded/qmousedriverplugin_qws.h deleted file mode 100644 index 275bbd1514..0000000000 --- a/src/gui/embedded/qmousedriverplugin_qws.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSEDRIVERPLUGIN_QWS_H -#define QMOUSEDRIVERPLUGIN_QWS_H - -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_LIBRARY - -class QWSMouseHandler; - -struct Q_GUI_EXPORT QWSMouseHandlerFactoryInterface : public QFactoryInterface -{ - virtual QWSMouseHandler* create(const QString &name, const QString &device) = 0; -}; - -#define QWSMouseHandlerFactoryInterface_iid "com.trolltech.Qt.QWSMouseHandlerFactoryInterface" -Q_DECLARE_INTERFACE(QWSMouseHandlerFactoryInterface, QWSMouseHandlerFactoryInterface_iid) - -class Q_GUI_EXPORT QMouseDriverPlugin : public QObject, public QWSMouseHandlerFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QWSMouseHandlerFactoryInterface:QFactoryInterface) -public: - explicit QMouseDriverPlugin(QObject *parent = 0); - ~QMouseDriverPlugin(); - - virtual QStringList keys() const = 0; - virtual QWSMouseHandler* create(const QString& driver, const QString &device) = 0; -}; - -#endif // QT_NO_LIBRARY - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSEDRIVERPLUGIN_QWS_H diff --git a/src/gui/embedded/qmouseintegrity_qws.cpp b/src/gui/embedded/qmouseintegrity_qws.cpp deleted file mode 100644 index 78a8c1b509..0000000000 --- a/src/gui/embedded/qmouseintegrity_qws.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_QWS_MOUSE_INTEGRITY - -#include "qmouseintegrity_qws.h" -#include <qwindowsystem_qws.h> -#include <qapplication.h> -#include <qtimer.h> -#include <qthread.h> - -#include <INTEGRITY.h> - - -typedef Address MOUSEHandler; -typedef struct MOUSEMessageStruct -{ - Value x; - Value y; - Value z; - Value buttons; -} MOUSEMessage; - -static Error MOUSE_Init(MOUSEHandler *handler, Boolean *isabsolute); -static Error MOUSE_SynchronousGetPosition(MOUSEHandler handler, MOUSEMessage *msg, - Boolean absolute); -static Error MOUSE_ShouldFilter(MOUSEHandler handler, Boolean *filter); - -QT_BEGIN_NAMESPACE - -class QIntMouseListenThread; - -class QIntMousePrivate : public QObject -{ - Q_OBJECT - friend class QIntMouseListenTaskThread; -Q_SIGNALS: - void mouseDataAvailable(int x, int y, int buttons); -public: - QIntMousePrivate(QIntMouseHandler *handler); - ~QIntMousePrivate(); - void dataReady(int x, int y, int buttons) { emit mouseDataAvailable(x, y, buttons); } - bool calibrated; - bool waitforread; - bool suspended; - QIntMouseListenThread *mousethread; - -private: - QIntMouseHandler *handler; -}; - -class QIntMouseListenThread : public QThread -{ -protected: - QIntMousePrivate *imp; - bool loop; -public: - QIntMouseListenThread(QIntMousePrivate *im) : QThread(), imp(im) {}; - ~QIntMouseListenThread() {}; - void run(); - void stoploop() { loop = false; }; -}; - - -QIntMouseHandler::QIntMouseHandler(const QString &driver, const QString &device) - : QObject(), QWSCalibratedMouseHandler(driver, device) -{ - QPoint test(1,1); - d = new QIntMousePrivate(this); - connect(d, SIGNAL(mouseDataAvailable(int, int, int)), this, SLOT(readMouseData(int, int, int))); - - d->calibrated = (test != transform(test)); - - d->mousethread->start(); -} - -QIntMouseHandler::~QIntMouseHandler() -{ - disconnect(d, SIGNAL(mouseDataAvailable(int, int, int)), this, SLOT(readMouseData(int, int, int))); - delete d; -} - -void QIntMouseHandler::resume() -{ - d->suspended = true; -} - -void QIntMouseHandler::suspend() -{ - d->suspended = false; -} - -void QIntMouseHandler::readMouseData(int x, int y, int buttons) -{ - d->waitforread = false; - if (d->suspended) - return; - if (d->calibrated) { - sendFiltered(QPoint(x, y), buttons); - } else { - QPoint pos; - pos = transform(QPoint(x, y)); - limitToScreen(pos); - mouseChanged(pos, buttons, 0); - } -} - -void QIntMouseHandler::clearCalibration() -{ - QWSCalibratedMouseHandler::clearCalibration(); -} - -void QIntMouseHandler::calibrate(const QWSPointerCalibrationData *data) -{ - QWSCalibratedMouseHandler::calibrate(data); -} - -void QIntMouseListenThread::run(void) -{ - MOUSEHandler handler; - MOUSEMessage msg; - Boolean filter; - Boolean isabsolute; - loop = true; - CheckSuccess(MOUSE_Init(&handler, &isabsolute)); - CheckSuccess(MOUSE_ShouldFilter(handler, &filter)); - if (!filter) - imp->calibrated = false; - imp->waitforread = false; - do { - MOUSE_SynchronousGetPosition(handler, &msg, isabsolute); - imp->dataReady(msg.x, msg.y, msg.buttons); - } while (loop); - QThread::exit(0); -} - -QIntMousePrivate::QIntMousePrivate(QIntMouseHandler *handler) - : QObject() -{ - this->handler = handler; - suspended = false; - mousethread = new QIntMouseListenThread(this); -} - -QIntMousePrivate::~QIntMousePrivate() -{ - mousethread->stoploop(); - mousethread->wait(); - delete mousethread; -} - -QT_END_NAMESPACE - -#include "qmouseintegrity_qws.moc" - -typedef struct USBMouseStruct -{ - Connection mouseconn; - Buffer mousemsg[2]; - Value x; - Value y; -} USBMouse; - -USBMouse mousedev; - -Error MOUSE_Init(MOUSEHandler *handler, Boolean *isabsolute) -{ - Error E; - bool loop = true; - memset((void*)&mousedev, 0, sizeof(USBMouse)); - mousedev.mousemsg[0].BufferType = DataImmediate; - mousedev.mousemsg[1].BufferType = DataImmediate | LastBuffer; - do { - E = RequestResource((Object*)&mousedev.mouseconn, - "MouseClient", "!systempassword"); - if (E == Success) { - *isabsolute = true; - loop = false; - } else { - E = RequestResource((Object*)&mousedev.mouseconn, - "USBMouseClient", "!systempassword"); - if (E == Success) { - *isabsolute = false; - loop = false; - } - } - if (loop) - sleep(1); - } while (loop); - *handler = (MOUSEHandler)&mousedev; - return Success; -} - -Error MOUSE_SynchronousGetPosition(MOUSEHandler handler, MOUSEMessage *msg, - Boolean isabsolute) -{ - signed long x; - signed long y; - USBMouse *mdev = (USBMouse *)handler; - mdev->mousemsg[0].Transferred = 0; - mdev->mousemsg[1].Transferred = 0; - SynchronousReceive(mdev->mouseconn, mdev->mousemsg); - if (isabsolute) { - x = (signed long)mdev->mousemsg[0].Length; - y = (signed long)mdev->mousemsg[1].TheAddress; - } else { - x = mdev->x + (signed long)mdev->mousemsg[0].Length; - y = mdev->y + (signed long)mdev->mousemsg[1].TheAddress; - } - if (x < 0) - mdev->x = 0; - else - mdev->x = x; - if (y < 0) - mdev->y = 0; - else - mdev->y = y; - msg->x = mdev->x; - msg->y = mdev->y; - msg->buttons = mdev->mousemsg[0].TheAddress; - return Success; -} - -Error MOUSE_ShouldFilter(MOUSEHandler handler, Boolean *filter) -{ - if (filter == NULL) - return Failure; - *filter = false; - return Success; -} - -#endif // QT_NO_QWS_MOUSE_INTEGRITY - diff --git a/src/gui/embedded/qmouseintegrity_qws.h b/src/gui/embedded/qmouseintegrity_qws.h deleted file mode 100644 index 46d27a3d2e..0000000000 --- a/src/gui/embedded/qmouseintegrity_qws.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSEINTEGRITY_QWS_H -#define QMOUSEINTEGRITY_QWS_H - -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MOUSE_INTEGRITY - -class QSocketNotifier; -class QIntMousePrivate; - -class QIntMouseHandler : public QObject, public QWSCalibratedMouseHandler { - Q_OBJECT -public: - QIntMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - ~QIntMouseHandler(); - - void resume(); - void suspend(); - - void calibrate(const QWSPointerCalibrationData *data); - void clearCalibration(); - -private: - QIntMousePrivate *d; -private Q_SLOTS: - void readMouseData(int x, int y, int buttons); -}; -#endif // QT_NO_QWS_MOUSE_INTEGRITY - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSEINTEGRITY_QWS_H diff --git a/src/gui/embedded/qmouselinuxinput_qws.cpp b/src/gui/embedded/qmouselinuxinput_qws.cpp deleted file mode 100644 index 534e9f16f7..0000000000 --- a/src/gui/embedded/qmouselinuxinput_qws.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmouselinuxinput_qws.h" - -#include <QScreen> -#include <QSocketNotifier> - -#include <qplatformdefs.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <errno.h> - -#include <linux/input.h> - -QT_BEGIN_NAMESPACE - - -class QWSLinuxInputMousePrivate : public QObject -{ - Q_OBJECT -public: - QWSLinuxInputMousePrivate(QWSLinuxInputMouseHandler *, const QString &); - ~QWSLinuxInputMousePrivate(); - - void enable(bool on); - -private Q_SLOTS: - void readMouseData(); - -private: - QWSLinuxInputMouseHandler *m_handler; - QSocketNotifier * m_notify; - int m_fd; - int m_x, m_y; - int m_buttons; -}; - -QWSLinuxInputMouseHandler::QWSLinuxInputMouseHandler(const QString &device) - : QWSCalibratedMouseHandler(device) -{ - d = new QWSLinuxInputMousePrivate(this, device); -} - -QWSLinuxInputMouseHandler::~QWSLinuxInputMouseHandler() -{ - delete d; -} - -void QWSLinuxInputMouseHandler::suspend() -{ - d->enable(false); -} - -void QWSLinuxInputMouseHandler::resume() -{ - d->enable(true); -} - -QWSLinuxInputMousePrivate::QWSLinuxInputMousePrivate(QWSLinuxInputMouseHandler *h, const QString &device) - : m_handler(h), m_notify(0), m_x(0), m_y(0), m_buttons(0) -{ - setObjectName(QLatin1String("LinuxInputSubsystem Mouse Handler")); - - QString dev = QLatin1String("/dev/input/event0"); - if (device.startsWith(QLatin1String("/dev/"))) - dev = device; - - m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); - if (m_fd >= 0) { - m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); - connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData())); - } else { - qWarning("Cannot open mouse input device '%s': %s", qPrintable(dev), strerror(errno)); - return; - } -} - -QWSLinuxInputMousePrivate::~QWSLinuxInputMousePrivate() -{ - if (m_fd >= 0) - QT_CLOSE(m_fd); -} - -void QWSLinuxInputMousePrivate::enable(bool on) -{ - if (m_notify) - m_notify->setEnabled(on); -} - -void QWSLinuxInputMousePrivate::readMouseData() -{ - if (!qt_screen) - return; - - struct ::input_event buffer[32]; - int n = 0; - - forever { - n = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); - - if (n == 0) { - qWarning("Got EOF from the input device."); - return; - } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) { - qWarning("Could not read from input device: %s", strerror(errno)); - return; - } else if (n % sizeof(buffer[0]) == 0) { - break; - } - } - - n /= sizeof(buffer[0]); - - for (int i = 0; i < n; ++i) { - struct ::input_event *data = &buffer[i]; - - bool unknown = false; - if (data->type == EV_ABS) { - if (data->code == ABS_X) { - m_x = data->value; - } else if (data->code == ABS_Y) { - m_y = data->value; - } else { - unknown = true; - } - } else if (data->type == EV_REL) { - if (data->code == REL_X) { - m_x += data->value; - } else if (data->code == REL_Y) { - m_y += data->value; - } else { - unknown = true; - } - } else if (data->type == EV_KEY && data->code == BTN_TOUCH) { - m_buttons = data->value ? Qt::LeftButton : 0; - } else if (data->type == EV_KEY) { - int button = 0; - switch (data->code) { - case BTN_LEFT: button = Qt::LeftButton; break; - case BTN_MIDDLE: button = Qt::MidButton; break; - case BTN_RIGHT: button = Qt::RightButton; break; - } - if (data->value) - m_buttons |= button; - else - m_buttons &= ~button; - } else if (data->type == EV_SYN && data->code == SYN_REPORT) { - QPoint pos(m_x, m_y); - pos = m_handler->transform(pos); - m_handler->limitToScreen(pos); - m_handler->mouseChanged(pos, m_buttons); - } else if (data->type == EV_MSC && data->code == MSC_SCAN) { - // kernel encountered an unmapped key - just ignore it - continue; - } else { - unknown = true; - } - if (unknown) { - qWarning("unknown mouse event type=%x, code=%x, value=%x", data->type, data->code, data->value); - } - } -} - -QT_END_NAMESPACE - -#include "qmouselinuxinput_qws.moc" diff --git a/src/gui/embedded/qmouselinuxinput_qws.h b/src/gui/embedded/qmouselinuxinput_qws.h deleted file mode 100644 index 2a9ddb3826..0000000000 --- a/src/gui/embedded/qmouselinuxinput_qws.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSELINUXINPUT_QWS_H -#define QMOUSELINUXINPUT_QWS_H - -#include <QtGui/QWSCalibratedMouseHandler> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MOUSE_LINUXINPUT - -class QWSLinuxInputMousePrivate; - -class QWSLinuxInputMouseHandler : public QWSCalibratedMouseHandler -{ -public: - QWSLinuxInputMouseHandler(const QString &); - ~QWSLinuxInputMouseHandler(); - - void suspend(); - void resume(); - -private: - QWSLinuxInputMousePrivate *d; - - friend class QWSLinuxInputMousePrivate; -}; - -#endif // QT_NO_QWS_MOUSE_LINUXINPUT - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSELINUXINPUT_QWS_H diff --git a/src/gui/embedded/qmouselinuxtp_qws.cpp b/src/gui/embedded/qmouselinuxtp_qws.cpp deleted file mode 100644 index 21fff97418..0000000000 --- a/src/gui/embedded/qmouselinuxtp_qws.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmouselinuxtp_qws.h" - -#ifndef QT_NO_QWS_MOUSE_LINUXTP -#include "qwindowsystem_qws.h" -#include "qsocketnotifier.h" -#include "qtimer.h" -#include "qapplication.h" -#include "qscreen_qws.h" -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <termios.h> - -QT_BEGIN_NAMESPACE - -#if defined(QT_QWS_IPAQ) - #define QT_QWS_IPAQ_RAW - #define QT_QWS_SCREEN_COORDINATES - typedef struct { - unsigned short pressure; - unsigned short x; - unsigned short y; - unsigned short pad; - } TS_EVENT; -#elif defined(QT_QWS_EBX) - #define QT_QWS_EBX_RAW - #define QT_QWS_SCREEN_COORDINATES -#ifndef QT_QWS_SHARP - typedef struct { - unsigned short pressure; - unsigned short x; - unsigned short y; - unsigned short pad; - } TS_EVENT; - #else - typedef struct { - long y; - long x; - long pressure; - long long millisecs; - } TS_EVENT; - #define QT_QWS_TP_SAMPLE_SIZE 10 - #define QT_QWS_TP_MINIMUM_SAMPLES 4 - #define QT_QWS_TP_PRESSURE_THRESHOLD 500 - #define QT_QWS_TP_MOVE_LIMIT 50 - #define QT_QWS_TP_JITTER_LIMIT 2 - #endif -#else // not IPAQ, not SHARP - typedef struct { - unsigned short pressure; - unsigned short x; - unsigned short y; - unsigned short pad; - } TS_EVENT; -#endif - -#ifndef QT_QWS_TP_SAMPLE_SIZE -#define QT_QWS_TP_SAMPLE_SIZE 5 -#endif - -#ifndef QT_QWS_TP_MINIMUM_SAMPLES -#define QT_QWS_TP_MINIMUM_SAMPLES 5 -#endif - -#ifndef QT_QWS_TP_PRESSURE_THRESHOLD -#define QT_QWS_TP_PRESSURE_THRESHOLD 1 -#endif - -#ifndef QT_QWS_TP_MOVE_LIMIT -#define QT_QWS_TP_MOVE_LIMIT 100 -#endif - -#ifndef QT_QWS_TP_JITTER_LIMIT -#define QT_QWS_TP_JITTER_LIMIT 2 -#endif - -class QWSLinuxTPMouseHandlerPrivate : public QObject -{ - Q_OBJECT -public: - QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h, const QString &); - ~QWSLinuxTPMouseHandlerPrivate(); - - void suspend(); - void resume(); -private: - static const int mouseBufSize = 2048; - int mouseFD; - QPoint oldmouse; - QPoint oldTotalMousePos; - bool waspressed; - QPolygon samples; - int currSample; - int lastSample; - int numSamples; - int skipCount; - int mouseIdx; - uchar mouseBuf[mouseBufSize]; - QWSLinuxTPMouseHandler *handler; - QSocketNotifier *mouseNotifier; - -private slots: - void readMouseData(); -}; - -QWSLinuxTPMouseHandler::QWSLinuxTPMouseHandler(const QString &driver, const QString &device) - : QWSCalibratedMouseHandler(driver, device) -{ - d = new QWSLinuxTPMouseHandlerPrivate(this, device); -} - -QWSLinuxTPMouseHandler::~QWSLinuxTPMouseHandler() -{ - delete d; -} - -void QWSLinuxTPMouseHandler::suspend() -{ - d->suspend(); -} - -void QWSLinuxTPMouseHandler::resume() -{ - d->resume(); -} - -QWSLinuxTPMouseHandlerPrivate::QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h, - const QString &device) - : samples(QT_QWS_TP_SAMPLE_SIZE), currSample(0), lastSample(0), - numSamples(0), skipCount(0), handler(h) -{ - QString mousedev; - if (device.isEmpty()) { -#if defined(QT_QWS_IPAQ) -# ifdef QT_QWS_IPAQ_RAW - mousedev = QLatin1String("/dev/h3600_tsraw"); -# else - mousedev = QLatin1String("/dev/h3600_ts"); -# endif -#else - mousedev = QLatin1String("/dev/ts"); -#endif - } else { - mousedev = device; - } - if ((mouseFD = QT_OPEN(mousedev.toLatin1().constData(), O_RDONLY | O_NDELAY)) < 0) { - qWarning("Cannot open %s (%s)", qPrintable(mousedev), strerror(errno)); - return; - } - - mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, - this); - connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData())); - waspressed=false; - mouseIdx = 0; -} - -QWSLinuxTPMouseHandlerPrivate::~QWSLinuxTPMouseHandlerPrivate() -{ - if (mouseFD >= 0) - QT_CLOSE(mouseFD); -} - -void QWSLinuxTPMouseHandlerPrivate::suspend() -{ - if (mouseNotifier) - mouseNotifier->setEnabled(false); -} - -void QWSLinuxTPMouseHandlerPrivate::resume() -{ - mouseIdx=0; - currSample=0; - lastSample=0; - numSamples=0; - skipCount=0; - if (mouseNotifier) - mouseNotifier->setEnabled(true); -} - - -void QWSLinuxTPMouseHandlerPrivate::readMouseData() -{ - if(!qt_screen) - return; - - int n; - do { - n = QT_READ(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx); - if (n > 0) - mouseIdx += n; - } while (n > 0 && mouseIdx < mouseBufSize); - - //qDebug("readMouseData()"); - - TS_EVENT *data; - int idx = 0; - - // perhaps we shouldn't be reading EVERY SAMPLE. - while (mouseIdx-idx >= (int)sizeof(TS_EVENT)) { - uchar *mb = mouseBuf+idx; - data = (TS_EVENT *) mb; - - if(data->pressure >= QT_QWS_TP_PRESSURE_THRESHOLD) { -#ifdef QT_QWS_SHARP - samples[currSample] = QPoint(1000 - data->x, data->y); -#else - samples[currSample] = QPoint(data->x, data->y); -#endif - numSamples++; - if (numSamples >= QT_QWS_TP_MINIMUM_SAMPLES) { - int sampleCount = qMin(numSamples + 1,samples.count()); - - // average the rest - QPoint mousePos = QPoint(0, 0); - QPoint totalMousePos = oldTotalMousePos; - totalMousePos += samples[currSample]; - if(numSamples >= samples.count()) - totalMousePos -= samples[lastSample]; - - mousePos = totalMousePos / (sampleCount - 1); -#if defined(QT_QWS_SCREEN_COORDINATES) - mousePos = handler->transform(mousePos); -#endif - if(!waspressed) - oldmouse = mousePos; - QPoint dp = mousePos - oldmouse; - int dxSqr = dp.x() * dp.x(); - int dySqr = dp.y() * dp.y(); - if (dxSqr + dySqr < (QT_QWS_TP_MOVE_LIMIT * QT_QWS_TP_MOVE_LIMIT)) { - if (waspressed) { - if ((dxSqr + dySqr > (QT_QWS_TP_JITTER_LIMIT * QT_QWS_TP_JITTER_LIMIT)) || skipCount > 2) { - handler->mouseChanged(mousePos,Qt::LeftButton); - oldmouse = mousePos; - skipCount = 0; - } else { - skipCount++; - } - } else { - handler->mouseChanged(mousePos,Qt::LeftButton); - oldmouse=mousePos; - waspressed=true; - } - - // save recuring information - currSample++; - if (numSamples >= samples.count()) - lastSample++; - oldTotalMousePos = totalMousePos; - } else { - numSamples--; // don't use this sample, it was bad. - } - } else { - // build up the average - oldTotalMousePos += samples[currSample]; - currSample++; - } - if (currSample >= samples.count()) - currSample = 0; - if (lastSample >= samples.count()) - lastSample = 0; - } else { - currSample = 0; - lastSample = 0; - numSamples = 0; - skipCount = 0; - oldTotalMousePos = QPoint(0,0); - if (waspressed) { - handler->mouseChanged(oldmouse,0); - oldmouse = QPoint(-100, -100); - waspressed=false; - } - } - idx += sizeof(TS_EVENT); - } - - int surplus = mouseIdx - idx; - for (int i = 0; i < surplus; i++) - mouseBuf[i] = mouseBuf[idx+i]; - mouseIdx = surplus; -} - -QT_END_NAMESPACE - -#include "qmouselinuxtp_qws.moc" - -#endif //QT_NO_QWS_MOUSE_LINUXTP diff --git a/src/gui/embedded/qmouselinuxtp_qws.h b/src/gui/embedded/qmouselinuxtp_qws.h deleted file mode 100644 index 1974ad0e89..0000000000 --- a/src/gui/embedded/qmouselinuxtp_qws.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSELINUXTP_QWS_H -#define QMOUSELINUXTP_QWS_H - -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MOUSE_LINUXTP - -class QWSLinuxTPMouseHandlerPrivate; - -class QWSLinuxTPMouseHandler : public QWSCalibratedMouseHandler -{ - friend class QWSLinuxTPMouseHandlerPrivate; -public: - explicit QWSLinuxTPMouseHandler(const QString & = QString(), - const QString & = QString()); - ~QWSLinuxTPMouseHandler(); - - void suspend(); - void resume(); -protected: - QWSLinuxTPMouseHandlerPrivate *d; -}; - -#endif // QT_NO_QWS_MOUSE_LINUXTP - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSELINUXTP_QWS_H diff --git a/src/gui/embedded/qmousepc_qws.cpp b/src/gui/embedded/qmousepc_qws.cpp deleted file mode 100644 index e3f85cbc77..0000000000 --- a/src/gui/embedded/qmousepc_qws.cpp +++ /dev/null @@ -1,794 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmousepc_qws.h" - -#ifndef QT_NO_QWS_MOUSE_PC - -#include "qwindowsystem_qws.h" -#include "qsocketnotifier.h" -#include "qwsevent_qws.h" -#include "qwscommand_qws_p.h" -#include "qwsutils_qws.h" - -#include "qapplication.h" -#include "qpolygon.h" -#include "qtimer.h" -#include "qfile.h" -#include "qtextstream.h" -#include "qstringlist.h" -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <termios.h> - -#include <qscreen_qws.h> - -QT_BEGIN_NAMESPACE - -//#define QWS_MOUSE_DEBUG - -/* - * Automatic-detection mouse driver - */ - -class QWSPcMouseSubHandler { -protected: - enum { max_buf=32 }; - - int fd; - - uchar buffer[max_buf]; - int nbuf; - - QPoint motion; - int bstate; - int wheel; - - int goodness; - int badness; - - virtual int tryData()=0; - -public: - QWSPcMouseSubHandler(int f) : fd(f) - { - initState(); - } - virtual ~QWSPcMouseSubHandler() {} - - int file() const { return fd; } - - void closeIfNot(int& f) - { - if (fd != f) { - f = fd; - QT_CLOSE(fd); - } - } - - void initState() { nbuf = bstate = goodness = badness = 0; } - - void worse(int by=1) { badness+=by; } - bool reliable() const { return goodness >= 5 && badness < 50; } - int buttonState() const { return bstate; } - bool motionPending() const { return motion!=QPoint(0,0); } - QPoint takeMotion() { QPoint r=motion; motion=QPoint(0,0); return r; } - int takeWheel() { int result = wheel; wheel = 0; return result; } - - void appendData(uchar* data, int length) - { - memcpy(buffer+nbuf, data, length); - nbuf += length; - } - - enum UsageResult { Insufficient, Motion, Button }; - - UsageResult useData() - { - int pbstate = bstate; - int n = tryData(); -#ifdef QWS_MOUSE_DEBUG - if (n) { - fprintf(stderr, "QWSPcMouseSubHandler tryData read %d bytes:", n); - for (int i=0; i<n; ++i) - fprintf(stderr, " %02x", buffer[i]); - fprintf(stderr, "\n"); - } -#endif - if (n > 0) { - if (n<nbuf) - memmove(buffer, buffer+n, nbuf-n); - nbuf -= n; - return (wheel || pbstate != bstate) ? Button : Motion; - } - return Insufficient; - } -}; - -class QWSPcMouseSubHandler_intellimouse : public QWSPcMouseSubHandler { - int packetsize; -public: - QWSPcMouseSubHandler_intellimouse(int f) : QWSPcMouseSubHandler(f) - { - init(); - } - - void init() - { - int n; - uchar reply[20]; - - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_intellimouse: pre-init tcflush"); -#endif - } - static const uchar initseq[] = { 243, 200, 243, 100, 243, 80 }; - static const uchar query[] = { 0xf2 }; - if (QT_WRITE(fd, initseq, sizeof(initseq))!=sizeof(initseq)) { - badness = 100; - return; - } - usleep(10000); - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_intellimouse: post-init tcflush"); -#endif - } - if (QT_WRITE(fd, query, sizeof(query))!=sizeof(query)) { - badness = 100; - return; - } - usleep(10000); - n = QT_READ(fd, reply, 20); - if (n > 0) { - goodness = 10; - switch (reply[n-1]) { - case 3: - case 4: - packetsize = 4; - break; - default: - packetsize = 3; - } - } else { - badness = 100; - } - } - - int tryData() - { - if (nbuf >= packetsize) { - //int overflow = (buffer[0]>>6)& 0x03; - - if (/*overflow ||*/ !(buffer[0] & 8)) { -#ifdef QWS_MOUSE_DEBUG - qDebug("Intellimouse: skipping (overflow)"); -#endif - badness++; - return 1; - } else { - QPoint delta((buffer[0] & 0x10) ? buffer[1]-256 : buffer[1], - (buffer[0] & 0x20) ? 256-buffer[2] : -buffer[2]); - motion += delta; - int nbstate = buffer[0] & 0x7; -#ifdef QWS_MOUSE_DEBUG - int debugwheel = -#endif - wheel = packetsize > 3 ? -(signed char)buffer[3] : 0; - if (wheel < -2 || wheel > 2) - wheel = 0; - wheel *= 120; // WHEEL_DELTA? -#ifdef QWS_MOUSE_DEBUG - qDebug("Intellimouse: motion %d,%d, state %d, raw wheel %d, wheel %d", motion.x(), motion.y(), nbstate, debugwheel, wheel); -#endif - if (motion.x() || motion.y() || bstate != nbstate || wheel) { - bstate = nbstate; - goodness++; - } else { - badness++; - return 1; - } - } - return packetsize; - } - return 0; - } -}; - -class QWSPcMouseSubHandler_mouseman : public QWSPcMouseSubHandler { - int packetsize; -public: - QWSPcMouseSubHandler_mouseman(int f) : QWSPcMouseSubHandler(f) - { - init(); - } - - void init() - { - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_mouseman: initial tcflush"); -#endif - } - QT_WRITE(fd,"",1); - usleep(50000); - QT_WRITE(fd,"@EeI!",5); - usleep(10000); - static const char ibuf[] = { 246, 244 }; - QT_WRITE(fd,ibuf,1); - QT_WRITE(fd,ibuf+1,1); - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_mouseman: tcflush"); -#endif - } - usleep(10000); - - char buf[100]; - while (QT_READ(fd, buf, 100) > 0) { } // eat unwanted replies - } - - int tryData() - { - if (nbuf >= 3) { - int nbstate = 0; - if (buffer[0] & 0x01) - nbstate |= Qt::LeftButton; - if (buffer[0] & 0x02) - nbstate |= Qt::RightButton; - if (buffer[0] & 0x04) - nbstate |= Qt::MidButton; - - int overflow = (buffer[0]>>6)& 0x03; - if (overflow) { - //### wheel events signalled with overflow bit, ignore for now - badness++; - return 1; - } else { - bool xs = buffer[0] & 0x10; - bool ys = buffer[0] & 0x20; - int dx = xs ? buffer[1]-256 : buffer[1]; - int dy = ys ? buffer[2]-256 : buffer[2]; - - motion += QPoint(dx, -dy); - if (motion.x() || motion.y() || bstate != nbstate) { - bstate = nbstate; - goodness++; - } else { - badness++; - return 1; - } - } - return 3; - } - return 0; - } -}; - -class QWSPcMouseSubHandler_serial : public QWSPcMouseSubHandler { -public: - QWSPcMouseSubHandler_serial(int f) : QWSPcMouseSubHandler(f) - { - initSerial(); - } - -protected: - void setflags(int f) - { - termios tty; - if (tcgetattr(fd, &tty) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_serial: tcgetattr"); -#endif - } - tty.c_iflag = IGNBRK | IGNPAR; - tty.c_oflag = 0; - tty.c_lflag = 0; - tty.c_cflag = f | CREAD | CLOCAL | HUPCL; -#ifdef Q_OS_LINUX - tty.c_line = 0; -#endif - tty.c_cc[VTIME] = 0; - tty.c_cc[VMIN] = 1; - if (tcsetattr(fd, TCSANOW, &tty) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_serial: tcgetattr"); -#endif - } - } - -private: - void initSerial() - { - int speed[4] = { B9600, B4800, B2400, B1200 }; - - for (int n = 0; n < 4; n++) { - setflags(CSTOPB | speed[n]); - QT_WRITE(fd, "*q", 2); - usleep(10000); - } - } -}; - -class QWSPcMouseSubHandler_mousesystems : public QWSPcMouseSubHandler_serial { -public: - // ##### This driver has not been tested - - QWSPcMouseSubHandler_mousesystems(int f) : QWSPcMouseSubHandler_serial(f) - { - init(); - } - - void init() - { - setflags(B1200|CS8|CSTOPB); - // 60Hz - if (QT_WRITE(fd, "R", 1)!=1) { - badness = 100; - return; - } - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QT_QWS_VNC_DEBUG - perror("QWSPcMouseSubHandler_mousesystems: tcflush"); -#endif - } - } - - int tryData() - { - if (nbuf >= 5) { - if ((buffer[0] & 0xf8) != 0x80) { - badness++; - return 1; - } - motion += - QPoint((signed char)buffer[1] + (signed char)buffer[3], - -(signed char)buffer[2] + (signed char)buffer[4]); - int t = ~buffer[0]; - int nbstate = ((t&3) << 1) | ((t&4) >> 2); - if (motion.x() || motion.y() || bstate != nbstate) { - bstate = nbstate; - goodness++; - } else { - badness++; - return 1; - } - return 5; - } - return 0; - } -}; - -class QWSPcMouseSubHandler_ms : public QWSPcMouseSubHandler_serial { - int mman; -public: - QWSPcMouseSubHandler_ms(int f) : QWSPcMouseSubHandler_serial(f) - { - mman=0; - init(); - } - - void init() - { - setflags(B1200|CS7); - // 60Hz - if (QT_WRITE(fd, "R", 1)!=1) { - badness = 100; - return; - } - if (tcflush(fd,TCIOFLUSH) == -1) { -#ifdef QWS_MOUSE_DEBUG - perror("QWSPcMouseSubHandler_ms: tcflush"); -#endif - } - } - - int tryData() - { - if (!(buffer[0] & 0x40)) { - if (buffer[0] == 0x20 && (bstate & Qt::MidButton)) { - mman=1; // mouseman extension - } - return 1; - } - int extra = mman&&(bstate & Qt::MidButton); - if (nbuf >= 3+extra) { - int nbstate = 0; - if (buffer[0] == 0x40 && !bstate && !buffer[1] && !buffer[2]) { - nbstate = Qt::MidButton; - } else { - nbstate = ((buffer[0] & 0x20) >> 5) - | ((buffer[0] & 0x10) >> 3); - if (extra && buffer[3] == 0x20) - nbstate = Qt::MidButton; - } - - if (buffer[1] & 0x40) { - badness++; - return 1; - } else { - motion += - QPoint((signed char)((buffer[0]&0x3)<<6) - |(signed char)(buffer[1]&0x3f), - (signed char)((buffer[0]&0xc)<<4) - |(signed char)(buffer[2]&0x3f)); - if (motion.x() || motion.y() || bstate != nbstate) { - bstate = nbstate; - goodness++; - } else { - badness++; - return 1; - } - return 3+extra; - } - } - return 0; - } -}; - -//=========================================================================== - -class QWSPcMouseHandlerPrivate : public QObject -{ - Q_OBJECT -public: - QWSPcMouseHandlerPrivate(QWSPcMouseHandler *h, const QString &, const QString &); - ~QWSPcMouseHandlerPrivate(); - - void suspend(); - void resume(); - -private: - enum { max_dev=32 }; - QWSPcMouseSubHandler *sub[max_dev]; - QList<QSocketNotifier*> notifiers; - int nsub; - int retries; - -private slots: - void readMouseData(int); - -private: - void openDevices(); - void closeDevices(); - void notify(int fd); - bool sendEvent(QWSPcMouseSubHandler& h); - -private: - QWSPcMouseHandler *handler; - QString driver; - QString device; - qreal accel; - int accel_limit; -}; - -QWSPcMouseHandler::QWSPcMouseHandler(const QString &driver, const QString &device) - : QWSMouseHandler(driver, device) -{ - d = new QWSPcMouseHandlerPrivate(this, driver, device); -} - -QWSPcMouseHandler::~QWSPcMouseHandler() -{ - delete d; -} - -void QWSPcMouseHandler::suspend() -{ - d->suspend(); -} - -void QWSPcMouseHandler::resume() -{ - d->resume(); -} - - -QWSPcMouseHandlerPrivate::QWSPcMouseHandlerPrivate(QWSPcMouseHandler *h, - const QString &drv, const QString &arg) - : handler(h), driver(drv) -{ - QStringList args = arg.split(QLatin1Char(':'), QString::SkipEmptyParts); - - int index; - - accel = qreal(2.0); - QRegExp accelRegex(QLatin1String("^accel=(\\d+\\.?\\d*)$")); - index = args.indexOf(accelRegex); - if (index >= 0) { - accel = qreal(accelRegex.cap(1).toDouble()); - args.removeAt(index); - } - - accel_limit = 5; - QRegExp accelLimitRegex(QLatin1String("^accel_limit=(\\d+)$")); - index = args.indexOf(accelLimitRegex); - if (index >= 0) { - accel_limit = accelLimitRegex.cap(1).toInt(); - args.removeAt(index); - } - - device = args.join(QString()); - - retries = 0; - openDevices(); -} - -QWSPcMouseHandlerPrivate::~QWSPcMouseHandlerPrivate() -{ - closeDevices(); -} - -/* -QWSPcMouseHandler::UsageResult QWSPcMouseHandler::useDev(Dev& d) -{ - if (d.nbuf >= mouseData[d.protocol].bytesPerPacket) { - uchar *mb = d.buf; - int bstate = 0; - int dx = 0; - int dy = 0; - - switch (mouseProtocol) { - case MouseMan: - case IntelliMouse: - { - bstate = mb[0] & 0x7; // assuming Qt::*Button order - - int overflow = (mb[0]>>6)& 0x03; - if (mouseProtocol == MouseMan && overflow) { - //### wheel events signalled with overflow bit, ignore for now - } - else { - bool xs = mb[0] & 0x10; - bool ys = mb[0] & 0x20; - dx = xs ? mb[1]-256 : mb[1]; - dy = ys ? mb[2]-256 : mb[2]; - } - break; - } - case Microsoft: - if (((mb[0] & 0x20) >> 3)) { - bstate |= Qt::LeftButton; - } - if (((mb[0] & 0x10) >> 4)) { - bstate |= Qt::RightButton; - } - - dx=(signed char)(((mb[0] & 0x03) << 6) | (mb[1] & 0x3f)); - dy=-(signed char)(((mb[0] & 0x0c) << 4) | (mb[2] & 0x3f)); - - break; - } - } - } -*/ - - -bool QWSPcMouseHandlerPrivate::sendEvent(QWSPcMouseSubHandler& h) -{ - if (h.reliable()) { - QPoint motion = h.takeMotion(); - if (qAbs(motion.x()) > accel_limit || qAbs(motion.y()) > accel_limit) - motion *= accel; - QPoint newPos = handler->pos() + motion; - if (qt_screen->isTransformed()) { - QSize s = QSize(qt_screen->width(), qt_screen->height()); - newPos = qt_screen->mapToDevice(newPos, s); - } - handler->limitToScreen(newPos); - - handler->mouseChanged(newPos, h.buttonState(), h.takeWheel()); - return true; - } else { - h.takeMotion(); - if (h.buttonState() & (Qt::RightButton|Qt::MidButton)) { - // Strange for the user to press right or middle without - // a moving mouse! - h.worse(); - } - return false; - } -} - -void QWSPcMouseHandlerPrivate::openDevices() -{ - nsub=0; - int fd = -1; - - QString drv = driver.toLower(); - if (!drv.isEmpty() && drv != QLatin1String("auto")) { - // Manually specified mouse - QByteArray dev = device.toLatin1(); - if (drv == QLatin1String("intellimouse")) { - if (dev.isEmpty()) - dev = "/dev/psaux"; - fd = QT_OPEN(dev, O_RDWR | O_NDELAY); - if (fd >= 0) - sub[nsub++] = new QWSPcMouseSubHandler_intellimouse(fd); - } else if (drv == QLatin1String("microsoft")) { - if (dev.isEmpty()) - dev = "/dev/ttyS0"; - fd = QT_OPEN(dev, O_RDWR | O_NDELAY); - if (fd >= 0) - sub[nsub++] = new QWSPcMouseSubHandler_ms(fd); - } else if (drv == QLatin1String("mousesystems")) { - if (dev.isEmpty()) - dev = "/dev/ttyS0"; - fd = QT_OPEN(dev, O_RDWR | O_NDELAY); - if (fd >= 0) - sub[nsub++] = new QWSPcMouseSubHandler_mousesystems(fd); - } else if (drv == QLatin1String("mouseman")) { - if (dev.isEmpty()) - dev = "/dev/psaux"; - fd = QT_OPEN(dev, O_RDWR | O_NDELAY); - if (fd >= 0) - sub[nsub++] = new QWSPcMouseSubHandler_mouseman(fd); - } - if (fd >= 0) - notify(fd); - else - qCritical("Error opening mouse device '%s': %s", - dev.constData(), strerror(errno)); - } else { - // Try automatically - fd = QT_OPEN("/dev/psaux", O_RDWR | O_NDELAY); - if (fd >= 0) { - sub[nsub++] = new QWSPcMouseSubHandler_intellimouse(fd); - notify(fd); - } - fd = QT_OPEN("/dev/input/mice", O_RDWR | O_NDELAY); - if (fd >= 0) { - sub[nsub++] = new QWSPcMouseSubHandler_intellimouse(fd); - notify(fd); - //qDebug("/dev/input/mice fd %d #%d", fd, nsub-1); - } - -// include the code below to auto-detect serial mice, and to mess up -// any sort of serial communication -#if 0 - const char fn[4][11] = { "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3" }; - for (int ch = 0; ch < 4; ++ch) { - fd = QT_OPEN(fn[ch], O_RDWR | O_NDELAY); - if (fd >= 0) { - //sub[nsub++] = new QWSPcMouseSubHandler_intellimouse(fd); - sub[nsub++] = new QWSPcMouseSubHandler_mousesystems(fd); - sub[nsub++] = new QWSPcMouseSubHandler_ms(fd); - notify(fd); - } - } -#endif - } -} - -void QWSPcMouseHandlerPrivate::closeDevices() -{ - int pfd=-1; - for (int i=0; i<nsub; i++) { - sub[i]->closeIfNot(pfd); - delete sub[i]; - } - qDeleteAll(notifiers); - notifiers.clear(); -} - -void QWSPcMouseHandlerPrivate::suspend() -{ - for (int i=0; i<notifiers.size(); ++i) - notifiers.at(i)->setEnabled(false); -} - -void QWSPcMouseHandlerPrivate::resume() -{ - for (int i=0; i<nsub; i++) - sub[i]->initState(); - - for (int i=0; i<notifiers.size(); ++i) - notifiers.at(i)->setEnabled(true); -} - - - -void QWSPcMouseHandlerPrivate::notify(int fd) -{ - QSocketNotifier *mouseNotifier - = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData(int))); - notifiers.append(mouseNotifier); -} - -void QWSPcMouseHandlerPrivate::readMouseData(int fd) -{ - for (;;) { - uchar buf[8]; - int n = read(fd, buf, 8); - if (n<=0) - break; - for (int i=0; i<nsub; i++) { - QWSPcMouseSubHandler& h = *sub[i]; - if (h.file() == fd) { - h.appendData(buf,n); - for (;;) { - switch (h.useData()) { - case QWSPcMouseSubHandler::Button: - sendEvent(h); - break; - case QWSPcMouseSubHandler::Insufficient: - goto breakbreak; - case QWSPcMouseSubHandler::Motion: - break; - } - } - breakbreak: - ; - } - } - } - bool any_reliable=false; - for (int i=0; i<nsub; i++) { - QWSPcMouseSubHandler& h = *sub[i]; - if (h.motionPending()) - sendEvent(h); - any_reliable = any_reliable || h.reliable(); - } - if (any_reliable) { - // ... get rid of all unreliable ones? All bad ones? - } else if (retries < 2) { - // Try again - maybe the mouse was being moved when we tried to init. - closeDevices(); - openDevices(); - retries++; - } -} - -QT_END_NAMESPACE - -#include "qmousepc_qws.moc" - -#endif // QT_NO_MOUSE_PC diff --git a/src/gui/embedded/qmousepc_qws.h b/src/gui/embedded/qmousepc_qws.h deleted file mode 100644 index 339418cdb8..0000000000 --- a/src/gui/embedded/qmousepc_qws.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSEPC_QWS_H -#define QMOUSEPC_QWS_H - -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MOUSE_PC - -class QWSPcMouseHandlerPrivate; - -class QWSPcMouseHandler : public QWSMouseHandler -{ -public: - explicit QWSPcMouseHandler(const QString & = QString(), - const QString & = QString()); - ~QWSPcMouseHandler(); - - void suspend(); - void resume(); -protected: - QWSPcMouseHandlerPrivate *d; -}; - -#endif // QT_NO_QWS_MOUSE_PC - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSEPC_QWS_H diff --git a/src/gui/embedded/qmouseqnx_qws.cpp b/src/gui/embedded/qmouseqnx_qws.cpp deleted file mode 100644 index cea3673d70..0000000000 --- a/src/gui/embedded/qmouseqnx_qws.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" -#include "qmouseqnx_qws.h" - -#include "qsocketnotifier.h" -#include "qdebug.h" - -#include <sys/dcmd_input.h> - -#include <errno.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QQnxMouseHandler - \preliminary - \ingroup qws - \internal - \since 4.6 - - \brief The QQnxMouseHandler class implements a mouse driver - for the QNX \c{devi-hid} input manager. - - To be able to compile this mouse handler, \l{Qt for Embedded Linux} - must be configured with the \c -qt-mouse-qnx option, see the - \l{Qt for Embedded Linux Pointer Handling}{Pointer Handling} documentation for details. - - In order to use this mouse handler, the \c{devi-hid} input manager - must be set up and run with the resource manager interface (option \c{-r}). - Also, Photon must not be running. - - Example invocation from command line: \c{/usr/photon/bin/devi-hid -Pr kbd mouse} - Note that after running \c{devi-hid}, you will not be able to use the local - shell anymore. It is suggested to run the command in a shell scrip, that launches - a Qt application after invocation of \c{devi-hid}. - - To make \l{Qt for Embedded Linux} explicitly choose the qnx mouse - handler, set the QWS_MOUSE_PROTO environment variable to \c{qnx}. By default, - the first mouse device (\c{/dev/devi/mouse0}) is used. To override, pass a device - name as the first and only parameter, for example - \c{QWS_MOUSE_PROTO=qnx:/dev/devi/mouse1; export QWS_MOUSE_PROTO}. - - \sa {Qt for Embedded Linux Pointer Handling}{Pointer Handling}, {Qt for Embedded Linux} -*/ - -/*! - Constructs a mouse handler for the specified \a device, defaulting to \c{/dev/devi/mouse0}. - The \a driver parameter must be \c{"qnx"}. - - Note that you should never instanciate this class, instead let QMouseDriverFactory - handle the mouse handlers. - - \sa QMouseDriverFactory - */ -QQnxMouseHandler::QQnxMouseHandler(const QString & /*driver*/, const QString &device) -{ - // open the mouse device with O_NONBLOCK so reading won't block when there's no data - mouseFD = QT_OPEN(device.isEmpty() ? "/dev/devi/mouse0" : device.toLatin1().constData(), - QT_OPEN_RDONLY | O_NONBLOCK); - if (mouseFD == -1) { - qErrnoWarning(errno, "QQnxMouseHandler: Unable to open mouse device"); - return; - } - - // register a socket notifier on the file descriptor so we'll wake up whenever - // there's a mouse move waiting for us. - mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, this); - connect(mouseNotifier, SIGNAL(activated(int)), SLOT(socketActivated())); - - qDebug() << "QQnxMouseHandler: connected."; -} - -/*! - Destroys this mouse handler and closes the connection to the mouse device. - */ -QQnxMouseHandler::~QQnxMouseHandler() -{ - QT_CLOSE(mouseFD); -} - -/*! \reimp */ -void QQnxMouseHandler::resume() -{ - if (mouseNotifier) - mouseNotifier->setEnabled(true); -} - -/*! \reimp */ -void QQnxMouseHandler::suspend() -{ - if (mouseNotifier) - mouseNotifier->setEnabled(false); -} - -/*! \internal - - This function is called whenever there is activity on the mouse device. - By default, it reads up to 10 mouse move packets and calls mouseChanged() - for each of them. -*/ -void QQnxMouseHandler::socketActivated() -{ - // _mouse_packet is a QNX structure. devi-hid is nice enough to translate - // the raw byte data from mouse devices into generic format for us. - _mouse_packet packet; - - int iteration = 0; - - // read mouse events in batches of 10. Since we're getting quite a lot - // of mouse events, it's better to do them in batches than to return to the - // event loop every time. - do { - int bytesRead = QT_READ(mouseFD, &packet, sizeof(packet)); - if (bytesRead == -1) { - // EAGAIN means that there are no more mouse events to read - if (errno != EAGAIN) - qErrnoWarning(errno, "QQnxMouseHandler: Unable to read from socket"); - return; - } - - // bytes read should always be equal to the size of a packet. - Q_ASSERT(bytesRead == sizeof(packet)); - - // translate the coordinates from the QNX data structure to Qt coordinates - // note the swapped y axis - QPoint pos = mousePos; - pos += QPoint(packet.dx, -packet.dy); - - // QNX only tells us relative mouse movements, not absolute ones, so limit the - // cursor position manually to the screen - limitToScreen(pos); - - // translate the QNX mouse button bitmask to Qt buttons - int buttons = Qt::NoButton; - - if (packet.hdr.buttons & _POINTER_BUTTON_LEFT) - buttons |= Qt::LeftButton; - if (packet.hdr.buttons & _POINTER_BUTTON_MIDDLE) - buttons |= Qt::MidButton; - if (packet.hdr.buttons & _POINTER_BUTTON_RIGHT) - buttons |= Qt::RightButton; - - // call mouseChanged() - this does all the magic to actually move the on-screen - // mouse cursor. - mouseChanged(pos, buttons, 0); - } while (++iteration < 11); -} - -QT_END_NAMESPACE - diff --git a/src/gui/embedded/qmouseqnx_qws.h b/src/gui/embedded/qmouseqnx_qws.h deleted file mode 100644 index 0779367600..0000000000 --- a/src/gui/embedded/qmouseqnx_qws.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSE_QNX_H -#define QMOUSE_QNX_H - -#include <QtCore/qobject.h> -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QSocketNotifier; - -class Q_GUI_EXPORT QQnxMouseHandler : public QObject, public QWSMouseHandler -{ - Q_OBJECT -public: - explicit QQnxMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - ~QQnxMouseHandler(); - - void resume(); - void suspend(); - -private Q_SLOTS: - void socketActivated(); - -private: - QSocketNotifier *mouseNotifier; - int mouseFD; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSE_QWS_H diff --git a/src/gui/embedded/qmousetslib_qws.cpp b/src/gui/embedded/qmousetslib_qws.cpp deleted file mode 100644 index 8794eed2f2..0000000000 --- a/src/gui/embedded/qmousetslib_qws.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmousetslib_qws.h" - -#if !defined(QT_NO_QWS_MOUSE_TSLIB) || defined(QT_PLUGIN) - -#include <QtCore/qregexp.h> -#include <QtCore/qstringlist.h> -#include "qsocketnotifier.h" -#include "qscreen_qws.h" - -#include <tslib.h> -#include <errno.h> - -QT_BEGIN_NAMESPACE - -#ifdef TSLIBMOUSEHANDLER_DEBUG -# include <QtCore/QDebug> -#endif - -/*! - \internal - - \class QWSTslibMouseHandler - \ingroup qws - - \brief The QWSTslibMouseHandler class implements a mouse driver - for the Universal Touch Screen Library, tslib. - - QWSTslibMouseHandler inherits the QWSCalibratedMouseHandler class, - providing calibration and noise reduction functionality in - addition to generating mouse events, for devices using the - Universal Touch Screen Library. - - To be able to compile this mouse handler, \l{Qt for Embedded Linux} - must be configured with the \c -qt-mouse-tslib option, see the - \l{Pointer Handling} documentation for details. In addition, the tslib - headers and library must be present in the build environment. The - tslib sources can be downloaded from \l - {http://tslib.berlios.de/}. Use the \c -L and \c -I options - with \c configure to explicitly specify the location of the - library and its headers: - - \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 0 - - In order to use this mouse handler, tslib must also be correctly - installed on the target machine. This includes providing a \c - ts.conf configuration file and setting the necessary environment - variables, see the README file provided with tslib for details. - - The ts.conf file will usually contain the following two lines - - \snippet doc/src/snippets/code/src_gui_embedded_qmousetslib_qws.cpp 1 - - To make \l{Qt for Embedded Linux} explicitly choose the tslib mouse - handler, set the QWS_MOUSE_PROTO environment variable. - - \sa {Pointer Handling}, {Qt for Embedded Linux} -*/ - -class QWSTslibMouseHandlerPrivate : public QObject -{ - Q_OBJECT -public: - QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h, - const QString &device); - ~QWSTslibMouseHandlerPrivate(); - - void suspend(); - void resume(); - - void calibrate(const QWSPointerCalibrationData *data); - void clearCalibration(); - -private: - QWSTslibMouseHandler *handler; - struct tsdev *dev; - QSocketNotifier *mouseNotifier; - int jitter_limit; - - struct ts_sample lastSample; - bool wasPressed; - int lastdx; - int lastdy; - - bool calibrated; - QString devName; - - bool open(); - void close(); - inline bool get_sample(struct ts_sample *sample); - -private slots: - void readMouseData(); -}; - -QWSTslibMouseHandlerPrivate::QWSTslibMouseHandlerPrivate(QWSTslibMouseHandler *h, - const QString &device) - : handler(h), dev(0), mouseNotifier(0), jitter_limit(3) -{ - QStringList args = device.split(QLatin1Char(':'), QString::SkipEmptyParts); - QRegExp jitterRegex(QLatin1String("^jitter_limit=(\\d+)$")); - int index = args.indexOf(jitterRegex); - if (index >= 0) { - jitter_limit = jitterRegex.cap(1).toInt(); - args.removeAt(index); - } - - devName = args.join(QString()); - - if (devName.isNull()) { - const char *str = getenv("TSLIB_TSDEVICE"); - if (str) - devName = QString::fromLocal8Bit(str); - } - - if (devName.isNull()) - devName = QLatin1String("/dev/ts"); - - if (!open()) - return; - - calibrated = true; - - int fd = ts_fd(dev); - mouseNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData())); - resume(); -} - -QWSTslibMouseHandlerPrivate::~QWSTslibMouseHandlerPrivate() -{ - close(); -} - -bool QWSTslibMouseHandlerPrivate::open() -{ - dev = ts_open(devName.toLocal8Bit().constData(), 1); - if (!dev) { - qCritical("QWSTslibMouseHandlerPrivate: ts_open() failed" - " with error: '%s'", strerror(errno)); - qCritical("Please check your tslib installation!"); - return false; - } - - if (ts_config(dev)) { - qCritical("QWSTslibMouseHandlerPrivate: ts_config() failed" - " with error: '%s'", strerror(errno)); - qCritical("Please check your tslib installation!"); - close(); - return false; - } - - return true; -} - -void QWSTslibMouseHandlerPrivate::close() -{ - if (dev) - ts_close(dev); -} - -void QWSTslibMouseHandlerPrivate::suspend() -{ - if (mouseNotifier) - mouseNotifier->setEnabled(false); -} - -void QWSTslibMouseHandlerPrivate::resume() -{ - memset(&lastSample, 0, sizeof(lastSample)); - wasPressed = false; - lastdx = 0; - lastdy = 0; - if (mouseNotifier) - mouseNotifier->setEnabled(true); -} - -bool QWSTslibMouseHandlerPrivate::get_sample(struct ts_sample *sample) -{ - if (!calibrated) - return (ts_read_raw(dev, sample, 1) == 1); - - return (ts_read(dev, sample, 1) == 1); -} - -void QWSTslibMouseHandlerPrivate::readMouseData() -{ - if (!qt_screen) - return; - - for(;;) { - struct ts_sample sample = lastSample; - bool pressed = wasPressed; - - // Fast return if there's no events. - if (!get_sample(&sample)) - return; - pressed = (sample.pressure > 0); - - // Only return last sample unless there's a press/release event. - while (pressed == wasPressed) { - if (!get_sample(&sample)) - break; - pressed = (sample.pressure > 0); - } - - // work around missing coordinates on mouse release in raw mode - if (!calibrated && !pressed && sample.x == 0 && sample.y == 0) { - sample.x = lastSample.x; - sample.y = lastSample.y; - } - - int dx = sample.x - lastSample.x; - int dy = sample.y - lastSample.y; - - // Remove small movements in oppsite direction - if (dx * lastdx < 0 && qAbs(dx) < jitter_limit) { - sample.x = lastSample.x; - dx = 0; - } - if (dy * lastdy < 0 && qAbs(dy) < jitter_limit) { - sample.y = lastSample.y; - dy = 0; - } - - if (wasPressed == pressed && dx == 0 && dy == 0) - return; - -#ifdef TSLIBMOUSEHANDLER_DEBUG - qDebug() << "last" << QPoint(lastSample.x, lastSample.y) - << "curr" << QPoint(sample.x, sample.y) - << "dx,dy" << QPoint(dx, dy) - << "ddx,ddy" << QPoint(dx*lastdx, dy*lastdy) - << "pressed" << wasPressed << pressed; -#endif - - lastSample = sample; - wasPressed = pressed; - if (dx != 0) - lastdx = dx; - if (dy != 0) - lastdy = dy; - - const QPoint p(sample.x, sample.y); - if (calibrated) { - // tslib should do all the translation and filtering, so we send a - // "raw" mouse event - handler->QWSMouseHandler::mouseChanged(p, pressed); - } else { - handler->sendFiltered(p, pressed); - } - } -} - -void QWSTslibMouseHandlerPrivate::clearCalibration() -{ - suspend(); - close(); - handler->QWSCalibratedMouseHandler::clearCalibration(); - calibrated = false; - open(); - resume(); -} - -void QWSTslibMouseHandlerPrivate::calibrate(const QWSPointerCalibrationData *data) -{ - suspend(); - close(); - // default implementation writes to /etc/pointercal - // using the same format as the tslib linear module. - handler->QWSCalibratedMouseHandler::calibrate(data); - calibrated = true; - open(); - resume(); -} - -/*! - \internal -*/ -QWSTslibMouseHandler::QWSTslibMouseHandler(const QString &driver, - const QString &device) - : QWSCalibratedMouseHandler(driver, device) -{ - d = new QWSTslibMouseHandlerPrivate(this, device); -} - -/*! - \internal -*/ -QWSTslibMouseHandler::~QWSTslibMouseHandler() -{ - delete d; -} - -/*! - \reimp -*/ -void QWSTslibMouseHandler::suspend() -{ - d->suspend(); -} - -/*! - \reimp -*/ -void QWSTslibMouseHandler::resume() -{ - d->resume(); -} - -/*! - \reimp -*/ -void QWSTslibMouseHandler::clearCalibration() -{ - d->clearCalibration(); -} - -/*! - \reimp -*/ -void QWSTslibMouseHandler::calibrate(const QWSPointerCalibrationData *data) -{ - d->calibrate(data); -} - -QT_END_NAMESPACE - -#include "qmousetslib_qws.moc" - -#endif //QT_NO_QWS_MOUSE_TSLIB diff --git a/src/gui/embedded/qmousetslib_qws.h b/src/gui/embedded/qmousetslib_qws.h deleted file mode 100644 index fc6206c03f..0000000000 --- a/src/gui/embedded/qmousetslib_qws.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSETSLIB_QWS_H -#define QMOUSETSLIB_QWS_H - -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if !defined(QT_NO_QWS_MOUSE_TSLIB) || defined(QT_PLUGIN) - -class QWSTslibMouseHandlerPrivate; - -class QWSTslibMouseHandler : public QWSCalibratedMouseHandler -{ -public: - explicit QWSTslibMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - ~QWSTslibMouseHandler(); - - void suspend(); - void resume(); - - void calibrate(const QWSPointerCalibrationData *data); - void clearCalibration(); - -protected: - friend class QWSTslibMouseHandlerPrivate; - QWSTslibMouseHandlerPrivate *d; -}; - - -#endif // QT_NO_QWS_MOUSE_TSLIB -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QMOUSETSLIB_QWS_H diff --git a/src/gui/embedded/qmousevfb_qws.cpp b/src/gui/embedded/qmousevfb_qws.cpp deleted file mode 100644 index 76eff3efe1..0000000000 --- a/src/gui/embedded/qmousevfb_qws.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_QWS_MOUSE_QVFB - -#include <stdlib.h> -#include <sys/types.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdio.h> - -#include <qvfbhdr.h> -#include <qmousevfb_qws.h> -#include <qwindowsystem_qws.h> -#include <qsocketnotifier.h> -#include <qapplication.h> -#include <qtimer.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -QT_BEGIN_NAMESPACE - -QVFbMouseHandler::QVFbMouseHandler(const QString &driver, const QString &device) - : QObject(), QWSMouseHandler(driver, device) -{ - QString mouseDev = device; - if (device.isEmpty()) - mouseDev = QLatin1String("/dev/vmouse"); - - mouseFD = QT_OPEN(mouseDev.toLatin1().constData(), O_RDWR | O_NDELAY); - if (mouseFD == -1) { - perror("QVFbMouseHandler::QVFbMouseHandler"); - qWarning("QVFbMouseHander: Unable to open device %s", - qPrintable(mouseDev)); - return; - } - - // Clear pending input - char buf[2]; - while (QT_READ(mouseFD, buf, 1) > 0) { } - - mouseIdx = 0; - - mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, this); - connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData())); -} - -QVFbMouseHandler::~QVFbMouseHandler() -{ - if (mouseFD >= 0) - QT_CLOSE(mouseFD); -} - -void QVFbMouseHandler::resume() -{ - mouseNotifier->setEnabled(true); -} - -void QVFbMouseHandler::suspend() -{ - mouseNotifier->setEnabled(false); -} - -void QVFbMouseHandler::readMouseData() -{ - int n; - do { - n = QT_READ(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx); - if (n > 0) - mouseIdx += n; - } while (n > 0); - - int idx = 0; - static const int packetsize = sizeof(QPoint) + 2*sizeof(int); - while (mouseIdx-idx >= packetsize) { - uchar *mb = mouseBuf+idx; - QPoint mousePos = *reinterpret_cast<QPoint *>(mb); - mb += sizeof(QPoint); - int bstate = *reinterpret_cast<int *>(mb); - mb += sizeof(int); - int wheel = *reinterpret_cast<int *>(mb); -// limitToScreen(mousePos); - mouseChanged(mousePos, bstate, wheel); - idx += packetsize; - } - - int surplus = mouseIdx - idx; - for (int i = 0; i < surplus; i++) - mouseBuf[i] = mouseBuf[idx+i]; - mouseIdx = surplus; -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_MOUSE_QVFB diff --git a/src/gui/embedded/qmousevfb_qws.h b/src/gui/embedded/qmousevfb_qws.h deleted file mode 100644 index f2e7bd14fc..0000000000 --- a/src/gui/embedded/qmousevfb_qws.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOUSEVFB_QWS_H -#define QMOUSEVFB_QWS_H - -#include <QtGui/qmouse_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MOUSE_QVFB - -class QSocketNotifier; - -class QVFbMouseHandler : public QObject, public QWSMouseHandler { - Q_OBJECT -public: - QVFbMouseHandler(const QString &driver = QString(), - const QString &device = QString()); - ~QVFbMouseHandler(); - - void resume(); - void suspend(); - -private: - int mouseFD; - int mouseIdx; - enum {mouseBufSize = 128}; - uchar mouseBuf[mouseBufSize]; - QSocketNotifier *mouseNotifier; - -private Q_SLOTS: - void readMouseData(); -}; -#endif // QT_NO_QWS_MOUSE_QVFB - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMOUSEVFB_QWS_H diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp deleted file mode 100644 index 90561fd06d..0000000000 --- a/src/gui/embedded/qscreen_qws.cpp +++ /dev/null @@ -1,3347 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" -#include "qscreen_qws.h" - -#include "qcolormap.h" -#include "qscreendriverfactory_qws.h" -#include "qwindowsystem_qws.h" -#include "qwidget.h" -#include "qcolor.h" -#include "qpixmap.h" -#include "qvarlengtharray.h" -#include "qwsdisplay_qws.h" -#include "qpainter.h" -#include <private/qdrawhelper_p.h> -#include <private/qpaintengine_raster_p.h> -#include <private/qpixmap_raster_p.h> -#include <private/qwindowsurface_qws_p.h> -#include <private/qpainter_p.h> -#include <private/qwidget_p.h> -#include <private/qgraphicssystem_qws_p.h> - -QT_BEGIN_NAMESPACE - -// #define QT_USE_MEMCPY_DUFF - -#ifndef QT_NO_QWS_CURSOR -Q_GUI_EXPORT QScreenCursor * qt_screencursor = 0; -#endif -Q_GUI_EXPORT QScreen * qt_screen = 0; - -ClearCacheFunc QScreen::clearCacheFunc = 0; - -#ifndef QT_NO_QWS_CURSOR -/*! - \class QScreenCursor - \ingroup qws - - \brief The QScreenCursor class is a base class for screen cursors - in Qt for Embedded Linux. - - Note that this class is non-portable, and that it is only - available in \l{Qt for Embedded Linux}. - - QScreenCursor implements a software cursor, but can be subclassed - to support hardware cursors as well. When deriving from the - QScreenCursor class it is important to maintain the cursor's - image, position, hot spot (the point within the cursor's image - that will be the position of the associated mouse events) and - visibility as well as informing whether it is hardware accelerated - or not. - - Note that there may only be one screen cursor at a time. Use the - static instance() function to retrieve a pointer to the current - screen cursor. Typically, the cursor is constructed by the QScreen - class or one of its descendants when it is initializing the - device; the QScreenCursor class should never be instantiated - explicitly. - - Use the move() function to change the position of the cursor, and - the set() function to alter its image or its hot spot. In - addition, you can find out whether the cursor is accelerated or - not, using the isAccelerated() function, and the boundingRect() - function returns the cursor's bounding rectangle. - - The cursor's appearance can be controlled using the isVisible(), - hide() and show() functions; alternatively the QWSServer class - provides some means of controlling the cursor's appearance using - the QWSServer::isCursorVisible() and QWSServer::setCursorVisible() - functions. - - \sa QScreen, QWSServer -*/ - -/*! - \fn static QScreenCursor* QScreenCursor::instance() - \since 4.2 - - Returns a pointer to the application's unique screen cursor. -*/ - -/*! - Constructs a screen cursor -*/ -QScreenCursor::QScreenCursor() -{ - pos = QPoint(qt_screen->deviceWidth()/2, qt_screen->deviceHeight()/2); - size = QSize(0,0); - enable = true; - hwaccel = false; - supportsAlpha = true; -} - -/*! - Destroys the screen cursor. -*/ -QScreenCursor::~QScreenCursor() -{ -} - -/*! - Hides the cursor from the screen. - - \sa show() -*/ -void QScreenCursor::hide() -{ - if (enable) { - enable = false; - if (!hwaccel) - qt_screen->exposeRegion(boundingRect(), 0); - } -} - -/*! - Shows the mouse cursor. - - \sa hide() -*/ -void QScreenCursor::show() -{ - if (!enable) { - enable = true; - if (!hwaccel) - qt_screen->exposeRegion(boundingRect(), 0); - } -} - -/*! - Sets the cursor's image to be the given \a image. - - The \a hotx and \a hoty parameters define the cursor's hot spot, - i.e., the point within the cursor's image that will be the - position of the associated mouse events. - - \sa move() -*/ -void QScreenCursor::set(const QImage &image, int hotx, int hoty) -{ - const QRect r = boundingRect(); - - hotspot = QPoint(hotx, hoty); - // These are in almost all cases the fastest formats to blend - QImage::Format f; - switch (qt_screen->depth()) { - case 12: - f = QImage::Format_ARGB4444_Premultiplied; - break; - case 15: - f = QImage::Format_ARGB8555_Premultiplied; - break; - case 16: - f = QImage::Format_ARGB8565_Premultiplied; - break; - case 18: - f = QImage::Format_ARGB6666_Premultiplied; - break; - default: - f = QImage::Format_ARGB32_Premultiplied; - } - - cursor = image.convertToFormat(f); - - size = image.size(); - - if (enable && !hwaccel) - qt_screen->exposeRegion(r | boundingRect(), 0); -} - -/*! - Moves the mouse cursor to the given position, i.e., (\a x, \a y). - - Note that the given position defines the top-left corner of the - cursor's image, i.e., not the cursor's hot spot (the position of - the associated mouse events). - - \sa set() -*/ -void QScreenCursor::move(int x, int y) -{ - QRegion r = boundingRect(); - pos = QPoint(x,y); - if (enable && !hwaccel) { - r |= boundingRect(); - qt_screen->exposeRegion(r, 0); - } -} - - -/*! - \fn void QScreenCursor::initSoftwareCursor () - - Initializes the screen cursor. - - This function is typically called from the screen driver when - initializing the device. Alternatively, the cursor can be set - directly using the pointer returned by the static instance() - function. - - \sa QScreen::initDevice() -*/ -void QScreenCursor::initSoftwareCursor() -{ - qt_screencursor = new QScreenCursor; -} - - -#endif // QT_NO_QWS_CURSOR - - -/*! - \fn QRect QScreenCursor::boundingRect () const - - Returns the cursor's bounding rectangle. -*/ - -/*! - \internal - \fn bool QScreenCursor::enabled () -*/ - -/*! - \fn QImage QScreenCursor::image () const - - Returns the cursor's image. -*/ - - -/*! - \fn bool QScreenCursor::isAccelerated () const - - Returns true if the cursor is accelerated; otherwise false. -*/ - -/*! - \fn bool QScreenCursor::isVisible () const - - Returns true if the cursor is visible; otherwise false. -*/ - -/*! - \internal - \fn bool QScreenCursor::supportsAlphaCursor () const -*/ - -/* - \variable QScreenCursor::cursor - - \brief the cursor's image. - - \sa image() -*/ - -/* - \variable QScreenCursor::size - - \brief the cursor's size -*/ - -/* - \variable QScreenCursor::pos - - \brief the cursor's position, i.e., the position of the top-left - corner of the crsor's image - - \sa set(), move() -*/ - -/* - \variable QScreenCursor::hotspot - - \brief the cursor's hotspot, i.e., the point within the cursor's - image that will be the position of the associated mouse events. - - \sa set(), move() -*/ - -/* - \variable QScreenCursor::enable - - \brief whether the cursor is visible or not - - \sa isVisible() -*/ - -/* - \variable QScreenCursor::hwaccel - - \brief holds whether the cursor is accelerated or not - - If the cursor is not accelerated, its image will be included by - the screen when it composites the window surfaces. - - \sa isAccelerated() - -*/ - -/* - \variable QScreenCursor::supportsAlpha -*/ - -/*! - \internal - \macro qt_screencursor - \relates QScreenCursor - - A global pointer referring to the unique screen cursor. It is - equivalent to the pointer returned by the - QScreenCursor::instance() function. -*/ - - - -class QScreenPrivate -{ -public: - QScreenPrivate(QScreen *parent, QScreen::ClassId id = QScreen::CustomClass); - ~QScreenPrivate(); - - inline QImage::Format preferredImageFormat() const; - - typedef void (*SolidFillFunc)(QScreen*, const QColor&, const QRegion&); - typedef void (*BlitFunc)(QScreen*, const QImage&, const QPoint&, const QRegion&); - - SolidFillFunc solidFill; - BlitFunc blit; - - QPoint offset; - QList<QScreen*> subScreens; - QPixmapDataFactory* pixmapFactory; - QGraphicsSystem* graphicsSystem; - QWSGraphicsSystem defaultGraphicsSystem; //### - QImage::Format pixelFormat; -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - bool fb_is_littleEndian; -#endif -#ifdef QT_QWS_CLIENTBLIT - bool supportsBlitInClients; -#endif - int classId; - QScreen *q_ptr; -}; - -template <typename T> -static void solidFill_template(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - T *dest = reinterpret_cast<T*>(screen->base()); - const T c = qt_colorConvert<T, quint32>(color.rgba(), 0); - const int stride = screen->linestep(); - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); - } -} - -#ifdef QT_QWS_DEPTH_GENERIC -static void solidFill_rgb_32bpp(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - quint32 *dest = reinterpret_cast<quint32*>(screen->base()); - const quint32 c = qt_convertToRgb<quint32>(color.rgba()); - - const int stride = screen->linestep(); - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); - } -} - -static void solidFill_rgb_16bpp(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - quint16 *dest = reinterpret_cast<quint16*>(screen->base()); - const quint16 c = qt_convertToRgb<quint32>(color.rgba()); - - const int stride = screen->linestep(); - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); - } -} -#endif // QT_QWS_DEPTH_GENERIC - -#ifdef QT_QWS_DEPTH_4 -static inline void qt_rectfill_gray4(quint8 *dest, quint8 value, - int x, int y, int width, int height, - int stride) -{ - const int pixelsPerByte = 2; - dest += y * stride + x / pixelsPerByte; - const int doAlign = x & 1; - const int doTail = (width - doAlign) & 1; - const int width8 = (width - doAlign) / pixelsPerByte; - - for (int j = 0; j < height; ++j) { - if (doAlign) - *dest = (*dest & 0xf0) | (value & 0x0f); - if (width8) - qt_memfill<quint8>(dest + doAlign, value, width8); - if (doTail) { - quint8 *d = dest + doAlign + width8; - *d = (*d & 0x0f) | (value & 0xf0); - } - dest += stride; - } -} - -static void solidFill_gray4(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - quint8 *dest = reinterpret_cast<quint8*>(screen->base()); - const quint8 c = qGray(color.rgba()) >> 4; - const quint8 c8 = (c << 4) | c; - - const int stride = screen->linestep(); - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - qt_rectfill_gray4(dest, c8, r.x(), r.y(), r.width(), r.height(), - stride); - } -} -#endif // QT_QWS_DEPTH_4 - -#ifdef QT_QWS_DEPTH_1 -static inline void qt_rectfill_mono(quint8 *dest, quint8 value, - int x, int y, int width, int height, - int stride) -{ - const int pixelsPerByte = 8; - const int alignWidth = qMin(width, (8 - (x & 7)) & 7); - const int doAlign = (alignWidth > 0 ? 1 : 0); - const int alignStart = pixelsPerByte - 1 - (x & 7); - const int alignStop = alignStart - (alignWidth - 1); - const quint8 alignMask = ((1 << alignWidth) - 1) << alignStop; - const int tailWidth = (width - alignWidth) & 7; - const int doTail = (tailWidth > 0 ? 1 : 0); - const quint8 tailMask = (1 << (pixelsPerByte - tailWidth)) - 1; - const int width8 = (width - alignWidth) / pixelsPerByte; - - dest += y * stride + x / pixelsPerByte; - stride -= (doAlign + width8); - - for (int j = 0; j < height; ++j) { - if (doAlign) { - *dest = (*dest & ~alignMask) | (value & alignMask); - ++dest; - } - if (width8) { - qt_memfill<quint8>(dest, value, width8); - dest += width8; - } - if (doTail) - *dest = (*dest & tailMask) | (value & ~tailMask); - dest += stride; - } -} - -static void solidFill_mono(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - quint8 *dest = reinterpret_cast<quint8*>(screen->base()); - const quint8 c8 = (qGray(color.rgba()) >> 7) * 0xff; - - const int stride = screen->linestep(); - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - qt_rectfill_mono(dest, c8, r.x(), r.y(), r.width(), r.height(), - stride); - } -} -#endif // QT_QWS_DEPTH_1 - -void qt_solidFill_setup(QScreen *screen, const QColor &color, - const QRegion ®ion) -{ - switch (screen->depth()) { -#ifdef QT_QWS_DEPTH_32 - case 32: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->solidFill = solidFill_template<quint32>; - else - screen->d_ptr->solidFill = solidFill_template<qabgr8888>; - break; -#endif -#ifdef QT_QWS_DEPTH_24 - case 24: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->solidFill = solidFill_template<qrgb888>; - else - screen->d_ptr->solidFill = solidFill_template<quint24>; - break; -#endif -#ifdef QT_QWS_DEPTH_18 - case 18: - screen->d_ptr->solidFill = solidFill_template<quint18>; - break; -#endif -#ifdef QT_QWS_DEPTH_16 - case 16: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->solidFill = solidFill_template<quint16>; - else - screen->d_ptr->solidFill = solidFill_template<qbgr565>; - break; -#endif -#ifdef QT_QWS_DEPTH_15 - case 15: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->solidFill = solidFill_template<qrgb555>; - else - screen->d_ptr->solidFill = solidFill_template<qbgr555>; - break; -#endif -#ifdef QT_QWS_DEPTH_12 - case 12: - screen->d_ptr->solidFill = solidFill_template<qrgb444>; - break; -#endif -#ifdef QT_QWS_DEPTH_8 - case 8: - screen->d_ptr->solidFill = solidFill_template<quint8>; - break; -#endif -#ifdef QT_QWS_DEPTH_4 - case 4: - screen->d_ptr->solidFill = solidFill_gray4; - break; -#endif -#ifdef QT_QWS_DEPTH_1 - case 1: - screen->d_ptr->solidFill = solidFill_mono; - break; -#endif - default: - qFatal("solidFill_setup(): Screen depth %d not supported!", - screen->depth()); - screen->d_ptr->solidFill = 0; - break; - } - screen->d_ptr->solidFill(screen, color, region); -} - -template <typename DST, typename SRC> -static void blit_template(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - DST *dest = reinterpret_cast<DST*>(screen->base()); - const int screenStride = screen->linestep(); - const int imageStride = image.bytesPerLine(); - - if (region.rectCount() == 1) { - const QRect r = region.boundingRect(); - const SRC *src = reinterpret_cast<const SRC*>(image.scanLine(r.y())) - + r.x(); - qt_rectconvert<DST, SRC>(dest, src, - r.x() + topLeft.x(), r.y() + topLeft.y(), - r.width(), r.height(), - screenStride, imageStride); - } else { - const QVector<QRect> rects = region.rects(); - - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i); - const SRC *src = reinterpret_cast<const SRC*>(image.scanLine(r.y())) - + r.x(); - qt_rectconvert<DST, SRC>(dest, src, - r.x() + topLeft.x(), r.y() + topLeft.y(), - r.width(), r.height(), - screenStride, imageStride); - } - } -} - -#ifdef QT_QWS_DEPTH_32 -static void blit_32(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<quint32, quint32>(screen, image, topLeft, region); - return; -#ifdef QT_QWS_DEPTH_16 - case QImage::Format_RGB16: - blit_template<quint32, quint16>(screen, image, topLeft, region); - return; -#endif - default: - qCritical("blit_32(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_32 - -#ifdef QT_QWS_DEPTH_24 -static void blit_24(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<quint24, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB888: - blit_template<quint24, qrgb888>(screen, image, topLeft, region); - return; -#ifdef QT_QWS_DEPTH_16 - case QImage::Format_RGB16: - blit_template<quint24, quint16>(screen, image, topLeft, region); - return; -#endif - default: - qCritical("blit_24(): Image format %d not supported!", image.format()); - } -} - -static void blit_qrgb888(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<qrgb888, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB888: - blit_template<qrgb888, qrgb888>(screen, image, topLeft, region); - return; -#ifdef QT_QWS_DEPTH_16 - case QImage::Format_RGB16: - blit_template<qrgb888, quint16>(screen, image, topLeft, region); - return; -#endif - default: - qCritical("blit_24(): Image format %d not supported!", image.format()); - break; - } -} -#endif // QT_QWS_DEPTH_24 - -#ifdef QT_QWS_DEPTH_18 -static void blit_18(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<qrgb666, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB666: - blit_template<qrgb666, qrgb666>(screen, image, topLeft, region); - return; -#ifdef QT_QWS_DEPTH_16 - case QImage::Format_RGB16: - blit_template<qrgb666, quint16>(screen, image, topLeft, region); - return; -#endif - default: - qCritical("blit_18(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_18 - -#if (Q_BYTE_ORDER == Q_BIG_ENDIAN) && (defined(QT_QWS_DEPTH_16) || defined(QT_QWS_DEPTH_15)) -class quint16LE -{ -public: - inline quint16LE(quint32 v) { - data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8); - } - - inline quint16LE(int v) { - data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8); - } - - inline quint16LE(quint16 v) { - data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8); - } - - inline quint16LE(qrgb555 v) { - data = (( (quint16)v & 0xff00) >> 8) | - (( (quint16)v & 0x00ff) << 8); - } - - inline bool operator==(const quint16LE &v) const - { - return data == v.data; - } - -private: - quint16 data; -}; -#endif - -#ifdef QT_QWS_DEPTH_16 -static void blit_16(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - // ### This probably doesn't work but it's a case which should never happen - blit_template<quint16, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<quint16, quint16>(screen, image, topLeft, region); - return; - default: - qCritical("blit_16(): Image format %d not supported!", image.format()); - } -} - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN -static void blit_16_bigToLittleEndian(QScreen *screen, const QImage &image, - const QPoint &topLeft, - const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<quint16LE, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<quint16LE, quint16>(screen, image, topLeft, region); - return; - default: - qCritical("blit_16_bigToLittleEndian(): Image format %d not supported!", image.format()); - } -} - -#endif // Q_BIG_ENDIAN -#endif // QT_QWS_DEPTH_16 - -#ifdef QT_QWS_DEPTH_15 -static void blit_15(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<qrgb555, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB555: - blit_template<qrgb555, qrgb555>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<qrgb555, quint16>(screen, image, topLeft, region); - return; - default: - qCritical("blit_15(): Image format %d not supported!", image.format()); - } -} - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN -static void blit_15_bigToLittleEndian(QScreen *screen, const QImage &image, - const QPoint &topLeft, - const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB555: - blit_template<quint16LE, qrgb555>(screen, image, topLeft, region); - return; - default: - qCritical("blit_15_bigToLittleEndian(): Image format %d not supported!", image.format()); - } -} -#endif // Q_BIG_ENDIAN -#endif // QT_QWS_DEPTH_15 - - -#ifdef QT_QWS_DEPTH_12 -static void blit_12(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_ARGB4444_Premultiplied: - blit_template<qrgb444, qargb4444>(screen, image, topLeft, region); - return; - case QImage::Format_RGB444: - blit_template<qrgb444, qrgb444>(screen, image, topLeft, region); - return; - default: - qCritical("blit_12(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_12 - -#ifdef QT_QWS_DEPTH_8 -static void blit_8(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - blit_template<quint8, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<quint8, quint16>(screen, image, topLeft, region); - return; - case QImage::Format_ARGB4444_Premultiplied: - blit_template<quint8, qargb4444>(screen, image, topLeft, region); - return; - case QImage::Format_RGB444: - blit_template<quint8, qrgb444>(screen, image, topLeft, region); - return; - default: - qCritical("blit_8(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_8 - -#ifdef QT_QWS_DEPTH_4 - -struct qgray4 { quint8 dummy; } Q_PACKED; - -template <typename SRC> -Q_STATIC_TEMPLATE_FUNCTION inline quint8 qt_convertToGray4(SRC color); - -template <> -inline quint8 qt_convertToGray4(quint32 color) -{ - return qGray(color) >> 4; -} - -template <> -inline quint8 qt_convertToGray4(quint16 color) -{ - const int r = (color & 0xf800) >> 11; - const int g = (color & 0x07e0) >> 6; // only keep 5 bit - const int b = (color & 0x001f); - return (r * 11 + g * 16 + b * 5) >> 6; -} - -template <> -inline quint8 qt_convertToGray4(qrgb444 color) -{ - return qt_convertToGray4(quint32(color)); -} - -template <> -inline quint8 qt_convertToGray4(qargb4444 color) -{ - return qt_convertToGray4(quint32(color)); -} - -template <typename SRC> -Q_STATIC_TEMPLATE_FUNCTION inline void qt_rectconvert_gray4(qgray4 *dest4, const SRC *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - const int pixelsPerByte = 2; - quint8 *dest8 = reinterpret_cast<quint8*>(dest4) - + y * dstStride + x / pixelsPerByte; - const int doAlign = x & 1; - const int doTail = (width - doAlign) & 1; - const int width8 = (width - doAlign) / pixelsPerByte; - const int count8 = (width8 + 3) / 4; - - srcStride = srcStride / sizeof(SRC) - width; - dstStride -= (width8 + doAlign); - - for (int i = 0; i < height; ++i) { - if (doAlign) { - *dest8 = (*dest8 & 0xf0) | qt_convertToGray4<SRC>(*src++); - ++dest8; - } - if (count8) { - int n = count8; - switch (width8 & 0x03) // duff's device - { - case 0: do { *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4 - | qt_convertToGray4<SRC>(src[1]); - src += 2; - case 3: *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4 - | qt_convertToGray4<SRC>(src[1]); - src += 2; - case 2: *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4 - | qt_convertToGray4<SRC>(src[1]); - src += 2; - case 1: *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4 - | qt_convertToGray4<SRC>(src[1]); - src += 2; - } while (--n > 0); - } - } - - if (doTail) - *dest8 = qt_convertToGray4<SRC>(*src++) << 4 | (*dest8 & 0x0f); - - dest8 += dstStride; - src += srcStride; - } -} - -template <> -void qt_rectconvert(qgray4 *dest, const quint32 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_gray4<quint32>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qgray4 *dest, const quint16 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_gray4<quint16>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qgray4 *dest, const qrgb444 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_gray4<qrgb444>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qgray4 *dest, const qargb4444 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_gray4<qargb4444>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -static void blit_4(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_ARGB32_Premultiplied: - blit_template<qgray4, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<qgray4, quint16>(screen, image, topLeft, region); - return; - case QImage::Format_RGB444: - blit_template<qgray4, qrgb444>(screen, image, topLeft, region); - return; - case QImage::Format_ARGB4444_Premultiplied: - blit_template<qgray4, qargb4444>(screen, image, topLeft, region); - return; - default: - qCritical("blit_4(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_4 - -#ifdef QT_QWS_DEPTH_1 - -struct qmono { quint8 dummy; } Q_PACKED; - -template <typename SRC> -Q_STATIC_TEMPLATE_FUNCTION inline quint8 qt_convertToMono(SRC color); - -template <> -inline quint8 qt_convertToMono(quint32 color) -{ - return qGray(color) >> 7; -} - -template <> -inline quint8 qt_convertToMono(quint16 color) -{ - return (qGray(qt_colorConvert<quint32, quint16>(color, 0)) >> 7); -} - -template <> -inline quint8 qt_convertToMono(qargb4444 color) -{ - return (qGray(quint32(color)) >> 7); -} - -template <> -inline quint8 qt_convertToMono(qrgb444 color) -{ - return (qGray(quint32(color)) >> 7); -} - -template <typename SRC> -inline void qt_rectconvert_mono(qmono *dest, const SRC *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - const int pixelsPerByte = 8; - quint8 *dest8 = reinterpret_cast<quint8*>(dest) - + y * dstStride + x / pixelsPerByte; - const int alignWidth = qMin(width, (8 - (x & 7)) & 7); - const int doAlign = (alignWidth > 0 ? 1 : 0); - const int alignStart = pixelsPerByte - 1 - (x & 7); - const int alignStop = alignStart - (alignWidth - 1); - const quint8 alignMask = ((1 << alignWidth) - 1) << alignStop; - const int tailWidth = (width - alignWidth) & 7; - const int doTail = (tailWidth > 0 ? 1 : 0); - const quint8 tailMask = (1 << (pixelsPerByte - tailWidth)) - 1; - const int width8 = (width - alignWidth) / pixelsPerByte; - - srcStride = srcStride / sizeof(SRC) - (width8 * 8 + alignWidth); - dstStride -= (width8 + doAlign); - - for (int j = 0; j < height; ++j) { - if (doAlign) { - quint8 d = *dest8 & ~alignMask; - for (int i = alignStart; i >= alignStop; --i) - d |= qt_convertToMono<SRC>(*src++) << i; - *dest8++ = d; - } - for (int i = 0; i < width8; ++i) { - *dest8 = (qt_convertToMono<SRC>(src[0]) << 7) - | (qt_convertToMono<SRC>(src[1]) << 6) - | (qt_convertToMono<SRC>(src[2]) << 5) - | (qt_convertToMono<SRC>(src[3]) << 4) - | (qt_convertToMono<SRC>(src[4]) << 3) - | (qt_convertToMono<SRC>(src[5]) << 2) - | (qt_convertToMono<SRC>(src[6]) << 1) - | (qt_convertToMono<SRC>(src[7])); - src += 8; - ++dest8; - } - if (doTail) { - quint8 d = *dest8 & tailMask; - switch (tailWidth) { - case 7: d |= qt_convertToMono<SRC>(src[6]) << 1; - case 6: d |= qt_convertToMono<SRC>(src[5]) << 2; - case 5: d |= qt_convertToMono<SRC>(src[4]) << 3; - case 4: d |= qt_convertToMono<SRC>(src[3]) << 4; - case 3: d |= qt_convertToMono<SRC>(src[2]) << 5; - case 2: d |= qt_convertToMono<SRC>(src[1]) << 6; - case 1: d |= qt_convertToMono<SRC>(src[0]) << 7; - } - *dest8 = d; - } - - dest8 += dstStride; - src += srcStride; - } -} - -template <> -void qt_rectconvert(qmono *dest, const quint32 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_mono<quint32>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qmono *dest, const quint16 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_mono<quint16>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qmono *dest, const qrgb444 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_mono<qrgb444>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -template <> -void qt_rectconvert(qmono *dest, const qargb4444 *src, - int x, int y, int width, int height, - int dstStride, int srcStride) -{ - qt_rectconvert_mono<qargb4444>(dest, src, x, y, width, height, - dstStride, srcStride); -} - -static void blit_1(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_ARGB32_Premultiplied: - blit_template<qmono, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<qmono, quint16>(screen, image, topLeft, region); - return; - case QImage::Format_RGB444: - blit_template<qmono, qrgb444>(screen, image, topLeft, region); - return; - case QImage::Format_ARGB4444_Premultiplied: - blit_template<qmono, qargb4444>(screen, image, topLeft, region); - return; - default: - qCritical("blit_1(): Image format %d not supported!", image.format()); - } -} -#endif // QT_QWS_DEPTH_1 - -#ifdef QT_QWS_DEPTH_GENERIC - -static void blit_rgb(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (image.format()) { - case QImage::Format_ARGB32_Premultiplied: - blit_template<qrgb, quint32>(screen, image, topLeft, region); - return; - case QImage::Format_RGB16: - blit_template<qrgb, quint16>(screen, image, topLeft, region); - return; - default: - qCritical("blit_rgb(): Image format %d not supported!", image.format()); - } -} - -void qt_set_generic_blit(QScreen *screen, int bpp, - int len_red, int len_green, int len_blue, int len_alpha, - int off_red, int off_green, int off_blue, int off_alpha) -{ - qrgb::bpp = bpp / 8; - qrgb::len_red = len_red; - qrgb::len_green = len_green; - qrgb::len_blue = len_blue; - qrgb::len_alpha = len_alpha; - qrgb::off_red = off_red; - qrgb::off_green = off_green; - qrgb::off_blue = off_blue; - qrgb::off_alpha = off_alpha; - screen->d_ptr->blit = blit_rgb; - if (bpp == 16) - screen->d_ptr->solidFill = solidFill_rgb_16bpp; - else if (bpp == 32) - screen->d_ptr->solidFill = solidFill_rgb_32bpp; -} - -#endif // QT_QWS_DEPTH_GENERIC - -void qt_blit_setup(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion) -{ - switch (screen->depth()) { -#ifdef QT_QWS_DEPTH_32 - case 32: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->blit = blit_32; - else - screen->d_ptr->blit = blit_template<qabgr8888, quint32>; - break; -#endif -#ifdef QT_QWS_DEPTH_24 - case 24: - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->blit = blit_qrgb888; - else - screen->d_ptr->blit = blit_24; - break; -#endif -#ifdef QT_QWS_DEPTH_18 - case 18: - screen->d_ptr->blit = blit_18; - break; -#endif -#ifdef QT_QWS_DEPTH_16 - case 16: -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - if (screen->d_ptr->fb_is_littleEndian) - screen->d_ptr->blit = blit_16_bigToLittleEndian; - else -#endif - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->blit = blit_16; - else - screen->d_ptr->blit = blit_template<qbgr565, quint16>; - break; -#endif -#ifdef QT_QWS_DEPTH_15 - case 15: -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - if (screen->d_ptr->fb_is_littleEndian) - screen->d_ptr->blit = blit_15_bigToLittleEndian; - else -#endif // Q_BIG_ENDIAN - if (screen->pixelType() == QScreen::NormalPixel) - screen->d_ptr->blit = blit_15; - else - screen->d_ptr->blit = blit_template<qbgr555, qrgb555>; - break; -#endif -#ifdef QT_QWS_DEPTH_12 - case 12: - screen->d_ptr->blit = blit_12; - break; -#endif -#ifdef QT_QWS_DEPTH_8 - case 8: - screen->d_ptr->blit = blit_8; - break; -#endif -#ifdef QT_QWS_DEPTH_4 - case 4: - screen->d_ptr->blit = blit_4; - break; -#endif -#ifdef QT_QWS_DEPTH_1 - case 1: - screen->d_ptr->blit = blit_1; - break; -#endif - default: - qFatal("blit_setup(): Screen depth %d not supported!", - screen->depth()); - screen->d_ptr->blit = 0; - break; - } - screen->d_ptr->blit(screen, image, topLeft, region); -} - -QScreenPrivate::QScreenPrivate(QScreen *parent, QScreen::ClassId id) - : defaultGraphicsSystem(QWSGraphicsSystem(parent)), - pixelFormat(QImage::Format_Invalid), -#ifdef QT_QWS_CLIENTBLIT - supportsBlitInClients(false), -#endif - classId(id), q_ptr(parent) -{ - solidFill = qt_solidFill_setup; - blit = qt_blit_setup; -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - fb_is_littleEndian = false; -#endif - pixmapFactory = 0; - graphicsSystem = &defaultGraphicsSystem; -} - -QScreenPrivate::~QScreenPrivate() -{ -} - -QImage::Format QScreenPrivate::preferredImageFormat() const -{ - if (pixelFormat > QImage::Format_Indexed8) - return pixelFormat; - - if (q_ptr->depth() <= 16) - return QImage::Format_RGB16; - else - return QImage::Format_ARGB32_Premultiplied; -} - -/*! - \class QScreen - \ingroup qws - - \brief The QScreen class is a base class for screen drivers in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several screen - protocols, see the \l{Qt for Embedded Linux Display Management}{display - management} documentation for details. Custom screen drivers can - be implemented by subclassing the QScreen class and creating a - screen driver plugin (derived from QScreenDriverPlugin). The - default implementation of the QScreenDriverFactory class - will automatically detect the plugin, and load the driver into the - server application at run-time using Qt's \l {How to Create Qt - Plugins}{plugin system}. - - When rendering, the default behavior is for each - client to render its widgets as well as its decorations into - memory, while the server copies the memory content to the device's - framebuffer using the screen driver. See the \l{Qt for Embedded Linux - Architecture} overview for details (note that it is possible for - the clients to manipulate and control the underlying hardware - directly as well). - - Starting with Qt 4.2, it is also possible to add an - accelerated graphics driver to take advantage of available - hardware resources. See the \l{Adding an Accelerated Graphics - Driver to Qt for Embedded Linux} documentation for details. - - \tableofcontents - - \section1 Framebuffer Management - - When a \l{Qt for Embedded Linux} application starts running, it - calls the screen driver's connect() function to map the - framebuffer and the accelerated drivers that the graphics card - control registers. The connect() function should then read out the - parameters of the framebuffer and use them as required to set this - class's protected variables. - - The initDevice() function can be reimplemented to initialize the - graphics card. Note, however, that connect() is called \e before - the initDevice() function, so, for some hardware configurations, - some of the initialization that would normally be done in the - initDevice() function might have to be done in the connect() - function. - - Likewise, just before a \l{Qt for Embedded Linux} application - exits, it calls the screen driver's disconnect() function. The - server application will in addition call the shutdownDevice() - function before it calls disconnect(). Note that the default - implementation of the shutdownDevice() function only hides the - mouse cursor. - - QScreen also provides the save() and restore() functions, making - it possible to save and restore the state of the graphics - card. Note that the default implementations do nothing. Hardware - screen drivers should reimplement these functions to save (and - restore) its registers, enabling switching between virtual - consoles. - - In addition, you can use the base() function to retrieve a pointer - to the beginning of the framebuffer, and the region() function to - retrieve the framebuffer's region. Use the onCard() function to - determine whether the framebuffer is within the graphics card's - memory, and the totalSize() function to determine the size of the - available graphics card memory (including the screen). Finally, - you can use the offset() function to retrieve the offset between - the framebuffer's coordinates and the application's coordinate - system. - - \section1 Palette Management - - QScreen provides several functions to retrieve information about - the color palette: The clut() function returns a pointer to the - color lookup table (i.e. its color palette). Use the colorCount() - function to determine the number of entries in this table, and the - alloc() function to retrieve the palette index of the color that - is the closest match to a given RGB value. - - To determine if the screen driver supports a given color depth, - use the supportsDepth() function that returns true of the - specified depth is supported. - - \section1 Drawing on Screen - - When a screen update is required, the \l{Qt for Embedded Linux} server runs - through all the top-level windows that intersect with the region - that is about to be updated, and ensures that the associated - clients have updated their memory buffer. Then the server calls - the exposeRegion() function that composes the window surfaces and - copies the content of memory to screen by calling the blit() and - solidFill() functions. - - The blit() function copies a given region in a given image to a - specified point using device coordinates, while the solidFill() - function fills the given region of the screen with the specified - color. Note that normally there is no need to call either of these - functions explicitly. - - In addition, QScreen provides the blank() function that can be - reimplemented to prevent any contents from being displayed on the - screen, and the setDirty() function that can be reimplemented to - indicate that a given rectangle of the screen has been - altered. Note that the default implementations of these functions - do nothing. - - Reimplement the mapFromDevice() and mapToDevice() functions to - map objects from the framebuffer coordinate system to the - coordinate space used by the application, and vice versa. Be aware - that the default implementations simply return the given objects - as they are. - - \section1 Properties - - \table - \header \o Property \o Functions - \row - \o Size - \o - - The size of the screen can be retrieved using the screenSize() - function. The size is returned in bytes. - - The framebuffer's logical width and height can be retrieved using - width() and height(), respectively. These functions return values - are given in pixels. Alternatively, the physicalWidth() and - physicalHeight() function returns the same metrics in - millimeters. QScreen also provides the deviceWidth() and - deviceHeight() functions returning the physical width and height - of the device in pixels. Note that the latter metrics can differ - from the ones used if the display is centered within the - framebuffer. - - \row - \o Resolution - \o - - Reimplement the setMode() function to be able to set the - framebuffer to a new resolution (width and height) and bit depth. - - The current depth of the framebuffer can be always be retrieved - using the depth() function. Use the pixmapDepth() function to - obtain the preferred depth for pixmaps. - - \row - \o Pixmap Alignment - \o - - Use the pixmapOffsetAlignment() function to retrieve the value to - which the start address of pixmaps held in the graphics card's - memory, should be aligned. - - Use the pixmapLinestepAlignment() to retrieve the value to which - the \e {individual scanlines} of pixmaps should be aligned. - - \row - \o Image Display - \o - - The isInterlaced() function tells whether the screen is displaying - images progressively, and the isTransformed() function whether it - is rotated. The transformOrientation() function can be - reimplemented to return the current rotation. - - \row - \o Scanlines - \o - - Use the linestep() function to retrieve the length of each - scanline of the framebuffer. - - \row - \o Pixel Type - \o - - The pixelType() function returns the screen's pixel storage format as - described by the PixelType enum. - - \endtable - - \section1 Subclassing and Initial Values - - You need to set the following members when implementing a subclass of QScreen: - - \table - \header \o Member \o Initial Value - \row \o \l{QScreen::}{data} \o A pointer to the framebuffer if possible; - 0 otherwise. - \row \o \l{QScreen::}{lstep} \o The number of bytes between each scanline - in the framebuffer. - \row \o \l{QScreen::}{w} \o The logical screen width in pixels. - \row \o \l{QScreen::}{h} \o The logical screen height in pixels. - \row \o \l{QScreen::}{dw} \o The real screen width in pixels. - \row \o \l{QScreen::}{dh} \o The real screen height in pixels. - \row \o \l{QScreen::}{d} \o The number of bits per pixel. - \row \o \l{QScreen::}{physWidth} \o The screen width in millimeters. - \row \o \l{QScreen::}{physHeight} \o The screen height in millimeters. - \endtable - - The logical screen values are the same as the real screen values unless the - screen is transformed in some way; e.g., rotated. - - See also the \l{Accelerated Graphics Driver Example} for an example that - shows how to initialize these values. - - \sa QScreenDriverPlugin, QScreenDriverFactory, {Qt for Embedded Linux Display - Management} -*/ - -/*! - \enum QScreen::PixelType - - This enum describes the pixel storage format of the screen, - i.e. the order of the red (R), green (G) and blue (B) components - of a pixel. - - \value NormalPixel Red-green-blue (RGB) - \value BGRPixel Blue-green-red (BGR) - - \sa pixelType() -*/ - -/*! - \enum QScreen::ClassId - - This enum defines the class identifiers for the known screen subclasses. - - \value LinuxFBClass QLinuxFBScreen - \value TransformedClass QTransformedScreen - \value VNCClass QVNCScreen - \value MultiClass QMultiScreen - \value VFbClass QVFbScreen - \value DirectFBClass QDirectFBScreen - \value SvgalibClass QSvgalibScreen - \value ProxyClass QProxyScreen - \value GLClass QGLScreen - \value CustomClass Unknown QScreen subclass - - \sa classId() -*/ - -/*! - \variable QScreen::screenclut - \brief the color table - - Initialize this variable in a subclass using a paletted screen mode, - and initialize its partner, QScreen::screencols. - - \sa screencols -*/ - -/*! - \variable QScreen::screencols - \brief the number of entries in the color table - - Initialize this variable in a subclass using a paletted screen mode, - and initialize its partner, QScreen::screenclut. - - \sa screenclut -*/ - -/*! - \variable QScreen::data - \brief points to the first visible pixel in the frame buffer. - - You must initialize this variable if you are using the default - implementation of non-buffered painting Qt::WA_PaintOnScreen, - QPixmap::grabWindow() or QDirectPainter::frameBuffer(). If you - initialize this variable, you must also initialize QScreen::size and - QScreen::mapsize. - - \sa QScreen::size, QScreen::mapsize -*/ - -/*! - \variable QScreen::w - \brief the logical width of the screen. - - This variable \e{must} be initialized by a subclass. -*/ - -/*! - \variable QScreen::lstep - \brief the number of bytes representing a line in the frame buffer. - - i.e., \e{line step}. \c {data[lstep * 2]} is the address of the - first visible pixel in the third line of the frame buffer. - - \sa data -*/ - -/*! - \variable QScreen::h - \brief the logical height of the screen. - - This variable \e{must} be initialized by a subclass. -*/ - -/*! - \variable QScreen::d - \brief the pixel depth - - This is the number of significant bits used to set a pixel - color. This variable \e{must} be initialized by a subclass. -*/ - -/*! - \variable QScreen::pixeltype - \brief set to BGRPixel - - Set this variable to BGRPixel in a subclass, if the screen pixel - format is a BGR type and you have used setPixelFormat() to set the - pixel format to the corresponding RGB format. e.g., you have set the - pixel format to QImage::Format_RGB555, but your screen really uses - BGR, not RGB. -*/ - -/*! - \variable QScreen::grayscale - \brief the gray scale screen mode flag - - Set this variable to true in a subclass, if you are using a - grayscale screen mode. e.g., in an 8-bit mode where you don't want - to use the palette, but you want to use the grayscales. -*/ - -/*! - \variable QScreen::dw - \brief the device width - - This is the number of pixels in a row of the physical screen. It - \e{must} be initialized by a subclass. Normally, it should be set to - the logical width QScreen::w, but it might be different, e.g., if - you are doing rotations in software. - - \sa QScreen::w -*/ - -/*! - \variable QScreen::dh - \brief the device height - - This is the number of pixels in a column of the physical screen. It - \e{must} be initialized by a subclass. Normally, it should be set to - the logical height QScreen::h, but it might be different, e.g., if - you are doing rotations in software. - - \sa QScreen::h -*/ - -/*! - \variable QScreen::size - \brief the number of bytes in the visible region of the frame buffer - - This is the number of bytes in the visible part of the block pointed - to by the QScreen::data pointer. You must initialize this variable - if you initialize the QScreen::data pointer. - - \sa QScreen::data, QScreen::mapsize -*/ - -/*! - \variable QScreen::mapsize - \brief the total number of bytes in the frame buffer - - This is the total number of bytes in the block pointed to by the - QScreen::data pointer. You must initialize this variable if you - initialize the QScreen::data pointer. - - \sa QScreen::data, QScreen::size -*/ - -/*! - \variable QScreen::physWidth - \brief the physical width of the screen in millimeters. - - Currently, this variable is used when calculating the screen DPI, - which in turn is used when deciding the actual font size Qt is - using. -*/ - -/*! - \variable QScreen::physHeight - \brief the physical height of the screen in millimeters. - - Currently, this variable is used when calculating the screen DPI, - which in turn is used when deciding the actual font size Qt is - using. -*/ - -/*! - \fn static QScreen* QScreen::instance() - - Returns a pointer to the application's QScreen instance. - - If this screen consists of several subscreens, operations to the - returned instance will affect all its subscreens. Use the - subscreens() function to retrieve access to a particular - subscreen. - - \sa subScreens(), subScreenIndexAt() -*/ - -/*! - \fn QList<QScreen*> QScreen::subScreens() const - \since 4.2 - - Returns a list of this screen's subscreens. Use the - subScreenIndexAt() function to retrieve the index of a screen at a - given position. - - Note that if \e this screen consists of several subscreens, - operations to \e this instance will affect all subscreens by - default. - - \sa instance(), subScreenIndexAt() -*/ - -/*! - \fn int QScreen::physicalWidth() const - \since 4.2 - - Returns the physical width of the screen in millimeters. - - \sa width(), deviceWidth(), physicalHeight() -*/ - -/*! - \fn int QScreen::physicalHeight() const - \since 4.2 - - Returns the physical height of the screen in millimeters. - - \sa height(), deviceHeight(), physicalWidth() -*/ - -/*! - \fn virtual bool QScreen::initDevice() = 0 - - This function is called by the \l{Qt for Embedded Linux} server to - initialize the framebuffer. Note that a server application will call the - connect() function prior to this function. - - Implement this function to make accelerated drivers set up the - graphics card. Return true to indicate success and false to indicate - failure. - - \sa shutdownDevice(), connect() -*/ - -/*! - \fn virtual bool QScreen::connect(const QString &displaySpec) = 0 - - This function is called by every \l{Qt for Embedded Linux} - application on startup, and must be implemented to map in the - framebuffer and the accelerated drivers that the graphics card - control registers. Note that connect must be called \e before - the initDevice() function. - - Ensure that true is returned if a connection to the screen device - is made. Otherwise, return false. Upon making the connection, the - function should read out the parameters of the framebuffer and use - them as required to set this class's protected variables. - - The \a displaySpec argument is passed by the QWS_DISPLAY - environment variable or the -display command line parameter, and - has the following syntax: - - \snippet doc/src/snippets/code/src_gui_embedded_qscreen_qws.cpp 0 - - For example, to use the mach64 driver on fb1 as display 2: - - \snippet doc/src/snippets/code/src_gui_embedded_qscreen_qws.cpp 1 - - See \l{Qt for Embedded Linux Display Management} for more details. - - \sa disconnect(), initDevice(), {Running Qt for Embedded Linux Applications} -*/ - -/*! - \fn QScreen::disconnect() - - This function is called by every \l{Qt for Embedded Linux} application - before exiting, and must be implemented to unmap the - framebuffer. Note that a server application will call the - shutdownDevice() function prior to this function. - - \sa connect(), shutdownDevice(), {Running Qt for Embedded Linux - Applications} -*/ - -/*! - \fn QScreen::setMode(int width, int height, int depth) - - Implement this function to reset the framebuffer's resolution (\a - width and \a height) and bit \a depth. - - After the resolution has been set, existing paint engines will be - invalid and the framebuffer should be completely redrawn. In a - multiple-process situation, all other applications must be - notified to reset their mode and update themselves accordingly. -*/ - -/*! - \fn QScreen::blank(bool on) - - Prevents the screen driver form displaying any content on the - screen. - - Note that the default implementation does nothing. - - Reimplement this function to prevent the screen driver from - displaying any contents on the screen if \a on is true; otherwise - the contents is expected to be shown. - - \sa blit() -*/ - -/*! - \fn int QScreen::pixmapOffsetAlignment() - - Returns the value (in bits) to which the start address of pixmaps - held in the graphics card's memory, should be aligned. - - Note that the default implementation returns 64; reimplement this - function to override the return value, e.g., when implementing an - accelerated driver (see the \l {Adding an Accelerated Graphics - Driver to Qt for Embedded Linux}{Adding an Accelerated Graphics Driver} - documentation for details). - - \sa pixmapLinestepAlignment() -*/ - -/*! - \fn int QScreen::pixmapLinestepAlignment() - - Returns the value (in bits) to which individual scanlines of - pixmaps held in the graphics card's memory, should be - aligned. - - Note that the default implementation returns 64; reimplement this - function to override the return value, e.g., when implementing an - accelerated driver (see the \l {Adding an Accelerated Graphics - Driver to Qt for Embedded Linux}{Adding an Accelerated Graphics Driver} - documentation for details). - - \sa pixmapOffsetAlignment() -*/ - -/*! - \fn QScreen::width() const - - Returns the logical width of the framebuffer in pixels. - - \sa deviceWidth(), physicalWidth(), height() -*/ - -/*! - \fn int QScreen::height() const - - Returns the logical height of the framebuffer in pixels. - - \sa deviceHeight(), physicalHeight(), width() -*/ - -/*! - \fn QScreen::depth() const - - Returns the depth of the framebuffer, in bits per pixel. - - Note that the returned depth is the number of bits each pixel - fills rather than the number of significant bits, so 24bpp and - 32bpp express the same range of colors (8 bits of red, green and - blue). - - \sa clut(), pixmapDepth() -*/ - -/*! - \fn int QScreen::pixmapDepth() const - - Returns the preferred depth for pixmaps, in bits per pixel. - - \sa depth() -*/ - -/*! - \fn QScreen::linestep() const - - Returns the length of each scanline of the framebuffer in bytes. - - \sa isInterlaced() -*/ - -/*! - \fn QScreen::deviceWidth() const - - Returns the physical width of the framebuffer device in pixels. - - Note that the returned width can differ from the width which - \l{Qt for Embedded Linux} will actually use, that is if the display is - centered within the framebuffer. - - \sa width(), physicalWidth(), deviceHeight() -*/ - -/*! - \fn QScreen::deviceHeight() const - - Returns the full height of the framebuffer device in pixels. - - Note that the returned height can differ from the height which - \l{Qt for Embedded Linux} will actually use, that is if the display is - centered within the framebuffer. - - \sa height(), physicalHeight(), deviceWidth() -*/ - -/*! - \fn uchar *QScreen::base() const - - Returns a pointer to the beginning of the framebuffer. - - \sa onCard(), region(), totalSize() -*/ - -/*! - \fn uchar *QScreen::cache(int) - - \internal - - This function is used to store pixmaps in graphics memory for the - use of the accelerated drivers. See QLinuxFbScreen (where the - caching is implemented) for more information. -*/ - -/*! - \fn QScreen::uncache(uchar *) - - \internal - - This function is called on pixmap destruction to remove them from - graphics card memory. -*/ - -/*! - \fn QScreen::screenSize() const - - Returns the size of the screen in bytes. - - The screen size is always located at the beginning of framebuffer - memory, i.e. it can also be retrieved using the base() function. - - \sa base(), region() -*/ - -/*! - \fn QScreen::totalSize() const - - Returns the size of the available graphics card memory (including - the screen) in bytes. - - \sa onCard() -*/ - -// Unaccelerated screen/driver setup. Can be overridden by accelerated -// drivers - -/*! - \fn QScreen::QScreen(int displayId) - - Constructs a new screen driver. - - The \a displayId identifies the \l{Qt for Embedded Linux} server to connect - to. -*/ - -/*! - \fn QScreen::clut() - - Returns a pointer to the screen's color lookup table (i.e. its - color palette). - - Note that this function only apply in paletted modes like 8-bit, - i.e. in modes where only the palette indexes (and not the actual - color values) are stored in memory. - - \sa alloc(), depth(), colorCount() -*/ - -/*! - \obsolete - \fn int QScreen::numCols() - - \sa colorCount() -*/ - -/*! - \since 4.6 - \fn int QScreen::colorCount() - - Returns the number of entries in the screen's color lookup table - (i.e. its color palette). A pointer to the color table can be - retrieved using the clut() function. - - \sa clut(), alloc() -*/ - -/*! - \since 4.4 - - Constructs a new screen driver. - - The \a display_id identifies the \l{Qt for Embedded Linux} - server to connect to. The \a classId specifies the class - identifier. -*/ -QScreen::QScreen(int display_id, ClassId classId) - : screencols(0), data(0), entries(0), entryp(0), lowest(0), - w(0), lstep(0), h(0), d(1), pixeltype(NormalPixel), grayscale(false), - dw(0), dh(0), size(0), mapsize(0), displayId(display_id), - physWidth(0), physHeight(0), d_ptr(new QScreenPrivate(this, classId)) -{ - clearCacheFunc = 0; -} - -QScreen::QScreen(int display_id) - : screencols(0), data(0), entries(0), entryp(0), lowest(0), - w(0), lstep(0), h(0), d(1), pixeltype(NormalPixel), grayscale(false), - dw(0), dh(0), size(0), mapsize(0), displayId(display_id), - physWidth(0), physHeight(0), d_ptr(new QScreenPrivate(this)) -{ - clearCacheFunc = 0; -} - -/*! - Destroys this screen driver. -*/ - -QScreen::~QScreen() -{ - delete d_ptr; -} - -/*! - This function is called by the \l{Qt for Embedded Linux} server before it - calls the disconnect() function when exiting. - - Note that the default implementation only hides the mouse cursor; - reimplement this function to do the necessary graphics card - specific cleanup. - - \sa initDevice(), disconnect() -*/ - -void QScreen::shutdownDevice() -{ -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->hide(); -#endif -} - -extern bool qws_accel; //in qapplication_qws.cpp - -/*! - \fn PixelType QScreen::pixelType() const - - Returns the pixel storage format of the screen. -*/ - -/*! - Returns the pixel format of the screen, or \c QImage::Format_Invalid - if the pixel format is not a supported image format. - -*/ -QImage::Format QScreen::pixelFormat() const -{ - return d_ptr->pixelFormat; -} - -/*! - Sets the screen's pixel format to \a format. - */ -void QScreen::setPixelFormat(QImage::Format format) -{ - d_ptr->pixelFormat = format; -} - - -/*! - \fn int QScreen::alloc(unsigned int red, unsigned int green, unsigned int blue) - - Returns the index in the screen's palette which is the closest - match to the given RGB value (\a red, \a green, \a blue). - - Note that this function only apply in paletted modes like 8-bit, - i.e. in modes where only the palette indexes (and not the actual - color values) are stored in memory. - - \sa clut(), colorCount() -*/ - -int QScreen::alloc(unsigned int r,unsigned int g,unsigned int b) -{ - int ret = 0; - if (d == 8) { - if (grayscale) - return qGray(r, g, b); - - // First we look to see if we match a default color - const int pos = (r + 25) / 51 * 36 + (g + 25) / 51 * 6 + (b + 25) / 51; - if (pos < screencols && screenclut[pos] == qRgb(r, g, b)) { - return pos; - } - - // search for nearest color - unsigned int mindiff = 0xffffffff; - unsigned int diff; - int dr,dg,db; - - for (int loopc = 0; loopc < screencols; ++loopc) { - dr = qRed(screenclut[loopc]) - r; - dg = qGreen(screenclut[loopc]) - g; - db = qBlue(screenclut[loopc]) - b; - diff = dr*dr + dg*dg + db*db; - - if (diff < mindiff) { - ret = loopc; - if (!diff) - break; - mindiff = diff; - } - } - } else if (d == 4) { - ret = qGray(r, g, b) >> 4; - } else if (d == 1) { - ret = qGray(r, g, b) >= 128; - } else { - qFatal("cannot alloc %dbpp color", d); - } - - return ret; -} - -/*! - Saves the current state of the graphics card. - - For example, hardware screen drivers should reimplement the save() - and restore() functions to save and restore its registers, - enabling swintching between virtual consoles. - - Note that the default implementation does nothing. - - \sa restore() -*/ - -void QScreen::save() -{ -} - -/*! - Restores the previously saved state of the graphics card. - - For example, hardware screen drivers should reimplement the save() - and restore() functions to save and restore its registers, - enabling swintching between virtual consoles. - - Note that the default implementation does nothing. - - \sa save() -*/ - -void QScreen::restore() -{ -} - -void QScreen::blank(bool) -{ -} - -/*! - \internal -*/ - -void QScreen::set(unsigned int, unsigned int, unsigned int, unsigned int) -{ -} - -/*! - \fn bool QScreen::supportsDepth(int depth) const - - Returns true if the screen supports the specified color \a depth; - otherwise returns false. - - \sa clut() -*/ - -bool QScreen::supportsDepth(int d) const -{ - if (false) { - //Just to simplify the ifdeffery -#ifdef QT_QWS_DEPTH_1 - } else if(d==1) { - return true; -#endif -#ifdef QT_QWS_DEPTH_4 - } else if(d==4) { - return true; -#endif -#ifdef QT_QWS_DEPTH_8 - } else if(d==8) { - return true; -#endif -#ifdef QT_QWS_DEPTH_16 - } else if(d==16) { - return true; -#endif -#ifdef QT_QWS_DEPTH_15 - } else if (d == 15) { - return true; -#endif -#ifdef QT_QWS_DEPTH_18 - } else if(d==18 || d==19) { - return true; -#endif -#ifdef QT_QWS_DEPTH_24 - } else if(d==24) { - return true; -#endif -#ifdef QT_QWS_DEPTH_32 - } else if(d==32) { - return true; -#endif - } - return false; -} - -/*! - \fn bool QScreen::onCard(const unsigned char *buffer) const - - Returns true if the specified \a buffer is within the graphics - card's memory; otherwise returns false (i.e. if it's in main RAM). - - \sa base(), totalSize() -*/ - -bool QScreen::onCard(const unsigned char * p) const -{ - long t=(unsigned long)p; - long bmin=(unsigned long)data; - if (t < bmin) - return false; - if(t >= bmin+mapsize) - return false; - return true; -} - -/*! - \fn bool QScreen::onCard(const unsigned char * buffer, ulong& offset) const - \overload - - If the specified \a buffer is within the graphics card's memory, - this function stores the offset from the start of graphics card - memory (in bytes), in the location specified by the \a offset - parameter. -*/ - -bool QScreen::onCard(const unsigned char * p, ulong& offset) const -{ - long t=(unsigned long)p; - long bmin=(unsigned long)data; - if (t < bmin) - return false; - long o = t - bmin; - if (o >= mapsize) - return false; - offset = o; - return true; -} - -/* -#if !defined(QT_NO_QWS_REPEATER) - { "Repeater", qt_get_screen_repeater, 0 }, -#endif -#if defined(QT_QWS_EE) - { "EE", qt_get_screen_ee, 0 }, -#endif - -*/ - -/* -Given a display_id (number of the \l{Qt for Embedded Linux} server to connect to) -and a spec (e.g. Mach64:/dev/fb0) return a QScreen-descendant. -The QScreenDriverFactory is queried for a suitable driver and, if found, -asked to create a driver. -People writing new graphics drivers should either hook their own -QScreen-descendant into QScreenDriverFactory or use the QScreenDriverPlugin -to make a dynamically loadable driver. -*/ - -Q_GUI_EXPORT QScreen* qt_get_screen(int display_id, const char *spec) -{ - QString displaySpec = QString::fromAscii(spec); - QString driver = displaySpec; - int colon = displaySpec.indexOf(QLatin1Char(':')); - if (colon >= 0) - driver.truncate(colon); - driver = driver.trimmed(); - - bool foundDriver = false; - QString driverName = driver; - - QStringList driverList; - if (!driver.isEmpty()) - driverList << driver; - else - driverList = QScreenDriverFactory::keys(); - - for (int i = 0; i < driverList.size(); ++i) { - const QString driverName = driverList.at(i); - qt_screen = QScreenDriverFactory::create(driverName, display_id); - if (qt_screen) { - foundDriver = true; - if (qt_screen->connect(displaySpec)) { - return qt_screen; - } else { - delete qt_screen; - qt_screen = 0; - } - } - } - - if (driver.isNull()) - qFatal("No suitable driver found"); - else if (foundDriver) - qFatal("%s: driver cannot connect", driver.toLatin1().constData()); - else - qFatal("%s: driver not found", driver.toLatin1().constData()); - - return 0; -} - -#ifndef QT_NO_QWS_CURSOR -static void blendCursor(QImage *dest, const QImage &cursor, const QPoint &offset) -{ - QRasterBuffer rb; - rb.prepare(dest); - - QSpanData spanData; - spanData.init(&rb, 0); - spanData.type = QSpanData::Texture; - spanData.initTexture(&cursor, 256); - spanData.dx = -offset.x(); - spanData.dy = -offset.y(); - if (!spanData.blend) - return; - - const QRect rect = QRect(offset, cursor.size()) - & QRect(QPoint(0, 0), dest->size()); - const int w = rect.width(); - const int h = rect.height(); - - QVarLengthArray<QT_FT_Span, 32> spans(h); - for (int i = 0; i < h; ++i) { - spans[i].x = rect.x(); - spans[i].len = w; - spans[i].y = rect.y() + i; - spans[i].coverage = 255; - } - spanData.blend(h, spans.constData(), &spanData); -} -#endif // QT_NO_QWS_CURSOR - -/*! - \fn void QScreen::exposeRegion(QRegion region, int windowIndex) - - This function is called by the \l{Qt for Embedded Linux} server whenever a - screen update is required. \a region is the area on the screen - that must be updated, and \a windowIndex is the index into - QWSServer::clientWindows() of the window that required the - update. QWSWindow::state() gives more information about the cause. - - The default implementation composes the - affected windows and paints the given \a region on screen by - calling the blit() and solidFill() functions - - This function can be reimplemented to perform composition in - hardware, or to perform transition effects. - For simpler hardware acceleration, or to interface with - this is typically done by reimplementing the blit() and - solidFill() functions instead. - - Note that there is no need to call this function explicitly. - - \sa blit(), solidFill(), blank() -*/ -void QScreen::exposeRegion(QRegion r, int windowIndex) -{ - r &= region(); - if (r.isEmpty()) - return; - - int changing = windowIndex; - // when we have just lowered a window, we have to expose all the windows below where the - // window used to be. - if (changing && qwsServer->clientWindows().at(changing)->state() == QWSWindow::Lowering) - changing = 0; -#ifdef QTOPIA_PERFTEST - static enum { PerfTestUnknown, PerfTestOn, PerfTestOff } perfTestState = PerfTestUnknown; - if(PerfTestUnknown == perfTestState) { - if(::getenv("QTOPIA_PERFTEST")) - perfTestState = PerfTestOn; - else - perfTestState = PerfTestOff; - } - if(PerfTestOn == perfTestState) { - QWSWindow *changed = qwsServer->clientWindows().at(changing); - if(!changed->client()->identity().isEmpty()) - qDebug() << "Performance : expose_region :" - << changed->client()->identity() - << r.boundingRect() << ": " - << qPrintable( QTime::currentTime().toString( "h:mm:ss.zzz" ) ); - } -#endif - - const QRect bounds = r.boundingRect(); - QRegion blendRegion; - QImage *blendBuffer = 0; - -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor && !qt_screencursor->isAccelerated()) { - blendRegion = r & qt_screencursor->boundingRect(); - } -#endif - compose(0, r, blendRegion, &blendBuffer, changing); - - if (blendBuffer && !blendBuffer->isNull()) { - const QPoint offset = blendRegion.boundingRect().topLeft(); -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor && !qt_screencursor->isAccelerated()) { - const QRect cursorRect = qt_screencursor->boundingRect(); - if (blendRegion.intersects(cursorRect)) { - blendCursor(blendBuffer, qt_screencursor->image(), - cursorRect.topLeft() - offset); - } - } -#endif // QT_NO_QWS_CURSOR - blit(*blendBuffer, offset, blendRegion); - delete blendBuffer; - } - - if (r.rectCount() == 1) { - setDirty(r.boundingRect()); - } else { - const QVector<QRect> rects = r.rects(); - for (int i = 0; i < rects.size(); ++i) - setDirty(rects.at(i)); - } -} - -/*! - \fn void QScreen::blit(const QImage &image, const QPoint &topLeft, const QRegion ®ion) - - Copies the given \a region in the given \a image to the point - specified by \a topLeft using device coordinates. - - This function is called from the exposeRegion() function; it is - not intended to be called explicitly. - - Reimplement this function to make use of \l{Adding an Accelerated - Graphics Driver to Qt for Embedded Linux}{accelerated hardware}. Note that - this function must be reimplemented if the framebuffer format is - not supported by \l{Qt for Embedded Linux} (See the - \l{Qt for Embedded Linux Display Management}{Display Management} - documentation for more details). - - \sa exposeRegion(), solidFill(), blank() -*/ -void QScreen::blit(const QImage &img, const QPoint &topLeft, const QRegion ®) -{ - const QRect bound = (region() & QRect(topLeft, img.size())).boundingRect(); - QWSDisplay::grab(); - d_ptr->blit(this, img, topLeft - offset(), - (reg & bound).translated(-topLeft)); - QWSDisplay::ungrab(); -} - -#ifdef QT_QWS_CLIENTBLIT -/*! - Returns true if this screen driver supports calling QScreen::blit() and - QScreen::setDirty() directly from non-server applications, otherwise returns - false. - - If available, this is used to optimize the performance of non-occluded, opaque - client windows by removing the server round trip when they are updated. - - \sa setSupportsBlitInClients() - */ -bool QScreen::supportsBlitInClients() const -{ - return d_ptr->supportsBlitInClients; -} - -/*! - If \a supported, the screen driver is marked as supporting blitting directly - from non-server applications. - - \sa supportsBlitInClients() - */ -void QScreen::setSupportsBlitInClients(bool supported) -{ - d_ptr->supportsBlitInClients = supported; -} -#endif - -/*! - \internal -*/ - -void QScreen::blit(QWSWindow *win, const QRegion &clip) -{ - QWSWindowSurface *surface = win->windowSurface(); - if (!surface) - return; - - const QImage &img = surface->image(); - if (img.isNull()) - return; - - const QRegion rgn = clip & win->paintedRegion(); - if (rgn.isEmpty()) - return; - - surface->lock(); - blit(img, win->requestedRegion().boundingRect().topLeft(), rgn); - surface->unlock(); -} - -struct fill_data { - quint32 color; - uchar *data; - int lineStep; - int x; - int y; - int w; - int h; -}; - -/*! - Fills the given \a region of the screen with the specified \a - color. - - This function is called from the exposeRegion() function; it is - not intended to be called explicitly. - - Reimplement this function to make use of \l{Adding an Accelerated - Graphics Driver to Qt for Embedded Linux}{accelerated hardware}. Note that - this function must be reimplemented if the framebuffer format is - not supported by \l{Qt for Embedded Linux} (See the - \l{Qt for Embedded Linux Display Management}{Display Management} - documentation for more details). - - \sa exposeRegion(), blit(), blank() -*/ -// the base class implementation works in device coordinates, so that transformed drivers can use it -void QScreen::solidFill(const QColor &color, const QRegion ®ion) -{ - QWSDisplay::grab(); - d_ptr->solidFill(this, color, - region.translated(-offset()) & QRect(0, 0, dw, dh)); - QWSDisplay::ungrab(); -} - -/*! - \since 4.2 - - Creates and returns a new window surface matching the given \a - key. - - The server application will call this function whenever it needs - to create a server side representation of a window, e.g. when - copying the content of memory to the screen using the screen - driver. - - Note that this function must be reimplemented when adding an - accelerated graphics driver. See the - \l{Adding an Accelerated Graphics Driver to Qt for Embedded Linux} - {Adding an Accelerated Graphics Driver} documentation for details. - - \sa {Qt for Embedded Linux Architecture} -*/ -QWSWindowSurface* QScreen::createSurface(const QString &key) const -{ -#ifndef QT_NO_PAINTONSCREEN - if (key == QLatin1String("OnScreen")) - return new QWSOnScreenSurface; - else -#endif - if (key == QLatin1String("mem")) - return new QWSLocalMemSurface; -#ifndef QT_NO_QWS_MULTIPROCESS - else if (key == QLatin1String("shm")) - return new QWSSharedMemSurface; -#endif -#ifndef QT_NO_PAINT_DEBUG - else if (key == QLatin1String("Yellow")) - return new QWSYellowSurface; -#endif -#ifndef QT_NO_DIRECTPAINTER - else if (key == QLatin1String("DirectPainter")) - return new QWSDirectPainterSurface; -#endif - - return 0; -} - -#ifndef QT_NO_PAINTONSCREEN -bool QScreen::isWidgetPaintOnScreen(const QWidget *w) -{ - static int doOnScreen = -1; - if (doOnScreen == -1) { - const QByteArray env = qgetenv("QT_ONSCREEN_PAINT"); - if (env == "force") - doOnScreen = 2; - else - doOnScreen = (env.toInt() > 0 ? 1 : 0); - } - - if (doOnScreen == 2) // force - return true; - - if (doOnScreen == 0 && !w->testAttribute(Qt::WA_PaintOnScreen)) - return false; - - return w->d_func()->isOpaque; -} -#endif - -/*! - \overload - - Creates and returns a new window surface for the given \a widget. -*/ -QWSWindowSurface* QScreen::createSurface(QWidget *widget) const -{ -#ifndef QT_NO_PAINTONSCREEN - if (isWidgetPaintOnScreen(widget) && base()) - return new QWSOnScreenSurface(widget); - else -#endif - if (QApplication::type() == QApplication::GuiServer) - return new QWSLocalMemSurface(widget); -#ifndef QT_NO_QWS_MULTIPROCESS - else - return new QWSSharedMemSurface(widget); -#endif - - return 0; -} - -void QScreen::compose(int level, const QRegion &exposed, QRegion &blend, - QImage **blendbuffer, int changing_level) -{ - QRect exposed_bounds = exposed.boundingRect(); - QWSWindow *win = 0; - do { - win = qwsServer->clientWindows().value(level); // null is background - ++level; - } while (win && !win->paintedRegion().boundingRect().intersects(exposed_bounds)); - - QWSWindowSurface *surface = (win ? win->windowSurface() : 0); - bool above_changing = level <= changing_level; // 0 is topmost - - QRegion exposedBelow = exposed; - bool opaque = true; - - if (win) { - opaque = win->isOpaque() || !surface->isBuffered(); - if (opaque) { - exposedBelow -= win->paintedRegion(); - if (above_changing || !surface->isBuffered()) - blend -= exposed & win->paintedRegion(); - } else { - blend += exposed & win->paintedRegion(); - } - } - if (win && !exposedBelow.isEmpty()) { - compose(level, exposedBelow, blend, blendbuffer, changing_level); - } else { - QSize blendSize = blend.boundingRect().size(); - if (!blendSize.isNull()) { - *blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat()); - } - } - - const QRegion blitRegion = exposed - blend; - if (!win) - paintBackground(blitRegion); - else if (!above_changing && surface->isBuffered()) - blit(win, blitRegion); - - QRegion blendRegion = exposed & blend; - - if (win) - blendRegion &= win->paintedRegion(); - if (!blendRegion.isEmpty()) { - - QPoint off = blend.boundingRect().topLeft(); - - QRasterBuffer rb; - rb.prepare(*blendbuffer); - QSpanData spanData; - spanData.init(&rb, 0); - if (!win) { - const QImage::Format format = (*blendbuffer)->format(); - switch (format) { - case QImage::Format_ARGB32_Premultiplied: - case QImage::Format_ARGB32: - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_ARGB8555_Premultiplied: - case QImage::Format_ARGB6666_Premultiplied: - case QImage::Format_ARGB4444_Premultiplied: - spanData.rasterBuffer->compositionMode = QPainter::CompositionMode_Source; - break; - default: - break; - } - spanData.setup(qwsServer->backgroundBrush(), 256, QPainter::CompositionMode_Source); - spanData.dx = off.x(); - spanData.dy = off.y(); - } else if (!surface->isBuffered()) { - return; - } else { - const QImage &img = surface->image(); - QPoint winoff = off - win->requestedRegion().boundingRect().topLeft(); - // convert win->opacity() from scale [0..255] to [0..256] - int const_alpha = win->opacity(); - const_alpha += (const_alpha >> 7); - spanData.type = QSpanData::Texture; - spanData.initTexture(&img, const_alpha); - spanData.dx = winoff.x(); - spanData.dy = winoff.y(); - } - if (!spanData.blend) - return; - - if (surface) - surface->lock(); - const QVector<QRect> rects = blendRegion.rects(); - const int nspans = 256; - QT_FT_Span spans[nspans]; - for (int i = 0; i < rects.size(); ++i) { - int y = rects.at(i).y() - off.y(); - int ye = y + rects.at(i).height(); - int x = rects.at(i).x() - off.x(); - int len = rects.at(i).width(); - while (y < ye) { - int n = qMin(nspans, ye - y); - int i = 0; - while (i < n) { - spans[i].x = x; - spans[i].len = len; - spans[i].y = y + i; - spans[i].coverage = 255; - ++i; - } - spanData.blend(n, spans, &spanData); - y += n; - } - } - if (surface) - surface->unlock(); - } -} - -void QScreen::paintBackground(const QRegion &r) -{ - const QBrush &bg = qwsServer->backgroundBrush(); - Qt::BrushStyle bs = bg.style(); - if (bs == Qt::NoBrush || r.isEmpty()) - return; - - if (bs == Qt::SolidPattern) { - solidFill(bg.color(), r); - } else { - const QRect br = r.boundingRect(); - QImage img(br.size(), d_ptr->preferredImageFormat()); - QPoint off = br.topLeft(); - QRasterBuffer rb; - rb.prepare(&img); - QSpanData spanData; - spanData.init(&rb, 0); - spanData.setup(bg, 256, QPainter::CompositionMode_Source); - spanData.dx = off.x(); - spanData.dy = off.y(); - Q_ASSERT(spanData.blend); - - const QVector<QRect> rects = r.rects(); - const int nspans = 256; - QT_FT_Span spans[nspans]; - for (int i = 0; i < rects.size(); ++i) { - int y = rects.at(i).y() - off.y(); - int ye = y + rects.at(i).height(); - int x = rects.at(i).x() - off.x(); - int len = rects.at(i).width(); - while (y < ye) { - int n = qMin(nspans, ye - y); - int i = 0; - while (i < n) { - spans[i].x = x; - spans[i].len = len; - spans[i].y = y + i; - spans[i].coverage = 255; - ++i; - } - spanData.blend(n, spans, &spanData); - y += n; - } - } - blit(img, br.topLeft(), r); - } -} - -/*! - \fn virtual int QScreen::sharedRamSize(void *) - - \internal -*/ - -/*! - \fn QScreen::setDirty(const QRect& rectangle) - - Marks the given \a rectangle as dirty. - - Note that the default implementation does nothing; reimplement - this function to indicate that the given \a rectangle has been - altered. -*/ - -void QScreen::setDirty(const QRect&) -{ -} - -/*! - \fn QScreen::isTransformed() const - - Returns true if the screen is transformed (for instance, rotated - 90 degrees); otherwise returns false. - - \sa transformOrientation(), isInterlaced() -*/ - -bool QScreen::isTransformed() const -{ - return false; -} - -/*! - \fn QScreen::isInterlaced() const - - Returns true if the display is interlaced (i.e. is displaying - images progressively like a television screen); otherwise returns - false. - - If the display is interlaced, the drawing is altered to look - better. - - \sa isTransformed(), linestep() -*/ - -bool QScreen::isInterlaced() const -{ - return false;//qws_screen_is_interlaced;; -} - -/*! - \fn QScreen::mapToDevice(const QSize &size) const - - Maps the given \a size from the coordinate space used by the - application to the framebuffer coordinate system. Note that the - default implementation simply returns the given \a size as it is. - - Reimplement this function to use the given device's coordinate - system when mapping. - - \sa mapFromDevice() -*/ - -QSize QScreen::mapToDevice(const QSize &s) const -{ - return s; -} - -/*! - \fn QScreen::mapFromDevice(const QSize &size) const - - Maps the given \a size from the framebuffer coordinate system to - the coordinate space used by the application. Note that the - default implementation simply returns the given \a size as it is. - - Reimplement this function to use the given device's coordinate - system when mapping. - - \sa mapToDevice() -*/ - -QSize QScreen::mapFromDevice(const QSize &s) const -{ - return s; -} - -/*! - \fn QScreen::mapToDevice(const QPoint &point, const QSize &screenSize) const - \overload - - Maps the given \a point from the coordinate space used by the - application to the framebuffer coordinate system, passing the - device's \a screenSize as argument. Note that the default - implementation returns the given \a point as it is. -*/ - -QPoint QScreen::mapToDevice(const QPoint &p, const QSize &) const -{ - return p; -} - -/*! - \fn QScreen::mapFromDevice(const QPoint &point, const QSize &screenSize) const - \overload - - Maps the given \a point from the framebuffer coordinate system to - the coordinate space used by the application, passing the device's - \a screenSize as argument. Note that the default implementation - simply returns the given \a point as it is. -*/ - -QPoint QScreen::mapFromDevice(const QPoint &p, const QSize &) const -{ - return p; -} - -/*! - \fn QScreen::mapToDevice(const QRect &rectangle, const QSize &screenSize) const - \overload - - Maps the given \a rectangle from the coordinate space used by the - application to the framebuffer coordinate system, passing the - device's \a screenSize as argument. Note that the default - implementation returns the given \a rectangle as it is. -*/ - -QRect QScreen::mapToDevice(const QRect &r, const QSize &) const -{ - return r; -} - -/*! - \fn QScreen::mapFromDevice(const QRect &rectangle, const QSize &screenSize) const - \overload - - Maps the given \a rectangle from the framebuffer coordinate system to - the coordinate space used by the application, passing the device's - \a screenSize as argument. Note that the default implementation - simply returns the given \a rectangle as it is. -*/ - -QRect QScreen::mapFromDevice(const QRect &r, const QSize &) const -{ - return r; -} - -/*! - \fn QScreen::mapToDevice(const QImage &image) const - \overload - - Maps the given \a image from the coordinate space used by the - application to the framebuffer coordinate system. Note that the - default implementation returns the given \a image as it is. -*/ - -QImage QScreen::mapToDevice(const QImage &i) const -{ - return i; -} - -/*! - \fn QScreen::mapFromDevice(const QImage &image) const - \overload - - Maps the given \a image from the framebuffer coordinate system to - the coordinate space used by the application. Note that the - default implementation simply returns the given \a image as it is. -*/ - -QImage QScreen::mapFromDevice(const QImage &i) const -{ - return i; -} - -/*! - \fn QScreen::mapToDevice(const QRegion ®ion, const QSize &screenSize) const - \overload - - Maps the given \a region from the coordinate space used by the - application to the framebuffer coordinate system, passing the - device's \a screenSize as argument. Note that the default - implementation returns the given \a region as it is. -*/ - -QRegion QScreen::mapToDevice(const QRegion &r, const QSize &) const -{ - return r; -} - -/*! - \fn QScreen::mapFromDevice(const QRegion ®ion, const QSize &screenSize) const - \overload - - Maps the given \a region from the framebuffer coordinate system to - the coordinate space used by the application, passing the device's - \a screenSize as argument. Note that the default implementation - simply returns the given \a region as it is. -*/ - -QRegion QScreen::mapFromDevice(const QRegion &r, const QSize &) const -{ - return r; -} - -/*! - \fn QScreen::transformOrientation() const - - Returns the current rotation as an integer value. - - Note that the default implementation returns 0; reimplement this - function to override this value. - - \sa isTransformed() -*/ - -int QScreen::transformOrientation() const -{ - return 0; -} - -int QScreen::pixmapDepth() const -{ - return depth(); -} - -/*! - \internal -*/ -int QScreen::memoryNeeded(const QString&) -{ - return 0; -} - -/*! - \internal -*/ -void QScreen::haltUpdates() -{ -} - -/*! - \internal -*/ -void QScreen::resumeUpdates() -{ -} - -/*! - \fn QRegion QScreen::region() const - \since 4.2 - - Returns the region covered by this screen driver. - - \sa base(), screenSize() -*/ - -/*! - \internal -*/ -void QScreen::setOffset(const QPoint &p) -{ - d_ptr->offset = p; -} - -/*! - \since 4.2 - - Returns the logical offset of the screen, i.e., the offset between - (0,0) in screen coordinates and the application coordinate system. -*/ -QPoint QScreen::offset() const -{ - return d_ptr->offset; -} - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN -void QScreen::setFrameBufferLittleEndian(bool littleEndian) -{ - d_ptr->fb_is_littleEndian = littleEndian; -} - -bool QScreen::frameBufferLittleEndian() const -{ - return d_ptr->fb_is_littleEndian; -} -#endif - -/*! - \fn int QScreen::subScreenIndexAt(const QPoint &position) const - \since 4.2 - - Returns the index of the subscreen at the given \a position; - returns -1 if no screen is found. - - The index identifies the subscreen in the list of pointers - returned by the subScreens() function. - - \sa instance(), subScreens() -*/ -int QScreen::subScreenIndexAt(const QPoint &p) const -{ - const QList<QScreen*> screens = subScreens(); - const int n = screens.count(); - for (int i = 0; i < n; ++i) { - if (screens.at(i)->region().contains(p)) - return i; - } - - return -1; -} - -#if 0 -#ifdef QT_LOADABLE_MODULES -#include <dlfcn.h> - -// ### needs update after driver init changes - -static QScreen * qt_dodriver(char * driver,char * a,unsigned char * b) - -{ - char buf[200]; - strcpy(buf,"/etc/qws/drivers/"); - qstrcpy(buf+17,driver); - qDebug("Attempting driver %s",driver); - - void * handle; - handle=dlopen(buf,RTLD_LAZY); - if(handle==0) { - qFatal("Module load error"); - } - QScreen *(*qt_get_screen_func)(char *,unsigned char *); - qt_get_screen_func=dlsym(handle,"qt_get_screen"); - if(qt_get_screen_func==0) { - qFatal("Couldn't get symbol"); - } - QScreen * ret=qt_get_screen_func(a,b); - return ret; -} - -static QScreen * qt_do_entry(char * entry) -{ - unsigned char config[256]; - - FILE * f=fopen(entry,"r"); - if(!f) { - return 0; - } - - int r=fread(config,256,1,f); - if(r<1) - return 0; - - fclose(f); - - unsigned short vendorid=*((unsigned short int *)config); - unsigned short deviceid=*(((unsigned short int *)config)+1); - if(config[0xb]!=3) - return 0; - - if(vendorid==0x1002) { - if(deviceid==0x4c4d) { - qDebug("Compaq Armada/IBM Thinkpad's Mach64 card"); - return qt_dodriver("mach64.so",entry,config); - } else if(deviceid==0x4742) { - qDebug("Desktop Rage Pro Mach64 card"); - return qt_dodriver("mach64.so",entry,config); - } else { - qDebug("Unrecognised ATI card id %x",deviceid); - return 0; - } - } else { - qDebug("Unrecognised vendor"); - } - return 0; -} - -extern bool qws_accel; - -/// ** NOT SUPPPORTED ** - -QScreen * qt_probe_bus() -{ - if(!qws_accel) { - return qt_dodriver("unaccel.so",0,0); - } - - QT_DIR *dirptr = QT_OPENDIR("/proc/bus/pci"); - if(!dirptr) - return qt_dodriver("unaccel.so",0,0); - QT_DIR * dirptr2; - QT_DIRENT *cards; - - QT_DIRENT *busses = QT_READDIR(dirptr); - - while(busses) { - if(busses->d_name[0]!='.') { - char buf[100]; - strcpy(buf,"/proc/bus/pci/"); - qstrcpy(buf+14,busses->d_name); - int p=strlen(buf); - dirptr2 = QT_OPENDIR(buf); - if(dirptr2) { - cards = QT_READDIR(dirptr2); - while(cards) { - if(cards->d_name[0]!='.') { - buf[p]='/'; - qstrcpy(buf+p+1,cards->d_name); - QScreen * ret=qt_do_entry(buf); - if(ret) - return ret; - } - cards = QT_READDIR(dirptr2); - } - QT_CLOSEDIR(dirptr2); - } - } - busses = QT_READDIR(dirptr); - } - QT_CLOSEDIR(dirptr); - - return qt_dodriver("unaccel.so",0,0); -} - -#else - -char *qt_qws_hardcoded_slot = "/proc/bus/pci/01/00.0"; - -const unsigned char* qt_probe_bus() -{ - const char * slot; - slot=::getenv("QWS_CARD_SLOT"); - if(!slot) - slot=qt_qws_hardcoded_slot; - if (slot) { - static unsigned char config[256]; - FILE * f=fopen(slot,"r"); - if(!f) { - qDebug("Open failure for %s",slot); - slot=0; - } else { - int r=fread((char*)config,256,1,f); - fclose(f); - if(r<1) { - qDebug("Read failure"); - return 0; - } else { - return config; - } - } - } - return 0; -} - -#endif - -#endif // 0 - -/*! - \internal - \since 4.4 -*/ -void QScreen::setPixmapDataFactory(QPixmapDataFactory *factory) -{ - static bool shownWarning = false; - if (!shownWarning) { - qWarning("QScreen::setPixmapDataFactory() is deprecated - use setGraphicsSystem() instead"); - shownWarning = true; - } - - d_ptr->pixmapFactory = factory; -} - -/*! - \internal - \since 4.4 -*/ -QPixmapDataFactory* QScreen::pixmapDataFactory() const -{ - return d_ptr->pixmapFactory; -} - -/*! - \internal - \since 4.5 -*/ -void QScreen::setGraphicsSystem(QGraphicsSystem* system) -{ - d_ptr->graphicsSystem = system; -} - -/*! - \internal - \since 4.5 -*/ -QGraphicsSystem* QScreen::graphicsSystem() const -{ - return d_ptr->graphicsSystem; -} - -/*! - \since 4.4 - - Returns the class identifier for the screen object. -*/ -QScreen::ClassId QScreen::classId() const -{ - return static_cast<ClassId>(d_ptr->classId); -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qscreen_qws.h b/src/gui/embedded/qscreen_qws.h deleted file mode 100644 index 85c775e377..0000000000 --- a/src/gui/embedded/qscreen_qws.h +++ /dev/null @@ -1,391 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREEN_QWS_H -#define QSCREEN_QWS_H - -#include <QtCore/qnamespace.h> -#include <QtCore/qpoint.h> -#include <QtCore/qlist.h> -#include <QtGui/qrgb.h> -#include <QtCore/qrect.h> -#include <QtGui/qimage.h> -#include <QtGui/qregion.h> - -struct fb_cmap; - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QScreenCursor; -class QBrush; -class QWSWindow; -class QWSWindowSurface; -class QGraphicsSystem; -class QPixmapData; - -#ifndef QT_QWS_DEPTH16_RGB -#define QT_QWS_DEPTH16_RGB 565 -#endif -static const int qt_rbits = (QT_QWS_DEPTH16_RGB/100); -static const int qt_gbits = (QT_QWS_DEPTH16_RGB/10%10); -static const int qt_bbits = (QT_QWS_DEPTH16_RGB%10); -static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits); -static const int qt_green_shift = qt_bbits-(8-qt_gbits); -static const int qt_neg_blue_shift = 8-qt_bbits; -static const int qt_blue_mask = (1<<qt_bbits)-1; -static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-(1<<qt_bbits); -static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits)); - -static const int qt_red_rounding_shift = qt_red_shift + qt_rbits; -static const int qt_green_rounding_shift = qt_green_shift + qt_gbits; -static const int qt_blue_rounding_shift = qt_bbits - qt_neg_blue_shift; - - -inline ushort qt_convRgbTo16(const int r, const int g, const int b) -{ - const int tr = r << qt_red_shift; - const int tg = g << qt_green_shift; - const int tb = b >> qt_neg_blue_shift; - - return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); -} - -inline ushort qt_convRgbTo16(QRgb c) -{ - const int tr = qRed(c) << qt_red_shift; - const int tg = qGreen(c) << qt_green_shift; - const int tb = qBlue(c) >> qt_neg_blue_shift; - - return (tb & qt_blue_mask) | (tg & qt_green_mask) | (tr & qt_red_mask); -} - -inline QRgb qt_conv16ToRgb(ushort c) -{ - const int r=(c & qt_red_mask); - const int g=(c & qt_green_mask); - const int b=(c & qt_blue_mask); - const int tr = r >> qt_red_shift | r >> qt_red_rounding_shift; - const int tg = g >> qt_green_shift | g >> qt_green_rounding_shift; - const int tb = b << qt_neg_blue_shift | b >> qt_blue_rounding_shift; - - return qRgb(tr,tg,tb); -} - -inline void qt_conv16ToRgb(ushort c, int& r, int& g, int& b) -{ - const int tr=(c & qt_red_mask); - const int tg=(c & qt_green_mask); - const int tb=(c & qt_blue_mask); - r = tr >> qt_red_shift | tr >> qt_red_rounding_shift; - g = tg >> qt_green_shift | tg >> qt_green_rounding_shift; - b = tb << qt_neg_blue_shift | tb >> qt_blue_rounding_shift; -} - -const int SourceSolid=0; -const int SourcePixmap=1; - -#ifndef QT_NO_QWS_CURSOR - -class QScreenCursor; -extern QScreenCursor *qt_screencursor; -extern bool qws_sw_cursor; - -class Q_GUI_EXPORT QScreenCursor -{ -public: - QScreenCursor(); - virtual ~QScreenCursor(); - - virtual void set(const QImage &image, int hotx, int hoty); - virtual void move(int x, int y); - virtual void show(); - virtual void hide(); - - bool supportsAlphaCursor() const { return supportsAlpha; } - - static bool enabled() { return qws_sw_cursor; } - - QRect boundingRect() const { return QRect(pos - hotspot, size); } - QImage image() const { return cursor; } - bool isVisible() const { return enable; } - bool isAccelerated() const { return hwaccel; } - - static void initSoftwareCursor(); - static QScreenCursor* instance() { return qt_screencursor; } - -protected: - QImage cursor; - - QSize size; - QPoint pos; - QPoint hotspot; - uint enable : 1; - uint hwaccel : 1; - uint supportsAlpha : 1; - -private: - friend class QProxyScreenCursor; -}; - -#endif // QT_NO_QWS_CURSOR - -// A (used) chunk of offscreen memory - -class QPoolEntry -{ -public: - unsigned int start; - unsigned int end; - int clientId; -}; - -class QScreen; -class QScreenPrivate; -class QPixmapDataFactory; - -extern Q_GUI_EXPORT QScreen *qt_screen; -typedef void(*ClearCacheFunc)(QScreen *obj, int); - -class Q_GUI_EXPORT QScreen { - -public: - enum ClassId { LinuxFBClass, TransformedClass, VNCClass, MultiClass, - VFbClass, DirectFBClass, SvgalibClass, ProxyClass, - GLClass, IntfbClass, CustomClass = 1024 }; - - QScreen(int display_id, ClassId classId); - explicit QScreen(int display_id); - virtual ~QScreen(); - static QScreen* instance() { return qt_screen; } - virtual bool initDevice() = 0; - virtual bool connect(const QString &displaySpec) = 0; - virtual void disconnect() = 0; - virtual void shutdownDevice(); - virtual void setMode(int,int,int) = 0; - virtual bool supportsDepth(int) const; - - virtual void save(); - virtual void restore(); - virtual void blank(bool on); - - virtual int pixmapOffsetAlignment() { return 64; } - virtual int pixmapLinestepAlignment() { return 64; } - virtual int sharedRamSize(void *) { return 0; } - - virtual bool onCard(const unsigned char *) const; - virtual bool onCard(const unsigned char *, ulong& out_offset) const; - - enum PixelType { NormalPixel, BGRPixel }; - - // sets a single color in the colormap - virtual void set(unsigned int,unsigned int,unsigned int,unsigned int); - // allocates a color - virtual int alloc(unsigned int,unsigned int,unsigned int); - - int width() const { return w; } - int height() const { return h; } - int depth() const { return d; } - virtual int pixmapDepth() const; - PixelType pixelType() const { return pixeltype; } - int linestep() const { return lstep; } - int deviceWidth() const { return dw; } - int deviceHeight() const { return dh; } - uchar * base() const { return data; } - // Ask for memory from card cache with alignment - virtual uchar * cache(int) { return 0; } - virtual void uncache(uchar *) {} - - QImage::Format pixelFormat() const; - - int screenSize() const { return size; } - int totalSize() const { return mapsize; } - - QRgb * clut() { return screenclut; } -#ifdef QT_DEPRECATED - QT_DEPRECATED int numCols() { return screencols; } -#endif - int colorCount() { return screencols; } - - virtual QSize mapToDevice(const QSize &) const; - virtual QSize mapFromDevice(const QSize &) const; - virtual QPoint mapToDevice(const QPoint &, const QSize &) const; - virtual QPoint mapFromDevice(const QPoint &, const QSize &) const; - virtual QRect mapToDevice(const QRect &, const QSize &) const; - virtual QRect mapFromDevice(const QRect &, const QSize &) const; - virtual QImage mapToDevice(const QImage &) const; - virtual QImage mapFromDevice(const QImage &) const; - virtual QRegion mapToDevice(const QRegion &, const QSize &) const; - virtual QRegion mapFromDevice(const QRegion &, const QSize &) const; - virtual int transformOrientation() const; - virtual bool isTransformed() const; - virtual bool isInterlaced() const; - - virtual void setDirty(const QRect&); - - virtual int memoryNeeded(const QString&); - - virtual void haltUpdates(); - virtual void resumeUpdates(); - - // composition manager methods - virtual void exposeRegion(QRegion r, int changing); - - // these work directly on the screen - virtual void blit(const QImage &img, const QPoint &topLeft, const QRegion ®ion); - virtual void solidFill(const QColor &color, const QRegion ®ion); - void blit(QWSWindow *bs, const QRegion &clip); - - virtual QWSWindowSurface* createSurface(QWidget *widget) const; - virtual QWSWindowSurface* createSurface(const QString &key) const; - - virtual QList<QScreen*> subScreens() const { return QList<QScreen*>(); } - virtual QRegion region() const { return QRect(offset(), QSize(w, h)); } - int subScreenIndexAt(const QPoint &p) const; - - void setOffset(const QPoint &p); - QPoint offset() const; - - int physicalWidth() const { return physWidth; } // physical display size in mm - int physicalHeight() const { return physHeight; } // physical display size in mm - - QPixmapDataFactory* pixmapDataFactory() const; // Deprecated, will be removed in 4.6 - QGraphicsSystem* graphicsSystem() const; - -#ifdef QT_QWS_CLIENTBLIT - bool supportsBlitInClients() const; - void setSupportsBlitInClients(bool); -#endif - - ClassId classId() const; - -protected: - void setPixelFormat(QImage::Format format); - void setPixmapDataFactory(QPixmapDataFactory *factory); // Deprecated, will be removed in 4.6 - void setGraphicsSystem(QGraphicsSystem* system); - - QRgb screenclut[256]; - int screencols; - - uchar * data; - - // Table of allocated lumps, kept in sorted highest-to-lowest order - // The table itself is allocated at the bottom of offscreen memory - // i.e. it's similar to having a stack (the table) and a heap - // (the allocated blocks). Freed space is implicitly described - // by the gaps between the allocated lumps (this saves entries and - // means we don't need to worry about coalescing freed lumps) - - QPoolEntry * entries; - int * entryp; - unsigned int * lowest; - - int w; - int lstep; - int h; - int d; - PixelType pixeltype; - bool grayscale; - - int dw; - int dh; - - int size; // Screen size - int mapsize; // Total mapped memory - - int displayId; - - int physWidth; - int physHeight; - - friend class QWSServer; - friend class QWSServerPrivate; - static ClearCacheFunc clearCacheFunc; - -private: - void compose(int level, const QRegion &exposed, QRegion &blend, - QImage **blendbuffer, int changing_level); - void paintBackground(const QRegion &); - - friend class QWSOnScreenSurface; - static bool isWidgetPaintOnScreen(const QWidget *w); - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - void setFrameBufferLittleEndian(bool littleEndian); - bool frameBufferLittleEndian() const; - friend class QVNCScreen; - friend class QLinuxFbScreen; - friend class QVFbScreen; - friend class QProxyScreen; - friend class QIntfbScreen; -#endif - friend void qt_solidFill_setup(QScreen*, const QColor&, const QRegion&); - friend void qt_blit_setup(QScreen *screen, const QImage &image, - const QPoint &topLeft, const QRegion ®ion); -#ifdef QT_QWS_DEPTH_GENERIC - friend void qt_set_generic_blit(QScreen *screen, int bpp, - int len_red, int len_green, int len_blue, - int len_alpha, int off_red, int off_green, - int off_blue, int off_alpha); -#endif - - QScreenPrivate *d_ptr; -}; - -// This lives in loadable modules - -#ifndef QT_LOADABLE_MODULES -extern "C" QScreen * qt_get_screen(int display_id, const char* spec); -#endif - -// This is in main lib, loads the right module, calls qt_get_screen -// In non-loadable cases just aliases to qt_get_screen - -const unsigned char * qt_probe_bus(); - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREEN_QWS_H diff --git a/src/gui/embedded/qscreendriverfactory_qws.cpp b/src/gui/embedded/qscreendriverfactory_qws.cpp deleted file mode 100644 index ea194e56c5..0000000000 --- a/src/gui/embedded/qscreendriverfactory_qws.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreendriverfactory_qws.h" - -#include "qscreen_qws.h" -#include "qapplication.h" -#include "qscreenlinuxfb_qws.h" -#include "qscreentransformed_qws.h" -#include "qscreenvfb_qws.h" -#include "qscreenmulti_qws_p.h" -#include "qscreenqnx_qws.h" -#include "qscreenintegrityfb_qws.h" -#include <stdlib.h> -#include "private/qfactoryloader_p.h" -#include "qscreendriverplugin_qws.h" -#ifndef QT_NO_QWS_DIRECTFB -#include "qdirectfbscreen.h" -#endif -#ifndef QT_NO_QWS_VNC -#include "qscreenvnc_qws.h" -#endif - -QT_BEGIN_NAMESPACE - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QScreenDriverFactoryInterface_iid, - QLatin1String("/gfxdrivers"), Qt::CaseInsensitive)) - -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - -/*! - \class QScreenDriverFactory - \ingroup qws - - \brief The QScreenDriverFactory class creates screen drivers in - Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - QScreenDriverFactory is used to detect and instantiate the - available screen drivers, allowing \l{Qt for Embedded Linux} to load the - preferred driver into the server application at runtime. The - create() function returns a QScreen object representing the screen - driver identified by a given key. The valid keys (i.e. the - supported drivers) can be retrieved using the keys() function. - - - \l{Qt for Embedded Linux} provides several built-in screen drivers. In - addition, custom screen drivers can be added using Qt's plugin - mechanism, i.e. by subclassing the QScreen class and creating a - screen driver plugin (QScreenDriverPlugin). See the - \l{Qt for Embedded Linux Display Management}{display management} - documentation for details. - - \sa QScreen, QScreenDriverPlugin -*/ - -/*! - Creates the screen driver specified by the given \a key, using the - display specified by the given \a displayId. - - Note that the keys are case-insensitive. - - \sa keys() -*/ -QScreen *QScreenDriverFactory::create(const QString& key, int displayId) -{ - QString driver = key.toLower(); -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_QNX) - if (driver == QLatin1String("qnx") || driver.isEmpty()) - return new QQnxScreen(displayId); -#endif -#if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_INTEGRITY) - if (driver == QLatin1String("integrityfb") || driver.isEmpty()) - return new QIntfbScreen(displayId); -#endif -#ifndef QT_NO_QWS_QVFB - if (driver == QLatin1String("qvfb") || driver.isEmpty()) - return new QVFbScreen(displayId); -#endif -#ifndef QT_NO_QWS_LINUXFB - if (driver == QLatin1String("linuxfb") || driver.isEmpty()) - return new QLinuxFbScreen(displayId); -#endif -#ifndef QT_NO_QWS_DIRECTFB - if (driver == QLatin1String("directfb") || driver.isEmpty()) - return new QDirectFBScreen(displayId); -#endif -#ifndef QT_NO_QWS_TRANSFORMED - if (driver == QLatin1String("transformed")) - return new QTransformedScreen(displayId); -#endif -#ifndef QT_NO_QWS_VNC - if (driver == QLatin1String("vnc")) - return new QVNCScreen(displayId); -#endif -#ifndef QT_NO_QWS_MULTISCREEN - if (driver == QLatin1String("multi")) - return new QMultiScreen(displayId); -#endif -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - - if (QScreenDriverFactoryInterface *factory = qobject_cast<QScreenDriverFactoryInterface*>(loader()->instance(key))) - return factory->create(driver, displayId); - -#endif -#endif - return 0; -} - -/*! - Returns the list of valid keys, i.e. the available screen drivers. - - \sa create() -*/ -QStringList QScreenDriverFactory::keys() -{ - QStringList list; - -#if defined(Q_OS_QNX) && !defined(QT_NO_QWS_QNX) - list << QLatin1String("QNX"); -#endif -#if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_INTEGRITY) - list << QLatin1String("INTEGRITYFB"); -#endif -#ifndef QT_NO_QWS_QVFB - list << QLatin1String("QVFb"); -#endif -#ifndef QT_NO_QWS_LINUXFB - list << QLatin1String("LinuxFb"); -#endif -#ifndef QT_NO_QWS_TRANSFORMED - list << QLatin1String("Transformed"); -#endif -#ifndef QT_NO_QWS_VNC - list << QLatin1String("VNC"); -#endif -#ifndef QT_NO_QWS_MULTISCREEN - list << QLatin1String("Multi"); -#endif - -#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) -#ifndef QT_NO_LIBRARY - QStringList plugins = loader()->keys(); - for (int i = 0; i < plugins.size(); ++i) { -# ifdef QT_NO_QWS_QVFB - // give QVFb top priority for autodetection - if (plugins.at(i) == QLatin1String("QVFb")) - list.prepend(plugins.at(i)); - else -# endif - if (!list.contains(plugins.at(i))) - list += plugins.at(i); - } -#endif //QT_NO_LIBRARY -#endif //QT_MAKEDLL - return list; -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qscreendriverfactory_qws.h b/src/gui/embedded/qscreendriverfactory_qws.h deleted file mode 100644 index 072ae9bad8..0000000000 --- a/src/gui/embedded/qscreendriverfactory_qws.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENDRIVERFACTORY_QWS_H -#define QSCREENDRIVERFACTORY_QWS_H - -#include <QtCore/qstringlist.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QString; -class QScreen; - -class Q_GUI_EXPORT QScreenDriverFactory -{ -public: - static QStringList keys(); - static QScreen *create(const QString&, int); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENDRIVERFACTORY_QWS_H diff --git a/src/gui/embedded/qscreendriverplugin_qws.cpp b/src/gui/embedded/qscreendriverplugin_qws.cpp deleted file mode 100644 index d7822c8ffc..0000000000 --- a/src/gui/embedded/qscreendriverplugin_qws.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreendriverplugin_qws.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_LIBRARY - -/*! - \class QScreenDriverPlugin - \ingroup plugins - \ingroup qws - - \brief The QScreenDriverPlugin class is an abstract base class for - screen driver plugins in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - \l{Qt for Embedded Linux} provides ready-made drivers for several screen - protocols, see the \l{Qt for Embedded Linux Display Management}{display - management} documentation for details. Custom screen drivers can be - implemented by subclassing the QScreen class and creating a screen - driver plugin. - - A screen driver plugin can be created by subclassing - QScreenDriverPlugin and reimplementing the pure virtual keys() and - create() functions. By exporting the derived class using the - Q_EXPORT_PLUGIN2() macro, The default implementation of the - QScreenDriverFactory class will automatically detect the plugin - and load the driver into the server application at run-time. See - \l{How to Create Qt Plugins} for details. - - \sa QScreen, QScreenDriverFactory -*/ - -/*! - \fn QStringList QScreenDriverPlugin::keys() const - - Implement this function to return the list of valid keys, i.e. the - screen drivers supported by this plugin. - - \l{Qt for Embedded Linux} provides ready-made drivers for several screen - protocols, see the \l{Qt for Embedded Linux Display Management}{display - management} documentation for details. - - \sa create() -*/ - -/*! - Constructs a screen driver plugin with the given \a parent. - - Note that this constructor is invoked automatically by the - Q_EXPORT_PLUGIN2() macro, so there is no need for calling it - explicitly. -*/ -QScreenDriverPlugin::QScreenDriverPlugin(QObject *parent) - : QObject(parent) -{ -} - -/*! - Destroys this screen driver plugin. - - Note that Qt destroys a plugin automatically when it is no longer - used, so there is no need for calling the destructor explicitly. -*/ -QScreenDriverPlugin::~QScreenDriverPlugin() -{ -} - - -/*! - \fn QScreen* QScreenDriverPlugin::create(const QString &key, int displayId) - - Implement this function to create a driver matching the type - specified by the given \a key and \a displayId parameters. Note - that keys are case-insensitive. - - \sa keys() -*/ - -#endif // QT_NO_LIBRARY - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qscreendriverplugin_qws.h b/src/gui/embedded/qscreendriverplugin_qws.h deleted file mode 100644 index 039a8aabf1..0000000000 --- a/src/gui/embedded/qscreendriverplugin_qws.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENDRIVERPLUGIN_QWS_H -#define QSCREENDRIVERPLUGIN_QWS_H - -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_LIBRARY - -class QScreen; - -struct Q_GUI_EXPORT QScreenDriverFactoryInterface : public QFactoryInterface -{ - virtual QScreen* create(const QString& driver, int displayId) = 0; -}; - -#define QScreenDriverFactoryInterface_iid "com.trolltech.Qt.QScreenDriverFactoryInterface" -Q_DECLARE_INTERFACE(QScreenDriverFactoryInterface, QScreenDriverFactoryInterface_iid) - -class Q_GUI_EXPORT QScreenDriverPlugin : public QObject, public QScreenDriverFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QScreenDriverFactoryInterface:QFactoryInterface) -public: - explicit QScreenDriverPlugin(QObject *parent = 0); - ~QScreenDriverPlugin(); - - virtual QStringList keys() const = 0; - virtual QScreen *create(const QString& driver, int displayId) = 0; -}; - -#endif // QT_NO_LIBRARY - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENDRIVERPLUGIN_QWS_H diff --git a/src/gui/embedded/qscreenintegrityfb_qws.cpp b/src/gui/embedded/qscreenintegrityfb_qws.cpp deleted file mode 100644 index 7b24490353..0000000000 --- a/src/gui/embedded/qscreenintegrityfb_qws.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_QWS_INTEGRITYFB - -#include <qscreenintegrityfb_qws.h> -#include <qwindowsystem_qws.h> -#include <qsocketnotifier.h> -#include <qapplication.h> -#include <qscreen_qws.h> -#include "qmouseintegrity_qws.h" -#include "qkbdintegrity_qws.h" -#include <qmousedriverfactory_qws.h> -#include <qkbddriverfactory_qws.h> -#include <qdebug.h> - -#include <INTEGRITY.h> -#include <device/fbdriver.h> - -QT_BEGIN_NAMESPACE - -class QIntfbScreenPrivate -{ -public: - QIntfbScreenPrivate(); - ~QIntfbScreenPrivate(); - - FBHandle handle; - struct FBInfoStruct fbinfo; - - QWSMouseHandler *mouse; -#ifndef QT_NO_QWS_KEYBOARD - QWSKeyboardHandler *keyboard; -#endif -}; - -QIntfbScreenPrivate::QIntfbScreenPrivate() - : mouse(0) - -{ -#ifndef QT_NO_QWS_KEYBOARD - keyboard = 0; -#endif -} - -QIntfbScreenPrivate::~QIntfbScreenPrivate() -{ - delete mouse; -#ifndef QT_NO_QWS_KEYBOARD - delete keyboard; -#endif -} - -/*! - \internal - - \class QIntfbScreen - \ingroup qws - - \brief The QIntfbScreen class implements a screen driver for the - INTEGRITY framebuffer drivers. - - Note that this class is only available in \l{Qt for INTEGRITY}. - Custom screen drivers can be added by subclassing the - QScreenDriverPlugin class, using the QScreenDriverFactory class to - dynamically load the driver into the application, but there should - only be one screen object per application. - - \sa QScreen, QScreenDriverPlugin, {Running Applications} -*/ - -/*! - \fn bool QIntfbScreen::connect(const QString & displaySpec) - \reimp -*/ - -/*! - \fn void QIntfbScreen::disconnect() - \reimp -*/ - -/*! - \fn bool QIntfbScreen::initDevice() - \reimp -*/ - -/*! - \fn void QIntfbScreen::restore() - \reimp -*/ - -/*! - \fn void QIntfbScreen::save() - \reimp -*/ - -/*! - \fn void QIntfbScreen::setDirty(const QRect & r) - \reimp -*/ - -/*! - \fn void QIntfbScreen::setMode(int nw, int nh, int nd) - \reimp -*/ - -/*! - \fn void QIntfbScreen::shutdownDevice() - \reimp -*/ - -/*! - \fn QIntfbScreen::QIntfbScreen(int displayId) - - Constructs a QVNCScreen object. The \a displayId argument - identifies the Qt for Embedded Linux server to connect to. -*/ -QIntfbScreen::QIntfbScreen(int display_id) - : QScreen(display_id, IntfbClass), d_ptr(new QIntfbScreenPrivate) -{ - d_ptr->handle = 0; - data = 0; -} - -/*! - Destroys this QIntfbScreen object. -*/ -QIntfbScreen::~QIntfbScreen() -{ - delete d_ptr; -} - -static QIntfbScreen *connected = 0; - -bool QIntfbScreen::connect(const QString &displaySpec) -{ - FBDriver *fbdev; - - CheckSuccess(gh_FB_get_driver(0, &fbdev)); - CheckSuccess(gh_FB_init_device(fbdev, 0, &d_ptr->handle)); - CheckSuccess(gh_FB_get_info(d_ptr->handle, &d_ptr->fbinfo)); - - data = (uchar *)d_ptr->fbinfo.start; - - d = d_ptr->fbinfo.bitsperpixel; - switch (d) { - case 1: - setPixelFormat(QImage::Format_Mono); - break; - case 8: - setPixelFormat(QImage::Format_Indexed8); - break; - case 12: - setPixelFormat(QImage::Format_RGB444); - break; - case 15: - setPixelFormat(QImage::Format_RGB555); - break; - case 16: - setPixelFormat(QImage::Format_RGB16); - break; - case 18: - setPixelFormat(QImage::Format_RGB666); - break; - case 24: - setPixelFormat(QImage::Format_RGB888); -#ifdef QT_QWS_DEPTH_GENERIC -#if Q_BYTE_ORDER != Q_BIG_ENDIAN - qt_set_generic_blit(this, 24, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - d_ptr->fbinfo.redoffset, - d_ptr->fbinfo.greenoffset, - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset); -#else - qt_set_generic_blit(this, 24, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - 16 - d_ptr->fbinfo.redoffset, - 16 - d_ptr->fbinfo.greenoffset, - 16 - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset); -#endif -#endif - break; - case 32: - setPixelFormat(QImage::Format_ARGB32_Premultiplied); -#ifdef QT_QWS_DEPTH_GENERIC -#if Q_BYTE_ORDER != Q_BIG_ENDIAN - qt_set_generic_blit(this, 32, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - d_ptr->fbinfo.redoffset, - d_ptr->fbinfo.greenoffset, - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset); -#else - qt_set_generic_blit(this, 32, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - 24 - d_ptr->fbinfo.redoffset, - 24 - d_ptr->fbinfo.greenoffset, - 24 - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset ? 24 - d_ptr->fbinfo.alphaoffset : 0); -#endif -#endif - break; - } - - dw = w = d_ptr->fbinfo.width; - dh = h = d_ptr->fbinfo.height; - - /* assumes no padding */ - lstep = w * ((d + 7) >> 3); - - mapsize = size = h * lstep; - - /* default values */ - int dpi = 72; - physWidth = qRound(dw * 25.4 / dpi); - physHeight = qRound(dh * 25.4 / dpi); - - qDebug("Connected to INTEGRITYfb server: %d x %d x %d %dx%dmm (%dx%ddpi)", - w, h, d, physWidth, physHeight, qRound(dw*25.4/physWidth), qRound(dh*25.4/physHeight) ); - - - QWSServer::setDefaultMouse("integrity"); - QWSServer::setDefaultKeyboard("integrity"); - - connected = this; - - return true; -} - -void QIntfbScreen::disconnect() -{ - connected = 0; -} - -bool QIntfbScreen::initDevice() -{ - - CheckSuccess(gh_FB_set_info(d_ptr->handle, &d_ptr->fbinfo, false)); - CheckSuccess(gh_FB_get_info(d_ptr->handle, &d_ptr->fbinfo)); - data = (uchar *)d_ptr->fbinfo.start; - d = d_ptr->fbinfo.bitsperpixel; - dw = w = d_ptr->fbinfo.width; - dh = h = d_ptr->fbinfo.height; - mapsize = d_ptr->fbinfo.length; - /* assumes no padding */ - lstep = w * ((d + 7) >> 3); - - mapsize = size = h * lstep; - - data = (uchar *)d_ptr->fbinfo.start; - - d = d_ptr->fbinfo.bitsperpixel; - switch (d) { - case 1: - setPixelFormat(QImage::Format_Mono); - break; - case 8: - setPixelFormat(QImage::Format_Indexed8); - break; - case 12: - setPixelFormat(QImage::Format_RGB444); - break; - case 15: - setPixelFormat(QImage::Format_RGB555); - break; - case 16: - setPixelFormat(QImage::Format_RGB16); - break; - case 18: - setPixelFormat(QImage::Format_RGB666); - break; - case 24: - setPixelFormat(QImage::Format_RGB888); - break; - case 32: - setPixelFormat(QImage::Format_ARGB32_Premultiplied); - break; - } -#ifdef QT_QWS_DEPTH_GENERIC -#if defined(__BIG_ENDIAN__) - qt_set_generic_blit(this, d, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - 24 - d_ptr->fbinfo.redoffset, - 24 - d_ptr->fbinfo.greenoffset, - 24 - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset ? 24 - d_ptr->fbinfo.alphaoffset : 0); -#else - qt_set_generic_blit(this, d, - d_ptr->fbinfo.redbits, - d_ptr->fbinfo.greenbits, - d_ptr->fbinfo.bluebits, - d_ptr->fbinfo.alphabits, - d_ptr->fbinfo.redoffset, - d_ptr->fbinfo.greenoffset, - d_ptr->fbinfo.blueoffset, - d_ptr->fbinfo.alphaoffset); -#endif -#endif - -#ifndef QT_NO_QWS_CURSOR - QScreenCursor::initSoftwareCursor(); -#endif - return true; -} - -void QIntfbScreen::shutdownDevice() -{ - gh_FB_close(d_ptr->handle); -} - -void QIntfbScreen::setMode(int ,int ,int) -{ -} - -// save the state of the graphics card -// This is needed so that e.g. we can restore the palette when switching -// between linux virtual consoles. -void QIntfbScreen::save() -{ - // nothing to do. -} - -// restore the state of the graphics card. -void QIntfbScreen::restore() -{ -} -void QIntfbScreen::setDirty(const QRect& rect) -{ - FBRect fbrect; - fbrect.dx = rect.x(); - fbrect.dy = rect.y(); - fbrect.width = rect.width(); - fbrect.height = rect.height(); - gh_FB_expose(d_ptr->handle, &fbrect); -} - -void QIntfbScreen::setBrightness(int b) -{ - if (connected) { - } -} - -void QIntfbScreen::blank(bool on) -{ -} - -#endif // QT_NO_QWS_INTEGRITYFB - -QT_END_NAMESPACE - diff --git a/src/gui/embedded/qscreenintegrityfb_qws.h b/src/gui/embedded/qscreenintegrityfb_qws.h deleted file mode 100644 index 06b39671f4..0000000000 --- a/src/gui/embedded/qscreenintegrityfb_qws.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENINTEGRITYFB_QWS_H -#define QSCREENINTEGRITYFB_QWS_H - -#include <QtGui/qscreen_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_INTEGRITYFB - -class QIntfbScreenPrivate; - -class Q_GUI_EXPORT QIntfbScreen : public QScreen -{ -public: - explicit QIntfbScreen(int display_id); - virtual ~QIntfbScreen(); - virtual bool initDevice(); - virtual bool connect(const QString &displaySpec); - virtual void disconnect(); - virtual void shutdownDevice(); - virtual void save(); - virtual void restore(); - virtual void setMode(int nw,int nh,int nd); - virtual void setDirty(const QRect& r); - virtual void blank(bool); - static void setBrightness(int b); - -private: - QIntfbScreenPrivate *d_ptr; -}; - -#endif // QT_NO_QWS_INTEGRITYFB - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENINTEGRITYFB_QWS_H diff --git a/src/gui/embedded/qscreenlinuxfb_qws.cpp b/src/gui/embedded/qscreenlinuxfb_qws.cpp deleted file mode 100644 index a566f5294c..0000000000 --- a/src/gui/embedded/qscreenlinuxfb_qws.cpp +++ /dev/null @@ -1,1386 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreenlinuxfb_qws.h" - -#ifndef QT_NO_QWS_LINUXFB -//#include "qmemorymanager_qws.h" -#include "qwsdisplay_qws.h" -#include "qpixmap.h" -#include <private/qwssignalhandler_p.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <unistd.h> -#include <stdlib.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <sys/kd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdio.h> -#include <limits.h> -#include <signal.h> - -#include "qwindowsystem_qws.h" - -#if !defined(Q_OS_DARWIN) && !defined(Q_OS_FREEBSD) -#include <linux/fb.h> - -#ifdef __i386__ -#include <asm/mtrr.h> -#endif -#endif - -QT_BEGIN_NAMESPACE - -extern int qws_client_id; - -//#define DEBUG_CACHE - -class QLinuxFbScreenPrivate : public QObject -{ -public: - QLinuxFbScreenPrivate(); - ~QLinuxFbScreenPrivate(); - - void openTty(); - void closeTty(); - - int fd; - int startupw; - int startuph; - int startupd; - bool blank; - QLinuxFbScreen::DriverTypes driverType; - - bool doGraphicsMode; -#ifdef QT_QWS_DEPTH_GENERIC - bool doGenericColors; -#endif - int ttyfd; - long oldKdMode; - QString ttyDevice; - QString displaySpec; -}; - -QLinuxFbScreenPrivate::QLinuxFbScreenPrivate() - : fd(-1), blank(true), doGraphicsMode(true), -#ifdef QT_QWS_DEPTH_GENERIC - doGenericColors(false), -#endif - ttyfd(-1), oldKdMode(KD_TEXT) -{ - QWSSignalHandler::instance()->addObject(this); -} - -QLinuxFbScreenPrivate::~QLinuxFbScreenPrivate() -{ - closeTty(); -} - -void QLinuxFbScreenPrivate::openTty() -{ - const char *const devs[] = {"/dev/tty0", "/dev/tty", "/dev/console", 0}; - - if (ttyDevice.isEmpty()) { - for (const char * const *dev = devs; *dev; ++dev) { - ttyfd = QT_OPEN(*dev, O_RDWR); - if (ttyfd != -1) - break; - } - } else { - ttyfd = QT_OPEN(ttyDevice.toAscii().constData(), O_RDWR); - } - - if (ttyfd == -1) - return; - - if (doGraphicsMode) { - ioctl(ttyfd, KDGETMODE, &oldKdMode); - if (oldKdMode != KD_GRAPHICS) { - int ret = ioctl(ttyfd, KDSETMODE, KD_GRAPHICS); - if (ret == -1) - doGraphicsMode = false; - } - } - - // No blankin' screen, no blinkin' cursor!, no cursor! - const char termctl[] = "\033[9;0]\033[?33l\033[?25l\033[?1c"; - QT_WRITE(ttyfd, termctl, sizeof(termctl)); -} - -void QLinuxFbScreenPrivate::closeTty() -{ - if (ttyfd == -1) - return; - - if (doGraphicsMode) - ioctl(ttyfd, KDSETMODE, oldKdMode); - - // Blankin' screen, blinkin' cursor! - const char termctl[] = "\033[9;15]\033[?33h\033[?25h\033[?0c"; - QT_WRITE(ttyfd, termctl, sizeof(termctl)); - - QT_CLOSE(ttyfd); - ttyfd = -1; -} - -/*! - \enum QLinuxFbScreen::DriverTypes - - This enum describes the driver type. - - \value GenericDriver Generic Linux framebuffer driver - \value EInk8Track e-Ink framebuffer driver using the 8Track chipset - */ - -/*! - \fn QLinuxFbScreen::fixupScreenInfo(fb_fix_screeninfo &finfo, fb_var_screeninfo &vinfo) - - Adjust the values returned by the framebuffer driver, to work - around driver bugs or nonstandard behavior in certain drivers. - \a finfo and \a vinfo specify the fixed and variable screen info - returned by the driver. - */ -void QLinuxFbScreen::fixupScreenInfo(fb_fix_screeninfo &finfo, fb_var_screeninfo &vinfo) -{ - // 8Track e-ink devices (as found in Sony PRS-505) lie - // about their bit depth -- they claim they're 1 bit per - // pixel while the only supported mode is 8 bit per pixel - // grayscale. - // Caused by this, they also miscalculate their line length. - if(!strcmp(finfo.id, "8TRACKFB") && vinfo.bits_per_pixel == 1) { - vinfo.bits_per_pixel = 8; - finfo.line_length = vinfo.xres; - } -} - -/*! - \internal - - \class QLinuxFbScreen - \ingroup qws - - \brief The QLinuxFbScreen class implements a screen driver for the - Linux framebuffer. - - Note that this class is only available in \l{Qt for Embedded Linux}. - Custom screen drivers can be added by subclassing the - QScreenDriverPlugin class, using the QScreenDriverFactory class to - dynamically load the driver into the application, but there should - only be one screen object per application. - - The QLinuxFbScreen class provides the cache() function allocating - off-screen graphics memory, and the complementary uncache() - function releasing the allocated memory. The latter function will - first sync the graphics card to ensure the memory isn't still - being used by a command in the graphics card FIFO queue. The - deleteEntry() function deletes the given memory block without such - synchronization. Given the screen instance and client id, the - memory can also be released using the clearCache() function, but - this should only be necessary if a client exits abnormally. - - In addition, when in paletted graphics modes, the set() function - provides the possibility of setting a specified color index to a - given RGB value. - - The QLinuxFbScreen class also acts as a factory for the - unaccelerated screen cursor and the unaccelerated raster-based - implementation of QPaintEngine (\c QRasterPaintEngine); - accelerated drivers for Linux should derive from this class. - - \sa QScreen, QScreenDriverPlugin, {Running Applications} -*/ - -/*! - \fn bool QLinuxFbScreen::useOffscreen() - \internal -*/ - -// Unaccelerated screen/driver setup. Can be overridden by accelerated -// drivers - -/*! - \fn QLinuxFbScreen::QLinuxFbScreen(int displayId) - - Constructs a QLinuxFbScreen object. The \a displayId argument - identifies the Qt for Embedded Linux server to connect to. -*/ - -QLinuxFbScreen::QLinuxFbScreen(int display_id) - : QScreen(display_id, LinuxFBClass), d_ptr(new QLinuxFbScreenPrivate) -{ - canaccel=false; - clearCacheFunc = &clearCache; -#ifdef QT_QWS_CLIENTBLIT - setSupportsBlitInClients(true); -#endif -} - -/*! - Destroys this QLinuxFbScreen object. -*/ - -QLinuxFbScreen::~QLinuxFbScreen() -{ -} - -/*! - \reimp - - This is called by \l{Qt for Embedded Linux} clients to map in the framebuffer. - It should be reimplemented by accelerated drivers to map in - graphics card registers; those drivers should then call this - function in order to set up offscreen memory management. The - device is specified in \a displaySpec; e.g. "/dev/fb". - - \sa disconnect() -*/ - -bool QLinuxFbScreen::connect(const QString &displaySpec) -{ - d_ptr->displaySpec = displaySpec; - - const QStringList args = displaySpec.split(QLatin1Char(':')); - - if (args.contains(QLatin1String("nographicsmodeswitch"))) - d_ptr->doGraphicsMode = false; - -#ifdef QT_QWS_DEPTH_GENERIC - if (args.contains(QLatin1String("genericcolors"))) - d_ptr->doGenericColors = true; -#endif - - QRegExp ttyRegExp(QLatin1String("tty=(.*)")); - if (args.indexOf(ttyRegExp) != -1) - d_ptr->ttyDevice = ttyRegExp.cap(1); - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN -#ifndef QT_QWS_FRAMEBUFFER_LITTLE_ENDIAN - if (args.contains(QLatin1String("littleendian"))) -#endif - QScreen::setFrameBufferLittleEndian(true); -#endif - - QString dev = QLatin1String("/dev/fb0"); - foreach(QString d, args) { - if (d.startsWith(QLatin1Char('/'))) { - dev = d; - break; - } - } - - if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) - d_ptr->fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); - if (d_ptr->fd == -1) { - if (QApplication::type() == QApplication::GuiServer) { - perror("QScreenLinuxFb::connect"); - qCritical("Error opening framebuffer device %s", qPrintable(dev)); - return false; - } - if (access(dev.toLatin1().constData(), R_OK) == 0) - d_ptr->fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); - } - - ::fb_fix_screeninfo finfo; - ::fb_var_screeninfo vinfo; - //####################### - // Shut up Valgrind - memset(&vinfo, 0, sizeof(vinfo)); - memset(&finfo, 0, sizeof(finfo)); - //####################### - - /* Get fixed screen information */ - if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { - perror("QLinuxFbScreen::connect"); - qWarning("Error reading fixed information"); - return false; - } - - d_ptr->driverType = strcmp(finfo.id, "8TRACKFB") ? GenericDriver : EInk8Track; - - if (finfo.type == FB_TYPE_VGA_PLANES) { - qWarning("VGA16 video mode not supported"); - return false; - } - - /* Get variable screen information */ - if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { - perror("QLinuxFbScreen::connect"); - qWarning("Error reading variable information"); - return false; - } - - fixupScreenInfo(finfo, vinfo); - - grayscale = vinfo.grayscale; - d = vinfo.bits_per_pixel; - if (d == 24) { - d = vinfo.red.length + vinfo.green.length + vinfo.blue.length; - if (d <= 0) - d = 24; // reset if color component lengths are not reported - } else if (d == 16) { - d = vinfo.red.length + vinfo.green.length + vinfo.blue.length; - if (d <= 0) - d = 16; - } - lstep = finfo.line_length; - - int xoff = vinfo.xoffset; - int yoff = vinfo.yoffset; - const char* qwssize; - if((qwssize=::getenv("QWS_SIZE")) && sscanf(qwssize,"%dx%d",&w,&h)==2) { - if (d_ptr->fd != -1) { - if ((uint)w > vinfo.xres) w = vinfo.xres; - if ((uint)h > vinfo.yres) h = vinfo.yres; - } - dw=w; - dh=h; - int xxoff, yyoff; - if (sscanf(qwssize, "%*dx%*d+%d+%d", &xxoff, &yyoff) == 2) { - if (xxoff < 0 || xxoff + w > vinfo.xres) - xxoff = vinfo.xres - w; - if (yyoff < 0 || yyoff + h > vinfo.yres) - yyoff = vinfo.yres - h; - xoff += xxoff; - yoff += yyoff; - } else { - xoff += (vinfo.xres - w)/2; - yoff += (vinfo.yres - h)/2; - } - } else { - dw=w=vinfo.xres; - dh=h=vinfo.yres; - } - - if (w == 0 || h == 0) { - qWarning("QScreenLinuxFb::connect(): Unable to find screen geometry, " - "will use 320x240."); - dw = w = 320; - dh = h = 240; - } - - setPixelFormat(vinfo); - - // Handle display physical size spec. - QStringList displayArgs = displaySpec.split(QLatin1Char(':')); - QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)")); - int dimIdxW = displayArgs.indexOf(mmWidthRx); - QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)")); - int dimIdxH = displayArgs.indexOf(mmHeightRx); - if (dimIdxW >= 0) { - mmWidthRx.exactMatch(displayArgs.at(dimIdxW)); - physWidth = mmWidthRx.cap(1).toInt(); - if (dimIdxH < 0) - physHeight = dh*physWidth/dw; - } - if (dimIdxH >= 0) { - mmHeightRx.exactMatch(displayArgs.at(dimIdxH)); - physHeight = mmHeightRx.cap(1).toInt(); - if (dimIdxW < 0) - physWidth = dw*physHeight/dh; - } - if (dimIdxW < 0 && dimIdxH < 0) { - if (vinfo.width != 0 && vinfo.height != 0 - && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { - physWidth = vinfo.width; - physHeight = vinfo.height; - } else { - const int dpi = 72; - physWidth = qRound(dw * 25.4 / dpi); - physHeight = qRound(dh * 25.4 / dpi); - } - } - - dataoffset = yoff * lstep + xoff * d / 8; - //qDebug("Using %dx%dx%d screen",w,h,d); - - /* Figure out the size of the screen in bytes */ - size = h * lstep; - - mapsize = finfo.smem_len; - - data = (unsigned char *)-1; - if (d_ptr->fd != -1) - data = (unsigned char *)mmap(0, mapsize, PROT_READ | PROT_WRITE, - MAP_SHARED, d_ptr->fd, 0); - - if ((long)data == -1) { - if (QApplication::type() == QApplication::GuiServer) { - perror("QLinuxFbScreen::connect"); - qWarning("Error: failed to map framebuffer device to memory."); - return false; - } - data = 0; - } else { - data += dataoffset; - } - - canaccel = useOffscreen(); - if(canaccel) - setupOffScreen(); - - // Now read in palette - if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { - screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; - int loopc; - ::fb_cmap startcmap; - startcmap.start=0; - startcmap.len=screencols; - startcmap.red=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - startcmap.green=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - startcmap.blue=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - startcmap.transp=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - if (d_ptr->fd == -1 || ioctl(d_ptr->fd, FBIOGETCMAP, &startcmap)) { - perror("QLinuxFbScreen::connect"); - qWarning("Error reading palette from framebuffer, using default palette"); - createPalette(startcmap, vinfo, finfo); - } - int bits_used = 0; - for(loopc=0;loopc<screencols;loopc++) { - screenclut[loopc]=qRgb(startcmap.red[loopc] >> 8, - startcmap.green[loopc] >> 8, - startcmap.blue[loopc] >> 8); - bits_used |= startcmap.red[loopc] - | startcmap.green[loopc] - | startcmap.blue[loopc]; - } - // WORKAROUND: Some framebuffer drivers only return 8 bit - // color values, so we need to not bit shift them.. - if ((bits_used & 0x00ff) && !(bits_used & 0xff00)) { - for(loopc=0;loopc<screencols;loopc++) { - screenclut[loopc] = qRgb(startcmap.red[loopc], - startcmap.green[loopc], - startcmap.blue[loopc]); - } - qWarning("8 bits cmap returned due to faulty FB driver, colors corrected"); - } - free(startcmap.red); - free(startcmap.green); - free(startcmap.blue); - free(startcmap.transp); - } else { - screencols=0; - } - - return true; -} - -/*! - \reimp - - This unmaps the framebuffer. - - \sa connect() -*/ - -void QLinuxFbScreen::disconnect() -{ - data -= dataoffset; - if (data) - munmap((char*)data,mapsize); - close(d_ptr->fd); -} - -// #define DEBUG_VINFO - -void QLinuxFbScreen::createPalette(fb_cmap &cmap, fb_var_screeninfo &vinfo, fb_fix_screeninfo &finfo) -{ - if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { - screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; - cmap.start=0; - cmap.len=screencols; - cmap.red=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - cmap.green=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - cmap.blue=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - cmap.transp=(unsigned short int *) - malloc(sizeof(unsigned short int)*screencols); - - if (screencols==16) { - if (finfo.type == FB_TYPE_PACKED_PIXELS) { - // We'll setup a grayscale cmap for 4bpp linear - int val = 0; - for (int idx = 0; idx < 16; ++idx, val += 17) { - cmap.red[idx] = (val<<8)|val; - cmap.green[idx] = (val<<8)|val; - cmap.blue[idx] = (val<<8)|val; - screenclut[idx]=qRgb(val, val, val); - } - } else { - // Default 16 colour palette - // Green is now trolltech green so certain images look nicer - // black d_gray l_gray white red green blue cyan magenta yellow - unsigned char reds[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0xFF, 0xA2, 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x82 }; - unsigned char greens[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0xC5, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F }; - unsigned char blues[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0x11, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F, 0x7F, 0x00, 0x00 }; - - for (int idx = 0; idx < 16; ++idx) { - cmap.red[idx] = ((reds[idx]) << 8)|reds[idx]; - cmap.green[idx] = ((greens[idx]) << 8)|greens[idx]; - cmap.blue[idx] = ((blues[idx]) << 8)|blues[idx]; - cmap.transp[idx] = 0; - screenclut[idx]=qRgb(reds[idx], greens[idx], blues[idx]); - } - } - } else { - if (grayscale) { - // Build grayscale palette - int i; - for(i=0;i<screencols;++i) { - int bval = screencols == 256 ? i : (i << 4); - ushort val = (bval << 8) | bval; - cmap.red[i] = val; - cmap.green[i] = val; - cmap.blue[i] = val; - cmap.transp[i] = 0; - screenclut[i] = qRgb(bval,bval,bval); - } - } else { - // 6x6x6 216 color cube - int idx = 0; - for(int ir = 0x0; ir <= 0xff; ir+=0x33) { - for(int ig = 0x0; ig <= 0xff; ig+=0x33) { - for(int ib = 0x0; ib <= 0xff; ib+=0x33) { - cmap.red[idx] = (ir << 8)|ir; - cmap.green[idx] = (ig << 8)|ig; - cmap.blue[idx] = (ib << 8)|ib; - cmap.transp[idx] = 0; - screenclut[idx]=qRgb(ir, ig, ib); - ++idx; - } - } - } - // Fill in rest with 0 - for (int loopc=0; loopc<40; ++loopc) { - screenclut[idx]=0; - ++idx; - } - screencols=idx; - } - } - } else if(finfo.visual==FB_VISUAL_DIRECTCOLOR) { - cmap.start=0; - int rbits=0,gbits=0,bbits=0; - switch (vinfo.bits_per_pixel) { - case 8: - rbits=vinfo.red.length; - gbits=vinfo.green.length; - bbits=vinfo.blue.length; - if(rbits==0 && gbits==0 && bbits==0) { - // cyber2000 driver bug hack - rbits=3; - gbits=3; - bbits=2; - } - break; - case 15: - rbits=5; - gbits=5; - bbits=5; - break; - case 16: - rbits=5; - gbits=6; - bbits=5; - break; - case 18: - case 19: - rbits=6; - gbits=6; - bbits=6; - break; - case 24: case 32: - rbits=gbits=bbits=8; - break; - } - screencols=cmap.len=1<<qMax(rbits,qMax(gbits,bbits)); - cmap.red=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.green=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.blue=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.transp=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - for(unsigned int i = 0x0; i < cmap.len; i++) { - cmap.red[i] = i*65535/((1<<rbits)-1); - cmap.green[i] = i*65535/((1<<gbits)-1); - cmap.blue[i] = i*65535/((1<<bbits)-1); - cmap.transp[i] = 0; - } - } -} - -/*! - \reimp - - This is called by the \l{Qt for Embedded Linux} server at startup time. - It turns off console blinking, sets up the color palette, enables write - combining on the framebuffer and initialises the off-screen memory - manager. -*/ - -bool QLinuxFbScreen::initDevice() -{ - d_ptr->openTty(); - - // Grab current mode so we can reset it - fb_var_screeninfo vinfo; - fb_fix_screeninfo finfo; - //####################### - // Shut up Valgrind - memset(&vinfo, 0, sizeof(vinfo)); - memset(&finfo, 0, sizeof(finfo)); - //####################### - - if (ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { - perror("QLinuxFbScreen::initDevice"); - qFatal("Error reading variable information in card init"); - return false; - } - -#ifdef DEBUG_VINFO - qDebug("Greyscale %d",vinfo.grayscale); - qDebug("Nonstd %d",vinfo.nonstd); - qDebug("Red %d %d %d",vinfo.red.offset,vinfo.red.length, - vinfo.red.msb_right); - qDebug("Green %d %d %d",vinfo.green.offset,vinfo.green.length, - vinfo.green.msb_right); - qDebug("Blue %d %d %d",vinfo.blue.offset,vinfo.blue.length, - vinfo.blue.msb_right); - qDebug("Transparent %d %d %d",vinfo.transp.offset,vinfo.transp.length, - vinfo.transp.msb_right); -#endif - - if (ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { - perror("QLinuxFbScreen::initDevice"); - qCritical("Error reading fixed information in card init"); - // It's not an /error/ as such, though definitely a bad sign - // so we return true - return true; - } - - fixupScreenInfo(finfo, vinfo); - - d_ptr->startupw=vinfo.xres; - d_ptr->startuph=vinfo.yres; - d_ptr->startupd=vinfo.bits_per_pixel; - grayscale = vinfo.grayscale; - -#ifdef __i386__ - // Now init mtrr - if(!::getenv("QWS_NOMTRR")) { - int mfd=QT_OPEN("/proc/mtrr",O_WRONLY,0); - // MTRR entry goes away when file is closed - i.e. - // hopefully when QWS is killed - if(mfd != -1) { - mtrr_sentry sentry; - sentry.base=(unsigned long int)finfo.smem_start; - //qDebug("Physical framebuffer address %p",(void*)finfo.smem_start); - // Size needs to be in 4k chunks, but that's not always - // what we get thanks to graphics card registers. Write combining - // these is Not Good, so we write combine what we can - // (which is not much - 4 megs on an 8 meg card, it seems) - unsigned int size=finfo.smem_len; - size=size >> 22; - size=size << 22; - sentry.size=size; - sentry.type=MTRR_TYPE_WRCOMB; - if(ioctl(mfd,MTRRIOC_ADD_ENTRY,&sentry)==-1) { - //printf("Couldn't add mtrr entry for %lx %lx, %s\n", - //sentry.base,sentry.size,strerror(errno)); - } - } - - // Should we close mfd here? - //QT_CLOSE(mfd); - } -#endif - if ((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4) || (finfo.visual==FB_VISUAL_DIRECTCOLOR)) - { - fb_cmap cmap; - createPalette(cmap, vinfo, finfo); - if (ioctl(d_ptr->fd, FBIOPUTCMAP, &cmap)) { - perror("QLinuxFbScreen::initDevice"); - qWarning("Error writing palette to framebuffer"); - } - free(cmap.red); - free(cmap.green); - free(cmap.blue); - free(cmap.transp); - } - - if (canaccel) { - *entryp=0; - *lowest = mapsize; - insert_entry(*entryp, *lowest, *lowest); // dummy entry to mark start - } - - shared->fifocount = 0; - shared->buffer_offset = 0xffffffff; // 0 would be a sensible offset (screen) - shared->linestep = 0; - shared->cliptop = 0xffffffff; - shared->clipleft = 0xffffffff; - shared->clipright = 0xffffffff; - shared->clipbottom = 0xffffffff; - shared->rop = 0xffffffff; - -#ifdef QT_QWS_DEPTH_GENERIC - if (pixelFormat() == QImage::Format_Invalid && screencols == 0 - && d_ptr->doGenericColors) - { - qt_set_generic_blit(this, vinfo.bits_per_pixel, - vinfo.red.length, vinfo.green.length, - vinfo.blue.length, vinfo.transp.length, - vinfo.red.offset, vinfo.green.offset, - vinfo.blue.offset, vinfo.transp.offset); - } -#endif - -#ifndef QT_NO_QWS_CURSOR - QScreenCursor::initSoftwareCursor(); -#endif - blank(false); - - return true; -} - -/* - The offscreen memory manager's list of entries is stored at the bottom - of the offscreen memory area and consistes of a series of QPoolEntry's, - each of which keep track of a block of allocated memory. Unallocated memory - is implicitly indicated by the gap between blocks indicated by QPoolEntry's. - The memory manager looks through any unallocated memory before the end - of currently-allocated memory to see if a new block will fit in the gap; - if it doesn't it allocated it from the end of currently-allocated memory. - Memory is allocated from the top of the framebuffer downwards; if it hits - the list of entries then offscreen memory is full and further allocations - are made from main RAM (and hence unaccelerated). Allocated memory can - be seen as a sort of upside-down stack; lowest keeps track of the - bottom of the stack. -*/ - -void QLinuxFbScreen::delete_entry(int pos) -{ - if (pos > *entryp || pos < 0) { - qWarning("Attempt to delete odd pos! %d %d", pos, *entryp); - return; - } - -#ifdef DEBUG_CACHE - qDebug("Remove entry: %d", pos); -#endif - - QPoolEntry *qpe = &entries[pos]; - if (qpe->start <= *lowest) { - // Lowest goes up again - *lowest = entries[pos-1].start; -#ifdef DEBUG_CACHE - qDebug(" moved lowest to %d", *lowest); -#endif - } - - (*entryp)--; - if (pos == *entryp) - return; - - int size = (*entryp)-pos; - memmove(&entries[pos], &entries[pos+1], size*sizeof(QPoolEntry)); -} - -void QLinuxFbScreen::insert_entry(int pos, int start, int end) -{ - if (pos > *entryp) { - qWarning("Attempt to insert odd pos! %d %d",pos,*entryp); - return; - } - -#ifdef DEBUG_CACHE - qDebug("Insert entry: %d, %d -> %d", pos, start, end); -#endif - - if (start < (int)*lowest) { - *lowest = start; -#ifdef DEBUG_CACHE - qDebug(" moved lowest to %d", *lowest); -#endif - } - - if (pos == *entryp) { - entries[pos].start = start; - entries[pos].end = end; - entries[pos].clientId = qws_client_id; - (*entryp)++; - return; - } - - int size=(*entryp)-pos; - memmove(&entries[pos+1],&entries[pos],size*sizeof(QPoolEntry)); - entries[pos].start=start; - entries[pos].end=end; - entries[pos].clientId=qws_client_id; - (*entryp)++; -} - -/*! - \fn uchar * QLinuxFbScreen::cache(int amount) - - Requests the specified \a amount of offscreen graphics card memory - from the memory manager, and returns a pointer to the data within - the framebuffer (or 0 if there is no free memory). - - Note that the display is locked while memory is allocated in order to - preserve the memory pool's integrity. - - Use the QScreen::onCard() function to retrieve an offset (in - bytes) from the start of graphics card memory for the returned - pointer. - - \sa uncache(), clearCache(), deleteEntry() -*/ - -uchar * QLinuxFbScreen::cache(int amount) -{ - if (!canaccel || entryp == 0) - return 0; - - qt_fbdpy->grab(); - - int startp = cacheStart + (*entryp+1) * sizeof(QPoolEntry); - if (startp >= (int)*lowest) { - // We don't have room for another cache QPoolEntry. -#ifdef DEBUG_CACHE - qDebug("No room for pool entry in VRAM"); -#endif - qt_fbdpy->ungrab(); - return 0; - } - - int align = pixmapOffsetAlignment(); - - if (*entryp > 1) { - // Try to find a gap in the allocated blocks. - for (int loopc = 0; loopc < *entryp-1; loopc++) { - int freestart = entries[loopc+1].end; - int freeend = entries[loopc].start; - if (freestart != freeend) { - while (freestart % align) { - freestart++; - } - int len=freeend-freestart; - if (len >= amount) { - insert_entry(loopc+1, freestart, freestart+amount); - qt_fbdpy->ungrab(); - return data+freestart; - } - } - } - } - - // No free blocks in already-taken memory; get some more - // if we can - int newlowest = (*lowest)-amount; - if (newlowest % align) { - newlowest -= align; - while (newlowest % align) { - newlowest++; - } - } - if (startp >= newlowest) { - qt_fbdpy->ungrab(); -#ifdef DEBUG_CACHE - qDebug("No VRAM available for %d bytes", amount); -#endif - return 0; - } - insert_entry(*entryp, newlowest, *lowest); - qt_fbdpy->ungrab(); - - return data + newlowest; -} - -/*! - \fn void QLinuxFbScreen::uncache(uchar * memoryBlock) - - Deletes the specified \a memoryBlock allocated from the graphics - card memory. - - Note that the display is locked while memory is unallocated in - order to preserve the memory pool's integrity. - - This function will first sync the graphics card to ensure the - memory isn't still being used by a command in the graphics card - FIFO queue. It is possible to speed up a driver by overriding this - function to avoid syncing. For example, the driver might delay - deleting the memory until it detects that all commands dealing - with the memory are no longer in the queue. Note that it will then - be up to the driver to ensure that the specified \a memoryBlock no - longer is being used. - - \sa cache(), deleteEntry(), clearCache() - */ -void QLinuxFbScreen::uncache(uchar * c) -{ - // need to sync graphics card - - deleteEntry(c); -} - -/*! - \fn void QLinuxFbScreen::deleteEntry(uchar * memoryBlock) - - Deletes the specified \a memoryBlock allocated from the graphics - card memory. - - \sa uncache(), cache(), clearCache() -*/ -void QLinuxFbScreen::deleteEntry(uchar * c) -{ - qt_fbdpy->grab(); - unsigned long pos=(unsigned long)c; - pos-=((unsigned long)data); - unsigned int hold=(*entryp); - for(unsigned int loopc=1;loopc<hold;loopc++) { - if (entries[loopc].start==pos) { - if (entries[loopc].clientId == qws_client_id) - delete_entry(loopc); - else - qWarning("Attempt to delete client id %d cache entry", - entries[loopc].clientId); - qt_fbdpy->ungrab(); - return; - } - } - qt_fbdpy->ungrab(); - qWarning("Attempt to delete unknown offset %ld",pos); -} - -/*! - Removes all entries from the cache for the specified screen \a - instance and client identified by the given \a clientId. - - Calling this function should only be necessary if a client exits - abnormally. - - \sa cache(), uncache(), deleteEntry() -*/ -void QLinuxFbScreen::clearCache(QScreen *instance, int clientId) -{ - QLinuxFbScreen *screen = (QLinuxFbScreen *)instance; - if (!screen->canaccel || !screen->entryp) - return; - qt_fbdpy->grab(); - for (int loopc = 0; loopc < *(screen->entryp); loopc++) { - if (screen->entries[loopc].clientId == clientId) { - screen->delete_entry(loopc); - loopc--; - } - } - qt_fbdpy->ungrab(); -} - - -void QLinuxFbScreen::setupOffScreen() -{ - // Figure out position of offscreen memory - // Set up pool entries pointer table and 64-bit align it - int psize = size; - - // hw: this causes the limitation of cursors to 64x64 - // the cursor should rather use the normal pixmap mechanism - psize += 4096; // cursor data - psize += 8; // for alignment - psize &= ~0x7; // align - - unsigned long pos = (unsigned long)data; - pos += psize; - entryp = ((int *)pos); - lowest = ((unsigned int *)pos)+1; - pos += (sizeof(int))*4; - entries = (QPoolEntry *)pos; - - // beginning of offscreen memory available for pixmaps. - cacheStart = psize + 4*sizeof(int) + sizeof(QPoolEntry); -} - -/*! - \reimp - - This is called by the \l{Qt for Embedded Linux} server when it shuts - down, and should be inherited if you need to do any card-specific cleanup. - The default version hides the screen cursor and reenables the blinking - cursor and screen blanking. -*/ - -void QLinuxFbScreen::shutdownDevice() -{ - // Causing crashes. Not needed. - //setMode(startupw,startuph,startupd); -/* - if (startupd == 8) { - ioctl(fd,FBIOPUTCMAP,startcmap); - free(startcmap->red); - free(startcmap->green); - free(startcmap->blue); - free(startcmap->transp); - delete startcmap; - startcmap = 0; - } -*/ - d_ptr->closeTty(); -} - -/*! - \fn void QLinuxFbScreen::set(unsigned int index,unsigned int red,unsigned int green,unsigned int blue) - - Sets the specified color \a index to the specified RGB value, (\a - red, \a green, \a blue), when in paletted graphics modes. -*/ - -void QLinuxFbScreen::set(unsigned int i,unsigned int r,unsigned int g,unsigned int b) -{ - if (d_ptr->fd != -1) { - fb_cmap cmap; - cmap.start=i; - cmap.len=1; - cmap.red=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.green=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.blue=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.transp=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.red[0]=r << 8; - cmap.green[0]=g << 8; - cmap.blue[0]=b << 8; - cmap.transp[0]=0; - ioctl(d_ptr->fd, FBIOPUTCMAP, &cmap); - free(cmap.red); - free(cmap.green); - free(cmap.blue); - free(cmap.transp); - } - screenclut[i] = qRgb(r, g, b); -} - -/*! - \reimp - - Sets the framebuffer to a new resolution and bit depth. The width is - in \a nw, the height is in \a nh, and the depth is in \a nd. After - doing this any currently-existing paint engines will be invalid and the - screen should be completely redrawn. In a multiple-process - Embedded Qt situation you must signal all other applications to - call setMode() to the same mode and redraw. -*/ - -void QLinuxFbScreen::setMode(int nw,int nh,int nd) -{ - if (d_ptr->fd == -1) - return; - - fb_fix_screeninfo finfo; - fb_var_screeninfo vinfo; - //####################### - // Shut up Valgrind - memset(&vinfo, 0, sizeof(vinfo)); - memset(&finfo, 0, sizeof(finfo)); - //####################### - - if (ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { - perror("QLinuxFbScreen::setMode"); - qFatal("Error reading variable information in mode change"); - } - - vinfo.xres=nw; - vinfo.yres=nh; - vinfo.bits_per_pixel=nd; - - if (ioctl(d_ptr->fd, FBIOPUT_VSCREENINFO, &vinfo)) { - perror("QLinuxFbScreen::setMode"); - qCritical("Error writing variable information in mode change"); - } - - if (ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { - perror("QLinuxFbScreen::setMode"); - qFatal("Error reading changed variable information in mode change"); - } - - if (ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { - perror("QLinuxFbScreen::setMode"); - qFatal("Error reading fixed information"); - } - - fixupScreenInfo(finfo, vinfo); - disconnect(); - connect(d_ptr->displaySpec); - exposeRegion(region(), 0); -} - -// save the state of the graphics card -// This is needed so that e.g. we can restore the palette when switching -// between linux virtual consoles. - -/*! - \reimp - - This doesn't do anything; accelerated drivers may wish to reimplement - it to save graphics cards registers. It's called by the - \l{Qt for Embedded Linux} server when the virtual console is switched. -*/ - -void QLinuxFbScreen::save() -{ - // nothing to do. -} - - -// restore the state of the graphics card. -/*! - \reimp - - This is called when the virtual console is switched back to - \l{Qt for Embedded Linux} and restores the palette. -*/ -void QLinuxFbScreen::restore() -{ - if (d_ptr->fd == -1) - return; - - if ((d == 8) || (d == 4)) { - fb_cmap cmap; - cmap.start=0; - cmap.len=screencols; - cmap.red=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.green=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.blue=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - cmap.transp=(unsigned short int *) - malloc(sizeof(unsigned short int)*256); - for (int loopc = 0; loopc < screencols; loopc++) { - cmap.red[loopc] = qRed(screenclut[loopc]) << 8; - cmap.green[loopc] = qGreen(screenclut[loopc]) << 8; - cmap.blue[loopc] = qBlue(screenclut[loopc]) << 8; - cmap.transp[loopc] = 0; - } - ioctl(d_ptr->fd, FBIOPUTCMAP, &cmap); - free(cmap.red); - free(cmap.green); - free(cmap.blue); - free(cmap.transp); - } -} - -/*! - \fn int QLinuxFbScreen::sharedRamSize(void * end) - \internal -*/ - -// This works like the QScreenCursor code. end points to the end -// of our shared structure, we return the amount of memory we reserved -int QLinuxFbScreen::sharedRamSize(void * end) -{ - shared=(QLinuxFb_Shared *)end; - shared--; - return sizeof(QLinuxFb_Shared); -} - -/*! - \reimp -*/ -void QLinuxFbScreen::setDirty(const QRect &r) -{ - if(d_ptr->driverType == EInk8Track) { - // e-Ink displays need a trigger to actually show what is - // in their framebuffer memory. The 8-Track driver does this - // by adding custom IOCTLs - FBIO_EINK_DISP_PIC (0x46a2) takes - // an argument specifying whether or not to flash the screen - // while updating. - // There doesn't seem to be a way to tell it to just update - // a subset of the screen. - if(r.left() == 0 && r.top() == 0 && r.width() == dw && r.height() == dh) - ioctl(d_ptr->fd, 0x46a2, 1); - else - ioctl(d_ptr->fd, 0x46a2, 0); - } -} - -/*! - \reimp -*/ -void QLinuxFbScreen::blank(bool on) -{ - if (d_ptr->blank == on) - return; - -#if defined(QT_QWS_IPAQ) - if (on) - system("apm -suspend"); -#else - if (d_ptr->fd == -1) - return; -// Some old kernel versions don't have this. These defines should go -// away eventually -#if defined(FBIOBLANK) -#if defined(VESA_POWERDOWN) && defined(VESA_NO_BLANKING) - ioctl(d_ptr->fd, FBIOBLANK, on ? VESA_POWERDOWN : VESA_NO_BLANKING); -#else - ioctl(d_ptr->fd, FBIOBLANK, on ? 1 : 0); -#endif -#endif -#endif - - d_ptr->blank = on; -} - -void QLinuxFbScreen::setPixelFormat(struct fb_var_screeninfo info) -{ - const fb_bitfield rgba[4] = { info.red, info.green, - info.blue, info.transp }; - - QImage::Format format = QImage::Format_Invalid; - - switch (d) { - case 32: { - const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0}, - {0, 8, 0}, {24, 8, 0}}; - const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0}, - {16, 8, 0}, {24, 8, 0}}; - if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_ARGB32; - } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB32; - } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB32; - pixeltype = QScreen::BGRPixel; - } - break; - } - case 24: { - const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0}, - {0, 8, 0}, {0, 0, 0}}; - const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0}, - {16, 8, 0}, {0, 0, 0}}; - if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB888; - } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB888; - pixeltype = QScreen::BGRPixel; - } - break; - } - case 18: { - const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0}, - {0, 6, 0}, {0, 0, 0}}; - if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0) - format = QImage::Format_RGB666; - break; - } - case 16: { - const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0}, - {0, 5, 0}, {0, 0, 0}}; - const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0}, - {11, 5, 0}, {0, 0, 0}}; - if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB16; - } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB16; - pixeltype = QScreen::BGRPixel; - } - break; - } - case 15: { - const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0}, - {0, 5, 0}, {15, 1, 0}}; - const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0}, - {10, 5, 0}, {15, 1, 0}}; - if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB555; - } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) { - format = QImage::Format_RGB555; - pixeltype = QScreen::BGRPixel; - } - break; - } - case 12: { - const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0}, - {0, 4, 0}, {0, 0, 0}}; - if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0) - format = QImage::Format_RGB444; - break; - } - case 8: - break; - case 1: - format = QImage::Format_Mono; //###: LSB??? - break; - default: - break; - } - - QScreen::setPixelFormat(format); -} - -bool QLinuxFbScreen::useOffscreen() -{ - // Not done for 8Track because on e-Ink displays, - // everything is offscreen anyway - if (d_ptr->driverType == EInk8Track || ((mapsize - size) < 16*1024)) - return false; - - return true; -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_LINUXFB diff --git a/src/gui/embedded/qscreenlinuxfb_qws.h b/src/gui/embedded/qscreenlinuxfb_qws.h deleted file mode 100644 index 4142bb5dd4..0000000000 --- a/src/gui/embedded/qscreenlinuxfb_qws.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENLINUXFB_QWS_H -#define QSCREENLINUXFB_QWS_H - -#include <QtGui/qscreen_qws.h> - -struct fb_cmap; -struct fb_var_screeninfo; -struct fb_fix_screeninfo; - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_LINUXFB - -class QLinuxFb_Shared -{ -public: - volatile int lastop; - volatile int optype; - volatile int fifocount; // Accel drivers only - volatile int fifomax; - volatile int forecol; // Foreground colour caching - volatile unsigned int buffer_offset; // Destination - volatile int linestep; - volatile int cliptop; // Clip rectangle - volatile int clipleft; - volatile int clipright; - volatile int clipbottom; - volatile unsigned int rop; - -}; - -class QLinuxFbScreenPrivate; - -class Q_GUI_EXPORT QLinuxFbScreen : public QScreen -{ -public: - explicit QLinuxFbScreen(int display_id); - virtual ~QLinuxFbScreen(); - - virtual bool initDevice(); - virtual bool connect(const QString &displaySpec); - - virtual bool useOffscreen(); - - enum DriverTypes { GenericDriver, EInk8Track }; - - virtual void disconnect(); - virtual void shutdownDevice(); - virtual void setMode(int,int,int); - virtual void save(); - virtual void restore(); - virtual void blank(bool on); - virtual void set(unsigned int,unsigned int,unsigned int,unsigned int); - virtual uchar * cache(int); - virtual void uncache(uchar *); - virtual int sharedRamSize(void *); - virtual void setDirty(const QRect&); - - QLinuxFb_Shared * shared; - -protected: - - void deleteEntry(uchar *); - - bool canaccel; - int dataoffset; - int cacheStart; - - virtual void fixupScreenInfo(fb_fix_screeninfo &finfo, fb_var_screeninfo &vinfo); - static void clearCache(QScreen *instance, int); - -private: - - void delete_entry(int); - void insert_entry(int,int,int); - void setupOffScreen(); - void createPalette(fb_cmap &cmap, fb_var_screeninfo &vinfo, fb_fix_screeninfo &finfo); - void setPixelFormat(struct fb_var_screeninfo); - - QLinuxFbScreenPrivate *d_ptr; -}; - -#endif // QT_NO_QWS_LINUXFB - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENLINUXFB_QWS_H diff --git a/src/gui/embedded/qscreenmulti_qws.cpp b/src/gui/embedded/qscreenmulti_qws.cpp deleted file mode 100644 index 8a27a7cb82..0000000000 --- a/src/gui/embedded/qscreenmulti_qws.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreenmulti_qws_p.h" - -#ifndef QT_NO_QWS_MULTISCREEN - -#include <qlist.h> -#include <qstringlist.h> -#include <qwidget.h> -#include <qdebug.h> - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_QWS_CURSOR - -class QMultiScreenCursor : public QScreenCursor -{ -public: - QMultiScreenCursor() : currentCursor(qt_screencursor) { enable = false; } - ~QMultiScreenCursor() { qt_screencursor = 0; } - - void set(const QImage &image, int hotx, int hoty); - void move(int x, int y); - void show(); - void hide(); - - void addCursor(QScreenCursor *cursor); - -private: - void setCurrentCursor(QScreenCursor *newCursor); - - QScreenCursor *currentCursor; - QList<QScreenCursor*> cursors; -}; - -void QMultiScreenCursor::set(const QImage &image, int hotx, int hoty) -{ - QScreenCursor::set(image, hotx, hoty); - if (currentCursor) - currentCursor->set(image, hotx, hoty); -} - -void QMultiScreenCursor::setCurrentCursor(QScreenCursor *newCursor) -{ - *((QScreenCursor*)this) = *newCursor; - currentCursor = newCursor; -} - -// XXX: this is a mess! -void QMultiScreenCursor::move(int x, int y) -{ - const int oldIndex = qt_screen->subScreenIndexAt(pos); - QScreenCursor::move(x, y); // updates pos - const int newIndex = qt_screen->subScreenIndexAt(pos); - - if (!currentCursor && oldIndex != -1) - setCurrentCursor(cursors.at(oldIndex)); - QScreenCursor *oldCursor = currentCursor; - - if (oldIndex != -1) { - const QScreen *oldScreen = qt_screen->subScreens().at(oldIndex); - if (newIndex == -1 || oldScreen->region().contains(pos)) { - oldCursor->move(x, y); - return; - } - } - - if (newIndex != -1) { - QScreenCursor *newCursor = cursors.at(newIndex); - newCursor->set(cursor, hotspot.x(), hotspot.y()); - - if (oldCursor) { - if (oldCursor->isVisible()) - newCursor->show(); - oldCursor->hide(); - } - - newCursor->move(x, y); - - setCurrentCursor(newCursor); - } -} - -void QMultiScreenCursor::show() -{ - if (currentCursor) - currentCursor->show(); -} - -void QMultiScreenCursor::hide() -{ - if (currentCursor) - currentCursor->hide(); -} - -void QMultiScreenCursor::addCursor(QScreenCursor *cursor) -{ - cursors.append(cursor); -} - -#endif - -class QMultiScreenPrivate -{ -public: - QMultiScreenPrivate() -#ifndef QT_NO_QWS_CURSOR - : cursor(0) -#endif - {} - ~QMultiScreenPrivate() - { -#ifndef QT_NO_QWS_CURSOR - delete cursor; -#endif - } - - QList<QScreen*> screens; - QRegion region; -#ifndef QT_NO_QWS_CURSOR - QMultiScreenCursor *cursor; -#endif -}; - -QMultiScreen::QMultiScreen(int displayId) - : QScreen(displayId, MultiClass), d_ptr(new QMultiScreenPrivate) -{ -} - -QMultiScreen::~QMultiScreen() -{ - delete d_ptr; -} - -bool QMultiScreen::initDevice() -{ - bool ok = true; - -#ifndef QT_NO_QWS_CURSOR - d_ptr->cursor = new QMultiScreenCursor; -#endif - - const int n = d_ptr->screens.count(); - for (int i = 0; i < n; ++i) { - QScreen *s = d_ptr->screens.at(i); - ok = s->initDevice() && ok; -#ifndef QT_NO_QWS_CURSOR - d_ptr->cursor->addCursor(qt_screencursor); // XXX -#endif - } - -#ifndef QT_NO_QWS_CURSOR - // XXX - qt_screencursor = d_ptr->cursor; -#endif - - return ok; -} - -static int getDisplayId(const QString &spec) -{ - QRegExp regexp(QLatin1String(":(\\d+)\\b")); - if (regexp.lastIndexIn(spec) != -1) { - const QString capture = regexp.cap(1); - return capture.toInt(); - } - return 0; -} - -static QPoint filterDisplayOffset(QString &spec) -{ - QRegExp regexp(QLatin1String(":offset=(\\d+),(\\d+)\\b")); - if (regexp.indexIn(spec) == -1) - return QPoint(); - - const int x = regexp.cap(1).toInt(); - const int y = regexp.cap(2).toInt(); - spec.remove(regexp.pos(0), regexp.matchedLength()); - return QPoint(x, y); -} - -bool QMultiScreen::connect(const QString &displaySpec) -{ - QString dSpec = displaySpec; - if (dSpec.startsWith(QLatin1String("Multi:"), Qt::CaseInsensitive)) - dSpec = dSpec.mid(QString::fromLatin1("Multi:").size()); - - const QString displayIdSpec = QString::fromLatin1(" :%1").arg(displayId); - if (dSpec.endsWith(displayIdSpec)) - dSpec = dSpec.left(dSpec.size() - displayIdSpec.size()); - - QStringList specs = dSpec.split(QLatin1Char(' '), QString::SkipEmptyParts); - foreach (QString spec, specs) { - const int id = getDisplayId(spec); - if (spec.startsWith("vnc:", Qt::CaseInsensitive)) { - spec.append(":noDisablePainting"); - } - const QPoint offset = filterDisplayOffset(spec); - QScreen *s = qt_get_screen(id, spec.toLatin1().constData()); - s->setOffset(offset); - addSubScreen(s); - } - - QScreen *firstScreen = d_ptr->screens.at(0); - Q_ASSERT(firstScreen); - - // XXX - QScreen::d = firstScreen->depth(); - - QScreen::lstep = 0; - QScreen::data = 0; - QScreen::size = 0; - - QScreen::w = d_ptr->region.boundingRect().width(); - QScreen::h = d_ptr->region.boundingRect().height(); - - QScreen::dw = QScreen::w; - QScreen::dh = QScreen::h; - - // XXX - Extend the physical size based on the first screen - // to encompass all screens, so that code that uses the multi - // screen to calculate dpi values will get the right numbers. - QScreen::physWidth = firstScreen->physicalWidth() * w / firstScreen->width(); - QScreen::physHeight = firstScreen->physicalHeight() * h / firstScreen->height(); - - // XXXXX - qt_screen = this; - - return true; -} - -void QMultiScreen::disconnect() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->disconnect(); -} - -void QMultiScreen::shutdownDevice() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->shutdownDevice(); -} - -void QMultiScreen::setMode(int, int, int) -{ - return; -} - -bool QMultiScreen::supportsDepth(int) const -{ - return false; -} - -void QMultiScreen::save() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->save(); -} - -void QMultiScreen::restore() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->restore(); -} - -void QMultiScreen::blank(bool on) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->blank(on); -} - -bool QMultiScreen::onCard(const unsigned char *ptr) const -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - if (d_ptr->screens.at(i)->onCard(ptr)) - return true; - return false; -} - -bool QMultiScreen::onCard(const unsigned char *ptr, ulong &offset) const -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - if (d_ptr->screens.at(i)->onCard(ptr, offset)) - return true; - return false; -} - -bool QMultiScreen::isInterlaced() const -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - if (d_ptr->screens.at(i)->isInterlaced()) - return true; - - return false; -} - -int QMultiScreen::memoryNeeded(const QString &string) -{ - int total = 0; - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - total += d_ptr->screens.at(i)->memoryNeeded(string); - return total; -} - -int QMultiScreen::sharedRamSize(void *arg) -{ - int total = 0; - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - total += d_ptr->screens.at(i)->sharedRamSize(arg); - return total; -} - -void QMultiScreen::haltUpdates() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->haltUpdates(); -} - -void QMultiScreen::resumeUpdates() -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) - d_ptr->screens.at(i)->resumeUpdates(); -} - -void QMultiScreen::exposeRegion(QRegion region, int changing) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - const QRegion r = region & screen->region(); - if (r.isEmpty()) - continue; - screen->exposeRegion(r, changing); - } -} - -void QMultiScreen::solidFill(const QColor &color, const QRegion ®ion) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - const QRegion r = region & screen->region(); - if (r.isEmpty()) - continue; - screen->solidFill(color, r); - } -} - -void QMultiScreen::blit(const QImage &img, const QPoint &topLeft, - const QRegion ®ion) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - const QRegion r = region & screen->region(); - if (r.isEmpty()) - continue; - screen->blit(img, topLeft, r); - } -} - -void QMultiScreen::blit(QWSWindow *bs, const QRegion &clip) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - const QRegion r = clip & screen->region(); - if (r.isEmpty()) - continue; - screen->blit(bs, r); - } -} - -void QMultiScreen::setDirty(const QRect &rect) -{ - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - const QRegion r = screen->region() & rect; - if (r.isEmpty()) - continue; - screen->setDirty(r.boundingRect()); - } -} - - -QWSWindowSurface* QMultiScreen::createSurface(const QString &key) const -{ - QWSWindowSurface* surf = 0; - const int n = d_ptr->screens.size(); - for (int i = 0; i < n; ++i) { - QScreen *screen = d_ptr->screens.at(i); - surf = screen->createSurface(key); - if (surf) - break; - } - return surf; -} - - -QWSWindowSurface* QMultiScreen::createSurface(QWidget *widget) const -{ - const QPoint midpoint = (widget->frameGeometry().topLeft() - + widget->frameGeometry().bottomRight()) / 2; - int index = subScreenIndexAt(midpoint); - if (index == -1) - index = 0; // XXX - return d_ptr->screens.at(index)->createSurface(widget); -} - -QList<QScreen*> QMultiScreen::subScreens() const -{ - return d_ptr->screens; -} - -QRegion QMultiScreen::region() const -{ - return d_ptr->region; -} - -void QMultiScreen::addSubScreen(QScreen *screen) -{ - d_ptr->screens.append(screen); - d_ptr->region += screen->region(); -} - -void QMultiScreen::removeSubScreen(QScreen *screen) -{ - d_ptr->screens.removeAll(screen); - d_ptr->region -= screen->region(); -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_MULTISCREEN diff --git a/src/gui/embedded/qscreenmulti_qws_p.h b/src/gui/embedded/qscreenmulti_qws_p.h deleted file mode 100644 index b7eba7e374..0000000000 --- a/src/gui/embedded/qscreenmulti_qws_p.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMULTISCREEN_QWS_P_H -#define QMULTISCREEN_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of the QLibrary class. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// - -#include <qscreen_qws.h> - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_QWS_MULTISCREEN - -class QMultiScreenPrivate; - -class QMultiScreen : public QScreen -{ -public: - QMultiScreen(int displayId); - ~QMultiScreen(); - bool initDevice(); - bool connect(const QString &displaySpec); - void disconnect(); - void shutdownDevice(); - void setMode(int,int,int); - bool supportsDepth(int) const; - - void save(); - void restore(); - void blank(bool on); - - bool onCard(const unsigned char *) const; - bool onCard(const unsigned char *, ulong& out_offset) const; - - bool isInterlaced() const; - - int memoryNeeded(const QString&); - int sharedRamSize(void *); - - void haltUpdates(); - void resumeUpdates(); - - void exposeRegion(QRegion r, int changing); - - void blit(const QImage &img, const QPoint &topLeft, const QRegion ®ion); - void solidFill(const QColor &color, const QRegion ®ion); - void blit(QWSWindow *bs, const QRegion &clip); - void setDirty(const QRect&); - - QWSWindowSurface* createSurface(QWidget *widget) const; - QWSWindowSurface* createSurface(const QString &key) const; - - QList<QScreen*> subScreens() const; - QRegion region() const; - -private: - void addSubScreen(QScreen *screen); - void removeSubScreen(QScreen *screen); - - QMultiScreenPrivate *d_ptr; -}; - - -QT_END_NAMESPACE -#endif // QT_NO_QWS_MULTISCREEN -#endif // QMULTISCREEN_QWS_P_H diff --git a/src/gui/embedded/qscreenproxy_qws.cpp b/src/gui/embedded/qscreenproxy_qws.cpp deleted file mode 100644 index 706524ad19..0000000000 --- a/src/gui/embedded/qscreenproxy_qws.cpp +++ /dev/null @@ -1,635 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qscreenproxy_qws.h> - -#ifndef QT_NO_QWS_PROXYSCREEN - -#include <qregexp.h> - -QT_BEGIN_NAMESPACE -#ifndef QT_NO_QWS_CURSOR - -/*! - \class QProxyScreenCursor - \since 4.5 - \ingroup qws - \brief The QProxyScreenCursor class provides a generic interface to - QScreenCursor implementations. -*/ - -/*! - Constructs a proxy screen cursor. -*/ -QProxyScreenCursor::QProxyScreenCursor() - : QScreenCursor(), realCursor(0), d_ptr(0) -{ -} - -/*! - Destroys the proxy screen cursor. -*/ -QProxyScreenCursor::~QProxyScreenCursor() -{ -} - -/*! - Sets the real screen cursor to be used for the proxy screen cursor to - the \a cursor specified. - - \sa screenCursor() -*/ -void QProxyScreenCursor::setScreenCursor(QScreenCursor *cursor) -{ - realCursor = cursor; - configure(); -} - -/*! - Returns the real screen cursor used by the proxy screen cursor. - - \sa setScreenCursor() -*/ -QScreenCursor* QProxyScreenCursor::screenCursor() const -{ - return realCursor; -} - -/*! - \reimp -*/ -void QProxyScreenCursor::set(const QImage &image, int hotx, int hoty) -{ - if (realCursor) { - hotspot = QPoint(hotx, hoty); - cursor = image; - size = image.size(); - realCursor->set(image, hotx, hoty); - } else { - QScreenCursor::set(image, hotx, hoty); - } -} - -/*! - \reimp -*/ -void QProxyScreenCursor::move(int x, int y) -{ - if (realCursor) { - pos = QPoint(x, y); - realCursor->move(x, y); - } else { - QScreenCursor::move(x, y); - } -} - -/*! - \reimp -*/ -void QProxyScreenCursor::show() -{ - if (realCursor) { - realCursor->show(); - enable = true; - } else { - QScreenCursor::show(); - } -} - -/*! - \reimp -*/ -void QProxyScreenCursor::hide() -{ - if (realCursor) { - realCursor->hide(); - enable = false; - } else { - QScreenCursor::hide(); - } -} - -/*! - \internal -*/ -void QProxyScreenCursor::configure() -{ - if (!realCursor) - return; - - cursor = realCursor->cursor; - size = realCursor->size; - pos = realCursor->pos; - hotspot = realCursor->hotspot; - enable = realCursor->enable; - hwaccel = realCursor->hwaccel; - supportsAlpha = realCursor->supportsAlpha; -} - -#endif // QT_NO_QWS_CURSOR - -/*! - \class QProxyScreen - \ingroup qws - \brief The QProxyScreen class provides a generic interface to QScreen implementations. -*/ - -/*! - \fn QProxyScreen::QProxyScreen(int displayId, ClassId classId) - - Constructs a proxy screen with the given \a displayId and \a classId. -*/ -QProxyScreen::QProxyScreen(int displayId, QScreen::ClassId classId) - : QScreen(displayId, classId), realScreen(0), d_ptr(0) -{ -} - -/*! - Destroys the proxy screen. -*/ -QProxyScreen::~QProxyScreen() -{ -} - -/*! - Sets the real \a screen to be used by the proxy screen. - - \sa screen() -*/ -void QProxyScreen::setScreen(QScreen *screen) -{ - realScreen = screen; - configure(); -} - -/*! - Returns the real screen used by the proxy screen. - - \sa setScreen() -*/ -QScreen* QProxyScreen::screen() const -{ - return realScreen; -} - - -/*! - \internal -*/ -void QProxyScreen::configure() -{ - if (!realScreen) - return; - - d = realScreen->depth(); - w = realScreen->width(); - h = realScreen->height(); - dw = realScreen->deviceWidth(); - dh = realScreen->deviceHeight(); - lstep = realScreen->linestep(); - data = realScreen->base(); - lstep = realScreen->linestep(); - size = realScreen->screenSize(); - physWidth = realScreen->physicalWidth(); - physHeight = realScreen->physicalHeight(); - pixeltype = realScreen->pixelType(); -#if Q_BYTE_ORDER == Q_BIG_ENDIAN - setFrameBufferLittleEndian(realScreen->frameBufferLittleEndian()); -#endif - - setOffset(realScreen->offset()); - setPixelFormat(realScreen->pixelFormat()); - -#ifdef QT_QWS_CLIENTBLIT - setSupportsBlitInClients(realScreen->supportsBlitInClients()); -#endif -} - -/*! - \internal - Returns the display ID that corresponds to the given \a spec. -*/ -static int getDisplayId(const QString &spec) -{ - QRegExp regexp(QLatin1String(":(\\d+)\\b")); - if (regexp.lastIndexIn(spec) != -1) { - const QString capture = regexp.cap(1); - return capture.toInt(); - } - return 0; -} - -/*! - \reimp -*/ -bool QProxyScreen::connect(const QString &displaySpec) -{ - const int id = getDisplayId(displaySpec); - realScreen = qt_get_screen(id, displaySpec.toLatin1().constData()); - configure(); - - return true; -} - -/*! - \reimp -*/ -void QProxyScreen::exposeRegion(QRegion r, int changing) -{ - if (!realScreen) { - QScreen::exposeRegion(r, changing); - return; - } - - realScreen->exposeRegion(r, changing); - r &= realScreen->region(); - - const QVector<QRect> rects = r.rects(); - for (int i = 0; i < rects.size(); ++i) - setDirty(rects.at(i)); -} - -/*! - \reimp -*/ -void QProxyScreen::blit(const QImage &image, const QPoint &topLeft, - const QRegion ®ion) -{ - if (!realScreen) { - QScreen::blit(image, topLeft, region); - return; - } - - realScreen->blit(image, topLeft, region); -} - -/*! - \reimp -*/ -void QProxyScreen::solidFill(const QColor &color, const QRegion ®ion) -{ - if (!realScreen) { - QScreen::solidFill(color, region); - return; - } - realScreen->solidFill(color, region); -} - -/*! - \reimp -*/ -QSize QProxyScreen::mapToDevice(const QSize &s) const -{ - if (!realScreen) - return QScreen::mapToDevice(s); - - return realScreen->mapToDevice(s); -} - -/*! - \reimp -*/ -QSize QProxyScreen::mapFromDevice(const QSize &s) const -{ - if (!realScreen) - return QScreen::mapFromDevice(s); - - return realScreen->mapFromDevice(s); -} - -/*! - \reimp -*/ -QPoint QProxyScreen::mapToDevice(const QPoint &p, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapToDevice(p, s); - - return realScreen->mapToDevice(p, s); -} - -/*! - \reimp -*/ -QPoint QProxyScreen::mapFromDevice(const QPoint &p, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapFromDevice(p, s); - - return realScreen->mapFromDevice(p, s); -} - -/*! - \reimp -*/ -QRect QProxyScreen::mapToDevice(const QRect &r, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapToDevice(r, s); - - return realScreen->mapToDevice(r, s); -} - -/*! - \reimp -*/ -QRect QProxyScreen::mapFromDevice(const QRect &r, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapFromDevice(r, s); - - return realScreen->mapFromDevice(r, s); -} - -/*! - \reimp -*/ -QRegion QProxyScreen::mapToDevice(const QRegion &r, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapToDevice(r, s); - - return realScreen->mapToDevice(r, s); -} - -/*! - \reimp -*/ -QRegion QProxyScreen::mapFromDevice(const QRegion &r, const QSize &s) const -{ - if (!realScreen) - return QScreen::mapFromDevice(r, s); - - return realScreen->mapFromDevice(r, s); -} - -/*! - \reimp -*/ -void QProxyScreen::disconnect() -{ - if (realScreen) { - realScreen->disconnect(); - delete realScreen; - realScreen = 0; - } -} - -/*! -*/ -bool QProxyScreen::initDevice() -{ - if (realScreen) - return realScreen->initDevice(); - - return false; -} - -/*! - \reimp -*/ -void QProxyScreen::shutdownDevice() -{ - if (realScreen) - realScreen->shutdownDevice(); -} - -/*! - \reimp -*/ -void QProxyScreen::setMode(int w,int h, int d) -{ - if (realScreen) { - realScreen->setMode(w, h, d); - } else { - QScreen::dw = QScreen::w = w; - QScreen::dh = QScreen::h = h; - QScreen::d = d; - } - configure(); - exposeRegion(region(), 0); -} - -/*! - \reimp -*/ -bool QProxyScreen::supportsDepth(int depth) const -{ - if (realScreen) - return realScreen->supportsDepth(depth); - return false; -} - -/*! - \reimp -*/ -void QProxyScreen::save() -{ - if (realScreen) - realScreen->save(); - QScreen::save(); -} - -/*! - \reimp -*/ -void QProxyScreen::restore() -{ - if (realScreen) - realScreen->restore(); - QScreen::restore(); -} - -/*! - \reimp -*/ -void QProxyScreen::blank(bool on) -{ - if (realScreen) - realScreen->blank(on); -} - -/*! - \reimp -*/ -bool QProxyScreen::onCard(const unsigned char *ptr) const -{ - if (realScreen) - return realScreen->onCard(ptr); - return false; -} - -/*! - \reimp -*/ -bool QProxyScreen::onCard(const unsigned char *ptr, ulong &offset) const -{ - if (realScreen) - return realScreen->onCard(ptr, offset); - return false; -} - -/*! - \reimp -*/ -bool QProxyScreen::isInterlaced() const -{ - if (realScreen) - return realScreen->isInterlaced(); - return false; -} - -/*! - \reimp -*/ -bool QProxyScreen::isTransformed() const -{ - if (realScreen) - return realScreen->isTransformed(); - return QScreen::isTransformed(); -} - -/*! - \reimp -*/ -int QProxyScreen::transformOrientation() const -{ - if (realScreen) - return realScreen->transformOrientation(); - return QScreen::transformOrientation(); -} - -/*! -\internal -*/ -int QProxyScreen::memoryNeeded(const QString &str) -{ - if (realScreen) - return realScreen->memoryNeeded(str); - else - return QScreen::memoryNeeded(str); -} - -/*! -\internal -*/ -int QProxyScreen::sharedRamSize(void *ptr) -{ - if (realScreen) - return realScreen->sharedRamSize(ptr); - else - return QScreen::sharedRamSize(ptr); -} - -/*! -\internal -*/ -void QProxyScreen::haltUpdates() -{ - if (realScreen) - realScreen->haltUpdates(); -} - -/*! -\internal -*/ -void QProxyScreen::resumeUpdates() -{ - if (realScreen) - realScreen->resumeUpdates(); -} - -/*! - \reimp -*/ -void QProxyScreen::setDirty(const QRect &rect) -{ - if (realScreen) - realScreen->setDirty(rect); -} - -/*! - \reimp -*/ -QWSWindowSurface* QProxyScreen::createSurface(QWidget *widget) const -{ - if (realScreen) - return realScreen->createSurface(widget); - - return QScreen::createSurface(widget); -} - -/*! - \reimp -*/ -QWSWindowSurface* QProxyScreen::createSurface(const QString &key) const -{ - if (realScreen) - return realScreen->createSurface(key); - - return QScreen::createSurface(key); -} - -/*! - \reimp -*/ -QList<QScreen*> QProxyScreen::subScreens() const -{ - if (realScreen) - return realScreen->subScreens(); - - return QScreen::subScreens(); -} - -/*! - \reimp -*/ -QRegion QProxyScreen::region() const -{ - if (realScreen) - return realScreen->region(); - else - return QScreen::region(); -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_PROXYSCREEN diff --git a/src/gui/embedded/qscreenproxy_qws.h b/src/gui/embedded/qscreenproxy_qws.h deleted file mode 100644 index bde36aa6bd..0000000000 --- a/src/gui/embedded/qscreenproxy_qws.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPROXYSCREEN_QWS_H -#define QPROXYSCREEN_QWS_H - -#include <QtGui/qscreen_qws.h> - -#ifndef QT_NO_QWS_PROXYSCREEN - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QProxyScreenPrivate; - -#ifndef QT_NO_QWS_CURSOR - -class QProxyScreenCursorPrivate; - -class Q_GUI_EXPORT QProxyScreenCursor : public QScreenCursor -{ -public: - QProxyScreenCursor(); - ~QProxyScreenCursor(); - - void setScreenCursor(QScreenCursor *cursor); - QScreenCursor* screenCursor() const; - - void set(const QImage &image, int hotx, int hoty); - void move(int x, int y); - void show(); - void hide(); - -private: - void configure(); - - QScreenCursor *realCursor; - QProxyScreenCursorPrivate *d_ptr; -}; - -#endif // QT_NO_QWS_CURSOR - -class Q_GUI_EXPORT QProxyScreen : public QScreen -{ -public: - QProxyScreen(int display_id, ClassId = ProxyClass); - ~QProxyScreen(); - - void setScreen(QScreen *screen); - QScreen *screen() const; - - QSize mapToDevice(const QSize &s) const; - QSize mapFromDevice(const QSize &s) const; - - QPoint mapToDevice(const QPoint &, const QSize &) const; - QPoint mapFromDevice(const QPoint &, const QSize &) const; - - QRect mapToDevice(const QRect &, const QSize &) const; - QRect mapFromDevice(const QRect &, const QSize &) const; - - QRegion mapToDevice(const QRegion &, const QSize &) const; - QRegion mapFromDevice(const QRegion &, const QSize &) const; - - bool connect(const QString &displaySpec); - bool initDevice(); - void shutdownDevice(); - void disconnect(); - - void setMode(int width, int height, int depth); - bool supportsDepth(int) const; - - void save(); - void restore(); - void blank(bool on); - - bool onCard(const unsigned char *) const; - bool onCard(const unsigned char *, ulong& out_offset) const; - - bool isInterlaced() const; - bool isTransformed() const; - int transformOrientation() const; - - int memoryNeeded(const QString&); - int sharedRamSize(void *); - - void haltUpdates(); - void resumeUpdates(); - - void exposeRegion(QRegion r, int changing); - void blit(const QImage &img, const QPoint &topLeft, const QRegion ®ion); - void solidFill(const QColor &color, const QRegion ®ion); - void setDirty(const QRect&); - - QWSWindowSurface* createSurface(QWidget *widget) const; - QWSWindowSurface* createSurface(const QString &key) const; - - QList<QScreen*> subScreens() const; - QRegion region() const; - -private: - void configure(); - - QScreen *realScreen; - QProxyScreenPrivate *d_ptr; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_QWS_PROXYSCREEN -#endif // QPROXYSCREEN_QWS_H diff --git a/src/gui/embedded/qscreenqnx_qws.cpp b/src/gui/embedded/qscreenqnx_qws.cpp deleted file mode 100644 index 7101a71d83..0000000000 --- a/src/gui/embedded/qscreenqnx_qws.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreenqnx_qws.h" -#include "qdebug.h" - -#include <gf/gf.h> - -QT_BEGIN_NAMESPACE - -// This struct holds all the pointers to QNX's internals -struct QQnxScreenContext -{ - inline QQnxScreenContext() - : device(0), display(0), layer(0), hwSurface(0), memSurface(0), context(0) - {} - - gf_dev_t device; - gf_dev_info_t deviceInfo; - gf_display_t display; - gf_display_info_t displayInfo; - gf_layer_t layer; - gf_surface_t hwSurface; - gf_surface_t memSurface; - gf_surface_info_t memSurfaceInfo; - gf_context_t context; -}; - -/*! - \class QQnxScreen - \preliminary - \ingroup qws - \since 4.6 - \internal - - \brief The QQnxScreen class implements a screen driver - for QNX io-display based devices. - - Note - you never have to instanciate this class, the QScreenDriverFactory - does that for us based on the \c{QWS_DISPLAY} environment variable. - - To activate this driver, set \c{QWS_DISPLAY} to \c{qnx}. - - Example: - \c{QWS_DISPLAY=qnx; export QWS_DISPLAY} - - By default, the main layer of the first display of the first device is used. - If you have multiple graphic cards, multiple displays or multiple layers and - don't want to connect to the default, you can override that with setting - the corresponding options \c{device}, \c{display} or \c{layer} in the \c{QWS_DISPLAY} variable: - - \c{QWS_DISPLAY=qnx:device=3:display=4:layer=5} - - In addition, it is suggested to set the physical width and height of the display. - QQnxScreen will use that information to compute the dots per inch (DPI) in order to render - fonts correctly. If this informaiton is omitted, QQnxScreen defaults to 72 dpi. - - \c{QWS_DISPLAY=qnx:mmWidth=120:mmHeight=80} - - \c{mmWidth} and \c{mmHeight} are the physical width/height of the screen in millimeters. - - \sa QScreen, QScreenDriverPlugin, {Running Qt for Embedded Linux Applications}{Running Applications} -*/ - -/*! - Constructs a QQnxScreen object. The \a display_id argument - identifies the Qt for Embedded Linux server to connect to. -*/ -QQnxScreen::QQnxScreen(int display_id) - : QScreen(display_id), d(new QQnxScreenContext) -{ -} - -/*! - Destroys this QQnxScreen object. -*/ -QQnxScreen::~QQnxScreen() -{ - delete d; -} - -/*! \reimp -*/ -bool QQnxScreen::initDevice() -{ - // implement this if you have multiple processes that want to access the display - // (not required if QT_NO_QWS_MULTIPROCESS is set) - return true; -} - -/*! \internal - Attaches to the named device \a name. -*/ -static bool attachDevice(QQnxScreenContext * const d, const char *name) -{ - int ret = gf_dev_attach(&d->device, name, &d->deviceInfo); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_dev_attach(%s) failed with error code %d", name, ret); - return false; - } - return true; -} - -/*! \internal - Attaches to the display at index \a displayIndex. - */ -static bool attachDisplay(QQnxScreenContext * const d, int displayIndex) -{ - int ret = gf_display_attach(&d->display, d->device, displayIndex, &d->displayInfo); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_display_attach(%d) failed with error code %d", - displayIndex, ret); - return false; - } - return true; -} - -/*! \internal - Attaches to the layer \a layerIndex. - */ -static bool attachLayer(QQnxScreenContext * const d, int layerIndex) -{ - int ret = gf_layer_attach(&d->layer, d->display, layerIndex, 0); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_layer_attach(%d) failed with error code %d", layerIndex, - ret); - return false; - } - gf_layer_enable(d->layer); - - return true; -} - -/*! \internal - Creates a new hardware surface (usually on the Gfx card memory) with the dimensions \a w * \a h. - */ -static bool createHwSurface(QQnxScreenContext * const d, int w, int h) -{ - int ret = gf_surface_create_layer(&d->hwSurface, &d->layer, 1, 0, - w, h, GF_FORMAT_ARGB8888, 0, 0); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_surface_create_layer(%dx%d) failed with error code %d", - w, h, ret); - return false; - } - - gf_layer_set_surfaces(d->layer, &d->hwSurface, 1); - - ret = gf_layer_update(d->layer, 0); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_layer_update() failed with error code %d\n", ret); - return false; - } - - return true; -} - -/*! \internal - Creates an in-memory, linear accessible surface of dimensions \a w * \a h. - This is the main surface that QWS blits to. - */ -static bool createMemSurface(QQnxScreenContext * const d, int w, int h) -{ - // Note: gf_surface_attach() could also be used, so we'll create the buffer - // and let the surface point to it. Here, we use surface_create instead. - - int ret = gf_surface_create(&d->memSurface, d->device, w, h, - GF_FORMAT_ARGB8888, 0, - GF_SURFACE_CREATE_CPU_FAST_ACCESS | GF_SURFACE_CREATE_CPU_LINEAR_ACCESSIBLE - | GF_SURFACE_PHYS_CONTIG | GF_SURFACE_CREATE_SHAREABLE); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_surface_create(%dx%d) failed with error code %d", - w, h, ret); - return false; - } - - gf_surface_get_info(d->memSurface, &d->memSurfaceInfo); - - if (d->memSurfaceInfo.sid == unsigned(GF_SID_INVALID)) { - qWarning("QQnxScreen: gf_surface_get_info() failed."); - return false; - } - - return true; -} - -/* \internal - Creates a QNX gf context and sets our memory surface on it. - */ -static bool createContext(QQnxScreenContext * const d) -{ - int ret = gf_context_create(&d->context); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_context_create() failed with error code %d", ret); - return false; - } - - ret = gf_context_set_surface(d->context, d->memSurface); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_context_set_surface() failed with error code %d", ret); - return false; - } - - return true; -} - -/*! \reimp - Connects to QNX's io-display based device based on the \a displaySpec parameters - from the \c{QWS_DISPLAY} environment variable. See the QQnxScreen class documentation - for possible parameters. - - \sa QQnxScreen - */ -bool QQnxScreen::connect(const QString &displaySpec) -{ - const QStringList params = displaySpec.split(QLatin1Char(':'), QString::SkipEmptyParts); - - bool isOk = false; - QRegExp deviceRegExp(QLatin1String("^device=(.+)$")); - if (params.indexOf(deviceRegExp) != -1) { - isOk = attachDevice(d, deviceRegExp.cap(1).toLocal8Bit().constData()); - } else { - // no device specified - attach to device 0 (the default) - isOk = attachDevice(d, GF_DEVICE_INDEX(0)); - } - - if (!isOk) - return false; - - qDebug("QQnxScreen: Attached to Device, number of displays: %d", d->deviceInfo.ndisplays); - - // default to display 0 - int displayIndex = 0; - QRegExp displayRegexp(QLatin1String("^display=(\\d+)$")); - if (params.indexOf(displayRegexp) != -1) { - displayIndex = displayRegexp.cap(1).toInt(); - } - - if (!attachDisplay(d, displayIndex)) - return false; - - qDebug("QQnxScreen: Attached to Display %d, resolution %dx%d, refresh %d Hz", - displayIndex, d->displayInfo.xres, d->displayInfo.yres, - d->displayInfo.refresh); - - - // default to main_layer_index from the displayInfo struct - int layerIndex = 0; - QRegExp layerRegexp(QLatin1String("^layer=(\\d+)$")); - if (params.indexOf(layerRegexp) != -1) { - layerIndex = layerRegexp.cap(1).toInt(); - } else { - layerIndex = d->displayInfo.main_layer_index; - } - - if (!attachLayer(d, layerIndex)) - return false; - - // tell QWSDisplay the width and height of the display - w = dw = d->displayInfo.xres; - h = dh = d->displayInfo.yres; - - // we only support 32 bit displays for now. - QScreen::d = 32; - - // assume 72 dpi as default, to calculate the physical dimensions if not specified - const int defaultDpi = 72; - - // Handle display physical size spec. - QRegExp mmWidthRegexp(QLatin1String("^mmWidth=(\\d+)$")); - if (params.indexOf(mmWidthRegexp) == -1) { - physWidth = qRound(dw * 25.4 / defaultDpi); - } else { - physWidth = mmWidthRegexp.cap(1).toInt(); - } - - QRegExp mmHeightRegexp(QLatin1String("^mmHeight=(\\d+)$")); - if (params.indexOf(mmHeightRegexp) == -1) { - physHeight = qRound(dh * 25.4 / defaultDpi); - } else { - physHeight = mmHeightRegexp.cap(1).toInt(); - } - - // create a hardware surface with our dimensions. In the old days, it was possible - // to get a pointer directly to the hw surface, so we could blit directly. Now, we - // have to use one indirection more, because it's not guaranteed that the hw surface - // is mappable into our process. - if (!createHwSurface(d, w, h)) - return false; - - // create an in-memory linear surface that is used by QWS. QWS will blit directly in here. - if (!createMemSurface(d, w, h)) - return false; - - // set the address of the in-memory buffer that QWS is blitting to - data = d->memSurfaceInfo.vaddr; - // set the line stepping - lstep = d->memSurfaceInfo.stride; - - // the overall size of the in-memory buffer is linestep * height - size = mapsize = lstep * h; - - // create a QNX drawing context - if (!createContext(d)) - return false; - - // we're always using a software cursor for now. Initialize it here. - QScreenCursor::initSoftwareCursor(); - - // done, the driver should be connected to the display now. - return true; -} - -/*! \reimp - */ -void QQnxScreen::disconnect() -{ - if (d->context) - gf_context_free(d->context); - - if (d->memSurface) - gf_surface_free(d->memSurface); - - if (d->hwSurface) - gf_surface_free(d->hwSurface); - - if (d->layer) - gf_layer_detach(d->layer); - - if (d->display) - gf_display_detach(d->display); - - if (d->device) - gf_dev_detach(d->device); - - d->memSurface = 0; - d->hwSurface = 0; - d->context = 0; - d->layer = 0; - d->display = 0; - d->device = 0; -} - -/*! \reimp - */ -void QQnxScreen::shutdownDevice() -{ -} - - -/*! \reimp - QQnxScreen doesn't support setting the mode, use io-display instead. - */ -void QQnxScreen::setMode(int,int,int) -{ - qWarning("QQnxScreen: Unable to change mode, use io-display instead."); -} - -/*! \reimp - */ -bool QQnxScreen::supportsDepth(int depth) const -{ - // only 32-bit for the moment - return depth == 32; -} - -/*! \reimp - */ -void QQnxScreen::exposeRegion(QRegion r, int changing) -{ - // here is where the actual magic happens. QWS will call exposeRegion whenever - // a region on the screen is dirty and needs to be updated on the actual screen. - - // first, call the parent implementation. The parent implementation will update - // the region on our in-memory surface - QScreen::exposeRegion(r, changing); - - // now our in-memory surface should be up to date with the latest changes. - // the code below copies the region from the in-memory surface to the hardware. - - // just get the bounding rectangle of the region. Most screen updates are rectangular - // anyways. Code could be optimized to blit each and every member of the region - // individually, but in real life, the speed-up is neglectable - const QRect br = r.boundingRect(); - if (br.isEmpty()) - return; // ignore empty regions because gf_draw_blit2 doesn't like 0x0 dimensions - - // start drawing. - int ret = gf_draw_begin(d->context); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_draw_begin() failed with error code %d", ret); - return; - } - - // blit the changed region from the memory surface to the hardware surface - ret = gf_draw_blit2(d->context, d->memSurface, d->hwSurface, - br.x(), br.y(), br.right(), br.bottom(), br.x(), br.y()); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_draw_blit2() failed with error code %d", ret); - } - - // flush all drawing commands (in our case, a single blit) - ret = gf_draw_flush(d->context); - if (ret != GF_ERR_OK) { - qWarning("QQnxScreen: gf_draw_flush() failed with error code %d", ret); - } - - // tell QNX that we're done drawing. - gf_draw_end(d->context); -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qscreenqnx_qws.h b/src/gui/embedded/qscreenqnx_qws.h deleted file mode 100644 index 35915ae794..0000000000 --- a/src/gui/embedded/qscreenqnx_qws.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENQNX_QWS_H -#define QSCREENQNX_QWS_H - -#include <QtGui/qscreen_qws.h> - -#ifndef QT_NO_QWS_QNX - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -struct QQnxScreenContext; - -class QQnxScreen : public QScreen -{ -public: - explicit QQnxScreen(int display_id); - ~QQnxScreen(); - - bool initDevice(); - bool connect(const QString &displaySpec); - void disconnect(); - void shutdownDevice(); - void setMode(int,int,int); - bool supportsDepth(int) const; - - void exposeRegion(QRegion r, int changing); - -private: - QQnxScreenContext * const d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_QWS_QNX - -#endif diff --git a/src/gui/embedded/qscreentransformed_qws.cpp b/src/gui/embedded/qscreentransformed_qws.cpp deleted file mode 100644 index f37ab8084b..0000000000 --- a/src/gui/embedded/qscreentransformed_qws.cpp +++ /dev/null @@ -1,748 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qscreentransformed_qws.h" - -#ifndef QT_NO_QWS_TRANSFORMED -#include <qscreendriverfactory_qws.h> -#include <qvector.h> -#include <private/qpainter_p.h> -#include <private/qmemrotate_p.h> -#include <qmatrix.h> - -#include <unistd.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <errno.h> - -#include <qwindowsystem_qws.h> -#include <qwsdisplay_qws.h> - -QT_BEGIN_NAMESPACE - -//#define QT_REGION_DEBUG - -#ifdef QT_REGION_DEBUG -#include <QDebug> -#endif - -class QTransformedScreenPrivate -{ -public: - QTransformedScreenPrivate(QTransformedScreen *parent); - - void configure(); - - QTransformedScreen::Transformation transformation; -#ifdef QT_QWS_DEPTH_GENERIC - bool doGenericColors; -#endif - QTransformedScreen *q; -}; - -QTransformedScreenPrivate::QTransformedScreenPrivate(QTransformedScreen *parent) - : transformation(QTransformedScreen::None), -#ifdef QT_QWS_DEPTH_GENERIC - doGenericColors(false), -#endif - q(parent) -{ -} - -extern "C" -#ifndef QT_BUILD_GUI_LIB -Q_DECL_EXPORT -#endif -void qws_setScreenTransformation(QScreen *that, int t) -{ - QTransformedScreen *tscreen = static_cast<QTransformedScreen*>(that); - tscreen->setTransformation((QTransformedScreen::Transformation)t); -} - -// --------------------------------------------------------------------------- -// Transformed Screen -// --------------------------------------------------------------------------- - -/*! - \internal - - \class QTransformedScreen - \ingroup qws - - \brief The QTransformedScreen class implements a screen driver for - a transformed screen. - - Note that this class is only available in \l{Qt for Embedded Linux}. - Custom screen drivers can be added by subclassing the - QScreenDriverPlugin class, using the QScreenDriverFactory class to - dynamically load the driver into the application, but there should - only be one screen object per application. - - Use the QScreen::isTransformed() function to determine if a screen - is transformed. The QTransformedScreen class itself provides means - of rotating the screen with its setTransformation() function; the - transformation() function returns the currently set rotation in - terms of the \l Transformation enum (which describes the various - available rotation settings). Alternatively, QTransformedScreen - provides an implementation of the QScreen::transformOrientation() - function, returning the current rotation as an integer value. - - \sa QScreen, QScreenDriverPlugin, {Running Applications} -*/ - -/*! - \enum QTransformedScreen::Transformation - - This enum describes the various rotations a transformed screen can - have. - - \value None No rotation - \value Rot90 90 degrees rotation - \value Rot180 180 degrees rotation - \value Rot270 270 degrees rotation -*/ - -/*! - \fn bool QTransformedScreen::isTransformed() const - \reimp -*/ - -/*! - Constructs a QTransformedScreen object. The \a displayId argument - identifies the Qt for Embedded Linux server to connect to. -*/ -QTransformedScreen::QTransformedScreen(int displayId) - : QProxyScreen(displayId, QScreen::TransformedClass) -{ - d_ptr = new QTransformedScreenPrivate(this); - d_ptr->transformation = None; - -#ifdef QT_REGION_DEBUG - qDebug() << "QTransformedScreen::QTransformedScreen"; -#endif -} - -void QTransformedScreenPrivate::configure() -{ - // ###: works because setTransformation recalculates unconditionally - q->setTransformation(transformation); -} - -/*! - Destroys the QTransformedScreen object. -*/ -QTransformedScreen::~QTransformedScreen() -{ - delete d_ptr; -} - -static int getDisplayId(const QString &spec) -{ - QRegExp regexp(QLatin1String(":(\\d+)\\b")); - if (regexp.lastIndexIn(spec) != -1) { - const QString capture = regexp.cap(1); - return capture.toInt(); - } - return 0; -} - -static QTransformedScreen::Transformation filterTransformation(QString &spec) -{ - QRegExp regexp(QLatin1String("\\bRot(\\d+):?\\b"), Qt::CaseInsensitive); - if (regexp.indexIn(spec) == -1) - return QTransformedScreen::None; - - const int degrees = regexp.cap(1).toInt(); - spec.remove(regexp.pos(0), regexp.matchedLength()); - - return static_cast<QTransformedScreen::Transformation>(degrees / 90); -} - -/*! - \reimp -*/ -bool QTransformedScreen::connect(const QString &displaySpec) -{ - QString dspec = displaySpec.trimmed(); - if (dspec.startsWith(QLatin1String("Transformed:"), Qt::CaseInsensitive)) - dspec = dspec.mid(QString::fromLatin1("Transformed:").size()); - else if (!dspec.compare(QLatin1String("Transformed"), Qt::CaseInsensitive)) - dspec = QString(); - - const QString displayIdSpec = QString::fromLatin1(" :%1").arg(displayId); - if (dspec.endsWith(displayIdSpec)) - dspec = dspec.left(dspec.size() - displayIdSpec.size()); - - d_ptr->transformation = filterTransformation(dspec); - - QString driver = dspec; - int colon = driver.indexOf(QLatin1Char(':')); - if (colon >= 0) - driver.truncate(colon); - - if (!QScreenDriverFactory::keys().contains(driver, Qt::CaseInsensitive)) - if (!dspec.isEmpty()) - dspec.prepend(QLatin1Char(':')); - - const int id = getDisplayId(dspec); - QScreen *s = qt_get_screen(id, dspec.toLatin1().constData()); - setScreen(s); - -#ifdef QT_QWS_DEPTH_GENERIC - d_ptr->doGenericColors = dspec.contains(QLatin1String("genericcolors")); -#endif - - d_ptr->configure(); - - // XXX - qt_screen = this; - - return true; -} - -/*! - Returns the currently set rotation. - - \sa setTransformation(), QScreen::transformOrientation() -*/ -QTransformedScreen::Transformation QTransformedScreen::transformation() const -{ - return d_ptr->transformation; -} - -/*! - \reimp -*/ -int QTransformedScreen::transformOrientation() const -{ - return (int)d_ptr->transformation; -} - -/*! - \reimp -*/ -void QTransformedScreen::exposeRegion(QRegion region, int changing) -{ - if (!data || d_ptr->transformation == None) { - QProxyScreen::exposeRegion(region, changing); - return; - } - QScreen::exposeRegion(region, changing); -} - -/*! - Rotates this screen object according to the specified \a transformation. - - \sa transformation() -*/ -void QTransformedScreen::setTransformation(Transformation transformation) -{ - d_ptr->transformation = transformation; - QSize size = mapFromDevice(QSize(dw, dh)); - w = size.width(); - h = size.height(); - - const QScreen *s = screen(); - size = mapFromDevice(QSize(s->physicalWidth(), s->physicalHeight())); - physWidth = size.width(); - physHeight = size.height(); - -#ifdef QT_REGION_DEBUG - qDebug() << "QTransformedScreen::setTransformation" << transformation - << "size" << w << h << "dev size" << dw << dh; -#endif - -} - -static inline QRect correctNormalized(const QRect &r) { - const int x1 = qMin(r.left(), r.right()); - const int x2 = qMax(r.left(), r.right()); - const int y1 = qMin(r.top(), r.bottom()); - const int y2 = qMax(r.top(), r.bottom()); - - return QRect( QPoint(x1,y1), QPoint(x2,y2) ); -} - -template <class DST, class SRC> -static inline void blit90(QScreen *screen, const QImage &image, - const QRect &rect, const QPoint &topLeft) -{ - const SRC *src = (const SRC*)(image.scanLine(rect.top())) + rect.left(); - DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep()) - + topLeft.x(); - qt_memrotate90(src, rect.width(), rect.height(), image.bytesPerLine(), - dest, screen->linestep()); -} - -template <class DST, class SRC> -static inline void blit180(QScreen *screen, const QImage &image, - const QRect &rect, const QPoint &topLeft) -{ - const SRC *src = (const SRC*)(image.scanLine(rect.top())) + rect.left(); - DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep()) - + topLeft.x(); - qt_memrotate180(src, rect.width(), rect.height(), image.bytesPerLine(), - dest, screen->linestep()); -} - -template <class DST, class SRC> -static inline void blit270(QScreen *screen, const QImage &image, - const QRect &rect, const QPoint &topLeft) -{ - const SRC *src = (const SRC *)(image.scanLine(rect.top())) + rect.left(); - DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep()) - + topLeft.x(); - qt_memrotate270(src, rect.width(), rect.height(), image.bytesPerLine(), - dest, screen->linestep()); -} - -typedef void (*BlitFunc)(QScreen *, const QImage &, const QRect &, const QPoint &); - -#define SET_BLIT_FUNC(dst, src, rotation, func) \ -do { \ - switch (rotation) { \ - case Rot90: \ - func = blit90<dst, src>; \ - break; \ - case Rot180: \ - func = blit180<dst, src>; \ - break; \ - case Rot270: \ - func = blit270<dst, src>; \ - break; \ - default: \ - break; \ - } \ -} while (0) - -/*! - \reimp -*/ -void QTransformedScreen::blit(const QImage &image, const QPoint &topLeft, - const QRegion ®ion) -{ - const Transformation trans = d_ptr->transformation; - if (trans == None) { - QProxyScreen::blit(image, topLeft, region); - return; - } - - const QVector<QRect> rects = region.rects(); - const QRect bound = QRect(0, 0, QScreen::w, QScreen::h) - & QRect(topLeft, image.size()); - - BlitFunc func = 0; -#ifdef QT_QWS_DEPTH_GENERIC - if (d_ptr->doGenericColors && depth() == 16) { - if (image.depth() == 16) - SET_BLIT_FUNC(qrgb_generic16, quint16, trans, func); - else - SET_BLIT_FUNC(qrgb_generic16, quint32, trans, func); - } else -#endif - switch (depth()) { -#ifdef QT_QWS_DEPTH_32 - case 32: -#ifdef QT_QWS_DEPTH_16 - if (image.depth() == 16) - SET_BLIT_FUNC(quint32, quint16, trans, func); - else -#endif - SET_BLIT_FUNC(quint32, quint32, trans, func); - break; -#endif -#if defined(QT_QWS_DEPTH_24) || defined(QT_QWS_DEPTH18) - case 24: - case 18: - SET_BLIT_FUNC(quint24, quint24, trans, func); - break; -#endif -#if defined(QT_QWS_DEPTH_16) || defined(QT_QWS_DEPTH_15) || defined(QT_QWS_DEPTH_12) - case 16: -#if defined QT_QWS_ROTATE_BGR - if (pixelType() == BGRPixel && image.depth() == 16) { - SET_BLIT_FUNC(qbgr565, quint16, trans, func); - break; - } //fall-through here!!! -#endif - case 15: -#if defined QT_QWS_ROTATE_BGR - if (pixelType() == BGRPixel && image.format() == QImage::Format_RGB555) { - SET_BLIT_FUNC(qbgr555, qrgb555, trans, func); - break; - } //fall-through here!!! -#endif - case 12: - if (image.depth() == 16) - SET_BLIT_FUNC(quint16, quint16, trans, func); - else - SET_BLIT_FUNC(quint16, quint32, trans, func); - break; -#endif -#ifdef QT_QWS_DEPTH_8 - case 8: - if (image.format() == QImage::Format_RGB444) - SET_BLIT_FUNC(quint8, qrgb444, trans, func); - else if (image.depth() == 16) - SET_BLIT_FUNC(quint8, quint16, trans, func); - else - SET_BLIT_FUNC(quint8, quint32, trans, func); - break; -#endif - default: - return; - } - if (!func) - return; - - QWSDisplay::grab(); - for (int i = 0; i < rects.size(); ++i) { - const QRect r = rects.at(i) & bound; - - QPoint dst; - switch (trans) { - case Rot90: - dst = mapToDevice(r.topRight(), QSize(w, h)); - break; - case Rot180: - dst = mapToDevice(r.bottomRight(), QSize(w, h)); - break; - case Rot270: - dst = mapToDevice(r.bottomLeft(), QSize(w, h)); - break; - default: - break; - } - func(this, image, r.translated(-topLeft), dst); - } - QWSDisplay::ungrab(); - -} - -/*! - \reimp -*/ -void QTransformedScreen::solidFill(const QColor &color, const QRegion ®ion) -{ - const QRegion tr = mapToDevice(region, QSize(w,h)); - - Q_ASSERT(tr.boundingRect() == mapToDevice(region.boundingRect(), QSize(w,h))); - -#ifdef QT_REGION_DEBUG - qDebug() << "QTransformedScreen::solidFill region" << region << "transformed" << tr; -#endif - QProxyScreen::solidFill(color, tr); -} - -/*! - \reimp -*/ -QSize QTransformedScreen::mapToDevice(const QSize &s) const -{ - switch (d_ptr->transformation) { - case None: - case Rot180: - break; - case Rot90: - case Rot270: - return QSize(s.height(), s.width()); - break; - } - return s; -} - -/*! - \reimp -*/ -QSize QTransformedScreen::mapFromDevice(const QSize &s) const -{ - switch (d_ptr->transformation) { - case None: - case Rot180: - break; - case Rot90: - case Rot270: - return QSize(s.height(), s.width()); - break; - } - return s; -} - -/*! - \reimp -*/ -QPoint QTransformedScreen::mapToDevice(const QPoint &p, const QSize &s) const -{ - QPoint rp(p); - - switch (d_ptr->transformation) { - case None: - break; - case Rot90: - rp.setX(p.y()); - rp.setY(s.width() - p.x() - 1); - break; - case Rot180: - rp.setX(s.width() - p.x() - 1); - rp.setY(s.height() - p.y() - 1); - break; - case Rot270: - rp.setX(s.height() - p.y() - 1); - rp.setY(p.x()); - break; - } - - return rp; -} - -/*! - \reimp -*/ -QPoint QTransformedScreen::mapFromDevice(const QPoint &p, const QSize &s) const -{ - QPoint rp(p); - - switch (d_ptr->transformation) { - case None: - break; - case Rot90: - rp.setX(s.height() - p.y() - 1); - rp.setY(p.x()); - break; - case Rot180: - rp.setX(s.width() - p.x() - 1); - rp.setY(s.height() - p.y() - 1); - break; - case Rot270: - rp.setX(p.y()); - rp.setY(s.width() - p.x() - 1); - break; - } - - return rp; -} - -/*! - \reimp -*/ -QRect QTransformedScreen::mapToDevice(const QRect &r, const QSize &s) const -{ - if (r.isNull()) - return QRect(); - - QRect tr; - switch (d_ptr->transformation) { - case None: - tr = r; - break; - case Rot90: - tr.setCoords(r.y(), s.width() - r.x() - 1, - r.bottom(), s.width() - r.right() - 1); - break; - case Rot180: - tr.setCoords(s.width() - r.x() - 1, s.height() - r.y() - 1, - s.width() - r.right() - 1, s.height() - r.bottom() - 1); - break; - case Rot270: - tr.setCoords(s.height() - r.y() - 1, r.x(), - s.height() - r.bottom() - 1, r.right()); - break; - } - - return correctNormalized(tr); -} - -/*! - \reimp -*/ -QRect QTransformedScreen::mapFromDevice(const QRect &r, const QSize &s) const -{ - if (r.isNull()) - return QRect(); - - QRect tr; - switch (d_ptr->transformation) { - case None: - tr = r; - break; - case Rot90: - tr.setCoords(s.height() - r.y() - 1, r.x(), - s.height() - r.bottom() - 1, r.right()); - break; - case Rot180: - tr.setCoords(s.width() - r.x() - 1, s.height() - r.y() - 1, - s.width() - r.right() - 1, s.height() - r.bottom() - 1); - break; - case Rot270: - tr.setCoords(r.y(), s.width() - r.x() - 1, - r.bottom(), s.width() - r.right() - 1); - break; - } - - return correctNormalized(tr); -} - -/*! - \reimp -*/ -QRegion QTransformedScreen::mapToDevice(const QRegion &rgn, const QSize &s) const -{ - if (d_ptr->transformation == None) - return QProxyScreen::mapToDevice(rgn, s); - -#ifdef QT_REGION_DEBUG - qDebug() << "mapToDevice size" << s << "rgn: " << rgn; -#endif - QRect tr; - QRegion trgn; - QVector<QRect> a = rgn.rects(); - const QRect *r = a.data(); - - int w = s.width(); - int h = s.height(); - int size = a.size(); - - switch (d_ptr->transformation) { - case None: - break; - case Rot90: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(r->y(), w - r->x() - 1, - r->bottom(), w - r->right() - 1); - trgn |= correctNormalized(tr); - } - break; - case Rot180: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(w - r->x() - 1, h - r->y() - 1, - w - r->right() - 1, h - r->bottom() - 1); - trgn |= correctNormalized(tr); - } - break; - case Rot270: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(h - r->y() - 1, r->x(), - h - r->bottom() - 1, r->right()); - trgn |= correctNormalized(tr); - } - break; - } -#ifdef QT_REGION_DEBUG - qDebug() << "mapToDevice trgn: " << trgn; -#endif - return trgn; -} - -/*! - \reimp -*/ -QRegion QTransformedScreen::mapFromDevice(const QRegion &rgn, const QSize &s) const -{ - if (d_ptr->transformation == None) - return QProxyScreen::mapFromDevice(rgn, s); - -#ifdef QT_REGION_DEBUG - qDebug() << "fromDevice: realRegion count: " << rgn.rects().size() << " isEmpty? " << rgn.isEmpty() << " bounds:" << rgn.boundingRect(); -#endif - QRect tr; - QRegion trgn; - QVector<QRect> a = rgn.rects(); - const QRect *r = a.data(); - - int w = s.width(); - int h = s.height(); - int size = a.size(); - - switch (d_ptr->transformation) { - case None: - break; - case Rot90: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(h - r->y() - 1, r->x(), - h - r->bottom() - 1, r->right()); - trgn |= correctNormalized(tr); - } - break; - case Rot180: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(w - r->x() - 1, h - r->y() - 1, - w - r->right() - 1, h - r->bottom() - 1); - trgn |= correctNormalized(tr); - } - break; - case Rot270: - for (int i = 0; i < size; i++, r++) { - tr.setCoords(r->y(), w - r->x() - 1, - r->bottom(), w - r->right() - 1); - trgn |= correctNormalized(tr); - } - break; - } -#ifdef QT_REGION_DEBUG - qDebug() << "fromDevice: transRegion count: " << trgn.rects().size() << " isEmpty? " << trgn.isEmpty() << " bounds:" << trgn.boundingRect(); -#endif - return trgn; -} - -/*! - \reimp -*/ -void QTransformedScreen::setDirty(const QRect& rect) -{ - const QRect r = mapToDevice(rect, QSize(width(), height())); - QProxyScreen::setDirty(r); -} - -/*! - \reimp -*/ -QRegion QTransformedScreen::region() const -{ - QRegion deviceRegion = QProxyScreen::region(); - return mapFromDevice(deviceRegion, QSize(deviceWidth(), deviceHeight())); -} - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_TRANSFORMED diff --git a/src/gui/embedded/qscreentransformed_qws.h b/src/gui/embedded/qscreentransformed_qws.h deleted file mode 100644 index 70f5063387..0000000000 --- a/src/gui/embedded/qscreentransformed_qws.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENTRANSFORMED_QWS_H -#define QSCREENTRANSFORMED_QWS_H - -#include <QtGui/qscreenproxy_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_TRANSFORMED - -class QTransformedScreenPrivate; - -class Q_AUTOTEST_EXPORT QTransformedScreen : public QProxyScreen -{ -public: - explicit QTransformedScreen(int display_id); - ~QTransformedScreen(); - - enum Transformation { None, Rot90, Rot180, Rot270 }; - - void setTransformation(Transformation t); - Transformation transformation() const; - int transformOrientation() const; - - QSize mapToDevice(const QSize &s) const; - QSize mapFromDevice(const QSize &s) const; - - QPoint mapToDevice(const QPoint &, const QSize &) const; - QPoint mapFromDevice(const QPoint &, const QSize &) const; - - QRect mapToDevice(const QRect &, const QSize &) const; - QRect mapFromDevice(const QRect &, const QSize &) const; - - QRegion mapToDevice(const QRegion &, const QSize &) const; - QRegion mapFromDevice(const QRegion &, const QSize &) const; - - bool connect(const QString &displaySpec); - - bool isTransformed() const { return transformation() != None; } - - void exposeRegion(QRegion region, int changing); - void blit(const QImage &img, const QPoint &topLeft, const QRegion ®ion); - void solidFill(const QColor &color, const QRegion ®ion); - void setDirty(const QRect&); - - QRegion region() const; - -private: - friend class QTransformedScreenPrivate; - QTransformedScreenPrivate *d_ptr; -}; - -#endif // QT_NO_QWS_TRANSFORMED - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENTRANSFORMED_QWS_H diff --git a/src/gui/embedded/qscreenvfb_qws.cpp b/src/gui/embedded/qscreenvfb_qws.cpp deleted file mode 100644 index 1c8829d500..0000000000 --- a/src/gui/embedded/qscreenvfb_qws.cpp +++ /dev/null @@ -1,445 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_QWS_QVFB - -#define QTOPIA_QVFB_BRIGHTNESS - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <qvfbhdr.h> -#include <qscreenvfb_qws.h> -#include <qkbdvfb_qws.h> -#include <qmousevfb_qws.h> -#include <qwindowsystem_qws.h> -#include <qsocketnotifier.h> -#include <qapplication.h> -#include <qscreen_qws.h> -#include <qmousedriverfactory_qws.h> -#include <qkbddriverfactory_qws.h> -#include <qdebug.h> - -QT_BEGIN_NAMESPACE - -class QVFbScreenPrivate -{ -public: - QVFbScreenPrivate(); - ~QVFbScreenPrivate(); - - bool success; - unsigned char *shmrgn; - int brightness; - bool blank; - QVFbHeader *hdr; - QWSMouseHandler *mouse; -#ifndef QT_NO_QWS_KEYBOARD - QWSKeyboardHandler *keyboard; -#endif -}; - -QVFbScreenPrivate::QVFbScreenPrivate() - : mouse(0) - -{ -#ifndef QT_NO_QWS_KEYBOARD - keyboard = 0; -#endif - brightness = 255; - blank = false; -} - -QVFbScreenPrivate::~QVFbScreenPrivate() -{ - delete mouse; -#ifndef QT_NO_QWS_KEYBOARD - delete keyboard; -#endif -} - -/*! - \internal - - \class QVFbScreen - \ingroup qws - - \brief The QVFbScreen class implements a screen driver for the - virtual framebuffer. - - Note that this class is only available in \l{Qt for Embedded Linux}. - Custom screen drivers can be added by subclassing the - QScreenDriverPlugin class, using the QScreenDriverFactory class to - dynamically load the driver into the application, but there should - only be one screen object per application. - - The Qt for Embedded Linux platform provides a \l{The Virtual - Framebuffer}{virtual framebuffer} for development and debugging; - the virtual framebuffer allows Qt for Embedded Linux applications to be - developed on a desktop machine, without switching between consoles - and X11. - - \sa QScreen, QScreenDriverPlugin, {Running Applications} -*/ - -/*! - \fn bool QVFbScreen::connect(const QString & displaySpec) - \reimp -*/ - -/*! - \fn void QVFbScreen::disconnect() - \reimp -*/ - -/*! - \fn bool QVFbScreen::initDevice() - \reimp -*/ - -/*! - \fn void QVFbScreen::restore() - \reimp -*/ - -/*! - \fn void QVFbScreen::save() - \reimp -*/ - -/*! - \fn void QVFbScreen::setDirty(const QRect & r) - \reimp -*/ - -/*! - \fn void QVFbScreen::setMode(int nw, int nh, int nd) - \reimp -*/ - -/*! - \fn void QVFbScreen::shutdownDevice() - \reimp -*/ - -/*! - \fn QVFbScreen::QVFbScreen(int displayId) - - Constructs a QVNCScreen object. The \a displayId argument - identifies the Qt for Embedded Linux server to connect to. -*/ -QVFbScreen::QVFbScreen(int display_id) - : QScreen(display_id, VFbClass), d_ptr(new QVFbScreenPrivate) -{ - d_ptr->shmrgn = 0; - d_ptr->hdr = 0; - data = 0; -} - -/*! - Destroys this QVFbScreen object. -*/ -QVFbScreen::~QVFbScreen() -{ - delete d_ptr; -} - -static QVFbScreen *connected = 0; - -bool QVFbScreen::connect(const QString &displaySpec) -{ - QStringList displayArgs = displaySpec.split(QLatin1Char(':')); - if (displayArgs.contains(QLatin1String("Gray"))) - grayscale = true; - - key_t key = ftok(QT_VFB_MOUSE_PIPE(displayId).toLocal8Bit(), 'b'); - - if (key == -1) - return false; - -#if Q_BYTE_ORDER == Q_BIG_ENDIAN -#ifndef QT_QWS_FRAMEBUFFER_LITTLE_ENDIAN - if (displayArgs.contains(QLatin1String("littleendian"))) -#endif - QScreen::setFrameBufferLittleEndian(true); -#endif - - int shmId = shmget(key, 0, 0); - if (shmId != -1) - d_ptr->shmrgn = (unsigned char *)shmat(shmId, 0, 0); - else - return false; - - if ((long)d_ptr->shmrgn == -1 || d_ptr->shmrgn == 0) { - qDebug("No shmrgn %ld", (long)d_ptr->shmrgn); - return false; - } - - d_ptr->hdr = (QVFbHeader *)d_ptr->shmrgn; - data = d_ptr->shmrgn + d_ptr->hdr->dataoffset; - - dw = w = d_ptr->hdr->width; - dh = h = d_ptr->hdr->height; - d = d_ptr->hdr->depth; - - switch (d) { - case 1: - setPixelFormat(QImage::Format_Mono); - break; - case 8: - setPixelFormat(QImage::Format_Indexed8); - break; - case 12: - setPixelFormat(QImage::Format_RGB444); - break; - case 15: - setPixelFormat(QImage::Format_RGB555); - break; - case 16: - setPixelFormat(QImage::Format_RGB16); - break; - case 18: - setPixelFormat(QImage::Format_RGB666); - break; - case 24: - setPixelFormat(QImage::Format_RGB888); - break; - case 32: - setPixelFormat(QImage::Format_ARGB32_Premultiplied); - break; - } - - lstep = d_ptr->hdr->linestep; - - // Handle display physical size spec. - int dimIdxW = -1; - int dimIdxH = -1; - for (int i = 0; i < displayArgs.size(); ++i) { - if (displayArgs.at(i).startsWith(QLatin1String("mmWidth"))) { - dimIdxW = i; - break; - } - } - for (int i = 0; i < displayArgs.size(); ++i) { - if (displayArgs.at(i).startsWith(QLatin1String("mmHeight"))) { - dimIdxH = i; - break; - } - } - if (dimIdxW >= 0) { - bool ok; - int pos = 7; - if (displayArgs.at(dimIdxW).at(pos) == QLatin1Char('=')) - ++pos; - int pw = displayArgs.at(dimIdxW).mid(pos).toInt(&ok); - if (ok) { - physWidth = pw; - if (dimIdxH < 0) - physHeight = dh*physWidth/dw; - } - } - if (dimIdxH >= 0) { - bool ok; - int pos = 8; - if (displayArgs.at(dimIdxH).at(pos) == QLatin1Char('=')) - ++pos; - int ph = displayArgs.at(dimIdxH).mid(pos).toInt(&ok); - if (ok) { - physHeight = ph; - if (dimIdxW < 0) - physWidth = dw*physHeight/dh; - } - } - if (dimIdxW < 0 && dimIdxH < 0) { - const int dpi = 72; - physWidth = qRound(dw * 25.4 / dpi); - physHeight = qRound(dh * 25.4 / dpi); - } - - qDebug("Connected to VFB server %s: %d x %d x %d %dx%dmm (%dx%ddpi)", displaySpec.toLatin1().data(), - w, h, d, physWidth, physHeight, qRound(dw*25.4/physWidth), qRound(dh*25.4/physHeight) ); - - size = lstep * h; - mapsize = size; - screencols = d_ptr->hdr->numcols; - memcpy(screenclut, d_ptr->hdr->clut, sizeof(QRgb) * screencols); - - connected = this; - - if (qgetenv("QT_QVFB_BGR").toInt()) - pixeltype = BGRPixel; - - return true; -} - -void QVFbScreen::disconnect() -{ - connected = 0; - if ((long)d_ptr->shmrgn != -1 && d_ptr->shmrgn) { - if (qApp->type() == QApplication::GuiServer && d_ptr->hdr->dataoffset >= (int)sizeof(QVFbHeader)) { - d_ptr->hdr->serverVersion = 0; - } - shmdt((char*)d_ptr->shmrgn); - } -} - -bool QVFbScreen::initDevice() -{ -#ifndef QT_NO_QWS_MOUSE_QVFB - const QString mouseDev = QT_VFB_MOUSE_PIPE(displayId); - d_ptr->mouse = new QVFbMouseHandler(QLatin1String("QVFbMouse"), mouseDev); - qwsServer->setDefaultMouse("None"); - if (d_ptr->mouse) - d_ptr->mouse->setScreen(this); -#endif - -#if !defined(QT_NO_QWS_KBD_QVFB) && !defined(QT_NO_QWS_KEYBOARD) - const QString keyboardDev = QT_VFB_KEYBOARD_PIPE(displayId); - d_ptr->keyboard = new QVFbKeyboardHandler(keyboardDev); - qwsServer->setDefaultKeyboard("None"); -#endif - - if (d_ptr->hdr->dataoffset >= (int)sizeof(QVFbHeader)) - d_ptr->hdr->serverVersion = QT_VERSION; - - if(d==8) { - screencols=256; - if (grayscale) { - // Build grayscale palette - for(int loopc=0;loopc<256;loopc++) { - screenclut[loopc]=qRgb(loopc,loopc,loopc); - } - } else { - // 6x6x6 216 color cube - int idx = 0; - for(int ir = 0x0; ir <= 0xff; ir+=0x33) { - for(int ig = 0x0; ig <= 0xff; ig+=0x33) { - for(int ib = 0x0; ib <= 0xff; ib+=0x33) { - screenclut[idx]=qRgb(ir, ig, ib); - idx++; - } - } - } - screencols=idx; - } - memcpy(d_ptr->hdr->clut, screenclut, sizeof(QRgb) * screencols); - d_ptr->hdr->numcols = screencols; - } else if (d == 4) { - int val = 0; - for (int idx = 0; idx < 16; idx++, val += 17) { - screenclut[idx] = qRgb(val, val, val); - } - screencols = 16; - memcpy(d_ptr->hdr->clut, screenclut, sizeof(QRgb) * screencols); - d_ptr->hdr->numcols = screencols; - } else if (d == 1) { - screencols = 2; - screenclut[1] = qRgb(0xff, 0xff, 0xff); - screenclut[0] = qRgb(0, 0, 0); - memcpy(d_ptr->hdr->clut, screenclut, sizeof(QRgb) * screencols); - d_ptr->hdr->numcols = screencols; - } - -#ifndef QT_NO_QWS_CURSOR - QScreenCursor::initSoftwareCursor(); -#endif - return true; -} - -void QVFbScreen::shutdownDevice() -{ -} - -void QVFbScreen::setMode(int ,int ,int) -{ -} - -// save the state of the graphics card -// This is needed so that e.g. we can restore the palette when switching -// between linux virtual consoles. -void QVFbScreen::save() -{ - // nothing to do. -} - -// restore the state of the graphics card. -void QVFbScreen::restore() -{ -} -void QVFbScreen::setDirty(const QRect& rect) -{ - const QRect r = rect.translated(-offset()); - d_ptr->hdr->dirty = true; - d_ptr->hdr->update = d_ptr->hdr->update.united(r); -} - -void QVFbScreen::setBrightness(int b) -{ - if (connected) { - connected->d_ptr->brightness = b; - - QVFbHeader *hdr = connected->d_ptr->hdr; - if (hdr->viewerVersion < 0x040400) // brightness not supported - return; - - const int br = connected->d_ptr->blank ? 0 : b; - if (hdr->brightness != br) { - hdr->brightness = br; - connected->setDirty(connected->region().boundingRect()); - } - } -} - -void QVFbScreen::blank(bool on) -{ - d_ptr->blank = on; - setBrightness(connected->d_ptr->brightness); -} - -#endif // QT_NO_QWS_QVFB - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qscreenvfb_qws.h b/src/gui/embedded/qscreenvfb_qws.h deleted file mode 100644 index dc5ff54a1b..0000000000 --- a/src/gui/embedded/qscreenvfb_qws.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSCREENVFB_QWS_H -#define QSCREENVFB_QWS_H - -#include <QtGui/qscreen_qws.h> -#include <QtGui/qvfbhdr.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_QVFB - -class QVFbScreenPrivate; - -class Q_GUI_EXPORT QVFbScreen : public QScreen -{ -public: - explicit QVFbScreen(int display_id); - virtual ~QVFbScreen(); - virtual bool initDevice(); - virtual bool connect(const QString &displaySpec); - virtual void disconnect(); - virtual void shutdownDevice(); - virtual void save(); - virtual void restore(); - virtual void setMode(int nw,int nh,int nd); - virtual void setDirty(const QRect& r); - virtual void blank(bool); -#ifdef QTOPIA_QVFB_BRIGHTNESS - static void setBrightness(int b); -#endif - -private: - QVFbScreenPrivate *d_ptr; -}; - -#endif // QT_NO_QWS_QVFB - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSCREENVFB_QWS_H diff --git a/src/gui/embedded/qsoundqss_qws.cpp b/src/gui/embedded/qsoundqss_qws.cpp deleted file mode 100644 index bd6da77d4c..0000000000 --- a/src/gui/embedded/qsoundqss_qws.cpp +++ /dev/null @@ -1,1530 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoundqss_qws.h" - -#ifndef QT_NO_SOUND -#include <qbytearray.h> -#include <qlist.h> -#include <qsocketnotifier.h> -#include <qfile.h> -#include <qfileinfo.h> -#include <qstringlist.h> -#include <qevent.h> -#include <qalgorithms.h> -#include <qtimer.h> -#include <qpointer.h> -#include <qendian.h> -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <unistd.h> -#include <stdlib.h> -#include <fcntl.h> -#include <errno.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/soundcard.h> - -#include <qdebug.h> - -#include <qvfbhdr.h> - -extern int errno; - -QT_BEGIN_NAMESPACE - -#define QT_QWS_SOUND_16BIT 1 // or 0, or undefined for always 0 -#define QT_QWS_SOUND_STEREO 1 // or 0, or undefined for always 0 - -// Zaurus SL5000D doesn't seem to return any error if setting to 44000 and it fails, -// however 44100 works, 44100 is more common that 44000. -static int sound_speed = 44100; -#ifndef QT_NO_QWS_SOUNDSERVER -extern int qws_display_id; -#endif - -static char *zeroMem = 0; - -struct QRiffChunk { - char id[4]; - quint32 size; - char data[4/*size*/]; -}; - -#if defined(QT_QWS_IPAQ) -static const int sound_fragment_size = 12; -#else -static const int sound_fragment_size = 12; -#endif -static const int sound_buffer_size = 1 << sound_fragment_size; -// nb. there will be an sound startup delay of -// 2^sound_fragment_size / sound_speed seconds. -// (eg. sound_fragment_size==12, sound_speed==44000 means 0.093s delay) - -#ifdef QT_QWS_SOUND_STEREO -static int sound_stereo=QT_QWS_SOUND_STEREO; -#else -static const int sound_stereo=0; -#endif -#ifdef QT_QWS_SOUND_16BIT -static bool sound_16bit=QT_QWS_SOUND_16BIT; -#else -static const bool sound_16bit=false; -#endif - -#ifndef QT_NO_QWS_SOUNDSERVER -class QWSSoundServerClient : public QObject { - Q_OBJECT - -public: - QWSSoundServerClient(QWS_SOCK_BASE *s, QObject* parent); - ~QWSSoundServerClient(); - -public slots: - void sendSoundCompleted(int, int); - void sendDeviceReady(int, int); - void sendDeviceError(int, int, int); - -signals: - void play(int, int, const QString&); - void play(int, int, const QString&, int, int); - void playRaw(int, int, const QString&, int, int, int, int); - - void pause(int, int); - void stop(int, int); - void resume(int, int); - void setVolume(int, int, int, int); - void setMute(int, int, bool); - - void stopAll(int); - - void playPriorityOnly(bool); - - void setSilent( bool ); - -private slots: - void tryReadCommand(); - -private: - void sendClientMessage(QString msg); - int mCurrentID; - int left, right; - bool priExist; - static int lastId; - static int nextId() { return ++lastId; } - QPointer<QWS_SOCK_BASE> socket; -}; - -int QWSSoundServerClient::lastId = 0; - -QWSSoundServerClient::QWSSoundServerClient(QWS_SOCK_BASE *s, QObject* parent) : - QObject( parent ) -{ - socket = s; - priExist = false; - mCurrentID = nextId(); - connect(socket,SIGNAL(readyRead()), - this,SLOT(tryReadCommand())); - connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater())); -} - -QWSSoundServerClient::~QWSSoundServerClient() -{ - if (priExist) - playPriorityOnly(false); - emit stopAll(mCurrentID); - if (socket) - socket->deleteLater(); -} - -static QString getStringTok(QString &in) -{ - int pos = in.indexOf(QLatin1Char(' ')); - QString ret; - if (pos > 0) { - ret = in.left(pos); - in = in.mid(pos+1); - } else { - ret = in; - in = QString::null; - } - return ret; -} - -static int getNumTok(QString &in) -{ - return getStringTok(in).toInt(); -} - -void QWSSoundServerClient::tryReadCommand() -{ - while ( socket->canReadLine() ) { - QString l = QString::fromAscii(socket->readLine()); - l.truncate(l.length()-1); // chomp - QString functionName = getStringTok(l); - int soundid = getNumTok(l); - if (functionName == QLatin1String("PLAY")) { - emit play(mCurrentID, soundid, l); - } else if (functionName == QLatin1String("PLAYEXTEND")) { - int volume = getNumTok(l); - int flags = getNumTok(l); - emit play(mCurrentID, soundid, l, volume, flags); - } else if (functionName == QLatin1String("PLAYRAW")) { - int chs = getNumTok(l); - int freq = getNumTok(l); - int bitspersample = getNumTok(l); - int flags = getNumTok(l); - emit playRaw(mCurrentID, soundid, l, freq, chs, bitspersample, flags); - } else if (functionName == QLatin1String("PAUSE")) { - emit pause(mCurrentID, soundid); - } else if (functionName == QLatin1String("STOP")) { - emit stop(mCurrentID, soundid); - } else if (functionName == QLatin1String("RESUME")) { - emit resume(mCurrentID, soundid); - } else if (functionName == QLatin1String("SETVOLUME")) { - int left = getNumTok(l); - int right = getNumTok(l); - emit setVolume(mCurrentID, soundid, left, right); - } else if (functionName == QLatin1String("MUTE")) { - emit setMute(mCurrentID, soundid, true); - } else if (functionName == QLatin1String("UNMUTE")) { - emit setMute(mCurrentID, soundid, false); - } else if (functionName == QLatin1String("PRIORITYONLY")) { - bool sPri = soundid != 0; - if (sPri != priExist) { - priExist = sPri; - emit playPriorityOnly(sPri); - } - } else if(functionName == QLatin1String("SILENT")) { - emit setSilent( soundid != 0 ); - } - } -} - -void QWSSoundServerClient::sendClientMessage(QString msg) -{ -#ifndef QT_NO_TEXTCODEC - QByteArray u = msg.toUtf8(); -#else - QByteArray u = msg.toLatin1(); -#endif - socket->write(u.data(), u.length()); - socket->flush(); -} - -void QWSSoundServerClient::sendSoundCompleted(int gid, int sid) -{ - if (gid == mCurrentID) - sendClientMessage(QLatin1String("SOUNDCOMPLETED ") - + QString::number(sid) + QLatin1Char('\n')); -} - -void QWSSoundServerClient::sendDeviceReady(int gid, int sid) -{ - if (gid == mCurrentID) - sendClientMessage(QLatin1String("DEVICEREADY ") - + QString::number(sid) + QLatin1Char('\n')); -} - -void QWSSoundServerClient::sendDeviceError(int gid, int sid, int err) -{ - if (gid == mCurrentID) - sendClientMessage(QLatin1String("DEVICEERROR ") - + QString::number(sid) + QLatin1Char(' ') - + QString::number(err) + QLatin1Char('\n')); -} -#endif - -static const int maxVolume = 100; -static const int runinLength = 2*sound_buffer_size; -class QWSSoundServerProvider { -public: - QWSSoundServerProvider(int w, int s) - : mWid(w), mSid(s), mMuted(false) - { - leftVolume = maxVolume>>1; - rightVolume = maxVolume>>1; - isPriority = false; - samples_due = 0; - max1 = max2 = out = 0;// = sound_buffer_size; - data = data1; - max = &max1; - sampleRunin = 0; - dev = -1; - } - - virtual ~QWSSoundServerProvider() { - } - - int groupId() const { return mWid; } - int soundId() const { return mSid; } - - void startSampleRunin() { - // inteded to provide even audio return from mute/pause/dead samples. - //sampleRunin = runinLength; // or more? - } - - - void setVolume(int lv, int rv) { - leftVolume = qMin(maxVolume, qMax(0, lv)); - rightVolume = qMin(maxVolume, qMax(0, rv)); - } - - void setMute(bool m) { mMuted = m; } - bool muted() { return mMuted; } - - void setPriority(bool p) { - if (p != isPriority) { - isPriority = p; // currently meaningless. - } - } - - - static void setPlayPriorityOnly(bool p) - { - if (p) - priorityExists++; - else - priorityExists--; - - if (priorityExists < 0) - qDebug("QSS: got more priority offs than ons"); - } - - // return -1 for file broken, give up. - // else return sampels ready for playing. - // argument is max samples server is looking for, - // in terms of current device status. - virtual int readySamples(int) = 0; - - int getSample(int off, int bps) { - - // - // 16-bit audio data is converted to native endian so that it can be scaled - // Yes, this is ugly on a BigEndian machine - // Perhaps it shouldn't be scaled at all - // - return (bps == 1) ? (data[out+off] - 128) * 128 : qToLittleEndian(((short*)data)[(out/2)+off]); - } - - int add(int* mixl, int* mixr, int count) - { - int bytesPerSample = chunkdata.wBitsPerSample >> 3; - - if ( mMuted ) { - sampleRunin -= qMin(sampleRunin,count); - while (count && (dev != -1)) { - if (out >= *max) { - // switch buffers - out = 0; - if (data == data1 && max2 != 0) { - data = data2; - max = &max2; - max1 = 0; - } else if (data == data2 && max1 != 0) { - data = data1; - max = &max1; - max2 = 0; - } else { - qDebug("QSS Read Error: both buffers empty"); - return 0; - } - } - samples_due += sound_speed; - while (count && samples_due >= chunkdata.samplesPerSec) { - samples_due -= chunkdata.samplesPerSec; - count--; - } - out += bytesPerSample * chunkdata.channels; - } - return count; - } - - // This shouldn't be the case - if ( !mixl || !mixr ) - return 0; - - int lVolNum = leftVolume, lVolDen = maxVolume; - int rVolNum = rightVolume, rVolDen = maxVolume; - if (priorityExists > 0 && !isPriority) { - lVolNum = 0; // later, make this gradually fade in and out. - lVolDen = 5; - rVolNum = 0; - rVolDen = 5; - } - - while (count && (dev != -1)) { - if (out >= *max) { - // switch buffers - out = 0; - if (data == data1 && max2 != 0) { - data = data2; - max = &max2; - max1 = 0; - } else if (data == data2 && max1 != 0) { - data = data1; - max = &max1; - max2 = 0; - } else { - qDebug("QSS Read Error: both buffers empty"); - return 0; - } - } - samples_due += sound_speed; - if (count && samples_due >= chunkdata.samplesPerSec) { - int l = getSample(0,bytesPerSample)*lVolNum/lVolDen; - int r = (chunkdata.channels == 2) ? getSample(1,bytesPerSample)*rVolNum/rVolDen : l; - if (!sound_stereo && chunkdata.channels == 2) - l += r; - if (sampleRunin) { - while (sampleRunin && count && samples_due >= chunkdata.samplesPerSec) { - mixl++; - if (sound_stereo) - mixr++; - samples_due -= chunkdata.samplesPerSec; - sampleRunin--; - count--; - } - } - while (count && samples_due >= chunkdata.samplesPerSec) { - *mixl++ += l; - if (sound_stereo) - *mixr++ += r; - samples_due -= chunkdata.samplesPerSec; - count--; - } - } - - // optimize out manipulation of sample if downsampling and we skip it - out += bytesPerSample * chunkdata.channels; - } - - return count; - } - - virtual bool finished() const = 0; - - bool equal(int wid, int sid) - { - return (wid == mWid && sid == mSid); - } - -protected: - - char * prepareBuffer( int &size) - { - // keep reading as long as there is 50 % or more room in off buffer. - if (data == data1 && (max2<<1 < sound_buffer_size)) { - size=sound_buffer_size - max2; - return (char *)data2; - } else if (data == data2 && (max1<<1 < sound_buffer_size)) { - size=sound_buffer_size - max1; - return (char *)data1; - } else { - size = 0; - return 0; - } - } - - void updateBuffer(int read) - { - // always reads to off buffer. - if (read >= 0) { - if (data == data2) { - max1 = read; - } else { - max2 = read; - } - } - } - - int devSamples() - { - int possible = (((max1+max2-out) / ((chunkdata.wBitsPerSample>>3)*chunkdata.channels)) - *sound_speed)/chunkdata.samplesPerSec; - - return possible; - } - - - struct { - qint16 formatTag; - qint16 channels; - qint32 samplesPerSec; - qint32 avgBytesPerSec; - qint16 blockAlign; - qint16 wBitsPerSample; - } chunkdata; - int dev; - int samples_due; -private: - int mWid; - int mSid; - int leftVolume; - int rightVolume; - bool isPriority; - static int priorityExists; - int *max; - uchar *data; - uchar data1[sound_buffer_size+4]; // +4 to handle badly aligned input data - uchar data2[sound_buffer_size+4]; // +4 to handle badly aligned input data - int out, max1, max2; - int sampleRunin; - bool mMuted; -}; - -int QWSSoundServerProvider::priorityExists = 0; - -class QWSSoundServerBucket : public QWSSoundServerProvider { -public: - QWSSoundServerBucket(int d, int wid, int sid) - : QWSSoundServerProvider(wid, sid) - { - dev = d; - wavedata_remaining = -1; - mFinishedRead = false; - mInsufficientSamples = false; - } - ~QWSSoundServerBucket() - { - //dev->close(); - ::close(dev); - } - bool finished() const - { - //return !max; - return mInsufficientSamples && mFinishedRead ; - } - int readySamples(int) - { - int size; - char *dest = prepareBuffer(size); - // may want to change this to something like - // if (data == data1 && max2<<1 < sound_buffer_size - // || - // data == data2 && max1<<1 < sound_buffer_size) - // so will keep filling off buffer while there is +50% space left - if (size > 0 && dest != 0) { - while ( wavedata_remaining < 0 ) { - //max = 0; - wavedata_remaining = -1; - // Keep reading chunks... - const int n = sizeof(chunk)-sizeof(chunk.data); - int nr = ::read(dev, (void*)&chunk,n); - if ( nr != n ) { - // XXX check error? or don't we care? - wavedata_remaining = 0; - mFinishedRead = true; - } else if ( qstrncmp(chunk.id,"data",4) == 0 ) { - wavedata_remaining = qToLittleEndian( chunk.size ); - - //out = max = sound_buffer_size; - - } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { - char d[4]; - if ( read(dev, d, 4) != 4 ) { - // XXX check error? or don't we care? - //qDebug("couldn't read riff"); - mInsufficientSamples = true; - mFinishedRead = true; - return 0; - } else if ( qstrncmp(d,"WAVE",4) != 0 ) { - // skip - if ( chunk.size > 1000000000 || lseek(dev,chunk.size-4, SEEK_CUR) == -1 ) { - //qDebug("oversized wav chunk"); - mFinishedRead = true; - } - } - } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { - if ( ::read(dev,(char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { - // XXX check error? or don't we care? - //qDebug("couldn't ready chunkdata"); - mFinishedRead = true; - } - -#define WAVE_FORMAT_PCM 1 - else - { - /* - ** Endian Fix the chuck data - */ - chunkdata.formatTag = qToLittleEndian( chunkdata.formatTag ); - chunkdata.channels = qToLittleEndian( chunkdata.channels ); - chunkdata.samplesPerSec = qToLittleEndian( chunkdata.samplesPerSec ); - chunkdata.avgBytesPerSec = qToLittleEndian( chunkdata.avgBytesPerSec ); - chunkdata.blockAlign = qToLittleEndian( chunkdata.blockAlign ); - chunkdata.wBitsPerSample = qToLittleEndian( chunkdata.wBitsPerSample ); - if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { - qWarning("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); - mFinishedRead = true; - } - } - } else { - // ignored chunk - if ( chunk.size > 1000000000 || lseek(dev, chunk.size, SEEK_CUR) == -1) { - //qDebug("chunk size too big"); - mFinishedRead = true; - } - } - } - // this looks wrong. - if (wavedata_remaining <= 0) { - mFinishedRead = true; - } - - } - // may want to change this to something like - // if (data == data1 && max2<<1 < sound_buffer_size - // || - // data == data2 && max1<<1 < sound_buffer_size) - // so will keep filling off buffer while there is +50% space left - - if (wavedata_remaining) { - if (size > 0 && dest != 0) { - int read = ::read(dev, dest, qMin(size, wavedata_remaining)); - // XXX check error? or don't we care? - wavedata_remaining -= read; - updateBuffer(read); - if (read <= 0) // data unexpectidly ended - mFinishedRead = true; - } - } - int possible = devSamples(); - if (possible == 0) - mInsufficientSamples = true; - return possible; - } - -protected: - QRiffChunk chunk; - int wavedata_remaining; - bool mFinishedRead; - bool mInsufficientSamples; -}; - -class QWSSoundServerStream : public QWSSoundServerProvider { -public: - QWSSoundServerStream(int d,int c, int f, int b, - int wid, int sid) - : QWSSoundServerProvider(wid, sid) - { - chunkdata.channels = c; - chunkdata.samplesPerSec = f; - chunkdata.wBitsPerSample = b; - dev = d; - //fcntl( dev, F_SETFL, O_NONBLOCK ); - lasttime = 0; - } - - ~QWSSoundServerStream() - { - if (dev != -1) { - ::close(dev); - dev = -1; - } - } - - bool finished() const - { - return (dev == -1); - } - - - int readySamples(int) - { - int size; - char *dest = prepareBuffer(size); - if (size > 0 && dest != 0 && dev != -1) { - - int read = ::read(dev, dest, size); - if (read < 0) { - switch(errno) { - case EAGAIN: - case EINTR: - // means read may yet succeed on the next attempt - break; - default: - // unexpected error, fail. - ::close(dev); - dev = -1; - } - } else if (read == 0) { - // 0 means writer has closed dev and/or - // file is at end. - ::close(dev); - dev = -1; - } else { - updateBuffer(read); - } - } - int possible = devSamples(); - if (possible == 0) - startSampleRunin(); - return possible; - } - -protected: - time_t lasttime; -}; - -#ifndef QT_NO_QWS_SOUNDSERVER -QWSSoundServerSocket::QWSSoundServerSocket(QObject *parent) : - QWSServerSocket(QT_VFB_SOUND_PIPE(qws_display_id), parent) -{ - connect(this, SIGNAL(newConnection()), this, SLOT(newConnection())); -} - - -#ifdef QT3_SUPPORT -QWSSoundServerSocket::QWSSoundServerSocket(QObject *parent, const char *name) : - QWSServerSocket(QT_VFB_SOUND_PIPE(qws_display_id), parent) -{ - if (name) - setObjectName(QString::fromAscii(name)); - connect(this, SIGNAL(newConnection()), this, SLOT(newConnection())); -} -#endif - -void QWSSoundServerSocket::newConnection() -{ - while (QWS_SOCK_BASE *sock = nextPendingConnection()) { - QWSSoundServerClient* client = new QWSSoundServerClient(sock,this); - - connect(client, SIGNAL(play(int,int,QString)), - this, SIGNAL(playFile(int,int,QString))); - connect(client, SIGNAL(play(int,int,QString,int,int)), - this, SIGNAL(playFile(int,int,QString,int,int))); - connect(client, SIGNAL(playRaw(int,int,QString,int,int,int,int)), - this, SIGNAL(playRawFile(int,int,QString,int,int,int,int))); - - connect(client, SIGNAL(pause(int,int)), - this, SIGNAL(pauseFile(int,int))); - connect(client, SIGNAL(stop(int,int)), - this, SIGNAL(stopFile(int,int))); - connect(client, SIGNAL(playPriorityOnly(bool)), - this, SIGNAL(playPriorityOnly(bool))); - connect(client, SIGNAL(stopAll(int)), - this, SIGNAL(stopAll(int))); - connect(client, SIGNAL(resume(int,int)), - this, SIGNAL(resumeFile(int,int))); - - connect(client, SIGNAL(setSilent(bool)), - this, SIGNAL(setSilent(bool))); - - connect(client, SIGNAL(setMute(int,int,bool)), - this, SIGNAL(setMute(int,int,bool))); - connect(client, SIGNAL(setVolume(int,int,int,int)), - this, SIGNAL(setVolume(int,int,int,int))); - - connect(this, SIGNAL(soundFileCompleted(int,int)), - client, SLOT(sendSoundCompleted(int,int))); - connect(this, SIGNAL(deviceReady(int,int)), - client, SLOT(sendDeviceReady(int,int))); - connect(this, SIGNAL(deviceError(int,int,int)), - client, SLOT(sendDeviceError(int,int,int))); - } -} - -#endif - -class QWSSoundServerPrivate : public QObject { - Q_OBJECT - -public: - QWSSoundServerPrivate(QObject* parent=0, const char* name=0) : - QObject(parent) - { - timerId = 0; - if (name) - setObjectName(QString::fromAscii(name)); -#ifndef QT_NO_QWS_SOUNDSERVER - server = new QWSSoundServerSocket(this); - - connect(server, SIGNAL(playFile(int,int,QString)), - this, SLOT(playFile(int,int,QString))); - connect(server, SIGNAL(playFile(int,int,QString,int,int)), - this, SLOT(playFile(int,int,QString,int,int))); - connect(server, SIGNAL(playRawFile(int,int,QString,int,int,int,int)), - this, SLOT(playRawFile(int,int,QString,int,int,int,int))); - - connect(server, SIGNAL(pauseFile(int,int)), - this, SLOT(pauseFile(int,int))); - connect(server, SIGNAL(stopFile(int,int)), - this, SLOT(stopFile(int,int))); - connect(server, SIGNAL(stopAll(int)), - this, SLOT(stopAll(int))); - connect(server, SIGNAL(playPriorityOnly(bool)), - this, SLOT(playPriorityOnly(bool))); - connect(server, SIGNAL(resumeFile(int,int)), - this, SLOT(resumeFile(int,int))); - - connect( server, SIGNAL(setSilent(bool)), - this, SLOT(setSilent(bool))); - - connect(server, SIGNAL(setMute(int,int,bool)), - this, SLOT(setMute(int,int,bool))); - connect(server, SIGNAL(setVolume(int,int,int,int)), - this, SLOT(setVolume(int,int,int,int))); - - connect(this, SIGNAL(soundFileCompleted(int,int)), - server, SIGNAL(soundFileCompleted(int,int))); - connect(this, SIGNAL(deviceReady(int,int)), - server, SIGNAL(deviceReady(int,int))); - connect(this, SIGNAL(deviceError(int,int,int)), - server, SIGNAL(deviceError(int,int,int))); - -#endif - silent = false; - fd = -1; - unwritten = 0; - can_GETOSPACE = true; - } - - ~QWSSoundServerPrivate() - { - qDeleteAll(active); - qDeleteAll(inactive); - } - -signals: - void soundFileCompleted(int, int); - void deviceReady(int, int); - void deviceError(int, int, int); - -public slots: - void playRawFile(int wid, int sid, const QString &filename, int freq, int channels, int bitspersample, int flags); - void playFile(int wid, int sid, const QString& filename); - void playFile(int wid, int sid, const QString& filename, int v, int flags); - void checkPresetVolumes(int wid, int sid, QWSSoundServerProvider *p); - void pauseFile(int wid, int sid); - void resumeFile(int wid, int sid); - void stopFile(int wid, int sid); - void stopAll(int wid); - void setVolume(int wid, int sid, int lv, int rv); - void setMute(int wid, int sid, bool m); - void playPriorityOnly(bool p); - void sendCompletedSignals(); - void feedDevice(int fd); - void setSilent( bool enabled ); - -protected: - void timerEvent(QTimerEvent* event); - -private: - int openFile(int wid, int sid, const QString& filename); - bool openDevice(); - void closeDevice() - { - if (fd >= 0) { - ::close(fd); - fd = -1; - } - } - - QList<QWSSoundServerProvider*> active; - QList<QWSSoundServerProvider*> inactive; - struct PresetVolume { - int wid; - int sid; - int left; - int right; - bool mute; - }; - QList<PresetVolume> volumes; - struct CompletedInfo { - CompletedInfo( ) : groupId( 0 ), soundId( 0 ) { } - CompletedInfo( int _groupId, int _soundId ) : groupId( _groupId ), soundId( _soundId ) { } - int groupId; - int soundId; - }; - QList<CompletedInfo> completed; - - bool silent; - - int fd; - int unwritten; - int timerId; - char* cursor; - short data[sound_buffer_size*2]; - bool can_GETOSPACE; -#ifndef QT_NO_QWS_SOUNDSERVER - QWSSoundServerSocket *server; -#endif -}; - -void QWSSoundServerPrivate::setSilent( bool enabled ) -{ - // Close output device - closeDevice(); - if( !unwritten && !active.count() ) { - sendCompletedSignals(); - } - // Stop processing audio - killTimer( timerId ); - silent = enabled; - // If audio remaining, open output device and continue processing - if( unwritten || active.count() ) { - openDevice(); - } -} - -void QWSSoundServerPrivate::timerEvent(QTimerEvent* event) -{ - // qDebug("QSS timer event"); - if( event->timerId() == timerId ) { - if (fd >= 0) - feedDevice(fd); - if (fd < 0) { - killTimer(timerId); - timerId = 0; - } - } -} - -void QWSSoundServerPrivate::playRawFile(int wid, int sid, const QString &filename, - int freq, int channels, int bitspersample, int flags) -{ -#ifdef QT_NO_QWS_SOUNDSERVER - Q_UNUSED(flags); -#endif - int f = openFile(wid, sid, filename); - if ( f ) { - QWSSoundServerStream *b = new QWSSoundServerStream(f, channels, freq, bitspersample, wid, sid); - // check preset volumes. - checkPresetVolumes(wid, sid, b); -#ifndef QT_NO_QWS_SOUNDSERVER - b->setPriority((flags & QWSSoundClient::Priority) == QWSSoundClient::Priority); -#endif - active.append(b); - emit deviceReady(wid, sid); - } -} - -void QWSSoundServerPrivate::playFile(int wid, int sid, const QString& filename) -{ - int f = openFile(wid, sid, filename); - if ( f ) { - QWSSoundServerProvider *b = new QWSSoundServerBucket(f, wid, sid); - checkPresetVolumes(wid, sid, b); - active.append( b ); - emit deviceReady(wid, sid); - } -} - -void QWSSoundServerPrivate::playFile(int wid, int sid, const QString& filename, - int v, int flags) -{ -#ifdef QT_NO_QWS_SOUNDSERVER - Q_UNUSED(flags); -#endif - int f = openFile(wid, sid, filename); - if ( f ) { - QWSSoundServerProvider *b = new QWSSoundServerBucket(f, wid, sid); - checkPresetVolumes(wid, sid, b); - b->setVolume(v, v); -#ifndef QT_NO_QWS_SOUNDSERVER - b->setPriority((flags & QWSSoundClient::Priority) == QWSSoundClient::Priority); -#endif - active.append(b); - emit deviceReady(wid, sid); - } -} - -void QWSSoundServerPrivate::checkPresetVolumes(int wid, int sid, QWSSoundServerProvider *p) -{ - QList<PresetVolume>::Iterator it = volumes.begin(); - while (it != volumes.end()) { - PresetVolume v = *it; - if (v.wid == wid && v.sid == sid) { - p->setVolume(v.left, v.right); - p->setMute(v.mute); - it = volumes.erase(it); - return; - } else { - ++it; - } - } -} - -void QWSSoundServerPrivate::pauseFile(int wid, int sid) -{ - QWSSoundServerProvider *bucket; - for (int i = 0; i < active.size(); ++i ) { - bucket = active.at(i); - if (bucket->equal(wid, sid)) { - // found bucket.... - active.removeAt(i); - inactive.append(bucket); - return; - } - } -} - -void QWSSoundServerPrivate::resumeFile(int wid, int sid) -{ - QWSSoundServerProvider *bucket; - for (int i = 0; i < inactive.size(); ++i ) { - bucket = inactive.at(i); - if (bucket->equal(wid, sid)) { - // found bucket.... - inactive.removeAt(i); - active.append(bucket); - return; - } - } -} - -void QWSSoundServerPrivate::stopFile(int wid, int sid) -{ - QWSSoundServerProvider *bucket; - for (int i = 0; i < active.size(); ++i ) { - bucket = active.at(i); - if (bucket->equal(wid, sid)) { - active.removeAt(i); - delete bucket; - return; - } - } - for (int i = 0; i < inactive.size(); ++i ) { - bucket = inactive.at(i); - if (bucket->equal(wid, sid)) { - inactive.removeAt(i); - delete bucket; - return; - } - } -} - -void QWSSoundServerPrivate::stopAll(int wid) -{ - QWSSoundServerProvider *bucket; - if (!active.isEmpty()) { - QList<QWSSoundServerProvider*>::Iterator it = active.begin(); - while (it != active.end()) { - bucket = *it; - if (bucket->groupId() == wid) { - it = active.erase(it); - delete bucket; - } else { - ++it; - } - } - } - if (!inactive.isEmpty()) { - QList<QWSSoundServerProvider*>::Iterator it = inactive.begin(); - while (it != inactive.end()) { - bucket = *it; - if (bucket->groupId() == wid) { - it = inactive.erase(it); - delete bucket; - } else { - ++it; - } - } - } -} - -void QWSSoundServerPrivate::setVolume(int wid, int sid, int lv, int rv) -{ - QWSSoundServerProvider *bucket; - for( int i = 0; i < active.size(); ++i ) { - bucket = active.at(i); - if (bucket->equal(wid, sid)) { - bucket->setVolume(lv,rv); - return; - } - } - // If gotten here, then it means wid/sid wasn't set up yet. - // first find and remove current preset volumes, then add this one. - QList<PresetVolume>::Iterator it = volumes.begin(); - while (it != volumes.end()) { - PresetVolume v = *it; - if (v.wid == wid && v.sid == sid) - it = volumes.erase(it); - else - ++it; - } - // and then add this volume - PresetVolume nv; - nv.wid = wid; - nv.sid = sid; - nv.left = lv; - nv.right = rv; - nv.mute = false; - volumes.append(nv); -} - -void QWSSoundServerPrivate::setMute(int wid, int sid, bool m) -{ - QWSSoundServerProvider *bucket; - for( int i = 0; i < active.size(); ++i ) { - bucket = active.at(i); - if (bucket->equal(wid, sid)) { - bucket->setMute(m); - return; - } - } - // if gotten here then setting is being applied before item - // is created. - QList<PresetVolume>::Iterator it = volumes.begin(); - while (it != volumes.end()) { - PresetVolume v = *it; - if (v.wid == wid && v.sid == sid) { - (*it).mute = m; - return; - } - } - if (m) { - PresetVolume nv; - nv.wid = wid; - nv.sid = sid; - nv.left = maxVolume>>1; - nv.right = maxVolume>>1; - nv.mute = true; - volumes.append(nv); - } -} - -void QWSSoundServerPrivate::playPriorityOnly(bool p) -{ - QWSSoundServerProvider::setPlayPriorityOnly(p); -} - -void QWSSoundServerPrivate::sendCompletedSignals() -{ - while( !completed.isEmpty() ) { - emit soundFileCompleted( (*completed.begin()).groupId, - (*completed.begin()).soundId ); - completed.erase( completed.begin() ); - } -} - - -int QWSSoundServerPrivate::openFile(int wid, int sid, const QString& filename) -{ - stopFile(wid, sid); // close and re-open. - int f = QT_OPEN(QFile::encodeName(filename), O_RDONLY|O_NONBLOCK); - if (f == -1) { - // XXX check ferror, check reason. - qDebug("Failed opening \"%s\"",filename.toLatin1().data()); -#ifndef QT_NO_QWS_SOUNDSERVER - emit deviceError(wid, sid, (int)QWSSoundClient::ErrOpeningFile ); -#endif - } else if ( openDevice() ) { - return f; - } -#ifndef QT_NO_QWS_SOUNDSERVER - emit deviceError(wid, sid, (int)QWSSoundClient::ErrOpeningAudioDevice ); -#endif - return 0; -} - -bool QWSSoundServerPrivate::openDevice() -{ - if (fd < 0) { - if( silent ) { - fd = QT_OPEN( "/dev/null", O_WRONLY ); - // Emulate write to audio device - int delay = 1000*(sound_buffer_size>>(sound_stereo+sound_16bit))/sound_speed/2; - timerId = startTimer(delay); - - return true; - } - // - // Don't block open right away. - // - bool openOkay = false; - if ((fd = QT_OPEN("/dev/dsp", O_WRONLY|O_NONBLOCK)) != -1) { - int flags = fcntl(fd, F_GETFL); - flags &= ~O_NONBLOCK; - openOkay = (fcntl(fd, F_SETFL, flags) == 0); - } - if (!openOkay) { - qDebug("Failed opening audio device"); - return false; - } - - // Setup soundcard at 16 bit mono - int v; - //v=0x00010000+sound_fragment_size; - // um the media player did this instead. - v=0x10000 * 4 + sound_fragment_size; - if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &v)) - qWarning("Could not set fragments to %08x",v); -#ifdef QT_QWS_SOUND_16BIT - // - // Use native endian - // Since we have manipulated the data volume the data - // is now in native format, even though its stored - // as little endian in the WAV file - // - v=AFMT_S16_NE; if (ioctl(fd, SNDCTL_DSP_SETFMT, &v)) - qWarning("Could not set format %d",v); - if (AFMT_S16_NE != v) - qDebug("Want format %d got %d", AFMT_S16_LE, v); -#else - v=AFMT_U8; if (ioctl(fd, SNDCTL_DSP_SETFMT, &v)) - qWarning("Could not set format %d",v); - if (AFMT_U8 != v) - qDebug("Want format %d got %d", AFMT_U8, v); -#endif - v=sound_stereo; if (ioctl(fd, SNDCTL_DSP_STEREO, &v)) - qWarning("Could not set stereo %d",v); - if (sound_stereo != v) - qDebug("Want stereo %d got %d", sound_stereo, v); -#ifdef QT_QWS_SOUND_STEREO - sound_stereo=v; -#endif - v=sound_speed; if (ioctl(fd, SNDCTL_DSP_SPEED, &sound_speed)) - qWarning("Could not set speed %d",v); - if (v != sound_speed) - qDebug("Want speed %d got %d", v, sound_speed); - - int delay = 1000*(sound_buffer_size>>(sound_stereo+sound_16bit)) - /sound_speed/2; - // qDebug("QSS delay: %d", delay); - timerId = startTimer(delay); - - // - // Check system volume - // - int mixerHandle = QT_OPEN( "/dev/mixer", O_RDWR|O_NONBLOCK ); - if ( mixerHandle >= 0 ) { - int volume; - ioctl( mixerHandle, MIXER_READ(0), &volume ); - close( mixerHandle ); - if ( volume < 1<<(sound_stereo+sound_16bit) ) - qDebug("Want sound at %d got %d", - 1<<(sound_stereo+sound_16bit), volume); - } else - qDebug( "get volume of audio device failed" ); - - } - return true; -} - -void QWSSoundServerPrivate::feedDevice(int fd) -{ - if ( !unwritten && active.size() == 0 ) { - closeDevice(); - sendCompletedSignals(); - return; - } else { - sendCompletedSignals(); - } - - QWSSoundServerProvider* bucket; - - // find out how much audio is possible - int available = sound_buffer_size; - QList<QWSSoundServerProvider*> running; - for (int i = 0; i < active.size(); ++i) { - bucket = active.at(i); - int ready = bucket->readySamples(available); - if (ready > 0) { - available = qMin(available, ready); - running.append(bucket); - } - } - - audio_buf_info info; - if (can_GETOSPACE && ioctl(fd,SNDCTL_DSP_GETOSPACE,&info)) { - can_GETOSPACE = false; - fcntl(fd, F_SETFL, O_NONBLOCK); - } - if (!can_GETOSPACE) - info.fragments = 4; // #### configurable? - if (info.fragments > 0) { - if (!unwritten) { - int left[sound_buffer_size]; - memset(left,0,available*sizeof(int)); - int right[sound_buffer_size]; - if ( sound_stereo ) - memset(right,0,available*sizeof(int)); - - if (running.size() > 0) { - // should do volume mod here in regards to each bucket to avoid flattened/bad peaks. - for (int i = 0; i < running.size(); ++i ) { - bucket = running.at(i); - int unused = bucket->add(left,right,available); - if (unused > 0) { - // this error is quite serious, as - // it will really screw up mixing. - qDebug("provider lied about samples ready"); - } - } - if ( sound_16bit ) { - short *d = (short*)data; - for (int i=0; i<available; i++) { - *d++ = (short)qMax(qMin(left[i],32767),-32768); - if ( sound_stereo ) - *d++ = (short)qMax(qMin(right[i],32767),-32768); - } - } else { - signed char *d = (signed char *)data; - for (int i=0; i<available; i++) { - *d++ = (signed char)qMax(qMin(left[i]/256,127),-128)+128; - if ( sound_stereo ) - *d++ = (signed char)qMax(qMin(right[i]/256,127),-128)+128; - } - } - unwritten = available*(sound_16bit+1)*(sound_stereo+1); - cursor = (char*)data; - } - } - // sound open, but nothing written. Should clear the buffer. - - int w; - if (unwritten) { - w = ::write(fd,cursor,unwritten); - - if (w < 0) { - if (can_GETOSPACE) - return; - w = 0; - } - - cursor += w; - unwritten -= w; - } else { - // write some zeros to clear the buffer? - if (!zeroMem) - zeroMem = (char *)calloc(sound_buffer_size, sizeof(char)); - w = ::write(fd, zeroMem, sound_buffer_size); - if (w < 0) - w = 0; - } - } - - QList<QWSSoundServerProvider*>::Iterator it = active.begin(); - while (it != active.end()) { - bucket = *it; - if (bucket->finished()) { - completed.append(CompletedInfo(bucket->groupId(), bucket->soundId())); - it = active.erase(it); - delete bucket; - } else { - ++it; - } - } -} - - -QWSSoundServer::QWSSoundServer(QObject* parent) : - QObject(parent) -{ - d = new QWSSoundServerPrivate(this); - - connect( d, SIGNAL(soundFileCompleted(int,int)), - this, SLOT(translateSoundCompleted(int,int)) ); -} - -void QWSSoundServer::playFile( int sid, const QString& filename ) -{ - //wid == 0, as it is the server initiating rather than a client - // if wid was passable, would accidently collide with server - // sockect's wids. - d->playFile(0, sid, filename); -} - -void QWSSoundServer::pauseFile( int sid ) -{ - d->pauseFile(0, sid); -} - -void QWSSoundServer::stopFile( int sid ) -{ - d->stopFile(0, sid); -} - -void QWSSoundServer::resumeFile( int sid ) -{ - d->resumeFile(0, sid); -} - -QWSSoundServer::~QWSSoundServer() -{ - d->stopAll(0); -} - -void QWSSoundServer::translateSoundCompleted( int, int sid ) -{ - emit soundCompleted( sid ); -} - -#ifndef QT_NO_QWS_SOUNDSERVER -QWSSoundClient::QWSSoundClient(QObject* parent) : - QWSSocket(parent) -{ - connectToLocalFile(QT_VFB_SOUND_PIPE(qws_display_id)); - QObject::connect(this,SIGNAL(readyRead()), - this,SLOT(tryReadCommand())); - if( state() == QWS_SOCK_BASE::ConnectedState ) QTimer::singleShot(1, this, SIGNAL(connected())); - else QTimer::singleShot(1, this, SLOT(emitConnectionRefused())); -} - -QWSSoundClient::~QWSSoundClient( ) -{ - flush(); -} - -void QWSSoundClient::reconnect() -{ - connectToLocalFile(QT_VFB_SOUND_PIPE(qws_display_id)); - if( state() == QWS_SOCK_BASE::ConnectedState ) emit connected(); - else emit error( QTcpSocket::ConnectionRefusedError ); -} - -void QWSSoundClient::sendServerMessage(QString msg) -{ -#ifndef QT_NO_TEXTCODEC - QByteArray u = msg.toUtf8(); -#else - QByteArray u = msg.toLatin1(); -#endif - write(u.data(), u.length()); - flush(); -} - -void QWSSoundClient::play( int id, const QString& filename ) -{ - QFileInfo fi(filename); - sendServerMessage(QLatin1String("PLAY ") - + QString::number(id) + QLatin1Char(' ') - + fi.absoluteFilePath() + QLatin1Char('\n')); -} - -void QWSSoundClient::play( int id, const QString& filename, int volume, int flags) -{ - QFileInfo fi(filename); - sendServerMessage(QLatin1String("PLAYEXTEND ") - + QString::number(id) + QLatin1Char(' ') - + QString::number(volume) + QLatin1Char(' ') - + QString::number(flags) + QLatin1Char(' ') - + fi.absoluteFilePath() + QLatin1Char('\n')); -} - -void QWSSoundClient::pause( int id ) -{ - sendServerMessage(QLatin1String("PAUSE ") - + QString::number(id) + QLatin1Char('\n')); -} - -void QWSSoundClient::stop( int id ) -{ - sendServerMessage(QLatin1String("STOP ") - + QString::number(id) + QLatin1Char('\n')); -} - -void QWSSoundClient::resume( int id ) -{ - sendServerMessage(QLatin1String("RESUME ") - + QString::number(id) + QLatin1Char('\n')); -} - -void QWSSoundClient::playRaw( int id, const QString& filename, - int freq, int chs, int bitspersample, int flags) -{ - QFileInfo fi(filename); - sendServerMessage(QLatin1String("PLAYRAW ") - + QString::number(id) + QLatin1Char(' ') - + QString::number(chs) + QLatin1Char(' ') - + QString::number(freq) + QLatin1Char(' ') - + QString::number(bitspersample) + QLatin1Char(' ') - + QString::number(flags) + QLatin1Char(' ') - + fi.absoluteFilePath() + QLatin1Char('\n')); -} - -void QWSSoundClient::setMute( int id, bool m ) -{ - sendServerMessage(QLatin1String(m ? "MUTE " : "UNMUTE ") - + QString::number(id) + QLatin1Char('\n')); -} - -void QWSSoundClient::setVolume( int id, int leftVol, int rightVol ) -{ - sendServerMessage(QLatin1String("SETVOLUME ") - + QString::number(id) + QLatin1Char(' ') - + QString::number(leftVol) + QLatin1Char(' ') - + QString::number(rightVol) + QLatin1Char('\n')); -} - -void QWSSoundClient::playPriorityOnly( bool pri ) -{ - sendServerMessage(QLatin1String("PRIORITYONLY ") - + QString::number(pri ? 1 : 0) + QLatin1Char('\n')); -} - -void QWSSoundClient::setSilent( bool enable ) -{ - sendServerMessage(QLatin1String("SILENT ") - + QString::number( enable ? 1 : 0 ) + QLatin1Char('\n')); -} - -void QWSSoundClient::tryReadCommand() -{ - while ( canReadLine() ) { - QString l = QString::fromAscii(readLine()); - l.truncate(l.length()-1); // chomp - QStringList token = l.split(QLatin1Char(' ')); - if (token[0] == QLatin1String("SOUNDCOMPLETED")) { - emit soundCompleted(token[1].toInt()); - } else if (token[0] == QLatin1String("DEVICEREADY")) { - emit deviceReady(token[1].toInt()); - } else if (token[0] == QLatin1String("DEVICEERROR")) { - emit deviceError(token[1].toInt(),(DeviceErrors)token[2].toInt()); - } - } -} - -void QWSSoundClient::emitConnectionRefused() -{ - emit error( QTcpSocket::ConnectionRefusedError ); -} -#endif - -QT_END_NAMESPACE - -#include "qsoundqss_qws.moc" - -#endif // QT_NO_SOUND diff --git a/src/gui/embedded/qsoundqss_qws.h b/src/gui/embedded/qsoundqss_qws.h deleted file mode 100644 index c802a72384..0000000000 --- a/src/gui/embedded/qsoundqss_qws.h +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOUNDQSS_QWS_H -#define QSOUNDQSS_QWS_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_SOUND - -#include <QtNetwork/qtcpserver.h> -#include <QtNetwork/qtcpsocket.h> -#include <QtGui/qwssocket_qws.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#if defined(QT_NO_NETWORK) || defined(QT_NO_DNS) -#define QT_NO_QWS_SOUNDSERVER -#endif - -#ifndef Q_OS_MAC - -class QWSSoundServerPrivate; - -class Q_GUI_EXPORT QWSSoundServer : public QObject { - Q_OBJECT -public: - explicit QWSSoundServer(QObject *parent=0); - ~QWSSoundServer(); - void playFile( int id, const QString& filename ); - void stopFile( int id ); - void pauseFile( int id ); - void resumeFile( int id ); - -Q_SIGNALS: - void soundCompleted( int ); - -private Q_SLOTS: - void translateSoundCompleted( int, int ); - -private: - QWSSoundServerPrivate* d; -}; - -#ifndef QT_NO_QWS_SOUNDSERVER -class Q_GUI_EXPORT QWSSoundClient : public QWSSocket { - Q_OBJECT -public: - - enum SoundFlags { - Priority = 0x01, - Streaming = 0x02 // currently ignored, but but could set up so both Raw and non raw can be done streaming or not. - }; - enum DeviceErrors { - ErrOpeningAudioDevice = 0x01, - ErrOpeningFile = 0x02, - ErrReadingFile = 0x04 - }; - explicit QWSSoundClient(QObject* parent=0); - ~QWSSoundClient( ); - void reconnect(); - void play( int id, const QString& filename ); - void play( int id, const QString& filename, int volume, int flags = 0 ); - void playRaw( int id, const QString&, int, int, int, int flags = 0 ); - - void pause( int id ); - void stop( int id ); - void resume( int id ); - void setVolume( int id, int left, int right ); - void setMute( int id, bool m ); - - // to be used by server only, to protect phone conversation/rings. - void playPriorityOnly(bool); - - // If silent, tell sound server to release audio device - // Otherwise, allow sound server to regain audio device - void setSilent(bool); - -Q_SIGNALS: - void soundCompleted(int); - void deviceReady(int id); - void deviceError(int id, QWSSoundClient::DeviceErrors); - -private Q_SLOTS: - void tryReadCommand(); - void emitConnectionRefused(); - -private: - void sendServerMessage(QString msg); -}; - -class QWSSoundServerSocket : public QWSServerSocket { - Q_OBJECT - -public: - explicit QWSSoundServerSocket(QObject *parent=0); -public Q_SLOTS: - void newConnection(); - -#ifdef QT3_SUPPORT -public: - QT3_SUPPORT_CONSTRUCTOR QWSSoundServerSocket(QObject *parent, const char *name); -#endif - -Q_SIGNALS: - void playFile(int, int, const QString&); - void playFile(int, int, const QString&, int, int); - void playRawFile(int, int, const QString&, int, int, int, int); - void pauseFile(int, int); - void stopFile(int, int); - void resumeFile(int, int); - void setVolume(int, int, int, int); - void setMute(int, int, bool); - - void stopAll(int); - - void playPriorityOnly(bool); - - void setSilent(bool); - - void soundFileCompleted(int, int); - void deviceReady(int, int); - void deviceError(int, int, int); -}; -#endif - -#endif // Q_OS_MAC - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_SOUND - -#endif // QSOUNDQSS_QWS_H diff --git a/src/gui/embedded/qtransportauth_qws.cpp b/src/gui/embedded/qtransportauth_qws.cpp deleted file mode 100644 index 81e67a9e90..0000000000 --- a/src/gui/embedded/qtransportauth_qws.cpp +++ /dev/null @@ -1,1563 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtransportauth_qws.h" -#include "qtransportauth_qws_p.h" - -#ifndef QT_NO_SXE - -#include "../../3rdparty/md5/md5.h" -#include "../../3rdparty/md5/md5.cpp" -#include "qwsutils_qws.h" -#include "qwssocket_qws.h" -#include "qwscommand_qws_p.h" -#include "qwindowsystem_qws.h" -#include "qbuffer.h" -#include "qthread.h" -#include "qabstractsocket.h" -#include "qlibraryinfo.h" -#include "qfile.h" -#include "qdebug.h" -#include <private/qcore_unix_p.h> // overrides QT_OPEN - -#include <syslog.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <time.h> - -#include <QtCore/qcache.h> - -#define BUF_SIZE 512 - -QT_BEGIN_NAMESPACE - -/*! - \internal - memset for security purposes, guaranteed not to be optimized away - http://www.faqs.org/docs/Linux-HOWTO/Secure-Programs-HOWTO.html -*/ -Q_GUI_EXPORT void *guaranteed_memset(void *v,int c,size_t n) -{ - volatile char *p = (char *)v; while (n--) *p++=c; return v; -} - -/*! - \class QTransportAuth - \internal - - \brief Authenticate a message transport. - - For performance reasons, message authentication is tied to an individual - message transport instance. For example in connection oriented transports - the authentication cookie can be cached against the connection avoiding - the overhead of authentication on every message. - - For each process there is one instance of the QTransportAuth object. - For server processes it can determine the \link secure-exe-environ.html SXE - Program Identity \endlink and provide access to policy data to determine if - the message should be forwarded for action. If not actioned, the message - may be treated as being from a flawed or malicious process. - - Retrieve the instance with the getInstance() method. The constructor is - disabled and instances of QTransportAuth should never be constructed by - calling classes. - - To make the Authentication easier to use a proxied QIODevice is provided - which uses an internal QBuffer. - - In the server code first get a pointer to a QTransportAuth::Data object - using the connectTransport() method: - - \snippet doc/src/snippets/code/src_gui_embedded_qtransportauth_qws.cpp 0 - - Here it is asserted that the transport is trusted. See the assumptions - listed in the \link secure-exe-environ.html SXE documentation \endlink - - Then proxy in the authentication device: - - \snippet doc/src/snippets/code/src_gui_embedded_qtransportauth_qws.cpp 1 - - In the client code it is similar. Use the connectTransport() method - just the same then proxy in the authentication device instead of the - socket in write calls: - - \snippet doc/src/snippets/code/src_gui_embedded_qtransportauth_qws.cpp 2 -*/ - -static int hmac_md5( - unsigned char* text, /* pointer to data stream */ - int text_length, /* length of data stream */ - const unsigned char* key, /* pointer to authentication key */ - int key_length, /* length of authentication key */ - unsigned char * digest /* caller digest to be filled in */ - ); - - - -#define KEY_CACHE_SIZE 30 - -const char * const errorStrings[] = { - "pending identity verification", - "message too small to carry auth data", - "cache miss on connection oriented transport", - "no magic bytes on message", - "key not found for prog id", - "authorization key match failed", - "key out of date" -}; - -const char *QTransportAuth::errorString( const Data &d ) -{ - if (( d.status & ErrMask ) == Success ) - return "success"; - int e = d.status & ErrMask; - if ( e > OutOfDate ) - return "unknown"; - return errorStrings[e]; -} - -SxeRegistryLocker::SxeRegistryLocker( QObject *reg ) - : m_success( false ) - , m_reg( 0 ) -{ - if ( reg ) - if ( !QMetaObject::invokeMethod( reg, "lockManifest", Q_RETURN_ARG(bool, m_success) )) - m_success = false; - m_reg = reg; -} - -SxeRegistryLocker::~SxeRegistryLocker() -{ - if ( m_success ) - QMetaObject::invokeMethod( m_reg, "unlockManifest" ); -} - - -QTransportAuthPrivate::QTransportAuthPrivate() - : keyInitialised(false) - , m_packageRegistry( 0 ) -{ -} - -QTransportAuthPrivate::~QTransportAuthPrivate() -{ -} - -/*! - \internal - Construct a new QTransportAuth -*/ -QTransportAuth::QTransportAuth() : QObject(*new QTransportAuthPrivate) -{ - // qDebug( "creating transport auth" ); -} - -/*! - \internal - Destructor -*/ -QTransportAuth::~QTransportAuth() -{ - // qDebug( "deleting transport auth" ); -} - -/*! - Set the process key for this currently running Qt Extended process to - the \a authdata. \a authdata should be sizeof(struct AuthCookie) - in length and contain the key and program id. Use this method - when setting or changing the SXE identity of the current program. -*/ -void QTransportAuth::setProcessKey( const char *authdata ) -{ - Q_D(QTransportAuth); - ::memcpy(&d->authKey, authdata, sizeof(struct AuthCookie)); - QFile proc_key( QLatin1String("/proc/self/lids_key") ); - // where proc key exists use that instead - if ( proc_key.open( QIODevice::ReadOnly )) - { - qint64 kb = proc_key.read( (char*)&d->authKey.key, QSXE_KEY_LEN ); -#ifdef QTRANSPORTAUTH_DEBUG - qDebug( "Using %li bytes of /proc/%i/lids_key\n", (long int)kb, getpid() ); -#else - Q_UNUSED( kb ); -#endif - } - d->keyInitialised = true; -} - - -/*! - Apply \a key as the process key for the currently running application. - - \a prog is current ignored - - Deprecated function -*/ -void QTransportAuth::setProcessKey( const char *key, const char *prog ) -{ - Q_UNUSED(prog); - setProcessKey( key ); -#ifdef QTRANSPORTAUTH_DEBUG - char displaybuf[QSXE_KEY_LEN*2+1]; - hexstring( displaybuf, (const unsigned char *)key, QSXE_KEY_LEN ); - qDebug() << "key" << displaybuf << "set"; -#endif -} - -/*! - Register \a pr as a policy handler object. The object pointed to - by \a pr should have a slot as follows - \snippet doc/src/snippets/code/src_gui_embedded_qtransportauth_qws.cpp 3 - All requests received by this server will then generate a call to - this slot, and may be processed for policy compliance. -*/ -void QTransportAuth::registerPolicyReceiver( QObject *pr ) -{ - // not every policy receiver needs setup - no error if this fails - QMetaObject::invokeMethod( pr, "setupPolicyCheck" ); - - connect( this, SIGNAL(policyCheck(QTransportAuth::Data&,QString)), - pr, SLOT(policyCheck(QTransportAuth::Data&,QString)), Qt::DirectConnection ); -} - -/*! - Unregister the \a pr from being a policy handler. No more policyCheck signals - are received by this object. -*/ -void QTransportAuth::unregisterPolicyReceiver( QObject *pr ) -{ - disconnect( pr ); - // not every policy receiver needs tear down - no error if this fails - QMetaObject::invokeMethod( pr, "teardownPolicyCheck" ); -} - -/*! - Record a new transport connection with \a properties and \a descriptor. - - The calling code is responsible for destroying the returned data when the - tranport connection is closed. -*/ -QTransportAuth::Data *QTransportAuth::connectTransport( unsigned char properties, int descriptor ) -{ - Data *data = new Data(properties, descriptor); - data->status = Pending; - return data; -} - -/*! - Is the transport trusted. This is true iff data written into the - transport medium cannot be intercepted or modified by another process. - This is for example true for Unix Domain Sockets, but not for shared - memory or UDP sockets. - - There is of course an underlying assumption that the kernel implementing - the transport is sound, ie it cannot be compromised by writing to - /dev/kmem or loading untrusted modules -*/ -inline bool QTransportAuth::Data::trusted() const -{ - return (bool)(properties & Trusted); -} - -/*! - Assert that the transport is trusted. - - For example with respect to shared memory, if it is ensured that no untrusted - root processes are running, and that unix permissions have been set such that - any untrusted non-root processes do not have access rights, then a shared - memory transport could be asserted to be trusted. - - \sa trusted() -*/ -inline void QTransportAuth::Data::setTrusted( bool t ) -{ - properties = t ? properties | Trusted : properties & ~Trusted; -} - -/*! - Is the transport connection oriented. This is true iff once a connection - has been accepted, and state established, then further messages over the - transport are guaranteed to have come from the original connecting entity. - This is for example true for Unix Domain Sockets, but not - for shared memory or UDP sockets. - - By extension if the transport is not trusted() then it should not be - assumed to be connection oriented, since spoofed connection information - could be created. For example if we assume the TCP/IP transport is - trusted, it can be treated as connection oriented; but this is only the - case if intervening routers are trusted. - - Connection oriented transports have authorization cached against the - connection, and thus authorization is only done at connect time. -*/ -inline bool QTransportAuth::Data::connection() const -{ - return (bool)(properties & Connection); -} - -/*! - Assert that the transport is connection oriented. - - \sa connection() -*/ -inline void QTransportAuth::Data::setConnection( bool t ) -{ - properties = t ? properties | Connection : properties & ~Connection; -} - -/*! - Return a pointer to the instance of this process's QTransportAuth object -*/ -QTransportAuth *QTransportAuth::getInstance() -{ - static QTransportAuth theInstance; - - return &theInstance; -} - -/*! - Set the full path to the key file - - Since this is normally relative to Qtopia::qpeDir() this needs to be - set within the Qt Extended framework. - - The keyfile should be protected by file permissions or by MAC rules - such that it can only be read/written by the "qpe" server process -*/ -void QTransportAuth::setKeyFilePath( const QString &path ) -{ - Q_D(QTransportAuth); - d->m_keyFilePath = path; -} - -QString QTransportAuth::keyFilePath() const -{ - Q_D(const QTransportAuth); - return d->m_keyFilePath; -} - -void QTransportAuth::setLogFilePath( const QString &path ) -{ - Q_D(QTransportAuth); - d->m_logFilePath = path; -} - -QString QTransportAuth::logFilePath() const -{ - Q_D(const QTransportAuth); - return d->m_logFilePath; -} - -void QTransportAuth::setPackageRegistry( QObject *registry ) -{ - Q_D(QTransportAuth); - d->m_packageRegistry = registry; -} - -bool QTransportAuth::isDiscoveryMode() const -{ -#if defined(SXE_DISCOVERY) - static bool checked = false; - static bool yesItIs = false; - - if ( checked ) return yesItIs; - - yesItIs = ( getenv( "SXE_DISCOVERY_MODE" ) != 0 ); - if ( yesItIs ) - { - qWarning("SXE Discovery mode on, ALLOWING ALL requests and logging to %s", - qPrintable(logFilePath())); - QFile::remove( logFilePath() ); - } - checked = true; - return yesItIs; -#else - return false; -#endif -} - -/*! - \internal - Return the authorizer device mapped to this client. Note that this - could probably all be void* instead of QWSClient* for generality. - Until the need for that rears its head its QWSClient* to save the casts. - - #### OK the need has arrived, but the public API is frozen. -*/ -QIODevice *QTransportAuth::passThroughByClient( QWSClient *client ) const -{ - Q_D(const QTransportAuth); - - if ( client == 0 ) return 0; - if ( d->buffersByClient.contains( client )) - { - return d->buffersByClient[client]; - } - // qWarning( "buffer not found for client %p", client ); - return 0; -} - -/*! - \internal - Return a QIODevice pointer (to an internal QBuffer) which can be used - to receive data after authorization on transport \a d. - - The return QIODevice will act as a pass-through. - - The data will be consumed from \a iod and forwarded on to the returned - QIODevice which can be connected to readyRead() signal handlers in - place of the original QIODevice \a iod. - - This will be called in the server process to handle incoming - authenticated requests. - - The returned QIODevice will take ownership of \a data which will be deleted - when the QIODevice is delected. - - \sa setTargetDevice() -*/ -QAuthDevice *QTransportAuth::recvBuf( QTransportAuth::Data *data, QIODevice *iod ) -{ - return new QAuthDevice( iod, data, QAuthDevice::Receive ); -} - -/*! - Return a QIODevice pointer (to an internal QBuffer) which can be used - to write data onto, for authorization on transport \a d. - - The return QIODevice will act as a pass-through. - - The data written to the return QIODevice will be forwarded on to the - returned QIODevice. In the case of a QTcpSocket, this will cause it - to send out the data with the authentication information on it. - - This will be called in the client process to generate outgoing - authenticated requests. - - The returned QIODevice will take ownership of \a data which will be deleted - when the QIODevice is delected. - - \sa setTargetDevice() -*/ -QAuthDevice *QTransportAuth::authBuf( QTransportAuth::Data *data, QIODevice *iod ) -{ - return new QAuthDevice( iod, data, QAuthDevice::Send ); -} - -const unsigned char *QTransportAuth::getClientKey( unsigned char progId ) -{ - Q_D(QTransportAuth); - return d->getClientKey( progId ); -} - -void QTransportAuth::invalidateClientKeyCache() -{ - Q_D(QTransportAuth); - d->invalidateClientKeyCache(); -} - -QMutex *QTransportAuth::getKeyFileMutex() -{ - Q_D(QTransportAuth); - return &d->keyfileMutex; -} - -/* - \internal - Respond to the destroyed(QObject*) signal of the QAuthDevice's - client object and remove it from the buffersByClient lookup hash. -*/ -void QTransportAuth::bufferDestroyed( QObject *cli ) -{ - Q_D(QTransportAuth); - if ( cli == NULL ) return; - - if ( d->buffersByClient.contains( cli )) - { - d->buffersByClient.remove( cli ); - // qDebug( "@@@@@@@ client %p removed @@@@@@@@@", cli ); - } - // qDebug( " client count %d", d->buffersByClient.count() ); -} - -bool QTransportAuth::authorizeRequest( QTransportAuth::Data &d, const QString &request ) -{ - bool isAuthorized = true; - - if ( !request.isEmpty() && request != QLatin1String("Unknown") ) - { - d.status &= QTransportAuth::ErrMask; // clear the status - emit policyCheck( d, request ); - isAuthorized = (( d.status & QTransportAuth::StatusMask ) == QTransportAuth::Allow ); - } -#if defined(SXE_DISCOVERY) - if (isDiscoveryMode()) { -#ifndef QT_NO_TEXTSTREAM - if (!logFilePath().isEmpty()) { - QFile log( logFilePath() ); - if (!log.open(QIODevice::WriteOnly | QIODevice::Append)) { - qWarning("Could not write to log in discovery mode: %s", - qPrintable(logFilePath())); - } else { - QTextStream ts( &log ); - ts << d.progId << '\t' << ( isAuthorized ? "Allow" : "Deny" ) << '\t' << request << endl; - } - } -#endif - isAuthorized = true; - } -#endif - if ( !isAuthorized ) - { - qWarning( "%s - denied: for Program Id %u [PID %d]" - , qPrintable(request), d.progId, d.processId ); - - char linkTarget[BUF_SIZE]=""; - char exeLink[BUF_SIZE]=""; - char cmdlinePath[BUF_SIZE]=""; - char cmdline[BUF_SIZE]=""; - - //get executable from /proc/pid/exe - snprintf( exeLink, BUF_SIZE, "/proc/%d/exe", d.processId ); - if ( -1 == ::readlink( exeLink, linkTarget, BUF_SIZE - 1 ) ) - { - qWarning( "SXE:- Error encountered in retrieving executable link target from /proc/%u/exe : %s", - d.processId, strerror(errno) ); - snprintf( linkTarget, BUF_SIZE, "%s", linkTarget ); - } - - //get cmdline from proc/pid/cmdline - snprintf( cmdlinePath, BUF_SIZE, "/proc/%d/cmdline", d.processId ); - int cmdlineFd = QT_OPEN( cmdlinePath, O_RDONLY ); - if ( cmdlineFd == -1 ) - { - qWarning( "SXE:- Error encountered in opening /proc/%u/cmdline: %s", - d.processId, strerror(errno) ); - snprintf( cmdline, BUF_SIZE, "%s", "Unknown" ); - } - else - { - if ( -1 == QT_READ(cmdlineFd, cmdline, BUF_SIZE - 1 ) ) - { - qWarning( "SXE:- Error encountered in reading /proc/%u/cmdline : %s", - d.processId, strerror(errno) ); - snprintf( cmdline, BUF_SIZE, "%s", "Unknown" ); - } - QT_CLOSE( cmdlineFd ); - } - - syslog( LOG_ERR | LOG_LOCAL6, "%s // PID:%u // ProgId:%u // Exe:%s // Request:%s // Cmdline:%s", - "<SXE Breach>", d.processId, d.progId, linkTarget, qPrintable(request), cmdline); - } - - return isAuthorized; -} - -inline bool __fileOpen( QFile *f ) -{ -#ifdef QTRANSPORTAUTH_DEBUG - if ( f->open( QIODevice::ReadOnly )) - { - qDebug( "Opened file: %s\n", qPrintable( f->fileName() )); - return true; - } - else - { - qWarning( "Could not open file: %s\n", qPrintable( f->fileName() )); - return false; - } -#else - return ( f->open( QIODevice::ReadOnly )); -#endif -} - -/*! - \internal - Find client keys for the \a progId. If it is cached should be very - fast, otherwise requires a read of the secret key file - - In the success case a pointer to the keys is returned. The pointer is - to storage allocated for the internal cache and must be used asap. - - The list returned is a sequence of one or more keys which match the - progId. There is no separator, each 16 byte sequence represents a key. - The sequence is followed by two iterations of the SXE magic - bytes,eg 0xBA, 0xD4, 0xD4, 0xBA, 0xBA, 0xD4, 0xD4, 0xBA - - NULL is returned in the following cases: - \list - \o the keyfiles could not be accessed - error condition - \o there was no key for the supplied program id - key auth failed - \endlist - - Note that for the keyfiles, there is multi-thread and multi-process - concurrency issues: they can be read by the qpe process when - QTransportAuth calls getClientKey to verify a request, and they can be - read or written by the packagemanager when updating package data. - - To protect against this, the keyfileMutex & SxeRegistryLocker is used. - - The sxe_installer tool can also update inode and device numbers in - the manifest file, but this only occurs outside of normal operation, - so qpe and packagemanager are never running when this occurs. -*/ -const unsigned char *QTransportAuthPrivate::getClientKey(unsigned char progId) -{ - int manifestMatchCount = 0; - struct IdBlock mr; - int total_size = 0; - char *result = 0; - char *result_ptr; - int keysFound = 0; - bool foundKey; - int keysRead = 0; - struct usr_key_entry keys_list[128]; - - if ( keyCache.contains( progId )) - return (const unsigned char *)keyCache[progId]; - - SxeRegistryLocker rlock( m_packageRegistry ); - - // ### Qt 4.3: this is hacky - see documentation for setKeyFilePath - QString manifestPath = m_keyFilePath + QLatin1String("/manifest"); - QString actualKeyPath = QLatin1String("/proc/lids/keys"); - bool noFailOnKeyMissing = true; - if ( !QFile::exists( actualKeyPath )) { - actualKeyPath = m_keyFilePath + QLatin1String( "/" QSXE_KEYFILE ); - } - QFile kf( actualKeyPath ); - QFile mn( manifestPath ); - if ( !__fileOpen( &mn )) - goto key_not_found; - // first find how much storage is needed - while ( mn.read( (char*)&mr, sizeof(struct IdBlock)) > 0 ) - if ( mr.progId == progId ) - manifestMatchCount++; - if ( manifestMatchCount == 0 ) - goto key_not_found; - if ( !__fileOpen( &kf )) - { - noFailOnKeyMissing = false; - goto key_not_found; - } - total_size = 2 * QSXE_MAGIC_BYTES + manifestMatchCount * QSXE_KEY_LEN; - result = (char*)malloc( total_size ); - Q_CHECK_PTR( result ); - mn.seek( 0 ); - result_ptr = result; - /* reading whole key array in is much more efficient, 99% case is this loop only - executes once, should not have more than 128 keyed items */ - while (( keysRead = kf.read( (char*)keys_list, sizeof(struct usr_key_entry)*128 )) > 0 ) - { - /* qDebug("PID %d: getClientKey() - read %d bytes = %d keys from %s", getpid(), keysRead, - keysRead/sizeof(struct usr_key_entry), qPrintable(actualKeyPath)); */ - keysRead /= sizeof(struct usr_key_entry); - while ( mn.read( (char*)&mr, sizeof(struct IdBlock)) > 0 ) - { - if ( mr.progId == progId ) - { - foundKey = false; - for ( int i = 0; i < keysRead; ++i ) - { - /* if ( i == 0 ) - qDebug() << " pid" << getpid() << "looking for device" << (dev_t)mr.device << "inode" << (ino_t)mr.inode; - qDebug() << " pid" << getpid() << "trying device" << keys_list[i].dev << "inode" << keys_list[i].ino; */ - if ( keys_list[i].ino == (ino_t)mr.inode && keys_list[i].dev == (dev_t)mr.device ) - { - memcpy( result_ptr, keys_list[i].key, QSXE_KEY_LEN ); - result_ptr += QSXE_KEY_LEN; - foundKey = true; - break; - } - } - if ( foundKey ) - { - keysFound++; - if ( keysFound == manifestMatchCount ) - break; - } - } - } - } - if ( result_ptr == result ) // nothing found! - goto key_not_found; - // 2 x magic bytes sentinel at end of sequence - for ( int i = 0; i < 2; ++i ) - for ( int j = 0; j < QSXE_MAGIC_BYTES; ++j ) - *result_ptr++ = magic[j]; - keyCache.insert( progId, result, total_size / 10 ); - /* qDebug( "PID %d : Found %d client keys for prog %u", getpid(), keysFound, progId ); */ - goto success_out; - -key_not_found: - if ( noFailOnKeyMissing ) // return an "empty" set of keys in this case - { - if ( result == 0 ) - { - result = (char*)malloc( 2 * QSXE_MAGIC_BYTES ); - Q_CHECK_PTR( result ); - } - result_ptr = result; - for ( int i = 0; i < 2; ++i ) - for ( int j = 0; j < QSXE_MAGIC_BYTES; ++j ) - *result_ptr++ = magic[j]; - return (unsigned char *)result; - } - qWarning( "PID %d : Not found client key for prog %u", getpid(), progId ); - if ( result ) - { - free( result ); - result = 0; - } -success_out: - if ( mn.isOpen() ) - mn.close(); - if ( kf.isOpen() ) - kf.close(); - return (unsigned char *)result; -} - -void QTransportAuthPrivate::invalidateClientKeyCache() -{ - keyfileMutex.lock(); - keyCache.clear(); - keyfileMutex.unlock(); -} - -//////////////////////////////////////////////////////////////////////// -//// -//// RequestAnalyzer definition -//// - - -RequestAnalyzer::RequestAnalyzer() - : moreData( false ) - , dataSize( 0 ) -{ -} - -RequestAnalyzer::~RequestAnalyzer() -{ -} - -/*! - Analzye the data in the\a msgQueue according to some protocol - and produce a request string for policy analysis. - - If enough data is in the queue for analysis of a complete message, - return a non-null string, and set a flag so requireMoreData() will - return false; otherwise return a null string and requireMoreData() - return true. - - The amount of bytes analyzed is then available via bytesAnalyzed(). - - A null string is also returned in the case where the message was - corrupt and could not be analyzed. In this case requireMoreData() - returns false. - -Note: this method will modify the msgQueue and pull off the data - deemed to be corrupt, in the case of corrupt data. - - In all other cases the msgQueue is left alone. The calling code - should then pull off the analyzed data. Use bytesAnalzyed() to - find how much data to pull off the queue. -*/ -QString RequestAnalyzer::analyze( QByteArray *msgQueue ) -{ -#ifdef Q_WS_QWS - dataSize = 0; - moreData = false; - QBuffer cmdBuf( msgQueue ); - cmdBuf.open( QIODevice::ReadOnly | QIODevice::Unbuffered ); - QWSCommand::Type command_type = (QWSCommand::Type)(qws_read_uint( &cmdBuf )); - QWSCommand *command = QWSCommand::factory(command_type); - // if NULL, factory will have already printed warning for bogus - // command_type just purge the bad stuff and attempt to recover - if ( command == NULL ) - { - *msgQueue = msgQueue->mid( sizeof(int) ); - return QString(); - } - QString request = QLatin1String(qws_getCommandTypeString(command_type)); -#ifndef QT_NO_COP - if ( !command->read( &cmdBuf )) - { - // not all command arrived yet - come back later - delete command; - moreData = true; - return QString(); - } - if ( command_type == QWSCommand::QCopSend ) - { - QWSQCopSendCommand *sendCommand = static_cast<QWSQCopSendCommand*>(command); - request += QString::fromLatin1("/QCop/%1/%2").arg( sendCommand->channel ).arg( sendCommand->message ); - } - if ( command_type == QWSCommand::QCopRegisterChannel ) - { - QWSQCopRegisterChannelCommand *registerCommand = static_cast<QWSQCopRegisterChannelCommand*>(command); - request += QString::fromLatin1("/QCop/RegisterChannel/%1").arg( registerCommand->channel ); - } -#endif - dataSize = QWS_PROTOCOL_ITEM_SIZE( *command ); - delete command; - return request; -#else - Q_UNUSED(msgQueue); - return QString(); -#endif -} - -//////////////////////////////////////////////////////////////////////// -//// -//// AuthDevice definition -//// - -/*! - Constructs a new auth device for the transport \a data and I/O device \a parent. - - Incoming or outgoing data will be authenticated according to the auth direction \a dir. - - The auth device will take ownership of the transport \a data and delete it when the device - is destroyed. -*/ -QAuthDevice::QAuthDevice( QIODevice *parent, QTransportAuth::Data *data, AuthDirection dir ) - : QIODevice( parent ) - , d( data ) - , way( dir ) - , m_target( parent ) - , m_client( 0 ) - , m_bytesAvailable( 0 ) - , m_skipWritten( 0 ) - , analyzer( 0 ) -{ - if ( dir == Receive ) // server side - { - connect( m_target, SIGNAL(readyRead()), - this, SLOT(recvReadyRead())); - } else { - connect( m_target, SIGNAL(readyRead()), - this, SIGNAL(readyRead())); - } - connect( m_target, SIGNAL(bytesWritten(qint64)), - this, SLOT(targetBytesWritten(qint64)) ); - open( QIODevice::ReadWrite | QIODevice::Unbuffered ); -} - -QAuthDevice::~QAuthDevice() -{ - if ( analyzer ) - delete analyzer; - delete d; -} - -/*! - \internal - Store a pointer to the related device or instance which this - authorizer is proxying for -*/ -void QAuthDevice::setClient( QObject *cli ) -{ - m_client = cli; - QTransportAuth::getInstance()->d_func()->buffersByClient[cli] = this; - QObject::connect( cli, SIGNAL(destroyed(QObject*)), - QTransportAuth::getInstance(), SLOT(bufferDestroyed(QObject*)) ); - // qDebug( "@@@@@@@@@@@@ client set %p @@@@@@@@@", cli ); - // qDebug( " client count %d", QTransportAuth::getInstance()->d_func()->buffersByClient.count() ); -} - -QObject *QAuthDevice::client() const -{ - return m_client; -} - -/* - \fn void QAuthDevice::authViolation(QTransportAuth::Data &) - - This signal is emitted if an authorization failure is generated, as - described in checkAuth(); - - \sa checkAuth() -*/ - - -/* - \fn void QAuthDevice::policyCheck(QTransportAuth::Data &transport, const QString &request ) - - This signal is emitted when a transport successfully delivers a request - and gives the opportunity to either deny or accept the request. - - This signal must be connected in the same thread, ie it cannot be queued. - - As soon as all handlers connected to this signal are processed the Allow or - Deny state on the \a transport is checked, and the request is allowed or denied - accordingly. - - \sa checkAuth() -*/ - -/*! - \internal - Reimplement QIODevice writeData method. - - For client end, when the device is written to the incoming data is - processed and an authentication header calculated. This is pushed - into the target device, followed by the actual incoming data (the - payload). - - For server end, it is a fatal error to write to the device. -*/ -qint64 QAuthDevice::writeData(const char *data, qint64 len) -{ - if ( way == Receive ) // server - return m_target->write( data, len ); - // client -#ifdef QTRANSPORTAUTH_DEBUG - char displaybuf[1024]; -#endif - char header[QSXE_HEADER_LEN]; - ::memset( header, 0, QSXE_HEADER_LEN ); - qint64 bytes = 0; - if ( QTransportAuth::getInstance()->authToMessage( *d, header, data, len )) - { - m_target->write( header, QSXE_HEADER_LEN ); -#ifdef QTRANSPORTAUTH_DEBUG - hexstring( displaybuf, (const unsigned char *)header, QSXE_HEADER_LEN ); - qDebug( "%d QAuthDevice::writeData - CLIENT: Header written: %s", getpid(), displaybuf ); -#endif - m_skipWritten += QSXE_HEADER_LEN; - } - m_target->write( data, len ); - bytes += len; -#ifdef QTRANSPORTAUTH_DEBUG - int bytesToDisplay = bytes; - const unsigned char *dataptr = (const unsigned char *)data; - while ( bytesToDisplay > 0 ) - { - int amt = bytes < 500 ? bytes : 500; - hexstring( displaybuf, dataptr, amt ); - qDebug( "%d QAuthDevice::writeData - CLIENT: %s", getpid(), bytes > 0 ? displaybuf : "(null)" ); - dataptr += 500; - bytesToDisplay -= 500; - } -#endif - if ( m_target->inherits( "QAbstractSocket" )) - static_cast<QAbstractSocket*>(m_target)->flush(); - return bytes; -} - -/*! - Reimplement from QIODevice - - Read data out of the internal message queue, reduce the queue by the amount - read. Note that the amount available is only ever the size of a command - (although a command can be very big) since we need to check at command - boundaries for new authentication headers. -*/ -qint64 QAuthDevice::readData( char *data, qint64 maxSize ) -{ - if ( way == Send ) // client - return m_target->read( data, maxSize ); - if ( msgQueue.size() == 0 ) - return 0; -#ifdef QTRANSPORTAUTH_DEBUG - char displaybuf[1024]; - hexstring( displaybuf, reinterpret_cast<const unsigned char *>(msgQueue.constData()), - msgQueue.size() > 500 ? 500 : msgQueue.size() ); - qDebug() << getpid() << "QAuthDevice::readData() buffered/requested/avail" - << msgQueue.size() << maxSize << m_bytesAvailable << displaybuf; -#endif - Q_ASSERT( m_bytesAvailable <= msgQueue.size() ); - qint64 bytes = ( maxSize > m_bytesAvailable ) ? m_bytesAvailable : maxSize; - ::memcpy( data, msgQueue.constData(), bytes ); - msgQueue = msgQueue.mid( bytes ); - m_bytesAvailable -= bytes; - return bytes; -} - -/*! - \internal - Receive readyRead signal from the target recv device. In response - authorize the data, and write results out to the recvBuf() device - for processing by the application. Trigger the readyRead signal. - - Authorizing involves first checking the transport is valid, ie the - handshake has either already been done and is cached on a trusted - transport, or was valid with this message; then second passing the - string representation of the service request up to any policyReceivers - - If either of these fail, the message is denied. In discovery mode - denied messages are allowed, but the message is logged. -*/ -void QAuthDevice::recvReadyRead() -{ - qint64 bytes = m_target->bytesAvailable(); - if ( bytes <= 0 ) return; - open( QIODevice::ReadWrite | QIODevice::Unbuffered ); - QUnixSocket *usock = static_cast<QUnixSocket*>(m_target); - QUnixSocketMessage msg = usock->read(); - msgQueue.append( msg.bytes() ); - d->processId = msg.processId(); - // if "fragmented" packet 1/2 way through start of a command, ie - // in the QWS msg type, cant do anything, come back later when - // there's more of the packet - if ( msgQueue.size() < (int)sizeof(int) ) - { - // qDebug() << "returning: msg size too small" << msgQueue.size(); - return; - } -#ifdef QTRANSPORTAUTH_DEBUG - char displaybuf[1024]; - hexstring( displaybuf, reinterpret_cast<const unsigned char *>(msgQueue.constData()), - msgQueue.size() > 500 ? 500 : msgQueue.size() ); - qDebug( "%d ***** SERVER read %lli bytes - msg %s", getpid(), bytes, displaybuf ); -#endif - - bool bufHasMessages = msgQueue.size() >= (int)sizeof(int); - while ( bufHasMessages ) - { - unsigned char saveStatus = d->status; - if (( d->status & QTransportAuth::ErrMask ) == QTransportAuth::NoSuchKey ) - { - QTransportAuth::getInstance()->authorizeRequest( *d, QLatin1String("NoSuchKey") ); - break; - } - if ( !QTransportAuth::getInstance()->authFromMessage( *d, msgQueue, msgQueue.size() )) - { - // not all arrived yet? come back later - if (( d->status & QTransportAuth::ErrMask ) == QTransportAuth::TooSmall ) - { - d->status = saveStatus; - return; - } - } - if (( d->status & QTransportAuth::ErrMask ) == QTransportAuth::NoMagic ) - { - // no msg auth header, don't change the success status for connections - if ( d->connection() ) - d->status = saveStatus; - } - else - { - // msg auth header detected and auth determined, remove hdr - msgQueue = msgQueue.mid( QSXE_HEADER_LEN ); - } - if ( !authorizeMessage() ) - break; - bufHasMessages = msgQueue.size() >= (int)sizeof(int); - } -} - -/** - \internal - Handle bytesWritten signals from the underlying target device. - We adjust the target's value for bytes that are part of auth packets. -*/ -void QAuthDevice::targetBytesWritten( qint64 bytes ) -{ - if ( m_skipWritten >= bytes ) { - m_skipWritten -= bytes; - bytes = 0; - } else if ( m_skipWritten > 0 ) { - bytes -= m_skipWritten; - m_skipWritten = 0; - } - if ( bytes > 0 ) { - emit bytesWritten( bytes ); - } -} - -/** - \internal - Pre-process the message to determine what QWS command it is. This - information is used as the "request" for the purposes of authorization. - - The request and other data on the connection (id, PID, etc.) are forwarded - to all policy listeners by emitting a signal. - - The signal must be processed synchronously because on return the allow/deny - status is used immediately to either drop or continue processing the message. -*/ -bool QAuthDevice::authorizeMessage() -{ - if ( analyzer == NULL ) - analyzer = new RequestAnalyzer(); - QString request = (*analyzer)( &msgQueue ); - if ( analyzer->requireMoreData() ) - return false; - bool isAuthorized = true; - - if ( !request.isEmpty() && request != QLatin1String("Unknown") ) - { - isAuthorized = QTransportAuth::getInstance()->authorizeRequest( *d, request ); - } - - bool moreToProcess = ( msgQueue.size() - analyzer->bytesAnalyzed() ) > (int)sizeof(int); - if ( isAuthorized ) - { -#ifdef QTRANSPORTAUTH_DEBUG - qDebug() << getpid() << "SERVER authorized: releasing" << analyzer->bytesAnalyzed() << "byte command" << request; -#endif - m_bytesAvailable = analyzer->bytesAnalyzed(); - emit QIODevice::readyRead(); - return moreToProcess; - } - else - { - msgQueue = msgQueue.mid( analyzer->bytesAnalyzed() ); - } - - return true; -} - -void QAuthDevice::setRequestAnalyzer( RequestAnalyzer *ra ) -{ - Q_ASSERT( ra ); - if ( analyzer ) - delete analyzer; - analyzer = ra; -} - -/*! - \internal - Add authentication header to the beginning of a message - - Note that the per-process auth cookie is used. This key should be rewritten in - the binary image of the executable at install time to make it unique. - - For this to be secure some mechanism (eg MAC kernel or other - permissions) must prevent other processes from reading the key. - - The buffer must have AUTH_SPACE(0) bytes spare at the beginning for the - authentication header to be added. - - Returns true if header successfully added. Will fail if the - per-process key has not yet been set with setProcessKey() -*/ -bool QTransportAuth::authToMessage( QTransportAuth::Data &d, char *hdr, const char *msg, int msgLen ) -{ - // qDebug( "authToMessage(): prog id %u", d.progId ); - // only authorize connection oriented transports once, unless key has changed - if ( d.connection() && ((d.status & QTransportAuth::ErrMask) != QTransportAuth::Pending) && - d_func()->authKey.progId == d.progId ) - return false; - d.progId = d_func()->authKey.progId; - // If Unix socket credentials are being used the key wont be set - if ( !d_func()->keyInitialised ) - return false; - unsigned char digest[QSXE_KEY_LEN]; - char *msgPtr = hdr; - // magic always goes on the beginning - for ( int m = 0; m < QSXE_MAGIC_BYTES; ++m ) - *msgPtr++ = magic[m]; - hdr[ QSXE_LEN_IDX ] = (unsigned char)msgLen; - if ( !d.trusted()) - { - // Use HMAC - int rc = hmac_md5( (unsigned char *)msg, msgLen, d_func()->authKey.key, QSXE_KEY_LEN, digest ); - if ( rc == -1 ) - return false; - memcpy( hdr + QSXE_KEY_IDX, digest, QSXE_KEY_LEN ); - } - else - { - memcpy( hdr + QSXE_KEY_IDX, d_func()->authKey.key, QSXE_KEY_LEN ); - } - - hdr[ QSXE_PROG_IDX ] = d_func()->authKey.progId; - -#ifdef QTRANSPORTAUTH_DEBUG - char keydisplay[QSXE_KEY_LEN*2+1]; - hexstring( keydisplay, d_func()->authKey.key, QSXE_KEY_LEN ); - - qDebug( "%d CLIENT Auth to message %s against prog id %u and key %s\n", - getpid(), msg, d_func()->authKey.progId, keydisplay ); -#endif - - // TODO implement sequence to prevent replay attack, not required - // for trusted transports - hdr[ QSXE_SEQ_IDX ] = 1; // dummy sequence - - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::Success; - return true; -} - - -/*! - Check authorization on the \a msg, which must be of size \a msgLen, - for the transport \a d. - - If able to determine authorization, return the program identity of - the message source in the reference \a progId, and return true. - - Otherwise return false. - - If data is being received on a socket, it may be that more data is yet - needed before authentication can proceed. - - Also the message may not be an authenticated at all. - - In these cases the method returns false to indicate authorization could - not be determined: - \list - \i The message is too small to carry the authentication data - (status TooSmall is set on the \a d transport ) - \i The 4 magic bytes are missing from the message start - (status NoMagic is set on the \a d transport ) - \i The message is too small to carry the auth + claimed payload - (status TooSmall is set on the \a d transport ) - \endlist - - If however the authentication header (preceded by the magic bytes) and - any authenticated payload is received the method will determine the - authentication status, and return true. - - In the following cases as well as returning true it will also emit - an authViolation(): - \list - \i If the program id claimed by the message is not found in the key file - (status NoSuchKey is set on the \a d transport ) - \i The authentication token failed against the claimed program id: - \list - \i in the case of trusted transports, the secret did not match - \i in the case of untrusted transports the HMAC code did not match - \endlist - (status FailMatch is set on the \a d transport ) - \endlist - - In these cases the authViolation( QTransportAuth::Data d ) signal is emitted - and the error string can be obtained from the status like this: - \snippet doc/src/snippets/code/src_gui_embedded_qtransportauth_qws.cpp 4 -*/ -bool QTransportAuth::authFromMessage( QTransportAuth::Data &d, const char *msg, int msgLen ) -{ - if ( msgLen < QSXE_MAGIC_BYTES ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::TooSmall; - return false; - } - // if no magic bytes, exit straight away - int m; - const unsigned char *mptr = reinterpret_cast<const unsigned char *>(msg); - for ( m = 0; m < QSXE_MAGIC_BYTES; ++m ) - { - if ( *mptr++ != magic[m] ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::NoMagic; - return false; - } - } - - if ( msgLen < AUTH_SPACE(1) ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::TooSmall; - return false; - } - - // At this point we know the header is at least long enough to contain valid auth - // data, however the data may be spoofed. If it is not verified then the status will - // be set to uncertified so the spoofed data will not be relied on. However we want to - // know the program id which is being reported (even if it might be spoofed) for - // policy debugging purposes. So set it here, rather than after verification. - d.progId = msg[QSXE_PROG_IDX]; - -#ifdef QTRANSPORTAUTH_DEBUG - char authhdr[QSXE_HEADER_LEN*2+1]; - hexstring( authhdr, reinterpret_cast<const unsigned char *>(msg), QSXE_HEADER_LEN ); - qDebug( "%d SERVER authFromMessage(): message header is %s", - getpid(), authhdr ); -#endif - - unsigned char authLen = (unsigned char)(msg[ QSXE_LEN_IDX ]); - - if ( msgLen < AUTH_SPACE(authLen) ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::TooSmall; - return false; - } - - bool isCached = d_func()->keyCache.contains( d.progId ); - const unsigned char *clientKey = d_func()->getClientKey( d.progId ); - if ( clientKey == NULL ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::NoSuchKey; - return false; - } - -#ifdef QTRANSPORTAUTH_DEBUG - char keydisplay[QSXE_KEY_LEN*2+1]; - hexstring( keydisplay, clientKey, QSXE_KEY_LEN ); - qDebug( "\t\tauthFromMessage(): message %s against prog id %u and key %s\n", - AUTH_DATA(msg), ((unsigned int)d.progId), keydisplay ); -#endif - - const unsigned char *auth_tok; - unsigned char digest[QSXE_KEY_LEN]; - bool multi_tok = false; - - bool need_to_recheck=false; - do - { - if ( !d.trusted()) - { - hmac_md5( AUTH_DATA(msg), authLen, clientKey, QSXE_KEY_LEN, digest ); - auth_tok = digest; - } - else - { - auth_tok = clientKey; - multi_tok = true; // 1 or more keys are in the clientKey - } - while( true ) - { - if ( memcmp( auth_tok, magic, QSXE_MAGIC_BYTES ) == 0 - && memcmp( auth_tok + QSXE_MAGIC_BYTES, magic, QSXE_MAGIC_BYTES ) == 0 ) - break; - if ( memcmp( msg + QSXE_KEY_IDX, auth_tok, QSXE_KEY_LEN ) == 0 ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::Success; - return true; - } - if ( !multi_tok ) - break; - auth_tok += QSXE_KEY_LEN; - } - //the keys cached on d.progId may not contain the binary key because the cache entry was made - //before the binary had first started, must search for client key again. - if ( isCached ) - { - d_func()->keyCache.remove(d.progId); - isCached = false; - -#ifdef QTRANSPORTAUTH_DEBUG - qDebug() << "QTransportAuth::authFromMessage(): key not found in set of keys cached" - << "against prog Id =" << d.progId << ". Re-obtaining client key. "; -#endif - clientKey = d_func()->getClientKey( d.progId ); - if ( clientKey == NULL ) - { - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::NoSuchKey; - return false; - } - need_to_recheck = true; - } - else - { - need_to_recheck = false; - } - } while( need_to_recheck ); - - d.status = ( d.status & QTransportAuth::StatusMask ) | QTransportAuth::FailMatch; - qWarning() << "QTransportAuth::authFromMessage():failed authentication"; - FAREnforcer::getInstance()->logAuthAttempt( QDateTime::currentDateTime() ); - emit authViolation( d ); - return false; -} - - -#ifdef QTRANSPORTAUTH_DEBUG -/*! - sprintf into hex - dest \a buf, src \a key, \a key_len is length of key. - - The target buf should be [ key_len * 2 + 1 ] in size -*/ -void hexstring( char *buf, const unsigned char* key, size_t key_len ) -{ - unsigned int i, p; - for ( i = 0, p = 0; i < key_len; i++, p+=2 ) - { - unsigned char lo_nibble = key[i] & 0x0f; - unsigned char hi_nibble = key[i] >> 4; - buf[p] = (int)hi_nibble > 9 ? hi_nibble-10 + 'A' : hi_nibble + '0'; - buf[p+1] = (int)lo_nibble > 9 ? lo_nibble-10 + 'A' : lo_nibble + '0'; - } - buf[p] = '\0'; -} -#endif - -/* - HMAC MD5 as listed in RFC 2104 - - This code is taken from: - - http://www.faqs.org/rfcs/rfc2104.html - - with the allowance for keys other than length 16 removed, but otherwise - a straight cut-and-paste. - - The HMAC_MD5 transform looks like: - - \snippet doc/src/snippets/code/src.gui.embedded.qtransportauth_qws.cpp 5 - - \list - \i where K is an n byte key - \i ipad is the byte 0x36 repeated 64 times - \i opad is the byte 0x5c repeated 64 times - \i and text is the data being protected - \endlist - - Hardware is available with accelerated implementations of HMAC-MD5 and - HMAC-SHA1. Where this hardware is available, this routine should be - replaced with a call into the accelerated version. -*/ - -static int hmac_md5( - unsigned char* text, /* pointer to data stream */ - int text_length, /* length of data stream */ - const unsigned char* key, /* pointer to authentication key */ - int key_length, /* length of authentication key */ - unsigned char * digest /* caller digest to be filled in */ - ) -{ - MD5Context context; - unsigned char k_ipad[65]; /* inner padding - * key XORd with ipad */ - unsigned char k_opad[65]; /* outer padding - * key XORd with opad */ - int i; - - /* in this implementation key_length == 16 */ - if ( key_length != 16 ) - { - fprintf( stderr, "Key length was %d - must be 16 bytes", key_length ); - return 0; - } - - /* start out by storing key in pads */ - memset( k_ipad, 0, sizeof k_ipad ); - memset( k_opad, 0, sizeof k_opad ); - memcpy( k_ipad, key, key_length ); - memcpy( k_opad, key, key_length ); - - /* XOR key with ipad and opad values */ - for (i=0; i<64; i++) { - k_ipad[i] ^= 0x36; - k_opad[i] ^= 0x5c; - } - - /* perform inner MD5 */ - MD5Init(&context); /* init context for 1st pass */ - MD5Update(&context, k_ipad, 64); /* start with inner pad */ - MD5Update(&context, text, text_length); /* then text of datagram */ - MD5Final(&context, digest); /* finish up 1st pass */ - - /* perform outer MD5 */ - MD5Init(&context); /* init context for 2nd pass */ - MD5Update(&context, k_opad, 64); /* start with outer pad */ - MD5Update(&context, digest, 16); /* then results of 1st * hash */ - MD5Final(&context, digest); /* finish up 2nd pass */ - return 1; -} - - -const int FAREnforcer::minutelyRate = 4; //allowed number of false authentication attempts per minute -const QString FAREnforcer::FARMessage = QLatin1String("FAR_Exceeded"); -const QString FAREnforcer::SxeTag = QLatin1String("<SXE Breach>"); -const int FAREnforcer::minute = 60; - -FAREnforcer::FAREnforcer():authAttempts() -{ - QDateTime nullDateTime = QDateTime(); - for (int i = 0; i < minutelyRate; i++ ) - authAttempts << nullDateTime; -} - - -FAREnforcer *FAREnforcer::getInstance() -{ - static FAREnforcer theInstance; - return &theInstance; -} - -void FAREnforcer::logAuthAttempt( QDateTime time ) -{ - QDateTime dt = authAttempts.takeFirst(); - - authAttempts.append( time ); - if ( dt.secsTo( authAttempts.last() ) <= minute ) - { -#if defined(SXE_DISCOVERY) - if ( QTransportAuth::getInstance()->isDiscoveryMode() ) { - static QBasicAtomicInt reported = Q_BASIC_ATOMIC_INITIALIZER(0); - if ( reported.testAndSetRelaxed(0,1) ) { -#ifndef QT_NO_TEXTSTREAM - QString logFilePath = QTransportAuth::getInstance()->logFilePath(); - if ( !logFilePath.isEmpty() ) { - QFile log( logFilePath ); - if ( !log.open(QIODevice::WriteOnly | QIODevice::Append) ) { - qWarning("Could not write to log in discovery mode: %s", - qPrintable(logFilePath) ); - } else { - QTextStream ts( &log ); - ts << "\t\tWarning: False Authentication Rate of " << minutelyRate << "\n" - << "\t\tserver connections/authentications per minute has been exceeded,\n" - << "\t\tno further warnings will be issued\n"; - } - } - } -#endif - reset(); - return; - } -#endif - syslog( LOG_ERR | LOG_LOCAL6, "%s %s", - qPrintable( FAREnforcer::SxeTag ), - qPrintable( FAREnforcer::FARMessage ) ); - reset(); - } -} - -void FAREnforcer::reset() -{ - QDateTime nullDateTime = QDateTime(); - for (int i = 0; i < minutelyRate; i++ ) - authAttempts[i] = nullDateTime; -} - -QT_END_NAMESPACE - -#include "moc_qtransportauth_qws_p.cpp" - -#endif // QT_NO_SXE diff --git a/src/gui/embedded/qtransportauth_qws.h b/src/gui/embedded/qtransportauth_qws.h deleted file mode 100644 index cd89e0f3aa..0000000000 --- a/src/gui/embedded/qtransportauth_qws.h +++ /dev/null @@ -1,281 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTRANSPORTAUTH_QWS_H -#define QTRANSPORTAUTH_QWS_H - -#include <QtCore/qglobal.h> - -#if !defined(QT_NO_SXE) || defined(SXE_INSTALLER) - -#include <QtCore/qobject.h> -#include <QtCore/qhash.h> -#include <QtCore/qstring.h> -#include <QtCore/qbuffer.h> -#include <QtCore/qpointer.h> - -#include <sys/types.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QAuthDevice; -class QWSClient; -class QIODevice; -class QTransportAuthPrivate; -class QMutex; - -class Q_GUI_EXPORT QTransportAuth : public QObject -{ - Q_OBJECT -public: - static QTransportAuth *getInstance(); - - enum Result { - // Error codes - Pending = 0x00, - TooSmall = 0x01, - CacheMiss = 0x02, - NoMagic = 0x03, - NoSuchKey = 0x04, - FailMatch = 0x05, - OutOfDate = 0x06, - // reserved for expansion - Success = 0x1e, - ErrMask = 0x1f, - - // Verification codes - Allow = 0x20, - Deny = 0x40, - Ask = 0x60, - // reserved - StatusMask = 0xe0 - }; - - enum Properties { - Trusted = 0x01, - Connection = 0x02, - UnixStreamSock = 0x04, - SharedMemory = 0x08, - MessageQueue = 0x10, - UDP = 0x20, - TCP = 0x40, - UserDefined = 0x80, - TransportType = 0xfc - }; - - struct Data - { - Data() { processId = -1; } - Data( unsigned char p, int d ) - : properties( p ) - , descriptor( d ) - , processId( -1 ) - { - if (( properties & TransportType ) == TCP || - ( properties & TransportType ) == UnixStreamSock ) - properties |= Connection; - } - - unsigned char properties; - unsigned char progId; - unsigned char status; - unsigned int descriptor; // socket fd or shmget key - pid_t processId; - - bool trusted() const; - void setTrusted( bool ); - bool connection() const; - void setConnection( bool ); - }; - - static const char *errorString( const QTransportAuth::Data & ); - - QTransportAuth::Data *connectTransport( unsigned char, int ); - - QAuthDevice *authBuf( QTransportAuth::Data *, QIODevice * ); - QAuthDevice *recvBuf( QTransportAuth::Data *, QIODevice * ); - QIODevice *passThroughByClient( QWSClient * ) const; - - void setKeyFilePath( const QString & ); - QString keyFilePath() const; - const unsigned char *getClientKey( unsigned char progId ); - void invalidateClientKeyCache(); - QMutex *getKeyFileMutex(); - void setLogFilePath( const QString & ); - QString logFilePath() const; - void setPackageRegistry( QObject *registry ); - bool isDiscoveryMode() const; - void setProcessKey( const char * ); - void setProcessKey( const char *, const char * ); - void registerPolicyReceiver( QObject * ); - void unregisterPolicyReceiver( QObject * ); - - bool authToMessage( QTransportAuth::Data &d, char *hdr, const char *msg, int msgLen ); - bool authFromMessage( QTransportAuth::Data &d, const char *msg, int msgLen ); - - bool authorizeRequest( QTransportAuth::Data &d, const QString &request ); - -Q_SIGNALS: - void policyCheck( QTransportAuth::Data &, const QString & ); - void authViolation( QTransportAuth::Data & ); -private Q_SLOTS: - void bufferDestroyed( QObject * ); - -private: - // users should never construct their own - QTransportAuth(); - ~QTransportAuth(); - - friend class QAuthDevice; - Q_DECLARE_PRIVATE(QTransportAuth) -}; - -class Q_GUI_EXPORT RequestAnalyzer -{ -public: - RequestAnalyzer(); - virtual ~RequestAnalyzer(); - QString operator()( QByteArray *data ) { return analyze( data ); } - bool requireMoreData() const { return moreData; } - qint64 bytesAnalyzed() const { return dataSize; } -protected: - virtual QString analyze( QByteArray * ); - bool moreData; - qint64 dataSize; -}; - -/*! - \internal - \class QAuthDevice - - \brief Pass-through QIODevice sub-class for authentication. - - Use this class to forward on or receive forwarded data over a real - device for authentication. -*/ -class Q_GUI_EXPORT QAuthDevice : public QIODevice -{ - Q_OBJECT -public: - enum AuthDirection { - Receive, - Send - }; - QAuthDevice( QIODevice *, QTransportAuth::Data *, AuthDirection ); - ~QAuthDevice(); - void setTarget( QIODevice *t ) { m_target = t; } - QIODevice *target() const { return m_target; } - void setClient( QObject* ); - QObject *client() const; - void setRequestAnalyzer( RequestAnalyzer * ); - bool isSequential() const; - bool atEnd() const; - qint64 bytesAvailable() const; - qint64 bytesToWrite() const; - bool seek( qint64 ); - QByteArray & buffer(); - -protected: - qint64 readData( char *, qint64 ); - qint64 writeData(const char *, qint64 ); -private Q_SLOTS: - void recvReadyRead(); - void targetBytesWritten( qint64 ); -private: - bool authorizeMessage(); - - QTransportAuth::Data *d; - AuthDirection way; - QIODevice *m_target; - QObject *m_client; - QByteArray msgQueue; - qint64 m_bytesAvailable; - qint64 m_skipWritten; - - RequestAnalyzer *analyzer; -}; - -inline bool QAuthDevice::isSequential() const -{ - return true; -} - -inline bool QAuthDevice::seek( qint64 ) -{ - return false; -} - -inline bool QAuthDevice::atEnd() const -{ - return msgQueue.isEmpty(); -} - -inline qint64 QAuthDevice::bytesAvailable() const -{ - if ( way == Receive ) - return m_bytesAvailable; - else - return ( m_target ? m_target->bytesAvailable() : 0 ); -} - -inline qint64 QAuthDevice::bytesToWrite() const -{ - return msgQueue.size(); -} - -inline QByteArray &QAuthDevice::buffer() -{ - return msgQueue; -} - - - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_SXE -#endif // QTRANSPORTAUTH_QWS_H diff --git a/src/gui/embedded/qtransportauth_qws_p.h b/src/gui/embedded/qtransportauth_qws_p.h deleted file mode 100644 index 9cdbaaf26a..0000000000 --- a/src/gui/embedded/qtransportauth_qws_p.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTRANSPORTAUTH_QWS_P_H -#define QTRANSPORTAUTH_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_SXE - -#include "qtransportauth_qws.h" -#include "qtransportauthdefs_qws.h" -#include "qbuffer.h" - -#include <qmutex.h> -#include <qdatetime.h> -#include "private/qobject_p.h" - -#include <QtCore/qcache.h> - -QT_BEGIN_NAMESPACE - -// Uncomment to generate debug output -// #define QTRANSPORTAUTH_DEBUG 1 - -#ifdef QTRANSPORTAUTH_DEBUG -void hexstring( char *buf, const unsigned char* key, size_t sz ); -#endif - -// proj id for ftok usage in sxe -#define SXE_PROJ 10022 - -/*! - \internal - memset for security purposes, guaranteed not to be optimized away - http://www.faqs.org/docs/Linux-HOWTO/Secure-Programs-HOWTO.html -*/ -void *guaranteed_memset(void *v,int c,size_t n); - -class QUnixSocketMessage; - -/*! - \internal - \class AuthCookie - Struct to carry process authentication key and id -*/ -#define QSXE_HEADER_LEN 24 - -/*! - \macro AUTH_ID - Macro to manage authentication header. Format of header is: - \table - \header \i BYTES \i CONTENT - \row \i 0-3 \i magic numbers - \row \i 4 \i length of authenticated data (max 255 bytes) - \row i\ 5 \i reserved - \row \i 6-21 \i MAC digest, or shared secret in case of simple auth - \row \i 22 \i program id - \row \i 23 \i sequence number - \endtable - Total length of the header is 24 bytes - - However this may change. Instead of coding these numbers use the AUTH_ID, - AUTH_KEY, AUTH_DATA and AUTH_SPACE macros. -*/ - -#define AUTH_ID(k) ((unsigned char)(k[QSXE_KEY_LEN])) -#define AUTH_KEY(k) ((unsigned char *)(k)) - -#define AUTH_DATA(x) (unsigned char *)((x) + QSXE_HEADER_LEN) -#define AUTH_SPACE(x) ((x) + QSXE_HEADER_LEN) -#define QSXE_LEN_IDX 4 -#define QSXE_KEY_IDX 6 -#define QSXE_PROG_IDX 22 -#define QSXE_SEQ_IDX 23 - -class SxeRegistryLocker : public QObject -{ - Q_OBJECT -public: - SxeRegistryLocker( QObject * ); - ~SxeRegistryLocker(); - bool success() const { return m_success; } -private: - bool m_success; - QObject *m_reg; -}; - -class QTransportAuthPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QTransportAuth) -public: - QTransportAuthPrivate(); - ~QTransportAuthPrivate(); - - const unsigned char *getClientKey( unsigned char progId ); - void invalidateClientKeyCache(); - - bool keyInitialised; - QString m_logFilePath; - QString m_keyFilePath; - QObject *m_packageRegistry; - AuthCookie authKey; - QCache<unsigned char, char> keyCache; - QHash< QObject*, QIODevice*> buffersByClient; - QMutex keyfileMutex; -}; - -/*! - \internal - Enforces the False Authentication Rate. If more than 4 authentications - are received per minute the sxemonitor is notified that the FAR has been exceeded -*/ -class FAREnforcer -{ - public: - static FAREnforcer *getInstance(); - void logAuthAttempt( QDateTime time = QDateTime::currentDateTime() ); - void reset(); - -#ifndef TEST_FAR_ENFORCER - private: -#endif - FAREnforcer(); - FAREnforcer( const FAREnforcer & ); - FAREnforcer &operator=(FAREnforcer const & ); - - static const QString FARMessage; - static const int minutelyRate; - static const QString SxeTag; - static const int minute; - - QList<QDateTime> authAttempts; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_SXE -#endif // QTRANSPORTAUTH_QWS_P_H - diff --git a/src/gui/embedded/qtransportauthdefs_qws.h b/src/gui/embedded/qtransportauthdefs_qws.h deleted file mode 100644 index a6d39fb425..0000000000 --- a/src/gui/embedded/qtransportauthdefs_qws.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTRANSPORTAUTHDEFS_QWS_H -#define QTRANSPORTAUTHDEFS_QWS_H - -#include <sys/types.h> -#include <string.h> - -#include <QtCore/qglobal.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#define QSXE_KEY_LEN 16 -#define QSXE_MAGIC_BYTES 4 - -// Number of bytes of each message to authenticate. Just need to ensure -// that the command at the beginning hasn't been tampered with. This value -// does not matter for trusted transports. -#define AMOUNT_TO_AUTHENTICATE 200 - -#define AUTH_ID(k) ((unsigned char)(k[QSXE_KEY_LEN])) -#define AUTH_KEY(k) ((unsigned char *)(k)) - -// must be a largish -ve number under any endianess when cast as an int -const unsigned char magic[QSXE_MAGIC_BYTES] = { 0xBA, 0xD4, 0xD4, 0xBA }; -const int magicInt = 0xBAD4D4BA; - -#define QSXE_KEYFILE "keyfile" - -/* - Header in above format, less the magic bytes. - Useful for reading off the socket -*/ -struct AuthHeader -{ - unsigned char len; - unsigned char pad; - unsigned char digest[QSXE_KEY_LEN]; - unsigned char id; - unsigned char seq; -}; - -/* - Header in a form suitable for authentication routines -*/ -struct AuthMessage -{ - AuthMessage() - { - ::memset( authData, 0, sizeof(authData) ); - ::memcpy( pad_magic, magic, QSXE_MAGIC_BYTES ); - } - unsigned char pad_magic[QSXE_MAGIC_BYTES]; - union { - AuthHeader hdr; - char authData[sizeof(AuthHeader)]; - }; - char payLoad[AMOUNT_TO_AUTHENTICATE]; -}; - -/** - Auth data as stored in _key -*/ -struct AuthCookie -{ - unsigned char key[QSXE_KEY_LEN]; - unsigned char pad; - unsigned char progId; -}; - -/* - Auth data as written to the key file - SUPERSEDED by usr_key_entry - - This is still used internally for some functions, ie the socket - related calls. -*/ -struct AuthRecord -{ - union { - AuthCookie auth; - char data[sizeof(struct AuthCookie)]; - }; - time_t change_time; -}; - -/*! - \class usr_key_entry - This comes from the SXE kernel patch file include/linux/lidsif.h - - This is the (new) data record for the key file (version 2). - - The key file is (now) either /proc/lids/keys (and the per-process - keys in /proc/<pid>/lids_key) OR for desktop/development ONLY (not - for production) it is $QPEDIR/etc/keyfile - - The key file maps keys to files. - - File are identified by inode and device numbers, not paths. - - (See the "installs" file for path to inode/device mapping) -*/ -struct usr_key_entry -{ - char key[QSXE_KEY_LEN]; - ino_t ino; - dev_t dev; -}; - - -/*! - \class IdBlock - \brief Data record for the manifest file. - The manifest file maps program id's to files -*/ -struct IdBlock -{ - quint64 inode; - quint64 device; - unsigned char pad; - unsigned char progId; - unsigned short installId; - unsigned int keyOffset; - qint64 install_time; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTRANSPORTAUTHDEFS_QWS_H - diff --git a/src/gui/embedded/qwindowsystem_qws.cpp b/src/gui/embedded/qwindowsystem_qws.cpp deleted file mode 100644 index 0d1ae0d2d2..0000000000 --- a/src/gui/embedded/qwindowsystem_qws.cpp +++ /dev/null @@ -1,4960 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" - -#include "qwindowsystem_qws.h" -#include "qwsevent_qws.h" -#include "qwscommand_qws_p.h" -#include "qtransportauth_qws_p.h" -#include "qwsutils_qws.h" -#include "qwscursor_qws.h" -#include "qwsdisplay_qws.h" -#include "qmouse_qws.h" -#include "qcopchannel_qws.h" -#include "qwssocket_qws.h" - -#include "qapplication.h" -#include "private/qapplication_p.h" -#include "qsocketnotifier.h" -#include "qpolygon.h" -#include "qimage.h" -#include "qcursor.h" -#include <private/qpaintengine_raster_p.h> -#include "qscreen_qws.h" -#include "qwindowdefs.h" -#include "private/qlock_p.h" -#include "qwslock_p.h" -#include "qfile.h" -#include "qtimer.h" -#include "qpen.h" -#include "qdesktopwidget.h" -#include "qevent.h" -#include "qinputcontext.h" -#include "qpainter.h" - -#include <qdebug.h> - -#include "qkbddriverfactory_qws.h" -#include "qmousedriverfactory_qws.h" - -#include <qbuffer.h> -#include <qdir.h> - -#include <private/qwindowsurface_qws_p.h> -#include <private/qfontengine_qpf_p.h> - -#include "qwindowsystem_p.h" - - -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> - -#ifndef QT_NO_QWS_MULTIPROCESS -#include <sys/param.h> -#include <sys/mount.h> -#endif - -#if !defined(QT_NO_SOUND) && !defined(Q_OS_DARWIN) -#ifdef QT_USE_OLD_QWS_SOUND -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/soundcard.h> -#else -#include "qsoundqss_qws.h" -#endif -#endif - -//#define QWS_DEBUG_FONTCLEANUP - -QT_BEGIN_NAMESPACE - -QWSServer Q_GUI_EXPORT *qwsServer=0; -static QWSServerPrivate *qwsServerPrivate=0; - -#define MOUSE 0 -#define KEY 1 -//#define EVENT_BLOCK_DEBUG - -QWSScreenSaver::~QWSScreenSaver() -{ -} - -extern QByteArray qws_display_spec; -extern void qt_init_display(); //qapplication_qws.cpp -extern QString qws_qtePipeFilename(); - -extern void qt_client_enqueue(const QWSEvent *); //qapplication_qws.cpp -extern QList<QWSCommand*> *qt_get_server_queue(); - -Q_GLOBAL_STATIC_WITH_ARGS(QString, defaultMouse, (QLatin1String("Auto"))) -Q_GLOBAL_STATIC_WITH_ARGS(QString, defaultKeyboard, (QLatin1String("TTY"))) -static const int FontCleanupInterval = 60 * 1000; - -static int qws_keyModifiers = 0; - -static QWSWindow *keyboardGrabber; -static bool keyboardGrabbing; - -static int get_object_id(int count = 1) -{ - static int next=1000; - int n = next; - next += count; - return n; -} -#ifndef QT_NO_QWS_INPUTMETHODS -static QWSInputMethod *current_IM = 0; - -static QWSWindow *current_IM_composing_win = 0; -static int current_IM_winId = -1; -static bool force_reject_strokeIM = false; -#endif - -static void cleanupFontsDir(); - -//#define QWS_REGION_DEBUG - -/*! - \class QWSScreenSaver - \ingroup qws - - \brief The QWSScreenSaver class is a base class for screensavers - in Qt for Embedded Linux. - - When running \l{Qt for Embedded Linux} applications, it is the server - application that installs and controls the screensaver. - \l{Qt for Embedded Linux} supports multilevel screen saving; i.e., it is possible to - specify several different levels of screen responsiveness. For - example, you can choose to first turn off the light before you - fully activate the screensaver. - - Note that there exists no default screensaver implementation. - - To create a custom screensaver, derive from this class and - reimplement the restore() and save() functions. These functions - are called whenever the screensaver is activated or deactivated, - respectively. Once an instance of your custom screensaver is - created, you can use the QWSServer::setScreenSaver() function to - install it. - - \sa QWSServer, QScreen, {Qt for Embedded Linux} -*/ - -/*! - \fn QWSScreenSaver::~QWSScreenSaver() - - Reimplement this function to destroy the screensaver. -*/ - -/*! - \fn QWSScreenSaver::restore() - - Implement this function to deactivate the screensaver, restoring - the previously saved screen. - - \sa save(), QWSServer::screenSaverActivate() -*/ - -/*! - \fn QWSScreenSaver::save(int level) - - Implement this function to activate the screensaver, saving the - current screen. - - \l{Qt for Embedded Linux} supports multilevel screen saving; i.e., it is - possible to specify several different levels of screen - responsiveness. For example, you can choose to first turn off the - light before you fully activate the screensaver. Use the - QWSServer::setScreenSaverIntervals() to specify the time intervals - between the different levels. - - This function should return true if the screensaver successfully - enters the given \a level; otherwise it should return false. - - \sa restore(), QWSServer::screenSaverActivate() -*/ - -class QWSWindowPrivate -{ -public: - QWSWindowPrivate(); - -#ifdef QT_QWS_CLIENTBLIT - QRegion directPaintRegion; -#endif - QRegion allocatedRegion; -#ifndef QT_NO_QWSEMBEDWIDGET - QList<QWSWindow*> embedded; - QWSWindow *embedder; -#endif - QWSWindow::State state; - Qt::WindowFlags windowFlags; - QRegion dirtyOnScreen; - bool painted; -}; - -QWSWindowPrivate::QWSWindowPrivate() - : -#ifndef QT_NO_QWSEMBEDWIDGET - embedder(0), state(QWSWindow::NoState), -#endif - painted(false) -{ -} - -/*! - \class QWSWindow - \ingroup qws - - \brief The QWSWindow class encapsulates a top-level window in - Qt for Embedded Linux. - - When you run a \l{Qt for Embedded Linux} application, it either runs as a - server or connects to an existing server. As applications add and - remove windows, the server process maintains information about - each window. In \l{Qt for Embedded Linux}, top-level windows are - encapsulated as QWSWindow objects. Note that you should never - construct the QWSWindow class yourself; the current top-level - windows can be retrieved using the QWSServer::clientWindows() - function. - - With a window at hand, you can retrieve its caption, name, opacity - and ID using the caption(), name(), opacity() and winId() - functions, respectively. Use the client() function to retrieve a - pointer to the client that owns the window. - - Use the isVisible() function to find out if the window is - visible. You can find out if the window is completely obscured by - another window or by the bounds of the screen, using the - isFullyObscured() function. The isOpaque() function returns true - if the window has an alpha channel equal to 255. Finally, the - requestedRegion() function returns the region of the display the - window wants to draw on. - - \sa QWSServer, QWSClient, {Qt for Embedded Linux Architecture} -*/ - -/*! - \fn int QWSWindow::winId() const - - Returns the window's ID. - - \sa name(), caption() -*/ - -/*! - \fn const QString &QWSWindow::name() const - - Returns the window's name, which is taken from the \l {QWidget::}{objectName()} - at the time of \l {QWidget::}{show()}. - - \sa caption(), winId() -*/ - -/*! - \fn const QString &QWSWindow::caption() const - - Returns the window's caption. - - \sa name(), winId() -*/ - -/*! - \fn QWSClient* QWSWindow::client() const - - Returns a reference to the QWSClient object that owns this window. - - \sa requestedRegion() -*/ - -/*! - \fn QRegion QWSWindow::requestedRegion() const - - Returns the region that the window has requested to draw onto, - including any window decorations. - - \sa client() -*/ - -/*! - \fn bool QWSWindow::isVisible() const - - Returns true if the window is visible; otherwise returns false. - - \sa isFullyObscured() -*/ - -/*! - \fn bool QWSWindow::isOpaque() const - - Returns true if the window is opaque, i.e., if its alpha channel - equals 255; otherwise returns false. - - \sa opacity() -*/ - -/*! - \fn uint QWSWindow::opacity () const - - Returns the window's alpha channel value. - - \sa isOpaque() -*/ - -/*! - \fn bool QWSWindow::isPartiallyObscured() const - \internal - - Returns true if the window is partially obsured by another window - or by the bounds of the screen; otherwise returns false. -*/ - -/*! - \fn bool QWSWindow::isFullyObscured() const - - Returns true if the window is completely obsured by another window - or by the bounds of the screen; otherwise returns false. - - \sa isVisible() -*/ - -/*! - \fn QWSWindowSurface* QWSWindow::windowSurface() const - \internal -*/ - -QWSWindow::QWSWindow(int i, QWSClient* client) - : id(i), modified(false), - onTop(false), c(client), last_focus_time(0), _opacity(255), - opaque(true), d(new QWSWindowPrivate) -{ - surface = 0; -} - - -/*! - \enum QWSWindow::State - - This enum describes the state of a window. Most of the - transitional states are set just before a call to - QScreen::exposeRegion() and reset immediately afterwards. - - \value NoState Initial state before the window is properly initialized. - \value Hidden The window is not visible. - \value Showing The window is being shown. - \value Visible The window is visible, and not in a transition. - \value Hiding The window is being hidden. - \value Raising The windoe is being raised. - \value Lowering The window is being raised. - \value Moving The window is being moved. - \value ChangingGeometry The window's geometry is being changed. - \value Destroyed The window is destroyed. - - \sa state(), QScreen::exposeRegion() -*/ - -/*! - Returns the current state of the window. - - \since 4.3 -*/ -QWSWindow::State QWSWindow::state() const -{ - return d->state; -} - -/*! - Returns the window flags of the window. This value is only available - after the first paint event. - - \since 4.3 -*/ -Qt::WindowFlags QWSWindow::windowFlags() const -{ - return d->windowFlags; -} - -/*! - Returns the region that has been repainted since the previous - QScreen::exposeRegion(), and needs to be copied to the screen. - \since 4.3 -*/ -QRegion QWSWindow::dirtyOnScreen() const -{ - return d->dirtyOnScreen; -} - -void QWSWindow::createSurface(const QString &key, const QByteArray &data) -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (surface && !surface->isBuffered()) - c->removeUnbufferedSurface(); -#endif - - delete surface; - surface = qt_screen->createSurface(key); - surface->setPermanentState(data); - -#ifndef QT_NO_QWS_MULTIPROCESS - if (!surface->isBuffered()) - c->addUnbufferedSurface(); -#endif -} - -/*! - \internal - Raises the window above all other windows except "Stay on top" windows. -*/ -void QWSWindow::raise() -{ - qwsServerPrivate->raiseWindow(this); -#ifndef QT_NO_QWSEMBEDWIDGET - const int n = d->embedded.size(); - for (int i = 0; i < n; ++i) - d->embedded.at(i)->raise(); -#endif -} - -/*! - \internal - Lowers the window below other windows. -*/ -void QWSWindow::lower() -{ - qwsServerPrivate->lowerWindow(this); -#ifndef QT_NO_QWSEMBEDWIDGET - const int n = d->embedded.size(); - for (int i = 0; i < n; ++i) - d->embedded.at(i)->lower(); -#endif -} - -/*! - \internal - Shows the window. -*/ -void QWSWindow::show() -{ - operation(QWSWindowOperationEvent::Show); -#ifndef QT_NO_QWSEMBEDWIDGET - const int n = d->embedded.size(); - for (int i = 0; i < n; ++i) - d->embedded.at(i)->show(); -#endif -} - -/*! - \internal - Hides the window. -*/ -void QWSWindow::hide() -{ - operation(QWSWindowOperationEvent::Hide); -#ifndef QT_NO_QWSEMBEDWIDGET - const int n = d->embedded.size(); - for (int i = 0; i < n; ++i) - d->embedded.at(i)->hide(); -#endif -} - -/*! - \internal - Make this the active window (i.e., sets the keyboard focus to this - window). -*/ -void QWSWindow::setActiveWindow() -{ - qwsServerPrivate->setFocus(this, true); -#ifndef QT_NO_QWSEMBEDWIDGET - const int n = d->embedded.size(); - for (int i = 0; i < n; ++i) - d->embedded.at(i)->setActiveWindow(); -#endif -} - -void QWSWindow::setName(const QString &n) -{ - rgnName = n; -} - -/*! - \internal - Sets the window's caption to \a c. -*/ -void QWSWindow::setCaption(const QString &c) -{ - rgnCaption = c; -} - - -static int global_focus_time_counter=100; - -void QWSWindow::focus(bool get) -{ - if (get) - last_focus_time = global_focus_time_counter++; - if (c) { - QWSFocusEvent event; - event.simpleData.window = id; - event.simpleData.get_focus = get; - c->sendEvent(&event); - } -} - -void QWSWindow::operation(QWSWindowOperationEvent::Operation o) -{ - if (!c) - return; - QWSWindowOperationEvent event; - event.simpleData.window = id; - event.simpleData.op = o; - c->sendEvent(&event); -} - -/*! - \internal - Destructor. -*/ -QWSWindow::~QWSWindow() -{ -#ifndef QT_NO_QWS_INPUTMETHODS - if (current_IM_composing_win == this) - current_IM_composing_win = 0; -#endif -#ifndef QT_NO_QWSEMBEDWIDGET - QWSWindow *embedder = d->embedder; - if (embedder) { - embedder->d->embedded.removeAll(this); - d->embedder = 0; - } - while (!d->embedded.isEmpty()) - stopEmbed(d->embedded.first()); -#endif - -#ifndef QT_NO_QWS_MULTIPROCESS - if (surface && !surface->isBuffered()) { - if (c && c->d_func()) // d_func() will be 0 if client is deleted - c->removeUnbufferedSurface(); - } -#endif - - delete surface; - delete d; -} - -/*! - \internal - - Returns the region that the window is allowed to draw onto, - including any window decorations but excluding regions covered by - other windows. - - \sa paintedRegion(), requestedRegion() -*/ -QRegion QWSWindow::allocatedRegion() const -{ - return d->allocatedRegion; -} - -#ifdef QT_QWS_CLIENTBLIT -QRegion QWSWindow::directPaintRegion() const -{ - return d->directPaintRegion; -} - -inline void QWSWindow::setDirectPaintRegion(const QRegion &r) -{ - d->directPaintRegion = r; -} -#endif - -/*! - \internal - - Returns the region that the window is known to have drawn into. - - \sa allocatedRegion(), requestedRegion() -*/ -QRegion QWSWindow::paintedRegion() const -{ - return (d->painted ? d->allocatedRegion : QRegion()); -} - -inline void QWSWindow::setAllocatedRegion(const QRegion ®ion) -{ - d->allocatedRegion = region; -} - -#ifndef QT_NO_QWSEMBEDWIDGET -inline void QWSWindow::startEmbed(QWSWindow *w) -{ - d->embedded.append(w); - w->d->embedder = this; -} - -inline void QWSWindow::stopEmbed(QWSWindow *w) -{ - w->d->embedder = 0; - w->client()->sendEmbedEvent(w->winId(), QWSEmbedEvent::Region, QRegion()); - d->embedded.removeAll(w); -} -#endif // QT_NO_QWSEMBEDWIDGET - -/********************************************************************* - * - * Class: QWSClient - * - *********************************************************************/ - -class QWSClientPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QWSClient) - -public: - QWSClientPrivate(); - ~QWSClientPrivate(); - - void setLockId(int id); - void unlockCommunication(); - -private: -#ifndef QT_NO_QWS_MULTIPROCESS - QWSLock *clientLock; - bool shutdown; - int numUnbufferedSurfaces; -#endif - QSet<QByteArray> usedFonts; - friend class QWSServerPrivate; -}; - -QWSClientPrivate::QWSClientPrivate() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - clientLock = 0; - shutdown = false; - numUnbufferedSurfaces = 0; -#endif -} - -QWSClientPrivate::~QWSClientPrivate() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - delete clientLock; -#endif -} - -void QWSClientPrivate::setLockId(int id) -{ -#ifdef QT_NO_QWS_MULTIPROCESS - Q_UNUSED(id); -#else - clientLock = new QWSLock(id); -#endif -} - -void QWSClientPrivate::unlockCommunication() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (clientLock) - clientLock->unlock(QWSLock::Communication); -#endif -} - -/*! - \class QWSClient - \ingroup qws - - \brief The QWSClient class encapsulates a client process in Qt for Embedded Linux. - - When you run a \l{Qt for Embedded Linux} application, it either runs as a - server or connects to an existing server. The server and client - processes have different responsibilities: The client process - performs all application specific operations. The server process - is responsible for managing the clients as well as taking care of - the pointer handling, character input, and screen output. In - addition, the server provides functionality to handle input - methods. - - As applications add and remove windows, the server process - maintains information about each window. In \l{Qt for Embedded Linux}, - top-level windows are encapsulated as QWSWindow objects. A list of - the current windows can be retrieved using the - QWSServer::clientWindows() function, and each window can tell - which client that owns it through its QWSWindow::client() - function. - - A QWSClient object has an unique ID that can be retrieved using - its clientId() function. QWSClient also provides the identity() - function which typically returns the name of this client's running - application. - - \sa QWSServer, QWSWindow, {Qt for Embedded Linux Architecture} -*/ - -/*! - \internal -*/ -//always use frame buffer -QWSClient::QWSClient(QObject* parent, QWS_SOCK_BASE* sock, int id) - : QObject(*new QWSClientPrivate, parent), command(0), cid(id) -{ -#ifdef QT_NO_QWS_MULTIPROCESS - Q_UNUSED(sock); - isClosed = false; -#else - csocket = 0; - if (!sock) { - socketDescriptor = -1; - isClosed = false; - } else { - csocket = static_cast<QWSSocket*>(sock); //### - isClosed = false; - - csocket->flush(); - socketDescriptor = csocket->socketDescriptor(); - connect(csocket, SIGNAL(readyRead()), this, SIGNAL(readyRead())); - connect(csocket, SIGNAL(disconnected()), this, SLOT(closeHandler())); - connect(csocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorHandler())); - } -#endif //QT_NO_QWS_MULTIPROCESS -} - -/*! - \internal -*/ -QWSClient::~QWSClient() -{ - qDeleteAll(cursors); - delete command; -#ifndef QT_NO_QWS_MULTIPROCESS - delete csocket; -#endif -} - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSClient::removeUnbufferedSurface() -{ - Q_D(QWSClient); - --d->numUnbufferedSurfaces; -} - -void QWSClient::addUnbufferedSurface() -{ - Q_D(QWSClient); - ++d->numUnbufferedSurfaces; -} -#endif // QT_NO_QWS_MULTIPROCESS - -/*! - \internal -*/ -void QWSClient::setIdentity(const QString& i) -{ - id = i; -} - -void QWSClient::closeHandler() -{ - isClosed = true; - emit connectionClosed(); -} - -void QWSClient::errorHandler() -{ -#if defined(QWS_SOCKET_DEBUG) - qDebug("Client %p error %s", this, csocket ? csocket->errorString().toLatin1().constData() : "(no socket)"); -#endif - isClosed = true; -//####Do we need to clean out the pipes? - - emit connectionClosed(); -} - -/*! - \internal -*/ -int QWSClient::socket() const -{ - return socketDescriptor; -} - -/*! - \internal -*/ -void QWSClient::sendEvent(QWSEvent* event) -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) { - // qDebug() << "QWSClient::sendEvent type " << event->type << " socket state " << csocket->state(); - if ((QAbstractSocket::SocketState)(csocket->state()) == QAbstractSocket::ConnectedState) { - event->write(csocket); - } - } - else -#endif - { - qt_client_enqueue(event); - } -} - -/*! - \internal -*/ -void QWSClient::sendRegionEvent(int winid, QRegion rgn, int type -#ifdef QT_QWS_CLIENTBLIT - , int id -#endif - ) -{ -#ifndef QT_NO_QWS_MULTIPROCESS - Q_D(QWSClient); - if (d->clientLock) - d->clientLock->lock(QWSLock::RegionEvent); -#endif - - QWSRegionEvent event; - event.setData(winid, rgn, type); -#ifdef QT_QWS_CLIENTBLIT - event.simpleData.id = id; -#endif - -// qDebug() << "Sending Region event to" << winid << "rgn" << rgn << "type" << type; - - sendEvent(&event); -} - -extern int qt_servershmid; - -/*! - \internal -*/ -void QWSClient::sendConnectedEvent(const char *display_spec) -{ - QWSConnectedEvent event; - event.simpleData.window = 0; - event.simpleData.len = strlen(display_spec) + 1; - event.simpleData.clientId = cid; - event.simpleData.servershmid = qt_servershmid; - char * tmp=(char *)display_spec; - event.setData(tmp, event.simpleData.len); - sendEvent(&event); -} - -/*! - \internal -*/ -void QWSClient::sendMaxWindowRectEvent(const QRect &rect) -{ - QWSMaxWindowRectEvent event; - event.simpleData.window = 0; - event.simpleData.rect = rect; - sendEvent(&event); -} - -/*! - \internal -*/ -#ifndef QT_NO_QWS_PROPERTIES -void QWSClient::sendPropertyNotifyEvent(int property, int state) -{ - QWSPropertyNotifyEvent event; - event.simpleData.window = 0; // not used yet - event.simpleData.property = property; - event.simpleData.state = state; - sendEvent(&event); -} - -/*! - \internal -*/ -void QWSClient::sendPropertyReplyEvent(int property, int len, const char *data) -{ - QWSPropertyReplyEvent event; - event.simpleData.window = 0; // not used yet - event.simpleData.property = property; - event.simpleData.len = len; - event.setData(data, len); - sendEvent(&event); -} -#endif //QT_NO_QWS_PROPERTIES - -/*! - \internal -*/ -void QWSClient::sendSelectionClearEvent(int windowid) -{ - QWSSelectionClearEvent event; - event.simpleData.window = windowid; - sendEvent(&event); -} - -/*! - \internal -*/ -void QWSClient::sendSelectionRequestEvent(QWSConvertSelectionCommand *cmd, int windowid) -{ - QWSSelectionRequestEvent event; - event.simpleData.window = windowid; - event.simpleData.requestor = cmd->simpleData.requestor; - event.simpleData.property = cmd->simpleData.selection; - event.simpleData.mimeTypes = cmd->simpleData.mimeTypes; - sendEvent(&event); -} - -#ifndef QT_NO_QWSEMBEDWIDGET -/*! - \internal -*/ -void QWSClient::sendEmbedEvent(int windowid, QWSEmbedEvent::Type type, - const QRegion ®ion) -{ - QWSEmbedEvent event; - event.setData(windowid, type, region); - sendEvent(&event); -} -#endif // QT_NO_QWSEMBEDWIDGET - -/*! - \fn void QWSClient::connectionClosed() - \internal -*/ - -/*! - \fn void QWSClient::readyRead(); - \internal -*/ - -/*! - \fn int QWSClient::clientId () const - - Returns an integer uniquely identfying this client. -*/ - -/*! - \fn QString QWSClient::identity () const - - Returns the name of this client's running application. -*/ -/********************************************************************* - * - * Class: QWSServer - * - *********************************************************************/ - -/*! - \class QWSServer - \brief The QWSServer class encapsulates a server process in Qt for Embedded Linux. - - \ingroup qws - - When you run a \l{Qt for Embedded Linux} application, it either runs as a - server or connects to an existing server. The server and client - processes have different responsibilities: The client process - performs all application specific operations. The server process - is responsible for managing the clients as well as taking care of - the pointer handling, character input, and screen output. In - addition, the server provides functionality to handle input - methods. - - In \l{Qt for Embedded Linux}, all system generated events are passed to the - server application which then propagates the event to the - appropriate client. See the \l{Qt for Embedded Linux Architecture} - documentation for details. - - Note that this class is instantiated by QApplication for - \l{Qt for Embedded Linux} server processes; you should never construct this - class yourself. Use the instance() function to retrieve a pointer - to the server object. - - Note that the static functions of the QWSServer class can only be - used in the server process. - - \tableofcontents - - \section1 Client Administration - - As applications add and remove windows, the server process - maintains information about each window. In \l{Qt for Embedded Linux}, - top-level windows are encapsulated as QWSWindow objects. Each - window can tell which client that owns it through its - QWSWindow::client() function. Use the clientWindows() function to - retrieve a list of the current top-level windows. Given a - particular position on the display, the window containing it can - be retrieved using the windowAt() function. - - QWSServer also provides the windowEvent() signal which is emitted - whenever something happens to a top level window; the WindowEvent - enum describes the various types of events that the signal - recognizes. In addition, the server class provides the - markedText() signal which is emitted whenever some text has been - selected in any of the windows, passing the selection as - parameter. - - The QCopChannel class and the QCOP communication protocol enable - transfer of messages between clients. QWSServer provides the - newChannel() and removedChannel() signals that is emitted whenever - a new QCopChannel object is created or destroyed, respectively. - - See also: QWSWindow, QWSClient and QCopChannel. - - - \section1 Mouse Handling - - The mouse driver (represented by an instance of the - QWSMouseHandler class) is loaded by the server application when it - starts running, using Qt's \l {How to Create Qt Plugins}{plugin - system}. A mouse driver receives mouse events from the device and - encapsulates each event with an instance of the QWSEvent class - which it then passes to the server. - - The openMouse() function opens the mouse devices specified by the - QWS_MOUSE_PROTO environment variable, and the setMouseHandler() - functions sets the primary mouse driver. Alternatively, the static - setDefaultMouse() function provides means of specifying the mouse - driver to use if the QWS_MOUSE_PROTO variable is not defined (note - that the default is otherwise platform dependent). The primary - mouse driver can be retrieved using the static mouseHandler() - function. Use the closeMouse() function to delete the mouse - drivers. - - In addition, the QWSServer class can control the flow of mouse - input using the suspendMouse() and resumeMouse() functions. - - See also: QWSMouseHandler and \l{Qt for Embedded Linux Pointer Handling}. - - \section1 Keyboard Handling - - The keyboard driver (represented by an instance of the - QWSKeyboardHandler class) is loaded by the server application when - it starts running, using Qt's \l {How to Create Qt Plugins}{plugin - system}. A keyboard driver receives keyboard events from the - device and encapsulates each event with an instance of the - QWSEvent class which it then passes to the server. - - The openKeyboard() function opens the keyboard devices specified - by the QWS_KEYBOARD environment variable, and the - setKeyboardHandler() functions sets the primary keyboard - driver. Alternatively, the static setDefaultKeyboard() function - provides means of specifying the keyboard driver to use if the - QWS_KEYBOARD variable is not defined (note again that the default - is otherwise platform dependent). The primary keyboard driver can - be retrieved using the static keyboardHandler() function. Use the - closeKeyboard() function to delete the keyboard drivers. - - In addition, the QWSServer class can handle key events from both - physical and virtual keyboards using the processKeyEvent() and - sendKeyEvent() functions, respectively. Use the - addKeyboardFilter() function to filter the key events from - physical keyboard drivers, the most recently added filter can be - removed and deleted using the removeKeyboardFilter() function. - - See also: QWSKeyboardHandler and \l{Qt for Embedded Linux Character Input}. - - \section1 Display Handling - - When a screen update is required, the server runs through all the - top-level windows that intersect with the region that is about to - be updated, and ensures that the associated clients have updated - their memory buffer. Then the server uses the screen driver - (represented by an instance of the QScreen class) to copy the - content of the memory to the screen. - - In addition, the QWSServer class provides some means of managing - the screen output: Use the refresh() function to refresh the - entire display, or alternatively a specified region of it. The - enablePainting() function can be used to disable (and enable) - painting onto the screen. QWSServer also provide the - setMaxWindowRect() function restricting the area of the screen - which \l{Qt for Embedded Linux} applications will consider to be the - maximum area to use for windows. To set the brush used as the - background in the absence of obscuring windows, QWSServer provides - the static setBackground() function. The corresponding - backgroundBrush() function returns the currently set brush. - - QWSServer also controls the screen saver: Use the setScreenSaver() - to install a custom screen saver derived from the QWSScreenSaver - class. Once installed, the screensaver can be activated using the - screenSaverActivate() function, and the screenSaverActive() - function returns its current status. Use the - setScreenSaverInterval() function to specify the timeout interval. - \l{Qt for Embedded Linux} also supports multilevel screen saving, use the - setScreenSaverIntervals() function to specify the various levels - and their timeout intervals. - - Finally, the QWSServer class controls the cursor's appearance, - i.e., use the setCursorVisible() function to hide or show the - cursor, and the isCursorVisible() function to determine whether - the cursor is visible on the display or not. - - See also: QScreen and \l{Qt for Embedded Linux Display Management}. - - \section1 Input Method Handling - - Whenever the server receives an event, it queries its stack of - top-level windows to find the window containing the event's - position (each window can identify the client application that - created it). Then the server forwards the event to the appropriate - client. If an input method is installed, it is used as a filter - between the server and the client application. - - Derive from the QWSInputMethod class to create custom input - methods, and use the server's setCurrentInputMethod() function to - install it. Use the sendIMEvent() and sendIMQuery() functions to - send input method events and queries. - - QWSServer provides the IMMouse enum describing the various mouse - events recognized by the QWSInputMethod::mouseHandler() - function. The latter function allows subclasses of QWSInputMethod - to handle mouse events within the preedit text. - - \sa QWSInputMethod -*/ - -/*! - \enum QWSServer::IMState - \obsolete - - This enum describes the various states of an input method. - - \value IMCompose Composing. - \value IMStart Equivalent to IMCompose. - \value IMEnd Finished composing. - - \sa QWSInputMethod::sendIMEvent() -*/ - -/*! - \enum QWSServer::IMMouse - - This enum describes the various types of mouse events recognized - by the QWSInputMethod::mouseHandler() function. - - \value MousePress An event generated by pressing a mouse button. - \value MouseRelease An event generated by relasing a mouse button. - \value MouseMove An event generated by moving the mouse cursor. - \value MouseOutside This value is only reserved, i.e., it is not used in - current implementations. - - \sa QWSInputMethod, setCurrentInputMethod() -*/ - -/*! - \enum QWSServer::ServerFlags - \internal - - This enum is used to pass various options to the window system - server. - - \value DisableKeyboard Ignore all keyboard input. - \value DisableMouse Ignore all mouse input. -*/ - -/*! - \enum QWSServer::WindowEvent - - This enum specifies the various events that can occur in a - top-level window. - - \value Create A new window has been created (by the QWidget constructor). - \value Destroy The window has been closed and deleted (by the QWidget destructor). - \value Hide The window has been hidden using the QWidget::hide() function. - \value Show The window has been shown using the QWidget::show() function or similar. - \value Raise The window has been raised to the top of the desktop. - \value Lower The window has been lowered. - \value Geometry The window has changed size or position. - \value Active The window has become the active window (i.e., it has keyboard focus). - \value Name The window has been named. - - \sa windowEvent() -*/ - -/*! - \fn void QWSServer::markedText(const QString &selection) - - This signal is emitted whenever some text is selected in any of - the running applications, passing the selected text in the \a - selection parameter. - - \sa windowEvent() -*/ - -/*! - \fn const QList<QWSWindow*> &QWSServer::clientWindows() - - Returns the list of current top-level windows. - - Note that the collection of top-level windows changes as - applications add and remove widgets so it should not be stored for - future use. The windows are sorted in stacking order from top-most - to bottom-most. - - Use the QWSWindow::client() function to retrieve the client - application that owns a given window. - - \sa windowAt(), instance() -*/ - -/*! - \fn void QWSServer::newChannel(const QString& channel) - - This signal is emitted whenever a new QCopChannel object is - created, passing the channel's name in the \a channel parameter. - - \sa removedChannel() -*/ - -/*! - \fn void QWSServer::removedChannel(const QString& channel) - - This signal is emitted immediately after the given the QCopChannel - object specified by \a channel, is destroyed. - - Note that a channel is not destroyed until all its listeners have - been unregistered. - - \sa newChannel() -*/ - -/*! - \fn QWSServer::QWSServer(int flags, QObject *parent) - \internal - - Construct a QWSServer object with the given \a parent. The \a - flags are used for keyboard and mouse settings. - - \warning This class is instantiated by QApplication for - \l{Qt for Embedded Linux} server processes. You should never construct - this class yourself. - - \sa {Running Applications} -*/ - -/*! - \fn static QWSServer* QWSServer::instance() - \since 4.2 - - Returns a pointer to the server instance. - - Note that the pointer will be 0 if the application is not the - server, i.e., if the QApplication::type() function doesn't return - QApplication::GuiServer. - - \sa clientWindows(), windowAt() -*/ - -struct QWSCommandStruct -{ - QWSCommandStruct(QWSCommand *c, QWSClient *cl) :command(c),client(cl){} - ~QWSCommandStruct() { delete command; } - - QWSCommand *command; - QWSClient *client; - -}; - -QWSServer::QWSServer(int flags, QObject *parent) : - QObject(*new QWSServerPrivate, parent) -{ - Q_D(QWSServer); - QT_TRY { - d->initServer(flags); - } QT_CATCH(...) { - qwsServer = 0; - qwsServerPrivate = 0; - QT_RETHROW; - } -} - -#ifdef QT3_SUPPORT -/*! - Use the two-argument overload and call the - QObject::setObjectName() function instead. -*/ -QWSServer::QWSServer(int flags, QObject *parent, const char *name) : - QObject(*new QWSServerPrivate, parent) -{ - Q_D(QWSServer); - setObjectName(QString::fromAscii(name)); - d->initServer(flags); -} -#endif - - -#ifndef QT_NO_QWS_MULTIPROCESS -static void ignoreSignal(int) {} // Used to eat SIGPIPE signals below -#endif - -bool QWSServerPrivate::screensaverblockevent( int index, int *screensaverinterval, bool isDown ) -{ - static bool ignoreEvents[2] = { false, false }; - if ( isDown ) { - if ( !ignoreEvents[index] ) { - bool wake = false; - if ( screensaverintervals ) { - if ( screensaverinterval != screensaverintervals ) { - wake = true; - } - } - if ( screensaverblockevents && wake ) { -#ifdef EVENT_BLOCK_DEBUG - qDebug( "waking the screen" ); -#endif - ignoreEvents[index] = true; - } else if ( !screensaverblockevents ) { -#ifdef EVENT_BLOCK_DEBUG - qDebug( "the screen was already awake" ); -#endif - ignoreEvents[index] = false; - } - } - } else { - if ( ignoreEvents[index] ) { -#ifdef EVENT_BLOCK_DEBUG - qDebug( "mouseup?" ); -#endif - ignoreEvents[index] = false; - return true; - } - } - return ignoreEvents[index]; -} - -void QWSServerPrivate::initServer(int flags) -{ - Q_Q(QWSServer); - Q_ASSERT(!qwsServer); - qwsServer = q; - qwsServerPrivate = this; - disablePainting = false; -#ifndef QT_NO_QWS_MULTIPROCESS - ssocket = new QWSServerSocket(qws_qtePipeFilename(), q); - QObject::connect(ssocket, SIGNAL(newConnection()), q, SLOT(_q_newConnection())); - - if ( !ssocket->isListening()) { - perror("QWSServerPrivate::initServer: server socket not listening"); - qFatal("Failed to bind to %s", qws_qtePipeFilename().toLatin1().constData()); - } - - struct linger tmp; - tmp.l_onoff=1; - tmp.l_linger=0; - setsockopt(ssocket->socketDescriptor(),SOL_SOCKET,SO_LINGER,(char *)&tmp,sizeof(tmp)); - - - signal(SIGPIPE, ignoreSignal); //we get it when we read -#endif - focusw = 0; - mouseGrabber = 0; - mouseGrabbing = false; - inputMethodMouseGrabbed = false; - keyboardGrabber = 0; - keyboardGrabbing = false; -#ifndef QT_NO_QWS_CURSOR - haveviscurs = false; - cursor = 0; - nextCursor = 0; -#endif - -#ifndef QT_NO_QWS_MULTIPROCESS - - if (!geteuid()) { -#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) - if(mount(0,"/var/shm", "shm", 0, 0)) { - /* This just confuses people with 2.2 kernels - if (errno != EBUSY) - qDebug("Failed mounting shm fs on /var/shm: %s",strerror(errno)); - */ - } -#endif - } -#endif - - // no selection yet - selectionOwner.windowid = -1; - selectionOwner.time.set(-1, -1, -1, -1); - - cleanupFontsDir(); - - // initialize the font database - // from qfontdatabase_qws.cpp - extern void qt_qws_init_fontdb(); - qt_qws_init_fontdb(); - - openDisplay(); - - screensavertimer = new QTimer(q); - screensavertimer->setSingleShot(true); - QObject::connect(screensavertimer, SIGNAL(timeout()), q, SLOT(_q_screenSaverTimeout())); - _q_screenSaverWake(); - - clientMap[-1] = new QWSClient(q, 0, 0); - - if (!bgBrush) - bgBrush = new QBrush(QColor(0x20, 0xb0, 0x50)); - - initializeCursor(); - - // input devices - if (!(flags&QWSServer::DisableMouse)) { - q->openMouse(); - } -#ifndef QT_NO_QWS_KEYBOARD - if (!(flags&QWSServer::DisableKeyboard)) { - q->openKeyboard(); - } -#endif - -#if !defined(QT_NO_SOUND) && !defined(QT_EXTERNAL_SOUND_SERVER) && !defined(Q_OS_DARWIN) - soundserver = new QWSSoundServer(q); -#endif -} - -/*! - \internal - Destructs this server. -*/ -QWSServer::~QWSServer() -{ - closeMouse(); -#ifndef QT_NO_QWS_KEYBOARD - closeKeyboard(); -#endif - d_func()->cleanupFonts(/*force =*/true); -} - -/*! - \internal - */ -void QWSServer::timerEvent(QTimerEvent *e) -{ - Q_D(QWSServer); - if (e->timerId() == d->fontCleanupTimer.timerId()) { - d->cleanupFonts(); - d->fontCleanupTimer.stop(); - } else { - QObject::timerEvent(e); - } -} - -const QList<QWSWindow*> &QWSServer::clientWindows() -{ - Q_D(QWSServer); - return d->windows; -} - -/*! - \internal -*/ -void QWSServerPrivate::releaseMouse(QWSWindow* w) -{ - if (w && mouseGrabber == w) { - mouseGrabber = 0; - mouseGrabbing = false; -#ifndef QT_NO_QWS_CURSOR - if (nextCursor) { - // Not grabbing -> set the correct cursor - setCursor(nextCursor); - nextCursor = 0; - } -#endif - } -} - -/*! - \internal -*/ -void QWSServerPrivate::releaseKeyboard(QWSWindow* w) -{ - if (keyboardGrabber == w) { - keyboardGrabber = 0; - keyboardGrabbing = false; - } -} - -void QWSServerPrivate::handleWindowClose(QWSWindow *w) -{ - w->shuttingDown(); - if (focusw == w) - setFocus(w,false); - if (mouseGrabber == w) - releaseMouse(w); - if (keyboardGrabber == w) - releaseKeyboard(w); -} - - -#ifndef QT_NO_QWS_MULTIPROCESS -/*! - \internal -*/ -void QWSServerPrivate::_q_newConnection() -{ - Q_Q(QWSServer); - while (QWS_SOCK_BASE *sock = ssocket->nextPendingConnection()) { - int socket = sock->socketDescriptor(); - sock->setParent(0); - - QWSClient *client = new QWSClient(q,sock, get_object_id()); - clientMap[socket] = client; - -#ifndef QT_NO_SXE -#ifdef QTRANSPORTAUTH_DEBUG - qDebug( "Transport auth connected: unix stream socket %d", socket ); -#endif - // get a handle to the per-process authentication service - QTransportAuth *a = QTransportAuth::getInstance(); - - // assert that this transport is trusted - QTransportAuth::Data *d = a->connectTransport( - QTransportAuth::UnixStreamSock | - QTransportAuth::Trusted, socket ); - - QAuthDevice *ad = a->recvBuf( d, sock ); - ad->setClient(client); - - QObject::connect(ad, SIGNAL(readyRead()), - q, SLOT(_q_doClient())); - - QObject::connect(client, SIGNAL(connectionClosed()), - q, SLOT(_q_clientClosed())); -#else - QObject::connect(client, SIGNAL(readyRead()), - q, SLOT(_q_doClient())); - QObject::connect(client, SIGNAL(connectionClosed()), - q, SLOT(_q_clientClosed())); -#endif // QT_NO_SXE - - client->sendConnectedEvent(qws_display_spec.constData()); - - if (clientMap.contains(socket)) { - QList<QScreen*> screens = qt_screen->subScreens(); - if (screens.isEmpty()) - screens.append(qt_screen); - for (int i = 0; i < screens.size(); ++i) { - const QApplicationPrivate *ap = QApplicationPrivate::instance(); - QScreen *screen = screens.at(i); - const QRect rect = ap->maxWindowRect(screen); - if (!rect.isEmpty()) - client->sendMaxWindowRectEvent(rect); - if (screen->isTransformed()) { - QWSScreenTransformationEvent event; - event.simpleData.screen = i; - event.simpleData.transformation = screen->transformOrientation(); - client->sendEvent(&event); - } - } - } - - // pre-provide some object id's - QWSCreateCommand cmd(30); - invokeCreate(&cmd, client); - } -} -/*! - \internal -*/ -void QWSServerPrivate::_q_clientClosed() -{ - Q_Q(QWSServer); - QWSClient* cl = (QWSClient*)q->sender(); - - // Remove any queued commands for this client - int i = 0; - while (i < commandQueue.size()) { - QWSCommandStruct *cs = commandQueue.at(i); - if (cs->client == cl) { - commandQueue.removeAt(i); - delete cs; - } else { - ++i; - } - } - -#ifndef QT_NO_COP - // Enfore unsubscription from all channels. - QCopChannel::detach(cl); -#endif - - // Shut down all windows for this client - for (int i = 0; i < windows.size(); ++i) { - QWSWindow* w = windows.at(i); - if (w->forClient(cl)) - w->shuttingDown(); - } - - // Delete all windows for this client - QRegion exposed; - i = 0; - while (i < windows.size()) { - QWSWindow* w = windows.at(i); - if (w->forClient(cl)) { - windows.takeAt(i); - w->c = 0; //so we don't send events to it anymore - releaseMouse(w); - releaseKeyboard(w); - exposed += w->allocatedRegion(); -// rgnMan->remove(w->allocationIndex()); - if (focusw == w) - setFocus(focusw,0); - if (mouseGrabber == w) - releaseMouse(w); - if (i < nReserved) - --nReserved; -#ifndef QT_NO_QWS_PROPERTIES - propertyManager.removeProperties(w->winId()); -#endif - emit q->windowEvent(w, QWSServer::Destroy); - w->d->state = QWSWindow::Destroyed; //??? - deletedWindows.append(w); - } else { - ++i; - } - } - if (deletedWindows.count()) - QTimer::singleShot(0, q, SLOT(_q_deleteWindowsLater())); - - QWSClientPrivate *clientPrivate = cl->d_func(); - if (!clientPrivate->shutdown) { -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "client" << cl->clientId() << "crashed"; -#endif - // this would be the place to emit a signal to notify about the - // crash of a client - crashedClientIds.append(cl->clientId()); - fontCleanupTimer.start(10, q_func()); - } - clientPrivate->shutdown = true; - - while (!clientPrivate->usedFonts.isEmpty()) { - const QByteArray font = *clientPrivate->usedFonts.begin(); -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "dereferencing font" << font << "from disconnected client"; -#endif - dereferenceFont(clientPrivate, font); - } - clientPrivate->usedFonts.clear(); - - //qDebug("removing client %d with socket %d", cl->clientId(), cl->socket()); - clientMap.remove(cl->socket()); - if (cl == cursorClient) - cursorClient = 0; - if (qt_screen->clearCacheFunc) - (qt_screen->clearCacheFunc)(qt_screen, cl->clientId()); // remove any remaining cache entries. - cl->deleteLater(); - - update_regions(); - exposeRegion(exposed); -} - -void QWSServerPrivate::_q_deleteWindowsLater() -{ - qDeleteAll(deletedWindows); - deletedWindows.clear(); -} - -#endif //QT_NO_QWS_MULTIPROCESS - -void QWSServerPrivate::referenceFont(QWSClientPrivate *client, const QByteArray &font) -{ - if (!client->usedFonts.contains(font)) { - client->usedFonts.insert(font); - - ++fontReferenceCount[font]; -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "Client" << client->q_func()->clientId() << "added font" << font; - qDebug() << "Refcount is" << fontReferenceCount[font]; -#endif - } -} - -void QWSServerPrivate::dereferenceFont(QWSClientPrivate *client, const QByteArray &font) -{ - if (client->usedFonts.contains(font)) { - client->usedFonts.remove(font); - - Q_ASSERT(fontReferenceCount[font]); - if (!--fontReferenceCount[font] && !fontCleanupTimer.isActive()) - fontCleanupTimer.start(FontCleanupInterval, q_func()); - -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "Client" << client->q_func()->clientId() << "removed font" << font; - qDebug() << "Refcount is" << fontReferenceCount[font]; -#endif - } -} - -static void cleanupFontsDir() -{ - static bool dontDelete = !qgetenv("QWS_KEEP_FONTS").isEmpty(); - if (dontDelete) - return; - - extern QString qws_fontCacheDir(); - QDir dir(qws_fontCacheDir(), QLatin1String("*.qsf")); - for (uint i = 0; i < dir.count(); ++i) { -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "removing stale font file" << dir[i]; -#endif - dir.remove(dir[i]); - } -} - -void QWSServerPrivate::cleanupFonts(bool force) -{ - static bool dontDelete = !qgetenv("QWS_KEEP_FONTS").isEmpty(); - if (dontDelete) - return; - -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "cleanupFonts()"; -#endif - if (!fontReferenceCount.isEmpty()) { - QMap<QByteArray, int>::Iterator it = fontReferenceCount.begin(); - while (it != fontReferenceCount.end()) { - if (it.value() && !force) { - ++it; - continue; - } - - const QByteArray &fontName = it.key(); -#if defined(QWS_DEBUG_FONTCLEANUP) - qDebug() << "removing unused font file" << fontName; -#endif - QT_TRY { - QFile::remove(QFile::decodeName(fontName)); - sendFontRemovedEvent(fontName); - - it = fontReferenceCount.erase(it); - } QT_CATCH(...) { - // so we were not able to remove the font. - // don't be angry and just continue with the next ones. - ++it; - } - } - } - - if (crashedClientIds.isEmpty()) - return; - - QList<QByteArray> removedFonts; -#if !defined(QT_NO_QWS_QPF2) && !defined(QT_FONTS_ARE_RESOURCES) - removedFonts = QFontEngineQPF::cleanUpAfterClientCrash(crashedClientIds); -#endif - crashedClientIds.clear(); - - for (int i = 0; i < removedFonts.count(); ++i) - sendFontRemovedEvent(removedFonts.at(i)); -} - -void QWSServerPrivate::sendFontRemovedEvent(const QByteArray &font) -{ - QWSFontEvent event; - event.simpleData.type = QWSFontEvent::FontRemoved; - event.setData(font.constData(), font.length(), false); - - QMap<int,QWSClient*>::const_iterator it = clientMap.constBegin(); - for (; it != clientMap.constEnd(); ++it) - (*it)->sendEvent(&event); -} - -/*! - \internal -*/ -QWSCommand* QWSClient::readMoreCommand() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - QIODevice *socket = 0; -#endif -#ifndef QT_NO_SXE - if (socketDescriptor != -1) // not server socket - socket = QTransportAuth::getInstance()->passThroughByClient( this ); -#if QTRANSPORTAUTH_DEBUG - if (socket) { - char displaybuf[1024]; - qint64 bytes = socket->bytesAvailable(); - if ( bytes > 511 ) bytes = 511; - hexstring( displaybuf, ((unsigned char *)(reinterpret_cast<QAuthDevice*>(socket)->buffer().constData())), bytes ); - qDebug( "readMoreCommand: %lli bytes - %s", socket->bytesAvailable(), displaybuf ); - } -#endif -#endif // QT_NO_SXE - -#ifndef QT_NO_QWS_MULTIPROCESS - if (!socket) - socket = csocket; // server socket - if (socket) { - // read next command - if (!command) { - int command_type = qws_read_uint(socket); - - if (command_type >= 0) - command = QWSCommand::factory(command_type); - } - if (command) { - if (command->read(socket)) { - // Finished reading a whole command. - QWSCommand* result = command; - command = 0; - return result; - } - } - - // Not finished reading a whole command. - return 0; - } else -#endif // QT_NO_QWS_MULTIPROCESS - { - QList<QWSCommand*> *serverQueue = qt_get_server_queue(); - return serverQueue->isEmpty() ? 0 : serverQueue->takeFirst(); - } -} - - -/*! - \internal -*/ -void QWSServer::processEventQueue() -{ - if (qwsServerPrivate) - qwsServerPrivate->doClient(qwsServerPrivate->clientMap.value(-1)); -} - - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSServerPrivate::_q_doClient() -{ - Q_Q(QWSServer); - - QWSClient* client; -#ifndef QT_NO_SXE - QAuthDevice *ad = qobject_cast<QAuthDevice*>(q->sender()); - if (ad) - client = (QWSClient*)ad->client(); - else -#endif - client = (QWSClient*)q->sender(); - - if (doClientIsActive) { - pendingDoClients.append(client); - return; - } - doClientIsActive = true; - - doClient(client); - - while (!pendingDoClients.isEmpty()) { - doClient(pendingDoClients.takeFirst()); - } - - doClientIsActive = false; -} -#endif // QT_NO_QWS_MULTIPROCESS - -void QWSServerPrivate::doClient(QWSClient *client) -{ - QWSCommand* command=client->readMoreCommand(); - - while (command) { - QWSCommandStruct *cs = new QWSCommandStruct(command, client); - commandQueue.append(cs); - // Try for some more... - command=client->readMoreCommand(); - } - - while (!commandQueue.isEmpty()) { - QWSCommandStruct *cs = commandQueue.takeAt(0); - switch (cs->command->type) { - case QWSCommand::Identify: - invokeIdentify((QWSIdentifyCommand*)cs->command, cs->client); - break; - case QWSCommand::Create: - invokeCreate((QWSCreateCommand*)cs->command, cs->client); - break; -#ifndef QT_NO_QWS_MULTIPROCESS - case QWSCommand::Shutdown: - cs->client->d_func()->shutdown = true; - break; -#endif - case QWSCommand::RegionName: - invokeRegionName((QWSRegionNameCommand*)cs->command, cs->client); - break; - case QWSCommand::Region: - invokeRegion((QWSRegionCommand*)cs->command, cs->client); - cs->client->d_func()->unlockCommunication(); - break; - case QWSCommand::RegionMove: - invokeRegionMove((QWSRegionMoveCommand*)cs->command, cs->client); - cs->client->d_func()->unlockCommunication(); - break; - case QWSCommand::RegionDestroy: - invokeRegionDestroy((QWSRegionDestroyCommand*)cs->command, cs->client); - break; -#ifndef QT_NO_QWS_PROPERTIES - case QWSCommand::AddProperty: - invokeAddProperty((QWSAddPropertyCommand*)cs->command); - break; - case QWSCommand::SetProperty: - invokeSetProperty((QWSSetPropertyCommand*)cs->command); - break; - case QWSCommand::RemoveProperty: - invokeRemoveProperty((QWSRemovePropertyCommand*)cs->command); - break; - case QWSCommand::GetProperty: - invokeGetProperty((QWSGetPropertyCommand*)cs->command, cs->client); - break; -#endif - case QWSCommand::SetSelectionOwner: - invokeSetSelectionOwner((QWSSetSelectionOwnerCommand*)cs->command); - break; - case QWSCommand::RequestFocus: - invokeSetFocus((QWSRequestFocusCommand*)cs->command, cs->client); - break; - case QWSCommand::ChangeAltitude: - invokeSetAltitude((QWSChangeAltitudeCommand*)cs->command, - cs->client); - cs->client->d_func()->unlockCommunication(); - break; - case QWSCommand::SetOpacity: - invokeSetOpacity((QWSSetOpacityCommand*)cs->command, - cs->client); - break; - -#ifndef QT_NO_QWS_CURSOR - case QWSCommand::DefineCursor: - invokeDefineCursor((QWSDefineCursorCommand*)cs->command, cs->client); - break; - case QWSCommand::SelectCursor: - invokeSelectCursor((QWSSelectCursorCommand*)cs->command, cs->client); - break; - case QWSCommand::PositionCursor: - invokePositionCursor((QWSPositionCursorCommand*)cs->command, cs->client); - break; -#endif - case QWSCommand::GrabMouse: - invokeGrabMouse((QWSGrabMouseCommand*)cs->command, cs->client); - break; - case QWSCommand::GrabKeyboard: - invokeGrabKeyboard((QWSGrabKeyboardCommand*)cs->command, cs->client); - break; -#if !defined(QT_NO_SOUND) && !defined(Q_OS_DARWIN) - case QWSCommand::PlaySound: - invokePlaySound((QWSPlaySoundCommand*)cs->command, cs->client); - break; -#endif -#ifndef QT_NO_COP - case QWSCommand::QCopRegisterChannel: - invokeRegisterChannel((QWSQCopRegisterChannelCommand*)cs->command, - cs->client); - break; - case QWSCommand::QCopSend: - invokeQCopSend((QWSQCopSendCommand*)cs->command, cs->client); - break; -#endif -#ifndef QT_NO_QWS_INPUTMETHODS - case QWSCommand::IMUpdate: - invokeIMUpdate((QWSIMUpdateCommand*)cs->command, cs->client); - break; - case QWSCommand::IMResponse: - invokeIMResponse((QWSIMResponseCommand*)cs->command, cs->client); - break; - case QWSCommand::IMMouse: - { - if (current_IM) { - QWSIMMouseCommand *cmd = (QWSIMMouseCommand *) cs->command; - current_IM->mouseHandler(cmd->simpleData.index, - cmd->simpleData.state); - } - } - break; -#endif - case QWSCommand::Font: - invokeFont((QWSFontCommand *)cs->command, cs->client); - break; - case QWSCommand::RepaintRegion: - invokeRepaintRegion((QWSRepaintRegionCommand*)cs->command, - cs->client); - cs->client->d_func()->unlockCommunication(); - break; -#ifndef QT_NO_QWSEMBEDWIDGET - case QWSCommand::Embed: - invokeEmbed(static_cast<QWSEmbedCommand*>(cs->command), - cs->client); - break; -#endif - case QWSCommand::ScreenTransform: - invokeScreenTransform(static_cast<QWSScreenTransformCommand*>(cs->command), - cs->client); - break; - } - delete cs; - } -} - - -void QWSServerPrivate::showCursor() -{ -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->show(); -#endif -} - -void QWSServerPrivate::hideCursor() -{ -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->hide(); -#endif -} - -/*! - \fn void QWSServer::enablePainting(bool enable) - - Enables painting onto the screen if \a enable is true; otherwise - painting is disabled. - - \sa {Qt for Embedded Linux Architecture#Drawing on Screen}{Qt for Embedded Linux - Architecture} -*/ -void QWSServer::enablePainting(bool enable) -{ - Q_D(QWSServer); - - if (d->disablePainting == !enable) - return; - - d->disablePainting = !enable; - - if (enable) { - // Reset the server side allocated regions to ensure update_regions() - // will send out region events. - for (int i = 0; i < d->windows.size(); ++i) { - QWSWindow *w = d->windows.at(i); - w->setAllocatedRegion(QRegion()); -#ifdef QT_QWS_CLIENTBLIT - w->setDirectPaintRegion(QRegion()); -#endif - } - d->update_regions(); - d->showCursor(); - } else { - // Disable painting by clients by taking away their allocated region. - // To ensure mouse events are still delivered to the correct windows, - // the allocated regions are not modified on the server. - for (int i = 0; i < d->windows.size(); ++i) { - QWSWindow *w = d->windows.at(i); - w->client()->sendRegionEvent(w->winId(), QRegion(), - QWSRegionEvent::Allocation); -#ifdef QT_QWS_CLIENTBLIT - w->client()->sendRegionEvent(w->winId(), QRegion(), - QWSRegionEvent::DirectPaint); -#endif - } - d->hideCursor(); - } -} - -/*! - Refreshes the display by making the screen driver update the - entire display. - - \sa QScreen::exposeRegion() -*/ -void QWSServer::refresh() -{ - Q_D(QWSServer); - d->exposeRegion(QScreen::instance()->region()); -//### send repaint to non-buffered windows -} - -/*! - \fn void QWSServer::refresh(QRegion & region) - \overload - - Refreshes the given \a region of the display. -*/ -void QWSServer::refresh(QRegion & r) -{ - Q_D(QWSServer); - d->exposeRegion(r); -//### send repaint to non-buffered windows -} - -/*! - \fn void QWSServer::setMaxWindowRect(const QRect& rectangle) - - Sets the maximum area of the screen that \l{Qt for Embedded Linux} - applications can use, to be the given \a rectangle. - - Note that this function can only be used in the server process. - - \sa QWidget::showMaximized() -*/ -void QWSServer::setMaxWindowRect(const QRect &rect) -{ - QList<QScreen*> subScreens = qt_screen->subScreens(); - if (subScreens.isEmpty() && qt_screen != 0) - subScreens.append(qt_screen); - - for (int i = 0; i < subScreens.size(); ++i) { - const QScreen *screen = subScreens.at(i); - const QRect r = (screen->region() & rect).boundingRect(); - if (r.isEmpty()) - continue; - - QApplicationPrivate *ap = QApplicationPrivate::instance(); - if (ap->maxWindowRect(screen) != r) { - ap->setMaxWindowRect(screen, i, r); - qwsServerPrivate->sendMaxWindowRectEvents(r); - } - } -} - -/*! - \internal -*/ -void QWSServerPrivate::sendMaxWindowRectEvents(const QRect &rect) -{ - QMap<int,QWSClient*>::const_iterator it = clientMap.constBegin(); - for (; it != clientMap.constEnd(); ++it) - (*it)->sendMaxWindowRectEvent(rect); -} - -/*! - \fn void QWSServer::setDefaultMouse(const char *mouseDriver) - - Sets the mouse driver that will be used if the QWS_MOUSE_PROTO - environment variable is not defined, to be the given \a - mouseDriver. - - Note that the default is platform-dependent. This function can - only be used in the server process. - - - \sa setMouseHandler(), {Qt for Embedded Linux Pointer Handling} -*/ -void QWSServer::setDefaultMouse(const char *m) -{ - *defaultMouse() = QString::fromAscii(m); -} - -/*! - \fn void QWSServer::setDefaultKeyboard(const char *keyboardDriver) - - Sets the keyboard driver that will be used if the QWS_KEYBOARD - environment variable is not defined, to be the given \a - keyboardDriver. - - Note that the default is platform-dependent. This function can - only be used in the server process. - - \sa setKeyboardHandler(), {Qt for Embedded Linux Character Input} -*/ -void QWSServer::setDefaultKeyboard(const char *k) -{ - *defaultKeyboard() = QString::fromAscii(k); -} - -#ifndef QT_NO_QWS_CURSOR -static bool prevWin; -#endif - - -extern int *qt_last_x,*qt_last_y; - - -/*! - \internal - - Send a mouse event. \a pos is the screen position where the mouse - event occurred and \a state is a mask indicating which buttons are - pressed. - - \a pos is in device coordinates -*/ -void QWSServer::sendMouseEvent(const QPoint& pos, int state, int wheel) -{ - bool block = qwsServerPrivate->screensaverblockevent(MOUSE, qwsServerPrivate->screensaverinterval, state); -#ifdef EVENT_BLOCK_DEBUG - qDebug() << "sendMouseEvent" << pos.x() << pos.y() << state << (block ? "block" : "pass"); -#endif - - if (state || wheel) - qwsServerPrivate->_q_screenSaverWake(); - - if ( block ) - return; - - QPoint tpos; - // transformations - if (qt_screen->isTransformed()) { - QSize s = QSize(qt_screen->deviceWidth(), qt_screen->deviceHeight()); - tpos = qt_screen->mapFromDevice(pos, s); - } else { - tpos = pos; - } - - if (qt_last_x) { - *qt_last_x = tpos.x(); - *qt_last_y = tpos.y(); - } - QWSServer::mousePosition = tpos; - qwsServerPrivate->mouseState = state; - -#ifndef QT_NO_QWS_INPUTMETHODS - const int btnMask = Qt::LeftButton | Qt::RightButton | Qt::MidButton; - int stroke_count; // number of strokes to keep shown. - if (force_reject_strokeIM || !current_IM) - { - stroke_count = 0; - } else { - stroke_count = current_IM->filter(tpos, state, wheel); - } - - if (stroke_count == 0) { - if (state&btnMask) - force_reject_strokeIM = true; - QWSServerPrivate::sendMouseEventUnfiltered(tpos, state, wheel); - } - // stop force reject after stroke ends. - if (state&btnMask && force_reject_strokeIM) - force_reject_strokeIM = false; - // on end of stroke, force_rejct - // and once a stroke is rejected, do not try again till pen is lifted -#else - QWSServerPrivate::sendMouseEventUnfiltered(tpos, state, wheel); -#endif // end QT_NO_QWS_FSIM -} - -void QWSServerPrivate::sendMouseEventUnfiltered(const QPoint &pos, int state, int wheel) -{ - const int btnMask = Qt::LeftButton | Qt::RightButton | Qt::MidButton; - QWSMouseEvent event; - - QWSWindow *win = qwsServer->windowAt(pos); - - QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1); - QWSClient *winClient = win ? win->client() : 0; - - - bool imMouse = false; -#ifndef QT_NO_QWS_INPUTMETHODS - // check for input method window - if (current_IM && current_IM_winId != -1) { - QWSWindow *kbw = keyboardGrabber ? keyboardGrabber : - qwsServerPrivate->focusw; - - imMouse = kbw == win; - if ( !imMouse ) { - QWidget *target = winClient == serverClient ? - QApplication::widgetAt(pos) : 0; - imMouse = target && (target->testAttribute(Qt::WA_InputMethodTransparent)); - } - } -#endif - - //If grabbing window disappears, grab is still active until - //after mouse release. - if ( qwsServerPrivate->mouseGrabber && (!imMouse || qwsServerPrivate->inputMethodMouseGrabbed)) { - win = qwsServerPrivate->mouseGrabber; - winClient = win ? win->client() : 0; - } - event.simpleData.window = win ? win->id : 0; - -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->move(pos.x(),pos.y()); - - // Arrow cursor over desktop - // prevWin remembers if the last event was over a window - if (!win && prevWin) { - if (!qwsServerPrivate->mouseGrabber) - qwsServerPrivate->setCursor(QWSCursor::systemCursor(Qt::ArrowCursor)); - else - qwsServerPrivate->nextCursor = QWSCursor::systemCursor(Qt::ArrowCursor); - prevWin = false; - } - // reset prevWin - if (win && !prevWin) - prevWin = true; -#endif - - if ((state&btnMask) && !qwsServerPrivate->mouseGrabbing) { - qwsServerPrivate->mouseGrabber = win; - if (imMouse) - qwsServerPrivate->inputMethodMouseGrabbed = true; - } - if (!(state&btnMask)) - qwsServerPrivate->inputMethodMouseGrabbed = false; - - event.simpleData.x_root=pos.x(); - event.simpleData.y_root=pos.y(); - event.simpleData.state=state | qws_keyModifiers; - event.simpleData.delta = wheel; - event.simpleData.time=qwsServerPrivate->timer.elapsed(); - - static int oldstate = 0; - -#ifndef QT_NO_QWS_INPUTMETHODS - //tell the input method if we click on a different window that is not IM transparent - bool isPress = state > oldstate; - if (isPress && !imMouse && current_IM && current_IM_winId != -1) - current_IM->mouseHandler(-1, QWSServer::MouseOutside); -#endif - - if (serverClient) - serverClient->sendEvent(&event); - if (winClient && winClient != serverClient) - winClient->sendEvent(&event); - - if ( !imMouse ) { - // Make sure that if we leave a window, that window gets one last mouse - // event so that it knows the mouse has left. - QWSClient *oldClient = qwsServer->d_func()->cursorClient; - if (oldClient && oldClient != winClient && oldClient != serverClient) { - event.simpleData.state = oldstate | qws_keyModifiers; - oldClient->sendEvent(&event); - } - } - - oldstate = state; - if ( !imMouse ) - qwsServer->d_func()->cursorClient = winClient; - - if (!(state&btnMask) && !qwsServerPrivate->mouseGrabbing) - qwsServerPrivate->releaseMouse(qwsServerPrivate->mouseGrabber); -} - -/*! - Returns the primary mouse driver. - - Note that this function can only be used in the server process. - - \sa setMouseHandler(), openMouse(), closeMouse() -*/ -QWSMouseHandler *QWSServer::mouseHandler() -{ - if (qwsServerPrivate->mousehandlers.empty()) - return 0; - return qwsServerPrivate->mousehandlers.first(); -} - -/*! - \since 4.5 - - Returns list of all mouse handlers - - Note that this function can only be used in the server process. - - \sa mouseHandler(), setMouseHandler(), openMouse(), closeMouse() -*/ -const QList<QWSMouseHandler*>& QWSServer::mouseHandlers() -{ - return qwsServerPrivate->mousehandlers; -} - - -// called by QWSMouseHandler constructor, not user code. -/*! - \fn void QWSServer::setMouseHandler(QWSMouseHandler* driver) - - Sets the primary mouse driver to be the given \a driver. - - \l{Qt for Embedded Linux} provides several ready-made mouse drivers, and - custom drivers are typically added using Qt's plugin - mechanism. See the \l{Qt for Embedded Linux Pointer Handling} documentation - for details. - - Note that this function can only be used in the server process. - - \sa mouseHandler(), setDefaultMouse() -*/ -void QWSServer::setMouseHandler(QWSMouseHandler* mh) -{ - if (!mh) - return; - qwsServerPrivate->mousehandlers.removeAll(mh); - qwsServerPrivate->mousehandlers.prepend(mh); -} - -/*! - \internal - \obsolete - Caller owns data in list, and must delete contents -*/ -QList<QWSInternalWindowInfo*> * QWSServer::windowList() -{ - QList<QWSInternalWindowInfo*> * ret=new QList<QWSInternalWindowInfo*>; - for (int i=0; i < qwsServerPrivate->windows.size(); ++i) { - QWSWindow *window = qwsServerPrivate->windows.at(i); - QWSInternalWindowInfo * qwi=new QWSInternalWindowInfo(); - qwi->winid=window->winId(); - qwi->clientid=window->client()->clientId(); - ret->append(qwi); - } - return ret; -} - -#ifndef QT_NO_COP -/*! - \internal -*/ -void QWSServerPrivate::sendQCopEvent(QWSClient *c, const QString &ch, - const QString &msg, const QByteArray &data, - bool response) -{ - Q_ASSERT(c); - - QWSQCopMessageEvent event; - event.channel = ch.toLatin1(); - event.message = msg.toLatin1(); - event.data = data; - event.simpleData.is_response = response; - event.simpleData.lchannel = ch.length(); - event.simpleData.lmessage = msg.length(); - event.simpleData.ldata = data.size(); - int l = event.simpleData.lchannel + event.simpleData.lmessage + - event.simpleData.ldata; - - // combine channel, message and data into one block of raw bytes - char *tmp = new char [l]; - char *d = tmp; - memcpy(d, event.channel.constData(), event.simpleData.lchannel); - d += event.simpleData.lchannel; - memcpy(d, event.message.constData(), event.simpleData.lmessage); - d += event.simpleData.lmessage; - memcpy(d, data.constData(), event.simpleData.ldata); - - event.setDataDirect(tmp, l); - - c->sendEvent(&event); -} -#endif - -/*! - \fn QWSWindow *QWSServer::windowAt(const QPoint& position) - - Returns the window containing the given \a position. - - Note that if there is no window under the specified point this - function returns 0. - - \sa clientWindows(), instance() -*/ -QWSWindow *QWSServer::windowAt(const QPoint& pos) -{ - Q_D(QWSServer); - for (int i=0; i<d->windows.size(); ++i) { - QWSWindow* w = d->windows.at(i); - if (w->allocatedRegion().contains(pos)) - return w; - } - return 0; -} - -#ifndef QT_NO_QWS_KEYBOARD -static int keyUnicode(int keycode) -{ - int code = 0xffff; - - if (keycode >= Qt::Key_A && keycode <= Qt::Key_Z) - code = keycode - Qt::Key_A + 'a'; - else if (keycode >= Qt::Key_0 && keycode <= Qt::Key_9) - code = keycode - Qt::Key_0 + '0'; - - return code; -} -#endif - -/*! - Sends the given key event. The key is identified by its \a unicode - value and the given \a keycode, \a modifiers, \a isPress and \a - autoRepeat parameters. - - Use this function to send key events generated by "virtual - keyboards" (note that the processKeyEvent() function is - impelemented using this function). - - The \a keycode parameter is the Qt keycode value as defined by the - Qt::Key enum. The \a modifiers is an OR combination of - Qt::KeyboardModifier values, indicating whether \gui - Shift/Alt/Ctrl keys are pressed. The \a isPress parameter is true - if the event is a key press event and \a autoRepeat is true if the - event is caused by an auto-repeat mechanism and not an actual key - press. - - Note that this function can only be used in the server process. - - \sa processKeyEvent(), {Qt for Embedded Linux Character Input} -*/ -void QWSServer::sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat) -{ - qws_keyModifiers = modifiers; - - if (isPress) { - if (keycode != Qt::Key_F34 && keycode != Qt::Key_F35) - qwsServerPrivate->_q_screenSaverWake(); - } - -#ifndef QT_NO_QWS_INPUTMETHODS - - if (!current_IM || !current_IM->filter(unicode, keycode, modifiers, isPress, autoRepeat)) - QWSServerPrivate::sendKeyEventUnfiltered(unicode, keycode, modifiers, isPress, autoRepeat); -#else - QWSServerPrivate::sendKeyEventUnfiltered(unicode, keycode, modifiers, isPress, autoRepeat); -#endif -} - -void QWSServerPrivate::sendKeyEventUnfiltered(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat) -{ - - QWSKeyEvent event; - QWSWindow *win = keyboardGrabber ? keyboardGrabber : - qwsServerPrivate->focusw; - - event.simpleData.window = win ? win->winId() : 0; - - event.simpleData.unicode = -#ifndef QT_NO_QWS_KEYBOARD - unicode < 0 ? keyUnicode(keycode) : -#endif - unicode; - event.simpleData.keycode = keycode; - event.simpleData.modifiers = modifiers; - event.simpleData.is_press = isPress; - event.simpleData.is_auto_repeat = autoRepeat; - - QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1); - QWSClient *winClient = win ? win->client() : 0; - if (serverClient) - serverClient->sendEvent(&event); - if (winClient && winClient != serverClient) - winClient->sendEvent(&event); -} - -/*! - \internal -*/ -void QWSServer::beginDisplayReconfigure() -{ - qwsServer->enablePainting(false); -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->hide(); -#endif - QWSDisplay::grab(true); - qt_screen->disconnect(); -} - -/*! - \internal -*/ -void QWSServer::endDisplayReconfigure() -{ - qt_screen->connect(QString()); - qwsServerPrivate->swidth = qt_screen->deviceWidth(); - qwsServerPrivate->sheight = qt_screen->deviceHeight(); - - QWSDisplay::ungrab(); -#ifndef QT_NO_QWS_CURSOR - if (qt_screencursor) - qt_screencursor->show(); -#endif - QApplicationPrivate *ap = QApplicationPrivate::instance(); - ap->setMaxWindowRect(qt_screen, 0, - QRect(0, 0, qt_screen->width(), qt_screen->height())); - QSize olds = qApp->desktop()->size(); - qApp->desktop()->resize(qt_screen->width(), qt_screen->height()); - qApp->postEvent(qApp->desktop(), new QResizeEvent(qApp->desktop()->size(), olds)); - qwsServer->enablePainting(true); - qwsServer->refresh(); - qDebug("Desktop size: %dx%d", qApp->desktop()->width(), qApp->desktop()->height()); -} - -void QWSServerPrivate::resetEngine() -{ -#ifndef QT_NO_QWS_CURSOR - if (!qt_screencursor) - return; - qt_screencursor->hide(); - qt_screencursor->show(); -#endif -} - - -#ifndef QT_NO_QWS_CURSOR -/*! - \fn void QWSServer::setCursorVisible(bool visible) - - Shows the cursor if \a visible is true: otherwise the cursor is - hidden. - - Note that this function can only be used in the server process. - - \sa isCursorVisible() -*/ -void QWSServer::setCursorVisible(bool vis) -{ - if (qwsServerPrivate && qwsServerPrivate->haveviscurs != vis) { - QWSCursor* c = qwsServerPrivate->cursor; - qwsServerPrivate->setCursor(QWSCursor::systemCursor(Qt::BlankCursor)); - qwsServerPrivate->haveviscurs = vis; - qwsServerPrivate->setCursor(c); - } -} - -/*! - Returns true if the cursor is visible; otherwise returns false. - - Note that this function can only be used in the server process. - - \sa setCursorVisible() -*/ -bool QWSServer::isCursorVisible() -{ - return qwsServerPrivate ? qwsServerPrivate->haveviscurs : true; -} -#endif - -#ifndef QT_NO_QWS_INPUTMETHODS - - -/*! - \fn void QWSServer::sendIMEvent(const QInputMethodEvent *event) - - Sends the given input method \a event. - - The \c QInputMethodEvent class is derived from QWSEvent, i.e., it - is a QWSEvent object of the QWSEvent::IMEvent type. - - If there is a window actively composing the preedit string, the - event is sent to that window. Otherwise, the event is sent to the - window currently in focus. - - \sa sendIMQuery(), QWSInputMethod::sendEvent() -*/ -void QWSServer::sendIMEvent(const QInputMethodEvent *ime) -{ - QWSIMEvent event; - - QWSWindow *win = keyboardGrabber ? keyboardGrabber : - qwsServerPrivate->focusw; - - //if currently composing then event must go to the composing window - - if (current_IM_composing_win) - win = current_IM_composing_win; - - event.simpleData.window = win ? win->winId() : 0; - event.simpleData.replaceFrom = ime->replacementStart();; - event.simpleData.replaceLength = ime->replacementLength(); - - QBuffer buffer; - buffer.open(QIODevice::WriteOnly); - QDataStream out(&buffer); - - out << ime->preeditString(); - out << ime->commitString(); - - const QList<QInputMethodEvent::Attribute> &attributes = ime->attributes(); - for (int i = 0; i < attributes.count(); ++i) { - const QInputMethodEvent::Attribute &a = attributes.at(i); - out << a.type << a.start << a.length << a.value; - } - event.setData(buffer.data(), buffer.size()); - QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1); - if (serverClient) - serverClient->sendEvent(&event); - if (win && win->client() && win->client() != serverClient) - win->client()->sendEvent(&event); - - current_IM_composing_win = ime->preeditString().isEmpty() ? 0 : win; - current_IM_winId = win ? win->winId() : 0; -} - - -/*! - Sends an input method query for the given \a property. - - To receive responses to input method queries, the virtual - QWSInputMethod::queryResponse() function must be reimplemented in - a QWSInputMethod subclass that is activated using the - setCurrentInputMethod() function. - - \sa sendIMEvent(), setCurrentInputMethod() -*/ -void QWSServer::sendIMQuery(int property) -{ - QWSIMQueryEvent event; - - QWSWindow *win = keyboardGrabber ? keyboardGrabber : - qwsServerPrivate->focusw; - if (current_IM_composing_win) - win = current_IM_composing_win; - - event.simpleData.window = win ? win->winId() : 0; - event.simpleData.property = property; - if (win && win->client()) - win->client()->sendEvent(&event); -} - - - -/*! - \fn void QWSServer::setCurrentInputMethod(QWSInputMethod *method) - - Sets the current input method to be the given \a method. - - Note that this function can only be used in the server process. - - \sa sendIMQuery(), sendIMEvent() -*/ -void QWSServer::setCurrentInputMethod(QWSInputMethod *im) -{ - if (current_IM) - current_IM->reset(); //??? send an update event instead ? - current_IM = im; -} - -/*! - \fn static void QWSServer::resetInputMethod() - - \internal -*/ - -#endif //QT_NO_QWS_INPUTMETHODS - -#ifndef QT_NO_QWS_PROPERTIES -/*! - \internal -*/ -void QWSServer::sendPropertyNotifyEvent(int property, int state) -{ - Q_D(QWSServer); - QWSServerPrivate::ClientIterator it = d->clientMap.begin(); - while (it != d->clientMap.end()) { - QWSClient *cl = *it; - ++it; - cl->sendPropertyNotifyEvent(property, state); - } -} -#endif - -void QWSServerPrivate::invokeIdentify(const QWSIdentifyCommand *cmd, QWSClient *client) -{ - client->setIdentity(cmd->id); -#ifndef QT_NO_QWS_MULTIPROCESS - if (client->clientId() > 0) - client->d_func()->setLockId(cmd->simpleData.idLock); -#endif -} - -void QWSServerPrivate::invokeCreate(QWSCreateCommand *cmd, QWSClient *client) -{ - QWSCreationEvent event; - event.simpleData.objectid = get_object_id(cmd->count); - event.simpleData.count = cmd->count; - client->sendEvent(&event); -} - -void QWSServerPrivate::invokeRegionName(const QWSRegionNameCommand *cmd, QWSClient *client) -{ - Q_Q(QWSServer); - QWSWindow* changingw = findWindow(cmd->simpleData.windowid, client); - if (changingw && (changingw->name() != cmd->name || changingw->caption() !=cmd->caption)) { - changingw->setName(cmd->name); - changingw->setCaption(cmd->caption); - emit q->windowEvent(changingw, QWSServer::Name); - } -} - -void QWSServerPrivate::invokeRegion(QWSRegionCommand *cmd, QWSClient *client) -{ -#ifdef QWS_REGION_DEBUG - qDebug("QWSServer::invokeRegion %d rects (%d)", - cmd->simpleData.nrectangles, cmd->simpleData.windowid); -#endif - - QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0); - if (!changingw) { - qWarning("Invalid window handle %08x",cmd->simpleData.windowid); - return; - } - if (!changingw->forClient(client)) { - qWarning("Disabled: clients changing other client's window region"); - return; - } - - request_region(cmd->simpleData.windowid, cmd->surfaceKey, cmd->surfaceData, - cmd->region); -} - -void QWSServerPrivate::invokeRegionMove(const QWSRegionMoveCommand *cmd, QWSClient *client) -{ - Q_Q(QWSServer); - QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0); - if (!changingw) { - qWarning("invokeRegionMove: Invalid window handle %d",cmd->simpleData.windowid); - return; - } - if (!changingw->forClient(client)) { - qWarning("Disabled: clients changing other client's window region"); - return; - } - -// changingw->setNeedAck(true); - moveWindowRegion(changingw, cmd->simpleData.dx, cmd->simpleData.dy); - emit q->windowEvent(changingw, QWSServer::Geometry); -} - -void QWSServerPrivate::invokeRegionDestroy(const QWSRegionDestroyCommand *cmd, QWSClient *client) -{ - Q_Q(QWSServer); - QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0); - if (!changingw) { - qWarning("invokeRegionDestroy: Invalid window handle %d",cmd->simpleData.windowid); - return; - } - if (!changingw->forClient(client)) { - qWarning("Disabled: clients changing other client's window region"); - return; - } - - setWindowRegion(changingw, QRegion()); -// rgnMan->remove(changingw->allocationIndex()); - for (int i = 0; i < windows.size(); ++i) { - if (windows.at(i) == changingw) { - windows.takeAt(i); - if (i < nReserved) - --nReserved; - break; - } - } - - handleWindowClose(changingw); -#ifndef QT_NO_QWS_PROPERTIES - propertyManager.removeProperties(changingw->winId()); -#endif - emit q->windowEvent(changingw, QWSServer::Destroy); - delete changingw; -} - -void QWSServerPrivate::invokeSetFocus(const QWSRequestFocusCommand *cmd, QWSClient *client) -{ - int winId = cmd->simpleData.windowid; - int gain = cmd->simpleData.flag; - - if (gain != 0 && gain != 1) { - qWarning("Only 0(lose) and 1(gain) supported"); - return; - } - - QWSWindow* changingw = findWindow(winId, 0); - if (!changingw) - return; - - if (!changingw->forClient(client)) { - qWarning("Disabled: clients changing other client's focus"); - return; - } - - setFocus(changingw, gain); -} - -void QWSServerPrivate::setFocus(QWSWindow* changingw, bool gain) -{ - Q_Q(QWSServer); -#ifndef QT_NO_QWS_INPUTMETHODS - /* - This is the logic: - QWSWindow *loser = 0; - if (gain && focusw != changingw) - loser = focusw; - else if (!gain && focusw == changingw) - loser = focusw; - But these five lines can be reduced to one: - */ - if (current_IM) { - QWSWindow *loser = (!gain == (focusw==changingw)) ? focusw : 0; - if (loser && loser->winId() == current_IM_winId) - current_IM->updateHandler(QWSInputMethod::FocusOut); - } -#endif - if (gain) { - if (focusw != changingw) { - if (focusw) focusw->focus(0); - focusw = changingw; - focusw->focus(1); - emit q->windowEvent(focusw, QWSServer::Active); - } - } else if (focusw == changingw) { - if (changingw->client()) - changingw->focus(0); - focusw = 0; - // pass focus to window which most recently got it... - QWSWindow* bestw=0; - for (int i=0; i<windows.size(); ++i) { - QWSWindow* w = windows.at(i); - if (w != changingw && !w->hidden() && - (!bestw || bestw->focusPriority() < w->focusPriority())) - bestw = w; - } - if (!bestw && changingw->focusPriority()) { // accept focus back? - bestw = changingw; // must be the only one - } - focusw = bestw; - if (focusw) { - focusw->focus(1); - emit q->windowEvent(focusw, QWSServer::Active); - } - } -} - - - -void QWSServerPrivate::invokeSetOpacity(const QWSSetOpacityCommand *cmd, QWSClient *client) -{ - Q_UNUSED( client ); - int winId = cmd->simpleData.windowid; - int opacity = cmd->simpleData.opacity; - - QWSWindow* changingw = findWindow(winId, 0); - - if (!changingw) { - qWarning("invokeSetOpacity: Invalid window handle %d", winId); - return; - } - - int altitude = windows.indexOf(changingw); - const bool wasOpaque = changingw->isOpaque(); - changingw->_opacity = opacity; - if (wasOpaque != changingw->isOpaque()) - update_regions(); - exposeRegion(changingw->allocatedRegion(), altitude); -} - -void QWSServerPrivate::invokeSetAltitude(const QWSChangeAltitudeCommand *cmd, - QWSClient *client) -{ - Q_UNUSED(client); - - int winId = cmd->simpleData.windowid; - int alt = cmd->simpleData.altitude; - bool fixed = cmd->simpleData.fixed; -#if 0 - qDebug("QWSServer::invokeSetAltitude winId %d alt %d)", winId, alt); -#endif - - if (alt < -1 || alt > 1) { - qWarning("QWSServer::invokeSetAltitude Only lower, raise and stays-on-top supported"); - return; - } - - QWSWindow* changingw = findWindow(winId, 0); - if (!changingw) { - qWarning("invokeSetAltitude: Invalid window handle %d", winId); - return; - } - - if (fixed && alt >= 1) { - changingw->onTop = true; - } - if (alt == QWSChangeAltitudeCommand::Lower) - changingw->lower(); - else - changingw->raise(); - -// if (!changingw->forClient(client)) { -// refresh(); -// } -} - -#ifndef QT_NO_QWS_PROPERTIES -void QWSServerPrivate::invokeAddProperty(QWSAddPropertyCommand *cmd) -{ - propertyManager.addProperty(cmd->simpleData.windowid, cmd->simpleData.property); -} - -void QWSServerPrivate::invokeSetProperty(QWSSetPropertyCommand *cmd) -{ - Q_Q(QWSServer); - if (propertyManager.setProperty(cmd->simpleData.windowid, - cmd->simpleData.property, - cmd->simpleData.mode, - cmd->data, - cmd->rawLen)) { - q->sendPropertyNotifyEvent(cmd->simpleData.property, - QWSPropertyNotifyEvent::PropertyNewValue); -#ifndef QT_NO_QWS_INPUTMETHODS - if (cmd->simpleData.property == QT_QWS_PROPERTY_MARKEDTEXT) { - QString s((const QChar*)cmd->data, cmd->rawLen/2); - emit q->markedText(s); - } -#endif - } -} - -void QWSServerPrivate::invokeRemoveProperty(QWSRemovePropertyCommand *cmd) -{ - Q_Q(QWSServer); - if (propertyManager.removeProperty(cmd->simpleData.windowid, - cmd->simpleData.property)) { - q->sendPropertyNotifyEvent(cmd->simpleData.property, - QWSPropertyNotifyEvent::PropertyDeleted); - } -} - - -bool QWSServerPrivate:: get_property(int winId, int property, const char *&data, int &len) -{ - return propertyManager.getProperty(winId, property, data, len); -} - - -void QWSServerPrivate::invokeGetProperty(QWSGetPropertyCommand *cmd, QWSClient *client) -{ - const char *data; - int len; - - if (propertyManager.getProperty(cmd->simpleData.windowid, - cmd->simpleData.property, - data, len)) { - client->sendPropertyReplyEvent(cmd->simpleData.property, len, data); - } else { - client->sendPropertyReplyEvent(cmd->simpleData.property, -1, 0); - } -} -#endif //QT_NO_QWS_PROPERTIES - -void QWSServerPrivate::invokeSetSelectionOwner(QWSSetSelectionOwnerCommand *cmd) -{ - qDebug("QWSServer::invokeSetSelectionOwner"); - - SelectionOwner so; - so.windowid = cmd->simpleData.windowid; - so.time.set(cmd->simpleData.hour, cmd->simpleData.minute, - cmd->simpleData.sec, cmd->simpleData.ms); - - if (selectionOwner.windowid != -1) { - QWSWindow *win = findWindow(selectionOwner.windowid, 0); - if (win) - win->client()->sendSelectionClearEvent(selectionOwner.windowid); - else - qDebug("couldn't find window %d", selectionOwner.windowid); - } - - selectionOwner = so; -} - -void QWSServerPrivate::invokeConvertSelection(QWSConvertSelectionCommand *cmd) -{ - qDebug("QWSServer::invokeConvertSelection"); - - if (selectionOwner.windowid != -1) { - QWSWindow *win = findWindow(selectionOwner.windowid, 0); - if (win) - win->client()->sendSelectionRequestEvent(cmd, selectionOwner.windowid); - else - qDebug("couldn't find window %d", selectionOwner.windowid); - } -} - -#ifndef QT_NO_QWS_CURSOR -void QWSServerPrivate::invokeDefineCursor(QWSDefineCursorCommand *cmd, QWSClient *client) -{ - if (cmd->simpleData.height > 64 || cmd->simpleData.width > 64) { - qDebug("Cannot define cursor size > 64x64"); - return; - } - - delete client->cursors.take(cmd->simpleData.id); - - int dataLen = cmd->simpleData.height * ((cmd->simpleData.width+7) / 8); - - if (dataLen > 0 && cmd->data) { - QWSCursor *curs = new QWSCursor(cmd->data, cmd->data + dataLen, - cmd->simpleData.width, cmd->simpleData.height, - cmd->simpleData.hotX, cmd->simpleData.hotY); - client->cursors.insert(cmd->simpleData.id, curs); - } -} - -void QWSServerPrivate::invokeSelectCursor(QWSSelectCursorCommand *cmd, QWSClient *client) -{ - int id = cmd->simpleData.id; - QWSCursor *curs = 0; - if (id <= Qt::LastCursor) { - curs = QWSCursor::systemCursor(id); - } - else { - QWSCursorMap cursMap = client->cursors; - QWSCursorMap::Iterator it = cursMap.find(id); - if (it != cursMap.end()) { - curs = it.value(); - } - } - if (curs == 0) { - curs = QWSCursor::systemCursor(Qt::ArrowCursor); - } - - QWSWindow* win = findWindow(cmd->simpleData.windowid, 0); - if (mouseGrabber) { - // If the mouse is being grabbed, we don't want just anyone to - // be able to change the cursor. We do want the cursor to be set - // correctly once mouse grabbing is stopped though. - if (win != mouseGrabber) - nextCursor = curs; - else - setCursor(curs); - } else if (win && win->allocatedRegion().contains(QWSServer::mousePosition)) { //##################### cursor - // A non-grabbing window can only set the cursor shape if the - // cursor is within its allocated region. - setCursor(curs); - } -} - -void QWSServerPrivate::invokePositionCursor(QWSPositionCursorCommand *cmd, QWSClient *) -{ - Q_Q(QWSServer); - QPoint newPos(cmd->simpleData.newX, cmd->simpleData.newY); - if (newPos != QWSServer::mousePosition) - q->sendMouseEvent(newPos, qwsServer->d_func()->mouseState); -} -#endif - -void QWSServerPrivate::invokeGrabMouse(QWSGrabMouseCommand *cmd, QWSClient *client) -{ - QWSWindow* win = findWindow(cmd->simpleData.windowid, 0); - if (!win) - return; - - if (cmd->simpleData.grab) { - if (!mouseGrabber || mouseGrabber->client() == client) { - mouseGrabbing = true; - mouseGrabber = win; - } - } else { - releaseMouse(mouseGrabber); - } -} - -void QWSServerPrivate::invokeGrabKeyboard(QWSGrabKeyboardCommand *cmd, QWSClient *client) -{ - QWSWindow* win = findWindow(cmd->simpleData.windowid, 0); - if (!win) - return; - - if (cmd->simpleData.grab) { - if (!keyboardGrabber || (keyboardGrabber->client() == client)) { - keyboardGrabbing = true; - keyboardGrabber = win; - } - } else { - releaseKeyboard(keyboardGrabber); - } -} - -#if !defined(QT_NO_SOUND) -void QWSServerPrivate::invokePlaySound(QWSPlaySoundCommand *cmd, QWSClient *) -{ -#if !defined(QT_EXTERNAL_SOUND_SERVER) && !defined(Q_OS_DARWIN) - soundserver->playFile( 1, cmd->filename ); -#else - Q_UNUSED(cmd); -#endif -} -#endif - -#ifndef QT_NO_COP -void QWSServerPrivate::invokeRegisterChannel(QWSQCopRegisterChannelCommand *cmd, - QWSClient *client) -{ - // QCopChannel will force us to emit the newChannel signal if this channel - // didn't already exist. - QCopChannel::registerChannel(cmd->channel, client); -} - -void QWSServerPrivate::invokeQCopSend(QWSQCopSendCommand *cmd, QWSClient *client) -{ - QCopChannel::answer(client, cmd->channel, cmd->message, cmd->data); -} - -#endif - -#ifndef QT_NO_QWS_INPUTMETHODS -void QWSServer::resetInputMethod() -{ - if (current_IM && qwsServer) { - current_IM->reset(); - } -} - -void QWSServerPrivate::invokeIMResponse(const QWSIMResponseCommand *cmd, - QWSClient *) -{ - if (current_IM) - current_IM->queryResponse(cmd->simpleData.property, cmd->result); -} - -void QWSServerPrivate::invokeIMUpdate(const QWSIMUpdateCommand *cmd, - QWSClient *) -{ - if (cmd->simpleData.type == QWSInputMethod::FocusIn) - current_IM_winId = cmd->simpleData.windowid; - - if (current_IM && (current_IM_winId == cmd->simpleData.windowid || cmd->simpleData.windowid == -1)) - current_IM->updateHandler(cmd->simpleData.type); -} - -#endif - -void QWSServerPrivate::invokeFont(const QWSFontCommand *cmd, QWSClient *client) -{ - QWSClientPrivate *priv = client->d_func(); - if (cmd->simpleData.type == QWSFontCommand::StartedUsingFont) { - referenceFont(priv, cmd->fontName); - } else if (cmd->simpleData.type == QWSFontCommand::StoppedUsingFont) { - dereferenceFont(priv, cmd->fontName); - } -} - -void QWSServerPrivate::invokeRepaintRegion(QWSRepaintRegionCommand * cmd, - QWSClient *) -{ - QRegion r; - r.setRects(cmd->rectangles,cmd->simpleData.nrectangles); - repaint_region(cmd->simpleData.windowid, cmd->simpleData.windowFlags, cmd->simpleData.opaque, r); -} - -#ifndef QT_NO_QWSEMBEDWIDGET -void QWSServerPrivate::invokeEmbed(QWSEmbedCommand *cmd, QWSClient *client) -{ - // Should find these two windows in a single loop - QWSWindow *embedder = findWindow(cmd->simpleData.embedder, client); - QWSWindow *embedded = findWindow(cmd->simpleData.embedded); - - if (!embedder) { - qWarning("QWSServer: Embed command from window %i failed: No such id.", - static_cast<int>(cmd->simpleData.embedder)); - return; - } - - if (!embedded) { - qWarning("QWSServer: Embed command on window %i failed: No such id.", - static_cast<int>(cmd->simpleData.embedded)); - return; - } - - switch (cmd->simpleData.type) { - case QWSEmbedEvent::StartEmbed: - embedder->startEmbed(embedded); - windows.removeAll(embedded); - windows.insert(windows.indexOf(embedder), embedded); - break; - case QWSEmbedEvent::StopEmbed: - embedder->stopEmbed(embedded); - break; - case QWSEmbedEvent::Region: - break; - } - - embedded->client()->sendEmbedEvent(embedded->winId(), - cmd->simpleData.type, cmd->region); - const QRegion oldAllocated = embedded->allocatedRegion(); - update_regions(); - exposeRegion(oldAllocated - embedded->allocatedRegion(), - windows.indexOf(embedded)); -} -#endif // QT_NO_QWSEMBEDWIDGET - -void QWSServerPrivate::invokeScreenTransform(const QWSScreenTransformCommand *cmd, - QWSClient *client) -{ - Q_UNUSED(client); - - QWSScreenTransformationEvent event; - event.simpleData.screen = cmd->simpleData.screen; - event.simpleData.transformation = cmd->simpleData.transformation; - - QMap<int, QWSClient*>::const_iterator it = clientMap.constBegin(); - for (; it != clientMap.constEnd(); ++it) - (*it)->sendEvent(&event); -} - -QWSWindow* QWSServerPrivate::newWindow(int id, QWSClient* client) -{ - Q_Q(QWSServer); - // Make a new window, put it on top. - QWSWindow* w = new QWSWindow(id,client); - - // insert after "stays on top" windows - bool added = false; - for (int i = nReserved; i < windows.size(); ++i) { - QWSWindow *win = windows.at(i); - if (!win->onTop) { - windows.insert(i, w); - added = true; - break; - } - } - if (!added) - windows.append(w); - emit q->windowEvent(w, QWSServer::Create); - return w; -} - -QWSWindow* QWSServerPrivate::findWindow(int windowid, QWSClient* client) -{ - for (int i=0; i<windows.size(); ++i) { - QWSWindow* w = windows.at(i); - if (w->winId() == windowid) - return w; - } - if (client) - return newWindow(windowid,client); - else - return 0; -} - -void QWSServerPrivate::raiseWindow(QWSWindow *changingw, int /*alt*/) -{ - Q_Q(QWSServer); - if (changingw == windows.first()) - return; - QWSWindow::State oldstate = changingw->d->state; - changingw->d->state = QWSWindow::Raising; - // Expose regions previously overlapped by transparent windows - const QRegion bound = changingw->allocatedRegion(); - QRegion expose; - int windowPos = 0; - - //change position in list: - for (int i = 0; i < windows.size(); ++i) { - QWSWindow *w = windows.at(i); - if (w == changingw) { - windowPos = i; - windows.takeAt(i); - break; - } - if (!w->isOpaque()) - expose += (w->allocatedRegion() & bound); - } - - bool onTop = changingw->onTop; - -#ifndef QT_NO_QWSEMBEDWIDGET - // an embedded window is on top if the embedder is on top - QWSWindow *embedder = changingw->d->embedder; - while (!onTop && embedder) { - onTop = embedder->onTop; - embedder = embedder->d->embedder; - } -#endif - - int newPos = -1; - if (onTop) { - windows.insert(nReserved, changingw); - newPos = nReserved; - } else { - // insert after "stays on top" windows - bool in = false; - for (int i = nReserved; i < windows.size(); ++i) { - QWSWindow *w = windows.at(i); - if (!w->onTop) { - windows.insert(i, changingw); - in = true; - newPos = i; - break; - } - } - if (!in) { - windows.append(changingw); - newPos = windows.size()-1; - } - } - - if (windowPos != newPos) { - update_regions(); - if (!expose.isEmpty()) - exposeRegion(expose, newPos); - } - changingw->d->state = oldstate; - emit q->windowEvent(changingw, QWSServer::Raise); -} - -void QWSServerPrivate::lowerWindow(QWSWindow *changingw, int /*alt*/) -{ - Q_Q(QWSServer); - if (changingw == windows.last()) - return; - QWSWindow::State oldstate = changingw->d->state; - changingw->d->state = QWSWindow::Lowering; - - int i = windows.indexOf(changingw); - int newIdx = windows.size()-1; - windows.move(i, newIdx); - - const QRegion bound = changingw->allocatedRegion(); - - update_regions(); - - // Expose regions previously overlapped by transparent window - if (!changingw->isOpaque()) { - QRegion expose; - for (int j = i; j < windows.size() - 1; ++j) - expose += (windows.at(j)->allocatedRegion() & bound); - if (!expose.isEmpty()) - exposeRegion(expose, newIdx); - } - - changingw->d->state = oldstate; - emit q->windowEvent(changingw, QWSServer::Lower); -} - -void QWSServerPrivate::update_regions() -{ - if (disablePainting) - return; - - QRegion available = QRect(0, 0, qt_screen->width(), qt_screen->height()); - QRegion transparentRegion; - - // only really needed if there are unbuffered surfaces... - const bool doLock = (clientMap.size() > 1); - if (doLock) - QWSDisplay::grab(true); - - for (int i = 0; i < windows.count(); ++i) { - QWSWindow *w = windows.at(i); - QRegion r = (w->requested_region & available); - -#ifndef QT_NO_QWSEMBEDWIDGET - // Subtract regions needed for embedded windows - const int n = w->d->embedded.size(); - for (int i = 0; i < n; ++i) - r -= w->d->embedded.at(i)->allocatedRegion(); - - // Limited to the embedder region - if (w->d->embedder) - r &= w->d->embedder->requested_region; -#endif // QT_NO_QWSEMBEDWIDGET - - QWSWindowSurface *surface = w->windowSurface(); - const bool opaque = w->isOpaque() - && (w->d->painted || !surface || !surface->isBuffered()); - - if (!opaque) { - transparentRegion += r; - } else { - if (surface && (surface->isRegionReserved() || !surface->isBuffered())) - r -= transparentRegion; - available -= r; - } - - if (r != w->allocatedRegion()) { - w->setAllocatedRegion(r); - w->client()->sendRegionEvent(w->winId(), r, - QWSRegionEvent::Allocation); - } - -#ifdef QT_QWS_CLIENTBLIT -#ifdef QT_NO_QWS_CURSOR - // This optimization only really works when there isn't a crazy cursor - // wizzing around. - QRegion directPaint = (r - transparentRegion); // in gloal coords - if(directPaint != w->directPaintRegion()) { - w->setDirectPaintRegion(directPaint); - static int id = 0; - surface->setDirectRegion(directPaint, ++id); - w->client()->sendRegionEvent(w->winId(), directPaint, - QWSRegionEvent::DirectPaint, id); - } -#endif -#endif - } - - if (doLock) - QWSDisplay::ungrab(); -} - -void QWSServerPrivate::moveWindowRegion(QWSWindow *changingw, int dx, int dy) -{ - if (!changingw) - return; - - QWSWindow::State oldState = changingw->d->state; - changingw->d->state = QWSWindow::Moving; - const QRegion oldRegion(changingw->allocatedRegion()); - changingw->requested_region.translate(dx, dy); - - // hw: Even if the allocated region doesn't change, the requested region - // region has changed and we need to send region events. - // Resetting the allocated region to force update_regions to send events. - changingw->setAllocatedRegion(QRegion()); - update_regions(); - const QRegion newRegion(changingw->allocatedRegion()); - - QWSWindowSurface *surface = changingw->windowSurface(); - QRegion expose; - if (surface) - expose = surface->move(QPoint(dx, dy), changingw->allocatedRegion()); - else - expose = oldRegion + newRegion; - - if (!changingw->d->painted && !expose.isEmpty()) - expose = oldRegion - newRegion; - - int idx = windows.indexOf(changingw); - exposeRegion(expose, idx); - changingw->d->state = oldState; -} - -/*! - Changes the requested region of window \a changingw to \a r - If \a changingw is 0, the server's reserved region is changed. -*/ -void QWSServerPrivate::setWindowRegion(QWSWindow* changingw, const QRegion &r) -{ - if (!changingw) { - qWarning("Not implemented in this release"); - return; - } - - if (changingw->requested_region == r) - return; - - const QRegion oldRegion(changingw->allocatedRegion()); - changingw->requested_region = r; - update_regions(); - const QRegion newRegion(changingw->allocatedRegion()); - - int idx = windows.indexOf(changingw); - exposeRegion(oldRegion - newRegion, idx); -} - - -void QWSServerPrivate::exposeRegion(const QRegion &r, int changing) -{ - if (disablePainting) - return; - - if (r.isEmpty()) - return; - - static bool initial = true; - if (initial) { - changing = 0; - initial = false; - qt_screen->exposeRegion(qt_screen->region(), changing); - } else { - qt_screen->exposeRegion(r, changing); - } -} - -/*! - Closes all pointer devices (specified by the QWS_MOUSE_PROTO - environment variable) by deleting the associated mouse drivers. - - \sa openMouse(), mouseHandler() -*/ -void QWSServer::closeMouse() -{ - Q_D(QWSServer); - qDeleteAll(d->mousehandlers); - d->mousehandlers.clear(); -} - -/*! - Opens the mouse devices specified by the QWS_MOUSE_PROTO - environment variable. Be advised that closeMouse() is called first - to delete all the existing mouse handlers. This behaviour could be - the cause of problems if you were not expecting it. - - \sa closeMouse(), mouseHandler() -*/ -void QWSServer::openMouse() -{ - Q_D(QWSServer); - QString mice = QString::fromLatin1(qgetenv("QWS_MOUSE_PROTO")); -#if defined(QT_QWS_CASSIOPEIA) - if (mice.isEmpty()) - mice = QLatin1String("TPanel:/dev/tpanel"); -#endif - if (mice.isEmpty()) - mice = *defaultMouse(); - closeMouse(); - bool needviscurs = true; - if (mice != QLatin1String("None")) { - const QStringList mouse = mice.split(QLatin1Char(' ')); - for (int i = mouse.size() - 1; i >= 0; --i) { - QWSMouseHandler *handler = d->newMouseHandler(mouse.at(i)); - setMouseHandler(handler); - /* XXX handle mouse cursor visibility sensibly - if (!h->inherits("QCalibratedMouseHandler")) - needviscurs = true; - */ - } - } -#ifndef QT_NO_QWS_CURSOR - setCursorVisible(needviscurs); -#else - Q_UNUSED(needviscurs) -#endif -} - -/*! - Suspends pointer handling by deactivating all the mouse drivers - registered by the QWS_MOUSE_PROTO environment variable. - - - \sa resumeMouse(), QWSMouseHandler::suspend() -*/ -void QWSServer::suspendMouse() -{ - Q_D(QWSServer); - for (int i=0; i < d->mousehandlers.size(); ++i) - d->mousehandlers.at(i)->suspend(); -} - -/*! - Resumes pointer handling by reactivating all the mouse drivers - registered by the QWS_MOUSE_PROTO environment variable. - - \sa suspendMouse(), QWSMouseHandler::resume() -*/ -void QWSServer::resumeMouse() -{ - Q_D(QWSServer); - for (int i=0; i < d->mousehandlers.size(); ++i) - d->mousehandlers.at(i)->resume(); -} - - - -QWSMouseHandler* QWSServerPrivate::newMouseHandler(const QString& spec) -{ - int c = spec.indexOf(QLatin1Char(':')); - QString mouseProto; - QString mouseDev; - if (c >= 0) { - mouseProto = spec.left(c); - mouseDev = spec.mid(c+1); - } else { - mouseProto = spec; - } - - int screen = -1; - const QList<QRegExp> regexps = QList<QRegExp>() - << QRegExp(QLatin1String(":screen=(\\d+)\\b")) - << QRegExp(QLatin1String("\\bscreen=(\\d+):")); - for (int i = 0; i < regexps.size(); ++i) { - QRegExp regexp = regexps.at(i); - if (regexp.indexIn(mouseDev) == -1) - continue; - screen = regexp.cap(1).toInt(); - mouseDev.remove(regexp.pos(0), regexp.matchedLength()); - break; - } - - QWSMouseHandler *handler = 0; - handler = QMouseDriverFactory::create(mouseProto, mouseDev); - if (screen != -1) - handler->setScreen(qt_screen->subScreens().at(screen)); - - return handler; -} - -#ifndef QT_NO_QWS_KEYBOARD - -/*! - Closes all the keyboard devices (specified by the QWS_KEYBOARD - environment variable) by deleting the associated keyboard - drivers. - - \sa openKeyboard(), keyboardHandler() -*/ -void QWSServer::closeKeyboard() -{ - Q_D(QWSServer); - qDeleteAll(d->keyboardhandlers); - d->keyboardhandlers.clear(); -} - -/*! - Returns the primary keyboard driver. - - Note that this function can only be used in the server process. - - \sa setKeyboardHandler(), openKeyboard(), closeKeyboard() -*/ -QWSKeyboardHandler* QWSServer::keyboardHandler() -{ - return qwsServerPrivate->keyboardhandlers.first(); -} - -/*! - \fn void QWSServer::setKeyboardHandler(QWSKeyboardHandler* driver) - - Sets the primary keyboard driver to be the given \a driver. - - \l{Qt for Embedded Linux} provides several ready-made keyboard drivers, and - custom drivers are typically added using Qt's plugin - mechanism. See the \l{Qt for Embedded Linux Character Input} documentation - for details. - - Note that this function can only be used in the server process. - - \sa keyboardHandler(), setDefaultKeyboard() -*/ -void QWSServer::setKeyboardHandler(QWSKeyboardHandler* kh) -{ - if (!kh) - return; - qwsServerPrivate->keyboardhandlers.removeAll(kh); - qwsServerPrivate->keyboardhandlers.prepend(kh); -} - -/*! - Opens the keyboard devices specified by the QWS_KEYBOARD - environment variable. - - \sa closeKeyboard(), keyboardHandler() -*/ -void QWSServer::openKeyboard() -{ - QString keyboards = QString::fromLatin1(qgetenv("QWS_KEYBOARD")); -#if defined(QT_QWS_CASSIOPEIA) - if (keyboards.isEmpty()) - keyboards = QLatin1String("Buttons"); -#endif - if (keyboards.isEmpty()) - keyboards = *defaultKeyboard(); - - closeKeyboard(); - if (keyboards == QLatin1String("None")) - return; - - QString device; - QString type; - QStringList keyboard = keyboards.split(QLatin1Char(' ')); - for (int i = keyboard.size() - 1; i >= 0; --i) { - const QString spec = keyboard.at(i); - int colon=spec.indexOf(QLatin1Char(':')); - if (colon>=0) { - type = spec.left(colon); - device = spec.mid(colon+1); - } else { - type = spec; - device = QString(); - } - QWSKeyboardHandler *handler = QKbdDriverFactory::create(type, device); - setKeyboardHandler(handler); - } -} - -#endif //QT_NO_QWS_KEYBOARD - -QPoint QWSServer::mousePosition; -QBrush *QWSServerPrivate::bgBrush = 0; - -void QWSServerPrivate::move_region(const QWSRegionMoveCommand *cmd) -{ - QWSClient *serverClient = clientMap.value(-1); - invokeRegionMove(cmd, serverClient); -} - -void QWSServerPrivate::set_altitude(const QWSChangeAltitudeCommand *cmd) -{ - QWSClient *serverClient = clientMap.value(-1); - invokeSetAltitude(cmd, serverClient); -} - -void QWSServerPrivate::set_opacity(const QWSSetOpacityCommand *cmd) -{ - QWSClient *serverClient = clientMap.value(-1); - invokeSetOpacity(cmd, serverClient); -} - - -void QWSServerPrivate::request_focus(const QWSRequestFocusCommand *cmd) -{ - invokeSetFocus(cmd, clientMap.value(-1)); -} - -void QWSServerPrivate::set_identity(const QWSIdentifyCommand *cmd) -{ - invokeIdentify(cmd, clientMap.value(-1)); -} - -void QWSServerPrivate::repaint_region(int wid, int windowFlags, bool opaque, - const QRegion ®ion) -{ - QWSWindow* changingw = findWindow(wid, 0); - if (!changingw) { - return; - } - - const bool isOpaque = changingw->opaque; - const bool wasPainted = changingw->d->painted; - changingw->opaque = opaque; - changingw->d->windowFlags = QFlag(windowFlags); - changingw->d->dirtyOnScreen |= region; - changingw->d->painted = true; - if (isOpaque != opaque || !wasPainted) - update_regions(); - - int level = windows.indexOf(changingw); - exposeRegion(region, level); - changingw->d->dirtyOnScreen = QRegion(); -} - -QRegion QWSServerPrivate::reserve_region(QWSWindow *win, const QRegion ®ion) -{ - QRegion r = region; - - int oldPos = windows.indexOf(win); - int newPos = oldPos < nReserved ? nReserved - 1 : nReserved; - for (int i = 0; i < nReserved; ++i) { - if (i != oldPos) { - QWSWindow *w = windows.at(i); - r -= w->requested_region; - } - } - windows.move(oldPos, newPos); - nReserved = newPos + 1; - - return r; -} - -void QWSServerPrivate::request_region(int wid, const QString &surfaceKey, - const QByteArray &surfaceData, - const QRegion ®ion) -{ - QWSWindow *changingw = findWindow(wid, 0); - if (!changingw) - return; - - Q_Q(QWSServer); - QWSWindow::State windowState = QWSWindow::NoState; - - if (region.isEmpty()) { - windowState = QWSWindow::Hiding; - emit q->windowEvent(changingw, QWSServer::Hide); - } - - const bool wasOpaque = changingw->opaque; - - changingw->createSurface(surfaceKey, surfaceData); - QWSWindowSurface *surface = changingw->windowSurface(); - - changingw->opaque = surface->isOpaque(); - - QRegion r; - if (surface->isRegionReserved()) - r = reserve_region(changingw, region); - else - r = region; - - if (!region.isEmpty()) { - if (changingw->isVisible()) - windowState = QWSWindow::ChangingGeometry; - else - windowState = QWSWindow::Showing; - } - changingw->d->state = windowState; - - if (!r.isEmpty() && wasOpaque != changingw->opaque && surface->isBuffered()) - changingw->requested_region = QRegion(); // XXX: force update_regions - - const QRegion oldAllocated = changingw->allocatedRegion(); - setWindowRegion(changingw, r); - if (oldAllocated == changingw->allocatedRegion()) { - // Always send region event to the requesting window even if the - // region didn't change. This is necessary as the client will reset - // the clip region until an event is received. - changingw->client()->sendRegionEvent(wid, changingw->allocatedRegion(), - QWSRegionEvent::Allocation); - } - - surface->QWindowSurface::setGeometry(r.boundingRect()); - - if (windowState == QWSWindow::Showing) - emit q->windowEvent(changingw, QWSServer::Show); - else if (windowState == QWSWindow::ChangingGeometry) - emit q->windowEvent(changingw, QWSServer::Geometry); - if (windowState == QWSWindow::Hiding) { - handleWindowClose(changingw); - changingw->d->state = QWSWindow::Hidden; - changingw->d->painted = false; - } else { - changingw->d->state = QWSWindow::Visible; - } -} - -void QWSServerPrivate::destroy_region(const QWSRegionDestroyCommand *cmd) -{ - invokeRegionDestroy(cmd, clientMap.value(-1)); -} - -void QWSServerPrivate::name_region(const QWSRegionNameCommand *cmd) -{ - invokeRegionName(cmd, clientMap.value(-1)); -} - -#ifndef QT_NO_QWS_INPUTMETHODS -void QWSServerPrivate::im_response(const QWSIMResponseCommand *cmd) - { - invokeIMResponse(cmd, clientMap.value(-1)); -} - -void QWSServerPrivate::im_update(const QWSIMUpdateCommand *cmd) -{ - invokeIMUpdate(cmd, clientMap.value(-1)); -} - -void QWSServerPrivate::send_im_mouse(const QWSIMMouseCommand *cmd) -{ - if (current_IM) - current_IM->mouseHandler(cmd->simpleData.index, cmd->simpleData.state); -} -#endif - -void QWSServerPrivate::openDisplay() -{ - qt_init_display(); - -// rgnMan = qt_fbdpy->regionManager(); - swidth = qt_screen->deviceWidth(); - sheight = qt_screen->deviceHeight(); -} - -void QWSServerPrivate::closeDisplay() -{ - if (qt_screen) - qt_screen->shutdownDevice(); -} - -/*! - Returns the brush used as background in the absence of obscuring - windows. - - \sa setBackground() -*/ -const QBrush &QWSServer::backgroundBrush() const -{ - return *QWSServerPrivate::bgBrush; -} - -/*! - Sets the brush used as background in the absence of obscuring - windows, to be the given \a brush. - - Note that this function can only be used in the server process. - - \sa backgroundBrush() -*/ -void QWSServer::setBackground(const QBrush &brush) -{ - if (!QWSServerPrivate::bgBrush) - QWSServerPrivate::bgBrush = new QBrush(brush); - else - *QWSServerPrivate::bgBrush = brush; - if (!qwsServer) - return; - qt_screen->exposeRegion(QRect(0,0,qt_screen->width(), qt_screen->height()), 0); -} - - -#ifdef QT3_SUPPORT -/*! - \fn void QWSServer::setDesktopBackground(const QImage &image) - - Sets the image used as background in the absence of obscuring - windows, to be the given \a image. - - Use the setBackground() function instead. - - \oldcode - QImage image; - setDesktopBackground(image); - \newcode - QImage image; - setBackground(QBrush(image)); - \endcode -*/ -void QWSServer::setDesktopBackground(const QImage &img) -{ - if (img.isNull()) - setBackground(Qt::NoBrush); - else - setBackground(QBrush(QPixmap::fromImage(img))); -} - -/*! - \fn void QWSServer::setDesktopBackground(const QColor &color) - \overload - - Sets the color used as background in the absence of obscuring - windows, to be the given \a color. - - Use the setBackground() function instead. - - \oldcode - QColor color; - setDesktopBackground(color); - \newcode - QColor color; - setBackground(QBrush(color)); - \endcode -*/ -void QWSServer::setDesktopBackground(const QColor &c) -{ - setBackground(QBrush(c)); -} -#endif //QT3_SUPPORT - -/*! - \internal - */ -void QWSServer::startup(int flags) -{ - if (qwsServer) - return; - unlink(qws_qtePipeFilename().toLatin1().constData()); - (void)new QWSServer(flags); -} - -/*! - \internal -*/ - -void QWSServer::closedown() -{ - QScopedPointer<QWSServer> server(qwsServer); - qwsServer = 0; - QT_TRY { - unlink(qws_qtePipeFilename().toLatin1().constData()); - } QT_CATCH(const std::bad_alloc &) { - // ### TODO - what to do when we run out of memory - // when calling toLatin1? - } -} - -void QWSServerPrivate::emergency_cleanup() -{ -#ifndef QT_NO_QWS_KEYBOARD - if (qwsServer) - qwsServer->closeKeyboard(); -#endif -} - -#ifndef QT_NO_QWS_KEYBOARD -static QList<QWSServer::KeyboardFilter*> *keyFilters = 0; - -/*! - Processes the given key event. The key is identified by its \a - unicode value and the given \a keycode, \a modifiers, \a isPress - and \a autoRepeat parameters. - - The \a keycode parameter is the Qt keycode value as defined by the - Qt::Key enum. The \a modifiers is an OR combination of - Qt::KeyboardModifier values, indicating whether \gui - Shift/Alt/Ctrl keys are pressed. The \a isPress parameter is true - if the event is a key press event and \a autoRepeat is true if the - event is caused by an auto-repeat mechanism and not an actual key - press. - - This function is typically called internally by keyboard drivers. - Note that this function can only be used in the server process. - - \sa sendKeyEvent(), {Qt for Embedded Linux Character Input} -*/ -void QWSServer::processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat) -{ - bool block; - // Don't block the POWER or LIGHT keys - if ( keycode == Qt::Key_F34 || keycode == Qt::Key_F35 ) - block = false; - else - block = qwsServerPrivate->screensaverblockevent(KEY, qwsServerPrivate->screensaverinterval, isPress); - -#ifdef EVENT_BLOCK_DEBUG - qDebug() << "processKeyEvent" << unicode << keycode << modifiers << isPress << autoRepeat << (block ? "block" : "pass"); -#endif - - // If we press a key and it's going to be blocked, wake up the screen - if ( block && isPress ) - qwsServerPrivate->_q_screenSaverWake(); - - if ( block ) - return; - - if (keyFilters) { - for (int i = 0; i < keyFilters->size(); ++i) { - QWSServer::KeyboardFilter *keyFilter = keyFilters->at(i); - if (keyFilter->filter(unicode, keycode, modifiers, isPress, autoRepeat)) - return; - } - } - sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); -} - -/*! - \fn void QWSServer::addKeyboardFilter(KeyboardFilter *filter) - - Activates the given keyboard \a filter all key events generated by - physical keyboard drivers (i.e., events sent using the - processKeyEvent() function). - - Note that the filter is not invoked for keys generated by \e - virtual keyboard drivers (i.e., events sent using the - sendKeyEvent() function). - - Note that this function can only be used in the server process. - - \sa removeKeyboardFilter() -*/ -void QWSServer::addKeyboardFilter(KeyboardFilter *f) -{ - if (!keyFilters) - keyFilters = new QList<QWSServer::KeyboardFilter*>; - if (f) { - keyFilters->prepend(f); - } -} - -/* -//####### - We should probably obsolete the whole keyboard filter thing since - it's not useful for input methods anyway - - We could do removeKeyboardFilter(KeyboardFilter *f), but - the "remove and delete the filter" concept does not match "user - remembers the pointer". -*/ - -/*! - Removes and deletes the most recently added filter. - - Note that the programmer is responsible for removing each added - keyboard filter. - - Note that this function can only be used in the server process. - - \sa addKeyboardFilter() -*/ -void QWSServer::removeKeyboardFilter() -{ - if (!keyFilters || keyFilters->isEmpty()) - return; - delete keyFilters->takeAt(0); -} -#endif // QT_NO_QWS_KEYBOARD - -/*! - \fn void QWSServer::setScreenSaverIntervals(int* intervals) - - Specifies the time \a intervals (in milliseconds) between the - different levels of screen responsiveness. - - \l{Qt for Embedded Linux} supports multilevel screen saving, i.e., it is - possible to specify several different levels of screen - responsiveness by implementing the QWSScreenSaver::save() - function. For example, you can choose to first turn off the light - before you fully activate the screensaver. See the QWSScreenSaver - documentation for details. - - Note that an interval of 0 milliseconds will turn off the - screensaver, and that the \a intervals array must be 0-terminated. - This function can only be used in the server process. - - \sa setScreenSaverInterval(), setScreenSaverBlockLevel() -*/ -void QWSServer::setScreenSaverIntervals(int* ms) -{ - if (!qwsServerPrivate) - return; - - delete [] qwsServerPrivate->screensaverintervals; - if (ms) { - int* t=ms; - int n=0; - while (*t++) n++; - if (n) { - n++; // the 0 - qwsServerPrivate->screensaverintervals = new int[n]; - memcpy(qwsServerPrivate->screensaverintervals, ms, n*sizeof(int)); - } else { - qwsServerPrivate->screensaverintervals = 0; - } - } else { - qwsServerPrivate->screensaverintervals = 0; - } - qwsServerPrivate->screensaverinterval = 0; - - qwsServerPrivate->screensavertimer->stop(); - qt_screen->blank(false); - qwsServerPrivate->_q_screenSaverWake(); -} - -/*! - \fn void QWSServer::setScreenSaverInterval(int milliseconds) - - Sets the timeout interval for the screensaver to the specified \a - milliseconds. To turn off the screensaver, set the timout interval - to 0. - - Note that this function can only be used in the server process. - - \sa setScreenSaverIntervals(), setScreenSaverBlockLevel() -*/ -void QWSServer::setScreenSaverInterval(int ms) -{ - int v[2]; - v[0] = ms; - v[1] = 0; - setScreenSaverIntervals(v); -} - -/*! - Block the key or mouse event that wakes the system from level \a eventBlockLevel or higher. - To completely disable event blocking (the default behavior), set \a eventBlockLevel to -1. - - The algorithm blocks the "down", "up" as well as any "repeat" events for the same key - but will not block other key events after the initial "down" event. For mouse events, the - algorithm blocks all mouse events until an event with no buttons pressed is received. - - There are 2 keys that are never blocked, Qt::Key_F34 (POWER) and Qt::Key_F35 (LIGHT). - - Example usage: - - \snippet doc/src/snippets/code/src_gui_embedded_qwindowsystem_qws.cpp 0 - - Note that this function can only be used in the server process. - - \sa setScreenSaverIntervals(), setScreenSaverInterval() -*/ -void QWSServer::setScreenSaverBlockLevel(int eventBlockLevel) -{ - if (!qwsServerPrivate) - return; - qwsServerPrivate->screensavereventblocklevel = eventBlockLevel; -#ifdef EVENT_BLOCK_DEBUG - qDebug() << "QWSServer::setScreenSaverBlockLevel() " << eventBlockLevel; -#endif -} - -extern bool qt_disable_lowpriority_timers; //in qeventloop_unix.cpp - -void QWSServerPrivate::_q_screenSaverWake() -{ - if (screensaverintervals) { - if (screensaverinterval != screensaverintervals) { - if (saver) saver->restore(); - screensaverinterval = screensaverintervals; - screensaverblockevents = false; - } else { - if (!screensavertimer->isActive()) { - qt_screen->blank(false); - if (saver) saver->restore(); - } - } - screensavertimer->start(*screensaverinterval); - screensavertime.start(); - } - qt_disable_lowpriority_timers=false; -} - -void QWSServerPrivate::_q_screenSaverSleep() -{ - qt_screen->blank(true); -#if !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX) - screensavertimer->stop(); -#else - if (screensaverinterval) { - screensavertimer->start(*screensaverinterval); - screensavertime.start(); - } else { - screensavertimer->stop(); - } -#endif - qt_disable_lowpriority_timers=true; -} - -/*! - \fn void QWSServer::setScreenSaver(QWSScreenSaver* screenSaver) - - Installs the given \a screenSaver, deleting the current screen - saver. - - Note that this function can only be used in the server process. - - \sa screenSaverActivate(), setScreenSaverInterval(), setScreenSaverIntervals(), setScreenSaverBlockLevel() -*/ -void QWSServer::setScreenSaver(QWSScreenSaver* ss) -{ - QWSServerPrivate *qd = qwsServer->d_func(); - delete qd->saver; - qd->saver = ss; -} - -void QWSServerPrivate::screenSave(int level) -{ - if (saver) { - // saver->save() may call QCoreApplication::processEvents, - // block event before calling saver->save(). - bool oldScreensaverblockevents = screensaverblockevents; - if (*screensaverinterval >= 1000) { - screensaverblockevents = (screensavereventblocklevel >= 0 && screensavereventblocklevel <= level); -#ifdef EVENT_BLOCK_DEBUG - if (screensaverblockevents) - qDebug("ready to block events"); -#endif - } - int *oldScreensaverinterval = screensaverinterval; - if (saver->save(level)) { - // only update screensaverinterval if it hasn't already changed - if (oldScreensaverinterval == screensaverinterval) { - if (screensaverinterval && screensaverinterval[1]) { - screensavertimer->start(*++screensaverinterval); - screensavertime.start(); - } else { - screensaverinterval = 0; - } - } - } else { - // restore previous state - screensaverblockevents = oldScreensaverblockevents; - - // for some reason, the saver don't want us to change to the - // next level, so we'll stay at this level for another interval - if (screensaverinterval && *screensaverinterval) { - screensavertimer->start(*screensaverinterval); - screensavertime.start(); - } - } - } else { - screensaverinterval = 0;//screensaverintervals; - screensaverblockevents = false; - _q_screenSaverSleep(); - } -} - -void QWSServerPrivate::_q_screenSaverTimeout() -{ - if (screensaverinterval) { - if (screensavertime.elapsed() > *screensaverinterval*2) { - // bogus (eg. unsuspend, system time changed) - _q_screenSaverWake(); // try again - return; - } - screenSave(screensaverinterval - screensaverintervals); - } -} - -/*! - Returns true if the screen saver is active; otherwise returns - false. - - Note that this function can only be used in the server process. - - \sa screenSaverActivate() -*/ -bool QWSServer::screenSaverActive() -{ - return qwsServerPrivate->screensaverinterval - && !qwsServerPrivate->screensavertimer->isActive(); -} - -/*! - \internal -*/ -void QWSServer::updateWindowRegions() const -{ - qwsServerPrivate->update_regions(); -} - -/*! - Activates the screen saver if \a activate is true; otherwise it is - deactivated. - - Note that this function can only be used in the server process. - - \sa screenSaverActive(), setScreenSaver() -*/ -void QWSServer::screenSaverActivate(bool activate) -{ - if (activate) - qwsServerPrivate->_q_screenSaverSleep(); - else - qwsServerPrivate->_q_screenSaverWake(); -} - -void QWSServerPrivate::disconnectClient(QWSClient *c) -{ - QTimer::singleShot(0, c, SLOT(closeHandler())); -} - -void QWSServerPrivate::updateClientCursorPos() -{ - Q_Q(QWSServer); - QWSWindow *win = qwsServerPrivate->mouseGrabber ? qwsServerPrivate->mouseGrabber : qwsServer->windowAt(QWSServer::mousePosition); - QWSClient *winClient = win ? win->client() : 0; - if (winClient && winClient != cursorClient) - q->sendMouseEvent(QWSServer::mousePosition, mouseState); -} - -#ifndef QT_NO_QWS_INPUTMETHODS - -/*! - \class QWSInputMethod - \preliminary - \ingroup qws - - \brief The QWSInputMethod class provides international input methods - in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - A \l{Qt for Embedded Linux} application requires a server application to be - running, or to be the server application itself. All system - generated events, including keyboard and mouse events, are passed - to the server application which then propagates the event to the - appropriate client. - - An input method consists of a filter and optionally a graphical - interface, and is used to filter input events between the server - and the client application. - - \tableofcontents - - \section1 Creating Custom Input Methods - - To implement a custom input method, derive from the QWSInputMethod - class, and use the server's \l - {QWSServer::}{setCurrentInputMethod()} function to install it. - - When subclassing QWSInputMethod, you can reimplement the filter() - functions to handle input from both physical and virtual keyboards - as well as mouse devices. Note that the default implementations do - nothing. Use the setInputResolution() function to control the - number of bits shifted when filtering mouse input, i.e., when - going from pointer resolution to screen resolution (the current - resolution can be retrieved using the inputResolutionShift() - function). - - Reimplement the reset() function to restore the state of the input - method. Note that the default implementation calls the sendEvent() - function with empty preedit and commit strings if the input method - is in compose mode (i.e., if the input method is actively - composing a preedit string). - - To receive replies to an input method query (sent using the - sendQuery() function), you must reimplement the queryResponse() - function, while the mouseHandler() function must be reimplemented - if you want to handle mouse events within the preedit - text. Reimplement the updateHandler() function to handle update - events including resets and focus changes. The UpdateType enum - describes the various types of update events recognized by the - input method. - - \section1 Using Input Methods - - In addition to the filter(), reset(), queryResponse(), - mouseHandler() and updateHandler() function mentioned in the - previous section, the QWSInputMethod provides several other - functions helping the window system to manage the installed input - methods. - - The sendEvent() function sends the given event to the focus - widget, while the sendPreeditString() function sends the given - preedit text (encapsulated by an event). QWSInputMethod also - provides the sendCommitString() convenience function which sends - an event encapsulating the given commit string to the current - focus widget, and the sendMouseEvent() function which sends the - given mouse event. - - Finally, the QWSInputMethod class provides the sendQuery() - function for sending input method queries. This function - encapsulates the event with a QWSEvent instance of the \l - {QWSEvent::}{IMQuery} type. - - \sa QWSServer, {Qt for Embedded Linux Architecture} -*/ - -/*! - Constructs a new input method. - - Use the QWSServer::setCurrentInputMethod() function to install it. -*/ - -QWSInputMethod::QWSInputMethod() -{ - -} - -/*! - Destroys this input method, uninstalling it if it is installed. -*/ -QWSInputMethod::~QWSInputMethod() -{ - if (current_IM == this) - current_IM = 0; -} - -/*! - Filters the key input identified by the given \a unicode, \a - keycode, \a modifiers, \a isPress and \a autoRepeat parameters. - - Note that the default implementation does nothing; reimplement - this function to handle input from both physical and virtual - devices. - - The \a keycode is a Qt::Key value, and the \a modifiers is an OR - combination of Qt::KeyboardModifiers. The \a isPress parameter is - telling whether the input is a key press or key release, and the - \a autoRepeat parameter determines whether the input is - autorepeated ( i.e., in which case the - QWSKeyboardHandler::beginAutoRepeat() function has been called). - - To block the event from further processing, return true when - reimplementing this function; the default implementation returns - false. - - \sa setInputResolution(), inputResolutionShift() -*/ -bool QWSInputMethod::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) -{ - Q_UNUSED(unicode); - Q_UNUSED(keycode); - Q_UNUSED(modifiers); - Q_UNUSED(isPress); - Q_UNUSED(autoRepeat); - return false; -} - -/*! - \overload - - Filters the mouse input identified by the given \a position, \a - state, and \a wheel parameters. -*/ -bool QWSInputMethod::filter(const QPoint &position, int state, int wheel) -{ - Q_UNUSED(position); - Q_UNUSED(state); - Q_UNUSED(wheel); - return false; -} - -/*! - Resets the state of the input method. - - If the input method is in compose mode, i.e., the input method is - actively composing a preedit string, the default implementation - calls sendEvent() with empty preedit and commit strings; otherwise - it does nothing. Reimplement this function to alter this behavior. - - \sa sendEvent() -*/ -void QWSInputMethod::reset() -{ - if (current_IM_composing_win) { - QInputMethodEvent ime; - sendEvent(&ime); - } -} - -/*! - \enum QWSInputMethod::UpdateType - - This enum describes the various types of update events recognized - by the input method. - - \value Update The input widget is updated in some way; use sendQuery() with - Qt::ImMicroFocus as an argument for more information. - \value FocusIn A new input widget receives focus. - \value FocusOut The input widget loses focus. - \value Reset The input method should be reset. - \value Destroyed The input widget is destroyed. - - \sa updateHandler() -*/ - -/*! - Handles update events including resets and focus changes. The - update events are specified by the given \a type which is one of - the UpdateType enum values. - - Note that reimplementations of this function must call the base - implementation for all cases that it does not handle itself. - - \sa UpdateType -*/ -void QWSInputMethod::updateHandler(int type) -{ - switch (type) { - case FocusOut: - case Reset: - reset(); - break; - - default: - break; - } -} - - -/*! - Receive replies to an input method query. - - Note that the default implementation does nothing; reimplement - this function to receive such replies. - - Internally, an input method query is passed encapsulated by an \l - {QWSEvent::IMQuery}{IMQuery} event generated by the sendQuery() - function. The queried property and the result is passed in the \a - property and \a result parameters. - - \sa sendQuery(), QWSServer::sendIMQuery() -*/ -void QWSInputMethod::queryResponse(int property, const QVariant &result) -{ - Q_UNUSED(property); - Q_UNUSED(result); -} - - - -/*! - \fn void QWSInputMethod::mouseHandler(int offset, int state) - - Handles mouse events within the preedit text. - - Note that the default implementation resets the input method on - all mouse presses; reimplement this function to alter this - behavior. - - The \a offset parameter specifies the position of the mouse event - within the string, and \a state specifies the type of the mouse - event as described by the QWSServer::IMMouse enum. If \a state is - less than 0, the mouse event is inside the associated widget, but - outside the preedit text. When clicking in a different widget, the - \a state is QWSServer::MouseOutside. - - \sa sendPreeditString(), reset() -*/ -void QWSInputMethod::mouseHandler(int, int state) -{ - if (state == QWSServer::MousePress || state == QWSServer::MouseOutside) - reset(); -} - - -/*! - Sends an event encapsulating the given \a preeditString, to the - focus widget. - - The specified \a selectionLength is the number of characters to be - marked as selected (starting at the given \a cursorPosition). If - \a selectionLength is negative, the text \e before \a - cursorPosition is marked. - - The preedit string is marked with QInputContext::PreeditFormat, - and the selected part is marked with - QInputContext::SelectionFormat. - - Sending an input method event with a non-empty preedit string will - cause the input method to enter compose mode. Sending an input - method event with an empty preedit string will cause the input - method to leave compose mode, i.e., the input method will no longer - be actively composing the preedit string. - - Internally, the event is represented by a QWSEvent object of the - \l {QWSEvent::IMEvent}{IMEvent} type. - - \sa sendEvent(), sendCommitString() -*/ - -void QWSInputMethod::sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength) -{ - QList<QInputMethodEvent::Attribute> attributes; - - int selPos = cursorPosition; - if (selectionLength == 0) { - selPos = 0; - } else if (selectionLength < 0) { - selPos += selectionLength; - selectionLength = -selectionLength; - } - if (selPos > 0) - attributes += QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, selPos, - QVariant(int(QInputContext::PreeditFormat))); - - if (selectionLength) - attributes += QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, selPos, selectionLength, - QVariant(int(QInputContext::SelectionFormat))); - - if (selPos + selectionLength < preeditString.length()) - attributes += QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, - selPos + selectionLength, - preeditString.length() - selPos - selectionLength, - QVariant(int(QInputContext::PreeditFormat))); - - attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPosition, 0, QVariant()); - - QInputMethodEvent ime(preeditString, attributes); - qwsServer->sendIMEvent(&ime); -} - -/*! - \fn void QWSInputMethod::sendCommitString(const QString &commitString, int replaceFromPosition, int replaceLength) - - Sends an event encapsulating the given \a commitString, to the - focus widget. - - Note that this will cause the input method to leave compose mode, - i.e., the input method will no longer be actively composing the - preedit string. - - If the specified \a replaceLength is greater than 0, the commit - string will replace the given number of characters of the - receiving widget's previous text, starting at the given \a - replaceFromPosition relative to the start of the current preedit - string. - - Internally, the event is represented by a QWSEvent object of the - \l {QWSEvent::IMEvent}{IMEvent} type. - - \sa sendEvent(), sendPreeditString() -*/ -void QWSInputMethod::sendCommitString(const QString &commitString, int replaceFrom, int replaceLength) -{ - QInputMethodEvent ime; - ime.setCommitString(commitString, replaceFrom, replaceLength); - qwsServer->sendIMEvent(&ime); -} - -/*! - \fn QWSInputMethod::sendIMEvent(QWSServer::IMState state, const QString &text, int cursorPosition, int selectionLength) - \obsolete - - Sends a QInputMethodEvent object to the focus widget. - - If the specified \a state is QWSServer::IMCompose, \a text is a - preedit string, \a cursorPosition is the cursor's position within - the preedit string, and \a selectionLength is the number of - characters (starting at \a cursorPosition) that should be marked - as selected by the input widget receiving the event. If the - specified \a state is QWSServer::IMEnd, \a text is a commit - string. - - Use sendEvent(), sendPreeditString() or sendCommitString() instead. -*/ - -/*! - \fn QWSInputMethod::sendEvent(const QInputMethodEvent *event) - - Sends the given \a event to the focus widget. - - The \c QInputMethodEvent class is derived from QWSEvent, i.e., the - given \a event is a QWSEvent object of the \l - {QWSEvent::IMEvent}{IMEvent} type. - - \sa sendPreeditString(), sendCommitString(), reset() -*/ - - -/*! - \fn void QWSInputMethod::sendQuery(int property) - - Sends an input method query (internally encapsulated by a QWSEvent - of the \l {QWSEvent::IMQuery}{IMQuery} type) for the specified \a - property. - - To receive responses to input method queries, the virtual - queryResponse() function must be reimplemented. - - \sa queryResponse(), QWSServer::sendIMQuery() -*/ - -/*! - Sets and returns the number of bits shifted to go from pointer - resolution to screen resolution when filtering mouse input. - - If \a isHigh is true and the device has a pointer device - resolution twice or more of the screen resolution, the positions - passed to the filter() function will be presented at the higher - resolution; otherwise the resolution will be equal to that of the - screen resolution. - - \sa inputResolutionShift(), filter() -*/ -uint QWSInputMethod::setInputResolution(bool isHigh) -{ - mIResolution = isHigh; - return inputResolutionShift(); -} - -/*! - Returns the number of bits shifted to go from pointer resolution - to screen resolution when filtering mouse input. - - \sa setInputResolution(), filter() -*/ -uint QWSInputMethod::inputResolutionShift() const -{ - return 0; // default for devices with single resolution. -} - -/*! - \fn void QWSInputMethod::sendMouseEvent( const QPoint &position, int state, int wheel ) - - Sends a mouse event specified by the given \a position, \a state - and \a wheel parameters. - - The given \a position will be transformed if the screen - coordinates do not match the pointer device coordinates. - - Note that the event will be not be tested by the active input - method, but calling the QWSServer::sendMouseEvent() function will - make the current input method filter the event. - - \sa mouseHandler(), sendEvent() -*/ -void QWSInputMethod::sendMouseEvent( const QPoint &pos, int state, int wheel ) -{ - if (qt_last_x) { - *qt_last_x = pos.x(); - *qt_last_y = pos.y(); - } - QWSServer::mousePosition = pos; - qwsServerPrivate->mouseState = state; - QWSServerPrivate::sendMouseEventUnfiltered(pos, state, wheel); -} -#endif // QT_NO_QWS_INPUTMETHODS - -/*! - \fn QWSWindow::QWSWindow(int i, QWSClient * client) - \internal - - Constructs a new top-level window, associated with the client \a - client and giving it the id \a i. -*/ - -/*! - \fn QWSServer::windowEvent(QWSWindow * window, QWSServer::WindowEvent eventType) - - This signal is emitted whenever something happens to a top-level - window (e.g., it's created or destroyed), passing a pointer to the - window and the event's type in the \a window and \a eventType - parameters, respectively. - - \sa markedText() -*/ - -/*! - \class QWSServer::KeyboardFilter - \ingroup qws - - \brief The KeyboardFilter class is a base class for global - keyboard event filters in Qt for Embedded Linux. - - Note that this class is only available in \l{Qt for Embedded Linux}. - - In \l{Qt for Embedded Linux}, all system generated events, including - keyboard events, are passed to the server application which then - propagates the event to the appropriate client. The KeyboardFilter - class is used to implement a global, low-level filter on the - server side. The server applies the filter to all keyboard events - before passing them on to the clients: - - \image qwsserver_keyboardfilter.png - - This feature can, for example, be used to filter things like APM - (advanced power management) suspended from a button without having - to filter for it in all applications. - - To add a new keyboard filter you must first create the filter by - deriving from this class, reimplementing the pure virtual filter() - function. Then you can install the filter on the server using - QWSServer's \l {QWSServer::}{addKeyboardFilter()} - function. QWSServer also provides a \l - {QWSServer::}{removeKeyboardFilter()} function. - - \sa {Qt for Embedded Linux Architecture}, QWSServer, QWSInputMethod -*/ - -/*! - \fn QWSServer::KeyboardFilter::~KeyboardFilter() - - Destroys the keyboard filter. -*/ - -/*! - \fn bool QWSServer::KeyboardFilter::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) - - Implement this function to return true if a given key event should - be stopped from being processed any further; otherwise it should - return false. - - A key event can be identified by the given \a unicode value and - the \a keycode, \a modifiers, \a isPress and \a autoRepeat - parameters. - - The \a keycode parameter is the Qt keycode value as defined by the - Qt::Key enum. The \a modifiers is an OR combination of - Qt::KeyboardModifier values, indicating whether \gui - Shift/Alt/Ctrl keys are pressed. The \a isPress parameter is true - if the event is a key press event and \a autoRepeat is true if the - event is caused by an auto-repeat mechanism and not an actual key - press. -*/ - -QT_END_NAMESPACE - -#include "moc_qwindowsystem_qws.cpp" diff --git a/src/gui/embedded/qwindowsystem_qws.h b/src/gui/embedded/qwindowsystem_qws.h deleted file mode 100644 index 65e1683d38..0000000000 --- a/src/gui/embedded/qwindowsystem_qws.h +++ /dev/null @@ -1,508 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSYSTEM_QWS_H -#define QWINDOWSYSTEM_QWS_H - -#include <QtCore/qbytearray.h> -#include <QtCore/qmap.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qlist.h> - -#include <QtGui/qwsevent_qws.h> -#include <QtGui/qkbd_qws.h> -#include <QtGui/qregion.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -struct QWSWindowPrivate; -class QWSCursor; -class QWSClient; -class QWSRegionManager; -class QBrush; -class QVariant; -class QInputMethodEvent; -class QWSInputMethod; -class QWSBackingStore; -class QWSWindowSurface; - -#ifdef QT3_SUPPORT -class QImage; -class QColor; -#endif - -class QWSInternalWindowInfo -{ -public: - int winid; - unsigned int clientid; - QString name; // Corresponds to QObject name of top-level widget -}; - - -class Q_GUI_EXPORT QWSScreenSaver -{ -public: - virtual ~QWSScreenSaver(); - virtual void restore()=0; - virtual bool save(int level)=0; -}; - - -class Q_GUI_EXPORT QWSWindow -{ - friend class QWSServer; - friend class QWSServerPrivate; - -public: - QWSWindow(int i, QWSClient* client); - ~QWSWindow(); - - int winId() const { return id; } - const QString &name() const { return rgnName; } - const QString &caption() const { return rgnCaption; } - QWSClient* client() const { return c; } - const QRegion &requestedRegion() const { return requested_region; } - QRegion allocatedRegion() const; - QRegion paintedRegion() const; - bool isVisible() const { return !requested_region.isEmpty(); } - bool isPartiallyObscured() const { return requested_region != allocatedRegion(); } - bool isFullyObscured() const { return allocatedRegion().isEmpty(); } - - enum State { NoState, Hidden, Showing, Visible, Hiding, Raising, Lowering, Moving, ChangingGeometry, Destroyed }; - State state() const; - Qt::WindowFlags windowFlags() const; - QRegion dirtyOnScreen() const; - - void raise(); - void lower(); - void show(); - void hide(); - void setActiveWindow(); - - bool isOpaque() const {return opaque && _opacity == 255;} - uint opacity() const { return _opacity; } - - QWSWindowSurface* windowSurface() const { return surface; } - -private: - bool hidden() const { return requested_region.isEmpty(); } - bool forClient(const QWSClient* cl) const { return cl==c; } - - void setName(const QString &n); - void setCaption(const QString &c); - - void focus(bool get); - int focusPriority() const { return last_focus_time; } - void operation(QWSWindowOperationEvent::Operation o); - void shuttingDown() { last_focus_time=0; } - -#ifdef QT_QWS_CLIENTBLIT - QRegion directPaintRegion() const; - inline void setDirectPaintRegion(const QRegion &topmost); -#endif - inline void setAllocatedRegion(const QRegion ®ion); - - void createSurface(const QString &key, const QByteArray &data); - -#ifndef QT_NO_QWSEMBEDWIDGET - void startEmbed(QWSWindow *window); - void stopEmbed(QWSWindow *window); -#endif - -private: - int id; - QString rgnName; - QString rgnCaption; - bool modified; - bool onTop; - QWSClient* c; - QRegion requested_region; - QRegion exposed; - int last_focus_time; - QWSWindowSurface *surface; - uint _opacity; - bool opaque; - QWSWindowPrivate *d; -#ifdef QT3_SUPPORT - inline QT3_SUPPORT QRegion requested() const { return requested_region; } -// inline QT3_SUPPORT QRegion allocation() const { return allocated_region; } -#endif -}; - - -#ifndef QT_NO_SOUND -class QWSSoundServer; -#ifdef QT_USE_OLD_QWS_SOUND -class QWSSoundServerData; - -class Q_GUI_EXPORT QWSSoundServer : public QObject { - Q_OBJECT -public: - QWSSoundServer(QObject* parent); - ~QWSSoundServer(); - void playFile(const QString& filename); -private Q_SLOTS: - void feedDevice(int fd); -private: - QWSSoundServerData* d; -}; -#endif -#endif - - -/********************************************************************* - * - * Class: QWSServer - * - *********************************************************************/ - -class QWSMouseHandler; -struct QWSCommandStruct; -class QWSServerPrivate; -class QWSServer; - -extern Q_GUI_EXPORT QWSServer *qwsServer; - -class Q_GUI_EXPORT QWSServer : public QObject -{ - friend class QCopChannel; - friend class QWSMouseHandler; - friend class QWSWindow; - friend class QWSDisplay; - friend class QWSInputMethod; - Q_OBJECT - Q_DECLARE_PRIVATE(QWSServer) -public: - explicit QWSServer(int flags = 0, QObject *parent=0); -#ifdef QT3_SUPPORT - QT3_SUPPORT_CONSTRUCTOR QWSServer(int flags, QObject *parent, const char *name); -#endif - ~QWSServer(); - enum ServerFlags { DisableKeyboard = 0x01, - DisableMouse = 0x02 }; - - static void sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat); -#ifndef QT_NO_QWS_KEYBOARD - static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, - bool isPress, bool autoRepeat); -#endif - - static QWSServer* instance() { return qwsServer; } - -#ifndef QT_NO_QWS_INPUTMETHODS -#ifdef QT3_SUPPORT - enum IMState { IMCompose, IMEnd, IMStart = IMCompose }; -#endif - enum IMMouse { MousePress, MouseRelease, MouseMove, MouseOutside }; //MouseMove reserved but not used - void sendIMEvent(const QInputMethodEvent*); - void sendIMQuery(int property); -#endif - -#ifndef QT_NO_QWS_KEYBOARD - class KeyboardFilter - { - public: - virtual ~KeyboardFilter() {} - virtual bool filter(int unicode, int keycode, int modifiers, - bool isPress, bool autoRepeat)=0; - }; - static void addKeyboardFilter(KeyboardFilter *f); - static void removeKeyboardFilter(); -#endif - -#ifndef QT_NO_QWS_INPUTMETHODS - static void setCurrentInputMethod(QWSInputMethod *im); - static void resetInputMethod(); -#endif - - static void setDefaultMouse(const char *); - static void setDefaultKeyboard(const char *); - static void setMaxWindowRect(const QRect&); - static void sendMouseEvent(const QPoint& pos, int state, int wheel = 0); - - static void setBackground(const QBrush &); -#ifdef QT3_SUPPORT - static QT3_SUPPORT void setDesktopBackground(const QImage &img); - static QT3_SUPPORT void setDesktopBackground(const QColor &); -#endif - static QWSMouseHandler *mouseHandler(); - static const QList<QWSMouseHandler*>& mouseHandlers(); - static void setMouseHandler(QWSMouseHandler*); -#ifndef QT_NO_QWS_KEYBOARD - static QWSKeyboardHandler* keyboardHandler(); - static void setKeyboardHandler(QWSKeyboardHandler* kh); -#endif - QWSWindow *windowAt(const QPoint& pos); - - const QList<QWSWindow*> &clientWindows(); - - void openMouse(); - void closeMouse(); - void suspendMouse(); - void resumeMouse(); -#ifndef QT_NO_QWS_KEYBOARD - void openKeyboard(); - void closeKeyboard(); -#endif - - static void setScreenSaver(QWSScreenSaver*); - static void setScreenSaverIntervals(int* ms); - static void setScreenSaverInterval(int); - static void setScreenSaverBlockLevel(int); - static bool screenSaverActive(); - static void screenSaverActivate(bool); - - // the following are internal. - void refresh(); - void refresh(QRegion &); - - void enablePainting(bool); - static void processEventQueue(); - static QList<QWSInternalWindowInfo*> * windowList(); - - void sendPropertyNotifyEvent(int property, int state); - - static QPoint mousePosition; - - static void startup(int flags); - static void closedown(); - - static void beginDisplayReconfigure(); - static void endDisplayReconfigure(); - -#ifndef QT_NO_QWS_CURSOR - static void setCursorVisible(bool); - static bool isCursorVisible(); -#endif - - const QBrush &backgroundBrush() const; - - enum WindowEvent { Create=0x0001, Destroy=0x0002, Hide=0x0004, Show=0x0008, - Raise=0x0010, Lower=0x0020, Geometry=0x0040, Active = 0x0080, - Name=0x0100 }; - -Q_SIGNALS: - void windowEvent(QWSWindow *w, QWSServer::WindowEvent e); - -#ifndef QT_NO_COP - void newChannel(const QString& channel); - void removedChannel(const QString& channel); - -#endif -#ifndef QT_NO_QWS_INPUTMETHODS - void markedText(const QString &); -#endif - -protected: - void timerEvent(QTimerEvent *e); - -private: - friend class QApplicationPrivate; - void updateWindowRegions() const; - -#ifdef QT3_SUPPORT -#ifndef QT_NO_QWS_KEYBOARD - static inline QT3_SUPPORT void setKeyboardFilter(QWSServer::KeyboardFilter *f) - { if (f) addKeyboardFilter(f); else removeKeyboardFilter(); } -#endif -#endif - -private: -#ifndef QT_NO_QWS_MULTIPROCESS - Q_PRIVATE_SLOT(d_func(), void _q_clientClosed()) - Q_PRIVATE_SLOT(d_func(), void _q_doClient()) - Q_PRIVATE_SLOT(d_func(), void _q_deleteWindowsLater()) -#endif - - Q_PRIVATE_SLOT(d_func(), void _q_screenSaverWake()) - Q_PRIVATE_SLOT(d_func(), void _q_screenSaverSleep()) - Q_PRIVATE_SLOT(d_func(), void _q_screenSaverTimeout()) - -#ifndef QT_NO_QWS_MULTIPROCESS - Q_PRIVATE_SLOT(d_func(), void _q_newConnection()) -#endif -}; - -#ifndef QT_NO_QWS_INPUTMETHODS -class Q_GUI_EXPORT QWSInputMethod : public QObject -{ - Q_OBJECT -public: - QWSInputMethod(); - virtual ~QWSInputMethod(); - - enum UpdateType {Update, FocusIn, FocusOut, Reset, Destroyed}; - - virtual bool filter(int unicode, int keycode, int modifiers, - bool isPress, bool autoRepeat); - - virtual bool filter(const QPoint &, int state, int wheel); - - virtual void reset(); - virtual void updateHandler(int type); - virtual void mouseHandler(int pos, int state); - virtual void queryResponse(int property, const QVariant&); - -protected: - uint setInputResolution(bool isHigh); - uint inputResolutionShift() const; - // needed for required transform - void sendMouseEvent(const QPoint &pos, int state, int wheel); - - void sendEvent(const QInputMethodEvent*); - void sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength = 0); - void sendCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0); - void sendQuery(int property); - -#ifdef QT3_SUPPORT - inline void sendIMEvent(QWSServer::IMState, const QString& txt, int cpos, int selLen = 0); -#endif -private: - bool mIResolution; -}; - -inline void QWSInputMethod::sendEvent(const QInputMethodEvent *ime) -{ - qwsServer->sendIMEvent(ime); -} -#ifdef QT3_SUPPORT -inline void QWSInputMethod::sendIMEvent(QWSServer::IMState state, const QString& txt, int cpos, int selLen) -{ - if (state == QWSServer::IMCompose) sendPreeditString(txt, cpos, selLen); else sendCommitString(txt); -} -#endif - -inline void QWSInputMethod::sendQuery(int property) -{ - qwsServer->sendIMQuery(property); -} - -// mouse events not inline as involve transformations. -#endif // QT_NO_QWS_INPUTMETHODS - - - -/********************************************************************* - * - * Class: QWSClient - * - *********************************************************************/ - -struct QWSMouseEvent; - -typedef QMap<int, QWSCursor*> QWSCursorMap; - -class QWSClientPrivate; -class QWSCommand; -class QWSConvertSelectionCommand; - -class Q_GUI_EXPORT QWSClient : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QWSClient) -public: - QWSClient(QObject* parent, QWS_SOCK_BASE *, int id); - ~QWSClient(); - - int socket() const; - - void setIdentity(const QString&); - QString identity() const { return id; } - - void sendEvent(QWSEvent* event); - void sendConnectedEvent(const char *display_spec); - void sendMaxWindowRectEvent(const QRect &rect); - void sendPropertyNotifyEvent(int property, int state); - void sendPropertyReplyEvent(int property, int len, const char *data); - void sendSelectionClearEvent(int windowid); - void sendSelectionRequestEvent(QWSConvertSelectionCommand *cmd, int windowid); -#ifndef QT_QWS_CLIENTBLIT - void sendRegionEvent(int winid, QRegion rgn, int type); -#else - void sendRegionEvent(int winid, QRegion rgn, int type, int id = 0); -#endif -#ifndef QT_NO_QWSEMBEDWIDGET - void sendEmbedEvent(int winid, QWSEmbedEvent::Type type, - const QRegion ®ion = QRegion()); -#endif - QWSCommand* readMoreCommand(); - - int clientId() const { return cid; } - - QWSCursorMap cursors; // cursors defined by this client -Q_SIGNALS: - void connectionClosed(); - void readyRead(); -private Q_SLOTS: - void closeHandler(); - void errorHandler(); - -private: -#ifndef QT_NO_QWS_MULTIPROCESS - friend class QWSWindow; - void removeUnbufferedSurface(); - void addUnbufferedSurface(); -#endif - -private: - int socketDescriptor; -#ifndef QT_NO_QWS_MULTIPROCESS - QWSSocket *csocket; -#endif - QWSCommand* command; - uint isClosed : 1; - QString id; - int cid; - - friend class QWSServerPrivate; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWINDOWSYSTEM_QWS_H diff --git a/src/gui/embedded/qwscommand_qws.cpp b/src/gui/embedded/qwscommand_qws.cpp deleted file mode 100644 index 71d3a06dbe..0000000000 --- a/src/gui/embedded/qwscommand_qws.cpp +++ /dev/null @@ -1,609 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwscommand_qws_p.h" -#include "qtransportauth_qws.h" -#include "qtransportauth_qws_p.h" - -#include <unistd.h> - -// #define QWSCOMMAND_DEBUG 1 // Uncomment to debug client/server communication - -#ifdef QWSCOMMAND_DEBUG -# include <qdebug.h> -# include "qfile.h" -# include <ctype.h> -#endif - -QT_BEGIN_NAMESPACE - -#ifdef QWSCOMMAND_DEBUG -// QWSHexDump -[ start ]--------------------------------------------- -# define QWSHEXDUMP_MAX 32 -class QWSHexDump -{ -public: - - QWSHexDump(const void *address, int len, int wrapAt = 16) - : wrap(wrapAt), dataSize(len) - { - init(); - data = reinterpret_cast<const char*>(address); - if (len < 0) - dataSize = 0; - } - - QWSHexDump(const char *str, int len = -1, int wrapAt = 16) - : wrap(wrapAt), dataSize(len) - { - init(); - data = str; - if (len == -1) - dataSize = str ? strlen(str) : 0; - } - - QWSHexDump(const QByteArray &array, int wrapAt = 16) - : wrap(wrapAt) - { - init(); - data = array.data(); - dataSize = array.size(); - } - - // Sets a customized prefix for the hexdump - void setPrefix(const char *str) { prefix = str; } - - // Sets number of bytes to cluster together - void setClusterSize(uint num) { clustering = num; } - - // Output hexdump to a text stream - void intoTextStream(QTextStream &strm) { - outstrm = &strm; - hexDump(); - } - - // Output hexdump to a QString - QString toString(); - -protected: - void init(); - void hexDump(); - void sideviewDump(int at); - -private: - uint wrap; - uint clustering; - uint dataSize; - int dataWidth; - const char *data; - const char *prefix; - bool dirty; - - char sideviewLayout[QWSHEXDUMP_MAX + 1]; - char sideview[15]; - - QTextStream *outstrm; -}; - -void QWSHexDump::init() -{ - prefix = "> "; // Standard line prefix - clustering = 2; // Word-size clustering by default - if (wrap > QWSHEXDUMP_MAX) // No wider than QWSHexDump_MAX bytes - wrap = QWSHEXDUMP_MAX; -} - -void QWSHexDump::hexDump() -{ - *outstrm << '(' << dataSize << " bytes):\n" << prefix; - sprintf(sideviewLayout, " [%%-%us]", wrap); - dataWidth = (2 * wrap) + (wrap / clustering); - - dirty = false; - uint wrapIndex = 0; - for (uint i = 0; i < dataSize; i++) { - uint c = static_cast<uchar>(data[i]); - sideview[wrapIndex = i%wrap] = isprint(c) ? c : '.'; - - if (wrapIndex && (wrapIndex % clustering == 0)) - *outstrm << ' '; - - outstrm->setFieldWidth(2); - outstrm->setPadChar('0'); - outstrm->setNumberFlags( QTextStream::ShowBase ); - *outstrm << hex << c; - dirty = true; - - if (wrapIndex == wrap-1) { - sideviewDump(wrapIndex); - wrapIndex = 0; - if (i+1 < dataSize) - *outstrm << endl << prefix; - } - - } - sideviewDump(wrapIndex); -} - -void QWSHexDump::sideviewDump(int at) -{ - if (dirty) { - dirty = false; - ++at; - sideview[at] = '\0'; - int currentWidth = (2 * at) + (at / clustering) - (at%clustering?0:1); - int missing = qMax(dataWidth - currentWidth, 0); - while (missing--) - *outstrm << ' '; - - *outstrm << " ["; - outstrm->setPadChar(' '); - outstrm->setFieldWidth(wrap); - outstrm->setFieldAlignment( QTextStream::AlignLeft ); - *outstrm << sideview; - *outstrm << ']'; - } -} - -// Output hexdump to a QString -QString QWSHexDump::toString() { - QString result; - QTextStream strm(&result, QFile::WriteOnly); - outstrm = &strm; - hexDump(); - return result; -} - -#ifndef QT_NO_DEBUG -QDebug &operator<<(QDebug &dbg, QWSHexDump *hd) { - if (!hd) - return dbg << "QWSHexDump(0x0)"; - QString result = hd->toString(); - dbg.nospace() << result; - return dbg.space(); -} - -// GCC & Intel wont handle references here -QDebug operator<<(QDebug dbg, QWSHexDump hd) { - return dbg << &hd; -} -#endif -// QWSHexDump -[ end ]----------------------------------------------- - - -QDebug &operator<<(QDebug &dbg, QWSCommand::Type tp) -{ - dbg << qws_getCommandTypeString( tp ); - return dbg; -} - -#define N_EVENTS 19 -const char * eventNames[N_EVENTS] = { - "NoEvent", - "Connected", - "Mouse", "Focus", "Key", - "Region", - "Creation", - "PropertyNotify", - "PropertyReply", - "SelectionClear", - "SelectionRequest", - "SelectionNotify", - "MaxWindowRect", - "QCopMessage", - "WindowOperation", - "IMEvent", - "IMQuery", - "IMInit", - "Font" - }; - -class QWSServer; -extern QWSServer *qwsServer; -#endif - -const char *qws_getCommandTypeString( QWSCommand::Type tp ) -{ - const char *typeStr; - switch(tp) { - case QWSCommand::Create: - typeStr = "Create"; - break; - case QWSCommand::Shutdown: - typeStr = "Shutdown"; - break; - case QWSCommand::Region: - typeStr = "Region"; - break; - case QWSCommand::RegionMove: - typeStr = "RegionMove"; - break; - case QWSCommand::RegionDestroy: - typeStr = "RegionDestroy"; - break; - case QWSCommand::SetProperty: - typeStr = "SetProperty"; - break; - case QWSCommand::AddProperty: - typeStr = "AddProperty"; - break; - case QWSCommand::RemoveProperty: - typeStr = "RemoveProperty"; - break; - case QWSCommand::GetProperty: - typeStr = "GetProperty"; - break; - case QWSCommand::SetSelectionOwner: - typeStr = "SetSelectionOwner"; - break; - case QWSCommand::ConvertSelection: - typeStr = "ConvertSelection"; - break; - case QWSCommand::RequestFocus: - typeStr = "RequestFocus"; - break; - case QWSCommand::ChangeAltitude: - typeStr = "ChangeAltitude"; - break; - case QWSCommand::SetOpacity: - typeStr = "SetOpacity"; - break; - case QWSCommand::DefineCursor: - typeStr = "DefineCursor"; - break; - case QWSCommand::SelectCursor: - typeStr = "SelectCursor"; - break; - case QWSCommand::PositionCursor: - typeStr = "PositionCursor"; - break; - case QWSCommand::GrabMouse: - typeStr = "GrabMouse"; - break; - case QWSCommand::PlaySound: - typeStr = "PlaySound"; - break; - case QWSCommand::QCopRegisterChannel: - typeStr = "QCopRegisterChannel"; - break; - case QWSCommand::QCopSend: - typeStr = "QCopSend"; - break; - case QWSCommand::RegionName: - typeStr = "RegionName"; - break; - case QWSCommand::Identify: - typeStr = "Identify"; - break; - case QWSCommand::GrabKeyboard: - typeStr = "GrabKeyboard"; - break; - case QWSCommand::RepaintRegion: - typeStr = "RepaintRegion"; - break; - case QWSCommand::IMMouse: - typeStr = "IMMouse"; - break; - case QWSCommand::IMUpdate: - typeStr = "IMUpdate"; - break; - case QWSCommand::IMResponse: - typeStr = "IMResponse"; - break; - case QWSCommand::Font: - typeStr = "Font"; - break; - case QWSCommand::Unknown: - default: - typeStr = "Unknown"; - break; - } - return typeStr; -} - - -/********************************************************************* - * - * Functions to read/write commands on/from a socket - * - *********************************************************************/ - -#ifndef QT_NO_QWS_MULTIPROCESS -void qws_write_command(QIODevice *socket, int type, char *simpleData, int simpleLen, - char *rawData, int rawLen) -{ -#ifdef QWSCOMMAND_DEBUG - if (simpleLen) qDebug() << "WRITE simpleData " << QWSHexDump(simpleData, simpleLen); - if (rawLen > 0) qDebug() << "WRITE rawData " << QWSHexDump(rawData, rawLen); -#endif - -#ifndef QT_NO_SXE - QTransportAuth *a = QTransportAuth::getInstance(); - // ###### as soon as public API can be modified get rid of horrible casts - QIODevice *ad = a->passThroughByClient(reinterpret_cast<QWSClient*>(socket)); - if (ad) - socket = ad; -#endif - - qws_write_uint(socket, type); - - if (rawLen > MAX_COMMAND_SIZE) { - qWarning("qws_write_command: Message of size %d too big. " - "Truncated to %d", rawLen, MAX_COMMAND_SIZE); - rawLen = MAX_COMMAND_SIZE; - } - - qws_write_uint(socket, rawLen == -1 ? 0 : rawLen); - - if (simpleData && simpleLen) - socket->write(simpleData, simpleLen); - - if (rawLen && rawData) - socket->write(rawData, rawLen); -} - -/* - command format: [type][rawLen][simpleData][rawData] - type is already read when entering this function -*/ - -bool qws_read_command(QIODevice *socket, char *&simpleData, int &simpleLen, - char *&rawData, int &rawLen, int &bytesRead) -{ - - // read rawLen - if (rawLen == -1) { - rawLen = qws_read_uint(socket); - if (rawLen == -1) - return false; - } - - // read simpleData, assumes socket is capable of buffering all the data - if (simpleLen && !rawData) { - if (socket->bytesAvailable() < uint(simpleLen)) - return false; - int tmp = socket->read(simpleData, simpleLen); - Q_ASSERT(tmp == simpleLen); - Q_UNUSED(tmp); - } - - if (rawLen > MAX_COMMAND_SIZE) { - socket->close(); - qWarning("qws_read_command: Won't read command of length %d, " - "connection closed.", rawLen); - return false; - } - - // read rawData - if (rawLen && !rawData) { - rawData = new char[rawLen]; - bytesRead = 0; - } - if (bytesRead < rawLen && socket->bytesAvailable()) - bytesRead += socket->read(rawData + bytesRead, rawLen - bytesRead); - - return (bytesRead == rawLen); -} -#endif - -/********************************************************************* - * - * QWSCommand base class - only use derived classes from that - * - *********************************************************************/ -QWSProtocolItem::~QWSProtocolItem() { - if (deleteRaw) - delete []rawDataPtr; -} - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSProtocolItem::write(QIODevice *s) { -#ifdef QWSCOMMAND_DEBUG - if (!qwsServer) - qDebug() << "QWSProtocolItem::write sending type " << static_cast<QWSCommand::Type>(type); - else - qDebug() << "QWSProtocolItem::write sending event " << (type < N_EVENTS ? eventNames[type] : "unknown"); -#endif - qws_write_command(s, type, simpleDataPtr, simpleLen, rawDataPtr, rawLen); -} - -bool QWSProtocolItem::read(QIODevice *s) { -#ifdef QWSCOMMAND_DEBUG - QLatin1String reread( (rawLen == -1) ? "" : "REREAD"); - if (qwsServer) - qDebug() << "QWSProtocolItem::read reading type " << static_cast<QWSCommand::Type>(type) << reread; - else - qDebug() << "QWSProtocolItem::read reading event " << (type < N_EVENTS ? eventNames[type] : "unknown") << reread; - //qDebug("QWSProtocolItem::read reading event %s", type < N_EVENTS ? eventNames[type] : "unknown"); -#endif - bool b = qws_read_command(s, simpleDataPtr, simpleLen, rawDataPtr, rawLen, bytesRead); - if (b) { - setData(rawDataPtr, rawLen, false); - deleteRaw = true; - } -#ifdef QWSCOMMAND_DEBUG - else - { - qDebug() << "error in reading command " << static_cast<QWSCommand::Type>(type); - } -#endif - return b; -} -#endif // QT_NO_QWS_MULTIPROCESS - -void QWSProtocolItem::copyFrom(const QWSProtocolItem *item) { - if (this == item) - return; - simpleLen = item->simpleLen; - memcpy(simpleDataPtr, item->simpleDataPtr, simpleLen); - setData(item->rawDataPtr, item->rawLen); -} - -void QWSProtocolItem::setData(const char *data, int len, bool allocateMem) { - if (deleteRaw) - delete [] rawDataPtr; - if (!data || len <= 0) { - rawDataPtr = 0; - rawLen = 0; - return; - } - if (allocateMem) { - rawDataPtr = new char[len]; - memcpy(rawDataPtr, data, len); - deleteRaw = true; - } else { - rawDataPtr = const_cast<char *>(data); - deleteRaw = false; - } - rawLen = len; -} - -QWSCommand *QWSCommand::factory(int type) -{ - QWSCommand *command = 0; - switch (type) { - case QWSCommand::Create: - command = new QWSCreateCommand; - break; - case QWSCommand::Shutdown: - command = new QWSCommand(type, 0, 0); - break; - case QWSCommand::Region: - command = new QWSRegionCommand; - break; - case QWSCommand::RegionMove: - command = new QWSRegionMoveCommand; - break; - case QWSCommand::RegionDestroy: - command = new QWSRegionDestroyCommand; - break; - case QWSCommand::AddProperty: - command = new QWSAddPropertyCommand; - break; - case QWSCommand::SetProperty: - command = new QWSSetPropertyCommand; - break; - case QWSCommand::RemoveProperty: - command = new QWSRemovePropertyCommand; - break; - case QWSCommand::GetProperty: - command = new QWSGetPropertyCommand; - break; - case QWSCommand::SetSelectionOwner: - command = new QWSSetSelectionOwnerCommand; - break; - case QWSCommand::RequestFocus: - command = new QWSRequestFocusCommand; - break; - case QWSCommand::ChangeAltitude: - command = new QWSChangeAltitudeCommand; - break; - case QWSCommand::SetOpacity: - command = new QWSSetOpacityCommand; - break; - case QWSCommand::DefineCursor: - command = new QWSDefineCursorCommand; - break; - case QWSCommand::SelectCursor: - command = new QWSSelectCursorCommand; - break; - case QWSCommand::GrabMouse: - command = new QWSGrabMouseCommand; - break; - case QWSCommand::GrabKeyboard: - command = new QWSGrabKeyboardCommand; - break; -#ifndef QT_NO_SOUND - case QWSCommand::PlaySound: - command = new QWSPlaySoundCommand; - break; -#endif -#ifndef QT_NO_COP - case QWSCommand::QCopRegisterChannel: - command = new QWSQCopRegisterChannelCommand; - break; - case QWSCommand::QCopSend: - command = new QWSQCopSendCommand; - break; -#endif - case QWSCommand::RegionName: - command = new QWSRegionNameCommand; - break; - case QWSCommand::Identify: - command = new QWSIdentifyCommand; - break; - case QWSCommand::RepaintRegion: - command = new QWSRepaintRegionCommand; - break; -#ifndef QT_NO_QWS_INPUTMETHODS - case QWSCommand::IMUpdate: - command = new QWSIMUpdateCommand; - break; - - case QWSCommand::IMMouse: - command = new QWSIMMouseCommand; - break; - - case QWSCommand::IMResponse: - command = new QWSIMResponseCommand; - break; -#endif - case QWSCommand::PositionCursor: - command = new QWSPositionCursorCommand; - break; -#ifndef QT_NO_QWSEMBEDWIDGET - case QWSCommand::Embed: - command = new QWSEmbedCommand; - break; -#endif - case QWSCommand::Font: - command = new QWSFontCommand; - break; - case QWSCommand::ScreenTransform: - command = new QWSScreenTransformCommand; - break; - default: - qWarning("QWSCommand::factory : Type error - got %08x!", type); - } - return command; -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qwscommand_qws_p.h b/src/gui/embedded/qwscommand_qws_p.h deleted file mode 100644 index 70ecc6be6d..0000000000 --- a/src/gui/embedded/qwscommand_qws_p.h +++ /dev/null @@ -1,851 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSCOMMAND_QWS_P_H -#define QWSCOMMAND_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -// When reading commands "off the wire" in the server, the rawLen is read -// and then that many bytes are allocated. If the rawLen is corrupted (or -// the protocol is being attacked) too many bytes can be allocated. Set -// a hard limit here for security. -#define MAX_COMMAND_SIZE (16 * 1024) - -#include <QtCore/qbytearray.h> -#include <QtGui/qwsutils_qws.h> -#include <QtGui/qfont.h> -#include <QtCore/qdatastream.h> -#include <QtCore/qvariant.h> -#include <QtCore/qrect.h> -#include <QtGui/qregion.h> -#include <QtCore/qvector.h> -#include <QtCore/qvarlengtharray.h> -#include <QtGui/qwsevent_qws.h> -#include "qwsprotocolitem_qws.h" - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QRect; - -/********************************************************************* - * - * Functions to read/write commands on/from a socket - * - *********************************************************************/ -#ifndef QT_NO_QWS_MULTIPROCESS -void qws_write_command(QIODevice *socket, int type, char *simpleData, int simpleLen, char *rawData, int rawLen); -bool qws_read_command(QIODevice *socket, char *&simpleData, int &simpleLen, char *&rawData, int &rawLen, int &bytesRead); -#endif - -struct QWSCommand : QWSProtocolItem -{ - QWSCommand(int t, int len, char *ptr) : QWSProtocolItem(t,len,ptr) {} - - enum Type { - Unknown = 0, - Create, - Shutdown, - Region, - RegionMove, - RegionDestroy, - SetProperty, - AddProperty, - RemoveProperty, - GetProperty, - SetSelectionOwner, - ConvertSelection, - RequestFocus, - ChangeAltitude, - SetOpacity, - DefineCursor, - SelectCursor, - PositionCursor, - GrabMouse, - PlaySound, - QCopRegisterChannel, - QCopSend, - RegionName, - Identify, - GrabKeyboard, - RepaintRegion, - IMMouse, - IMUpdate, - IMResponse, - Embed, - Font, - ScreenTransform - }; - static QWSCommand *factory(int type); -}; - -const char *qws_getCommandTypeString( QWSCommand::Type tp ); - -#ifndef QT_NO_DEBUG -class QDebug; -QDebug &operator<<(QDebug &dbg, QWSCommand::Type tp); -#endif // QT_NO_DEBUG - -/********************************************************************* - * - * Commands - * - *********************************************************************/ - -struct QWSIdentifyCommand : public QWSCommand -{ - QWSIdentifyCommand() : - QWSCommand(QWSCommand::Identify, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) - { - simpleData.idLen = 0; - simpleData.idLock = -1; - } - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - if ( simpleData.idLen > MAX_COMMAND_SIZE ) - { - qWarning( "Identify command - name length %d - too big!", simpleData.idLen ); - simpleData.idLen = MAX_COMMAND_SIZE; - } - if ( simpleData.idLen * int(sizeof(QChar)) > len ) - { - qWarning( "Identify command - name length %d - buffer size %d - buffer overrun!", simpleData.idLen, len ); - } - else - { - id = QString(reinterpret_cast<const QChar*>(d), simpleData.idLen); - } - } - - void setId(const QString& i, int lock) - { - id = i; - simpleData.idLen = id.length(); - simpleData.idLock = lock; - setData(reinterpret_cast<const char*>(id.unicode()), simpleData.idLen*2, true); - } - - struct SimpleData { - int idLen; - int idLock; - } simpleData; - QString id; -}; - -struct QWSCreateCommand : public QWSCommand -{ - QWSCreateCommand(int n = 1) : - QWSCommand(QWSCommand::Create, sizeof(count), - reinterpret_cast<char *>(&count)), count(n) {} - int count; -}; - -struct QWSRegionNameCommand : public QWSCommand -{ - QWSRegionNameCommand() : - QWSCommand(QWSCommand::RegionName, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - if ( simpleData.nameLen > MAX_COMMAND_SIZE ) - { - qWarning( "region name command - name length too big!" ); - simpleData.nameLen = MAX_COMMAND_SIZE; - } - if ( simpleData.captionLen > MAX_COMMAND_SIZE ) - { - qWarning( "region name command - caption length too big!" ); - simpleData.captionLen = MAX_COMMAND_SIZE; - } - if ( simpleData.nameLen + simpleData.captionLen > len ) - { - qWarning( "region name command - name length %d - caption length %d - buffer size %d - buffer overrun!", - simpleData.nameLen, simpleData.captionLen, len ); - - } - else - { - name = QString(reinterpret_cast<const QChar*>(d), simpleData.nameLen/2); - d += simpleData.nameLen; - caption = QString(reinterpret_cast<const QChar*>(d), simpleData.captionLen/2); - } - } - - void setName(const QString& n, const QString &c) - { - name = n; - caption = c; - int l = simpleData.nameLen = name.length()*2; - l += simpleData.captionLen = caption.length()*2; - char *d = new char[l]; - memcpy(d, name.unicode(), simpleData.nameLen); - memcpy(d+simpleData.nameLen, caption.unicode(), simpleData.captionLen); - setData(d, l, true); - delete[] d; - } - - struct SimpleData { - int windowid; - int nameLen; - int captionLen; - } simpleData; - QString name; - QString caption; -}; - -struct QWSRegionCommand : public QWSCommand -{ - QWSRegionCommand() : - QWSCommand(QWSCommand::Region, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem = true) { - QWSCommand::setData(d, len, allocateMem); - - if( simpleData.nrectangles * int(sizeof(QRect)) + simpleData.surfacekeylength * int(sizeof(QChar)) + simpleData.surfacedatalength * int(sizeof(char)) > len ) - { - qWarning( "region command - rectangle count %d - surface key length %d - region data size %d - buffer size %d - buffer overrun!", - simpleData.nrectangles, simpleData.surfacekeylength, simpleData.surfacedatalength, len ); - } - else - { - char *ptr = rawDataPtr; - - region.setRects(reinterpret_cast<QRect*>(ptr), simpleData.nrectangles); - ptr += simpleData.nrectangles * sizeof(QRect); - - surfaceKey = QString(reinterpret_cast<QChar*>(ptr), - simpleData.surfacekeylength); - ptr += simpleData.surfacekeylength * sizeof(QChar); - - surfaceData = QByteArray(ptr, simpleData.surfacedatalength); - } - } - - void setData(int id, const QString &key, const QByteArray &data, - const QRegion ®) - { - surfaceKey = key; - surfaceData = data; - region = reg; - - const QVector<QRect> rects = reg.rects(); - - simpleData.windowid = id; - simpleData.surfacekeylength = key.size(); - simpleData.surfacedatalength = data.size(); - simpleData.nrectangles = rects.count(); - - QVarLengthArray<char, 256> buffer; - buffer.append(reinterpret_cast<const char*>(rects.constData()), - rects.count() * sizeof(QRect)); - buffer.append(reinterpret_cast<const char*>(key.constData()), - key.size() * sizeof(QChar)); - buffer.append(data, data.size()); - - QWSCommand::setData(buffer.constData(), buffer.size(), true); - } - - /* XXX this will pad out in a compiler dependent way, - should move nrectangles to before windowtype, and - add reserved bytes. - Symptom will be valgrind reported uninitialized memory usage - */ - struct SimpleData { - int windowid; - int surfacekeylength; - int surfacedatalength; - int nrectangles; - } simpleData; - - QString surfaceKey; - QByteArray surfaceData; - QRegion region; -}; - -struct QWSSetOpacityCommand : public QWSCommand -{ - QWSSetOpacityCommand() : - QWSCommand(QWSCommand::SetOpacity, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid; - uchar opacity; - } simpleData; -}; - -struct QWSRegionMoveCommand : public QWSCommand -{ - QWSRegionMoveCommand() : - QWSCommand(QWSCommand::RegionMove, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid; - int dx; - int dy; - } simpleData; - -}; - -struct QWSRegionDestroyCommand : public QWSCommand -{ - QWSRegionDestroyCommand() : - QWSCommand(QWSCommand::RegionDestroy, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid; - } simpleData; - -}; - -struct QWSRequestFocusCommand : public QWSCommand -{ - QWSRequestFocusCommand() : - QWSCommand(QWSCommand::RequestFocus, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid; - int flag; - } simpleData; -}; - -struct QWSChangeAltitudeCommand : public QWSCommand -{ - QWSChangeAltitudeCommand() : - QWSCommand(QWSCommand::ChangeAltitude, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - enum Altitude { - Lower = -1, - Raise = 0, - StaysOnTop = 1 - }; - - struct SimpleData { - int windowid; - Altitude altitude; - bool fixed; - } simpleData; - -}; - - -struct QWSAddPropertyCommand : public QWSCommand -{ - QWSAddPropertyCommand() : - QWSCommand(QWSCommand::AddProperty, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid, property; - } simpleData; - -}; - -struct QWSSetPropertyCommand : public QWSCommand -{ - QWSSetPropertyCommand() : - QWSCommand(QWSCommand::SetProperty, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) { data = 0; } - - void setData(const char *d, int len, bool allocateMem = true) { - QWSCommand::setData(d, len, allocateMem); - data = rawDataPtr; - } - - struct SimpleData { - int windowid, property, mode; - } simpleData; - - char *data; -}; - -struct QWSRepaintRegionCommand : public QWSCommand -{ - QWSRepaintRegionCommand() : - QWSCommand(QWSCommand::RepaintRegion, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem = true) { - QWSCommand::setData(d, len, allocateMem); - - if( simpleData.nrectangles * int(sizeof(QRect)) > len ) - { - qWarning( "repaint region command - region rectangle count %d - buffer size %d - buffer overrun", - simpleData.nrectangles, len ); - - simpleData.nrectangles = len / sizeof(QRect); - } - rectangles = reinterpret_cast<QRect *>(rawDataPtr); - } - - struct SimpleData { - int windowid; - int windowFlags; - bool opaque; - int nrectangles; - } simpleData; - - QRect * rectangles; - -}; - -struct QWSRemovePropertyCommand : public QWSCommand -{ - QWSRemovePropertyCommand() : - QWSCommand(QWSCommand::RemoveProperty, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid, property; - } simpleData; - -}; - -struct QWSGetPropertyCommand : public QWSCommand -{ - QWSGetPropertyCommand() : - QWSCommand(QWSCommand::GetProperty, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid, property; - } simpleData; - -}; - -struct QWSSetSelectionOwnerCommand : public QWSCommand -{ - QWSSetSelectionOwnerCommand() : - QWSCommand(QWSCommand::SetSelectionOwner, - sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int windowid; - int hour, minute, sec, ms; // time - } simpleData; - -}; - -struct QWSConvertSelectionCommand : public QWSCommand -{ - QWSConvertSelectionCommand() : - QWSCommand(QWSCommand::ConvertSelection, - sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int requestor; // requestor window of the selection - int selection; // property on requestor into which the selection should be stored - int mimeTypes; // property ion requestor in which the mimetypes, in which the selection may be, are stored - } simpleData; - -}; - -struct QWSDefineCursorCommand : public QWSCommand -{ - QWSDefineCursorCommand() : - QWSCommand(QWSCommand::DefineCursor, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem = true) { - QWSCommand::setData(d, len, allocateMem); - data = reinterpret_cast<unsigned char *>(rawDataPtr); - if (simpleData.height * ((simpleData.width+7) / 8) > len) { - qWarning("define cursor command - width %d height %d- buffer size %d - buffer overrun", - simpleData.width, simpleData.height, len ); - simpleData.width = simpleData.height = 0; - } - } - - struct SimpleData { - int width; - int height; - int hotX; - int hotY; - int id; - } simpleData; - - unsigned char *data; -}; - -struct QWSSelectCursorCommand : public QWSCommand -{ - QWSSelectCursorCommand() : - QWSCommand(QWSCommand::SelectCursor, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int windowid; - int id; - } simpleData; -}; - -struct QWSPositionCursorCommand : public QWSCommand -{ - QWSPositionCursorCommand() : - QWSCommand(QWSCommand::PositionCursor, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int newX; - int newY; - } simpleData; -}; - -struct QWSGrabMouseCommand : public QWSCommand -{ - QWSGrabMouseCommand() : - QWSCommand(QWSCommand::GrabMouse, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int windowid; - bool grab; // grab or ungrab? - } simpleData; -}; - -struct QWSGrabKeyboardCommand : public QWSCommand -{ - QWSGrabKeyboardCommand() : - QWSCommand(QWSCommand::GrabKeyboard, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int windowid; - bool grab; // grab or ungrab? - } simpleData; -}; - -#ifndef QT_NO_SOUND -struct QWSPlaySoundCommand : public QWSCommand -{ - QWSPlaySoundCommand() : - QWSCommand(QWSCommand::PlaySound, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - filename = QString(reinterpret_cast<QChar*>(rawDataPtr),len/2); - } - void setFileName(const QString& n) - { - setData(reinterpret_cast<const char*>(n.unicode()), n.length()*2, true); - } - - struct SimpleData { - int windowid; - } simpleData; - QString filename; -}; -#endif - - -#ifndef QT_NO_COP -struct QWSQCopRegisterChannelCommand : public QWSCommand -{ - QWSQCopRegisterChannelCommand() : - QWSCommand(QWSCommand::QCopRegisterChannel, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - if ( simpleData.chLen > MAX_COMMAND_SIZE ) - { - qWarning( "Command channel name too large!" ); - simpleData.chLen = MAX_COMMAND_SIZE; - } - if( simpleData.chLen * int(sizeof(QChar)) > len ) - { - qWarning( "register qcop channel command - channel name length %d - buffer size %d - buffer overrun!", simpleData.chLen, len ); - } - else - { - channel = QString(reinterpret_cast<const QChar*>(d), simpleData.chLen); - } - } - - void setChannel(const QString& n) - { - channel = n; - simpleData.chLen = channel.length(); - setData(reinterpret_cast<const char*>(channel.unicode()), simpleData.chLen*2, true); - } - - struct SimpleData { - int chLen; - } simpleData; - QString channel; -}; - -struct QWSQCopSendCommand : public QWSCommand -{ - QWSQCopSendCommand() : - QWSCommand(QWSCommand::QCopSend, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - - if( simpleData.clen * int(sizeof(QChar)) + simpleData.mlen * int(sizeof(QChar)) + simpleData.dlen * int(sizeof(char)) > len ) - { - qWarning( "qcop send command - channel name length %d - message name length %d - data size %d - buffer size %d - buffer overrun!", - simpleData.clen, simpleData.mlen, simpleData.dlen, len ); - } - else - { - const QChar *cd = reinterpret_cast<const QChar*>(d); - channel = QString(cd,simpleData.clen); cd += simpleData.clen; - message = QString(cd,simpleData.mlen); - d += simpleData.clen*sizeof(QChar) + simpleData.mlen*sizeof(QChar); - data = QByteArray(d, simpleData.dlen); - } - } - - void setMessage(const QString &c, const QString &m, - const QByteArray &data) - { - this->channel = c; - this->message = m; - this->data = data; - simpleData.clen = c.length(); - simpleData.mlen = m.length(); - simpleData.dlen = data.size(); - int l = simpleData.clen*sizeof(QChar); - l += simpleData.mlen*sizeof(QChar); - l += simpleData.dlen; - char *tmp = new char[l]; - char *d = tmp; - memcpy(d, c.unicode(), simpleData.clen*sizeof(QChar)); - d += simpleData.clen*sizeof(QChar); - memcpy(d, m.unicode(), simpleData.mlen*sizeof(QChar)); - d += simpleData.mlen*sizeof(QChar); - memcpy(d, data.data(), simpleData.dlen); - QWSCommand::setData(tmp, l, false); - deleteRaw = true; - } - - struct SimpleData { - int clen; - int mlen; - int dlen; - } simpleData; - QString channel; - QString message; - QByteArray data; -}; - -#endif - - -#ifndef QT_NO_QWS_INPUTMETHODS - -struct QWSIMMouseCommand : public QWSCommand -{ - QWSIMMouseCommand() : - QWSCommand(QWSCommand::IMMouse, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int windowid; - int state; - int index; - } simpleData; -}; - - -struct QWSIMResponseCommand : public QWSCommand -{ - QWSIMResponseCommand() : - QWSCommand(QWSCommand::IMResponse, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - - QByteArray tmp = QByteArray::fromRawData(d, len); - QDataStream s(tmp); - s >> result; - } - - void setResult(const QVariant & v) - { - QByteArray tmp; - QDataStream s(&tmp, QIODevice::WriteOnly); - s << v; - setData(tmp.data(), tmp.size(), true); - } - - struct SimpleData { - int windowid; - int property; - } simpleData; - - QVariant result; -}; - -struct QWSIMUpdateCommand: public QWSCommand -{ - QWSIMUpdateCommand() : - QWSCommand(QWSCommand::IMUpdate, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - struct SimpleData { - int windowid; - int type; - int widgetid; - } simpleData; -}; - -#endif - -#ifndef QT_NO_QWSEMBEDWIDGET -struct QWSEmbedCommand : public QWSCommand -{ - QWSEmbedCommand() : QWSCommand(QWSCommand::Embed, - sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) - {} - - void setData(const char *d, int len, bool allocateMem = true) - { - QWSCommand::setData(d, len, allocateMem); - - if( simpleData.rects * int(sizeof(QRect)) > len ) - { - qWarning( "embed command - region rectangle count %d - buffer size %d - buffer overrun!", - simpleData.rects, len ); - } - else - { - region.setRects(reinterpret_cast<QRect*>(rawDataPtr), - simpleData.rects); - } - } - - void setData(WId embedder, WId embedded, QWSEmbedEvent::Type type, - const QRegion reg = QRegion()) - { - simpleData.embedder = embedder; - simpleData.embedded = embedded; - simpleData.type = type; - - region = reg; - const QVector<QRect> rects = reg.rects(); - simpleData.rects = rects.count(); - - QWSCommand::setData(reinterpret_cast<const char*>(rects.constData()), - rects.count() * sizeof(QRect)); - } - - struct { - WId embedder; - WId embedded; - QWSEmbedEvent::Type type; - int rects; - } simpleData; - - QRegion region; -}; -#endif // QT_NO_QWSEMBEDWIDGET - -struct QWSFontCommand : public QWSCommand -{ - enum CommandType { - StartedUsingFont, - StoppedUsingFont - }; - - QWSFontCommand() : - QWSCommand(QWSCommand::Font, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem) { - QWSCommand::setData(d, len, allocateMem); - - fontName = QByteArray(d, len); - } - - void setFontName(const QByteArray &name) - { - setData(name.constData(), name.size(), true); - } - - struct SimpleData { - int type; - } simpleData; - - QByteArray fontName; -}; - -struct QWSScreenTransformCommand : public QWSCommand -{ - QWSScreenTransformCommand() : - QWSCommand(QWSCommand::ScreenTransform, - sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} - - void setTransformation(int screen, int transformation) - { - simpleData.screen = screen; - simpleData.transformation = transformation; - } - - struct SimpleData { - int screen; - int transformation; - } simpleData; -}; - -QT_END_NAMESPACE - -#endif // QWSCOMMAND_QWS_P_H diff --git a/src/gui/embedded/qwscursor_qws.cpp b/src/gui/embedded/qwscursor_qws.cpp deleted file mode 100644 index 0313e00391..0000000000 --- a/src/gui/embedded/qwscursor_qws.cpp +++ /dev/null @@ -1,654 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcursor.h" -#include "qbitmap.h" -#include "qscreen_qws.h" -#include "qapplication.h" -#include "qwindowsystem_qws.h" -#include "qwindowsystem_p.h" -#include "qwscursor_qws.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_QWS_CURSOR -static QWSCursor *systemCursorTable[Qt::LastCursor+1]; -static bool systemCursorTableInit = false; - -// 16 x 16 -static const uchar cur_arrow_bits[] = { - 0x07, 0x00, 0x39, 0x00, 0xc1, 0x01, 0x02, 0x0e, 0x02, 0x10, 0x02, 0x08, - 0x04, 0x04, 0x04, 0x02, 0x04, 0x04, 0x88, 0x08, 0x48, 0x11, 0x28, 0x22, - 0x10, 0x44, 0x00, 0x28, 0x00, 0x10, 0x00, 0x00 }; -static const uchar mcur_arrow_bits[] = { - 0x07, 0x00, 0x3f, 0x00, 0xff, 0x01, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x0f, - 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x0f, 0x78, 0x1f, 0x38, 0x3e, - 0x10, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00 }; - -static const unsigned char cur_up_arrow_bits[] = { - 0x80, 0x00, 0x40, 0x01, 0x40, 0x01, 0x20, 0x02, 0x20, 0x02, 0x10, 0x04, - 0x10, 0x04, 0x08, 0x08, 0x78, 0x0f, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, - 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0, 0x01}; -static const unsigned char mcur_up_arrow_bits[] = { - 0x80, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0xe0, 0x03, 0xe0, 0x03, 0xf0, 0x07, - 0xf0, 0x07, 0xf8, 0x0f, 0xf8, 0x0f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01}; - -static const unsigned char cur_cross_bits[] = { - 0xc0, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, - 0x7f, 0x7f, 0x01, 0x40, 0x7f, 0x7f, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, - 0x40, 0x01, 0x40, 0x01, 0xc0, 0x01, 0x00, 0x00}; -static const unsigned char mcur_cross_bits[] = { - 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00}; - -static const uchar cur_ibeam_bits[] = { - 0x00, 0x00, 0xe0, 0x03, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, - 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, - 0x80, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00 }; -static const uchar mcur_ibeam_bits[] = { - 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, - 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0x00, 0x00 }; - -static const uchar cur_ver_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, - 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f, - 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 }; -static const uchar mcur_ver_bits[] = { - 0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f, - 0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f, - 0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 }; - -static const uchar cur_hor_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18, - 0x38, 0x38, 0xfc, 0x7f, 0xfc, 0x7f, 0x38, 0x38, 0x30, 0x18, 0x20, 0x08, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar mcur_hor_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x60, 0x0c, 0x70, 0x1c, 0x78, 0x3c, - 0xfc, 0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f, 0x78, 0x3c, - 0x70, 0x1c, 0x60, 0x0c, 0x40, 0x04, 0x00, 0x00 }; -static const uchar cur_bdiag_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, - 0x00, 0x37, 0x88, 0x23, 0xd8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0xf8, 0x00, - 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar mcur_bdiag_bits[] = { - 0x00, 0x00, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x04, 0x7f, - 0x8c, 0x7f, 0xdc, 0x77, 0xfc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, - 0xfc, 0x03, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00 }; -static const uchar cur_fdiag_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, - 0xf8, 0x00, 0xd8, 0x01, 0x88, 0x23, 0x00, 0x37, 0x00, 0x3e, 0x00, 0x3c, - 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00 }; -static const uchar mcur_fdiag_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, - 0xfc, 0x41, 0xfc, 0x63, 0xdc, 0x77, 0x8c, 0x7f, 0x04, 0x7f, 0x00, 0x7e, - 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x7f, 0x00, 0x00 }; -static const uchar cur_blank_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -// 20 x 20 -static const uchar forbidden_bits[] = { - 0x00,0x00,0x00,0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xf0,0x00,0x38,0xc0,0x01, - 0x7c,0x80,0x03,0xec,0x00,0x03,0xce,0x01,0x07,0x86,0x03,0x06,0x06,0x07,0x06, - 0x06,0x0e,0x06,0x06,0x1c,0x06,0x0e,0x38,0x07,0x0c,0x70,0x03,0x1c,0xe0,0x03, - 0x38,0xc0,0x01,0xf0,0xe0,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00,0x00,0x00,0x00 }; - -static const uchar forbiddenm_bits[] = { - 0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xff,0x00,0xf8,0xff,0x01,0xfc,0xf0,0x03, - 0xfe,0xc0,0x07,0xfe,0x81,0x07,0xff,0x83,0x0f,0xcf,0x07,0x0f,0x8f,0x0f,0x0f, - 0x0f,0x1f,0x0f,0x0f,0x3e,0x0f,0x1f,0xfc,0x0f,0x1e,0xf8,0x07,0x3e,0xf0,0x07, - 0xfc,0xe0,0x03,0xf8,0xff,0x01,0xf0,0xff,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00}; - -// 32 x 32 -static const uchar wait_data_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00, - 0x00, 0x04, 0x40, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x08, 0x20, 0x00, - 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0x20, 0x00, - 0x00, 0x50, 0x15, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x40, 0x05, 0x00, - 0x00, 0x80, 0x02, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x20, 0x08, 0x00, - 0x00, 0x10, 0x10, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x88, 0x22, 0x00, - 0x00, 0x48, 0x25, 0x00, 0x00, 0xa8, 0x2a, 0x00, 0x00, 0xfc, 0x7f, 0x00, - 0x00, 0x04, 0x40, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar wait_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00, - 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xf8, 0x3f, 0x00, - 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, - 0x00, 0xf0, 0x1f, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0xc0, 0x07, 0x00, - 0x00, 0x80, 0x03, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0xe0, 0x0f, 0x00, - 0x00, 0xf0, 0x1f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, - 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xfc, 0x7f, 0x00, - 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uchar hsplit_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, - 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, - 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03, - 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00, - 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, - 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar hsplitm_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, - 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00, - 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07, - 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00, - 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, - 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar vsplit_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar vsplitm_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, - 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, - 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, - 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, - 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar phand_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, - 0x7e, 0x04, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x70, 0x08, 0x00, 0x00, - 0x08, 0x08, 0x00, 0x00, 0x70, 0x14, 0x00, 0x00, 0x08, 0x22, 0x00, 0x00, - 0x30, 0x41, 0x00, 0x00, 0xc0, 0x20, 0x00, 0x00, 0x40, 0x12, 0x00, 0x00, - 0x80, 0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar phandm_bits[] = { - 0xfe, 0x01, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, - 0xfc, 0x1f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, - 0xf8, 0xff, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, - 0xc0, 0x1f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uchar size_all_data_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x80, 0x81, 0xc0, 0x00, - 0xc0, 0xff, 0xff, 0x01, 0x80, 0x81, 0xc0, 0x00, 0x00, 0x81, 0x40, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uchar size_all_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, - 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc2, 0x21, 0x00, - 0x00, 0xc3, 0x61, 0x00, 0x80, 0xc3, 0xe1, 0x00, 0xc0, 0xff, 0xff, 0x01, - 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0x80, 0xc3, 0xe1, 0x00, - 0x00, 0xc3, 0x61, 0x00, 0x00, 0xc2, 0x21, 0x00, 0x00, 0xc0, 0x01, 0x00, - 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, - 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const uchar whatsthis_bits[] = { - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x07, 0x00, - 0x09, 0x18, 0x0e, 0x00, 0x11, 0x1c, 0x0e, 0x00, 0x21, 0x1c, 0x0e, 0x00, - 0x41, 0x1c, 0x0e, 0x00, 0x81, 0x1c, 0x0e, 0x00, 0x01, 0x01, 0x07, 0x00, - 0x01, 0x82, 0x03, 0x00, 0xc1, 0xc7, 0x01, 0x00, 0x49, 0xc0, 0x01, 0x00, - 0x95, 0xc0, 0x01, 0x00, 0x93, 0xc0, 0x01, 0x00, 0x21, 0x01, 0x00, 0x00, - 0x20, 0xc1, 0x01, 0x00, 0x40, 0xc2, 0x01, 0x00, 0x40, 0x02, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static const uchar whatsthism_bits[] = { - 0x01, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0x00, 0x07, 0xf8, 0x0f, 0x00, - 0x0f, 0xfc, 0x1f, 0x00, 0x1f, 0x3e, 0x1f, 0x00, 0x3f, 0x3e, 0x1f, 0x00, - 0x7f, 0x3e, 0x1f, 0x00, 0xff, 0x3e, 0x1f, 0x00, 0xff, 0x9d, 0x0f, 0x00, - 0xff, 0xc3, 0x07, 0x00, 0xff, 0xe7, 0x03, 0x00, 0x7f, 0xe0, 0x03, 0x00, - 0xf7, 0xe0, 0x03, 0x00, 0xf3, 0xe0, 0x03, 0x00, 0xe1, 0xe1, 0x03, 0x00, - 0xe0, 0xe1, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, - 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - -static const uchar busy_bits[] = { - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, - 0x41, 0xe0, 0xff, 0x00, 0x81, 0x20, 0x80, 0x00, 0x01, 0xe1, 0xff, 0x00, - 0x01, 0x42, 0x40, 0x00, 0xc1, 0x47, 0x40, 0x00, 0x49, 0x40, 0x55, 0x00, - 0x95, 0x80, 0x2a, 0x00, 0x93, 0x00, 0x15, 0x00, 0x21, 0x01, 0x0a, 0x00, - 0x20, 0x01, 0x11, 0x00, 0x40, 0x82, 0x20, 0x00, 0x40, 0x42, 0x44, 0x00, - 0x80, 0x41, 0x4a, 0x00, 0x00, 0x40, 0x55, 0x00, 0x00, 0xe0, 0xff, 0x00, - 0x00, 0x20, 0x80, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static const uchar busym_bits[] = { - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, - 0x7f, 0xe0, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00, - 0xff, 0xc3, 0x7f, 0x00, 0xff, 0xc7, 0x7f, 0x00, 0x7f, 0xc0, 0x7f, 0x00, - 0xf7, 0x80, 0x3f, 0x00, 0xf3, 0x00, 0x1f, 0x00, 0xe1, 0x01, 0x0e, 0x00, - 0xe0, 0x01, 0x1f, 0x00, 0xc0, 0x83, 0x3f, 0x00, 0xc0, 0xc3, 0x7f, 0x00, - 0x80, 0xc1, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0x00, - 0x00, 0xe0, 0xff, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -// 16 x 16 -static const uchar openhand_bits[] = { - 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92, - 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20, - 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00}; -static const uchar openhandm_bits[] = { - 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff, - 0xfe,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f, - 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00}; -static const uchar closedhand_bits[] = { - 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50, - 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10, - 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00}; -static const uchar closedhandm_bits[] = { - 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f, - 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f, - 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00}; - -#endif - -void QWSServerPrivate::initializeCursor() -{ - Q_Q(QWSServer); - // setup system cursors -#ifndef QT_NO_QWS_CURSOR -// qt_screen->initCursor(sharedram + ramlen,true); - - // default cursor - cursor = 0; - setCursor(QWSCursor::systemCursor(Qt::ArrowCursor)); -#endif - q->sendMouseEvent(QPoint(swidth/2, sheight/2), 0); -} - -void QWSServerPrivate::setCursor(QWSCursor *curs) -{ -#ifdef QT_NO_QWS_CURSOR - Q_UNUSED(curs); -#else - if (cursor == curs) - return; - - cursor = curs; - - if (!haveviscurs || !curs) - curs = QWSCursor::systemCursor(Qt::BlankCursor); - - if (qt_screencursor) { - qt_screencursor->set(curs->image(), - curs->hotSpot().x(), - curs->hotSpot().y()); - } -#endif -} - -#ifndef QT_NO_QWS_CURSOR -static void cleanupSystemCursorTable() -{ - for (int i = 0; i <= Qt::LastCursor; i++) - if (systemCursorTable[i]) { - delete systemCursorTable[i]; - systemCursorTable[i] = 0; - } -} -#endif - -void QWSCursor::createSystemCursor(int id) -{ -#ifdef QT_NO_QWS_CURSOR - Q_UNUSED(id); -#else - if (!systemCursorTableInit) { - for (int i = 0; i <= Qt::LastCursor; i++) - systemCursorTable[i] = 0; - qAddPostRoutine(cleanupSystemCursorTable); - systemCursorTableInit = true; - } - switch (id) { - // 16x16 cursors - case Qt::ArrowCursor: - systemCursorTable[Qt::ArrowCursor] = - new QWSCursor(cur_arrow_bits, mcur_arrow_bits, 16, 16, 0, 0); - break; - - case Qt::UpArrowCursor: - systemCursorTable[Qt::UpArrowCursor] = - new QWSCursor(cur_up_arrow_bits, mcur_up_arrow_bits, 16, 16, 7, 0); - break; - - case Qt::CrossCursor: - systemCursorTable[Qt::CrossCursor] = - new QWSCursor(cur_cross_bits, mcur_cross_bits, 16, 16, 7, 7); - break; - - case Qt::IBeamCursor: - systemCursorTable[Qt::IBeamCursor] = - new QWSCursor(cur_ibeam_bits, mcur_ibeam_bits, 16, 16, 7, 7); - break; - - case Qt::SizeVerCursor: - systemCursorTable[Qt::SizeVerCursor] = - new QWSCursor(cur_ver_bits, mcur_ver_bits, 16, 16, 7, 7); - break; - - case Qt::SizeHorCursor: - systemCursorTable[Qt::SizeHorCursor] = - new QWSCursor(cur_hor_bits, mcur_hor_bits, 16, 16, 7, 7); - break; - - case Qt::SizeBDiagCursor: - systemCursorTable[Qt::SizeBDiagCursor] = - new QWSCursor(cur_bdiag_bits, mcur_bdiag_bits, 16, 16, 7, 7); - break; - - case Qt::SizeFDiagCursor: - systemCursorTable[Qt::SizeFDiagCursor] = - new QWSCursor(cur_fdiag_bits, mcur_fdiag_bits, 16, 16, 7, 7); - break; - - case Qt::BlankCursor: - systemCursorTable[Qt::BlankCursor] = - new QWSCursor(0, 0, 0, 0, 0, 0); - break; - - // 20x20 cursors - case Qt::ForbiddenCursor: - systemCursorTable[Qt::ForbiddenCursor] = - new QWSCursor(forbidden_bits, forbiddenm_bits, 20, 20, 10, 10); - break; - - // 32x32 cursors - case Qt::WaitCursor: - systemCursorTable[Qt::WaitCursor] = - new QWSCursor(wait_data_bits, wait_mask_bits, 32, 32, 15, 15); - break; - - case Qt::SplitVCursor: - systemCursorTable[Qt::SplitVCursor] = - new QWSCursor(vsplit_bits, vsplitm_bits, 32, 32, 15, 15); - break; - - case Qt::SplitHCursor: - systemCursorTable[Qt::SplitHCursor] = - new QWSCursor(hsplit_bits, hsplitm_bits, 32, 32, 15, 15); - break; - - case Qt::SizeAllCursor: - systemCursorTable[Qt::SizeAllCursor] = - new QWSCursor(size_all_data_bits, size_all_mask_bits, 32, 32, 15, 15); - break; - - case Qt::PointingHandCursor: - systemCursorTable[Qt::PointingHandCursor] = - new QWSCursor(phand_bits, phandm_bits, 32, 32, 0, 0); - break; - - case Qt::WhatsThisCursor: - systemCursorTable[Qt::WhatsThisCursor] = - new QWSCursor(whatsthis_bits, whatsthism_bits, 32, 32, 0, 0); - break; - case Qt::BusyCursor: - systemCursorTable[Qt::BusyCursor] = - new QWSCursor(busy_bits, busym_bits, 32, 32, 0, 0); - break; - - case Qt::OpenHandCursor: - systemCursorTable[Qt::OpenHandCursor] = - new QWSCursor(openhand_bits, openhandm_bits, 16, 16, 8, 8); - break; - case Qt::ClosedHandCursor: - systemCursorTable[Qt::ClosedHandCursor] = - new QWSCursor(closedhand_bits, closedhandm_bits, 16, 16, 8, 8); - break; - default: - qWarning("Unknown system cursor %d", id); - } -#endif -} - -QWSCursor *QWSCursor::systemCursor(int id) -{ - QWSCursor *cursor = 0; -#ifdef QT_NO_QWS_CURSOR - Q_UNUSED(id); -#else - if (id >= 0 && id <= Qt::LastCursor) { - if (!systemCursorTable[id]) - createSystemCursor(id); - cursor = systemCursorTable[id]; - } - - if (cursor == 0) { - if (!systemCursorTable[Qt::ArrowCursor]) - createSystemCursor(Qt::ArrowCursor); - cursor = systemCursorTable[Qt::ArrowCursor]; - } -#endif - return cursor; -} - -void QWSCursor::set(const uchar *data, const uchar *mask, - int width, int height, int hx, int hy) -{ -#ifdef QT_NO_QWS_CURSOR - Q_UNUSED(data); - Q_UNUSED(mask); - Q_UNUSED(width); - Q_UNUSED(height); - Q_UNUSED(hx); - Q_UNUSED(hy); -#else - hot.setX(hx); - hot.setY(hy); - - cursor = QImage(width,height, QImage::Format_Indexed8); - - if (!width || !height || !data || !mask || cursor.isNull()) - return; - - cursor.setColorCount(3); - cursor.setColor(0, 0xff000000); - cursor.setColor(1, 0xffffffff); - cursor.setColor(2, 0x00000000); - - int bytesPerLine = (width + 7) / 8; - int p = 0; - int d, m; - - int x = -1, w = 0; - - uchar *cursor_data = cursor.bits(); - int bpl = cursor.bytesPerLine(); - for (int i = 0; i < height; i++) - { - for (int j = 0; j < bytesPerLine; j++, data++, mask++) - { - for (int b = 0; b < 8 && j*8+b < width; b++) - { - d = *data & (1 << b); - m = *mask & (1 << b); - if (d && m) p = 0; - else if (!d && m) p = 1; - else p = 2; - cursor_data[j*8+b] = p; - - // calc region - if (x < 0 && m) - x = j*8+b; - else if (x >= 0 && !m) { - x = -1; - w = 0; - } - if (m) - w++; - } - } - if (x >= 0) { - x = -1; - w = 0; - } - cursor_data += bpl; - } - - if (qt_screencursor && qt_screencursor->supportsAlphaCursor()) - createDropShadow(5, 2); -#endif -} - -// now we're really silly -void QWSCursor::createDropShadow(int dropx, int dropy) -{ - //#### -#if 1 || defined(QT_NO_QWS_CURSOR) || defined(QT_NO_QWS_ALHPA_CURSOR) - Q_UNUSED(dropx); - Q_UNUSED(dropy); -#else - if (cursor.width() + dropx > 64 || cursor.height() + dropy > 64) - return; - - if (!cursor.hasAlphaBuffer()) { - cursor.setAlphaBuffer(true); - - const int nblur=4; - const int darkness=140; - - QImage drop(cursor.width()+dropx+nblur, cursor.height()+dropy+nblur, 8, 18); - drop.setColor(0, 0xff000000); // bg (black) - drop.setColor(1, 0xffffffff); // fg (white) - for (int i=0; i<16; i++) { - drop.setColor(2+i, (darkness*i/16)<<24); - } - drop.fill(2); // all trans - QImage drop2 = drop.copy(); - - int cp; - - // made solid shadow - for (int row = 0; row < cursor.height(); row++) { - for (int col = 0; col < cursor.width(); col++) { - cp = cursor.pixelIndex(col, row); - if (cp != 2) - drop.setPixel(col+dropx, row+dropy, 17); - } - } - - // blur shadow - for (int blur=0; blur<nblur; blur++) { - QImage& to((blur&1)?drop:drop2); - QImage& from((blur&1)?drop2:drop); - for (int row = 1; row < drop.height()-1; row++) { - for (int col = 1; col < drop.width()-1; col++) { - int t=0; - for (int dx=-1; dx<=1; dx++) { - for (int dy=-1; dy<=1; dy++) { - t += from.pixelIndex(col+dx,row+dy)-2; - } - } - to.setPixel(col,row,2+t/9); - } - } - } - - // copy cursor - for (int row = 0; row < cursor.height(); row++) { - for (int col = 0; col < cursor.width(); col++) { - cp = cursor.pixelIndex(col, row); - if (cp != 2) - drop.setPixel(col, row, cp); - } - } - - cursor = drop; - } -#endif -} - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qwscursor_qws.h b/src/gui/embedded/qwscursor_qws.h deleted file mode 100644 index 39464173c1..0000000000 --- a/src/gui/embedded/qwscursor_qws.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSCURSOR_QWS_H -#define QWSCURSOR_QWS_H - -#include <QtGui/qimage.h> -#include <QtGui/qregion.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QWSCursor -{ -public: - QWSCursor() {} - QWSCursor(const uchar *data, const uchar *mask, int width, int height, - int hotX, int hotY) - { set(data, mask, width, height, hotX, hotY); } - - void set(const uchar *data, const uchar *mask, - int width, int height, int hotX, int hotY); - - QPoint hotSpot() const { return hot; } - QImage &image() { return cursor; } - - static QWSCursor *systemCursor(int id); - -private: - static void createSystemCursor(int id); - void createDropShadow(int dropx, int dropy); - -private: - QPoint hot; - QImage cursor; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSCURSOR_QWS_H diff --git a/src/gui/embedded/qwsdisplay_qws.h b/src/gui/embedded/qwsdisplay_qws.h deleted file mode 100644 index 81acb425c9..0000000000 --- a/src/gui/embedded/qwsdisplay_qws.h +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSDISPLAY_QWS_H -#define QWSDISPLAY_QWS_H - -#include <QtCore/qobject.h> -#include <QtCore/qbytearray.h> -#include <QtGui/qregion.h> -#include <QtGui/qimage.h> -#include <QtGui/qwindowdefs.h> -#include <QtCore/qlist.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QWSEvent; -class QWSMouseEvent; -class QWSQCopMessageEvent; -class QVariant; -class QLock; - -class QWSWindowInfo -{ - -public: - - int winid; - unsigned int clientid; - QString name; - -}; - -#define QT_QWS_PROPERTY_CONVERTSELECTION 999 -#define QT_QWS_PROPERTY_WINDOWNAME 998 -#define QT_QWS_PROPERTY_MARKEDTEXT 997 - -class QWSDisplay; -extern Q_GUI_EXPORT QWSDisplay *qt_fbdpy; - -class Q_GUI_EXPORT QWSDisplay -{ -public: - QWSDisplay(); - ~QWSDisplay(); - - static QWSDisplay* instance() { return qt_fbdpy; } - - bool eventPending() const; - QWSEvent *getEvent(); -// QWSRegionManager *regionManager() const; - - uchar* frameBuffer() const; - int width() const; - int height() const; - int depth() const; - int pixmapDepth() const; - bool supportsDepth(int) const; - - uchar *sharedRam() const; - int sharedRamSize() const; - -#ifndef QT_NO_QWS_PROPERTIES - void addProperty(int winId, int property); - void setProperty(int winId, int property, int mode, const QByteArray &data); - void setProperty(int winId, int property, int mode, const char * data); - void removeProperty(int winId, int property); - bool getProperty(int winId, int property, char *&data, int &len); -#endif // QT_NO_QWS_PROPERTIES - - QList<QWSWindowInfo> windowList(); - int windowAt(const QPoint &); - - void setIdentity(const QString &appName); - void nameRegion(int winId, const QString& n, const QString &c); - void requestRegion(int winId, const QString &surfacekey, - const QByteArray &surfaceData, - const QRegion ®ion); - void repaintRegion(int winId, int windowFlags, bool opaque, QRegion); - void moveRegion(int winId, int dx, int dy); - void destroyRegion(int winId); - void requestFocus(int winId, bool get); - void setAltitude(int winId, int altitude, bool fixed = false); - void setOpacity(int winId, int opacity); - int takeId(); - void setSelectionOwner(int winId, const QTime &time); - void convertSelection(int winId, int selectionProperty, const QString &mimeTypes); - void defineCursor(int id, const QBitmap &curs, const QBitmap &mask, - int hotX, int hotY); - void destroyCursor(int id); - void selectCursor(QWidget *w, unsigned int id); - void setCursorPosition(int x, int y); - void grabMouse(QWidget *w, bool grab); - void grabKeyboard(QWidget *w, bool grab); - void playSoundFile(const QString&); - void registerChannel(const QString &channel); - void sendMessage(const QString &channel, const QString &msg, - const QByteArray &data); - void flushCommands(); -#ifndef QT_NO_QWS_INPUTMETHODS - void sendIMUpdate(int type, int winId, int widgetid); - void resetIM(); - void sendIMResponse(int winId, int property, const QVariant &result); - void sendIMMouseEvent(int index, bool isPress); -#endif - QWSQCopMessageEvent* waitForQCopResponse(); - void sendFontCommand(int type, const QByteArray &fontName); - - void setWindowCaption(QWidget *w, const QString &); - - // Lock display for access only by this process - static bool initLock(const QString &filename, bool create = false); - static bool grabbed(); - static void grab(); - static void grab(bool write); - static void ungrab(); - - static void setTransformation(int transformation, int screenNo = -1); - static void setRawMouseEventFilter(void (*filter)(QWSMouseEvent *)); - -private: - friend int qt_fork_qapplication(); - friend void qt_app_reinit( const QString& newAppName ); - friend class QApplication; - friend class QCopChannel; - friend class QWSEmbedWidget; - friend class QWSEmbedWidgetPrivate; - class Data; - friend class Data; - Data *d; - - friend class QWSMemorySurface; - friend class QWSOnScreenSurface; - friend class QWSDirectPainterSurface; - int getPropertyLen; - char *getPropertyData; - static QLock *lock; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSDISPLAY_QWS_H diff --git a/src/gui/embedded/qwsdisplay_qws_p.h b/src/gui/embedded/qwsdisplay_qws_p.h deleted file mode 100644 index a217a2af7c..0000000000 --- a/src/gui/embedded/qwsdisplay_qws_p.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSDISPLAY_QWS_P_H -#define QWSDISPLAY_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qwsdisplay_qws.h" -#include "qwssocket_qws.h" -#include "qwsevent_qws.h" -#include <private/qwssharedmemory_p.h> -#include "qwscommand_qws_p.h" -#include "qwslock_p.h" - -QT_BEGIN_NAMESPACE - -class QWSDisplay::Data -{ -public: - Data(QObject* parent, bool singleProcess = false); - ~Data(); - - void flush(); - - bool queueNotEmpty(); - QWSEvent *dequeue(); - QWSEvent *peek(); - - bool directServerConnection(); - void fillQueue(); -#ifndef QT_NO_QWS_MULTIPROCESS - void connectToPipe(); - void waitForConnection(); - void waitForPropertyReply(); - void waitForRegionAck(int winId); - void waitForRegionEvents(int winId, bool ungrabDisplay); - bool hasPendingRegionEvents() const; -#endif - void waitForCreation(); -#ifndef QT_NO_COP - void waitForQCopResponse(); -#endif - void init(); - void reinit( const QString& newAppName ); - void create(int n = 1); - - void flushCommands(); - void sendCommand(QWSCommand & cmd); - void sendSynchronousCommand(QWSCommand & cmd); - - QWSEvent *readMore(); - - int takeId(); - - void setMouseFilter(void (*filter)(QWSMouseEvent*)); - - //####public data members - -// QWSRegionManager *rgnMan; - uchar *sharedRam; -#ifndef QT_NO_QWS_MULTIPROCESS - QWSSharedMemory shm; -#endif - int sharedRamSize; - -#ifndef QT_NO_QWS_MULTIPROCESS - static QWSLock *clientLock; - - static bool lockClient(QWSLock::LockType, int timeout = -1); - static void unlockClient(QWSLock::LockType); - static bool waitClient(QWSLock::LockType, int timeout = -1); - static QWSLock* getClientLock(); -#endif // QT_NO_QWS_MULTIPROCESS - -private: -#ifndef QT_NO_QWS_MULTIPROCESS - QWSSocket *csocket; -#endif - QList<QWSEvent*> queue; - -#if 0 - void debugQueue() { - for (int i = 0; i < queue.size(); ++i) { - QWSEvent *e = queue.at(i); - qDebug( " ev %d type %d sl %d rl %d", i, e->type, e->simpleLen, e->rawLen); - } - } -#endif - - QWSConnectedEvent* connected_event; - QWSMouseEvent* mouse_event; - int region_events_count; - int mouse_state; - int mouse_winid; - QPoint region_offset; - int region_offset_window; -#ifndef QT_NO_COP - QWSQCopMessageEvent *qcop_response; -#endif - QWSEvent* current_event; - QList<int> unused_identifiers; -#ifdef QAPPLICATION_EXTRA_DEBUG - int mouse_event_count; -#endif - void (*mouseFilter)(QWSMouseEvent *); - - enum { VariableEvent=-1 }; - -}; - -QT_END_NAMESPACE - -#endif // QWSDISPLAY_QWS_P_H diff --git a/src/gui/embedded/qwsevent_qws.cpp b/src/gui/embedded/qwsevent_qws.cpp deleted file mode 100644 index bcecafed40..0000000000 --- a/src/gui/embedded/qwsevent_qws.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwsevent_qws.h" - -QT_BEGIN_NAMESPACE - -QWSEvent *QWSEvent::factory(int type) -{ - QWSEvent *event = 0; - switch (type) { - case QWSEvent::Connected: - event = new QWSConnectedEvent; - break; - case QWSEvent::MaxWindowRect: - event = new QWSMaxWindowRectEvent; - break; - case QWSEvent::Mouse: - event = new QWSMouseEvent; - break; - case QWSEvent::Focus: - event = new QWSFocusEvent; - break; - case QWSEvent::Key: - event = new QWSKeyEvent; - break; - case QWSEvent::Region: - event = new QWSRegionEvent; - break; - case QWSEvent::Creation: - event = new QWSCreationEvent; - break; -#ifndef QT_NO_QWS_PROPERTIES - case QWSEvent::PropertyNotify: - event = new QWSPropertyNotifyEvent; - break; - case QWSEvent::PropertyReply: - event = new QWSPropertyReplyEvent; - break; -#endif // QT_NO_QWS_PROPERTIES - case QWSEvent::SelectionClear: - event = new QWSSelectionClearEvent; - break; - case QWSEvent::SelectionRequest: - event = new QWSSelectionRequestEvent; - break; - case QWSEvent::SelectionNotify: - event = new QWSSelectionNotifyEvent; - break; -#ifndef QT_NO_COP - case QWSEvent::QCopMessage: - event = new QWSQCopMessageEvent; - break; -#endif - case QWSEvent::WindowOperation: - event = new QWSWindowOperationEvent; - break; - -#ifndef QT_NO_QWS_INPUTMETHODS - case QWSEvent::IMEvent: - event = new QWSIMEvent; - break; - case QWSEvent::IMQuery: - event = new QWSIMQueryEvent; - break; - case QWSEvent::IMInit: - event = new QWSIMInitEvent; - break; -#endif -#ifndef QT_NO_QWSEMBEDWIDGET - case QWSEvent::Embed: - event = new QWSEmbedEvent; - break; -#endif - case QWSEvent::Font: - event = new QWSFontEvent; - break; - case QWSEvent::ScreenTransformation: - event = new QWSScreenTransformationEvent; - break; - default: - qCritical("QWSEvent::factory() : Unknown event type %08x!", type); - } - return event; -} - -/*! - \class QWSEvent - \ingroup qws - - \brief The QWSEvent class encapsulates an event in Qt for Embedded Linux. - - When running a \l{Qt for Embedded Linux} application, it either runs as a - server or connects to an existing server. All system generated - events are passed to the server application which then propagates - the event to the appropriate client. - - Whenever the server receives an event, it queries its stack of - top-level windows to find the window containing the event's - position. Each window can identify the client application that - created it, and returns its ID to the server upon - request. Finally, the server forwards the event, encapsulated by - an instance of the QWSEvent class, to the appropriate client. - - \image qt-embedded-client.png - - The server communicates with the client applications over the UNIX - domain socket. You can retrieve direct access to all the events a - client receives from the server, by reimplementing QApplication's - \l {QApplication::}{qwsEventFilter()} function. - - QWSEvent provides the \l Type enum specifying the origin of the - event. Internally, each type is represented by a QWSEvent - subclass, e.g., \c QWSKeyEvent. - - \sa QWSServer, QWSClient, {Qt for Embedded Linux Architecture} -*/ - -/*! - \enum QWSEvent::Type - - This enum describes the origin of the event. - - \value NoEvent No event has occurred. - \value Connected An application has connected to the server. - \value Mouse A mouse button is pressed or released, or the mouse cursor is moved. - See also \l{Qt for Embedded Linux Pointer Handling}. - \value Focus A window has lost or received focus. - \value Key A key is pressed or released. See also \l{Qt for Embedded Linux Character Input}. - \value Region A region has changed. - \value Creation The server has created an ID, typically for a window. - \value PropertyNotify A property has changed. - \value PropertyReply The server is responding to a request for a property's value. - \value SelectionClear A selection is deleted. - \value SelectionRequest The server has queried for a selection. - \value SelectionNotify A new selection has been created. - \value MaxWindowRect The server has changed the maximum window for an application. - \value QCopMessage A new Qt Cop message has appeared. See also QCopChannel - \value WindowOperation A window operation, e.g. resizing, has occurred. - \value IMEvent An input method has been used to enter text for languages with - non-Latin alphabets. See also QWSInputMethod. - \value IMQuery An input method query for a specified property has occurred. - See also QWSInputMethod. - \value NEvent The number of events has changed. - \value Embed An event used internally to implement embedded windows. See also - QWSEmbedWidget. - \value ScreenTransformation An event used internally to notify the client processes - that the screen has changed for example, rotation, etc. - \omitvalue Font - \omitvalue IMInit -*/ - -/*! - \fn QWSMouseEvent *QWSEvent::asMouse() - \internal -*/ - -/*! - \fn int QWSEvent::window() - \internal -*/ - -/*! - \fn int QWSEvent::window() const - \internal -*/ - -/*! - \fn QWSEvent *QWSEvent::factory(int type) - \internal -*/ - -/*! - \fn QWSEvent::QWSEvent( int t, int len, char * ptr) - \internal -*/ - -QT_END_NAMESPACE diff --git a/src/gui/embedded/qwsevent_qws.h b/src/gui/embedded/qwsevent_qws.h deleted file mode 100644 index f439ee5843..0000000000 --- a/src/gui/embedded/qwsevent_qws.h +++ /dev/null @@ -1,459 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSEVENT_QWS_H -#define QWSEVENT_QWS_H - -#include <QtGui/qwsutils_qws.h> -#include <QtGui/qwsprotocolitem_qws.h> -#include <QtCore/qrect.h> -#include <QtGui/qregion.h> -#include <QtCore/qvector.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -struct QWSMouseEvent; - -struct QWSEvent : QWSProtocolItem { - - QWSEvent(int t, int len, char *ptr) : QWSProtocolItem(t,len,ptr) {} - - - - enum Type { - NoEvent, - Connected, - Mouse, - Focus, - Key, - Region, - Creation, - PropertyNotify, - PropertyReply, - SelectionClear, - SelectionRequest, - SelectionNotify, - MaxWindowRect, - QCopMessage, - WindowOperation, - IMEvent, - IMQuery, - IMInit, - Embed, - Font, - ScreenTransformation, - NEvent - }; - - QWSMouseEvent *asMouse() - { return type == Mouse ? reinterpret_cast<QWSMouseEvent*>(this) : 0; } - int window() { return *(reinterpret_cast<int*>(simpleDataPtr)); } - int window() const { return *(reinterpret_cast<int*>(simpleDataPtr)); } - static QWSEvent *factory(int type); -}; - - -//All events must start with windowID - -struct QWSConnectedEvent : QWSEvent { - QWSConnectedEvent() - : QWSEvent(QWSEvent::Connected, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - display = reinterpret_cast<char*>(rawDataPtr); - } - - struct SimpleData { - int window; - int len; - int clientId; - int servershmid; - } simpleData; - - char *display; -}; - -struct QWSMaxWindowRectEvent : QWSEvent { - QWSMaxWindowRectEvent() - : QWSEvent(MaxWindowRect, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) { } - struct SimpleData { - int window; - QRect rect; - } simpleData; -}; - -struct QWSMouseEvent : QWSEvent { - QWSMouseEvent() - : QWSEvent(QWSEvent::Mouse, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int window; - int x_root, y_root, state, delta; - int time; // milliseconds - } simpleData; -}; - -struct QWSFocusEvent : QWSEvent { - QWSFocusEvent() - : QWSEvent(QWSEvent::Focus, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) - { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); } - struct SimpleData { - int window; - uint get_focus:1; - } simpleData; -}; - -struct QWSKeyEvent: QWSEvent { - QWSKeyEvent() - : QWSEvent(QWSEvent::Key, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int window; - uint keycode; - Qt::KeyboardModifiers modifiers; - ushort unicode; - uint is_press:1; - uint is_auto_repeat:1; - } simpleData; -}; - - -struct QWSCreationEvent : QWSEvent { - QWSCreationEvent() - : QWSEvent(QWSEvent::Creation, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int objectid; - int count; - } simpleData; -}; - -#ifndef QT_NO_QWS_PROPERTIES -struct QWSPropertyNotifyEvent : QWSEvent { - QWSPropertyNotifyEvent() - : QWSEvent(QWSEvent::PropertyNotify, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - enum State { - PropertyNewValue, - PropertyDeleted - }; - struct SimpleData { - int window; - int property; - int state; - } simpleData; -}; -#endif - -struct QWSSelectionClearEvent : QWSEvent { - QWSSelectionClearEvent() - : QWSEvent(QWSEvent::SelectionClear, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int window; - } simpleData; -}; - -struct QWSSelectionRequestEvent : QWSEvent { - QWSSelectionRequestEvent() - : QWSEvent(QWSEvent::SelectionRequest, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int window; - int requestor; // window which wants the selection - int property; // property on requestor into which the selection should be stored, normally QWSProperty::PropSelection - int mimeTypes; // Value is stored in the property mimeType on the requestor window. This value may contain - // multiple mimeTypes separated by ;; where the order reflects the priority - } simpleData; -}; - -struct QWSSelectionNotifyEvent : QWSEvent { - QWSSelectionNotifyEvent() - : QWSEvent(QWSEvent::SelectionNotify, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - struct SimpleData { - int window; - int requestor; // the window which wanted the selection and to which this event is sent - int property; // property of requestor in which the data of the selection is stored - int mimeType; // a property on the requestor in which the mime type in which the selection is, is stored - } simpleData; -}; - -//complex events: - -struct QWSRegionEvent : QWSEvent { - QWSRegionEvent() - : QWSEvent(QWSEvent::Region, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) - { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); } - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - rectangles = reinterpret_cast<QRect*>(rawDataPtr); - } - - void setData(int winId, const QRegion ®ion, uint type) { - const QVector<QRect> rects = region.rects(); - setData(reinterpret_cast<const char*>(rects.constData()), - rects.size() * sizeof(QRect)); - simpleData.window = winId; - simpleData.nrectangles = rects.size(); - simpleData.type = type; -#ifdef QT_QWS_CLIENTBLIT - simpleData.id = 0; -#endif - } - - enum Type {Allocation -#ifdef QT_QWS_CLIENTBLIT - , DirectPaint -#endif - }; - struct SimpleData { - int window; - int nrectangles; -#ifdef QT_QWS_CLIENTBLIT - int id; -#endif - uint type:8; - } simpleData; - - QRect *rectangles; -}; - -#ifndef QT_NO_QWSEMBEDWIDGET -struct QWSEmbedEvent : QWSEvent -{ - QWSEmbedEvent() : QWSEvent(QWSEvent::Embed, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) - {} - - enum Type { StartEmbed = 1, StopEmbed = 2, Region = 4 }; - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - region.setRects(reinterpret_cast<const QRect *>(rawDataPtr), - simpleData.nrectangles); - } - - void setData(int winId, Type type, const QRegion ® = QRegion()) { - simpleData.window = winId; - simpleData.nrectangles = reg.rects().size(); - simpleData.type = type; - region = reg; - const QVector<QRect> rects = reg.rects(); - QWSEvent::setData(reinterpret_cast<const char*>(rects.data()), - rects.size() * sizeof(QRect)); - } - - struct SimpleData { - int window; - int nrectangles; - Type type; - } simpleData; - - QRegion region; -}; -#endif // QT_NO_QWSEMBEDWIDGET - -#ifndef QT_NO_QWS_PROPERTIES -struct QWSPropertyReplyEvent : QWSEvent { - QWSPropertyReplyEvent() - : QWSEvent(QWSEvent::PropertyReply, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - data = reinterpret_cast<char*>(rawDataPtr); - } - - struct SimpleData { - int window; - int property; - int len; - } simpleData; - char *data; -}; -#endif //QT_NO_QWS_PROPERTIES - -#ifndef QT_NO_COP -struct QWSQCopMessageEvent : QWSEvent { - QWSQCopMessageEvent() - : QWSEvent(QWSEvent::QCopMessage, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) - { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); } - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - char* p = rawDataPtr; - channel = QByteArray(p, simpleData.lchannel); - p += simpleData.lchannel; - message = QByteArray(p, simpleData.lmessage); - p += simpleData.lmessage; - data = QByteArray(p, simpleData.ldata); - } - - void setDataDirect(const char *d, int len) { - QWSEvent::setData(d, len, false); - deleteRaw = true; - } - - struct SimpleData { - bool is_response; - int lchannel; - int lmessage; - int ldata; - } simpleData; - - QByteArray channel; - QByteArray message; - QByteArray data; -}; - -#endif - -struct QWSWindowOperationEvent : QWSEvent { - QWSWindowOperationEvent() - : QWSEvent(WindowOperation, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) { } - - enum Operation { Show, Hide, ShowMaximized, ShowNormal, ShowMinimized, Close }; - struct SimpleData { - int window; - Operation op; - } simpleData; -}; - -#ifndef QT_NO_QWS_INPUTMETHODS - - -struct QWSIMEvent : QWSEvent { - QWSIMEvent() - : QWSEvent(IMEvent, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) - { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); } - - struct SimpleData { - int window; - int replaceFrom; - int replaceLength; - } simpleData; - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - streamingData = QByteArray::fromRawData(rawDataPtr, len); - } - QByteArray streamingData; -}; - - -struct QWSIMInitEvent : QWSEvent { - QWSIMInitEvent() - : QWSEvent(IMInit, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) - { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); } - - struct SimpleData { - int window; - int existence; - } simpleData; - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - streamingData = QByteArray::fromRawData(rawDataPtr, len); - } - QByteArray streamingData; -}; - - -struct QWSIMQueryEvent : QWSEvent { - QWSIMQueryEvent() - : QWSEvent(QWSEvent::IMQuery, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int window; - int property; - } simpleData; - -}; - -#endif - -struct QWSFontEvent : QWSEvent { - QWSFontEvent() - : QWSEvent(QWSEvent::Font, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - enum EventType { - FontRemoved - }; - - void setData(const char *d, int len, bool allocateMem = true) { - QWSEvent::setData(d, len, allocateMem); - fontName = QByteArray::fromRawData(rawDataPtr, len); - } - - struct SimpleData { - uchar type; - } simpleData; - QByteArray fontName; -}; - -struct QWSScreenTransformationEvent : QWSEvent { - QWSScreenTransformationEvent() - : QWSEvent(QWSEvent::ScreenTransformation, sizeof(simpleData), - reinterpret_cast<char*>(&simpleData)) {} - - struct SimpleData { - int screen; - int transformation; - } simpleData; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSEVENT_QWS_H diff --git a/src/gui/embedded/qwsmanager_qws.cpp b/src/gui/embedded/qwsmanager_qws.cpp deleted file mode 100644 index 5b5695264b..0000000000 --- a/src/gui/embedded/qwsmanager_qws.cpp +++ /dev/null @@ -1,537 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwsmanager_qws.h" - -#ifndef QT_NO_QWS_MANAGER - -#include "qdrawutil.h" -#include "qapplication.h" -#include "qstyle.h" -#include "qwidget.h" -#include "qmenu.h" -#include "qpainter.h" -#include "private/qpainter_p.h" -#include "qregion.h" -#include "qevent.h" -#include "qcursor.h" -#include "qwsdisplay_qws.h" -#include "qdesktopwidget.h" - -#include <private/qapplication_p.h> -#include <private/qwidget_p.h> -#include <private/qbackingstore_p.h> -#include <private/qwindowsurface_qws_p.h> -#include "qdecorationfactory_qws.h" - -#include "qlayout.h" - -#include "qwsmanager_p.h" - -#include <qdebug.h> - -QT_BEGIN_NAMESPACE - -QWidget *QWSManagerPrivate::active = 0; -QPoint QWSManagerPrivate::mousePos; - - -QWSManagerPrivate::QWSManagerPrivate() - : QObjectPrivate(), activeRegion(QDecoration::None), managed(0), popup(0), - previousRegionType(0), previousRegionRepainted(false), entireDecorationNeedsRepaint(false) -{ - cached_region.regionType = 0; -} - -QRegion &QWSManager::cachedRegion() -{ - return d_func()->cached_region.region; -} - -/*! - \class QWSManager - \ingroup qws - \internal -*/ - -/*! - -*/ -QWSManager::QWSManager(QWidget *w) - : QObject(*new QWSManagerPrivate, (QObject*)0) -{ - d_func()->managed = w; - -} - -QWSManager::~QWSManager() -{ - Q_D(QWSManager); -#ifndef QT_NO_MENU - if (d->popup) - delete d->popup; -#endif - if (d->managed == QWSManagerPrivate::active) - QWSManagerPrivate::active = 0; -} - -QWidget *QWSManager::widget() -{ - Q_D(QWSManager); - return d->managed; -} - -QWidget *QWSManager::grabbedMouse() -{ - return QWSManagerPrivate::active; -} - -QRegion QWSManager::region() -{ - Q_D(QWSManager); - return QApplication::qwsDecoration().region(d->managed, d->managed->geometry()); -} - -bool QWSManager::event(QEvent *e) -{ - if (QObject::event(e)) - return true; - - switch (e->type()) { - case QEvent::MouseMove: - mouseMoveEvent((QMouseEvent*)e); - break; - - case QEvent::MouseButtonPress: - mousePressEvent((QMouseEvent*)e); - break; - - case QEvent::MouseButtonRelease: - mouseReleaseEvent((QMouseEvent*)e); - break; - - case QEvent::MouseButtonDblClick: - mouseDoubleClickEvent((QMouseEvent*)e); - break; - - case QEvent::Paint: - paintEvent((QPaintEvent*)e); - break; - - default: - return false; - break; - } - - return true; -} - -void QWSManager::mousePressEvent(QMouseEvent *e) -{ - Q_D(QWSManager); - d->mousePos = e->globalPos(); - d->activeRegion = QApplication::qwsDecoration().regionAt(d->managed, d->mousePos); - if(d->cached_region.regionType) - d->previousRegionRepainted |= repaintRegion(d->cached_region.regionType, QDecoration::Pressed); - - if (d->activeRegion == QDecoration::Menu) { - QPoint pos = (QApplication::layoutDirection() == Qt::LeftToRight - ? d->managed->geometry().topLeft() - : d->managed->geometry().topRight()); - menu(pos); - } - if (d->activeRegion != QDecoration::None && - d->activeRegion != QDecoration::Menu) { - d->active = d->managed; - d->managed->grabMouse(); - } - if (d->activeRegion != QDecoration::None && - d->activeRegion != QDecoration::Close && - d->activeRegion != QDecoration::Minimize && - d->activeRegion != QDecoration::Menu) { - d->managed->raise(); - } - - if (e->button() == Qt::RightButton) { - menu(e->globalPos()); - } -} - -void QWSManager::mouseReleaseEvent(QMouseEvent *e) -{ - Q_D(QWSManager); - d->managed->releaseMouse(); - if (d->cached_region.regionType && d->previousRegionRepainted && QApplication::mouseButtons() == 0) { - bool doesHover = repaintRegion(d->cached_region.regionType, QDecoration::Hover); - if (!doesHover) { - repaintRegion(d->cached_region.regionType, QDecoration::Normal); - d->previousRegionRepainted = false; - } - } - - if (e->button() == Qt::LeftButton) { - //handleMove(); - int itm = QApplication::qwsDecoration().regionAt(d->managed, e->globalPos()); - int activatedItem = d->activeRegion; - d->activeRegion = QDecoration::None; - d->active = 0; - if (activatedItem == itm) - QApplication::qwsDecoration().regionClicked(d->managed, itm); - } else if (d->activeRegion == QDecoration::None) { - d->active = 0; - } -} - -void QWSManager::mouseDoubleClickEvent(QMouseEvent *e) -{ - Q_D(QWSManager); - if (e->button() == Qt::LeftButton) - QApplication::qwsDecoration().regionDoubleClicked(d->managed, - QApplication::qwsDecoration().regionAt(d->managed, e->globalPos())); -} - -static inline Qt::CursorShape regionToShape(int region) -{ - if (region == QDecoration::None) - return Qt::ArrowCursor; - - static const struct { - int region; - Qt::CursorShape shape; - } r2s[] = { - { QDecoration::TopLeft, Qt::SizeFDiagCursor }, - { QDecoration::Top, Qt::SizeVerCursor}, - { QDecoration::TopRight, Qt::SizeBDiagCursor}, - { QDecoration::Left, Qt::SizeHorCursor}, - { QDecoration::Right, Qt::SizeHorCursor}, - { QDecoration::BottomLeft, Qt::SizeBDiagCursor}, - { QDecoration::Bottom, Qt::SizeVerCursor}, - { QDecoration::BottomRight, Qt::SizeFDiagCursor}, - { QDecoration::None, Qt::ArrowCursor} - }; - - int i = 0; - while (region != r2s[i].region && r2s[i].region) - ++i; - return r2s[i].shape; -} - -void QWSManager::mouseMoveEvent(QMouseEvent *e) -{ - Q_D(QWSManager); - if (d->newCachedRegion(e->globalPos())) { - if(d->previousRegionType && d->previousRegionRepainted) - repaintRegion(d->previousRegionType, QDecoration::Normal); - if(d->cached_region.regionType) { - d->previousRegionRepainted = repaintRegion(d->cached_region.regionType, QDecoration::Hover); - } - } - - -#ifndef QT_NO_CURSOR - if (d->managed->minimumSize() != d->managed->maximumSize()) { - QWSDisplay *qwsd = QApplication::desktop()->qwsDisplay(); - qwsd->selectCursor(d->managed, regionToShape(d->cachedRegionAt())); - } -#endif //QT_NO_CURSOR - - if (d->activeRegion) - handleMove(e->globalPos()); -} - -void QWSManager::handleMove(QPoint g) -{ - Q_D(QWSManager); - - // don't allow dragging to where the user probably cannot click! - QApplicationPrivate *ap = QApplicationPrivate::instance(); - const QRect maxWindowRect = ap->maxWindowRect(qt_screen); - if (maxWindowRect.isValid()) { - if (g.x() < maxWindowRect.x()) - g.setX(maxWindowRect.x()); - if (g.y() < maxWindowRect.y()) - g.setY(maxWindowRect.y()); - if (g.x() > maxWindowRect.right()) - g.setX(maxWindowRect.right()); - if (g.y() > maxWindowRect.bottom()) - g.setY(maxWindowRect.bottom()); - } - - if (g == d->mousePos) - return; - - if ( d->managed->isMaximized() ) - return; - - int x = d->managed->geometry().x(); - int y = d->managed->geometry().y(); - int w = d->managed->width(); - int h = d->managed->height(); - - QRect geom(d->managed->geometry()); - - QPoint delta = g - d->mousePos; - d->mousePos = g; - - if (d->activeRegion == QDecoration::Title) { - geom = QRect(x + delta.x(), y + delta.y(), w, h); - } else { - bool keepTop = true; - bool keepLeft = true; - switch (d->activeRegion) { - case QDecoration::Top: - geom.setTop(geom.top() + delta.y()); - keepTop = false; - break; - case QDecoration::Bottom: - geom.setBottom(geom.bottom() + delta.y()); - keepTop = true; - break; - case QDecoration::Left: - geom.setLeft(geom.left() + delta.x()); - keepLeft = false; - break; - case QDecoration::Right: - geom.setRight(geom.right() + delta.x()); - keepLeft = true; - break; - case QDecoration::TopRight: - geom.setTopRight(geom.topRight() + delta); - keepLeft = true; - keepTop = false; - break; - case QDecoration::TopLeft: - geom.setTopLeft(geom.topLeft() + delta); - keepLeft = false; - keepTop = false; - break; - case QDecoration::BottomLeft: - geom.setBottomLeft(geom.bottomLeft() + delta); - keepLeft = false; - keepTop = true; - break; - case QDecoration::BottomRight: - geom.setBottomRight(geom.bottomRight() + delta); - keepLeft = true; - keepTop = true; - break; - default: - return; - } - - QSize newSize = QLayout::closestAcceptableSize(d->managed, geom.size()); - - int dx = newSize.width() - geom.width(); - int dy = newSize.height() - geom.height(); - - if (keepTop) { - geom.setBottom(geom.bottom() + dy); - d->mousePos.ry() += dy; - } else { - geom.setTop(geom.top() - dy); - d->mousePos.ry() -= dy; - } - if (keepLeft) { - geom.setRight(geom.right() + dx); - d->mousePos.rx() += dx; - } else { - geom.setLeft(geom.left() - dx); - d->mousePos.rx() -= dx; - } - } - if (geom != d->managed->geometry()) { - QApplication::sendPostedEvents(); - d->managed->setGeometry(geom); - } -} - -void QWSManager::paintEvent(QPaintEvent *) -{ - Q_D(QWSManager); - d->dirtyRegion(QDecoration::All, QDecoration::Normal); -} - -void QWSManagerPrivate::dirtyRegion(int decorationRegion, - QDecoration::DecorationState state, - const QRegion &clip) -{ - QTLWExtra *topextra = managed->d_func()->extra->topextra; - QWidgetBackingStore *bs = topextra->backingStore.data(); - const bool pendingUpdateRequest = bs->isDirty(); - - if (decorationRegion == QDecoration::All) { - if (clip.isEmpty()) - entireDecorationNeedsRepaint = true; - dirtyRegions.clear(); - dirtyStates.clear(); - } - int i = dirtyRegions.indexOf(decorationRegion); - if (i >= 0) { - dirtyRegions.removeAt(i); - dirtyStates.removeAt(i); - } - - dirtyRegions.append(decorationRegion); - dirtyStates.append(state); - if (!entireDecorationNeedsRepaint) - dirtyClip += clip; - - if (!pendingUpdateRequest) - QApplication::postEvent(managed, new QEvent(QEvent::UpdateRequest), Qt::LowEventPriority); -} - -void QWSManagerPrivate::clearDirtyRegions() -{ - dirtyRegions.clear(); - dirtyStates.clear(); - dirtyClip = QRegion(); - entireDecorationNeedsRepaint = false; -} - -bool QWSManager::repaintRegion(int decorationRegion, QDecoration::DecorationState state) -{ - Q_D(QWSManager); - - d->dirtyRegion(decorationRegion, state); - return true; -} - -void QWSManager::menu(const QPoint &pos) -{ -#ifdef QT_NO_MENU - Q_UNUSED(pos); -#else - Q_D(QWSManager); - if (d->popup) - delete d->popup; - - // Basic window operation menu - d->popup = new QMenu(); - QApplication::qwsDecoration().buildSysMenu(d->managed, d->popup); - connect(d->popup, SIGNAL(triggered(QAction*)), SLOT(menuTriggered(QAction*))); - - d->popup->popup(pos); - d->activeRegion = QDecoration::None; -#endif // QT_NO_MENU -} - -void QWSManager::menuTriggered(QAction *action) -{ -#ifdef QT_NO_MENU - Q_UNUSED(action); -#else - Q_D(QWSManager); - QApplication::qwsDecoration().menuTriggered(d->managed, action); - d->popup->deleteLater(); - d->popup = 0; -#endif -} - -void QWSManager::startMove() -{ - Q_D(QWSManager); - d->mousePos = QCursor::pos(); - d->activeRegion = QDecoration::Title; - d->active = d->managed; - d->managed->grabMouse(); -} - -void QWSManager::startResize() -{ - Q_D(QWSManager); - d->activeRegion = QDecoration::BottomRight; - d->active = d->managed; - d->managed->grabMouse(); -} - -void QWSManager::maximize() -{ - Q_D(QWSManager); - // find out how much space the decoration needs - const int screen = QApplication::desktop()->screenNumber(d->managed); - const QRect desk = QApplication::desktop()->availableGeometry(screen); - QRect dummy(0, 0, 1, 1); - QRect nr; - QRegion r = QApplication::qwsDecoration().region(d->managed, dummy); - if (r.isEmpty()) { - nr = desk; - } else { - r += dummy; // make sure we get the full window region in case of 0 width borders - QRect rect = r.boundingRect(); - nr = QRect(desk.x()-rect.x(), desk.y()-rect.y(), - desk.width() - (rect.width()==1 ? 0 : rect.width()-1), // ==1 -> dummy - desk.height() - (rect.height()==1 ? 0 : rect.height()-1)); - } - d->managed->setGeometry(nr); -} - -bool QWSManagerPrivate::newCachedRegion(const QPoint &pos) -{ - // Check if anything has changed that would affect the region caching - if (managed->windowFlags() == cached_region.windowFlags - && managed->geometry() == cached_region.windowGeometry - && cached_region.region.contains(pos)) - return false; - - // Update the cached region - int reg = QApplication::qwsDecoration().regionAt(managed, pos); - if (QWidget::mouseGrabber()) - reg = QDecoration::None; - - previousRegionType = cached_region.regionType; - cached_region.regionType = reg; - cached_region.region = QApplication::qwsDecoration().region(managed, managed->geometry(), - reg); - // Make room for borders around the widget, even if the decoration doesn't have a frame. - if (reg && !(reg & int(QDecoration::Borders))) { - cached_region.region -= QApplication::qwsDecoration().region(managed, managed->geometry(), QDecoration::Borders); - } - cached_region.windowFlags = managed->windowFlags(); - cached_region.windowGeometry = managed->geometry(); -// QRect rec = cached_region.region.boundingRect(); -// qDebug("Updated cached region: 0x%04x (%d, %d) (%d, %d, %d, %d)", -// reg, pos.x(), pos.y(), rec.x(), rec.y(), rec.right(), rec.bottom()); - return true; -} - -QT_END_NAMESPACE - -#endif //QT_NO_QWS_MANAGER diff --git a/src/gui/embedded/qwsmanager_qws.h b/src/gui/embedded/qwsmanager_qws.h deleted file mode 100644 index 5a33bfd038..0000000000 --- a/src/gui/embedded/qwsmanager_qws.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSMANAGER_QWS_H -#define QWSMANAGER_QWS_H - -#include <QtGui/qpixmap.h> -#include <QtCore/qobject.h> -#include <QtGui/qdecoration_qws.h> -#include <QtGui/qevent.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_QWS_MANAGER - -class QAction; -class QPixmap; -class QWidget; -class QPopupMenu; -class QRegion; -class QMouseEvent; -class QWSManagerPrivate; - -class Q_GUI_EXPORT QWSManager : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QWSManager) -public: - explicit QWSManager(QWidget *); - ~QWSManager(); - - static QDecoration *newDefaultDecoration(); - - QWidget *widget(); - static QWidget *grabbedMouse(); - void maximize(); - void startMove(); - void startResize(); - - QRegion region(); - QRegion &cachedRegion(); - -protected Q_SLOTS: - void menuTriggered(QAction *action); - -protected: - void handleMove(QPoint g); - - virtual bool event(QEvent *e); - virtual void mouseMoveEvent(QMouseEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void paintEvent(QPaintEvent *); - bool repaintRegion(int region, QDecoration::DecorationState state); - - void menu(const QPoint &); - -private: - friend class QWidget; - friend class QETWidget; - friend class QWidgetPrivate; - friend class QApplication; - friend class QApplicationPrivate; - friend class QWidgetBackingStore; - friend class QWSWindowSurface; - friend class QGLDrawable; -}; - -QT_BEGIN_INCLUDE_NAMESPACE -#include <QtGui/qdecorationdefault_qws.h> -QT_END_INCLUDE_NAMESPACE - -#endif // QT_NO_QWS_MANAGER - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSMANAGER_QWS_H diff --git a/src/gui/embedded/qwsproperty_qws.cpp b/src/gui/embedded/qwsproperty_qws.cpp deleted file mode 100644 index b5ce4c52be..0000000000 --- a/src/gui/embedded/qwsproperty_qws.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwsproperty_qws.h" - -#ifndef QT_NO_QWS_PROPERTIES -#include "qwscommand_qws_p.h" -#include "qwindowsystem_qws.h" -#include "qhash.h" -#include "qalgorithms.h" -#include "qbytearray.h" - -#include <stdio.h> - -QT_BEGIN_NAMESPACE - -class QWSPropertyManager::Data { -public: - QByteArray find(int winId, int property) - { - return properties.value(winId).value(property); - } - - typedef QHash<int, QHash<int, QByteArray> > PropertyHash; - PropertyHash properties; -}; - -/********************************************************************* - * - * Class: QWSPropertyManager - * - *********************************************************************/ - -QWSPropertyManager::QWSPropertyManager() -{ - d = new Data; -} - -QWSPropertyManager::~QWSPropertyManager() -{ - delete d; -} - -bool QWSPropertyManager::setProperty(int winId, int property, int mode, const char *data, int len) -{ - QHash<int, QByteArray> props = d->properties.value(winId); - QHash<int, QByteArray>::iterator it = props.find(property); - if (it == props.end()) - return false; - - switch (mode) { - case PropReplace: - d->properties[winId][property] = QByteArray(data, len); - break; - case PropAppend: - d->properties[winId][property].append(data); - break; - case PropPrepend: - d->properties[winId][property].prepend(data); - break; - } - return true; -} - -bool QWSPropertyManager::hasProperty(int winId, int property) -{ - return d->properties.value(winId).contains(property); -} - -bool QWSPropertyManager::removeProperty(int winId, int property) -{ - QWSPropertyManager::Data::PropertyHash::iterator it = d->properties.find(winId); - if (it == d->properties.end()) - return false; - return d->properties[winId].remove( property ); -} - -bool QWSPropertyManager::addProperty(int winId, int property) -{ - if( !d->properties[winId].contains(property) ) - d->properties[winId][property] = QByteArray(); // only add if it doesn't exist - return true; -} - -bool QWSPropertyManager::getProperty(int winId, int property, const char *&data, int &len) -{ - QHash<int, QByteArray> props = d->properties.value(winId); - QHash<int, QByteArray>::iterator it = props.find(property); - if (it == props.end()) { - data = 0; - len = -1; - return false; - } - data = it.value().constData(); - len = it.value().length(); - - return true; -} - -bool QWSPropertyManager::removeProperties(int winId) -{ - return d->properties.remove(winId); -} - -QT_END_NAMESPACE - -#endif //QT_NO_QWS_PROPERTIES diff --git a/src/gui/embedded/qwsproperty_qws.h b/src/gui/embedded/qwsproperty_qws.h deleted file mode 100644 index 4a779e0905..0000000000 --- a/src/gui/embedded/qwsproperty_qws.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSPROPERTY_QWS_H -#define QWSPROPERTY_QWS_H - -#include <QtCore/qglobal.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -/********************************************************************* - * - * Class: QWSPropertyManager - * - *********************************************************************/ - -#ifndef QT_NO_QWS_PROPERTIES - -class QWSPropertyManager -{ -public: - enum Mode { - PropReplace = 0, - PropPrepend, - PropAppend - }; - - // pre-defined properties - enum Atom { - PropSelection = 0 - }; - - QWSPropertyManager(); - ~QWSPropertyManager(); - - bool setProperty(int winId, int property, int mode, const char *data, int len); - bool hasProperty(int winId, int property); - bool removeProperty(int winId, int property); - bool addProperty(int winId, int property); - bool getProperty(int winId, int property, const char *&data, int &len); - bool removeProperties(int winId); - -private: - class Data; - Data* d; -}; - -#endif // QT_NO_QWS_PROPERTIES - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSPROPERTY_QWS_H diff --git a/src/gui/embedded/qwsprotocolitem_qws.h b/src/gui/embedded/qwsprotocolitem_qws.h deleted file mode 100644 index 0afd4c2a02..0000000000 --- a/src/gui/embedded/qwsprotocolitem_qws.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSPROTOCOLITEM_QWS_H -#define QWSPROTOCOLITEM_QWS_H - -/********************************************************************* - * - * QWSCommand base class - only use derived classes from that - * - *********************************************************************/ - -#include <QtCore/qglobal.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QIODevice; - -struct QWSProtocolItem -{ - // ctor - dtor - QWSProtocolItem(int t, int len, char *ptr) : type(t), - simpleLen(len), rawLen(-1), deleteRaw(false), simpleDataPtr(ptr), - rawDataPtr(0), bytesRead(0) { } - virtual ~QWSProtocolItem(); - - // data - int type; - int simpleLen; - int rawLen; - bool deleteRaw; - - // functions -#ifndef QT_NO_QWS_MULTIPROCESS - void write(QIODevice *s); - bool read(QIODevice *s); -#endif - void copyFrom(const QWSProtocolItem *item); - - virtual void setData(const char *data, int len, bool allocateMem = true); - - char *simpleDataPtr; - char *rawDataPtr; - // temp variables - int bytesRead; -}; - -// This should probably be a method on QWSProtocolItem, but this way avoids -// changing the API of this apparently public header -// size = (int)type + (int)rawLenSize + simpleLen + rawLen -#define QWS_PROTOCOL_ITEM_SIZE( item ) \ - (2 * sizeof(int)) + ((item).simpleDataPtr ? (item).simpleLen : 0) + ((item).rawDataPtr ? (item).rawLen : 0) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSPROTOCOLITEM_QWS_H diff --git a/src/gui/embedded/qwssocket_qws.cpp b/src/gui/embedded/qwssocket_qws.cpp deleted file mode 100644 index 463af6c336..0000000000 --- a/src/gui/embedded/qwssocket_qws.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" -#include "qwssocket_qws.h" - -#ifndef QT_NO_QWS_MULTIPROCESS - -#include <fcntl.h> -#include <netdb.h> -#include <errno.h> -#include <stdio.h> -#include <sys/file.h> -#include <sys/time.h> -#include <sys/un.h> - -#ifdef __MIPSEL__ -# ifndef SOCK_DGRAM -# define SOCK_DGRAM 1 -# endif -# ifndef SOCK_STREAM -# define SOCK_STREAM 2 -# endif -#endif - -#if defined(Q_OS_SOLARIS) || defined (QT_LINUXBASE) -// uff-da apparently Solaris doesn't have the SUN_LEN macro, here is -// an implementation of it... -# ifndef SUN_LEN -# define SUN_LEN(su) \ - sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path) -# endif - -// nor the POSIX names of UNIX domain sockets *sigh* -# ifndef AF_LOCAL -# define AF_LOCAL AF_UNIX -# endif -# ifndef PF_LOCAL -# define PF_LOCAL PF_UNIX -# endif -#endif // Q_OS_SOLARIS || QT_LINUXBASE - -QT_BEGIN_NAMESPACE - -/*********************************************************************** - * - * QWSSocket - * - **********************************************************************/ -QWSSocket::QWSSocket(QObject *parent) - : QWS_SOCK_BASE(parent) -{ -#ifndef QT_NO_SXE - QObject::connect( this, SIGNAL(stateChanged(SocketState)), - this, SLOT(forwardStateChange(SocketState))); -#endif -} - -QWSSocket::~QWSSocket() -{ -} - -#ifndef QT_NO_SXE -QString QWSSocket::errorString() -{ - switch (QUnixSocket::error()) { - case NoError: - return QString(); - case InvalidPath: - case NonexistentPath: - return QLatin1String("Bad path"); // NO_TR - default: - return QLatin1String("Bad socket"); // NO TR - } -} - -void QWSSocket::forwardStateChange(QUnixSocket::SocketState st ) -{ - switch ( st ) - { - case ConnectedState: - emit connected(); - break; - case ClosingState: - break; - case UnconnectedState: - emit disconnected(); - break; - default: - // nothing - break; - } - if ( QUnixSocket::error() != NoError ) - emit error((QAbstractSocket::SocketError)0); -} -#endif - -bool QWSSocket::connectToLocalFile(const QString &file) -{ -#ifndef QT_NO_SXE - bool result = QUnixSocket::connect( file.toLocal8Bit() ); - if ( !result ) - { - perror( "QWSSocketAuth::connectToLocalFile could not connect:" ); - emit error(QAbstractSocket::ConnectionRefusedError); - return false; - } - return true; -#else - // create socket - int s = ::socket(PF_LOCAL, SOCK_STREAM, 0); - - // connect to socket - struct sockaddr_un a; - memset(&a, 0, sizeof(a)); - a.sun_family = PF_LOCAL; - strncpy(a.sun_path, file.toLocal8Bit().constData(), sizeof(a.sun_path) - 1); - int r = ::connect(s, (struct sockaddr*)&a, SUN_LEN(&a)); - if (r == 0) { - setSocketDescriptor(s); - } else { - perror("QWSSocket::connectToLocalFile could not connect:"); - ::close(s); - emit error(ConnectionRefusedError); - return false; - } -#endif - return true; -} - - -/*********************************************************************** - * - * QWSServerSocket - * - **********************************************************************/ -QWSServerSocket::QWSServerSocket(const QString& file, QObject *parent) -#ifndef QT_NO_SXE - : QUnixSocketServer(parent) -#else - : QTcpServer(parent) -#endif -{ - init(file); -} - -void QWSServerSocket::init(const QString &file) -{ -#ifndef QT_NO_SXE - QByteArray fn = file.toLocal8Bit(); - bool result = QUnixSocketServer::listen( fn ); - if ( !result ) - { - QUnixSocketServer::ServerError err = serverError(); - switch ( err ) - { - case InvalidPath: - qWarning("QWSServerSocket:: invalid path %s", qPrintable(file)); - break; - case ResourceError: - case BindError: - case ListenError: - qWarning("QWSServerSocket:: could not listen on path %s", qPrintable(file)); - break; - default: - break; - } - } -#else - int backlog = 16; //##### - -// create socket - int s = ::socket(PF_LOCAL, SOCK_STREAM, 0); - if (s == -1) { - perror("QWSServerSocket::init"); - qWarning("QWSServerSocket: unable to create socket."); - return; - } - - QByteArray fn = file.toLocal8Bit(); - unlink(fn.constData()); // doesn't have to succeed - - // bind socket - struct sockaddr_un a; - memset(&a, 0, sizeof(a)); - a.sun_family = PF_LOCAL; - strncpy(a.sun_path, fn.constData(), sizeof(a.sun_path) - 1); - int r = ::bind(s, (struct sockaddr*)&a, SUN_LEN(&a)); - if (r < 0) { - perror("QWSServerSocket::init"); - qWarning("QWSServerSocket: could not bind to file %s", fn.constData()); - ::close(s); - return; - } - - if (chmod(fn.constData(), 0600) < 0) { - perror("QWSServerSocket::init"); - qWarning("Could not set permissions of %s", fn.constData()); - ::close(s); - return; - } - - // listen - if (::listen(s, backlog) == 0) { - if (!setSocketDescriptor(s)) - qWarning( "QWSServerSocket could not set descriptor %d : %s", s, errorString().toLatin1().constData()); - } else { - perror("QWSServerSocket::init"); - qWarning("QWSServerSocket: could not listen to file %s", fn.constData()); - ::close(s); - } -#endif -} - -QWSServerSocket::~QWSServerSocket() -{ -} - -#ifndef QT_NO_SXE - -void QWSServerSocket::incomingConnection(int socketDescriptor) -{ - inboundConnections.append( socketDescriptor ); - emit newConnection(); -} - - -QWSSocket *QWSServerSocket::nextPendingConnection() -{ - QMutexLocker locker( &ssmx ); - if ( inboundConnections.count() == 0 ) - return 0; - QWSSocket *s = new QWSSocket(); - s->setSocketDescriptor( inboundConnections.takeFirst() ); - return s; -} - -#endif // QT_NO_SXE - -QT_END_NAMESPACE - -#endif //QT_NO_QWS_MULTIPROCESS diff --git a/src/gui/embedded/qwssocket_qws.h b/src/gui/embedded/qwssocket_qws.h deleted file mode 100644 index 4f90564bdb..0000000000 --- a/src/gui/embedded/qwssocket_qws.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSSOCKET_QWS_H -#define QWSSOCKET_QWS_H - -#include <QtCore/qconfig.h> -#include <QtGui/qwsutils_qws.h> - -#ifndef QT_NO_QWS_MULTIPROCESS - -#ifndef QT_NO_SXE -#include <QtCore/qmutex.h> -#include <QtGui/private/qunixsocketserver_p.h> -#include <QtGui/private/qunixsocket_p.h> -#else -#include <QtNetwork/qtcpsocket.h> -#include <QtNetwork/qtcpserver.h> -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - - -class QWSSocket : public QWS_SOCK_BASE -{ - Q_OBJECT -public: - explicit QWSSocket(QObject *parent=0); - ~QWSSocket(); - - bool connectToLocalFile(const QString &file); - -#ifndef QT_NO_SXE - QString errorString(); -Q_SIGNALS: - void connected(); - void disconnected(); - void error(QAbstractSocket::SocketError); -private Q_SLOTS: - void forwardStateChange(SocketState); -#endif - -private: - Q_DISABLE_COPY(QWSSocket) -}; - - -class QWSServerSocket : public QWS_SOCK_SERVER_BASE -{ - Q_OBJECT -public: - QWSServerSocket(const QString& file, QObject *parent=0); - ~QWSServerSocket(); - -#ifndef QT_NO_SXE - QWSSocket *nextPendingConnection(); -Q_SIGNALS: - void newConnection(); -protected: - void incomingConnection(int socketDescriptor); -private: - QMutex ssmx; - QList<int> inboundConnections; -#endif - -private: - Q_DISABLE_COPY(QWSServerSocket) - - void init(const QString &file); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_QWS_MULTIPROCESS - -#endif // QWSSOCKET_QWS_H diff --git a/src/gui/embedded/qwsutils_qws.h b/src/gui/embedded/qwsutils_qws.h deleted file mode 100644 index c1295082fd..0000000000 --- a/src/gui/embedded/qwsutils_qws.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSUTILS_QWS_H -#define QWSUTILS_QWS_H - -#include <QtCore/QIODevice> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_SXE -#define QWS_SOCK_BASE QUnixSocket -#define QWS_SOCK_SERVER_BASE QUnixSocketServer -class QUnixSocket; -class QUnixSocketServer; -#else -#define QWS_SOCK_BASE QTcpSocket -#define QWS_SOCK_SERVER_BASE QTcpServer -class QTcpSocket; -class QTcpServer; -#endif -class QWSSocket; -class QWSServerSocket; - -/******************************************************************** - * - * Convenient socket functions - * - ********************************************************************/ -#ifndef QT_NO_QWS_MULTIPROCESS -inline int qws_read_uint(QIODevice *socket) -{ - if (!socket || socket->bytesAvailable() < (int)sizeof(int)) - return -1; - - int i; - socket->read(reinterpret_cast<char*>(&i), sizeof(i)); - - return i; -} - -inline void qws_write_uint(QIODevice *socket, int i) -{ - if (!socket) - return; - - socket->write(reinterpret_cast<char*>(&i), sizeof(i)); -} - -#endif // QT_NO_QWS_MULTIPROCESS - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QWSUTILS_QWS_H diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp deleted file mode 100644 index 3c1907089d..0000000000 --- a/src/gui/image/qpixmap_qws.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qpixmap.h> -#include <qapplication.h> -#include <qwidget.h> -#include <qdesktopwidget.h> -#include <qscreen_qws.h> -#include <qwsdisplay_qws.h> -#include <private/qdrawhelper_p.h> -#include <private/qpixmap_raster_p.h> - - -QT_BEGIN_NAMESPACE - -QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) -{ - QWidget *widget = QWidget::find(window); - if (!widget) - return QPixmap(); - - QRect grabRect = widget->frameGeometry(); - if (!widget->isWindow()) - grabRect.translate(widget->parentWidget()->mapToGlobal(QPoint())); - if (w < 0) - w = widget->width() - x; - if (h < 0) - h = widget->height() - y; - grabRect &= QRect(x, y, w, h).translated(widget->mapToGlobal(QPoint())); - - QScreen *screen = qt_screen; - QDesktopWidget *desktop = QApplication::desktop(); - if (!desktop) - return QPixmap(); - if (desktop->numScreens() > 1) { - const int screenNo = desktop->screenNumber(widget); - if (screenNo != -1) - screen = qt_screen->subScreens().at(screenNo); - grabRect = grabRect.translated(-screen->region().boundingRect().topLeft()); - } - - if (screen->pixelFormat() == QImage::Format_Invalid) { - qWarning("QPixmap::grabWindow(): Unable to copy pixels from framebuffer"); - return QPixmap(); - } - - if (screen->isTransformed()) { - const QSize screenSize(screen->width(), screen->height()); - grabRect = screen->mapToDevice(grabRect, screenSize); - } - - QWSDisplay::grab(false); - QPixmap pixmap; - QImage img(screen->base(), - screen->deviceWidth(), screen->deviceHeight(), - screen->linestep(), screen->pixelFormat()); - img = img.copy(grabRect); - QWSDisplay::ungrab(); - - if (screen->isTransformed()) { - QMatrix matrix; - switch (screen->transformOrientation()) { - case 1: matrix.rotate(90); break; - case 2: matrix.rotate(180); break; - case 3: matrix.rotate(270); break; - default: break; - } - img = img.transformed(matrix); - } - - if (screen->pixelType() == QScreen::BGRPixel) - img = img.rgbSwapped(); - - return QPixmap::fromImage(img); -} - -QRgb* QPixmap::clut() const -{ - if (data && data->classId() == QPixmapData::RasterClass) { - const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); - return d->image.colorTable().data(); - } - - return 0; -} - -int QPixmap::numCols() const -{ - return colorCount(); -} - -int QPixmap::colorCount() const -{ - if (data && data->classId() == QPixmapData::RasterClass) { - const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); - return d->image.colorCount(); - } - - return 0; -} - -const uchar* QPixmap::qwsBits() const -{ - if (data && data->classId() == QPixmapData::RasterClass) { - const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); - return d->image.bits(); - } - - return 0; -} - -int QPixmap::qwsBytesPerLine() const -{ - if (data && data->classId() == QPixmapData::RasterClass) { - const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); - return d->image.bytesPerLine(); - } - - return 0; -} - -QT_END_NAMESPACE diff --git a/src/gui/inputmethod/qwsinputcontext_qws.cpp b/src/gui/inputmethod/qwsinputcontext_qws.cpp deleted file mode 100644 index d8d64f28d4..0000000000 --- a/src/gui/inputmethod/qwsinputcontext_qws.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwsinputcontext_p.h" -#include "qinputcontext_p.h" -#include "qwsdisplay_qws.h" -#include "qwsevent_qws.h" -#include "private/qwscommand_qws_p.h" -#include "qwindowsystem_qws.h" -#include "qevent.h" -#include "qtextformat.h" - -#include <qbuffer.h> - -#include <qdebug.h> - -#ifndef QT_NO_QWS_INPUTMETHODS - -QT_BEGIN_NAMESPACE - -static QWidget* activeWidget = 0; - -//#define EXTRA_DEBUG - -QWSInputContext::QWSInputContext(QObject *parent) - :QInputContext(parent) -{ -} - -void QWSInputContext::reset() -{ - QPaintDevice::qwsDisplay()->resetIM(); -} - - -void QWSInputContext::setFocusWidget( QWidget *w ) -{ - QWidget *oldFocus = focusWidget(); - if (oldFocus == w) - return; - - if (w) { - QWSInputContext::updateImeStatus(w, true); - } else { - if (oldFocus) - QWSInputContext::updateImeStatus(oldFocus, false); - } - - if (oldFocus) { - QWidget *tlw = oldFocus->window(); - int winid = tlw->internalWinId(); - - int widgetid = oldFocus->internalWinId(); - QPaintDevice::qwsDisplay()->sendIMUpdate(QWSInputMethod::FocusOut, winid, widgetid); - } - - QInputContext::setFocusWidget(w); - - if (!w) - return; - - QWidget *tlw = w->window(); - int winid = tlw->winId(); - - int widgetid = w->winId(); - QPaintDevice::qwsDisplay()->sendIMUpdate(QWSInputMethod::FocusIn, winid, widgetid); - - //setfocus ??? - - update(); -} - - -void QWSInputContext::widgetDestroyed(QWidget *w) -{ - if (w == QT_PREPEND_NAMESPACE(activeWidget)) - QT_PREPEND_NAMESPACE(activeWidget) = 0; - QInputContext::widgetDestroyed(w); -} - -void QWSInputContext::update() -{ - QWidget *w = focusWidget(); - if (!w) - return; - - QWidget *tlw = w->window(); - int winid = tlw->winId(); - - int widgetid = w->winId(); - QPaintDevice::qwsDisplay()->sendIMUpdate(QWSInputMethod::Update, winid, widgetid); - -} - -void QWSInputContext::mouseHandler( int x, QMouseEvent *event) -{ - if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) - QPaintDevice::qwsDisplay()->sendIMMouseEvent( x, event->type() == QEvent::MouseButtonPress ); -} - -QWidget *QWSInputContext::activeWidget() -{ - return QT_PREPEND_NAMESPACE(activeWidget); -} - - -bool QWSInputContext::isComposing() const -{ - return QT_PREPEND_NAMESPACE(activeWidget) != 0; -} - -bool QWSInputContext::translateIMQueryEvent(QWidget *w, const QWSIMQueryEvent *e) -{ - Qt::InputMethodQuery type = static_cast<Qt::InputMethodQuery>(e->simpleData.property); - QVariant result = w->inputMethodQuery(type); - QWidget *tlw = w->window(); - int winId = tlw->winId(); - - if ( type == Qt::ImMicroFocus ) { - // translate to relative to tlw - QRect mf = result.toRect(); - mf.moveTopLeft(w->mapTo(tlw,mf.topLeft())); - result = mf; - } - - QPaintDevice::qwsDisplay()->sendIMResponse(winId, e->simpleData.property, result); - - return false; -} - -bool QWSInputContext::translateIMInitEvent(const QWSIMInitEvent *e) -{ - Q_UNUSED(e); - qDebug("### QWSInputContext::translateIMInitEvent not implemented ###"); - return false; -} - -bool QWSInputContext::translateIMEvent(QWidget *w, const QWSIMEvent *e) -{ - QDataStream stream(e->streamingData); - QString preedit; - QString commit; - - stream >> preedit; - stream >> commit; - - if (preedit.isEmpty() && QT_PREPEND_NAMESPACE(activeWidget)) - w = QT_PREPEND_NAMESPACE(activeWidget); - - QInputContext *qic = w->inputContext(); - if (!qic) - return false; - - QList<QInputMethodEvent::Attribute> attrs; - - - while (!stream.atEnd()) { - int type = -1; - int start = -1; - int length = -1; - QVariant data; - stream >> type >> start >> length >> data; - if (stream.status() != QDataStream::Ok) { - qWarning("corrupted QWSIMEvent"); - //qic->reset(); //??? - return false; - } - if (type == QInputMethodEvent::TextFormat) - data = qic->standardFormat(static_cast<QInputContext::StandardFormat>(data.toInt())); - attrs << QInputMethodEvent::Attribute(static_cast<QInputMethodEvent::AttributeType>(type), start, length, data); - } -#ifdef EXTRA_DEBUG - qDebug() << "preedit" << preedit << "len" << preedit.length() <<"commit" << commit << "len" << commit.length() - << "n attr" << attrs.count(); -#endif - - if (preedit.isEmpty()) - QT_PREPEND_NAMESPACE(activeWidget) = 0; - else - QT_PREPEND_NAMESPACE(activeWidget) = w; - - - QInputMethodEvent ime(preedit, attrs); - if (!commit.isEmpty() || e->simpleData.replaceLength > 0) - ime.setCommitString(commit, e->simpleData.replaceFrom, e->simpleData.replaceLength); - - - extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_qws.cpp - qt_sendSpontaneousEvent(w, &ime); - - return true; -} - -Q_GUI_EXPORT void (*qt_qws_inputMethodStatusChanged)(QWidget*) = 0; - -void QWSInputContext::updateImeStatus(QWidget *w, bool hasFocus) -{ - Q_UNUSED(hasFocus); - - if (!w || !qt_qws_inputMethodStatusChanged) - return; - qt_qws_inputMethodStatusChanged(w); -} - - -QT_END_NAMESPACE - -#endif // QT_NO_QWS_INPUTMETHODS diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 798d6aaf6f..0e95a6aabf 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -238,11 +238,11 @@ qpa { kernel/qapplication_qpa.cpp \ kernel/qclipboard_qpa.cpp \ kernel/qcursor_qpa.cpp \ - kernel/qdnd_qws.cpp \ + kernel/qdnd_qpa.cpp \ kernel/qdesktopwidget_qpa.cpp \ kernel/qgenericpluginfactory_qpa.cpp \ kernel/qgenericplugin_qpa.cpp \ - kernel/qkeymapper_qws.cpp \ + kernel/qkeymapper_qpa.cpp \ kernel/qwidget_qpa.cpp \ kernel/qeventdispatcher_qpa.cpp \ kernel/qwindowsysteminterface_qpa.cpp \ diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp deleted file mode 100644 index 642d3e6afc..0000000000 --- a/src/gui/kernel/qapplication_qws.cpp +++ /dev/null @@ -1,3797 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglobal.h" -#include "qlibrary.h" -#include "qcursor.h" -#include "qapplication.h" -#include "private/qapplication_p.h" -#include "qwidget.h" -#include "qbitarray.h" -#include "qpainter.h" -#include "qpixmapcache.h" -#include "qdatetime.h" -#include "qtextcodec.h" -#include "qdatastream.h" -#include "qbuffer.h" -#include "qsocketnotifier.h" -#include "qsessionmanager.h" -#include "qclipboard.h" -#include "qbitmap.h" -#include "qwssocket_qws.h" -#include "qtransportauth_qws.h" -#include "private/qtransportauth_qws_p.h" -#include "qwsevent_qws.h" -#include "private/qwscommand_qws_p.h" -#include "qwsproperty_qws.h" -#include "qscreen_qws.h" -#include "qscreenproxy_qws.h" -#include "qcopchannel_qws.h" -#include "private/qlock_p.h" -#include "private/qwslock_p.h" -//#include "qmemorymanager_qws.h" -#include "qwsmanager_qws.h" -//#include "qwsregionmanager_qws.h" -#include "qwindowsystem_qws.h" -#include "private/qwindowsystem_p.h" -#include "qdecorationfactory_qws.h" - -#include "qwsdisplay_qws.h" -#include "private/qwsdisplay_qws_p.h" -#include "private/qwsinputcontext_p.h" -#include "qfile.h" -#include "qhash.h" -#include "qdesktopwidget.h" -#include "qcolormap.h" -#include "private/qcursor_p.h" -#include "qsettings.h" -#include "qdebug.h" -#include "qeventdispatcher_qws_p.h" -#if !defined(QT_NO_GLIB) -# include "qeventdispatcher_glib_qws_p.h" -#endif - - -#include "private/qwidget_p.h" -#include "private/qbackingstore_p.h" -#include "private/qwindowsurface_qws_p.h" -#include "private/qfont_p.h" - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> -#include <errno.h> -#include <fcntl.h> -#ifdef Q_OS_VXWORKS -# include <sys/times.h> -#else -# include <sys/time.h> -#endif -#include <sys/stat.h> -#include <sys/types.h> - -#include <qvfbhdr.h> - -#ifndef QT_NO_QWS_MULTIPROCESS -#ifdef QT_NO_QSHM -#include <sys/ipc.h> -#include <sys/shm.h> -#ifndef Q_OS_DARWIN -# include <sys/sem.h> -#endif -#include <sys/socket.h> -#else -#include "private/qwssharedmemory_p.h" -#endif -#endif - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_DIRECTPAINTER -class QDirectPainter; -extern void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type); -#ifndef QT_NO_QWSEMBEDWIDGET -extern void qt_directpainter_embedevent(QDirectPainter *dp, - const QWSEmbedEvent *e); -#endif -#endif // QT_NO_DIRECTPAINTER - -const int qwsSharedRamSize = 1 * 1024; // misc data, written by server, read by clients - -extern QApplication::Type qt_appType; -extern QDesktopWidget *qt_desktopWidget; - -//these used to be environment variables, they are initialized from -//environment variables in - -bool qws_savefonts = false; -bool qws_screen_is_interlaced=false; //### should be detected -bool qws_shared_memory = false; -bool qws_sw_cursor = true; -bool qws_accel = true; // ### never set -QByteArray qws_display_spec(":0"); -Q_GUI_EXPORT int qws_display_id = 0; -Q_GUI_EXPORT int qws_client_id = 0; -QWidget *qt_pressGrab = 0; -QWidget *qt_mouseGrb = 0; -int *qt_last_x = 0; -int *qt_last_y = 0; - -static int mouse_x_root = -1; -static int mouse_y_root = -1; -static int mouse_state = 0; -static int mouse_double_click_distance = 5; - -int qt_servershmid = -1; - -bool qws_overrideCursor = false; -#ifndef QT_NO_QWS_MANAGER - -extern Q_GUI_EXPORT QWSServer *qwsServer; - -static QDecoration *qws_decoration = 0; -#endif - -#if defined(QT_DEBUG) -/* -extern "C" void dumpmem(const char* m) -{ - static int init=0; - static int prev=0; - FILE* f = fopen("/proc/meminfo","r"); - // char line[100]; - int total=0,used=0,free=0,shared=0,buffers=0,cached=0; - fscanf(f,"%*[^M]Mem: %d %d %d %d %d %d",&total,&used,&free,&shared,&buffers,&cached); - used -= buffers + cached; - if (!init) { - init=used; - } else { - printf("%40s: %+8d = %8d\n",m,used-init-prev,used-init); - prev = used-init; - } - fclose(f); -} -*/ -#endif - -// Get the name of the directory where Qt for Embedded Linux temporary data should -// live. -QString qws_dataDir() -{ - static QString result; - if (!result.isEmpty()) - return result; - result = QT_VFB_DATADIR(qws_display_id); - QByteArray dataDir = result.toLocal8Bit(); - -#if defined(Q_OS_INTEGRITY) - /* ensure filesystem is ready before starting requests */ - WaitForFileSystemInitialization(); -#endif - - if (QT_MKDIR(dataDir, 0700)) { - if (errno != EEXIST) { - qFatal("Cannot create Qt for Embedded Linux data directory: %s", dataDir.constData()); - } - } - - QT_STATBUF buf; - if (QT_LSTAT(dataDir, &buf)) - qFatal("stat failed for Qt for Embedded Linux data directory: %s", dataDir.constData()); - - if (!S_ISDIR(buf.st_mode)) - qFatal("%s is not a directory", dataDir.constData()); - -#if !defined(Q_OS_INTEGRITY) && !defined(Q_OS_VXWORKS) - if (buf.st_uid != getuid()) - qFatal("Qt for Embedded Linux data directory is not owned by user %d", getuid()); - - if ((buf.st_mode & 0677) != 0600) - qFatal("Qt for Embedded Linux data directory has incorrect permissions: %s", dataDir.constData()); -#endif - - result.append("/"); - return result; -} - -// Get the filename of the pipe Qt for Embedded Linux uses for server/client comms -Q_GUI_EXPORT QString qws_qtePipeFilename() -{ - qws_dataDir(); - return QTE_PIPE(qws_display_id); -} - -static void setMaxWindowRect(const QRect &rect) -{ - const QList<QScreen*> subScreens = qt_screen->subScreens(); - QScreen *screen = qt_screen; - int screenNo = 0; - for (int i = 0; i < subScreens.size(); ++i) { - if (subScreens.at(i)->region().contains(rect)) { - screen = subScreens.at(i); - screenNo = i; - break; - } - } - - QApplicationPrivate *ap = QApplicationPrivate::instance(); - ap->setMaxWindowRect(screen, screenNo, rect); -} - -void QApplicationPrivate::setMaxWindowRect(const QScreen *screen, int screenNo, - const QRect &rect) -{ - if (maxWindowRects.value(screen) == rect) - return; - - maxWindowRects[screen] = rect; - - // Re-resize any maximized windows - QWidgetList l = QApplication::topLevelWidgets(); - for (int i = 0; i < l.size(); ++i) { - QWidget *w = l.at(i); - QScreen *s = w->d_func()->getScreen(); - if (w->isMaximized() && s == screen) - w->d_func()->setMaxWindowState_helper(); - } - - if ( qt_desktopWidget ) // XXX workaround crash - emit QApplication::desktop()->workAreaResized(screenNo); -} - -#ifndef QT_NO_QWS_DYNAMICSCREENTRANSFORMATION - -typedef void (*TransformFunc)(QScreen *, int); -#ifndef QT_NO_QWS_TRANSFORMED -extern "C" void qws_setScreenTransformation(QScreen *, int); -#endif -static TransformFunc getTransformationFunction() -{ - static TransformFunc func = 0; - - if (!func) { -#ifdef QT_NO_QWS_TRANSFORMED -# ifndef QT_NO_LIBRARY - // symbol is not built into the library, search for the plugin - const QStringList paths = QApplication::libraryPaths(); - foreach (const QString &path, paths) { - const QString file = path + QLatin1String("/gfxdrivers/libqgfxtransformed"); - func = (TransformFunc)QLibrary::resolve(file, - "qws_setScreenTransformation"); - if (func) - break; - } -# endif -#else - func = qws_setScreenTransformation; -#endif - if (!func) - func = (TransformFunc)-1; - } - - if (func == (TransformFunc)-1) - return 0; - - return func; -} - -static void setScreenTransformation(int screenNo, int transformation) -{ - QScreen *screen = QScreen::instance(); - const QList<QScreen*> subScreens = screen->subScreens(); - - if (screenNo == -1) - screenNo = 0; - - if (screenNo == -1 && !subScreens.isEmpty()) - screenNo = 0; - - if (subScreens.isEmpty() && screenNo == 0) { - // nothing - } else if (screenNo < 0 || screenNo >= subScreens.size()) { - qWarning("setScreenTransformation: invalid screen %i", screenNo); - return; - } - - if (screenNo < subScreens.size()) - screen = subScreens.at(screenNo); - - QApplicationPrivate *ap = QApplicationPrivate::instance(); - ap->setScreenTransformation(screen, screenNo, transformation); -} - -void QApplicationPrivate::setScreenTransformation(QScreen *screen, - int screenNo, - int transformation) -{ - QScreen *transformed = screen; - - while (transformed->classId() == QScreen::ProxyClass) - transformed = static_cast<QProxyScreen*>(transformed)->screen(); - - if (transformed->classId() != QScreen::TransformedClass) - return; - - TransformFunc setScreenTransformation = getTransformationFunction(); - if (!setScreenTransformation) - return; - - setScreenTransformation(transformed, transformation); - - // need to re-configure() proxies bottom-up - if (screen->classId() == QScreen::ProxyClass) { - QList<QProxyScreen*> proxies; - QScreen *s = screen; - - do { - QProxyScreen *proxy = static_cast<QProxyScreen*>(s); - proxies.append(proxy); - s = proxy->screen(); - } while (s->classId() == QScreen::ProxyClass); - - do { - QProxyScreen *proxy = proxies.takeLast(); - proxy->setScreen(proxy->screen()); // triggers configure() - } while (!proxies.isEmpty()); - } - - if (qt_desktopWidget) { // XXX workaround crash for early screen transform events - QDesktopWidget *desktop = QApplication::desktop(); - - emit desktop->resized(screenNo); - if (maxWindowRect(screen).isEmpty()) // not explicitly set - emit desktop->workAreaResized(screenNo); - } - - QWSServer *server = QWSServer::instance(); - if (server) { - server->updateWindowRegions(); - QRegion r = screen->region(); - server->refresh(r); - } - - // make sure maximized and fullscreen windows are updated - QWidgetList list = QApplication::topLevelWidgets(); - for (int i = list.size() - 1; i >= 0; --i) { - QWidget *w = list.at(i); - if (w->isFullScreen()) - w->d_func()->setFullScreenSize_helper(); - else if (w->isMaximized()) - w->d_func()->setMaxWindowState_helper(); - } -} - -#endif // QT_NO_QWS_DYNAMICSCREENTRANSFORMATION - -/***************************************************************************** - Internal variables and functions - *****************************************************************************/ - - -static QString appName; // application name -static const char *appFont = 0; // application font -static const char *appBGCol = 0; // application bg color -static const char *appFGCol = 0; // application fg color -static const char *appBTNCol = 0; // application btn color -static const char *mwGeometry = 0; // main widget geometry -static const char *mwTitle = 0; // main widget title -//static bool mwIconic = false; // main widget iconified - -static bool app_do_modal = false; // modal mode -Q_GUI_EXPORT QWSDisplay *qt_fbdpy = 0; // QWS `display' -QLock *QWSDisplay::lock = 0; - -static int mouseButtonPressed = 0; // last mouse button pressed -static int mouseButtonPressTime = 0; // when was a button pressed -static short mouseXPos, mouseYPos; // mouse position in act window - -extern QWidgetList *qt_modal_stack; // stack of modal widgets - -static QWidget *popupButtonFocus = 0; -static QWidget *popupOfPopupButtonFocus = 0; -static bool popupCloseDownMode = false; -static bool popupGrabOk; -static QPointer<QWidget> *mouseInWidget = 0; -QPointer<QWidget> qt_last_mouse_receiver = 0; - -static bool sm_blockUserInput = false; // session management - -QWidget *qt_button_down = 0; // widget got last button-down -WId qt_last_cursor = 0xffffffff; // Was -1, but WIds are unsigned - -class QWSMouseEvent; -class QWSKeyEvent; - -class QETWidget : public QWidget // event translator widget -{ -public: - bool translateMouseEvent(const QWSMouseEvent *, int oldstate); - bool translateKeyEvent(const QWSKeyEvent *, bool grab); - bool translateRegionEvent(const QWSRegionEvent *); -#ifndef QT_NO_QWSEMBEDWIDGET - void translateEmbedEvent(const QWSEmbedEvent *event); -#endif - bool translateWheelEvent(const QWSMouseEvent *me); - void repaintDecoration(QRegion r, bool post); - void updateRegion(); - - bool raiseOnClick() - { - // With limited windowmanagement/taskbar/etc., raising big windows - // (eg. spreadsheet) over the top of everything else (eg. calculator) - // is just annoying. - return !isMaximized() && !isFullScreen(); - } -}; - -void QApplicationPrivate::createEventDispatcher() -{ - Q_Q(QApplication); -#if !defined(QT_NO_GLIB) - if (qgetenv("QT_NO_GLIB").isEmpty() && QEventDispatcherGlib::versionSupported()) - eventDispatcher = (q->type() != QApplication::Tty - ? new QWSEventDispatcherGlib(q) - : new QEventDispatcherGlib(q)); - else -#endif - eventDispatcher = (q->type() != QApplication::Tty - ? new QEventDispatcherQWS(q) - : new QEventDispatcherUNIX(q)); -} - -// Single-process stuff. This should maybe move into qwindowsystem_qws.cpp - -static bool qws_single_process; -static QList<QWSEvent*> incoming; -static QList<QWSCommand*> outgoing; - -void qt_client_enqueue(const QWSEvent *event) -{ - QWSEvent *copy = QWSEvent::factory(event->type); - copy->copyFrom(event); - incoming.append(copy); -} - -QList<QWSCommand*> *qt_get_server_queue() -{ - return &outgoing; -} - -void qt_server_enqueue(const QWSCommand *command) -{ - QWSCommand *copy = QWSCommand::factory(command->type); - QT_TRY { - copy->copyFrom(command); - outgoing.append(copy); - } QT_CATCH(...) { - delete copy; - QT_RETHROW; - } -} - -QWSDisplay::Data::Data(QObject* parent, bool singleProcess) -{ -#ifdef QT_NO_QWS_MULTIPROCESS - Q_UNUSED(parent); - Q_UNUSED(singleProcess); -#else - if (singleProcess) - csocket = 0; - else { - csocket = new QWSSocket(parent); - QObject::connect(csocket, SIGNAL(disconnected()), - qApp, SLOT(quit())); - } - clientLock = 0; -#endif - init(); -} - -QWSDisplay::Data::~Data() -{ -// delete rgnMan; rgnMan = 0; -// delete memorymanager; memorymanager = 0; - qt_screen->disconnect(); - delete qt_screen; qt_screen = 0; -#ifndef QT_NO_QWS_CURSOR - delete qt_screencursor; qt_screencursor = 0; -#endif -#ifndef QT_NO_QWS_MULTIPROCESS - shm.detach(); - if (csocket) { - QWSCommand shutdownCmd(QWSCommand::Shutdown, 0, 0); - shutdownCmd.write(csocket); - csocket->flush(); // may be pending QCop message, eg. - delete csocket; - } - delete clientLock; - clientLock = 0; -#endif - delete connected_event; - delete mouse_event; - delete current_event; - qDeleteAll(queue); -#ifndef QT_NO_COP - delete qcop_response; -#endif -} - -#ifndef QT_NO_QWS_MULTIPROCESS -bool QWSDisplay::Data::lockClient(QWSLock::LockType type, int timeout) -{ - return !clientLock || clientLock->lock(type, timeout); -} - -void QWSDisplay::Data::unlockClient(QWSLock::LockType type) -{ - if (clientLock) clientLock->unlock(type); -} - -bool QWSDisplay::Data::waitClient(QWSLock::LockType type, int timeout) -{ - return !clientLock || clientLock->wait(type, timeout); -} - -QWSLock* QWSDisplay::Data::getClientLock() -{ - return clientLock; -} -#endif // QT_NO_QWS_MULTIPROCESS - -void QWSDisplay::Data::flush() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) { - csocket->waitForReadyRead(0); - csocket->flush(); - } -#endif -} - -#if 0 -void QWSDisplay::Data::debugQueue() { - for (int i = 0; i < queue.size(); ++i) { - QWSEvent *e = queue.at(i); - qDebug( " ev %d type %d sl %d rl %d", i, e->type, e->simpleLen, e->rawLen); - } -} -#endif - -bool QWSDisplay::Data::queueNotEmpty() -{ - return mouse_event/*||region_event*/||queue.count() > 0; -} -QWSEvent* QWSDisplay::Data::dequeue() -{ - QWSEvent *r=0; - if (queue.count()) { - r = queue.first(); - queue.removeFirst(); - if (r->type == QWSEvent::Region) - region_events_count--; - } else if (mouse_event) { - r = mouse_event; - mouse_event = 0; -#ifdef QAPPLICATION_EXTRA_DEBUG - mouse_event_count = 0; -#endif - } - return r; -} - -QWSEvent* QWSDisplay::Data::peek() -{ - return queue.first(); -} - -bool QWSDisplay::Data::directServerConnection() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - return csocket == 0; -#else - return true; -#endif -} - -void QWSDisplay::Data::create(int n) -{ - QWSCreateCommand cmd(n); - sendCommand(cmd); -} - -void QWSDisplay::Data::flushCommands() -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) - csocket->flush(); -#endif -} - -void QWSDisplay::Data::sendCommand(QWSCommand & cmd) -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) - cmd.write(csocket); - else -#endif - qt_server_enqueue(&cmd); -} - -void QWSDisplay::Data::sendSynchronousCommand(QWSCommand & cmd) -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) { - lockClient(QWSLock::Communication); - cmd.write(csocket); - bool ok = true; - while (csocket->bytesToWrite() > 0) { - if (!csocket->waitForBytesWritten(-1)) { - qCritical("QWSDisplay::Data::sendSynchronousCommand: %s", - qPrintable(csocket->errorString())); - ok = false; - break; - } - } - if (ok) - waitClient(QWSLock::Communication); - } else -#endif - qt_server_enqueue(&cmd); -} - -int QWSDisplay::Data::takeId() -{ - int unusedIdCount = unused_identifiers.count(); - if (unusedIdCount <= 10) - create(15); - if (unusedIdCount == 0) { - create(1); // Make sure we have an incoming id to wait for, just in case we're recursive - waitForCreation(); - } - - return unused_identifiers.takeFirst(); -} - -void QWSDisplay::Data::setMouseFilter(void (*filter)(QWSMouseEvent*)) -{ - mouseFilter = filter; -} - -#ifndef QT_NO_QWS_MULTIPROCESS - -QWSLock* QWSDisplay::Data::clientLock = 0; - -void Q_GUI_EXPORT qt_app_reinit( const QString& newAppName ) -{ - qt_fbdpy->d->reinit( newAppName ); -} - -#endif // QT_NO_QWS_MULTIPROCESS - -class QDesktopWidget; - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSDisplay::Data::reinit( const QString& newAppName ) -{ - Q_ASSERT(csocket); - - delete connected_event; - connected_event = 0; - region_events_count = 0; -// region_ack = 0; - delete mouse_event; - mouse_event = 0; -// region_event = 0; - region_offset_window = 0; -#ifndef QT_NO_COP - delete qcop_response; - qcop_response = 0; -#endif - delete current_event; - current_event = 0; -#ifdef QAPPLICATION_EXTRA_DEBUG - mouse_event_count = 0; -#endif - mouseFilter = 0; - - qt_desktopWidget = 0; - delete QWSDisplay::Data::clientLock; - QWSDisplay::Data::clientLock = 0; - - QString pipe = qws_qtePipeFilename(); - - // QWS client - // Cleanup all cached ids - unused_identifiers.clear(); - delete csocket; - - appName = newAppName; - qApp->setObjectName( appName ); - - csocket = new QWSSocket(); - QObject::connect(csocket, SIGNAL(disconnected()), - qApp, SLOT(quit())); - csocket->connectToLocalFile(pipe); - - QWSDisplay::Data::clientLock = new QWSLock(); - - QWSIdentifyCommand cmd; - cmd.setId(appName, QWSDisplay::Data::clientLock->id()); - -#ifndef QT_NO_SXE - QTransportAuth *a = QTransportAuth::getInstance(); - QTransportAuth::Data *d = a->connectTransport( - QTransportAuth::UnixStreamSock | - QTransportAuth::Trusted, - csocket->socketDescriptor()); - QAuthDevice *ad = a->authBuf( d, csocket ); - ad->setClient( csocket ); - - cmd.write(ad); -#else - cmd.write(csocket); -#endif - - // wait for connect confirmation - waitForConnection(); - - qws_client_id = connected_event->simpleData.clientId; - - if (!QWSDisplay::initLock(pipe, false)) - qFatal("Cannot get display lock"); - - if (shm.attach(connected_event->simpleData.servershmid)) { - sharedRam = static_cast<uchar *>(shm.address()); - QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData()); - if (s) - sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData())); - } else { - perror("QWSDisplay::Data::init"); - qFatal("Client can't attach to main ram memory."); - } - - qApp->desktop(); - - // We wait for creation mainly so that we can process important - // initialization events such as MaxWindowRect that are sent - // before object id creation. Waiting here avoids later window - // resizing since we have the MWR before windows are displayed. - waitForCreation(); - - sharedRamSize -= sizeof(int); - qt_last_x = reinterpret_cast<int *>(sharedRam + sharedRamSize); - sharedRamSize -= sizeof(int); - qt_last_y = reinterpret_cast<int *>(sharedRam + sharedRamSize); - -#ifndef QT_NO_COP - QCopChannel::reregisterAll(); -#endif - csocket->flush(); -} -#endif - -void QWSDisplay::Data::init() -{ - connected_event = 0; - region_events_count = 0; -// region_ack = 0; - mouse_event = 0; - mouse_state = -1; - mouse_winid = 0; -// region_event = 0; - region_offset_window = 0; -#ifndef QT_NO_COP - qcop_response = 0; -#endif - current_event = 0; -#ifdef QAPPLICATION_EXTRA_DEBUG - mouse_event_count = 0; -#endif - mouseFilter = 0; - - QString pipe = qws_qtePipeFilename(); - - sharedRamSize = qwsSharedRamSize; - -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) { - // QWS client - - connectToPipe(); - - QWSDisplay::Data::clientLock = new QWSLock(); - - QWSIdentifyCommand cmd; - cmd.setId(appName, QWSDisplay::Data::clientLock->id()); -#ifndef QT_NO_SXE - QTransportAuth *a = QTransportAuth::getInstance(); - QTransportAuth::Data *d = a->connectTransport( - QTransportAuth::UnixStreamSock | - QTransportAuth::Trusted, - csocket->socketDescriptor()); - QAuthDevice *ad = a->authBuf( d, csocket ); - ad->setClient( csocket ); - cmd.write(ad); -#else - cmd.write(csocket); -#endif - - // create(30); // not necessary, server will send ids anyway - waitForConnection(); - - qws_client_id = connected_event->simpleData.clientId; - - // now we want to get the exact display spec to use if we haven't - // specified anything. - if (qws_display_spec.at(0) == ':') - qws_display_spec = connected_event->display; - - if (!QWSDisplay::initLock(pipe, false)) - qFatal("Cannot get display lock"); - - if (shm.attach(connected_event->simpleData.servershmid)) { - sharedRam = static_cast<uchar *>(shm.address()); - QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData()); - if (s) - sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData())); - } else { - perror("QWSDisplay::Data::init"); - qFatal("Client can't attach to main ram memory."); - } - - // We wait for creation mainly so that we can process important - // initialization events such as MaxWindowRect that are sent - // before object id creation. Waiting here avoids later window - // resizing since we have the MWR before windows are displayed. - waitForCreation(); - } else -#endif - { - create(30); - - // QWS server - if (!QWSDisplay::initLock(pipe, true)) - qFatal("Cannot get display lock"); - - QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData()); - if (s) - sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData())); - -#ifndef QT_NO_QWS_MULTIPROCESS - - if (!shm.create(sharedRamSize)) { - perror("Cannot create main ram shared memory\n"); - qFatal("Unable to allocate %d bytes of shared memory", sharedRamSize); - } - qt_servershmid = shm.id(); - sharedRam = static_cast<uchar *>(shm.address()); -#else - sharedRam=static_cast<uchar *>(malloc(sharedRamSize)); -#endif - // Need to zero index count at end of block, might as well zero - // the rest too - memset(sharedRam,0,sharedRamSize); - - QWSIdentifyCommand cmd; - cmd.setId(appName, -1); - qt_server_enqueue(&cmd); - } - - // Allow some memory for the graphics driver too - //### Note that sharedRamSize() has side effects; it must be called - //### once, and only once, and before initDevice() - sharedRamSize -= qt_screen->sharedRamSize(sharedRam+sharedRamSize); - -#ifndef QT_NO_QWS_MULTIPROCESS - if(!csocket) -#endif - { - //QWS server process - if (!qt_screen->initDevice()) - qFatal("Unable to initialize screen driver!"); - } - - sharedRamSize -= sizeof(int); - qt_last_x = reinterpret_cast<int *>(sharedRam + sharedRamSize); - sharedRamSize -= sizeof(int); - qt_last_y = reinterpret_cast<int *>(sharedRam + sharedRamSize); - - /* Initialise framebuffer memory manager */ - /* Add 4k for luck and to avoid clobbering hardware cursor */ -// int screensize=qt_screen->screenSize(); -// memorymanager=new QMemoryManager(qt_screen->base()+screensize+4096, -// qt_screen->totalSize()-(screensize+4096),0); - -// #ifndef QT_NO_QWS_MULTIPROCESS -// rgnMan = new QWSRegionManager(pipe, csocket); -// #else -// rgnMan = new QWSRegionManager(pipe, 0); //####### not necessary -// #endif -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) - csocket->flush(); -#endif -} - - -QWSEvent* QWSDisplay::Data::readMore() -{ -#ifdef QT_NO_QWS_MULTIPROCESS - return incoming.isEmpty() ? 0 : incoming.takeFirst(); -#else - if (!csocket) - return incoming.isEmpty() ? 0 : incoming.takeFirst(); - // read next event - if (!current_event) { - int event_type = qws_read_uint(csocket); - - if (event_type >= 0) { - current_event = QWSEvent::factory(event_type); - } - } - - if (current_event) { - if (current_event->read(csocket)) { - // Finished reading a whole event. - QWSEvent* result = current_event; - current_event = 0; - return result; - } - } - - // Not finished reading a whole event. - return 0; -#endif -} - -void QWSDisplay::Data::fillQueue() -{ - QWSServer::processEventQueue(); - QWSEvent *e = readMore(); -#ifndef QT_NO_QWS_MULTIPROCESS - int bytesAvailable = csocket ? csocket->bytesAvailable() : 0; - int bytesRead = 0; -#endif - while (e) { -#ifndef QT_NO_QWS_MULTIPROCESS - bytesRead += QWS_PROTOCOL_ITEM_SIZE((*e)); -#endif - if (e->type == QWSEvent::Connected) { - connected_event = static_cast<QWSConnectedEvent *>(e); - return; - } else if (e->type == QWSEvent::Creation) { - QWSCreationEvent *ce = static_cast<QWSCreationEvent*>(e); - int id = ce->simpleData.objectid; - int count = ce->simpleData.count; - for (int i = 0; i < count; ++i) - unused_identifiers.append(id++); - delete e; - } else if (e->type == QWSEvent::Mouse) { - if (!qt_screen) { - delete e; - } else { - QWSMouseEvent *me = static_cast<QWSMouseEvent*>(e); - if (mouseFilter) - mouseFilter(me); -#ifdef QAPPLICATION_EXTRA_DEBUG - static const char *defaultAction= "INITIAL"; - const char * action = defaultAction; -#endif - delete mouse_event; - if (mouse_winid != me->window () - || mouse_state != me->simpleData.state) { - queue.append(me); - mouse_winid = me->window(); - mouse_state = me->simpleData.state; - mouse_event = 0; -#ifdef QAPPLICATION_EXTRA_DEBUG - mouse_event_count = 0; - action = "ENQUEUE"; -#endif - } else { -#ifdef QAPPLICATION_EXTRA_DEBUG - if (mouse_event) - action = "COMPRESS"; - mouse_event_count++; -#endif - mouse_event = me; - } -#ifdef QAPPLICATION_EXTRA_DEBUG - if (me->simpleData.state !=0 || action != defaultAction || mouse_event_count != 0) - qDebug("fillQueue %s (%d,%d), state %x win %d count %d", action, - me->simpleData.x_root, me->simpleData.y_root, me->simpleData.state, - me->window(), mouse_event_count); -#endif - } -#ifndef QT_NO_QWS_MULTIPROCESS - } else if (e->type == QWSEvent::Region && clientLock) { - // not really an unlock, decrements the semaphore - region_events_count++; - clientLock->unlock(QWSLock::RegionEvent); - queue.append(e); -#endif -#ifndef QT_NO_QWS_PROPERTIES - } else if (e->type == QWSEvent::PropertyReply) { - QWSPropertyReplyEvent *pe = static_cast<QWSPropertyReplyEvent*>(e); - int len = pe->simpleData.len; - char *data; - if (len <= 0) { - data = 0; - } else { - data = new char[len]; - memcpy(data, pe->data, len) ; - } - QPaintDevice::qwsDisplay()->getPropertyLen = len; - QPaintDevice::qwsDisplay()->getPropertyData = data; - delete e; -#endif // QT_NO_QWS_PROPERTIES - } else if (e->type==QWSEvent::MaxWindowRect && qt_screen) { - // Process this ASAP, in case new widgets are created (startup) - setMaxWindowRect((static_cast<QWSMaxWindowRectEvent*>(e))->simpleData.rect); - delete e; -#ifndef QT_NO_QWS_DYNAMICSCREENTRANSFORMATION - } else if (e->type == QWSEvent::ScreenTransformation) { - QWSScreenTransformationEvent *pe = static_cast<QWSScreenTransformationEvent*>(e); - setScreenTransformation(pe->simpleData.screen, - pe->simpleData.transformation); - delete e; -#endif -#ifndef QT_NO_COP - } else if (e->type == QWSEvent::QCopMessage) { - QWSQCopMessageEvent *pe = static_cast<QWSQCopMessageEvent*>(e); - if (pe->simpleData.is_response) { - qcop_response = pe; - } else { - queue.append(e); - } -#endif - } else { - queue.append(e); - } - //debugQueue(); -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket && bytesRead >= bytesAvailable) - break; -#endif - e = readMore(); - } -} - -#ifndef QT_NO_QWS_MULTIPROCESS - -static int qws_connection_timeout = 5; - -void QWSDisplay::Data::connectToPipe() -{ - Q_ASSERT(csocket); - - int timeout = qgetenv("QWS_CONNECTION_TIMEOUT").toInt(); - if (timeout) - qws_connection_timeout = timeout; - - const QString pipe = qws_qtePipeFilename(); - int i = 0; - while (!csocket->connectToLocalFile(pipe)) { - if (++i > qws_connection_timeout) { - qWarning("No Qt for Embedded Linux server appears to be running."); - qWarning("If you want to run this program as a server,"); - qWarning("add the \"-qws\" command-line option."); - exit(1); - } - sleep(1); - } -} - -void QWSDisplay::Data::waitForConnection() -{ - connected_event = 0; - - for (int i = 0; i < qws_connection_timeout; i++) { - fillQueue(); - if (connected_event) - return; - csocket->flush(); - csocket->waitForReadyRead(1000); - } - - csocket->flush(); - if (!connected_event) - qFatal("Did not receive a connection event from the qws server"); -} - -void QWSDisplay::Data::waitForRegionAck(int winId) -{ - QWSEvent *ack = 0; - - if (csocket) { // GuiClient - int i = 0; - while (!ack) { - fillQueue(); - - while (i < queue.size()) { - QWSEvent *e = queue.at(i); - if (e->type == QWSEvent::Region && e->window() == winId) { - ack = e; - queue.removeAt(i); - break; - } - ++i; - } - - if (!ack) { - csocket->flush(); - csocket->waitForReadyRead(1000); - } - } - } else { // GuiServer - fillQueue(); - for (int i = 0; i < queue.size(); /* nothing */) { - QWSEvent *e = queue.at(i); - if (e->type == QWSEvent::Region && e->window() == winId) { - ack = e; - queue.removeAt(i); - break; - } - ++i; - } - if (!ack) // already processed - return; - } - - Q_ASSERT(ack); - - qApp->qwsProcessEvent(ack); - delete ack; - region_events_count--; -} - -void QWSDisplay::Data::waitForRegionEvents(int winId, bool ungrabDisplay) -{ - if (!clientLock) - return; - - int removedEventsCount = 0; - - // fill queue with unreceived region events - if (!clientLock->hasLock(QWSLock::RegionEvent)) { - bool ungrabbed = false; - if (ungrabDisplay && QWSDisplay::grabbed()) { - QWSDisplay::ungrab(); - ungrabbed = true; - } - - for (;;) { - fillQueue(); - if (clientLock->hasLock(QWSLock::RegionEvent)) - break; - csocket->flush(); - csocket->waitForReadyRead(1000); - } - - if (ungrabbed) - QWSDisplay::grab(true); - } - - // check the queue for pending region events - QWSEvent *regionEvent = 0; - for (int i = 0; i < queue.size(); /* nothing */) { - QWSEvent *e = queue.at(i); - if (e->type == QWSEvent::Region && e->window() == winId) { - QWSRegionEvent *re = static_cast<QWSRegionEvent*>(e); - if (re->simpleData.type == QWSRegionEvent::Allocation) { - delete regionEvent; - regionEvent = re; - } - queue.removeAt(i); - removedEventsCount++; - } else { - ++i; - } - } - - if (regionEvent) { - qApp->qwsProcessEvent(regionEvent); - delete regionEvent; - } - region_events_count -= removedEventsCount; -} - -bool QWSDisplay::Data::hasPendingRegionEvents() const -{ - if (clientLock && !clientLock->hasLock(QWSLock::RegionEvent)) - return true; - - return region_events_count > 0; -} - -#endif // QT_NO_QWS_MULTIPROCESS - -void QWSDisplay::Data::waitForCreation() -{ - fillQueue(); -#ifndef QT_NO_QWS_MULTIPROCESS - while (unused_identifiers.count() == 0) { - if (csocket) { - csocket->flush(); - csocket->waitForReadyRead(1000); - } - fillQueue(); - } -#endif -} - - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSDisplay::Data::waitForPropertyReply() -{ - if (!csocket) - return; - fillQueue(); - while (qt_fbdpy->getPropertyLen == -2) { - csocket->flush(); - csocket->waitForReadyRead(1000); - fillQueue(); - } -} -#endif - -#ifndef QT_NO_COP -void QWSDisplay::Data::waitForQCopResponse() -{ - for (;;) { - fillQueue(); - if (qcop_response) - break; -#ifndef QT_NO_QWS_MULTIPROCESS - if (csocket) { - csocket->flush(); - csocket->waitForReadyRead(1000); - } -#endif - } - queue.prepend(qcop_response); - qcop_response = 0; -} -#endif - -/*! - \class QWSDisplay - \brief The QWSDisplay class provides a display for QWS; it is an internal class. - - \internal - - \ingroup qws -*/ - -QWSDisplay::QWSDisplay() -{ - d = new Data(0, qws_single_process); -} - -QWSDisplay::~QWSDisplay() -{ - delete d; - delete lock; - lock = 0; -} - -bool QWSDisplay::grabbed() -{ - return lock->locked(); -} - -void QWSDisplay::grab() -{ - lock->lock(QLock::Read); -} - -void QWSDisplay::grab(bool write) -{ - lock->lock(write ? QLock::Write : QLock::Read); - -} -void QWSDisplay::ungrab() -{ - lock->unlock(); -} - -#if 0 -QWSRegionManager *QWSDisplay::regionManager() const -{ - return d->rgnMan; -} -#endif - -bool QWSDisplay::eventPending() const -{ -#ifndef QT_NO_QWS_MULTIPROCESS - d->flush(); -#endif - d->fillQueue(); - return d->queueNotEmpty(); -} - - -/* - Caller must delete return value! - */ -QWSEvent *QWSDisplay::getEvent() -{ - d->fillQueue(); - Q_ASSERT(d->queueNotEmpty()); - QWSEvent* e = d->dequeue(); - - return e; -} - -uchar* QWSDisplay::frameBuffer() const { return qt_screen->base(); } -int QWSDisplay::width() const { return qt_screen->width(); } -int QWSDisplay::height() const { return qt_screen->height(); } -int QWSDisplay::depth() const { return qt_screen->depth(); } -int QWSDisplay::pixmapDepth() const { return qt_screen->pixmapDepth(); } -bool QWSDisplay::supportsDepth(int depth) const { return qt_screen->supportsDepth(depth); } -uchar *QWSDisplay::sharedRam() const { return d->sharedRam; } -int QWSDisplay::sharedRamSize() const { return d->sharedRamSize; } - -#ifndef QT_NO_QWS_PROPERTIES - -void QWSDisplay::addProperty(int winId, int property) -{ - QWSAddPropertyCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - d->sendCommand(cmd); -} - -void QWSDisplay::setProperty(int winId, int property, int mode, const QByteArray &data) -{ - QWSSetPropertyCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - cmd.simpleData.mode = mode; - cmd.setData(data.constData(), data.size()); - d->sendCommand(cmd); -} - -void QWSDisplay::setProperty(int winId, int property, int mode, - const char * data) -{ - QWSSetPropertyCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - cmd.simpleData.mode = mode; - cmd.setData(data, strlen(data)); - d->sendCommand(cmd); -} - -void QWSDisplay::removeProperty(int winId, int property) -{ - QWSRemovePropertyCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - d->sendCommand(cmd); -} - -/* - It is the caller's responsibility to delete[] \a data. - */ -bool QWSDisplay::getProperty(int winId, int property, char *&data, int &len) -{ - if (d->directServerConnection()) { - const char *propertyData; - bool retval = qwsServer->d_func()->get_property(winId, property, propertyData, len); - if (len <= 0) { - data = 0; - } else { - data = new char[len]; - memcpy(data, propertyData, len) ; - } - return retval; - } - QWSGetPropertyCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - d->sendCommand(cmd); - - getPropertyLen = -2; - getPropertyData = 0; - -#ifndef QT_NO_QWS_MULTIPROCESS - d->waitForPropertyReply(); -#endif - - len = getPropertyLen; - data = getPropertyData; - - getPropertyLen = -2; - getPropertyData = 0; - - return len != -1; -} - -#endif // QT_NO_QWS_PROPERTIES - -void QWSDisplay::setAltitude(int winId, int alt, bool fixed) -{ - QWSChangeAltitudeCommand cmd; -#ifdef QT_DEBUG - memset(cmd.simpleDataPtr, 0, sizeof(cmd.simpleData)); //shut up Valgrind -#endif - cmd.simpleData.windowid = winId; - cmd.simpleData.altitude = QWSChangeAltitudeCommand::Altitude(alt); - cmd.simpleData.fixed = fixed; - if (d->directServerConnection()) { - qwsServer->d_func()->set_altitude(&cmd); - } else { - d->sendSynchronousCommand(cmd); - } -} - -void QWSDisplay::setOpacity(int winId, int opacity) -{ - QWSSetOpacityCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.opacity = opacity; - if (d->directServerConnection()) { - qwsServer->d_func()->set_opacity(&cmd); - } else { - d->sendCommand(cmd); - } -} - - - -void QWSDisplay::requestFocus(int winId, bool get) -{ - QWSRequestFocusCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.flag = get; - if (d->directServerConnection()) - qwsServer->d_func()->request_focus(&cmd); - else - d->sendCommand(cmd); -} - -void QWSDisplay::setIdentity(const QString &appName) -{ - QWSIdentifyCommand cmd; -#ifdef QT_NO_QWS_MULTIPROCESS - const int id = -1; -#else - const int id = QWSDisplay::Data::clientLock ? QWSDisplay::Data::clientLock->id() : -1; -#endif - cmd.setId(appName, id); - if (d->directServerConnection()) - qwsServer->d_func()->set_identity(&cmd); - else - d->sendCommand(cmd); -} - -void QWSDisplay::nameRegion(int winId, const QString& n, const QString &c) -{ - QWSRegionNameCommand cmd; - cmd.simpleData.windowid = winId; - cmd.setName(n, c); - if (d->directServerConnection()) - qwsServer->d_func()->name_region(&cmd); - else - d->sendCommand(cmd); -} - -void QWSDisplay::requestRegion(int winId, const QString &surfaceKey, - const QByteArray &surfaceData, - const QRegion ®ion) -{ - if (d->directServerConnection()) { - qwsServer->d_func()->request_region(winId, surfaceKey, - surfaceData, region); - } else { - QWSRegionCommand cmd; - cmd.setData(winId, surfaceKey, surfaceData, region); - d->sendSynchronousCommand(cmd); - } -} - -void QWSDisplay::repaintRegion(int winId, int windowFlags, bool opaque, QRegion r) -{ - if (d->directServerConnection()) { - qwsServer->d_func()->repaint_region(winId, windowFlags, opaque, r); - } else { - QVector<QRect> ra = r.rects(); - - /* - for (int i = 0; i < ra.size(); i++) { - QRect r(ra[i]); - qDebug("rect: %d %d %d %d", r.x(), r.y(), r.right(), r.bottom()); - } - */ - - QWSRepaintRegionCommand cmd; - /* XXX QWSRegionCommand is padded out in a compiler dependent way. - Zeroed out to avoid valgrind reporting uninitialized memory usage. - */ -#ifdef QT_DEBUG - memset(cmd.simpleDataPtr, 0, sizeof(cmd.simpleData)); //shut up Valgrind -#endif - cmd.simpleData.windowid = winId; - cmd.simpleData.windowFlags = windowFlags; - cmd.simpleData.opaque = opaque; - cmd.simpleData.nrectangles = ra.count(); - cmd.setData(reinterpret_cast<const char *>(ra.constData()), - ra.count() * sizeof(QRect), false); - - d->sendSynchronousCommand(cmd); - } -} - - -void QWSDisplay::moveRegion(int winId, int dx, int dy) -{ - QWSRegionMoveCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.dx = dx; - cmd.simpleData.dy = dy; - - if (d->directServerConnection()) { - qwsServer->d_func()->move_region(&cmd); - } else { - d->sendSynchronousCommand(cmd); - } -// d->offsetPendingExpose(winId, QPoint(cmd.simpleData.dx, cmd.simpleData.dy)); -} - -void QWSDisplay::destroyRegion(int winId) -{ - QWSRegionDestroyCommand cmd; - cmd.simpleData.windowid = winId; - if (d->directServerConnection()) { - qwsServer->d_func()->destroy_region(&cmd); - } else { - d->sendCommand(cmd); - } -} - -#ifndef QT_NO_QWS_INPUTMETHODS - -void QWSDisplay::sendIMUpdate(int type, int winId, int widgetid) -{ - QWSIMUpdateCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.widgetid = widgetid; - - cmd.simpleData.type = type; - - if (d->directServerConnection()) { - qwsServer->d_func()->im_update(&cmd); - } else { - d->sendCommand(cmd); - } -} - -void QWSDisplay::sendIMResponse(int winId, int property, const QVariant &result) -{ - QWSIMResponseCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.property = property; - - cmd.setResult(result); - - if (d->directServerConnection()) { - qwsServer->d_func()->im_response(&cmd); - } else { - d->sendCommand(cmd); - } -} - -void QWSDisplay::resetIM() -{ - sendIMUpdate(QWSInputMethod::Reset, -1, -1); -} - -void QWSDisplay::sendIMMouseEvent(int index, bool isPress) -{ - QWSIMMouseCommand cmd; - cmd.simpleData.index = index; - cmd.simpleData.state = isPress ? QWSServer::MousePress : QWSServer::MouseRelease; - if (d->directServerConnection()) { - qwsServer->d_func()->send_im_mouse(&cmd); - } else { - d->sendCommand(cmd); - } -} - -#endif - -int QWSDisplay::takeId() -{ - return d->takeId(); -} - -bool QWSDisplay::initLock(const QString &filename, bool create) -{ - if (!lock) { - lock = new QLock(filename, 'd', create); - - if (!lock->isValid()) { - delete lock; - lock = 0; - return false; - } - } - - return true; -} - -void QWSDisplay::setSelectionOwner(int winId, const QTime &time) -{ - QWSSetSelectionOwnerCommand cmd; - cmd.simpleData.windowid = winId; - cmd.simpleData.hour = time.hour(); - cmd.simpleData.minute = time.minute(); - cmd.simpleData.sec = time.second(); - cmd.simpleData.ms = time.msec(); - d->sendCommand(cmd); -} - -void QWSDisplay::convertSelection(int winId, int selectionProperty, const QString &mimeTypes) -{ -#ifdef QT_NO_QWS_PROPERTIES - Q_UNUSED(mimeTypes); -#else - // ### we need the atom/property thingy like in X here - addProperty(winId, QT_QWS_PROPERTY_CONVERTSELECTION); - setProperty(winId, QT_QWS_PROPERTY_CONVERTSELECTION, - int(QWSPropertyManager::PropReplace), mimeTypes.toLatin1()); -#endif - QWSConvertSelectionCommand cmd; - cmd.simpleData.requestor = winId; - cmd.simpleData.selection = selectionProperty; - cmd.simpleData.mimeTypes = QT_QWS_PROPERTY_CONVERTSELECTION; - d->sendCommand(cmd); -} - -void QWSDisplay::defineCursor(int id, const QBitmap &curs, const QBitmap &mask, - int hotX, int hotY) -{ - const QImage cursImg = curs.toImage().convertToFormat(QImage::Format_MonoLSB); - const QImage maskImg = mask.toImage().convertToFormat(QImage::Format_MonoLSB); - - QWSDefineCursorCommand cmd; - cmd.simpleData.width = curs.width(); - cmd.simpleData.height = curs.height(); - cmd.simpleData.hotX = hotX; - cmd.simpleData.hotY = hotY; - cmd.simpleData.id = id; - - - // must copy each scanline since there might be gaps between them - const int height = curs.height(); - const int width = curs.width(); - const int dst_bpl = (width + 7) / 8; - - int dataLen = dst_bpl * height; - uchar *data = new uchar[dataLen*2]; - uchar *dst = data; - - int src_bpl = cursImg.bytesPerLine(); - const uchar *cursSrc = cursImg.bits(); - for (int i = 0; i < height; ++i) { - memcpy(dst, cursSrc + i*src_bpl, dst_bpl); - dst += dst_bpl; - } - - src_bpl = maskImg.bytesPerLine(); - const uchar *maskSrc = maskImg.bits(); - for (int i = 0; i < height; ++i) { - memcpy(dst, maskSrc + i*src_bpl, dst_bpl); - dst += dst_bpl; - } - - cmd.setData(reinterpret_cast<char*>(data), dataLen*2); - delete [] data; - d->sendCommand(cmd); -} - -void QWSDisplay::destroyCursor(int id) -{ - QWSDefineCursorCommand cmd; - cmd.simpleData.width = 0; - cmd.simpleData.height = 0; - cmd.simpleData.hotX = 0; - cmd.simpleData.hotY = 0; - cmd.simpleData.id = id; - cmd.setData(0, 0); - - d->sendCommand(cmd); -} - -#ifndef QT_NO_SOUND -void QWSDisplay::playSoundFile(const QString& f) -{ - QWSPlaySoundCommand cmd; - cmd.setFileName(f); - d->sendCommand(cmd); -} -#endif - -#ifndef QT_NO_COP -void QWSDisplay::registerChannel(const QString& channel) -{ - QWSQCopRegisterChannelCommand reg; - reg.setChannel(channel); - qt_fbdpy->d->sendCommand(reg); -} - -void QWSDisplay::sendMessage(const QString &channel, const QString &msg, - const QByteArray &data) -{ - QWSQCopSendCommand com; - com.setMessage(channel, msg, data); - qt_fbdpy->d->sendCommand(com); -} - -void QWSDisplay::flushCommands() -{ - qt_fbdpy->d->flushCommands(); -} - -/* - caller deletes result -*/ -QWSQCopMessageEvent* QWSDisplay::waitForQCopResponse() -{ - qt_fbdpy->d->waitForQCopResponse(); - QWSQCopMessageEvent *e = static_cast<QWSQCopMessageEvent*>(qt_fbdpy->d->dequeue()); - Q_ASSERT(e->type == QWSEvent::QCopMessage); - return e; -} -#endif - -void QWSDisplay::sendFontCommand(int type, const QByteArray &fontName) -{ - QWSFontCommand cmd; - cmd.simpleData.type = type; - cmd.setFontName(fontName); - d->sendCommand(cmd); -} - -void QWSDisplay::setWindowCaption(QWidget *w, const QString &c) -{ - if (w->isWindow()) { - nameRegion(w->internalWinId(), w->objectName(), c); - static_cast<QETWidget *>(w)->repaintDecoration(qApp->desktop()->rect(), true); - } -} - -void QWSDisplay::selectCursor(QWidget *w, unsigned int cursId) -{ - if (cursId != qt_last_cursor) - { - QWidget *top = w->window(); - qt_last_cursor = cursId; - QWSSelectCursorCommand cmd; - cmd.simpleData.windowid = top->internalWinId(); - cmd.simpleData.id = cursId; - d->sendCommand(cmd); - d->flush(); - } -} - -void QWSDisplay::setCursorPosition(int x, int y) -{ - QWSPositionCursorCommand cmd; - cmd.simpleData.newX = x; - cmd.simpleData.newY = y; - d->sendCommand(cmd); - d->flush(); -} - -void QWSDisplay::grabMouse(QWidget *w, bool grab) -{ - QWidget *top = w->window(); - QWSGrabMouseCommand cmd; -#ifdef QT_DEBUG - memset(cmd.simpleDataPtr, 0, sizeof(cmd.simpleData)); //shut up Valgrind -#endif - cmd.simpleData.windowid = top->winId(); - cmd.simpleData.grab = grab; - d->sendCommand(cmd); - d->flush(); -} - -void QWSDisplay::grabKeyboard(QWidget *w, bool grab) -{ - QWidget *top = w->window(); - QWSGrabKeyboardCommand cmd; -#ifdef QT_DEBUG - memset(cmd.simpleDataPtr, 0, sizeof(cmd.simpleData)); //shut up Valgrind -#endif - cmd.simpleData.windowid = top->winId(); - cmd.simpleData.grab = grab; - d->sendCommand(cmd); - d->flush(); -} - -QList<QWSWindowInfo> QWSDisplay::windowList() -{ - QList<QWSWindowInfo> ret; - if(d->directServerConnection()) { - QList<QWSInternalWindowInfo*> * qin=QWSServer::windowList(); - for (int i = 0; i < qin->count(); ++i) { - QWSInternalWindowInfo * qwi = qin->at(i); - QWSWindowInfo tmp; - tmp.winid = qwi->winid; - tmp.clientid = qwi->clientid; - tmp.name = QString(qwi->name); - ret.append(tmp); - } - qDeleteAll(*qin); - delete qin; - } - return ret; -} - -int QWSDisplay::windowAt(const QPoint &p) -{ - //### currently only implemented for the server process - int ret = 0; - if(d->directServerConnection()) { - QWSWindow *win = qwsServer->windowAt(p); - if (win) - return win->winId(); - } - return ret; -} - -void QWSDisplay::setRawMouseEventFilter(void (*filter)(QWSMouseEvent *)) -{ - if (qt_fbdpy) - qt_fbdpy->d->setMouseFilter(filter); -} - -/*! - \relates QScreen - - Here it is. \a transformation and \a screenNo - */ -void QWSDisplay::setTransformation(int transformation, int screenNo) -{ - QWSScreenTransformCommand cmd; - cmd.setTransformation(screenNo, transformation); - QWSDisplay::instance()->d->sendCommand(cmd); -} - -static bool qt_try_modal(QWidget *, QWSEvent *); - -/***************************************************************************** - qt_init() - initializes Qt/FB - *****************************************************************************/ - -static void qt_set_qws_resources() - -{ - if (QApplication::desktopSettingsAware()) - QApplicationPrivate::qws_apply_settings(); - - if (appFont) - QApplication::setFont(QFont(QString::fromLocal8Bit(appFont))); - - if (appBGCol || appBTNCol || appFGCol) { - (void) QApplication::style(); // trigger creation of application style and system palettes - QColor btn; - QColor bg; - QColor fg; - if (appBGCol) - bg = QColor(appBGCol); - else - bg = QApplicationPrivate::sys_pal->color(QPalette::Window); - if (appFGCol) - fg = QColor(appFGCol); - else - fg = QApplicationPrivate::sys_pal->color(QPalette::WindowText); - if (appBTNCol) - btn = QColor(appBTNCol); - else - btn = QApplicationPrivate::sys_pal->color(QPalette::Button); - - int h,s,v; - fg.getHsv(&h,&s,&v); - QColor base = Qt::white; - bool bright_mode = false; - if (v >= 255 - 50) { - base = btn.darker(150); - bright_mode = true; - } - - QPalette pal(fg, btn, btn.lighter(), btn.darker(), btn.darker(150), fg, Qt::white, base, bg); - if (bright_mode) { - pal.setColor(QPalette::HighlightedText, base); - pal.setColor(QPalette::Highlight, Qt::white); - } else { - pal.setColor(QPalette::HighlightedText, Qt::white); - pal.setColor(QPalette::Highlight, Qt::darkBlue); - } - QColor disabled((fg.red() + btn.red()) / 2, - (fg.green() + btn.green())/ 2, - (fg.blue() + btn.blue()) / 2); - pal.setColorGroup(QPalette::Disabled, disabled, btn, btn.lighter(125), - btn.darker(), btn.darker(150), disabled, Qt::white, Qt::white, bg); - if (bright_mode) { - pal.setColor(QPalette::Disabled, QPalette::HighlightedText, base); - pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::white); - } else { - pal.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white); - pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); - } - QApplicationPrivate::setSystemPalette(pal); - - } -} - -void QApplicationPrivate::initializeWidgetPaletteHash() -{ -} - -/*! \internal - apply the settings to the application -*/ -bool QApplicationPrivate::qws_apply_settings() -{ -#ifndef QT_NO_SETTINGS - QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); - settings.beginGroup(QLatin1String("Qt")); - - QStringList strlist; - int i; - QPalette pal(Qt::black); - int groupCount = 0; - strlist = settings.value(QLatin1String("Palette/active")).toStringList(); - if (strlist.count() == QPalette::NColorRoles) { - ++groupCount; - for (i = 0; i < QPalette::NColorRoles; i++) - pal.setColor(QPalette::Active, (QPalette::ColorRole) i, - QColor(strlist[i])); - } - strlist = settings.value(QLatin1String("Palette/inactive")).toStringList(); - if (strlist.count() == QPalette::NColorRoles) { - ++groupCount; - for (i = 0; i < QPalette::NColorRoles; i++) - pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i, - QColor(strlist[i])); - } - strlist = settings.value(QLatin1String("Palette/disabled")).toStringList(); - if (strlist.count() == QPalette::NColorRoles) { - ++groupCount; - for (i = 0; i < QPalette::NColorRoles; i++) - pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i, - QColor(strlist[i])); - } - - - if (groupCount == QPalette::NColorGroups) - QApplicationPrivate::setSystemPalette(pal); - - QString str = settings.value(QLatin1String("font")).toString(); - if (!str.isEmpty()) { - QFont font(QApplication::font()); - font.fromString(str); - QApplicationPrivate::setSystemFont(font); - } - - // read library (ie. plugin) path list - QString libpathkey = - QString::fromLatin1("%1.%2/libraryPath") - .arg(QT_VERSION >> 16) - .arg((QT_VERSION & 0xff00) >> 8); - QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':')); -#ifndef QT_NO_LIBRARY - if (! pathlist.isEmpty()) { - QStringList::ConstIterator it = pathlist.constBegin(); - while (it != pathlist.constEnd()) - QApplication::addLibraryPath(*it++); - } -#endif - - // read new QStyle - QString stylename = settings.value(QLatin1String("style")).toString(); - if (QCoreApplication::startingUp()) { - if (!stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull()) - QApplicationPrivate::styleOverride = stylename; - } else { - QApplication::setStyle(stylename); - } - - int num = - settings.value(QLatin1String("doubleClickInterval"), - QApplication::doubleClickInterval()).toInt(); - QApplication::setDoubleClickInterval(num); - - num = - settings.value(QLatin1String("cursorFlashTime"), - QApplication::cursorFlashTime()).toInt(); - QApplication::setCursorFlashTime(num); - -#ifndef QT_NO_WHEELEVENT - num = - settings.value(QLatin1String("wheelScrollLines"), - QApplication::wheelScrollLines()).toInt(); - QApplication::setWheelScrollLines(num); -#endif - - QString colorspec = settings.value(QLatin1String("colorSpec"), - QVariant(QLatin1String("default"))).toString(); - if (colorspec == QLatin1String("normal")) - QApplication::setColorSpec(QApplication::NormalColor); - else if (colorspec == QLatin1String("custom")) - QApplication::setColorSpec(QApplication::CustomColor); - else if (colorspec == QLatin1String("many")) - QApplication::setColorSpec(QApplication::ManyColor); - else if (colorspec != QLatin1String("default")) - colorspec = QLatin1String("default"); - -#ifndef QT_NO_TEXTCODEC - QString defaultcodec = settings.value(QLatin1String("defaultCodec"), - QVariant(QLatin1String("none"))).toString(); - if (defaultcodec != QLatin1String("none")) { - QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1()); - if (codec) - QTextCodec::setCodecForTr(codec); - } -#endif - - int w = settings.value(QLatin1String("globalStrut/width")).toInt(); - int h = settings.value(QLatin1String("globalStrut/height")).toInt(); - QSize strut(w, h); - if (strut.isValid()) - QApplication::setGlobalStrut(strut); - - QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList(); - QApplication::setEffectEnabled(Qt::UI_General, - effects.contains(QLatin1String("general"))); - QApplication::setEffectEnabled(Qt::UI_AnimateMenu, - effects.contains(QLatin1String("animatemenu"))); - QApplication::setEffectEnabled(Qt::UI_FadeMenu, - effects.contains(QLatin1String("fademenu"))); - QApplication::setEffectEnabled(Qt::UI_AnimateCombo, - effects.contains(QLatin1String("animatecombo"))); - QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, - effects.contains(QLatin1String("animatetooltip"))); - QApplication::setEffectEnabled(Qt::UI_FadeTooltip, - effects.contains(QLatin1String("fadetooltip"))); - QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, - effects.contains(QLatin1String("animatetoolbox"))); - - settings.beginGroup(QLatin1String("Font Substitutions")); - QStringList fontsubs = settings.childKeys(); - if (!fontsubs.isEmpty()) { - QStringList::Iterator it = fontsubs.begin(); - for (; it != fontsubs.end(); ++it) { - QString fam = *it; - QStringList subs = settings.value(fam).toStringList(); - QFont::insertSubstitutions(fam, subs); - } - } - settings.endGroup(); - - settings.endGroup(); // Qt - - settings.beginGroup(QLatin1String("QWS Font Fallbacks")); - if (!settings.childKeys().isEmpty()) { - // from qfontdatabase_qws.cpp - extern void qt_applyFontDatabaseSettings(const QSettings &); - qt_applyFontDatabaseSettings(settings); - } - settings.endGroup(); - - return true; -#else - return false; -#endif // QT_NO_SETTINGS -} - - - -static void init_display() -{ - if (qt_fbdpy) return; // workaround server==client case - - // Connect to FB server - qt_fbdpy = new QWSDisplay(); - - // Get display parameters - // Set paintdevice parameters - // XXX initial info sent from server - // Misc. initialization - - QColormap::initialize(); - QFont::initialize(); -#ifndef QT_NO_CURSOR - QCursorData::initialize(); -#endif - - qApp->setObjectName(appName); - - if (!QApplicationPrivate::sys_font) { -#ifdef QT_NO_FREETYPE - QFont f = QFont(QLatin1String("helvetica"), 10); -#else - QFont f = QFont(QLatin1String("DejaVu Sans"), 12); -#endif - QApplicationPrivate::setSystemFont(f); - } - qt_set_qws_resources(); -} - -void qt_init_display() -{ - qt_is_gui_used = true; - qws_single_process = true; - init_display(); -} - -static bool read_bool_env_var(const char *var, bool defaultvalue) -{ - // returns true if env variable is set to non-zero - // returns false if env var is set to zero - // returns defaultvalue if env var not set - char *x = ::getenv(var); - return (x && *x) ? (strcmp(x,"0") != 0) : defaultvalue; -} - -static int read_int_env_var(const char *var, int defaultvalue) -{ - bool ok; - int r = qgetenv(var).toInt(&ok); - return ok ? r : defaultvalue; -} - -void qt_init(QApplicationPrivate *priv, int type) -{ -#ifdef QT_NO_QWS_MULTIPROCESS - if (type == QApplication::GuiClient) - type = QApplication::GuiServer; -#endif - if (type == QApplication::GuiServer) - qt_is_gui_used = false; //we'll turn it on in a second - qws_sw_cursor = read_bool_env_var("QWS_SW_CURSOR",qws_sw_cursor); - qws_screen_is_interlaced = read_bool_env_var("QWS_INTERLACE",false); - - const char *display = ::getenv("QWS_DISPLAY"); - if (display) - qws_display_spec = display; // since we setenv later! - - //qws_savefonts = qgetenv("QWS_SAVEFONTS") != 0; - //qws_shared_memory = qgetenv("QWS_NOSHARED") == 0; - - mouse_double_click_distance = read_int_env_var("QWS_DBLCLICK_DISTANCE", 5); - - priv->inputContext = 0; - - int flags = 0; - char *p; - int argc = priv->argc; - char **argv = priv->argv; - int j; - - // Set application name - - if (argv && *argv) { //apparently, we allow people to pass 0 on the other platforms - p = strrchr(argv[0], '/'); - appName = QString::fromLocal8Bit(p ? p + 1 : argv[0]); - } - - // Get command line params - - j = argc ? 1 : 0; - QString decoration; - for (int i=1; i<argc; i++) { - if (argv[i] && *argv[i] != '-') { - argv[j++] = argv[i]; - continue; - } - QByteArray arg = argv[i]; - if (arg == "-fn" || arg == "-font") { - if (++i < argc) - appFont = argv[i]; - } else if (arg == "-bg" || arg == "-background") { - if (++i < argc) - appBGCol = argv[i]; - } else if (arg == "-btn" || arg == "-button") { - if (++i < argc) - appBTNCol = argv[i]; - } else if (arg == "-fg" || arg == "-foreground") { - if (++i < argc) - appFGCol = argv[i]; - } else if (arg == "-name") { - if (++i < argc) - appName = QString::fromLocal8Bit(argv[i]); - } else if (arg == "-title") { - if (++i < argc) - mwTitle = argv[i]; - } else if (arg == "-geometry") { - if (++i < argc) - mwGeometry = argv[i]; - } else if (arg == "-shared") { - qws_shared_memory = true; - } else if (arg == "-noshared") { - qws_shared_memory = false; - } else if (arg == "-savefonts") { - qws_savefonts = true; - } else if (arg == "-nosavefonts") { - qws_savefonts = false; - } else if (arg == "-swcursor") { - qws_sw_cursor = true; - } else if (arg == "-noswcursor") { - qws_sw_cursor = false; - } else if (arg == "-keyboard") { - flags &= ~QWSServer::DisableKeyboard; - } else if (arg == "-nokeyboard") { - flags |= QWSServer::DisableKeyboard; - } else if (arg == "-mouse") { - flags &= ~QWSServer::DisableMouse; - } else if (arg == "-nomouse") { - flags |= QWSServer::DisableMouse; - } else if (arg == "-qws") { - type = QApplication::GuiServer; - } else if (arg == "-interlaced") { - qws_screen_is_interlaced = true; - } else if (arg == "-display") { - if (++i < argc) - qws_display_spec = argv[i]; - } else if (arg == "-decoration") { - if (++i < argc) - decoration = QString::fromLocal8Bit(argv[i]); - } else { - argv[j++] = argv[i]; - } - } - if(j < priv->argc) { - priv->argv[j] = 0; - priv->argc = j; - } - - mouseInWidget = new QPointer<QWidget>; - - const QString disp = QString::fromLatin1(qws_display_spec); - QRegExp regexp(QLatin1String(":(\\d+)$")); - if (regexp.lastIndexIn(disp) != -1) { - const QString capture = regexp.cap(1); - bool ok = false; - int id = capture.toInt(&ok); - if (ok) - qws_display_id = id; - } - - if (type == QApplication::GuiServer) { - qt_appType = QApplication::Type(type); - qws_single_process = true; - QWSServer::startup(flags); - if (!display) // if not already set - qputenv("QWS_DISPLAY", qws_display_spec); - } - - if(qt_is_gui_used) { - init_display(); -#ifndef QT_NO_QWS_MANAGER - if (decoration.isEmpty() && !qws_decoration) { - const QStringList keys = QDecorationFactory::keys(); - if (!keys.isEmpty()) - decoration = keys.first(); - } - if (!decoration.isEmpty()) - qws_decoration = QApplication::qwsSetDecoration(decoration); -#endif // QT_NO_QWS_MANAGER -#ifndef QT_NO_QWS_INPUTMETHODS - qApp->setInputContext(new QWSInputContext(qApp)); -#endif - } - -/*### convert interlace style - if (qws_screen_is_interlaced) - QApplication::setStyle(new QInterlaceStyle); -*/ -} - -/***************************************************************************** - qt_cleanup() - cleans up when the application is finished - *****************************************************************************/ - -void qt_cleanup() -{ - QPixmapCache::clear(); -#ifndef QT_NO_CURSOR - QCursorData::cleanup(); -#endif - QFont::cleanup(); - QColormap::cleanup(); - - if (qws_single_process) { - QWSServer::closedown(); - } - - qDeleteAll(outgoing); - outgoing.clear(); - qDeleteAll(incoming); - incoming.clear(); - - if (qt_is_gui_used) { - delete qt_fbdpy; - } - qt_fbdpy = 0; - -#ifndef QT_NO_QWS_MANAGER - delete qws_decoration; - qws_decoration = 0; -#endif - - delete mouseInWidget; - mouseInWidget = 0; - -#if !defined(QT_NO_IM) - delete QApplicationPrivate::inputContext; - QApplicationPrivate::inputContext = 0; -#endif -} - - -/***************************************************************************** - Platform specific global and internal functions - *****************************************************************************/ - -QString QApplicationPrivate::appName() const // get application name -{ - return QT_PREPEND_NAMESPACE(appName); -} - -/***************************************************************************** - Platform specific QApplication members - *****************************************************************************/ - -#define NoValue 0x0000 -#define XValue 0x0001 -#define YValue 0x0002 -#define WidthValue 0x0004 -#define HeightValue 0x0008 -#define AllValues 0x000F -#define XNegative 0x0010 -#define YNegative 0x0020 - -/* Copyright notice for ReadInteger and parseGeometry - -Copyright (c) 1985, 1986, 1987 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - -*/ -/* - * XParseGeometry parses strings of the form - * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where - * width, height, xoffset, and yoffset are unsigned integers. - * Example: "=80x24+300-49" - * The equal sign is optional. - * It returns a bitmask that indicates which of the four values - * were actually found in the string. For each value found, - * the corresponding argument is updated; for each value - * not found, the corresponding argument is left unchanged. - */ - -static int -ReadInteger(char *string, char **NextString) -{ - register int Result = 0; - int Sign = 1; - - if (*string == '+') - string++; - else if (*string == '-') - { - string++; - Sign = -1; - } - for (; (*string >= '0') && (*string <= '9'); string++) - { - Result = (Result * 10) + (*string - '0'); - } - *NextString = string; - if (Sign >= 0) - return Result; - else - return -Result; -} - -static int parseGeometry(const char* string, - int* x, int* y, int* width, int* height) -{ - int mask = NoValue; - register char *strind; - unsigned int tempWidth=0, tempHeight=0; - int tempX=0, tempY=0; - char *nextCharacter; - - if (!string || (*string == '\0')) return mask; - if (*string == '=') - string++; /* ignore possible '=' at beg of geometry spec */ - - strind = const_cast<char *>(string); - if (*strind != '+' && *strind != '-' && *strind != 'x') { - tempWidth = ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - mask |= WidthValue; - } - - if (*strind == 'x' || *strind == 'X') { - strind++; - tempHeight = ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - mask |= HeightValue; - } - - if ((*strind == '+') || (*strind == '-')) { - if (*strind == '-') { - strind++; - tempX = -ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - mask |= XNegative; - - } - else - { strind++; - tempX = ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - } - mask |= XValue; - if ((*strind == '+') || (*strind == '-')) { - if (*strind == '-') { - strind++; - tempY = -ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - mask |= YNegative; - - } - else - { - strind++; - tempY = ReadInteger(strind, &nextCharacter); - if (strind == nextCharacter) - return 0; - strind = nextCharacter; - } - mask |= YValue; - } - } - - /* If strind isn't at the end of the string then it's an invalid - geometry specification. */ - - if (*strind != '\0') return 0; - - if (mask & XValue) - *x = tempX; - if (mask & YValue) - *y = tempY; - if (mask & WidthValue) - *width = tempWidth; - if (mask & HeightValue) - *height = tempHeight; - return mask; -} - -#ifdef QT3_SUPPORT -void QApplication::setMainWidget(QWidget *mainWidget) -{ - QApplicationPrivate::main_widget = mainWidget; - if (QApplicationPrivate::main_widget) // give WM command line - QApplicationPrivate::applyQWSSpecificCommandLineArguments(QApplicationPrivate::main_widget); -} -#endif - -void QApplicationPrivate::applyQWSSpecificCommandLineArguments(QWidget *main_widget) -{ - static bool beenHereDoneThat = false; - if (beenHereDoneThat) - return; - beenHereDoneThat = true; - if (qApp->windowIcon().isNull() && main_widget->testAttribute(Qt::WA_SetWindowIcon)) - qApp->setWindowIcon(main_widget->windowIcon()); - if (mwTitle) // && main_widget->windowTitle().isEmpty()) - main_widget->setWindowTitle(QString::fromLocal8Bit(mwTitle)); - if (mwGeometry) { // parse geometry - int x = 0; - int y = 0; - int w = 0; - int h = 0; - int m = parseGeometry(mwGeometry, &x, &y, &w, &h); - QSize minSize = main_widget->minimumSize(); - QSize maxSize = main_widget->maximumSize(); - if ((m & XValue) == 0) - x = main_widget->geometry().x(); - if ((m & YValue) == 0) - y = main_widget->geometry().y(); - if ((m & WidthValue) == 0) - w = main_widget->width(); - if ((m & HeightValue) == 0) - h = main_widget->height(); - w = qMin(w,maxSize.width()); - h = qMin(h,maxSize.height()); - w = qMax(w,minSize.width()); - h = qMax(h,minSize.height()); - if ((m & XNegative)) { - x = qApp->desktop()->width() + x - w; - x -= (main_widget->frameGeometry().width() - main_widget->width()) / 2; - } else { - x += (main_widget->geometry().x() - main_widget->x()); - } - if ((m & YNegative)) { - y = qApp->desktop()->height() + y - h; - } else { - y += (main_widget->geometry().y() - main_widget->y()); - } - - main_widget->setGeometry(x, y, w, h); - } -} - -/***************************************************************************** - QApplication cursor stack - *****************************************************************************/ -#ifndef QT_NO_CURSOR -void QApplication::setOverrideCursor(const QCursor &cursor) -{ - qApp->d_func()->cursor_list.prepend(cursor); - - QWidget *w = QWidget::mouseGrabber(); - if (!w && qt_last_x) - w = topLevelAt(*qt_last_x, *qt_last_y); - if (!w) - w = desktop(); - QPaintDevice::qwsDisplay()->selectCursor(w, qApp->d_func()->cursor_list.first().handle()); -} - -void QApplication::restoreOverrideCursor() -{ - if (qApp->d_func()->cursor_list.isEmpty()) - return; - qApp->d_func()->cursor_list.removeFirst(); - - QWidget *w = QWidget::mouseGrabber(); - if (!w && qt_last_x) - w = topLevelAt(*qt_last_x, *qt_last_y); - if (!w) - w = desktop(); - - int cursor_handle = Qt::ArrowCursor; - if (qApp->d_func()->cursor_list.isEmpty()) { - qws_overrideCursor = false; - QWidget *upw = QApplication::widgetAt(*qt_last_x, *qt_last_y); - if (upw) - cursor_handle = upw->cursor().handle(); - } else { - cursor_handle = qApp->d_func()->cursor_list.first().handle(); - } - QPaintDevice::qwsDisplay()->selectCursor(w, cursor_handle); -} -#endif// QT_NO_CURSOR - - - -/***************************************************************************** - Routines to find a Qt widget from a screen position - *****************************************************************************/ - -/*! - \internal -*/ -QWidget *QApplicationPrivate::findWidget(const QObjectList& list, - const QPoint &pos, bool rec) -{ - QWidget *w; - - for (int i = list.size()-1; i >= 0; --i) { - if (list.at(i)->isWidgetType()) { - w = static_cast<QWidget*>(list.at(i)); - if (w->isVisible() && !w->testAttribute(Qt::WA_TransparentForMouseEvents) && w->geometry().contains(pos) - && (!w->d_func()->extra || w->d_func()->extra->mask.isEmpty() || w->d_func()->extra->mask.contains(pos - w->geometry().topLeft()) )) { - if (!rec) - return w; - QWidget *c = w->childAt(w->mapFromParent(pos)); - return c ? c : w; - } - } - } - return 0; -} - - -QWidget *QApplication::topLevelAt(const QPoint &pos) -{ - //### QWSDisplay::windowAt() is currently only implemented in the server process - int winId = QPaintDevice::qwsDisplay()->windowAt(pos); - if (winId !=0) - return QWidget::find(winId); - -#if 1 - // fallback implementation for client processes -//### This is slightly wrong: we have no guarantee that the list is in -//### stacking order, so if the topmost window is transparent, we may -//### return the wrong widget - - QWidgetList list = topLevelWidgets(); - for (int i = list.size()-1; i >= 0; --i) { - QWidget *w = list[i]; - if (w != QApplication::desktop() && - w->isVisible() && w->d_func()->localAllocatedRegion().contains(w->mapFromParent(pos)) - ) - return w; - } -#endif - return 0; -} - -void QApplication::beep() -{ -} - -void QApplication::alert(QWidget *, int) -{ -} - -int QApplication::qwsProcessEvent(QWSEvent* event) -{ - Q_D(QApplication); - QScopedLoopLevelCounter loopLevelCounter(d->threadData); - int oldstate = -1; - bool isMove = false; - if (event->type == QWSEvent::Mouse) { - QWSMouseEvent::SimpleData &mouse = event->asMouse()->simpleData; - isMove = mouse_x_root != mouse.x_root || mouse_y_root != mouse.y_root; - oldstate = mouse_state; - mouse_x_root = mouse.x_root; - mouse_y_root = mouse.y_root; - mouse_state = mouse.state; - } - - long unused; - if (filterEvent(event, &unused)) // send through app filter - return 1; - - if (qwsEventFilter(event)) // send through app filter - return 1; - - -#ifndef QT_NO_QWS_PROPERTIES - if (event->type == QWSEvent::PropertyNotify) { - QWSPropertyNotifyEvent *e = static_cast<QWSPropertyNotifyEvent*>(event); - if (e->simpleData.property == 424242) { // Clipboard -#ifndef QT_NO_CLIPBOARD - if (qt_clipboard) { - QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event)); - QApplication::sendEvent(qt_clipboard, &e); - } -#endif - } - } -#endif //QT_NO_QWS_PROPERTIES -#ifndef QT_NO_COP - else if (event->type == QWSEvent::QCopMessage) { - QWSQCopMessageEvent *e = static_cast<QWSQCopMessageEvent*>(event); - QCopChannel::sendLocally(QLatin1String(e->channel), QLatin1String(e->message), e->data); - return 0; - } -#endif -#if !defined(QT_NO_QWS_QPF2) - else if (event->type == QWSEvent::Font) { - QWSFontEvent *e = static_cast<QWSFontEvent *>(event); - if (e->simpleData.type == QWSFontEvent::FontRemoved) { - QFontCache::instance()->removeEngineForFont(e->fontName); - } - } -#endif - - QPointer<QETWidget> widget = static_cast<QETWidget*>(QWidget::find(WId(event->window()))); -#ifdef Q_BACKINGSTORE_SUBSURFACES - if (!widget) { // XXX: hw: hack for accessing subsurfaces - extern QWSWindowSurface* qt_findWindowSurface(int); - QWSWindowSurface *s = qt_findWindowSurface(event->window()); - if (s) - widget = static_cast<QETWidget*>(s->window()); - } -#endif - -#ifndef QT_NO_DIRECTPAINTER - if (!widget && d->directPainters) { - QDirectPainter *dp = d->directPainters->value(WId(event->window())); - if (dp == 0) { - } else if (event->type == QWSEvent::Region) { - QWSRegionEvent *e = static_cast<QWSRegionEvent*>(event); - QRegion reg; - reg.setRects(e->rectangles, e->simpleData.nrectangles); - qt_directpainter_region(dp, reg, e->simpleData.type); - return 1; -#ifndef QT_NO_QWSEMBEDWIDGET - } else if (event->type == QWSEvent::Embed) { - QWSEmbedEvent *e = static_cast<QWSEmbedEvent*>(event); - qt_directpainter_embedevent(dp, e); - return 1; - #endif // QT_NO_QWSEMBEDWIDGET - } - } -#endif // QT_NO_DIRECTPAINTER - -#ifndef QT_NO_QWS_MANAGER - if (d->last_manager && event->type == QWSEvent::Mouse) { - QPoint pos(event->asMouse()->simpleData.x_root, event->asMouse()->simpleData.y_root); - if (!d->last_manager->cachedRegion().contains(pos)) { - // MouseEvent not yet delivered, so QCursor::pos() is not yet updated, sending 2 x pos - QMouseEvent outside(QEvent::MouseMove, pos, pos, Qt::NoButton, 0, 0); - QApplication::sendSpontaneousEvent(d->last_manager, &outside); - d->last_manager = 0; - qt_last_cursor = 0xffffffff; //decoration is like another window; must redo cursor - } - } -#endif // QT_NO_QWS_MANAGER - - QETWidget *keywidget=0; - bool grabbed=false; - if (event->type==QWSEvent::Key || event->type == QWSEvent::IMEvent || event->type == QWSEvent::IMQuery) { - keywidget = static_cast<QETWidget*>(QWidget::keyboardGrabber()); - if (keywidget) { - grabbed = true; - } else { - if (QWidget *popup = QApplication::activePopupWidget()) { - if (popup->focusWidget()) - keywidget = static_cast<QETWidget*>(popup->focusWidget()); - else - keywidget = static_cast<QETWidget*>(popup); - } else if (QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget->isVisible()) - keywidget = static_cast<QETWidget*>(QApplicationPrivate::focus_widget); - else if (widget) - keywidget = static_cast<QETWidget*>(widget->window()); - } - } else if (event->type==QWSEvent::MaxWindowRect) { - QRect r = static_cast<QWSMaxWindowRectEvent*>(event)->simpleData.rect; - setMaxWindowRect(r); - return 0; -#ifndef QT_NO_QWS_DYNAMICSCREENTRANSFORMATION - } else if (event->type == QWSEvent::ScreenTransformation) { - QWSScreenTransformationEvent *pe = static_cast<QWSScreenTransformationEvent*>(event); - setScreenTransformation(pe->simpleData.screen, - pe->simpleData.transformation); - return 0; -#endif - } else if (widget && event->type==QWSEvent::Mouse) { - // The mouse event is to one of my top-level widgets - // which one? - const int btnMask = Qt::LeftButton | Qt::RightButton | Qt::MidButton; - QPoint p(event->asMouse()->simpleData.x_root, - event->asMouse()->simpleData.y_root); - int mouseButtonState = event->asMouse()->simpleData.state & btnMask; - static int btnstate = 0; - - QETWidget *w = static_cast<QETWidget*>(QWidget::mouseGrabber()); - if (w && !mouseButtonState && qt_pressGrab == w) - qt_pressGrab = 0; -#ifndef QT_NO_QWS_MANAGER - if (!w) - w = static_cast<QETWidget*>(QWSManager::grabbedMouse()); -#endif - if (w) { - // Our mouse is grabbed - send it. - widget = w; - btnstate = mouseButtonState; - } else { - static QWidget *gw = 0; - // Three jobs to do here: - // 1. find the child widget this event belongs to. - // 2. make sure the cursor is correct. - // 3. handle implicit mouse grab due to button press. - w = widget; // w is the widget the cursor is in. - - //### ??? alloc_region - //#### why should we get events outside alloc_region ???? - if (1 /*widget->data->alloc_region.contains(dp) */) { - // Find the child widget that the cursor is in. - w = static_cast<QETWidget*>(widget->childAt(widget->mapFromParent(p))); - if (!w) - w = widget; -#ifndef QT_NO_CURSOR - // Update Cursor. - if (!gw || gw != w || qt_last_cursor == 0xffffffff) { - QCursor *curs = 0; - if (!qApp->d_func()->cursor_list.isEmpty()) - curs = &qApp->d_func()->cursor_list.first(); - else if (w->d_func()->extraData()) - curs = w->d_func()->extraData()->curs; - QWidget *pw = w; - // If this widget has no cursor set, try parent. - while (!curs) { - pw = pw->parentWidget(); - if (!pw) - break; - if (pw->d_func()->extraData()) - curs = pw->d_func()->extraData()->curs; - } - if (!qws_overrideCursor) { - if (curs) - QPaintDevice::qwsDisplay()->selectCursor(widget, curs->handle()); - else - QPaintDevice::qwsDisplay()->selectCursor(widget, Qt::ArrowCursor); - } - } -#endif - gw = w; - } else { - // This event is not for any of our widgets - gw = 0; - } - if (mouseButtonState && !btnstate) { - // The server has grabbed the mouse for us. - // Remember which of my widgets has it. - qt_pressGrab = w; - if (!widget->isActiveWindow() && - (!app_do_modal || QApplication::activeModalWidget() == widget) && - !((widget->windowFlags() & Qt::FramelessWindowHint) || (widget->windowType() == Qt::Tool))) { - widget->activateWindow(); - if (widget->raiseOnClick()) - widget->raise(); - } - } - btnstate = mouseButtonState; - widget = w; - } - } - - if (!widget) { // don't know this window - if (!QWidget::mouseGrabber() -#ifndef QT_NO_QWS_MANAGER - && !QWSManager::grabbedMouse() -#endif - ) { - qt_last_cursor = 0xffffffff; // cursor can be changed by another application - } - - QWidget* popup = QApplication::activePopupWidget(); - if (popup) { - - /* - That is more than suboptimal. The real solution should - do some keyevent and buttonevent translation, so that - the popup still continues to work as the user expects. - Unfortunately this translation is currently only - possible with a known widget. I'll change that soon - (Matthias). - */ - - // Danger - make sure we don't lock the server - switch (event->type) { - case QWSEvent::Mouse: - case QWSEvent::Key: - do { - popup->close(); - } while ((popup = qApp->activePopupWidget())); - return 1; - } - } - if (event->type == QWSEvent::Mouse && *mouseInWidget) { - QApplicationPrivate::dispatchEnterLeave(0, *mouseInWidget); - (*mouseInWidget) = 0; - } - return -1; - } - - if (app_do_modal) // modal event handling - if (!qt_try_modal(widget, event)) { - return 1; - } - - if (widget->qwsEvent(event)) // send through widget filter - return 1; - switch (event->type) { - - case QWSEvent::Mouse: { // mouse event - QWSMouseEvent *me = event->asMouse(); - QWSMouseEvent::SimpleData &mouse = me->simpleData; - - // Translate a QWS event into separate move - // and press/release events - // Beware of reentrancy: we can enter a modal state - // inside translateMouseEvent - - if (isMove) { - QWSMouseEvent move = *me; - move.simpleData.state = oldstate; - widget->translateMouseEvent(&move, oldstate); - } - if ((mouse.state&Qt::MouseButtonMask) != (oldstate&Qt::MouseButtonMask)) { - widget->translateMouseEvent(me, oldstate); - } - - if (mouse.delta != 0) - widget->translateWheelEvent(me); - - if (qt_button_down && (mouse_state & Qt::MouseButtonMask) == 0) - qt_button_down = 0; - - break; - } - case QWSEvent::Key: // keyboard event - if (keywidget) // should always exist - keywidget->translateKeyEvent(static_cast<QWSKeyEvent*>(event), grabbed); - break; - -#ifndef QT_NO_QWS_INPUTMETHODS - case QWSEvent::IMEvent: - if (keywidget) // should always exist - QWSInputContext::translateIMEvent(keywidget, static_cast<QWSIMEvent*>(event)); - break; - - case QWSEvent::IMQuery: - if (keywidget) // should always exist - QWSInputContext::translateIMQueryEvent(keywidget, static_cast<QWSIMQueryEvent*>(event)); - break; - - case QWSEvent::IMInit: - QWSInputContext::translateIMInitEvent(static_cast<QWSIMInitEvent*>(event)); - break; -#endif - case QWSEvent::Region: - widget->translateRegionEvent(static_cast<QWSRegionEvent*>(event)); - break; - case QWSEvent::Focus: - if ((static_cast<QWSFocusEvent*>(event))->simpleData.get_focus) { - if (widget == static_cast<QWidget *>(desktop())) - return true; // not interesting - if (activeWindow() != widget) { - setActiveWindow(widget); - if (QApplicationPrivate::active_window) - static_cast<QETWidget *>(QApplicationPrivate::active_window)->repaintDecoration(desktop()->rect(), false); - if (widget && !d->inPopupMode()) { - QWidget *w = widget->focusWidget(); - while (w && w->focusProxy()) - w = w->focusProxy(); - if (w && (w->focusPolicy() != Qt::NoFocus)) - w->setFocus(); - else - widget->QWidget::focusNextPrevChild(true); - if (!QApplicationPrivate::focus_widget) { - if (widget->focusWidget()) - widget->focusWidget()->setFocus(); - else - widget->window()->setFocus(); - } - } - } - } else { // lost focus - if (widget == static_cast<QWidget *>(desktop())) - return true; // not interesting - if (QApplicationPrivate::focus_widget) { - QETWidget *old = static_cast<QETWidget *>(QApplicationPrivate::active_window); - setActiveWindow(0); - qt_last_cursor = 0xffffffff; - //QApplicationPrivate::active_window = 0; - if (old) - old->repaintDecoration(desktop()->rect(), false); - /* activateWindow() sends focus events - QApplication::setFocusWidget(0); - */ - } - } - break; - - case QWSEvent::WindowOperation: - if (static_cast<QWidget *>(widget) == desktop()) - return true; - switch ((static_cast<QWSWindowOperationEvent *>(event))->simpleData.op) { - case QWSWindowOperationEvent::Show: - widget->show(); - break; - case QWSWindowOperationEvent::Hide: - widget->hide(); - break; - case QWSWindowOperationEvent::ShowMaximized: - widget->showMaximized(); - break; - case QWSWindowOperationEvent::ShowMinimized: - widget->showMinimized(); - break; - case QWSWindowOperationEvent::ShowNormal: - widget->showNormal(); - break; - case QWSWindowOperationEvent::Close: - widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); - break; - } - break; -#ifndef QT_NO_QWSEMBEDWIDGET - case QWSEvent::Embed: - widget->translateEmbedEvent(static_cast<QWSEmbedEvent*>(event)); - break; -#endif - default: - break; - } - - return 0; -} - -bool QApplication::qwsEventFilter(QWSEvent *) -{ - return false; -} - -void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors) -{ - if (start < 0 || start > 39) { - qWarning("QApplication::qwsSetCustomColors: start < 0 || start > 39"); - return; - } - if (start + numColors > 40) { - numColors = 40 - start; - qWarning("QApplication::qwsSetCustomColors: Too many colors"); - } - start += 216; - for (int i = 0; i < numColors; i++) { - qt_screen->set(start + i, qRed(colorTable[i]), qGreen(colorTable[i]), - qBlue(colorTable[i])); - } -} - -#ifndef QT_NO_QWS_MANAGER -QDecoration &QApplication::qwsDecoration() -{ - return *qws_decoration; -} - -void QApplication::qwsSetDecoration(QDecoration *dec) -{ - if (dec) { - delete qws_decoration; - qws_decoration = dec; - QWidgetList widgets = topLevelWidgets(); - for (int i = 0; i < widgets.size(); ++i) { - QWidget *w = widgets[i]; - if (w->isVisible() && w != desktop()) { - static_cast<QETWidget *>(w)->updateRegion(); - static_cast<QETWidget *>(w)->repaintDecoration(desktop()->rect(), false); - if (w->isMaximized()) - w->showMaximized(); - } - } - } -} - -QDecoration* QApplication::qwsSetDecoration(const QString &decoration) -{ - QDecoration *decore = QDecorationFactory::create(decoration); - if (!decore) - return 0; - - qwsSetDecoration(decore); - return decore; -} - -#endif - -bool QApplicationPrivate::modalState() -{ - return app_do_modal; -} - -void QApplicationPrivate::enterModal_sys(QWidget *widget) -{ - if (!qt_modal_stack) - qt_modal_stack = new QWidgetList; - qt_modal_stack->insert(0, widget); - app_do_modal = true; -} - -void QApplicationPrivate::leaveModal_sys(QWidget *widget) -{ - if (qt_modal_stack && qt_modal_stack->removeAll(widget)) { - if (qt_modal_stack->isEmpty()) { - delete qt_modal_stack; - qt_modal_stack = 0; - } - } - app_do_modal = qt_modal_stack != 0; -} - -static bool qt_try_modal(QWidget *widget, QWSEvent *event) -{ - QWidget * top = 0; - - if (QApplicationPrivate::tryModalHelper(widget, &top)) - return true; - - bool block_event = false; - bool paint_event = false; - - switch (event->type) { - case QWSEvent::Focus: - if (!static_cast<QWSFocusEvent*>(event)->simpleData.get_focus) - break; - // drop through - case QWSEvent::Mouse: // disallow mouse/key events - case QWSEvent::Key: - block_event = true; - break; - } - - if (top->parentWidget() == 0 && (block_event || paint_event)) - top->raise(); - - return !block_event; -} - -static int openPopupCount = 0; -void QApplicationPrivate::openPopup(QWidget *popup) -{ - openPopupCount++; - if (!popupWidgets) { // create list - popupWidgets = new QWidgetList; - - /* only grab if you are the first/parent popup */ - QPaintDevice::qwsDisplay()->grabMouse(popup,true); - QPaintDevice::qwsDisplay()->grabKeyboard(popup,true); - popupGrabOk = true; - } - popupWidgets->append(popup); // add to end of list - - // popups are not focus-handled by the window system (the first - // popup grabbed the keyboard), so we have to do that manually: A - // new popup gets the focus - if (popup->focusWidget()) { - popup->focusWidget()->setFocus(Qt::PopupFocusReason); - } else if (popupWidgets->count() == 1) { // this was the first popup - if (QWidget *fw = QApplication::focusWidget()) { - QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason); - QApplication::sendEvent(fw, &e); - } - } -} - -void QApplicationPrivate::closePopup(QWidget *popup) -{ - if (!popupWidgets) - return; - - popupWidgets->removeAll(popup); - if (popup == popupOfPopupButtonFocus) { - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - if (popupWidgets->count() == 0) { // this was the last popup - popupCloseDownMode = true; // control mouse events - delete popupWidgets; - popupWidgets = 0; - if (popupGrabOk) { // grabbing not disabled - QPaintDevice::qwsDisplay()->grabMouse(popup,false); - QPaintDevice::qwsDisplay()->grabKeyboard(popup,false); - popupGrabOk = false; - // XXX ungrab keyboard - } - if (active_window) { - if (QWidget *fw = active_window->focusWidget()) { - if (fw != QApplication::focusWidget()) { - fw->setFocus(Qt::PopupFocusReason); - } else { - QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason); - QApplication::sendEvent(fw, &e); - } - } - } - } else { - // popups are not focus-handled by the window system (the - // first popup grabbed the keyboard), so we have to do that - // manually: A popup was closed, so the previous popup gets - // the focus. - QWidget* aw = popupWidgets->last(); - if (QWidget *fw = aw->focusWidget()) - fw->setFocus(Qt::PopupFocusReason); - } -} - -/***************************************************************************** - Event translation; translates FB events to Qt events - *****************************************************************************/ - -// -// Mouse event translation -// -// FB doesn't give mouse double click events, so we generate them by -// comparing window, time and position between two mouse press events. -// - - -// Needed for QCursor::pos - -static const int AnyButton = (Qt::LeftButton | Qt::MidButton | Qt::RightButton); - - - -// -// Wheel event translation -// -bool QETWidget::translateWheelEvent(const QWSMouseEvent *me) -{ -#ifdef QT_NO_WHEELEVENT - Q_UNUSED(me); - return false; -#else - const QWSMouseEvent::SimpleData &mouse = me->simpleData; - - // Figure out wheeling direction: - // Horizontal wheel w/o Alt - // OR Vertical wheel w/ Alt ==> Horizontal wheeling - // ..all other permutations ==> Vertical wheeling - int axis = mouse.delta / 120; // WHEEL_DELTA? - Qt::Orientation orient = ((axis == 2 || axis == -2) && ((mouse.state & Qt::AltModifier) == 0)) - ||((axis == 1 || axis == -1) && mouse.state & Qt::AltModifier) - ? Qt::Horizontal : Qt::Vertical; - - QPoint mousePoint = QPoint(mouse.x_root, mouse.y_root); - - // send the event to the widget or its ancestors - QWidget* popup = qApp->activePopupWidget(); - if (popup && window() != popup) - popup->close(); - QWheelEvent we(mapFromGlobal(mousePoint), mousePoint, mouse.delta, - Qt::MouseButtons(mouse.state & Qt::MouseButtonMask), - Qt::KeyboardModifiers(mouse.state & Qt::KeyboardModifierMask), orient); - if (QApplication::sendSpontaneousEvent(this, &we)) - return true; - - // send the event to the widget that has the focus or its ancestors, if different - QWidget *w = this; - if (w != qApp->focusWidget() && (w = qApp->focusWidget())) { - QWidget* popup = qApp->activePopupWidget(); - if (popup && w != popup) - popup->hide(); - if (QApplication::sendSpontaneousEvent(w, &we)) - return true; - } - return false; -#endif -} - -bool QETWidget::translateMouseEvent(const QWSMouseEvent *event, int prevstate) -{ - static bool manualGrab = false; - QPoint pos; - QPoint globalPos; - int button = 0; - - if (sm_blockUserInput) // block user interaction during session management - return true; - const QWSMouseEvent::SimpleData &mouse = event->simpleData; - pos = mapFromGlobal(QPoint(mouse.x_root, mouse.y_root)); -// if (qt_last_x) { -// *qt_last_x=mouse.x_root; -// *qt_last_y=mouse.y_root; -// } - globalPos.rx() = mouse.x_root; - globalPos.ry() = mouse.y_root; - - QEvent::Type type = QEvent::None; - - Qt::MouseButtons buttonstate = Qt::MouseButtons(mouse.state & Qt::MouseButtonMask); - Qt::KeyboardModifiers keystate = Qt::KeyboardModifiers(mouse.state & Qt::KeyboardModifierMask); - - if (mouse.state == prevstate) { - // mouse move - type = QEvent::MouseMove; - } else if ((mouse.state&AnyButton) != (prevstate&AnyButton)) { - Qt::MouseButtons current_buttons = Qt::MouseButtons(prevstate&Qt::MouseButtonMask); - for (button = Qt::LeftButton; !type && button <= Qt::MidButton; button<<=1) { - if ((mouse.state&button) != (current_buttons&button)) { - // button press or release - current_buttons = Qt::MouseButtons(current_buttons ^ button); - -#ifndef QT_NO_QWS_INPUTMETHODS - //############ We used to do a QInputContext::reset(oldFocus); - // when we changed the focus widget. See change 93389 for where the - // focus code went. The IM code was (after testing for ClickToFocus): - //if (mouse.state&button && w != QInputContext::microFocusWidget()) //button press - // QInputContext::reset(oldFocus); - -#endif - if (mouse.state&button) { //button press - qt_button_down = childAt(pos); - if (!qt_button_down) - qt_button_down = this; - if (/*XXX mouseActWindow == this &&*/ - mouseButtonPressed == button && - long(mouse.time) -long(mouseButtonPressTime) - < QApplication::doubleClickInterval() && - qAbs(mouse.x_root - mouseXPos) < mouse_double_click_distance && - qAbs(mouse.y_root - mouseYPos) < mouse_double_click_distance ) { - type = QEvent::MouseButtonDblClick; - mouseButtonPressTime -= 2000; // no double-click next time - } else { - type = QEvent::MouseButtonPress; - mouseButtonPressTime = mouse.time; - } - mouseButtonPressed = button; // save event params for - mouseXPos = globalPos.x(); // future double click tests - mouseYPos = globalPos.y(); - } else { // mouse button released - if (manualGrab) { // release manual grab - manualGrab = false; - // XXX XUngrabPointer(x11Display(), CurrentTime); - } - - type = QEvent::MouseButtonRelease; - } - } - } - button >>= 1; - } - //XXX mouseActWindow = winId(); // save some event params - - if (type == 0) { // event consumed - return false; //EXIT in the normal case - } - - if (qApp->d_func()->inPopupMode()) { // in popup mode - QWidget *popup = qApp->activePopupWidget(); - // in X11, this would be the window we are over. - // in QWS this is the top level popup. to allow mouse - // events to other widgets, need to go through qApp->QApplicationPrivate::popupWidgets. - QSize s(qt_screen->width(), qt_screen->height()); - for (int i = 0; i < QApplicationPrivate::popupWidgets->size(); ++i) { - QWidget *w = QApplicationPrivate::popupWidgets->at(i); - - if ((w->windowType() == Qt::Popup) && w->d_func()->localAllocatedRegion().contains(globalPos - w->geometry().topLeft())) - { - popup = w; - break; - } - } - pos = popup->mapFromGlobal(globalPos); - bool releaseAfter = false; - QWidget *popupChild = popup->childAt(pos); - QWidget *popupTarget = popupChild ? popupChild : popup; - - if (popup != popupOfPopupButtonFocus){ - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - - if (!popupTarget->isEnabled()) { - return false; //EXIT special case - } - - switch (type) { - case QEvent::MouseButtonPress: - case QEvent::MouseButtonDblClick: - popupButtonFocus = popupChild; - popupOfPopupButtonFocus = popup; - break; - case QEvent::MouseButtonRelease: - releaseAfter = true; - break; - default: - break; // nothing for mouse move - } - - int oldOpenPopupCount = openPopupCount; - - if (popupButtonFocus) { - QMouseEvent e(type, popupButtonFocus->mapFromGlobal(globalPos), - globalPos, Qt::MouseButton(button), buttonstate, keystate); - QApplication::sendSpontaneousEvent(popupButtonFocus, & e); - if (releaseAfter) { - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - } else if (popupChild) { - QMouseEvent e(type, popupChild->mapFromGlobal(globalPos), - globalPos, Qt::MouseButton(button), buttonstate, keystate); - QApplication::sendSpontaneousEvent(popupChild, & e); - } else { - QMouseEvent e(type, pos, globalPos, Qt::MouseButton(button), buttonstate, keystate); - QApplication::sendSpontaneousEvent(popupChild ? popupChild : popup, & e); - } -#ifndef QT_NO_CONTEXTMENU - if (type == QEvent::MouseButtonPress && button == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { - QWidget *popupEvent = popup; - if(popupButtonFocus) - popupEvent = popupButtonFocus; - else if(popupChild) - popupEvent = popupChild; - QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, keystate); - QApplication::sendSpontaneousEvent(popupEvent, &e); - } -#endif // QT_NO_CONTEXTMENU - - if (releaseAfter) - qt_button_down = 0; - - } else { //qApp not in popup mode - QWidget *widget = this; - QWidget *w = QWidget::mouseGrabber(); - if (!w && qt_button_down) - w = qt_button_down; - if (w && w != this) { - widget = w; - pos = mapToGlobal(pos); - pos = w->mapFromGlobal(pos); - } - - if (popupCloseDownMode) { - popupCloseDownMode = false; - if ((windowType() == Qt::Popup)) // ignore replayed event - return true; //EXIT - } - - QPointer<QWidget> leaveAfterRelease = 0; - if (type == QEvent::MouseButtonRelease && - (mouse.state & (~button) & (Qt::LeftButton | - Qt::MidButton | - Qt::RightButton)) == 0) { - // Button released outside the widget -> leave the widget after the - // release event has been delivered. - if (widget == qt_button_down && (pos.x() < 0 || pos.y() < 0)) - leaveAfterRelease = qt_button_down; - qt_button_down = 0; - } - - int oldOpenPopupCount = openPopupCount; - - QMouseEvent e(type, pos, globalPos, Qt::MouseButton(button), buttonstate, keystate); -#ifndef QT_NO_QWS_MANAGER - if (widget->isWindow() && widget->d_func()->topData()->qwsManager - && (widget->d_func()->topData()->qwsManager->region().contains(globalPos) - || QWSManager::grabbedMouse() )) { - if ((*mouseInWidget)) { - QApplicationPrivate::dispatchEnterLeave(0, *mouseInWidget); - (*mouseInWidget) = 0; - } - QApplication::sendSpontaneousEvent(widget->d_func()->topData()->qwsManager, &e); - qApp->d_func()->last_manager = widget->d_func()->topData()->qwsManager; - } else -#endif - { - if (widget != (*mouseInWidget)) { - QApplicationPrivate::dispatchEnterLeave(widget, *mouseInWidget); - (*mouseInWidget) = widget; - qt_last_mouse_receiver = widget; - } - QApplication::sendSpontaneousEvent(widget, &e); - if (leaveAfterRelease && !QWidget::mouseGrabber()) { - *mouseInWidget = QApplication::widgetAt(globalPos); - qt_last_mouse_receiver = *mouseInWidget; - QApplicationPrivate::dispatchEnterLeave(*mouseInWidget, leaveAfterRelease); - leaveAfterRelease = 0; - } - } -#ifndef QT_NO_CONTEXTMENU - if (type == QEvent::MouseButtonPress && button == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { - QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, keystate); - QApplication::sendSpontaneousEvent(widget, &e); - } -#endif // QT_NO_CONTEXTMENU - } - return true; -} - - -bool QETWidget::translateKeyEvent(const QWSKeyEvent *event, bool grab) /* grab is used in the #ifdef */ -{ - int code = -1; - //### Qt assumes keyboard state is state *before*, while QWS uses state after the event - static Qt::KeyboardModifiers oldstate; - Qt::KeyboardModifiers state = oldstate; - oldstate = event->simpleData.modifiers; - - if (sm_blockUserInput) // block user interaction during session management - return true; - - if (!isEnabled()) - return true; - - QEvent::Type type = event->simpleData.is_press ? - QEvent::KeyPress : QEvent::KeyRelease; - bool autor = event->simpleData.is_auto_repeat; - QString text; - char ascii = 0; - if (event->simpleData.unicode) { - QChar ch(event->simpleData.unicode); - if (ch.unicode() != 0xffff) - text += ch; - ascii = ch.toLatin1(); - } - code = event->simpleData.keycode; - -#if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT) - if (type == QEvent::KeyPress && !grab - && static_cast<QApplicationPrivate*>(qApp->d_ptr.data())->use_compat()) { - // send accel events if the keyboard is not grabbed - QKeyEvent a(type, code, state, text, autor, int(text.length())); - if (static_cast<QApplicationPrivate*>(qApp->d_ptr.data())->qt_tryAccelEvent(this, &a)) - return true; - } -#else - Q_UNUSED(grab); -#endif - if (!text.isEmpty() && testAttribute(Qt::WA_KeyCompression)) { - // the widget wants key compression so it gets it - - // XXX not implemented - } - - QKeyEvent e(type, code, state, text, autor, int(text.length())); - return QApplication::sendSpontaneousEvent(this, &e); -} - -bool QETWidget::translateRegionEvent(const QWSRegionEvent *event) -{ - QWSWindowSurface *surface = static_cast<QWSWindowSurface*>(windowSurface()); - Q_ASSERT(surface); - - QRegion region; - region.setRects(event->rectangles, event->simpleData.nrectangles); - - switch (event->simpleData.type) { - case QWSRegionEvent::Allocation: - region.translate(-mapToGlobal(QPoint())); - surface->setClipRegion(region); - break; -#ifdef QT_QWS_CLIENTBLIT - case QWSRegionEvent::DirectPaint: - surface->setDirectRegion(region, event->simpleData.id); - break; -#endif - default: - break; - } - - return true; -} - -#ifndef QT_NO_QWSEMBEDWIDGET -void QETWidget::translateEmbedEvent(const QWSEmbedEvent *event) -{ - if (event->simpleData.type | QWSEmbedEvent::Region) { - const QRegion region = event->region; - setGeometry(region.boundingRect()); - setVisible(!region.isEmpty()); - } -} -#endif // QT_NO_QWSEMBEDWIDGET - -void QETWidget::repaintDecoration(QRegion r, bool post) -{ - Q_UNUSED(post); -#ifdef QT_NO_QWS_MANAGER - Q_UNUSED(r); -#else - //please note that qwsManager is a QObject, not a QWidget. - //therefore, normal ways of painting do not work. - // However, it does listen to paint events. - - Q_D(QWidget); - if (isWindow() && d->topData()->qwsManager && isVisible()) { - QWSManager *manager = d->topData()->qwsManager; - r &= manager->region(); - if (!r.isEmpty()) - manager->repaintRegion(QDecoration::All, QDecoration::Normal); - } -#endif -} - -void QETWidget::updateRegion() -{ - Q_D(QWidget); - - QTLWExtra *topextra = d->maybeTopData(); - if (!topextra) - return; - - QRegion myregion = d->localRequestedRegion(); - myregion.translate(geometry().topLeft()); - -#ifndef QT_NO_QWS_MANAGER - QWSManager *manager = topextra->qwsManager; - if (manager) - myregion += manager->region(); -#endif - - QRect br(myregion.boundingRect()); - topextra->frameStrut.setCoords(d->data.crect.x() - br.x(), - d->data.crect.y() - br.y(), - br.right() - d->data.crect.right(), - br.bottom() - d->data.crect.bottom()); -} - -void QApplication::setCursorFlashTime(int msecs) -{ - QApplicationPrivate::cursor_flash_time = msecs; -} - - -int QApplication::cursorFlashTime() -{ - return QApplicationPrivate::cursor_flash_time; -} - -void QApplication::setDoubleClickInterval(int ms) -{ - QApplicationPrivate::mouse_double_click_time = ms; -} - -int QApplication::doubleClickInterval() -{ - return QApplicationPrivate::mouse_double_click_time; -} - -void QApplication::setKeyboardInputInterval(int ms) -{ - QApplicationPrivate::keyboard_input_time = ms; -} - -int QApplication::keyboardInputInterval() -{ - return QApplicationPrivate::keyboard_input_time; -} - -#ifndef QT_NO_WHEELEVENT -void QApplication::setWheelScrollLines(int lines) -{ - QApplicationPrivate::wheel_scroll_lines = lines; -} - -int QApplication::wheelScrollLines() -{ - return QApplicationPrivate::wheel_scroll_lines; -} -#endif - -void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) -{ - switch (effect) { - case Qt::UI_AnimateMenu: - QApplicationPrivate::animate_menu = enable; - break; - case Qt::UI_FadeMenu: - if (enable) - QApplicationPrivate::animate_menu = true; - QApplicationPrivate::fade_menu = enable; - break; - case Qt::UI_AnimateCombo: - QApplicationPrivate::animate_combo = enable; - break; - case Qt::UI_AnimateTooltip: - QApplicationPrivate::animate_tooltip = enable; - break; - case Qt::UI_FadeTooltip: - if (enable) - QApplicationPrivate::animate_tooltip = true; - QApplicationPrivate::fade_tooltip = enable; - break; - case Qt::UI_AnimateToolBox: - QApplicationPrivate::animate_toolbox = enable; - break; - default: - QApplicationPrivate::animate_ui = enable; - break; - } -} - -bool QApplication::isEffectEnabled(Qt::UIEffect effect) -{ - if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui) - return false; - - switch(effect) { - case Qt::UI_AnimateMenu: - return QApplicationPrivate::animate_menu; - case Qt::UI_FadeMenu: - return QApplicationPrivate::fade_menu; - case Qt::UI_AnimateCombo: - return QApplicationPrivate::animate_combo; - case Qt::UI_AnimateTooltip: - return QApplicationPrivate::animate_tooltip; - case Qt::UI_FadeTooltip: - return QApplicationPrivate::fade_tooltip; - case Qt::UI_AnimateToolBox: - return QApplicationPrivate::animate_toolbox; - default: - return QApplicationPrivate::animate_ui; - } -} - -void QApplication::setArgs(int c, char **v) -{ - Q_D(QApplication); - d->argc = c; - d->argv = v; -} - -void QApplicationPrivate::initializeMultitouch_sys() -{ } -void QApplicationPrivate::cleanupMultitouch_sys() -{ } - -/* \internal - This is used to clean up the qws server - in case the QApplication constructor threw an exception -*/ -QWSServerCleaner::~QWSServerCleaner() -{ - if (qwsServer && qws_single_process) - QWSServer::closedown(); -} - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qclipboard_qws.cpp b/src/gui/kernel/qclipboard_qws.cpp deleted file mode 100644 index d50b412215..0000000000 --- a/src/gui/kernel/qclipboard_qws.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qclipboard.h" - -#ifndef QT_NO_CLIPBOARD - -#include "qapplication.h" -#include "qbitmap.h" -#include "qdatetime.h" -#include "qbuffer.h" -#include "qwidget.h" -#include "qevent.h" - -#include <qwsdisplay_qws.h> -#include <qwsproperty_qws.h> -#include <qwsevent_qws.h> - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - - -/***************************************************************************** - Internal QClipboard functions for Qt for Embedded Linux - *****************************************************************************/ - -static const int TextClipboard=424242; -static bool init = false; - -static inline void qwsInitClipboard() -{ - //### this should go into QWSServer; it only needs to happen once. - if( !init ) { - QPaintDevice::qwsDisplay()->addProperty(0, TextClipboard); - init = true; - } -} - -static QString qwsClipboardText() -{ - char * data; - int len; - qwsInitClipboard(); - if( !QPaintDevice::qwsDisplay()->getProperty(0, TextClipboard, data, len) ) { -// qDebug("Property received: %d bytes", len); - } - - QString s((const QChar*)data, len/sizeof(QChar)); - // qDebug("Property received: '%s'", s.toAscii().constData()); - delete[] data; - return s; -} - - -static void qwsSetClipboardText(const QString& s) -{ - qwsInitClipboard(); - // qDebug("qwsSetClipboardText( %s )", s.toAscii().data()); - int len = s.length()*sizeof(QChar); - QByteArray ba((const char*)s.unicode(), len); - QPaintDevice::qwsDisplay()-> - setProperty(0, TextClipboard, QWSPropertyManager::PropReplace, ba); - -} - -class QClipboardData -{ -public: - QClipboardData(); - ~QClipboardData(); - - void setSource(QMimeData* s) - { - if (s == src) - return; - delete src; - src = s; - } - QMimeData* source() - { return src; } -#if 0 - void addTransferredPixmap(QPixmap pm) - { /* TODO: queue them */ - transferred[tindex] = pm; - tindex=(tindex+1)%2; - } - void clearTransfers() - { - transferred[0] = QPixmap(); - transferred[1] = QPixmap(); - } -#endif - - void clear(); - -private: - QMimeData* src; - -#if 0 - QPixmap transferred[2]; - int tindex; -#endif -}; - -QClipboardData::QClipboardData() -{ - src = 0; -#if 0 - tindex=0; -#endif -} - -QClipboardData::~QClipboardData() -{ - delete src; -} - -void QClipboardData::clear() -{ - delete src; - src = 0; -} - - -static QClipboardData *internalCbData = 0; - -static void cleanupClipboardData() -{ - delete internalCbData; - internalCbData = 0; -} - -static QClipboardData *clipboardData() -{ - if (internalCbData == 0) { - internalCbData = new QClipboardData; - qAddPostRoutine(cleanupClipboardData); - } - return internalCbData; -} - - -/***************************************************************************** - QClipboard member functions for FB. - *****************************************************************************/ - -#if 0 - -QString QClipboard::text() const -{ - return qwsClipboardText(); -} - -void QClipboard::setText(const QString &text) -{ - qwsSetClipboardText(text); -} - -QString QClipboard::text(QString& subtype) const -{ - QString r; - if (subtype == "plain") - r = text(); - return r; -} - -#endif - -void QClipboard::clear(Mode mode) -{ - setText(QString(), mode); -} - - -bool QClipboard::event(QEvent *e) -{ - static bool recursionWatch = false; - if (e->type() != QEvent::Clipboard || recursionWatch) - return QObject::event(e); - - recursionWatch = true; - QWSPropertyNotifyEvent *event = (QWSPropertyNotifyEvent *)(((QClipboardEvent *)e)->data()); - if (event && event->simpleData.state == QWSPropertyNotifyEvent::PropertyNewValue) { - QClipboardData *d = clipboardData(); - QString t = qwsClipboardText(); - if( (d->source() == 0 && !t.isEmpty()) || (d->source() != 0 && d->source()->text() != t) ) { - if( !d->source() ) - d->setSource(new QMimeData); - d->source()->setText( t ); - emitChanged(QClipboard::Clipboard); - } - } - - recursionWatch = false; - return true; -} - -const QMimeData* QClipboard::mimeData(Mode mode) const -{ - if (mode != Clipboard) return 0; - - QClipboardData *d = clipboardData(); - // Try and get data from QWSProperty if no mime data has been set on us. - if( !d->source() ) { - QString t = qwsClipboardText(); - if( !t.isEmpty() ) { - QMimeData* nd = new QMimeData; - nd->setText( t ); - d->setSource( nd ); - } - } - return d->source(); -} - -void QClipboard::setMimeData(QMimeData* src, Mode mode) -{ - if (mode != Clipboard) return; - - QClipboardData *d = clipboardData(); - - /* Propagate text data to other QWSClients */ - - QString newText; - if( src != 0 ) - newText = src->text(); - QString oldText; - if( d->source() != 0 ) - oldText = d->source()->text(); - - d->setSource(src); - - if( oldText != newText ) { - if( d->source() == 0 ) { - qwsSetClipboardText( QString() ); - } else { - qwsSetClipboardText( d->source()->text() ); - } - } - - emitChanged(QClipboard::Clipboard); -} - -bool QClipboard::supportsMode(Mode mode) const -{ - return (mode == Clipboard); -} - -bool QClipboard::ownsMode(Mode mode) const -{ - if (mode == Clipboard) - qWarning("QClipboard::ownsClipboard: UNIMPLEMENTED!"); - return false; -} - -void QClipboard::connectNotify( const char * ) -{ -} - -void QClipboard::ownerDestroyed() -{ -} - -#endif // QT_NO_CLIPBOARD - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qcursor_qws.cpp b/src/gui/kernel/qcursor_qws.cpp deleted file mode 100644 index 60674c9507..0000000000 --- a/src/gui/kernel/qcursor_qws.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qcursor.h> -#include <private/qcursor_p.h> -#include <qbitmap.h> -#include <qwsdisplay_qws.h> - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - -#ifndef QT_NO_CURSOR - -static int nextCursorId = Qt::BitmapCursor; - -/***************************************************************************** - Internal QCursorData class - *****************************************************************************/ - -QCursorData::QCursorData(Qt::CursorShape s) - : cshape(s), bm(0), bmm(0), hx(0), hy(0), id(s) -{ - ref = 1; -} - -QCursorData::~QCursorData() -{ - delete bm; - delete bmm; - QT_TRY { - QPaintDevice::qwsDisplay()->destroyCursor(id); - } QT_CATCH(const std::bad_alloc &) { - // do nothing. - } -} - - -/***************************************************************************** - Global cursors - *****************************************************************************/ - -int QCursor::handle() const -{ - return d->id; -} - - -QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY) -{ - if (!QCursorData::initialized) - QCursorData::initialize(); - if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) { - qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)"); - QCursorData *c = qt_cursorTable[0]; - c->ref.ref(); - return c; - } - QCursorData *d = new QCursorData; - d->bm = new QBitmap(bitmap); - d->bmm = new QBitmap(mask); - d->cshape = Qt::BitmapCursor; - d->id = ++nextCursorId; - d->hx = hotX >= 0 ? hotX : bitmap.width() / 2; - d->hy = hotY >= 0 ? hotY : bitmap.height() / 2; - - QPaintDevice::qwsDisplay()->defineCursor(d->id, *d->bm, *d->bmm, d->hx, d->hy); - return d; -} - -void QCursorData::update() -{ -} - -#endif //QT_NO_CURSOR - -extern int *qt_last_x,*qt_last_y; - -QPoint QCursor::pos() -{ - // This doesn't know about hotspots yet so we disable it - //qt_accel_update_cursor(); - if (qt_last_x) - return QPoint(*qt_last_x, *qt_last_y); - else - return QPoint(); -} - -void QCursor::setPos(int x, int y) -{ - // Need to check, since some X servers generate null mouse move - // events, causing looping in applications which call setPos() on - // every mouse move event. - // - if (pos() == QPoint(x, y)) - return; - QPaintDevice::qwsDisplay()->setCursorPosition(x, y); -} - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qdesktopwidget_qws.cpp b/src/gui/kernel/qdesktopwidget_qws.cpp deleted file mode 100644 index 1e21845df6..0000000000 --- a/src/gui/kernel/qdesktopwidget_qws.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdesktopwidget.h" -#include "qscreen_qws.h" -#include "private/qapplication_p.h" - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - -QDesktopWidget::QDesktopWidget() - : QWidget(0, Qt::Desktop) -{ - setObjectName(QLatin1String("desktop")); -} - -QDesktopWidget::~QDesktopWidget() -{ -} - -bool QDesktopWidget::isVirtualDesktop() const -{ - return true; -} - -int QDesktopWidget::primaryScreen() const -{ - return 0; -} - -int QDesktopWidget::numScreens() const -{ - QScreen *screen = QScreen::instance(); - if (!screen) - return 0; - - const QList<QScreen*> subScreens = screen->subScreens(); - return qMax(subScreens.size(), 1); -} - -QWidget *QDesktopWidget::screen(int) -{ - return this; -} - -const QRect QDesktopWidget::availableGeometry(int screenNo) const -{ - const QScreen *screen = QScreen::instance(); - if (screenNo == -1) - screenNo = 0; - if (!screen || screenNo < 0) - return QRect(); - - const QList<QScreen*> subScreens = screen->subScreens(); - if (!subScreens.isEmpty()) { - if (screenNo >= subScreens.size()) - return QRect(); - screen = subScreens.at(screenNo); - } - - QApplicationPrivate *ap = QApplicationPrivate::instance(); - const QRect r = ap->maxWindowRect(screen); - if (!r.isEmpty()) - return r; - - return screen->region().boundingRect(); -} - -const QRect QDesktopWidget::screenGeometry(int screenNo) const -{ - const QScreen *screen = QScreen::instance(); - if (screenNo == -1) - screenNo = 0; - if (!screen || screenNo < 0) - return QRect(); - - const QList<QScreen*> subScreens = screen->subScreens(); - if (subScreens.size() == 0 && screenNo == 0) - return screen->region().boundingRect(); - - if (screenNo >= subScreens.size()) - return QRect(); - - return subScreens.at(screenNo)->region().boundingRect(); -} - -int QDesktopWidget::screenNumber(const QWidget *w) const -{ - if (!w) - return 0; - - QRect frame = w->frameGeometry(); - if (!w->isWindow()) - frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0))); - const QPoint midpoint = (frame.topLeft() + frame.bottomRight()) / 2; - return screenNumber(midpoint); -} - -int QDesktopWidget::screenNumber(const QPoint &p) const -{ - const QScreen *screen = QScreen::instance(); - if (!screen || !screen->region().contains(p)) - return -1; - - const QList<QScreen*> subScreens = screen->subScreens(); - if (subScreens.size() == 0) - return 0; - - for (int i = 0; i < subScreens.size(); ++i) - if (subScreens.at(i)->region().contains(p)) - return i; - - return -1; -} - -void QDesktopWidget::resizeEvent(QResizeEvent *) -{ -} - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qdnd_qws.cpp b/src/gui/kernel/qdnd_qpa.cpp index b744c2f085..b744c2f085 100644 --- a/src/gui/kernel/qdnd_qws.cpp +++ b/src/gui/kernel/qdnd_qpa.cpp diff --git a/src/gui/kernel/qeventdispatcher_glib_qws.cpp b/src/gui/kernel/qeventdispatcher_glib_qws.cpp deleted file mode 100644 index 7a800cea07..0000000000 --- a/src/gui/kernel/qeventdispatcher_glib_qws.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qeventdispatcher_glib_qws_p.h" - -#include "qapplication.h" - -#include "qplatformdefs.h" -#include "qapplication.h" -#include "private/qwscommand_qws_p.h" -#include "qwsdisplay_qws.h" -#include "qwsevent_qws.h" -#include "qwindowsystem_qws.h" - -#include <glib.h> - -QT_BEGIN_NAMESPACE - -// from qapplication_qws.cpp -extern QWSDisplay* qt_fbdpy; // QWS `display' - -//from qwindowsystem_qws.cpp -extern QList<QWSCommand*> *qt_get_server_queue(); - -struct GQWSEventSource -{ - GSource source; - QEventLoop::ProcessEventsFlags flags; - QWSEventDispatcherGlib *q; - QWSEventDispatcherGlibPrivate *d; -}; - -class QWSEventDispatcherGlibPrivate : public QEventDispatcherGlibPrivate -{ - Q_DECLARE_PUBLIC(QWSEventDispatcherGlib) - -public: - QWSEventDispatcherGlibPrivate(); - GQWSEventSource *qwsEventSource; - QList<QWSEvent*> queuedUserInputEvents; -}; - -static gboolean qwsEventSourcePrepare(GSource *s, gint *timeout) -{ - if (timeout) - *timeout = -1; - GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s); - return qt_fbdpy->eventPending() || !source->d->queuedUserInputEvents.isEmpty() - || !qt_get_server_queue()->isEmpty() ; -} - -static gboolean qwsEventSourceCheck(GSource *s) -{ - GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s); - return qt_fbdpy->eventPending() || !source->d->queuedUserInputEvents.isEmpty() - || !qt_get_server_queue()->isEmpty() ; -} - -static gboolean qwsEventSourceDispatch(GSource *s, GSourceFunc callback, gpointer user_data) -{ - GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s); - - //??? ulong marker = XNextRequest(X11->display); - do { - QWSEvent *event; - if (!(source->flags & QEventLoop::ExcludeUserInputEvents) - && !source->d->queuedUserInputEvents.isEmpty()) { - // process a pending user input event - event = source->d->queuedUserInputEvents.takeFirst(); - } else if (qt_fbdpy->eventPending()) { - event = qt_fbdpy->getEvent(); - - if (source->flags & QEventLoop::ExcludeUserInputEvents) { - // queue user input events - - if (event->type == QWSEvent::Mouse || event->type == QWSEvent::Key) { - source->d->queuedUserInputEvents.append(event); - continue; - } - } - } else { - // no event to process - break; - } - - // send through event filter - if (source->q->filterEvent(event)) { - delete event; - continue; - } - - bool ret = qApp->qwsProcessEvent(event) == 1; - delete event; - if (ret) { - return true; - } - - } while (qt_fbdpy->eventPending()); - - if (callback) - callback(user_data); - return true; -} - -static GSourceFuncs qwsEventSourceFuncs = { - qwsEventSourcePrepare, - qwsEventSourceCheck, - qwsEventSourceDispatch, - NULL, - NULL, - NULL -}; - -QWSEventDispatcherGlibPrivate::QWSEventDispatcherGlibPrivate() -{ - qwsEventSource = reinterpret_cast<GQWSEventSource *>(g_source_new(&qwsEventSourceFuncs, - sizeof(GQWSEventSource))); - g_source_set_can_recurse(&qwsEventSource->source, true); - - qwsEventSource->flags = QEventLoop::AllEvents; - qwsEventSource->q = 0; - qwsEventSource->d = 0; - - g_source_attach(&qwsEventSource->source, mainContext); -} - -QWSEventDispatcherGlib::QWSEventDispatcherGlib(QObject *parent) - : QEventDispatcherGlib(*new QWSEventDispatcherGlibPrivate, parent) -{ -} - -QWSEventDispatcherGlib::~QWSEventDispatcherGlib() -{ - Q_D(QWSEventDispatcherGlib); - - g_source_destroy(&d->qwsEventSource->source); - d->qwsEventSource = 0; -} - -bool QWSEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) -{ - Q_D(QWSEventDispatcherGlib); - QEventLoop::ProcessEventsFlags saved_flags = d->qwsEventSource->flags; - d->qwsEventSource->flags = flags; - bool returnValue = QEventDispatcherGlib::processEvents(flags); - d->qwsEventSource->flags = saved_flags; - return returnValue; -} - -void QWSEventDispatcherGlib::startingUp() -{ - Q_D(QWSEventDispatcherGlib); - d->qwsEventSource->q = this; - d->qwsEventSource->d = d; -} - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qeventdispatcher_glib_qws_p.h b/src/gui/kernel/qeventdispatcher_glib_qws_p.h deleted file mode 100644 index 66cb2fc9dc..0000000000 --- a/src/gui/kernel/qeventdispatcher_glib_qws_p.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWSEVENTDISPATCHER_GLIB_P_H -#define QWSEVENTDISPATCHER_GLIB_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of the QLibrary class. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/private/qeventdispatcher_glib_p.h> - -QT_BEGIN_NAMESPACE - -class QWSEventDispatcherGlibPrivate; - -class QWSEventDispatcherGlib : public QEventDispatcherGlib -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QWSEventDispatcherGlib) - -public: - explicit QWSEventDispatcherGlib(QObject *parent = 0); - ~QWSEventDispatcherGlib(); - - bool processEvents(QEventLoop::ProcessEventsFlags flags); - - void startingUp(); -}; - -QT_END_NAMESPACE - -#endif // QWSEVENTDISPATCHER_GLIB_P_H diff --git a/src/gui/kernel/qeventdispatcher_qws.cpp b/src/gui/kernel/qeventdispatcher_qws.cpp deleted file mode 100644 index c5df07ea86..0000000000 --- a/src/gui/kernel/qeventdispatcher_qws.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" -#include "qapplication.h" -#include "private/qwscommand_qws_p.h" -#include "qwsdisplay_qws.h" -#include "qwsevent_qws.h" -#include "qwindowsystem_qws.h" -#include "qeventdispatcher_qws_p.h" -#include "private/qeventdispatcher_unix_p.h" -#ifndef QT_NO_THREAD -# include "qmutex.h" -#endif - -#include <errno.h> - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - -class QEventDispatcherQWSPrivate : public QEventDispatcherUNIXPrivate -{ - Q_DECLARE_PUBLIC(QEventDispatcherQWS) -public: - inline QEventDispatcherQWSPrivate() - { } - QList<QWSEvent*> queuedUserInputEvents; -}; - - -QEventDispatcherQWS::QEventDispatcherQWS(QObject *parent) - : QEventDispatcherUNIX(*new QEventDispatcherQWSPrivate, parent) -{ } - -QEventDispatcherQWS::~QEventDispatcherQWS() -{ } - - - -// from qapplication_qws.cpp -extern QWSDisplay* qt_fbdpy; // QWS `display' - -//#define ZERO_FOR_THE_MOMENT - -bool QEventDispatcherQWS::processEvents(QEventLoop::ProcessEventsFlags flags) -{ - Q_D(QEventDispatcherQWS); - // process events from the QWS server - int nevents = 0; - - // handle gui and posted events - d->interrupt = false; - QApplication::sendPostedEvents(); - - while (!d->interrupt) { // also flushes output buffer ###can be optimized - QWSEvent *event; - if (!(flags & QEventLoop::ExcludeUserInputEvents) - && !d->queuedUserInputEvents.isEmpty()) { - // process a pending user input event - event = d->queuedUserInputEvents.takeFirst(); - } else if (qt_fbdpy->eventPending()) { - event = qt_fbdpy->getEvent(); // get next event - if (flags & QEventLoop::ExcludeUserInputEvents) { - // queue user input events - if (event->type == QWSEvent::Mouse || event->type == QWSEvent::Key) { - d->queuedUserInputEvents.append(event); - continue; - } - } - } else { - break; - } - - if (filterEvent(event)) { - delete event; - continue; - } - nevents++; - - bool ret = qApp->qwsProcessEvent(event) == 1; - delete event; - if (ret) { - return true; - } - } - - if (!d->interrupt) { - extern QList<QWSCommand*> *qt_get_server_queue(); - if (!qt_get_server_queue()->isEmpty()) { - QWSServer::processEventQueue(); - } - - if (QEventDispatcherUNIX::processEvents(flags)) - return true; - } - return (nevents > 0); -} - -bool QEventDispatcherQWS::hasPendingEvents() -{ - extern uint qGlobalPostedEventsCount(); // from qapplication.cpp - return qGlobalPostedEventsCount() || qt_fbdpy->eventPending(); -} - -void QEventDispatcherQWS::startingUp() -{ - -} - -void QEventDispatcherQWS::closingDown() -{ - -} - -void QEventDispatcherQWS::flush() -{ - if(qApp) - qApp->sendPostedEvents(); - (void)qt_fbdpy->eventPending(); // flush -} - - -int QEventDispatcherQWS::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - timeval *timeout) -{ - return QEventDispatcherUNIX::select(nfds, readfds, writefds, exceptfds, timeout); -} - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qeventdispatcher_qws_p.h b/src/gui/kernel/qeventdispatcher_qws_p.h deleted file mode 100644 index e73ed6ce5e..0000000000 --- a/src/gui/kernel/qeventdispatcher_qws_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QEVENTDISPATCHER_QWS_P_H -#define QEVENTDISPATCHER_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "private/qeventdispatcher_unix_p.h" - -QT_BEGIN_NAMESPACE - -class QEventDispatcherQWSPrivate; - -class QEventDispatcherQWS : public QEventDispatcherUNIX -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QEventDispatcherQWS) - -public: - explicit QEventDispatcherQWS(QObject *parent = 0); - ~QEventDispatcherQWS(); - - bool processEvents(QEventLoop::ProcessEventsFlags flags); - bool hasPendingEvents(); - - void flush(); - - void startingUp(); - void closingDown(); - -protected: - int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - timeval *timeout); -}; - -QT_END_NAMESPACE - -#endif // QEVENTDISPATCHER_QWS_P_H diff --git a/src/gui/kernel/qkeymapper_qws.cpp b/src/gui/kernel/qkeymapper_qpa.cpp index 7e4114057f..7e4114057f 100644 --- a/src/gui/kernel/qkeymapper_qws.cpp +++ b/src/gui/kernel/qkeymapper_qpa.cpp diff --git a/src/gui/kernel/qsessionmanager_qws.cpp b/src/gui/kernel/qsessionmanager_qws.cpp deleted file mode 100644 index e355d055ad..0000000000 --- a/src/gui/kernel/qsessionmanager_qws.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qsessionmanager.h> - -#ifndef QT_NO_SESSIONMANAGER - -QT_BEGIN_NAMESPACE - -class QSessionManagerPrivate : public QObjectPrivate -{ -public: - QSessionManagerPrivate(QSessionManager *m, const QString &id, - const QString &key); - - QStringList restartCommand; - QStringList discardCommand; - const QString sessionId; - const QString sessionKey; - QSessionManager::RestartHint restartHint; -}; - -QSessionManagerPrivate::QSessionManagerPrivate(QSessionManager*, - const QString &id, - const QString &key) - : QObjectPrivate(), sessionId(id), sessionKey(key) -{ -} - -QSessionManager::QSessionManager(QApplication *app, QString &id, QString &key) - : QObject(*new QSessionManagerPrivate(this, id, key), app) -{ - Q_D(QSessionManager); - d->restartHint = RestartIfRunning; -} - -QSessionManager::~QSessionManager() -{ -} - -QString QSessionManager::sessionId() const -{ - Q_D(const QSessionManager); - return d->sessionId; -} - -QString QSessionManager::sessionKey() const -{ - Q_D(const QSessionManager); - return d->sessionKey; -} - - -bool QSessionManager::allowsInteraction() -{ - return false; -} - -bool QSessionManager::allowsErrorInteraction() -{ - return false; -} - -void QSessionManager::release() -{ -} - -void QSessionManager::cancel() -{ -} - -void QSessionManager::setRestartHint(QSessionManager::RestartHint hint) -{ - Q_D(QSessionManager); - d->restartHint = hint; -} - -QSessionManager::RestartHint QSessionManager::restartHint() const -{ - Q_D(const QSessionManager); - return d->restartHint; -} - -void QSessionManager::setRestartCommand(const QStringList &command) -{ - Q_D(QSessionManager); - d->restartCommand = command; -} - -QStringList QSessionManager::restartCommand() const -{ - Q_D(const QSessionManager); - return d->restartCommand; -} - -void QSessionManager::setDiscardCommand(const QStringList &command) -{ - Q_D(QSessionManager); - d->discardCommand = command; -} - -QStringList QSessionManager::discardCommand() const -{ - Q_D(const QSessionManager); - return d->discardCommand; -} - -void QSessionManager::setManagerProperty(const QString &name, - const QString &value) -{ - Q_UNUSED(name); - Q_UNUSED(value); -} - -void QSessionManager::setManagerProperty(const QString &name, - const QStringList &value) -{ - Q_UNUSED(name); - Q_UNUSED(value); -} - -bool QSessionManager::isPhase2() const -{ - return false; -} - -void QSessionManager::requestPhase2() -{ -} - -QT_END_NAMESPACE - -#endif // QT_NO_SESSIONMANAGER diff --git a/src/gui/kernel/qsound_qws.cpp b/src/gui/kernel/qsound_qws.cpp deleted file mode 100644 index c48347bf76..0000000000 --- a/src/gui/kernel/qsound_qws.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qapplication.h" - -#ifndef QT_NO_SOUND - -#include "qsound.h" -#include "qpaintdevice.h" -#include "qwsdisplay_qws.h" -#include "qsound_p.h" - -#include "qsoundqss_qws.h" - -#include "qhash.h" -#include "qfileinfo.h" - -#include "qbytearray.h" -#include "quuid.h" -#include "qdatastream.h" -#include "qcopchannel_qws.h" -#include "qbuffer.h" - - -QT_BEGIN_NAMESPACE - -#ifdef MEDIA_SERVER - -#define SERVER_CHANNEL "QPE/MediaServer" - -class QCopMessage : public QDataStream -{ -public: - QCopMessage( const QString& channel, const QString& message ) - : QDataStream( new QBuffer ), m_channel( channel ), m_message( message ) - { - device()->open( QIODevice::WriteOnly ); - } - - ~QCopMessage() - { - QCopChannel::send( m_channel, m_message, ((QBuffer*)device())->buffer() ); - delete device(); - } - -private: - QString m_channel; - QString m_message; -}; - -#endif // MEDIA_SERVER - -class QAuServerQWS; - -class QAuBucketQWS : public QObject, public QAuBucket -{ - Q_OBJECT -public: - QAuBucketQWS( QAuServerQWS*, QSound*, QObject* parent = 0 ); - - ~QAuBucketQWS(); - -#ifndef MEDIA_SERVER - int id() const { return id_; } -#endif - - QSound* sound() const { return sound_; } - -#ifdef MEDIA_SERVER - void play(); - - void stop(); -#endif - -signals: - // Only for Media Server - void done( QAuBucketQWS* ); - -private slots: - // Only for Media Server - void processMessage( const QString& msg, const QByteArray& data ); - -private: -#ifdef MEDIA_SERVER - QCopChannel *m_channel; - QUuid m_id; -#endif - -#ifndef MEDIA_SERVER - int id_; -#endif - QSound *sound_; - QAuServerQWS *server_; - - static int next; -}; - -int QAuBucketQWS::next = 0; - -class QAuServerQWS : public QAuServer -{ - Q_OBJECT -public: - QAuServerQWS( QObject* parent ); - - void init( QSound* s ) - { - QAuBucketQWS *bucket = new QAuBucketQWS( this, s ); -#ifdef MEDIA_SERVER - connect( bucket, SIGNAL(done(QAuBucketQWS*)), - this, SLOT(complete(QAuBucketQWS*)) ); -#endif - setBucket( s, bucket ); - } - -#ifndef MEDIA_SERVER - // Register bucket - void insert( QAuBucketQWS *bucket ) - { - buckets.insert( bucket->id(), bucket ); - } - - // Remove bucket from register - void remove( QAuBucketQWS *bucket ) - { - buckets.remove( bucket->id() ); - } -#endif - - void play( QSound* s ) - { - QString filepath = QFileInfo( s->fileName() ).absoluteFilePath(); -#if defined(QT_NO_QWS_SOUNDSERVER) - server->playFile( bucket( s )->id(), filepath ); -#elif defined(MEDIA_SERVER) - bucket( s )->play(); -#else - client->play( bucket( s )->id(), filepath ); -#endif - } - - void stop( QSound* s ) - { -#if defined(QT_NO_QWS_SOUNDSERVER) - server->stopFile( bucket( s )->id() ); -#elif defined(MEDIA_SERVER) - bucket( s )->stop(); -#else - client->stop( bucket( s )->id() ); -#endif - } - - bool okay() { return true; } - -private slots: - // Continue playing sound if loops remain - void complete( int id ) - { -#ifndef MEDIA_SERVER - QAuBucketQWS *bucket = find( id ); - if( bucket ) { - QSound *sound = bucket->sound(); - if( decLoop( sound ) ) { - play( sound ); - } - } -#else - Q_UNUSED(id); -#endif - } - - // Only for Media Server - void complete( QAuBucketQWS* bucket ) - { -#ifndef MEDIA_SERVER - Q_UNUSED(bucket); -#else - QSound *sound = bucket->sound(); - if( decLoop( sound ) ) { - play( sound ); - } -#endif - } - -protected: - QAuBucketQWS* bucket( QSound *s ) - { - return (QAuBucketQWS*)QAuServer::bucket( s ); - } - -private: -#ifndef MEDIA_SERVER - // Find registered bucket with given id, return null if none found - QAuBucketQWS* find( int id ) - { - QHash<int, QAuBucketQWS*>::Iterator it = buckets.find( id ); - if( it != buckets.end() ) { - return it.value(); - } - - return 0; - } - - QHash<int, QAuBucketQWS*> buckets; // ### possible problem with overlapping keys - -#ifdef QT_NO_QWS_SOUNDSERVER - QWSSoundServer *server; -#else - QWSSoundClient *client; -#endif - -#endif // MEDIA_SERVER -}; - -QAuServerQWS::QAuServerQWS(QObject* parent) : - QAuServer(parent) -{ -#ifndef MEDIA_SERVER - setObjectName(QLatin1String("qauserverqws")); - -#ifdef QT_NO_QWS_SOUNDSERVER - server = new QWSSoundServer( this ); // ### only suitable for single application - - connect( server, SIGNAL(soundCompleted(int)), - this, SLOT(complete(int)) ); -#else - client = new QWSSoundClient( this ); // ### requires successful connection - - connect( client, SIGNAL(soundCompleted(int)), - this, SLOT(complete(int)) ); -#endif - -#endif // MEDIA_SERVER -} - -QAuBucketQWS::QAuBucketQWS( QAuServerQWS *server, QSound *sound, QObject* parent ) - : QObject( parent ), sound_( sound ), server_( server ) -{ -#ifdef MEDIA_SERVER - m_id = QUuid::createUuid(); - - sound->setObjectName( m_id.toString() ); - - m_channel = new QCopChannel(QLatin1String("QPE/QSound/") + m_id, this ); - connect( m_channel, SIGNAL(received(QString,QByteArray)), - this, SLOT(processMessage(QString,QByteArray)) ); - - { - QCopMessage message( QLatin1String(SERVER_CHANNEL), QLatin1String("subscribe(QUuid)") ); - message << m_id; - } - - { - QString filepath = QFileInfo( sound_->fileName() ).absoluteFilePath(); - QCopMessage message( QLatin1String(SERVER_CHANNEL), QLatin1String("open(QUuid,QString)") ); - message << m_id << filepath; - } -#else - id_ = next++; - server_->insert( this ); -#endif -} - -#ifdef MEDIA_SERVER -void QAuBucketQWS::play() -{ - QString filepath = QFileInfo( sound_->fileName() ).absoluteFilePath(); - - QCopMessage message( QLatin1String(SERVER_CHANNEL), QLatin1String("play(QUuid)") ); - message << m_id; -} - -void QAuBucketQWS::stop() -{ - QCopMessage message( QLatin1String(SERVER_CHANNEL), QLatin1String("stop(QUuid)") ); - message << m_id; -} -#endif // MEDIA_SERVER - -void QAuBucketQWS::processMessage( const QString& msg, const QByteArray& data ) -{ - Q_UNUSED(data); -#ifndef MEDIA_SERVER - Q_UNUSED(msg); -#else - if( msg == QLatin1String("done()") ) { - emit done( this ); - } -#endif -} - -QAuBucketQWS::~QAuBucketQWS() -{ -#ifdef MEDIA_SERVER - QCopMessage message( QLatin1String(SERVER_CHANNEL), QLatin1String("revoke(QUuid)") ); - message << m_id; -#else - server_->remove( this ); -#endif -} - - -QAuServer* qt_new_audio_server() -{ - return new QAuServerQWS(qApp); -} - -#include "qsound_qws.moc" - -#endif // QT_NO_SOUND - -QT_END_NAMESPACE diff --git a/src/gui/kernel/qwidget_qws.cpp b/src/gui/kernel/qwidget_qws.cpp deleted file mode 100644 index 86ebc04165..0000000000 --- a/src/gui/kernel/qwidget_qws.cpp +++ /dev/null @@ -1,1221 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcursor.h" -#include "qapplication.h" -#include "qapplication_p.h" -#include "qpainter.h" -#include "qbitmap.h" -#include "qimage.h" -#include "qhash.h" -#include "qstack.h" -#include "qlayout.h" -#include "qtextcodec.h" -#include "qinputcontext.h" -#include "qdesktopwidget.h" - -#include "qwsdisplay_qws.h" -#include "private/qwsdisplay_qws_p.h" -#include "qscreen_qws.h" -#include "qwsmanager_qws.h" -#include <private/qwsmanager_p.h> -#include <private/qbackingstore_p.h> -#include <private/qwindowsurface_qws_p.h> -#include <private/qwslock_p.h> -#include "qpaintengine.h" - -#include "qdebug.h" - -#include "qwidget_p.h" - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - -extern int *qt_last_x; -extern int *qt_last_y; -extern WId qt_last_cursor; -extern bool qws_overrideCursor; -extern QWidget *qt_pressGrab; -extern QWidget *qt_mouseGrb; - -static QWidget *keyboardGrb = 0; - -static int takeLocalId() -{ - static int n=-1000; - return --n; -} - -class QWSServer; -extern QWSServer *qwsServer; - -static inline bool isServerProcess() -{ - return (qwsServer != 0); -} - -/***************************************************************************** - QWidget member functions - *****************************************************************************/ - -void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool /*destroyOldWindow*/) -{ - Q_Q(QWidget); - Qt::WindowType type = q->windowType(); - - // Make sure the WindowTitleHint is on if any of the title bar hints are set - // Note: This might be moved to cross-platform QWidgetPrivate::adjustFlags() - if ( !(data.window_flags & Qt::CustomizeWindowHint) && ( - (data.window_flags & Qt::WindowSystemMenuHint) || - (data.window_flags & Qt::WindowContextHelpButtonHint) || - (data.window_flags & Qt::WindowMinimizeButtonHint) || - (data.window_flags & Qt::WindowMaximizeButtonHint) || - (data.window_flags & Qt::WindowCloseButtonHint) ) ) { - data.window_flags |= Qt::WindowTitleHint; - } - - // Decoration plugins on QWS don't support switching on the close button on its own - if (data.window_flags & Qt::WindowCloseButtonHint) - data.window_flags |= Qt::WindowSystemMenuHint; - - Qt::WindowFlags flags = data.window_flags; - - data.alloc_region_index = -1; - - // we don't have a "Drawer" window type - if (type == Qt::Drawer) { - type = Qt::Widget; - flags &= ~Qt::WindowType_Mask; - } - - - bool topLevel = (flags & Qt::Window); - bool popup = (type == Qt::Popup); - bool dialog = (type == Qt::Dialog - || type == Qt::Sheet - || (flags & Qt::MSWindowsFixedSizeDialogHint)); - bool desktop = (type == Qt::Desktop); - bool tool = (type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip); - - -#ifndef QT_NO_WARNING_OUTPUT - static bool toolWarningShown = false; - if (!toolWarningShown && type == Qt::Tool && !(flags & Qt::FramelessWindowHint)) { - qWarning("Qt for Embedded Linux " QT_VERSION_STR " does not support tool windows with frames.\n" - "This behavior will change in a later release. To ensure compatibility with\n" - "future versions, use (Qt::Tool | Qt::FramelessWindowHint)."); - toolWarningShown = true; - } -#endif - - WId id; - QWSDisplay* dpy = QWidget::qwsDisplay(); - - if (!window) // always initialize - initializeWindow = true; - - // use the size of the primary screen to determine the default window size - QList<QScreen *> screens = qt_screen->subScreens(); - if (screens.isEmpty()) - screens.append(qt_screen); - int sw = screens[0]->width(); - int sh = screens[0]->height(); - - if (desktop) { // desktop widget - dialog = popup = false; // force these flags off - data.crect.setRect(0, 0, sw, sh); - } else if (topLevel && !q->testAttribute(Qt::WA_Resized)) { - int width = sw / 2; - int height = 4 * sh / 10; - if (extra) { - width = qMax(qMin(width, extra->maxw), extra->minw); - height = qMax(qMin(height, extra->maxh), extra->minh); - } - data.crect.setSize(QSize(width, height)); - } - - if (window) { // override the old window - id = window; - setWinId(window); - } else if (desktop) { // desktop widget - id = (WId)-2; // id = root window -#if 0 - QWidget *otherDesktop = q->find(id); // is there another desktop? - if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) { - otherDesktop->d_func()->setWinId(0); // remove id from widget mapper - setWinId(id); // make sure otherDesktop is - otherDesktop->d_func()->setWinId(id); // found first - } else -#endif - { - setWinId(id); - } - } else { - id = topLevel ? dpy->takeId() : takeLocalId(); - setWinId(id); // set widget id/handle + hd - } - - - bool hasFrame = true; - if (topLevel) { - if (desktop || popup || tool || q->testAttribute(Qt::WA_DontShowOnScreen)) - hasFrame = false; - else - hasFrame = !(flags & Qt::FramelessWindowHint); - } - if (desktop) { - q->setAttribute(Qt::WA_WState_Visible); - } else if (topLevel) { // set X cursor - //QCursor *oc = QApplication::overrideCursor(); - if (initializeWindow) { - //XXX XDefineCursor(dpy, winid, oc ? oc->handle() : cursor().handle()); - } - QWidget::qwsDisplay()->nameRegion(q->internalWinId(), q->objectName(), q->windowTitle()); - } - - if (topLevel) { - createTLExtra(); - QTLWExtra *topextra = extra->topextra; -#ifndef QT_NO_QWS_MANAGER - if (hasFrame) { - // get size of wm decoration and make the old crect the new frect - QRect cr = data.crect; - QRegion r = QApplication::qwsDecoration().region(q, cr) | cr; - QRect br(r.boundingRect()); - topextra->frameStrut.setCoords(cr.x() - br.x(), - cr.y() - br.y(), - br.right() - cr.right(), - br.bottom() - cr.bottom()); - if (!q->testAttribute(Qt::WA_Moved) || topextra->posFromMove) - data.crect.translate(topextra->frameStrut.left(), topextra->frameStrut.top()); - if (!topData()->qwsManager) { - topData()->qwsManager = new QWSManager(q); - if((q->data->window_state & ~Qt::WindowActive) == Qt::WindowMaximized) - topData()->qwsManager->maximize(); - } - - } else if (topData()->qwsManager) { - delete topData()->qwsManager; - topData()->qwsManager = 0; - data.crect.translate(-topextra->frameStrut.left(), -topextra->frameStrut.top()); - topextra->frameStrut.setCoords(0, 0, 0, 0); - } -#endif - if (!topextra->caption.isEmpty()) - setWindowTitle_helper(topextra->caption); - - //XXX If we are session managed, inform the window manager about it - } else { - if (extra && extra->topextra) { // already allocated due to reparent? - extra->topextra->frameStrut.setCoords(0, 0, 0, 0); - } - //updateRequestedRegion(mapToGlobal(QPoint(0,0))); - } -} - - -void QWidget::destroy(bool destroyWindow, bool destroySubWindows) -{ - Q_D(QWidget); - d->aboutToDestroy(); - if (!isWindow() && parentWidget()) - parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); - - d->deactivateWidgetCleanup(); - if (testAttribute(Qt::WA_WState_Created)) { - setAttribute(Qt::WA_WState_Created, false); - QObjectList childObjects = children(); - for (int i = 0; i < childObjects.size(); ++i) { - QObject *obj = childObjects.at(i); - if (obj->isWidgetType()) - static_cast<QWidget*>(obj)->destroy(destroySubWindows, - destroySubWindows); - } - releaseMouse(); - if (qt_pressGrab == this) - qt_pressGrab = 0; - - if (keyboardGrb == this) - releaseKeyboard(); - if (testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal - QApplicationPrivate::leaveModal(this); - else if ((windowType() == Qt::Popup)) - qApp->d_func()->closePopup(this); -#ifndef QT_NO_IM - if (d->ic) { - delete d->ic; - d->ic =0; - } else { - // release previous focus information participating with - // preedit preservation of qic -- while we still have a winId - QInputContext *qic = QApplicationPrivate::inputContext; - if (qic) - qic->widgetDestroyed(this); - } -#endif //QT_NO_IM - - if ((windowType() == Qt::Desktop)) { - } else { - if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) { - d->hide_sys(); - } - if (destroyWindow && isWindow()) { - if (d->extra && d->extra->topextra && d->extra->topextra->backingStore) - d->extra->topextra->backingStore->windowSurface->setGeometry(QRect()); - qwsDisplay()->destroyRegion(internalWinId()); - } - } - QT_TRY { - d->setWinId(0); - } QT_CATCH (const std::bad_alloc &) { - // swallow - destructors must not throw - } - } -} - - -void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) -{ - Q_Q(QWidget); - bool wasCreated = q->testAttribute(Qt::WA_WState_Created); - if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) - q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); -#ifndef QT_NO_CURSOR - QCursor oldcurs; - bool setcurs=q->testAttribute(Qt::WA_SetCursor); - if (setcurs) { - oldcurs = q->cursor(); - q->unsetCursor(); - } -#endif - - WId old_winid = data.winid; - if ((q->windowType() == Qt::Desktop)) - old_winid = 0; - - if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_WState_Created)) - hide_sys(); - - setWinId(0); - - if (parent != newparent) { - QWidget *oldparent = q->parentWidget(); - QObjectPrivate::setParent_helper(newparent); - if (oldparent) { -// oldparent->d_func()->setChildrenAllocatedDirty(); -// oldparent->data->paintable_region_dirty = true; - } - if (newparent) { -// newparent->d_func()->setChildrenAllocatedDirty(); -// newparent->data->paintable_region_dirty = true; - //@@@@@@@ - } - } - Qt::FocusPolicy fp = q->focusPolicy(); - QSize s = q->size(); - //QBrush bgc = background(); // save colors - bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); - - data.window_flags = f; - q->setAttribute(Qt::WA_WState_Created, false); - q->setAttribute(Qt::WA_WState_Visible, false); - q->setAttribute(Qt::WA_WState_Hidden, false); - adjustFlags(data.window_flags, q); - // keep compatibility with previous versions, we need to preserve the created state - // (but we recreate the winId for the widget being reparented, again for compatibility) - if (wasCreated || (!q->isWindow() && newparent->testAttribute(Qt::WA_WState_Created))) - createWinId(); - if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden) - q->setAttribute(Qt::WA_WState_Hidden); - q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); - - if (q->isWindow()) { - QRect fs = frameStrut(); - data.crect = QRect(fs.left(), fs.top(), s.width(), s.height()); - if ((data.window_flags & Qt::FramelessWindowHint) && extra && extra->topextra) - extra->topextra->frameStrut.setCoords(0, 0, 0, 0); - } else { - data.crect = QRect(0, 0, s.width(), s.height()); - } - - q->setFocusPolicy(fp); - if (extra && !extra->mask.isEmpty()) { - QRegion r = extra->mask; - extra->mask = QRegion(); - q->setMask(r); - } - if ((int)old_winid > 0) { - QWidget::qwsDisplay()->destroyRegion(old_winid); - extra->topextra->backingStore->windowSurface->setGeometry(QRect()); - } -#ifndef QT_NO_CURSOR - if (setcurs) { - q->setCursor(oldcurs); - } -#endif -} - - -QPoint QWidget::mapToGlobal(const QPoint &pos) const -{ - int x=pos.x(), y=pos.y(); - const QWidget* w = this; - while (w) { - x += w->data->crect.x(); - y += w->data->crect.y(); - w = w->isWindow() ? 0 : w->parentWidget(); - } - return QPoint(x, y); -} - -QPoint QWidget::mapFromGlobal(const QPoint &pos) const -{ - int x=pos.x(), y=pos.y(); - const QWidget* w = this; - while (w) { - x -= w->data->crect.x(); - y -= w->data->crect.y(); - w = w->isWindow() ? 0 : w->parentWidget(); - } - return QPoint(x, y); -} - -#if 0 // ##### -void QWidget::setMicroFocusHint(int x, int y, int width, int height, - bool text, QFont *) -{ - if (QRect(x, y, width, height) != microFocusHint()) { - d->createExtra(); - d->extra->micro_focus_hint.setRect(x, y, width, height); - } -#ifndef QT_NO_QWS_INPUTMETHODS - if (text) { - QWidget *tlw = window(); - int winid = tlw->internalWinId(); - QPoint p(x, y + height); - QPoint gp = mapToGlobal(p); - - QRect r = QRect(mapToGlobal(QPoint(0,0)), - size()); - - r.setBottom(tlw->geometry().bottom()); - - //qDebug("QWidget::setMicroFocusHint %d %d %d %d", r.x(), - // r.y(), r.width(), r.height()); - QInputContext::setMicroFocusWidget(this); - - qwsDisplay()->setIMInfo(winid, gp.x(), gp.y(), r); - - //send font info, ###if necessary - qwsDisplay()->setInputFont(winid, font()); - } -#endif -} -#endif - -void QWidgetPrivate::updateSystemBackground() {} - -#ifndef QT_NO_CURSOR -void QWidgetPrivate::setCursor_sys(const QCursor &cursor) -{ - Q_UNUSED(cursor); - Q_Q(QWidget); - if (q->isVisible()) - updateCursor(); -} - -void QWidgetPrivate::unsetCursor_sys() -{ - Q_Q(QWidget); - if (q->isVisible()) - updateCursor(); -} -#endif //QT_NO_CURSOR - -void QWidgetPrivate::setWindowTitle_sys(const QString &caption) -{ - Q_Q(QWidget); - QWidget::qwsDisplay()->setWindowCaption(q, caption); -} - -void QWidgetPrivate::setWindowIcon_sys(bool /*forceReset*/) -{ -#if 0 - QTLWExtra* x = d->topData(); - delete x->icon; - x->icon = 0; - QBitmap mask; - if (unscaledPixmap.isNull()) { - } else { - QImage unscaledIcon = unscaledPixmap.toImage(); - QPixmap pixmap = - QPixmap::fromImage(unscaledIcon.scale(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - x->icon = new QPixmap(pixmap); - mask = pixmap.mask() ? *pixmap.mask() : pixmap.createHeuristicMask(); - } -#endif -} - -void QWidgetPrivate::setWindowIconText_sys(const QString &iconText) -{ - Q_UNUSED(iconText); -} - -void QWidget::grabMouse() -{ - if (qt_mouseGrb) - qt_mouseGrb->releaseMouse(); - - qwsDisplay()->grabMouse(this,true); - - qt_mouseGrb = this; - qt_pressGrab = 0; -} - -#ifndef QT_NO_CURSOR -void QWidget::grabMouse(const QCursor &cursor) -{ - if (qt_mouseGrb) - qt_mouseGrb->releaseMouse(); - - qwsDisplay()->grabMouse(this,true); - qwsDisplay()->selectCursor(this, cursor.handle()); - qt_mouseGrb = this; - qt_pressGrab = 0; -} -#endif - -void QWidget::releaseMouse() -{ - if (qt_mouseGrb == this) { - qwsDisplay()->grabMouse(this,false); - qt_mouseGrb = 0; - } -} - -void QWidget::grabKeyboard() -{ - if (keyboardGrb) - keyboardGrb->releaseKeyboard(); - qwsDisplay()->grabKeyboard(this, true); - keyboardGrb = this; -} - -void QWidget::releaseKeyboard() -{ - if (keyboardGrb == this) { - qwsDisplay()->grabKeyboard(this, false); - keyboardGrb = 0; - } -} - - -QWidget *QWidget::mouseGrabber() -{ - if (qt_mouseGrb) - return qt_mouseGrb; - return qt_pressGrab; -} - - -QWidget *QWidget::keyboardGrabber() -{ - return keyboardGrb; -} - -void QWidget::activateWindow() -{ - QWidget *tlw = window(); - if (tlw->isVisible()) { - Q_ASSERT(tlw->testAttribute(Qt::WA_WState_Created)); - qwsDisplay()->requestFocus(tlw->internalWinId(), true); - } -} - -void QWidgetPrivate::show_sys() -{ - Q_Q(QWidget); - q->setAttribute(Qt::WA_Mapped); - if (q->testAttribute(Qt::WA_DontShowOnScreen)) { - invalidateBuffer(q->rect()); - return; - } - - if (q->isWindow()) { - - - if (!q->testAttribute(Qt::WA_ShowWithoutActivating) - && q->windowType() != Qt::Popup - && q->windowType() != Qt::Tool - && q->windowType() != Qt::ToolTip) { - QWidget::qwsDisplay()->requestFocus(data.winid,true); - } - - - if (QWindowSurface *surface = q->windowSurface()) { - const QRect frameRect = q->frameGeometry(); - if (surface->geometry() != frameRect) - surface->setGeometry(frameRect); - } - - QRegion r = localRequestedRegion(); -#ifndef QT_NO_QWS_MANAGER - if (extra && extra->topextra && extra->topextra->qwsManager) { - r.translate(data.crect.topLeft()); - r += extra->topextra->qwsManager->region(); - r.translate(-data.crect.topLeft()); - } -#endif - data.fstrut_dirty = true; - invalidateBuffer(r); - bool staysontop = - (q->windowFlags() & Qt::WindowStaysOnTopHint) - || q->windowType() == Qt::Popup; - if (!staysontop && q->parentWidget()) { // if our parent stays on top, so must we - QWidget *ptl = q->parentWidget()->window(); - if (ptl && (ptl->windowFlags() & Qt::WindowStaysOnTopHint)) - staysontop = true; - } - - QWSChangeAltitudeCommand::Altitude altitude; - altitude = staysontop ? QWSChangeAltitudeCommand::StaysOnTop : QWSChangeAltitudeCommand::Raise; - QWidget::qwsDisplay()->setAltitude(data.winid, altitude, true); - if (!q->objectName().isEmpty()) { - QWidget::qwsDisplay()->setWindowCaption(q, q->windowTitle()); - } - } -#ifdef Q_BACKINGSTORE_SUBSURFACES - else if ( extra && extra->topextra && extra->topextra->windowSurface) { - QWSWindowSurface *surface; - surface = static_cast<QWSWindowSurface*>(q->windowSurface()); - const QPoint p = q->mapToGlobal(QPoint()); - surface->setGeometry(QRect(p, q->size())); - } -#endif - - if (!q->window()->data->in_show) { - invalidateBuffer(q->rect()); - } -} - - -void QWidgetPrivate::hide_sys() -{ - Q_Q(QWidget); - deactivateWidgetCleanup(); - - if (q->isWindow()) { - q->releaseMouse(); -// requestWindowRegion(QRegion()); - - if (extra->topextra->backingStore) - extra->topextra->backingStore->releaseBuffer(); - - - QWidget::qwsDisplay()->requestFocus(data.winid,false); - } else { - QWidget *p = q->parentWidget(); - if (p &&p->isVisible()) { - invalidateBuffer(q->rect()); - } - } -} - - - -static Qt::WindowStates effectiveState(Qt::WindowStates state) - { - if (state & Qt::WindowMinimized) - return Qt::WindowMinimized; - else if (state & Qt::WindowFullScreen) - return Qt::WindowFullScreen; - else if (state & Qt::WindowMaximized) - return Qt::WindowMaximized; - return Qt::WindowNoState; - } - -void QWidgetPrivate::setMaxWindowState_helper() -{ - // in_set_window_state is usually set in setWindowState(), but this - // function is used in other functions as well - // (e.g QApplicationPrivate::setMaxWindowRect()) - const uint old_state = data.in_set_window_state; - data.in_set_window_state = 1; - -#ifndef QT_NO_QWS_MANAGER - if (extra && extra->topextra && extra->topextra->qwsManager) - extra->topextra->qwsManager->maximize(); - else -#endif - { - Q_Q(QWidget); - const QDesktopWidget *desktop = QApplication::desktop(); - const int screen = desktop->screenNumber(q); - const QRect maxWindowRect = desktop->availableGeometry(screen); - q->setGeometry(maxWindowRect); - } - data.in_set_window_state = old_state; -} - -void QWidgetPrivate::setFullScreenSize_helper() -{ - Q_Q(QWidget); - - const uint old_state = data.in_set_window_state; - data.in_set_window_state = 1; - - const QRect screen = qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(q)); - q->move(screen.topLeft()); - q->resize(screen.size()); - - data.in_set_window_state = old_state; -} - -void QWidget::setWindowState(Qt::WindowStates newstate) -{ - Q_D(QWidget); - Qt::WindowStates oldstate = windowState(); - if (oldstate == newstate) - return; - if (isWindow() && !testAttribute(Qt::WA_WState_Created)) - create(); - - data->window_state = newstate; - data->in_set_window_state = 1; - bool needShow = false; - Qt::WindowStates newEffectiveState = effectiveState(newstate); - Qt::WindowStates oldEffectiveState = effectiveState(oldstate); - if (isWindow() && newEffectiveState != oldEffectiveState) { - d->createTLExtra(); - if (oldEffectiveState == Qt::WindowNoState) { //normal - d->topData()->normalGeometry = geometry(); - } else if (oldEffectiveState == Qt::WindowFullScreen) { - setParent(0, d->topData()->savedFlags); - needShow = true; - } else if (oldEffectiveState == Qt::WindowMinimized) { - needShow = true; - } - - if (newEffectiveState == Qt::WindowMinimized) { - //### not ideal... - hide(); - needShow = false; - } else if (newEffectiveState == Qt::WindowFullScreen) { - d->topData()->savedFlags = windowFlags(); - setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint)); - d->setFullScreenSize_helper(); - raise(); - needShow = true; - } else if (newEffectiveState == Qt::WindowMaximized) { - createWinId(); - d->setMaxWindowState_helper(); - } else { //normal - QRect r = d->topData()->normalGeometry; - if (r.width() >= 0) { - d->topData()->normalGeometry = QRect(0,0,-1,-1); - setGeometry(r); - } - } - } - data->in_set_window_state = 0; - - if (needShow) - show(); - - if (newstate & Qt::WindowActive) - activateWindow(); - - QWindowStateChangeEvent e(oldstate); - QApplication::sendEvent(this, &e); -} - -void QWidgetPrivate::setFocus_sys() -{ - -} - -void QWidgetPrivate::raise_sys() -{ - Q_Q(QWidget); - //@@@ transaction - if (q->isWindow()) { - Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); - QWidget::qwsDisplay()->setAltitude(q->internalWinId(), - QWSChangeAltitudeCommand::Raise); - // XXX: subsurfaces? -#ifdef QT_NO_WINDOWGROUPHINT -#else - QObjectList childObjects = q->children(); - if (!childObjects.isEmpty()) { - QWidgetList toraise; - for (int i = 0; i < childObjects.size(); ++i) { - QObject *obj = childObjects.at(i); - if (obj->isWidgetType()) { - QWidget* w = static_cast<QWidget*>(obj); - if (w->isWindow()) - toraise.append(w); - } - } - - for (int i = 0; i < toraise.size(); ++i) { - QWidget *w = toraise.at(i); - if (w->isVisible()) - w->raise(); - } - } -#endif // QT_NO_WINDOWGROUPHINT - } -} - -void QWidgetPrivate::lower_sys() -{ - Q_Q(QWidget); - if (q->isWindow()) { - Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); - QWidget::qwsDisplay()->setAltitude(data.winid, - QWSChangeAltitudeCommand::Lower); - } else if (QWidget *p = q->parentWidget()) { - setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); - } -} - -void QWidgetPrivate::stackUnder_sys(QWidget*) -{ - Q_Q(QWidget); - if (QWidget *p = q->parentWidget()) { - setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); - } -} - -void QWidgetPrivate::moveSurface(QWindowSurface *surface, const QPoint &offset) -{ - QWSWindowSurface *s = static_cast<QWSWindowSurface*>(surface); - if (!s->move(offset)) - s->invalidateBuffer(); - - QWSDisplay::instance()->moveRegion(s->winId(), offset.x(), offset.y()); -} - -void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) -{ - Q_Q(QWidget); - if (extra) { // any size restrictions? - w = qMin(w,extra->maxw); - h = qMin(h,extra->maxh); - w = qMax(w,extra->minw); - h = qMax(h,extra->minh); - } - - QPoint oldp = q->geometry().topLeft(); - QSize olds = q->size(); - QRect r(x, y, w, h); - - bool isResize = olds != r.size(); - isMove = oldp != r.topLeft(); //### why do we have isMove as a parameter? - - // We only care about stuff that changes the geometry, or may - // cause the window manager to change its state - if (r.size() == olds && oldp == r.topLeft()) - return; - - if (!data.in_set_window_state) { - q->data->window_state &= ~Qt::WindowMaximized; - q->data->window_state &= ~Qt::WindowFullScreen; - if (q->isWindow()) - topData()->normalGeometry = QRect(0, 0, -1, -1); - } - QPoint oldPos = q->pos(); - data.crect = r; - - if ((q->windowType() == Qt::Desktop)) - return; - - if (q->isVisible()) { - - bool toplevelMove = false; - QWSWindowSurface *surface = 0; - - if (q->isWindow()) { - //### ConfigPending not implemented, do we need it? - //setAttribute(Qt::WA_WState_ConfigPending); - const QWidgetBackingStore *bs = maybeBackingStore(); - if (bs) - surface = static_cast<QWSWindowSurface*>(bs->windowSurface); - if (isMove && !isResize && surface) { - const QPoint offset(x - oldp.x(), y - oldp.y()); - moveSurface(surface, offset); - toplevelMove = true; //server moves window, but we must send moveEvent, which might trigger painting - -#ifdef Q_BACKINGSTORE_SUBSURFACES - QList<QWindowSurface*> surfaces = bs->subSurfaces; - for (int i = 0; i < surfaces.size(); ++i) - moveSurface(surfaces.at(i), offset); -#endif - } else { - updateFrameStrut(); - } - } - - if (!toplevelMove) { - if (q->isWindow()) { - if (surface) - surface->setGeometry(q->frameGeometry()); - else - invalidateBuffer(q->rect()); //### - -#ifdef Q_BACKINGSTORE_SUBSURFACES - // XXX: should not resize subsurfaces. Children within a layout - // will be resized automatically while children with a static - // geometry should get a new clip region instead. - const QRect clipRect = q->geometry(); - QWidgetBackingStore *bs = maybeBackingStore(); - QList<QWindowSurface*> surfaces = bs->subSurfaces; - for (int i = 0; i < surfaces.size(); ++i) { - QWSWindowSurface *s = static_cast<QWSWindowSurface*>(surfaces.at(i)); - QRect srect = s->geometry(); - s->setGeometry(clipRect & srect); - } -#endif - } -#ifdef Q_BACKINGSTORE_SUBSURFACES - // XXX: merge this case with the isWindow() case - else if (maybeTopData() && maybeTopData()->windowSurface) { - QWSWindowSurface *surface; - surface = static_cast<QWSWindowSurface*>(q->windowSurface()); - if (isMove && !isResize) { - moveSurface(surface, QPoint(x - oldp.x(), y - oldp.y())); - } else { - const QPoint p = q->mapToGlobal(QPoint()); - surface->setGeometry(QRect(p, QSize(w, h))); - } - } -#endif - else { - if (isMove && !isResize) - moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y()); - else - invalidateBuffer_resizeHelper(oldPos, olds); - } - } - - //### must have frame geometry correct before sending move/resize events - if (isMove) { - QMoveEvent e(q->pos(), oldPos); - QApplication::sendEvent(q, &e); - } - if (isResize) { - QResizeEvent e(r.size(), olds); - QApplication::sendEvent(q, &e); - } - - } else { // not visible - if (isMove && q->pos() != oldPos) - q->setAttribute(Qt::WA_PendingMoveEvent, true); - if (isResize) - q->setAttribute(Qt::WA_PendingResizeEvent, true); - } -} - -void QWidgetPrivate::setConstraints_sys() -{ -} - -QScreen* QWidgetPrivate::getScreen() const -{ - Q_Q(const QWidget); - - const QList<QScreen*> subScreens = qt_screen->subScreens(); - if (subScreens.isEmpty() || q->windowType() == Qt::Desktop) - return qt_screen; - - const int screen = QApplication::desktop()->screenNumber(q); - - return qt_screen->subScreens().at(screen < 0 ? 0 : screen); -} - -void QWidgetPrivate::scroll_sys(int dx, int dy) -{ - Q_Q(QWidget); - scrollChildren(dx, dy); - scrollRect(q->rect(), dx, dy); -} - -void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r) -{ - scrollRect(r, dx, dy); -} - -int QWidget::metric(PaintDeviceMetric m) const -{ - Q_D(const QWidget); - - int val; - if (m == PdmWidth) { - val = data->crect.width(); - } else if (m == PdmWidthMM) { - const QScreen *screen = d->getScreen(); - val = data->crect.width() * screen->physicalWidth() / screen->width(); - } else if (m == PdmHeight) { - val = data->crect.height(); - } else if (m == PdmHeightMM) { - const QScreen *screen = d->getScreen(); - val = data->crect.height() * screen->physicalHeight() / screen->height(); - } else if (m == PdmDepth) { - return qwsDisplay()->depth(); - } else if (m == PdmDpiX || m == PdmPhysicalDpiX) { - if (d->extra && d->extra->customDpiX) - return d->extra->customDpiX; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); - const QScreen *screen = d->getScreen(); - return qRound(screen->width() / double(screen->physicalWidth() / 25.4)); - } else if (m == PdmDpiY || m == PdmPhysicalDpiY) { - if (d->extra && d->extra->customDpiY) - return d->extra->customDpiY; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); - const QScreen *screen = d->getScreen(); - return qRound(screen->height() / double(screen->physicalHeight() / 25.4)); - } else if (m == PdmNumColors) { - QScreen *screen = d->getScreen(); - int ret = screen->colorCount(); - if (!ret) { - const int depth = qwsDisplay()->depth(); - switch (depth) { - case 1: - ret = 2; - break; - case 8: - ret = 256; - break; - case 16: - ret = 65536; - break; - case 24: - ret = 16777216; - break; - case 32: - ret = 2147483647; - break; - } - } - return ret; - } else { - val = QPaintDevice::metric(m);// XXX - } - return val; -} - -void QWidgetPrivate::createSysExtra() -{ -} - -void QWidgetPrivate::deleteSysExtra() -{ -} - -void QWidgetPrivate::createTLSysExtra() -{ -#ifndef QT_NO_QWS_MANAGER - extra->topextra->qwsManager = 0; -#endif -} - -void QWidgetPrivate::deleteTLSysExtra() -{ -} - -void QWidgetPrivate::registerDropSite(bool on) -{ - Q_UNUSED(on); -} - -QRegion QWidgetPrivate::localRequestedRegion() const -{ - Q_Q(const QWidget); - QRegion r(q->rect()); - if (extra && !extra->mask.isEmpty()) - r &= extra->mask; - - return r; -} - -QRegion QWidgetPrivate::localAllocatedRegion() const -{ - Q_Q(const QWidget); - - QWidgetBackingStore *wbs = q->window()->d_func()->maybeBackingStore(); - - QWindowSurface *ws = wbs ? wbs->windowSurface : 0; - if (!ws) - return QRegion(); - QRegion r = static_cast<QWSWindowSurface*>(ws)->clipRegion(); - if (!q->isWindow()) { - QPoint off = q->mapTo(q->window(), QPoint()); - r &= localRequestedRegion().translated(off); - r.translate(-off); - } - return r; -} - -inline bool QRect::intersects(const QRect &r) const -{ - return (qMax(x1, r.x1) <= qMin(x2, r.x2) && - qMax(y1, r.y1) <= qMin(y2, r.y2)); -} - -void QWidgetPrivate::setMask_sys(const QRegion ®ion) -{ - Q_UNUSED(region); - Q_Q(QWidget); - - if (!q->isVisible() || !q->isWindow()) - return; - - data.fstrut_dirty = true; - invalidateBuffer(q->rect()); - QWindowSurface *surface = extra->topextra->backingStore->windowSurface; - if (surface) { - // QWSWindowSurface::setGeometry() returns without doing anything - // if old geom == new geom. Therefore, we need to reset the old value. - surface->QWindowSurface::setGeometry(QRect()); - surface->setGeometry(q->frameGeometry()); - } -} - -void QWidgetPrivate::updateFrameStrut() -{ - Q_Q(QWidget); - - if(!q->isVisible() || (q->windowType() == Qt::Desktop)) { - data.fstrut_dirty = q->isVisible(); - return; - } - -#ifndef QT_NO_QWS_MANAGER - if (extra && extra->topextra && extra->topextra->qwsManager) { - QTLWExtra *topextra = extra->topextra; - const QRect oldFrameStrut = topextra->frameStrut; - const QRect contents = data.crect; - QRegion r = localRequestedRegion().translated(contents.topLeft()); - r += extra->topextra->qwsManager->region(); - const QRect frame = r.boundingRect(); - - topextra->frameStrut.setCoords(contents.left() - frame.left(), - contents.top() - frame.top(), - frame.right() - contents.right(), - frame.bottom() - contents.bottom()); - topextra->qwsManager->repaintRegion(QDecoration::All, QDecoration::Normal); - } -#endif - data.fstrut_dirty = false; -} - -#ifndef QT_NO_CURSOR -void QWidgetPrivate::updateCursor() const -{ - Q_Q(const QWidget); - - if (QApplication::overrideCursor()) - return; - - if (qt_last_x - && (!QWidget::mouseGrabber() || QWidget::mouseGrabber() == q) - && qt_last_cursor != (WId)q->cursor().handle()) - { - const QPoint pos(*qt_last_x, *qt_last_y); - const QPoint offset = q->mapToGlobal(QPoint()); - if (!localAllocatedRegion().contains(pos - offset)) - return; - - const QWidget *w = q->childAt(q->mapFromGlobal(pos)); - if (!w || w->cursor().handle() == q->cursor().handle()) - QWidget::qwsDisplay()->selectCursor(const_cast<QWidget*>(q), - q->cursor().handle()); - } -} -#endif - -void QWidgetPrivate::setWindowOpacity_sys(qreal level) -{ - Q_Q(QWidget); - Q_UNUSED(level); - createWinId(); - QWidget::qwsDisplay()->setOpacity(q->data->winid, topData()->opacity); -} - -//static QSingleCleanupHandler<QWSPaintEngine> qt_paintengine_cleanup_handler; -//static QWSPaintEngine *qt_widget_paintengine = 0; -QPaintEngine *QWidget::paintEngine() const -{ - qWarning("QWidget::paintEngine: Should no longer be called"); - return 0; //##### @@@ -// if (!qt_widget_paintengine) { -// qt_widget_paintengine = new QRasterPaintEngine(); -// qt_paintengine_cleanup_handler.set(&qt_widget_paintengine); -// } -// if (qt_widget_paintengine->isActive()) { -// if (d->extraPaintEngine) -// return d->extraPaintEngine; -// const_cast<QWidget *>(this)->d_func()->extraPaintEngine = new QRasterPaintEngine(); -// return d->extraPaintEngine; -// } -// return qt_widget_paintengine; -} - -QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() -{ - Q_Q(QWidget); - if (q->windowType() == Qt::Desktop) - return 0; - q->ensurePolished(); - return qt_screen->createSurface(q); -} - -void QWidgetPrivate::setModal_sys() -{ -} - - -QT_END_NAMESPACE diff --git a/src/gui/painting/qcolormap_qws.cpp b/src/gui/painting/qcolormap_qws.cpp deleted file mode 100644 index 5c0933d6eb..0000000000 --- a/src/gui/painting/qcolormap_qws.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcolormap.h" -#include "qcolor.h" -#include "qpaintdevice.h" -#include "qscreen_qws.h" -#include "qwsdisplay_qws.h" - -QT_BEGIN_NAMESPACE - -class QColormapPrivate -{ -public: - inline QColormapPrivate() - : ref(1), mode(QColormap::Direct), depth(0), numcolors(0) - { } - - QAtomicInt ref; - - QColormap::Mode mode; - int depth; - int numcolors; -}; - -static QColormapPrivate *screenMap = 0; - -void QColormap::initialize() -{ - screenMap = new QColormapPrivate; - - screenMap->depth = QPaintDevice::qwsDisplay()->depth(); - if (screenMap->depth < 8) { - screenMap->mode = QColormap::Indexed; - screenMap->numcolors = 256; - } else { - screenMap->mode = QColormap::Direct; - screenMap->numcolors = -1; - } -} - -void QColormap::cleanup() -{ - delete screenMap; - screenMap = 0; -} - -QColormap QColormap::instance(int /*screen*/) -{ - return QColormap(); -} - -QColormap::QColormap() - : d(screenMap) -{ d->ref.ref(); } - -QColormap::QColormap(const QColormap &colormap) - :d (colormap.d) -{ d->ref.ref(); } - -QColormap::~QColormap() -{ - if (!d->ref.deref()) - delete d; -} - -QColormap::Mode QColormap::mode() const -{ return d->mode; } - - -int QColormap::depth() const -{ return d->depth; } - - -int QColormap::size() const -{ - return d->numcolors; -} - -uint QColormap::pixel(const QColor &color) const -{ - QRgb rgb = color.rgba(); - if (d->mode == QColormap::Direct) { - switch(d->depth) { - case 16: - return qt_convRgbTo16(rgb); - case 24: - case 32: - { - const int r = qRed(rgb); - const int g = qGreen(rgb); - const int b = qBlue(rgb); - const int red_shift = 16; - const int green_shift = 8; - const int red_mask = 0xff0000; - const int green_mask = 0x00ff00; - const int blue_mask = 0x0000ff; - const int tg = g << green_shift; -#ifdef QT_QWS_DEPTH_32_BGR - if (qt_screen->pixelType() == QScreen::BGRPixel) { - const int tb = b << red_shift; - return 0xff000000 | (r & blue_mask) | (tg & green_mask) | (tb & red_mask); - } -#endif - const int tr = r << red_shift; - return 0xff000000 | (b & blue_mask) | (tg & green_mask) | (tr & red_mask); - } - } - } - return qt_screen->alloc(qRed(rgb), qGreen(rgb), qBlue(rgb)); -} - -const QColor QColormap::colorAt(uint pixel) const -{ - if (d->mode == Direct) { - if (d->depth == 16) { - pixel = qt_conv16ToRgb(pixel); - } - const int red_shift = 16; - const int green_shift = 8; - const int red_mask = 0xff0000; - const int green_mask = 0x00ff00; - const int blue_mask = 0x0000ff; -#ifdef QT_QWS_DEPTH_32_BGR - if (qt_screen->pixelType() == QScreen::BGRPixel) { - return QColor((pixel & blue_mask), - (pixel & green_mask) >> green_shift, - (pixel & red_mask) >> red_shift); - } -#endif - return QColor((pixel & red_mask) >> red_shift, - (pixel & green_mask) >> green_shift, - (pixel & blue_mask)); - } - Q_ASSERT_X(int(pixel) < qt_screen->colorCount(), "QColormap::colorAt", "pixel out of bounds of palette"); - return QColor(qt_screen->clut()[pixel]); -} - -const QVector<QColor> QColormap::colormap() const -{ - return QVector<QColor>(); -} - -QColormap &QColormap::operator=(const QColormap &colormap) -{ qAtomicAssign(d, colormap.d); return *this; } - -QT_END_NAMESPACE diff --git a/src/gui/painting/qgraphicssystem_qws.cpp b/src/gui/painting/qgraphicssystem_qws.cpp deleted file mode 100644 index 40f9ad4839..0000000000 --- a/src/gui/painting/qgraphicssystem_qws.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qscreen_qws.h> -#include "qgraphicssystem_qws_p.h" -#include <private/qpixmap_raster_p.h> -#include <private/qwindowsurface_qws_p.h> - -QT_BEGIN_NAMESPACE - -QPixmapData *QWSGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const -{ - if (screen->pixmapDataFactory()) - return screen->pixmapDataFactory()->create(type); //### For 4.4 compatibility - else - return new QRasterPixmapData(type); -} - -QWindowSurface *QWSGraphicsSystem::createWindowSurface(QWidget *widget) const -{ - return screen->createSurface(widget); -} - -QT_END_NAMESPACE diff --git a/src/gui/painting/qgraphicssystem_qws_p.h b/src/gui/painting/qgraphicssystem_qws_p.h deleted file mode 100644 index 92b92628cd..0000000000 --- a/src/gui/painting/qgraphicssystem_qws_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGRAPHICSSYSTEM_QWS_P_H -#define QGRAPHICSSYSTEM_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qgraphicssystem_p.h" - -QT_BEGIN_NAMESPACE - -class Q_GUI_EXPORT QWSGraphicsSystem : public QGraphicsSystem -{ -public: - - QWSGraphicsSystem() - : screen(QScreen::instance()) {} - - QWSGraphicsSystem(QScreen* s) - : screen(s) {} - - virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; - -private: - QScreen* screen; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/gui/painting/qpaintdevice_qws.cpp b/src/gui/painting/qpaintdevice_qws.cpp deleted file mode 100644 index 6f9433ab62..0000000000 --- a/src/gui/painting/qpaintdevice_qws.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpaintdevice.h" -#include "qpainter.h" -#include "qwidget.h" -#include "qbitmap.h" -#include "qapplication.h" -#include "qwsdisplay_qws.h" - -QT_BEGIN_NAMESPACE - -QWSDisplay *QPaintDevice::qwsDisplay() -{ - return qt_fbdpy; -} - -QT_END_NAMESPACE diff --git a/src/gui/painting/qprintengine_qws.cpp b/src/gui/painting/qprintengine_qws.cpp deleted file mode 100644 index 1aef2c68cf..0000000000 --- a/src/gui/painting/qprintengine_qws.cpp +++ /dev/null @@ -1,886 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <private/qprintengine_qws_p.h> - -#ifndef QT_NO_PRINTER - -#include <private/qpaintengine_raster_p.h> -#include <qimage.h> -#include <qfile.h> -#include <qdebug.h> -#include <QCopChannel> - -QT_BEGIN_NAMESPACE - -#define MM(n) int((n * 720 + 127) / 254) -#define IN(n) int(n * 72) - -extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size); - -QtopiaPrintEngine::QtopiaPrintEngine(QPrinter::PrinterMode mode) - : QPaintEngine(*(new QtopiaPrintEnginePrivate( mode ))) -{ - d_func()->initialize(); -} - -bool QtopiaPrintEngine::begin(QPaintDevice *) -{ - Q_D(QtopiaPrintEngine); - Q_ASSERT_X(d->printerState == QPrinter::Idle, "QtopiaPrintEngine", "printer already active"); - - // Create a new off-screen monochrome image to handle the drawing process. - QSize size = paperRect().size(); - if ( d->pageImage ) - delete d->pageImage; - d->pageImage = new QImage( size, QImage::Format_RGB32 ); - if ( !(d->pageImage) ) - return false; - - // Recreate the paint engine on the new image. - delete d->_paintEngine; - d->_paintEngine = 0; - d->paintEngine()->state = state; - - // Begin the paint process on the image. - if (!d->paintEngine()->begin(d->pageImage)) - return false; - - // Clear the first page to all-white. - clearPage(); - - // Clear the print buffer and output the image header. - d->buffer.clear(); - d->writeG3FaxHeader(); - - // The print engine is currently active. - d->printerState = QPrinter::Active; - return true; -} - -bool QtopiaPrintEngine::end() -{ - Q_D(QtopiaPrintEngine); - - d->paintEngine()->end(); - - // Flush the last page. - flushPage(); - - // Output the fax data to a file (TODO: send to the print queuing daemon). - QString filename; - if ( !d->outputFileName.isEmpty() ) - filename = QString::fromLocal8Bit(qgetenv("HOME").constData()) + QLatin1String("/Documents/") + d->outputFileName; - else - filename = QString::fromLocal8Bit(qgetenv("HOME").constData()) + QLatin1String("/tmp/qwsfax.tiff"); - - setProperty(QPrintEngine::PPK_OutputFileName, filename); - QFile file( filename ); - if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) { - qDebug( "Failed to open %s for printer output", - filename.toLatin1().constData() ); - } else { - file.write( d->buffer.data() ); - file.close(); - } - - // Free up the memory for the image buffer. - d->buffer.clear(); - - // Finalize the print job. - d->printerState = QPrinter::Idle; - - // call qcop service - QMap<QString, QVariant> map; - for ( int x = 0; x <= QPrintEngine::PPK_Duplex; x++ ) - map.insert( QString::number(x), property((QPrintEngine::PrintEnginePropertyKey)(x))); - QVariant variant(map); - - QByteArray data; - QDataStream out(&data, QIODevice::WriteOnly); - out << variant; - QCopChannel::send(QLatin1String("QPE/Service/Print"), QLatin1String("print(QVariant)"), data); - - return true; -} - -QPaintEngine *QtopiaPrintEngine::paintEngine() const -{ - return const_cast<QtopiaPrintEnginePrivate *>(d_func())->paintEngine(); -} - -void QtopiaPrintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) -{ - Q_D(QtopiaPrintEngine); - Q_ASSERT(d->printerState == QPrinter::Active); - d->paintEngine()->drawPixmap(r, pm, sr); -} - -void QtopiaPrintEngine::drawTextItem(const QPointF &p, const QTextItem &ti) -{ - Q_D(QtopiaPrintEngine); - Q_ASSERT(d->printerState == QPrinter::Active); - d->paintEngine()->drawTextItem(p, ti); -} - -void QtopiaPrintEngine::updateState(const QPaintEngineState &state) -{ - Q_D(QtopiaPrintEngine); - d->paintEngine()->updateState(state); -} - -QRect QtopiaPrintEngine::paperRect() const -{ - QSizeF s = qt_paperSizeToQSizeF(d_func()->paperSize); - s.rwidth() = MM(s.width()); - s.rheight() = MM(s.height()); - int w = qRound(s.width()*d_func()->resolution/72.); - int h = qRound(s.height()*d_func()->resolution/72.); - if (d_func()->orientation == QPrinter::Portrait) - return QRect(0, 0, w, h); - else - return QRect(0, 0, h, w); -} - -QRect QtopiaPrintEngine::pageRect() const -{ - QRect r = paperRect(); - if (d_func()->fullPage) - return r; - // would be nice to get better margins than this. - return QRect(d_func()->resolution/3, d_func()->resolution/3, r.width()-2*d_func()->resolution/3, r.height()-2*d_func()->resolution/3); -} - -bool QtopiaPrintEngine::newPage() -{ - flushPage(); - clearPage(); - ++(d_func()->pageNumber); - return true; -} - -bool QtopiaPrintEngine::abort() -{ - return false; -} - -QPrinter::PrinterState QtopiaPrintEngine::printerState() const -{ - return d_func()->printerState; -} - -int QtopiaPrintEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const -{ - int val; - QRect r = d_func()->fullPage ? paperRect() : pageRect(); - switch (metricType) { - case QPaintDevice::PdmWidth: - val = r.width(); - break; - case QPaintDevice::PdmHeight: - val = r.height(); - break; - case QPaintDevice::PdmDpiX: - val = d_func()->resolution; - break; - case QPaintDevice::PdmDpiY: - val = d_func()->resolution; - break; - case QPaintDevice::PdmPhysicalDpiX: - case QPaintDevice::PdmPhysicalDpiY: - val = QT_QWS_PRINTER_DEFAULT_DPI; - break; - case QPaintDevice::PdmWidthMM: - val = qRound(r.width()*25.4/d_func()->resolution); - break; - case QPaintDevice::PdmHeightMM: - val = qRound(r.height()*25.4/d_func()->resolution); - break; - case QPaintDevice::PdmNumColors: - val = 2; - break; - case QPaintDevice::PdmDepth: - val = 1; - break; - default: - qWarning("QtopiaPrintEngine::metric: Invalid metric command"); - return 0; - } - return val; -} - -QVariant QtopiaPrintEngine::property(PrintEnginePropertyKey key) const -{ - Q_D(const QtopiaPrintEngine); - QVariant ret; - - switch (key) { - case PPK_CollateCopies: - ret = d->collateCopies; - break; - case PPK_ColorMode: - ret = d->colorMode; - break; - case PPK_Creator: - ret = d->creator; - break; - case PPK_DocumentName: - ret = d->docName; - break; - case PPK_FullPage: - ret = d->fullPage; - break; - case PPK_CopyCount: // fallthrough - case PPK_NumberOfCopies: - ret = d->numCopies; - break; - case PPK_SupportsMultipleCopies: - ret = false; - break; - case PPK_Orientation: - ret = d->orientation; - break; - case PPK_OutputFileName: - ret = d->outputFileName; - break; - case PPK_PageOrder: - ret = d->pageOrder; - break; - case PPK_PageRect: - ret = pageRect(); - break; - case PPK_PaperSize: - ret = d->paperSize; - break; - case PPK_PaperRect: - ret = paperRect(); - break; - case PPK_PaperSource: - ret = d->paperSource; - break; - case PPK_PrinterName: - ret = d->printerName; - break; - case PPK_PrinterProgram: - ret = d->printProgram; - break; - case PPK_Resolution: - ret = d->resolution; - break; - case PPK_SupportedResolutions: - ret = QList<QVariant>() << QT_QWS_PRINTER_DEFAULT_DPI; - break; - default: - break; - } - return ret; -} - -void QtopiaPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) -{ - Q_D(QtopiaPrintEngine); - switch (key) { - case PPK_CollateCopies: - d->collateCopies = value.toBool(); - break; - case PPK_ColorMode: - d->colorMode = QPrinter::ColorMode(value.toInt()); - break; - case PPK_Creator: - d->creator = value.toString(); - break; - case PPK_DocumentName: - d->docName = value.toString(); - break; - case PPK_FullPage: - d->fullPage = value.toBool(); - break; - case PPK_CopyCount: // fallthrough - case PPK_NumberOfCopies: - d->numCopies = value.toInt(); - break; - case PPK_Orientation: - d->orientation = QPrinter::Orientation(value.toInt()); - break; - case PPK_OutputFileName: - d->outputFileName = value.toString(); - break; - case PPK_PageOrder: - d->pageOrder = QPrinter::PageOrder(value.toInt()); - break; - case PPK_PaperSize: - d->paperSize = QPrinter::PaperSize(value.toInt()); - break; - case PPK_PaperSource: - d->paperSource = QPrinter::PaperSource(value.toInt()); - case PPK_PrinterName: - d->printerName = value.toString(); - break; - case PPK_PrinterProgram: - d->printProgram = value.toString(); - break; - case PPK_Resolution: - d->resolution = value.toInt(); - break; - default: - break; - } -} - -void QtopiaPrintEngine::clearPage() -{ - d_func()->pageImage->fill(QColor(255, 255, 255).rgb()); -} - -void QtopiaPrintEngine::flushPage() -{ - d_func()->writeG3FaxPage(); -} - -QtopiaPrintEnginePrivate::~QtopiaPrintEnginePrivate() -{ - if ( pageImage ) - delete pageImage; -} - -void QtopiaPrintEnginePrivate::initialize() -{ - _paintEngine = 0; -} - -QPaintEngine *QtopiaPrintEnginePrivate::paintEngine() -{ - if (!_paintEngine) - _paintEngine = new QRasterPaintEngine(pageImage); - return _paintEngine; -} - -void QtopiaPrintEnginePrivate::writeG3FaxHeader() -{ - // Write the TIFF file magic number (little-endian TIFF). - buffer.append( (char)'I' ); - buffer.append( (char)'I' ); - buffer.append( (char)42 ); - buffer.append( (char)0 ); - - // Leave a place-holder for the IFD offset of the first page. - ifdPatch = buffer.size(); - buffer.append( (int)0 ); -} - -// Tag values, from RFC 2301. -#define TIFF_IFD_NEW_SUB_FILE_TYPE 254 -#define TIFF_IFD_IMAGE_WIDTH 256 -#define TIFF_IFD_IMAGE_LENGTH 257 -#define TIFF_IFD_BITS_PER_SAMPLE 258 -#define TIFF_IFD_COMPRESSION 259 -#define TIFF_IFD_PHOTOMETRIC_INTERP 262 -#define TIFF_IFD_FILL_ORDER 266 -#define TIFF_IFD_STRIP_OFFSETS 273 -#define TIFF_IFD_ORIENTATION 274 -#define TIFF_IFD_SAMPLES_PER_PIXEL 277 -#define TIFF_IFD_ROWS_PER_STRIP 278 -#define TIFF_IFD_STRIP_BYTE_COUNTS 279 -#define TIFF_IFD_X_RESOLUTION 282 -#define TIFF_IFD_Y_RESOLUTION 283 -#define TIFF_IFD_PLANAR_CONFIG 284 -#define TIFF_IFD_T4_OPTIONS 292 -#define TIFF_IFD_RESOLUTION_UNIT 296 -#define TIFF_IFD_PAGE_NUMBER 297 -#define TIFF_IFD_CLEAN_FAX_DATA 327 - -// IFD type values. -#define TIFF_TYPE_SHORT 3 -#define TIFF_TYPE_LONG 4 -#define TIFF_TYPE_RATIONAL 5 - -// Construct a SHORT pair from two values. -#define TIFF_SHORT_PAIR(a,b) (((a) & 0xFFFF) | ((b) << 16)) - -// Width of a FAX page in pixels, in the baseline specification from RFC 2301. -// This must be hard-wired, as per the RFC. We truncate any pixels that -// are beyond this limit, or pad lines to reach this limit. -#define TIFF_FAX_WIDTH 1728 - -void QtopiaPrintEnginePrivate::writeG3FaxPage() -{ - // Pad the image file to a word boundary, just in case. - buffer.pad(); - - // Back-patch the IFD link for the previous page. - buffer.patch( ifdPatch, buffer.size() ); - - // Output the contents of the IFD for this page (these must be - // in ascending order of tag value). - buffer.append( (short)19 ); // Number of IFD entries. - writeG3IFDEntry( TIFF_IFD_NEW_SUB_FILE_TYPE, TIFF_TYPE_LONG, 1, 2 ); - writeG3IFDEntry( TIFF_IFD_IMAGE_WIDTH, TIFF_TYPE_LONG, 1, TIFF_FAX_WIDTH ); - writeG3IFDEntry - ( TIFF_IFD_IMAGE_LENGTH, TIFF_TYPE_LONG, 1, pageImage->height() ); - writeG3IFDEntry( TIFF_IFD_BITS_PER_SAMPLE, TIFF_TYPE_SHORT, 1, 1 ); - writeG3IFDEntry( TIFF_IFD_COMPRESSION, TIFF_TYPE_SHORT, 1, 3 ); - writeG3IFDEntry( TIFF_IFD_PHOTOMETRIC_INTERP, TIFF_TYPE_SHORT, 1, 0 ); - writeG3IFDEntry( TIFF_IFD_FILL_ORDER, TIFF_TYPE_SHORT, 1, 1 ); - int stripOffsets = - writeG3IFDEntry( TIFF_IFD_STRIP_OFFSETS, TIFF_TYPE_LONG, 1, 0 ); - writeG3IFDEntry( TIFF_IFD_ORIENTATION, TIFF_TYPE_SHORT, 1, 1 ); - writeG3IFDEntry( TIFF_IFD_SAMPLES_PER_PIXEL, TIFF_TYPE_SHORT, 1, 1 ); - writeG3IFDEntry - ( TIFF_IFD_ROWS_PER_STRIP, TIFF_TYPE_LONG, 1, pageImage->height() ); - int stripBytes = writeG3IFDEntry - ( TIFF_IFD_STRIP_BYTE_COUNTS, TIFF_TYPE_LONG, 1, 0 ); - int xres = - writeG3IFDEntry( TIFF_IFD_X_RESOLUTION, TIFF_TYPE_RATIONAL, 1, 0 ); - int yres = - writeG3IFDEntry( TIFF_IFD_Y_RESOLUTION, TIFF_TYPE_RATIONAL, 1, 0 ); - writeG3IFDEntry( TIFF_IFD_PLANAR_CONFIG, TIFF_TYPE_SHORT, 1, 1 ); - writeG3IFDEntry( TIFF_IFD_T4_OPTIONS, TIFF_TYPE_LONG, 1, 2 ); - writeG3IFDEntry( TIFF_IFD_RESOLUTION_UNIT, TIFF_TYPE_SHORT, 1, 2 ); - writeG3IFDEntry( TIFF_IFD_PAGE_NUMBER, TIFF_TYPE_SHORT, 2, - TIFF_SHORT_PAIR( pageNumber, 0 ) ); - writeG3IFDEntry( TIFF_IFD_CLEAN_FAX_DATA, TIFF_TYPE_SHORT, 1, 0 ); - - // Leave a place-holder for the IFD offset of the next page. - ifdPatch = buffer.size(); - buffer.append( (int)0 ); - - // Output the X and Y resolutions, as rational values (usually 200/1). - buffer.patch( xres, buffer.size() ); - buffer.append( (int)resolution ); - buffer.append( (int)1 ); - buffer.patch( yres, buffer.size() ); - buffer.append( (int)resolution ); - buffer.append( (int)1 ); - - // We are now at the start of the image data - set the strip offset. - int start = buffer.size(); - buffer.patch( stripOffsets, start ); - - // Output the image data. - int width = pageImage->width(); - QImage::Format imageFormat = pageImage->format(); - for ( int y = 0; y < pageImage->height(); ++y ) { - unsigned char *scan = pageImage->scanLine(y); - int prev, pixel, len; - writeG3EOL(); - prev = 0; - len = 0; - - uint currentColor = qRgb(255, 255, 255); // start with white - - for ( int x = 0; x < width && x < TIFF_FAX_WIDTH; ++x ) { - if ( imageFormat == QImage::Format_RGB32 ) { - // read color of the current pixel - uint *p = (uint *)scan + x; - - if ( *p == currentColor ) { // if it is the same color - len++; // imcrement length - } else { // otherwise write color into the buffer - if ( len > 0 ) { - if ( currentColor == qRgb(0, 0, 0) ) - writeG3BlackRun( len ); - else - writeG3WhiteRun( len ); - } - // initialise length and color; - len = 1; - currentColor = *p; - } - } else if ( imageFormat == QImage::Format_Mono ) { - pixel = ((scan[x >> 3] & (1 << (x & 7))) != 0); - if ( pixel != prev ) { - if ( prev ) { - writeG3BlackRun( len ); - } else { - writeG3WhiteRun( len ); - } - prev = pixel; - len = 1; - } else { - ++len; - } - } - } - - if ( imageFormat == QImage::Format_RGB32 ) { - // Output the last run on the line, and pad to TIFF_FAX_WIDTH. - if ( len != 0 ) { - if ( currentColor == qRgb(0, 0, 0) ) - writeG3BlackRun( len ); - else - writeG3WhiteRun( len ); - } - if ( width < TIFF_FAX_WIDTH ) - writeG3WhiteRun( TIFF_FAX_WIDTH - width ); - } else if ( imageFormat == QImage::Format_Mono ) { - if ( len != 0 ) { - if ( prev ) { - writeG3BlackRun( len ); - if ( width < TIFF_FAX_WIDTH ) { - writeG3WhiteRun( TIFF_FAX_WIDTH - width ); - } - } else { - if ( width < TIFF_FAX_WIDTH ) { - writeG3WhiteRun( len + ( TIFF_FAX_WIDTH - width ) ); - } else { - writeG3WhiteRun( len ); - } - } - } - } - } - - // Flush the last partial byte, which is padded with zero fill bits. - if ( partialBits > 0 ) { - buffer.append( (char)( partialByte << ( 8 - partialBits ) ) ); - partialByte = 0; - partialBits = 0; - } - - // end of page add six EOLs - for ( int i = 0; i < 6; i++ ) - writeG3EOL(); - - // Update the byte count for the image data strip. - buffer.patch( stripBytes, buffer.size() - start ); -} - -int QtopiaPrintEnginePrivate::writeG3IFDEntry - ( int tag, int type, int count, int value ) -{ - buffer.append( (short)tag ); - buffer.append( (short)type ); - buffer.append( count ); - buffer.append( value ); - return buffer.size() - 4; // Offset of the value for back-patching. -} - -void QtopiaPrintEnginePrivate::writeG3Code( int code, int bits ) -{ - partialByte = ( ( partialByte << bits ) | code ); - partialBits += bits; - while ( partialBits >= 8 ) { - partialBits -= 8; - buffer.append( (char)( partialByte >> partialBits ) ); - } -} - -void QtopiaPrintEnginePrivate::writeG3WhiteRun( int len ) -{ - static struct { - unsigned short code; - unsigned short bits; - } whiteCodes[64 + 27] = { - {0x0035, 8}, // 0 - {0x0007, 6}, - {0x0007, 4}, - {0x0008, 4}, - {0x000B, 4}, - {0x000C, 4}, - {0x000E, 4}, - {0x000F, 4}, - {0x0013, 5}, // 8 - {0x0014, 5}, - {0x0007, 5}, - {0x0008, 5}, - {0x0008, 6}, - {0x0003, 6}, - {0x0034, 6}, - {0x0035, 6}, - {0x002A, 6}, // 16 - {0x002B, 6}, - {0x0027, 7}, - {0x000C, 7}, - {0x0008, 7}, - {0x0017, 7}, - {0x0003, 7}, - {0x0004, 7}, - {0x0028, 7}, // 24 - {0x002B, 7}, - {0x0013, 7}, - {0x0024, 7}, - {0x0018, 7}, - {0x0002, 8}, - {0x0003, 8}, - {0x001A, 8}, - {0x001B, 8}, // 32 - {0x0012, 8}, - {0x0013, 8}, - {0x0014, 8}, - {0x0015, 8}, - {0x0016, 8}, - {0x0017, 8}, - {0x0028, 8}, - {0x0029, 8}, // 40 - {0x002A, 8}, - {0x002B, 8}, - {0x002C, 8}, - {0x002D, 8}, - {0x0004, 8}, - {0x0005, 8}, - {0x000A, 8}, - {0x000B, 8}, // 48 - {0x0052, 8}, - {0x0053, 8}, - {0x0054, 8}, - {0x0055, 8}, - {0x0024, 8}, - {0x0025, 8}, - {0x0058, 8}, - {0x0059, 8}, // 56 - {0x005A, 8}, - {0x005B, 8}, - {0x004A, 8}, - {0x004B, 8}, - {0x0032, 8}, - {0x0033, 8}, - {0x0034, 8}, - {0x001B, 5}, // Make up codes: 64 - {0x0012, 5}, // 128 - {0x0017, 6}, // 192 - {0x0037, 7}, // 256 - {0x0036, 8}, // 320 - {0x0037, 8}, // 384 - {0x0064, 8}, // 448 - {0x0065, 8}, // 512 - {0x0068, 8}, // 576 - {0x0067, 8}, // 640 - {0x00CC, 9}, // 704 - {0x00CD, 9}, // 768 - {0x00D2, 9}, // 832 - {0x00D3, 9}, // 896 - {0x00D4, 9}, // 960 - {0x00D5, 9}, // 1024 - {0x00D6, 9}, // 1088 - {0x00D7, 9}, // 1152 - {0x00D8, 9}, // 1216 - {0x00D9, 9}, // 1280 - {0x00DA, 9}, // 1344 - {0x00DB, 9}, // 1408 - {0x0098, 9}, // 1472 - {0x0099, 9}, // 1536 - {0x009A, 9}, // 1600 - {0x0018, 6}, // 1664 - {0x009B, 9}, // 1728 - }; - if ( len >= 64 ) { - int index = 63 + (len >> 6); - writeG3Code( whiteCodes[index].code, whiteCodes[index].bits ); - len &= 63; - } - writeG3Code( whiteCodes[len].code, whiteCodes[len].bits ); -} - -void QtopiaPrintEnginePrivate::writeG3BlackRun( int len ) -{ - static struct { - unsigned short code; - unsigned short bits; - } blackCodes[64 + 27] = { - {0x0037, 10}, // 0 - {0x0002, 3}, - {0x0003, 2}, - {0x0002, 2}, - {0x0003, 3}, - {0x0003, 4}, - {0x0002, 4}, - {0x0003, 5}, - {0x0005, 6}, // 8 - {0x0004, 6}, - {0x0004, 7}, - {0x0005, 7}, - {0x0007, 7}, - {0x0004, 8}, - {0x0007, 8}, - {0x0018, 9}, - {0x0017, 10}, // 16 - {0x0018, 10}, - {0x0008, 10}, - {0x0067, 11}, - {0x0068, 11}, - {0x006C, 11}, - {0x0037, 11}, - {0x0028, 11}, - {0x0017, 11}, // 24 - {0x0018, 11}, - {0x00CA, 12}, - {0x00CB, 12}, - {0x00CC, 12}, - {0x00CD, 12}, - {0x0068, 12}, - {0x0069, 12}, - {0x006A, 12}, // 32 - {0x006B, 12}, - {0x00D2, 12}, - {0x00D3, 12}, - {0x00D4, 12}, - {0x00D5, 12}, - {0x00D6, 12}, - {0x00D7, 12}, - {0x006C, 12}, // 40 - {0x006D, 12}, - {0x00DA, 12}, - {0x00DB, 12}, - {0x0054, 12}, - {0x0055, 12}, - {0x0056, 12}, - {0x0057, 12}, - {0x0064, 12}, // 48 - {0x0065, 12}, - {0x0052, 12}, - {0x0053, 12}, - {0x0024, 12}, - {0x0037, 12}, - {0x0038, 12}, - {0x0027, 12}, - {0x0028, 12}, // 56 - {0x0058, 12}, - {0x0059, 12}, - {0x002B, 12}, - {0x002C, 12}, - {0x005A, 12}, - {0x0066, 12}, - {0x0067, 12}, - {0x000F, 10}, // Make up codes: 64 - {0x00C8, 12}, // 128 - {0x00C9, 12}, // 192 - {0x005B, 12}, // 256 - {0x0033, 12}, // 320 - {0x0034, 12}, // 384 - {0x0035, 12}, // 448 - {0x006C, 13}, // 512 - {0x006D, 13}, // 576 - {0x004A, 13}, // 640 - {0x004B, 13}, // 704 - {0x004C, 13}, // 768 - {0x004D, 13}, // 832 - {0x0072, 13}, // 896 - {0x0073, 13}, // 960 - {0x0074, 13}, // 1024 - {0x0075, 13}, // 1088 - {0x0076, 13}, // 1152 - {0x0077, 13}, // 1216 - {0x0052, 13}, // 1280 - {0x0053, 13}, // 1344 - {0x0054, 13}, // 1408 - {0x0055, 13}, // 1472 - {0x005A, 13}, // 1536 - {0x005B, 13}, // 1600 - {0x0064, 13}, // 1664 - {0x0065, 13}, // 1728 - }; - if ( len >= 64 ) { - int index = 63 + (len >> 6); - writeG3Code( blackCodes[index].code, blackCodes[index].bits ); - len &= 63; - } - writeG3Code( blackCodes[len].code, blackCodes[len].bits ); -} - -void QtopiaPrintEnginePrivate::writeG3EOL() -{ - int bitToPad; - if ( partialBits <= 4 ) { - bitToPad = 4 - partialBits; - } else { - bitToPad = 8 - partialBits + 4; - } - - partialByte = ((partialByte << (bitToPad + 12)) | 0x0001); - partialBits += bitToPad + 12; - - while ( partialBits >= 8 ) { - partialBits -= 8; - buffer.append( (char)(partialByte >> partialBits ) ); - } -// writeG3Code( 0x0001, 12 ); -} - -void QtopiaPrintBuffer::append( short value ) -{ - if ( _bigEndian ) { - _data.append( (char)(value >> 8) ); - _data.append( (char)value ); - } else { - _data.append( (char)value ); - _data.append( (char)(value >> 8) ); - } -} - -void QtopiaPrintBuffer::append( int value ) -{ - if ( _bigEndian ) { - _data.append( (char)(value >> 24) ); - _data.append( (char)(value >> 16) ); - _data.append( (char)(value >> 8) ); - _data.append( (char)value ); - } else { - _data.append( (char)value ); - _data.append( (char)(value >> 8) ); - _data.append( (char)(value >> 16) ); - _data.append( (char)(value >> 24) ); - } -} - -void QtopiaPrintBuffer::patch( int posn, int value ) -{ - if ( _bigEndian ) { - _data[posn] = (char)(value >> 24); - _data[posn + 1] = (char)(value >> 16); - _data[posn + 2] = (char)(value >> 8); - _data[posn + 3] = (char)value; - } else { - _data[posn] = (char)value; - _data[posn + 1] = (char)(value >> 8); - _data[posn + 2] = (char)(value >> 16); - _data[posn + 3] = (char)(value >> 24); - } -} - -void QtopiaPrintBuffer::pad() -{ - while ( ( _data.size() % 4 ) != 0 ) - _data.append( (char)0 ); -} - -QT_END_NAMESPACE - -#endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprintengine_qws_p.h b/src/gui/painting/qprintengine_qws_p.h deleted file mode 100644 index 59cbe3eba8..0000000000 --- a/src/gui/painting/qprintengine_qws_p.h +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPRINTENGINE_QWS_P_H -#define QPRINTENGINE_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "QtGui/qprinter.h" - -#ifndef QT_NO_PRINTER - -#include "QtGui/qprintengine.h" -#include "QtCore/qbytearray.h" -#include "private/qpaintengine_p.h" - -QT_BEGIN_NAMESPACE - -class QtopiaPrintEnginePrivate; -class QRasterPaintEngine; -class QPrinterPrivate; -class QImage; - -class QtopiaPrintEngine : public QPaintEngine, public QPrintEngine -{ - Q_DECLARE_PRIVATE(QtopiaPrintEngine) -public: - QtopiaPrintEngine(QPrinter::PrinterMode mode); - - // override QWSPaintEngine - bool begin(QPaintDevice *dev); - bool end(); - void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); - void drawTextItem(const QPointF &p, const QTextItem &ti); - QPaintEngine::Type type() const { return QPaintEngine::X11; } - - QPaintEngine *paintEngine() const; - - void updateState(const QPaintEngineState &state); - - QRect paperRect() const; - QRect pageRect() const; - - bool newPage(); - bool abort(); - - QPrinter::PrinterState printerState() const; - - int metric(QPaintDevice::PaintDeviceMetric metricType) const; - - QVariant property(PrintEnginePropertyKey key) const; - void setProperty(PrintEnginePropertyKey key, const QVariant &value); - -private: - friend class QPrintDialog; - friend class QPageSetupDialog; - - void clearPage(); - void flushPage(); -}; - -class QtopiaPrintBuffer -{ -public: - QtopiaPrintBuffer( bool bigEndian=FALSE ) { _bigEndian = bigEndian; } - ~QtopiaPrintBuffer() {} - - const QByteArray& data() const { return _data; } - - int size() const { return _data.size(); } - - void clear() { _data.clear(); } - - void append( char value ) { _data.append( value ); } - void append( short value ); - void append( int value ); - void append( const QByteArray& array ) { _data.append( array ); } - - void patch( int posn, int value ); - - void pad(); - -private: - QByteArray _data; - bool _bigEndian; -}; - -#define QT_QWS_PRINTER_DEFAULT_DPI 200 - -class QtopiaPrintEnginePrivate : public QPaintEnginePrivate -{ - Q_DECLARE_PUBLIC(QtopiaPrintEngine) -public: - QtopiaPrintEnginePrivate(QPrinter::PrinterMode m) : - mode(m), - printerState(QPrinter::Idle), - orientation(QPrinter::Portrait), - paperSize(QPrinter::A4), - pageOrder(QPrinter::FirstPageFirst), - colorMode(QPrinter::GrayScale), - paperSource(QPrinter::OnlyOne), - resolution(QT_QWS_PRINTER_DEFAULT_DPI), - _paintEngine(0), - numCopies(1), - outputToFile(false), - fullPage(false), - collateCopies(false), - pageNumber(0), - pageImage(0), - partialByte(0), - partialBits(0) - { - } - ~QtopiaPrintEnginePrivate(); - - void initialize(); - QPaintEngine *paintEngine(); - - QPrinter::PrinterMode mode; - - QString printerName; - QString outputFileName; - QString printProgram; - QString docName; - QString creator; - - QPrinter::PrinterState printerState; - - QPrinter::Orientation orientation; - QPrinter::PaperSize paperSize; - QPrinter::PageOrder pageOrder; - QPrinter::ColorMode colorMode; - QPrinter::PaperSource paperSource; - - int resolution; - QPaintEngine *_paintEngine; - int numCopies; - - bool outputToFile; - bool fullPage; - bool collateCopies; - - int pageNumber; - - QImage *pageImage; - - QtopiaPrintBuffer buffer; - - // Definitions that are only relevant to G3FAX output. - int ifdPatch; - int partialByte; - int partialBits; - void writeG3FaxHeader(); - void writeG3FaxPage(); - int writeG3IFDEntry( int tag, int type, int count, int value ); - void writeG3Code( int code, int bits ); - void writeG3WhiteRun( int len ); - void writeG3BlackRun( int len ); - void writeG3EOL(); -}; - -QT_END_NAMESPACE - -#endif // QT_NO_PRINTER - -#endif // QPRINTENGINE_QWS_P_H diff --git a/src/gui/painting/qregion_qws.cpp b/src/gui/painting/qregion_qws.cpp deleted file mode 100644 index dca46d3ec0..0000000000 --- a/src/gui/painting/qregion_qws.cpp +++ /dev/null @@ -1,3183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// XXX - add appropriate friendship relationships -#define private public -#include "qregion.h" -#undef private -#include "qpainterpath.h" -#include "qpolygon.h" -#include "qbuffer.h" -#include "qimage.h" -#include <qdebug.h> -#include "qbitmap.h" -#include <stdlib.h> -#include <qatomic.h> -#include <qsemaphore.h> - -QT_BEGIN_NAMESPACE - -class QFastMutex -{ - QAtomicInt contenders; - QSemaphore semaphore; -public: - inline QFastMutex() - : contenders(0), semaphore(0) - { } - inline void lock() - { - if (contenders.fetchAndAddAcquire(1) != 0) { - semaphore.acquire(); - contenders.deref(); - } - } - inline bool tryLock() - { - return contenders.testAndSetAcquire(0, 1); - } - inline void unlock() - { - if (!contenders.testAndSetRelease(1, 0)) - semaphore.release(); - } -}; - - -/* - * 1 if r1 contains r2 - * 0 if r1 does not completely contain r2 - */ -#define CONTAINSCHECK(r1, r2) \ - ((r2).left() >= (r1).left() && (r2).right() <= (r1).right() && \ - (r2).top() >= (r1).top() && (r2).bottom() <= (r1).bottom()) - -/* - * clip region - */ -struct QRegionPrivate : public QRegion::QRegionData { - enum { Single, Vector } mode; - int numRects; - QVector<QRect> rects; - QRect single; - QRect extents; - QRect innerRect; - union { - int innerArea; - QRegionPrivate *next; - }; - - inline void vector() - { - if(mode != Vector && numRects) { - if(rects.size() < 1) rects.resize(1); - rects[0] = single; - } - mode = Vector; - } - - inline QRegionPrivate() : mode(Single), numRects(0), innerArea(-1) {} - inline QRegionPrivate(const QRect &r) : mode(Single) { - numRects = 1; -// rects[0] = r; - single = r; - extents = r; - innerRect = r; - innerArea = r.width() * r.height(); - } - - inline QRegionPrivate(const QRegionPrivate &r) { - mode = r.mode; - rects = r.rects; - single = r.single; - numRects = r.numRects; - extents = r.extents; - innerRect = r.innerRect; - innerArea = r.innerArea; - } - - inline QRegionPrivate &operator=(const QRegionPrivate &r) { - mode = r.mode; - rects = r.rects; - single = r.single; - numRects = r.numRects; - extents = r.extents; - innerRect = r.innerRect; - innerArea = r.innerArea; - return *this; - } - - /* - * Returns true if r is guaranteed to be fully contained in this region. - * A false return value does not guarantee the opposite. - */ - inline bool contains(const QRegionPrivate &r) const { - const QRect &r1 = innerRect; - const QRect &r2 = r.extents; - return CONTAINSCHECK(r1, r2); - } - - inline void updateInnerRect(const QRect &rect) { - const int area = rect.width() * rect.height(); - if (area > innerArea) { - innerArea = area; - innerRect = rect; - } - } - - void append(const QRegionPrivate *r); - void prepend(const QRegionPrivate *r); - inline bool canAppend(const QRegionPrivate *r) const; - inline bool canPrepend(const QRegionPrivate *r) const; -}; - -static QRegionPrivate *qt_nextRegionPtr = 0; -static QFastMutex qt_nextRegionLock; - -static QRegionPrivate *qt_allocRegionMemory() -{ - QRegionPrivate *rv = 0; - qt_nextRegionLock.lock(); - - if(qt_nextRegionPtr) { - rv = qt_nextRegionPtr; - qt_nextRegionPtr = rv->next; - } else { - qt_nextRegionPtr = - (QRegionPrivate *)malloc(256 * sizeof(QRegionPrivate)); - for(int ii = 0; ii < 256; ++ii) { - if(ii == 255) { - qt_nextRegionPtr[ii].next = 0; - } else { - qt_nextRegionPtr[ii].next = &qt_nextRegionPtr[ii + 1]; - } - } - - rv = qt_nextRegionPtr; - qt_nextRegionPtr = rv->next; - } - - qt_nextRegionLock.unlock(); - return rv; -} - -static void qt_freeRegionMemory(QRegionPrivate *rp) -{ - qt_nextRegionLock.lock(); - rp->next = qt_nextRegionPtr; - qt_nextRegionPtr = rp; - qt_nextRegionLock.unlock(); -} - -static QRegionPrivate *qt_allocRegion() -{ - QRegionPrivate *mem = qt_allocRegionMemory(); - return new (mem) QRegionPrivate; -} - -static QRegionPrivate *qt_allocRegion(const QRect &r) -{ - QRegionPrivate *mem = qt_allocRegionMemory(); - return new (mem) QRegionPrivate(r); -} - -static QRegionPrivate *qt_allocRegion(const QRegionPrivate &r) -{ - QRegionPrivate *mem = qt_allocRegionMemory(); - return new (mem) QRegionPrivate(r); -} - -void qt_freeRegion(QRegionPrivate *rp) -{ - rp->~QRegionPrivate(); - qt_freeRegionMemory(rp); -// delete rp; -} - -static inline bool isEmptyHelper(const QRegionPrivate *preg) -{ - return !preg || preg->numRects == 0; -} - -void QRegionPrivate::append(const QRegionPrivate *r) -{ - Q_ASSERT(!isEmptyHelper(r)); - - vector(); - QRect *destRect = rects.data() + numRects; - const QRect *srcRect = (r->mode==Vector)?r->rects.constData():&r->single; - int numAppend = r->numRects; - - // test for merge in x direction - { - const QRect *rFirst = srcRect; - QRect *myLast = rects.data() + (numRects - 1); - if (rFirst->top() == myLast->top() - && rFirst->height() == myLast->height() - && rFirst->left() == (myLast->right() + 1)) - { - myLast->setWidth(myLast->width() + rFirst->width()); - updateInnerRect(*myLast); - ++srcRect; - --numAppend; - } - } - - // append rectangles - const int newNumRects = numRects + numAppend; - if (newNumRects > rects.size()) { - rects.resize(newNumRects); - destRect = rects.data() + numRects; - } - memcpy(destRect, srcRect, numAppend * sizeof(QRect)); - - // update inner rectangle - if (innerArea < r->innerArea) { - innerArea = r->innerArea; - innerRect = r->innerRect; - } - - // update extents - destRect = &extents; - srcRect = &r->extents; - extents.setCoords(qMin(destRect->left(), srcRect->left()), - qMin(destRect->top(), srcRect->top()), - qMax(destRect->right(), srcRect->right()), - qMax(destRect->bottom(), srcRect->bottom())); - - numRects = newNumRects; -} - -void QRegionPrivate::prepend(const QRegionPrivate *r) -{ -#if 1 - Q_UNUSED(r); -#else - // XXX ak: does not respect vectorization of region - - Q_ASSERT(!isEmpty(r)); - - // move existing rectangles - memmove(rects.data() + r->numRects, rects.constData(), - numRects * sizeof(QRect)); - - // prepend new rectangles - memcpy(rects.data(), r->rects.constData(), r->numRects * sizeof(QRect)); - - // update inner rectangle - if (innerArea < r->innerArea) { - innerArea = r->innerArea; - innerRect = r->innerRect; - } - - // update extents - destRect = &extents; - srcRect = &r->extents; - extents.setCoords(qMin(destRect->left(), srcRect->left()), - qMin(destRect->top(), srcRect->top()), - qMax(destRect->right(), srcRect->right()), - qMax(destRect->bottom(), srcRect->bottom())); - - numRects = newNumRects; -#endif -} - -bool QRegionPrivate::canAppend(const QRegionPrivate *r) const -{ - Q_ASSERT(!isEmptyHelper(r)); - - const QRect *rFirst = (r->mode==Vector)?r->rects.constData():&r->single; - const QRect *myLast = (mode==Vector)?(rects.constData() + (numRects - 1)):&single; - // XXX: possible improvements: - // - nFirst->top() == myLast->bottom() + 1, must possibly merge bands - if (rFirst->top() > (myLast->bottom() + 1) - || (rFirst->top() == myLast->top() - && rFirst->height() == myLast->height() - && rFirst->left() > myLast->right())) - { - return true; - } - - return false; -} - -bool QRegionPrivate::canPrepend(const QRegionPrivate *r) const -{ -#if 1 - Q_UNUSED(r); - return false; -#else - return r->canAppend(this); -#endif -} - -#if defined(Q_WS_X11) -QT_BEGIN_INCLUDE_NAMESPACE -# include "qregion_x11.cpp" -QT_END_INCLUDE_NAMESPACE -#elif defined(Q_WS_MAC) -QT_BEGIN_INCLUDE_NAMESPACE -# include "qregion_mac.cpp" -QT_END_INCLUDE_NAMESPACE -#elif defined(Q_WS_QWS) -static QRegionPrivate qrp; -QRegion::QRegionData QRegion::shared_empty = {Q_BASIC_ATOMIC_INITIALIZER(1), &qrp}; -#endif - -typedef void (*OverlapFunc)(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End, - register const QRect *r2, const QRect *r2End, register int y1, register int y2); -typedef void (*NonOverlapFunc)(register QRegionPrivate &dest, register const QRect *r, const QRect *rEnd, - register int y1, register int y2); - -static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2); -static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest); -static void miRegionOp(register QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2, - OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func, - NonOverlapFunc nonOverlap2Func); - -#define RectangleOut 0 -#define RectangleIn 1 -#define RectanglePart 2 -#define EvenOddRule 0 -#define WindingRule 1 - -// START OF region.h extract -/* $XConsortium: region.h,v 11.14 94/04/17 20:22:20 rws Exp $ */ -/************************************************************************ - -Copyright (c) 1987 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -#ifndef _XREGION_H -#define _XREGION_H - -QT_BEGIN_INCLUDE_NAMESPACE -#include <limits.h> -QT_END_INCLUDE_NAMESPACE - -/* 1 if two BOXs overlap. - * 0 if two BOXs do not overlap. - * Remember, x2 and y2 are not in the region - */ -#define EXTENTCHECK(r1, r2) \ - ((r1)->right() >= (r2)->left() && \ - (r1)->left() <= (r2)->right() && \ - (r1)->bottom() >= (r2)->top() && \ - (r1)->top() <= (r2)->bottom()) - -/* - * update region extents - */ -#define EXTENTS(r,idRect){\ - if((r)->left() < (idRect)->extents.left())\ - (idRect)->extents.setLeft((r)->left());\ - if((r)->top() < (idRect)->extents.top())\ - (idRect)->extents.setTop((r)->top());\ - if((r)->right() > (idRect)->extents.right())\ - (idRect)->extents.setRight((r)->right());\ - if((r)->bottom() > (idRect)->extents.bottom())\ - (idRect)->extents.setBottom((r)->bottom());\ - } - -/* - * Check to see if there is enough memory in the present region. - */ -#define MEMCHECK(dest, rect, firstrect){\ - if ((dest).numRects >= ((dest).rects.size()-1)){\ - firstrect.resize(firstrect.size() * 2); \ - (rect) = (firstrect).data() + (dest).numRects;\ - }\ - } - - -/* - * number of points to buffer before sending them off - * to scanlines(): Must be an even number - */ -#define NUMPTSTOBUFFER 200 - -/* - * used to allocate buffers for points and link - * the buffers together - */ -typedef struct _POINTBLOCK { - QPoint pts[NUMPTSTOBUFFER]; - struct _POINTBLOCK *next; -} POINTBLOCK; - -#endif -// END OF region.h extract - -// START OF Region.c extract -/* $XConsortium: Region.c /main/30 1996/10/22 14:21:24 kaleb $ */ -/************************************************************************ - -Copyright (c) 1987, 1988 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. - - -Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* - * The functions in this file implement the Region abstraction, similar to one - * used in the X11 sample server. A Region is simply an area, as the name - * implies, and is implemented as a "y-x-banded" array of rectangles. To - * explain: Each Region is made up of a certain number of rectangles sorted - * by y coordinate first, and then by x coordinate. - * - * Furthermore, the rectangles are banded such that every rectangle with a - * given upper-left y coordinate (y1) will have the same lower-right y - * coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it - * will span the entire vertical distance of the band. This means that some - * areas that could be merged into a taller rectangle will be represented as - * several shorter rectangles to account for shorter rectangles to its left - * or right but within its "vertical scope". - * - * An added constraint on the rectangles is that they must cover as much - * horizontal area as possible. E.g. no two rectangles in a band are allowed - * to touch. - * - * Whenever possible, bands will be merged together to cover a greater vertical - * distance (and thus reduce the number of rectangles). Two bands can be merged - * only if the bottom of one touches the top of the other and they have - * rectangles in the same places (of the same width, of course). This maintains - * the y-x-banding that's so nice to have... - */ -/* $XFree86: xc/lib/X11/Region.c,v 1.1.1.2.2.2 1998/10/04 15:22:50 hohndel Exp $ */ - -static void UnionRectWithRegion(register const QRect *rect, const QRegionPrivate *source, - QRegionPrivate &dest) -{ - if (!rect->width() || !rect->height()) - return; - - QRegionPrivate region(*rect); - - Q_ASSERT(EqualRegion(source, &dest)); - Q_ASSERT(!isEmptyHelper(®ion)); - - if (dest.numRects == 0) - dest = region; - else if (dest.canAppend(®ion)) - dest.append(®ion); - else - UnionRegion(®ion, source, dest); -} - -/*- - *----------------------------------------------------------------------- - * miSetExtents -- - * Reset the extents and innerRect of a region to what they should be. - * Called by miSubtract and miIntersect b/c they can't figure it out - * along the way or do so easily, as miUnion can. - * - * Results: - * None. - * - * Side Effects: - * The region's 'extents' and 'innerRect' structure is overwritten. - * - *----------------------------------------------------------------------- - */ -static void miSetExtents(QRegionPrivate &dest) -{ - register const QRect *pBox, - *pBoxEnd; - register QRect *pExtents; - - dest.innerRect.setCoords(0, 0, -1, -1); - dest.innerArea = -1; - if (dest.numRects == 0) { - dest.extents.setCoords(0, 0, 0, 0); - return; - } - - pExtents = &dest.extents; - pBox = (dest.mode==QRegionPrivate::Vector)?(dest.rects.constData()):(&dest.single); - pBoxEnd = (dest.mode==QRegionPrivate::Vector)?(&pBox[dest.numRects - 1]):(&dest.single); - - /* - * Since pBox is the first rectangle in the region, it must have the - * smallest y1 and since pBoxEnd is the last rectangle in the region, - * it must have the largest y2, because of banding. Initialize x1 and - * x2 from pBox and pBoxEnd, resp., as good things to initialize them - * to... - */ - pExtents->setLeft(pBox->left()); - pExtents->setTop(pBox->top()); - pExtents->setRight(pBoxEnd->right()); - pExtents->setBottom(pBoxEnd->bottom()); - - Q_ASSERT(pExtents->top() <= pExtents->bottom()); - while (pBox <= pBoxEnd) { - if (pBox->left() < pExtents->left()) - pExtents->setLeft(pBox->left()); - if (pBox->right() > pExtents->right()) - pExtents->setRight(pBox->right()); - dest.updateInnerRect(*pBox); - ++pBox; - } - Q_ASSERT(pExtents->left() <= pExtents->right()); -} - -/* TranslateRegion(pRegion, x, y) - translates in place - added by raymond -*/ - -static void OffsetRegion(register QRegionPrivate ®ion, register int x, register int y) -{ - register int nbox; - register QRect *pbox; - - if(region.mode == QRegionPrivate::Single) { - region.single.translate(x, y); - } else { - pbox = region.rects.data(); - nbox = region.numRects; - - while (nbox--) { - pbox->translate(x, y); - ++pbox; - } - } - region.extents.translate(x, y); - region.innerRect.translate(x, y); -} - -/*====================================================================== - * Region Intersection - *====================================================================*/ -/*- - *----------------------------------------------------------------------- - * miIntersectO -- - * Handle an overlapping band for miIntersect. - * - * Results: - * None. - * - * Side Effects: - * Rectangles may be added to the region. - * - *----------------------------------------------------------------------- - */ -static void miIntersectO(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End, - register const QRect *r2, const QRect *r2End, int y1, int y2) -{ - register int x1; - register int x2; - register QRect *pNextRect; - - pNextRect = dest.rects.data() + dest.numRects; - - while (r1 != r1End && r2 != r2End) { - x1 = qMax(r1->left(), r2->left()); - x2 = qMin(r1->right(), r2->right()); - - /* - * If there's any overlap between the two rectangles, add that - * overlap to the new region. - * There's no need to check for subsumption because the only way - * such a need could arise is if some region has two rectangles - * right next to each other. Since that should never happen... - */ - if (x1 <= x2) { - Q_ASSERT(y1 <= y2); - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(x1, y1, x2, y2); - ++dest.numRects; - ++pNextRect; - } - - /* - * Need to advance the pointers. Shift the one that extends - * to the right the least, since the other still has a chance to - * overlap with that region's next rectangle, if you see what I mean. - */ - if (r1->right() < r2->right()) { - ++r1; - } else if (r2->right() < r1->right()) { - ++r2; - } else { - ++r1; - ++r2; - } - } -} - -/*====================================================================== - * Generic Region Operator - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miCoalesce -- - * Attempt to merge the boxes in the current band with those in the - * previous one. Used only by miRegionOp. - * - * Results: - * The new index for the previous band. - * - * Side Effects: - * If coalescing takes place: - * - rectangles in the previous band will have their y2 fields - * altered. - * - dest.numRects will be decreased. - * - *----------------------------------------------------------------------- - */ -static int miCoalesce(register QRegionPrivate &dest, int prevStart, int curStart) -{ - register QRect *pPrevBox; /* Current box in previous band */ - register QRect *pCurBox; /* Current box in current band */ - register QRect *pRegEnd; /* End of region */ - int curNumRects; /* Number of rectangles in current band */ - int prevNumRects; /* Number of rectangles in previous band */ - int bandY1; /* Y1 coordinate for current band */ - QRect *rData = dest.rects.data(); - - pRegEnd = rData + dest.numRects; - - pPrevBox = rData + prevStart; - prevNumRects = curStart - prevStart; - - /* - * Figure out how many rectangles are in the current band. Have to do - * this because multiple bands could have been added in miRegionOp - * at the end when one region has been exhausted. - */ - pCurBox = rData + curStart; - bandY1 = pCurBox->top(); - for (curNumRects = 0; pCurBox != pRegEnd && pCurBox->top() == bandY1; ++curNumRects) { - ++pCurBox; - } - - if (pCurBox != pRegEnd) { - /* - * If more than one band was added, we have to find the start - * of the last band added so the next coalescing job can start - * at the right place... (given when multiple bands are added, - * this may be pointless -- see above). - */ - --pRegEnd; - while ((pRegEnd - 1)->top() == pRegEnd->top()) - --pRegEnd; - curStart = pRegEnd - rData; - pRegEnd = rData + dest.numRects; - } - - if (curNumRects == prevNumRects && curNumRects != 0) { - pCurBox -= curNumRects; - /* - * The bands may only be coalesced if the bottom of the previous - * matches the top scanline of the current. - */ - if (pPrevBox->bottom() == pCurBox->top() - 1) { - /* - * Make sure the bands have boxes in the same places. This - * assumes that boxes have been added in such a way that they - * cover the most area possible. I.e. two boxes in a band must - * have some horizontal space between them. - */ - do { - if (pPrevBox->left() != pCurBox->left() || pPrevBox->right() != pCurBox->right()) { - // The bands don't line up so they can't be coalesced. - return curStart; - } - ++pPrevBox; - ++pCurBox; - --prevNumRects; - } while (prevNumRects != 0); - - dest.numRects -= curNumRects; - pCurBox -= curNumRects; - pPrevBox -= curNumRects; - - /* - * The bands may be merged, so set the bottom y of each box - * in the previous band to that of the corresponding box in - * the current band. - */ - do { - pPrevBox->setBottom(pCurBox->bottom()); - dest.updateInnerRect(*pPrevBox); - ++pPrevBox; - ++pCurBox; - curNumRects -= 1; - } while (curNumRects != 0); - - /* - * If only one band was added to the region, we have to backup - * curStart to the start of the previous band. - * - * If more than one band was added to the region, copy the - * other bands down. The assumption here is that the other bands - * came from the same region as the current one and no further - * coalescing can be done on them since it's all been done - * already... curStart is already in the right place. - */ - if (pCurBox == pRegEnd) { - curStart = prevStart; - } else { - do { - *pPrevBox++ = *pCurBox++; - dest.updateInnerRect(*pPrevBox); - } while (pCurBox != pRegEnd); - } - } - } - return curStart; -} - -/*- - *----------------------------------------------------------------------- - * miRegionOp -- - * Apply an operation to two regions. Called by miUnion, miInverse, - * miSubtract, miIntersect... - * - * Results: - * None. - * - * Side Effects: - * The new region is overwritten. - * - * Notes: - * The idea behind this function is to view the two regions as sets. - * Together they cover a rectangle of area that this function divides - * into horizontal bands where points are covered only by one region - * or by both. For the first case, the nonOverlapFunc is called with - * each the band and the band's upper and lower extents. For the - * second, the overlapFunc is called to process the entire band. It - * is responsible for clipping the rectangles in the band, though - * this function provides the boundaries. - * At the end of each band, the new region is coalesced, if possible, - * to reduce the number of rectangles in the region. - * - *----------------------------------------------------------------------- - */ -static void miRegionOp(register QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2, - OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func, - NonOverlapFunc nonOverlap2Func) -{ - register const QRect *r1; // Pointer into first region - register const QRect *r2; // Pointer into 2d region - const QRect *r1End; // End of 1st region - const QRect *r2End; // End of 2d region - register int ybot; // Bottom of intersection - register int ytop; // Top of intersection - int prevBand; // Index of start of previous band in dest - int curBand; // Index of start of current band in dest - register const QRect *r1BandEnd; // End of current band in r1 - register const QRect *r2BandEnd; // End of current band in r2 - int top; // Top of non-overlapping band - int bot; // Bottom of non-overlapping band - - /* - * Initialization: - * set r1, r2, r1End and r2End appropriately, preserve the important - * parts of the destination region until the end in case it's one of - * the two source regions, then mark the "new" region empty, allocating - * another array of rectangles for it to use. - */ - r1 = (reg1->mode==QRegionPrivate::Vector)?reg1->rects.data():®1->single; - r2 = (reg2->mode==QRegionPrivate::Vector)?reg2->rects.data():®2->single; - r1End = r1 + reg1->numRects; - r2End = r2 + reg2->numRects; - - dest.vector(); - QVector<QRect> oldRects = dest.rects; - - dest.numRects = 0; - - /* - * Allocate a reasonable number of rectangles for the new region. The idea - * is to allocate enough so the individual functions don't need to - * reallocate and copy the array, which is time consuming, yet we don't - * have to worry about using too much memory. I hope to be able to - * nuke the realloc() at the end of this function eventually. - */ - dest.rects.resize(qMax(reg1->numRects,reg2->numRects) * 2); - - /* - * Initialize ybot and ytop. - * In the upcoming loop, ybot and ytop serve different functions depending - * on whether the band being handled is an overlapping or non-overlapping - * band. - * In the case of a non-overlapping band (only one of the regions - * has points in the band), ybot is the bottom of the most recent - * intersection and thus clips the top of the rectangles in that band. - * ytop is the top of the next intersection between the two regions and - * serves to clip the bottom of the rectangles in the current band. - * For an overlapping band (where the two regions intersect), ytop clips - * the top of the rectangles of both regions and ybot clips the bottoms. - */ - if (reg1->extents.top() < reg2->extents.top()) - ybot = reg1->extents.top() - 1; - else - ybot = reg2->extents.top() - 1; - - /* - * prevBand serves to mark the start of the previous band so rectangles - * can be coalesced into larger rectangles. qv. miCoalesce, above. - * In the beginning, there is no previous band, so prevBand == curBand - * (curBand is set later on, of course, but the first band will always - * start at index 0). prevBand and curBand must be indices because of - * the possible expansion, and resultant moving, of the new region's - * array of rectangles. - */ - prevBand = 0; - - do { - curBand = dest.numRects; - - /* - * This algorithm proceeds one source-band (as opposed to a - * destination band, which is determined by where the two regions - * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the - * rectangle after the last one in the current band for their - * respective regions. - */ - r1BandEnd = r1; - while (r1BandEnd != r1End && r1BandEnd->top() == r1->top()) - ++r1BandEnd; - - r2BandEnd = r2; - while (r2BandEnd != r2End && r2BandEnd->top() == r2->top()) - ++r2BandEnd; - - /* - * First handle the band that doesn't intersect, if any. - * - * Note that attention is restricted to one band in the - * non-intersecting region at once, so if a region has n - * bands between the current position and the next place it overlaps - * the other, this entire loop will be passed through n times. - */ - if (r1->top() < r2->top()) { - top = qMax(r1->top(), ybot + 1); - bot = qMin(r1->bottom(), r2->top() - 1); - - if (nonOverlap1Func != 0 && bot >= top) - (*nonOverlap1Func)(dest, r1, r1BandEnd, top, bot); - ytop = r2->top(); - } else if (r2->top() < r1->top()) { - top = qMax(r2->top(), ybot + 1); - bot = qMin(r2->bottom(), r1->top() - 1); - - if (nonOverlap2Func != 0 && bot >= top) - (*nonOverlap2Func)(dest, r2, r2BandEnd, top, bot); - ytop = r1->top(); - } else { - ytop = r1->top(); - } - - /* - * If any rectangles got added to the region, try and coalesce them - * with rectangles from the previous band. Note we could just do - * this test in miCoalesce, but some machines incur a not - * inconsiderable cost for function calls, so... - */ - if (dest.numRects != curBand) - prevBand = miCoalesce(dest, prevBand, curBand); - - /* - * Now see if we've hit an intersecting band. The two bands only - * intersect if ybot >= ytop - */ - ybot = qMin(r1->bottom(), r2->bottom()); - curBand = dest.numRects; - if (ybot >= ytop) - (*overlapFunc)(dest, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot); - - if (dest.numRects != curBand) - prevBand = miCoalesce(dest, prevBand, curBand); - - /* - * If we've finished with a band (y2 == ybot) we skip forward - * in the region to the next band. - */ - if (r1->bottom() == ybot) - r1 = r1BandEnd; - if (r2->bottom() == ybot) - r2 = r2BandEnd; - } while (r1 != r1End && r2 != r2End); - - /* - * Deal with whichever region still has rectangles left. - */ - curBand = dest.numRects; - if (r1 != r1End) { - if (nonOverlap1Func != 0) { - do { - r1BandEnd = r1; - while (r1BandEnd < r1End && r1BandEnd->top() == r1->top()) - ++r1BandEnd; - (*nonOverlap1Func)(dest, r1, r1BandEnd, qMax(r1->top(), ybot + 1), r1->bottom()); - r1 = r1BandEnd; - } while (r1 != r1End); - } - } else if ((r2 != r2End) && (nonOverlap2Func != 0)) { - do { - r2BandEnd = r2; - while (r2BandEnd < r2End && r2BandEnd->top() == r2->top()) - ++r2BandEnd; - (*nonOverlap2Func)(dest, r2, r2BandEnd, qMax(r2->top(), ybot + 1), r2->bottom()); - r2 = r2BandEnd; - } while (r2 != r2End); - } - - if (dest.numRects != curBand) - (void)miCoalesce(dest, prevBand, curBand); - - /* - * A bit of cleanup. To keep regions from growing without bound, - * we shrink the array of rectangles to match the new number of - * rectangles in the region. - * - * Only do this stuff if the number of rectangles allocated is more than - * twice the number of rectangles in the region (a simple optimization). - */ - if (qMax(4, dest.numRects) < (dest.rects.size() >> 1)) - dest.rects.resize(dest.numRects); -} - -/*====================================================================== - * Region Union - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miUnionNonO -- - * Handle a non-overlapping band for the union operation. Just - * Adds the rectangles into the region. Doesn't have to check for - * subsumption or anything. - * - * Results: - * None. - * - * Side Effects: - * dest.numRects is incremented and the final rectangles overwritten - * with the rectangles we're passed. - * - *----------------------------------------------------------------------- - */ - -static void miUnionNonO(register QRegionPrivate &dest, register const QRect *r, const QRect *rEnd, - register int y1, register int y2) -{ - register QRect *pNextRect; - - pNextRect = dest.rects.data() + dest.numRects; - - Q_ASSERT(y1 <= y2); - - while (r != rEnd) { - Q_ASSERT(r->left() <= r->right()); - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(r->left(), y1, r->right(), y2); - dest.numRects++; - ++pNextRect; - ++r; - } -} - - -/*- - *----------------------------------------------------------------------- - * miUnionO -- - * Handle an overlapping band for the union operation. Picks the - * left-most rectangle each time and merges it into the region. - * - * Results: - * None. - * - * Side Effects: - * Rectangles are overwritten in dest.rects and dest.numRects will - * be changed. - * - *----------------------------------------------------------------------- - */ - -static void miUnionO(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End, - register const QRect *r2, const QRect *r2End, register int y1, register int y2) -{ - register QRect *pNextRect; - - pNextRect = dest.rects.data() + dest.numRects; - -#define MERGERECT(r) \ - if ((dest.numRects != 0) && \ - (pNextRect[-1].top() == y1) && \ - (pNextRect[-1].bottom() == y2) && \ - (pNextRect[-1].right() >= r->left()-1)) { \ - if (pNextRect[-1].right() < r->right()) { \ - pNextRect[-1].setRight(r->right()); \ - dest.updateInnerRect(pNextRect[-1]); \ - Q_ASSERT(pNextRect[-1].left() <= pNextRect[-1].right()); \ - } \ - } else { \ - MEMCHECK(dest, pNextRect, dest.rects) \ - pNextRect->setCoords(r->left(), y1, r->right(), y2); \ - dest.updateInnerRect(*pNextRect); \ - dest.numRects++; \ - pNextRect++; \ - } \ - r++; - - Q_ASSERT(y1 <= y2); - while (r1 != r1End && r2 != r2End) { - if (r1->left() < r2->left()) { - MERGERECT(r1) - } else { - MERGERECT(r2) - } - } - - if (r1 != r1End) { - do { - MERGERECT(r1) - } while (r1 != r1End); - } else { - while (r2 != r2End) { - MERGERECT(r2) - } - } -} - -static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest) -{ - Q_ASSERT(!isEmptyHelper(reg1) && !isEmptyHelper(reg2)); - Q_ASSERT(!reg1->contains(*reg2)); - Q_ASSERT(!reg2->contains(*reg1)); - Q_ASSERT(!EqualRegion(reg1, reg2)); - Q_ASSERT(!reg1->canAppend(reg2)); - Q_ASSERT(!reg2->canAppend(reg1)); - - if (reg1->innerArea > reg2->innerArea) { - dest.innerArea = reg1->innerArea; - dest.innerRect = reg1->innerRect; - } else { - dest.innerArea = reg2->innerArea; - dest.innerRect = reg2->innerRect; - } - miRegionOp(dest, reg1, reg2, miUnionO, miUnionNonO, miUnionNonO); - - dest.extents.setCoords(qMin(reg1->extents.left(), reg2->extents.left()), - qMin(reg1->extents.top(), reg2->extents.top()), - qMax(reg1->extents.right(), reg2->extents.right()), - qMax(reg1->extents.bottom(), reg2->extents.bottom())); -} - -/*====================================================================== - * Region Subtraction - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miSubtractNonO -- - * Deal with non-overlapping band for subtraction. Any parts from - * region 2 we discard. Anything from region 1 we add to the region. - * - * Results: - * None. - * - * Side Effects: - * dest may be affected. - * - *----------------------------------------------------------------------- - */ - -static void miSubtractNonO1(register QRegionPrivate &dest, register const QRect *r, - const QRect *rEnd, register int y1, register int y2) -{ - register QRect *pNextRect; - - pNextRect = dest.rects.data() + dest.numRects; - - Q_ASSERT(y1<=y2); - - while (r != rEnd) { - Q_ASSERT(r->left() <= r->right()); - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(r->left(), y1, r->right(), y2); - ++dest.numRects; - ++pNextRect; - ++r; - } -} - -/*- - *----------------------------------------------------------------------- - * miSubtractO -- - * Overlapping band subtraction. x1 is the left-most point not yet - * checked. - * - * Results: - * None. - * - * Side Effects: - * dest may have rectangles added to it. - * - *----------------------------------------------------------------------- - */ - -static void miSubtractO(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End, - register const QRect *r2, const QRect *r2End, register int y1, register int y2) -{ - register QRect *pNextRect; - register int x1; - - x1 = r1->left(); - - Q_ASSERT(y1 <= y2); - pNextRect = dest.rects.data() + dest.numRects; - - while (r1 != r1End && r2 != r2End) { - if (r2->right() < x1) { - /* - * Subtrahend missed the boat: go to next subtrahend. - */ - ++r2; - } else if (r2->left() <= x1) { - /* - * Subtrahend precedes minuend: nuke left edge of minuend. - */ - x1 = r2->right() + 1; - if (x1 > r1->right()) { - /* - * Minuend completely covered: advance to next minuend and - * reset left fence to edge of new minuend. - */ - ++r1; - if (r1 != r1End) - x1 = r1->left(); - } else { - // Subtrahend now used up since it doesn't extend beyond minuend - ++r2; - } - } else if (r2->left() <= r1->right()) { - /* - * Left part of subtrahend covers part of minuend: add uncovered - * part of minuend to region and skip to next subtrahend. - */ - Q_ASSERT(x1 < r2->left()); - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(x1, y1, r2->left() - 1, y2); - ++dest.numRects; - ++pNextRect; - - x1 = r2->right() + 1; - if (x1 > r1->right()) { - /* - * Minuend used up: advance to new... - */ - ++r1; - if (r1 != r1End) - x1 = r1->left(); - } else { - // Subtrahend used up - ++r2; - } - } else { - /* - * Minuend used up: add any remaining piece before advancing. - */ - if (r1->right() >= x1) { - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(x1, y1, r1->right(), y2); - ++dest.numRects; - ++pNextRect; - } - ++r1; - if (r1 != r1End) - x1 = r1->left(); - } - } - - /* - * Add remaining minuend rectangles to region. - */ - while (r1 != r1End) { - Q_ASSERT(x1 <= r1->right()); - MEMCHECK(dest, pNextRect, dest.rects) - pNextRect->setCoords(x1, y1, r1->right(), y2); - ++dest.numRects; - ++pNextRect; - - ++r1; - if (r1 != r1End) - x1 = r1->left(); - } -} - -/*- - *----------------------------------------------------------------------- - * miSubtract -- - * Subtract regS from regM and leave the result in regD. - * S stands for subtrahend, M for minuend and D for difference. - * - * Side Effects: - * regD is overwritten. - * - *----------------------------------------------------------------------- - */ - -static void SubtractRegion(QRegionPrivate *regM, QRegionPrivate *regS, - register QRegionPrivate &dest) -{ - Q_ASSERT(!isEmptyHelper(regM)); - Q_ASSERT(!isEmptyHelper(regS)); - Q_ASSERT(EXTENTCHECK(®M->extents, ®S->extents)); - Q_ASSERT(!regS->contains(*regM)); - Q_ASSERT(!EqualRegion(regM, regS)); - - miRegionOp(dest, regM, regS, miSubtractO, miSubtractNonO1, 0); - - /* - * Can't alter dest's extents before we call miRegionOp because - * it might be one of the source regions and miRegionOp depends - * on the extents of those regions being the unaltered. Besides, this - * way there's no checking against rectangles that will be nuked - * due to coalescing, so we have to examine fewer rectangles. - */ - miSetExtents(dest); -} - -static void XorRegion(QRegionPrivate *sra, QRegionPrivate *srb, QRegionPrivate &dest) -{ - Q_ASSERT(!isEmptyHelper(sra) && !isEmptyHelper(srb)); - Q_ASSERT(EXTENTCHECK(&sra->extents, &srb->extents)); - Q_ASSERT(!EqualRegion(sra, srb)); - - QRegionPrivate tra, trb; - - if (!srb->contains(*sra)) - SubtractRegion(sra, srb, tra); - if (!sra->contains(*srb)) - SubtractRegion(srb, sra, trb); - - Q_ASSERT(isEmptyHelper(&trb) || !tra.contains(trb)); - Q_ASSERT(isEmptyHelper(&tra) || !trb.contains(tra)); - - if (isEmptyHelper(&tra)) { - dest = trb; - } else if (isEmptyHelper(&trb)) { - dest = tra; - } else if (tra.canAppend(&trb)) { - dest = tra; - dest.append(&trb); - } else if (trb.canAppend(&tra)) { - dest = trb; - dest.append(&tra); - } else { - UnionRegion(&tra, &trb, dest); - } -} - -/* - * Check to see if two regions are equal - */ -static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2) -{ - if (r1->numRects != r2->numRects) { - return false; - } else if (r1->numRects == 0) { - return true; - } else if (r1->extents != r2->extents) { - return false; - } else if (r1->mode == QRegionPrivate::Single && r2->mode == QRegionPrivate::Single) { - return r1->single == r2->single; - } else { - const QRect *rr1 = (r1->mode==QRegionPrivate::Vector)?r1->rects.constData():&r1->single; - const QRect *rr2 = (r2->mode==QRegionPrivate::Vector)?r2->rects.constData():&r2->single; - for (int i = 0; i < r1->numRects; ++i, ++rr1, ++rr2) { - if (*rr1 != *rr2) - return false; - } - } - - return true; -} - -static bool PointInRegion(QRegionPrivate *pRegion, int x, int y) -{ - int i; - - if (pRegion->mode == QRegionPrivate::Single) - return pRegion->single.contains(x, y); - if (isEmptyHelper(pRegion)) - return false; - if (!pRegion->extents.contains(x, y)) - return false; - if (pRegion->innerRect.contains(x, y)) - return true; - for (i = 0; i < pRegion->numRects; ++i) { - if (pRegion->rects[i].contains(x, y)) - return true; - } - return false; -} - -static bool RectInRegion(register QRegionPrivate *region, int rx, int ry, uint rwidth, uint rheight) -{ - register const QRect *pbox; - register const QRect *pboxEnd; - QRect rect(rx, ry, rwidth, rheight); - register QRect *prect = ▭ - int partIn, partOut; - - if (!region || region->numRects == 0 || !EXTENTCHECK(®ion->extents, prect)) - return RectangleOut; - - partOut = false; - partIn = false; - - /* can stop when both partOut and partIn are true, or we reach prect->y2 */ - for (pbox = (region->mode==QRegionPrivate::Vector)?region->rects.constData():®ion->single, pboxEnd = pbox + region->numRects; - pbox < pboxEnd; ++pbox) { - if (pbox->bottom() < ry) - continue; - - if (pbox->top() > ry) { - partOut = true; - if (partIn || pbox->top() > prect->bottom()) - break; - ry = pbox->top(); - } - - if (pbox->right() < rx) - continue; /* not far enough over yet */ - - if (pbox->left() > rx) { - partOut = true; /* missed part of rectangle to left */ - if (partIn) - break; - } - - if (pbox->left() <= prect->right()) { - partIn = true; /* definitely overlap */ - if (partOut) - break; - } - - if (pbox->right() >= prect->right()) { - ry = pbox->bottom() + 1; /* finished with this band */ - if (ry > prect->bottom()) - break; - rx = prect->left(); /* reset x out to left again */ - } else { - /* - * Because boxes in a band are maximal width, if the first box - * to overlap the rectangle doesn't completely cover it in that - * band, the rectangle must be partially out, since some of it - * will be uncovered in that band. partIn will have been set true - * by now... - */ - break; - } - } - return partIn ? ((ry <= prect->bottom()) ? RectanglePart : RectangleIn) : RectangleOut; -} -// END OF Region.c extract -// START OF poly.h extract -/* $XConsortium: poly.h,v 1.4 94/04/17 20:22:19 rws Exp $ */ -/************************************************************************ - -Copyright (c) 1987 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* - * This file contains a few macros to help track - * the edge of a filled object. The object is assumed - * to be filled in scanline order, and thus the - * algorithm used is an extension of Bresenham's line - * drawing algorithm which assumes that y is always the - * major axis. - * Since these pieces of code are the same for any filled shape, - * it is more convenient to gather the library in one - * place, but since these pieces of code are also in - * the inner loops of output primitives, procedure call - * overhead is out of the question. - * See the author for a derivation if needed. - */ - - -/* - * In scan converting polygons, we want to choose those pixels - * which are inside the polygon. Thus, we add .5 to the starting - * x coordinate for both left and right edges. Now we choose the - * first pixel which is inside the pgon for the left edge and the - * first pixel which is outside the pgon for the right edge. - * Draw the left pixel, but not the right. - * - * How to add .5 to the starting x coordinate: - * If the edge is moving to the right, then subtract dy from the - * error term from the general form of the algorithm. - * If the edge is moving to the left, then add dy to the error term. - * - * The reason for the difference between edges moving to the left - * and edges moving to the right is simple: If an edge is moving - * to the right, then we want the algorithm to flip immediately. - * If it is moving to the left, then we don't want it to flip until - * we traverse an entire pixel. - */ -#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \ - int dx; /* local storage */ \ -\ - /* \ - * if the edge is horizontal, then it is ignored \ - * and assumed not to be processed. Otherwise, do this stuff. \ - */ \ - if ((dy) != 0) { \ - xStart = (x1); \ - dx = (x2) - xStart; \ - if (dx < 0) { \ - m = dx / (dy); \ - m1 = m - 1; \ - incr1 = -2 * dx + 2 * (dy) * m1; \ - incr2 = -2 * dx + 2 * (dy) * m; \ - d = 2 * m * (dy) - 2 * dx - 2 * (dy); \ - } else { \ - m = dx / (dy); \ - m1 = m + 1; \ - incr1 = 2 * dx - 2 * (dy) * m1; \ - incr2 = 2 * dx - 2 * (dy) * m; \ - d = -2 * m * (dy) + 2 * dx; \ - } \ - } \ -} - -#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \ - if (m1 > 0) { \ - if (d > 0) { \ - minval += m1; \ - d += incr1; \ - } \ - else { \ - minval += m; \ - d += incr2; \ - } \ - } else {\ - if (d >= 0) { \ - minval += m1; \ - d += incr1; \ - } \ - else { \ - minval += m; \ - d += incr2; \ - } \ - } \ -} - - -/* - * This structure contains all of the information needed - * to run the bresenham algorithm. - * The variables may be hardcoded into the declarations - * instead of using this structure to make use of - * register declarations. - */ -typedef struct { - int minor_axis; /* minor axis */ - int d; /* decision variable */ - int m, m1; /* slope and slope+1 */ - int incr1, incr2; /* error increments */ -} BRESINFO; - - -#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \ - BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \ - bres.m, bres.m1, bres.incr1, bres.incr2) - -#define BRESINCRPGONSTRUCT(bres) \ - BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2) - - - -/* - * These are the data structures needed to scan - * convert regions. Two different scan conversion - * methods are available -- the even-odd method, and - * the winding number method. - * The even-odd rule states that a point is inside - * the polygon if a ray drawn from that point in any - * direction will pass through an odd number of - * path segments. - * By the winding number rule, a point is decided - * to be inside the polygon if a ray drawn from that - * point in any direction passes through a different - * number of clockwise and counter-clockwise path - * segments. - * - * These data structures are adapted somewhat from - * the algorithm in (Foley/Van Dam) for scan converting - * polygons. - * The basic algorithm is to start at the top (smallest y) - * of the polygon, stepping down to the bottom of - * the polygon by incrementing the y coordinate. We - * keep a list of edges which the current scanline crosses, - * sorted by x. This list is called the Active Edge Table (AET) - * As we change the y-coordinate, we update each entry in - * in the active edge table to reflect the edges new xcoord. - * This list must be sorted at each scanline in case - * two edges intersect. - * We also keep a data structure known as the Edge Table (ET), - * which keeps track of all the edges which the current - * scanline has not yet reached. The ET is basically a - * list of ScanLineList structures containing a list of - * edges which are entered at a given scanline. There is one - * ScanLineList per scanline at which an edge is entered. - * When we enter a new edge, we move it from the ET to the AET. - * - * From the AET, we can implement the even-odd rule as in - * (Foley/Van Dam). - * The winding number rule is a little trickier. We also - * keep the EdgeTableEntries in the AET linked by the - * nextWETE (winding EdgeTableEntry) link. This allows - * the edges to be linked just as before for updating - * purposes, but only uses the edges linked by the nextWETE - * link as edges representing spans of the polygon to - * drawn (as with the even-odd rule). - */ - -/* - * for the winding number rule - */ -#define CLOCKWISE 1 -#define COUNTERCLOCKWISE -1 - -typedef struct _EdgeTableEntry { - int ymax; /* ycoord at which we exit this edge. */ - BRESINFO bres; /* Bresenham info to run the edge */ - struct _EdgeTableEntry *next; /* next in the list */ - struct _EdgeTableEntry *back; /* for insertion sort */ - struct _EdgeTableEntry *nextWETE; /* for winding num rule */ - int ClockWise; /* flag for winding number rule */ -} EdgeTableEntry; - - -typedef struct _ScanLineList{ - int scanline; /* the scanline represented */ - EdgeTableEntry *edgelist; /* header node */ - struct _ScanLineList *next; /* next in the list */ -} ScanLineList; - - -typedef struct { - int ymax; /* ymax for the polygon */ - int ymin; /* ymin for the polygon */ - ScanLineList scanlines; /* header node */ -} EdgeTable; - - -/* - * Here is a struct to help with storage allocation - * so we can allocate a big chunk at a time, and then take - * pieces from this heap when we need to. - */ -#define SLLSPERBLOCK 25 - -typedef struct _ScanLineListBlock { - ScanLineList SLLs[SLLSPERBLOCK]; - struct _ScanLineListBlock *next; -} ScanLineListBlock; - - - -/* - * - * a few macros for the inner loops of the fill code where - * performance considerations don't allow a procedure call. - * - * Evaluate the given edge at the given scanline. - * If the edge has expired, then we leave it and fix up - * the active edge table; otherwise, we increment the - * x value to be ready for the next scanline. - * The winding number rule is in effect, so we must notify - * the caller when the edge has been removed so he - * can reorder the Winding Active Edge Table. - */ -#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \ - if (pAET->ymax == y) { /* leaving this edge */ \ - pPrevAET->next = pAET->next; \ - pAET = pPrevAET->next; \ - fixWAET = 1; \ - if (pAET) \ - pAET->back = pPrevAET; \ - } \ - else { \ - BRESINCRPGONSTRUCT(pAET->bres) \ - pPrevAET = pAET; \ - pAET = pAET->next; \ - } \ -} - - -/* - * Evaluate the given edge at the given scanline. - * If the edge has expired, then we leave it and fix up - * the active edge table; otherwise, we increment the - * x value to be ready for the next scanline. - * The even-odd rule is in effect. - */ -#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \ - if (pAET->ymax == y) { /* leaving this edge */ \ - pPrevAET->next = pAET->next; \ - pAET = pPrevAET->next; \ - if (pAET) \ - pAET->back = pPrevAET; \ - } \ - else { \ - BRESINCRPGONSTRUCT(pAET->bres) \ - pPrevAET = pAET; \ - pAET = pAET->next; \ - } \ -} -// END OF poly.h extract -// START OF PolyReg.c extract -/* $XConsortium: PolyReg.c,v 11.23 94/11/17 21:59:37 converse Exp $ */ -/************************************************************************ - -Copyright (c) 1987 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* $XFree86: xc/lib/X11/PolyReg.c,v 1.1.1.2.8.2 1998/10/04 15:22:49 hohndel Exp $ */ - -#define LARGE_COORDINATE 1000000 -#define SMALL_COORDINATE -LARGE_COORDINATE - -/* - * InsertEdgeInET - * - * Insert the given edge into the edge table. - * First we must find the correct bucket in the - * Edge table, then find the right slot in the - * bucket. Finally, we can insert it. - * - */ -static void InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline, - ScanLineListBlock **SLLBlock, int *iSLLBlock) -{ - register EdgeTableEntry *start, *prev; - register ScanLineList *pSLL, *pPrevSLL; - ScanLineListBlock *tmpSLLBlock; - - /* - * find the right bucket to put the edge into - */ - pPrevSLL = &ET->scanlines; - pSLL = pPrevSLL->next; - while (pSLL && (pSLL->scanline < scanline)) { - pPrevSLL = pSLL; - pSLL = pSLL->next; - } - - /* - * reassign pSLL (pointer to ScanLineList) if necessary - */ - if ((!pSLL) || (pSLL->scanline > scanline)) { - if (*iSLLBlock > SLLSPERBLOCK-1) - { - tmpSLLBlock = - (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock)); - (*SLLBlock)->next = tmpSLLBlock; - tmpSLLBlock->next = (ScanLineListBlock *)NULL; - *SLLBlock = tmpSLLBlock; - *iSLLBlock = 0; - } - pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]); - - pSLL->next = pPrevSLL->next; - pSLL->edgelist = (EdgeTableEntry *)NULL; - pPrevSLL->next = pSLL; - } - pSLL->scanline = scanline; - - /* - * now insert the edge in the right bucket - */ - prev = 0; - start = pSLL->edgelist; - while (start && (start->bres.minor_axis < ETE->bres.minor_axis)) { - prev = start; - start = start->next; - } - ETE->next = start; - - if (prev) - prev->next = ETE; - else - pSLL->edgelist = ETE; -} - -/* - * CreateEdgeTable - * - * This routine creates the edge table for - * scan converting polygons. - * The Edge Table (ET) looks like: - * - * EdgeTable - * -------- - * | ymax | ScanLineLists - * |scanline|-->------------>-------------->... - * -------- |scanline| |scanline| - * |edgelist| |edgelist| - * --------- --------- - * | | - * | | - * V V - * list of ETEs list of ETEs - * - * where ETE is an EdgeTableEntry data structure, - * and there is one ScanLineList per scanline at - * which an edge is initially entered. - * - */ - -static void CreateETandAET(register int count, register const QPoint *pts, - EdgeTable *ET, EdgeTableEntry *AET, register EdgeTableEntry *pETEs, - ScanLineListBlock *pSLLBlock) -{ - register const QPoint *top, - *bottom, - *PrevPt, - *CurrPt; - int iSLLBlock = 0; - int dy; - - if (count < 2) - return; - - /* - * initialize the Active Edge Table - */ - AET->next = 0; - AET->back = 0; - AET->nextWETE = 0; - AET->bres.minor_axis = SMALL_COORDINATE; - - /* - * initialize the Edge Table. - */ - ET->scanlines.next = 0; - ET->ymax = SMALL_COORDINATE; - ET->ymin = LARGE_COORDINATE; - pSLLBlock->next = 0; - - PrevPt = &pts[count - 1]; - - /* - * for each vertex in the array of points. - * In this loop we are dealing with two vertices at - * a time -- these make up one edge of the polygon. - */ - while (count--) { - CurrPt = pts++; - - /* - * find out which point is above and which is below. - */ - if (PrevPt->y() > CurrPt->y()) { - bottom = PrevPt; - top = CurrPt; - pETEs->ClockWise = 0; - } else { - bottom = CurrPt; - top = PrevPt; - pETEs->ClockWise = 1; - } - - /* - * don't add horizontal edges to the Edge table. - */ - if (bottom->y() != top->y()) { - pETEs->ymax = bottom->y() - 1; /* -1 so we don't get last scanline */ - - /* - * initialize integer edge algorithm - */ - dy = bottom->y() - top->y(); - BRESINITPGONSTRUCT(dy, top->x(), bottom->x(), pETEs->bres) - - InsertEdgeInET(ET, pETEs, top->y(), &pSLLBlock, &iSLLBlock); - - if (PrevPt->y() > ET->ymax) - ET->ymax = PrevPt->y(); - if (PrevPt->y() < ET->ymin) - ET->ymin = PrevPt->y(); - ++pETEs; - } - - PrevPt = CurrPt; - } -} - -/* - * loadAET - * - * This routine moves EdgeTableEntries from the - * EdgeTable into the Active Edge Table, - * leaving them sorted by smaller x coordinate. - * - */ - -static void loadAET(register EdgeTableEntry *AET, register EdgeTableEntry *ETEs) -{ - register EdgeTableEntry *pPrevAET; - register EdgeTableEntry *tmp; - - pPrevAET = AET; - AET = AET->next; - while (ETEs) { - while (AET && AET->bres.minor_axis < ETEs->bres.minor_axis) { - pPrevAET = AET; - AET = AET->next; - } - tmp = ETEs->next; - ETEs->next = AET; - if (AET) - AET->back = ETEs; - ETEs->back = pPrevAET; - pPrevAET->next = ETEs; - pPrevAET = ETEs; - - ETEs = tmp; - } -} - -/* - * computeWAET - * - * This routine links the AET by the - * nextWETE (winding EdgeTableEntry) link for - * use by the winding number rule. The final - * Active Edge Table (AET) might look something - * like: - * - * AET - * ---------- --------- --------- - * |ymax | |ymax | |ymax | - * | ... | |... | |... | - * |next |->|next |->|next |->... - * |nextWETE| |nextWETE| |nextWETE| - * --------- --------- ^-------- - * | | | - * V-------------------> V---> ... - * - */ -static void computeWAET(register EdgeTableEntry *AET) -{ - register EdgeTableEntry *pWETE; - register int inside = 1; - register int isInside = 0; - - AET->nextWETE = 0; - pWETE = AET; - AET = AET->next; - while (AET) { - if (AET->ClockWise) - ++isInside; - else - --isInside; - - if (!inside && !isInside || inside && isInside) { - pWETE->nextWETE = AET; - pWETE = AET; - inside = !inside; - } - AET = AET->next; - } - pWETE->nextWETE = 0; -} - -/* - * InsertionSort - * - * Just a simple insertion sort using - * pointers and back pointers to sort the Active - * Edge Table. - * - */ - -static int InsertionSort(register EdgeTableEntry *AET) -{ - register EdgeTableEntry *pETEchase; - register EdgeTableEntry *pETEinsert; - register EdgeTableEntry *pETEchaseBackTMP; - register int changed = 0; - - AET = AET->next; - while (AET) { - pETEinsert = AET; - pETEchase = AET; - while (pETEchase->back->bres.minor_axis > AET->bres.minor_axis) - pETEchase = pETEchase->back; - - AET = AET->next; - if (pETEchase != pETEinsert) { - pETEchaseBackTMP = pETEchase->back; - pETEinsert->back->next = AET; - if (AET) - AET->back = pETEinsert->back; - pETEinsert->next = pETEchase; - pETEchase->back->next = pETEinsert; - pETEchase->back = pETEinsert; - pETEinsert->back = pETEchaseBackTMP; - changed = 1; - } - } - return changed; -} - -/* - * Clean up our act. - */ -static void FreeStorage(register ScanLineListBlock *pSLLBlock) -{ - register ScanLineListBlock *tmpSLLBlock; - - while (pSLLBlock) { - tmpSLLBlock = pSLLBlock->next; - free(pSLLBlock); - pSLLBlock = tmpSLLBlock; - } -} - -/* - * Create an array of rectangles from a list of points. - * If indeed these things (POINTS, RECTS) are the same, - * then this proc is still needed, because it allocates - * storage for the array, which was allocated on the - * stack by the calling procedure. - * - */ -static void PtsToRegion(register int numFullPtBlocks, register int iCurPtBlock, - POINTBLOCK *FirstPtBlock, QRegionPrivate *reg) -{ - register QRect *rects; - register QPoint *pts; - register POINTBLOCK *CurPtBlock; - register int i; - register QRect *extents; - register int numRects; - - extents = ®->extents; - numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1; - - reg->rects.resize(numRects); - - CurPtBlock = FirstPtBlock; - rects = reg->rects.data() - 1; - numRects = 0; - extents->setLeft(INT_MAX); - extents->setRight(INT_MIN); - reg->innerArea = -1; - - for (; numFullPtBlocks >= 0; --numFullPtBlocks) { - /* the loop uses 2 points per iteration */ - i = NUMPTSTOBUFFER >> 1; - if (!numFullPtBlocks) - i = iCurPtBlock >> 1; - if(i) { - for (pts = CurPtBlock->pts; i--; pts += 2) { - if (pts->x() == pts[1].x()) - continue; - if (numRects && pts->x() == rects->left() && pts->y() == rects->bottom() + 1 - && pts[1].x() == rects->right()+1 && (numRects == 1 || rects[-1].top() != rects->top()) - && (i && pts[2].y() > pts[1].y())) { - rects->setBottom(pts[1].y()); - reg->updateInnerRect(*rects); - continue; - } - ++numRects; - ++rects; - rects->setCoords(pts->x(), pts->y(), pts[1].x() - 1, pts[1].y()); - if (rects->left() < extents->left()) - extents->setLeft(rects->left()); - if (rects->right() > extents->right()) - extents->setRight(rects->right()); - reg->updateInnerRect(*rects); - } - } - CurPtBlock = CurPtBlock->next; - } - - if (numRects) { - extents->setTop(reg->rects[0].top()); - extents->setBottom(rects->bottom()); - } else { - extents->setCoords(0, 0, 0, 0); - } - reg->numRects = numRects; -} - -/* - * polytoregion - * - * Scan converts a polygon by returning a run-length - * encoding of the resultant bitmap -- the run-length - * encoding is in the form of an array of rectangles. - */ -static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule, - QRegionPrivate *region) - //Point *Pts; /* the pts */ - //int Count; /* number of pts */ - //int rule; /* winding rule */ -{ - register EdgeTableEntry *pAET; /* Active Edge Table */ - register int y; /* current scanline */ - register int iPts = 0; /* number of pts in buffer */ - register EdgeTableEntry *pWETE; /* Winding Edge Table Entry*/ - register ScanLineList *pSLL; /* current scanLineList */ - register QPoint *pts; /* output buffer */ - EdgeTableEntry *pPrevAET; /* ptr to previous AET */ - EdgeTable ET; /* header node for ET */ - EdgeTableEntry AET; /* header node for AET */ - EdgeTableEntry *pETEs; /* EdgeTableEntries pool */ - ScanLineListBlock SLLBlock; /* header for scanlinelist */ - int fixWAET = false; - POINTBLOCK FirstPtBlock, *curPtBlock; /* PtBlock buffers */ - POINTBLOCK *tmpPtBlock; - int numFullPtBlocks = 0; - - region->vector(); - - /* special case a rectangle */ - if (((Count == 4) || - ((Count == 5) && (Pts[4].x() == Pts[0].x()) && (Pts[4].y() == Pts[0].y()))) - && (((Pts[0].y() == Pts[1].y()) && (Pts[1].x() == Pts[2].x()) && (Pts[2].y() == Pts[3].y()) - && (Pts[3].x() == Pts[0].x())) || ((Pts[0].x() == Pts[1].x()) - && (Pts[1].y() == Pts[2].y()) && (Pts[2].x() == Pts[3].x()) - && (Pts[3].y() == Pts[0].y())))) { - int x = qMin(Pts[0].x(), Pts[2].x()); - region->extents.setLeft(x); - int y = qMin(Pts[0].y(), Pts[2].y()); - region->extents.setTop(y); - region->extents.setWidth(qMax(Pts[0].x(), Pts[2].x()) - x); - region->extents.setHeight(qMax(Pts[0].y(), Pts[2].y()) - y); - if ((region->extents.left() <= region->extents.right()) && - (region->extents.top() <= region->extents.bottom())) { - region->numRects = 1; - region->rects.resize(1); - region->rects[0] = region->extents; - region->innerRect = region->extents; - region->innerArea = region->innerRect.width() * region->innerRect.height(); - } - return region; - } - - if (!(pETEs = static_cast<EdgeTableEntry *>(malloc(sizeof(EdgeTableEntry) * Count)))) - return 0; - - pts = FirstPtBlock.pts; - CreateETandAET(Count, Pts, &ET, &AET, pETEs, &SLLBlock); - pSLL = ET.scanlines.next; - curPtBlock = &FirstPtBlock; - - if (rule == EvenOddRule) { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - - /* - * for each active edge - */ - while (pAET) { - pts->setX(pAET->bres.minor_axis); - pts->setY(y); - ++pts; - ++iPts; - - /* - * send out the buffer - */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK)); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - ++numFullPtBlocks; - iPts = 0; - } - EVALUATEEDGEEVENODD(pAET, pPrevAET, y) - } - InsertionSort(&AET); - } - } else { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - computeWAET(&AET); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - pWETE = pAET; - - /* - * for each active edge - */ - while (pAET) { - /* - * add to the buffer only those edges that - * are in the Winding active edge table. - */ - if (pWETE == pAET) { - pts->setX(pAET->bres.minor_axis); - pts->setY(y); - ++pts; - ++iPts; - - /* - * send out the buffer - */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = static_cast<POINTBLOCK *>(malloc(sizeof(POINTBLOCK))); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - ++numFullPtBlocks; - iPts = 0; - } - pWETE = pWETE->nextWETE; - } - EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) - } - - /* - * recompute the winding active edge table if - * we just resorted or have exited an edge. - */ - if (InsertionSort(&AET) || fixWAET) { - computeWAET(&AET); - fixWAET = false; - } - } - } - FreeStorage(SLLBlock.next); - PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); - for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { - tmpPtBlock = curPtBlock->next; - free(curPtBlock); - curPtBlock = tmpPtBlock; - } - free(pETEs); - return region; -} -// END OF PolyReg.c extract - -QRegionPrivate *qt_bitmapToRegion(const QBitmap& bitmap, QRegionPrivate *region) -{ - region->vector(); - - QImage image = bitmap.toImage(); - - QRect xr; - -#define AddSpan \ - { \ - xr.setCoords(prev1, y, x-1, y); \ - UnionRectWithRegion(&xr, region, *region); \ - } - - const uchar zero = 0; - bool little = image.format() == QImage::Format_MonoLSB; - - int x, - y; - for (y = 0; y < image.height(); ++y) { - uchar *line = image.scanLine(y); - int w = image.width(); - uchar all = zero; - int prev1 = -1; - for (x = 0; x < w;) { - uchar byte = line[x / 8]; - if (x > w - 8 || byte!=all) { - if (little) { - for (int b = 8; b > 0 && x < w; --b) { - if (!(byte & 0x01) == !all) { - // More of the same - } else { - // A change. - if (all!=zero) { - AddSpan - all = zero; - } else { - prev1 = x; - all = ~zero; - } - } - byte >>= 1; - ++x; - } - } else { - for (int b = 8; b > 0 && x < w; --b) { - if (!(byte & 0x80) == !all) { - // More of the same - } else { - // A change. - if (all != zero) { - AddSpan - all = zero; - } else { - prev1 = x; - all = ~zero; - } - } - byte <<= 1; - ++x; - } - } - } else { - x += 8; - } - } - if (all != zero) { - AddSpan - } - } -#undef AddSpan - - return region; -} - -/* - Constructs an empty region. - - \sa isEmpty() -*/ - -QRegion::QRegion() - : d(&shared_empty) -{ - d->ref.ref(); -} - -/* - \overload - - Create a region based on the rectange \a r with region type \a t. - - If the rectangle is invalid a null region will be created. - - \sa QRegion::RegionType -*/ - -QRegion::QRegion(const QRect &r, RegionType t) -{ - if (r.isEmpty()) { - d = &shared_empty; - d->ref.ref(); - } else { -// d = new QRegionData; - QRegionPrivate *rp = 0; - if (t == Rectangle) { -// rp = new QRegionPrivate(r); - rp = qt_allocRegion(r); - } else if (t == Ellipse) { - QPainterPath path; - path.addEllipse(r.x(), r.y(), r.width(), r.height()); - QPolygon a = path.toSubpathPolygons().at(0).toPolygon(); - rp = qt_allocRegion(); -// rp = new QRegionPrivate; - PolygonRegion(a.constData(), a.size(), EvenOddRule, rp); - } - d = rp; - d->ref = 1; -#if defined(Q_WS_X11) - d->rgn = 0; - d->xrectangles = 0; -#elif defined(Q_WS_MAC) - d->rgn = 0; -#endif - d->qt_rgn = rp; - } -} - -/* - Constructs a polygon region from the point array \a a with the fill rule - specified by \a fillRule. - - If \a fillRule is \l{Qt::WindingFill}, the polygon region is defined - using the winding algorithm; if it is \l{Qt::OddEvenFill}, the odd-even fill - algorithm is used. - - \warning This constructor can be used to create complex regions that will - slow down painting when used. -*/ - -QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule) -{ - if (a.count() > 2) { - //d = new QRegionData; - // QRegionPrivate *rp = new QRegionPrivate; - QRegionPrivate *rp = qt_allocRegion(); - PolygonRegion(a.constData(), a.size(), - fillRule == Qt::WindingFill ? WindingRule : EvenOddRule, rp); - d = rp; - d->ref = 1; -#if defined(Q_WS_X11) - d->rgn = 0; - d->xrectangles = 0; -#elif defined(Q_WS_MAC) - d->rgn = 0; -#endif - d->qt_rgn = rp; - } else { - d = &shared_empty; - d->ref.ref(); - } -} - - -/* - Constructs a new region which is equal to region \a r. -*/ - -QRegion::QRegion(const QRegion &r) -{ - d = r.d; - d->ref.ref(); -} - - -/* - Constructs a region from the bitmap \a bm. - - The resulting region consists of the pixels in bitmap \a bm that - are Qt::color1, as if each pixel was a 1 by 1 rectangle. - - This constructor may create complex regions that will slow down - painting when used. Note that drawing masked pixmaps can be done - much faster using QPixmap::setMask(). -*/ -QRegion::QRegion(const QBitmap &bm) -{ - if (bm.isNull()) { - d = &shared_empty; - d->ref.ref(); - } else { - // d = new QRegionData; -// QRegionPrivate *rp = new QRegionPrivate; - QRegionPrivate *rp = qt_allocRegion(); - - qt_bitmapToRegion(bm, rp); - d = rp; - d->ref = 1; -#if defined(Q_WS_X11) - d->rgn = 0; - d->xrectangles = 0; -#elif defined(Q_WS_MAC) - d->rgn = 0; -#endif - d->qt_rgn = rp; - } -} - -void QRegion::cleanUp(QRegion::QRegionData *x) -{ - // delete x->qt_rgn; -#if defined(Q_WS_X11) - if (x->rgn) - XDestroyRegion(x->rgn); - if (x->xrectangles) - free(x->xrectangles); -#elif defined(Q_WS_MAC) - if (x->rgn) - qt_mac_dispose_rgn(x->rgn); -#endif - if(x->qt_rgn) { -// delete x->qt_rgn; - qt_freeRegion(x->qt_rgn); - } else { - delete x; - } -} - -/* - Destroys the region. -*/ - -QRegion::~QRegion() -{ - if (!d->ref.deref()) - cleanUp(d); -} - - -/* - Assigns \a r to this region and returns a reference to the region. -*/ - -QRegion &QRegion::operator=(const QRegion &r) -{ - r.d->ref.ref(); - if (!d->ref.deref()) - cleanUp(d); - d = r.d; - return *this; -} - - -/* - \internal -*/ - -QRegion QRegion::copy() const -{ - QRegion r; - QRegionData *x = 0; // new QRegionData; - QRegionPrivate *rp = 0; - if (d->qt_rgn) -// rp = new QRegionPrivate(*d->qt_rgn); - rp = qt_allocRegion(*d->qt_rgn); - else - rp = qt_allocRegion(); - x = rp; - x->qt_rgn = rp; - x->ref = 1; -#if defined(Q_WS_X11) - x->rgn = 0; - x->xrectangles = 0; -#elif defined(Q_WS_MAC) - x->rgn = 0; -#endif - - if (!r.d->ref.deref()) - cleanUp(r.d); - r.d = x; - return r; -} - -/* - Returns true if the region is empty; otherwise returns false. An - empty region is a region that contains no points. - - Example: - \snippet doc/src/snippets/code/src.gui.painting.qregion_qws.cpp 0 -*/ - -bool QRegion::isEmpty() const -{ - return d == &shared_empty || d->qt_rgn->numRects == 0; -} - - -/* - Returns true if the region contains the point \a p; otherwise - returns false. -*/ - -bool QRegion::contains(const QPoint &p) const -{ - return PointInRegion(d->qt_rgn, p.x(), p.y()); -} - -/* - \overload - - Returns true if the region overlaps the rectangle \a r; otherwise - returns false. -*/ - -bool QRegion::contains(const QRect &r) const -{ - if(!d->qt_rgn) - return false; - if(d->qt_rgn->mode == QRegionPrivate::Single) - return d->qt_rgn->single.contains(r); - - return RectInRegion(d->qt_rgn, r.left(), r.top(), r.width(), r.height()) != RectangleOut; -} - - - -/* - Translates (moves) the region \a dx along the X axis and \a dy - along the Y axis. -*/ - -void QRegion::translate(int dx, int dy) -{ - if ((dx == 0 && dy == 0) || isEmptyHelper(d->qt_rgn)) - return; - - detach(); - OffsetRegion(*d->qt_rgn, dx, dy); -#if defined(Q_WS_X11) - if (d->xrectangles) { - free(d->xrectangles); - d->xrectangles = 0; - } -#elif defined(Q_WS_MAC) - if(d->rgn) { - qt_mac_dispose_rgn(d->rgn); - d->rgn = 0; - } -#endif -} - -/* - \fn QRegion QRegion::unite(const QRegion &r) const - \obsolete - - Use united(\a r) instead. -*/ - -/* - \fn QRegion QRegion::united(const QRegion &r) const - \since 4.2 - - Returns a region which is the union of this region and \a r. - - \img runion.png Region Union - - The figure shows the union of two elliptical regions. - - \sa intersected(), subtracted(), xored() -*/ - -QRegion QRegion::unite(const QRegion &r) const -{ - if (isEmptyHelper(d->qt_rgn)) - return r; - if (isEmptyHelper(r.d->qt_rgn)) - return *this; - - if (d->qt_rgn->contains(*r.d->qt_rgn)) { - return *this; - } else if (r.d->qt_rgn->contains(*d->qt_rgn)) { - return r; - } else if (d->qt_rgn->canAppend(r.d->qt_rgn)) { - QRegion result(*this); - result.detach(); - result.d->qt_rgn->append(r.d->qt_rgn); - return result; - } else if (r.d->qt_rgn->canAppend(d->qt_rgn)) { - QRegion result(r); - result.detach(); - result.d->qt_rgn->append(d->qt_rgn); - return result; - } else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) { - return *this; - } else { - QRegion result; - result.detach(); - UnionRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn); - return result; - } -} - -QRegion& QRegion::operator+=(const QRegion &r) -{ - if (isEmptyHelper(d->qt_rgn)) - return *this = r; - if (isEmptyHelper(r.d->qt_rgn)) - return *this; - - if (d->qt_rgn->contains(*r.d->qt_rgn)) { - return *this; - } else if (r.d->qt_rgn->contains(*d->qt_rgn)) { - return *this = r; - } else if (d->qt_rgn->canAppend(r.d->qt_rgn)) { - detach(); - d->qt_rgn->append(r.d->qt_rgn); - return *this; - } else if (d->qt_rgn->canPrepend(r.d->qt_rgn)) { - detach(); - d->qt_rgn->prepend(r.d->qt_rgn); - return *this; - } else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) { - return *this; - } - - return *this = unite(r); -} - -/* - \fn QRegion QRegion::intersect(const QRegion &r) const - \obsolete - - Use intersected(\a r) instead. -*/ - -/* - \fn QRegion QRegion::intersected(const QRegion &r) const - \since 4.2 - - Returns a region which is the intersection of this region and \a r. - - \img rintersect.png Region Intersection - - The figure shows the intersection of two elliptical regions. -*/ - -QRegion QRegion::intersect(const QRegion &r) const -{ - if (isEmptyHelper(d->qt_rgn) || isEmptyHelper(r.d->qt_rgn) - || !EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents)) - return QRegion(); - - /* this is fully contained in r */ - if (r.d->qt_rgn->contains(*d->qt_rgn)) - return *this; - - /* r is fully contained in this */ - if (d->qt_rgn->contains(*r.d->qt_rgn)) - return r; - - if(r.d->qt_rgn->mode == QRegionPrivate::Single && - d->qt_rgn->mode == QRegionPrivate::Single) - return QRegion(r.d->qt_rgn->single.intersected(d->qt_rgn->single)); -#ifdef QT_GREENPHONE_OPT - else if(r.d->qt_rgn->mode == QRegionPrivate::Single) - return intersect(r.d->qt_rgn->single); - else if(d->qt_rgn->mode == QRegionPrivate::Single) - return r.intersect(d->qt_rgn->single); -#endif - - QRegion result; - result.detach(); - miRegionOp(*result.d->qt_rgn, d->qt_rgn, r.d->qt_rgn, miIntersectO, 0, 0); - - /* - * Can't alter dest's extents before we call miRegionOp because - * it might be one of the source regions and miRegionOp depends - * on the extents of those regions being the same. Besides, this - * way there's no checking against rectangles that will be nuked - * due to coalescing, so we have to examine fewer rectangles. - */ - miSetExtents(*result.d->qt_rgn); - return result; -} - -#ifdef QT_GREENPHONE_OPT -/* - \overload - */ -QRegion QRegion::intersect(const QRect &r) const -{ - // No intersection - if(r.isEmpty() || isEmpty() || !EXTENTCHECK(&r, &d->qt_rgn->extents)) - return QRegion(); - - // This is fully contained in r - if(CONTAINSCHECK(r, d->qt_rgn->extents)) - return *this; - - // r is fully contained in this - if(CONTAINSCHECK(d->qt_rgn->innerRect, r)) - return QRegion(r); - - if(d->qt_rgn->mode == QRegionPrivate::Single) { - return QRegion(d->qt_rgn->single & r); - } else { - QRegion rv(*this); - rv.detach(); - - rv.d->qt_rgn->extents &= r; - rv.d->qt_rgn->innerRect &= r; - rv.d->qt_rgn->innerArea = rv.d->qt_rgn->innerRect.height() * - rv.d->qt_rgn->innerRect.width(); - - int numRects = 0; - for(int ii = 0; ii < rv.d->qt_rgn->numRects; ++ii) { - QRect result = rv.d->qt_rgn->rects[ii] & r; - if(!result.isEmpty()) - rv.d->qt_rgn->rects[numRects++] = result; - } - rv.d->qt_rgn->numRects = numRects; - return rv; - } -} - -/* - \overload - */ -const QRegion QRegion::operator&(const QRect &r) const -{ - return intersect(r); -} - -/* - \overload - */ -QRegion& QRegion::operator&=(const QRect &r) -{ - if(isEmpty() || CONTAINSCHECK(r, d->qt_rgn->extents)) { - // Do nothing - } else if(r.isEmpty() || !EXTENTCHECK(&r, &d->qt_rgn->extents)) { - *this = QRegion(); - } else if(CONTAINSCHECK(d->qt_rgn->innerRect, r)) { - *this = QRegion(r); - } else { - detach(); - if(d->qt_rgn->mode == QRegionPrivate::Single) { - QRect result = d->qt_rgn->single & r; - d->qt_rgn->single = result; - d->qt_rgn->extents = result; - d->qt_rgn->innerRect = result; - d->qt_rgn->innerArea = result.height() * result.width(); - } else { - d->qt_rgn->extents &= r; - d->qt_rgn->innerRect &= r; - d->qt_rgn->innerArea = d->qt_rgn->innerRect.height() * - d->qt_rgn->innerRect.width(); - - int numRects = 0; - for(int ii = 0; ii < d->qt_rgn->numRects; ++ii) { - QRect result = d->qt_rgn->rects[ii] & r; - if(!result.isEmpty()) - d->qt_rgn->rects[numRects++] = result; - } - d->qt_rgn->numRects = numRects; - } - } - return *this; -} -#endif - -/* - \fn QRegion QRegion::subtract(const QRegion &r) const - \obsolete - - Use subtracted(\a r) instead. -*/ - -/* - \fn QRegion QRegion::subtracted(const QRegion &r) const - \since 4.2 - - Returns a region which is \a r subtracted from this region. - - \img rsubtract.png Region Subtraction - - The figure shows the result when the ellipse on the right is - subtracted from the ellipse on the left (\c {left - right}). - - \sa intersected(), united(), xored() -*/ - -QRegion QRegion::subtract(const QRegion &r) const -{ - if (isEmptyHelper(d->qt_rgn) || isEmptyHelper(r.d->qt_rgn)) - return *this; - if (r.d->qt_rgn->contains(*d->qt_rgn)) - return QRegion(); - if (!EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents)) - return *this; - if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) - return QRegion(); - - QRegion result; - result.detach(); - SubtractRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn); - return result; -} - -/* - \fn QRegion QRegion::eor(const QRegion &r) const - \obsolete - - Use xored(\a r) instead. -*/ - -/* - \fn QRegion QRegion::xored(const QRegion &r) const - \since 4.2 - - Returns a region which is the exclusive or (XOR) of this region - and \a r. - - \img rxor.png Region XORed - - The figure shows the exclusive or of two elliptical regions. - - \sa intersected(), united(), subtracted() -*/ - -QRegion QRegion::eor(const QRegion &r) const -{ - if (isEmptyHelper(d->qt_rgn)) { - return r; - } else if (isEmptyHelper(r.d->qt_rgn)) { - return *this; - } else if (!EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents)) { - return (*this + r); - } else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) { - return QRegion(); - } else { - QRegion result; - result.detach(); - XorRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn); - return result; - } -} - -/* - Returns the bounding rectangle of this region. An empty region - gives a rectangle that is QRect::isNull(). -*/ - -QRect QRegion::boundingRect() const -{ - if (isEmpty()) - return QRect(); - return d->qt_rgn->extents; -} - -/* \internal - Returns true if \a rect is guaranteed to be fully contained in \a region. - A false return value does not guarantee the opposite. -*/ -bool qt_region_strictContains(const QRegion ®ion, const QRect &rect) -{ - if (isEmptyHelper(region.d->qt_rgn) || !rect.isValid()) - return false; - -#if 0 // TEST_INNERRECT - static bool guard = false; - if (guard) - return QRect(); - guard = true; - QRegion inner = region.d->qt_rgn->innerRect; - Q_ASSERT((inner - region).isEmpty()); - guard = false; - - int maxArea = 0; - for (int i = 0; i < region.d->qt_rgn->numRects; ++i) { - const QRect r = region.d->qt_rgn->rects.at(i); - if (r.width() * r.height() > maxArea) - maxArea = r.width() * r.height(); - } - - if (maxArea > region.d->qt_rgn->innerArea) { - qDebug() << "not largest rectangle" << region << region.d->qt_rgn->innerRect; - } - Q_ASSERT(maxArea <= region.d->qt_rgn->innerArea); -#endif - - const QRect r1 = region.d->qt_rgn->innerRect; - return (rect.left() >= r1.left() && rect.right() <= r1.right() - && rect.top() >= r1.top() && rect.bottom() <= r1.bottom()); -} - -/* - Returns an array of non-overlapping rectangles that make up the - region. - - The union of all the rectangles is equal to the original region. -*/ -QVector<QRect> QRegion::rects() const -{ - if (d->qt_rgn) { - d->qt_rgn->vector(); - d->qt_rgn->rects.resize(d->qt_rgn->numRects); - return d->qt_rgn->rects; - } else { - return QVector<QRect>(); - } -} - -/* - \fn void QRegion::setRects(const QRect *rects, int number) - - Sets the region using the array of rectangles specified by \a rects and - \a number. - The rectangles \e must be optimally Y-X sorted and follow these restrictions: - - \list - \o The rectangles must not intersect. - \o All rectangles with a given top coordinate must have the same height. - \o No two rectangles may abut horizontally (they should be combined - into a single wider rectangle in that case). - \o The rectangles must be sorted in ascending order, with Y as the major - sort key and X as the minor sort key. - \endlist - \omit - Only some platforms have these restrictions (Qt for Embedded Linux, X11 and Mac OS X). - \endomit -*/ -void QRegion::setRects(const QRect *rects, int num) -{ - *this = QRegion(); - if (!rects || num == 0 || (num == 1 && rects->isEmpty())) - return; - - detach(); - - if(num == 1) { - d->qt_rgn->single = *rects; - d->qt_rgn->mode = QRegionPrivate::Single; - d->qt_rgn->numRects = num; - d->qt_rgn->extents = *rects; - d->qt_rgn->innerRect = *rects; - } else { - d->qt_rgn->mode = QRegionPrivate::Vector; - d->qt_rgn->rects.resize(num); - d->qt_rgn->numRects = num; - int left = INT_MAX, - right = INT_MIN, - top = INT_MAX, - bottom = INT_MIN; - for (int i = 0; i < num; ++i) { - const QRect &rect = rects[i]; - d->qt_rgn->rects[i] = rect; - left = qMin(rect.left(), left); - right = qMax(rect.right(), right); - top = qMin(rect.top(), top); - bottom = qMax(rect.bottom(), bottom); - d->qt_rgn->updateInnerRect(rect); - } - d->qt_rgn->extents = QRect(QPoint(left, top), QPoint(right, bottom)); - } -} - -/* - Returns true if the region is equal to \a r; otherwise returns - false. -*/ - -bool QRegion::operator==(const QRegion &r) const -{ - if (!d->qt_rgn || !r.d->qt_rgn) - return r.d->qt_rgn == d->qt_rgn; - - if (d == r.d) - return true; - else - return EqualRegion(d->qt_rgn, r.d->qt_rgn); -} - -#ifdef QT_GREENPHONE_OPT -bool QRegion::isRect() const -{ - return d->qt_rgn && d->qt_rgn->mode == QRegionPrivate::Single; -} -#endif - -QT_END_NAMESPACE diff --git a/src/gui/painting/qwindowsurface_qws.cpp b/src/gui/painting/qwindowsurface_qws.cpp deleted file mode 100644 index cb293cb135..0000000000 --- a/src/gui/painting/qwindowsurface_qws.cpp +++ /dev/null @@ -1,1433 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsurface_qws_p.h" -#include <qwidget.h> -#include <qscreen_qws.h> -#include <qwsmanager_qws.h> -#include <qapplication.h> -#include <qwsdisplay_qws.h> -#include <qrgb.h> -#include <qpaintengine.h> -#include <qdesktopwidget.h> -#include <private/qapplication_p.h> -#include <private/qwsdisplay_qws_p.h> -#include <private/qwidget_p.h> -#include <private/qwsmanager_p.h> -#include <private/qwslock_p.h> -#include <private/qbackingstore_p.h> -#include <stdio.h> - -QT_BEGIN_NAMESPACE - -#ifdef Q_BACKINGSTORE_SUBSURFACES - -typedef QMap<int, QWSWindowSurface*> SurfaceMap; -Q_GLOBAL_STATIC(SurfaceMap, winIdToSurfaceMap); - -QWSWindowSurface* qt_findWindowSurface(int winId) -{ - return winIdToSurfaceMap()->value(winId); -} - -static void qt_insertWindowSurface(int winId, QWSWindowSurface *surface) -{ - if (!surface) - winIdToSurfaceMap()->remove(winId); - else - winIdToSurfaceMap()->insert(winId, surface); -} - -#endif // Q_BACKINGSTORE_SUBSURFACES - -inline bool isWidgetOpaque(const QWidget *w) -{ - return w->d_func()->isOpaque && !w->testAttribute(Qt::WA_TranslucentBackground); -} - -static inline QScreen *getScreen(const QWidget *w) -{ - const QList<QScreen*> subScreens = qt_screen->subScreens(); - if (subScreens.isEmpty()) - return qt_screen; - - const int screen = QApplication::desktop()->screenNumber(w); - - return qt_screen->subScreens().at(screen < 0 ? 0 : screen); -} - -static int bytesPerPixel(QImage::Format format) -{ - switch (format) { - case QImage::Format_Invalid: - return 0; -#ifndef QT_NO_DEBUG - case QImage::Format_Mono: - case QImage::Format_MonoLSB: - qFatal("QWSWindowSurface: Invalid backingstore format: %i", - int(format)); -#endif - case QImage::Format_Indexed8: - return 1; - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - case QImage::Format_ARGB32_Premultiplied: - return 4; - case QImage::Format_RGB16: - case QImage::Format_RGB555: - case QImage::Format_RGB444: - case QImage::Format_ARGB4444_Premultiplied: - return 2; - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_ARGB8555_Premultiplied: - case QImage::Format_ARGB6666_Premultiplied: - case QImage::Format_RGB666: - case QImage::Format_RGB888: - return 3; - default: -#ifndef QT_NO_DEBUG - qFatal("QWSWindowSurface: Invalid backingstore format: %i", - int(format)); -#endif - return 0; - } -} - -static inline int nextMulOf4(int n) -{ - return ((n + 3) & 0xfffffffc); -} - -static inline void setImageMetrics(QImage &img, QWidget *window) { - QScreen *myScreen = getScreen(window); - if (myScreen) { - int dpmx = myScreen->width()*1000 / myScreen->physicalWidth(); - int dpmy = myScreen->height()*1000 / myScreen->physicalHeight(); - img.setDotsPerMeterX(dpmx); - img.setDotsPerMeterY(dpmy); - } -} - -void QWSWindowSurface::invalidateBuffer() -{ - - QWidget *win = window(); - if (win) { - win->d_func()->invalidateBuffer(win->rect()); -#ifndef QT_NO_QWS_MANAGER - QTLWExtra *topextra = win->d_func()->extra->topextra; - QWSManager *manager = topextra->qwsManager; - if (manager) - manager->d_func()->dirtyRegion(QDecoration::All, - QDecoration::Normal); -#endif - } -} - -QWSWindowSurfacePrivate::QWSWindowSurfacePrivate() - : flags(0), -#ifdef QT_QWS_CLIENTBLIT - directId(-1), -#endif - winId(0) -{ -} - -void QWSWindowSurfacePrivate::setWinId(int id) -{ - winId = id; -} - -int QWSWindowSurface::winId() const -{ - // XXX: the widget winId may change during the lifetime of the widget!!! - - const QWidget *win = window(); - if (win && win->isWindow()) - return win->internalWinId(); - -#ifdef Q_BACKINGSTORE_SUBSURFACES - if (!d_ptr->winId) { - QWSWindowSurface *that = const_cast<QWSWindowSurface*>(this); - QWSDisplay *display = QWSDisplay::instance(); - const int id = display->takeId(); - qt_insertWindowSurface(id, that); - that->d_ptr->winId = id; - - if (win) - display->nameRegion(id, win->objectName(), win->windowTitle()); - else - display->nameRegion(id, QString(), QString()); - - display->setAltitude(id, 1, true); // XXX - } -#endif - - return d_ptr->winId; -} - -void QWSWindowSurface::setWinId(int id) -{ - d_ptr->winId = id; -} - -/*! - \class QWSWindowSurface - \since 4.2 - \ingroup qws - \preliminary - \internal - - \brief The QWSWindowSurface class provides the drawing area for top-level - windows in Qt for Embedded Linux. - - Note that this class is only available in Qt for Embedded Linux. - - In \l{Qt for Embedded Linux}, the default behavior is for each client to - render its widgets into memory while the server is responsible for - putting the contents of the memory onto the - screen. QWSWindowSurface is used by the window system to implement - the associated memory allocation. - - When a screen update is required, the server runs through all the - top-level windows that intersect with the region that is about to - be updated, and ensures that the associated clients have updated - their memory buffer. Then the server uses the screen driver to - copy the content of the memory to the screen. To locate the - relevant parts of memory, the driver is provided with the list of - top-level windows that intersect with the given region. Associated - with each of the top-level windows there is a window surface - representing the drawing area of the window. - - When deriving from the QWSWindowSurface class, e.g., when adding - an \l {Adding an Accelerated Graphics Driver to Qt for Embedded Linux} - {accelerated graphics driver}, there are several pure virtual - functions that must be implemented. In addition, QWSWindowSurface - provides several virtual functions that can be reimplemented to - customize the drawing process. - - \tableofcontents - - \section1 Pure Virtual Functions - - There are in fact two window surface instances for each top-level - window; one used by the application when drawing a window, and - another used by the server application to perform window - compositioning. Implement the attach() to create the server-side - representation of the surface. The data() function must be - implemented to provide the required data. - - Implement the key() function to uniquely identify the surface - class, and the isValid() function to determine is a surface - corresponds to a given widget. - - The geometry() function must be implemented to let the window - system determine the area required by the window surface - (QWSWindowSurface also provides a corresponding virtual - setGeometry() function that is called whenever the area necessary - for the top-level window to be drawn, changes). The image() - function is called by the window system during window - compositioning, and must be implemented to return an image of the - top-level window. - - Finally, the paintDevice() function must be implemented to return - the appropriate paint device, and the scroll() function must be - implemented to scroll the given region of the surface the given - number of pixels. - - \section1 Virtual Functions - - When painting onto the surface, the window system will always call - the beginPaint() function before any painting operations are - performed. Likewise the endPaint() function is automatically - called when the painting is done. Reimplement the painterOffset() - function to alter the offset that is applied when drawing. - - The window system uses the flush() function to put a given region - of the widget onto the screen, and the release() function to - deallocate the screen region corresponding to this window surface. - - \section1 Other Members - - QWSWindowSurface provides the window() function returning a - pointer to the top-level window the surface is representing. The - currently visible region of the associated widget can be retrieved - and set using the clipRegion() and setClipRegion() functions, - respectively. - - When the window system performs the window compositioning, it uses - the SurfaceFlag enum describing the surface content. The currently - set surface flags can be retrieved and altered using the - surfaceFlags() and setSurfaceFlags() functions. In addition, - QWSWindowSurface provides the isBuffered(), isOpaque() and - isRegionReserved() convenience functions. - - \sa {Qt for Embedded Linux Architecture#Drawing on Screen}{Qt for - Embedded Linux Architecture} -*/ - -/*! - \enum QWSWindowSurface::SurfaceFlag - - This enum is used to describe the window surface's contents. It - is used by the screen driver to handle region allocation and - composition. - - \value RegionReserved The surface contains a reserved area. Once - allocated, a reserved area can not not be changed by the window - system, i.e., no other widgets can be drawn on top of this. - - \value Buffered - The surface is in a memory area which is not part of a framebuffer. - (A top-level window with QWidget::windowOpacity() other than 1.0 must use - a buffered surface in order to making blending with the background work.) - - \value Opaque - The surface contains only opaque pixels. - - \sa surfaceFlags(), setSurfaceFlags() -*/ - -/*! - \fn bool QWSWindowSurface::isValid() const - \since 4.3 - - Implement this function to return true if the surface is a valid - surface for the given top-level \a window; otherwise return - false. - - \sa window(), key() -*/ - -/*! - \fn QString QWSWindowSurface::key() const - - Implement this function to return a string that uniquely - identifies the class of this surface. - - \sa window(), isValid() -*/ - -/*! - \fn QByteArray QWSWindowSurface::permanentState() const - \since 4.3 - - Implement this function to return the data required for creating a - server-side representation of the surface. - - \sa attach() -*/ - -/*! - \fn void QWSWindowSurface::setPermanentState(const QByteArray &data) - \since 4.3 - - Implement this function to attach a server-side surface instance - to the corresponding client side instance using the given \a - data. Return true if successful; otherwise return false. - - \sa data() -*/ - -/*! - \fn const QImage QWSWindowSurface::image() const - - Implement this function to return an image of the top-level window. - - \sa geometry() -*/ - -/*! - \fn bool QWSWindowSurface::isRegionReserved() const - - Returns true if the QWSWindowSurface::RegionReserved is set; otherwise - returns false. - - \sa surfaceFlags() -*/ - -/*! - \fn bool QWSWindowSurface::isBuffered() const - - Returns true if the QWSWindowSurface::Buffered is set; otherwise returns false. - - \sa surfaceFlags() -*/ - -/*! - \fn bool QWSWindowSurface::isOpaque() const - - Returns true if the QWSWindowSurface::Opaque is set; otherwise - returns false. - - \sa surfaceFlags() -*/ - - -/*! - Constructs an empty surface. -*/ -QWSWindowSurface::QWSWindowSurface() - : QWindowSurface(0), d_ptr(new QWSWindowSurfacePrivate) -{ -} - -/*! - Constructs an empty surface for the given top-level \a widget. -*/ -QWSWindowSurface::QWSWindowSurface(QWidget *widget) - : QWindowSurface(widget), d_ptr(new QWSWindowSurfacePrivate) -{ -} - -QWSWindowSurface::~QWSWindowSurface() -{ -#ifdef Q_BACKINGSTORE_SUBSURFACES - if (d_ptr->winId) - winIdToSurfaceMap()->remove(d_ptr->winId); -#endif - - delete d_ptr; -} - -/*! - Returns the offset to be used when painting. - - \sa paintDevice() -*/ -QPoint QWSWindowSurface::painterOffset() const -{ - const QWidget *w = window(); - if (!w) - return QPoint(); - return w->geometry().topLeft() - w->frameGeometry().topLeft(); -} - -void QWSWindowSurface::beginPaint(const QRegion &) -{ - lock(); -} - -void QWSWindowSurface::endPaint(const QRegion &) -{ - unlock(); -} - -// XXX: documentation!!! -QByteArray QWSWindowSurface::transientState() const -{ - return QByteArray(); -} - -QByteArray QWSWindowSurface::permanentState() const -{ - return QByteArray(); -} - -void QWSWindowSurface::setTransientState(const QByteArray &state) -{ - Q_UNUSED(state); -} - -void QWSWindowSurface::setPermanentState(const QByteArray &state) -{ - Q_UNUSED(state); -} - -bool QWSWindowSurface::lock(int timeout) -{ - Q_UNUSED(timeout); - return true; -} - -void QWSWindowSurface::unlock() -{ -} - -#ifdef QT_QWS_CLIENTBLIT -/*! \internal */ -const QRegion QWSWindowSurface::directRegion() const -{ - return d_ptr->direct; -} - -/*! \internal */ -int QWSWindowSurface::directRegionId() const -{ - return d_ptr->directId; -} - -/*! \internal */ -void QWSWindowSurface::setDirectRegion(const QRegion &r, int id) -{ - d_ptr->direct = r; - d_ptr->directId = id; -} -#endif - -/*! - Returns the region currently visible on the screen. - - \sa setClipRegion() -*/ -const QRegion QWSWindowSurface::clipRegion() const -{ - return d_ptr->clip; -} - -/*! - Sets the region currently visible on the screen to be the given \a - clip region. - - \sa clipRegion() -*/ -void QWSWindowSurface::setClipRegion(const QRegion &clip) -{ - if (clip == d_ptr->clip) - return; - - QRegion expose = (clip - d_ptr->clip); - d_ptr->clip = clip; - - if (expose.isEmpty() || clip.isEmpty()) - return; // No repaint or flush required. - - QWidget *win = window(); - if (!win) - return; - - if (isBuffered()) { - // No repaint required. Flush exposed area via the backing store. - win->d_func()->syncBackingStore(expose); - return; - } - -#ifndef QT_NO_QWS_MANAGER - // Invalidate exposed decoration area. - if (win && win->isWindow()) { - QTLWExtra *topextra = win->d_func()->extra->topextra; - if (QWSManager *manager = topextra->qwsManager) { - QRegion decorationExpose(manager->region()); - decorationExpose.translate(-win->geometry().topLeft()); - decorationExpose &= expose; - if (!decorationExpose.isEmpty()) { - expose -= decorationExpose; - manager->d_func()->dirtyRegion(QDecoration::All, QDecoration::Normal, decorationExpose); - } - } - } -#endif - - // Invalidate exposed widget area. - win->d_func()->invalidateBuffer(expose); -} - -/*! - Returns the surface flags describing the contents of this surface. - - \sa isBuffered(), isOpaque(), isRegionReserved() -*/ -QWSWindowSurface::SurfaceFlags QWSWindowSurface::surfaceFlags() const -{ - return d_ptr->flags; -} - -/*! - Sets the surface flags describing the contents of this surface, to - be the given \a flags. - - \sa surfaceFlags() -*/ -void QWSWindowSurface::setSurfaceFlags(SurfaceFlags flags) -{ - d_ptr->flags = flags; -} - -void QWSWindowSurface::setGeometry(const QRect &rect) -{ - QRegion mask = rect; - - const QWidget *win = window(); - if (win) { -#ifndef QT_NO_QWS_MANAGER - if (win->isWindow()) { - QTLWExtra *topextra = win->d_func()->extra->topextra; - QWSManager *manager = topextra->qwsManager; - - if (manager) { - // The frame geometry is the bounding rect of manager->region, - // which could be too much, so we need to clip. - mask &= (manager->region() + win->geometry()); - } - } -#endif - - const QRegion winMask = win->mask(); - if (!winMask.isEmpty()) - mask &= winMask.translated(win->geometry().topLeft()); - } - - setGeometry(rect, mask); -} - -void QWSWindowSurface::setGeometry(const QRect &rect, const QRegion &mask) -{ - if (rect == geometry()) // XXX: && mask == prevMask - return; - - const bool isResize = rect.size() != geometry().size(); - const bool needsRepaint = isResize || !isBuffered(); - - QWindowSurface::setGeometry(rect); - - const QRegion region = mask & rect; - QWidget *win = window(); - // Only request regions for widgets visible on the screen. - // (Added the !win check for compatibility reasons, because - // there was no "if (win)" check before). - const bool requestQWSRegion = !win || !win->testAttribute(Qt::WA_DontShowOnScreen); - if (requestQWSRegion) - QWidget::qwsDisplay()->requestRegion(winId(), key(), permanentState(), region); - - if (needsRepaint) - invalidateBuffer(); - - if (!requestQWSRegion) { - // We didn't request a region, hence we won't get a QWSRegionEvent::Allocation - // event back from the server so we set the clip directly. We have to - // do this after the invalidateBuffer() call above, as it might trigger a - // backing store sync, resulting in too many update requests. - setClipRegion(region); - } -} - -static inline void flushUpdate(QWidget *widget, const QRegion ®ion, - const QPoint &offset) -{ -#ifdef QT_NO_PAINT_DEBUG - Q_UNUSED(widget); - Q_UNUSED(region); - Q_UNUSED(offset); -#else - static int delay = -1; - - if (delay == -1) - delay = qgetenv("QT_FLUSH_UPDATE").toInt() * 10; - - if (delay == 0) - return; - - static QWSYellowSurface surface(true); - surface.setDelay(delay); - surface.flush(widget, region, offset); -#endif // QT_NO_PAINT_DEBUG -} - -void QWSWindowSurface::flush(QWidget *widget, const QRegion ®ion, - const QPoint &offset) -{ - const QWidget *win = window(); - if (!win) - return; - -#ifndef QT_NO_GRAPHICSVIEW - QWExtra *extra = win->d_func()->extra; - if (extra && extra->proxyWidget) - return; -#endif //QT_NO_GRAPHICSVIEW - - Q_UNUSED(offset); - - const bool opaque = isOpaque(); -#ifdef QT_QWS_DISABLE_FLUSHCLIPPING - QRegion toFlush = region; -#else - QRegion toFlush = region & d_ptr->clip; -#endif - - if (!toFlush.isEmpty()) { - flushUpdate(widget, toFlush, QPoint(0, 0)); - QPoint globalZero = win->mapToGlobal(QPoint(0, 0)); - toFlush.translate(globalZero); - -#ifdef QT_QWS_CLIENTBLIT - bool needRepaint = true; - if (opaque) { - QScreen* widgetScreen = getScreen(widget); - if (widgetScreen->supportsBlitInClients()) { - - QWSDisplay::grab(); - if(directRegion().intersected(toFlush) == toFlush) { - QPoint translate = -globalZero + painterOffset() + geometry().topLeft(); - QRegion flushRegion = toFlush.translated(translate); - widgetScreen->blit(image(), geometry().topLeft(), flushRegion); - widgetScreen->setDirty(toFlush.boundingRect()); - needRepaint = false; - } - QWSDisplay::ungrab(); - } - } - - if(needRepaint) -#endif - win->qwsDisplay()->repaintRegion(winId(), win->windowFlags(), opaque, toFlush); - } -} - -/*! - Move the surface with the given \a offset. - - A subclass may reimplement this function to enable accelerated window move. - It must return true if the move was successful and no repaint is necessary, - false otherwise. - - The default implementation updates the QWindowSurface geometry and - returns true if the surface is buffered; false otherwise. - - This function is called by the window system on the client instance. - - \sa isBuffered() -*/ -bool QWSWindowSurface::move(const QPoint &offset) -{ - QWindowSurface::setGeometry(geometry().translated(offset)); - return isBuffered(); -} - -/*! - Move the surface with the given \a offset. - - The new visible region after the window move is given by \a newClip - in screen coordinates. - - A subclass may reimplement this function to enable accelerated window move. - The returned region indicates the area that still needs to be composed - on the screen. - - The default implementation updates the QWindowSurface geometry and - returns the union of the old and new geometry. - - This function is called by the window system on the server instance. -*/ -QRegion QWSWindowSurface::move(const QPoint &offset, const QRegion &newClip) -{ - const QRegion oldGeometry = geometry(); - QWindowSurface::setGeometry(geometry().translated(offset)); - return oldGeometry + newClip; -} - -void QWSWindowSurface::releaseSurface() -{ -} - -bool QWSMemorySurface::lock(int timeout) -{ - Q_UNUSED(timeout); -#ifndef QT_NO_QWS_MULTIPROCESS - if (memlock && !memlock->lock(QWSLock::BackingStore)) - return false; -#endif -#ifndef QT_NO_THREAD - threadLock.lock(); -#endif - return true; -} - -void QWSMemorySurface::unlock() -{ -#ifndef QT_NO_THREAD - threadLock.unlock(); -#endif -#ifndef QT_NO_QWS_MULTIPROCESS - if (memlock) - memlock->unlock(QWSLock::BackingStore); -#endif -} - -QWSMemorySurface::QWSMemorySurface() - : QWSWindowSurface() -#ifndef QT_NO_QWS_MULTIPROCESS - , memlock(0) -#endif -{ - setSurfaceFlags(Buffered); -} - -QWSMemorySurface::QWSMemorySurface(QWidget *w) - : QWSWindowSurface(w) -{ - SurfaceFlags flags = Buffered; - if (isWidgetOpaque(w)) - flags |= Opaque; - setSurfaceFlags(flags); - -#ifndef QT_NO_QWS_MULTIPROCESS - memlock = QWSDisplay::Data::getClientLock(); -#endif -} - -QWSMemorySurface::~QWSMemorySurface() -{ -} - - -QImage::Format -QWSMemorySurface::preferredImageFormat(const QWidget *widget) const -{ - QScreen *screen = getScreen(widget); - const int depth = screen->depth(); - const bool opaque = isWidgetOpaque(widget); - - if (!opaque) { - if (depth <= 12) - return QImage::Format_ARGB4444_Premultiplied; - else if (depth <= 15) - return QImage::Format_ARGB8555_Premultiplied; - else if (depth <= 16) - return QImage::Format_ARGB8565_Premultiplied; - else if (depth <= 18) - return QImage::Format_ARGB6666_Premultiplied; - else - return QImage::Format_ARGB32_Premultiplied; - } - - QImage::Format format = screen->pixelFormat(); - if (format > QImage::Format_Indexed8) // ### assumes all new image formats supports a QPainter - return format; - - if (depth <= 12) - return QImage::Format_RGB444; - else if (depth <= 15) - return QImage::Format_RGB555; - else if (depth <= 16) - return QImage::Format_RGB16; - else if (depth <= 18) - return QImage::Format_RGB666; - else if (depth <= 24) - return QImage::Format_RGB888; - else - return QImage::Format_ARGB32_Premultiplied; -} - -#ifndef QT_NO_QWS_MULTIPROCESS -void QWSMemorySurface::setLock(int lockId) -{ - if (memlock && memlock->id() == lockId) - return; - delete memlock; - memlock = (lockId == -1 ? 0 : new QWSLock(lockId)); - return; -} -#endif // QT_NO_QWS_MULTIPROCESS - -bool QWSMemorySurface::isValid() const -{ - if (img.isNull()) - return true; - - const QWidget *win = window(); - if (preferredImageFormat(win) != img.format()) - return false; - - if (isOpaque() != isWidgetOpaque(win)) // XXX: use QWidgetPrivate::isOpaque() - return false; - - return true; -} - -// ### copied from qwindowsurface_raster.cpp -- should be cross-platform -void QWSMemorySurface::beginPaint(const QRegion &rgn) -{ - if (!isWidgetOpaque(window())) { - QPainter p(&img); - p.setCompositionMode(QPainter::CompositionMode_Source); - const QVector<QRect> rects = rgn.rects(); - const QColor blank = Qt::transparent; - for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { - QRect r = *it; -#ifdef Q_BACKINGSTORE_SUBSURFACES - r.translate(painterOffset()); -#endif - p.fillRect(r, blank); - } - } - QWSWindowSurface::beginPaint(rgn); -} - -// from qwindowsurface.cpp -extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); - -bool QWSMemorySurface::scroll(const QRegion &area, int dx, int dy) -{ - const QVector<QRect> rects = area.rects(); - for (int i = 0; i < rects.size(); ++i) - qt_scrollRectInImage(img, rects.at(i), QPoint(dx, dy)); - - return true; -} - -QPoint QWSMemorySurface::painterOffset() const -{ - const QWidget *w = window(); - if (!w) - return QPoint(); - - if (w->mask().isEmpty()) - return QWSWindowSurface::painterOffset(); - - const QRegion region = w->mask() - & w->frameGeometry().translated(-w->geometry().topLeft()); - return -region.boundingRect().topLeft(); -} - -QWSLocalMemSurface::QWSLocalMemSurface() - : QWSMemorySurface(), mem(0), memsize(0) -{ -} - -QWSLocalMemSurface::QWSLocalMemSurface(QWidget *w) - : QWSMemorySurface(w), mem(0), memsize(0) -{ -} - -QWSLocalMemSurface::~QWSLocalMemSurface() -{ - if (memsize) - delete[] mem; -} - -void QWSLocalMemSurface::setGeometry(const QRect &rect) -{ - QSize size = rect.size(); - - QWidget *win = window(); - if (win && !win->mask().isEmpty()) { - const QRegion region = win->mask() - & rect.translated(-win->geometry().topLeft()); - size = region.boundingRect().size(); - } - - uchar *deleteLater = 0; - // In case of a Hide event we need to delete the memory after sending the - // event to the server in order to let the server animate the event. - if (size.isEmpty()) { - deleteLater = mem; - mem = 0; - } - - if (img.size() != size) { - delete[] mem; - if (size.isEmpty()) { - mem = 0; - img = QImage(); - } else { - const QImage::Format format = preferredImageFormat(win); - const int bpl = nextMulOf4(bytesPerPixel(format) * size.width()); - const int memsize = bpl * size.height(); - mem = new uchar[memsize]; - img = QImage(mem, size.width(), size.height(), bpl, format); - setImageMetrics(img, win); - } - } - - QWSWindowSurface::setGeometry(rect); - delete[] deleteLater; -} - -QByteArray QWSLocalMemSurface::permanentState() const -{ - QByteArray array; - array.resize(sizeof(uchar*) + 3 * sizeof(int) + - sizeof(SurfaceFlags)); - - char *ptr = array.data(); - - *reinterpret_cast<uchar**>(ptr) = mem; - ptr += sizeof(uchar*); - - reinterpret_cast<int*>(ptr)[0] = img.width(); - reinterpret_cast<int*>(ptr)[1] = img.height(); - ptr += 2 * sizeof(int); - - *reinterpret_cast<int *>(ptr) = img.format(); - ptr += sizeof(int); - - *reinterpret_cast<SurfaceFlags*>(ptr) = surfaceFlags(); - - return array; -} - -void QWSLocalMemSurface::setPermanentState(const QByteArray &data) -{ - int width; - int height; - QImage::Format format; - SurfaceFlags flags; - - const char *ptr = data.constData(); - - mem = *reinterpret_cast<uchar* const*>(ptr); - ptr += sizeof(uchar*); - - width = reinterpret_cast<const int*>(ptr)[0]; - height = reinterpret_cast<const int*>(ptr)[1]; - ptr += 2 * sizeof(int); - - format = QImage::Format(*reinterpret_cast<const int*>(ptr)); - ptr += sizeof(int); - - flags = *reinterpret_cast<const SurfaceFlags*>(ptr); - - const int bpl = nextMulOf4(bytesPerPixel(format) * width); - QWSMemorySurface::img = QImage(mem, width, height, bpl, format); - setSurfaceFlags(flags); -} - -void QWSLocalMemSurface::releaseSurface() -{ - mem = 0; - img = QImage(); -} - -#ifndef QT_NO_QWS_MULTIPROCESS - -QWSSharedMemSurface::QWSSharedMemSurface() - : QWSMemorySurface() -{ -} - -QWSSharedMemSurface::QWSSharedMemSurface(QWidget *widget) - : QWSMemorySurface(widget) -{ -} - -QWSSharedMemSurface::~QWSSharedMemSurface() -{ - // mem.detach() is done automatically by ~QSharedMemory -} - -bool QWSSharedMemSurface::setMemory(int memId) -{ - if (mem.id() == memId) - return true; - - mem.detach(); - if (!mem.attach(memId)) { - perror("QWSSharedMemSurface: attaching to shared memory"); - qCritical("QWSSharedMemSurface: Error attaching to" - " shared memory 0x%x", memId); - return false; - } - - return true; -} - -#ifdef QT_QWS_CLIENTBLIT -void QWSSharedMemSurface::setDirectRegion(const QRegion &r, int id) -{ - QWSMemorySurface::setDirectRegion(r, id); - if(mem.address()) - *(uint *)mem.address() = id; -} - -const QRegion QWSSharedMemSurface::directRegion() const -{ - QWSSharedMemory *cmem = const_cast<QWSSharedMemory *>(&mem); - if (cmem->address() && ((int*)cmem->address())[0] == directRegionId()) - return QWSMemorySurface::directRegion(); - else - return QRegion(); -} -#endif - -void QWSSharedMemSurface::setPermanentState(const QByteArray &data) -{ - int memId; - int width; - int height; - int lockId; - QImage::Format format; - SurfaceFlags flags; - - const int *ptr = reinterpret_cast<const int*>(data.constData()); - - memId = ptr[0]; - width = ptr[1]; - height = ptr[2]; - lockId = ptr[3]; - format = QImage::Format(ptr[4]); - flags = SurfaceFlags(ptr[5]); - - setSurfaceFlags(flags); - setMemory(memId); - setLock(lockId); - -#ifdef QT_QWS_CLIENTBLIT - uchar *base = static_cast<uchar*>(mem.address()) + sizeof(uint); -#else - uchar *base = static_cast<uchar*>(mem.address()); -#endif - const int bpl = nextMulOf4(bytesPerPixel(format) * width); - QWSMemorySurface::img = QImage(base, width, height, bpl, format); -} - -void QWSSharedMemSurface::setGeometry(const QRect &rect) -{ - const QSize size = rect.size(); - if (img.size() != size) { - if (size.isEmpty()) { - mem.detach(); - img = QImage(); - } else { - mem.detach(); - - QWidget *win = window(); - const QImage::Format format = preferredImageFormat(win); - const int bpl = nextMulOf4(bytesPerPixel(format) * size.width()); -#ifdef QT_QWS_CLIENTBLIT - const int imagesize = bpl * size.height() + sizeof(uint); -#else - const int imagesize = bpl * size.height(); -#endif - if (!mem.create(imagesize)) { - perror("QWSSharedMemSurface::setGeometry allocating shared memory"); - qFatal("Error creating shared memory of size %d", imagesize); - } -#ifdef QT_QWS_CLIENTBLIT - *((uint *)mem.address()) = 0; - uchar *base = static_cast<uchar*>(mem.address()) + sizeof(uint); -#else - uchar *base = static_cast<uchar*>(mem.address()); -#endif - img = QImage(base, size.width(), size.height(), bpl, format); - setImageMetrics(img, win); - } - } - - QWSWindowSurface::setGeometry(rect); -} - -QByteArray QWSSharedMemSurface::permanentState() const -{ - QByteArray array; - array.resize(6 * sizeof(int)); - - int *ptr = reinterpret_cast<int*>(array.data()); - - ptr[0] = mem.id(); - ptr[1] = img.width(); - ptr[2] = img.height(); - ptr[3] = (memlock ? memlock->id() : -1); - ptr[4] = int(img.format()); - ptr[5] = int(surfaceFlags()); - - return array; -} - -void QWSSharedMemSurface::releaseSurface() -{ - mem.detach(); - img = QImage(); -} - -#endif // QT_NO_QWS_MULTIPROCESS - -#ifndef QT_NO_PAINTONSCREEN - -QWSOnScreenSurface::QWSOnScreenSurface(QWidget *w) - : QWSMemorySurface(w) -{ - attachToScreen(getScreen(w)); - setSurfaceFlags(Opaque); -} - -QWSOnScreenSurface::QWSOnScreenSurface() - : QWSMemorySurface() -{ - setSurfaceFlags(Opaque); -} - -void QWSOnScreenSurface::attachToScreen(const QScreen *s) -{ - screen = s; - uchar *base = screen->base(); - QImage::Format format = screen->pixelFormat(); - - if (format == QImage::Format_Invalid || format == QImage::Format_Indexed8) { - //### currently we have no paint engine for indexed image formats - qFatal("QWSOnScreenSurface::attachToScreen(): screen depth %d " - "not implemented", screen->depth()); - return; - } - QWSMemorySurface::img = QImage(base, screen->width(), screen->height(), - screen->linestep(), format ); -} - -QWSOnScreenSurface::~QWSOnScreenSurface() -{ -} - -QPoint QWSOnScreenSurface::painterOffset() const -{ - return geometry().topLeft() + QWSWindowSurface::painterOffset(); -} - -bool QWSOnScreenSurface::isValid() const -{ - const QWidget *win = window(); - if (screen != getScreen(win)) - return false; - if (img.isNull()) - return false; - return QScreen::isWidgetPaintOnScreen(win); -} - -QByteArray QWSOnScreenSurface::permanentState() const -{ - QByteArray array; - array.resize(sizeof(int)); - int *ptr = reinterpret_cast<int*>(array.data()); - ptr[0] = QApplication::desktop()->screenNumber(window()); - return array; -} - -void QWSOnScreenSurface::setPermanentState(const QByteArray &data) -{ - const int *ptr = reinterpret_cast<const int*>(data.constData()); - const int screenNo = ptr[0]; - - QScreen *screen = qt_screen; - if (screenNo > 0) - screen = qt_screen->subScreens().at(screenNo); - attachToScreen(screen); -} - -#endif // QT_NO_PAINTONSCREEN - -#ifndef QT_NO_PAINT_DEBUG - -QWSYellowSurface::QWSYellowSurface(bool isClient) - : QWSWindowSurface(), delay(10) -{ - if (isClient) { - setWinId(QWidget::qwsDisplay()->takeId()); - QWidget::qwsDisplay()->nameRegion(winId(), - QLatin1String("Debug flush paint"), - QLatin1String("Silly yellow thing")); - QWidget::qwsDisplay()->setAltitude(winId(), 1, true); - } - setSurfaceFlags(Buffered); -} - -QWSYellowSurface::~QWSYellowSurface() -{ -} - -QByteArray QWSYellowSurface::permanentState() const -{ - QByteArray array; - array.resize(2 * sizeof(int)); - - int *ptr = reinterpret_cast<int*>(array.data()); - ptr[0] = surfaceSize.width(); - ptr[1] = surfaceSize.height(); - - return array; -} - -void QWSYellowSurface::setPermanentState(const QByteArray &data) -{ - const int *ptr = reinterpret_cast<const int*>(data.constData()); - - const int width = ptr[0]; - const int height = ptr[1]; - - img = QImage(width, height, QImage::Format_ARGB32); - img.fill(qRgba(255,255,31,127)); -} - -void QWSYellowSurface::flush(QWidget *widget, const QRegion ®ion, - const QPoint &offset) -{ - Q_UNUSED(offset); - - QWSDisplay *display = QWidget::qwsDisplay(); - QRegion rgn = region; - - if (widget) - rgn.translate(widget->mapToGlobal(QPoint(0, 0))); - - surfaceSize = region.boundingRect().size(); - - const int id = winId(); - display->requestRegion(id, key(), permanentState(), rgn); - display->setAltitude(id, 1, true); - display->repaintRegion(id, 0, false, rgn); - - ::usleep(500 * delay); - display->requestRegion(id, key(), permanentState(), QRegion()); - ::usleep(500 * delay); -} - -#endif // QT_NO_PAINT_DEBUG - -#ifndef QT_NO_DIRECTPAINTER - -static inline QScreen *getPrimaryScreen() -{ - QScreen *screen = QScreen::instance(); - if (!screen->base()) { - QList<QScreen*> subScreens = screen->subScreens(); - if (subScreens.size() < 1) - return 0; - screen = subScreens.at(0); - } - return screen; -} - -QWSDirectPainterSurface::QWSDirectPainterSurface(bool isClient, - QDirectPainter::SurfaceFlag flags) - : QWSWindowSurface(), flushingRegionEvents(false), doLocking(false) -{ - setSurfaceFlags(Opaque); - synchronous = (flags == QDirectPainter::ReservedSynchronous); - - if (isClient) { - setWinId(QWidget::qwsDisplay()->takeId()); - QWidget::qwsDisplay()->nameRegion(winId(), - QLatin1String("QDirectPainter reserved space"), - QLatin1String("reserved")); - } else { - setWinId(0); - } - _screen = QScreen::instance(); - if (!_screen->base()) { - QList<QScreen*> subScreens = _screen->subScreens(); - if (subScreens.size() < 1) - _screen = 0; - else - _screen = subScreens.at(0); - } -} - -QWSDirectPainterSurface::~QWSDirectPainterSurface() -{ - if (winId() && QWSDisplay::instance()) // make sure not in QApplication destructor - QWidget::qwsDisplay()->destroyRegion(winId()); -} - -void QWSDirectPainterSurface::setRegion(const QRegion ®ion) -{ - const int id = winId(); - QWidget::qwsDisplay()->requestRegion(id, key(), permanentState(), region); -#ifndef QT_NO_QWS_MULTIPROCESS - if (synchronous) - QWSDisplay::instance()->d->waitForRegionAck(id); -#endif -} - -void QWSDirectPainterSurface::flush(QWidget *, const QRegion &r, const QPoint &) -{ - QWSDisplay::instance()->repaintRegion(winId(), 0, true, r); -} - -QByteArray QWSDirectPainterSurface::permanentState() const -{ - QByteArray res; - if (isRegionReserved()) - res.append( 'r'); - return res; -} - -void QWSDirectPainterSurface::setPermanentState(const QByteArray &ba) -{ - if (ba.size() > 0 && ba.at(0) == 'r') - setReserved(); - setSurfaceFlags(surfaceFlags() | Opaque); -} - -void QWSDirectPainterSurface::beginPaint(const QRegion ®ion) -{ - QWSWindowSurface::beginPaint(region); -#ifndef QT_NO_QWS_MULTIPROCESS - if (!synchronous) { - flushingRegionEvents = true; - QWSDisplay::instance()->d->waitForRegionEvents(winId(), doLocking); - flushingRegionEvents = false; - } -#endif -} - -bool QWSDirectPainterSurface::hasPendingRegionEvents() const -{ -#ifndef QT_NO_QWS_MULTIPROCESS - if (synchronous) - return false; - - return QWSDisplay::instance()->d->hasPendingRegionEvents(); -#else - return false; -#endif -} - -bool QWSDirectPainterSurface::lock(int timeout) -{ -#ifndef QT_NO_THREAD - threadLock.lock(); -#endif - Q_UNUSED(timeout); - if (doLocking) - QWSDisplay::grab(true); - return true; -} - -void QWSDirectPainterSurface::unlock() -{ - if (doLocking) - QWSDisplay::ungrab(); -#ifndef QT_NO_THREAD - threadLock.unlock(); -#endif -} - -#endif // QT_NO_DIRECTPAINTER - -QT_END_NAMESPACE diff --git a/src/gui/painting/qwindowsurface_qws_p.h b/src/gui/painting/qwindowsurface_qws_p.h deleted file mode 100644 index fd56c814a3..0000000000 --- a/src/gui/painting/qwindowsurface_qws_p.h +++ /dev/null @@ -1,355 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSURFACE_QWS_P_H -#define QWINDOWSURFACE_QWS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qwindowsurface_p.h" -#include <qregion.h> -#include <qimage.h> -#include <qdirectpainter_qws.h> -#include <qmutex.h> -#include <private/qwssharedmemory_p.h> - -QT_BEGIN_NAMESPACE - -class QScreen; -class QWSWindowSurfacePrivate; - -class Q_GUI_EXPORT QWSWindowSurface : public QWindowSurface -{ -public: - QWSWindowSurface(); - QWSWindowSurface(QWidget *widget); - ~QWSWindowSurface(); - - virtual bool isValid() const = 0; - - virtual void setGeometry(const QRect &rect); - virtual void setGeometry(const QRect &rect, const QRegion &mask); - virtual void flush(QWidget *widget, const QRegion ®ion, - const QPoint &offset); - - virtual bool move(const QPoint &offset); - virtual QRegion move(const QPoint &offset, const QRegion &newClip); - - virtual QPoint painterOffset() const; // remove!!! - - virtual void beginPaint(const QRegion &); - virtual void endPaint(const QRegion &); - - virtual bool lock(int timeout = -1); - virtual void unlock(); - - virtual QString key() const = 0; - - // XXX: not good enough - virtual QByteArray transientState() const; - virtual QByteArray permanentState() const; - virtual void setTransientState(const QByteArray &state); - virtual void setPermanentState(const QByteArray &state); - - virtual QImage image() const = 0; - virtual QPaintDevice *paintDevice() = 0; - - const QRegion clipRegion() const; - void setClipRegion(const QRegion &); - -#ifdef QT_QWS_CLIENTBLIT - virtual const QRegion directRegion() const; - virtual int directRegionId() const; - virtual void setDirectRegion(const QRegion &, int); -#endif - - enum SurfaceFlag { - RegionReserved = 0x1, - Buffered = 0x2, - Opaque = 0x4 - }; - Q_DECLARE_FLAGS(SurfaceFlags, SurfaceFlag) - - SurfaceFlags surfaceFlags() const; - - inline bool isRegionReserved() const { - return surfaceFlags() & RegionReserved; - } - inline bool isBuffered() const { return surfaceFlags() & Buffered; } - inline bool isOpaque() const { return surfaceFlags() & Opaque; } - - int winId() const; - virtual void releaseSurface(); - -protected: - void setSurfaceFlags(SurfaceFlags type); - void setWinId(int id); - -private: - friend class QWidgetPrivate; - - void invalidateBuffer(); - - QWSWindowSurfacePrivate *d_ptr; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QWSWindowSurface::SurfaceFlags) - -class QWSWindowSurfacePrivate -{ -public: - QWSWindowSurfacePrivate(); - - void setWinId(int id); - - QWSWindowSurface::SurfaceFlags flags; - QRegion clip; -#ifdef QT_QWS_CLIENTBLIT - QRegion direct; - int directId; -#endif - - int winId; -}; - -class QWSLock; - -class Q_GUI_EXPORT QWSMemorySurface : public QWSWindowSurface -{ -public: - QWSMemorySurface(); - QWSMemorySurface(QWidget *widget); - ~QWSMemorySurface(); - - bool isValid() const; - - QPaintDevice *paintDevice() { return &img; } - bool scroll(const QRegion &area, int dx, int dy); - - QImage image() const { return img; } - QPoint painterOffset() const; - - void beginPaint(const QRegion &rgn); - - bool lock(int timeout = -1); - void unlock(); - -protected: - QImage::Format preferredImageFormat(const QWidget *widget) const; - -#ifndef QT_NO_QWS_MULTIPROCESS - void setLock(int lockId); - QWSLock *memlock; -#endif -#ifndef QT_NO_THREAD - QMutex threadLock; -#endif - - QImage img; -}; - -class Q_GUI_EXPORT QWSLocalMemSurface : public QWSMemorySurface -{ -public: - QWSLocalMemSurface(); - QWSLocalMemSurface(QWidget *widget); - ~QWSLocalMemSurface(); - - void setGeometry(const QRect &rect); - - QString key() const { return QLatin1String("mem"); } - QByteArray permanentState() const; - - void setPermanentState(const QByteArray &data); - virtual void releaseSurface(); -protected: - uchar *mem; - int memsize; -}; - -#ifndef QT_NO_QWS_MULTIPROCESS -class Q_GUI_EXPORT QWSSharedMemSurface : public QWSMemorySurface -{ -public: - QWSSharedMemSurface(); - QWSSharedMemSurface(QWidget *widget); - ~QWSSharedMemSurface(); - - void setGeometry(const QRect &rect); - - QString key() const { return QLatin1String("shm"); } - QByteArray permanentState() const; - - void setPermanentState(const QByteArray &data); - -#ifdef QT_QWS_CLIENTBLIT - virtual void setDirectRegion(const QRegion &, int); - virtual const QRegion directRegion() const; -#endif - virtual void releaseSurface(); - -private: - bool setMemory(int memId); - - QWSSharedMemory mem; -}; -#endif // QT_NO_QWS_MULTIPROCESS - -#ifndef QT_NO_PAINTONSCREEN -class Q_GUI_EXPORT QWSOnScreenSurface : public QWSMemorySurface -{ -public: - QWSOnScreenSurface(); - QWSOnScreenSurface(QWidget *widget); - ~QWSOnScreenSurface(); - - bool isValid() const; - QPoint painterOffset() const; - - QString key() const { return QLatin1String("OnScreen"); } - QByteArray permanentState() const; - - void setPermanentState(const QByteArray &data); - -private: - void attachToScreen(const QScreen *screen); - - const QScreen *screen; -}; -#endif // QT_NO_PAINTONSCREEN - -#ifndef QT_NO_PAINT_DEBUG -class Q_GUI_EXPORT QWSYellowSurface : public QWSWindowSurface -{ -public: - QWSYellowSurface(bool isClient = false); - ~QWSYellowSurface(); - - void setDelay(int msec) { delay = msec; } - - bool isValid() const { return true; } - - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - - QString key() const { return QLatin1String("Yellow"); } - QByteArray permanentState() const; - - void setPermanentState(const QByteArray &data); - - QPaintDevice *paintDevice() { return &img; } - QImage image() const { return img; } - -private: - int delay; - QSize surfaceSize; // client side - QImage img; // server side -}; -#endif // QT_NO_PAINT_DEBUG - -#ifndef QT_NO_DIRECTPAINTER - -class QScreen; - -class Q_GUI_EXPORT QWSDirectPainterSurface : public QWSWindowSurface -{ -public: - QWSDirectPainterSurface(bool isClient = false, - QDirectPainter::SurfaceFlag flags = QDirectPainter::NonReserved); - ~QWSDirectPainterSurface(); - - void setReserved() { setSurfaceFlags(RegionReserved); } - - void setGeometry(const QRect &rect) { setRegion(rect); } - - void setRegion(const QRegion ®ion); - QRegion region() const { return clipRegion(); } - - void flush(QWidget*, const QRegion &, const QPoint &); - - bool isValid() const { return false; } - - QString key() const { return QLatin1String("DirectPainter"); } - QByteArray permanentState() const; - - void setPermanentState(const QByteArray &); - - QImage image() const { return QImage(); } - QPaintDevice *paintDevice() { return 0; } - - // hw: get rid of this - WId windowId() const { return static_cast<WId>(winId()); } - - QScreen *screen() const { return _screen; } - - void beginPaint(const QRegion &); - bool lock(int timeout = -1); - void unlock(); - - void setLocking(bool b) { doLocking = b; } - - bool hasPendingRegionEvents() const; - -private: - QScreen *_screen; -#ifndef QT_NO_THREAD - QMutex threadLock; -#endif - - friend void qt_directpainter_region(QDirectPainter*, const QRegion&, int); - bool flushingRegionEvents; - bool synchronous; - bool doLocking; -}; - -#endif // QT_NO_DIRECTPAINTER - -QT_END_NAMESPACE - -#endif // QWINDOWSURFACE_QWS_P_H diff --git a/src/gui/text/qabstractfontengine_qws.cpp b/src/gui/text/qabstractfontengine_qws.cpp deleted file mode 100644 index 7cb868f655..0000000000 --- a/src/gui/text/qabstractfontengine_qws.cpp +++ /dev/null @@ -1,776 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qabstractfontengine_qws.h" -#include "qabstractfontengine_p.h" - -#include <private/qtextengine_p.h> -#include <private/qpaintengine_raster_p.h> - -#include <qmath.h> - -QT_BEGIN_NAMESPACE - -class QFontEngineInfoPrivate -{ -public: - inline QFontEngineInfoPrivate() - : pixelSize(0), weight(QFont::Normal), style(QFont::StyleNormal) - {} - - QString family; - qreal pixelSize; - int weight; - QFont::Style style; - QList<QFontDatabase::WritingSystem> writingSystems; -}; - -/*! - \class QFontEngineInfo - \preliminary - \brief The QFontEngineInfo class describes a specific font provided by a font engine plugin. - \since 4.3 - \ingroup qws - - \tableofcontents - - QFontEngineInfo is used to describe a request of a font to a font engine plugin as well as to - describe the actual fonts a plugin provides. - - \sa QAbstractFontEngine, QFontEnginePlugin -*/ - -/*! - Constructs a new empty QFontEngineInfo. -*/ -QFontEngineInfo::QFontEngineInfo() -{ - d = new QFontEngineInfoPrivate; -} - -/*! - Constructs a new QFontEngineInfo with the specified \a family. - The resulting object represents a freely scalable font with normal - weight and style. -*/ -QFontEngineInfo::QFontEngineInfo(const QString &family) -{ - d = new QFontEngineInfoPrivate; - d->family = family; -} - -/*! - Creates a new font engine info object with the same attributes as \a other. -*/ -QFontEngineInfo::QFontEngineInfo(const QFontEngineInfo &other) - : d(new QFontEngineInfoPrivate(*other.d)) -{ -} - -/*! - Assigns \a other to this font engine info object, and returns a reference - to this. -*/ -QFontEngineInfo &QFontEngineInfo::operator=(const QFontEngineInfo &other) -{ - *d = *other.d; - return *this; -} - -/*! - Destroys this QFontEngineInfo object. -*/ -QFontEngineInfo::~QFontEngineInfo() -{ - delete d; -} - -/*! - \property QFontEngineInfo::family - the family name of the font -*/ - -void QFontEngineInfo::setFamily(const QString &family) -{ - d->family = family; -} - -QString QFontEngineInfo::family() const -{ - return d->family; -} - -/*! - \property QFontEngineInfo::pixelSize - the pixel size of the font - - A pixel size of 0 represents a freely scalable font. -*/ - -void QFontEngineInfo::setPixelSize(qreal size) -{ - d->pixelSize = size; -} - -qreal QFontEngineInfo::pixelSize() const -{ - return d->pixelSize; -} - -/*! - \property QFontEngineInfo::weight - the weight of the font - - The value should be from the \l{QFont::Weight} enumeration. -*/ - -void QFontEngineInfo::setWeight(int weight) -{ - d->weight = weight; -} - -int QFontEngineInfo::weight() const -{ - return d->weight; -} - -/*! - \property QFontEngineInfo::style - the style of the font -*/ - -void QFontEngineInfo::setStyle(QFont::Style style) -{ - d->style = style; -} - -QFont::Style QFontEngineInfo::style() const -{ - return d->style; -} - -/*! - \property QFontEngineInfo::writingSystems - the writing systems supported by the font - - An empty list means that any writing system is supported. -*/ - -QList<QFontDatabase::WritingSystem> QFontEngineInfo::writingSystems() const -{ - return d->writingSystems; -} - -void QFontEngineInfo::setWritingSystems(const QList<QFontDatabase::WritingSystem> &writingSystems) -{ - d->writingSystems = writingSystems; -} - -class QFontEnginePluginPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QFontEnginePlugin) - - QString foundry; -}; - -/*! - \class QFontEnginePlugin - \preliminary - \brief The QFontEnginePlugin class is the base class for font engine factory plugins in Qt for Embedded Linux. - \since 4.3 - \ingroup qws - \ingroup plugins - - \tableofcontents - - QFontEnginePlugin is provided by font engine plugins to create - instances of subclasses of QAbstractFontEngine. - - The member functions create() and availableFontEngines() must be - implemented. - - \sa QAbstractFontEngine, QFontEngineInfo -*/ - -/*! - Creates a font engine plugin that creates font engines with the - specified \a foundry and \a parent. -*/ -QFontEnginePlugin::QFontEnginePlugin(const QString &foundry, QObject *parent) - : QObject(*new QFontEnginePluginPrivate, parent) -{ - Q_D(QFontEnginePlugin); - d->foundry = foundry; -} - -/*! - Destroys this font engine plugin. -*/ -QFontEnginePlugin::~QFontEnginePlugin() -{ -} - -/*! - Returns a list of foundries the font engine plugin provides. - The default implementation returns the foundry specified with the constructor. -*/ -QStringList QFontEnginePlugin::keys() const -{ - Q_D(const QFontEnginePlugin); - return QStringList(d->foundry); -} - -/*! - \fn QAbstractFontEngine *QFontEnginePlugin::create(const QFontEngineInfo &info) - - Implemented in subclasses to create a new font engine that provides a font that - matches \a info. -*/ - -/*! - \fn QList<QFontEngineInfo> QFontEnginePlugin::availableFontEngines() const - - Implemented in subclasses to return a list of QFontEngineInfo objects that represents all font - engines the plugin can create. -*/ - -class QAbstractFontEnginePrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QAbstractFontEngine) -public: -}; - -//The <classname> class is|provides|contains|specifies... -/*! - \class QAbstractFontEngine - \preliminary - \brief The QAbstractFontEngine class is the base class for font engine plugins in Qt for Embedded Linux. - \since 4.3 - \ingroup qws - - \tableofcontents - - QAbstractFontEngine is implemented by font engine plugins through QFontEnginePlugin. - - \sa QFontEnginePlugin, QFontEngineInfo -*/ - -/*! - \enum QAbstractFontEngine::Capability - - This enum describes the capabilities of a font engine. - - \value CanRenderGlyphs_Gray The font engine can render individual glyphs into 8 bpp images. - \value CanRenderGlyphs_Mono The font engine can render individual glyphs into 1 bpp images. - \value CanRenderGlyphs The font engine can render individual glyphs into images. - \value CanOutlineGlyphs The font engine can convert glyphs to painter paths. -*/ - -/*! - \enum QAbstractFontEngine::FontProperty - - This enum describes the properties of a font provided by a font engine. - - \value Ascent The ascent of the font, specified as a 26.6 fixed point value. - \value Descent The descent of the font, specified as a 26.6 fixed point value. - \value Leading The leading of the font, specified as a 26.6 fixed point value. - \value XHeight The 'x' height of the font, specified as a 26.6 fixed point value. - \value AverageCharWidth The average character width of the font, specified as a 26.6 fixed point value. - \value LineThickness The thickness of the underline and strikeout lines for the font, specified as a 26.6 fixed point value. - \value UnderlinePosition The distance from the base line to the underline position for the font, specified as a 26.6 fixed point value. - \value MaxCharWidth The width of the widest character in the font, specified as a 26.6 fixed point value. - \value MinLeftBearing The minimum left bearing of the font, specified as a 26.6 fixed point value. - \value MinRightBearing The maximum right bearing of the font, specified as a 26.6 fixed point value. - \value GlyphCount The number of glyphs in the font, specified as an integer value. - \value CacheGlyphsHint A boolean value specifying whether rendered glyphs should be cached by Qt. - \value OutlineGlyphsHint A boolean value specifying whether the font engine prefers outline drawing over image rendering for uncached glyphs. -*/ - -/*! - \enum QAbstractFontEngine::TextShapingFlag - - This enum describes flags controlling conversion of characters to glyphs and their metrics. - - \value RightToLeft The text is used in a right-to-left context. - \value ReturnDesignMetrics Return font design metrics instead of pixel metrics. -*/ - -/*! - \typedef QAbstractFontEngine::Fixed - - This type is \c int, interpreted as a 26.6 fixed point value. -*/ - -/*! - \class QAbstractFontEngine::GlyphMetrics - \brief QAbstractFontEngine::GlyphMetrics defines the metrics of a single glyph. - \preliminary - \since 4.3 -*/ - -/*! - \variable QAbstractFontEngine::GlyphMetrics::x - - The horizontal offset from the origin. -*/ - -/*! - \fn QAbstractFontEngine::GlyphMetrics::GlyphMetrics() - - Constructs an empty glyph metrics object with all values - set to zero. -*/ - -/*! - \variable QAbstractFontEngine::GlyphMetrics::y - - The vertical offset from the origin (baseline). -*/ - -/*! - \variable QAbstractFontEngine::GlyphMetrics::width - - The width of the glyph. -*/ - -/*! - \variable QAbstractFontEngine::GlyphMetrics::height - - The height of the glyph. -*/ - -/*! - \variable QAbstractFontEngine::GlyphMetrics::advance - - The advance of the glyph. -*/ - -/*! - \class QAbstractFontEngine::FixedPoint - \brief QAbstractFontEngine::FixedPoint defines a point in the place using 26.6 fixed point precision. - \preliminary - \since 4.3 -*/ - -/*! - \variable QAbstractFontEngine::FixedPoint::x - - The x coordinate of this point. -*/ - -/*! - \variable QAbstractFontEngine::FixedPoint::y - - The y coordinate of this point. -*/ - -/*! - Constructs a new QAbstractFontEngine with the given \a parent. -*/ -QAbstractFontEngine::QAbstractFontEngine(QObject *parent) - : QObject(*new QAbstractFontEnginePrivate, parent) -{ -} - -/*! - Destroys this QAbstractFontEngine object. -*/ -QAbstractFontEngine::~QAbstractFontEngine() -{ -} - -/*! - \fn QAbstractFontEngine::Capabilities QAbstractFontEngine::capabilities() const - - Implemented in subclasses to specify the font engine's capabilities. The return value - may be cached by the caller and is expected not to change during the lifetime of the - font engine. -*/ - -/*! - \fn QVariant QAbstractFontEngine::fontProperty(FontProperty property) const - - Implemented in subclasses to return the value of the font attribute \a property. The return - value may be cached by the caller and is expected not to change during the lifetime of the font - engine. -*/ - -/*! - \fn bool QAbstractFontEngine::convertStringToGlyphIndices(const QChar *string, int length, uint *glyphs, int *numGlyphs, TextShapingFlags flags) const - - Implemented in subclasses to convert the characters specified by \a string and \a length to - glyph indicies, using \a flags. The glyph indicies should be returned in the \a glyphs array - provided by the caller. The maximum size of \a glyphs is specified by the value pointed to by \a - numGlyphs. If successful, the subclass implementation sets the value pointed to by \a numGlyphs - to the actual number of glyph indices generated, and returns true. Otherwise, e.g. if there is - not enough space in the provided \a glyphs array, it should set \a numGlyphs to the number of - glyphs needed for the conversion and return false. -*/ - -/*! - \fn void QAbstractFontEngine::getGlyphAdvances(const uint *glyphs, int numGlyphs, Fixed *advances, TextShapingFlags flags) const - - Implemented in subclasses to retrieve the advances of the array specified by \a glyphs and \a - numGlyphs, using \a flags. The result is returned in \a advances, which is allocated by the - caller and contains \a numGlyphs elements. -*/ - -/*! - \fn QAbstractFontEngine::GlyphMetrics QAbstractFontEngine::glyphMetrics(uint glyph) const - - Implemented in subclass to return the metrics for \a glyph. -*/ - -/*! - Implemented in subclasses to render the specified \a glyph into a \a buffer with the given \a depth , - \a bytesPerLine and \a height. - - Returns true if rendering succeeded, false otherwise. -*/ -bool QAbstractFontEngine::renderGlyph(uint glyph, int depth, int bytesPerLine, int height, uchar *buffer) -{ - Q_UNUSED(glyph) - Q_UNUSED(depth) - Q_UNUSED(bytesPerLine) - Q_UNUSED(height) - Q_UNUSED(buffer) - qWarning("QAbstractFontEngine: renderGlyph is not implemented in font plugin!"); - return false; -} - -/*! - Implemented in subclasses to add the outline of the glyphs specified by \a glyphs and \a - numGlyphs at the specified \a positions to the painter path \a path. -*/ -void QAbstractFontEngine::addGlyphOutlinesToPath(uint *glyphs, int numGlyphs, FixedPoint *positions, QPainterPath *path) -{ - Q_UNUSED(glyphs) - Q_UNUSED(numGlyphs) - Q_UNUSED(positions) - Q_UNUSED(path) - qWarning("QAbstractFontEngine: addGlyphOutlinesToPath is not implemented in font plugin!"); -} - -/* -bool QAbstractFontEngine::supportsExtension(Extension extension) const -{ - Q_UNUSED(extension) - return false; -} - -QVariant QAbstractFontEngine::extension(Extension extension, const QVariant &argument) -{ - Q_UNUSED(argument) - Q_UNUSED(extension) - return QVariant(); -} -*/ - -QProxyFontEngine::QProxyFontEngine(QAbstractFontEngine *customEngine, const QFontDef &def) - : engine(customEngine) -{ - fontDef = def; - engineCapabilities = engine->capabilities(); -} - -QProxyFontEngine::~QProxyFontEngine() -{ - delete engine; -} - -bool QProxyFontEngine::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const -{ - if (*nglyphs < len) { - *nglyphs = len; - return false; - } - - QVarLengthArray<uint> glyphIndicies(*nglyphs); - if (!engine->convertStringToGlyphIndices(str, len, glyphIndicies.data(), nglyphs, QAbstractFontEngine::TextShapingFlags(int(flags)))) - return false; - - // ### use memcopy instead - for (int i = 0; i < *nglyphs; ++i) { - glyphs->glyphs[i] = glyphIndicies[i]; - } - glyphs->numGlyphs = *nglyphs; - - recalcAdvances(glyphs, flags); - return true; -} - -void QProxyFontEngine::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const -{ - const int nglyphs = glyphs->numGlyphs; - - QVarLengthArray<QAbstractFontEngine::Fixed> advances(nglyphs); - engine->getGlyphAdvances(glyphs->glyphs, nglyphs, advances.data(), QAbstractFontEngine::TextShapingFlags(int(flags))); - - - // ### use memcopy instead - for (int i = 0; i < nglyphs; ++i) { - glyphs->advances_x[i] = QFixed::fromFixed(advances[i]); - glyphs->advances_y[i] = 0; - } -} - - -static QImage alphaMapFromPath(QFontEngine *fe, glyph_t glyph) -{ - glyph_metrics_t gm = fe->boundingBox(glyph); - int glyph_x = qFloor(gm.x.toReal()); - int glyph_y = qFloor(gm.y.toReal()); - int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x; - int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y; - - if (glyph_width <= 0 || glyph_height <= 0) - return QImage(); - QFixedPoint pt; - pt.x = 0; - pt.y = -glyph_y; // the baseline - QPainterPath path; - QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied); - im.fill(Qt::transparent); - QPainter p(&im); - p.setRenderHint(QPainter::Antialiasing); - fe->addGlyphsToPath(&glyph, &pt, 1, &path, 0); - p.setPen(Qt::NoPen); - p.setBrush(Qt::black); - p.drawPath(path); - p.end(); - - QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); - QVector<QRgb> colors(256); - for (int i=0; i<256; ++i) - colors[i] = qRgba(0, 0, 0, i); - indexed.setColorTable(colors); - - for (int y=0; y<im.height(); ++y) { - uchar *dst = (uchar *) indexed.scanLine(y); - uint *src = (uint *) im.scanLine(y); - for (int x=0; x<im.width(); ++x) - dst[x] = qAlpha(src[x]); - } - - return indexed; -} - - -QImage QProxyFontEngine::alphaMapForGlyph(glyph_t glyph) -{ - if (!(engineCapabilities & QAbstractFontEngine::CanRenderGlyphs_Gray)) - return alphaMapFromPath(this, glyph); - - QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyph); - if (metrics.width <= 0 || metrics.height <= 0) - return QImage(); - - QImage img(metrics.width >> 6, metrics.height >> 6, QImage::Format_Indexed8); - - // ### we should have QImage::Format_GrayScale8 - static QVector<QRgb> colorMap; - if (colorMap.isEmpty()) { - colorMap.resize(256); - for (int i=0; i<256; ++i) - colorMap[i] = qRgba(0, 0, 0, i); - } - - img.setColorTable(colorMap); - - engine->renderGlyph(glyph, /*depth*/8, img.bytesPerLine(), img.height(), img.bits()); - - return img; -} - -void QProxyFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags) -{ - if (engineCapabilities & QAbstractFontEngine::CanOutlineGlyphs) - engine->addGlyphOutlinesToPath(glyphs, nglyphs, reinterpret_cast<QAbstractFontEngine::FixedPoint *>(positions), path); - else - QFontEngine::addGlyphsToPath(glyphs, positions, nglyphs, path, flags); -} - -glyph_metrics_t QProxyFontEngine::boundingBox(const QGlyphLayout &glyphs) -{ - if (glyphs.numGlyphs == 0) - return glyph_metrics_t(); - - QFixed w = 0; - for (int i = 0; i < glyphs.numGlyphs; ++i) - w += glyphs.effectiveAdvance(i); - - return glyph_metrics_t(0, -ascent(), w, ascent() + descent(), w, 0); -} - -glyph_metrics_t QProxyFontEngine::boundingBox(glyph_t glyph) -{ - glyph_metrics_t m; - - QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyph); - m.x = QFixed::fromFixed(metrics.x); - m.y = QFixed::fromFixed(metrics.y); - m.width = QFixed::fromFixed(metrics.width); - m.height = QFixed::fromFixed(metrics.height); - m.xoff = QFixed::fromFixed(metrics.advance); - - return m; -} - -QFixed QProxyFontEngine::ascent() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Ascent).toInt()); -} - -QFixed QProxyFontEngine::descent() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Descent).toInt()); -} - -QFixed QProxyFontEngine::leading() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::Leading).toInt()); -} - -QFixed QProxyFontEngine::xHeight() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::XHeight).toInt()); -} - -QFixed QProxyFontEngine::averageCharWidth() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::AverageCharWidth).toInt()); -} - -QFixed QProxyFontEngine::lineThickness() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::LineThickness).toInt()); -} - -QFixed QProxyFontEngine::underlinePosition() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::UnderlinePosition).toInt()); -} - -qreal QProxyFontEngine::maxCharWidth() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MaxCharWidth).toInt()).toReal(); -} - -qreal QProxyFontEngine::minLeftBearing() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MinLeftBearing).toInt()).toReal(); -} - -qreal QProxyFontEngine::minRightBearing() const -{ - return QFixed::fromFixed(engine->fontProperty(QAbstractFontEngine::MinRightBearing).toInt()).toReal(); -} - -int QProxyFontEngine::glyphCount() const -{ - return engine->fontProperty(QAbstractFontEngine::GlyphCount).toInt(); -} - -bool QProxyFontEngine::canRender(const QChar *string, int len) -{ - QVarLengthArray<uint> glyphs(len); - int numGlyphs = len; - - if (!engine->convertStringToGlyphIndices(string, len, glyphs.data(), &numGlyphs, /*flags*/0)) - return false; - - for (int i = 0; i < numGlyphs; ++i) - if (!glyphs[i]) - return false; - - return true; -} - -void QProxyFontEngine::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemInt &si) -{ - QPaintEngineState *pState = p->state; - QRasterPaintEngine *paintEngine = static_cast<QRasterPaintEngine*>(p); - - QTransform matrix = pState->transform(); - matrix.translate(_x, _y); - QFixed x = QFixed::fromReal(matrix.dx()); - QFixed y = QFixed::fromReal(matrix.dy()); - - QVarLengthArray<QFixedPoint> positions; - QVarLengthArray<glyph_t> glyphs; - getGlyphPositions(si.glyphs, matrix, si.flags, glyphs, positions); - if (glyphs.size() == 0) - return; - - for(int i = 0; i < glyphs.size(); i++) { - QImage glyph = alphaMapForGlyph(glyphs[i]); - if (glyph.isNull()) - continue; - - if (glyph.format() != QImage::Format_Indexed8 - && glyph.format() != QImage::Format_Mono) - continue; - - QAbstractFontEngine::GlyphMetrics metrics = engine->glyphMetrics(glyphs[i]); - - int depth = glyph.format() == QImage::Format_Mono ? 1 : 8; - paintEngine->alphaPenBlt(glyph.bits(), glyph.bytesPerLine(), depth, - qRound(positions[i].x + QFixed::fromFixed(metrics.x)), - qRound(positions[i].y + QFixed::fromFixed(metrics.y)), - glyph.width(), glyph.height()); - } -} - -/* - * This is only called when we use the proxy fontengine directly (without sharing the rendered - * glyphs). So we prefer outline rendering over rendering of unshared glyphs. That decision is - * done in qfontdatabase_qws.cpp by looking at the ShareGlyphsHint and the pixel size of the font. - */ -bool QProxyFontEngine::drawAsOutline() const -{ - if (!(engineCapabilities & QAbstractFontEngine::CanOutlineGlyphs)) - return false; - - QVariant outlineHint = engine->fontProperty(QAbstractFontEngine::OutlineGlyphsHint); - return !outlineHint.isValid() || outlineHint.toBool(); -} - -QT_END_NAMESPACE diff --git a/src/gui/text/qabstractfontengine_qws.h b/src/gui/text/qabstractfontengine_qws.h deleted file mode 100644 index dfc15dcf5d..0000000000 --- a/src/gui/text/qabstractfontengine_qws.h +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTFONTENGINE_QWS_H -#define QABSTRACTFONTENGINE_QWS_H - -#include <QtCore/qobject.h> -#include <QtCore/qhash.h> -#include <QtCore/qvariant.h> -#include <QtCore/qfactoryinterface.h> -#include <QtGui/qpaintengine.h> -#include <QtGui/qfontdatabase.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QFontEngineInfoPrivate; - -class Q_GUI_EXPORT QFontEngineInfo -{ -public: - QDOC_PROPERTY(QString family READ family WRITE setFamily) - QDOC_PROPERTY(qreal pixelSize READ pixelSize WRITE setPixelSize) - QDOC_PROPERTY(int weight READ weight WRITE setWeight) - QDOC_PROPERTY(QFont::Style style READ style WRITE setStyle) - QDOC_PROPERTY(QList<QFontDatabase::WritingSystem> writingSystems READ writingSystems WRITE setWritingSystems) - - QFontEngineInfo(); - explicit QFontEngineInfo(const QString &family); - QFontEngineInfo(const QFontEngineInfo &other); - QFontEngineInfo &operator=(const QFontEngineInfo &other); - ~QFontEngineInfo(); - - void setFamily(const QString &name); - QString family() const; - - void setPixelSize(qreal size); - qreal pixelSize() const; - - void setWeight(int weight); - int weight() const; - - void setStyle(QFont::Style style); - QFont::Style style() const; - - QList<QFontDatabase::WritingSystem> writingSystems() const; - void setWritingSystems(const QList<QFontDatabase::WritingSystem> &writingSystems); - -private: - QFontEngineInfoPrivate *d; -}; - -class QAbstractFontEngine; - -struct Q_GUI_EXPORT QFontEngineFactoryInterface : public QFactoryInterface -{ - virtual QAbstractFontEngine *create(const QFontEngineInfo &info) = 0; - virtual QList<QFontEngineInfo> availableFontEngines() const = 0; -}; - -#define QFontEngineFactoryInterface_iid "com.trolltech.Qt.QFontEngineFactoryInterface" -Q_DECLARE_INTERFACE(QFontEngineFactoryInterface, QFontEngineFactoryInterface_iid) - -class QFontEnginePluginPrivate; - -class Q_GUI_EXPORT QFontEnginePlugin : public QObject, public QFontEngineFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QFontEngineFactoryInterface:QFactoryInterface) -public: - QFontEnginePlugin(const QString &foundry, QObject *parent = 0); - ~QFontEnginePlugin(); - - virtual QStringList keys() const; - - virtual QAbstractFontEngine *create(const QFontEngineInfo &info) = 0; - virtual QList<QFontEngineInfo> availableFontEngines() const = 0; - -private: - Q_DECLARE_PRIVATE(QFontEnginePlugin) - Q_DISABLE_COPY(QFontEnginePlugin) -}; - -class QAbstractFontEnginePrivate; - -class Q_GUI_EXPORT QAbstractFontEngine : public QObject -{ - Q_OBJECT -public: - enum Capability { - CanOutlineGlyphs = 1, - CanRenderGlyphs_Mono = 2, - CanRenderGlyphs_Gray = 4, - CanRenderGlyphs = CanRenderGlyphs_Mono | CanRenderGlyphs_Gray - }; - Q_DECLARE_FLAGS(Capabilities, Capability) - - explicit QAbstractFontEngine(QObject *parent = 0); - ~QAbstractFontEngine(); - - typedef int Fixed; // 26.6 - - struct FixedPoint - { - Fixed x; - Fixed y; - }; - - struct GlyphMetrics - { - inline GlyphMetrics() - : x(0), y(0), width(0), height(0), - advance(0) {} - Fixed x; - Fixed y; - Fixed width; - Fixed height; - Fixed advance; - }; - - enum FontProperty { - Ascent, - Descent, - Leading, - XHeight, - AverageCharWidth, - LineThickness, - UnderlinePosition, - MaxCharWidth, - MinLeftBearing, - MinRightBearing, - GlyphCount, - - // hints - CacheGlyphsHint, - OutlineGlyphsHint - }; - - // keep in sync with QTextEngine::ShaperFlag!! - enum TextShapingFlag { - RightToLeft = 0x0001, - ReturnDesignMetrics = 0x0002 - }; - Q_DECLARE_FLAGS(TextShapingFlags, TextShapingFlag) - - virtual Capabilities capabilities() const = 0; - virtual QVariant fontProperty(FontProperty property) const = 0; - - virtual bool convertStringToGlyphIndices(const QChar *string, int length, uint *glyphs, int *numGlyphs, TextShapingFlags flags) const = 0; - - virtual void getGlyphAdvances(const uint *glyphs, int numGlyphs, Fixed *advances, TextShapingFlags flags) const = 0; - - virtual GlyphMetrics glyphMetrics(uint glyph) const = 0; - - virtual bool renderGlyph(uint glyph, int depth, int bytesPerLine, int height, uchar *buffer); - - virtual void addGlyphOutlinesToPath(uint *glyphs, int numGlyphs, FixedPoint *positions, QPainterPath *path); - - /* - enum Extension { - GetTrueTypeTable - }; - - virtual bool supportsExtension(Extension extension) const; - virtual QVariant extension(Extension extension, const QVariant &argument = QVariant()); - */ - -private: - Q_DECLARE_PRIVATE(QAbstractFontEngine) - Q_DISABLE_COPY(QAbstractFontEngine) -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFontEngine::Capabilities) -Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFontEngine::TextShapingFlags) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/gui/text/qfont_qws.cpp b/src/gui/text/qfont_qws.cpp deleted file mode 100644 index ea2a944432..0000000000 --- a/src/gui/text/qfont_qws.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwidget.h" -#include "qpainter.h" -#include "qfont_p.h" -#include <private/qunicodetables_p.h> -#include "qfontdatabase.h" -#include "qtextcodec.h" -#include "qapplication.h" -#include "qfile.h" -#include "qtextstream.h" -#include "qmap.h" -//#include "qmemorymanager_qws.h" -#include "qtextengine_p.h" -#include "qfontengine_p.h" -#if !defined(QT_NO_FREETYPE) -#include "qfontengine_ft_p.h" -#endif - -QT_BEGIN_NAMESPACE - -void QFont::initialize() -{ } - -void QFont::cleanup() -{ - QFontCache::cleanup(); -} - - -/***************************************************************************** - QFont member functions - *****************************************************************************/ - -Qt::HANDLE QFont::handle() const -{ -#ifndef QT_NO_FREETYPE - return freetypeFace(); -#endif - return 0; -} - -FT_Face QFont::freetypeFace() const -{ -#ifndef QT_NO_FREETYPE - QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); - if (engine->type() == QFontEngine::Multi) - engine = static_cast<QFontEngineMulti *>(engine)->engine(0); - if (engine->type() == QFontEngine::Freetype) { - const QFontEngineFT *ft = static_cast<const QFontEngineFT *>(engine); - return ft->non_locked_face(); - } -#endif - return 0; -} - -QString QFont::rawName() const -{ - return QLatin1String("unknown"); -} - -void QFont::setRawName(const QString &) -{ -} - -QString QFont::defaultFamily() const -{ - switch(d->request.styleHint) { - case QFont::Times: - return QString::fromLatin1("times"); - case QFont::Courier: - case QFont::Monospace: - return QString::fromLatin1("courier"); - case QFont::Decorative: - return QString::fromLatin1("old english"); - case QFont::Helvetica: - case QFont::System: - default: - return QString::fromLatin1("helvetica"); - } -} - -QString QFont::lastResortFamily() const -{ - return QString::fromLatin1("helvetica"); -} - -QString QFont::lastResortFont() const -{ - qFatal("QFont::lastResortFont: Cannot find any reasonable font"); - // Shut compiler up - return QString(); -} - - -QT_END_NAMESPACE diff --git a/src/gui/text/qfontdatabase_qws.cpp b/src/gui/text/qfontdatabase_qws.cpp deleted file mode 100644 index d076de05d3..0000000000 --- a/src/gui/text/qfontdatabase_qws.cpp +++ /dev/null @@ -1,975 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdir.h" -#if defined(Q_WS_QWS) -#include "qscreen_qws.h" //so we can check for rotation -#include "qwindowsystem_qws.h" -#endif -#include "qlibraryinfo.h" -#include "qabstractfileengine.h" -#include <QtCore/qsettings.h> -#if !defined(QT_NO_FREETYPE) -#include "qfontengine_ft_p.h" - -#include <ft2build.h> -#include FT_FREETYPE_H - -#endif -#include "qfontengine_qpf_p.h" -#include "private/qfactoryloader_p.h" -#include "private/qcore_unix_p.h" // overrides QT_OPEN -#include "qabstractfontengine_qws.h" -#include "qabstractfontengine_p.h" -#include <qdatetime.h> -#include "qplatformdefs.h" - -// for mmap -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <errno.h> - -#ifdef QT_FONTS_ARE_RESOURCES -#include <qresource.h> -#endif - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_LIBRARY -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QFontEngineFactoryInterface_iid, QLatin1String("/fontengines"), Qt::CaseInsensitive)) -#endif - -const quint8 DatabaseVersion = 4; - -// QFontDatabasePrivate::addFont() went into qfontdatabase.cpp - -#ifndef QT_NO_QWS_QPF2 -void QFontDatabasePrivate::addQPF2File(const QByteArray &file) -{ -#ifndef QT_FONTS_ARE_RESOURCES - struct stat st; - if (stat(file.constData(), &st)) - return; - int f = QT_OPEN(file, O_RDONLY, 0); - if (f < 0) - return; - const uchar *data = (const uchar *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0); - const int dataSize = st.st_size; -#else - QResource res(QLatin1String(file.constData())); - const uchar *data = res.data(); - const int dataSize = res.size(); - //qDebug() << "addQPF2File" << file << data; -#endif - if (data && data != (const uchar *)MAP_FAILED) { - if (QFontEngineQPF::verifyHeader(data, dataSize)) { - QString fontName = QFontEngineQPF::extractHeaderField(data, QFontEngineQPF::Tag_FontName).toString(); - int pixelSize = QFontEngineQPF::extractHeaderField(data, QFontEngineQPF::Tag_PixelSize).toInt(); - QVariant weight = QFontEngineQPF::extractHeaderField(data, QFontEngineQPF::Tag_Weight); - QVariant style = QFontEngineQPF::extractHeaderField(data, QFontEngineQPF::Tag_Style); - QByteArray writingSystemBits = QFontEngineQPF::extractHeaderField(data, QFontEngineQPF::Tag_WritingSystems).toByteArray(); - - if (!fontName.isEmpty() && pixelSize) { - int fontWeight = 50; - if (weight.type() == QVariant::Int || weight.type() == QVariant::UInt) - fontWeight = weight.toInt(); - - bool italic = static_cast<QFont::Style>(style.toInt()) & QFont::StyleItalic; - - QList<QFontDatabase::WritingSystem> writingSystems; - for (int i = 0; i < writingSystemBits.count(); ++i) { - uchar currentByte = writingSystemBits.at(i); - for (int j = 0; j < 8; ++j) { - if (currentByte & 1) - writingSystems << QFontDatabase::WritingSystem(i * 8 + j); - currentByte >>= 1; - } - } - - addFont(fontName, /*foundry*/ "prerendered", fontWeight, italic, - pixelSize, file, /*fileIndex*/ 0, - /*antialiased*/ true, writingSystems); - } - } else { - qDebug() << "header verification of QPF2 font" << file << "failed. maybe it is corrupt?"; - } -#ifndef QT_FONTS_ARE_RESOURCES - munmap((void *)data, st.st_size); -#endif - } -#ifndef QT_FONTS_ARE_RESOURCES - QT_CLOSE(f); -#endif -} -#endif // QT_NO_QWS_QPF2 - -// QFontDatabasePrivate::addTTFile() went into qfontdatabase.cpp - -static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt); - -extern QString qws_fontCacheDir(); - -#ifndef QT_FONTS_ARE_RESOURCES -bool QFontDatabasePrivate::loadFromCache(const QString &fontPath) -{ -#ifdef Q_WS_QWS - const bool weAreTheServer = QWSServer::instance(); -#else - const bool weAreTheServer = true; // assume single-process -#endif - - QString fontDirFile = fontPath + QLatin1String("/fontdir"); - - QFile binaryDb(qws_fontCacheDir() + QLatin1String("/fontdb")); - - if (weAreTheServer) { - QDateTime dbTimeStamp = QFileInfo(binaryDb.fileName()).lastModified(); - - QDateTime fontPathTimeStamp = QFileInfo(fontPath).lastModified(); - if (dbTimeStamp < fontPathTimeStamp) - return false; // let the caller create the cache - - if (QFile::exists(fontDirFile)) { - QDateTime fontDirTimeStamp = QFileInfo(fontDirFile).lastModified(); - if (dbTimeStamp < fontDirTimeStamp) - return false; - } - } - - if (!binaryDb.open(QIODevice::ReadOnly)) { - if (weAreTheServer) - return false; // let the caller create the cache - qFatal("QFontDatabase::loadFromCache: Could not open font database cache!"); - } - - QDataStream stream(&binaryDb); - quint8 version = 0; - quint8 dataStreamVersion = 0; - stream >> version >> dataStreamVersion; - if (version != DatabaseVersion || dataStreamVersion != stream.version()) { - if (weAreTheServer) - return false; // let the caller create the cache - qFatal("QFontDatabase::loadFromCache: Wrong version of the font database cache detected. Found %d/%d expected %d/%d", - version, dataStreamVersion, DatabaseVersion, stream.version()); - } - - QString originalFontPath; - stream >> originalFontPath; - if (originalFontPath != fontPath) { - if (weAreTheServer) - return false; // let the caller create the cache - qFatal("QFontDatabase::loadFromCache: Font path doesn't match. Found %s in database, expected %s", qPrintable(originalFontPath), qPrintable(fontPath)); - } - - QString familyname; - stream >> familyname; - //qDebug() << "populating database from" << binaryDb.fileName(); - while (!familyname.isEmpty() && !stream.atEnd()) { - QString foundryname; - int weight; - quint8 italic; - int pixelSize; - QByteArray file; - int fileIndex; - quint8 antialiased; - quint8 writingSystemCount; - - QList<QFontDatabase::WritingSystem> writingSystems; - - stream >> foundryname >> weight >> italic >> pixelSize - >> file >> fileIndex >> antialiased >> writingSystemCount; - - for (quint8 i = 0; i < writingSystemCount; ++i) { - quint8 ws; - stream >> ws; - writingSystems.append(QFontDatabase::WritingSystem(ws)); - } - - addFont(familyname, foundryname.toLatin1().constData(), weight, italic, pixelSize, file, fileIndex, antialiased, - writingSystems); - - stream >> familyname; - } - - stream >> fallbackFamilies; - //qDebug() << "fallback families from cache:" << fallbackFamilies; - return true; -} -#endif // QT_FONTS_ARE_RESOURCES - -/*! - \internal -*/ - -static QString qwsFontPath() -{ - QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QWS_FONTDIR")); - if (fontpath.isEmpty()) { -#ifdef QT_FONTS_ARE_RESOURCES - fontpath = QLatin1String(":/qt/fonts"); -#else -#ifndef QT_NO_SETTINGS - fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath); - fontpath += QLatin1String("/fonts"); -#else - fontpath = QLatin1String("/lib/fonts"); -#endif -#endif //QT_FONTS_ARE_RESOURCES - } - - return fontpath; -} - -#if defined(QFONTDATABASE_DEBUG) && defined(QT_FONTS_ARE_RESOURCES) -class FriendlyResource : public QResource -{ -public: - bool isDir () const { return QResource::isDir(); } - bool isFile () const { return QResource::isFile(); } - QStringList children () const { return QResource::children(); } -}; -#endif -/*! - \internal -*/ -static void initializeDb() -{ - QFontDatabasePrivate *db = privateDb(); - if (!db || db->count) - return; - - QString fontpath = qwsFontPath(); -#ifndef QT_FONTS_ARE_RESOURCES - QString fontDirFile = fontpath + QLatin1String("/fontdir"); - - if(!QFile::exists(fontpath)) { - qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", - fontpath.toLocal8Bit().constData()); - } - - const bool loaded = db->loadFromCache(fontpath); - - if (db->reregisterAppFonts) { - db->reregisterAppFonts = false; - for (int i = 0; i < db->applicationFonts.count(); ++i) - if (!db->applicationFonts.at(i).families.isEmpty()) { - registerFont(&db->applicationFonts[i]); - } - } - - if (loaded) - return; - - QString dbFileName = qws_fontCacheDir() + QLatin1String("/fontdb"); - - QFile binaryDb(dbFileName + QLatin1String(".tmp")); - binaryDb.open(QIODevice::WriteOnly | QIODevice::Truncate); - db->stream = new QDataStream(&binaryDb); - *db->stream << DatabaseVersion << quint8(db->stream->version()) << fontpath; -// qDebug() << "creating binary database at" << binaryDb.fileName(); - - // Load in font definition file - FILE* fontdef=fopen(fontDirFile.toLocal8Bit().constData(),"r"); - if (fontdef) { - char buf[200]=""; - char name[200]=""; - char render[200]=""; - char file[200]=""; - char isitalic[10]=""; - char flags[10]=""; - do { - fgets(buf,200,fontdef); - if (buf[0] != '#') { - int weight=50; - int size=0; - sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); - QString filename; - if (file[0] != '/') - filename.append(fontpath).append(QLatin1Char('/')); - filename += QLatin1String(file); - bool italic = isitalic[0] == 'y'; - bool smooth = QByteArray(flags).contains('s'); - if (file[0] && QFile::exists(filename)) - db->addFont(QString::fromUtf8(name), /*foundry*/"", weight, italic, size/10, QFile::encodeName(filename), /*fileIndex*/ 0, smooth); - } - } while (!feof(fontdef)); - fclose(fontdef); - } - - - QDir dir(fontpath, QLatin1String("*.qpf")); - for (int i=0; i<int(dir.count()); i++) { - int u0 = dir[i].indexOf(QLatin1Char('_')); - int u1 = dir[i].indexOf(QLatin1Char('_'), u0+1); - int u2 = dir[i].indexOf(QLatin1Char('_'), u1+1); - int u3 = dir[i].indexOf(QLatin1Char('.'), u1+1); - if (u2 < 0) u2 = u3; - - QString familyname = dir[i].left(u0); - int pixelSize = dir[i].mid(u0+1,u1-u0-1).toInt()/10; - bool italic = dir[i].mid(u2-1,1) == QLatin1String("i"); - int weight = dir[i].mid(u1+1,u2-u1-1-(italic?1:0)).toInt(); - - db->addFont(familyname, /*foundry*/ "qt", weight, italic, pixelSize, QFile::encodeName(dir.absoluteFilePath(dir[i])), - /*fileIndex*/ 0, /*antialiased*/ true); - } - -#ifndef QT_NO_FREETYPE - dir.setNameFilters(QStringList() << QLatin1String("*.ttf") - << QLatin1String("*.ttc") << QLatin1String("*.pfa") - << QLatin1String("*.pfb")); - dir.refresh(); - for (int i = 0; i < int(dir.count()); ++i) { - const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); -// qDebug() << "looking at" << file; - db->addTTFile(file); - } -#endif - -#ifndef QT_NO_QWS_QPF2 - dir.setNameFilters(QStringList() << QLatin1String("*.qpf2")); - dir.refresh(); - for (int i = 0; i < int(dir.count()); ++i) { - const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); -// qDebug() << "looking at" << file; - db->addQPF2File(file); - } -#endif - -#else //QT_FONTS_ARE_RESOURCES -#ifdef QFONTDATABASE_DEBUG - { - QResource fontdir(fontpath); - FriendlyResource *fr = static_cast<FriendlyResource*>(&fontdir); - qDebug() << "fontdir" << fr->isValid() << fr->isDir() << fr->children(); - - } -#endif -#ifndef QT_NO_QWS_QPF2 - QDir dir(fontpath, QLatin1String("*.qpf2")); - for (int i = 0; i < int(dir.count()); ++i) { - const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); - //qDebug() << "looking at" << file; - db->addQPF2File(file); - } -#endif -#endif //QT_FONTS_ARE_RESOURCES - - -#ifdef QFONTDATABASE_DEBUG - // print the database - for (int f = 0; f < db->count; f++) { - QtFontFamily *family = db->families[f]; - FD_DEBUG("'%s' %s", qPrintable(family->name), (family->fixedPitch ? "fixed" : "")); -#if 0 - for (int i = 0; i < QFont::LastPrivateScript; ++i) { - FD_DEBUG("\t%s: %s", qPrintable(QFontDatabase::scriptName((QFont::Script) i)), - ((family->scripts[i] & QtFontFamily::Supported) ? "Supported" : - (family->scripts[i] & QtFontFamily::UnSupported) == QtFontFamily::UnSupported ? - "UnSupported" : "Unknown")); - } -#endif - - for (int fd = 0; fd < family->count; fd++) { - QtFontFoundry *foundry = family->foundries[fd]; - FD_DEBUG("\t\t'%s'", qPrintable(foundry->name)); - for (int s = 0; s < foundry->count; s++) { - QtFontStyle *style = foundry->styles[s]; - FD_DEBUG("\t\t\tstyle: style=%d weight=%d\n" - "\t\t\tstretch=%d", - style->key.style, style->key.weight, - style->key.stretch); - if (style->smoothScalable) - FD_DEBUG("\t\t\t\tsmooth scalable"); - else if (style->bitmapScalable) - FD_DEBUG("\t\t\t\tbitmap scalable"); - if (style->pixelSizes) { - FD_DEBUG("\t\t\t\t%d pixel sizes", style->count); - for (int z = 0; z < style->count; ++z) { - QtFontSize *size = style->pixelSizes + z; - FD_DEBUG("\t\t\t\t size %5d", - size->pixelSize); - } - } - } - } - } -#endif // QFONTDATABASE_DEBUG - -#ifndef QT_NO_LIBRARY - QStringList pluginFoundries = loader()->keys(); -// qDebug() << "plugin foundries:" << pluginFoundries; - for (int i = 0; i < pluginFoundries.count(); ++i) { - const QString foundry(pluginFoundries.at(i)); - - QFontEngineFactoryInterface *factory = qobject_cast<QFontEngineFactoryInterface *>(loader()->instance(foundry)); - if (!factory) { - qDebug() << "Could not load plugin for foundry" << foundry; - continue; - } - - QList<QFontEngineInfo> fonts = factory->availableFontEngines(); - for (int i = 0; i < fonts.count(); ++i) { - QFontEngineInfo info = fonts.at(i); - - int weight = info.weight(); - if (weight <= 0) - weight = QFont::Normal; - - db->addFont(info.family(), foundry.toLatin1().constData(), - weight, info.style() != QFont::StyleNormal, - qRound(info.pixelSize()), /*file*/QByteArray(), - /*fileIndex*/0, /*antiAliased*/true, - info.writingSystems()); - } - } -#endif - -#ifndef QT_FONTS_ARE_RESOURCES - // the empty string/familyname signifies the end of the font list. - *db->stream << QString(); -#endif - { - bool coveredWritingSystems[QFontDatabase::WritingSystemsCount] = { 0 }; - - db->fallbackFamilies.clear(); - - for (int i = 0; i < db->count; ++i) { - QtFontFamily *family = db->families[i]; - bool add = false; - if (family->count == 0) - continue; - if (family->bogusWritingSystems) - continue; - for (int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) { - if (coveredWritingSystems[ws]) - continue; - if (family->writingSystems[ws] & QtFontFamily::Supported) { - coveredWritingSystems[ws] = true; - add = true; - } - } - if (add) - db->fallbackFamilies << family->name; - } - //qDebug() << "fallbacks on the server:" << db->fallbackFamilies; -#ifndef QT_FONTS_ARE_RESOURCES - *db->stream << db->fallbackFamilies; -#endif - } -#ifndef QT_FONTS_ARE_RESOURCES - delete db->stream; - db->stream = 0; - QFile::remove(dbFileName); - binaryDb.rename(dbFileName); -#endif -} - -// called from qwindowsystem_qws.cpp -void qt_qws_init_fontdb() -{ - initializeDb(); -} - -#ifndef QT_NO_SETTINGS -// called from qapplication_qws.cpp -void qt_applyFontDatabaseSettings(const QSettings &settings) -{ - initializeDb(); - QFontDatabasePrivate *db = privateDb(); - for (int i = 0; i < db->count; ++i) { - QtFontFamily *family = db->families[i]; - if (settings.contains(family->name)) - family->fallbackFamilies = settings.value(family->name).toStringList(); - } - - if (settings.contains(QLatin1String("Global Fallbacks"))) - db->fallbackFamilies = settings.value(QLatin1String("Global Fallbacks")).toStringList(); -} -#endif // QT_NO_SETTINGS - -static inline void load(const QString & = QString(), int = -1) -{ - initializeDb(); -} - -#ifndef QT_NO_FREETYPE - -#if (FREETYPE_MAJOR*10000+FREETYPE_MINOR*100+FREETYPE_PATCH) >= 20105 -#define X_SIZE(face,i) ((face)->available_sizes[i].x_ppem) -#define Y_SIZE(face,i) ((face)->available_sizes[i].y_ppem) -#else -#define X_SIZE(face,i) ((face)->available_sizes[i].width << 6) -#define Y_SIZE(face,i) ((face)->available_sizes[i].height << 6) -#endif - -#endif // QT_NO_FREETYPE - -static -QFontEngine *loadSingleEngine(int script, const QFontPrivate *fp, - const QFontDef &request, - QtFontFamily *family, QtFontFoundry *foundry, - QtFontStyle *style, QtFontSize *size) -{ - Q_UNUSED(script); - Q_UNUSED(fp); -#ifdef QT_NO_FREETYPE - Q_UNUSED(foundry); -#endif -#ifdef QT_NO_QWS_QPF - Q_UNUSED(family); -#endif - Q_ASSERT(size); - - int pixelSize = size->pixelSize; - if (!pixelSize || (style->smoothScalable && pixelSize == SMOOTH_SCALABLE)) - pixelSize = request.pixelSize; - -#ifndef QT_NO_QWS_QPF2 - if (foundry->name == QLatin1String("prerendered")) { -#ifdef QT_FONTS_ARE_RESOURCES - QResource res(QLatin1String(size->fileName.constData())); - if (res.isValid()) { - QFontEngineQPF *fe = new QFontEngineQPF(request, res.data(), res.size()); - if (fe->isValid()) - return fe; - delete fe; - qDebug() << "fontengine is not valid! " << size->fileName; - } else { - qDebug() << "Resource not valid" << size->fileName; - } -#else - int f = ::open(size->fileName, O_RDONLY, 0); - if (f >= 0) { - QFontEngineQPF *fe = new QFontEngineQPF(request, f); - if (fe->isValid()) - return fe; - delete fe; // will close f - qDebug() << "fontengine is not valid!"; - } -#endif - } else -#endif - if ( foundry->name != QLatin1String("qt") ) { ///#### is this the best way???? - QString file = QFile::decodeName(size->fileName); - - QFontDef def = request; - def.pixelSize = pixelSize; - -#ifdef QT_NO_QWS_SHARE_FONTS - bool shareFonts = false; -#else - static bool dontShareFonts = !qgetenv("QWS_NO_SHARE_FONTS").isEmpty(); - bool shareFonts = !dontShareFonts; -#endif - - QScopedPointer<QFontEngine> engine; - -#ifndef QT_NO_LIBRARY - QFontEngineFactoryInterface *factory = qobject_cast<QFontEngineFactoryInterface *>(loader()->instance(foundry->name)); - if (factory) { - QFontEngineInfo info; - info.setFamily(request.family); - info.setPixelSize(request.pixelSize); - info.setStyle(QFont::Style(request.style)); - info.setWeight(request.weight); - // #### antialiased - - QAbstractFontEngine *customEngine = factory->create(info); - if (customEngine) { - engine.reset(new QProxyFontEngine(customEngine, def)); - - if (shareFonts) { - QVariant hint = customEngine->fontProperty(QAbstractFontEngine::CacheGlyphsHint); - if (hint.isValid()) - shareFonts = hint.toBool(); - else - shareFonts = (pixelSize < 64); - } - } - } -#endif // QT_NO_LIBRARY - if ((engine.isNull() && !file.isEmpty() && QFile::exists(file)) || privateDb()->isApplicationFont(file)) { - QFontEngine::FaceId faceId; - faceId.filename = file.toLocal8Bit(); - faceId.index = size->fileIndex; - -#ifndef QT_NO_FREETYPE - - QScopedPointer<QFontEngineFT> fte(new QFontEngineFT(def)); - bool antialias = style->antialiased && !(request.styleStrategy & QFont::NoAntialias); - if (fte->init(faceId, antialias, - antialias ? QFontEngineFT::Format_A8 : QFontEngineFT::Format_Mono)) { -#ifdef QT_NO_QWS_QPF2 - return fte.take(); -#else - // try to distinguish between bdf and ttf fonts we can pre-render - // and don't try to share outline fonts - shareFonts = shareFonts - && !fte->defaultGlyphs()->outline_drawing - && !fte->getSfntTable(MAKE_TAG('h', 'e', 'a', 'd')).isEmpty(); - engine.reset(fte.take()); -#endif - } -#endif // QT_NO_FREETYPE - } - if (!engine.isNull()) { -#if !defined(QT_NO_QWS_QPF2) && !defined(QT_FONTS_ARE_RESOURCES) - if (shareFonts) { - QScopedPointer<QFontEngineQPF> fe(new QFontEngineQPF(def, -1, engine.data())); - engine.take(); - if (fe->isValid()) - return fe.take(); - qWarning("Initializing QFontEngineQPF failed for %s", qPrintable(file)); - engine.reset(fe->takeRenderingEngine()); - } -#endif - return engine.take(); - } - } else - { -#ifndef QT_NO_QWS_QPF - QString fn = qwsFontPath(); - fn += QLatin1Char('/'); - fn += family->name.toLower() - + QLatin1Char('_') + QString::number(pixelSize*10) - + QLatin1Char('_') + QString::number(style->key.weight) - + (style->key.style == QFont::StyleItalic ? - QLatin1String("i.qpf") : QLatin1String(".qpf")); - //###rotation ### - - QFontEngine *fe = new QFontEngineQPF1(request, fn); - return fe; -#endif // QT_NO_QWS_QPF - } - return new QFontEngineBox(pixelSize); -} - -static -QFontEngine *loadEngine(int script, const QFontPrivate *fp, - const QFontDef &request, - QtFontFamily *family, QtFontFoundry *foundry, - QtFontStyle *style, QtFontSize *size) -{ - QScopedPointer<QFontEngine> engine(loadSingleEngine(script, fp, request, family, foundry, - style, size)); -#ifndef QT_NO_QWS_QPF - if (!engine.isNull() - && script == QUnicodeTables::Common - && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { - - QStringList fallbacks = privateDb()->fallbackFamilies; - - if (family && !family->fallbackFamilies.isEmpty()) - fallbacks = family->fallbackFamilies; - - QFontEngine *fe = new QFontEngineMultiQWS(engine.data(), script, fallbacks); - engine.take(); - engine.reset(fe); - } -#endif - return engine.take(); -} - -static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) -{ - QFontDatabasePrivate *db = privateDb(); -#ifdef QT_NO_FREETYPE - Q_UNUSED(fnt); -#else - fnt->families = db->addTTFile(QFile::encodeName(fnt->fileName), fnt->data); - db->fallbackFamilies += fnt->families; -#endif - db->reregisterAppFonts = true; -} - -bool QFontDatabase::removeApplicationFont(int handle) -{ - QMutexLocker locker(fontDatabaseMutex()); - - QFontDatabasePrivate *db = privateDb(); - if (handle < 0 || handle >= db->applicationFonts.count()) - return false; - - db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont(); - - db->reregisterAppFonts = true; - db->invalidate(); - return true; -} - -bool QFontDatabase::removeAllApplicationFonts() -{ - QMutexLocker locker(fontDatabaseMutex()); - - QFontDatabasePrivate *db = privateDb(); - if (db->applicationFonts.isEmpty()) - return false; - - db->applicationFonts.clear(); - db->invalidate(); - return true; -} - -bool QFontDatabase::supportsThreadedFontRendering() -{ - return true; -} - -/*! - \internal -*/ -QFontEngine * -QFontDatabase::findFont(int script, const QFontPrivate *fp, - const QFontDef &request) -{ - QMutexLocker locker(fontDatabaseMutex()); - - const int force_encoding_id = -1; - - if (!privateDb()->count) - initializeDb(); - - QScopedPointer<QFontEngine> fe; - if (fp) { - if (fp->rawMode) { - fe.reset(loadEngine(script, fp, request, 0, 0, 0, 0)); - - // if we fail to load the rawmode font, use a 12pixel box engine instead - if (fe.isNull()) - fe.reset(new QFontEngineBox(12)); - return fe.take(); - } - - QFontCache::Key key(request, script); - fe.reset(QFontCache::instance()->findEngine(key)); - if (! fe.isNull()) - return fe.take(); - } - - QString family_name, foundry_name; - QtFontStyle::Key styleKey; - styleKey.style = request.style; - styleKey.weight = request.weight; - styleKey.stretch = request.stretch; - char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; - - parseFontName(request.family, foundry_name, family_name); - - FM_DEBUG("QFontDatabase::findFont\n" - " request:\n" - " family: %s [%s], script: %d\n" - " weight: %d, style: %d\n" - " stretch: %d\n" - " pixelSize: %g\n" - " pitch: %c", - family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), - foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), - script, request.weight, request.style, request.stretch, request.pixelSize, pitch); - - if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) { - fe.reset(new QTestFontEngine(request.pixelSize)); - fe->fontDef = request; - } - - if (fe.isNull()) - { - QtFontDesc desc; - match(script, request, family_name, foundry_name, force_encoding_id, &desc); - - if (desc.family != 0 && desc.foundry != 0 && desc.style != 0 - ) { - FM_DEBUG(" BEST:\n" - " family: %s [%s]\n" - " weight: %d, style: %d\n" - " stretch: %d\n" - " pixelSize: %d\n" - " pitch: %c\n" - " encoding: %d\n", - desc.family->name.toLatin1().constData(), - desc.foundry->name.isEmpty() ? "-- none --" : desc.foundry->name.toLatin1().constData(), - desc.style->key.weight, desc.style->key.style, - desc.style->key.stretch, desc.size ? desc.size->pixelSize : 0xffff, - 'p', 0 - ); - - fe.reset(loadEngine(script, fp, request, desc.family, desc.foundry, desc.style, desc.size - )); - } else { - FM_DEBUG(" NO MATCH FOUND\n"); - } - if (! fe.isNull()) - initFontDef(desc, request, &fe->fontDef); - } - -#ifndef QT_NO_FREETYPE - if (! fe.isNull()) { - if (scriptRequiresOpenType(script) && fe->type() == QFontEngine::Freetype) { - HB_Face hbFace = static_cast<QFontEngineFT *>(fe.data())->harfbuzzFace(); - if (!hbFace || !hbFace->supported_scripts[script]) { - FM_DEBUG(" OpenType support missing for script\n"); - fe.reset(0); - } - } - } -#endif - - if (! fe.isNull()) { - if (fp) { - QFontDef def = request; - if (def.family.isEmpty()) { - def.family = fp->request.family; - def.family = def.family.left(def.family.indexOf(QLatin1Char(','))); - } - QFontCache::Key key(def, script); - QFontCache::instance()->insertEngine(key, fe.data()); - } - } - - if (fe.isNull()) { - if (!request.family.isEmpty()) - return 0; - - FM_DEBUG("returning box engine"); - - fe.reset(new QFontEngineBox(request.pixelSize)); - - if (fp) { - QFontCache::Key key(request, script); - QFontCache::instance()->insertEngine(key, fe.data()); - } - } - - if (fp && fp->dpi > 0) { - fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / fp->dpi)); - } else { - fe->fontDef.pointSize = request.pointSize; - } - - return fe.take(); -} - -void QFontDatabase::load(const QFontPrivate *d, int script) -{ - QFontDef req = d->request; - - if (req.pixelSize == -1) - req.pixelSize = qRound(req.pointSize*d->dpi/72); - if (req.pointSize < 0) - req.pointSize = req.pixelSize*72.0/d->dpi; - - if (!d->engineData) { - QFontCache::Key key(req, script); - - // look for the requested font in the engine data cache - d->engineData = QFontCache::instance()->findEngineData(key); - - if (!d->engineData) { - // create a new one - d->engineData = new QFontEngineData; - QT_TRY { - QFontCache::instance()->insertEngineData(key, d->engineData); - } QT_CATCH(...) { - delete d->engineData; - d->engineData = 0; - QT_RETHROW; - } - } else { - d->engineData->ref.ref(); - } - } - - // the cached engineData could have already loaded the engine we want - if (d->engineData->engines[script]) return; - - // double scale = 1.0; // ### TODO: fix the scale calculations - - // list of families to try - QStringList family_list; - - if (!req.family.isEmpty()) { - family_list = req.family.split(QLatin1Char(',')); - - // append the substitute list for each family in family_list - QStringList subs_list; - QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd(); - for (; it != end; ++it) - subs_list += QFont::substitutes(*it); - family_list += subs_list; - - // append the default fallback font for the specified script - // family_list << ... ; ########### - - // add the default family - QString defaultFamily = QApplication::font().family(); - if (! family_list.contains(defaultFamily)) - family_list << defaultFamily; - - // add QFont::defaultFamily() to the list, for compatibility with - // previous versions - family_list << QApplication::font().defaultFamily(); - } - - // null family means find the first font matching the specified script - family_list << QString(); - - // load the font - QFontEngine *engine = 0; - QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd(); - for (; !engine && it != end; ++it) { - req.family = *it; - - engine = QFontDatabase::findFont(script, d, req); - if (engine && (engine->type()==QFontEngine::Box) && !req.family.isEmpty()) - engine = 0; - } - - engine->ref.ref(); - d->engineData->engines[script] = engine; -} - - -QT_END_NAMESPACE diff --git a/src/gui/text/qfontengine_qws.cpp b/src/gui/text/qfontengine_qws.cpp deleted file mode 100644 index b71c4a7aba..0000000000 --- a/src/gui/text/qfontengine_qws.cpp +++ /dev/null @@ -1,665 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfontengine_p.h" -#include <private/qunicodetables_p.h> -#include <qwsdisplay_qws.h> -#include <qvarlengtharray.h> -#include <private/qpainter_p.h> -#include <private/qpaintengine_raster_p.h> -#include <private/qpdf_p.h> -#include "qtextengine_p.h" -#include "private/qcore_unix_p.h" // overrides QT_OPEN - -#include <qdebug.h> - - -#ifndef QT_NO_QWS_QPF - -#include "qfile.h" -#include "qdir.h" - -#define QT_USE_MMAP -#include <stdlib.h> - -#ifdef QT_USE_MMAP -// for mmap -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <errno.h> - -# if defined(QT_LINUXBASE) && !defined(MAP_FILE) - // LSB 3.2 does not define MAP_FILE -# define MAP_FILE 0 -# endif - -#endif - -#endif // QT_NO_QWS_QPF - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_QWS_QPF -QT_BEGIN_INCLUDE_NAMESPACE -#include "qplatformdefs.h" -QT_END_INCLUDE_NAMESPACE - -static inline unsigned int getChar(const QChar *str, int &i, const int len) -{ - unsigned int uc = str[i].unicode(); - if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) { - uint low = str[i+1].unicode(); - if (low >= 0xdc00 && low < 0xe000) { - uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000; - ++i; - } - } - return uc; -} - -#define FM_SMOOTH 1 - - -class Q_PACKED QPFGlyphMetrics { - -public: - quint8 linestep; - quint8 width; - quint8 height; - quint8 flags; - - qint8 bearingx; // Difference from pen position to glyph's left bbox - quint8 advance; // Difference between pen positions - qint8 bearingy; // Used for putting characters on baseline - - qint8 reserved; // Do not use - - // Flags: - // RendererOwnsData - the renderer is responsible for glyph data - // memory deletion otherwise QPFGlyphTree must - // delete [] the data when the glyph is deleted. - enum Flags { RendererOwnsData=0x01 }; -}; - -class QPFGlyph { -public: - QPFGlyph() { metrics=0; data=0; } - QPFGlyph(QPFGlyphMetrics* m, uchar* d) : - metrics(m), data(d) { } - ~QPFGlyph() {} - - QPFGlyphMetrics* metrics; - uchar* data; -}; - -struct Q_PACKED QPFFontMetrics{ - qint8 ascent,descent; - qint8 leftbearing,rightbearing; - quint8 maxwidth; - qint8 leading; - quint8 flags; - quint8 underlinepos; - quint8 underlinewidth; - quint8 reserved3; -}; - - -class QPFGlyphTree { -public: - /* reads in a tree like this: - - A-Z - / \ - 0-9 a-z - - etc. - - */ - glyph_t min,max; - QPFGlyphTree* less; - QPFGlyphTree* more; - QPFGlyph* glyph; -public: -#ifdef QT_USE_MMAP - QPFGlyphTree(uchar*& data) - { - read(data); - } -#else - QPFGlyphTree(QIODevice& f) - { - read(f); - } -#endif - - ~QPFGlyphTree() - { - // NOTE: does not delete glyph[*].metrics or .data. - // the caller does this (only they know who owns - // the data). See clear(). - delete less; - delete more; - delete [] glyph; - } - - bool inFont(glyph_t g) const - { - if ( g < min ) { - if ( !less ) - return false; - return less->inFont(g); - } else if ( g > max ) { - if ( !more ) - return false; - return more->inFont(g); - } - return true; - } - - QPFGlyph* get(glyph_t g) - { - if ( g < min ) { - if ( !less ) - return 0; - return less->get(g); - } else if ( g > max ) { - if ( !more ) - return 0; - return more->get(g); - } - return &glyph[g - min]; - } - int totalChars() const - { - if ( !this ) return 0; - return max-min+1 + less->totalChars() + more->totalChars(); - } - int weight() const - { - if ( !this ) return 0; - return 1 + less->weight() + more->weight(); - } - - void dump(int indent=0) - { - for (int i=0; i<indent; i++) printf(" "); - printf("%d..%d",min,max); - //if ( indent == 0 ) - printf(" (total %d)",totalChars()); - printf("\n"); - if ( less ) less->dump(indent+1); - if ( more ) more->dump(indent+1); - } - -private: - QPFGlyphTree() - { - } - -#ifdef QT_USE_MMAP - void read(uchar*& data) - { - // All node data first - readNode(data); - // Then all non-video data - readMetrics(data); - // Then all video data - readData(data); - } -#else - void read(QIODevice& f) - { - // All node data first - readNode(f); - // Then all non-video data - readMetrics(f); - // Then all video data - readData(f); - } -#endif - -#ifdef QT_USE_MMAP - void readNode(uchar*& data) - { - uchar rw = *data++; - uchar cl = *data++; - min = (rw << 8) | cl; - rw = *data++; - cl = *data++; - max = (rw << 8) | cl; - int flags = *data++; - if ( flags & 1 ) - less = new QPFGlyphTree; - else - less = 0; - if ( flags & 2 ) - more = new QPFGlyphTree; - else - more = 0; - int n = max-min+1; - glyph = new QPFGlyph[n]; - - if ( less ) - less->readNode(data); - if ( more ) - more->readNode(data); - } -#else - void readNode(QIODevice& f) - { - char rw; - char cl; - f.getChar(&rw); - f.getChar(&cl); - min = (rw << 8) | cl; - f.getChar(&rw); - f.getChar(&cl); - max = (rw << 8) | cl; - char flags; - f.getChar(&flags); - if ( flags & 1 ) - less = new QPFGlyphTree; - else - less = 0; - if ( flags & 2 ) - more = new QPFGlyphTree; - else - more = 0; - int n = max-min+1; - glyph = new QPFGlyph[n]; - - if ( less ) - less->readNode(f); - if ( more ) - more->readNode(f); - } -#endif - -#ifdef QT_USE_MMAP - void readMetrics(uchar*& data) - { - int n = max-min+1; - for (int i=0; i<n; i++) { - glyph[i].metrics = (QPFGlyphMetrics*)data; - data += sizeof(QPFGlyphMetrics); - } - if ( less ) - less->readMetrics(data); - if ( more ) - more->readMetrics(data); - } -#else - void readMetrics(QIODevice& f) - { - int n = max-min+1; - for (int i=0; i<n; i++) { - glyph[i].metrics = new QPFGlyphMetrics; - f.read((char*)glyph[i].metrics, sizeof(QPFGlyphMetrics)); - } - if ( less ) - less->readMetrics(f); - if ( more ) - more->readMetrics(f); - } -#endif - -#ifdef QT_USE_MMAP - void readData(uchar*& data) - { - int n = max-min+1; - for (int i=0; i<n; i++) { - QSize s( glyph[i].metrics->width, glyph[i].metrics->height ); - //######### s = qt_screen->mapToDevice( s ); - uint datasize = glyph[i].metrics->linestep * s.height(); - glyph[i].data = data; data += datasize; - } - if ( less ) - less->readData(data); - if ( more ) - more->readData(data); - } -#else - void readData(QIODevice& f) - { - int n = max-min+1; - for (int i=0; i<n; i++) { - QSize s( glyph[i].metrics->width, glyph[i].metrics->height ); - //############### s = qt_screen->mapToDevice( s ); - uint datasize = glyph[i].metrics->linestep * s.height(); - glyph[i].data = new uchar[datasize]; // ### deleted? - f.read((char*)glyph[i].data, datasize); - } - if ( less ) - less->readData(f); - if ( more ) - more->readData(f); - } -#endif - -}; - -class QFontEngineQPF1Data -{ -public: - QPFFontMetrics fm; - QPFGlyphTree *tree; - void *mmapStart; - size_t mmapLength; -}; - -#if defined(Q_OS_INTEGRITY) -static void *qt_mmap(void *start, size_t length, int /*prot*/, int /*flags*/, int fd, off_t offset) -{ - // INTEGRITY cannot mmap local files - load it into a local buffer - if (::lseek(fd, offset, SEEK_SET) == -1) { -# if defined(DEBUG_FONTENGINE) - perror("lseek failed"); -# endif - } - void *buf = malloc(length); - if (::read(fd, buf, length) != (ssize_t)length) { -# if defined(DEBUG_FONTENGINE) - perror("read failed"); -# endif - } - - return buf; -} -#else -static inline void *qt_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) -{ - return mmap(start, length, prot, flags, fd, offset); -} -#endif - - - -QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn) -{ - cache_cost = 1; - - int f = QT_OPEN( QFile::encodeName(fn), O_RDONLY, 0); - Q_ASSERT(f>=0); - QT_STATBUF st; - if ( QT_FSTAT( f, &st ) ) - qFatal("Failed to stat %s",QFile::encodeName(fn).data()); - uchar* data = (uchar*)qt_mmap( 0, // any address - st.st_size, // whole file - PROT_READ, // read-only memory -#if defined(Q_OS_INTEGRITY) - 0, -#elif !defined(Q_OS_SOLARIS) && !defined(Q_OS_QNX4) && !defined(Q_OS_VXWORKS) - MAP_FILE | MAP_PRIVATE, // swap-backed map from file -#else - MAP_PRIVATE, -#endif - f, 0 ); // from offset 0 of f -#if !defined(MAP_FAILED) && (defined(Q_OS_QNX4) || defined(Q_OS_INTEGRITY)) -#define MAP_FAILED ((void *)-1) -#endif - if ( !data || data == (uchar*)MAP_FAILED ) - qFatal("Failed to mmap %s",QFile::encodeName(fn).data()); - QT_CLOSE(f); - - d = new QFontEngineQPF1Data; - d->mmapStart = data; - d->mmapLength = st.st_size; - memcpy(reinterpret_cast<char*>(&d->fm),data,sizeof(d->fm)); - - data += sizeof(d->fm); - d->tree = new QPFGlyphTree(data); - glyphFormat = (d->fm.flags & FM_SMOOTH) ? QFontEngineGlyphCache::Raster_A8 - : QFontEngineGlyphCache::Raster_Mono; -#if 0 - qDebug() << "font file" << fn - << "ascent" << d->fm.ascent << "descent" << d->fm.descent - << "leftbearing" << d->fm.leftbearing - << "rightbearing" << d->fm.rightbearing - << "maxwidth" << d->fm.maxwidth - << "leading" << d->fm.leading - << "flags" << d->fm.flags - << "underlinepos" << d->fm.underlinepos - << "underlinewidth" << d->fm.underlinewidth; -#endif -} - -QFontEngineQPF1::~QFontEngineQPF1() -{ - if (d->mmapStart) - munmap(d->mmapStart, d->mmapLength); - delete d->tree; - delete d; -} - - -bool QFontEngineQPF1::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const -{ - if(*nglyphs < len) { - *nglyphs = len; - return false; - } - *nglyphs = 0; - - bool mirrored = flags & QTextEngine::RightToLeft; - for(int i = 0; i < len; i++) { - unsigned int uc = getChar(str, i, len); - if (mirrored) - uc = QChar::mirroredChar(uc); - glyphs->glyphs[*nglyphs] = uc < 0x10000 ? uc : 0; - ++*nglyphs; - } - - glyphs->numGlyphs = *nglyphs; - - if (flags & QTextEngine::GlyphIndicesOnly) - return true; - - recalcAdvances(glyphs, flags); - - return true; -} - -void QFontEngineQPF1::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const -{ - for(int i = 0; i < glyphs->numGlyphs; i++) { - QPFGlyph *glyph = d->tree->get(glyphs->glyphs[i]); - - glyphs->advances_x[i] = glyph ? glyph->metrics->advance : 0; - glyphs->advances_y[i] = 0; - - if (!glyph) - glyphs->glyphs[i] = 0; - } -} - -void QFontEngineQPF1::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemInt &si) -{ - QPaintEngineState *pState = p->state; - QRasterPaintEngine *paintEngine = static_cast<QRasterPaintEngine*>(p); - - QTransform matrix = pState->transform(); - matrix.translate(_x, _y); - QFixed x = QFixed::fromReal(matrix.dx()); - QFixed y = QFixed::fromReal(matrix.dy()); - - QVarLengthArray<QFixedPoint> positions; - QVarLengthArray<glyph_t> glyphs; - getGlyphPositions(si.glyphs, matrix, si.flags, glyphs, positions); - if (glyphs.size() == 0) - return; - - int depth = (d->fm.flags & FM_SMOOTH) ? 8 : 1; - for(int i = 0; i < glyphs.size(); i++) { - const QPFGlyph *glyph = d->tree->get(glyphs[i]); - if (!glyph) - continue; - - int bpl = glyph->metrics->linestep; - - if(glyph->data) - paintEngine->alphaPenBlt(glyph->data, bpl, depth, - qRound(positions[i].x) + glyph->metrics->bearingx, - qRound(positions[i].y) - glyph->metrics->bearingy, - glyph->metrics->width,glyph->metrics->height); - } -} - - -QImage QFontEngineQPF1::alphaMapForGlyph(glyph_t g) -{ - const QPFGlyph *glyph = d->tree->get(g); - if (!glyph) - return QImage(); - - int mono = !(d->fm.flags & FM_SMOOTH); - - const uchar *bits = glyph->data;//((const uchar *) glyph); - - QImage image; - if (mono) { - image = QImage((glyph->metrics->width+7)&~7, glyph->metrics->height, QImage::Format_Mono); - image.setColor(0, qRgba(0, 0, 0, 0)); - image.setColor(1, qRgba(0, 0, 0, 255)); - } else { - image = QImage(glyph->metrics->width, glyph->metrics->height, QImage::Format_Indexed8); - for (int j=0; j<256; ++j) - image.setColor(j, qRgba(0, 0, 0, j)); - } - for (int i=0; i<glyph->metrics->height; ++i) { - memcpy(image.scanLine(i), bits, glyph->metrics->linestep); - bits += glyph->metrics->linestep; - } - return image; -} - - - -void QFontEngineQPF1::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) -{ - addBitmapFontToPath(x, y, glyphs, path, flags); -} - -glyph_metrics_t QFontEngineQPF1::boundingBox(const QGlyphLayout &glyphs) -{ - if (glyphs.numGlyphs == 0) - return glyph_metrics_t(); - - QFixed w = 0; - for (int i = 0; i < glyphs.numGlyphs; ++i) - w += glyphs.effectiveAdvance(i); - return glyph_metrics_t(0, -ascent(), w - lastRightBearing(glyphs), ascent()+descent()+1, w, 0); -} - -glyph_metrics_t QFontEngineQPF1::boundingBox(glyph_t glyph) -{ - const QPFGlyph *g = d->tree->get(glyph); - if (!g) - return glyph_metrics_t(); - Q_ASSERT(g); - return glyph_metrics_t(g->metrics->bearingx, -g->metrics->bearingy, - g->metrics->width, g->metrics->height, - g->metrics->advance, 0); -} - -QFixed QFontEngineQPF1::ascent() const -{ - return d->fm.ascent; -} - -QFixed QFontEngineQPF1::descent() const -{ - return d->fm.descent; -} - -QFixed QFontEngineQPF1::leading() const -{ - return d->fm.leading; -} - -qreal QFontEngineQPF1::maxCharWidth() const -{ - return d->fm.maxwidth; -} -/* -const char *QFontEngineQPF1::name() const -{ - return "qt"; -} -*/ -bool QFontEngineQPF1::canRender(const QChar *str, int len) -{ - for(int i = 0; i < len; i++) - if (!d->tree->inFont(str[i].unicode())) - return false; - return true; -} - -QFontEngine::Type QFontEngineQPF1::type() const -{ - return QPF1; -} - -qreal QFontEngineQPF1::minLeftBearing() const -{ - return d->fm.leftbearing; -} - -qreal QFontEngineQPF1::minRightBearing() const -{ - return d->fm.rightbearing; -} - -QFixed QFontEngineQPF1::underlinePosition() const -{ - return d->fm.underlinepos; -} - -QFixed QFontEngineQPF1::lineThickness() const -{ - return d->fm.underlinewidth; -} - -#endif //QT_NO_QWS_QPF - -QT_END_NAMESPACE diff --git a/src/gui/util/qdesktopservices_qws.cpp b/src/gui/util/qdesktopservices_qws.cpp deleted file mode 100644 index 324fa51a62..0000000000 --- a/src/gui/util/qdesktopservices_qws.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qcoreapplication.h> -#include <qdir.h> - -QT_BEGIN_NAMESPACE - -static bool launchWebBrowser(const QUrl &url) -{ - Q_UNUSED(url); - qWarning("QDesktopServices::launchWebBrowser not implemented"); - return false; -} - -static bool openDocument(const QUrl &file) -{ - Q_UNUSED(file); - qWarning("QDesktopServices::openDocument not implemented"); - return false; -} - - -QString QDesktopServices::storageLocation(StandardLocation type) -{ - if (type == DataLocation) { - QString qwsDataHome = QLatin1String(qgetenv("QWS_DATA_HOME")); - if (qwsDataHome.isEmpty()) - qwsDataHome = QDir::homePath() + QLatin1String("/.qws/share"); - qwsDataHome += QLatin1String("/data/") - + QCoreApplication::organizationName() + QLatin1Char('/') - + QCoreApplication::applicationName(); - return qwsDataHome; - } - if (type == QDesktopServices::CacheLocation) { - QString qwsCacheHome = QLatin1String(qgetenv("QWS_CACHE_HOME")); - if (qwsCacheHome.isEmpty()) - qwsCacheHome = QDir::homePath() + QLatin1String("/.qws/cache/"); - qwsCacheHome += QCoreApplication::organizationName() + QLatin1Char('/') - + QCoreApplication::applicationName(); - return qwsCacheHome; - } - - qWarning("QDesktopServices::storageLocation %d not implemented", type); - return QString(); -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - Q_UNUSED(type); - qWarning("QDesktopServices::displayName not implemented"); - return QString(); -} - -QT_END_NAMESPACE diff --git a/src/gui/util/qsystemtrayicon_qws.cpp b/src/gui/util/qsystemtrayicon_qpa.cpp index 48f8fe8922..48f8fe8922 100644 --- a/src/gui/util/qsystemtrayicon_qws.cpp +++ b/src/gui/util/qsystemtrayicon_qpa.cpp diff --git a/src/gui/util/util.pri b/src/gui/util/util.pri index 2814a2d30a..46230b5be5 100644 --- a/src/gui/util/util.pri +++ b/src/gui/util/util.pri @@ -43,7 +43,7 @@ unix:x11 { embedded|qpa { SOURCES += \ - util/qsystemtrayicon_qws.cpp + util/qsystemtrayicon_qpa.cpp } !embedded:!qpa:!x11:mac { |