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