Difference between revisions of "OpText Test Programs - OOP344 20101"

From CDOT Wiki
Jump to: navigation, search
(OpText R0.31 test main (with help window))
(Undo revision 37134 by Fardad (Talk))
Line 1: Line 1:
 
 
{{OOP344 Index}}
 
{{OOP344 Index}}
 
= BFrame R0.1 test main =
 
= BFrame R0.1 test main =
Line 112: Line 111:
 
</big>
 
</big>
  
= OpText R0.4 test main (with help window) =
+
= OpText R0.31 test main (with help window) =
  
 
[[OpText Text Editor (AS2) - OOP344 20101]]
 
[[OpText Text Editor (AS2) - OOP344 20101]]
 
<big><pre>
 
<big><pre>
  
#include "btext.h"
+
# include "btext.h"
 
+
# include "blabel.h"
#include "blabel.h"
+
# include "bedit.h"
 
+
# include "bform.h"
#include "bedit.h"
+
# include <string.h>
 
 
#include "bvedit.h"
 
 
 
#include "bform.h"
 
 
 
#include <cstring>
 
 
 
#include <cctype>
 
 
 
using namespace std;
 
  
 
bool Yes(const char* message, BForm* owner){
 
bool Yes(const char* message, BForm* owner){
 
 
   int key;
 
   int key;
 
 
   BForm YesNo((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
 
   BForm YesNo((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
 
 
   YesNo.add(new BLabel(2, 2, 36)).add(new BLabel("(Y)es / (N)o", 4, 12));
 
   YesNo.add(new BLabel(2, 2, 36)).add(new BLabel("(Y)es / (N)o", 4, 12));
 
 
   YesNo[0].set(message);
 
   YesNo[0].set(message);
 
 
   key = YesNo.edit(0, owner);
 
   key = YesNo.edit(0, owner);
 
 
   return key == 'Y' || key == 'y';
 
   return key == 'Y' || key == 'y';
 
 
}
 
}
 
 
void Help(BForm* owner){
 
void Help(BForm* owner){
 
 
   BForm help((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
 
   BForm help((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
 
 
   help.add(new BLabel(2, 3,36))
 
   help.add(new BLabel(2, 3,36))
 
 
     .add(new BLabel("Escape Key: Exit the test program.", 4, 3))
 
     .add(new BLabel("Escape Key: Exit the test program.", 4, 3))
 
+
     .add(new BLabel("F1 Key: Open this window.", 6, 3));
     .add(new BLabel("F1 Key: Open this window.", 6, 3));  
 
 
 
 
   switch(owner->curField()){
 
   switch(owner->curField()){
 
 
     case 2:
 
     case 2:
 
 
       help[0].set("Enter the name here!");
 
       help[0].set("Enter the name here!");
 
 
       break;
 
       break;
 
+
     case 4:
     case 4:  
 
 
 
 
       help[0].set("Enter the Last name here!");
 
       help[0].set("Enter the Last name here!");
 
 
       break;
 
       break;
 
 
     case 6:
 
     case 6:
 
 
       help[0].set("Enter Phone number: (999)999-9999");
 
       help[0].set("Enter Phone number: (999)999-9999");
 
 
   }
 
   }
 
 
   help.edit(0, owner);
 
   help.edit(0, owner);
 
}
 
 
void PhoneHelp(MessageStatus st, BForm& owner){
 
 
  if(st == ClearMessage){
 
 
    owner[6].set("");
 
 
  }
 
 
  else{
 
 
    owner[6].set("Phone Format: 999-999-9999");
 
 
  }
 
 
  owner.display(7);
 
 
}
 
 
void LastNameHelp(MessageStatus st, BForm& owner){
 
 
  if(st == ClearMessage){
 
 
    owner[7].set("");
 
 
  }
 
 
  else{
 
 
    owner[7].set("i.e. Middle name and Surname");
 
 
  }
 
 
  owner.display(8);
 
 
}
 
 
bool ValidPhone(const char* ph , BForm& owner){
 
 
  bool ok = true;
 
 
  int i;
 
 
  for(i=0;ok && i<3;ok = (bool)isdigit(ph[i]), i++);
 
 
  ok = ph[i++] == '-';
 
 
  for(;ok && i<7;ok = (bool)isdigit(ph[i]), i++);
 
 
  ok = ph[i++] == '-';
 
 
  for(;ok && i<12;ok = (bool)isdigit(ph[i]), i++);
 
 
  if(ok){
 
 
    owner[8].set("");
 
 
  }
 
 
  else{
 
 
    owner[8].set("Invlid phone number, please use the specified phone number format!");
 
 
  }
 
 
  owner.display(9);
 
 
  return ok;
 
 
 
}
 
}
  
 
int main() {
 
int main() {
 
 
   int insert = 1;
 
   int insert = 1;
 
 
   int key;
 
   int key;
 
 
   bool done = false;
 
   bool done = false;
 
 
   bio_init();
 
   bio_init();
  
 
   BForm F(3, 5, 20, 70, true);
 
   BForm F(3, 5, 20, 70, true);
 
  BLabel PhHelp(9, 34, 30);
 
 
  BLabel LnHelp(6, 37, 30);
 
 
  BLabel ErrMes(18, 2, 67);
 
 
 
   F.add(new BLabel("Name:", 3, 2))
 
   F.add(new BLabel("Name:", 3, 2))
 
 
     .add(new BEdit(2, 10, 20, 40, &insert,true))
 
     .add(new BEdit(2, 10, 20, 40, &insert,true))
 
 
     .add(new BLabel("Lastname:", 6, 2))
 
     .add(new BLabel("Lastname:", 6, 2))
 
+
     .add(new BEdit(5, 13, 20, 40, &insert, true))
     .add(new BVedit(5, 13, 20, 40, &insert,NO_VFUNC, LastNameHelp, true))
 
 
 
 
     .add(new BLabel("Phone Number", 9,2))
 
     .add(new BLabel("Phone Number", 9,2))
 
+
     .add(new BEdit(8, 16, 15, 20, &insert, true));
     .add(new BVedit(8, 16, 13, 12, &insert,ValidPhone,PhoneHelp, true));
 
 
 
  F.add(PhHelp);
 
 
 
  F.add(LnHelp);
 
 
 
  F.add(ErrMes);
 
 
 
 
   while(!done){
 
   while(!done){
 
 
     key = F.edit();
 
     key = F.edit();
 
 
     switch(key){
 
     switch(key){
 
 
       case F1_KEY:
 
       case F1_KEY:
 
 
         Help(&F);
 
         Help(&F);
 
 
         break;
 
         break;
 
 
       case ESCAPE_KEY:
 
       case ESCAPE_KEY:
 
 
         if(Yes("Do you really want to quit?", &F)){
 
         if(Yes("Do you really want to quit?", &F)){
 
 
           done = true;
 
           done = true;
 
 
         }
 
         }
 
 
         F.display(OT_CLR_AND_DSPLY_ALL);
 
         F.display(OT_CLR_AND_DSPLY_ALL);
 
 
         break;
 
         break;
 
 
     }
 
     }
 
 
   }
 
   }
 
 
   bio_end();
 
   bio_end();
 
 
   return 0;
 
   return 0;
 
 
}
 
}
 
 
</pre></big>
 
</pre></big>
  

Revision as of 18:24, 28 March 2010


OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources

BFrame R0.1 test main

OpText Text Editor (AS2) - OOP344 20101

# include "btext.h"
# include "bframe.h"

int main(int argc, char* argv[], char* env[]) {
  int ro = 0;
  int co = 0;
  bool done = false;
  int key = 0;
  bio_init();
  int rows = bio_rows();
  int cols = bio_cols();
  BFrame bframe(8, 30, 5, 10, true);
  while(!done){
    bio_clrscr();
    bframe.draw(ro, co);
    key = bio_getch();
    switch(key){
      case RIGHT_KEY:
        if(co + 40 < cols)
          co++;
        break;
      case LEFT_KEY:
        if(co + 30 > 0)
          co--;
        break;
      case DOWN_KEY:
        if(ro + 13 < rows )
          ro++;
        break;
      case UP_KEY:
        if(ro + 8 > 0 )
          ro--;
        break;
      case ESCAPE_KEY:
        done = true;
        break;
    }
  }
  bio_end();
  return 0;
}

R0.1 Executable on matrix:

~fardad.soleimanloo/bframetest

OpText R0.3 test main

OpText Text Editor (AS2) - OOP344 20101


# include "btext.h"
# include "blabel.h"
# include "bedit.h"
# include "bform.h"
# include <string.h>

bool Yes(const char* message, BForm* owner){
  int key;
  BForm YesNo((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
  YesNo.add(new BLabel(2, 2, 36)).add(new BLabel("(Y)es / (N)o", 4, 12));
  YesNo[0].set(message);
  key = YesNo.edit(0, owner);
  return key == 'Y' || key == 'y';
}
int main() {
  int insert = 1;
  int key;
  bool done = false;
  bio_init();
  BForm F(3, 5, 20, 70, true);
  F.add(new BLabel("Name:", 3, 2))
    .add(new BEdit(2, 10, 20, 40, &insert,true))
    .add(new BLabel("Lastname:", 6, 2))
    .add(new BEdit(5, 13, 20, 40, &insert, true))
    .add(new BLabel("Phone Number", 9,2))
    .add(new BEdit(8, 16, 15, 20, &insert, true));
  while(!done){
    key = F.edit();
    switch(key){
      case F1_KEY:
        // Help.edit(); to do later
        break;
      case ESCAPE_KEY:
        if(Yes("Do you really want to quit?", &F)){
          done = true;
        }
        F.display(OT_CLR_AND_DSPLY_ALL);
        break;
    }
  }
  bio_end();
  return 0;

}

R0.3 Executable on matrix:

~fardad.soleimanloo/optext0.3

OpText R0.31 test main (with help window)

OpText Text Editor (AS2) - OOP344 20101


# include "btext.h"
# include "blabel.h"
# include "bedit.h"
# include "bform.h"
# include <string.h>

bool Yes(const char* message, BForm* owner){
  int key;
  BForm YesNo((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
  YesNo.add(new BLabel(2, 2, 36)).add(new BLabel("(Y)es / (N)o", 4, 12));
  YesNo[0].set(message);
  key = YesNo.edit(0, owner);
  return key == 'Y' || key == 'y';
}
void Help(BForm* owner){
  BForm help((bio_rows()- 10)/2, (bio_cols()-40)/2, 10, 40, true);
  help.add(new BLabel(2, 3,36))
    .add(new BLabel("Escape Key: Exit the test program.", 4, 3))
    .add(new BLabel("F1 Key: Open this window.", 6, 3));
  switch(owner->curField()){
    case 2:
      help[0].set("Enter the name here!");
      break;
    case 4:
      help[0].set("Enter the Last name here!");
      break;
    case 6:
      help[0].set("Enter Phone number: (999)999-9999");
  }
  help.edit(0, owner);
}

int main() {
  int insert = 1;
  int key;
  bool done = false;
  bio_init();

  BForm F(3, 5, 20, 70, true);
  F.add(new BLabel("Name:", 3, 2))
    .add(new BEdit(2, 10, 20, 40, &insert,true))
    .add(new BLabel("Lastname:", 6, 2))
    .add(new BEdit(5, 13, 20, 40, &insert, true))
    .add(new BLabel("Phone Number", 9,2))
    .add(new BEdit(8, 16, 15, 20, &insert, true));
  while(!done){
    key = F.edit();
    switch(key){
      case F1_KEY:
        Help(&F);
        break;
      case ESCAPE_KEY:
        if(Yes("Do you really want to quit?", &F)){
          done = true;
        }
        F.display(OT_CLR_AND_DSPLY_ALL);
        break;
    }
  }
  bio_end();
  return 0;
}

R0.31 Executable on matrix

~fardad.soleimanloo/optext0.31