Merge "Text selection refactoring" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 5a8a6e0..797ae32 100755 (executable)
@@ -53,6 +53,8 @@ const std::string EMPTY_STRING("");
 const std::string KEY_C_NAME = "c";
 const std::string KEY_V_NAME = "v";
 const std::string KEY_X_NAME = "x";
+const std::string KEY_A_NAME = "a";
+const std::string KEY_INSERT_NAME = "Insert";
 
 const char * const PLACEHOLDER_TEXT = "text";
 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
@@ -2907,12 +2909,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
       // Do nothing
       return false;
     }
-    else if ( keyEvent.IsCtrlModifier() )
+    else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier())
     {
       bool consumed = false;
-      if (keyName == KEY_C_NAME)
+      if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME)
       {
-        // Ctrl-C to copy the selected text
+        // Ctrl-C or Ctrl+Insert to copy the selected text
         TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
         consumed = true;
       }
@@ -2928,6 +2930,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
         TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
         consumed = true;
       }
+      else if (keyName == KEY_A_NAME)
+      {
+        // Ctrl-A to select All the text
+        TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL );
+        consumed = true;
+      }
       return consumed;
     }
     else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
@@ -2967,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() )
       {
@@ -3205,6 +3214,26 @@ Uint32Pair Controller::GetTextSelectionRange() const
   return mImpl->GetTextSelectionRange();
 }
 
+void Controller::SelectWholeText()
+{
+  SelectEvent( 0.f, 0.f, SelectionType::ALL );
+}
+
+void Controller::SelectNone()
+{
+  SelectEvent( 0.f, 0.f, SelectionType::NONE );
+}
+
+string Controller::GetSelectedText() const
+{
+  string text;
+  if( EventData::SELECTING == mImpl->mEventData->mState )
+  {
+    mImpl->RetrieveSelection( text, false );
+  }
+  return text;
+}
+
 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
 {
   // Whether the text needs to be relaid-out.
@@ -3360,6 +3389,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" );
@@ -3427,6 +3470,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;
 
@@ -3902,16 +3946,6 @@ bool Controller::RemoveSelectedText()
   return textRemoved;
 }
 
-std::string Controller::GetSelectedText()
-{
-  std::string text;
-  if( EventData::SELECTING == mImpl->mEventData->mState )
-  {
-    mImpl->RetrieveSelection( text, false );
-  }
-  return text;
-}
-
 // private : Relayout.
 
 bool Controller::DoRelayout( const Size& size,
@@ -4216,6 +4250,8 @@ void Controller::TextDeletedEvent()
     return;
   }
 
+  if (!IsEditable()) return;
+
   mImpl->mEventData->mCheckScrollAmount = true;
 
   // The natural size needs to be re-calculated.
@@ -4239,6 +4275,8 @@ bool Controller::DeleteEvent( int keyCode )
     return removed;
   }
 
+  if (!IsEditable()) return false;
+
   // InputMethodContext is no longer handling key-events
   mImpl->ClearPreEditFlag();