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