⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 garray.c

📁 Graphviz - Graph Drawing Programs from AT&T Research and Lucent Bell Labs See doc/build.html for
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: garray.c,v 1.2 2005/04/08 20:45:34 erg Exp $ $Revision: 1.2 $ *//* vim:set shiftwidth=4 ts=8: *//***********************************************************      This software is part of the graphviz package      **                http://www.graphviz.org/                 **                                                         **            Copyright (c) 1994-2004 AT&T Corp.           **                and is licensed under the                **            Common Public License, Version 1.0           **                      by AT&T Corp.                      **                                                         **        Information and Software Systems Research        **              AT&T Research, Florham Park NJ             ***********************************************************//* Lefteris Koutsofios - AT&T Labs Research */#include "common.h"#include "g.h"#include "gcommon.h"#include "mem.h"#define WAU widget->u.aextern WidgetClass arrayWidgetClass;static void awcallback (Widget, XtPointer, XtPointer);int GAcreatewidget (    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    PIXsize_t ps;    int ai;    XColor c;    int color;    if (!parent) {        Gerr (POS, G_ERRNOPARENTWIDGET);        return -1;    }    WAU->func = NULL;    ps.x = ps.y = MINAWSIZE;    RESETARGS;    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRSIZE:            GETSIZE (attrp[ai].u.s, ps, MINAWSIZE);            break;        case G_ATTRBORDERWIDTH:            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);            break;        case G_ATTRMODE:            if (strcmp ("horizontal", attrp[ai].u.t) == 0) {                ADD2ARGS (XtNorientation, XtorientHorizontal);                WAU->mode = G_AWHARRAY;            } else if (strcmp ("vertical", attrp[ai].u.t) == 0) {                WAU->mode = G_AWVARRAY;            } else {                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);                return -1;            }            break;        case G_ATTRLAYOUT:            if (strcmp ("on", attrp[ai].u.t) == 0)                Gawsetmode (widget, FALSE);            else if (strcmp ("off", attrp[ai].u.t) == 0)                Gawsetmode (widget, TRUE);            else {                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);                return -1;            }            break;        case G_ATTRCOLOR:            color = attrp[ai].u.c.index;            if (color != 0 && color != 1) {                Gerr (POS, G_ERRBADCOLORINDEX, color);                return -1;            }            c.red = attrp[ai].u.c.r * 257;            c.green = attrp[ai].u.c.g * 257;            c.blue = attrp[ai].u.c.b * 257;            if (XAllocColor (                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c            )) {                if (color == 0)                    ADD2ARGS (XtNbackground, c.pixel);                else                    ADD2ARGS (XtNforeground, c.pixel);	    }            break;        case G_ATTRWINDOWID:            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");            return -1;        case G_ATTRRESIZECB:            WAU->func = (Gawcoordscb) attrp[ai].u.func;            break;        case G_ATTRUSERDATA:            widget->udata = attrp[ai].u.u;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    ADD2ARGS (XtNwidth, ps.x);    ADD2ARGS (XtNheight, ps.y);    if (!(widget->w = XtCreateWidget (        "array", arrayWidgetClass, parent->w, argp, argn    ))) {        Gerr (POS, G_ERRCANNOTCREATEWIDGET);        return -1;    }    XtAddCallback (widget->w, XtNcallback, awcallback, (XtPointer) NULL);    Glazymanage (widget->w);    return 0;}int GAsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    PIXsize_t ps;    int ai;    RESETARGS;    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRSIZE:            GETSIZE (attrp[ai].u.s, ps, MINAWSIZE);            ADD2ARGS (XtNwidth, ps.x);            ADD2ARGS (XtNheight, ps.y);            break;        case G_ATTRBORDERWIDTH:            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);            break;        case G_ATTRMODE:            Gerr (POS, G_ERRCANNOTSETATTR2, "mode");            return -1;        case G_ATTRLAYOUT:            if (strcmp ("on", attrp[ai].u.t) == 0)                Gawsetmode (widget, FALSE);            else if (strcmp ("off", attrp[ai].u.t) == 0)                Gawsetmode (widget, TRUE);            else {                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);                return -1;            }            break;        case G_ATTRWINDOWID:            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");            return -1;        case G_ATTRRESIZECB:            WAU->func = (Gawcoordscb) attrp[ai].u.func;            break;        case G_ATTRUSERDATA:            widget->udata = attrp[ai].u.u;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    XtSetValues (widget->w, argp, argn);    return 0;}int GAgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    Dimension width, height;    int ai;    for (ai = 0; ai < attrn; ai++) {        RESETARGS;        switch (attrp[ai].id) {        case G_ATTRSIZE:            ADD2ARGS (XtNwidth, &width);            ADD2ARGS (XtNheight, &height);            XtGetValues (widget->w, argp, argn);            attrp[ai].u.s.x = width, attrp[ai].u.s.y = height;            break;        case G_ATTRBORDERWIDTH:            ADD2ARGS (XtNborderWidth, &width);            XtGetValues (widget->w, argp, argn);            attrp[ai].u.i = width;            break;        case G_ATTRMODE:            attrp[ai].u.t = (                WAU->mode == G_AWHARRAY            ) ? "horizontal" : "vertical";            break;        case G_ATTRLAYOUT:            attrp[ai].u.t = (Gawgetmode (widget)) ? "off" : "on";            break;        case G_ATTRWINDOWID:            sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w));            attrp[ai].u.t = &Gbufp[0];            break;        case G_ATTRRESIZECB:            attrp[ai].u.func = WAU->func;            break;        case G_ATTRUSERDATA:            attrp[ai].u.u = widget->udata;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    return 0;}int GAdestroywidget (Gwidget_t *widget) {    XtDestroyWidget (widget->w);    return 0;}static void awcallback (Widget w, XtPointer clientdata, XtPointer calldata) {    Gwidget_t *widget;    if (!(widget = findwidget ((unsigned long) w, G_ARRAYWIDGET)))        return;    if (WAU->func)        (*WAU->func) (widget - &Gwidgets[0], (Gawdata_t *) calldata);    else        Gawdefcoordscb (widget - &Gwidgets[0], (Gawdata_t *) calldata);}/* the rest of this file contains the implementation of the array widget */#include <X11/IntrinsicP.h>typedef struct _ArrayClassRec *ArrayWidgetClass;typedef struct _ArrayRec *ArrayWidget;typedef struct _ArrayClassPart {    int dummy; /* not used */} ArrayClassPart;typedef struct _ArrayClassRec {    CoreClassPart core_class;    CompositeClassPart composite_class;    ArrayClassPart array_class;} ArrayClassRec;typedef struct _ArrayPart {    XtCallbackList callbacks;    XtOrientation orientation;    Gawdata_t data;    int batchmode;} ArrayPart;typedef struct _ArrayRec {    CorePart core;    CompositePart composite;    ArrayPart array;} ArrayRec;#define CHILDINCR 10#define CHILDSIZE sizeof (Gawcarray_t)static XtResource resources[] = {    {        XtNcallback,        XtCCallback,        XtRCallback,        sizeof (XtPointer),        XtOffsetOf (ArrayRec, array.callbacks),        XtRCallback, (XtPointer) NULL    },    {        XtNorientation,        XtCOrientation,        XtROrientation,        sizeof (XtOrientation),        XtOffsetOf (ArrayRec, array.orientation),        XtRImmediate, (XtPointer) XtorientVertical    }};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -