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.
19 * @file FUiCtrl_CustomListItemFormatImpl.cpp
20 * @brief This file contains implementation of _CustomListItemFormatImpl class
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_CustomListItemFormatImpl.h"
25 #include "FUi_ResourceManager.h"
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Base::Collection;
30 namespace Tizen { namespace Ui { namespace Controls
33 _ElementFormatData::_ElementFormatData(void)
40 _ElementFormatData::~_ElementFormatData(void)
44 _CustomListItemFormatImpl::_CustomListItemFormatImpl(void)
48 _CustomListItemFormatImpl::~_CustomListItemFormatImpl(void)
50 elementFormatDataList.RemoveAll(true);
53 _CustomListItemFormatImpl*
54 _CustomListItemFormatImpl::CreateInstanceN(void)
56 _CustomListItemFormatImpl* pImpl = new (std::nothrow) _CustomListItemFormatImpl();
57 SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
63 _CustomListItemFormatImpl::GetElementFormatById(int elementId)
65 for (int elementCount = 0; elementCount < elementFormatDataList.GetCount(); elementCount++)
67 _ElementFormatData* pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(elementCount));
68 SysTryReturn(NID_UI_CTRL, pElementFormatData, null, E_SYSTEM, "Invalid format data.");
70 if (pElementFormatData->elementId == elementId)
72 return pElementFormatData;
80 _CustomListItemFormatImpl::CreateElementN(int elementId)
82 _ElementFormatData* pElementFormatData = new (std::nothrow) _ElementFormatData();
83 SysTryReturn(NID_UI_CTRL, pElementFormatData, null, E_OUT_OF_MEMORY, "The memory is insufficient.");
85 pElementFormatData->elementId = elementId;
87 GET_SHAPE_CONFIG(LIST::TEXT_ELEMENT_FONTSIZE_DEFAULT, _CONTROL_ORIENTATION_PORTRAIT, pElementFormatData->textSize);
89 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->normalTextColor);
90 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->highlightedTextColor);
91 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->focusedTextColor);
93 return pElementFormatData;
97 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect)
99 _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
100 result r = E_SUCCESS;
102 if (!pElementFormatData)
104 pElementFormatData = CreateElementN(elementId);
106 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
108 r = elementFormatDataList.Add(*pElementFormatData);
109 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111 GET_SHAPE_CONFIG(LIST::TEXT_ELEMENT_FONTSIZE_DEFAULT, _CONTROL_ORIENTATION_PORTRAIT, pElementFormatData->textSize);
114 pElementFormatData->rect = rect;
120 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize)
122 _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
123 result r = E_SUCCESS;
125 if (!pElementFormatData)
127 pElementFormatData = CreateElementN(elementId);
129 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
131 r = elementFormatDataList.Add(*pElementFormatData);
132 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
135 pElementFormatData->rect = rect;
136 pElementFormatData->textSize = textSize;
142 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize, const Color& normalTextColor, const Color& focusedTextColor)
144 _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
145 result r = E_SUCCESS;
147 if (!pElementFormatData)
149 pElementFormatData = CreateElementN(elementId);
151 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
153 r = elementFormatDataList.Add(*pElementFormatData);
154 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 pElementFormatData->rect = rect;
158 pElementFormatData->textSize = textSize;
160 pElementFormatData->normalTextColor = normalTextColor;
161 pElementFormatData->focusedTextColor = focusedTextColor;
162 pElementFormatData->highlightedTextColor = normalTextColor;
168 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize, const Color& normalTextColor, const Color& focusedTextColor, const Color& highlightedTextColor)
170 _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
171 result r = E_SUCCESS;
173 if (!pElementFormatData)
175 pElementFormatData = CreateElementN(elementId);
177 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
179 r = elementFormatDataList.Add(*pElementFormatData);
180 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
183 pElementFormatData->rect = rect;
184 pElementFormatData->textSize = textSize;
186 pElementFormatData->normalTextColor = normalTextColor;
187 pElementFormatData->focusedTextColor = focusedTextColor;
188 pElementFormatData->highlightedTextColor = highlightedTextColor;
194 _CustomListItemFormatImpl::GetElement(int elementId) const
196 _ElementFormatData* pElementFormatData = null;
197 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
199 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
201 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
203 return pElementFormatData->rect;
207 return Rectangle(0, 0, -1, -1);
211 _CustomListItemFormatImpl::GetFirstElementId(void)
213 _ElementFormatData* pElementFormatData = null;
215 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
217 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
218 if (pElementFormatData != null)
220 return pElementFormatData->elementId;
228 _CustomListItemFormatImpl::GetFirstEnabledElementId(void)
230 _ElementFormatData* pElementFormatData = null;
232 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
234 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
235 if (pElementFormatData != null && pElementFormatData->enable)
237 return pElementFormatData->elementId;
245 _CustomListItemFormatImpl::GetNextElementId(int elementId)
247 _ElementFormatData* pElementFormatData = null;
248 int nextElementId = -1;
251 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
253 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
254 if (pElementFormatData != null)
256 if (elementId == pElementFormatData->elementId)
260 else if (found == true)
262 nextElementId = pElementFormatData->elementId;
267 return nextElementId;
271 _CustomListItemFormatImpl::GetNextEnabledElementId(int elementId)
273 _ElementFormatData* pElementFormatData = null;
274 int nextEnabledElementId = -1;
277 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
279 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
280 if (pElementFormatData != null)
282 if (pElementFormatData->elementId == elementId)
286 else if (pElementFormatData->enable && found == true)
288 nextEnabledElementId = pElementFormatData->elementId;
294 return nextEnabledElementId;
298 _CustomListItemFormatImpl::GetPreviousEnabledElementId(int elementId)
300 _ElementFormatData* pElementFormatData = null;
301 int prevEnabledElementId = -1;
303 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
305 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
306 if (pElementFormatData != null)
308 if (pElementFormatData->elementId != elementId)
310 prevEnabledElementId = pElementFormatData->elementId;
312 else if (pElementFormatData->enable && pElementFormatData->elementId == elementId)
319 return prevEnabledElementId;
323 _CustomListItemFormatImpl::IsElementEventEnabled(int elementId)
325 _ElementFormatData* pElementFormatData = null;
327 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
329 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
330 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
332 return pElementFormatData->enable;
340 _CustomListItemFormatImpl::SetElementEventEnabled(int elementId, bool enable)
342 _ElementFormatData* pElementFormatData = null;
344 for (int count = 0; count < elementFormatDataList.GetCount(); count++)
346 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
347 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
349 pElementFormatData->enable = enable;
356 }}} //Tizen::Ui::Controls