Merge "DALi Version 2.1.23" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-selection-popup-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
20
21 // EXTERNAL INCLUDES
22 #if defined(__GLIBC__)
23 #include <libintl.h>
24 #endif
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>
31 #include <string.h>
32 #include <cfloat>
33
34 // INTERNAL INCLUDES
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/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>
47
48 namespace Dali
49 {
50 namespace Toolkit
51 {
52 namespace Internal
53 {
54 namespace
55 {
56 #if defined(__GLIBC__)
57 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
58 #endif
59
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
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
65 #endif
66
67 #ifdef DGETTEXT_ENABLED
68
69 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
70 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
71 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
72 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
73 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
74 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
75
76 #else
77
78 #define POPUP_CUT_STRING "Cut"
79 #define POPUP_COPY_STRING "Copy"
80 #define POPUP_PASTE_STRING "Paste"
81 #define POPUP_SELECT_STRING "Select"
82 #define POPUP_SELECT_ALL_STRING "Select All"
83 #define POPUP_CLIPBOARD_STRING "Clipboard"
84
85 #endif
86
87 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
88 const char* const OPTION_SELECT_ALL("option-select_all");    // "Select All" popup option.
89 const char* const OPTION_CUT("optionCut");                   // "Cut" popup option.
90 const char* const OPTION_COPY("optionCopy");                 // "Copy" popup option.
91 const char* const OPTION_PASTE("optionPaste");               // "Paste" popup option.
92 const char* const OPTION_CLIPBOARD("optionClipboard");       // "Clipboard" popup option.
93
94 const std::string IDS_LTR("IDS_LTR");
95 const std::string RTL_DIRECTION("RTL");
96
97 BaseHandle Create()
98 {
99   return Toolkit::TextSelectionPopup::New(NULL);
100 }
101
102 // Setup properties, signals and actions using the type-registry.
103
104 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextSelectionPopup, Toolkit::Control, Create);
105
106 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE)
107 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE)
108 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE)
109 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE)
110 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE)
111 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "optionDividerPadding", VECTOR4, OPTION_DIVIDER_PADDING)
112 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE)
113 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE)
114 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE)
115 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE)
116 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE)
117 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE)
118 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR)
119 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR)
120 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR)
121 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE)
122 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION)
123 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION)
124 DALI_PROPERTY_REGISTRATION(Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER)
125
126 DALI_TYPE_REGISTRATION_END()
127
128 } // namespace
129
130 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New(TextSelectionPopupCallbackInterface* callbackInterface)
131 {
132   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n");
133
134   // Create the implementation, temporarily owned by this handle on stack
135   IntrusivePtr<TextSelectionPopup> impl = new TextSelectionPopup(callbackInterface);
136
137   // Pass ownership to CustomActor handle
138   Dali::Toolkit::TextSelectionPopup handle(*impl);
139
140   // Second-phase init of the implementation
141   // This can only be done after the CustomActor connection has been made...
142   impl->Initialize();
143
144   return handle;
145 }
146
147 void TextSelectionPopup::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
148 {
149   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
150
151   if(selectionPopup)
152   {
153     PropertyHandler::SetProperty(selectionPopup, index, value);
154   }
155 }
156
157 Property::Value TextSelectionPopup::GetProperty(BaseObject* object, Property::Index index)
158 {
159   Property::Value value;
160
161   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast(Dali::BaseHandle(object));
162
163   if(selectionPopup)
164   {
165     value = PropertyHandler::GetProperty(selectionPopup, index);
166   }
167   return value;
168 }
169
170 void TextSelectionPopup::EnableButtons(Toolkit::TextSelectionPopup::Buttons buttonsToEnable)
171 {
172   mEnabledButtons = buttonsToEnable;
173   mButtonsChanged = true;
174 }
175
176 void TextSelectionPopup::RaiseAbove(Actor target)
177 {
178   if(mToolbar)
179   {
180     mToolbar.RaiseAbove(target);
181   }
182 }
183
184 void TextSelectionPopup::ShowPopup()
185 {
186   if((!mPopupShowing || mButtonsChanged) &&
187      (Toolkit::TextSelectionPopup::NONE != mEnabledButtons))
188   {
189     Actor self = Self();
190     AddPopupOptionsToToolbar(mShowIcons, mShowCaptions);
191
192     Animation animation = Animation::New(mFadeInDuration);
193     animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 1.0f);
194     animation.Play();
195     mPopupShowing = true;
196   }
197 }
198
199 void TextSelectionPopup::HidePopup()
200 {
201   if(mPopupShowing)
202   {
203     mPopupShowing       = false;
204     Actor     self      = Self();
205     Animation animation = Animation::New(mFadeOutDuration);
206     animation.AnimateTo(Property(self, Actor::Property::COLOR_ALPHA), 0.0f);
207     animation.FinishedSignal().Connect(this, &TextSelectionPopup::HideAnimationFinished);
208     animation.Play();
209   }
210 }
211
212 void TextSelectionPopup::OnInitialize()
213 {
214   DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n");
215   Actor self = Self();
216   self.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
217   self.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f);
218
219   // Accessibility
220   self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
221   self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::DIALOG);
222 }
223
224 DevelControl::ControlAccessible* TextSelectionPopup::CreateAccessibleObject()
225 {
226   return new TextSelectionPopupAccessible(Self());
227 }
228
229 Dali::Accessibility::States TextSelectionPopup::TextSelectionPopupAccessible::CalculateStates()
230 {
231   auto states = ControlAccessible::CalculateStates();
232
233   states[Dali::Accessibility::State::MODAL] = true;
234
235   return states;
236 }
237
238 void TextSelectionPopup::HideAnimationFinished(Animation& animation)
239 {
240   Actor self = Self();
241   if(!mPopupShowing) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
242   {
243     DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n");
244     UnparentAndReset(mToolbar);
245   }
246 }
247
248 bool TextSelectionPopup::OnCutButtonPressed(Toolkit::Button button)
249 {
250   if(mCallbackInterface)
251   {
252     mCallbackInterface->TextPopupButtonTouched(Toolkit::TextSelectionPopup::CUT);
253   }
254
255   return true;
256 }
257
258 bool TextSelectionPopup::OnCopyButtonPressed(Toolkit::Button button)
259 {
260   if(mCallbackInterface)
261   {
262     mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::COPY);
263   }
264
265   return true;
266 }
267
268 bool TextSelectionPopup::OnPasteButtonPressed(Toolkit::Button button)
269 {
270   if(mCallbackInterface)
271   {
272     mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::PASTE);
273   }
274
275   return true;
276 }
277
278 bool TextSelectionPopup::OnSelectButtonPressed(Toolkit::Button button)
279 {
280   if(mCallbackInterface)
281   {
282     mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT);
283   }
284
285   return true;
286 }
287
288 bool TextSelectionPopup::OnSelectAllButtonPressed(Toolkit::Button button)
289 {
290   if(mCallbackInterface)
291   {
292     mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::SELECT_ALL);
293   }
294
295   return true;
296 }
297
298 bool TextSelectionPopup::OnClipboardButtonPressed(Toolkit::Button button)
299 {
300   if(mCallbackInterface)
301   {
302     mCallbackInterface->TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::CLIPBOARD);
303   }
304
305   return true;
306 }
307
308 void TextSelectionPopup::SetDimensionToCustomise(const PopupCustomisations& settingToCustomise, const Size& dimension)
309 {
310   switch(settingToCustomise)
311   {
312     case POPUP_MAXIMUM_SIZE:
313     {
314       mPopupMaxSize = dimension;
315       if(mToolbar)
316       {
317         mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension);
318       }
319       break;
320     }
321     case OPTION_MAXIMUM_SIZE:
322     {
323       mOptionMaxSize = dimension;
324       // Option max size not currently currently supported
325       break;
326     }
327     case OPTION_MINIMUM_SIZE:
328     {
329       mOptionMinSize = dimension;
330       // Option min size not currently currently supported
331       break;
332     }
333     case OPTION_DIVIDER_SIZE:
334     {
335       mOptionDividerSize = dimension;
336       if(mToolbar)
337       {
338         // Resize Dividers not currently supported
339       }
340       break;
341     }
342   } // switch
343 }
344
345 Size TextSelectionPopup::GetDimensionToCustomise(const PopupCustomisations& settingToCustomise) const
346 {
347   switch(settingToCustomise)
348   {
349     case POPUP_MAXIMUM_SIZE:
350     {
351       if(mToolbar)
352       {
353         return mToolbar.GetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE).Get<Vector2>();
354       }
355       else
356       {
357         return mPopupMaxSize;
358       }
359     }
360     case OPTION_MAXIMUM_SIZE:
361     {
362       return mOptionMaxSize;
363     }
364     case OPTION_MINIMUM_SIZE:
365     {
366       return mOptionMinSize;
367     }
368     case OPTION_DIVIDER_SIZE:
369     {
370       return mOptionDividerSize;
371     }
372   } // switch
373
374   return Size::ZERO;
375 }
376
377 void TextSelectionPopup::SetButtonImage(Toolkit::TextSelectionPopup::Buttons button, const std::string& image)
378 {
379   switch(button)
380   {
381     case Toolkit::TextSelectionPopup::CLIPBOARD:
382     {
383       mClipboardIconImage = image;
384       break;
385     }
386     case Toolkit::TextSelectionPopup::CUT:
387     {
388       mCutIconImage = image;
389       break;
390     }
391     case Toolkit::TextSelectionPopup::COPY:
392     {
393       mCopyIconImage = image;
394       break;
395     }
396     case Toolkit::TextSelectionPopup::PASTE:
397     {
398       mPasteIconImage = image;
399       break;
400     }
401     case Toolkit::TextSelectionPopup::SELECT:
402     {
403       mSelectIconImage = image;
404       break;
405     }
406     case Toolkit::TextSelectionPopup::SELECT_ALL:
407     {
408       mSelectAllIconImage = image;
409       break;
410     }
411     default:
412     {
413       DALI_ASSERT_DEBUG("TextSelectionPopup SetPopupImage Unknown Button");
414     }
415   } // switch
416 }
417
418 const std::string& TextSelectionPopup::GetButtonImage(Toolkit::TextSelectionPopup::Buttons button) const
419 {
420   switch(button)
421   {
422     case Toolkit::TextSelectionPopup::CLIPBOARD:
423     {
424       return mClipboardIconImage;
425       break;
426     }
427     case Toolkit::TextSelectionPopup::CUT:
428     {
429       return mCutIconImage;
430       break;
431     }
432     case Toolkit::TextSelectionPopup::COPY:
433     {
434       return mCopyIconImage;
435       break;
436     }
437     case Toolkit::TextSelectionPopup::PASTE:
438     {
439       return mPasteIconImage;
440       break;
441     }
442     case Toolkit::TextSelectionPopup::SELECT:
443     {
444       return mSelectIconImage;
445       break;
446     }
447     case Toolkit::TextSelectionPopup::SELECT_ALL:
448     {
449       return mSelectAllIconImage;
450       break;
451     }
452     case Toolkit::TextSelectionPopup::NONE:
453     {
454       break;
455     }
456   } // switch
457
458   DALI_ASSERT_DEBUG("TextSelectionPopup GetPopupImage Unknown Button");
459   static std::string empty;
460   return empty;
461 }
462
463 void TextSelectionPopup::SetPressedImage(const std::string& filename)
464 {
465   mPressedImage = filename;
466 }
467
468 std::string TextSelectionPopup::GetPressedImage() const
469 {
470   return mPressedImage;
471 }
472
473 void TextSelectionPopup::SetOptionDividerPadding(const Padding& padding)
474 {
475   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextSelectionPopup::SetOptionDividerPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.top, padding.bottom);
476   mOptionDividerPadding = Padding(padding.left, padding.right, padding.top, padding.bottom);
477 }
478
479 Padding TextSelectionPopup::GetOptionDividerPadding() const
480 {
481   return mOptionDividerPadding;
482 }
483
484 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
485 {
486   mOrderListOfButtons.clear();
487   mOrderListOfButtons.reserve(8u);
488
489   // Create button for each possible option using Option priority
490   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CUT)));
491   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::COPY)));
492   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::PASTE)));
493   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT)));
494   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL)));
495   mOrderListOfButtons.push_back(ButtonRequirement(Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != (mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD)));
496
497   // Sort the buttons according their priorities.
498   std::sort(mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare());
499 }
500
501 void TextSelectionPopup::AddOption(const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption)
502 {
503   // 1. Create a option.
504   DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n");
505
506   Toolkit::PushButton option = Toolkit::PushButton::New();
507   option.SetProperty(Dali::Actor::Property::NAME, button.name);
508   option.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
509
510   switch(button.id)
511   {
512     case Toolkit::TextSelectionPopup::CUT:
513     {
514       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCutButtonPressed);
515       break;
516     }
517     case Toolkit::TextSelectionPopup::COPY:
518     {
519       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnCopyButtonPressed);
520       break;
521     }
522     case Toolkit::TextSelectionPopup::PASTE:
523     {
524       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnPasteButtonPressed);
525       break;
526     }
527     case Toolkit::TextSelectionPopup::SELECT:
528     {
529       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectButtonPressed);
530       break;
531     }
532     case Toolkit::TextSelectionPopup::SELECT_ALL:
533     {
534       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnSelectAllButtonPressed);
535       break;
536     }
537     case Toolkit::TextSelectionPopup::CLIPBOARD:
538     {
539       option.ClickedSignal().Connect(this, &TextSelectionPopup::OnClipboardButtonPressed);
540       break;
541     }
542     case Toolkit::TextSelectionPopup::NONE:
543     {
544       // Nothing to do:
545       break;
546     }
547   }
548
549   // 2. Set the options contents.
550   if(showCaption)
551   {
552     // PushButton layout properties.
553     option.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, Vector4(24.0f, 24.0f, 14.0f, 14.0f));
554
555     // Label properties.
556     Property::Map buttonLabelProperties;
557     buttonLabelProperties.Insert(Toolkit::TextVisual::Property::TEXT, button.caption);
558     option.SetProperty(Toolkit::Button::Property::LABEL, buttonLabelProperties);
559   }
560   if(showIcons)
561   {
562     option.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
563     option.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM");
564
565     // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
566     //option.SetProperty(  Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
567     //option.SetProperty(  Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
568   }
569
570   // 3. Set the normal option image (blank / Transparent).
571   option.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "");
572
573   // 4. Set the pressed option image.
574   Property::Value selectedBackgroundValue(mPressedImage);
575   if(mPressedImage.empty())
576   {
577     // The image can be blank, the color can be used in that case.
578     selectedBackgroundValue = Property::Value{{Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR},
579                                               {Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor}};
580   }
581   option.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue);
582   option.SetProperty(Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME);
583
584   // 5 Add option to tool bar
585   mToolbar.AddOption(option);
586
587   // 6. Add the divider
588   if(showDivider)
589   {
590     const Size    size(mOptionDividerSize.width, 0.0f); // Height FILL_TO_PARENT
591     const Padding padding(mOptionDividerPadding);
592
593     Toolkit::Control divider = Toolkit::Control::New();
594 #ifdef DECORATOR_DEBUG
595     divider.SetProperty(Dali::Actor::Property::NAME, "Text's popup divider");
596 #endif
597     divider.SetProperty(Actor::Property::SIZE, size);
598     divider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
599     divider.SetProperty(Actor::Property::PADDING, padding);
600     divider.SetBackgroundColor(mDividerColor);
601     mToolbar.AddDivider(divider);
602   }
603 }
604
605 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
606 {
607   std::size_t numberOfOptions = 0u;
608   for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
609   {
610     const ButtonRequirement& button(*it);
611     if(button.enabled)
612     {
613       ++numberOfOptions;
614     }
615   }
616
617   return numberOfOptions;
618 }
619
620 void TextSelectionPopup::AddPopupOptionsToToolbar(bool showIcons, bool showCaptions)
621 {
622   DALI_LOG_INFO(gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n");
623
624   CreateOrderedListOfPopupOptions();
625
626   mButtonsChanged = false;
627   UnparentAndReset(mToolbar);
628
629   if(!mToolbar)
630   {
631     Actor self = Self();
632     mToolbar   = Toolkit::TextSelectionToolbar::New();
633     if(mPopupMaxSize != Vector2::ZERO) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
634     {
635       mToolbar.SetProperty(Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize);
636     }
637     mToolbar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
638 #ifdef DECORATOR_DEBUG
639     mToolbar.SetProperty(Dali::Actor::Property::NAME, "TextSelectionToolbar");
640 #endif
641     self.Add(mToolbar);
642   }
643
644   // Whether to mirror the list of buttons (for right to left languages)
645   bool mirror = false;
646 #if defined(__GLIBC__)
647   char* idsLtr = GET_LOCALE_TEXT(IDS_LTR.c_str());
648   if(NULL != idsLtr)
649   {
650     mirror = (0 == strcmp(idsLtr, RTL_DIRECTION.c_str()));
651
652     if(mirror)
653     {
654       std::reverse(mOrderListOfButtons.begin(), mOrderListOfButtons.end());
655     }
656   }
657 #endif
658
659   // Iterate list of buttons and add active ones to Toolbar
660   std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
661   std::size_t numberOfOptionsAdded    = 0u;
662   for(std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); (it != endIt); ++it)
663   {
664     const ButtonRequirement& button(*it);
665     if(button.enabled)
666     {
667       numberOfOptionsAdded++;
668       AddOption(button, (numberOfOptionsAdded < numberOfOptionsRequired), showIcons, showCaptions);
669     }
670   }
671
672   if(mirror)
673   {
674     mToolbar.ScrollTo(Vector2(mPopupMaxSize.x, 0.f));
675   }
676 }
677
678 void TextSelectionPopup::CreateBackgroundBorder(Property::Map& propertyMap)
679 {
680   // Removes previous image if necessary
681   DevelControl::UnregisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
682
683   if(!propertyMap.Empty())
684   {
685     Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap);
686
687     if(visual)
688     {
689       DevelControl::RegisterVisual(*this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT);
690     }
691   }
692 }
693
694 TextSelectionPopup::TextSelectionPopup(TextSelectionPopupCallbackInterface* callbackInterface)
695 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
696   mToolbar(),
697   mPopupMaxSize(),
698   mOptionMaxSize(),
699   mOptionMinSize(),
700   mOptionDividerSize(),
701   mOptionDividerPadding(),
702   mEnabledButtons(Toolkit::TextSelectionPopup::NONE),
703   mCallbackInterface(callbackInterface),
704   mPressedColor(DEFAULT_OPTION_PRESSED_COLOR),
705   mDividerColor(Color::WHITE),
706   mIconColor(Color::WHITE),
707   mSelectOptionPriority(1),
708   mSelectAllOptionPriority(2),
709   mCutOptionPriority(4),
710   mCopyOptionPriority(3),
711   mPasteOptionPriority(5),
712   mClipboardOptionPriority(6),
713   mFadeInDuration(0.0f),
714   mFadeOutDuration(0.0f),
715   mShowIcons(false),
716   mShowCaptions(true),
717   mPopupShowing(false),
718   mButtonsChanged(false)
719 {
720 }
721
722 TextSelectionPopup::~TextSelectionPopup()
723 {
724 }
725
726 } // namespace Internal
727
728 } // namespace Toolkit
729
730 } // namespace Dali