#include <stdio.h>
#include <X11/Xos.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Toggle.h>
#include "xgc.h"
static void change_dashlist(Widget, caddr_t, caddr_t);
static short dashlist = 240;
static Widget *dashes;
void
create_dashlist_choice(Widget w)
{
static XtCallbackRec callbacklist[] = {
{(XtCallbackProc) change_dashlist, NULL},
{NULL, NULL}
};
static Arg labelargs[] = {
{XtNborderWidth, (XtArgVal) 0},
{XtNjustify, (XtArgVal) XtJustifyRight},
{XtNvertDistance, (XtArgVal) 4}
};
static Arg dashargs[] = {
{XtNcallback, (XtArgVal) NULL},
{XtNhorizDistance, (XtArgVal) NULL},
{XtNfromHoriz, (XtArgVal) NULL},
{XtNwidth, (XtArgVal) 10},
{XtNheight, (XtArgVal) 10},
{XtNhighlightThickness, (XtArgVal) 1},
{XtNstate, (XtArgVal) False},
{XtNlabel, (XtArgVal) ""}
};
static Widget label;
static int *dashinfo;
int i;
char name[11];
dashes = (Widget *) malloc(DASHLENGTH * sizeof(Widget));
dashinfo = (int *) malloc(DASHLENGTH * sizeof(int));
label = XtCreateManagedWidget("dashlist",labelWidgetClass,w,
labelargs,XtNumber(labelargs));
dashargs[0].value = (XtArgVal) callbacklist;
for (i=0;i<DASHLENGTH;++i) {
if (i==0) {
dashargs[1].value = (XtArgVal) 10;
dashargs[2].value = (XtArgVal) label;
}
else {
dashargs[1].value = (XtArgVal) -1;
dashargs[2].value = (XtArgVal) dashes[i-1];
}
if (dashlist&1<<i)
dashargs[6].value = (XtArgVal) True;
else
dashargs[6].value = (XtArgVal) False;
snprintf(name, sizeof name, "dashlist%d",i);
dashinfo[i] = i;
callbacklist[0].closure = (caddr_t) &dashinfo[i];
dashes[i] = XtCreateManagedWidget(name,toggleWidgetClass,w,
dashargs,XtNumber(dashargs));
}
}
static void
change_dashlist(Widget w, caddr_t closure, caddr_t call_data)
{
int num;
Boolean on;
char buf[80];
static Arg args[] = {
{XtNstate, (XtArgVal) NULL}
};
args[0].value = (XtArgVal) &on;
num = * (int *) closure;
XtGetValues(w,args,XtNumber(args));
if (on) {
dashlist |= 1<<num;
}
else {
dashlist &= ~(1<<num);
}
snprintf(buf, sizeof buf, "dashlist %d\n",dashlist);
interpret(buf);
}
void
update_dashlist(int newdash)
{
int i;
static Arg dashargs[] = {
{XtNstate, (XtArgVal) NULL}
};
dashlist = newdash;
for (i = 0; i < DASHLENGTH; ++i) {
if (newdash & 1<<i)
dashargs[0].value = (XtArgVal) True;
else
dashargs[0].value = (XtArgVal) False;
XtSetValues(dashes[i],dashargs,XtNumber(dashargs));
}
}