PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #include <AppKit/AppKit.h>
  31. #include "slplugin-objc.h"
  32. void setupCocoa()
  33. {
  34. static bool inited = false;
  35. if(!inited)
  36. {
  37. createAutoReleasePool();
  38. // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents.
  39. // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr'
  40. // when init'ing the Cocoa App window.
  41. [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
  42. // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
  43. // http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
  44. // Needed for Carbon based applications which call into Cocoa
  45. NSApplicationLoad();
  46. // 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
  47. [[[NSWindow alloc] init] release];
  48. deleteAutoReleasePool();
  49. inited = true;
  50. }
  51. }
  52. static NSAutoreleasePool *sPool = NULL;
  53. void createAutoReleasePool()
  54. {
  55. if(!sPool)
  56. {
  57. sPool = [[NSAutoreleasePool alloc] init];
  58. }
  59. }
  60. void deleteAutoReleasePool()
  61. {
  62. if(sPool)
  63. {
  64. [sPool release];
  65. sPool = NULL;
  66. }
  67. }