2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUi_ResourceConfigMacro.h
19 * @brief This is the header file for resource config macros.
22 * This header file contains declaration of resource config macros..
25 #ifndef _FUI_RESOURCE_CONFIG_MACRO_H_
26 #define _FUI_RESOURCE_CONFIG_MACRO_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"
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\
46 class control ## Config\
49 control ## Config(void)\
51 ConfigLoader::GetInstance()->AddInitFunc(control ## Config::Initialize);\
53 ~control ## Config(void){};\
54 static bool Initialize(MapContainer & table, const String & mode);\
56 static const char* GetControlName(void)\
60 static String GetCurrentThemeName(void)\
64 static String GetAPIVersion(void)\
66 if(Tizen::App::_AppInfo::IsOspCompat())\
75 static void ConvertStringToColor32(const char* pString, Color& color)\
81 unsigned int temp = 0;\
82 len = strlen(pString);\
85 SysLog(NID_UI, "String is empty");\
88 for (index = 1; index < len + 1; index++)\
91 if ((ch >= '0') && (ch <= '9'))\
97 else if ((ch >= 'A') && (ch <= 'F'))\
100 gap = ch - 'A' + 10;\
103 else if ((ch >= 'a') && (ch <= 'f'))\
106 gap = ch - 'a' + 10;\
110 color.SetRGB32(temp, true);\
112 static void AddDimensionConfig(MapContainer & table, const char* key, int width, int height)\
114 Dimension* pDimension = null;\
115 ResourceDimensionMap* pDimensionMap = table.GetDimensionMap();\
116 if(pDimensionMap != null)\
118 String _key = GetControlName();\
121 result r = pDimensionMap->GetValue(_key, pDimension);\
122 if(r == E_OBJ_NOT_FOUND)\
124 pDimension = new (std::nothrow) Dimension(width, height);\
125 SysAssert(pDimension);\
126 pDimensionMap->Add(_key, pDimension);\
128 else if(r == E_SUCCESS)\
130 pDimension->SetSize(width, height);\
134 static void AddShapeConfig(MapContainer & table, const char* key, int value)\
136 Integer* pInteger = null;\
137 ResourceShapeMap* pShapeMap = table.GetShapeMap();\
138 if(pShapeMap != null)\
140 String _key = GetControlName();\
143 result r = pShapeMap->GetValue(_key, pInteger);\
144 if(r == E_OBJ_NOT_FOUND)\
146 pInteger = new (std::nothrow) Integer(value);\
147 SysAssert(pInteger);\
148 pShapeMap->Add(_key, pInteger);\
150 else if(r == E_SUCCESS)\
156 static void AddFixedValueConfig(MapContainer & table, const char* key, int value)\
158 Integer* pInteger = null;\
159 ResourceShapeMap* pFixedValueMap = table.GetFixedValueMap();\
160 if(pFixedValueMap != null)\
162 String _key = GetControlName();\
165 result r = pFixedValueMap->GetValue(_key, pInteger);\
166 if(r == E_OBJ_NOT_FOUND)\
168 pInteger = new (std::nothrow) Integer(value);\
169 SysAssert(pInteger);\
170 pFixedValueMap->Add(_key, pInteger);\
172 else if(r == E_SUCCESS)\
178 static void AddImageConfig(MapContainer & table, const char* key, const char* value)\
180 String* pString = null;\
181 ResourceImageMap* pImageMap = table.GetImageMap();\
182 if(pImageMap != null)\
184 String _key = GetControlName();\
187 result r = pImageMap->GetValue(_key, pString);\
188 if(r == E_OBJ_NOT_FOUND)\
190 pString = new (std::nothrow) String(value);\
192 pString->SubString(1,*pString);\
193 pImageMap->Add(_key, pString);\
195 else if(r == E_SUCCESS)\
198 pString->SubString(1,*pString);\
202 static void AddColorConfig(MapContainer & table, const char* key, const char* value)\
204 Color* pColor = null;\
206 result r = E_FAILURE;\
207 ResourceColorMap* pColorMap = table.GetColorMap();\
208 if(pColorMap != null)\
210 _key = GetControlName();\
213 String valueString(value);\
214 if((valueString.StartsWith(L"$", 0)))\
216 Color* pColor2 = null;\
218 valueString.SubString(1, key2);\
219 if(!(key2.Contains(L"::")))\
221 key2.Insert("DEFAULTCOLORTABLE::",0);\
223 r = pColorMap->GetValue(key2, pColor);\
226 SysLog(NID_UI,"[OBJ_NOT_FOUND] Resource color code is not valid : %s", value);\
227 r = pColorMap->GetValue(L"foreground", pColor);\
230 pColor2 = new (std::nothrow) Color(*pColor);\
232 pColorMap->Add(_key, pColor2);\
236 pColor2 = new (std::nothrow) Color(0xff000000);\
238 pColorMap->Add(_key, pColor2);\
244 r = pColorMap->ContainsKey(_key, found);\
247 pColorMap->SetValue(_key, pColor2);\
251 pColor2 = new (std::nothrow) Color(*pColor);\
253 pColorMap->Add(_key, pColor2);\
254 SysLog(NID_UI, "Resource Color is added , key : %ls, value : %x", _key.GetPointer(), pColor2->GetRGB32());\
260 r = pColorMap->GetValue(_key, pColor);\
261 if(r == E_OBJ_NOT_FOUND)\
263 pColor = new (std::nothrow) Color();\
265 ConvertStringToColor32(value,*pColor);\
266 pColorMap->Add(_key, pColor);\
268 else if(r == E_SUCCESS)\
271 ConvertStringToColor32(value,_color);\
272 pColorMap->SetValue(_key, &_color);\
277 control ## Config(const control ## Config &);\
278 control ## Config& operator =(const control ## Config&);\
280 bool control ## Config::Initialize(MapContainer & table, const String & mode)\
282 String themeName = GetCurrentThemeName();\
283 String apiVer = GetAPIVersion();\
284 String __mode = mode;\
285 if (themeName.GetLength() > 0)\
287 __mode = __mode + L"_" + themeName;\
289 #define START_UI_CONFIG_API_VERSION(ver)\
292 #define END_UI_CONFIG_API_VERSION(ver)\
295 #define START_UI_CONFIG_MODE(_mode)\
296 if (__mode == #_mode)\
298 #define END_UI_CONFIG_MODE(_mode)\
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);
307 #define END_UI_CONFIG(control)\
310 control ## Config __config ## control;\
311 }}}//Tizen::Ui::_Resource
313 #endif // _FUI_RESOURCE_CONFIG_MACRO_H_