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[] = "$TOG: Mrmwcrw.c /main/20 1999/05/19 15:26:23 mgreess $"
31 #endif
32 #endif
33
34 /*
35 *++
36 * FACILITY:
37 *
38 * UIL Resource Manager (URM):
39 *
40 * ABSTRACT:
41 *
42 * This module contains the routine which implement widget creation
43 * and management at runtime from a widget stored in a resource context.
44 *
45 *--
46 */
47
48
49 /*
50 *
51 * INCLUDE FILES
52 *
53 */
54 #include <stdio.h>
55 #include <Mrm/MrmAppl.h>
56 #include <Mrm/Mrm.h>
57 #include "MrmosI.h"
58 #include "MrmMsgI.h"
59 #include <X11/keysym.h>
60 #include <Xm/XmosP.h> /* for ALLOCATE/DEALLOCATE_LOCAL */
61 #include <Xm/RowColumn.h> /* for XmGetTearOffControl */
62 #include <Xm/DisplayP.h> /* for XmDisplay */
63
64 #include <Xm/XmRenderTI.h>
65 #include <Xm/XmTabListI.h>
66 #include <Xm/ResIndI.h>
67
68 /*
69 *
70 * TABLE OF CONTENTS
71 *
72 * UrmCreateWidgetTree Create a widget and its subtree
73 *
74 * UrmCreateWidgetInstance Create a widget instance
75 *
76 * Urm__CW_CreateArglist Create a widget arglist
77 *
78 * Urm__CW_FixupCallback Complete a callback item
79 *
80 * Urm__CW_EvaluateResource Evaluate a resource ref value
81 *
82 */
83
84
85 static void DisplayDestroyCallback (Widget w,
86 XtPointer client_data,
87 XtPointer call_data );
88
89 /*
90 *
91 * DEFINE and MACRO DEFINITIONS
92 *
93 */
94
95 #define MAKEINT(float_value) ((int) (((float_value) > 0.0) ? \
96 ((float_value) + 0.5) : \
97 ((float_value) - 0.5)))
98
99
100
101 /*
102 *++
103 *
104 * PROCEDURE DESCRIPTION:
105 *
106 * UrmCreateWidgetInstanceCleanup determines from a RGM widget
107 * record if the widget instance is real. If it is and it has
108 * a cleanup, the cleanup is called. This mechanism is
109 * used to clean up dangling XmRenderTable and XmRendition handles
110 * left dangling in calls to UrmCreateWidgetInstance.
111 *
112 * FORMAL PARAMETERS:
113 *
114 * context_id context containing widget record describing widget
115 * to create
116 * hierarchy_id URM hierarchy from which to read public resources
117 * file_id URM file from which to read private resources
118 * child id of child widget
119 *
120 * IMPLICIT INPUTS:
121 *
122 * IMPLICIT OUTPUTS:
123 *
124 * FUNCTION VALUE:
125 *
126 * MrmSUCCESS operation succeeded
127 * MrmBAD_CONTEXT invalid context
128 * MrmBAD_WIDGET_REC invalid widget record
129 *
130 * SIDE EFFECTS:
131 *
132 *--
133 */
134
135 Cardinal
UrmCreateWidgetInstanceCleanup(URMResourceContextPtr context_id,Widget child,IDBFile file_id)136 UrmCreateWidgetInstanceCleanup (URMResourceContextPtr context_id,
137 Widget child,
138 IDBFile file_id)
139 {
140 /*
141 * Local variables
142 */
143 RGMWidgetRecordPtr widgetrec ; /* widget record in the context */
144 WCIClassDescPtr cldesc ; /* class descriptor */
145 Cardinal result;
146
147 /*
148 * Validate the context and the widget record in the context.
149 * Check the variety and call the appropriate set or create function.
150 */
151 if ( ! UrmRCValid(context_id) )
152 return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0043,
153 NULL, NULL, MrmBAD_CONTEXT) ;
154 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
155 if ( ! UrmWRValid(widgetrec) )
156 return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0026,
157 NULL, context_id, MrmBAD_WIDGET_REC) ;
158
159 if (widgetrec->variety == UilMrmWidgetVariety)
160 {
161 result = Urm__FindClassDescriptor (file_id,
162 widgetrec->type,
163 (XtPointer)
164 ((char *)widgetrec+widgetrec->class_offs),
165 &cldesc) ;
166 if ( result != MrmSUCCESS ) return result ;
167
168 if (NULL != cldesc->cleanup) (*(cldesc->cleanup)) (child) ;
169 }
170 else if (widgetrec->variety != UilMrmAutoChildVariety)
171 return Urm__UT_Error("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0055,
172 NULL, context_id, MrmBAD_WIDGET_REC);
173
174 return MrmSUCCESS;
175 }
176
177
178 /*
179 *++
180 *
181 * PROCEDURE DESCRIPTION:
182 *
183 * UrmCreateWidgetTree is the recursive routine
184 * which recurses down a widget subtree and instantiates all widgets
185 * in the tree. The recursion process is:
186 *
187 * o Create this widget.
188 * o Create a new context. Read each child of this widget
189 * into the context in succession. Create each child,
190 * saving its id.
191 * o manage the children
192 *
193 * This routine accepts override parameters for the widget name, and
194 * to override arguments in the creation arglist. The latter are appended
195 * to the list created from the UID file, and do not replace all values.
196 * The parameters are not passed down to any children in the subtree.
197 *
198 * FORMAL PARAMETERS:
199 *
200 * context_id context containing widget record describing widget
201 * to create
202 * parent id of parent widget
203 * hierarchy_id URM hierarchy from which to read public resources
204 * file_id URM file from which to read private resources
205 * ov_name Name to override widget name (NULL for no override)
206 * ov_args Override arglist, exactly as would be given to
207 * XtCreateWidget (conversion complete, etc). NULL
208 * for no override.
209 * ov_num_args # args in ov_args; 0 for no override
210 * keytype type of key which accessed this widget
211 * kindex index for URMrIndex access
212 * krid resource id for URMrRID access
213 * svlist list of SetValues descriptors for widgets in tree
214 * wref_id to accumulate widget reference definitions
215 * w_return To return id of newly created widget
216 *
217 * IMPLICIT INPUTS:
218 *
219 * IMPLICIT OUTPUTS:
220 *
221 * FUNCTION VALUE:
222 *
223 * MrmSUCCESS operation succeeded
224 * MrmBAD_CONTEXT invalid context
225 * MrmBAD_WIDGET_REC invalid widget record
226 *
227 * SIDE EFFECTS:
228 *
229 *--
230 */
231
232 Cardinal
UrmCreateWidgetTree(URMResourceContextPtr context_id,Widget parent,MrmHierarchy hierarchy_id,IDBFile file_id,String ov_name,ArgList ov_args,Cardinal ov_num_args,MrmCode keytype,String kindex,MrmResource_id krid,MrmManageFlag manage,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,Widget * w_return)233 UrmCreateWidgetTree (URMResourceContextPtr context_id,
234 Widget parent,
235 MrmHierarchy hierarchy_id,
236 IDBFile file_id,
237 String ov_name,
238 ArgList ov_args,
239 Cardinal ov_num_args,
240 MrmCode keytype,
241 String kindex,
242 MrmResource_id krid,
243 MrmManageFlag manage,
244 URMPointerListPtr *svlist,
245 URMResourceContextPtr wref_id,
246 Widget *w_return)
247 {
248 /*
249 * Local variables
250 */
251 Cardinal result ; /* function results */
252 Widget widget_id ; /* this widget id */
253 URMResourceContextPtr child_ctx ; /* context for children */
254 Widget child_id ; /* current child */
255 IDBFile loc_file_id ; /* local file id, may be modified */
256 RGMWidgetRecordPtr widgetrec ; /* the widget record in the context */
257 int ndx ; /* loop index */
258 RGMChildrenDescPtr childrendesc ; /* children list descriptor */
259 RGMChildDescPtr childptr ; /* current child */
260 String child_idx = NULL ; /* current child index */
261 char err_msg[300] ;
262 char *w_name;
263
264 /*
265 * Create the widget instance.
266 */
267 result = UrmCreateOrSetWidgetInstance (context_id, parent, hierarchy_id,
268 file_id, ov_name, ov_args, ov_num_args,
269 keytype, kindex, krid, manage, svlist,
270 wref_id, &widget_id, &w_name) ;
271 if ( result != MrmSUCCESS ) return result ;
272 *w_return = widget_id ;
273
274 /*
275 * Initialize a context, and create all the children, Saving their ids.
276 * Note there are no interior returns from the processing loop, and that
277 * all locally acquired resources are returned at the routine exit.
278 *
279 * Initialize a sibling reference context for any class which allows
280 * sibling widget references.
281 */
282 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
283 if ( widgetrec->children_offs > 0)
284 {
285 UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &child_ctx);
286 childrendesc =
287 (RGMChildrenDescPtr)((char *)widgetrec+widgetrec->children_offs);
288
289 for ( ndx=0 ; ndx<childrendesc->count ; ndx++ )
290 {
291 childptr = &childrendesc->child[ndx] ;
292
293 /*
294 * Read the next child into the child context. Continue looping if it
295 * can't be found. Reading the child from a hierarchy may modify the
296 * file id, but only for reading the child's subtree.
297 */
298 loc_file_id = file_id ;
299 switch ( childptr->type )
300 {
301 case URMrIndex:
302 child_idx = (char *) widgetrec+childptr->key.index_offs ;
303 if ( childptr->access == URMaPublic )
304 result = UrmHGetWidget (hierarchy_id, child_idx,
305 child_ctx, &loc_file_id) ;
306 else
307 result = UrmGetIndexedWidget (file_id, child_idx, child_ctx) ;
308 if ( result != MrmSUCCESS )
309 sprintf (err_msg, _MrmMMsg_0052, child_idx) ;
310 break ;
311 case URMrRID:
312 result = UrmGetRIDWidget (file_id, childptr->key.id,
313 child_ctx) ;
314 if ( result != MrmSUCCESS )
315 sprintf (err_msg, _MrmMMsg_0053, childptr->key.id) ;
316 break ;
317 default:
318 result = MrmFAILURE ;
319 sprintf (err_msg, _MrmMMsg_0054, childptr->type) ;
320 break ;
321 }
322 if ( result != MrmSUCCESS )
323 {
324 Urm__UT_Error ("UrmCreateWidgetTree",
325 err_msg, NULL, NULL, result) ;
326 continue ;
327 }
328
329 /*
330 * Create the child and its subtree.
331 */
332 result = UrmCreateWidgetTree (child_ctx, widget_id, hierarchy_id,
333 loc_file_id, NULL, NULL, 0,
334 childptr->type, child_idx,
335 childptr->key.id,
336 ((childptr->manage) ?
337 MrmManageManage : MrmManageUnmanage),
338 svlist, wref_id, &child_id) ;
339 UrmCreateWidgetInstanceCleanup(child_ctx, child_id, loc_file_id);
340 if ( result != MrmSUCCESS ) continue ;
341
342 /*
343 * loop end
344 */
345 }
346 /*
347 * done. Deallocate local resources.
348 */
349 UrmFreeResourceContext (child_ctx) ;
350 }
351
352 /*
353 * Add the parent widget to the widget reference structure, and update the
354 * SetValues descriptors if appropriate
355 */
356 if ((w_name != NULL) && (*svlist != NULL))
357 Urm__CW_ResolveSVWidgetRef(svlist, w_name, *w_return);
358
359 return MrmSUCCESS ;
360 }
361
362
363 /*
364 *++
365 *
366 * PROCEDURE DESCRIPTION:
367 *
368 * UrmCreateOrSetWidgetInstance determines from a RGM widget
369 * record if the widget instance is real and has to be created by
370 * a call to UrmCreateWidgetInstance or is an automatic child widget
371 * and has to be set by a call to UrmSetWidgetInstance.
372 *
373 * Once UrmCreateOrSetWidgetInstance has been called, then the only
374 * information in the RGM record which may still be required is the
375 * privacy information and the widget children list. This information
376 * may be copied and the resource context reused by users who are doing
377 * recursive widget access, and wish to avoid recursive accumulation
378 * of resource contexts in memory.
379 *
380 * The URM hierarchy for public resources and the IDB file for private
381 * resources are required to evaluate resource references occurring in
382 * the widget arglist.
383 *
384 * This routine accepts override parameters for the widget name, and
385 * to override arguments in the creation arglist. The latter are appended
386 * to the list created from the UID file, and do not replace all values.
387 *
388 * FORMAL PARAMETERS:
389 *
390 * context_id context containing widget record describing widget
391 * to create
392 * parent id of parent widget
393 * hierarchy_id URM hierarchy from which to read public resources
394 * file_id URM file from which to read private resources
395 * ov_name Name to override widget name (NULL for no override)
396 * ov_args Override arglist, exactly as would be given to
397 * XtCreateWidget (conversion complete, etc). NULL
398 * for no override.
399 * ov_num_args # args in ov_args; 0 for no override
400 * keytype type of key which accessed this widget
401 * kindex index for URMrIndex access
402 * krid resource id for URMrRID access
403 * manage create-managed flag
404 * svlist list of SetValues descriptors
405 * wref_id structure in which to resolve references to widgets
406 * which have already been defined.
407 * w_return To return id of newly created widget
408 *
409 * IMPLICIT INPUTS:
410 *
411 * IMPLICIT OUTPUTS:
412 *
413 * FUNCTION VALUE:
414 *
415 * MrmSUCCESS operation succeeded
416 * MrmBAD_CONTEXT invalid context
417 * MrmBAD_WIDGET_REC invalid widget record
418 *
419 * SIDE EFFECTS:
420 *
421 *--
422 */
423
424 Cardinal
UrmCreateOrSetWidgetInstance(URMResourceContextPtr context_id,Widget parent,MrmHierarchy hierarchy_id,IDBFile file_id,String ov_name,ArgList ov_args,Cardinal ov_num_args,MrmCode keytype,String kindex,MrmResource_id krid,MrmManageFlag manage,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,Widget * w_return,char ** w_name)425 UrmCreateOrSetWidgetInstance (URMResourceContextPtr context_id,
426 Widget parent,
427 MrmHierarchy hierarchy_id,
428 IDBFile file_id,
429 String ov_name,
430 ArgList ov_args,
431 Cardinal ov_num_args,
432 MrmCode keytype,
433 String kindex,
434 MrmResource_id krid,
435 MrmManageFlag manage,
436 URMPointerListPtr *svlist,
437 URMResourceContextPtr wref_id,
438 Widget *w_return,
439 char **w_name)
440 {
441 /*
442 * Local variables
443 */
444 RGMWidgetRecordPtr widgetrec ; /* widget record in the context */
445
446 /*
447 * Validate the context and the widget record in the context.
448 * Check the variety and call the appropriate set or create function.
449 */
450 if ( ! UrmRCValid(context_id) )
451 return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0043,
452 NULL, NULL, MrmBAD_CONTEXT) ;
453 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
454 if ( ! UrmWRValid(widgetrec) )
455 return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0026,
456 NULL, context_id, MrmBAD_WIDGET_REC) ;
457
458 if (widgetrec->variety == UilMrmWidgetVariety)
459 {
460 return UrmCreateWidgetInstance(context_id, parent, hierarchy_id, file_id,
461 ov_name, ov_args, ov_num_args, keytype,
462 kindex, krid, manage, svlist, wref_id,
463 w_return, w_name);
464 }
465 else if (widgetrec->variety == UilMrmAutoChildVariety)
466 {
467 *w_name = NULL;
468 return UrmSetWidgetInstance(context_id, parent, hierarchy_id, file_id,
469 ov_args, ov_num_args, keytype, kindex,
470 krid, manage, svlist, wref_id, w_return);
471 }
472 else
473 return Urm__UT_Error("UrmCreateOrSetWidgetInstance", _MrmMMsg_0055,
474 NULL, context_id, MrmBAD_WIDGET_REC);
475 }
476
477
478 /*
479 *++
480 *
481 * PROCEDURE DESCRIPTION:
482 *
483 * UrmCreateWidgetInstance creates a widget instance from a RGM widget
484 * record by:
485 *
486 * o Creating a legal XtCreateWidget arglist from the RGM
487 * arglist by expanding compressed tags, evaluating values,
488 * and doing type conversion.
489 *
490 * o Deriving the correct low-level widget creation routine
491 * from the RGM record's class specifier, and calling with
492 * the given parent and the arglist.
493 *
494 * Once UrmCreateWidgetInstance has been called, then the only
495 * information in the RGM record which may still be required is the
496 * privacy information and the widget children list. This information
497 * may be copied and the resource context reused by users who are doing
498 * recursive widget access, and wish to avoid recursive accumulation
499 * of resource contexts in memory (see next routine).
500 *
501 * The URM hierarchy for public resources and the IDB file for private
502 * resources are required to evaluate resource references occurring in
503 * the widget arglist.
504 *
505 * This routine accepts override parameters for the widget name, and
506 * to override arguments in the creation arglist. The latter are appended
507 * to the list created from the UID file, and do not replace all values.
508 *
509 * FORMAL PARAMETERS:
510 *
511 * context_id context containing widget record describing widget
512 * to create
513 * parent id of parent widget
514 * hierarchy_id URM hierarchy from which to read public resources
515 * file_id URM file from which to read private resources
516 * ov_name Name to override widget name (NULL for no override)
517 * ov_args Override arglist, exactly as would be given to
518 * XtCreateWidget (conversion complete, etc). NULL
519 * for no override.
520 * ov_num_args # args in ov_args; 0 for no override
521 * keytype type of key which accessed this widget
522 * kindex index for URMrIndex access
523 * krid resource id for URMrRID access
524 * manage create-managed flag
525 * svlist list of SetValues descriptors
526 * wref_id structure in which to resolve references to widgets
527 * which have already been defined.
528 * w_return To return id of newly created widget
529 *
530 * IMPLICIT INPUTS:
531 *
532 * IMPLICIT OUTPUTS:
533 *
534 * FUNCTION VALUE:
535 *
536 * MrmSUCCESS operation succeeded
537 * MrmBAD_CONTEXT invalid context
538 * MrmBAD_WIDGET_REC invalid widget record
539 *
540 * SIDE EFFECTS:
541 *
542 *--
543 */
544
545 /*ARGSUSED*/
546 Cardinal
UrmCreateWidgetInstance(URMResourceContextPtr context_id,Widget parent,MrmHierarchy hierarchy_id,IDBFile file_id,String ov_name,ArgList ov_args,Cardinal ov_num_args,MrmCode keytype,String kindex,MrmResource_id krid,MrmManageFlag manage,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,Widget * w_return,char ** w_name)547 UrmCreateWidgetInstance (URMResourceContextPtr context_id,
548 Widget parent,
549 MrmHierarchy hierarchy_id,
550 IDBFile file_id,
551 String ov_name,
552 ArgList ov_args,
553 Cardinal ov_num_args,
554 MrmCode keytype, /* unused */
555 String kindex, /* unused */
556 MrmResource_id krid, /* unused */
557 MrmManageFlag manage,
558 URMPointerListPtr *svlist,
559 URMResourceContextPtr wref_id,
560 Widget *w_return,
561 char **w_name)
562 {
563 /*
564 * Local variables
565 */
566 Cardinal result ; /* function results */
567 RGMWidgetRecordPtr widgetrec ; /* widget record in the context */
568 RGMArgListDescPtr argdesc = NULL ; /* arg list descriptor in record */
569 Arg *args = NULL ; /* arg list argument for create */
570 Cardinal num_used = 0 ; /* number of args used in arglist */
571 MrmCount num_listent = ov_num_args ; /* # entries in args */
572 WCIClassDescPtr cldesc ; /* class descriptor */
573 URMPointerListPtr ptrlist = NULL ; /* to hold scratch callbacks */
574 URMPointerListPtr cblist = NULL ; /* to hold scratch contexts */
575 URMPointerListPtr ftllist = NULL ; /* to hold scratch fontlists */
576 int ndx ; /* loop index */
577 RGMCallbackDescPtr cbptr ; /* creation callback descriptor */
578 RGMCallbackItemPtr itmptr ; /* current callback item */
579 void (* cb_rtn) () ; /* current callback routine */
580 /* BEGIN OSF Fix pir 1860, 2813 */
581 XmAnyCallbackStruct cb_reason; /* creation callback reason */
582 /* END OSF Fix pir 1860, 2813 */
583
584 /*
585 * Validate the context and the widget record in the context.
586 * Get the low-level creation routine pointer.
587 */
588 if ( ! UrmRCValid(context_id) )
589 return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0043,
590 NULL, NULL, MrmBAD_CONTEXT) ;
591 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
592 if ( ! UrmWRValid(widgetrec) )
593 return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0026,
594 NULL, context_id, MrmBAD_WIDGET_REC) ;
595
596 result = Urm__FindClassDescriptor (file_id,
597 widgetrec->type,
598 (XtPointer)
599 ((char *)widgetrec+widgetrec->class_offs),
600 &cldesc) ;
601 if ( result != MrmSUCCESS )
602 return result ;
603
604 /*
605 * Allocate the args list, big enough for all the arguments in the widget
606 * record plus all the override arguments. Also initialize a pointer list
607 * to save any contexts created to evaluate resources.
608 */
609 if ( widgetrec->arglist_offs != 0)
610 {
611 argdesc = (RGMArgListDescPtr)
612 ((char *)widgetrec + widgetrec->arglist_offs) ;
613 num_listent += argdesc->count + argdesc->extra ;
614 UrmPlistInit (10, &ftllist) ;
615 }
616 if ( num_listent > 0 )
617 {
618 args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ;
619 UrmPlistInit (10, &ptrlist) ;
620 }
621
622 /*
623 * Set up the structure for the callback list to free memory on destory widget
624 */
625 UrmPlistInit (10, &cblist);
626
627 /*
628 * Set the arg list from the widget record argument list
629 */
630 if ( argdesc != NULL )
631 {
632 Urm__CW_CreateArglist
633 (parent, widgetrec, argdesc, ptrlist, cblist, ftllist,
634 hierarchy_id, file_id, args, svlist, wref_id, &num_used) ;
635 }
636
637 /*
638 * Copy in any override args
639 */
640 for ( ndx=0 ; ndx<ov_num_args ; ndx++ )
641 {
642 args[ndx+num_used].name = ov_args[ndx].name ;
643 args[ndx+num_used].value = ov_args[ndx].value ;
644 }
645 num_used += ov_num_args ;
646
647 /*
648 * Create the widget
649 */
650 *w_name = (ov_name != NULL) ? ov_name : (char*)widgetrec+widgetrec->name_offs;
651 *w_return = (*(cldesc->creator)) (parent, *w_name, args, num_used) ;
652
653 Urm__CW_AddWRef (wref_id, *w_name, *w_return) ;
654 if ( *svlist != NULL )
655 Urm__CW_UpdateSVWidgetRef (svlist, *w_return) ;
656
657 if ( manage==MrmManageManage )XtManageChild(*w_return);
658
659 /*
660 * Call the creation callbacks if there are any.
661 */
662 if ( widgetrec->creation_offs != 0)
663 {
664 if (strcmp(file_id->db_version, URM1_1version) <= 0)
665 cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)
666 ((char *)widgetrec +
667 widgetrec->creation_offs));
668 else
669 cbptr = (RGMCallbackDescPtr) ((char *)widgetrec +
670 widgetrec->creation_offs) ;
671
672 if ( ptrlist == NULL )
673 UrmPlistInit (10, &ptrlist) ;
674 result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec, cbptr,
675 ptrlist, cblist, hierarchy_id,
676 file_id, wref_id) ;
677 if ( result == MrmSUCCESS )
678 for ( ndx=0 ; ndx<cbptr->count ; ndx++ )
679 {
680 itmptr = &cbptr->item[ndx] ;
681
682 cb_rtn = (void (*)()) itmptr->runtime.callback.callback ;
683 if ( cb_rtn != (XtCallbackProc)NULL )
684 /* BEGIN OSF Fix pir 2813 */
685 {
686 cb_reason.reason = MrmCR_CREATE;
687 cb_reason.event = NULL;
688 (*cb_rtn) (*w_return, itmptr->runtime.callback.closure,
689 &cb_reason) ;
690 }
691 /* END OSF Fix pir 2813 */
692 }
693 else if (result == MrmUNRESOLVED_REFS)
694 Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056,
695 NULL, NULL, MrmFAILURE) ;
696 else
697 return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057,
698 NULL, NULL, MrmFAILURE);
699
700 if (strcmp(file_id->db_version, URM1_1version) <= 0)
701 XtFree((char *)cbptr);
702 }
703
704 /*
705 * successfully created (as far as we can tell). Deallocate all local
706 * resources, including any contexts in the pointer list.
707 */
708 if ( args != NULL ) XtFree ((char*)args) ;
709 if ( ptrlist != NULL )
710 {
711 for ( ndx=0 ; ndx<UrmPlistNum(ptrlist) ; ndx++ )
712 UrmFreeResourceContext ((URMResourceContextPtr)UrmPlistPtrN(ptrlist,ndx)) ;
713 UrmPlistFree (ptrlist) ;
714 }
715
716 /*
717 * Add a destroy callback if the widget had any callbacks or font-lists
718 * associated with it.
719 * Otherwise just wipe out the memory for the Plist now.
720 */
721 if (cblist->num_ptrs > 0)
722 {
723 XtAddCallback (*w_return, XmNdestroyCallback,
724 (XtCallbackProc) UrmDestroyCallback, cblist);
725 }
726 else
727 {
728 UrmPlistFree (cblist);
729 }
730
731 /*
732 ** We should really let Xt take care of handling the fontlists by using its
733 ** converters; but for the meanwhile avoid freeing the fontlists here, as the
734 ** widget may be one which doesn't do an XmFontListCopy. Instead, later free
735 ** our extra copy.
736 */
737 if (ftllist != NULL)
738 {
739 if (UrmPlistNum(ftllist) > 0)
740 XtAddCallback(*w_return, XmNdestroyCallback,
741 (XtCallbackProc) UrmDestroyCallback, ftllist);
742 else
743 UrmPlistFree (ftllist) ;
744 }
745
746 return MrmSUCCESS ;
747
748 }
749
750
751 /*
752 *++
753 *
754 * PROCEDURE DESCRIPTION:
755 *
756 * UrmSetWidgetInstance sets the appropriate resources from a RGM widget
757 * record on the appropriate automatically created child of parent by:
758 *
759 * o Creating a legal XtSetValues arglist from the RGM
760 * arglist by expanding compressed tags, evaluating values,
761 * and doing type conversion.
762 *
763 * o Finding the correct widget child of parent by uncompressing
764 * the resource compression code found in the RGM record's
765 * type specifier, and calling XtNameToWidget on the result.
766 *
767 * Once UrmSetWidgetInstance has been called, then the only
768 * information in the RGM record which may still be required is the
769 * privacy information and the widget children list. This information
770 * may be copied and the resource context reused by users who are doing
771 * recursive widget access, and wish to avoid recursive accumulation
772 * of resource contexts in memory (see next routine).
773 *
774 * The URM hierarchy for public resources and the IDB file for private
775 * resources are required to evaluate resource references occurring in
776 * the widget arglist.
777 *
778 * This routine accepts override parameters to override
779 * arguments in the setvalues arglist. They are appended
780 * to the list created from the UID file, and do not replace all values.
781 *
782 * FORMAL PARAMETERS:
783 *
784 * context_id context containing widget record describing widget
785 * to create
786 * parent id of parent widget
787 * hierarchy_id URM hierarchy from which to read public resources
788 * file_id URM file from which to read private resources
789 * ov_args Override arglist, exactly as would be given to
790 * XtCreateWidget (conversion complete, etc). NULL
791 * for no override.
792 * ov_num_args # args in ov_args; 0 for no override
793 * keytype type of key which accessed this widget
794 * kindex index for URMrIndex access
795 * krid resource id for URMrRID access
796 * manage create-managed flag
797 * svlist list of SetValues descriptors
798 * wref_id structure in which to resolve references to widgets
799 * which have already been defined.
800 * w_return To return id of newly created widget
801 *
802 * IMPLICIT INPUTS:
803 *
804 * IMPLICIT OUTPUTS:
805 *
806 * FUNCTION VALUE:
807 *
808 * MrmSUCCESS operation succeeded
809 * MrmBAD_CONTEXT invalid context
810 * MrmBAD_WIDGET_REC invalid widget record
811 *
812 * SIDE EFFECTS:
813 *
814 *--
815 */
816
817 /*ARGSUSED*/
818 Cardinal
UrmSetWidgetInstance(URMResourceContextPtr context_id,Widget parent,MrmHierarchy hierarchy_id,IDBFile file_id,ArgList ov_args,Cardinal ov_num_args,MrmCode keytype,String kindex,MrmResource_id krid,MrmManageFlag manage,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,Widget * w_return)819 UrmSetWidgetInstance (URMResourceContextPtr context_id,
820 Widget parent,
821 MrmHierarchy hierarchy_id,
822 IDBFile file_id,
823 ArgList ov_args,
824 Cardinal ov_num_args,
825 MrmCode keytype, /* unused */
826 String kindex, /* unused */
827 MrmResource_id krid, /* unused */
828 MrmManageFlag manage,
829 URMPointerListPtr *svlist,
830 URMResourceContextPtr wref_id,
831 Widget *w_return)
832 {
833 /*
834 * Local variables
835 */
836 Cardinal result ; /* function results */
837 RGMWidgetRecordPtr widgetrec ; /* widget record in the context */
838 String c_name ; /* child name */
839 String c_name_tmp ; /* child name - temporary */
840 RGMArgListDescPtr argdesc = NULL ; /* arg list descriptor in record */
841 Arg *args = NULL ; /* arg list argument for create */
842 Cardinal num_used = 0 ; /* number of args used in arglist */
843 MrmCount num_listent = ov_num_args ; /* # entries in args */
844 URMPointerListPtr ptrlist = NULL ;/* to hold scratch contexts */
845 URMPointerListPtr cblist = NULL ; /* to hold scratch callbacks */
846 URMPointerListPtr ftllist = NULL ;/* to hold scratch fontlists */
847 int ndx ; /* loop index */
848 RGMCallbackDescPtr cbptr ; /* creation callback descriptor */
849 RGMCallbackItemPtr itmptr ; /* current callback item */
850 void (* cb_rtn) () ; /* current callback routine */
851 /* BEGIN OSF Fix pir 1860, 2813 */
852 XmAnyCallbackStruct cb_reason; /* creation callback reason */
853 /* END OSF Fix pir 1860, 2813 */
854
855 /*
856 * Validate the context and the widget record in the context.
857 */
858 if ( ! UrmRCValid(context_id) )
859 return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0043,
860 NULL, NULL, MrmBAD_CONTEXT) ;
861 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
862 if ( ! UrmWRValid(widgetrec) )
863 return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0026,
864 NULL, context_id, MrmBAD_WIDGET_REC) ;
865
866 result = Urm__UncompressCode (file_id, widgetrec->type, &c_name) ;
867 if ( result != MrmSUCCESS )
868 return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0058,
869 NULL, context_id, result) ;
870
871 /* Find the widget */
872 if (strcmp(c_name, "TearOffControl") == 0) /* Special case */
873 *w_return = XmGetTearOffControl(parent);
874 else
875 {
876 /* Need to add * for ScrolledText and ScrolledList */
877 c_name_tmp = (String)ALLOCATE_LOCAL((strlen(c_name) + 2) * sizeof(char));
878 sprintf(c_name_tmp, "*%s", c_name);
879 *w_return = XtNameToWidget(parent, c_name_tmp);
880
881 /* Deal with ScrollBars for ScrolledList and ScrolledText subclasses. */
882 if ((*w_return == NULL) &&
883 ((strcmp(c_name, "VertScrollBar") == 0) ||
884 (strcmp(c_name, "HorScrollBar") == 0)))
885 {
886 *w_return = XtNameToWidget(XtParent(parent), c_name_tmp);
887 }
888
889 DEALLOCATE_LOCAL(c_name_tmp);
890 }
891
892 if (*w_return == NULL)
893 return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0059,
894 NULL, context_id, MrmFAILURE) ;
895
896 /*
897 * Allocate the args list, big enough for all the arguments in the widget
898 * record plus all the override arguments. Also initialize a pointer list
899 * to save any contexts created to evaluate resources.
900 */
901 if ( widgetrec->arglist_offs != 0)
902 {
903 argdesc = (RGMArgListDescPtr)
904 ((char *)widgetrec + widgetrec->arglist_offs) ;
905 num_listent += argdesc->count + argdesc->extra ;
906 UrmPlistInit (10, &ftllist) ;
907 }
908 if ( num_listent > 0 )
909 {
910 args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ;
911 UrmPlistInit (10, &ptrlist) ;
912 }
913
914 /*
915 * Set up the structure for the callback list to free memory on destroy widget
916 */
917 UrmPlistInit (10, &cblist);
918
919 /*
920 * Set the arg list from the widget record argument list
921 */
922 if ( argdesc != NULL )
923 {
924 Urm__CW_CreateArglist
925 (parent, widgetrec, argdesc, ptrlist, cblist, ftllist,
926 hierarchy_id, file_id, args, svlist, wref_id, &num_used) ;
927 }
928
929 /*
930 * Copy in any override args
931 */
932 for ( ndx=0 ; ndx<ov_num_args ; ndx++ )
933 {
934 args[ndx+num_used].name = ov_args[ndx].name ;
935 args[ndx+num_used].value = ov_args[ndx].value ;
936 }
937 num_used += ov_num_args ;
938
939 /*
940 * Set the widget values
941 */
942 XtSetValues(*w_return, args, num_used) ;
943
944 /*
945 * If the uil file said unmanaged, then unmanage the widget.
946 */
947 if ( manage==MrmManageUnmanage )XtUnmanageChild(*w_return);
948
949 /*
950 * Call the creation callbacks if there are any.
951 */
952 if ( widgetrec->creation_offs != 0)
953 {
954 if (strcmp(file_id->db_version, URM1_1version) <= 0)
955 cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)
956 ((char *)widgetrec +
957 widgetrec->creation_offs));
958 else
959 cbptr = (RGMCallbackDescPtr) ((char *)widgetrec +
960 widgetrec->creation_offs) ;
961
962 if ( ptrlist == NULL )
963 UrmPlistInit (10, &ptrlist) ;
964 result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec,
965 cbptr, ptrlist, cblist, hierarchy_id,
966 file_id, wref_id) ;
967 if ( result == MrmSUCCESS )
968 for ( ndx=0 ; ndx<cbptr->count ; ndx++ )
969 {
970 itmptr = &cbptr->item[ndx] ;
971
972 cb_rtn = (void (*)()) itmptr->runtime.callback.callback ;
973 if ( cb_rtn != (XtCallbackProc)NULL )
974 /* BEGIN OSF Fix pir 2813 */
975 {
976 cb_reason.reason = MrmCR_CREATE;
977 cb_reason.event = NULL;
978 (*cb_rtn) (*w_return, itmptr->runtime.callback.closure,
979 &cb_reason) ;
980 }
981 /* END OSF Fix pir 2813 */
982 }
983 else if (result == MrmUNRESOLVED_REFS)
984 Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056,
985 NULL, NULL, MrmFAILURE) ;
986 else
987 return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057,
988 NULL, NULL, MrmFAILURE);
989
990 if (strcmp(file_id->db_version, URM1_1version) <= 0)
991 XtFree((char *)cbptr);
992 }
993
994 /*
995 * successfully set (as far as we can tell). Deallocate all local
996 * resources, including any contexts in the pointer list.
997 */
998 if ( args != NULL ) XtFree ((char*)args) ;
999 if ( ptrlist != NULL )
1000 {
1001 for ( ndx=0 ; ndx<UrmPlistNum(ptrlist) ; ndx++ )
1002 UrmFreeResourceContext ((URMResourceContextPtr)UrmPlistPtrN(ptrlist,ndx)) ;
1003 UrmPlistFree (ptrlist) ;
1004 }
1005
1006 /*
1007 * Add a destroy callback if the widget had any callbacks or font-lists
1008 * associated with it.
1009 * Otherwise just wipe out the memory for the Plist now.
1010 */
1011 if (cblist->num_ptrs > 0)
1012 {
1013 XtAddCallback (*w_return, XmNdestroyCallback,
1014 (XtCallbackProc) UrmDestroyCallback, cblist);
1015 }
1016 else
1017 {
1018 UrmPlistFree (cblist);
1019 }
1020
1021 /*
1022 ** We should really let Xt take care of handling the fontlists by using its
1023 ** converters; but for the meanwhile avoid freeing the fontlists here, as the
1024 ** widget may be one which doesn't do an XmFontListCopy. Instead, later free
1025 ** our extra copy.
1026 */
1027 if (ftllist != NULL)
1028 {
1029 if (UrmPlistNum(ftllist) > 0)
1030 XtAddCallback(*w_return, XmNdestroyCallback,
1031 (XtCallbackProc) UrmDestroyCallback, ftllist);
1032 else
1033 UrmPlistFree (ftllist) ;
1034 }
1035
1036 return MrmSUCCESS ;
1037
1038 }
1039
1040
1041 /*
1042 *++
1043 *
1044 * PROCEDURE DESCRIPTION:
1045 *
1046 * Urm__CW_CreateArglist reads the arglist descriptor in an RGM widget
1047 * record and produces a legal arglist for XtCreateWidget in the args
1048 * parameter. Any argument which encounters an error, or which must
1049 * be done with a SetValues, does not appear in the list.
1050 *
1051 * FORMAL PARAMETERS:
1052 *
1053 * parent parent of the widget being created
1054 * widgetrec widget record pointer
1055 * argdesc arglist descriptor in widget record
1056 * ctxlist A pointer list to save contexts created to
1057 * evaluate literals.
1058 * ftllist A pointer list to save fontlists created for use
1059 * as resource values, and which must be freed
1060 * hierarchy_id URM hierarchy from which to read public resources
1061 * file_id URM file from which to read private resources
1062 * args buffer in which the arglist array of longwords is to
1063 * be created. Caller guarantees that it is big enough
1064 * (since caller knows number of arguments).
1065 * svlist SetValues descriptor list. This routine will add
1066 * any SetValues widget arguments to this list.
1067 * wref_id reference structure from which references to
1068 * previously created widgets in the tree can be
1069 * resolved.
1070 * num_used Returns number of arguments actually set in args
1071 *
1072 * IMPLICIT INPUTS:
1073 *
1074 * IMPLICIT OUTPUTS:
1075 *
1076 * FUNCTION VALUE:
1077 *
1078 * SIDE EFFECTS:
1079 *
1080 *--
1081 */
1082
1083 void
Urm__CW_CreateArglist(Widget parent,RGMWidgetRecordPtr widgetrec,RGMArgListDescPtr argdesc,URMPointerListPtr ctxlist,URMPointerListPtr cblist,URMPointerListPtr ftllist,MrmHierarchy hierarchy_id,IDBFile file_id,ArgList args,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,Cardinal * num_used)1084 Urm__CW_CreateArglist (Widget parent,
1085 RGMWidgetRecordPtr widgetrec,
1086 RGMArgListDescPtr argdesc,
1087 URMPointerListPtr ctxlist,
1088 URMPointerListPtr cblist,
1089 URMPointerListPtr ftllist,
1090 MrmHierarchy hierarchy_id,
1091 IDBFile file_id,
1092 ArgList args,
1093 URMPointerListPtr *svlist,
1094 URMResourceContextPtr wref_id,
1095 Cardinal *num_used)
1096
1097 {
1098 /*
1099 * Local structures
1100 */
1101 typedef struct {
1102 RGMIconImagePtr icon ; /* icon to be converted */
1103 RGMArgumentPtr pixarg ; /* argument in widget record */
1104 String filename; /* file name if pixtype is bitmap */
1105 MrmType pixtype ; /* MrmRtypeIconImage or */
1106 /* MrmRtypeXBitmapFile */
1107 } _SavePixmapItem, *_SavePixmapItemPtr ;
1108
1109 /*
1110 * Local variables
1111 */
1112 Cardinal result ; /* function results */
1113 int ndx, cbndx; /* loop indices */
1114 RGMArgumentPtr argptr ; /* current argument descriptor */
1115 MrmType reptype ; /* arg value representation type */
1116 long argval ; /* arg value as it is in record */
1117 int vec_count ; /* count of items in the vector */
1118 long val ; /* value as immediate or pointer */
1119 RGMCallbackDescPtr cbptr ; /* val as callback descriptor */
1120 RGMCallbackItemPtr items; /* Callback items as RGM items */
1121 XtCallbackRec *callbacks; /* Callback items as Xt callbacks */
1122 RGMIconImagePtr icon ; /* val as icon image */
1123 RGMResourceDescPtr resptr ; /* values as resource reference */
1124 String ref_name ; /* referenced widget name */
1125 Widget ref_id ; /* referenced widget id */
1126 IDBFile act_file ; /* file from which literals read */
1127 RGMTextVectorPtr vecptr ; /* text vector arg value */
1128 char err_msg[300] ;
1129 _SavePixmapItem pixargs[10] ; /* to save pixmap args */
1130 Cardinal pixargs_cnt = 0 ; /* # pixargs saved */
1131 _SavePixmapItemPtr savepix ; /* current saved pixmap entry */
1132 Screen *screen ; /* screen for pixmaps */
1133 Display *display ; /* display for pixmaps */
1134 Pixel fgint = (Pixel) -1 ; /* fg for pixmaps */
1135 Pixel bgint = (Pixel) -1 ; /* background for pixmaps */
1136 Pixmap pixmap ; /* result of icon conversion */
1137 Cardinal uncmp_res ; /* string uncompression result */
1138 WCIClassDescPtr class_desc ; /* for URM__FindClassDescriptor */
1139 String resource_name ; /* resource name for comparison */
1140 int vec_size ;
1141 RGMFontListPtr fontlist; /* for converting old style fontlist */
1142 Boolean swap_needed; /* for resource arguments */
1143
1144 /*
1145 * Loop through all the arguments in descriptor. An entry is made in the
1146 * in the arglist for each entry which can be successfully evaluated,
1147 * fixed up, and converted.
1148 *
1149 * Some arguments may be affected by other arg values in the arglist. These
1150 * are deferred so that these other values will
1151 * be available if they are present in the arglist. This removes order
1152 * dependency. All such arguments are handled as special cases:
1153 * IconImages: saved in pixargs vector
1154 *
1155 * Ordering may have an important effect on finding widget references. In
1156 * particular, references to widgets in submenus depends on the submenus
1157 * being created before the reference, as the referenced widget then
1158 * appears in the widget reference structure. This is currently done
1159 * by the compiler, which orders submenus first in an arglist.
1160 */
1161 for ( ndx=0 ; ndx<argdesc->count ; ndx++ )
1162 {
1163 argptr = &argdesc->args[ndx] ;
1164 reptype = argptr->arg_val.rep_type ;
1165 swap_needed = FALSE ;
1166
1167 /*
1168 * Create the value. Some representation types and arguments require
1169 * special handling. First, the immediate value or pointer is evaluated.
1170 * then special handling is done. If no special handling is required, then
1171 * the value is fixed up, converted, and put in the args list.
1172 *
1173 * Icon images are loaded (i.e. brought into memory and all pointer
1174 * fixups done), but they are then treated as SetValues args, and saved
1175 * for processing after the widget is created.
1176 */
1177 argval = Urm__CW_EvaluateValOrOffset (reptype, (XtPointer)widgetrec,
1178 argptr->arg_val.datum.ival,
1179 argptr->arg_val.datum.offset) ;
1180 val = argval ;
1181 switch ( reptype )
1182 {
1183 case MrmRtypeCallback:
1184 if (strcmp(file_id->db_version, URM1_1version) <= 0)
1185 cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)val);
1186 else
1187 cbptr = (RGMCallbackDescPtr)val;
1188
1189 result = Urm__CW_FixupCallback(parent, (XtPointer)widgetrec, cbptr,
1190 ctxlist, cblist, hierarchy_id,
1191 file_id, wref_id) ;
1192 switch (result)
1193 {
1194 case MrmSUCCESS:
1195 /* Move individual items so array functions as callback list */
1196 items = cbptr->item;
1197 callbacks = (XtCallbackRec *)((RGMCallbackDescPtr)val)->item;
1198
1199 for (cbndx = 0; cbndx <= cbptr->count; cbndx++)
1200 /* <= so that null item is copied. */
1201 {
1202 callbacks[cbndx].callback = (XtCallbackProc)
1203 items[cbndx].runtime.callback.callback;
1204 callbacks[cbndx].closure = (XtPointer)
1205 items[cbndx].runtime.callback.closure;
1206 }
1207
1208 val = (long)callbacks;
1209 break;
1210 case MrmUNRESOLVED_REFS:
1211 Urm__CW_AppendCBSVWidgetRef
1212 (file_id, svlist, cbptr, argptr->tag_code,
1213 (String) ((char *)widgetrec+argptr->stg_or_relcode.tag_offs));
1214 /* No break */
1215 default:
1216 continue;
1217 }
1218 if (strcmp(file_id->db_version, URM1_1version) <= 0)
1219 XtFree((char *)cbptr);
1220 break ;
1221 case MrmRtypeResource:
1222 resptr = (RGMResourceDescPtr) val ;
1223 if (resptr->cvt_type & MrmResourceUnswapped)
1224 {
1225 resptr->cvt_type &= ~MrmResourceUnswapped;
1226 swap_needed = TRUE;
1227 }
1228
1229 switch ( resptr->res_group )
1230 {
1231 case URMgWidget:
1232 if ( ((unsigned char)resptr->cvt_type==RGMwrTypeSubTree) ||
1233 Urm__IsSubtreeResource(file_id,argptr->tag_code) )
1234 {
1235 result =
1236 Urm__CW_LoadWidgetResource (parent, widgetrec, resptr,
1237 ctxlist, hierarchy_id, file_id,
1238 svlist, wref_id, &val) ;
1239 if ( result != MrmSUCCESS ) continue ;
1240 }
1241 else
1242 {
1243 if ( resptr->type != URMrIndex )
1244 {
1245 Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0060,
1246 NULL, NULL, MrmFAILURE) ;
1247 continue;
1248 }
1249 ref_name = (String) resptr->key.index;
1250 result = Urm__CW_FindWRef (wref_id, ref_name, &ref_id) ;
1251 if ( result != MrmSUCCESS )
1252 {
1253 Urm__CW_AppendSVWidgetRef
1254 (file_id, svlist, ref_name, argptr->tag_code,
1255 (String)widgetrec+
1256 argptr->stg_or_relcode.tag_offs);
1257 continue ;
1258 }
1259 val = (long) ref_id ;
1260 }
1261 break ;
1262 case URMgLiteral:
1263 result = Urm__CW_ReadLiteral (resptr, hierarchy_id, file_id,
1264 ctxlist, &reptype, &argval,
1265 &vec_count, &act_file, &vec_size) ;
1266 val = argval ;
1267 if ( result != MrmSUCCESS ) continue ;
1268 switch ( reptype )
1269 {
1270 case MrmRtypeIconImage:
1271 savepix = &pixargs[pixargs_cnt] ;
1272 savepix->icon = (RGMIconImagePtr) val ;
1273 savepix->pixarg = argptr ;
1274 savepix->pixtype = reptype ;
1275 pixargs_cnt += 1 ;
1276 continue ;
1277 case MrmRtypeXBitmapFile:
1278 savepix = &pixargs[pixargs_cnt] ;
1279 savepix->filename = (String) val ;
1280 savepix->pixarg = argptr ;
1281 savepix->pixtype = reptype ;
1282 pixargs_cnt += 1 ;
1283 continue ;
1284 case MrmRtypeInteger:
1285 case MrmRtypeBoolean:
1286 if ( swap_needed )
1287 {
1288 swapbytes( val );
1289 swap_needed = FALSE ;
1290 }
1291 break;
1292 case MrmRtypeFontList:
1293 if (strcmp(file_id->db_version, URM1_1version) <= 0)
1294 {
1295 int count = ((OldRGMFontListPtr)val)->count;
1296 fontlist = (RGMFontListPtr)
1297 XtMalloc(sizeof(RGMFontList) +
1298 (sizeof(RGMFontItem) * (count - 1)));
1299 result = Urm__CW_FixupValue((long)fontlist, reptype,
1300 (XtPointer)val, file_id,
1301 &swap_needed);
1302 val = (long)fontlist;
1303 }
1304 else
1305 result = Urm__CW_FixupValue(val, reptype,
1306 (XtPointer)val,
1307 file_id, &swap_needed) ;
1308 break;
1309 case MrmRtypeSingleFloat:
1310 if ( swap_needed )
1311 {
1312 swapbytes( val );
1313 swap_needed = FALSE ;
1314 }
1315 _MrmOSIEEEFloatToHost( (float *) &val );
1316 break;
1317 case MrmRtypeFloat:
1318 if ( swap_needed )
1319 {
1320 swapdouble( *(double *)val );
1321 swap_needed = FALSE ;
1322 }
1323 _MrmOSIEEEDoubleToHost( (double *) val );
1324 break;
1325 default:
1326 result = Urm__CW_FixupValue(val,reptype,(XtPointer)val,
1327 file_id, &swap_needed) ;
1328 }
1329 if ( result != MrmSUCCESS ) continue ;
1330
1331 /*
1332 * Fix for CR 5410 - Do not run ConvertValue on Colors
1333 * because the parent's colormap should be used when
1334 * allocating the colors which is currently impossible
1335 * in ConvertValue. Convert the colors separately.
1336 */
1337 if (reptype == MrmRtypeColor)
1338 {
1339 Pixel pix;
1340 RGMColorDescPtr colorptr;
1341 Colormap cmap;
1342
1343 uncmp_res = Urm__FindClassDescriptor
1344 (file_id, widgetrec->type,
1345 (XtPointer)((char *)widgetrec+widgetrec->class_offs),
1346 &class_desc) ;
1347 if ((uncmp_res == MrmSUCCESS) &&
1348 (class_desc->creator == _XmCreateRendition))
1349 {
1350 display = _XmRenderTableDisplay((XmRenderTable)parent);
1351 cmap = XDefaultColormap(display, XDefaultScreen(display));
1352 }
1353 else {
1354 display = XtDisplay(parent);
1355 cmap = parent->core.colormap;
1356 }
1357
1358 colorptr = (RGMColorDescPtr) val;
1359 switch (colorptr->desc_type)
1360 {
1361 case URMColorDescTypeName:
1362 result = Urm__UT_GetNamedColorPixel
1363 (display, cmap, colorptr, &pix,
1364 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display)));
1365 if ( result != MrmSUCCESS )
1366 {
1367 sprintf (err_msg, _MrmMMsg_0061,
1368 (String)(colorptr->desc.name)) ;
1369 result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg,
1370 NULL, NULL, MrmNOT_FOUND) ;
1371 }
1372 break;
1373 case URMColorDescTypeRGB:
1374 result = Urm__UT_GetColorPixel
1375 (display, cmap, colorptr, &pix,
1376 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display)));
1377 if ( result != MrmSUCCESS )
1378 {
1379 sprintf (err_msg, _MrmMMsg_0039,
1380 colorptr->desc.rgb.red,
1381 colorptr->desc.rgb.green,
1382 colorptr->desc.rgb.blue) ;
1383 result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg,
1384 NULL, NULL, MrmNOT_FOUND) ;
1385 }
1386 break;
1387 default:
1388 sprintf (err_msg, _MrmMMsg_0040);
1389 result = Urm__UT_Error ("Urm__CW_ConvertValue",
1390 err_msg, NULL, NULL, MrmFAILURE) ;
1391 };
1392 val = (long) pix ;
1393 }
1394 else
1395 /*
1396 * End Fix for CR 5410
1397 */
1398 {
1399 uncmp_res = Urm__FindClassDescriptor
1400 (file_id, widgetrec->type,
1401 (XtPointer)((char *)widgetrec+widgetrec->class_offs),
1402 &class_desc) ;
1403 if ((uncmp_res == MrmSUCCESS) &&
1404 (class_desc->creator == _XmCreateRendition))
1405 display = _XmRenderTableDisplay((XmRenderTable)parent);
1406 else
1407 display = XtDisplay(parent);
1408
1409 result = Urm__CW_ConvertValue (parent, &val, reptype,
1410 resptr->cvt_type, display,
1411 hierarchy_id, ftllist) ;
1412 }
1413
1414 if ( result != MrmSUCCESS ) continue ;
1415 if ( argptr->tag_code == UilMrmUnknownCode )
1416 {
1417 resource_name = (char *)
1418 ((char *)widgetrec+argptr->stg_or_relcode.tag_offs) ;
1419 }
1420 else
1421 {
1422 uncmp_res = Urm__UncompressCode
1423 (file_id, argptr->tag_code, &resource_name) ;
1424 if ( uncmp_res != MrmSUCCESS )
1425 {
1426 sprintf (err_msg, _MrmMMsg_0062,
1427 argptr->tag_code) ;
1428 Urm__UT_Error ("Urm__CW_CreateArglist",
1429 err_msg, NULL, NULL, uncmp_res) ;
1430 }
1431 }
1432
1433 if ( strcmp(resource_name, XmNuserData) == 0)
1434 {
1435 switch (reptype)
1436 {
1437 case MrmRtypeChar8Vector:
1438 case MrmRtypeCStringVector:
1439 vec_size -= (sizeof ( RGMTextVector ) -
1440 sizeof ( RGMTextEntry ));
1441 break;
1442 default:
1443 break;
1444 }
1445 Urm__CW_SafeCopyValue (&val, reptype, cblist,
1446 vec_count, vec_size);
1447 }
1448
1449 /*
1450 * Fix for CR 3281 - check to see if the resource_name
1451 * is XmNaccelerators. If it is, run
1452 * XtParseAcceleratorTable and assign the output to val.
1453 */
1454 if ( strcmp(resource_name, XmNaccelerators) == 0)
1455 {
1456 val = (long)XtParseAcceleratorTable((String)argval);
1457 }
1458 /*
1459 * End fix for CR 3281
1460 */
1461 break ;
1462
1463 default:
1464 Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0063,
1465 NULL, NULL, MrmFAILURE) ;
1466 continue ;
1467 }
1468 break ;
1469 case MrmRtypeIconImage:
1470 icon = (RGMIconImagePtr) val ;
1471 result = Urm__CW_LoadIconImage (icon, (XtPointer)widgetrec,
1472 hierarchy_id, file_id, ctxlist) ;
1473 if ( result != MrmSUCCESS ) continue ;
1474 savepix = &pixargs[pixargs_cnt] ;
1475 savepix->icon = icon ;
1476 savepix->pixarg = argptr ;
1477 savepix->pixtype = reptype ;
1478 pixargs_cnt += 1 ;
1479 continue ;
1480 case MrmRtypeXBitmapFile:
1481 savepix = &pixargs[pixargs_cnt] ;
1482 savepix->filename = (String) val ;
1483 savepix->pixarg = argptr ;
1484 savepix->pixtype = reptype ;
1485 pixargs_cnt += 1 ;
1486 continue ;
1487 default:
1488 result = Urm__CW_FixupValue (val, reptype, (XtPointer)widgetrec,
1489 file_id, &swap_needed) ;
1490 if ( result != MrmSUCCESS ) continue ;
1491 uncmp_res = Urm__FindClassDescriptor
1492 (file_id, widgetrec->type,
1493 (XtPointer)((char *)widgetrec+widgetrec->class_offs),
1494 &class_desc);
1495 if ((uncmp_res == MrmSUCCESS) &&
1496 (class_desc->creator == _XmCreateRendition))
1497 display = _XmRenderTableDisplay((XmRenderTable)parent);
1498 else if ((uncmp_res == MrmSUCCESS) &&
1499 (class_desc->creator == _XmCreateTab))
1500 display = NULL;
1501 else display = XtDisplay(parent);
1502 result = Urm__CW_ConvertValue
1503 (parent, &val, reptype, 0, display,
1504 hierarchy_id, ftllist) ;
1505 if ( result != MrmSUCCESS ) continue ;
1506 break ;
1507 }
1508
1509 args[*num_used].value = (XtArgVal)val ;
1510
1511 /*
1512 * Create the tag string in the name slot of the current entry. Also
1513 * do any special processing based on tag code:
1514 * - Retain values of foreground and background if they are
1515 * explicitly set
1516 * - Set the count for some lists
1517 *
1518 * 'argval' has preserved the pointer to RGM structures which may have
1519 * been replaced in 'val' by a pointer to structures (lists) required by
1520 * the toolkit
1521 */
1522 if ( argptr->tag_code == UilMrmUnknownCode )
1523 {
1524 args[*num_used].name = (char *)
1525 widgetrec+argptr->stg_or_relcode.tag_offs ;
1526 *num_used += 1 ;
1527 }
1528 else
1529 {
1530 uncmp_res = Urm__UncompressCode
1531 (file_id, argptr->tag_code, &(args[*num_used].name)) ;
1532 if ( uncmp_res == MrmSUCCESS )
1533 *num_used += 1 ;
1534 else
1535 {
1536 sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ;
1537 Urm__UT_Error ("Urm__CW_CreateArglist", err_msg,
1538 NULL, NULL, uncmp_res) ;
1539 }
1540 }
1541
1542 /*
1543 * Special processing:
1544 * retain the value pointer for foreground or background.
1545 * Note reference to name in arglist from previous operation.
1546 */
1547 /* Begin fixing OSF 5473 */
1548 if(*num_used){
1549 if ( strcmp(args[*num_used-1].name,XmNforeground) == 0 )
1550 fgint = val ;
1551 if ( strcmp(args[*num_used-1].name,XmNbackground) == 0 )
1552 bgint = val ;
1553 }
1554 /* End fixing OSF 5473 */
1555
1556 /*
1557 * Create an additional arglist entry for the count field for any argument
1558 * which has a related argument (which is always a counter)
1559 */
1560 if ( argptr->tag_code != UilMrmUnknownCode )
1561 if ( argptr->stg_or_relcode.related_code != 0)
1562 {
1563 switch ( reptype )
1564 {
1565 case MrmRtypeChar8Vector:
1566 case MrmRtypeCStringVector:
1567 /*
1568 * Fix for HaL DTS 10226 - If the type is Integer Vector
1569 * (used mainly in the XmNselectionArray resource on
1570 * the Text and TextField widgets), load in the count
1571 * for the XmNselectionArrayCount resource.
1572 */
1573 case MrmRtypeIntegerVector:
1574 vecptr = (RGMTextVectorPtr) argval;
1575 args[*num_used].value = (XtArgVal)vecptr->count;
1576 break;
1577 }
1578 uncmp_res = Urm__UncompressCode
1579 (file_id, argptr->stg_or_relcode.related_code,
1580 &args[*num_used].name);
1581 if ( uncmp_res == MrmSUCCESS )
1582 *num_used += 1;
1583 else
1584 {
1585 sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ;
1586 Urm__UT_Error ("Urm__CW_CreateArglist", err_msg,
1587 NULL, NULL, uncmp_res) ;
1588 }
1589 }
1590
1591 } /* Loop end */
1592
1593
1594 /*
1595 * Now set any pixmap arguments. This requires finding the display, screen,
1596 * foreground, and background values for this widget. These values are
1597 * available from the parent widget and the arglist.
1598 */
1599 if ( pixargs_cnt > 0 )
1600 {
1601 Urm__CW_GetPixmapParms (parent, &screen, &display, &fgint, &bgint) ;
1602 for ( ndx=0,savepix=pixargs ; ndx<pixargs_cnt ; ndx++,savepix++ )
1603 {
1604 if ( savepix->pixtype == MrmRtypeXBitmapFile ) {
1605 result = Urm__CW_ReadBitmapFile
1606 (savepix->filename, screen,
1607 fgint, bgint, &pixmap, parent);
1608 if ( result != MrmSUCCESS ) continue ;
1609 }
1610 else {
1611 /*
1612 ** Create a pixmap from an Icon definition
1613 */
1614 result = UrmCreatePixmap (savepix->icon, screen, display,
1615 fgint, bgint, &pixmap, parent) ;
1616 if ( result != MrmSUCCESS ) continue ;
1617 }
1618
1619 /*
1620 ** Place resultant Pixmap in arglist
1621 */
1622 args[*num_used].value = (XtArgVal) pixmap ;
1623 argptr = savepix->pixarg ;
1624 if ( argptr->tag_code == UilMrmUnknownCode )
1625 args[*num_used].name = (char *)
1626 (widgetrec+argptr->stg_or_relcode.tag_offs) ;
1627 else
1628 Urm__UncompressCode
1629 (file_id, argptr->tag_code, &(args[*num_used].name)) ;
1630 *num_used += 1 ;
1631 }
1632 }
1633
1634 /*
1635 * arglist creation complete.
1636 */
1637
1638 }
1639
1640
1641
1642 /*
1643 *++
1644 *
1645 * PROCEDURE DESCRIPTION:
1646 *
1647 * Return either a immediate value (ival) or a widget record memory
1648 * pointer depending on the representation type.
1649 *
1650 * FORMAL PARAMETERS:
1651 *
1652 * reptype representation type, from RGMrType...
1653 * bufptr buffer address for offset
1654 * ival immediate value
1655 * offset offset in widget record
1656 *
1657 * IMPLICIT INPUTS:
1658 *
1659 * IMPLICIT OUTPUTS:
1660 *
1661 * FUNCTION VALUE:
1662 *
1663 * SIDE EFFECTS:
1664 *
1665 *--
1666 */
1667
1668 long
Urm__CW_EvaluateValOrOffset(MrmType reptype,XtPointer bufptr,long ival,MrmOffset offset)1669 Urm__CW_EvaluateValOrOffset (MrmType reptype,
1670 XtPointer bufptr,
1671 long ival,
1672 MrmOffset offset)
1673 {
1674
1675 switch ( reptype )
1676 {
1677 case MrmRtypeInteger:
1678 case MrmRtypeBoolean:
1679 case MrmRtypeSingleFloat:
1680 return ival ;
1681 case MrmRtypeNull:
1682 return 0;
1683 default:
1684 return (long) ((char *)bufptr+offset) ;
1685 }
1686
1687 }
1688
1689
1690
1691 /*
1692 *++
1693 *
1694 * PROCEDURE DESCRIPTION:
1695 *
1696 * This routine does any fixups required on a value. The fixups are
1697 * usually relocation of pointers within the object located by the
1698 * value interpreted as a pointer to a data structure.
1699 *
1700 * FORMAL PARAMETERS:
1701 *
1702 * val value of an argument (may be a pointer)
1703 * reptype vaue representation type, from RGMrType...
1704 * bufptr the buffer (base address) for any fixed-up
1705 * values
1706 *
1707 * IMPLICIT INPUTS:
1708 *
1709 * IMPLICIT OUTPUTS:
1710 *
1711 * FUNCTION VALUE:
1712 *
1713 * MrmSUCCESS ;
1714 *
1715 * SIDE EFFECTS:
1716 *
1717 *--
1718 */
1719
1720 /*ARGSUSED*/
1721 Cardinal
Urm__CW_FixupValue(long val,MrmType reptype,XtPointer bufptr,IDBFile file_id,Boolean * swap_needed)1722 Urm__CW_FixupValue (long val,
1723 MrmType reptype,
1724 XtPointer bufptr,
1725 IDBFile file_id, /* unused */
1726 Boolean *swap_needed)
1727 {
1728 /*
1729 * Local variables
1730 */
1731 RGMTextVectorPtr vecptr ; /* text vector arg value */
1732 int fixndx ; /* list fixup loop index */
1733 /* BEGIN OSF Fix CR 4859 */
1734 RGMWCharEntryPtr wcharentry; /* Resource as wide character string */
1735 wchar_t *wcstr_r;
1736 size_t max_size, str_size;
1737 /* END OSF Fix CR 4859 */
1738 RGMFontItemPtr fontitem; /* resource as font item */
1739 OldRGMFontItemPtr olditem; /* old style font item */
1740 RGMFontListPtr fontlist ; /* resource as font list */
1741 OldRGMFontListPtr oldlist ; /* resource as old style font list */
1742
1743 switch ( reptype )
1744 {
1745 case MrmRtypeChar8Vector:
1746 case MrmRtypeCStringVector:
1747 vecptr = (RGMTextVectorPtr) val ;
1748 if ( *swap_needed )
1749 {
1750 swapbytes(vecptr->count);
1751 swapbytes(vecptr->validation);
1752 }
1753 for ( fixndx=0 ; fixndx<vecptr->count ; fixndx++ )
1754 {
1755 if ( *swap_needed )
1756 {
1757 #ifdef WORD64
1758 swap4bytes(vecptr->item[fixndx].text_item.rep_type);
1759 swap4bytes(vecptr->item[fixndx].text_item.offset);
1760 #else
1761 swap2bytes(vecptr->item[fixndx].text_item.rep_type);
1762 swap2bytes(vecptr->item[fixndx].text_item.offset);
1763 #endif
1764 }
1765 if (reptype == MrmRtypeChar8Vector)
1766 vecptr->item[fixndx].pointer = (XtPointer)
1767 ((char *)bufptr+vecptr->item[fixndx].text_item.offset) ;
1768 else
1769 vecptr->item[fixndx].pointer = (XtPointer)
1770 XmCvtByteStreamToXmString((unsigned char *)bufptr +
1771 vecptr->item[fixndx].text_item.offset);
1772 }
1773 *swap_needed = FALSE;
1774 break ;
1775
1776 /* BEGIN OSF Fix CR 4859 */
1777 case MrmRtypeWideCharacter:
1778 wcharentry = (RGMWCharEntryPtr)val;
1779 if (*swap_needed)
1780 swapbytes(wcharentry->wchar_item.count);
1781 /* Allocate memory */
1782 max_size = wcharentry->wchar_item.count;
1783 wcstr_r = (wchar_t *)XtMalloc(sizeof(wchar_t) * (max_size + 1));
1784
1785 /* Convert, realloc, store */
1786 str_size = mbstowcs(wcstr_r, wcharentry->wchar_item.bytes, max_size);
1787 if (str_size == -1)
1788 return(Urm__UT_Error("Urm__CW_FixupValue", _MrmMMsg_0110,
1789 NULL, NULL, MrmFAILURE));
1790 if (str_size != max_size)
1791 wcstr_r = (wchar_t *)XtRealloc((char *)wcstr_r,
1792 sizeof(wchar_t) * (str_size + 1));
1793 else
1794 wcstr_r[str_size] = (wchar_t)0L;
1795 wcharentry->pointer = (XtPointer)wcstr_r;
1796 *swap_needed = FALSE;
1797 break;
1798
1799 /* END OSF Fix CR 4859 */
1800 case MrmRtypeFont:
1801 case MrmRtypeFontSet:
1802 fontitem = (RGMFontItemPtr) val;
1803 if ( *swap_needed )
1804 {
1805 swapbytes( fontitem->cset.cs_offs );
1806 swapbytes( fontitem->font.font_offs );
1807 }
1808 fontitem->cset.charset = (/*XmStringCharset*/String)
1809 bufptr+fontitem->cset.cs_offs;
1810 fontitem->font.font = (String)
1811 bufptr+fontitem->font.font_offs;
1812 *swap_needed = FALSE;
1813 break;
1814 case MrmRtypeFontList:
1815 if (strcmp(file_id->db_version, URM1_1version) <= 0)
1816 /* Converting an old style fontlist */
1817 {
1818 oldlist = (OldRGMFontListPtr)bufptr;
1819
1820 fontlist = (RGMFontListPtr)val;
1821
1822 fontlist->validation = oldlist->validation;
1823 fontlist->count = oldlist->count;
1824
1825 for ( fixndx=0 ; fixndx<oldlist->count ; fixndx++ )
1826 {
1827 olditem = &oldlist->item[fixndx];
1828 fontitem = &fontlist->item[fixndx];
1829
1830 fontitem->cset.charset =
1831 XtNewString(( /*XmStringCharset*/String)
1832 bufptr+olditem->cset.cs_offs);
1833 fontitem->font.font =
1834 XtNewString((String)bufptr+olditem->font.font_offs);
1835 fontitem->type = MrmRtypeFont;
1836 }
1837 }
1838 else
1839 {
1840 fontlist = (RGMFontListPtr) val ;
1841 if ( *swap_needed )
1842 {
1843 swapbytes( fontlist->validation );
1844 swapbytes( fontlist->count );
1845 }
1846 for ( fixndx=0 ; fixndx<fontlist->count ; fixndx++ )
1847 {
1848 fontitem = &fontlist->item[fixndx];
1849 if ( *swap_needed )
1850 {
1851 swapbytes( fontitem->cset.cs_offs );
1852 swapbytes( fontitem->font.font_offs );
1853 swapbytes( fontitem->type );
1854 }
1855 fontitem->cset.charset = ( /*XmStringCharset*/String)
1856 bufptr+fontitem->cset.cs_offs;
1857 fontitem->font.font = (String)
1858 bufptr+fontitem->font.font_offs;
1859 }
1860 }
1861 *swap_needed = FALSE;
1862 break ;
1863 case MrmRtypeHorizontalInteger:
1864 case MrmRtypeVerticalInteger:
1865 {
1866 RGMUnitsIntegerPtr unitsvalue;
1867
1868 unitsvalue = (RGMUnitsIntegerPtr) val;
1869 if ( *swap_needed )
1870 {
1871 swapbytes( unitsvalue->value );
1872 swapbytes( unitsvalue->units );
1873 *swap_needed = FALSE;
1874 }
1875 }
1876 break ;
1877 case MrmRtypeHorizontalFloat:
1878 case MrmRtypeVerticalFloat:
1879 {
1880 RGMUnitsFloatPtr unitsvalue;
1881 double *floatval;
1882
1883 unitsvalue = (RGMUnitsFloatPtr) val;
1884 floatval = (double *)(&unitsvalue->value[0]);
1885 if ( *swap_needed )
1886 {
1887 swapdouble(*floatval);
1888 swapbytes( unitsvalue->units );
1889 }
1890 *swap_needed = FALSE;
1891 _MrmOSIEEEDoubleToHost( floatval );
1892 *((double *)(&unitsvalue->value[0])) = *floatval;
1893 }
1894 break ;
1895 default:
1896 break ;
1897 }
1898 return MrmSUCCESS ;
1899
1900 }
1901
1902
1903
1904 /*
1905 *++
1906 *
1907 * PROCEDURE DESCRIPTION:
1908 *
1909 * This routine converts the display into a string byte by
1910 * byte. Any Null bytes are not (?) omitted in returned string.
1911 *
1912 * FORMAL PARAMETERS:
1913 *
1914 * val the value to be converted (may be a pointer)
1915 * add_sting a string to be added to the returned string
1916 * after the display.
1917 * add_string_size the additional string length when Calloc on
1918 * the return value is done.
1919 *
1920 * IMPLICIT INPUTS:
1921 *
1922 * IMPLICIT OUTPUTS:
1923 *
1924 * FUNCTION VALUE:
1925 *
1926 * returns the string if one is created, otherwise returns null
1927 *
1928 * SIDE EFFECTS:
1929 *
1930 *--
1931 */
1932
1933 String
Urm__CW_DisplayToString(char * val,String add_string,int add_string_size)1934 Urm__CW_DisplayToString (char *val,
1935 String add_string,
1936 int add_string_size)
1937 {
1938 /*
1939 * Local variables
1940 */
1941 String return_val;
1942 unsigned int dpysize = sizeof(Display *);
1943 int ndx;
1944 int count=0;
1945
1946 return_val = XtCalloc (1, dpysize + add_string_size);
1947 if (return_val == NULL)
1948 {
1949 return (return_val);
1950 }
1951
1952 for (ndx=0 ; ndx<dpysize ; ndx++)
1953 {
1954 /* SUPPRESS 112 */
1955 if (val[ndx] != '\0')
1956 {
1957 /* SUPPRESS 112 */
1958 return_val[count] = val[ndx];
1959 count ++;
1960 }
1961 }
1962
1963 if (count == 0)
1964 {
1965 XtFree (return_val);
1966 return_val = NULL;
1967 return (return_val);
1968 }
1969
1970 strcat (&return_val[count], add_string);
1971
1972 return (return_val);
1973
1974 }
1975
1976
1977 /*
1978 *++
1979 *
1980 * PROCEDURE DESCRIPTION:
1981 *
1982 * This routine performs any type conversion required. All
1983 * conversion required are specified by the representation
1984 * type.
1985 *
1986 * Where conversion of a representation is expensive, and the
1987 * results of the conversion are repeatable, conversions are
1988 * done once and cached in the callbacks routine hash table.
1989 *
1990 * FORMAL PARAMETERS:
1991 *
1992 * val the value to be converted (may be a pointer)
1993 * reptype value representation type, from RGMrType...
1994 * cvttype conversion destination type, from RGMrType...
1995 * display needed for font and pixel creation
1996 * hierarchy_id for name lookup
1997 * ftllist A pointer list to save fontlists and XmStrings created
1998 * for use as resource values, and which must be freed
1999 *
2000 * IMPLICIT INPUTS:
2001 *
2002 * IMPLICIT OUTPUTS:
2003 *
2004 * FUNCTION VALUE:
2005 *
2006 * MrmSUCCESS operation succeeded
2007 * MrmFAILURE conversion failure, don't use argument
2008 *
2009 * SIDE EFFECTS:
2010 *
2011 *--
2012 */
2013
2014 Cardinal
Urm__CW_ConvertValue(Widget parent,long * val,MrmType reptype,MrmType cvttype,Display * display,MrmHierarchy hierarchy_id,URMPointerListPtr ftllist)2015 Urm__CW_ConvertValue (Widget parent,
2016 long *val,
2017 MrmType reptype,
2018 MrmType cvttype,
2019 Display *display,
2020 MrmHierarchy hierarchy_id,
2021 URMPointerListPtr ftllist)
2022 {
2023 /*
2024 * Local variables
2025 */
2026 Cardinal result ; /* function results */
2027 XFontStruct *font ; /* result of conversion to font */
2028 XFontSet fontset ; /* result of converstion to fontset */
2029 char **missing_csets; /* For XCreateFontSet */
2030 int missing_cset_cnt; /* For XCreateFontSet */
2031 char *def_string; /* For XCreateFontSet */
2032 XmFontListEntry fontset_entry; /* For creating fontlist */
2033 XtTranslations trans ; /* result of parsing trans table */
2034 WidgetClass clrec ; /* result of class name conversion */
2035 XtPointer addr ; /* result of variable conversion */
2036 String fontstg ; /* font id string */
2037 RGMFontItemPtr fontptr ; /* val as font descriptor */
2038 RGMFontListPtr fontlist ; /* val as font list */
2039 XmFontList dfontlist = NULL; /* converted font list */
2040 RGMColorDescPtr colorptr ; /* val as color descriptor */
2041 Pixel pix ; /* result of color/pixel conversion */
2042 int ndx ; /* conversion loop index */
2043 KeySym xkey; /* result of keysym conversion */
2044 char err_msg[300] ;
2045 XmString cstg ; /* to copy compound strings */
2046 String dpyandfontstr;
2047 RGMTextVectorPtr vecptr ; /* val as text vector */
2048 int vec_count; /* for moving strings */
2049 int orientation = XmNO_ORIENTATION; /* for values w/units */
2050 Screen *screen;
2051 RGMUnitsIntegerPtr unitsintvalue;
2052 RGMUnitsFloatPtr unitsfloatvalue;
2053 Pixel fgint = (Pixel) -1;
2054 Pixel bgint = (Pixel) -1;
2055 Pixmap pixmap;
2056
2057 /* BEGIN HAL Fix CR 5439 */
2058 /* If the cvttype is not zero, we should do some
2059 type checking here to avoid the confusing error
2060 message issued like the bug CR 5439 case. The
2061 following is for fixing that defect. */
2062
2063 if(cvttype){/* If destination type is clear, definitly need conversion */
2064 /* Need to do type conversion */
2065 switch(cvttype){
2066
2067 case MrmRtypeIconImage:
2068 if(reptype == MrmRtypeInteger)
2069 {
2070 sprintf(err_msg, _MrmMMsg_0111, (*val)) ;
2071 return Urm__UT_Error ("Urm__CW_ConvertValue",
2072 err_msg, NULL, NULL, MrmFAILURE);
2073 }
2074 break;
2075
2076 default: /* The place to do other type checking in Mrm */
2077 /*EMPTY*/;
2078 }
2079 }
2080 /* END HAL Fix CR 5439 */
2081 switch ( reptype )
2082 {
2083 case MrmRtypeChar8:
2084 {
2085 switch ( cvttype )
2086 {
2087 case MrmRtypeCString:
2088 cstg = XmStringGenerate(((String)*val), XmFONTLIST_DEFAULT_TAG,
2089 XmCHARSET_TEXT, NULL);
2090 if ( cstg == NULL )
2091 {
2092 sprintf (err_msg, _MrmMMsg_0064, (String)(*val)) ;
2093 return Urm__UT_Error ("Urm__CW_ConvertValue",
2094 err_msg, NULL, NULL, MrmFAILURE) ;
2095 }
2096 *val = (long) cstg;
2097 /* BEGIN OSF Fix CR 6189 */
2098 /* fix memory leak */
2099 if ( ftllist != NULL )
2100 {
2101 UrmPlistAppendPointer (ftllist, (XtPointer)(long)cvttype);
2102 UrmPlistAppendPointer (ftllist, (XtPointer)*val);
2103 }
2104 /* END OSF Fix CR 6189 */
2105 break;
2106 case MrmRtypeTransTable:
2107 /*
2108 * WARNING: memory leak created...
2109 */
2110 trans = XtParseTranslationTable ((String)(*val)) ;
2111 if ( trans == NULL )
2112 {
2113 sprintf (err_msg, _MrmMMsg_0065, (String)(*val)) ;
2114 return Urm__UT_Error ("Urm__CW_ConvertValue",
2115 err_msg, NULL, NULL, MrmFAILURE) ;
2116 }
2117 *val = (long) trans ;
2118 break ;
2119 }
2120 break;
2121 }
2122 case MrmRtypeChar8Vector:
2123 {
2124 String *tbl;
2125
2126 vecptr = (RGMTextVectorPtr) (*val) ;
2127 /* Have to pack vecptr */
2128 vec_count = vecptr->count;
2129 tbl = (String *)vecptr->item;
2130 for (ndx = 0; ndx < vec_count; ndx++)
2131 tbl[ndx] = (String)(vecptr->item[ndx].pointer);
2132 *val = (long)tbl;
2133 break ;
2134 }
2135 case MrmRtypeCStringVector:
2136 {
2137 XmStringTable tbl;
2138
2139 vecptr = (RGMTextVectorPtr) (*val) ;
2140 /* Have to pack vecptr */
2141 vec_count = vecptr->count;
2142 tbl = (XmStringTable)vecptr->item;
2143 for (ndx = 0; ndx < vec_count; ndx++)
2144 tbl[ndx] = (XmString)(vecptr->item[ndx].pointer);
2145 *val = (long)tbl;
2146 break;
2147 }
2148 case MrmRtypeCString:
2149 cstg = XmCvtByteStreamToXmString((unsigned char *)*val);
2150 *val = (long)cstg;
2151 /* BEGIN OSF Fix CR 8392 */
2152 /* fix memory leak */
2153 if ( ftllist != NULL )
2154 {
2155 UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
2156 UrmPlistAppendPointer (ftllist, (XtPointer)*val);
2157 }
2158 /* END OSF Fix CR 8392 */
2159 break;
2160 case MrmRtypeIntegerVector:
2161 {
2162 RGMIntegerVectorPtr vecptr ; /* val as integer vector */
2163
2164 vecptr = (RGMIntegerVectorPtr) (*val) ;
2165 *val = (long) vecptr->item ;
2166 break ;
2167 }
2168 case MrmRtypeAddrName:
2169 result = Urm__LookupNameInHierarchy (hierarchy_id, (String)(*val), &addr);
2170 if ( result != MrmSUCCESS )
2171 {
2172 sprintf (err_msg, _MrmMMsg_0066, (String)(*val)) ;
2173 return Urm__UT_Error ("Urm__CW_ConvertValue",
2174 err_msg, NULL, NULL, result) ;
2175 }
2176 *val = (long) addr ;
2177 break ;
2178 case MrmRtypeIconImage:
2179 Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint);
2180 result = UrmCreatePixmap((RGMIconImagePtr)(*val), screen, display,
2181 fgint, bgint, &pixmap, parent);
2182 if (result != MrmSUCCESS)
2183 return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112,
2184 NULL, NULL, MrmFAILURE));
2185 *val = (long)pixmap;
2186 break;
2187
2188 case MrmRtypeXBitmapFile:
2189 Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint);
2190 result = Urm__CW_ReadBitmapFile((char *)(*val), screen,
2191 fgint, bgint, &pixmap, parent);
2192 if (result != MrmSUCCESS)
2193 return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112,
2194 NULL, NULL, MrmFAILURE));
2195 *val = (long)pixmap;
2196 break;
2197
2198 case MrmRtypeFont:
2199 case MrmRtypeFontSet:
2200 fontptr = (RGMFontItemPtr) (*val) ;
2201 fontstg = fontptr->font.font;
2202 dpyandfontstr = Urm__CW_DisplayToString ((char*)&display,
2203 fontstg, strlen(fontstg) + 1);
2204 if ( dpyandfontstr == NULL)
2205 {
2206 return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069,
2207 NULL, NULL, MrmFAILURE) ;
2208 }
2209 switch (reptype)
2210 {
2211 case MrmRtypeFont:
2212 result =
2213 Urm__WCI_LookupRegisteredName(dpyandfontstr, (XtPointer *)&font);
2214
2215 if ( result != MrmSUCCESS )
2216 {
2217 font = XLoadQueryFont (display, fontstg);
2218 if ( font == NULL )
2219 {
2220 sprintf (err_msg, _MrmMMsg_0070, fontstg);
2221 return Urm__UT_Error ("Urm__CW_ConvertValue",
2222 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2223 }
2224 Urm__WCI_RegisterNames (&dpyandfontstr, (XtPointer *)&font, 1);
2225 {
2226 XmDisplay dd = (XmDisplay) XmGetXmDisplay(display);
2227 if (dd)
2228 XtAddCallback((Widget)dd,XtNdestroyCallback,
2229 DisplayDestroyCallback, (XtPointer)
2230 XtNewString(dpyandfontstr));
2231 }
2232 }
2233 break;
2234
2235 case MrmRtypeFontSet:
2236 result = Urm__WCI_LookupRegisteredName(dpyandfontstr,
2237 (XtPointer *)&fontset);
2238
2239 if ( result != MrmSUCCESS )
2240 {
2241 fontset = XCreateFontSet(display, fontstg, &missing_csets,
2242 &missing_cset_cnt, &def_string);
2243 if (fontset == NULL)
2244 {
2245 sprintf(err_msg, _MrmMMsg_0071, fontstg);
2246 return Urm__UT_Error ("Urm__CW_ConvertValue",
2247 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2248 }
2249 Urm__WCI_RegisterNames(&dpyandfontstr,
2250 (XtPointer *)&fontset, 1);
2251 }
2252 break;
2253 }
2254 XtFree (dpyandfontstr);
2255 if ( cvttype == MrmRtypeFontList )
2256 {
2257 switch(reptype)
2258 {
2259 case MrmRtypeFont:
2260 dfontlist = XmFontListCreate (font, fontptr->cset.charset) ;
2261 break;
2262
2263 case MrmRtypeFontSet:
2264 fontset_entry = XmFontListEntryCreate(fontptr->cset.charset,
2265 XmFONT_IS_FONTSET,
2266 fontset);
2267 dfontlist = XmFontListAppendEntry(NULL, fontset_entry);
2268 break;
2269 }
2270
2271 if ( ftllist != NULL )
2272 {
2273 UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
2274 UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist);
2275 }
2276 *val = (long) dfontlist ;
2277 }
2278 else
2279 *val = (long) font ;
2280 break ;
2281 case MrmRtypeFontList:
2282 fontlist = (RGMFontListPtr) (*val) ;
2283 dfontlist = NULL ;
2284 for ( ndx=0 ; ndx<fontlist->count ; ndx++ )
2285 {
2286 fontstg = fontlist->item[ndx].font.font;
2287 dpyandfontstr = Urm__CW_DisplayToString((char*)&display,
2288 fontstg,
2289 strlen(fontstg) + 1);
2290 if ( dpyandfontstr == NULL)
2291 {
2292 return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069,
2293 NULL, NULL, MrmFAILURE) ;
2294 }
2295
2296 switch (fontlist->item[ndx].type)
2297 {
2298 case MrmRtypeFont:
2299 result = Urm__WCI_LookupRegisteredName(dpyandfontstr,
2300 (XtPointer *)&font);
2301 if ( result != MrmSUCCESS )
2302 {
2303 font = XLoadQueryFont (display, fontstg);
2304 if ( font == NULL )
2305 {
2306 sprintf (err_msg, _MrmMMsg_0070, fontstg);
2307 return Urm__UT_Error ("Urm__CW_ConvertValue",
2308 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2309 }
2310 Urm__WCI_RegisterNames(&dpyandfontstr, (XtPointer *)&font, 1);
2311 {
2312 XmDisplay dd = (XmDisplay) XmGetXmDisplay(display);
2313 if (dd)
2314 XtAddCallback((Widget)dd,XtNdestroyCallback,
2315 DisplayDestroyCallback, (XtPointer)
2316 XtNewString(dpyandfontstr));
2317 }
2318 }
2319 break;
2320
2321 case MrmRtypeFontSet:
2322 result = Urm__WCI_LookupRegisteredName(dpyandfontstr,
2323 (XtPointer *)&fontset);
2324 if ( result != MrmSUCCESS )
2325 {
2326 fontset = XCreateFontSet(display, fontstg, &missing_csets,
2327 &missing_cset_cnt, &def_string);
2328 if (fontset == NULL)
2329 {
2330 sprintf(err_msg, _MrmMMsg_0071, fontstg);
2331 return Urm__UT_Error ("Urm__CW_ConvertValue",
2332 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2333 }
2334
2335 if (missing_csets != NULL)
2336 {
2337 sprintf(err_msg, _MrmMMsg_0072, fontstg);
2338 XFreeStringList(missing_csets);
2339 }
2340 Urm__WCI_RegisterNames(&dpyandfontstr,
2341 (XtPointer *)&fontset, 1);
2342 }
2343 break;
2344 }
2345
2346 XtFree (dpyandfontstr);
2347 switch(fontlist->item[ndx].type)
2348 {
2349 case MrmRtypeFont:
2350 if ( dfontlist == NULL )
2351 dfontlist = XmFontListCreate
2352 (font, fontlist->item[ndx].cset.charset) ;
2353 else
2354 dfontlist = XmFontListAdd
2355 (dfontlist, font, fontlist->item[ndx].cset.charset) ;
2356 if ( dfontlist == NULL )
2357 {
2358 sprintf (err_msg, _MrmMMsg_0073,
2359 fontlist->item[ndx].font.font) ;
2360 return Urm__UT_Error ("Urm__CW_ConvertValue",
2361 err_msg, NULL, NULL, MrmFAILURE) ;
2362 }
2363 break;
2364 case MrmRtypeFontSet:
2365 fontset_entry =
2366 XmFontListEntryCreate(fontlist->item[ndx].cset.charset,
2367 XmFONT_IS_FONTSET,
2368 fontset);
2369 dfontlist = XmFontListAppendEntry(NULL, fontset_entry);
2370 if ( dfontlist == NULL )
2371 {
2372 sprintf (err_msg, _MrmMMsg_0074,
2373 fontlist->item[ndx].font.font) ;
2374 return Urm__UT_Error ("Urm__CW_ConvertValue",
2375 err_msg, NULL, NULL, MrmFAILURE) ;
2376 }
2377 break;
2378 }
2379 }
2380
2381 *val = (long) dfontlist ;
2382 /*
2383 * Save only the final fontlist to be freed later. All intermediate
2384 * ones are freed by XmFontListAdd
2385 */
2386 if ( ftllist != NULL )
2387 {
2388 UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
2389 UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist);
2390 }
2391 break ;
2392 case MrmRtypeColor:
2393 colorptr = (RGMColorDescPtr) (*val) ;
2394 switch (colorptr->desc_type)
2395 {
2396 case URMColorDescTypeName:
2397 result = Urm__UT_GetNamedColorPixel
2398 (display, (Colormap)0, colorptr, &pix,
2399 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ;
2400 if ( result != MrmSUCCESS )
2401 {
2402 if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS;
2403 sprintf (err_msg, _MrmMMsg_0061, (String)(colorptr->desc.name)) ;
2404 return Urm__UT_Error ("Urm__CW_ConvertValue",
2405 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2406 }
2407 break;
2408 case URMColorDescTypeRGB:
2409 result = Urm__UT_GetColorPixel
2410 (display, (Colormap)0, colorptr, &pix,
2411 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ;
2412 if ( result != MrmSUCCESS )
2413 {
2414 if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS;
2415 sprintf (err_msg, _MrmMMsg_0039,
2416 colorptr->desc.rgb.red,
2417 colorptr->desc.rgb.green,
2418 colorptr->desc.rgb.blue) ;
2419 return Urm__UT_Error ("Urm__CW_ConvertValue",
2420 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2421 }
2422 break;
2423 default:
2424 sprintf(err_msg, _MrmMMsg_0040);
2425 return Urm__UT_Error ("Urm__CW_ConvertValue",
2426 err_msg, NULL, NULL, MrmFAILURE) ;
2427 };
2428 *val = (long) pix ;
2429 break ;
2430 /* BEGIN OSF Fix CR 4859 */
2431 case MrmRtypeWideCharacter:
2432 {
2433 RGMWCharEntryPtr wcharentry;
2434
2435 wcharentry = (RGMWCharEntryPtr)*val;
2436 *val = (long)wcharentry->pointer;
2437 break;
2438 }
2439 /* END OSF Fix CR 4859 */
2440 case MrmRtypeTransTable:
2441 /*
2442 * WARNING: memory leak created...
2443 */
2444 trans = XtParseTranslationTable ((String)(*val)) ;
2445 if ( trans == NULL )
2446 {
2447 sprintf (err_msg, _MrmMMsg_0065, (String)(*val)) ;
2448 return Urm__UT_Error ("Urm__CW_ConvertValue",
2449 err_msg, NULL, NULL, MrmFAILURE) ;
2450 }
2451 *val = (long) trans ;
2452 break ;
2453 case MrmRtypeClassRecName:
2454 clrec = Urm__WCI_GetClRecOfName ((String)*val) ;
2455 if ( clrec == NULL )
2456 {
2457 sprintf (err_msg, _MrmMMsg_0075, (String)(*val)) ;
2458 return Urm__UT_Error ("Urm__CW_ConvertValue",
2459 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2460 }
2461 *val = (long) clrec ;
2462 break ;
2463 case MrmRtypeKeysym:
2464 xkey = XStringToKeysym ((String)*val);
2465 if ( xkey == NoSymbol )
2466 {
2467 sprintf (err_msg, _MrmMMsg_0076, (String)(*val)) ;
2468 return Urm__UT_Error ("Urm__CW_ConvertValue",
2469 err_msg, NULL, NULL, MrmNOT_FOUND) ;
2470 }
2471 *val = (long) xkey;
2472 break;
2473 case MrmRtypeHorizontalInteger:
2474 orientation = XmHORIZONTAL;
2475 /* fall through */
2476 case MrmRtypeVerticalInteger:
2477 if (orientation == XmNO_ORIENTATION)
2478 {
2479 orientation = XmVERTICAL;
2480 }
2481 /* get a screen that we can use */
2482 screen = DefaultScreenOfDisplay(display);
2483 unitsintvalue = (RGMUnitsIntegerPtr) *val;
2484 if (unitsintvalue->value != 0)
2485 {
2486 *val = _XmConvertUnits(screen, orientation, unitsintvalue->units,
2487 unitsintvalue->value, XmPIXELS);
2488 if (*val == 0)
2489 {
2490 return Urm__UT_Error ("Urm__CW_ConvertValue",
2491 _MrmMMsg_0115, NULL, NULL, MrmNOT_FOUND) ;
2492 }
2493 }
2494 else *val = 0;
2495 break;
2496 case MrmRtypeHorizontalFloat:
2497 orientation = XmHORIZONTAL;
2498 /* fall through */
2499 case MrmRtypeVerticalFloat:
2500 {
2501 float float_val, int_value;
2502 int int_units, float_units;
2503
2504 if (orientation == XmNO_ORIENTATION)
2505 {
2506 orientation = XmVERTICAL;
2507 }
2508 /* get a screen that we can use */
2509 screen = DefaultScreenOfDisplay(display);
2510 unitsfloatvalue = (RGMUnitsFloatPtr) *val;
2511 float_units = unitsfloatvalue->units;
2512 float_val = (float)(*((double *)(&unitsfloatvalue->value[0])));
2513
2514 if (float_val != 0)
2515 {
2516 if (_XmConvertFloatUnitsToIntUnits(float_units, float_val,
2517 &int_units, &int_value,
2518 XmPIXELS) == False)
2519 {
2520 return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0116,
2521 NULL, NULL, MrmFAILURE);
2522 }
2523 *val = _XmConvertUnits(screen, orientation, int_units,
2524 MAKEINT(int_value), XmPIXELS);
2525 if (*val == 0)
2526 {
2527 return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0115,
2528 NULL, NULL, MrmFAILURE);
2529 }
2530 }
2531 else *val = 0;
2532 }
2533 break;
2534 default:
2535 break ;
2536 }
2537
2538 return MrmSUCCESS ;
2539
2540 }
2541
2542 /*
2543 ** Remove the font from the hash table so it won't later cause a protocol
2544 ** error if the display is closed and reopened and the same value is fetched.
2545 */
2546 /*ARGSUSED*/
2547 static void
DisplayDestroyCallback(Widget w,XtPointer client_data,XtPointer call_data)2548 DisplayDestroyCallback ( Widget w,
2549 XtPointer client_data,
2550 XtPointer call_data ) /* unused */
2551 {
2552 String dpyandfontstr = (String) client_data;
2553 XFontStruct *font ;
2554
2555 if (MrmSUCCESS == Urm__WCI_LookupRegisteredName(dpyandfontstr,
2556 (XtPointer *)&font))
2557 XFreeFont(XtDisplay(w), font);
2558 Urm__WCI_UnregisterName (dpyandfontstr);
2559 XtFree(dpyandfontstr);
2560 }
2561
2562
2563
2564 /*
2565 *++
2566 *
2567 * PROCEDURE DESCRIPTION:
2568 *
2569 * This routine copies a value to an 'eternal' block in order
2570 * to guarantee that callback tag values will live forever.
2571 *
2572 * FORMAL PARAMETERS:
2573 *
2574 * val the value to be copied (may be a pointer)
2575 * reptype value representation type
2576 * vec_count number of elements in the vector (for vector types)
2577 *
2578 * IMPLICIT INPUTS:
2579 *
2580 * IMPLICIT OUTPUTS:
2581 *
2582 * FUNCTION VALUE:
2583 *
2584 * SIDE EFFECTS:
2585 *
2586 *--
2587 */
2588
2589 static char* staticNull = NULL;
2590
2591 void
Urm__CW_SafeCopyValue(long * val,MrmType reptype,URMPointerListPtr cblist,int vec_count,int vec_size)2592 Urm__CW_SafeCopyValue (long *val,
2593 MrmType reptype,
2594 URMPointerListPtr cblist,
2595 int vec_count,
2596 int vec_size)
2597 {
2598 /*
2599 * Local variables
2600 */
2601 int *int_src ; /* to copy integer values */
2602 int *int_dst ;
2603 String char8_src ; /* to copy string values */
2604 String char8_dst ;
2605 float *single_float_src ; /* to copy FP values */
2606 float *single_float_dst ;
2607 double *float_src ; /* to copy FP values */
2608 double *float_dst ;
2609 XmString cstr_src ; /* to copy compound strings */
2610 XmString *cstr_table_src; /* to copy compound string table */
2611 XmString *cstr_table_dst ;
2612 String *char8_table_src ; /* to coy string table */
2613 String *char8_table_dst ;
2614 wchar_t *wchar_src; /* to copy wide character strings */
2615 wchar_t *wchar_dst;
2616 size_t size;
2617 int cnt ;
2618
2619 /*
2620 * Make copies of all primitive data structures. Note this has the side
2621 * effect of converting integer values to by-reference.
2622 */
2623 switch ( reptype )
2624 {
2625 case MrmRtypeIntegerVector:
2626 int_src = (int *) *val ;
2627 int_dst = (int *) XtMalloc ((unsigned int)vec_size) ;
2628 UrmBCopy (int_src, int_dst, vec_size) ;
2629 *val = (long) int_dst ;
2630 if (cblist != NULL)
2631 {
2632 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2633 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2634 }
2635 break ;
2636
2637 case MrmRtypeCStringVector:
2638 cstr_table_src = (XmString *)*val;
2639 cstr_table_dst =
2640 (XmString *)XtMalloc(vec_count * sizeof(XmString)) ;
2641 for (cnt=0; cnt<vec_count; cnt++)
2642 cstr_table_dst[cnt] =
2643 XmStringCopy(cstr_table_src[cnt]);
2644 *val = (long) cstr_table_dst ;
2645 if (cblist != NULL)
2646 {
2647 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2648 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2649 }
2650 break ;
2651
2652 case MrmRtypeChar8Vector:
2653 char8_table_src = (String *)*val ;
2654 char8_table_dst = (String *) XtMalloc (vec_size) ;
2655
2656 /* Copy the pointers and strings. */
2657 UrmBCopy (char8_table_src, char8_table_dst, vec_size) ;
2658
2659 /* Now adjust the pointers at the beginning of the destination
2660 string table to point to the strings in the destination
2661 instead of the source. */
2662 for (cnt=0; cnt<vec_count; cnt++)
2663 {
2664 char8_table_dst[cnt]
2665 = (String) ((char *) char8_table_dst +
2666 ((unsigned long) char8_table_src[cnt] -
2667 (unsigned long) char8_table_src)) ;
2668 }
2669 *val = (long) char8_table_dst ;
2670 if (cblist != NULL)
2671 {
2672 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2673 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2674 }
2675 break ;
2676
2677 case MrmRtypeInteger:
2678 case MrmRtypeBoolean:
2679 int_dst = (int *) XtMalloc (sizeof(int)) ;
2680 *int_dst = *val ;
2681 *val = (long) int_dst ;
2682 if (cblist != NULL)
2683 {
2684 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2685 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2686 }
2687 break ;
2688
2689 case MrmRtypeChar8:
2690 char8_src = (String) *val ;
2691 char8_dst = (String) XtMalloc (strlen(char8_src)+1) ;
2692 strcpy (char8_dst, char8_src) ;
2693 *val = (long) char8_dst ;
2694 if (cblist != NULL)
2695 {
2696 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2697 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2698 }
2699 break ;
2700
2701 case MrmRtypeSingleFloat:
2702 single_float_src = (float *) *val ;
2703 single_float_dst = (float *) XtMalloc (sizeof(float)) ;
2704 *single_float_dst = *single_float_src ;
2705 *val = (long) single_float_dst ;
2706 if (cblist != NULL)
2707 {
2708 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2709 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2710 }
2711 break ;
2712
2713 case MrmRtypeFloat:
2714 float_src = (double *) *val ;
2715 float_dst = (double *) XtMalloc (sizeof(double)) ;
2716 *float_dst = *float_src ;
2717 *val = (long) float_dst ;
2718 if (cblist != NULL)
2719 {
2720 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2721 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2722 }
2723 break ;
2724
2725 case MrmRtypeNull:
2726 *val = (long) &staticNull ;
2727 /*
2728 * Don't add anything to a callback list for the null type
2729 */
2730 break ;
2731
2732 case MrmRtypeCString:
2733 cstr_src = XmStringCopy ((XmString)(*val)) ;
2734 *val = (long) cstr_src ;
2735 if (cblist != NULL)
2736 {
2737 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2738 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2739 }
2740 break ;
2741
2742 case MrmRtypeWideCharacter:
2743 wchar_src = (wchar_t *) *val ;
2744
2745 for (cnt = 0; ; cnt++) if (wchar_src[cnt] == 0) break;
2746 size = (cnt+1) * sizeof(wchar_t);
2747
2748 wchar_dst = (wchar_t *) XtMalloc (size) ;
2749 memcpy(wchar_dst, wchar_src, size) ;
2750 *val = (long) wchar_dst ;
2751 if (cblist != NULL)
2752 {
2753 UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
2754 UrmPlistAppendPointer (cblist, (XtPointer)*val);
2755 }
2756 break ;
2757
2758 default:
2759 break ;
2760 }
2761
2762 }
2763
2764
2765
2766 /*
2767 *++
2768 *
2769 * PROCEDURE DESCRIPTION:
2770 *
2771 * This routine destorys all the tags which where created for a given
2772 * widgets callbacks. All the tags are stored in a pointer list. The first
2773 * item on the list is the MRMtype followed by a pointer to the actual
2774 * data. Use XmStringFree for comound string types,
2775 * XmFontListFree for font-lists, and XtFree for all other
2776 * types.
2777 *
2778 * FORMAL PARAMETERS:
2779 *
2780 * w The widget we are freeing the memory for
2781 * list_id The pointer to the list of tags
2782 * reason Standard callback reason (not used)
2783 *
2784 * IMPLICIT INPUTS:
2785 *
2786 * {@tbs@}
2787 *
2788 * IMPLICIT OUTPUTS:
2789 *
2790 * {@tbs@}
2791 *
2792 * FUNCTION VALUE:
2793 *
2794 * {@tbs@}
2795 *
2796 * SIDE EFFECTS:
2797 *
2798 * none known
2799 *
2800 *--
2801 */
2802
2803 /*ARGSUSED*/
2804 void
UrmDestroyCallback(Widget w,URMPointerListPtr list_id,XmAnyCallbackStruct * reason)2805 UrmDestroyCallback (Widget w, /* unused */
2806 URMPointerListPtr list_id,
2807 XmAnyCallbackStruct * reason) /* unused */
2808 {
2809 /*
2810 * Local variables
2811 */
2812 MrmType reptype ;
2813 /* BEGIN OSF Fix CR 6843 */
2814 int ndx, i ;
2815 /* END OSF Fix CR 6843 */
2816
2817 for (ndx=0 ; ndx<list_id->num_ptrs ; ndx++)
2818 {
2819 reptype = (MrmType)(long)list_id->ptr_vec[ndx];
2820 ndx++;
2821 switch ( reptype )
2822 {
2823 case MrmRtypeCString:
2824 XmStringFree ((XmString)list_id->ptr_vec[ndx]);
2825 break ;
2826 /* BEGIN OSF Fix CR 6224 */
2827 case MrmRtypeFont:
2828 /* Do not free the fontstruct. */
2829 break;
2830 /* END OSF Fix CR 6224 */
2831 case MrmRtypeFontList:
2832 XmFontListFree ((XmFontList)list_id->ptr_vec[ndx]);
2833 break;
2834 default:
2835 /* BEGIN OSF Fix CR 6843 */
2836 /* Check for duplicates on list before freeing. */
2837 if (list_id->ptr_vec[ndx] != NULL)
2838 {
2839 for (i = ndx + 1; i < list_id->num_ptrs; ++i)
2840 if (list_id->ptr_vec[ndx] == list_id->ptr_vec[i])
2841 list_id->ptr_vec[i] = NULL;
2842
2843 XtFree (list_id->ptr_vec[ndx]);
2844 }
2845 /* END OSF Fix CR 6843 */
2846 break ;
2847 }
2848 }
2849
2850 UrmPlistFree (list_id);
2851
2852 }
2853
2854
2855 /*
2856 *++
2857 *
2858 * PROCEDURE DESCRIPTION:
2859 *
2860 * This routine reads a literal resource from either a hierarchy or
2861 * a file. It returns the resource type and either a pointer to the
2862 * value or its immediate value.
2863 *
2864 * FORMAL PARAMETERS:
2865 *
2866 * resptr resource reference to literal
2867 * hierarchy_id hierarchy from which to read public resource
2868 * file_id file from which to read private resource
2869 * ctxlist list in which to save resource contexts
2870 * type to return representation type
2871 * val to return immediate value or pointer
2872 * vec_count to return number of items if type is a vector
2873 * act_file_id to return id of file from which literal was read
2874 *
2875 * IMPLICIT INPUTS:
2876 *
2877 * IMPLICIT OUTPUTS:
2878 *
2879 * FUNCTION VALUE:
2880 *
2881 * SIDE EFFECTS:
2882 *
2883 * MrmSUCCESS operation succeeded
2884 * other some failure, usually reading the literal
2885 *
2886 *--
2887 */
2888
2889 Cardinal
Urm__CW_ReadLiteral(RGMResourceDescPtr resptr,MrmHierarchy hierarchy_id,IDBFile file_id,URMPointerListPtr ctxlist,MrmType * type,long * val,int * vec_count,IDBFile * act_file_id,int * vec_size)2890 Urm__CW_ReadLiteral (RGMResourceDescPtr resptr ,
2891 MrmHierarchy hierarchy_id ,
2892 IDBFile file_id ,
2893 URMPointerListPtr ctxlist ,
2894 MrmType *type ,
2895 long *val ,
2896 int *vec_count ,
2897 IDBFile *act_file_id ,
2898 int *vec_size )
2899 {
2900 /*
2901 * Local variables
2902 */
2903 Cardinal result ; /* function results */
2904 URMResourceContextPtr context_id ; /* context for reading literal */
2905 char err_msg[300] ;
2906 long *bufptr ; /* context buffer */
2907
2908 /*
2909 * Acquire a context and read the literal into it.
2910 */
2911 UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ;
2912 switch ( resptr->type )
2913 {
2914 case URMrIndex:
2915 if ( resptr->access == URMaPublic )
2916 result = Urm__HGetIndexedLiteral
2917 (hierarchy_id, resptr->key.index, context_id, act_file_id) ;
2918 else
2919 result = UrmGetIndexedLiteral
2920 (file_id, resptr->key.index, context_id) ;
2921 if ( result != MrmSUCCESS )
2922 {
2923 UrmFreeResourceContext (context_id) ;
2924 sprintf (err_msg, _MrmMMsg_0077, resptr->key.index) ;
2925 return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
2926 NULL, NULL, result) ;
2927 }
2928 break ;
2929 case URMrRID:
2930 result = UrmGetRIDLiteral (file_id, resptr->key.id, context_id) ;
2931 *act_file_id = file_id ;
2932 if ( result != MrmSUCCESS )
2933 {
2934 UrmFreeResourceContext (context_id) ;
2935 sprintf (err_msg, _MrmMMsg_0078, resptr->key.id) ;
2936 return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
2937 NULL, NULL, result) ;
2938 }
2939 break ;
2940 default:
2941 result = MrmFAILURE ;
2942 UrmFreeResourceContext (context_id) ;
2943 sprintf ( err_msg, _MrmMMsg_0079, resptr->type) ;
2944 return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
2945 NULL, NULL, result) ;
2946 }
2947
2948 /*
2949 * return the rep type, size, and value. Save the resource context.
2950 */
2951 *type = UrmRCType (context_id) ;
2952 *vec_size = UrmRCSize(context_id);
2953 *vec_count = 0;
2954 bufptr = (long *) UrmRCBuffer (context_id) ;
2955 *val = Urm__CW_EvaluateValOrOffset (*type, (XtPointer)bufptr, *bufptr, 0) ;
2956 UrmPlistAppendPointer (ctxlist, (XtPointer)context_id) ;
2957
2958 /*
2959 * Handle literals which may have further embedded literal references. Note
2960 * that the file for private references is the local file, possibly changed
2961 * by the HGetIndexedLiteral
2962 */
2963 switch ( *type )
2964 {
2965 case MrmRtypeIntegerVector:
2966 *vec_count = ((RGMIntegerVectorPtr)*val)->count ;
2967 break;
2968 case MrmRtypeChar8Vector:
2969 case MrmRtypeCStringVector:
2970 *vec_count = ((RGMTextVectorPtr)*val)->count ;
2971 break;
2972 case MrmRtypeIconImage:
2973 result = Urm__CW_LoadIconImage ((RGMIconImagePtr)*val,
2974 (XtPointer)*val, hierarchy_id,
2975 *act_file_id, ctxlist) ;
2976 if ( result != MrmSUCCESS ) return result ;
2977 break ;
2978 }
2979
2980 return MrmSUCCESS ;
2981
2982 }
2983
2984
2985
2986 /*
2987 *++
2988 *
2989 * PROCEDURE DESCRIPTION:
2990 *
2991 * This routine completes the loading and fixup of a URM
2992 * icon image. Iconimages may have several other literal
2993 * resource references embedded within their definition.
2994 * These are all read and turned into memory references.
2995 *
2996 * FORMAL PARAMETERS:
2997 *
2998 * iconptr The (unfixedup) icon image now in memory
2999 * bufptr buffer for offsets
3000 * hierarchy_id hierarchy from which to read public resource
3001 * file_id file from which to read private resource
3002 * ctxlist list in which to save resource contexts
3003 *
3004 * IMPLICIT INPUTS:
3005 *
3006 * IMPLICIT OUTPUTS:
3007 *
3008 * FUNCTION VALUE:
3009 *
3010 * MrmSUCCESS operation succeeded
3011 * other failures from ReadLiteral
3012 *
3013 * SIDE EFFECTS:
3014 *
3015 *--
3016 */
3017
3018 Cardinal
Urm__CW_LoadIconImage(RGMIconImagePtr iconptr,XtPointer bufptr,MrmHierarchy hierarchy_id,IDBFile file_id,URMPointerListPtr ctxlist)3019 Urm__CW_LoadIconImage (RGMIconImagePtr iconptr ,
3020 XtPointer bufptr ,
3021 MrmHierarchy hierarchy_id ,
3022 IDBFile file_id ,
3023 URMPointerListPtr ctxlist )
3024 {
3025 /*
3026 * Local variables
3027 */
3028 Cardinal result ; /* function results */
3029 RGMResourceDescPtr resptr ; /* to read resource literals */
3030 RGMColorTablePtr ctable ; /* color table in icon image */
3031 Cardinal ndx ; /* loop index */
3032 RGMColorTableEntryPtr citem ; /* color table entry */
3033 MrmType cttype = MrmRtypeColorTable ; /* expected type */
3034 XtPointer ctbufptr ; /* buffer base addr for table */
3035 MrmType ctype ; /* color entry type */
3036 IDBFile act_file ; /* file from which literals read */
3037 char err_msg[300] ;
3038 int vec_size ;
3039 Boolean swap_needed = FALSE ;
3040
3041 /*
3042 * Fixup pointers as required. Read the color table if it is a resource.
3043 * Note that bufptr is reset to a color table resource read in in order
3044 * provide the correct relocation for color items.
3045 */
3046 if (iconptr->validation != URMIconImageValid)
3047 { if ( Urm__SwapValidation(iconptr->validation) == URMIconImageValid )
3048 { swapbytes( iconptr->validation );
3049 swapbytes( iconptr->width );
3050 swapbytes( iconptr->height );
3051 swapbytes( iconptr->hot_x );
3052 swapbytes( iconptr->hot_y );
3053 swapbytes( iconptr->ct_type );
3054 swapbytes( iconptr->annex1 );
3055 swapbytes( iconptr->color_table.ctoff );
3056 swapbytes( iconptr->pixel_data.pdoff );
3057 swap_needed = TRUE;
3058 }
3059 else
3060 { /* CR9259 */
3061 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3062 _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ;
3063 }
3064 }
3065 iconptr->pixel_data.pdptr = (char *) bufptr+iconptr->pixel_data.pdoff ;
3066 switch ( iconptr->ct_type )
3067 {
3068 case MrmRtypeColorTable:
3069 iconptr->color_table.ctptr = (RGMColorTablePtr)
3070 ((char *)bufptr+iconptr->color_table.ctoff) ;
3071 ctbufptr = bufptr ;
3072 break ;
3073 case MrmRtypeResource: {
3074 int vec_count;
3075 resptr = (RGMResourceDescPtr)
3076 ((char *)bufptr+iconptr->color_table.ctoff) ;
3077 if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr);
3078 result = Urm__CW_ReadLiteral
3079 (resptr, hierarchy_id, file_id, ctxlist,
3080 &cttype, (long *)(&iconptr->color_table.ctptr),
3081 &vec_count, &act_file, &vec_size) ;
3082 if ( result != MrmSUCCESS ) return result ;
3083 if ( cttype != MrmRtypeColorTable )
3084 {
3085 sprintf (err_msg, _MrmMMsg_0080, cttype) ;
3086 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3087 err_msg, NULL, NULL, MrmNOT_VALID) ;
3088 }
3089 ctbufptr = (XtPointer) iconptr->color_table.ctptr ;
3090 break ;
3091 }
3092 default:
3093 sprintf (err_msg, _MrmMMsg_0081, iconptr->ct_type) ;
3094 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3095 err_msg, NULL, NULL, MrmNOT_VALID) ;
3096 }
3097
3098 /*
3099 * Load any resource colors in the color table.
3100 */
3101 ctable = iconptr->color_table.ctptr ;
3102 if (ctable->validation != URMColorTableValid)
3103 { if ( Urm__SwapValidation(ctable->validation) == URMColorTableValid )
3104 { swapbytes( ctable->validation );
3105 swapbytes( ctable->count );
3106 swap_needed = TRUE;
3107 }
3108 else
3109 {
3110 /* CR9259 */
3111 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3112 _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ;
3113 }
3114 }
3115
3116 for ( ndx=URMColorTableUserMin ; ndx<ctable->count ; ndx++ )
3117 {
3118 citem = &ctable->item[ndx] ;
3119 if ( swap_needed )
3120 {
3121 swapbytes( citem->type );
3122 swapbytes( citem->annex1 );
3123 swapbytes( citem->color_item.coffs );
3124 }
3125 switch ( citem->type )
3126 {
3127 case MrmRtypeColor:
3128 citem->color_item.cptr = (RGMColorDescPtr)
3129 ((char *)ctbufptr+citem->color_item.coffs) ;
3130 break ;
3131 case MrmRtypeResource: {
3132 int vec_count;
3133 resptr = (RGMResourceDescPtr)
3134 ((char *)ctbufptr+citem->color_item.coffs) ;
3135 if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr);
3136 ctype = MrmRtypeColor ;
3137 result = Urm__CW_ReadLiteral
3138 (resptr, hierarchy_id, file_id,
3139 ctxlist, &ctype, (long *)(&citem->color_item.cptr),
3140 &vec_count, &act_file, &vec_size) ;
3141 if ( result != MrmSUCCESS ) return result ;
3142 if ( ctype != MrmRtypeColor )
3143 {
3144 sprintf (err_msg, _MrmMMsg_0082, ctype) ;
3145 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3146 err_msg, NULL, NULL, MrmNOT_VALID) ;
3147 }
3148 break ;
3149 }
3150 default:
3151 sprintf ( err_msg, _MrmMMsg_0083, citem->type) ;
3152 return Urm__UT_Error ("Urm__CW_LoadIconImage",
3153 err_msg, NULL, NULL, MrmNOT_VALID) ;
3154 }
3155 }
3156 return MrmSUCCESS ;
3157
3158 }
3159
3160
3161
3162 /*
3163 *++
3164 *
3165 * PROCEDURE DESCRIPTION:
3166 *
3167 * This routine fixes up a callback list in a record to function
3168 * as the callback list passed to create. It must turn routine
3169 * names into addresses, and evaluate tag values.
3170 *
3171 * FORMAL PARAMETERS:
3172 *
3173 * parent this widget's parent
3174 * bufptr buffer (base address) for resolving offsets
3175 * cbdesc Callback descriptor in record. Its pointers
3176 * must be fixed up and its tag values evaluated.
3177 * ctxlist A pointer list to save contexts created to
3178 * evaluate literals.
3179 * hierarchy_id URM hierarchy from which to read public resources
3180 * file_id URM file from which to read private resources
3181 * wref_id reference structure from which references to
3182 * previously created widgets in the tree can be
3183 * resolved.
3184 *
3185 * IMPLICIT INPUTS:
3186 *
3187 * IMPLICIT OUTPUTS:
3188 *
3189 * FUNCTION VALUE:
3190 *
3191 * MrmSUCCESS operation succeeded
3192 * MrmUNRESOLVED_REFS unresolved references to widgets remain
3193 * other conversion or resource evaluation failure
3194 *
3195 * SIDE EFFECTS:
3196 *
3197 *--
3198 */
3199
3200 Cardinal
Urm__CW_FixupCallback(Widget parent,XtPointer bufptr,RGMCallbackDescPtr cbdesc,URMPointerListPtr ctxlist,URMPointerListPtr cblist,MrmHierarchy hierarchy_id,IDBFile file_id,URMResourceContextPtr wref_id)3201 Urm__CW_FixupCallback (Widget parent ,
3202 XtPointer bufptr ,
3203 RGMCallbackDescPtr cbdesc ,
3204 URMPointerListPtr ctxlist ,
3205 URMPointerListPtr cblist ,
3206 MrmHierarchy hierarchy_id ,
3207 IDBFile file_id ,
3208 URMResourceContextPtr wref_id)
3209 {
3210 /*
3211 * Local variables
3212 */
3213 Cardinal result ; /* function results */
3214 int ndx ; /* loop index */
3215 RGMCallbackItemPtr itmptr ; /* current list item */
3216 String rtn_name ; /* routine name in item */
3217 MrmType reptype ; /* arg value representation type */
3218 RGMResourceDescPtr resptr ; /* resource descriptor in tag */
3219 IDBFile act_file ; /* file from which literals read */
3220 XtPointer rtn_addr ; /* routine address */
3221 long tag_val ; /* to save value */
3222 int vec_count ; /* number of items in the vector */
3223 char err_msg[300] ;
3224 MrmCount unres_ref_count = 0; /* num unres. widgets in cblist */
3225 String ref_name; /* referenced widget name */
3226 Widget ref_id ; /* referenced widget id */
3227 int vec_size ;
3228 RGMFontListPtr fontlist; /* for converting old style fontlist */
3229 Boolean swap_needed = FALSE;
3230
3231 /*
3232 * Loop through all the items in the callback list
3233 */
3234 for ( ndx=0 ; ndx<cbdesc->count ; ndx++ )
3235 {
3236 itmptr = &cbdesc->item[ndx] ;
3237
3238 /*
3239 * Set the routine pointer to the actual routine address. This
3240 * routine name must be a registered URM callback.
3241 */
3242 rtn_name = (String) bufptr + itmptr->cb_item.routine ;
3243 result = Urm__LookupNameInHierarchy (hierarchy_id, rtn_name, &rtn_addr) ;
3244 if ( result != MrmSUCCESS )
3245 {
3246 sprintf (err_msg, _MrmMMsg_0084, rtn_name) ;
3247 return Urm__UT_Error ("Urm__CW_FixupCallback",
3248 err_msg, NULL, NULL, result) ;
3249 }
3250
3251 /*
3252 * Evaluate the tag value, and set in the item.
3253 */
3254 reptype = itmptr->cb_item.rep_type ;
3255 tag_val = Urm__CW_EvaluateValOrOffset (reptype, bufptr,
3256 itmptr->cb_item.datum.ival,
3257 itmptr->cb_item.datum.offset) ;
3258 switch ( reptype )
3259 {
3260 case MrmRtypeResource:
3261 resptr = (RGMResourceDescPtr) tag_val ;
3262 switch ( resptr->res_group )
3263 {
3264 case URMgWidget:
3265 /* Do we need to worry about subtree resources here? */
3266 if (resptr->type != URMrIndex)
3267 {
3268 Urm__UT_Error("Urm__CW_FixupCallback", _MrmMMsg_0085,
3269 NULL, NULL, MrmNOT_VALID);
3270 continue;
3271 }
3272 ref_name = (String) resptr->key.index;
3273 /* See if reference can be resolved immediatetly. */
3274 result = Urm__CW_FindWRef(wref_id, ref_name, &ref_id) ;
3275 if ( result == MrmSUCCESS ) tag_val = (long)ref_id;
3276 else { /* Save to resolve later */
3277 itmptr->runtime.resolved = FALSE;
3278 itmptr->runtime.wname = Urm__UT_AllocString(ref_name);
3279 tag_val = 0L;
3280 unres_ref_count++;
3281 }
3282 break;
3283
3284 case URMgLiteral:
3285 result = Urm__CW_ReadLiteral
3286 (resptr, hierarchy_id, file_id, ctxlist,
3287 &reptype, &tag_val, &vec_count, &act_file, &vec_size);
3288 if ( result != MrmSUCCESS ) continue ;
3289
3290 if ((reptype == MrmRtypeFontList) &&
3291 (strcmp(file_id->db_version, URM1_1version) <= 0))
3292 {
3293 int count = ((OldRGMFontListPtr)tag_val)->count;
3294
3295 fontlist = (RGMFontListPtr)
3296 XtMalloc(sizeof(RGMFontList) +
3297 (sizeof(RGMFontItem) * (count - 1)));
3298 result = Urm__CW_FixupValue((long)fontlist, reptype,
3299 (XtPointer)tag_val, file_id,
3300 &swap_needed);
3301 XtFree((char *)tag_val);
3302 tag_val = (long)fontlist;
3303 }
3304 else
3305 result = Urm__CW_FixupValue (tag_val, reptype,
3306 (XtPointer)tag_val, file_id,
3307 &swap_needed) ;
3308
3309 if ( result != MrmSUCCESS ) continue ;
3310 result = Urm__CW_ConvertValue
3311 (parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent),
3312 hierarchy_id, NULL) ;
3313 if ( result != MrmSUCCESS ) continue ;
3314
3315 switch (reptype)
3316 {
3317 case MrmRtypeChar8Vector:
3318 case MrmRtypeCStringVector:
3319 vec_size -= (sizeof ( RGMTextVector ) -
3320 sizeof ( RGMTextEntry ));
3321 break;
3322 default:
3323 break;
3324 }
3325
3326 Urm__CW_SafeCopyValue (&tag_val, reptype, cblist,
3327 vec_count, vec_size) ;
3328 itmptr->runtime.resolved = TRUE;
3329 break ;
3330 default:
3331 return Urm__UT_Error ("Urm__CW_FixupCallback", _MrmMMsg_0063,
3332 NULL, NULL, MrmFAILURE) ;
3333 }
3334 break ;
3335 default:
3336 result = Urm__CW_FixupValue (tag_val, reptype, bufptr, file_id,
3337 &swap_needed) ;
3338 if ( result != MrmSUCCESS ) continue ;
3339 result = Urm__CW_ConvertValue
3340 (parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent),
3341 hierarchy_id, NULL) ;
3342 Urm__CW_SafeCopyValue (&tag_val, reptype, cblist, 0, 0) ;
3343 itmptr->runtime.resolved = TRUE;
3344 break ;
3345 }
3346
3347 itmptr->runtime.callback.callback = (XtCallbackProc)rtn_addr;
3348 itmptr->runtime.callback.closure = (XtPointer) tag_val ;
3349 }
3350
3351 cbdesc->unres_ref_count = unres_ref_count;
3352 if (unres_ref_count == 0)
3353 /*
3354 * callback list successfully fixed up
3355 */
3356 return MrmSUCCESS ;
3357 else return MrmUNRESOLVED_REFS;
3358
3359 }
3360
3361
3362 /*
3363 *++
3364 *
3365 * PROCEDURE DESCRIPTION:
3366 *
3367 * This routine evaluates a resource reference to a widget by loading
3368 * the widget definition and instantiating the widget tree. It returns
3369 * the widget id.
3370 * This routine evaluates a resource reference, resulting in setting
3371 *
3372 * FORMAL PARAMETERS:
3373 *
3374 * parent parent of the widget being created
3375 * widgetrec widget record pointer
3376 * resptr the resource to be evaluated
3377 * ctxlist A pointer list to save contexts created to
3378 * evaluate literals.
3379 * hierarchy_id URM hierarchy from which to read public resources
3380 * file_id URM file from which to read private resources
3381 * wref_id widget reference structure
3382 * svlist SetValues descriptor list
3383 * val to return the value (widget id)
3384 *
3385 * IMPLICIT INPUTS:
3386 *
3387 * IMPLICIT OUTPUTS:
3388 *
3389 * FUNCTION VALUE:
3390 *
3391 * MrmSUCCESS operation succeeded
3392 * other load or instantiate failure
3393 *
3394 * SIDE EFFECTS:
3395 *
3396 *--
3397 */
3398
3399 /*ARGSUSED*/
3400 Cardinal
Urm__CW_LoadWidgetResource(Widget parent,RGMWidgetRecordPtr widgetrec,RGMResourceDescPtr resptr,URMPointerListPtr ctxlist,MrmHierarchy hierarchy_id,IDBFile file_id,URMPointerListPtr * svlist,URMResourceContextPtr wref_id,long * val)3401 Urm__CW_LoadWidgetResource (Widget parent ,
3402 RGMWidgetRecordPtr widgetrec , /* unused */
3403 RGMResourceDescPtr resptr ,
3404 URMPointerListPtr ctxlist , /* unused */
3405 MrmHierarchy hierarchy_id ,
3406 IDBFile file_id ,
3407 URMPointerListPtr *svlist ,
3408 URMResourceContextPtr wref_id ,
3409 long *val )
3410
3411 {
3412 /*
3413 * Local variables
3414 */
3415 Cardinal result ; /* function results */
3416 URMResourceContextPtr context_id ; /* context for widget record */
3417 IDBFile loc_fileid = file_id ; /* file id from HGet */
3418 char err_msg[300] ; /* to format error messages */
3419
3420
3421 /*
3422 * Acquire a context, then load the widget and instantiate the tree.
3423 * An HGet call may replace the file for private references.
3424 */
3425 UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ;
3426 switch ( resptr->type )
3427 {
3428 case URMrIndex:
3429 if ( resptr->access == URMaPublic )
3430 result = UrmHGetWidget
3431 (hierarchy_id, resptr->key.index, context_id, &loc_fileid) ;
3432 else
3433 result = UrmGetIndexedWidget
3434 (file_id, resptr->key.index, context_id) ;
3435 if ( result != MrmSUCCESS )
3436 sprintf (err_msg, _MrmMMsg_0086, resptr->key.index) ;
3437 break ;
3438
3439 case URMrRID:
3440 result = UrmGetRIDWidget (file_id, resptr->key.id, context_id) ;
3441 if ( result != MrmSUCCESS )
3442 sprintf (err_msg, _MrmMMsg_0087, resptr->key.id) ;
3443 break ;
3444
3445 default:
3446 result = MrmFAILURE ;
3447 sprintf ( err_msg, _MrmMMsg_0088, resptr->type) ;
3448 }
3449
3450 if ( result != MrmSUCCESS )
3451 {
3452 UrmFreeResourceContext (context_id) ;
3453 return Urm__UT_Error ("Urm__CW_LoadWidgetResource",
3454 err_msg, NULL, NULL, result) ;
3455 }
3456
3457 /*
3458 * Now create the widget subtree. The pointer result is the widget id of
3459 * the widget we now have (the root of the tree).
3460 */
3461 result = UrmCreateWidgetTree
3462 (context_id, parent, hierarchy_id, loc_fileid, NULL, NULL, 0,
3463 resptr->type, resptr->key.index, resptr->key.id, MrmManageDefault,
3464 (URMPointerListPtr *)svlist, wref_id, (Widget *)val) ;
3465 if ( result != MrmSUCCESS )
3466 Urm__UT_Error ("Urm__CW_LoadWidgetResource", _MrmMMsg_0089,
3467 NULL, NULL, result) ;
3468 UrmFreeResourceContext (context_id) ;
3469 return result ;
3470
3471 }
3472
3473
3474
3475 /*
3476 *++
3477 *
3478 * PROCEDURE DESCRIPTION:
3479 *
3480 * This routine returns parameters needed to create a pixmap from
3481 * an IconImage. It extracts the screen and display from the given
3482 * widget. It then determines the foreground and background colors
3483 * for the widget. The setting of these values is idiosyncratic, due
3484 * to the fact that all widgets have a Background attribute from core,
3485 * but are not guaranteed to have a Foreground attribute.
3486 * - if value is already set, do nothing
3487 * - else choose the value for the widget if available
3488 * - else choose white/black PixelOfScreen
3489 * - make sure we haven't ended up with identical values
3490 * for both foreground and background. If we have, accept
3491 * the background value and set the foreground to something
3492 * else (black or white).
3493 *
3494 * FORMAL PARAMETERS:
3495 *
3496 * w widget to use for default values
3497 * screen to return screen for pixmap
3498 * display to return display for pixmap
3499 * fgint to return foreground value for pixmap. A value of
3500 * -1 on input means this must be set; else ignored
3501 * bgint to return background value for pixmap. -1 is used
3502 * as above to signal value needed
3503 *
3504 * IMPLICIT INPUTS:
3505 *
3506 * IMPLICIT OUTPUTS:
3507 *
3508 * FUNCTION VALUE:
3509 *
3510 * SIDE EFFECTS:
3511 *
3512 *--
3513 */
3514
3515 void
Urm__CW_GetPixmapParms(Widget w,Screen ** screen,Display ** display,Pixel * fgint,Pixel * bgint)3516 Urm__CW_GetPixmapParms (Widget w ,
3517 Screen **screen ,
3518 Display **display ,
3519 Pixel *fgint ,
3520 Pixel *bgint )
3521 {
3522 /*
3523 * Local variables
3524 */
3525 Arg pixarg[2] ; /* to read FG/BG values */
3526 Cardinal pcnt = 0 ; /* # entries in arglist */
3527
3528 /*
3529 * Screen and display come straight from widget
3530 */
3531 *screen = XtScreen (w) ;
3532 *display = XtDisplay (w) ;
3533
3534 /*
3535 * Else load the foreground and background pixel values from the
3536 * widget. Fallback to Black/WhitePixelOfScreen if the widget
3537 * doesn't have these values.
3538 */
3539 if ( *fgint == -1 )
3540 {
3541 XtSetArg (pixarg[pcnt], XmNforeground, fgint) ;
3542 pcnt += 1 ;
3543 }
3544 if ( *bgint == -1 )
3545 {
3546 XtSetArg (pixarg[pcnt], XmNbackground, bgint) ;
3547 pcnt += 1 ;
3548 }
3549 if ( pcnt > 0 )
3550 XtGetValues (w, pixarg, pcnt) ;
3551
3552 /*
3553 * Fall back on ...PixelOfScreen
3554 */
3555 if ( *fgint == -1 )
3556 *fgint = BlackPixelOfScreen (*screen) ;
3557 if ( *bgint == -1 )
3558 *bgint = WhitePixelOfScreen (*screen) ;
3559
3560 /*
3561 * Make sure we haven't ended with identical values
3562 */
3563 if ( *fgint == *bgint )
3564 {
3565 if ( *bgint == BlackPixelOfScreen(*screen) )
3566 *fgint = WhitePixelOfScreen (*screen) ;
3567 else
3568 *fgint = BlackPixelOfScreen (*screen) ;
3569 }
3570
3571 }
3572
3573
3574
3575 /*
3576 *++
3577 *
3578 * PROCEDURE DESCRIPTION:
3579 *
3580 * This routine translates an RGMCallbackDescPtr stored in a 1.1 uid
3581 * file into the equivalent 1.2+ structure. This routine allocates
3582 * memory which must later be freed using XtFree.
3583 *
3584 * FORMAL PARAMETERS:
3585 *
3586 * oldptr Pointer into the buffer where the 1.1 callback
3587 * descriptor starts.
3588 *
3589 * IMPLICIT INPUTS:
3590 *
3591 * IMPLICIT OUTPUTS:
3592 *
3593 * FUNCTION VALUE:
3594 *
3595 * This function returns a pointer to a new RGMCallbackDesc containing
3596 * all the information from the structure stored in the uid file.
3597 *
3598 * SIDE EFFECTS:
3599 *
3600 * Memory is allocated which must be freed using XtFree.
3601 *
3602 *--
3603 */
3604
3605 RGMCallbackDescPtr
Urm__CW_TranslateOldCallback(OldRGMCallbackDescPtr oldptr)3606 Urm__CW_TranslateOldCallback (OldRGMCallbackDescPtr oldptr)
3607 {
3608 /*
3609 * Local variables
3610 */
3611 RGMCallbackDescPtr cbptr; /* pointer to new callback descriptor */
3612 RGMCallbackItemPtr itmptr; /* current callback item */
3613 OldRGMCallbackItemPtr olditmptr; /* callback item being converted */
3614 int ndx; /* loop index */
3615
3616 cbptr = (RGMCallbackDescPtr) XtMalloc(sizeof(RGMCallbackDesc) +
3617 oldptr->count*sizeof(RGMCallbackItem));
3618
3619 cbptr->validation = oldptr->validation;
3620 cbptr->count = oldptr->count;
3621
3622 /* Loop through all items in old callback list copying to new. */
3623 for (ndx = 0; ndx <= cbptr->count; ndx++)
3624 /* <= so that null item is copied. */
3625 {
3626 olditmptr = &oldptr->item[ndx];
3627 itmptr = &cbptr->item[ndx];
3628
3629 itmptr->cb_item.routine = olditmptr->cb_item.routine;
3630 itmptr->cb_item.rep_type = olditmptr->cb_item.rep_type;
3631 itmptr->cb_item.datum = olditmptr->cb_item.datum;
3632 }
3633
3634 return cbptr;
3635 }
3636
3637