| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <private/qcursor_p.h>
|
|---|
| 43 | #include <qbitmap.h>
|
|---|
| 44 | #include <qcursor.h>
|
|---|
| 45 |
|
|---|
| 46 | #ifndef QT_NO_CURSOR
|
|---|
| 47 |
|
|---|
| 48 | #include <qimage.h>
|
|---|
| 49 | #include <qt_windows.h>
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
|
|---|
| 54 |
|
|---|
| 55 | /*****************************************************************************
|
|---|
| 56 | Internal QCursorData class
|
|---|
| 57 | *****************************************************************************/
|
|---|
| 58 |
|
|---|
| 59 | QCursorData::QCursorData(Qt::CursorShape s)
|
|---|
| 60 | : cshape(s), bm(0), bmm(0), hx(0), hy(0), hcurs(0)
|
|---|
| 61 | {
|
|---|
| 62 | ref = 1;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | QCursorData::~QCursorData()
|
|---|
| 66 | {
|
|---|
| 67 | delete bm;
|
|---|
| 68 | delete bmm;
|
|---|
| 69 | #if !defined(Q_OS_WINCE) || defined(GWES_ICONCURS)
|
|---|
| 70 | if (hcurs)
|
|---|
| 71 | DestroyCursor(hcurs);
|
|---|
| 72 | #endif
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
|
|---|
| 77 | {
|
|---|
| 78 | if (!QCursorData::initialized)
|
|---|
| 79 | QCursorData::initialize();
|
|---|
| 80 | if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
|
|---|
| 81 | qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
|
|---|
| 82 | QCursorData *c = qt_cursorTable[0];
|
|---|
| 83 | c->ref.ref();
|
|---|
| 84 | return c;
|
|---|
| 85 | }
|
|---|
| 86 | QCursorData *d = new QCursorData;
|
|---|
| 87 | d->bm = new QBitmap(bitmap);
|
|---|
| 88 | d->bmm = new QBitmap(mask);
|
|---|
| 89 | d->hcurs = 0;
|
|---|
| 90 | d->cshape = Qt::BitmapCursor;
|
|---|
| 91 | d->hx = hotX >= 0 ? hotX : bitmap.width()/2;
|
|---|
| 92 | d->hy = hotY >= 0 ? hotY : bitmap.height()/2;
|
|---|
| 93 | return d;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | HCURSOR QCursor::handle() const
|
|---|
| 97 | {
|
|---|
| 98 | if (!QCursorData::initialized)
|
|---|
| 99 | QCursorData::initialize();
|
|---|
| 100 | if (!d->hcurs)
|
|---|
| 101 | d->update();
|
|---|
| 102 | return d->hcurs;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | QCursor::QCursor(HCURSOR handle)
|
|---|
| 106 | {
|
|---|
| 107 | d = new QCursorData(Qt::CustomCursor);
|
|---|
| 108 | d->hcurs = handle;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | #endif //QT_NO_CURSOR
|
|---|
| 112 |
|
|---|
| 113 | QPoint QCursor::pos()
|
|---|
| 114 | {
|
|---|
| 115 | POINT p;
|
|---|
| 116 | GetCursorPos(&p);
|
|---|
| 117 | return QPoint(p.x, p.y);
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | void QCursor::setPos(int x, int y)
|
|---|
| 121 | {
|
|---|
| 122 | SetCursorPos(x, y);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | #ifndef QT_NO_CURSOR
|
|---|
| 126 |
|
|---|
| 127 | extern HBITMAP qt_createIconMask(const QBitmap &bitmap);
|
|---|
| 128 |
|
|---|
| 129 | static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy)
|
|---|
| 130 | {
|
|---|
| 131 | HCURSOR cur = 0;
|
|---|
| 132 | #if !defined(Q_OS_WINCE)
|
|---|
| 133 | QBitmap mask = pixmap.mask();
|
|---|
| 134 | if (mask.isNull()) {
|
|---|
| 135 | mask = QBitmap(pixmap.size());
|
|---|
| 136 | mask.fill(Qt::color1);
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | HBITMAP ic = pixmap.toWinHBITMAP(QPixmap::Alpha);
|
|---|
| 140 | HBITMAP im = qt_createIconMask(mask);
|
|---|
| 141 |
|
|---|
| 142 | ICONINFO ii;
|
|---|
| 143 | ii.fIcon = 0;
|
|---|
| 144 | ii.xHotspot = hx;
|
|---|
| 145 | ii.yHotspot = hy;
|
|---|
| 146 | ii.hbmMask = im;
|
|---|
| 147 | ii.hbmColor = ic;
|
|---|
| 148 |
|
|---|
| 149 | cur = CreateIconIndirect(&ii);
|
|---|
| 150 |
|
|---|
| 151 | DeleteObject(ic);
|
|---|
| 152 | DeleteObject(im);
|
|---|
| 153 | #elif defined(GWES_ICONCURS)
|
|---|
| 154 | QImage bbits, mbits;
|
|---|
| 155 | bool invb, invm;
|
|---|
| 156 | bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 157 | mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 158 | invb = bbits.numColors() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
|
|---|
| 159 | invm = mbits.numColors() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));
|
|---|
| 160 |
|
|---|
| 161 | int sysW = GetSystemMetrics(SM_CXCURSOR);
|
|---|
| 162 | int sysH = GetSystemMetrics(SM_CYCURSOR);
|
|---|
| 163 | int sysN = qMax(1, sysW / 8);
|
|---|
| 164 | int n = qMax(1, bbits.width() / 8);
|
|---|
| 165 | int h = bbits.height();
|
|---|
| 166 |
|
|---|
| 167 | uchar* xBits = new uchar[sysH * sysN];
|
|---|
| 168 | uchar* xMask = new uchar[sysH * sysN];
|
|---|
| 169 | int x = 0;
|
|---|
| 170 | for (int i = 0; i < sysH; ++i) {
|
|---|
| 171 | if (i >= h) {
|
|---|
| 172 | memset(&xBits[x] , 255, sysN);
|
|---|
| 173 | memset(&xMask[x] , 0, sysN);
|
|---|
| 174 | x += sysN;
|
|---|
| 175 | } else {
|
|---|
| 176 | int fillWidth = n > sysN ? sysN : n;
|
|---|
| 177 | uchar *bits = bbits.scanLine(i);
|
|---|
| 178 | uchar *mask = mbits.scanLine(i);
|
|---|
| 179 | for (int j = 0; j < fillWidth; ++j) {
|
|---|
| 180 | uchar b = bits[j];
|
|---|
| 181 | uchar m = mask[j];
|
|---|
| 182 | if (invb)
|
|---|
| 183 | b ^= 0xFF;
|
|---|
| 184 | if (invm)
|
|---|
| 185 | m ^= 0xFF;
|
|---|
| 186 | xBits[x] = ~m;
|
|---|
| 187 | xMask[x] = b ^ m;
|
|---|
| 188 | ++x;
|
|---|
| 189 | }
|
|---|
| 190 | for (int j = fillWidth; j < sysN; ++j ) {
|
|---|
| 191 | xBits[x] = 255;
|
|---|
| 192 | xMask[x] = 0;
|
|---|
| 193 | ++x;
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | cur = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
|
|---|
| 199 | xBits, xMask);
|
|---|
| 200 | #else
|
|---|
| 201 | Q_UNUSED(pixmap);
|
|---|
| 202 | Q_UNUSED(hx);
|
|---|
| 203 | Q_UNUSED(hy);
|
|---|
| 204 | #endif
|
|---|
| 205 | return cur;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | void QCursorData::update()
|
|---|
| 209 | {
|
|---|
| 210 | if (!QCursorData::initialized)
|
|---|
| 211 | QCursorData::initialize();
|
|---|
| 212 | if (hcurs)
|
|---|
| 213 | return;
|
|---|
| 214 |
|
|---|
| 215 | if (cshape == Qt::BitmapCursor && !pixmap.isNull()) {
|
|---|
| 216 | hcurs = create32BitCursor(pixmap, hx, hy);
|
|---|
| 217 | if (hcurs)
|
|---|
| 218 | return;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 | // Non-standard Windows cursors are created from bitmaps
|
|---|
| 223 |
|
|---|
| 224 | static const uchar vsplit_bits[] = {
|
|---|
| 225 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 226 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 227 | 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
|
|---|
| 228 | 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
|
|---|
| 229 | 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
|
|---|
| 230 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
|
|---|
| 231 | 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
|
|---|
| 232 | 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
|
|---|
| 233 | 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 234 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 235 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 236 | static const uchar vsplitm_bits[] = {
|
|---|
| 237 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 238 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
|
|---|
| 239 | 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
|
|---|
| 240 | 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
|
|---|
| 241 | 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
|
|---|
| 242 | 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
|
|---|
| 243 | 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
|
|---|
| 244 | 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
|
|---|
| 245 | 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
|
|---|
| 246 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 248 | static const uchar hsplit_bits[] = {
|
|---|
| 249 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 250 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 251 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
|
|---|
| 252 | 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
|
|---|
| 253 | 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
|
|---|
| 254 | 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
|
|---|
| 255 | 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
|
|---|
| 256 | 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 257 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 258 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 259 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 260 | static const uchar hsplitm_bits[] = {
|
|---|
| 261 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 262 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 263 | 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
|
|---|
| 264 | 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
|
|---|
| 265 | 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
|
|---|
| 266 | 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
|
|---|
| 267 | 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
|
|---|
| 268 | 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 269 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 270 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 272 | static const uchar phand_bits[] = {
|
|---|
| 273 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,
|
|---|
| 274 | 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,
|
|---|
| 275 | 0x80, 0x1c, 0x00, 0x00, 0x80, 0xe4, 0x00, 0x00, 0x80, 0x24, 0x03, 0x00,
|
|---|
| 276 | 0x80, 0x24, 0x05, 0x00, 0xb8, 0x24, 0x09, 0x00, 0xc8, 0x00, 0x09, 0x00,
|
|---|
| 277 | 0x88, 0x00, 0x08, 0x00, 0x90, 0x00, 0x08, 0x00, 0xa0, 0x00, 0x08, 0x00,
|
|---|
| 278 | 0x20, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x04, 0x00,
|
|---|
| 279 | 0x80, 0x00, 0x04, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x01, 0x02, 0x00,
|
|---|
| 280 | 0x00, 0x01, 0x02, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 281 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 282 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 283 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 284 |
|
|---|
| 285 | static const uchar phandm_bits[] = {
|
|---|
| 286 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00,
|
|---|
| 287 | 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00,
|
|---|
| 288 | 0x80, 0x1f, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00,
|
|---|
| 289 | 0x80, 0xff, 0x07, 0x00, 0xb8, 0xff, 0x0f, 0x00, 0xf8, 0xff, 0x0f, 0x00,
|
|---|
| 290 | 0xf8, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0x0f, 0x00,
|
|---|
| 291 | 0xe0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x07, 0x00,
|
|---|
| 292 | 0x80, 0xff, 0x07, 0x00, 0x80, 0xff, 0x07, 0x00, 0x00, 0xff, 0x03, 0x00,
|
|---|
| 293 | 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 294 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 295 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 296 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 297 |
|
|---|
| 298 | static const uchar openhand_bits[] = {
|
|---|
| 299 | 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92,
|
|---|
| 300 | 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20,
|
|---|
| 301 | 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00};
|
|---|
| 302 | static const uchar openhandm_bits[] = {
|
|---|
| 303 | 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff,
|
|---|
| 304 | 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f,
|
|---|
| 305 | 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00};
|
|---|
| 306 | static const uchar closedhand_bits[] = {
|
|---|
| 307 | 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50,
|
|---|
| 308 | 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,
|
|---|
| 309 | 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00};
|
|---|
| 310 | static const uchar closedhandm_bits[] = {
|
|---|
| 311 | 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f,
|
|---|
| 312 | 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f,
|
|---|
| 313 | 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00};
|
|---|
| 314 |
|
|---|
| 315 | static const uchar * const cursor_bits32[] = {
|
|---|
| 316 | vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits,
|
|---|
| 317 | phand_bits, phandm_bits
|
|---|
| 318 | };
|
|---|
| 319 |
|
|---|
| 320 | unsigned short *sh;
|
|---|
| 321 | switch (cshape) { // map to windows cursor
|
|---|
| 322 | case Qt::ArrowCursor:
|
|---|
| 323 | sh = (unsigned short*)IDC_ARROW;
|
|---|
| 324 | break;
|
|---|
| 325 | case Qt::UpArrowCursor:
|
|---|
| 326 | sh = (unsigned short*)IDC_UPARROW;
|
|---|
| 327 | break;
|
|---|
| 328 | case Qt::CrossCursor:
|
|---|
| 329 | sh = (unsigned short*)IDC_CROSS;
|
|---|
| 330 | break;
|
|---|
| 331 | case Qt::WaitCursor:
|
|---|
| 332 | sh = (unsigned short*)IDC_WAIT;
|
|---|
| 333 | break;
|
|---|
| 334 | case Qt::IBeamCursor:
|
|---|
| 335 | sh = (unsigned short*)IDC_IBEAM;
|
|---|
| 336 | break;
|
|---|
| 337 | case Qt::SizeVerCursor:
|
|---|
| 338 | sh = (unsigned short*)IDC_SIZENS;
|
|---|
| 339 | break;
|
|---|
| 340 | case Qt::SizeHorCursor:
|
|---|
| 341 | sh = (unsigned short*)IDC_SIZEWE;
|
|---|
| 342 | break;
|
|---|
| 343 | case Qt::SizeBDiagCursor:
|
|---|
| 344 | sh = (unsigned short*)IDC_SIZENESW;
|
|---|
| 345 | break;
|
|---|
| 346 | case Qt::SizeFDiagCursor:
|
|---|
| 347 | sh = (unsigned short*)IDC_SIZENWSE;
|
|---|
| 348 | break;
|
|---|
| 349 | case Qt::SizeAllCursor:
|
|---|
| 350 | sh = (unsigned short*)IDC_SIZEALL;
|
|---|
| 351 | break;
|
|---|
| 352 | case Qt::ForbiddenCursor:
|
|---|
| 353 | sh = (unsigned short*)IDC_NO;
|
|---|
| 354 | break;
|
|---|
| 355 | case Qt::WhatsThisCursor:
|
|---|
| 356 | sh = (unsigned short*)IDC_HELP;
|
|---|
| 357 | break;
|
|---|
| 358 | case Qt::BusyCursor:
|
|---|
| 359 | sh = (unsigned short*)IDC_APPSTARTING;
|
|---|
| 360 | break;
|
|---|
| 361 | case Qt::PointingHandCursor:
|
|---|
| 362 | if ((QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) > QSysInfo::WV_95 ||
|
|---|
| 363 | (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) > QSysInfo::WV_NT) {
|
|---|
| 364 | sh = (unsigned short*)IDC_HAND;
|
|---|
| 365 | break;
|
|---|
| 366 | }
|
|---|
| 367 | // fall through
|
|---|
| 368 | case Qt::BlankCursor:
|
|---|
| 369 | case Qt::SplitVCursor:
|
|---|
| 370 | case Qt::SplitHCursor:
|
|---|
| 371 | case Qt::OpenHandCursor:
|
|---|
| 372 | case Qt::ClosedHandCursor:
|
|---|
| 373 | case Qt::BitmapCursor: {
|
|---|
| 374 | QImage bbits, mbits;
|
|---|
| 375 | bool invb, invm;
|
|---|
| 376 | if (cshape == Qt::BlankCursor) {
|
|---|
| 377 | bbits = QImage(32, 32, QImage::Format_Mono);
|
|---|
| 378 | bbits.fill(0); // ignore color table
|
|---|
| 379 | mbits = bbits.copy();
|
|---|
| 380 | hx = hy = 16;
|
|---|
| 381 | invb = invm = false;
|
|---|
| 382 | } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) {
|
|---|
| 383 | bool open = cshape == Qt::OpenHandCursor;
|
|---|
| 384 | QBitmap cb = QBitmap::fromData(QSize(16, 16), open ? openhand_bits : closedhand_bits);
|
|---|
| 385 | QBitmap cm = QBitmap::fromData(QSize(16, 16), open ? openhandm_bits : closedhandm_bits);
|
|---|
| 386 | bbits = cb.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 387 | mbits = cm.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 388 | hx = hy = 8;
|
|---|
| 389 | invb = invm = false;
|
|---|
| 390 | } else if (cshape != Qt::BitmapCursor) {
|
|---|
| 391 | int i = cshape - Qt::SplitVCursor;
|
|---|
| 392 | QBitmap cb = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2]);
|
|---|
| 393 | QBitmap cm = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2 + 1]);
|
|---|
| 394 | bbits = cb.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 395 | mbits = cm.toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 396 | if (cshape == Qt::PointingHandCursor) {
|
|---|
| 397 | hx = 7;
|
|---|
| 398 | hy = 0;
|
|---|
| 399 | } else
|
|---|
| 400 | hx = hy = 16;
|
|---|
| 401 | invb = invm = false;
|
|---|
| 402 | } else {
|
|---|
| 403 | bbits = bm->toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 404 | mbits = bmm->toImage().convertToFormat(QImage::Format_Mono);
|
|---|
| 405 | invb = bbits.numColors() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
|
|---|
| 406 | invm = mbits.numColors() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));
|
|---|
| 407 | }
|
|---|
| 408 | int n = qMax(1, bbits.width() / 8);
|
|---|
| 409 | int h = bbits.height();
|
|---|
| 410 | #if !defined(Q_OS_WINCE)
|
|---|
| 411 | uchar* xBits = new uchar[h * n];
|
|---|
| 412 | uchar* xMask = new uchar[h * n];
|
|---|
| 413 | int x = 0;
|
|---|
| 414 | for (int i = 0; i < h; ++i) {
|
|---|
| 415 | uchar *bits = bbits.scanLine(i);
|
|---|
| 416 | uchar *mask = mbits.scanLine(i);
|
|---|
| 417 | for (int j = 0; j < n; ++j) {
|
|---|
| 418 | uchar b = bits[j];
|
|---|
| 419 | uchar m = mask[j];
|
|---|
| 420 | if (invb)
|
|---|
| 421 | b ^= 0xff;
|
|---|
| 422 | if (invm)
|
|---|
| 423 | m ^= 0xff;
|
|---|
| 424 | xBits[x] = ~m;
|
|---|
| 425 | xMask[x] = b ^ m;
|
|---|
| 426 | ++x;
|
|---|
| 427 | }
|
|---|
| 428 | }
|
|---|
| 429 | hcurs = CreateCursor(qWinAppInst(), hx, hy, bbits.width(), bbits.height(),
|
|---|
| 430 | xBits, xMask);
|
|---|
| 431 | delete [] xBits;
|
|---|
| 432 | delete [] xMask;
|
|---|
| 433 | #elif defined(GWES_ICONCURS) // Q_OS_WINCE
|
|---|
| 434 | // Windows CE only supports fixed cursor size.
|
|---|
| 435 | int sysW = GetSystemMetrics(SM_CXCURSOR);
|
|---|
| 436 | int sysH = GetSystemMetrics(SM_CYCURSOR);
|
|---|
| 437 | int sysN = qMax(1, sysW / 8);
|
|---|
| 438 | uchar* xBits = new uchar[sysH * sysN];
|
|---|
| 439 | uchar* xMask = new uchar[sysH * sysN];
|
|---|
| 440 | int x = 0;
|
|---|
| 441 | for (int i = 0; i < sysH; ++i) {
|
|---|
| 442 | if (i >= h) {
|
|---|
| 443 | memset(&xBits[x] , 255, sysN);
|
|---|
| 444 | memset(&xMask[x] , 0, sysN);
|
|---|
| 445 | x += sysN;
|
|---|
| 446 | } else {
|
|---|
| 447 | int fillWidth = n > sysN ? sysN : n;
|
|---|
| 448 | uchar *bits = bbits.scanLine(i);
|
|---|
| 449 | uchar *mask = mbits.scanLine(i);
|
|---|
| 450 | for (int j = 0; j < fillWidth; ++j) {
|
|---|
| 451 | uchar b = bits[j];
|
|---|
| 452 | uchar m = mask[j];
|
|---|
| 453 | if (invb)
|
|---|
| 454 | b ^= 0xFF;
|
|---|
| 455 | if (invm)
|
|---|
| 456 | m ^= 0xFF;
|
|---|
| 457 | xBits[x] = ~m;
|
|---|
| 458 | xMask[x] = b ^ m;
|
|---|
| 459 | ++x;
|
|---|
| 460 | }
|
|---|
| 461 | for (int j = fillWidth; j < sysN; ++j ) {
|
|---|
| 462 | xBits[x] = 255;
|
|---|
| 463 | xMask[x] = 0;
|
|---|
| 464 | ++x;
|
|---|
| 465 | }
|
|---|
| 466 | }
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | hcurs = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
|
|---|
| 470 | xBits, xMask);
|
|---|
| 471 | delete [] xBits;
|
|---|
| 472 | delete [] xMask;
|
|---|
| 473 | #else
|
|---|
| 474 | Q_UNUSED(n);
|
|---|
| 475 | Q_UNUSED(h);
|
|---|
| 476 | #endif
|
|---|
| 477 | return;
|
|---|
| 478 | }
|
|---|
| 479 | default:
|
|---|
| 480 | qWarning("QCursor::update: Invalid cursor shape %d", cshape);
|
|---|
| 481 | return;
|
|---|
| 482 | }
|
|---|
| 483 | // ### From MSDN:
|
|---|
| 484 | // ### LoadCursor has been superseded by the LoadImage function.
|
|---|
| 485 | QT_WA({
|
|---|
| 486 | hcurs = LoadCursorW(0, reinterpret_cast<const TCHAR *>(sh));
|
|---|
| 487 | } , {
|
|---|
| 488 | hcurs = LoadCursorA(0, reinterpret_cast<const char*>(sh));
|
|---|
| 489 | });
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | QT_END_NAMESPACE
|
|---|
| 493 | #endif // QT_NO_CURSOR
|
|---|