home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / imagetoo / imagetl1.lha / Imagetool / src+obj / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  6.7 KB  |  235 lines

  1. /* cat > headers/dialog.h << "EOF" */
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  3. /* dialog.h: header for dialog.c file            */
  4. /*         provides dialog box to force user to input */
  5. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  6. /* SCCS information: %W%    %G% - NCSA */
  7.  
  8. #define dialog_h    1
  9.  
  10. #include "all.h"
  11. #include "newext.h"
  12.  
  13. /* EOF */
  14. /* cat > src+obj/dialog/dialog_event.c << "EOF" */
  15. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  16. /* dialog_event: event handler for dialog panel text    */
  17. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  18. /* SCCS information: %W%    %G% - NCSA */
  19.  
  20. /* #include "dialog.h" */
  21.  
  22. dialog_event (item, event)
  23.     Panel_item      item;
  24.     Event          *event;
  25. {
  26.     Menu            which_menu;
  27.     Menu_item       menu_item;
  28.  
  29.         /* handle ASCII characters first */
  30.     if (event_is_ascii (event))
  31.     {
  32. /* printf ("event = %d\n", event_action (event)); */
  33. /* panel_accept_key (item, event);  */
  34.         panel_default_handle_event (item, event);
  35.         return;
  36.     }
  37.         /* get menu from client data */
  38.     if ((which_menu = (Menu) panel_get (text_item, PANEL_CLIENT_DATA)) != NULL)
  39.         if (display_panel_menu (item, event, dialog_panel, which_menu))
  40.         {        /* store first item from menu into panel text */
  41.             menu_item = menu_get (which_menu, MENU_NTH_ITEM, 1);
  42.             panel_set_value (text_item, menu_get (menu_item, MENU_STRING));
  43.             return;
  44.         }
  45. }
  46. /* EOF */
  47. /* cat > src+obj/dialog/dialog_proc.c << "EOF" */
  48. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  49. /* dialog_proc: dialog procedure            */
  50. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  51. /* SCCS information: %W%    %G% - NCSA */
  52.  
  53. /* #include "dialog.h" */
  54.  
  55. Panel_setting
  56. dialog_proc (item, event)
  57.     Panel_item      item;
  58.     Event          *event;
  59. {
  60.     switch (event_id (event))
  61.     {
  62.         case '\t':
  63.             return PANEL_INSERT;
  64.         case '\r':
  65.         case '\n':
  66.             window_return (1);
  67.             return PANEL_NONE;
  68.         default:
  69.             return PANEL_INSERT;
  70.     }
  71. }
  72. /* EOF */
  73. /* cat > src+obj/dialog/init_dialog.c << "EOF" */
  74. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  75. /* init_dialog: initialize dialog            */
  76. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  77. /* SCCS information: %W%    %G% - NCSA */
  78.  
  79. /* #include "dialog.h" */
  80.  
  81. Frame
  82. init_dialog (name, msg, result, ok_only, d, r, menu)
  83.     char           *name;
  84.                 /* input: label for panel text */
  85.     char           *msg;
  86.                 /* input: panel message above panel text */
  87.     char           *result;
  88.                 /* input: initial value displayed
  89.                    return: value in panel text */
  90.     int             ok_only;
  91.                 /* input: 0 - require typed response, item is used
  92.                       1 - no typed response, msg is used  */
  93.     int             d;
  94.                 /* input: number of characters displayed in the panel text */
  95.     int             r;
  96.                 /* input: number of characters stored for the panel text */
  97.     Menu            menu;
  98.                 /* input: for PANEL_TEXT = text_item:
  99.                       (not) NULL - a menu to be popped up
  100.                       NULL         - no menu provided */
  101. {
  102.     Frame           dialog_box;
  103.     int             top, left, w, h;
  104.  
  105.     dialog_box = window_create (0, FRAME, FRAME_SHOW_LABEL, FALSE, 0);
  106.     dialog_panel = window_create (dialog_box, PANEL,
  107.                       PANEL_FONT, font_panel,
  108.                       0);
  109.     top = left = 0;
  110.     w = 50;
  111.     h = 25;
  112.     if (msg != NULL)
  113.     {
  114.         panel_create_item (dialog_panel, PANEL_MESSAGE,
  115.                    PANEL_LABEL_STRING, msg,
  116.                    PANEL_LABEL_BOLD, TRUE,
  117.                    0);
  118.         top += h;
  119.         left += w;
  120.     }
  121.     if (!ok_only)
  122.     {
  123.         text_item = panel_create_item (dialog_panel, PANEL_TEXT,
  124.                            PANEL_ITEM_X, left,
  125.                            PANEL_ITEM_Y, top,
  126.                            PANEL_VALUE_DISPLAY_LENGTH, d,
  127.                            PANEL_VALUE_STORED_LENGTH, r,
  128.                            PANEL_LABEL_STRING, name,
  129.                            PANEL_LABEL_BOLD, FALSE,
  130.                            PANEL_NOTIFY_STRING, "\r\t\n",
  131.                            PANEL_CLIENT_DATA, menu,
  132.                            PANEL_EVENT_PROC, dialog_event,
  133.                            PANEL_NOTIFY_PROC, dialog_proc,
  134.                            0);
  135.         if (strlen (result) > 0)
  136.                 /* initialize with input value */
  137.             panel_set_value (text_item, result);
  138.         top += h;
  139.         left += 2 * w;
  140.     }
  141.     panel_create_item (dialog_panel, PANEL_BUTTON,
  142.                PANEL_ITEM_X, left,
  143.                PANEL_ITEM_Y, top,
  144.                PANEL_LABEL_IMAGE, panel_button_image (dialog_panel, "Ok", 3, font_panel_button),
  145.                PANEL_CLIENT_DATA, 1,
  146.                PANEL_NOTIFY_PROC, ok_cancel,
  147.                0);
  148.     panel_create_item (dialog_panel, PANEL_BUTTON,
  149.                PANEL_ITEM_X, left + w,
  150.                PANEL_ITEM_Y, top,
  151.                PANEL_LABEL_IMAGE, panel_button_image (dialog_panel, "Cancel", 6, font_panel_button),
  152.                PANEL_CLIENT_DATA, 0,
  153.                PANEL_NOTIFY_PROC, ok_cancel,
  154.                0);
  155.     window_fit (dialog_panel);
  156.     window_fit (dialog_box);
  157.  
  158.     w = (int) window_get (dialog_box, WIN_WIDTH);
  159.     h = (int) window_get (dialog_box, WIN_HEIGHT);
  160.  
  161.     window_set (dialog_box, WIN_X, 1150 / 2 - w / 2, WIN_Y, 900 / 2 - h / 2, 0);
  162.  
  163.         /* set color map same with imagetool */
  164.     (void) color_dialog_win ();
  165.  
  166.     return dialog_box;
  167. }
  168. /* EOF */
  169. /* cat > src+obj/dialog/mydialog.c << "EOF" */
  170. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  171. /* mydialog: create my dialog                */
  172. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  173. /* SCCS information: %W%    %G% - NCSA */
  174.  
  175. /* #include "dialog.h" */
  176.  
  177. mydialog (item, msg, result, ok_only, show_length, real_length, menu)
  178.     char           *item;
  179.                 /* input: label for panel text */
  180.     char           *msg;
  181.                 /* input: panel message above panel text */
  182.     char           *result;
  183.                 /* input: initial value displayed
  184.                       return: value in panel text */
  185.     int             ok_only;
  186.                 /* input: 0 - require typed response, item is used
  187.                         1 - no typed response, msg is used  */
  188.     int             show_length;
  189.                 /* input: number of characters displayed in the panel text */
  190.     int             real_length;
  191.                 /* input: number of character stored for the panel text */
  192.     Menu            menu;
  193.                 /* input: for PANEL_TEXT = text_item:
  194.                         (not) NULL - menu to be popped up
  195.                         NULL         - no menu provided */
  196. {
  197.     Frame           dialog;
  198.     int             answer;
  199.  
  200.     if (!ok_only)
  201.     {
  202.         if (item == NULL || result == NULL)
  203.             return (-1);
  204.     }
  205.  
  206.     dialog = init_dialog (item, msg, result, ok_only, show_length, real_length, menu);
  207.  
  208.     if ((answer = (int) window_loop (dialog)) && !ok_only)
  209.     {
  210.         strcpy (result, (char *) panel_get_value (text_item));
  211.         if (strlen (result) == 0)    /* answer yes but no name */
  212.             answer = -1;
  213.     }
  214.  
  215.     window_set (dialog, FRAME_NO_CONFIRM, TRUE, 0);
  216.     window_destroy (dialog);
  217.     return (answer);
  218. }
  219. /* EOF */
  220. /* cat > src+obj/dialog/ok_cancel.c << "EOF" */
  221. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  222. /* ok_cancel: ok to cancel                */
  223. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  224. /* SCCS information: %W%    %G% - NCSA */
  225.  
  226. /* #include "dialog.h" */
  227.  
  228. ok_cancel (item, event)
  229.     Panel_item      item;
  230.     Event          *event;
  231. {
  232.     window_return ((int) panel_get (item, PANEL_CLIENT_DATA));
  233. }
  234. /* EOF */
  235.