int iupMatrixKeyPress_CB(Ihandle* ih, int c, int press) { int oldc = c; IFniiiis cb; if (!iupMatrixIsValid(ih, 1)) return IUP_DEFAULT; if (!press) return IUP_DEFAULT; cb = (IFniiiis)IupGetCallback(ih, "ACTION_CB"); if (cb) { if (iup_isprint(c)) { char value[2]={0,0}; value[0] = (char)c; c = cb(ih, c, ih->data->lines.focus_cell, ih->data->columns.focus_cell, 0, value); } else { c = cb(ih, c, ih->data->lines.focus_cell, ih->data->columns.focus_cell, 0, iupMatrixCellGetValue(ih, ih->data->lines.focus_cell, ih->data->columns.focus_cell)); } if (c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE) return c; else if (c == IUP_DEFAULT) c = oldc; } if (c != K_HOME && c != K_sHOME) ih->data->homekeycount = 0; if (c != K_END && c != K_sEND) ih->data->endkeycount = 0; return iupMatrixProcessKeyPress(ih, c); }
static int iMatrixEditTextKeyAny_CB(Ihandle* ih_text, int c) { Ihandle* ih = ih_text->parent; IFniiiis cb = (IFniiiis) IupGetCallback(ih, "ACTION_CB"); if (cb && !iup_isprint(c)) /* only for keys that are NOT ASCii characters */ { int oldc = c; c = cb(ih, c, ih->data->edit_lin, ih->data->edit_col, 1, IupGetAttribute(ih_text, "VALUE")); if(c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE) return c; else if(c == IUP_DEFAULT) c = oldc; } switch (c) { case K_cUP: case K_cDOWN: case K_cLEFT: case K_cRIGHT: if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih, c); return IUP_IGNORE; } break; case K_UP: if (!IupGetInt(ih_text, "MULTILINE") || IupGetInt(ih_text, "CARET") == 1) /* if Multiline CARET will be "L,C" */ { /* if at the first line of the text */ if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih, c); return IUP_IGNORE; } } break; case K_DOWN: { /* if at the last line of the text */ if (!IupGetInt(ih_text, "MULTILINE") || IupGetInt(ih_text, "LINECOUNT") == IupGetInt(ih_text, "CARET")) /* if Multiline CARET will be "L,C" */ { if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih, c); return IUP_IGNORE; } } } break; case K_LEFT: if (IupGetInt(ih_text, "CARETPOS") == 0) { /* if at the first character */ if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih, c); return IUP_IGNORE; } } break; case K_RIGHT: { /* if at the last character */ if (IupGetInt(ih_text, "COUNT") == IupGetInt(ih_text, "CARETPOS")) { if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih, c); return IUP_IGNORE; } } } break; case K_ESC: iupMatrixEditAbort(ih); return IUP_IGNORE; /* always ignore to avoid the defaultesc behavior from here */ case K_CR: if (iupMatrixEditConfirm(ih) == IUP_DEFAULT) { if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Win32") && IupGetInt(ih_text, "MULTILINE")) { /* work around for Windows when using Multiline */ iupAttribSet(ih, "_IUPMAT_IGNORE_SHOW", "1"); } if (iupMatrixAuxCallLeaveCellCb(ih) != IUP_IGNORE) { iupMATRIX_ScrollKeyCr(ih); iupMatrixAuxCallEnterCellCb(ih); } iupMatrixDrawUpdate(ih); } return IUP_IGNORE; /* always ignore to avoid the defaultenter behavior from here */ } return IUP_CONTINUE; }
static int iMatrixEditTextKeyAny_CB(Ihandle* ih, int c) { Ihandle* ih_matrix = ih->parent; IFniiiis cb = (IFniiiis) IupGetCallback(ih_matrix, "ACTION_CB"); if (cb && !iup_isprint(c)) /* only for other keys that are not characters */ { int oldc = c; c = cb(ih_matrix, c, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, 1, IupGetAttribute(ih, "VALUE")); if(c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE) return c; else if(c == IUP_DEFAULT) c = oldc; } switch (c) { case K_cUP: case K_cDOWN: case K_cLEFT: case K_cRIGHT: if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih_matrix, c); return IUP_IGNORE; } break; case K_UP: if (IupGetInt(ih, "CARET") == 1) { /* if at the first line of the text */ if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih_matrix, c); return IUP_IGNORE; } } break; case K_DOWN: { char* value = IupGetAttribute(ih, "VALUE"); if (value) { /* if at the last line of the text */ if (iupStrLineCount(value) == IupGetInt(ih, "CARET")) { if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih_matrix, c); return IUP_IGNORE; } } } } break; case K_LEFT: if (IupGetInt(ih, "CARETPOS") == 0) { /* if at the first character */ if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih_matrix, c); return IUP_IGNORE; } } break; case K_RIGHT: { char* value = IupGetAttribute(ih, "VALUE"); if (value) { /* if at the last character */ if ((int)strlen(value) == IupGetInt(ih, "CARETPOS")) { if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { iupMatrixProcessKeyPress(ih_matrix, c); return IUP_IGNORE; } } } } break; case K_ESC: iMatrixEditCancel(ih_matrix, 1, 0, 0); /* set focus + NO update + NO ignore */ return IUP_IGNORE; /* always ignore to avoid the defaultesc behavior from here */ case K_CR: if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { if (iupStrEqualNoCase(IupGetGlobal("DRIVER"), "Win32") && IupGetInt(ih, "MULTILINE")) { /* work around for Windows when using Multiline */ iupAttribSetStr(ih_matrix, "_IUPMAT_IGNORE_SHOW", "1"); } if (iupMatrixAuxCallLeaveCellCb(ih_matrix) != IUP_IGNORE) { iupMATRIX_ScrollKeyCr(ih_matrix); iupMatrixAuxCallEnterCellCb(ih_matrix); } iupMatrixDrawUpdate(ih_matrix); } return IUP_IGNORE; /* always ignore to avoid the defaultenter behavior from here */ } return IUP_CONTINUE; }