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