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