$#include "ListView.h" /// %ListView selection highlight mode. enum HighlightMode { /// Never highlight selections. HM_NEVER, /// Highlight when focused. HM_FOCUS, /// Highlight always. HM_ALWAYS }; /// Scrollable list %UI element. class ListView : public ScrollView { public: /// Construct. ListView(Context* context); /// Destruct. virtual ~ListView(); /// Add item to the end of the list. void AddItem(UIElement* item); /// \brief Insert item at a specific index. In hierarchy mode, the optional parameter will be used to determine the child's indent level in respect to its parent. /// If index is greater than the total items then the new item is inserted at the end of the list. /// In hierarchy mode, if index is greater than the index of last children of the specified parent item then the new item is inserted next to the last children. /// And if the index is lesser than the index of the parent item itself then the new item is inserted before the first child item. void InsertItem(unsigned index, UIElement* item, UIElement* parentItem = 0); /// Remove specific item, starting search at the specified index if provided. In hierarchy mode will also remove any children. void RemoveItem(UIElement* item, unsigned index = 0); /// Remove item at index. In hierarchy mode will also remove any children. void RemoveItem(unsigned index); /// Remove all items. void RemoveAllItems(); /// Set selection. void SetSelection(unsigned index); /// Add item to the selection, multiselect mode only. void AddSelection(unsigned index); /// Remove item from the selection. void RemoveSelection(unsigned index); /// Toggle selection of an item. void ToggleSelection(unsigned index); /// Move selection by a delta and clamp at list ends. If additive (multiselect only), will add to the existing selection. void ChangeSelection(int delta, bool additive = false); /// Clear selection. void ClearSelection(); /// Set selected items' highlight mode. void SetHighlightMode(HighlightMode mode); /// Enable multiselect. void SetMultiselect(bool enable); /// \brief Enable hierarchy mode. Allows items to have parent-child relationship at different indent level and the ability to expand/collapse child items. /// All items in the list will be lost during mode change. void SetHierarchyMode(bool enable); /// Set base indent, i.e. the indent level of the ultimate parent item. void SetBaseIndent(int baseIndent); /// Enable clearing of selection on defocus. void SetClearSelectionOnDefocus(bool enable); /// Set item doubleclick interval in seconds. void SetDoubleClickInterval(float interval); /// Expand item at index. Only has effect in hierarchy mode. void Expand(unsigned index, bool enable, bool recursive = false); /// Toggle item's expanded flag at index. Only has effect in hierarchy mode. void ToggleExpand(unsigned index, bool recursive = false); /// Return number of items. unsigned GetNumItems() const; /// Return item at index. UIElement* GetItem(unsigned index) const; /// Return index of item, or M_MAX_UNSIGNED If not found. unsigned FindItem(UIElement* item) const; /// Return first selected index, or M_MAX_UNSIGNED if none selected. unsigned GetSelection() const; /// Return first selected item, or null if none selected. UIElement* GetSelectedItem() const; /// Return whether an item at index is seleccted. bool IsSelected(unsigned index) const; /// Return whether an item at index has its children expanded (in hierachy mode only). bool IsExpanded(unsigned index) const; /// Return highlight mode. HighlightMode GetHighlightMode() const { return highlightMode_; } /// Return whether multiselect enabled. bool GetMultiselect() const { return multiselect_; } /// Return whether selection is cleared on defocus. bool GetClearSelectionOnDefocus() const { return clearSelectionOnDefocus_; } /// Return whether hierarchy mode enabled. bool GetHierarchyMode() const { return hierarchyMode_; } /// Return base indent. int GetBaseIndent() const { return baseIndent_; } /// Return item doubleclick interval in seconds. float GetDoubleClickInterval() const; };