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_FastScrollIndex.cpp
20 * @brief This is the implementation file for the _FastScrollIndex class.
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_FastScrollIndex.h"
26 #include "FGrp_BitmapImpl.h"
28 namespace Tizen { namespace Ui { namespace Controls
31 _FastScrollIndex::_FastScrollIndex(void)
34 , __pParentIndex(null)
35 , __pIndexObserver(null)
37 , __indexType(FAST_SCROLL_INDEX_TYPE_NORMAL)
41 _FastScrollIndex::~_FastScrollIndex(void)
45 __pIndexObserver->OnIndexDeleted(*this);
50 __pParentIndex->RemoveChildIndex(this, false);
51 __pParentIndex = null;
65 _FastScrollIndex::CreateFastScrollIndexN(void)
67 _FastScrollIndex* pIndex = new (std::nothrow) _FastScrollIndex();
68 SysTryReturn(NID_UI_CTRL, pIndex, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
70 result r = pIndex->Construct();
71 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
73 SetLastResult(E_SUCCESS);
83 _FastScrollIndex::SetIndexText(Tizen::Base::String* pText)
90 __pText = new (std::nothrow) Tizen::Base::String(*pText);
91 SysTryReturnResult(NID_UI_CTRL, __pText, E_OUT_OF_MEMORY, "Memory allocation failed.");
94 // send the action to _IFastScrollIndexObserver
97 __pIndexObserver->OnIndexDataUpdated(*this);
104 _FastScrollIndex::GetIndexText(void) const
110 _FastScrollIndex::SetIndexImage(Tizen::Graphics::Bitmap* pImage)
117 __pImage = Tizen::Graphics::_BitmapImpl::CloneN(*pImage);
120 // send the action to _IFastScrollIndexObserver
121 if (__pIndexObserver)
123 __pIndexObserver->OnIndexDataUpdated(*this);
129 Tizen::Graphics::Bitmap*
130 _FastScrollIndex::GetIndexImage(void) const
136 _FastScrollIndex::SetIndexObserver(_IFastScrollIndexObserver* pIndexListener)
138 __pIndexObserver = pIndexListener;
141 _IFastScrollIndexObserver*
142 _FastScrollIndex::GetIndexObserver(void) const
144 return __pIndexObserver;
148 _FastScrollIndex::SetOmissionIndex(int indexCountMax)
150 int childCount = GetChildCount();
151 int maxOmissionSlot = (indexCountMax - 1) / 2;
152 int omissionCount = childCount - indexCountMax;
153 int omittedNum = (omissionCount / maxOmissionSlot) + 1;
155 int additionalOmittedNum = (omissionCount % maxOmissionSlot);
156 int additionalOmissionStartIndex = ((maxOmissionSlot - additionalOmittedNum) / 2);
159 result r = E_SUCCESS;
161 Tizen::Base::String omissionText(L".");
163 if ((indexCountMax % 2) == 0)
165 r = AddChildIndex(GetChildIndex(i), true);
166 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add child index.");
171 while (i < childCount)
173 r = AddChildIndex(GetChildIndex(i), true);
174 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add child index.");
184 int omittedCount = omittedNum;
185 if ((additionalOmissionStartIndex < 0) && (additionalOmittedNum > 0))
188 additionalOmittedNum--;
191 if (omittedCount < 2)
195 additionalOmissionStartIndex--;
200 r = AddChildIndex(&omissionText, null, true);
201 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add child index.");
203 _FastScrollIndex* pOmissionBaseIndex = GetChildIndex(j, true);
204 SysTryReturnResult(NID_UI_CTRL, pOmissionBaseIndex, GetLastResult(), "Failed to get the child index.");
205 pOmissionBaseIndex->SetOmitted(true);
207 additionalOmissionStartIndex--;
209 for (int k = 0; k < omittedCount; k++)
211 pOmissionBaseIndex->AddOmissionChildIndex(GetChildIndex(i + k));
215 SetIndexType(FAST_SCROLL_INDEX_TYPE_OMISSION);
221 _FastScrollIndex::AddChildIndex(Tizen::Base::String* pText, Tizen::Graphics::Bitmap* pImage, bool omitted)
223 _FastScrollIndex* pNewIndex = _FastScrollIndex::CreateFastScrollIndexN();
224 SysTryReturnResult(NID_UI_CTRL, pNewIndex, GetLastResult(), "Failed to create _FastScrollIndex.");
226 result r = pNewIndex->SetIndexText(pText);
227 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set text.", GetErrorMessage(r));
229 pNewIndex->SetIndexImage(pImage);
231 return AddChildIndex(pNewIndex, omitted);
240 _FastScrollIndex::AddChildIndex(_FastScrollIndex* pChildIndex, bool omitted)
242 return AddChildIndex(GetChildCount(omitted), pChildIndex, omitted);
246 _FastScrollIndex::AddChildIndex(int childOrder, Tizen::Base::String* pText, Tizen::Graphics::Bitmap* pImage, bool omitted)
248 _FastScrollIndex* pNewIndex = _FastScrollIndex::CreateFastScrollIndexN();
249 SysTryReturnResult(NID_UI_CTRL, pNewIndex, GetLastResult(), "Failed to create _FastScrollIndex.");
251 result r = pNewIndex->SetIndexText(pText);
252 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set text.", GetErrorMessage(r));
254 pNewIndex->SetIndexImage(pImage);
256 return AddChildIndex(childOrder, pNewIndex, omitted);
265 _FastScrollIndex::AddChildIndex(int childOrder, _FastScrollIndex* pChildIndex, bool omitted)
267 SysTryReturnResult(NID_UI_CTRL, pChildIndex, E_INVALID_ARG, "Invalid argument is used. pChildIndex is null.");
269 Tizen::Base::Collection::ArrayList* pList = &__childIndexList;
272 pList = &__childOmittedIndexList;
275 if (pList->GetCount() <= childOrder)
277 childOrder = GetChildCount(omitted);
280 pList->InsertAt(*pChildIndex, childOrder);
281 pChildIndex->SetParentIndex(this);
283 if (__pIndexObserver)
285 __pIndexObserver->OnChildIndexAttached(*this, childOrder, *pChildIndex);
292 _FastScrollIndex::AddOmissionChildIndex(_FastScrollIndex* pChildIndex)
294 if (GetOmitted() == false)
299 SysTryReturnVoidResult(NID_UI_CTRL, pChildIndex, E_INVALID_ARG,
300 "[E_INVALID_ARG] Invalid argument is used. pChildIndex is null.");
302 __childIndexList.InsertAt(*pChildIndex, GetChildCount());
306 _FastScrollIndex::AddChildTextIndexArray(int childOrder, const wchar_t* pTextIndexArray, int textLenth, int indexCount)
308 result r = E_SUCCESS;
310 Tizen::Base::String* indexText = null;
312 wchar_t* pTempChar = new (std::nothrow) wchar_t[textLenth+1];
313 SysTryReturnResult(NID_UI_CTRL, pTempChar, E_OUT_OF_MEMORY, "Memory allocation failed.");
317 for (i = 0; i < indexCount; i++)
319 for (j = 0; j < textLenth; j++)
321 pTempChar[j] = pTextIndexArray[(i*textLenth)+j];
325 indexText = new (std::nothrow) Tizen::Base::String(pTempChar);
326 SysTryCatch(NID_UI_CTRL, indexText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
328 r = AddChildIndex(childOrder+i, indexText, null);
329 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child index.", GetErrorMessage(r));
347 _FastScrollIndex::RemoveChildIndex(int childOrder, bool destroy)
349 _FastScrollIndex* pIndex = GetChildIndex(childOrder);
350 SysTryReturnResult(NID_UI_CTRL, pIndex, GetLastResult(), "Failed to get the child index.");
352 return RemoveChildIndex(pIndex, destroy);
356 _FastScrollIndex::RemoveChildIndex(_FastScrollIndex* pChildIndex, bool destroy)
358 int detachedOrder = 0;
360 __childIndexList.IndexOf(*pChildIndex, detachedOrder);
364 __childIndexList.Remove(*pChildIndex, true);
368 __childIndexList.Remove(*pChildIndex, false);
369 pChildIndex->SetParentIndex(null);
372 if (__pIndexObserver)
374 __pIndexObserver->OnChildIndexDetached(*this, detachedOrder, *pChildIndex);
381 _FastScrollIndex::RemoveChildren(bool destroy)
383 RemoveOmissionChildren(destroy);
385 int childrenCount = __childIndexList.GetCount();
386 for (int i = childrenCount-1; i >= 0; i--)
388 __childIndexList.RemoveAt(i, destroy);
393 _FastScrollIndex::RemoveOmissionChildren(bool destroy)
395 int childrenCount = __childOmittedIndexList.GetCount();
397 if (childrenCount <= 0)
402 for (int i = childrenCount-1; i >= 0; i--)
404 _FastScrollIndex* pIndex = GetChildIndex(i, true);
405 SysTryReturnResult(NID_UI_CTRL, pIndex, GetLastResult(), "Failed to get the child index.");
407 if (pIndex->GetOmitted())
409 pIndex->RemoveChildren(false);
411 __childOmittedIndexList.RemoveAt(i, true);
415 __childOmittedIndexList.RemoveAt(i, false);
418 SetIndexType(FAST_SCROLL_INDEX_TYPE_NORMAL);
424 _FastScrollIndex::GetChildIndex(int childOrder, bool omitted) const
426 if (omitted && __childOmittedIndexList.GetCount() > 0)
428 Object* pOmittedChildIndex = const_cast <Object*>(__childOmittedIndexList.GetAt(childOrder));
429 SysTryReturn(NID_UI_CTRL, pOmittedChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
430 GetErrorMessage(GetLastResult()));
432 return dynamic_cast <_FastScrollIndex*>(pOmittedChildIndex);
435 Object* pChildIndex = const_cast <Object*>(__childIndexList.GetAt(childOrder));
436 SysTryReturn(NID_UI_CTRL, pChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
437 GetErrorMessage(GetLastResult()));
439 return dynamic_cast <_FastScrollIndex*>(pChildIndex);
443 _FastScrollIndex::GetChildOrder(const _FastScrollIndex* pChildIndex, bool omitted) const
446 if (omitted && __childOmittedIndexList.GetCount() > 0)
448 __childOmittedIndexList.IndexOf(*pChildIndex, childIndex);
452 __childIndexList.IndexOf(*pChildIndex, childIndex);
458 _FastScrollIndex::GetChildCount(bool omitted) const
462 return __childOmittedIndexList.GetCount();
465 return __childIndexList.GetCount();
469 _FastScrollIndex::SetParentIndex(_FastScrollIndex* pParent)
471 __pParentIndex = pParent;
475 _FastScrollIndex::GetParentIndex(void) const
477 return __pParentIndex;
481 _FastScrollIndex::GetIndexOrder(bool omitted) const
485 return __pParentIndex->GetChildOrder(this, omitted);
494 _FastScrollIndex::SetIndexType(_FastScrollIndexType type)
500 _FastScrollIndex::GetIndexType(void) const
506 _FastScrollIndex::SetOmitted(bool omitted)
512 _FastScrollIndex::GetOmitted(void) const
518 _FastScrollIndex::Construct(void)
523 } } } // Tizen::Ui::Controls