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