Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.cpp
1 /*
2  * Copyright (c) 2020 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     internal->GetWindow().SetSize(Window::WindowSize(positionSize.width, positionSize.height));
117     internal->GetWindow().SetPosition(Window::WindowPosition(positionSize.x, positionSize.y));
118
119     return Application(internal.Get());
120   }
121   else
122   {
123     internal = Internal::Adaptor::Application::New(argc, argv, stylesheet, windowMode, positionSize, Internal::Adaptor::Framework::NORMAL);
124     return Application(internal.Get());
125   }
126 }
127
128 Application::~Application()
129 {
130 }
131
132 Application::Application()
133 {
134 }
135
136 Application::Application(const Application& copy) = default;
137
138 Application& Application::operator=(const Application& rhs) = default;
139
140 Application::Application(Application&& rhs) = default;
141
142 Application& Application::operator=(Application&& rhs) = default;
143
144 void Application::MainLoop()
145 {
146   Internal::Adaptor::GetImplementation(*this).MainLoop();
147 }
148
149 void Application::Lower()
150 {
151   Internal::Adaptor::GetImplementation(*this).Lower();
152 }
153
154 void Application::Quit()
155 {
156   Internal::Adaptor::GetImplementation(*this).Quit();
157 }
158
159 bool Application::AddIdle(CallbackBase* callback)
160 {
161   return Internal::Adaptor::GetImplementation(*this).AddIdle(callback, false);
162 }
163
164 Window Application::GetWindow()
165 {
166   return Internal::Adaptor::GetImplementation(*this).GetWindow();
167 }
168
169 std::string Application::GetResourcePath()
170 {
171   return Internal::Adaptor::Application::GetResourcePath();
172 }
173
174 std::string Application::GetRegion() const
175 {
176   return Internal::Adaptor::GetImplementation(*this).GetRegion();
177 }
178
179 std::string Application::GetLanguage() const
180 {
181   return Internal::Adaptor::GetImplementation(*this).GetLanguage();
182 }
183
184 ObjectRegistry Application::GetObjectRegistry() const
185 {
186   return Internal::Adaptor::GetImplementation(*this).GetObjectRegistry();
187 }
188
189 Application::AppSignalType& Application::InitSignal()
190 {
191   return Internal::Adaptor::GetImplementation(*this).InitSignal();
192 }
193
194 Application::AppSignalType& Application::TerminateSignal()
195 {
196   return Internal::Adaptor::GetImplementation(*this).TerminateSignal();
197 }
198
199 Application::AppSignalType& Application::PauseSignal()
200 {
201   return Internal::Adaptor::GetImplementation(*this).PauseSignal();
202 }
203
204 Application::AppSignalType& Application::ResumeSignal()
205 {
206   return Internal::Adaptor::GetImplementation(*this).ResumeSignal();
207 }
208
209 Application::AppSignalType& Application::ResetSignal()
210 {
211   return Internal::Adaptor::GetImplementation(*this).ResetSignal();
212 }
213
214 Application::AppControlSignalType& Application::AppControlSignal()
215 {
216   return Internal::Adaptor::GetImplementation(*this).AppControlSignal();
217 }
218
219 Application::AppSignalType& Application::LanguageChangedSignal()
220 {
221   return Internal::Adaptor::GetImplementation(*this).LanguageChangedSignal();
222 }
223
224 Application::AppSignalType& Application::RegionChangedSignal()
225 {
226   return Internal::Adaptor::GetImplementation(*this).RegionChangedSignal();
227 }
228
229 Application::LowBatterySignalType& Application::LowBatterySignal()
230 {
231   return Internal::Adaptor::GetImplementation(*this).LowBatterySignal();
232 }
233
234 Application::LowMemorySignalType& Application::LowMemorySignal()
235 {
236   return Internal::Adaptor::GetImplementation(*this).LowMemorySignal();
237 }
238
239 Application::Application(Internal::Adaptor::Application* application)
240 : BaseHandle(application)
241 {
242 }
243
244 } // namespace Dali