Removed REQUIRES_STYLE_CHANGE_SIGNALS
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-input-method-options.cpp
1 /*
2  * Copyright (c) 2019 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 /**
19  * This is a copy of dali-adaptor/devel-api/adaptor-framework/input-method-options.cpp.
20  */
21
22 // CLASS HEADER
23 #include <dali/devel-api/adaptor-framework/input-method-options.h>
24
25 using namespace Dali::InputMethod;
26 using namespace Dali::InputMethod::Category;
27
28 namespace Dali
29 {
30
31 #define TOKEN_STRING(x) #x
32
33 struct InputMethodOptions::Impl
34 {
35   Impl()
36   {
37     mPanelLayout = PanelLayout::NORMAL;
38     mAutoCapital = AutoCapital::SENTENCE;
39     mButtonAction = ButtonAction::DEFAULT;
40     mVariation = NormalLayout::NORMAL;
41   }
42
43   PanelLayout::Type mPanelLayout;
44   AutoCapital::Type mAutoCapital;
45   ButtonAction::Type mButtonAction;
46   int mVariation:4;
47 };
48
49 InputMethodOptions::InputMethodOptions()
50 {
51   mImpl.reset(new Impl());
52 }
53
54 InputMethodOptions::~InputMethodOptions()
55 {
56   // destructor cannot be inlined and must be in a unit
57   // for unique_ptr to work with forward declaration
58 }
59
60 bool InputMethodOptions::IsPassword() const
61 {
62   return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
63 }
64
65 void InputMethodOptions::ApplyProperty( const Property::Map& settings )
66 {
67   for ( unsigned int i = 0, count = settings.Count(); i < count; ++i )
68   {
69     Property::Key key = settings.GetKeyAt( i );
70     if( key.type == Property::Key::INDEX )
71     {
72       continue;
73     }
74
75     Property::Value item = settings.GetValue(i);
76
77     if( key == TOKEN_STRING( PANEL_LAYOUT ) )
78     {
79       if( item.GetType() == Property::INTEGER )
80       {
81         int value = item.Get< int >();
82         mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
83       }
84     }
85     else if ( key == TOKEN_STRING( BUTTON_ACTION ) )
86     {
87       if ( item.GetType() == Property::INTEGER )
88       {
89         int value = item.Get< int >();
90         mImpl->mButtonAction = static_cast<InputMethod::ButtonAction::Type>(value);
91       }
92     }
93     else if ( key == TOKEN_STRING( AUTO_CAPITALIZE ) )
94     {
95       if ( item.GetType() == Property::INTEGER )
96       {
97         int value = item.Get< int >();
98         mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
99       }
100     }
101     else if( key == TOKEN_STRING( VARIATION ) )
102     {
103       if( item.GetType() == Property::INTEGER )
104       {
105         int value = item.Get< int >();
106         mImpl->mVariation = value;
107       }
108     }
109     else
110     {
111     }
112   }
113 }
114
115 void InputMethodOptions::RetrieveProperty( Property::Map& settings )
116 {
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;
121 }
122
123 bool InputMethodOptions::CompareAndSet( InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
124 {
125   return true;
126   bool updated = false;
127
128   switch (type)
129   {
130     case PANEL_LAYOUT:
131     {
132       if ( options.mImpl->mPanelLayout != mImpl->mPanelLayout )
133       {
134         mImpl->mPanelLayout = options.mImpl->mPanelLayout;
135         index = static_cast<int>(mImpl->mPanelLayout);
136         updated = true;
137       }
138       break;
139     }
140     case BUTTON_ACTION:
141     {
142       if ( options.mImpl->mButtonAction != mImpl->mButtonAction )
143       {
144         mImpl->mButtonAction = options.mImpl->mButtonAction;
145         index = static_cast<int>(mImpl->mButtonAction);
146         updated = true;
147       }
148       break;
149     }
150     case AUTO_CAPITALIZE:
151     {
152       if ( options.mImpl->mAutoCapital != mImpl->mAutoCapital )
153       {
154         mImpl->mAutoCapital = options.mImpl->mAutoCapital;
155         index = static_cast<int>(mImpl->mAutoCapital);
156         updated = true;
157       }
158       break;
159     }
160     case VARIATION:
161     {
162       if ( options.mImpl->mVariation != mImpl->mVariation )
163       {
164         mImpl->mVariation = options.mImpl->mVariation;
165         index = static_cast<int>(mImpl->mVariation);
166         updated = true;
167       }
168       break;
169     }
170   }
171   return updated;
172 }
173
174 } // namespace Dali