6 #ifndef TB_SELECT_ITEM_H
7 #define TB_SELECT_ITEM_H
9 #include "tb_linklist.h"
15 class TBSelectItemSource;
81 virtual bool Filter(
int index,
const TBStr & filter);
111 TB_SORT GetSort()
const {
return m_sort; }
115 void InvokeItemAdded(
int index);
116 void InvokeItemRemoved(
int index);
117 void InvokeAllItemsRemoved();
119 friend class TBSelectItemViewer;
120 TBLinkListOf<TBSelectItemViewer> m_viewers;
143 T *item = m_items[index];
144 widget->SetID(item->id);
145 widget->SetStateRaw(item->state);
154 if (m_items.Add(item, index))
156 InvokeItemAdded(index);
166 T *
GetItem(
int index) {
return m_items[index]; }
169 const T *
GetItem(
int index)
const {
return m_items[index]; }
180 if (!m_items.GetNumItems())
182 m_items.Delete(index);
183 InvokeItemRemoved(index);
189 if (!m_items.GetNumItems())
192 InvokeAllItemsRemoved();
203 #define def_skin TBIDC("NormalItem")
206 : str(str), id(
id), skin_image(img_id),
tag(val) {}
208 : str(str), id(str), skin_image(img_id), sub_source(sub_source) {}
215 void SetSkinImage(
const TBID &image) { skin_image = image; }
220 TBID skin_image = def_skin;
243 #endif // TB_SELECT_ITEM_H
virtual const TBStr & GetItemString(int index) const
Get the string of a item.
Definition: tb_select_item.h:134
virtual TBSelectItemSource * GetItemSubSource(int)
Get the source to be used if this item should open a sub menu.
Definition: tb_select_item.h:90
virtual int GetNumItems() const =0
Get the number of items.
bool AddItem(T *item)
Add a new item last.
Definition: tb_select_item.h:163
TB_SORT
Definition: tb_select_item.h:17
bool AddItem(T *item, int index)
Add a new item at the given index.
Definition: tb_select_item.h:152
T * FindItemByID(TBID id)
Get the item at the given index.
Definition: tb_select_item.h:172
virtual TBID GetItemID(int index) const
Get the id of the item.
Definition: tb_select_item.h:137
const T * GetItem(int index) const
Get the item at the given index.
Definition: tb_select_item.h:169
TBGenericStringItem item for TBGenericStringItemSource.
Definition: tb_select_item.h:200
Descending sort.
Definition: tb_select_item.h:20
void DeleteItem(int index)
Delete the item at the given index.
Definition: tb_select_item.h:178
TBGenericStringItemSource is a item source list providing items of type TBGenericStringItem.
Definition: tb_select_item.h:236
virtual TBSelectItemSource * GetItemSubSource(int index)
Get the source to be used if this item should open a sub menu.
Definition: tb_select_item.h:135
void SetSource(TBSelectItemSource *source)
Set the source which should provide the items for this viewer.
Definition: tb_select_item.cpp:133
virtual TBWidget * CreateItemWidget(int index, TBSelectItemViewer *viewer)
Create the item representation widget(s).
Definition: tb_select_item.h:139
T * GetItem(int index)
Get the item at the given index.
Definition: tb_select_item.h:166
TBValue tag
This value is free to use for anything.
Definition: tb_select_item.h:225
Item Separator.
Definition: tb_select_item.h:229
virtual void OnItemAdded(int index)=0
Called when the item at the given index has been added.
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
const T * FindItemByID(TBID id) const
Get the item at the given index.
Definition: tb_select_item.h:175
virtual int GetNumItems() const
Get the number of items.
Definition: tb_select_item.h:138
virtual TBWidget * CreateItemWidget(int index, TBSelectItemViewer *viewer)
Create the item representation widget(s).
Definition: tb_select_item.cpp:164
void InvokeItemChanged(int index, TBSelectItemViewer *exclude_viewer=nullptr)
Invoke OnItemChanged on all open viewers for this source.
Definition: tb_select_item.cpp:201
virtual void OnAllItemsRemoved()=0
Called when all items have been removed.
virtual TBID GetItemImage(int) const
Get the skin image to be painted before the text for this item.
Definition: tb_select_item.h:93
TBSelectItemViewer is the viewer for items provided by TBSelectItemSource.
Definition: tb_select_item.h:27
TBSelectItemSource is a item provider interface for list widgets (TBSelectList and TBSelectDropdown)...
Definition: tb_select_item.h:72
virtual void OnItemRemoved(int index)=0
Called when the item at the given index has been removed.
Definition: tb_object.h:21
TBListOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:47
void DeleteAllItems()
Delete all items.
Definition: tb_select_item.h:187
Ascending sort.
Definition: tb_select_item.h:19
TBStr is a simple string class.
Definition: tb_str.h:62
TBValue holds value of a specific type.
Definition: tb_value.h:59
Definition: tb_linklist.h:83
virtual void OnSourceChanged()=0
Called when the source has changed or been unset by calling SetSource.
void SetSort(TB_SORT sort)
Set sort type.
Definition: tb_select_item.h:110
virtual int FindIDIndex(TBID id) const
Get the index of the first item having this id or -1 if not found.
Definition: tb_select_item.cpp:193
No sorting. Items appear in list order.
Definition: tb_select_item.h:18
virtual const TBStr & GetItemString(int index) const =0
Get the string of a item.
WIDGET_STATE
TBWidget state types (may be combined).
Definition: tb_widgets.h:219
virtual void OnItemChanged(int index)=0
Called when the item at the given index has changed in a way that should update the viewer...
TBSelectItemSourceList is a item provider for list widgets (TBSelectList and TBSelectDropdown).
Definition: tb_select_item.h:128
virtual TBID GetItemID(int) const
Get the id of the item.
Definition: tb_select_item.h:96
virtual bool Filter(int index, const TBStr &filter)
Return true if an item matches the given filter text.
Definition: tb_select_item.cpp:156
virtual TBID GetItemImage(int index) const
Get the skin image to be painted before the text for this item.
Definition: tb_select_item.h:136