33ff63da75df90d9e0653168cf69ddeb81237f35
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-editable-text.cpp
1 /*
2  * Copyright (c) 2021 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/internal/accessibility/bridge/bridge-editable-text.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/clipboard/common/clipboard-impl.h>
23
24 using namespace Dali::Accessibility;
25
26 void BridgeEditableText::RegisterInterfaces()
27 {
28   DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceEditableText};
29   AddFunctionToInterface(desc, "CopyText", &BridgeEditableText::CopyText);
30   AddFunctionToInterface(desc, "CutText", &BridgeEditableText::CutText);
31   AddFunctionToInterface(desc, "DeleteText", &BridgeEditableText::DeleteText);
32   AddFunctionToInterface(desc, "InsertText", &BridgeEditableText::InsertText);
33   AddFunctionToInterface(desc, "PasteText", &BridgeEditableText::PasteText);
34   AddFunctionToInterface(desc, "SetTextContents", &BridgeEditableText::SetTextContents);
35   mDbusServer.addInterface("/", desc, true);
36 }
37
38 EditableText* BridgeEditableText::FindSelf() const
39 {
40   auto self = BridgeBase::FindSelf();
41   assert(self);
42   auto editableTextInterface = dynamic_cast<EditableText*>(self);
43   if(!editableTextInterface)
44   {
45     throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Text interface"};
46   }
47   return editableTextInterface;
48 }
49
50 DBus::ValueOrError<bool> BridgeEditableText::CopyText(int32_t startPos, int32_t endPos)
51 {
52   return FindSelf()->CopyText(startPos, endPos);
53 }
54
55 DBus::ValueOrError<bool> BridgeEditableText::CutText(int32_t startPos, int32_t endPos)
56 {
57   return FindSelf()->CutText(startPos, endPos);
58 }
59
60 DBus::ValueOrError<bool> BridgeEditableText::DeleteText(int32_t startPos, int32_t endPos)
61 {
62   return FindSelf()->DeleteText(startPos, endPos);
63 }
64
65 DBus::ValueOrError<bool> BridgeEditableText::InsertText(int32_t startPos, std::string text, [[maybe_unused]] int32_t length)
66 {
67   return FindSelf()->InsertText(startPos, std::move(text));
68 }
69
70 DBus::ValueOrError<bool> BridgeEditableText::PasteText(int32_t pos)
71 {
72   // auto imfManager = Dali::Internal::Adaptor::ImfManager::Get();
73   // imfManager.SetCursorPosition( pos );
74   // auto clipboard = Dali::Internal::Adaptor::Clipboard::Get();
75   // clipboard.RequestItem();
76   // return true;
77   return false;
78 }
79
80 DBus::ValueOrError<bool> BridgeEditableText::SetTextContents(std::string newContents)
81 {
82   return FindSelf()->SetTextContents(std::move(newContents));
83 }