home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / education / a / biology1 / !Biology1 / c / YNTF < prev   
Text File  |  1991-12-03  |  5KB  |  154 lines

  1. /* YNTF.c */
  2.  
  3. #include <string.h>
  4.  
  5. #include "wimp.h"
  6. #include "wimpt.h"
  7.  
  8. #include "input.h"
  9. #include "prompts.h"
  10. #include "keys.h"
  11.  
  12. static wimp_i ok;  /* required for clearing icon button and text */
  13.  
  14. /* Functions for dealing with res type 2/3 */
  15.  
  16. static void make_icon (wimp_w wnd, int x, int line, char *str, wimp_i *result)
  17.   { int len = strlen (str);
  18.     wimp_icreate   info;
  19.     wimp_redrawstr r;
  20.  
  21.     info.w        = wnd;
  22.     info.i.box.x0 = 4 + x;
  23.     info.i.box.x1 = info.i.box.x0 + (len * 8 + 4) * 2;
  24.     info.i.box.y1 = - line * 32;
  25.     info.i.box.y0 = info.i.box.y1 - 40 - 16;
  26.     info.i.flags  = wimp_ITEXT | wimp_IHCENTRE | wimp_IVCENTRE |
  27.                     wimp_INDIRECT | 7 * wimp_IFORECOL;
  28.     info.i.data.indirecttext.buffer      = str;
  29.     info.i.data.indirecttext.validstring = "";
  30.     info.i.data.indirecttext.bufflen     = len + 1;
  31.  
  32.     wimpt_noerr (wimp_create_icon (&info, result));   
  33.  
  34.     r.w = wnd;
  35.     memcpy (&r.box, &info.i.box, sizeof (wimp_box));
  36.  
  37.     wimpt_noerr (wimp_force_redraw (&r));
  38.   }
  39.  
  40. static void make_button (wimp_w wnd, int x, int line, char *str, wimp_i *ic)
  41.   { int len = strlen (str);
  42.     wimp_icreate   info;
  43.     wimp_redrawstr r;
  44.  
  45.     info.w        = wnd;
  46.     info.i.box.x0 = x - 8;
  47.     info.i.box.x1 = x + 16 * len + 8;
  48.     info.i.box.y1 = - line * 32;
  49.     info.i.box.y0 = info.i.box.y1 - 40 - 16;
  50.     info.i.flags  = wimp_ITEXT | wimp_IBORDER |
  51.                     wimp_IHCENTRE | wimp_IVCENTRE | wimp_IFILLED |
  52.                     wimp_IBTYPE * wimp_BCLICKDEBOUNCE |
  53.                     wimp_INDIRECT | 7 * wimp_IFORECOL;
  54.     info.i.data.indirecttext.buffer      = str;
  55.     info.i.data.indirecttext.validstring = "";
  56.     info.i.data.indirecttext.bufflen     = len;
  57.  
  58.     wimpt_noerr (wimp_create_icon (&info, ic));
  59.  
  60.     r.w = wnd;
  61.     memcpy (&r.box, &info.i.box, sizeof (wimp_box));
  62.  
  63.     wimpt_noerr (wimp_force_redraw (&r));
  64.   }
  65.  
  66. static void prompt (wimp_w wnd, int line, char *prompt, wimp_i *st1,
  67.                                        char *seperator, wimp_i *st2,
  68.                                         char *ic1_text, wimp_i *ic1,
  69.                                         char *ic2_text, wimp_i *ic2
  70.                    )
  71.   {
  72.     int total_len = strlen (prompt)   + strlen (seperator) +
  73.                     strlen (ic1_text) + strlen (ic2_text)  + 6;
  74.  
  75.     int width  = standard_line; 
  76.     int x     = (width - total_len) * 8;   /* OS units, Predictive on mode */
  77.  
  78.     make_icon (wnd, x, line, prompt, st1);
  79.  
  80.     x += 16 * (strlen (prompt) + 2);
  81.  
  82.     make_button (wnd, x, line, ic1_text, ic1);
  83.  
  84.     x += 16 * (strlen (ic1_text) + 2);
  85.  
  86.     make_icon (wnd, x, line, seperator, st2);
  87.  
  88.     x += 16 * (strlen (seperator) + 2);
  89.  
  90.     make_button (wnd, x, line, ic2_text, ic2);
  91.   }
  92.  
  93.  
  94. /* Calls concat initialization, to register icons */
  95. void *prompt_YNTF (wimp_w wnd, int line, char *corr_let)
  96.   {
  97.     wimp_i text1, text2, but1, but2;
  98.  
  99.     if (strcmp (corr_let, "YN") == 0)
  100.         prompt (wnd, line, "Is the above statement correct ?", &text1,
  101.                        "or", &text2,
  102.                        "Yes", &but1,
  103.                        "No", &but2);
  104.     else
  105.         prompt (wnd, line, "Is the above statement", &text1, "or", &text2,
  106.             "True", &but1, "False", &but2);
  107.     input_icon (wnd, but1, text1, corr_let[0]);
  108.     input_icon (wnd, but2, text2, corr_let[1]);
  109.  
  110.     return (concat_YNTF_wakeup (wnd, but1, but2));
  111.   }                   
  112.  
  113. char *ans_YNTF (char *correct_ans)
  114.   { static char  message[29];
  115.  
  116.     message[0] = '\0';
  117.     strcpy (message, "The statement is ");
  118.     switch (correct_ans[0])
  119.       { case 'Y' :                        
  120.             strcat (message, "correct");
  121.             break;
  122.         case 'N' :
  123.             strcat (message, "not correct");
  124.             break;
  125.         case 'T' :
  126.             strcat (message, "True");
  127.             break;
  128.         case 'F' :
  129.             strcat (message, "False");
  130.             break;
  131.       }
  132.     return (message);
  133.   }
  134.  
  135. void *prompt_ok (wimp_w wnd, int line, char *prompt)
  136.   { int      total_len;                 
  137.     int      x;             /* OS units */
  138.     wimp_i   st1;           /* icon for assoc. text */
  139.  
  140.     total_len = strlen (prompt) + 4 + 6;  
  141.     x = (standard_line - total_len) * 8;
  142.     make_icon (wnd, x, line, prompt, &st1);
  143.     x += 16 * (strlen (prompt) + 2);
  144.     make_button (wnd, x, line, "O.K.", &ok);
  145.   
  146.     input_icon (wnd, ok, st1, key_ret);
  147.     return (concat_ok_wakeup (wnd, ok));
  148.   }
  149.  
  150. void prompt_ok_delete (wimp_w wnd)
  151.   {
  152.     input_delete_icon (wnd, ok);
  153.   }
  154.