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