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