From bdd3618e153d5518275f3afdccdf5a4bed90756e Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 16 Nov 2025 09:22:29 +0000 Subject: [PATCH] better git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@745 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/TypeDefs.h | 3 +-- src/widget/combobox.c | 18 ++++++++++++------ src/widget/listbox.c | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index ee6b4ff..9fe099e 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -124,7 +124,7 @@ struct _MwListBox { MwWidget vscroll; MwWidget frame; MwListBoxEntry* list; - int selected; + int selected; unsigned long click_time; int pressed; int* width; @@ -134,7 +134,6 @@ struct _MwListBox { struct _MwComboBox { char** list; int opened; - int selected; MwWidget listbox; }; diff --git a/src/widget/combobox.c b/src/widget/combobox.c index 0dd7ce7..387eaba 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -8,13 +8,13 @@ static int create(MwWidget handle) { cb->list = NULL; cb->opened = 0; - cb->selected = 0; cb->listbox = NULL; handle->internal = cb; MwSetDefault(handle); MwSetInteger(handle, MwNareaShown, 6); + MwSetInteger(handle, MwNvalue, 0); return 0; } @@ -46,13 +46,13 @@ static void draw(MwWidget handle) { rc = r; /* draw text */ - if(arrlen(cb->list) > cb->selected) { + if(arrlen(cb->list) > MwGetInteger(handle, MwNvalue)) { MwPoint p; p.x = MwDefaultBorderWidth(handle) * 2 + 4; p.y = MwGetInteger(handle, MwNheight) / 2; - MwDrawText(handle, &p, cb->list[cb->selected], 0, MwALIGNMENT_BEGINNING, text); + MwDrawText(handle, &p, cb->list[MwGetInteger(handle, MwNvalue)], 0, MwALIGNMENT_BEGINNING, text); } r = rc; @@ -84,7 +84,7 @@ static void listbox_activate(MwWidget handle, void* user, void* client) { (void)user; - cb->selected = *(int*)client; + MwSetInteger(handle->parent, MwNvalue, *(int*)client); cb->opened = 0; cb->listbox = NULL; @@ -154,6 +154,12 @@ static void click(MwWidget handle) { MwForceRender(handle); } +static void prop_change(MwWidget handle, const char* prop) { + if(strcmp(prop, MwNvalue) == 0) { + MwForceRender(handle); + } +} + static void mwComboBoxAddImpl(MwWidget handle, int index, const char* text) { MwComboBox cb = handle->internal; char* t = MwStringDupliacte(text); @@ -162,7 +168,7 @@ static void mwComboBoxAddImpl(MwWidget handle, int index, const char* text) { arrins(cb->list, index, t); - if(index <= cb->selected) MwForceRender(handle); + if(index <= MwGetInteger(handle, MwNvalue)) MwForceRender(handle); } static const char* mwComboBoxGetImpl(MwWidget handle, int index) { @@ -189,7 +195,7 @@ MwClassRec MwComboBoxClassRec = { draw, /* draw */ click, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ NULL, /* mouse_move */ MwForceRender2, /* mouse_up */ MwForceRender2, /* mouse_down */ diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 6c6bef6..bba20f6 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -319,7 +319,7 @@ static int create(MwWidget handle) { MwSetInteger(handle, MwNsingleClickSelectable, 0); MwSetInteger(handle, MwNhasHeading, 0); - MwSetInteger(handle, MwNhasHeading, 0); + MwSetInteger(handle, MwNvalue, 0); resize(handle); lb->list = NULL;