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 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "Cursor.h"
33
34 #include "Image.h"
35 #include "IntPoint.h"
36
37 #include "NotImplemented.h"
38
39 #include <stdio.h>
40 #include <stdlib.h>
41
42 #undef CopyCursor
43
44 namespace WebCore {
45
Cursor(PlatformCursor p)46 Cursor::Cursor(PlatformCursor p)
47 : m_impl(p)
48 {
49 }
50
Cursor(const Cursor & other)51 Cursor::Cursor(const Cursor& other)
52 : m_impl(other.m_impl)
53 {
54 }
55
~Cursor()56 Cursor::~Cursor()
57 {
58 }
59
Cursor(Image * image,const IntPoint & hotspot)60 Cursor::Cursor(Image* image, const IntPoint& hotspot)
61 #ifndef QT_NO_CURSOR
62 : m_impl(*(image->nativeImageForCurrentFrame()), hotspot.x(), hotspot.y())
63 #endif
64 {
65 }
66
operator =(const Cursor & other)67 Cursor& Cursor::operator=(const Cursor& other)
68 {
69 m_impl = other.m_impl;
70 return *this;
71 }
72
73 namespace {
74
75 // FIXME: static deleter
76 class Cursors : public Noncopyable {
77 protected:
Cursors()78 Cursors()
79 #ifndef QT_NO_CURSOR
80 : CrossCursor(Qt::CrossCursor)
81 , MoveCursor(Qt::SizeAllCursor)
82 , PointerCursor(Qt::ArrowCursor)
83 , PointingHandCursor(Qt::PointingHandCursor)
84 , IBeamCursor(Qt::IBeamCursor)
85 , WaitCursor(Qt::WaitCursor)
86 , WhatsThisCursor(Qt::WhatsThisCursor)
87 , SizeHorCursor(Qt::SizeHorCursor)
88 , SizeVerCursor(Qt::SizeVerCursor)
89 , SizeFDiagCursor(Qt::SizeFDiagCursor)
90 , SizeBDiagCursor(Qt::SizeBDiagCursor)
91 , SplitHCursor(Qt::SplitHCursor)
92 , SplitVCursor(Qt::SplitVCursor)
93 , NoDropCursor(Qt::ForbiddenCursor)
94 , BlankCursor(Qt::BlankCursor)
95 , ZoomInCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/zoomInCursor.png")), 7, 7))
96 , ZoomOutCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/zoomOutCursor.png")), 7, 7))
97 , VerticalTextCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/verticalTextCursor.png")), 7, 7))
98 , CellCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/cellCursor.png")), 7, 7))
99 , ContextMenuCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/contextMenuCursor.png")), 3, 2))
100 , CopyCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/copyCursor.png")), 3, 2))
101 , ProgressCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/progressCursor.png")), 3, 2))
102 , AliasCursor(QCursor(QPixmap(QLatin1String(":/webkit/resources/aliasCursor.png")), 11, 3))
103
104 #endif
105 {
106 }
107
~Cursors()108 ~Cursors()
109 {
110 }
111
112 public:
113 static Cursors* self();
114 static Cursors* s_self;
115
116 Cursor CrossCursor;
117 Cursor MoveCursor;
118 Cursor PointerCursor;
119 Cursor PointingHandCursor;
120 Cursor IBeamCursor;
121 Cursor WaitCursor;
122 Cursor WhatsThisCursor;
123 Cursor SizeHorCursor;
124 Cursor SizeVerCursor;
125 Cursor SizeFDiagCursor;
126 Cursor SizeBDiagCursor;
127 Cursor SplitHCursor;
128 Cursor SplitVCursor;
129 Cursor NoDropCursor;
130 Cursor BlankCursor;
131 Cursor ZoomInCursor;
132 Cursor ZoomOutCursor;
133 Cursor VerticalTextCursor;
134 Cursor CellCursor;
135 Cursor ContextMenuCursor;
136 Cursor CopyCursor;
137 Cursor ProgressCursor;
138 Cursor AliasCursor;
139 };
140
141 Cursors* Cursors::s_self = 0;
142
self()143 Cursors* Cursors::self()
144 {
145 if (!s_self)
146 s_self = new Cursors();
147
148 return s_self;
149 }
150
151 }
152
pointerCursor()153 const Cursor& pointerCursor()
154 {
155 return Cursors::self()->PointerCursor;
156 }
157
moveCursor()158 const Cursor& moveCursor()
159 {
160 return Cursors::self()->MoveCursor;
161 }
162
crossCursor()163 const Cursor& crossCursor()
164 {
165 return Cursors::self()->CrossCursor;
166 }
167
handCursor()168 const Cursor& handCursor()
169 {
170 return Cursors::self()->PointingHandCursor;
171 }
172
iBeamCursor()173 const Cursor& iBeamCursor()
174 {
175 return Cursors::self()->IBeamCursor;
176 }
177
waitCursor()178 const Cursor& waitCursor()
179 {
180 return Cursors::self()->WaitCursor;
181 }
182
helpCursor()183 const Cursor& helpCursor()
184 {
185 return Cursors::self()->WhatsThisCursor;
186 }
187
eastResizeCursor()188 const Cursor& eastResizeCursor()
189 {
190 return Cursors::self()->SizeHorCursor;
191 }
192
northResizeCursor()193 const Cursor& northResizeCursor()
194 {
195 return Cursors::self()->SizeVerCursor;
196 }
197
northEastResizeCursor()198 const Cursor& northEastResizeCursor()
199 {
200 return Cursors::self()->SizeBDiagCursor;
201 }
202
northWestResizeCursor()203 const Cursor& northWestResizeCursor()
204 {
205 return Cursors::self()->SizeFDiagCursor;
206 }
207
southResizeCursor()208 const Cursor& southResizeCursor()
209 {
210 return Cursors::self()->SizeVerCursor;
211 }
212
southEastResizeCursor()213 const Cursor& southEastResizeCursor()
214 {
215 return Cursors::self()->SizeFDiagCursor;
216 }
217
southWestResizeCursor()218 const Cursor& southWestResizeCursor()
219 {
220 return Cursors::self()->SizeBDiagCursor;
221 }
222
westResizeCursor()223 const Cursor& westResizeCursor()
224 {
225 return Cursors::self()->SizeHorCursor;
226 }
227
northSouthResizeCursor()228 const Cursor& northSouthResizeCursor()
229 {
230 return Cursors::self()->SizeVerCursor;
231 }
232
eastWestResizeCursor()233 const Cursor& eastWestResizeCursor()
234 {
235 return Cursors::self()->SizeHorCursor;
236 }
237
northEastSouthWestResizeCursor()238 const Cursor& northEastSouthWestResizeCursor()
239 {
240 return Cursors::self()->SizeBDiagCursor;
241 }
242
northWestSouthEastResizeCursor()243 const Cursor& northWestSouthEastResizeCursor()
244 {
245 return Cursors::self()->SizeFDiagCursor;
246 }
247
columnResizeCursor()248 const Cursor& columnResizeCursor()
249 {
250 return Cursors::self()->SplitHCursor;
251 }
252
rowResizeCursor()253 const Cursor& rowResizeCursor()
254 {
255 return Cursors::self()->SplitVCursor;
256 }
257
middlePanningCursor()258 const Cursor& middlePanningCursor()
259 {
260 return moveCursor();
261 }
262
eastPanningCursor()263 const Cursor& eastPanningCursor()
264 {
265 return eastResizeCursor();
266 }
267
northPanningCursor()268 const Cursor& northPanningCursor()
269 {
270 return northResizeCursor();
271 }
272
northEastPanningCursor()273 const Cursor& northEastPanningCursor()
274 {
275 return northEastResizeCursor();
276 }
277
northWestPanningCursor()278 const Cursor& northWestPanningCursor()
279 {
280 return northWestResizeCursor();
281 }
282
southPanningCursor()283 const Cursor& southPanningCursor()
284 {
285 return southResizeCursor();
286 }
287
southEastPanningCursor()288 const Cursor& southEastPanningCursor()
289 {
290 return southEastResizeCursor();
291 }
292
southWestPanningCursor()293 const Cursor& southWestPanningCursor()
294 {
295 return southWestResizeCursor();
296 }
297
westPanningCursor()298 const Cursor& westPanningCursor()
299 {
300 return westResizeCursor();
301 }
302
verticalTextCursor()303 const Cursor& verticalTextCursor()
304 {
305 return Cursors::self()->VerticalTextCursor;
306 }
307
cellCursor()308 const Cursor& cellCursor()
309 {
310 return Cursors::self()->CellCursor;
311 }
312
contextMenuCursor()313 const Cursor& contextMenuCursor()
314 {
315 return Cursors::self()->ContextMenuCursor;
316 }
317
noDropCursor()318 const Cursor& noDropCursor()
319 {
320 return Cursors::self()->NoDropCursor;
321 }
322
copyCursor()323 const Cursor& copyCursor()
324 {
325 return Cursors::self()->CopyCursor;
326 }
327
progressCursor()328 const Cursor& progressCursor()
329 {
330 return Cursors::self()->ProgressCursor;
331 }
332
aliasCursor()333 const Cursor& aliasCursor()
334 {
335 return Cursors::self()->AliasCursor;
336 }
337
noneCursor()338 const Cursor& noneCursor()
339 {
340 return Cursors::self()->BlankCursor;
341 }
342
notAllowedCursor()343 const Cursor& notAllowedCursor()
344 {
345 return Cursors::self()->NoDropCursor;
346 }
347
zoomInCursor()348 const Cursor& zoomInCursor()
349 {
350 return Cursors::self()->ZoomInCursor;
351 }
352
zoomOutCursor()353 const Cursor& zoomOutCursor()
354 {
355 return Cursors::self()->ZoomOutCursor;
356 }
357
grabCursor()358 const Cursor& grabCursor()
359 {
360 notImplemented();
361 return Cursors::self()->PointerCursor;
362 }
363
grabbingCursor()364 const Cursor& grabbingCursor()
365 {
366 notImplemented();
367 return Cursors::self()->PointerCursor;
368 }
369
370 }
371
372 // vim: ts=4 sw=4 et
373