Browse Source

Activate/Deactivate keyboard in system interface

AndryBlack 14 years ago
parent
commit
7d67a4bd8d

+ 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;
 

+ 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;