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