PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llwindow/llwindowmacosx-objc.mm

https://bitbucket.org/lindenlab/viewer-beta/
Objective C++ | 120 lines | 59 code | 20 blank | 41 comment | 5 complexity | 5aec47cd0837b0dcccb8ec5d2a61c142 MD5 | raw file
  1/** 
  2 * @file llwindowmacosx-objc.mm
  3 * @brief Definition of functions shared between llwindowmacosx.cpp
  4 * and llwindowmacosx-objc.mm.
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include <AppKit/AppKit.h>
 29
 30/*
 31 * These functions are broken out into a separate file because the
 32 * objective-C typedef for 'BOOL' conflicts with the one in
 33 * llcommon/stdtypes.h.  This makes it impossible to use the standard
 34 * linden headers with any objective-C++ source.
 35 */
 36
 37#include "llwindowmacosx-objc.h"
 38
 39void setupCocoa()
 40{
 41	static bool inited = false;
 42	
 43	if(!inited)
 44	{
 45		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 46		
 47		// The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents.
 48		// ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' 
 49		// when init'ing the Cocoa App window.		
 50		[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
 51		
 52		// This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
 53		//   http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
 54		
 55		//	Needed for Carbon based applications which call into Cocoa
 56		NSApplicationLoad();
 57
 58		//	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
 59		[[[NSWindow alloc] init] release];
 60
 61		[pool release];
 62		
 63		inited = true;
 64	}
 65}
 66
 67CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
 68{
 69	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 70
 71	// extra retain on the NSCursor since we want it to live for the lifetime of the app.
 72	NSCursor *cursor =
 73		[[[NSCursor alloc] 
 74				initWithImage:
 75					[[[NSImage alloc] initWithContentsOfFile:
 76						[NSString stringWithFormat:@"%s", fullpath]
 77					]autorelease] 
 78				hotSpot:NSMakePoint(hotspotX, hotspotY)
 79		]retain];	
 80		
 81	[pool release];
 82	
 83	return (CursorRef)cursor;
 84}
 85
 86// 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.
 87OSErr releaseImageCursor(CursorRef ref)
 88{
 89	if( ref != NULL )
 90	{
 91		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 92		NSCursor *cursor = (NSCursor*)ref;
 93		[cursor release];
 94		[pool release];
 95	}
 96	else
 97	{
 98		return paramErr;
 99	}
100	
101	return noErr;
102}
103
104OSErr setImageCursor(CursorRef ref)
105{
106	if( ref != NULL )
107	{
108		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
109		NSCursor *cursor = (NSCursor*)ref;
110		[cursor set];
111		[pool release];
112	}
113	else
114	{
115		return paramErr;
116	}
117	
118	return noErr;
119}
120