1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "cursor.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/cursor.h"
27 #include "wx/mgl/private.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 class wxCursorRefData
: public wxObjectRefData
44 wxCursorRefData::wxCursorRefData()
46 m_cursor
= (MGLCursor
*) NULL
;
49 wxCursorRefData::~wxCursorRefData()
54 //-----------------------------------------------------------------------------
56 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
58 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
64 wxCursor::wxCursor(int cursorId
)
66 const char *cursorname
= NULL
;
67 m_refData
= new wxCursorRefData();
71 // FIXME_MGL -- what about storing these default cursors in executable
72 // as XPMs so that wxMGL binary wouldn't depend on
73 // tons of files in $MGL_ROOT/cursors? I don't know yet...
74 case wxCURSOR_ARROW
: cursorname
= "arrow.cur"; break;
75 case wxCURSOR_BULLSEYE
: cursorname
= "bullseye.cur"; break;
76 case wxCURSOR_CHAR
: cursorname
= "char.cur"; break;
77 case wxCURSOR_CROSS
: cursorname
= "cross.cur"; break;
78 case wxCURSOR_HAND
: cursorname
= "hand.cur"; break;
79 case wxCURSOR_IBEAM
: cursorname
= "ibeam.cur"; break;
80 case wxCURSOR_LEFT_BUTTON
: cursorname
= "leftbtn.cur"; break;
81 case wxCURSOR_MAGNIFIER
: cursorname
= "magnif1.cur"; break;
82 case wxCURSOR_MIDDLE_BUTTON
: cursorname
= "midbtn.cur"; break;
83 case wxCURSOR_NO_ENTRY
: cursorname
= "noentry.cur"; break;
84 case wxCURSOR_PAINT_BRUSH
: cursorname
= "pbrush.cur"; break;
85 case wxCURSOR_PENCIL
: cursorname
= "pencil.cur"; break;
86 case wxCURSOR_POINT_LEFT
: cursorname
= "pntleft.cur"; break;
87 case wxCURSOR_POINT_RIGHT
: cursorname
= "pntright.cur"; break;
88 case wxCURSOR_QUESTION_ARROW
: cursorname
= "query.cur"; break;
89 case wxCURSOR_RIGHT_BUTTON
: cursorname
= "rightbtn.cur"; break;
90 case wxCURSOR_SIZENESW
: cursorname
= "sizenesw.cur"; break;
91 case wxCURSOR_SIZENS
: cursorname
= "sizens.cur"; break;
92 case wxCURSOR_SIZENWSE
: cursorname
= "sizenwse.cur"; break;
93 case wxCURSOR_SIZEWE
: cursorname
= "sizewe.cur"; break;
94 case wxCURSOR_SIZING
: cursorname
= "size.cur"; break;
95 case wxCURSOR_SPRAYCAN
: cursorname
= "spraycan.cur"; break;
96 case wxCURSOR_WAIT
: cursorname
= "wait.cur"; break;
97 case wxCURSOR_WATCH
: cursorname
= "clock.cur"; break;
98 case wxCURSOR_BLANK
: cursorname
= "blank.cur"; break;
101 *this = wxNullCursor
;
106 wxFAIL_MSG(wxT("unsupported cursor type"));
110 M_CURSORDATA
->m_cursor
= new MGLCursor(cursorname
);
112 // if we cannot load arrow cursor, use MGL's default arrow cursor:
113 if ( !M_CURSORDATA
->m_cursor
->valid() && cursorId
== wxCURSOR_ARROW
)
115 delete M_CURSORDATA
->m_cursor
;
116 M_CURSORDATA
->m_cursor
= new MGLCursor(MGL_DEF_CURSOR
);
119 if ( !M_CURSORDATA
->m_cursor
->valid() )
121 wxLogError(_("Couldn't create cursor."));
126 wxCursor::wxCursor(const char WXUNUSED(bits
)[],
128 int WXUNUSED(height
),
129 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
),
130 const char WXUNUSED(maskBits
)[],
131 wxColour
* WXUNUSED(fg
), wxColour
* WXUNUSED(bg
) )
136 wxCursor::wxCursor(const wxString
& cursor_file
,
138 int hotSpotX
, int hotSpotY
)
140 if ( flags
== wxBITMAP_TYPE_CUR
|| flags
== wxBITMAP_TYPE_CUR_RESOURCE
)
142 m_refData
= new wxCursorRefData();
143 M_CURSORDATA
->m_cursor
= new MGLCursor(cursor_file
.mb_str());
144 if ( !M_CURSORDATA
->m_cursor
->valid() )
146 wxLogError(_("Couldn't create cursor."));
152 wxLogError(wxT("Cannot load cursor resource of this type."));
156 wxCursor::wxCursor(const wxCursor
&cursor
)
161 wxCursor::~wxCursor()
163 // wxObject unrefs data
166 wxCursor
& wxCursor::operator = (const wxCursor
& cursor
)
168 if ( *this == cursor
)
174 bool wxCursor::operator == (const wxCursor
& cursor
) const
176 return (m_refData
== cursor
.m_refData
);
179 bool wxCursor::operator != (const wxCursor
& cursor
) const
181 return (m_refData
!= cursor
.m_refData
);
184 bool wxCursor::Ok() const
186 return (m_refData
!= NULL
);
189 MGLCursor
*wxCursor::GetMGLCursor() const
191 return M_CURSORDATA
->m_cursor
;
196 // ----------------------------------------------------------------------------
197 // Global cursor setting
198 // ----------------------------------------------------------------------------
200 static wxCursor gs_globalCursor
= wxNullCursor
;
202 void wxSetCursor(const wxCursor
& cursor
)
206 MGL_wmSetGlobalCursor(g_winMng
, *cursor
.GetMGLCursor());
207 gs_globalCursor
= cursor
;
211 MGL_wmSetGlobalCursor(g_winMng
, NULL
);
212 gs_globalCursor
= wxNullCursor
;
218 //-----------------------------------------------------------------------------
219 // busy cursor routines
220 //-----------------------------------------------------------------------------
222 static wxCursor gs_savedCursor
= wxNullCursor
;
223 static int gs_busyCount
= 0;
225 const wxCursor
&wxBusyCursor::GetStoredCursor()
227 return gs_savedCursor
;
230 const wxCursor
wxBusyCursor::GetBusyCursor()
232 return gs_globalCursor
;
235 void wxEndBusyCursor()
237 if ( --gs_busyCount
> 0 ) return;
239 wxSetCursor(gs_savedCursor
);
240 gs_savedCursor
= wxNullCursor
;
243 void wxBeginBusyCursor(wxCursor
*cursor
)
245 if ( gs_busyCount
++ > 0 ) return;
247 wxASSERT_MSG( !gs_savedCursor
.Ok(),
248 wxT("forgot to call wxEndBusyCursor, will leak memory") );
250 gs_savedCursor
= gs_globalCursor
;
252 wxSetCursor(*cursor
);
254 wxSetCursor(wxCursor(wxCURSOR_WAIT
));
259 return (gs_busyCount
> 0);