From c88b16647fadc6650251e425a2fceef687ab2231 Mon Sep 17 00:00:00 2001 From: erg Date: Fri, 8 Apr 2005 20:45:34 +0000 Subject: [PATCH] Update with new lefty, fixing many bugs and supporting new features --- cmd/lefty/ws/x11/gpcanvas.c | 894 ++++++++++++++++++------------------ cmd/lefty/ws/x11/gquery.c | 477 ++++++++++--------- cmd/lefty/ws/x11/gscroll.c | 390 ++++++++-------- cmd/lefty/ws/x11/gtext.c | 457 +++++++++--------- cmd/lefty/ws/x11/gview.c | 335 +++++++------- 5 files changed, 1281 insertions(+), 1272 deletions(-) diff --git a/cmd/lefty/ws/x11/gpcanvas.c b/cmd/lefty/ws/x11/gpcanvas.c index 328b022d1..d6705b99e 100644 --- a/cmd/lefty/ws/x11/gpcanvas.c +++ b/cmd/lefty/ws/x11/gpcanvas.c @@ -14,7 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -/* Lefteris Koutsofios - AT&T Bell Laboratories */ +/* Lefteris Koutsofios - AT&T Labs Research */ #include "common.h" #include "g.h" @@ -41,26 +41,27 @@ static long count; #define BLUE WPU->colors[WPU->gattr.color].nb static char *gstyles[5] = { - /* G_SOLID */ "16 0", - /* G_DASHED */ " 4 4", - /* G_DOTTED */ " 2 2", - /* G_LONGDASHED */ " 4 12", + /* G_SOLID */ "16 0", + /* G_DASHED */ " 4 4", + /* G_DOTTED */ " 2 2", + /* G_LONGDASHED */ " 4 12", /* G_SHORTDASHED */ "12 4", }; char *Gpscanvasname = "out.ps"; -static char *findfont(char *); -static void setgattr(Gwidget_t *, Ggattr_t *); +static char *findfont (char *); +static void setgattr (Gwidget_t *, Ggattr_t *); -static PIXrect_t rdrawtopix(Gwidget_t *, Grect_t); -static PIXpoint_t pdrawtopix(Gwidget_t *, Gpoint_t); -static PIXsize_t sdrawtopix(Gwidget_t *, Gsize_t); -static PIXpoint_t pdrawtobpix(Gbitmap_t *, Gpoint_t); +static PIXrect_t rdrawtopix (Gwidget_t *, Grect_t); +static PIXpoint_t pdrawtopix (Gwidget_t *, Gpoint_t); +static PIXsize_t sdrawtopix (Gwidget_t *, Gsize_t); +static PIXpoint_t pdrawtobpix (Gbitmap_t *, Gpoint_t); -int GPcreatewidget(Gwidget_t * parent, Gwidget_t * widget, - int attrn, Gwattr_t * attrp) -{ +int GPcreatewidget ( + Gwidget_t *parent, Gwidget_t *widget, + int attrn, Gwattr_t *attrp +) { PIXpoint_t po; PIXsize_t ps; struct Gpwcolor_t *cp; @@ -69,59 +70,62 @@ int GPcreatewidget(Gwidget_t * parent, Gwidget_t * widget, char *s, *path; int color, lflag, ai, i, x, y, w, h, r, g, b; - if (!(path = buildpath("lefty.psp", 0)) || !(pfp = fopen(path, "r"))) { - Gerr(POS, G_ERRCANNOTOPENFILE, "lefty.psp"); - return -1; + if ( + !(path = buildpath ("lefty.psp", 0)) || + !(pfp = fopen (path, "r")) + ) { + Gerr (POS, G_ERRCANNOTOPENFILE, "lefty.psp"); + return -1; } s = Gpscanvasname; lflag = FALSE; po.x = po.y = 0; ps.x = ps.y = MINPWSIZE; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRORIGIN: - GETORIGIN(attrp[ai].u.p, po); - break; - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINPWSIZE); - break; - case G_ATTRNAME: - if (attrp[ai].u.t && attrp[ai].u.t[0]) - s = attrp[ai].u.t; - break; - case G_ATTRMODE: - if (Strcmp("landscape", attrp[ai].u.t) == 0) - lflag = TRUE; - else if (Strcmp("portrait", attrp[ai].u.t) == 0) - lflag = FALSE; - else { - Gerr(POS, G_ERRBADATTRVALUE, attrp[ai].u.t); - return -1; - } - break; - case G_ATTRCOLOR: - /* will do it after the widget is created */ - break; - case G_ATTRVIEWPORT: - /* will do it after the widget is created */ - break; - case G_ATTRWINDOW: - /* will do it after the widget is created */ - break; - case G_ATTRWINDOWID: - Gerr(POS, G_ERRCANNOTSETATTR1, "windowid"); - return -1; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRORIGIN: + GETORIGIN (attrp[ai].u.p, po); + break; + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINPWSIZE); + break; + case G_ATTRNAME: + if (attrp[ai].u.t && attrp[ai].u.t[0]) + s = attrp[ai].u.t; + break; + case G_ATTRMODE: + if (strcmp ("landscape", attrp[ai].u.t) == 0) + lflag = TRUE; + else if (strcmp ("portrait", attrp[ai].u.t) == 0) + lflag = FALSE; + else { + Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t); + return -1; + } + break; + case G_ATTRCOLOR: + /* will do it after the widget is created */ + break; + case G_ATTRVIEWPORT: + /* will do it after the widget is created */ + break; + case G_ATTRWINDOW: + /* will do it after the widget is created */ + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR1, "windowid"); + return -1; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } - if (!(FP = fopen(s, "w"))) { - Gerr(POS, G_ERRCANNOTOPENFILE, s); - return -1; + if (!(FP = fopen (s, "w"))) { + Gerr (POS, G_ERRCANNOTOPENFILE, s); + return -1; } WPU->colors[0].r = WPU->colors[0].g = WPU->colors[0].b = 255; WPU->colors[0].nr = WPU->colors[0].ng = WPU->colors[0].nb = 1.0; @@ -130,7 +134,7 @@ int GPcreatewidget(Gwidget_t * parent, Gwidget_t * widget, WPU->colors[1].nr = WPU->colors[1].ng = WPU->colors[1].nb = 0.0; WPU->colors[1].inuse = TRUE; for (i = 2; i < G_MAXCOLORS; i++) - WPU->colors[i].inuse = FALSE; + WPU->colors[i].inuse = FALSE; WPU->gattr.color = 1; WPU->gattr.width = 0; WPU->gattr.mode = -1; @@ -140,331 +144,349 @@ int GPcreatewidget(Gwidget_t * parent, Gwidget_t * widget, WPU->wrect.c.x = 1.0, WPU->wrect.c.y = 1.0; WPU->vsize.x = ps.x, WPU->vsize.y = ps.y; if (lflag) - x = po.y, y = po.x, w = ps.y, h = ps.x; + x = po.y, y = po.x, w = ps.y, h = ps.x; else - x = po.x, y = po.y, w = ps.x, h = ps.y; - fprintf(FP, "%%! LEFTY Output\n"); - fprintf(FP, "%%%%BoundingBox: %d %d %d %d\n", - (int) (PSXOFF + PSMAXPTW * x / maxsize.x + 0.5), - (int) (PSYOFF + PSMAXPTH * y / maxsize.y + 0.5), - (int) (PSXOFF + PSMAXPTW * w / maxsize.x + 0.5), - (int) (PSYOFF + PSMAXPTH * h / maxsize.y + 0.5)); - fprintf(FP, "%%%%EndComments\n"); - while (fgets(buf, 120, pfp)) - fputs(&buf[0], FP); - fclose(pfp); - fprintf(FP, "/ICP { %d %d %d %d SCP } def\n", - (int) po.x, (int) po.y, - (int) (po.x + ps.x - 1), (int) (po.y + ps.y - 1)); - fprintf(FP, "/BB { %d %d %d %d } def\n", - (int) po.x, (int) po.y, - (int) (po.x + ps.x - 1), (int) (po.y + ps.y - 1)); + x = po.x, y = po.y, w = ps.x, h = ps.y; + fprintf (FP, "%%! LEFTY Output\n"); + fprintf ( + FP, "%%%%BoundingBox: %d %d %d %d\n", + (int) (PSXOFF + PSMAXPTW * x / maxsize.x + 0.5), + (int) (PSYOFF + PSMAXPTH * y / maxsize.y + 0.5), + (int) (PSXOFF + PSMAXPTW * w / maxsize.x + 0.5), + (int) (PSYOFF + PSMAXPTH * h / maxsize.y + 0.5) + ); + fprintf (FP, "%%%%EndComments\n"); + while (fgets (buf, 120, pfp)) + fputs (&buf[0], FP); + fclose (pfp); + fprintf ( + FP, "/ICP { %d %d %d %d SCP } def\n", + (int) po.x, (int) po.y, + (int) (po.x + ps.x - 1), (int) (po.y + ps.y - 1) + ); + fprintf ( + FP, "/BB { %d %d %d %d } def\n", + (int) po.x, (int) po.y, + (int) (po.x + ps.x - 1), (int) (po.y + ps.y - 1) + ); if (!lflag) - fprintf(FP, "[%f 0 0 %f %d %d] concat\n", - PSPTPI / PSDPI, PSPTPI / PSDPI, PSXOFF, PSYOFF); + fprintf ( + FP, "[%f 0 0 %f %d %d] concat\n", + PSPTPI / PSDPI, PSPTPI / PSDPI, PSXOFF, PSYOFF + ); else - fprintf(FP, "[0 %f %f 0 %d %d] concat\n", - PSPTPI / PSDPI, -PSPTPI / PSDPI, - (int) (PSXOFF + ps.y * PSPTPI / PSDPI), PSYOFF); - fprintf(FP, "%d %d translate ICP\n", (int) po.x, (int) po.y); - fprintf(FP, "1 setlinecap\n"); - fprintf(FP, "ICP\n"); + fprintf ( + FP, "[0 %f %f 0 %d %d] concat\n", + PSPTPI / PSDPI, - PSPTPI / PSDPI, + (int) (PSXOFF + ps.y * PSPTPI / PSDPI), PSYOFF + ); + fprintf (FP, "%d %d translate ICP\n", (int) po.x, (int) po.y); + fprintf (FP, "1 setlinecap\n"); + fprintf (FP, "ICP\n"); WPU->gattr.color = 1; - fprintf(FP, "%f %f %f CL\n", RED, GREEN, BLUE); + fprintf (FP, "%f %f %f CL\n", RED, GREEN, BLUE); WPU->defgattr = WPU->gattr; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRCOLOR: - color = attrp[ai].u.c.index; - if (color < 0 || color > G_MAXCOLORS) { - Gerr(POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); - return -1; - } - cp = &WPU->colors[color]; - r = attrp[ai].u.c.r; - g = attrp[ai].u.c.g; - b = attrp[ai].u.c.b; - cp->r = r, cp->g = g, cp->b = b; - cp->nr = r / 256.0, cp->ng = g / 256.0, cp->nb = b / 256.0; - cp->inuse = TRUE; - break; - case G_ATTRVIEWPORT: - WPU->vsize.x = (int) (attrp[ai].u.s.x + 0.5); - WPU->vsize.y = (int) (attrp[ai].u.s.y + 0.5); - fprintf(FP, "0 0 %d %d SCP\n", - (int) WPU->vsize.x, (int) WPU->vsize.y); - break; - case G_ATTRWINDOW: - WPU->wrect = attrp[ai].u.r; - break; - } + switch (attrp[ai].id) { + case G_ATTRCOLOR: + color = attrp[ai].u.c.index; + if (color < 0 || color > G_MAXCOLORS) { + Gerr (POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); + return -1; + } + cp = &WPU->colors[color]; + r = attrp[ai].u.c.r; + g = attrp[ai].u.c.g; + b = attrp[ai].u.c.b; + cp->r = r, cp->g = g, cp->b = b; + cp->nr = r / 256.0, cp->ng = g / 256.0, cp->nb = b / 256.0; + cp->inuse = TRUE; + break; + case G_ATTRVIEWPORT: + WPU->vsize.x = (int) (attrp[ai].u.s.x + 0.5); + WPU->vsize.y = (int) (attrp[ai].u.s.y + 0.5); + fprintf ( + FP, "0 0 %d %d SCP\n", (int) WPU->vsize.x, (int) WPU->vsize.y + ); + break; + case G_ATTRWINDOW: + WPU->wrect = attrp[ai].u.r; + break; + } } return 0; } -int GPsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GPsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { struct Gpwcolor_t *cp; int color, ai, r, g, b; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRORIGIN: - break; - case G_ATTRSIZE: - break; - case G_ATTRNAME: - break; - case G_ATTRMODE: - break; - case G_ATTRCOLOR: - color = attrp[ai].u.c.index; - if (color < 0 || color > G_MAXCOLORS) { - Gerr(POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); - return -1; - } - cp = &WPU->colors[color]; - r = attrp[ai].u.c.r; - g = attrp[ai].u.c.g; - b = attrp[ai].u.c.b; - cp->r = r, cp->g = g, cp->b = b; - cp->nr = r / 256.0, cp->ng = g / 256.0, cp->nb = b / 256.0; - cp->inuse = TRUE; - break; - case G_ATTRVIEWPORT: - WPU->vsize.x = (int) (attrp[ai].u.s.x + 0.5); - WPU->vsize.y = (int) (attrp[ai].u.s.y + 0.5); - fprintf(FP, "0 0 %d %d SCP\n", - (int) WPU->vsize.x, (int) WPU->vsize.y); - break; - case G_ATTRWINDOW: - WPU->wrect = attrp[ai].u.r; - break; - case G_ATTRWINDOWID: - Gerr(POS, G_ERRCANNOTSETATTR2, "windowid"); - return -1; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRORIGIN: + break; + case G_ATTRSIZE: + break; + case G_ATTRNAME: + break; + case G_ATTRMODE: + break; + case G_ATTRCOLOR: + color = attrp[ai].u.c.index; + if (color < 0 || color > G_MAXCOLORS) { + Gerr (POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); + return -1; + } + cp = &WPU->colors[color]; + r = attrp[ai].u.c.r; + g = attrp[ai].u.c.g; + b = attrp[ai].u.c.b; + cp->r = r, cp->g = g, cp->b = b; + cp->nr = r / 256.0, cp->ng = g / 256.0, cp->nb = b / 256.0; + cp->inuse = TRUE; + break; + case G_ATTRVIEWPORT: + WPU->vsize.x = (int) (attrp[ai].u.s.x + 0.5); + WPU->vsize.y = (int) (attrp[ai].u.s.y + 0.5); + fprintf ( + FP, "0 0 %d %d SCP\n", (int) WPU->vsize.x, (int) WPU->vsize.y + ); + break; + case G_ATTRWINDOW: + WPU->wrect = attrp[ai].u.r; + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR2, "windowid"); + return -1; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } return 0; } -int GPgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GPgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { struct Gpwcolor_t *cp; int color, ai; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRORIGIN: - break; - case G_ATTRSIZE: - break; - case G_ATTRNAME: - break; - case G_ATTRMODE: - break; - case G_ATTRCOLOR: - color = attrp[ai].u.c.index; - if (color < 0 || color > G_MAXCOLORS - || !WPU->colors[color].inuse) { - Gerr(POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); - return -1; - } - cp = &WPU->colors[color]; - attrp[ai].u.c.r = cp->r; - attrp[ai].u.c.g = cp->g; - attrp[ai].u.c.b = cp->b; - break; - case G_ATTRVIEWPORT: - attrp[ai].u.s = WPU->vsize; - break; - case G_ATTRWINDOW: - attrp[ai].u.r = WPU->wrect; - break; - case G_ATTRWINDOWID: - Gerr(POS, G_ERRCANNOTGETATTR, "windowid"); - break; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRORIGIN: + break; + case G_ATTRSIZE: + break; + case G_ATTRNAME: + break; + case G_ATTRMODE: + break; + case G_ATTRCOLOR: + color = attrp[ai].u.c.index; + if (color < 0 || color > G_MAXCOLORS || !WPU->colors[color].inuse) { + Gerr (POS, G_ERRBADCOLORINDEX, attrp[ai].u.c.index); + return -1; + } + cp = &WPU->colors[color]; + attrp[ai].u.c.r = cp->r; + attrp[ai].u.c.g = cp->g; + attrp[ai].u.c.b = cp->b; + break; + case G_ATTRVIEWPORT: + attrp[ai].u.s = WPU->vsize; + break; + case G_ATTRWINDOW: + attrp[ai].u.r = WPU->wrect; + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTGETATTR, "windowid"); + break; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } return 0; } -int GPdestroywidget(Gwidget_t * widget) -{ - fprintf(FP, "stroke showpage\n"); - fclose(FP); +int GPdestroywidget (Gwidget_t *widget) { + fprintf (FP, "stroke showpage\n"); + fclose (FP); return 0; } -int GPcanvasclear(Gwidget_t * widget) -{ - fprintf(FP, "ICP DO\n"); +int GPcanvasclear (Gwidget_t *widget) { + fprintf (FP, "ICP DO\n"); WPU->gattr.color = 0; - fprintf(FP, "%f %f %f CL\n", RED, GREEN, BLUE); - fprintf(FP, "BB BOX FI\n"); + fprintf (FP, "%f %f %f CL\n", RED, GREEN, BLUE); + fprintf (FP, "BB BOX FI\n"); WPU->gattr.color = -1; - fprintf(FP, "0 0 %d %d SCP\n", (int) WPU->vsize.x, (int) WPU->vsize.y); + fprintf (FP, "0 0 %d %d SCP\n", (int) WPU->vsize.x, (int) WPU->vsize.y); return 0; } -int GPsetgfxattr(Gwidget_t * widget, Ggattr_t * ap) -{ - setgattr(widget, ap); +int GPsetgfxattr (Gwidget_t *widget, Ggattr_t *ap) { + setgattr (widget, ap); WPU->defgattr = WPU->gattr; return 0; } -int GPgetgfxattr(Gwidget_t * widget, Ggattr_t * ap) -{ +int GPgetgfxattr (Gwidget_t *widget, Ggattr_t *ap) { if ((ap->flags & G_GATTRCOLOR)) - ap->color = WPU->gattr.color; + ap->color = WPU->gattr.color; if ((ap->flags & G_GATTRWIDTH)) - ap->width = WPU->gattr.width; + ap->width = WPU->gattr.width; if ((ap->flags & G_GATTRMODE)) - ap->mode = WPU->gattr.mode; + ap->mode = WPU->gattr.mode; if ((ap->flags & G_GATTRFILL)) - ap->fill = WPU->gattr.fill; + ap->fill = WPU->gattr.fill; if ((ap->flags & G_GATTRSTYLE)) - ap->style = WPU->gattr.style; + ap->style = WPU->gattr.style; return 0; } -int GParrow(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap) -{ +int GParrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { PIXpoint_t pp1, pp2, pa, pb, pd; double tangent; int l; - pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2); + pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2); pd.x = pp1.x - pp2.x, pd.y = pp1.y - pp2.y; if (pd.x == 0 && pd.y == 0) - return 0; - tangent = atan2((double) pd.y, (double) pd.x); - if ((l = sqrt((double) (pd.x * pd.x + pd.y * pd.y))) < 30) - l = 30; - pa.x = l * cos(tangent + M_PI / 7) + pp2.x; - pa.y = l * sin(tangent + M_PI / 7) + pp2.y; - pb.x = l * cos(tangent - M_PI / 7) + pp2.x; - pb.y = l * sin(tangent - M_PI / 7) + pp2.y; - setgattr(widget, ap); - fprintf(FP, "%d %d %d %d LI\n", - (int) pp2.x, (int) pp2.y, (int) pp1.x, (int) pp1.y); - fprintf(FP, "%d %d %d %d LI\n", - (int) pp2.x, (int) pp2.y, (int) pa.x, (int) pa.y); - fprintf(FP, "%d %d %d %d LI\n", - (int) pp2.x, (int) pp2.y, (int) pb.x, (int) pb.y); + return 0; + tangent = atan2 ((double) pd.y, (double) pd.x); + if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) < 30) + l = 30; + pa.x = l * cos (tangent + M_PI / 7) + pp2.x; + pa.y = l * sin (tangent + M_PI / 7) + pp2.y; + pb.x = l * cos (tangent - M_PI / 7) + pp2.x; + pb.y = l * sin (tangent - M_PI / 7) + pp2.y; + setgattr (widget, ap); + fprintf ( + FP, "%d %d %d %d LI\n", + (int) pp2.x, (int) pp2.y, (int) pp1.x, (int) pp1.y + ); + fprintf ( + FP, "%d %d %d %d LI\n", + (int) pp2.x, (int) pp2.y, (int) pa.x, (int) pa.y + ); + fprintf ( + FP, "%d %d %d %d LI\n", + (int) pp2.x, (int) pp2.y, (int) pb.x, (int) pb.y + ); return 0; } -int GPline(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap) -{ +int GPline (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { PIXpoint_t pp1, pp2; - pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2); + pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2); if (count++ == 100) - count = 0, fprintf(FP, "DO\n"); - setgattr(widget, ap); - fprintf(FP, "%d %d %d %d LI\n", - (int) pp2.x, (int) pp2.y, (int) pp1.x, (int) pp1.y); + count = 0, fprintf (FP, "DO\n"); + setgattr (widget, ap); + fprintf ( + FP, "%d %d %d %d LI\n", + (int) pp2.x, (int) pp2.y, (int) pp1.x, (int) pp1.y + ); return 0; } -int GPbox(Gwidget_t * widget, Grect_t gr, Ggattr_t * ap) -{ +int GPbox (Gwidget_t *widget, Grect_t gr, Ggattr_t *ap) { PIXrect_t pr; - pr = rdrawtopix(widget, gr); - setgattr(widget, ap); + pr = rdrawtopix (widget, gr); + setgattr (widget, ap); if (WPU->gattr.fill) - fprintf(FP, "DO %d %d %d %d BOX FI\n", - (int) pr.o.x, (int) pr.o.y, (int) pr.c.x, (int) pr.c.y); + fprintf ( + FP, "DO %d %d %d %d BOX FI\n", + (int) pr.o.x, (int) pr.o.y, (int) pr.c.x, (int) pr.c.y + ); else - fprintf(FP, "DO %d %d %d %d BOX DO\n", - (int) pr.o.x, (int) pr.o.y, (int) pr.c.x, (int) pr.c.y); + fprintf ( + FP, "DO %d %d %d %d BOX DO\n", + (int) pr.o.x, (int) pr.o.y, (int) pr.c.x, (int) pr.c.y + ); return 0; } -int GPpolygon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap) -{ +int GPpolygon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) { PIXpoint_t pp; int i; if (gpn == 0) - return 0; + return 0; - pp = pdrawtopix(widget, gpp[0]); - setgattr(widget, ap); - fprintf(FP, "DO %d %d moveto\n", (int) pp.x, (int) pp.y); + pp = pdrawtopix (widget, gpp[0]); + setgattr (widget, ap); + fprintf (FP, "DO %d %d moveto\n", (int) pp.x, (int) pp.y); for (i = 1; i < gpn; i++) { - pp = pdrawtopix(widget, gpp[i]); - fprintf(FP, "%d %d lineto\n", (int) pp.x, (int) pp.y); + pp = pdrawtopix (widget, gpp[i]); + fprintf (FP, "%d %d lineto\n", (int) pp.x, (int) pp.y); } if (WPU->gattr.fill) - fprintf(FP, "FI\n"); + fprintf (FP, "FI\n"); else - fprintf(FP, "DO\n"); + fprintf (FP, "DO\n"); return 0; } -int GPsplinegon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap) -{ +int GPsplinegon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) { PIXpoint_t p0, p1, p2, p3; int i; if (gpn == 0) - return 0; + return 0; - p0 = pdrawtopix(widget, gpp[0]); - setgattr(widget, ap); - fprintf(FP, "DO %d %d moveto\n", (int) p0.x, (int) p0.y); + p0 = pdrawtopix (widget, gpp[0]); + setgattr (widget, ap); + fprintf (FP, "DO %d %d moveto\n", (int) p0.x, (int) p0.y); for (i = 1; i < gpn; i += 3) { - p1 = pdrawtopix(widget, gpp[i]); - p2 = pdrawtopix(widget, gpp[i + 1]); - p3 = pdrawtopix(widget, gpp[i + 2]); - fprintf(FP, "%d %d %d %d %d %d CT\n", (int) p1.x, (int) p1.y, - (int) p2.x, (int) p2.y, (int) p3.x, (int) p3.y); + p1 = pdrawtopix (widget, gpp[i]); + p2 = pdrawtopix (widget, gpp[i + 1]); + p3 = pdrawtopix (widget, gpp[i + 2]); + fprintf ( + FP, "%d %d %d %d %d %d CT\n", (int) p1.x, (int) p1.y, + (int) p2.x, (int) p2.y, (int) p3.x, (int) p3.y + ); } if (WPU->gattr.fill) - fprintf(FP, "FI\n"); + fprintf (FP, "FI\n"); else - fprintf(FP, "DO\n"); + fprintf (FP, "DO\n"); return 0; } -int GParc(Gwidget_t * widget, Gpoint_t gc, Gsize_t gs, - double ang1, double ang2, Ggattr_t * ap) -{ +int GParc ( + Gwidget_t *widget, Gpoint_t gc, Gsize_t gs, + double ang1, double ang2, Ggattr_t *ap +) { PIXpoint_t pc; PIXsize_t ps; - pc = pdrawtopix(widget, gc), ps = sdrawtopix(widget, gs); - setgattr(widget, ap); + pc = pdrawtopix (widget, gc), ps = sdrawtopix (widget, gs); + setgattr (widget, ap); if (WPU->gattr.fill) - fprintf(FP, "DO %d %d %f %d %f %f ARF\n", - pc.x, pc.y, (double) ps.y / (double) ps.x, ps.x, ang1, - ang2); + fprintf ( + FP, "DO %d %d %f %d %f %f ARF\n", + pc.x, pc.y, (double) ps.y / (double) ps.x, ps.x, ang1, ang2 + ); else - fprintf(FP, "DO %d %d %f %d %f %f AR\n", - pc.x, pc.y, (double) ps.y / (double) ps.x, ps.x, ang1, - ang2); + fprintf ( + FP, "DO %d %d %f %d %f %f AR\n", + pc.x, pc.y, (double) ps.y / (double) ps.x, ps.x, ang1, ang2 + ); return 0; } -int GPtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go, - char *fn, double fs, char *justs, Ggattr_t * ap) -{ +int GPtext ( + Gwidget_t *widget, Gtextline_t *tlp, int n, Gpoint_t go, char *fn, + double fs, char *justs, Ggattr_t *ap +) { Gsize_t gs; PIXpoint_t po; PIXsize_t ps; @@ -472,123 +494,124 @@ int GPtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go, char c, *p; int i; - po = pdrawtopix(widget, go); + po = pdrawtopix (widget, go); gs.x = 0, gs.y = fs; - ps = sdrawtopix(widget, gs); - font = findfont(fn); - setgattr(widget, ap); - fprintf(FP, "DO %d (%c) %d (%c) [", - (int) po.x, justs[0], (int) po.y, justs[1]); + ps = sdrawtopix (widget, gs); + font = findfont (fn); + setgattr (widget, ap); + fprintf ( + FP, "DO %d (%c) %d (%c) [", + (int) po.x, justs[0], (int) po.y, justs[1] + ); for (i = 0; i < n; i++) { - c = tlp[i].p[tlp[i].n], tlp[i].p[tlp[i].n] = '\000'; - fprintf(FP, "[ ("); - for (p = tlp[i].p; *p; p++) { /* generate PS escapes as needed */ - if ((*p == '(') || (*p == ')') || (*p == '\\')) - fputc('\\', FP); - fputc(*p, FP); - } - fprintf(FP, ") (%c) ] ", tlp[i].j); - tlp[i].p[tlp[i].n] = c; + c = tlp[i].p[tlp[i].n], tlp[i].p[tlp[i].n] = '\000'; + fprintf (FP, "[ ("); + for (p = tlp[i].p; *p; p++) { /* generate PS escapes as needed */ + if ((*p == '(') || (*p == ')') || (*p == '\\')) + fputc('\\',FP); + fputc(*p,FP); + } + fprintf (FP,") (%c) ] ", tlp[i].j); + tlp[i].p[tlp[i].n] = c; } - fprintf(FP, "] %d /%s %d TXT\n", n, font, (int) ps.y); + fprintf (FP, "] %d /%s %d TXT\n", n, font, (int) ps.y); return 0; } -static char *findfont(char *name) -{ +static char *findfont (char *name) { char *font; - if (name[0] == '\000' || Strcmp(name, "default") == 0) - font = "Times-Roman"; + if (name[0] == '\000' || strcmp (name, "default") == 0) + font = "Times-Roman"; else - font = name; + font = name; return font; } -int GPcreatebitmap(Gwidget_t * widget, Gbitmap_t * bitmap, Gsize_t s) -{ +int GPcreatebitmap (Gwidget_t *widget, Gbitmap_t *bitmap, Gsize_t s) { if (!widget) { - Gerr(POS, G_ERRNOPARENTWIDGET); - return -1; + Gerr (POS, G_ERRNOPARENTWIDGET); + return -1; } if (!bitmap) { - Gerr(POS, G_ERRNOBITMAP); - return -1; + Gerr (POS, G_ERRNOBITMAP); + return -1; } - bitmap->u.bits = Marrayalloc((long) ((int) s.x * (int) s.y * 3)); + bitmap->u.bits = Marrayalloc ((long) ((int) s.x * (int) s.y * 3)); bitmap->ctype = widget->type; bitmap->canvas = widget - &Gwidgets[0]; bitmap->size = s; return 0; } -int GPdestroybitmap(Gbitmap_t * bitmap) -{ +int GPdestroybitmap (Gbitmap_t *bitmap) { if (!bitmap) { - Gerr(POS, G_ERRNOBITMAP); - return -1; + Gerr (POS, G_ERRNOBITMAP); + return -1; } - Marrayfree(bitmap->u.bits); + Marrayfree (bitmap->u.bits); return 0; } -int GPreadbitmap(Gwidget_t * widget, Gbitmap_t * bitmap, FILE * fp) -{ - Gsize_t s = { 0, 0 }; +int GPreadbitmap (Gwidget_t *widget, Gbitmap_t *bitmap, FILE *fp) { + Gsize_t s; char bufp[2048]; char *s1, *s2; char c; int bufn, bufi, step, x, y, k; if (!widget) { - Gerr(POS, G_ERRNOPARENTWIDGET); - return -1; + Gerr (POS, G_ERRNOPARENTWIDGET); + return -1; } if (!bitmap) { - Gerr(POS, G_ERRNOBITMAP); - return -1; + Gerr (POS, G_ERRNOBITMAP); + return -1; } step = 0; while (step < 3) { - l1: - if (!fgets(bufp, 2048, fp)) { - Gerr(POS, G_ERRCANNOTREADBITMAP); - return -1; - } - s1 = &bufp[0]; - l2: - for (; *s1 && isspace(*s1); s1++); - if (!*s1 || *s1 == '#') - goto l1; - switch (step) { - case 0: - if (strncmp(s1, "P6", 2) != 0) { - Gerr(POS, G_ERRCANNOTREADBITMAP); - return -1; - } - step++, s1 += 2; - goto l2; - case 1: - for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++); - c = *s2, *s2 = 0; - if (s2 == s1 || (s.x = atoi(s1)) <= 0) { - *s2 = c, Gerr(POS, G_ERRCANNOTREADBITMAP); - return -1; - } - *s2 = c, step++, s1 = s2; - goto l2; - case 2: - for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++); - c = *s2, *s2 = 0; - if (s2 == s1 || (s.y = atoi(s1)) <= 0) { - *s2 = c, Gerr(POS, G_ERRCANNOTREADBITMAP); - return -1; - } - *s2 = c, step++, s1 = s2; - goto l2; - } +l1: + if (!fgets (bufp, 2048, fp)) { + Gerr (POS, G_ERRCANNOTREADBITMAP); + return -1; + } + s1 = &bufp[0]; +l2: + for (; *s1 && isspace (*s1); s1++) + ; + if (!*s1 || *s1 == '#') + goto l1; + switch (step) { + case 0: + if (strncmp (s1, "P6", 2) != 0) { + Gerr (POS, G_ERRCANNOTREADBITMAP); + return -1; + } + step++, s1 += 2; + goto l2; + case 1: + for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++) + ; + c = *s2, *s2 = 0; + if (s2 == s1 || (s.x = atoi (s1)) <= 0) { + *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP); + return -1; + } + *s2 = c, step++, s1 = s2; + goto l2; + case 2: + for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++) + ; + c = *s2, *s2 = 0; + if (s2 == s1 || (s.y = atoi (s1)) <= 0) { + *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP); + return -1; + } + *s2 = c, step++, s1 = s2; + goto l2; + } } - bitmap->u.bits = Marrayalloc((long) ((int) s.x * (int) s.y * 3)); + bitmap->u.bits = Marrayalloc ((long) ((int) s.x * (int) s.y * 3)); bitmap->ctype = widget->type; bitmap->canvas = widget - &Gwidgets[0]; bitmap->size = s; @@ -596,31 +619,31 @@ int GPreadbitmap(Gwidget_t * widget, Gbitmap_t * bitmap, FILE * fp) bufp[bufi] = 0; s1 = (char *) bitmap->u.bits; for (y = 0; y < s.y; y++) { - for (x = 0; x < s.x; x++) { - for (k = 0; k < 3; k++) { - if (bufi == bufn) { - if ((bufn = fread(bufp, 1, 2047, fp)) == 0) { - Marrayfree(bitmap->u.bits); - Gerr(POS, G_ERRCANNOTCREATEBITMAP); - return -1; - } - bufi = 0; - } - *s1++ = bufp[bufi++]; - } - } + for (x = 0; x < s.x; x++) { + for (k = 0; k < 3; k++) { + if (bufi == bufn) { + if ((bufn = fread (bufp, 1, 2047, fp)) == 0) { + Marrayfree (bitmap->u.bits); + Gerr (POS, G_ERRCANNOTCREATEBITMAP); + return -1; + } + bufi = 0; + } + *s1++ = bufp[bufi++]; + } + } } return 0; } -int GPwritebitmap(Gbitmap_t * bitmap, FILE * fp) -{ +int GPwritebitmap (Gbitmap_t *bitmap, FILE *fp) { return -1; } -int GPbitblt(Gwidget_t * widget, Gpoint_t gp, Grect_t gr, - Gbitmap_t * bitmap, char *mode, Ggattr_t * ap) -{ +int GPbitblt ( + Gwidget_t *widget, Gpoint_t gp, Grect_t gr, Gbitmap_t *bitmap, + char *mode, Ggattr_t *ap +) { PIXrect_t pr, br; PIXpoint_t pp; PIXsize_t bs; @@ -631,101 +654,99 @@ int GPbitblt(Gwidget_t * widget, Gpoint_t gp, Grect_t gr, char *s; if (gr.o.x > gr.c.x) - p.x = gr.o.x, gr.o.x = gr.c.x, gr.c.x = p.x; + p.x = gr.o.x, gr.o.x = gr.c.x, gr.c.x = p.x; if (gr.o.y > gr.c.y) - p.y = gr.o.y, gr.o.y = gr.c.y, gr.c.y = p.y; + p.y = gr.o.y, gr.o.y = gr.c.y, gr.c.y = p.y; tvx = WPU->vsize.x, tvy = WPU->vsize.y; twx = WPU->wrect.c.x - WPU->wrect.o.x; twy = WPU->wrect.c.y - WPU->wrect.o.y; scale.x = tvx / twx, scale.y = tvy / twy; - pr = rdrawtopix(widget, gr); - pp = pdrawtobpix(bitmap, gp); + pr = rdrawtopix (widget, gr); + pp = pdrawtobpix (bitmap, gp); bs.x = (pr.c.x - pr.o.x + 1) / scale.x; bs.y = (pr.c.y - pr.o.y + 1) / scale.y; br.o.x = pp.x, br.o.y = pp.y - bs.y + 1; br.c.x = br.o.x + bs.x - 1, br.c.y = br.o.y + bs.y - 1; if (br.o.x < 0) - pr.o.x -= br.o.x * scale.x, br.o.x = 0; + pr.o.x -= br.o.x * scale.x, br.o.x = 0; if (br.o.y < 0) - pr.o.y -= br.o.y * scale.y, br.o.y = 0; + pr.o.y -= br.o.y * scale.y, br.o.y = 0; if (br.c.x >= bitmap->size.x) { - pr.c.x -= (br.c.x + 1 - bitmap->size.x) * scale.x; - br.c.x = bitmap->size.x - 1; + pr.c.x -= (br.c.x + 1 - bitmap->size.x) * scale.x; + br.c.x = bitmap->size.x - 1; } if (br.c.y >= bitmap->size.y) { - pr.c.y -= (br.c.y + 1 - bitmap->size.y) * scale.y; - br.c.y = bitmap->size.y - 1; + pr.c.y -= (br.c.y + 1 - bitmap->size.y) * scale.y; + br.c.y = bitmap->size.y - 1; } if (pr.o.x < 0) - br.o.x -= pr.o.x / scale.x, pr.o.x = 0; + br.o.x -= pr.o.x / scale.x, pr.o.x = 0; if (pr.o.y < 0) - br.o.y -= pr.o.y / scale.y, pr.o.y = 0; + br.o.y -= pr.o.y / scale.y, pr.o.y = 0; if (pr.c.x >= tvx) - br.c.x -= (pr.c.x + 1 - tvx) / scale.x, pr.c.x = tvx - 1; + br.c.x -= (pr.c.x + 1 - tvx) / scale.x, pr.c.x = tvx - 1; if (pr.c.y >= tvy) - br.c.y -= (pr.c.y + 1 - tvy) / scale.y, pr.c.y = tvy - 1; + br.c.y -= (pr.c.y + 1 - tvy) / scale.y, pr.c.y = tvy - 1; bs.x = (pr.c.x - pr.o.x + 1) / scale.x; bs.y = (pr.c.y - pr.o.y + 1) / scale.y; - setgattr(widget, ap); - fprintf(FP, "DO gsave\n"); - fprintf(FP, "%d %d translate\n", pr.o.x, pr.o.y); - fprintf(FP, "%f %f scale\n", scale.x * bs.x, scale.y * bs.y); - fprintf(FP, "/mystr %d string def\n", 3 * bs.x); - fprintf(FP, "%d %d 8\n", bs.x, bs.y); - fprintf(FP, "[%d 0 0 %d 0 %d]\n", bs.x, -bs.y, bs.y); - fprintf(FP, - "{currentfile mystr readhexstring pop} false 3 colorimage\n"); + setgattr (widget, ap); + fprintf (FP, "DO gsave\n"); + fprintf (FP, "%d %d translate\n", pr.o.x, pr.o.y); + fprintf (FP, "%f %f scale\n", scale.x * bs.x, scale.y * bs.y); + fprintf (FP, "/mystr %d string def\n", 3 * bs.x); + fprintf (FP, "%d %d 8\n", bs.x, bs.y); + fprintf (FP, "[%d 0 0 %d 0 %d]\n", bs.x, -bs.y, bs.y); + fprintf (FP, "{currentfile mystr readhexstring pop} false 3 colorimage\n"); for (y = 0; y < bs.y; y++) { - s = (char *) (bitmap->u.bits + - 3 * ((int) bitmap->size.x * (br.o.y + y) + br.o.x)); - for (x = 0; x < bs.x; x++) { - hi = (*s >> 4) & 15, lo = *s++ && 15; - fprintf(FP, "%x%x", hi, lo); - hi = (*s >> 4) & 15, lo = *s++ && 15; - fprintf(FP, "%x%x", hi, lo); - hi = (*s >> 4) & 15, lo = *s++ && 15; - fprintf(FP, "%x%x", hi, lo); - } - fprintf(FP, "\n"); + s = (char *) ( + bitmap->u.bits + 3 * ((int) bitmap->size.x * (br.o.y + y) + br.o.x) + ); + for (x = 0; x < bs.x; x++) { + hi = (*s >> 4) & 15, lo = *s++ && 15; + fprintf (FP, "%x%x", hi, lo); + hi = (*s >> 4) & 15, lo = *s++ && 15; + fprintf (FP, "%x%x", hi, lo); + hi = (*s >> 4) & 15, lo = *s++ && 15; + fprintf (FP, "%x%x", hi, lo); + } + fprintf (FP, "\n"); } - fprintf(FP, "grestore\nNP\n"); + fprintf (FP, "grestore\nNP\n"); return 0; } -static void setgattr(Gwidget_t * widget, Ggattr_t * ap) -{ +static void setgattr (Gwidget_t *widget, Ggattr_t *ap) { int color, width, style; if (!(ap->flags & G_GATTRCOLOR)) - ap->color = WPU->defgattr.color; + ap->color = WPU->defgattr.color; if (!(ap->flags & G_GATTRWIDTH)) - ap->width = WPU->defgattr.width; + ap->width = WPU->defgattr.width; if (!(ap->flags & G_GATTRFILL)) - ap->fill = WPU->defgattr.fill; + ap->fill = WPU->defgattr.fill; if (!(ap->flags & G_GATTRSTYLE)) - ap->style = WPU->defgattr.style; + ap->style = WPU->defgattr.style; color = ap->color; if (color >= G_MAXCOLORS || !(WPU->colors[color].inuse)) - color = 1; + color = 1; if (color != WPU->gattr.color) { - WPU->gattr.color = color; - fprintf(FP, "%f %f %f CL\n", RED, GREEN, BLUE); + WPU->gattr.color = color; + fprintf (FP, "%f %f %f CL\n", RED, GREEN, BLUE); } width = ap->width; if (width != WPU->gattr.width) { - WPU->gattr.width = width; - fprintf(FP, "DO %d setlinewidth NP\n", width); + WPU->gattr.width = width; + fprintf (FP, "DO %d setlinewidth NP\n", width); } WPU->gattr.fill = ap->fill; style = ap->style; if (style != WPU->gattr.style) { - WPU->gattr.style = style; - fprintf(FP, "DO [ %s ] 0 setdash NP\n", gstyles[style]); + WPU->gattr.style = style; + fprintf (FP, "DO [ %s ] 0 setdash NP\n", gstyles[style]); } } -static PIXrect_t rdrawtopix(Gwidget_t * widget, Grect_t gr) -{ +static PIXrect_t rdrawtopix (Gwidget_t *widget, Grect_t gr) { PIXrect_t pr; double tvx, tvy, twx, twy; @@ -739,8 +760,7 @@ static PIXrect_t rdrawtopix(Gwidget_t * widget, Grect_t gr) return pr; } -static PIXpoint_t pdrawtopix(Gwidget_t * widget, Gpoint_t gp) -{ +static PIXpoint_t pdrawtopix (Gwidget_t *widget, Gpoint_t gp) { PIXpoint_t pp; double tvx, tvy, twx, twy; @@ -752,8 +772,7 @@ static PIXpoint_t pdrawtopix(Gwidget_t * widget, Gpoint_t gp) return pp; } -static PIXsize_t sdrawtopix(Gwidget_t * widget, Gsize_t gs) -{ +static PIXsize_t sdrawtopix (Gwidget_t *widget, Gsize_t gs) { PIXsize_t ps; double tvx, tvy, twx, twy; @@ -765,8 +784,7 @@ static PIXsize_t sdrawtopix(Gwidget_t * widget, Gsize_t gs) return ps; } -static PIXpoint_t pdrawtobpix(Gbitmap_t * bitmap, Gpoint_t gp) -{ +static PIXpoint_t pdrawtobpix (Gbitmap_t *bitmap, Gpoint_t gp) { PIXpoint_t pp; double tvy; diff --git a/cmd/lefty/ws/x11/gquery.c b/cmd/lefty/ws/x11/gquery.c index 741012647..fcb312e0d 100644 --- a/cmd/lefty/ws/x11/gquery.c +++ b/cmd/lefty/ws/x11/gquery.c @@ -14,169 +14,163 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -/* Lefteris Koutsofios - AT&T Bell Laboratories */ +/* Lefteris Koutsofios - AT&T Labs Research */ #include "common.h" #include "g.h" #include "gcommon.h" +#include "SF.h" #define WQU widget->u.q -static void qwcallback(Widget, XtPointer, XtPointer); -static void qbwcallback(Widget, XtPointer, XtPointer); +static void qwcallback (Widget, XtPointer, XtPointer); +static void qbwcallback (Widget, XtPointer, XtPointer); -int GQcreatewidget(Gwidget_t * parent, Gwidget_t * widget, - int attrn, Gwattr_t * attrp) -{ +int GQcreatewidget ( + Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp +) { Widget w; int ai; WQU->mode = G_QWSTRING; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRMODE: - if (Strcmp("string", attrp[ai].u.t) == 0) - WQU->mode = G_QWSTRING; - else if (Strcmp("file", attrp[ai].u.t) == 0) - WQU->mode = G_QWFILE; - else if (Strcmp("choice", attrp[ai].u.t) == 0) - WQU->mode = G_QWCHOICE; - else { - Gerr(POS, G_ERRBADATTRVALUE, attrp[ai].u.t); - return -1; - } - break; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRMODE: + if (strcmp ("string", attrp[ai].u.t) == 0) + WQU->mode = G_QWSTRING; + else if (strcmp ("file", attrp[ai].u.t) == 0) + WQU->mode = G_QWFILE; + else if (strcmp ("choice", attrp[ai].u.t) == 0) + WQU->mode = G_QWCHOICE; + else { + Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t); + return -1; + } + break; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } switch (WQU->mode) { case G_QWSTRING: - if (!(widget->w = XtCreatePopupShell("popup", - transientShellWidgetClass, - Groot, NULL, 0))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; - } - XtAddCallback(widget->w, XtNpopdownCallback, qwcallback, NULL); - RESETARGS; - ADD2ARGS(XtNlabel, "abcdefghijklmno"); - ADD2ARGS(XtNvalue, ""); - if (!(WQU->w = XtCreateManagedWidget("dialog", - dialogWidgetClass, widget->w, - argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; - } - XawDialogAddButton(WQU->w, "Cancel", qbwcallback, (XtPointer) 1); - XawDialogAddButton(WQU->w, "OK", qbwcallback, (XtPointer) 2); - if (!(w = XtNameToWidget(WQU->w, "value"))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; - } - XtOverrideTranslations(w, Gqwpoptable); - break; + if (!(widget->w = XtCreatePopupShell ( + "popup", transientShellWidgetClass, Groot, NULL, 0 + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; + } + XtAddCallback (widget->w, XtNpopdownCallback, qwcallback, NULL); + RESETARGS; + ADD2ARGS (XtNlabel, "abcdefghijklmno"); + ADD2ARGS (XtNvalue, ""); + if (!(WQU->w = XtCreateManagedWidget ( + "dialog", dialogWidgetClass, widget->w, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; + } + XawDialogAddButton (WQU->w, "Cancel", qbwcallback, (XtPointer) 1); + XawDialogAddButton (WQU->w, "OK", qbwcallback, (XtPointer) 2); + if (!(w = XtNameToWidget (WQU->w, "value"))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; + } + XtOverrideTranslations (w, Gqwpoptable); + break; case G_QWFILE: - widget->w = 0; - break; + widget->w = 0; + break; case G_QWCHOICE: - if (!(widget->w = XtCreatePopupShell("popup", - transientShellWidgetClass, - Groot, NULL, 0))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; - } - XtAddCallback(widget->w, XtNpopdownCallback, qwcallback, NULL); - RESETARGS; - ADD2ARGS(XtNlabel, "abcdefghijklmno"); - if (!(WQU->w = XtCreateManagedWidget("dialog", - dialogWidgetClass, widget->w, - argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; - } - break; + if (!(widget->w = XtCreatePopupShell ( + "popup", transientShellWidgetClass, Groot, NULL, 0 + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; + } + XtAddCallback (widget->w, XtNpopdownCallback, qwcallback, NULL); + RESETARGS; + ADD2ARGS (XtNlabel, "abcdefghijklmno"); + if (!(WQU->w = XtCreateManagedWidget ( + "dialog", dialogWidgetClass, widget->w, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; + } + break; } return 0; } -int GQsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GQsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { int ai; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRMODE: - Gerr(POS, G_ERRCANNOTSETATTR2, "mode"); - return -1; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRMODE: + Gerr (POS, G_ERRCANNOTSETATTR2, "mode"); + return -1; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } return 0; } -int GQgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GQgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { int ai; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRMODE: - switch (WQU->mode) { - case G_QWSTRING: - attrp[ai].u.t = "string"; - break; - case G_QWFILE: - attrp[ai].u.t = "file"; - break; - case G_QWCHOICE: - attrp[ai].u.t = "choice"; - break; - } - break; - case G_ATTRUSERDATA: - attrp[ai].u.u = widget->udata; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + switch (attrp[ai].id) { + case G_ATTRMODE: + switch (WQU->mode) { + case G_QWSTRING: + attrp[ai].u.t = "string"; + break; + case G_QWFILE: + attrp[ai].u.t = "file"; + break; + case G_QWCHOICE: + attrp[ai].u.t = "choice"; + break; + } + break; + case G_ATTRUSERDATA: + attrp[ai].u.u = widget->udata; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } return 0; } -int GQdestroywidget(Gwidget_t * widget) -{ +int GQdestroywidget (Gwidget_t *widget) { switch (WQU->mode) { case G_QWSTRING: - XtDestroyWidget(widget->w); - break; + XtDestroyWidget (widget->w); + break; case G_QWFILE: - break; + break; case G_QWCHOICE: - XtDestroyWidget(widget->w); - break; + XtDestroyWidget (widget->w); + break; } return 0; } -extern int XsraSelFile(Widget toplevel, char *prompt, char *ok, char *cancel, - char *failed, char *init_path, char *mode, - int (*show_entry) (char *, char **, struct stat *), - char *name_return, int name_size); - -int GQqueryask(Gwidget_t * widget, char *prompt, char *args, - char *responsep, int responsen) -{ +int GQqueryask ( + Gwidget_t *widget, char *prompt, char *args, + char *responsep, int responsen +) { Window rwin, cwin; Dimension width, height; int rx, ry, x, y; @@ -189,148 +183,153 @@ int GQqueryask(Gwidget_t * widget, char *prompt, char *args, switch (WQU->mode) { case G_QWSTRING: - RESETARGS; - ADD2ARGS(XtNlabel, prompt); - ADD2ARGS(XtNvalue, args ? args : ""); - XtSetValues(WQU->w, argp, argn); - XtRealizeWidget(widget->w); - XQueryPointer(Gdisplay, XtWindow(widget->w), - &rwin, &cwin, &rx, &ry, &x, &y, &mask); - RESETARGS; - ADD2ARGS(XtNwidth, &width); - ADD2ARGS(XtNheight, &height); - XtGetValues(widget->w, argp, argn); - rx -= (width / 2), ry -= (height / 2); - if (rx + width > DisplayWidth(Gdisplay, Gscreenn)) - rx = DisplayWidth(Gdisplay, Gscreenn) - width; - if (ry + height > DisplayHeight(Gdisplay, Gscreenn)) - ry = DisplayHeight(Gdisplay, Gscreenn) - height; - if (rx < 0) - rx = 0; - if (ry < 0) - ry = 0; - RESETARGS; - ADD2ARGS(XtNx, rx); - ADD2ARGS(XtNy, ry); - XtSetValues(widget->w, argp, argn); - WQU->state = 2; - WQU->button = 0; - XtPopup(widget->w, XtGrabExclusive); - while (WQU->state) { - if (WQU->state == 1) { - if (WQU->button != 1) { - strncpy(responsep, - XawDialogGetValueString(WQU->w), responsen); - } - XtPopdown(widget->w); - } - Gprocessevents(TRUE, G_ONEEVENT); - } - XtUnrealizeWidget(widget->w); - Gpopdownflag = TRUE; - if (WQU->button == 1) - return -1; - break; + RESETARGS; + ADD2ARGS (XtNlabel, prompt); + ADD2ARGS (XtNvalue, args ? args : ""); + XtSetValues (WQU->w, argp, argn); + XtRealizeWidget (widget->w); + XQueryPointer ( + Gdisplay, XtWindow (widget->w), + &rwin, &cwin, &rx, &ry, &x, &y, &mask + ); + RESETARGS; + ADD2ARGS (XtNwidth, &width); + ADD2ARGS (XtNheight, &height); + XtGetValues (widget->w, argp, argn); + rx -= (width / 2), ry -= (height / 2); + if (rx + width > DisplayWidth (Gdisplay, Gscreenn)) + rx = DisplayWidth (Gdisplay, Gscreenn) - width; + if (ry + height > DisplayHeight (Gdisplay, Gscreenn)) + ry = DisplayHeight (Gdisplay, Gscreenn) - height; + if (rx < 0) + rx = 0; + if (ry < 0) + ry = 0; + RESETARGS; + ADD2ARGS (XtNx, rx); + ADD2ARGS (XtNy, ry); + XtSetValues (widget->w, argp, argn); + WQU->state = 2; + WQU->button = 0; + XtPopup (widget->w, XtGrabExclusive); + while (WQU->state) { + if (WQU->state == 1) { + if (WQU->button != 1) { + strncpy ( + responsep, XawDialogGetValueString (WQU->w), responsen + ); + } + XtPopdown (widget->w); + } + Gprocessevents (TRUE, G_ONEEVENT); + } + XtUnrealizeWidget (widget->w); + Gpopdownflag = TRUE; + if (WQU->button == 1) + return -1; + break; case G_QWFILE: - if (!XsraSelFile(Groot, prompt, "OK", "Cancel", "FAIL", - (args ? args : "/"), "r", NULL, responsep, - responsen)) { - Gpopdownflag = TRUE; - return -1; - } - Gpopdownflag = TRUE; - break; + if (!XsraSelFile ( + Groot, prompt, "OK", "Cancel", "FAIL", + (args ? args : "/"), "r", NULL, responsep, responsen + )) { + Gpopdownflag = TRUE; + return -1; + } + Gpopdownflag = TRUE; + break; case G_QWCHOICE: - if (!args) - return -1; - RESETARGS; - ADD2ARGS(XtNlabel, prompt); - XtSetValues(WQU->w, argp, argn); - for (s1 = args, i = 1; *s1; i++) { - s2 = s1; - while (*s2 && *s2 != '|') - s2++; - c = *s2, *s2 = 0; - strcpy(buttons[i], s1); - widgets[i] = XtCreateManagedWidget(s1, commandWidgetClass, - WQU->w, NULL, 0); - XtAddCallback(widgets[i], XtNcallback, qbwcallback, - (XtPointer) i); - *s2 = c; - s1 = s2; - if (*s1) - s1++; - } - XtRealizeWidget(widget->w); - XQueryPointer(Gdisplay, XtWindow(widget->w), - &rwin, &cwin, &rx, &ry, &x, &y, &mask); - RESETARGS; - ADD2ARGS(XtNwidth, &width); - ADD2ARGS(XtNheight, &height); - XtGetValues(widget->w, argp, argn); - rx -= (width / 2), ry -= (height / 2); - if (rx + width > DisplayWidth(Gdisplay, Gscreenn)) - rx = DisplayWidth(Gdisplay, Gscreenn) - width; - if (ry + height > DisplayHeight(Gdisplay, Gscreenn)) - ry = DisplayHeight(Gdisplay, Gscreenn) - height; - if (rx < 0) - rx = 0; - if (ry < 0) - ry = 0; - RESETARGS; - ADD2ARGS(XtNx, rx); - ADD2ARGS(XtNy, ry); - XtSetValues(widget->w, argp, argn); - WQU->state = 2; - WQU->button = 0; - XtPopup(widget->w, XtGrabExclusive); - while (WQU->state) { - if (WQU->state == 1) { - if (WQU->button > 0) - strncpy(responsep, buttons[WQU->button], responsen); - XtPopdown(widget->w); - } - Gprocessevents(TRUE, G_ONEEVENT); - } - XtUnrealizeWidget(widget->w); - for (i--; i > 0; i--) - XtDestroyWidget(widgets[i]); - Gpopdownflag = TRUE; - break; + if (!args) + return -1; + RESETARGS; + ADD2ARGS (XtNlabel, prompt); + XtSetValues (WQU->w, argp, argn); + for (s1 = args, i = 1; *s1; i++) { + s2 = s1; + while (*s2 && *s2 != '|') + s2++; + c = *s2, *s2 = 0; + strcpy (buttons[i], s1); + widgets[i] = XtCreateManagedWidget ( + s1, commandWidgetClass, WQU->w, NULL, 0 + ); + XtAddCallback (widgets[i], XtNcallback, qbwcallback, (XtPointer) i); + *s2 = c; + s1 = s2; + if (*s1) + s1++; + } + XtRealizeWidget (widget->w); + XQueryPointer ( + Gdisplay, XtWindow (widget->w), + &rwin, &cwin, &rx, &ry, &x, &y, &mask + ); + RESETARGS; + ADD2ARGS (XtNwidth, &width); + ADD2ARGS (XtNheight, &height); + XtGetValues (widget->w, argp, argn); + rx -= (width / 2), ry -= (height / 2); + if (rx + width > DisplayWidth (Gdisplay, Gscreenn)) + rx = DisplayWidth (Gdisplay, Gscreenn) - width; + if (ry + height > DisplayHeight (Gdisplay, Gscreenn)) + ry = DisplayHeight (Gdisplay, Gscreenn) - height; + if (rx < 0) + rx = 0; + if (ry < 0) + ry = 0; + RESETARGS; + ADD2ARGS (XtNx, rx); + ADD2ARGS (XtNy, ry); + XtSetValues (widget->w, argp, argn); + WQU->state = 2; + WQU->button = 0; + XtPopup (widget->w, XtGrabExclusive); + while (WQU->state) { + if (WQU->state == 1) { + if (WQU->button > 0) + strncpy (responsep, buttons[WQU->button], responsen); + XtPopdown (widget->w); + } + Gprocessevents (TRUE, G_ONEEVENT); + } + XtUnrealizeWidget (widget->w); + for (i--; i > 0; i--) + XtDestroyWidget (widgets[i]); + Gpopdownflag = TRUE; + break; } if (responsep[0] && responsep[strlen(responsep) - 1] == '\n') - responsep[strlen(responsep) - 1] = 0; + responsep[strlen(responsep) - 1] = 0; return 0; } -void Gqwpopaction(Widget w, XEvent * evp, char **app, unsigned int *anp) -{ +void Gqwpopaction (Widget w, XEvent *evp, char **app, unsigned int *anp) { Gwidget_t *widget; char c; if (evp->type == KeyPress || evp->type == KeyRelease) - XLookupString((XKeyEvent *) evp, &c, 1, NULL, NULL); + XLookupString ((XKeyEvent *) evp, &c, 1, NULL, NULL); if (c != 13) - return; - widget = findwidget((unsigned long) XtParent(XtParent(w)), - G_QUERYWIDGET); + return; + widget = findwidget ( + (unsigned long) XtParent (XtParent (w)), G_QUERYWIDGET + ); WQU->state = 1; } -static void qwcallback(Widget w, XtPointer clientdata, XtPointer calldata) -{ +static void qwcallback (Widget w, XtPointer clientdata, XtPointer calldata) { Gwidget_t *widget; - widget = findwidget((unsigned long) w, G_QUERYWIDGET); + widget = findwidget ((unsigned long) w, G_QUERYWIDGET); WQU->state = 0; } -static void qbwcallback(Widget w, XtPointer clientdata, XtPointer calldata) -{ +static void qbwcallback (Widget w, XtPointer clientdata, XtPointer calldata) { Gwidget_t *widget; - widget = findwidget((unsigned long) XtParent(XtParent(w)), - G_QUERYWIDGET); + widget = findwidget ( + (unsigned long) XtParent (XtParent (w)), G_QUERYWIDGET + ); WQU->button = (long) clientdata; WQU->state = 1; } diff --git a/cmd/lefty/ws/x11/gscroll.c b/cmd/lefty/ws/x11/gscroll.c index f7365779f..6a8016548 100644 --- a/cmd/lefty/ws/x11/gscroll.c +++ b/cmd/lefty/ws/x11/gscroll.c @@ -14,15 +14,15 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -/* Lefteris Koutsofios - AT&T Bell Laboratories */ +/* Lefteris Koutsofios - AT&T Labs Research */ #include "common.h" #include "g.h" #include "gcommon.h" -int GScreatewidget(Gwidget_t * parent, Gwidget_t * widget, - int attrn, Gwattr_t * attrp) -{ +int GScreatewidget ( + Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp +) { PIXsize_t ps; #if XlibSpecificationRelease < 5 Widget w; @@ -32,87 +32,89 @@ int GScreatewidget(Gwidget_t * parent, Gwidget_t * widget, int color; if (!parent) { - Gerr(POS, G_ERRNOPARENTWIDGET); - return -1; + Gerr (POS, G_ERRNOPARENTWIDGET); + return -1; } ps.x = ps.y = MINSWSIZE; RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINSWSIZE); - break; - case G_ATTRBORDERWIDTH: - ADD2ARGS(XtNborderWidth, attrp[ai].u.i); - break; - case G_ATTRCHILDCENTER: - Gerr(POS, G_ERRCANNOTSETATTR1, "childcenter"); - return -1; - case G_ATTRMODE: - if (Strcmp("forcebars", attrp[ai].u.t) == 0) - ADD2ARGS(XtNforceBars, True); - else { - Gerr(POS, G_ERRBADATTRVALUE, attrp[ai].u.t); - return -1; + switch (attrp[ai].id) { + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINSWSIZE); + break; + case G_ATTRBORDERWIDTH: + ADD2ARGS (XtNborderWidth, attrp[ai].u.i); + break; + case G_ATTRCHILDCENTER: + Gerr (POS, G_ERRCANNOTSETATTR1, "childcenter"); + return -1; + case G_ATTRMODE: + if (strcmp ("forcebars", attrp[ai].u.t) == 0) + ADD2ARGS (XtNforceBars, 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_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_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR1, "windowid"); + return -1; + case G_ATTRUSERDATA: + widget->udata = attrp[ai].u.u; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } - ADD2ARGS(XtNallowHoriz, True); - ADD2ARGS(XtNallowVert, True); - ADD2ARGS(XtNwidth, ps.x); - ADD2ARGS(XtNheight, ps.y); - if (!(widget->w = XtCreateWidget("scroll", viewportWidgetClass, - parent->w, argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; + ADD2ARGS (XtNallowHoriz, True); + ADD2ARGS (XtNallowVert, True); + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + if (!(widget->w = XtCreateWidget ( + "scroll", viewportWidgetClass, parent->w, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; } #if XlibSpecificationRelease < 5 RESETARGS; - ADD2ARGS(XtNwidth, ps.x); - ADD2ARGS(XtNheight, ps.y); - if (!(w = XtCreateWidget("owsucks", formWidgetClass, - widget->w, argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + if (!(w = XtCreateWidget ( + "owsucks", formWidgetClass, widget->w, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; } - Glazymanage(w); - Glazymanage(widget->w); - XtDestroyWidget(w); + Glazymanage (w); + Glazymanage (widget->w); + XtDestroyWidget (w); #else - Glazymanage(widget->w); + Glazymanage (widget->w); #endif return 0; } -int GSsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GSsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { PIXpoint_t po; PIXsize_t ps; Dimension width, height; @@ -122,132 +124,129 @@ int GSsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINSWSIZE); - ADD2ARGS(XtNwidth, ps.x); - ADD2ARGS(XtNheight, ps.y); - break; - case G_ATTRBORDERWIDTH: - ADD2ARGS(XtNborderWidth, attrp[ai].u.i); - break; - case G_ATTRCHILDCENTER: - GETORIGIN(attrp[ai].u.p, po); - ADD2ARGS(XtNwidth, &width); - ADD2ARGS(XtNheight, &height); - XtGetValues(widget->w, argp, argn); - po.x -= width / 2, po.y -= height / 2; - if (po.x < 0) - po.x = 0; - if (po.y < 0) - po.y = 0; - XawViewportSetCoordinates(widget->w, po.x, po.y); - break; - case G_ATTRMODE: - if (Strcmp("forcebars", attrp[ai].u.t) == 0) - ADD2ARGS(XtNforceBars, 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; + switch (attrp[ai].id) { + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINSWSIZE); + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + break; + case G_ATTRBORDERWIDTH: + ADD2ARGS (XtNborderWidth, attrp[ai].u.i); + break; + case G_ATTRCHILDCENTER: + GETORIGIN (attrp[ai].u.p, po); + ADD2ARGS (XtNwidth, &width); + ADD2ARGS (XtNheight, &height); + XtGetValues (widget->w, argp, argn); + po.x -= width / 2, po.y -= height / 2; + if (po.x < 0) + po.x = 0; + if (po.y < 0) + po.y = 0; + XawViewportSetCoordinates (widget->w, po.x, po.y); + break; + case G_ATTRMODE: + if (strcmp ("forcebars", attrp[ai].u.t) == 0) + ADD2ARGS (XtNforceBars, 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); } - 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_ERRCANNOTSETATTR2, "windowid"); - return -1; - case G_ATTRUSERDATA: - widget->udata = attrp[ai].u.u; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR2, "windowid"); + return -1; + 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); + XtSetValues (widget->w, argp, argn); return 0; } -int GSgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GSgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { Dimension width, height; Position x, y; Boolean tf; Gwidget_t *child; int ai, wi; - child = 0; 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_ATTRCHILDCENTER: - for (wi = 0; wi < Gwidgetn; wi++) { - child = &Gwidgets[wi]; - if (child->inuse && child->pwi == widget - &Gwidgets[0]) - break; - } - if (wi == Gwidgetn) { - Gerr(POS, G_ERRNOCHILDWIDGET); - return -1; - } - ADD2ARGS(XtNwidth, &width); - ADD2ARGS(XtNheight, &height); - XtGetValues(widget->w, argp, argn); - RESETARGS; - ADD2ARGS(XtNx, &x); - ADD2ARGS(XtNy, &y); - XtGetValues(child->w, argp, argn); - attrp[ai].u.p.x = width / 2 - x, attrp[ai].u.p.y = - height / 2 - y; - break; - case G_ATTRMODE: - ADD2ARGS(XtNforceBars, &tf); - attrp[ai].u.t = (tf == True) ? "forcebars" : ""; - break; - case G_ATTRWINDOWID: - sprintf(&Gbufp[0], "0x%lx", XtWindow(widget->w)); - attrp[ai].u.t = &Gbufp[0]; - break; - case G_ATTRUSERDATA: - attrp[ai].u.u = widget->udata; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + 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_ATTRCHILDCENTER: + for (wi = 0; wi < Gwidgetn; wi++) { + child = &Gwidgets[wi]; + if (child->inuse && child->pwi == widget - &Gwidgets[0]) + break; + } + if (wi == Gwidgetn) { + Gerr (POS, G_ERRNOCHILDWIDGET); + return -1; + } + ADD2ARGS (XtNwidth, &width); + ADD2ARGS (XtNheight, &height); + XtGetValues (widget->w, argp, argn); + RESETARGS; + ADD2ARGS (XtNx, &x); + ADD2ARGS (XtNy, &y); + XtGetValues (child->w, argp, argn); + attrp[ai].u.p.x = width / 2 - x, attrp[ai].u.p.y = height / 2 - y; + break; + case G_ATTRMODE: + ADD2ARGS (XtNforceBars, &tf); + attrp[ai].u.t = (tf == True) ? "forcebars" : ""; + break; + case G_ATTRWINDOWID: + sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w)); + attrp[ai].u.t = &Gbufp[0]; + break; + case G_ATTRUSERDATA: + attrp[ai].u.u = widget->udata; + break; + default: + Gerr (POS, G_ERRBADATTRID, attrp[ai].id); + return -1; + } } return 0; } -int GSdestroywidget(Gwidget_t * widget) -{ - XtDestroyWidget(widget->w); +int GSdestroywidget (Gwidget_t *widget) { + XtDestroyWidget (widget->w); return 0; } @@ -255,39 +254,36 @@ int GSdestroywidget(Gwidget_t * widget) #include #include -void XawViewportSetCoordinates(Widget gw, Position x, Position y) -{ +void XawViewportSetCoordinates (Widget gw, Position x, Position y) { ViewportWidget w = (ViewportWidget) gw; Widget child = w->viewport.child; Widget clip = w->viewport.clip; Position mx, my; if (x > (int) child->core.width) - x = child->core.width; + x = child->core.width; else if (x < 0) - x = child->core.x; + x = child->core.x; if (y > (int) child->core.height) - y = child->core.height; + y = child->core.height; else if (y < 0) - y = child->core.y; + y = child->core.y; mx = -x, my = -y; - if (-mx + (int) clip->core.width > (int) child->core.width) - mx = -(child->core.width - clip->core.width); + if (- mx + (int) clip->core.width > (int) child->core.width) + mx = - (child->core.width - clip->core.width); - if (-my + (int) clip->core.height > (int) child->core.height) - my = -(child->core.height - clip->core.height); + if (- my + (int) clip->core.height > (int) child->core.height) + my = - (child->core.height - clip->core.height); /* make sure we never move past left/top borders */ - if (mx >= 0) - mx = 0; - if (my >= 0) - my = 0; + if (mx >= 0) mx = 0; + if (my >= 0) my = 0; - XtMoveWidget(child, mx, my); - XtUnmanageChild(child); - XtManageChild(child); + XtMoveWidget (child, mx, my); + XtUnmanageChild (child); + XtManageChild (child); } #endif diff --git a/cmd/lefty/ws/x11/gtext.c b/cmd/lefty/ws/x11/gtext.c index 86ec9d208..b35d4a664 100644 --- a/cmd/lefty/ws/x11/gtext.c +++ b/cmd/lefty/ws/x11/gtext.c @@ -14,7 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -/* Lefteris Koutsofios - AT&T Bell Laboratories */ +/* Lefteris Koutsofios - AT&T Labs Research */ #include "common.h" #include "g.h" @@ -23,9 +23,9 @@ #define WTU widget->u.t -int GTcreatewidget(Gwidget_t * parent, Gwidget_t * widget, - int attrn, Gwattr_t * attrp) -{ +int GTcreatewidget ( + Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp +) { PIXsize_t ps; char *s; int ai; @@ -33,94 +33,95 @@ int GTcreatewidget(Gwidget_t * parent, Gwidget_t * widget, int color; static XawTextSelectType sarray[] = { - XawselectLine, XawselectNull + XawselectLine, XawselectNull }; if (!parent) { - Gerr(POS, G_ERRNOPARENTWIDGET); - return -1; + Gerr (POS, G_ERRNOPARENTWIDGET); + return -1; } WTU->func = NULL; ps.x = ps.y = MINTWSIZE; s = "oneline"; RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINTWSIZE); - break; - case G_ATTRBORDERWIDTH: - ADD2ARGS(XtNborderWidth, attrp[ai].u.i); - break; - case G_ATTRTEXT: - ADD2ARGS(XtNstring, attrp[ai].u.t); - break; - case G_ATTRAPPENDTEXT: - Gerr(POS, G_ERRCANNOTSETATTR1, "appendtext"); - return -1; - case G_ATTRMODE: - s = attrp[ai].u.t; - break; - case G_ATTRCOLOR: - color = attrp[ai].u.c.index; - if (color != 0 && color != 1) { - Gerr(POS, G_ERRBADCOLORINDEX, color); - return -1; + switch (attrp[ai].id) { + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINTWSIZE); + break; + case G_ATTRBORDERWIDTH: + ADD2ARGS (XtNborderWidth, attrp[ai].u.i); + break; + case G_ATTRTEXT: + ADD2ARGS (XtNstring, attrp[ai].u.t); + break; + case G_ATTRAPPENDTEXT: + Gerr (POS, G_ERRCANNOTSETATTR1, "appendtext"); + return -1; + case G_ATTRMODE: + s = attrp[ai].u.t; + 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); } - 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_ATTRNEWLINECB: - WTU->func = (Gtwnewlinecb) 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; - } + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR1, "windowid"); + return -1; + case G_ATTRNEWLINECB: + WTU->func = (Gtwnewlinecb) 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 (Strcmp("oneline", s) == 0) - ADD2ARGS(XtNeditType, XawtextAppend); - else if (Strcmp("input", s) == 0 || Strcmp("select", s) == 0) - ADD2ARGS(XtNeditType, XawtextEdit); - else if (Strcmp("output", s) == 0) - ADD2ARGS(XtNeditType, XawtextRead); + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + if (strcmp ("oneline", s) == 0) + ADD2ARGS (XtNeditType, XawtextAppend); + else if (strcmp ("input", s) == 0 || strcmp ("select", s) == 0) + ADD2ARGS (XtNeditType, XawtextEdit); + else if (strcmp ("output", s) == 0) + ADD2ARGS (XtNeditType, XawtextRead); else { - Gerr(POS, G_ERRBADATTRVALUE, s); - return -1; + Gerr (POS, G_ERRBADATTRVALUE, s); + return -1; } - ADD2ARGS(XtNscrollHorizontal, XawtextScrollWhenNeeded); - ADD2ARGS(XtNscrollVertical, XawtextScrollWhenNeeded); - if (!(widget->w = XtCreateWidget("ascii", asciiTextWidgetClass, - parent->w, argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; + ADD2ARGS (XtNscrollHorizontal, XawtextScrollWhenNeeded); + ADD2ARGS (XtNscrollVertical, XawtextScrollWhenNeeded); + if (!(widget->w = XtCreateWidget ( + "ascii", asciiTextWidgetClass, parent->w, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; } - if (Strcmp("oneline", s) == 0 || Strcmp("input", s) == 0) - XtOverrideTranslations(widget->w, Gtweoltable); - else if (Strcmp("select", s) == 0) - XawTextSetSelectionArray(widget->w, sarray); - Glazymanage(widget->w); + if (strcmp ("oneline", s) == 0 || strcmp ("input", s) == 0) + XtOverrideTranslations (widget->w, Gtweoltable); + else if (strcmp ("select", s) == 0) + XawTextSetSelectionArray (widget->w, sarray); + Glazymanage (widget->w); return 0; } -int GTsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GTsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { PIXsize_t ps; XawTextBlock tb; int ai, li; @@ -129,78 +130,78 @@ int GTsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINTWSIZE); - ADD2ARGS(XtNwidth, ps.x); - ADD2ARGS(XtNheight, ps.y); - break; - case G_ATTRBORDERWIDTH: - ADD2ARGS(XtNborderWidth, attrp[ai].u.i); - break; - case G_ATTRTEXT: - ADD2ARGS(XtNstring, attrp[ai].u.t); - break; - case G_ATTRAPPENDTEXT: - XawTextSetInsertionPoint(widget->w, 327670000); - li = XawTextGetInsertionPoint(widget->w); - tb.firstPos = 0, tb.length = strlen(attrp[ai].u.t); - tb.ptr = attrp[ai].u.t, tb.format = FMT8BIT; - XawTextReplace(widget->w, li, li, &tb); - li = XawTextGetInsertionPoint(widget->w); - tb.firstPos = 0, tb.length = 1; - tb.ptr = "\n", tb.format = FMT8BIT; - XawTextReplace(widget->w, li, li, &tb); - break; - case G_ATTRMODE: - if (Strcmp("oneline", attrp[ai].u.t) == 0) - ADD2ARGS(XtNeditType, XawtextAppend); - else if (Strcmp("input", attrp[ai].u.t) == 0) - ADD2ARGS(XtNeditType, XawtextEdit); - else if (Strcmp("output", attrp[ai].u.t) == 0) - ADD2ARGS(XtNeditType, XawtextRead); - 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); + switch (attrp[ai].id) { + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINTWSIZE); + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + break; + case G_ATTRBORDERWIDTH: + ADD2ARGS (XtNborderWidth, attrp[ai].u.i); + break; + case G_ATTRTEXT: + ADD2ARGS (XtNstring, attrp[ai].u.t); + break; + case G_ATTRAPPENDTEXT: + XawTextSetInsertionPoint (widget->w, 327670000); + li = XawTextGetInsertionPoint (widget->w); + tb.firstPos = 0, tb.length = strlen (attrp[ai].u.t); + tb.ptr = attrp[ai].u.t, tb.format = FMT8BIT; + XawTextReplace (widget->w, li, li, &tb); + li = XawTextGetInsertionPoint (widget->w); + tb.firstPos = 0, tb.length = 1; + tb.ptr = "\n", tb.format = FMT8BIT; + XawTextReplace (widget->w, li, li, &tb); + break; + case G_ATTRMODE: + if (strcmp ("oneline", attrp[ai].u.t) == 0) + ADD2ARGS (XtNeditType, XawtextAppend); + else if (strcmp ("input", attrp[ai].u.t) == 0) + ADD2ARGS (XtNeditType, XawtextEdit); + else if (strcmp ("output", attrp[ai].u.t) == 0) + ADD2ARGS (XtNeditType, XawtextRead); + 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_ERRCANNOTSETATTR2, "windowid"); - return -1; - case G_ATTRNEWLINECB: - WTU->func = (Gtwnewlinecb) 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; - } + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR2, "windowid"); + return -1; + case G_ATTRNEWLINECB: + WTU->func = (Gtwnewlinecb) 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); + XtSetValues (widget->w, argp, argn); return 0; } -int GTgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GTgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { Dimension width, height; XawTextEditType mode; XawTextBlock tb; @@ -209,114 +210,110 @@ int GTgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) long fi, li; 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_ATTRTEXT: - w = XawTextGetSource(widget->w); - tb.firstPos = 0, tb.ptr = NULL, tb.format = - FMT8BIT, tb.length = 0; - rtn = XawTextSourceRead(w, 0, &tb, 30000); - if (rtn > Gbufn + 1) { - Gbufp = Marraygrow(Gbufp, (long) (rtn + 1) * BUFSIZE); - Gbufn = rtn + 1; - } - for (Gbufi = 0; Gbufi < rtn; Gbufi++) - Gbufp[Gbufi] = tb.ptr[Gbufi]; - Gbufp[Gbufi++] = '\000'; - attrp[ai].u.t = &Gbufp[0]; - break; - case G_ATTRAPPENDTEXT: - Gerr(POS, G_ERRCANNOTGETATTR, "appendtext"); - return -1; - case G_ATTRSELECTION: - w = XawTextGetSource(widget->w); - XawTextGetSelectionPos(widget->w, &fi, &li); - tb.firstPos = 0, tb.ptr = NULL, tb.format = - FMT8BIT, tb.length = 0; - rtn = XawTextSourceRead(w, fi, &tb, li - fi); - if (li - fi > Gbufn + 1) { - Gbufp = Marraygrow(Gbufp, (long) (rtn + 1) * BUFSIZE); - Gbufn = rtn + 1; - } - for (Gbufi = 0; Gbufi < li - fi; Gbufi++) - Gbufp[Gbufi] = tb.ptr[Gbufi]; - Gbufp[Gbufi++] = '\000'; - attrp[ai].u.t = &Gbufp[0]; - break; - case G_ATTRMODE: - ADD2ARGS(XtNeditType, &mode); - XtGetValues(widget->w, argp, argn); - if (mode == XawtextAppend) - attrp[ai].u.t = "oneline"; - else if (mode == XawtextEdit) - attrp[ai].u.t = "input"; - else if (mode == XawtextRead) - attrp[ai].u.t = "output"; - else { - panic(POS, "GTgetwidgetattr", "unexpected text mode"); - return -1; - } - break; - case G_ATTRWINDOWID: - sprintf(&Gbufp[0], "0x%lx", XtWindow(widget->w)); - attrp[ai].u.t = &Gbufp[0]; - break; - case G_ATTRNEWLINECB: - attrp[ai].u.func = (void *) (WTU->func); - break; - case G_ATTRUSERDATA: - attrp[ai].u.u = widget->udata; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + 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_ATTRTEXT: + w = XawTextGetSource (widget->w); + tb.firstPos = 0, tb.ptr = NULL, tb.format = FMT8BIT, tb.length = 0; + rtn = XawTextSourceRead (w, 0, &tb, 30000); + if (rtn > Gbufn + 1) { + Gbufp = Marraygrow (Gbufp, (long) (rtn + 1) * BUFSIZE); + Gbufn = rtn + 1; + } + for (Gbufi = 0; Gbufi < rtn; Gbufi++) + Gbufp[Gbufi] = tb.ptr[Gbufi]; + Gbufp[Gbufi++] = '\000'; + attrp[ai].u.t = &Gbufp[0]; + break; + case G_ATTRAPPENDTEXT: + Gerr (POS, G_ERRCANNOTGETATTR, "appendtext"); + return -1; + case G_ATTRSELECTION: + w = XawTextGetSource (widget->w); + XawTextGetSelectionPos (widget->w, &fi, &li); + tb.firstPos = 0, tb.ptr = NULL, tb.format = FMT8BIT, tb.length = 0; + rtn = XawTextSourceRead (w, fi, &tb, li - fi); + if (li - fi > Gbufn + 1) { + Gbufp = Marraygrow (Gbufp, (long) (rtn + 1) * BUFSIZE); + Gbufn = rtn + 1; + } + for (Gbufi = 0; Gbufi < li - fi; Gbufi++) + Gbufp[Gbufi] = tb.ptr[Gbufi]; + Gbufp[Gbufi++] = '\000'; + attrp[ai].u.t = &Gbufp[0]; + break; + case G_ATTRMODE: + ADD2ARGS (XtNeditType, &mode); + XtGetValues (widget->w, argp, argn); + if (mode == XawtextAppend) + attrp[ai].u.t = "oneline"; + else if (mode == XawtextEdit) + attrp[ai].u.t = "input"; + else if (mode == XawtextRead) + attrp[ai].u.t = "output"; + else { + panic (POS, "GTgetwidgetattr", "unexpected text mode"); + return -1; + } + break; + case G_ATTRWINDOWID: + sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w)); + attrp[ai].u.t = &Gbufp[0]; + break; + case G_ATTRNEWLINECB: + attrp[ai].u.func = WTU->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 GTdestroywidget(Gwidget_t * widget) -{ - XtDestroyWidget(widget->w); +int GTdestroywidget (Gwidget_t *widget) { + XtDestroyWidget (widget->w); return 0; } /* used for one line text input widgets */ -void Gtweolaction(Widget w, XEvent * evp, char **app, unsigned int *anp) -{ +void Gtweolaction (Widget w, XEvent *evp, char **app, unsigned int *anp) { Gwidget_t *widget; Widget ww; XawTextBlock tb; int ret, fi, li, n, i; - widget = findwidget((unsigned long) w, G_TEXTWIDGET); - li = XawTextGetInsertionPoint(w) - 1; - ww = XawTextGetSource(w); + widget = findwidget ((unsigned long) w, G_TEXTWIDGET); + li = XawTextGetInsertionPoint (w) - 1; + ww = XawTextGetSource (w); tb.firstPos = 0, tb.ptr = "\n", tb.format = FMT8BIT, tb.length = 1; - fi = XawTextSourceSearch(ww, li, XawsdLeft, &tb); + fi = XawTextSourceSearch (ww, li, XawsdLeft, &tb); if (fi == XawTextSearchError) - fi = 0; + fi = 0; else - fi++; + fi++; n = li - fi; Gbufp[(Gbufi = 0)] = '\000'; while (Gbufi != n) { - ret = XawTextSourceRead(ww, fi, &tb, n - Gbufi) - fi; - for (i = 0; i < ret; i++) - Gbufp[Gbufi++] = tb.ptr[i]; + ret = XawTextSourceRead (ww, fi, &tb, n - Gbufi) - fi; + for (i = 0; i < ret; i++) + Gbufp[Gbufi++] = tb.ptr[i]; } Gbufp[Gbufi] = '\000'; if (n >= 0 && WTU->func) - (*WTU->func) (widget - &Gwidgets[0], Gbufp); + (*WTU->func) (widget - &Gwidgets[0], Gbufp); } diff --git a/cmd/lefty/ws/x11/gview.c b/cmd/lefty/ws/x11/gview.c index c816adb72..d07a5982a 100644 --- a/cmd/lefty/ws/x11/gview.c +++ b/cmd/lefty/ws/x11/gview.c @@ -14,7 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -/* Lefteris Koutsofios - AT&T Bell Laboratories */ +/* Lefteris Koutsofios - AT&T Labs Research */ #include "common.h" #include "g.h" @@ -22,10 +22,10 @@ #define WVU widget->u.v -int GVcreatewidget(Gwidget_t * parent, Gwidget_t * widget, - int attrn, Gwattr_t * attrp) -{ - PIXpoint_t po = { 0, 0 }; +int GVcreatewidget ( + Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp +) { + PIXpoint_t po; PIXsize_t ps; XSizeHints hints; char *s; @@ -40,73 +40,73 @@ int GVcreatewidget(Gwidget_t * parent, Gwidget_t * widget, haveorigin = FALSE; RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRORIGIN: - haveorigin = TRUE; - GETORIGIN(attrp[ai].u.p, po); - ADD2ARGS(XtNx, po.x); - ADD2ARGS(XtNy, po.y); - break; - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINVWSIZE); - break; - case G_ATTRNAME: - s = attrp[ai].u.t; - 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); + switch (attrp[ai].id) { + case G_ATTRORIGIN: + haveorigin = TRUE; + GETORIGIN (attrp[ai].u.p, po); + ADD2ARGS (XtNx, po.x); + ADD2ARGS (XtNy, po.y); + break; + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINVWSIZE); + break; + case G_ATTRNAME: + s = attrp[ai].u.t; + 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_ATTRZORDER: - Gerr(POS, G_ERRCANNOTSETATTR1, "zorder"); - return -1; - case G_ATTRWINDOWID: - Gerr(POS, G_ERRCANNOTSETATTR1, "windowid"); - return -1; - case G_ATTREVENTCB: - WVU->func = (Gviewcb) 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; - } + break; + case G_ATTRZORDER: + Gerr (POS, G_ERRCANNOTSETATTR1, "zorder"); + return -1; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR1, "windowid"); + return -1; + case G_ATTREVENTCB: + WVU->func = (Gviewcb) 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 = XtAppCreateShell(s, "LEFTY", - topLevelShellWidgetClass, Gdisplay, - argp, argn))) { - Gerr(POS, G_ERRCANNOTCREATEWIDGET); - return -1; + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + if (!(widget->w = XtAppCreateShell ( + s, "LEFTY", topLevelShellWidgetClass, Gdisplay, argp, argn + ))) { + Gerr (POS, G_ERRCANNOTCREATEWIDGET); + return -1; } if (haveorigin) { - hints.x = po.x, hints.y = po.y; - hints.width = ps.x, hints.height = ps.y; - hints.flags = USPosition; - Glazyrealize(widget->w, TRUE, &hints); + hints.x = po.x, hints.y = po.y; + hints.width = ps.x, hints.height = ps.y; + hints.flags = USPosition; + Glazyrealize (widget->w, TRUE, &hints); } else - Glazyrealize(widget->w, FALSE, NULL); + Glazyrealize (widget->w, FALSE, NULL); return 0; } -int GVsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GVsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { PIXpoint_t po; PIXsize_t ps; int ai; @@ -115,136 +115,135 @@ int GVsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) RESETARGS; for (ai = 0; ai < attrn; ai++) { - switch (attrp[ai].id) { - case G_ATTRORIGIN: - GETORIGIN(attrp[ai].u.p, po); - ADD2ARGS(XtNx, po.x); - ADD2ARGS(XtNy, po.y); - break; - case G_ATTRSIZE: - GETSIZE(attrp[ai].u.s, ps, MINVWSIZE); - ADD2ARGS(XtNwidth, ps.x); - ADD2ARGS(XtNheight, ps.y); - break; - case G_ATTRNAME: + switch (attrp[ai].id) { + case G_ATTRORIGIN: + GETORIGIN (attrp[ai].u.p, po); + ADD2ARGS (XtNx, po.x); + ADD2ARGS (XtNy, po.y); + break; + case G_ATTRSIZE: + GETSIZE (attrp[ai].u.s, ps, MINVWSIZE); + ADD2ARGS (XtNwidth, ps.x); + ADD2ARGS (XtNheight, ps.y); + break; + case G_ATTRNAME: #if XlibSpecificationRelease < 5 - return -1; + return -1; #else - XmbSetWMProperties(Gdisplay, XtWindow(widget->w), - attrp[ai].u.t, attrp[ai].u.t, NULL, 0, NULL, - NULL, NULL); + XmbSetWMProperties ( + Gdisplay, XtWindow (widget->w), + attrp[ai].u.t, attrp[ai].u.t, NULL, 0, NULL, NULL, NULL + ); #endif - 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_ATTRZORDER: - Gflushlazyq(); - if (Strcmp(attrp[ai].u.t, "top") == 0) - XRaiseWindow(Gdisplay, XtWindow(widget->w)); - else if (Strcmp(attrp[ai].u.t, "bottom") == 0) - XLowerWindow(Gdisplay, XtWindow(widget->w)); - 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_ERRCANNOTSETATTR2, "windowid"); - return -1; - case G_ATTREVENTCB: - WVU->func = (Gviewcb) 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; - } + break; + case G_ATTRZORDER: + Gflushlazyq (); + if (strcmp (attrp[ai].u.t, "top") == 0) + XRaiseWindow (Gdisplay, XtWindow (widget->w)); + else if (strcmp (attrp[ai].u.t, "bottom") == 0) + XLowerWindow (Gdisplay, XtWindow (widget->w)); + else { + Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t); + return -1; + } + break; + case G_ATTRWINDOWID: + Gerr (POS, G_ERRCANNOTSETATTR2, "windowid"); + return -1; + case G_ATTREVENTCB: + WVU->func = (Gviewcb) 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); + XtSetValues (widget->w, argp, argn); return 0; } -int GVgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) -{ +int GVgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { Position x, y; Dimension width, height; int ai; for (ai = 0; ai < attrn; ai++) { - RESETARGS; - switch (attrp[ai].id) { - case G_ATTRORIGIN: - ADD2ARGS(XtNx, &x); - ADD2ARGS(XtNy, &y); - XtGetValues(widget->w, argp, argn); - attrp[ai].u.p.x = x, attrp[ai].u.p.y = y; - break; - 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_ATTRNAME: - Gerr(POS, G_ERRNOTIMPLEMENTED); - return -1; - case G_ATTRZORDER: - Gerr(POS, G_ERRNOTIMPLEMENTED); - return -1; - case G_ATTRWINDOWID: - sprintf(&Gbufp[0], "0x%lx", XtWindow(widget->w)); - attrp[ai].u.t = &Gbufp[0]; - break; - case G_ATTREVENTCB: - attrp[ai].u.func = (void *) (WVU->func); - break; - case G_ATTRUSERDATA: - attrp[ai].u.u = widget->udata; - break; - default: - Gerr(POS, G_ERRBADATTRID, attrp[ai].id); - return -1; - } + RESETARGS; + switch (attrp[ai].id) { + case G_ATTRORIGIN: + ADD2ARGS (XtNx, &x); + ADD2ARGS (XtNy, &y); + XtGetValues (widget->w, argp, argn); + attrp[ai].u.p.x = x, attrp[ai].u.p.y = y; + break; + 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_ATTRNAME: + Gerr (POS, G_ERRNOTIMPLEMENTED); + return -1; + case G_ATTRZORDER: + Gerr (POS, G_ERRNOTIMPLEMENTED); + return -1; + case G_ATTRWINDOWID: + sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w)); + attrp[ai].u.t = &Gbufp[0]; + break; + case G_ATTREVENTCB: + attrp[ai].u.func = WVU->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 GVdestroywidget(Gwidget_t * widget) -{ +int GVdestroywidget (Gwidget_t *widget) { WVU->closing = TRUE; - XtDestroyWidget(widget->w); + XtDestroyWidget (widget->w); return 0; } -void Gwmdelaction(Widget w, XEvent * evp, char **app, unsigned int *anp) -{ +void Gwmdelaction (Widget w, XEvent *evp, char **app, unsigned int *anp) { Gwidget_t *widget; Gevent_t gev; - widget = findwidget((unsigned long) w, G_VIEWWIDGET); + widget = findwidget ((unsigned long) w, G_VIEWWIDGET); if (!widget) - exit(0); - gev.type = G_MOUSE, gev.code = 0, gev.data = 0; + exit (0); + gev.type = 0, gev.code = 0, gev.data = 0; gev.wi = widget - &Gwidgets[0]; if (WVU->func) - (*WVU->func) (&gev); + (*WVU->func) (&gev); else - exit(0); + exit (0); } -- 2.40.0