Merge "Add a TextEditor property to limit input to maximum characters" into devel...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-view / navigation-view-impl.cpp
1 /*
2  * Copyright (c) 2017 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::OnSceneConnection( int depth )
75 {
76   Self().SetProperty( Actor::Property::SENSITIVE,true);
77
78   Control::OnSceneConnection( depth );
79 }
80
81 void NavigationView::Push( Actor& actor )
82 {
83   // check the uninitialized item
84   // check the duplicated push for the top item
85   if(!actor )
86   {
87     return;
88   }
89
90   if( mContentStack.size() > 0 )
91   {
92     Self().Remove( mContentStack.back()  );
93   }
94
95   //push the new item into the stack and show it
96   mContentStack.push_back(actor);
97   Self().Add(actor);
98 }
99
100 Actor NavigationView::Pop()
101 {
102   // cannot pop out the bottom-most item
103   Actor poppedItem;
104   if( mContentStack.size() > 1 )
105   {
106     // pop out the top item of the stack and show the new item right under the old one.
107     Self().Remove(mContentStack.back());
108     poppedItem = mContentStack.back();
109     mContentStack.pop_back();
110     Self().Add(mContentStack.back());
111   }
112
113   return poppedItem;
114 }
115
116 } // namespace Internal
117
118 } // namespace Toolkit
119
120 } // namespace Dali