2 * Copyright (c) 2024 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/type-registry-helper.h>
34 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/control-devel.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
38 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
39 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
40 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
41 #include <dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h>
42 #include <dali-toolkit/internal/helpers/color-conversion.h>
43 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
44 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
45 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
46 #include <dali-toolkit/public-api/visuals/visual-properties.h>
56 #if defined(__GLIBC__)
57 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
60 const char* TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME("TextSelectionPopupButton");
61 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR(Dali::Vector4(0.24f, 0.72f, 0.8f, 1.0f));
62 const float DEFAULT_OPTION_PRESSED_CORNER_RADIUS = 0.0f;
63 const Dali::Vector4 DEFAULT_LABEL_PADDING(Dali::Vector4(24.0f, 24.0f, 14.0f, 14.0f));
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
69 #ifdef DGETTEXT_ENABLED
71 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
72 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
73 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
74 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
75 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
76 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
80 #define POPUP_CUT_STRING "Cut"
81 #define POPUP_COPY_STRING "Copy"
82 #define POPUP_PASTE_STRING "Paste"
83 #define POPUP_SELECT_STRING "Select"
84 #define POPUP_SELECT_ALL_STRING "Select All"
85 #define POPUP_CLIPBOARD_STRING "Clipboard"
89 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
90 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
91 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
92 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
93 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
94 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
96 const char* IDS_LTR("IDS_LTR");
97 const char* RTL_DIRECTION("RTL");
101 return Toolkit::TextSelectionPopup::New(NULL);
104 // Setup properties, signals and actions using the type-registry.
106 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextSelectionPopup, Toolkit::Control, Create);
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE)
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE)
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE)
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE)
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE)
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerPadding", VECTOR4, OPTION_DIVIDER_PADDING)
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE)
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE)
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE)
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE)
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE)
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE)
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR)
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR)
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR)
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedCornerRadius", FLOAT, POPUP_PRESSED_CORNER_RADIUS)
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE)
125 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION)
126 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION)
127 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER)
128 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "background", MAP, BACKGROUND)
129 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "labelMinimumSize", VECTOR2, LABEL_MINIMUM_SIZE)
130 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "labelPadding", VECTOR4, LABEL_PADDING)
131 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "labelTextVisual", MAP, LABEL_TEXT_VISUAL)
132 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR)
134 DALI_TYPE_REGISTRATION_END()
138 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New(TextSelectionPopupCallbackInterface* callbackInterface)
140 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n");
142 // Create the implementation, temporarily owned by this handle on stack
143 IntrusivePtr<TextSelectionPopup> impl = new TextSelectionPopup(callbackInterface);
145 // Pass ownership to CustomActor handle
146 Dali::Toolkit::TextSelectionPopup handle(*impl);
148 // Second-phase init of the implementation
149 // This can only be done after the CustomActor connection has been made...
155 void TextSelectionPopup::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
157 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
161 PropertyHandler::SetProperty(selectionPopup, index, value);
165 Property::Value TextSelectionPopup::GetProperty(BaseObject* object, Property::Index index)
167 Property::Value value;
168 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
172 value = PropertyHandler::GetProperty(selectionPopup, index);
177 void TextSelectionPopup::SetProperties(const Property::Map& properties)
179 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Self());
183 const Property::Map::SizeType count = properties.Count();
184 for(Property::Map::SizeType position = 0; position < count; ++position)
186 KeyValuePair keyValue = properties.GetKeyValue(position);
187 Property::Key& key = keyValue.first;
188 Property::Value& value = keyValue.second;
189 PropertyHandler::SetProperty(selectionPopup, key.indexKey, value);
194 void TextSelectionPopup::GetProperties(Property::Map& properties)
198 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE, GetDimensionToCustomise(POPUP_MAXIMUM_SIZE));
199 map.Insert(Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, GetDimensionToCustomise(OPTION_DIVIDER_SIZE));
200 map.Insert(Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING, Vector4(mOptionDividerPadding.left, mOptionDividerPadding.right, mOptionDividerPadding.top, mOptionDividerPadding.bottom));
201 map.Insert(Toolkit::TextSelectionPopup::Property::LABEL_MINIMUM_SIZE, mLabelMinimumSize);
202 map.Insert(Toolkit::TextSelectionPopup::Property::LABEL_PADDING, Vector4(mLabelPadding.left, mLabelPadding.right, mLabelPadding.top, mLabelPadding.bottom));
203 map.Insert(Toolkit::TextSelectionPopup::Property::LABEL_TEXT_VISUAL, mLabelTextVisual);
204 map.Insert(Toolkit::TextSelectionPopup::Property::ENABLE_SCROLL_BAR, mEnableScrollBar);
205 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR, mDividerColor);
206 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION, mFadeInDuration);
207 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION, mFadeOutDuration);
208 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR, mPressedColor);
209 map.Insert(Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_CORNER_RADIUS, mPressedCornerRadius);
211 Property::Map backgroundMap;
212 Toolkit::Visual::Base backgroundVisual = DevelControl::GetVisual(*this, Toolkit::Control::Property::BACKGROUND);
215 backgroundVisual.CreatePropertyMap(backgroundMap);
217 map.Insert(Toolkit::TextSelectionPopup::Property::BACKGROUND, backgroundMap);
219 Property::Map borderMap;
220 Toolkit::Visual::Base borderVisual = DevelControl::GetVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
223 borderVisual.CreatePropertyMap(borderMap);
225 map.Insert(Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, borderMap);
230 void TextSelectionPopup::EnableButtons(Toolkit::TextSelectionPopup::Buttons buttonsToEnable)
232 mEnabledButtons = buttonsToEnable;
233 mButtonsChanged = true;
236 void TextSelectionPopup::RaiseAbove(Actor target)
240 mToolbar.RaiseAbove(target);
244 void TextSelectionPopup::ShowPopup()
246 if((!mPopupShowing || mButtonsChanged) &&
247 (Toolkit::TextSelectionPopup::NONE != mEnabledButtons))
250 AddPopupOptionsToToolbar(mShowIcons, mShowCaptions);
252 Animation animation = Animation::New(mFadeInDuration);
253 animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 1.0f);
255 mPopupShowing = true;
259 void TextSelectionPopup::HidePopup()
263 mPopupShowing = false;
265 Animation animation = Animation::New(mFadeOutDuration);
266 animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 0.0f);
267 animation.FinishedSignal().Connect(this, &TextSelectionPopup::HideAnimationFinished);
272 void TextSelectionPopup::OnInitialize()
274 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n");
276 self.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
277 self.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f);
280 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
281 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::DIALOG);
284 void TextSelectionPopup::HideAnimationFinished(Animation& animation)
287 if(!mPopupShowing) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
289 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n");
290 UnparentAndReset(mToolbar);
294 bool TextSelectionPopup::OnCutButtonPressed(Toolkit::Button button)
296 if(mCallbackInterface)
298 mCallbackInterface->TextPopupButtonTouched(Toolkit::TextSelectionPopup::CUT);
304 bool TextSelectionPopup::OnCopyButtonPressed(Toolkit::Button button)
306 if(mCallbackInterface)
308 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::COPY);
314 bool TextSelectionPopup::OnPasteButtonPressed(Toolkit::Button button)
316 if(mCallbackInterface)
318 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::PASTE);
324 bool TextSelectionPopup::OnSelectButtonPressed(Toolkit::Button button)
326 if(mCallbackInterface)
328 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT);
334 bool TextSelectionPopup::OnSelectAllButtonPressed(Toolkit::Button button)
336 if(mCallbackInterface)
338 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT_ALL);
344 bool TextSelectionPopup::OnClipboardButtonPressed(Toolkit::Button button)
346 if(mCallbackInterface)
348 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::CLIPBOARD);
354 void TextSelectionPopup::SetDimensionToCustomise(const PopupCustomisations& settingToCustomise, const Size& dimension)
356 switch(settingToCustomise)
358 case POPUP_MAXIMUM_SIZE:
360 mPopupMaxSize = dimension;
363 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension);
367 case OPTION_MAXIMUM_SIZE:
369 mOptionMaxSize = dimension;
370 // Option max size not currently currently supported
373 case OPTION_MINIMUM_SIZE:
375 mOptionMinSize = dimension;
376 // Option min size not currently currently supported
379 case OPTION_DIVIDER_SIZE:
381 mOptionDividerSize = dimension;
384 // Resize Dividers not currently supported
391 Size TextSelectionPopup::GetDimensionToCustomise(const PopupCustomisations& settingToCustomise) const
393 switch(settingToCustomise)
395 case POPUP_MAXIMUM_SIZE:
399 return mToolbar.GetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE).Get<Vector2>();
403 return mPopupMaxSize;
406 case OPTION_MAXIMUM_SIZE:
408 return mOptionMaxSize;
410 case OPTION_MINIMUM_SIZE:
412 return mOptionMinSize;
414 case OPTION_DIVIDER_SIZE:
416 return mOptionDividerSize;
423 void TextSelectionPopup::SetButtonImage(Toolkit::TextSelectionPopup::Buttons button, const std::string& image)
427 case Toolkit::TextSelectionPopup::CLIPBOARD:
429 mClipboardIconImage = image;
432 case Toolkit::TextSelectionPopup::CUT:
434 mCutIconImage = image;
437 case Toolkit::TextSelectionPopup::COPY:
439 mCopyIconImage = image;
442 case Toolkit::TextSelectionPopup::PASTE:
444 mPasteIconImage = image;
447 case Toolkit::TextSelectionPopup::SELECT:
449 mSelectIconImage = image;
452 case Toolkit::TextSelectionPopup::SELECT_ALL:
454 mSelectAllIconImage = image;
459 DALI_ASSERT_DEBUG("TextSelectionPopup SetPopupImage Unknown Button");
464 const std::string& TextSelectionPopup::GetButtonImage(Toolkit::TextSelectionPopup::Buttons button) const
468 case Toolkit::TextSelectionPopup::CLIPBOARD:
470 return mClipboardIconImage;
473 case Toolkit::TextSelectionPopup::CUT:
475 return mCutIconImage;
478 case Toolkit::TextSelectionPopup::COPY:
480 return mCopyIconImage;
483 case Toolkit::TextSelectionPopup::PASTE:
485 return mPasteIconImage;
488 case Toolkit::TextSelectionPopup::SELECT:
490 return mSelectIconImage;
493 case Toolkit::TextSelectionPopup::SELECT_ALL:
495 return mSelectAllIconImage;
498 case Toolkit::TextSelectionPopup::NONE:
504 DALI_ASSERT_DEBUG("TextSelectionPopup GetPopupImage Unknown Button");
505 static std::string empty;
509 void TextSelectionPopup::SetPressedImage(const std::string& filename)
511 mPressedImage = filename;
514 std::string TextSelectionPopup::GetPressedImage() const
516 return mPressedImage;
519 void TextSelectionPopup::SetOptionDividerPadding(const Padding& padding)
521 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetOptionDividerPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
522 mOptionDividerPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
525 Padding TextSelectionPopup::GetOptionDividerPadding() const
527 return mOptionDividerPadding;
530 void TextSelectionPopup::SetLabelPadding(const Padding& padding)
532 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
533 mLabelPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
536 Padding TextSelectionPopup::GetLabelPadding() const
538 return mLabelPadding;
541 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
543 mOrderListOfButtons.clear();
544 mOrderListOfButtons.reserve(8u);
546 // Create button for each possible option using Option priority
547 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CUT)));
548 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::COPY)));
549 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::PASTE)));
550 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT)));
551 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL)));
552 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD)));
554 // Sort the buttons according their priorities.
555 std::sort(mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare());
558 void TextSelectionPopup::AddOption(const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption)
560 // 1. Create a option.
561 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n");
563 Toolkit::PushButton option = Toolkit::PushButton::New();
564 option.SetProperty(Dali::Actor::Property::NAME, button.name);
565 option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
566 option.SetProperty(Actor::Property::MINIMUM_SIZE, mLabelMinimumSize);
570 case Toolkit::TextSelectionPopup::CUT:
572 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCutButtonPressed);
575 case Toolkit::TextSelectionPopup::COPY:
577 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCopyButtonPressed);
580 case Toolkit::TextSelectionPopup::PASTE:
582 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnPasteButtonPressed);
585 case Toolkit::TextSelectionPopup::SELECT:
587 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectButtonPressed);
590 case Toolkit::TextSelectionPopup::SELECT_ALL:
592 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectAllButtonPressed);
595 case Toolkit::TextSelectionPopup::CLIPBOARD:
597 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnClipboardButtonPressed);
600 case Toolkit::TextSelectionPopup::NONE:
607 // 2. Set the options contents.
610 // PushButton layout properties.
611 const Padding padding(mLabelPadding);
612 option.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, padding);
615 Property::Map buttonLabelProperties;
616 buttonLabelProperties.Insert(Toolkit::TextVisual::Property::TEXT, button.caption);
617 buttonLabelProperties.Merge(mLabelTextVisual);
619 option.SetProperty(Toolkit::Button::Property::LABEL, buttonLabelProperties);
623 option.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
624 option.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM");
626 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
627 //option.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
628 //option.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
631 // 3. Set the normal option image (blank / Transparent).
632 option.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "");
634 // 4. Set the pressed option image.
635 Property::Value selectedBackgroundValue(mPressedImage);
636 if(mPressedImage.empty())
638 // The image can be blank, the color can be used in that case.
639 selectedBackgroundValue = Property::Value{{Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR},
640 {Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor},
641 {Toolkit::DevelVisual::Property::CORNER_RADIUS, mPressedCornerRadius},
642 {Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE}};
644 option.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue);
645 // The value set by user takes precedence over the theme value.
646 if(mLabelTextVisual.Count() == 0)
648 option.SetProperty(Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME);
651 // 5 Add option to tool bar
652 mToolbar.AddOption(option);
654 // 6. Add the divider
657 const Size size(mOptionDividerSize.width, 0.0f); // Height FILL_TO_PARENT
658 const Padding padding(mOptionDividerPadding);
660 Toolkit::Control divider = Toolkit::Control::New();
661 #ifdef DECORATOR_DEBUG
662 divider.SetProperty(Dali::Actor::Property::NAME, "Text's popup divider");
664 divider.SetProperty(Actor::Property::SIZE, size);
665 divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
666 divider.SetProperty(Actor::Property::PADDING, padding);
667 divider.SetBackgroundColor(mDividerColor);
668 mToolbar.AddDivider(divider);
672 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
674 std::size_t numberOfOptions = 0u;
675 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
677 const ButtonRequirement& button(*it);
684 return numberOfOptions;
687 void TextSelectionPopup::AddPopupOptionsToToolbar(bool showIcons, bool showCaptions)
689 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n");
691 CreateOrderedListOfPopupOptions();
693 mButtonsChanged = false;
694 UnparentAndReset(mToolbar);
699 mToolbar = Toolkit::TextSelectionToolbar::New();
700 if(mPopupMaxSize != Vector2::ZERO) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
702 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize);
704 mToolbar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
705 #ifdef DECORATOR_DEBUG
706 mToolbar.SetProperty(Dali::Actor::Property::NAME, "TextSelectionToolbar");
708 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, mEnableScrollBar);
712 // Whether to mirror the list of buttons (for right to left languages)
714 #if defined(__GLIBC__)
715 char* idsLtr = GET_LOCALE_TEXT(IDS_LTR);
718 mirror = (0 == strcmp(idsLtr, RTL_DIRECTION));
722 std::reverse(mOrderListOfButtons.begin(), mOrderListOfButtons.end());
727 // Iterate list of buttons and add active ones to Toolbar
728 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
729 std::size_t numberOfOptionsAdded = 0u;
730 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
732 const ButtonRequirement& button(*it);
735 numberOfOptionsAdded++;
736 AddOption(button, (numberOfOptionsAdded < numberOfOptionsRequired), showIcons, showCaptions);
742 mToolbar.ScrollTo(Vector2(mPopupMaxSize.x, 0.f));
746 void TextSelectionPopup::CreateBackgroundBorder(Property::Map& propertyMap)
748 // Removes previous image if necessary
749 DevelControl::UnregisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
751 if(!propertyMap.Empty())
753 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
757 DevelControl::RegisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT);
762 void TextSelectionPopup::CreateBackground(Property::Map& propertyMap)
764 // Removes previous image if necessary
765 DevelControl::UnregisterVisual(*this, Toolkit::Control::Property::BACKGROUND);
767 if(!propertyMap.Empty())
769 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
773 DevelControl::RegisterVisual(*this, Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND);
778 TextSelectionPopup::TextSelectionPopup(TextSelectionPopupCallbackInterface* callbackInterface)
779 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
784 mOptionDividerSize(),
785 mOptionDividerPadding(),
787 mLabelPadding(DEFAULT_LABEL_PADDING),
789 mEnableScrollBar(true),
790 mEnabledButtons(Toolkit::TextSelectionPopup::NONE),
791 mCallbackInterface(callbackInterface),
792 mPressedColor(DEFAULT_OPTION_PRESSED_COLOR),
793 mPressedCornerRadius(DEFAULT_OPTION_PRESSED_CORNER_RADIUS),
794 mDividerColor(Color::WHITE),
795 mIconColor(Color::WHITE),
796 mSelectOptionPriority(1),
797 mSelectAllOptionPriority(2),
798 mCutOptionPriority(4),
799 mCopyOptionPriority(3),
800 mPasteOptionPriority(5),
801 mClipboardOptionPriority(6),
802 mFadeInDuration(0.0f),
803 mFadeOutDuration(0.0f),
806 mPopupShowing(false),
807 mButtonsChanged(false)
811 TextSelectionPopup::~TextSelectionPopup()
815 } // namespace Internal
817 } // namespace Toolkit