SystemInterface.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. static WString clipboard_text;
  36. SystemInterface::SystemInterface() : ReferenceCountable(0)
  37. {
  38. }
  39. SystemInterface::~SystemInterface()
  40. {
  41. }
  42. #ifdef ROCKET_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. String message_user = CreateString(1024, "%s\nWould you like to interrupt execution?", message.c_str());
  49. // Return TRUE if the user presses NO (continue execution)
  50. return (IDNO == MessageBoxA(NULL, message_user.c_str(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
  51. }
  52. else
  53. {
  54. OutputDebugStringA(message.c_str());
  55. OutputDebugStringA("\r\n");
  56. }
  57. return true;
  58. }
  59. #else
  60. bool SystemInterface::LogMessage(Log::Type ROCKET_UNUSED_PARAMETER(logtype), const String& message)
  61. {
  62. ROCKET_UNUSED(logtype);
  63. fprintf(stderr,"%s\n", message.c_str());
  64. return true;
  65. }
  66. #endif
  67. void SystemInterface::SetMouseCursor(const String& cursor_name)
  68. {
  69. }
  70. void SystemInterface::SetClipboardText(const WString& text)
  71. {
  72. // The default implementation will only copy and paste within the application
  73. clipboard_text = text;
  74. }
  75. void SystemInterface::GetClipboardText(WString& text)
  76. {
  77. text = clipboard_text;
  78. }
  79. int SystemInterface::TranslateString(String& translated, const String& input)
  80. {
  81. translated = input;
  82. return 0;
  83. }
  84. // Joins the path of an RML or RCSS file with the path of a resource specified within the file.
  85. void SystemInterface::JoinPath(String& translated_path, const String& document_path, const String& path)
  86. {
  87. // If the path is absolute, strip the leading / and return it.
  88. if (path.size() > 0 && path[0] == '/')
  89. {
  90. translated_path = path.substr(1);
  91. return;
  92. }
  93. // If the path is a Windows-style absolute path, return it directly.
  94. size_t drive_pos = path.find(':');
  95. size_t slash_pos = Math::Min(path.find('/'), path.find('\\'));
  96. if (drive_pos != String::npos &&
  97. drive_pos < slash_pos)
  98. {
  99. translated_path = path;
  100. return;
  101. }
  102. // Strip off the referencing document name.
  103. translated_path = document_path;
  104. translated_path = Replace(translated_path, '\\', '/');
  105. size_t file_start = translated_path.rfind('/');
  106. if (file_start != String::npos)
  107. translated_path.resize(file_start + 1);
  108. else
  109. translated_path.clear();
  110. // Append the paths and send through URL to removing any '..'.
  111. URL url(Replace(translated_path, ':', '|') + Replace(path, '\\', '/'));
  112. translated_path = Replace(url.GetPathedFileName(), '|', ':');
  113. }
  114. // Activate keyboard (for touchscreen devices)
  115. void SystemInterface::ActivateKeyboard()
  116. {
  117. }
  118. // Deactivate keyboard (for touchscreen devices)
  119. void SystemInterface::DeactivateKeyboard()
  120. {
  121. }
  122. // Called when this system interface is released.
  123. void SystemInterface::Release()
  124. {
  125. }
  126. void SystemInterface::OnReferenceDeactivate()
  127. {
  128. Release();
  129. }
  130. }
  131. }