⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_driver.c

📁 ncurses-5.4
💻 C
📖 第 1 页 / 共 5 页
字号:
/*---------------------------------------------------------------------------|   Facility      :  libnform  |   Function      :  static void Synchronize_Buffer(FORM * form)|   |   Description   :  If there was a change, copy the content of the|                    window into the buffer, so the buffer is synchronized|                    with the windows content. We have to indicate that the|                    buffer needs validation due to the change.||   Return Values :  -+--------------------------------------------------------------------------*/INLINE static void Synchronize_Buffer(FORM * form){  if (form->status & _WINDOW_MODIFIED)    {      form->status &= ~_WINDOW_MODIFIED;      form->status |=  _FCHECK_REQUIRED;      Window_To_Buffer(form->w,form->current);      wmove(form->w,form->currow,form->curcol);    }}/*---------------------------------------------------------------------------|   Facility      :  libnform  |   Function      :  static bool Field_Grown( FIELD *field, int amount)|   |   Description   :  This function is called for growable dynamic fields|                    only. It has to increase the buffers and to allocate|                    a new window for this field.|                    This function has the side effect to set a new|                    field-buffer pointer, the dcols and drows values|                    as well as a new current Window for the field.||   Return Values :  TRUE     - field successfully increased|                    FALSE    - there was some error+--------------------------------------------------------------------------*/static bool Field_Grown(FIELD * field, int amount){  bool result = FALSE;  if (field && Growable(field))    {      bool single_line_field = Single_Line_Field(field);      int old_buflen = Buffer_Length(field);      int new_buflen;      int old_dcols = field->dcols;      int old_drows = field->drows;      char *oldbuf  = field->buf;      char *newbuf;      int growth;      FORM *form = field->form;      bool need_visual_update = ((form != (FORM *)0)      &&				 (form->status & _POSTED) &&				 (form->current==field));            if (need_visual_update)	Synchronize_Buffer(form);            if (single_line_field)	{	  growth = field->cols * amount;	  if (field->maxgrow)	    growth = Minimum(field->maxgrow - field->dcols,growth);	  field->dcols += growth;	  if (field->dcols == field->maxgrow)	    field->status &= ~_MAY_GROW;	}      else	{	  growth = (field->rows + field->nrow) * amount;	  if (field->maxgrow)	    growth = Minimum(field->maxgrow - field->drows,growth);	  field->drows += growth;	  if (field->drows == field->maxgrow)	    field->status &= ~_MAY_GROW;	}      /* drows, dcols changed, so we get really the new buffer length */      new_buflen = Buffer_Length(field);      newbuf=(char *)malloc((size_t)Total_Buffer_Size(field));      if (!newbuf)	{ /* restore to previous state */	  field->dcols = old_dcols;	  field->drows = old_drows;	  if (( single_line_field && (field->dcols!=field->maxgrow)) ||	      (!single_line_field && (field->drows!=field->maxgrow)))	    field->status |= _MAY_GROW;	  return FALSE;	}      else	{ /* Copy all the buffers. This is the reason why we can't	     just use realloc().	     */	  int i;	  char *old_bp;	  char *new_bp;	  	  field->buf = newbuf;	  for(i=0;i<=field->nbuf;i++)	    {	      new_bp = Address_Of_Nth_Buffer(field,i);	      old_bp = oldbuf + i*(1+old_buflen);	      memcpy(new_bp,old_bp,(size_t)old_buflen);	      if (new_buflen > old_buflen)		memset(new_bp + old_buflen,C_BLANK,		       (size_t)(new_buflen - old_buflen));	      *(new_bp + new_buflen) = '\0';	    }	  if (need_visual_update)	    { 	      	      WINDOW *new_window = newpad(field->drows,field->dcols);	      if (!new_window)		{ /* restore old state */		  field->dcols = old_dcols;		  field->drows = old_drows;		  field->buf   = oldbuf;		  if (( single_line_field              && 			(field->dcols!=field->maxgrow)) ||		      (!single_line_field              && 		       (field->drows!=field->maxgrow)))		    field->status |= _MAY_GROW;		  free( newbuf );		  return FALSE;		}	      assert(form!=(FORM *)0);	      if (form->w)		delwin(form->w);	      form->w = new_window;	      Set_Field_Window_Attributes(field,form->w);	      werase(form->w);	      Buffer_To_Window(field,form->w);	      untouchwin(form->w);	      wmove(form->w,form->currow,form->curcol);	    }	  free(oldbuf);	  /* reflect changes in linked fields */	  if (field != field->link)	    {	      FIELD *linked_field;	      for(linked_field = field->link;		  linked_field!= field;		  linked_field = linked_field->link)		{		  linked_field->buf   = field->buf;		  linked_field->drows = field->drows;		  linked_field->dcols = field->dcols;		}	    }	  result = TRUE;	}	    }  return(result);}/*---------------------------------------------------------------------------|   Facility      :  libnform  |   Function      :  int _nc_Position_Form_Cursor(FORM * form)|   |   Description   :  Position the cursor in the window for the current|                    field to be in sync. with the currow and curcol |                    values.||   Return Values :  E_OK              - success|                    E_BAD_ARGUMENT    - invalid form pointer|                    E_SYSTEM_ERROR    - form has no current field or|                                        field-window+--------------------------------------------------------------------------*/NCURSES_EXPORT(int)_nc_Position_Form_Cursor (FORM * form){  FIELD  *field;  WINDOW *formwin;    if (!form)    return(E_BAD_ARGUMENT);  if (!form->w || !form->current)     return(E_SYSTEM_ERROR);  field    = form->current;  formwin  = Get_Form_Window(form);  wmove( form->w, form->currow, form->curcol );  if ( Has_Invisible_Parts(field) )    {      /* in this case fieldwin isn't derived from formwin, so we have	 to move the cursor in formwin by hand... */      wmove(formwin,	    field->frow + form->currow - form->toprow,	    field->fcol + form->curcol - form->begincol);      wcursyncup(formwin);    }  else     wcursyncup(form->w);  return(E_OK);}/*---------------------------------------------------------------------------|   Facility      :  libnform  |   Function      :  int _nc_Refresh_Current_Field(FORM * form)|   |   Description   :  Propagate the changes in the fields window to the|                    window of the form.||   Return Values :  E_OK              - on success|                    E_BAD_ARGUMENT    - invalid form pointer|                    E_SYSTEM_ERROR    - general error+--------------------------------------------------------------------------*/NCURSES_EXPORT(int)_nc_Refresh_Current_Field (FORM * form){  WINDOW *formwin;  FIELD  *field;  if (!form)    RETURN(E_BAD_ARGUMENT);  if (!form->w || !form->current)     RETURN(E_SYSTEM_ERROR);  field    = form->current;  formwin  = Get_Form_Window(form);  if (field->opts & O_PUBLIC)    {      if (Is_Scroll_Field(field))	{	  /* Again, in this case the fieldwin isn't derived from formwin,	     so we have to perform a copy operation. */	  if (Single_Line_Field(field))	    { /* horizontal scrolling */	      if (form->curcol < form->begincol)		  form->begincol = form->curcol;	      else		{		  if (form->curcol >= (form->begincol + field->cols))		      form->begincol = form->curcol - field->cols + 1;		}	      copywin(form->w,		      formwin,		      0,		      form->begincol,		      field->frow,		      field->fcol,		      field->frow,		      field->cols + field->fcol - 1,		      0);	    }	  else	    { /* A multi-line, i.e. vertical scrolling field */	      int row_after_bottom,first_modified_row,first_unmodified_row;	      if (field->drows > field->rows)		{		  row_after_bottom = form->toprow + field->rows;		  if (form->currow < form->toprow)		    {		      form->toprow = form->currow;		      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);  return _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 void Perform_Justification(FIELD  * field, WINDOW * win){  char *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);      waddnstr(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 void Undo_Justification(FIELD  * field, WINDOW * win){  char *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);      waddnstr(win,bp,len);    }}/*---------------------------------------------------------------------------|   Facility      :  libnform  |   Function      :  static bool Check_Char(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -