From eff6ef3fa03afe2dbeaa7a182faa3d0ec78a732a Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 18 Oct 2025 12:51:41 +0000 Subject: [PATCH] fix segfault git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@407 b9cfdab3-6d41-4d17-bbe4-086880011989 --- src/filechooser.c | 12 ++++++++++++ src/widget/listbox.c | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/filechooser.c b/src/filechooser.c index a25098b..76cac42 100644 --- a/src/filechooser.c +++ b/src/filechooser.c @@ -28,6 +28,8 @@ typedef struct filechooser { MwLLPixmap computer; } filechooser_t; +static void scan(MwWidget handle, const char* path); + static void destroy(MwWidget handle) { filechooser_t* fc = handle->opaque; int i; @@ -67,6 +69,15 @@ static void okay(MwWidget handle, void* user, void* call) { destroy(handle->parent); } +static void files_activate(MwWidget handle, void* user, void* call) { + int index = *(int*)call; + filechooser_t* fc = handle->parent->opaque; + + (void)user; + + scan(handle->parent, fc->sorted_entries[index - 1]->name); +} + static void layout(MwWidget handle) { filechooser_t* fc = handle->opaque; int w = MwGetInteger(handle, MwNwidth); @@ -100,6 +111,7 @@ static void layout(MwWidget handle) { MwNhasHeading, 1, MwNleftPadding, 16, NULL); + MwAddUserHandler(fc->files, MwNactivateHandler, files_activate, NULL); } else { MwVaApply(fc->files, MwNx, wx, diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 44e2648..35d3294 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -73,13 +73,16 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) { int h = MwGetInteger(handle, MwNheight); st = get_first_entry(handle->parent, lb); - for(i = 0; i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) { + for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) { if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M"))) { unsigned long t; + + lb->selected = st + i; + if(((t = MwLLGetTick()) - lb->click_time) < 250 && lb->selected == st + i) { MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected); } - lb->selected = st + i; + lb->click_time = t; } y += MwTextHeight(handle, "M"); @@ -114,7 +117,7 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) { int h = MwGetInteger(handle, MwNheight); st = get_first_entry(handle->parent, lb); - for(i = 0; i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) { + for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) { if(y <= p->y && p->y <= (y + MwTextHeight(handle, "M"))) { lb->selected = st + i; }