home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / stdwin.zoo / atari / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  4.6 KB  |  234 lines

  1. #include <osbind.h>
  2. #include "window.h"
  3. #include "trees.h"
  4. #include "atari_proto.h"
  5. #undef P
  6.  
  7. #define REV    0x110f1L
  8. #define MAXLEN    40
  9.  
  10. #define NDEF_FLAG    (SELECTABLE | EXIT)
  11. #define DEF_FLAG    (SELECTABLE | EXIT | DEFAULT)
  12.  
  13. static char    curdir[256] ;
  14.  
  15. extern char    *rindex () ;
  16.  
  17. int
  18. waskfile (prompt, buf, buflen, new)
  19.     char    *prompt ;
  20.     char    *buf ;
  21.     int    buflen ;
  22.     int    new ;
  23. {
  24.     static char    dir[256] ;
  25.     static char    fname[256] ;
  26.     char    *p = dir ;
  27.     int    button ;
  28.  
  29.     if (!*dir) {
  30.         int    drive ;
  31.  
  32.         drive = Dgetdrv () ;
  33.         *p++ = (char) drive + 'A' ;
  34.         *p++ = ':' ;
  35.         Dgetpath (p, drive + 1) ;
  36.         strcat (dir, "\\*.*") ;
  37.         strcpy (curdir, dir) ;
  38.     }
  39.  
  40.     if (*buf) {
  41.         char    *pdir ;
  42.  
  43.         p = rindex (buf, '\\') ;
  44.  
  45.         if (buf[1] == ':')    /* buf contains full path name */
  46.             pdir = dir ;
  47.         else
  48.             pdir = &dir[2] ;
  49.  
  50.         if (p) {
  51.             strncpy (pdir, buf, (size_t) (p - buf)) ;
  52.             strcat (dir, "\\*.*") ;
  53.             strcpy (fname, &buf[(int) (p - buf) + 1]) ;
  54.         }
  55.         else
  56.             strcpy (fname, buf) ;
  57.     }
  58.  
  59.     if (!fsel_input (dir, fname, &button)) {
  60.         wdebug ("waskfile: fsel_input") ;
  61.         buf[0] = '\0' ;
  62.         return (FALSE) ;
  63.     }
  64.  
  65.     if (!button) {
  66.         buf[0] = '\0' ;
  67.         return (FALSE) ;
  68.     }
  69.  
  70.     if ((p = rindex (dir, '\\')) == NULL)
  71.         p = dir ;
  72.  
  73.     if (strncmp (curdir, dir, (size_t) (p - dir)) == 0) {
  74.         strcpy (buf, fname) ;
  75.         return (TRUE) ;
  76.     }
  77.  
  78.     if (buflen < ((int) (p - dir + 1) + (int)strlen (fname))) {
  79.         wdebug ("waskfile: buffer not long enough") ;
  80.         buf[0] = '\0' ;
  81.         return (FALSE) ;
  82.     }
  83.  
  84.     strncpy (buf, dir, (size_t) (p - dir) + 1) ;
  85.     buf[(int) (p - dir) + 1] = 0 ;
  86.     strcat (buf, fname) ;
  87.  
  88.     return (TRUE) ;
  89. }
  90.  
  91. TEDINFO
  92. *tedinfo (buf, len)
  93.     char    *buf ;
  94.     int    len ;
  95. {
  96.     TEDINFO    *e = ALLOC (TEDINFO) ;
  97.     char    *tmpl = malloc ((size_t)len) ;
  98.     char    *valid = malloc ((size_t)len) ;
  99.     int    str_len = (int)strlen (buf) ;
  100.     int    i ;
  101.  
  102.     for (i = 0 ; i < len - 1 ; i++) {
  103.         /*if (i >= str_len)
  104.             buf[i] = '@' ;*/
  105.         tmpl[i] = '_' ;
  106.         valid[i] = 'X' ;
  107.     }
  108.     buf[len-1] = tmpl[len-1] = valid[len-1] = '\0' ;
  109.  
  110.     e->te_ptext = buf ;
  111.     e->te_ptmplt = tmpl ;
  112.     e->te_pvalid = valid ;
  113.     e->te_font = IBM ;
  114.     e->te_junk1 = 0 ;
  115.     e->te_just = TE_LEFT ;
  116.     e->te_color = 0x01f0 ;
  117.     e->te_junk2 = 0 ;
  118.     e->te_thickness = 0 ;
  119.     e->te_txtlen = len - 1 ;
  120.     e->te_tmplen = len - 1 ;
  121.  
  122.     return (e) ;
  123. }
  124.  
  125. OBJECT
  126. *str_obj (prompt, buf, buflen)
  127.     char    *prompt ;
  128.     char    *buf ;
  129.     int    buflen ;
  130. {
  131.     TREE    tree = { 0, 0, 0 } ;
  132.     TREE    *t = &tree ;
  133.     TEDINFO    *edit ;
  134.     int    lh = wlineheight () ;
  135.     int    cw = wcharwidth ('m') ;
  136.     int    pr_width = wtextwidth (prompt, -1) ;
  137.     int    buf_width = buflen <= 40 ? buflen * cw : 40 * cw ;
  138.     int    but_width = 17 * cw ;
  139.             /*
  140.             ** 12 for the characters, 3 for the space around the
  141.             ** buttons and 2 for the borders of the buttons
  142.             */
  143.     int    box_width ;
  144.     int    box_height = 8 * lh + 6 ;
  145.  
  146.     box_width = (pr_width > buf_width ?
  147.             (pr_width > but_width ? pr_width : but_width) :
  148.             (buf_width > but_width ? buf_width : but_width))
  149.         + 6 * cw + 6 ;
  150.  
  151.     tr_add (t, 0, G_BOX, NONE, NORMAL, (long)BAR, 0, 0, box_width, box_height) ;
  152.     tr_add (t, 1, G_BOX, NONE, NORMAL, (long)BAR, 3, 3, box_width - 6,
  153.                             box_height - 6) ;
  154.     tr_add (t, 1, G_STRING, NONE, NORMAL, prompt, 3 * cw, lh, pr_width, lh);
  155.  
  156.     edit = tedinfo (buf, buflen > 40 ? 40 : buflen) ;
  157.     tr_add (t, 0, G_FTEXT ,NONE, NORMAL, edit, 3 * cw, 5 * lh / 2,
  158.                             buf_width, 2 * lh) ;
  159.  
  160.     tr_add (t, 0, G_BUTTON, DEF_FLAG, NORMAL, " Ok ", 3 * cw, 6 * lh,
  161.                                 4 * cw, lh) ;
  162.     tr_add (t, 0, G_BUTTON, NDEF_FLAG, NORMAL, " Cancel ",
  163.                 box_width - 15 * cw, 6 * lh, 8 * cw, lh) ;
  164.  
  165.     return (tr_tree (t)) ;
  166. }
  167.  
  168. int
  169. waskstr (prompt, buf, buflen)
  170.     char    *prompt ;
  171.     char    *buf ;
  172.     int    buflen ;
  173. {
  174.     OBJECT    *dialog = str_obj (prompt, buf, buflen) ;
  175.     Rect    tmpbox ;
  176.     int    dummy ;
  177.     int    rc ;
  178.  
  179.     graf_mouse (ARROW, &dummy) ;
  180.  
  181.     form_center (dialog, &tmpbox.x, &tmpbox.y, &tmpbox.w, &tmpbox.h) ;
  182. /*    form_dial (0, 1, 1, 1, 1, tmpbox) ; */
  183.     form_dial (0, 1, 1, 1, 1, tmpbox.x, tmpbox.y, tmpbox.w, tmpbox.h) ;
  184.  
  185. /*    objc_draw (dialog, ROOT, MAX_DEPTH, tmpbox) ; */
  186.     objc_draw (dialog, ROOT, MAX_DEPTH, tmpbox.x, tmpbox.y,
  187.            tmpbox.w, tmpbox.h) ;
  188.  
  189.     rc = form_do (dialog, 3) ;
  190.  
  191. /*    form_dial (3, 1, 1, 1, 1, tmpbox) ; */
  192.     form_dial (3, 1, 1, 1, 1, tmpbox.x, tmpbox.y, tmpbox.w, tmpbox.h) ;
  193.  
  194.     graf_mouse (BUSY_BEE, &dummy) ;
  195.  
  196.     if (rc == 5) {    /*    Cancel    */
  197.         buf[0] = '\0' ;
  198.         return (FALSE) ;
  199.     }
  200.     return (TRUE) ;
  201. }
  202.  
  203. int
  204. waskync (question, def)
  205.     char    *question ;
  206.     int    def ;
  207. {
  208.     char    buf[256] ;
  209.  
  210.     strcpy (buf, "[2][") ;
  211.     if ((int)strlen (question) >= 16)
  212.         strcat (buf, question) ;
  213.     else
  214.         sprintf (buf + 4, "%-16s", question) ;
  215.     strcat (buf, "][Yes|No|Cancel]") ;
  216.  
  217.     return (2 - form_alert (2 - def, buf)) ;
  218. }
  219.  
  220. void
  221. wmessage (str)
  222.     char    *str ;
  223. {
  224.     char    buf[256] ;
  225.  
  226.     strcpy (buf, "[1][") ;
  227.     strcat (buf, str) ;
  228.     strcat (buf, "][ Ok ]") ;
  229.  
  230.     (void) form_alert (1, buf) ;
  231.  
  232.     return ;
  233. }
  234.