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 FUiCtrlTableView.h
20 * @brief This is the header file for the %TableView class.
22 * This header file contains the declarations of the %TableView class and its helper classes.
25 #ifndef _FUI_CTRL_TABLE_VIEW_H_
26 #define _FUI_CTRL_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 ITableViewItemProvider;
36 class ITableViewItemEventListener;
37 class IFastScrollListener;
38 class IScrollEventListener;
42 * @brief This class defines common behavior for a %TableView control.
46 * The %TableView class defines common behavior for a %TableView control.
48 //Sample code for TableViewSample.h
52 : public Tizen::Ui::Controls::Form
53 , public Tizen::Ui::Controls::ITableViewItemProvider
54 , public Tizen::Ui::Controls::ITableViewItemEventListener
59 , __pContextItem(null){}
61 bool Initialize(void);
62 virtual result OnInitializing(void);
63 virtual result OnTerminating(void);
65 // ITableViewItemEventListener
66 virtual void OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status);
67 virtual void OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated);
68 virtual void OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView, int itemIndexFrom, int itemIndexTo);
70 // ITableViewItemProvider
71 virtual int GetItemCount(void);
72 virtual Tizen::Ui::Controls::TableViewItem* CreateItem(int itemIndex, int itemWidth);
73 virtual bool DeleteItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem);
74 virtual void UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem);
75 virtual int GetDefaultItemHeight(void);
78 Tizen::Ui::Controls::TableView* __pTableView;
79 Tizen::Ui::Controls::TableViewContextItem* __pContextItem;
84 //Sample code for TableViewSample.cpp
86 #include <FGraphics.h>
88 #include "TableViewSample.h"
90 using namespace Tizen::App;
91 using namespace Tizen::Base;
92 using namespace Tizen::Graphics;
93 using namespace Tizen::Media;
94 using namespace Tizen::Ui::Controls;
97 TableViewSample::Initialize(void)
99 Construct(FORM_STYLE_NORMAL);
104 TableViewSample::OnInitializing(void)
106 result r = E_SUCCESS;
108 // Creates an instance of TableView
109 __pTableView = new TableView();
110 __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
111 __pTableView->SetItemProvider(*this);
112 __pTableView->AddTableViewItemEventListener(*this);
114 // Adds the TableView to the form
115 AddControl(*__pTableView);
117 // Creates an instance of TableViewContextItem
118 __pContextItem = new TableViewContextItem();
119 __pContextItem->Construct(Dimension(720, 100));
121 Button* pButton = new Button();
122 pButton->Construct(Rectangle(10, 10, 200, 80), L"Context1");
124 Button* pButton2 = new Button();
125 pButton2->Construct(Rectangle(250, 10, 200, 80), L"Context2");
127 __pContextItem->AddControl(*pButton);
128 __pContextItem->AddControl(*pButton2);
134 TableViewSample::OnTerminating(void)
136 result r = E_SUCCESS;
138 // Deallocates the item context
139 delete __pItemContext;
140 __pItemContext = null;
145 // ITableViewItemEventListener implementation
147 TableViewSample::OnTableViewItemStateChanged(TableView& tableView, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
153 TableViewSample::OnTableViewContextItemActivationStateChanged(TableView& tableView, int itemIndex, TableViewContextItem* pContextItem, bool activated)
159 TableViewSample::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView, int itemIndexFrom, int itemIndexTo)
164 // ITableViewItemProvider implementation
166 TableViewSample::GetItemCount(void)
172 TableViewSample::GetDefaultItemHeight(void)
178 TableViewSample::CreateItem(int itemIndex, int itemWidth)
180 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
181 TableViewItem* pItem = new TableViewItem();
183 switch (itemIndex % 5)
186 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
189 style = TABLE_VIEW_ANNEX_STYLE_MARK;
192 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
195 style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
198 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
204 pItem->Construct(Dimension(itemWidth, GetDefaultItemHeight()), style);
207 text.Format(30, L"TableViewItem %d", itemIndex);
209 Label* pLabel = new Label();
210 pLabel->Construct(Rectangle(0, 0, itemWidth, GetDefaultItemHeight(), text);
212 pItem->AddControl(*pLabel);
213 pItem->SetContextItem(__pContextItem);
219 TableViewSample::DeleteItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
227 TableViewSample::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
235 class _OSP_EXPORT_ TableView
236 : public Tizen::Ui::Container
240 * The object is not fully constructed after this constructor is called. Hence, the Construct() method must be called after calling this constructor.
247 * This destructor overrides Tizen::Base::Object::~Object().
251 virtual ~TableView(void);
254 * Initializes this instance of %TableView with the specified parameters.
258 * @return An error code
259 * @param[in] rect An instance of the Graphics::Rectangle class
260 * This instance represents the x and y coordinates of the left top corner of the created %TableView along with the width and height.
261 * @param[in] itemDivider Set to @c true to display an item divider, @n
263 * @param[in] scrollStyle The style of %TableView scroll bar style
264 * @exception E_SUCCESS The method is successful.
265 * @exception E_INVALID_ARG A specified input parameter is invalid, or either the rect.width or rect.height parameter has a negative value.
268 result Construct(const Tizen::Graphics::Rectangle& rect, bool itemDivider, TableViewScrollBarStyle scrollStyle);
271 * Sets the item provider that creates and deletes items for the simple style table view.
275 * @param[in] pProvider The item provider to create and delete items
276 * @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.
277 * To reset the item provider, pass @c null to @c pProvider.
279 void SetItemProvider(ITableViewItemProvider* pProvider);
282 * Begins the reordering mode.
286 * @see ITableViewViewItemEventListener::OnTableViewItemReordered()
288 void BeginReorderingMode(void);
291 * Ends the reordering mode.
295 * @see ITableViewViewItemEventListener::OnTableViewItemReordered()
297 void EndReorderingMode(void);
300 * Returns whether the %TableView control is in reordering mode or not.
304 * @return @c true if the %TableView is in reordering mode, @n
307 bool IsInReorderingMode(void) const;
310 * Adds a listener instance that listens to state changes of table view items. @n
311 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
315 * @return An error code
316 * @param[in] listener The event listener to add
317 * @exception E_SUCCESS The method is successful.
318 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
319 * @remarks The specified listener should be allocated in heap memory.
321 result AddTableViewItemEventListener(ITableViewItemEventListener& listener);
324 * Removes a listener instance that listens to state changes of table view items. @n
325 * The removed listener cannot listen to events when they are fired.
329 * @return An error code
330 * @param[in] listener The event listener to remove
331 * @exception E_SUCCESS The method is successful.
332 * @exception E_OBJ_NOT_FOUND The listener is not found.
334 result RemoveTableViewItemEventListener(ITableViewItemEventListener& listener);
337 * Adds a listener instance that listens to state changes of a fast scroll. @n
338 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
342 * @return An error code
343 * @param[in] listener The event listener to add
344 * @exception E_SUCCESS The method is successful.
345 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
346 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
347 * @remarks The specified listener should be allocated in heap memory.
349 result AddFastScrollListener(IFastScrollListener& listener);
352 * Removes a listener instance that listens to state changes of a fast scroll. @n
353 * The removed listener cannot listen to events when they are fired.
357 * @return An error code
358 * @param[in] listener The event listener to remove
359 * @exception E_SUCCESS The method is successful.
360 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
361 * @exception E_OBJ_NOT_FOUND The listener is not found.
363 result RemoveFastScrollListener(IFastScrollListener& listener);
366 * Adds a listener instance that listens to state changes of a scroll event. @n
367 * The added listener can listen to events on the specified event dispatcher's context when they are fired.
371 * @return An error code
372 * @param[in] listener The event listener to add
373 * @see IScrollEventListener::OnScrollEndReached()
374 * @see RemoveScrollEventListener()
375 * @exception E_SUCCESS The method is successful.
376 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
377 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
378 * @remarks The specified listener should be allocated in heap memory.
380 result AddScrollEventListener(IScrollEventListener& listener);
383 * Removes a listener instance that listens to state changes of a scroll event. @n
384 * The removed listener cannot listen to events when they are fired.
388 * @return An error code
389 * @param[in] listener The event listener to remove
390 * @see IScrollEventListener::OnScrollEndReached()
391 * @see AddScrollEventListener()
392 * @exception E_SUCCESS The method is successful.
393 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
394 * @exception E_OBJ_NOT_FOUND The listener is not found.
396 result RemoveScrollEventListener(IScrollEventListener& listener);
399 * Sets the index table view of the scroll by texts.
403 * @return An error code
404 * @param[in] text The text of the index
405 * @param[in] useSearchIcon Set to @c true to show the magnifying icon, @n
407 * @exception E_SUCCESS The method is successful.
408 * @exception E_INVALID_ARG A specified input parameter is invalid.
409 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
411 result SetFastScrollIndex(const Tizen::Base::String& text, bool useSearchIcon);
414 * Gets the group and item indexes of the top item.
418 * @return The item index
419 * @exception E_SUCCESS The method is successful.
420 * @exception E_OBJ_NOT_FOUND Top drawn item is not found.
422 int GetTopDrawnItemIndex(void) const;
425 * Gets the group and item indexes of the bottom item.
429 * @return The item index
430 * @exception E_SUCCESS The method is successful.
431 * @exception E_OBJ_NOT_FOUND Bottom drawn item is not found.
433 int GetBottomDrawnItemIndex(void) const;
436 * Scrolls to the item at the specified index.
437 * The specified item is drawn at the position specified by the item alignment.
441 * @return An error code
442 * @param[in] itemIndex The targeted item index
443 * @param[in] itemAlignment The item alignment
444 * @exception E_SUCCESS The method is successful.
445 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
447 result ScrollToItem(int itemIndex, TableViewScrollItemAlignment itemAlignment = TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
450 * Checks or unchecks the item at the specified index.
454 * @return An error code
455 * @param[in] itemIndex The item index to be checked
456 * @param[in] check Set to @c true to select the item, @n
458 * @exception E_SUCCESS The method is successful.
459 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
460 * @exception E_INVALID_OPERATION The item is disabled.
461 * @remarks This method works only when the annex style of the item allows selection.
463 result SetItemChecked(int itemIndex, bool check);
466 * Returns whether the item at the specified index is selected or not.
470 * @return @c true if the item is selected, @n
472 * @param[in] itemIndex The item itemIndex
473 * @exception E_SUCCESS The method is successful.
474 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
475 * @remarks This method returns @c false, if the annex style of the item does not allow selection.
477 bool IsItemChecked(int itemIndex) const;
480 * Enables or disables the item at the specified index.
484 * @return An error code
485 * @param[in] itemIndex The item index
486 * @param[in] enable Set to @c true to enable the specified item, @n
488 * @exception E_SUCCESS The method is successful.
489 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
491 result SetItemEnabled(int itemIndex, bool enable);
494 * Returns whether the item at the specified index is enabled or disabled.
498 * @return @c true if the item is enabled, @n
500 * @param[in] itemIndex The item index
501 * @exception E_SUCCESS The method is successful.
502 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
504 bool IsItemEnabled(int itemIndex) const;
507 * Counts all the items of the specified group.
511 * @return The total number of items
513 int GetItemCount(void) const;
516 * Updates the specified item. @n
517 * 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
518 * 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.
519 * Note that calling this method with TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY invokes item provider's UpdateItem() for the given index in sequence.
523 * @return An error code
524 * @param[in] itemIndex The item index
525 * @param[in] type The item to be added, removed, or modified
526 * @exception E_SUCCESS The method is successful.
527 * @exception E_OUT_OF_RANGE A specified input parameter is invalid.
528 * @remarks If the specified itemIndex.
530 result RefreshItem(int itemIndex, TableViewRefreshType type);
533 * Updates all the items of a table view.
537 * @return An error code
538 * @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.
540 void UpdateTableView(void);
543 * Gets the index of the item at the specified position.
547 * @return The item index of the item on specified position
548 * @param[in] position The position of the item
549 * @remarks This method returns -1 if no item is found at the given position.
551 int GetItemIndexFromPosition(const Tizen::Graphics::Point& position) const;
554 * Sets the color of a division line between items.
558 * @return An error code
559 * @param[in] color The division line color
561 void SetItemDividerColor(const Tizen::Graphics::Color& color);
564 * Gets the color of a division line between items.
568 * @return The color of a division line
570 Tizen::Graphics::Color GetItemDividerColor(void) const;
573 * Sets the background color of this control.
577 * @param[in] color The background color
578 * @remarks The background bitmap has priority over the background color. When both the background bitmap and the background color are specified,
579 * only the bitmap image is displayed.
581 void SetBackgroundColor(const Tizen::Graphics::Color& color);
584 * Gets the background color of this control.
588 * @return The background color
590 Tizen::Graphics::Color GetBackgroundColor(void) const;
593 * Sets the scroll input handling mode.
597 * @param[in] mode The scroll input handling mode
598 * @see GetScrollInputMode()
600 void SetScrollInputMode(ScrollInputMode mode);
604 * Gets the scroll input handling mode.
608 * @return The scroll input handling mode
609 * @see SetScrollInputMode()
611 ScrollInputMode GetScrollInputMode(void) const;
614 * Scrolls the list contents with the amount of pixels.
618 * @return An error code
619 * @param[in] pixel The amount of pixels to scroll
620 * @exception E_SUCCESS The method is successful.
621 * @exception E_OUT_OF_RANGE The specified @c pixel is out of range.
622 * @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.
623 * Likewise, in case of positive @c pixel on the bottom position of scroll it will also return E_OUT_OF_RANGE.
625 result ScrollByPixel(int pixel);
628 * Gets the current scroll position
632 int GetCurrentScrollPosition(void) const;
635 * Enables or disables the scroll of TableView items.
639 void SetScrollEnabled(bool enable);
642 * Checks whether the scroll is enabled or disabled.
646 bool IsScrollEnabled(void) const;
649 friend class _TableViewImpl;
651 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
652 TableView(const TableView& rhs);
654 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
655 TableView& operator =(const TableView& rhs);
658 }}} // Tizen::Ui::Controls
660 #endif // _FUI_CTRL_TABLE_VIEW_H_