X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ef344ff86223f1f0961f025c0b249c898529c095..4566d7db6fc8adaecc8c5d5245a6b876c114496a:/src/mgl/cursor.cpp diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index eb959e8ff8..3ec1a27da2 100644 --- a/src/mgl/cursor.cpp +++ b/src/mgl/cursor.cpp @@ -3,12 +3,12 @@ // 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__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "cursor.h" #endif @@ -20,9 +20,11 @@ #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 "wx/mgl/private.h" @@ -51,9 +53,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,15 +69,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) { - // FIXME_MGL -- what about storing these default cursors in executable - // as XPMs so that wxMGL binary wouldn't depend on - // tons of files in $MGL_ROOT/cursors? I don't know yet... 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; @@ -121,6 +135,12 @@ wxCursor::wxCursor(int cursorId) 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)[], @@ -197,14 +217,21 @@ MGLCursor *wxCursor::GetMGLCursor() const // Global cursor setting // ---------------------------------------------------------------------------- -static wxCursor g_globalCursor = wxNullCursor; +static wxCursor gs_globalCursor = wxNullCursor; void wxSetCursor(const wxCursor& cursor) { if ( cursor.Ok() ) { - MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); - g_globalCursor = cursor; + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); + gs_globalCursor = cursor; + } + else + { + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, NULL); + gs_globalCursor = wxNullCursor; } } @@ -224,7 +251,7 @@ const wxCursor &wxBusyCursor::GetStoredCursor() const wxCursor wxBusyCursor::GetBusyCursor() { - return wxCursor(wxCURSOR_WAIT); + return gs_globalCursor; } void wxEndBusyCursor() @@ -242,7 +269,7 @@ void wxBeginBusyCursor(wxCursor *cursor) wxASSERT_MSG( !gs_savedCursor.Ok(), wxT("forgot to call wxEndBusyCursor, will leak memory") ); - gs_savedCursor = g_globalCursor; + gs_savedCursor = gs_globalCursor; if ( cursor->Ok() ) wxSetCursor(*cursor); else @@ -254,3 +281,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)