Add SelectionCleared signal
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
index a806c70..5e6d740 100644 (file)
@@ -147,6 +147,7 @@ DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked",         SIGNAL_ANC
 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered",         SIGNAL_INPUT_FILTERED         )
 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged",      SIGNAL_SELECTION_CHANGED      )
+DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared",      SIGNAL_SELECTION_CLEARED      )
 
 DALI_TYPE_REGISTRATION_END()
 // clang-format on
@@ -1272,6 +1273,14 @@ bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface*
       fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
     }
   }
+  else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
+  {
+    if(field)
+    {
+      Internal::TextField& fieldImpl(GetImpl(field));
+      fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
+    }
+  }
   else
   {
     // signalName does not match any signal
@@ -1316,6 +1325,11 @@ DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
   return mSelectionChangedSignal;
 }
 
+DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
+{
+  return mSelectionClearedSignal;
+}
+
 void TextField::OnInitialize()
 {
   Actor self = Self();
@@ -1522,6 +1536,11 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
     EmitSelectionChangedSignal();
   }
 
+  if(mSelectionCleared)
+  {
+    EmitSelectionClearedSignal();
+  }
+
   // The text-field emits signals when the input style changes. These changes of style are
   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
   // can't be emitted during the size negotiation as the callbacks may update the UI.
@@ -1918,10 +1937,22 @@ void TextField::EmitSelectionChangedSignal()
   mSelectionChanged = false;
 }
 
+void TextField::EmitSelectionClearedSignal()
+{
+  Dali::Toolkit::TextField handle(GetOwner());
+  mSelectionClearedSignal.Emit(handle);
+  mSelectionCleared = false;
+}
+
 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
 {
   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
   {
+    if(newStart == newEnd)
+    {
+      mSelectionCleared = true;
+    }
+
     mSelectionChanged  = true;
     mOldSelectionStart = oldStart;
     mOldSelectionEnd   = oldEnd;
@@ -2074,7 +2105,8 @@ TextField::TextField()
   mHasBeenStaged(false),
   mTextChanged(false),
   mCursorPositionChanged(false),
-  mSelectionChanged(false)
+  mSelectionChanged(false),
+  mSelectionCleared(false)
 {
 }