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