X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/082642722c2d2299f9abeb4e7046b6ce19989abb..6a6e2822455ac3275dad20d5a0b474e4eb4b2582:/src/cocoa/cursor.mm diff --git a/src/cocoa/cursor.mm b/src/cocoa/cursor.mm index c6adebd707..f5b548cc42 100644 --- a/src/cocoa/cursor.mm +++ b/src/cocoa/cursor.mm @@ -1,31 +1,27 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: cursor.mm +// Name: src/cocoa/cursor.mm // Purpose: wxCursor class for wxCocoa // Author: Ryan Norton // Modified by: // Created: 2004-10-05 // RCS-ID: $Id$ // Copyright: (c) Ryan Norton -// Licence: wxWidgets licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "cursor.h" -#endif - #include "wx/wxprec.h" + +#include "wx/cursor.h" + #ifndef WX_PRECOMP #include "wx/icon.h" - #include "wx/cursor.h" #endif //WX_PRECOMP #import #import -#include +#include "wx/cocoa/string.h" -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) -#endif typedef struct tagClassicCursor { @@ -180,62 +176,63 @@ NSCursor* wxGetStockCursor( short sIndex ) { ClassicCursor* pCursor = &gMacCursors[sIndex]; - //Classic mac cursors are 1bps 16x16 black and white with a + //Classic mac cursors are 1bps 16x16 black and white with a //identical mask that is 1 for on and 0 for off NSImage *theImage = [[NSImage alloc] initWithSize:NSMakeSize(16.0,16.0)]; - + //NSCursor takes an NSImage takes a number of Representations - here //we need only one for the raw data - NSBitmapImageRep *theRep = - [[NSBitmapImageRep alloc] + NSBitmapImageRep *theRep = + [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil // Allocate the buffer for us :) - pixelsWide: 16 + pixelsWide: 16 pixelsHigh: 16 bitsPerSample: 1 - samplesPerPixel: 2 - hasAlpha: YES // Well, more like a mask... - isPlanar: NO + samplesPerPixel: 2 + hasAlpha: YES // Well, more like a mask... + isPlanar: NO colorSpaceName: NSCalibratedWhiteColorSpace // Normal B/W - 0 black 1 white bytesPerRow: 0 // I don't care - figure it out for me :) bitsPerPixel: 2]; // bitsPerSample * samplesPerPixel - + //unsigned int is better to put data in then a void* //note that working with bitfields would be a lot better here - //but since it breaks some compilers... - wxUint32 *data = (wxUint32 *)[theRep bitmapData]; - + wxUint32 *data = (wxUint32 *)[theRep bitmapData]; + //traverse through the bitmap data for (int i = 0; i < 16; ++i) { //bit alpha bit alpha ... :D - - //Notice the = instead of |= - + + //Notice the = instead of |= - //this is to avoid doing a memset earlier data[i] = 0; - + //do the rest of those bits and alphas :) for (int shift = 0; shift < 32; ++shift) { - data[i] |= ( !!( (pCursor->mask[i] & (1 << (shift >> 1) )) ) ) << shift; - data[i] |= ( !( (pCursor->bits[i] & (1 << (shift >> 1) )) ) ) << ++shift; + const int bit = 1 << (shift >> 1); + data[i] |= ( !!( (pCursor->mask[i] & bit) ) ) << shift; + data[i] |= ( !( (pCursor->bits[i] & bit) ) ) << ++shift; } } //add the representation (data) to the image [theImage addRepresentation:theRep]; - + //create the new cursor - NSCursor* theCursor = [[NSCursor alloc] initWithImage:theImage + NSCursor* theCursor = [[NSCursor alloc] initWithImage:theImage hotSpot:NSMakePoint(pCursor->hotspot[1], pCursor->hotspot[0]) ]; - + //do the usual cleanups - [theRep release]; + [theRep release]; [theImage release]; - + //return the new cursor return theCursor; -} +} wxCursorRefData::wxCursorRefData() : m_width(32), m_height(32), m_hCursor(nil) @@ -256,34 +253,33 @@ 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 wxString& cursor_file, long flags, int hotSpotX, int hotSpotY) { m_refData = new wxCursorRefData; - + //TODO: Not sure if this works or not NSImage* theImage; - + if (flags & wxBITMAP_TYPE_MACCURSOR_RESOURCE) { //[NSBundle bundleForClass:[self class]]? - theImage = [[NSImage alloc] + theImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:wxNSStringWithWxString(cursor_file) ofType:nil] ]; - + } - else + else theImage = [[NSImage alloc] initByReferencingFile:wxNSStringWithWxString(cursor_file) ]; - + wxASSERT(theImage); - + M_CURSORDATA->m_hCursor = [[NSCursor alloc] initWithImage:theImage hotSpot:NSMakePoint(hotSpotX, hotSpotY) ]; - + [theImage release]; } @@ -300,7 +296,7 @@ wxCursor::wxCursor(int cursor_type) case wxCURSOR_ARROW: M_CURSORDATA->m_hCursor = [[NSCursor arrowCursor] retain]; break; -/* TODO: +/* TODO: case wxCURSOR_COPY_ARROW: M_CURSORDATA->m_themeCursor = kThemeCopyArrowCursor ; break; @@ -321,7 +317,7 @@ wxCursor::wxCursor(int cursor_type) M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSizeNESW); } break; -/* TODO: +/* TODO: case wxCURSOR_SIZEWE: { M_CURSORDATA->m_themeCursor = kThemeResizeLeftRightCursor; @@ -338,7 +334,7 @@ wxCursor::wxCursor(int cursor_type) M_CURSORDATA->m_hCursor = wxGetStockCursor(kwxCursorSize); } break; -/* TODO: +/* TODO: case wxCURSOR_HAND: { M_CURSORDATA->m_themeCursor = kThemePointingHandCursor; @@ -430,35 +426,34 @@ void wxSetCursor(const wxCursor& cursor) static int wxBusyCursorCount = 0; // Set the cursor to the busy cursor for all windows -void wxBeginBusyCursor(wxCursor *cursor) +void wxBeginBusyCursor(const wxCursor *cursor) { - wxBusyCursorCount ++; - if (wxBusyCursorCount == 1) - { + wxBusyCursorCount ++; + if (wxBusyCursorCount == 1) + { // TODO - } - else - { + } + else + { // TODO - } + } } // Restore cursor to normal void wxEndBusyCursor() { - if (wxBusyCursorCount == 0) - return; - - wxBusyCursorCount --; - if (wxBusyCursorCount == 0) - { - // TODO - } + if (wxBusyCursorCount == 0) + return; + + wxBusyCursorCount --; + if (wxBusyCursorCount == 0) + { + // TODO + } } -// TRUE if we're between the above two calls +// true if we're between the above two calls bool wxIsBusy() { return (wxBusyCursorCount > 0); -} - +}