PageRenderTime 19ms CodeModel.GetById 9ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include <AppKit/AppKit.h>
  28. /*
  29. * These functions are broken out into a separate file because the
  30. * objective-C typedef for 'BOOL' conflicts with the one in
  31. * llcommon/stdtypes.h. This makes it impossible to use the standard
  32. * linden headers with any objective-C++ source.
  33. */
  34. #include "llwindowmacosx-objc.h"
  35. void setupCocoa()
  36. {
  37. static bool inited = false;
  38. if(!inited)
  39. {
  40. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  41. // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents.
  42. // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr'
  43. // when init'ing the Cocoa App window.
  44. [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
  45. // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
  46. // http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
  47. // Needed for Carbon based applications which call into Cocoa
  48. NSApplicationLoad();
  49. // 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
  50. [[[NSWindow alloc] init] release];
  51. [pool release];
  52. inited = true;
  53. }
  54. }
  55. CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
  56. {
  57. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  58. // extra retain on the NSCursor since we want it to live for the lifetime of the app.
  59. NSCursor *cursor =
  60. [[[NSCursor alloc]
  61. initWithImage:
  62. [[[NSImage alloc] initWithContentsOfFile:
  63. [NSString stringWithFormat:@"%s", fullpath]
  64. ]autorelease]
  65. hotSpot:NSMakePoint(hotspotX, hotspotY)
  66. ]retain];
  67. [pool release];
  68. return (CursorRef)cursor;
  69. }
  70. // 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.
  71. OSErr releaseImageCursor(CursorRef ref)
  72. {
  73. if( ref != NULL )
  74. {
  75. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  76. NSCursor *cursor = (NSCursor*)ref;
  77. [cursor release];
  78. [pool release];
  79. }
  80. else
  81. {
  82. return paramErr;
  83. }
  84. return noErr;
  85. }
  86. OSErr setImageCursor(CursorRef ref)
  87. {
  88. if( ref != NULL )
  89. {
  90. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  91. NSCursor *cursor = (NSCursor*)ref;
  92. [cursor set];
  93. [pool release];
  94. }
  95. else
  96. {
  97. return paramErr;
  98. }
  99. return noErr;
  100. }