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