SystemInterface.cpp 4.0 KB

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