X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-selection-popup-impl.cpp;h=91ef03b6b61d1a72ce757bbe96653da648e35688;hp=be7834aa7e9880c6b0c405fe66bbcc7cc34f6ce2;hb=cb6abb2872336c1532a69093f05d8cb333c31f47;hpb=8c18e2ceb273e1db22547264a4466fa565081a29 diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index be7834a..91ef03b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -19,7 +19,7 @@ #include // INTERNAL INCLUDES -#include +#include #include #include @@ -48,7 +48,7 @@ namespace const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.69f, 0.93f, 0.93f, 1.0f ) ); const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); -const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.5f, 1.0f, 1.0f, 1.0f ) ); +const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.12f, 0.56f, 1.0f, 1.0f ) ); const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" ); const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" ); @@ -89,7 +89,7 @@ const char* const OPTION_CLIPBOARD("option-clipboard"); BaseHandle Create() { - return Toolkit::TextSelectionPopup::New(); + return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL ); } // Setup properties, signals and actions using the type-registry. @@ -112,14 +112,18 @@ DALI_TYPE_REGISTRATION_END() } // namespace -Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New() + +Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable, + TextSelectionPopupCallbackInterface* callbackInterface ) { - // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup(); + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface ); // Pass ownership to CustomActor handle Dali::Toolkit::TextSelectionPopup handle( *impl ); + impl->mEnabledButtons = buttonsToEnable; + // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... impl->Initialize(); @@ -165,37 +169,37 @@ void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( CLIPBOARD, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image ); break; } case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( CUT, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image ); break; } case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( COPY, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image ); break; } case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( PASTE, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image ); break; } case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( SELECT, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image ); break; } case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE: { ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - impl.SetButtonImage( SELECT_ALL, image ); + impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image ); break; } } // switch @@ -236,7 +240,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( CLIPBOARD ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) ); if( image ) { value = image.GetUrl(); @@ -245,7 +249,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( CUT ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) ); if( image ) { value = image.GetUrl(); @@ -254,7 +258,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( COPY ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) ); if( image ) { value = image.GetUrl(); @@ -263,7 +267,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( PASTE ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) ); if( image ) { value = image.GetUrl(); @@ -272,7 +276,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( SELECT ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) ); if( image ) { value = image.GetUrl(); @@ -281,7 +285,7 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I } case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE: { - ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( SELECT_ALL ) ); + ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) ); if( image ) { value = image.GetUrl(); @@ -298,6 +302,66 @@ void TextSelectionPopup::OnInitialize() CreatePopup(); } +bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT ); + } + + return true; +} + +bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY ); + } + + return true; +} + +bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE ); + } + + return true; +} + +bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT ); + } + + return true; +} + +bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL ); + } + + return true; +} + +bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button ) +{ + if( mCallbackInterface ) + { + mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD ); + } + + return true; +} + void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension ) { switch( settingToCustomise ) @@ -373,37 +437,37 @@ Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& set return Size::ZERO; } -void TextSelectionPopup::SetButtonImage( Buttons button, Dali::Image image ) +void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image ) { switch ( button ) { break; - case CLIPBOARD: + case Toolkit::TextSelectionPopup::CLIPBOARD: { mClipboardIconImage = image; } break; - case CUT : + case Toolkit::TextSelectionPopup::CUT : { mCutIconImage = image; } break; - case COPY : + case Toolkit::TextSelectionPopup::COPY : { mCopyIconImage = image; } break; - case PASTE : + case Toolkit::TextSelectionPopup::PASTE : { mPasteIconImage = image; } break; - case SELECT : + case Toolkit::TextSelectionPopup::SELECT : { mSelectIconImage = image; } break; - case SELECT_ALL : + case Toolkit::TextSelectionPopup::SELECT_ALL : { mSelectAllIconImage = image; } @@ -415,36 +479,36 @@ void TextSelectionPopup::SetButtonImage( Buttons button, Dali::Image image ) } // switch } -Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) +Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button ) { switch ( button ) { - case CLIPBOARD : + case Toolkit::TextSelectionPopup::CLIPBOARD : { return mClipboardIconImage; } break; - case CUT : + case Toolkit::TextSelectionPopup::CUT : { return mCutIconImage; } break; - case COPY : + case Toolkit::TextSelectionPopup::COPY : { return mCopyIconImage; } break; - case PASTE : + case Toolkit::TextSelectionPopup::PASTE : { return mPasteIconImage; } break; - case SELECT : + case Toolkit::TextSelectionPopup::SELECT : { return mSelectIconImage; } break; - case SELECT_ALL : + case Toolkit::TextSelectionPopup::SELECT_ALL : { return mSelectAllIconImage; } @@ -467,42 +531,47 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) { mCutIconImage = ResourceImage::New( OPTION_ICON_CUT ); } - mOrderListOfButtons.push_back( ButtonRequirement( CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, false ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) ); if ( !mCopyIconImage ) { mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY ); } - mOrderListOfButtons.push_back( ButtonRequirement( COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, false ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) ); if ( !mPasteIconImage ) { mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE ); } - mOrderListOfButtons.push_back( ButtonRequirement( PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, false ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) ); if ( !mSelectIconImage ) mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT ); - mOrderListOfButtons.push_back( ButtonRequirement( SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, true ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) ); if ( !mSelectAllIconImage ) { mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL ); } - mOrderListOfButtons.push_back( ButtonRequirement( SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, true ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) ); if ( !mClipboardIconImage ) { mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD ); } - mOrderListOfButtons.push_back( ButtonRequirement( CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, false ) ); + mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) ); // Sort the buttons according their priorities. std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() ); } - void TextSelectionPopup::AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption ) + void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption ) { + + const std::string& name = button.name; + const std::string& caption = button.caption; + Image iconImage = button.icon; + // 1. Create the backgrounds for the popup option both normal and pressed. // Both containers will be added to a button. @@ -515,7 +584,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) optionPressedContainer.SetDrawMode( DrawMode::OVERLAY ); optionPressedContainer.SetFitHeight( 0 ); optionPressedContainer.SetFitWidth( 0 ); - optionPressedContainer.SetBackgroundColor(Color::RED); //todo member variable + optionPressedContainer.SetBackgroundColor( mPressedColor ); #ifdef DECORATOR_DEBUG optionContainer.SetName("optionContainer"); @@ -536,7 +605,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) Padding padding; padding.left = 24.0f; padding.right = 24.0f; - padding.top = 13.0f; + padding.top = 14.0f; padding.bottom = 14.0f; captionTextLabel.SetPadding( padding ); pressedCaptionTextLabel.SetPadding( padding ); @@ -554,7 +623,6 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); icon.SetColor( mIconColor ); - pressedIcon.SetColor( mIconPressedColor ); if ( showCaption & showIcons ) { @@ -576,7 +644,45 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) option.SetName( name ); option.SetAnimationTime( 0.0f ); option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed ); + + switch( button.id ) + { + case Toolkit::TextSelectionPopup::CUT: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::COPY: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::PASTE: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::SELECT: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::SELECT_ALL: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::CLIPBOARD: + { + option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed ); + break; + } + case Toolkit::TextSelectionPopup::NONE: + { + // Nothing to do: + break; + } + } // 5. Set the normal option image. option.SetButtonImage( optionContainer ); @@ -626,7 +732,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) if ( button.enabled ) { numberOfOptionsAdded++; - AddOption( button.name, button.caption, button.icon, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions ); + AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions ); } } } @@ -648,15 +754,17 @@ Dali::Image TextSelectionPopup::GetButtonImage( Buttons button ) } } -TextSelectionPopup::TextSelectionPopup() +TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface ) : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mToolbar(), mMaxSize(), mMinSize(), mOptionDividerSize( Size( 2.0f, 0.0f) ), + mEnabledButtons( Toolkit::TextSelectionPopup::NONE ), + mCallbackInterface( callbackInterface ), mLineColor( DEFAULT_POPUP_LINE_COLOR ), mIconColor( DEFAULT_OPTION_ICON ), - mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ), + mPressedColor( DEFAULT_OPTION_ICON_PRESSED ), mSelectOptionPriority( 1 ), mSelectAllOptionPriority ( 2 ), mCutOptionPriority ( 3 ),