Merge "When matchSystemLanguageDirection is set, it should follow the direction setti...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index f9fe425..14bac16
@@ -22,7 +22,8 @@
 #include <cstring>
 #include <limits>
 #include <dali/public-api/adaptor-framework/key.h>
-#include <dali/public-api/common/stage.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/object/property-helper-devel.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/text/rendering-backend.h>
 #include <dali-toolkit/public-api/text/text-enumerations.h>
 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/devel-api/text/rendering-backend.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
-#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
@@ -63,7 +63,7 @@ namespace // unnamed namespace
 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
 #endif
 
-const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
 } // unnamed namespace
 
@@ -83,7 +83,6 @@ BaseHandle Create()
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
 
-DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",                     INTEGER,   RENDERING_BACKEND                    )
 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text",                                 STRING,    TEXT                                 )
 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor",                            VECTOR4,   TEXT_COLOR                           )
 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily",                           STRING,    FONT_FAMILY                          )
@@ -138,9 +137,12 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection",           BOOLEAN,   ENABLE_SHIFT_SELECTION               )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle",               BOOLEAN,   ENABLE_GRAB_HANDLE                   )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection",   BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION      )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",               INTEGER,   RENDERING_BACKEND                    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength",                      INTEGER,   MAX_LENGTH                           )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -192,7 +194,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P
 
     switch( index )
     {
-      case Toolkit::TextEditor::Property::RENDERING_BACKEND:
+      case Toolkit::DevelTextEditor::Property::RENDERING_BACKEND:
       {
         int backend = value.Get< int >();
         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
@@ -771,6 +773,17 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P
         }
         break;
       }
+      case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
+      {
+        if( impl.mController )
+        {
+          const int max = value.Get< int >();
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p MAX_LENGTH %d\n", impl.mController.Get(), max );
+
+          impl.mController->SetMaximumNumberOfCharacters( max );
+        }
+        break;
+      }
     } // switch
   } // texteditor
 }
@@ -787,7 +800,7 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
 
     switch( index )
     {
-      case Toolkit::TextEditor::Property::RENDERING_BACKEND:
+      case Toolkit::DevelTextEditor::Property::RENDERING_BACKEND:
       {
         value = impl.mRenderingBackend;
         break;
@@ -1171,6 +1184,14 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
         }
         break;
       }
+      case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
+      {
+        if( impl.mController )
+        {
+          value = impl.mController->GetMaximumNumberOfCharacters();
+        }
+        break;
+      }
     } //switch
   }
 
@@ -1182,6 +1203,11 @@ InputMethodContext TextEditor::GetInputMethodContext()
   return mInputMethodContext;
 }
 
+DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
+{
+  return mMaxLengthReachedSignal;
+}
+
 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   Dali::BaseHandle handle( object );
@@ -1197,6 +1223,14 @@ bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface
   {
     editor.InputStyleChangedSignal().Connect( tracker, functor );
   }
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
+  {
+    if( editor )
+    {
+      Internal::TextEditor& editorImpl( GetImpl( editor ) );
+      editorImpl.MaxLengthReachedSignal().Connect( tracker, functor );
+    }
+  }
   else
   {
     // signalName does not match any signal
@@ -1282,7 +1316,7 @@ void TextEditor::OnInitialize()
   // Fill-parent area by default
   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
-  self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
+  self.OnSceneSignal().Connect( this, &TextEditor::OnSceneConnect );
 
   DevelControl::SetInputMethodContext( *this, mInputMethodContext );
 
@@ -1367,7 +1401,15 @@ void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
   Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
 
   // Support Right-To-Left of padding
-  Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+  Dali::LayoutDirection::Type layoutDirection;
+  if( mController->IsMatchSystemLanguageDirection() )
+  {
+    layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+  }
+  else
+  {
+    layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+  }
   if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
   {
     std::swap( padding.start, padding.end );
@@ -1559,12 +1601,12 @@ void TextEditor::OnLongPress( const LongPressGesture& gesture )
 
 bool TextEditor::OnKeyEvent( const KeyEvent& event )
 {
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
 
-  if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
+  if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
   {
     // Make sure ClearKeyInputFocus when only key is up
-    if( event.state == KeyEvent::Up )
+    if( event.GetState() == KeyEvent::UP )
     {
       ClearKeyInputFocus();
     }
@@ -1588,7 +1630,8 @@ void TextEditor::TextChanged()
 
 void TextEditor::MaxLengthReached()
 {
-  // Nothing to do as TextEditor doesn't emit a max length reached signal.
+  Dali::Toolkit::TextEditor handle( GetOwner() );
+  mMaxLengthReachedSignal.Emit( handle );
 }
 
 void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
@@ -1759,7 +1802,7 @@ void TextEditor::OnScrollIndicatorAnimationFinished( Animation& animation )
   }
 }
 
-void TextEditor::OnStageConnect( Dali::Actor actor )
+void TextEditor::OnSceneConnect( Dali::Actor actor )
 {
   if ( mHasBeenStaged )
   {
@@ -1807,20 +1850,20 @@ void TextEditor::KeyboardStatusChanged(bool keyboardShown)
   }
 }
 
-void TextEditor::OnStageConnection( int depth )
+void TextEditor::OnSceneConnection( int depth )
 {
   // Sets the depth to the visuals inside the text's decorator.
   mDecorator->SetTextDepth( depth );
 
   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
 
-  // Call the Control::OnStageConnection() to set the depth of the background.
-  Control::OnStageConnection( depth );
+  // Call the Control::OnSceneConnection() to set the depth of the background.
+  Control::OnSceneConnection( depth );
 }
 
-bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
+bool TextEditor::OnTouched( Actor actor, const TouchEvent& touch )
 {
-  return true;
+  return false;
 }
 
 void TextEditor::OnIdleSignal()