Blame lib/Mrm/Mrmwrefs.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 */ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
 */ 
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: Mrmwrefs.c /main/14 1996/11/13 14:07:43 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
Packit b099d7
/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *  FACILITY:
Packit b099d7
 *
Packit b099d7
 *      UIL Resource Manager (URM):
Packit b099d7
 *
Packit b099d7
 *  ABSTRACT:
Packit b099d7
 *
Packit b099d7
 *	This module contains all routines which manage references to
Packit b099d7
 *	widgets which must be handled during or immediately after
Packit b099d7
 *	widget creation.
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  INCLUDE FILES
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include <stdio.h>
Packit b099d7
#include <Mrm/MrmAppl.h>
Packit b099d7
#include <Mrm/Mrm.h>
Packit b099d7
#include "MrmMsgI.h"
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	routine acquires a resource context, and initializes
Packit b099d7
 *	it for use a a widget reference structure.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	wref_id		to return pointer to initialized context
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *      See UrmGetResourceContext
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Urm__CW_InitWRef (URMResourceContextPtr		*wref_id)
Packit b099d7
{
Packit b099d7
  Cardinal		result;		/* function results */
Packit b099d7
  URMWRefStructPtr	refdsc;		/* buffer as reference structure */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Acquire and initialize resource context
Packit b099d7
   */
Packit b099d7
  result = UrmGetResourceContext ((char *(*)())NULL,(void(*)())NULL, 
Packit b099d7
				  500, wref_id);
Packit b099d7
  if ( result != MrmSUCCESS ) return result;
Packit b099d7
Packit b099d7
  refdsc = (URMWRefStructPtr) UrmRCBuffer (*wref_id);
Packit b099d7
  refdsc->num_refs = 0;
Packit b099d7
  refdsc->heap_size = 0;
Packit b099d7
Packit b099d7
  return MrmSUCCESS;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine adds a widget definition to the widget reference structure
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	wref_id		widget reference structure
Packit b099d7
 *	w_name		name of the widget to enter
Packit b099d7
 *	w_id		widget id
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *      See UrmResizeResourceContext
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Urm__CW_AddWRef (URMResourceContextPtr	wref_id,
Packit b099d7
		 String			w_name,
Packit b099d7
		 Widget			w_id)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result;		/* function results */
Packit b099d7
  URMWRefStructPtr	refdsc;		/* buffer as reference structure */
Packit b099d7
  MrmCount		name_bytes;	/* # bytes for name & NULL */
Packit b099d7
  MrmCount		bytes_needed;	/* # bytes for whole ref */
Packit b099d7
  Cardinal		ndx;		/* entry index in structure */
Packit b099d7
  MrmOffset		new_offs;	/* new offset in heap */
Packit b099d7
  Cardinal		old_size;	/* old buffer size */
Packit b099d7
  Cardinal		new_size;	/* new buffer size */
Packit b099d7
  Cardinal		delta;		/* difference in size */
Packit b099d7
  char			*old_heap;	/* old heap address */
Packit b099d7
  char			*new_heap;	/* new heap address */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Set up pointers. Compute size needed and available, and resize structure
Packit b099d7
   * if required. Name need not be entered if it is compiler-generated
Packit b099d7
   * (contains non-legal character '-')
Packit b099d7
   */
Packit b099d7
  refdsc = (URMWRefStructPtr) UrmRCBuffer (wref_id);
Packit b099d7
  name_bytes = strlen(w_name);
Packit b099d7
  for ( ndx=0 ; ndx
Packit b099d7
    if ( w_name[ndx] == '-' ) return MrmFAILURE;
Packit b099d7
  name_bytes += 1;
Packit b099d7
Packit b099d7
  bytes_needed = sizeof(URMWRef) + name_bytes;
Packit b099d7
  bytes_needed = _FULLWORD(bytes_needed);
Packit b099d7
  if ( bytes_needed > (UrmRCBufSize(wref_id)-UrmWRefBytesUsed(refdsc)) )
Packit b099d7
    {
Packit b099d7
      old_size = UrmRCBufSize (wref_id);
Packit b099d7
      new_size = 2 * old_size;
Packit b099d7
      delta = new_size - old_size;
Packit b099d7
      result = UrmResizeResourceContext (wref_id, new_size);
Packit b099d7
      if ( result != MrmSUCCESS ) return result;
Packit b099d7
      refdsc = (URMWRefStructPtr) UrmRCBuffer (wref_id);
Packit b099d7
      old_heap = (char *) refdsc+old_size-refdsc->heap_size;
Packit b099d7
      new_heap = (char *) (old_heap+delta);
Packit b099d7
      UrmBCopy (old_heap, new_heap, refdsc->heap_size);
Packit b099d7
      for ( ndx=0 ; ndx<refdsc->num_refs ; ndx++ )
Packit b099d7
	refdsc->refs[ndx].w_name_offs += delta;
Packit b099d7
    }
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * There is enough space. Copy in the name, and set up the descriptor.
Packit b099d7
   */
Packit b099d7
  new_offs = UrmRCBufSize(wref_id) - refdsc->heap_size - name_bytes;
Packit b099d7
  ndx = refdsc->num_refs;
Packit b099d7
  refdsc->refs[ndx].w_id = w_id;
Packit b099d7
  refdsc->refs[ndx].w_name_offs = new_offs;
Packit b099d7
  refdsc->num_refs += 1;
Packit b099d7
  refdsc->heap_size += name_bytes;
Packit b099d7
  strcpy ((String)refdsc+new_offs, w_name);
Packit b099d7
Packit b099d7
  return MrmSUCCESS;
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine searches the widget reference structure for a widget,
Packit b099d7
 *	and returns its id if found.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	wref_id		widget reference structure
Packit b099d7
 *	w_name		name of widget to be found
Packit b099d7
 *	w_id_return	to return widget id
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *      MrmSUCCESS	- found, id is returned
Packit b099d7
 *	MrmNOT_FOUND	- not found
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Urm__CW_FindWRef (URMResourceContextPtr	wref_id,
Packit b099d7
		  String		w_name,
Packit b099d7
		  Widget		*w_id_return)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  URMWRefStructPtr	refdsc;		/* buffer as reference structure */
Packit b099d7
  int			ndx;		/* loop index */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Search the vector for the name, returning the id if found. Search
Packit b099d7
   * backwards, so the most recent definitions are searched first.
Packit b099d7
   */
Packit b099d7
  refdsc = (URMWRefStructPtr) UrmRCBuffer (wref_id);
Packit b099d7
  for ( ndx=refdsc->num_refs-1 ; ndx>=0 ; ndx-- )
Packit b099d7
    if ( strcmp(w_name,UrmWRefNameN(refdsc,ndx)) == 0 )
Packit b099d7
      {
Packit b099d7
	*w_id_return = UrmWRefIdN (refdsc, ndx);
Packit b099d7
	return MrmSUCCESS;
Packit b099d7
      }
Packit b099d7
  return MrmNOT_FOUND;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine creates a SetValues descriptor, initializes it from
Packit b099d7
 *	the resource descriptor, and appends it to the list. The id of the
Packit b099d7
 *	widget to be modified is set NULL to identify this descriptor as
Packit b099d7
 *	one to be set.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		file from which to uncompress argtag
Packit b099d7
 *	svlist		list of SetValues of descriptor
Packit b099d7
 *	w_name		widget name
Packit b099d7
 *	argtag		Argument tag code
Packit b099d7
 *	argname		Argument tag name if code is URMcUnknown
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
void 
Packit b099d7
Urm__CW_AppendSVWidgetRef (IDBFile		file_id,
Packit b099d7
			   URMPointerListPtr	*svlist,
Packit b099d7
			   String		w_name,
Packit b099d7
			   MrmCode		argtag,
Packit b099d7
			   String		argname)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  URMSetValuesDescPtr	svdesc ;	/* new descriptor */
Packit b099d7
  Cardinal		uncmp_res;	/* function result */
Packit b099d7
  char			errmsg[300];
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Initialize the pointer list if required
Packit b099d7
   */
Packit b099d7
  if ( *svlist == NULL )
Packit b099d7
    UrmPlistInit (10, svlist) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Create and set the new descriptor. The argument tag must be uncompressed
Packit b099d7
   * into its string now, when the compression code for it is available from the
Packit b099d7
   * file. If the tag code is unknown, then the string must be copied into
Packit b099d7
   * allocated memory.
Packit b099d7
   */
Packit b099d7
  svdesc = (URMSetValuesDescPtr) XtMalloc (sizeof(URMSetValuesDesc)) ;
Packit b099d7
  svdesc->setw = NULL ;
Packit b099d7
  svdesc->type = URMsvWidgetRef ;
Packit b099d7
  svdesc->tagcode = argtag ;
Packit b099d7
  if ( argtag == UilMrmUnknownCode )
Packit b099d7
    {
Packit b099d7
      svdesc->tagname = (String) XtMalloc (strlen(argname)+1);
Packit b099d7
      strcpy (svdesc->tagname, argname);
Packit b099d7
    }
Packit b099d7
  else
Packit b099d7
    {
Packit b099d7
      uncmp_res = Urm__UncompressCode (file_id, argtag, &svdesc->tagname);
Packit b099d7
      if ( uncmp_res != MrmSUCCESS )
Packit b099d7
	{
Packit b099d7
	  sprintf (errmsg, _MrmMMsg_0108, argtag);
Packit b099d7
	  XtFree ((char *)svdesc);
Packit b099d7
	  Urm__UT_Error ("Urm__CW_AppendSVWidgetRef", errmsg, 
Packit b099d7
			 NULL, NULL, MrmNOT_FOUND);
Packit b099d7
	  return;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
  svdesc->done = FALSE ;
Packit b099d7
  svdesc->sv.wname = Urm__UT_AllocString (w_name) ;
Packit b099d7
  UrmPlistAppendPointer (( URMPointerListPtr)*svlist, (XtPointer) svdesc) ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine creates a SetValues descriptor, initializes it from
Packit b099d7
 *	the resource descriptor, adds the callback list and appends it to the
Packit b099d7
 *	list. The id of the
Packit b099d7
 *	widget to be modified is set NULL to identify this descriptor as
Packit b099d7
 *	one to be set.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		file from which to uncompress argtag
Packit b099d7
 *	svlist		list of SetValues of descriptor
Packit b099d7
 *	w_name		widget name
Packit b099d7
 *	argtag		Argument tag code
Packit b099d7
 *	argname		Argument tag name if code is URMcUnknown
Packit b099d7
 *	cbptr		Callback description pointer
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
void 
Packit b099d7
Urm__CW_AppendCBSVWidgetRef (IDBFile			file_id,
Packit b099d7
			     URMPointerListPtr		*svlist,
Packit b099d7
			     RGMCallbackDescPtr		cbptr,
Packit b099d7
			     MrmCode			argtag,
Packit b099d7
			     String			argname)
Packit b099d7
{
Packit b099d7
  URMSetValuesDescPtr	svdesc ;	/* new descriptor */
Packit b099d7
  RGMCallbackDescPtr	cbdesc;		/* Copy of descriptor */
Packit b099d7
  MrmSize		descsize;	/* Size of descriptor to be copied */
Packit b099d7
  Cardinal		uncmp_res;	/* function result */
Packit b099d7
  char			errmsg[300];
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Initialize the pointer list if required
Packit b099d7
   */
Packit b099d7
  if ( *svlist == NULL )
Packit b099d7
    UrmPlistInit (10, svlist) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Create and set the new descriptor. The argument tag must be uncompressed
Packit b099d7
   * into its string now, when the compression code for it is available from the
Packit b099d7
   * file. If the tag code is unknown, then the string must be copied into
Packit b099d7
   * allocated memory.
Packit b099d7
   */
Packit b099d7
  svdesc = (URMSetValuesDescPtr) XtMalloc (sizeof(URMSetValuesDesc)) ;
Packit b099d7
  svdesc->setw = NULL ;
Packit b099d7
  svdesc->type = URMsvCallBackList ;
Packit b099d7
  svdesc->tagcode = argtag ;
Packit b099d7
  if ( argtag == UilMrmUnknownCode )
Packit b099d7
    {
Packit b099d7
      svdesc->tagname = (String) XtMalloc (strlen(argname)+1);
Packit b099d7
      strcpy (svdesc->tagname, argname);
Packit b099d7
    }
Packit b099d7
  else
Packit b099d7
    {
Packit b099d7
      uncmp_res = Urm__UncompressCode (file_id, argtag, &svdesc->tagname);
Packit b099d7
      if ( uncmp_res != MrmSUCCESS )
Packit b099d7
	{
Packit b099d7
	  sprintf (errmsg, _MrmMMsg_0108, argtag);
Packit b099d7
	  XtFree ((char *)svdesc);
Packit b099d7
	  Urm__UT_Error ("Urm__CW_AppendCBSVWidgetRef", errmsg, 
Packit b099d7
			 NULL, NULL, MrmNOT_FOUND);
Packit b099d7
	  return;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
  svdesc->done = FALSE ;
Packit b099d7
  /* Copy callback descriptor */
Packit b099d7
  descsize = sizeof(RGMCallbackDesc) + (cbptr->count)*sizeof(RGMCallbackItem);
Packit b099d7
  cbdesc = (RGMCallbackDescPtr)XtMalloc(descsize);
Packit b099d7
  memcpy(cbdesc, cbptr, descsize);
Packit b099d7
  svdesc->sv.callbacks = cbdesc ;
Packit b099d7
  UrmPlistAppendPointer (( URMPointerListPtr)*svlist, (XtPointer) svdesc) ;
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine updates a SetValues list from a just-created widget.
Packit b099d7
 *	Any entry whose modified widget field is NULL is has the modified
Packit b099d7
 *	widget set to the given widget. 
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	svlist		List of SetValues descriptors
Packit b099d7
 *	cur_id		current widget to be entered in descriptors
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
void 
Packit b099d7
Urm__CW_UpdateSVWidgetRef (URMPointerListPtr		*svlist,
Packit b099d7
			   Widget			cur_id)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  int			ndx ;		/* loop index */
Packit b099d7
  URMSetValuesDescPtr	svdesc ;	/* current SetValues descriptor */
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Loop over all descriptors. Enter the current widget as appropriate.
Packit b099d7
   * Since each descriptor is used only once, immediately free any
Packit b099d7
   * allocated tag string.
Packit b099d7
   */
Packit b099d7
  for ( ndx=0 ; ndx
Packit b099d7
    {
Packit b099d7
      svdesc = (URMSetValuesDescPtr) UrmPlistPtrN(*svlist,ndx) ;
Packit b099d7
      if ( svdesc->done ) continue ;
Packit b099d7
      if ( svdesc->setw == NULL )
Packit b099d7
	svdesc->setw = cur_id ;
Packit b099d7
    }
Packit b099d7
}
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine updates a SetValues list from a just-created widget.
Packit b099d7
 *	Any entry whose modified widget field is NULL is has the modified
Packit b099d7
 *	widget set to the given widget. It also uses this widget to
Packit b099d7
 *	immediately update any previously saved widget which can be
Packit b099d7
 *	resolved with this new widget and to update widget references
Packit b099d7
 *	in callback items.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	svlist		List of SetValues descriptors
Packit b099d7
 *	cur_name	current widget's name
Packit b099d7
 *	cur_id		current widget to be entered in descriptors
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
void 
Packit b099d7
Urm__CW_ResolveSVWidgetRef (URMPointerListPtr		*svlist,
Packit b099d7
			    String			cur_name,
Packit b099d7
			    Widget			cur_id)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  int			ndx ;		/* loop index */
Packit b099d7
  int			cbndx;		/* callback list index */
Packit b099d7
  URMSetValuesDescPtr	svdesc ;	/* current SetValues descriptor */
Packit b099d7
  Arg			args[1] ;	/* SetValues argument list */
Packit b099d7
  RGMCallbackDescPtr	cbdesc;		/* Current callback descriptor */
Packit b099d7
  RGMCallbackItemPtr	items;		/* Array of callback items */
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Loop over all descriptors. Enter the current widget as appropriate.
Packit b099d7
   * Since each descriptor is used only once, immediately free any
Packit b099d7
   * allocated tag string.
Packit b099d7
   */
Packit b099d7
  for ( ndx=0 ; ndx
Packit b099d7
    {
Packit b099d7
      svdesc = (URMSetValuesDescPtr) UrmPlistPtrN(*svlist,ndx) ;
Packit b099d7
      if ( svdesc->done ) continue ;
Packit b099d7
      if ( svdesc->setw == NULL )
Packit b099d7
	{
Packit b099d7
	  svdesc->setw = cur_id ;
Packit b099d7
	  continue ;
Packit b099d7
	}
Packit b099d7
      switch (svdesc->type)
Packit b099d7
	{
Packit b099d7
	case URMsvWidgetRef:
Packit b099d7
	  if ( strcmp(cur_name,svdesc->sv.wname) == 0 )
Packit b099d7
	    {
Packit b099d7
	      args[0].name = svdesc->tagname ;
Packit b099d7
	      args[0].value = (XtArgVal) cur_id ;
Packit b099d7
	      XtSetValues (svdesc->setw, args, 1) ;
Packit b099d7
	      svdesc->done = TRUE ;
Packit b099d7
	      if ( svdesc->tagcode == UilMrmUnknownCode )
Packit b099d7
		{
Packit b099d7
		  XtFree ((char *)svdesc->tagname);
Packit b099d7
		  svdesc->tagname = NULL;
Packit b099d7
		}
Packit b099d7
	      /* Does this really need to be freed here? */
Packit b099d7
	      XtFree(svdesc->sv.wname);
Packit b099d7
	      svdesc->sv.wname = NULL;
Packit b099d7
	    }
Packit b099d7
	  break;
Packit b099d7
	
Packit b099d7
	case URMsvCallBackList:
Packit b099d7
	  cbdesc = (RGMCallbackDescPtr)svdesc->sv.callbacks;
Packit b099d7
	  items = cbdesc->item;
Packit b099d7
	
Packit b099d7
	  /* Loop through callback items, resolving where possible */
Packit b099d7
	  for (cbndx = 0; cbndx < cbdesc->count; cbndx++)
Packit b099d7
	    {
Packit b099d7
	      if (items[cbndx].runtime.resolved) continue; 
Packit b099d7
Packit b099d7
	      if (strcmp(cur_name, items[cbndx].runtime.wname) == 0) 
Packit b099d7
		/* Finish resolving the callback item. */
Packit b099d7
		{
Packit b099d7
		  items[cbndx].runtime.callback.closure = (XtPointer)cur_id;
Packit b099d7
		  items[cbndx].runtime.resolved = TRUE;
Packit b099d7
		  cbdesc->unres_ref_count--;
Packit b099d7
		  /* Free the widget name. */
Packit b099d7
		  XtFree(items[cbndx].runtime.wname);
Packit b099d7
		  items[cbndx].runtime.wname = NULL;
Packit b099d7
		}
Packit b099d7
	    }
Packit b099d7
	
Packit b099d7
	  if (cbdesc->unres_ref_count == 0)
Packit b099d7
	    {
Packit b099d7
	      /* Move individual items so array functions as callback list */
Packit b099d7
	      XtCallbackRec *callbacks = (XtCallbackRec *)items;
Packit b099d7
	    
Packit b099d7
	      for (cbndx = 0; cbndx <= cbdesc->count; cbndx++)
Packit b099d7
		/* <= so that null item is copied. */
Packit b099d7
		{
Packit b099d7
		  callbacks[cbndx].callback = (XtCallbackProc)
Packit b099d7
		    items[cbndx].runtime.callback.callback;
Packit b099d7
		  callbacks[cbndx].closure = (XtPointer)
Packit b099d7
		    items[cbndx].runtime.callback.closure;
Packit b099d7
		}
Packit b099d7
		
Packit b099d7
		
Packit b099d7
	      args[0].name = svdesc->tagname;
Packit b099d7
	      args[0].value = (XtArgVal)items;
Packit b099d7
	      XtSetValues(svdesc->setw, args, 1);
Packit b099d7
	      svdesc->done = TRUE;
Packit b099d7
Packit b099d7
	      /* Free memory. */
Packit b099d7
	      if ( svdesc->tagcode == UilMrmUnknownCode )
Packit b099d7
		{
Packit b099d7
		  XtFree ((char *)svdesc->tagname);
Packit b099d7
		  svdesc->tagname = NULL;
Packit b099d7
		}
Packit b099d7
Packit b099d7
	      XtFree((char *)svdesc->sv.callbacks);
Packit b099d7
	      svdesc->sv.callbacks = NULL;
Packit b099d7
	    }
Packit b099d7
	  break;
Packit b099d7
	    
Packit b099d7
	default:
Packit b099d7
	  continue;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
}
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *      This routine frees a SetValues descriptor.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *      svdesc          SetValues descriptor
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
void 
Packit b099d7
Urm__CW_FreeSetValuesDesc (URMSetValuesDescPtr         svdesc)
Packit b099d7
{
Packit b099d7
  if ( (svdesc->type == URMsvWidgetRef) && (svdesc->sv.wname != NULL) )
Packit b099d7
    XtFree ((char *)svdesc->sv.wname);
Packit b099d7
Packit b099d7
  XtFree ((char *)svdesc);
Packit b099d7
}