Qt 4.8
qcursor_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qcursor.h>
43 #include <private/qcursor_p.h>
44 #include <qbitmap.h>
45 #include <qwsdisplay_qws.h>
46 
48 
50 
51 #ifndef QT_NO_CURSOR
52 
54 
55 /*****************************************************************************
56  Internal QCursorData class
57  *****************************************************************************/
58 
60  : cshape(s), bm(0), bmm(0), hx(0), hy(0), id(s)
61 {
62  ref = 1;
63 }
64 
66 {
67  delete bm;
68  delete bmm;
69  QT_TRY {
71  } QT_CATCH(const std::bad_alloc &) {
72  // do nothing.
73  }
74 }
75 
76 
77 /*****************************************************************************
78  Global cursors
79  *****************************************************************************/
80 
81 int QCursor::handle() const
82 {
83  return d->id;
84 }
85 
86 
87 QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
88 {
91  if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
92  qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
94  c->ref.ref();
95  return c;
96  }
97  QCursorData *d = new QCursorData;
98  d->bm = new QBitmap(bitmap);
99  d->bmm = new QBitmap(mask);
101  d->id = ++nextCursorId;
102  d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
103  d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
104 
105  QPaintDevice::qwsDisplay()->defineCursor(d->id, *d->bm, *d->bmm, d->hx, d->hy);
106  return d;
107 }
108 
109 void QCursorData::update()
110 {
111 }
112 
113 #endif //QT_NO_CURSOR
114 
115 extern int *qt_last_x,*qt_last_y;
116 
118 {
119  // This doesn't know about hotspots yet so we disable it
120  //qt_accel_update_cursor();
121  if (qt_last_x)
122  return QPoint(*qt_last_x, *qt_last_y);
123  else
124  return QPoint();
125 }
126 
127 void QCursor::setPos(int x, int y)
128 {
129  // Need to check, since some X servers generate null mouse move
130  // events, causing looping in applications which call setPos() on
131  // every mouse move event.
132  //
133  if (pos() == QPoint(x, y))
134  return;
136 }
137 
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
double d
Definition: qnumeric_p.h:62
static int nextCursorId
Definition: qcursor_qws.cpp:53
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void setCursorPosition(int x, int y)
static QWSDisplay * qwsDisplay()
short hy
Definition: qcursor_p.h:91
int * qt_last_x
bool ref()
Atomically increments the value of this QAtomicInt.
static bool initialized
Definition: qcursor_p.h:125
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
int * qt_last_y
static QCursorData * setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
Definition: qcursor_mac.mm:278
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QCursorData(Qt::CursorShape s=Qt::ArrowCursor)
Definition: qcursor_mac.mm:253
void destroyCursor(int id)
Q_CORE_EXPORT void qWarning(const char *,...)
QCursorData * qt_cursorTable[Qt::LastCursor+1]
Definition: qcursor.cpp:398
#define QT_CATCH(A)
Definition: qglobal.h:1537
void update()
Creates the cursor.
Definition: qcursor_mac.mm:387
Qt::CursorShape cshape
Definition: qcursor_p.h:88
CursorShape
Definition: qnamespace.h:1262
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void defineCursor(int id, const QBitmap &curs, const QBitmap &mask, int hotX, int hotY)
short hx
Definition: qcursor_p.h:91
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
QBitmap * bmm
Definition: qcursor_p.h:89
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87
QBitmap * bm
Definition: qcursor_p.h:89
#define QT_TRY
Definition: qglobal.h:1536
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310