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

  1. /*
  2.  * $XConsortium: widgets.c,v 1.20 92/02/11 11:44:24 dave 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.  
  24. /*
  25.  * Code for creating all widgets used by EditRes.
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <X11/Intrinsic.h>
  30. #include <X11/StringDefs.h>    /* Get standard string definations. */
  31.  
  32. #include <X11/Xaw/AsciiText.h>
  33. #include <X11/Xaw/Box.h>    
  34. #include <X11/Xaw/Cardinals.h>    
  35. #include <X11/Xaw/Label.h>    
  36. #include <X11/Xaw/List.h>    
  37. #include <X11/Xaw/MenuButton.h>    
  38. #include <X11/Xaw/Paned.h>    
  39. #include <X11/Xaw/Panner.h>    
  40. #include <X11/Xaw/Porthole.h>    
  41. #include <X11/Xaw/SmeBSB.h>    
  42. #include <X11/Xaw/SmeLine.h>    
  43. #include <X11/Xaw/SimpleMenu.h>    
  44. #include <X11/Xaw/Toggle.h>    
  45. #include <X11/Xaw/Tree.h>
  46. #include <X11/Xaw/Viewport.h>    
  47.  
  48. #include "editresP.h"
  49.  
  50. /*
  51.  * functions.
  52.  */
  53.  
  54. static void CreateResourceNameForm(), SetToggleGroupLeaders(), CreateLists();
  55. static void CreateCommandMenu(), CreateTreeCommandMenu(), FreeClientData();
  56. static void FreeResBox(), CreateValueWidget(), PopupOnNode();
  57. static Widget CreateTopArea();
  58. static void MakeBoxLookNice();
  59.  
  60. extern void GetResourceList(), AnyChosen(), SetResourceString();
  61. extern void PannerCallback(), PortholeCallback(), DumpTreeToFile();
  62. extern void Quit(), SendTree(), FlashActiveWidgets();
  63. extern void TreeSelect(), TreeRelabel(), TreeActivate(), FindWidget();
  64. extern void ResourceListCallback(), PopdownResBox(), SaveResource();
  65. extern void GetNamesAndClasses(), ApplyResource(), ActivateResourceWidgets();
  66. extern void ActivateWidgetsAndSetResourceString(), SetFile();
  67.  
  68. extern void InitSetValues();
  69.  
  70. /*    Function Name: BuildWidgetTree
  71.  *    Description: Creates all widgets for Editres.
  72.  *    Arguments: parent - the shell to put them into.
  73.  *    Returns: none.
  74.  */
  75.  
  76. void 
  77. BuildWidgetTree(parent)
  78. Widget parent;
  79. {
  80.     Widget paned, porthole, panner;
  81.  
  82.     paned = XtCreateManagedWidget("paned", panedWidgetClass, parent,
  83.                   NULL, ZERO);
  84.  
  85.     panner = CreateTopArea(paned);
  86.  
  87.     porthole = XtCreateManagedWidget("porthole", portholeWidgetClass,
  88.                      paned, NULL, ZERO);
  89.  
  90. /*
  91.  * Allow the panner and porthole to talk to each other.
  92.  */
  93.  
  94.     XtAddCallback(porthole, 
  95.           XtNreportCallback, PortholeCallback, (XtPointer) panner);
  96.     XtAddCallback(panner, 
  97.           XtNreportCallback, PannerCallback, (XtPointer) porthole);
  98.  
  99.     global_tree_parent = porthole;
  100. }
  101.  
  102. /*    Function Name: CreateTopArea
  103.  *    Description: Creates the top part of the display
  104.  *    Arguments: parent - widget to put this menu bar into.
  105.  *    Returns: none. 
  106.  */
  107.  
  108. static Widget
  109. CreateTopArea(parent)
  110. Widget parent;
  111. {
  112.     Widget box, panner, pane;
  113.  
  114.     box = XtCreateManagedWidget("box", boxWidgetClass, parent, NULL, ZERO);
  115.  
  116.     CreateCommandMenu(box);
  117.     CreateTreeCommandMenu(box);
  118.  
  119.     pane = XtCreateManagedWidget("hPane", panedWidgetClass, parent, NULL,ZERO);
  120.  
  121.     {
  122.     panner = XtCreateManagedWidget("panner", pannerWidgetClass, 
  123.                        pane, NULL, ZERO);
  124.     global_screen_data.info_label = XtCreateManagedWidget("userMessage", 
  125.                                  labelWidgetClass,
  126.                                  pane, NULL, ZERO);
  127.     }
  128.     return(panner);
  129. }
  130.  
  131. /*    Function Name: CreateCommandMenu
  132.  *    Description: Creats the command menu.
  133.  *    Arguments: parent - widget to put this menu into.
  134.  *    Returns: none.
  135.  */
  136.  
  137. static void
  138. CreateCommandMenu(parent)
  139. Widget parent;
  140. {
  141.     Widget menu, entry, button;
  142.  
  143.     button = XtCreateManagedWidget("commands", menuButtonWidgetClass, parent,
  144.                    NULL, ZERO);
  145.  
  146.     menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, button,
  147.                   NULL, ZERO);
  148.     
  149.     entry = XtCreateManagedWidget("sendTree", smeBSBObjectClass, menu,
  150.                     NULL, ZERO);
  151.     XtAddCallback(entry, XtNcallback, SendTree, (XtPointer) TRUE);
  152.  
  153.     entry = XtCreateManagedWidget("refreshTree", smeBSBObjectClass, menu,
  154.                   NULL, ZERO);
  155.     XtAddCallback(entry, XtNcallback, SendTree, (XtPointer) FALSE);
  156.  
  157.     entry = XtCreateManagedWidget("dumpTreeToFile", smeBSBObjectClass, menu,
  158.                     NULL, ZERO);
  159.     XtAddCallback(entry, XtNcallback, DumpTreeToFile, NULL);
  160.  
  161.     entry = XtCreateManagedWidget("line", smeLineObjectClass, menu,
  162.                   NULL, ZERO);
  163.     entry= XtCreateManagedWidget("getResourceList", smeBSBObjectClass, menu,
  164.                  NULL, ZERO);
  165.     XtAddCallback(entry, XtNcallback, GetResourceList, NULL);
  166.  
  167.     entry = XtCreateManagedWidget("setValues", smeBSBObjectClass, menu,
  168.                     NULL, ZERO);
  169.     XtAddCallback(entry, XtNcallback, InitSetValues, NULL);
  170.  
  171.     entry = XtCreateManagedWidget("line", smeLineObjectClass, menu,
  172.                   NULL, ZERO);
  173.  
  174.     entry = XtCreateManagedWidget("quit", smeBSBObjectClass, menu,
  175.                     NULL, ZERO);
  176.     XtAddCallback(entry, XtNcallback, Quit, NULL);
  177.  
  178. }
  179.  
  180. /*    Function Name: CreateTreeCommandMenu
  181.  *    Description: Creats the command menu.
  182.  *    Arguments: parent - widget to put this menu into.
  183.  *    Returns: none.
  184.  */
  185.  
  186. #define SELECT 0
  187. #define ACTIVATE 1
  188. #define LABEL 2
  189. #define LINE 3
  190. #define FIND 4
  191. #define FLASH 5
  192.  
  193. struct tree_ops_menu {
  194.     char * name;
  195.     int type;
  196.     XtPointer data;
  197. };
  198.  
  199. static void
  200. CreateTreeCommandMenu(parent)
  201. Widget parent;
  202. {
  203.     Widget menu, button, entry;
  204.     int i, number;
  205.     static struct tree_ops_menu tree_menu[] = {
  206.     { "showClientWidget", FIND, (XtPointer) NULL },
  207.         { "selectAll", SELECT, (XtPointer) SelectAll },
  208.     { "unselectAll", SELECT, (XtPointer) SelectNone },
  209.     { "invertAll", SELECT, (XtPointer) SelectInvert },
  210.     { "line", LINE, (XtPointer) NULL },
  211.     { "selectChildren", SELECT, (XtPointer) SelectChildren },
  212.         { "selectParent", SELECT, (XtPointer) SelectParent },
  213.     { "selectDescendants", SELECT, (XtPointer) SelectDescendants },
  214.         { "selectAncestors", SELECT, (XtPointer) SelectAncestors },
  215.         { "line", LINE, (XtPointer) NULL },
  216.         { "showWidgetNames", LABEL, (XtPointer) NameLabel },
  217.         { "showClassNames", LABEL, (XtPointer) ClassLabel },
  218.         { "showWidgetIDs", LABEL, (XtPointer) IDLabel},
  219.         { "showWidgetWindows", LABEL, (XtPointer) WindowLabel },
  220.         { "line", LINE, (XtPointer) NULL },
  221.     { "flashActiveWidgets", FLASH, (XtPointer) NULL }
  222.     };
  223.  
  224.     button = XtCreateManagedWidget("treeCommands", menuButtonWidgetClass,
  225.                    parent, NULL, ZERO);
  226.  
  227.     menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, button,
  228.                   NULL, ZERO);
  229.  
  230.     for ( i = 0, number = XtNumber(tree_menu) ; i < number ; i++) {
  231.     void (*func)();
  232.     WidgetClass class = smeBSBObjectClass;
  233.  
  234.     switch (tree_menu[i].type) {
  235.     case SELECT:
  236.         func = TreeSelect;
  237.         break;
  238.     case LABEL:
  239.         func = TreeRelabel;
  240.         break;
  241.     case LINE:
  242.         func = NULL;
  243.         class = smeLineObjectClass;
  244.         break;
  245.     case FIND:
  246.         func = FindWidget;
  247.         break;
  248.     case FLASH:
  249.         func = FlashActiveWidgets;
  250.         break;
  251.     default:
  252.         continue;
  253.     }
  254.  
  255.     entry = XtCreateManagedWidget(tree_menu[i].name, class, menu,
  256.                       NULL, ZERO);
  257.     if (func != NULL) 
  258.         XtAddCallback(entry, XtNcallback, func, tree_menu[i].data);
  259.     }
  260. }
  261.  
  262. static Pixmap old_pixmap;
  263.  
  264. /*    Function Name: PrepareToLayoutTree
  265.  *    Description: prepares the Tree widget to be layed out.
  266.  *    Arguments: tree - the Tree widget.
  267.  *    Returns: none
  268.  */
  269.  
  270. void
  271. PrepareToLayoutTree(tree)
  272. Widget tree;
  273. {
  274.     Arg args[1];
  275.  
  276.     XtSetArg(args[0], XtNbackgroundPixmap, &old_pixmap);
  277.     XtGetValues(XtParent(tree), args, ONE);
  278.  
  279.     XtSetArg(args[0], XtNbackgroundPixmap, None);
  280.     XtSetValues(XtParent(tree), args, ONE);
  281.  
  282.     XtUnmapWidget(tree);
  283. }
  284.  
  285. /*    Function Name: LayoutTree
  286.  *    Description: Laysout the tree widget.
  287.  *    Arguments: tree - the widget tree.
  288.  *    Returns: none.
  289.  */
  290.  
  291. void
  292. LayoutTree(tree)
  293. Widget tree;
  294. {
  295.     Arg args[1];
  296.     
  297.     XawTreeForceLayout(tree);
  298.     XtMapWidget(tree); 
  299.  
  300.     XtSetArg(args[0], XtNbackgroundPixmap, old_pixmap);
  301.     XtSetValues(XtParent(tree), args, ONE);
  302. }
  303.  
  304. /************************************************************
  305.  *
  306.  * Functions for creating the Resource Box.
  307.  *
  308.  ************************************************************/
  309.  
  310. /*    Function Name: CreateResourceBoxWidgets
  311.  *    Description: Creates the widgets that make up the resource box.
  312.  *    Arguments: node - the widget node.
  313.  *                 names - the list of names that make up the normal resources.
  314.  *                 cons_names - the list of names that make up 
  315.  *                              the constraint resources. 
  316.  *    Returns: none.
  317.  */
  318.  
  319. void
  320. CreateResourceBoxWidgets(node, names, cons_names)
  321. WNode * node;
  322. char **names, **cons_names;
  323. {
  324.     Widget pane, box, button;
  325.     ResourceBoxInfo * res_box;
  326.  
  327.     res_box = (ResourceBoxInfo *) XtMalloc(sizeof(ResourceBoxInfo));
  328.     node->resources->res_box = res_box;
  329.  
  330.     res_box->shell = XtCreatePopupShell(RESOURCE_BOX,
  331.                     transientShellWidgetClass,
  332.                     node->widget, NULL, ZERO);
  333.     XtAddCallback(res_box->shell, XtNdestroyCallback,
  334.           FreeResBox, (XtPointer) node);
  335.  
  336.     pane = XtCreateManagedWidget("pane", panedWidgetClass, 
  337.                  res_box->shell, NULL, ZERO);
  338.  
  339.     res_box->res_label = XtCreateManagedWidget("resourceLabel", 
  340.                            labelWidgetClass, 
  341.                            pane, NULL, ZERO);
  342.  
  343.     CreateResourceNameForm(pane, node);
  344.     CreateLists(pane, node, names, cons_names);
  345.     CreateValueWidget(pane, node);
  346.  
  347.     XtSetKeyboardFocus(pane, res_box->value_wid); /* send keyboard to value. */
  348.  
  349.     box = XtCreateManagedWidget("commandBox", boxWidgetClass,
  350.                  pane, NULL, ZERO);
  351.  
  352.     button = XtCreateManagedWidget("setFile", commandWidgetClass,
  353.                    box, NULL, ZERO);
  354.     XtAddCallback(button, XtNcallback, SetFile, NULL);
  355.  
  356.     button = XtCreateManagedWidget("save", commandWidgetClass,
  357.                    box, NULL, ZERO);
  358.     XtAddCallback(button, XtNcallback, SaveResource,(XtPointer) res_box);
  359.  
  360.     button = XtCreateManagedWidget("apply", commandWidgetClass,
  361.                    box, NULL, ZERO);
  362.     XtAddCallback(button, XtNcallback, ApplyResource,(XtPointer) node);
  363.  
  364.     button = XtCreateManagedWidget("saveAndApply", commandWidgetClass,
  365.                    box, NULL, ZERO);
  366.     XtAddCallback(button, XtNcallback, SaveResource,(XtPointer) res_box);
  367.     XtAddCallback(button, XtNcallback, ApplyResource,(XtPointer) node);
  368.  
  369.     button = XtCreateManagedWidget("cancel", commandWidgetClass,
  370.                    box, NULL, ZERO);
  371.     XtAddCallback(button,XtNcallback,PopdownResBox,(XtPointer)res_box->shell);
  372.  
  373.     SetToggleGroupLeaders(node);
  374.     PopupOnNode(node, res_box->shell);
  375. }
  376.  
  377. /*    Function Name: CreateResourceNameForm
  378.  *    Description: Creates the Form widget with children that represent
  379.  *                   the full resource name for this object.
  380.  *    Arguments: parent - parent of the form.
  381.  *                 node - the node corrosponding to this object.
  382.  *    Returns: none
  383.  */
  384.  
  385. static void
  386. CreateResourceNameForm(parent, node)
  387. Widget parent;
  388. WNode * node;
  389. {
  390.     ResourceBoxInfo * res_box = node->resources->res_box;
  391.     AnyInfo *new_info, *old_info;
  392.     char **names, **classes;
  393.     Widget form;
  394.     NameInfo * name_info = NULL;
  395.     Cardinal num_args;
  396.     Arg args[10];
  397.     int i;
  398.     Widget dot, star, name, class, single, any;
  399.  
  400.     GetNamesAndClasses(node, &names, &classes);
  401.  
  402.     form = XtCreateManagedWidget("namesAndClasses", formWidgetClass,
  403.                  parent, NULL, ZERO);
  404.  
  405.     name = class = any = NULL;
  406.     i = 0;
  407.     old_info = NULL;
  408.     while (TRUE) {
  409.  
  410.     num_args = 0;
  411.     XtSetArg(args[num_args], XtNfromHoriz, name); num_args++;
  412.     XtSetArg(args[num_args], XtNradioData, "."); num_args++;
  413.     dot = XtCreateManagedWidget("dot", toggleWidgetClass, 
  414.                     form, args, num_args);
  415.     XtAddCallback(dot, XtNcallback, 
  416.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  417.  
  418.     num_args = 0;
  419.     XtSetArg(args[num_args], XtNfromHoriz, class); num_args++;
  420.     XtSetArg(args[num_args], XtNfromVert, dot); num_args++;
  421.     XtSetArg(args[num_args], XtNradioGroup, dot); num_args++;
  422.     XtSetArg(args[num_args], XtNradioData, "*"); num_args++;
  423.     star = XtCreateManagedWidget("star", toggleWidgetClass, 
  424.                      form, args, num_args);
  425.     XtAddCallback(star,XtNcallback, 
  426.               ActivateWidgetsAndSetResourceString, (XtPointer) node);
  427.  
  428.     if (name_info != NULL) {
  429.         name_info->next = (NameInfo *) XtMalloc(sizeof(NameInfo));
  430.         name_info = name_info->next;
  431.     }
  432.     else
  433.         res_box->name_info = 
  434.              name_info = (NameInfo *) XtMalloc(sizeof(NameInfo));
  435.  
  436.     name_info->sep_leader = dot;
  437.     name_info->name_leader = NULL;
  438.  
  439.     if (names[i] != NULL) {
  440.         new_info = (AnyInfo *) XtMalloc(sizeof(AnyInfo));
  441.         new_info->node = node;
  442.         new_info->left_dot = dot;
  443.         new_info->left_star = star;
  444.         new_info->left_count = 0;
  445.         if (old_info != NULL) 
  446.         old_info->right_count = &(new_info->left_count);
  447.     }
  448.     else if (old_info != NULL) 
  449.         old_info->right_count = NULL;
  450.  
  451.     if (old_info != NULL) {
  452.         old_info->right_dot = dot;
  453.         old_info->right_star = star;
  454.  
  455.         XtAddCallback(any, XtNcallback, AnyChosen, (XtPointer) old_info);
  456.         XtAddCallback(any, XtNdestroyCallback, 
  457.               FreeClientData, (XtPointer) old_info);
  458.     }
  459.  
  460.     if ( names[i] == NULL) /* no more name and class boxes. */
  461.         break;
  462.  
  463.     old_info = new_info;
  464.  
  465.     num_args = 0;
  466.     XtSetArg(args[num_args], XtNfromHoriz, dot); num_args++;
  467.     XtSetArg(args[num_args], XtNlabel, names[i]); num_args++;
  468.     XtSetArg(args[num_args], XtNradioData, names[i]); num_args++;
  469.     name = XtCreateManagedWidget("name", toggleWidgetClass, 
  470.                      form, args, num_args);
  471.     XtAddCallback(name,XtNcallback,
  472.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  473.  
  474.     num_args = 0;
  475.     XtSetArg(args[num_args], XtNfromHoriz, star); num_args++;
  476.     XtSetArg(args[num_args], XtNfromVert, name); num_args++;
  477.     XtSetArg(args[num_args], XtNlabel, classes[i]); num_args++;
  478.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  479.     XtSetArg(args[num_args], XtNradioData, classes[i]); num_args++;
  480.     class = XtCreateManagedWidget("class", toggleWidgetClass, 
  481.                       form,args,num_args);
  482.     XtAddCallback(class, XtNcallback,
  483.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  484.  
  485.     num_args = 0;
  486.     XtSetArg(args[num_args], XtNfromHoriz, star); num_args++;
  487.     XtSetArg(args[num_args], XtNfromVert, class); num_args++;
  488.     XtSetArg(args[num_args], XtNradioData, "?"); num_args++;
  489.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  490.     single = XtCreateManagedWidget("single", toggleWidgetClass, 
  491.                        form, args, num_args);
  492.     XtAddCallback(single,XtNcallback,
  493.               ActivateWidgetsAndSetResourceString,(XtPointer) node);
  494.  
  495.     num_args = 0;
  496.     XtSetArg(args[num_args], XtNfromHoriz, any); num_args++;
  497.     XtSetArg(args[num_args], XtNfromVert, single); num_args++;
  498.     XtSetArg(args[num_args], XtNradioGroup, name); num_args++;
  499.     XtSetArg(args[num_args], XtNradioData, ANY_RADIO_DATA); num_args++;
  500.     any = XtCreateManagedWidget("any", toggleWidgetClass, 
  501.                     form, args, num_args);
  502.  
  503.     name_info->name_leader = name;
  504.  
  505.     MakeBoxLookNice(dot, star, any, single, name, class,
  506.             (i == 0 ? -1 : (names[i + 1] ? 0 : 1)));
  507.  
  508.     i++;
  509.     }
  510.  
  511.     name_info->next = NULL;
  512.     XtFree((char *)names);        /* Free what you allocate... */
  513.     XtFree((char *)classes);
  514. }
  515.  
  516. /*    Function Name: SetToggleGroupLeaders
  517.  *    Description: Sets the leaders of each toggle group.
  518.  *                 node - The widget node containing this res box.
  519.  *    Returns: none
  520.  */
  521.  
  522. static void
  523. SetToggleGroupLeaders(node)
  524. WNode * node;
  525. {
  526.     NameInfo *name;
  527.     ResourceBoxInfo * res_box = node->resources->res_box;
  528.     static Arg args[] = {
  529.     {XtNstate, (XtArgVal) TRUE}
  530.     };
  531.  
  532.     for (name  = res_box->name_info; name != NULL; name = name->next) {
  533.     XtSetValues(name->sep_leader, args, XtNumber(args));
  534.     if (name->name_leader != NULL)
  535.         XtSetValues(name->name_leader, args, XtNumber(args));
  536.     }
  537.     SetResourceString(NULL, (XtPointer) node, NULL);
  538. }
  539.  
  540. /*    Function Name: MakeBoxLookNice
  541.  *    Description: Resizes the box that contains the resource names
  542.  *                   to look a bit nicer.
  543.  *    Arguments: dot, star - the widgets containing the separator types.
  544.  *                 any, single, name, class - the widgets that contain the
  545.  *                                     name and class of this object.
  546.  *    Returns: none.
  547.  */
  548.  
  549. static void
  550. MakeBoxLookNice(dot, star, any, single, name, class, endbox)
  551. Widget dot, star, any, single, name, class;
  552. int endbox;
  553. {
  554.  
  555. #define MAX_HDIST 3
  556.  
  557.     Arg args[10];
  558.     Cardinal num_args;
  559.     Dimension any_width, name_class_width, dot_star_width;
  560.     Dimension width_1, width_2;
  561.     int h_dist[MAX_HDIST];
  562.     int i;
  563.  
  564.     /*
  565.      * Make sure that the dot and star widgets are the same size.
  566.      */
  567.  
  568.     num_args = 0;
  569.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[0])); num_args++;
  570.     XtSetArg(args[num_args], XtNwidth, &width_1); num_args++;
  571.     XtGetValues(dot, args, num_args);
  572.  
  573.     num_args = 0;
  574.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  575.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  576.     XtGetValues(star, args, num_args);
  577.  
  578.     num_args = 0;
  579.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[2])); num_args++;
  580.     XtSetArg(args[num_args], XtNwidth, &any_width); num_args++;
  581.     XtGetValues(any, args, num_args);
  582.     
  583.     dot_star_width = (width_1 > width_2) ? width_1 : width_2;
  584.     for (i = 1 ; i < MAX_HDIST; i++) {
  585.     if (h_dist[i] > h_dist[0]) h_dist[0] = h_dist[i];
  586.     }
  587.  
  588.     num_args = 0;
  589.     XtSetArg(args[num_args], XtNhorizDistance, h_dist[0]); num_args++;
  590.     XtSetValues(any, args, num_args);
  591.     
  592.     /*
  593.      * Add a new arg, and continue...
  594.      */
  595.     XtSetArg(args[num_args], XtNwidth, dot_star_width); num_args++; 
  596.     XtSetValues(star, args, num_args);
  597.     XtSetValues(dot, args, num_args);
  598.  
  599.  
  600.     /*
  601.      * Now make sure that the Any Widget is as wide as the longest
  602.      * of the name and class widgets, plus space for the dot and star widgets.
  603.      * Don't forget the Form widget's internal space.
  604.      */
  605.  
  606.     num_args = 0;
  607.     XtSetArg(args[num_args], XtNwidth, &width_1); num_args++;
  608.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[0])); num_args++;
  609.     XtGetValues(name, args, num_args);
  610.  
  611.     num_args = 0;
  612.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  613.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  614.     XtGetValues(class, args, num_args);
  615.  
  616.     if (width_2 > width_1) width_1 = width_2;
  617.     if (h_dist[1] > h_dist[0]) h_dist[0] = h_dist[1];
  618.  
  619.     num_args = 0;
  620.     XtSetArg(args[num_args], XtNwidth, &width_2); num_args++;
  621.     XtSetArg(args[num_args], XtNhorizDistance, &(h_dist[1])); num_args++;
  622.     XtGetValues(single, args, num_args);
  623.  
  624.     name_class_width = (width_1 > width_2) ? width_1 : width_2;
  625.     if (h_dist[1] > h_dist[0]) h_dist[0] = h_dist[1];
  626.     if (any_width > name_class_width)
  627.     name_class_width = any_width;
  628.     any_width = dot_star_width + h_dist[0] + name_class_width;
  629.     if (endbox < 0)
  630.     any_width += dot_star_width / 2;
  631.     else if (endbox > 0)
  632.     any_width += (dot_star_width - dot_star_width / 2);
  633.  
  634.     num_args = 0;
  635.     XtSetArg(args[num_args], XtNwidth, any_width); num_args++;
  636.     XtSetValues(any, args, num_args);    
  637.  
  638.     num_args = 0;
  639.     XtSetArg(args[num_args], XtNwidth, name_class_width); num_args++;
  640.     XtSetArg(args[num_args], XtNhorizDistance, h_dist[0]); num_args++;
  641.     XtSetValues(name, args, num_args);    
  642.     XtSetValues(class, args, num_args);    
  643.     XtSetValues(single, args, num_args);    
  644. }
  645.  
  646. /*    Function Name: CreateLists
  647.  *    Description: Creates the list widgets for the normal and constraint 
  648.  *                   resources
  649.  *    Arguments: parent - parent of the lists.
  650.  *                 node - The widget node containing this res box.
  651.  *                 names, cons_names - lists for norm and cons resource boxes.
  652.  *    Returns: none
  653.  */
  654.  
  655. static void
  656. CreateLists(parent, node, names, cons_names) 
  657. Widget parent;
  658. WNode * node;
  659. char **names, **cons_names;
  660. {
  661.     Cardinal num_args;
  662.     ResourceBoxInfo * res_box = node->resources->res_box;
  663.     Arg args[1];
  664.  
  665.     (void) XtCreateManagedWidget("namesLabel", labelWidgetClass, 
  666.                  parent, NULL, ZERO);
  667.     
  668.     num_args = 0;
  669.     XtSetArg(args[num_args], XtNlist, names); num_args++;    
  670.     res_box->norm_list = XtCreateManagedWidget("namesList", listWidgetClass, 
  671.                       parent, args, num_args);
  672.     XtAddCallback(res_box->norm_list, XtNcallback, 
  673.           ResourceListCallback, (XtPointer) node);
  674.     XtAddCallback(res_box->norm_list, XtNdestroyCallback, 
  675.           FreeClientData, (XtPointer) names);
  676.  
  677.     if (cons_names != NULL) {
  678.     (void) XtCreateManagedWidget("constraintLabel", labelWidgetClass, 
  679.                      parent, NULL, ZERO);
  680.     
  681.     num_args = 0;
  682.     XtSetArg(args[num_args], XtNlist, cons_names); num_args++;    
  683.     res_box->cons_list = XtCreateManagedWidget("constraintList", 
  684.                            listWidgetClass, 
  685.                            parent, args, num_args);
  686.     XtAddCallback(res_box->cons_list, XtNcallback, 
  687.               ResourceListCallback, (XtPointer) node);
  688.     XtAddCallback(res_box->cons_list, XtNdestroyCallback, 
  689.               FreeClientData, (XtPointer) cons_names);
  690.     }
  691.     else 
  692.     res_box->cons_list = NULL;
  693. }
  694.  
  695. /*    Function Name: CreateValueWidget
  696.  *    Description: Creates the value widget for entering the resources value.
  697.  *    Arguments: parent - parent of this widget.
  698.  *                 res_box - the resource box info.
  699.  *    Returns: none.
  700.  */
  701.  
  702. static void
  703. CreateValueWidget(parent, node)
  704. Widget parent;
  705. WNode * node;
  706. {
  707.     Widget form, label;
  708.     Cardinal num_args;
  709.     Arg args[10];
  710.     ResourceBoxInfo * res_box = node->resources->res_box;
  711.     
  712.     form = XtCreateManagedWidget("valueForm", formWidgetClass,
  713.                  parent, NULL, ZERO);
  714.  
  715.     num_args = 0;
  716.     XtSetArg(args[num_args], XtNleft, XawChainLeft); num_args++;
  717.     XtSetArg(args[num_args], XtNright, XawChainLeft); num_args++;
  718.     XtSetArg(args[num_args], XtNtop, XawChainTop); num_args++;
  719.     XtSetArg(args[num_args], XtNbottom, XawChainBottom); num_args++;
  720.     label = XtCreateManagedWidget("valueLabel", labelWidgetClass, 
  721.                  form, args, num_args);
  722.  
  723.     num_args = 0;
  724.     XtSetArg(args[num_args], XtNfromHoriz, label); num_args++;
  725.     XtSetArg(args[num_args], XtNleft, XawChainLeft); num_args++;
  726.     XtSetArg(args[num_args], XtNright, XawChainRight); num_args++;
  727.     XtSetArg(args[num_args], XtNtop, XawChainTop); num_args++;
  728.     XtSetArg(args[num_args], XtNbottom, XawChainBottom); num_args++;
  729.     res_box->value_wid = XtCreateManagedWidget("valueText", 
  730.                            asciiTextWidgetClass, 
  731.                            form, args, num_args);
  732. #ifdef notdef
  733.     XtAddCallback(XawTextGetSource(res_box->value_wid), XtNcallback,
  734.           SetResourceString, (XtPointer) node);
  735. #endif
  736. }
  737.  
  738. /*    Function Name: PopupOnNode
  739.  *    Description: Pops a shell widget up centered on the node specified.
  740.  *    Arguments: node - the node.
  741.  *                 shell - the shell to popup.
  742.  *    Returns: none.
  743.  */
  744.  
  745. extern Atom wm_delete_window;
  746.  
  747. static void
  748. PopupOnNode(node, shell)
  749. WNode * node;
  750. Widget shell;
  751. {
  752.     Arg args[3];
  753.     Cardinal num_args;
  754.     Position x, y;
  755.     Dimension width, height, bw;
  756.  
  757.     num_args = 0;
  758.     XtSetArg(args[num_args], XtNwidth, &width); num_args++;
  759.     XtSetArg(args[num_args], XtNheight, &height); num_args++;
  760.     XtSetArg(args[num_args], XtNborderWidth, &bw); num_args++;
  761.     XtGetValues(node->widget, args, num_args);
  762.     XtTranslateCoords(node->widget, 
  763.               (Position) (width/2 + bw), (Position) (height/2 + bw),
  764.               &x, &y);
  765.     
  766.     XtOverrideTranslations
  767.       (shell, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  768.     XtRealizeWidget(shell);
  769.     wm_delete_window = XInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW",
  770.                    False);
  771.     (void) XSetWMProtocols (XtDisplay(shell), XtWindow(shell),
  772.                             &wm_delete_window, 1);
  773.     XtGetValues(shell, args, num_args);    /* use same arg_list. */
  774.  
  775.     x -= (Position) (width/2 + bw);
  776.     y -= (Position) (height/2 + bw);
  777.  
  778.     if (x < 0)
  779.     x = 0;
  780.     else {
  781.     Position max_loc = WidthOfScreen(XtScreen(shell)) - 
  782.                          (Position) (width + 2 * bw);
  783.     if (x > max_loc)
  784.         x = max_loc;
  785.     }
  786.  
  787.     if (y < 0) 
  788.     y = 0;
  789.     else {
  790.     Position max_loc = HeightOfScreen(XtScreen(shell)) - 
  791.                          (Position) (height + 2 * bw);
  792.     if (y > max_loc)
  793.         y = max_loc;
  794.     }
  795.  
  796.     num_args = 0;
  797.     XtSetArg(args[num_args], XtNx, x); num_args++;
  798.     XtSetArg(args[num_args], XtNy, y); num_args++;
  799.     XtSetValues(shell, args, num_args);
  800.  
  801.     XtPopup(shell, XtGrabNone);
  802. }
  803.  
  804. /*    Function Name: FreeClientData
  805.  *    Description: Frees the client data passed to this function.
  806.  *    Arguments: w - UNUSED.
  807.  *                 list_ptr - pointer to the list to check.
  808.  *                 junk - UNUSED.
  809.  *    Returns: none
  810.  */
  811.  
  812. /* ARGSUSED */
  813. static void
  814. FreeClientData(w, ptr, junk)
  815. Widget w;
  816. XtPointer ptr, junk;
  817. {
  818.     XtFree(ptr);
  819. }
  820.  
  821. /*    Function Name: FreeResBox.
  822.  *    Description: Frees resource box allocated memory.
  823.  *    Arguments: w - UNUSED.
  824.  *                 ptr - pointer to the node that has this resources box.
  825.  *                 junk - UNUSED.
  826.  *    Returns: none
  827.  */
  828.  
  829. /* ARGSUSED */
  830. static void
  831. FreeResBox(w, ptr, junk)
  832. Widget w;
  833. XtPointer ptr, junk;
  834. {
  835.     WNode * node = (WNode *) ptr;
  836.     NameInfo *old_name, *name = node->resources->res_box->name_info;
  837.     
  838.     global_resource_box_up = FALSE;
  839.  
  840.     XtFree((XtPointer) node->resources->res_box);
  841.     node->resources->res_box = NULL;
  842.  
  843.     while (name != NULL) {
  844.     old_name = name;
  845.     name = name->next;
  846.     XtFree((XtPointer) old_name);
  847.     } 
  848. }
  849.  
  850.  
  851.     
  852.