home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part05 / confirmer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-14  |  4.2 KB  |  165 lines

  1.  
  2. /**************************************************************************
  3.    Touchup a bitmap graphics editor for the Sun Workstation running SunView
  4.    Copyright (c) 1988 by Raymond Kreisel
  5.    1/22/88 @ Suny Stony Brook
  6.  
  7.    This program may be redistributed without fee as long as this copyright
  8.    notice is intact.
  9.  
  10. ==> PLEASE send comments and bug reports to one of the following addresses:
  11.  
  12.        Ray Kreisel
  13.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  14.  
  15.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  16.        ARPA-Internet: rayk@sbcs.sunysb.edu            
  17.        CSnet: rayk@suny-sb
  18.  
  19.  "If I get home before daylight, I just might get some sleep tonight...."
  20.  
  21. **************************************************************************/
  22. /**************************************************************************
  23.     file: confirmer.c
  24.     purpose: This file contains a simple confirmer copied from the
  25.      Sunview manual that has been souped up a little
  26.  
  27.     modifications:
  28.         date:    Tue Mar 22 22:04:58 EST 1988
  29.         author:    rayk
  30.         changes:add comments
  31. **************************************************************************/
  32.  
  33. #include <stdio.h>
  34. #include <sys/file.h>
  35. #include <suntool/sunview.h>
  36. #include <suntool/panel.h>
  37. #include <suntool/canvas.h>
  38. #include <suntool/walkmenu.h>
  39. #include <suntool/scrollbar.h>
  40. #include <math.h>
  41. #include <pixrect/pixrect_hs.h>
  42.  
  43. extern Panel panel;
  44.  
  45. static Frame  init_confirmer();
  46. static void yes_no();
  47.  
  48. /***************************************************************
  49.         confirm
  50.         purpose: To display a window on the base_frame Sunwindow
  51.                 force the user to answer the question by selecting
  52.         either YES or NO
  53.         parameter:
  54.                 message: The question to asked.
  55.         returns:
  56.         1 : if the user answered YES
  57.         0 : if the user answered NO
  58.  ***************************************************************/
  59. int confirm(message)
  60. char     *message; 
  61. {
  62.     Frame     confirmer;
  63.     int       answer;
  64.  
  65. /* create the confirmer */
  66.     confirmer = init_confirmer(message);
  67.     window_bell(panel);
  68. /* make the user answer */
  69.      answer = (int) window_loop(confirmer);
  70.  
  71. /* destroy the confirmer */
  72.     window_set(confirmer, FRAME_NO_CONFIRM, TRUE, 0);
  73.     window_destroy(confirmer);
  74.  
  75.         return answer;
  76. }
  77.  
  78. static Frame
  79. init_confirmer(message)
  80. char     *message; 
  81. extern   Frame  base_frame;
  82. Frame           confirmer;
  83. Panel           panel;
  84. Panel_item      message_item;
  85. int             left, top, width, height;
  86. Rect            *r;
  87. struct pixrect  *pr;
  88.  
  89. /* create the confirmer base frame */
  90.     confirmer = window_create(base_frame, FRAME, 
  91.                                   FRAME_SHOW_LABEL, FALSE,
  92.                   0);
  93.  
  94. /* create the single panel subwindow */
  95.     panel = window_create(confirmer, PANEL, 0);
  96.  
  97. /* put in the message */
  98.     message_item = panel_create_item(panel, PANEL_MESSAGE,
  99.                     PANEL_LABEL_STRING, message,
  100.                     0);
  101.  
  102.     pr = panel_button_image(panel, "NO", 3, 0);
  103.     width = 2 * pr->pr_width + 10;
  104.  
  105.       r = (Rect *) panel_get(message_item, PANEL_ITEM_RECT);
  106.  
  107. /* center the yes/no buttons under the message */
  108.     left = (r->r_width - width) / 2;
  109.     if (left < 0)
  110.         left = 0;
  111.     top = rect_bottom(r) + 5;
  112.  
  113.         panel_create_item(panel, PANEL_BUTTON,
  114.                   PANEL_ITEM_X, left,
  115.               PANEL_ITEM_Y, top,
  116.               PANEL_LABEL_IMAGE, pr,
  117.               PANEL_CLIENT_DATA, FALSE,
  118.           PANEL_NOTIFY_PROC, yes_no,
  119.           0);
  120.  
  121.         panel_create_item(panel, PANEL_BUTTON,
  122.               PANEL_LABEL_IMAGE, panel_button_image(panel, "YES", 3, 0),
  123.               PANEL_CLIENT_DATA, TRUE,
  124.           PANEL_NOTIFY_PROC, yes_no,
  125.           0);
  126.  
  127.  
  128.     window_fit(panel);
  129.     window_fit(confirmer);
  130.  
  131. /* center the confirmer frame in the base frame */
  132.     r = (Rect *) window_get(base_frame, WIN_RECT);
  133.  
  134.     width = (int) window_get(confirmer, WIN_WIDTH);
  135.     height = (int) window_get(confirmer, WIN_HEIGHT);
  136.  
  137.     left = (r->r_width - width) / 2;
  138.     top = (r->r_height - height) / 3;
  139.  
  140.         if (left < 0) 
  141.             left = 0; 
  142.      if (top < 0)
  143.         top = 0;
  144.  
  145.     window_set(confirmer, WIN_X, left, WIN_Y, top,
  146.             0);
  147.  
  148.         left = left + (width - width/3);
  149.         top = top + height / 2;      
  150.     window_set(base_frame, WIN_MOUSE_XY, left, top,  0);
  151.  
  152.     return confirmer;
  153. }
  154.  
  155. /* yes/no notify proc */
  156. static void
  157. yes_no(item, event)
  158. Panel_item   item;
  159. Event        *event;
  160. {
  161.     window_return(panel_get(item, PANEL_CLIENT_DATA));
  162. }
  163.  
  164.