Merge "Fix to default Shadow Color setting" into tizen
[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 <libintl.h>
32 #include <cfloat>
33
34 // todo Move this to adaptor??
35 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
36
37 namespace Dali
38 {
39
40 namespace Toolkit
41 {
42
43 namespace Internal
44 {
45
46 namespace
47 {
48 const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
49 const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
50 const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) );
51 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
52 const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.5f, 1.0f, 1.0f, 1.0f ) );
53 const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
54 const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
55
56 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
57 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
58 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
59 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
60 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
61 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
62 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
63
64 const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 450.0f, 100.0f ); ///< The maximum size of the popup.
65
66 const Dali::Vector2 OPTION_ICON_SIZE( 65.0f, 65.0f );       ///< The size of the icon.
67 const float OPTION_MARGIN_WIDTH( 10.f );          ///< The margin between the right or lefts edge and the text or icon.
68 const float OPTION_MAX_WIDTH( 110.0f );          ///< The maximum width of the option   //todo Make Property
69 const float OPTION_MIN_WIDTH( 86.0f );           ///< The minimum width of the option. //todo Make Property
70 const float POPUP_DIVIDER_WIDTH( 3.f );        ///< The size of the divider.
71
72 const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail.
73 const float POPUP_TAIL_Y_OFFSET( 5.f );        ///< The y offset of the tail (when its position is on the bottom).
74 const float POPUP_TAIL_TOP_Y_OFFSET( 3.f );    ///< The y offset of the tail (when its position is on the top).
75
76 const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
77 const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
78
79 const char* const OPTION_SELECT_WORD = "option-select_word";                       // "Select Word" popup option.
80 const char* const OPTION_SELECT_ALL("option-select_all");                          // "Select All" popup option.
81 const char* const OPTION_CUT("option-cut");                                        // "Cut" popup option.
82 const char* const OPTION_COPY("option-copy");                                      // "Copy" popup option.
83 const char* const OPTION_PASTE("option-paste");                                    // "Paste" popup option.
84 const char* const OPTION_CLIPBOARD("option-clipboard");                            // "Clipboard" popup option.
85
86 } // namespace
87
88 //// Comparison function for ButtonRequirement Priority
89 //bool TextSelectionPopup::PriorityCompare( ButtonRequirement const& a, ButtonRequirement const& b )
90 //{
91 //  return a.priority < b.priority;
92 //}
93
94
95 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
96 {
97   // Create the implementation, temporarily owned by this handle on stack
98   IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
99
100   // Pass ownership to CustomActor handle
101   Dali::Toolkit::TextSelectionPopup handle( *impl );
102
103   // Second-phase init of the implementation
104   // This can only be done after the CustomActor connection has been made...
105   impl->Initialize();
106
107   return handle;
108 }
109
110 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
111 {
112   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
113
114   if( selectionPopup )
115   {
116     TextSelectionPopup& impl( GetImpl( selectionPopup ) );
117
118     switch( index )
119     {
120       case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
121       {
122        impl.SetPopupMaxSize( value.Get< Vector2 >() );
123        break;
124       }
125       case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
126       {
127         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
128         impl.SetPopupImage( POPUP_BACKGROUND, image );
129         break;
130       }
131       case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
132       {
133         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
134         impl.SetPopupImage( POPUP_CLIPBOARD_BUTTON, image );
135         break;
136       }
137       case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
138       {
139         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
140         impl.SetPopupImage( POPUP_CUT_BUTTON_ICON, image );
141         break;
142       }
143       case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
144       {
145         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
146         impl.SetPopupImage( POPUP_COPY_BUTTON_ICON, image );
147         break;
148       }
149       case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
150       {
151         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
152         impl.SetPopupImage( POPUP_PASTE_BUTTON_ICON, image );
153         break;
154       }
155       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
156       {
157         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
158         impl.SetPopupImage( POPUP_SELECT_BUTTON_ICON, image );
159         break;
160       }
161       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
162       {
163         ResourceImage image = ResourceImage::New( value.Get< std::string >() );
164         impl.SetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON, image );
165         break;
166       }
167     } // switch
168   } // TextSelectionPopup
169 }
170
171 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
172 {
173   Property::Value value;
174
175   Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
176
177   if( selectionPopup )
178   {
179     TextSelectionPopup& impl( GetImpl( selectionPopup ) );
180
181     switch( index )
182     {
183       case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
184       {
185         value = impl.GetPopupMaxSize();
186         break;
187       }
188       case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
189       {
190         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_BACKGROUND ) );
191         if( image )
192         {
193           value = image.GetUrl();
194         }
195         break;
196       }
197       case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
198       {
199         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CLIPBOARD_BUTTON ) );
200         if( image )
201         {
202           value = image.GetUrl();
203         }
204         break;
205       }
206       case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
207       {
208         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CUT_BUTTON_ICON ) );
209         if( image )
210         {
211           value = image.GetUrl();
212         }
213         break;
214       }
215       case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
216       {
217         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_COPY_BUTTON_ICON ) );
218         if( image )
219         {
220           value = image.GetUrl();
221         }
222         break;
223       }
224       case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
225       {
226         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_PASTE_BUTTON_ICON ) );
227         if( image )
228         {
229           value = image.GetUrl();
230         }
231         break;
232       }
233       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
234       {
235         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_BUTTON_ICON ) );
236         if( image )
237         {
238           value = image.GetUrl();
239         }
240         break;
241       }
242       case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
243       {
244         ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON ) );
245         if( image )
246         {
247           value = image.GetUrl();
248         }
249         break;
250       }
251     } // switch
252   }
253   return value;
254 }
255
256 void TextSelectionPopup::OnInitialize()
257 {
258   CreatePopup();
259 }
260
261 void TextSelectionPopup::OnRelayout( const Vector2& size, RelayoutContainer& container )
262 {
263
264 }
265
266 void TextSelectionPopup::SetPopupMaxSize( const Size& maxSize )
267 {
268   mMaxSize = maxSize;
269 }
270
271 const Dali::Vector2& TextSelectionPopup::GetPopupMaxSize() const
272 {
273   return mMaxSize;
274 }
275
276 void TextSelectionPopup::SetPopupImage( PopupParts part, Dali::Image image )
277 {
278    switch ( part )
279    {
280    case POPUP_BACKGROUND :
281    {
282      mBackgroundImage = image;
283    }
284    break;
285    case POPUP_CLIPBOARD_BUTTON :
286    {
287      mClipboardIconImage  = image;
288    }
289    break;
290    case POPUP_CUT_BUTTON_ICON :
291    {
292      mCutIconImage = image;
293    }
294    break;
295    case POPUP_COPY_BUTTON_ICON :
296    {
297      mCopyIconImage = image;
298    }
299    break;
300    case POPUP_PASTE_BUTTON_ICON :
301    {
302      mPasteIconImage = image;
303    }
304    break;
305    case POPUP_SELECT_BUTTON_ICON :
306    {
307      mSelectIconImage = image;
308    }
309    break;
310    case POPUP_SELECT_ALL_BUTTON_ICON :
311    {
312      mSelectAllIconImage = image;
313    }
314    break;
315
316    } // switch
317 }
318
319 Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part )
320 {
321   switch ( part )
322   {
323   case POPUP_BACKGROUND :
324   {
325     return mBackgroundImage;
326   }
327   break;
328   case POPUP_CLIPBOARD_BUTTON :
329   {
330     return mClipboardIconImage;
331   }
332   break;
333   case POPUP_CUT_BUTTON_ICON :
334   {
335     return mCutIconImage;
336   }
337   break;
338   case POPUP_COPY_BUTTON_ICON :
339   {
340     return mCopyIconImage;
341   }
342   break;
343   case POPUP_PASTE_BUTTON_ICON :
344   {
345     return mPasteIconImage;
346   }
347   break;
348   case POPUP_SELECT_BUTTON_ICON :
349   {
350     return mSelectIconImage;
351   }
352   break;
353   case POPUP_SELECT_ALL_BUTTON_ICON :
354   {
355     return mSelectAllIconImage;
356   }
357   break;
358   default :
359   {
360     DALI_ASSERT_DEBUG( "Unknown Popup Part" );
361   }
362   } // switch
363
364   return Dali::Image();
365 }
366
367  void TextSelectionPopup::CreateOrderedListOfPopupOptions()
368  {
369    mOrderListOfButtons.clear();
370
371    // Create button for each possible option using Option priority
372    if ( !mCutIconImage )
373    {
374      mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
375    }
376    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), mCutIconImage, true ) );
377
378    if ( !mCopyIconImage )
379    {
380      mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
381    }
382    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), mCopyIconImage, true ) );
383
384    if ( !mPasteIconImage )
385    {
386      mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
387    }
388    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), mPasteIconImage, true ) );
389
390    if ( !mSelectIconImage )
391    mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
392    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), mSelectIconImage, true ) );
393
394    if ( !mSelectAllIconImage )
395    {
396     mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
397    }
398    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), mSelectAllIconImage, true ) );
399
400    if ( !mClipboardIconImage )
401    {
402      mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
403    }
404    mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), mClipboardIconImage, true ) );
405
406    // Sort the buttons according their priorities.
407    std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
408  }
409
410  void TextSelectionPopup::CreateBackground()
411  {
412    if ( mBackgroundImage )
413    {
414      SetBackgroundImage (  mBackgroundImage );
415    }
416
417    SetBackgroundColor( mBackgroundColor );
418  }
419
420  void TextSelectionPopup::AddOption( Dali::Toolkit::TableView& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons, bool showCaption, std::size_t& indexInTable )
421  {
422    // 1. Create the backgrounds for the popup option both normal and pressed.
423    // Both containers will be added to a button.
424
425    Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons)?2:1 , 1 );
426    optionContainer.SetDrawMode( DrawMode::OVERLAY );
427    optionContainer.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
428    optionContainer.SetMinimumSize( Vector2( OPTION_MIN_WIDTH, 0 ) );
429    optionContainer.SetFitWidth( 0 );
430
431    Toolkit::TableView  optionPressedContainer = Toolkit::TableView::New( (showIcons)?2:1 , 1 );
432    optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
433    optionPressedContainer.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
434    optionPressedContainer.SetMinimumSize( Vector2( OPTION_MIN_WIDTH, 0 ) );
435    optionPressedContainer.SetFitWidth( 0 );
436 #ifdef DECORATOR_DEBUG
437    optionContainer.SetName("optionContainer");
438    optionPressedContainer.SetName("optionPressedContainer");
439 #endif
440    // 2. Add text.
441
442    if ( showCaption )
443    {
444    Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
445    captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
446    optionContainer.SetFitHeight( 0 );
447
448    Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
449    pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
450    optionPressedContainer.SetFitHeight( 0 );
451
452    captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
453    captionTextLabel.SetMaximumSize( Vector2( OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH , FLT_MAX ) ); //todo FLT_MAX Size negotiation feature needed
454
455    pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
456    pressedCaptionTextLabel.SetMaximumSize( Vector2( OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH , FLT_MAX) ); //todo FLT_MAX Size negotiation feature needed
457
458    optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition( 1, 0 )  ); // todo Labels need ellipsis or similar
459    optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition( 1, 0 )  ); // todo Labels need ellipsis or similar
460    }
461
462    if ( showIcons )
463    {
464      // 3. Create the icons
465      ImageActor pressedIcon = ImageActor::New(  iconImage );
466      ImageActor icon = ImageActor::New(  iconImage );
467      icon.SetName("image-icon-2014");
468      icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
469      pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
470      pressedIcon.SetColor( mIconPressedColor );
471      optionContainer.SetFitHeight( 0 );
472      optionPressedContainer.SetFitHeight( 0 );
473      optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 )  );
474      optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 )  );
475      icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
476      pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
477    }
478
479    // 5. Create a option.
480    Toolkit::PushButton option = Toolkit::PushButton::New();
481    option.SetName( name );
482    option.SetAnimationTime( 0.0f );
483    option.SetSize( OPTION_ICON_SIZE );
484    //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
485
486    // 6. Set the normal option image.
487    option.SetButtonImage( optionContainer );
488
489    // 7. Set the pressed option image
490    option.SetSelectedImage( optionPressedContainer );
491
492    // 9 Add option to table view
493    parent.SetFitWidth( indexInTable );
494    parent.AddChild( option, Toolkit::TableView::CellPosition( 0, indexInTable )  );
495    indexInTable++;
496
497    // 10. Add the divider
498    if( !finalOption )
499    {
500      const Size size( POPUP_DIVIDER_WIDTH, 0.0f ); // Height FILL_TO_PARENT
501
502      ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
503
504      divider.SetSize( size );
505      divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
506      parent.SetFitWidth( indexInTable );
507      parent.AddChild( divider, Toolkit::TableView::CellPosition( 0, indexInTable )  );
508      indexInTable++;
509    }
510  }
511
512  void TextSelectionPopup::SetUpPopup()
513  {
514    Actor self = Self();
515    self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
516
517    // Create Layer and Stencil.
518    mStencilLayer = Layer::New();
519    mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
520    mStencilLayer.SetParentOrigin( ParentOrigin::CENTER );
521
522    ImageActor stencil = CreateSolidColorActor( Color::RED );
523    stencil.SetDrawMode( DrawMode::STENCIL );
524    stencil.SetVisible( true );
525    stencil.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
526    stencil.SetParentOrigin( ParentOrigin::CENTER );
527
528    Actor scrollview = Actor::New(); //todo make a scrollview
529    scrollview.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
530    scrollview.SetParentOrigin( ParentOrigin::CENTER );
531
532    mTableOfButtons.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
533    mTableOfButtons.SetFitHeight( 0 );
534    mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER );
535
536    mStencilLayer.Add( stencil );
537    mStencilLayer.Add( scrollview );
538    scrollview.Add( mTableOfButtons );
539    self.Add( mStencilLayer );
540    //self.Add ( mTableOfButtons );
541  }
542
543  void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons, bool showCaptions )
544  {
545    mContentSize = Vector2::ZERO;
546
547    // Add the options into the buttons container.
548
549    // 1. Determine how many buttons are active and should be added to container.
550    std::size_t numberOfOptions = 0u;
551    for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
552    {
553      const ButtonRequirement& button( *it );
554      if( button.enabled )
555      {
556        ++numberOfOptions;
557      }
558    }
559
560    // 2. Iterate list of buttons and add active ones.
561    std::size_t optionsAdded = 0u;
562
563    numberOfOptions = ( numberOfOptions*2 ) - 1 ; // Last Option does not get a divider so -1 or if only one option then also no divider
564
565    mTableOfButtons = Dali::Toolkit::TableView::New( 1, numberOfOptions );
566
567    for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
568    {
569      const ButtonRequirement& button( *it );
570      if ( button.enabled )
571      {
572        AddOption( mTableOfButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions - 1, showIcons, showCaptions, optionsAdded ); // -1 to ignore the last divider
573      }
574    }
575  }
576
577  void TextSelectionPopup::CreatePopup()
578  {
579    if ( !mStencilLayer )
580    {
581      CreateOrderedListOfPopupOptions();  //todo Currently causes all options to be shown
582      CreateBackground();
583      AddPopupOptions( true, true, false );  // todo false so not to show Labels until ellipses or similar possible.
584      SetUpPopup();
585    }
586
587    mStencilLayer.RaiseToTop();
588  }
589
590 TextSelectionPopup::TextSelectionPopup()
591 : Control( ControlBehaviour( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) ),
592   mMaxSize ( DEFAULT_POPUP_MAX_SIZE ),
593   mVisiblePopUpSize( DEFAULT_POPUP_MAX_SIZE ),
594   mRequiredPopUpSize( DEFAULT_POPUP_MAX_SIZE ),
595   mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
596   mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
597   mLineColor( DEFAULT_POPUP_LINE_COLOR ),
598   mIconColor( DEFAULT_OPTION_ICON ),
599   mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
600   mTextColor( DEFAULT_OPTION_TEXT ),
601   mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
602   mSelectOptionPriority( 1 ),
603   mSelectAllOptionPriority ( 2 ),
604   mCutOptionPriority ( 3 ),
605   mCopyOptionPriority ( 4 ),
606   mPasteOptionPriority ( 5 ),
607   mClipboardOptionPriority( 6 ),
608   mShowIcons( true ),
609   mShowCaptions( false )
610 {
611 }
612
613 TextSelectionPopup::~TextSelectionPopup()
614 {
615 }
616
617
618 } // namespace Internal
619
620 } // namespace Toolkit
621
622 } // namespace Dali