diff --git a/include/Mw/String.h b/include/Mw/String.h index 5987fad..6fe8b67 100644 --- a/include/Mw/String.h +++ b/include/Mw/String.h @@ -18,7 +18,7 @@ extern "C" { * @param str String * @return String */ -MWDECL char* MwStringDupliacte(const char* str); +MWDECL char* MwStringDuplicate(const char* str); /*! * @brief Concatenates 2 strings diff --git a/include/Mw/Widget/ListBox.h b/include/Mw/Widget/ListBox.h index 66e7398..93e21bf 100644 --- a/include/Mw/Widget/ListBox.h +++ b/include/Mw/Widget/ListBox.h @@ -72,7 +72,7 @@ MwInline void MwListBoxInsert(MwWidget handle, int index, void* packet) { * @param index Index */ MwInline void MwListBoxDelete(MwWidget handle, int index) { - MwVaWidgetExecute(handle, "mwListboxDelete", NULL, index); + MwVaWidgetExecute(handle, "mwListBoxDelete", NULL, index); } /*! diff --git a/include/Mw/Widget/TreeView.h b/include/Mw/Widget/TreeView.h index 77073f6..8dd3a46 100644 --- a/include/Mw/Widget/TreeView.h +++ b/include/Mw/Widget/TreeView.h @@ -19,6 +19,36 @@ extern "C" { */ MWDECL MwClass MwTreeViewClass; +/*! + * @brief Adds item to the treeview + * @param handle Widget + * @parma parent Parent + * @parma pixmap Pixmap + * @param item Item + */ +MwInline void* MwTreeViewAdd(MwWidget handle, void* parent, MwLLPixmap pixmap, const char* item) { + void* out; + MwVaWidgetExecute(handle, "mwTreeViewAdd", &out, parent, pixmap, item); + return out; +} + +/*! + * @brief Deletes item from the treeview + * @param handle Widget + * @param item Item + */ +MwInline void MwTreeViewDelete(MwWidget handle, void* item) { + MwVaWidgetExecute(handle, "mwTreeViewDelete", NULL, item); +} + +/*! + * @brief Resets the treeview + * @param handle Widget + */ +MwInline void MwTreeViewReset(MwWidget handle) { + MwVaWidgetExecute(handle, "mwTreeViewReset", NULL); +} + #ifdef __cplusplus } #endif diff --git a/src/abstract/directory.c b/src/abstract/directory.c index 119b42f..16376fb 100644 --- a/src/abstract/directory.c +++ b/src/abstract/directory.c @@ -60,7 +60,7 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) { free(entry); return NULL; } - entry->name = MwStringDupliacte(dir->ffd.cFileName); + entry->name = MwStringDuplicate(dir->ffd.cFileName); if(dir->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { entry->type = MwDIRECTORY_DIRECTORY; @@ -81,7 +81,7 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) { free(entry); return NULL; } - entry->name = MwStringDupliacte(d->d_name); + entry->name = MwStringDuplicate(d->d_name); p = malloc(strlen(dir->base) + 1 + strlen(d->d_name) + 1); strcpy(p, dir->base); @@ -174,7 +174,7 @@ static void MwDirectoryJoinSingle(char* target, char* p) { char* MwDirectoryJoin(char* a, char* b) { char* p = malloc(strlen(a) + 1 + strlen(b) + 1); - char* bdup = MwStringDupliacte(b); + char* bdup = MwStringDuplicate(b); char* b2 = bdup; int i; diff --git a/src/backend/x11.c b/src/backend/x11.c index abac619..fba2d1e 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -943,7 +943,7 @@ static char* MwLLGetClipboardImpl(MwLL handle) { XGetWindowProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property, 0, (~0L), 0, AnyPropertyType, &t, &format, &size, &N, (unsigned char**)&data); if(t == target) { - r = MwStringDupliacte(data); + r = MwStringDuplicate(data); XFree(data); } XDeleteProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property); diff --git a/src/core.c b/src/core.c index 367fef2..ff7cd35 100644 --- a/src/core.c +++ b/src/core.c @@ -106,7 +106,7 @@ static void llfocusouthandler(MwLL handle, void* data) { MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) { MwWidget h = malloc(sizeof(*h)); - h->name = MwStringDupliacte(name); + h->name = MwStringDuplicate(name); h->parent = parent; h->children = NULL; @@ -361,7 +361,7 @@ void MwSetText(MwWidget handle, const char* key, const char* value) { if(strcmp(key, MwNtitle) == 0) { MwLLSetTitle(handle->lowlevel, value); } else { - char* v = MwStringDupliacte(value); + char* v = MwStringDuplicate(value); if(shgeti(handle->text, key) != -1) free(shget(handle->text, key)); diff --git a/src/dialog/filechooser.c b/src/dialog/filechooser.c index 33f35d7..b0eda3d 100644 --- a/src/dialog/filechooser.c +++ b/src/dialog/filechooser.c @@ -385,7 +385,7 @@ static void scan(MwWidget handle, const char* path, int record) { qsort(fc->entries, arrlen(fc->entries), sizeof(MwDirectoryEntry*), qsort_files); if(record) { - char* str = MwStringDupliacte(path); + char* str = MwStringDuplicate(path); while(arrlen(fc->history) > fc->history_seek) { free(fc->history[fc->history_seek]); @@ -403,7 +403,7 @@ static void scan(MwWidget handle, const char* path, int record) { } if(fc->path != NULL) free(fc->path); - fc->path = MwStringDupliacte(path); + fc->path = MwStringDuplicate(path); MwVaApply(fc->addr, MwNtext, path, diff --git a/src/string.c b/src/string.c index 0b21ba1..7835d50 100644 --- a/src/string.c +++ b/src/string.c @@ -1,7 +1,7 @@ /* $Id$ */ #include -char* MwStringDupliacte(const char* str) { +char* MwStringDuplicate(const char* str) { char* r = malloc(strlen(str) + 1); strcpy(r, str); diff --git a/src/widget/combobox.c b/src/widget/combobox.c index 56573c3..49dfba1 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -162,7 +162,7 @@ static void prop_change(MwWidget handle, const char* prop) { static void mwComboBoxAddImpl(MwWidget handle, int index, const char* text) { MwComboBox cb = handle->internal; - char* t = MwStringDupliacte(text); + char* t = MwStringDuplicate(text); if(index == -1) index = arrlen(cb->list); diff --git a/src/widget/listbox.c b/src/widget/listbox.c index abd1cb1..5c61e52 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -43,7 +43,7 @@ int MwListBoxPacketInsert(MwListBoxPacket* packet, int index) { } void MwListBoxPacketSet(MwListBoxPacket* packet, int index, int col, const char* text) { - char* t = text == NULL ? NULL : MwStringDupliacte(text); + char* t = text == NULL ? NULL : MwStringDuplicate(text); int i; if(col == -1) col = arrlen(packet->names[index]); @@ -410,7 +410,7 @@ static void mwListBoxInsertImpl(MwWidget handle, int index, MwListBoxPacket* pac entry.name = NULL; for(j = 0; j < max; j++) { if(arrlen(packet->names[i]) > j && packet->names[i][j] != NULL) { - name = MwStringDupliacte(packet->names[i][j]); + name = MwStringDuplicate(packet->names[i][j]); arrput(entry.name, name); } else { arrput(entry.name, NULL); @@ -494,8 +494,6 @@ static void mwListBoxSetWidthImpl(MwWidget handle, int index, int width) { } static void func_handler(MwWidget handle, const char* name, void* out, va_list va) { - (void)out; - if(strcmp(name, "mwListBoxDelete") == 0) { int index = va_arg(va, int); mwListBoxDeleteImpl(handle, index); diff --git a/src/widget/menu.c b/src/widget/menu.c index 1842690..62fbafc 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -179,7 +179,7 @@ static void mouse_up(MwWidget handle, void* ptr) { static MwMenu mwMenuAddImpl(MwWidget handle, MwMenu menu, const char* name) { MwMenu m = menu == NULL ? handle->internal : menu; MwMenu new = malloc(sizeof(*new)); - new->name = MwStringDupliacte(name); + new->name = MwStringDuplicate(name); new->sub = NULL; new->wsub = NULL; new->keep = 0; diff --git a/src/widget/treeview.c b/src/widget/treeview.c index 024820e..656180c 100644 --- a/src/widget/treeview.c +++ b/src/widget/treeview.c @@ -282,37 +282,12 @@ static void resize(MwWidget handle) { static int create(MwWidget handle) { MwTreeView tv = malloc(sizeof(*tv)); - MwTreeViewEntry e, e2, e3; memset(tv, 0, sizeof(*tv)); handle->internal = tv; MwSetDefault(handle); - e3.label = MwStringDupliacte("hello"); - e3.pixmap = NULL; - e3.tree = NULL; - e3.opened = 1; - e3.selected = 0; - e3.click_time = 0; - - e2.label = MwStringDupliacte("hello"); - e2.pixmap = NULL; - e2.tree = NULL; - e2.opened = 1; - e2.selected = 0; - e2.click_time = 0; - arrput(e2.tree, e3); - - e.label = MwStringDupliacte("hello"); - e.pixmap = NULL; - e.tree = NULL; - e.opened = 1; - e.selected = 0; - e.click_time = 0; - arrput(e.tree, e2); - arrput(tv->tree, e); - MwSetInteger(handle, MwNsingleClickSelectable, 0); MwSetInteger(handle, MwNleftPadding, 0); @@ -343,6 +318,44 @@ static void prop_change(MwWidget handle, const char* prop) { if(strcmp(prop, MwNwidth) == 0 || strcmp(prop, MwNheight) == 0) resize(handle); } +static void* mwTreeViewAddImpl(MwWidget handle, void* parent, MwLLPixmap pixmap, const char* item){ + MwTreeView tv = handle->internal; + MwTreeViewEntry t; + + t.label = MwStringDuplicate(item); + t.pixmap = pixmap; + t.selected = 0; + t.opened = 1; + t.click_time = 0; + + if(parent == NULL){ + arrput(tv->tree, t); + } + resize(handle); +} + +static void mwTreeViewDeleteImpl(MwWidget handle, void* item){ +} + +static void mwTreeViewResetImpl(MwWidget handle){ +} + +static void func_handler(MwWidget handle, const char* name, void* out, va_list va) { + if(strcmp(name, "mwTreeViewAdd") == 0){ + void* parent = va_arg(va, void*); + MwLLPixmap pixmap = va_arg(va, MwLLPixmap); + const char* item = va_arg(va, const char*); + *(void**)out = mwTreeViewAddImpl(handle, parent, pixmap, item); + } + if(strcmp(name, "mwTreeViewDelete") == 0){ + void* item = va_arg(va, void*); + mwTreeViewDeleteImpl(handle, item); + } + if(strcmp(name, "mwTreeViewReset") == 0){ + mwTreeViewResetImpl(handle); + } +} + static void tick(MwWidget handle) { MwTreeView tv = handle->internal; @@ -363,7 +376,7 @@ MwClassRec MwTreeViewClassRec = { NULL, /* mouse_up */ NULL, /* mouse_down */ NULL, /* key */ - NULL, /* execute */ + func_handler, /* execute */ tick, /* tick */ NULL, NULL,