wip rewrite listbox
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
10fda7bfc4
commit
a666010564
7 changed files with 67 additions and 228 deletions
|
|
@ -210,20 +210,16 @@ static void layout(MwWidget handle) {
|
|||
ww = 160;
|
||||
wh = h - 10 - 24 - 5 - 24 - 5 - 24 - 5;
|
||||
if(fc->nav == NULL) {
|
||||
MwListBoxPacket* p = MwListBoxCreatePacket();
|
||||
int index;
|
||||
|
||||
index = MwListBoxPacketInsert(p, -1);
|
||||
MwListBoxPacketSet(p, index, 0, "Home");
|
||||
MwListBoxPacketSetIcon(p, index, fc->computer);
|
||||
int index;
|
||||
|
||||
fc->nav = MwVaCreateWidget(MwListBoxClass, "nav", handle, wx, wy, ww, wh,
|
||||
MwNleftPadding, 16,
|
||||
NULL);
|
||||
MwListBoxInsert(fc->nav, -1, p);
|
||||
MwAddUserHandler(fc->nav, MwNlistBoxActivateHandler, nav_activate, NULL);
|
||||
|
||||
MwListBoxDestroyPacket(p);
|
||||
index = MwListBoxInsert(fc->nav, -1, 0, "Home");
|
||||
MwListBoxSetIcon(fc->nav, index, fc->computer);
|
||||
|
||||
MwAddUserHandler(fc->nav, MwNlistBoxActivateHandler, nav_activate, NULL);
|
||||
} else {
|
||||
MwVaApply(fc->nav,
|
||||
MwNx, wx,
|
||||
|
|
@ -409,11 +405,10 @@ static int qsort_files(const void* a, const void* b) {
|
|||
}
|
||||
|
||||
static void scan(MwWidget handle, const char* path, int record) {
|
||||
filechooser_t* fc = handle->opaque;
|
||||
void* dir = MwDirectoryOpen(path);
|
||||
int i;
|
||||
MwListBoxPacket* p = MwListBoxCreatePacket();
|
||||
int index;
|
||||
filechooser_t* fc = handle->opaque;
|
||||
void* dir = MwDirectoryOpen(path);
|
||||
int i;
|
||||
int index;
|
||||
|
||||
if(dir != NULL) {
|
||||
MwDirectoryEntry* entry;
|
||||
|
|
@ -467,10 +462,9 @@ static void scan(MwWidget handle, const char* path, int record) {
|
|||
MwListBoxSetWidth(fc->files, 1, 128);
|
||||
MwListBoxSetWidth(fc->files, 2, 0);
|
||||
|
||||
index = MwListBoxPacketInsert(p, -1);
|
||||
MwListBoxPacketSet(p, index, -1, "Name");
|
||||
MwListBoxPacketSet(p, index, -1, "Date modified");
|
||||
MwListBoxPacketSet(p, index, -1, "Size");
|
||||
index = MwListBoxInsert(fc->files, -1, 0, "Name");
|
||||
MwListBoxInsert(fc->files, index, -1, "Date modified");
|
||||
MwListBoxInsert(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;
|
||||
|
|
@ -479,11 +473,10 @@ static void scan(MwWidget handle, const char* path, int record) {
|
|||
|
||||
MwStringTime(date, fc->entries[i]->mtime);
|
||||
|
||||
index = MwListBoxPacketInsert(p, -1);
|
||||
MwListBoxPacketSetIcon(p, index, fc->dir);
|
||||
MwListBoxPacketSet(p, index, -1, fc->entries[i]->name);
|
||||
MwListBoxPacketSet(p, index, -1, date);
|
||||
MwListBoxPacketSet(p, index, -1, NULL);
|
||||
index = MwListBoxInsert(fc->files, -1, 0, fc->entries[i]->name);
|
||||
MwListBoxInsert(fc->files, index, -1, date);
|
||||
MwListBoxInsert(fc->files, index, -1, NULL);
|
||||
MwListBoxSetIcon(fc->files, index, fc->dir);
|
||||
|
||||
arrput(fc->sorted_entries, fc->entries[i]);
|
||||
}
|
||||
|
|
@ -496,17 +489,14 @@ static void scan(MwWidget handle, const char* path, int record) {
|
|||
MwStringTime(date, fc->entries[i]->mtime);
|
||||
MwStringSize(size, fc->entries[i]->size);
|
||||
|
||||
index = MwListBoxPacketInsert(p, -1);
|
||||
MwListBoxPacketSetIcon(p, index, fc->file);
|
||||
MwListBoxPacketSet(p, index, -1, fc->entries[i]->name);
|
||||
MwListBoxPacketSet(p, index, -1, date);
|
||||
MwListBoxPacketSet(p, index, -1, size);
|
||||
index = MwListBoxInsert(fc->files, -1, 0, fc->entries[i]->name);
|
||||
MwListBoxInsert(fc->files, index, -1, date);
|
||||
MwListBoxInsert(fc->files, index, -1, size);
|
||||
MwListBoxSetIcon(fc->files, index, fc->file);
|
||||
|
||||
arrput(fc->sorted_entries, fc->entries[i]);
|
||||
}
|
||||
}
|
||||
MwListBoxInsert(fc->files, -1, p);
|
||||
MwListBoxDestroyPacket(p);
|
||||
}
|
||||
|
||||
MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
|
||||
|
|
|
|||
|
|
@ -101,7 +101,6 @@ static void click(MwWidget handle) {
|
|||
if(cb->opened) {
|
||||
MwPoint p;
|
||||
int i;
|
||||
void* packet;
|
||||
int width = MwGetInteger(handle, MwNwidth);
|
||||
int ent = MwGetInteger(handle, MwNareaShown);
|
||||
|
||||
|
|
@ -125,13 +124,9 @@ static void click(MwWidget handle) {
|
|||
|
||||
MwLLSetCursor(((MwListBox)cb->listbox->internal)->frame->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
|
||||
|
||||
packet = MwListBoxCreatePacket();
|
||||
for(i = 0; i < arrlen(cb->list); i++) {
|
||||
int index = MwListBoxPacketInsert(packet, -1);
|
||||
MwListBoxPacketSet(packet, index, 0, cb->list[i]);
|
||||
MwListBoxInsert(cb->listbox, -1, 0, cb->list[i]);
|
||||
}
|
||||
MwListBoxInsert(cb->listbox, -1, packet);
|
||||
MwListBoxDestroyPacket(packet);
|
||||
|
||||
MwAddUserHandler(cb->listbox, MwNlistBoxActivateHandler, listbox_activate, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,61 +6,6 @@
|
|||
|
||||
#define Font MwFLBuildFont(MwFLFlagMonospace)
|
||||
|
||||
MwListBoxPacket* MwListBoxCreatePacket(void) {
|
||||
MwListBoxPacket* packet = malloc(sizeof(*packet));
|
||||
memset(packet, 0, sizeof(*packet));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
void MwListBoxDestroyPacket(MwListBoxPacket* packet) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for(i = 0; i < arrlen(packet->names); i++) {
|
||||
for(j = 0; j < arrlen(packet->names[i]); j++) {
|
||||
if(packet->names[i][j] != NULL) free(packet->names[i][j]);
|
||||
}
|
||||
arrfree(packet->names[i]);
|
||||
}
|
||||
|
||||
arrfree(packet->names);
|
||||
arrfree(packet->pixmaps);
|
||||
|
||||
free(packet);
|
||||
}
|
||||
|
||||
int MwListBoxPacketInsert(MwListBoxPacket* packet, int index) {
|
||||
int i;
|
||||
|
||||
if(index == -1) index = arrlen(packet->names);
|
||||
for(i = arrlen(packet->names); i < index; i++) {
|
||||
arrput(packet->names, NULL);
|
||||
arrput(packet->pixmaps, NULL);
|
||||
}
|
||||
|
||||
arrins(packet->names, index, NULL);
|
||||
arrins(packet->pixmaps, index, NULL);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void MwListBoxPacketSet(MwListBoxPacket* packet, int index, int col, const char* text) {
|
||||
char* t = text == NULL ? NULL : MwStringDuplicate(text);
|
||||
int i;
|
||||
|
||||
if(col == -1) col = arrlen(packet->names[index]);
|
||||
for(i = arrlen(packet->names[index]); i < col; i++) {
|
||||
arrput(packet->names[index], NULL);
|
||||
}
|
||||
|
||||
arrins(packet->names[index], col, t);
|
||||
}
|
||||
|
||||
void MwListBoxPacketSetIcon(MwListBoxPacket* packet, int index, MwLLPixmap icon) {
|
||||
packet->pixmaps[index] = icon;
|
||||
}
|
||||
|
||||
static int get_first_entry(MwWidget handle, MwListBox lb) {
|
||||
int st = 0;
|
||||
int y = MwGetInteger(handle, MwNhasHeading) ? 1 : 0;
|
||||
|
|
@ -442,38 +387,11 @@ static void prop_change(MwWidget handle, const char* prop) {
|
|||
}
|
||||
}
|
||||
|
||||
static void mwListBoxInsertImpl(MwWidget handle, int index, MwListBoxPacket* packet) {
|
||||
int i;
|
||||
static void mwListBoxInsertImpl(MwWidget handle, int row, int col, const char* text) {
|
||||
MwListBox lb = handle->internal;
|
||||
int old;
|
||||
int max = 0;
|
||||
if(index == -1) index = arrlen(lb->list);
|
||||
old = index;
|
||||
|
||||
for(i = 0; i < arrlen(packet->names); i++) {
|
||||
if(arrlen(packet->names[i]) > max) max = arrlen(packet->names[i]);
|
||||
}
|
||||
|
||||
for(i = 0; i < arrlen(packet->names); i++) {
|
||||
MwListBoxEntry entry;
|
||||
char* name;
|
||||
int j;
|
||||
|
||||
entry.name = NULL;
|
||||
for(j = 0; j < max; j++) {
|
||||
if(arrlen(packet->names[i]) > j && packet->names[i][j] != NULL) {
|
||||
name = MwStringDuplicate(packet->names[i][j]);
|
||||
arrput(entry.name, name);
|
||||
} else {
|
||||
arrput(entry.name, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
entry.pixmap = packet->pixmaps[i];
|
||||
|
||||
arrins(lb->list, index, entry);
|
||||
index++;
|
||||
}
|
||||
if(row == -1) row = arrlen(lb->list);
|
||||
old = row;
|
||||
|
||||
resize(handle);
|
||||
if(old < (MwGetInteger(lb->vscroll, MwNvalue) + MwGetInteger(lb->vscroll, MwNareaShown))) {
|
||||
|
|
@ -579,9 +497,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
|
|||
mwListBoxSetAlignmentImpl(handle, index, alignment);
|
||||
}
|
||||
if(strcmp(name, "mwListBoxInsert") == 0) {
|
||||
int index = va_arg(va, int);
|
||||
MwListBoxPacket* packet = va_arg(va, MwListBoxPacket*);
|
||||
mwListBoxInsertImpl(handle, index, packet);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue