Home | History | Annotate | Line # | Download | only in motif_l
      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
     41  *
     42  * void XutShowWidgetTree( FILE *fp, Widget root, int indent )
     43  *	prints the widgets and sub-widgets beneath the named root widget
     44  */
     45 #ifdef DEBUG
     46 #if defined(__STDC__)
     47 void	XutShowWidgetTree( FILE *fp, Widget root, int indent )
     48 #else
     49 void	XutShowWidgetTree( fp, root, indent )
     50 FILE	*fp;
     51 Widget	root;
     52 int	indent;
     53 #endif
     54 {
     55 #if ! defined(DECWINDOWS)
     56     WidgetList	l, l2;
     57     int		i, count = 0;
     58 
     59     /* print where we are right now */
     60     fprintf( fp,
     61 	     "%*.*swidget => 0x%x name => \"%s\"\n\r",
     62 	     indent,
     63 	     indent,
     64 	     "",
     65 	     root,
     66 	     XtName(root) );
     67 
     68     /* get the correct widget values */
     69     XtVaGetValues( root, XtNchildren, &l, 0 );
     70     XtVaGetValues( root, XtNchildren, &l2, 0 );
     71     XtVaGetValues( root, XtNnumChildren, &count, 0 );
     72 
     73     /* print the sub-widgets */
     74     for ( i=0; i<count; i++ ) {
     75 	XutShowWidgetTree( fp, l[i], indent+4 );
     76     }
     77 
     78     /* tidy up if this thing contained children */
     79     if ( count > 0 ) {
     80 	/* we may or may not have to free the children */
     81 	if ( l != l2 ) {
     82 	    XtFree( (char *) l );
     83 	    XtFree( (char *) l2 );
     84 	}
     85     }
     86 #endif
     87 }
     88 #endif
     89 
     90 
     91 /* Utilities for converting X resources...
     93  *
     94  * __XutConvertResources( Widget, String root, XutResource *, int count )
     95  *	The resource block is loaded with converted values
     96  *	If the X resource does not exist, no change is made to the value
     97  *	'root' should be the application name.
     98  *
     99  * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int));
    100  */
    101 void __XutConvertResources(Widget wid, String root, XutResource *resources, int count)
    102 {
    103     int		i;
    104     XrmValue	from, to;
    105     String	kind;
    106     Boolean	success = True;
    107 
    108     /* for each resource */
    109     for (i=0; i<count; i++) {
    110 
    111 	/* is there a value in the database? */
    112 	from.addr = XGetDefault( XtDisplay(wid), root, resources[i].name );
    113 	if ( from.addr == NULL || *from.addr == '\0' )
    114 	    continue;
    115 
    116 	/* load common parameters */
    117 	from.size = strlen( from.addr );
    118 	to.addr   = resources[i].value;
    119 
    120 	/* load type-specific parameters */
    121 	switch ( resources[i].kind ) {
    122 	    case XutRKinteger:
    123 		to.size	= sizeof(int);
    124 		kind	= XtRInt;
    125 		break;
    126 
    127 	    case XutRKboolean:
    128 		/* String to Boolean */
    129 		to.size	= sizeof(Boolean);
    130 		kind	= XtRBoolean;
    131 		break;
    132 
    133 	    case XutRKfont:
    134 		/* String to Font structure */
    135 		to.size	= sizeof(XFontStruct *);
    136 		kind	= XtRFontStruct;
    137 		break;
    138 
    139 	    case XutRKpixelBackup:
    140 		/* String to Pixel backup algorithm */
    141 		if ( success ) continue;
    142 		/* FALL through */
    143 
    144 	    case XutRKpixel:
    145 		/* String to Pixel */
    146 		to.size	= sizeof(Pixel);
    147 		kind	= XtRPixel;
    148 		break;
    149 
    150 	    case XutRKcursor:
    151 		/* String to Cursor */
    152 		to.size	= sizeof(int);
    153 		kind	= XtRCursor;
    154 		break;
    155 
    156 	    default:
    157 		return;
    158 	}
    159 
    160 	/* call the converter */
    161 	success = XtConvertAndStore( wid, XtRString, &from, kind, &to );
    162     }
    163 }
    164