CCustomListBox



Implements list box with supporting of any type items. Use a base class when developing a listbox-like controls.

You can find more information in comments below. Overrided methods can be found in corresponding base classes and interfaces.

class CCustomListBox :public CControlItemList
{
public:
    enum class State // Possible states 
    {
        Normal,
        Hovered,
        Focused,
        FocusedHovered,
        Disabled
    };

    using FCompare = bool(*)(IListItem *a, IListItem *b); // Items comparing(for sorting) function prototype 
protected:
    void SortItems() override;
    virtual FCompare getCompareItems(); // Return items comparison function. Null by default 
    virtual int Search(const String &search); // Return index of first item started by "search" substring. Default -1. Search should be done with applying translation to item captions(not to "search") if translateable items(like color names) are used. Also dont forget to convert to lower case("search" is already converted) 
public:
    void(*OnActivate)(IControl *sender, const int index); // Event called when item has been activated(index is -1 if there is no new active item) 
    void(*OnSelect)(IControl *sender, IListItem *item); // Event called when item has been selected 
    void(*OnDeselect)(IControl *sender, IListItem *item); // Event called when item has been deselected 

    // IControl methods 
    void Refresh(const bool refresh_children) override;

    bool InsertItem(IListItem *item, const int before) override;
    bool DeleteItem(const int index) override;
    bool DeleteItem(IListItem *item) override;
    bool DeleteItems() override;

    RectF getClientRect() override;
    RectF getRenderRect() override;

    bool setDPI(const Point &value) override;
    
    IListItemOwner *QueryListItemOwner() override;

    CCustomListBox(const String &class_name, const bool accept_form, const bool accept_control, const bool tab_stop);
    ~CCustomListBox() override;

    State getState(); // Return current state 
    bool isSortable() const; // Return whether items should be sorted 
    int getActiveIndex(); // Return active item index 
    float getSearchResetInterval() const; // Return search by typing reset interval(in seconds) 
    int getColumns() const; // Return column count 
    bool isMultiselect() const; // Whether multiple item could be selected at the same time 
    float getScrollInterval() const; // Scroll interval(in seconds) 
    // Return layout properties 
    RectF getBorderWidth() const;
    RectF getBorderRadius() const;
    RectF getPadding() const;
    ScrollVisibility getHorizontalScrollBar() const;
    ScrollVisibility getVerticalScrollBar() const;
    Color getShadowColor(const State state) const;
    PointF getShadowShift(const State state) const;
    int getShadowRadius(const State state) const;
    BorderColor getBorderColor(const State state) const;
    Color getLeftBorderColor(const State state) const;
    Color getTopBorderColor(const State state) const;
    Color getRightBorderColor(const State state) const;
    Color getBottomBorderColor(const State state) const;
    Color getBackgroundColor(const State state) const;
    Gradient *getBackgroundGradient(const State state);
    Color getCornerColor(const State state) const;

    bool setHScroll(IBuiltInScroll *value); // Assign new horizontal scroll 
    bool setVScroll(IBuiltInScroll *value); // Assign new vertical scroll 
    bool setSortable(const bool value); // Set whether items should be sorted 
    bool setActiveIndex(const int value); // Set active item 
    bool setSearchResetInterval(const float value); // Set search reset interval(in seconds) 
    bool setColumns(const int value); // Set column count 
    bool setMultiselect(const bool value); // Set whether several items could be selected at the same time 
    bool setScrollInterval(const float value); // Set scroll interval(in seconds) 
    // Set layout properties 
    bool setBorderWidth(const RectF &value);
    bool setBorderRadius(const RectF &value);
    bool setPadding(const RectF &value);
    bool setHorizontalScrollBar(const ScrollVisibility value);
    bool setVerticalScrollBar(const ScrollVisibility value);
    bool setShadowColor(const State state, const Color &value);
    bool setShadowShift(const State state, const PointF &value);
    bool setShadowRadius(const State state, const int value);
    bool setBorderColor(const State state, const BorderColor &value);
    bool setLeftBorderColor(const State state, const Color &value);
    bool setTopBorderColor(const State state, const Color &value);
    bool setRightBorderColor(const State state, const Color &value);
    bool setBottomBorderColor(const State state, const Color &value);
    bool setBackgroundColor(const State state, const Color &value);
    bool setCornerColor(const State state, const Color &value);

    void LockUpdate(); // Lock update and repaint 
    void UnlockUpdate(); // Unlock update and repaint 
};
Namespace: nitisa::standard
Include: Standard/Controls/ListBox/CustomListBox.h