2 * Copyright (c) 2017 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>
22 #include <dali/devel-api/adaptor-framework/input-method-devel.h>
24 using namespace Dali::InputMethod;
25 using namespace Dali::InputMethod::Category;
30 #define TOKEN_STRING(x) #x
32 struct InputMethodOptions::Impl
36 mPanelLayout = PanelLayout::NORMAL;
37 mAutoCapital = AutoCapital::SENTENCE;
38 mActionButton = ActionButtonTitle::DEFAULT;
39 mVariation = NormalLayout::NORMAL;
42 PanelLayout::Type mPanelLayout;
43 AutoCapital::Type mAutoCapital;
44 ActionButtonTitle::Type mActionButton;
48 InputMethodOptions::InputMethodOptions()
50 mImpl.reset(new Impl());
53 InputMethodOptions::~InputMethodOptions()
55 // destructor cannot be inlined and must be in a unit
56 // for unique_ptr to work with forward declaration
59 bool InputMethodOptions::IsPassword()
61 return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
64 void InputMethodOptions::ApplyProperty( const Property::Map& settings )
66 for ( unsigned int i = 0, count = settings.Count(); i < count; ++i )
68 Property::Key key = settings.GetKeyAt( i );
69 if( key.type == Property::Key::INDEX )
74 Property::Value item = settings.GetValue(i);
76 if( key == TOKEN_STRING( PANEL_LAYOUT ) )
78 if( item.GetType() == Property::INTEGER )
80 int value = item.Get< int >();
81 mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
84 else if ( key == TOKEN_STRING( AUTO_CAPITALISE ) )
86 if ( item.GetType() == Property::INTEGER )
88 int value = item.Get< int >();
89 mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
92 else if ( key == TOKEN_STRING( ACTION_BUTTON ) )
94 if ( item.GetType() == Property::INTEGER )
96 int value = item.Get< int >();
97 mImpl->mActionButton = static_cast<InputMethod::ActionButtonTitle::Type>(value);
100 else if( key == TOKEN_STRING( VARIATION ) )
102 if( item.GetType() == Property::INTEGER )
104 int value = item.Get< int >();
105 mImpl->mVariation = value;
114 void InputMethodOptions::RetrieveProperty( Property::Map& settings )
116 settings[TOKEN_STRING( PANEL_LAYOUT )] = mImpl->mPanelLayout;
117 settings[TOKEN_STRING( AUTO_CAPITALISE )] = mImpl->mAutoCapital;
118 settings[TOKEN_STRING( ACTION_BUTTON )] = mImpl->mActionButton;
119 settings[TOKEN_STRING( VARIATION )] = mImpl->mVariation;
122 bool InputMethodOptions::CompareAndSet( InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
124 bool updated = false;
130 if ( options.mImpl->mPanelLayout != mImpl->mPanelLayout )
132 mImpl->mPanelLayout = options.mImpl->mPanelLayout;
133 index = static_cast<int>(mImpl->mPanelLayout);
138 case AUTO_CAPITALISE:
140 if ( options.mImpl->mAutoCapital != mImpl->mAutoCapital )
142 mImpl->mAutoCapital = options.mImpl->mAutoCapital;
143 index = static_cast<int>(mImpl->mAutoCapital);
148 case ACTION_BUTTON_TITLE:
150 if ( options.mImpl->mActionButton != mImpl->mActionButton )
152 mImpl->mActionButton = options.mImpl->mActionButton;
153 index = static_cast<int>(mImpl->mActionButton);
160 if ( options.mImpl->mVariation != mImpl->mVariation )
162 mImpl->mVariation = options.mImpl->mVariation;
163 index = static_cast<int>(mImpl->mVariation);