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