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       mPopup.Show();
347     }
348     else if( button.GetName() == POPUP_BUTTON_TITLE_ID )
349     {
350       mPopup = CreatePopup();
351       mPopup.SetTitle( "Popup!" );
352
353       mPopup.Show();
354     }
355     else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
356     {
357       mPopup = CreatePopup();
358
359       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
360       okayButton.SetName( OKAY_BUTTON_ID );
361       okayButton.SetLabel( "OK!" );
362       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
363       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
364
365       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
366
367       mPopup.AddButton( okayButton );
368
369       mPopup.Show();
370     }
371     else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
372     {
373       mPopup = CreatePopup();
374
375       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
376       cancelButton.SetName( CANCEL_BUTTON_ID );
377       cancelButton.SetLabel( "Cancel" );
378       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
379       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
380
381       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
382
383       mPopup.AddButton( cancelButton );
384
385       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
386       okayButton.SetName( OKAY_BUTTON_ID );
387       okayButton.SetLabel( "OK!" );
388       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
389       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
390
391       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
392
393       mPopup.AddButton( okayButton );
394
395       mPopup.Show();
396     }
397     else if( button.GetName() == POPUP_BUTTON_TITLE_BUTTONS_ID )
398     {
399       mPopup = CreatePopup();
400       mPopup.SetTitle( "Popup!" );
401
402       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
403       cancelButton.SetName( CANCEL_BUTTON_ID );
404       cancelButton.SetLabel( "Cancel" );
405       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
406       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
407
408       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
409
410       mPopup.AddButton( cancelButton );
411
412       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
413       okayButton.SetName( OKAY_BUTTON_ID );
414       okayButton.SetLabel( "OK!" );
415       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
416       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
417
418       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
419
420       mPopup.AddButton( okayButton );
421
422       mPopup.Show();
423     }
424     else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
425     {
426       mPopup = CreatePopup();
427
428       TextLabel text = TextLabel::New( CONTENT_TEXT );
429       text.SetName( "POPUP_CONTENT_TEXT" );
430       text.SetProperty( TextLabel::Property::MULTI_LINE, true );
431       text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
432       text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
433       text.SetResizePolicy( FILL_TO_PARENT, Dali::HEIGHT );
434       text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
435
436       mPopup.Add( text );
437
438       mPopup.Show();
439     }
440     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
441     {
442       mPopup = CreatePopup();
443
444       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
445       image.SetResizePolicy( FILL_TO_PARENT, WIDTH );
446       image.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
447       image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
448
449       mPopup.Add( image );
450
451       mPopup.Show();
452     }
453     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
454     {
455       mPopup = CreatePopup();
456
457       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
458       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
459
460       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
461       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
462
463       mPopup.Add( image );
464
465       mPopup.Show();
466     }
467     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
468     {
469       mPopup = CreatePopup();
470
471       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
472       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
473
474       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
475       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
476       image.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO );
477
478       mPopup.Add( image );
479
480       mPopup.Show();
481     }
482     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
483     {
484       mPopup = CreatePopup();
485
486       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
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( FILL_WITH_ASPECT_RATIO );
492
493       mPopup.Add( image );
494
495       mPopup.Show();
496     }
497     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
498     {
499       mPopup = CreatePopup();
500       mPopup.SetTitle( "Popup!" );
501
502       Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
503       text.SetName( "POPUP_CONTENT_TEXT" );
504       text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
505       text.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
506       text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
507
508       mPopup.Add( text );
509
510       mPopup.Show();
511     }
512     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID )
513     {
514       mPopup = CreatePopup();
515       mPopup.SetTitle( "Popup!" );
516
517       Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
518       text.SetName( "POPUP_CONTENT_TEXT" );
519       text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
520       text.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
521       text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
522
523       mPopup.Add( text );
524
525       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
526       cancelButton.SetName( CANCEL_BUTTON_ID );
527       cancelButton.SetLabel( "Cancel" );
528       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
529       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
530
531       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
532
533       mPopup.AddButton( cancelButton );
534
535       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
536       okayButton.SetName( OKAY_BUTTON_ID );
537       okayButton.SetLabel( "OK!" );
538       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
539       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
540
541       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
542
543       mPopup.AddButton( okayButton );
544
545       mPopup.Show();
546     }
547     else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
548     {
549       mPopup = CreatePopup();
550       mPopup.SetTitle( "Warning" );
551
552       // Content
553       Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
554       content.SetName( "COMPLEX_TABLEVIEW" );
555       content.SetResizePolicy( FILL_TO_PARENT, WIDTH );
556       content.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
557       content.SetFitHeight( 0 );
558       content.SetFitHeight( 1 );
559       content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
560
561       // Text
562       {
563         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
564         text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
565         text.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
566
567         content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
568       }
569
570       // Image
571       {
572         ImageActor image = ImageActor::New( ResourceImage::New( IMAGE1 ) );
573         image.SetName( "COMPLEX_IMAGE" );
574         image.SetResizePolicy( FILL_TO_PARENT, WIDTH );
575         image.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
576         image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
577         content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
578       }
579
580       // Text 2
581       {
582         Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
583         root.SetResizePolicy( FILL_TO_PARENT, WIDTH );
584         root.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
585         root.SetFitHeight( 0 );
586         root.SetFitWidth( 0 );
587         root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
588
589         Dali::Image unchecked = Dali::ResourceImage::New( CHECKBOX_UNCHECKED_IMAGE );
590         Dali::Image checked = Dali::ResourceImage::New( CHECKBOX_CHECKED_IMAGE );
591         Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
592         checkBox.SetBackgroundImage( unchecked );
593         checkBox.SetSelectedImage( checked );
594         checkBox.SetSize( 48, 48 );
595
596         root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
597
598         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
599         Actor textActor = text;
600         textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
601
602         root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
603
604         content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
605       }
606
607       mPopup.Add( content );
608
609       // Buttons
610       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
611       cancelButton.SetName( CANCEL_BUTTON_ID );
612       cancelButton.SetLabel( "Cancel" );
613       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
614       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
615
616       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
617
618       mPopup.AddButton( cancelButton );
619
620       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
621       okayButton.SetName( OKAY_BUTTON_ID );
622       okayButton.SetLabel( "OK!" );
623       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
624       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
625
626       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
627
628       mPopup.AddButton( okayButton );
629
630       mPopup.Show();
631     }
632     else if( button.GetName() == TABLEVIEW_BUTTON_EMPTY_ID )
633     {
634       mPopup = CreatePopup();
635       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
636       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
637
638
639       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
640       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
641
642       mPopup.Add( table );
643
644       mPopup.Show();
645     }
646     else if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
647     {
648       mPopup = CreatePopup();
649       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
650       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
651
652
653       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
654       table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" );
655       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
656
657       Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
658       backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
659       table.Add( backing );
660
661       mPopup.Add( table );
662
663       mPopup.Show();
664     }
665     else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
666     {
667       mPopup = CreatePopup();
668       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
669       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
670
671
672       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
673       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
674
675       {
676         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
677         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
678         table.Add( backing );
679       }
680       {
681         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
682         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
683         table.Add( backing );
684       }
685       {
686         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
687         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
688         table.Add( backing );
689       }
690
691       mPopup.Add( table );
692
693       mPopup.Show();
694     }
695     else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
696     {
697       mPopup = CreatePopup();
698       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
699       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
700
701
702       Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
703       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
704
705       // Column 0
706       {
707         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
708         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
709         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
710       }
711       {
712         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
713         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
714         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
715       }
716       {
717         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
718         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
719         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
720       }
721
722       // Column 1
723       {
724         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
725         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
726         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
727       }
728       {
729         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
730         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
731         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
732       }
733       {
734         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
735         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
736         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
737       }
738
739       // Column 2
740       {
741         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
742         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
743         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
744       }
745       {
746         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
747         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
748         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
749       }
750       {
751         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
752         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
753         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
754       }
755
756       mPopup.Add( table );
757
758       mPopup.Show();
759     }
760     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
761     {
762       mPopup = CreatePopup();
763       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
764       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
765
766
767       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
768       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
769       table.SetFixedHeight( 0, 50.0f );
770
771       {
772         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
773         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
774         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
775         text.SetAnchorPoint( AnchorPoint::CENTER );
776         text.SetParentOrigin( ParentOrigin::CENTER );
777         backing.Add( text );
778         table.Add( backing );
779       }
780       {
781         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
782         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
783         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
784         text.SetAnchorPoint( AnchorPoint::CENTER );
785         text.SetParentOrigin( ParentOrigin::CENTER );
786         backing.Add( text );
787         table.Add( backing );
788       }
789       {
790         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
791         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
792         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
793         text.SetAnchorPoint( AnchorPoint::CENTER );
794         text.SetParentOrigin( ParentOrigin::CENTER );
795         backing.Add( text );
796         table.Add( backing );
797       }
798
799       mPopup.Add( table );
800
801       mPopup.Show();
802     }
803     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
804     {
805       mPopup = CreatePopup();
806       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
807       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
808
809
810       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
811       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
812       table.SetFixedHeight( 0, 50.0f );
813       table.SetFixedHeight( 2, 50.0f );
814
815       {
816         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
817         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
818         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
819         text.SetAnchorPoint( AnchorPoint::CENTER );
820         text.SetParentOrigin( ParentOrigin::CENTER );
821         backing.Add( text );
822         table.Add( backing );
823       }
824       {
825         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
826         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
827         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
828         text.SetAnchorPoint( AnchorPoint::CENTER );
829         text.SetParentOrigin( ParentOrigin::CENTER );
830         backing.Add( text );
831         table.Add( backing );
832       }
833       {
834         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
835         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
836         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
837         text.SetAnchorPoint( AnchorPoint::CENTER );
838         text.SetParentOrigin( ParentOrigin::CENTER );
839         backing.Add( text );
840         table.Add( backing );
841       }
842
843       mPopup.Add( table );
844
845       mPopup.Show();
846     }
847     else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
848     {
849       mPopup = CreatePopup();
850       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
851       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
852
853
854       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
855       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
856       table.SetFitHeight( 0 );
857       table.SetFitHeight( 2 );
858
859       {
860         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
861         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
862         backing.SetSize( 0.0f, 100.0f );
863
864         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
865         text.SetAnchorPoint( AnchorPoint::CENTER );
866         text.SetParentOrigin( ParentOrigin::CENTER );
867         backing.Add( text );
868
869         table.Add( backing );
870       }
871       {
872         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
873         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
874
875         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
876         text.SetAnchorPoint( AnchorPoint::CENTER );
877         text.SetParentOrigin( ParentOrigin::CENTER );
878         backing.Add( text );
879
880         table.Add( backing );
881       }
882       {
883         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
884         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
885         backing.SetSize( 0.0f, 100.0f );
886
887         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
888         text.SetAnchorPoint( AnchorPoint::CENTER );
889         text.SetParentOrigin( ParentOrigin::CENTER );
890         backing.Add( text );
891
892         table.Add( backing );
893       }
894
895       mPopup.Add( table );
896
897       mPopup.Show();
898     }
899     else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
900     {
901       mPopup = CreatePopup();
902       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS );
903       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
904
905       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
906       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
907       table.SetFitHeight( 1 );
908
909       {
910         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
911         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
912
913         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
914         text.SetAnchorPoint( AnchorPoint::CENTER );
915         text.SetParentOrigin( ParentOrigin::CENTER );
916         backing.Add( text );
917
918         table.Add( backing );
919       }
920       {
921         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
922         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
923         backing.SetSize( 0.0f, 200.0f );
924
925         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
926         text.SetAnchorPoint( AnchorPoint::CENTER );
927         text.SetParentOrigin( ParentOrigin::CENTER );
928         backing.Add( text );
929
930         table.Add( backing );
931       }
932       {
933         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
934         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
935
936         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
937         text.SetAnchorPoint( AnchorPoint::CENTER );
938         text.SetParentOrigin( ParentOrigin::CENTER );
939         backing.Add( text );
940
941         table.Add( backing );
942       }
943
944       mPopup.Add( table );
945
946       mPopup.Show();
947     }
948     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
949     {
950       mPopup = CreatePopup();
951       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, WIDTH );
952       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
953       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
954
955       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
956       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
957       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
958       table.SetFitHeight( 0 );
959       table.SetFitHeight( 1 );
960       table.SetFitHeight( 2 );
961
962       {
963         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
964         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
965         backing.SetSize( 0.0f, 100.0f );
966
967         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
968         text.SetAnchorPoint( AnchorPoint::CENTER );
969         text.SetParentOrigin( ParentOrigin::CENTER );
970         backing.Add( text );
971
972         table.Add( backing );
973       }
974       {
975         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
976         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
977         backing.SetSize( 0.0f, 200.0f );
978
979         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
980         text.SetAnchorPoint( AnchorPoint::CENTER );
981         text.SetParentOrigin( ParentOrigin::CENTER );
982         backing.Add( text );
983
984         table.Add( backing );
985       }
986       {
987         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
988         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
989         backing.SetSize( 0.0f, 300.0f );
990
991         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
992         text.SetAnchorPoint( AnchorPoint::CENTER );
993         text.SetParentOrigin( ParentOrigin::CENTER );
994         backing.Add( text );
995
996         table.Add( backing );
997       }
998
999       mPopup.Add( table );
1000
1001       mPopup.Show();
1002     }
1003     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
1004     {
1005       mPopup = CreatePopup();
1006       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, WIDTH );
1007       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1008       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1009
1010       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1011       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1012       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1013       table.SetFitHeight( 0 );
1014       table.SetFitHeight( 1 );
1015
1016       {
1017         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1018         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1019         backing.SetResizePolicy( FIXED, HEIGHT );
1020         backing.SetSize( 0.0f, 100.0f );
1021
1022         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1023         text.SetAnchorPoint( AnchorPoint::CENTER );
1024         text.SetParentOrigin( ParentOrigin::CENTER );
1025         backing.Add( text );
1026
1027         table.Add( backing );
1028       }
1029       {
1030         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1031         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1032         backing.SetSize( 0.0f, 200.0f );
1033
1034         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1035         text.SetAnchorPoint( AnchorPoint::CENTER );
1036         text.SetParentOrigin( ParentOrigin::CENTER );
1037         backing.Add( text );
1038
1039         table.Add( backing );
1040       }
1041
1042       mPopup.Add( table );
1043
1044       mPopup.Show();
1045     }
1046     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
1047     {
1048       mPopup = CreatePopup();
1049       mPopup.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, WIDTH );
1050       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1051       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1052
1053       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1054       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1055       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1056       table.SetFixedHeight( 0, 20.0f );
1057       table.SetFitHeight( 1 );
1058
1059       {
1060         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1061         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
1062
1063         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
1064         text.SetAnchorPoint( AnchorPoint::CENTER );
1065         text.SetParentOrigin( ParentOrigin::CENTER );
1066         backing.Add( text );
1067
1068         table.Add( backing );
1069       }
1070       {
1071         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1072         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1073         backing.SetSize( 0.0f, 200.0f );
1074
1075         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
1076         text.SetAnchorPoint( AnchorPoint::CENTER );
1077         text.SetParentOrigin( ParentOrigin::CENTER );
1078         backing.Add( text );
1079
1080         table.Add( backing );
1081       }
1082
1083       mPopup.Add( table );
1084
1085       mPopup.Show();
1086     }
1087     else if( button.GetName() == OKAY_BUTTON_ID || button.GetName() == CANCEL_BUTTON_ID )
1088     {
1089       if( mPopup )
1090       {
1091         mPopup.Hide();
1092       }
1093     }
1094
1095     return true;
1096   }
1097
1098   void OnPopupOutsideTouched()
1099   {
1100     if( mPopup )
1101     {
1102       mPopup.Hide();
1103     }
1104   }
1105
1106   void OnKeyEvent( const KeyEvent& event )
1107   {
1108     if( event.state == KeyEvent::Down )
1109     {
1110       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
1111       {
1112         // Exit application when click back or escape.
1113         mApplication.Quit();
1114       }
1115     }
1116   }
1117
1118 public: // From ItemFactory
1119
1120   /**
1121    * @brief Return the number of items to display in the item view
1122    *
1123    * @return Return the number of items to display
1124    */
1125   virtual unsigned int GetNumberOfItems()
1126   {
1127     switch( mDemoState )
1128     {
1129       case POPUP:
1130       {
1131         return POPUP_BUTTON_ITEMS_COUNT;
1132       }
1133
1134       case TABLEVIEW:
1135       {
1136         return TABLEVIEW_BUTTON_ITEMS_COUNT;
1137       }
1138
1139       default:
1140       {
1141         break;
1142       }
1143     }
1144
1145     return 0;
1146   }
1147
1148   /**
1149    * @brief Create a new item to populate the item view with
1150    *
1151    * @param[in] itemId The index of the item to create
1152    * @return Return the created actor for the given ID
1153    */
1154   virtual Actor NewItem(unsigned int itemId)
1155   {
1156     const ButtonItem* buttonDataArray = NULL;
1157     switch( mDemoState )
1158     {
1159       case POPUP:
1160       {
1161         buttonDataArray = POPUP_BUTTON_ITEMS;
1162         break;
1163       }
1164
1165       case TABLEVIEW:
1166       {
1167         buttonDataArray = TABLEVIEW_BUTTON_ITEMS;
1168         break;
1169       }
1170
1171       default:
1172       {
1173         break;
1174       }
1175     }
1176
1177     if( buttonDataArray )
1178     {
1179       Toolkit::PushButton popupButton = Toolkit::PushButton::New();
1180       popupButton.SetName( buttonDataArray[ itemId ].name );
1181       popupButton.SetLabel( buttonDataArray[ itemId ].text );
1182       popupButton.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
1183
1184       popupButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
1185       popupButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
1186
1187       popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
1188
1189       return popupButton;
1190     }
1191
1192     return Actor();
1193   }
1194
1195 private:
1196
1197   enum DemoState
1198   {
1199     POPUP,
1200     TABLEVIEW
1201   };
1202
1203   Application&      mApplication;
1204   Toolkit::View     mView;                   ///< The View instance.
1205   Toolkit::ToolBar  mToolBar;                ///< The View's Toolbar.
1206   Layer             mContentLayer;           ///< Content layer
1207
1208   Toolkit::TextLabel mTitleActor;             ///< Title text
1209
1210   Toolkit::Popup    mMenu;                   ///< The navigation menu
1211   bool              mMenuShown;              ///< If the navigation menu is currently being displayed or not
1212
1213   Toolkit::Popup    mPopup;
1214
1215   Toolkit::ItemView mItemView;               ///< ItemView to hold test images
1216
1217   DemoState mDemoState;
1218 };
1219
1220 void RunTest( Application& application )
1221 {
1222   SizeNegotiationController test( application );
1223
1224   application.MainLoop();
1225 }
1226
1227 // Entry point for Linux & SLP applications
1228 //
1229 int main( int argc, char **argv )
1230 {
1231   Application application = Application::New( &argc, &argv );
1232
1233   RunTest( application );
1234
1235   return 0;
1236 }