Merge "(Page) Using registered properties" into tizen
[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_PROPERTY_REGISTRATION( Toolkit, Page, "title",     STRING, TITLE     )
44 DALI_PROPERTY_REGISTRATION( Toolkit, Page, "sub-title", STRING, SUB_TITLE )
45 DALI_TYPE_REGISTRATION_END()
46
47 } // unnamed namespace
48
49 Page::Page()
50 : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
51   mTitle(""),
52   mSubTitle("")
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::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
165 {
166   Toolkit::Page page = Toolkit::Page::DownCast( Dali::BaseHandle( object ) );
167
168   if ( page )
169   {
170     switch ( index )
171     {
172       case Toolkit::Page::Property::TITLE:
173       {
174         GetImpl( page ).SetTitle( value.Get< std::string >() );
175         break;
176       }
177
178       case Toolkit::Page::Property::SUB_TITLE:
179       {
180         GetImpl( page ).SetSubTitle( value.Get< std::string >() );
181         break;
182       }
183     }
184   }
185 }
186
187 Property::Value Page::GetProperty( BaseObject* object, Property::Index propertyIndex )
188 {
189   Property::Value value;
190
191   Toolkit::Page page = Toolkit::Page::DownCast( Dali::BaseHandle( object ) );
192
193   if ( page )
194   {
195     switch ( propertyIndex )
196     {
197       case Toolkit::Page::Property::TITLE:
198       {
199         value = GetImpl( page ).mTitle;
200         break;
201       }
202
203       case Toolkit::Page::Property::SUB_TITLE:
204       {
205         value = GetImpl( page ).mSubTitle;
206         break;
207       }
208     }
209   }
210
211   return value;
212 }
213
214 } // namespace Internal
215
216 } // namespace Toolkit
217
218 } // namespace Dali