TextInput Emit signal when text is modified.
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 20 May 2014 20:37:10 +0000 (21:37 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 27 May 2014 14:39:09 +0000 (15:39 +0100)
TextInput emits signal when text is modified, developer can query number of characters on
receiving this signal and behaviour accordingly.

Change-Id: Ie4794493ec3d724e522475bc53ae43a5dbea8697

base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp
base/dali-toolkit/internal/controls/text-input/text-input-impl.h
base/dali-toolkit/public-api/controls/text-input/text-input.cpp
capi/dali-toolkit/public-api/controls/text-input/text-input.h

index e9de775..24710e7 100644 (file)
@@ -443,6 +443,8 @@ void TextInput::SetText(const std::string& initialText)
   RemoveHighlight();
 
   DrawCursor();
   RemoveHighlight();
 
   DrawCursor();
+
+  EmitTextModified();
 }
 
 void TextInput::SetText( const MarkupProcessor::StyledTextArray& styleText )
 }
 
 void TextInput::SetText( const MarkupProcessor::StyledTextArray& styleText )
@@ -488,6 +490,8 @@ void TextInput::SetText( const MarkupProcessor::StyledTextArray& styleText )
                                              Toolkit::Alignment::VerticalTop ) );
     mDisplayedTextView.SetLineJustification( leftToRight ? Toolkit::TextView::Left : Toolkit::TextView::Right);
   }
                                              Toolkit::Alignment::VerticalTop ) );
     mDisplayedTextView.SetLineJustification( leftToRight ? Toolkit::TextView::Left : Toolkit::TextView::Right);
   }
+
+  EmitTextModified();
 }
 
 void TextInput::SetMaxCharacterLength(std::size_t maxChars)
 }
 
 void TextInput::SetMaxCharacterLength(std::size_t maxChars)
@@ -535,6 +539,11 @@ Toolkit::TextInput::StyleChangedSignalV2& TextInput::StyleChangedSignal()
   return mStyleChangedSignalV2;
 }
 
   return mStyleChangedSignalV2;
 }
 
+Toolkit::TextInput::TextModifiedSignalType& TextInput::TextModifiedSignal()
+{
+  return mTextModifiedSignal;
+}
+
 Toolkit::TextInput::MaxInputCharactersReachedSignalV2& TextInput::MaxInputCharactersReachedSignal()
 {
   return mMaxInputCharactersReachedSignalV2;
 Toolkit::TextInput::MaxInputCharactersReachedSignalV2& TextInput::MaxInputCharactersReachedSignal()
 {
   return mMaxInputCharactersReachedSignalV2;
@@ -1044,6 +1053,7 @@ void TextInput::OnKeyInputFocusLost()
     RemovePreEditStyle();
     const std::size_t numberOfCharactersDeleted = DeletePreEdit();
     InsertAt( mPreEditString, mPreEditStartPosition, numberOfCharactersDeleted );
     RemovePreEditStyle();
     const std::size_t numberOfCharactersDeleted = DeletePreEdit();
     InsertAt( mPreEditString, mPreEditStartPosition, numberOfCharactersDeleted );
+    EmitTextModified();
   }
 
   ImfManager imfManager = ImfManager::Get();
   }
 
   ImfManager imfManager = ImfManager::Get();
@@ -1622,7 +1632,6 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button )
 
     ShowGrabHandleAndSetVisibility( false );
 
 
     ShowGrabHandleAndSetVisibility( false );
 
-
     HidePopup();
   }
   else if(name == OPTION_CLIPBOARD)
     HidePopup();
   }
   else if(name == OPTION_CLIPBOARD)
@@ -1784,6 +1793,7 @@ bool TextInput::OnKeyDownEvent(const KeyEvent& event)
       // Received key String
       mCursorPosition = mCursorPosition + InsertAt( Text( keyString ), mCursorPosition, 0 );
       update = true;
       // Received key String
       mCursorPosition = mCursorPosition + InsertAt( Text( keyString ), mCursorPosition, 0 );
       update = true;
+      EmitTextModified();
     }
   }
 
     }
   }
 
@@ -2234,6 +2244,8 @@ ImfManager::ImfCallbackData TextInput::ImfEventReceived( Dali::ImfManager& imfMa
       mCursorPosition = toDelete;
       mNumberOfSurroundingCharactersDeleted = numberOfCharacters;
 
       mCursorPosition = toDelete;
       mNumberOfSurroundingCharactersDeleted = numberOfCharacters;
 
+      EmitTextModified();
+
       DALI_LOG_INFO( gLogFilter, Debug::General, "ImfEventReceived - deleteSurrounding post-delete range mCursorPosition[%u] \n", mCursorPosition);
       break;
     }
       DALI_LOG_INFO( gLogFilter, Debug::General, "ImfEventReceived - deleteSurrounding post-delete range mCursorPosition[%u] \n", mCursorPosition);
       break;
     }
@@ -2325,6 +2337,7 @@ bool TextInput::PreEditReceived(const std::string& keyString, std::size_t cursor
           mDisplayedTextView.RemoveTextFrom( mPreEditStartPosition, numberOfCharactersToReplace );
         }
         GetTextLayoutInfo();
           mDisplayedTextView.RemoveTextFrom( mPreEditStartPosition, numberOfCharactersToReplace );
         }
         GetTextLayoutInfo();
+        EmitTextModified();
       }
       else
       {
       }
       else
       {
@@ -2334,6 +2347,7 @@ bool TextInput::PreEditReceived(const std::string& keyString, std::size_t cursor
         mCursorPosition = mPreEditStartPosition + std::min( cursorOffset, mPreEditLength );
         ApplyPreEditStyle( mPreEditStartPosition, mPreEditLength );
         DALI_LOG_INFO(gLogFilter, Debug::General, "PreEditReceived mCursorPosition[%u] \n", mCursorPosition);
         mCursorPosition = mPreEditStartPosition + std::min( cursorOffset, mPreEditLength );
         ApplyPreEditStyle( mPreEditStartPosition, mPreEditLength );
         DALI_LOG_INFO(gLogFilter, Debug::General, "PreEditReceived mCursorPosition[%u] \n", mCursorPosition);
+        EmitTextModified();
       }
       // cursor update to keyboard is not done here as the keyboard knows the cursor position and provides the 'cursorOffset'.
       DrawCursor();
       }
       // cursor update to keyboard is not done here as the keyboard knows the cursor position and provides the 'cursorOffset'.
       DrawCursor();
@@ -2353,9 +2367,9 @@ bool TextInput::PreEditReceived(const std::string& keyString, std::size_t cursor
       mCursorPosition = mPreEditStartPosition + std::min( cursorOffset, mPreEditLength );
       ApplyPreEditStyle( mPreEditStartPosition, mPreEditLength );
       DALI_LOG_INFO(gLogFilter, Debug::General, "PreEditReceived mCursorPosition[%u] mPreEditStartPosition[%u]\n", mCursorPosition, mPreEditStartPosition);
       mCursorPosition = mPreEditStartPosition + std::min( cursorOffset, mPreEditLength );
       ApplyPreEditStyle( mPreEditStartPosition, mPreEditLength );
       DALI_LOG_INFO(gLogFilter, Debug::General, "PreEditReceived mCursorPosition[%u] mPreEditStartPosition[%u]\n", mCursorPosition, mPreEditStartPosition);
-
       // cursor update to keyboard is not done here as the keyboard knows the cursor position and provides the 'cursorOffset'.
       DrawCursor();
       // cursor update to keyboard is not done here as the keyboard knows the cursor position and provides the 'cursorOffset'.
       DrawCursor();
+      EmitTextModified();
     }
     else
     {
     }
     else
     {
@@ -2416,6 +2430,8 @@ bool TextInput::CommitReceived(const std::string& keyString )
         }
       }
 
         }
       }
 
+      EmitTextModified();
+
       if ( mSelectTextOnCommit )
       {
         SelectText(mRequestedSelection.mStartOfSelection, mRequestedSelection.mEndOfSelection );
       if ( mSelectTextOnCommit )
       {
         SelectText(mRequestedSelection.mStartOfSelection, mRequestedSelection.mEndOfSelection );
@@ -2437,6 +2453,7 @@ bool TextInput::CommitReceived(const std::string& keyString )
         mCursorPosition = mCursorPosition + InsertAt( Text( keyString ), mCursorPosition, mNumberOfSurroundingCharactersDeleted );
         update = true;
         mNumberOfSurroundingCharactersDeleted = 0;
         mCursorPosition = mCursorPosition + InsertAt( Text( keyString ), mCursorPosition, mNumberOfSurroundingCharactersDeleted );
         update = true;
         mNumberOfSurroundingCharactersDeleted = 0;
+        EmitTextModified();
       }
       else
       {
       }
       else
       {
@@ -5092,11 +5109,18 @@ void TextInput::GetTextLayoutInfo()
 void TextInput::EmitStyleChangedSignal()
 {
   // emit signal if input style changes.
 void TextInput::EmitStyleChangedSignal()
 {
   // emit signal if input style changes.
-
   Toolkit::TextInput handle( GetOwner() );
   mStyleChangedSignalV2.Emit( handle, mInputStyle );
 }
 
   Toolkit::TextInput handle( GetOwner() );
   mStyleChangedSignalV2.Emit( handle, mInputStyle );
 }
 
+void TextInput::EmitTextModified()
+{
+  // emit signal when text changes.
+  Toolkit::TextInput handle( GetOwner() );
+  mTextModifiedSignal.Emit( handle );
+}
+
+
 void TextInput::EmitMaxInputCharactersReachedSignal()
 {
   // emit signal if max characters is reached during text input.
 void TextInput::EmitMaxInputCharactersReachedSignal()
 {
   // emit signal if max characters is reached during text input.
index 1712d2e..636f234 100644 (file)
@@ -130,6 +130,11 @@ public:
   Toolkit::TextInput::StyleChangedSignalV2& StyleChangedSignal();
 
   /**
   Toolkit::TextInput::StyleChangedSignalV2& StyleChangedSignal();
 
   /**
+   * @copydoc Toolkit::TextInput::TextModifiedSignal()
+   */
+  Toolkit::TextInput::TextModifiedSignalType& TextModifiedSignal();
+
+  /**
    * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
    */
   Toolkit::TextInput::MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
    * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
    */
   Toolkit::TextInput::MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
@@ -1316,6 +1321,11 @@ public:  // Public to allow internal testing.
   void EmitStyleChangedSignal();
 
   /**
   void EmitStyleChangedSignal();
 
   /**
+   * Emit signal when text is modified.
+   */
+  void EmitTextModified();
+
+  /**
    * Emits max input characters reached signal.
    */
   void EmitMaxInputCharactersReachedSignal();
    * Emits max input characters reached signal.
    */
   void EmitMaxInputCharactersReachedSignal();
@@ -1445,6 +1455,7 @@ private:
   Toolkit::TextInput::InputSignalV2                      mInputStartedSignalV2;              ///< Signal emitted when input starts
   Toolkit::TextInput::InputSignalV2                      mInputFinishedSignalV2;             ///< Signal emitted when input ends
   Toolkit::TextInput::StyleChangedSignalV2               mStyleChangedSignalV2;              ///< Signal emitted when style changes.
   Toolkit::TextInput::InputSignalV2                      mInputStartedSignalV2;              ///< Signal emitted when input starts
   Toolkit::TextInput::InputSignalV2                      mInputFinishedSignalV2;             ///< Signal emitted when input ends
   Toolkit::TextInput::StyleChangedSignalV2               mStyleChangedSignalV2;              ///< Signal emitted when style changes.
+  Toolkit::TextInput::TextModifiedSignalType             mTextModifiedSignal;                ///< Signal emitted when text modified.
   Toolkit::TextInput::MaxInputCharactersReachedSignalV2  mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
   Toolkit::TextInput::InputSignalV2                      mCutAndPasteToolBarDisplayedV2;     ///< Signal emitted when toolbar displayed
   Toolkit::TextInput::InputTextExceedBoundariesSignalV2  mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
   Toolkit::TextInput::MaxInputCharactersReachedSignalV2  mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
   Toolkit::TextInput::InputSignalV2                      mCutAndPasteToolBarDisplayedV2;     ///< Signal emitted when toolbar displayed
   Toolkit::TextInput::InputTextExceedBoundariesSignalV2  mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
index ff15d35..ed566de 100644 (file)
@@ -343,6 +343,11 @@ TextInput::StyleChangedSignalV2& TextInput::StyleChangedSignal()
   return GetImpl(*this).StyleChangedSignal();
 }
 
   return GetImpl(*this).StyleChangedSignal();
 }
 
+TextInput::TextModifiedSignalType& TextInput::TextModifiedSignal()
+{
+  return GetImpl(*this).TextModifiedSignal();
+}
+
 TextInput::MaxInputCharactersReachedSignalV2& TextInput::MaxInputCharactersReachedSignal()
 {
   return GetImpl(*this).MaxInputCharactersReachedSignal();
 TextInput::MaxInputCharactersReachedSignalV2& TextInput::MaxInputCharactersReachedSignal()
 {
   return GetImpl(*this).MaxInputCharactersReachedSignal();
index 68cde3d..cd672c3 100644 (file)
@@ -547,6 +547,9 @@ public: /* Signals */
   /// @brief Input style changed signal.
   typedef SignalV2< void ( TextInput textInput, const TextStyle& style ) > StyleChangedSignalV2;
 
   /// @brief Input style changed signal.
   typedef SignalV2< void ( TextInput textInput, const TextStyle& style ) > StyleChangedSignalV2;
 
+  /// @brief Text modified signal.
+  typedef SignalV2< void ( TextInput textInput  ) > TextModifiedSignalType;
+
   /// @brief Max input characters reached signal.
   typedef SignalV2< void ( TextInput textInput ) > MaxInputCharactersReachedSignalV2;
 
   /// @brief Max input characters reached signal.
   typedef SignalV2< void ( TextInput textInput ) > MaxInputCharactersReachedSignalV2;
 
@@ -581,6 +584,13 @@ public: /* Signals */
   StyleChangedSignalV2& StyleChangedSignal();
 
   /**
   StyleChangedSignalV2& StyleChangedSignal();
 
   /**
+   * @brief Signal emitted when text changes.
+   *
+   * @return The signal to connect to.
+   */
+  TextModifiedSignalType& TextModifiedSignal();
+
+  /**
    * @brief Signal emitted when max input characters are reached during text input.
    *
    * @return The signal to connect to
    * @brief Signal emitted when max input characters are reached during text input.
    *
    * @return The signal to connect to