llwindowmacosx-objc.mm

Go to the documentation of this file.
00001 
00033 #include <AppKit/AppKit.h>
00034 
00035 /*
00036  * These functions are broken out into a separate file because the
00037  * objective-C typedef for 'BOOL' conflicts with the one in
00038  * llcommon/stdtypes.h.  This makes it impossible to use the standard
00039  * linden headers with any objective-C++ source.
00040  */
00041 
00042 #include "llwindowmacosx-objc.h"
00043 
00044 void setupCocoa()
00045 {
00046         static bool inited = false;
00047         
00048         if(!inited)
00049         {
00050                 // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
00051                 //   http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
00052                 
00053                 //      Needed for Carbon based applications which call into Cocoa
00054                 NSApplicationLoad();
00055 
00056                 //      Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image
00057                 [[[NSWindow alloc] init] release];
00058         }
00059 }
00060 
00061 CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
00062 {
00063         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00064 
00065         // extra retain on the NSCursor since we want it to live for the lifetime of the app.
00066         NSCursor *cursor =
00067                 [[[NSCursor alloc] 
00068                                 initWithImage:
00069                                         [[[NSImage alloc] initWithContentsOfFile:
00070                                                 [NSString stringWithFormat:@"%s", fullpath]
00071                                         ]autorelease] 
00072                                 hotSpot:NSMakePoint(hotspotX, hotspotY)
00073                 ]retain];       
00074                 
00075         [pool release];
00076         
00077         return (CursorRef)cursor;
00078 }
00079 
00080 // This is currently unused, since we want all our cursors to persist for the life of the app, but I've included it for completeness.
00081 OSErr releaseImageCursor(CursorRef ref)
00082 {
00083         if( ref != NULL )
00084         {
00085                 NSCursor *cursor = (NSCursor*)ref;
00086                 [cursor release];
00087         }
00088         else
00089         {
00090                 return paramErr;
00091         }
00092         
00093         return noErr;
00094 }
00095 
00096 OSErr setImageCursor(CursorRef ref)
00097 {
00098         if( ref != NULL )
00099         {
00100                 NSCursor *cursor = (NSCursor*)ref;
00101                 [cursor set];
00102         }
00103         else
00104         {
00105                 return paramErr;
00106         }
00107         
00108         return noErr;
00109 }
00110 

Generated on Thu Jul 1 06:09:46 2010 for Second Life Viewer by  doxygen 1.4.7