1/* $NetBSD$ */ 2 3/*- 4 * Copyright (c) 1996 5 * Rob Zimmermann. All rights reserved. 6 * Copyright (c) 1996 7 * Keith Bostic. All rights reserved. 8 * 9 * See the LICENSE file for redistribution information. 10 */ 11 12#include "config.h" 13 14#ifndef lint 15static 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 18#include <sys/types.h> 19#include <sys/queue.h> 20 21#include <X11/Intrinsic.h> 22#include <X11/StringDefs.h> 23#include <X11/Shell.h> 24#include <X11/Xatom.h> 25 26#include <bitstring.h> 27#include <stdio.h> 28#include <string.h> 29 30#undef LOCK_SUCCESS 31#include "../common/common.h" 32#include "../ipc/ip.h" 33#include "m_motif.h" 34 35 36/* Widget hierarchy routines 37 * 38 * void XutShowWidgetTree( FILE *fp, Widget root, int indent ) 39 * prints the widgets and sub-widgets beneath the named root widget 40 */ 41#ifdef DEBUG 42#if defined(__STDC__) 43void XutShowWidgetTree( FILE *fp, Widget root, int indent ) 44#else 45void XutShowWidgetTree( fp, root, indent ) 46FILE *fp; 47Widget root; 48int indent; 49#endif 50{ 51#if ! defined(DECWINDOWS) 52 WidgetList l, l2; 53 int i, count = 0; 54 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) ); 63 64 /* get the correct widget values */ 65 XtVaGetValues( root, XtNchildren, &l, 0 ); 66 XtVaGetValues( root, XtNchildren, &l2, 0 ); 67 XtVaGetValues( root, XtNnumChildren, &count, 0 ); 68 69 /* print the sub-widgets */ 70 for ( i=0; i<count; i++ ) { 71 XutShowWidgetTree( fp, l[i], indent+4 ); 72 } 73 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 ); 80 } 81 } 82#endif 83} 84#endif 85 86 87/* Utilities for converting X resources... 88 * 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. 93 * 94 * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int)); 95 */ 96void __XutConvertResources(Widget wid, String root, XutResource *resources, int count) 97{ 98 int i; 99 XrmValue from, to; 100 String kind; 101 Boolean success = True; 102 103 /* for each resource */ 104 for (i=0; i<count; i++) { 105 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; 110 111 /* load common parameters */ 112 from.size = strlen( from.addr ); 113 to.addr = resources[i].value; 114 115 /* load type-specific parameters */ 116 switch ( resources[i].kind ) { 117 case XutRKinteger: 118 to.size = sizeof(int); 119 kind = XtRInt; 120 break; 121 122 case XutRKboolean: 123 /* String to Boolean */ 124 to.size = sizeof(Boolean); 125 kind = XtRBoolean; 126 break; 127 128 case XutRKfont: 129 /* String to Font structure */ 130 to.size = sizeof(XFontStruct *); 131 kind = XtRFontStruct; 132 break; 133 134 case XutRKpixelBackup: 135 /* String to Pixel backup algorithm */ 136 if ( success ) continue; 137 /* FALL through */ 138 139 case XutRKpixel: 140 /* String to Pixel */ 141 to.size = sizeof(Pixel); 142 kind = XtRPixel; 143 break; 144 145 case XutRKcursor: 146 /* String to Cursor */ 147 to.size = sizeof(int); 148 kind = XtRCursor; 149 break; 150 151 default: 152 return; 153 } 154 155 /* call the converter */ 156 success = XtConvertAndStore( wid, XtRString, &from, kind, &to ); 157 } 158} 159