Oops. Last change to mem.h was bogus.
[nvi.git] / motif_l / m_util.c
blob1cb933047600e0b02d4b16377a7f0a10f051032e
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_util.c,v 8.11 2001/06/25 15:19:28 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:28 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
21 #include <X11/Shell.h>
22 #include <X11/Xatom.h>
24 #include <bitstring.h>
25 #include <stdio.h>
26 #include <string.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "m_motif.h"
33 /* Widget hierarchy routines
35 * void XutShowWidgetTree( FILE *fp, Widget root, int indent )
36 * prints the widgets and sub-widgets beneath the named root widget
38 #ifdef DEBUG
39 #if defined(__STDC__)
40 void XutShowWidgetTree( FILE *fp, Widget root, int indent )
41 #else
42 void XutShowWidgetTree( fp, root, indent )
43 FILE *fp;
44 Widget root;
45 int indent;
46 #endif
48 #if ! defined(DECWINDOWS)
49 WidgetList l, l2;
50 int i, count = 0;
52 /* print where we are right now */
53 fprintf( fp,
54 "%*.*swidget => 0x%x name => \"%s\"\n\r",
55 indent,
56 indent,
57 "",
58 root,
59 XtName(root) );
61 /* get the correct widget values */
62 XtVaGetValues( root, XtNchildren, &l, 0 );
63 XtVaGetValues( root, XtNchildren, &l2, 0 );
64 XtVaGetValues( root, XtNnumChildren, &count, 0 );
66 /* print the sub-widgets */
67 for ( i=0; i<count; i++ ) {
68 XutShowWidgetTree( fp, l[i], indent+4 );
71 /* tidy up if this thing contained children */
72 if ( count > 0 ) {
73 /* we may or may not have to free the children */
74 if ( l != l2 ) {
75 XtFree( (char *) l );
76 XtFree( (char *) l2 );
79 #endif
81 #endif
84 /* Utilities for converting X resources...
86 * __XutConvertResources( Widget, String root, XutResource *, int count )
87 * The resource block is loaded with converted values
88 * If the X resource does not exist, no change is made to the value
89 * 'root' should be the application name.
91 * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int));
93 void __XutConvertResources(Widget wid, String root, XutResource *resources, int count)
95 int i;
96 XrmValue from, to;
97 String kind;
98 Boolean success = True;
100 /* for each resource */
101 for (i=0; i<count; i++) {
103 /* is there a value in the database? */
104 from.addr = XGetDefault( XtDisplay(wid), root, resources[i].name );
105 if ( from.addr == NULL || *from.addr == '\0' )
106 continue;
108 /* load common parameters */
109 from.size = strlen( from.addr );
110 to.addr = resources[i].value;
112 /* load type-specific parameters */
113 switch ( resources[i].kind ) {
114 case XutRKinteger:
115 to.size = sizeof(int);
116 kind = XtRInt;
117 break;
119 case XutRKboolean:
120 /* String to Boolean */
121 to.size = sizeof(Boolean);
122 kind = XtRBoolean;
123 break;
125 case XutRKfont:
126 /* String to Font structure */
127 to.size = sizeof(XFontStruct *);
128 kind = XtRFontStruct;
129 break;
131 case XutRKpixelBackup:
132 /* String to Pixel backup algorithm */
133 if ( success ) continue;
134 /* FALL through */
136 case XutRKpixel:
137 /* String to Pixel */
138 to.size = sizeof(Pixel);
139 kind = XtRPixel;
140 break;
142 case XutRKcursor:
143 /* String to Cursor */
144 to.size = sizeof(int);
145 kind = XtRCursor;
146 break;
148 default:
149 return;
152 /* call the converter */
153 success = XtConvertAndStore( wid, XtRString, &from, kind, &to );