home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / editres / svpopup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-08  |  9.0 KB  |  326 lines

  1. /*
  2.  * $XConsortium: svpopup.c,v 1.13 91/07/09 09:46:48 rws Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Chris D. Peterson, MIT X Consortium
  24.  */
  25.  
  26. #include <X11/Intrinsic.h>
  27. #include <X11/StringDefs.h>    /* Get standard string definations. */
  28. #include <X11/Xatom.h>
  29. #include <X11/cursorfont.h>
  30. #include <X11/Shell.h>
  31.  
  32. #include "editresP.h"
  33.  
  34. #include <X11/Xaw/AsciiText.h>
  35. #include <X11/Xaw/Cardinals.h>    
  36. #include <X11/Xaw/Command.h>    
  37. #include <X11/Xaw/Form.h>
  38. #include <X11/Xaw/Label.h>    
  39.  
  40. #include <stdio.h>
  41.  
  42. extern void SetMessage(), SetCommand(), InsertWidgetFromNode();
  43. extern void GetAllStrings(), PopupCentered();
  44.  
  45. static void _SetField(), CreateSetValuesPopup();
  46. static void DoSetValues(), CancelSetValues();
  47.  
  48. /*    Function Name: PopupSetValues
  49.  *    Description: This function pops up the setvalues dialog
  50.  *    Arguments: parent - the parent of the setvalues popup.
  51.  *                 event - the event that caused this popup, or NULL.
  52.  *    Returns: none
  53.  */
  54.  
  55. /* ARGSUSED */
  56. void
  57. PopupSetValues(parent, event)
  58. Widget parent;
  59. XEvent * event;
  60. {
  61.     Arg args[1];
  62.  
  63.     if (global_tree_info == NULL) {
  64.     SetMessage(global_screen_data.info_label,
  65.            "No widget Tree is avaliable.");
  66.     return;
  67.     }
  68.  
  69. /* 
  70.  * Check and possibly create the popup.
  71.  */
  72.  
  73.     if (global_screen_data.set_values_popup == NULL)
  74.     CreateSetValuesPopup(parent, &global_screen_data);
  75.  
  76. /*
  77.  * Clear out the old strings, and set the active widget to the name widget.
  78.  */
  79.  
  80.     XtSetArg(args[0], XtNstring, "");
  81.     XtSetValues(global_screen_data.res_text, args, ONE);
  82.     XtSetValues(global_screen_data.val_text, args, ONE);
  83.  
  84.     _SetField(global_screen_data.res_text, global_screen_data.val_text);
  85.  
  86. /*
  87.  * Pop it up.
  88.  */
  89.  
  90.     PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
  91. }
  92.  
  93. /*    Function Name: ModifySVEntry
  94.  *    Description: Action routine that can be bound to the set values 
  95.  *                   dialog box's Text Widget that will send input to the 
  96.  *                   field specified.
  97.  *    Arguments:   (Standard Action Routine args) 
  98.  *    Returns:     none.
  99.  */
  100.  
  101. /* ARGSUSED */
  102. void 
  103. ModifySVEntry(w, event, params, num_params)
  104. Widget w;
  105. XEvent *event;
  106. String * params;
  107. Cardinal * num_params;
  108. {
  109.     Widget new, old;
  110.     char msg[BUFSIZ];
  111.     
  112.     if (*num_params != 1) {
  113.     strcpy(msg, 
  114.            "Error: SVActiveEntry Action must have exactly one argument.");
  115.     SetMessage(global_screen_data.info_label, msg);
  116.     return;
  117.     }
  118.     
  119.     switch (params[0][0]) {
  120.     case 'r':
  121.     case 'R':
  122.     new = global_screen_data.res_text;
  123.     old = global_screen_data.val_text;
  124.     break;
  125.     case 'v':
  126.     case 'V':
  127.     new = global_screen_data.val_text;
  128.     old = global_screen_data.res_text;
  129.     break;
  130.     default:
  131.     sprintf(msg, "%s %s", "Error: SVActiveEntry Action's first Argument",
  132.         "must be either 'Resource' or 'Value'.");
  133.     SetMessage(global_screen_data.info_label, msg);
  134.     return;
  135.     }
  136.     
  137.     _SetField(new, old);
  138. }
  139.  
  140. /************************************************************
  141.  *
  142.  * Private Functions
  143.  *
  144.  ************************************************************/
  145.  
  146. /*    Function Name: _SetField
  147.  *    Description: Sets the current text entry field.
  148.  *    Arguments: new, old - new and old text fields.
  149.  *    Returns: none
  150.  */
  151.  
  152. static void
  153. _SetField(new, old)
  154. Widget new, old;
  155. {
  156.     Arg args[2];
  157.     Pixel new_border, old_border, old_bg;
  158.     
  159.     if (!XtIsSensitive(new)) {
  160.     XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
  161.     return;
  162.     }
  163.     
  164.     XtSetKeyboardFocus(XtParent(new), new); 
  165.     
  166.     XtSetArg(args[0], XtNborderColor, &old_border);
  167.     XtSetArg(args[1], XtNbackground, &old_bg);
  168.     XtGetValues(new, args, TWO);
  169.     
  170.     XtSetArg(args[0], XtNborderColor, &new_border);
  171.     XtGetValues(old, args, ONE);
  172.     
  173.     if (old_border != old_bg)    /* Colors are already correct, return. */
  174.     return;
  175.  
  176.     XtSetArg(args[0], XtNborderColor, old_border);
  177.     XtSetValues(old, args, ONE);
  178.  
  179.     XtSetArg(args[0], XtNborderColor, new_border);
  180.     XtSetValues(new, args, ONE);
  181. }
  182.  
  183. /*    Function Name: CreateSetValuesPopup
  184.  *    Description: Creates the setvalues popup.
  185.  *    Arguments: parent - the parent of the popup.
  186.  *                 scr_data - the data about this screen.
  187.  *    Returns: the set values popup.
  188.  */
  189.  
  190. static void
  191. CreateSetValuesPopup(parent, scr_data)
  192. Widget parent;
  193. ScreenData * scr_data;
  194. {
  195.     Widget form, cancel, do_it, label;
  196.     Widget res_label;
  197.     Arg args[10];
  198.     Cardinal num_args;
  199.     
  200.     scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup", 
  201.                             transientShellWidgetClass, 
  202.                             parent, NULL, ZERO);
  203.  
  204.     form = XtCreateManagedWidget("form", formWidgetClass, 
  205.                  scr_data->set_values_popup, NULL, ZERO);
  206.  
  207.     num_args = 0;
  208.     label = XtCreateManagedWidget("label", labelWidgetClass,
  209.                   form, args, num_args);
  210.  
  211.  
  212.     num_args = 0;
  213.     XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  214.     res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
  215.                   form, args, num_args);
  216.  
  217.     num_args = 0;
  218.     XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  219.     XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  220.     scr_data->res_text = XtCreateManagedWidget("resourceText", 
  221.                           asciiTextWidgetClass,
  222.                           form, args, num_args);
  223.  
  224.     num_args = 0;
  225.     XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  226.     (void)  XtCreateManagedWidget("valueLabel", labelWidgetClass,
  227.                   form, args, num_args);
  228.  
  229.     num_args = 0;
  230.     XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  231.     XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  232.     scr_data->val_text = XtCreateManagedWidget("valueText", 
  233.                           asciiTextWidgetClass,
  234.                           form, args, num_args);
  235.   
  236.     num_args = 0;
  237.     XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  238.     do_it = XtCreateManagedWidget("setValues", commandWidgetClass, 
  239.                       form, args, num_args);
  240.  
  241.     num_args = 0;
  242.     XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  243.     XtSetArg(args[num_args], XtNfromHoriz, do_it); num_args++;
  244.     cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  245.                    form, args, num_args);
  246.  
  247.     XtAddCallback(do_it, XtNcallback, DoSetValues, NULL);
  248.     XtAddCallback(cancel, XtNcallback, CancelSetValues, NULL);
  249.  
  250. /*
  251.  * Initialize the text entry fields.
  252.  */
  253.  
  254.     {
  255.     Pixel color;
  256.  
  257.     num_args = 0;
  258.     XtSetArg(args[num_args], XtNbackground, &color); num_args++;
  259.     XtGetValues(scr_data->val_text, args, num_args);
  260.  
  261.     num_args = 0;
  262.     XtSetArg(args[num_args], XtNborderColor, color); num_args++;
  263.     XtSetValues(scr_data->val_text, args, num_args);
  264.  
  265.     XtSetKeyboardFocus(form, scr_data->res_text);
  266.     }
  267. }
  268.  
  269. /*    Function Name: DoSetValues
  270.  *    Description: Performs a SetValues.
  271.  *    Arguments: w - the widget that called this.
  272.  *                 junk, garbage - ** UNUSED **.
  273.  *    Returns: none.
  274.  */
  275.  
  276. /* ARGSUSED */
  277. static void
  278. DoSetValues(w, junk, garbage)
  279. Widget w;
  280. caddr_t junk, garbage;
  281. {
  282.     ProtocolStream * stream = &(global_client.stream);
  283.     char *res_name, *res_value;
  284.     Arg args[1];
  285.     Cardinal i;
  286.  
  287.     if (global_tree_info->num_nodes == 0) {
  288.     SetMessage(global_screen_data.info_label,
  289.            "There are no currently active widgets.");
  290.     return;
  291.     }
  292.         
  293.     XtSetArg(args[0], XtNstring, &res_name);
  294.     XtGetValues(global_screen_data.res_text, args, ONE);
  295.  
  296.     XtSetArg(args[0], XtNstring, &res_value);
  297.     XtGetValues(global_screen_data.val_text, args, ONE);
  298.     
  299.     _XEditResResetStream(stream);
  300.     _XEditResPutString8(stream, res_name);
  301.     _XEditResPutString8(stream, XtRString);
  302.     _XEditResPutString8(stream, res_value);
  303.     _XEditResPut16(stream, global_tree_info->num_nodes);
  304.  
  305.     for (i = 0; i < global_tree_info->num_nodes; i++) 
  306.     InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
  307.  
  308.     SetCommand(w, LocalSetValues, NULL);
  309. }
  310.  
  311. /*    Function Name: CancelSetValues
  312.  *    Description: Pops down the setvalues popup.
  313.  *    Arguments: w - any grandchild of the popup.
  314.  *                 junk, garbage - ** UNUSED **.
  315.  *    Returns: none.
  316.  */
  317.  
  318. /* ARGSUSED */
  319. static void
  320. CancelSetValues(w, junk, garbage)
  321. Widget w;
  322. caddr_t junk, garbage;
  323. {
  324.     XtPopdown(XtParent(XtParent(w))); 
  325. }
  326.