2 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
3 * Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "CursorGtk.h"
31 #include "NotImplemented.h"
32 #include <wtf/Assertions.h>
39 static GdkCursor* customCursorNew(CustomCursorType cursorType)
41 CustomCursor cursor = CustomCursors[cursorType];
42 GdkCursor* c = gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name);
44 const GdkColor fg = { 0, 0, 0, 0 };
45 const GdkColor bg = { 65535, 65535, 65535, 65535 };
47 GdkPixmap* source = gdk_bitmap_create_from_data(NULL, cursor.bits, 32, 32);
48 GdkPixmap* mask = gdk_bitmap_create_from_data(NULL, cursor.mask_bits, 32, 32);
49 c = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, cursor.hot_x, cursor.hot_y);
50 g_object_unref(source);
57 Cursor::Cursor(const Cursor& other)
58 : m_impl(other.m_impl)
61 gdk_cursor_ref(m_impl);
64 Cursor::Cursor(Image*, const IntPoint&)
66 // FIXME: We don't support images for cursors yet.
67 // This is just a placeholder to avoid crashes.
68 Cursor other(crossCursor());
69 m_impl = other.m_impl;
72 gdk_cursor_ref(m_impl);
78 gdk_cursor_unref(m_impl);
81 Cursor& Cursor::operator=(const Cursor& other)
83 gdk_cursor_ref(other.m_impl);
84 gdk_cursor_unref(m_impl);
85 m_impl = other.m_impl;
89 Cursor::Cursor(GdkCursor* c)
97 const Cursor& pointerCursor()
99 static Cursor c = gdk_cursor_new(GDK_LEFT_PTR);
103 const Cursor& crossCursor()
105 static Cursor c = gdk_cursor_new(GDK_CROSS);
109 const Cursor& handCursor()
111 static Cursor c = gdk_cursor_new(GDK_HAND2);
115 const Cursor& moveCursor()
117 static Cursor c = gdk_cursor_new(GDK_FLEUR);
121 const Cursor& iBeamCursor()
123 static Cursor c = gdk_cursor_new(GDK_XTERM);
127 const Cursor& waitCursor()
129 static Cursor c = gdk_cursor_new(GDK_WATCH);
133 const Cursor& helpCursor()
135 static Cursor c = gdk_cursor_new(GDK_QUESTION_ARROW);
139 const Cursor& eastResizeCursor()
141 static Cursor c = gdk_cursor_new(GDK_RIGHT_SIDE);
145 const Cursor& northResizeCursor()
147 static Cursor c = gdk_cursor_new(GDK_TOP_SIDE);
151 const Cursor& northEastResizeCursor()
153 static Cursor c = gdk_cursor_new(GDK_TOP_RIGHT_CORNER);
157 const Cursor& northWestResizeCursor()
159 static Cursor c = gdk_cursor_new(GDK_TOP_LEFT_CORNER);
163 const Cursor& southResizeCursor()
165 static Cursor c = gdk_cursor_new(GDK_BOTTOM_SIDE);
169 const Cursor& southEastResizeCursor()
171 static Cursor c = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
175 const Cursor& southWestResizeCursor()
177 static Cursor c = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
181 const Cursor& westResizeCursor()
183 static Cursor c = gdk_cursor_new(GDK_LEFT_SIDE);
187 const Cursor& northSouthResizeCursor()
189 static Cursor c = gdk_cursor_new(GDK_TOP_TEE);
193 const Cursor& eastWestResizeCursor()
195 static Cursor c = gdk_cursor_new(GDK_LEFT_SIDE);
199 const Cursor& northEastSouthWestResizeCursor()
201 static Cursor c = gdk_cursor_new(GDK_SIZING);
205 const Cursor& northWestSouthEastResizeCursor()
207 static Cursor c = gdk_cursor_new(GDK_SIZING);
211 const Cursor& columnResizeCursor()
213 static Cursor c = gdk_cursor_new(GDK_DOUBLE_ARROW);
217 const Cursor& rowResizeCursor()
219 static Cursor c = gdk_cursor_new(GDK_DOUBLE_ARROW);
223 const Cursor& middlePanningCursor()
228 const Cursor& eastPanningCursor()
230 return eastResizeCursor();
233 const Cursor& northPanningCursor()
235 return northResizeCursor();
238 const Cursor& northEastPanningCursor()
240 return northEastResizeCursor();
243 const Cursor& northWestPanningCursor()
245 return northWestResizeCursor();
248 const Cursor& southPanningCursor()
250 return southResizeCursor();
253 const Cursor& southEastPanningCursor()
255 return southEastResizeCursor();
258 const Cursor& southWestPanningCursor()
260 return southWestResizeCursor();
263 const Cursor& westPanningCursor()
265 return westResizeCursor();
269 const Cursor& verticalTextCursor()
271 static Cursor c = customCursorNew(CustomCursorVerticalText);
275 const Cursor& cellCursor()
278 return pointerCursor();
281 const Cursor& contextMenuCursor()
283 static Cursor c = customCursorNew(CustomCursorContextMenu);
287 const Cursor& noDropCursor()
290 return pointerCursor();
293 const Cursor& copyCursor()
295 static Cursor c = customCursorNew(CustomCursorCopy);
299 const Cursor& progressCursor()
302 return pointerCursor();
305 const Cursor& aliasCursor()
307 static Cursor c = customCursorNew(CustomCursorAlias);
311 const Cursor& noneCursor()
314 return pointerCursor();
317 const Cursor& notAllowedCursor()
320 return pointerCursor();
323 const Cursor& zoomInCursor()
325 static Cursor c = customCursorNew(CustomCursorZoomIn);
329 const Cursor& zoomOutCursor()
331 static Cursor c = customCursorNew(CustomCursorZoomOut);
335 const Cursor& grabCursor()
338 return pointerCursor();
341 const Cursor& grabbingCursor()
344 return pointerCursor();