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