X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/osx/carbon/cursor.cpp diff --git a/src/osx/carbon/cursor.cpp b/src/osx/carbon/cursor.cpp index af2f32a726..fba9efb8f5 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] = { @@ -187,11 +196,21 @@ ClassicCursor gMacCursors[kwxCursorLast+1] = {0x000A, 0x0006} }, +{ +{0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x0810, 0x1088, 0x1088, 0x1088, +0x1388, 0x1008, 0x1008, 0x0810, 0x07E0, 0x07E0, 0x07E0, 0x07E0}, +{0x07E0, 0x07E0, 0x07E0, 0x07E0, 0x0FF0, 0x1FF8, 0x1FF8, 0x1FF8, +0x1FF8, 0x1FF8, 0x1FF8, 0x0FF0, 0x07E0, 0x07E0, 0x07E0, 0x07E0}, +{0x0008, 0x0008} +}, + }; +#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 +231,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; @@ -221,14 +239,14 @@ wxCursorRefData::wxCursorRefData() #endif } -wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) +wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) : wxGDIRefData() { - // 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 +256,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 +282,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 +289,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 +296,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 +304,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 +334,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 +483,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 ) ; @@ -533,7 +527,7 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX #if wxUSE_IMAGE wxImage image ; image.LoadFile( cursor_file, flags ) ; - if ( image.Ok() ) + if ( image.IsOk() ) { image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ; image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ; @@ -546,12 +540,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 +636,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 +662,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 ) ;