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