]> git.saurik.com Git - wxWidgets.git/blame - src/x11/cursor.cpp
wxGTK1 : wx/private/eventloopsourcesmanager.h was missing in evtloop.cpp
[wxWidgets.git] / src / x11 / cursor.cpp
CommitLineData
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
83df96d6 7// Copyright: (c) Julian Smart
670f9935 8// Licence: wxWindows licence
83df96d6
JS
9/////////////////////////////////////////////////////////////////////////////
10
670f9935
WS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
83df96d6 14#include "wx/cursor.h"
670f9935
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/app.h"
de6185e2 18 #include "wx/utils.h"
923d28da 19 #include "wx/icon.h"
dd05139a 20 #include "wx/gdicmn.h"
8f884a0d 21 #include "wx/image.h"
670f9935
WS
22#endif
23
bc797f4c 24#include "wx/x11/private.h"
c79a329d
JS
25
26#if !wxUSE_NANOX
b555c37c 27#include <X11/cursorfont.h>
c79a329d 28#endif
83df96d6 29
a11672a4
RR
30//-----------------------------------------------------------------------------
31// wxCursor
32//-----------------------------------------------------------------------------
33
8f884a0d 34class wxCursorRefData: public wxGDIRefData
a11672a4
RR
35{
36public:
37
38 wxCursorRefData();
d3c7fc99 39 virtual ~wxCursorRefData();
a11672a4
RR
40
41 WXCursor m_cursor;
42 WXDisplay *m_display;
66f75561
VZ
43
44private:
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);
a11672a4 48};
83df96d6
JS
49
50wxCursorRefData::wxCursorRefData()
51{
a11672a4
RR
52 m_cursor = NULL;
53 m_display = NULL;
83df96d6
JS
54}
55
56wxCursorRefData::~wxCursorRefData()
57{
a11672a4
RR
58 if (m_cursor)
59 XFreeCursor( (Display*) m_display, (Cursor) m_cursor );
83df96d6
JS
60}
61
a11672a4
RR
62//-----------------------------------------------------------------------------
63
64#define M_CURSORDATA ((wxCursorRefData *)m_refData)
65
66IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
67
83df96d6
JS
68wxCursor::wxCursor()
69{
a11672a4 70
83df96d6
JS
71}
72
0ef5b1da 73void wxCursor::InitFromStock( wxStockCursor cursorId )
83df96d6 74{
a11672a4 75 m_refData = new wxCursorRefData();
83df96d6 76
c79a329d
JS
77#if wxUSE_NANOX
78 // TODO Create some standard cursors from bitmaps.
670f9935
WS
79
80
c79a329d
JS
81#else
82 // !wxUSE_NANOX
670f9935 83
a11672a4
RR
84 M_CURSORDATA->m_display = wxGlobalDisplay();
85 wxASSERT_MSG( M_CURSORDATA->m_display, wxT("No display") );
670f9935 86
a11672a4
RR
87 int x_cur = XC_left_ptr;
88 switch (cursorId)
83df96d6 89 {
a11672a4
RR
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
83df96d6
JS
125 }
126
a11672a4 127 M_CURSORDATA->m_cursor = (WXCursor) XCreateFontCursor( (Display*) M_CURSORDATA->m_display, x_cur );
c79a329d 128#endif
a11672a4 129}
83df96d6 130
a0739a9a
VZ
131wxCursor::wxCursor(const wxString& WXUNUSED(name),
132 wxBitmapType WXUNUSED(type),
133 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY))
a11672a4 134{
0ef5b1da 135 wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") );
a11672a4 136}
83df96d6 137
a11672a4 138#if wxUSE_IMAGE
89954433 139wxCursor::wxCursor( const wxImage & WXUNUSED(image) )
83df96d6 140{
54385bdb 141 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
a11672a4
RR
142}
143#endif
83df96d6 144
a11672a4
RR
145wxCursor::~wxCursor()
146{
147}
83df96d6 148
8f884a0d 149wxGDIRefData *wxCursor::CreateGDIRefData() const
a11672a4 150{
8f884a0d
VZ
151 return new wxCursorRefData;
152}
153
66f75561
VZ
154wxGDIRefData *
155wxCursor::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const
8f884a0d 156{
66f75561
VZ
157 wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxX11.") );
158
159 return new wxCursorRefData;
83df96d6
JS
160}
161
a11672a4 162WXCursor wxCursor::GetCursor() const
83df96d6 163{
a11672a4
RR
164 return M_CURSORDATA->m_cursor;
165}
83df96d6 166
a11672a4
RR
167//-----------------------------------------------------------------------------
168// busy cursor routines
169//-----------------------------------------------------------------------------
83df96d6 170
a11672a4 171/* extern */ wxCursor g_globalCursor;
83df96d6 172
a11672a4
RR
173static wxCursor gs_savedCursor;
174static int gs_busyCount = 0;
175
176const wxCursor &wxBusyCursor::GetStoredCursor()
83df96d6 177{
a11672a4 178 return gs_savedCursor;
83df96d6
JS
179}
180
a11672a4 181const wxCursor wxBusyCursor::GetBusyCursor()
83df96d6 182{
a11672a4
RR
183 return wxCursor(wxCURSOR_WATCH);
184}
83df96d6 185
a11672a4
RR
186void wxEndBusyCursor()
187{
188 if (--gs_busyCount > 0)
189 return;
83df96d6 190
a11672a4
RR
191 wxSetCursor( gs_savedCursor );
192 gs_savedCursor = wxNullCursor;
83df96d6 193
a11672a4 194 if (wxTheApp)
d794dcb6 195 wxTheApp->ProcessIdle();
83df96d6
JS
196}
197
f516d986 198void wxBeginBusyCursor( const wxCursor *WXUNUSED(cursor) )
83df96d6 199{
a11672a4
RR
200 if (gs_busyCount++ > 0)
201 return;
83df96d6 202
a1b806b9 203 wxASSERT_MSG( !gs_savedCursor.IsOk(),
a11672a4
RR
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)
a0749355 211 wxTheApp->ProcessIdle();
83df96d6
JS
212}
213
a11672a4 214bool wxIsBusy()
83df96d6 215{
a11672a4 216 return gs_busyCount > 0;
83df96d6
JS
217}
218
a11672a4
RR
219void wxSetCursor( const wxCursor& cursor )
220{
221 g_globalCursor = cursor;
222}