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