1 /* 2 * Copyright (C) 2006 Dirk Mueller <mueller (at) kde.org> 3 * Copyright (C) 2006 George Staikos <staikos (at) kde.org> 4 * Copyright (C) 2006 Charles Samuels <charles (at) 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 46 Cursor::Cursor(PlatformCursor p) 47 : m_impl(p) 48 { 49 } 50 51 Cursor::Cursor(const Cursor& other) 52 : m_impl(other.m_impl) 53 { 54 } 55 56 Cursor::~Cursor() 57 { 58 } 59 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 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: 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 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 143 Cursors* Cursors::self() 144 { 145 if (!s_self) 146 s_self = new Cursors(); 147 148 return s_self; 149 } 150 151 } 152 153 const Cursor& pointerCursor() 154 { 155 return Cursors::self()->PointerCursor; 156 } 157 158 const Cursor& moveCursor() 159 { 160 return Cursors::self()->MoveCursor; 161 } 162 163 const Cursor& crossCursor() 164 { 165 return Cursors::self()->CrossCursor; 166 } 167 168 const Cursor& handCursor() 169 { 170 return Cursors::self()->PointingHandCursor; 171 } 172 173 const Cursor& iBeamCursor() 174 { 175 return Cursors::self()->IBeamCursor; 176 } 177 178 const Cursor& waitCursor() 179 { 180 return Cursors::self()->WaitCursor; 181 } 182 183 const Cursor& helpCursor() 184 { 185 return Cursors::self()->WhatsThisCursor; 186 } 187 188 const Cursor& eastResizeCursor() 189 { 190 return Cursors::self()->SizeHorCursor; 191 } 192 193 const Cursor& northResizeCursor() 194 { 195 return Cursors::self()->SizeVerCursor; 196 } 197 198 const Cursor& northEastResizeCursor() 199 { 200 return Cursors::self()->SizeBDiagCursor; 201 } 202 203 const Cursor& northWestResizeCursor() 204 { 205 return Cursors::self()->SizeFDiagCursor; 206 } 207 208 const Cursor& southResizeCursor() 209 { 210 return Cursors::self()->SizeVerCursor; 211 } 212 213 const Cursor& southEastResizeCursor() 214 { 215 return Cursors::self()->SizeFDiagCursor; 216 } 217 218 const Cursor& southWestResizeCursor() 219 { 220 return Cursors::self()->SizeBDiagCursor; 221 } 222 223 const Cursor& westResizeCursor() 224 { 225 return Cursors::self()->SizeHorCursor; 226 } 227 228 const Cursor& northSouthResizeCursor() 229 { 230 return Cursors::self()->SizeVerCursor; 231 } 232 233 const Cursor& eastWestResizeCursor() 234 { 235 return Cursors::self()->SizeHorCursor; 236 } 237 238 const Cursor& northEastSouthWestResizeCursor() 239 { 240 return Cursors::self()->SizeBDiagCursor; 241 } 242 243 const Cursor& northWestSouthEastResizeCursor() 244 { 245 return Cursors::self()->SizeFDiagCursor; 246 } 247 248 const Cursor& columnResizeCursor() 249 { 250 return Cursors::self()->SplitHCursor; 251 } 252 253 const Cursor& rowResizeCursor() 254 { 255 return Cursors::self()->SplitVCursor; 256 } 257 258 const Cursor& middlePanningCursor() 259 { 260 return moveCursor(); 261 } 262 263 const Cursor& eastPanningCursor() 264 { 265 return eastResizeCursor(); 266 } 267 268 const Cursor& northPanningCursor() 269 { 270 return northResizeCursor(); 271 } 272 273 const Cursor& northEastPanningCursor() 274 { 275 return northEastResizeCursor(); 276 } 277 278 const Cursor& northWestPanningCursor() 279 { 280 return northWestResizeCursor(); 281 } 282 283 const Cursor& southPanningCursor() 284 { 285 return southResizeCursor(); 286 } 287 288 const Cursor& southEastPanningCursor() 289 { 290 return southEastResizeCursor(); 291 } 292 293 const Cursor& southWestPanningCursor() 294 { 295 return southWestResizeCursor(); 296 } 297 298 const Cursor& westPanningCursor() 299 { 300 return westResizeCursor(); 301 } 302 303 const Cursor& verticalTextCursor() 304 { 305 return Cursors::self()->VerticalTextCursor; 306 } 307 308 const Cursor& cellCursor() 309 { 310 return Cursors::self()->CellCursor; 311 } 312 313 const Cursor& contextMenuCursor() 314 { 315 return Cursors::self()->ContextMenuCursor; 316 } 317 318 const Cursor& noDropCursor() 319 { 320 return Cursors::self()->NoDropCursor; 321 } 322 323 const Cursor& copyCursor() 324 { 325 return Cursors::self()->CopyCursor; 326 } 327 328 const Cursor& progressCursor() 329 { 330 return Cursors::self()->ProgressCursor; 331 } 332 333 const Cursor& aliasCursor() 334 { 335 return Cursors::self()->AliasCursor; 336 } 337 338 const Cursor& noneCursor() 339 { 340 return Cursors::self()->BlankCursor; 341 } 342 343 const Cursor& notAllowedCursor() 344 { 345 return Cursors::self()->NoDropCursor; 346 } 347 348 const Cursor& zoomInCursor() 349 { 350 return Cursors::self()->ZoomInCursor; 351 } 352 353 const Cursor& zoomOutCursor() 354 { 355 return Cursors::self()->ZoomOutCursor; 356 } 357 358 const Cursor& grabCursor() 359 { 360 notImplemented(); 361 return Cursors::self()->PointerCursor; 362 } 363 364 const Cursor& grabbingCursor() 365 { 366 notImplemented(); 367 return Cursors::self()->PointerCursor; 368 } 369 370 } 371 372 // vim: ts=4 sw=4 et 373