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