TextSelectionToolbar and Style Properties added
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-selection-popup-impl.cpp
1 /*
2  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
23 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
24 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/images/nine-patch-image.h>
28 #include <dali/public-api/images/resource-image.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/vector4.h>
31 #include <dali/devel-api/object/type-registry-helper.h>
32 #include <libintl.h>
33 #include <cfloat>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 namespace
45 {
46 // todo Move this to adaptor??
47 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
48
49 const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.69f, 0.93f, 0.93f, 1.0f ) );
50 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
51 const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.5f, 1.0f, 1.0f, 1.0f ) );
52
53 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
54 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
55 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
56 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
57 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
58 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
59 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
60
61 const float OPTION_MARGIN_WIDTH( 10.f );          ///< The margin between the right or lefts edge and the text or icon.
62
63 #ifdef DGETTEXT_ENABLED
64
65 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
66 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
67 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
68 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
69 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
70 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
71
72 #else
73
74 #define POPUP_CUT_STRING  "Cut"
75 #define POPUP_COPY_STRING  "Copy"
76 #define POPUP_PASTE_STRING  "Paste"
77 #define POPUP_SELECT_STRING  "Select"
78 #define POPUP_SELECT_ALL_STRING  "Select All"
79 #define POPUP_CLIPBOARD_STRING  "Clipboard"
80
81 #endif
82
83 const char* const OPTION_SELECT_WORD = "option-select_word";                       // "Select Word" popup option.
84 const char* const OPTION_SELECT_ALL("option-select_all");                          // "Select All" popup option.
85 const char* const OPTION_CUT("option-cut");                                        // "Cut" popup option.
86 const char* const OPTION_COPY("option-copy");                                      // "Copy" popup option.
87 const char* const OPTION_PASTE("option-paste");                                    // "Paste" popup option.
88 const char* const OPTION_CLIPBOARD("option-clipboard");                            // "Clipboard" popup option.
89
90 BaseHandle Create()
91 {
92   return Toolkit::TextSelectionPopup::New();
93 }
94
95 // Setup properties, signals and actions using the type-registry.
96
97 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
98
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2,   POPUP_MAX_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2,   POPUP_MIN_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2,   OPTION_MAX_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2,   OPTION_MIN_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2,   OPTION_DIVIDER_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
110
111 DALI_TYPE_REGISTRATION_END()
112
113 } // namespace
114
115 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
116 {
117   // Create the implementation, temporarily owned by this handle on stack
118   IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
119
120   // Pass ownership to CustomActor handle
121   Dali::Toolkit::TextSelectionPopup handle( *impl );
122
123   // Second-phase init of the implementation
124   // This can only be done after the CustomActor connection has been made...
125   impl->Initialize();
126
127   return handle;
128 }
129
130 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
131 {
132   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
133
134   if( selectionPopup )
135   {
136     TextSelectionPopup& impl( GetImpl( selectionPopup ) );
137
138     switch( index )
139     {
140       case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
141       {
142        impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
143        break;
144       }
145       case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE:
146       {
147         impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
148         break;
149       }
150       case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
151       {
152         impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
153         break;
154       }
155       case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
156       {
157         impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
158         break;
159       }
160       case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
161       {
162         impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
163         break;
164       }
165       case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
166       {
167         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
168         impl.SetButtonImage( CLIPBOARD, image );
169         break;
170       }
171       case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
172       {
173         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
174         impl.SetButtonImage( CUT, image );
175         break;
176       }
177       case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
178       {
179         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
180         impl.SetButtonImage( COPY, image );
181         break;
182       }
183       case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
184       {
185         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
186         impl.SetButtonImage( PASTE, image );
187         break;
188       }
189       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
190       {
191         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
192         impl.SetButtonImage( SELECT, image );
193         break;
194       }
195       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
196       {
197         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
198         impl.SetButtonImage( SELECT_ALL, image );
199         break;
200       }
201     } // switch
202   } // TextSelectionPopup
203 }
204
205 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
206 {
207   Property::Value value;
208
209   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
210
211   if( selectionPopup )
212   {
213     TextSelectionPopup& impl( GetImpl( selectionPopup ) );
214
215     switch( index )
216     {
217       case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
218       {
219         value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
220         break;
221       }
222       case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
223       {
224         value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
225         break;
226       }
227       case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
228       {
229         value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
230         break;
231       }
232       case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
233       {
234         value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
235         break;
236       }
237       case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
238       {
239         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( CLIPBOARD ) );
240         if( image )
241         {
242           value = image.GetUrl();
243         }
244         break;
245       }
246       case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
247       {
248         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( CUT ) );
249         if( image )
250         {
251           value = image.GetUrl();
252         }
253         break;
254       }
255       case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
256       {
257         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( COPY ) );
258         if( image )
259         {
260           value = image.GetUrl();
261         }
262         break;
263       }
264       case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
265       {
266         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( PASTE ) );
267         if( image )
268         {
269           value = image.GetUrl();
270         }
271         break;
272       }
273       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
274       {
275         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( SELECT ) );
276         if( image )
277         {
278           value = image.GetUrl();
279         }
280         break;
281       }
282       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
283       {
284         ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( SELECT_ALL ) );
285         if( image )
286         {
287           value = image.GetUrl();
288         }
289         break;
290       }
291     } // switch
292   }
293   return value;
294 }
295
296 void TextSelectionPopup::OnInitialize()
297 {
298   CreatePopup();
299 }
300
301 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
302 {
303   switch( settingToCustomise )
304   {
305     case POPUP_MAXIMUM_SIZE :
306     {
307       Actor self = Self();
308       mMaxSize = dimension;
309       if ( mToolbar )
310       {
311         mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
312       }
313       break;
314     }
315     case POPUP_MINIMUM_SIZE :
316     {
317       Actor self = Self();
318       mMinSize = dimension;
319       // Option can not be smaller than this if only one.
320       break;
321     }
322     case OPTION_MAXIMUM_SIZE :
323     {
324       mOptionMaxSize = dimension;
325       // Option max size not currently currently supported
326
327       break;
328     }
329     case OPTION_MINIMUM_SIZE :
330     {
331       mOptionMinSize = dimension;
332       // Option min size not currently currently supported
333       break;
334     }
335     case OPTION_DIVIDER_SIZE :
336     {
337       mOptionDividerSize = dimension;
338       if ( mToolbar )
339       {
340         // Resize Dividers not currently supported
341       }
342       break;
343     }
344   } // switch
345 }
346
347 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
348 {
349   switch( settingToCustomise )
350   {
351     case POPUP_MAXIMUM_SIZE :
352     {
353       return mMaxSize;
354     }
355     case POPUP_MINIMUM_SIZE :
356     {
357       return mMinSize;
358     }
359     case OPTION_MAXIMUM_SIZE :
360     {
361       return mOptionMaxSize;
362     }
363     case OPTION_MINIMUM_SIZE :
364     {
365       return mOptionMinSize;
366     }
367     case OPTION_DIVIDER_SIZE :
368     {
369       return mOptionDividerSize;
370     }
371   } // switch
372
373   return Size::ZERO;
374 }
375
376 void TextSelectionPopup::SetButtonImage( Buttons button, Dali::Image image )
377 {
378    switch ( button )
379    {
380    break;
381    case CLIPBOARD:
382    {
383      mClipboardIconImage  = image;
384    }
385    break;
386    case CUT :
387    {
388      mCutIconImage = image;
389    }
390    break;
391    case COPY :
392    {
393      mCopyIconImage = image;
394    }
395    break;
396    case PASTE :
397    {
398      mPasteIconImage = image;
399    }
400    break;
401    case SELECT :
402    {
403      mSelectIconImage = image;
404    }
405    break;
406    case SELECT_ALL :
407    {
408      mSelectAllIconImage = image;
409    }
410    break;
411    default :
412    {
413      DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
414    }
415    } // switch
416 }
417
418 Dali::Image TextSelectionPopup::GetButtonImage( Buttons button )
419 {
420   switch ( button )
421   {
422   case CLIPBOARD :
423   {
424     return mClipboardIconImage;
425   }
426   break;
427   case CUT :
428   {
429     return mCutIconImage;
430   }
431   break;
432   case COPY :
433   {
434     return mCopyIconImage;
435   }
436   break;
437   case PASTE :
438   {
439     return mPasteIconImage;
440   }
441   break;
442   case SELECT :
443   {
444     return mSelectIconImage;
445   }
446   break;
447   case SELECT_ALL :
448   {
449     return mSelectAllIconImage;
450   }
451   break;
452   default :
453   {
454     DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
455   }
456   } // switch
457
458   return Dali::Image();
459 }
460
461  void TextSelectionPopup::CreateOrderedListOfPopupOptions()
462  {
463    mOrderListOfButtons.clear();
464
465    // Create button for each possible option using Option priority
466    if ( !mCutIconImage )
467    {
468      mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
469    }
470    mOrderListOfButtons.push_back( ButtonRequirement( CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, false ) );
471
472    if ( !mCopyIconImage )
473    {
474      mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
475    }
476    mOrderListOfButtons.push_back( ButtonRequirement( COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, false ) );
477
478    if ( !mPasteIconImage )
479    {
480      mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
481    }
482    mOrderListOfButtons.push_back( ButtonRequirement( PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, false ) );
483
484    if ( !mSelectIconImage )
485    mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
486    mOrderListOfButtons.push_back( ButtonRequirement( SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, true ) );
487
488    if ( !mSelectAllIconImage )
489    {
490     mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
491    }
492    mOrderListOfButtons.push_back( ButtonRequirement( SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, true ) );
493
494    if ( !mClipboardIconImage )
495    {
496      mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
497    }
498    mOrderListOfButtons.push_back( ButtonRequirement( CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, false ) );
499
500    // Sort the buttons according their priorities.
501    std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
502  }
503
504  void TextSelectionPopup::AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption  )
505  {
506    // 1. Create the backgrounds for the popup option both normal and pressed.
507    // Both containers will be added to a button.
508
509    Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
510    optionContainer.SetDrawMode( DrawMode::OVERLAY );
511    optionContainer.SetFitHeight( 0 );
512    optionContainer.SetFitWidth( 0 );
513
514    Toolkit::TableView  optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
515    optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
516    optionPressedContainer.SetFitHeight( 0 );
517    optionPressedContainer.SetFitWidth( 0 );
518    optionPressedContainer.SetBackgroundColor(Color::RED); //todo member variable
519
520 #ifdef DECORATOR_DEBUG
521    optionContainer.SetName("optionContainer");
522    optionPressedContainer.SetName("optionPressedContainer");
523 #endif
524    // 2. Add text.
525
526    if ( showCaption )
527    {
528      Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
529      captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
530      captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
531
532      Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
533      pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
534      pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
535
536      Padding padding;
537      padding.left = 24.0f;
538      padding.right = 24.0f;
539      padding.top = 13.0f;
540      padding.bottom = 14.0f;
541      captionTextLabel.SetPadding( padding );
542      pressedCaptionTextLabel.SetPadding( padding );
543
544      optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 )  );
545      optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
546    }
547
548    // 3. Create the icons
549    if ( showIcons )
550    {
551      ImageActor pressedIcon = ImageActor::New(  iconImage );
552      ImageActor icon = ImageActor::New(  iconImage );
553
554      icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
555      pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
556      icon.SetColor( mIconColor );
557      pressedIcon.SetColor( mIconPressedColor );
558
559      if ( showCaption & showIcons )
560      {
561        optionContainer.SetFitHeight( 1 );
562        optionContainer.SetFitWidth( 1 );
563        optionPressedContainer.SetFitHeight( 1 );
564        optionPressedContainer.SetFitWidth( 1 );
565      }
566
567      optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 )  );
568      optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 )  );
569
570      icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
571      pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
572    }
573
574    // 4. Create a option.
575    Toolkit::PushButton option = Toolkit::PushButton::New();
576    option.SetName( name );
577    option.SetAnimationTime( 0.0f );
578    option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
579    //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
580
581    // 5. Set the normal option image.
582    option.SetButtonImage( optionContainer );
583
584    // 6. Set the pressed option image
585    option.SetSelectedImage( optionPressedContainer );
586
587    // 7 Add option to tool bar
588    mToolbar.AddOption( option );
589
590    // 8. Add the divider
591    if( showDivider )
592    {
593      const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
594
595      ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
596      divider.SetSize( size );
597      divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
598      divider.SetColor( mLineColor );
599      mToolbar.AddDivider( divider );
600    }
601  }
602
603  std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
604  {
605    std::size_t numberOfOptions = 0u;
606    for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
607    {
608      const ButtonRequirement& button( *it );
609      if( button.enabled )
610      {
611        ++numberOfOptions;
612      }
613    }
614
615    return numberOfOptions;
616  }
617
618  void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
619  {
620    // Iterate list of buttons and add active ones to Toolbar
621    std::size_t numberOfOptionsRequired =  GetNumberOfEnabledOptions();
622    std::size_t numberOfOptionsAdded = 0u;
623    for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
624    {
625      const ButtonRequirement& button( *it );
626      if ( button.enabled )
627      {
628        numberOfOptionsAdded++;
629        AddOption(  button.name, button.caption, button.icon, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
630      }
631    }
632  }
633
634  void TextSelectionPopup::CreatePopup()
635  {
636    Actor self = Self();
637    CreateOrderedListOfPopupOptions();  //todo Currently causes all options to be shown
638    self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
639    SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
640
641    if ( !mToolbar )
642    {
643      mToolbar = Toolkit::TextSelectionToolbar::New();
644      mToolbar.SetParentOrigin( ParentOrigin::CENTER );
645      mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
646      self.Add( mToolbar );
647      AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
648    }
649  }
650
651 TextSelectionPopup::TextSelectionPopup()
652 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
653   mToolbar(),
654   mMaxSize(),
655   mMinSize(),
656   mOptionDividerSize( Size( 2.0f, 0.0f) ),
657   mLineColor( DEFAULT_POPUP_LINE_COLOR ),
658   mIconColor( DEFAULT_OPTION_ICON ),
659   mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
660   mSelectOptionPriority( 1 ),
661   mSelectAllOptionPriority ( 2 ),
662   mCutOptionPriority ( 3 ),
663   mCopyOptionPriority ( 4 ),
664   mPasteOptionPriority ( 5 ),
665   mClipboardOptionPriority( 6 ),
666   mShowIcons( false ),
667   mShowCaptions( true )
668 {
669 }
670
671 TextSelectionPopup::~TextSelectionPopup()
672 {
673 }
674
675
676 } // namespace Internal
677
678 } // namespace Toolkit
679
680 } // namespace Dali
681
682