Follow the include-order coding conventions
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-frame / navigation-title-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-title-bar.h"
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Internal
28 {
29
30 //ToDo: use const variables instead of magic numbers
31
32 NavigationTitleBar::NavigationTitleBar(NavigationControl& naviControl,
33                                        Toolkit::NaviTitleBarStyle titleBarStylePortrait,
34                                        Toolkit::NaviTitleBarStyle titleBarStyleLandscape )
35 : NavigationBar(naviControl, titleBarStylePortrait, titleBarStyleLandscape ),
36   mStylePortrait( titleBarStylePortrait ),
37   mStyleLandscape( titleBarStyleLandscape ),
38   mCurrentStyle( &mStylePortrait )
39 {
40   // title bar is located at the top of the frame
41   mLayout.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
42   mLayout.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
43   if(mBackground)
44   {
45     mBackground.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
46     mBackground.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
47   }
48
49   // button layout: three rows, controls will be put in the middle row, the top and bottom rows are just for margins
50   mButtonLayout = Toolkit::TableView::New(3, 1);
51   // title layout: fours rows, the top and bottom rows are just for margins
52   // if subtitle exists, title in the second row and subtitle in the third row
53   // if no subtitle, title will occupy both second and third row
54   mTitleLayout= Toolkit::TableView::New( 4,1 );
55   // title icon layout: the top row, the bottom row and the left column are all for margins
56   mTitleIconLayout= Toolkit::TableView::New( 3,2 );
57   SetFixedSizes();
58
59   mTitle = Toolkit::TextView::New();
60   mTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
61   mTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
62   mSubTitle = Toolkit::TextView::New();
63   mSubTitle.SetTextAlignment( Toolkit::Alignment::HorizontalLeft );
64   mSubTitle.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit);
65 }
66
67 void NavigationTitleBar::Update( Toolkit::Page page )
68 {
69   const std::vector<Actor>& controls = page.GetControlsOnTitleBar();
70
71   // if there is no control to place on the bar ano no title is set, hide the bar
72   if(controls.empty() && page.GetTitle().empty())
73   {
74     mVisible = false;
75     mLayout.SetVisible(false);
76     mBackground.SetVisible(false);
77     return;
78   }
79
80   if(mLayout.GetColumns() == 4)// | leftMargin | titleLayout(may have icon and subtitle) | buttonLayout | rightMargin |
81   {
82     //remove buttonLayout
83     mLayout.DeleteColumn(2);
84   }
85   // remove titleLayout
86   mLayout.RemoveChildAt( Toolkit::TableView::CellPosition(0,1) );
87   //Remove the controls in the buttonLayout
88   mButtonLayout.Resize(3,1);
89   //remove titleIcon
90   if(mTitleLayout.GetColumns() == 2)
91   {
92     mTitleLayout.DeleteColumn( 0 );
93   }
94   // remove title and subtitle
95   mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(2,0) );
96   mTitleLayout.RemoveChildAt( Toolkit::TableView::CellPosition(1,0) );
97
98   // add controls at the right part of the bar(if exist)
99   if(!controls.empty())
100   {
101     int numControls = controls.size();
102
103     for( int index = 0; index < numControls; index++)
104     {
105       mButtonLayout.AddChild( controls[index], Toolkit::TableView::CellPosition(1, 2*index + 1) );
106       mButtonLayout.SetFixedWidth (2*index, mCurrentStyle->gapBetweenButtons);
107       mButtonLayout.SetFixedWidth (2*index+1, mCurrentStyle->buttonSize);
108     }
109
110     mLayout.InsertColumn(2);
111     mLayout.SetFixedWidth(2, numControls * ( mCurrentStyle->buttonSize + mCurrentStyle->gapBetweenButtons) );
112     mLayout.AddChild(mButtonLayout, Toolkit::TableView::CellPosition(0,2));
113   }
114
115   // add title and subtitle(if exist)
116   mTitle.SetText( page.GetTitle() );
117   mTitle.SetStyleToCurrentText(mCurrentStyle->titleTextStyle);
118   if( page.GetSubTitle().empty() )  //display title
119   {
120     mTitleLayout.SetFixedHeight( 1,mCurrentStyle->titleHeightWithoutSubtitle - mCurrentStyle->subtitleHeight );
121     mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0,2,1) );
122   }
123   else //display title and subtitle
124   {
125     mTitleLayout.SetFixedHeight( 1, mCurrentStyle->titleHeightWithSubtitle );
126     mTitleLayout.AddChild( mTitle, Toolkit::TableView::CellPosition(1,0) );
127     mSubTitle.SetText( page.GetSubTitle() );
128     mSubTitle.SetStyleToCurrentText(mCurrentStyle->subtitleTextStyle);
129     mTitleLayout.AddChild( mSubTitle, Toolkit::TableView::CellPosition(2,0) );
130   }
131
132   // insert title icon to the left of the title(if exist)
133   if( page.GetTitleIcon() )
134   {
135     mTitleIconLayout.RemoveChildAt(Toolkit::TableView::CellPosition(1,0) );
136     mTitleIconLayout.AddChild( page.GetTitleIcon(), Toolkit::TableView::CellPosition(1,0) );
137     mTitleLayout.InsertColumn( 0 );
138     mTitleLayout.SetFixedWidth( 0, mCurrentStyle->titleLeftMargin + mCurrentStyle->titleIconSize);
139     mTitleLayout.AddChild( mTitleIconLayout, Toolkit::TableView::CellPosition(1,0,2,1) );
140   }
141
142   mLayout.AddChild( mTitleLayout, Toolkit::TableView::CellPosition(0,1) );
143
144   mVisible = true;
145   mLayout.SetVisible(true);
146   mBackground.SetVisible(true);
147 }
148
149 void NavigationTitleBar::OrientationUpdate( bool isPortrait )
150 {
151   mCurrentStyle = isPortrait ? &mStylePortrait : &mStyleLandscape;
152   SetFixedSizes();
153   Update( mCurrentItem );
154 }
155
156 void NavigationTitleBar::SetFixedSizes()
157 {
158   mLayout.SetFixedWidth(0, mCurrentStyle->titleLeftMargin);
159   mLayout.SetFixedWidth(2, mCurrentStyle->buttonRightMargin);
160
161   mButtonLayout.SetFixedHeight(2, mCurrentStyle->buttonBottomMargin);
162   mButtonLayout.SetFixedHeight(1, mCurrentStyle->buttonSize);
163
164   mTitleLayout.SetFixedHeight( 3,mCurrentStyle->titleBottomMargin );
165   mTitleLayout.SetFixedHeight( 2,mCurrentStyle->subtitleHeight );
166
167   mTitleIconLayout.SetFixedWidth( 0, mCurrentStyle->titleIconSize );
168   mTitleIconLayout.SetFixedHeight( 1, mCurrentStyle->titleIconSize );
169 }
170
171 } // namespace Internal
172
173 } // namespace Toolkit
174
175 } // namespace Dali