DisplayList.c revision efbcb2bf
17a84e134Smrg/*
27a84e134Smrg * Copyright (c) 1998 by The XFree86 Project, Inc.
37a84e134Smrg *
47a84e134Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57a84e134Smrg * copy of this software and associated documentation files (the "Software"),
67a84e134Smrg * to deal in the Software without restriction, including without limitation
77a84e134Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87a84e134Smrg * and/or sell copies of the Software, and to permit persons to whom the
97a84e134Smrg * Software is furnished to do so, subject to the following conditions:
107a84e134Smrg *
117a84e134Smrg * The above copyright notice and this permission notice shall be included in
127a84e134Smrg * all copies or substantial portions of the Software.
13421c997bSmrg *
147a84e134Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157a84e134Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167a84e134Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
177a84e134Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
187a84e134Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
197a84e134Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
207a84e134Smrg * SOFTWARE.
217a84e134Smrg *
227a84e134Smrg * Except as contained in this notice, the name of the XFree86 Project shall
237a84e134Smrg * not be used in advertising or otherwise to promote the sale, use or other
247a84e134Smrg * dealings in this Software without prior written authorization from the
257a84e134Smrg * XFree86 Project.
267a84e134Smrg *
277a84e134Smrg * Author: Paulo César Pereira de Andrade
287a84e134Smrg */
297a84e134Smrg
307a84e134Smrg#ifdef HAVE_CONFIG_H
317a84e134Smrg#include <config.h>
327a84e134Smrg#endif
337a84e134Smrg#include <ctype.h>
347a84e134Smrg#include <string.h>
357a84e134Smrg#include <stdio.h>
367a84e134Smrg#include <stdlib.h>
377a84e134Smrg#include <X11/IntrinsicP.h>
387a84e134Smrg#include <X11/StringDefs.h>
397a84e134Smrg#include <X11/CoreP.h>
407a84e134Smrg#include <X11/Xfuncs.h>
417a84e134Smrg#include <X11/Xmu/CharSet.h>
427a84e134Smrg#include "Private.h"
437a84e134Smrg
447a84e134Smrg
457a84e134Smrg#ifndef OLDXAW
467a84e134Smrg
477a84e134Smrg/*
487a84e134Smrg * Types
497a84e134Smrg */
507a84e134Smrgtypedef struct _XawDLProc XawDLProc;
517a84e134Smrgtypedef struct _XawDLData XawDLData;
527a84e134Smrgtypedef struct _XawDLInfo XawDLInfo;
537a84e134Smrg
547a84e134Smrgstruct _XawDLProc {
557a84e134Smrg  XrmQuark qname;
567a84e134Smrg  String *params;
577a84e134Smrg  Cardinal num_params;
587a84e134Smrg  XawDisplayListProc proc;
597a84e134Smrg  XtPointer args;
607a84e134Smrg  XawDLData *data;
617a84e134Smrg};
627a84e134Smrg
637a84e134Smrgstruct _XawDLData {
647a84e134Smrg  XawDLClass *dlclass;
657a84e134Smrg  XtPointer data;
667a84e134Smrg};
677a84e134Smrg
687a84e134Smrgstruct _XawDLInfo {
697a84e134Smrg  String name;
707a84e134Smrg  XrmQuark qname;
717a84e134Smrg  XawDisplayListProc proc;
727a84e134Smrg};
737a84e134Smrg
747a84e134Smrgstruct _XawDL {
757a84e134Smrg  XawDLProc **procs;
767a84e134Smrg  Cardinal num_procs;
777a84e134Smrg  XawDLData **data;
787a84e134Smrg  Cardinal num_data;
797a84e134Smrg  Screen *screen;
807a84e134Smrg  Colormap colormap;
817a84e134Smrg  int depth;
827a84e134Smrg  XrmQuark qrep;  /* for cache lookup */
837a84e134Smrg};
847a84e134Smrg
857a84e134Smrgstruct _XawDLClass {
867a84e134Smrg  String name;
877a84e134Smrg  XawDLInfo **infos;
887a84e134Smrg  Cardinal num_infos;
897a84e134Smrg  XawDLArgsInitProc args_init;
907a84e134Smrg  XawDLArgsDestructor args_destructor;
917a84e134Smrg  XawDLDataInitProc data_init;
927a84e134Smrg  XawDLDataDestructor data_destructor;
937a84e134Smrg};
947a84e134Smrg
957a84e134Smrg/*
967a84e134Smrg * Private Methods
977a84e134Smrg */
987a84e134Smrgstatic XawDLClass *_XawFindDLClass(String);
997a84e134Smrgstatic int qcmp_dlist_class(_Xconst void*, _Xconst void*);
1007a84e134Smrgstatic int bcmp_dlist_class(_Xconst void*, _Xconst void*);
1017a84e134Smrgstatic XawDLInfo *_XawFindDLInfo(XawDLClass*, String);
1027a84e134Smrgstatic int qcmp_dlist_info(_Xconst void*, _Xconst void*);
1037a84e134Smrgstatic int bcmp_dlist_info(_Xconst void*, _Xconst void*);
1047a84e134Smrgstatic void *_Xaw_Xlib_ArgsInitProc(String, String*, Cardinal*,
1057a84e134Smrg				    Screen*, Colormap, int);
1067a84e134Smrgstatic void _Xaw_Xlib_ArgsDestructor(Display*, String, XtPointer,
1077a84e134Smrg				     String*, Cardinal*);
1087a84e134Smrgstatic void *_Xaw_Xlib_DataInitProc(String, Screen*, Colormap, int);
1097a84e134Smrgstatic void _Xaw_Xlib_DataDestructor(Display*, String, XtPointer);
1107a84e134Smrg
1117a84e134Smrg/*
1127a84e134Smrg * Initialization
1137a84e134Smrg */
1147a84e134Smrgstatic XawDLClass **classes;
1157a84e134Smrgstatic Cardinal num_classes;
1167a84e134Smrgstatic String xlib = "xlib";
1177a84e134Smrg
1187a84e134Smrg/*
1197a84e134Smrg * Implementation
1207a84e134Smrg */
1217a84e134Smrgvoid
1227a84e134SmrgXawRunDisplayList(Widget w, _XawDisplayList *list,
1237a84e134Smrg		       XEvent *event, Region region)
1247a84e134Smrg{
1257a84e134Smrg  Cardinal i;
1267a84e134Smrg
1277a84e134Smrg  if (!XtIsRealized(w))
1287a84e134Smrg    return;
1297a84e134Smrg
1307a84e134Smrg  for (i = 0; i < list->num_procs; i++)
1317a84e134Smrg    {
132efbcb2bfSmrg      XawDLProc *proc = list->procs[i];
1337a84e134Smrg      proc->proc(w, proc->args, proc->data->data, event, region);
1347a84e134Smrg    }
1357a84e134Smrg}
1367a84e134Smrg
1377a84e134Smrg#define DLERR  -2
1387a84e134Smrg#define DLEOF  -1
1397a84e134Smrg#define DLEND  1
1407a84e134Smrg#define DLNAME 2
1417a84e134Smrg#define DLARG  3
1425ec34c4cSmrgstatic String
1435ec34c4cSmrgread_token(String src, char *dst, Cardinal size, int *status)
1447a84e134Smrg{
1457a84e134Smrg  int ch;
1467a84e134Smrg  Bool esc, quote;
1477a84e134Smrg  Cardinal i;
1487a84e134Smrg
1497a84e134Smrg  i = 0;
1507a84e134Smrg  esc = quote = False;
1517a84e134Smrg
1527a84e134Smrg  /*CONSTCOND*/
1537a84e134Smrg  while (1)
1547a84e134Smrg    {
1557a84e134Smrg      ch = *src;
1567a84e134Smrg      if (ch != '\n' && isspace(ch))
1577a84e134Smrg	++src;
1587a84e134Smrg      else
1597a84e134Smrg	break;
1607a84e134Smrg    }
1617a84e134Smrg
1627a84e134Smrg  for (; i < size - 1; src++)
1637a84e134Smrg    {
1647a84e134Smrg      ch = *src;
1657a84e134Smrg      if (ch == '"')
1667a84e134Smrg	{
1677a84e134Smrg	  if (quote)
1687a84e134Smrg	    {
1697a84e134Smrg	      quote = False;
1707a84e134Smrg	      continue;
1717a84e134Smrg	    }
1727a84e134Smrg	  quote = True;
1737a84e134Smrg	  continue;
1747a84e134Smrg	}
1757a84e134Smrg      if (ch == '\\')
1767a84e134Smrg	{
1777a84e134Smrg	  if (esc)
1787a84e134Smrg	    {
1795ec34c4cSmrg	      dst[i++] = (char)ch;
1807a84e134Smrg	      esc = False;
1817a84e134Smrg	      continue;
1827a84e134Smrg	    }
1837a84e134Smrg	  esc = True;
1847a84e134Smrg	  continue;
1857a84e134Smrg	}
1867a84e134Smrg      if (ch == '\0')
1877a84e134Smrg	{
1887a84e134Smrg	  *status = DLEOF;
1897a84e134Smrg	  dst[i] = '\0';
1907a84e134Smrg	  return (src);
1917a84e134Smrg	}
1927a84e134Smrg      else if (!esc)
1937a84e134Smrg	{
1947a84e134Smrg	  if (!quote)
1957a84e134Smrg	    {
1967a84e134Smrg	      if (ch == ',')
1977a84e134Smrg		{
1987a84e134Smrg		  *status = DLARG;
1997a84e134Smrg		  dst[i] = '\0';
2007a84e134Smrg		  return (++src);
2017a84e134Smrg		}
2027a84e134Smrg	      else if (ch == ' ' || ch == '\t')
2037a84e134Smrg		{
2047a84e134Smrg		  *status = DLNAME;
2057a84e134Smrg		  dst[i] = '\0';
2067a84e134Smrg		  return (++src);
2077a84e134Smrg		}
2087a84e134Smrg	      else if (ch == ';' || ch == '\n')
2097a84e134Smrg		{
2107a84e134Smrg		  *status = DLEND;
2117a84e134Smrg		  dst[i] = '\0';
2127a84e134Smrg		  return (++src);
2137a84e134Smrg		}
2147a84e134Smrg	    }
2157a84e134Smrg	}
2167a84e134Smrg      else
2177a84e134Smrg	esc = False;
2185ec34c4cSmrg      dst[i++] = (char)ch;
2197a84e134Smrg    }
2207a84e134Smrg
2217a84e134Smrg  *status = DLERR;
2227a84e134Smrg  dst[i] = '\0';
2237a84e134Smrg
2247a84e134Smrg  return (src);
2257a84e134Smrg}
2267a84e134Smrg
2277a84e134Smrg_XawDisplayList *XawCreateDisplayList(String string, Screen *screen,
2287a84e134Smrg				     Colormap colormap, int depth)
2297a84e134Smrg{
2307a84e134Smrg  _XawDisplayList *dlist;
2317a84e134Smrg  XawDLClass *lc, *xlibc;
2327a84e134Smrg  XawDLData *data;
2337a84e134Smrg  XawDLInfo *info;
2347a84e134Smrg  XawDLProc *proc;
2357a84e134Smrg  char cname[64], fname[64], aname[1024];
2367a84e134Smrg  Cardinal i;
2375ec34c4cSmrg  String cp;
2387a84e134Smrg  int status;
2397a84e134Smrg
2407a84e134Smrg  xlibc = XawGetDisplayListClass(xlib);
2417a84e134Smrg  if (!xlibc)
2427a84e134Smrg    {
2437a84e134Smrg      XawDisplayListInitialize();
2447a84e134Smrg      xlibc = XawGetDisplayListClass(xlib);
2457a84e134Smrg    }
2467a84e134Smrg
2477a84e134Smrg  dlist = (_XawDisplayList *)XtMalloc(sizeof(_XawDisplayList));
2487a84e134Smrg  dlist->procs = NULL;
2497a84e134Smrg  dlist->num_procs = 0;
2507a84e134Smrg  dlist->data = NULL;
2517a84e134Smrg  dlist->num_data = 0;
2527a84e134Smrg  dlist->screen = screen;
2537a84e134Smrg  dlist->colormap = colormap;
2547a84e134Smrg  dlist->depth = depth;
2557a84e134Smrg  dlist->qrep = NULLQUARK;
2567a84e134Smrg  if (!string || !string[0])
2577a84e134Smrg    return (dlist);
2587a84e134Smrg
2597a84e134Smrg  cp = string;
2607a84e134Smrg
2617a84e134Smrg  status = 0;
2627a84e134Smrg  while (status != DLEOF)
2637a84e134Smrg    {
264efbcb2bfSmrg      String fp, lp;
265efbcb2bfSmrg
2667a84e134Smrg      lp = cp;
2677a84e134Smrg      cp = read_token(cp, fname, sizeof(fname), &status);
2687a84e134Smrg
2697a84e134Smrg      if (status != DLNAME && status != DLEND && status != DLEOF)
2707a84e134Smrg	{
2717a84e134Smrg	  char msg[256];
2727a84e134Smrg
273421c997bSmrg	  snprintf(msg, sizeof(msg),
274421c997bSmrg		   "Error parsing displayList at \"%s\"", lp);
2757a84e134Smrg	  XtAppWarning(XtDisplayToApplicationContext(DisplayOfScreen(screen)),
2767a84e134Smrg		       msg);
2777a84e134Smrg	  XawDestroyDisplayList(dlist);
2787a84e134Smrg	  return (NULL);
2797a84e134Smrg	}
2807a84e134Smrg      fp = fname;
2817a84e134Smrg      /*CONSTCOND*/
2827a84e134Smrg      while (1)
2837a84e134Smrg	{
2847a84e134Smrg	  fp = strchr(fp, ':');
2857a84e134Smrg	  if (!fp || (fp == cp || fp[-1] != '\\'))
2867a84e134Smrg	    break;
2877a84e134Smrg	  ++fp;
2887a84e134Smrg	}
2897a84e134Smrg      if (fp)
2907a84e134Smrg	{
2915ec34c4cSmrg	  snprintf(cname, (size_t)(fp - fname + 1), "%s", fname);
2927a84e134Smrg	  memmove(fname, fp + 1, strlen(fp));
2937a84e134Smrg	  lc = cname[0] ? XawGetDisplayListClass(cname) : xlibc;
2947a84e134Smrg	  if (!lc)
2957a84e134Smrg	    {
2967a84e134Smrg	      char msg[256];
2977a84e134Smrg
298421c997bSmrg	      snprintf(msg, sizeof(msg),
299421c997bSmrg		       "Cannot find displayList class \"%s\"", cname);
3007a84e134Smrg	      XtAppWarning(XtDisplayToApplicationContext
3017a84e134Smrg			   (DisplayOfScreen(screen)), msg);
3027a84e134Smrg	      XawDestroyDisplayList(dlist);
3037a84e134Smrg	      return (NULL);
3047a84e134Smrg	    }
3057a84e134Smrg	}
3067a84e134Smrg      else
3077a84e134Smrg	lc = xlibc;
3087a84e134Smrg
3097a84e134Smrg      if (status == DLEOF && !fname[0])
3107a84e134Smrg	break;
3117a84e134Smrg
3127a84e134Smrg      if ((info = _XawFindDLInfo(lc, fname)) == NULL)
3137a84e134Smrg	{
3147a84e134Smrg	  char msg[256];
3157a84e134Smrg
316421c997bSmrg	  snprintf(msg, sizeof(msg),
317421c997bSmrg		   "Cannot find displayList procedure \"%s\"", fname);
3187a84e134Smrg	  XtAppWarning(XtDisplayToApplicationContext(DisplayOfScreen(screen)),
3197a84e134Smrg		       msg);
3207a84e134Smrg	  XawDestroyDisplayList(dlist);
3217a84e134Smrg	  return (NULL);
3227a84e134Smrg	}
3237a84e134Smrg
3247a84e134Smrg      proc = (XawDLProc *)XtMalloc(sizeof(XawDLProc));
3257a84e134Smrg      proc->qname = info->qname;
3267a84e134Smrg      proc->params = NULL;
3277a84e134Smrg      proc->num_params = 0;
3287a84e134Smrg      proc->proc = info->proc;
3297a84e134Smrg      proc->args = NULL;
3307a84e134Smrg      proc->data = NULL;
3317a84e134Smrg
3327a84e134Smrg      if (!dlist->procs)
3337a84e134Smrg	{
3347a84e134Smrg	  dlist->num_procs = 1;
3357a84e134Smrg	  dlist->procs = (XawDLProc**)XtMalloc(sizeof(XawDLProc*));
3367a84e134Smrg	}
3377a84e134Smrg      else
3387a84e134Smrg	{
3397a84e134Smrg	  ++dlist->num_procs;
3407a84e134Smrg	  dlist->procs = (XawDLProc**)
3415ec34c4cSmrg	    XtRealloc((char *)dlist->procs, (Cardinal)(sizeof(XawDLProc*) *
3425ec34c4cSmrg		      dlist->num_procs));
3437a84e134Smrg	}
3447a84e134Smrg      dlist->procs[dlist->num_procs - 1] = proc;
3457a84e134Smrg
3467a84e134Smrg      while (status != DLEND && status != DLEOF)
3477a84e134Smrg	{
3487a84e134Smrg	  lp = cp;
3497a84e134Smrg	  cp = read_token(cp, aname, sizeof(aname), &status);
3507a84e134Smrg
3517a84e134Smrg	  if (status != DLARG && status != DLEND && status != DLEOF)
3527a84e134Smrg	    {
3537a84e134Smrg	      char msg[256];
3547a84e134Smrg
355421c997bSmrg	      snprintf(msg, sizeof(msg),
356421c997bSmrg		       "Error parsing displayList at \"%s\"", lp);
3577a84e134Smrg	      XtAppWarning(XtDisplayToApplicationContext
3587a84e134Smrg			   (DisplayOfScreen(screen)), msg);
3597a84e134Smrg	      XawDestroyDisplayList(dlist);
3607a84e134Smrg	      return (NULL);
3617a84e134Smrg	    }
3627a84e134Smrg
3637a84e134Smrg	  if (!proc->num_params)
3647a84e134Smrg	    {
3657a84e134Smrg	      proc->num_params = 1;
3667a84e134Smrg	      proc->params = (String *)XtMalloc(sizeof(String));
3677a84e134Smrg	    }
3687a84e134Smrg	  else
3697a84e134Smrg	    {
3707a84e134Smrg	      ++proc->num_params;
3717a84e134Smrg	      proc->params = (String *)XtRealloc((char *)proc->params,
3725ec34c4cSmrg						 (Cardinal)(sizeof(String) *
3735ec34c4cSmrg						 proc->num_params));
3747a84e134Smrg	    }
3757a84e134Smrg	  proc->params[proc->num_params - 1] = XtNewString(aname);
3767a84e134Smrg	}
3777a84e134Smrg
3787a84e134Smrg      /* verify if data is already created for lc */
3797a84e134Smrg      data = NULL;
3807a84e134Smrg      for (i = 0; i < dlist->num_data; i++)
3817a84e134Smrg	if (dlist->data[i]->dlclass == lc)
3827a84e134Smrg	  {
3837a84e134Smrg	    data = dlist->data[i];
3847a84e134Smrg	    break;
3857a84e134Smrg	  }
3867a84e134Smrg
3877a84e134Smrg      if (!data)
3887a84e134Smrg	{
3897a84e134Smrg	  data = (XawDLData *)XtMalloc(sizeof(XawDLData));
3907a84e134Smrg	  data->dlclass = lc;
3917a84e134Smrg	  if (lc->data_init)
3927a84e134Smrg	    data->data = lc->data_init(lc->name, screen, colormap, depth);
3937a84e134Smrg	  else
3947a84e134Smrg	    data->data = NULL;
3957a84e134Smrg
3967a84e134Smrg	  if (!dlist->data)
3977a84e134Smrg	    {
3987a84e134Smrg	      dlist->num_data = 1;
3997a84e134Smrg	      dlist->data = (XawDLData **)XtMalloc(sizeof(XawDLData*));
4007a84e134Smrg	    }
4017a84e134Smrg	  else
4027a84e134Smrg	    {
4037a84e134Smrg	      ++dlist->num_data;
4047a84e134Smrg	      dlist->data = (XawDLData **)
4055ec34c4cSmrg		XtRealloc((char *)dlist->data, (Cardinal)(sizeof(XawDLData*) *
4065ec34c4cSmrg			  dlist->num_data));
4077a84e134Smrg	    }
4087a84e134Smrg	  dlist->data[dlist->num_data - 1] = data;
4097a84e134Smrg	}
4107a84e134Smrg
4117a84e134Smrg      if (lc->args_init)
4127a84e134Smrg	{
4137a84e134Smrg	  proc->args = lc->args_init(fname, proc->params, &proc->num_params,
4147a84e134Smrg				    screen, colormap, depth);
4157a84e134Smrg	  if (proc->args == XAWDL_CONVERT_ERROR)
4167a84e134Smrg	    {
4177a84e134Smrg	      char msg[256];
4187a84e134Smrg
4197a84e134Smrg	      proc->args = NULL;
420421c997bSmrg	      snprintf(msg, sizeof(msg),
421421c997bSmrg		       "Cannot convert arguments to displayList function \"%s\"",
422421c997bSmrg		       fname);
4237a84e134Smrg	      XtAppWarning(XtDisplayToApplicationContext
4247a84e134Smrg			   (DisplayOfScreen(screen)), msg);
4257a84e134Smrg	      XawDestroyDisplayList(dlist);
4267a84e134Smrg	      return (NULL);
4277a84e134Smrg	    }
4287a84e134Smrg	}
4297a84e134Smrg      else
4307a84e134Smrg	proc->args = NULL;
4317a84e134Smrg
4327a84e134Smrg      proc->data = data;
4337a84e134Smrg    }
4347a84e134Smrg
4357a84e134Smrg  dlist->qrep = XrmStringToQuark(string);
4367a84e134Smrg  return (dlist);
4377a84e134Smrg}
4387a84e134Smrg
4397a84e134SmrgString
4407a84e134SmrgXawDisplayListString(_XawDisplayList *dlist)
4417a84e134Smrg{
4427a84e134Smrg  if (!dlist || dlist->qrep == NULLQUARK)
4437a84e134Smrg    return ("");
4447a84e134Smrg  return (XrmQuarkToString(dlist->qrep));
4457a84e134Smrg}
4467a84e134Smrg
4477a84e134Smrgvoid
4487a84e134SmrgXawDestroyDisplayList(_XawDisplayList *dlist)
4497a84e134Smrg{
4507a84e134Smrg  Cardinal i, j;
4517a84e134Smrg
4527a84e134Smrg  if (!dlist)
4537a84e134Smrg    return;
4547a84e134Smrg
4557a84e134Smrg  for (i = 0; i < dlist->num_procs; i++)
4567a84e134Smrg    {
457efbcb2bfSmrg      XawDLProc *proc = dlist->procs[i];
458efbcb2bfSmrg      XawDLData *data = proc->data;
4597a84e134Smrg
4607a84e134Smrg      if (data)
4617a84e134Smrg	{
4627a84e134Smrg	  if (data->dlclass->args_destructor)
4637a84e134Smrg	    data->dlclass->args_destructor(DisplayOfScreen(dlist->screen),
4647a84e134Smrg					   XrmQuarkToString(proc->qname),
4657a84e134Smrg					   proc->args,
4667a84e134Smrg					   proc->params, &proc->num_params);
4677a84e134Smrg	  if (data->data)
4687a84e134Smrg	    {
4697a84e134Smrg	      if (data->dlclass->data_destructor)
4707a84e134Smrg		{
4717a84e134Smrg		  data->dlclass
4727a84e134Smrg		    ->data_destructor(DisplayOfScreen(dlist->screen),
4737a84e134Smrg				      data->dlclass->name,  data->data);
4747a84e134Smrg		  data->data = NULL;
4757a84e134Smrg		}
4767a84e134Smrg	    }
4777a84e134Smrg	}
4787a84e134Smrg
4797a84e134Smrg      for (j = 0; j < proc->num_params; j++)
4805ec34c4cSmrg	XtFree((char *)proc->params[j]);
4817a84e134Smrg      if (proc->num_params)
4827a84e134Smrg	XtFree((char *)proc->params);
4837a84e134Smrg      XtFree((char *)proc);
4847a84e134Smrg    }
4857a84e134Smrg
4867a84e134Smrg  if (dlist->num_procs)
4877a84e134Smrg    XtFree((char *)dlist->procs);
4887a84e134Smrg
4897a84e134Smrg  XtFree((char *)dlist);
4907a84e134Smrg}
4917a84e134Smrg
4927a84e134Smrg/**********************************************************************
4937a84e134Smrg * If you want to implement your own class of procedures, look at
4945b16253fSmrg * the code below.
4957a84e134Smrg **********************************************************************/
4967a84e134Smrg/* Start of Implementation of class "xlib" */
4977a84e134Smrgtypedef struct _XawXlibData {
4987a84e134Smrg  GC gc;
4997a84e134Smrg  unsigned long mask;
5007a84e134Smrg  XGCValues values;
5017a84e134Smrg  int shape;
5027a84e134Smrg  int mode;
5037a84e134Smrg  char *dashes;
5047a84e134Smrg  /* these fields can be used for optimization, to
5057a84e134Smrg   * avoid unnecessary coordinates recalculation.
5067a84e134Smrg   */
5077a84e134Smrg  Position x, y;
5087a84e134Smrg  Dimension width, height;
5097a84e134Smrg} XawXlibData;
5107a84e134Smrg
5117a84e134Smrgtypedef struct _XawDLPosition {
5127a84e134Smrg  Position pos;
5137a84e134Smrg  short denom;
5147a84e134Smrg  Boolean high;
5157a84e134Smrg} XawDLPosition;
5167a84e134Smrg
5177a84e134Smrgtypedef struct _XawDLPositionPtr {
5187a84e134Smrg  XawDLPosition *pos;
5197a84e134Smrg  Cardinal num_pos;
5207a84e134Smrg} XawDLPositionPtr;
5217a84e134Smrg
5227a84e134Smrgtypedef struct _XawDLArcArgs {
5237a84e134Smrg  XawDLPosition pos[4];
5247a84e134Smrg  int angle1;
5257a84e134Smrg  int angle2;
5267a84e134Smrg} XawDLArcArgs;
5277a84e134Smrg
5287a84e134Smrgtypedef struct _XawDLStringArgs {
5297a84e134Smrg  XawDLPosition pos[2];
5307a84e134Smrg  char *string;
5317a84e134Smrg  int length;
5327a84e134Smrg} XawDLStringArgs;
5337a84e134Smrg
5347a84e134Smrgtypedef struct _XawDLCopyArgs {
5357a84e134Smrg  XawPixmap *pixmap;
5367a84e134Smrg  XawDLPosition pos[6];
5377a84e134Smrg  int plane;
5387a84e134Smrg} XawDLCopyArgs;
5397a84e134Smrg
5407a84e134Smrgtypedef struct _XawDLImageArgs {
5417a84e134Smrg  XawPixmap *pixmap;
5427a84e134Smrg  XawDLPosition pos[4];
5437a84e134Smrg  int depth;
5447a84e134Smrg} XawDLImageArgs;
5457a84e134Smrg
5465ec34c4cSmrg#define X_ARG(x) ((Position)(((x).denom != 0) ?				      \
5477a84e134Smrg		  ((float)XtWidth(w) * ((float)(x).pos / (float)(x).denom)) : \
5485ec34c4cSmrg		  (float)((x).high ? XtWidth(w) - (x).pos : (x).pos)))
5495ec34c4cSmrg#define Y_ARG(x) ((Position)(((x).denom != 0) ?				      \
5507a84e134Smrg		  ((float)XtHeight(w) * ((float)(x).pos / (float)(x).denom)): \
5515ec34c4cSmrg		  (float)((x).high ? XtHeight(w) - (x).pos : (x).pos)))
5527a84e134Smrg#define DRECT		0
5537a84e134Smrg#define FRECT		1
5547a84e134Smrg#define LINE		2
5557a84e134Smrg#define GCFG		3
5567a84e134Smrg#define GCBG		4
5577a84e134Smrg#define FPOLY		5
5587a84e134Smrg#define DARC		6
5597a84e134Smrg#define FARC		7
5607a84e134Smrg#define DLINES		8
5617a84e134Smrg#define MASK		9
5627a84e134Smrg#define UMASK		10
5637a84e134Smrg#define LWIDTH		11
5647a84e134Smrg#define POINT		12
5657a84e134Smrg#define POINTS		13
5667a84e134Smrg#define SEGMENTS	14
5677a84e134Smrg#define ARCMODE		15
5687a84e134Smrg#define COORDMODE	16
5697a84e134Smrg#define SHAPEMODE	17
5707a84e134Smrg#define LINESTYLE	18
5717a84e134Smrg#define CAPSTYLE	19
5727a84e134Smrg#define JOINSTYLE	20
5737a84e134Smrg#define FILLSTYLE	21
5747a84e134Smrg#define FILLRULE	22
5757a84e134Smrg#define	TILE		23
5767a84e134Smrg#define STIPPLE		24
5777a84e134Smrg#define TSORIGIN	25
5787a84e134Smrg#define FUNCTION	26
5797a84e134Smrg#define PLANEMASK	27
5807a84e134Smrg#define DSTRING		28
5817a84e134Smrg#define PSTRING		29
5827a84e134Smrg#define FONT		30
5837a84e134Smrg#define DASHES		31
5847a84e134Smrg#define SUBWMODE	32
5857a84e134Smrg#define EXPOSURES	33
5867a84e134Smrg#define CLIPORIGIN	34
5877a84e134Smrg#define CLIPMASK	35
5887a84e134Smrg#define CLIPRECTS	36
5897a84e134Smrg#define COPYAREA	37
5907a84e134Smrg#define COPYPLANE	38
5917a84e134Smrg#define IMAGE		39
5927a84e134Smrg
5937a84e134Smrgstatic void
5947a84e134SmrgDl1Point(Widget w, XtPointer args, XtPointer data, int id)
5957a84e134Smrg{
5967a84e134Smrg  XawDLPosition *pos = (XawDLPosition *)args;
5977a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
5987a84e134Smrg  Display *display;
5997a84e134Smrg  Window window;
6007a84e134Smrg  Position x, y;
6017a84e134Smrg
6025ec34c4cSmrg  x = (Position)(X_ARG(pos[0]));
6035ec34c4cSmrg  y = (Position)(Y_ARG(pos[1]));
6047a84e134Smrg
6057a84e134Smrg  if (!XtIsWidget(w))
6067a84e134Smrg    {
6077a84e134Smrg      Position xpad, ypad;
6087a84e134Smrg
6095ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
6105ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
6115ec34c4cSmrg      x = (Position)(x + xpad);
6125ec34c4cSmrg      y = (Position)(y + ypad);
6137a84e134Smrg      display = XtDisplayOfObject(w);
6147a84e134Smrg      window = XtWindowOfObject(w);
6157a84e134Smrg    }
6167a84e134Smrg  else
6177a84e134Smrg    {
6187a84e134Smrg      display = XtDisplay(w);
6197a84e134Smrg      window = XtWindow(w);
6207a84e134Smrg    }
6217a84e134Smrg
6227a84e134Smrg  if (id == POINT)
6237a84e134Smrg    XDrawPoint(display, window, xdata->gc, x, y);
6247a84e134Smrg  else if (id == TSORIGIN)
6257a84e134Smrg    {
6267a84e134Smrg      xdata->values.ts_x_origin = x;
6277a84e134Smrg      xdata->values.ts_y_origin = y;
6287a84e134Smrg      xdata->mask |= GCTileStipXOrigin | GCTileStipYOrigin;
6297a84e134Smrg      XSetTSOrigin(display, xdata->gc, x, y);
6307a84e134Smrg    }
6317a84e134Smrg  else if (id == CLIPORIGIN)
6327a84e134Smrg    {
6337a84e134Smrg      xdata->values.clip_x_origin = x;
6347a84e134Smrg      xdata->values.clip_y_origin = y;
6357a84e134Smrg      xdata->mask |= GCClipXOrigin | GCClipYOrigin;
6367a84e134Smrg      XSetClipOrigin(display, xdata->gc, x, y);
6377a84e134Smrg    }
6387a84e134Smrg}
6397a84e134Smrg
6407a84e134Smrgstatic void
6417a84e134SmrgDl2Points(Widget w, XtPointer args, XtPointer data, int id)
6427a84e134Smrg{
6437a84e134Smrg  XawDLPosition *pos = (XawDLPosition *)args;
6447a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
6457a84e134Smrg  Display *display;
6467a84e134Smrg  Window window;
6477a84e134Smrg  Position x1, y1, x2, y2;
6487a84e134Smrg
6497a84e134Smrg  x1 = X_ARG(pos[0]);
6507a84e134Smrg  y1 = Y_ARG(pos[1]);
6517a84e134Smrg  x2 = X_ARG(pos[2]);
6527a84e134Smrg  y2 = Y_ARG(pos[3]);
6537a84e134Smrg
6547a84e134Smrg  if (!XtIsWidget(w))
6557a84e134Smrg    {
6567a84e134Smrg      Position xpad, ypad;
6577a84e134Smrg
6585ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
6595ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
6605ec34c4cSmrg      x1 = (Position)(x1 + xpad); y1 = (Position)(y1 + ypad);
6615ec34c4cSmrg      x2 = (Position)(x2 + xpad); y2 = (Position)(y2 + ypad);
6627a84e134Smrg      display = XtDisplayOfObject(w);
6637a84e134Smrg      window = XtWindowOfObject(w);
6647a84e134Smrg    }
6657a84e134Smrg  else
6667a84e134Smrg    {
6677a84e134Smrg      display = XtDisplay(w);
6687a84e134Smrg      window = XtWindow(w);
6697a84e134Smrg    }
6707a84e134Smrg
6717a84e134Smrg  if (id == DRECT)
6725ec34c4cSmrg    XDrawRectangle(display, window, xdata->gc, x1, y1, (unsigned)(x2 - x1), (unsigned)(y2 - y1));
6737a84e134Smrg  else if (id == FRECT)
6745ec34c4cSmrg    XFillRectangle(display, window, xdata->gc, x1, y1, (unsigned)(x2 - x1), (unsigned)(y2 - y1));
6757a84e134Smrg  else if (id == LINE)
6767a84e134Smrg    XDrawLine(display, window, xdata->gc, x1, y1, x2, y2);
6777a84e134Smrg}
6787a84e134Smrg
6797a84e134Smrg/* ARGSUSED */
6807a84e134Smrgstatic void
6815ec34c4cSmrgDlLine(Widget w, XtPointer args, XtPointer data, XEvent *event _X_UNUSED, Region region _X_UNUSED)
6827a84e134Smrg{
6837a84e134Smrg  Dl2Points(w, args, data, LINE);
6847a84e134Smrg}
6857a84e134Smrg
6867a84e134Smrg/* ARGSUSED */
6877a84e134Smrgstatic void
6887a84e134SmrgDlDrawRectangle(Widget w, XtPointer args, XtPointer data,
6895ec34c4cSmrg		XEvent *event _X_UNUSED, Region region _X_UNUSED)
6907a84e134Smrg{
6917a84e134Smrg  Dl2Points(w, args, data, DRECT);
6927a84e134Smrg}
6937a84e134Smrg
6947a84e134Smrg/* ARGSUSED */
6957a84e134Smrgstatic void
6967a84e134SmrgDlFillRectangle(Widget w, XtPointer args, XtPointer data,
6975ec34c4cSmrg		XEvent *event _X_UNUSED, Region region _X_UNUSED)
6987a84e134Smrg{
6997a84e134Smrg  Dl2Points(w, args, data, FRECT);
7007a84e134Smrg}
7017a84e134Smrg
7027a84e134Smrgstatic void
7037a84e134SmrgDlXPoints(Widget w, XtPointer args, XtPointer data, int id)
7047a84e134Smrg{
7057a84e134Smrg  XawDLPositionPtr *pos_ptr = (XawDLPositionPtr *)args;
7067a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
7077a84e134Smrg  XPoint points_buf[16];
7087a84e134Smrg  XPoint *points;
7097a84e134Smrg  Display *display;
7107a84e134Smrg  Window window;
7117a84e134Smrg  Cardinal num_points, i, j;
7127a84e134Smrg
7137a84e134Smrg  num_points = pos_ptr->num_pos>>1;
7147a84e134Smrg  points = (XPoint *)XawStackAlloc(sizeof(XPoint) * num_points, points_buf);
7157a84e134Smrg
7167a84e134Smrg  for (i = j = 0; i < num_points; i++, j = i << 1)
7177a84e134Smrg    {
718efbcb2bfSmrg      XawDLPosition *pos = &pos_ptr->pos[j];
7197a84e134Smrg      points[i].x = X_ARG(pos[0]);
7207a84e134Smrg      points[i].y = Y_ARG(pos[1]);
7217a84e134Smrg    }
7227a84e134Smrg
7237a84e134Smrg  if (!XtIsWidget(w))
7247a84e134Smrg    {
7257a84e134Smrg      Position xpad, ypad;
7267a84e134Smrg
7275ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
7285ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
7297a84e134Smrg      if (xdata->mode != CoordModePrevious)
7307a84e134Smrg	{
7317a84e134Smrg	  for (i = 0; i < num_points; i++)
7327a84e134Smrg	    {
7335ec34c4cSmrg	      points[i].x = (short)(points[i].x + xpad);
7345ec34c4cSmrg	      points[i].y = (short)(points[i].y + ypad);
7357a84e134Smrg	    }
7367a84e134Smrg	}
737efbcb2bfSmrg      else if (num_points != 0)
7387a84e134Smrg	{
7395ec34c4cSmrg	  points[0].x = (short)(points[0].x + xpad);
7405ec34c4cSmrg	  points[0].y = (short)(points[0].y + ypad);
7417a84e134Smrg	}
7427a84e134Smrg      display = XtDisplayOfObject(w);
7437a84e134Smrg      window = XtWindowOfObject(w);
7447a84e134Smrg    }
7457a84e134Smrg  else
7467a84e134Smrg    {
7477a84e134Smrg      display = XtDisplay(w);
7487a84e134Smrg      window = XtWindow(w);
7497a84e134Smrg    }
7507a84e134Smrg
7517a84e134Smrg  if (id == FPOLY)
7525ec34c4cSmrg    XFillPolygon(display, window, xdata->gc, points, (int)num_points,
7537a84e134Smrg		 xdata->shape, xdata->mode);
7547a84e134Smrg  else if (id == DLINES)
7555ec34c4cSmrg    XDrawLines(display, window, xdata->gc, points, (int)num_points, xdata->mode);
7567a84e134Smrg  else if (id == POINTS)
7575ec34c4cSmrg    XDrawPoints(display, window, xdata->gc, points, (int)num_points, xdata->mode);
7587a84e134Smrg
7597a84e134Smrg  XawStackFree(points, points_buf);
7607a84e134Smrg}
7617a84e134Smrg
7627a84e134Smrg/* ARGSUSED */
7637a84e134Smrgstatic void
7647a84e134SmrgDlFillPolygon(Widget w, XtPointer args, XtPointer data,
7655ec34c4cSmrg	      XEvent *event _X_UNUSED, Region region _X_UNUSED)
7667a84e134Smrg{
7677a84e134Smrg  DlXPoints(w, args, data, FPOLY);
7687a84e134Smrg}
7697a84e134Smrg
7707a84e134Smrg/* ARGSUSED */
7717a84e134Smrgstatic void
7727a84e134SmrgDlDrawLines(Widget w, XtPointer args, XtPointer data,
7735ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
7747a84e134Smrg{
7757a84e134Smrg  DlXPoints(w, args, data, DLINES);
7767a84e134Smrg}
7777a84e134Smrg
7787a84e134Smrg/* ARGSUSED */
7797a84e134Smrgstatic void
7807a84e134SmrgDlDrawPoints(Widget w, XtPointer args, XtPointer data,
7815ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
7827a84e134Smrg{
7837a84e134Smrg  DlXPoints(w, args, data, POINTS);
7847a84e134Smrg}
7857a84e134Smrg
7867a84e134Smrg/* ARGSUSED */
7877a84e134Smrgstatic void
7887a84e134SmrgDlForeground(Widget w, XtPointer args, XtPointer data,
7895ec34c4cSmrg	     XEvent *event _X_UNUSED, Region region _X_UNUSED)
7907a84e134Smrg{
7917a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
7927a84e134Smrg  Pixel foreground = (Pixel)args;
7937a84e134Smrg
7947a84e134Smrg  if (xdata->values.foreground != foreground)
7957a84e134Smrg    {
7967a84e134Smrg      xdata->mask |= GCForeground;
7977a84e134Smrg      xdata->values.foreground = foreground;
7987a84e134Smrg      XSetForeground(XtDisplayOfObject(w), xdata->gc, foreground);
7997a84e134Smrg    }
8007a84e134Smrg}
8017a84e134Smrg
8027a84e134Smrg/* ARGSUSED */
8037a84e134Smrgstatic void
8047a84e134SmrgDlBackground(Widget w, XtPointer args, XtPointer data,
8055ec34c4cSmrg	     XEvent *event _X_UNUSED, Region region _X_UNUSED)
8067a84e134Smrg{
8077a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
8087a84e134Smrg  Pixel background = (Pixel)args;
8097a84e134Smrg
8107a84e134Smrg  if (xdata->values.background != background)
8117a84e134Smrg    {
8127a84e134Smrg      xdata->mask |= GCBackground;
8137a84e134Smrg      xdata->values.background = background;
8147a84e134Smrg      XSetBackground(XtDisplayOfObject(w), xdata->gc, background);
8157a84e134Smrg    }
8167a84e134Smrg}
8177a84e134Smrg
8187a84e134Smrgstatic void
8197a84e134SmrgDlArc(Widget w, XtPointer args, XtPointer data, Bool fill)
8207a84e134Smrg{
8217a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
8227a84e134Smrg  XawDLArcArgs *arc = (XawDLArcArgs *)args;
8237a84e134Smrg  Position x1, y1, x2, y2;
8247a84e134Smrg  Display *display;
8257a84e134Smrg  Window window;
8267a84e134Smrg
8277a84e134Smrg  x1 = X_ARG(arc->pos[0]);
8287a84e134Smrg  y1 = Y_ARG(arc->pos[1]);
8297a84e134Smrg  x2 = X_ARG(arc->pos[2]);
8307a84e134Smrg  y2 = Y_ARG(arc->pos[3]);
8317a84e134Smrg
8327a84e134Smrg  if (!XtIsWidget(w))
8337a84e134Smrg    {
8347a84e134Smrg      Position xpad, ypad;
8357a84e134Smrg
8365ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
8375ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
8385ec34c4cSmrg      x1 = (Position)(x1 + xpad);
8395ec34c4cSmrg      y1 = (Position)(y1 + ypad);
8405ec34c4cSmrg      x2 = (Position)(x2 + xpad);
8415ec34c4cSmrg      y2 = (Position)(y2 + ypad);
8427a84e134Smrg      display = XtDisplayOfObject(w);
8437a84e134Smrg      window = XtWindowOfObject(w);
8447a84e134Smrg    }
8457a84e134Smrg  else
8467a84e134Smrg    {
8477a84e134Smrg      display = XtDisplay(w);
8487a84e134Smrg      window = XtWindow(w);
8497a84e134Smrg    }
8507a84e134Smrg
8517a84e134Smrg  if (fill)
8525ec34c4cSmrg    XFillArc(display, window, xdata->gc, x1, y1, (unsigned)(x2 - x1), (unsigned)(y2 - y1),
8537a84e134Smrg	     arc->angle1, arc->angle2);
8547a84e134Smrg  else
8555ec34c4cSmrg    XDrawArc(display, window, xdata->gc, x1, y1, (unsigned)(x2 - x1), (unsigned)(y2 - y1),
8567a84e134Smrg	     arc->angle1, arc->angle2);
8577a84e134Smrg}
8587a84e134Smrg
8597a84e134Smrg/* ARGSUSED */
8607a84e134Smrgstatic void
8617a84e134SmrgDlDrawArc(Widget w, XtPointer args, XtPointer data,
8625ec34c4cSmrg	  XEvent *event _X_UNUSED, Region region _X_UNUSED)
8637a84e134Smrg{
8647a84e134Smrg  DlArc(w, args, data, False);
8657a84e134Smrg}
8667a84e134Smrg
8677a84e134Smrg/* ARGSUSED */
8687a84e134Smrgstatic void
8697a84e134SmrgDlFillArc(Widget w, XtPointer args, XtPointer data,
8705ec34c4cSmrg	  XEvent *event _X_UNUSED, Region region _X_UNUSED)
8717a84e134Smrg{
8727a84e134Smrg  DlArc(w, args, data, True);
8737a84e134Smrg}
8747a84e134Smrg
8757a84e134Smrg/*ARGSUSED*/
8767a84e134Smrgstatic void
8775ec34c4cSmrgDlMask(Widget w, XtPointer args _X_UNUSED, XtPointer data,
8787a84e134Smrg       XEvent *event, Region region)
8797a84e134Smrg{
8807a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
8817a84e134Smrg  Display *display = XtDisplayOfObject(w);
8827a84e134Smrg
8837a84e134Smrg  if (region)
8847a84e134Smrg    XSetRegion(display, xdata->gc, region);
8857a84e134Smrg  else if (event)
8867a84e134Smrg    {
887efbcb2bfSmrg      XRectangle rect =
888efbcb2bfSmrg	{
889efbcb2bfSmrg	  .x = (short)event->xexpose.x,
890efbcb2bfSmrg	  .y = (short)event->xexpose.y,
891efbcb2bfSmrg	  .width = (unsigned short)event->xexpose.width,
892efbcb2bfSmrg	  .height = (unsigned short)event->xexpose.height
893efbcb2bfSmrg	};
8947a84e134Smrg
8957a84e134Smrg      XSetClipRectangles(display, xdata->gc, 0, 0, &rect, 1, Unsorted);
8967a84e134Smrg    }
8977a84e134Smrg}
8987a84e134Smrg
8997a84e134Smrg/* ARGSUSED */
9007a84e134Smrgstatic void
9015ec34c4cSmrgDlUmask(Widget w, XtPointer args _X_UNUSED, XtPointer data,
9025ec34c4cSmrg	XEvent *event _X_UNUSED, Region region _X_UNUSED)
9037a84e134Smrg{
9047a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
9057a84e134Smrg
9067a84e134Smrg  XSetClipMask(XtDisplayOfObject(w), xdata->gc, None);
9077a84e134Smrg}
9087a84e134Smrg
9097a84e134Smrg/* ARGSUSED */
9107a84e134Smrgstatic void
9117a84e134SmrgDlLineWidth(Widget w, XtPointer args, XtPointer data,
9125ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
9137a84e134Smrg{
9147a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
9155ec34c4cSmrg  unsigned line_width = (unsigned)(unsigned long)args;
9167a84e134Smrg
917efbcb2bfSmrg  if ((unsigned)xdata->values.line_width != line_width)
9187a84e134Smrg    {
9197a84e134Smrg      xdata->mask |= GCLineWidth;
9205ec34c4cSmrg      xdata->values.line_width = (int)line_width;
9217a84e134Smrg      XChangeGC(XtDisplayOfObject(w), xdata->gc, GCLineWidth, &xdata->values);
9227a84e134Smrg    }
9237a84e134Smrg}
9247a84e134Smrg
9257a84e134Smrg/* ARGSUSED */
9267a84e134Smrgstatic void
9275ec34c4cSmrgDlDrawPoint(Widget w, XtPointer args, XtPointer data, XEvent *event _X_UNUSED, Region region _X_UNUSED)
9287a84e134Smrg{
9297a84e134Smrg  Dl1Point(w, args, data, POINT);
9307a84e134Smrg}
9317a84e134Smrg
9327a84e134Smrg/* ARGSUSED */
9337a84e134Smrgstatic void
9347a84e134SmrgDlDrawSegments(Widget w, XtPointer args, XtPointer data,
9355ec34c4cSmrg	       XEvent *event _X_UNUSED, Region region _X_UNUSED)
9367a84e134Smrg{
9377a84e134Smrg  XawDLPositionPtr *pos_ptr = (XawDLPositionPtr *)args;
9387a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
9397a84e134Smrg  XSegment *segments;
9407a84e134Smrg  XSegment segments_buf[8];
9417a84e134Smrg  Display *display;
9427a84e134Smrg  Window window;
9437a84e134Smrg  Cardinal num_segments, i, j;
9447a84e134Smrg
9457a84e134Smrg  num_segments = pos_ptr->num_pos>>2;
9467a84e134Smrg  segments = (XSegment *)XawStackAlloc(sizeof(XSegment) * num_segments, segments_buf);
9477a84e134Smrg
9487a84e134Smrg  for (i = j = 0; i < num_segments; i++, j = i << 2)
9497a84e134Smrg    {
950efbcb2bfSmrg      XawDLPosition *pos = &pos_ptr->pos[j];
9517a84e134Smrg      segments[i].x1 = X_ARG(pos[0]);
9527a84e134Smrg      segments[i].y1 = Y_ARG(pos[1]);
9537a84e134Smrg      segments[i].x2 = X_ARG(pos[2]);
9547a84e134Smrg      segments[i].y2 = Y_ARG(pos[3]);
9557a84e134Smrg    }
9567a84e134Smrg
9577a84e134Smrg  if (!XtIsWidget(w))
9587a84e134Smrg    {
9597a84e134Smrg      Position xpad, ypad;
9607a84e134Smrg
9615ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
9625ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
9637a84e134Smrg      for (i = 0; i < num_segments; i++)
9647a84e134Smrg	{
9655ec34c4cSmrg	  segments[i].x1 = (short)(segments[i].x1 + xpad);
9665ec34c4cSmrg	  segments[i].y1 = (short)(segments[i].y1 + ypad);
9675ec34c4cSmrg	  segments[i].x2 = (short)(segments[i].x2 + xpad);
9685ec34c4cSmrg	  segments[i].y2 = (short)(segments[i].y2 + ypad);
9697a84e134Smrg	}
9707a84e134Smrg      display = XtDisplayOfObject(w);
9717a84e134Smrg      window = XtWindowOfObject(w);
9727a84e134Smrg    }
9737a84e134Smrg  else
9747a84e134Smrg    {
9757a84e134Smrg      display = XtDisplay(w);
9767a84e134Smrg      window = XtWindow(w);
9777a84e134Smrg    }
9787a84e134Smrg
9795ec34c4cSmrg  XDrawSegments(display, window, xdata->gc, segments, (int)num_segments);
9807a84e134Smrg
9817a84e134Smrg  XawStackFree(segments, segments_buf);
9827a84e134Smrg}
9837a84e134Smrg
9847a84e134Smrg/* ARGSUSED */
9857a84e134Smrgstatic void
9867a84e134SmrgDlArcMode(Widget w, XtPointer args, XtPointer data,
9875ec34c4cSmrg	  XEvent *event _X_UNUSED, Region region _X_UNUSED)
9887a84e134Smrg{
9897a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
9905ec34c4cSmrg  int arc_mode  = (int)(long)args;
9917a84e134Smrg
9927a84e134Smrg  if (xdata->values.arc_mode != arc_mode)
9937a84e134Smrg    {
9947a84e134Smrg      xdata->mask |= GCArcMode;
9957a84e134Smrg      xdata->values.arc_mode = arc_mode;
9967a84e134Smrg      XSetArcMode(XtDisplayOfObject(w), xdata->gc, arc_mode);
9977a84e134Smrg    }
9987a84e134Smrg}
9997a84e134Smrg
10007a84e134Smrg/* ARGSUSED */
10017a84e134Smrgstatic void
10025ec34c4cSmrgDlCoordMode(Widget w _X_UNUSED, XtPointer args, XtPointer data,
10035ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
10047a84e134Smrg{
10057a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10065ec34c4cSmrg  int mode  = (int)(long)args;
10077a84e134Smrg
10087a84e134Smrg  xdata->mode = mode;
10097a84e134Smrg}
10107a84e134Smrg
10117a84e134Smrg/* ARGSUSED */
10127a84e134Smrgstatic void
10135ec34c4cSmrgDlShapeMode(Widget w _X_UNUSED, XtPointer args, XtPointer data,
10145ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
10157a84e134Smrg{
10167a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10175ec34c4cSmrg  int shape  = (int)(long)args;
10187a84e134Smrg
10197a84e134Smrg  xdata->shape = shape;
10207a84e134Smrg}
10217a84e134Smrg
10227a84e134Smrg/* ARGSUSED */
10237a84e134Smrgstatic void
10247a84e134SmrgDlLineStyle(Widget w, XtPointer args, XtPointer data,
10255ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
10267a84e134Smrg{
10277a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10285ec34c4cSmrg  int line_style = (int)(long)args;
10297a84e134Smrg
10307a84e134Smrg  if (xdata->values.line_style != line_style)
10317a84e134Smrg    {
10327a84e134Smrg      xdata->mask |= GCLineStyle;
10337a84e134Smrg      xdata->values.line_style = line_style;
10347a84e134Smrg      XChangeGC(XtDisplayOfObject(w), xdata->gc, GCLineStyle, &xdata->values);
10357a84e134Smrg    }
10367a84e134Smrg}
10377a84e134Smrg
10387a84e134Smrg/* ARGSUSED */
10397a84e134Smrgstatic void
10407a84e134SmrgDlCapStyle(Widget w, XtPointer args, XtPointer data,
10415ec34c4cSmrg	   XEvent *event _X_UNUSED, Region region _X_UNUSED)
10427a84e134Smrg{
10437a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10445ec34c4cSmrg  int cap_style = (int)(long)args;
10457a84e134Smrg
10467a84e134Smrg  if (xdata->values.cap_style != cap_style)
10477a84e134Smrg    {
10487a84e134Smrg      xdata->mask |= GCCapStyle;
10497a84e134Smrg      xdata->values.cap_style = cap_style;
10507a84e134Smrg      XChangeGC(XtDisplayOfObject(w), xdata->gc, GCCapStyle, &xdata->values);
10517a84e134Smrg    }
10527a84e134Smrg}
10537a84e134Smrg
10547a84e134Smrg/* ARGSUSED */
10557a84e134Smrgstatic void
10567a84e134SmrgDlJoinStyle(Widget w, XtPointer args, XtPointer data,
10575ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
10587a84e134Smrg{
10597a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10605ec34c4cSmrg  int join_style = (int)(long)args;
10617a84e134Smrg
10627a84e134Smrg  if (xdata->values.join_style != join_style)
10637a84e134Smrg    {
10647a84e134Smrg      xdata->mask |= GCJoinStyle;
10657a84e134Smrg      xdata->values.join_style = join_style;
10667a84e134Smrg      XChangeGC(XtDisplayOfObject(w), xdata->gc, GCJoinStyle, &xdata->values);
10677a84e134Smrg    }
10687a84e134Smrg}
10697a84e134Smrg
10707a84e134Smrg/* ARGSUSED */
10717a84e134Smrgstatic void
10727a84e134SmrgDlFillStyle(Widget w, XtPointer args, XtPointer data,
10735ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
10747a84e134Smrg{
10757a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10765ec34c4cSmrg  int fill_style = (int)(long)args;
10777a84e134Smrg
10787a84e134Smrg  if (xdata->values.fill_style != fill_style)
10797a84e134Smrg    {
10807a84e134Smrg      xdata->mask |= GCFillStyle;
10817a84e134Smrg      xdata->values.fill_style = fill_style;
10827a84e134Smrg      XSetFillStyle(XtDisplayOfObject(w), xdata->gc, fill_style);
10837a84e134Smrg    }
10847a84e134Smrg}
10857a84e134Smrg
10867a84e134Smrg/* ARGSUSED */
10877a84e134Smrgstatic void
10887a84e134SmrgDlFillRule(Widget w, XtPointer args, XtPointer data,
10895ec34c4cSmrg	   XEvent *event _X_UNUSED, Region region _X_UNUSED)
10907a84e134Smrg{
10917a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
10925ec34c4cSmrg  int fill_rule = (int)(long)args;
10937a84e134Smrg
10947a84e134Smrg  if (xdata->values.fill_rule != fill_rule)
10957a84e134Smrg    {
10967a84e134Smrg      xdata->mask |= GCFillRule;
10977a84e134Smrg      xdata->values.fill_rule = fill_rule;
10987a84e134Smrg      XSetFillRule(XtDisplayOfObject(w), xdata->gc, fill_rule);
10997a84e134Smrg    }
11007a84e134Smrg}
11017a84e134Smrg
11027a84e134Smrg/* ARGSUSED */
11037a84e134Smrgstatic void
11047a84e134SmrgDlTile(Widget w, XtPointer args, XtPointer data,
11055ec34c4cSmrg       XEvent *event _X_UNUSED, Region region _X_UNUSED)
11067a84e134Smrg{
11077a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
11087a84e134Smrg  XawPixmap *pixmap = (XawPixmap *)args;
11097a84e134Smrg
11107a84e134Smrg  if (pixmap && xdata->values.tile != pixmap->pixmap)
11117a84e134Smrg    {
11127a84e134Smrg      xdata->mask |= GCTile;
11137a84e134Smrg      xdata->values.tile = pixmap->pixmap;
11147a84e134Smrg      XSetTile(XtDisplayOfObject(w), xdata->gc, xdata->values.tile);
11157a84e134Smrg    }
11167a84e134Smrg}
11177a84e134Smrg
11187a84e134Smrg/* ARGSUSED */
11197a84e134Smrgstatic void
11207a84e134SmrgDlStipple(Widget w, XtPointer args, XtPointer data,
11215ec34c4cSmrg	  XEvent *event _X_UNUSED, Region region _X_UNUSED)
11227a84e134Smrg{
11237a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
11247a84e134Smrg  XawPixmap *pixmap = (XawPixmap *)args;
11257a84e134Smrg
11267a84e134Smrg  if (pixmap && xdata->values.stipple != pixmap->pixmap)
11277a84e134Smrg    {
11287a84e134Smrg      xdata->mask |= GCStipple;
11297a84e134Smrg      xdata->values.stipple = pixmap->pixmap;
11307a84e134Smrg      XSetStipple(XtDisplayOfObject(w), xdata->gc, xdata->values.stipple);
11317a84e134Smrg    }
11327a84e134Smrg}
11337a84e134Smrg
11347a84e134Smrg/* ARGSUSED */
11357a84e134Smrgstatic void
11365ec34c4cSmrgDlTSOrigin(Widget w, XtPointer args, XtPointer data, XEvent *event _X_UNUSED, Region region _X_UNUSED)
11377a84e134Smrg{
11387a84e134Smrg  Dl1Point(w, args, data, TSORIGIN);
11397a84e134Smrg}
11407a84e134Smrg
11417a84e134Smrg/* ARGSUSED */
11427a84e134Smrgstatic void
11437a84e134SmrgDlFunction(Widget w, XtPointer args, XtPointer data,
11445ec34c4cSmrg	   XEvent *event _X_UNUSED, Region region _X_UNUSED)
11457a84e134Smrg{
11467a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
11475ec34c4cSmrg  int function = (int)(long)args;
11487a84e134Smrg
11497a84e134Smrg  if (function != xdata->values.function)
11507a84e134Smrg    {
11517a84e134Smrg      xdata->mask |= GCFunction;
11527a84e134Smrg      xdata->values.function = function;
11537a84e134Smrg      XSetFunction(XtDisplayOfObject(w), xdata->gc, function);
11547a84e134Smrg    }
11557a84e134Smrg}
11567a84e134Smrg
11577a84e134Smrg/* ARGSUSED */
11587a84e134Smrgstatic void
11597a84e134SmrgDlPlaneMask(Widget w, XtPointer args, XtPointer data,
11605ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
11617a84e134Smrg{
11627a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
11637a84e134Smrg  unsigned long plane_mask = (unsigned long)args;
11647a84e134Smrg
11657a84e134Smrg  if (xdata->values.plane_mask != plane_mask)
11667a84e134Smrg    {
11677a84e134Smrg      xdata->mask |= GCPlaneMask;
11687a84e134Smrg      xdata->values.plane_mask = plane_mask;
11697a84e134Smrg      XSetPlaneMask(XtDisplayOfObject(w), xdata->gc, plane_mask);
11707a84e134Smrg    }
11717a84e134Smrg}
11727a84e134Smrg
11737a84e134Smrgstatic void
11747a84e134SmrgDlString(Widget w, XtPointer args, XtPointer data, Bool image)
11757a84e134Smrg{
11767a84e134Smrg  XawDLStringArgs *string = (XawDLStringArgs *)args;
11777a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
11787a84e134Smrg  Display *display;
11797a84e134Smrg  Window window;
11807a84e134Smrg  Position x, y;
11817a84e134Smrg
11825ec34c4cSmrg  x = (Position)(X_ARG(string->pos[0]));
11835ec34c4cSmrg  y = (Position)(Y_ARG(string->pos[1]));
11847a84e134Smrg
11857a84e134Smrg  if (!XtIsWidget(w))
11867a84e134Smrg    {
11877a84e134Smrg      Position xpad, ypad;
11887a84e134Smrg
11895ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
11905ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
11915ec34c4cSmrg      x = (Position)(x + xpad);
11925ec34c4cSmrg      y = (Position)(y + ypad);
11937a84e134Smrg      display = XtDisplayOfObject(w);
11947a84e134Smrg      window = XtWindowOfObject(w);
11957a84e134Smrg    }
11967a84e134Smrg  else
11977a84e134Smrg    {
11987a84e134Smrg      display = XtDisplay(w);
11997a84e134Smrg      window = XtWindow(w);
12007a84e134Smrg    }
12017a84e134Smrg
12027a84e134Smrg  if (image)
12037a84e134Smrg    XDrawImageString(display, window, xdata->gc, x, y, string->string, string->length);
12047a84e134Smrg  else
12057a84e134Smrg    XDrawString(display, window, xdata->gc, x, y, string->string, string->length);
12067a84e134Smrg}
12077a84e134Smrg
12087a84e134Smrg/* ARGSUSED */
12097a84e134Smrgstatic void
12107a84e134SmrgDlDrawString(Widget w, XtPointer args, XtPointer data,
12115ec34c4cSmrg	     XEvent *event _X_UNUSED, Region region _X_UNUSED)
12127a84e134Smrg{
12137a84e134Smrg  DlString(w, args, data, False);
12147a84e134Smrg}
12157a84e134Smrg
12167a84e134Smrg/* ARGSUSED */
12177a84e134Smrgstatic void
12187a84e134SmrgDlPaintString(Widget w, XtPointer args, XtPointer data,
12195ec34c4cSmrg	      XEvent *event _X_UNUSED, Region region _X_UNUSED)
12207a84e134Smrg{
12217a84e134Smrg  DlString(w, args, data, True);
12227a84e134Smrg}
12237a84e134Smrg
12247a84e134Smrg/* ARGSUSED */
12257a84e134Smrgstatic void
12267a84e134SmrgDlFont(Widget w, XtPointer args, XtPointer data,
12275ec34c4cSmrg       XEvent *event _X_UNUSED, Region region _X_UNUSED)
12287a84e134Smrg{
12297a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
12307a84e134Smrg  Font font = (Font)args;
12317a84e134Smrg
12327a84e134Smrg  if (xdata->values.font != font)
12337a84e134Smrg    {
12347a84e134Smrg      xdata->mask |= GCFont;
12357a84e134Smrg      xdata->values.font = font;
12367a84e134Smrg      XSetFont(XtDisplayOfObject(w), xdata->gc, font);
12377a84e134Smrg    }
12387a84e134Smrg}
12397a84e134Smrg
12407a84e134Smrg/* ARGSUSED */
12417a84e134Smrgstatic void
12427a84e134SmrgDlDashes(Widget w, XtPointer args, XtPointer data,
12435ec34c4cSmrg	 XEvent *event _X_UNUSED, Region region _X_UNUSED)
12447a84e134Smrg{
12457a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
12467a84e134Smrg  char *dashes = args;
12477a84e134Smrg
12487a84e134Smrg  if (xdata->dashes != dashes)
12497a84e134Smrg    {
12507a84e134Smrg      xdata->mask |= GCDashOffset | GCDashList;
12517a84e134Smrg      xdata->dashes = dashes;
12527a84e134Smrg      XSetDashes(XtDisplayOfObject(w), xdata->gc, 0, dashes + 1, *dashes);
12537a84e134Smrg    }
12547a84e134Smrg}
12557a84e134Smrg
12567a84e134Smrg/* ARGSUSED */
12577a84e134Smrgstatic void
12587a84e134SmrgDlSubwindowMode(Widget w, XtPointer args, XtPointer data,
12595ec34c4cSmrg		XEvent *event _X_UNUSED, Region region _X_UNUSED)
12607a84e134Smrg{
12617a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
12625ec34c4cSmrg  int subwindow_mode = (int)(long)args;
12637a84e134Smrg
12647a84e134Smrg  if (xdata->values.subwindow_mode != subwindow_mode)
12657a84e134Smrg    {
12667a84e134Smrg      xdata->mask |= GCSubwindowMode;
12677a84e134Smrg      xdata->values.subwindow_mode = subwindow_mode;
12687a84e134Smrg      XSetSubwindowMode(XtDisplayOfObject(w), xdata->gc, subwindow_mode);
12697a84e134Smrg    }
12707a84e134Smrg}
12717a84e134Smrg
12727a84e134Smrg/* ARGSUSED */
12737a84e134Smrgstatic void
12747a84e134SmrgDlExposures(Widget w, XtPointer args, XtPointer data,
12755ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
12767a84e134Smrg{
12777a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
12787a84e134Smrg  Bool graphics_exposures = (Bool)(long)args;
12797a84e134Smrg
12807a84e134Smrg  if (xdata->values.graphics_exposures != graphics_exposures)
12817a84e134Smrg    {
12827a84e134Smrg      xdata->mask |= GCGraphicsExposures;
12837a84e134Smrg      xdata->values.graphics_exposures = graphics_exposures;
12847a84e134Smrg      XSetGraphicsExposures(XtDisplayOfObject(w), xdata->gc, graphics_exposures);
12857a84e134Smrg    }
12867a84e134Smrg}
12877a84e134Smrg
12887a84e134Smrg/* ARGSUSED */
12897a84e134Smrgstatic void
12905ec34c4cSmrgDlClipOrigin(Widget w, XtPointer args, XtPointer data, XEvent *event _X_UNUSED, Region region _X_UNUSED)
12917a84e134Smrg{
12927a84e134Smrg  Dl1Point(w, args, data, CLIPORIGIN);
12937a84e134Smrg}
12947a84e134Smrg
12957a84e134Smrg/* ARGSUSED */
12967a84e134Smrgstatic void
12977a84e134SmrgDlClipMask(Widget w, XtPointer args, XtPointer data,
12985ec34c4cSmrg	   XEvent *event _X_UNUSED, Region region _X_UNUSED)
12997a84e134Smrg{
13007a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
13017a84e134Smrg  XawPixmap *pixmap = (XawPixmap *)args;
13027a84e134Smrg  Pixmap clip_mask;
13037a84e134Smrg
13047a84e134Smrg  if (pixmap)
13057a84e134Smrg    clip_mask = pixmap->mask ? pixmap->mask : pixmap->pixmap;
13067a84e134Smrg  else
13077a84e134Smrg    clip_mask = None;
13087a84e134Smrg
13097a84e134Smrg  if (xdata->values.clip_mask != clip_mask)
13107a84e134Smrg    {
13117a84e134Smrg      xdata->mask |= GCClipMask;
13127a84e134Smrg      XSetClipMask(XtDisplayOfObject(w), xdata->gc, clip_mask);
13137a84e134Smrg    }
13147a84e134Smrg}
13157a84e134Smrg
13167a84e134Smrg/* ARGSUSED */
13177a84e134Smrgstatic void
13187a84e134SmrgDlClipRectangles(Widget w, XtPointer args, XtPointer data,
13195ec34c4cSmrg		 XEvent *event _X_UNUSED, Region region _X_UNUSED)
13207a84e134Smrg{
13217a84e134Smrg  XawDLPositionPtr *pos_ptr = (XawDLPositionPtr *)args;
13227a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
13237a84e134Smrg  XRectangle *rects;
13247a84e134Smrg  XRectangle rects_buf[8];
13257a84e134Smrg  Cardinal num_rects, i, j;
13267a84e134Smrg
13277a84e134Smrg  num_rects = pos_ptr->num_pos>>2;
13287a84e134Smrg  rects = (XRectangle *)XawStackAlloc(sizeof(XRectangle) * num_rects, rects_buf);
13297a84e134Smrg
13307a84e134Smrg  for (i = j = 0; i < num_rects; i++, j = i << 2)
13317a84e134Smrg    {
1332efbcb2bfSmrg      XawDLPosition *pos = &pos_ptr->pos[j];
1333efbcb2bfSmrg      Position x1 = X_ARG(pos[0]);
1334efbcb2bfSmrg      Position y1 = Y_ARG(pos[1]);
1335efbcb2bfSmrg      Position x2 = X_ARG(pos[2]);
1336efbcb2bfSmrg      Position y2 = Y_ARG(pos[3]);
13377a84e134Smrg      rects[i].x = XawMin(x1, x2);
13387a84e134Smrg      rects[i].y = XawMin(y1, y2);
13395ec34c4cSmrg      rects[i].width = (unsigned short)(XawMax(x1, x2) - rects[i].x);
13405ec34c4cSmrg      rects[i].height = (unsigned short)(XawMax(y1, y2) - rects[i].y);
13417a84e134Smrg    }
13427a84e134Smrg
13437a84e134Smrg  if (!XtIsWidget(w))
13447a84e134Smrg    {
13457a84e134Smrg      Position xpad, ypad;
13467a84e134Smrg
13475ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
13485ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
13497a84e134Smrg      for (i = 0; i < num_rects; i++)
13507a84e134Smrg	{
13515ec34c4cSmrg	  rects[i].x = (short)(rects[i].x + xpad);
13525ec34c4cSmrg	  rects[i].y = (short)(rects[i].y + ypad);
13537a84e134Smrg	}
13547a84e134Smrg    }
13557a84e134Smrg
13565ec34c4cSmrg  XSetClipRectangles(XtDisplayOfObject(w), xdata->gc, 0, 0, rects, (int)num_rects, Unsorted);
13577a84e134Smrg
13587a84e134Smrg  XawStackFree(rects, rects_buf);
13597a84e134Smrg}
13607a84e134Smrg
13617a84e134Smrgstatic void
13627a84e134SmrgDlCopy(Widget w, XtPointer args, XtPointer data, Bool plane)
13637a84e134Smrg{
13647a84e134Smrg  XawDLCopyArgs *copy = (XawDLCopyArgs *)args;
13657a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
13667a84e134Smrg  int src_x, src_y, dst_x, dst_y, width, height, tmp1, tmp2;
13677a84e134Smrg
13687a84e134Smrg  tmp1 = X_ARG(copy->pos[0]);
13697a84e134Smrg  tmp2 = X_ARG(copy->pos[2]);
13707a84e134Smrg  dst_x = XawMin(tmp1, tmp2);
13717a84e134Smrg  width = XawMax(tmp1, tmp2) - dst_x;
13727a84e134Smrg
13737a84e134Smrg  tmp1 = Y_ARG(copy->pos[1]);
13747a84e134Smrg  tmp2 = Y_ARG(copy->pos[3]);
13757a84e134Smrg  dst_y = XawMin(tmp1, tmp2);
13767a84e134Smrg  height = XawMax(tmp1, tmp2) - dst_y;
13777a84e134Smrg
13787a84e134Smrg  src_x = X_ARG(copy->pos[4]);
13797a84e134Smrg  src_y = Y_ARG(copy->pos[5]);
13807a84e134Smrg
13817a84e134Smrg  if (width <= 0)
13827a84e134Smrg    {
13837a84e134Smrg      if (copy->pixmap)
13847a84e134Smrg	width = copy->pixmap->width;
13857a84e134Smrg      else
13867a84e134Smrg	{
13877a84e134Smrg	  if ((width = XtWidth(w) - src_x) < 0)
13887a84e134Smrg	    width = 0;
13897a84e134Smrg	}
13907a84e134Smrg    }
13917a84e134Smrg  if (height <= 0)
13927a84e134Smrg    {
13937a84e134Smrg      if (copy->pixmap)
13947a84e134Smrg	height = copy->pixmap->height;
13957a84e134Smrg      else
13967a84e134Smrg	{
13977a84e134Smrg	  if ((height = XtHeight(w) - src_y) < 0)
13987a84e134Smrg	    height = 0;
13997a84e134Smrg	}
14007a84e134Smrg    }
14017a84e134Smrg
14027a84e134Smrg  if (!XtIsWidget(w))
14037a84e134Smrg    {
14047a84e134Smrg      Position xpad, ypad;
14057a84e134Smrg
14065ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
14075ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
14087a84e134Smrg      src_x += xpad;
14097a84e134Smrg      src_y += ypad;
14107a84e134Smrg      dst_x += xpad;
14117a84e134Smrg      dst_y += ypad;
14127a84e134Smrg    }
14137a84e134Smrg
14147a84e134Smrg  if (plane)
14157a84e134Smrg    XCopyPlane(XtDisplayOfObject(w), XtWindowOfObject(w),
14167a84e134Smrg	       copy->pixmap ? copy->pixmap->pixmap : XtWindowOfObject(w),
14175ec34c4cSmrg	       xdata->gc, src_x, src_y, (unsigned)width, (unsigned)height, dst_x, dst_y,
14185ec34c4cSmrg	       (unsigned long)(copy->plane ? copy->plane : 1));
14197a84e134Smrg  else
14207a84e134Smrg    XCopyArea(XtDisplayOfObject(w),
14217a84e134Smrg	      copy->pixmap ? copy->pixmap->pixmap : XtWindowOfObject(w),
14225ec34c4cSmrg	      XtWindowOfObject(w), xdata->gc, src_x, src_y, (unsigned)width, (unsigned)height, dst_x, dst_y);
14237a84e134Smrg}
14247a84e134Smrg
14257a84e134Smrg/* ARGSUSED */
14267a84e134Smrgstatic void
14277a84e134SmrgDlCopyArea(Widget w, XtPointer args, XtPointer data,
14285ec34c4cSmrg	   XEvent *event _X_UNUSED, Region region _X_UNUSED)
14297a84e134Smrg{
14307a84e134Smrg  DlCopy(w, args, data, False);
14317a84e134Smrg}
14327a84e134Smrg
14337a84e134Smrg/* ARGSUSED */
14347a84e134Smrgstatic void
14357a84e134SmrgDlCopyPlane(Widget w, XtPointer args, XtPointer data,
14365ec34c4cSmrg	    XEvent *event _X_UNUSED, Region region _X_UNUSED)
14377a84e134Smrg{
14387a84e134Smrg  DlCopy(w, args, data, True);
14397a84e134Smrg}
14407a84e134Smrg
14417a84e134Smrg/*ARGSUSED*/
14427a84e134Smrg/* Note:
14437a84e134Smrg *	  This function is destructive if you set the ts_x_origin, ts_y_origin,
14447a84e134Smrg *	and/or clip-mask. It is meant to be the only function used in a display
14457a84e134Smrg *	list. If you need to use other functions (and those values), be sure to
14467a84e134Smrg *	set them after calling this function.
14477a84e134Smrg */
14487a84e134Smrgstatic void
14495ec34c4cSmrgDlImage(Widget w, XtPointer args, XtPointer data, XEvent *event _X_UNUSED, Region region _X_UNUSED)
14507a84e134Smrg{
14517a84e134Smrg  XawDLImageArgs *image = (XawDLImageArgs *)args;
14527a84e134Smrg  XawXlibData *xdata = (XawXlibData *)data;
14537a84e134Smrg  int x, y, xs, ys, xe, ye, width, height;
14547a84e134Smrg  Display *display;
14557a84e134Smrg  Window window;
14567a84e134Smrg
14577a84e134Smrg  width = image->pixmap->width;
14587a84e134Smrg  height = image->pixmap->height;
14597a84e134Smrg  xs = X_ARG(image->pos[0]);
14607a84e134Smrg  ys = Y_ARG(image->pos[1]);
14617a84e134Smrg  xe = X_ARG(image->pos[2]);
14627a84e134Smrg  ye = Y_ARG(image->pos[3]);
14637a84e134Smrg
14647a84e134Smrg  if (xe <= 0)
14657a84e134Smrg    xe = xs + width;
14667a84e134Smrg  if (ye <= 0)
14677a84e134Smrg    ye = ys + height;
14687a84e134Smrg
14697a84e134Smrg  if (!XtIsWidget(w))
14707a84e134Smrg    {
14717a84e134Smrg      Position xpad, ypad;
14727a84e134Smrg
14735ec34c4cSmrg      xpad = (Position)(XtX(w) + XtBorderWidth(w));
14745ec34c4cSmrg      ypad = (Position)(XtY(w) + XtBorderWidth(w));
14757a84e134Smrg      xe += xpad;
14767a84e134Smrg      ye += ypad;
14777a84e134Smrg      xe += xpad;
14787a84e134Smrg      ye += ypad;
14797a84e134Smrg      display = XtDisplayOfObject(w);
14807a84e134Smrg      window = XtWindowOfObject(w);
14817a84e134Smrg    }
14827a84e134Smrg  else
14837a84e134Smrg    {
14847a84e134Smrg      display = XtDisplay(w);
14857a84e134Smrg      window = XtWindow(w);
14867a84e134Smrg    }
14877a84e134Smrg
14887a84e134Smrg  for (y = ys; y < ye; y += height)
14897a84e134Smrg    for (x = xs; x < xe; x += width)
14907a84e134Smrg      {
14917a84e134Smrg	XSetClipOrigin(display, xdata->gc, x, y);
14927a84e134Smrg	if (image->pixmap->mask)
14937a84e134Smrg	  XSetClipMask(display, xdata->gc, image->pixmap->mask);
14947a84e134Smrg	if (image->depth == 1)
14957a84e134Smrg	  XCopyPlane(display, image->pixmap->pixmap, window, xdata->gc,
14965ec34c4cSmrg		     0, 0, (unsigned)XawMin(width, xe - x), (unsigned)XawMin(height, ye - y),
14977a84e134Smrg		     x, y, 1L);
14987a84e134Smrg	else
14997a84e134Smrg	  XCopyArea(display, image->pixmap->pixmap, window, xdata->gc, 0, 0,
15005ec34c4cSmrg		     (unsigned)XawMin(width, xe - x), (unsigned)XawMin(height, ye - y), x, y);
15017a84e134Smrg      }
15027a84e134Smrg
15037a84e134Smrg  XSetClipMask(display, xdata->gc, None);
15047a84e134Smrg}
15057a84e134Smrg
15067a84e134Smrgtypedef struct _Dl_init Dl_init;
15077a84e134Smrgstruct _Dl_init {
15087a84e134Smrg  String name;
15097a84e134Smrg  XawDisplayListProc proc;
15107a84e134Smrg  Cardinal id;
15117a84e134Smrg};
15127a84e134Smrg
15137a84e134Smrgstatic Dl_init dl_init[] =
15147a84e134Smrg{
15157a84e134Smrg  {"arc-mode",		DlArcMode,		ARCMODE},
15167a84e134Smrg  {"background",	DlBackground,		GCBG},
15177a84e134Smrg  {"bg",		DlBackground,		GCBG},
15187a84e134Smrg  {"cap-style",		DlCapStyle,		CAPSTYLE},
15197a84e134Smrg  {"clip-mask",		DlClipMask,		CLIPMASK},
15207a84e134Smrg  {"clip-origin",	DlClipOrigin,		CLIPORIGIN},
15217a84e134Smrg  {"clip-rectangles",	DlClipRectangles,	CLIPRECTS},
15227a84e134Smrg  {"clip-rects",	DlClipRectangles,	CLIPRECTS},
15237a84e134Smrg  {"coord-mode",	DlCoordMode,		COORDMODE},
15247a84e134Smrg  {"copy-area",		DlCopyArea,		COPYAREA},
15257a84e134Smrg  {"copy-plane",	DlCopyPlane,		COPYPLANE},
15267a84e134Smrg  {"dashes",		DlDashes,		DASHES},
15277a84e134Smrg  {"draw-arc",		DlDrawArc,		DARC},
15287a84e134Smrg  {"draw-line",		DlLine,			LINE},
15297a84e134Smrg  {"draw-lines",	DlDrawLines,		DLINES},
15307a84e134Smrg  {"draw-point",	DlDrawPoint,		POINT},
15317a84e134Smrg  {"draw-points",	DlDrawPoints,		POINTS},
15327a84e134Smrg  {"draw-rect",		DlDrawRectangle,	DRECT},
15337a84e134Smrg  {"draw-rectangle",	DlDrawRectangle,	DRECT},
15347a84e134Smrg  {"draw-segments",	DlDrawSegments,		SEGMENTS},
15357a84e134Smrg  {"draw-string",	DlDrawString,		DSTRING},
15367a84e134Smrg  {"exposures",		DlExposures,		EXPOSURES},
15377a84e134Smrg  {"fg",		DlForeground,		GCFG},
15387a84e134Smrg  {"fill-arc",		DlFillArc,		FARC},
15397a84e134Smrg  {"fill-poly",		DlFillPolygon,		FPOLY},
15407a84e134Smrg  {"fill-polygon",	DlFillPolygon,		FPOLY},
15417a84e134Smrg  {"fill-rect",		DlFillRectangle,	FRECT},
15427a84e134Smrg  {"fill-rectangle",	DlFillRectangle,	FRECT},
15437a84e134Smrg  {"fill-rule",		DlFillRule,		FILLRULE},
15447a84e134Smrg  {"fill-style",	DlFillStyle,		FILLSTYLE},
15457a84e134Smrg  {"font",		DlFont,			FONT},
15467a84e134Smrg  {"foreground",	DlForeground,		GCFG},
15477a84e134Smrg  {"function",		DlFunction,		FUNCTION},
15487a84e134Smrg  {"image",		DlImage,		IMAGE},
15497a84e134Smrg  {"join-style",	DlJoinStyle,		JOINSTYLE},
15507a84e134Smrg  {"line",		DlLine,			LINE},
15517a84e134Smrg  {"line-style",	DlLineStyle,		LINESTYLE},
15527a84e134Smrg  {"line-width",	DlLineWidth,		LWIDTH},
15537a84e134Smrg  {"lines",		DlDrawLines,		DLINES},
15547a84e134Smrg  {"mask",		DlMask,			MASK},
15557a84e134Smrg  {"paint-string",	DlPaintString,		PSTRING},
15567a84e134Smrg  {"plane-mask",	DlPlaneMask,		PLANEMASK},
15577a84e134Smrg  {"point",		DlDrawPoint,		POINT},
15587a84e134Smrg  {"points",		DlDrawPoints,		POINTS},
15597a84e134Smrg  {"segments",		DlDrawSegments,		SEGMENTS},
15607a84e134Smrg  {"shape-mode",	DlShapeMode,		SHAPEMODE},
15617a84e134Smrg  {"stipple",		DlStipple,		STIPPLE},
15627a84e134Smrg  {"subwindow-mode",	DlSubwindowMode,	SUBWMODE},
15637a84e134Smrg  {"tile",		DlTile,			TILE},
15647a84e134Smrg  {"ts-origin",		DlTSOrigin,		TSORIGIN},
15657a84e134Smrg  {"umask",		DlUmask,		UMASK},
15667a84e134Smrg};
15677a84e134Smrg
15687a84e134Smrgvoid
15697a84e134SmrgXawDisplayListInitialize(void)
15707a84e134Smrg{
15717a84e134Smrg  static Bool first_time = True;
15727a84e134Smrg  XawDLClass *lc;
15737a84e134Smrg  Cardinal i;
15747a84e134Smrg
15757a84e134Smrg  if (first_time == False)
15767a84e134Smrg    return;
15777a84e134Smrg
15787a84e134Smrg  first_time = False;
15797a84e134Smrg
15807a84e134Smrg  lc = XawCreateDisplayListClass(xlib,
15817a84e134Smrg				 _Xaw_Xlib_ArgsInitProc,
15827a84e134Smrg				 _Xaw_Xlib_ArgsDestructor,
15837a84e134Smrg				 _Xaw_Xlib_DataInitProc,
15847a84e134Smrg				 _Xaw_Xlib_DataDestructor);
15857a84e134Smrg  for (i = 0; i < sizeof(dl_init) / sizeof(dl_init[0]); i++)
15867a84e134Smrg    (void)XawDeclareDisplayListProc(lc, dl_init[i].name, dl_init[i].proc);
15877a84e134Smrg}
15887a84e134Smrg
15897a84e134Smrgstatic int
15907a84e134Smrgbcmp_cvt_proc(register _Xconst void *string,
15917a84e134Smrg	      register _Xconst void *dlinfo)
15927a84e134Smrg{
15937a84e134Smrg  return (strcmp((String)string, ((Dl_init*)dlinfo)->name));
15947a84e134Smrg}
15957a84e134Smrg
15967a84e134Smrgstatic long
15977a84e134Smrgread_int(char *cp, char **cpp)
15987a84e134Smrg{
15997a84e134Smrg  long value = 0, sign = 1;
16007a84e134Smrg
16017a84e134Smrg  if (*cp == '-')
16027a84e134Smrg    {
16037a84e134Smrg      sign = -1;
16047a84e134Smrg      ++cp;
16057a84e134Smrg    }
16067a84e134Smrg  else if (*cp == '+')
16077a84e134Smrg    ++cp;
16087a84e134Smrg  value = 0;
16097a84e134Smrg  while (*cp >= '0' && *cp <= '9')
16107a84e134Smrg    {
16117a84e134Smrg      value = value * 10 + *cp - '0';
16127a84e134Smrg      ++cp;
16137a84e134Smrg    }
16147a84e134Smrg  if (cpp)
16157a84e134Smrg    *cpp = cp;
16167a84e134Smrg  return (value * sign);
16177a84e134Smrg}
16187a84e134Smrg
16197a84e134Smrgstatic void
16207a84e134Smrgread_position(char *arg, XawDLPosition *pos)
16217a84e134Smrg{
16227a84e134Smrg  int ch;
16237a84e134Smrg  char *str = arg;
16247a84e134Smrg
16257a84e134Smrg  ch = *str;
16267a84e134Smrg  if (ch == '-' || ch == '+')
16277a84e134Smrg    {
16287a84e134Smrg      ++str;
16297a84e134Smrg      if (ch == '-')
16307a84e134Smrg	pos->high = True;
16315ec34c4cSmrg      pos->pos = (Position)read_int(str, NULL);
16327a84e134Smrg    }
16337a84e134Smrg  else if (isdigit(ch))
16347a84e134Smrg    {
16355ec34c4cSmrg      pos->pos = (Position)read_int(str, &str);
16367a84e134Smrg      ch = *str++;
16377a84e134Smrg      if (ch == '/')
16385ec34c4cSmrg	pos->denom = (Position)read_int(str, NULL);
16397a84e134Smrg    }
16407a84e134Smrg}
16417a84e134Smrg
16427a84e134Smrg/* ARGSUSED */
16437a84e134Smrgstatic void *
16447a84e134Smrg_Xaw_Xlib_ArgsInitProc(String proc_name, String *params, Cardinal *num_params,
16457a84e134Smrg		       Screen *screen, Colormap colormap, int depth)
16467a84e134Smrg{
16477a84e134Smrg  Cardinal id, i;
16487a84e134Smrg  Dl_init *init;
16497a84e134Smrg  void *retval = XAWDL_CONVERT_ERROR;
16507a84e134Smrg
16517a84e134Smrg  init = (Dl_init *)bsearch(proc_name, dl_init,
16527a84e134Smrg			    sizeof(dl_init) / sizeof(dl_init[0]),
16537a84e134Smrg			    sizeof(dl_init[0]),
16547a84e134Smrg			    bcmp_cvt_proc);
16557a84e134Smrg
16567a84e134Smrg  id = init->id;
16577a84e134Smrg
16587a84e134Smrg  switch (id)
16597a84e134Smrg    {
16607a84e134Smrg    case LINE:
16617a84e134Smrg    case DRECT:
16627a84e134Smrg    case FRECT:
16637a84e134Smrg      if (*num_params == 4)
16647a84e134Smrg	{
16657a84e134Smrg	  XawDLPosition *pos = (XawDLPosition *)XtCalloc(1, sizeof(XawDLPosition) * 4);
16667a84e134Smrg
16677a84e134Smrg	  for (i = 0; i < 4; i++)
16685ec34c4cSmrg	    read_position((char *)params[i], &pos[i]);
16697a84e134Smrg	  retval = (void *)pos;
16707a84e134Smrg	}
16717a84e134Smrg      break;
16727a84e134Smrg    case POINT:
16737a84e134Smrg    case TSORIGIN:
16747a84e134Smrg    case CLIPORIGIN:
16757a84e134Smrg      if (*num_params == 2)
16767a84e134Smrg	{
16777a84e134Smrg	  XawDLPosition *pos = (XawDLPosition *)XtCalloc(1, sizeof(XawDLPosition) * 2);
16787a84e134Smrg
16795ec34c4cSmrg	  read_position((char *)params[0], &pos[0]);
16805ec34c4cSmrg	  read_position((char *)params[1], &pos[1]);
16817a84e134Smrg	  retval = (void *)pos;
16827a84e134Smrg	}
16837a84e134Smrg      break;
16847a84e134Smrg    case DLINES:
16857a84e134Smrg    case FPOLY:
16867a84e134Smrg    case POINTS:
16877a84e134Smrg      if (*num_params >= 4 && !(*num_params & 1))
16887a84e134Smrg	{
16897a84e134Smrg	  XawDLPositionPtr *pos = XtNew(XawDLPositionPtr);
16907a84e134Smrg
16915ec34c4cSmrg	  pos->pos = (XawDLPosition *)XtCalloc(1, (Cardinal)(sizeof(XawDLPosition) *
16925ec34c4cSmrg					       (size_t)*num_params));
16937a84e134Smrg	  pos->num_pos = *num_params;
16947a84e134Smrg	  for (i = 0; i < *num_params; i++)
16955ec34c4cSmrg	    read_position((char *)params[i], &pos->pos[i]);
16967a84e134Smrg	  retval = (void *)pos;
16977a84e134Smrg	}
16987a84e134Smrg      break;
16997a84e134Smrg    case SEGMENTS:
17007a84e134Smrg    case CLIPRECTS:
17017a84e134Smrg      if (*num_params >= 4 && !(*num_params % 4))
17027a84e134Smrg	{
17037a84e134Smrg	  XawDLPositionPtr *pos = XtNew(XawDLPositionPtr);
17047a84e134Smrg
17055ec34c4cSmrg	  pos->pos = (XawDLPosition *)XtCalloc(1, (Cardinal)(sizeof(XawDLPosition) *
17065ec34c4cSmrg					       (size_t)*num_params));
17077a84e134Smrg	  pos->num_pos = *num_params;
17087a84e134Smrg	  for (i = 0; i < *num_params; i++)
17095ec34c4cSmrg	    read_position((char *)params[i], &pos->pos[i]);
17107a84e134Smrg	  retval = (void *)pos;
17117a84e134Smrg	}
17127a84e134Smrg      break;
17137a84e134Smrg    case DARC:
17147a84e134Smrg    case FARC:
17157a84e134Smrg      if (*num_params >= 4 && *num_params <= 6)
17167a84e134Smrg	{
17177a84e134Smrg	  XawDLArcArgs *args = (XawDLArcArgs *)XtCalloc(1, sizeof(XawDLArcArgs));
17187a84e134Smrg
17197a84e134Smrg	  args->angle1 = 0;
17207a84e134Smrg	  args->angle2 = 360;
17217a84e134Smrg	  for (i = 0; i < 4; i++)
17225ec34c4cSmrg	    read_position((char *)params[i], &args->pos[i]);
17237a84e134Smrg	  if (*num_params > 4)
17245ec34c4cSmrg	    args->angle1 = (int)read_int((char *)params[4], NULL);
17257a84e134Smrg	  if (*num_params > 5)
17265ec34c4cSmrg	    args->angle2 = (int)read_int((char *)params[5], NULL);
17277a84e134Smrg	  args->angle1 *= 64;
17287a84e134Smrg	  args->angle2 *= 64;
17297a84e134Smrg	  retval = (void *)args;
17307a84e134Smrg	}
17317a84e134Smrg      break;
17327a84e134Smrg    case GCFG:
17337a84e134Smrg    case GCBG:
17347a84e134Smrg      {
17357a84e134Smrg	XColor xcolor;
17367a84e134Smrg
17377a84e134Smrg	if (*num_params == 1 &&
17387a84e134Smrg	    XAllocNamedColor(DisplayOfScreen(screen), colormap,
17397a84e134Smrg			     params[0], &xcolor, &xcolor))
17407a84e134Smrg	  retval = (void *)xcolor.pixel;
17417a84e134Smrg      } break;
17427a84e134Smrg    case MASK:
17437a84e134Smrg    case UMASK:
17447a84e134Smrg      if (*num_params == 0)
17457a84e134Smrg	retval = NULL;
17467a84e134Smrg      break;
17477a84e134Smrg    case LWIDTH:
17487a84e134Smrg      if (*num_params == 1)
1749efbcb2bfSmrg	{
1750efbcb2bfSmrg	  long x = read_int((char *)params[0], NULL);
1751efbcb2bfSmrg	  retval = (void *)x;
1752efbcb2bfSmrg	}
17537a84e134Smrg      break;
17547a84e134Smrg    case ARCMODE:
17557a84e134Smrg      if (*num_params == 1)
17567a84e134Smrg	{
17577a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "pieslice") == 0)
17587a84e134Smrg	    retval = (void *)ArcPieSlice;
17597a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "chord") == 0)
17607a84e134Smrg	    retval = (void *)ArcChord;
17617a84e134Smrg	}
17627a84e134Smrg      break;
17637a84e134Smrg    case COORDMODE:
17647a84e134Smrg      if (*num_params == 1)
17657a84e134Smrg	{
17667a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "origin") == 0)
17677a84e134Smrg	    retval = (void *)CoordModeOrigin;
17687a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "previous") == 0)
17697a84e134Smrg	    retval = (void *)CoordModePrevious;
17707a84e134Smrg	}
17717a84e134Smrg      break;
17727a84e134Smrg    case SHAPEMODE:
17737a84e134Smrg      if (*num_params == 1)
17747a84e134Smrg	{
17757a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "complex") == 0)
17767a84e134Smrg	    retval = (void *)Complex;
17777a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "convex") == 0)
17787a84e134Smrg	    retval = (void *)Convex;
17797a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "nonconvex") == 0)
17807a84e134Smrg	    retval = (void *)Nonconvex;
17817a84e134Smrg	}
17827a84e134Smrg      break;
17837a84e134Smrg    case LINESTYLE:
17847a84e134Smrg      if (*num_params == 1)
17857a84e134Smrg	{
17867a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "solid") == 0)
17877a84e134Smrg	    retval = (void *)LineSolid;
17887a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "onoffdash") == 0)
17897a84e134Smrg	    retval = (void *)LineOnOffDash;
17907a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "doubledash") == 0)
17917a84e134Smrg	    retval = (void *)LineDoubleDash;
17927a84e134Smrg	}
17937a84e134Smrg      break;
17947a84e134Smrg    case CAPSTYLE:
17957a84e134Smrg      if (*num_params == 1)
17967a84e134Smrg	{
17977a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "notlast") == 0)
17987a84e134Smrg	    retval = (void *)CapNotLast;
17997a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "butt") == 0)
18007a84e134Smrg	    retval = (void *)CapButt;
18017a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "round") == 0)
18027a84e134Smrg	    retval = (void *)CapRound;
18037a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "projecting") == 0)
18047a84e134Smrg	    retval = (void *)CapProjecting;
18057a84e134Smrg	}
18067a84e134Smrg      break;
18077a84e134Smrg    case JOINSTYLE:
18087a84e134Smrg      if (*num_params == 1)
18097a84e134Smrg	{
18107a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "miter") == 0)
18117a84e134Smrg	    retval = (void *)JoinMiter;
18127a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "round") == 0)
18137a84e134Smrg	    retval = (void *)JoinRound;
18147a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "bevel") == 0)
18157a84e134Smrg	    retval = (void *)JoinBevel;
18167a84e134Smrg	}
18177a84e134Smrg      break;
18187a84e134Smrg    case FILLSTYLE:
18197a84e134Smrg      if (*num_params == 1)
18207a84e134Smrg	{
18217a84e134Smrg	  if (*num_params && XmuCompareISOLatin1(params[0], "solid") == 0)
18227a84e134Smrg	    retval = (void *)FillSolid;
18237a84e134Smrg	  else if (*num_params && XmuCompareISOLatin1(params[0], "tiled") == 0)
18247a84e134Smrg	    retval = (void *)FillTiled;
18257a84e134Smrg	  else if (*num_params && XmuCompareISOLatin1(params[0], "stippled") == 0)
18267a84e134Smrg	    retval = (void *)FillStippled;
18277a84e134Smrg	  else if (*num_params && XmuCompareISOLatin1(params[0], "opaquestippled") == 0)
18287a84e134Smrg	    retval = (void *)FillOpaqueStippled;
18297a84e134Smrg	}
18307a84e134Smrg      break;
18317a84e134Smrg    case FILLRULE:
18327a84e134Smrg      if (*num_params == 1)
18337a84e134Smrg	{
18347a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "evenodd") == 0)
18357a84e134Smrg	    retval = (void *)EvenOddRule;
18367a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "winding") == 0)
18377a84e134Smrg	    retval = (void *)WindingRule;
18387a84e134Smrg	}
18397a84e134Smrg      break;
18407a84e134Smrg    case TILE:
18417a84e134Smrg      if (*num_params == 1)
18427a84e134Smrg	retval = (void *)XawLoadPixmap(params[0], screen, colormap, depth);
18437a84e134Smrg      if (retval == NULL)
18447a84e134Smrg	{
18457a84e134Smrg	  XtDisplayStringConversionWarning(DisplayOfScreen(screen), (String)params[0],
18467a84e134Smrg					   XtRPixmap);
18477a84e134Smrg	  retval = XAWDL_CONVERT_ERROR;
18487a84e134Smrg	}
18497a84e134Smrg      break;
18507a84e134Smrg    case STIPPLE:
18517a84e134Smrg      if (*num_params == 1)
18527a84e134Smrg	retval = (void *)XawLoadPixmap(params[0], screen, colormap, 1);
18537a84e134Smrg      if (retval == NULL)
18547a84e134Smrg	{
18557a84e134Smrg	  XtDisplayStringConversionWarning(DisplayOfScreen(screen), (String)params[0],
18567a84e134Smrg					   XtRBitmap);
18577a84e134Smrg	  retval = XAWDL_CONVERT_ERROR;
18587a84e134Smrg	}
18597a84e134Smrg      break;
18607a84e134Smrg    case FUNCTION:
18617a84e134Smrg      if (*num_params == 1)
18627a84e134Smrg	{
18637a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "set") == 0)
18647a84e134Smrg	    retval = (void *)GXset;
18657a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "clear") == 0)
18667a84e134Smrg	    retval = (void *)GXclear;
18677a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "and") == 0)
18687a84e134Smrg	    retval = (void *)GXand;
18697a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "andreverse") == 0)
18707a84e134Smrg	    retval = (void *)GXandReverse;
18717a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "copy") == 0)
18727a84e134Smrg	    retval = (void *)GXcopy;
18737a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "andinverted") == 0)
18747a84e134Smrg	    retval = (void *)GXandInverted;
18757a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "noop") == 0)
18767a84e134Smrg	    retval = (void *)GXnoop;
18777a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "xor") == 0)
18787a84e134Smrg	    retval = (void *)GXxor;
18797a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "or") == 0)
18807a84e134Smrg	    retval = (void *)GXor;
18817a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "nor") == 0)
18827a84e134Smrg	    retval = (void *)GXnor;
18837a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "equiv") == 0)
18847a84e134Smrg	    retval = (void *)GXequiv;
18857a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "invert") == 0)
18867a84e134Smrg	    retval = (void *)GXinvert;
18877a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "orreverse") == 0)
18887a84e134Smrg	    retval = (void *)GXorReverse;
18897a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "copyinverted") == 0)
18907a84e134Smrg	    retval = (void *)GXcopyInverted;
18917a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "nand") == 0)
18927a84e134Smrg	    retval = (void *)GXnand;
18937a84e134Smrg	}
18947a84e134Smrg      break;
18957a84e134Smrg    case PLANEMASK:
18967a84e134Smrg      if (*num_params == 1)
1897efbcb2bfSmrg	{
1898efbcb2bfSmrg	  long x = read_int((char *)params[0], NULL);
1899efbcb2bfSmrg	  retval = (void *)x;
1900efbcb2bfSmrg	}
19017a84e134Smrg      break;
19027a84e134Smrg    case DSTRING:
19037a84e134Smrg    case PSTRING:
19047a84e134Smrg      if (*num_params == 3)
19057a84e134Smrg	{
19067a84e134Smrg	  XawDLStringArgs *string = (XawDLStringArgs *)
19077a84e134Smrg		XtCalloc(1, sizeof(XawDLStringArgs));
19087a84e134Smrg
19095ec34c4cSmrg	  read_position((char *)params[0], &string->pos[0]);
19105ec34c4cSmrg	  read_position((char *)params[1], &string->pos[1]);
19117a84e134Smrg	  string->string = XtNewString(params[2]);
19125ec34c4cSmrg	  string->length = (int)strlen(string->string);
19137a84e134Smrg	  retval = string;
19147a84e134Smrg	}
19157a84e134Smrg      break;
19167a84e134Smrg    case FONT:
19177a84e134Smrg      if (*num_params == 1)
1918efbcb2bfSmrg	{
1919efbcb2bfSmrg	  Font x = XLoadFont(DisplayOfScreen(screen), params[0]);
1920efbcb2bfSmrg	  retval = (void *)x;
1921efbcb2bfSmrg	}
19227a84e134Smrg      break;
19237a84e134Smrg    case DASHES:
19247a84e134Smrg      if (*num_params && *num_params < 127)
19257a84e134Smrg	{
19267a84e134Smrg	  char *dashes;
19277a84e134Smrg
19287a84e134Smrg	  dashes = XtMalloc(*num_params + 1);
19297a84e134Smrg
19307a84e134Smrg	  for (i = 0; i < *num_params; i++)
19315ec34c4cSmrg	    dashes[i + 1] = (char)read_int((char *)params[i], NULL);
19325ec34c4cSmrg	  *dashes = (char)*num_params;
19337a84e134Smrg	  retval = dashes;
19347a84e134Smrg	}
19357a84e134Smrg      break;
19367a84e134Smrg    case SUBWMODE:
19377a84e134Smrg      if (*num_params == 1)
19387a84e134Smrg	{
19397a84e134Smrg	  if (XmuCompareISOLatin1(params[0], "clipbychildren") == 0)
19407a84e134Smrg	    retval = (void *)ClipByChildren;
19417a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "includeinferiors") == 0)
19427a84e134Smrg	    retval = (void *)IncludeInferiors;
19437a84e134Smrg	}
19447a84e134Smrg      break;
19457a84e134Smrg    case EXPOSURES:
19467a84e134Smrg      if (*num_params == 1)
19477a84e134Smrg	{
19485b16253fSmrg	  if (isdigit((unsigned char)params[0][0]) || params[0][0] == '+' || params[0][0] == '-')
1949efbcb2bfSmrg	    {
1950efbcb2bfSmrg	      long x = read_int((char *)params[0], NULL);
1951efbcb2bfSmrg	      retval = (void *)x;
1952efbcb2bfSmrg	    }
19537a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "true") == 0 ||
19547a84e134Smrg	    XmuCompareISOLatin1(params[0], "on") == 0)
19557a84e134Smrg	    retval = (void *)True;
19567a84e134Smrg	  else if (XmuCompareISOLatin1(params[0], "false") == 0 ||
19577a84e134Smrg	    XmuCompareISOLatin1(params[0], "off") == 0)
19587a84e134Smrg	    retval = (void *)False;
19597a84e134Smrg	}
19607a84e134Smrg      break;
19617a84e134Smrg    case CLIPMASK:
19627a84e134Smrg      if (*num_params == 1)
19637a84e134Smrg	retval = (void *)XawLoadPixmap(params[0], screen, colormap, 1);
19647a84e134Smrg      if (retval == NULL)
19657a84e134Smrg	{
19667a84e134Smrg	  retval = XAWDL_CONVERT_ERROR;
19677a84e134Smrg	  XtDisplayStringConversionWarning(DisplayOfScreen(screen), (String)params[0],
19687a84e134Smrg					   XtRPixmap);
19697a84e134Smrg	}
19707a84e134Smrg      break;
19717a84e134Smrg    case COPYAREA:
19727a84e134Smrg    case COPYPLANE:
19737a84e134Smrg      if (*num_params > 2 && *num_params <= 7 + (id == COPYPLANE))
19747a84e134Smrg	{
19757a84e134Smrg	  XawDLCopyArgs *args = (XawDLCopyArgs *)
19767a84e134Smrg		XtCalloc(1, sizeof(XawDLCopyArgs));
19777a84e134Smrg
19787a84e134Smrg	  retval = args;
19797a84e134Smrg	  if (params[0][0] == '\0' || strcmp(params[0], ".") == 0)
19807a84e134Smrg	    args->pixmap = NULL;
19817a84e134Smrg	  else
19827a84e134Smrg	   {
19837a84e134Smrg	     args->pixmap = XawLoadPixmap(params[0], screen, colormap, id == COPYPLANE ? 1 : depth);
19847a84e134Smrg	     if (args->pixmap == NULL)
19857a84e134Smrg	      {
19867a84e134Smrg		XtDisplayStringConversionWarning(DisplayOfScreen(screen), (String)params[0],
19877a84e134Smrg						 XtRBitmap);
19887a84e134Smrg		retval = XAWDL_CONVERT_ERROR;
19897a84e134Smrg		XtFree((char *)args);
19907a84e134Smrg	      }
19917a84e134Smrg	  }
19927a84e134Smrg	  if (retval != XAWDL_CONVERT_ERROR)
19937a84e134Smrg	    {
19947a84e134Smrg	      for (i = 1; i < *num_params && i < 7; i++)
19955ec34c4cSmrg		read_position((char *)params[i], &args->pos[i - 1]);
19967a84e134Smrg	      if (*num_params > 7)
19975ec34c4cSmrg		args->plane = (int)read_int((char *)params[7], NULL);
19987a84e134Smrg	    }
19997a84e134Smrg	}
20007a84e134Smrg      break;
20017a84e134Smrg    case IMAGE:
20027a84e134Smrg      if (*num_params > 2 && *num_params <= 7)
20037a84e134Smrg	{
20047a84e134Smrg	  XawDLImageArgs *args = (XawDLImageArgs *)
20057a84e134Smrg		XtCalloc(1, sizeof(XawDLImageArgs));
20067a84e134Smrg
20077a84e134Smrg	  retval = args;
20087a84e134Smrg	  args->pixmap = XawLoadPixmap(params[0], screen, colormap, depth);
20097a84e134Smrg	  if (args->pixmap == NULL)
20107a84e134Smrg	    {
20117a84e134Smrg	      XtDisplayStringConversionWarning(DisplayOfScreen(screen),
20127a84e134Smrg					       (String)params[0], XtRPixmap);
20137a84e134Smrg	      retval = XAWDL_CONVERT_ERROR;
20147a84e134Smrg	      XtFree((char *)args);
20157a84e134Smrg	    }
20167a84e134Smrg	  else
20177a84e134Smrg	    {
20187a84e134Smrg	      args->depth = depth;
20197a84e134Smrg	      for (i = 1; i < *num_params && i < 5; i++)
20205ec34c4cSmrg		read_position((char *)params[i], &args->pos[i - 1]);
20217a84e134Smrg	    }
20227a84e134Smrg	}
20237a84e134Smrg      break;
20247a84e134Smrg    }
20257a84e134Smrg
20267a84e134Smrg  return (retval);
20277a84e134Smrg}
20287a84e134Smrg
20297a84e134Smrg/* ARGSUSED */
20307a84e134Smrgstatic void *
20315ec34c4cSmrg_Xaw_Xlib_DataInitProc(String class_name _X_UNUSED,
20325ec34c4cSmrg		       Screen *screen _X_UNUSED, Colormap colormap _X_UNUSED, int depth)
20337a84e134Smrg{
20347a84e134Smrg  XawXlibData *data;
20357a84e134Smrg  Window tmp_win;
20367a84e134Smrg
20377a84e134Smrg  data = (XawXlibData *)XtMalloc(sizeof(XawXlibData));
20387a84e134Smrg
20397a84e134Smrg  tmp_win = XCreateWindow(DisplayOfScreen(screen),
20407a84e134Smrg			  RootWindowOfScreen(screen),
20417a84e134Smrg			  0, 0, 1, 1, 1, depth,
2042775e7de9Smrg			  InputOutput, (Visual *)CopyFromParent, 0, NULL);
20437a84e134Smrg  data->mask = 0;
20447a84e134Smrg  data->gc = XCreateGC(DisplayOfScreen(screen), tmp_win, 0, &data->values);
20457a84e134Smrg  XDestroyWindow(DisplayOfScreen(screen), tmp_win);
20467a84e134Smrg  data->shape = Complex;
20477a84e134Smrg  data->mode = CoordModeOrigin;
20487a84e134Smrg  data->dashes = NULL;
20497a84e134Smrg
20507a84e134Smrg  return ((void *)data);
20517a84e134Smrg}
20527a84e134Smrg
20537a84e134Smrg/* ARGSUSED */
20547a84e134Smrgstatic void
20555ec34c4cSmrg_Xaw_Xlib_ArgsDestructor(Display *display _X_UNUSED, String proc_name, XtPointer args,
20565ec34c4cSmrg			 String *params _X_UNUSED, Cardinal *num_params _X_UNUSED)
20577a84e134Smrg{
20587a84e134Smrg  Cardinal id;
20597a84e134Smrg  Dl_init *init;
20607a84e134Smrg
20617a84e134Smrg  init = (Dl_init *)bsearch(proc_name, dl_init,
20627a84e134Smrg			    sizeof(dl_init) / sizeof(dl_init[0]),
20637a84e134Smrg			    sizeof(dl_init[0]),
20647a84e134Smrg			    bcmp_cvt_proc);
20657a84e134Smrg
20667a84e134Smrg  id = init->id;
20677a84e134Smrg
20687a84e134Smrg  switch (id)
20697a84e134Smrg    {
20707a84e134Smrg    case LINE:
20717a84e134Smrg    case DRECT:
20727a84e134Smrg    case FRECT:
20737a84e134Smrg    case DARC:
20747a84e134Smrg    case FARC:
20757a84e134Smrg    case POINT:
20767a84e134Smrg    case TSORIGIN:
20777a84e134Smrg    case DASHES:
20787a84e134Smrg    case CLIPORIGIN:
20797a84e134Smrg    case COPYAREA:
20807a84e134Smrg    case COPYPLANE:
20817a84e134Smrg    case IMAGE:
20827a84e134Smrg      XtFree(args);
20837a84e134Smrg      break;
20847a84e134Smrg    case DSTRING:
20857a84e134Smrg    case PSTRING:
20867a84e134Smrg      {
20877a84e134Smrg	XawDLStringArgs *string = (XawDLStringArgs *)args;
20887a84e134Smrg	XtFree(string->string);
20897a84e134Smrg	XtFree(args);
20907a84e134Smrg      } break;
20917a84e134Smrg    case DLINES:
20927a84e134Smrg    case FPOLY:
20937a84e134Smrg    case POINTS:
20947a84e134Smrg    case SEGMENTS:
20957a84e134Smrg    case CLIPRECTS:
20967a84e134Smrg      {
20977a84e134Smrg	XawDLPositionPtr *ptr = (XawDLPositionPtr *)args;
20987a84e134Smrg
20997a84e134Smrg	XtFree((char *)ptr->pos);
21007a84e134Smrg	XtFree(args);
21017a84e134Smrg      } break;
21027a84e134Smrg    }
21037a84e134Smrg}
21047a84e134Smrg
21057a84e134Smrg/* ARGSUSED */
21067a84e134Smrgstatic void
21075ec34c4cSmrg_Xaw_Xlib_DataDestructor(Display *display, String class_name _X_UNUSED, XtPointer data)
21087a84e134Smrg{
21097a84e134Smrg  if (data)
21107a84e134Smrg    {
21117a84e134Smrg      XawXlibData *xdata = (XawXlibData *)data;
21127a84e134Smrg
21137a84e134Smrg      XFreeGC(display, xdata->gc);
21147a84e134Smrg      if (xdata->dashes)
21157a84e134Smrg	XtFree(xdata->dashes);
21167a84e134Smrg      XtFree((char *)data);
21177a84e134Smrg    }
21187a84e134Smrg}
21197a84e134Smrg
21207a84e134Smrg/* Start of DLInfo Management Functions */
21217a84e134Smrgstatic int
21227a84e134Smrgqcmp_dlist_info(register _Xconst void *left, register _Xconst void *right)
21237a84e134Smrg{
21247a84e134Smrg  return (strcmp((*(XawDLInfo **)left)->name, (*(XawDLInfo **)right)->name));
21257a84e134Smrg}
21267a84e134Smrg
21277a84e134SmrgBool XawDeclareDisplayListProc(XawDLClass *lc, String name,
21287a84e134Smrg				  XawDisplayListProc proc)
21297a84e134Smrg{
21307a84e134Smrg  XawDLInfo *info;
21317a84e134Smrg
21327a84e134Smrg  if (!lc || !proc || !name || name[0] == '\0')
21337a84e134Smrg    return (False);
21347a84e134Smrg
2135efbcb2bfSmrg  if (_XawFindDLInfo(lc, name) != NULL)
21367a84e134Smrg    /* Since the data structures to the displayList classes are(should be)
21377a84e134Smrg     * opaque, it is not a good idea to allow overriding a displayList
21387a84e134Smrg     * procedure; it's better to choose another name or class name!
21397a84e134Smrg     */
21407a84e134Smrg    return (False);
21417a84e134Smrg
21427a84e134Smrg  info = (XawDLInfo *)XtMalloc(sizeof(XawDLInfo));
21437a84e134Smrg  info->name = XtNewString(name);
21447a84e134Smrg  info->qname = XrmStringToQuark(info->name);
21457a84e134Smrg  info->proc = proc;
21467a84e134Smrg
21477a84e134Smrg  if (!lc->num_infos)
21487a84e134Smrg    {
21497a84e134Smrg      lc->num_infos = 1;
21507a84e134Smrg      lc->infos = (XawDLInfo **)XtMalloc(sizeof(XawDLInfo*));
21517a84e134Smrg    }
21527a84e134Smrg  else
21537a84e134Smrg    {
21547a84e134Smrg      ++lc->num_infos;
21557a84e134Smrg      lc->infos = (XawDLInfo **)
21565ec34c4cSmrg	XtRealloc((char *)lc->infos, (Cardinal)(sizeof(XawDLInfo*) * (size_t)lc->num_infos));
21577a84e134Smrg    }
21587a84e134Smrg  lc->infos[lc->num_infos - 1] = info;
21597a84e134Smrg
21607a84e134Smrg  if (lc->num_infos > 1)
21617a84e134Smrg    qsort(lc->infos, lc->num_infos, sizeof(XawDLInfo*), qcmp_dlist_info);
21627a84e134Smrg
21637a84e134Smrg  return (True);
21647a84e134Smrg}
21657a84e134Smrg
21667a84e134Smrgstatic int
21677a84e134Smrgbcmp_dlist_info(register _Xconst void *string,
21687a84e134Smrg		register _Xconst void *dlinfo)
21697a84e134Smrg{
21707a84e134Smrg  return (strcmp((String)string, (*(XawDLClass **)dlinfo)->name));
21717a84e134Smrg}
21727a84e134Smrg
21737a84e134Smrgstatic XawDLInfo *
21747a84e134Smrg_XawFindDLInfo(XawDLClass *lc, String name)
21757a84e134Smrg{
21767a84e134Smrg  XawDLInfo **info;
21777a84e134Smrg
21787a84e134Smrg  if (!lc->infos)
21797a84e134Smrg    return (NULL);
21807a84e134Smrg
21817a84e134Smrg  info = (XawDLInfo **)bsearch(name, lc->infos, lc->num_infos,
21827a84e134Smrg			       sizeof(XawDLInfo*), bcmp_dlist_info);
21837a84e134Smrg
21847a84e134Smrg  return (info ? *info : NULL);
21857a84e134Smrg}
21867a84e134Smrg
21877a84e134Smrg/* Start of DLClass Management Functions */
21887a84e134SmrgXawDLClass *
21897a84e134SmrgXawGetDisplayListClass(String name)
21907a84e134Smrg{
21917a84e134Smrg  return (_XawFindDLClass(name));
21927a84e134Smrg}
21937a84e134Smrg
21947a84e134Smrgstatic int
21957a84e134Smrgqcmp_dlist_class(register _Xconst void *left, register _Xconst void *right)
21967a84e134Smrg{
21977a84e134Smrg  return (strcmp((*(XawDLClass **)left)->name, (*(XawDLClass **)right)->name));
21987a84e134Smrg}
21997a84e134Smrg
22007a84e134SmrgXawDLClass *
22017a84e134SmrgXawCreateDisplayListClass(String name,
22027a84e134Smrg			  XawDLArgsInitProc args_init,
22037a84e134Smrg			  XawDLArgsDestructor args_destructor,
22047a84e134Smrg			  XawDLDataInitProc data_init,
22057a84e134Smrg			  XawDLDataDestructor data_destructor)
22067a84e134Smrg{
22077a84e134Smrg  XawDLClass *lc;
22087a84e134Smrg
22097a84e134Smrg  if (!name || name[0] == '\0')
22107a84e134Smrg    return (NULL);
22117a84e134Smrg
22127a84e134Smrg  lc = (XawDLClass *)XtMalloc(sizeof(XawDLClass));
22137a84e134Smrg  lc->name = XtNewString(name);
22147a84e134Smrg  lc->infos = NULL;
22157a84e134Smrg  lc->num_infos = 0;
22167a84e134Smrg  lc->args_init = args_init;
22177a84e134Smrg  lc->args_destructor = args_destructor;
22187a84e134Smrg  lc->data_init = data_init;
22197a84e134Smrg  lc->data_destructor = data_destructor;
22207a84e134Smrg
22217a84e134Smrg  if (!classes)
22227a84e134Smrg    {
22237a84e134Smrg      num_classes = 1;
22247a84e134Smrg      classes = (XawDLClass **)XtMalloc(sizeof(XawDLClass));
22257a84e134Smrg    }
22267a84e134Smrg  else
22277a84e134Smrg    {
22287a84e134Smrg      ++num_classes;
22297a84e134Smrg      classes = (XawDLClass **)XtRealloc((char *)classes,
22305ec34c4cSmrg					 (Cardinal)(sizeof(XawDLClass) * (size_t)num_classes));
22317a84e134Smrg    }
22327a84e134Smrg  classes[num_classes - 1] = lc;
22337a84e134Smrg
22347a84e134Smrg  if (num_classes > 1)
22357a84e134Smrg    qsort(&classes[0], num_classes, sizeof(XawDLClass*), qcmp_dlist_class);
22367a84e134Smrg
22377a84e134Smrg  return (lc);
22387a84e134Smrg}
22397a84e134Smrg
22407a84e134Smrgstatic int
22417a84e134Smrgbcmp_dlist_class(register _Xconst void *string,
22427a84e134Smrg		 register _Xconst void *dlist)
22437a84e134Smrg{
22447a84e134Smrg  return (strcmp((String)string, (*(XawDLClass **)dlist)->name));
22457a84e134Smrg}
22467a84e134Smrg
22477a84e134Smrgstatic XawDLClass *
22487a84e134Smrg_XawFindDLClass(String name)
22497a84e134Smrg{
22507a84e134Smrg  XawDLClass **lc;
22517a84e134Smrg
22527a84e134Smrg  if (!classes)
22537a84e134Smrg    return (NULL);
22547a84e134Smrg
22557a84e134Smrg  lc = (XawDLClass **)bsearch(name, &classes[0], num_classes,
22567a84e134Smrg			      sizeof(XawDLClass*), bcmp_dlist_class);
22577a84e134Smrg
22587a84e134Smrg  return (lc ? *lc : NULL);
22597a84e134Smrg}
22607a84e134Smrg
22617a84e134Smrg#endif /* OLDXAW */
2262