]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/cursor.cpp
c314e4f387a53d530517bc56745fae8568b21984
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"
21 #include "wx/gdicmn.h"
25 #include "wx/x11/private.h"
28 #include <X11/cursorfont.h>
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 class wxCursorRefData
: public wxGDIRefData
40 virtual ~wxCursorRefData();
46 // There is no way to copy m_cursor so we can't implement a copy ctor
48 wxDECLARE_NO_COPY_CLASS(wxCursorRefData
);
51 wxCursorRefData::wxCursorRefData()
57 wxCursorRefData::~wxCursorRefData()
60 XFreeCursor( (Display
*) m_display
, (Cursor
) m_cursor
);
63 //-----------------------------------------------------------------------------
65 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
67 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
74 void wxCursor::InitFromStock( wxStockCursor cursorId
)
76 m_refData
= new wxCursorRefData();
79 // TODO Create some standard cursors from bitmaps.
85 M_CURSORDATA
->m_display
= wxGlobalDisplay();
86 wxASSERT_MSG( M_CURSORDATA
->m_display
, wxT("No display") );
88 int x_cur
= XC_left_ptr
;
91 case wxCURSOR_DEFAULT
: x_cur
= XC_left_ptr
; break;
92 case wxCURSOR_HAND
: x_cur
= XC_hand1
; break;
93 case wxCURSOR_CROSS
: x_cur
= XC_crosshair
; break;
94 case wxCURSOR_SIZEWE
: x_cur
= XC_sb_h_double_arrow
; break;
95 case wxCURSOR_SIZENS
: x_cur
= XC_sb_v_double_arrow
; break;
96 case wxCURSOR_ARROWWAIT
:
98 case wxCURSOR_WATCH
: x_cur
= XC_watch
; break;
99 case wxCURSOR_SIZING
: x_cur
= XC_sizing
; break;
100 case wxCURSOR_SPRAYCAN
: x_cur
= XC_spraycan
; break;
101 case wxCURSOR_IBEAM
: x_cur
= XC_xterm
; break;
102 case wxCURSOR_PENCIL
: x_cur
= XC_pencil
; break;
103 case wxCURSOR_NO_ENTRY
: x_cur
= XC_pirate
; break;
104 case wxCURSOR_SIZENWSE
:
105 case wxCURSOR_SIZENESW
: x_cur
= XC_fleur
; break;
106 case wxCURSOR_QUESTION_ARROW
: x_cur
= XC_question_arrow
; break;
107 case wxCURSOR_PAINT_BRUSH
: x_cur
= XC_spraycan
; break;
108 case wxCURSOR_MAGNIFIER
: x_cur
= XC_plus
; break;
109 case wxCURSOR_CHAR
: x_cur
= XC_xterm
; break;
110 case wxCURSOR_LEFT_BUTTON
: x_cur
= XC_leftbutton
; break;
111 case wxCURSOR_MIDDLE_BUTTON
: x_cur
= XC_middlebutton
; break;
112 case wxCURSOR_RIGHT_BUTTON
: x_cur
= XC_rightbutton
; break;
113 case wxCURSOR_BULLSEYE
: x_cur
= XC_target
; break;
115 case wxCURSOR_POINT_LEFT
: x_cur
= XC_sb_left_arrow
; break;
116 case wxCURSOR_POINT_RIGHT
: x_cur
= XC_sb_right_arrow
; break;
118 case wxCURSOR_DOUBLE_ARROW: x_cur = XC_double_arrow; break;
119 case wxCURSOR_CROSS_REVERSE: x_cur = XC_cross_reverse; break;
120 case wxCURSOR_BASED_ARROW_UP: x_cur = XC_based_arrow_up; break;
121 case wxCURSOR_BASED_ARROW_DOWN: x_cur = XC_based_arrow_down; break;
124 wxFAIL_MSG(wxT("unsupported cursor type"));
125 // will use the standard one
128 M_CURSORDATA
->m_cursor
= (WXCursor
) XCreateFontCursor( (Display
*) M_CURSORDATA
->m_display
, x_cur
);
132 wxCursor::wxCursor(const wxString
& WXUNUSED(name
),
133 wxBitmapType
WXUNUSED(type
),
134 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
))
136 wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") );
140 wxCursor::wxCursor( const wxImage
& WXUNUSED(image
) )
142 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
146 wxCursor::~wxCursor()
150 wxGDIRefData
*wxCursor::CreateGDIRefData() const
152 return new wxCursorRefData
;
156 wxCursor::CloneGDIRefData(const wxGDIRefData
* WXUNUSED(data
)) const
158 wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxX11.") );
160 return new wxCursorRefData
;
163 WXCursor
wxCursor::GetCursor() const
165 return M_CURSORDATA
->m_cursor
;
168 //-----------------------------------------------------------------------------
169 // busy cursor routines
170 //-----------------------------------------------------------------------------
172 /* extern */ wxCursor g_globalCursor
;
174 static wxCursor gs_savedCursor
;
175 static int gs_busyCount
= 0;
177 const wxCursor
&wxBusyCursor::GetStoredCursor()
179 return gs_savedCursor
;
182 const wxCursor
wxBusyCursor::GetBusyCursor()
184 return wxCursor(wxCURSOR_WATCH
);
187 void wxEndBusyCursor()
189 if (--gs_busyCount
> 0)
192 wxSetCursor( gs_savedCursor
);
193 gs_savedCursor
= wxNullCursor
;
196 wxTheApp
->ProcessIdle();
199 void wxBeginBusyCursor( const wxCursor
*WXUNUSED(cursor
) )
201 if (gs_busyCount
++ > 0)
204 wxASSERT_MSG( !gs_savedCursor
.IsOk(),
205 wxT("forgot to call wxEndBusyCursor, will leak memory") );
207 gs_savedCursor
= g_globalCursor
;
209 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
212 wxTheApp
->ProcessIdle();
217 return gs_busyCount
> 0;
220 void wxSetCursor( const wxCursor
& cursor
)
222 g_globalCursor
= cursor
;