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.
19 #include <dali/devel-api/adaptor-framework/input-method-options.h>
21 using namespace Dali::InputMethod;
22 using namespace Dali::InputMethod::Category;
26 #define TOKEN_STRING(x) #x
28 struct InputMethodOptions::Impl
32 mPanelLayout = PanelLayout::NORMAL;
33 mAutoCapital = AutoCapital::SENTENCE;
34 mButtonAction = ButtonAction::DEFAULT;
35 mVariation = NormalLayout::NORMAL;
38 PanelLayout::Type mPanelLayout;
39 AutoCapital::Type mAutoCapital;
40 ButtonAction::Type mButtonAction;
44 InputMethodOptions::InputMethodOptions()
46 mImpl.reset(new Impl());
49 InputMethodOptions::~InputMethodOptions()
51 // destructor cannot be inlined and must be in a unit
52 // for unique_ptr to work with forward declaration
55 bool InputMethodOptions::IsPassword() const
57 return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
60 void InputMethodOptions::ApplyProperty(const Property::Map& settings)
62 for(unsigned int i = 0, count = settings.Count(); i < count; ++i)
64 Property::Key key = settings.GetKeyAt(i);
65 if(key.type == Property::Key::INDEX)
70 Property::Value item = settings.GetValue(i);
72 if(key == TOKEN_STRING(PANEL_LAYOUT))
74 if(item.GetType() == Property::INTEGER)
76 int value = item.Get<int>();
77 mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
80 else if(key == TOKEN_STRING(BUTTON_ACTION))
82 if(item.GetType() == Property::INTEGER)
84 int value = item.Get<int>();
85 mImpl->mButtonAction = static_cast<InputMethod::ButtonAction::Type>(value);
88 else if(key == TOKEN_STRING(AUTO_CAPITALIZE))
90 if(item.GetType() == Property::INTEGER)
92 int value = item.Get<int>();
93 mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
96 else if(key == TOKEN_STRING(VARIATION))
98 if(item.GetType() == Property::INTEGER)
100 int value = item.Get<int>();
101 mImpl->mVariation = value;
110 void InputMethodOptions::RetrieveProperty(Property::Map& settings)
112 settings[TOKEN_STRING(PANEL_LAYOUT)] = mImpl->mPanelLayout;
113 settings[TOKEN_STRING(BUTTON_ACTION)] = mImpl->mButtonAction;
114 settings[TOKEN_STRING(AUTO_CAPITALIZE)] = mImpl->mAutoCapital;
115 settings[TOKEN_STRING(VARIATION)] = mImpl->mVariation;
118 bool InputMethodOptions::CompareAndSet(InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
120 bool updated = false;
126 if(options.mImpl->mPanelLayout != mImpl->mPanelLayout)
128 mImpl->mPanelLayout = options.mImpl->mPanelLayout;
129 index = static_cast<int>(mImpl->mPanelLayout);
136 if(options.mImpl->mButtonAction != mImpl->mButtonAction)
138 mImpl->mButtonAction = options.mImpl->mButtonAction;
139 index = static_cast<int>(mImpl->mButtonAction);
144 case AUTO_CAPITALIZE:
146 if(options.mImpl->mAutoCapital != mImpl->mAutoCapital)
148 mImpl->mAutoCapital = options.mImpl->mAutoCapital;
149 index = static_cast<int>(mImpl->mAutoCapital);
156 if(options.mImpl->mVariation != mImpl->mVariation)
158 mImpl->mVariation = options.mImpl->mVariation;
159 index = static_cast<int>(mImpl->mVariation);