Browse Source

Merge pull request #17 from andryblack/master

Several changes to simplify integration for mobile devices
Lloyd Weehuizen 14 years ago
parent
commit
1277539c8f

+ 6 - 0
Include/Rocket/Core/SystemInterface.h

@@ -79,6 +79,12 @@ public:
 	/// @return True to continue execution, false to break into the debugger.
 	virtual bool LogMessage(Log::Type type, const String& message);
 
+	/// Activate keyboard (for touchscreen devices)
+	virtual void ActivateKeyboard();
+	
+	/// Deactivate keyboard (for touchscreen devices)
+	virtual void DeactivateKeyboard();
+	
 	/// Called when this system interface is no longer required.
 	virtual void Release();
 

+ 25 - 0
Source/Controls/WidgetTextInput.cpp

@@ -30,6 +30,7 @@
 #include <Rocket/Core.h>
 #include <Rocket/Controls/ElementFormControl.h>
 #include <Rocket/Controls/Clipboard.h>
+#include <Rocket/Core/SystemInterface.h>
 
 namespace Rocket {
 namespace Controls {
@@ -38,6 +39,8 @@ const float CURSOR_BLINK_TIME = 0.7f;
 
 WidgetTextInput::WidgetTextInput(ElementFormControl* _parent) : internal_dimensions(0, 0), scroll_offset(0, 0), cursor_position(0, 0), cursor_size(0, 0), cursor_geometry(_parent), selection_geometry(_parent)
 {
+	keyboard_showed = false;
+	
 	parent = _parent;
 	parent->SetProperty("white-space", "pre");
 	parent->SetProperty("overflow", "hidden");
@@ -629,6 +632,9 @@ void WidgetTextInput::ShowCursor(bool show, bool move_to_cursor)
 	if (show)
 	{
 		cursor_visible = true;
+		SetKeyboardActive(true);
+		keyboard_showed = true;
+		
 		cursor_timer = CURSOR_BLINK_TIME;
 		last_update_time = Core::GetSystemInterface()->GetElapsedTime();
 
@@ -656,6 +662,11 @@ void WidgetTextInput::ShowCursor(bool show, bool move_to_cursor)
 		cursor_visible = false;
 		cursor_timer = -1;
 		last_update_time = 0;
+		if (keyboard_showed)
+		{
+			SetKeyboardActive(false);
+			keyboard_showed = false;
+		}
 	}
 }
 
@@ -958,5 +969,19 @@ void WidgetTextInput::GetLineSelection(Core::WString& pre_selection, Core::WStri
 	post_selection = line.Substring(selection_begin_index + selection_length - line_begin);
 }
 
+void WidgetTextInput::SetKeyboardActive(bool active)
+{
+	Core::SystemInterface* system = Core::GetSystemInterface();
+	if (system) {
+		if (active) 
+		{
+			system->ActivateKeyboard();
+		} else 
+		{
+			system->DeactivateKeyboard();
+		}
+	}
+}
+	
 }
 }

+ 4 - 0
Source/Controls/WidgetTextInput.h

@@ -214,6 +214,10 @@ private:
 	// Cursor visibility and timings.
 	float cursor_timer;
 	bool cursor_visible;
+	bool keyboard_showed;
+	/// Activate or deactivate keyboard (for touchscreen devices)
+	/// @param[in] active True if need activate keyboard, false if need deactivate.
+	void SetKeyboardActive(bool active);
 
 	float last_update_time;
 

+ 7 - 1
Source/Core/Core.cpp

@@ -44,8 +44,9 @@ static RenderInterface* render_interface = NULL;
 static SystemInterface* system_interface = NULL;
 // Rocket's file I/O interface.
 FileInterface* file_interface =  NULL;
+#ifndef ROCKET_NO_FILE_INTERFACE_DEFAULT
 static FileInterfaceDefault file_interface_default;
-
+#endif
 static bool initialised = false;
 
 typedef std::map< String, Context* > ContextMap;
@@ -84,8 +85,13 @@ bool Initialise()
 
 	if (file_interface == NULL)
 	{		
+#ifndef ROCKET_NO_FILE_INTERFACE_DEFAULT
 		file_interface = &file_interface_default;
 		file_interface->AddReference();
+#else
+		Log::Message(Log::LT_ERROR, "No file interface set!");
+		return false;
+#endif
 	}
 
 	Log::Initialise();

+ 4 - 0
Source/Core/FileInterfaceDefault.cpp

@@ -28,6 +28,8 @@
 #include "precompiled.h"
 #include "FileInterfaceDefault.h"
 
+#ifndef ROCKET_NO_FILE_INTERFACE_DEFAULT
+
 namespace Rocket {
 namespace Core {
 
@@ -67,3 +69,5 @@ size_t FileInterfaceDefault::Tell(FileHandle file)
 
 }
 }
+
+#endif /*ROCKET_NO_FILE_INTERFACE_DEFAULT*/

+ 4 - 0
Source/Core/FileInterfaceDefault.h

@@ -30,6 +30,8 @@
 
 #include <Rocket/Core/FileInterface.h>
 
+#ifndef ROCKET_NO_FILE_INTERFACE_DEFAULT
+
 namespace Rocket {
 namespace Core {
 
@@ -73,4 +75,6 @@ public:
 }
 }
 
+#endif /*ROCKET_NO_FILE_INTERFACE_DEFAULT*/
+
 #endif

+ 10 - 0
Source/Core/SystemInterface.cpp

@@ -106,6 +106,16 @@ void SystemInterface::JoinPath(String& translated_path, const String& document_p
 	URL url(translated_path.Replace(":", "|") + path.Replace("\\", "/"));
 	translated_path = url.GetPathedFileName().Replace("|", ":");
 }
+	
+// Activate keyboard (for touchscreen devices)
+void SystemInterface::ActivateKeyboard() 
+{
+}
+	
+// Deactivate keyboard (for touchscreen devices)
+void SystemInterface::DeactivateKeyboard() 
+{
+}
 
 // Called when this system interface is released.
 void SystemInterface::Release()

+ 12 - 0
Source/Debugger/SystemInterface.cpp

@@ -63,6 +63,18 @@ bool SystemInterface::LogMessage(Core::Log::Type type, const Core::String& messa
 
 	return application_interface->LogMessage(type, message);
 }
+	
+// Activate keyboard (for touchscreen devices)
+void SystemInterface::ActivateKeyboard()
+{
+	application_interface->ActivateKeyboard();
+}
+	
+// Deactivate keyboard (for touchscreen devices)
+void SystemInterface::DeactivateKeyboard()
+{
+	application_interface->DeactivateKeyboard();
+}
 
 }
 }

+ 5 - 0
Source/Debugger/SystemInterface.h

@@ -66,6 +66,11 @@ public:
 	/// @return True to continue execution, false to break into the debugger.
 	virtual bool LogMessage(Core::Log::Type type, const Core::String& message);
 
+	/// Activate keyboard (for touchscreen devices)
+	virtual void ActivateKeyboard();
+	
+	/// Deactivate keyboard (for touchscreen devices)
+	virtual void DeactivateKeyboard();
 private:
 	Core::SystemInterface* application_interface;
 	ElementLog* log;