Browse Source

Feature: single-line text input controls now also dispatch boolean "linebreak" attribute with "change" events.

We can't listen to "keydown" events on text widgets since they are inhibited by input elements themselves. To properly detect changes caused by linebreak key (ENTER) presses, dispatch "linebreak" attribute with "change" events.
Victor Luchitz 13 years ago
parent
commit
e2ae51a2e7

+ 2 - 1
Source/Controls/WidgetTextInput.cpp

@@ -234,10 +234,11 @@ Core::Element* WidgetTextInput::GetElement()
 }
 
 // Dispatches a change event to the widget's element.
-void WidgetTextInput::DispatchChangeEvent()
+void WidgetTextInput::DispatchChangeEvent(bool linebreak)
 {
 	Rocket::Core::Dictionary parameters;
 	parameters.Set("value", GetElement()->GetAttribute< Rocket::Core::String >("value", ""));
+	parameters.Set("linebreak", linebreak);
 	GetElement()->DispatchEvent("change", parameters);
 }
 

+ 1 - 1
Source/Controls/WidgetTextInput.h

@@ -109,7 +109,7 @@ protected:
 	Core::Element* GetElement();
 
 	/// Dispatches a change event to the widget's element.
-	void DispatchChangeEvent();
+	void DispatchChangeEvent(bool linebreak = false);
 
 private:
 	/// Moves the cursor along the current line.

+ 1 - 1
Source/Controls/WidgetTextInputSingleLine.cpp

@@ -58,7 +58,7 @@ bool WidgetTextInputSingleLine::IsCharacterValid(Rocket::Core::word character)
 // Called when the user pressed enter.
 void WidgetTextInputSingleLine::LineBreak()
 {
-	DispatchChangeEvent();
+	DispatchChangeEvent(true);
 }
 
 // Strips all \n and \r characters from the string.