float IupGetFloatId2(Ihandle* ih, const char* name, int lin, int col) { float f = 0; char *value = IupGetAttributeId2(ih, name, lin, col); if (value) iupStrToFloat(value, &f); return f; }
static int release(Ihandle *self, int lin, int col) { char* value = IupGetAttributeId2(self, "", lin, col); if (!value) value = "NULL"; printf("release_cb(%d, %d)\n", lin, col); printf(" VALUE%d:%d = %s\n", lin, col, value); return IUP_DEFAULT; }
static int GetAttributeId2(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int lin = (int)luaL_checkinteger(L,3); int col = (int)luaL_checkinteger(L,4); const char *value = IupGetAttributeId2(ih, name, lin, col); iuplua_pushvalue(L, ih, name, value); return 1; }
int iupmaskMatSet(Ihandle* ih, const char* mask_str, int autofill, int casei, int lin, int col) { (void)autofill; IupSetAttributeId2(ih,"MASKCASEI", lin, col, casei?"YES":"NO"); IupSetAttributeId2(ih,"MASK", lin, col, (char*)mask_str); if (iupStrEqual(mask_str, IupGetAttributeId2(ih,"MASK", lin, col))) return 1; else return 0; }
int iupmaskMatGet(Ihandle *ih, char **sval, int lin, int col) { char *val = IupGetAttributeId2(ih,"",lin,col); Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA"); if (iupMaskCheck(mask,val)==1) { *sval = val; return 1; } else return 0; }
int IupGetIntId2(Ihandle* ih, const char* name, int lin, int col) { int i = 0; char *value = IupGetAttributeId2(ih, name, lin, col); if (value) { if (!iupStrToInt(value, &i)) { if (iupStrBoolean(value)) i = 1; } } return i; }
int iupmaskMatGetInt(Ihandle *ih, int *ival, int lin, int col) { char *val = IupGetAttributeId2(ih,"",lin,col); Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA"); if(iupMaskCheck(mask,val)==1) { *ival = 0; sscanf(val,"%d",ival); return 1; } else return 0; }
int iupmaskMatGetFloat(Ihandle *ih, float *fval, int lin, int col) { char *val = IupGetAttributeId2(ih,"",lin,col); Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA"); if (iupMaskCheck(mask,val)==1) { *fval = 0.0F; sscanf(val,"%f",fval); return 1; } else return 0; }
int iupmaskMatGetDouble(Ihandle *ih, double *dval, int lin, int col) { char *val = IupGetAttributeId2(ih,"",lin,col); Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA"); if(iupMaskCheck(mask,val)==1) { *dval = 0.0; sscanf(val,"%lf",dval); return 1; } else return 0; }
static int edition_cb(Ihandle *self, int lin, int col, int mode, int update) { if (mode == 0) { char* value = IupGetAttribute(self, "VALUE"); #ifndef BIG_MATRIX if (value && strcmp(value, data[lin-1][col-1])!=0) #else char* cell = IupGetAttributeId2(self, "", lin, col); if (value && cell && strcmp(value, cell)!=0) #endif return IUP_IGNORE; } return IUP_DEFAULT; }
static int MatGetAttribute(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int lin = luaL_checkint(L,3); int col = luaL_checkint(L,4); const char *value = IupGetAttributeId2(ih, name, lin, col); if (!value || iupATTRIB_ISINTERNAL(name)) lua_pushnil(L); else { if (iupAttribIsNotString(ih, name)) { if (iupObjectCheck((Ihandle*)value)) iuplua_pushihandle(L, (Ihandle*)value); else lua_pushlightuserdata(L, (void*)value); } else lua_pushstring(L,value); } return 1; }
static int iMatrixListDrawImageCol(Ihandle *ih, ImatrixListData* mtxList, int lin, int col, int x1, int x2, int y1, int y2, cdCanvas *cnv) { char* image_name; int make_inactive = 0, itemactive, imageactive, imagevalue, showdelete, active = iupdrvIsActive(ih), linedelete; int lines_num = ih->data->lines.num; Ihandle* image; itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); imagevalue = IupGetIntId(ih, "IMAGEVALUE", lin); showdelete = IupGetInt(ih, "SHOWDELETE"); linedelete = IupGetIntId(ih, "LINEDELETE", lin); if (!active || !itemactive || !imageactive) make_inactive = 1; image_name = iupAttribGetId(ih, "IMAGE", lin); if (!image_name) { char* attrib_name; if (mtxList->editable) { if (lin == lines_num-1) attrib_name = "IMAGEADD"; else { if (showdelete || linedelete) attrib_name = "IMAGEDEL"; else { if (imagevalue) attrib_name = "IMAGECHECK"; else attrib_name = "IMAGEUNCHECK"; } } } else { if (imagevalue) attrib_name = "IMAGECHECK"; else attrib_name = "IMAGEUNCHECK"; } image_name = iupAttribGetStr(ih, attrib_name); /* this will check for the default values also */ } image = iupImageGetHandle(image_name); if (image) { int width = IupGetInt(image, "WIDTH"); int height = IupGetInt(image, "HEIGHT"); long bgcolor = cdIupConvertColor(IupGetAttributeId2(ih, "CELLBGCOLOR", lin, col)); /* Calc the image_name position */ int x = x2 - x1 - width; int y = y1 - y2 - 1 - height; x /= 2; x += x1; y /= 2; y += y2; cdIupDrawImage(cnv, image, x, y, 0, 0, make_inactive, bgcolor); } return IUP_DEFAULT; /* draw nothing more */ }
char* IupMatGetAttribute(Ihandle* ih, const char* name, int lin, int col) { return IupGetAttributeId2(ih, name, lin, col); }
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); } }
int iupMatrixEditShowXY(Ihandle* ih, int x, int y) { char* mask; /* work around for Windows when using Multiline */ if (iupAttribGet(ih, "_IUPMAT_IGNORE_SHOW")) { iupAttribSet(ih, "_IUPMAT_IGNORE_SHOW", NULL); return 0; } /* there are no cells that can be edited */ if (ih->data->columns.num <= 1 || ih->data->lines.num <= 1) return 0; if (ih->data->editing || iupMatrixEditIsVisible(ih)) { if (ih->data->edit_hide_onfocus) return 0; iupMatrixEditHide(ih); } ih->data->edit_lin = ih->data->lines.focus_cell; ih->data->edit_col = ih->data->columns.focus_cell; /* notify application */ if (iMatrixEditCallEditionCbUpdateValue(ih, 1, 0) == IUP_IGNORE) /* only place where mode=1 */ return 0; if (iMatrixEditCallMenuDropCb(ih, ih->data->edit_lin, ih->data->edit_col)) return 0; ih->data->editing = 1; /* select edit control */ iMatrixEditChooseElement(ih); /* position the cell to make it visible */ /* If the focus is not visible, a scroll is done for that the focus to be visible */ if (!iupMatrixAuxIsCellStartVisible(ih, ih->data->edit_lin, ih->data->edit_col)) iupMatrixScrollToVisible(ih, ih->data->edit_lin, ih->data->edit_col); /* set attributes */ iupMatrixPrepareDrawData(ih); IupStoreAttribute(ih->data->datah, "BGCOLOR", iupMatrixGetBgColorStr(ih, ih->data->edit_lin, ih->data->edit_col)); IupStoreAttribute(ih->data->datah, "FGCOLOR", iupMatrixGetFgColorStr(ih, ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "FONT", iupMatrixGetFont(ih, ih->data->edit_lin, ih->data->edit_col)); mask = IupGetAttributeId2(ih, "MASK", ih->data->edit_lin, ih->data->edit_col); if (mask) { IupSetAttribute(ih->data->datah, "MASKCASEI", IupGetAttributeId2(ih, "MASKCASEI", ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "MASKNOEMPTY", IupGetAttributeId2(ih, "MASKNOEMPTY", ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "MASK", mask); } else { mask = IupGetAttributeId2(ih, "MASKINT", ih->data->edit_lin, ih->data->edit_col); if (mask) IupSetAttribute(ih->data->datah, "MASKINT", mask); else { mask = IupGetAttributeId2(ih, "MASKFLOAT", ih->data->edit_lin, ih->data->edit_col); if (mask) IupSetAttribute(ih->data->datah, "MASKFLOAT", mask); else IupSetAttribute(ih->data->datah, "MASK", NULL); } } iupMatrixEditUpdatePos(ih); /* activate and show */ IupSetAttribute(ih->data->datah, "ACTIVE", "YES"); IupSetAttribute(ih->data->datah, "VISIBLE", "YES"); IupSetFocus(ih->data->datah); if (ih->data->datah == ih->data->texth) { if (iupAttribGetBoolean(ih, "EDITALIGN")) IupSetStrAttribute(ih->data->datah, "ALIGNMENT", IupGetAttributeId(ih, "ALIGNMENT", ih->data->edit_col)); if (x || y) { int pos; x -= ih->data->datah->x; y -= ih->data->datah->y; pos = IupConvertXYToPos(ih->data->datah, x, y); IupSetInt(ih->data->datah, "CARETPOS", pos); } } return 1; }
int iupmaskMatCheck(Ihandle *ih, int lin, int col) { char *val = IupGetAttributeId2(ih,"",lin,col); Imask* mask = (Imask*)IupGetAttribute(ih,"OLD_MASK_DATA"); return iupMaskCheck(mask,val)==1; }