static char* iMatrixExGetNumericUnitAttrib(Ihandle* ih, int col) { int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); if (!quantity) return NULL; else { int unit = IupGetIntId(ih, "NUMERICUNITINDEX", col); return iMatrixExReturnUnit(imatex_quantities[quantity].units[unit].u_name); } }
static char* iMatrixExGetNumericUnitSymbolShownAttrib(Ihandle* ih, int col) { int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); if (!quantity) return NULL; else { int unit = IupGetIntId(ih, "NUMERICUNITSHOWNINDEX", col); return iMatrixExReturnSymbol(&(imatex_quantities[quantity].units[unit])); } }
int iupMatrixExIsColumnVisible(Ihandle* ih, int col) { int width = 0; char* value; if (col==0) return (IupGetIntId(ih, "RASTERWIDTH", 0) != 0); /* to be invisible must exist the attribute and must be set to 0 (zero), or else is visible */ value = iupAttribGetId(ih, "WIDTH", col); if (!value) { value = iupAttribGetId(ih, "RASTERWIDTH", col); if (!value) return 1; } if (iupStrToInt(value, &width)==1) { if (width==0) return 0; } return 1; }
static int iMatrixListSetFocusColorAttrib(Ihandle* ih, const char* value) { int lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); iupAttribSetStr(ih, "FOCUSCOLOR", value); iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); return 1; }
static char* iMatrixExGetNumericUnitCountAttrib(Ihandle* ih, int col) { int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); if (!quantity) return NULL; else return iupStrReturnInt(imatex_quantities[quantity].units_count); }
static int iMatrixListEnterItem_CB(Ihandle *ih, int lin, int col) { IFnii cb = (IFnii)IupGetCallback(ih, "LISTACTION_CB"); int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", lin); if (cb) cb(ih, lin, 1); (void)col; return IUP_DEFAULT; }
static char* iMatrixExGetNumericQuantityAttrib(Ihandle* ih, int col) { if (!IupGetAttributeId(ih, "NUMERICQUANTITYINDEX", col)) return NULL; else { int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); return (char*)imatex_quantities[quantity].q_name; } }
static void iMatrixListSetFocusItem(Ihandle* ih, ImatrixListData* mtxList, int lin) { if (lin != ih->data->lines.focus_cell) { int old_lin = ih->data->lines.focus_cell; int itemactive = IupGetIntId(ih, "ITEMACTIVE", old_lin); ih->data->lines.focus_cell = -1; iMatrixListUpdateItemBgColor(ih, old_lin, iupAttribGetId(ih, "ITEMBGCOLOR", old_lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", old_lin); itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); ih->data->lines.focus_cell = lin; iMatrixListUpdateItemBgColor(ih, lin, iupAttribGetId(ih, "ITEMBGCOLOR", lin), itemactive); IupSetfAttribute(ih, "REDRAW", "L%d", lin); } if (mtxList->label_col) IupSetfAttribute(ih, "FOCUSCELL", "%d:%d", lin, mtxList->label_col); else IupSetfAttribute(ih, "FOCUSCELL", "%d:1", lin); }
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 cbUnHideAllTabs(Ihandle* ih) { Ihandle* tabs = (Ihandle*)IupGetAttribute(ih, "APP_TABS"); int i, count = IupGetInt(tabs, "COUNT"); for (i = 0; i < count; i++) { if (!IupGetIntId(tabs, "TABVISIBLE", i)) { IupSetAttributeId(tabs, "TABVISIBLE", i, "Yes"); printf("tab %d = was hidden\n", i); } else printf("tab %d = is visible\n", i); } return IUP_DEFAULT; }
static int cbEnableAllTabs(Ihandle* ih) { Ihandle* tabs = (Ihandle*)IupGetAttribute(ih, "APP_TABS"); int i, count = IupGetInt(tabs, "COUNT"); for (i = 0; i < count; i++) { if (!IupGetIntId(tabs, "TABACTIVE", i)) { IupSetAttributeId(tabs, "TABACTIVE", i, "Yes"); printf("tab %d = was inactive\n", i); } else printf("tab %d = is active\n", i); } return IUP_DEFAULT; }
static int iMatrixListDrawColorCol(Ihandle *ih, int lin, int x1, int x2, int y1, int y2, cdCanvas *cnv) { unsigned char red, green, blue; char* color = iupAttribGetId(ih, "COLOR", lin); if (iupStrToRGB(color, &red, &green, &blue)) { static const int DX_BORDER = 2; static const int DY_BORDER = 3; static const int DX_FILL = 3; static const int DY_FILL = 4; int active = iupdrvIsActive(ih); int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); long framecolor; if (!itemactive) { red = IMAT_LIGHTER(red); green = IMAT_LIGHTER(green); blue = IMAT_LIGHTER(blue); } if (!active) { unsigned char bg_r, bg_g, bg_b; iupStrToRGB(ih->data->bgcolor, &bg_r, &bg_g, &bg_b); iupImageColorMakeInactive(&red, &green, &blue, bg_r, bg_g, bg_b); } /* Fill the box with the color */ cdCanvasForeground(cnv, cdEncodeColor(red, green, blue)); cdCanvasBox(cnv, x1 + DX_FILL, x2 - DX_FILL, y1 - DY_FILL, y2 + DY_FILL); /* Draw the border */ framecolor = cdIupConvertColor(iupAttribGetStr(ih, "FRAMECOLOR")); cdCanvasForeground(cnv, framecolor); cdCanvasRect(cnv, x1 + DX_BORDER, x2 - DX_BORDER, y1 - DY_BORDER, y2 + DY_BORDER); } return IUP_DEFAULT; /* draw nothing more */ }
int iupMatrixExIsLineVisible(Ihandle* ih, int lin) { int height = 0; char* value; if (lin==0) return (IupGetIntId(ih, "RASTERHEIGHT", 0) != 0); value = iupAttribGetId(ih, "HEIGHT", lin); if(!value) { value = iupAttribGetId(ih, "RASTERHEIGHT", lin); if(!value) return 1; } if (iupStrToInt(value, &height)==1) { if (height==0) return 0; } return 1; }
static int iMatrixListSetItemFgColorAttrib(Ihandle* ih, int lin, const char* value) { int itemactive = IupGetIntId(ih, "ITEMACTIVE", lin); iMatrixListUpdateItemFgColor(ih, lin, value, itemactive); return 1; }
int IupTreeGetInt(Ihandle* ih, const char* a, int id) { return IupGetIntId(ih, a, id); }
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; }
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 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 */ }