source: trunk/src/gui/kernel/qcursor_pm.cpp@ 477

Last change on this file since 477 was 182, checked in by Dmitry A. Kuminov, 16 years ago

gui: Implemented standard cursor shapes (#54).

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author Id
File size: 5.4 KB
Line 
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
55QT_BEGIN_NAMESPACE
56
57extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
58
59/*****************************************************************************
60 Internal QCursorData class
61 *****************************************************************************/
62
63QCursorData::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
69QCursorData::~QCursorData()
70{
71 delete bm;
72 delete bmm;
73 if (hptr && !isSysPtr)
74 WinDestroyPointer(hptr);
75}
76
77
78QCursorData *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
98HPOINTER 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
107QCursor::QCursor(HPOINTER handle)
108{
109 d = new QCursorData(Qt::CustomCursor);
110 d->hptr = handle;
111}
112
113#endif //QT_NO_CURSOR
114
115QPoint 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
124void 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
133void 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;