8aa23185a19a9f2f1037be917fa251f41662f5b2
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.cpp
1 /*
2  * Copyright (c) 2015 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
24 // INTERNAL INCLUDES
25 #include <dali/internal/adaptor/common/application-impl.h>
26
27 namespace Dali
28 {
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(),
52       Internal::Adaptor::Framework::NORMAL);
53     return Application(internal.Get());
54   }
55 }
56
57 Application Application::New( int* argc, char **argv[], const std::string& stylesheet )
58 {
59   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
60   if( internal )
61   {
62     // pre-initialized application
63     internal->SetCommandLineOptions( argc, argv );
64     if( argc && ( *argc > 0 ) )
65     {
66       internal->GetWindow().SetClass( (*argv)[0], "" );
67     }
68     internal->SetStyleSheet( stylesheet );
69
70     return Application( internal.Get() );
71   }
72   else
73   {
74     internal = Internal::Adaptor::Application::New( argc, argv, stylesheet, OPAQUE, PositionSize(),
75       Internal::Adaptor::Framework::NORMAL);
76     return Application(internal.Get());
77   }
78 }
79
80 Application Application::New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode )
81 {
82   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
83   if( internal )
84   {
85     // pre-initialized application
86     internal->SetCommandLineOptions( argc, argv );
87     if( argc && ( *argc > 0 ) )
88     {
89       internal->GetWindow().SetClass( (*argv)[0], "" );
90     }
91     internal->SetStyleSheet( stylesheet );
92
93     internal->GetWindow().SetTransparency( ( windowMode == Application::OPAQUE ? false : true ) );
94
95     return Application( internal.Get() );
96   }
97   else
98   {
99     internal = Internal::Adaptor::Application::New( argc, argv, stylesheet, windowMode, PositionSize(),
100       Internal::Adaptor::Framework::NORMAL);
101     return Application(internal.Get());
102   }
103 }
104
105 Application Application::New( int* argc, char **argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize )
106 {
107   Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
108   if( internal )
109   {
110     // pre-initialized application
111     internal->SetCommandLineOptions( argc, argv );
112     if( argc && ( *argc > 0 ) )
113     {
114       internal->GetWindow().SetClass( (*argv)[0], "" );
115     }
116     internal->SetStyleSheet( stylesheet );
117
118     internal->GetWindow().SetTransparency( ( windowMode == Application::OPAQUE ? false : true ) );
119     internal->GetWindow().SetSize( Window::WindowSize( positionSize.width, positionSize.height ) );
120     internal->GetWindow().SetPosition( Window::WindowPosition( positionSize.x, positionSize.y ) );
121
122     return Application( internal.Get() );
123   }
124   else
125   {
126     internal = Internal::Adaptor::Application::New( argc, argv, stylesheet, windowMode, positionSize, Internal::Adaptor::Framework::NORMAL );
127     return Application( internal.Get() );
128   }
129 }
130
131 Application::~Application()
132 {
133 }
134
135 Application::Application()
136 {
137 }
138
139 Application::Application(const Application& application)
140 : BaseHandle(application)
141 {
142 }
143
144 Application& Application::operator=(const Application& application)
145 {
146   if( *this != application )
147   {
148     BaseHandle::operator=( application );
149   }
150   return *this;
151 }
152
153 void Application::MainLoop()
154 {
155   Internal::Adaptor::GetImplementation(*this).MainLoop(Configuration::APPLICATION_HANDLES_CONTEXT_LOSS);
156 }
157
158 void Application::MainLoop(Configuration::ContextLoss configuration)
159 {
160   Internal::Adaptor::GetImplementation(*this).MainLoop(configuration);
161 }
162
163 void Application::Lower()
164 {
165   Internal::Adaptor::GetImplementation(*this).Lower();
166 }
167
168 void Application::Quit()
169 {
170   Internal::Adaptor::GetImplementation(*this).Quit();
171 }
172
173 bool Application::AddIdle( CallbackBase* callback )
174 {
175   return Internal::Adaptor::GetImplementation(*this).AddIdle( callback, false );
176 }
177
178 Window Application::GetWindow()
179 {
180   return Internal::Adaptor::GetImplementation(*this).GetWindow();
181 }
182
183 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
184 {
185   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: ReplaceWindow is deprecated and will be removed from next release.\n" );
186
187   Internal::Adaptor::GetImplementation(*this).ReplaceWindow(windowPosition, name);
188 }
189
190 std::string Application::GetResourcePath()
191 {
192   return Internal::Adaptor::Application::GetResourcePath();
193 }
194
195 std::string Application::GetRegion() const
196 {
197   return Internal::Adaptor::GetImplementation(*this).GetRegion();
198 }
199
200 std::string Application::GetLanguage() const
201 {
202   return Internal::Adaptor::GetImplementation(*this).GetLanguage();
203 }
204
205 void Application::SetViewMode( ViewMode viewMode )
206 {
207   Internal::Adaptor::GetImplementation(*this).SetViewMode( viewMode );
208 }
209
210 ViewMode Application::GetViewMode() const
211 {
212   return Internal::Adaptor::GetImplementation(*this).GetViewMode();
213 }
214
215 void Application::SetStereoBase( float stereoBase )
216 {
217   Internal::Adaptor::GetImplementation(*this).SetStereoBase( stereoBase );
218 }
219
220 float Application::GetStereoBase() const
221 {
222   return Internal::Adaptor::GetImplementation(*this).GetStereoBase();
223 }
224
225 Application::AppSignalType& Application::InitSignal()
226 {
227   return Internal::Adaptor::GetImplementation(*this).InitSignal();
228 }
229
230 Application::AppSignalType& Application::TerminateSignal()
231 {
232   return Internal::Adaptor::GetImplementation(*this).TerminateSignal();
233 }
234
235 Application::AppSignalType& Application::PauseSignal()
236 {
237   return Internal::Adaptor::GetImplementation(*this).PauseSignal();
238 }
239
240 Application::AppSignalType& Application::ResumeSignal()
241 {
242   return Internal::Adaptor::GetImplementation(*this).ResumeSignal();
243 }
244
245 Application::AppSignalType& Application::ResetSignal()
246 {
247   return Internal::Adaptor::GetImplementation(*this).ResetSignal();
248 }
249
250 Application::AppSignalType& Application::ResizeSignal()
251 {
252   DALI_LOG_WARNING_NOFN( "DEPRECATION WARNING: ResizeSignal() is deprecated and will be removed from next release. Use Window::ResizedSignal() instead.\n" );
253
254   return Internal::Adaptor::GetImplementation(*this).ResizeSignal();
255 }
256
257 Application::AppControlSignalType & Application::AppControlSignal()
258 {
259   return Internal::Adaptor::GetImplementation(*this).AppControlSignal();
260 }
261
262 Application::AppSignalType& Application::LanguageChangedSignal()
263 {
264   return Internal::Adaptor::GetImplementation(*this).LanguageChangedSignal();
265 }
266
267 Application::AppSignalType& Application::RegionChangedSignal()
268 {
269   return Internal::Adaptor::GetImplementation(*this).RegionChangedSignal();
270 }
271
272 Application::AppSignalType& Application::BatteryLowSignal()
273 {
274   DALI_LOG_WARNING_NOFN( "DEPRECATION WARNING: BatteryLowSignal() is deprecated and will be removed from next release. Use Application::LowBatterySignal() instead.\n" );
275   return Internal::Adaptor::GetImplementation(*this).BatteryLowSignal();
276 }
277
278 Application::AppSignalType& Application::MemoryLowSignal()
279 {
280   DALI_LOG_WARNING_NOFN( "DEPRECATION WARNING: MemoryLowSignal() is deprecated and will be removed from next release. Use Application::LowMemorySignal() instead.\n" );
281   return Internal::Adaptor::GetImplementation(*this).MemoryLowSignal();
282 }
283
284 Application::LowBatterySignalType& Application::LowBatterySignal()
285 {
286   return Internal::Adaptor::GetImplementation(*this).LowBatterySignal();
287 }
288
289 Application::LowMemorySignalType& Application::LowMemorySignal()
290 {
291   return Internal::Adaptor::GetImplementation(*this).LowMemorySignal();
292 }
293
294 Application::Application(Internal::Adaptor::Application* application)
295 : BaseHandle(application)
296 {
297 }
298
299
300 } // namespace Dali