]>
Commit | Line | Data |
---|---|---|
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_HAND: gdk_cur = GDK_HAND1; break; | |
68 | case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break; | |
69 | case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break; | |
70 | case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break; | |
71 | case wxCURSOR_WAIT: | |
72 | case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break; | |
73 | case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break; | |
74 | case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break; | |
75 | case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break; | |
76 | case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break; | |
77 | case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break; | |
78 | case wxCURSOR_SIZENWSE: | |
79 | case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break; | |
80 | case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break; | |
81 | case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break; | |
82 | case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break; | |
83 | case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break; | |
84 | case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break; | |
85 | case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break; | |
86 | case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break; | |
87 | /* | |
88 | case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break; | |
89 | case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break; | |
90 | case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break; | |
91 | case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break; | |
92 | */ | |
93 | default: | |
94 | wxFAIL_MSG(_T("unsupported cursor type")); | |
95 | // will use the standard one | |
96 | ||
97 | case wxCURSOR_ARROW: | |
98 | break; | |
99 | } | |
100 | ||
101 | M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur ); | |
102 | } | |
103 | ||
104 | wxCursor::wxCursor( const wxCursor &cursor ) | |
105 | { | |
106 | Ref( cursor ); | |
107 | } | |
108 | ||
109 | wxCursor::~wxCursor() | |
110 | { | |
111 | } | |
112 | ||
113 | wxCursor& wxCursor::operator = ( const wxCursor& cursor ) | |
114 | { | |
115 | if (*this == cursor) | |
116 | return (*this); | |
117 | ||
118 | Ref( cursor ); | |
119 | ||
120 | return *this; | |
121 | } | |
122 | ||
123 | bool wxCursor::operator == ( const wxCursor& cursor ) const | |
124 | { | |
125 | return m_refData == cursor.m_refData; | |
126 | } | |
127 | ||
128 | bool wxCursor::operator != ( const wxCursor& cursor ) const | |
129 | { | |
130 | return m_refData != cursor.m_refData; | |
131 | } | |
132 | ||
133 | bool wxCursor::Ok() const | |
134 | { | |
135 | return (m_refData != NULL); | |
136 | } | |
137 | ||
138 | GdkCursor *wxCursor::GetCursor() const | |
139 | { | |
140 | return M_CURSORDATA->m_cursor; | |
141 | } | |
142 | ||
143 | //----------------------------------------------------------------------------- | |
144 | // busy cursor routines | |
145 | //----------------------------------------------------------------------------- | |
146 | ||
147 | extern wxCursor g_globalCursor; | |
148 | ||
149 | static wxCursor gs_savedCursor; | |
150 | static int gs_busyCount = 0; | |
151 | ||
152 | void wxEndBusyCursor() | |
153 | { | |
154 | if (--gs_busyCount > 0) | |
155 | return; | |
156 | ||
157 | wxSetCursor( gs_savedCursor ); | |
158 | gs_savedCursor = wxNullCursor; | |
159 | } | |
160 | ||
161 | void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) ) | |
162 | { | |
163 | if (gs_busyCount++ > 0) | |
164 | return; | |
165 | ||
166 | wxASSERT_MSG( !gs_savedCursor.Ok(), | |
167 | _T("forgot to call wxEndBusyCursor, will leak memory") ); | |
168 | ||
169 | gs_savedCursor = g_globalCursor; | |
170 | ||
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_isIdle) | |
182 | wxapp_install_idle_handler(); | |
183 | ||
184 | g_globalCursor = cursor; | |
185 | } |