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 
28 #include "precompiled.h"
29 #include "../../Include/Rocket/Core/SystemInterface.h"
30 #include "../../Include/Rocket/Core/Log.h"
31 
32 #ifdef ROCKET_PLATFORM_WIN32
33 #include <windows.h>
34 #endif
35 
36 namespace Rocket {
37 namespace Core {
38 
SystemInterface()39 SystemInterface::SystemInterface() : ReferenceCountable(0)
40 {
41 }
42 
~SystemInterface()43 SystemInterface::~SystemInterface()
44 {
45 }
46 
47 #ifdef ROCKET_PLATFORM_WIN32
LogMessage(Log::Type logtype,const String & message)48 bool SystemInterface::LogMessage(Log::Type logtype, const String& message)
49 {
50 	// By default we just send a platform message
51 	if (logtype == Log::LT_ASSERT)
52 	{
53 		Core::String message(1024, "%s\nWould you like to interrupt execution?", message.CString());
54 
55 		// Return TRUE if the user presses NO (continue execution)
56 		return (IDNO == MessageBoxA(NULL, message.CString(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL));
57 	}
58 	else
59 	{
60 		OutputDebugStringA(message.CString());
61 		OutputDebugStringA("\r\n");
62 	}
63 	return true;
64 }
65 #else
LogMessage(Log::Type ROCKET_UNUSED_PARAMETER (logtype),const String & message)66 bool SystemInterface::LogMessage(Log::Type ROCKET_UNUSED_PARAMETER(logtype), const String& message)
67 {
68 	ROCKET_UNUSED(logtype);
69 
70 	fprintf(stderr,"%s\n", message.CString());
71 	return true;
72 }
73 #endif
74 
TranslateString(String & translated,const String & input)75 int SystemInterface::TranslateString(String& translated, const String& input)
76 {
77 	translated = input;
78 	return 0;
79 }
80 
81 // Joins the path of an RML or RCSS file with the path of a resource specified within the file.
JoinPath(String & translated_path,const String & document_path,const String & path)82 void SystemInterface::JoinPath(String& translated_path, const String& document_path, const String& path)
83 {
84 	// If the path is absolute, strip the leading / and return it.
85 	if (path.Substring(0, 1) == "/")
86 	{
87 		translated_path = path.Substring(1);
88 		return;
89 	}
90 
91 	// If the path is a Windows-style absolute path, return it directly.
92 	size_t drive_pos = path.Find(":");
93 	size_t slash_pos = Math::Min(path.Find("/"), path.Find("\\"));
94 	if (drive_pos != String::npos &&
95 		drive_pos < slash_pos)
96 	{
97 		translated_path = path;
98 		return;
99 	}
100 
101 	// Strip off the referencing document name.
102 	translated_path = document_path;
103 	translated_path = translated_path.Replace("\\", "/");
104 	size_t file_start = translated_path.RFind("/");
105 	if (file_start != String::npos)
106 		translated_path.Resize(file_start + 1);
107 	else
108 		translated_path.Clear();
109 
110 	// Append the paths and send through URL to removing any '..'.
111 	URL url(translated_path.Replace(":", "|") + path.Replace("\\", "/"));
112 	translated_path = url.GetPathedFileName().Replace("|", ":");
113 }
114 
115 // Activate keyboard (for touchscreen devices)
ActivateKeyboard()116 void SystemInterface::ActivateKeyboard()
117 {
118 }
119 
120 // Deactivate keyboard (for touchscreen devices)
DeactivateKeyboard()121 void SystemInterface::DeactivateKeyboard()
122 {
123 }
124 
125 // Called when this system interface is released.
Release()126 void SystemInterface::Release()
127 {
128 }
129 
OnReferenceDeactivate()130 void SystemInterface::OnReferenceDeactivate()
131 {
132 	Release();
133 }
134 
135 }
136 }
137