diff options
author | Thomas McGuire <thomas.mcguire@kdab.com> | 2012-03-26 15:50:21 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-03 15:08:35 +0200 |
commit | dcacb8833a92bf6f28a9f709fb6b88a733ba2101 (patch) | |
tree | 41c5337574ab88ddf2b7d588d886c24d192a6b3c /src/plugins | |
parent | da3baf5e2b9fb9ea1a57b35a757c7c8b850e9a56 (diff) | |
download | qt4-tools-dcacb8833a92bf6f28a9f709fb6b88a733ba2101.tar.gz |
Make everything in QBBScreen non-static
Cherry-picked from qtbase b5f343b3677a7c7f09d91d7d60f310717325e840
Change-Id: Idf7176bd83215f1251c1e2200a5bf0168adfe523
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/blackberry/qbbintegration.cpp | 51 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbintegration.h | 6 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreen.cpp | 105 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreen.h | 29 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbwindow.cpp | 42 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbwindow.h | 4 |
6 files changed, 127 insertions, 110 deletions
diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp index 8d797134be..840ae1fe3f 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.cpp +++ b/src/plugins/platforms/blackberry/qbbintegration.cpp @@ -92,7 +92,7 @@ QBBIntegration::QBBIntegration() : } // Create displays for all possible screens (which may not be attached) - QBBScreen::createDisplays(mContext); + createDisplays(); // create/start event thread mEventThread = new QBBEventThread(mContext); @@ -101,7 +101,7 @@ QBBIntegration::QBBIntegration() : // Create/start navigator event handler // Not on BlackBerry, it has specialised event dispatcher which also handles navigator events #ifndef Q_OS_BLACKBERRY - mNavigatorEventHandler = new QBBNavigatorEventHandler(*QBBScreen::primaryDisplay()); + mNavigatorEventHandler = new QBBNavigatorEventHandler(*primaryDisplay()); // delay invocation of start() to the time the event loop is up and running // needed to have the QThread internals of the main thread properly initialized @@ -127,7 +127,7 @@ QBBIntegration::QBBIntegration() : // TODO check if we need to do this for all screens or only the primary one QObject::connect(mVirtualKeyboard, SIGNAL(heightChanged(int)), - QBBScreen::primaryDisplay(), SLOT(keyboardHeightChanged(int))); + primaryDisplay(), SLOT(keyboardHeightChanged(int))); // Set up the input context qApp->setInputContext(new QBBInputContext(*mVirtualKeyboard, qApp)); @@ -153,7 +153,7 @@ QBBIntegration::~QBBIntegration() delete mNavigatorEventHandler; // destroy all displays - QBBScreen::destroyDisplays(); + destroyDisplays(); // close connection to QNX composition manager screen_destroy_context(mContext); @@ -193,8 +193,7 @@ QPlatformWindow *QBBIntegration::createPlatformWindow(QWidget *widget, WId winId { Q_UNUSED(winId); - // New windows are created on the primary display. - return new QBBWindow(widget, mContext); + return new QBBWindow(widget, mContext, primaryDisplay()); } QWindowSurface *QBBIntegration::createWindowSurface(QWidget *widget, WId winId) const @@ -216,7 +215,7 @@ void QBBIntegration::moveToScreen(QWidget *window, int screen) QBBWindow* platformWindow = static_cast<QBBWindow*>(window->platformWindow()); // lookup platform screen by index - QBBScreen* platformScreen = static_cast<QBBScreen*>(QBBScreen::screens().at(screen)); + QBBScreen* platformScreen = static_cast<QBBScreen*>(mScreens.at(screen)); // move the platform window to the platform screen (this can fail when move to screen // is called before the window is actually created). @@ -226,7 +225,7 @@ void QBBIntegration::moveToScreen(QWidget *window, int screen) QList<QPlatformScreen *> QBBIntegration::screens() const { - return QBBScreen::screens(); + return mScreens; } #ifndef QT_NO_CLIPBOARD @@ -240,9 +239,45 @@ QPlatformClipboard *QBBIntegration::clipboard() const } #endif +QBBScreen *QBBIntegration::primaryDisplay() const +{ + return static_cast<QBBScreen*>(mScreens.first()); +} + void QBBIntegration::setCursorPos(int x, int y) { mEventThread->injectPointerMoveEvent(x, y); } +void QBBIntegration::createDisplays() +{ + // get number of displays + errno = 0; + int displayCount; + int result = screen_get_context_property_iv(mContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount); + if (result != 0) + qFatal("QBBIntegration: failed to query display count, errno=%d", errno); + + // get all displays + errno = 0; + screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); + result = screen_get_context_property_pv(mContext, SCREEN_PROPERTY_DISPLAYS, (void **)displays); + if (result != 0) + qFatal("QBBIntegration: failed to query displays, errno=%d", errno); + + for (int i=0; i<displayCount; i++) { +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << "QBBIntegration: Creating screen for display " << i; +#endif + QBBScreen *screen = new QBBScreen(mContext, displays[i], i); + mScreens.push_back(screen); + } +} + +void QBBIntegration::destroyDisplays() +{ + qDeleteAll(mScreens); + mScreens.clear(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h index 0ab50caaaa..355008c4f6 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.h +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -50,6 +50,7 @@ class QBBEventThread; class QBBNavigatorEventHandler; class QBBLocaleThread; class QBBAbstractVirtualKeyboard; +class QBBScreen; class QBBIntegration : public QPlatformIntegration { @@ -76,11 +77,16 @@ public: bool paintUsingOpenGL() const { return mPaintUsingOpenGL; } private: + QBBScreen *primaryDisplay() const; + void createDisplays(); + void destroyDisplays(); + screen_context_t mContext; QBBEventThread *mEventThread; QBBNavigatorEventHandler *mNavigatorEventHandler; QBBLocaleThread *mLocaleThread; QPlatformFontDatabase *mFontDb; + QList<QPlatformScreen*> mScreens; bool mPaintUsingOpenGL; QBBAbstractVirtualKeyboard *mVirtualKeyboard; }; diff --git a/src/plugins/platforms/blackberry/qbbscreen.cpp b/src/plugins/platforms/blackberry/qbbscreen.cpp index 60969fc05a..fd075d1d8a 100644 --- a/src/plugins/platforms/blackberry/qbbscreen.cpp +++ b/src/plugins/platforms/blackberry/qbbscreen.cpp @@ -43,7 +43,6 @@ #include "qbbrootwindow.h" #include "qbbwindow.h" -#include <QUuid> #include <QDebug> #include <QtGui/QWindowSystemInterface> @@ -52,18 +51,14 @@ QT_BEGIN_NAMESPACE -#define MAGIC_ZORDER_FOR_NO_NAV 10 - -QList<QPlatformScreen *> QBBScreen::sScreens; -QList<QBBWindow*> QBBScreen::sChildren; - -QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, bool primary) +QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, int screenIndex) : mContext(context), mDisplay(display), mPosted(false), mUsingOpenGL(false), - mPrimaryDisplay(primary), - mKeyboardHeight(0) + mPrimaryDisplay(screenIndex == 0), + mKeyboardHeight(0), + mScreenIndex(screenIndex) { #if defined(QBBSCREEN_DEBUG) qDebug() << "QBBScreen::QBBScreen"; @@ -120,48 +115,7 @@ QBBScreen::~QBBScreen() #endif } -/* static */ -void QBBScreen::createDisplays(screen_context_t context) -{ - // get number of displays - errno = 0; - int displayCount; - int result = screen_get_context_property_iv(context, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount); - if (result != 0) { - qFatal("QBBScreen: failed to query display count, errno=%d", errno); - } - - // get all displays - errno = 0; - screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); - result = screen_get_context_property_pv(context, SCREEN_PROPERTY_DISPLAYS, (void **)displays); - if (result != 0) { - qFatal("QBBScreen: failed to query displays, errno=%d", errno); - } - - for (int i=0; i<displayCount; i++) { -#if defined(QBBSCREEN_DEBUG) - qDebug() << "QBBScreen::Creating screen for display " << i; -#endif - QBBScreen *screen = new QBBScreen(context, displays[i], i==0); - sScreens.push_back(screen); - } -} - -/* static */ -void QBBScreen::destroyDisplays() -{ - while (sScreens.length()) { - delete sScreens.front(); - sScreens.pop_front(); - } - - // We're not managing the child windows anymore so we need to clear the list. - sChildren.clear(); -} - -/* static */ -int QBBScreen::defaultDepth() +static int defaultDepth() { static int defaultDepth = 0; if (defaultDepth == 0) { @@ -188,6 +142,11 @@ QRect QBBScreen::availableGeometry() const mCurrentGeometry.width(), mCurrentGeometry.height() - mKeyboardHeight); } +int QBBScreen::depth() const +{ + return defaultDepth(); +} + /*! Check if the supplied angles are perpendicular to each other. */ @@ -240,17 +199,28 @@ void QBBScreen::setRotation(int rotation) } } +QBBWindow *QBBScreen::findWindow(screen_window_t windowHandle) +{ + Q_FOREACH (QBBWindow *window, mChildren) { + QBBWindow * const result = window->findWindow(windowHandle); + if (result) + return result; + } + + return 0; +} + void QBBScreen::addWindow(QBBWindow* window) { #if defined(QBBSCREEN_DEBUG) qDebug() << "QBBScreen::addWindow=" << window; #endif - if (sChildren.contains(window)) + if (mChildren.contains(window)) return; - sChildren.push_back(window); - QBBScreen::updateHierarchy(); + mChildren.push_back(window); + updateHierarchy(); } void QBBScreen::removeWindow(QBBWindow* window) @@ -259,8 +229,9 @@ void QBBScreen::removeWindow(QBBWindow* window) qDebug() << "QBBScreen::removeWindow=" << window; #endif - sChildren.removeAll(window); - QBBScreen::updateHierarchy(); + const int numWindowsRemoved = mChildren.removeAll(window); + if (numWindowsRemoved > 0) + updateHierarchy(); } void QBBScreen::raiseWindow(QBBWindow* window) @@ -270,8 +241,8 @@ void QBBScreen::raiseWindow(QBBWindow* window) #endif removeWindow(window); - sChildren.push_back(window); - QBBScreen::updateHierarchy(); + mChildren.push_back(window); + updateHierarchy(); } void QBBScreen::lowerWindow(QBBWindow* window) @@ -281,8 +252,8 @@ void QBBScreen::lowerWindow(QBBWindow* window) #endif removeWindow(window); - sChildren.push_front(window); - QBBScreen::updateHierarchy(); + mChildren.push_front(window); + updateHierarchy(); } void QBBScreen::updateHierarchy() @@ -291,22 +262,16 @@ void QBBScreen::updateHierarchy() qDebug() << "QBBScreen::updateHierarchy"; #endif - QList<QBBWindow*>::iterator it; - QList<QPlatformScreen *>::iterator sit; - QMap<QPlatformScreen *, int> map; + QList<QBBWindow*>::const_iterator it; int topZorder = 1; // root window is z-order 0, all "top" level windows are "above" it - for (sit = sScreens.begin(); sit != sScreens.end(); sit++) - map[*sit] = 0; - - for (it = sChildren.begin(); it != sChildren.end(); it++) { + for (it = mChildren.constBegin(); it != mChildren.constEnd(); ++it) { (*it)->updateZorder(topZorder); - map[static_cast<QBBScreen*>((*it)->screen())] = 1; } // After a hierarchy update, we need to force a flush on all screens. // Right now, all screens share a context. - screen_flush_context( primaryDisplay()->mContext, 0 ); + screen_flush_context( mContext, 0 ); } void QBBScreen::onWindowPost(QBBWindow* window) @@ -329,7 +294,7 @@ void QBBScreen::keyboardHeightChanged(int height) mKeyboardHeight = height; - QWindowSystemInterface::handleScreenAvailableGeometryChange(screens().indexOf(this)); + QWindowSystemInterface::handleScreenAvailableGeometryChange(mScreenIndex); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbscreen.h b/src/plugins/platforms/blackberry/qbbscreen.h index 9d2b815170..0f8f839260 100644 --- a/src/plugins/platforms/blackberry/qbbscreen.h +++ b/src/plugins/platforms/blackberry/qbbscreen.h @@ -41,7 +41,6 @@ #define QBBSCREEN_H #include <QtGui/QPlatformScreen> -#include <QByteArray> #include "qbbrootwindow.h" @@ -55,15 +54,12 @@ class QBBScreen : public QPlatformScreen { Q_OBJECT public: - static QList<QPlatformScreen *> screens() { return sScreens; } - static void createDisplays(screen_context_t context); - static void destroyDisplays(); - static QBBScreen* primaryDisplay() { return static_cast<QBBScreen*>(sScreens.at(0)); } - static int defaultDepth(); + QBBScreen(screen_context_t context, screen_display_t display, int screenIndex); + virtual ~QBBScreen(); virtual QRect geometry() const { return mCurrentGeometry; } virtual QRect availableGeometry() const; - virtual int depth() const { return defaultDepth(); } + virtual int depth() const; virtual QImage::Format format() const { return (depth() == 32) ? QImage::Format_RGB32 : QImage::Format_RGB16; } virtual QSize physicalSize() const { return mCurrentPhysicalSize; } @@ -75,12 +71,14 @@ public: screen_context_t nativeContext() const { return mContext; } const char *windowGroupName() const { return mRootWindow->groupName().constData(); } + QBBWindow *findWindow(screen_window_t windowHandle); + /* Window hierarchy management */ - static void addWindow(QBBWindow* child); - static void removeWindow(QBBWindow* child); - static void raiseWindow(QBBWindow* window); - static void lowerWindow(QBBWindow* window); - static void updateHierarchy(); + void addWindow(QBBWindow* child); + void removeWindow(QBBWindow* child); + void raiseWindow(QBBWindow* window); + void lowerWindow(QBBWindow* window); + void updateHierarchy(); void onWindowPost(QBBWindow* window); void ensureDisplayCreated(); @@ -106,11 +104,8 @@ private: QRect mStartGeometry; QRect mCurrentGeometry; - static QList<QPlatformScreen *> sScreens; - static QList<QBBWindow*> sChildren; - - QBBScreen(screen_context_t context, screen_display_t display, bool primary); - virtual ~QBBScreen(); + QList<QBBWindow*> mChildren; + int mScreenIndex; bool isPrimaryDisplay() { return mPrimaryDisplay; } }; diff --git a/src/plugins/platforms/blackberry/qbbwindow.cpp b/src/plugins/platforms/blackberry/qbbwindow.cpp index ffdb118c83..515b6c2390 100644 --- a/src/plugins/platforms/blackberry/qbbwindow.cpp +++ b/src/plugins/platforms/blackberry/qbbwindow.cpp @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -QBBWindow::QBBWindow(QWidget *window, screen_context_t context) +QBBWindow::QBBWindow(QWidget *window, screen_context_t context, QBBScreen *screen) : QPlatformWindow(window), mContext(context), mCurrentBufferIndex(-1), @@ -120,10 +120,7 @@ QBBWindow::QBBWindow(QWidget *window, screen_context_t context) } // Set the screen to the primary display (this is the default specified by screen). - setScreen(QBBScreen::primaryDisplay()); - - // Add the window to the root of the Hierarchy. - QBBScreen::addWindow(this); + setScreen(screen); } QBBWindow::~QBBWindow() @@ -134,7 +131,7 @@ QBBWindow::~QBBWindow() // Remove from parent's Hierarchy. removeFromParent(); - QBBScreen::updateHierarchy(); + mScreen->updateHierarchy(); // We shouldn't allow this case unless QT allows it. Does it? Or should we send the // handleCloseEvent on all children when this window is deleted? @@ -428,6 +425,9 @@ void QBBWindow::setScreen(QBBScreen *platformScreen) if (mScreen == platformScreen) return; + if (mScreen) + mScreen->removeWindow(this); + platformScreen->addWindow(this); mScreen = platformScreen; // The display may not have a root (desktop) window yet so we must ensure that one has been @@ -458,7 +458,7 @@ void QBBWindow::setScreen(QBBScreen *platformScreen) (*it)->setScreen(platformScreen); } - QBBScreen::updateHierarchy(); + mScreen->updateHierarchy(); } void QBBWindow::removeFromParent() @@ -470,7 +470,7 @@ void QBBWindow::removeFromParent() else qFatal("QBBWindow: Window Hierarchy broken; window has parent, but parent hasn't got child."); } else { - QBBScreen::removeWindow(this); + mScreen->removeWindow(this); } } @@ -499,10 +499,10 @@ void QBBWindow::setParent(const QPlatformWindow *window) mParent->mChildren.push_back(this); } else { - QBBScreen::addWindow(this); + mScreen->addWindow(this); } - QBBScreen::updateHierarchy(); + mScreen->updateHierarchy(); } void QBBWindow::raise() @@ -516,10 +516,10 @@ void QBBWindow::raise() removeFromParent(); oldParent->mChildren.push_back(this); } else { - QBBScreen::raiseWindow(this); + mScreen->raiseWindow(this); } - QBBScreen::updateHierarchy(); + mScreen->updateHierarchy(); } void QBBWindow::lower() @@ -533,10 +533,10 @@ void QBBWindow::lower() removeFromParent(); oldParent->mChildren.push_front(this); } else { - QBBScreen::lowerWindow(this); + mScreen->lowerWindow(this); } - QBBScreen::updateHierarchy(); + mScreen->updateHierarchy(); } void QBBWindow::requestActivateWindow() @@ -561,6 +561,20 @@ void QBBWindow::gainedFocus() QWindowSystemInterface::handleWindowActivated(widget()); } +QBBWindow *QBBWindow::findWindow(screen_window_t windowHandle) +{ + if (mWindow == windowHandle) + return this; + + Q_FOREACH (QBBWindow *window, mChildren) { + QBBWindow * const result = window->findWindow(windowHandle); + if (result) + return result; + } + + return 0; +} + void QBBWindow::updateZorder(int &topZorder) { errno = 0; diff --git a/src/plugins/platforms/blackberry/qbbwindow.h b/src/plugins/platforms/blackberry/qbbwindow.h index 5168dfa0aa..91a8f260d1 100644 --- a/src/plugins/platforms/blackberry/qbbwindow.h +++ b/src/plugins/platforms/blackberry/qbbwindow.h @@ -61,7 +61,7 @@ class QBBWindow : public QPlatformWindow { friend class QBBScreen; public: - QBBWindow(QWidget *window, screen_context_t context); + QBBWindow(QWidget *window, screen_context_t context, QBBScreen *screen); virtual ~QBBWindow(); virtual void setGeometry(const QRect &rect); @@ -92,6 +92,8 @@ public: QBBScreen* screen() const { return mScreen; } const QList<QBBWindow*>& children() const { return mChildren; } + QBBWindow *findWindow(screen_window_t windowHandle); + private: screen_context_t mContext; screen_window_t mWindow; |