New layouting classes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-controller.cpp
1 /*
2  * Copyright (c) 2018 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 // CLASS HEADER
18 #include <dali-toolkit/devel-api/layouting/layout-controller.h>
19
20 // EXTERNAL INCLUDES
21 #include <dali/devel-api/adaptor-framework/singleton-service.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/internal/layouting/layout-controller-impl.h>
25
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31
32 LayoutController::LayoutController()
33 {
34 }
35
36 LayoutController::~LayoutController()
37 {
38 }
39
40 LayoutController LayoutController::Get()
41 {
42   LayoutController layoutController;
43
44   SingletonService singletonService( SingletonService::Get() );
45   if ( singletonService )
46   {
47     Dali::BaseHandle handle = singletonService.GetSingleton( typeid(LayoutController) );
48     if( handle )
49     {
50       // If so, downcast the handle of singleton to layout controller
51       layoutController = LayoutController( dynamic_cast<Internal::LayoutController*>( handle.GetObjectPtr() ) );
52     }
53
54     if( !layoutController )
55     {
56       // If not, create the layout controller and register it as a singleton
57       Internal::LayoutController* impl = new Internal::LayoutController();
58       layoutController = LayoutController( impl );
59       impl->Initialize();
60
61       // Registering the singleton will automatically register the processor with Core.
62       singletonService.Register( typeid(layoutController), layoutController );
63     }
64   }
65
66   return layoutController;
67 }
68
69 void LayoutController::RequestLayout( LayoutBase layout )
70 {
71   GetImpl(*this).RequestLayout( GetImplementation( layout ) );
72 }
73
74 LayoutController::LayoutController( Internal::LayoutController *impl )
75 : BaseHandle( impl )
76 {
77 }
78
79 } //namespace Toolkit
80 } //namespace Dali