]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/cursor.cpp
bitmap and image updates
[wxWidgets.git] / src / gtk / cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cursor.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "cursor.h"
13 #endif
14
15 #include "wx/cursor.h"
16 #include "wx/utils.h"
17
18 #include <gdk/gdk.h>
19
20 //-----------------------------------------------------------------------------
21 // idle system
22 //-----------------------------------------------------------------------------
23
24 extern void wxapp_install_idle_handler();
25 extern bool g_isIdle;
26
27 //-----------------------------------------------------------------------------
28 // wxCursor
29 //-----------------------------------------------------------------------------
30
31 class wxCursorRefData: public wxObjectRefData
32 {
33 public:
34
35 wxCursorRefData();
36 ~wxCursorRefData();
37
38 GdkCursor *m_cursor;
39 };
40
41 wxCursorRefData::wxCursorRefData()
42 {
43 m_cursor = (GdkCursor *) NULL;
44 }
45
46 wxCursorRefData::~wxCursorRefData()
47 {
48 if (m_cursor) gdk_cursor_destroy( m_cursor );
49 }
50
51 //-----------------------------------------------------------------------------
52
53 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
54
55 IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
56
57 wxCursor::wxCursor()
58 {
59 }
60
61 wxCursor::wxCursor( int cursorId )
62 {
63 m_refData = new wxCursorRefData();
64
65 GdkCursorType gdk_cur = GDK_LEFT_PTR;
66 switch (cursorId)
67 {
68 case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break;
69 case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
70 case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
71 case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
72 case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
73 case wxCURSOR_WAIT:
74 case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
75 case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
76 case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
77 case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
78 case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
79 case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
80 case wxCURSOR_SIZENWSE:
81 case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break;
82 case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break;
83 case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break;
84 case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break;
85 case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break;
86 case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break;
87 case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break;
88 case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break;
89 case wxCURSOR_BULLSEYE: gdk_cur = GDK_TARGET; break;
90
91 case wxCURSOR_POINT_LEFT: gdk_cur = GDK_SB_LEFT_ARROW; break;
92 case wxCURSOR_POINT_RIGHT: gdk_cur = GDK_SB_RIGHT_ARROW; break;
93 /*
94 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
95 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
96 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
97 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
98 */
99 default:
100 wxFAIL_MSG(wxT("unsupported cursor type"));
101 // will use the standard one
102
103 case wxCURSOR_ARROW:
104 break;
105 }
106
107 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
108 }
109
110 wxCursor::wxCursor( const wxCursor &cursor )
111 {
112 Ref( cursor );
113 }
114
115 wxCursor::~wxCursor()
116 {
117 }
118
119 wxCursor& wxCursor::operator = ( const wxCursor& cursor )
120 {
121 if (*this == cursor)
122 return (*this);
123
124 Ref( cursor );
125
126 return *this;
127 }
128
129 bool wxCursor::operator == ( const wxCursor& cursor ) const
130 {
131 return m_refData == cursor.m_refData;
132 }
133
134 bool wxCursor::operator != ( const wxCursor& cursor ) const
135 {
136 return m_refData != cursor.m_refData;
137 }
138
139 bool wxCursor::Ok() const
140 {
141 return (m_refData != NULL);
142 }
143
144 GdkCursor *wxCursor::GetCursor() const
145 {
146 return M_CURSORDATA->m_cursor;
147 }
148
149 //-----------------------------------------------------------------------------
150 // busy cursor routines
151 //-----------------------------------------------------------------------------
152
153 extern wxCursor g_globalCursor;
154
155 static wxCursor gs_savedCursor;
156 static int gs_busyCount = 0;
157
158 void wxEndBusyCursor()
159 {
160 if (--gs_busyCount > 0)
161 return;
162
163 wxSetCursor( gs_savedCursor );
164 gs_savedCursor = wxNullCursor;
165
166 wxYield();
167 }
168
169 void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
170 {
171 if (gs_busyCount++ > 0)
172 return;
173
174 wxASSERT_MSG( !gs_savedCursor.Ok(),
175 wxT("forgot to call wxEndBusyCursor, will leak memory") );
176
177 gs_savedCursor = g_globalCursor;
178
179 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
180
181 wxYield();
182 }
183
184 bool wxIsBusy()
185 {
186 return gs_busyCount > 0;
187 }
188
189 void wxSetCursor( const wxCursor& cursor )
190 {
191 if (g_isIdle)
192 wxapp_install_idle_handler();
193
194 g_globalCursor = cursor;
195 }