/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali-toolkit/internal/text/hidden-text.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
using namespace Dali::Toolkit;
-const uint32_t STAR = 0x2A; // Set default substitute character as '*'
-const int DEFAULT_SHOW_DURATION = 1000;
+const int DEFAULT_SHOW_DURATION = 1000;
namespace Dali
{
-
namespace Toolkit
{
-
namespace Text
{
-
-const char * const PROPERTY_MODE = "mode";
-const char * const PROPERTY_SUBSTITUTE_CHARACTER = "substituteCharacter";
-const char * const PROPERTY_SUBSTITUTE_COUNT = "substituteCount";
-const char * const PROPERTY_SHOW_DURATION = "showDuration";
-
-HiddenText::HiddenText( Observer* observer )
-: mObserver( observer ),
- mHideMode( static_cast< int >( Toolkit::HiddenInput::Mode::HIDE_NONE ) ),
- mSubstituteText( STAR ),
- mDisplayDuration( DEFAULT_SHOW_DURATION ),
- mSubstituteCount( 0 ),
- mPreviousTextCount( 0 )
+const char* const PROPERTY_MODE = "mode";
+const char* const PROPERTY_SUBSTITUTE_CHARACTER = "substituteCharacter";
+const char* const PROPERTY_SUBSTITUTE_COUNT = "substituteCount";
+const char* const PROPERTY_SHOW_DURATION = "showDuration";
+
+HiddenText::HiddenText(Observer* observer)
+: mObserver(observer),
+ mHideMode(static_cast<int>(Toolkit::HiddenInput::Mode::HIDE_NONE)),
+ mSubstituteText(STAR),
+ mDisplayDuration(DEFAULT_SHOW_DURATION),
+ mSubstituteCount(0),
+ mPreviousTextCount(0u),
+ mIsLastCharacterShow(false)
{
- mTimer = Timer::New( mDisplayDuration );
- mTimer.TickSignal().Connect( this, &HiddenText::OnTick );
+ mTimer = Timer::New(mDisplayDuration);
+ mTimer.TickSignal().Connect(this, &HiddenText::OnTick);
}
-void HiddenText::SetProperties( const Property::Map& map )
+void HiddenText::SetProperties(const Property::Map& map)
{
- const Property::Map::SizeType count = map.Count();
+ const Property::Map::SizeType count = map.Count();
- for ( Property::Map::SizeType position = 0; position < count; ++position )
- {
- KeyValuePair keyValue = map.GetKeyValue( position );
- Property::Key& key = keyValue.first;
- Property::Value& value = keyValue.second;
+ for(Property::Map::SizeType position = 0; position < count; ++position)
+ {
+ KeyValuePair keyValue = map.GetKeyValue(position);
+ Property::Key& key = keyValue.first;
+ Property::Value& value = keyValue.second;
- if( key == Toolkit::HiddenInput::Property::MODE || key == PROPERTY_MODE )
- {
- value.Get( mHideMode );
- }
- else if( key == Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER || key == PROPERTY_SUBSTITUTE_CHARACTER )
- {
- value.Get( mSubstituteText );
- }
- else if( key == Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT || key == PROPERTY_SUBSTITUTE_COUNT )
- {
- value.Get( mSubstituteCount );
- }
- else if( key == Toolkit::HiddenInput::Property::SHOW_DURATION || key == PROPERTY_SHOW_DURATION )
- {
- value.Get( mDisplayDuration );
- }
+ if(key == Toolkit::HiddenInput::Property::MODE || key == PROPERTY_MODE)
+ {
+ value.Get(mHideMode);
}
+ else if(key == Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER || key == PROPERTY_SUBSTITUTE_CHARACTER)
+ {
+ value.Get(mSubstituteText);
+ }
+ else if(key == Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT || key == PROPERTY_SUBSTITUTE_COUNT)
+ {
+ value.Get(mSubstituteCount);
+ }
+ else if(key == Toolkit::HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION || key == PROPERTY_SHOW_DURATION)
+ {
+ value.Get(mDisplayDuration);
+ }
+ }
}
-void HiddenText::GetProperties( Property::Map& map )
+void HiddenText::GetProperties(Property::Map& map)
{
- map[Toolkit::HiddenInput::Property::MODE] = mHideMode;
- map[Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER] = mSubstituteText;
- map[Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT] = mSubstituteCount;
- map[Toolkit::HiddenInput::Property::SHOW_DURATION] = mDisplayDuration;
+ map[Toolkit::HiddenInput::Property::MODE] = mHideMode;
+ map[Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER] = mSubstituteText;
+ map[Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT] = mSubstituteCount;
+ map[Toolkit::HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION] = mDisplayDuration;
}
-void HiddenText::Substitute( const Vector<Character>& source, Vector<Character>& destination )
+void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>& destination, Length cursorPos)
{
const Length characterCount = source.Count();
- destination.Resize( characterCount );
+ destination.Resize(characterCount);
- uint32_t* begin = destination.Begin();
- uint32_t* end = begin + characterCount;
+ uint32_t* begin = destination.Begin();
+ uint32_t* end = begin + characterCount;
uint32_t* hideStart = NULL;
- uint32_t* hideEnd = NULL;
+ uint32_t* hideEnd = NULL;
uint32_t* sourcePos = source.Begin();
- switch ( mHideMode )
+ switch(mHideMode)
{
case Toolkit::HiddenInput::Mode::HIDE_NONE:
{
hideStart = NULL;
- hideEnd = NULL;
+ hideEnd = NULL;
break;
}
case Toolkit::HiddenInput::Mode::HIDE_ALL:
{
hideStart = begin;
- hideEnd = end;
+ hideEnd = end;
break;
}
case Toolkit::HiddenInput::Mode::HIDE_COUNT:
{
hideStart = begin;
- hideEnd = begin + mSubstituteCount;
+ hideEnd = begin + mSubstituteCount;
break;
}
case Toolkit::HiddenInput::Mode::SHOW_COUNT:
{
hideStart = begin + mSubstituteCount;
- hideEnd = end;
+ hideEnd = end;
break;
}
case Toolkit::HiddenInput::Mode::SHOW_LAST_CHARACTER:
{
- if (mPreviousTextCount < characterCount)
+ hideStart = begin;
+ hideEnd = end;
+ if(mPreviousTextCount < characterCount)
{
- hideStart = begin;
- hideEnd = end-1;
- if ( mDisplayDuration > 0 )
+ if(mDisplayDuration > 0)
{
- mTimer.SetInterval( mDisplayDuration );
+ mTimer.SetInterval(mDisplayDuration);
mTimer.Start();
+ mIsLastCharacterShow = true;
}
else
{
}
else
{
- hideStart = begin;
- hideEnd = end;
+ mIsLastCharacterShow = false;
}
break;
}
}
- for (; begin < end; ++begin )
+
+
+ if(mHideMode == Toolkit::HiddenInput::Mode::SHOW_LAST_CHARACTER)
{
- if (begin >= hideStart && begin < hideEnd)
+ Length currentPos = 0u;
+ for(; begin < end; ++begin)
{
- *begin = static_cast<uint32_t>(mSubstituteText);
+ if(begin >= hideStart && begin < hideEnd && cursorPos > 0u && currentPos != cursorPos - 1u)
+ {
+ *begin = static_cast<uint32_t>(mSubstituteText);
+ }
+ else
+ {
+ *begin = mIsLastCharacterShow ? *sourcePos : static_cast<uint32_t>(mSubstituteText);
+ }
sourcePos++;
+ currentPos++;
}
- else
+ }
+ else
+ {
+ for(; begin < end; ++begin)
{
- *begin = *sourcePos++;
+ if(begin >= hideStart && begin < hideEnd)
+ {
+ *begin = static_cast<uint32_t>(mSubstituteText);
+ sourcePos++;
+ }
+ else
+ {
+ *begin = *sourcePos++;
+ }
}
}
mPreviousTextCount = characterCount;
}
+void HiddenText::InitPreviousTextCount()
+{
+ mPreviousTextCount = 0u;
+}
+
+int HiddenText::GetHideMode()
+{
+ return mHideMode;
+}
+
bool HiddenText::OnTick()
{
- if( mObserver != NULL )
+ if(mObserver != NULL)
{
mObserver->DisplayTimeExpired();
}
-
+ mIsLastCharacterShow = false;
return false;
}