]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/cursor.cpp
3 // Purpose: wxCursor class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/cursor.h"
20 #include "wx/gdicmn.h"
24 #include "wx/x11/private.h"
27 #include <X11/cursorfont.h>
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 class wxCursorRefData
: public wxGDIRefData
39 virtual ~wxCursorRefData();
45 // There is no way to copy m_cursor so we can't implement a copy ctor
47 wxDECLARE_NO_COPY_CLASS(wxCursorRefData
);
50 wxCursorRefData::wxCursorRefData()
56 wxCursorRefData::~wxCursorRefData()
59 XFreeCursor( (Display
*) m_display
, (Cursor
) m_cursor
);
62 //-----------------------------------------------------------------------------
64 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
66 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
73 void wxCursor::InitFromStock( wxStockCursor cursorId
)
75 m_refData
= new wxCursorRefData();
78 // TODO Create some standard cursors from bitmaps.
84 M_CURSORDATA
->m_display
= wxGlobalDisplay();
85 wxASSERT_MSG( M_CURSORDATA
->m_display
, wxT("No display") );
87 int x_cur
= XC_left_ptr
;
90 case wxCURSOR_DEFAULT
: x_cur
= XC_left_ptr
; break;
91 case wxCURSOR_HAND
: x_cur
= XC_hand1
; break;
92 case wxCURSOR_CROSS
: x_cur
= XC_crosshair
; break;
93 case wxCURSOR_SIZEWE
: x_cur
= XC_sb_h_double_arrow
; break;
94 case wxCURSOR_SIZENS
: x_cur
= XC_sb_v_double_arrow
; break;
95 case wxCURSOR_ARROWWAIT
:
97 case wxCURSOR_WATCH
: x_cur
= XC_watch
; break;
98 case wxCURSOR_SIZING
: x_cur
= XC_sizing
; break;
99 case wxCURSOR_SPRAYCAN
: x_cur
= XC_spraycan
; break;
100 case wxCURSOR_IBEAM
: x_cur
= XC_xterm
; break;
101 case wxCURSOR_PENCIL
: x_cur
= XC_pencil
; break;
102 case wxCURSOR_NO_ENTRY
: x_cur
= XC_pirate
; break;
103 case wxCURSOR_SIZENWSE
:
104 case wxCURSOR_SIZENESW
: x_cur
= XC_fleur
; break;
105 case wxCURSOR_QUESTION_ARROW
: x_cur
= XC_question_arrow
; break;
106 case wxCURSOR_PAINT_BRUSH
: x_cur
= XC_spraycan
; break;
107 case wxCURSOR_MAGNIFIER
: x_cur
= XC_plus
; break;
108 case wxCURSOR_CHAR
: x_cur
= XC_xterm
; break;
109 case wxCURSOR_LEFT_BUTTON
: x_cur
= XC_leftbutton
; break;
110 case wxCURSOR_MIDDLE_BUTTON
: x_cur
= XC_middlebutton
; break;
111 case wxCURSOR_RIGHT_BUTTON
: x_cur
= XC_rightbutton
; break;
112 case wxCURSOR_BULLSEYE
: x_cur
= XC_target
; break;
114 case wxCURSOR_POINT_LEFT
: x_cur
= XC_sb_left_arrow
; break;
115 case wxCURSOR_POINT_RIGHT
: x_cur
= XC_sb_right_arrow
; break;
117 case wxCURSOR_DOUBLE_ARROW: x_cur = XC_double_arrow; break;
118 case wxCURSOR_CROSS_REVERSE: x_cur = XC_cross_reverse; break;
119 case wxCURSOR_BASED_ARROW_UP: x_cur = XC_based_arrow_up; break;
120 case wxCURSOR_BASED_ARROW_DOWN: x_cur = XC_based_arrow_down; break;
123 wxFAIL_MSG(wxT("unsupported cursor type"));
124 // will use the standard one
127 M_CURSORDATA
->m_cursor
= (WXCursor
) XCreateFontCursor( (Display
*) M_CURSORDATA
->m_display
, x_cur
);
131 wxCursor::wxCursor(const wxString
& WXUNUSED(name
),
132 wxBitmapType
WXUNUSED(type
),
133 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
))
135 wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") );
139 wxCursor::wxCursor( const wxImage
& WXUNUSED(image
) )
141 wxFAIL_MSG( wxT("wxCursor creation from wxImage not yet implemented") );
145 wxCursor::~wxCursor()
149 wxGDIRefData
*wxCursor::CreateGDIRefData() const
151 return new wxCursorRefData
;
155 wxCursor::CloneGDIRefData(const wxGDIRefData
* WXUNUSED(data
)) const
157 wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxX11.") );
159 return new wxCursorRefData
;
162 WXCursor
wxCursor::GetCursor() const
164 return M_CURSORDATA
->m_cursor
;
167 //-----------------------------------------------------------------------------
168 // busy cursor routines
169 //-----------------------------------------------------------------------------
171 /* extern */ wxCursor g_globalCursor
;
173 static wxCursor gs_savedCursor
;
174 static int gs_busyCount
= 0;
176 const wxCursor
&wxBusyCursor::GetStoredCursor()
178 return gs_savedCursor
;
181 const wxCursor
wxBusyCursor::GetBusyCursor()
183 return wxCursor(wxCURSOR_WATCH
);
186 void wxEndBusyCursor()
188 if (--gs_busyCount
> 0)
191 wxSetCursor( gs_savedCursor
);
192 gs_savedCursor
= wxNullCursor
;
195 wxTheApp
->ProcessIdle();
198 void wxBeginBusyCursor( const wxCursor
*WXUNUSED(cursor
) )
200 if (gs_busyCount
++ > 0)
203 wxASSERT_MSG( !gs_savedCursor
.IsOk(),
204 wxT("forgot to call wxEndBusyCursor, will leak memory") );
206 gs_savedCursor
= g_globalCursor
;
208 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
211 wxTheApp
->ProcessIdle();
216 return gs_busyCount
> 0;
219 void wxSetCursor( const wxCursor
& cursor
)
221 g_globalCursor
= cursor
;