static int iMatrixSetShowAttrib(Ihandle* ih, const char* value) { int lin = -1, col = -1; /* Get the parameters. The '*' indicates that want to keep the table in the same line or column */ if (iupStrToIntInt(value, &lin, &col, ':') != 2) { if (lin != -1) col = ih->data->columns.first; else if (col != -1) lin = ih->data->lines.first; else return 0; } /* Check if the cell exists */ if (!iupMatrixCheckCellPos(ih, lin, col)) return 0; /* Can not be a title */ if((lin < 1) || (col < 1)) return 0; if (!iupMatrixAuxIsCellStartVisible(ih, lin, col)) iupMatrixScrollToVisible(ih, lin, col); return 0; }
int iupMatrixEditShow(Ihandle* ih) { char* mask; int w, h, x, y; /* work around for Windows when using Multiline */ if (iupAttribGet(ih, "_IUPMAT_IGNORE_SHOW")) { iupAttribSetStr(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; /* not active */ if(!IupGetInt(ih, "ACTIVE")) return 0; /* already visible */ if(IupGetInt(ih->data->datah, "VISIBLE")) return 0; /* notify application */ if (iMatrixEditCallEditionCb(ih, 1, 0) == IUP_IGNORE) return 0; if (iMatrixEditCallMenuDropCb(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)) return 0; /* 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->lines.focus_cell, ih->data->columns.focus_cell)) iupMatrixScrollToVisible(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell); /* set attributes */ iupMatrixPrepareDrawData(ih); IupStoreAttribute(ih->data->datah, "BGCOLOR", iupMatrixGetBgColor(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)); IupStoreAttribute(ih->data->datah, "FGCOLOR", iupMatrixGetFgColor(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)); IupSetAttribute(ih->data->datah, "FONT", iupMatrixGetFont(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)); mask = IupMatGetAttribute(ih,"MASK", ih->data->lines.focus_cell, ih->data->columns.focus_cell); if (mask) { IupSetAttribute(ih->data->datah, "MASKCASEI", IupMatGetAttribute(ih,"MASKCASEI", ih->data->lines.focus_cell, ih->data->columns.focus_cell)); IupSetAttribute(ih->data->datah, "MASK", mask); } else { mask = IupMatGetAttribute(ih,"MASKINT", ih->data->lines.focus_cell, ih->data->columns.focus_cell); if (mask) IupSetAttribute(ih->data->datah, "MASKINT", mask); else { mask = IupMatGetAttribute(ih,"MASKFLOAT", ih->data->lines.focus_cell, ih->data->columns.focus_cell); if (mask) IupSetAttribute(ih->data->datah, "MASKFLOAT", mask); else IupSetAttribute(ih->data->datah, "MASK", NULL); } } /* calc size */ iupMatrixGetVisibleCellDim(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell, &x, &y, &w, &h); ih->data->datah->x = x; ih->data->datah->y = y; ih->data->datah->currentwidth = w; ih->data->datah->currentheight = h; iupClassObjectLayoutUpdate(ih->data->datah); /* activate and show */ IupSetAttribute(ih->data->datah, "ACTIVE", "YES"); IupSetAttribute(ih->data->datah, "VISIBLE", "YES"); IupSetFocus(ih->data->datah); return 1; }
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 iupMatrixProcessKeyPress(Ihandle* ih, int c) { /* This function is also called from inside the keyboard callbacks of the Text and Dropdown list when in edition mode */ int ret = IUP_IGNORE; /* default for processed keys */ /* Hide (off) the marked cells if the key is not tab/del */ if (c != K_TAB && c != K_sTAB && c != K_DEL && c != K_sDEL) iupMatrixMarkClearAll(ih, 1); /* If the focus is not visible, a scroll is done for that the focus to be visible */ if (!iupMatrixAuxIsCellFullVisible(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)) iupMatrixScrollToVisible(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell); switch (c) { case K_CR+2000: /* used by the iMatrixEditTextKeyAny_CB and iMatrixEditDropDownKeyAny_CB */ if (iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyCr(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_cHOME: case K_sHOME: case K_HOME: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyHome(ih); ih->data->homekeycount++; iupMatrixAuxCallEnterCellCb(ih); break; case K_cEND: case K_sEND: case K_END: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyEnd(ih); ih->data->endkeycount++; iupMatrixAuxCallEnterCellCb(ih); break; case K_sTAB: case K_TAB: return IUP_CONTINUE; /* do not redraw */ case K_cLEFT: case K_sLEFT: case K_LEFT: if (iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyLeft(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_cRIGHT: case K_sRIGHT: case K_RIGHT: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyRight(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_cUP: case K_sUP: case K_UP: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyUp(ih); iupMatrixAuxCallEnterCellCb(ih); break ; case K_cDOWN: case K_sDOWN: case K_DOWN: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyDown(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_sPGUP: case K_PGUP: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyPgUp(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_sPGDN: case K_PGDN: if(iupMatrixAuxCallLeaveCellCb(ih) == IUP_IGNORE) break; iupMatrixScrollKeyPgDown(ih); iupMatrixAuxCallEnterCellCb(ih); break; case K_SP: case K_CR: case K_sCR: if (iupMatrixEditShow(ih)) return IUP_IGNORE; /* do not redraw */ break; case K_sDEL: case K_DEL: { int lin, col; char str[100]; IFnii mark_cb = (IFnii)IupGetCallback(ih, "MARK_CB"); iupMatrixPrepareDrawData(ih); for(lin = 1; lin < ih->data->lines.num; lin++) { for(col = 1; col < ih->data->columns.num; col++) { if (iupMatrixMarkCellGet(ih, lin, col, mark_cb, str)) { if (iupMatrixAuxCallEditionCbLinCol(ih, lin, col, 1) != IUP_IGNORE) { IFniis value_edit_cb; iupMatrixCellSetValue(ih, lin, col, NULL); value_edit_cb = (IFniis)IupGetCallback(ih, "VALUE_EDIT_CB"); if (value_edit_cb) value_edit_cb(ih, lin, col, NULL); iupMatrixDrawCells(ih, lin, col, lin, col); } } } } break; } default: /* if a valid character is pressed enter edition mode */ if (iup_isprint(c)) { if (iupMatrixEditShow(ih)) { if (ih->data->datah == ih->data->texth) { char value[2] = {0,0}; value[0] = (char)c; IupStoreAttribute(ih->data->datah, "VALUE", value); IupSetAttribute(ih->data->datah, "CARET", "2"); } return IUP_IGNORE; /* do not redraw */ } } ret = IUP_DEFAULT; /* unprocessed keys */ break; } iupMatrixDrawUpdate(ih); return ret; }