int iupClassAttribIsRegistered(Iclass* ic, const char* name) { IattribFunc* afunc = NULL; if (ic->has_attrib_id!=0) { const char* name_id = iClassFindId(name); if (name_id) { const char* partial_name = iClassCutNameId(name, name_id); if (!partial_name) partial_name = "IDVALUE"; /* pure numbers are used as attributes in IupList and IupMatrix, translate them into IDVALUE. */ afunc = (IattribFunc*)iupTableGet(ic->attrib_func, partial_name); } } if (!afunc) afunc = (IattribFunc*)iupTableGet(ic->attrib_func, name); if (afunc) return 1; return 0; }
void iupClassObjectGetAttributeInfo(Ihandle* ih, const char* name, char* *def_value, int *inherit) { IattribFunc* afunc; if (ih->iclass->has_attrib_id!=0) { const char* name_id = iClassFindId(name); if (name_id) { const char* partial_name = iClassCutNameId(name, name_id); if (!partial_name) partial_name = "IDVALUE"; /* pure numbers are used as attributes in IupList and IupMatrix, translate them into IDVALUE. */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, partial_name); if (afunc && afunc->flags & IUPAF_HAS_ID) { *def_value = NULL; /* id numbered attributes have default value NULL always */ *inherit = 0; /* id numbered attributes are NON inheritable always */ return; /* if the function exists, then must return here */ } } } /* if not has_attrib_id, or not found an ID, or not found the partial name, check using the full name */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name); *def_value = NULL; *inherit = 1; /* default is inheritable */ if (afunc) { *def_value = iClassGetDefaultValue(afunc); *inherit = !(afunc->flags & IUPAF_NO_INHERIT) && /* is inheritable */ !(afunc->flags & IUPAF_NO_STRING); /* is a string */ } }
char* iupClassObjectGetAttribute(Ihandle* ih, const char* name, char* *def_value, int *inherit) { IattribFunc* afunc; if (ih->iclass->has_attrib_id!=0) { const char* name_id = iClassFindId(name); if (name_id) { const char* partial_name = iClassCutNameId(name, name_id); if (!partial_name) partial_name = "IDVALUE"; /* pure numbers are used as attributes in IupList and IupMatrix, translate them into IDVALUE. */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, partial_name); if (afunc && afunc->flags & IUPAF_HAS_ID) { *def_value = NULL; /* id numbered attributes have default value NULL always */ *inherit = 0; /* id numbered attributes are NON inheritable always */ if (afunc->flags & IUPAF_WRITEONLY) return NULL; if (afunc->get && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED)) { if (afunc->flags & IUPAF_HAS_ID2) { IattribGetId2Func id2_get = (IattribGetId2Func)afunc->get; int id1=IUP_INVALID_ID, id2=IUP_INVALID_ID; iupStrToIntInt(name_id, &id1, &id2, ':'); return id2_get(ih, id1, id2); } else { IattribGetIdFunc id_get = (IattribGetIdFunc)afunc->get; int id=IUP_INVALID_ID; if (iupStrToInt(name_id, &id)) return id_get(ih, id); } } else return NULL; /* if the function exists, then must return here */ } } } /* if not has_attrib_id, or not found an ID, or not found the partial name, check using the full name */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name); *def_value = NULL; *inherit = 1; /* default is inheritable */ if (afunc) { *def_value = iClassGetDefaultValue(afunc); *inherit = !(afunc->flags & IUPAF_NO_INHERIT) && /* is inheritable */ !(afunc->flags & IUPAF_NO_STRING); /* is a string */ if (afunc->flags & IUPAF_WRITEONLY) return NULL; if (afunc->get && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED)) { if (afunc->flags & IUPAF_HAS_ID2) { IattribGetId2Func id2_get = (IattribGetId2Func)afunc->get; return id2_get(ih, IUP_INVALID_ID, IUP_INVALID_ID); /* empty Id */ } else if (afunc->flags & IUPAF_HAS_ID) { IattribGetIdFunc id_get = (IattribGetIdFunc)afunc->get; return id_get(ih, IUP_INVALID_ID); /* empty Id */ } else return afunc->get(ih); } } return NULL; }
int iupClassObjectSetAttribute(Ihandle* ih, const char* name, const char * value, int *inherit) { IattribFunc* afunc; if (ih->iclass->has_attrib_id!=0) { const char* name_id = iClassFindId(name); if (name_id) { const char* partial_name = iClassCutNameId(name, name_id); if (!partial_name) partial_name = "IDVALUE"; /* pure numbers are used as attributes in IupList and IupMatrix, translate them into IDVALUE. */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, partial_name); if (afunc && afunc->flags & IUPAF_HAS_ID) { *inherit = 0; /* id numbered attributes are NON inheritable always */ if (afunc->flags & IUPAF_READONLY) { if (afunc->flags & IUPAF_NO_STRING) return -1; /* value is NOT a string, can NOT call iupAttribSetStr */ return 0; } if (afunc->set && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED)) { if (afunc->flags & IUPAF_HAS_ID2) { IattribSetId2Func id2_set = (IattribSetId2Func)afunc->set; int id1=IUP_INVALID_ID, id2=IUP_INVALID_ID; iupStrToIntInt(name_id, &id1, &id2, ':'); /* ignore errors because of '*' ids */ return id2_set(ih, id1, id2, value); } else { IattribSetIdFunc id_set = (IattribSetIdFunc)afunc->set; int id=IUP_INVALID_ID; if (iupStrToInt(name_id, &id)) return id_set(ih, id, value); } } if (afunc->flags & IUPAF_NO_STRING) return -1; /* value is NOT a string, can NOT call iupAttribSetStr */ return 1; /* if the function exists, then must return here */ } } } /* if not has_attrib_id, or not found an ID, or not found the partial name, check using the full name */ afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name); *inherit = 1; /* default is inheritable */ if (afunc) { *inherit = !(afunc->flags & IUPAF_NO_INHERIT) && /* is inheritable */ !(afunc->flags & IUPAF_NO_STRING); /* is a string */ if (afunc->flags & IUPAF_READONLY) { if (afunc->flags & IUPAF_NO_STRING) return -1; /* value is NOT a string, can NOT call iupAttribSetStr */ return 0; } if (afunc->set && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED)) { int ret; if (!value) { /* inheritable attributes when reset must check the parent value */ if (*inherit && ih->parent) value = iupAttribGetInherit(ih->parent, name); if (!value) value = iClassGetDefaultValue(afunc); } if (afunc->flags & IUPAF_HAS_ID2) { IattribSetId2Func id2_set = (IattribSetId2Func)afunc->set; return id2_set(ih, IUP_INVALID_ID, IUP_INVALID_ID, value); /* empty Id */ } else if (afunc->flags & IUPAF_HAS_ID) { IattribSetIdFunc id_set = (IattribSetIdFunc)afunc->set; return id_set(ih, IUP_INVALID_ID, value); /* empty Id */ } else ret = afunc->set(ih, value); if (ret == 1 && afunc->flags & IUPAF_NO_STRING) return -1; /* value is NOT a string, can NOT call iupAttribSetStr */ if (*inherit) return 1; /* inheritable attributes are always stored in the hash table, */ else /* to indicate that they are set at the control. */ return ret; } } return 1; /* function not found, default to string */ }