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