2 * Copyright (c) 2023 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.
19 #include <dali/internal/clipboard/common/clipboard-impl.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/system/linux/dali-ecore-x.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/object/any.h>
26 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/common/singleton-service.h>
30 #include <dali/internal/adaptor/common/adaptor-impl.h>
31 #include <dali/internal/window-system/ubuntu-x11/window-interface-ecore-x.h>
39 struct Clipboard::Impl
41 Impl(Ecore_X_Window ecoreXwin)
43 mApplicationWindow = ecoreXwin;
46 bool HasType(const std::string& mimeType)
48 return mMimeType == mimeType ? true : false;
51 bool SetData(const Dali::Clipboard::ClipData& clipData)
53 mMimeType = clipData.GetMimeType();
54 mData = clipData.GetData();
61 mDataSentSignal.Emit(mMimeType.c_str(), mData.c_str());
62 mDataSelectedSignal.Emit(mMimeType.c_str());
67 uint32_t GetData(const std::string &mimeType)
69 if(!mMimeType.compare(mimeType.c_str()))
72 // For consistency of operation with tizen Wl2, a fake callback is occurs using a timer.
73 if(mDataReceiveTimer.IsRunning())
75 mDataReceiveTimer.Stop();
77 mDataReceiveTimer.Start();
78 DALI_LOG_RELEASE_INFO("request data, id:%u, request type:%s\n", mDataId, mimeType.c_str());
86 DALI_LOG_RELEASE_INFO("receive data, success signal emit, id:%u, type:%s, data:%s\n", mDataId, mMimeType.c_str(), mData.c_str());
87 mDataReceivedSignal.Emit(mDataId, mMimeType.c_str(), mData.c_str());
91 Ecore_X_Window mApplicationWindow;
92 std::string mMimeType;
96 Dali::Clipboard::DataSentSignalType mDataSentSignal;
97 Dali::Clipboard::DataReceivedSignalType mDataReceivedSignal;
98 Dali::Clipboard::DataSelectedSignalType mDataSelectedSignal;
100 Dali::Timer mDataReceiveTimer;
103 Clipboard::Clipboard(Impl* impl)
106 mImpl->mDataReceiveTimer = Dali::Timer::New(10);
107 mImpl->mDataReceiveTimer.TickSignal().Connect(this, &Clipboard::OnReceiveData);
110 Clipboard::~Clipboard()
115 Dali::Clipboard Clipboard::Get()
117 Dali::Clipboard clipboard;
119 Dali::SingletonService service(SingletonService::Get());
122 // Check whether the singleton is already created
123 Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::Clipboard));
126 // If so, downcast the handle
127 clipboard = Dali::Clipboard(dynamic_cast<Clipboard*>(handle.GetObjectPtr()));
131 Adaptor& adaptorImpl(Adaptor::GetImplementation(Adaptor::Get()));
132 Any nativewindow = adaptorImpl.GetNativeWindowHandle();
134 // The Ecore_X_Window needs to use the Clipboard.
135 // Only when the render surface is window, we can get the Ecore_X_Window.
136 Ecore_X_Window ecoreXwin(AnyCast<Ecore_X_Window>(nativewindow));
139 // If we fail to get Ecore_X_Window, we can't use the Clipboard correctly.
140 // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
141 // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
142 Clipboard::Impl* impl(new Clipboard::Impl(ecoreXwin));
143 clipboard = Dali::Clipboard(new Clipboard(impl));
144 service.Register(typeid(clipboard), clipboard);
152 bool Clipboard::IsAvailable()
154 Dali::SingletonService service(SingletonService::Get());
157 Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::Clipboard));
166 Dali::Clipboard::DataSentSignalType& Clipboard::DataSentSignal()
168 return mImpl->mDataSentSignal;
171 Dali::Clipboard::DataReceivedSignalType& Clipboard::DataReceivedSignal()
173 return mImpl->mDataReceivedSignal;
176 Dali::Clipboard::DataSelectedSignalType& Clipboard::DataSelectedSignal()
178 return mImpl->mDataSelectedSignal;
181 bool Clipboard::HasType(const std::string& mimeType)
183 return mImpl->HasType(mimeType);
186 bool Clipboard::SetData(const Dali::Clipboard::ClipData& clipData)
188 return mImpl->SetData(clipData);
191 uint32_t Clipboard::GetData(const std::string &mimeType)
193 return mImpl->GetData(mimeType);
196 size_t Clipboard::NumberOfItems()
198 bool isItem = HasType(MIME_TYPE_TEXT_PLAIN) || HasType(MIME_TYPE_HTML) || HasType(MIME_TYPE_TEXT_URI);
199 return isItem ? 1u : 0u;
202 void Clipboard::ShowClipboard()
206 void Clipboard::HideClipboard(bool skipFirstHide)
210 bool Clipboard::IsVisible() const
215 bool Clipboard::OnReceiveData()
217 return mImpl->OnReceiveData();
220 } // namespace Adaptor
222 } // namespace Internal