X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8f7b34a878bbcb2f71a0c7694e2a3bec51460218..54a6974c51b533d398bfc13f06cf5e26f13866c1:/src/mgl/cursor.cpp diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index 0764b93519..b2a4c69a7c 100644 --- a/src/mgl/cursor.cpp +++ b/src/mgl/cursor.cpp @@ -1,17 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: cursor.cpp +// Name: src/mgl/cursor.cpp // Purpose: // Author: Vaclav Slavik // Id: $Id$ -// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "cursor.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -20,11 +15,13 @@ #endif #include "wx/cursor.h" +#include "wx/module.h" #include "wx/utils.h" #include "wx/log.h" #include "wx/intl.h" +#include "wx/hashmap.h" -#include +#include "wx/mgl/private.h" //----------------------------------------------------------------------------- @@ -51,9 +48,13 @@ wxCursorRefData::~wxCursorRefData() delete m_cursor; } +#define M_CURSORDATA ((wxCursorRefData *)m_refData) + //----------------------------------------------------------------------------- -#define M_CURSORDATA ((wxCursorRefData *)m_refData) +WX_DECLARE_HASH_MAP(int, wxCursor, wxIntegerHash, wxIntegerEqual, wxCursorsHash); + +static wxCursorsHash *gs_cursorsHash = NULL; IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject) @@ -63,12 +64,23 @@ wxCursor::wxCursor() wxCursor::wxCursor(int cursorId) { + if ( !gs_cursorsHash ) + gs_cursorsHash = new wxCursorsHash; + + if ( gs_cursorsHash->find(cursorId) != gs_cursorsHash->end() ) + { + wxLogTrace(_T("mglcursor"), _T("cursor id %i fetched from cache"), cursorId); + *this = (*gs_cursorsHash)[cursorId]; + return; + } + const char *cursorname = NULL; m_refData = new wxCursorRefData(); switch (cursorId) { case wxCURSOR_ARROW: cursorname = "arrow.cur"; break; + case wxCURSOR_RIGHT_ARROW: cursorname = "rightarr.cur"; break; case wxCURSOR_BULLSEYE: cursorname = "bullseye.cur"; break; case wxCURSOR_CHAR: cursorname = "char.cur"; break; case wxCURSOR_CROSS: cursorname = "cross.cur"; break; @@ -95,17 +107,14 @@ wxCursor::wxCursor(int cursorId) case wxCURSOR_BLANK: cursorname = "blank.cur"; break; case wxCURSOR_NONE: - // FIXME_MGL - make sure wxWindow uses cursor with - // GetMGLCursor() == NULL correctly, i.e. calls MS_hide() *this = wxNullCursor; return; - break; default: wxFAIL_MSG(wxT("unsupported cursor type")); break; } - + M_CURSORDATA->m_cursor = new MGLCursor(cursorname); // if we cannot load arrow cursor, use MGL's default arrow cursor: @@ -114,12 +123,18 @@ wxCursor::wxCursor(int cursorId) delete M_CURSORDATA->m_cursor; M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR); } - + if ( !M_CURSORDATA->m_cursor->valid() ) { wxLogError(_("Couldn't create cursor.")); UnRef(); } + else + { + (*gs_cursorsHash)[cursorId] = *this; + wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"), + cursorId, cursorname); + } } wxCursor::wxCursor(const char WXUNUSED(bits)[], @@ -134,7 +149,7 @@ wxCursor::wxCursor(const char WXUNUSED(bits)[], wxCursor::wxCursor(const wxString& cursor_file, long flags, - int hotSpotX, int hotSpotY) + int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) { if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE ) { @@ -152,24 +167,11 @@ wxCursor::wxCursor(const wxString& cursor_file, } } -wxCursor::wxCursor(const wxCursor &cursor) -{ - Ref(cursor); -} - wxCursor::~wxCursor() { // wxObject unrefs data } -wxCursor& wxCursor::operator = (const wxCursor& cursor) -{ - if ( *this == cursor ) - return (*this); - Ref(cursor); - return *this; -} - bool wxCursor::operator == (const wxCursor& cursor) const { return (m_refData == cursor.m_refData); @@ -196,13 +198,21 @@ MGLCursor *wxCursor::GetMGLCursor() const // Global cursor setting // ---------------------------------------------------------------------------- +static wxCursor gs_globalCursor = wxNullCursor; void wxSetCursor(const wxCursor& cursor) { if ( cursor.Ok() ) { - //MGL_setGlobalCursor(cursor.GetMGLCursor()); - // FIXME_MGL -- needs MGL WM first + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); + gs_globalCursor = cursor; + } + else + { + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, NULL); + gs_globalCursor = wxNullCursor; } } @@ -212,10 +222,7 @@ void wxSetCursor(const wxCursor& cursor) // busy cursor routines //----------------------------------------------------------------------------- -// FIXME_MGL -- do we need this? It may be better to incorporate -// support for it into MGL (a stack of global cursors?) -static wxCursor gs_savedCursor; -static wxCursor g_globalCursor; +static wxCursor gs_savedCursor = wxNullCursor; static int gs_busyCount = 0; const wxCursor &wxBusyCursor::GetStoredCursor() @@ -225,7 +232,7 @@ const wxCursor &wxBusyCursor::GetStoredCursor() const wxCursor wxBusyCursor::GetBusyCursor() { - return wxCursor(wxCURSOR_WAIT); + return gs_globalCursor; } void wxEndBusyCursor() @@ -234,19 +241,20 @@ void wxEndBusyCursor() wxSetCursor(gs_savedCursor); gs_savedCursor = wxNullCursor; - //wxYield(); FIXME_MGL - needed? } -void wxBeginBusyCursor(wxCursor *WXUNUSED(cursor)) +void wxBeginBusyCursor(wxCursor *cursor) { if ( gs_busyCount++ > 0 ) return; wxASSERT_MSG( !gs_savedCursor.Ok(), wxT("forgot to call wxEndBusyCursor, will leak memory") ); - gs_savedCursor = g_globalCursor; - wxSetCursor(wxCursor(wxCURSOR_WAIT)); - //wxYield(); FIXME_MGL - needed? + gs_savedCursor = gs_globalCursor; + if ( cursor->Ok() ) + wxSetCursor(*cursor); + else + wxSetCursor(wxCursor(wxCURSOR_WAIT)); } bool wxIsBusy() @@ -254,3 +262,24 @@ bool wxIsBusy() return (gs_busyCount > 0); } + + +//----------------------------------------------------------------------------- +// module - clean up code +//----------------------------------------------------------------------------- + +class wxCursorModule : public wxModule +{ +public: + virtual bool OnInit() { return true; } + + virtual void OnExit() + { + wxDELETE(gs_cursorsHash); + } + +private: + DECLARE_DYNAMIC_CLASS(wxCursorModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxCursorModule, wxModule)