X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/637b7e4f3a0fd1c6bdfc21d28e37bcf760e3b364..bbd92d1dbea02db8c28e9c17bfacc0563d855b25:/src/mac/carbon/cursor.cpp diff --git a/src/mac/carbon/cursor.cpp b/src/mac/carbon/cursor.cpp index caa824901d..c48663d7fd 100644 --- a/src/mac/carbon/cursor.cpp +++ b/src/mac/carbon/cursor.cpp @@ -6,63 +6,65 @@ // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" -#include "wx/app.h" #include "wx/cursor.h" -#include "wx/icon.h" -#include "wx/image.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/icon.h" + #include "wx/image.h" +#endif // WX_PRECOMP + #include "wx/xpmdecod.h" #include "wx/mac/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) +IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject) -class WXDLLEXPORT wxCursorRefData: public wxBitmapRefData +class WXDLLEXPORT wxCursorRefData: public wxGDIRefData { - DECLARE_NO_COPY_CLASS(wxCursorRefData) - - friend class WXDLLEXPORT wxBitmap; - friend class WXDLLEXPORT wxCursor; - public: wxCursorRefData(); - ~wxCursorRefData(); + wxCursorRefData(const wxCursorRefData& cursor); + virtual ~wxCursorRefData(); + + virtual bool IsOk() const + { + if ( m_hCursor != NULL ) + return true; +#if !wxMAC_USE_COCOA + if ( m_themeCursor != -1 ) + return true; +#endif + + return false; + } protected: +#if wxMAC_USE_COCOA + WX_NSCursor m_hCursor; +#else WXHCURSOR m_hCursor; bool m_disposeHandle; bool m_releaseHandle; bool m_isColorCursor; long m_themeCursor; -}; +#endif + + friend class wxCursor; -#define M_CURSORDATA ((wxCursorRefData *)m_refData) -#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData) + DECLARE_NO_ASSIGN_CLASS(wxCursorRefData) +}; -const short kwxCursorBullseye = 0; -const short kwxCursorBlank = 1; -const short kwxCursorPencil = 2; -const short kwxCursorMagnifier = 3; -const short kwxCursorNoEntry = 4; -const short kwxCursorPaintBrush = 5; -const short kwxCursorPointRight = 6; -const short kwxCursorPointLeft = 7; -const short kwxCursorQuestionArrow = 8; -const short kwxCursorRightArrow = 9; -const short kwxCursorSizeNS = 10; -const short kwxCursorSize = 11; -const short kwxCursorSizeNESW = 12; -const short kwxCursorSizeNWSE = 13; -const short kwxCursorRoller = 14; -const short kwxCursorLast = kwxCursorRoller; +#define M_CURSORDATA wx_static_cast(wxCursorRefData*, m_refData) -Cursor gMacCursors[kwxCursorLast+1] = +ClassicCursor gMacCursors[kwxCursorLast+1] = { { @@ -189,6 +191,7 @@ Cursor gMacCursors[kwxCursorLast+1] = wxCursor gMacCurrentCursor ; +#if !wxMAC_USE_COCOA CursHandle wxGetStockCursor( int number ) { wxASSERT_MSG( number >= 0 && number <=kwxCursorLast , wxT("invalid stock cursor id") ) ; @@ -204,23 +207,46 @@ CursHandle wxGetStockCursor( int number ) #endif return c ; } +#endif wxCursorRefData::wxCursorRefData() { - SetWidth( 16 ); - SetHeight( 16 ); m_hCursor = NULL; +#if wxMAC_USE_COCOA +#else m_disposeHandle = false; m_releaseHandle = false; m_isColorCursor = false; m_themeCursor = -1; +#endif +} + +wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) +{ + // FIXME: need to copy the cursor + m_hCursor = NULL; + +#if wxMAC_USE_COCOA + wxUnusedVar(cursor); +#else + m_disposeHandle = false; + m_releaseHandle = false; + m_isColorCursor = cursor.m_isColorCursor; + m_themeCursor = cursor.m_themeCursor; +#endif } wxCursorRefData::~wxCursorRefData() { +#if wxMAC_USE_COCOA + if ( m_hCursor ) + wxMacCocoaRelease(m_hCursor); +#else if ( m_isColorCursor ) { - ::DisposeCCursor( (CCrsrHandle) m_hCursor ) ; +#ifndef __LP64__ + ::DisposeCCursor( (CCrsrHandle) m_hCursor ) ; +#endif } else if ( m_disposeHandle ) { @@ -231,6 +257,7 @@ wxCursorRefData::~wxCursorRefData() // we don't release the resource since it may already // be in use again } +#endif } wxCursor::wxCursor() @@ -249,17 +276,22 @@ wxCursor::wxCursor( const wxImage &image ) #endif } -wxCursor::wxCursor(const char **bits) +wxCursor::wxCursor(const char* const* bits) { (void) CreateFromXpm(bits); } -wxCursor::wxCursor(char **bits) +wxGDIRefData *wxCursor::CreateGDIRefData() const +{ + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { - (void) CreateFromXpm((const char **)bits); + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); } -bool wxCursor::CreateFromXpm(const char **bits) +bool wxCursor::CreateFromXpm(const char* const* bits) { #if wxUSE_IMAGE wxCHECK_MSG( bits != NULL, false, wxT("invalid cursor data") ); @@ -278,11 +310,7 @@ WXHCURSOR wxCursor::GetHCURSOR() const return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } -bool wxCursor::Ok() const -{ - return (m_refData != NULL && ( M_CURSORDATA->m_hCursor != NULL || M_CURSORDATA->m_themeCursor != -1 ) ) ; -} - +#if !wxMAC_USE_COCOA short GetCTabIndex( CTabHandle colors , RGBColor *col ) { short retval = 0 ; @@ -303,18 +331,28 @@ short GetCTabIndex( CTabHandle colors , RGBColor *col ) return retval ; } +#endif #if wxUSE_IMAGE 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 + wxBitmap bmp( image ); + CGImageRef cgimage = wxMacCreateCGImageFromBitmap(bmp); + if ( cgimage ) + { + M_CURSORDATA->m_hCursor = wxMacCocoaCreateCursorFromCGImage( cgimage, hotSpotX, hotSpotY ); + CFRelease( cgimage ); + } +#else +#ifndef __LP64__ int w = 16; int h = 16; - int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); - int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); int image_w = image.GetWidth(); int image_h = image.GetHeight(); @@ -440,6 +478,8 @@ void wxCursor::CreateFromImage(const wxImage & image) HUnlock( (Handle)ch ) ; M_CURSORDATA->m_hCursor = ch ; M_CURSORDATA->m_isColorCursor = true ; +#endif +#endif } #endif //wxUSE_IMAGE @@ -449,6 +489,10 @@ wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int ho m_refData = new wxCursorRefData; if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE ) { +#if wxMAC_USE_COCOA + wxFAIL_MSG( wxT("Not implemented") ); +#else +#ifndef __LP64__ Str255 theName ; wxMacStringToPascal( cursor_file , theName ) ; @@ -481,6 +525,8 @@ wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int ho M_CURSORDATA->m_releaseHandle = true ; } } +#endif +#endif } else { @@ -491,7 +537,8 @@ wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int ho { image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ; image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ; - delete m_refData ; + m_refData->DecRef() ; + m_refData = NULL ; CreateFromImage( image ) ; } #endif @@ -502,7 +549,9 @@ wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int ho wxCursor::wxCursor(int cursor_type) { m_refData = new wxCursorRefData; - +#if wxMAC_USE_COCOA + M_CURSORDATA->m_hCursor = wxMacCocoaCreateStockCursor( cursor_type ); +#else switch (cursor_type) { case wxCURSOR_COPY_ARROW: @@ -605,26 +654,34 @@ wxCursor::wxCursor(int cursor_type) if ( M_CURSORDATA->m_themeCursor == -1 ) M_CURSORDATA->m_releaseHandle = true; +#endif } void wxCursor::MacInstall() const { gMacCurrentCursor = *this ; +#if wxMAC_USE_COCOA + if ( IsOk() ) + wxMacCocoaSetCursor( M_CURSORDATA->m_hCursor ); +#else if ( m_refData && M_CURSORDATA->m_themeCursor != -1 ) { SetThemeCursor( M_CURSORDATA->m_themeCursor ) ; } else if ( m_refData && M_CURSORDATA->m_hCursor ) { - if ( M_CURSORDATA->m_isColorCursor ) +#ifndef __LP64__ + if ( M_CURSORDATA->m_isColorCursor ) ::SetCCursor( (CCrsrHandle) M_CURSORDATA->m_hCursor ) ; else ::SetCursor( * (CursHandle) M_CURSORDATA->m_hCursor ) ; +#endif } else { SetThemeCursor( kThemeArrowCursor ) ; } +#endif } wxCursor::~wxCursor() @@ -632,7 +689,9 @@ wxCursor::~wxCursor() } // Global cursor setting +wxCursor gGlobalCursor; void wxSetCursor(const wxCursor& cursor) { cursor.MacInstall() ; + gGlobalCursor = cursor; }