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