2 * Copyright (c) 2019 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 * This is a copy of dali-adaptor/devel-api/adaptor-framework/input-method-options.cpp.
23 #include <dali/devel-api/adaptor-framework/input-method-options.h>
25 using namespace Dali::InputMethod;
26 using namespace Dali::InputMethod::Category;
31 #define TOKEN_STRING(x) #x
33 struct InputMethodOptions::Impl
37 mPanelLayout = PanelLayout::NORMAL;
38 mAutoCapital = AutoCapital::SENTENCE;
39 mButtonAction = ButtonAction::DEFAULT;
40 mVariation = NormalLayout::NORMAL;
43 PanelLayout::Type mPanelLayout;
44 AutoCapital::Type mAutoCapital;
45 ButtonAction::Type mButtonAction;
49 InputMethodOptions::InputMethodOptions()
51 mImpl.reset(new Impl());
54 InputMethodOptions::~InputMethodOptions()
56 // destructor cannot be inlined and must be in a unit
57 // for unique_ptr to work with forward declaration
60 bool InputMethodOptions::IsPassword() const
62 return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
65 void InputMethodOptions::ApplyProperty( const Property::Map& settings )
67 for ( unsigned int i = 0, count = settings.Count(); i < count; ++i )
69 Property::Key key = settings.GetKeyAt( i );
70 if( key.type == Property::Key::INDEX )
75 Property::Value item = settings.GetValue(i);
77 if( key == TOKEN_STRING( PANEL_LAYOUT ) )
79 if( item.GetType() == Property::INTEGER )
81 int value = item.Get< int >();
82 mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
85 else if ( key == TOKEN_STRING( BUTTON_ACTION ) )
87 if ( item.GetType() == Property::INTEGER )
89 int value = item.Get< int >();
90 mImpl->mButtonAction = static_cast<InputMethod::ButtonAction::Type>(value);
93 else if ( key == TOKEN_STRING( AUTO_CAPITALIZE ) )
95 if ( item.GetType() == Property::INTEGER )
97 int value = item.Get< int >();
98 mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
101 else if( key == TOKEN_STRING( VARIATION ) )
103 if( item.GetType() == Property::INTEGER )
105 int value = item.Get< int >();
106 mImpl->mVariation = value;
115 void InputMethodOptions::RetrieveProperty( Property::Map& settings )
117 settings[TOKEN_STRING( PANEL_LAYOUT )] = mImpl->mPanelLayout;
118 settings[TOKEN_STRING( BUTTON_ACTION )] = mImpl->mButtonAction;
119 settings[TOKEN_STRING( AUTO_CAPITALIZE )] = mImpl->mAutoCapital;
120 settings[TOKEN_STRING( VARIATION )] = mImpl->mVariation;
123 bool InputMethodOptions::CompareAndSet( InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
126 bool updated = false;
132 if ( options.mImpl->mPanelLayout != mImpl->mPanelLayout )
134 mImpl->mPanelLayout = options.mImpl->mPanelLayout;
135 index = static_cast<int>(mImpl->mPanelLayout);
142 if ( options.mImpl->mButtonAction != mImpl->mButtonAction )
144 mImpl->mButtonAction = options.mImpl->mButtonAction;
145 index = static_cast<int>(mImpl->mButtonAction);
150 case AUTO_CAPITALIZE:
152 if ( options.mImpl->mAutoCapital != mImpl->mAutoCapital )
154 mImpl->mAutoCapital = options.mImpl->mAutoCapital;
155 index = static_cast<int>(mImpl->mAutoCapital);
162 if ( options.mImpl->mVariation != mImpl->mVariation )
164 mImpl->mVariation = options.mImpl->mVariation;
165 index = static_cast<int>(mImpl->mVariation);