Blame lib/Xm/EditresCom.c

Packit b099d7
/* $XConsortium: EditresCom.c /main/34 1995/12/11 00:19:42 gildea $ */
Packit b099d7
Packit b099d7
/*
Packit b099d7
Packit b099d7
Copyright (c) 1989  X Consortium
Packit b099d7
Packit b099d7
Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b099d7
of this software and associated documentation files (the "Software"), to deal
Packit b099d7
in the Software without restriction, including without limitation the rights
Packit b099d7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Packit b099d7
copies of the Software, and to permit persons to whom the Software is
Packit b099d7
furnished to do so, subject to the following conditions:
Packit b099d7
Packit b099d7
The above copyright notice and this permission notice shall be included in
Packit b099d7
all copies or substantial portions of the Software.
Packit b099d7
Packit b099d7
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b099d7
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b099d7
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit b099d7
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit b099d7
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit b099d7
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit b099d7
Packit b099d7
Except as contained in this notice, the name of the X Consortium shall not be
Packit b099d7
used in advertising or otherwise to promote the sale, use or other dealings
Packit b099d7
in this Software without prior written authorization from the X Consortium.
Packit b099d7
Packit b099d7
*/
Packit b099d7
/* $XFree86: xc/lib/Xmu/EditresCom.c,v 1.3.2.4 1999/07/23 13:22:15 hohndel Exp $ */
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * Author:  Chris D. Peterson, Dave Sternlicht, MIT X Consortium
Packit b099d7
 */
Packit b099d7
Packit b099d7
/*
Packit b099d7
    Replacement EditresCom.c for the one in Xmu to add the GetValues
Packit b099d7
    feature, and to modify the PositionInChild function for Motif. This
Packit b099d7
    modification is needed because Motif's VendorShell lies about the
Packit b099d7
    real position of it's child.
Packit b099d7
 */
Packit b099d7
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#include <X11/IntrinsicP.h>	/* To get into the composite and core widget
Packit b099d7
				   structures. */
Packit b099d7
#include <X11/ObjectP.h>	/* For XtIs<Classname> macros. */
Packit b099d7
#include <X11/StringDefs.h>	/* for XtRString. */
Packit b099d7
#define  XK_LATIN1
Packit b099d7
#include <X11/keysymdef.h>
Packit b099d7
#include <X11/ShellP.h>		/* for Application Shell Widget class. */
Packit b099d7
Packit b099d7
#include <X11/Xatom.h>
Packit b099d7
#include <X11/Xos.h>		/* for strcpy declaration */
Packit b099d7
#include <X11/Xmu/EditresP.h>
Packit b099d7
#include <X11/Xmu/CharSet.h>
Packit b099d7
#include <X11/Xmd.h>
Packit b099d7
Packit b099d7
#include <stdio.h>
Packit b099d7
Packit b099d7
#define _XEditResPutBool _XEditResPut8	
Packit b099d7
#define _XEditResPutResourceType _XEditResPut8
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Local structure definitions.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
typedef enum { BlockNone, BlockSetValues, BlockAll } EditresBlock;
Packit b099d7
Packit b099d7
typedef struct _SetValuesEvent {
Packit b099d7
    EditresCommand type;	/* first field must be type. */
Packit b099d7
    WidgetInfo * widgets;
Packit b099d7
    unsigned short num_entries;		/* number of set values requests. */
Packit b099d7
    char * name;
Packit b099d7
    char * res_type;
Packit b099d7
    XtPointer value;
Packit b099d7
    unsigned short value_len;
Packit b099d7
} SetValuesEvent;
Packit b099d7
Packit b099d7
typedef struct _SVErrorInfo {
Packit b099d7
    SetValuesEvent * event;
Packit b099d7
    ProtocolStream * stream;
Packit b099d7
    unsigned short * count;
Packit b099d7
    WidgetInfo * entry;
Packit b099d7
} SVErrorInfo;
Packit b099d7
Packit b099d7
typedef struct _GetValuesEvent {
Packit b099d7
  EditresCommand type;		/* first field must be type */
Packit b099d7
  WidgetInfo * widgets;
Packit b099d7
  unsigned short num_entries;	/* number of get values requests */
Packit b099d7
  char * name;
Packit b099d7
} GetValuesEvent;
Packit b099d7
Packit b099d7
typedef struct _FindChildEvent {
Packit b099d7
    EditresCommand type;	/* first field must be type. */
Packit b099d7
    WidgetInfo * widgets;
Packit b099d7
    short x, y;
Packit b099d7
} FindChildEvent;
Packit b099d7
Packit b099d7
typedef struct _GenericGetEvent {
Packit b099d7
    EditresCommand type;	/* first field must be type. */
Packit b099d7
    WidgetInfo * widgets;
Packit b099d7
    unsigned short num_entries;		/* number of set values requests. */
Packit b099d7
} GenericGetEvent, GetResEvent, GetGeomEvent;
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * Things that are common to all events.
Packit b099d7
 */
Packit b099d7
Packit b099d7
typedef struct _AnyEvent {
Packit b099d7
    EditresCommand type;	/* first field must be type. */
Packit b099d7
    WidgetInfo * widgets;
Packit b099d7
} AnyEvent;
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * The event union.
Packit b099d7
 */
Packit b099d7
Packit b099d7
typedef union _EditresEvent {
Packit b099d7
    AnyEvent any_event;
Packit b099d7
    SetValuesEvent set_values_event;
Packit b099d7
    GetResEvent get_resources_event;
Packit b099d7
    GetGeomEvent get_geometry_event;
Packit b099d7
    FindChildEvent find_child_event;
Packit b099d7
} EditresEvent;
Packit b099d7
Packit b099d7
typedef struct _Globals {
Packit b099d7
    EditresBlock block;
Packit b099d7
    SVErrorInfo error_info;
Packit b099d7
    ProtocolStream stream;
Packit b099d7
    ProtocolStream * command_stream; /* command stream. */
Packit b099d7
#if defined(LONG64) || defined(WORD64)
Packit b099d7
    unsigned long base_address;
Packit b099d7
#endif
Packit b099d7
} Globals;
Packit b099d7
Packit b099d7
#define CURRENT_PROTOCOL_VERSION 5L
Packit b099d7
Packit b099d7
#define streq(a,b) (strcmp( (a), (b) ) == 0)
Packit b099d7
Packit b099d7
static Atom res_editor_command, res_editor_protocol, client_value;
Packit b099d7
Packit b099d7
static Globals globals;
Packit b099d7
Packit b099d7
static void SendFailure(), SendCommand(), InsertWidget(), ExecuteCommand();
Packit b099d7
static void FreeEvent(), ExecuteSetValues(), ExecuteGetGeometry();
Packit b099d7
static void ExecuteGetResources();
Packit b099d7
Packit b099d7
static void GetCommand();
Packit b099d7
static void LoadResources();
Packit b099d7
static Boolean IsChild();
Packit b099d7
static void DumpChildren();
Packit b099d7
static char *DumpWidgets(), *DoSetValues(), *DoFindChild();
Packit b099d7
static char *DoGetGeometry(), *DoGetResources(), *DumpValues();
Packit b099d7
Packit b099d7
#ifndef HAVE_XMU_N_COPY_ISO
Packit b099d7
void _XmNCopyISOLatin1Lowered(char *dst, char *src, int size)
Packit b099d7
{
Packit b099d7
    register unsigned char *dest, *source;
Packit b099d7
    int bytes;
Packit b099d7
Packit b099d7
    if (size <= 0)
Packit b099d7
	return;
Packit b099d7
Packit b099d7
    for (dest = (unsigned char *)dst, source = (unsigned char *)src, bytes = 0;
Packit b099d7
	 *source && bytes < size - 1;
Packit b099d7
	 source++, dest++, bytes++)
Packit b099d7
    {
Packit b099d7
	if ((*source >= XK_A) && (*source <= XK_Z))
Packit b099d7
	    *dest = *source + (XK_a - XK_A);
Packit b099d7
	else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
Packit b099d7
	    *dest = *source + (XK_agrave - XK_Agrave);
Packit b099d7
	else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
Packit b099d7
	    *dest = *source + (XK_oslash - XK_Ooblique);
Packit b099d7
	else
Packit b099d7
	    *dest = *source;
Packit b099d7
    }
Packit b099d7
    *dest = '\0';
Packit b099d7
}
Packit b099d7
#endif
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Resource Editor Communication Code
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResCheckMessages
Packit b099d7
 *	Description: This callback routine is set on all shell widgets,
Packit b099d7
 *                   and checks to see if a client message event
Packit b099d7
 *                   has come from the resource editor.
Packit b099d7
 *	Arguments: w - the shell widget.
Packit b099d7
 *                 data - *** UNUSED ***
Packit b099d7
 *                 event - The X Event that triggered this handler.
Packit b099d7
 *                 cont - *** UNUSED ***.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
void
Packit b099d7
_XmEditResCheckMessages(w, data, event, cont)
Packit b099d7
Widget w;
Packit b099d7
XtPointer data;
Packit b099d7
XEvent *event;
Packit b099d7
Boolean *cont;
Packit b099d7
{
Packit b099d7
    Time time;
Packit b099d7
    ResIdent ident;
Packit b099d7
    static Boolean first_time = FALSE;
Packit b099d7
    static Atom res_editor, res_comm;
Packit b099d7
    Display * dpy;
Packit b099d7
Packit b099d7
    if (event->type == ClientMessage) {
Packit b099d7
	XClientMessageEvent * c_event = (XClientMessageEvent *) event;
Packit b099d7
	dpy = XtDisplay(w);
Packit b099d7
Packit b099d7
	if (!first_time) {
Packit b099d7
	    Atom atoms[4];
Packit b099d7
	    static char* names[] = {
Packit b099d7
		EDITRES_NAME, EDITRES_COMMAND_ATOM,
Packit b099d7
		EDITRES_PROTOCOL_ATOM, EDITRES_CLIENT_VALUE };
Packit b099d7
		
Packit b099d7
	    first_time = TRUE;
Packit b099d7
	    XInternAtoms(dpy, names, 4, FALSE, atoms);
Packit b099d7
	    res_editor = atoms[0];
Packit b099d7
	    res_editor_command = atoms[1];
Packit b099d7
	    res_editor_protocol = atoms[2];
Packit b099d7
	    /* Used in later procedures. */
Packit b099d7
	    client_value = atoms[3];
Packit b099d7
	    LoadResources(w);
Packit b099d7
	}
Packit b099d7
Packit b099d7
	if ((c_event->message_type != res_editor) ||
Packit b099d7
	    (c_event->format != EDITRES_SEND_EVENT_FORMAT))
Packit b099d7
	    return;
Packit b099d7
Packit b099d7
	time = c_event->data.l[0];
Packit b099d7
	res_comm = c_event->data.l[1];
Packit b099d7
	ident = (ResIdent) c_event->data.l[2];
Packit b099d7
	if (c_event->data.l[3] != CURRENT_PROTOCOL_VERSION) {
Packit b099d7
	    _XEditResResetStream(&globals.stream);
Packit b099d7
	    _XEditResPut8(&globals.stream, (unsigned int) CURRENT_PROTOCOL_VERSION);
Packit b099d7
	    SendCommand(w, res_comm, ident, ProtocolMismatch, &globals.stream);
Packit b099d7
	    return;
Packit b099d7
	}
Packit b099d7
Packit b099d7
	XtGetSelectionValue(w, res_comm, res_editor_command,
Packit b099d7
			    GetCommand, (XtPointer)(long) ident, time);
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: BuildEvent
Packit b099d7
 *	Description: Takes the info out the protocol stream an constructs
Packit b099d7
 *                   the proper event structure.
Packit b099d7
 *	Arguments: w - widget to own selection, in case of error.
Packit b099d7
 *                 sel - selection to send error message beck in.
Packit b099d7
 *                 data - the data for the request.
Packit b099d7
 *                 ident - the id number we are looking for.
Packit b099d7
 *                 length - length of request.
Packit b099d7
 *	Returns: the event, or NULL.
Packit b099d7
 */
Packit b099d7
Packit b099d7
#if defined(Lynx) && defined(ERROR_MESSAGE)
Packit b099d7
#undef ERROR_MESSAGE
Packit b099d7
#endif
Packit b099d7
Packit b099d7
#define ERROR_MESSAGE ("Client: Improperly formatted protocol request")
Packit b099d7
Packit b099d7
static EditresEvent *
Packit b099d7
BuildEvent(w, sel, data, ident, length)
Packit b099d7
Widget w;
Packit b099d7
Atom sel;
Packit b099d7
XtPointer data;
Packit b099d7
ResIdent ident;
Packit b099d7
unsigned long length;
Packit b099d7
{
Packit b099d7
    EditresEvent * event;
Packit b099d7
    ProtocolStream alloc_stream, *stream;
Packit b099d7
    unsigned char temp;
Packit b099d7
    register unsigned int i;
Packit b099d7
Packit b099d7
    stream = &alloc_stream;	/* easier to think of it this way... */
Packit b099d7
Packit b099d7
    stream->current = stream->top = (unsigned char *) data;
Packit b099d7
    stream->size = HEADER_SIZE;		/* size of header. */
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Retrieve the Header.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    if (length < HEADER_SIZE) {
Packit b099d7
	SendFailure(w, sel, ident, ERROR_MESSAGE);
Packit b099d7
	return(NULL);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    (void) _XEditResGet8(stream, &temp);
Packit b099d7
    if (temp != ident)		/* Id's don't match, ignore request. */
Packit b099d7
	return(NULL);		
Packit b099d7
Packit b099d7
    event = (EditresEvent *) XtCalloc(sizeof(EditresEvent), 1);
Packit b099d7
Packit b099d7
    (void) _XEditResGet8(stream, &temp);
Packit b099d7
    event->any_event.type = (EditresCommand) temp;
Packit b099d7
    (void) _XEditResGet32(stream, &(stream->size));
Packit b099d7
    stream->top = stream->current; /* reset stream to top of value.*/
Packit b099d7
	
Packit b099d7
    /*
Packit b099d7
     * Now retrieve the data segment.
Packit b099d7
     */
Packit b099d7
    
Packit b099d7
    switch(event->any_event.type) {
Packit b099d7
    case SendWidgetTree:
Packit b099d7
	break;			/* no additional info */
Packit b099d7
    case SetValues:
Packit b099d7
        {
Packit b099d7
	    SetValuesEvent * sv_event = (SetValuesEvent *) event;
Packit b099d7
	    
Packit b099d7
	    if ( !(_XEditResGetString8(stream, &(sv_event->name)) &&
Packit b099d7
		   _XEditResGetString8(stream, &(sv_event->res_type))))
Packit b099d7
	    {
Packit b099d7
		goto done;
Packit b099d7
	    }
Packit b099d7
Packit b099d7
	    /*
Packit b099d7
	     * Since we need the value length, we have to pull the
Packit b099d7
	     * value out by hand.
Packit b099d7
	     */
Packit b099d7
Packit b099d7
	    if (!_XEditResGet16(stream, &(sv_event->value_len)))
Packit b099d7
		goto done;
Packit b099d7
Packit b099d7
	    sv_event->value = XtMalloc(sizeof(char) * 
Packit b099d7
				       (sv_event->value_len + 1));
Packit b099d7
Packit b099d7
	    for (i = 0; i < sv_event->value_len; i++) {
Packit b099d7
		if (!_XEditResGet8(stream, 
Packit b099d7
				   (unsigned char *) sv_event->value + i)) 
Packit b099d7
		{
Packit b099d7
		    goto done;
Packit b099d7
		}
Packit b099d7
	    }
Packit b099d7
	    ((char*)sv_event->value)[i] = '\0'; /* NULL terminate that sucker. */
Packit b099d7
Packit b099d7
	    if (!_XEditResGet16(stream, &(sv_event->num_entries)))
Packit b099d7
		goto done;
Packit b099d7
Packit b099d7
	    sv_event->widgets = (WidgetInfo *)
Packit b099d7
		XtCalloc(sizeof(WidgetInfo), sv_event->num_entries);
Packit b099d7
	    
Packit b099d7
	    for (i = 0; i < sv_event->num_entries; i++) {
Packit b099d7
		if (!_XEditResGetWidgetInfo(stream, sv_event->widgets + i))
Packit b099d7
		    goto done;
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
	break;
Packit b099d7
    case FindChild:
Packit b099d7
        {
Packit b099d7
	    FindChildEvent * find_event = (FindChildEvent *) event;
Packit b099d7
	    
Packit b099d7
	    find_event->widgets = (WidgetInfo *) 
Packit b099d7
		                  XtCalloc(sizeof(WidgetInfo), 1);
Packit b099d7
Packit b099d7
	    if (!(_XEditResGetWidgetInfo(stream, find_event->widgets) &&
Packit b099d7
		  _XEditResGetSigned16(stream, &(find_event->x)) &&
Packit b099d7
		  _XEditResGetSigned16(stream, &(find_event->y))))
Packit b099d7
	    {
Packit b099d7
		goto done;
Packit b099d7
	    }	    				
Packit b099d7
Packit b099d7
	}
Packit b099d7
	break;
Packit b099d7
    case GetGeometry:
Packit b099d7
    case GetResources:
Packit b099d7
        {
Packit b099d7
	    GenericGetEvent * get_event = (GenericGetEvent *) event;
Packit b099d7
	    
Packit b099d7
	    if (!_XEditResGet16(stream, &(get_event->num_entries)))
Packit b099d7
		goto done;
Packit b099d7
		
Packit b099d7
	    get_event->widgets = (WidgetInfo *)
Packit b099d7
		XtCalloc(sizeof(WidgetInfo), get_event->num_entries);
Packit b099d7
	    for (i = 0; i < get_event->num_entries; i++) {
Packit b099d7
		if (!_XEditResGetWidgetInfo(stream, get_event->widgets + i)) 
Packit b099d7
		    goto done;
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
	break;
Packit b099d7
Packit b099d7
    case GetValues: 
Packit b099d7
        {
Packit b099d7
            GetValuesEvent * gv_event = (GetValuesEvent *) event;
Packit b099d7
            _XEditResGetString8(stream, &(gv_event->name));
Packit b099d7
            _XEditResGet16(stream, &(gv_event->num_entries));
Packit b099d7
	    gv_event->widgets = (WidgetInfo *)
Packit b099d7
		XtCalloc(sizeof(WidgetInfo), gv_event->num_entries);
Packit b099d7
            _XEditResGetWidgetInfo(stream, gv_event->widgets);
Packit b099d7
        }
Packit b099d7
        break;	
Packit b099d7
Packit b099d7
    default:
Packit b099d7
	{
Packit b099d7
	    char buf[BUFSIZ];
Packit b099d7
	    
Packit b099d7
	    sprintf(buf, "Unknown Protocol request %d.",event->any_event.type);
Packit b099d7
	    SendFailure(w, sel, ident, buf);
Packit b099d7
	    return(NULL);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
    return(event);
Packit b099d7
Packit b099d7
 done:
Packit b099d7
Packit b099d7
    SendFailure(w, sel, ident, ERROR_MESSAGE);
Packit b099d7
    FreeEvent(event);
Packit b099d7
    return(NULL);
Packit b099d7
}    
Packit b099d7
Packit b099d7
/*	Function Name: FreeEvent
Packit b099d7
 *	Description: Frees the event structure and any other pieces
Packit b099d7
 *                   in it that need freeing.
Packit b099d7
 *	Arguments: event - the event to free.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
FreeEvent(event)
Packit b099d7
EditresEvent * event;
Packit b099d7
{
Packit b099d7
    if (event->any_event.widgets != NULL) {
Packit b099d7
	XtFree((char *)event->any_event.widgets->ids);
Packit b099d7
	XtFree((char *)event->any_event.widgets);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    if (event->any_event.type == SetValues) {
Packit b099d7
	XtFree(event->set_values_event.name);     /* XtFree does not free if */
Packit b099d7
	XtFree(event->set_values_event.res_type); /* value is NULL. */
Packit b099d7
    }
Packit b099d7
	
Packit b099d7
    XtFree((char *)event);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: GetCommand
Packit b099d7
 *	Description: Gets the Command out of the selection asserted by the
Packit b099d7
 *                   resource manager.
Packit b099d7
 *	Arguments: (See Xt XtConvertSelectionProc)
Packit b099d7
 *                 data - contains the ident number for the command.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
static void
Packit b099d7
GetCommand(w, data, selection, type, value, length, format)
Packit b099d7
Widget w;
Packit b099d7
XtPointer data, value;
Packit b099d7
Atom *selection, *type;
Packit b099d7
unsigned long *length;
Packit b099d7
int * format;
Packit b099d7
{
Packit b099d7
    ResIdent ident = (ResIdent)(long) data;
Packit b099d7
    EditresEvent * event;
Packit b099d7
Packit b099d7
    if ( (*type != res_editor_protocol) || (*format != EDITRES_FORMAT) )
Packit b099d7
	return;
Packit b099d7
Packit b099d7
    if ((event = BuildEvent(w, *selection, value, ident, *length)) != NULL) {
Packit b099d7
	ExecuteCommand(w, *selection, ident, event);
Packit b099d7
	FreeEvent(event);
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: ExecuteCommand
Packit b099d7
 *	Description: Executes a command string received from the 
Packit b099d7
 *                   resource editor.
Packit b099d7
 *	Arguments: w       - a widget.
Packit b099d7
 *                 command - the command to execute.
Packit b099d7
 *                 value - the associated with the command.
Packit b099d7
 *	Returns: none.
Packit b099d7
 *
Packit b099d7
 * NOTES:  munges str
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */    
Packit b099d7
static void
Packit b099d7
ExecuteCommand(w, sel, ident, event)
Packit b099d7
Widget w;
Packit b099d7
Atom sel;
Packit b099d7
ResIdent ident;
Packit b099d7
EditresEvent * event;
Packit b099d7
{
Packit b099d7
    char * (*func)();
Packit b099d7
    char * str;
Packit b099d7
Packit b099d7
    if (globals.block == BlockAll) {
Packit b099d7
	SendFailure(w, sel, ident, 
Packit b099d7
		    "This client has blocked all Editres commands.");
Packit b099d7
	return;
Packit b099d7
    }
Packit b099d7
    else if ((globals.block == BlockSetValues) && 
Packit b099d7
	(event->any_event.type == SetValues)) {
Packit b099d7
	SendFailure(w, sel, ident, 
Packit b099d7
		    "This client has blocked all SetValues requests.");
Packit b099d7
	return;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    switch(event->any_event.type) {
Packit b099d7
    case SendWidgetTree:
Packit b099d7
#if defined(LONG64) || defined(WORD64)
Packit b099d7
	globals.base_address = (unsigned long)w & 0xFFFFFFFF00000000;
Packit b099d7
#endif
Packit b099d7
	func = DumpWidgets;
Packit b099d7
	break;
Packit b099d7
    case SetValues:
Packit b099d7
	func = DoSetValues;
Packit b099d7
	break;
Packit b099d7
    case FindChild:
Packit b099d7
	func = DoFindChild;
Packit b099d7
	break;
Packit b099d7
    case GetGeometry:
Packit b099d7
	func = DoGetGeometry;
Packit b099d7
	break;
Packit b099d7
    case GetResources:
Packit b099d7
	func = DoGetResources;
Packit b099d7
	break;
Packit b099d7
    case GetValues:
Packit b099d7
        func = DumpValues;
Packit b099d7
    break;
Packit b099d7
    default: 
Packit b099d7
        {
Packit b099d7
	    char buf[BUFSIZ];
Packit b099d7
	    sprintf(buf,"Unknown Protocol request %d.",event->any_event.type);
Packit b099d7
	    SendFailure(w, sel, ident, buf);
Packit b099d7
	    return;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    _XEditResResetStream(&globals.stream);
Packit b099d7
    if ((str = (*func)(w, event, &globals.stream)) == NULL)
Packit b099d7
	SendCommand(w, sel, ident, PartialSuccess, &globals.stream);
Packit b099d7
    else {
Packit b099d7
	SendFailure(w, sel, ident, str);
Packit b099d7
	XtFree(str);
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: ConvertReturnCommand
Packit b099d7
 *	Description: Converts a selection.
Packit b099d7
 *	Arguments: w - the widget that owns the selection.
Packit b099d7
 *                 selection - selection to convert.
Packit b099d7
 *                 target - target type for this selection.
Packit b099d7
 *                 type_ret - type of the selection.
Packit b099d7
 *                 value_ret - selection value;
Packit b099d7
 *                 length_ret - lenght of this selection.
Packit b099d7
 *                 format_ret - the format the selection is in.
Packit b099d7
 *	Returns: True if conversion was sucessful.
Packit b099d7
 */
Packit b099d7
    
Packit b099d7
/* ARGSUSED */
Packit b099d7
static Boolean
Packit b099d7
ConvertReturnCommand(w, selection, target,
Packit b099d7
		     type_ret, value_ret, length_ret, format_ret)
Packit b099d7
Widget w;
Packit b099d7
Atom * selection, * target, * type_ret;
Packit b099d7
XtPointer *value_ret;
Packit b099d7
unsigned long * length_ret;
Packit b099d7
int * format_ret;
Packit b099d7
{
Packit b099d7
    /*
Packit b099d7
     * I assume the intrinsics give me the correct selection back.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    if ((*target != client_value))
Packit b099d7
	return(FALSE);
Packit b099d7
Packit b099d7
    *type_ret = res_editor_protocol;
Packit b099d7
    *value_ret = (XtPointer) globals.command_stream->real_top;
Packit b099d7
    *length_ret = globals.command_stream->size + HEADER_SIZE;
Packit b099d7
    *format_ret = EDITRES_FORMAT;
Packit b099d7
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: CommandDone
Packit b099d7
 *	Description: done with the selection.
Packit b099d7
 *	Arguments: *** UNUSED ***
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
static void
Packit b099d7
CommandDone(widget, selection, target)
Packit b099d7
Widget widget;
Packit b099d7
Atom *selection;
Packit b099d7
Atom *target;    
Packit b099d7
{
Packit b099d7
    /* Keep the toolkit from automaticaly freeing the selection value */
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: SendFailure
Packit b099d7
 *	Description: Sends a failure message.
Packit b099d7
 *	Arguments: w - the widget to own the selection.
Packit b099d7
 *                 sel - the selection to assert.
Packit b099d7
 *	 	   ident - the identifier.
Packit b099d7
 *                 str - the error message.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
SendFailure(w, sel, ident, str) 
Packit b099d7
Widget w;
Packit b099d7
Atom sel;
Packit b099d7
ResIdent ident;
Packit b099d7
char * str;
Packit b099d7
{
Packit b099d7
    _XEditResResetStream(&globals.stream);
Packit b099d7
    _XEditResPutString8(&globals.stream, str);
Packit b099d7
    SendCommand(w, sel, ident, Failure, &globals.stream);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: BuildReturnPacket
Packit b099d7
 *	Description: Builds a return packet, given the data to send.
Packit b099d7
 *	Arguments: ident - the identifier.
Packit b099d7
 *                 command - the command code.
Packit b099d7
 *                 stream - the protocol stream.
Packit b099d7
 *	Returns: packet - the packet to send.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static XtPointer
Packit b099d7
BuildReturnPacket(ident, command, stream)
Packit b099d7
ResIdent ident;
Packit b099d7
EditresCommand command;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    long old_alloc, old_size;
Packit b099d7
    unsigned char * old_current;
Packit b099d7
    
Packit b099d7
    /*
Packit b099d7
     * We have cleverly keep enough space at the top of the header
Packit b099d7
     * for the return protocol stream, so all we have to do is
Packit b099d7
     * fill in the space.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    /* 
Packit b099d7
     * Fool the insert routines into putting the header in the right
Packit b099d7
     * place while being damn sure not to realloc (that would be very bad.
Packit b099d7
     */
Packit b099d7
    
Packit b099d7
    old_current = stream->current;
Packit b099d7
    old_alloc = stream->alloc;
Packit b099d7
    old_size = stream->size;
Packit b099d7
Packit b099d7
    stream->current = stream->real_top;
Packit b099d7
    stream->alloc = stream->size + (2 * HEADER_SIZE);	
Packit b099d7
    
Packit b099d7
    _XEditResPut8(stream, ident);
Packit b099d7
    _XEditResPut8(stream, (unsigned char) command);
Packit b099d7
    _XEditResPut32(stream, old_size);
Packit b099d7
Packit b099d7
    stream->alloc = old_alloc;
Packit b099d7
    stream->current = old_current;
Packit b099d7
    stream->size = old_size;
Packit b099d7
    
Packit b099d7
    return((XtPointer) stream->real_top);
Packit b099d7
}    
Packit b099d7
Packit b099d7
/*	Function Name: SendCommand
Packit b099d7
 *	Description: Builds a return command line.
Packit b099d7
 *	Arguments: w - the widget to own the selection.
Packit b099d7
 *                 sel - the selection to assert.
Packit b099d7
 *	 	   ident - the identifier.
Packit b099d7
 *                 command - the command code.
Packit b099d7
 *                 stream - the protocol stream.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
SendCommand(w, sel, ident, command, stream)
Packit b099d7
Widget w;
Packit b099d7
Atom sel;
Packit b099d7
ResIdent ident;
Packit b099d7
EditresCommand command;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    BuildReturnPacket(ident, command, stream);
Packit b099d7
    globals.command_stream = stream;	
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * I REALLY want to own the selection.  Since this was not triggered
Packit b099d7
 * by a user action, and I am the only one using this atom it is safe to
Packit b099d7
 * use CurrentTime.
Packit b099d7
 */
Packit b099d7
Packit b099d7
    XtOwnSelection(w, sel, CurrentTime,
Packit b099d7
		   ConvertReturnCommand, NULL, CommandDone);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Generic Utility Functions.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: FindChildren
Packit b099d7
 *	Description: Retuns all children (popup, normal and otherwise)
Packit b099d7
 *                   of this widget
Packit b099d7
 *	Arguments: parent - the parent widget.
Packit b099d7
 *                 children - the list of children.
Packit b099d7
 *                 normal - return normal children.
Packit b099d7
 *                 popup - return popup children.
Packit b099d7
 *	Returns: the number of children.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static int
Packit b099d7
FindChildren(parent, children, normal, popup)
Packit b099d7
Widget parent, **children;
Packit b099d7
Boolean normal, popup;
Packit b099d7
{
Packit b099d7
    CompositeWidget cw = (CompositeWidget) parent;
Packit b099d7
    int i, num_children, current = 0;
Packit b099d7
    
Packit b099d7
    num_children = 0;
Packit b099d7
Packit b099d7
    if (XtIsWidget(parent) && popup)
Packit b099d7
	num_children += parent->core.num_popups;
Packit b099d7
	
Packit b099d7
    if (XtIsComposite(parent) && normal) 
Packit b099d7
	num_children += cw->composite.num_children; 
Packit b099d7
Packit b099d7
    if (num_children == 0) {	
Packit b099d7
	*children = NULL; 
Packit b099d7
	return(0);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    *children =(Widget*) XtMalloc((Cardinal) sizeof(Widget) * num_children);
Packit b099d7
Packit b099d7
    if (XtIsComposite(parent) && normal)
Packit b099d7
	for (i = 0; i < cw->composite.num_children; i++,current++) 
Packit b099d7
	    (*children)[current] = cw->composite.children[i]; 
Packit b099d7
Packit b099d7
    if (XtIsWidget(parent) && popup)
Packit b099d7
	for ( i = 0; i < parent->core.num_popups; i++, current++) 
Packit b099d7
	    (*children)[current] = parent->core.popup_list[i];
Packit b099d7
Packit b099d7
    return(num_children);
Packit b099d7
}
Packit b099d7
		
Packit b099d7
/*	Function Name: IsChild
Packit b099d7
 *	Description: check to see of child is a child of parent.
Packit b099d7
 *	Arguments: top - the top of the tree.
Packit b099d7
 *                 parent - the parent widget.
Packit b099d7
 *                 child - the child.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static Boolean
Packit b099d7
IsChild(top, parent, child)
Packit b099d7
Widget top, parent, child;
Packit b099d7
{
Packit b099d7
    int i, num_children;
Packit b099d7
    Widget * children;
Packit b099d7
Packit b099d7
    if (parent == NULL)
Packit b099d7
	return(top == child);
Packit b099d7
Packit b099d7
    num_children = FindChildren(parent, &children, TRUE, TRUE);
Packit b099d7
Packit b099d7
    for (i = 0; i < num_children; i++) {
Packit b099d7
	if (children[i] == child) {
Packit b099d7
	    XtFree((char *)children);
Packit b099d7
	    return(TRUE);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    XtFree((char *)children);
Packit b099d7
    return(FALSE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: VerifyWidget
Packit b099d7
 *	Description: Makes sure all the widgets still exist.
Packit b099d7
 *	Arguments: w - any widget in the tree.
Packit b099d7
 *                 info - the info about the widget to verify.
Packit b099d7
 *	Returns: an error message or NULL.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char * 
Packit b099d7
VerifyWidget(w, info)
Packit b099d7
Widget w;
Packit b099d7
WidgetInfo *info;
Packit b099d7
{
Packit b099d7
    Widget top;
Packit b099d7
Packit b099d7
    register int count;
Packit b099d7
    register Widget parent;
Packit b099d7
    register unsigned long * child;
Packit b099d7
Packit b099d7
    for (top = w; XtParent(top) != NULL; top = XtParent(top)) {}
Packit b099d7
Packit b099d7
    parent = NULL;
Packit b099d7
    child = info->ids;
Packit b099d7
    count = 0;
Packit b099d7
Packit b099d7
    while (TRUE) {
Packit b099d7
	if (!IsChild(top, parent, (Widget) *child)) 
Packit b099d7
	    return(XtNewString("This widget no longer exists in the client."));
Packit b099d7
Packit b099d7
	if (++count == info->num_widgets)
Packit b099d7
	    break;
Packit b099d7
Packit b099d7
	parent = (Widget) *child++;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    info->real_widget = (Widget) *child;
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code to Perform SetValues operations.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
Packit b099d7
/*	Function Name: 	DoSetValues
Packit b099d7
 *	Description: performs the setvalues requested.
Packit b099d7
 *	Arguments: w - a widget in the tree.
Packit b099d7
 *                 event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: NULL.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char *
Packit b099d7
DoSetValues(w, event, stream)
Packit b099d7
Widget w;
Packit b099d7
EditresEvent * event;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    char * str;
Packit b099d7
    register unsigned i;
Packit b099d7
    unsigned short count = 0;
Packit b099d7
    SetValuesEvent * sv_event = (SetValuesEvent *) event;
Packit b099d7
    
Packit b099d7
    _XEditResPut16(stream, count); /* insert 0, will be overwritten later. */
Packit b099d7
Packit b099d7
    for (i = 0 ; i < sv_event->num_entries; i++) {
Packit b099d7
	if ((str = VerifyWidget(w, &(sv_event->widgets[i]))) != NULL) {
Packit b099d7
	    _XEditResPutWidgetInfo(stream, &(sv_event->widgets[i]));
Packit b099d7
	    _XEditResPutString8(stream, str);
Packit b099d7
	    XtFree(str);
Packit b099d7
	    count++;
Packit b099d7
	}
Packit b099d7
	else 
Packit b099d7
	    ExecuteSetValues(sv_event->widgets[i].real_widget, 
Packit b099d7
			     sv_event, sv_event->widgets + i, stream, &count);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Overwrite the first 2 bytes with the real count.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    *(stream->top) = count >> XER_NBBY;
Packit b099d7
    *(stream->top + 1) = count;
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: HandleToolkitErrors
Packit b099d7
 *	Description: Handles X Toolkit Errors.
Packit b099d7
 *	Arguments: name - name of the error.
Packit b099d7
 *                 type - type of the error.
Packit b099d7
 *                 class - class of the error.
Packit b099d7
 *                 msg - the default message.
Packit b099d7
 *                 params, num_params - the extra parameters for this message.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
static void
Packit b099d7
HandleToolkitErrors(name, type, class, msg, params, num_params)
Packit b099d7
String name, type, class, msg, *params;
Packit b099d7
Cardinal * num_params;
Packit b099d7
{
Packit b099d7
    SVErrorInfo * info = &globals.error_info;	
Packit b099d7
    char buf[BUFSIZ];
Packit b099d7
    char *pbuf;
Packit b099d7
    int len;
Packit b099d7
Packit b099d7
    if ( streq(name, "unknownType") ) {
Packit b099d7
	char *msg1 = "The `";
Packit b099d7
	char *msg2 = "' resource is not used by this widget.";
Packit b099d7
	len = strlen(msg1) + strlen(msg2) + strlen(info->event->name) + 1;
Packit b099d7
	if (len > sizeof(buf))
Packit b099d7
	    pbuf = XtMalloc(len);
Packit b099d7
	else
Packit b099d7
	    pbuf = buf;
Packit b099d7
	if (pbuf == NULL) {
Packit b099d7
	    pbuf = buf;
Packit b099d7
	    sprintf(pbuf, "A%s", msg2);
Packit b099d7
	} else {
Packit b099d7
	    sprintf(pbuf, "%s%s%s", msg1, info->event->name, msg2); 
Packit b099d7
	}
Packit b099d7
    } else if ( streq(name, "noColormap") ) {
Packit b099d7
	len = strlen(msg) + 1;
Packit b099d7
	if (params[0])
Packit b099d7
	    len += strlen(params[0]);
Packit b099d7
	if (len > sizeof(buf))
Packit b099d7
	    pbuf = XtMalloc(len);
Packit b099d7
	else
Packit b099d7
	    pbuf = buf;
Packit b099d7
	if (pbuf == NULL) {
Packit b099d7
	    pbuf = buf;
Packit b099d7
	    sprintf(pbuf, "Message too long");
Packit b099d7
	} else {
Packit b099d7
	    sprintf(pbuf, msg, params[0]); 
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
    else if (streq(name, "conversionFailed") || streq(name, "conversionError"))
Packit b099d7
    {
Packit b099d7
	char *msg1, *msg2, *msg3;
Packit b099d7
	if (streq(info->event->value, XtRString)) {
Packit b099d7
	    msg1 = "Could not convert the string '";
Packit b099d7
	    msg2 = "' for the `";
Packit b099d7
	    msg3 = "' resource.";
Packit b099d7
	    len = strlen(msg1) + strlen(msg2) + strlen(msg3) + 1 +
Packit b099d7
			strlen(info->event->value) + strlen(info->event->name);
Packit b099d7
	} else {
Packit b099d7
	    msg1 = "Could not convert the `";
Packit b099d7
	    msg2 = "' resource.";
Packit b099d7
	    msg3 = "";
Packit b099d7
	    len = strlen(msg1) + strlen(msg2) + strlen(info->event->name) + 1;
Packit b099d7
	}
Packit b099d7
	if (len > sizeof(buf))
Packit b099d7
	    pbuf = XtMalloc(len);
Packit b099d7
	else
Packit b099d7
	    pbuf = buf;
Packit b099d7
	if (streq(info->event->value, XtRString)) {
Packit b099d7
	    if (pbuf == NULL) {
Packit b099d7
		pbuf = buf;
Packit b099d7
		sprintf(pbuf, "Could not convert a string");
Packit b099d7
	    } else {
Packit b099d7
		sprintf(pbuf, "%s%s%s%s%s", msg1, (char *)info->event->value, msg2,
Packit b099d7
			info->event->name, msg3);
Packit b099d7
	    }
Packit b099d7
	} else {
Packit b099d7
	    if (pbuf == NULL) {
Packit b099d7
		pbuf = buf;
Packit b099d7
		sprintf(pbuf, "Could not convert a resource");
Packit b099d7
	    } else {
Packit b099d7
		sprintf(pbuf, "%s%s%s", msg1, info->event->name, msg2);
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
    } else {
Packit b099d7
	char *msg1 = "Name: ", *msg2 = ", Type: ", *msg3 = ", Class: ";
Packit b099d7
	char *msg4 = ", Msg: ";
Packit b099d7
	len = strlen(msg1) + strlen(msg2) + strlen(msg3) + strlen(msg4) +
Packit b099d7
		strlen(name) + strlen(type) + strlen(class) + strlen(msg) + 1;
Packit b099d7
	if (len > sizeof(buf))
Packit b099d7
	    pbuf = XtMalloc(len);
Packit b099d7
	else
Packit b099d7
	    pbuf = buf;
Packit b099d7
	if (pbuf == NULL) {
Packit b099d7
	    pbuf = buf;
Packit b099d7
	    sprintf(pbuf, "Message too long to show");
Packit b099d7
	} else {
Packit b099d7
	    sprintf(pbuf, "%s%s%s%s%s%s%s%s", msg1, name, msg2, type,
Packit b099d7
			msg3, class, msg4, msg);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Insert this info into the protocol stream, and update the count.
Packit b099d7
     */ 
Packit b099d7
Packit b099d7
    (*(info->count))++;
Packit b099d7
    _XEditResPutWidgetInfo(info->stream, info->entry);
Packit b099d7
    _XEditResPutString8(info->stream, pbuf);
Packit b099d7
    if (pbuf != buf)
Packit b099d7
	XtFree(pbuf);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: ExecuteSetValues
Packit b099d7
 *	Description: Performs a setvalues for a given command.
Packit b099d7
 *	Arguments: w - the widget to perform the set_values on.
Packit b099d7
 *                 sv_event - the set values event.
Packit b099d7
 *                 sv_info - the set_value info.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
ExecuteSetValues(w, sv_event, entry, stream, count)
Packit b099d7
Widget w;
Packit b099d7
SetValuesEvent * sv_event;
Packit b099d7
WidgetInfo * entry;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned short * count;
Packit b099d7
{
Packit b099d7
    XtErrorMsgHandler old;
Packit b099d7
    
Packit b099d7
    SVErrorInfo * info = &globals.error_info;	
Packit b099d7
    info->event = sv_event;	/* No data can be passed to */
Packit b099d7
    info->stream = stream;	/* an error handler, so we */
Packit b099d7
    info->count = count;	/* have to use a global, YUCK... */
Packit b099d7
    info->entry = entry;
Packit b099d7
Packit b099d7
    old = XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w),
Packit b099d7
				    HandleToolkitErrors);
Packit b099d7
Packit b099d7
    XtVaSetValues(w, XtVaTypedArg,
Packit b099d7
		  sv_event->name, sv_event->res_type,
Packit b099d7
		  sv_event->value, sv_event->value_len,
Packit b099d7
		  NULL);
Packit b099d7
Packit b099d7
    (void)XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w), old);
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for Creating and dumping widget tree.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: 	DumpWidgets
Packit b099d7
 *	Description: Given a widget it builds a protocol packet
Packit b099d7
 *                   containing the entire widget heirarchy.
Packit b099d7
 *	Arguments: w - a widget in the tree.
Packit b099d7
 *                 event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: NULL
Packit b099d7
 */
Packit b099d7
Packit b099d7
#define TOOLKIT_TYPE ("Xt")
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
static char * 
Packit b099d7
DumpWidgets(w, event, stream)
Packit b099d7
Widget w;
Packit b099d7
EditresEvent * event;		/* UNUSED */
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    unsigned short count = 0;
Packit b099d7
        
Packit b099d7
    /* Find Tree's root. */
Packit b099d7
    for ( ; XtParent(w) != NULL; w = XtParent(w)) {}
Packit b099d7
    
Packit b099d7
    /*
Packit b099d7
     * hold space for count, overwritten later. 
Packit b099d7
     */
Packit b099d7
Packit b099d7
    _XEditResPut16(stream, (unsigned int) 0);
Packit b099d7
Packit b099d7
    DumpChildren(w, stream, &count);
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * write out toolkit type (Xt, of course...). 
Packit b099d7
     */
Packit b099d7
Packit b099d7
    _XEditResPutString8(stream, TOOLKIT_TYPE);
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Overwrite the first 2 bytes with the real count.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    *(stream->top) = count >> XER_NBBY;
Packit b099d7
    *(stream->top + 1) = count;
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: DumpChildren
Packit b099d7
 *	Description: Adds a child's name to the list.
Packit b099d7
 *	Arguments: w - the widget to dump.
Packit b099d7
 *                 stream - the stream to dump to.
Packit b099d7
 *                 count - number of dumps we have performed.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* This is a trick/kludge.  To make shared libraries happier (linking
Packit b099d7
 * against Xmu but not linking against Xt, and apparently even work
Packit b099d7
 * as we desire on SVR4, we need to avoid an explicit data reference
Packit b099d7
 * to applicationShellWidgetClass.  XtIsTopLevelShell is known
Packit b099d7
 * (implementation dependent assumption!) to use a bit flag.  So we
Packit b099d7
 * go that far.  Then, we test whether it is an applicationShellWidget
Packit b099d7
 * class by looking for an explicit class name.  Seems pretty safe.
Packit b099d7
 */
Packit b099d7
static Bool isApplicationShell(w)
Packit b099d7
    Widget w;
Packit b099d7
{
Packit b099d7
    register WidgetClass c;
Packit b099d7
Packit b099d7
    if (!XtIsTopLevelShell(w))
Packit b099d7
	return False;
Packit b099d7
    for (c = XtClass(w); c; c = c->core_class.superclass) {
Packit b099d7
	if (!strcmp(c->core_class.class_name, "ApplicationShell"))
Packit b099d7
	    return True;
Packit b099d7
    }
Packit b099d7
    return False;
Packit b099d7
}
Packit b099d7
Packit b099d7
static void
Packit b099d7
DumpChildren(w, stream, count)
Packit b099d7
Widget w;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned short *count;
Packit b099d7
{
Packit b099d7
    int i, num_children;
Packit b099d7
    Widget *children;
Packit b099d7
    unsigned long window;
Packit b099d7
    char * class;
Packit b099d7
Packit b099d7
    (*count)++;
Packit b099d7
	
Packit b099d7
    InsertWidget(stream, w);       /* Insert the widget into the stream. */
Packit b099d7
Packit b099d7
    _XEditResPutString8(stream, XtName(w)); /* Insert name */
Packit b099d7
Packit b099d7
    if (isApplicationShell(w))
Packit b099d7
	class = ((ApplicationShellWidget) w)->application.class;
Packit b099d7
    else
Packit b099d7
	class = XtClass(w)->core_class.class_name;
Packit b099d7
Packit b099d7
    _XEditResPutString8(stream, class); /* Insert class */
Packit b099d7
Packit b099d7
     if (XtIsWidget(w))
Packit b099d7
	 if (XtIsRealized(w))
Packit b099d7
	    window = XtWindow(w);
Packit b099d7
	else
Packit b099d7
	    window = EDITRES_IS_UNREALIZED;
Packit b099d7
     else
Packit b099d7
	 window = EDITRES_IS_OBJECT;
Packit b099d7
Packit b099d7
    _XEditResPut32(stream, window); /* Insert window id. */
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Find children and recurse.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    num_children = FindChildren(w, &children, TRUE, TRUE);
Packit b099d7
    for (i = 0; i < num_children; i++) 
Packit b099d7
	DumpChildren(children[i], stream, count);
Packit b099d7
Packit b099d7
    XtFree((char *)children);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for getting the geometry of widgets.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: 	DoGetGeometry
Packit b099d7
 *	Description: retrieves the Geometry of each specified widget.
Packit b099d7
 *	Arguments: w - a widget in the tree.
Packit b099d7
 *                 event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: NULL
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char *
Packit b099d7
DoGetGeometry(w, event, stream)
Packit b099d7
Widget w;
Packit b099d7
EditresEvent * event;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    unsigned i;
Packit b099d7
    char * str;
Packit b099d7
    GetGeomEvent * geom_event = (GetGeomEvent *) event;
Packit b099d7
    
Packit b099d7
    _XEditResPut16(stream, geom_event->num_entries);
Packit b099d7
Packit b099d7
    for (i = 0 ; i < geom_event->num_entries; i++) {
Packit b099d7
Packit b099d7
	/* 
Packit b099d7
	 * Send out the widget id. 
Packit b099d7
	 */
Packit b099d7
Packit b099d7
	_XEditResPutWidgetInfo(stream, &(geom_event->widgets[i]));
Packit b099d7
	if ((str = VerifyWidget(w, &(geom_event->widgets[i]))) != NULL) {
Packit b099d7
	    _XEditResPutBool(stream, True); /* an error occured. */
Packit b099d7
	    _XEditResPutString8(stream, str);	/* set message. */
Packit b099d7
	    XtFree(str);
Packit b099d7
	}
Packit b099d7
	else 
Packit b099d7
	    ExecuteGetGeometry(geom_event->widgets[i].real_widget, stream);
Packit b099d7
    }
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: ExecuteGetGeometry
Packit b099d7
 *	Description: Gets the geometry for each widget specified.
Packit b099d7
 *	Arguments: w - the widget to get geom on.
Packit b099d7
 *                 stream - stream to append to.
Packit b099d7
 *	Returns: True if no error occured.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
ExecuteGetGeometry(w, stream)
Packit b099d7
Widget w;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    int i;
Packit b099d7
    Boolean mapped_when_man;
Packit b099d7
    Dimension width, height, border_width;
Packit b099d7
    Arg args[8];
Packit b099d7
    Cardinal num_args = 0;
Packit b099d7
    Position x, y;
Packit b099d7
    
Packit b099d7
    if ( !XtIsRectObj(w) || (XtIsWidget(w) && !XtIsRealized(w)) ) {
Packit b099d7
	_XEditResPutBool(stream, False); /* no error. */
Packit b099d7
	_XEditResPutBool(stream, False); /* not visable. */
Packit b099d7
	for (i = 0; i < 5; i++) /* fill in extra space with 0's. */
Packit b099d7
	    _XEditResPut16(stream, 0);
Packit b099d7
	return;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    XtSetArg(args[num_args], XtNwidth, &width); num_args++;
Packit b099d7
    XtSetArg(args[num_args], XtNheight, &height); num_args++;
Packit b099d7
    XtSetArg(args[num_args], XtNborderWidth, &border_width); num_args++;
Packit b099d7
    XtSetArg(args[num_args], XtNmappedWhenManaged, &mapped_when_man);
Packit b099d7
    num_args++;
Packit b099d7
    XtGetValues(w, args, num_args);
Packit b099d7
Packit b099d7
    if (!(XtIsManaged(w) && mapped_when_man) && XtIsWidget(w)) {
Packit b099d7
	XWindowAttributes attrs;
Packit b099d7
	
Packit b099d7
	/* 
Packit b099d7
	 * The toolkit does not maintain mapping state, we have
Packit b099d7
	 * to go to the server.
Packit b099d7
	 */
Packit b099d7
	
Packit b099d7
	if (XGetWindowAttributes(XtDisplay(w), XtWindow(w), &attrs) != 0) {
Packit b099d7
	    if (attrs.map_state != IsViewable) {
Packit b099d7
		_XEditResPutBool(stream, False); /* no error. */
Packit b099d7
		_XEditResPutBool(stream, False); /* not visable. */
Packit b099d7
		for (i = 0; i < 5; i++) /* fill in extra space with 0's. */
Packit b099d7
		    _XEditResPut16(stream, 0);
Packit b099d7
		return;
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
	else {
Packit b099d7
	    _XEditResPut8(stream, True); /* Error occured. */
Packit b099d7
	    _XEditResPutString8(stream, "XGetWindowAttributes failed.");
Packit b099d7
	    return;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    XtTranslateCoords(w, -((int) border_width), -((int) border_width), &x, &y);
Packit b099d7
Packit b099d7
    _XEditResPutBool(stream, False); /* no error. */
Packit b099d7
    _XEditResPutBool(stream, True); /* Visable. */
Packit b099d7
    _XEditResPut16(stream, x);
Packit b099d7
    _XEditResPut16(stream, y);
Packit b099d7
    _XEditResPut16(stream, width);
Packit b099d7
    _XEditResPut16(stream, height);
Packit b099d7
    _XEditResPut16(stream, border_width);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for executing FindChild.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: PositionInChild
Packit b099d7
 *	Description: returns true if this location is in the child.
Packit b099d7
 *	Arguments: child - the child widget to check.
Packit b099d7
 *                 x, y - location of point to check in the parent's
Packit b099d7
 *                        coord space.
Packit b099d7
 *	Returns: TRUE if the position is in this child.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static Boolean
Packit b099d7
PositionInChild(child, x, y)
Packit b099d7
Widget child;
Packit b099d7
int x, y;
Packit b099d7
{
Packit b099d7
    Arg args[6];
Packit b099d7
    Cardinal num;
Packit b099d7
    Dimension width, height, border_width;
Packit b099d7
    Position child_x, child_y;
Packit b099d7
    Boolean mapped_when_managed;
Packit b099d7
Packit b099d7
    if (!XtIsRectObj(child))	/* we must at least be a rect obj. */
Packit b099d7
	return(FALSE);
Packit b099d7
Packit b099d7
    num = 0;
Packit b099d7
    XtSetArg(args[num], XtNmappedWhenManaged, &mapped_when_managed); num++;
Packit b099d7
    XtSetArg(args[num], XtNwidth, &width); num++;
Packit b099d7
    XtSetArg(args[num], XtNheight, &height); num++;
Packit b099d7
    XtSetArg(args[num], XtNx, &child_x); num++;
Packit b099d7
    XtSetArg(args[num], XtNy, &child_y); num++;
Packit b099d7
    XtSetArg(args[num], XtNborderWidth, &border_width); num++;
Packit b099d7
    XtGetValues(child, args, num);
Packit b099d7
    if (XtIsVendorShell(XtParent(child)))
Packit b099d7
    {
Packit b099d7
    	child_x = -border_width;
Packit b099d7
    	child_y = -border_width;
Packit b099d7
    }
Packit b099d7
 
Packit b099d7
    /*
Packit b099d7
     * The only way we will know of the widget is mapped is to see if
Packit b099d7
     * mapped when managed is True and this is a managed child.  Otherwise
Packit b099d7
     * we will have to ask the server if this window is mapped.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    if (XtIsWidget(child) && !(mapped_when_managed && XtIsManaged(child)) ) {
Packit b099d7
	XWindowAttributes attrs;
Packit b099d7
Packit b099d7
	if (XtIsRealized(child))
Packit b099d7
	{
Packit b099d7
	    if (XGetWindowAttributes(XtDisplay(child), 
Packit b099d7
				     XtWindow(child), &attrs) != 0) {
Packit b099d7
		/* oops */
Packit b099d7
	    }
Packit b099d7
	    else if (attrs.map_state != IsViewable)
Packit b099d7
		return(FALSE);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return (x >= child_x) &&
Packit b099d7
	   (x <= (child_x + (Position)width + 2 * (Position)border_width)) &&
Packit b099d7
	   (y >= child_y) &&
Packit b099d7
	   (y <= (child_y + (Position)height + 2 * (Position)border_width));
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _FindChild
Packit b099d7
 *	Description: Finds the child that actually contatians the point shown.
Packit b099d7
 *	Arguments: parent - a widget that is known to contain the point
Packit b099d7
 *                 	    specified.
Packit b099d7
 *                 x, y - The point in coordinates relative to the 
Packit b099d7
 *                        widget specified.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static Widget 
Packit b099d7
_FindChild(parent, x, y)
Packit b099d7
Widget parent;
Packit b099d7
int x, y;
Packit b099d7
{
Packit b099d7
    Widget * children;
Packit b099d7
    int i = FindChildren(parent, &children, TRUE, FALSE);
Packit b099d7
Packit b099d7
    while (i > 0) {
Packit b099d7
	i--;
Packit b099d7
Packit b099d7
	if (PositionInChild(children[i], x, y)) {
Packit b099d7
	    Widget child = children[i];
Packit b099d7
	    
Packit b099d7
	    XtFree((char *)children);
Packit b099d7
	    return(_FindChild(child, x - child->core.x, y - child->core.y));
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    XtFree((char *)children);
Packit b099d7
    return(parent);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: DoFindChild
Packit b099d7
 *	Description: finds the child that contains the location specified.
Packit b099d7
 *	Arguments: w - a widget in the tree.
Packit b099d7
 *                 event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: an allocated error message if something went horribly
Packit b099d7
 *               wrong and no set values were performed, else NULL.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char *
Packit b099d7
DoFindChild(w, event, stream)
Packit b099d7
Widget w;
Packit b099d7
EditresEvent * event;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    char * str;
Packit b099d7
    Widget parent, child;
Packit b099d7
    Position parent_x, parent_y;
Packit b099d7
    FindChildEvent * find_event = (FindChildEvent *) event;
Packit b099d7
    
Packit b099d7
    if ((str = VerifyWidget(w, find_event->widgets)) != NULL) 
Packit b099d7
	return(str);
Packit b099d7
Packit b099d7
    parent = find_event->widgets->real_widget;
Packit b099d7
Packit b099d7
    XtTranslateCoords(parent, (Position) 0, (Position) 0,
Packit b099d7
		      &parent_x, &parent_y);
Packit b099d7
    
Packit b099d7
    child = _FindChild(parent, find_event->x - (int) parent_x,
Packit b099d7
		       find_event->y - (int) parent_y);
Packit b099d7
Packit b099d7
    InsertWidget(stream, child);
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Procedures for performing GetResources.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: DoGetResources
Packit b099d7
 *	Description: Gets the Resources associated with the widgets passed.
Packit b099d7
 *	Arguments: w - a widget in the tree.
Packit b099d7
 *                 event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: NULL
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char *
Packit b099d7
DoGetResources(w, event, stream)
Packit b099d7
Widget w;
Packit b099d7
EditresEvent * event;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    unsigned int i;
Packit b099d7
    char * str;
Packit b099d7
    GetResEvent * res_event = (GetResEvent *) event;
Packit b099d7
    
Packit b099d7
    _XEditResPut16(stream, res_event->num_entries); /* number of replys */
Packit b099d7
Packit b099d7
    for (i = 0 ; i < res_event->num_entries; i++) {
Packit b099d7
	/* 
Packit b099d7
	 * Send out the widget id. 
Packit b099d7
	 */
Packit b099d7
	_XEditResPutWidgetInfo(stream, &(res_event->widgets[i]));
Packit b099d7
	if ((str = VerifyWidget(w, &(res_event->widgets[i]))) != NULL) {
Packit b099d7
	    _XEditResPutBool(stream, True); /* an error occured. */
Packit b099d7
	    _XEditResPutString8(stream, str);	/* set message. */
Packit b099d7
	    XtFree(str);
Packit b099d7
	}
Packit b099d7
	else {
Packit b099d7
	    _XEditResPutBool(stream, False); /* no error occured. */
Packit b099d7
	    ExecuteGetResources(res_event->widgets[i].real_widget,
Packit b099d7
				stream);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: ExecuteGetResources.
Packit b099d7
 *	Description: Gets the resources for any individual widget.
Packit b099d7
 *	Arguments: w - the widget to get resources on.
Packit b099d7
 *                 stream - the protocol stream.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
ExecuteGetResources(w, stream)
Packit b099d7
Widget w;
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    XtResourceList norm_list, cons_list;
Packit b099d7
    Cardinal num_norm, num_cons;
Packit b099d7
    register int i;
Packit b099d7
Packit b099d7
    /* 
Packit b099d7
     * Get Normal Resources. 
Packit b099d7
     */
Packit b099d7
Packit b099d7
    XtGetResourceList(XtClass(w), &norm_list, &num_norm);
Packit b099d7
Packit b099d7
    if (XtParent(w) != NULL) 
Packit b099d7
	XtGetConstraintResourceList(XtClass(XtParent(w)),&cons_list,&num_cons);
Packit b099d7
    else
Packit b099d7
	num_cons = 0;
Packit b099d7
Packit b099d7
    _XEditResPut16(stream, num_norm + num_cons); /* how many resources. */
Packit b099d7
    
Packit b099d7
    /*
Packit b099d7
     * Insert all the normal resources.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    for ( i = 0; i < (int) num_norm; i++) {
Packit b099d7
	_XEditResPutResourceType(stream, NormalResource);
Packit b099d7
	_XEditResPutString8(stream, norm_list[i].resource_name);
Packit b099d7
	_XEditResPutString8(stream, norm_list[i].resource_class);
Packit b099d7
	_XEditResPutString8(stream, norm_list[i].resource_type);
Packit b099d7
    }
Packit b099d7
    XtFree((char *) norm_list);
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Insert all the constraint resources.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    if (num_cons > 0) {
Packit b099d7
	for ( i = 0; i < (int) num_cons; i++) {
Packit b099d7
	    _XEditResPutResourceType(stream, ConstraintResource);
Packit b099d7
	    _XEditResPutString8(stream, cons_list[i].resource_name);
Packit b099d7
	    _XEditResPutString8(stream, cons_list[i].resource_class);
Packit b099d7
	    _XEditResPutString8(stream, cons_list[i].resource_type);
Packit b099d7
	}
Packit b099d7
	XtFree((char *) cons_list);
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
static void
Packit b099d7
EditResCvtWarningHandler(String name,
Packit b099d7
				 String type,
Packit b099d7
				 String class,
Packit b099d7
				 String def,
Packit b099d7
				 String *params,
Packit b099d7
				 Cardinal *num_params)
Packit b099d7
{
Packit b099d7
    /* just ignore the warning */
Packit b099d7
    return;
Packit b099d7
}
Packit b099d7
Packit b099d7
static void
Packit b099d7
_XtGetStringValues(Widget w, Arg *warg, int numargs)
Packit b099d7
{
Packit b099d7
    XtResourceList res_list;
Packit b099d7
    Cardinal num_res;
Packit b099d7
    XtResource *res = NULL;
Packit b099d7
    long value;
Packit b099d7
    int size, i;
Packit b099d7
    char *string = "";
Packit b099d7
    char *buffer;
Packit b099d7
    Arg args[1];
Packit b099d7
    XrmValue to, from, to_color;
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Look for the resource.
Packit b099d7
     */
Packit b099d7
    XtGetResourceList(XtClass(w), &res_list, &num_res);
Packit b099d7
    for (i = 0; i < (int)num_res && res == NULL; i++)
Packit b099d7
    {
Packit b099d7
	if (0 == strcmp(res_list[i].resource_name, warg->name))
Packit b099d7
	    res = &res_list[i];
Packit b099d7
    }
Packit b099d7
    if (res == NULL && XtParent(w) != NULL)
Packit b099d7
    {
Packit b099d7
	XtFree((char *)res_list);
Packit b099d7
	XtGetConstraintResourceList(XtClass(XtParent(w)), &res_list, &num_res);
Packit b099d7
    }
Packit b099d7
    for (i = 0; i < (int)num_res && res == NULL; i++)
Packit b099d7
    {
Packit b099d7
	if (0 == strcmp(res_list[i].resource_name, warg->name))
Packit b099d7
	    res = &res_list[i];
Packit b099d7
    }
Packit b099d7
Packit b099d7
    if (res == NULL)
Packit b099d7
    {
Packit b099d7
	/* Couldn't find resource */
Packit b099d7
Packit b099d7
	XtFree((char *)res_list);
Packit b099d7
	*(XtPointer *)(warg->value) = NULL;
Packit b099d7
	return;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    size = res->resource_size;
Packit b099d7
    buffer = *(char **)(warg->value);
Packit b099d7
Packit b099d7
Packit b099d7
    /* try to get the value in the proper size */
Packit b099d7
    switch (res->resource_size)
Packit b099d7
    {
Packit b099d7
#if (LONG_BIT == 64)
Packit b099d7
	long v8;
Packit b099d7
#endif
Packit b099d7
	int v4;
Packit b099d7
	short v2;
Packit b099d7
	char v1;
Packit b099d7
Packit b099d7
    case 1:
Packit b099d7
	XtSetArg(args[0], res->resource_name, &v1;;
Packit b099d7
	XtGetValues(w, args, 1);
Packit b099d7
	value = (int)v1;
Packit b099d7
	break;
Packit b099d7
    case 2:
Packit b099d7
	XtSetArg(args[0], res->resource_name, &v2;;
Packit b099d7
	XtGetValues(w, args, 1);
Packit b099d7
	value = (int)v2;
Packit b099d7
	break;
Packit b099d7
    case 4:
Packit b099d7
	XtSetArg(args[0], res->resource_name, &v4;;
Packit b099d7
	XtGetValues(w, args, 1);
Packit b099d7
	value = (int)v4;
Packit b099d7
	break;
Packit b099d7
#if (LONG_BIT == 64)
Packit b099d7
    case 8:
Packit b099d7
	XtSetArg(args[0], res->resource_name, &v8;;
Packit b099d7
	XtGetValues(w, args, 1);
Packit b099d7
	value = (long)v8;
Packit b099d7
	break;
Packit b099d7
#endif
Packit b099d7
    default:
Packit b099d7
	fprintf(stderr, "_XtGetStringValues: bad size %d\n",
Packit b099d7
		res->resource_size);
Packit b099d7
	string = "bad size";
Packit b099d7
	goto done;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * If the resource is already String, no conversion needed.
Packit b099d7
     */
Packit b099d7
    if (strcmp(XtRString, res->resource_type) == 0)
Packit b099d7
    {
Packit b099d7
	if (value == 0)
Packit b099d7
	    string = "(null)";
Packit b099d7
	else
Packit b099d7
	    string = (char *)value;
Packit b099d7
    }
Packit b099d7
    else
Packit b099d7
    {
Packit b099d7
	XtErrorMsgHandler old_handler;
Packit b099d7
Packit b099d7
	/*
Packit b099d7
	 * Ignore conversion warnings.
Packit b099d7
	 */
Packit b099d7
	old_handler = XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w),
Packit b099d7
					     EditResCvtWarningHandler);
Packit b099d7
	from.size = res->resource_size;
Packit b099d7
	from.addr = (caddr_t)&value;
Packit b099d7
	to.addr = NULL;
Packit b099d7
	to.size = 0;
Packit b099d7
	to_color.addr = NULL;
Packit b099d7
	to_color.size = 0;
Packit b099d7
	/*
Packit b099d7
	 * Special case for type Pixel.
Packit b099d7
	 */
Packit b099d7
	if (0 == strcmp(res->resource_type, XtRPixel)
Packit b099d7
	    && XtConvertAndStore(w, XtRPixel, &from, XtRColor, &to)
Packit b099d7
	    && XtConvertAndStore(w, XtRColor, &to, XtRString, &to_color))
Packit b099d7
	{
Packit b099d7
	    string = to_color.addr;
Packit b099d7
	}
Packit b099d7
	else if (XtConvertAndStore(w, res->resource_type,
Packit b099d7
				   &from, XtRString, &to))
Packit b099d7
	{
Packit b099d7
	    string = to.addr;
Packit b099d7
	}
Packit b099d7
	else
Packit b099d7
	{
Packit b099d7
	    /* 
Packit b099d7
	     * Conversion failed, fall back to representing it as integer.
Packit b099d7
	     */
Packit b099d7
	    switch (res->resource_size)
Packit b099d7
	    {
Packit b099d7
		case sizeof(char):
Packit b099d7
		  sprintf(buffer, "%d", (unsigned char)value);
Packit b099d7
		string = buffer;
Packit b099d7
		break;
Packit b099d7
		case sizeof(short):
Packit b099d7
		  sprintf(buffer, "%d", (short)value);
Packit b099d7
		string = buffer;
Packit b099d7
		break;
Packit b099d7
		case sizeof(int):
Packit b099d7
		  sprintf(buffer, "%d", (int)value);
Packit b099d7
		string = buffer;
Packit b099d7
		break;
Packit b099d7
#if (LONG_BIT == 64)
Packit b099d7
		case sizeof(long):
Packit b099d7
		  sprintf(buffer, "%ld", value);
Packit b099d7
		string = buffer;
Packit b099d7
		break;
Packit b099d7
#endif
Packit b099d7
	    default:
Packit b099d7
		break;
Packit b099d7
	    }
Packit b099d7
	    /*
Packit b099d7
	    strcat(buffer, " (integer fallback conversion)");
Packit b099d7
	    */
Packit b099d7
	    sprintf(&buffer[strlen(buffer)], " (%s)", res->resource_type);
Packit b099d7
	}
Packit b099d7
	/*
Packit b099d7
	 * Restore original warning handler.
Packit b099d7
	 */
Packit b099d7
	XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w), old_handler);
Packit b099d7
    }
Packit b099d7
Packit b099d7
Packit b099d7
    if (string == NULL)
Packit b099d7
    {
Packit b099d7
	/* can't happen */
Packit b099d7
#ifdef DEBUG
Packit b099d7
	fprintf(stderr, "_LesstifEditResPutValueString8: couldn't convert to string\n");
Packit b099d7
	fprintf(stderr, "Class = %s Type = %s Name = %s\n", res->resource_type,
Packit b099d7
		res->resource_name, res->resource_class);
Packit b099d7
#endif
Packit b099d7
	string = "";
Packit b099d7
    }
Packit b099d7
  done:
Packit b099d7
    *((char **)(warg->value)) = string;
Packit b099d7
#ifdef DEBUG
Packit b099d7
    fprintf(stderr, "put %s at %#x\n", string, stream->current);
Packit b099d7
#endif
Packit b099d7
Packit b099d7
    XtFree((char *)res_list);
Packit b099d7
}
Packit b099d7
/*
Packit b099d7
 *	Function Name: DumpValues
Packit b099d7
 *	Description: Returns resource values to the resource editor.
Packit b099d7
 *	Arguments: event - the event that caused this action.
Packit b099d7
 *                 stream - the protocol stream to add.
Packit b099d7
 *	Returns: NULL
Packit b099d7
 */
Packit b099d7
Packit b099d7
static char*
Packit b099d7
DumpValues(w, event, stream)	/* ARGSUSED */
Packit b099d7
Widget w;
Packit b099d7
EditresEvent* event; 
Packit b099d7
ProtocolStream* stream;
Packit b099d7
{
Packit b099d7
  Arg warg[1];
Packit b099d7
  String res_value = NULL;
Packit b099d7
  GetValuesEvent * gv_event = (GetValuesEvent *)event; 
Packit b099d7
  char buffer[64], *str;
Packit b099d7
Packit b099d7
  res_value = buffer;
Packit b099d7
Packit b099d7
  /* put the count in the stream. */
Packit b099d7
Packit b099d7
  _XEditResPut16(stream, (unsigned int) 1); 
Packit b099d7
Packit b099d7
  /* get the resource of the widget asked for by the */
Packit b099d7
  /* resource editor and insert it into the stream */
Packit b099d7
  XtSetArg(warg[0], gv_event->name, &res_value);
Packit b099d7
    if ((str = VerifyWidget(w, &(gv_event->widgets[0]))) != NULL)
Packit b099d7
    {
Packit b099d7
	_XEditResPutString8(stream, str);
Packit b099d7
	XtFree(str);
Packit b099d7
    }
Packit b099d7
    else
Packit b099d7
    {
Packit b099d7
	_XtGetStringValues(gv_event->widgets[0].real_widget, warg, 1);
Packit b099d7
	if (!res_value) res_value = "NoValue";
Packit b099d7
	_XEditResPutString8(stream, res_value);
Packit b099d7
    }
Packit b099d7
  return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for inserting values into the protocol stream.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: InsertWidget
Packit b099d7
 *	Description: Inserts the full parent heirarchy of this
Packit b099d7
 *                   widget into the protocol stream as a widget list.
Packit b099d7
 *	Arguments: stream - the protocol stream.
Packit b099d7
 *                 w - the widget to insert.
Packit b099d7
 *	Returns: none
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
InsertWidget(stream, w)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
Widget w;
Packit b099d7
{
Packit b099d7
    Widget temp;
Packit b099d7
    unsigned long * widget_list;
Packit b099d7
    register int i, num_widgets;
Packit b099d7
Packit b099d7
    for (temp = w, i = 0; temp != 0; temp = XtParent(temp), i++) {}
Packit b099d7
Packit b099d7
    num_widgets = i;
Packit b099d7
    widget_list = (unsigned long *) 
Packit b099d7
	                XtMalloc(sizeof(unsigned long) * num_widgets);
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Put the widgets into the list.
Packit b099d7
     * make sure that they are inserted in the list from parent -> child.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    for (i--, temp = w; temp != NULL; temp = XtParent(temp), i--) 
Packit b099d7
	widget_list[i] = (unsigned long) temp;
Packit b099d7
	
Packit b099d7
    _XEditResPut16(stream, num_widgets);	/* insert number of widgets. */
Packit b099d7
    for (i = 0; i < num_widgets; i++) /* insert Widgets themselves. */
Packit b099d7
	_XEditResPut32(stream, widget_list[i]);
Packit b099d7
    
Packit b099d7
    XtFree((char *)widget_list);
Packit b099d7
}
Packit b099d7
Packit b099d7
#if 0
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * All of the following routines are public.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResPutString8
Packit b099d7
 *	Description: Inserts a string into the protocol stream.
Packit b099d7
 *	Arguments: stream - stream to insert string into.
Packit b099d7
 *                 str - string to insert.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResPutString8(stream, str)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
char * str;
Packit b099d7
{
Packit b099d7
    int i, len = strlen(str);
Packit b099d7
Packit b099d7
    _XEditResPut16(stream, len);
Packit b099d7
    for (i = 0 ; i < len ; i++, str++)
Packit b099d7
	_XEditResPut8(stream, *str);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResPut8
Packit b099d7
 *	Description: Inserts an 8 bit integer into the protocol stream.
Packit b099d7
 *	Arguments: stream - stream to insert string into.
Packit b099d7
 *                 value - value to insert.
Packit b099d7
 *	Returns: none
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResPut8(stream, value)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned int value;
Packit b099d7
{
Packit b099d7
    unsigned char temp;
Packit b099d7
Packit b099d7
    if (stream->size >= stream->alloc) {
Packit b099d7
	stream->alloc += 100;
Packit b099d7
	stream->real_top = (unsigned char *) XtRealloc(
Packit b099d7
						  (char *)stream->real_top,
Packit b099d7
						  stream->alloc + HEADER_SIZE);
Packit b099d7
	stream->top = stream->real_top + HEADER_SIZE;
Packit b099d7
	stream->current = stream->top + stream->size;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    temp = (unsigned char) (value & BYTE_MASK);
Packit b099d7
    *((stream->current)++) = temp;
Packit b099d7
    (stream->size)++;
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResPut16
Packit b099d7
 *	Description: Inserts a 16 bit integer into the protocol stream.
Packit b099d7
 *	Arguments: stream - stream to insert string into.
Packit b099d7
 *                 value - value to insert.
Packit b099d7
 *	Returns: void
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResPut16(stream, value)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned int value;
Packit b099d7
{
Packit b099d7
    _XEditResPut8(stream, (value >> XER_NBBY) & BYTE_MASK);
Packit b099d7
    _XEditResPut8(stream, value & BYTE_MASK);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResPut32
Packit b099d7
 *	Description: Inserts a 32 bit integer into the protocol stream.
Packit b099d7
 *	Arguments: stream - stream to insert string into.
Packit b099d7
 *                 value - value to insert.
Packit b099d7
 *	Returns: void
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResPut32(stream, value)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned long value;
Packit b099d7
{
Packit b099d7
    int i;
Packit b099d7
Packit b099d7
    for (i = 3; i >= 0; i--) 
Packit b099d7
	_XEditResPut8(stream, (value >> (XER_NBBY*i)) & BYTE_MASK);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResPutWidgetInfo
Packit b099d7
 *	Description: Inserts the widget info into the protocol stream.
Packit b099d7
 *	Arguments: stream - stream to insert widget info into.
Packit b099d7
 *                 info - info to insert.
Packit b099d7
 *	Returns: none
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResPutWidgetInfo(stream, info)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
WidgetInfo * info;
Packit b099d7
{
Packit b099d7
    unsigned int i;
Packit b099d7
Packit b099d7
    _XEditResPut16(stream, info->num_widgets);
Packit b099d7
    for (i = 0; i < info->num_widgets; i++) 
Packit b099d7
	_XEditResPut32(stream, info->ids[i]);
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for retrieving values from the protocol stream.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
    
Packit b099d7
/*	Function Name: _XEditResResetStream
Packit b099d7
 *	Description: resets the protocol stream
Packit b099d7
 *	Arguments: stream - the stream to reset.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
void
Packit b099d7
_XEditResResetStream(stream)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
{
Packit b099d7
    stream->current = stream->top;
Packit b099d7
    stream->size = 0;
Packit b099d7
    if (stream->real_top == NULL) {
Packit b099d7
	stream->real_top = (unsigned char *) XtRealloc(
Packit b099d7
						  (char *)stream->real_top,
Packit b099d7
						  stream->alloc + HEADER_SIZE);
Packit b099d7
	stream->top = stream->real_top + HEADER_SIZE;
Packit b099d7
	stream->current = stream->top + stream->size;
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE 
Packit b099d7
 *
Packit b099d7
 * The only modified field if the "current" field.
Packit b099d7
 *
Packit b099d7
 * The only fields that must be set correctly are the "current", "top"
Packit b099d7
 * and "size" fields.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGetg8
Packit b099d7
 *	Description: Retrieves an unsigned 8 bit value
Packit b099d7
 *                   from the protocol stream.
Packit b099d7
 *	Arguments: stream.
Packit b099d7
 *                 val - a pointer to value to return.
Packit b099d7
 *	Returns: TRUE if sucessful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGet8(stream, val)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned char * val;
Packit b099d7
{
Packit b099d7
    if (stream->size < (stream->current - stream->top)) 
Packit b099d7
	return(FALSE);
Packit b099d7
Packit b099d7
    *val = *((stream->current)++);
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGet16
Packit b099d7
 *	Description: Retrieves an unsigned 16 bit value
Packit b099d7
 *                   from the protocol stream.
Packit b099d7
 *	Arguments: stream.
Packit b099d7
 *                 val - a pointer to value to return.
Packit b099d7
 *	Returns: TRUE if sucessful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGet16(stream, val)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned short * val;
Packit b099d7
{
Packit b099d7
    unsigned char temp1, temp2;
Packit b099d7
Packit b099d7
    if ( !(_XEditResGet8(stream, &temp1) && _XEditResGet8(stream, &temp2)) )
Packit b099d7
	return(FALSE);
Packit b099d7
    
Packit b099d7
    *val = (((unsigned short) temp1 << XER_NBBY) + ((unsigned short) temp2));
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGetSigned16
Packit b099d7
 *	Description: Retrieves an signed 16 bit value from the protocol stream.
Packit b099d7
 *	Arguments: stream.
Packit b099d7
 *                 val - a pointer to value to return.
Packit b099d7
 *	Returns: TRUE if sucessful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGetSigned16(stream, val)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
short * val;
Packit b099d7
{
Packit b099d7
    unsigned char temp1, temp2;
Packit b099d7
Packit b099d7
    if ( !(_XEditResGet8(stream, &temp1) && _XEditResGet8(stream, &temp2)) )
Packit b099d7
	return(FALSE);
Packit b099d7
    
Packit b099d7
    if (temp1 & (1 << (XER_NBBY - 1))) { /* If the sign bit is active. */
Packit b099d7
	*val = -1;		 /* store all 1's */
Packit b099d7
	*val &= (temp1 << XER_NBBY); /* Now and in the MSB */
Packit b099d7
	*val &= temp2;		 /* and LSB */
Packit b099d7
    }
Packit b099d7
    else 
Packit b099d7
	*val = (((unsigned short) temp1 << XER_NBBY) + ((unsigned short) temp2));
Packit b099d7
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGet32
Packit b099d7
 *	Description: Retrieves an unsigned 32 bit value
Packit b099d7
 *                   from the protocol stream.
Packit b099d7
 *	Arguments: stream.
Packit b099d7
 *                 val - a pointer to value to return.
Packit b099d7
 *	Returns: TRUE if sucessful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGet32(stream, val)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
unsigned long * val;
Packit b099d7
{
Packit b099d7
    unsigned short temp1, temp2;
Packit b099d7
Packit b099d7
    if ( !(_XEditResGet16(stream, &temp1) && _XEditResGet16(stream, &temp2)) )
Packit b099d7
	return(FALSE);
Packit b099d7
    
Packit b099d7
    *val = (((unsigned short) temp1 << (XER_NBBY * 2)) + 
Packit b099d7
	    ((unsigned short) temp2));
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGetString8
Packit b099d7
 *	Description: Retrieves an 8 bit string value from the protocol stream.
Packit b099d7
 *	Arguments: stream - the protocol stream
Packit b099d7
 *                 str - the string to retrieve.
Packit b099d7
 *	Returns: True if retrieval was successful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGetString8(stream, str)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
char ** str;
Packit b099d7
{
Packit b099d7
    unsigned short len;
Packit b099d7
    register unsigned i;
Packit b099d7
Packit b099d7
    if (!_XEditResGet16(stream, &len)) {
Packit b099d7
	return(FALSE);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    *str = XtMalloc(sizeof(char) * (len + 1));
Packit b099d7
Packit b099d7
    for (i = 0; i < len; i++) {
Packit b099d7
	if (!_XEditResGet8(stream, (unsigned char *) *str + i)) {
Packit b099d7
	    XtFree(*str);
Packit b099d7
	    *str = NULL;
Packit b099d7
	    return(FALSE);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
    (*str)[i] = '\0';		/* NULL terminate that sucker. */
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _XEditResGetWidgetInfo
Packit b099d7
 *	Description: Retrieves the list of widgets that follow and stores
Packit b099d7
 *                   them in the widget info structure provided.
Packit b099d7
 *	Arguments: stream - the protocol stream
Packit b099d7
 *                 info - the widget info struct to store into.
Packit b099d7
 *	Returns: True if retrieval was successful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_XEditResGetWidgetInfo(stream, info)
Packit b099d7
ProtocolStream * stream;
Packit b099d7
WidgetInfo * info;
Packit b099d7
{
Packit b099d7
    unsigned int i;
Packit b099d7
Packit b099d7
    if (!_XEditResGet16(stream, &(info->num_widgets))) 
Packit b099d7
	return(FALSE);
Packit b099d7
Packit b099d7
    info->ids = (unsigned long *) XtMalloc(sizeof(long) * (info->num_widgets));
Packit b099d7
Packit b099d7
    for (i = 0; i < info->num_widgets; i++) {
Packit b099d7
	if (!_XEditResGet32(stream, info->ids + i)) {
Packit b099d7
	    XtFree((char *)info->ids);
Packit b099d7
	    info->ids = NULL;
Packit b099d7
	    return(FALSE);
Packit b099d7
	}
Packit b099d7
#if defined(LONG64) || defined(WORD64)
Packit b099d7
	info->ids[i] |= globals.base_address;
Packit b099d7
#endif
Packit b099d7
    }
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
#endif
Packit b099d7
	    
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 * Code for Loading the EditresBlock resource.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: CvStringToBlock
Packit b099d7
 *	Description: Converts a string to an editres block value.
Packit b099d7
 *	Arguments: dpy - the display.
Packit b099d7
 *                 args, num_args - **UNUSED **
Packit b099d7
 *                 from_val, to_val - value to convert, and where to put result
Packit b099d7
 *                 converter_data - ** UNUSED **
Packit b099d7
 *	Returns: TRUE if conversion was sucessful.
Packit b099d7
 */
Packit b099d7
Packit b099d7
/* ARGSUSED */
Packit b099d7
static Boolean
Packit b099d7
CvtStringToBlock(dpy, args, num_args, from_val, to_val, converter_data)
Packit b099d7
Display * dpy;
Packit b099d7
XrmValue * args;
Packit b099d7
Cardinal * num_args;
Packit b099d7
XrmValue * from_val, * to_val;
Packit b099d7
XtPointer * converter_data;
Packit b099d7
{
Packit b099d7
    char ptr[BUFSIZ];
Packit b099d7
    static EditresBlock block;
Packit b099d7
#ifndef HAVE_XMU_N_COPY_ISO
Packit b099d7
     _XmNCopyISOLatin1Lowered(ptr, from_val->addr, sizeof(ptr));
Packit b099d7
#else
Packit b099d7
    XmuNCopyISOLatin1Lowered(ptr, from_val->addr, sizeof(ptr));
Packit b099d7
#endif
Packit b099d7
    if (streq(ptr, "none")) 
Packit b099d7
	block = BlockNone;
Packit b099d7
    else if (streq(ptr, "setvalues")) 
Packit b099d7
	block = BlockSetValues;
Packit b099d7
    else if (streq(ptr, "all")) 
Packit b099d7
	block = BlockAll;
Packit b099d7
    else {
Packit b099d7
	Cardinal num_params = 1;
Packit b099d7
	String params[1];
Packit b099d7
Packit b099d7
	params[0] = from_val->addr;
Packit b099d7
	XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
Packit b099d7
			"CvtStringToBlock", "unknownValue", "EditresError",
Packit b099d7
			"Could not convert string \"%s\" to EditresBlock.",
Packit b099d7
			params, &num_params);
Packit b099d7
	return(FALSE);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    if (to_val->addr != NULL) {
Packit b099d7
	if (to_val->size < sizeof(EditresBlock)) {
Packit b099d7
	    to_val->size = sizeof(EditresBlock);
Packit b099d7
	    return(FALSE);
Packit b099d7
	}
Packit b099d7
	*(EditresBlock *)(to_val->addr) = block;
Packit b099d7
    }
Packit b099d7
    else 
Packit b099d7
	to_val->addr = (XtPointer) block;
Packit b099d7
Packit b099d7
    to_val->size = sizeof(EditresBlock);
Packit b099d7
    return(TRUE);
Packit b099d7
}
Packit b099d7
    
Packit b099d7
#define XtREditresBlock ("EditresBlock")
Packit b099d7
Packit b099d7
/*	Function Name: LoadResources
Packit b099d7
 *	Description: Loads a global resource the determines of this
Packit b099d7
 *                   application should allow Editres requests.
Packit b099d7
 *	Arguments: w - any widget in the tree.
Packit b099d7
 *	Returns: none.
Packit b099d7
 */
Packit b099d7
Packit b099d7
static void
Packit b099d7
LoadResources(w)
Packit b099d7
Widget w;
Packit b099d7
{
Packit b099d7
    static XtResource resources[] = {
Packit b099d7
        {"editresBlock", "EditresBlock", XtREditresBlock, sizeof(EditresBlock),
Packit b099d7
	 XtOffsetOf(Globals, block), XtRImmediate, (XtPointer) BlockNone}
Packit b099d7
    };
Packit b099d7
Packit b099d7
    for (; XtParent(w) != NULL; w = XtParent(w)) {} 
Packit b099d7
Packit b099d7
    XtAppSetTypeConverter(XtWidgetToApplicationContext(w),
Packit b099d7
			  XtRString, XtREditresBlock, CvtStringToBlock,
Packit b099d7
			  NULL, (Cardinal) 0, XtCacheAll, NULL);
Packit b099d7
Packit b099d7
    XtGetApplicationResources( w, (XtPointer) &globals, resources,
Packit b099d7
			      XtNumber(resources), NULL, (Cardinal) 0);
Packit b099d7
}
Packit b099d7
Packit b099d7