char* IupGetAttributeId2(Ihandle* ih, const char* name, int lin, int col) { char *value; iupASSERT(name!=NULL); if (!name) return NULL; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return NULL; value = iupClassObjectGetAttributeId2(ih, name, lin, col); if (!value) { char attr[100]; sprintf(attr, "%s%d:%d", name, lin, col); value = iupAttribGet(ih, attr); } return value; }
void IupSaveClassAttributes(Ihandle* ih) { int has_attrib_id, start_id = 0; Iclass* ic; char *name; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return; ic = ih->iclass; has_attrib_id = ic->has_attrib_id; if (iupClassMatch(ic, "tree") || /* tree can only set id attributes after map, so they can not be saved */ iupClassMatch(ic, "cells")) /* cells does not have any saveable id attributes */ has_attrib_id = 0; if (iupClassMatch(ic, "list")) start_id = 1; name = iupTableFirst(ic->attrib_func); while (name) { IattribFunc* afunc = (IattribFunc*)iupTableGet(ic->attrib_func, name); if (afunc && !(afunc->flags & IUPAF_NO_STRING) && /* is a string */ !(afunc->flags & IUPAF_READONLY) && /* not read-only */ !(afunc->flags & IUPAF_WRITEONLY) && /* not write-only */ !(afunc->flags & IUPAF_CALLBACK)) /* not a callback */ { if ((afunc->flags&IUPAF_NO_SAVE) && iupBaseNoSaveCheck(ih, name)) /* can not be saved */ { name = iupTableNext(ic->attrib_func); continue; } if (!(afunc->flags & IUPAF_HAS_ID)) /* no ID */ { int inherit; char *def_value; char *value = iupClassObjectGetAttribute(ih, name, &def_value, &inherit); if (value && value[0]) /* NOT NULL and not empty */ { if ((def_value && iupStrEqualNoCase(def_value, value)) || /* equal to the default value */ (!def_value && iupStrFalse(value))) /* default=NULL and value=NO */ { name = iupTableNext(ic->attrib_func); continue; } if (!iupStrEqualNoCase(value, iupAttribGet(ih, name))) /* NOT already stored */ iupAttribSetStr(ih, name, value); } } else if (has_attrib_id) { char *value; if (iupStrEqual(name, "IDVALUE")) name = ""; if (afunc->flags&IUPAF_HAS_ID2) { int lin, col, numcol = IupGetInt(ih, "NUMCOL")+1, numlin = IupGetInt(ih, "NUMLIN")+1; for (lin=0; lin<numlin; lin++) { for (col=0; col<numcol; col++) { value = iupClassObjectGetAttributeId2(ih, name, lin, col); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId2(ih, name, lin, col))) /* NOT already stored */ iupAttribSetStrId2(ih, name, lin, col, value); } } } } else { int id, count = IupGetInt(ih, "COUNT"); for (id=start_id; id<count+start_id; id++) { value = iupClassObjectGetAttributeId(ih, name, id); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId(ih, name, id))) /* NOT already stored */ iupAttribSetStrId(ih, name, id, value); } } } } } name = iupTableNext(ic->attrib_func); } }