Size negotiation example
[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.SetPreferredSize( Vector2( 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.SetPreferredSize( Vector2( 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.SetDimensionDependency( HEIGHT, WIDTH );
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.SetDimensionDependency( HEIGHT, WIDTH );
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( FILL_TO_PARENT, ALL_DIMENSIONS );
479       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
480       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
481
482       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
483       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
484
485       mPopup.Add( image );
486
487       // The popup is not yet on the stage so needs to be flaged as dirty
488       mPopup.MarkDirtyForRelayout();
489
490       mPopup.Show();
491     }
492     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
493     {
494       mPopup = CreatePopup();
495
496       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
497       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
498       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
499
500       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
501       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
502       image.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO );
503
504       mPopup.Add( image );
505
506       // The popup is not yet on the stage so needs to be flaged as dirty
507       mPopup.MarkDirtyForRelayout();
508
509       mPopup.Show();
510     }
511     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
512     {
513       mPopup = CreatePopup();
514
515       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
516       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
517       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
518
519       ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
520       image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
521       image.SetSizeScalePolicy( FILL_WITH_ASPECT_RATIO );
522
523       mPopup.Add( image );
524
525       // The popup is not yet on the stage so needs to be flaged as dirty
526       mPopup.MarkDirtyForRelayout();
527
528       mPopup.Show();
529     }
530     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
531     {
532       mPopup = CreatePopup();
533       mPopup.SetTitle( "Popup!" );
534
535       Toolkit::TextView text = Toolkit::TextView::New();
536       text.SetName( "POPUP_CONTENT_TEXT" );
537       text.SetText( CONTENT_TEXT );
538       text.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
539       text.SetWidthExceedPolicy( Toolkit::TextView::Split );
540       text.SetLineJustification( Toolkit::TextView::Center );
541       text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
542       text.SetDimensionDependency( HEIGHT, WIDTH );
543       text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
544
545       mPopup.Add( text );
546
547       // The popup is not yet on the stage so needs to be flaged as dirty
548       mPopup.MarkDirtyForRelayout();
549
550       mPopup.Show();
551     }
552     else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID )
553     {
554       mPopup = CreatePopup();
555       mPopup.SetTitle( "Popup!" );
556
557       Toolkit::TextView text = Toolkit::TextView::New();
558       text.SetName( "POPUP_CONTENT_TEXT" );
559       text.SetText( CONTENT_TEXT );
560       text.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
561       text.SetWidthExceedPolicy( Toolkit::TextView::Split );
562       text.SetLineJustification( Toolkit::TextView::Left );
563       text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
564       text.SetDimensionDependency( HEIGHT, WIDTH );
565       text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
566
567       mPopup.Add( text );
568
569       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
570       cancelButton.SetName( CANCEL_BUTTON_ID );
571       cancelButton.SetLabel( "Cancel" );
572       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
573       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
574
575       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
576
577       mPopup.AddButton( cancelButton );
578
579       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
580       okayButton.SetName( OKAY_BUTTON_ID );
581       okayButton.SetLabel( "OK!" );
582       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
583       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
584
585       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
586
587       mPopup.AddButton( okayButton );
588
589       // The popup is not yet on the stage so needs to be flaged as dirty
590       mPopup.MarkDirtyForRelayout();
591
592       mPopup.Show();
593     }
594     else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
595     {
596       mPopup = CreatePopup();
597       mPopup.SetTitle( "Warning" );
598
599       // Content
600       Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
601       content.SetName( "COMPLEX_TABLEVIEW" );
602       content.SetResizePolicy( FILL_TO_PARENT, WIDTH );
603       content.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
604       content.SetFitHeight( 0 );
605       content.SetFitHeight( 1 );
606       content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
607
608       // Text
609       {
610         Toolkit::TextView text = Toolkit::TextView::New();
611         text.SetText( "Do you really want to quit?" );
612         text.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
613         text.SetWidthExceedPolicy( Toolkit::TextView::Split );
614         text.SetLineJustification( Toolkit::TextView::Left );
615         text.SetResizePolicy( FILL_TO_PARENT, WIDTH );
616         text.SetDimensionDependency( HEIGHT, WIDTH );
617
618         content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
619       }
620
621       // Image
622       {
623         ImageActor image = ImageActor::New( ResourceImage::New( IMAGE1 ) );
624         image.SetName( "COMPLEX_IMAGE" );
625         image.SetResizePolicy( FILL_TO_PARENT, WIDTH );
626         image.SetDimensionDependency( HEIGHT, WIDTH );
627         image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
628         content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
629       }
630
631       // Text 2
632       {
633         Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
634         root.SetResizePolicy( FILL_TO_PARENT, WIDTH );
635         root.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
636         root.SetFitHeight( 0 );
637         root.SetFitWidth( 0 );
638         root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
639
640         Dali::Image unchecked = Dali::ResourceImage::New( CHECKBOX_UNCHECKED_IMAGE );
641         Dali::Image checked = Dali::ResourceImage::New( CHECKBOX_CHECKED_IMAGE );
642         Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
643         checkBox.SetBackgroundImage( unchecked );
644         checkBox.SetSelectedImage( checked );
645         checkBox.SetPreferredSize( Vector2( 48, 48 ) );
646         checkBox.SetResizePolicy( FIXED, ALL_DIMENSIONS );
647
648         root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
649
650         Toolkit::TextView text = Toolkit::TextView::New();
651         text.SetText( "Don't show again" );
652         text.SetLineJustification( Toolkit::TextView::Left );
653         Actor textActor = text;
654         textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
655
656         root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
657
658         content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0, 0, 2 ) );  // Column span 2
659       }
660
661       mPopup.Add( content );
662
663       // Buttons
664       Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
665       cancelButton.SetName( CANCEL_BUTTON_ID );
666       cancelButton.SetLabel( "Cancel" );
667       cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
668       cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
669
670       cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
671
672       mPopup.AddButton( cancelButton );
673
674       Toolkit::PushButton okayButton = Toolkit::PushButton::New();
675       okayButton.SetName( OKAY_BUTTON_ID );
676       okayButton.SetLabel( "OK!" );
677       okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
678       okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
679
680       okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
681
682       mPopup.AddButton( okayButton );
683
684       // The popup is not yet on the stage so needs to be flaged as dirty
685       mPopup.MarkDirtyForRelayout();
686
687       mPopup.Show();
688     }
689     else if( button.GetName() == TABLEVIEW_BUTTON_EMPTY_ID )
690     {
691       mPopup = CreatePopup();
692       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
693       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
694       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
695
696
697       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
698       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
699
700       mPopup.Add( table );
701
702       // The popup is not yet on the stage so needs to be flaged as dirty
703       mPopup.MarkDirtyForRelayout();
704
705       mPopup.Show();
706     }
707     else if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
708     {
709       mPopup = CreatePopup();
710       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
711       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
712       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
713
714
715       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
716       table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" );
717       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
718
719       Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
720       backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
721       table.Add( backing );
722
723       mPopup.Add( table );
724
725       // The popup is not yet on the stage so needs to be flaged as dirty
726       mPopup.MarkDirtyForRelayout();
727
728       mPopup.Show();
729     }
730     else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
731     {
732       mPopup = CreatePopup();
733       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
734       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
735       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
736
737
738       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
739       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
740
741       {
742         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
743         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
744         table.Add( backing );
745       }
746       {
747         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
748         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
749         table.Add( backing );
750       }
751       {
752         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
753         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
754         table.Add( backing );
755       }
756
757       mPopup.Add( table );
758
759       // The popup is not yet on the stage so needs to be flaged as dirty
760       mPopup.MarkDirtyForRelayout();
761
762       mPopup.Show();
763     }
764     else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
765     {
766       mPopup = CreatePopup();
767       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
768       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
769       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
770
771
772       Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
773       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
774
775       // Column 0
776       {
777         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
778         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
779         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
780       }
781       {
782         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
783         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
784         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
785       }
786       {
787         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
788         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
789         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
790       }
791
792       // Column 1
793       {
794         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
795         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
796         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
797       }
798       {
799         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
800         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
801         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
802       }
803       {
804         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
805         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
806         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
807       }
808
809       // Column 2
810       {
811         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
812         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
813         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
814       }
815       {
816         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
817         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
818         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
819       }
820       {
821         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
822         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
823         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
824       }
825
826       mPopup.Add( table );
827
828       // The popup is not yet on the stage so needs to be flaged as dirty
829       mPopup.MarkDirtyForRelayout();
830
831       mPopup.Show();
832     }
833     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
834     {
835       mPopup = CreatePopup();
836       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
837       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
838       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
839
840
841       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
842       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
843       table.SetFixedHeight( 0, 50.0f );
844
845       {
846         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
847         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
848         TextActor text = TextActor::New( "Fixed" );
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( 1.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         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
865         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
866         TextActor text = TextActor::New( "Fill" );
867         text.SetAnchorPoint( AnchorPoint::CENTER );
868         text.SetParentOrigin( ParentOrigin::CENTER );
869         backing.Add( text );
870         table.Add( backing );
871       }
872
873       mPopup.Add( table );
874
875       // The popup is not yet on the stage so needs to be flaged as dirty
876       mPopup.MarkDirtyForRelayout();
877
878       mPopup.Show();
879     }
880     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
881     {
882       mPopup = CreatePopup();
883       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
884       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
885       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
886
887
888       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
889       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
890       table.SetFixedHeight( 0, 50.0f );
891       table.SetFixedHeight( 2, 50.0f );
892
893       {
894         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
895         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
896         TextActor text = TextActor::New( "Fixed" );
897         text.SetAnchorPoint( AnchorPoint::CENTER );
898         text.SetParentOrigin( ParentOrigin::CENTER );
899         backing.Add( text );
900         table.Add( backing );
901       }
902       {
903         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
904         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
905         TextActor text = TextActor::New( "Fill" );
906         text.SetAnchorPoint( AnchorPoint::CENTER );
907         text.SetParentOrigin( ParentOrigin::CENTER );
908         backing.Add( text );
909         table.Add( backing );
910       }
911       {
912         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
913         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
914         TextActor text = TextActor::New( "Fixed" );
915         text.SetAnchorPoint( AnchorPoint::CENTER );
916         text.SetParentOrigin( ParentOrigin::CENTER );
917         backing.Add( text );
918         table.Add( backing );
919       }
920
921       mPopup.Add( table );
922
923       // The popup is not yet on the stage so needs to be flaged as dirty
924       mPopup.MarkDirtyForRelayout();
925
926       mPopup.Show();
927     }
928     else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
929     {
930       mPopup = CreatePopup();
931       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
932       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
933       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
934
935
936       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
937       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
938       table.SetFitHeight( 0 );
939       table.SetFitHeight( 2 );
940
941       {
942         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
943         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
944         backing.SetResizePolicy( FIXED, HEIGHT );
945         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
946
947         TextActor text = TextActor::New( "Fit" );
948         text.SetAnchorPoint( AnchorPoint::CENTER );
949         text.SetParentOrigin( ParentOrigin::CENTER );
950         backing.Add( text );
951
952         table.Add( backing );
953       }
954       {
955         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
956         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
957
958         TextActor text = TextActor::New( "Fill" );
959         text.SetAnchorPoint( AnchorPoint::CENTER );
960         text.SetParentOrigin( ParentOrigin::CENTER );
961         backing.Add( text );
962
963         table.Add( backing );
964       }
965       {
966         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
967         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
968         backing.SetResizePolicy( FIXED, HEIGHT );
969         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
970
971         TextActor text = TextActor::New( "Fit" );
972         text.SetAnchorPoint( AnchorPoint::CENTER );
973         text.SetParentOrigin( ParentOrigin::CENTER );
974         backing.Add( text );
975
976         table.Add( backing );
977       }
978
979       mPopup.Add( table );
980
981       // The popup is not yet on the stage so needs to be flaged as dirty
982       mPopup.MarkDirtyForRelayout();
983
984       mPopup.Show();
985     }
986     else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
987     {
988       mPopup = CreatePopup();
989       mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
990       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
991       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
992
993
994       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
995       table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
996       table.SetFitHeight( 1 );
997
998       {
999         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1000         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
1001
1002         TextActor text = TextActor::New( "Fill" );
1003         text.SetAnchorPoint( AnchorPoint::CENTER );
1004         text.SetParentOrigin( ParentOrigin::CENTER );
1005         backing.Add( text );
1006
1007         table.Add( backing );
1008       }
1009       {
1010         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
1011         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1012         backing.SetResizePolicy( FIXED, HEIGHT );
1013         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1014
1015         TextActor text = TextActor::New( "Fit" );
1016         text.SetAnchorPoint( AnchorPoint::CENTER );
1017         text.SetParentOrigin( ParentOrigin::CENTER );
1018         backing.Add( text );
1019
1020         table.Add( backing );
1021       }
1022       {
1023         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1024         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
1025
1026         TextActor text = TextActor::New( "Fill" );
1027         text.SetAnchorPoint( AnchorPoint::CENTER );
1028         text.SetParentOrigin( ParentOrigin::CENTER );
1029         backing.Add( text );
1030
1031         table.Add( backing );
1032       }
1033
1034       mPopup.Add( table );
1035
1036       // The popup is not yet on the stage so needs to be flaged as dirty
1037       mPopup.MarkDirtyForRelayout();
1038
1039       mPopup.Show();
1040     }
1041     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
1042     {
1043       mPopup = CreatePopup();
1044       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1045       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1046       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1047       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1048
1049       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1050       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1051       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1052       table.SetFitHeight( 0 );
1053       table.SetFitHeight( 1 );
1054       table.SetFitHeight( 2 );
1055
1056       {
1057         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1058         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1059         backing.SetResizePolicy( FIXED, HEIGHT );
1060         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
1061
1062         TextActor text = TextActor::New( "Fit" );
1063         text.SetAnchorPoint( AnchorPoint::CENTER );
1064         text.SetParentOrigin( ParentOrigin::CENTER );
1065         backing.Add( text );
1066
1067         table.Add( backing );
1068       }
1069       {
1070         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
1071         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1072         backing.SetResizePolicy( FIXED, HEIGHT );
1073         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1074
1075         TextActor text = TextActor::New( "Fit" );
1076         text.SetAnchorPoint( AnchorPoint::CENTER );
1077         text.SetParentOrigin( ParentOrigin::CENTER );
1078         backing.Add( text );
1079
1080         table.Add( backing );
1081       }
1082       {
1083         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1084         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1085         backing.SetResizePolicy( FIXED, HEIGHT );
1086         backing.SetPreferredSize( Vector2( 0.0f, 300.0f ) );
1087
1088         TextActor text = TextActor::New( "Fit" );
1089         text.SetAnchorPoint( AnchorPoint::CENTER );
1090         text.SetParentOrigin( ParentOrigin::CENTER );
1091         backing.Add( text );
1092
1093         table.Add( backing );
1094       }
1095
1096       mPopup.Add( table );
1097
1098       // The popup is not yet on the stage so needs to be flaged as dirty
1099       mPopup.MarkDirtyForRelayout();
1100
1101       mPopup.Show();
1102     }
1103     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
1104     {
1105       mPopup = CreatePopup();
1106       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1107       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1108       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1109       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1110
1111       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1112       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1113       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1114       table.SetFitHeight( 0 );
1115       table.SetFitHeight( 1 );
1116
1117       {
1118         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1119         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1120         backing.SetResizePolicy( FIXED, HEIGHT );
1121         backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) );
1122
1123         TextActor text = TextActor::New( "Fit" );
1124         text.SetAnchorPoint( AnchorPoint::CENTER );
1125         text.SetParentOrigin( ParentOrigin::CENTER );
1126         backing.Add( text );
1127
1128         table.Add( backing );
1129       }
1130       {
1131         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1132         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1133         backing.SetResizePolicy( FIXED, HEIGHT );
1134         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1135
1136         TextActor text = TextActor::New( "Fit" );
1137         text.SetAnchorPoint( AnchorPoint::CENTER );
1138         text.SetParentOrigin( ParentOrigin::CENTER );
1139         backing.Add( text );
1140
1141         table.Add( backing );
1142       }
1143
1144       mPopup.Add( table );
1145
1146       // The popup is not yet on the stage so needs to be flaged as dirty
1147       mPopup.MarkDirtyForRelayout();
1148
1149       mPopup.Show();
1150     }
1151     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
1152     {
1153       mPopup = CreatePopup();
1154       mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1155       mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1156       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
1157       mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
1158
1159       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
1160       table.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1161       table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
1162       table.SetFixedHeight( 0, 20.0f );
1163       table.SetFitHeight( 1 );
1164
1165       {
1166         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
1167         backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
1168
1169         TextActor text = TextActor::New( "Fixed" );
1170         text.SetAnchorPoint( AnchorPoint::CENTER );
1171         text.SetParentOrigin( ParentOrigin::CENTER );
1172         backing.Add( text );
1173
1174         table.Add( backing );
1175       }
1176       {
1177         Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
1178         backing.SetResizePolicy( FILL_TO_PARENT, WIDTH );
1179         backing.SetResizePolicy( FIXED, HEIGHT );
1180         backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) );
1181
1182         TextActor text = TextActor::New( "Fit" );
1183         text.SetAnchorPoint( AnchorPoint::CENTER );
1184         text.SetParentOrigin( ParentOrigin::CENTER );
1185         backing.Add( text );
1186
1187         table.Add( backing );
1188       }
1189
1190       mPopup.Add( table );
1191
1192       // The popup is not yet on the stage so needs to be flaged as dirty
1193       mPopup.MarkDirtyForRelayout();
1194
1195       mPopup.Show();
1196     }
1197     else if( button.GetName() == OKAY_BUTTON_ID || button.GetName() == CANCEL_BUTTON_ID )
1198     {
1199       if( mPopup )
1200       {
1201         mPopup.Hide();
1202       }
1203     }
1204
1205     return true;
1206   }
1207
1208   void OnPopupOutsideTouched()
1209   {
1210     if( mPopup )
1211     {
1212       mPopup.Hide();
1213     }
1214   }
1215
1216   void OnKeyEvent( const KeyEvent& event )
1217   {
1218     if( event.state == KeyEvent::Down )
1219     {
1220       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
1221       {
1222         // Exit application when click back or escape.
1223         mApplication.Quit();
1224       }
1225     }
1226   }
1227
1228 public: // From ItemFactory
1229
1230   /**
1231    * @brief Return the number of items to display in the item view
1232    *
1233    * @return Return the number of items to display
1234    */
1235   virtual unsigned int GetNumberOfItems()
1236   {
1237     switch( mDemoState )
1238     {
1239       case POPUP:
1240       {
1241         return POPUP_BUTTON_ITEMS_COUNT;
1242       }
1243
1244       case TABLEVIEW:
1245       {
1246         return TABLEVIEW_BUTTON_ITEMS_COUNT;
1247       }
1248
1249       default:
1250       {
1251         break;
1252       }
1253     }
1254
1255     return 0;
1256   }
1257
1258   /**
1259    * @brief Create a new item to populate the item view with
1260    *
1261    * @param[in] itemId The index of the item to create
1262    * @return Return the created actor for the given ID
1263    */
1264   virtual Actor NewItem(unsigned int itemId)
1265   {
1266     const ButtonItem* buttonDataArray = NULL;
1267     switch( mDemoState )
1268     {
1269       case POPUP:
1270       {
1271         buttonDataArray = POPUP_BUTTON_ITEMS;
1272         break;
1273       }
1274
1275       case TABLEVIEW:
1276       {
1277         buttonDataArray = TABLEVIEW_BUTTON_ITEMS;
1278         break;
1279       }
1280
1281       default:
1282       {
1283         break;
1284       }
1285     }
1286
1287     if( buttonDataArray )
1288     {
1289       Toolkit::PushButton popupButton = Toolkit::PushButton::New();
1290       popupButton.SetName( buttonDataArray[ itemId ].name );
1291       popupButton.SetLabel( buttonDataArray[ itemId ].text );
1292       popupButton.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
1293
1294       popupButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
1295       popupButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
1296
1297       popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
1298
1299       return popupButton;
1300     }
1301
1302     return Actor();
1303   }
1304
1305 private:
1306
1307   enum DemoState
1308   {
1309     POPUP,
1310     TABLEVIEW
1311   };
1312
1313   Application&      mApplication;
1314   Toolkit::View     mView;                   ///< The View instance.
1315   Toolkit::ToolBar  mToolBar;                ///< The View's Toolbar.
1316   Layer             mContentLayer;           ///< Content layer
1317
1318   Toolkit::TextView mTitleActor;             ///< Title text
1319
1320   Toolkit::Popup    mMenu;                   ///< The navigation menu
1321   bool              mMenuShown;              ///< If the navigation menu is currently being displayed or not
1322
1323   Toolkit::Popup    mPopup;
1324
1325   Toolkit::ItemView mItemView;               ///< ItemView to hold test images
1326
1327   DemoState mDemoState;
1328 };
1329
1330 void RunTest( Application& application )
1331 {
1332   SizeNegotiationController test( application );
1333
1334   application.MainLoop();
1335 }
1336
1337 // Entry point for Linux & SLP applications
1338 //
1339 int main( int argc, char **argv )
1340 {
1341   Application application = Application::New( &argc, &argv );
1342
1343   RunTest( application );
1344
1345   return 0;
1346 }