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