// widgetListBox.h  -- ListBox widget API
#ifndef WIDGET_LISTBOX_H
#define WIDGET_LISTBOX_H

#include "../core/dvxWidget.h"

typedef struct {
    WidgetT *(*create)(WidgetT *parent);
    void     (*setItems)(WidgetT *w, const char **items, int32_t count);
    int32_t  (*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, int32_t idx);
    void     (*setMultiSelect)(WidgetT *w, bool multi);
    bool     (*isItemSelected)(const WidgetT *w, int32_t idx);
    void     (*setItemSelected)(WidgetT *w, int32_t idx, bool selected);
    void     (*selectAll)(WidgetT *w);
    void     (*clearSelection)(WidgetT *w);
    void     (*setReorderable)(WidgetT *w, bool reorderable);
} ListBoxApiT;

static inline const ListBoxApiT *dvxListBoxApi(void) {
    static const ListBoxApiT *sApi;
    if (!sApi) { sApi = (const ListBoxApiT *)wgtGetApi("listbox"); }
    return sApi;
}

#define wgtListBox(parent)                          dvxListBoxApi()->create(parent)
#define wgtListBoxSetItems(w, items, count)          dvxListBoxApi()->setItems(w, items, count)
#define wgtListBoxGetSelected(w)                     dvxListBoxApi()->getSelected(w)
#define wgtListBoxSetSelected(w, idx)                dvxListBoxApi()->setSelected(w, idx)
#define wgtListBoxSetMultiSelect(w, multi)           dvxListBoxApi()->setMultiSelect(w, multi)
#define wgtListBoxIsItemSelected(w, idx)             dvxListBoxApi()->isItemSelected(w, idx)
#define wgtListBoxSetItemSelected(w, idx, selected)  dvxListBoxApi()->setItemSelected(w, idx, selected)
#define wgtListBoxSelectAll(w)                       dvxListBoxApi()->selectAll(w)
#define wgtListBoxClearSelection(w)                  dvxListBoxApi()->clearSelection(w)
#define wgtListBoxSetReorderable(w, reorderable)     dvxListBoxApi()->setReorderable(w, reorderable)

#endif // WIDGET_LISTBOX_H
