X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/148af7c534dcd3cf129c10db13fc37828d0f3cc1..404b319a85dadd7decf7a5a5331020520031a41c:/src/cocoa/cursor.mm?ds=sidebyside diff --git a/src/cocoa/cursor.mm b/src/cocoa/cursor.mm index 126ef111aa..be8c6adb97 100644 --- a/src/cocoa/cursor.mm +++ b/src/cocoa/cursor.mm @@ -8,7 +8,7 @@ // RCS-ID: $Id$ // Copyright: (c) Ryan Norton // 2007, Software 2000 Ltd. -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" @@ -35,7 +35,7 @@ typedef struct tagClassicCursor }ClassicCursor; /////////////////////////////////////////////////////////////////////////// -// This is a direct copy from src/mac/carbon/cursor.cpp and should be +// This is a direct copy from src/osx/carbon/cursor.cpp and should be // changed to use common code if we plan on keeping it this way. // Note that this is basically an array of classic 'CURS' resources. @@ -181,7 +181,7 @@ ClassicCursor gMacCursors[kwxCursorLast+1] = } ; -// End of data copied from src/mac/carbon/cursor.cpp +// End of data copied from src/osx/carbon/cursor.cpp /////////////////////////////////////////////////////////////////////////// /* NSCursorCreateWithPrivateId @@ -393,9 +393,25 @@ static inline int GetPrivateCursorIdForStockCursor(int stock_cursor_id) return -1; } +// Keep an array of stock cursors so they can share wxCursorRefData and thus +// wxObject::IsSameAs will return true. +// They will obviously be destroyed at static destruction time which should +// theoretically be fine. +static wxCursor s_stockCursors[wxCURSOR_MAX]; + // Cursors by stock number (enum wxStockCursor) wxCursor::wxCursor(int stock_cursor_id) { + // We default-constructed wxObject so our m_refData == NULL + if(stock_cursor_id >= 0 && stock_cursor_id < wxCURSOR_MAX) + { + // Attempt to reference an existing stock cursor + Ref(s_stockCursors[stock_cursor_id]); + } + // If we succeeded in getting an existing stock cursor, we're done. + if(m_refData != NULL) + return; + m_refData = new wxCursorRefData; M_CURSORDATA->m_hCursor = nil; @@ -431,6 +447,13 @@ wxCursor::wxCursor(int stock_cursor_id) // This should never happen as the arrowCursor should always exist. wxASSERT(M_CURSORDATA->m_hCursor != nil); + + // Store ourself as the new stock cursor for this ID so that future + // calls will share the same ref data. + if(stock_cursor_id >= 0 && stock_cursor_id < wxCURSOR_MAX) + { + s_stockCursors[stock_cursor_id] = *this; + } } wxCursor::~wxCursor()