Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.cpp
1 /*
2  * Copyright (c) 2021 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 <dali/public-api/adaptor-framework/application.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/object-registry.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/adaptor/common/application-impl.h>
27
28 namespace Dali
29 {
30 Application Application::New()
31 {
32   return New(NULL, NULL);
33 }
34
35 Application Application::New(int* argc, char** argv[])
36 {
37   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
38   if(internal)
39   {
40     // pre-initialized application
41     internal->SetCommandLineOptions(argc, argv);
42     if(argc && (*argc > 0))
43     {
44       internal->GetWindow().SetClass((*argv)[0], "");
45     }
46
47     return Application(internal.Get());
48   }
49   else
50   {
51     internal = Internal::Adaptor::Application::New(argc, argv, "", OPAQUE, PositionSize(), Internal::Adaptor::Framework::NORMAL);
52     return Application(internal.Get());
53   }
54 }
55
56 Application Application::New(int* argc, char** argv[], const std::string& stylesheet)
57 {
58   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
59   if(internal)
60   {
61     // pre-initialized application
62     internal->SetCommandLineOptions(argc, argv);
63     if(argc && (*argc > 0))
64     {
65       internal->GetWindow().SetClass((*argv)[0], "");
66     }
67     internal->SetStyleSheet(stylesheet);
68
69     return Application(internal.Get());
70   }
71   else
72   {
73     internal = Internal::Adaptor::Application::New(argc, argv, stylesheet, OPAQUE, PositionSize(), Internal::Adaptor::Framework::NORMAL);
74     return Application(internal.Get());
75   }
76 }
77
78 Application Application::New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode)
79 {
80   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
81   if(internal)
82   {
83     // pre-initialized application
84     internal->SetCommandLineOptions(argc, argv);
85     if(argc && (*argc > 0))
86     {
87       internal->GetWindow().SetClass((*argv)[0], "");
88     }
89     internal->SetStyleSheet(stylesheet);
90
91     internal->GetWindow().SetTransparency((windowMode == Application::OPAQUE ? false : true));
92
93     return Application(internal.Get());
94   }
95   else
96   {
97     internal = Internal::Adaptor::Application::New(argc, argv, stylesheet, windowMode, PositionSize(), Internal::Adaptor::Framework::NORMAL);
98     return Application(internal.Get());
99   }
100 }
101
102 Application Application::New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize)
103 {
104   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
105   if(internal)
106   {
107     // pre-initialized application
108     internal->SetCommandLineOptions(argc, argv);
109     if(argc && (*argc > 0))
110     {
111       internal->GetWindow().SetClass((*argv)[0], "");
112     }
113     internal->SetStyleSheet(stylesheet);
114
115     internal->GetWindow().SetTransparency((windowMode == Application::OPAQUE ? false : true));
116
117     //Store only the value before adaptor is created
118     internal->StoreWindowPositionSize(positionSize);
119
120     return Application(internal.Get());
121   }
122   else
123   {
124     internal = Internal::Adaptor::Application::New(argc, argv, stylesheet, windowMode, positionSize, Internal::Adaptor::Framework::NORMAL);
125     return Application(internal.Get());
126   }
127 }
128
129 Application::~Application()
130 {
131 }
132
133 Application::Application()
134 {
135 }
136
137 Application::Application(const Application& copy) = default;
138
139 Application& Application::operator=(const Application& rhs) = default;
140
141 Application::Application(Application&& rhs) = default;
142
143 Application& Application::operator=(Application&& rhs) = default;
144
145 void Application::MainLoop()
146 {
147   Internal::Adaptor::GetImplementation(*this).MainLoop();
148 }
149
150 void Application::Lower()
151 {
152   Internal::Adaptor::GetImplementation(*this).Lower();
153 }
154
155 void Application::Quit()
156 {
157   Internal::Adaptor::GetImplementation(*this).Quit();
158 }
159
160 bool Application::AddIdle(CallbackBase* callback)
161 {
162   return Internal::Adaptor::GetImplementation(*this).AddIdle(callback, false);
163 }
164
165 Window Application::GetWindow()
166 {
167   return Internal::Adaptor::GetImplementation(*this).GetWindow();
168 }
169
170 std::string Application::GetResourcePath()
171 {
172   return Internal::Adaptor::Application::GetResourcePath();
173 }
174
175 std::string Application::GetRegion() const
176 {
177   return Internal::Adaptor::GetImplementation(*this).GetRegion();
178 }
179
180 std::string Application::GetLanguage() const
181 {
182   return Internal::Adaptor::GetImplementation(*this).GetLanguage();
183 }
184
185 ObjectRegistry Application::GetObjectRegistry() const
186 {
187   return Internal::Adaptor::GetImplementation(*this).GetObjectRegistry();
188 }
189
190 Application::AppSignalType& Application::InitSignal()
191 {
192   return Internal::Adaptor::GetImplementation(*this).InitSignal();
193 }
194
195 Application::AppSignalType& Application::TerminateSignal()
196 {
197   return Internal::Adaptor::GetImplementation(*this).TerminateSignal();
198 }
199
200 Application::AppSignalType& Application::PauseSignal()
201 {
202   return Internal::Adaptor::GetImplementation(*this).PauseSignal();
203 }
204
205 Application::AppSignalType& Application::ResumeSignal()
206 {
207   return Internal::Adaptor::GetImplementation(*this).ResumeSignal();
208 }
209
210 Application::AppSignalType& Application::ResetSignal()
211 {
212   return Internal::Adaptor::GetImplementation(*this).ResetSignal();
213 }
214
215 Application::AppControlSignalType& Application::AppControlSignal()
216 {
217   return Internal::Adaptor::GetImplementation(*this).AppControlSignal();
218 }
219
220 Application::AppSignalType& Application::LanguageChangedSignal()
221 {
222   return Internal::Adaptor::GetImplementation(*this).LanguageChangedSignal();
223 }
224
225 Application::AppSignalType& Application::RegionChangedSignal()
226 {
227   return Internal::Adaptor::GetImplementation(*this).RegionChangedSignal();
228 }
229
230 Application::LowBatterySignalType& Application::LowBatterySignal()
231 {
232   return Internal::Adaptor::GetImplementation(*this).LowBatterySignal();
233 }
234
235 Application::LowMemorySignalType& Application::LowMemorySignal()
236 {
237   return Internal::Adaptor::GetImplementation(*this).LowMemorySignal();
238 }
239
240 Graphics::Controller& Application::GetController()
241 {
242   return Internal::Adaptor::GetImplementation(*this).GetController();
243 }
244
245 Application::Application(Internal::Adaptor::Application* application)
246 : BaseHandle(application)
247 {
248 }
249
250 } // namespace Dali