2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 FUiCtrlCustomList.h
20 * @brief This is the header file for the %CustomList class.
22 * This header file contains the declarations of the %CustomList class and its helper classes.
25 #ifndef _FUI_CTRL_CUSTOM_LIST_H_
26 #define _FUI_CTRL_CUSTOM_LIST_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FGrpRectangle.h>
31 #include <FUiControl.h>
32 #include <FUiContainer.h>
33 #include <FUiCtrlCustomListTypes.h>
34 #include <FUiICustomItemEventListener.h>
35 #include <FUiCtrlCustomListItem.h>
36 #include <FUiCtrlListTypes.h>
38 namespace Tizen { namespace Ui { namespace Controls
44 * @brief <i> [Deprecated] </i> This class defines the common behavior of a %CustomList control.
46 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
49 * The %CustomList class represents a list which has user-configured items. An item in a custom list can have
50 * different layout and height than the other items. Each item is composed of elements, which can be texts and bitmaps
51 * and is configured using CustomListItem and CustomListItemFormat.
53 * When an item in a custom list is selected or deselected, an item event is generated. It is passed on to all item event listeners
54 * that have registered an interest in item events generated by the custom list. If an application wants to perform tasks when a custom
55 * list item is selected and deselected, it must implement ICustomItemEventListener and register the listener to receive events from
56 * the custom list by calling the custom list's AddCustomItemEventListener() method.
58 * Note that CustomListItem and CustomListItemFormat need to be created on a heap. The items of a custom list are deleted automatically
59 * when the %CustomList control is destroyed. If you want to remove certain list items, you must use RemoveItemAt(). CustomListItemFormat
60 * must be deleted by the application.
62 * Refer to CustomListItem and CustomListItemFormat.
66 * @image html ui_controls_customlist.png
69 * This is a simple UI application that uses a %CustomList control.
73 //Sample code for CustomListSample.h
76 // Forward Declaration
77 class CustomListElement;
79 class CustomListSample
80 : public Tizen::Ui::Controls::Form
81 , public Tizen::Ui::ICustomItemEventListener
84 CustomListSample(void)
86 , __pCustomListItemFormat(null)
87 , __pListElement(null){}
89 bool Initialize(void);
90 result AddListItem(Tizen::Ui::Controls::CustomList& customList, Tizen::Base::String itemText,
91 Tizen::Graphics::Bitmap* pBitmapNormal, Tizen::Graphics::Bitmap* pBitmapFocused);
93 virtual result OnInitializing(void);
94 virtual result OnTerminating(void);
96 // ICustomItemEventListener
97 virtual void OnItemStateChanged(const Tizen::Ui::Control& source, int index, int itemId, Tizen::Ui::ItemStatus status);
98 virtual void OnItemStateChanged(const Tizen::Ui::Control& source, int index, int itemId, int elementId, Tizen::Ui::ItemStatus status);
101 static const int ID_LIST_ITEM = 101;
102 static const int ID_LIST_TEXT = 102;
103 static const int ID_LIST_BITMAP = 103;
104 static const int ID_FORMAT_CUSTOM = 104;
106 Tizen::Ui::Controls::CustomList* __pCustomList;
107 Tizen::Ui::Controls::CustomListItemFormat* __pCustomListItemFormat;
108 CustomListElement* __pListElement;
113 // Sample code for CutomListSample.cpp
115 #include <FGraphics.h>
117 #include "CustomListSample.h"
119 using namespace Tizen::App;
120 using namespace Tizen::Base;
121 using namespace Tizen::Graphics;
122 using namespace Tizen::Ui;
123 using namespace Tizen::Ui::Controls;
125 class CustomListElement
126 : public ICustomListElement
130 DrawElement(const Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& rect, CustomListItemStatus itemStatus)
132 result r = E_SUCCESS;
134 Canvas* pCanvas = const_cast<Canvas*>(&canvas);
136 pCanvas->SetLineWidth(5);
137 pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_GREEN));
138 if (pCanvas->DrawRectangle(rect) != E_SUCCESS)
143 if (pCanvas->DrawText(Point(rect.x+20, rect.y+20), L"Custom") != E_SUCCESS)
153 CustomListSample::Initialize()
155 Construct(FORM_STYLE_NORMAL);
160 CustomListSample::OnInitializing(void)
162 result r = E_SUCCESS;
164 // Creates an instance of CustomListElement
165 __pListElement = new CustomListElement();
167 // Creates an instance of CustomList
168 __pCustomList = new CustomList();
169 __pCustomList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), CUSTOM_LIST_STYLE_NORMAL);
170 __pCustomList->AddCustomItemEventListener(*this);
172 // Creates an instance of CustomListItemFormat
173 __pCustomListItemFormat = new CustomListItemFormat();
174 __pCustomListItemFormat->Construct();
175 __pCustomListItemFormat->AddElement(ID_LIST_TEXT, Rectangle(10, 25, 150, 80));
176 __pCustomListItemFormat->AddElement(ID_LIST_BITMAP, Rectangle(170, 10, 70, 80));
177 __pCustomListItemFormat->AddElement(ID_FORMAT_CUSTOM, Rectangle(GetClientAreaBounds().width - 120, 20, 100, 60));
178 __pCustomListItemFormat->SetElementEventEnabled(ID_LIST_TEXT, true);
179 __pCustomListItemFormat->SetElementEventEnabled(ID_LIST_BITMAP, true);
180 __pCustomListItemFormat->SetElementEventEnabled(ID_FORMAT_CUSTOM, true);
182 // Gets instances of Bitmap
183 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
184 Bitmap *pBitmapNormal = pAppResource->GetBitmapN(L"tizen.png");
185 Bitmap *pBitmapFocused = pAppResource->GetBitmapN(L"tizen.png");
187 // Adds the item to the custom list
188 for (int i = 0; i < 30; i++)
190 String str = L"Text";
192 AddListItem(*__pCustomList, str, pBitmapNormal, pBitmapFocused);
195 // Adds the custom list to the form
196 AddControl(*__pCustomList);
198 // Deallocates bitmaps
199 delete pBitmapNormal;
200 delete pBitmapFocused;
206 CustomListSample::OnTerminating(void)
208 result r = E_SUCCESS;
210 // Deallocates item format and the element
211 delete __pCustomListItemFormat;
212 delete __pListElement;
218 CustomListSample::AddListItem(CustomList& customList, String itemText, Bitmap* pBitmapNormal, Bitmap* pBitmapFocused)
220 // Creates an instance of CustomListItem
221 CustomListItem* pItem = new CustomListItem();
223 pItem->Construct(100);
224 pItem->SetItemFormat(*__pCustomListItemFormat);
225 pItem->SetElement(ID_LIST_TEXT, itemText);
226 pItem->SetElement(ID_LIST_BITMAP, *pBitmapNormal, pBitmapFocused);
227 pItem->SetElement(ID_FORMAT_CUSTOM, *(static_cast<ICustomListElement *>(__pListElement)));
229 customList.AddItem(*pItem, ID_LIST_ITEM);
234 // ICustomItemEventListener implementation
236 CustomListSample::OnItemStateChanged(const Control& source, int index, int itemId, ItemStatus status)
251 CustomListSample::OnItemStateChanged(const Control& source, int index, int itemId, int elementId, Tizen::Ui::ItemStatus status)
282 class _OSP_EXPORT_ CustomList
283 : public Tizen::Ui::Control
288 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
290 * @brief <i> [Deprecated] </i>
291 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
299 * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
301 * @brief <i> [Deprecated] </i>
302 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
306 virtual ~CustomList(void);
311 * Initializes this instance of %CustomList with the specified parameters.
313 * @brief <i> [Deprecated] </i>
314 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
317 * @return An error code
318 * @param[in] rect The x and y position of the top-left corner of the %CustomList control along with the width and height of the control
319 * @param[in] style The style set of %CustomList
320 * @param[in] itemDivider Set to @c true to display the divider, @n
322 * @exception E_SUCCESS The method is successful.
323 * @exception E_INVALID_ARG A specified input parameter is invalid.
324 * @exception E_SYSTEM A system error has occurred.
325 * @remarks The size of the control must be within the range as defined by the minimum and maximum size.
326 * @remarks The minimum size of this control is 92 x 72 on a WVGA screen, 60 x 48 on a HVGA screen and 46 x 36 on a WQVGA screen.
329 result Construct(const Tizen::Graphics::Rectangle& rect, CustomListStyle style, bool itemDivider = true);
334 * Adds the custom item event listener instance. @n
335 * The added listener gets notified when the state of CustomListItem is changed.
337 * @brief <i> [Deprecated] </i>
338 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
341 * @param[in] listener The event listener to add
344 void AddCustomItemEventListener(Tizen::Ui::ICustomItemEventListener& listener);
348 * Removes the custom item event listener instance. @n
349 * The removed listener is not notified even when custom item events are fired.
351 * @brief <i> [Deprecated] </i>
352 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
355 * @param[in] listener The event listener to remove
358 void RemoveCustomItemEventListener(Tizen::Ui::ICustomItemEventListener& listener);
362 * Adds the specified item to the %CustomList control.
364 * @brief <i> [Deprecated] </i>
365 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
368 * @return An error code
369 * @param[in] item The custom list item to add
370 * @param[in] itemId The item ID for the item
371 * @exception E_SUCCESS The method is successful.
372 * @exception E_SYSTEM A system error has occurred.
373 * @remarks The specified @c itemId can be used to identify a specific CustomListItem or @n
374 * to associate user-allocated resources. @n
375 * Note that the custom list does not throw an exception @n
376 * if the same itemID is assigned to multiple items. @n
377 * @remarks The added item is deleted automatically when the list is destroyed. @n
378 * Do not add, insert, or set an item that already belongs to the %CustomList control.
381 result AddItem(const CustomListItem& item, int itemId = LIST_ITEM_UNSPECIFIED_ID);
385 * Inserts the specified item to %CustomList at the specified index.
387 * @brief <i> [Deprecated] </i>
388 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
391 * @return An error code
392 * @param[in] index The index at which to insert the item
393 * @param[in] item The custom list item to insert
394 * @param[in] itemId The item ID for the item
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
397 * The specified @c index is less than @c 0 or greater than or equal to the item count.
398 * @exception E_SYSTEM A system error has occurred.
399 * @remarks The inserted item is deleted automatically when the list is destroyed. @n
400 * Do not add, insert, or set an item that already belongs to the %CustomList control.
403 result InsertItemAt(int index, const CustomListItem& item, int itemId = LIST_ITEM_UNSPECIFIED_ID);
407 * Sets the contents of the item at the specified index in the %CustomList control.
409 * @brief <i> [Deprecated] </i>
410 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
413 * @return An error code
414 * @param[in] index The index at which to set the contents of the item
415 * @param[in] item The custom list item to set
416 * @param[in] itemId The item ID for the item
417 * @exception E_SUCCESS The method is successful.
418 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
419 * The specified @c index is less than @c 0 or greater than or equal to the item count.
420 * @exception E_SYSTEM A system error has occurred.
421 * @remarks Do not add, insert, or set an item that already belongs to the %CustomList control.
424 result SetItemAt(int index, const CustomListItem& item, int itemId = LIST_ITEM_UNSPECIFIED_ID);
428 * Removes the item at the specified index in the %CustomList control.
430 * @brief <i> [Deprecated] </i>
431 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
434 * @return An error code
435 * @param[in] index The index of the item to delete
436 * @exception E_SUCCESS The method is successful.
437 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
438 * The specified @c index is less than @c 0 or greater than or equal to the item count.
439 * @exception E_SYSTEM A system error has occurred.
440 * @remarks The removed list item is deleted from the memory.
443 result RemoveItemAt(int index);
447 * Removes all the items from the %CustomList control.
449 * @brief <i> [Deprecated] </i>
450 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
453 * @return An error code
454 * @exception E_SUCCESS The method is successful.
455 * @exception E_SYSTEM A system error has occurred.
456 * @remarks The removed list items are deleted from the memory.
459 result RemoveAllItems(void);
463 * Gets the item at the specified index in the %CustomList control.
465 * @brief <i> [Deprecated] </i>
466 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
469 * @return A custom list item, @n
470 * else @c null if the specified index is out of range
471 * @param[in] index The index of the item to get
474 const CustomListItem* GetItemAt(int index) const;
478 * Gets the number of items in the %CustomList control.
480 * @brief <i> [Deprecated] </i>
481 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
484 * @return The number of items in %CustomList, @n
485 * else @c -1 if an error occurs
488 int GetItemCount(void) const;
492 * Enables or disables the status of the item at the specified @c index in the %CustomList control.
494 * @brief <i> [Deprecated] </i>
495 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
498 * @return An error code
499 * @param[in] index The index of the item whose status is to set
500 * @param[in] enable Set to @c true to enable, @n
502 * @exception E_SUCCESS The method is successful.
503 * @exception E_SYSTEM A system error has occurred.
506 result SetItemEnabled(int index, bool enable);
510 * Checks whether the specified index in the %CustomList control is enabled.
512 * @brief <i> [Deprecated] </i>
513 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
516 * @return @c true if the item is enabled, @n
518 * @param[in] index The index of the item to check
521 bool IsItemEnabled(int index) const;
525 * Sets the check status of the item at the specified index in the %CustomList control.
527 * @brief <i> [Deprecated] </i>
528 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
531 * @return An error code
532 * @param[in] index The index of the item to set
533 * @param[in] check The check status
534 * @exception E_SUCCESS The method is successful.
535 * @exception E_SYSTEM A system error has occurred.
536 * @remarks This method can only be used when the style of the list allows selection.
539 result SetItemChecked(int index, bool check);
543 * Checks whether the item at the specified index is checked in the %CustomList control.
545 * @brief <i> [Deprecated] </i>
546 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
549 * @return @c true if the item is checked, @n
551 * @param[in] index The index of the item to check
552 * @remarks This method can only be used when the style of the list allows selection.
555 bool IsItemChecked(int index) const;
559 * Sets the check status for all items of the %CustomList control.
561 * @brief <i> [Deprecated] </i>
562 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
565 * @return An error code
566 * @param[in] check The check status
567 * @exception E_SUCCESS The method is successful.
568 * @exception E_SYSTEM A system error has occurred.
569 * @remarks This method can only be used when the style of the list allows multiple selections.
572 result SetAllItemsChecked(bool check);
577 * Removes the checked items of the %CustomList control.
579 * @brief <i> [Deprecated] </i>
580 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
583 * @return An error code
584 * @exception E_SUCCESS The method is successful.
585 * @exception E_SYSTEM A system error has occurred.
586 * @remarks This method can only be used when the style of the list allows multiple selections.
587 * @remarks The removed list items are deleted from the memory.
590 result RemoveAllCheckedItems(void);
594 * Gets the first item of all the checked items in the %CustomList control.
596 * @brief <i> [Deprecated] </i>
597 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
600 * @return The index of the first checked item, @n
601 * else @c -1 if no item is checked or an error occurs
604 int GetFirstCheckedItemIndex(void) const;
608 * Gets the last item of all the checked items in the %CustomList control.
610 * @brief <i> [Deprecated] </i>
611 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
614 * @return The index of the last checked item, @n
615 * else @c -1 if no item is checked or an error occurs
618 int GetLastCheckedItemIndex(void) const;
622 * Gets the next checked item from the specified index in the %CustomList control.
624 * @brief <i> [Deprecated] </i>
625 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
628 * @return The index of the next checked item @n
629 * else @c -1 if no more item after the specified index is checked, @n
630 * or the specified @c index is less than @c 0 or greater than the item count.
631 * @param[in] index The index of the %CustomList control item
634 int GetNextCheckedItemIndexAfter(int index) const;
638 * Gets the index of the item at the specified position.
640 * @brief <i> [Deprecated] </i>
641 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
644 * @return The index of the item, @n
645 * else @c -1 if the specified position is not inside any of the items
646 * @param[in] x The x position of the point
647 * @param[in] y The y position of the point
650 int GetItemIndexFromPosition(int x, int y) const;
654 * Gets the index of the item at the specified position.
656 * @brief <i> [Deprecated] </i>
657 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
660 * @return The index of the item, @n
661 * else @c -1 if the specified position is not inside any of the items
662 * @param[in] position The position of the point
665 int GetItemIndexFromPosition(const Tizen::Graphics::Point& position) const;
669 * Gets the index of the first item from the visible items in the %CustomList control.
671 * @brief <i> [Deprecated] </i>
672 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
675 * @return The index of the first item, @n
676 * else @c -1 if no item is visible
679 int GetTopDrawnItemIndex(void) const;
683 * Gets the index of the last item from the visible items in the %CustomList control.
685 * @brief <i> [Deprecated] </i>
686 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
689 * @return The index of the last item, @n
690 * else @c -1 if no item is visible
693 int GetBottomDrawnItemIndex(void) const;
697 * Sets the background color of the %CustomList control.
699 * @brief <i> [Deprecated] </i>
700 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
703 * @param[in] color The background color
706 void SetBackgroundColor(const Tizen::Graphics::Color& color);
710 * Sets the text to be displayed when there is no item in the %CustomList control.
712 * @brief <i> [Deprecated] </i>
713 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
716 * @param[in] text The text message to display
719 void SetTextOfEmptyList(const Tizen::Base::String& text);
723 * Sets the color of the text to be displayed when there is no item in the %CustomList control.
725 * @brief <i> [Deprecated] </i>
726 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
729 * @param[in] color The color of the text to display
732 void SetTextColorOfEmptyList(const Tizen::Graphics::Color& color);
736 * Gets the color of the text to display when there is no item in the CustomList control.
738 * @brief <i> [Deprecated] </i>
739 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
742 * @return The color of the text to be displayed
745 Tizen::Graphics::Color GetTextColorOfEmptyList(void) const;
749 * Gets the index of the item.
751 * @brief <i> [Deprecated] </i>
752 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
755 * @return The index of the item, @n
756 * else @c -1 if no item has the specified item ID
757 * @param[in] itemId The item ID of the %CustomList control item
758 * @remarks One or more indexes can have the same item ID, @n
759 * and this method returns the first item from such items.
762 int GetItemIndexFromItemId(int itemId) const;
766 * Gets the item ID of the item at the specified index.
768 * @brief <i> [Deprecated] </i>
769 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
772 * @return The item ID of the item, @n
773 * else @c -1 if the specified @c index is less than @c 0 or greater than the item count
774 * @param[in] index The index of the %CustomList control item
777 int GetItemIdAt(int index) const;
781 * Scrolls to the bottom of the %CustomList control.
783 * @brief <i> [Deprecated] </i>
784 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
788 void ScrollToBottom(void);
792 * Scrolls to the top of the %CustomList.
794 * @brief <i> [Deprecated] </i>
795 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
799 void ScrollToTop(void);
803 * Scrolls to the item at the specified index. @n
804 * The specified item is drawn at the top of the %CustomList control.
806 * @brief <i> [Deprecated] </i>
807 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
810 * @return An error code
811 * @param[in] index The index of the %CustomList control item
812 * @exception E_SUCCESS The method is successful.
813 * @exception E_SYSTEM A system error has occurred.
814 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
815 * The specified @c index is less than @c 0 or greater than the item count.
818 result ScrollToTop(int index);
822 * Draws and shows the item at the specified index in the %CustomList control.
824 * @brief <i> [Deprecated] </i>
825 * @deprecated This class is deprecated. Instead of using this class, use ListView class.
828 * @return An error code
830 * @param[in] index The index of the %CustomList control item
831 * @exception E_SUCCESS The method is successful.
832 * @exception E_SYSTEM A system error has occurred.
833 * @exception E_INVALID_OPERATION The item has never been drawn before calling this method.
834 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
835 * The specified @c index is less than @c 0 or greater than the item count.
838 result RefreshItem(int index);
842 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
844 CustomList(const CustomList& rhs);
847 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
849 CustomList& operator =(const CustomList& rhs);
851 friend class _CustomListImpl;
855 }}} //Tizen::Ui::Controls
857 #endif // _FUI_CTRL_CUSTOM_LIST_H_