diff --git a/examples/basic/listbox.c b/examples/basic/listbox.c
index 3f63ad1..ce7e9ac 100644
--- a/examples/basic/listbox.c
+++ b/examples/basic/listbox.c
@@ -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);
}
diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c
index 593e766..c6043f2 100644
--- a/examples/basic/periodic.c
+++ b/examples/basic/periodic.c
@@ -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);
diff --git a/include/Mw/Widget/ListBox.h b/include/Mw/Widget/ListBox.h
index 1c5c609..ae07068 100644
--- a/include/Mw/Widget/ListBox.h
+++ b/include/Mw/Widget/ListBox.h
@@ -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);
}
/*!
diff --git a/milsko.xml b/milsko.xml
index 690e237..37d3fe5 100644
--- a/milsko.xml
+++ b/milsko.xml
@@ -549,44 +549,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -688,9 +650,16 @@
+
+
+
+
+
+
+
-
+
diff --git a/src/dialog/filechooser.c b/src/dialog/filechooser.c
index ff1683c..42fbf08 100644
--- a/src/dialog/filechooser.c
+++ b/src/dialog/filechooser.c
@@ -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) {
diff --git a/src/widget/combobox.c b/src/widget/combobox.c
index b913878..f553444 100644
--- a/src/widget/combobox.c
+++ b/src/widget/combobox.c
@@ -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);
diff --git a/src/widget/listbox.c b/src/widget/listbox.c
index 6f2a9db..31fd00f 100644
--- a/src/widget/listbox.c
+++ b/src/widget/listbox.c
@@ -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);
}
}