Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-demo.git] / examples / size-negotiation / size-negotiation-example.cpp
1 /*
2  * Copyright (c) 2014 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
22 using namespace Dali;
23
24 // Define this so that it is interchangeable
25 // "DP" stands for Device independent Pixels
26 #define DP(x) DemoHelper::ScalePointSize(x)
27
28 struct ButtonItem
29 {
30   const char* name;
31   const char* text;
32 };
33
34
35 namespace
36 {
37
38 const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "background-gradient.jpg";
39 const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png";
40
41 const char* const TOOLBAR_TITLE = "Size Negotiation";
42 const int TOOLBAR_HEIGHT = 62;
43
44 const char* MENU_ICON_IMAGE = DALI_IMAGE_DIR "icon-cluster-none.png";
45
46 const char* const PUSHBUTTON_BUTTON_IMAGE = DALI_IMAGE_DIR "button-up.9.png";
47 const char* const PUSHBUTTON_PRESS_IMAGE = DALI_IMAGE_DIR "button-down.9.png";
48
49 const char* const POPUPS_MENU_ID = "POPUPS_MENU";
50 const char* const TABLEVIEW_MENU_ID = "TABLEVIEW_MENU";
51
52 const char* const POPUP_BUTTON_EMPTY_ID = "POPUP_BUTTON_EMPTY";
53 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
54 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
55 const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2";
56 const char* const POPUP_BUTTON_TITLE_BUTTONS_ID = "POPUP_BUTTON_TITLE_BUTTONS";
57 const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT";
58 const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE";
59 const char* const POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID = "POPUP_BUTTON_CONTENT_IMAGE_SCALE";
60 const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT";
61 const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL";
62 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT";
63 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS";
64 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
65
66 const char* const TABLEVIEW_BUTTON_EMPTY_ID = "TABLEVIEW_BUTTON_EMPTY";
67 const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL";
68 const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL";
69 const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL";
70 const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1";
71 const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2";
72 const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1";
73 const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2";
74 const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1";
75 const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2";
76 const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3";
77
78 const char* const OKAY_BUTTON_ID = "OKAY_BUTTON";
79 const char* const CANCEL_BUTTON_ID = "CANCEL_BUTTON";
80
81 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.";
82 const char* const IMAGE1 = DALI_IMAGE_DIR "gallery-medium-5.jpg";
83 const char* const IMAGE2 = DALI_IMAGE_DIR "background-magnifier.jpg";
84 const char* const CHECKBOX_UNCHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-unselected.png";
85 const char* const CHECKBOX_CHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-selected.png";
86
87 const ButtonItem MENU_ITEMS[] = {
88     { POPUPS_MENU_ID,        "Popups" },
89     { TABLEVIEW_MENU_ID,     "TableView" }
90 };
91
92 const unsigned int MENU_ITEMS_COUNT = sizeof( MENU_ITEMS ) / sizeof( MENU_ITEMS[0] );
93
94 const ButtonItem POPUP_BUTTON_ITEMS[] = {
95     { POPUP_BUTTON_COMPLEX_ID,                    "Complex" },
96     { POPUP_BUTTON_EMPTY_ID,                      "Empty" },
97     { POPUP_BUTTON_TITLE_ID,                      "Title" },
98     { POPUP_BUTTON_BUTTONS_1_ID,                  "1 Button" },
99     { POPUP_BUTTON_BUTTONS_2_ID,                  "2 Buttons" },
100     { POPUP_BUTTON_TITLE_BUTTONS_ID,              "Title & Buttons" },
101     { POPUP_BUTTON_CONTENT_TEXT_ID,               "Text" },
102     { POPUP_BUTTON_CONTENT_IMAGE_ID,              "Image" },
103     { POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID,        "Image Scale" },
104     { POPUP_BUTTON_CONTENT_IMAGE_FIT_ID,          "Image Fit" },
105     { POPUP_BUTTON_CONTENT_IMAGE_FILL_ID,         "Image Fill" },
106     { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID,         "Title Text" },
107     { POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID, "Title, text, buttons" }
108
109 };
110
111 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
112
113 const ButtonItem TABLEVIEW_BUTTON_ITEMS[] = {
114     { TABLEVIEW_BUTTON_EMPTY_ID,                    "Empty" },
115     { TABLEVIEW_BUTTON_1CELL_ID,                    "1 Cell" },
116     { TABLEVIEW_BUTTON_3CELL_ID,                    "3 Cell" },
117     { TABLEVIEW_BUTTON_3X3CELL_ID,                  "3x3 Cells" },
118     { TABLEVIEW_BUTTON_FIXED1_ID,                   "Fixed 1" },
119     { TABLEVIEW_BUTTON_FIXED2_ID,                   "Fixed 2" },
120     { TABLEVIEW_BUTTON_FIT1_ID,                     "Fit Top Bottom" },
121     { TABLEVIEW_BUTTON_FIT2_ID,                     "Fit Middle" },
122     { TABLEVIEW_BUTTON_NATURAL1_ID,                 "Natural 1" },
123     { TABLEVIEW_BUTTON_NATURAL2_ID,                 "Natural 2" },
124     { TABLEVIEW_BUTTON_NATURAL3_ID,                 "Natural 3" },
125 };
126
127 const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] );
128
129 }  // namespace
130
131
132
133 /**
134  * This example shows the usage of size negotiation.
135  */
136 class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory
137 {
138 public:
139
140   SizeNegotiationController( Application& application )
141     : mApplication( application ),
142       mMenuShown( false ),
143       mDemoState( POPUP )
144   {
145     // Connect to the Application's Init signal
146     mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create );
147   }
148
149   ~SizeNegotiationController()
150   {
151     // Nothing to do here
152   }
153
154   void Create( Application& application )
155   {
156     // The Init signal is received once (only) during the Application lifetime
157
158     Stage stage = Stage::GetCurrent();
159
160     // Respond to key events
161     stage.KeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent);
162
163     // Creates a default view with a default tool bar.
164     // The view is added to the stage.
165     mContentLayer = DemoHelper::CreateView( application,
166                                             mView,
167                                             mToolBar,
168                                             BACKGROUND_IMAGE,
169                                             TOOLBAR_IMAGE,
170                                             std::string("") );
171
172     mTitleActor = Dali::Toolkit::TextLabel::New(); // FIXME
173     mTitleActor.SetName( "CUSTOM_TOOLBAR_TITLE" );
174
175     SetTitle();
176
177     // Create menu button
178     Toolkit::PushButton viewButton = Toolkit::PushButton::New();
179     viewButton.SetBackgroundImage( ResourceImage::New( MENU_ICON_IMAGE ) );
180     viewButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnMenu );
181     mToolBar.AddControl( viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
182
183     // Add title to the tool bar.
184     const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
185     mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
186
187     mItemView = Toolkit::ItemView::New( *this );
188     mItemView.SetParentOrigin( ParentOrigin::CENTER );
189     mItemView.SetAnchorPoint( AnchorPoint::CENTER );
190     mItemView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
191
192     // Use a grid layout for tests
193     Toolkit::GridLayoutPtr gridLayout = Toolkit::GridLayout::New();
194     gridLayout->SetNumberOfColumns( 2 );
195     gridLayout->SetTopMargin( DP(TOOLBAR_HEIGHT) + DP(20.0f) );
196     gridLayout->SetBottomMargin( DP(100.0f) );
197     gridLayout->SetRowSpacing( DP(20.0f) );
198     mItemView.AddLayout( *gridLayout );
199
200     Vector2 stageSize = stage.GetSize();
201     float layoutWidth = Toolkit::IsHorizontal( gridLayout->GetOrientation() ) ? stageSize.height : stageSize.width;
202     float gridItemSize = ( layoutWidth / gridLayout->GetNumberOfColumns() ) * 0.5f;
203     gridLayout->SetScrollSpeedFactor( gridLayout->GetNumberOfColumns() / gridItemSize * 0.5f );
204
205     mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
206
207     mContentLayer.Add( mItemView );
208   }
209
210   void SetTitle()
211   {
212     std::string subTitle = "";
213
214     switch( mDemoState )
215     {
216       case POPUP:
217       {
218         subTitle = "Popups";
219         break;
220       }
221
222       case TABLEVIEW:
223       {
224         subTitle = "TableView";
225         break;
226       }
227
228       default:
229       {
230         break;
231       }
232     }
233
234     mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, std::string( std::string( TOOLBAR_TITLE ) + ": " + subTitle ) );
235   }
236
237   bool OnMenu( Toolkit::Button button )
238   {
239     ShowMenu();
240     return true;
241   }
242
243   void ShowMenu()
244   {
245     Stage stage = Stage::GetCurrent();
246     const float popupWidth = stage.GetSize().x * 0.5f;
247
248     mMenu = Toolkit::Popup::New();
249     mMenu.SetParentOrigin( ParentOrigin::TOP_LEFT );
250     mMenu.SetAnchorPoint( AnchorPoint::TOP_LEFT );
251     mMenu.HideTail();
252     mMenu.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::HideMenu );
253     mMenu.SetPreferredSize( Vector2( popupWidth, 0.0f ) );
254     mMenu.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
255
256     Toolkit::TableView tableView = Toolkit::TableView::New( 0, 0 );
257     tableView.SetResizePolicy( FILL_TO_PARENT, WIDTH );
258     tableView.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
259     mMenu.Add( tableView );
260
261     for( unsigned int i = 0; i < MENU_ITEMS_COUNT; ++i )
262     {
263       Toolkit::PushButton menuButton = Toolkit::PushButton::New();
264       menuButton.SetName( MENU_ITEMS[ i ].name );
265       menuButton.SetLabel( MENU_ITEMS[ i ].text );
266       menuButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnMenuSelect );
267
268       tableView.Add( menuButton );
269       tableView.SetFitHeight( i );
270     }
271
272     // Show the menu
273     mMenu.Show();
274     mMenuShown = true;
275   }
276
277   void HideMenu()
278   {
279     if( mMenu )
280     {
281       mMenu.Hide();
282       mMenu.Reset();
283     }
284
285     mMenuShown = false;
286   }
287
288   bool OnMenuSelect( Toolkit::Button button )
289   {
290     bool refresh = false;
291
292     if( button.GetName() == POPUPS_MENU_ID )
293     {
294       if( mDemoState != POPUP )
295       {
296         refresh = true;
297         mDemoState = POPUP;
298       }
299     }
300     else if( button.GetName() == TABLEVIEW_MENU_ID )
301     {
302       if( mDemoState != TABLEVIEW )
303       {
304         refresh = true;
305         mDemoState = TABLEVIEW;
306       }
307     }
308
309     if( refresh )
310     {
311       SetTitle();
312
313       mItemView.Refresh();
314     }
315
316     HideMenu();
317     return true;
318   }
319
320   Toolkit::Popup CreatePopup()
321   {
322     Stage stage = Stage::GetCurrent();
323     const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
324
325     Toolkit::Popup popup = Toolkit::Popup::New();
326     popup.SetName( "POPUP" );
327     popup.SetParentOrigin( ParentOrigin::CENTER );
328     popup.SetAnchorPoint( AnchorPoint::CENTER );
329     popup.SetPreferredSize( Vector2( POPUP_WIDTH_DP, 0.0f ) );
330     popup.HideTail();
331
332     popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched );
333
334     return popup;
335   }
336
337   bool OnButtonClicked( Toolkit::Button button )
338   {
339     if( button.GetName() == POPUP_BUTTON_EMPTY_ID )
340     {
341       mPopup = CreatePopup();
342
343       // The popup is not yet on the stage so needs to be flaged as dirty
344       mPopup.MarkDirtyForRelayout();
345
346       mPopup.Show();
347     }
348     else if( button.GetName() == POPUP_BUTTON_TITLE_ID )
349     {
350       mPopup = CreatePopup();
351       mPopup.SetTitle( "Popup!" );
352
353       // The popup is not yet on the stage so needs to be flaged as dirty
354       mPopup.MarkDirtyForRelayout();
355
356       mPopup.Show();
357     }
358     else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
359     {
360       mPopup = CreatePopup();
361
362       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
363       okayButton.SetName( OKAY_BUTTON_ID );
364       okayButton.SetLabel( "OK!" );
365       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
366       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
367
368       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
369
370       mPopup.AddButton( okayButton );
371
372       // The popup is not yet on the stage so needs to be flaged as dirty
373       mPopup.MarkDirtyForRelayout();
374
375       mPopup.Show();
376     }
377     else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
378     {
379       mPopup = CreatePopup();
380
381       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
382       cancelButton.SetName( CANCEL_BUTTON_ID );
383       cancelButton.SetLabel( "Cancel" );
384       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
385       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
386
387       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
388
389       mPopup.AddButton( cancelButton );
390
391       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
392       okayButton.SetName( OKAY_BUTTON_ID );
393       okayButton.SetLabel( "OK!" );
394       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
395       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
396
397       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
398
399       mPopup.AddButton( okayButton );
400
401       // The popup is not yet on the stage so needs to be flaged as dirty
402       mPopup.MarkDirtyForRelayout();
403
404       mPopup.Show();
405     }
406     else if( button.GetName() == POPUP_BUTTON_TITLE_BUTTONS_ID )
407     {
408       mPopup = CreatePopup();
409       mPopup.SetTitle( "Popup!" );
410
411       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
412       cancelButton.SetName( CANCEL_BUTTON_ID );
413       cancelButton.SetLabel( "Cancel" );
414       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
415       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
416
417       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
418
419       mPopup.AddButton( cancelButton );
420
421       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
422       okayButton.SetName( OKAY_BUTTON_ID );
423       okayButton.SetLabel( "OK!" );
424       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
425       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
426
427       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
428
429       mPopup.AddButton( okayButton );
430
431       // The popup is not yet on the stage so needs to be flaged as dirty
432       mPopup.MarkDirtyForRelayout();
433
434       mPopup.Show();
435     }
436     else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
437     {
438       mPopup = CreatePopup();
439
440       // FIXME - Add text
441
442       // The popup is not yet on the stage so needs to be flaged as dirty
443       mPopup.MarkDirtyForRelayout();
444
445       mPopup.Show();
446     }
447     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
448     {
449       mPopup = CreatePopup();
450
451       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
452       image.SetResizePolicy( FILL_TO_PARENT, WIDTH );
453       image.SetDimensionDependency( HEIGHT, WIDTH );
454       image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
455
456       mPopup.Add( image );
457
458       // The popup is not yet on the stage so needs to be flaged as dirty
459       mPopup.MarkDirtyForRelayout();
460
461       mPopup.Show();
462     }
463     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
464     {
465       mPopup = CreatePopup();
466
467       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
468       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
469       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
470
471       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
472       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
473
474       mPopup.Add( image );
475
476       // The popup is not yet on the stage so needs to be flaged as dirty
477       mPopup.MarkDirtyForRelayout();
478
479       mPopup.Show();
480     }
481     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
482     {
483       mPopup = CreatePopup();
484
485       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
486       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
487       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
488
489       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
490       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
491       image.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO );
492
493       mPopup.Add( image );
494
495       // The popup is not yet on the stage so needs to be flaged as dirty
496       mPopup.MarkDirtyForRelayout();
497
498       mPopup.Show();
499     }
500     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
501     {
502       mPopup = CreatePopup();
503
504       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
505       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
506       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
507
508       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
509       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
510       image.SetSizeScalePolicy( FILL_WITH_ASPECT_RATIO );
511
512       mPopup.Add( image );
513
514       // The popup is not yet on the stage so needs to be flaged as dirty
515       mPopup.MarkDirtyForRelayout();
516
517       mPopup.Show();
518     }
519     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
520     {
521       mPopup = CreatePopup();
522       mPopup.SetTitle( "Popup!" );
523
524       // FIXME - Add text
525
526       // The popup is not yet on the stage so needs to be flaged as dirty
527       mPopup.MarkDirtyForRelayout();
528
529       mPopup.Show();
530     }
531     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID )
532     {
533       mPopup = CreatePopup();
534       mPopup.SetTitle( "Popup!" );
535
536       // FIXME - Add text
537
538       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
539       cancelButton.SetName( CANCEL_BUTTON_ID );
540       cancelButton.SetLabel( "Cancel" );
541       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
542       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
543
544       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
545
546       mPopup.AddButton( cancelButton );
547
548       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
549       okayButton.SetName( OKAY_BUTTON_ID );
550       okayButton.SetLabel( "OK!" );
551       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
552       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
553
554       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
555
556       mPopup.AddButton( okayButton );
557
558       // The popup is not yet on the stage so needs to be flaged as dirty
559       mPopup.MarkDirtyForRelayout();
560
561       mPopup.Show();
562     }
563     else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
564     {
565       mPopup = CreatePopup();
566       mPopup.SetTitle( "Warning" );
567
568       // Content
569       Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
570       content.SetName( "COMPLEX_TABLEVIEW" );
571       content.SetResizePolicy( FILL_TO_PARENT, WIDTH );
572       content.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
573       content.SetFitHeight( 0 );
574       content.SetFitHeight( 1 );
575       content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
576
577       // Text
578       {
579         Toolkit::TextLabel text = Toolkit::TextLabel::New();
580         // FIXME
581
582         content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
583       }
584
585       // Image
586       {
587         ImageActor image = ImageActor::New( ResourceImage::New( IMAGE1 ) );
588         image.SetName( "COMPLEX_IMAGE" );
589         image.SetResizePolicy( FILL_TO_PARENT, WIDTH );
590         image.SetDimensionDependency( HEIGHT, WIDTH );
591         image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
592         content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
593       }
594
595       // Text 2
596       {
597         Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
598         root.SetResizePolicy( FILL_TO_PARENT, WIDTH );
599         root.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
600         root.SetFitHeight( 0 );
601         root.SetFitWidth( 0 );
602         root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
603
604         Dali::Image unchecked = Dali::ResourceImage::New( CHECKBOX_UNCHECKED_IMAGE );
605         Dali::Image checked = Dali::ResourceImage::New( CHECKBOX_CHECKED_IMAGE );
606         Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
607         checkBox.SetBackgroundImage( unchecked );
608         checkBox.SetSelectedImage( checked );
609         checkBox.SetPreferredSize( Vector2( 48, 48 ) );
610         checkBox.SetResizePolicy( FIXED, ALL_DIMENSIONS );
611
612         root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
613
614         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
615         // FIXME
616         Actor textActor = text;
617         textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
618
619         root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
620
621         content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0, 0, 2 ) );  // Column span 2
622       }
623
624       mPopup.Add( content );
625
626       // Buttons
627       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
628       cancelButton.SetName( CANCEL_BUTTON_ID );
629       cancelButton.SetLabel( "Cancel" );
630       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
631       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
632
633       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
634
635       mPopup.AddButton( cancelButton );
636
637       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
638       okayButton.SetName( OKAY_BUTTON_ID );
639       okayButton.SetLabel( "OK!" );
640       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
641       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
642
643       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
644
645       mPopup.AddButton( okayButton );
646
647       // The popup is not yet on the stage so needs to be flaged as dirty
648       mPopup.MarkDirtyForRelayout();
649
650       mPopup.Show();
651     }
652     else if( button.GetName() == TABLEVIEW_BUTTON_EMPTY_ID )
653     {
654       mPopup = CreatePopup();
655       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
656       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
657       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
658
659
660       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
661       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
662
663       mPopup.Add( table );
664
665       // The popup is not yet on the stage so needs to be flaged as dirty
666       mPopup.MarkDirtyForRelayout();
667
668       mPopup.Show();
669     }
670     else if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
671     {
672       mPopup = CreatePopup();
673       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
674       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
675       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
676
677
678       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
679       table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" );
680       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
681
682       Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
683       backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
684       table.Add( backing );
685
686       mPopup.Add( table );
687
688       // The popup is not yet on the stage so needs to be flaged as dirty
689       mPopup.MarkDirtyForRelayout();
690
691       mPopup.Show();
692     }
693     else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
694     {
695       mPopup = CreatePopup();
696       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
697       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
698       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
699
700
701       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
702       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
703
704       {
705         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
706         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
707         table.Add( backing );
708       }
709       {
710         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
711         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
712         table.Add( backing );
713       }
714       {
715         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
716         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
717         table.Add( backing );
718       }
719
720       mPopup.Add( table );
721
722       // The popup is not yet on the stage so needs to be flaged as dirty
723       mPopup.MarkDirtyForRelayout();
724
725       mPopup.Show();
726     }
727     else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
728     {
729       mPopup = CreatePopup();
730       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
731       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
732       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
733
734
735       Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
736       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
737
738       // Column 0
739       {
740         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
741         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
742         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
743       }
744       {
745         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
746         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
747         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
748       }
749       {
750         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
751         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
752         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
753       }
754
755       // Column 1
756       {
757         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
758         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
759         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
760       }
761       {
762         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
763         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
764         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
765       }
766       {
767         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
768         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
769         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
770       }
771
772       // Column 2
773       {
774         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
775         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
776         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
777       }
778       {
779         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
780         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
781         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
782       }
783       {
784         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
785         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
786         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
787       }
788
789       mPopup.Add( table );
790
791       // The popup is not yet on the stage so needs to be flaged as dirty
792       mPopup.MarkDirtyForRelayout();
793
794       mPopup.Show();
795     }
796     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
797     {
798       mPopup = CreatePopup();
799       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
800       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
801       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
802
803
804       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
805       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
806       table.SetFixedHeight( 0, 50.0f );
807
808       {
809         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
810         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
811         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
812         text.SetAnchorPoint( AnchorPoint::CENTER );
813         text.SetParentOrigin( ParentOrigin::CENTER );
814         backing.Add( text );
815         table.Add( backing );
816       }
817       {
818         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
819         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
820         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
821         text.SetAnchorPoint( AnchorPoint::CENTER );
822         text.SetParentOrigin( ParentOrigin::CENTER );
823         backing.Add( text );
824         table.Add( backing );
825       }
826       {
827         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
828         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
829         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
830         text.SetAnchorPoint( AnchorPoint::CENTER );
831         text.SetParentOrigin( ParentOrigin::CENTER );
832         backing.Add( text );
833         table.Add( backing );
834       }
835
836       mPopup.Add( table );
837
838       // The popup is not yet on the stage so needs to be flaged as dirty
839       mPopup.MarkDirtyForRelayout();
840
841       mPopup.Show();
842     }
843     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
844     {
845       mPopup = CreatePopup();
846       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
847       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
848       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
849
850
851       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
852       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
853       table.SetFixedHeight( 0, 50.0f );
854       table.SetFixedHeight( 2, 50.0f );
855
856       {
857         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
858         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
859         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
860         text.SetAnchorPoint( AnchorPoint::CENTER );
861         text.SetParentOrigin( ParentOrigin::CENTER );
862         backing.Add( text );
863         table.Add( backing );
864       }
865       {
866         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
867         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
868         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
869         text.SetAnchorPoint( AnchorPoint::CENTER );
870         text.SetParentOrigin( ParentOrigin::CENTER );
871         backing.Add( text );
872         table.Add( backing );
873       }
874       {
875         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
876         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
877         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
878         text.SetAnchorPoint( AnchorPoint::CENTER );
879         text.SetParentOrigin( ParentOrigin::CENTER );
880         backing.Add( text );
881         table.Add( backing );
882       }
883
884       mPopup.Add( table );
885
886       // The popup is not yet on the stage so needs to be flaged as dirty
887       mPopup.MarkDirtyForRelayout();
888
889       mPopup.Show();
890     }
891     else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
892     {
893       mPopup = CreatePopup();
894       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
895       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
896       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
897
898
899       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
900       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
901       table.SetFitHeight( 0 );
902       table.SetFitHeight( 2 );
903
904       {
905         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
906         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
907         backing.SetResizePolicy( FIXED, HEIGHT );
908         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
909
910         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
911         text.SetAnchorPoint( AnchorPoint::CENTER );
912         text.SetParentOrigin( ParentOrigin::CENTER );
913         backing.Add( text );
914
915         table.Add( backing );
916       }
917       {
918         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
919         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
920
921         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
922         text.SetAnchorPoint( AnchorPoint::CENTER );
923         text.SetParentOrigin( ParentOrigin::CENTER );
924         backing.Add( text );
925
926         table.Add( backing );
927       }
928       {
929         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
930         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
931         backing.SetResizePolicy( FIXED, HEIGHT );
932         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
933
934         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
935         text.SetAnchorPoint( AnchorPoint::CENTER );
936         text.SetParentOrigin( ParentOrigin::CENTER );
937         backing.Add( text );
938
939         table.Add( backing );
940       }
941
942       mPopup.Add( table );
943
944       // The popup is not yet on the stage so needs to be flaged as dirty
945       mPopup.MarkDirtyForRelayout();
946
947       mPopup.Show();
948     }
949     else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
950     {
951       mPopup = CreatePopup();
952       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
953       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
954       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
955
956
957       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
958       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
959       table.SetFitHeight( 1 );
960
961       {
962         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
963         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
964
965         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
966         text.SetAnchorPoint( AnchorPoint::CENTER );
967         text.SetParentOrigin( ParentOrigin::CENTER );
968         backing.Add( text );
969
970         table.Add( backing );
971       }
972       {
973         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
974         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
975         backing.SetResizePolicy( FIXED, HEIGHT );
976         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
977
978         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
979         text.SetAnchorPoint( AnchorPoint::CENTER );
980         text.SetParentOrigin( ParentOrigin::CENTER );
981         backing.Add( text );
982
983         table.Add( backing );
984       }
985       {
986         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
987         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
988
989         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
990         text.SetAnchorPoint( AnchorPoint::CENTER );
991         text.SetParentOrigin( ParentOrigin::CENTER );
992         backing.Add( text );
993
994         table.Add( backing );
995       }
996
997       mPopup.Add( table );
998
999       // The popup is not yet on the stage so needs to be flaged as dirty
1000       mPopup.MarkDirtyForRelayout();
1001
1002       mPopup.Show();
1003     }
1004     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
1005     {
1006       mPopup = CreatePopup();
1007       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1008       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1009       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1010       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1011
1012       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1013       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1014       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1015       table.SetFitHeight( 0 );
1016       table.SetFitHeight( 1 );
1017       table.SetFitHeight( 2 );
1018
1019       {
1020         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1021         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1022         backing.SetResizePolicy( FIXED, HEIGHT );
1023         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
1024
1025         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1026         text.SetAnchorPoint( AnchorPoint::CENTER );
1027         text.SetParentOrigin( ParentOrigin::CENTER );
1028         backing.Add( text );
1029
1030         table.Add( backing );
1031       }
1032       {
1033         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
1034         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1035         backing.SetResizePolicy( FIXED, HEIGHT );
1036         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1037
1038         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1039         text.SetAnchorPoint( AnchorPoint::CENTER );
1040         text.SetParentOrigin( ParentOrigin::CENTER );
1041         backing.Add( text );
1042
1043         table.Add( backing );
1044       }
1045       {
1046         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1047         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1048         backing.SetResizePolicy( FIXED, HEIGHT );
1049         backing.SetPreferredSize( Vector2( 0.0f, 300.0f ) );
1050
1051         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1052         text.SetAnchorPoint( AnchorPoint::CENTER );
1053         text.SetParentOrigin( ParentOrigin::CENTER );
1054         backing.Add( text );
1055
1056         table.Add( backing );
1057       }
1058
1059       mPopup.Add( table );
1060
1061       // The popup is not yet on the stage so needs to be flaged as dirty
1062       mPopup.MarkDirtyForRelayout();
1063
1064       mPopup.Show();
1065     }
1066     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
1067     {
1068       mPopup = CreatePopup();
1069       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1070       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1071       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1072       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1073
1074       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1075       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1076       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1077       table.SetFitHeight( 0 );
1078       table.SetFitHeight( 1 );
1079
1080       {
1081         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1082         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1083         backing.SetResizePolicy( FIXED, HEIGHT );
1084         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
1085
1086         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1087         text.SetAnchorPoint( AnchorPoint::CENTER );
1088         text.SetParentOrigin( ParentOrigin::CENTER );
1089         backing.Add( text );
1090
1091         table.Add( backing );
1092       }
1093       {
1094         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1095         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1096         backing.SetResizePolicy( FIXED, HEIGHT );
1097         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1098
1099         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1100         text.SetAnchorPoint( AnchorPoint::CENTER );
1101         text.SetParentOrigin( ParentOrigin::CENTER );
1102         backing.Add( text );
1103
1104         table.Add( backing );
1105       }
1106
1107       mPopup.Add( table );
1108
1109       // The popup is not yet on the stage so needs to be flaged as dirty
1110       mPopup.MarkDirtyForRelayout();
1111
1112       mPopup.Show();
1113     }
1114     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
1115     {
1116       mPopup = CreatePopup();
1117       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1118       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1119       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1120       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1121
1122       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1123       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1124       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1125       table.SetFixedHeight( 0, 20.0f );
1126       table.SetFitHeight( 1 );
1127
1128       {
1129         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1130         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
1131
1132         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
1133         text.SetAnchorPoint( AnchorPoint::CENTER );
1134         text.SetParentOrigin( ParentOrigin::CENTER );
1135         backing.Add( text );
1136
1137         table.Add( backing );
1138       }
1139       {
1140         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1141         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1142         backing.SetResizePolicy( FIXED, HEIGHT );
1143         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1144
1145         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1146         text.SetAnchorPoint( AnchorPoint::CENTER );
1147         text.SetParentOrigin( ParentOrigin::CENTER );
1148         backing.Add( text );
1149
1150         table.Add( backing );
1151       }
1152
1153       mPopup.Add( table );
1154
1155       // The popup is not yet on the stage so needs to be flaged as dirty
1156       mPopup.MarkDirtyForRelayout();
1157
1158       mPopup.Show();
1159     }
1160     else if( button.GetName() == OKAY_BUTTON_ID || button.GetName() == CANCEL_BUTTON_ID )
1161     {
1162       if( mPopup )
1163       {
1164         mPopup.Hide();
1165       }
1166     }
1167
1168     return true;
1169   }
1170
1171   void OnPopupOutsideTouched()
1172   {
1173     if( mPopup )
1174     {
1175       mPopup.Hide();
1176     }
1177   }
1178
1179   void OnKeyEvent( const KeyEvent& event )
1180   {
1181     if( event.state == KeyEvent::Down )
1182     {
1183       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
1184       {
1185         // Exit application when click back or escape.
1186         mApplication.Quit();
1187       }
1188     }
1189   }
1190
1191 public: // From ItemFactory
1192
1193   /**
1194    * @brief Return the number of items to display in the item view
1195    *
1196    * @return Return the number of items to display
1197    */
1198   virtual unsigned int GetNumberOfItems()
1199   {
1200     switch( mDemoState )
1201     {
1202       case POPUP:
1203       {
1204         return POPUP_BUTTON_ITEMS_COUNT;
1205       }
1206
1207       case TABLEVIEW:
1208       {
1209         return TABLEVIEW_BUTTON_ITEMS_COUNT;
1210       }
1211
1212       default:
1213       {
1214         break;
1215       }
1216     }
1217
1218     return 0;
1219   }
1220
1221   /**
1222    * @brief Create a new item to populate the item view with
1223    *
1224    * @param[in] itemId The index of the item to create
1225    * @return Return the created actor for the given ID
1226    */
1227   virtual Actor NewItem(unsigned int itemId)
1228   {
1229     const ButtonItem* buttonDataArray = NULL;
1230     switch( mDemoState )
1231     {
1232       case POPUP:
1233       {
1234         buttonDataArray = POPUP_BUTTON_ITEMS;
1235         break;
1236       }
1237
1238       case TABLEVIEW:
1239       {
1240         buttonDataArray = TABLEVIEW_BUTTON_ITEMS;
1241         break;
1242       }
1243
1244       default:
1245       {
1246         break;
1247       }
1248     }
1249
1250     if( buttonDataArray )
1251     {
1252       Toolkit::PushButton popupButton = Toolkit::PushButton::New();
1253       popupButton.SetName( buttonDataArray[ itemId ].name );
1254       popupButton.SetLabel( buttonDataArray[ itemId ].text );
1255       popupButton.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
1256
1257       popupButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
1258       popupButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
1259
1260       popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
1261
1262       return popupButton;
1263     }
1264
1265     return Actor();
1266   }
1267
1268 private:
1269
1270   enum DemoState
1271   {
1272     POPUP,
1273     TABLEVIEW
1274   };
1275
1276   Application&      mApplication;
1277   Toolkit::View     mView;                   ///< The View instance.
1278   Toolkit::ToolBar  mToolBar;                ///< The View's Toolbar.
1279   Layer             mContentLayer;           ///< Content layer
1280
1281   Toolkit::TextLabel mTitleActor;             ///< Title text
1282
1283   Toolkit::Popup    mMenu;                   ///< The navigation menu
1284   bool              mMenuShown;              ///< If the navigation menu is currently being displayed or not
1285
1286   Toolkit::Popup    mPopup;
1287
1288   Toolkit::ItemView mItemView;               ///< ItemView to hold test images
1289
1290   DemoState mDemoState;
1291 };
1292
1293 void RunTest( Application& application )
1294 {
1295   SizeNegotiationController test( application );
1296
1297   application.MainLoop();
1298 }
1299
1300 // Entry point for Linux & SLP applications
1301 //
1302 int main( int argc, char **argv )
1303 {
1304   Application application = Application::New( &argc, &argv );
1305
1306   RunTest( application );
1307
1308   return 0;
1309 }