Merge "Text Editing (enable) property in text controls" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.cpp
index 7b85236..4224df2 100644 (file)
@@ -140,6 +140,9 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle",
 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_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextStart",              INTEGER,   SELECTED_TEXT_START                  )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextEnd",                INTEGER,   SELECTED_TEXT_END                    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing",                  BOOLEAN,   ENABLE_EDITING                       )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
@@ -696,6 +699,33 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P
         impl.mController->SetMaximumNumberOfCharacters( max );
         break;
       }
+      case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START:
+      {
+        if( impl.mController )
+        {
+          uint32_t start = static_cast<uint32_t>(value.Get< int >());
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
+          impl.SetTextSelectionRange( &start, nullptr );
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_END:
+      {
+        if( impl.mController )
+        {
+          uint32_t end = static_cast<uint32_t>(value.Get< int >());
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
+          impl.SetTextSelectionRange( nullptr, &end );
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::ENABLE_EDITING:
+      {
+        const bool editable = value.Get< bool >();
+        DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
+        impl.SetEditable( editable );
+        break;
+      }
     } // switch
   } // texteditor
 }
@@ -1010,6 +1040,23 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
         value = impl.mController->GetMaximumNumberOfCharacters();
         break;
       }
+      case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START:
+      {
+        Uint32Pair range = impl.GetTextSelectionRange();
+        value = static_cast<int>(range.first);
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_END:
+      {
+        Uint32Pair range = impl.GetTextSelectionRange();
+        value = static_cast<int>(range.second);
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::ENABLE_EDITING:
+      {
+        value = impl.IsEditable();
+        break;
+      }
     } //switch
   }
 
@@ -1077,7 +1124,7 @@ void TextEditor::OnInitialize()
 {
   Actor self = Self();
 
-  mController = Text::Controller::New( this, this );
+  mController = Text::Controller::New( this, this, this);
 
   mDecorator = Text::Decorator::New( *mController,
                                      *mController );
@@ -1333,7 +1380,7 @@ void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
 void TextEditor::OnKeyInputFocusGained()
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
-  if ( mInputMethodContext )
+  if ( mInputMethodContext  && IsEditable() )
   {
     mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
 
@@ -1387,7 +1434,7 @@ void TextEditor::OnKeyInputFocusLost()
 void TextEditor::OnTap( const TapGesture& gesture )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
-  if ( mInputMethodContext )
+  if ( mInputMethodContext && IsEditable() )
   {
     mInputMethodContext.Activate();
   }
@@ -1407,7 +1454,7 @@ void TextEditor::OnPan( const PanGesture& gesture )
 
 void TextEditor::OnLongPress( const LongPressGesture& gesture )
 {
-  if ( mInputMethodContext )
+  if ( mInputMethodContext && IsEditable() )
   {
     mInputMethodContext.Activate();
   }
@@ -1526,6 +1573,25 @@ void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
   }
 }
 
+void TextEditor::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    mController->SetTextSelectionRange( start, end );
+    SetKeyInputFocus();
+  }
+}
+
+Uint32Pair TextEditor::GetTextSelectionRange() const
+{
+  Uint32Pair range(0, 0);
+  if( mController && mController->IsShowingRealText() )
+  {
+    range = mController->GetTextSelectionRange();
+  }
+  return range;
+}
+
 void TextEditor::UpdateScrollBar()
 {
   using namespace Dali;
@@ -1723,6 +1789,20 @@ void TextEditor::ApplyScrollPosition()
   }
 }
 
+bool TextEditor::IsEditable() const
+{
+  return mController->IsEditable();
+}
+
+void TextEditor::SetEditable( bool editable )
+{
+  mController->SetEditable(editable);
+  if ( mInputMethodContext && !editable )
+  {
+    mInputMethodContext.Deactivate();
+  }
+}
+
 TextEditor::TextEditor()
 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mAnimationPeriod( 0.0f, 0.0f ),