T_FGP.CPP

 #include"VB_PRO~1\T_BGP.cpp"

int G_FLAG=0;
int M_FLAG=0;
struct GCELL
{
int C_LEFT;
int C_TOP;
int C_RIGHT;
int C_BOT;

int CFG;
int CBG;
int SETFLAG;
int C_MIDX;
int C_MIDY;
char C_DATA;

GCELL * nextgc;
GCELL * prevgc;
GCELL * upgc;
GCELL * downgc;
};

struct GROW
{
GCELL * grow;
GROW  * nextgr;
GROW  * prevgr;
};
/*
struct GROW_DIM
{
       int FC_left;
       int FC_top;
       int LC_right;
       int LC_bot;
}GRD[50];
*/
struct SCREEN_COL
{
CELL * sc_col;
SCREEN_COL * nextsc;
};
struct SCREEN_GCOL
{
GCELL * sc_gcol;
SCREEN_GCOL * nextgsc;
};

class TEXT_BOX_FGP: public TEXT_BOX_BGP
{
public:
GROW *firstgr;
GROW *lastgr;

GCELL * firstgc;
GCELL * lastgc;

GROW  * curgr;
GCELL * curgc;

GCELL * pregc;

SCREEN_COL * firstsc;
SCREEN_COL * lastsc;

int GCL;
int GRW;
int TB_LEFT;
int TB_TOP;
int TB_RIGHT;
int TB_BOT;

int TB_WIDTH;
int TB_HEIGHT;

int TB_CELL_WIDTH;
int TB_CELL_HEIGHT;

int NO_OF_CELL_INROW;
int NO_OF_CELL_INCOL;
int NO_OF_CELL;
// FONT SETTINGS
int ST_STYLE_F1;
int ST_STYLE_F2;
int ST_STYLE_F3;

int ST_USIZE_F1;
int ST_USIZE_F2;
int ST_USIZE_F3;
int ST_USIZE_F4;

int SCREEN_INC_BY;
int CURRENT_SC_VAL;

int FOCUS;
int W_FLAG;

// COLOR SETTINGS

int BG_COLOR;
int TEXT_COLOR;
int HIGHLIGHT_COLOR;

public:
TEXT_BOX_FGP(int TL,int TT,int TR,int TB,int f_style,int f_size,int bit_1,int bit_2,int bit_3,int bit_4):TEXT_BOX_BGP()
{
   TB_LEFT=TL;
   TB_TOP=TT;
   TB_RIGHT=TR;
   TB_BOT=TB;
// FONT SETTINGS
ST_STYLE_F1=f_style; //2
ST_STYLE_F2=0; //DIRECTION SHOULD BE 0
ST_STYLE_F3=f_size; //1

ST_USIZE_F1=bit_1; //2
ST_USIZE_F2=bit_2; //2
ST_USIZE_F3=bit_3; //6
ST_USIZE_F4=bit_4; //4


   //settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   //setusercharsize(4,4,8,8);
   settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   setusercharsize(ST_USIZE_F1,ST_USIZE_F2,ST_USIZE_F3,ST_USIZE_F4);

   TB_CELL_WIDTH=textwidth("m");
   TB_CELL_HEIGHT=1+textheight("H")+1;

   TB_WIDTH=(TB_RIGHT-TB_LEFT);//-20;
   TB_HEIGHT=(TB_BOT-TB_TOP);//-20;
   if(TB_HEIGHT<=TB_CELL_WIDTH)
{
TB_BOT+=TB_TOP+TB_CELL_HEIGHT+5;
TB_HEIGHT=(TB_BOT-TB_TOP);
}

   NO_OF_CELL_INROW=int(TB_WIDTH/(1+TB_CELL_WIDTH));
   NO_OF_CELL_INCOL=int(TB_HEIGHT/(1+TB_CELL_HEIGHT));

   NO_OF_CELL=NO_OF_CELL_INCOL * NO_OF_CELL_INROW;
//---------------------------------------------------------------------------
   BG_COLOR=BLUE;
   TEXT_COLOR=WHITE;
   HIGHLIGHT_COLOR=GREEN;
   // ^------------------ COLOR SETTINGS
   firstgr=NULL;
   firstgc=NULL;
   GCL=1;
   GRW=1;
   TB_RAW_PAINT();
   curgr=firstgr;
   curgc=curgr->grow;
   curr=firstr;
   curc=curr->row;
   //pregc=curgc;
   SCREEN_ROW=curr;
   SCREEN_CELL=curr->row;
   GCL=1;GRW=1;
   SCREEN_INC_BY=5;
   CURRENT_SC_VAL=1;
   count=260;



if(NO_OF_CELL_INCOL>1)
SET_UP_DOWN_GC(firstgr);
TEXTBOX_PRINT(curgr,SCREEN_ROW,CURRENT_SC_VAL);
curgr=firstgr;
curgc=curgr->grow;
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
FOCUS=1;
}
void TB_RAW_PAINT();
void ROW_PRINT(GROW * cgr,ROW * cr,int start_col);
void TEXTBOX_PRINT(GROW * fgr,ROW * fr,int start_col);
CELL * GOTO_CELL_MPTR(int x1,int y1,int x2,int y2);

GCELL * G_UP_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);
GCELL * G_DOWN_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);
GCELL * G_LEFT_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc);
GCELL * G_RIGHT_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc);
GCELL * G_CURSOR(GCELL * cgc,GCELL * pgc,int mode);
GCELL * G_ENTER_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);
GCELL * G_ADD_CELL(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl,char val);

GCELL * G_SCROLL_UP(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_ROW);
GCELL * G_SCROLL_DOWN(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_ROW);
GCELL * G_SCROLL_LEFT(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_COL);
GCELL * G_SCROLL_RIGHT(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_COL);

GCELL * G_DEL_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);
GCELL * G_BACKSPACE_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);
GCELL * G_HOME_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl);

void SET_UP_DOWN_GC(GROW * fgr);
int PROCESS();
void MOUSE_SELECT(int x1,int y1,int x2,int y2);
void SET_FOCUS();
void LOST_FOCUS();
void GET_TEXT_SETTINGS();

};

void TEXT_BOX_FGP::TB_RAW_PAINT()
{
//    int temp_left,temp_top,temp_right,temp_bot;
    firstgr=NULL;
    firstgc=NULL;
    //setcolor(4);
    //rectangle(TB_LEFT,TB_TOP,TB_RIGHT,TB_BOT);
  setcolor(15);
  int cx=TB_LEFT+1,cy=TB_TOP+1;
  for(int i=1;i<=NO_OF_CELL_INCOL;i++)
{
   for(int j=1;j<=NO_OF_CELL_INROW;j++)
{
    //rectangle(cx,cy,cx+TB_CELL_WIDTH,cy+TB_CELL_HEIGHT);
    GCELL * newgc=new GCELL;

    newgc->C_LEFT=cx;
    newgc->C_TOP=cy;
    newgc->C_RIGHT=cx+TB_CELL_WIDTH;
    newgc->C_BOT=cy+TB_CELL_HEIGHT;
    newgc->C_MIDX=newgc->C_LEFT+(newgc->C_RIGHT-newgc->C_LEFT)/2;
    newgc->C_MIDY=newgc->C_TOP+(newgc->C_BOT-newgc->C_TOP)/2;
    newgc->CFG=15;
    newgc->CBG=1;
    newgc->SETFLAG=0;

    newgc->C_DATA=' ';
    newgc->nextgc=NULL;
    newgc->prevgc=NULL;
    newgc->upgc=NULL;
    newgc->downgc=NULL;

    if(firstgc==NULL)
{
firstgc=newgc;
lastgc=firstgc;
}
   else
{
  lastgc->nextgc=newgc;
  lastgc->nextgc->prevgc=lastgc;
  lastgc=newgc;
}
if((firstgr!=NULL)&&(j==1)&&(i!=1))
      {
GROW * newgr=new GROW;
newgr->grow=newgc;
newgr->nextgr=NULL;
newgr->prevgr=NULL;
lastgr->nextgr=newgr;
lastgr->nextgr->prevgr=lastgr;
lastgr=newgr;
      }
if((firstgr==NULL)&&(i==1))
      {
GROW * newgr=new GROW;
newgr->grow=newgc;
newgr->nextgr=NULL;
newgr->prevgr=NULL;
firstgr=newgr;
lastgr=firstgr;

      }

  /*     if(j==1)
{
  temp_left=cx;
  temp_top=cy;
}
    if(j==NO_OF_CELL_INROW)
{
  temp_right=cx+TB_CELL_WIDTH;
  temp_bot=cy+TB_CELL_HEIGHT;
}                       */
    cx=cx+TB_CELL_WIDTH+1;
}
   /////////////
   /*    GRD[i].FC_left=temp_left;
   GRD[i].FC_top=temp_top;
   GRD[i].LC_right=temp_right;
   GRD[i].LC_bot=temp_bot;     */
   /////////////
   cx=TB_LEFT+1;
   cy=cy+TB_CELL_HEIGHT+1;
}
    setcolor(15);
    rectangle(TB_LEFT,TB_TOP,TB_RIGHT,TB_BOT);
    setfillstyle(1,BG_COLOR);
    floodfill(TB_LEFT+5,TB_TOP+2,15);
/*    //rectangle(GRD[3].FC_left,GRD[3].FC_top,GRD[3].LC_right,GRD[3].LC_bot);
    //setcolor(15);
    //outtextxy(firstgr->grow->C_LEFT+2,firstgr->grow->C_TOP+1,"A");
*/
}
void TEXT_BOX_FGP::ROW_PRINT(GROW * cgr,ROW * cr,int start_col)
{
GCELL * tgc;
CELL * tc;
tgc=cgr->grow;
tc=cr->row;
if(start_col>1)
     {
for(int inc=1;inc<start_col;inc++)
tc=tc->nextc;

     }

char temp[2];
   settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   setusercharsize(ST_USIZE_F1,ST_USIZE_F2,ST_USIZE_F3,ST_USIZE_F4);
   settextjustify(CENTER_TEXT,CENTER_TEXT);

setviewport(0,0,getmaxx(),getmaxy(),1);
hidemouseptr();
for(int i=1;i<=NO_OF_CELL_INROW;i++)
     {
       setviewport(tgc->C_LEFT,tgc->C_TOP,tgc->C_RIGHT,tgc->C_BOT,1);
       clearviewport();
       setfillstyle(1,BG_COLOR);
       floodfill(2,2,15);
       setcolor(TEXT_COLOR);
if(tc!=NULL)
     {
       temp[0]=tc->data;
       temp[1]='\0';
       outtextxy((TB_CELL_WIDTH)/2,(TB_CELL_HEIGHT)/2,temp);
       tgc->C_DATA=tc->data;
       tc=tc->nextc;
     }
else
     {
       temp[0]=' ';
       temp[1]='\0';
       outtextxy((TB_CELL_WIDTH)/2,(TB_CELL_HEIGHT)/2,temp);
       tgc->C_DATA=' ';
     }
       tgc=tgc->nextgc;
     setviewport(0,0,getmaxx(),getmaxy(),1);
      }
setviewport(0,0,getmaxx(),getmaxy(),1);
tgc=NULL;
tc=NULL;
showmouseptr();
}

void TEXT_BOX_FGP::TEXTBOX_PRINT(GROW * fgr,ROW * fr,int start_col)
{
GCELL * tgc;
CELL  * tc;

GROW * tgr;
ROW * tr;
char temp[2];
/*
tgc=fgr->grow;
setcolor(15);
rectangle(TB_LEFT,TB_TOP,TB_RIGHT,TB_BOT);    // <- ALTERNATIVE 1
setfillstyle(0,1);
floodfill(TB_LEFT+2,TB_TOP+2,15);
*/
/*
setviewport(TB_LEFT,TB_TOP,TB_RIGHT,TB_BOT,1);
clearviewport();
setfillstyle(1,1);                            // <- ALTERNATIVE 2
floodfill(TB_LEFT+2,TB_TOP+2,15);

*/
setviewport(0,0,getmaxx(),getmaxy(),1);

tgc=fgr->grow;
tc=fr->row;

if(start_col>1)
     {
for(int inc=1;inc<start_col;inc++)
tc=tc->nextc;
//cl=cl+start_col-1;
     }

tgr=fgr;
tr=fr;
   settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   setusercharsize(ST_USIZE_F1,ST_USIZE_F2,ST_USIZE_F3,ST_USIZE_F4);
   settextjustify(CENTER_TEXT,CENTER_TEXT);
hidemouseptr();
while((tgc!=NULL))
     {
       setviewport(tgc->C_LEFT,tgc->C_TOP,tgc->C_RIGHT,tgc->C_BOT,1);
       clearviewport();               // <- FLOWING STYLE
       setfillstyle(1,BG_COLOR);
       floodfill(2,2,15);             // <- ALTERNATIVE 3  COMM 2
       setcolor(TEXT_COLOR);
       if(tc!=NULL)
   {
      temp[0]=tc->data;
      temp[1]='\0';
      tgc->C_DATA=tc->data;
      tc=tc->nextc;

   }
       else
   {  temp[0]=' ';
      temp[1]='\0';
      tgc->C_DATA=' ';
   }
       outtextxy((TB_CELL_WIDTH)/2,(TB_CELL_HEIGHT)/2,temp);
       tgc=tgc->nextgc;
       if((tgc==tgr->nextgr->grow)&&(tgr->nextgr!=NULL))
      {
if(tr->nextr!=NULL)
     {
tr=tr->nextr;
tc=tr->row;
if(start_col>1)
{
for(int inc=1;inc<start_col;inc++)
tc=tc->nextc;

}

     }
else
     tc=NULL;
tgr=tgr->nextgr;
      }
      setviewport(0,0,getmaxx(),getmaxy(),1);
      }
//*/
/*
int j=1;
while(fgr!=NULL)
{                             // <- ALTERNATIVE 4 TRUE SPEED
    ROW_PRINT(fgr,j,temp);
    fgr=fgr->nextgr;
    j++;
}
*/

/*
   int j=1;
   while(fgr!=NULL)
   {
     tgc=fgr->grow;
     setviewport(GRD[j].FC_left,GRD[j].FC_top,GRD[j].LC_right,GRD[j].LC_bot,1);
     clearviewport();

for(int i=1;i<=NO_OF_CELL_INROW;i++)
     {
setviewport(tgc->C_LEFT,tgc->C_TOP,tgc->C_RIGHT,tgc->C_BOT,1);
setfillstyle(1,1);
floodfill(2,2,15);
setcolor(15);          // <- ALTERNATIVE 5 TRUE SPEED
outtextxy(2,1,temp);
tgc=tgc->nextgc;       // SAVES FUNCTION SWITCHING TIME
      }
    fgr=fgr->nextgr;
    j++;
    }
*/
setviewport(0,0,getmaxx(),getmaxy(),1);
tgc=NULL;
tc=NULL;
tgr=NULL;
tr=NULL;
showmouseptr();
}
GCELL * TEXT_BOX_FGP::G_UP_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
CELL *tc;

if(cr->prevr!=NULL)
       {
int tcl=1; int P_FLAG=0,W_FLAG=0;
tc=cr->prevr->row;
   while(tc->nextc!=NULL)
   {
     tc=tc->nextc;
     tcl++;
   }
   if((tcl<=CURRENT_SC_VAL))   // remove =
       P_FLAG=1;
   else if((tcl>CURRENT_SC_VAL)&&(tcl<cl))
       P_FLAG=2;
   else    // if(tcl>=cl)
      {
if((tcl>=cl))
P_FLAG=3;
      }


       if((P_FLAG==1))
   {
      CURRENT_SC_VAL=1;
      curc=tc;
      if(cgr->prevgr!=NULL)
      {
      curgr=curgr->prevgr;
      curgc=curgr->grow;

      }
      else
      {
      curgc=curgr->grow;
      SCREEN_ROW=SCREEN_ROW->prevr;
      }
       prevcl=tcl;
       cl=tcl;
       curr=curr->prevr;

      tc=curr->row;
      while(tc->nextc!=NULL)
     {
tc=tc->nextc;
curgc=curgc->nextgc;
     }
       cgc=curgc;
       GCL=tcl;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

   }
       if(P_FLAG==2)
   {
      CURRENT_SC_VAL=tcl;
      curc=tc;
      GCL=1;
      if(cgr->prevgr!=NULL)
      {
      curgr=curgr->prevgr;
      curgc=curgr->grow;

      }
      else
      {
      curgc=curgr->grow;
      SCREEN_ROW=SCREEN_ROW->prevr;
      }
      for(int inc=1;inc<5;inc++)
  {
CURRENT_SC_VAL-=1;
curgc=curgc->nextgc;
GCL++;
  }
       prevcl=tcl;
       cl=tcl;
       curr=curr->prevr;
       cgc=curgc;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

   }
       if(P_FLAG==3)
   {

CURRENT_SC_VAL=CURRENT_SC_VAL;
tc=curr->prevr->row;
      if(cgr->prevgr!=NULL)
      {
      curgr=curgr->prevgr;
      }
      else
      {
      SCREEN_ROW=SCREEN_ROW->prevr;
      W_FLAG=1;
      }
for(int inc=1;inc<cl;inc++)
      {
  tc=tc->nextc;
      }
if(curgc->upgc!=NULL)
curgc=curgc->upgc;
curc=tc;
curr=curr->prevr;
prevcl=cl;
GCL=GCL;
cgc=curgc;
       if(W_FLAG)
       {
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;
       }
   }
     //  W
       }


/*       if(cr->prevr!=NULL)
     {
tc=cr->prevr->row;
curc=UP_KEY(curr,curc);      // SCROLL FIRST
   if(curgr->prevgr!=NULL)
      {
curgr=cgr->prevgr;
// cgc=curgr->grow;
if(prevcl>cl)   // if(GCL>cl)
   {
int tcl=1;
cgc=curgr->grow;
while(tc->nextc!=NULL)
{
tc=tc->nextc;
cgc=cgc->nextgc;
tcl++;
}
GCL=tcl;

    }
else
    {
if(cgc->upgc!=NULL)
{
cgc=cgc->upgc;
}

    }
    GRW--;


      }
else
     {
       curgc=G_SCROLL_UP(curgr,curgc,curr,curc,1);
       cgc=curgc;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

     }

     }    */
tc=NULL;
return cgc;
}
GCELL * TEXT_BOX_FGP::G_DOWN_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
CELL * tc;

if(cr->nextr!=NULL)
       {
int tcl=1; int P_FLAG=0,W_FLAG=0;

tc=cr->nextr->row;
   while(tc->nextc!=NULL)
   {
     tc=tc->nextc;
     tcl++;
   }
   if((tcl<=CURRENT_SC_VAL))    // remove =
       P_FLAG=1;
   else if((tcl>CURRENT_SC_VAL)&&(tcl<cl))
       P_FLAG=2;
   else    // if(tcl>=cl)
      {
if((tcl>=cl))
P_FLAG=3;
      }
       if((P_FLAG==1))
   {
      CURRENT_SC_VAL=1;
      curc=tc;
      if(cgr->nextgr!=NULL)
      {
      curgr=curgr->nextgr;
      curgc=curgr->grow;

      }
      else
      {
      curgc=curgr->grow;
      SCREEN_ROW=SCREEN_ROW->nextr;
      }
       prevcl=tcl;
       cl=tcl;
       curr=curr->nextr;

      tc=curr->row;
      while(tc->nextc!=NULL)
     {
tc=tc->nextc;
curgc=curgc->nextgc;
     }
       cgc=curgc;
       GCL=tcl;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

   }
       if(P_FLAG==2)
   {
      CURRENT_SC_VAL=tcl;
      curc=tc;
      GCL=1;
      if(cgr->nextgr!=NULL)
      {
      curgr=curgr->nextgr;
      curgc=curgr->grow;

      }
      else
      {
      curgc=curgr->grow;
      SCREEN_ROW=SCREEN_ROW->nextr;
      }
      for(int inc=1;inc<5;inc++)
  {
CURRENT_SC_VAL-=1;
curgc=curgc->nextgc;
GCL++;
  }
       prevcl=tcl;
       cl=tcl;
       curr=curr->nextr;
       cgc=curgc;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

   }
       if(P_FLAG==3)
   {
CURRENT_SC_VAL=CURRENT_SC_VAL;
tc=curr->nextr->row;
      if(cgr->nextgr!=NULL)
      {
      curgr=curgr->nextgr;
      }
      else
      {
      SCREEN_ROW=SCREEN_ROW->nextr;
       W_FLAG=1;
      }
for(int inc=1;inc<cl;inc++)
      {
  tc=tc->nextc;

      }
if(curgc->downgc!=NULL)
curgc=curgc->downgc;
curc=tc;
curr=curr->nextr;
prevcl=cl;
GCL=GCL;
cgc=curgc;
       if(W_FLAG)
       {
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;
       }
   }
     //  W
       }
/*       if(cr->nextr!=NULL)
     {                                  // SCROLL FIRST
tc=cr->nextr->row;
curc=DOWN_KEY(curr,curc);

if(curgr->nextgr!=NULL)
     {
curgr=cgr->nextgr;
if(prevcl>cl)
  {
cgc=curgr->grow;
int tcl=1;
while(tc->nextc!=NULL)
{

tc=tc->nextc;
cgc=cgc->nextgc;
tcl++;
}
GCL=tcl;
  }
else
  {
if(cgc->downgc!=NULL)
cgc=cgc->downgc;
  }
GRW++;
////
     }
else
     {
       curgc=G_SCROLL_DOWN(curgr,curgc,curr,curc,1);
       cgc=curgc;
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

     }
     }           // IF TCL => CURRENT PRINT FROM CURRENT
*/ // ELSE SET CURRENT = MOVE BACKWARD FIVE CELLS
tc=NULL;
return cgc;
}

GCELL * TEXT_BOX_FGP::G_LEFT_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc)
{
if(cc->prevc!=NULL)
    {

if((cgc==cgr->grow))
    {
       int tcl=cl;
       for(int inc=1;inc<5;inc++)
{
if(curc->prevc!=NULL)
{
curc=LEFT_KEY(curr,curc);          // SCROLL FIRST
if(curgc->nextgc!=NULL)
curgc=curgc->nextgc;

CURRENT_SC_VAL-=1;
GCL+=1;

}

}
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
curc=cc;
cl=tcl;
cgc=curgc;
    }
else
{
   if(cc->prevc!=NULL)
       {      // SCROLL FIRST
curc=LEFT_KEY(cr,cc);
if(cgc!=cgr->grow)
{
cgc=cgc->prevgc;
GCL--;
}
       }
}




       }


return cgc;
}

GCELL * TEXT_BOX_FGP::G_RIGHT_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc)
{
if(cc->nextc!=NULL)
    {

if((cgc->nextgc==cgr->nextgr->grow)||(cgc->nextgc==NULL))
    {
       int tcl=cl;
       for(int inc=1;inc<5;inc++)
{
if(curc->nextc!=NULL)
{
curc=RIGHT_KEY(curr,curc);          // SCROLL FIRST
if(curgc->prevgc!=NULL)
curgc=curgc->prevgc;

CURRENT_SC_VAL+=1;
GCL-=1;

}

}
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
curc=cc;
cl=tcl;
cgc=curgc;
    }
else
{
curc=RIGHT_KEY(cr,cc);          // SCROLL FIRST
if(cgc->nextgc!=cgr->nextgr->grow)
    {
cgc=cgc->nextgc;        // TO BE TESTED
GCL++;
    }
}
    }
return cgc;

}
GCELL * TEXT_BOX_FGP::G_CURSOR(GCELL * cgc,GCELL * pgc,int mode)
{

if(mode==1)
{
setwritemode(1);
       setcolor(15);
       line(pgc->C_LEFT,pgc->C_BOT,pgc->C_RIGHT,pgc->C_BOT);
}
       setcolor(15);
       line(cgc->C_LEFT,cgc->C_BOT,cgc->C_RIGHT,cgc->C_BOT);
if(mode==1)
setwritemode(0);
       pgc=cgc;
return pgc;
///
}
GCELL * TEXT_BOX_FGP::G_ENTER_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
       curc=ENTER_KEY(cr,cc,cl);
       if(cgr->nextgr==NULL)
       {
       cgc=G_SCROLL_DOWN(curgr,curgc,curr,curc,1);
       }
       else
       {
       cgr=cgr->nextgr;
       GRW++;
       }
       cgc=cgr->grow;
       curgr=cgr;

       GCL=1;
return cgc;
}
GCELL * TEXT_BOX_FGP::G_ADD_CELL(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl,char val)
{
   if((curgc->nextgc==curgr->nextgr->grow)||(curgc->nextgc==NULL))
{
  CURRENT_SC_VAL+=(NO_OF_CELL_INROW/2);
for(int dec=1;dec<(NO_OF_CELL_INROW/2);dec++)
curgc=curgc->prevgc;
cgc=curgc;
GCL-=(NO_OF_CELL_INROW/2);
       TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
       //delay(5);
       pregc=G_CURSOR(curgc,pregc,0);
       G_FLAG=1;

}
   else
{
   cgc=cgc->nextgc;
   GCL++;
}
   curc=ADD_CELL(cr,cc,cl,val);
return cgc;
}
GCELL * TEXT_BOX_FGP::G_SCROLL_UP(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_ROW)
{
///////////////
    if((SCREEN_ROW->prevr!=NULL))
      {                                  // UP_DOWN VERSION_01 CURRENT
if(SC_ROW==1)
    {
      CELL * tc;
      tc=cr->row;
      SCREEN_ROW=SCREEN_ROW->prevr;
//////////////
if(GCL>cl)
  {
cgc=curgr->grow;
int tcl=1;
while(tc->nextc!=NULL)
{

tc=tc->nextc;
cgc=cgc->nextgc;
tcl++;
}
GCL=tcl;
  }
       tc=NULL;
//////////////////

     }
       }
return cgc;

/////////////////

}

GCELL * TEXT_BOX_FGP::G_SCROLL_DOWN(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int SC_ROW)
{
    if((SCREEN_ROW->nextr!=NULL))
      {                                  // UP_DOWN VERSION_01 CURRENT
if(SC_ROW==1)
    {
      CELL * tc;
      tc=cr->row;
      SCREEN_ROW=SCREEN_ROW->nextr;
//////////////
if(GCL>cl)
  {
cgc=curgr->grow;
int tcl=1;
while(tc->nextc!=NULL)
{

tc=tc->nextc;
cgc=cgc->nextgc;
tcl++;
}
GCL=tcl;
  }

//////////////////
       tc=NULL;
     }
       }
return cgc;

}
void TEXT_BOX_FGP::SET_UP_DOWN_GC(GROW * fgr)
{
//SETTING DOWN
/*
SCREEN_GCOL * fgsc=new SCREEN_GCOL;
SCREEN_GCOL * lgsc=new SCREEN_GCOL;
fgsc=NULL;
      while(fgr!=NULL)
    {
SCREEN_GCOL * newgsc=new SCREEN_GCOL;
newgsc->sc_gcol=fgr->grow;
newgsc->nextgsc=NULL;
  if(fgsc==NULL)
       {
fgsc=newgsc;
lgsc=fgsc;
       }
  else
       {
lgsc->nextgsc=newgsc;
lgsc=newgsc;
       }
  fgr=fgr->nextgr;
    }

SCREEN_GCOL * tgsc=new SCREEN_GCOL;
*/
GCELL * primary_cell;
GCELL * secondry_cell;
GROW *  primary_row;
GROW *  secondry_row;

SCREEN_GCOL * newgsc;

fgr=firstgr;
primary_row=fgr;
secondry_row=fgr->nextgr;
primary_cell=primary_row->grow;

while(primary_cell!=primary_row->nextgr->grow)
   {
primary_cell->upgc=NULL;
primary_cell=primary_cell->nextgc;
   }
primary_cell=primary_row->grow;
while(primary_row->nextgr!=NULL)
   {
primary_cell=primary_row->grow;
secondry_cell=secondry_row->grow;

while((primary_cell!=secondry_row->grow))
    {
primary_cell->downgc=secondry_cell;
secondry_cell->upgc=primary_cell;

primary_cell=primary_cell->nextgc;
secondry_cell=secondry_cell->nextgc;
    }
primary_row=primary_row->nextgr;
secondry_row=secondry_row->nextgr;

   }
primary_cell=secondry_row->grow;
while(primary_cell!=NULL)
   {
primary_cell->downgc=NULL;
primary_cell=primary_cell->nextgc;
   }
/*tgsc=fgsc;
gotoxy(10,10);
primary_row=fgr;
GCELL * tgc=new GCELL;
tgc=fgr->nextgr->grow;
int count=1; setcolor(4);
while(tgc!=fgr->nextgr->nextgr->grow)
{
   rectangle(tgc->downgc->C_LEFT,tgc->downgc->C_TOP,tgc->downgc->C_RIGHT,tgc->downgc->C_BOT);
   tgc=tgc->nextgc;
   count++;
}
cout<<count;
*/
primary_cell=NULL;
secondry_cell=NULL;
primary_row=NULL;
secondry_row=NULL;
newgsc=NULL;

}
GCELL * TEXT_BOX_FGP::G_DEL_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
    curc=DEL_KEY(cr,cc,cl);
return cgc;
}
GCELL * TEXT_BOX_FGP::G_BACKSPACE_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
     W_FLAG=0;
     if((curgc==curgr->grow)&&(cl>1))
     return cgc;
     if((curgc==curgr->grow)&&(cl==1)&&(curgc->upgc!=NULL))
{
int tcl=1;
CELL * tc;
tc=cr->prevr->row;
while(tc->nextc!=NULL)
{
  tc=tc->nextc;
  tcl++;
}
CURRENT_SC_VAL=tcl-5;

curc=BACKSPACE_KEY(cr,cc,cl);
cgc=cgr->prevgr->grow;
for(int inc=1;inc<=5;inc++)
cgc=cgc->nextgc;
curgr=curgr->prevgr;
GCL=6;
GRW=GRW-1;
W_FLAG=1;
cl=tcl;
tc=NULL;
return cgc;           // NEEDS TO BE IMPLEMENTED
}
     curc=BACKSPACE_KEY(cr,cc,cl);
     if(cgc->prevgc!=NULL)
{
cgc=cgc->prevgc;
GCL--;
}
return cgc;
}
GCELL * TEXT_BOX_FGP::G_HOME_KEY(GROW * cgr,GCELL * cgc,ROW * cr,CELL * cc,int gcl)
{
  curc=HOME_KEY(cr,cc);
  cgc=cgr->grow;
  CURRENT_SC_VAL=1;
  GCL=1;
  return cgc;
}
void TEXT_BOX_FGP::MOUSE_SELECT(int x1,int y1,int x2,int y2)
{
GCELL * fgc;
fgc=firstgr->grow;
char temp[2];
   settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   setusercharsize(ST_USIZE_F1,ST_USIZE_F2,ST_USIZE_F3,ST_USIZE_F4);
   settextjustify(CENTER_TEXT,CENTER_TEXT);
   hidemouseptr();
   while(fgc!=NULL)
  {
     if((fgc->C_MIDX>x1)&&(fgc->C_MIDY>y1)&&(fgc->C_MIDX<x2)&&(fgc->C_MIDY<y2)) //&&(fgc->SETFLAG==0))
    {
if((fgc->SETFLAG==0))
{
setviewport(fgc->C_LEFT,fgc->C_TOP,fgc->C_RIGHT,fgc->C_BOT,1);
clearviewport();
setfillstyle(1,HIGHLIGHT_COLOR);
floodfill(2,2,15);
setcolor(TEXT_COLOR);
temp[0]=fgc->C_DATA;
temp[1]='\0';
outtextxy((TB_CELL_WIDTH)/2,(TB_CELL_HEIGHT)/2,temp);
fgc->SETFLAG=1;
M_FLAG=1;

}
    }
     else
    {
if(fgc->SETFLAG==1)
{
setviewport(fgc->C_LEFT,fgc->C_TOP,fgc->C_RIGHT,fgc->C_BOT,1);
clearviewport();
setfillstyle(1,BG_COLOR);
floodfill(2,2,15);
setcolor(TEXT_COLOR);
temp[0]=fgc->C_DATA;
temp[1]='\0';
outtextxy((TB_CELL_WIDTH)/2,(TB_CELL_HEIGHT)/2,temp);
fgc->SETFLAG=0;
}
    }


      fgc=fgc->nextgc;
  }
  showmouseptr();
fgc=NULL;

}

int TEXT_BOX_FGP::PROCESS()
{
int button,x,kbkey,y,done=0;
getmousepos(&button,&x,&y);
if((button&1==1))
      {
   if((x>TB_LEFT)&&(y>TB_TOP)&&(x<TB_RIGHT)&&(y<TB_BOT))
     {
      if(FOCUS==0)
{
   SET_FOCUS();
   *(&button)=0;
}
     }
   else
     {
       if(FOCUS==1)
{
   LOST_FOCUS();
   *(&button)=0;
}
     }
     }



if(FOCUS==1)
   {

      if(bioskey(1)!=0)
{
kbkey=bioskey(0);
if(M_FLAG==1)
{
MOUSE_SELECT(TB_LEFT,TB_TOP,TB_LEFT+1,TB_TOP+1);
M_FLAG=0;
ROW_PRINT(curgr,curr,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}

     if(kbkey==283)
  {
  done=1;
  return done;
  }
     if(kbkey==LEFT)
curgc=G_LEFT_KEY(curgr,curgc,curr,curc);
     if(kbkey==RIGHT)
curgc=G_RIGHT_KEY(curgr,curgc,curr,curc);
     if(kbkey==DOWN)
curgc=G_DOWN_KEY(curgr,curgc,curr,curc,GCL);
     if(kbkey==UP)
curgc=G_UP_KEY(curgr,curgc,curr,curc,GCL);
     if(kbkey==HOME)
{
curgc=G_HOME_KEY(curgr,curgc,curr,curc,GCL);
TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}
     if(((isalnum(toascii(kbkey)))||(isspace(toascii(kbkey)))||(ispunct(toascii(kbkey))))&&(kbkey!=ENTER)&&(LIMIT_FLAG==0))
{
curgc=G_ADD_CELL(curgr,curgc,curr,curc,GCL,char(kbkey));
count++;
ROW_PRINT(curgr,curr,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}
     if(kbkey==DEL)
{
W_FLAG=0;
  if((curc->nextc==NULL)&&(curr->nextr!=NULL))
     W_FLAG=1;
  if((curc->nextc==NULL)&&(curc->prevc==NULL)&&(curr->nextr!=NULL))
     W_FLAG=1;
curgc=G_DEL_KEY(curgr,curgc,curr,curc,cl);
if(W_FLAG==1)
TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
else
ROW_PRINT(curgr,curr,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}
     if(kbkey==BACKSPACE)
{
W_FLAG=0;
curgc=G_BACKSPACE_KEY(curgr,curgc,curr,curc,cl);
if(W_FLAG==1)
TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
else
ROW_PRINT(curgr,curr,CURRENT_SC_VAL);

pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}

     if((kbkey==ENTER)&&(LIMIT_FLAG==0))
{
curgc=G_ENTER_KEY(curgr,curgc,curr,curc,GCL);
CURRENT_SC_VAL=1;
TEXTBOX_PRINT(firstgr,SCREEN_ROW,CURRENT_SC_VAL);
pregc=G_CURSOR(curgc,pregc,0);
G_FLAG=1;
}

     if(G_FLAG==0)
  pregc=G_CURSOR(curgc,pregc,1);
     else
  G_FLAG=0;


  }
      }
if((button&1==1)&&((x>TB_LEFT)&&(y>TB_TOP)&&(x<TB_RIGHT)&&(y<TB_BOT)))
      {

   int sx,sy,ex,ey;
   getmousepos(&button,&x,&y);
   sx=x;
   sy=y;
   while((button&1==1)&&(((x>TB_LEFT)&&(y>TB_TOP)&&(x<TB_RIGHT)&&(y<TB_BOT))))
{
   getmousepos(&button,&x,&y);
   ex=x;
   ey=y;
   if(ex>TB_RIGHT)
   ex=TB_RIGHT;
   if(ey>TB_BOT)
   ey=TB_BOT;
   hidemouseptr();

   MOUSE_SELECT(sx,sy,ex,ey);

   showmouseptr();

}


   settextstyle(ST_STYLE_F1,ST_STYLE_F2,ST_STYLE_F3);
   setusercharsize(ST_USIZE_F1,ST_USIZE_F2,ST_USIZE_F3,ST_USIZE_F4);
   settextjustify(CENTER_TEXT,CENTER_TEXT);

}


return 0;
}
/////////////////////////////
void TEXT_BOX_FGP::LOST_FOCUS()
{
   FOCUS=0;
   gotoxy(65,23);
   cout<<"OUT OF FOCUS";
}
void TEXT_BOX_FGP::SET_FOCUS()
{
   FOCUS=1;
   gotoxy(65,23);
   cout<<"FOCUS IS SET";
}

/// LINE 589 RIGHT LEFT CHANGED ELSE OK

Project Homepage: