#include "declare.h"
//********************************************************
void edit_matrix(float **a,int ni,int nj,char x1,char y1,char ki,
                 char kj,char color,char color_frame)
{
 char far* vid;
 int i,j,i0,j0,n=11;
 char x,y,indi=2;
 char *buf;
 const char curs = 112;
 union keyb
 {
  int k;
  char ch[2];
 } key;
 union REGS r;
 buf = new char [12];
 i0 = j0 = 0;
 wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
 r.h.ah = 2;
 r.h.bh = 0;
 r.h.dh = 25;
 r.h.dl = x;
 int86(0x10,&r,&r);
 cursor(x1,y1,n,curs);
 x = x1;
 y = y1;
 i = j = 0;
 if(ni==1) indi = 0;       // строка? столбец?
  else if(nj==1) indi = 1; //  матрица?
 do
 {
  wr_koord(x1+1,y1-1,i,j,indi,color_frame);
  key.k = bioskey(0);
  switch(key.ch[1])
  {
   case 71:    //HOME
	   cursor(x,y,n,color);
	   x = x1;
	   y = y1;
	   cursor(x,y,n,curs);
	   i0 = j0 = i = j = 0;
	   wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	   cursor(x,y,n,curs);
	   break;
   case 79:    //END
	   cursor(x,y,n,color);
	   x = x1 + (n+2)*(kj-1);
	   y = y1 + ki - 1;
	   cursor(x,y,n,curs);
	   i = ni-1;
	   j = nj-1;
	   i0 = i - ki + 1;
	   j0 = j - kj + 1;
	   wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	   cursor(x,y,n,curs);
	   break;

   case 72: if(y != y1)     //вверх
	    {
	     cursor(x,y,n,color);
	     y--;
	     i--;
	     cursor(x,y,n,curs);
	    }
	    else
	     if(i)
	    {
	     i--;
	     i0--;
	     wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	     cursor(x,y,n,curs);
	    }
	   break;
   case 77: if(j-j0 != kj-1)     //право
	    {
	     cursor(x,y,n,color);
	     x = x + n + 2;
	     j++;
	     cursor(x,y,n,curs);
	    }
	    else
	     if(j<nj-1)
	    {
	     j++;
	     j0++;
	     wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	     cursor(x,y,n,curs);
	    }
	   break;
   case 80: if(i-i0 != ki-1)      //низ
	    {
	     cursor(x,y,n,color);
	     y++;
	     i++;
	     cursor(x,y,n,curs);
	    }
	    else
	     if(i<ni-1)
	    {
	     i++;
	     i0++;
	     wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	     cursor(x,y,n,curs);
	    }
	   break;
   case 75: if( x != x1)       // лево
	    {
	     cursor(x,y,n,color);
	     x = x - n - 2;
	     j--;
	     cursor(x,y,n,curs);
	    }
	    else
	     if(j)
	    {
	     j--;
	     j0--;
	     wr_sektor(a,i0,j0,ki,kj,x1,y1,color);
	     cursor(x,y,n,curs);
	    }
	   break;
   case 28: a[i][j] = edit_str(x,y,x+n);       //ввод
	    sprintf(buf,"%11.3e",a[i][j]);
	    menu(x,y,buf,curs);
	    break;
  }
 }
 while(key.ch[1] != 1);
 cursor(x,y,n,color);
 delete buf;
}
//********************************************************
void wr_sektor(float **a,int ii,int jj,char ki,char kj,char x1,char y1,
	       char color)
{
 int i,j;
 char x,y,*buf;
 char n=11;
 buf = new char[n+1];
 for(i=ii,y=y1;i<ii+ki;i++,y++)
 for(j=jj,x=x1;j<jj+kj;j++,x=x+n+2)
 {
   sprintf(buf,"%11.3e",a[i][j]);
   menu(x,y,buf,color);
 }
 delete buf;
}
//********************************************************
