Util_SystemGUI_OSX.mm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /************************************************************************************
  2. Filename : Util_SystemGUI.mm
  3. Content : OS GUI access, usually for diagnostics.
  4. Created : October 20, 2014
  5. Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
  6. Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
  7. you may not use the Oculus VR Rift SDK except in compliance with the License,
  8. which is provided at the time of installation or download, or which
  9. otherwise accompanies this software in either electronic or hard copy form.
  10. You may obtain a copy of the License at
  11. http://www.oculusvr.com/licenses/LICENSE-3.2
  12. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. *************************************************************************************/
  18. #include "Util_SystemGUI.h"
  19. #include <Cocoa/Cocoa.h>
  20. #include <CoreFoundation/CoreFoundation.h>
  21. namespace OVR { namespace Util {
  22. bool DisplayMessageBox(const char* pTitle, const char* pText)
  23. {
  24. // To consider: Replace usage of CFUserNotificationDisplayAlert with something a little smarter.
  25. size_t titleLength = strlen(pTitle);
  26. size_t textLength = strlen(pText);
  27. if(textLength > 1500) // CFUserNotificationDisplayAlert isn't smart enough to handle large text sizes and screws up its size if so.
  28. textLength = 1500; // Problem: this can theoretically split a UTF8 multibyte sequence. Need to find a divisible boundary.
  29. CFAllocatorRef allocator = NULL; // To do: support alternative allocator.
  30. CFStringRef titleRef = CFStringCreateWithBytes(allocator, (const UInt8*)pTitle, (CFIndex)titleLength, kCFStringEncodingUTF8, false);
  31. CFStringRef textRef = CFStringCreateWithBytes(allocator, (const UInt8*)pText, (CFIndex)textLength, kCFStringEncodingUTF8, false);
  32. CFOptionFlags result;
  33. CFUserNotificationDisplayAlert(0, // No timeout
  34. kCFUserNotificationNoteAlertLevel,
  35. NULL, // Icon URL, use default.
  36. NULL, // Unused
  37. NULL, // Localization of strings
  38. titleRef, // Title text
  39. textRef, // Body text
  40. CFSTR("OK"), // Default "OK" text in button
  41. CFSTR("Cancel"), // Other button title
  42. NULL, // Yet another button title, NULL means no other button.
  43. &result); // response flags
  44. CFRelease(titleRef);
  45. CFRelease(textRef);
  46. return (result == kCFUserNotificationDefaultResponse);
  47. }
  48. } } // namespace OVR { namespace Util {