]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cursor.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
dbf858b5 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
8bbe427f | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "cursor.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/cursor.h" | |
4dcaf11a | 16 | #include "wx/utils.h" |
c801d85f | 17 | |
83624f79 RR |
18 | #include "gdk/gdk.h" |
19 | ||
238d735d RR |
20 | //----------------------------------------------------------------------------- |
21 | // idle system | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | extern void wxapp_install_idle_handler(); | |
25 | extern bool g_isIdle; | |
26 | ||
c801d85f KB |
27 | //----------------------------------------------------------------------------- |
28 | // wxCursor | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class wxCursorRefData: public wxObjectRefData | |
32 | { | |
33 | public: | |
8bbe427f VZ |
34 | |
35 | wxCursorRefData(); | |
36 | ~wxCursorRefData(); | |
37 | ||
c801d85f KB |
38 | GdkCursor *m_cursor; |
39 | }; | |
40 | ||
8bbe427f | 41 | wxCursorRefData::wxCursorRefData() |
c801d85f | 42 | { |
2d17d68f | 43 | m_cursor = (GdkCursor *) NULL; |
ff7b1510 | 44 | } |
c801d85f | 45 | |
8bbe427f | 46 | wxCursorRefData::~wxCursorRefData() |
c801d85f | 47 | { |
2d17d68f | 48 | if (m_cursor) gdk_cursor_destroy( m_cursor ); |
ff7b1510 | 49 | } |
c801d85f KB |
50 | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | #define M_CURSORDATA ((wxCursorRefData *)m_refData) | |
54 | ||
55 | IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject) | |
56 | ||
8bbe427f | 57 | wxCursor::wxCursor() |
c801d85f | 58 | { |
ff7b1510 | 59 | } |
c801d85f | 60 | |
debe6624 | 61 | wxCursor::wxCursor( int cursorId ) |
c801d85f | 62 | { |
2d17d68f RR |
63 | m_refData = new wxCursorRefData(); |
64 | ||
65 | GdkCursorType gdk_cur = GDK_LEFT_PTR; | |
66 | switch (cursorId) | |
67 | { | |
f7bdcdd7 | 68 | case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break; |
2d17d68f RR |
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; | |
7c39369e | 73 | case wxCURSOR_WAIT: |
2d17d68f RR |
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; | |
7c39369e | 80 | case wxCURSOR_SIZENWSE: |
2d17d68f RR |
81 | case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break; |
82 | case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break; | |
7c39369e VZ |
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; | |
2d17d68f RR |
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; | |
13971833 RD |
89 | case wxCURSOR_BULLSEYE: gdk_cur = GDK_TARGET; break; |
90 | ||
c801d85f | 91 | /* |
7c39369e VZ |
92 | case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break; |
93 | case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break; | |
2d17d68f RR |
94 | case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break; |
95 | case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break; | |
c801d85f | 96 | */ |
7c39369e | 97 | default: |
223d09f6 | 98 | wxFAIL_MSG(wxT("unsupported cursor type")); |
7c39369e VZ |
99 | // will use the standard one |
100 | ||
101 | case wxCURSOR_ARROW: | |
102 | break; | |
2d17d68f | 103 | } |
8bbe427f | 104 | |
2d17d68f | 105 | M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur ); |
ff7b1510 | 106 | } |
c801d85f KB |
107 | |
108 | wxCursor::wxCursor( const wxCursor &cursor ) | |
109 | { | |
2d17d68f | 110 | Ref( cursor ); |
ff7b1510 | 111 | } |
c801d85f | 112 | |
8bbe427f | 113 | wxCursor::~wxCursor() |
c801d85f | 114 | { |
ff7b1510 | 115 | } |
c801d85f KB |
116 | |
117 | wxCursor& wxCursor::operator = ( const wxCursor& cursor ) | |
118 | { | |
7c39369e VZ |
119 | if (*this == cursor) |
120 | return (*this); | |
121 | ||
2d17d68f | 122 | Ref( cursor ); |
7c39369e | 123 | |
2d17d68f | 124 | return *this; |
ff7b1510 | 125 | } |
c801d85f | 126 | |
8bbe427f | 127 | bool wxCursor::operator == ( const wxCursor& cursor ) const |
c801d85f | 128 | { |
2d17d68f | 129 | return m_refData == cursor.m_refData; |
ff7b1510 | 130 | } |
c801d85f | 131 | |
8bbe427f | 132 | bool wxCursor::operator != ( const wxCursor& cursor ) const |
c801d85f | 133 | { |
2d17d68f | 134 | return m_refData != cursor.m_refData; |
ff7b1510 | 135 | } |
c801d85f | 136 | |
8bbe427f | 137 | bool wxCursor::Ok() const |
c801d85f | 138 | { |
2d17d68f | 139 | return (m_refData != NULL); |
ff7b1510 | 140 | } |
c801d85f | 141 | |
8bbe427f | 142 | GdkCursor *wxCursor::GetCursor() const |
c801d85f | 143 | { |
2d17d68f | 144 | return M_CURSORDATA->m_cursor; |
ff7b1510 | 145 | } |
c801d85f KB |
146 | |
147 | //----------------------------------------------------------------------------- | |
148 | // busy cursor routines | |
149 | //----------------------------------------------------------------------------- | |
150 | ||
238d735d | 151 | extern wxCursor g_globalCursor; |
7c39369e | 152 | |
238d735d | 153 | static wxCursor gs_savedCursor; |
89a43902 | 154 | static int gs_busyCount = 0; |
c801d85f | 155 | |
8bbe427f | 156 | void wxEndBusyCursor() |
c801d85f | 157 | { |
238d735d | 158 | if (--gs_busyCount > 0) |
89a43902 VZ |
159 | return; |
160 | ||
238d735d RR |
161 | wxSetCursor( gs_savedCursor ); |
162 | gs_savedCursor = wxNullCursor; | |
13971833 | 163 | |
e65cc56a | 164 | wxYield(); |
ff7b1510 | 165 | } |
c801d85f KB |
166 | |
167 | void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) ) | |
168 | { | |
238d735d | 169 | if (gs_busyCount++ > 0) |
89a43902 VZ |
170 | return; |
171 | ||
238d735d | 172 | wxASSERT_MSG( !gs_savedCursor.Ok(), |
223d09f6 | 173 | wxT("forgot to call wxEndBusyCursor, will leak memory") ); |
7c39369e | 174 | |
238d735d | 175 | gs_savedCursor = g_globalCursor; |
13971833 | 176 | |
238d735d | 177 | wxSetCursor( wxCursor(wxCURSOR_WATCH) ); |
13971833 | 178 | |
4dcaf11a | 179 | wxYield(); |
ff7b1510 | 180 | } |
c801d85f | 181 | |
8bbe427f | 182 | bool wxIsBusy() |
c801d85f | 183 | { |
89a43902 | 184 | return gs_busyCount > 0; |
ff7b1510 | 185 | } |
c801d85f KB |
186 | |
187 | void wxSetCursor( const wxCursor& cursor ) | |
188 | { | |
13971833 | 189 | if (g_isIdle) |
238d735d RR |
190 | wxapp_install_idle_handler(); |
191 | ||
192 | g_globalCursor = cursor; | |
ff7b1510 | 193 | } |