From eed0eb6a476d54ce19aeff137984aa981d9e3976 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 15 Jun 2010 00:59:57 -0700 Subject: Upgrading to iup 3.1 --- iup/src/iup_list.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'iup/src/iup_list.c') diff --git a/iup/src/iup_list.c b/iup/src/iup_list.c index 5965665..1077d98 100755 --- a/iup/src/iup_list.c +++ b/iup/src/iup_list.c @@ -53,6 +53,37 @@ static void iListCallActionCallback(Ihandle* ih, IFnsii cb, int pos, int state) IupExitLoop(); } +void iupListUpdateOldValue(Ihandle* ih, int pos, int removed) +{ + if (!ih->data->has_editbox) + { + char* old_value = iupAttribGet(ih, "_IUPLIST_OLDVALUE"); + if (old_value) + { + int old_pos = atoi(old_value)-1; /* was in IUP reference, starting at 1 */ + if (ih->data->is_dropdown || !ih->data->is_multiple) + { + if (old_pos >= pos) + { + if (removed && old_pos == pos) + { + /* when the current item is removed nothing remains selected */ + iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); + } + else + iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", removed? old_pos-1: old_pos+1); + } + } + else + { + /* multiple selection on a non drop-down list. */ + char* value = IupGetAttribute(ih, "VALUE"); + iupAttribStoreStr(ih, "_IUPLIST_OLDVALUE", value); + } + } + } +} + void iupListSingleCallActionCallback(Ihandle* ih, IFnsii cb, int pos) { char* old_str = iupAttribGet(ih, "_IUPLIST_OLDVALUE"); @@ -77,7 +108,7 @@ void iupListMultipleCallActionCallback(Ihandle* ih, IFnsii cb, IFns multi_cb, in char* old_str = iupAttribGet(ih, "_IUPLIST_OLDVALUE"); int old_count = old_str? strlen(old_str): 0; - char* str = iupStrGetMemory(count+1); + char* str = malloc(count+1); memset(str, '-', count); str[count]=0; for (i=0; i count-1) return -1; + if (pos == count) return -2; + if (pos > count) return -1; return pos; } @@ -217,7 +254,10 @@ int iupListSetIdValueAttrib(Ihandle* ih, const char* name_id, const char* value) if (pos >= 0 && pos <= count-1) { if (pos == 0) + { iupdrvListRemoveAllItems(ih); + iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); + } else { int i = pos; @@ -245,7 +285,7 @@ int iupListSetIdValueAttrib(Ihandle* ih, const char* name_id, const char* value) static int iListSetAppendItemAttrib(Ihandle* ih, const char* value) { - if (!ih->handle) /* do not store the action before map */ + if (!ih->handle) /* do not do the action before map */ return 0; if (value) iupdrvListAppendItem(ih, value); @@ -254,27 +294,32 @@ static int iListSetAppendItemAttrib(Ihandle* ih, const char* value) static int iListSetInsertItemAttrib(Ihandle* ih, const char* name_id, const char* value) { - if (!ih->handle) /* do not store the action before map */ + if (!ih->handle) /* do not do the action before map */ return 0; if (value) { int pos = iupListGetPos(ih, name_id); - if (pos!=-1) + if (pos >= 0) iupdrvListInsertItem(ih, pos, value); + else if (pos == -2) + iupdrvListAppendItem(ih, value); } return 0; } static int iListSetRemoveItemAttrib(Ihandle* ih, const char* value) { - if (!ih->handle) /* do not store the action before map */ + if (!ih->handle) /* do not do the action before map */ return 0; if (!value) + { iupdrvListRemoveAllItems(ih); + iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); + } else { int pos = iupListGetPos(ih, value); - if (pos!=-1) + if (pos >= 0) iupdrvListRemoveItem(ih, pos); } return 0; -- cgit v1.2.3