int IupClassMatch(Ihandle* ih, const char* classname) { iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return 0; return iupClassMatch(ih->iclass, classname); }
void IupCopyClassAttributes(Ihandle* src_ih, Ihandle* dst_ih) { int has_attrib_id, start_id = 0; Iclass* ic; char *name; iupASSERT(iupObjectCheck(src_ih)); if (!iupObjectCheck(src_ih)) return; iupASSERT(iupObjectCheck(dst_ih)); if (!iupObjectCheck(dst_ih)) return; if (!IupClassMatch(dst_ih, src_ih->iclass->name)) return; ic = src_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(src_ih, name)) /* can not be saved */ { name = iupTableNext(ic->attrib_func); continue; } if (!(afunc->flags & IUPAF_HAS_ID)) /* no ID */ { char *value = IupGetAttribute(src_ih, name); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttribute(dst_ih, name))) /* NOT already equal */ IupStoreAttribute(dst_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(src_ih, "NUMCOL")+1, numlin = IupGetInt(src_ih, "NUMLIN")+1; for (lin=0; lin<numlin; lin++) { for (col=0; col<numcol; col++) { value = IupGetAttributeId2(src_ih, name, lin, col); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttributeId2(dst_ih, name, lin, col))) /* NOT already stored */ IupStoreAttributeId2(dst_ih, name, lin, col, value); } } } } else { int id, count = IupGetInt(src_ih, "COUNT"); for (id=start_id; id<count+start_id; id++) { value = IupGetAttributeId(src_ih, name, id); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttributeId(dst_ih, name, id))) /* NOT already stored */ IupStoreAttributeId(dst_ih, name, id, value); } } } } } name = iupTableNext(ic->attrib_func); } 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) && !(afunc->flags & IUPAF_WRITEONLY) && !(afunc->flags & IUPAF_HAS_ID) && !(afunc->flags & IUPAF_CALLBACK)) { char *value = IupGetAttribute(src_ih, name); if (value && /* NOT NULL */ !iupStrEqualNoCase(value, IupGetAttribute(dst_ih, name))) /* NOT already stored */ IupStoreAttribute(dst_ih, name, value); } name = iupTableNext(ic->attrib_func); } }