]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/x11/cursor.cpp | |
3 | // Purpose: wxCursor class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // Copyright: (c) Julian Smart | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/cursor.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/icon.h" | |
20 | #include "wx/gdicmn.h" | |
21 | #include "wx/image.h" | |
22 | #endif | |
23 | ||
24 | #include "wx/x11/private.h" | |
25 | ||
26 | #if !wxUSE_NANOX | |
27 | #include <X11/cursorfont.h> | |
28 | #endif | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // wxCursor | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | class wxCursorRefData: public wxGDIRefData | |
35 | { | |
36 | public: | |
37 | ||
38 | wxCursorRefData(); | |
39 | virtual ~wxCursorRefData(); | |
40 | ||
41 | WXCursor m_cursor; | |
42 | WXDisplay *m_display; | |
43 | ||
44 | private: | |
45 | // There is no way to copy m_cursor so we can't implement a copy ctor | |
46 | // properly. | |
47 | wxDECLARE_NO_COPY_CLASS(wxCursorRefData); | |
48 | }; | |
49 | ||
50 | wxCursorRefData::wxCursorRefData() | |
51 | { | |
52 | m_cursor = NULL; | |
53 | m_display = NULL; | |
54 | } | |
55 | ||
56 | wxCursorRefData::~wxCursorRefData() | |
57 | { | |
58 | if (m_cursor) | |
59 | XFreeCursor( (Display*) m_display, (Cursor) m_cursor ); | |
60 | } | |
61 | ||
62 | //----------------------------------------------------------------------------- | |
63 | ||
64 | #define M_CURSORDATA ((wxCursorRefData *)m_refData) | |
65 | ||
66 | IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject) | |
67 | ||
68 | wxCursor::wxCursor() | |
69 | { | |
70 | ||
71 | } | |
72 | ||
73 | void wxCursor::InitFromStock( wxStockCursor cursorId ) | |
74 | { | |
75 | m_refData = new wxCursorRefData(); | |
76 | ||
77 | #if wxUSE_NANOX | |
78 | // TODO Create some standard cursors from bitmaps. | |
79 | ||
80 | ||
81 | #else | |
82 | // !wxUSE_NANOX | |
83 | ||
84 | M_CURSORDATA->m_display = wxGlobalDisplay(); | |
85 | wxASSERT_MSG( M_CURSORDATA->m_display, wxT("No display") ); | |
86 | ||
87 | int x_cur = XC_left_ptr; | |
88 | switch (cursorId) | |
89 | { | |
90 | case wxCURSOR_DEFAULT: x_cur = XC_left_ptr; break; | |
91 | case wxCURSOR_HAND: x_cur = XC_hand1; break; | |
92 | case wxCURSOR_CROSS: x_cur = XC_crosshair; break; | |
93 | case wxCURSOR_SIZEWE: x_cur = XC_sb_h_double_arrow; break; | |
94 | case wxCURSOR_SIZENS: x_cur = XC_sb_v_double_arrow; break; | |
95 | case wxCURSOR_ARROWWAIT: | |
96 | case wxCURSOR_WAIT: | |
97 | case wxCURSOR_WATCH: x_cur = XC_watch; break; | |
98 | case wxCURSOR_SIZING: x_cur = XC_sizing; break; | |
99 | case wxCURSOR_SPRAYCAN: x_cur = XC_spraycan; break; | |
100 | case wxCURSOR_IBEAM: x_cur = XC_xterm; break; | |
101 | case wxCURSOR_PENCIL: x_cur = XC_pencil; break; | |
102 | case wxCURSOR_NO_ENTRY: x_cur = XC_pirate; break; | |
103 | case wxCURSOR_SIZENWSE: | |
104 | case wxCURSOR_SIZENESW: x_cur = XC_fleur; break; | |
105 | case wxCURSOR_QUESTION_ARROW: x_cur = XC_question_arrow; break; | |
106 | case wxCURSOR_PAINT_BRUSH: x_cur = XC_spraycan; break; | |
107 | case wxCURSOR_MAGNIFIER: x_cur = XC_plus; break; | |
108 | case wxCURSOR_CHAR: x_cur = XC_xterm; break; | |
109 | case wxCURSOR_LEFT_BUTTON: x_cur = XC_leftbutton; break; | |
110 | case wxCURSOR_MIDDLE_BUTTON: x_cur = XC_middlebutton; break; | |
111 | case wxCURSOR_RIGHT_BUTTON: x_cur = XC_rightbutton; break; | |
112 | case wxCURSOR_BULLSEYE: x_cur = XC_target; break; | |
113 | ||
114 | case wxCURSOR_POINT_LEFT: x_cur = XC_sb_left_arrow; break; | |
115 | case wxCURSOR_POINT_RIGHT: x_cur = XC_sb_right_arrow; break; | |
116 | /* | |
117 | case wxCURSOR_DOUBLE_ARROW: x_cur = XC_double_arrow; break; | |
118 | case wxCURSOR_CROSS_REVERSE: x_cur = XC_cross_reverse; break; | |
119 | case wxCURSOR_BASED_ARROW_UP: x_cur = XC_based_arrow_up; break; | |
120 | case wxCURSOR_BASED_ARROW_DOWN: x_cur = XC_based_arrow_down; break; | |
121 | */ | |
122 | default: | |
123 | wxFAIL_MSG(wxT("unsupported cursor type")); | |
124 | // will use the standard one | |
125 | } | |
126 | ||
127 | M_CURSORDATA->m_cursor = (WXCursor) XCreateFontCursor( (Display*) M_CURSORDATA->m_display, x_cur ); | |
128 | #endif | |
129 | } | |
130 | ||
131 | wxCursor::wxCursor(const wxString& WXUNUSED(name), | |
132 | wxBitmapType WXUNUSED(type), | |
133 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) | |
134 | { | |
135 | wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") ); | |
136 | } | |
137 | ||
138 | #if wxUSE_IMAGE | |
139 | wxCursor::wxCursor( const wxImage & WXUNUSED(image) ) | |
140 | { | |
141 | wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") ); | |
142 | } | |
143 | #endif | |
144 | ||
145 | wxCursor::~wxCursor() | |
146 | { | |
147 | } | |
148 | ||
149 | wxGDIRefData *wxCursor::CreateGDIRefData() const | |
150 | { | |
151 | return new wxCursorRefData; | |
152 | } | |
153 | ||
154 | wxGDIRefData * | |
155 | wxCursor::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const | |
156 | { | |
157 | wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxX11.") ); | |
158 | ||
159 | return new wxCursorRefData; | |
160 | } | |
161 | ||
162 | WXCursor wxCursor::GetCursor() const | |
163 | { | |
164 | return M_CURSORDATA->m_cursor; | |
165 | } | |
166 | ||
167 | //----------------------------------------------------------------------------- | |
168 | // busy cursor routines | |
169 | //----------------------------------------------------------------------------- | |
170 | ||
171 | /* extern */ wxCursor g_globalCursor; | |
172 | ||
173 | static wxCursor gs_savedCursor; | |
174 | static int gs_busyCount = 0; | |
175 | ||
176 | const wxCursor &wxBusyCursor::GetStoredCursor() | |
177 | { | |
178 | return gs_savedCursor; | |
179 | } | |
180 | ||
181 | const wxCursor wxBusyCursor::GetBusyCursor() | |
182 | { | |
183 | return wxCursor(wxCURSOR_WATCH); | |
184 | } | |
185 | ||
186 | void wxEndBusyCursor() | |
187 | { | |
188 | if (--gs_busyCount > 0) | |
189 | return; | |
190 | ||
191 | wxSetCursor( gs_savedCursor ); | |
192 | gs_savedCursor = wxNullCursor; | |
193 | ||
194 | if (wxTheApp) | |
195 | wxTheApp->ProcessIdle(); | |
196 | } | |
197 | ||
198 | void wxBeginBusyCursor( const wxCursor *WXUNUSED(cursor) ) | |
199 | { | |
200 | if (gs_busyCount++ > 0) | |
201 | return; | |
202 | ||
203 | wxASSERT_MSG( !gs_savedCursor.IsOk(), | |
204 | wxT("forgot to call wxEndBusyCursor, will leak memory") ); | |
205 | ||
206 | gs_savedCursor = g_globalCursor; | |
207 | ||
208 | wxSetCursor( wxCursor(wxCURSOR_WATCH) ); | |
209 | ||
210 | if (wxTheApp) | |
211 | wxTheApp->ProcessIdle(); | |
212 | } | |
213 | ||
214 | bool wxIsBusy() | |
215 | { | |
216 | return gs_busyCount > 0; | |
217 | } | |
218 | ||
219 | void wxSetCursor( const wxCursor& cursor ) | |
220 | { | |
221 | g_globalCursor = cursor; | |
222 | } |