Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / resource / FUi_ResourceConfigMacro.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUi_ResourceConfigMacro.h
19  * @brief               This is the header file for resource config macros.
20  * @version             3.0
21  *
22  * This header file contains declaration of resource config macros..
23  *
24  */
25 #ifndef _FUI_RESOURCE_CONFIG_MACRO_H_
26 #define _FUI_RESOURCE_CONFIG_MACRO_H_
27
28 #include <new>
29 #include <string.h>
30 #include <FBaseString.h>
31 #include <FBaseSysLog.h>
32 #include <FBaseInteger.h>
33 #include <FGrpColor.h>
34 #include <FGrpDimension.h>
35 #include <FApp_AppInfo.h>
36 #include "FUi_ResourceConfigLoader.h"
37 #include "FUi_ResourceConfigParser.h"
38 #include "FUi_ResourceMapContainer.h"
39
40 #define START_UI_CONFIG(control)\
41 using namespace Tizen::Base;\
42 using namespace Tizen::Base::Collection;\
43 using namespace Tizen::Graphics;\
44 namespace Tizen { namespace Ui { namespace _Resource\
45 {\
46 class control ## Config\
47 {\
48 public:\
49         control ## Config(void)\
50         {\
51                 ConfigLoader::GetInstance()->AddInitFunc(control ## Config::Initialize);\
52         };\
53         ~control ## Config(void){};\
54         static bool Initialize(MapContainer & table, const String & mode);\
55 private:\
56         static const char* GetControlName(void)\
57         {\
58                 return #control;\
59         }\
60         static String GetCurrentThemeName(void)\
61         {\
62                 return L"";\
63         };\
64         static String GetAPIVersion(void)\
65         {\
66                 if(Tizen::App::_AppInfo::IsOspCompat())\
67                 {\
68                         return L"2.0";\
69                 }\
70                 else \
71                 {\
72                         return L"";\
73                 }\
74         };\
75         static void ConvertStringToColor32(const char* pString, Color& color)\
76         {\
77                 int index = 0;\
78                 int len = 0;\
79                 int gap = 0;\
80                 char ch;\
81                 unsigned int temp = 0;\
82                 len = strlen(pString);\
83                 if (len < 1)\
84                 {\
85                         SysLog(NID_UI, "String is empty");\
86                         return;\
87                 }\
88                 for (index = 1; index < len + 1; index++)\
89                 {\
90                         ch = pString[index];\
91                         if ((ch >= '0') && (ch <= '9'))\
92                         {\
93                                 temp = temp << 4;\
94                                 gap = ch - '0';\
95                                 temp |= gap;\
96                         }\
97                         else if ((ch >= 'A') && (ch <= 'F'))\
98                         {\
99                                 temp = temp << 4;\
100                                 gap = ch - 'A' + 10;\
101                                 temp |= gap;\
102                         }\
103                         else if ((ch >= 'a') && (ch <= 'f'))\
104                         {\
105                                 temp = temp << 4;\
106                                 gap = ch - 'a' + 10;\
107                                 temp |= gap;\
108                         }\
109                 }\
110                 color.SetRGB32(temp, true);\
111         };\
112         static void AddDimensionConfig(MapContainer & table, const char* key, int width, int height)\
113         {\
114                 Dimension* pDimension = null;\
115                 ResourceDimensionMap* pDimensionMap = table.GetDimensionMap();\
116                 if(pDimensionMap != null)\
117                 {\
118                         String _key = GetControlName();\
119                         _key.Append(L"::");\
120                         _key.Append(key);\
121                         result r = pDimensionMap->GetValue(_key, pDimension);\
122                         if(r == E_OBJ_NOT_FOUND)\
123                         {\
124                                 pDimension = new (std::nothrow) Dimension(width, height);\
125                                 SysAssert(pDimension);\
126                                 pDimensionMap->Add(_key, pDimension);\
127                         }\
128                         else if(r == E_SUCCESS)\
129                         {\
130                                 pDimension->SetSize(width, height);\
131                         }\
132                 }\
133         };\
134         static void AddShapeConfig(MapContainer & table, const char* key, int value)\
135         {\
136                 Integer* pInteger = null;\
137                 ResourceShapeMap* pShapeMap = table.GetShapeMap();\
138                 if(pShapeMap != null)\
139                 {\
140                         String _key = GetControlName();\
141                         _key.Append(L"::");\
142                         _key.Append(key);\
143                         result r = pShapeMap->GetValue(_key, pInteger);\
144                         if(r == E_OBJ_NOT_FOUND)\
145                         {\
146                                 pInteger = new (std::nothrow) Integer(value);\
147                                 SysAssert(pInteger);\
148                                 pShapeMap->Add(_key, pInteger);\
149                         }\
150                         else if(r == E_SUCCESS)\
151                         {\
152                                 *pInteger = value;\
153                         }\
154                 }\
155         };\
156         static void AddFixedValueConfig(MapContainer & table, const char* key, int value)\
157         {\
158                 Integer* pInteger = null;\
159                 ResourceShapeMap* pFixedValueMap = table.GetFixedValueMap();\
160                 if(pFixedValueMap != null)\
161                 {\
162                         String _key = GetControlName();\
163                         _key.Append(L"::");\
164                         _key.Append(key);\
165                         result r = pFixedValueMap->GetValue(_key, pInteger);\
166                         if(r == E_OBJ_NOT_FOUND)\
167                         {\
168                                 pInteger = new (std::nothrow) Integer(value);\
169                                 SysAssert(pInteger);\
170                                 pFixedValueMap->Add(_key, pInteger);\
171                         }\
172                         else if(r == E_SUCCESS)\
173                         {\
174                                 *pInteger = value;\
175                         }\
176                 }\
177         };\
178         static void AddImageConfig(MapContainer & table, const char* key, const char* value)\
179         {\
180                 String* pString = null;\
181                 ResourceImageMap* pImageMap = table.GetImageMap();\
182                 if(pImageMap != null)\
183                 {\
184                         String _key = GetControlName();\
185                         _key.Append(L"::");\
186                         _key.Append(key);\
187                         result r = pImageMap->GetValue(_key, pString);\
188                         if(r == E_OBJ_NOT_FOUND)\
189                         {\
190                                 pString = new (std::nothrow) String(value);\
191                                 SysAssert(pString);\
192                                 pString->SubString(1,*pString);\
193                                 pImageMap->Add(_key, pString);\
194                         }\
195                         else if(r == E_SUCCESS)\
196                         {\
197                                 *pString = value;\
198                                 pString->SubString(1,*pString);\
199                         }\
200                 }\
201         };\
202         static void AddColorConfig(MapContainer & table, const char* key, const char* value)\
203         {\
204                 Color* pColor = null;\
205                 String _key = L"";\
206                 result r = E_FAILURE;\
207                 ResourceColorMap* pColorMap = table.GetColorMap();\
208                 if(pColorMap != null)\
209                 {\
210                         _key = GetControlName();\
211                         _key.Append(L"::");\
212                         _key.Append(key);\
213                         String valueString(value);\
214                         if((valueString.StartsWith(L"$", 0)))\
215                         {\
216                                 Color* pColor2 = null;\
217                                 String key2(L"");\
218                                 valueString.SubString(1, key2);\
219                                 if(!(key2.Contains(L"::")))\
220                                 {\
221                                         key2.Insert("DEFAULTCOLORTABLE::",0);\
222                                 }\
223                                 r = pColorMap->GetValue(key2, pColor);\
224                                 if(r != E_SUCCESS)\
225                                 {\
226                                         SysLog(NID_UI,"[OBJ_NOT_FOUND] Resource color code is not valid : %s", value);\
227                                         r = pColorMap->GetValue(L"foreground", pColor);\
228                                         if(r == E_SUCCESS)\
229                                         {\
230                                                 pColor2 = new (std::nothrow) Color(*pColor);\
231                                                 SysAssert(pColor2);\
232                                                 pColorMap->Add(_key, pColor2);\
233                                         }\
234                                         else\
235                                         {\
236                                                 pColor2 = new (std::nothrow) Color(0xff000000);\
237                                                 SysAssert(pColor2);\
238                                                 pColorMap->Add(_key, pColor2);\
239                                         }\
240                                 }\
241                                 else\
242                                 {\
243                                         bool found = false;\
244                                         r = pColorMap->ContainsKey(_key, found);\
245                                         if(found)\
246                                         {\
247                                                 pColorMap->SetValue(_key, pColor2);\
248                                         }\
249                                         else\
250                                         {\
251                                                 pColor2 = new (std::nothrow) Color(*pColor);\
252                                                 SysAssert(pColor2);\
253                                                 pColorMap->Add(_key, pColor2);\
254                                                 SysLog(NID_UI, "Resource Color is added , key : %ls, value : %x", _key.GetPointer(), pColor2->GetRGB32());\
255                                         }\
256                                 }\
257                         }\
258                         else\
259                         {\
260                                 r = pColorMap->GetValue(_key, pColor);\
261                                 if(r == E_OBJ_NOT_FOUND)\
262                                 {\
263                                         pColor = new (std::nothrow) Color();\
264                                         SysAssert(pColor);\
265                                         ConvertStringToColor32(value,*pColor);\
266                                         pColorMap->Add(_key, pColor);\
267                                 }\
268                                 else if(r == E_SUCCESS)\
269                                 {\
270                                         Color _color;\
271                                         ConvertStringToColor32(value,_color);\
272                                         pColorMap->SetValue(_key, &_color);\
273                                 }\
274                         }\
275                 }\
276         };\
277         control ## Config(const control ## Config &);\
278         control ## Config& operator =(const control ## Config&);\
279 };\
280 bool control ## Config::Initialize(MapContainer & table, const String & mode)\
281 {\
282         String themeName = GetCurrentThemeName();\
283         String apiVer = GetAPIVersion();\
284         String __mode = mode;\
285         if (themeName.GetLength() > 0)\
286         {\
287                 __mode = __mode + L"_" + themeName;\
288         }
289 #define START_UI_CONFIG_API_VERSION(ver)\
290         if(apiVer == ver)\
291         {
292 #define END_UI_CONFIG_API_VERSION(ver)\
293         }
294
295 #define START_UI_CONFIG_MODE(_mode)\
296         if (__mode == #_mode)\
297         {
298 #define END_UI_CONFIG_MODE(_mode)\
299         }
300
301 #define ADD_DIMENSION_CONFIG(key, width, height) AddDimensionConfig(table, #key, width, height);
302 #define ADD_COLOR_CONFIG(key, value) AddColorConfig(table, #key, #value);
303 #define ADD_SHAPE_CONFIG(key, value) AddShapeConfig(table, #key, value);
304 #define ADD_FIXED_VALUE_CONFIG(key, value) AddFixedValueConfig(table, #key, value);
305 #define ADD_IMAGE_CONFIG(key, value) AddImageConfig(table, #key, #value);
306
307 #define END_UI_CONFIG(control)\
308         return true;\
309 };\
310 control ## Config __config ## control;\
311 }}}//Tizen::Ui::_Resource
312
313 #endif // _FUI_RESOURCE_CONFIG_MACRO_H_