Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / motif_l / m_util.c
blobd2111f6e89ac3f0bc7bec5194473f8fc916bd071
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1996
5 * Rob Zimmermann. All rights reserved.
6 * Copyright (c) 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
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 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <X11/Intrinsic.h>
22 #include <X11/StringDefs.h>
23 #include <X11/Shell.h>
24 #include <X11/Xatom.h>
26 #include <bitstring.h>
27 #include <stdio.h>
28 #include <string.h>
30 #undef LOCK_SUCCESS
31 #include "../common/common.h"
32 #include "../ipc/ip.h"
33 #include "m_motif.h"
36 /* Widget hierarchy routines
38 * void XutShowWidgetTree( FILE *fp, Widget root, int indent )
39 * prints the widgets and sub-widgets beneath the named root widget
41 #ifdef DEBUG
42 #if defined(__STDC__)
43 void XutShowWidgetTree( FILE *fp, Widget root, int indent )
44 #else
45 void XutShowWidgetTree( fp, root, indent )
46 FILE *fp;
47 Widget root;
48 int indent;
49 #endif
51 #if ! defined(DECWINDOWS)
52 WidgetList l, l2;
53 int i, count = 0;
55 /* print where we are right now */
56 fprintf( fp,
57 "%*.*swidget => 0x%x name => \"%s\"\n\r",
58 indent,
59 indent,
60 "",
61 root,
62 XtName(root) );
64 /* get the correct widget values */
65 XtVaGetValues( root, XtNchildren, &l, 0 );
66 XtVaGetValues( root, XtNchildren, &l2, 0 );
67 XtVaGetValues( root, XtNnumChildren, &count, 0 );
69 /* print the sub-widgets */
70 for ( i=0; i<count; i++ ) {
71 XutShowWidgetTree( fp, l[i], indent+4 );
74 /* tidy up if this thing contained children */
75 if ( count > 0 ) {
76 /* we may or may not have to free the children */
77 if ( l != l2 ) {
78 XtFree( (char *) l );
79 XtFree( (char *) l2 );
82 #endif
84 #endif
87 /* Utilities for converting X resources...
89 * __XutConvertResources( Widget, String root, XutResource *, int count )
90 * The resource block is loaded with converted values
91 * If the X resource does not exist, no change is made to the value
92 * 'root' should be the application name.
94 * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int));
96 void __XutConvertResources(Widget wid, String root, XutResource *resources, int count)
98 int i;
99 XrmValue from, to;
100 String kind;
101 Boolean success = True;
103 /* for each resource */
104 for (i=0; i<count; i++) {
106 /* is there a value in the database? */
107 from.addr = XGetDefault( XtDisplay(wid), root, resources[i].name );
108 if ( from.addr == NULL || *from.addr == '\0' )
109 continue;
111 /* load common parameters */
112 from.size = strlen( from.addr );
113 to.addr = resources[i].value;
115 /* load type-specific parameters */
116 switch ( resources[i].kind ) {
117 case XutRKinteger:
118 to.size = sizeof(int);
119 kind = XtRInt;
120 break;
122 case XutRKboolean:
123 /* String to Boolean */
124 to.size = sizeof(Boolean);
125 kind = XtRBoolean;
126 break;
128 case XutRKfont:
129 /* String to Font structure */
130 to.size = sizeof(XFontStruct *);
131 kind = XtRFontStruct;
132 break;
134 case XutRKpixelBackup:
135 /* String to Pixel backup algorithm */
136 if ( success ) continue;
137 /* FALL through */
139 case XutRKpixel:
140 /* String to Pixel */
141 to.size = sizeof(Pixel);
142 kind = XtRPixel;
143 break;
145 case XutRKcursor:
146 /* String to Cursor */
147 to.size = sizeof(int);
148 kind = XtRCursor;
149 break;
151 default:
152 return;
155 /* call the converter */
156 success = XtConvertAndStore( wid, XtRString, &from, kind, &to );