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