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