2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
22 #if defined(__GLIBC__)
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/animation/animation.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/object/property-map.h>
30 #include <dali/public-api/object/type-registry-helper.h>
35 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
39 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
40 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
41 #include <dali-toolkit/internal/helpers/color-conversion.h>
42 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
43 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
44 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
45 #include <dali-toolkit/public-api/visuals/visual-properties.h>
55 #if defined(__GLIBC__)
56 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
59 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME("TextSelectionPopupButton");
60 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR(Dali::Vector4(0.24f, 0.72f, 0.8f, 1.0f));
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
66 #ifdef DGETTEXT_ENABLED
68 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
69 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
70 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
71 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
72 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
73 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
77 #define POPUP_CUT_STRING "Cut"
78 #define POPUP_COPY_STRING "Copy"
79 #define POPUP_PASTE_STRING "Paste"
80 #define POPUP_SELECT_STRING "Select"
81 #define POPUP_SELECT_ALL_STRING "Select All"
82 #define POPUP_CLIPBOARD_STRING "Clipboard"
86 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
87 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
88 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
89 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
90 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
91 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
93 const std::string IDS_LTR("IDS_LTR");
94 const std::string RTL_DIRECTION("RTL");
98 return Toolkit::TextSelectionPopup::New(NULL);
101 // Setup properties, signals and actions using the type-registry.
103 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextSelectionPopup, Toolkit::Control, Create);
105 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE)
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE)
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE)
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE)
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE)
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerPadding", VECTOR4, OPTION_DIVIDER_PADDING)
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE)
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE)
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE)
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE)
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE)
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE)
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR)
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR)
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR)
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE)
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION)
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION)
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER)
125 DALI_TYPE_REGISTRATION_END()
129 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New(TextSelectionPopupCallbackInterface* callbackInterface)
131 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n");
133 // Create the implementation, temporarily owned by this handle on stack
134 IntrusivePtr<TextSelectionPopup> impl = new TextSelectionPopup(callbackInterface);
136 // Pass ownership to CustomActor handle
137 Dali::Toolkit::TextSelectionPopup handle(*impl);
139 // Second-phase init of the implementation
140 // This can only be done after the CustomActor connection has been made...
146 void TextSelectionPopup::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
148 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
152 TextSelectionPopup& impl(GetImpl(selectionPopup));
156 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
158 impl.SetDimensionToCustomise(POPUP_MAXIMUM_SIZE, value.Get<Vector2>());
161 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
163 impl.SetDimensionToCustomise(OPTION_MAXIMUM_SIZE, value.Get<Vector2>());
166 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
168 impl.SetDimensionToCustomise(OPTION_MINIMUM_SIZE, value.Get<Vector2>());
171 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
173 impl.SetDimensionToCustomise(OPTION_DIVIDER_SIZE, value.Get<Vector2>());
176 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
178 Vector4 padding(value.Get<Vector4>());
179 impl.SetOptionDividerPadding(Padding(padding.x, padding.y, padding.z, padding.w));
182 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
184 impl.SetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD, value.Get<std::string>());
187 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
189 impl.SetButtonImage(Toolkit::TextSelectionPopup::CUT, value.Get<std::string>());
192 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
194 impl.SetButtonImage(Toolkit::TextSelectionPopup::COPY, value.Get<std::string>());
197 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
199 impl.SetButtonImage(Toolkit::TextSelectionPopup::PASTE, value.Get<std::string>());
202 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
204 impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT, value.Get<std::string>());
207 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
209 impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL, value.Get<std::string>());
212 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
214 impl.mDividerColor = value.Get<Vector4>();
217 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
219 impl.mIconColor = value.Get<Vector4>();
222 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
224 impl.mPressedColor = value.Get<Vector4>();
227 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
229 impl.SetPressedImage(value.Get<std::string>());
232 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
234 impl.mFadeInDuration = value.Get<float>();
237 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
239 impl.mFadeOutDuration = value.Get<float>();
242 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
244 Property::Map map = value.Get<Property::Map>();
245 impl.CreateBackgroundBorder(map);
249 } // TextSelectionPopup
252 Property::Value TextSelectionPopup::GetProperty(BaseObject* object, Property::Index index)
254 Property::Value value;
256 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
260 TextSelectionPopup& impl(GetImpl(selectionPopup));
264 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
266 value = impl.GetDimensionToCustomise(POPUP_MAXIMUM_SIZE);
269 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
271 value = impl.GetDimensionToCustomise(OPTION_MAXIMUM_SIZE);
274 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
276 value = impl.GetDimensionToCustomise(OPTION_MINIMUM_SIZE);
279 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
281 value = impl.GetDimensionToCustomise(OPTION_DIVIDER_SIZE);
284 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
286 Padding padding = impl.GetOptionDividerPadding();
287 value = Vector4(padding.left, padding.right, padding.top, padding.bottom);
290 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
292 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD);
295 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
297 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CUT);
300 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
302 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::COPY);
305 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
307 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::PASTE);
310 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
312 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT);
315 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
317 value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL);
320 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
322 value = impl.GetPressedImage();
325 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
327 value = impl.mFadeInDuration;
330 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
332 value = impl.mFadeOutDuration;
335 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
338 Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
341 visual.CreatePropertyMap(map);
351 void TextSelectionPopup::EnableButtons(Toolkit::TextSelectionPopup::Buttons buttonsToEnable)
353 mEnabledButtons = buttonsToEnable;
354 mButtonsChanged = true;
357 void TextSelectionPopup::RaiseAbove(Actor target)
361 mToolbar.RaiseAbove(target);
365 void TextSelectionPopup::ShowPopup()
367 if((!mPopupShowing || mButtonsChanged) &&
368 (Toolkit::TextSelectionPopup::NONE != mEnabledButtons))
371 AddPopupOptionsToToolbar(mShowIcons, mShowCaptions);
373 Animation animation = Animation::New(mFadeInDuration);
374 animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 1.0f);
376 mPopupShowing = true;
380 void TextSelectionPopup::HidePopup()
384 mPopupShowing = false;
386 Animation animation = Animation::New(mFadeOutDuration);
387 animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 0.0f);
388 animation.FinishedSignal().Connect(this, &TextSelectionPopup::HideAnimationFinished);
393 void TextSelectionPopup::OnInitialize()
395 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n");
397 self.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
398 self.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f);
400 DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
401 return std::make_unique<DevelControl::ControlAccessible>(actor, Dali::Accessibility::Role::DIALOG, true);
404 //Enable highightability
405 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
408 void TextSelectionPopup::HideAnimationFinished(Animation& animation)
411 if(!mPopupShowing) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
413 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n");
414 UnparentAndReset(mToolbar);
418 bool TextSelectionPopup::OnCutButtonPressed(Toolkit::Button button)
420 if(mCallbackInterface)
422 mCallbackInterface->TextPopupButtonTouched(Toolkit::TextSelectionPopup::CUT);
428 bool TextSelectionPopup::OnCopyButtonPressed(Toolkit::Button button)
430 if(mCallbackInterface)
432 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::COPY);
438 bool TextSelectionPopup::OnPasteButtonPressed(Toolkit::Button button)
440 if(mCallbackInterface)
442 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::PASTE);
448 bool TextSelectionPopup::OnSelectButtonPressed(Toolkit::Button button)
450 if(mCallbackInterface)
452 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT);
458 bool TextSelectionPopup::OnSelectAllButtonPressed(Toolkit::Button button)
460 if(mCallbackInterface)
462 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT_ALL);
468 bool TextSelectionPopup::OnClipboardButtonPressed(Toolkit::Button button)
470 if(mCallbackInterface)
472 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::CLIPBOARD);
478 void TextSelectionPopup::SetDimensionToCustomise(const PopupCustomisations& settingToCustomise, const Size& dimension)
480 switch(settingToCustomise)
482 case POPUP_MAXIMUM_SIZE:
484 mPopupMaxSize = dimension;
487 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension);
491 case OPTION_MAXIMUM_SIZE:
493 mOptionMaxSize = dimension;
494 // Option max size not currently currently supported
497 case OPTION_MINIMUM_SIZE:
499 mOptionMinSize = dimension;
500 // Option min size not currently currently supported
503 case OPTION_DIVIDER_SIZE:
505 mOptionDividerSize = dimension;
508 // Resize Dividers not currently supported
515 Size TextSelectionPopup::GetDimensionToCustomise(const PopupCustomisations& settingToCustomise) const
517 switch(settingToCustomise)
519 case POPUP_MAXIMUM_SIZE:
523 return mToolbar.GetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE).Get<Vector2>();
527 return mPopupMaxSize;
530 case OPTION_MAXIMUM_SIZE:
532 return mOptionMaxSize;
534 case OPTION_MINIMUM_SIZE:
536 return mOptionMinSize;
538 case OPTION_DIVIDER_SIZE:
540 return mOptionDividerSize;
547 void TextSelectionPopup::SetButtonImage(Toolkit::TextSelectionPopup::Buttons button, const std::string& image)
551 case Toolkit::TextSelectionPopup::CLIPBOARD:
553 mClipboardIconImage = image;
556 case Toolkit::TextSelectionPopup::CUT:
558 mCutIconImage = image;
561 case Toolkit::TextSelectionPopup::COPY:
563 mCopyIconImage = image;
566 case Toolkit::TextSelectionPopup::PASTE:
568 mPasteIconImage = image;
571 case Toolkit::TextSelectionPopup::SELECT:
573 mSelectIconImage = image;
576 case Toolkit::TextSelectionPopup::SELECT_ALL:
578 mSelectAllIconImage = image;
583 DALI_ASSERT_DEBUG("TextSelectionPopup SetPopupImage Unknown Button");
588 const std::string& TextSelectionPopup::GetButtonImage(Toolkit::TextSelectionPopup::Buttons button) const
592 case Toolkit::TextSelectionPopup::CLIPBOARD:
594 return mClipboardIconImage;
597 case Toolkit::TextSelectionPopup::CUT:
599 return mCutIconImage;
602 case Toolkit::TextSelectionPopup::COPY:
604 return mCopyIconImage;
607 case Toolkit::TextSelectionPopup::PASTE:
609 return mPasteIconImage;
612 case Toolkit::TextSelectionPopup::SELECT:
614 return mSelectIconImage;
617 case Toolkit::TextSelectionPopup::SELECT_ALL:
619 return mSelectAllIconImage;
622 case Toolkit::TextSelectionPopup::NONE:
628 DALI_ASSERT_DEBUG("TextSelectionPopup GetPopupImage Unknown Button");
629 static std::string empty;
633 void TextSelectionPopup::SetPressedImage(const std::string& filename)
635 mPressedImage = filename;
638 std::string TextSelectionPopup::GetPressedImage() const
640 return mPressedImage;
643 void TextSelectionPopup::SetOptionDividerPadding(const Padding& padding)
645 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetOptionDividerPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
646 mOptionDividerPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
649 Padding TextSelectionPopup::GetOptionDividerPadding() const
651 return mOptionDividerPadding;
654 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
656 mOrderListOfButtons.clear();
657 mOrderListOfButtons.reserve(8u);
659 // Create button for each possible option using Option priority
660 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CUT)));
661 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::COPY)));
662 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::PASTE)));
663 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT)));
664 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL)));
665 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD)));
667 // Sort the buttons according their priorities.
668 std::sort(mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare());
671 void TextSelectionPopup::AddOption(const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption)
673 // 1. Create a option.
674 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n");
676 Toolkit::PushButton option = Toolkit::PushButton::New();
677 option.SetProperty(Dali::Actor::Property::NAME, button.name);
678 option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
682 case Toolkit::TextSelectionPopup::CUT:
684 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCutButtonPressed);
687 case Toolkit::TextSelectionPopup::COPY:
689 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCopyButtonPressed);
692 case Toolkit::TextSelectionPopup::PASTE:
694 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnPasteButtonPressed);
697 case Toolkit::TextSelectionPopup::SELECT:
699 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectButtonPressed);
702 case Toolkit::TextSelectionPopup::SELECT_ALL:
704 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectAllButtonPressed);
707 case Toolkit::TextSelectionPopup::CLIPBOARD:
709 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnClipboardButtonPressed);
712 case Toolkit::TextSelectionPopup::NONE:
719 // 2. Set the options contents.
722 // PushButton layout properties.
723 option.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, Vector4(24.0f, 24.0f, 14.0f, 14.0f));
726 Property::Map buttonLabelProperties;
727 buttonLabelProperties.Insert(Toolkit::TextVisual::Property::TEXT, button.caption);
728 option.SetProperty(Toolkit::Button::Property::LABEL, buttonLabelProperties);
732 option.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
733 option.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM");
735 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
736 //option.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
737 //option.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
740 // 3. Set the normal option image (blank / Transparent).
741 option.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "");
743 // 4. Set the pressed option image.
744 Property::Value selectedBackgroundValue(mPressedImage);
745 if(mPressedImage.empty())
747 // The image can be blank, the color can be used in that case.
748 selectedBackgroundValue = Property::Value{{Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR},
749 {Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor}};
751 option.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue);
752 option.SetProperty(Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME);
754 // 5 Add option to tool bar
755 mToolbar.AddOption(option);
757 // 6. Add the divider
760 const Size size(mOptionDividerSize.width, 0.0f); // Height FILL_TO_PARENT
761 const Padding padding(mOptionDividerPadding);
763 Toolkit::Control divider = Toolkit::Control::New();
764 #ifdef DECORATOR_DEBUG
765 divider.SetProperty(Dali::Actor::Property::NAME, "Text's popup divider");
767 divider.SetProperty(Actor::Property::SIZE, size);
768 divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
769 divider.SetProperty(Actor::Property::PADDING, padding);
770 divider.SetBackgroundColor(mDividerColor);
771 mToolbar.AddDivider(divider);
775 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
777 std::size_t numberOfOptions = 0u;
778 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
780 const ButtonRequirement& button(*it);
787 return numberOfOptions;
790 void TextSelectionPopup::AddPopupOptionsToToolbar(bool showIcons, bool showCaptions)
792 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n");
794 CreateOrderedListOfPopupOptions();
796 mButtonsChanged = false;
797 UnparentAndReset(mToolbar);
802 mToolbar = Toolkit::TextSelectionToolbar::New();
803 if(mPopupMaxSize != Vector2::ZERO) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
805 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize);
807 mToolbar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
808 #ifdef DECORATOR_DEBUG
809 mToolbar.SetProperty(Dali::Actor::Property::NAME, "TextSelectionToolbar");
814 // Whether to mirror the list of buttons (for right to left languages)
816 #if defined(__GLIBC__)
817 char* idsLtr = GET_LOCALE_TEXT(IDS_LTR.c_str());
820 mirror = (0 == strcmp(idsLtr, RTL_DIRECTION.c_str()));
824 std::reverse(mOrderListOfButtons.begin(), mOrderListOfButtons.end());
829 // Iterate list of buttons and add active ones to Toolbar
830 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
831 std::size_t numberOfOptionsAdded = 0u;
832 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
834 const ButtonRequirement& button(*it);
837 numberOfOptionsAdded++;
838 AddOption(button, (numberOfOptionsAdded < numberOfOptionsRequired), showIcons, showCaptions);
844 mToolbar.ScrollTo(Vector2(mPopupMaxSize.x, 0.f));
848 void TextSelectionPopup::CreateBackgroundBorder(Property::Map& propertyMap)
850 // Removes previous image if necessary
851 DevelControl::UnregisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
853 if(!propertyMap.Empty())
855 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
859 DevelControl::RegisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT);
864 TextSelectionPopup::TextSelectionPopup(TextSelectionPopupCallbackInterface* callbackInterface)
865 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
870 mOptionDividerSize(),
871 mOptionDividerPadding(),
872 mEnabledButtons(Toolkit::TextSelectionPopup::NONE),
873 mCallbackInterface(callbackInterface),
874 mPressedColor(DEFAULT_OPTION_PRESSED_COLOR),
875 mDividerColor(Color::WHITE),
876 mIconColor(Color::WHITE),
877 mSelectOptionPriority(1),
878 mSelectAllOptionPriority(2),
879 mCutOptionPriority(4),
880 mCopyOptionPriority(3),
881 mPasteOptionPriority(5),
882 mClipboardOptionPriority(6),
883 mFadeInDuration(0.0f),
884 mFadeOutDuration(0.0f),
887 mPopupShowing(false),
888 mButtonsChanged(false)
892 TextSelectionPopup::~TextSelectionPopup()
896 } // namespace Internal
898 } // namespace Toolkit