home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3065 / edit-defaults.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-15  |  8.9 KB  |  303 lines

  1. /*
  2.  *    edit-defaults.c : Modify default parameters
  3.  *
  4.  *    George Ferguson, ferguson@cs.rochester.edu, 27 Feb 1991.
  5.  *
  6.  *    $Id: edit-defaults.c,v 2.1 91/02/28 11:21:17 ferguson Exp $
  7.  */
  8. #include <stdio.h>
  9. #include <X11/Intrinsic.h>
  10. #include <X11/Shell.h>
  11. #include <X11/StringDefs.h>
  12. #include <X11/Xaw/Form.h>
  13. #include <X11/Xaw/Command.h>
  14. #include <X11/Xaw/Label.h>
  15. #include <X11/Xaw/AsciiText.h>
  16. #include <X11/Xaw/Cardinals.h>
  17. #include "xkal.h"
  18. #include "month.h"
  19. #include "day.h"
  20. #include "app-resources.h"
  21. #ifdef USE_ALERT
  22. #include "alert.h"
  23. #endif
  24.  
  25. /*
  26.  * Functions declared in this file
  27.  */
  28. void editDefaults();
  29. void focusNextDefaultsItem(),focusPrevDefaultsItem();
  30.  
  31. static void initDefaultsShell(),setDefaultsItems(),setText();
  32. static void applyProc(),revertProc(),dismissProc();
  33.  
  34. /*
  35.  * Data declared in this file
  36.  */
  37. static Widget defaultsShell,defaultsForm;
  38. static Widget applyButton,revertButton,dismissButton;
  39. static Widget pAppsLabel,pAppsText,bakExtLabel,bakExtText,dateLabel,dateText;
  40. static Widget numMonLabel,numMonText;
  41. static Widget chkIntLabel,chkIntText,reaSilLabel,reaSilText;
  42. static Widget defLevLabel,defLevText,levDelLabel,levDelText;
  43.  
  44. #define ACTION_PROC(NAME)    void NAME(w,event,params,num_params) \
  45.                     Widget w; \
  46.                     XEvent *event; \
  47.                     String *params; \
  48.                     Cardinal *num_params;
  49.  
  50. #define CALLBACK_PROC(NAME)    static void NAME(w,client_data,call_data) \
  51.                     Widget w; \
  52.                     caddr_t client_data,call_data;
  53.  
  54. /*    -    -    -    -    -    -    -    -    */
  55. /* External interface (action) procedure */
  56. /*
  57.  * editDefaults() : Pops up (possibly creating) the defaults editor,
  58.  *    and fills it with the information from the current values of
  59.  *    the application defaults.
  60.  */
  61. /*ARGSUSED*/
  62. ACTION_PROC(editDefaults)
  63. {
  64.     if (defaultsShell == NULL)
  65.     initDefaultsShell();
  66.     setDefaultsItems();
  67.     XtPopup(defaultsShell,XtGrabNone);
  68. }
  69.  
  70. /*    -    -    -    -    -    -    -    -    */
  71. /* Initialization procedures */
  72. /*
  73.  * initDefaultsShell() : Create the popup defaults editor.
  74.  */
  75. static void
  76. initDefaultsShell()
  77. {
  78.     defaultsShell = XtCreatePopupShell("defaultsShell",topLevelShellWidgetClass,
  79.                             toplevel,NULL,ZERO);
  80.     defaultsForm = XtCreateManagedWidget("defaultsForm",formWidgetClass,
  81.                         defaultsShell,NULL,ZERO);
  82.     applyButton = XtCreateManagedWidget("applyButton",commandWidgetClass,
  83.                             defaultsForm,NULL,ZERO);
  84.     XtAddCallback(applyButton,"callback",applyProc,NULL);
  85.     revertButton = XtCreateManagedWidget("revertButton",commandWidgetClass,
  86.                             defaultsForm,NULL,ZERO);
  87.     XtAddCallback(revertButton,"callback",revertProc,NULL);
  88.     dismissButton = XtCreateManagedWidget("dismissButton",commandWidgetClass,
  89.                             defaultsForm,NULL,ZERO);
  90.     XtAddCallback(dismissButton,"callback",dismissProc,NULL);
  91.  
  92.     pAppsLabel = XtCreateManagedWidget("personalAppointsLabel",labelWidgetClass,
  93.                             defaultsForm,NULL,ZERO);
  94.     pAppsText = XtCreateManagedWidget("personalAppointsText",
  95.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  96.     bakExtLabel = XtCreateManagedWidget("backupExtensionLabel",labelWidgetClass,
  97.                             defaultsForm,NULL,ZERO);
  98.     bakExtText = XtCreateManagedWidget("backupExtensionText",
  99.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  100.     dateLabel = XtCreateManagedWidget("dateLabel",labelWidgetClass,
  101.                             defaultsForm,NULL,ZERO);
  102.     dateText = XtCreateManagedWidget("dateText",
  103.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  104.     numMonLabel = XtCreateManagedWidget("numMonthsLabel",labelWidgetClass,
  105.                             defaultsForm,NULL,ZERO);
  106.     numMonText = XtCreateManagedWidget("numMonthsText",
  107.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  108.     chkIntLabel = XtCreateManagedWidget("checkpointIntervalLabel",
  109.                 labelWidgetClass,defaultsForm,NULL,ZERO);
  110.     chkIntText = XtCreateManagedWidget("checkpointIntervalText",
  111.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  112.     reaSilLabel = XtCreateManagedWidget("rearrangeSilentlyLabel",
  113.                 labelWidgetClass,defaultsForm,NULL,ZERO);
  114.     reaSilText = XtCreateManagedWidget("rearrangeSilentlyText",
  115.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  116.     defLevLabel = XtCreateManagedWidget("defaultLevelLabel",labelWidgetClass,
  117.                             defaultsForm,NULL,ZERO);
  118.     defLevText = XtCreateManagedWidget("defaultLevelText",
  119.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  120.     levDelLabel = XtCreateManagedWidget("levelDelimLabel",labelWidgetClass,
  121.                             defaultsForm,NULL,ZERO);
  122.     levDelText = XtCreateManagedWidget("levelDelimText",
  123.                 asciiTextWidgetClass,defaultsForm,NULL,ZERO);
  124. }
  125.  
  126. /*
  127.  * setDefaultsItems() : Sets the values in the defaults editor from the
  128.  *    current state of the application resources.
  129.  */
  130. static void
  131. setDefaultsItems()
  132. {
  133.     char buf[8];
  134.  
  135.     setText(pAppsText,appResources.personalAppoints);
  136.     setText(bakExtText,appResources.backupExtension);
  137.     setText(dateText,appResources.date);
  138.     sprintf(buf,"%d",appResources.numMonths);
  139.     setText(numMonText,buf);
  140.     sprintf(buf,"%d",appResources.checkpointInterval);
  141.     setText(chkIntText,buf);
  142.     setText(reaSilText,appResources.rearrangeSilently ? "True" : "False");
  143.     sprintf(buf,"%d",appResources.defaultLevel);
  144.     setText(defLevText,buf);
  145.     setText(levDelText,appResources.levelDelim);
  146. }
  147.  
  148. /*
  149.  * setText() : Set the value of a text item.
  150.  */
  151. static void
  152. setText(item,text)
  153. Widget item;
  154. char *text;
  155. {
  156.     Arg args[1];
  157.  
  158.     XtSetArg(args[0],XtNstring,text);
  159.     XtSetValues(item,args,ONE);
  160. }
  161.  
  162. /*    -    -    -    -    -    -    -    -    */
  163. /* Callback procedures */
  164. /*
  165.  * applyProc() : Callback for apply button - Set the application resources
  166.  *    from the items on the defaults editor panel. Some of these require
  167.  *    special action when changed, and this routine does that.
  168.  */
  169. /*ARGSUSED*/
  170. CALLBACK_PROC(applyProc)
  171. {
  172.     Arg args[1];
  173.     char *s;
  174.     int n;
  175.  
  176.     XtSetArg(args[0],XtNstring,&(appResources.personalAppoints));
  177.     XtGetValues(pAppsText,args,ONE);
  178.     XtSetArg(args[0],XtNstring,&(appResources.backupExtension));
  179.     XtGetValues(bakExtText,args,ONE);
  180.     XtSetArg(args[0],XtNstring,&s);
  181.     XtGetValues(dateText,args,ONE);
  182.     if (strcmp(s,appResources.date) != 0) {
  183.     appResources.date = XtNewString(s);        /* leak! */
  184.     parseDate(appResources.date,¤tDay,¤tMon,¤tYear);
  185.     }
  186.     XtSetArg(args[0],XtNstring,&s);
  187.     XtGetValues(numMonText,args,ONE);
  188.     if (strcmp(s,"1") != 0 && strcmp(s,"2") != 0 &&
  189.                 strcmp(s,"3") != 0 && strcmp(s,"12") != 0) {
  190. #ifdef USE_ALERT
  191.     alert("Error: numMonths must be 1, 2, 3, or 12.");
  192. #else
  193.     fprintf(stderr,"\007%s: numMonths must be 1, 2, 3, or 12\n",program);
  194. #endif
  195.     } else if (n != appResources.numMonths) {
  196.     n = ONE;
  197.     setNumMonths((Widget)NULL,(XEvent *)NULL,&s,&n);
  198.     }
  199.     XtSetArg(args[0],XtNstring,&s);
  200.     XtGetValues(chkIntText,args,ONE);
  201.     n = atoi(s);
  202.     if (n != appResources.checkpointInterval) {
  203.     appResources.checkpointInterval = n;
  204.     XtRemoveTimeOut(timeoutId);
  205.     if (n > 0)
  206.         timeoutId = XtAppAddTimeOut(app_con,(unsigned long)(n*60000),
  207.                                 timeoutProc,NULL);
  208.     }
  209.     XtSetArg(args[0],XtNstring,&s);
  210.     XtGetValues(reaSilText,args,ONE);
  211.     n  = (strcasecmp(s,"True") == 0 || strcmp(s,"1") == 0);
  212.     if (n != appResources.rearrangeSilently) {
  213.     appResources.rearrangeSilently = n;
  214.     if (currentDayFormData != NULL) {
  215.         checkpointAppoints(currentDayFormData);
  216.         setDayFormData(currentDayFormData);
  217.     }
  218.     }
  219.     XtSetArg(args[0],XtNstring,&s);
  220.     XtGetValues(defLevText,args,ONE);
  221.     appResources.defaultLevel = atoi(s);
  222.     XtSetArg(args[0],XtNstring,&(appResources.levelDelim));
  223.     XtGetValues(levDelText,args,ONE);
  224. }
  225.  
  226. /*
  227.  * revertProc() : Callback for revert button - Reset the text strings to
  228.  *      the way they were when editDefaults was called last. Does NOT undo
  229.  *      any changed that were made.
  230.  */
  231. /*ARGSUSED*/
  232. CALLBACK_PROC(revertProc)
  233. {
  234.     setDefaultsItems();
  235. }
  236.  
  237. /*
  238.  * dismissProc() : Callback for dismiss button - Pop down the editor.
  239.  */
  240. /*ARGSUSED*/
  241. CALLBACK_PROC(dismissProc)
  242. {
  243.     XtPopdown(defaultsShell);
  244. }
  245.  
  246. /*    -    -    -    -    -    -    -    -    */
  247. /* Action procedures */
  248. /*
  249.  * focusNextDefaultstem() : Move input focus to next defaults editor item,
  250.  *    wrapping at bottom.
  251.  */
  252. /*ARGSUSED*/
  253. ACTION_PROC(focusNextDefaultsItem)
  254. {
  255.     if (w == pAppsText)
  256.     w = bakExtText;
  257.     else if (w == bakExtText)
  258.     w = dateText;
  259.     else if (w == dateText)
  260.     w = numMonText;
  261.     else if (w == numMonText)
  262.     w = chkIntText;
  263.     else if (w == chkIntText)
  264.     w = reaSilText;
  265.     else if (w == reaSilText)
  266.     w = defLevText;
  267.     else if (w == defLevText)
  268.     w = levDelText;
  269.     else if (w == levDelText)
  270.     w = pAppsText;
  271.     else
  272.     return;
  273.     XSetInputFocus(display,XtWindow(w),RevertToParent,CurrentTime);
  274. }
  275.  
  276. /*
  277.  * focusNextDefaultsItem() : Move input focus to previous defaults editor item,
  278.  *    wrapping at top.
  279.  */
  280. /*ARGSUSED*/
  281. ACTION_PROC(focusPrevDefaultsItem)
  282. {
  283.     if (w == pAppsText)
  284.     w = levDelText;
  285.     else if (w == bakExtText)
  286.     w = pAppsText;
  287.     else if (w == dateText)
  288.     w = bakExtText;
  289.     else if (w == numMonText)
  290.     w = dateText;
  291.     else if (w == chkIntText)
  292.     w = numMonText;
  293.     else if (w == reaSilText)
  294.     w = chkIntText;
  295.     else if (w == defLevText)
  296.     w = reaSilText;
  297.     else if (w == levDelText)
  298.     w = defLevText;
  299.     else
  300.     return;
  301.     XSetInputFocus(display,XtWindow(w),RevertToParent,CurrentTime);
  302. }
  303.