X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Ftext-input%2Ftext-input-impl.cpp;h=d61594284d1d3f8e54ea2cff60c627a307f5e197;hp=3d79aad868631b79f71e58b354b622a87e106e64;hb=58186fc1abcee2136a81c2060f90e9fb4f0ddeca;hpb=40472c84617d3f505ba9861d3628f77e796ab45c diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp index 3d79aad..d615942 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp @@ -1,18 +1,19 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include @@ -26,9 +27,6 @@ #include #include #include -#include - -#define GET_LOCALE_TEXT(string) dgettext("sys_string", string) using namespace std; using namespace Dali; @@ -46,7 +44,7 @@ const std::size_t DEFAULT_NUMBER_OF_LINES_LIMIT( std::numeric_limits& boundingRectangle ) originY + boundingRectangle.height ); mBoundingRectangleWorldCoordinates = boundary; + + // Set Boundary for Popup so it keeps the Pop-up within the area also. + mPopUpPanel.SetPopupBoundary( boundingRectangle ); } const Rect TextInput::GetBoundingRectangle() const @@ -1360,7 +1389,7 @@ void TextInput::OnDoubleTap(Dali::Actor actor, Dali::TapGesture tap) SelectText( start, end ); } // if no text but clipboard has content then show paste option - if ( mClipboard.NumberOfItems() || !mStyledText.empty() ) + if ( ( mClipboard && mClipboard.NumberOfItems() ) || !mStyledText.empty() ) { ShowPopupCutCopyPaste(); } @@ -1550,7 +1579,7 @@ void TextInput::OnLongPress(Dali::Actor actor, Dali::LongPressGesture longPress) } // if no text but clipboard has content then show paste option, if no text and clipboard empty then do nothing - if ( mClipboard.NumberOfItems() || !mStyledText.empty() ) + if ( ( mClipboard && mClipboard.NumberOfItems() ) || !mStyledText.empty() ) { ShowPopupCutCopyPaste(); } @@ -1577,7 +1606,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) const std::string& name = button.GetName(); - if(name == OPTION_SELECT_WORD) + if(name == TextInputPopup::OPTION_SELECT_WORD) { std::size_t start = 0; std::size_t end = 0; @@ -1585,7 +1614,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) SelectText( start, end ); } - else if(name == OPTION_SELECT_ALL) + else if(name == TextInputPopup::OPTION_SELECT_ALL) { SetCursorVisibility(false); StopCursorBlinkTimer(); @@ -1595,7 +1624,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) SelectText( start, end ); } - else if(name == OPTION_CUT) + else if(name == TextInputPopup::OPTION_CUT) { bool ret = CopySelectedTextToClipboard(); @@ -1610,7 +1639,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) HidePopup(); } - else if(name == OPTION_COPY) + else if(name == TextInputPopup::OPTION_COPY) { CopySelectedTextToClipboard(); @@ -1621,7 +1650,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) HidePopup(); } - else if(name == OPTION_PASTE) + else if(name == TextInputPopup::OPTION_PASTE) { const Text retrievedString( mClipboard.GetItem( 0 ) ); // currently can only get first item in clip board, index 0; @@ -1634,7 +1663,7 @@ bool TextInput::OnPopupButtonPressed( Toolkit::Button button ) HidePopup(); } - else if(name == OPTION_CLIPBOARD) + else if(name == TextInputPopup::OPTION_CLIPBOARD) { // In the case of clipboard being shown we do not want to show updated pop-up after hide animation completes // Hence pass the false parameter for signalFinished. @@ -2110,7 +2139,7 @@ void TextInput::ApplyPreEditStyle( std::size_t preEditStartPosition, std::size_t { if ( mPreEditFlag && ( preEditStringLength > 0 ) ) { - mUnderlinedPriorToPreEdit = mInputStyle.GetUnderline(); + mUnderlinedPriorToPreEdit = mInputStyle.IsUnderlineEnabled(); TextStyle style; style.SetUnderline( true ); ApplyStyleToRange( style, TextStyle::UNDERLINE , preEditStartPosition, preEditStartPosition + preEditStringLength -1 ); @@ -2872,7 +2901,7 @@ void TextInput::DrawCursor(const std::size_t nthChar) mCursor.SetSize(size); // If the character is italic then the cursor also tilts. - mCursor.SetRotation( mInputStyle.GetItalics() ? Degree( mInputStyle.GetItalicsAngle() - CURSOR_ANGLE_OFFSET ) : Degree( 0.f ), Vector3::ZAXIS ); + mCursor.SetRotation( mInputStyle.IsItalicsEnabled() ? Degree( mInputStyle.GetItalicsAngle() - CURSOR_ANGLE_OFFSET ) : Degree( 0.f ), Vector3::ZAXIS ); DALI_ASSERT_DEBUG( mCursorPosition <= mTextLayoutInfo.mCharacterLayoutInfoTable.size() ); @@ -3666,9 +3695,9 @@ void TextInput::ClearPopup() mPopUpPanel.Clear(); } -void TextInput::AddPopupOption(const std::string& name, const std::string& caption, const Image icon, bool finalOption) +void TextInput::AddPopupOptions() { - mPopUpPanel.AddOption(name, caption, icon, finalOption); + mPopUpPanel.AddPopupOptions(); } void TextInput::SetPopupPosition(const Vector3& position) @@ -3716,7 +3745,7 @@ void TextInput::ShowPopup(bool animate) Vector3 bottomHandle; bottomHandle.y = std::max ( mSelectionHandleTwoActualPosition.y , mSelectionHandleOneActualPosition.y ); bottomHandle.y += GetSelectionHandleSize().y + BOTTOM_HANDLE_BOTTOM_OFFSET; - mPopUpPanel.SetAlternativeOffset(Vector2(0.0f, bottomHandle.y - topHandle.y)); + mPopUpPanel.SetAlternativeOffset(Vector2( mBoundingRectangleWorldCoordinates.x, bottomHandle.y - topHandle.y)); } else { @@ -3725,11 +3754,11 @@ void TextInput::ShowPopup(bool animate) const Size rowSize = GetRowRectFromCharacterPosition( mCursorPosition ); position.y -= rowSize.height; // if can't be positioned above, then position below row. - Vector2 alternativePopUpPosition( 0.0f, position.y ); // default if no grab handle + Vector2 alternativePopUpPosition( mBoundingRectangleWorldCoordinates.x, position.y ); // default if no grab handle if ( mGrabHandle ) { - alternativePopUpPosition.y = rowSize.height + ( mGrabHandle.GetCurrentSize().height * DEFAULT_GRAB_HANDLE_RELATIVE_SIZE.y ) ; // If grab handle enabled then position pop-up below the grab handle. + alternativePopUpPosition.y = rowSize.height + mGrabHandle.GetCurrentSize().height + BOTTOM_HANDLE_BOTTOM_OFFSET ; } mPopUpPanel.SetAlternativeOffset( alternativePopUpPosition ); } @@ -3737,7 +3766,7 @@ void TextInput::ShowPopup(bool animate) // reposition popup above the desired cursor posiiton. Vector3 textViewSize = mDisplayedTextView.GetCurrentSize(); textViewSize.z = 0.0f; - // World position = world position of ParentOrigin of cursor (i.e. top-left corner of TextView) + cursor position; + // World position = world position of local position i.e. top-left corner of TextView Vector3 worldPosition = mDisplayedTextView.GetCurrentWorldPosition() - (textViewSize * 0.5f) + position; SetPopupPosition( worldPosition ); @@ -3752,29 +3781,29 @@ void TextInput::ShowPopup(bool animate) void TextInput::ShowPopupCutCopyPaste() { ClearPopup(); + + mPopUpPanel.CreateOrderedListOfOptions(); // todo Move this so only run when order has changed // Check the selected text is whole text or not. if( IsTextSelected() && ( mStyledText.size() != GetSelectedText().size() ) ) { - Image selectAllIcon = Image::New( DEFAULT_ICON_SELECT_ALL ); - AddPopupOption( OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsSelectAll, true ); } if ( !mStyledText.empty() ) { - Image cutIcon = Image::New( DEFAULT_ICON_CUT ); - Image copyIcon = Image::New( DEFAULT_ICON_COPY ); - AddPopupOption( OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon ); - AddPopupOption( OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, true ); + + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsCopy, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsCut, true ); } - if(mClipboard.NumberOfItems()) + if( mClipboard && mClipboard.NumberOfItems() ) { - Image pasteIcon = Image::New( DEFAULT_ICON_PASTE ); - Image clipboardIcon = Image::New( DEFAULT_ICON_CLIPBOARD ); - AddPopupOption( OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon ); - AddPopupOption( OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsPaste, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsClipboard, true ); } + AddPopupOptions(); + mPopUpPanel.Hide(false); ShowPopup(); } @@ -3782,24 +3811,23 @@ void TextInput::ShowPopupCutCopyPaste() void TextInput::SetUpPopUpSelection() { ClearPopup(); - + mPopUpPanel.CreateOrderedListOfOptions(); // todo Move this so only run when order has changed // If no text exists then don't offer to select if ( !mStyledText.empty() ) { - Image selectIcon = Image::New( DEFAULT_ICON_SELECT ); - Image selectAllIcon = Image::New( DEFAULT_ICON_SELECT_ALL ); - AddPopupOption( OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon ); - AddPopupOption( OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsSelectAll, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsSelect, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsCut, true ); } // if clipboard has valid contents then offer paste option - if( mClipboard.NumberOfItems() ) + if( mClipboard && mClipboard.NumberOfItems() ) { - Image pasteIcon = Image::New( DEFAULT_ICON_PASTE ); - Image clipboardIcon = Image::New( DEFAULT_ICON_CLIPBOARD ); - AddPopupOption( OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, true ); - AddPopupOption( OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsPaste, true ); + mPopUpPanel.TogglePopUpButtonOnOff( TextInputPopup::ButtonsClipboard, true ); } + AddPopupOptions(); + mPopUpPanel.Hide(false); } @@ -4670,7 +4698,7 @@ void TextInput::CreateHighlight() mMeshData.SetHasNormals( true ); mCustomMaterial = Material::New("CustomMaterial"); - mCustomMaterial.SetDiffuseColor( LIGHTBLUE ); + mCustomMaterial.SetDiffuseColor( mMaterialColor ); mMeshData.SetMaterial( mCustomMaterial ); @@ -5107,6 +5135,127 @@ void TextInput::GetTextLayoutInfo() } } +void TextInput::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) +{ + Toolkit::TextInput textInput = Toolkit::TextInput::DownCast( Dali::BaseHandle( object ) ); + + if ( textInput ) + { + TextInput& textInputImpl( GetImpl( textInput ) ); + + switch ( propertyIndex ) + { + case Toolkit::TextInput::HIGHLIGHT_COLOR_PROPERTY: + { + textInputImpl.SetMaterialDiffuseColor( value.Get< Vector4 >() ); + break; + } + case Toolkit::TextInput::CUT_AND_PASTE_COLOR_PROPERTY: + { + textInputImpl.mPopUpPanel.SetCutPastePopUpColor( value.Get< Vector4 >() ); + break; + } + case Toolkit::TextInput::CUT_AND_PASTE_PRESSED_COLOR_PROPERTY: + { + textInputImpl.mPopUpPanel.SetCutPastePopUpPressedColor( value.Get< Vector4 >() ); + break; + } + case Toolkit::TextInput::CUT_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsCut, value.Get() ); + break; + } + case Toolkit::TextInput::COPY_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsCopy, value.Get() ); + break; + } + case Toolkit::TextInput::PASTE_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsPaste, value.Get() ); + break; + } + case Toolkit::TextInput::SELECT_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsSelect, value.Get() ); + break; + } + case Toolkit::TextInput::SELECT_ALL_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsSelectAll, value.Get() ); + break; + } + case Toolkit::TextInput::CLIPBOARD_BUTTON_POSITION_PRIORITY_PROPERTY: + { + textInputImpl.mPopUpPanel.SetButtonPriorityPosition( TextInputPopup::ButtonsClipboard, value.Get() ); + break; + } + } + } +} + +Property::Value TextInput::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Property::Value value; + + Toolkit::TextInput textInput = Toolkit::TextInput::DownCast( Dali::BaseHandle( object ) ); + + if ( textInput ) + { + TextInput& textInputImpl( GetImpl( textInput ) ); + + switch ( propertyIndex ) + { + case Toolkit::TextInput::HIGHLIGHT_COLOR_PROPERTY: + { + value = textInputImpl.GetMaterialDiffuseColor(); + break; + } + case Toolkit::TextInput::CUT_AND_PASTE_COLOR_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetCutPastePopUpColor(); + break; + } + case Toolkit::TextInput::CUT_AND_PASTE_PRESSED_COLOR_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetCutPastePopUpPressedColor(); + break; + } + case Toolkit::TextInput::CUT_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsCut ); + break; + } + case Toolkit::TextInput::COPY_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsCopy ); + break; + } + case Toolkit::TextInput::PASTE_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsPaste ); + break; + } + case Toolkit::TextInput::SELECT_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsSelect ); + break; + } + case Toolkit::TextInput::SELECT_ALL_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsSelectAll ); + break; + } + case Toolkit::TextInput::CLIPBOARD_BUTTON_POSITION_PRIORITY_PROPERTY: + { + value = textInputImpl.mPopUpPanel.GetButtonPriorityPosition( TextInputPopup::ButtonsClipboard ); + break; + } + } + } + return value; +} + void TextInput::EmitStyleChangedSignal() { // emit signal if input style changes.