2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #import <Cocoa/Cocoa.h>
20 #include "extern-definitions.h"
23 #include <dali/internal/adaptor/common/framework.h>
26 #include <dali/integration-api/debug.h>
29 #include <dali/internal/system/common/callback-manager.h>
43 /// Application Status Enum
54 } // Unnamed namespace
57 * Impl to hide WindowsSystem data members
59 struct Framework::Impl
64 : mAbortCallBack( nullptr ),
65 mLanguage( "NOT_SUPPORTED" ),
66 mRegion( "NOT_SUPPORTED" )
72 delete mAbortCallBack;
75 std::string GetLanguage() const
80 std::string GetRegion() const
85 void SetAbortCallback( CallbackBase *base )
87 mAbortCallBack = base;
90 bool ExecuteCallback()
92 if( nullptr != mAbortCallBack )
94 CallbackBase::Execute( *mAbortCallBack );
103 Impl( const Impl& impl ) = delete;
106 Impl& operator=( const Impl& impl ) = delete;
110 CallbackBase* mAbortCallBack;
111 std::string mLanguage;
115 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
116 : mObserver(observer),
124 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
128 mImpl = new Impl(this);
130 // ensures the NSApp global object is initialized
131 [NSApplication sharedApplication];
133 // this is needed for applications without a bundle
134 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
136 // make sure we can become the key window
137 [NSApp activateIgnoringOtherApps:YES];
140 Framework::~Framework()
150 void Framework::Run()
153 AppStatusHandler(APP_CREATE, nullptr);
158 void Framework::Quit()
160 AppStatusHandler(APP_TERMINATE, nullptr);
163 bool Framework::IsMainLoopRunning()
168 void Framework::AddAbortCallback( CallbackBase* callback )
170 mImpl->SetAbortCallback( callback );
173 std::string Framework::GetBundleName() const
178 void Framework::SetBundleName(const std::string& name)
183 std::string Framework::GetBundleId() const
188 std::string Framework::GetResourcePath()
190 // "DALI_APPLICATION_PACKAGE" is used by macOS specifically to get the already configured Application package path.
191 const char* macEnvironmentVariable = "DALI_APPLICATION_PACKAGE";
192 char* value = getenv( macEnvironmentVariable );
194 std::string resourcePath;
197 resourcePath = value;
200 if( resourcePath.back() != '/' )
208 std::string Framework::GetDataPath()
210 return app_get_data_path();
213 void Framework::SetBundleId(const std::string& id)
218 void Framework::AbortCallback( )
220 // if an abort call back has been installed run it.
221 if( false == mImpl->ExecuteCallback() )
227 bool Framework::AppStatusHandler(int type, void *)
243 mObserver.OnResume();
247 mObserver.OnTerminate();
254 case APP_LANGUAGE_CHANGE:
255 mObserver.OnLanguageChanged();
265 void Framework::InitThreads()
269 std::string Framework::GetLanguage() const
271 return mImpl->GetLanguage();
274 std::string Framework::GetRegion() const
276 return mImpl->GetRegion();
279 } // namespace Adaptor
281 } // namespace Internal