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