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 FUiCtrlGroupedTableView.h
20 * @brief This is the header file for the %GroupedTableView class.
22 * This header file contains the declarations of the %GroupedTableView class and its helper classes.
25 #ifndef _FUI_CTRL_GROUPED_TABLE_VIEW_H_
26 #define _FUI_CTRL_GROUPED_TABLE_VIEW_H_
28 #include <FGrpRectangle.h>
29 #include <FGrpColor.h>
30 #include <FUiContainer.h>
31 #include <FUiCtrlTableViewTypes.h>
33 namespace Tizen { namespace Ui { namespace Controls
35 class IGroupedTableViewItemProvider;
36 class IGroupedTableViewItemEventListener;
37 class IFastScrollListener;
38 class IScrollEventListener;
41 * @class GroupedTableView
42 * @brief This class defines common behavior for a %GroupedTableView control.
46 * The %GroupedTableView class defines common behavior for a %GroupedTableView control.
48 //Sample code for GroupedTableViewSample.h
51 class GroupedTableViewSample
52 : public Tizen::Ui::Controls::Form
53 , public Tizen::Ui::Controls::IGroupedTableViewItemProvider
54 , public Tizen::Ui::Controls::IGroupedTableViewItemEventListener
55 , public Tizen::Ui::Controls::IFastScrollListener
58 GroupedTableViewSample(void)
59 : __pGroupedTableView(null)
60 , __pContextItem(null){}
62 bool Initialize(void);
63 virtual result OnInitializing(void);
64 virtual result OnTerminating(void);
66 // IGroupedTableViewItemEventListener
67 virtual void OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status);
68 virtual void OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status);
69 virtual void OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated);
71 // IGroupedTableViewItemProvider
72 virtual int GetGroupCount(void);
73 virtual int GetItemCount(int groupIndex);
74 virtual Tizen::Ui::Controls::TableViewGroupItem* CreateGroupItem(int groupIndex, int itemWidth);
75 virtual bool DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem);
76 virtual void UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem);
77 virtual Tizen::Ui::Controls::TableViewItem* CreateItem(int groupIndex, int itemIndex, int itemWidth);
78 virtual bool DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem);
79 virtual void UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem);
80 virtual int GetDefaultItemHeight(void);
81 virtual int GetDefaultGroupItemHeight(void);
83 // IFastScrollListener
84 virtual void OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index);
87 Tizen::Ui::Controls::GroupedTableView* __pGroupedTableView;
88 Tizen::Ui::Controls::TableViewContextItem* __pContextItem;
94 //Sample code for GroupedTableViewSample.cpp
96 #include <FGraphics.h>
98 #include "GroupedTableViewSample.h"
100 using namespace Tizen::App;
101 using namespace Tizen::Base;
102 using namespace Tizen::Graphics;
103 using namespace Tizen::Media;
104 using namespace Tizen::Ui::Controls;
107 GroupedTableViewSample::Initialize(void)
109 Construct(FORM_STYLE_NORMAL);
114 GroupedTableViewSample::OnInitializing(void)
116 result r = E_SUCCESS;
118 // Creates an instance of TableView
119 __pGroupedTableView = new GroupedTableView();
120 __pGroupedTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL);
121 __pGroupedTableView->SetItemProvider(*this);
122 __pGroupedTableView->AddTableViewItemEventListener(*this);
124 __pGroupedTableView->AddFastScrollListener(*this);
125 __pGroupedTableView->SetFastScrollIndex(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ", true);
127 // Adds the TableView to the form
128 AddControl(*__pGroupedTableView);
130 // Creates an instance of TableViewContextItem
131 __pContextItem = new TableViewContextItem();
132 __pContextItem->Construct(Dimension(720, 100));
134 Button* pButton = new Button();
135 pButton->Construct(Rectangle(10, 10, 200, 80), L"Context1");
137 Button* pButton2 = new Button();
138 pButton2->Construct(Rectangle(250, 10, 200, 80), L"Context2");
140 __pContextItem->AddControl(*pButton);
141 __pContextItem->AddControl(*pButton2);
147 GroupedTableViewSample::OnTerminating(void)
149 result r = E_SUCCESS;
151 // Deallocates the item context
152 delete __pItemContext;
153 __pItemContext = null;
158 // IGroupedTableViewItemEventListener implementation
160 GroupedTableViewSample::OnGroupedTableViewGroupItemStateChanged(GroupedTableView& tableView, int groupIndex, TableViewGroupItem* pItem, TableViewItemStatus status)
162 if (tableView.IsGroupExpanded(groupIndex))
164 tableView.CollapseGroup(groupIndex);
168 tableView.ExpandGroup(groupIndex);
173 GroupedTableViewSample::OnGroupedTableViewItemStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
179 GroupedTableViewSample::OnGroupedTableViewContextItemActivationStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewContextItem* pContextItem, bool activated)
184 // IFastScrollListener implementation
186 GroupedTableViewSample::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index)
191 // IGroupedTableViewItemProvider implementation
193 GroupedTableViewSample::GetGroupCount(void)
199 GroupedTableViewSample::GetItemCount(int groupIndex)
205 GroupedTableViewSample::GetDefaultItemHeight(void)
211 GroupedTableViewSample::GetDefaultGroupItemHeight(void)
217 GroupedTableViewSample::CreateGroupItem(int groupIndex, int itemWidth)
219 TableViewGroupItem* pItem = new TableViewGroupItem();
220 pItem->Construct(Dimension(itemWidth, GetDefaultGroupItemHeight()));
223 text.Format(30, L"Group title %d", itemIndex);
225 Label* pLabel = new Label();
226 pLabel->Construct(Rectangle(0, 0, itemWidth, GetDefaultGroupItemHeight(), text);
228 pItem->AddControl(*pLable);
234 GroupedTableViewSample::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
242 GroupedTableViewSample::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
248 GroupedTableViewSample::CreateItem(int groupIndex, int itemIndex, int itemWidth)
250 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
251 TableViewItem* pItem = new TableViewItem();
253 switch (itemIndex % 5)
256 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
259 style = TABLE_VIEW_ANNEX_STYLE_MARK;
262 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
265 style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
268 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
274 pItem->Construct(Dimension(itemWidth, GetDefaultItemHeight()), style);
277 text.Format(30, L"TableViewItem %d", itemIndex);
279 Label* pLabel = new Label();
280 pLabel->Construct(Rectangle(0, 0, itemWidth, GetDefaultItemHeight(), text);
282 pItem->AddControl(*pLabel);
283 pItem->SetContextItem(__pContextItem);
289 GroupedTableViewSample::DeleteItem(int groupIndex, int itemIndex, Controls::TableViewItem* pItem)
297 GroupedTableViewSample::UpdateItem(int groupIndex, int itemIndex, Controls::TableViewItem* pItem)
305 class _OSP_EXPORT_ GroupedTableView
306 : public Tizen::Ui::Container
310 * The object is not fully constructed after this constructor is called. Hence, the Construct() method must be called after calling this constructor.
314 GroupedTableView(void);
317 * This destructor overrides Tizen::Base::Object::~Object().
321 virtual ~GroupedTableView(void);
324 * Initializes this instance of %GroupedTableView with the specified parameters.
328 * @return An error code
329 * @param[in] rect An instance of the Graphics::Rectangle class
330 * This instance represents the x and y coordinates of the left top corner of the created %GroupedTableView along with the width and height.
331 * @param[in] itemDivider Set to @c true to display an item divider, @n
333 * @param[in] scrollStyle The style of %GroupedTableView scroll bar style
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_INVALID_ARG A specified input parameter is invalid, or either the rect.width or rect.height parameter has a negative value.
338 result Construct(const Tizen::Graphics::Rectangle& rect, bool itemDivider, TableViewScrollBarStyle scrollStyle);
341 * Sets the item provider that creates and deletes items for the grouped style table view.
345 * @param[in] pProvider The item provider to create and delete items
346 * @remarks If an item provider is not set for the table view, the table view does not work. The specified provider should be allocated in heap memory.
347 * To reset the item provider, pass @c null to @c pProvider.
349 void SetItemProvider(IGroupedTableViewItemProvider* pProvider);
352 * Expands the group's items.
356 * @return An error code
357 * @param[in] groupIndex The index of the group
358 * @exception E_SUCCESS The method is successful.
359 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
361 result ExpandGroup(int groupIndex);
364 * Collapses the group's items.
368 * @return An error code
369 * @param[in] groupIndex The index of the group
370 * @exception E_SUCCESS The method is successful.
371 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
373 result CollapseGroup(int groupIndex);
376 * Expands all groups of table view.
381 void ExpandAllGroup(void);
384 * Collapses all groups of table view.
389 void CollapseAllGroup(void);
392 * Returns whether the group is expanded or not.
396 * @return @c true if the group is expanded, else @c false
397 * @param[in] groupIndex The index of the group
398 * @exception E_SUCCESS The method is successful.
399 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
401 bool IsGroupExpanded(int groupIndex) const;
404 * Sets the grouped look is enabled.
408 * @param[in] enable The enabled/disabled status
410 void SetGroupedLookEnabled(bool enable);
413 * Returns whether the grouped look is enabled or not.
417 * @return @c true if the grouped look is enabled, else @c false
419 bool IsGroupedLookEnabled(void) const;
422 * Adds a listener instance that listens to state changes of table view items. @n
423 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
427 * @return An error code
428 * @param[in] listener The event listener to add
429 * @exception E_SUCCESS The method is successful.
430 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
431 * @remarks The specified listener should be allocated in heap memory.
433 result AddGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener);
436 * Removes a listener instance that listens to state changes of table view items. @n
437 * The removed listener cannot listen to events when they are fired.
441 * @return An error code
442 * @param[in] listener The event listener to remove
443 * @exception E_SUCCESS The method is successful.
444 * @exception E_OBJ_NOT_FOUND The listener is not found.
446 result RemoveGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener);
449 * Adds a listener instance that listens to state changes of a fast scroll. @n
450 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
454 * @return An error code
455 * @param[in] listener The event listener to add
456 * @exception E_SUCCESS The method is successful.
457 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
458 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
459 * @remarks The specified listener should be allocated in heap memory.
461 result AddFastScrollListener(IFastScrollListener& listener);
464 * Removes a listener instance that listens to state changes of a fast scroll. @n
465 * The removed listener cannot listen to events when they are fired.
469 * @return An error code
470 * @param[in] listener The event listener to remove
471 * @exception E_SUCCESS The method is successful.
472 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
473 * @exception E_OBJ_NOT_FOUND The listener is not found.
475 result RemoveFastScrollListener(IFastScrollListener& listener);
478 * Adds a listener instance that listens to state changes of a scroll event. @n
479 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
483 * @return An error code
484 * @param[in] listener The event listener to add
485 * @see IScrollEventListener::OnScrollEndReached()
486 * @see RemoveScrollEventListener()
487 * @exception E_SUCCESS The method is successful.
488 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
489 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
490 * @remarks The specified listener should be allocated in heap memory.
492 result AddScrollEventListener(IScrollEventListener& listener);
495 * Removes a listener instance that listens to state changes of a scroll event. @n
496 * The removed listener cannot listen to events when they are fired.
500 * @return An error code
501 * @param[in] listener The event listener to remove
502 * @see IScrollEventListener::OnScrollEndReached()
503 * @see AddScrollEventListener()
504 * @exception E_SUCCESS The method is successful.
505 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
506 * @exception E_OBJ_NOT_FOUND The listener is not found.
508 result RemoveScrollEventListener(IScrollEventListener& listener);
511 * Enables or disables the collapse by pinch gesture.
515 * @param[in] enable Set to @c true to enable the collapse by pinch gesture, else @c false
517 void SetCollapseByPinchGestureEnabled(bool enable);
520 * Returns whether the collapse by pinch gesture is enabled or not.
524 * @return @c true if the collapse by pinch gesture is enabled, else @c false
526 bool IsCollapseByPinchGestureEnabled(void) const;
529 * Sets the text index of the fast scroll.
533 * @return An error code
534 * @param[in] text The text of the index
535 * @param[in] useSearchIcon Set to @c true to show the magnifying icon, @n
537 * @exception E_SUCCESS The method is successful.
538 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
540 result SetFastScrollIndex(const Tizen::Base::String& text, bool useSearchIcon);
543 * Gets the group and item indexes of the top item.
547 * @return An error code
548 * @param[out] groupIndex The group index
549 * @param[out] itemIndex The item index
550 * @exception E_SUCCESS The method is successful.
551 * @exception E_OBJ_NOT_FOUND Top drawn item is not found.
553 result GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const;
556 * Gets the group and item indexes of the bottom item.
560 * @return An error code
561 * @param[out] groupIndex The group index
562 * @param[out] itemIndex The item index
563 * @exception E_SUCCESS The method is successful.
564 * @exception E_OBJ_NOT_FOUND Bottom drawn item is not found.
566 result GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const;
569 * Scrolls to the item at the specified index.
570 * The specified item is drawn at the position specified by the item alignment.
574 * @return An error code
575 * @param[in] groupIndex The group index
576 * @param[in] itemIndex The item index
577 * @param[in] itemAlignment The item alignment
578 * @exception E_SUCCESS The method is successful.
579 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
580 * @remarks If the specified item. itemIndex is -1, then the method is applied to the group item with the given index.
582 result ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment = TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
585 * Checks or unchecks the item at the specified index.
589 * @return An error code
590 * @param[in] groupIndex The group index
591 * @param[in] itemIndex The item index
592 * @param[in] check Set to @c true to select the item, @n
594 * @exception E_SUCCESS The method is successful.
595 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
596 * @exception E_INVALID_OPERATION The item is disabled.
597 * @remarks This method works only when the annex style of the item allows selection.
599 result SetItemChecked(int groupIndex, int itemIndex, bool check);
602 * Returns whether the item at the specified index is selected or not.
606 * @return @c true if the item is selected, @n
608 * @param[in] groupIndex The group index
609 * @param[in] itemIndex The item index
610 * @exception E_SUCCESS The method is successful.
611 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
612 * @remarks This method returns @c false, if the annex style of the item does not allow selection.
614 bool IsItemChecked(int groupIndex, int itemIndex) const;
617 * Enables or disables the item at the specified index.
621 * @return An error code
622 * @param[in] groupIndex The group index
623 * @param[in] itemIndex The item index
624 * @param[in] enable Set to @c true to enable the specified item, @n
626 * @exception E_SUCCESS The method is successful.
627 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
629 result SetItemEnabled(int groupIndex, int itemIndex, bool enable);
632 * Returns whether the item at the specified index is enabled or disabled.
636 * @return @c true if the item is enabled, @n
638 * @param[in] groupIndex The group index
639 * @param[in] itemIndex The item index
640 * @exception E_SUCCESS The method is successful.
641 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
643 bool IsItemEnabled(int groupIndex, int itemIndex) const;
646 * Counts the total number of groups.
650 * @return The total number of groups
652 int GetGroupCount(void) const;
655 * Counts all the items of the specified group.
659 * @return The total number of items in the specified group
660 * @param[in] groupIndex The group index
661 * @exception E_SUCCESS The method is successful.
662 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
664 int GetItemCountAt(int groupIndex) const;
667 * Updates the specified item. @n
668 * For instance, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD is used when a new item needs to be added and TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE is used when an item is deleted from the
669 * table view. Moreover, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY is used when the content of an existing item has changed and it needs to be updated.
670 * Note that calling this method with TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY invokes item provider's UpdateItem() for the given index in sequence.
674 * @return An error code
675 * @param[in] groupIndex The group index
676 * @param[in] itemIndex The item index
677 * @param[in] type The item to be added, removed, or modified
678 * @exception E_SUCCESS The method is successful.
679 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
680 * @remarks If the specified item. itemIndex is -1, then the method is applied to the group item with the given index.
681 * Note that if TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE option is used to a group item, all the items in the group (including the group item itself) are
682 * removed from the table view.
684 result RefreshItem(int groupIndex, int itemIndex, TableViewRefreshType type);
687 * Updates all the items of a table view.
691 * @remarks This method clears all the items in the table view and invokes the methods of the item provider again to update the table view.
693 void UpdateTableView(void);
696 * Gets the index of the item at the specified position.
700 * @param[in] position The position of the item
701 * @param[out] groupIndex The group index of the item on specified position
702 * @param[out] itemIndex The item index of the item on specified position
703 * @remarks This method sets both of groupIndex and itemIndex to -1 if no item is found at the given position.
705 void GetItemIndexFromPosition(const Tizen::Graphics::Point& position, int& groupIndex, int& itemIndex) const;
708 * Sets the color of a division line between items.
712 * @return An error code
713 * @param[in] color The division line color
715 void SetItemDividerColor(const Tizen::Graphics::Color& color);
718 * Gets the color of a division line between items.
722 * @return The color of a division line
724 Tizen::Graphics::Color GetItemDividerColor(void) const;
727 * Sets the background color of this control.
731 * @param[in] color The background color
732 * @remarks The background bitmap has priority over the background color. When both the background bitmap and the background color are specified,
733 * only the bitmap image is displayed.
735 void SetBackgroundColor(const Tizen::Graphics::Color& color);
738 * Sets the scroll input handling mode.
742 * @param[in] mode The scroll input handling mode
743 * @see GetScrollInputMode()
745 void SetScrollInputMode(ScrollInputMode mode);
748 * Gets the scroll input handling mode.
752 * @return The scroll input handling mode
753 * @see SetScrollInputMode()
755 ScrollInputMode GetScrollInputMode(void) const;
758 * Gets the background color of this control.
762 * @return The background color
764 Tizen::Graphics::Color GetBackgroundColor(void) const;
767 * Scrolls the list contents with the amount of pixels.
771 * @return An error code
772 * @param[in] pixel The amount of pixels to scroll
773 * @exception E_SUCCESS The method is successful.
774 * @exception E_OUT_OF_RANGE The specified @c pixel is out of range.
775 * @remarks If you call ScrollByPixel() with negative @c pixel when position of scroll is already top of contents then it will return E_OUT_OF_RANGE.
776 * Likewise, in case of positive @c pixel on the bottom position of scroll it will also return E_OUT_OF_RANGE.
778 result ScrollByPixel(int pixel);
781 * Gets the current scroll position
785 int GetCurrentScrollPosition(void) const;
788 * Enables or disables the scroll of GroupedTableView items.
792 void SetScrollEnabled(bool enable);
795 * Checks whether the scroll is enabled or disabled.
799 bool IsScrollEnabled(void) const;
802 friend class _TableViewImpl;
804 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
805 GroupedTableView(const GroupedTableView& rhs);
807 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
808 GroupedTableView& operator =(const GroupedTableView& rhs);
809 }; // GroupedTableView
811 }}} // Tizen::Ui::Controls
813 #endif // _FUI_CTRL_GROUPED_TABLE_VIEW_H_