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