]> git.saurik.com Git - wxWidgets.git/blame - src/x11/cursor.cpp
mac cleanup, pure cgcolor
[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"
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
34class wxCursorRefData: public wxObjectRefData
35{
36public:
37
38 wxCursorRefData();
d3c7fc99 39 virtual ~wxCursorRefData();
a11672a4
RR
40
41 WXCursor m_cursor;
42 WXDisplay *m_display;
43};
83df96d6
JS
44
45wxCursorRefData::wxCursorRefData()
46{
a11672a4
RR
47 m_cursor = NULL;
48 m_display = NULL;
83df96d6
JS
49}
50
51wxCursorRefData::~wxCursorRefData()
52{
a11672a4
RR
53 if (m_cursor)
54 XFreeCursor( (Display*) m_display, (Cursor) m_cursor );
83df96d6
JS
55}
56
a11672a4
RR
57//-----------------------------------------------------------------------------
58
59#define M_CURSORDATA ((wxCursorRefData *)m_refData)
60
61IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
62
83df96d6
JS
63wxCursor::wxCursor()
64{
a11672a4 65
83df96d6
JS
66}
67
a11672a4 68wxCursor::wxCursor( int cursorId )
83df96d6 69{
a11672a4 70 m_refData = new wxCursorRefData();
83df96d6 71
c79a329d
JS
72#if wxUSE_NANOX
73 // TODO Create some standard cursors from bitmaps.
670f9935
WS
74
75
c79a329d
JS
76#else
77 // !wxUSE_NANOX
670f9935 78
a11672a4
RR
79 M_CURSORDATA->m_display = wxGlobalDisplay();
80 wxASSERT_MSG( M_CURSORDATA->m_display, wxT("No display") );
670f9935 81
a11672a4
RR
82 int x_cur = XC_left_ptr;
83 switch (cursorId)
83df96d6 84 {
a11672a4
RR
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
83df96d6
JS
120 }
121
a11672a4 122 M_CURSORDATA->m_cursor = (WXCursor) XCreateFontCursor( (Display*) M_CURSORDATA->m_display, x_cur );
c79a329d 123#endif
a11672a4 124}
83df96d6 125
89954433
VZ
126wxCursor::wxCursor(const char WXUNUSED(bits)[],
127 int WXUNUSED(width), int WXUNUSED(height),
128 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
129 const char WXUNUSED(maskBits)[],
130 wxColour *WXUNUSED(fg), wxColour *WXUNUSED(bg))
a11672a4 131{
54385bdb 132 wxFAIL_MSG( wxT("wxCursor creation from bits not yet implemented") );
a11672a4 133}
83df96d6 134
a11672a4 135#if wxUSE_IMAGE
89954433 136wxCursor::wxCursor( const wxImage & WXUNUSED(image) )
83df96d6 137{
54385bdb 138 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
a11672a4
RR
139}
140#endif
83df96d6 141
a11672a4
RR
142wxCursor::~wxCursor()
143{
144}
83df96d6 145
b7cacb43 146bool wxCursor::IsOk() const
a11672a4
RR
147{
148 return (m_refData != NULL);
83df96d6
JS
149}
150
a11672a4 151WXCursor wxCursor::GetCursor() const
83df96d6 152{
a11672a4
RR
153 return M_CURSORDATA->m_cursor;
154}
83df96d6 155
a11672a4
RR
156//-----------------------------------------------------------------------------
157// busy cursor routines
158//-----------------------------------------------------------------------------
83df96d6 159
a11672a4 160/* extern */ wxCursor g_globalCursor;
83df96d6 161
a11672a4
RR
162static wxCursor gs_savedCursor;
163static int gs_busyCount = 0;
164
165const wxCursor &wxBusyCursor::GetStoredCursor()
83df96d6 166{
a11672a4 167 return gs_savedCursor;
83df96d6
JS
168}
169
a11672a4 170const wxCursor wxBusyCursor::GetBusyCursor()
83df96d6 171{
a11672a4
RR
172 return wxCursor(wxCURSOR_WATCH);
173}
83df96d6 174
a11672a4
RR
175void wxEndBusyCursor()
176{
177 if (--gs_busyCount > 0)
178 return;
83df96d6 179
a11672a4
RR
180 wxSetCursor( gs_savedCursor );
181 gs_savedCursor = wxNullCursor;
83df96d6 182
a11672a4 183 if (wxTheApp)
d794dcb6 184 wxTheApp->ProcessIdle();
83df96d6
JS
185}
186
f516d986 187void wxBeginBusyCursor( const wxCursor *WXUNUSED(cursor) )
83df96d6 188{
a11672a4
RR
189 if (gs_busyCount++ > 0)
190 return;
83df96d6 191
a11672a4
RR
192 wxASSERT_MSG( !gs_savedCursor.Ok(),
193 wxT("forgot to call wxEndBusyCursor, will leak memory") );
194
195 gs_savedCursor = g_globalCursor;
196
197 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
198
199 if (wxTheApp)
a0749355 200 wxTheApp->ProcessIdle();
83df96d6
JS
201}
202
a11672a4 203bool wxIsBusy()
83df96d6 204{
a11672a4 205 return gs_busyCount > 0;
83df96d6
JS
206}
207
a11672a4
RR
208void wxSetCursor( const wxCursor& cursor )
209{
210 g_globalCursor = cursor;
211}