]> granicus.if.org Git - graphviz/commitdiff
Update with new lefty, fixing many bugs and supporting new features
authorerg <devnull@localhost>
Fri, 8 Apr 2005 20:45:34 +0000 (20:45 +0000)
committererg <devnull@localhost>
Fri, 8 Apr 2005 20:45:34 +0000 (20:45 +0000)
cmd/lefty/ws/mswin32/gcanvas.c
cmd/lefty/ws/mswin32/gcommon.c

index e925119e9d692928c1fed9bf41f99f993f6a10b4..e08bb32fa39513eb98f91712703578bbc3f58601 100644 (file)
@@ -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"
 #define min(a, b) (((a) <= (b)) ? (a) : (b))
 
 static long gstyles[5] = {
-    /* G_SOLID */ PS_SOLID,
-    /* G_DASHED */ PS_DASH,
-    /* G_DOTTED */ PS_DOT,
-    /* G_LONGDASHED */ PS_DASH,
+    /* G_SOLID */       PS_SOLID,
+    /* G_DASHED */      PS_DASH,
+    /* G_DOTTED */      PS_DOT,
+    /* G_LONGDASHED */  PS_DASH,
     /* G_SHORTDASHED */ PS_DASH,
 };
 
 static char grays[][4] = {
-    {0x00, 0x00, 0x00, 0x00,},
-    {0x08, 0x00, 0x00, 0x00,},
-    {0x08, 0x00, 0x02, 0x00,},
-    {0x0A, 0x00, 0x02, 0x00,},
-    {0x0A, 0x00, 0x0A, 0x00,},
-    {0x0A, 0x04, 0x0A, 0x00,},
-    {0x0A, 0x04, 0x0A, 0x01,},
-    {0x0A, 0x05, 0x0A, 0x01,},
-    {0x0A, 0x05, 0x0A, 0x05,},
-    {0x0E, 0x05, 0x0A, 0x05,},
-    {0x0E, 0x05, 0x0B, 0x05,},
-    {0x0F, 0x05, 0x0B, 0x05,},
-    {0x0F, 0x05, 0x0F, 0x05,},
-    {0x0F, 0x0D, 0x0F, 0x05,},
-    {0x0F, 0x0D, 0x0F, 0x07,},
-    {0x0F, 0x0F, 0x0F, 0x07,},
-    {0x0F, 0x0F, 0x0F, 0x0F,},
+    { 0x00, 0x00, 0x00, 0x00 },
+    { 0x08, 0x00, 0x00, 0x00 },
+    { 0x08, 0x00, 0x02, 0x00 },
+    { 0x0A, 0x00, 0x02, 0x00 },
+    { 0x0A, 0x00, 0x0A, 0x00 },
+    { 0x0A, 0x04, 0x0A, 0x00 },
+    { 0x0A, 0x04, 0x0A, 0x01 },
+    { 0x0A, 0x05, 0x0A, 0x01 },
+    { 0x0A, 0x05, 0x0A, 0x05 },
+    { 0x0E, 0x05, 0x0A, 0x05 },
+    { 0x0E, 0x05, 0x0B, 0x05 },
+    { 0x0F, 0x05, 0x0B, 0x05 },
+    { 0x0F, 0x05, 0x0F, 0x05 },
+    { 0x0F, 0x0D, 0x0F, 0x05 },
+    { 0x0F, 0x0D, 0x0F, 0x07 },
+    { 0x0F, 0x0F, 0x0F, 0x07 },
+    { 0x0F, 0x0F, 0x0F, 0x0F }
 };
 
 static int curcursori = -1;
 
-static void bezier(PIXpoint_t, PIXpoint_t, PIXpoint_t, PIXpoint_t);
-static HFONT findfont(char *, int);
-static int scalebitmap(Gwidget_t *, Gbitmap_t *, Gsize_t, int, int);
-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 Gsize_t spixtodraw(Gwidget_t *, PIXsize_t);
-static Grect_t rpixtodraw(Gwidget_t *, PIXrect_t);
-static PIXrect_t rdrawtobpix(Gbitmap_t *, Grect_t);
-static PIXpoint_t pdrawtobpix(Gbitmap_t *, Gpoint_t);
-
-int GCcreatewidget(Gwidget_t * parent, Gwidget_t * widget,
-                  int attrn, Gwattr_t * attrp)
-{
+static void bezier (PIXpoint_t, PIXpoint_t, PIXpoint_t, PIXpoint_t);
+static HFONT findfont (char *, int);
+static int scalebitmap (Gwidget_t *, Gbitmap_t *, Gsize_t, int, int);
+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 Gsize_t    spixtodraw (Gwidget_t *, PIXsize_t);
+static Grect_t    rpixtodraw (Gwidget_t *, PIXrect_t);
+static PIXrect_t  rdrawtobpix (Gbitmap_t *, Grect_t);
+static PIXpoint_t pdrawtobpix (Gbitmap_t *, Gpoint_t);
+
+int GCcreatewidget (
+    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
+{
     PIXsize_t ps;
-    LOGPALETTE pal[2];         /* the 2 here is to provide enough space
-                                  for palPalEntry[0] and [1] */
+    /* the 2 here is to provide enough space for palPalEntry[0] and [1] */
+    LOGPALETTE pal[2];
+
     HBRUSH brush;
     HPEN pen;
     HBITMAP bmap;
@@ -89,8 +90,8 @@ int GCcreatewidget(Gwidget_t * parent, Gwidget_t * widget,
     int color, ai, i;
 
     if (!parent) {
-       Gerr(POS, G_ERRNOPARENTWIDGET);
-       return -1;
+        Gerr (POS, G_ERRNOPARENTWIDGET);
+        return -1;
     }
     wflags = WS_CHILDWINDOW;
     WCU->func = NULL;
@@ -99,56 +100,57 @@ int GCcreatewidget(Gwidget_t * parent, Gwidget_t * widget,
     WCU->bstate[0] = WCU->bstate[1] = WCU->bstate[2] = 0;
     ps.x = ps.y = MINCWSIZE;
     for (ai = 0; ai < attrn; ai++) {
-       switch (attrp[ai].id) {
-       case G_ATTRSIZE:
-           GETSIZE(attrp[ai].u.s, ps, MINCWSIZE);
-           break;
-       case G_ATTRBORDERWIDTH:
-           wflags |= WS_BORDER;
-           break;
-       case G_ATTRCURSOR:
-           /* will do it after the widget is created */
-           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_ATTREVENTCB:
-           WCU->func = 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;
-       }
+        switch (attrp[ai].id) {
+        case G_ATTRSIZE:
+            GETSIZE (attrp[ai].u.s, ps, MINCWSIZE);
+            break;
+        case G_ATTRBORDERWIDTH:
+            wflags |= WS_BORDER;
+            break;
+        case G_ATTRCURSOR:
+            /* will do it after the widget is created */
+            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_ATTREVENTCB:
+            WCU->func = 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;
+        }
     }
-    Gadjustwrect(parent, &ps);
+    Gadjustwrect (parent, &ps);
     WCU->wrect.o.x = 0.0, WCU->wrect.o.y = 0.0;
     WCU->wrect.c.x = 1.0, WCU->wrect.c.y = 1.0;
     WCU->vsize.x = ps.x, WCU->vsize.y = ps.y;
-    if (!(widget->w = CreateWindow("CanvasClass", "canvas", wflags, 0, 0,
-                                  ps.x, ps.y, parent->w,
-                                  (HMENU) (widget - &Gwidgets[0]),
-                                  hinstance, NULL))) {
-       Gerr(POS, G_ERRCANNOTCREATEWIDGET);
-       return -1;
+    if (!(widget->w = CreateWindow (
+        "CanvasClass", "canvas", wflags, 0, 0,
+        ps.x, ps.y, parent->w, (HMENU) (widget - &Gwidgets[0]),
+        hinstance, NULL
+    ))) {
+        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
+        return -1;
     }
-    ShowWindow(widget->w, SW_SHOW);
-    UpdateWindow(widget->w);
-    SetCursor(LoadCursor((HINSTANCE) NULL, IDC_ARROW));
-    GC = GetDC(widget->w);
+    ShowWindow (widget->w, SW_SHOW);
+    UpdateWindow (widget->w);
+    SetCursor (LoadCursor ((HINSTANCE) NULL, IDC_ARROW));
+    GC = GetDC (widget->w);
     WCU->ncolor = 2;
-    pal[0].palVersion = 0x300; /* HA HA HA */
+    pal[0].palVersion = 0x300; /* HA HA HA */
     pal[0].palNumEntries = 2;
     pal[0].palPalEntry[0].peRed = 255;
     pal[0].palPalEntry[0].peGreen = 255;
@@ -158,23 +160,23 @@ int GCcreatewidget(Gwidget_t * parent, Gwidget_t * widget,
     pal[0].palPalEntry[1].peGreen = 0;
     pal[0].palPalEntry[1].peBlue = 0;
     pal[0].palPalEntry[1].peFlags = 0;
-    WCU->cmap = CreatePalette(&pal[0]);
+    WCU->cmap = CreatePalette (&pal[0]);
     WCU->colors[0].color = pal[0].palPalEntry[0];
     for (i = 1; i < G_MAXCOLORS; i++)
-       WCU->colors[i].color = pal[0].palPalEntry[1];
-    SelectPalette(GC, WCU->cmap, FALSE);
-    RealizePalette(GC);
+        WCU->colors[i].color = pal[0].palPalEntry[1];
+    SelectPalette (GC, WCU->cmap, FALSE);
+    RealizePalette (GC);
     WCU->colors[0].inuse = TRUE;
     WCU->colors[1].inuse = TRUE;
     for (i = 2; i < G_MAXCOLORS; i++)
-       WCU->colors[i].inuse = FALSE;
+        WCU->colors[i].inuse = FALSE;
     WCU->gattr.color = 1;
-    brush = CreateSolidBrush(PALETTEINDEX(1));
-    SelectObject(GC, brush);
-    pen = CreatePen(PS_SOLID, 1, PALETTEINDEX(1));
-    SelectObject(GC, pen);
-    SetTextColor(GC, PALETTEINDEX(1));
-    SetBkMode(GC, TRANSPARENT);
+    brush = CreateSolidBrush (PALETTEINDEX (1));
+    SelectObject (GC, brush);
+    pen = CreatePen (PS_SOLID, 1, PALETTEINDEX (1));
+    SelectObject (GC, pen);
+    SetTextColor (GC, PALETTEINDEX (1));
+    SetBkMode (GC, TRANSPARENT);
     WCU->gattr.width = 0;
     WCU->gattr.mode = G_SRC;
     WCU->gattr.fill = 0;
@@ -182,75 +184,74 @@ int GCcreatewidget(Gwidget_t * parent, Gwidget_t * widget,
     WCU->defgattr = WCU->gattr;
     WCU->font = NULL;
     if (Gdepth == 1) {
-       for (i = 0; i < 17; i++) {
-           if (!(bmap = CreateBitmap(4, 4, 1, 1, &grays[i][0])))
-               continue;
-           WCU->grays[i] = CreatePatternBrush(bmap);
-       }
+        for (i = 0; i < 17; i++) {
+            if (!(bmap = CreateBitmap (4, 4, 1, 1, &grays[i][0])))
+                continue;
+            WCU->grays[i] = CreatePatternBrush (bmap);
+        }
     }
     for (ai = 0; ai < attrn; ai++) {
-       switch (attrp[ai].id) {
-       case G_ATTRCURSOR:
-           if (Strcmp(attrp[ai].u.t, "watch") == 0) {
-               curcursori = 1;
-               cursor = LoadCursor((HINSTANCE) NULL, IDC_WAIT);
-           } else if (Strcmp(attrp[ai].u.t, "default") == 0) {
-               curcursori = -1;
-               cursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-           } else {
-               Gerr(POS, G_ERRNOSUCHCURSOR, attrp[ai].u.t);
-               return -1;
-           }
-           SetCursor(cursor);
-           break;
-       case G_ATTRCOLOR:
-           color = attrp[ai].u.c.index;
-           if (color < 0 || color > G_MAXCOLORS) {
-               Gerr(POS, G_ERRBADCOLORINDEX, color);
-               return -1;
-           }
-           WCU->colors[color].color.peRed = attrp[ai].u.c.r;
-           WCU->colors[color].color.peGreen = attrp[ai].u.c.g;
-           WCU->colors[color].color.peBlue = attrp[ai].u.c.b;
-           WCU->colors[color].color.peFlags = 0;
-           if (color >= WCU->ncolor)
-               ResizePalette(WCU->cmap, color + 1), WCU->ncolor =
-                   color + 1;
-           SetPaletteEntries(WCU->cmap, (int) color, 1,
-                             &WCU->colors[color].color);
-           RealizePalette(GC);
-           WCU->colors[color].inuse = TRUE;
-           if (color == WCU->gattr.color)
-               WCU->gattr.color = -1;
-           break;
-       case G_ATTRVIEWPORT:
-           if (attrp[ai].u.s.x == 0)
-               attrp[ai].u.s.x = 1;
-           if (attrp[ai].u.s.y == 0)
-               attrp[ai].u.s.y = 1;
-           WCU->vsize.x = (int) (attrp[ai].u.s.x + 0.5);
-           WCU->vsize.y = (int) (attrp[ai].u.s.y + 0.5);
-           SetWindowPos(widget->w, (HWND) NULL, 0, 0, WCU->vsize.x,
-                        WCU->vsize.y,
-                        SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
-           break;
-       case G_ATTRWINDOW:
-           if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)
-               attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;
-           if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)
-               attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;
-           WCU->wrect = attrp[ai].u.r;
-           break;
-       }
+        switch (attrp[ai].id) {
+        case G_ATTRCURSOR:
+            if (strcmp (attrp[ai].u.t, "watch") == 0) {
+                curcursori = 1;
+                cursor = LoadCursor ((HINSTANCE) NULL, IDC_WAIT);
+            } else if (strcmp (attrp[ai].u.t, "default") == 0) {
+                curcursori = -1;
+                cursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+            } else {
+                Gerr (POS, G_ERRNOSUCHCURSOR, attrp[ai].u.t);
+                return -1;
+            }
+            SetCursor (cursor);
+            break;
+        case G_ATTRCOLOR:
+            color = attrp[ai].u.c.index;
+            if (color < 0 || color > G_MAXCOLORS) {
+                Gerr (POS, G_ERRBADCOLORINDEX, color);
+                return -1;
+            }
+            WCU->colors[color].color.peRed = attrp[ai].u.c.r;
+            WCU->colors[color].color.peGreen = attrp[ai].u.c.g;
+            WCU->colors[color].color.peBlue = attrp[ai].u.c.b;
+            WCU->colors[color].color.peFlags = 0;
+            if (color >= WCU->ncolor)
+                ResizePalette (WCU->cmap, color + 1), WCU->ncolor = color + 1;
+            SetPaletteEntries (
+                WCU->cmap, (int) color, 1, &WCU->colors[color].color);
+            RealizePalette (GC);
+            WCU->colors[color].inuse = TRUE;
+            if (color == WCU->gattr.color)
+                WCU->gattr.color = -1;
+            break;
+        case G_ATTRVIEWPORT:
+            if (attrp[ai].u.s.x == 0)
+                attrp[ai].u.s.x = 1;
+            if (attrp[ai].u.s.y == 0)
+                attrp[ai].u.s.y = 1;
+            WCU->vsize.x = (int) (attrp[ai].u.s.x + 0.5);
+            WCU->vsize.y = (int) (attrp[ai].u.s.y + 0.5);
+            SetWindowPos (
+                widget->w, (HWND) NULL, 0, 0, WCU->vsize.x,
+                WCU->vsize.y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE
+            );
+            break;
+        case G_ATTRWINDOW:
+            if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)
+                attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;
+            if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)
+                attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;
+            WCU->wrect = attrp[ai].u.r;
+            break;
+        }
     }
     if (parent && parent->type == G_ARRAYWIDGET)
-       Gawinsertchild(parent, widget);
-    Gadjustclip(widget);
+        Gawinsertchild (parent, widget);
+    Gadjustclip (widget);
     return 0;
 }
 
-int GCsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp)
-{
+int GCsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
     HCURSOR cursor;
     Gwidget_t *parent;
     PIXsize_t ps;
@@ -260,361 +261,352 @@ int GCsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp)
     parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
     wflags1 = SWP_NOMOVE | SWP_NOZORDER;
     for (ai = 0; ai < attrn; ai++) {
-       switch (attrp[ai].id) {
-       case G_ATTRSIZE:
-           GETSIZE(attrp[ai].u.s, ps, MINCWSIZE);
-           Gadjustwrect(parent, &ps);
-           SetWindowPos(widget->w, (HWND) NULL, 0, 0, ps.x, ps.y,
-                        wflags1);
-           break;
-       case G_ATTRBORDERWIDTH:
-           Gerr(POS, G_ERRCANNOTSETATTR2, "borderwidth");
-           return -1;
-       case G_ATTRCURSOR:
-           if (Strcmp(attrp[ai].u.t, "watch") == 0) {
-               curcursori = 1;
-               cursor = LoadCursor((HINSTANCE) NULL, IDC_WAIT);
-           } else if (Strcmp(attrp[ai].u.t, "default") == 0) {
-               curcursori = -1;
-               cursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-           } else {
-               Gerr(POS, G_ERRNOSUCHCURSOR, attrp[ai].u.t);
-               return -1;
-           }
-           SetCursor(cursor);
-           break;
-       case G_ATTRCOLOR:
-           color = attrp[ai].u.c.index;
-           if (color < 0 || color > G_MAXCOLORS) {
-               Gerr(POS, G_ERRBADCOLORINDEX, color);
-               return -1;
-           }
-           WCU->colors[color].color.peRed = attrp[ai].u.c.r;
-           WCU->colors[color].color.peGreen = attrp[ai].u.c.g;
-           WCU->colors[color].color.peBlue = attrp[ai].u.c.b;
-           WCU->colors[color].color.peFlags = 0;
-           if (color >= WCU->ncolor)
-               ResizePalette(WCU->cmap, color + 1), WCU->ncolor =
-                   color + 1;
-           SetPaletteEntries(WCU->cmap, (int) color, 1,
-                             &WCU->colors[color].color);
-           RealizePalette(GC);
-           WCU->colors[color].inuse = TRUE;
-           if (color == WCU->gattr.color)
-               WCU->gattr.color = -1;
-           break;
-       case G_ATTRVIEWPORT:
-           if (attrp[ai].u.s.x == 0)
-               attrp[ai].u.s.x = 1;
-           if (attrp[ai].u.s.y == 0)
-               attrp[ai].u.s.y = 1;
-           WCU->vsize.x = (int) (attrp[ai].u.s.x + 0.5);
-           WCU->vsize.y = (int) (attrp[ai].u.s.y + 0.5);
-           ps.x = WCU->vsize.x, ps.y = WCU->vsize.y;
-           Gadjustwrect(&Gwidgets[widget->pwi], &ps);
-           SetWindowPos(widget->w, (HWND) NULL, 0, 0, ps.x,
-                        ps.y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
-           Gadjustclip(widget);
-           break;
-       case G_ATTRWINDOW:
-           if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)
-               attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;
-           if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)
-               attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;
-           WCU->wrect = attrp[ai].u.r;
-           Gadjustclip(widget);
-           break;
-       case G_ATTRWINDOWID:
-           Gerr(POS, G_ERRCANNOTSETATTR2, "windowid");
-           return -1;
-       case G_ATTREVENTCB:
-           WCU->func = 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;
-       }
+        switch (attrp[ai].id) {
+        case G_ATTRSIZE:
+            GETSIZE (attrp[ai].u.s, ps, MINCWSIZE);
+            Gadjustwrect (parent, &ps);
+            SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps.x, ps.y, wflags1);
+            break;
+        case G_ATTRBORDERWIDTH:
+            Gerr (POS, G_ERRCANNOTSETATTR2, "borderwidth");
+            return -1;
+        case G_ATTRCURSOR:
+            if (strcmp (attrp[ai].u.t, "watch") == 0) {
+                curcursori = 1;
+                cursor = LoadCursor ((HINSTANCE) NULL, IDC_WAIT);
+            } else if (strcmp (attrp[ai].u.t, "default") == 0) {
+                curcursori = -1;
+                cursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+            } else {
+                Gerr (POS, G_ERRNOSUCHCURSOR, attrp[ai].u.t);
+                return -1;
+            }
+            SetCursor (cursor);
+            break;
+        case G_ATTRCOLOR:
+            color = attrp[ai].u.c.index;
+            if (color < 0 || color > G_MAXCOLORS) {
+                Gerr (POS, G_ERRBADCOLORINDEX, color);
+                return -1;
+            }
+            WCU->colors[color].color.peRed = attrp[ai].u.c.r;
+            WCU->colors[color].color.peGreen = attrp[ai].u.c.g;
+            WCU->colors[color].color.peBlue = attrp[ai].u.c.b;
+            WCU->colors[color].color.peFlags = 0;
+            if (color >= WCU->ncolor)
+                ResizePalette (WCU->cmap, color + 1), WCU->ncolor = color + 1;
+            SetPaletteEntries (
+                WCU->cmap, (int) color, 1, &WCU->colors[color].color
+            );
+            RealizePalette (GC);
+            WCU->colors[color].inuse = TRUE;
+            if (color == WCU->gattr.color)
+                WCU->gattr.color = -1;
+            break;
+        case G_ATTRVIEWPORT:
+            if (attrp[ai].u.s.x == 0)
+                attrp[ai].u.s.x = 1;
+            if (attrp[ai].u.s.y == 0)
+                attrp[ai].u.s.y = 1;
+            WCU->vsize.x = (int) (attrp[ai].u.s.x + 0.5);
+            WCU->vsize.y = (int) (attrp[ai].u.s.y + 0.5);
+            ps.x = WCU->vsize.x, ps.y = WCU->vsize.y;
+            Gadjustwrect (&Gwidgets[widget->pwi], &ps);
+            SetWindowPos (
+                widget->w, (HWND) NULL, 0, 0, ps.x,
+                ps.y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE
+            );
+            Gadjustclip (widget);
+            break;
+        case G_ATTRWINDOW:
+            if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)
+                attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;
+            if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)
+                attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;
+            WCU->wrect = attrp[ai].u.r;
+            Gadjustclip (widget);
+            break;
+        case G_ATTRWINDOWID:
+            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
+            return -1;
+        case G_ATTREVENTCB:
+            WCU->func = 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;
+        }
     }
     return 0;
 }
 
-int GCgetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp)
-{
+int GCgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
     PALETTEENTRY *cp;
     RECT r;
     int color, ai;
 
     for (ai = 0; ai < attrn; ai++) {
-       switch (attrp[ai].id) {
-       case G_ATTRSIZE:
-           GetWindowRect(widget->w, &r);
-           attrp[ai].u.s.x = r.right - r.left;
-           attrp[ai].u.s.y = r.bottom - r.top;
-           break;
-       case G_ATTRBORDERWIDTH:
-           Gerr(POS, G_ERRCANNOTGETATTR, "borderwidth");
-           return -1;
-       case G_ATTRCURSOR:
-           attrp[ai].u.t = (curcursori == -1) ? "default" : "watch";
-           break;
-       case G_ATTRCOLOR:
-           color = attrp[ai].u.c.index;
-           if (color < 0 || color > G_MAXCOLORS) {
-               Gerr(POS, G_ERRBADCOLORINDEX, color);
-               return -1;
-           }
-           if (WCU->colors[color].inuse) {
-               cp = &WCU->colors[color].color;
-               attrp[ai].u.c.r = cp->peRed;
-               attrp[ai].u.c.g = cp->peGreen;
-               attrp[ai].u.c.b = cp->peBlue;
-           } else {
-               attrp[ai].u.c.r = -1;
-               attrp[ai].u.c.g = -1;
-               attrp[ai].u.c.b = -1;
-           }
-           break;
-       case G_ATTRVIEWPORT:
-           attrp[ai].u.s = WCU->vsize;
-           break;
-       case G_ATTRWINDOW:
-           attrp[ai].u.r = WCU->wrect;
-           break;
-       case G_ATTRWINDOWID:
-           sprintf(&Gbufp[0], "0x%lx", widget->w);
-           attrp[ai].u.t = &Gbufp[0];
-           break;
-       case G_ATTREVENTCB:
-           attrp[ai].u.func = WCU->func;
-           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_ATTRSIZE:
+            GetWindowRect (widget->w, &r);
+            attrp[ai].u.s.x = r.right - r.left;
+            attrp[ai].u.s.y = r.bottom - r.top;
+            break;
+        case G_ATTRBORDERWIDTH:
+            Gerr (POS, G_ERRCANNOTGETATTR, "borderwidth");
+            return -1;
+        case G_ATTRCURSOR:
+            attrp[ai].u.t = (curcursori == -1) ? "default" : "watch";
+            break;
+        case G_ATTRCOLOR:
+            color = attrp[ai].u.c.index;
+            if (color < 0 || color > G_MAXCOLORS) {
+                Gerr (POS, G_ERRBADCOLORINDEX, color);
+                return -1;
+            }
+            if (WCU->colors[color].inuse) {
+                cp = &WCU->colors[color].color;
+                attrp[ai].u.c.r = cp->peRed;
+                attrp[ai].u.c.g = cp->peGreen;
+                attrp[ai].u.c.b = cp->peBlue;
+            } else {
+                attrp[ai].u.c.r = -1;
+                attrp[ai].u.c.g = -1;
+                attrp[ai].u.c.b = -1;
+            }
+            break;
+        case G_ATTRVIEWPORT:
+            attrp[ai].u.s = WCU->vsize;
+            break;
+        case G_ATTRWINDOW:
+            attrp[ai].u.r = WCU->wrect;
+            break;
+        case G_ATTRWINDOWID:
+            sprintf (&Gbufp[0], "0x%lx", widget->w);
+            attrp[ai].u.t = &Gbufp[0];
+            break;
+        case G_ATTREVENTCB:
+            attrp[ai].u.func = WCU->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 GCdestroywidget(Gwidget_t * widget)
-{
+int GCdestroywidget (Gwidget_t *widget) {
     Gwidget_t *parent;
 
     parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
     if (parent && parent->type == G_ARRAYWIDGET)
-       Gawdeletechild(parent, widget);
-    DestroyWindow(widget->w);
+        Gawdeletechild (parent, widget);
+    DestroyWindow (widget->w);
     return 0;
 }
 
-int GCcanvasclear(Gwidget_t * widget)
-{
+int GCcanvasclear (Gwidget_t *widget) {
     Ggattr_t attr;
     RECT r;
     HBRUSH brush, pbrush;
 
     attr.flags = 0;
-    setgattr(widget, &attr);
-    brush = CreateSolidBrush(PALETTEINDEX(0));
-    pbrush = SelectObject(GC, brush);
-    GetClientRect(widget->w, &r);
-    Rectangle(GC, r.left, r.top, r.right, r.bottom);
-    SelectObject(GC, pbrush);
-    DeleteObject(brush);
+    setgattr (widget, &attr);
+    brush = CreateSolidBrush (PALETTEINDEX (0));
+    pbrush = SelectObject (GC, brush);
+    GetClientRect (widget->w, &r);
+    Rectangle (GC, r.left, r.top, r.right, r.bottom);
+    SelectObject (GC, pbrush);
+    DeleteObject (brush);
     WCU->needredraw = FALSE;
     return 0;
 }
 
-int GCsetgfxattr(Gwidget_t * widget, Ggattr_t * ap)
-{
-    setgattr(widget, ap);
+int GCsetgfxattr (Gwidget_t *widget, Ggattr_t *ap) {
+    setgattr (widget, ap);
     WCU->defgattr = WCU->gattr;
     return 0;
 }
 
-int GCgetgfxattr(Gwidget_t * widget, Ggattr_t * ap)
-{
+int GCgetgfxattr (Gwidget_t *widget, Ggattr_t *ap) {
     if ((ap->flags & G_GATTRCOLOR))
-       ap->color = WCU->gattr.color;
+        ap->color = WCU->gattr.color;
     if ((ap->flags & G_GATTRWIDTH))
-       ap->width = WCU->gattr.width;
+        ap->width = WCU->gattr.width;
     if ((ap->flags & G_GATTRMODE))
-       ap->mode = WCU->gattr.mode;
+        ap->mode = WCU->gattr.mode;
     if ((ap->flags & G_GATTRFILL))
-       ap->fill = WCU->gattr.fill;
+        ap->fill = WCU->gattr.fill;
     if ((ap->flags & G_GATTRSTYLE))
-       ap->style = WCU->gattr.style;
+        ap->style = WCU->gattr.style;
     return 0;
 }
 
-int GCarrow(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap)
-{
+int GCarrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {
     PIXpoint_t pp1, pp2, pa, pb, pd;
     Grect_t gr;
     double tangent, l;
 
     if (gp1.x < gp2.x)
-       gr.o.x = gp1.x, gr.c.x = gp2.x;
+        gr.o.x = gp1.x, gr.c.x = gp2.x;
     else
-       gr.o.x = gp2.x, gr.c.x = gp1.x;
+        gr.o.x = gp2.x, gr.c.x = gp1.x;
     if (gp1.y < gp2.y)
-       gr.o.y = gp1.y, gr.c.y = gp2.y;
+        gr.o.y = gp1.y, gr.c.y = gp2.y;
     else
-       gr.o.y = gp2.y, gr.c.y = gp1.y;
-    if (!ISVISIBLE(gr))
-       return 1;
-    pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2);
+        gr.o.y = gp2.y, gr.c.y = gp1.y;
+    if (!ISVISIBLE (gr))
+        return 1;
+    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);
-    MoveToEx(GC, pp1.x, pp1.y, NULL), LineTo(GC, pp2.x, pp2.y);
-    MoveToEx(GC, pa.x, pa.y, NULL), LineTo(GC, pp2.x, pp2.y);
-    MoveToEx(GC, pb.x, pb.y, NULL), LineTo(GC, pp2.x, pp2.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);
+    MoveToEx (GC, pp1.x, pp1.y, NULL), LineTo (GC, pp2.x, pp2.y);
+    MoveToEx (GC, pa.x, pa.y, NULL), LineTo (GC, pp2.x, pp2.y);
+    MoveToEx (GC, pb.x, pb.y, NULL), LineTo (GC, pp2.x, pp2.y);
     return 0;
 }
 
-int GCline(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap)
-{
+int GCline (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {
     PIXpoint_t pp1, pp2;
     Grect_t gr;
 
     if (gp1.x < gp2.x)
-       gr.o.x = gp1.x, gr.c.x = gp2.x;
+        gr.o.x = gp1.x, gr.c.x = gp2.x;
     else
-       gr.o.x = gp2.x, gr.c.x = gp1.x;
+        gr.o.x = gp2.x, gr.c.x = gp1.x;
     if (gp1.y < gp2.y)
-       gr.o.y = gp1.y, gr.c.y = gp2.y;
+        gr.o.y = gp1.y, gr.c.y = gp2.y;
     else
-       gr.o.y = gp2.y, gr.c.y = gp1.y;
-    if (!ISVISIBLE(gr))
-       return 1;
-    pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2);
-    setgattr(widget, ap);
-    MoveToEx(GC, pp1.x, pp1.y, NULL);
-    LineTo(GC, pp2.x, pp2.y);
+        gr.o.y = gp2.y, gr.c.y = gp1.y;
+    if (!ISVISIBLE (gr))
+        return 1;
+    pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2);
+    setgattr (widget, ap);
+    MoveToEx (GC, pp1.x, pp1.y, NULL);
+    LineTo (GC, pp2.x, pp2.y);
     return 0;
 }
 
-int GCbox(Gwidget_t * widget, Grect_t gr, Ggattr_t * ap)
-{
+int GCbox (Gwidget_t *widget, Grect_t gr, Ggattr_t *ap) {
     PIXrect_t pr;
     Grect_t gr2;
 
     if (gr.o.x <= gr.c.x)
-       gr2.o.x = gr.o.x, gr2.c.x = gr.c.x;
+        gr2.o.x = gr.o.x, gr2.c.x = gr.c.x;
     else
-       gr2.o.x = gr.c.x, gr2.c.x = gr.o.x;
+        gr2.o.x = gr.c.x, gr2.c.x = gr.o.x;
     if (gr.o.y <= gr.c.y)
-       gr2.o.y = gr.o.y, gr2.c.y = gr.c.y;
+        gr2.o.y = gr.o.y, gr2.c.y = gr.c.y;
     else
-       gr2.o.y = gr.c.y, gr2.c.y = gr.o.y;
-    if (!ISVISIBLE(gr2))
-       return 1;
-    pr = rdrawtopix(widget, gr);
-    setgattr(widget, ap);
+        gr2.o.y = gr.c.y, gr2.c.y = gr.o.y;
+    if (!ISVISIBLE (gr2))
+        return 1;
+    pr = rdrawtopix (widget, gr);
+    setgattr (widget, ap);
     if (WCU->gattr.fill)
-       Rectangle(GC, pr.o.x, pr.o.y, pr.c.x, pr.c.y);
+        Rectangle (GC, pr.o.x, pr.o.y, pr.c.x, pr.c.y);
     else {
-       Gppp[0].x = pr.o.x, Gppp[0].y = pr.o.y;
-       Gppp[1].x = pr.c.x, Gppp[1].y = pr.o.y;
-       Gppp[2].x = pr.c.x, Gppp[2].y = pr.c.y;
-       Gppp[3].x = pr.o.x, Gppp[3].y = pr.c.y;
-       Gppp[4].x = pr.o.x, Gppp[4].y = pr.o.y;
-       Polyline(GC, Gppp, 5);
+        Gppp[0].x = pr.o.x, Gppp[0].y = pr.o.y;
+        Gppp[1].x = pr.c.x, Gppp[1].y = pr.o.y;
+        Gppp[2].x = pr.c.x, Gppp[2].y = pr.c.y;
+        Gppp[3].x = pr.o.x, Gppp[3].y = pr.c.y;
+        Gppp[4].x = pr.o.x, Gppp[4].y = pr.o.y;
+        Polyline (GC, Gppp, 5);
     }
     return 0;
 }
 
-int GCpolygon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap)
-{
+int GCpolygon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {
     Grect_t gr;
     int n, i;
 
     if (gpn == 0)
-       return 0;
+        return 0;
     gr.o = gpp[0], gr.c = gpp[0];
     for (i = 1; i < gpn; i++) {
-       gr.o.x = min(gr.o.x, gpp[i].x);
-       gr.o.y = min(gr.o.y, gpp[i].y);
-       gr.c.x = max(gr.c.x, gpp[i].x);
-       gr.c.y = max(gr.c.y, gpp[i].y);
+        gr.o.x = min (gr.o.x, gpp[i].x);
+        gr.o.y = min (gr.o.y, gpp[i].y);
+        gr.c.x = max (gr.c.x, gpp[i].x);
+        gr.c.y = max (gr.c.y, gpp[i].y);
     }
-    if (!ISVISIBLE(gr))
-       return 1;
+    if (!ISVISIBLE (gr))
+        return 1;
     if (gpn + 1 > Gppn) {
-       n = (((gpn + 1) + PPINCR - 1) / PPINCR) * PPINCR;
-       Gppp = Marraygrow(Gppp, (long) n * PPSIZE);
-       Gppn = n;
+        n = (((gpn + 1) + PPINCR - 1) / PPINCR) * PPINCR;
+        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);
+        Gppn = n;
     }
     for (i = 0; i < gpn; i++)
-       Gppp[i] = pdrawtopix(widget, gpp[i]);
-    setgattr(widget, ap);
+        Gppp[i] = pdrawtopix (widget, gpp[i]);
+    setgattr (widget, ap);
     if (WCU->gattr.fill) {
-       if (Gppp[gpn - 1].x != Gppp[0].x || Gppp[gpn - 1].y != Gppp[0].y)
-           Gppp[gpn] = Gppp[0], gpn++;
-       Polygon(GC, Gppp, (int) gpn);
+        if (Gppp[gpn - 1].x != Gppp[0].x || Gppp[gpn - 1].y != Gppp[0].y)
+            Gppp[gpn] = Gppp[0], gpn++;
+        Polygon (GC, Gppp, (int) gpn);
     } else
-       Polyline(GC, Gppp, (int) gpn);
+        Polyline (GC, Gppp, (int) gpn);
     return 0;
 }
 
-int GCsplinegon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap)
-{
+int GCsplinegon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {
     PIXpoint_t p0, p1, p2, p3;
     Grect_t gr;
     int n, i;
 
     if (gpn == 0)
-       return 0;
+        return 0;
     gr.o = gpp[0], gr.c = gpp[0];
     for (i = 1; i < gpn; i++) {
-       gr.o.x = min(gr.o.x, gpp[i].x);
-       gr.o.y = min(gr.o.y, gpp[i].y);
-       gr.c.x = max(gr.c.x, gpp[i].x);
-       gr.c.y = max(gr.c.y, gpp[i].y);
+        gr.o.x = min (gr.o.x, gpp[i].x);
+        gr.o.y = min (gr.o.y, gpp[i].y);
+        gr.c.x = max (gr.c.x, gpp[i].x);
+        gr.c.y = max (gr.c.y, gpp[i].y);
     }
-    if (!ISVISIBLE(gr))
-       return 1;
+    if (!ISVISIBLE (gr))
+        return 1;
     Gppi = 1;
     if (Gppi >= Gppn) {
-       n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
-       Gppp = Marraygrow(Gppp, (long) n * PPSIZE);
-       Gppn = n;
+        n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
+        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);
+        Gppn = n;
     }
-    Gppp[0] = p3 = pdrawtopix(widget, gpp[0]);
+    Gppp[0] = p3 = pdrawtopix (widget, gpp[0]);
     for (i = 1; i < gpn; i += 3) {
-       p0 = p3;
-       p1 = pdrawtopix(widget, gpp[i]);
-       p2 = pdrawtopix(widget, gpp[i + 1]);
-       p3 = pdrawtopix(widget, gpp[i + 2]);
-       bezier(p0, p1, p2, p3);
+        p0 = p3;
+        p1 = pdrawtopix (widget, gpp[i]);
+        p2 = pdrawtopix (widget, gpp[i + 1]);
+        p3 = pdrawtopix (widget, gpp[i + 2]);
+        bezier (p0, p1, p2, p3);
     }
-    setgattr(widget, ap);
+    setgattr (widget, ap);
     if (WCU->gattr.fill) {
-       if (Gppp[Gppi - 1].x != Gppp[0].x || Gppp[Gppi - 1].y != Gppp[0].y)
-           Gppp[Gppi] = Gppp[0], Gppi++;
-       Polygon(GC, Gppp, (int) Gppi);
+        if (Gppp[Gppi - 1].x != Gppp[0].x || Gppp[Gppi - 1].y != Gppp[0].y)
+            Gppp[Gppi] = Gppp[0], Gppi++;
+        Polygon (GC, Gppp, (int) Gppi);
     } else
-       Polyline(GC, Gppp, (int) Gppi);
+        Polyline (GC, Gppp, (int) Gppi);
     return 0;
 }
 
-static void bezier(PIXpoint_t p0, PIXpoint_t p1,
-                  PIXpoint_t p2, PIXpoint_t p3)
-{
+static void bezier (
+    PIXpoint_t p0, PIXpoint_t p1, PIXpoint_t p2, PIXpoint_t p3
+{
     Gpoint_t gp0, gp1, gp2;
     Gsize_t s;
     PIXpoint_t p;
@@ -622,39 +614,40 @@ static void bezier(PIXpoint_t p0, PIXpoint_t p1,
     int n, i, steps;
 
     if ((s.x = p3.x - p0.x) < 0)
-       s.x = -s.x;
+        s.x = - s.x;
     if ((s.y = p3.y - p0.y) < 0)
-       s.y = -s.y;
+        s.y = - s.y;
     if (s.x > s.y)
-       steps = s.x / 5 + 1;
+        steps = s.x / 5 + 1;
     else
-       steps = s.y / 5 + 1;
+        steps = s.y / 5 + 1;
     for (i = 0; i <= steps; i++) {
-       t = i / (double) steps;
-       gp0.x = p0.x + t * (p1.x - p0.x);
-       gp0.y = p0.y + t * (p1.y - p0.y);
-       gp1.x = p1.x + t * (p2.x - p1.x);
-       gp1.y = p1.y + t * (p2.y - p1.y);
-       gp2.x = p2.x + t * (p3.x - p2.x);
-       gp2.y = p2.y + t * (p3.y - p2.y);
-       gp0.x = gp0.x + t * (gp1.x - gp0.x);
-       gp0.y = gp0.y + t * (gp1.y - gp0.y);
-       gp1.x = gp1.x + t * (gp2.x - gp1.x);
-       gp1.y = gp1.y + t * (gp2.y - gp1.y);
-       p.x = gp0.x + t * (gp1.x - gp0.x) + 0.5;
-       p.y = gp0.y + t * (gp1.y - gp0.y) + 0.5;
-       if (Gppi >= Gppn) {
-           n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
-           Gppp = Marraygrow(Gppp, (long) n * PPSIZE);
-           Gppn = n;
-       }
-       Gppp[Gppi++] = p;
+        t = i / (double) steps;
+        gp0.x = p0.x + t * (p1.x - p0.x);
+        gp0.y = p0.y + t * (p1.y - p0.y);
+        gp1.x = p1.x + t * (p2.x - p1.x);
+        gp1.y = p1.y + t * (p2.y - p1.y);
+        gp2.x = p2.x + t * (p3.x - p2.x);
+        gp2.y = p2.y + t * (p3.y - p2.y);
+        gp0.x = gp0.x + t * (gp1.x - gp0.x);
+        gp0.y = gp0.y + t * (gp1.y - gp0.y);
+        gp1.x = gp1.x + t * (gp2.x - gp1.x);
+        gp1.y = gp1.y + t * (gp2.y - gp1.y);
+        p.x = gp0.x + t * (gp1.x - gp0.x) + 0.5;
+        p.y = gp0.y + t * (gp1.y - gp0.y) + 0.5;
+        if (Gppi >= Gppn) {
+            n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
+            Gppp = Marraygrow (Gppp, (long) n * PPSIZE);
+            Gppn = n;
+        }
+        Gppp[Gppi++] = p;
     }
 }
 
-int GCarc(Gwidget_t * widget, Gpoint_t gc, Gsize_t gs, double ang1,
-         double ang2, Ggattr_t * ap)
-{
+int GCarc (
+    Gwidget_t *widget, Gpoint_t gc, Gsize_t gs, double ang1,
+    double ang2, Ggattr_t *ap
+) {
     PIXpoint_t pc;
     PIXsize_t ps;
     Grect_t gr;
@@ -662,98 +655,93 @@ int GCarc(Gwidget_t * widget, Gpoint_t gc, Gsize_t gs, double ang1,
 
     gr.o.x = gc.x - gs.x, gr.o.y = gc.y - gs.y;
     gr.c.x = gc.x + gs.x, gr.c.y = gc.y + gs.y;
-    if (!ISVISIBLE(gr))
-       return 1;
-    pc = pdrawtopix(widget, gc), ps = sdrawtopix(widget, gs);
-    setgattr(widget, ap);
+    if (!ISVISIBLE (gr))
+        return 1;
+    pc = pdrawtopix (widget, gc), ps = sdrawtopix (widget, gs);
+    setgattr (widget, ap);
     a1 = ang1 * M_PI / 180, a2 = ang2 * M_PI / 180;
     if (WCU->gattr.fill)
-       Chord(GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
-             (int) (cos(a1) * ps.x), (int) (sin(a1) * ps.x),
-             (int) (cos(a2) * ps.x), (int) (sin(a2) * ps.x));
+        Chord (
+            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
+            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),
+            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)
+        );
     else
-       Arc(GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
-           (int) (cos(a1) * ps.x), (int) (sin(a1) * ps.x),
-           (int) (cos(a2) * ps.x), (int) (sin(a2) * ps.x));
+        Arc (
+            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
+            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),
+            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)
+        );
     return 0;
 }
 
 #define YSCALE ((WCU->vsize.y) / (WCU->wrect.c.y - WCU->wrect.o.y))
 
-int GCtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go,
-          char *fn, double fs, char *justs, Ggattr_t * ap)
-{
+int GCtext (
+    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;
     PIXrect_t pr;
     Grect_t gr;
     HFONT font;
+    TEXTMETRIC tm;
     SIZE size;
     RECT r;
     int x, y, w, h, i;
 
-    po = pdrawtopix(widget, go);
+    po = pdrawtopix (widget, go);
     gs.x = 0, gs.y = fs;
-    ps = sdrawtopix(widget, gs);
-    if (!(font = findfont(fn, ps.y))) {
-       Rectangle(GC, po.x, po.y, po.x + 1, po.y + 1);
-       return 0;
+    ps = sdrawtopix (widget, gs);
+    if (!(font = findfont (fn, ps.y))) {
+        Rectangle (GC, po.x, po.y, po.x + 1, po.y + 1);
+        return 0;
     }
-    setgattr(widget, ap);
-    SETFONT(font);
+    setgattr (widget, ap);
+    SETFONT (font);
+    GetTextMetrics (GC, &tm);
     for (w = h = 0, i = 0; i < n; i++) {
-       if (tlp[i].n)
-           GetTextExtentPoint32(GC, tlp[i].p, (int) tlp[i].n, &size);
-       else
-           GetTextExtentPoint32(GC, "M", (int) 1, &size);
-       tlp[i].w = size.cx, tlp[i].h = size.cy;
-       w = max(w, size.cx), h += size.cy;
+        if (tlp[i].n)
+            GetTextExtentPoint32 (GC, tlp[i].p, (int) tlp[i].n, &size);
+        else
+            GetTextExtentPoint32 (GC, "M", (int) 1, &size);
+        tlp[i].w = size.cx, tlp[i].h = size.cy;
+        w = max (w, size.cx), h += size.cy;
     }
     switch (justs[0]) {
-    case 'l':
-       po.x += w / 2;
-       break;
-    case 'r':
-       po.x -= w / 2;
-       break;
+    case 'l': po.x += w / 2; break;
+    case 'r': po.x -= w / 2; break;
     }
     switch (justs[1]) {
-    case 'd':
-       po.y -= h;
-       break;
-    case 'c':
-       po.y -= h / 2;
-       break;
+    case 'd': po.y -= h; break;
+    case 'b': po.y -= (h - tm.tmDescent); break;
+    case 'c': po.y -= h / 2; break;
     }
     pr.o.x = po.x - w / 2, pr.o.y = po.y;
     pr.c.x = po.x + w / 2, pr.c.y = po.y + h;
-    gr = rpixtodraw(widget, pr);
-    if (!ISVISIBLE(gr))
-       return 1;
+    gr = rpixtodraw (widget, pr);
+    if (!ISVISIBLE (gr))
+        return 1;
     for (i = 0; i < n; i++) {
-       switch (tlp[i].j) {
-       case 'l':
-           x = po.x - w / 2;
-           break;
-       case 'n':
-           x = po.x - tlp[i].w / 2;
-           break;
-       case 'r':
-           x = po.x - (tlp[i].w - w / 2);
-           break;
-       }
-       y = po.y + i * tlp[i].h;
-       r.left = x, r.top = y;
-       r.right = x + tlp[i].w, r.bottom = y + tlp[i].h;
-       DrawText(GC, tlp[i].p, (int) tlp[i].n, &r, DT_LEFT | DT_TOP);
+        switch (tlp[i].j) {
+        case 'l': x = po.x - w / 2; break;
+        case 'n': x = po.x - tlp[i].w / 2; break;
+        case 'r': x = po.x - (tlp[i].w - w / 2); break;
+        }
+        y = po.y + i * tlp[i].h;
+        r.left = x, r.top = y;
+        r.right = x + tlp[i].w, r.bottom = y + tlp[i].h;
+        DrawText (GC, tlp[i].p, (int) tlp[i].n, &r, DT_LEFT | DT_TOP);
     }
     return 0;
 }
 
-int GCgettextsize(Gwidget_t * widget, Gtextline_t * tlp, int n, char *fn,
-                 double fs, Gsize_t * gsp)
-{
+int GCgettextsize (
+    Gwidget_t *widget, Gtextline_t *tlp, int n, char *fn,
+    double fs, Gsize_t *gsp
+) {
     Gsize_t gs;
     PIXsize_t ps;
     HFONT font;
@@ -761,60 +749,59 @@ int GCgettextsize(Gwidget_t * widget, Gtextline_t * tlp, int n, char *fn,
     SIZE size;
 
     gs.x = 0, gs.y = fs;
-    ps = sdrawtopix(widget, gs);
-    if (!(font = findfont(fn, ps.y))) {
-       gsp->x = 1, gsp->y = 1;
-       return 0;
+    ps = sdrawtopix (widget, gs);
+    if (!(font = findfont (fn, ps.y))) {
+        gsp->x = 1, gsp->y = 1;
+        return 0;
     }
-    SETFONT(font);
+    SETFONT (font);
     for (ps.x = ps.y = 0, i = 0; i < n; i++) {
-       GetTextExtentPoint32(GC, tlp[i].p, (int) tlp[i].n, &size);
-       ps.x = max(ps.x, size.cx), ps.y += size.cy;
+        GetTextExtentPoint32 (GC, tlp[i].p, (int) tlp[i].n, &size);
+        ps.x = max (ps.x, size.cx), ps.y += size.cy;
     }
-    *gsp = spixtodraw(widget, ps);
+    *gsp = spixtodraw (widget, ps);
     return 0;
 }
 
-static HFONT findfont(char *name, int size)
-{
+static HFONT findfont (char *name, int size) {
     HFONT font;
     int fi;
 
     if (name[0] == '\000')
-       return Gfontp[0].font;
+        return Gfontp[0].font;
 
-    sprintf(&Gbufp[0], name, size);
+    sprintf (&Gbufp[0], name, size);
     for (fi = 0; fi < Gfontn; fi++)
-       if (Strcmp(&Gbufp[0], Gfontp[fi].name) == 0
-           && Gfontp[fi].size == size)
-           return Gfontp[fi].font;
-    font = CreateFont((int) size,
-                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &Gbufp[0]);
+        if (strcmp (&Gbufp[0], Gfontp[fi].name) == 0 && Gfontp[fi].size == size)
+            return Gfontp[fi].font;
+    font = CreateFont (
+        (int) size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &Gbufp[0]
+    );
     if (!font)
-       font = Gfontp[0].font;
+        font = Gfontp[0].font;
 
-    Gfontp = Marraygrow(Gfontp, (long) (Gfontn + 1) * FONTSIZE);
-    Gfontp[Gfontn].name = strdup(&Gbufp[0]);
+    Gfontp = Marraygrow (Gfontp, (long) (Gfontn + 1) * FONTSIZE);
+    Gfontp[Gfontn].name = strdup (&Gbufp[0]);
     Gfontp[Gfontn].size = size;
     Gfontp[Gfontn].font = font;
     Gfontn++;
     return font;
 }
 
-int GCcreatebitmap(Gwidget_t * widget, Gbitmap_t * bitmap, Gsize_t s)
-{
+int GCcreatebitmap (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;
     }
-    if (!(bitmap->u.bmap.orig = CreateBitmap((int) s.x, (int) s.y, 1,
-                                            Gdepth, NULL))) {
-       Gerr(POS, G_ERRCANNOTCREATEBITMAP);
-       return -1;
+    if (!(bitmap->u.bmap.orig = CreateBitmap (
+        (int) s.x, (int) s.y, 1, Gdepth, NULL
+    ))) {
+        Gerr (POS, G_ERRCANNOTCREATEBITMAP);
+        return -1;
     }
     bitmap->u.bmap.scaled = 0;
     bitmap->scale.x = bitmap->scale.y = 1;
@@ -824,20 +811,18 @@ int GCcreatebitmap(Gwidget_t * widget, Gbitmap_t * bitmap, Gsize_t s)
     return 0;
 }
 
-int GCdestroybitmap(Gbitmap_t * bitmap)
-{
+int GCdestroybitmap (Gbitmap_t *bitmap) {
     if (!bitmap) {
-       Gerr(POS, G_ERRNOBITMAP);
-       return -1;
+        Gerr (POS, G_ERRNOBITMAP);
+        return -1;
     }
-    DeleteObject(bitmap->u.bmap.orig);
+    DeleteObject (bitmap->u.bmap.orig);
     if (bitmap->u.bmap.scaled)
-       DeleteObject(bitmap->u.bmap.scaled);
+        DeleteObject (bitmap->u.bmap.scaled);
     return 0;
 }
 
-int GCreadbitmap(Gwidget_t * widget, Gbitmap_t * bitmap, FILE * fp)
-{
+int GCreadbitmap (Gwidget_t *widget, Gbitmap_t *bitmap, FILE *fp) {
     Gsize_t s;
     HDC gc;
     char bufp[2048];
@@ -847,60 +832,64 @@ int GCreadbitmap(Gwidget_t * widget, Gbitmap_t * bitmap, FILE * fp)
     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;
+        }
     }
-    if (!(bitmap->u.bmap.orig = CreateBitmap((int) s.x, (int) s.y, 1,
-                                            Gdepth, NULL))) {
-       Gerr(POS, G_ERRCANNOTCREATEBITMAP);
-       return -1;
+    if (!(bitmap->u.bmap.orig = CreateBitmap (
+        (int) s.x, (int) s.y, 1, Gdepth, NULL
+    ))) {
+        Gerr (POS, G_ERRCANNOTCREATEBITMAP);
+        return -1;
     }
-    gc = CreateCompatibleDC(GC);
-    SelectObject(gc, bitmap->u.bmap.orig);
+    gc = CreateCompatibleDC (GC);
+    SelectObject (gc, bitmap->u.bmap.orig);
     bitmap->u.bmap.scaled = 0;
     bitmap->scale.x = bitmap->scale.y = 1;
     bitmap->ctype = widget->type;
@@ -909,30 +898,29 @@ int GCreadbitmap(Gwidget_t * widget, Gbitmap_t * bitmap, FILE * fp)
     bufi = bufn = 0;
     bufp[bufi] = 0;
     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) {
-                       if (ferror(fp))
-                           bufn = -1;
-                       DeleteDC(gc);
-                       DeleteObject(bitmap->u.bmap.orig);
-                       Gerr(POS, G_ERRCANNOTCREATEBITMAP);
-                       return -1;
-                   }
-                   bufi = 0;
-               }
-               rgb[k] = (unsigned char) bufp[bufi++];
-           }
-           SetPixel(gc, x, y, RGB(rgb[0], rgb[1], rgb[2]));
-       }
+        for (x = 0; x < s.x; x++) {
+            for (k = 0; k < 3; k++) {
+                if (bufi == bufn) {
+                    if ((bufn = fread (bufp, 1, 2047, fp)) == 0) {
+                        if (ferror (fp))
+                            bufn = -1;
+                        DeleteDC (gc);
+                        DeleteObject (bitmap->u.bmap.orig);
+                        Gerr (POS, G_ERRCANNOTCREATEBITMAP);
+                        return -1;
+                    }
+                    bufi = 0;
+                }
+                rgb[k] = (unsigned char) bufp[bufi++];
+            }
+            SetPixel (gc, x, y, RGB (rgb[0], rgb[1], rgb[2]));
+        }
     }
-    DeleteDC(gc);
+    DeleteDC (gc);
     return 0;
 }
 
-int GCwritebitmap(Gbitmap_t * bitmap, FILE * fp)
-{
+int GCwritebitmap (Gbitmap_t *bitmap, FILE *fp) {
     Gwidget_t *widget;
     HDC gc;
     COLORREF color;
@@ -940,47 +928,49 @@ int GCwritebitmap(Gbitmap_t * bitmap, FILE * fp)
     int bufi, x, y, w, h;
 
     if (!bitmap) {
-       Gerr(POS, G_ERRNOBITMAP);
-       return -1;
+        Gerr (POS, G_ERRNOBITMAP);
+        return -1;
     }
-    if (bitmap->canvas < 0 || bitmap->canvas >= Gwidgetn ||
-       !Gwidgets[bitmap->canvas].inuse) {
-       Gerr(POS, G_ERRBADWIDGETID, bitmap->canvas);
-       return -1;
+    if (
+        bitmap->canvas < 0 || bitmap->canvas >= Gwidgetn ||
+        !Gwidgets[bitmap->canvas].inuse
+    ) {
+        Gerr (POS, G_ERRBADWIDGETID, bitmap->canvas);
+        return -1;
     }
     widget = &Gwidgets[bitmap->canvas];
     if (widget->type != G_CANVASWIDGET && widget->type != G_PCANVASWIDGET) {
-       Gerr(POS, G_ERRNOTACANVAS, bitmap->canvas);
-       return -1;
+        Gerr (POS, G_ERRNOTACANVAS, bitmap->canvas);
+        return -1;
     }
-    gc = CreateCompatibleDC(GC);
-    SelectObject(gc, bitmap->u.bmap.orig);
-    fprintf(fp, "P6\n%d %d 255\n", (int) bitmap->size.x,
-           (int) bitmap->size.y);
+    gc = CreateCompatibleDC (GC);
+    SelectObject (gc, bitmap->u.bmap.orig);
+    fprintf (fp, "P6\n%d %d 255\n", (int) bitmap->size.x, (int) bitmap->size.y);
     bufi = 0;
     w = bitmap->size.x;
     h = bitmap->size.y;
     for (y = 0; y < h; y++) {
-       for (x = 0; x < w; x++) {
-           color = GetPixel(gc, x, y);
-           bufp[bufi++] = GetRValue(color);
-           bufp[bufi++] = GetGValue(color);
-           bufp[bufi++] = GetBValue(color);
-           if (bufi + 3 >= 2048) {
-               fwrite(bufp, 1, bufi, fp);
-               bufi = 0;
-           }
-       }
+        for (x = 0; x < w; x++) {
+            color = GetPixel (gc, x, y);
+            bufp[bufi++] = GetRValue (color);
+            bufp[bufi++] = GetGValue (color);
+            bufp[bufi++] = GetBValue (color);
+            if (bufi + 3 >= 2048) {
+                fwrite (bufp, 1, bufi, fp);
+                bufi = 0;
+            }
+        }
     }
     if (bufi > 0)
-       fwrite(bufp, 1, bufi, fp);
-    DeleteDC(gc);
+        fwrite (bufp, 1, bufi, fp);
+    DeleteDC (gc);
     return 0;
 }
 
-int GCbitblt(Gwidget_t * widget, Gpoint_t gp, Grect_t gr,
-            Gbitmap_t * bitmap, char *mode, Ggattr_t * ap)
-{
+int GCbitblt (
+    Gwidget_t *widget, Gpoint_t gp, Grect_t gr, Gbitmap_t *bitmap,
+    char *mode, Ggattr_t *ap
+) {
     PIXrect_t pr, r;
     PIXpoint_t pp;
     PIXsize_t s;
@@ -991,100 +981,103 @@ int GCbitblt(Gwidget_t * widget, Gpoint_t gp, Grect_t gr,
     double tvx, tvy, twx, twy;
 
     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;
-    if (strcmp(mode, "b2c") == 0) {
-       if (!ISVISIBLE(gr))
-           return 1;
-       tvx = WCU->vsize.x, tvy = WCU->vsize.y;
-       twx = WCU->wrect.c.x - WCU->wrect.o.x;
-       twy = WCU->wrect.c.y - WCU->wrect.o.y;
-       scale.x = tvx / twx, scale.y = tvy / twy;
-       if (scale.x == 1 && scale.y == 1)
-           pix = bitmap->u.bmap.orig;
-       else {
-           if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
-               scalebitmap(widget, bitmap, scale, TRUE, 1);
-           pix = bitmap->u.bmap.scaled;
-       }
-       pr = rdrawtopix(widget, gr);
-       pp = pdrawtobpix(bitmap, gp);
-       s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
-       r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
-       r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
-       if (r.o.x < 0)
-           pr.o.x -= r.o.x, r.o.x = 0;
-       if (r.o.y < 0)
-           pr.o.y -= r.o.y, r.o.y = 0;
-       if (r.c.x >= bitmap->size.x * scale.x) {
-           pr.c.x -= (r.c.x + 1 - bitmap->size.x * scale.x);
-           r.c.x = bitmap->size.x * scale.x - 1;
-       }
-       if (r.c.y >= bitmap->size.y * scale.y) {
-           pr.c.y -= (r.c.y + 1 - bitmap->size.y * scale.y);
-           r.c.y = bitmap->size.y * scale.y - 1;
-       }
-       if (pr.o.x < 0)
-           r.o.x -= pr.o.x, pr.o.x = 0;
-       if (pr.o.y < 0)
-           r.o.y -= pr.o.y, pr.o.y = 0;
-       setgattr(widget, ap);
-       gc = CreateCompatibleDC(GC);
-       SelectObject(gc, pix);
-       BitBlt(GC, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
-              gc, r.o.x, r.o.y, (WCU->gattr.mode == G_SRC) ?
-              SRCCOPY : SRCINVERT);
-       DeleteDC(gc);
-    } else if (strcmp(mode, "c2b") == 0) {
-       tvx = WCU->vsize.x, tvy = WCU->vsize.y;
-       twx = WCU->wrect.c.x - WCU->wrect.o.x;
-       twy = WCU->wrect.c.y - WCU->wrect.o.y;
-       scale.x = tvx / twx, scale.y = tvy / twy;
-       if (scale.x == 1 && scale.y == 1)
-           pix = bitmap->u.bmap.orig;
-       else {
-           if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
-               scalebitmap(widget, bitmap, scale, FALSE, 1);
-           pix = bitmap->u.bmap.scaled;
-       }
-       pr = rdrawtobpix(bitmap, gr);
-       pp = pdrawtopix(widget, gp);
-       s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
-       r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
-       r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
-       if (pr.o.x < 0)
-           r.o.x -= pr.o.x, pr.o.x = 0;
-       if (pr.o.y < 0)
-           r.o.y -= pr.o.y, pr.o.y = 0;
-       if (pr.c.x >= bitmap->size.x * scale.x) {
-           r.c.x -= (pr.c.x + 1 - bitmap->size.x * scale.x);
-           pr.c.x = bitmap->size.x * scale.x - 1;
-       }
-       if (pr.c.y >= bitmap->size.y * scale.y) {
-           r.c.y -= (pr.c.y + 1 - bitmap->size.y * scale.y);
-           pr.c.y = bitmap->size.y * scale.y - 1;
-       }
-       if (r.o.x < 0)
-           pr.o.x -= r.o.x, r.o.x = 0;
-       if (r.o.y < 0)
-           pr.o.y -= r.o.y, r.o.y = 0;
-       setgattr(widget, ap);
-       gc = CreateCompatibleDC(GC);
-       SelectObject(gc, pix);
-       BitBlt(gc, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
-              GC, r.o.x, r.o.y, (WCU->gattr.mode == G_SRC) ?
-              SRCCOPY : SRCINVERT);
-       if (pix != bitmap->u.bmap.orig)
-           scalebitmap(widget, bitmap, scale, TRUE, -1);
-       DeleteDC(gc);
+        p.y = gr.o.y, gr.o.y = gr.c.y, gr.c.y = p.y;
+    if (strcmp (mode, "b2c") == 0) {
+        if (!ISVISIBLE (gr))
+            return 1;
+        tvx = WCU->vsize.x, tvy = WCU->vsize.y;
+        twx = WCU->wrect.c.x - WCU->wrect.o.x;
+        twy = WCU->wrect.c.y - WCU->wrect.o.y;
+        scale.x = tvx / twx, scale.y = tvy / twy;
+        if (scale.x == 1 && scale.y == 1)
+            pix = bitmap->u.bmap.orig;
+        else {
+            if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
+                scalebitmap (widget, bitmap, scale, TRUE, 1);
+            pix = bitmap->u.bmap.scaled;
+        }
+        pr = rdrawtopix (widget, gr);
+        pp = pdrawtobpix (bitmap, gp);
+        s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
+        r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
+        r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
+        if (r.o.x < 0)
+            pr.o.x -= r.o.x, r.o.x = 0;
+        if (r.o.y < 0)
+            pr.o.y -= r.o.y, r.o.y = 0;
+        if (r.c.x >= bitmap->size.x * scale.x) {
+            pr.c.x -= (r.c.x + 1 - bitmap->size.x * scale.x);
+            r.c.x = bitmap->size.x * scale.x - 1;
+        }
+        if (r.c.y >= bitmap->size.y * scale.y) {
+            pr.c.y -= (r.c.y + 1 - bitmap->size.y * scale.y);
+            r.c.y = bitmap->size.y * scale.y - 1;
+        }
+        if (pr.o.x < 0)
+            r.o.x -= pr.o.x, pr.o.x = 0;
+        if (pr.o.y < 0)
+            r.o.y -= pr.o.y, pr.o.y = 0;
+        setgattr (widget, ap);
+        gc = CreateCompatibleDC (GC);
+        SelectObject (gc, pix);
+        BitBlt (
+            GC, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
+            gc, r.o.x, r.o.y, (WCU->gattr.mode == G_SRC) ? SRCCOPY : SRCINVERT
+        );
+        DeleteDC (gc);
+    } else if (strcmp (mode, "c2b") == 0) {
+        tvx = WCU->vsize.x, tvy = WCU->vsize.y;
+        twx = WCU->wrect.c.x - WCU->wrect.o.x;
+        twy = WCU->wrect.c.y - WCU->wrect.o.y;
+        scale.x = tvx / twx, scale.y = tvy / twy;
+        if (scale.x == 1 && scale.y == 1)
+            pix = bitmap->u.bmap.orig;
+        else {
+            if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
+                scalebitmap (widget, bitmap, scale, FALSE, 1);
+            pix = bitmap->u.bmap.scaled;
+        }
+        pr = rdrawtobpix (bitmap, gr);
+        pp = pdrawtopix (widget, gp);
+        s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
+        r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
+        r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
+        if (pr.o.x < 0)
+            r.o.x -= pr.o.x, pr.o.x = 0;
+        if (pr.o.y < 0)
+            r.o.y -= pr.o.y, pr.o.y = 0;
+        if (pr.c.x >= bitmap->size.x * scale.x) {
+            r.c.x -= (pr.c.x + 1 - bitmap->size.x * scale.x);
+            pr.c.x = bitmap->size.x * scale.x - 1;
+        }
+        if (pr.c.y >= bitmap->size.y * scale.y) {
+            r.c.y -= (pr.c.y + 1 - bitmap->size.y * scale.y);
+            pr.c.y = bitmap->size.y * scale.y - 1;
+        }
+        if (r.o.x < 0)
+            pr.o.x -= r.o.x, r.o.x = 0;
+        if (r.o.y < 0)
+            pr.o.y -= r.o.y, r.o.y = 0;
+        setgattr (widget, ap);
+        gc = CreateCompatibleDC (GC);
+        SelectObject (gc, pix);
+        BitBlt (
+            gc, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
+            GC, r.o.x, r.o.y, (WCU->gattr.mode == G_SRC) ? SRCCOPY : SRCINVERT
+        );
+        if (pix != bitmap->u.bmap.orig)
+            scalebitmap (widget, bitmap, scale, TRUE, -1);
+        DeleteDC (gc);
     }
     return 0;
 }
 
-static int scalebitmap(Gwidget_t * widget, Gbitmap_t * bitmap,
-                      Gsize_t scale, int copybits, int dir)
-{
+static int scalebitmap (
+    Gwidget_t *widget, Gbitmap_t *bitmap, Gsize_t scale,
+    int copybits, int dir
+) {
     Gsize_t nsize, o2n;
     HBITMAP opix, spix;
     COLORREF color;
@@ -1093,115 +1086,115 @@ static int scalebitmap(Gwidget_t * widget, Gbitmap_t * bitmap,
     double prod, rgb[3], xr2, yr2, xl2, yl2, xf2, yf2, xr, yr, xl, yl;
 
     if (!copybits) {
-       if (dir == 1) {
-           nsize.x = (int) (bitmap->size.x * scale.x);
-           nsize.y = (int) (bitmap->size.y * scale.y);
-           if (!(spix = CreateBitmap((int) nsize.x, (int) nsize.y, 1,
-                                     Gdepth, NULL))) {
-               Gerr(POS, G_ERRCANNOTCREATEBITMAP);
-               return -1;
-           }
-           if (bitmap->u.bmap.scaled)
-               DeleteObject(bitmap->u.bmap.scaled);
-           bitmap->u.bmap.scaled = spix;
-           bitmap->scale = scale;
-       }
-       return 0;
+        if (dir == 1) {
+            nsize.x = (int) (bitmap->size.x * scale.x);
+            nsize.y = (int) (bitmap->size.y * scale.y);
+            if (!(spix = CreateBitmap (
+                (int) nsize.x, (int) nsize.y, 1, Gdepth, NULL
+            ))) {
+                Gerr (POS, G_ERRCANNOTCREATEBITMAP);
+                return -1;
+            }
+            if (bitmap->u.bmap.scaled)
+                DeleteObject (bitmap->u.bmap.scaled);
+            bitmap->u.bmap.scaled = spix;
+            bitmap->scale = scale;
+        }
+        return 0;
     }
     if (dir == 1) {
-       nsize.x = (int) (bitmap->size.x * scale.x);
-       nsize.y = (int) (bitmap->size.y * scale.y);
-       o2n.x = 1 / scale.x, o2n.y = 1 / scale.y;
-       if (!(spix = CreateBitmap((int) nsize.x, (int) nsize.y, 1,
-                                 Gdepth, NULL))) {
-           Gerr(POS, G_ERRCANNOTCREATEBITMAP);
-           return -1;
-       }
-       opix = bitmap->u.bmap.orig;
+        nsize.x = (int) (bitmap->size.x * scale.x);
+        nsize.y = (int) (bitmap->size.y * scale.y);
+        o2n.x = 1 / scale.x, o2n.y = 1 / scale.y;
+        if (!(spix = CreateBitmap (
+            (int) nsize.x, (int) nsize.y, 1, Gdepth, NULL
+        ))) {
+            Gerr (POS, G_ERRCANNOTCREATEBITMAP);
+            return -1;
+        }
+        opix = bitmap->u.bmap.orig;
     } else {
-       nsize.x = (int) bitmap->size.x;
-       nsize.y = (int) bitmap->size.y;
-       o2n.x = scale.x, o2n.y = scale.y;
-       spix = bitmap->u.bmap.orig;
-       opix = bitmap->u.bmap.scaled;
+        nsize.x = (int) bitmap->size.x;
+        nsize.y = (int) bitmap->size.y;
+        o2n.x = scale.x, o2n.y = scale.y;
+        spix = bitmap->u.bmap.orig;
+        opix = bitmap->u.bmap.scaled;
     }
-    gc1 = CreateCompatibleDC(GC);
-    SelectObject(gc1, opix);
-    gc2 = CreateCompatibleDC(GC);
-    SelectObject(gc2, spix);
+    gc1 = CreateCompatibleDC (GC);
+    SelectObject (gc1, opix);
+    gc2 = CreateCompatibleDC (GC);
+    SelectObject (gc2, spix);
     prod = o2n.x * o2n.y;
     y = 0;
     yr = o2n.y;
     yl = 0;
     for (yp = 0; yp < nsize.y; yp++) {
-       x = 0;
-       xr = o2n.x;
-       xl = 0;
-       for (xp = 0; xp < nsize.x; xp++) {
-           y2 = y;
-           yr2 = yr;
-           yl2 = yl;
-           rgb[0] = rgb[1] = rgb[2] = 0;
-           do {
-               x2 = x;
-               xr2 = xr;
-               xl2 = xl;
-               yf2 = (yl2 + yr2 > 1) ? 1 - yl2 : yr2, yr2 -= yf2;
-               do {
-                   xf2 = (xl2 + xr2 > 1) ? 1 - xl2 : xr2, xr2 -= xf2;
-                   color = GetPixel(gc1, x2, y2);
-                   rgb[0] += (GetRValue(color) * xf2 * yf2 / prod);
-                   rgb[1] += (GetGValue(color) * xf2 * yf2 / prod);
-                   rgb[2] += (GetBValue(color) * xf2 * yf2 / prod);
-                   xl2 += xf2;
-                   if (xl2 >= 1)
-                       x2++, xl2 -= 1;
-               } while (xr2 > 0);
-               xr2 = o2n.x;
-               yl2 += yf2;
-               if (yl2 >= 1)
-                   y2++, yl2 -= 1;
-           } while (yr2 > 0);
-           yr2 = o2n.y;
-           SetPixel(gc2, xp, yp, RGB(rgb[0], rgb[1], rgb[2]));
-           x = x2;
-           xr = xr2;
-           xl = xl2;
-       }
-       y = y2;
-       yr = yr2;
-       yl = yl2;
+        x = 0;
+        xr = o2n.x;
+        xl = 0;
+        for (xp = 0; xp < nsize.x; xp++) {
+            y2 = y;
+            yr2 = yr;
+            yl2 = yl;
+            rgb[0] = rgb[1] = rgb[2] = 0;
+            do {
+                x2 = x;
+                xr2 = xr;
+                xl2 = xl;
+                yf2 = (yl2 + yr2 > 1) ? 1 - yl2 : yr2, yr2 -= yf2;
+                do {
+                    xf2 = (xl2 + xr2 > 1) ? 1 - xl2 : xr2, xr2 -= xf2;
+                    color = GetPixel (gc1, x2, y2);
+                    rgb[0] += (GetRValue (color) * xf2 * yf2 / prod);
+                    rgb[1] += (GetGValue (color) * xf2 * yf2 / prod);
+                    rgb[2] += (GetBValue (color) * xf2 * yf2 / prod);
+                    xl2 += xf2;
+                    if (xl2 >= 1)
+                        x2++, xl2 -= 1;
+                } while (xr2 > 0);
+                xr2 = o2n.x;
+                yl2 += yf2;
+                if (yl2 >= 1)
+                    y2++, yl2 -= 1;
+            } while (yr2 > 0);
+            yr2 = o2n.y;
+            SetPixel (gc2, xp, yp, RGB (rgb[0], rgb[1], rgb[2]));
+            x = x2;
+            xr = xr2;
+            xl = xl2;
+        }
+        y = y2;
+        yr = yr2;
+        yl = yl2;
     }
-    DeleteDC(gc1);
-    DeleteDC(gc2);
+    DeleteDC (gc1);
+    DeleteDC (gc2);
     if (dir == 1) {
-       if (bitmap->u.bmap.scaled)
-           DeleteObject(bitmap->u.bmap.scaled);
-       bitmap->u.bmap.scaled = spix;
-       bitmap->scale = scale;
+        if (bitmap->u.bmap.scaled)
+            DeleteObject (bitmap->u.bmap.scaled);
+        bitmap->u.bmap.scaled = spix;
+        bitmap->scale = scale;
     }
     return 0;
 }
 
-int GCgetmousecoords(Gwidget_t * widget, Gpoint_t * gpp, int *count)
-{
+int GCgetmousecoords (Gwidget_t *widget, Gpoint_t *gpp, int *count) {
     PIXpoint_t pp;
     POINT p;
     int n1, n2, n3;
 
-    GetCursorPos(&p);
-    ScreenToClient(widget->w, &p);
+    GetCursorPos (&p);
+    ScreenToClient (widget->w, &p);
     pp.x = p.x, pp.y = p.y;
-    *gpp = ppixtodraw(widget, pp);
-    n1 = GetAsyncKeyState(VK_LBUTTON);
-    n2 = GetAsyncKeyState(VK_MBUTTON);
-    n3 = GetAsyncKeyState(VK_RBUTTON);
+    *gpp = ppixtodraw (widget, pp);
+    n1 = GetAsyncKeyState (VK_LBUTTON);
+    n2 = GetAsyncKeyState (VK_MBUTTON);
+    n3 = GetAsyncKeyState (VK_RBUTTON);
     *count = (n1 < 0 ? 1 : 0) + (n2 < 0 ? 1 : 0) + (n3 < 0 ? 1 : 0);
     return 0;
 }
 
-static void setgattr(Gwidget_t * widget, Ggattr_t * ap)
-{
+static void setgattr (Gwidget_t *widget, Ggattr_t *ap) {
     HBRUSH brush, pbrush;
     HPEN pen, ppen;
     PALETTEENTRY *colorp;
@@ -1209,58 +1202,60 @@ static void setgattr(Gwidget_t * widget, Ggattr_t * ap)
     double intens;
 
     if (!(ap->flags & G_GATTRCOLOR))
-       ap->color = WCU->defgattr.color;
+        ap->color = WCU->defgattr.color;
     if (!(ap->flags & G_GATTRWIDTH))
-       ap->width = WCU->defgattr.width;
+        ap->width = WCU->defgattr.width;
     if (!(ap->flags & G_GATTRMODE))
-       ap->mode = WCU->defgattr.mode;
+        ap->mode = WCU->defgattr.mode;
     if (!(ap->flags & G_GATTRFILL))
-       ap->fill = WCU->defgattr.fill;
+        ap->fill = WCU->defgattr.fill;
     if (!(ap->flags & G_GATTRSTYLE))
-       ap->style = WCU->defgattr.style;
+        ap->style = WCU->defgattr.style;
     flag = FALSE;
     mode = ap->mode;
     if (mode != WCU->gattr.mode) {
-       WCU->gattr.mode = mode;
-       SetROP2(GC, (int) mode);
+        WCU->gattr.mode = mode;
+        SetROP2 (GC, (int) mode);
     }
     WCU->gattr.fill = ap->fill;
     color = ap->color;
     if (color >= G_MAXCOLORS || !(WCU->colors[color].inuse))
-       color = 1;
+        color = 1;
     if (color != WCU->gattr.color)
-       WCU->gattr.color = color, flag = TRUE;
+        WCU->gattr.color = color, flag = TRUE;
     width = ap->width;
     if (width != WCU->gattr.width)
-       WCU->gattr.width = width, flag = TRUE;
+        WCU->gattr.width = width, flag = TRUE;
     style = ap->style;
     if (style != WCU->gattr.style)
-       WCU->gattr.style = style, style = TRUE;
+        WCU->gattr.style = style, style = TRUE;
 
     if (!flag)
-       return;
+        return;
     WCU->gattr.color = color;
     if (Gdepth == 1) {
-       colorp = &WCU->colors[color].color;
-       intens = (0.3 * colorp->peBlue + 0.59 * colorp->peRed +
-                 0.11 * colorp->peGreen) / 255.0;
-       pati =
-           (intens <= 0.0625) ? 16 : -16.0 * (log(intens) / 2.7725887222);
-       brush = WCU->grays[pati];
+        colorp = &WCU->colors[color].color;
+        intens = (
+            0.3 * colorp->peBlue + 0.59 * colorp->peRed +
+            0.11 * colorp->peGreen
+        ) / 255.0;
+        pati = (intens <= 0.0625) ? 16 : -16.0 * (log (intens) / 2.7725887222);
+        brush = WCU->grays[pati];
     } else
-       brush = CreateSolidBrush(PALETTEINDEX(WCU->gattr.color));
-    pbrush = SelectObject(GC, brush);
+        brush = CreateSolidBrush (PALETTEINDEX (WCU->gattr.color));
+    pbrush = SelectObject (GC, brush);
     if (Gdepth != 1)
-       DeleteObject(pbrush);
-    pen = CreatePen((int) gstyles[WCU->gattr.style], WCU->gattr.width,
-                   PALETTEINDEX(WCU->gattr.color));
-    ppen = SelectObject(GC, pen);
-    DeleteObject(ppen);
-    SetTextColor(GC, PALETTEINDEX(WCU->gattr.color));
+        DeleteObject (pbrush);
+    pen = CreatePen (
+        (int) gstyles[WCU->gattr.style], WCU->gattr.width,
+        PALETTEINDEX (WCU->gattr.color)
+    );
+    ppen = SelectObject (GC, pen);
+    DeleteObject (ppen);
+    SetTextColor (GC, PALETTEINDEX (WCU->gattr.color));
 }
 
-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;
 
@@ -1268,14 +1263,13 @@ static PIXrect_t rdrawtopix(Gwidget_t * widget, Grect_t gr)
     twx = WCU->wrect.c.x - WCU->wrect.o.x;
     twy = WCU->wrect.c.y - WCU->wrect.o.y;
     pr.o.x = tvx * (gr.o.x - WCU->wrect.o.x) / twx + 0.5;
-    pr.o.y = tvy * (1.0 - (gr.c.y - WCU->wrect.o.y) / twy) + 0.5;
+    pr.o.y = tvy * (1.0  - (gr.c.y - WCU->wrect.o.y) / twy) + 0.5;
     pr.c.x = tvx * (gr.c.x - WCU->wrect.o.x) / twx + 0.5;
-    pr.c.y = tvy * (1.0 - (gr.o.y - WCU->wrect.o.y) / twy) + 0.5;
+    pr.c.y = tvy * (1.0  - (gr.o.y - WCU->wrect.o.y) / twy) + 0.5;
     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;
 
@@ -1283,12 +1277,11 @@ static PIXpoint_t pdrawtopix(Gwidget_t * widget, Gpoint_t gp)
     twx = WCU->wrect.c.x - WCU->wrect.o.x;
     twy = WCU->wrect.c.y - WCU->wrect.o.y;
     pp.x = tvx * (gp.x - WCU->wrect.o.x) / twx + 0.5;
-    pp.y = tvy * (1.0 - (gp.y - WCU->wrect.o.y) / twy) + 0.5;
+    pp.y = tvy * (1.0  - (gp.y - WCU->wrect.o.y) / twy) + 0.5;
     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;
 
@@ -1300,8 +1293,7 @@ static PIXsize_t sdrawtopix(Gwidget_t * widget, Gsize_t gs)
     return ps;
 }
 
-Gpoint_t ppixtodraw(Gwidget_t * widget, PIXpoint_t pp)
-{
+Gpoint_t ppixtodraw (Gwidget_t *widget, PIXpoint_t pp) {
     Gpoint_t gp;
     double tvx, tvy, twx, twy;
 
@@ -1313,8 +1305,7 @@ Gpoint_t ppixtodraw(Gwidget_t * widget, PIXpoint_t pp)
     return gp;
 }
 
-static Gsize_t spixtodraw(Gwidget_t * widget, PIXsize_t ps)
-{
+static Gsize_t spixtodraw (Gwidget_t *widget, PIXsize_t ps) {
     Gsize_t gs;
     double tvx, tvy, twx, twy;
 
@@ -1326,8 +1317,7 @@ static Gsize_t spixtodraw(Gwidget_t * widget, PIXsize_t ps)
     return gs;
 }
 
-static Grect_t rpixtodraw(Gwidget_t * widget, PIXrect_t pr)
-{
+static Grect_t rpixtodraw (Gwidget_t *widget, PIXrect_t pr) {
     Grect_t gr;
     double tvx, tvy, twx, twy, n;
 
@@ -1339,14 +1329,13 @@ static Grect_t rpixtodraw(Gwidget_t * widget, PIXrect_t pr)
     gr.c.x = (pr.c.x / tvx) * twx + WCU->wrect.o.x;
     gr.c.y = (1.0 - pr.o.y / tvy) * twy + WCU->wrect.o.y;
     if (gr.o.x > gr.c.x)
-       n = gr.o.x, gr.o.x = gr.c.x, gr.c.x = n;
+        n = gr.o.x, gr.o.x = gr.c.x, gr.c.x = n;
     if (gr.o.y > gr.c.y)
-       n = gr.o.y, gr.o.y = gr.c.y, gr.c.y = n;
+        n = gr.o.y, gr.o.y = gr.c.y, gr.c.y = n;
     return gr;
 }
 
-static PIXrect_t rdrawtobpix(Gbitmap_t * bitmap, Grect_t gr)
-{
+static PIXrect_t rdrawtobpix (Gbitmap_t *bitmap, Grect_t gr) {
     PIXrect_t pr;
     double tvy;
 
@@ -1358,8 +1347,7 @@ static PIXrect_t rdrawtobpix(Gbitmap_t * bitmap, Grect_t gr)
     return pr;
 }
 
-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;
 
@@ -1369,21 +1357,20 @@ static PIXpoint_t pdrawtobpix(Gbitmap_t * bitmap, Gpoint_t gp)
     return pp;
 }
 
-void Gadjustclip(Gwidget_t * widget)
-{
+void Gadjustclip (Gwidget_t *widget) {
     Gwidget_t *parent;
     PIXrect_t pr;
     RECT r1, r2, r3;
 
     parent = &Gwidgets[widget->pwi];
-    GetWindowRect(widget->w, &r1);
-    GetClientRect(parent->w, &r2);
-    GetWindowRect(parent->w, &r3);
-    pr.o.x = max(0, -(r1.left - r3.left));
-    pr.o.y = max(0, -(r1.top - r3.top));
-    pr.c.x = min(r1.right - r1.left, pr.o.x + r2.right - r2.left);
-    pr.c.y = min(r1.bottom - r1.top, pr.o.y + r2.bottom - r2.top);
-    pr.c.x = max(pr.o.x, pr.c.x);
-    pr.c.y = max(pr.o.y, pr.c.y);
-    WCU->clip = rpixtodraw(widget, pr);
+    GetWindowRect (widget->w, &r1);
+    GetClientRect (parent->w, &r2);
+    GetWindowRect (parent->w, &r3);
+    pr.o.x = max (0, -(r1.left - r3.left));
+    pr.o.y = max (0, -(r1.top - r3.top));
+    pr.c.x = min (r1.right - r1.left, pr.o.x + r2.right - r2.left);
+    pr.c.y = min (r1.bottom - r1.top, pr.o.y + r2.bottom - r2.top);
+    pr.c.x = max (pr.o.x, pr.c.x);
+    pr.c.y = max (pr.o.y, pr.c.y);
+    WCU->clip = rpixtodraw (widget, pr);
 }
index 0018becbae2297b7bcff1d3fba7c7388b0196759..929bcb6ca6d56b7b1411c832f03378752828a2d9 100644 (file)
@@ -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"
@@ -45,138 +45,135 @@ static HFONT deffont;
 static int twobmouse;
 static HWND palettechanged;
 
-LRESULT CALLBACK LeftyWndProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK ArrayWndProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK CanvasWndProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK LabelWndProc(HWND, UINT, WPARAM, LPARAM);
-LRESULT CALLBACK ScrollWndProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK LeftyWndProc (HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK ArrayWndProc (HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK CanvasWndProc (HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK LabelWndProc (HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK ScrollWndProc (HWND, UINT, WPARAM, LPARAM);
 
-static void processcommand(Gwidget_t *, WPARAM, LPARAM);
-static void handleresize(Gwidget_t *);
+static void processcommand (Gwidget_t *, WPARAM, LPARAM);
+static void handleresize (Gwidget_t *);
 
-int Ginitgraphics(void)
-{
+int Ginitgraphics (void) {
     WNDCLASS wc;
     HDC hdc;
     ATOM rtn;
 
     if (!hprevinstance) {
-       wc.style = NULL;
-       wc.lpfnWndProc = LeftyWndProc;
-       wc.cbClsExtra = 0;
-       wc.cbWndExtra = 0;
-       wc.hInstance = hinstance;
-       wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
-       wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-       wc.lpszMenuName = 0;
-       wc.lpszClassName = "LeftyClass";
-       if (!(rtn = RegisterClass(&wc)))
-           panic(POS, "GXinit", "register class rtn = %d", (int) rtn);
-
-       wc.style = NULL;
-       wc.lpfnWndProc = ArrayWndProc;
-       wc.cbClsExtra = 0;
-       wc.cbWndExtra = 0;
-       wc.hInstance = hinstance;
-       wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
-       wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-       wc.lpszMenuName = 0;
-       wc.lpszClassName = "ArrayClass";
-       if (!(rtn = RegisterClass(&wc)))
-           panic(POS, "GXinit", "register class rtn = %d", (int) rtn);
-
-       wc.style = CS_OWNDC;
-       wc.lpfnWndProc = CanvasWndProc;
-       wc.cbClsExtra = 0;
-       wc.cbWndExtra = 0;
-       wc.hInstance = hinstance;
-       wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
-       wc.hCursor = NULL;
-       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-       wc.lpszMenuName = 0;
-       wc.lpszClassName = "CanvasClass";
-       if (!(rtn = RegisterClass(&wc)))
-           panic(POS, "GXinit", "register class rtn = %d", (int) rtn);
-
-       wc.style = NULL;
-       wc.lpfnWndProc = ScrollWndProc;
-       wc.cbClsExtra = 0;
-       wc.cbWndExtra = 0;
-       wc.hInstance = hinstance;
-       wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
-       wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-       wc.lpszMenuName = 0;
-       wc.lpszClassName = "ScrollClass";
-       if (!(rtn = RegisterClass(&wc)))
-           panic(POS, "GXinit", "register class rtn = %d", (int) rtn);
-
-       wc.style = NULL;
-       wc.lpfnWndProc = LabelWndProc;
-       wc.cbClsExtra = 0;
-       wc.cbWndExtra = 0;
-       wc.hInstance = hinstance;
-       wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
-       wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
-       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-       wc.lpszMenuName = 0;
-       wc.lpszClassName = "LabelClass";
-       if (!(rtn = RegisterClass(&wc)))
-           panic(POS, "GXinit", "register class rtn = %d", (int) rtn);
+        wc.style = NULL;
+        wc.lpfnWndProc = LeftyWndProc;
+        wc.cbClsExtra = 0;
+        wc.cbWndExtra = 0;
+        wc.hInstance = hinstance;
+        wc.hIcon = LoadIcon ((HINSTANCE) NULL, IDI_APPLICATION);
+        wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+        wc.hbrBackground = GetStockObject (WHITE_BRUSH);
+        wc.lpszMenuName = 0;
+        wc.lpszClassName = "LeftyClass";
+        if (!(rtn = RegisterClass (&wc)))
+            panic (POS, "GXinit", "register class rtn = %d", (int) rtn);
+
+        wc.style = NULL;
+        wc.lpfnWndProc = ArrayWndProc;
+        wc.cbClsExtra = 0;
+        wc.cbWndExtra = 0;
+        wc.hInstance = hinstance;
+        wc.hIcon = LoadIcon ((HINSTANCE) NULL, IDI_APPLICATION);
+        wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+        wc.hbrBackground = GetStockObject (WHITE_BRUSH);
+        wc.lpszMenuName = 0;
+        wc.lpszClassName = "ArrayClass";
+        if (!(rtn = RegisterClass (&wc)))
+            panic (POS, "GXinit", "register class rtn = %d", (int) rtn);
+
+        wc.style = CS_OWNDC;
+        wc.lpfnWndProc = CanvasWndProc;
+        wc.cbClsExtra = 0;
+        wc.cbWndExtra = 0;
+        wc.hInstance = hinstance;
+        wc.hIcon = LoadIcon ((HINSTANCE) NULL, IDI_APPLICATION);
+        wc.hCursor = NULL;
+        wc.hbrBackground = GetStockObject (WHITE_BRUSH);
+        wc.lpszMenuName = 0;
+        wc.lpszClassName = "CanvasClass";
+        if (!(rtn = RegisterClass (&wc)))
+            panic (POS, "GXinit", "register class rtn = %d", (int) rtn);
+
+        wc.style = NULL;
+        wc.lpfnWndProc = ScrollWndProc;
+        wc.cbClsExtra = 0;
+        wc.cbWndExtra = 0;
+        wc.hInstance = hinstance;
+        wc.hIcon = LoadIcon ((HINSTANCE) NULL, IDI_APPLICATION);
+        wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+        wc.hbrBackground = GetStockObject (WHITE_BRUSH);
+        wc.lpszMenuName = 0;
+        wc.lpszClassName = "ScrollClass";
+        if (!(rtn = RegisterClass (&wc)))
+            panic (POS, "GXinit", "register class rtn = %d", (int) rtn);
+
+        wc.style = NULL;
+        wc.lpfnWndProc = LabelWndProc;
+        wc.cbClsExtra = 0;
+        wc.cbWndExtra = 0;
+        wc.hInstance = hinstance;
+        wc.hIcon = LoadIcon ((HINSTANCE) NULL, IDI_APPLICATION);
+        wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
+        wc.hbrBackground = GetStockObject (WHITE_BRUSH);
+        wc.lpszMenuName = 0;
+        wc.lpszClassName = "LabelClass";
+        if (!(rtn = RegisterClass (&wc)))
+            panic (POS, "GXinit", "register class rtn = %d", (int) rtn);
     }
-    if (getenv("LEFTY3BMOUSE"))
-       twobmouse = FALSE;
+    if (getenv ("LEFTY3BMOUSE"))
+        twobmouse = FALSE;
     else
-       twobmouse = TRUE;
-    hdc = GetDC((HWND) NULL);
-    Gdepth = GetDeviceCaps(hdc, BITSPIXEL);
-    deffont = GetStockObject(SYSTEM_FONT);
+        twobmouse = TRUE;
+    hdc = GetDC ((HWND) NULL);
+    Gdepth = GetDeviceCaps (hdc, BITSPIXEL);
+    deffont = GetStockObject (SYSTEM_FONT);
 #ifndef FEATURE_MS
-    if (!(Gxfp = fopen("/dev/windows", "r")))
-       panic(POS, "GXinit", "cannot open windows device");
-    Gxfd = fileno(Gxfp);
+    if (!(Gxfp = fopen ("/dev/windows", "r")))
+        panic (POS, "GXinit", "cannot open windows device");
+    Gxfd = fileno (Gxfp);
 #endif
     Gpopdownflag = FALSE;
-    Gbufp = Marrayalloc((long) BUFINCR * BUFSIZE);
+    Gbufp = Marrayalloc ((long) BUFINCR * BUFSIZE);
     Gbufn = BUFINCR;
-    Gppp = Marrayalloc((long) PPINCR * PPSIZE);
+    Gppp = Marrayalloc ((long) PPINCR * PPSIZE);
     Gppn = PPINCR;
-    Gfontp = Marrayalloc((long) FONTSIZE);
+    Gfontp = Marrayalloc ((long) FONTSIZE);
     Gfontn = 1;
-    Gfontp[0].name = strdup("default");
+    Gfontp[0].name = strdup ("default");
     if (!Gdefaultfont)
-       Gfontp[0].font = deffont;
+        Gfontp[0].font = deffont;
     else if (Gdefaultfont[0] != '\000')
-       Gfontp[0].font = CreateFont(0, 0, 0, 0, 0,
-                                   0, 0, 0, 0, 0, 0, 0, 0, Gdefaultfont);
+        Gfontp[0].font = CreateFont (
+            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Gdefaultfont
+        );
     else
-       Gfontp[0].font = NULL;
-    ReleaseDC((HWND) NULL, hdc);
+        Gfontp[0].font = NULL;
+    ReleaseDC ((HWND) NULL, hdc);
     Gnocallbacks = FALSE;
     return 0;
 }
 
-int Gtermgraphics(void)
-{
+int Gtermgraphics (void) {
     int fi;
 
     for (fi = 0; fi < Gfontn; fi++)
-       free(Gfontp[fi].name);
-    Marrayfree(Gfontp), Gfontp = NULL, Gfontn = 0;
-    Marrayfree(Gppp), Gppp = NULL, Gppn = 0;
-    Marrayfree(Gbufp), Gbufp = NULL, Gbufn = 0;
+        free (Gfontp[fi].name);
+    Marrayfree (Gfontp), Gfontp = NULL, Gfontn = 0;
+    Marrayfree (Gppp), Gppp = NULL, Gppn = 0;
+    Marrayfree (Gbufp), Gbufp = NULL, Gbufn = 0;
     return 0;
 }
 
-int Gsync(void)
-{
+int Gsync (void) {
     return 0;
 }
 
-int Gresetbstate(int wi)
-{
+int Gresetbstate (int wi) {
     Gcw_t *cw;
     int bn;
 
@@ -188,107 +185,106 @@ int Gresetbstate(int wi)
     return 0;
 }
 
-int Gprocessevents(int waitflag, Geventmode_t mode)
-{
+int Gprocessevents (int waitflag, int mode) {
     MSG msg;
     int rtn;
 
     rtn = 0;
     switch (waitflag) {
     case TRUE:
-       if (!GetMessage(&msg, (HWND) NULL, (UINT) NULL, (UINT) NULL))
-           exit(msg.wParam);
-       TranslateMessage(&msg);
-       DispatchMessage(&msg);
-       if (mode == G_ONEEVENT)
-           return 1;
-       rtn = 1;
-       /* FALL THROUGH */
+        if (!GetMessage(&msg, (HWND) NULL, (UINT) NULL, (UINT) NULL))
+            exit (msg.wParam);
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
+        if (mode == G_ONEEVENT)
+            return 1;
+        rtn = 1;
+        /* FALL THROUGH */
     case FALSE:
-       while (PeekMessage(&msg, (HWND) 0, (UINT) 0, (UINT) 0, PM_REMOVE)) {
-           if (msg.message == WM_QUIT)
-               exit(msg.wParam);
-           TranslateMessage(&msg);
-           DispatchMessage(&msg);
-           if (mode == G_ONEEVENT)
-               return 1;
-           rtn = 1;
-       }
-       break;
+        while (PeekMessage(&msg, (HWND) 0, (UINT) 0, (UINT) 0, PM_REMOVE)) {
+            if (msg.message == WM_QUIT)
+                exit (msg.wParam);
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+            if (mode == G_ONEEVENT)
+                return 1;
+            rtn = 1;
+        }
+        break;
     }
     return rtn;
 }
 
-LRESULT CALLBACK LeftyWndProc(HWND hwnd,
-                             UINT message, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK LeftyWndProc (
+    HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
+{
     Gwidget_t *widget;
     WINDOWPOS *wpos;
     Gevent_t gev;
 
-    widget = findwidget(hwnd, G_VIEWWIDGET);
+    widget = findwidget (hwnd, G_VIEWWIDGET);
     switch (message) {
     case WM_WINDOWPOSCHANGED:
-       if (Gnocallbacks || !widget)
-           return (DefWindowProc(hwnd, message, wparam, lparam));
-       wpos = (WINDOWPOS *) lparam;
-       if (!(wpos->flags & SWP_NOSIZE))
-           handleresize(widget);
-       break;
+        if (Gnocallbacks || !widget)
+            return (DefWindowProc(hwnd, message, wparam, lparam));
+        wpos = (WINDOWPOS *) lparam;
+        if (!(wpos->flags & SWP_NOSIZE))
+            handleresize (widget);
+        break;
     case WM_COMMAND:
-       if (Gnocallbacks || !widget)
-           return (DefWindowProc(hwnd, message, wparam, lparam));
-       processcommand(widget, wparam, lparam);
-       break;
+        if (Gnocallbacks || !widget)
+            return (DefWindowProc(hwnd, message, wparam, lparam));
+        processcommand (widget, wparam, lparam);
+        break;
     case WM_CLOSE:
-       if (!widget)
-           exit(0);
-       if (WVU->closing)
-           DestroyWindow(hwnd);
-       if (Gnocallbacks)
-           exit(0);
-       gev.type = 0, gev.code = 0, gev.data = 0;
-       gev.wi = widget - &Gwidgets[0];
-       if (WVU->func)
-           (*WVU->func) (&gev);
-       else
-           exit(0);
-       break;
+        if (!widget)
+            exit (0);
+        if (WVU->closing)
+            DestroyWindow (hwnd);
+        if (Gnocallbacks)
+            exit (0);
+        gev.type = 0, gev.code = 0, gev.data = 0;
+        gev.wi = widget - &Gwidgets[0];
+        if (WVU->func)
+            (*WVU->func) (&gev);
+        else
+            exit (0);
+        break;
     case WM_PALETTECHANGED:
-       palettechanged = (HWND) wparam;
-       break;
+        palettechanged = (HWND) wparam;
+        break;
     default:
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     }
     return 0;
 }
 
-LRESULT CALLBACK ArrayWndProc(HWND hwnd,
-                             UINT message, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK ArrayWndProc (
+    HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
+{
     Gwidget_t *widget;
     WINDOWPOS *wpos;
 
-    if (Gnocallbacks || !(widget = findwidget(hwnd, G_ARRAYWIDGET)))
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+    if (Gnocallbacks || !(widget = findwidget (hwnd, G_ARRAYWIDGET)))
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     switch (message) {
     case WM_WINDOWPOSCHANGED:
-       wpos = (WINDOWPOS *) lparam;
-       if (!(wpos->flags & SWP_NOSIZE))
-           handleresize(widget);
-       break;
+        wpos = (WINDOWPOS *) lparam;
+        if (!(wpos->flags & SWP_NOSIZE))
+            handleresize (widget);
+        break;
     case WM_COMMAND:
-       processcommand(widget, wparam, lparam);
-       break;
+        processcommand (widget, wparam, lparam);
+        break;
     default:
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        return (DefWindowProc (hwnd, message, wparam, lparam));
     }
     return 0;
 }
 
-LRESULT CALLBACK CanvasWndProc(HWND hwnd,
-                              UINT message, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK CanvasWndProc (
+    HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
+{
     Gwidget_t *widget;
     WINDOWPOS *wpos;
     PIXpoint_t pp;
@@ -296,104 +292,94 @@ LRESULT CALLBACK CanvasWndProc(HWND hwnd,
     POINT p;
     int wi, bn;
 
-    if (Gnocallbacks || !(widget = findwidget(hwnd, G_CANVASWIDGET)))
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+    static int cntlflag;
+
+    if (Gnocallbacks || !(widget = findwidget (hwnd, G_CANVASWIDGET)))
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     Gpopdownflag = FALSE;
     switch (message) {
     case WM_PAINT:
-       if (palettechanged != hwnd)
-           RealizePalette(widget->u.c->gc);
-       Gneedredraw = widget->u.c->needredraw = TRUE;
-       Gadjustclip(widget);
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        if (palettechanged != hwnd)
+            RealizePalette (widget->u.c->gc);
+        Gneedredraw = widget->u.c->needredraw = TRUE;
+        Gadjustclip (widget);
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     case WM_WINDOWPOSCHANGED:
-       wpos = (WINDOWPOS *) lparam;
-       if (!(wpos->flags & SWP_NOSIZE))
-           handleresize(widget);
-       return 0;
+        wpos = (WINDOWPOS *) lparam;
+        if (!(wpos->flags & SWP_NOSIZE))
+            handleresize (widget);
+        return 0;
     case WM_MOUSEACTIVATE:
-       SetFocus(widget->w);
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        SetFocus (widget->w);
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     case WM_COMMAND:
-       processcommand(widget, wparam, lparam);
-       return 0;
+        processcommand (widget, wparam, lparam);
+        return 0;
     case WM_CHAR:
-       gev.type = G_KEYBD;
-       gev.code = G_DOWN;      /* I don't know how to get up events so I make */
-       Gpopdownflag = TRUE;    /* the code after this switch send the up event */
-       gev.data = wparam;
-       GetCursorPos(&p);
-       ScreenToClient(widget->w, &p);
-       pp.x = p.x, pp.y = p.y;
-       gev.p = ppixtodraw(widget, pp);
-       /* continues after the end of this switch */
-       break;
+        gev.type = G_KEYBD;
+        gev.code = G_DOWN;   /* I don't know how to get up events so I make */
+        Gpopdownflag = TRUE; /* the code after this switch send the up event */
+        gev.data = wparam;
+        GetCursorPos (&p);
+        ScreenToClient (widget->w, &p);
+        pp.x = p.x, pp.y = p.y;
+        gev.p = ppixtodraw (widget, pp);
+        /* continues after the end of this switch */
+        break;
     case WM_LBUTTONDOWN:
     case WM_LBUTTONUP:
     case WM_MBUTTONDOWN:
     case WM_MBUTTONUP:
     case WM_RBUTTONDOWN:
     case WM_RBUTTONUP:
-       gev.type = G_MOUSE;
-       if (twobmouse) {
-           if (message == WM_LBUTTONDOWN && (wparam & MK_CONTROL))
-               message = WM_MBUTTONDOWN;
-           if (message == WM_LBUTTONUP && (wparam & MK_CONTROL))
-               message = WM_MBUTTONUP;
-       }
-       switch (message) {
-       case WM_LBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_LEFT;
-           break;
-       case WM_LBUTTONUP:
-           gev.code = G_UP, gev.data = G_LEFT;
-           break;
-       case WM_MBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_MIDDLE;
-           break;
-       case WM_MBUTTONUP:
-           gev.code = G_UP, gev.data = G_MIDDLE;
-           break;
-       case WM_RBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_RIGHT;
-           break;
-       case WM_RBUTTONUP:
-           gev.code = G_UP, gev.data = G_RIGHT;
-           break;
-       }
-       pp.x = LOWORD(lparam), pp.y = HIWORD(lparam);
-       gev.p = ppixtodraw(widget, pp);
-       bn = WCU->bstate[gev.data];
-       WCU->bstate[gev.data] = (gev.code == G_DOWN) ? 1 : 0;
-       bn = WCU->bstate[gev.data] - bn;
-       widget->u.c->buttonsdown += bn;
-       Gbuttonsdown += bn;
-       /* continues after the end of this switch */
-       break;
+        gev.type = G_MOUSE;
+        if (twobmouse) {
+            if (message == WM_LBUTTONDOWN && (wparam & MK_CONTROL))
+                message = WM_MBUTTONDOWN, cntlflag = TRUE;
+            if (message == WM_LBUTTONUP && cntlflag)
+                message = WM_MBUTTONUP, cntlflag = FALSE;
+        }
+        switch (message) {
+        case WM_LBUTTONDOWN: gev.code = G_DOWN, gev.data = G_LEFT;   break;
+        case WM_LBUTTONUP:   gev.code = G_UP,   gev.data = G_LEFT;   break;
+        case WM_MBUTTONDOWN: gev.code = G_DOWN, gev.data = G_MIDDLE; break;
+        case WM_MBUTTONUP:   gev.code = G_UP,   gev.data = G_MIDDLE; break;
+        case WM_RBUTTONDOWN: gev.code = G_DOWN, gev.data = G_RIGHT;  break;
+        case WM_RBUTTONUP:   gev.code = G_UP,   gev.data = G_RIGHT;  break;
+        }
+        pp.x = LOWORD (lparam), pp.y = HIWORD (lparam);
+        gev.p = ppixtodraw (widget, pp);
+        bn = WCU->bstate[gev.data];
+        WCU->bstate[gev.data] = (gev.code == G_DOWN) ? 1 : 0;
+        bn = WCU->bstate[gev.data] - bn;
+        widget->u.c->buttonsdown += bn;
+        Gbuttonsdown += bn;
+        /* continues after the end of this switch */
+        break;
     default:
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     }
     wi = gev.wi = widget - &Gwidgets[0];
     if (widget->u.c->func)
-       (*widget->u.c->func) (&gev);
+        (*widget->u.c->func) (&gev);
     if (Gpopdownflag) {
-       Gpopdownflag = FALSE;
-       if (gev.code == G_DOWN) {
-           gev.code = G_UP;
-           widget = &Gwidgets[wi];
-           WCU->bstate[gev.data] = 0;
-           widget->u.c->buttonsdown--;
-           Gbuttonsdown--;
-           if (widget->inuse && widget->u.c->func)
-               (*widget->u.c->func) (&gev);
-       }
+        Gpopdownflag = FALSE;
+        if (gev.code == G_DOWN) {
+            gev.code = G_UP;
+            widget = &Gwidgets[wi];
+            WCU->bstate[gev.data] = 0;
+            widget->u.c->buttonsdown--;
+            Gbuttonsdown--;
+            if (widget->inuse && widget->u.c->func)
+                (*widget->u.c->func) (&gev);
+        }
     }
     return 0;
 }
 
-LRESULT CALLBACK LabelWndProc(HWND hwnd,
-                             UINT message, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK LabelWndProc (
+    HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
+{
     Gwidget_t *widget;
     PAINTSTRUCT paintstruct;
     WINDOWPOS *wpos;
@@ -402,260 +388,218 @@ LRESULT CALLBACK LabelWndProc(HWND hwnd,
     HDC hdc;
     int wi;
 
-    if (Gnocallbacks || !(widget = findwidget(hwnd, G_LABELWIDGET)))
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+    if (Gnocallbacks || !(widget = findwidget (hwnd, G_LABELWIDGET)))
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     switch (message) {
     case WM_PAINT:
-       hdc = BeginPaint(widget->w, &paintstruct);
-       GetWindowText(widget->w, &Gbufp[0], Gbufn);
-       GetClientRect(widget->w, &r);
-       DrawText(hdc, (LPCSTR) & Gbufp[0], strlen(Gbufp), &r, DT_LEFT);
-       EndPaint(widget->w, &paintstruct);
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        hdc = BeginPaint (widget->w, &paintstruct);
+        GetWindowText (widget->w, &Gbufp[0], Gbufn);
+        GetClientRect (widget->w, &r);
+        DrawText (hdc, (LPCSTR) &Gbufp[0], strlen (Gbufp), &r, DT_LEFT);
+        EndPaint (widget->w, &paintstruct);
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     case WM_WINDOWPOSCHANGED:
-       wpos = (WINDOWPOS *) lparam;
-       if (!(wpos->flags & SWP_NOSIZE))
-           handleresize(widget);
-       return 0;
+        wpos = (WINDOWPOS *) lparam;
+        if (!(wpos->flags & SWP_NOSIZE))
+            handleresize (widget);
+        return 0;
     case WM_COMMAND:
-       processcommand(widget, wparam, lparam);
-       return 0;
+        processcommand (widget, wparam, lparam);
+        return 0;
     case WM_KEYDOWN:
     case WM_KEYUP:
-       gev.type = G_KEYBD;
-       gev.code = (message == WM_KEYDOWN) ? G_DOWN : G_UP;
-       gev.data = wparam;
-       /* continues after the end of this switch */
-       break;
+        gev.type = G_KEYBD;
+        gev.code = (message == WM_KEYDOWN) ? G_DOWN : G_UP;
+        gev.data = wparam;
+        /* continues after the end of this switch */
+        break;
     case WM_LBUTTONDOWN:
     case WM_LBUTTONUP:
     case WM_MBUTTONDOWN:
     case WM_MBUTTONUP:
     case WM_RBUTTONDOWN:
     case WM_RBUTTONUP:
-       gev.type = G_MOUSE;
-       if (wparam & MK_CONTROL) {
-           if (message == WM_LBUTTONDOWN)
-               message = WM_MBUTTONDOWN;
-           else if (message == WM_LBUTTONUP)
-               message = WM_MBUTTONUP;
-       }
-       switch (message) {
-       case WM_LBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_LEFT;
-           break;
-       case WM_LBUTTONUP:
-           gev.code = G_UP, gev.data = G_LEFT;
-           break;
-       case WM_MBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_MIDDLE;
-           break;
-       case WM_MBUTTONUP:
-           gev.code = G_UP, gev.data = G_MIDDLE;
-           break;
-       case WM_RBUTTONDOWN:
-           gev.code = G_DOWN, gev.data = G_RIGHT;
-           break;
-       case WM_RBUTTONUP:
-           gev.code = G_UP, gev.data = G_RIGHT;
-           break;
-       }
-       /* continues after the end of this switch */
-       break;
+        gev.type = G_MOUSE;
+        if (wparam & MK_CONTROL) {
+            if (message == WM_LBUTTONDOWN)
+                message = WM_MBUTTONDOWN;
+            else if (message == WM_LBUTTONUP)
+                message = WM_MBUTTONUP;
+        }
+        switch (message) {
+        case WM_LBUTTONDOWN: gev.code = G_DOWN, gev.data = G_LEFT;   break;
+        case WM_LBUTTONUP:   gev.code = G_UP,   gev.data = G_LEFT;   break;
+        case WM_MBUTTONDOWN: gev.code = G_DOWN, gev.data = G_MIDDLE; break;
+        case WM_MBUTTONUP:   gev.code = G_UP,   gev.data = G_MIDDLE; break;
+        case WM_RBUTTONDOWN: gev.code = G_DOWN, gev.data = G_RIGHT;  break;
+        case WM_RBUTTONUP:   gev.code = G_UP,   gev.data = G_RIGHT;  break;
+        }
+        /* continues after the end of this switch */
+        break;
     default:
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     }
     wi = gev.wi = widget - &Gwidgets[0];
     if (widget->u.l->func)
-       (*widget->u.l->func) (&gev);
+        (*widget->u.l->func) (&gev);
     if (Gpopdownflag) {
-       Gpopdownflag = FALSE;
-       if (gev.type == G_MOUSE && gev.code == G_DOWN) {
-           gev.code = G_UP;
-           widget = &Gwidgets[wi];
-           if (widget->inuse && widget->u.l->func)
-               (*widget->u.l->func) (&gev);
-       }
+        Gpopdownflag = FALSE;
+        if (gev.type == G_MOUSE && gev.code == G_DOWN) {
+            gev.code = G_UP;
+            widget = &Gwidgets[wi];
+            if (widget->inuse && widget->u.l->func)
+                (*widget->u.l->func) (&gev);
+        }
     }
     return 0;
 }
 
-LRESULT CALLBACK ScrollWndProc(HWND hwnd,
-                              UINT message, WPARAM wparam, LPARAM lparam)
-{
+LRESULT CALLBACK ScrollWndProc (
+    HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
+{
     Gwidget_t *widget, *child;
     WINDOWPOS *wpos;
     PIXpoint_t po;
     RECT r;
     int dummy, dx, dy, wi;
 
-    if (Gnocallbacks || !(widget = findwidget(hwnd, G_SCROLLWIDGET)))
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+    if (Gnocallbacks || !(widget = findwidget (hwnd, G_SCROLLWIDGET)))
+        return (DefWindowProc(hwnd, message, wparam, lparam));
     switch (message) {
     case WM_WINDOWPOSCHANGED:
-       wpos = (WINDOWPOS *) lparam;
-       if (!(wpos->flags & SWP_NOSIZE))
-           handleresize(widget);
-       break;
+        wpos = (WINDOWPOS *) lparam;
+        if (!(wpos->flags & SWP_NOSIZE))
+            handleresize (widget);
+        break;
     case WM_HSCROLL:
     case WM_VSCROLL:
-       for (wi = 0; wi < Gwidgetn; wi++) {
-           child = &Gwidgets[wi];
-           if (child->inuse && child->pwi == widget - &Gwidgets[0])
-               break;
-       }
-       if (wi == Gwidgetn)
-           return (DefWindowProc(hwnd, message, wparam, lparam));
-       GetClientRect(widget->w, &r);
-       GetScrollRange(widget->w, SB_HORZ, &dummy, &dx);
-       GetScrollRange(widget->w, SB_VERT, &dummy, &dy);
-       po.x = GetScrollPos(widget->w, SB_HORZ);
-       po.y = GetScrollPos(widget->w, SB_VERT);
-       switch (message) {
-       case WM_HSCROLL:
-           switch (LOWORD(wparam)) {
-           case SB_BOTTOM:
-               po.x = dx;
-               break;
-           case SB_LINEDOWN:
-               po.x += 10;
-               break;
-           case SB_LINEUP:
-               po.x -= 10;
-               break;
-           case SB_PAGEDOWN:
-               po.x += (r.right - r.left);
-               break;
-           case SB_PAGEUP:
-               po.x -= (r.right - r.left);
-               break;
-           case SB_THUMBPOSITION:
-               po.x = HIWORD(wparam);
-               break;
-           case SB_THUMBTRACK:
-               po.x = HIWORD(wparam);
-               break;
-           case SB_TOP:
-               po.x = 0;
-               break;
-           }
-           po.x = min(po.x, dx);
-           po.x = max(po.x, 0);
-           SetScrollPos(widget->w, SB_HORZ, po.x, TRUE);
-           SetWindowPos(child->w, (HWND) NULL, -po.x, -po.y, 0, 0,
-                        SWP_NOSIZE | SWP_NOZORDER);
-           break;
-       case WM_VSCROLL:
-           switch (LOWORD(wparam)) {
-           case SB_BOTTOM:
-               po.y = dy;
-               break;
-           case SB_LINEDOWN:
-               po.y += 10;
-               break;
-           case SB_LINEUP:
-               po.y -= 10;
-               break;
-           case SB_PAGEDOWN:
-               po.y += (r.bottom - r.top);
-               break;
-           case SB_PAGEUP:
-               po.y -= (r.bottom - r.top);
-               break;
-           case SB_THUMBPOSITION:
-               po.y = HIWORD(wparam);
-               break;
-           case SB_THUMBTRACK:
-               po.y = HIWORD(wparam);
-               break;
-           case SB_TOP:
-               po.y = 0;
-               break;
-           }
-           po.y = min(po.y, dy);
-           po.y = max(po.y, 0);
-           SetScrollPos(widget->w, SB_VERT, po.y, TRUE);
-           SetWindowPos(child->w, (HWND) NULL, -po.x, -po.y, 0, 0,
-                        SWP_NOSIZE | SWP_NOZORDER);
-           break;
-       }
-       break;
+        for (wi = 0; wi < Gwidgetn; wi++) {
+            child = &Gwidgets[wi];
+            if (child->inuse && child->pwi == widget - &Gwidgets[0])
+                break;
+        }
+        if (wi == Gwidgetn)
+            return (DefWindowProc(hwnd, message, wparam, lparam));
+        GetClientRect (widget->w, &r);
+        GetScrollRange (widget->w, SB_HORZ, &dummy, &dx);
+        GetScrollRange (widget->w, SB_VERT, &dummy, &dy);
+        po.x = GetScrollPos (widget->w, SB_HORZ);
+        po.y = GetScrollPos (widget->w, SB_VERT);
+        switch (message) {
+        case WM_HSCROLL:
+            switch (LOWORD (wparam)) {
+            case SB_BOTTOM:        po.x = dx;                  break;
+            case SB_LINEDOWN:      po.x += 10;                 break;
+            case SB_LINEUP:        po.x -= 10;                 break;
+            case SB_PAGEDOWN:      po.x += (r.right - r.left); break;
+            case SB_PAGEUP:        po.x -= (r.right - r.left); break;
+            case SB_THUMBPOSITION: po.x = HIWORD (wparam);     break;
+            case SB_THUMBTRACK:    po.x = HIWORD (wparam);     break;
+            case SB_TOP:           po.x = 0;                   break;
+            }
+            po.x = min (po.x, dx);
+            po.x = max (po.x, 0);
+            SetScrollPos (widget->w, SB_HORZ, po.x, TRUE);
+            SetWindowPos (
+                child->w, (HWND) NULL, -po.x, -po.y, 0, 0,
+                SWP_NOSIZE | SWP_NOZORDER
+            );
+            break;
+        case WM_VSCROLL:
+            switch (LOWORD (wparam)) {
+            case SB_BOTTOM:        po.y = dy;                  break;
+            case SB_LINEDOWN:      po.y += 10;                 break;
+            case SB_LINEUP:        po.y -= 10;                 break;
+            case SB_PAGEDOWN:      po.y += (r.bottom - r.top); break;
+            case SB_PAGEUP:        po.y -= (r.bottom - r.top); break;
+            case SB_THUMBPOSITION: po.y = HIWORD (wparam);     break;
+            case SB_THUMBTRACK:    po.y = HIWORD (wparam);     break;
+            case SB_TOP:           po.y = 0;                   break;
+            }
+            po.y = min (po.y, dy);
+            po.y = max (po.y, 0);
+            SetScrollPos (widget->w, SB_VERT, po.y, TRUE);
+            SetWindowPos (
+                child->w, (HWND) NULL, -po.x, -po.y, 0, 0,
+                SWP_NOSIZE | SWP_NOZORDER
+            );
+            break;
+        }
+        break;
     default:
-       return (DefWindowProc(hwnd, message, wparam, lparam));
+        return (DefWindowProc (hwnd, message, wparam, lparam));
     }
     return 0;
 }
 
-static void processcommand(Gwidget_t * widget, WPARAM wparam,
-                          LPARAM lparam)
-{
+static void processcommand (Gwidget_t *widget, WPARAM wparam, LPARAM lparam) {
     Gwidget_t *child;
     WORD l;
     int n;
 
-    if (lparam == 0) {         /* it's a menu */
-       if (LOWORD(wparam) != 999)
-           menuselected = LOWORD(wparam);
-       menupoped = FALSE;
-       return;
+    if (lparam == 0) { /* it's a menu */
+        if (LOWORD (wparam) != 999)
+            menuselected = LOWORD (wparam);
+        menupoped = FALSE;
+        return;
     }
-    if (!(LOWORD(wparam) > 0 && LOWORD(wparam) < Gwidgetn))
-       return;
-    child = &Gwidgets[LOWORD(wparam)];
+    if (!(LOWORD (wparam) > 0 && LOWORD (wparam) < Gwidgetn))
+        return;
+    child = &Gwidgets[LOWORD (wparam)];
     if (!child->inuse)
-       return;
+        return;
 
     switch (child->type) {
     case G_TEXTWIDGET:
-       if (HIWORD(wparam) == EN_CHANGE) {      /* it's a text widget message */
-           if ((n = SendMessage(child->w, EM_GETLINECOUNT, 0, 0L)) < 2)
-               return;
-           *((WORD *) & Gbufp[0]) = Gbufn - 1;
-           l = SendMessage(child->w, EM_GETLINE, n - 1,
-                           (LPARAM) (LPSTR) & Gbufp[0]);
-           if (l != 0)
-               return;         /* no carriage return yet */
-           *((WORD *) & Gbufp[0]) = Gbufn - 1;
-           l = SendMessage(child->w, EM_GETLINE, n - 2,
-                           (LPARAM) (LPSTR) & Gbufp[0]);
-           Gbufp[l] = 0;
-           if (l > 0 && child->u.t->func)
-               (*child->u.t->func) (child - &Gwidgets[0], &Gbufp[0]);
-       }
-       break;
+        if (HIWORD (wparam) == EN_CHANGE) { /* it's a text widget message */
+            if ((n = SendMessage (child->w, EM_GETLINECOUNT, 0, 0L)) < 2)
+                return;
+            *((WORD *) &Gbufp[0]) = Gbufn - 1;
+            l = SendMessage (
+                child->w, EM_GETLINE, n - 1, (LPARAM) (LPSTR) &Gbufp[0]
+            );
+            if (l != 0)
+                return; /* no carriage return yet */
+            *((WORD *) &Gbufp[0]) = Gbufn - 1;
+            l = SendMessage (
+                child->w, EM_GETLINE, n - 2, (LPARAM) (LPSTR) &Gbufp[0]
+            );
+            Gbufp[l] = 0;
+            if (l > 0 && child->u.t->func)
+                (*child->u.t->func) (child - &Gwidgets[0], &Gbufp[0]);
+        }
+        break;
     case G_BUTTONWIDGET:
-       if (child->u.b->func)
-           (*child->u.b->func) (child - &Gwidgets[0], child->udata);
-       break;
+        if (child->u.b->func)
+            (*child->u.b->func) (child - &Gwidgets[0], child->udata);
+        break;
     }
 }
 
-void Gadjustwrect(Gwidget_t * parent, PIXsize_t * psp)
-{
+void Gadjustwrect (Gwidget_t *parent, PIXsize_t *psp) {
     RECT r;
 
-    GetClientRect(parent->w, &r);
+    GetClientRect (parent->w, &r);
     switch (parent->type) {
     case G_ARRAYWIDGET:
-       if (parent->u.a->data.type == G_AWHARRAY)
-           psp->y = r.bottom - r.top;
-       else
-           psp->x = r.right - r.left;
-       break;
+        if (parent->u.a->data.type == G_AWHARRAY)
+            psp->y = r.bottom - r.top;
+        else
+            psp->x = r.right - r.left;
+        break;
     case G_SCROLLWIDGET:
-       psp->x = max(psp->x, r.right - r.left);
-       psp->y = max(psp->y, r.bottom - r.top);
-       break;
+        psp->x = max (psp->x, r.right - r.left);
+        psp->y = max (psp->y, r.bottom - r.top);
+        break;
     case G_VIEWWIDGET:
     case G_QUERYWIDGET:
-       psp->x = r.right - r.left;
-       psp->y = r.bottom - r.top;
-       break;
+        psp->x = r.right - r.left;
+        psp->y = r.bottom - r.top;
+        break;
     }
 }
 
-static void handleresize(Gwidget_t * widget)
-{
+static void handleresize (Gwidget_t *widget) {
     Gwidget_t *parent, *child;
     PIXsize_t ps1, ps2;
     PIXpoint_t po;
@@ -665,98 +609,95 @@ static void handleresize(Gwidget_t * widget)
 
     wflags1 = SWP_NOMOVE | SWP_NOZORDER;
     wflags2 = SWP_NOSIZE | SWP_NOZORDER;
-    GetWindowRect(widget->w, &r);
+    GetWindowRect (widget->w, &r);
     ps1.x = r.right - r.left, ps1.y = r.bottom - r.top;
     ps2 = ps1;
     /* first, take care of parent */
     parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
     if (!parent)
-       goto handlechildren;
+        goto handlechildren;
     switch (parent->type) {
     case G_VIEWWIDGET:
-       Gadjustwrect(parent, &ps1);
-       if (ps1.x != ps2.x || ps1.y != ps2.y) {
-           Gnocallbacks = TRUE;
-           SetWindowPos(widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y,
-                        wflags1);
-           Gnocallbacks = FALSE;
-       }
-       break;
+        Gadjustwrect (parent, &ps1);
+        if (ps1.x != ps2.x || ps1.y != ps2.y) {
+            Gnocallbacks = TRUE;
+            SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
+            Gnocallbacks = FALSE;
+        }
+        break;
     case G_ARRAYWIDGET:
-       Gnocallbacks = TRUE;
-       Gawresize(parent);
-       Gnocallbacks = FALSE;
-       break;
+        Gnocallbacks = TRUE;
+        Gawresize (parent);
+        Gnocallbacks = FALSE;
+        break;
     case G_SCROLLWIDGET:
-       Gnocallbacks = TRUE;
-       for (i = 0; i < 2; i++) {
-           Gadjustwrect(parent, &ps1);
-           if (ps1.x > ps2.x || ps1.y > ps2.y)
-               SetWindowPos(widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y,
-                            wflags1);
-           GetClientRect(parent->w, &r);
-           ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
-           dx = max(0, ps1.x - ps2.x);
-           dy = max(0, ps1.y - ps2.y);
-           SetScrollRange(parent->w, SB_HORZ, 0, dx, TRUE);
-           SetScrollRange(parent->w, SB_VERT, 0, dy, TRUE);
-           po.x = GetScrollPos(parent->w, SB_HORZ);
-           po.y = GetScrollPos(parent->w, SB_VERT);
-           po.x = min(po.x, dx);
-           po.x = max(po.x, 0);
-           SetScrollPos(parent->w, SB_HORZ, po.x, TRUE);
-           po.y = min(po.y, dy);
-           po.y = max(po.y, 0);
-           SetScrollPos(parent->w, SB_VERT, po.y, TRUE);
-           SetWindowPos(widget->w, (HWND) NULL, -po.x, -po.y, 0, 0,
-                        wflags2);
-           ps2 = ps1;
-       }
-       Gnocallbacks = FALSE;
-       break;
+        Gnocallbacks = TRUE;
+        for (i = 0; i  < 2; i++) {
+            Gadjustwrect (parent, &ps1);
+            if (ps1.x > ps2.x || ps1.y > ps2.y)
+                SetWindowPos (
+                    widget->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1
+                );
+            GetClientRect (parent->w, &r);
+            ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
+            dx = max (0, ps1.x - ps2.x);
+            dy = max (0, ps1.y - ps2.y);
+            SetScrollRange (parent->w, SB_HORZ, 0, dx, TRUE);
+            SetScrollRange (parent->w, SB_VERT, 0, dy, TRUE);
+            po.x = GetScrollPos (parent->w, SB_HORZ);
+            po.y = GetScrollPos (parent->w, SB_VERT);
+            po.x = min (po.x, dx);
+            po.x = max (po.x, 0);
+            SetScrollPos (parent->w, SB_HORZ, po.x, TRUE);
+            po.y = min (po.y, dy);
+            po.y = max (po.y, 0);
+            SetScrollPos (parent->w, SB_VERT, po.y, TRUE);
+            SetWindowPos (widget->w, (HWND) NULL, -po.x, -po.y, 0, 0, wflags2);
+            ps2 = ps1;
+        }
+        Gnocallbacks = FALSE;
+        break;
     }
 
-  handlechildren:
+handlechildren:
     for (wi = 0; wi < Gwidgetn; wi++) {
-       child = &Gwidgets[wi];
-       if (child->inuse && child->pwi == widget - &Gwidgets[0])
-           break;
+        child = &Gwidgets[wi];
+        if (child->inuse && child->pwi == widget - &Gwidgets[0])
+            break;
     }
     if (wi == Gwidgetn)
-       return;
-    GetWindowRect(child->w, &r);
+        return;
+    GetWindowRect (child->w, &r);
     ps1.x = r.right - r.left, ps1.y = r.bottom - r.top;
     ps2 = ps1;
     switch (widget->type) {
     case G_VIEWWIDGET:
-       Gadjustwrect(widget, &ps1);
-       if (ps1.x != ps2.x || ps1.y != ps2.y)
-           SetWindowPos(child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y,
-                        wflags1);
-       break;
+        Gadjustwrect (widget, &ps1);
+        if (ps1.x != ps2.x || ps1.y != ps2.y)
+            SetWindowPos (child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
+        break;
     case G_ARRAYWIDGET:
-       Gawresize(widget);
-       break;
+        Gawresize (widget);
+        break;
     case G_SCROLLWIDGET:
-       Gadjustwrect(widget, &ps1);
-       if (ps1.x > ps2.x || ps1.y > ps2.y)
-           SetWindowPos(child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y,
-                        wflags1);
-       GetClientRect(widget->w, &r);
-       ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
-       dx = max(0, ps1.x - ps2.x);
-       dy = max(0, ps1.y - ps2.y);
-       SetScrollRange(widget->w, SB_HORZ, 0, dx, TRUE);
-       SetScrollRange(widget->w, SB_VERT, 0, dy, TRUE);
-       po.x = GetScrollPos(widget->w, SB_HORZ);
-       po.y = GetScrollPos(widget->w, SB_VERT);
-       po.x = min(po.x, dx);
-       po.x = max(po.x, 0);
-       SetScrollPos(widget->w, SB_HORZ, po.x, TRUE);
-       po.y = min(po.y, dy);
-       po.y = max(po.y, 0);
-       SetScrollPos(widget->w, SB_VERT, po.y, TRUE);
-       SetWindowPos(child->w, (HWND) NULL, -po.x, -po.y, 0, 0, wflags2);
-       break;
+        Gadjustwrect (widget, &ps1);
+        if (ps1.x > ps2.x || ps1.y > ps2.y)
+            SetWindowPos (child->w, (HWND) NULL, 0, 0, ps1.x, ps1.y, wflags1);
+        GetClientRect (widget->w, &r);
+        ps2.x = r.right - r.left, ps2.y = r.bottom - r.top;
+        dx = max (0, ps1.x - ps2.x);
+        dy = max (0, ps1.y - ps2.y);
+        SetScrollRange (widget->w, SB_HORZ, 0, dx, TRUE);
+        SetScrollRange (widget->w, SB_VERT, 0, dy, TRUE);
+        po.x = GetScrollPos (widget->w, SB_HORZ);
+        po.y = GetScrollPos (widget->w, SB_VERT);
+        po.x = min (po.x, dx);
+        po.x = max (po.x, 0);
+        SetScrollPos (widget->w, SB_HORZ, po.x, TRUE);
+        po.y = min (po.y, dy);
+        po.y = max (po.y, 0);
+        SetScrollPos (widget->w, SB_VERT, po.y, TRUE);
+        SetWindowPos (child->w, (HWND) NULL, -po.x, -po.y, 0, 0, wflags2);
+        break;
     }
 }