Advertisement
azaroma

form.c

Apr 7th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.60 KB | None | 0 0
  1. #include "menu.h"
  2. #include "form.h"
  3. #include "curses.h"
  4. #include "stdlib.h"
  5. #include "signal.h"
  6.  
  7. static void finish(int sig);
  8.  
  9. /* student struct */
  10. struct student_struct
  11. {
  12.     int ID;
  13.     char *name;
  14.     float p1, p2, f;
  15. };
  16. typedef struct student_struct student;
  17.  
  18. void addstu(WINDOW *viewwin, student *class);
  19.  
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.     signal(SIGINT, finish);
  24.     WINDOW *viewwin;
  25.     student *class;
  26.     int width, height;
  27.  
  28.     /* initialize curses */
  29.     initscr();
  30.     keypad(stdscr, TRUE);
  31.     cbreak();
  32.     noecho();
  33.  
  34.     /* create windows */
  35.     getmaxyx(stdscr, height, width);
  36.     viewwin = newwin(height - (height/10 + 2), (width/2) - 1, (height/10) + 1, (width/2) + 1);
  37.    
  38.     box(viewwin, 0, 0);
  39.     wattron(viewwin, A_REVERSE);
  40.     mvwprintw(viewwin, 1, 1, "%s", "View");
  41.     mvwhline(viewwin, 2, 1, ACS_HLINE, (width/2) - 3); 
  42.     wattroff(viewwin, A_REVERSE);
  43.     wrefresh(viewwin);
  44.  
  45.     addstu(viewwin, class);
  46.  
  47.     finish(0); 
  48. }
  49.  
  50. void addstu(WINDOW *viewwin, student *class)
  51. {
  52.     //WINDOW *viewsub;
  53.     FIELD *info[5];
  54.     FORM *adding;
  55.     keypad(viewwin, TRUE);
  56.     //keypad(viewsub, TRUE);
  57.     int height, width, c;
  58.     getmaxyx(viewwin, height, width);
  59.     //viewsub = derwin(viewwin, height - 6, width - 4, 4, 2);
  60.    
  61.     /* initialize the fields */
  62.     info[0] = new_field(1, 15, 1, 1, 0, 0);
  63.     info[1] = new_field(1, 15, 2, 1, 0, 0);
  64.     info[4] = NULL;
  65.    
  66.     /* set field options */
  67.     set_field_back(info[0], A_UNDERLINE);
  68.     set_field_back(info[1], A_UNDERLINE);
  69.  
  70.     /* create the form */
  71.     adding = new_form(info);
  72.  
  73.     /* set main window and subwindow for the form */
  74.     set_form_win(adding, viewwin);
  75.     //set_form_sub(adding, viewsub);
  76.     set_form_sub(adding, derwin(viewwin, height - 6, width - 4, 5, 2));
  77.    
  78.     /* format window */
  79.     box(viewwin, 0, 0);
  80.     wattron(viewwin, A_REVERSE);
  81.     mvwprintw(viewwin, 1, 1, "%s", "Inserte la información del alumno");
  82.     mvwhline(viewwin, 2, 1, ACS_HLINE, width - 2);
  83.     wattroff(viewwin, A_REVERSE);
  84.  
  85.     //mvwprintw(viewwin, 0, 1, "%s", "Nombre:");
  86.    
  87.     /* post form */
  88.     post_form(adding); 
  89.  
  90.     touchwin(viewwin); 
  91.     wrefresh(viewwin);
  92.  
  93.     while((c = wgetch(viewwin)) != KEY_F(5))
  94.     {
  95.         switch(c)
  96.         {
  97.             case KEY_DOWN:
  98.                 form_driver(adding, REQ_NEXT_FIELD);
  99.                 form_driver(adding, REQ_END_LINE);
  100.                 break;
  101.             case KEY_UP:
  102.                 form_driver(adding, REQ_PREV_FIELD);
  103.                 form_driver(adding, REQ_END_LINE);
  104.                 break;
  105.             default:
  106.                 form_driver(adding, c);
  107.                 break;
  108.         }
  109.        
  110.     }
  111.  
  112.     /* unpost form and free memory */
  113.     unpost_form(adding);
  114.     free_form(adding);
  115.     free_field(info[0]);
  116.     free_field(info[1]);
  117. }
  118.  
  119. static void finish(int sig)
  120. {
  121.     endwin();
  122.  
  123.     /* do the non-curses wrap up here */
  124.  
  125.     exit(0);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement