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