listbox rewrite done
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit

This commit is contained in:
Nishi 2026-04-18 19:40:28 +09:00
commit 55c562645a
Signed by: nishi
GPG key ID: 27EF69B208EB9343
6 changed files with 77 additions and 32 deletions

View file

@ -40,18 +40,18 @@ int main() {
MwSetInteger(lb, MwNleftPadding, 20);
index = MwListBoxInsert(lb, -1, 0, "Harvard sentence");
MwListBoxInsert(lb, index, -1, "Length");
index = MwListBoxSet(lb, -1, 0, "Harvard sentence");
MwListBoxSet(lb, index, -1, "Length");
for(i = 0; i < len; i++) {
char sz[16];
MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
index = MwListBoxInsert(lb, -1, 0, harvard[i]);
MwListBoxInsert(lb, index, -1, sz);
index = MwListBoxSet(lb, -1, 0, harvard[i]);
MwListBoxSet(lb, index, -1, sz);
MwListBoxSetIcon(lb, index, px);
}
MwAddUserHandler(lb, MwNactivateHandler, activate, NULL);
MwAddUserHandler(lb, MwNlistBoxActivateHandler, activate, NULL);
MwVaApply(lb,
MwNhasHeading, 1,
NULL);

View file

@ -26,7 +26,6 @@ typedef struct _MwLabelSegment MwLabelSegment;
typedef struct _MwListBoxEntry MwListBoxEntry;
typedef struct _MwTreeViewEntry MwTreeViewEntry;
typedef struct _MwDirectoryEntry MwDirectoryEntry;
typedef struct _MwListBoxPacket MwListBoxPacket;
typedef struct _MwBox* MwBox;
typedef struct _MwMouse MwMouse;
#ifdef _MILSKO
@ -202,11 +201,6 @@ struct _MwDirectoryEntry {
time_t mtime;
};
struct _MwListBoxPacket {
MwLLPixmap* pixmaps;
char*** names;
};
struct _MwBox {
int layout;
};

View file

@ -26,10 +26,10 @@ MWDECL MwClass MwListBoxClass;
* @param text Text
* @return Index
*/
MwInline int MwListBoxInsert(MwWidget handle, int row, int col, const char* text) {
MwInline int MwListBoxSet(MwWidget handle, int row, int col, const char* text) {
int out;
MwVaWidgetExecute(handle, "mwListBoxInsert", (void*)&out, row, col, text);
MwVaWidgetExecute(handle, "mwListBoxSet", (void*)&out, row, col, text);
return out;
}

View file

@ -216,7 +216,7 @@ static void layout(MwWidget handle) {
MwNleftPadding, 16,
NULL);
index = MwListBoxInsert(fc->nav, -1, 0, "Home");
index = MwListBoxSet(fc->nav, -1, 0, "Home");
MwListBoxSetIcon(fc->nav, index, fc->computer);
MwAddUserHandler(fc->nav, MwNlistBoxActivateHandler, nav_activate, NULL);
@ -462,9 +462,9 @@ static void scan(MwWidget handle, const char* path, int record) {
MwListBoxSetWidth(fc->files, 1, 128);
MwListBoxSetWidth(fc->files, 2, 0);
index = MwListBoxInsert(fc->files, -1, 0, "Name");
MwListBoxInsert(fc->files, index, -1, "Date modified");
MwListBoxInsert(fc->files, index, -1, "Size");
index = MwListBoxSet(fc->files, -1, 0, "Name");
MwListBoxSet(fc->files, index, -1, "Date modified");
MwListBoxSet(fc->files, index, -1, "Size");
for(i = 0; i < arrlen(fc->entries); i++) {
if(strcmp(fc->entries[i]->name, ".") == 0 || strcmp(fc->entries[i]->name, "..") == 0) continue;
@ -473,9 +473,9 @@ static void scan(MwWidget handle, const char* path, int record) {
MwStringTime(date, fc->entries[i]->mtime);
index = MwListBoxInsert(fc->files, -1, 0, fc->entries[i]->name);
MwListBoxInsert(fc->files, index, -1, date);
MwListBoxInsert(fc->files, index, -1, NULL);
index = MwListBoxSet(fc->files, -1, 0, fc->entries[i]->name);
MwListBoxSet(fc->files, index, -1, date);
MwListBoxSet(fc->files, index, -1, NULL);
MwListBoxSetIcon(fc->files, index, fc->dir);
arrput(fc->sorted_entries, fc->entries[i]);
@ -489,9 +489,9 @@ static void scan(MwWidget handle, const char* path, int record) {
MwStringTime(date, fc->entries[i]->mtime);
MwStringSize(size, fc->entries[i]->size);
index = MwListBoxInsert(fc->files, -1, 0, fc->entries[i]->name);
MwListBoxInsert(fc->files, index, -1, date);
MwListBoxInsert(fc->files, index, -1, size);
index = MwListBoxSet(fc->files, -1, 0, fc->entries[i]->name);
MwListBoxSet(fc->files, index, -1, date);
MwListBoxSet(fc->files, index, -1, size);
MwListBoxSetIcon(fc->files, index, fc->file);
arrput(fc->sorted_entries, fc->entries[i]);

View file

@ -125,7 +125,7 @@ static void click(MwWidget handle) {
MwLLSetCursor(((MwListBox)cb->listbox->internal)->frame->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
for(i = 0; i < arrlen(cb->list); i++) {
MwListBoxInsert(cb->listbox, -1, 0, cb->list[i]);
MwListBoxSet(cb->listbox, -1, 0, cb->list[i]);
}
MwAddUserHandler(cb->listbox, MwNlistBoxActivateHandler, listbox_activate, NULL);

View file

@ -387,18 +387,64 @@ static void prop_change(MwWidget handle, const char* prop) {
}
}
static void mwListBoxInsertImpl(MwWidget handle, int row, int col, const char* text) {
static void redrawIfNeeded(MwWidget handle, int row) {
MwListBox lb = handle->internal;
int old;
if(row == -1) row = arrlen(lb->list);
old = row;
resize(handle);
if(old < (MwGetInteger(lb->vscroll, MwNvalue) + MwGetInteger(lb->vscroll, MwNareaShown))) {
if(MwGetInteger(lb->vscroll, MwNvalue) <= row && row <= (MwGetInteger(lb->vscroll, MwNvalue) + MwGetInteger(lb->vscroll, MwNareaShown))) {
MwForceRender(lb->frame);
}
}
static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text) {
MwListBox lb = handle->internal;
MwListBoxEntry entry;
char* t = text == NULL ? NULL : MwStringDuplicate(text);
if(row == -1) row = arrlen(lb->list);
entry.name = NULL;
entry.pixmap = NULL;
if(row < arrlen(lb->list)) {
entry = lb->list[row];
}
if(col == -1) col = arrlen(entry.name);
arrins(entry.name, col, t);
if(row < arrlen(lb->list)) {
lb->list[row] = entry;
} else {
arrins(lb->list, row, entry);
}
if(row >= arrlen(lb->list)) resize(handle);
redrawIfNeeded(handle, row);
return row;
}
static void mwListBoxSetIconImpl(MwWidget handle, int index, MwLLPixmap icon) {
MwListBox lb = handle->internal;
MwListBoxEntry entry;
if(index == -1) index = arrlen(lb->list);
entry.name = NULL;
entry.pixmap = NULL;
if(index < arrlen(lb->list)) {
entry = lb->list[index];
}
entry.pixmap = icon;
if(index < arrlen(lb->list)) {
lb->list[index] = entry;
} else {
arrins(lb->list, index, entry);
}
if(index >= arrlen(lb->list)) resize(handle);
redrawIfNeeded(handle, index);
}
static void mwListBoxDeleteImpl(MwWidget handle, int index) {
MwListBox lb = handle->internal;
int i;
@ -496,11 +542,16 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
int alignment = va_arg(va, int);
mwListBoxSetAlignmentImpl(handle, index, alignment);
}
if(strcmp(name, "mwListBoxInsert") == 0) {
if(strcmp(name, "mwListBoxSet") == 0) {
int row = va_arg(va, int);
int col = va_arg(va, int);
const char* text = va_arg(va, const char*);
mwListBoxInsertImpl(handle, row, col, text);
*(int*)out = mwListBoxSetImpl(handle, row, col, text);
}
if(strcmp(name, "mwListBoxSetIcon") == 0) {
int index = va_arg(va, int);
MwLLPixmap icon = va_arg(va, MwLLPixmap);
mwListBoxSetIconImpl(handle, index, icon);
}
}