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