Remove dependency to std::vector and property::value from property notification API
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-frame / navigation-bar.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 // CLASS HEADER
19 #include "navigation-bar.h"
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 NavigationBar::NavigationBar(NavigationControl& naviControl,
36                              Toolkit::BasicNaviBarStyle barStylePortrait,
37                              Toolkit::BasicNaviBarStyle barStyleLandscape )
38 :mInternalNavigationControl( naviControl ),
39  mBasicStylePortrait( barStylePortrait ),
40  mBasicStyleLandscape( barStyleLandscape ),
41  mBasicCurrentStyle( &mBasicStylePortrait ),
42  mIsPortrait( true ),
43  mVisible( true )
44 {
45   mInternalNavigationControl.ItemPushedSignal().Connect( this, &NavigationBar::OnItemPushed );
46   mInternalNavigationControl.ItemPoppedSignal().Connect( this, &NavigationBar::OnItemPopped );
47
48   mLayout = Toolkit::TableView::New(1,3);
49   mInternalNavigationControl.GetBarLayer().Add(mLayout);
50   mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
51   mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
52   mLayout.SetDrawMode(DrawMode::OVERLAY);
53
54   SetBackground( mBasicCurrentStyle->background );
55 }
56
57 NavigationBar::~NavigationBar()
58 {
59 }
60
61 void NavigationBar::ScaleStyleUpdate( Vector2 naviControlSize, int orientation )
62 {
63   bool isPortrait( orientation == 0 || orientation == 180 );
64   // change in orientation.
65   if(mIsPortrait != isPortrait)
66   {
67     mIsPortrait = isPortrait;
68     mBasicCurrentStyle = isPortrait ? &mBasicStylePortrait : &mBasicStyleLandscape;
69     OrientationUpdate( isPortrait );
70     mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
71     mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
72     if(mBackground)
73     {
74       mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
75     }
76   }
77
78   mRelativeScale = naviControlSize.x / static_cast<float>( mBasicCurrentStyle->referenceWidth);
79   mLayout.SetScale(mRelativeScale);
80   mBarHeight = mBasicCurrentStyle->height * mRelativeScale;
81   if(mBackground)
82   {
83     mBackground.SetScale(mRelativeScale);
84   }
85 }
86
87 float NavigationBar::GetBarHeight() const
88 {
89   if( mVisible )
90   {
91     return mBarHeight;
92   }
93   else
94   {
95     return 0.0f;
96   }
97 }
98
99 void NavigationBar::SetBackground( Actor background )
100 {
101   mBackground = background;
102   mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
103   mInternalNavigationControl.GetBarLayer().Add( mBackground );
104   mBackground.SetScale(mRelativeScale);
105 }
106
107 void NavigationBar::OnItemPushed( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
108 {
109   mCurrentItem = naviItem;
110   Update( mCurrentItem );
111 }
112
113 void NavigationBar::OnItemPopped( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
114 {
115   mCurrentItem = mInternalNavigationControl.GetCurrentItem();
116   Update( mCurrentItem );
117 }
118
119 } // namespace Internal
120
121 } // namespace Toolkit
122
123 } // namespace Dali