diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index 24d0d94..d8e556f 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -126,7 +126,6 @@ struct _MwListBox { MwWidget vscroll; MwWidget frame; MwListBoxEntry* list; - int selected; unsigned long click_time; int pressed; int* width; diff --git a/src/dialog/filechooser.c b/src/dialog/filechooser.c index b0eda3d..cd5bcc9 100644 --- a/src/dialog/filechooser.c +++ b/src/dialog/filechooser.c @@ -68,9 +68,16 @@ static void cancel_window(MwWidget handle, void* user, void* call) { } static void okay(MwWidget handle, void* user, void* call) { + filechooser_t* fc = handle->parent->opaque; + char* p; + (void)user; (void)call; + p = MwDirectoryJoin(fc->path, fc->sorted_entries[MwGetInteger(fc->files, MwNvalue)]->name); + MwDispatchUserHandler(handle->parent, MwNfileChosenHandler, p); + free(p); + destroy(handle->parent); } diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 4ab02a2..71202f6 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -133,12 +133,13 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) { for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) { if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M") + Padding)) { unsigned long t; - int old = lb->selected; + int old = MwGetInteger(handle->parent, MwNvalue); - lb->selected = st + i; + MwSetInteger(handle->parent, MwNvalue, st + i); if((((t = MwTimeGetTick()) - lb->click_time) < MwDoubleClickTimeout && old == st + i) || MwGetInteger(handle->parent, MwNsingleClickSelectable)) { - MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected); + int n = MwGetInteger(handle->parent, MwNvalue); + MwDispatchUserHandler(handle->parent, MwNactivateHandler, &n); } lb->click_time = t; @@ -177,7 +178,7 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) { st = get_first_entry(handle->parent, lb); for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) { if(y <= p->y && p->y <= (y + MwTextHeight(handle, "M") + Padding)) { - lb->selected = st + i; + MwSetInteger(handle->parent, MwNvalue, st + i); } y += MwTextHeight(handle, "M") + Padding; } @@ -219,7 +220,7 @@ static void frame_draw(MwWidget handle) { ent = area / MwTextHeight(handle, "M") + 2; for(i = st; i < arrlen(lb->list) && i < st + ent; i++) { - int selected = lb->selected == i ? 1 : 0; + int selected = MwGetInteger(handle->parent, MwNvalue) == i ? 1 : 0; int j; if(selected) { @@ -346,10 +347,10 @@ static int create(MwWidget handle) { MwSetInteger(handle, MwNsingleClickSelectable, 0); MwSetInteger(handle, MwNhasHeading, 0); MwSetInteger(handle, MwNleftPadding, 0); + MwSetInteger(handle, MwNvalue, -1); resize(handle); lb->list = NULL; - lb->selected = -1; lb->click_time = 0; lb->width = NULL; lb->alignment = NULL; @@ -480,11 +481,11 @@ static void mwListBoxDeleteImpl(MwWidget handle, int index) { arrfree(lb->list[index].name); arrdel(lb->list, index); - if(lb->selected >= arrlen(lb->list)) { - lb->selected = arrlen(lb->list) - 1; + if(MwGetInteger(handle, MwNvalue) >= arrlen(lb->list)) { + MwSetInteger(handle, MwNvalue, arrlen(lb->list) - 1); } - if(lb->selected < 0) { - lb->selected = -1; + if(MwGetInteger(handle, MwNvalue) < 0) { + MwSetInteger(handle, MwNvalue, -1); } resize(handle); @@ -505,7 +506,7 @@ static void mwListBoxResetImpl(MwWidget handle) { arrdel(lb->list, 0); } - lb->selected = -1; + MwSetInteger(handle, MwNvalue, -1); MwSetInteger(lb->vscroll, MwNvalue, 0);