SystemInterface.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "../../Include/Rocket/Core/SystemInterface.h"
  29. #include "../../Include/Rocket/Core/Log.h"
  30. #ifdef ROCKET_PLATFORM_WIN32
  31. #include <windows.h>
  32. #endif
  33. namespace Rocket {
  34. namespace Core {
  35. SystemInterface::SystemInterface() : ReferenceCountable(0)
  36. {
  37. }
  38. SystemInterface::~SystemInterface()
  39. {
  40. }
  41. #ifdef ROCKET_PLATFORM_WIN32
  42. bool SystemInterface::LogMessage(Log::Type logtype, const String& message)
  43. {
  44. // By default we just send a platform message
  45. if (logtype == Log::LT_ASSERT)
  46. {
  47. Core::String message(1024, "%s\nWould you like to interrupt execution?", message.CString());
  48. // Return TRUE if the user presses NO (continue execution)
  49. return (IDNO == MessageBoxA(NULL, message.CString(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
  50. }
  51. else
  52. {
  53. OutputDebugStringA(message.CString());
  54. OutputDebugStringA("\r\n");
  55. }
  56. return true;
  57. }
  58. #else
  59. bool SystemInterface::LogMessage(Log::Type ROCKET_UNUSED_PARAMETER(logtype), const String& message)
  60. {
  61. ROCKET_UNUSED(logtype);
  62. fprintf(stderr,"%s\n", message.CString());
  63. return true;
  64. }
  65. #endif
  66. void SystemInterface::SetMouseCursor(const String& cursor_name)
  67. {
  68. }
  69. int SystemInterface::TranslateString(String& translated, const String& input)
  70. {
  71. translated = input;
  72. return 0;
  73. }
  74. // Joins the path of an RML or RCSS file with the path of a resource specified within the file.
  75. void SystemInterface::JoinPath(String& translated_path, const String& document_path, const String& path)
  76. {
  77. // If the path is absolute, strip the leading / and return it.
  78. if (path.Substring(0, 1) == "/")
  79. {
  80. translated_path = path.Substring(1);
  81. return;
  82. }
  83. // If the path is a Windows-style absolute path, return it directly.
  84. size_t drive_pos = path.Find(":");
  85. size_t slash_pos = Math::Min(path.Find("/"), path.Find("\\"));
  86. if (drive_pos != String::npos &&
  87. drive_pos < slash_pos)
  88. {
  89. translated_path = path;
  90. return;
  91. }
  92. // Strip off the referencing document name.
  93. translated_path = document_path;
  94. translated_path = translated_path.Replace("\\", "/");
  95. size_t file_start = translated_path.RFind("/");
  96. if (file_start != String::npos)
  97. translated_path.Resize(file_start + 1);
  98. else
  99. translated_path.Clear();
  100. // Append the paths and send through URL to removing any '..'.
  101. URL url(translated_path.Replace(":", "|") + path.Replace("\\", "/"));
  102. translated_path = url.GetPathedFileName().Replace("|", ":");
  103. }
  104. // Activate keyboard (for touchscreen devices)
  105. void SystemInterface::ActivateKeyboard()
  106. {
  107. }
  108. // Deactivate keyboard (for touchscreen devices)
  109. void SystemInterface::DeactivateKeyboard()
  110. {
  111. }
  112. // Called when this system interface is released.
  113. void SystemInterface::Release()
  114. {
  115. }
  116. void SystemInterface::OnReferenceDeactivate()
  117. {
  118. Release();
  119. }
  120. }
  121. }