diff --git a/include/Mw/Widget/TreeView.h b/include/Mw/Widget/TreeView.h index 6c450b9..83f8b42 100644 --- a/include/Mw/Widget/TreeView.h +++ b/include/Mw/Widget/TreeView.h @@ -81,6 +81,16 @@ MwInline void MwTreeViewSetPixmap(MwWidget handle, void* item, MwLLPixmap pixmap MwVaWidgetExecute(handle, "mwTreeViewSetPixmap", NULL, item, pixmap); } +/*! + * @brief Sets the opened state of ithe item + * @param handle Widget + * @param item Item + * @param opened Opened or not + */ +MwInline void MwTreeViewSetOpened(MwWidget handle, void* item, int opened) { + MwVaWidgetExecute(handle, "mwTreeViewSetOpened", NULL, item, opened); +} + #ifdef __cplusplus } #endif diff --git a/src/core.c b/src/core.c index 074145e..e184f8c 100644 --- a/src/core.c +++ b/src/core.c @@ -238,10 +238,10 @@ static void MwFreeWidget(MwWidget handle) { void MwDestroyWidget(MwWidget handle) { if(handle->parent != NULL) { int i; - for(i = 0; i < arrlen(handle->parent->destroy_queue); i++){ + for(i = 0; i < arrlen(handle->parent->destroy_queue); i++) { if(handle->parent->destroy_queue[i] == handle) break; } - if(i == arrlen(handle->parent->destroy_queue)){ + if(i == arrlen(handle->parent->destroy_queue)) { arrput(handle->parent->destroy_queue, handle); } } diff --git a/src/widget/treeview.c b/src/widget/treeview.c index 564ec13..1d99316 100644 --- a/src/widget/treeview.c +++ b/src/widget/treeview.c @@ -410,7 +410,17 @@ static void mwTreeViewSetPixmapImpl(MwWidget handle, void* item, MwLLPixmap pixm e->pixmap = pixmap; - if(e->parent != NULL && e->parent->opened) { + if(e->parent == NULL || (e->parent != NULL && e->parent->opened)) { + resize(handle); + } +} + +static void mwTreeViewSetOpenedImpl(MwWidget handle, void* item, int opened) { + MwTreeViewEntry* e = item; + + e->opened = opened; + + if(e->parent == NULL || (e->parent != NULL && e->parent->opened)) { resize(handle); } } @@ -443,6 +453,11 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v MwLLPixmap pixmap = va_arg(va, MwLLPixmap); mwTreeViewSetPixmapImpl(handle, item, pixmap); } + if(strcmp(name, "mwTreeViewSetOpened") == 0) { + void* item = va_arg(va, void*); + int opened = va_arg(va, int); + mwTreeViewSetOpenedImpl(handle, item, opened); + } } static void tick(MwWidget handle) {