📄 frm_driver.c
字号:
field->status |= _NEWTOP; } if (form->currow >= row_after_bottom) { form->toprow = form->currow - field->rows + 1; field->status |= _NEWTOP; } if (field->status & _NEWTOP) { /* means we have to copy whole range */ first_modified_row = form->toprow; first_unmodified_row = first_modified_row + field->rows; field->status &= ~_NEWTOP; } else { /* we try to optimize : finding the range of touched lines */ first_modified_row = form->toprow; while (first_modified_row < row_after_bottom) { if (is_linetouched(form->w, first_modified_row)) break; first_modified_row++; } first_unmodified_row = first_modified_row; while (first_unmodified_row < row_after_bottom) { if (!is_linetouched(form->w, first_unmodified_row)) break; first_unmodified_row++; } } } else { first_modified_row = form->toprow; first_unmodified_row = first_modified_row + field->rows; } if (first_unmodified_row != first_modified_row) copywin(form->w, formwin, first_modified_row, 0, field->frow + first_modified_row - form->toprow, field->fcol, field->frow + first_unmodified_row - form->toprow - 1, field->cols + field->fcol - 1, 0); } wsyncup(formwin); } else { /* if the field-window is simply a derived window, i.e. contains no * invisible parts, the whole thing is trivial */ wsyncup(form->w); } } untouchwin(form->w); returnCode(_nc_Position_Form_Cursor(form));}/*---------------------------------------------------------------------------| Facility : libnform| Function : static void Perform_Justification(| FIELD * field,| WINDOW * win)|| Description : Output field with requested justification|| Return Values : -+--------------------------------------------------------------------------*/static voidPerform_Justification(FIELD *field, WINDOW *win){ FIELD_CELL *bp; int len; int col = 0; bp = Get_Start_Of_Data(field->buf, Buffer_Length(field)); len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp); if (len > 0) { assert(win && (field->drows == 1) && (field->dcols == field->cols)); switch (field->just) { case JUSTIFY_LEFT: break; case JUSTIFY_CENTER: col = (field->cols - len) / 2; break; case JUSTIFY_RIGHT: col = field->cols - len; break; default: break; } wmove(win, 0, col); myADDNSTR(win, bp, len); }}/*---------------------------------------------------------------------------| Facility : libnform| Function : static void Undo_Justification(| FIELD * field,| WINDOW * win)|| Description : Display field without any justification, i.e.| left justified|| Return Values : -+--------------------------------------------------------------------------*/static voidUndo_Justification(FIELD *field, WINDOW *win){ FIELD_CELL *bp; int len; bp = Get_Start_Of_Data(field->buf, Buffer_Length(field)); len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp); if (len > 0) { assert(win); wmove(win, 0, 0); myADDNSTR(win, bp, len); }}/*---------------------------------------------------------------------------| Facility : libnform| Function : static bool Check_Char(| FIELDTYPE * typ,| int ch,| TypeArgument *argp)|| Description : Perform a single character check for character ch| according to the fieldtype instance.|| Return Values : TRUE - Character is valid| FALSE - Character is invalid+--------------------------------------------------------------------------*/static boolCheck_Char(FIELDTYPE *typ, int ch, TypeArgument *argp){ if (typ) { if (typ->status & _LINKED_TYPE) { assert(argp); return ( Check_Char(typ->left, ch, argp->left) || Check_Char(typ->right, ch, argp->right)); } else { if (typ->ccheck) return typ->ccheck(ch, (void *)argp); } } return (!iscntrl(UChar(ch)) ? TRUE : FALSE);}/*---------------------------------------------------------------------------| Facility : libnform| Function : static int Display_Or_Erase_Field(| FIELD * field,| bool bEraseFlag)|| Description : Create a subwindow for the field and display the| buffer contents (apply justification if required)| or simply erase the field.|| Return Values : E_OK - on success| E_SYSTEM_ERROR - some error (typical no memory)+--------------------------------------------------------------------------*/static intDisplay_Or_Erase_Field(FIELD *field, bool bEraseFlag){ WINDOW *win; WINDOW *fwin; if (!field) return E_SYSTEM_ERROR; fwin = Get_Form_Window(field->form); win = derwin(fwin, field->rows, field->cols, field->frow, field->fcol); if (!win) return E_SYSTEM_ERROR; else { if (field->opts & O_VISIBLE) Set_Field_Window_Attributes(field, win); else wattrset(win, getattrs(fwin)); werase(win); } if (!bEraseFlag) { if (field->opts & O_PUBLIC) { if (Justification_Allowed(field)) Perform_Justification(field, win); else Buffer_To_Window(field, win); } field->status &= ~_NEWTOP; } wsyncup(win); delwin(win); return E_OK;}/* Macros to preset the bEraseFlag */#define Display_Field(field) Display_Or_Erase_Field(field,FALSE)#define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)/*---------------------------------------------------------------------------| Facility : libnform| Function : static int Synchronize_Field(FIELD * field)|| Description : Synchronize the windows content with the value in| the buffer.|| Return Values : E_OK - success| E_BAD_ARGUMENT - invalid field pointer| E_SYSTEM_ERROR - some severe basic error+--------------------------------------------------------------------------*/static intSynchronize_Field(FIELD *field){ FORM *form; int res = E_OK; if (!field) return (E_BAD_ARGUMENT); if (((form = field->form) != (FORM *)0) && Field_Really_Appears(field)) { if (field == form->current) { form->currow = form->curcol = form->toprow = form->begincol = 0; werase(form->w); if ((field->opts & O_PUBLIC) && Justification_Allowed(field)) Undo_Justification(field, form->w); else Buffer_To_Window(field, form->w); field->status |= _NEWTOP; res = _nc_Refresh_Current_Field(form); } else res = Display_Field(field); } field->status |= _CHANGED; return (res);}/*---------------------------------------------------------------------------| Facility : libnform| Function : static int Synchronize_Linked_Fields(FIELD * field)|| Description : Propagate the Synchronize_Field function to all linked| fields. The first error that occurs in the sequence| of updates is the return value.|| Return Values : E_OK - success| E_BAD_ARGUMENT - invalid field pointer| E_SYSTEM_ERROR - some severe basic error+--------------------------------------------------------------------------*/static intSynchronize_Linked_Fields(FIELD *field){ FIELD *linked_field; int res = E_OK; int syncres; if (!field) return (E_BAD_ARGUMENT); if (!field->link) return (E_SYSTEM_ERROR); for (linked_field = field->link; linked_field != field; linked_field = linked_field->link) { if (((syncres = Synchronize_Field(linked_field)) != E_OK) && (res == E_OK)) res = syncres; } return (res);}/*---------------------------------------------------------------------------| Facility : libnform| Function : int _nc_Synchronize_Attributes(FIELD * field)|| Description : If a fields visual attributes have changed, this| routine is called to propagate those changes to the| screen.|| Return Values : E_OK - success| E_BAD_ARGUMENT - invalid field pointer| E_SYSTEM_ERROR - some severe basic error+--------------------------------------------------------------------------*/NCURSES_EXPORT(int)_nc_Synchronize_Attributes(FIELD *field){ FORM *form; int res = E_OK; WINDOW *formwin; T((T_CALLED("_nc_Synchronize_Attributes(%p)"), field)); if (!field) returnCode(E_BAD_ARGUMENT); CHECKPOS(field->form); if (((form = field->form) != (FORM *)0) && Field_Really_Appears(field)) { if (form->current == field) { Synchronize_Buffer(form); Set_Field_Window_Attributes(field, form->w); werase(form->w); wmove(form->w, form->currow, form->curcol); if (field->opts & O_PUBLIC) { if (Justification_Allowed(field)) Undo_Justification(field, form->w); else Buffer_To_Window(field, form->w); } else { formwin = Get_Form_Window(form); copywin(form->w, formwin, 0, 0, field->frow, field->fcol, field->rows - 1, field->cols - 1, 0); wsyncup(formwin); Buffer_To_Window(field, form->w); field->status |= _NEWTOP; /* fake refresh to paint all */ _nc_Refresh_Current_Field(form); } } else { res = Display_Field(field); } } CHECKPOS(form); returnCode(res);}/*---------------------------------------------------------------------------| Facility : libnform| Function : int _nc_Synchronize_Options(FIELD * field,| Field_Options newopts)|| Description : If a fields options have changed, this routine is| called to propagate these changes to the screen and| to really change the behavior of the field.|| Return Values : E_OK - success| E_BAD_ARGUMENT - invalid field pointer| E_SYSTEM_ERROR - some severe basic error+--------------------------------------------------------------------------*/NCURSES_EXPORT(int)_nc_Synchronize_Options(FIELD *field, Field_Options newopts){ Field_Options oldopts; Field_Options changed_opts; FORM *form; int res = E_OK; T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), field, newopts)); if (!field) returnCode(E_BAD_ARGUMENT); oldopts = field->opts; changed_opts = oldopts ^ newopts; field->opts = newopts; form = field->form; if (form) { if (form->current == field) { field->opts = oldopts; returnCode(E_CURRENT); } if (form->status & _POSTED) { if ((form->curpage == field->page)) { if (changed_opts & O_VISIBLE) { if (newopts & O_VISIBLE) res = Display_Field(field); else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -