]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/cursor.cpp
3aff9bfa0e719ea6451f901795bcb8076bdeac77
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/cursor.cpp
3 // Purpose: wxCursor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/cursor.h"
23 #include "wx/gdicmn.h"
25 #include "wx/x11/private.h"
28 #include <X11/cursorfont.h>
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 class wxCursorRefData
: public wxObjectRefData
46 wxCursorRefData::wxCursorRefData()
52 wxCursorRefData::~wxCursorRefData()
55 XFreeCursor( (Display
*) m_display
, (Cursor
) m_cursor
);
58 //-----------------------------------------------------------------------------
60 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
62 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
69 wxCursor::wxCursor( int cursorId
)
71 m_refData
= new wxCursorRefData();
74 // TODO Create some standard cursors from bitmaps.
80 M_CURSORDATA
->m_display
= wxGlobalDisplay();
81 wxASSERT_MSG( M_CURSORDATA
->m_display
, wxT("No display") );
83 int x_cur
= XC_left_ptr
;
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
:
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;
110 case wxCURSOR_POINT_LEFT
: x_cur
= XC_sb_left_arrow
; break;
111 case wxCURSOR_POINT_RIGHT
: x_cur
= XC_sb_right_arrow
; break;
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;
119 wxFAIL_MSG(wxT("unsupported cursor type"));
120 // will use the standard one
123 M_CURSORDATA
->m_cursor
= (WXCursor
) XCreateFontCursor( (Display
*) M_CURSORDATA
->m_display
, x_cur
);
127 wxCursor::wxCursor(const char bits
[], int width
, int height
,
128 int hotSpotX
, int hotSpotY
,
129 const char maskBits
[], wxColour
*fg
, wxColour
*bg
)
131 wxFAIL_MSG( wxT("wxCursor creation from bits not yet implemented") );
135 wxCursor::wxCursor( const wxImage
& image
)
137 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
141 wxCursor::~wxCursor()
145 bool wxCursor::operator == ( const wxCursor
& cursor
) const
147 return m_refData
== cursor
.m_refData
;
150 bool wxCursor::operator != ( const wxCursor
& cursor
) const
152 return m_refData
!= cursor
.m_refData
;
155 bool wxCursor::Ok() const
157 return (m_refData
!= NULL
);
160 WXCursor
wxCursor::GetCursor() const
162 return M_CURSORDATA
->m_cursor
;
165 //-----------------------------------------------------------------------------
166 // busy cursor routines
167 //-----------------------------------------------------------------------------
169 /* extern */ wxCursor g_globalCursor
;
171 static wxCursor gs_savedCursor
;
172 static int gs_busyCount
= 0;
174 const wxCursor
&wxBusyCursor::GetStoredCursor()
176 return gs_savedCursor
;
179 const wxCursor
wxBusyCursor::GetBusyCursor()
181 return wxCursor(wxCURSOR_WATCH
);
184 void wxEndBusyCursor()
186 if (--gs_busyCount
> 0)
189 wxSetCursor( gs_savedCursor
);
190 gs_savedCursor
= wxNullCursor
;
193 wxTheApp
->ProcessIdle();
196 void wxBeginBusyCursor( const wxCursor
*WXUNUSED(cursor
) )
198 if (gs_busyCount
++ > 0)
201 wxASSERT_MSG( !gs_savedCursor
.Ok(),
202 wxT("forgot to call wxEndBusyCursor, will leak memory") );
204 gs_savedCursor
= g_globalCursor
;
206 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
209 wxTheApp
->ProcessIdle();
214 return gs_busyCount
> 0;
217 void wxSetCursor( const wxCursor
& cursor
)
219 g_globalCursor
= cursor
;