// treeView.h  -- TreeView widget API
#ifndef TREEVIEW_H
#define TREEVIEW_H

#include "../../../libs/kpunch/libdvx/dvxWgt.h"

typedef struct {
    WidgetT *(*create)(WidgetT *parent);
    WidgetT *(*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, WidgetT *item);
    void     (*setMultiSelect)(WidgetT *w, bool multi);
    void     (*setReorderable)(WidgetT *w, bool reorderable);
    WidgetT *(*item)(WidgetT *parent, const char *text);
    void     (*itemSetExpanded)(WidgetT *w, bool expanded);
    bool     (*itemIsExpanded)(const WidgetT *w);
    bool     (*itemIsSelected)(const WidgetT *w);
    void     (*itemSetSelected)(WidgetT *w, bool selected);
} TreeViewApiT;

static inline const TreeViewApiT *dvxTreeViewApi(void) {
    static const TreeViewApiT *sApi;
    if (!sApi) { sApi = (const TreeViewApiT *)wgtGetApi("treeview"); }
    return sApi;
}

#define wgtTreeView(parent)                       dvxTreeViewApi()->create(parent)
#define wgtTreeViewGetSelected(w)                 dvxTreeViewApi()->getSelected(w)
#define wgtTreeViewSetSelected(w, item)           dvxTreeViewApi()->setSelected(w, item)
#define wgtTreeViewSetMultiSelect(w, multi)       dvxTreeViewApi()->setMultiSelect(w, multi)
#define wgtTreeViewSetReorderable(w, reorderable) dvxTreeViewApi()->setReorderable(w, reorderable)
#define wgtTreeItem(parent, text)                 dvxTreeViewApi()->item(parent, text)
#define wgtTreeItemSetExpanded(w, expanded)       dvxTreeViewApi()->itemSetExpanded(w, expanded)
#define wgtTreeItemIsExpanded(w)                  dvxTreeViewApi()->itemIsExpanded(w)
#define wgtTreeItemIsSelected(w)                  dvxTreeViewApi()->itemIsSelected(w)
#define wgtTreeItemSetSelected(w, selected)       dvxTreeViewApi()->itemSetSelected(w, selected)

#endif // TREEVIEW_H
