3a375de7c914c9cdcd07532579c8bdfce149234d
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / navigation-frame / page-impl.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
20 #include "page-impl.h"
21
22 // EXTERNAL INCLUDES
23
24 // INTERNAL INCLUDES
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 namespace
36 {
37
38 BaseHandle Create()
39 {
40   return Toolkit::Page::New();
41 }
42
43 TypeRegistration mType( typeid(Toolkit::Page), typeid(CustomActor), Create );
44
45 } // unnamed namespace
46
47 Page::Page()
48 : Control( CONTROL_BEHAVIOUR_NONE ),
49   mTitle(""),
50   mSubTitle("")
51 {
52 }
53
54 Page::~Page()
55 {
56   Toolkit::Page::ControlOnBarContainer::const_iterator iter;
57
58   if( !mToolBarControls.empty() )
59   {
60     for( iter = mToolBarControls.begin(); iter != mToolBarControls.end(); iter++ )
61     {
62       delete( *iter );
63     }
64   }
65
66 }
67
68 Toolkit::Page Page::New()
69 {
70   // Create the implementation, temporarily owned by this handle on stack
71   IntrusivePtr< Page > internalpage = new Page();
72
73   // Pass ownership to CustomActor handle
74   Toolkit::Page page( *internalpage );
75
76   // Second-phase init of the implementation
77   // This can only be done after the CustomActor connection has been made...
78   internalpage->Initialize();
79
80   return page;
81
82 }
83
84 void Page::SetTitle(const std::string& title)
85 {
86   mTitle = title;
87 }
88
89 const std::string& Page::GetTitle() const
90 {
91   return mTitle;
92 }
93
94 void Page::SetSubTitle(const std::string& subtitle)
95 {
96   mSubTitle = subtitle;
97 }
98
99 const std::string& Page::GetSubTitle() const
100 {
101   return mSubTitle;
102 }
103
104 void Page::SetTitleIcon( Actor titleIcon)
105 {
106   mTitleIcon = titleIcon;
107 }
108
109 Actor Page::GetTitleIcon() const
110 {
111   return mTitleIcon;
112 }
113
114 bool Page::AddControlToToolBar(Actor control, Toolkit::Alignment::Type alignment)
115 {
116   if( !control || ( alignment!=Toolkit::Alignment::HorizontalLeft
117                  && alignment!=Toolkit::Alignment::HorizontalCenter
118                  && alignment!=Toolkit::Alignment::HorizontalRight ) )
119   {
120     return false;
121   }
122   else
123   {
124     mToolBarControls.push_back(new Toolkit::Page::ControlOnBar(control, alignment));
125     return true;
126   }
127 }
128
129 const Toolkit::Page::ControlOnBarContainer& Page::GetControlsOnToolBar() const
130 {
131   return mToolBarControls;
132 }
133
134 bool Page::AddControlToTitleBar(Actor control)
135 {
136   if( !control )
137   {
138     return false;
139   }
140   else
141   {
142     mTitleBarControls.push_back(control);
143     return true;
144   }
145 }
146
147 const ActorContainer& Page::GetControlsOnTitleBar() const
148 {
149   return mTitleBarControls;
150 }
151
152 void Page::SetPopupMenu( Toolkit::Popup popupMenu )
153 {
154   mPopupMenu = popupMenu;
155 }
156
157 Toolkit::Popup Page::GetPopupMenu() const
158 {
159   return mPopupMenu;
160 }
161
162 void Page::OnInitialize()
163 {
164   Actor self = Self();
165
166   mPropertyTitle = self.RegisterProperty( Dali::Toolkit::Page::PROPERTY_TITLE, "", Property::READ_WRITE );
167   mPropertySubTitle = self.RegisterProperty( Dali::Toolkit::Page::PROPERTY_SUB_TITLE, "", Property::READ_WRITE );
168 }
169
170 void Page::OnPropertySet( Property::Index index, Property::Value propertyValue )
171 {
172   if( index == mPropertyTitle )
173   {
174     std::string title( propertyValue.Get<std::string>() );
175     SetTitle(title);
176   }
177   else if( index == mPropertySubTitle )
178   {
179     std::string subTitle( propertyValue.Get<std::string>() );
180     SetSubTitle(subTitle);
181   }
182 }
183
184 } // namespace Internal
185
186 } // namespace Toolkit
187
188 } // namespace Dali