Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / popup / popup-example.cpp
1 /*
2  * Copyright (c) 2019 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 #include "shared/view.h"
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/popup/popup.h>
22
23 using namespace Dali;
24
25 using Dali::Toolkit::TextLabel;
26
27 struct ButtonItem
28 {
29   const char* name;
30   const char* text;
31 };
32
33 namespace
34 {
35
36 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
37 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
38
39 const char* const TOOLBAR_TITLE = "Popup";
40
41 const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png";
42 const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png";
43 const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png";
44 const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png";
45
46 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
47 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
48 const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2";
49 const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST";
50 const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS";
51 const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT";
52 const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE";
53 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT";
54 const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS";
55 const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID";
56 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
57 const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE";
58
59 // Names to give Popup PushButton controls.
60 const char* const POPUP_CONTROL_OK_NAME = "controlOk";
61 const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
62
63 const char* const CONTENT_TEXT = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
64 const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg";
65 const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg";
66
67 // Control area image.
68 const char*   DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
69
70 const ButtonItem POPUP_BUTTON_ITEMS[] = {
71     { POPUP_BUTTON_COMPLEX_ID,                     "Complex" },
72     { POPUP_BUTTON_TOAST_ID,                       "Toast Popup" },
73     { POPUP_BUTTON_TITLE_ID,                       "Title" },
74     { POPUP_BUTTON_BUTTONS_1_ID,                   "1 Button" },
75     { POPUP_BUTTON_BUTTONS_2_ID,                   "2 Buttons" },
76     { POPUP_BUTTON_FIXED_SIZE_ID,                  "Fixed Size" },
77     { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID,       "Title + Content + Buttons" },
78     { POPUP_BUTTON_CONTENT_TEXT_ID,                "Content Text" },
79     { POPUP_BUTTON_CONTENT_IMAGE_ID,               "Content Image" },
80     { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID,          "Title + Content" },
81     { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" },
82     { POPUP_BUTTON_CUSTOM_STYLE,                   "Custom Styled Popup" }
83 };
84
85 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
86
87 const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name
88 }  // anonymous namespace
89
90
91 /**
92  * This example shows the usage of the Popup class.
93  */
94 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
95 {
96 public:
97
98   PopupExample( Application& application )
99     : mApplication( application ),
100       mContextual( false ),
101       mAnimationFade( true )
102   {
103     // Connect to the Application's Init signal
104     mApplication.InitSignal().Connect( this, &PopupExample::Create );
105   }
106
107   ~PopupExample()
108   {
109     // Nothing to do here
110   }
111
112   void Create( Application& application )
113   {
114     // The Init signal is received once (only) during the Application lifetime
115     Stage stage = Stage::GetCurrent();
116
117     // Respond to key events if not handled
118     stage.KeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
119
120     // Creates a default view with a default tool bar.
121     // The view is added to the stage.
122     mContentLayer = DemoHelper::CreateView( application,
123                                             mView,
124                                             mToolBar,
125                                             BACKGROUND_IMAGE,
126                                             TOOLBAR_IMAGE,
127                                             std::string("") );
128
129     mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
130     mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
131
132     // Add title to the tool bar.
133     const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
134     mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
135
136     // Create animation button.
137     mAnimationButton = Toolkit::PushButton::New();
138     mAnimationButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE );
139     mAnimationButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE );
140     mAnimationButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
141     mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
142     mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
143
144     // Create context button.
145     mContextButton = Toolkit::PushButton::New();
146     mContextButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE );
147     mContextButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE );
148     mContextButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
149     mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
150     mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
151
152     // Add title to the tool bar.
153     mItemView = Toolkit::ItemView::New( *this );
154     mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
155     mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
156     mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
157
158     // Use a grid layout for tests
159     Vector2 stageSize = stage.GetSize();
160     Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
161     Vector3 itemSize;
162     gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
163     itemSize.height = stageSize.y / 10;
164     gridLayout->SetItemSize( itemSize );
165     mItemView.AddLayout( *gridLayout );
166
167     mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
168
169     mContentLayer.Add( mItemView );
170   }
171
172   bool OnContextClicked( Toolkit::Button button )
173   {
174     mContextual = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>();
175     return true;
176   }
177
178   bool OnAnimationClicked( Toolkit::Button button )
179   {
180     mAnimationFade = ! ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() );
181     return true;
182   }
183
184   /**
185    * This function is designed as a shortcut to convert any resize policies set for a popup to
186    * ones that will work for contextual mode (for demo purposes).
187    * Note that in a real-use case example the policies would be set to something appropriate
188    * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
189    * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
190    * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
191    * this function converts the old policies and size to new ones that would give the popup the
192    * same visual appearance.
193    * @param[in] popup The popup whose policies should be modified.
194    */
195   void SetupContextualResizePolicy( Toolkit::Popup& popup )
196   {
197     Vector2 stageSize = Stage::GetCurrent().GetSize();
198     // Some defaults when creating a new fixed size.
199     // This is NOT a Vector2 so we can modify each dimension in a for-loop.
200     float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
201     bool modifySize = false;
202
203     // Loop through each of two dimensions to process them.
204     for( unsigned int dimension = 0; dimension < 2; ++dimension )
205     {
206       float stageDimensionSize, sizeModeFactor;
207       Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
208
209       // Setup information related to the current dimension we are processing.
210       if( policyDimension == Dimension::WIDTH )
211       {
212         stageDimensionSize = stageSize.x;
213         sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).x;
214       }
215       else
216       {
217         stageDimensionSize = stageSize.y;
218         sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).y;
219       }
220
221       bool modifyPolicy = false;
222       ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
223       ResizePolicy::Type newPolicy( policy );
224
225       // Switch on each policy type to determine the new behaviour.
226       switch( policy )
227       {
228         case ResizePolicy::FIXED:
229         case ResizePolicy::USE_ASSIGNED_SIZE:
230         {
231           break;
232         }
233
234         case ResizePolicy::USE_NATURAL_SIZE:
235         case ResizePolicy::FIT_TO_CHILDREN:
236         case ResizePolicy::DIMENSION_DEPENDENCY:
237         {
238           // Set size to 0 so the policy determines size.
239           // If a non-zero size is set, policy is converted to fixed.
240           newSize[ dimension ] = 0.0f;
241           modifySize = true;
242           break;
243         }
244
245         // The following cases emulate the three size-mode related resize policies.
246         case ResizePolicy::FILL_TO_PARENT:
247         {
248           newPolicy = ResizePolicy::FIXED;
249           newSize[ dimension ] = stageDimensionSize;
250           modifyPolicy = true;
251           break;
252         }
253
254         case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
255         {
256           newPolicy = ResizePolicy::FIXED;
257           newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
258           modifyPolicy = true;
259           break;
260         }
261
262         case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
263         {
264           newPolicy = ResizePolicy::FIXED;
265           newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
266           modifyPolicy = true;
267           break;
268         }
269       }
270
271       if( modifyPolicy )
272       {
273         // Set the new policy for this dimension, if it has been modified.
274         popup.SetResizePolicy( newPolicy, policyDimension );
275         modifySize = true;
276       }
277     }
278
279     if( modifySize )
280     {
281       // The size is set once at the end.
282       popup.SetProperty( Actor::Property::SIZE, Vector2( newSize[ 0 ], newSize[ 1 ] ) );
283     }
284   }
285
286   void SetupPopup( Toolkit::Popup popup, Actor parent )
287   {
288     if( mAnimationFade )
289     {
290       popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
291     }
292     else
293     {
294       popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
295     }
296
297     if( mContextual )
298     {
299       popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
300
301       // Modify the preset demo resize policies (and size) to contextual ones.
302       SetupContextualResizePolicy( popup );
303
304       parent.Add( popup );
305     }
306     else
307     {
308       Stage::GetCurrent().Add( popup );
309     }
310
311     mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
312   }
313
314   void HidePopup()
315   {
316     if( mPopup )
317     {
318       mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
319     }
320   }
321
322   void PopupHidden()
323   {
324     if( mPopup )
325     {
326       mPopup.Unparent();
327       mPopup.Reset();
328     }
329   }
330
331   Toolkit::Popup CreatePopup()
332   {
333     Stage stage = Stage::GetCurrent();
334     const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
335
336     Toolkit::Popup popup = Toolkit::Popup::New();
337     popup.SetProperty( Dali::Actor::Property::NAME, "popup" );
338     popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
339     popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
340     popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) );
341     popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
342
343     popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
344     popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
345
346     return popup;
347   }
348
349   Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
350   {
351     Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
352     confirmationPopup.SetProperty( Dali::Actor::Property::NAME, "MAIN-POPUP-SELF" );
353
354     if( numberOfButtons > 0 )
355     {
356       // Start with a control area image.
357       Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
358       footer.SetProperty( Dali::Actor::Property::NAME, "controlAreaImage" );
359       // Set up the container's layout.
360       footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
361       footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
362       footer.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 130.0f ) );
363       footer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
364       footer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
365
366       Actor okButton = CreateOKButton();
367       okButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
368       okButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
369       okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
370       okButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0 ) );
371
372       if( numberOfButtons > 1 )
373       {
374         Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
375         controlLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
376         controlLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
377         controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
378
379         Actor cancelButton = CreateCancelButton();
380         cancelButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
381         cancelButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
382         cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
383         cancelButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0 ) );
384
385         controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
386
387         controlLayout.SetRelativeWidth( 0, 0.5f );
388         controlLayout.SetRelativeWidth( 1, 0.5f );
389
390         controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
391         controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
392         controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
393         controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
394
395         footer.Add( controlLayout );
396       }
397       else
398       {
399         footer.Add( okButton );
400       }
401
402       confirmationPopup.SetFooter( footer );
403     }
404
405     confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
406
407     return confirmationPopup;
408   }
409
410   Actor CreateTitle( std::string title )
411   {
412     Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
413     titleActor.SetProperty( Dali::Actor::Property::NAME, "titleActor" );
414     titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
415     titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
416     titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
417
418     return titleActor;
419   }
420
421   Toolkit::PushButton CreateOKButton()
422   {
423     Toolkit::PushButton okayButton = Toolkit::PushButton::New();
424     okayButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_OK_NAME );
425     okayButton.SetProperty( Toolkit::Button::Property::LABEL, "OK!" );
426
427     okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
428
429     return okayButton;
430   }
431
432   Toolkit::PushButton CreateCancelButton()
433   {
434     Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
435     cancelButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_CANCEL_NAME );
436     cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" );
437
438     cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
439
440     return cancelButton;
441   }
442
443   bool OnPopupButtonClicked( Toolkit::Button button )
444   {
445     // Handle Popup pushbuttons being clicked.
446     HidePopup();
447     return true;
448   }
449
450   bool OnButtonClicked( Toolkit::Button button )
451   {
452     // Handle menu items that create popups.
453     if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_ID )
454     {
455       mPopup = CreatePopup();
456       mPopup.SetTitle( CreateTitle( "Popup!" ) );
457
458       SetupPopup( mPopup, button );
459     }
460     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_BUTTONS_1_ID )
461     {
462       mPopup = CreateConfirmationPopup( 1 );
463       mPopup.SetTitle( CreateTitle( "Title" ) );
464
465       SetupPopup( mPopup, button );
466     }
467     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_BUTTONS_2_ID )
468     {
469       mPopup = CreateConfirmationPopup( 2 );
470       mPopup.SetTitle( CreateTitle( "Title" ) );
471
472       SetupPopup( mPopup, button );
473     }
474     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TOAST_ID )
475     {
476       // Create a toast popup via the type registry (as it is a named-type).
477       TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
478       if( typeInfo )
479       {
480         BaseHandle baseHandle = typeInfo.CreateInstance();
481         if( baseHandle )
482         {
483           mPopup = Toolkit::Popup::DownCast( baseHandle );
484           mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
485
486           Stage::GetCurrent().Add( mPopup );
487           mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
488         }
489       }
490     }
491     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
492     {
493       mPopup = CreateConfirmationPopup( 2 );
494       mPopup.SetTitle( CreateTitle( "Erase image" ) );
495
496       Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
497       text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" );
498       text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
499       text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
500       text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
501       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
502       text.SetProperty( Actor::Property::PADDING, Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
503       mPopup.SetContent( text );
504
505       SetupPopup( mPopup, button );
506     }
507     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_TEXT_ID )
508     {
509       mPopup = CreatePopup();
510
511       TextLabel text = TextLabel::New( CONTENT_TEXT );
512       text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" );
513       text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
514       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
515       text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
516       text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
517       text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
518       text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
519       text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
520
521       mPopup.Add( text );
522
523       SetupPopup( mPopup, button );
524     }
525     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_ID )
526     {
527       mPopup = CreatePopup();
528       Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 );
529       image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
530       image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
531       image.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
532
533       mPopup.Add( image );
534
535       SetupPopup( mPopup, button );
536     }
537     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
538     {
539       mPopup = CreatePopup();
540       mPopup.SetTitle( CreateTitle( "Popup!" ) );
541
542       Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
543       text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" );
544       text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
545       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
546       text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
547       text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
548       text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
549
550       mPopup.Add( text );
551
552       SetupPopup( mPopup, button );
553     }
554     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_FIXED_SIZE_ID )
555     {
556       mPopup = CreatePopup();
557       mPopup.SetTitle( CreateTitle( "Popup!" ) );
558
559       Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
560       text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" );
561       text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
562       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
563       text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
564
565       mPopup.Add( text );
566
567       // Fix the popup's size.
568       mPopup.SetProperty( Actor::Property::SIZE, Vector2( 240.0f, 400.0f ) );
569       mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
570
571       SetupPopup( mPopup, button );
572     }
573     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
574     {
575       mPopup = CreateConfirmationPopup( 2 );
576       mPopup.SetTitle( CreateTitle( "Popup!" ) );
577
578       Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
579       text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" );
580       text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
581       text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
582       text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
583       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
584       text.SetProperty( Actor::Property::PADDING, Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
585
586       mPopup.Add( text );
587
588       SetupPopup( mPopup, button );
589     }
590     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_COMPLEX_ID )
591     {
592       mPopup = CreateConfirmationPopup( 2 );
593       mPopup.SetTitle( CreateTitle( "Warning" ) );
594
595       // Content
596       Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
597       content.SetProperty( Dali::Actor::Property::NAME, "COMPLEX_TABLEVIEW" );
598       content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
599       content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
600       content.SetFitHeight( 0 );
601       content.SetFitHeight( 1 );
602       content.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
603
604       // Text
605       {
606         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
607         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
608         text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
609         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
610         text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
611
612         content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
613       }
614
615       // Image
616       {
617         Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 );
618         image.SetProperty( Dali::Actor::Property::NAME, "COMPLEX_IMAGE" );
619         image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
620         image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
621         image.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
622         content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
623       }
624
625       // Text 2
626       {
627         Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
628         root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
629         root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
630         root.SetFitHeight( 0 );
631         root.SetFitWidth( 0 );
632         root.SetProperty( Actor::Property::PADDING, Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
633
634         Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
635         checkBox.SetProperty( Actor::Property::SIZE, Vector2( 48, 48 ) );
636         root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
637
638         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
639         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
640         Actor textActor = text;
641         textActor.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
642
643         root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
644
645         content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
646       }
647
648       mPopup.SetContent( content );
649
650       SetupPopup( mPopup, button );
651     }
652     else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CUSTOM_STYLE )
653     {
654       mPopup = CreateConfirmationPopup( 2 );
655
656       Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" );
657       titleActor.SetProperty( Dali::Actor::Property::NAME, "titleActor" );
658       titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED );
659       titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
660       titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
661       mPopup.SetTitle( titleActor );
662
663       SetupPopup( mPopup, button );
664
665       mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME );
666     }
667
668     return true;
669   }
670
671   void OnKeyEvent( const KeyEvent& event )
672   {
673     if( event.state == KeyEvent::Down )
674     {
675       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
676       {
677         // Exit application when click back or escape.
678         mApplication.Quit();
679       }
680     }
681   }
682
683 public: // From ItemFactory
684
685   /**
686    * @brief Return the number of items to display in the item view
687    *
688    * @return Return the number of items to display
689    */
690   virtual unsigned int GetNumberOfItems()
691   {
692     return POPUP_BUTTON_ITEMS_COUNT;
693   }
694
695   /**
696    * @brief Create a new item to populate the item view with
697    *
698    * @param[in] itemId The index of the item to create
699    * @return Return the created actor for the given ID
700    */
701   virtual Actor NewItem(unsigned int itemId)
702   {
703     Toolkit::PushButton popupButton = Toolkit::PushButton::New();
704     popupButton.SetProperty( Dali::Actor::Property::NAME, POPUP_BUTTON_ITEMS[ itemId ].name );
705     popupButton.SetProperty( Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[ itemId ].text );
706     popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
707
708     popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
709
710     return popupButton;
711   }
712
713 private:
714
715
716   Application&        mApplication;
717   Toolkit::Control    mView;                       ///< The View instance.
718   Toolkit::ToolBar    mToolBar;                    ///< The View's Toolbar.
719   Toolkit::PushButton mContextButton;              ///< For toggling contextual mode.
720   Toolkit::PushButton mAnimationButton;            ///< For toggling the fade animation.
721   Layer               mContentLayer;               ///< Content layer
722
723   Toolkit::TextLabel  mTitleActor;                 ///< Title text
724
725   bool                mContextual;                 ///< True if currently using the contextual popup mode.
726   bool                mAnimationFade;              ///< True if currently using the fade animation.
727
728   Toolkit::Popup      mPopup;                       ///< The current example popup.
729
730   Toolkit::ItemView   mItemView;                    ///< ItemView to hold test images
731
732 };
733
734 int DALI_EXPORT_API main( int argc, char **argv )
735 {
736   Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
737   PopupExample test( application );
738   application.MainLoop();
739   return 0;
740 }