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