1 /*
2 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
3 * Copyright (C) 2006 George Staikos <staikos@kde.org>
4 * Copyright (C) 2006 Charles Samuels <charles@kde.org>
5 * Copyright (C) 2008, 2009 Holger Hans Peter Freyther
6 * Copyright (C) 2010 University of Szeged
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "config.h"
33 #include "Cursor.h"
34
35 #include "Image.h"
36 #include "IntPoint.h"
37
38 #include "NotImplemented.h"
39
40 #include <stdio.h>
41 #include <stdlib.h>
42
43 #undef CopyCursor
44
45 namespace WebCore {
46
Cursor(const Cursor & other)47 Cursor::Cursor(const Cursor& other)
48 : m_type(other.m_type)
49 , m_image(other.m_image)
50 , m_hotSpot(other.m_hotSpot)
51 #ifndef QT_NO_CURSOR
52 , m_platformCursor(other.m_platformCursor ? new QCursor(*other.m_platformCursor) : 0)
53 #endif
54 {
55 }
56
~Cursor()57 Cursor::~Cursor()
58 {
59 #ifndef QT_NO_CURSOR
60 delete m_platformCursor;
61 #endif
62 }
63
operator =(const Cursor & other)64 Cursor& Cursor::operator=(const Cursor& other)
65 {
66 m_type = other.m_type;
67 m_image = other.m_image;
68 m_hotSpot = other.m_hotSpot;
69 #ifndef QT_NO_CURSOR
70 m_platformCursor = other.m_platformCursor ? new QCursor(*other.m_platformCursor) : 0;
71 #endif
72 return *this;
73 }
74
75 #ifndef QT_NO_CURSOR
createCustomCursor(Image * image,const IntPoint & hotSpot)76 static QCursor* createCustomCursor(Image* image, const IntPoint& hotSpot)
77 {
78 IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
79 return new QCursor(*(image->nativeImageForCurrentFrame()), effectiveHotSpot.x(), effectiveHotSpot.y());
80 }
81 #endif
82
ensurePlatformCursor() const83 void Cursor::ensurePlatformCursor() const
84 {
85 #ifndef QT_NO_CURSOR
86 if (m_platformCursor)
87 return;
88
89 switch (m_type) {
90 case Pointer:
91 m_platformCursor = new QCursor(Qt::ArrowCursor);
92 break;
93 case Cross:
94 m_platformCursor = new QCursor(Qt::CrossCursor);
95 break;
96 case Hand:
97 m_platformCursor = new QCursor(Qt::PointingHandCursor);
98 break;
99 case IBeam:
100 m_platformCursor = new QCursor(Qt::IBeamCursor);
101 break;
102 case Wait:
103 m_platformCursor = new QCursor(Qt::WaitCursor);
104 break;
105 case Help:
106 m_platformCursor = new QCursor(Qt::WhatsThisCursor);
107 break;
108 case EastResize:
109 case EastPanning:
110 m_platformCursor = new QCursor(Qt::SizeHorCursor);
111 break;
112 case NorthResize:
113 case NorthPanning:
114 m_platformCursor = new QCursor(Qt::SizeVerCursor);
115 break;
116 case NorthEastResize:
117 case NorthEastPanning:
118 m_platformCursor = new QCursor(Qt::SizeBDiagCursor);
119 break;
120 case NorthWestResize:
121 case NorthWestPanning:
122 m_platformCursor = new QCursor(Qt::SizeFDiagCursor);
123 break;
124 case SouthResize:
125 case SouthPanning:
126 m_platformCursor = new QCursor(Qt::SizeVerCursor);
127 break;
128 case SouthEastResize:
129 case SouthEastPanning:
130 m_platformCursor = new QCursor(Qt::SizeFDiagCursor);
131 break;
132 case SouthWestResize:
133 case SouthWestPanning:
134 m_platformCursor = new QCursor(Qt::SizeBDiagCursor);
135 break;
136 case WestResize:
137 case WestPanning:
138 m_platformCursor = new QCursor(Qt::SizeHorCursor);
139 break;
140 case NorthSouthResize:
141 m_platformCursor = new QCursor(Qt::SizeVerCursor);
142 break;
143 case EastWestResize:
144 m_platformCursor = new QCursor(Qt::SizeHorCursor);
145 break;
146 case NorthEastSouthWestResize:
147 m_platformCursor = new QCursor(Qt::SizeBDiagCursor);
148 break;
149 case NorthWestSouthEastResize:
150 m_platformCursor = new QCursor(Qt::SizeFDiagCursor);
151 break;
152 case ColumnResize:
153 m_platformCursor = new QCursor(Qt::SplitHCursor);
154 break;
155 case RowResize:
156 m_platformCursor = new QCursor(Qt::SplitVCursor);
157 break;
158 case MiddlePanning:
159 case Move:
160 m_platformCursor = new QCursor(Qt::SizeAllCursor);
161 break;
162 case None:
163 m_platformCursor = new QCursor(Qt::BlankCursor);
164 break;
165 case NoDrop:
166 case NotAllowed:
167 m_platformCursor = new QCursor(Qt::ForbiddenCursor);
168 break;
169 case Grab:
170 case Grabbing:
171 notImplemented();
172 m_platformCursor = new QCursor(Qt::ArrowCursor);
173 break;
174 case VerticalText:
175 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/verticalTextCursor.png")), 7, 7);
176 break;
177 case Cell:
178 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/cellCursor.png")), 7, 7);
179 break;
180 case ContextMenu:
181 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/contextMenuCursor.png")), 3, 2);
182 break;
183 case Alias:
184 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/aliasCursor.png")), 11, 3);
185 break;
186 case Progress:
187 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/progressCursor.png")), 3, 2);
188 break;
189 case Copy:
190 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/copyCursor.png")), 3, 2);
191 break;
192 case ZoomIn:
193 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/zoomInCursor.png")), 7, 7);
194 break;
195 case ZoomOut:
196 m_platformCursor = new QCursor(QPixmap(QLatin1String(":/webkit/resources/zoomOutCursor.png")), 7, 7);
197 break;
198 case Custom:
199 m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot);
200 break;
201 default:
202 ASSERT_NOT_REACHED();
203 }
204 #endif
205 }
206
207 }
208
209 // vim: ts=4 sw=4 et
210