2 * Copyright (c) 2018 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;
27 #define TOKEN_STRING(x) #x
29 struct InputMethodOptions::Impl
33 mPanelLayout = PanelLayout::NORMAL;
34 mAutoCapital = AutoCapital::SENTENCE;
35 mButtonAction = ButtonAction::DEFAULT;
36 mVariation = NormalLayout::NORMAL;
39 PanelLayout::Type mPanelLayout;
40 AutoCapital::Type mAutoCapital;
41 ButtonAction::Type mButtonAction;
45 InputMethodOptions::InputMethodOptions()
47 mImpl.reset(new Impl());
50 InputMethodOptions::~InputMethodOptions()
52 // destructor cannot be inlined and must be in a unit
53 // for unique_ptr to work with forward declaration
56 bool InputMethodOptions::IsPassword()
58 return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
61 void InputMethodOptions::ApplyProperty( const Property::Map& settings )
63 for ( unsigned int i = 0, count = settings.Count(); i < count; ++i )
65 Property::Key key = settings.GetKeyAt( i );
66 if( key.type == Property::Key::INDEX )
71 Property::Value item = settings.GetValue(i);
73 if( key == TOKEN_STRING( PANEL_LAYOUT ) )
75 if( item.GetType() == Property::INTEGER )
77 int value = item.Get< int >();
78 mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
81 else if ( key == TOKEN_STRING( BUTTON_ACTION ) )
83 if ( item.GetType() == Property::INTEGER )
85 int value = item.Get< int >();
86 mImpl->mButtonAction = static_cast<InputMethod::ButtonAction::Type>(value);
89 else if ( key == TOKEN_STRING( AUTO_CAPITALIZE ) )
91 if ( item.GetType() == Property::INTEGER )
93 int value = item.Get< int >();
94 mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
97 else if( key == TOKEN_STRING( VARIATION ) )
99 if( item.GetType() == Property::INTEGER )
101 int value = item.Get< int >();
102 mImpl->mVariation = value;
111 void InputMethodOptions::RetrieveProperty( Property::Map& settings )
113 settings[TOKEN_STRING( PANEL_LAYOUT )] = mImpl->mPanelLayout;
114 settings[TOKEN_STRING( BUTTON_ACTION )] = mImpl->mButtonAction;
115 settings[TOKEN_STRING( AUTO_CAPITALIZE )] = mImpl->mAutoCapital;
116 settings[TOKEN_STRING( VARIATION )] = mImpl->mVariation;
119 bool InputMethodOptions::CompareAndSet( InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
121 bool updated = false;
127 if ( options.mImpl->mPanelLayout != mImpl->mPanelLayout )
129 mImpl->mPanelLayout = options.mImpl->mPanelLayout;
130 index = static_cast<int>(mImpl->mPanelLayout);
137 if ( options.mImpl->mButtonAction != mImpl->mButtonAction )
139 mImpl->mButtonAction = options.mImpl->mButtonAction;
140 index = static_cast<int>(mImpl->mButtonAction);
145 case AUTO_CAPITALIZE:
147 if ( options.mImpl->mAutoCapital != mImpl->mAutoCapital )
149 mImpl->mAutoCapital = options.mImpl->mAutoCapital;
150 index = static_cast<int>(mImpl->mAutoCapital);
157 if ( options.mImpl->mVariation != mImpl->mVariation )
159 mImpl->mVariation = options.mImpl->mVariation;
160 index = static_cast<int>(mImpl->mVariation);