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/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 std::string 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 std::string IDS_LTR("IDS_LTR");
97 const std::string 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 DevelControl::ControlAccessible* TextSelectionPopup::CreateAccessibleObject()
286 return new TextSelectionPopupAccessible(Self());
289 Dali::Accessibility::States TextSelectionPopup::TextSelectionPopupAccessible::CalculateStates()
291 auto states = ControlAccessible::CalculateStates();
293 states[Dali::Accessibility::State::MODAL] = true;
298 void TextSelectionPopup::HideAnimationFinished(Animation& animation)
301 if(!mPopupShowing) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
303 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n");
304 UnparentAndReset(mToolbar);
308 bool TextSelectionPopup::OnCutButtonPressed(Toolkit::Button button)
310 if(mCallbackInterface)
312 mCallbackInterface->TextPopupButtonTouched(Toolkit::TextSelectionPopup::CUT);
318 bool TextSelectionPopup::OnCopyButtonPressed(Toolkit::Button button)
320 if(mCallbackInterface)
322 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::COPY);
328 bool TextSelectionPopup::OnPasteButtonPressed(Toolkit::Button button)
330 if(mCallbackInterface)
332 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::PASTE);
338 bool TextSelectionPopup::OnSelectButtonPressed(Toolkit::Button button)
340 if(mCallbackInterface)
342 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT);
348 bool TextSelectionPopup::OnSelectAllButtonPressed(Toolkit::Button button)
350 if(mCallbackInterface)
352 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT_ALL);
358 bool TextSelectionPopup::OnClipboardButtonPressed(Toolkit::Button button)
360 if(mCallbackInterface)
362 mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::CLIPBOARD);
368 void TextSelectionPopup::SetDimensionToCustomise(const PopupCustomisations& settingToCustomise, const Size& dimension)
370 switch(settingToCustomise)
372 case POPUP_MAXIMUM_SIZE:
374 mPopupMaxSize = dimension;
377 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension);
381 case OPTION_MAXIMUM_SIZE:
383 mOptionMaxSize = dimension;
384 // Option max size not currently currently supported
387 case OPTION_MINIMUM_SIZE:
389 mOptionMinSize = dimension;
390 // Option min size not currently currently supported
393 case OPTION_DIVIDER_SIZE:
395 mOptionDividerSize = dimension;
398 // Resize Dividers not currently supported
405 Size TextSelectionPopup::GetDimensionToCustomise(const PopupCustomisations& settingToCustomise) const
407 switch(settingToCustomise)
409 case POPUP_MAXIMUM_SIZE:
413 return mToolbar.GetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE).Get<Vector2>();
417 return mPopupMaxSize;
420 case OPTION_MAXIMUM_SIZE:
422 return mOptionMaxSize;
424 case OPTION_MINIMUM_SIZE:
426 return mOptionMinSize;
428 case OPTION_DIVIDER_SIZE:
430 return mOptionDividerSize;
437 void TextSelectionPopup::SetButtonImage(Toolkit::TextSelectionPopup::Buttons button, const std::string& image)
441 case Toolkit::TextSelectionPopup::CLIPBOARD:
443 mClipboardIconImage = image;
446 case Toolkit::TextSelectionPopup::CUT:
448 mCutIconImage = image;
451 case Toolkit::TextSelectionPopup::COPY:
453 mCopyIconImage = image;
456 case Toolkit::TextSelectionPopup::PASTE:
458 mPasteIconImage = image;
461 case Toolkit::TextSelectionPopup::SELECT:
463 mSelectIconImage = image;
466 case Toolkit::TextSelectionPopup::SELECT_ALL:
468 mSelectAllIconImage = image;
473 DALI_ASSERT_DEBUG("TextSelectionPopup SetPopupImage Unknown Button");
478 const std::string& TextSelectionPopup::GetButtonImage(Toolkit::TextSelectionPopup::Buttons button) const
482 case Toolkit::TextSelectionPopup::CLIPBOARD:
484 return mClipboardIconImage;
487 case Toolkit::TextSelectionPopup::CUT:
489 return mCutIconImage;
492 case Toolkit::TextSelectionPopup::COPY:
494 return mCopyIconImage;
497 case Toolkit::TextSelectionPopup::PASTE:
499 return mPasteIconImage;
502 case Toolkit::TextSelectionPopup::SELECT:
504 return mSelectIconImage;
507 case Toolkit::TextSelectionPopup::SELECT_ALL:
509 return mSelectAllIconImage;
512 case Toolkit::TextSelectionPopup::NONE:
518 DALI_ASSERT_DEBUG("TextSelectionPopup GetPopupImage Unknown Button");
519 static std::string empty;
523 void TextSelectionPopup::SetPressedImage(const std::string& filename)
525 mPressedImage = filename;
528 std::string TextSelectionPopup::GetPressedImage() const
530 return mPressedImage;
533 void TextSelectionPopup::SetOptionDividerPadding(const Padding& padding)
535 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetOptionDividerPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
536 mOptionDividerPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
539 Padding TextSelectionPopup::GetOptionDividerPadding() const
541 return mOptionDividerPadding;
544 void TextSelectionPopup::SetLabelPadding(const Padding& padding)
546 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
547 mLabelPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
550 Padding TextSelectionPopup::GetLabelPadding() const
552 return mLabelPadding;
555 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
557 mOrderListOfButtons.clear();
558 mOrderListOfButtons.reserve(8u);
560 // Create button for each possible option using Option priority
561 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CUT)));
562 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::COPY)));
563 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::PASTE)));
564 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT)));
565 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL)));
566 mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD)));
568 // Sort the buttons according their priorities.
569 std::sort(mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare());
572 void TextSelectionPopup::AddOption(const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption)
574 // 1. Create a option.
575 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n");
577 Toolkit::PushButton option = Toolkit::PushButton::New();
578 option.SetProperty(Dali::Actor::Property::NAME, button.name);
579 option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
580 option.SetProperty(Actor::Property::MINIMUM_SIZE, mLabelMinimumSize);
584 case Toolkit::TextSelectionPopup::CUT:
586 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCutButtonPressed);
589 case Toolkit::TextSelectionPopup::COPY:
591 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCopyButtonPressed);
594 case Toolkit::TextSelectionPopup::PASTE:
596 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnPasteButtonPressed);
599 case Toolkit::TextSelectionPopup::SELECT:
601 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectButtonPressed);
604 case Toolkit::TextSelectionPopup::SELECT_ALL:
606 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectAllButtonPressed);
609 case Toolkit::TextSelectionPopup::CLIPBOARD:
611 option.ClickedSignal().Connect(this, &TextSelectionPopup::OnClipboardButtonPressed);
614 case Toolkit::TextSelectionPopup::NONE:
621 // 2. Set the options contents.
624 // PushButton layout properties.
625 const Padding padding(mLabelPadding);
626 option.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, padding);
629 Property::Map buttonLabelProperties;
630 buttonLabelProperties.Insert(Toolkit::TextVisual::Property::TEXT, button.caption);
631 buttonLabelProperties.Merge(mLabelTextVisual);
633 option.SetProperty(Toolkit::Button::Property::LABEL, buttonLabelProperties);
637 option.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
638 option.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM");
640 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
641 //option.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
642 //option.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
645 // 3. Set the normal option image (blank / Transparent).
646 option.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "");
648 // 4. Set the pressed option image.
649 Property::Value selectedBackgroundValue(mPressedImage);
650 if(mPressedImage.empty())
652 // The image can be blank, the color can be used in that case.
653 selectedBackgroundValue = Property::Value{{Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR},
654 {Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor},
655 {Toolkit::DevelVisual::Property::CORNER_RADIUS, mPressedCornerRadius},
656 {Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE}};
658 option.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue);
659 // The value set by user takes precedence over the theme value.
660 if(mLabelTextVisual.Count() == 0)
662 option.SetProperty(Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME);
665 // 5 Add option to tool bar
666 mToolbar.AddOption(option);
668 // 6. Add the divider
671 const Size size(mOptionDividerSize.width, 0.0f); // Height FILL_TO_PARENT
672 const Padding padding(mOptionDividerPadding);
674 Toolkit::Control divider = Toolkit::Control::New();
675 #ifdef DECORATOR_DEBUG
676 divider.SetProperty(Dali::Actor::Property::NAME, "Text's popup divider");
678 divider.SetProperty(Actor::Property::SIZE, size);
679 divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
680 divider.SetProperty(Actor::Property::PADDING, padding);
681 divider.SetBackgroundColor(mDividerColor);
682 mToolbar.AddDivider(divider);
686 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
688 std::size_t numberOfOptions = 0u;
689 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
691 const ButtonRequirement& button(*it);
698 return numberOfOptions;
701 void TextSelectionPopup::AddPopupOptionsToToolbar(bool showIcons, bool showCaptions)
703 DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n");
705 CreateOrderedListOfPopupOptions();
707 mButtonsChanged = false;
708 UnparentAndReset(mToolbar);
713 mToolbar = Toolkit::TextSelectionToolbar::New();
714 if(mPopupMaxSize != Vector2::ZERO) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
716 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize);
718 mToolbar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
719 #ifdef DECORATOR_DEBUG
720 mToolbar.SetProperty(Dali::Actor::Property::NAME, "TextSelectionToolbar");
722 mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::ENABLE_SCROLL_BAR, mEnableScrollBar);
726 // Whether to mirror the list of buttons (for right to left languages)
728 #if defined(__GLIBC__)
729 char* idsLtr = GET_LOCALE_TEXT(IDS_LTR.c_str());
732 mirror = (0 == strcmp(idsLtr, RTL_DIRECTION.c_str()));
736 std::reverse(mOrderListOfButtons.begin(), mOrderListOfButtons.end());
741 // Iterate list of buttons and add active ones to Toolbar
742 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
743 std::size_t numberOfOptionsAdded = 0u;
744 for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
746 const ButtonRequirement& button(*it);
749 numberOfOptionsAdded++;
750 AddOption(button, (numberOfOptionsAdded < numberOfOptionsRequired), showIcons, showCaptions);
756 mToolbar.ScrollTo(Vector2(mPopupMaxSize.x, 0.f));
760 void TextSelectionPopup::CreateBackgroundBorder(Property::Map& propertyMap)
762 // Removes previous image if necessary
763 DevelControl::UnregisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
765 if(!propertyMap.Empty())
767 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
771 DevelControl::RegisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT);
776 void TextSelectionPopup::CreateBackground(Property::Map& propertyMap)
778 // Removes previous image if necessary
779 DevelControl::UnregisterVisual(*this, Toolkit::Control::Property::BACKGROUND);
781 if(!propertyMap.Empty())
783 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
787 DevelControl::RegisterVisual(*this, Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND);
792 TextSelectionPopup::TextSelectionPopup(TextSelectionPopupCallbackInterface* callbackInterface)
793 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
798 mOptionDividerSize(),
799 mOptionDividerPadding(),
801 mLabelPadding(DEFAULT_LABEL_PADDING),
803 mEnableScrollBar(true),
804 mEnabledButtons(Toolkit::TextSelectionPopup::NONE),
805 mCallbackInterface(callbackInterface),
806 mPressedColor(DEFAULT_OPTION_PRESSED_COLOR),
807 mPressedCornerRadius(DEFAULT_OPTION_PRESSED_CORNER_RADIUS),
808 mDividerColor(Color::WHITE),
809 mIconColor(Color::WHITE),
810 mSelectOptionPriority(1),
811 mSelectAllOptionPriority(2),
812 mCutOptionPriority(4),
813 mCopyOptionPriority(3),
814 mPasteOptionPriority(5),
815 mClipboardOptionPriority(6),
816 mFadeInDuration(0.0f),
817 mFadeOutDuration(0.0f),
820 mPopupShowing(false),
821 mButtonsChanged(false)
825 TextSelectionPopup::~TextSelectionPopup()
829 } // namespace Internal
831 } // namespace Toolkit