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