Text Editing (enable) property in text controls
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 48036ad..ca02bac 100755 (executable)
@@ -143,10 +143,12 @@ ControllerPtr Controller::New( ControlInterface* controlInterface )
 }
 
 ControllerPtr Controller::New( ControlInterface* controlInterface,
-                               EditableControlInterface* editableControlInterface )
+                               EditableControlInterface* editableControlInterface,
+                               SelectableControlInterface* selectableControlInterface )
 {
   return ControllerPtr( new Controller( controlInterface,
-                                        editableControlInterface ) );
+                                        editableControlInterface,
+                                        selectableControlInterface ) );
 }
 
 // public : Configure the text controller.
@@ -2973,6 +2975,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
     else
     {
       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
+      if (!IsEditable()) return false;
 
       if( !keyString.empty() )
       {
@@ -3193,6 +3196,24 @@ void Controller::SelectEvent( float x, float y, SelectionType selectType )
   }
 }
 
+void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
+{
+  if( mImpl->mEventData )
+  {
+    mImpl->mEventData->mCheckScrollAmount = true;
+    mImpl->mEventData->mIsLeftHandleSelected = true;
+    mImpl->mEventData->mIsRightHandleSelected = true;
+    mImpl->SetTextSelectionRange(start, end);
+    mImpl->RequestRelayout();
+    KeyboardFocusGainEvent();
+  }
+}
+
+Uint32Pair Controller::GetTextSelectionRange() const
+{
+  return mImpl->GetTextSelectionRange();
+}
+
 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
 {
   // Whether the text needs to be relaid-out.
@@ -3348,6 +3369,20 @@ void Controller::AddDecoration( Actor& actor, bool needsClipping )
   }
 }
 
+bool Controller::IsEditable() const
+{
+  return mImpl->IsEditable();
+}
+
+void Controller::SetEditable( bool editable )
+{
+  mImpl->SetEditable( editable );
+  if(mImpl->mEventData && mImpl->mEventData->mDecorator)
+  {
+    mImpl->mEventData->mDecorator->SetEditable( editable );
+  }
+}
+
 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
 {
   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
@@ -3415,6 +3450,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt
   {
     case Toolkit::TextSelectionPopup::CUT:
     {
+      if (!IsEditable()) return;
       mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
       mImpl->mOperationsPending = ALL_OPERATIONS;
 
@@ -4204,6 +4240,8 @@ void Controller::TextDeletedEvent()
     return;
   }
 
+  if (!IsEditable()) return;
+
   mImpl->mEventData->mCheckScrollAmount = true;
 
   // The natural size needs to be re-calculated.
@@ -4227,6 +4265,8 @@ bool Controller::DeleteEvent( int keyCode )
     return removed;
   }
 
+  if (!IsEditable()) return false;
+
   // InputMethodContext is no longer handling key-events
   mImpl->ClearPreEditFlag();
 
@@ -4448,19 +4488,21 @@ Actor Controller::CreateBackgroundActor()
 Controller::Controller()
 : mImpl( NULL )
 {
-  mImpl = new Controller::Impl( NULL, NULL );
+  mImpl = new Controller::Impl( nullptr, nullptr, nullptr );
 }
 
 Controller::Controller( ControlInterface* controlInterface )
 {
-  mImpl = new Controller::Impl( controlInterface, NULL );
+  mImpl = new Controller::Impl( controlInterface, NULL, NULL );
 }
 
 Controller::Controller( ControlInterface* controlInterface,
-                        EditableControlInterface* editableControlInterface )
+                        EditableControlInterface* editableControlInterface,
+                        SelectableControlInterface* selectableControlInterface )
 {
   mImpl = new Controller::Impl( controlInterface,
-                                editableControlInterface );
+                                editableControlInterface,
+                                selectableControlInterface );
 }
 
 // The copy constructor and operator are left unimplemented.