Fixed crash when Visual model positions < glyphs
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / relayout-controller.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 "relayout-controller.h"
20
21 // EXTERNAL INCLUDES
22 #include <stack>
23 #include <sstream>
24 #include <dali/public-api/adaptor-framework/singleton-service.h>
25 #include <dali/integration-api/debug.h>
26
27 // INTERNAL INCLUDES
28
29 #include "relayout-controller-impl.h"
30 #include "dali-toolkit/public-api/controls/control.h"
31 #include "dali-toolkit/public-api/controls/control-impl.h"
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 namespace
43 {
44 // Flag to avoid doing more than one request per frame
45 // getting the singleton handle can be expensive as it requires calling to adaptor, dynamic cast etc
46 // and it can get called 100 times per frame easily in startup and new view initialization
47   bool gRelayoutRequestPending = false;
48 }
49
50 RelayoutController::RelayoutController()
51 {
52
53 }
54
55 RelayoutController::~RelayoutController()
56 {
57
58 }
59
60 void RelayoutController::Request()
61 {
62   // are we already going to do it this frame
63   if( !gRelayoutRequestPending )
64   {
65     RelayoutController controller;
66
67     // Check whether the RelayoutController is already created
68     SingletonService singletonService( SingletonService::Get() );
69     if ( singletonService )
70     {
71       Dali::BaseHandle handle = singletonService.GetSingleton(typeid(RelayoutController));
72
73       if(handle)
74       {
75         // If so, downcast the handle of singleton to RelayoutController
76         controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
77       }
78
79       if(!controller)
80       {
81         // If not, create the RelayoutController and register it as a singleton
82         controller = RelayoutController( new Internal::RelayoutControllerImpl(gRelayoutRequestPending) );
83         singletonService.Register( typeid(controller), controller );
84       }
85
86       GetImpl(controller).Request();
87       gRelayoutRequestPending = true;
88     }
89   }
90 }
91
92 RelayoutController::RelayoutController(Internal::RelayoutControllerImpl *impl)
93   : BaseHandle(impl)
94 {
95 }
96
97 } // namespace Internal
98
99 } // namespace Toolkit
100
101 } // namespace Dali
102