| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** Copyright (C) 2009 netlabs.org. OS/2 parts.
|
|---|
| 7 | **
|
|---|
| 8 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 9 | **
|
|---|
| 10 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 11 | ** Commercial Usage
|
|---|
| 12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 13 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 14 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 15 | ** a written agreement between you and Nokia.
|
|---|
| 16 | **
|
|---|
| 17 | ** GNU Lesser General Public License Usage
|
|---|
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 19 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 21 | ** packaging of this file. Please review the following information to
|
|---|
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 24 | **
|
|---|
| 25 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 26 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 27 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 28 | ** package.
|
|---|
| 29 | **
|
|---|
| 30 | ** GNU General Public License Usage
|
|---|
| 31 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 32 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 34 | ** packaging of this file. Please review the following information to
|
|---|
| 35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 37 | **
|
|---|
| 38 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 39 | ** contact the sales department at [email protected].
|
|---|
| 40 | ** $QT_END_LICENSE$
|
|---|
| 41 | **
|
|---|
| 42 | ****************************************************************************/
|
|---|
| 43 |
|
|---|
| 44 | #include <private/qcursor_p.h>
|
|---|
| 45 | #include <qbitmap.h>
|
|---|
| 46 | #include <qcursor.h>
|
|---|
| 47 |
|
|---|
| 48 | #ifndef QT_NO_CURSOR
|
|---|
| 49 |
|
|---|
| 50 | #include <qimage.h>
|
|---|
| 51 | #include <qapplication.h>
|
|---|
| 52 | #include <qdesktopwidget.h>
|
|---|
| 53 | #include <qt_os2.h>
|
|---|
| 54 |
|
|---|
| 55 | QT_BEGIN_NAMESPACE
|
|---|
| 56 |
|
|---|
| 57 | extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
|
|---|
| 58 |
|
|---|
| 59 | /*****************************************************************************
|
|---|
| 60 | Internal QCursorData class
|
|---|
| 61 | *****************************************************************************/
|
|---|
| 62 |
|
|---|
| 63 | QCursorData::QCursorData(Qt::CursorShape s)
|
|---|
| 64 | : cshape(s), bm(0), bmm(0), hx(0), hy(0), hptr(NULLHANDLE), isSysPtr(false)
|
|---|
| 65 | {
|
|---|
| 66 | ref = 1;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | QCursorData::~QCursorData()
|
|---|
| 70 | {
|
|---|
| 71 | delete bm;
|
|---|
| 72 | delete bmm;
|
|---|
| 73 | if (hptr && !isSysPtr)
|
|---|
| 74 | WinDestroyPointer(hptr);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
|
|---|
| 79 | {
|
|---|
| 80 | if (!QCursorData::initialized)
|
|---|
| 81 | QCursorData::initialize();
|
|---|
| 82 | if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
|
|---|
| 83 | qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
|
|---|
| 84 | QCursorData *c = qt_cursorTable[0];
|
|---|
| 85 | c->ref.ref();
|
|---|
| 86 | return c;
|
|---|
| 87 | }
|
|---|
| 88 | QCursorData *d = new QCursorData;
|
|---|
| 89 | d->bm = new QBitmap(bitmap);
|
|---|
| 90 | d->bmm = new QBitmap(mask);
|
|---|
| 91 | d->hptr = NULLHANDLE;
|
|---|
| 92 | d->cshape = Qt::BitmapCursor;
|
|---|
| 93 | d->hx = hotX >= 0 ? hotX : bitmap.width()/2;
|
|---|
| 94 | d->hy = hotY >= 0 ? hotY : bitmap.height()/2;
|
|---|
| 95 | return d;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | HPOINTER QCursor::handle() const
|
|---|
| 99 | {
|
|---|
| 100 | if (!QCursorData::initialized)
|
|---|
| 101 | QCursorData::initialize();
|
|---|
| 102 | if (d->hptr == NULLHANDLE)
|
|---|
| 103 | d->update();
|
|---|
| 104 | return d->hptr;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | QCursor::QCursor(HPOINTER handle)
|
|---|
| 108 | {
|
|---|
| 109 | d = new QCursorData(Qt::CustomCursor);
|
|---|
| 110 | d->hptr = handle;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | #endif //QT_NO_CURSOR
|
|---|
| 114 |
|
|---|
| 115 | QPoint QCursor::pos()
|
|---|
| 116 | {
|
|---|
| 117 | POINTL p;
|
|---|
| 118 | WinQueryPointerPos(HWND_DESKTOP, &p);
|
|---|
| 119 | // flip y coordinate
|
|---|
| 120 | p.y = QApplication::desktop()->height() - (p.y + 1);
|
|---|
| 121 | return QPoint(p.x, p.y);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | void QCursor::setPos(int x, int y)
|
|---|
| 125 | {
|
|---|
| 126 | // flip y coordinate
|
|---|
| 127 | y = QApplication::desktop()->height() - (y + 1);
|
|---|
| 128 | WinSetPointerPos(HWND_DESKTOP, x, y);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | #ifndef QT_NO_CURSOR
|
|---|
| 132 |
|
|---|
| 133 | void QCursorData::update()
|
|---|
| 134 | {
|
|---|
| 135 | if (!QCursorData::initialized)
|
|---|
| 136 | QCursorData::initialize();
|
|---|
| 137 | // @todo we depend on QPixmap vs HBITMAP integration here
|
|---|
| 138 |
|
|---|
| 139 | LONG id = 0;
|
|---|
| 140 | const uchar *bits = 0;
|
|---|
| 141 | const uchar *mask = 0;
|
|---|
| 142 | bool isbitmap = false;
|
|---|
| 143 |
|
|---|
| 144 | switch (cshape) { // map to OS/2 cursor
|
|---|
| 145 | case Qt::ArrowCursor:
|
|---|
| 146 | case Qt::UpArrowCursor: // @todo what's this?
|
|---|
| 147 | case Qt::CrossCursor: // @todo what's this?
|
|---|
| 148 | id = SPTR_ARROW;
|
|---|
| 149 | break;
|
|---|
| 150 | case Qt::WaitCursor:
|
|---|
| 151 | id = SPTR_WAIT;
|
|---|
| 152 | break;
|
|---|
| 153 | case Qt::IBeamCursor:
|
|---|
| 154 | id = SPTR_TEXT;
|
|---|
| 155 | break;
|
|---|
| 156 | case Qt::SizeVerCursor:
|
|---|
| 157 | id = SPTR_SIZENS;
|
|---|
| 158 | break;
|
|---|
| 159 | case Qt::SizeHorCursor:
|
|---|
| 160 | id = SPTR_SIZEWE;
|
|---|
| 161 | break;
|
|---|
| 162 | case Qt::SizeBDiagCursor:
|
|---|
| 163 | id = SPTR_SIZENESW;
|
|---|
| 164 | break;
|
|---|
| 165 | case Qt::SizeFDiagCursor:
|
|---|
| 166 | id = SPTR_SIZENWSE;
|
|---|
| 167 | break;
|
|---|
| 168 | case Qt::SizeAllCursor:
|
|---|
| 169 | id = SPTR_MOVE;
|
|---|
| 170 | break;
|
|---|
| 171 | case Qt::ForbiddenCursor:
|
|---|
| 172 | id = SPTR_ILLEGAL;
|
|---|
| 173 | break;
|
|---|
| 174 | default:
|
|---|
| 175 | // @temporary
|
|---|
| 176 | id = SPTR_ARROW;
|
|---|
| 177 | break;
|
|---|
| 178 | // @todo later here will be this:
|
|---|
| 179 | // qWarning("QCursor::update: Invalid cursor shape %d", cshape);
|
|---|
| 180 | // return;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | if ((bits && mask) || isbitmap) {
|
|---|
| 185 | // @todo later
|
|---|
| 186 | hptr = 0;
|
|---|
| 187 | isSysPtr = false;
|
|---|
| 188 | } else {
|
|---|
| 189 | hptr = WinQuerySysPointer(HWND_DESKTOP, id, FALSE);
|
|---|
| 190 | isSysPtr = true;
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | #endif // QT_NO_CURSOR
|
|---|
| 195 |
|
|---|
| 196 | QT_END_NAMESPACE
|
|---|