]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCursor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cursor.h"
16 #include "wx/cursor.h"
17 #include "wx/gdicmn.h"
22 #include "wx/x11/private.h"
25 #include <X11/cursorfont.h>
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 class wxCursorRefData
: public wxObjectRefData
43 wxCursorRefData::wxCursorRefData()
49 wxCursorRefData::~wxCursorRefData()
52 XFreeCursor( (Display
*) m_display
, (Cursor
) m_cursor
);
55 //-----------------------------------------------------------------------------
57 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
59 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
66 wxCursor::wxCursor( int cursorId
)
68 m_refData
= new wxCursorRefData();
71 // TODO Create some standard cursors from bitmaps.
77 M_CURSORDATA
->m_display
= wxGlobalDisplay();
78 wxASSERT_MSG( M_CURSORDATA
->m_display
, wxT("No display") );
80 int x_cur
= XC_left_ptr
;
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
:
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;
107 case wxCURSOR_POINT_LEFT
: x_cur
= XC_sb_left_arrow
; break;
108 case wxCURSOR_POINT_RIGHT
: x_cur
= XC_sb_right_arrow
; break;
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;
116 wxFAIL_MSG(wxT("unsupported cursor type"));
117 // will use the standard one
120 M_CURSORDATA
->m_cursor
= (WXCursor
) XCreateFontCursor( (Display
*) M_CURSORDATA
->m_display
, x_cur
);
124 wxCursor::wxCursor(const char bits
[], int width
, int height
,
125 int hotSpotX
, int hotSpotY
,
126 const char maskBits
[], wxColour
*fg
, wxColour
*bg
)
128 wxFAIL_MSG( "wxCursor creation from bits not yet implemented" );
132 wxCursor::wxCursor( const wxCursor
&cursor
)
138 wxCursor::wxCursor( const wxImage
& image
)
140 wxFAIL_MSG( "wxCursor creation from wxImage not yet implemented" );
144 wxCursor::~wxCursor()
148 wxCursor
& wxCursor::operator = ( const wxCursor
& cursor
)
158 bool wxCursor::operator == ( const wxCursor
& cursor
) const
160 return m_refData
== cursor
.m_refData
;
163 bool wxCursor::operator != ( const wxCursor
& cursor
) const
165 return m_refData
!= cursor
.m_refData
;
168 bool wxCursor::Ok() const
170 return (m_refData
!= NULL
);
173 WXCursor
wxCursor::GetCursor() const
175 return M_CURSORDATA
->m_cursor
;
178 //-----------------------------------------------------------------------------
179 // busy cursor routines
180 //-----------------------------------------------------------------------------
182 /* extern */ wxCursor g_globalCursor
;
184 static wxCursor gs_savedCursor
;
185 static int gs_busyCount
= 0;
187 const wxCursor
&wxBusyCursor::GetStoredCursor()
189 return gs_savedCursor
;
192 const wxCursor
wxBusyCursor::GetBusyCursor()
194 return wxCursor(wxCURSOR_WATCH
);
197 void wxEndBusyCursor()
199 if (--gs_busyCount
> 0)
202 wxSetCursor( gs_savedCursor
);
203 gs_savedCursor
= wxNullCursor
;
206 wxTheApp
->SendIdleEvents();
209 void wxBeginBusyCursor( wxCursor
*WXUNUSED(cursor
) )
211 if (gs_busyCount
++ > 0)
214 wxASSERT_MSG( !gs_savedCursor
.Ok(),
215 wxT("forgot to call wxEndBusyCursor, will leak memory") );
217 gs_savedCursor
= g_globalCursor
;
219 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
222 wxTheApp
->SendIdleEvents();
227 return gs_busyCount
> 0;
230 void wxSetCursor( const wxCursor
& cursor
)
232 g_globalCursor
= cursor
;