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                 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00051                 
00052                 // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
00053                 //   http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
00054                 
00055                 //      Needed for Carbon based applications which call into Cocoa
00056                 NSApplicationLoad();
00057 
00058                 //      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
00059                 [[[NSWindow alloc] init] release];
00060 
00061                 [pool release];
00062         }
00063 }
00064 
00065 CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
00066 {
00067         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00068 
00069         // extra retain on the NSCursor since we want it to live for the lifetime of the app.
00070         NSCursor *cursor =
00071                 [[[NSCursor alloc] 
00072                                 initWithImage:
00073                                         [[[NSImage alloc] initWithContentsOfFile:
00074                                                 [NSString stringWithFormat:@"%s", fullpath]
00075                                         ]autorelease] 
00076                                 hotSpot:NSMakePoint(hotspotX, hotspotY)
00077                 ]retain];       
00078                 
00079         [pool release];
00080         
00081         return (CursorRef)cursor;
00082 }
00083 
00084 // 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.
00085 OSErr releaseImageCursor(CursorRef ref)
00086 {
00087         if( ref != NULL )
00088         {
00089                 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00090                 NSCursor *cursor = (NSCursor*)ref;
00091                 [cursor release];
00092                 [pool release];
00093         }
00094         else
00095         {
00096                 return paramErr;
00097         }
00098         
00099         return noErr;
00100 }
00101 
00102 OSErr setImageCursor(CursorRef ref)
00103 {
00104         if( ref != NULL )
00105         {
00106                 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00107                 NSCursor *cursor = (NSCursor*)ref;
00108                 [cursor set];
00109                 [pool release];
00110         }
00111         else
00112         {
00113                 return paramErr;
00114         }
00115         
00116         return noErr;
00117 }
00118 

Generated on Fri May 16 08:33:03 2008 for SecondLife by  doxygen 1.5.5