]> git.saurik.com Git - wxWidgets.git/blame - src/x11/cursor.cpp
Derive wxWebViewEvent from wxNotifyEvent.
[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
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 35class wxCursorRefData: public wxGDIRefData
a11672a4
RR
36{
37public:
38
39 wxCursorRefData();
d3c7fc99 40 virtual ~wxCursorRefData();
a11672a4
RR
41
42 WXCursor m_cursor;
43 WXDisplay *m_display;
66f75561
VZ
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);
a11672a4 49};
83df96d6
JS
50
51wxCursorRefData::wxCursorRefData()
52{
a11672a4
RR
53 m_cursor = NULL;
54 m_display = NULL;
83df96d6
JS
55}
56
57wxCursorRefData::~wxCursorRefData()
58{
a11672a4
RR
59 if (m_cursor)
60 XFreeCursor( (Display*) m_display, (Cursor) m_cursor );
83df96d6
JS
61}
62
a11672a4
RR
63//-----------------------------------------------------------------------------
64
65#define M_CURSORDATA ((wxCursorRefData *)m_refData)
66
67IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
68
83df96d6
JS
69wxCursor::wxCursor()
70{
a11672a4 71
83df96d6
JS
72}
73
0ef5b1da 74void wxCursor::InitFromStock( wxStockCursor cursorId )
83df96d6 75{
a11672a4 76 m_refData = new wxCursorRefData();
83df96d6 77
c79a329d
JS
78#if wxUSE_NANOX
79 // TODO Create some standard cursors from bitmaps.
670f9935
WS
80
81
c79a329d
JS
82#else
83 // !wxUSE_NANOX
670f9935 84
a11672a4
RR
85 M_CURSORDATA->m_display = wxGlobalDisplay();
86 wxASSERT_MSG( M_CURSORDATA->m_display, wxT("No display") );
670f9935 87
a11672a4
RR
88 int x_cur = XC_left_ptr;
89 switch (cursorId)
83df96d6 90 {
a11672a4
RR
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
83df96d6
JS
126 }
127
a11672a4 128 M_CURSORDATA->m_cursor = (WXCursor) XCreateFontCursor( (Display*) M_CURSORDATA->m_display, x_cur );
c79a329d 129#endif
a11672a4 130}
83df96d6 131
a0739a9a
VZ
132wxCursor::wxCursor(const wxString& WXUNUSED(name),
133 wxBitmapType WXUNUSED(type),
134 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY))
a11672a4 135{
0ef5b1da 136 wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") );
a11672a4 137}
83df96d6 138
a11672a4 139#if wxUSE_IMAGE
89954433 140wxCursor::wxCursor( const wxImage & WXUNUSED(image) )
83df96d6 141{
54385bdb 142 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
a11672a4
RR
143}
144#endif
83df96d6 145
a11672a4
RR
146wxCursor::~wxCursor()
147{
148}
83df96d6 149
8f884a0d 150wxGDIRefData *wxCursor::CreateGDIRefData() const
a11672a4 151{
8f884a0d
VZ
152 return new wxCursorRefData;
153}
154
66f75561
VZ
155wxGDIRefData *
156wxCursor::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const
8f884a0d 157{
66f75561
VZ
158 wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxX11.") );
159
160 return new wxCursorRefData;
83df96d6
JS
161}
162
a11672a4 163WXCursor wxCursor::GetCursor() const
83df96d6 164{
a11672a4
RR
165 return M_CURSORDATA->m_cursor;
166}
83df96d6 167
a11672a4
RR
168//-----------------------------------------------------------------------------
169// busy cursor routines
170//-----------------------------------------------------------------------------
83df96d6 171
a11672a4 172/* extern */ wxCursor g_globalCursor;
83df96d6 173
a11672a4
RR
174static wxCursor gs_savedCursor;
175static int gs_busyCount = 0;
176
177const wxCursor &wxBusyCursor::GetStoredCursor()
83df96d6 178{
a11672a4 179 return gs_savedCursor;
83df96d6
JS
180}
181
a11672a4 182const wxCursor wxBusyCursor::GetBusyCursor()
83df96d6 183{
a11672a4
RR
184 return wxCursor(wxCURSOR_WATCH);
185}
83df96d6 186
a11672a4
RR
187void wxEndBusyCursor()
188{
189 if (--gs_busyCount > 0)
190 return;
83df96d6 191
a11672a4
RR
192 wxSetCursor( gs_savedCursor );
193 gs_savedCursor = wxNullCursor;
83df96d6 194
a11672a4 195 if (wxTheApp)
d794dcb6 196 wxTheApp->ProcessIdle();
83df96d6
JS
197}
198
f516d986 199void wxBeginBusyCursor( const wxCursor *WXUNUSED(cursor) )
83df96d6 200{
a11672a4
RR
201 if (gs_busyCount++ > 0)
202 return;
83df96d6 203
a1b806b9 204 wxASSERT_MSG( !gs_savedCursor.IsOk(),
a11672a4
RR
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)
a0749355 212 wxTheApp->ProcessIdle();
83df96d6
JS
213}
214
a11672a4 215bool wxIsBusy()
83df96d6 216{
a11672a4 217 return gs_busyCount > 0;
83df96d6
JS
218}
219
a11672a4
RR
220void wxSetCursor( const wxCursor& cursor )
221{
222 g_globalCursor = cursor;
223}