X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5fd1ea325c96d90db1bf84eb477026f38d710e68..41ce9ae1b02dbfbe467978be871506246d7ab48e:/src/mgl/cursor.cpp diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index f1ce135b33..eedb0085dc 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,9 +15,14 @@ #endif #include "wx/cursor.h" -#include "wx/utils.h" -#include "wx/log.h" -#include "wx/intl.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/utils.h" + #include "wx/hashmap.h" + #include "wx/module.h" +#endif #include "wx/mgl/private.h" @@ -36,14 +36,14 @@ class wxCursorRefData: public wxObjectRefData public: wxCursorRefData(); - ~wxCursorRefData(); + virtual ~wxCursorRefData(); MGLCursor *m_cursor; }; wxCursorRefData::wxCursorRefData() { - m_cursor = (MGLCursor*) NULL; + m_cursor = NULL; } wxCursorRefData::~wxCursorRefData() @@ -51,9 +51,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) @@ -61,17 +65,25 @@ wxCursor::wxCursor() { } -wxCursor::wxCursor(int cursorId) +void wxCursor::InitFromStock(wxStockCursor 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; @@ -100,13 +112,12 @@ wxCursor::wxCursor(int cursorId) case wxCURSOR_NONE: *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: @@ -115,29 +126,25 @@ 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(); } -} - -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[], - wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) ) -{ - //FIXME_MGL + else + { + (*gs_cursorsHash)[cursorId] = *this; + wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"), + cursorId, cursorname); + } } wxCursor::wxCursor(const wxString& cursor_file, - long flags, - int hotSpotX, int hotSpotY) + wxBitmapType type, + int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) { - if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE ) + if ( type == wxBITMAP_TYPE_CUR || type == wxBITMAP_TYPE_CUR_RESOURCE ) { m_refData = new wxCursorRefData(); M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str()); @@ -153,39 +160,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); -} - -bool wxCursor::operator != (const wxCursor& cursor) const -{ - return (m_refData != cursor.m_refData); -} - -bool wxCursor::Ok() const -{ - return (m_refData != NULL); -} - MGLCursor *wxCursor::GetMGLCursor() const { return M_CURSORDATA->m_cursor; @@ -203,13 +182,15 @@ void wxSetCursor(const wxCursor& cursor) { if ( cursor.Ok() ) { - MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); gs_globalCursor = cursor; } else { - MGL_wmSetGlobalCursor(g_winMng, NULL); - gs_globalCursor = wxNullCursor; + if ( g_winMng ) + MGL_wmSetGlobalCursor(g_winMng, NULL); + gs_globalCursor = wxNullCursor; } } @@ -240,7 +221,7 @@ void wxEndBusyCursor() gs_savedCursor = wxNullCursor; } -void wxBeginBusyCursor(wxCursor *cursor) +void wxBeginBusyCursor(const wxCursor *cursor) { if ( gs_busyCount++ > 0 ) return; @@ -259,3 +240,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)