1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 
28 #ifdef REV_INFO
29 #ifndef lint
30 static char rcsid[] = "$XConsortium: Mrmappl.c /main/17 1996/11/13 13:59:58 drk $"
31 #endif
32 #endif
33 
34 /*
35  *++
36  *  FACILITY:
37  *
38  *      UIL Resource Manager (URM):
39  *
40  *  ABSTRACT:
41  *
42  *	These are the top-level routines in URM normally accessible to
43  *	and used by an application at runtime to access URM facilities.
44  *
45  *--
46  */
47 
48 
49 /*
50  *
51  *  INCLUDE FILES
52  *
53  */
54 
55 #include <Mrm/MrmAppl.h>
56 #include <Mrm/Mrm.h>
57 #include "MrmMsgI.h"
58 
59 
60 /*
61  *
62  *  TABLE OF CONTENTS
63  *
64  *	MrmOpenHierarchy		Open a hierarchy
65  *
66  *	MrmOpenHierarchyPerDisplay     	Open a hierarchy taking display arg
67  *
68  *	MrmOpenHierarchyFromBuffer	Open a hierarchy from a memory buffer
69  *
70  *	MrmCloseHierarchy		Close an open hierarchy
71  *
72  *	MrmRegisterClass		Register a widget class
73  *
74  *	MrmFetchInterfaceModule		Fetch widgets in an interface module
75  *
76  *	MrmFetchWidget			Fetch a widget
77  *
78  *	MrmFetchWidgetOverride		Fetch a widget, overriding name, args
79  *
80  *	MrmFetchSetValues		Do SetValues from UID literals
81  *
82  */
83 
84 
85 
86 /*
87  *++
88  *
89  *  PROCEDURE DESCRIPTION:
90  *
91  *	This routine allocates a hierarchy descriptor, and opens
92  *	all the IDB files in the hierarchy. It initializes the
93  *	optimized search lists in the hierarchy from the open files.
94  *	All files are closed if there are any errors.
95  *
96  *  FORMAL PARAMETERS:
97  *
98  *	num_files		The number of files in the name list
99  *	name_list		A list of the file names
100  *	os_ext_list		A list of system-dependent ancillary
101  *				structures corresponding to the files.
102  *				This parameter may be NULL.
103  *	hierarchy_id_return	To return the hierarchy id
104  *
105  *  IMPLICIT INPUTS:
106  *
107  *  IMPLICIT OUTPUTS:
108  *
109  *  FUNCTION VALUE:
110  *
111  *	MrmSUCCESS	operation succeeded
112  *	MrmFAILURE	operation failed, no further reason
113  *	Others		see UrmIdbOpenFileRead
114  *
115  *  SIDE EFFECTS:
116  *
117  *--
118  */
119 
120 Cardinal
121 MrmOpenHierarchy (
122 #if NeedWidePrototypes
123 		  int			num_files,
124 #else
125 		  MrmCount		num_files,
126 #endif
127 		  String		*name_list,
128 		  MrmOsOpenParamPtr	*os_ext_list,
129 		  MrmHierarchy		*hierarchy_id_return)
130 {
131 
132   /*
133    *  Local variables
134    */
135   Cardinal result;
136 
137   _MrmProcessLock();
138   result = Urm__OpenHierarchy
139     (num_files, name_list, os_ext_list, hierarchy_id_return, FALSE, NULL);
140   _MrmProcessUnlock();
141 
142   return result;
143 }
144 
145 
146 /*
147  *++
148  *
149  *  PROCEDURE DESCRIPTION:
150  *
151  *	This routine allocates a hierarchy descriptor, and opens
152  *	all the IDB files in the hierarchy. It initializes the
153  *	optimized search lists in the hierarchy from the open files.
154  *	All files are closed if there are any errors.
155  *
156  *  FORMAL PARAMETERS:
157  *
158  *	display			The Display to be passed to XtResolvePathname
159  *	num_files		The number of files in the name list
160  *	name_list		A list of the file names
161  *	os_ext_list		A list of system-dependent ancillary
162  *				structures corresponding to the files.
163  *				This parameter may be NULL.
164  *	hierarchy_id_return	To return the hierarchy id
165  *
166  *  IMPLICIT INPUTS:
167  *
168  *  IMPLICIT OUTPUTS:
169  *
170  *  FUNCTION VALUE:
171  *
172  *	MrmSUCCESS	operation succeeded
173  *	MrmFAILURE	operation failed, no further reason
174  *	Others		see UrmIdbOpenFileRead
175  *
176  *  SIDE EFFECTS:
177  *
178  *--
179  */
180 
181 Cardinal
MrmOpenHierarchyPerDisplay(Display * display,int num_files,String * name_list,MrmOsOpenParamPtr * os_ext_list,MrmHierarchy * hierarchy_id_return)182 MrmOpenHierarchyPerDisplay (Display		*display,
183 #if NeedWidePrototypes
184 			    int			num_files,
185 #else
186 			    MrmCount		num_files,
187 #endif
188 			    String		*name_list,
189 			    MrmOsOpenParamPtr	*os_ext_list,
190 			    MrmHierarchy	*hierarchy_id_return)
191 {
192 
193   /*
194    *  Local variables
195    */
196   MrmOsOpenParam	os_data;
197   MrmOsOpenParamPtr	new_os_ext_list = &os_data;
198   Cardinal		result;
199 
200   _MrmProcessLock();
201 
202   if (os_ext_list == NULL)
203     os_ext_list = (MrmOsOpenParamPtr *)&new_os_ext_list;
204 
205   (*os_ext_list)->display = display;
206 
207   result = Urm__OpenHierarchy(num_files, name_list, os_ext_list,
208 			      hierarchy_id_return, FALSE, NULL);
209   _MrmProcessUnlock();
210   return result;
211 }
212 
213 
214 
215 /*
216  *++
217  *
218  *  PROCEDURE DESCRIPTION:
219  *
220  *	MrmOpenHierarcyFromBuffer opens a buffer containing the
221  *	memory image of a UID file.
222  *
223  *  FORMAL PARAMETERS:
224  *
225  *	hierarchy_id	ID of an open URM database hierarchy
226  *
227  *  IMPLICIT INPUTS:
228  *
229  *  IMPLICIT OUTPUTS:
230  *
231  *  FUNCTION VALUE:
232  *
233 
234  *	MrmSUCCESS	operation succeeded
235  *	MrmFAILURE	operation failed, no further reason
236  *
237  *  SIDE EFFECTS:
238  *
239  *--
240  */
241 
242 Cardinal
MrmOpenHierarchyFromBuffer(unsigned char * uid_buffer,MrmHierarchy * hierarchy_id_return)243 MrmOpenHierarchyFromBuffer (unsigned char	*uid_buffer,
244 			    MrmHierarchy	*hierarchy_id_return)
245 {
246 
247   /*
248    *  Local variables
249    */
250   Cardinal		result;
251 
252   _MrmProcessLock();
253   result = Urm__OpenHierarchy((MrmCount) 1, NULL, NULL,
254 			      hierarchy_id_return, TRUE, uid_buffer);
255   _MrmProcessUnlock();
256   return result;
257 }
258 
259 /*
260  *++
261  *
262  *  PROCEDURE DESCRIPTION:
263  *
264  *	MrmCloseHierarchy closes a URM search hierarchy.
265  *
266  *  FORMAL PARAMETERS:
267  *
268  *	hierarchy_id	ID of an open URM database hierarchy
269  *
270  *  IMPLICIT INPUTS:
271  *
272  *  IMPLICIT OUTPUTS:
273  *
274  *  FUNCTION VALUE:
275  *
276 
277  *	MrmSUCCESS	operation succeeded
278  *	MrmFAILURE	operation failed, no further reason
279  *
280  *  SIDE EFFECTS:
281  *
282  *--
283  */
284 
285 Cardinal
MrmCloseHierarchy(MrmHierarchy hierarchy_id)286 MrmCloseHierarchy (MrmHierarchy                hierarchy_id)
287 {
288 
289   /*
290    *  Local variables
291    */
292   Cardinal		result;
293 
294   _MrmProcessLock();
295   result = Urm__CloseHierarchy (hierarchy_id);
296   _MrmProcessUnlock();
297   return result;
298 }
299 
300 
301 
302 /*
303  *++
304  *
305  *  PROCEDURE DESCRIPTION:
306  *
307  *	This routine registers a vector of names and associated values
308  *	for access in URM. The values may be callback routines, pointers
309  *	to user-defined data, or any other values. The information provided
310  *	is used exactly as registered callback information is used.
311  *
312  *	The names in the list are case-sensitive, as usual. The list may
313  *	either ordered or unordered; this routine will detect lexicographic
314  *	ordering if it exists, and exploit it.
315  *
316  *	For details on callbacks in URM, consult XmRegisterMRMCallbacks.
317  *
318  *  FORMAL PARAMETERS:
319  *
320  *	reglist		A list of name/value pairs for the names to
321  *			be registered. Each name is a case-sensitive
322  *			nul-terminated ASCII string. Each value is
323  *			a 32-bit quantity, interpreted as a procedure
324  *			address if the name is a callback routine, and
325  *			uninterpreted otherwise.
326  *	num_reg		The number of entries in reglist.
327  *
328  *  IMPLICIT INPUTS:
329  *
330  *  IMPLICIT OUTPUTS:
331  *
332  *  FUNCTION VALUE:
333  *
334  *  SIDE EFFECTS:
335  *
336  *--
337  */
338 
339 Cardinal
MrmRegisterNames(MrmRegisterArglist reglist,int num_reg)340 MrmRegisterNames (MrmRegisterArglist		reglist,
341 #if NeedWidePrototypes
342 		  int				num_reg
343 #else
344 		  MrmCount			num_reg
345 #endif
346 		  )
347 {
348 
349   /*
350    *  Local variables
351    */
352   Cardinal		result;		/* function result */
353   String		*names;		/* vector of names */
354   XtPointer		*values;	/* vector of values */
355   int			ndx;		/* loop index */
356 
357 
358   _MrmProcessLock();
359   /*
360    * Construct RegisterNames vectors, and call the WCI routine
361    */
362   names = (String *) XtMalloc (num_reg*sizeof(String));
363   values = (XtPointer *) XtMalloc (num_reg*sizeof(XtPointer));
364   for ( ndx=0 ; ndx<num_reg ; ndx++ )
365     {
366       names[ndx] = reglist[ndx].name;
367       values[ndx] = reglist[ndx].value;
368     }
369 
370   result = Urm__WCI_RegisterNames (names, values, num_reg);
371   XtFree ((char*)names);
372   XtFree ((char*)values);
373   _MrmProcessUnlock();
374   return result;
375 
376 }
377 
378 
379 
380 /*
381  *++
382  *
383  *  PROCEDURE DESCRIPTION:
384  *
385  *	This routine registers a vector of names and associated values for
386  *	access in URM within a specific hierarchy. It is similar to
387  *	MrmRegisterNames, except that the names have scope only over the
388  *	hierarchy rather than global scope. For information on the names
389  *	and values, see MrmRegister Names.
390  *
391  *  FORMAL PARAMETERS:
392  *
393  *	hierarchy_id	An open hierarchy descriptor.
394  *	reglist		A list of name/value pairs for the names to
395  *			be registered. Each name is a case-sensitive
396  *			nul-terminated ASCII string. Each value is
397  *			a 32-bit quantity, interpreted as a procedure
398  *			address if the name is a callback routine, and
399  *			uninterpreted otherwise.
400  *	num_reg		The number of entries in reglist.
401  *
402  *  IMPLICIT INPUTS:
403  *
404  *  IMPLICIT OUTPUTS:
405  *
406  *  FUNCTION VALUE:
407  *
408  *  SIDE EFFECTS:
409  *
410  *--
411  */
412 
413 Cardinal
MrmRegisterNamesInHierarchy(MrmHierarchy hierarchy_id,MrmRegisterArglist reglist,int num_reg)414 MrmRegisterNamesInHierarchy (MrmHierarchy		hierarchy_id,
415 			     MrmRegisterArglist		reglist,
416 #if NeedWidePrototypes
417 			     int		num_reg
418 #else
419 			     MrmCount			num_reg
420 #endif
421 			     )
422 {
423 
424   /*
425    *  Local variables
426    */
427   Cardinal		result;		/* function result */
428   String		*names;		/* vector of names */
429   XtPointer		*values;	/* vector of values */
430   int			ndx;		/* loop index */
431 
432   _MrmProcessLock();
433   /*
434    * Construct RegisterNames vectors, and call the hierarchy routine
435    */
436   names = (String *) XtMalloc (num_reg*sizeof(String));
437   values = (XtPointer *) XtMalloc (num_reg*sizeof(XtPointer));
438   for ( ndx=0 ; ndx<num_reg ; ndx++ )
439     {
440       names[ndx] = reglist[ndx].name;
441       values[ndx] = reglist[ndx].value;
442     }
443 
444   result = Urm__RegisterNamesInHierarchy
445     (hierarchy_id, names, values, num_reg);
446   XtFree ((char*)names);
447   XtFree ((char*)values);
448   _MrmProcessUnlock();
449   return result;
450 
451 }
452 
453 
454 
455 /*
456  *++
457  *
458  *  PROCEDURE DESCRIPTION:
459  *
460  *	MrmFetchInterfaceModule fetches all the widgets defined in some
461  *	interface module in the URM database hierarchy. Typically, each
462  *	application has one or more modules which define its interface;
463  *	each must be fetched in order to initialize all the widgets the
464  *	application requires. Applications are not constrained to have all
465  *	their widgets defined in a single module.
466  *
467  *	If the module defines a main window widget, MrmFetchInterfaceModule
468  *	returns its id. If no main window widget is contained in the module,
469  *	NULL is returned. No widgets are realized. The ids of widgets other
470  *	than the main window may be obtained using creation callbacks.
471  *
472  *  FORMAL PARAMETERS:
473  *
474  *	hierarchy_id	Hierarchy containing interface definition
475  *	module_name	Name of interface module defining top level of
476  *			interface; by convention, this is usually the generic
477  *			name of the application
478  *	parent		The parent widget for the topmost widgets being
479  *			fetched from the module. Usually the top-level
480  *			widget.
481  *	w_return	To return the widget id of the main window widget
482  *			for the application
483  *
484  *  IMPLICIT INPUTS:
485  *
486  *  IMPLICIT OUTPUTS:
487  *
488  *  FUNCTION VALUE:
489  *
490  *	MrmSUCCESS	operation succeeded
491  *	MrmNOT_FOUND	interface module or topmost widget not found
492  *	MrmFAILURE	Couldn't complete initialization
493  *
494  *  SIDE EFFECTS:
495  *
496  *--
497  */
498 
499 /*ARGSUSED*/
500 Cardinal
MrmFetchInterfaceModule(MrmHierarchy hierarchy_id,char * module_name,Widget parent,Widget * w_return)501 MrmFetchInterfaceModule (MrmHierarchy		hierarchy_id,
502 			 char			*module_name,
503 			 Widget			parent,
504 			 Widget			*w_return) /* unused */
505 
506 {
507 
508   /*
509    *  Local variables
510    */
511   Cardinal		result;		/* function results */
512   URMResourceContextPtr	mod_context;	/* context containing module */
513   RGMModuleDescPtr	modptr;		/* Interface module in context */
514   int			ndx;		/* loop index */
515   Widget		cur_w;		/* current widget id */
516   MrmType		class;		/* current widget class */
517   IDBFile		hfile_id;	/* file where module was found */
518   _MrmWidgetToAppContext(parent);
519 
520   _MrmAppLock(app);
521   _MrmProcessLock();
522   /*
523    * Validate the hierachy, then attempt to fetch the module.
524    */
525   if ( hierarchy_id == NULL )
526     {
527       result = Urm__UT_Error ("MrmFetchInterfaceModule", _MrmMMsg_0023,
528 			      NULL, NULL, MrmBAD_HIERARCHY);
529       _MrmProcessUnlock();
530       _MrmAppUnlock(app);
531       return result;
532     }
533 
534   if ( ! MrmHierarchyValid(hierarchy_id) )
535     {
536       result = Urm__UT_Error ("MrmFetchInterfaceModule", _MrmMMsg_0024,
537 			      NULL, NULL, MrmBAD_HIERARCHY);
538       _MrmProcessUnlock();
539       _MrmAppUnlock(app);
540       return result;
541     }
542 
543   result = UrmGetResourceContext (NULL, NULL, 0, &mod_context);
544   if ( result != MrmSUCCESS )
545     {
546       _MrmProcessUnlock();
547       _MrmAppUnlock(app);
548       return result;
549     }
550 
551   result = UrmIFMHGetModule (hierarchy_id, module_name, mod_context, &hfile_id);
552   if ( result != MrmSUCCESS )
553     {
554       UrmFreeResourceContext (mod_context);
555       _MrmProcessUnlock();
556       _MrmAppUnlock(app);
557       return result;
558     }
559 
560   /*
561    * We have the module. Loop through all the widgets it defines, and fetch
562    * each one.
563    */
564   modptr = (RGMModuleDescPtr) UrmRCBuffer (mod_context);
565   if ( ! UrmInterfaceModuleValid(modptr) )
566     {
567       UrmFreeResourceContext (mod_context);
568       result = Urm__UT_Error ("MrmFetchInterfaceModule", _MrmMMsg_0025,
569 			      NULL, mod_context, MrmBAD_IF_MODULE);
570       _MrmProcessUnlock();
571       _MrmAppUnlock(app);
572       return result;
573     }
574 
575   for ( ndx=0 ; ndx<modptr->count ; ndx++ )
576     {
577       result = MrmFetchWidget (hierarchy_id, modptr->topmost[ndx].index,
578 			       parent, &cur_w, &class);
579       if ( result != MrmSUCCESS )
580         {
581 	  UrmFreeResourceContext (mod_context);
582 	  _MrmProcessUnlock();
583 	  _MrmAppUnlock(app);
584 	  return result;
585         }
586     }
587 
588   /*
589    * successfully fetched all widgets
590    */
591   UrmFreeResourceContext (mod_context);
592   _MrmProcessUnlock();
593   _MrmAppUnlock(app);
594   return MrmSUCCESS;
595 
596 }
597 
598 
599 
600 /*
601  *++
602  *
603  *  PROCEDURE DESCRIPTION:
604  *
605  *	MrmFetchWidget fetchs any indexed application widget. As usual in fetch
606  *	operations, the fetched widget's subtree is also fetched. There are
607  *	no constraints on this widget except that it must not also appear
608  *	as the child of some widget within its own subtree, i.e. there must
609  *	be no cycles in the subtree graph! MrmFetchWidget does not do a
610  *	XtManageChild for the newly created widget.
611  *
612  *	The semantics of the URM database require that any widget which is to
613  *	be fetched with MrmFetchWidget meet the following requirements:
614  *
615  *		o Not be referenced as the child of any widget in the database
616  *
617  *		o Be indexed
618  *
619  *	MrmFetchWidget replaces XmFetchTopmost, and is used to fetch
620  *	topmost widgets where MrmFetchInterfaceModule is not used. A topmost
621  *	widget is either the main window or any indexed widget whose parent is
622  *	the top-level widget. MrmFetchWidget may be called at any time to fetch
623  *	a widget which was not fetched at application startup. MrmFetchWidget
624  *	determines if a widget has already been fetched by checking *w_return
625  *	for a NULL value. Non-NULL values signify that the widget already
626  *	has been fetched, and MrmFetchWidget no-ops. (If the toolkit ever
627  *	supplies a validation routine for widgets, this will be used in
628  *	place of a non-NULL check). Thus MrmFetchWidget may be used to
629  *	defer fetching popup widgets until they are first referenced
630  *	(presumably in a callback), and then fetching them once.
631  *
632  *	MrmFetchWidget may also be used to make multiple instances of a
633  *	widget (and its subtree). In this case, the UID definition functions
634  *	as a skeleton; there are no constraints on how many times a widget
635  *	definition may be fetched. The only requirement is the *w_return be
636  *	NULL on each call. This may be used to make multiple copies of
637  *	a widget in e.g. a dialog box or menu (to construct a uniform form).
638  *
639  *	The index which identifies the widget must be known to the application
640  *	via previous agreement.
641  *	MrmFetchWidget will successfully fetch topmost widgets as long as the
642  *	parent parameter is correct (the top-level widget), and this
643  *	replaces XmFetchTopmost (which vanishes).
644  *
645  *  FORMAL PARAMETERS:
646  *
647  *	hierarchy_id	Hierarchy containing interface definition
648  *	index		The index of the widget to fetch.
649  *	parent		ID of the parent widget
650  *	w_return	To return the widget id of the created widget.
651  *			*w_return must be NULL or MrmFetchWidget no-ops.
652  *	class_return	To return the code identifying the widget class.
653  *			This is principally used to distinguish main window
654  *			and other toolkit widgets. It will be one of the
655  *			URMwc... codes defined in MRM.h. The code
656  *			for a main window is URMwcMainWindow.
657  *
658  *  IMPLICIT INPUTS:
659  *
660  *  IMPLICIT OUTPUTS:
661  *
662  *  FUNCTION VALUE:
663  *
664  *	MrmSUCCESS	operation succeeded
665  *	MrmNOT_FOUND	widget not found in database
666  *	MrmFAILURE	operation failed, no further reason
667  *
668  *  SIDE EFFECTS:
669  *
670  *--
671  */
672 
673 Cardinal
MrmFetchWidget(MrmHierarchy hierarchy_id,String index,Widget parent,Widget * w_return,MrmType * class_return)674 MrmFetchWidget (MrmHierarchy                hierarchy_id,
675 		String                      index,
676 		Widget                      parent,
677 		Widget                      *w_return,
678 		MrmType                     *class_return)
679 {
680 
681   return MrmFetchWidgetOverride (hierarchy_id, index, parent,
682 				 NULL, NULL, 0, w_return, class_return);
683 
684 }
685 
686 
687 
688 /*
689  *++
690  *
691  *  PROCEDURE DESCRIPTION:
692  *
693  *	This procedure is the extended version of MrmFetchWidget. It is
694  *	identical to MrmFetchWidget in all respsects, except that it allows
695  *	the caller to override the widget's name and any number of the
696  *	arguments which would otherwise receive from the UID database or
697  *	one of the defaulting mechanisms (i.e. the override is not limited
698  *	to those arguments in the UID file).
699  *
700  *	The override parameters apply only to the widget fetched and returned
701  *	by this procedure; its children (subtree) do not receive any override
702  *	parameters.
703  *
704  *  FORMAL PARAMETERS:
705  *
706  *	hierarchy_id	Hierarchy containing interface definition
707  *	index		The index of the widget to fetch.
708  *	parent		ID of the parent widget
709  *	ov_name		Name to override widget name (NULL for no override)
710  *	ov_args		Override arglist, exactly as would be given to
711  *			XtCreateWidget (conversion complete, etc). NULL
712  *			for no override.
713  *	ov_num_args	# args in ov_args; 0 for no override
714  *	w_return	To return the widget id of the created widget.
715  *			*w_return must be NULL or MrmFetchWidget no-ops.
716  *	class_return	To return the code identifying the widget class.
717  *			This is principally used to distinguish main window
718  *			and other toolkit widgets. It will be one of the
719  *			URMwc... codes defined in MRM.h. The code
720  *			for a main window is URMwcMainWindow.
721  *
722  *  IMPLICIT INPUTS:
723  *
724  *  IMPLICIT OUTPUTS:
725  *
726  *  FUNCTION VALUE:
727  *
728  *	MrmSUCCESS	operation succeeded
729  *	MrmNOT_FOUND	widget not found in database
730  *	MrmFAILURE	operation failed, no further reason
731  *
732  *  SIDE EFFECTS:
733  *
734  *--
735  */
736 
737 Cardinal
MrmFetchWidgetOverride(MrmHierarchy hierarchy_id,String index,Widget parent,String ov_name,ArgList ov_args,Cardinal ov_num_args,Widget * w_return,MrmType * class_return)738 MrmFetchWidgetOverride (MrmHierarchy		hierarchy_id,
739 			String			index,
740 			Widget			parent,
741 			String			ov_name,
742 			ArgList			ov_args,
743 			Cardinal		ov_num_args,
744 			Widget			*w_return,
745 			MrmType			*class_return)
746 {
747 
748   /*
749    *  Local variables
750    */
751   Cardinal		result;		/* function results */
752   URMResourceContextPtr	w_context;	/* context containing widget */
753   RGMWidgetRecordPtr	widgetrec;	/* widget record in context */
754   IDBFile		hfile_id;	/* file in widget was found */
755   URMResourceContextPtr	wref_ctx;	/* for widget references */
756   URMSetValuesDescPtr	svlist = NULL;	/* list of SetValues descriptors */
757   int			ndx ;		/* loop index */
758   char			errmsg[300];
759   _MrmWidgetToAppContext(parent);
760 
761   _MrmAppLock(app);
762   _MrmProcessLock();
763 
764   /*
765    * Validate the hierachy, then attempt to fetch the widget
766    */
767   if ( hierarchy_id == NULL )
768     {
769       result = Urm__UT_Error ("MrmFetchWidgetOverride", _MrmMMsg_0023,
770 			      NULL, NULL, MrmBAD_HIERARCHY);
771       _MrmProcessUnlock();
772       _MrmAppUnlock(app);
773       return result;
774     }
775 
776   if ( ! MrmHierarchyValid(hierarchy_id) )
777     {
778       result = Urm__UT_Error ("MrmFetchWidgetOverride", _MrmMMsg_0024,
779 			      NULL, NULL, MrmBAD_HIERARCHY);
780       _MrmProcessUnlock();
781       _MrmAppUnlock(app);
782       return result;
783     }
784 
785   result = UrmGetResourceContext (NULL, NULL, 300, &w_context);
786   if ( result != MrmSUCCESS )
787     {
788       _MrmProcessUnlock();
789       _MrmAppUnlock(app);
790       return result;
791     }
792 
793   result = UrmHGetWidget (hierarchy_id, index, w_context, &hfile_id);
794   if ( result != MrmSUCCESS )
795     {
796       UrmFreeResourceContext (w_context);
797       _MrmProcessUnlock();
798       _MrmAppUnlock(app);
799       return result;
800     }
801 
802   /*
803    * Validate the widget record, then set the class return. Then instantiate the
804    * widget and its subtree.
805    */
806   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (w_context);
807   if ( ! UrmWRValid(widgetrec) )
808     {
809       UrmFreeResourceContext (w_context);
810       result = Urm__UT_Error ("MrmFetchWidgetOverride", _MrmMMsg_0026,
811 			      NULL, w_context, MrmFAILURE);
812       _MrmProcessUnlock();
813       _MrmAppUnlock(app);
814       return result;
815     }
816   /*
817    * The following test breaks compatibility with the CDE1.0
818    * version of Mrm and cannot be done for CDEnext.
819    *
820    *   if (widgetrec->access == URMaPrivate)
821    *     {
822    *       UrmFreeResourceContext (w_context);
823    *       sprintf(errmsg, _MrmMMsg_0119, index);
824    *       result = Urm__UT_Error("MrmFetchWidgetOverride", errmsg,
825    * 			     NULL, w_context, MrmFAILURE);
826    *       _MrmProcessUnlock();
827    *       _MrmAppUnlock(app);
828    *       return result;
829    *     }
830    */
831 
832   *class_return = widgetrec->type;
833 
834   Urm__CW_InitWRef (&wref_ctx);
835   result = UrmCreateWidgetTree (w_context, parent, hierarchy_id, hfile_id,
836 				ov_name, ov_args, ov_num_args,
837 				URMrIndex, index, 0L, MrmManageDefault,
838 				(URMPointerListPtr *)&svlist, wref_ctx,
839 				w_return);
840   UrmFreeResourceContext (w_context);
841   if ( result != MrmSUCCESS )
842     {
843       _MrmProcessUnlock();
844       _MrmAppUnlock(app);
845       return result;
846     }
847 
848   /*
849    * Free up resources
850    */
851   if ( svlist != NULL )
852     {
853       for ( ndx=0 ; ndx<UrmPlistNum((URMPointerListPtr)svlist) ; ndx++ )
854         Urm__CW_FreeSetValuesDesc
855 	  ((URMSetValuesDescPtr)UrmPlistPtrN((URMPointerListPtr)svlist,ndx));
856       UrmPlistFree ((URMPointerListPtr)svlist);
857     }
858   UrmFreeResourceContext (wref_ctx);
859 
860   /*
861    * successfully initialized
862    */
863   _MrmProcessUnlock();
864   _MrmAppUnlock(app);
865   return MrmSUCCESS;
866 
867 }
868 
869 
870 
871 /*
872  *++
873  *
874  *  PROCEDURE DESCRIPTION:
875  *
876  *	This routine does an XtSetValues on a widget, evaluating the values
877  *	as public literal resource references resolvable from a URM
878  *	hierarchy. Each literal is fetched from the hierarchy, and
879  *	its value is fixed up and converted as required. This value is
880  *	then placed in the arglist, and used as the actual value for
881  *	an XtSetValues call. This routine allows a widget to be modified
882  *	after creation using UID file values exactly as is done for creation
883  *	values in MrmFetchWidget.
884  *
885  *	As in FetchWidget, each argument whose value can be evaluated from
886  *	the UID hierarchy is set in the widget. Values which are not found
887  *	or for which conversion errors occur are not modified.
888  *
889  *	Each entry in the arglist identifies an argument to be modified in
890  *	the widget. The .name part identifies the tag, as usual (XmN...).
891  *	the .value part must be a String whose values is the index of the
892  *	literal. Thus
893  *		args[n].name = "label"		(XmNlabel)
894  *		args[n].value = "OK_button_label"
895  *	would modify the label resource of the widget to have the value
896  *	of the literal accessed by index 'OK_button_label' in the
897  *	hierarchy.
898  *
899  *  FORMAL PARAMETERS:
900  *
901  *	hierarchy_id	URM hierarchy to be searched for literal definitions
902  *	w		the widget to be modified
903  *	args		An arglist specifying the widget arguments to be
904  *			modified. The .name part of each argument must be
905  *			the usual XmN... string identifying the argument
906  *			(argument tag). The .value part must be a String
907  *			giveing the index of the literal. All literals must
908  *			be public literals accessed by index.
909  *	num_args	the number of entries in args.
910  *
911  *  IMPLICIT INPUTS:
912  *
913  *  IMPLICIT OUTPUTS:
914  *
915  *  FUNCTION VALUE:
916  *
917  *  SIDE EFFECTS:
918  *
919  *--
920  */
921 
922 Cardinal
MrmFetchSetValues(MrmHierarchy hierarchy_id,Widget w,ArgList args,Cardinal num_args)923 MrmFetchSetValues (MrmHierarchy                hierarchy_id,
924 		   Widget                      w,
925 		   ArgList                     args,
926 		   Cardinal                    num_args)
927 {
928 
929   /*
930    *  Local variables
931    */
932   Cardinal		result;
933   _MrmWidgetToAppContext(w);
934 
935   _MrmAppLock(app);
936   _MrmProcessLock();
937 
938   /*
939    * Validate the hierachy, then attempt to modify the widget
940    */
941   if ( hierarchy_id == NULL )
942     {
943       result = Urm__UT_Error ("MrmFetchSetValues", _MrmMMsg_0023,
944 			      NULL, NULL, MrmBAD_HIERARCHY);
945       _MrmProcessUnlock();
946       _MrmAppUnlock(app);
947       return result;
948     }
949 
950   if ( ! MrmHierarchyValid(hierarchy_id) )
951     {
952       result = Urm__UT_Error ("MrmFetchSetValues", _MrmMMsg_0024,
953 			      NULL, NULL, MrmBAD_HIERARCHY);
954       _MrmProcessUnlock();
955       _MrmAppUnlock(app);
956       return result;
957     }
958 
959   result = UrmFetchSetValues (hierarchy_id, w, args, num_args);
960   _MrmProcessUnlock();
961   _MrmAppUnlock(app);
962   return result;
963 }
964