Merge "Add SetProperty and GetProperty to Visuals." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-view / navigation-view-impl.cpp
1 /*
2  * Copyright (c) 2016 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-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry-helper.h>
23
24 // INTERNAL INCLUDES
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 namespace // to register type
36 {
37
38 BaseHandle Create()
39 {
40   return Toolkit::NavigationView::New();
41 }
42
43 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::NavigationView, Toolkit::Control, Create )
44 DALI_TYPE_REGISTRATION_END()
45
46 } // namespace
47
48 NavigationView::NavigationView()
49 : Control(ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) )
50 {
51 }
52
53 NavigationView::~NavigationView()
54 {
55   // Clear all the items in the stack, forces their destruction before NavigationView is destroyed.
56   mContentStack.clear();
57 }
58
59 Toolkit::NavigationView NavigationView::New()
60 {
61   // Create the implementation, temporarily owned by this handle on stack
62   IntrusivePtr< NavigationView > internalNavigationView = new NavigationView();
63
64   // Pass ownership to CustomActor handle
65   Toolkit::NavigationView navigationView( *internalNavigationView );
66
67   // Second-phase init of the implementation
68   // This can only be done after the CustomActor connection has been made...
69   internalNavigationView->Initialize();
70
71   return navigationView;
72 }
73
74 void NavigationView::OnStageConnection( int depth )
75 {
76   Self().SetSensitive(true);
77 }
78
79 void NavigationView::Push( Actor& actor )
80 {
81   // check the uninitialized item
82   // check the duplicated push for the top item
83   if(!actor )
84   {
85     return;
86   }
87
88   if( mContentStack.size() > 0 )
89   {
90     Self().Remove( mContentStack.back()  );
91   }
92
93   //push the new item into the stack and show it
94   mContentStack.push_back(actor);
95   Self().Add(actor);
96 }
97
98 Actor NavigationView::Pop()
99 {
100   // cannot pop out the bottom-most item
101   Actor poppedItem;
102   if( mContentStack.size() > 1 )
103   {
104     // pop out the top item of the stack and show the new item right under the old one.
105     Self().Remove(mContentStack.back());
106     poppedItem = mContentStack.back();
107     mContentStack.pop_back();
108     Self().Add(mContentStack.back());
109   }
110
111   return poppedItem;
112 }
113
114 } // namespace Internal
115
116 } // namespace Toolkit
117
118 } // namespace Dali