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