X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..c9ed413ab4f5673ffff00198dc6ce1397398bda4:/src/osx/carbon/cursor.cpp?ds=sidebyside diff --git a/src/osx/carbon/cursor.cpp b/src/osx/carbon/cursor.cpp index af2f32a726..fddaa09533 100644 --- a/src/osx/carbon/cursor.cpp +++ b/src/osx/carbon/cursor.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/cursor.cpp +// Name: src/osx/carbon/cursor.cpp // Purpose: wxCursor class // Author: Stefan Csomor // Modified by: @@ -36,33 +36,42 @@ public: virtual bool IsOk() const { +#if wxOSX_USE_COCOA_OR_CARBON if ( m_hCursor != NULL ) return true; -#if !wxMAC_USE_COCOA +#if wxOSX_USE_CARBON if ( m_themeCursor != -1 ) return true; #endif return false; +#else + // in order to avoid asserts, always claim to have a valid cursor + return true; +#endif } protected: -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA WX_NSCursor m_hCursor; -#else +#elif wxOSX_USE_CARBON WXHCURSOR m_hCursor; bool m_disposeHandle; bool m_releaseHandle; bool m_isColorCursor; long m_themeCursor; +#elif wxOSX_USE_IPHONE + void* m_hCursor; #endif friend class wxCursor; - DECLARE_NO_ASSIGN_CLASS(wxCursorRefData) + wxDECLARE_NO_ASSIGN_CLASS(wxCursorRefData); }; -#define M_CURSORDATA wx_static_cast(wxCursorRefData*, m_refData) +#define M_CURSORDATA static_cast(m_refData) + +#if wxOSX_USE_COCOA_OR_CARBON ClassicCursor gMacCursors[kwxCursorLast+1] = { @@ -189,9 +198,11 @@ ClassicCursor gMacCursors[kwxCursorLast+1] = }; +#endif + wxCursor gMacCurrentCursor ; -#if !wxMAC_USE_COCOA +#if wxOSX_USE_CARBON CursHandle wxGetStockCursor( int number ) { wxASSERT_MSG( number >= 0 && number <=kwxCursorLast , wxT("invalid stock cursor id") ) ; @@ -212,8 +223,7 @@ CursHandle wxGetStockCursor( int number ) wxCursorRefData::wxCursorRefData() { m_hCursor = NULL; -#if wxMAC_USE_COCOA -#else +#if wxOSX_USE_CARBON m_disposeHandle = false; m_releaseHandle = false; m_isColorCursor = false; @@ -223,12 +233,12 @@ wxCursorRefData::wxCursorRefData() wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) { - // FIXME: need to copy the cursor m_hCursor = NULL; -#if wxMAC_USE_COCOA - wxUnusedVar(cursor); -#else +#if wxOSX_USE_COCOA + m_hCursor = (WX_NSCursor) wxMacCocoaRetain(cursor.m_hCursor); +#elif wxOSX_USE_CARBON + // FIXME: need to copy the cursor m_disposeHandle = false; m_releaseHandle = false; m_isColorCursor = cursor.m_isColorCursor; @@ -238,10 +248,10 @@ wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) wxCursorRefData::~wxCursorRefData() { -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA if ( m_hCursor ) wxMacCocoaRelease(m_hCursor); -#else +#elif wxOSX_USE_CARBON if ( m_isColorCursor ) { #ifndef __LP64__ @@ -264,11 +274,6 @@ wxCursor::wxCursor() { } -wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) -{ -} - wxCursor::wxCursor( const wxImage &image ) { #if wxUSE_IMAGE @@ -276,11 +281,6 @@ wxCursor::wxCursor( const wxImage &image ) #endif } -wxCursor::wxCursor(const char* const* bits) -{ - (void) CreateFromXpm(bits); -} - wxGDIRefData *wxCursor::CreateGDIRefData() const { return new wxCursorRefData; @@ -288,21 +288,7 @@ wxGDIRefData *wxCursor::CreateGDIRefData() const wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); -} - -bool wxCursor::CreateFromXpm(const char* const* bits) -{ -#if wxUSE_IMAGE - wxCHECK_MSG( bits != NULL, false, wxT("invalid cursor data") ); - wxXPMDecoder decoder; - wxImage img = decoder.ReadData(bits); - wxCHECK_MSG( img.Ok(), false, wxT("invalid cursor data") ); - CreateFromImage( img ) ; - return true; -#else - return false; -#endif + return new wxCursorRefData(*static_cast(data)); } WXHCURSOR wxCursor::GetHCURSOR() const @@ -310,7 +296,7 @@ WXHCURSOR wxCursor::GetHCURSOR() const return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } -#if !wxMAC_USE_COCOA +#if wxOSX_USE_CARBON short GetCTabIndex( CTabHandle colors , RGBColor *col ) { short retval = 0 ; @@ -340,15 +326,15 @@ void wxCursor::CreateFromImage(const wxImage & image) m_refData = new wxCursorRefData; int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA wxBitmap bmp( image ); CGImageRef cgimage = wxMacCreateCGImageFromBitmap(bmp); if ( cgimage ) { - M_CURSORDATA->m_hCursor = wxMacCocoaCreateCursorFromCGImage( cgimage, hotSpotX, hotSpotY ); + M_CURSORDATA->m_hCursor = wxMacCocoaCreateCursorFromCGImage( cgimage, hotSpotX, hotSpotY ); CFRelease( cgimage ); } -#else +#elif wxOSX_USE_CARBON #ifndef __LP64__ int w = 16; int h = 16; @@ -489,9 +475,9 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX m_refData = new wxCursorRefData; if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE ) { -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA wxFAIL_MSG( wxT("Not implemented") ); -#else +#elif wxOSX_USE_CARBON #ifndef __LP64__ Str255 theName ; wxMacStringToPascal( cursor_file , theName ) ; @@ -546,12 +532,12 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX } // Cursors by stock number -wxCursor::wxCursor(int cursor_type) +void wxCursor::InitFromStock(wxStockCursor cursor_type) { m_refData = new wxCursorRefData; -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA M_CURSORDATA->m_hCursor = wxMacCocoaCreateStockCursor( cursor_type ); -#else +#elif wxOSX_USE_CARBON switch (cursor_type) { case wxCURSOR_COPY_ARROW: @@ -642,6 +628,14 @@ wxCursor::wxCursor(int cursor_type) M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorRoller); break; + case wxCURSOR_OPEN_HAND: + M_CURSORDATA->m_themeCursor = kThemeOpenHandCursor; + break; + + case wxCURSOR_CLOSED_HAND: + M_CURSORDATA->m_themeCursor = kThemeClosedHandCursor; + break; + case wxCURSOR_CHAR: case wxCURSOR_ARROW: case wxCURSOR_LEFT_BUTTON: @@ -660,10 +654,10 @@ wxCursor::wxCursor(int cursor_type) void wxCursor::MacInstall() const { gMacCurrentCursor = *this ; -#if wxMAC_USE_COCOA +#if wxOSX_USE_COCOA if ( IsOk() ) wxMacCocoaSetCursor( M_CURSORDATA->m_hCursor ); -#else +#elif wxOSX_USE_CARBON if ( m_refData && M_CURSORDATA->m_themeCursor != -1 ) { SetThemeCursor( M_CURSORDATA->m_themeCursor ) ;