1 /*
2  *
3 Copyright 1989, 1998  The Open Group
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24  */
25 
26 
27 #include <X11/Intrinsic.h>
28 #include <X11/StringDefs.h>
29 
30 #include <X11/Xaw/Cardinals.h>
31 #include <X11/Xaw/List.h>
32 #include <X11/Xaw/Panner.h>
33 #include <X11/Xaw/Toggle.h>
34 #include <X11/Xfuncs.h>
35 #include <X11/Xos.h>		/* for W_OK def */
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 
40 #include "editresP.h"
41 
42 /*
43  * Local function definitions.
44  */
45 static char * GetResourceName ( ResourceBoxInfo * res_box );
46 static void _AppendResourceString ( Widget w, XtPointer res_box_ptr,
47 				    XtPointer filename_ptr );
48 static void _SetResourcesFile ( Widget w, XtPointer junk,
49 				XtPointer filename_ptr );
50 static void ObtainResource ( XtPointer node_ptr );
51 static void CreateSetValuesCommand ( WNode * node, XtPointer info_ptr );
52 static void SetOnlyMatchingWidgets ( WNode * node, XtPointer info_ptr );
53 
54 /*	Function Name: Quit
55  *	Description: This function prints a message to stdout.
56  *	Arguments: w - ** UNUSED **
57  *                 call_data - ** UNUSED **
58  *                 client_data - ** UNUSED **
59  *	Returns: none
60  */
61 
62 /* ARGSUSED */
63 void
Quit(Widget w,XtPointer client_data,XtPointer call_data)64 Quit(Widget w, XtPointer client_data, XtPointer call_data)
65 {
66     XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
67     exit(0);
68 }
69 
70 /*	Function Name: SendTree
71  *	Description: This function initiates the client communication.
72  *                   by getting the resource tree.
73  *	Arguments: w - the widget that made the selection.
74  *                 value - a boolean value stored as a pointer.
75  *                         if True then get a new client, otherwise
76  *                         refresh the current client.
77  *                 call_data - ** UNUSED **
78  *	Returns: none
79  */
80 
81 /* ARGSUSED */
82 void
SendTree(Widget w,XtPointer value,XtPointer call_data)83 SendTree(Widget w, XtPointer value, XtPointer call_data)
84 {
85     if ((Boolean)(long) value)
86 	global_client.window = None;
87 
88     if (!XtIsWidget(w))     /* Make sure that we use a "Real" widget here. */
89 	w = XtParent(w);
90 
91     _XEditResResetStream(&(global_client.stream)); /* an empty message. */
92 
93     SetCommand(w, LocalSendWidgetTree, NULL);
94 }
95 
96 /*	Function Name: FindWidget
97  *	Description: Maps a widget in the client to one in the currently
98  *                   displayed widget tree.
99  *	Arguments: w - the widget that invoked this action.
100  *                 call_data, client_data ** UNUSED **
101  *	Returns: none
102  */
103 
104 /* ARGSUSED */
105 void
FindWidget(Widget w,XtPointer client_data,XtPointer call_data)106 FindWidget(Widget w, XtPointer client_data, XtPointer call_data)
107 {
108 
109     _FindWidget(XtParent(w));	/* Use parent since it is a "real"
110 				   widget not a rect_obj. */
111 }
112 
113 /*	Function Name: InitSetValues
114  *	Description: This function pops up the setvalues dialog
115  *	Arguments: w - the widget caused this action.
116  *                 call_data - ** UNUSED **
117  *                 client_data - ** UNUSED **
118  *	Returns: none
119  */
120 
121 /* ARGSUSED */
122 void
InitSetValues(Widget w,XtPointer client_data,XtPointer call_data)123 InitSetValues(Widget w, XtPointer client_data, XtPointer call_data)
124 {
125     if (!XtIsWidget(w))     /* Make sure that we use a "Real" widget here. */
126 	w = XtParent(w);
127 
128     PopupSetValues(w, NULL);
129 }
130 
131 /*	Function Name: TreeSelect
132  *	Description: Selects all widgets.
133  *	Arguments: w - the widget caused this action.
134  *                 call_data - ** UNUSED **
135  *                 client_data - The type of thing to select.
136  *	Returns: none
137  */
138 
139 /* ARGSUSED */
140 void
TreeSelect(Widget w,XtPointer client_data,XtPointer call_data)141 TreeSelect(Widget w, XtPointer client_data, XtPointer call_data)
142 {
143     SelectTypes type = (SelectTypes) (unsigned long) client_data;
144 
145     _TreeSelect(global_tree_info, type);
146 }
147 
148 /*	Function Name: TreeRelabel
149  *	Description: Relabels a tree to the type specified.
150  *	Arguments: w - the widget caused this action.
151  *                 call_data - ** UNUSED **
152  *                 client_data - the type of label to assign to each node.
153  *	Returns: none
154  */
155 
156 /* ARGSUSED */
157 void
TreeRelabel(Widget w,XtPointer client_data,XtPointer call_data)158 TreeRelabel(Widget w, XtPointer client_data, XtPointer call_data)
159 {
160     LabelTypes type = (LabelTypes) (unsigned long) client_data;
161 
162     _TreeRelabel(global_tree_info, type);
163 }
164 
165 /*	Function Name: PannerCallback
166  *	Description: called when the panner has moved.
167  *	Arguments: panner - the panner widget.
168  *                 closure - *** NOT USED ***.
169  *                 report_ptr - the panner record.
170  *	Returns: none.
171  */
172 
173 /* ARGSUSED */
174 void
PannerCallback(Widget w,XtPointer closure,XtPointer report_ptr)175 PannerCallback(Widget w, XtPointer closure, XtPointer report_ptr)
176 {
177     Arg args[2];
178     XawPannerReport *report = (XawPannerReport *) report_ptr;
179 
180     if (global_tree_info == NULL)
181 	return;
182 
183     XtSetArg (args[0], XtNx, -report->slider_x);
184     XtSetArg (args[1], XtNy, -report->slider_y);
185 
186     XtSetValues(global_tree_info->tree_widget, args, TWO);
187 }
188 
189 /*	Function Name: PortholeCallback
190  *	Description: called when the porthole or its child has
191  *                   changed
192  *	Arguments: porthole - the porthole widget.
193  *                 panner_ptr - the panner widget.
194  *                 report_ptr - the porthole record.
195  *	Returns: none.
196  */
197 
198 /* ARGSUSED */
199 void
PortholeCallback(Widget w,XtPointer panner_ptr,XtPointer report_ptr)200 PortholeCallback(Widget w, XtPointer panner_ptr, XtPointer report_ptr)
201 {
202     Arg args[10];
203     Cardinal n = 0;
204     XawPannerReport *report = (XawPannerReport *) report_ptr;
205     Widget panner = (Widget) panner_ptr;
206 
207     XtSetArg (args[n], XtNsliderX, report->slider_x); n++;
208     XtSetArg (args[n], XtNsliderY, report->slider_y); n++;
209     if (report->changed != (XawPRSliderX | XawPRSliderY)) {
210 	XtSetArg (args[n], XtNsliderWidth, report->slider_width); n++;
211 	XtSetArg (args[n], XtNsliderHeight, report->slider_height); n++;
212 	XtSetArg (args[n], XtNcanvasWidth, report->canvas_width); n++;
213 	XtSetArg (args[n], XtNcanvasHeight, report->canvas_height); n++;
214     }
215     XtSetValues (panner, args, n);
216 }
217 
218 /*	Function Name: FlashActiveWidgets
219  *	Description: called to flass all active widgets in the display.
220  *	Arguments: *** NOT USED ***
221  *	Returns: none.
222  */
223 
224 /* ARGSUSED */
225 void
FlashActiveWidgets(Widget w,XtPointer junk,XtPointer garbage)226 FlashActiveWidgets(Widget w, XtPointer junk, XtPointer garbage)
227 {
228     _FlashActiveWidgets(global_tree_info);
229 }
230 
231 /*	Function Name: GetResourceList
232  *	Description: Gets the resources lists of all active widgets.
233  *	Arguments: ** NOT USED **
234  *	Returns: none
235  */
236 
237 /* ARGSUSED */
238 void
GetResourceList(Widget w,XtPointer junk,XtPointer garbage)239 GetResourceList(Widget w, XtPointer junk, XtPointer garbage)
240 {
241     WNode * node;
242     ProtocolStream * stream = &(global_client.stream);
243 
244     if (global_tree_info == NULL) {
245 	SetMessage(global_screen_data.info_label,
246 		   res_labels[17]);
247 	return;
248     }
249 
250     if (global_tree_info->num_nodes != 1) {
251 	SetMessage(global_screen_data.info_label,
252 	      res_labels[19]);
253 	return;
254     }
255 
256     node = global_tree_info->active_nodes[0];
257     if (node->resources != NULL) {
258 	char * errors = NULL;
259 	CreateResourceBox(node, &errors);
260 	if (errors != NULL) {
261 	    SetMessage(global_screen_data.info_label, errors);
262 	    XtFree(errors);
263 	}
264 	return;
265     }
266 
267     /*
268      * No resoruces, fetch them from the client.
269      */
270 
271     _XEditResResetStream(stream);
272     _XEditResPut16(stream, (unsigned short) 1);
273     InsertWidgetFromNode(stream, node);
274     SetCommand(global_tree_info->tree_widget, LocalGetResources, NULL);
275 }
276 
277 /*	Function Name: DumpTreeToFile
278  *	Description: Dumps all widgets in the tree to a file.
279  *	Arguments: w - the widget that activated this callback.
280  *                 junk, garbage - ** NOT USED **.
281  *	Returns: none.
282  */
283 
284 /* ARGSUSED */
285 void
DumpTreeToFile(Widget w,XtPointer junk,XtPointer garbage)286 DumpTreeToFile(Widget w, XtPointer junk, XtPointer garbage)
287 {
288     _PopupFileDialog(XtParent(w), "Enter the filename:", "",
289 		     _DumpTreeToFile, (XtPointer) global_tree_info);
290 }
291 
292 /************************************************************
293  *
294  * Callbacks for the Resource Box.
295  *
296  ************************************************************/
297 
298 
299 /*	Function Name: AnyChosen
300  *	Description: Callback that is called when the "any" widget
301  *                   is activated.
302  *	Arguments: w - the "any" widget that activated this callback.
303  *                 any_info_ptr - pointer to struct containing
304  *                                dot and star widgets to lock.
305  *                 state_ptr - state of the any toggle.
306  *	Returns: none.
307  */
308 
309 /* ARGSUSED */
310 void
AnyChosen(Widget w,XtPointer any_info_ptr,XtPointer state_ptr)311 AnyChosen(Widget w, XtPointer any_info_ptr, XtPointer state_ptr)
312 {
313     AnyInfo * any_info = (AnyInfo *) any_info_ptr;
314     Boolean state = (Boolean)(long) state_ptr;
315     Arg args[1];
316 
317     if (state) {
318 
319 	if (any_info->left_count == 0) {
320 	    XtSetSensitive(any_info->left_dot, FALSE);
321 	    XtSetSensitive(any_info->left_star, FALSE);
322 
323 	    XtSetArg(args[0], XtNstate, TRUE);
324 	    XtSetValues(any_info->left_star, args, ONE);
325 	}
326 
327 	if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) {
328 	    XtSetSensitive(any_info->right_dot, FALSE);
329 	    XtSetSensitive(any_info->right_star, FALSE);
330 
331 	    XtSetArg(args[0], XtNstate, TRUE);
332 	    XtSetValues(any_info->right_star, args, ONE);
333 	}
334 	any_info->left_count++;
335 
336 	if (any_info->right_count != NULL)
337 	    (*any_info->right_count)++;
338     }
339     else {			/* state == 0 */
340 	if (any_info->left_count > 0)
341 	    any_info->left_count--;
342 	if ((any_info->right_count != NULL)&&(*any_info->right_count > 0))
343 	    (*any_info->right_count)--;
344 
345 	if (any_info->left_count == 0) {
346 	    XtSetSensitive(any_info->left_dot, TRUE);
347 	    XtSetSensitive(any_info->left_star, TRUE);
348 
349 	    XtSetArg(args[0], XtNstate, TRUE);
350 	    XtSetValues(any_info->left_dot, args, ONE);
351 	}
352 
353 	if ((any_info->right_count == NULL)||(*any_info->right_count == 0)) {
354 	    XtSetSensitive(any_info->right_dot, TRUE);
355 	    XtSetSensitive(any_info->right_star, TRUE);
356 
357 	    XtSetArg(args[0], XtNstate, TRUE);
358 	    XtSetValues(any_info->right_dot, args, ONE);
359 	}
360     }
361     SetResourceString(NULL, (XtPointer) any_info->node, NULL);
362     ActivateResourceWidgets(NULL, (XtPointer) any_info->node, NULL);
363 }
364 
365 /*	Function Name: GetResourceName
366  *	Description: Gets the name of the current resource.
367  *	Arguments: res_box - the resource box.
368  *	Returns: the name of the currently selected resource.
369  */
370 
371 
372 static char *
GetResourceName(ResourceBoxInfo * res_box)373 GetResourceName(ResourceBoxInfo *res_box)
374 {
375     XawListReturnStruct * list_info;
376     char * result;
377 
378     list_info = XawListShowCurrent(res_box->norm_list);
379     if ((list_info->list_index == XAW_LIST_NONE) &&
380 	(res_box->cons_list != NULL)) {
381 	list_info = XawListShowCurrent(res_box->cons_list);
382     }
383 
384     if (list_info->list_index == XAW_LIST_NONE)
385 	result = "unknown";
386     else
387 	result = list_info->string;
388 
389     return(result);
390 }
391 
392 
393 /*	Function Name: ActivateWidgetsAndSetResourceString
394  *	Description: Sets the new resources string, then
395  *                   activates all widgets that match this resource,
396  *	Arguments: w - the widget that activated this.
397  *                 node_ptr - the node that owns this resource box.
398  *                 call_data - passed on to other callbacks.
399  *	Returns: none.
400  *
401  * NOTE: I cannot just have two callback routines, since I care which
402  *       order that these are executed in, sigh...
403  */
404 
405 void
ActivateWidgetsAndSetResourceString(Widget w,XtPointer node_ptr,XtPointer call_data)406 ActivateWidgetsAndSetResourceString(Widget w,
407 				    XtPointer node_ptr, XtPointer call_data)
408 {
409     SetResourceString(w, node_ptr, call_data);
410     ActivateResourceWidgets(w, node_ptr, call_data);
411 }
412 
413 /*	Function Name: SetResourceString
414  *	Description: Sets the resource label to correspond to the currently
415  *                   chosen string.
416  *	Arguments: w - The widget that invoked this callback, or NULL.
417  *                 node_ptr - pointer to widget node contating this res box.
418  *                 call_data - The call data for the action that invoked
419  *                             this callback.
420  *	Returns: none.
421  */
422 
423 void
SetResourceString(Widget w,XtPointer node_ptr,XtPointer junk)424 SetResourceString(Widget w, XtPointer node_ptr, XtPointer junk)
425 {
426     static char * malloc_string; /* These are both inited to zero. */
427     static Cardinal malloc_size;
428 
429     WNode * node = (WNode *) node_ptr;
430     ResourceBoxInfo * res_box = node->resources->res_box;
431     char * temp, buf[BUFSIZ * 10];	/* here's hoping it's big enough. */
432     NameInfo * name_node = res_box->name_info;
433     Arg args[1];
434     Cardinal len;
435 
436     if ((w != NULL) && XtIsSubclass(w, toggleWidgetClass)) {
437 	/*
438 	 * Only set resources when toggles are activated, not when they are
439 	 * deactivated.
440 	 */
441 	if (!((Boolean)(long) junk))
442 	    return;
443     }
444 
445     buf[0] = '\0';		/* clear out string. */
446 
447     /*
448      * Get the widget name/class info.
449      */
450 
451     if ((temp = (char *) XawToggleGetCurrent(name_node->sep_leader)) != NULL)
452 	strcat(buf, temp);
453 
454     for ( ; name_node->next != NULL ; name_node = name_node->next) {
455 	temp = (char *) XawToggleGetCurrent(name_node->name_leader);
456 	if ( (temp != NULL) && !streq(temp, ANY_RADIO_DATA) ) {
457 	    strcat(buf, temp);
458 	    temp = (char *) XawToggleGetCurrent(name_node->next->sep_leader);
459 	    if (temp == NULL)
460 		strcat(buf, "!");
461 	    else
462 		strcat(buf, temp);
463 	}
464     }
465 
466     strcat(buf, GetResourceName(res_box));
467     len = strlen(buf) + 2; /* Leave space for ':' and '\0' */
468 
469 #ifdef notdef
470     XtSetArg(args[0], XtNstring, &temp);
471     XtGetValues(res_box->value_wid, args, ONE);
472     len += strlen(temp);
473 #endif
474 
475     if (len > malloc_size) {
476 	malloc_string = XtRealloc(malloc_string, sizeof(char) * len);
477 	malloc_size = len;
478     }
479 
480     strcpy(malloc_string, buf);
481     strcat(malloc_string, ":");
482 #ifdef notdef
483     strcat(malloc_string, temp);
484 #endif
485 
486     XtSetArg(args[0], XtNlabel, malloc_string);
487     XtSetValues(res_box->res_label, args, ONE);
488 }
489 
490 /*	Function Name: ResourceListCallback
491  *	Description: Callback functions for the resource lists.  This
492  *                   routine is essentialy called by the list widgets
493  *                   Notify action.  If action EnableGetVal has been
494  *                   invoked,  ResourceListCallback will perform a
495  *                   GetValues protocol request.
496  *	Arguments: list - the list widget that we are dealing with.
497  *                 node_ptr - pointer to widget node contating this res box.
498  *                 junk - UNUSED.
499  *	Returns: none
500  */
501 
502 extern Boolean do_get_values;
503 
504 void
ResourceListCallback(Widget list,XtPointer node_ptr,XtPointer junk)505 ResourceListCallback(Widget list, XtPointer node_ptr, XtPointer junk)
506 {
507     Widget o_list;
508     WNode * node = (WNode *) node_ptr;
509     ResourceBoxInfo * res_box = node->resources->res_box;
510 
511     if (list == res_box->norm_list)
512 	o_list = res_box->cons_list;
513     else
514 	o_list = res_box->norm_list;
515 
516     if (o_list != NULL)
517 	XawListUnhighlight(o_list);
518 
519     SetResourceString(list, node_ptr, junk);
520 
521     /* get the resource value from the application */
522     if (global_effective_protocol_version >=
523 	PROTOCOL_VERSION_ONE_POINT_ONE && do_get_values) {
524       ObtainResource(node_ptr);
525       do_get_values = False;
526     }
527 }
528 
529 /*	Function Name: PopdownResBox
530  *	Description: Pops down the resource box.
531  *	Arguments: w - UNUSED
532  *                 shell_ptr - pointer to the shell to pop down.
533  *                 junk - UNUSED.
534  *	Returns: none
535  */
536 
537 /* ARGSUSED */
538 void
PopdownResBox(Widget w,XtPointer shell_ptr,XtPointer junk)539 PopdownResBox(Widget w, XtPointer shell_ptr, XtPointer junk)
540 {
541     Widget shell = (Widget) shell_ptr;
542 
543     XtPopdown(shell);
544     XtDestroyWidget(shell);
545 }
546 
547 /* ARGSUSED */
548 static void
_AppendResourceString(Widget w,XtPointer res_box_ptr,XtPointer filename_ptr)549 _AppendResourceString(Widget w, XtPointer res_box_ptr, XtPointer filename_ptr)
550 {
551     Arg args[1];
552     FILE * fp;
553     char buf[BUFSIZ], * resource_string, *filename = (char *) filename_ptr;
554     ResourceBoxInfo * res_box = (ResourceBoxInfo *) res_box_ptr;
555     char *value_ptr;
556 
557     if (filename != NULL) {
558 	if (global_resources.allocated_save_resources_file)
559 	    XtFree(global_resources.save_resources_file);
560 	else
561 	    global_resources.allocated_save_resources_file = TRUE;
562 
563 	global_resources.save_resources_file = XtNewString(filename);
564     }
565 
566     if ((fp = fopen(global_resources.save_resources_file, "a+")) == NULL) {
567 	snprintf(buf, sizeof(buf), "%s",
568                  "Unable to open this file for writing, would "
569                  "you like To try again?");
570 	_PopupFileDialog(global_toplevel ,buf,
571 			global_resources.save_resources_file,
572 			_AppendResourceString, res_box_ptr);
573 	return;
574     }
575 
576     XtSetArg(args[0], XtNlabel, &resource_string);
577     XtGetValues(res_box->res_label, args, ONE);
578 
579     XtSetArg(args[0], XtNstring, &value_ptr);
580     XtGetValues(res_box->value_wid, args, ONE);
581 
582     fprintf(fp, "%s %s\n", resource_string, value_ptr);
583 
584     fclose(fp);
585 }
586 
587 /*	Function Name: SaveResource
588  *	Description: Save the current resource to your resource file
589  *	Arguments: w - any widget in the application.
590  *                 res_box_ptr - the resource box info.
591  *                 junk - UNUSED.
592  *	Returns: none
593  */
594 
595 /* ARGSUSED */
596 void
SaveResource(Widget w,XtPointer res_box_ptr,XtPointer junk)597 SaveResource(Widget w, XtPointer res_box_ptr, XtPointer junk)
598 {
599     /*
600      * If there is no filename the ask for one, otherwise just save to
601      * current file.
602      */
603 
604     if (streq(global_resources.save_resources_file, ""))
605 	_PopupFileDialog(XtParent(w), "Enter file to dump resources into:",
606 			 global_resources.save_resources_file,
607 			 _AppendResourceString, res_box_ptr);
608     else
609 	_AppendResourceString(w, res_box_ptr, NULL);
610 }
611 
612 /*	Function Name: _SetResourcesFile
613  *	Description: Sets the filename of the file to save the resources to.
614  *	Arguments: w - UNUSED
615  *                 junk - UNUSED
616  *                 filename_ptr - a pointer to the filename;
617  *	Returns: none
618  */
619 
620 /* ARGSUSED */
621 static void
_SetResourcesFile(Widget w,XtPointer junk,XtPointer filename_ptr)622 _SetResourcesFile(Widget w, XtPointer junk, XtPointer filename_ptr)
623 {
624     char *filename = (char *) filename_ptr;
625 
626     if (global_resources.allocated_save_resources_file)
627 	XtFree(global_resources.save_resources_file);
628     else
629 	global_resources.allocated_save_resources_file = TRUE;
630 
631     global_resources.save_resources_file = XtNewString(filename);
632 }
633 
634 /*	Function Name: SetFile
635  *	Description: Changes the current save file
636  *	Arguments: w - UNUSED.
637  *                 res_box_ptr - UNUSED.
638  *                 junk - UNUSED.
639  *	Returns: none
640  */
641 
642 /* ARGSUSED */
643 void
SetFile(Widget w,XtPointer junk,XtPointer garbage)644 SetFile(Widget w, XtPointer junk, XtPointer garbage)
645 {
646     /*
647      * If there is no filename the ask for one, otherwise just save to
648      * current file.
649      */
650 
651     _PopupFileDialog(XtParent(w), "Enter file to dump resources into:",
652 		     global_resources.save_resources_file,
653 		     _SetResourcesFile, NULL);
654 }
655 
656 /*	Function Name: ApplyResource
657  *	Description: Apply the current resource to the running application.
658  *	Arguments: w - any widget in the application.
659  *                 node_ptr - a pointer to the node containing
660  *                            the current resouce box.
661  *                 junk - UNUSED.
662  *	Returns: none
663  */
664 
665 /* ARGSUSED */
666 void
ApplyResource(Widget w,XtPointer node_ptr,XtPointer junk)667 ApplyResource(Widget w, XtPointer node_ptr, XtPointer junk)
668 {
669     ProtocolStream * stream = &(global_client.stream);
670     ApplyResourcesInfo info;
671     WNode * node = (WNode *) node_ptr;
672     char * value;
673     unsigned short size, i;
674     long len;
675     Arg args[1];
676 
677     info.name = GetResourceName(node->resources->res_box);
678     info.class = "IGNORE_ME";	/* Not currently used.  */
679     info.stream = stream;
680     info.count = 0;
681 
682     XtSetArg(args[0], XtNlabel, &value);
683     XtGetValues(node->resources->res_box->res_label, args, ONE);
684 
685     info.database = NULL;
686     XrmPutLineResource(&(info.database), value);
687 
688 
689     _XEditResResetStream(stream);
690     _XEditResPutString8(stream, info.name); /* Insert name */
691     _XEditResPutString8(stream, XtRString); /* insert type */
692 
693     /*
694      * Insert value.
695      */
696 
697     value = GetResourceValueForSetValues(node, &size);
698     _XEditResPut16(stream, size);
699     for (i = 0; i < size; i++)
700 	_XEditResPut8(stream, value[i]);
701     XtFree(value);
702     len = stream->current - stream->top;
703 
704     /*
705      * Insert the widget count, overriden later.
706      */
707 
708     _XEditResPut16(stream, 0);
709 
710     ExecuteOverAllNodes(node->tree_info->top_node,
711 			CreateSetValuesCommand, (XtPointer) &info);
712 
713     if (info.count > 0) {
714 	*(stream->top + len++) = info.count >> XER_NBBY; /* Set the correct */
715 	*(stream->top + len) = info.count;               /* count. */
716 
717 	SetCommand(node->tree_info->tree_widget, LocalSetValues, NULL);
718     }
719     else
720 	SetMessage(global_screen_data.info_label,
721 		   res_labels[20]);
722 
723     XrmDestroyDatabase(info.database);
724 }
725 
726 /*	Function Name: ObtainResource
727  *	Description: Obtain the current resource from the running application.
728  *	Arguments: node_ptr - a pointer to the node containing
729  *                            the current resouce box.
730  *	Returns: none
731  */
732 
733 /* ARGSUSED */
734 static void
ObtainResource(XtPointer node_ptr)735 ObtainResource(XtPointer node_ptr)
736 {
737     ProtocolStream * stream = &(global_client.stream);
738     ObtainResourcesInfo info;
739     WNode * node = (WNode *) node_ptr;
740     char * value;
741     Arg args[1];
742 
743     info.name = GetResourceName(node->resources->res_box);
744     info.class = "IGNORE_ME";	/* Not currently used.  */
745     info.stream = stream;
746     info.count = 1;
747 
748     XtSetArg(args[0], XtNlabel, &value);
749     XtGetValues(node->resources->res_box->res_label, args, ONE);
750 
751     info.database = NULL;
752     XrmPutLineResource(&(info.database), value);
753 
754     _XEditResResetStream(stream);
755     _XEditResPutString8(stream, info.name); /* insert name */
756 
757     /*
758      * Insert the widget count, always 1
759      */
760 
761     _XEditResPut16(stream, 1);
762 
763     /*CreateGetValuesCommand(node, (XtPointer)&info);  Inserts widget */
764 
765     /* Insert widget */
766     InsertWidgetFromNode(stream, node);
767 
768     SetCommand(node->tree_info->tree_widget, LocalGetValues, NULL);
769 }
770 
771 /*	Function Name: CreateSetValuesCommand
772  *	Description: Creates the SetValues command if this widget
773  *                   matches the resource string in the database.
774  *	Arguments: node - the current node.
775  *                 info_ptr - the pointer to the apply info.
776  *	Returns: none
777  */
778 
779 static void
CreateSetValuesCommand(WNode * node,XtPointer info_ptr)780 CreateSetValuesCommand(WNode *node, XtPointer info_ptr)
781 {
782     ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr;
783     XrmNameList name_quarks;
784     XrmClassList class_quarks;
785     char ** names, **classes;
786 
787     GetNamesAndClasses(node, &names, &classes);
788     name_quarks = (XrmNameList) Quarkify(names, info->name);
789     class_quarks = (XrmNameList) Quarkify(classes, info->class);
790 
791     if (CheckDatabase(info->database, name_quarks, class_quarks)) {
792 	InsertWidgetFromNode(info->stream, node);
793 	info->count++;
794     }
795 
796     XtFree((char *)names);
797     XtFree((char *)classes);
798     XtFree((char *)name_quarks);
799     XtFree((char *)class_quarks);
800 }
801 
802 /*	Function Name: CreateGetValuesCommand
803  *	Description: Creates the GetValues command.
804  *	Arguments: node - the current node.
805  *                 info_ptr - the pointer to the apply info.
806  *	Returns: none
807  */
808 
809 /*****
810 
811 static void
812 CreateGetValuesCommand(WNode *node, XtPointer info_ptr)
813 {
814     ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr;
815     XrmNameList name_quarks;
816     XrmClassList class_quarks;
817     char ** names, **classes;
818 
819     GetNamesAndClasses(node, &names, &classes);
820     name_quarks = (XrmNameList) Quarkify(names, info->name);
821     class_quarks = (XrmNameList) Quarkify(classes, info->class);
822 
823     if (CheckDatabase(info->database, name_quarks, class_quarks)) {
824 	InsertWidgetFromNode(info->stream, node);
825 	info->count++;
826     }
827 
828     XtFree((char *)names);
829     XtFree((char *)classes);
830     XtFree((char *)name_quarks);
831     XtFree((char *)class_quarks);
832 }
833 
834 *****/
835 
836 /*	Function Name: ActivateResourceWidgets
837  *	Description: Activates all widgets that match this resource.
838  *	Arguments: w - UNUSED.
839  *                 node_ptr - the node that owns this resource box.
840  *                 junk - UNUSED.
841  *	Returns: none.
842  */
843 
844 /* ARGSUSED */
845 void
ActivateResourceWidgets(Widget w,XtPointer node_ptr,XtPointer junk)846 ActivateResourceWidgets(Widget w, XtPointer node_ptr, XtPointer junk)
847 {
848     WNode * node = (WNode *) node_ptr;
849     ApplyResourcesInfo info;
850     char * line;
851     Arg args[1];
852 
853     info.name = GetResourceName(node->resources->res_box);
854     info.class = "IGNORE_ME";	/* Not currently used.  */
855 
856     /*
857      * Unused fields.
858      */
859 
860     info.count = 0;
861     info.stream = NULL;
862 
863     XtSetArg(args[0], XtNlabel, &line);
864     XtGetValues(node->resources->res_box->res_label, args, ONE);
865 
866     info.database = NULL;
867     XrmPutLineResource(&(info.database), line);
868 
869 
870     ExecuteOverAllNodes(node->tree_info->top_node,
871 			SetOnlyMatchingWidgets, (XtPointer) &info);
872 
873     XrmDestroyDatabase(info.database);
874 }
875 
876 /*	Function Name: SetOnlyMatchingWidgets
877  *	Description: Activates all widgets in the tree that match this
878  *                   resource specifiction.
879  *	Arguments: node - the current node.
880  *                 info_ptr - the pointer to the apply info.
881  *	Returns: none
882  */
883 
884 static void
SetOnlyMatchingWidgets(WNode * node,XtPointer info_ptr)885 SetOnlyMatchingWidgets(WNode *node, XtPointer info_ptr)
886 {
887     ApplyResourcesInfo * info = (ApplyResourcesInfo *) info_ptr;
888     XrmNameList name_quarks;
889     XrmClassList class_quarks;
890     char ** names, **classes;
891     Boolean state;
892     Arg args[1];
893 
894     GetNamesAndClasses(node, &names, &classes);
895     name_quarks = (XrmNameList) Quarkify(names, info->name);
896     class_quarks = (XrmNameList) Quarkify(classes, info->class);
897 
898     state = CheckDatabase(info->database, name_quarks, class_quarks);
899 
900     XtSetArg(args[0], XtNstate, state);
901     XtSetValues(node->widget, args, ONE);
902     TreeToggle(node->widget, (XtPointer) node, (XtPointer)(long) state);
903 
904     XtFree((char *)names);
905     XtFree((char *)classes);
906     XtFree((char *)name_quarks);
907     XtFree((char *)class_quarks);
908 }
909