forked from pyrite-dev/milsko
wip rewrite listbox
This commit is contained in:
parent
10fda7bfc4
commit
a666010564
7 changed files with 67 additions and 228 deletions
|
|
@ -23,12 +23,11 @@ void activate(MwWidget handle, void* user, void* call) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
MwWidget lb;
|
||||
int len = sizeof(harvard) / sizeof(harvard[0]) - 1;
|
||||
int i;
|
||||
MwListBoxPacket* packet;
|
||||
int index;
|
||||
MwLLPixmap px;
|
||||
MwWidget lb;
|
||||
int len = sizeof(harvard) / sizeof(harvard[0]) - 1;
|
||||
int i;
|
||||
int index;
|
||||
MwLLPixmap px;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
|
|
@ -41,18 +40,15 @@ int main() {
|
|||
|
||||
MwSetInteger(lb, MwNleftPadding, 20);
|
||||
|
||||
packet = MwListBoxCreatePacket();
|
||||
index = MwListBoxPacketInsert(packet, -1);
|
||||
MwListBoxPacketSet(packet, index, 0, "Harvard sentence");
|
||||
MwListBoxPacketSet(packet, index, 1, "Length");
|
||||
index = MwListBoxInsert(lb, -1, 0, "Harvard sentence");
|
||||
MwListBoxInsert(lb, index, -1, "Length");
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
char sz[16];
|
||||
MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
|
||||
index = MwListBoxPacketInsert(packet, -1);
|
||||
MwListBoxPacketSetIcon(packet, index, px);
|
||||
MwListBoxPacketSet(packet, index, 0, harvard[i]);
|
||||
MwListBoxPacketSet(packet, index, 1, sz);
|
||||
index = MwListBoxInsert(lb, -1, 0, harvard[i]);
|
||||
MwListBoxInsert(lb, index, -1, sz);
|
||||
MwListBoxSetIcon(lb, index, px);
|
||||
}
|
||||
|
||||
MwAddUserHandler(lb, MwNactivateHandler, activate, NULL);
|
||||
|
|
@ -60,9 +56,6 @@ int main() {
|
|||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
MwListBoxSetWidth(lb, 0, -128);
|
||||
MwListBoxInsert(lb, -1, packet);
|
||||
|
||||
MwListBoxDestroyPacket(packet);
|
||||
|
||||
MwLoop(wmain);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,12 +145,11 @@ static void menu_handler(MwWidget handle, void* user, void* call) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
MwWidget f, w;
|
||||
MwListBoxPacket* pkt;
|
||||
int index;
|
||||
MwMenu m, m2;
|
||||
void* v;
|
||||
int i;
|
||||
MwWidget f, w;
|
||||
int index;
|
||||
MwMenu m, m2;
|
||||
void* v;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
|
|
@ -242,13 +241,8 @@ int main() {
|
|||
MwNhasHeading, 1,
|
||||
NULL);
|
||||
w = child(f);
|
||||
pkt = MwListBoxCreatePacket();
|
||||
index = MwListBoxPacketInsert(pkt, -1);
|
||||
MwListBoxPacketSet(pkt, index, 0, "Epic title...");
|
||||
index = MwListBoxPacketInsert(pkt, -1);
|
||||
MwListBoxPacketSet(pkt, index, 0, "Hello");
|
||||
MwListBoxInsert(w, -1, pkt);
|
||||
MwListBoxDestroyPacket(pkt);
|
||||
index = MwListBoxInsert(w, -1, 0, "Epic title...");
|
||||
index = MwListBoxInsert(w, -1, 0, "Hello");
|
||||
add(f);
|
||||
|
||||
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
|
||||
|
|
|
|||
|
|
@ -19,50 +19,29 @@ extern "C" {
|
|||
MWDECL MwClass MwListBoxClass;
|
||||
|
||||
/*!
|
||||
* @brief Creates a listbox packet
|
||||
* @return Packet
|
||||
*/
|
||||
MWDECL MwListBoxPacket* MwListBoxCreatePacket(void);
|
||||
|
||||
/*!
|
||||
* @brief Destroys a listbox packet
|
||||
* @param packet Packet
|
||||
*/
|
||||
MWDECL void MwListBoxDestroyPacket(MwListBoxPacket* packet);
|
||||
|
||||
/*!
|
||||
* @brief Inserts a new item to a packet
|
||||
* @param packet Packet
|
||||
* @param index Index
|
||||
* @return Index
|
||||
*/
|
||||
MWDECL int MwListBoxPacketInsert(MwListBoxPacket* packet, int index);
|
||||
|
||||
/*!
|
||||
* @brief Sets a column of item in a packet
|
||||
* @param packet Packet
|
||||
* @param index Index
|
||||
* @brief Inserts item on the listbox
|
||||
* @param handle Widget
|
||||
* @param row Row
|
||||
* @param col Column
|
||||
* @param text Text
|
||||
* @return Index
|
||||
*/
|
||||
MWDECL void MwListBoxPacketSet(MwListBoxPacket* packet, int index, int col, const char* text);
|
||||
MwInline int MwListBoxInsert(MwWidget handle, int row, int col, const char* text) {
|
||||
int out;
|
||||
|
||||
MwVaWidgetExecute(handle, "mwListBoxInsert", (void*)&out, row, col, text);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets an icon of item in a packet
|
||||
* @param packet Packet
|
||||
* @brief Sets the icon of the row
|
||||
* @param handle Widget
|
||||
* @param index Index
|
||||
* @param icon Icon
|
||||
*/
|
||||
MWDECL void MwListBoxPacketSetIcon(MwListBoxPacket* packet, int index, MwLLPixmap icon);
|
||||
|
||||
/*!
|
||||
* @brief Inserts item on the listbox
|
||||
* @param handle Widget
|
||||
* @param index Index
|
||||
* @param packet Packet
|
||||
*/
|
||||
MwInline void MwListBoxInsert(MwWidget handle, int index, void* packet) {
|
||||
MwVaWidgetExecute(handle, "mwListBoxInsert", NULL, index, packet);
|
||||
MwInline void MwListBoxSetIcon(MwWidget handle, int index, MwLLPixmap icon) {
|
||||
MwVaWidgetExecute(handle, "mwListBoxSetIcon", NULL, index, icon);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
47
milsko.xml
47
milsko.xml
|
|
@ -549,44 +549,6 @@
|
|||
</function>
|
||||
</functions>
|
||||
</header>
|
||||
<header name="Widget/ListBox">
|
||||
<functions>
|
||||
<function name="MwListBoxCreatePacket">
|
||||
<return>
|
||||
<pointer />
|
||||
</return>
|
||||
</function>
|
||||
<function name="MwListBoxDestroyPacket">
|
||||
<arguments>
|
||||
<pointer name="packet" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="MwListBoxPacketInsert">
|
||||
<return>
|
||||
<integer />
|
||||
</return>
|
||||
<arguments>
|
||||
<pointer name="packet" />
|
||||
<integer name="index" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="MwListBoxPacketSet">
|
||||
<arguments>
|
||||
<pointer name="packet" />
|
||||
<integer name="index" />
|
||||
<integer name="col" />
|
||||
<string name="text" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="MwListBoxPacketSetIcon">
|
||||
<arguments>
|
||||
<pointer name="packet" />
|
||||
<integer name="index" />
|
||||
<pixmap name="icon" />
|
||||
</arguments>
|
||||
</function>
|
||||
</functions>
|
||||
</header>
|
||||
|
||||
<!-- They are not alphabetically sorted for reasons -->
|
||||
<header name="Widget/Vulkan">
|
||||
|
|
@ -688,9 +650,16 @@
|
|||
</handlers>
|
||||
<functions>
|
||||
<function name="Insert">
|
||||
<arguments>
|
||||
<integer name="row" />
|
||||
<integer name="col" />
|
||||
<string name="text" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="SetIcon">
|
||||
<arguments>
|
||||
<integer name="index" />
|
||||
<pointer name="packet" />
|
||||
<pixmap name="icon" />
|
||||
</arguments>
|
||||
</function>
|
||||
<function name="Delete">
|
||||
|
|
|
|||
|
|
@ -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