PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 1ms RepoModel.GetById 120ms app.codeStats 0ms

/indra/llplugin/slplugin/slplugin-objc.mm

https://bitbucket.org/lindenlab/viewer-beta/
Objective C++ | 82 lines | 31 code | 15 blank | 36 comment | 3 complexity | cce8f2b74b6f2890e464da151ae621e2 MD5 | raw file
 1/**
 2 * @file slplugin-objc.mm
 3 * @brief Objective-C++ file for use with the loader shell, so we can use a couple of Cocoa APIs.
 4 *
 5 * @cond
 6 *
 7 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 8 * Second Life Viewer Source Code
 9 * Copyright (C) 2010, Linden Research, Inc.
10 * 
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License only.
15 * 
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 * 
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 * 
25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
26 * $/LicenseInfo$
27 *
28 * @endcond
29 */
30
31
32#include <AppKit/AppKit.h>
33
34#include "slplugin-objc.h"
35
36
37void setupCocoa()
38{
39	static bool inited = false;
40	
41	if(!inited)
42	{
43		createAutoReleasePool();
44		
45		// The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents.
46		// ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' 
47		// when init'ing the Cocoa App window.		
48		[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
49		
50		// This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
51		//   http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
52		
53		//	Needed for Carbon based applications which call into Cocoa
54		NSApplicationLoad();
55
56		//	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
57		[[[NSWindow alloc] init] release];
58		
59		deleteAutoReleasePool();
60		
61		inited = true;
62	}
63}
64
65static NSAutoreleasePool *sPool = NULL;
66
67void createAutoReleasePool()
68{
69	if(!sPool)
70	{
71		sPool = [[NSAutoreleasePool alloc] init];
72	}
73}
74
75void deleteAutoReleasePool()
76{
77	if(sPool)
78	{
79		[sPool release];
80		sPool = NULL;
81	}
82}