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