static void iMatrixListInitSize(Ihandle* ih, ImatrixListData* mtxList) { char str[30]; int num_col = 0; if (mtxList->label_col != 0) num_col++; if (mtxList->color_col != 0) num_col++; if (mtxList->image_col != 0) num_col++; sprintf(str, "%d", num_col); iupMatrixSetNumColAttrib(ih, str); /* "NUMCOL" */ IupSetStrAttribute(ih, "NUMCOL_VISIBLE", str); if (mtxList->color_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->color_col)) IupSetIntId(ih, "WIDTH", mtxList->color_col, IMTXL_COLOR_WIDTH); } if (mtxList->image_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->image_col)) IupSetIntId(ih, "WIDTH", mtxList->image_col, IMTXL_IMAGE_WIDTH); } }
static int iMatrixExSetNumericUnitShownAttrib(Ihandle* ih, int col, const char* value) { int unit; int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); if (!quantity) return 0; unit = iMatrixFindUnit(imatex_quantities[quantity].units, imatex_quantities[quantity].units_count, value); if (unit < 0) return 0; IupSetIntId(ih, "NUMERICUNITSHOWNINDEX", col, unit); return 0; }
static int iMatrixExSetNumericUnitSymbolAttrib(Ihandle* ih, int col, const char* value) { int unit, utf8; int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); if (!quantity) return 0; utf8 = IupGetInt(NULL, "UTF8MODE"); unit = iMatrixFindUnitSymbol(imatex_quantities[quantity].units, imatex_quantities[quantity].units_count, value, utf8); if (unit < 0) return 0; IupSetIntId(ih, "NUMERICUNITINDEX", col, unit); return 0; }
static int iMatrixExSetNumericQuantityAttrib(Ihandle* ih, int col, const char* value) { if (!value) { IupSetCallback(ih, "NUMERICCONVERT_FUNC", NULL); IupSetAttributeId(ih, "NUMERICQUANTITYINDEX", col, NULL); } else { int quantity = iMatrixFindQuantity(value); if (quantity < 0) quantity = 0; /* Set to None, this will enable the numeric column, but no unit conversion */ /* set the callback before setting the attribute */ IupSetCallback(ih, "NUMERICCONVERT_FUNC", (Icallback)iMatrixConvertFunc); IupSetIntId(ih, "NUMERICQUANTITYINDEX", col, quantity); } return 0; }
static int iMatrixListKeyAny_CB(Ihandle *ih, int key) { ImatrixListData* mtxList = (ImatrixListData*)iupAttribGet(ih, "_IUPMTXLIST_DATA"); if (IupGetInt(ih, "EDITMODE")) return IUP_CONTINUE; if (key == K_SP || key == K_sSP) { if (mtxList->image_col != 0) { int lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); int imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); int lines_num = ih->data->lines.num; if (!itemactive || !imageactive) return IUP_IGNORE; if (!mtxList->editable || lin != lines_num-1) { IFnii imagevaluechanged_cb = (IFnii)IupGetCallback(ih, "IMAGEVALUECHANGED_CB"); int imagevalue = !IupGetIntId(ih, "IMAGEVALUE", lin); if (!imagevaluechanged_cb || imagevaluechanged_cb(ih, lin, imagevalue) != IUP_IGNORE) { IupSetIntId(ih, "IMAGEVALUE", lin, imagevalue); IupSetfAttribute(ih, "REDRAW", "L%d", lin); return IUP_IGNORE; } } return IUP_IGNORE; } } else if (key == K_HOME || key == K_sHOME) { iMatrixListSetFocusItem(ih, mtxList, 1); IupSetAttribute(ih, "SHOW", "1:*"); return IUP_IGNORE; } else if (key == K_END || key == K_sEND) { iMatrixListSetFocusItem(ih, mtxList, ih->data->lines.num-1); IupSetfAttribute(ih, "SHOW", "%d:*", ih->data->lines.num-1); return IUP_IGNORE; } else if (key == K_DEL || key == K_sDEL) { if (mtxList->editable) { IFni listremove_cb = (IFni)IupGetCallback(ih, "LISTREMOVE_CB"); /* notify the application that a line will be removed */ int lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); if (itemactive && (!listremove_cb || listremove_cb(ih, lin) != IUP_IGNORE)) { /* Remove the line */ IupSetInt(ih, "DELLIN", lin); return IUP_IGNORE; } } } else if (key == K_F2 || key == K_CR || key == K_sCR) { int lin = ih->data->lines.focus_cell; iMatrixListSetFocusItem(ih, mtxList, lin); /* this will position focus at the right cell */ IupSetAttribute(ih, "EDITMODE", "Yes"); return IUP_IGNORE; } else { /* if a valid character is pressed enter edition mode */ if (iup_isprint(key)) { int lin = ih->data->lines.focus_cell; iMatrixListSetFocusItem(ih, mtxList, lin); /* this will position focus at the right cell */ IupSetAttribute(ih, "EDITMODE", "Yes"); if (IupGetInt(ih, "EDITMODE")) { char value[2] = {0,0}; value[0] = (char)key; IupStoreAttribute(ih->data->datah, "VALUEMASKED", value); IupSetAttribute(ih->data->datah, "CARET", "2"); return IUP_IGNORE; } } } return IUP_CONTINUE; }
static int iMatrixListRelease_CB(Ihandle *ih, int lin, int col, char *status) { ImatrixListData* mtxList = (ImatrixListData*)iupAttribGet(ih, "_IUPMTXLIST_DATA"); IFniis listrelease_cb = (IFniis)IupGetCallback(ih, "LISTRELEASE_CB"); int lines_num = ih->data->lines.num; int itemactive, imageactive; /* call application callback before anything */ if (listrelease_cb && listrelease_cb(ih, lin, col, status)==IUP_IGNORE) return IUP_IGNORE; if (mtxList->last_click_lin != lin || mtxList->last_click_col != col) return IUP_DEFAULT; /* only the image column must be processed */ if (col != mtxList->image_col) return IUP_DEFAULT; itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); if (!itemactive || !imageactive) return IUP_DEFAULT; if (mtxList->editable && lin == lines_num-1) { /* click on IMAGEADD - start editing */ iMatrixListSetFocusItem(ih, mtxList, lin); IupSetAttribute(ih, "EDITMODE", "Yes"); } else if (iMatrixListCheckDelete(ih)) { /* click on IMAGEDEL */ IFni listremove_cb = (IFni)IupGetCallback(ih, "LISTREMOVE_CB"); if (lin == 0) { if (mtxList->editable) lines_num--; for (lin = lines_num-1; lin>0; lin--) { itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); if (!itemactive || !imageactive) continue; if (!listremove_cb || listremove_cb(ih, lin) != IUP_IGNORE) IupSetInt(ih, "DELLIN", lin); } } else { /* notify the application that a line will be removed */ if (!listremove_cb || listremove_cb(ih, lin) != IUP_IGNORE) { /* Remove the line */ IupSetInt(ih, "DELLIN", lin); } } } else { /* click on IMAGECHECK/IMAGEUNCHECK */ IFnii imagevaluechanged_cb = (IFnii)IupGetCallback(ih, "IMAGEVALUECHANGED_CB"); int imagevalue = !IupGetIntId(ih, "IMAGEVALUE", lin); if (!imagevaluechanged_cb || imagevaluechanged_cb(ih, lin, imagevalue) != IUP_IGNORE) { IupSetIntId(ih, "IMAGEVALUE", lin, imagevalue); IupSetfAttribute(ih, "REDRAW", "L%d", lin); if (lin==0) { if (mtxList->editable) lines_num--; for (lin=1; lin<lines_num; lin++) { itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); imageactive = IupGetIntId(ih, "IMAGEACTIVE", lin); if (!itemactive || !imageactive) continue; if (!imagevaluechanged_cb || imagevaluechanged_cb(ih, lin, imagevalue) != IUP_IGNORE) { IupSetIntId(ih, "IMAGEVALUE", lin, imagevalue); IupSetfAttribute(ih, "REDRAW", "L%d", lin); } } } } } return IUP_DEFAULT; }