X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/69659fd770f615210efac4b4fa741b3ad6223616..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/cocoa/cursor.mm diff --git a/src/cocoa/cursor.mm b/src/cocoa/cursor.mm index 7f3ec31b19..c0458ce439 100644 --- a/src/cocoa/cursor.mm +++ b/src/cocoa/cursor.mm @@ -259,13 +259,6 @@ static inline NSCursor* NSCursorCreateWithPrivateId(short sIndex) return theCursor; } -// TODO: Remove in trunk.. needed for 2.8 -NSCursor* wxGetStockCursor( short sIndex ) -{ - wxLogDebug("Please do not call wxGetStockCursor."); - return NSCursorCreateWithPrivateId(sIndex); -} - wxCursorRefData::wxCursorRefData() : m_width(32), m_height(32), m_hCursor(nil) { @@ -400,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; @@ -424,7 +433,7 @@ wxCursor::wxCursor(int stock_cursor_id) { int privateId; if( (privateId = GetPrivateCursorIdForStockCursor(stock_cursor_id)) >= 0) - { // wxGetStockCursor is not a get method but an alloc method. + { M_CURSORDATA->m_hCursor = NSCursorCreateWithPrivateId(privateId); } } @@ -432,12 +441,19 @@ wxCursor::wxCursor(int stock_cursor_id) // Stage 3: Give up, complain, and use a normal arrow if(M_CURSORDATA->m_hCursor == nil) { - wxLogDebug("Could not find suitable cursor for wxStockCursor = %d. Using normal pointer.", stock_cursor_id); + wxLogDebug(wxT("Could not find suitable cursor for wxStockCursor = %d. Using normal pointer."), stock_cursor_id); M_CURSORDATA->m_hCursor = [[NSCursor arrowCursor] retain]; } // 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()