void iupMatrixScrollMove(iupMatrixScrollMoveFunc func, Ihandle* ih, int mode, float pos, int m) { int old_lines_first = ih->data->lines.first; int old_columns_first = ih->data->columns.first; int old_lines_first_offset = ih->data->lines.first_offset; int old_columns_first_offset = ih->data->columns.first_offset; iupMatrixEditHide(ih); func(ih, mode, pos, m); if (ih->data->lines.first != old_lines_first || ih->data->lines.first_offset != old_lines_first_offset || ih->data->columns.first != old_columns_first || ih->data->columns.first_offset != old_columns_first_offset) { /* when "first" is changed must update scroll pos */ if (ih->data->columns.first != old_columns_first || ih->data->columns.first_offset != old_columns_first_offset) iupMatrixAuxUpdateScrollPos(ih, IMAT_PROCESS_COL); if (ih->data->lines.first != old_lines_first || ih->data->lines.first_offset != old_lines_first_offset) iupMatrixAuxUpdateScrollPos(ih, IMAT_PROCESS_LIN); iMatrixScrollCallScrollTopCb(ih); iupMatrixDraw(ih, 0); } }
static int iMatrixEditKillFocus_CB(Ihandle* ih_edit) { Ihandle* ih = ih_edit->parent; if (IupGetGlobal("MOTIFVERSION")) { if (iupAttribGet(ih, "_IUPMAT_DROPDOWN") || /* from iMatrixEditDropDown_CB, in Motif */ iupAttribGet(ih, "_IUPMAT_DOUBLECLICK")) /* from iMatrixMouseLeftPress, in Motif */ { iupAttribSet(ih, "_IUPMAT_DOUBLECLICK", NULL); iupAttribSet(ih, "_IUPMAT_DROPDOWN", NULL); return IUP_DEFAULT; } } if (iupAttribGet(ih, "_IUPMAT_IGNOREFOCUS")) return IUP_DEFAULT; if (ih->data->edit_hide_onfocus) { ih->data->edit_hidden_byfocus = 1; iupMatrixEditHide(ih); ih->data->edit_hidden_byfocus = 0; } else { IFn cb = (IFn)IupGetCallback(ih, "EDITKILLFOCUS_CB"); if (cb) cb(ih); } return IUP_DEFAULT; }
static int iMatrixEditDropDownKeyAny_CB(Ihandle* ih, int c) { Ihandle* ih_matrix = ih->parent; IFniiiis cb = (IFniiiis)IupGetCallback(ih_matrix, "ACTION_CB"); if (cb) { int oldc = c; c = cb(ih_matrix, c, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, 1, ""); if (c == IUP_IGNORE || c == IUP_CLOSE || c == IUP_CONTINUE) return c; else if(c == IUP_DEFAULT) c = oldc; } switch (c) { case K_CR: if (iupMatrixEditHide(ih_matrix) == IUP_DEFAULT) { if (iupMatrixAuxCallLeaveCellCb(ih_matrix) != IUP_IGNORE) { iupMATRIX_ScrollKeyCr(ih_matrix); iupMatrixAuxCallEnterCellCb(ih_matrix); } iupMatrixDrawUpdate(ih_matrix); return IUP_IGNORE; } break; case K_ESC: iMatrixEditCancel(ih_matrix, 1, 0, 0); /* set focus + NO update + NO ignore */ return IUP_IGNORE; } return IUP_CONTINUE; }
static int iMatrixSetEditModeAttrib(Ihandle* ih, const char* value) { if (iupStrBoolean(value)) iupMatrixEditShow(ih); else { iupMatrixEditHide(ih); iupMatrixDrawUpdate(ih); } return 1; }
static int iMatrixEditDropDownAction_CB(Ihandle* ih, char* t, int i, int v) { Ihandle* ih_matrix = ih->parent; IFniinsii cb = (IFniinsii)IupGetCallback(ih_matrix, "DROPSELECT_CB"); if(cb) { int ret = cb(ih_matrix, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, ih, t, i, v); /* If the user returns IUP_CONTINUE in a dropselect_cb the value is accepted and the matrix leaves edition mode. */ if (ret == IUP_CONTINUE) { iupMatrixEditHide(ih_matrix); iupMatrixDrawUpdate(ih_matrix); } } return IUP_DEFAULT; }
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; }
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; }