Tk Source Code

Check-in [f80ff0cf]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Commit changes received from René Zaumseil
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-510
Files: files | file ages | folders
SHA3-256: f80ff0cf9e4a01f25b16ebbf152ce9b42deb28d1ed6d228d4a16c4818fca9b26
User & Date: fvogel 2018-06-28 18:24:38
Context
2018-07-04
20:06
Commit changes received from René Zaumseil check-in: ac543027 user: fvogel tags: tip-510
2018-06-28
18:24
Commit changes received from René Zaumseil check-in: f80ff0cf user: fvogel tags: tip-510
2018-06-26
21:26
Bugfixes by René Zaumseil: TRUE and FALSE were undefined under Linux, and types were wrong in rbcTile.c check-in: 6b1b31ec user: fvogel tags: tip-510
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/rbc/rbcConfig.c.

1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
        Tk_ConfigureWidget(interp, tkwin, specsPtr, argc, argv, widgRec, flags);
    if (isTemporary) {
        Tk_DestroyWindow(tkwin);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcStringToEnum --
 *
 *      Converts the string into its enumerated type.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcStringToEnum(
    ClientData clientData,      /* Vectors of valid strings. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String to match. */
    char *widgRec,              /* Widget record. */
    int offset)
{                               /* Offset of field in record */
    int            *enumPtr = (int *) (widgRec + offset);
    char            c;
    register char **p;
    register int    i;
    int             count;

    c = string[0];
    count = 0;
    for (p = (char **) clientData; *p != NULL; p++) {
        if ((c == p[0][0]) && (strcmp(string, *p) == 0)) {
            *enumPtr = count;
            return TCL_OK;
        }
        count++;
    }
    *enumPtr = -1;

    Tcl_AppendResult(interp, "bad value \"", string, "\": should be ",
        (char *) NULL);
    p = (char **) clientData;
    if (count > 0) {
        Tcl_AppendResult(interp, p[0], (char *) NULL);
    }
    for (i = 1; i < (count - 1); i++) {
        Tcl_AppendResult(interp, " ", p[i], ", ", (char *) NULL);
    }
    if (count > 1) {
        Tcl_AppendResult(interp, " or ", p[count - 1], ".", (char *) NULL);
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcEnumToString --
 *
 *      Returns the string associated with the enumerated type.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
const char     *
RbcEnumToString(
    ClientData clientData,      /* List of strings. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget record */
    int offset,                 /* Offset of field in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             value = *(int *) (widgRec + offset);
    char          **p;
    int             count;

    count = 0;
    for (p = (char **) clientData; *p != NULL; p++) {
        count++;
    }
    if ((value >= count) || (value < 0)) {
        return "unknown value";
    }
    p = (char **) clientData;
    return p[value];
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

1356
1357
1358
1359
1360
1361
1362






























































































1363
        Tk_ConfigureWidget(interp, tkwin, specsPtr, argc, argv, widgRec, flags);
    if (isTemporary) {
        Tk_DestroyWindow(tkwin);
    }
    return result;
}































































































/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Changes to generic/rbc/rbcGrAxis.c.

2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
....
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
....
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
....
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
static void
DrawAxis(
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcAxis * axisPtr)
{
    if (axisPtr->border != NULL) {
        RbcFill3DRectangle(graphPtr->tkwin, drawable, axisPtr->border,
            axisPtr->region.left + graphPtr->plotBorderWidth,
            axisPtr->region.top + graphPtr->plotBorderWidth,
            axisPtr->region.right - axisPtr->region.left,
            axisPtr->region.bottom - axisPtr->region.top,
            axisPtr->borderWidth, axisPtr->relief);
    }
    if (axisPtr->title != NULL) {
................................................................................
                (char *) NULL);
            ckfree((char *) names);
            return TCL_ERROR;
        }
        if (axisPtr->linkPtr != NULL) {
            /* Move the axis from the old margin's "use" list to the new. */
            RbcChainUnlinkLink(axisPtr->chainPtr, axisPtr->linkPtr);
            RbcChainAppendLink(chainPtr, axisPtr->linkPtr);
        } else {
            axisPtr->linkPtr = RbcChainAppend(chainPtr, axisPtr);
        }
        axisPtr->chainPtr = chainPtr;
        axisPtr->flags |= AXIS_ONSCREEN;
    }
    graphPtr->flags |=
................................................................................
{
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    RbcDim2D        textDim;
    int             isHoriz;
    char           *minPtr, *maxPtr;
    char           *minFormat, *maxFormat;
    char            minString[200], maxString[200];
    int             vMin, hMin, vMax, hMax;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padX.side1 + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padY.side2 - 2;  /* Offsets */

................................................................................
{
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    double          vMin, hMin, vMax, hMax;
    char            string[200];
    int             textWidth, textHeight;
    char           *minFmt, *maxFmt;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padX.side1 + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padY.side2 - 2;  /* Offsets */
    for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.table, &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);






|







 







|







 







|







 







|







2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
....
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
....
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
....
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
static void
DrawAxis(
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcAxis * axisPtr)
{
    if (axisPtr->border != NULL) {
        Tk_Fill3DRectangle(graphPtr->tkwin, drawable, axisPtr->border,
            axisPtr->region.left + graphPtr->plotBorderWidth,
            axisPtr->region.top + graphPtr->plotBorderWidth,
            axisPtr->region.right - axisPtr->region.left,
            axisPtr->region.bottom - axisPtr->region.top,
            axisPtr->borderWidth, axisPtr->relief);
    }
    if (axisPtr->title != NULL) {
................................................................................
                (char *) NULL);
            ckfree((char *) names);
            return TCL_ERROR;
        }
        if (axisPtr->linkPtr != NULL) {
            /* Move the axis from the old margin's "use" list to the new. */
            RbcChainUnlinkLink(axisPtr->chainPtr, axisPtr->linkPtr);
            RbcChainLinkBefore(chainPtr, axisPtr->linkPtr, (RbcChainLink *)NULL);/* append on end */
        } else {
            axisPtr->linkPtr = RbcChainAppend(chainPtr, axisPtr);
        }
        axisPtr->chainPtr = chainPtr;
        axisPtr->flags |= AXIS_ONSCREEN;
    }
    graphPtr->flags |=
................................................................................
{
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    RbcDim2D        textDim;
    int             isHoriz;
    char           *minPtr, *maxPtr;
    const char     *minFormat, *maxFormat;
    char            minString[200], maxString[200];
    int             vMin, hMin, vMax, hMax;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padX.side1 + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padY.side2 - 2;  /* Offsets */

................................................................................
{
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    double          vMin, hMin, vMax, hMax;
    char            string[200];
    int             textWidth, textHeight;
    const char     *minFmt, *maxFmt;

#define SPACING 8
    vMin = vMax = graphPtr->left + graphPtr->padX.side1 + 2;
    hMin = hMax = graphPtr->bottom - graphPtr->padY.side2 - 2;  /* Offsets */
    for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.table, &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);

Changes to generic/rbc/rbcGrBar.c.

1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
....
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
        nRects);
    if ((penPtr->border != NULL) && (penPtr->borderWidth > 0) &&
        (penPtr->relief != TK_RELIEF_FLAT)) {
        XRectangle     *endPtr;

        for (rectPtr = rectangles, endPtr = rectangles + nRects;
            rectPtr < endPtr; rectPtr++) {
            RbcDraw3DRectangle(graphPtr->tkwin, drawable, penPtr->border,
                rectPtr->x, rectPtr->y, rectPtr->width, rectPtr->height,
                penPtr->borderWidth, penPtr->relief);
        }
    }
}

/*
................................................................................
 *      Memory is allocated for the bar element structure.
 *
 * ----------------------------------------------------------------------
 */
RbcElement     *
RbcBarElement(
    RbcGraph * graphPtr,
    char *name,
    RbcUid type)
{
    register Bar   *barPtr;

    barPtr = RbcCalloc(1, sizeof(Bar));
    assert(barPtr);
    barPtr->normalPenPtr = &(barPtr->builtinPen);






|







 







|







1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
....
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
        nRects);
    if ((penPtr->border != NULL) && (penPtr->borderWidth > 0) &&
        (penPtr->relief != TK_RELIEF_FLAT)) {
        XRectangle     *endPtr;

        for (rectPtr = rectangles, endPtr = rectangles + nRects;
            rectPtr < endPtr; rectPtr++) {
            Tk_Draw3DRectangle(graphPtr->tkwin, drawable, penPtr->border,
                rectPtr->x, rectPtr->y, rectPtr->width, rectPtr->height,
                penPtr->borderWidth, penPtr->relief);
        }
    }
}

/*
................................................................................
 *      Memory is allocated for the bar element structure.
 *
 * ----------------------------------------------------------------------
 */
RbcElement     *
RbcBarElement(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid type)
{
    register Bar   *barPtr;

    barPtr = RbcCalloc(1, sizeof(Bar));
    assert(barPtr);
    barPtr->normalPenPtr = &(barPtr->builtinPen);

Changes to generic/rbc/rbcGrLegd.c.

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
...
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
    symbolX = midX + legendPtr->ipadX.side1;

    pixmap = Tk_GetPixmap(graphPtr->display, Tk_WindowId(legendPtr->tkwin),
        width, height, Tk_Depth(legendPtr->tkwin));

    if (legendPtr->border != NULL) {
        /* Background color and relief. */
        RbcFill3DRectangle(legendPtr->tkwin, pixmap, legendPtr->border, 0, 0,
            width, height, 0, TK_RELIEF_FLAT);
    } else if (legendPtr->site & RBC_LEGEND_IN_PLOT) {
        /*
         * Legend background is transparent and is positioned over the
         * the plot area.  Either copy the part of the background from
         * the backing store pixmap or (if no backing store exists)
         * just fill it with the background color of the plot.
................................................................................
        linkPtr != NULL; linkPtr = RbcChainPrevLink(linkPtr)) {
        elemPtr = RbcChainGetValue(linkPtr);
        if (elemPtr->label == NULL) {
            continue;           /* Skip this entry */
        }
        if (elemPtr->flags & RBC_LABEL_ACTIVE) {
            legendPtr->style.state |= RBC_STATE_ACTIVE;
            RbcFill3DRectangle(legendPtr->tkwin, pixmap,
                legendPtr->activeBorder, x, y,
                legendPtr->style.width, legendPtr->style.height,
                legendPtr->entryBorderWidth, legendPtr->activeRelief);
        } else {
            legendPtr->style.state &= ~RBC_STATE_ACTIVE;
            if (elemPtr->labelRelief != TK_RELIEF_FLAT) {
                RbcDraw3DRectangle(legendPtr->tkwin, pixmap, graphPtr->border,
                    x, y, legendPtr->style.width, legendPtr->style.height,
                    legendPtr->entryBorderWidth, elemPtr->labelRelief);
            }
        }
        (*elemPtr->procsPtr->drawSymbolProc) (graphPtr, pixmap, elemPtr,
            x + symbolX, y + symbolY, symbolSize);
        RbcDrawText(legendPtr->tkwin, pixmap, elemPtr->label,
................................................................................
    /*
     * Draw the border and/or background of the legend.
     */
    border = legendPtr->border;
    if (border == NULL) {
        border = graphPtr->border;
    }
    RbcDraw3DRectangle(legendPtr->tkwin, pixmap, border, 0, 0, width, height,
        legendPtr->borderWidth, legendPtr->relief);

    XCopyArea(graphPtr->display, pixmap, drawable, graphPtr->drawGC, 0, 0,
        width, height, legendPtr->x, legendPtr->y);
    Tk_FreePixmap(graphPtr->display, pixmap);
}







|







 







|






|







 







|







886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
...
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
    symbolX = midX + legendPtr->ipadX.side1;

    pixmap = Tk_GetPixmap(graphPtr->display, Tk_WindowId(legendPtr->tkwin),
        width, height, Tk_Depth(legendPtr->tkwin));

    if (legendPtr->border != NULL) {
        /* Background color and relief. */
        Tk_Fill3DRectangle(legendPtr->tkwin, pixmap, legendPtr->border, 0, 0,
            width, height, 0, TK_RELIEF_FLAT);
    } else if (legendPtr->site & RBC_LEGEND_IN_PLOT) {
        /*
         * Legend background is transparent and is positioned over the
         * the plot area.  Either copy the part of the background from
         * the backing store pixmap or (if no backing store exists)
         * just fill it with the background color of the plot.
................................................................................
        linkPtr != NULL; linkPtr = RbcChainPrevLink(linkPtr)) {
        elemPtr = RbcChainGetValue(linkPtr);
        if (elemPtr->label == NULL) {
            continue;           /* Skip this entry */
        }
        if (elemPtr->flags & RBC_LABEL_ACTIVE) {
            legendPtr->style.state |= RBC_STATE_ACTIVE;
            Tk_Fill3DRectangle(legendPtr->tkwin, pixmap,
                legendPtr->activeBorder, x, y,
                legendPtr->style.width, legendPtr->style.height,
                legendPtr->entryBorderWidth, legendPtr->activeRelief);
        } else {
            legendPtr->style.state &= ~RBC_STATE_ACTIVE;
            if (elemPtr->labelRelief != TK_RELIEF_FLAT) {
                Tk_Draw3DRectangle(legendPtr->tkwin, pixmap, graphPtr->border,
                    x, y, legendPtr->style.width, legendPtr->style.height,
                    legendPtr->entryBorderWidth, elemPtr->labelRelief);
            }
        }
        (*elemPtr->procsPtr->drawSymbolProc) (graphPtr, pixmap, elemPtr,
            x + symbolX, y + symbolY, symbolSize);
        RbcDrawText(legendPtr->tkwin, pixmap, elemPtr->label,
................................................................................
    /*
     * Draw the border and/or background of the legend.
     */
    border = legendPtr->border;
    if (border == NULL) {
        border = graphPtr->border;
    }
    Tk_Draw3DRectangle(legendPtr->tkwin, pixmap, border, 0, 0, width, height,
        legendPtr->borderWidth, legendPtr->relief);

    XCopyArea(graphPtr->display, pixmap, drawable, graphPtr->drawGC, 0, 0,
        width, height, legendPtr->x, legendPtr->y);
    Tk_FreePixmap(graphPtr->display, pixmap);
}

Changes to generic/rbc/rbcGrLine.c.

5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
 *      Memory is allocated for the line element structure.
 *
 *----------------------------------------------------------------------
 */
RbcElement *
RbcLineElement(
    RbcGraph *graphPtr,
    char *name,
    RbcUid classUid)
{
    register Line *linePtr;
    linePtr = RbcCalloc(1, sizeof(Line));
    assert(linePtr);
    linePtr->procsPtr = &lineProcs;
    if (classUid == rbcLineElementUid) {






|







5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
 *      Memory is allocated for the line element structure.
 *
 *----------------------------------------------------------------------
 */
RbcElement *
RbcLineElement(
    RbcGraph *graphPtr,
    const char *name,
    RbcUid classUid)
{
    register Line *linePtr;
    linePtr = RbcCalloc(1, sizeof(Line));
    assert(linePtr);
    linePtr->procsPtr = &lineProcs;
    if (classUid == rbcLineElementUid) {

Changes to generic/rbc/rbcGrMarker.c.

2477
2478
2479
2480
2481
2482
2483

2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
....
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
DrawImageMarker(
    RbcMarker * markerPtr,
    Drawable drawable)
{                               /* Pixmap or window to draw into */
    ImageMarker    *imPtr = (ImageMarker *) markerPtr;
    int             width, height;


    if ((imPtr->tkImage == NULL) || (Tk_ImageIsDeleted(imPtr->tkImage))) {
        return;
    }
    if (imPtr->pixmap == None) {
        Pixmap          pixmap;
        Tk_Image        tkImage;

        tkImage = (imPtr->tmpImage != NULL) ? imPtr->tmpImage : imPtr->tkImage;
        Tk_SizeOfImage(tkImage, &width, &height);
        /* pixmap = Tk_ImageGetPhotoPixmap(tkImage); */
        pixmap = None;
        if (pixmap == None) {   /* May not be a "photo" image. */
            Tk_RedrawImage(tkImage, 0, 0, width, height, drawable,
                (int) imPtr->anchorPos.x, (int) imPtr->anchorPos.y);
        } else {
            XCopyArea(imPtr->graphPtr->display, pixmap, drawable,
                imPtr->gc, 0, 0, width, height, (int) imPtr->anchorPos.x,
................................................................................
    RbcMarker * markerPtr,      /* Marker to be printed */
    RbcPsToken * psToken)
{
    ImageMarker    *imPtr = (ImageMarker *) markerPtr;
    const char     *imageName;
    Tk_PhotoHandle  photo;

    if ((imPtr->tkImage == NULL) || (Tk_ImageIsDeleted(imPtr->tkImage))) {
        return;                 /* Image doesn't exist anymore */
    }
    imageName = (imPtr->tmpImage == NULL)
        ? RbcNameOfImage(imPtr->tkImage) : RbcNameOfImage(imPtr->tmpImage);
    photo = Tk_FindPhoto(markerPtr->graphPtr->interp, imageName);
    if (photo == NULL) {
        return;                 /* Image isn't a photo image */






>
|








<







 







|







2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493

2494
2495
2496
2497
2498
2499
2500
....
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
DrawImageMarker(
    RbcMarker * markerPtr,
    Drawable drawable)
{                               /* Pixmap or window to draw into */
    ImageMarker    *imPtr = (ImageMarker *) markerPtr;
    int             width, height;

    /* check if image still exists */
    if ((imPtr->tkImage == NULL) || (RbcImageIsDeleted(imPtr->tkImage))) {
        return;
    }
    if (imPtr->pixmap == None) {
        Pixmap          pixmap;
        Tk_Image        tkImage;

        tkImage = (imPtr->tmpImage != NULL) ? imPtr->tmpImage : imPtr->tkImage;
        Tk_SizeOfImage(tkImage, &width, &height);

        pixmap = None;
        if (pixmap == None) {   /* May not be a "photo" image. */
            Tk_RedrawImage(tkImage, 0, 0, width, height, drawable,
                (int) imPtr->anchorPos.x, (int) imPtr->anchorPos.y);
        } else {
            XCopyArea(imPtr->graphPtr->display, pixmap, drawable,
                imPtr->gc, 0, 0, width, height, (int) imPtr->anchorPos.x,
................................................................................
    RbcMarker * markerPtr,      /* Marker to be printed */
    RbcPsToken * psToken)
{
    ImageMarker    *imPtr = (ImageMarker *) markerPtr;
    const char     *imageName;
    Tk_PhotoHandle  photo;

    if ((imPtr->tkImage == NULL) || (RbcImageIsDeleted(imPtr->tkImage))) {
        return;                 /* Image doesn't exist anymore */
    }
    imageName = (imPtr->tmpImage == NULL)
        ? RbcNameOfImage(imPtr->tkImage) : RbcNameOfImage(imPtr->tmpImage);
    photo = Tk_FindPhoto(markerPtr->graphPtr->interp, imageName);
    if (photo == NULL) {
        return;                 /* Image isn't a photo image */

Changes to generic/rbc/rbcGrMisc.c.

1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
int
RbcMaxRequestSize(
    Display * display,
    unsigned int elemSize)
{
    long            size;

#ifdef HAVE_XEXTENDEDMAXREQUESTSIZE
    size = XExtendedMaxRequestSize(display);
    if (size == 0) {
        size = XMaxRequestSize(display);
    }
#else
    size = XMaxRequestSize(display);
#endif
    size -= 4;
    return ((size * 4) / elemSize);
}

#undef RbcFill3DRectangle

/*
 *----------------------------------------------------------------------
 *
 * RbcFill3DRectangle --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcFill3DRectangle(
    Tk_Window tkwin,            /* Window for which border was allocated. */
    Drawable drawable,          /* X window or pixmap in which to draw. */
    Tk_3DBorder border,         /* Token for border to draw. */
    int x,                      /* Outside area of rectangular region. */
    int y,                      /* Outside area of rectangular region. */
    int width,                  /* Outside area of rectangular region. */
    int height,                 /* Outside area of rectangular region. */
    int borderWidth,            /* Desired width for border, in
                                 * pixels. Border will be *inside* region. */
    int relief)
{                               /* Indicates 3D effect: TK_RELIEF_FLAT,
                                 * TK_RELIEF_RAISED, or TK_RELIEF_SUNKEN. */
#ifndef notdef
    if ((borderWidth > 1) && (width > 2) && (height > 2) &&
        ((relief == TK_RELIEF_SUNKEN) || (relief == TK_RELIEF_RAISED))) {
        GC              lightGC, darkGC;
        int             x2, y2;

        x2 = x + width - 1;
        y2 = y + height - 1;
#define TK_3D_LIGHT2_GC TK_3D_DARK_GC+1
#define TK_3D_DARK2_GC TK_3D_DARK_GC+2
        if (relief == TK_RELIEF_RAISED) {
            lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#ifdef _WIN32
            darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
            darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
        } else {
#ifdef _WIN32
            lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
            lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
            darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
        }
        XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x2, y);
        XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x2, y);
        XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x, y2);
        XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x, y2);
        x++, y++, width -= 2, height -= 2, borderWidth--;
    }
#endif
    Tk_Fill3DRectangle(tkwin, drawable, border, x, y, width, height,
        borderWidth, relief);
}

#undef RbcDraw3DRectangle

/*
 *----------------------------------------------------------------------
 *
 * RbcDraw3DRectangle --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcDraw3DRectangle(
    Tk_Window tkwin,            /* Window for which border was allocated. */
    Drawable drawable,          /* X window or pixmap in which to draw. */
    Tk_3DBorder border,         /* Token for border to draw. */
    int x,                      /* Outside area of rectangular region. */
    int y,                      /* Outside area of rectangular region. */
    int width,                  /* Outside area of rectangular region. */
    int height,                 /* Outside area of rectangular region. */
    int borderWidth,            /* Desired width for border, in
                                 * pixels. Border will be *inside* region. */
    int relief)
{                               /* Indicates 3D effect: TK_RELIEF_FLAT,
                                 * TK_RELIEF_RAISED, or TK_RELIEF_SUNKEN. */
#ifndef notdef
    if ((borderWidth > 1) && (width > 2) && (height > 2) &&
        ((relief == TK_RELIEF_SUNKEN) || (relief == TK_RELIEF_RAISED))) {
        GC              lightGC, darkGC;
        int             x2, y2;

        x2 = x + width - 1;
        y2 = y + height - 1;
        if (relief == TK_RELIEF_RAISED) {
            lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
#ifdef _WIN32
            darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
#else
            darkGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
        } else {
#ifdef _WIN32
            lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
#else
            lightGC = DefaultGC(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
#endif
            darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
        }
        XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x2, y);
        XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x2, y);
        XDrawLine(Tk_Display(tkwin), drawable, darkGC, x2, y2, x, y2);
        XDrawLine(Tk_Display(tkwin), drawable, lightGC, x, y, x, y2);
        x++, y++, width -= 2, height -= 2, borderWidth--;
    }
#endif
    Tk_Draw3DRectangle(tkwin, drawable, border, x, y, width, height,
        borderWidth, relief);
}

#ifdef notdef
typedef struct {
    Screen         *screen;
    Visual         *visual;
    Colormap        colormap;
    Tk_Uid          nameUid;
} BorderKey;

typedef struct {
    Screen         *screen;     /* Screen on which the border will be used. */
    Visual         *visual;     /* Visual for all windows and pixmaps using
                                 * the border. */
    int             depth;      /* Number of bits per pixel of drawables where
                                 * the border will be used. */
    Colormap        colormap;   /* Colormap out of which pixels are
                                 * allocated. */
    int             refCount;   /* Number of active uses of this color
                                 * (each active use corresponds to a
                                 * call to RbcGet3DBorder).  If this
                                 * count is 0, then this structure is
                                 * no longer valid and it isn't
                                 * present in borderTable: it is being
                                 * kept around only because there are
                                 * objects referring to it.  The
                                 * structure is freed when refCount is
                                 * 0. */
    XColor         *bgColorPtr; /* Color of face. */
    XColor         *shadows[4];
    Pixmap          darkStipple;        /* Stipple pattern to use for drawing
                                         * shadows areas.  Used for displays with
                                         * <= 64 colors or where colormap has filled
                                         * up. */
    Pixmap          lightStipple;       /* Stipple pattern to use for drawing
                                         * shadows areas.  Used for displays with
                                         * <= 64 colors or where colormap has filled
                                         * up. */
    GC              bgGC;       /* Used (if necessary) to draw areas in
                                 * the background color. */
    GC              lightGC, darkGC;
    Tcl_HashEntry  *hashPtr;    /* Entry in borderTable (needed in
                                 * order to delete structure). */
    struct Rbc3DBorderStruct *nextPtr;
} Border       ,
               *Rbc3DBorder;

/*
 *----------------------------------------------------------------------
 *
 * RbcDraw3DRectangle --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcDraw3DRectangle(
    Tk_Window tkwin,            /* Window for which border was allocated. */
    Drawable drawable,          /* X window or pixmap in which to draw. */
    Rbc3DBorder * borderPtr,    /* Border to draw. */
    int x,                      /* Outside area of rectangular region. */
    int y,                      /* Outside area of rectangular region. */
    int width,                  /* Outside area of rectangular region. */
    int height,                 /* Outside area of rectangular region. */
    int borderWidth,            /* Desired width for border, in
                                 * pixels. Border will be *inside* region. */
    int relief)
{                               /* Indicates 3D effect: TK_RELIEF_FLAT,
                                 * TK_RELIEF_RAISED, or TK_RELIEF_SUNKEN. */
    if ((width > (2 * borderWidth)) && (height > (2 * borderWidth))) {
        int             x2, y2;
        int             i;

        x2 = x + width - 1;
        y2 = y + height - 1;

        XSetForeground(borderPtr->lightGC, borderPtr->shadows[0]);
        XSetForeground(borderPtr->darkGC, borderPtr->shadows[3]);
        XDrawLine(Tk_Display(tkwin), drawable, borderPtr->lightGC, x, y, x2, y);
        XDrawLine(Tk_Display(tkwin), drawable, borderPtr->lightGC, x, y, x, y2);
        XDrawLine(Tk_Display(tkwin), drawable, borderPtr->darkGC,
            x2, y, x2, y2);
        XDrawLine(Tk_Display(tkwin), drawable, borderPtr->darkGC,
            x2, y2, x, y2);
        XSetForeground(borderPtr->lightGC, borderPtr->shadows[1]);
        XSetForeground(borderPtr->darkGC, borderPtr->shadows[2]);
        for (i = 1; i < (borderWidth - 1); i++) {

            /*
             *  +---------
             *  |+-------
             *  ||+-----
             *  |||
             *  |||
             *  ||
             *  |
             */
            x++, y++, x2--, y2--;
            XDrawLine(Tk_Display(tkwin), drawable, borderPtr->lightGC,
                x, y, x2, y);
            XDrawLine(Tk_Display(tkwin), drawable, borderPtr->lightGC,
                x, y, x, y2);
            XDrawLine(Tk_Display(tkwin), drawable, borderPtr->darkGC,
                x2, y, x2, y2);
            XDrawLine(Tk_Display(tkwin), drawable, borderPtr->darkGC,
                x2, y2, x, y2);
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcFill3DRectangle --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcFill3DRectangle(
    Tk_Window tkwin,            /* Window for which border was allocated. */
    Drawable drawable,          /* X window or pixmap in which to draw. */
    Tk_3DBorder border,         /* Token for border to draw. */
    int x,                      /* Outside area of rectangular region. */
    int y,                      /* Outside area of rectangular region. */
    int width,                  /* Outside area of rectangular region. */
    int height,                 /* Outside area of rectangular region. */
    int borderWidth,            /* Desired width for border, in
                                 * pixels. Border will be *inside* region. */
    int relief)
{                               /* Indicates 3D effect: TK_RELIEF_FLAT,
                                 * TK_RELIEF_RAISED, or TK_RELIEF_SUNKEN. */
    Rbc3DBorder    *borderPtr;

    XFillRectangle(Tk_Display(tkwin), drawable, borderPtr->bgGC, x, y, width,
        height);
    if ((borderWidth > 0) && (relief != TK_RELIEF_FLAT)) {
        RbcDraw3DRectangle(tkwin, drawable, borderPtr, x, y, width, height,
            borderWidth, relief);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * FreeBorder --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
FreeBorder(
    Display * display,
    Border * borderPtr)
{
    int             i;

    if (borderPtr->bgColorPtr != NULL) {
        Tk_FreeColor(display, borderPtr->bgColorPtr);
    }
    for (i = 0; i < 4; i++) {
        Tk_FreeColor(display, borderPtr->shadows[i]);
    }
    if (borderPtr->tile != NULL) {
        RbcFreeTile(tile);
    }
    if (borderPtr->darkGC != NULL) {
        RbcFreePrivateGC(display, borderPtr->darkGC);
    }
    if (borderPtr->lightGC != NULL) {
        RbcFreePrivateGC(tkwin, borderPtr->lightGC);
    }
    if (borderPtr->bgGC != NULL) {
        RbcFreePrivateGC(tkwin, borderPtr->bgGC);
    }
    ckree((char *) borderPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcFree3DBorder --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcFree3DBorder(
    Display * display,
    Rbc3DBorder border)
{
    Border         *borderPtr = (Border *) border;

    borderPtr->refCount--;
    if (borderPtr->refCount >= 0) {
        /* Search for the border in the bucket. Start at the head. */
        headPtr = Tcl_GetHashValue(borderPtr->hashPtr);
        lastPtr = NULL;
        while ((headPtr != borderPtr) && (headPtr != NULL)) {
            lastPtr = headPtr;
            headPtr = headPtr->next;
        }
        if (headPtr == NULL) {
            return;             /* This can't happen. It means that
                                 * we could not find the border. */
        }
        if (lastPtr != NULL) {
            lastPtr->next = borderPtr->next;
        } else {
            Tcl_DeleteHashEntry(borderPtr->hashPtr);
        }
        FreeBorder(display, borderPtr);
    }
}

#define SetColor(c,r,g,b) ((c)->red = (int)((r) * 65535.0), \
			   (c)->green = (int)((g) * 65535.0), \
			   (c)->blue = (int)((b) * 65535.0))

/*
 *----------------------------------------------------------------------
 *
 * XColorToHSV --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
XColorToHSV(
    XColor * colorPtr,
    HSV * hsvPtr)
{
    unsigned short  max, min;
    double          range;
    unsigned short *colorValues;

    /* Find the minimum and maximum RGB intensities */
    colorValues = (unsigned short *) &colorPtr->red;
    max = MAX3(colorValues[0], colorValues[1], colorValues[2]);
    min = MIN3(colorValues[0], colorValues[1], colorValues[2]);

    hsvPtr->val = (double) max / 65535.0;
    hsvPtr->hue = hsvPtr->sat = 0.0;

    range = (double) (max - min);
    if (max != min) {
        hsvPtr->sat = range / (double) max;
    }
    if (hsvPtr->sat > 0.0) {
        double          red, green, blue;

        /* Normalize the RGB values */
        red = (double) (max - colorPtr->red) / range;
        green = (double) (max - colorPtr->green) / range;
        blue = (double) (max - colorPtr->blue) / range;

        if (colorPtr->red == max) {
            hsvPtr->hue = (blue - green);
        } else if (colorPtr->green == max) {
            hsvPtr->hue = 2 + (red - blue);
        } else if (colorPtr->blue == max) {
            hsvPtr->hue = 4 + (green - red);
        }
        hsvPtr->hue *= 60.0;
    } else {
        hsvPtr->sat = 0.5;
    }
    if (hsvPtr->hue < 0.0) {
        hsvPtr->hue += 360.0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * HSVToXColor --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
HSVToXColor(
    HSV * hsvPtr,
    XColor * colorPtr)
{
    double          hue, p, q, t;
    double          frac;
    int             quadrant;

    if (hsvPtr->val < 0.0) {
        hsvPtr->val = 0.0;
    } else if (hsvPtr->val > 1.0) {
        hsvPtr->val = 1.0;
    }
    if (hsvPtr->sat == 0.0) {
        SetColor(colorPtr, hsvPtr->val, hsvPtr->val, hsvPtr->val);
        return;
    }
    hue = FMOD(hsvPtr->hue, 360.0) / 60.0;
    quadrant = (int) floor(hue);
    frac = hsvPtr->hue - quadrant;
    p = hsvPtr->val * (1 - (hsvPtr->sat));
    q = hsvPtr->val * (1 - (hsvPtr->sat * frac));
    t = hsvPtr->val * (1 - (hsvPtr->sat * (1 - frac)));

    switch (quadrant) {
    case 0:
        SetColor(colorPtr, hsvPtr->val, t, p);
        break;
    case 1:
        SetColor(colorPtr, q, hsvPtr->val, p);
        break;
    case 2:
        SetColor(colorPtr, p, hsvPtr->val, t);
        break;
    case 3:
        SetColor(colorPtr, p, q, hsvPtr->val);
        break;
    case 4:
        SetColor(colorPtr, t, p, hsvPtr->val);
        break;
    case 5:
        SetColor(colorPtr, hsvPtr->val, p, q);
        break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGet3DBorder --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
Rbc3DBorder    *
RbcGet3DBorder(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    char *borderName)
{
    Rbc3DBorder    *borderPtr, *lastBorderPtr;
    Tcl_HashEntry  *hPtr;
    RbcTile         tile;
    XColor         *bgColorPtr;
    char          **argv;
    char           *colorName;
    int             argc;
    int             isNew;

    lastBorderPtr = NULL;
    hPtr = Tcl_CreateHashEntry(&dataPtr->borderTable, borderName, &isNew);
    if (!isNew) {
        borderPtr = lastBorderPtr = Tcl_GetHashValue(hPtr);
        while (borderPtr != NULL) {
            if ((Tk_Screen(tkwin) == borderPtr->screen) &&
                (Tk_Colormap(tkwin) == borderPtr->colormap)) {
                borderPtr->refCount++;
                return borderPtr;
            }
            borderPtr = borderPtr->nextPtr;
        }
    }
    /* Create a new border. */
    argv = NULL;
    bgColorPtr = NULL;
    tile = NULL;

    if (Tcl_SplitList(interp, borderName, &argc, &argv) != TCL_OK) {
        goto error;
    }
    colorName = borderName;
    if ((argc == 2) && (RbcGetTile(interp, tkwin, argv[0], &tile) == TCL_OK)) {
        colorName = argv[1];
    }
    bgColorPtr = Tk_GetColor(interp, tkwin, colorName);
    if (bgColorPtr == NULL) {
        goto error;
    }

    /* Create a new border */
    borderPtr = RbcCalloc(1, sizeof(Rbc3DBorder));
    assert(borderPtr);
    borderPtr->screen = Tk_Screen(tkwin);
    borderPtr->visual = Tk_Visual(tkwin);
    borderPtr->depth = Tk_Depth(tkwin);
    borderPtr->colormap = Tk_Colormap(tkwin);
    borderPtr->refCount = 1;
    borderPtr->bgColorPtr = bgColorPtr;
    borderPtr->tile = tile;
    borderPtr->darkGC = RbcGetPrivateGC(tkwin, 0, NULL);
    borderPtr->lightGC = RbcGetPrivateGC(tkwin, 0, NULL);
    borderPtr->hashPtr = lastBorderPtr->hashPtr;
    lastBorderPtr->nextPtr = lastBorderPtr;
    {
        HSV             hsv;
        XColor          color;
        double          sat, sat0, diff, step, hstep;
        int             count;

        /* Convert the face (background) color to HSV */
        XColorToHSV(borderPtr->bgColorPtr, &hsv);

        /* Using the color as the baseline intensity, pick a set of
         * colors around the intensity. */
#define UFLOOR(x,u)		(floor((x)*(u))/(u))
        diff = hsv.sat - UFLOOR(hsv.sat, 0.2);
        sat = 0.1 + (diff - 0.1);
        sat0 = hsv.sat;
        count = 0;
        for (sat = 0.1 + (diff - 0.1); sat <= 1.0; sat += 0.2) {
            if (FABS(sat0 - sat) >= 0.1) {
                hsv.sat = sat;
                HSVToXColor(&hsv, &color);
                borderPtr->shadows[count] = Tk_GetColorByValue(tkwin, &color);
                count++;
            }
        }
    }
    Tcl_SetHashValue(hPtr, borderPtr);
    if (argv != NULL) {
        ckfree((char *) argv);
    }
    return TCL_OK;

  error:
    if (argv != NULL) {
        ckfree((char *) argv);
    }
    if (tile != NULL) {
        RbcFreeTile(tile);
    }
    if (bgColorPtr != NULL) {
        Tk_FreeColor(bgColorPtr);
    }
    if (isNew) {
        Tcl_DeleteHashEntry(&borderTable, hPtr);
    }
    return NULL;
}

#endif

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */






|
<
<
<
<
<
<
<




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

1533
1534
1535
1536
1537
1538
1539
1540







1541
1542
1543
1544














































































































































































































































































































































































































































































































































































































































1545
int
RbcMaxRequestSize(
    Display * display,
    unsigned int elemSize)
{
    long            size;

    size = SHRT_MAX / 4;/* XMaxRequestSize emulation */







    size -= 4;
    return ((size * 4) / elemSize);
}















































































































































































































































































































































































































































































































































































































































/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Changes to generic/rbc/rbcGrPs.c.

98
99
100
101
102
103
104

105
106
107
108
109
110
111
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    {TK_CONFIG_CUSTOM, "-width", "width", "Width",
            DEF_PS_WIDTH, Tk_Offset(RbcPostScript, reqWidth),
        TK_CONFIG_DONT_SET_DEFAULT, &rbcDistanceOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

/* TODO: These do not belong here */

extern void     RbcMarkersToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    int under);
extern void     RbcElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
................................................................................
    RbcPsToken * psToken);
extern void     RbcAxesToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
extern void     RbcAxisLimitsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);

static const char *NameOfColorMode(
    RbcPsColorMode colorMode);
static int      CgetOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);






>







 







|







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    {TK_CONFIG_CUSTOM, "-width", "width", "Width",
            DEF_PS_WIDTH, Tk_Offset(RbcPostScript, reqWidth),
        TK_CONFIG_DONT_SET_DEFAULT, &rbcDistanceOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

/* TODO: These do not belong here */
/*
extern void     RbcMarkersToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    int under);
extern void     RbcElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
................................................................................
    RbcPsToken * psToken);
extern void     RbcAxesToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
extern void     RbcAxisLimitsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
*/
static const char *NameOfColorMode(
    RbcPsColorMode colorMode);
static int      CgetOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);

Changes to generic/rbc/rbcGraph.c.

2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
....
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
        x = graphPtr->left - graphPtr->plotBorderWidth;
        y = graphPtr->top - graphPtr->plotBorderWidth;
        width = (graphPtr->right - graphPtr->left) +
            (2 * graphPtr->plotBorderWidth);
        height = (graphPtr->bottom - graphPtr->top) +
            (2 * graphPtr->plotBorderWidth);
        RbcDraw3DRectangle(graphPtr->tkwin, drawable, graphPtr->border, x, y,
            width, height, graphPtr->plotBorderWidth, graphPtr->plotRelief);
    }
    if (RbcLegendSite(graphPtr->legend) & RBC_LEGEND_IN_MARGIN) {
        /* Legend is drawn on one of the graph margins */
        RbcDrawLegend(graphPtr->legend, drawable);
    }
    if (graphPtr->title != NULL) {
................................................................................
    }
    if ((RbcLegendSite(graphPtr->legend) & RBC_LEGEND_IN_PLOT) &&
        (RbcLegendIsRaised(graphPtr->legend))) {
        RbcDrawLegend(graphPtr->legend, drawable);
    }
    /* Draw 3D border just inside of the focus highlight ring. */
    if ((graphPtr->borderWidth > 0) && (graphPtr->relief != TK_RELIEF_FLAT)) {
        RbcDraw3DRectangle(graphPtr->tkwin, drawable, graphPtr->border,
            graphPtr->highlightWidth, graphPtr->highlightWidth,
            graphPtr->width - 2 * graphPtr->highlightWidth,
            graphPtr->height - 2 * graphPtr->highlightWidth,
            graphPtr->borderWidth, graphPtr->relief);
    }
    /* Draw focus highlight ring. */
    if ((graphPtr->highlightWidth > 0) && (graphPtr->flags & RBC_GRAPH_FOCUS)) {






|







 







|







2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
....
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
        x = graphPtr->left - graphPtr->plotBorderWidth;
        y = graphPtr->top - graphPtr->plotBorderWidth;
        width = (graphPtr->right - graphPtr->left) +
            (2 * graphPtr->plotBorderWidth);
        height = (graphPtr->bottom - graphPtr->top) +
            (2 * graphPtr->plotBorderWidth);
        Tk_Draw3DRectangle(graphPtr->tkwin, drawable, graphPtr->border, x, y,
            width, height, graphPtr->plotBorderWidth, graphPtr->plotRelief);
    }
    if (RbcLegendSite(graphPtr->legend) & RBC_LEGEND_IN_MARGIN) {
        /* Legend is drawn on one of the graph margins */
        RbcDrawLegend(graphPtr->legend, drawable);
    }
    if (graphPtr->title != NULL) {
................................................................................
    }
    if ((RbcLegendSite(graphPtr->legend) & RBC_LEGEND_IN_PLOT) &&
        (RbcLegendIsRaised(graphPtr->legend))) {
        RbcDrawLegend(graphPtr->legend, drawable);
    }
    /* Draw 3D border just inside of the focus highlight ring. */
    if ((graphPtr->borderWidth > 0) && (graphPtr->relief != TK_RELIEF_FLAT)) {
        Tk_Draw3DRectangle(graphPtr->tkwin, drawable, graphPtr->border,
            graphPtr->highlightWidth, graphPtr->highlightWidth,
            graphPtr->width - 2 * graphPtr->highlightWidth,
            graphPtr->height - 2 * graphPtr->highlightWidth,
            graphPtr->borderWidth, graphPtr->relief);
    }
    /* Draw focus highlight ring. */
    if ((graphPtr->highlightWidth > 0) && (graphPtr->flags & RBC_GRAPH_FOCUS)) {

Changes to generic/rbc/rbcImage.c.

3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
....
3363
3364
3365
3366
3367
3368
3369






















3370


3371
3372

3373
3374

3375
3376
3377
    XImage         *imagePtr;   /* Image structure for converted pixels. */
    XVisualInfo     visualInfo; /* Information about the visual that these
                                 * windows are using. */
    GC              gc;         /* Graphics context for writing images
                                 * to the pixmap. */
} TkPhotoInstance;

/*
 * ----------------------------------------------------------------------
 *
 * Tk_ImageDeleted --
 *
 *      Is there any other way to determine if an image has been
 *      deleted?
 *
 * Results:
 *      Returns 1 if the image has been deleted, 0 otherwise.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
int
Tk_ImageIsDeleted(
    Tk_Image tkImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) tkImage;

    if (imagePtr->masterPtr == NULL) {
        return TRUE;
    }
    return (imagePtr->masterPtr->typePtr == NULL);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_ImageGetMaster --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
Tk_ImageMaster
Tk_ImageGetMaster(
    Tk_Image tkImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) tkImage;

    return (Tk_ImageMaster) imagePtr->masterPtr;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_ImageGetType --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
Tk_ImageType   *
Tk_ImageGetType(
    Tk_Image tkImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) tkImage;

    return imagePtr->masterPtr->typePtr;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_ImageGetPhotoPixmap --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
Pixmap
Tk_ImageGetPhotoPixmap(
    Tk_Image tkImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) tkImage;

    if (strcmp(imagePtr->masterPtr->typePtr->name, "photo") == 0) {
        TkPhotoInstance *instPtr = (TkPhotoInstance *) imagePtr->instanceData;
        return instPtr->pixels;
    }
    return None;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_ImageGetPhotoGC --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
GC
Tk_ImageGetPhotoGC(
    Tk_Image photoImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) photoImage;
    if (strcmp(imagePtr->masterPtr->typePtr->name, "photo") == 0) {
        TkPhotoInstance *instPtr = (TkPhotoInstance *) imagePtr->instanceData;
        return instPtr->gc;
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TempImageChangedProc
 *
 *      The image is over-written each time it's resized.  We always
 *      resample from the color image we saved when the photo image
................................................................................
 *
 *--------------------------------------------------------------
 */
const char     *
RbcNameOfImage(
    Tk_Image tkImage)
{






















    Tk_ImageMaster  master;



    master = Tk_ImageGetMaster(tkImage);

    return Tk_NameOfImage(master);
}



/* vim: set ts=4 sw=4 sts=4 ff=unix et : */






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>

<
>
|
|
>
|


3118
3119
3120
3121
3122
3123
3124



































































































































3125
3126
3127
3128
3129
3130
3131
....
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264

3265
3266
3267
3268
3269
3270
3271
    XImage         *imagePtr;   /* Image structure for converted pixels. */
    XVisualInfo     visualInfo; /* Information about the visual that these
                                 * windows are using. */
    GC              gc;         /* Graphics context for writing images
                                 * to the pixmap. */
} TkPhotoInstance;




































































































































/*
 *----------------------------------------------------------------------
 *
 * TempImageChangedProc
 *
 *      The image is over-written each time it's resized.  We always
 *      resample from the color image we saved when the photo image
................................................................................
 *
 *--------------------------------------------------------------
 */
const char     *
RbcNameOfImage(
    Tk_Image tkImage)
{
    TkImage *imagePtr = (TkImage *) tkImage;
    return Tk_NameOfImage((Tk_ImageMaster) imagePtr->masterPtr);
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcImageDeleted --
 *
 *      Is there any other way to determine if an image has been
 *      deleted?
 *
 * Results:
 *      Returns 1 if the image has been deleted, 0 otherwise.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
int
RbcImageIsDeleted(
    Tk_Image tkImage)
{                               /* Token for image. */
    TkImage        *imagePtr = (TkImage *) tkImage;


    if (imagePtr->masterPtr == NULL) {
        return TRUE;
    }
    return (imagePtr->masterPtr->typePtr == NULL);
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Changes to generic/rbc/rbcInt.h.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
...
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
....
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
....
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
....
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
....
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870

1871
1872

1873
1874

1875

1876

1877
1878
1879
1880
1881



















1882
1883
1884
1885
1886
1887





1888
1889
1890
1891
1892
1893
1894
1895






1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907








1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968






1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082

2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149









2150
2151
2152






2153
2154



2155


2156
2157
2158





























2159
2160















2161




2162



















2163
2164















2165












2166
2167





2168






































2169
2170

2171
2172



































2173
2174

2175
2176
2177
2178












2179


































2180









2181
2182





2183
2184
2185
2186
2187




2188



2189
2190
2191















2192
2193
















2194
2195
2196
2197
2198
2199
2200
....
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312

2313
2314


2315
2316
2317
2318
2319
2320
2321
....
2324
2325
2326
2327
2328
2329
2330








2331
2332
2333
2334
2335
2336
2337
....
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369







2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400

2401

2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554

2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645

2646
2647
2648
2649

2650
2651
2652
2653
2654
2655

2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681



2682
2683
2684
2685
2686
2687



2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698

2699
2700
2701
2702
2703
2704

2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718

2719
2720
2721
2722
2723
2724
2725
2726
2727
2728

2729
2730
2731
2732
2733
2734
2735

2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749

2750
2751
2752
2753

2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787

2788
2789

2790
2791
2792
2793
2794
2795
2796
2797


2798
2799


2800
2801
2802
2803
2804
2805
2806
....
2815
2816
2817
2818
2819
2820
2821







































































































































































2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844





2845

2846



2847
2848
2849
2850
2851
2852

2853










2854
2855
2856





























2857












2858
2859






2860
2861
2862


2863
2864
2865
2866
2867
2868

2869


2870
2871
2872


2873

2874
2875
2876
2877
2878
2879
2880




2881
2882




2883
2884
2885

2886
2887
2888

2889
2890
2891





2892
2893










2894
2895
2896
2897


2898
2899
2900
2901
2902
2903
2904





2905
2906
2907



2908
2909
2910


2911
2912
2913
2914
2915
2916
2917
2918







2919
2920

2921
2922
2923
2924

2925
2926
2927

2928
2929
2930
2931
2932
2933
2934

2935
2936

2937
2938




2939
2940

2941
2942
2943



2944
2945








2946
2947
2948
2949
2950
2951


2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962

2963
2964
2965
2966
2967
2968
2969
....
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
....
3062
3063
3064
3065
3066
3067
3068




3069
3070














3071
3072






3073

3074

















3075

3076





3077









3078
3079














3080
3081

















3082
















3083
3084








3085
3086











3087
3088
3089
3090
3091
3092
3093
....
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
#include "tk3d.h"
#include "tkFont.h"

#include <assert.h>

/*
 * Mathematical functions 
 */
#undef ABS
#define ABS(x)		(((x)<0)?(-(x)):(x))

#undef EXP10
#define EXP10(x)	(pow(10.0,(x)))

................................................................................
#define RBC_SELECT_BACKGROUND   "lightblue1"
#define RBC_SELECT_FOREGROUND   "black"
#define RBC_INDICATOR_COLOR	    "maroon"

#define RBC_OP_LINEAR_SEARCH	1
#define RBC_OP_BINARY_SEARCH	0

#ifdef notdef
#define RbcFill3DRectangle	Tk_Fill3DRectangle
#define RbcDraw3DRectangle	Tk_Draw3DRectangle
#endif

#define RBC_STATIC_STRING_SPACE 150

#define RBC_NS_SEARCH_NONE		(0)
#define RBC_NS_SEARCH_CURRENT	(1<<0)
#define RBC_NS_SEARCH_GLOBAL	(1<<1)
#define RBC_NS_SEARCH_BOTH		(RBC_NS_SEARCH_GLOBAL | RBC_NS_SEARCH_CURRENT)

................................................................................
} RbcParseVector;

/*
 * RbcOp --
 *
 * 	Generic function prototype of CmdOptions.
 */
typedef int     (
    *RbcOp)         (
    );
 /*TODO*/

/*
 * RbcOpSpec --
 *
 * 	Structure to specify a set of operations for a Tcl command.
 *      This is passed to the RbcGetOp procedure to look
 *      for a function pointer associated with the operation name.
................................................................................
 *
 *	Holds a pair of foreground, background colors.
 */
typedef struct {
    XColor         *fgColor, *bgColor;
} RbcColorPair;

Tk_OptionParseProc RbcStringToEnum;
Tk_OptionPrintProc RbcEnumToString;

Tcl_AppInitProc RbcGraphInit;
Tcl_AppInitProc RbcVectorInit;
Tcl_AppInitProc RbcSplineInit;
typedef void    (
    RbcTileChangedProc) (
    ClientData clientData,
    RbcTile tile);

/*
 * RbcPix32 --
................................................................................
                                         * title above/left of the axis. */
    RbcPoint2D      titlePos;   /* Position of the title */
    unsigned short int titleWidth, titleHeight;
    int             lineWidth;  /* Width of lines representing axis
                                 * (including ticks).  If zero, then
                                 * no axis lines or ticks are
                                 * drawn. */
    char          **limitsFormats;      /* One or two strings of sprintf-like
                                         * formats describing how to display
                                         * virtual axis limits. If NULL,
                                         * display no limits. */
    int             nFormats;
    RbcTextStyle    limitsTextStyle;    /* Text attributes (color, font,
                                         * rotation, etc.)  of the limits. */
    double          windowSize; /* Size of a sliding window of values
................................................................................
                                         * in/out.  */
    double          xRange, yRange;     /* Initial X-axis and Y-axis ranges:
                                         * used to scale the size of element's
                                         * symbol. */
    int             state;
} RbcElement;

RbcElement     *RbcBarElement(
    );
RbcElement     *RbcLineElement(
    );

/*
 * RbcFreqInfo --
 */
typedef struct {
    int             freq;       /* Number of occurrences of x-coordinate */
    RbcAxis2D       axes;       /* Indicates which x and y axis are mapped to
                                 * the x-value */
................................................................................
    Tcl_HashTable   freqTable;  /* */
    int             nStacks;    /* Number of entries in frequency array.
                                 * If zero, indicates nothing special needs
                                 * to be done for "stack" or "align" modes */
    char           *dataCmd;    /* New data callback? */
} RbcGraph;

Tcl_CmdProc     RbcGraphInstCmdProc;
typedef         ClientData(
    MakeTagProc)    (
    RbcGraph * graphPtr,
    const char *tagName);
MakeTagProc     RbcMakeElementTag;
MakeTagProc     RbcMakeMarkerTag;
MakeTagProc     RbcMakeAxisTag;

RbcBindTagProc  RbcGraphTags;

typedef int     (
    RbcSwitchParseProc) (
    ClientData clientData,
    Tcl_Interp * interp,
    char *switchName,
    char *value,
................................................................................
} RbcResampleFilter;

/*
 * Data declarations:
 */
extern double   rbcNaN;
extern RbcResampleFilter *rbcBoxFilterPtr;      /* The ubiquitous box filter */
extern Tk_OptionParseProc RbcStringToStyles;
extern Tk_OptionPrintProc RbcStylesToString;
extern RbcUid   rbcBarElementUid;
extern RbcUid   rbcLineElementUid;
extern RbcUid   rbcStripElementUid;
extern RbcUid   rbcLineMarkerUid;
extern RbcUid   rbcBitmapMarkerUid;
extern RbcUid   rbcImageMarkerUid;
extern RbcUid   rbcTextMarkerUid;
extern RbcUid   rbcPolygonMarkerUid;
extern RbcUid   rbcWindowMarkerUid;
extern RbcUid   rbcXAxisUid;
extern RbcUid   rbcYAxisUid;

/*
 * Function declarations:
 */

/* int RbcNumberOfPoints(RbcAxis2D e); */
#define RbcNumberOfPoints(e)	MIN((e)->x.nValues, (e)->y.nValues)

/* int RbcLineWidth(int w); */
#define RbcLineWidth(w)	(((w) > 1) ? (w) : 0)

/* int RbcPadding(RbcPad w); */
#define RbcPadding(x)	((x).side1 + (x).side2)

MODULE_SCOPE double RbcFindElemVectorMinimum(
    RbcElemVector * vecPtr,
    double minLimit);
MODULE_SCOPE void RbcFreePalette(
    RbcGraph * graphPtr,
    RbcChain * palette);
RbcPenStyle   **RbcStyleMap(
    RbcElement * elemPtr);
MODULE_SCOPE void RbcMapErrorBars(
    RbcGraph * graphPtr,
    RbcElement * elemPtr,
    RbcPenStyle ** dataToStyle);

MODULE_SCOPE void RbcFreeColorPair(
    RbcColorPair * pairPtr);
MODULE_SCOPE RbcUid RbcGetUid(
    const char *string);
MODULE_SCOPE void RbcFreeUid(
    RbcUid uid);
MODULE_SCOPE RbcUid RbcFindUid(
    char *string);
MODULE_SCOPE RbcTextLayout *RbcGetTextLayout(
    char *string,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcGetTextExtents(
    RbcTextStyle * stylePtr,
    char *text,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcInitTextStyle(
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcResetTextStyle(
    Tk_Window tkwin,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcFreeTextStyle(
    Display * display,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcSetDrawTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    GC gc,
    XColor * normalColor,
    XColor * activeColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcSetPrintTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    XColor * fgColor,
    XColor * bgColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcDrawText(
    Tk_Window tkwin,
    Drawable drawable,
    char *string,
    RbcTextStyle * stylePtr,
    int x,
    int y);
MODULE_SCOPE void RbcDrawTextLayout(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int x,
    int y);
MODULE_SCOPE void RbcDrawText2(
    Tk_Window tkwin,
    Drawable drawable,
    char *string,
    RbcTextStyle * stylePtr,
    int x,
    int y,
    RbcDim2D * dimPtr);
MODULE_SCOPE Pixmap RbcCreateTextBitmap(
    Tk_Window tkwin,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE int RbcDrawRotatedText(
    Display * display,
    Drawable drawable,
    int x,
    int y,
    double theta,
    RbcTextStyle * stylePtr,
    RbcTextLayout * textPtr);
MODULE_SCOPE void RbcListInit(
    RbcList * list,
    int type);
MODULE_SCOPE void RbcListReset(
    RbcList * list);
MODULE_SCOPE RbcList *RbcListCreate(
    int type);
MODULE_SCOPE void RbcListDestroy(
    RbcList * list);
MODULE_SCOPE RbcListNode *RbcListCreateNode(
    RbcList * list,
    const char *key);
MODULE_SCOPE void RbcListDeleteNode(
    RbcListNode * node);
MODULE_SCOPE RbcListNode *RbcListAppend(
    RbcList * list,
    const char *key,
    ClientData clientData);
MODULE_SCOPE RbcListNode *RbcListPrepend(
    RbcList * list,
    const char *key,
    ClientData clientData);
MODULE_SCOPE void RbcListLinkAfter(
    RbcList * list,
    RbcListNode * node,
    RbcListNode * afterNode);
MODULE_SCOPE void RbcListLinkBefore(
    RbcList * list,
    RbcListNode * node,
    RbcListNode * beforeNode);
MODULE_SCOPE void RbcListUnlinkNode(
    RbcListNode * node);
MODULE_SCOPE RbcListNode *RbcListGetNode(
    RbcList * list,
    const char *key);
MODULE_SCOPE void Rb_ListDeleteNodeByKey(
    RbcList * list,
    const char *key);
MODULE_SCOPE RbcListNode *RbcListGetNthNode(
    RbcList * list,
    int position,
    int direction);
MODULE_SCOPE void RbcListSort(
    RbcList * list,
    RbcListCompareProc * proc);
#define RbcListGetLength(list) \
	(((list) == NULL) ? 0 : ((RbcList *)list)->nNodes)

#define RbcListFirstNode(list) \
	(((list) == NULL) ? NULL : ((RbcList *)list)->headPtr)

#define RbcListLastNode(list)	\
	(((list) == NULL) ? NULL : ((RbcList *)list)->tailPtr)

#define RbcListPrevNode(node)	((node)->prevPtr)

#define RbcListNextNode(node) 	((node)->nextPtr)

#define RbcListGetKey(node)	\
	(((node)->listPtr->type == TCL_STRING_KEYS) \
		 ? (node)->key.string : (node)->key.oneWordValue)
#define RbcListGetValue(node)  	((node)->clientData)
#define RbcListSetValue(node, value) \



















	((node)->clientData = (ClientData)(value))
#define RbcListAppendNode(list, node) \
	(RbcListLinkBefore((list), (node), (RbcListNode *)NULL))
#define RbcListPrependNode(list, node) \
	(RbcListLinkAfter((list), (node), (RbcListNode *)NULL))






MODULE_SCOPE void RbcDestroyBindingTable(
    RbcBindTable * table);
MODULE_SCOPE RbcBindTable *RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc,
    RbcBindTagProc * tagProc);






MODULE_SCOPE int RbcConfigureBindings(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcConfigureBindingsFromObj(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int objc,
    Tcl_Obj * const *objv);








MODULE_SCOPE void RbcPickCurrentItem(
    RbcBindTable * table);
MODULE_SCOPE void RbcDeleteBindings(
    RbcBindTable * table,
    ClientData object);
MODULE_SCOPE void RbcMoveBindingTable(
    RbcBindTable * table,
    Tk_Window tkwin);

#define RbcSetFocusItem(bindPtr, object, context) \
    ((bindPtr)->focusItem = (ClientData)(object),\
    (bindPtr)->focusContext = (ClientData)(context))

#define RbcSetCurrentItem(bindPtr, object, context) \
    ((bindPtr)->currentItem = (ClientData)(object),\
    (bindPtr)->currentContext = (ClientData)(context))

#define RbcGetCurrentItem(bindPtr)  ((bindPtr)->currentItem)
#define RbcGetCurrentContext(bindPtr)  ((bindPtr)->currentContext)
#define RbcGetLatestItem(bindPtr)  ((bindPtr)->newItem)

#define RbcGetBindingData(bindPtr)  ((bindPtr)->clientData)

#define RbcChainGetLength(c)	(((c) == NULL) ? 0 : (c)->nLinks)
#define RbcChainFirstLink(c)	(((c) == NULL) ? NULL : (c)->headPtr)
#define RbcChainLastLink(c)	(((c) == NULL) ? NULL : (c)->tailPtr)
#define RbcChainPrevLink(l)	((l)->prevPtr)
#define RbcChainNextLink(l) 	((l)->nextPtr)
#define RbcChainGetValue(l)  	((l)->clientData)
#define RbcChainSetValue(l, value) ((l)->clientData = (ClientData)(value))
#define RbcChainAppendLink(c, l) \
	(RbcChainLinkBefore((c), (l), (RbcChainLink *)NULL))
#define RbcChainPrependLink(c, l) \
	(RbcChainLinkAfter((c), (l), (RbcChainLink *)NULL))

MODULE_SCOPE void RbcChainInit(
    RbcChain * chainPtr);
MODULE_SCOPE RbcChain *RbcChainCreate(
    );
MODULE_SCOPE void RbcChainDestroy(
    RbcChain * chainPtr);
MODULE_SCOPE RbcChainLink *RbcChainNewLink(
    void);
MODULE_SCOPE RbcChainLink *RbcChainAllocLink(
    unsigned int size);
MODULE_SCOPE RbcChainLink *RbcChainAppend(
    RbcChain * chainPtr,
    ClientData clientData);
MODULE_SCOPE RbcChainLink *RbcChainPrepend(
    RbcChain * chainPtr,
    ClientData clientData);
MODULE_SCOPE void RbcChainReset(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainLinkAfter(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * afterLinkPtr);
MODULE_SCOPE void RbcChainLinkBefore(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * beforeLinkPtr);






MODULE_SCOPE void RbcChainUnlinkLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE void RbcChainDeleteLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE RbcChainLink *RbcChainGetNthLink(
    RbcChain * chainPtr,
    int n);
MODULE_SCOPE void RbcChainSort(
    RbcChain * chainPtr,
    RbcChainCompareProc * proc);

MODULE_SCOPE RbcOp RbcGetOp(
    Tcl_Interp * interp,
    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int argc,
    const char **argv,
    int flags);
MODULE_SCOPE RbcOp RbcGetOpFromObj(
    Tcl_Interp * interp,
    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int objc,
    Tcl_Obj * const *objv,
    int flags);
MODULE_SCOPE void RbcDraw3DRectangle(
    Tk_Window tkwin,
    Drawable drawable,
    Tk_3DBorder border,
    int x,
    int y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcFill3DRectangle(
    Tk_Window tkwin,
    Drawable drawable,
    Tk_3DBorder border,
    int x,
    int y,
    int width,
    int height,
    int borderWidth,
    int relief);

MODULE_SCOPE void RbcSetDashes(
    Display * display,
    GC gc,
    RbcDashes * dashesPtr);
MODULE_SCOPE RbcDashes *RbcGetDashes(
    GC gc);

MODULE_SCOPE char *RbcItoa(
    int value);
MODULE_SCOPE char *RbcUtoa(
    unsigned int value);
MODULE_SCOPE char *RbcDtoa(
    Tcl_Interp * interp,
    double value);

MODULE_SCOPE int RbcNaturalSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcQuadraticSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcSimplifyLine(
    RbcPoint2D * origPts,
    int low,
    int high,
    double tolerance,
    int indices[]);
MODULE_SCOPE int RbcNaturalParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcExtents2D * extsPtr,
    int isClosed,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcCatromParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE void RbcInitHexTable(
    char *table);
MODULE_SCOPE GC RbcGetPrivateGC(
    Tk_Window tkwin,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE GC RbcGetPrivateGCFromDrawable(
    Display * display,
    Drawable drawable,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE void RbcFreePrivateGC(
    Display * display,
    GC gc);
MODULE_SCOPE Tk_Window RbcFindChild(
    Tk_Window parent,
    char *name);
MODULE_SCOPE Tk_Window RbcFirstChild(
    Tk_Window parent);
MODULE_SCOPE Tk_Window RbcNextChild(
    Tk_Window tkwin);

MODULE_SCOPE int RbcGetPixels(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int check,
    int *valuePtr);
MODULE_SCOPE int RbcGetPosition(
    Tcl_Interp * interp,
    char *string,
    int *indexPtr);
MODULE_SCOPE int RbcGetXY(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int *x,
    int *y);
MODULE_SCOPE RbcPoint2D RbcGetProjection(
    int x,
    int y,
    RbcPoint2D * p,
    RbcPoint2D * q);

MODULE_SCOPE int RbcConfigModified(
    Tk_ConfigSpec * specs,
    ...);
MODULE_SCOPE void RbcDStringAppendElements(
    Tcl_DString * dsPtr,
    ...);
MODULE_SCOPE void RbcMakeTransparentWindowExist(
    Tk_Window tkwin,
    Window parent,
    int isBusy);
MODULE_SCOPE Window RbcGetParent(
    Display * display,
    Window tkwin);
MODULE_SCOPE void RbcGetBoundingBox(
    int width,
    int height,
    double theta,
    double *widthPtr,
    double *heightPtr,
    RbcPoint2D * points);
MODULE_SCOPE void RbcInitEpsCanvasItem(
    Tcl_Interp * interp);
MODULE_SCOPE void RbcTranslateAnchor(
    int x,
    int y,
    int width,
    int height,
    Tk_Anchor anchor,
    int *transXPtr,
    int *transYPtr);
MODULE_SCOPE RbcPoint2D RbcTranslatePoint(
    RbcPoint2D * pointPtr,
    int width,
    int height,
    Tk_Anchor anchor);
MODULE_SCOPE int RbcConfigureWidgetComponent(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *name,
    const char *class,
    const Tk_ConfigSpec * specs,
    int argc,
    const char **argv,
    char *widgRec,
    int flags);









MODULE_SCOPE int RbcMaxRequestSize(
    Display * display,
    unsigned int elemSize);






MODULE_SCOPE Window RbcGetRealWindowId(
    Tk_Window tkwin);



MODULE_SCOPE int RbcRootX(


    Tk_Window tkwin);
MODULE_SCOPE int RbcRootY(
    Tk_Window tkwin);





























MODULE_SCOPE void RbcRootCoordinates(
    Tk_Window tkwin,















    int x,




    int y,



















    int *rootXPtr,
    int *rootYPtr);















MODULE_SCOPE void RbcMapToplevel(












    Tk_Window tkwin);
MODULE_SCOPE void RbcUnmapToplevel(





    Tk_Window tkwin);






































MODULE_SCOPE void RbcRaiseToplevel(
    Tk_Window tkwin);

MODULE_SCOPE void RbcLowerToplevel(
    Tk_Window tkwin);



































MODULE_SCOPE void RbcResizeToplevel(
    Tk_Window tkwin,

    int width,
    int height);
MODULE_SCOPE void RbcMoveToplevel(
    Tk_Window tkwin,












    int x,


































    int y);









MODULE_SCOPE void RbcMoveResizeToplevel(
    Tk_Window tkwin,





    int x,
    int y,
    int width,
    int height);
MODULE_SCOPE ClientData RbcGetWindowInstanceData(




    Tk_Window tkwin);



MODULE_SCOPE void RbcSetWindowInstanceData(
    Tk_Window tkwin,
    ClientData instanceData);















MODULE_SCOPE void RbcDeleteWindowInstanceData(
    Tk_Window tkwin);
















MODULE_SCOPE int RbcAdjustViewport(
    int offset,
    int worldSize,
    int windowSize,
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE int RbcGetScrollInfo(
................................................................................
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE void RbcUpdateScrollbar(
    Tcl_Interp * interp,
    char *scrollCmd,
    double firstFract,
    double lastFract);
MODULE_SCOPE int RbcReparentWindow(
    Display * display,
    Window window,
    Window newParent,
    int x,
    int y);

MODULE_SCOPE char *RbcStrdup(
    const char *ptr);
MODULE_SCOPE void *RbcCalloc(
    unsigned int nElem,
    size_t size);
MODULE_SCOPE int RbcGetTile(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *imageName,
    RbcTile * tilePtr);
MODULE_SCOPE void RbcFreeTile(
    RbcTile tile);
MODULE_SCOPE const char *RbcNameOfTile(
    RbcTile tile);
MODULE_SCOPE void RbcSetTileChangedProc(
    RbcTile tile,
    RbcTileChangedProc * changeProc,
    ClientData clientData);
MODULE_SCOPE void RbcTileRectangle(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    int x,
    int y,
    unsigned int width,
    unsigned int height);
MODULE_SCOPE void RbcTileRectangles(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE void RbcTilePolygon(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XPoint * pointArr,
    int nPoints);
Pixmap          RbcPixmapOfTile(
    RbcTile tile);
MODULE_SCOPE void RbcSizeOfTile(
    RbcTile tile,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcSetTileOrigin(
    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);
MODULE_SCOPE void RbcSetTSOrigin(
    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);

MODULE_SCOPE void RbcColorImageToGreyscale(
    RbcColorImage * image);
MODULE_SCOPE void RbcColorImageToPhoto(
    Tcl_Interp * interp,
    RbcColorImage * image,
    Tk_PhotoHandle photo);
MODULE_SCOPE RbcColorImage *RbcConvolveColorImage(
    RbcColorImage * srcImage,
    RbcFilter2D * filter);
MODULE_SCOPE RbcColorImage *RbcCreateColorImage(
    int width,
    int height);
MODULE_SCOPE int RbcGetResampleFilter(
    Tcl_Interp * interp,
    char *filterName,
    RbcResampleFilter ** filterPtrPtr);
MODULE_SCOPE void RbcFreeColorImage(
    RbcColorImage * image);
MODULE_SCOPE RbcColorImage *RbcPhotoToColorImage(
    Tk_PhotoHandle photo);
MODULE_SCOPE RbcColorImage *RbcPhotoRegionToColorImage(
    Tk_PhotoHandle photo,
    int x,
    int y,
    int width,
    int height);
MODULE_SCOPE int RbcQuantizeColorImage(
    RbcColorImage * src,

    RbcColorImage * dest,
    int nColors);


MODULE_SCOPE RbcColorImage *RbcResampleColorImage(
    RbcColorImage * image,
    int destWidth,
    int destHeight,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);
MODULE_SCOPE void RbcResamplePhoto(
................................................................................
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);








MODULE_SCOPE RbcColorImage *RbcResizeColorImage(
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
................................................................................
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight);
MODULE_SCOPE RbcColorImage *RbcRotateColorImage(
    RbcColorImage * image,
    double theta);
MODULE_SCOPE void RbcResizePhoto(
    Tcl_Interp * interp,
    Tk_PhotoHandle srcPhoto,
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto);
MODULE_SCOPE int RbcSnapPhoto(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight,
    const char *photoName,
    double inputGamma);







MODULE_SCOPE RbcRegion2D *RbcSetRegion(
    int x,
    int y,
    int width,
    int height,
    RbcRegion2D * regionPtr);

/* Missing routines from the Tk photo C API */

MODULE_SCOPE int Tk_ImageIsDeleted(
    Tk_Image tkImage);
MODULE_SCOPE Tk_ImageMaster Tk_ImageGetMaster(
    Tk_Image tkImage);
MODULE_SCOPE Tk_ImageType *Tk_ImageGetType(
    Tk_Image tkImage);
MODULE_SCOPE Pixmap Tk_ImageGetPhotoPixmap(
    Tk_Image photoImage);
MODULE_SCOPE GC Tk_ImageGetPhotoGC(
    Tk_Image photoImage);

MODULE_SCOPE const char *RbcNameOfImage(
    Tk_Image tkImage);
MODULE_SCOPE Tk_Image RbcCreateTemporaryImage(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData);
MODULE_SCOPE int RbcDestroyTemporaryImage(
    Tcl_Interp * interp,
    Tk_Image tkImage);
MODULE_SCOPE GC RbcGetBitmapGC(
    Tk_Window tkwin);



MODULE_SCOPE RbcPsToken *RbcGetPsToken(
    Tcl_Interp * interp,
    Tk_Window tkwin);
MODULE_SCOPE void RbcReleasePsToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcPostScriptFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcScratchBufferFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE void RbcAppendToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcFormatToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcDraw3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcFill3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcBackgroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcBitmapDataToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    int width,
    int height);
MODULE_SCOPE void RbcClearBackgroundToPostScript(
    RbcPsToken * psToken);
MODULE_SCOPE int RbcColorImageToPsData(
    RbcColorImage * image,
    int nComponents,
    Tcl_DString * resultPtr,
    const char *prefix);
MODULE_SCOPE void RbcColorImageToPostScript(
    RbcPsToken * psToken,
    RbcColorImage * image,
    double x,
    double y);
MODULE_SCOPE void RbcForegroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcFontToPostScript(
    RbcPsToken * psToken,
    Tk_Font font);
MODULE_SCOPE void RbcWindowToPostScript(
    RbcPsToken * psToken,
    Tk_Window tkwin,
    double x,
    double y);
MODULE_SCOPE void RbcLineDashesToPostScript(
    RbcPsToken * psToken,
    RbcDashes * dashesPtr);
MODULE_SCOPE void RbcLineWidthToPostScript(
    RbcPsToken * psToken,
    int lineWidth);
MODULE_SCOPE void RbcPathToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcPhotoToPostScript(
    RbcPsToken * psToken,
    Tk_PhotoHandle photoToken,
    double x,
    double y);
MODULE_SCOPE void RbcPolygonToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcLineToPostScript(
    RbcPsToken * psToken,
    XPoint * pointArr,
    int nPoints);
MODULE_SCOPE void RbcTextToPostScript(
    RbcPsToken * psToken,
    char *string,
    RbcTextStyle * attrPtr,
    double x,
    double y);
MODULE_SCOPE void RbcRectangleToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcRegionToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcRectanglesToPostScript(
    RbcPsToken * psToken,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE void RbcBitmapToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    double scaleX,
    double scaleY);
MODULE_SCOPE void RbcSegmentsToPostScript(
    RbcPsToken * psToken,
    XSegment * segArr,
    int nSegs);
MODULE_SCOPE void RbcStippleToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap);
MODULE_SCOPE void RbcLineAttributesToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr,
    int lineWidth,
    RbcDashes * dashesPtr,
    int capStyle,
    int joinStyle);
MODULE_SCOPE int RbcFileToPostScript(
    RbcPsToken * psToken,
    const char *fileName);
MODULE_SCOPE void Rbc2DSegmentsToPostScript(
    RbcPsToken * psToken,
    RbcSegment2D * segments,
    int nSegments);
MODULE_SCOPE int RbcCreateLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawLegend(
    RbcLegend * legendPtr,
    Drawable drawable);
MODULE_SCOPE void RbcMapLegend(
    RbcLegend * legendPtr,
    int width,
    int height);
MODULE_SCOPE int RbcLegendOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,

    const char **argv);
MODULE_SCOPE int RbcLegendSite(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendWidth(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendHeight(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsHidden(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsRaised(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendX(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendY(
    RbcLegend * legendPtr);
MODULE_SCOPE void RbcLegendRemoveElement(
    RbcLegend * legendPtr,
    RbcElement * elemPtr);

MODULE_SCOPE int RbcCreatePostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE double RbcInvHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcInvVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double y);
MODULE_SCOPE RbcPoint2D RbcInvMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE RbcPoint2D RbcMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE RbcGraph *RbcGetGraphFromWindowData(
    Tk_Window tkwin);
MODULE_SCOPE int RbcLineRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * p,
    RbcPoint2D * q);
MODULE_SCOPE int RbcPolyRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * inputPts,
    int nInputPts,
    RbcPoint2D * outputPts);

MODULE_SCOPE void RbcComputeStacks(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcConfigureCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyMarkers(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyPostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawAxes(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawAxisLimits(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawElements(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawActiveElements(
    RbcGraph * graphPtr,
    Drawable drawable);

MODULE_SCOPE void RbcDrawGraph(
    RbcGraph * graphPtr,
    Drawable drawable,
    int backingStore);

MODULE_SCOPE void RbcDrawGrid(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawMarkers(
    RbcGraph * graphPtr,
    Drawable drawable,

    int under);
MODULE_SCOPE void RbcDraw2DSegments(
    Display * display,
    Drawable drawable,
    GC gc,
    RbcSegment2D * segments,
    int nSegments);
MODULE_SCOPE void RbcInitFreqTable(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcLayoutGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcLayoutMargins(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcEventuallyRedrawGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcResetAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcResetStacks(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcGraphExtents(
    RbcGraph * graphPtr,
    RbcExtents2D * extsPtr);
MODULE_SCOPE void RbcDisableCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcEnableCrosshairs(
    RbcGraph * graphPtr);



MODULE_SCOPE void RbcMapAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcMapElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcMapMarkers(
    RbcGraph * graphPtr);



MODULE_SCOPE void RbcMapGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcUpdateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyPens(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcGetPen(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid classUid,
    RbcPen ** penPtrPtr);

MODULE_SCOPE RbcPen *RbcBarPen(
    const char *penName);
MODULE_SCOPE RbcPen *RbcLinePen(
    const char *penName);
MODULE_SCOPE RbcPen *RbcCreatePen(
    RbcGraph * graphPtr,

    const char *penName,
    RbcUid classUid,
    int nOpts,
    const char **options);
MODULE_SCOPE void RbcFreePen(
    RbcGraph * graphPtr,
    RbcPen * penPtr);

MODULE_SCOPE int RbcVirtualAxisOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
/* rbcGrAxis.c */

MODULE_SCOPE int RbcAxisOp(
    RbcGraph * graphPtr,
    int margin,
    int argc,
    const char **argv);
/* rbcGrElem.c */
MODULE_SCOPE int RbcElementOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,

    const char **argv,
    RbcUid classUid);
/* rbcGrGrid.c */
MODULE_SCOPE int RbcGridOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,

    const char **argv);
/* rbcGrHairs.c */
MODULE_SCOPE int RbcCrosshairsOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
/* rbcGrMarker.c */
MODULE_SCOPE int RbcMarkerOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
/* rbcGrPen.c */

MODULE_SCOPE int RbcPenOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,

    const char **argv);
/* rbcGrMisc.c */
MODULE_SCOPE int RbcPointInPolygon(
    RbcPoint2D * samplePtr,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE int RbcRegionInPolygon(
    RbcExtents2D * extsPtr,
    RbcPoint2D * points,
    int nPoints,
    int enclosed);
MODULE_SCOPE int RbcPointInSegments(
    RbcPoint2D * samplePtr,
    RbcSegment2D * segments,
    int nSegments,
    double halo);
/* rbcGrPs.c */
MODULE_SCOPE int RbcPostScriptOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);
/* rbcGrAxis.c */
MODULE_SCOPE int RbcGraphUpdateNeeded(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcDefaultAxes(
    RbcGraph * graphPtr);
RbcAxis        *RbcGetFirstAxis(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcGetAxisSegments(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    RbcSegment2D ** segPtrPtr,
    int *nSegmentsPtr);

MODULE_SCOPE RbcMarker *RbcNearestMarker(
    RbcGraph * graphPtr,

    int x,
    int y,
    int under);
MODULE_SCOPE RbcAxis *RbcNearestAxis(
    RbcGraph * graphPtr,
    int x,
    int y);
/* rbcGraph.c */


MODULE_SCOPE int RbcGraphType(
    RbcGraph * graphPtr);


/* rbcParse.c */
MODULE_SCOPE void RbcExpandParseValue(
    RbcParseValue * parsePtr,
    int needed);
MODULE_SCOPE int RbcParseNestedCmd(
    Tcl_Interp * interp,
    char *string,
................................................................................
MODULE_SCOPE int RbcParseQuotes(
    Tcl_Interp * interp,
    char *string,
    int termChar,
    int flags,
    char **termPtr,
    RbcParseValue * parsePtr);







































































































































































/* rbcSwitch.c */
MODULE_SCOPE int RbcProcessSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specs,
    int argc,
    const char **argv,
    char *record,
    int flags);
MODULE_SCOPE void RbcFreeSwitches(
    RbcSwitchSpec * specs,
    char *record,
    int flags);
MODULE_SCOPE int RbcSwitchChanged(
    RbcSwitchSpec * specs,
    ...);
MODULE_SCOPE int RbcProcessObjSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specPtr,
    int objc,
    Tcl_Obj * const *objv,
    char *record,
    int flags);
MODULE_SCOPE double Rbcdrand48(





    void);

/* rbcVector.c */



MODULE_SCOPE void RbcVectorFlushCache(
    RbcVectorObject * vPtr);
RbcVectorObject *RbcVectorParseElement(
    Tcl_Interp * interp,
    RbcVectorInterpData * dataPtr,
    const char *start,

    char **endPtr,










    int flags);
MODULE_SCOPE int RbcVectorChangeLength(
    RbcVectorObject * vPtr,





























    int length);












MODULE_SCOPE void RbcVectorUpdateClients(
    RbcVectorObject * vPtr);






MODULE_SCOPE int RbcVectorMapVariable(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,


    const char *name);
MODULE_SCOPE RbcVectorObject *RbcVectorCreate(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    const char *cmdName,
    const char *varName,

    int *newPtr);


MODULE_SCOPE int RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,


    const char *string,

    int *indexPtr,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
MODULE_SCOPE int RbcGetDouble(
    Tcl_Interp * interp,
    Tcl_Obj * objPtr,
    double *valuePtr);




MODULE_SCOPE void RbcVectorFree(
    RbcVectorObject * vPtr);




MODULE_SCOPE int RbcVectorGetIndexRange(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,

    const char *string,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);

MODULE_SCOPE int RbcVectorDuplicate(
    RbcVectorObject * destPtr,
    RbcVectorObject * srcPtr);





MODULE_SCOPE Tcl_Obj *RbcGetValues(
    RbcVectorObject * vPtr,










    int first,
    int last);
MODULE_SCOPE void RbcReplicateValue(
    RbcVectorObject * vPtr,


    int first,
    int last,
    double value);
MODULE_SCOPE int RbcVectorLookupName(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    RbcVectorObject ** vPtrPtr);





MODULE_SCOPE int RbcVectorReset(
    RbcVectorObject * vPtr,
    double *valueArr,



    int length,
    int size,
    Tcl_FreeProc * freeProc);


MODULE_SCOPE void RbcVectorUpdateRange(
    RbcVectorObject * vPtr);
MODULE_SCOPE RbcVectorObject *RbcVectorNew(
    RbcVectorInterpData * dataPtr);
MODULE_SCOPE RbcVectorInterpData *RbcVectorGetInterpData(
    Tcl_Interp * interp);
MODULE_SCOPE int RbcVectorNotifyPending(
    RbcVectorId clientId);







MODULE_SCOPE void RbcFreeVectorId(
    RbcVectorId clientId);

MODULE_SCOPE int RbcGetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,
    RbcVector ** vecPtrPtr);

MODULE_SCOPE int RbcVectorExists2(
    Tcl_Interp * interp,
    const char *vecName);

MODULE_SCOPE RbcVectorId RbcAllocVectorId(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE void RbcSetVectorChangedProc(
    RbcVectorId clientId,
    RbcVectorChangedProc * proc,
    ClientData clientData);

MODULE_SCOPE char *RbcNameOfVectorId(
    RbcVectorId clientId);

MODULE_SCOPE int RbcGetVector(
    Tcl_Interp * interp,




    const char *vecName,
    RbcVector ** vecPtrPtr);

MODULE_SCOPE int RbcCreateVector(
    Tcl_Interp * interp,
    const char *vecName,



    int size,
    RbcVector ** vecPtrPtr);








MODULE_SCOPE int RbcResizeVector(
    RbcVector * vecPtr,
    int nValues);
MODULE_SCOPE char *RbcNameOfVector(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcResetVector(


    RbcVector * vecPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);
MODULE_SCOPE int RbcVectorReset(
    RbcVectorObject * vPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);

/* rbcVecObjCmd.c */
MODULE_SCOPE int RbcAppendOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcArithOp(
................................................................................
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcOffsetOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRandomOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcPopulateOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRangeOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
................................................................................
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcVariableOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);




/* rbcVecMath.c */
MODULE_SCOPE double RbcVecMin(














    RbcVector * vecPtr);
MODULE_SCOPE double RbcVecMax(






    RbcVector * vecPtr);

MODULE_SCOPE int RbcExprVector(

















    Tcl_Interp * interp,

    char *string,





    RbcVector * vecPtr);









MODULE_SCOPE void RbcVectorInstallMathFunctions(
    Tcl_HashTable * tablePtr);














MODULE_SCOPE void RbcVectorInstallSpecialIndices(
    Tcl_HashTable * tablePtr);

















MODULE_SCOPE int *RbcVectorSortIndex(
















    RbcVectorObject ** vPtrPtr,
    int nVectors);






















/* rbcWinImage.c rbcUnixImage.c */
MODULE_SCOPE RbcColorImage *RbcDrawableToColorImage(
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
................................................................................
    int regionX,
    int regionY,
    unsigned int regionWidth,
    unsigned int regionHeight,
    unsigned int virtWidth,
    unsigned int virtHeight,
    double theta);



/* Windows */
#ifdef _WIN32
#include "rbcWin.h"
#endif

#ifndef _WIN32






|







 







<
<
<
<
<







 







|
<
<
<







 







<
<
<
<
<
<







 







|







 







<
<
<
<
<







 







<




<
<
<
<
<







 







<
<













|











|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


>


>


>

>

>



<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
<

>
>
>
>
>
|
<
<
<
<
<
<
<
>
>
>
>
>
>












>
>
>
>
>
>
>
>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|


<
<
<
<
<
<
<
<
<
<
<
<
|









>
>
>
>
>
>






|

|
|

|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










>
>
>
>
>
>
>
>
>
|
<
<
>
>
>
>
>
>
|
<
>
>
>
|
>
>

|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>


|
<
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>


|
<
<
>
>
>
>
|
>
>
>
|
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<






<
|
>
|
|
>
>







 







>
>
>
>
>
>
>
>







 







|
|
|
<
<
<
<
<
<
<
<












>
>
>
>
>
>
>






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







|
<
>

>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
>
|
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>
>
|
<
<
<
<
<
>
>
>
|
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
>
|
<
<
<
|
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
>
|
<
<
|
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
>
|
|
<
|
<
<
<
<
>
>
|
<
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








<
<
<
<
<
<
<







|
>
>
>
>
>
|
>
|
>
>
>
|
<
<
<
<
<
>
|
>
>
>
>
>
>
>
>
>
>
|
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
|
<
<
>
>
|
<
<
<
<
<
>
|
>
>
|
<
<
>
>
|
>
|
|
<
|
<
<
<
>
>
>
>
|
<
>
>
>
>
|

<
>
|
<
<
>
|
<
<
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
|
|
|
<
>
>
|
|
<
|
<
<
<
>
>
>
>
>
|
<
<
>
>
>
|
|
<
>
>
|
<
<
<
<
<
<
<
>
>
>
>
>
>
>
|
<
>
|
<
<
<
>
|

<
>
|
<
|
|
<
<
<
>
|
<
>
|

>
>
>
>
|
<
>
|

<
>
>
>
|
<
>
>
>
>
>
>
>
>
|
|
<
|

|
>
>
|
<
<
<
<
<
<
<
<
<
<
>







 







|




|







 







>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>

<
>
>
>
>
>
>
>
>
>
>
>







 







<
<







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
109
110
111
112
113
114
115





116
117
118
119
120
121
122
...
682
683
684
685
686
687
688
689



690
691
692
693
694
695
696
...
815
816
817
818
819
820
821






822
823
824
825
826
827
828
...
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
....
1287
1288
1289
1290
1291
1292
1293





1294
1295
1296
1297
1298
1299
1300
....
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602





1603
1604
1605
1606
1607
1608
1609
....
1669
1670
1671
1672
1673
1674
1675


1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701












































































































































1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717


1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737




1738
1739
1740
1741
1742
1743
1744







1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779



























1780
1781
1782












1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810

1811














































1812



1813

















































1814
1815
1816
1817
1818
1819
1820
















1821
1822
1823
































1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843


1844
1845
1846
1847
1848
1849
1850

1851
1852
1853
1854
1855
1856
1857
1858

1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888

1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959

1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004

2005
2006

2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042

2043
2044
2045
2046

2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104

2105
2106
2107
2108
2109
2110
2111
2112


2113
2114
2115
2116
2117
2118
2119
2120
2121


2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137

2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
....
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263

2264
2265
2266
2267
2268
2269

2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
....
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
....
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318








2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
















2344
2345
2346
2347
2348
2349
2350
2351

2352
2353
2354
2355



















2356
































































































































2357



2358
2359














































































2360











2361
2362



2363
2364





2365
2366








2367
















2368
2369
2370
2371





2372
2373
2374
2375










2376
2377





2378
2379



2380









2381
2382









2383
2384


2385



2386
2387













2388
2389



2390
2391

































2392
2393

2394
2395
2396

2397




2398
2399
2400

2401
2402
2403
2404
2405
2406
2407
2408
2409
....
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599







2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619





2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632


2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675

2676
2677
2678
2679
2680
2681
2682


2683
2684
2685





2686
2687
2688
2689
2690


2691
2692
2693
2694
2695
2696

2697



2698
2699
2700
2701
2702

2703
2704
2705
2706
2707
2708

2709
2710


2711
2712


2713
2714
2715
2716
2717
2718

2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731

2732
2733
2734
2735

2736



2737
2738
2739
2740
2741
2742


2743
2744
2745
2746
2747

2748
2749
2750







2751
2752
2753
2754
2755
2756
2757
2758

2759
2760



2761
2762
2763

2764
2765

2766
2767



2768
2769

2770
2771
2772
2773
2774
2775
2776
2777

2778
2779
2780

2781
2782
2783
2784

2785
2786
2787
2788
2789
2790
2791
2792
2793
2794

2795
2796
2797
2798
2799
2800










2801
2802
2803
2804
2805
2806
2807
2808
....
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
....
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974

2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989

2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034

3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
....
3079
3080
3081
3082
3083
3084
3085


3086
3087
3088
3089
3090
3091
3092
#include "tk3d.h"
#include "tkFont.h"

#include <assert.h>

/*
 * Mathematical functions
 */
#undef ABS
#define ABS(x)		(((x)<0)?(-(x)):(x))

#undef EXP10
#define EXP10(x)	(pow(10.0,(x)))

................................................................................
#define RBC_SELECT_BACKGROUND   "lightblue1"
#define RBC_SELECT_FOREGROUND   "black"
#define RBC_INDICATOR_COLOR	    "maroon"

#define RBC_OP_LINEAR_SEARCH	1
#define RBC_OP_BINARY_SEARCH	0






#define RBC_STATIC_STRING_SPACE 150

#define RBC_NS_SEARCH_NONE		(0)
#define RBC_NS_SEARCH_CURRENT	(1<<0)
#define RBC_NS_SEARCH_GLOBAL	(1<<1)
#define RBC_NS_SEARCH_BOTH		(RBC_NS_SEARCH_GLOBAL | RBC_NS_SEARCH_CURRENT)

................................................................................
} RbcParseVector;

/*
 * RbcOp --
 *
 * 	Generic function prototype of CmdOptions.
 */
typedef int     (*RbcOp)         ();




/*
 * RbcOpSpec --
 *
 * 	Structure to specify a set of operations for a Tcl command.
 *      This is passed to the RbcGetOp procedure to look
 *      for a function pointer associated with the operation name.
................................................................................
 *
 *	Holds a pair of foreground, background colors.
 */
typedef struct {
    XColor         *fgColor, *bgColor;
} RbcColorPair;







typedef void    (
    RbcTileChangedProc) (
    ClientData clientData,
    RbcTile tile);

/*
 * RbcPix32 --
................................................................................
                                         * title above/left of the axis. */
    RbcPoint2D      titlePos;   /* Position of the title */
    unsigned short int titleWidth, titleHeight;
    int             lineWidth;  /* Width of lines representing axis
                                 * (including ticks).  If zero, then
                                 * no axis lines or ticks are
                                 * drawn. */
    const char    **limitsFormats;      /* One or two strings of sprintf-like
                                         * formats describing how to display
                                         * virtual axis limits. If NULL,
                                         * display no limits. */
    int             nFormats;
    RbcTextStyle    limitsTextStyle;    /* Text attributes (color, font,
                                         * rotation, etc.)  of the limits. */
    double          windowSize; /* Size of a sliding window of values
................................................................................
                                         * in/out.  */
    double          xRange, yRange;     /* Initial X-axis and Y-axis ranges:
                                         * used to scale the size of element's
                                         * symbol. */
    int             state;
} RbcElement;






/*
 * RbcFreqInfo --
 */
typedef struct {
    int             freq;       /* Number of occurrences of x-coordinate */
    RbcAxis2D       axes;       /* Indicates which x and y axis are mapped to
                                 * the x-value */
................................................................................
    Tcl_HashTable   freqTable;  /* */
    int             nStacks;    /* Number of entries in frequency array.
                                 * If zero, indicates nothing special needs
                                 * to be done for "stack" or "align" modes */
    char           *dataCmd;    /* New data callback? */
} RbcGraph;


typedef         ClientData(
    MakeTagProc)    (
    RbcGraph * graphPtr,
    const char *tagName);






typedef int     (
    RbcSwitchParseProc) (
    ClientData clientData,
    Tcl_Interp * interp,
    char *switchName,
    char *value,
................................................................................
} RbcResampleFilter;

/*
 * Data declarations:
 */
extern double   rbcNaN;
extern RbcResampleFilter *rbcBoxFilterPtr;      /* The ubiquitous box filter */


extern RbcUid   rbcBarElementUid;
extern RbcUid   rbcLineElementUid;
extern RbcUid   rbcStripElementUid;
extern RbcUid   rbcLineMarkerUid;
extern RbcUid   rbcBitmapMarkerUid;
extern RbcUid   rbcImageMarkerUid;
extern RbcUid   rbcTextMarkerUid;
extern RbcUid   rbcPolygonMarkerUid;
extern RbcUid   rbcWindowMarkerUid;
extern RbcUid   rbcXAxisUid;
extern RbcUid   rbcYAxisUid;

/*
 * Inline function declarations:
 */

/* int RbcNumberOfPoints(RbcAxis2D e); */
#define RbcNumberOfPoints(e)	MIN((e)->x.nValues, (e)->y.nValues)

/* int RbcLineWidth(int w); */
#define RbcLineWidth(w)	(((w) > 1) ? (w) : 0)

/* int RbcPadding(RbcPad w); */
#define RbcPadding(x)	((x).side1 + (x).side2)

/* int RbcListGetLength(RbcList *list); */












































































































































#define RbcListGetLength(list) \
	(((list) == NULL) ? 0 : ((RbcList *)list)->nNodes)
/* RbcListNode *RbcListFirstNode(RbcList *list); */
#define RbcListFirstNode(list) \
	(((list) == NULL) ? NULL : ((RbcList *)list)->headPtr)
/* RbcListNode *RbcListLastNode(RbcList *list); */
#define RbcListLastNode(list)	\
	(((list) == NULL) ? NULL : ((RbcList *)list)->tailPtr)
/* RbcListNode *RbcListPrevNode(RbcListNode *node); */
#define RbcListPrevNode(node)	((node)->prevPtr)
/* RbcListNode *RbcListNextNode(RbcListNode *node); */
#define RbcListNextNode(node) 	((node)->nextPtr)
/* char *RbcListGetKey(RbcListNode *node); */
#define RbcListGetKey(node)	\
	(((node)->listPtr->type == TCL_STRING_KEYS) \
		 ? (node)->key.string : (node)->key.oneWordValue)


/* ClientData RbcGetCurrentItem(RbcBindTable *bindPtr); */
#define RbcGetCurrentItem(bindPtr)  ((bindPtr)->currentItem)
/* */
/* ClientData RbcGetBindingData(RbcBindTable *bindPtr); */
#define RbcGetBindingData(bindPtr)  ((bindPtr)->clientData)
/* int RbcChainGetLength(RbcChain *c); */
#define RbcChainGetLength(c)	(((c) == NULL) ? 0 : (c)->nLinks)
/* RbcChainLink *RbcChainFirstLink(RbcChain *c); */
#define RbcChainFirstLink(c)	(((c) == NULL) ? NULL : (c)->headPtr)
/* */
/* RbcChainLink *RbcChainLastLink(RbcChain *c); */
#define RbcChainLastLink(c)	(((c) == NULL) ? NULL : (c)->tailPtr)
/* RbcChainLink *RbcChainPrevLink(RbcChainLink *l); */
#define RbcChainPrevLink(l)	((l)->prevPtr)
/* RbcChainLink *RbcChainNextLink(RbcChainLink *l); */
#define RbcChainNextLink(l) 	((l)->nextPtr)
/* ClientData RbcChainGetValue(RbcChainLink *l); */
#define RbcChainGetValue(l)  	((l)->clientData)
/* void RbcChainSetValue(RbcChainLink *l, ClientData value); */
#define RbcChainSetValue(l, value) ((l)->clientData = (ClientData)(value))





/*
 * Function declarations:
 */

/* rbcAlloc.c */
MODULE_SCOPE void *RbcCalloc(







    unsigned int nElem,
    size_t size);
MODULE_SCOPE char *RbcStrdup(
    const char *ptr);

/* rbcBind.c */
MODULE_SCOPE int RbcConfigureBindings(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcConfigureBindingsFromObj(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int objc,
    Tcl_Obj * const *objv);
MODULE_SCOPE RbcBindTable *RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc,
    RbcBindTagProc * tagProc);
MODULE_SCOPE void RbcDestroyBindingTable(
    RbcBindTable * table);
MODULE_SCOPE void RbcPickCurrentItem(
    RbcBindTable * table);
MODULE_SCOPE void RbcDeleteBindings(
    RbcBindTable * table,
    ClientData object);
MODULE_SCOPE void RbcMoveBindingTable(
    RbcBindTable * table,
    Tk_Window tkwin);




























/* rbcChain,c */
MODULE_SCOPE RbcChain *RbcChainCreate(
    );












MODULE_SCOPE void RbcChainInit(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainLinkAfter(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * afterLinkPtr);
MODULE_SCOPE void RbcChainLinkBefore(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * beforeLinkPtr);
MODULE_SCOPE RbcChainLink *RbcChainNewLink(
    void);
MODULE_SCOPE void RbcChainReset(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainDestroy(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainUnlinkLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE void RbcChainDeleteLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE RbcChainLink *RbcChainAppend(
    RbcChain * chainPtr,
    ClientData clientData);
MODULE_SCOPE RbcChainLink *RbcChainPrepend(
    RbcChain * chainPtr,
    ClientData clientData);

MODULE_SCOPE RbcChainLink *RbcChainAllocLink(














































    unsigned int size);





















































/* rbcConfig.c */
MODULE_SCOPE int RbcGetPixels(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int check,
    int *valuePtr);
















MODULE_SCOPE int RbcConfigModified(
    Tk_ConfigSpec * specs,
    ...);
































MODULE_SCOPE int RbcConfigureWidgetComponent(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *name,
    const char *class,
    const Tk_ConfigSpec * specs,
    int argc,
    const char **argv,
    char *widgRec,
    int flags);

/* rbcGraph.c */
MODULE_SCOPE void RbcEventuallyRedrawGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcGraphTags(
    RbcBindTable * table,
    ClientData object,
    ClientData context,
    RbcList * list);
MODULE_SCOPE int RbcGraphInstCmdProc(


    ClientData clientData,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);
MODULE_SCOPE void RbcLayoutGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawGraph(

    RbcGraph * graphPtr,
    Drawable drawable,
    int backingStore);
MODULE_SCOPE int RbcGraphInit(
    Tcl_Interp * interp);
MODULE_SCOPE RbcGraph *RbcGetGraphFromWindowData(
    Tk_Window tkwin);
MODULE_SCOPE int RbcGraphType(

    RbcGraph * graphPtr);

/* rbcGrAxis.c */
MODULE_SCOPE double RbcInvHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcInvVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double y);
MODULE_SCOPE RbcPoint2D RbcMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE RbcPoint2D RbcInvMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE void RbcResetAxes(

    RbcGraph * graphPtr);
MODULE_SCOPE void RbcGetAxisSegments(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    RbcSegment2D ** segPtrPtr,
    int *nSegmentsPtr);
MODULE_SCOPE void RbcLayoutMargins(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcDefaultAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcVirtualAxisOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcAxisOp(
    RbcGraph * graphPtr,
    int margin,
    int argc,
    const char **argv);
MODULE_SCOPE void RbcMapAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawAxes(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcAxesToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDrawAxisLimits(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcAxisLimitsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE RbcAxis *RbcGetFirstAxis(
    RbcChain * chainPtr);
MODULE_SCOPE RbcAxis *RbcNearestAxis(
    RbcGraph * graphPtr,
    int x,
    int y);
MODULE_SCOPE ClientData RbcMakeAxisTag(
    RbcGraph * graphPtr,
    const char *tagName);

/* rbcGrBar.c */
MODULE_SCOPE RbcPen *RbcBarPen(
    const char *penName);
MODULE_SCOPE RbcElement *RbcBarElement(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid type);
MODULE_SCOPE void RbcInitFreqTable(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcComputeStacks(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcResetStacks(
    RbcGraph * graphPtr);

/* rbcGrElem.c */
MODULE_SCOPE double RbcFindElemVectorMinimum(
    RbcElemVector * vecPtr,
    double minLimit);
MODULE_SCOPE void RbcFreePalette(
    RbcGraph * graphPtr,
    RbcChain * palette);
MODULE_SCOPE int RbcStringToStyles(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,

    const char *string,
    char *widgRec,
    int offset);
MODULE_SCOPE const char *RbcStylesToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);
MODULE_SCOPE RbcPenStyle **RbcStyleMap(
    RbcElement * elemPtr);
MODULE_SCOPE void RbcMapErrorBars(
    RbcGraph * graphPtr,
    RbcElement * elemPtr,
    RbcPenStyle ** dataToStyle);
MODULE_SCOPE void RbcDestroyElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcMapElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawElements(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawActiveElements(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcActiveElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE int RbcGraphUpdateNeeded(
    RbcGraph * graphPtr);
MODULE_SCOPE ClientData RbcMakeElementTag(
    RbcGraph * graphPtr,
    const char *tagName);
MODULE_SCOPE int RbcElementOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    RbcUid classUid);

/* rbcGrGrid.c */
MODULE_SCOPE void RbcMapGrid(

    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawGrid(

    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcGridToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDestroyGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcGridOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrHairs.c */
MODULE_SCOPE void RbcConfigureCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcEnableCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDisableCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcUpdateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCrosshairsOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrLegd.c */
MODULE_SCOPE void RbcMapLegend(

    RbcLegend * legendPtr,
    int width,
    int height);
MODULE_SCOPE void RbcDrawLegend(

    RbcLegend * legendPtr,
    Drawable drawable);
MODULE_SCOPE void RbcLegendToPostScript(
    RbcLegend * legendPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDestroyLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcLegendOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcLegendSite(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendWidth(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendHeight(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsHidden(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsRaised(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendX(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendY(
    RbcLegend * legendPtr);
MODULE_SCOPE void RbcLegendRemoveElement(
    RbcLegend * legendPtr,
    RbcElement * elemPtr);

/* rbcGrLine.c */
MODULE_SCOPE RbcPen *RbcLinePen(
    const char *penName);
MODULE_SCOPE RbcElement *RbcLineElement(
    RbcGraph *graphPtr,
    const char *name,
    RbcUid classUid);

/* rbcGrMarker.c */
MODULE_SCOPE ClientData RbcMakeMarkerTag(
    RbcGraph * graphPtr,
    const char *tagName);
MODULE_SCOPE int RbcMarkerOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE void RbcMarkersToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    int under);
MODULE_SCOPE void RbcDrawMarkers(
    RbcGraph * graphPtr,
    Drawable drawable,
    int under);
MODULE_SCOPE void RbcMapMarkers(

    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyMarkers(
    RbcGraph * graphPtr);
MODULE_SCOPE RbcMarker *RbcNearestMarker(
    RbcGraph * graphPtr,
    int x,
    int y,
    int under);



/* rbcGrMisc.c */
MODULE_SCOPE int RbcGetXY(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int *x,
    int *y);
MODULE_SCOPE void RbcFreeColorPair(


    RbcColorPair * pairPtr);
MODULE_SCOPE int RbcPointInSegments(
    RbcPoint2D * samplePtr,
    RbcSegment2D * segments,
    int nSegments,
    double halo);
MODULE_SCOPE int RbcPointInPolygon(
    RbcPoint2D * samplePtr,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE int RbcRegionInPolygon(
    RbcExtents2D * extsPtr,
    RbcPoint2D * points,
    int nPoints,
    int enclosed);
MODULE_SCOPE void RbcGraphExtents(

    RbcGraph * graphPtr,
    RbcExtents2D * extsPtr);
MODULE_SCOPE int RbcLineRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * p,
    RbcPoint2D * q);
MODULE_SCOPE int RbcPolyRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * inputPts,
    int nInputPts,
    RbcPoint2D * outputPts);
MODULE_SCOPE RbcPoint2D RbcGetProjection(
    int x,
    int y,
    RbcPoint2D * p,
    RbcPoint2D * q);
MODULE_SCOPE int RbcAdjustViewport(
    int offset,
    int worldSize,
    int windowSize,
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE int RbcGetScrollInfo(
................................................................................
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE void RbcUpdateScrollbar(
    Tcl_Interp * interp,
    char *scrollCmd,
    double firstFract,
    double lastFract);
MODULE_SCOPE GC RbcGetPrivateGCFromDrawable(
    Display * display,
    Drawable drawable,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE GC RbcGetPrivateGC(
    Tk_Window tkwin,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE void RbcFreePrivateGC(
    Display * display,
    GC gc);
MODULE_SCOPE void RbcSetDashes(
    Display * display,
    GC gc,
    RbcDashes * dashesPtr);
MODULE_SCOPE int RbcSimplifyLine(
    RbcPoint2D * origPts,
    int low,
    int high,
    double tolerance,
    int indices[]);
MODULE_SCOPE void RbcDraw2DSegments(
    Display * display,
    Drawable drawable,
    GC gc,
    RbcSegment2D * segments,
    int nSegments);
MODULE_SCOPE int RbcMaxRequestSize(
    Display * display,
    unsigned int elemSize);

/* rbcPen.c */
MODULE_SCOPE void RbcFreePen(
    RbcGraph * graphPtr,
    RbcPen * penPtr);
MODULE_SCOPE RbcPen *RbcCreatePen(
    RbcGraph * graphPtr,
    const char *penName,
    RbcUid classUid,
    int nOpts,
    const char **options);
MODULE_SCOPE int RbcGetPen(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid classUid,
    RbcPen ** penPtrPtr);
MODULE_SCOPE void RbcDestroyPens(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcPenOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrPs.c */
MODULE_SCOPE void RbcDestroyPostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreatePostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcPostScriptOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);

/* rbcImage.c */
MODULE_SCOPE RbcColorImage *RbcCreateColorImage(
    int width,
    int height);
MODULE_SCOPE void RbcFreeColorImage(
    RbcColorImage * image);
MODULE_SCOPE void RbcGammaCorrectColorImage(
    RbcColorImage * src,
    double newGamma);
MODULE_SCOPE void RbcColorImageToGreyscale(
    RbcColorImage * image);
MODULE_SCOPE void RbcColorImageToPhoto(
    Tcl_Interp * interp,
    RbcColorImage * image,
    Tk_PhotoHandle photo);

MODULE_SCOPE RbcColorImage *RbcPhotoRegionToColorImage(
    Tk_PhotoHandle photo,
    int x,
    int y,
    int width,
    int height);

MODULE_SCOPE RbcColorImage *RbcPhotoToColorImage(
    Tk_PhotoHandle photo);
MODULE_SCOPE int RbcGetResampleFilter(
    Tcl_Interp * interp,
    char *filterName,
    RbcResampleFilter ** filterPtrPtr);
MODULE_SCOPE RbcColorImage *RbcResampleColorImage(
    RbcColorImage * image,
    int destWidth,
    int destHeight,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);
MODULE_SCOPE void RbcResamplePhoto(
................................................................................
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);
MODULE_SCOPE void RbcResizePhoto(
    Tcl_Interp * interp,
    Tk_PhotoHandle srcPhoto,
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto);
MODULE_SCOPE RbcColorImage *RbcResizeColorImage(
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
................................................................................
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight);
MODULE_SCOPE RbcColorImage *RbcConvolveColorImage(
    RbcColorImage * srcImage,
    RbcFilter2D * filter);








MODULE_SCOPE int RbcSnapPhoto(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight,
    const char *photoName,
    double inputGamma);
MODULE_SCOPE RbcColorImage *RbcRotateColorImage(
    RbcColorImage * image,
    double theta);
MODULE_SCOPE int RbcQuantizeColorImage(
    RbcColorImage * src,
    RbcColorImage * dest,
    int nColors);
MODULE_SCOPE RbcRegion2D *RbcSetRegion(
    int x,
    int y,
    int width,
    int height,
    RbcRegion2D * regionPtr);
















MODULE_SCOPE Tk_Image RbcCreateTemporaryImage(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData);
MODULE_SCOPE int RbcDestroyTemporaryImage(
    Tcl_Interp * interp,
    Tk_Image tkImage);
MODULE_SCOPE const char *RbcNameOfImage(

    Tk_Image tkImage);

/* rbcList.c */
MODULE_SCOPE RbcList *RbcListCreate(



















    int type);
































































































































MODULE_SCOPE RbcListNode *RbcListCreateNode(



    RbcList * list,
    const char *key);














































































MODULE_SCOPE void RbcListReset(











    RbcList * list);
MODULE_SCOPE void RbcListDestroy(



    RbcList * list);
MODULE_SCOPE void RbcListInit(





    RbcList * list,
    int type);








MODULE_SCOPE void RbcListLinkAfter(
















    RbcList * list,
    RbcListNode * node,
    RbcListNode * afterNode);
MODULE_SCOPE void RbcListLinkBefore(





    RbcList * list,
    RbcListNode * node,
    RbcListNode * beforeNode);
MODULE_SCOPE void RbcListUnlinkNode(










    RbcListNode * node);
MODULE_SCOPE RbcListNode *RbcListGetNode(





    RbcList * list,
    const char *key);



MODULE_SCOPE void RbcListDeleteNode(









    RbcListNode * node);
MODULE_SCOPE void Rb_ListDeleteNodeByKey(









    RbcList * list,
    const char *key);


MODULE_SCOPE RbcListNode *RbcListAppend(



    RbcList * list,
    const char *key,













    ClientData clientData);
MODULE_SCOPE RbcListNode *RbcListPrepend(



    RbcList * list,
    const char *key,

































    ClientData clientData);
MODULE_SCOPE RbcListNode *RbcListGetNthNode(

    RbcList * list,
    int position,
    int direction);

MODULE_SCOPE void RbcListSort(




    RbcList * list,
    RbcListCompareProc * proc);
MODULE_SCOPE int RbcImageIsDeleted(

    Tk_Image tkImage);

/* rbcParse.c */
MODULE_SCOPE void RbcExpandParseValue(
    RbcParseValue * parsePtr,
    int needed);
MODULE_SCOPE int RbcParseNestedCmd(
    Tcl_Interp * interp,
    char *string,
................................................................................
MODULE_SCOPE int RbcParseQuotes(
    Tcl_Interp * interp,
    char *string,
    int termChar,
    int flags,
    char **termPtr,
    RbcParseValue * parsePtr);

/* rbcPs.c */
MODULE_SCOPE RbcPsToken *RbcGetPsToken(
    Tcl_Interp * interp,
    Tk_Window tkwin);
MODULE_SCOPE void RbcReleasePsToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcPostScriptFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcScratchBufferFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE void RbcAppendToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcFormatToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE int RbcFileToPostScript(
    RbcPsToken * psToken,
    const char *fileName);
MODULE_SCOPE void RbcBackgroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcForegroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcBitmapDataToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    int width,
    int height);
MODULE_SCOPE int RbcColorImageToPsData(
    RbcColorImage * image,
    int nComponents,
    Tcl_DString * resultPtr,
    const char *prefix);
MODULE_SCOPE void RbcClearBackgroundToPostScript(
    RbcPsToken * psToken);
MODULE_SCOPE void RbcLineWidthToPostScript(
    RbcPsToken * psToken,
    int lineWidth);
MODULE_SCOPE void RbcLineDashesToPostScript(
    RbcPsToken * psToken,
    RbcDashes * dashesPtr);
MODULE_SCOPE void RbcLineAttributesToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr,
    int lineWidth,
    RbcDashes * dashesPtr,
    int capStyle,
    int joinStyle);
MODULE_SCOPE void RbcRectangleToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcRegionToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcPathToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcPolygonToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcSegmentsToPostScript(
    RbcPsToken * psToken,
    XSegment * segArr,
    int nSegs);
MODULE_SCOPE void RbcRectanglesToPostScript(
    RbcPsToken * psToken,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE void RbcDraw3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcFill3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcStippleToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap);
MODULE_SCOPE void RbcColorImageToPostScript(
    RbcPsToken * psToken,
    RbcColorImage * image,
    double x,
    double y);
MODULE_SCOPE void RbcWindowToPostScript(
    RbcPsToken * psToken,
    Tk_Window tkwin,
    double x,
    double y);
MODULE_SCOPE void RbcPhotoToPostScript(
    RbcPsToken * psToken,
    Tk_PhotoHandle photoToken,
    double x,
    double y);
MODULE_SCOPE void RbcFontToPostScript(
    RbcPsToken * psToken,
    Tk_Font font);
MODULE_SCOPE void RbcTextToPostScript(
    RbcPsToken * psToken,
    char *string,
    RbcTextStyle * attrPtr,
    double x,
    double y);
MODULE_SCOPE void RbcLineToPostScript(
    RbcPsToken * psToken,
    XPoint * pointArr,
    int nPoints);
MODULE_SCOPE void RbcBitmapToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    double scaleX,
    double scaleY);
MODULE_SCOPE void Rbc2DSegmentsToPostScript(
    RbcPsToken * psToken,
    RbcSegment2D * segments,
    int nSegments);

/* rbcSpline.c */
MODULE_SCOPE int RbcQuadraticSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcNaturalSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcSplineInit(
    Tcl_Interp * interp);
MODULE_SCOPE int RbcNaturalParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcExtents2D * extsPtr,
    int isClosed,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcCatromParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);

/* rbcSwitch.c */
MODULE_SCOPE int RbcProcessSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specs,
    int argc,
    const char **argv,
    char *record,
    int flags);







MODULE_SCOPE int RbcProcessObjSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specPtr,
    int objc,
    Tcl_Obj * const *objv,
    char *record,
    int flags);
MODULE_SCOPE void RbcFreeSwitches(
    RbcSwitchSpec * specs,
    char *record,
    int flags);
MODULE_SCOPE int RbcSwitchChanged(
    RbcSwitchSpec * specs,
    ...);

/* rbcText.c */
MODULE_SCOPE RbcTextLayout *RbcGetTextLayout(
    char *string,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcGetTextExtents(





    RbcTextStyle * stylePtr,
    char *text,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcGetBoundingBox(
    int width,
    int height,
    double theta,
    double *widthPtr,
    double *heightPtr,
    RbcPoint2D * points);
MODULE_SCOPE void RbcTranslateAnchor(
    int x,


    int y,
    int width,
    int height,
    Tk_Anchor anchor,
    int *transXPtr,
    int *transYPtr);
MODULE_SCOPE RbcPoint2D RbcTranslatePoint(
    RbcPoint2D * pointPtr,
    int width,
    int height,
    Tk_Anchor anchor);
MODULE_SCOPE Pixmap RbcCreateTextBitmap(
    Tk_Window tkwin,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcInitTextStyle(
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcSetDrawTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    GC gc,
    XColor * normalColor,
    XColor * activeColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcSetPrintTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    XColor * fgColor,
    XColor * bgColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcDrawTextLayout(

    Tk_Window tkwin,
    Drawable drawable,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int x,
    int y);
MODULE_SCOPE void RbcDrawText2(


    Tk_Window tkwin,
    Drawable drawable,
    char *string,





    RbcTextStyle * stylePtr,
    int x,
    int y,
    RbcDim2D * dimPtr);
MODULE_SCOPE void RbcDrawText(


    Tk_Window tkwin,
    Drawable drawable,
    char *string,
    RbcTextStyle * stylePtr,
    int x,
    int y);

MODULE_SCOPE GC RbcGetBitmapGC(



    Tk_Window tkwin);
MODULE_SCOPE void RbcResetTextStyle(
    Tk_Window tkwin,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcFreeTextStyle(

    Display * display,
    RbcTextStyle * stylePtr);

/* rbcTile.c */
MODULE_SCOPE int RbcGetTile(
    Tcl_Interp * interp,

    Tk_Window tkwin,
    const char *imageName,


    RbcTile * tilePtr);
MODULE_SCOPE void RbcFreeTile(


    RbcTile tile);
MODULE_SCOPE const char *RbcNameOfTile(
    RbcTile tile);
Pixmap          RbcPixmapOfTile(
    RbcTile tile);
MODULE_SCOPE void RbcSizeOfTile(

    RbcTile tile,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcSetTileChangedProc(
    RbcTile tile,
    RbcTileChangedProc * changeProc,
    ClientData clientData);
MODULE_SCOPE void RbcSetTileOrigin(
    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);
MODULE_SCOPE void RbcSetTSOrigin(

    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);

MODULE_SCOPE void RbcTilePolygon(



    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XPoint * pointArr,
    int nPoints);
MODULE_SCOPE void RbcTileRectangle(


    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    int x,
    int y,

    unsigned int width,
    unsigned int height);
MODULE_SCOPE void RbcTileRectangles(







    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XRectangle * rectArr,
    int nRects);

/* rbcUtil.c */
MODULE_SCOPE char *RbcItoa(

    int value);
MODULE_SCOPE char *RbcUtoa(



    unsigned int value);
MODULE_SCOPE char *RbcDtoa(
    Tcl_Interp * interp,

    double value);
MODULE_SCOPE RbcUid RbcGetUid(

    const char *string);
MODULE_SCOPE void RbcFreeUid(



    RbcUid uid);
MODULE_SCOPE RbcUid RbcFindUid(

    char *string);
MODULE_SCOPE RbcOp RbcGetOp(
    Tcl_Interp * interp,
    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int argc,
    const char **argv,

    int flags);
MODULE_SCOPE RbcOp RbcGetOpFromObj(
    Tcl_Interp * interp,

    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int objc,

    Tcl_Obj * const *objv,
    int flags);

/* rbcVecMath.c */
MODULE_SCOPE void RbcVectorInstallMathFunctions(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE void RbcVectorInstallSpecialIndices(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE double RbcVecMin(
    RbcVector * vecPtr);

MODULE_SCOPE double RbcVecMax(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcExprVector(
    Tcl_Interp * interp,
    char *string,
    RbcVector * vecPtr);











/* rbcVecObjCmd.c */
MODULE_SCOPE int RbcAppendOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcArithOp(
................................................................................
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcOffsetOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcPopulateOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRandomOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRangeOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
................................................................................
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcVariableOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int *RbcVectorSortIndex(
    RbcVectorObject ** vPtrPtr,
    int nVectors);

/* rbcVector.c */
MODULE_SCOPE double Rbcdrand48(
    void);
MODULE_SCOPE int RbcVectorInit(
    Tcl_Interp * interp);
MODULE_SCOPE RbcVectorInterpData *RbcVectorGetInterpData(
    Tcl_Interp * interp);
MODULE_SCOPE RbcVectorObject *RbcVectorNew(
    RbcVectorInterpData * dataPtr);
MODULE_SCOPE RbcVectorObject *RbcVectorCreate(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int *newPtr);
MODULE_SCOPE void RbcVectorFree(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorDuplicate(
    RbcVectorObject * destPtr,
    RbcVectorObject * srcPtr);
MODULE_SCOPE void RbcVectorFlushCache(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorMapVariable(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *name);
MODULE_SCOPE int RbcVectorReset(
    RbcVectorObject * vPtr,
    double *valueArr,
    int length,
    int size,
    Tcl_FreeProc * freeProc);
MODULE_SCOPE int RbcVectorNotifyPending(
    RbcVectorId clientId);
MODULE_SCOPE int RbcVectorChangeLength(
    RbcVectorObject * vPtr,
    int length);
MODULE_SCOPE int RbcVectorLookupName(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    RbcVectorObject ** vPtrPtr);
MODULE_SCOPE void RbcVectorUpdateRange(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
MODULE_SCOPE int RbcVectorGetIndexRange(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
RbcVectorObject *RbcVectorParseElement(
    Tcl_Interp * interp,
    RbcVectorInterpData * dataPtr,
    const char *start,
    char **endPtr,
    int flags);
MODULE_SCOPE void RbcVectorUpdateClients(

    RbcVectorObject * vPtr);
MODULE_SCOPE Tcl_Obj *RbcGetValues(
    RbcVectorObject * vPtr,
    int first,
    int last);
MODULE_SCOPE void RbcReplicateValue(
    RbcVectorObject * vPtr,
    int first,
    int last,
    double value);
MODULE_SCOPE int RbcGetDouble(
    Tcl_Interp * interp,
    Tcl_Obj * objPtr,
    double *valuePtr);
MODULE_SCOPE void RbcFreeVectorId(

    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcVectorExists2(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE RbcVectorId RbcAllocVectorId(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE void RbcSetVectorChangedProc(
    RbcVectorId clientId,
    RbcVectorChangedProc * proc,
    ClientData clientData);
MODULE_SCOPE char *RbcNameOfVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVector(
    Tcl_Interp * interp,
    const char *vecName,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector(
    Tcl_Interp * interp,
    const char *vecName,
    int size,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcResizeVector(
    RbcVector * vecPtr,
    int nValues);
MODULE_SCOPE char *RbcNameOfVector(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcResetVector(
    RbcVector * vecPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);


/* rbcWindow.c */
MODULE_SCOPE Tk_Window RbcFindChild(
    Tk_Window parent,
    char *name);
MODULE_SCOPE void RbcSetWindowInstanceData(
    Tk_Window tkwin,
    ClientData instanceData);
MODULE_SCOPE ClientData RbcGetWindowInstanceData(
    Tk_Window tkwin);
MODULE_SCOPE void RbcDeleteWindowInstanceData(
    Tk_Window tkwin);

/* rbcWinImage.c rbcUnixImage.c */
MODULE_SCOPE RbcColorImage *RbcDrawableToColorImage(
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
................................................................................
    int regionX,
    int regionY,
    unsigned int regionWidth,
    unsigned int regionHeight,
    unsigned int virtWidth,
    unsigned int virtHeight,
    double theta);



/* Windows */
#ifdef _WIN32
#include "rbcWin.h"
#endif

#ifndef _WIN32

Changes to generic/rbc/rbcList.c.

9
10
11
12
13
14
15












16
17
18
19
20
21
22
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"













static RbcListNode *FindString(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindOneWord(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindArray(






>
>
>
>
>
>
>
>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/* ClientData RbcListGetValue((RbcListNode *node); */
#define RbcListGetValue(node)  	((node)->clientData)
/* void RbcListSetValue((RbcListNode *node, ClientData value); */
#define RbcListSetValue(node, value) \
	((node)->clientData = (ClientData)(value))

#define RbcListAppendNode(list, node) \
	(RbcListLinkBefore((list), (node), (RbcListNode *)NULL))

#define RbcListPrependNode(list, node) \
	(RbcListLinkAfter((list), (node), (RbcListNode *)NULL))

static RbcListNode *FindString(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindOneWord(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindArray(

Changes to generic/rbc/rbcPs.c.

876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
...
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
{
    RbcAppendToPostScript(tokenPtr, " 1.0 1.0 1.0 SetBgColor\n", (char *) NULL);
}

/*
 *--------------------------------------------------------------
 *
 * RbcCapStyleToPostScript --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcCapStyleToPostScript(
    RbcPsToken * tokenPtr,
    int capStyle)
{
    /*
     * X11:not last = 0, butt = 1, round = 2, projecting = 3
     * PS: butt = 0, round = 1, projecting = 2
     */
................................................................................
    }
    RbcFormatToPostScript(tokenPtr, "%d setlinecap\n", capStyle);
}

/*
 *--------------------------------------------------------------
 *
 * RbcJoinStyleToPostScript --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcJoinStyleToPostScript(
    RbcPsToken * tokenPtr,
    int joinStyle)
{
    /*
     * miter = 0, round = 1, bevel = 2
     */
    RbcFormatToPostScript(tokenPtr, "%d setlinejoin\n", joinStyle);
................................................................................
    RbcPsToken * tokenPtr,
    XColor * colorPtr,
    int lineWidth,
    RbcDashes * dashesPtr,
    int capStyle,
    int joinStyle)
{
    RbcJoinStyleToPostScript(tokenPtr, joinStyle);
    RbcCapStyleToPostScript(tokenPtr, capStyle);
    RbcForegroundToPostScript(tokenPtr, colorPtr);
    RbcLineWidthToPostScript(tokenPtr, lineWidth);
    RbcLineDashesToPostScript(tokenPtr, dashesPtr);
    RbcAppendToPostScript(tokenPtr, "/DashesProc {} def\n", (char *) NULL);
}

/*






|












|







 







|












|







 







|
|







876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
...
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
{
    RbcAppendToPostScript(tokenPtr, " 1.0 1.0 1.0 SetBgColor\n", (char *) NULL);
}

/*
 *--------------------------------------------------------------
 *
 * CapStyleToPostScript --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
CapStyleToPostScript(
    RbcPsToken * tokenPtr,
    int capStyle)
{
    /*
     * X11:not last = 0, butt = 1, round = 2, projecting = 3
     * PS: butt = 0, round = 1, projecting = 2
     */
................................................................................
    }
    RbcFormatToPostScript(tokenPtr, "%d setlinecap\n", capStyle);
}

/*
 *--------------------------------------------------------------
 *
 * JoinStyleToPostScript --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
JoinStyleToPostScript(
    RbcPsToken * tokenPtr,
    int joinStyle)
{
    /*
     * miter = 0, round = 1, bevel = 2
     */
    RbcFormatToPostScript(tokenPtr, "%d setlinejoin\n", joinStyle);
................................................................................
    RbcPsToken * tokenPtr,
    XColor * colorPtr,
    int lineWidth,
    RbcDashes * dashesPtr,
    int capStyle,
    int joinStyle)
{
    JoinStyleToPostScript(tokenPtr, joinStyle);
    CapStyleToPostScript(tokenPtr, capStyle);
    RbcForegroundToPostScript(tokenPtr, colorPtr);
    RbcLineWidthToPostScript(tokenPtr, lineWidth);
    RbcLineDashesToPostScript(tokenPtr, dashesPtr);
    RbcAppendToPostScript(tokenPtr, "/DashesProc {} def\n", (char *) NULL);
}

/*

Changes to generic/rbc/rbcSwitch.c.

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
                != TCL_OK) {
                return TCL_ERROR;
            }
            break;

        case RBC_SWITCH_CUSTOM:
            if ((*specPtr->customPtr->parseProc)
                (specPtr->customPtr->clientData, interp, specPtr->switchName,
                    string, record, specPtr->offset) != TCL_OK) {
                return TCL_ERROR;
            }
            break;

        default:
            Tcl_AppendResult(interp, "bad switch table: unknown type \"",
                RbcItoa(specPtr->type), "\"", (char *) NULL);






|
|







195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
                != TCL_OK) {
                return TCL_ERROR;
            }
            break;

        case RBC_SWITCH_CUSTOM:
            if ((*specPtr->customPtr->parseProc)
                (specPtr->customPtr->clientData, interp, (char *)specPtr->switchName,
                    (char *)string, record, specPtr->offset) != TCL_OK) {
                return TCL_ERROR;
            }
            break;

        default:
            Tcl_AppendResult(interp, "bad switch table: unknown type \"",
                RbcItoa(specPtr->type), "\"", (char *) NULL);

Changes to generic/rbc/rbcText.c.

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    RbcTextLayout * textPtr)
{
    register RbcTextFragment *fragPtr;
    register int    i;

    fragPtr = textPtr->fragArr;
    for (i = 0; i < textPtr->nFrags; i++, fragPtr++) {
#if HAVE_UTF
        Tk_DrawChars(display, drawable, gc, font, fragPtr->text, fragPtr->count,
            x + fragPtr->x, y + fragPtr->y);
#else
        XDrawString(display, drawable, gc, x + fragPtr->x, y + fragPtr->y,
            fragPtr->text, fragPtr->count);
#endif /*HAVE_UTF */
    }
}

/*
 * -----------------------------------------------------------------
 *
 * RbcGetTextLayout --






<


<
<
<
<







53
54
55
56
57
58
59

60
61




62
63
64
65
66
67
68
    RbcTextLayout * textPtr)
{
    register RbcTextFragment *fragPtr;
    register int    i;

    fragPtr = textPtr->fragArr;
    for (i = 0; i < textPtr->nFrags; i++, fragPtr++) {

        Tk_DrawChars(display, drawable, gc, font, fragPtr->text, fragPtr->count,
            x + fragPtr->x, y + fragPtr->y);




    }
}

/*
 * -----------------------------------------------------------------
 *
 * RbcGetTextLayout --

Changes to generic/rbc/rbcTile.c.

2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 * rbcTile.c --
 *
 *      This module manages images for tiled backgrounds for the rbc toolkit.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

#define TILE_THREAD_KEY	"Rbc Tile Data"
#define TILE_MAGIC ((unsigned int) 0x46170277)
typedef struct {
    Tcl_HashTable tileTable; /* Hash table of tile structures keyed by
                              * the name of the image. */
    Tcl_Interp *interp;
} TileInterpData;
................................................................................
UpdateTile(
    ClientData clientData)
{
    Tile *tilePtr = (Tile *)clientData;
    RbcTileClient *clientPtr;
    RbcChainLink *linkPtr;
    tilePtr->flags &= ~TILE_NOTIFY_PENDING;
    if (Tk_ImageIsDeleted(tilePtr->tkImage)) {
        if (tilePtr->pixmap != None) {
            Tk_FreePixmap(tilePtr->display, tilePtr->pixmap);
        }
        tilePtr->pixmap = None;
    } else {
        /* Pick any client window to generate the new pixmap. */
        linkPtr = RbcChainFirstLink(tilePtr->clients);






|





>







 







|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 * rbcTile.c --
 *
 *      This module manages images for tiled backgrounds for the rbc toolkit.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

#define TILE_THREAD_KEY	"Rbc Tile Data"
#define TILE_MAGIC ((unsigned int) 0x46170277)
typedef struct {
    Tcl_HashTable tileTable; /* Hash table of tile structures keyed by
                              * the name of the image. */
    Tcl_Interp *interp;
} TileInterpData;
................................................................................
UpdateTile(
    ClientData clientData)
{
    Tile *tilePtr = (Tile *)clientData;
    RbcTileClient *clientPtr;
    RbcChainLink *linkPtr;
    tilePtr->flags &= ~TILE_NOTIFY_PENDING;
    if (RbcImageIsDeleted(tilePtr->tkImage)) {
        if (tilePtr->pixmap != None) {
            Tk_FreePixmap(tilePtr->display, tilePtr->pixmap);
        }
        tilePtr->pixmap = None;
    } else {
        /* Pick any client window to generate the new pixmap. */
        linkPtr = RbcChainFirstLink(tilePtr->clients);

Changes to generic/rbc/rbcUtil.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/*
#include <ctype.h>
#include <stdarg.h>
*/

static int      BinaryOpSearch(
    RbcOpSpec specArr[],
    int nSpecs,
    const char *string);
static int      LinearOpSearch(
    RbcOpSpec specArr[],
    int nSpecs,
    const char *string);

#if HAVE_UTF

/*
 *----------------------------------------------------------------------
 *
 * RbcDictionaryCompare
 *
 *      This function compares two strings as if they were being used in
 *      an index or card catalog.  The case of alphabetic characters is
 *      ignored, except to break ties.  Thus "B" comes before "b" but
 *      after "a".  Also, integers embedded in the strings compare in
 *      numerical order.  In other words, "x10y" comes after "x9y", not
 *      before it as it would when using strcmp().
 *
 * Results:
 *      A negative result means that the first element comes before the
 *      second, and a positive result means that the second element
 *      should come first.  A result of zero means the two elements
 *      are equal and it doesn't matter which comes first.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
int
RbcDictionaryCompare(
    char *left,
    char *right)
{
    Tcl_UniChar     uniLeft, uniRight, uniLeftLower, uniRightLower;
    int             diff, zeros;
    int             secondaryDiff = 0;

    for (;;) {
        if ((isdigit(UCHAR(*right))) && (isdigit(UCHAR(*left)))) {
            /*
             * There are decimal numbers embedded in the two
             * strings.  Compare them as numbers, rather than
             * strings.  If one number has more leading zeros than
             * the other, the number with more leading zeros sorts
             * later, but only as a secondary choice.
             */

            zeros = 0;
            while ((*right == '0') && (isdigit(UCHAR(right[1])))) {
                right++;
                zeros--;
            }
            while ((*left == '0') && (isdigit(UCHAR(left[1])))) {
                left++;
                zeros++;
            }
            if (secondaryDiff == 0) {
                secondaryDiff = zeros;
            }

            /*
             * The code below compares the numbers in the two
             * strings without ever converting them to integers.  It
             * does this by first comparing the lengths of the
             * numbers and then comparing the digit values.
             */

            diff = 0;
            for (;;) {
                if (diff == 0) {
                    diff = UCHAR(*left) - UCHAR(*right);
                }
                right++;
                left++;

                /* Ignore commas in numbers. */
                if (*left == ',') {
                    left++;
                }
                if (*right == ',') {
                    right++;
                }

                if (!isdigit(UCHAR(*right))) {  /* INTL: digit */
                    if (isdigit(UCHAR(*left))) {        /* INTL: digit */
                        return 1;
                    } else {
                        /*
                         * The two numbers have the same length. See
                         * if their values are different.
                         */

                        if (diff != 0) {
                            return diff;
                        }
                        break;
                    }
                } else if (!isdigit(UCHAR(*left))) {    /* INTL: digit */
                    return -1;
                }
            }
            continue;
        }

        /*
         * Convert character to Unicode for comparison purposes.  If either
         * string is at the terminating null, do a byte-wise comparison and
         * bail out immediately.
         */
        if ((*left != '\0') && (*right != '\0')) {
            left += Tcl_UtfToUniChar(left, &uniLeft);
            right += Tcl_UtfToUniChar(right, &uniRight);
            /*
             * Convert both chars to lower for the comparison, because
             * dictionary sorts are case insensitve.  Convert to lower, not
             * upper, so chars between Z and a will sort before A (where most
             * other interesting punctuations occur)
             */
            uniLeftLower = Tcl_UniCharToLower(uniLeft);
            uniRightLower = Tcl_UniCharToLower(uniRight);
        } else {
            diff = UCHAR(*left) - UCHAR(*right);
            break;
        }

        diff = uniLeftLower - uniRightLower;
        if (diff) {
            return diff;
        } else if (secondaryDiff == 0) {
            if (Tcl_UniCharIsUpper(uniLeft) && Tcl_UniCharIsLower(uniRight)) {
                secondaryDiff = -1;
            } else if (Tcl_UniCharIsUpper(uniRight)
                && Tcl_UniCharIsLower(uniLeft)) {
                secondaryDiff = 1;
            }
        }
    }
    if (diff == 0) {
        diff = secondaryDiff;
    }
    return diff;
}

#else

/*
 *--------------------------------------------------------------
 *
 * RbcDictionaryCompare --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcDictionaryCompare(
    char *left,                 /* Left string of the comparison */
    char *right)
{                               /* Right string of the comparison */
    int             diff, zeros;
    int             secondaryDiff = 0;

    while (1) {
        if (isdigit(UCHAR(*right)) && isdigit(UCHAR(*left))) {
            /*
             * There are decimal numbers embedded in the two
             * strings.  Compare them as numbers, rather than
             * strings.  If one number has more leading zeros than
             * the other, the number with more leading zeros sorts
             * later, but only as a secondary choice.
             */

            zeros = 0;
            while ((*right == '0') && (isdigit(UCHAR(right[1])))) {
                right++;
                zeros--;
            }
            while ((*left == '0') && (isdigit(UCHAR(left[1])))) {
                left++;
                zeros++;
            }
            if (secondaryDiff == 0) {
                secondaryDiff = zeros;
            }

            /*
             * The code below compares the numbers in the two
             * strings without ever converting them to integers.  It
             * does this by first comparing the lengths of the
             * numbers and then comparing the digit values.
             */

            diff = 0;
            while (1) {
                if (diff == 0) {
                    diff = UCHAR(*left) - UCHAR(*right);
                }
                right++;
                left++;
                /* Ignore commas in numbers. */
                if (*left == ',') {
                    left++;
                }
                if (*right == ',') {
                    right++;
                }
                if (!isdigit(UCHAR(*right))) {
                    if (isdigit(UCHAR(*left))) {
                        return 1;
                    } else {
                        /*
                         * The two numbers have the same length. See
                         * if their values are different.
                         */

                        if (diff != 0) {
                            return diff;
                        }
                        break;
                    }
                } else if (!isdigit(UCHAR(*left))) {
                    return -1;
                }
            }
            continue;
        }
        diff = UCHAR(*left) - UCHAR(*right);
        if (diff) {
            if (isupper(UCHAR(*left)) && islower(UCHAR(*right))) {
                diff = UCHAR(tolower(*left)) - UCHAR(*right);
                if (diff) {
                    return diff;
                } else if (secondaryDiff == 0) {
                    secondaryDiff = -1;
                }
            } else if (isupper(UCHAR(*right)) && islower(UCHAR(*left))) {
                diff = UCHAR(*left) - UCHAR(tolower(UCHAR(*right)));
                if (diff) {
                    return diff;
                } else if (secondaryDiff == 0) {
                    secondaryDiff = 1;
                }
            } else {
                return diff;
            }
        }
        if (*left == 0) {
            break;
        }
        left++;
        right++;
    }
    if (diff == 0) {
        diff = secondaryDiff;
    }
    return diff;
}
#endif

#ifndef NDEBUG

/*
 *--------------------------------------------------------------
 *
 * RbcAssert --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcAssert(
    char *testExpr,
    char *fileName,
    int lineNumber)
{
#ifdef WINDEBUG
    PurifyPrintf("line %d of %s: Assert \"%s\" failed\n", lineNumber,
        fileName, testExpr);
#endif
    fprintf(stderr, "line %d of %s: Assert \"%s\" failed\n",
        lineNumber, fileName, testExpr);
    fflush(stderr);
    abort();
}
#endif

/*
 *--------------------------------------------------------------
 *
 * RbcDStringAppendElements --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcDStringAppendElements(
    Tcl_DString * dsPtr,
    ...)
{
    va_list         argList;
    register char  *elem;

    va_start(argList, dsPtr);
    while ((elem = va_arg(argList, char *)) != NULL) {
        Tcl_DStringAppendElement(dsPtr, elem);
    }
    va_end(argList);
}

static char     stringRep[200];

/*
 *--------------------------------------------------------------
 *
 * RbcItoa --
................................................................................
    Tcl_Interp * interp,
    double value)
{
    Tcl_PrintDouble(interp, value, stringRep);
    return stringRep;
}

#if HAVE_UTF

#undef fopen

/*
 *--------------------------------------------------------------
 *
 * RbcOpenUtfFile --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
FILE           *
RbcOpenUtfFile(
    char *fileName,
    char *mode)
{
    Tcl_DString     dString;
    FILE           *f;

    fileName = Tcl_UtfToExternalDString(NULL, fileName, -1, &dString);
    f = fopen(fileName, mode);
    Tcl_DStringFree(&dString);
    return f;
}

#endif /* HAVE_UTF */

/*
 *--------------------------------------------------------------
 *
 * RbcInitHexTable --
 *
 *      Table index for the hex values. Initialized once, first time.
 *      Used for translation value or delimiter significance lookup.
 *
 *      We build the table at run time for several reasons:
 *
 *        1.  portable to non-ASCII machines.
 *        2.  still reentrant since we set the init flag after setting
 *            table.
 *        3.  easier to extend.
 *        4.  less prone to bugs.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcInitHexTable(
    char hexTable[])
{
    hexTable['0'] = 0;
    hexTable['1'] = 1;
    hexTable['2'] = 2;
    hexTable['3'] = 3;
    hexTable['4'] = 4;
    hexTable['5'] = 5;
    hexTable['6'] = 6;
    hexTable['7'] = 7;
    hexTable['8'] = 8;
    hexTable['9'] = 9;
    hexTable['a'] = hexTable['A'] = 10;
    hexTable['b'] = hexTable['B'] = 11;
    hexTable['c'] = hexTable['C'] = 12;
    hexTable['d'] = hexTable['D'] = 13;
    hexTable['e'] = hexTable['E'] = 14;
    hexTable['f'] = hexTable['F'] = 15;
}

/*
 *--------------------------------------------------------------
 *
 * RbcGetPosition --
 *
 *      Convert a string representing a numeric position.
 *      A position can be in one of the following forms.
 *
 *        number - number of the item in the hierarchy, indexed
 *                 from zero.
 *        "end"  - last position in the hierarchy.
 *
 * Results:
 *      A standard Tcl result.  If "string" is a valid index, then
 *      *indexPtr is filled with the corresponding numeric index.
 *      If "end" was selected then *indexPtr is set to -1.
 *      Otherwise an error message is left in interp->result.
 *
 * Side effects:
 *      None.
 *
 *--------------------------------------------------------------
 */
int
RbcGetPosition(
    Tcl_Interp * interp,        /* Interpreter to report results back
                                 * to. */
    char *string,               /* String representation of the index.
                                 * Can be an integer or "end" to refer
                                 * to the last index. */
    int *indexPtr)
{                               /* Holds the converted index. */
    if ((string[0] == 'e') && (strcmp(string, "end") == 0)) {
        *indexPtr = -1;         /* Indicates last position in hierarchy. */
    } else {
        int             position;

        if (Tcl_GetInt(interp, string, &position) != TCL_OK) {
            return TCL_ERROR;
        }
        if (position < 0) {
            Tcl_AppendResult(interp, "bad position \"", string, "\"",
                (char *) NULL);
            return TCL_ERROR;
        }
        *indexPtr = position;
    }
    return TCL_OK;
}

/*
 * The hash table below is used to keep track of all the RbcUids created
 * so far.
 */
static Tcl_HashTable uidTable;
static int      uidInitialized = 0;







<
<
<
<
<









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







10
11
12
13
14
15
16





17
18
19
20
21
22
23
24
25





































































































































































































































































































































26
27
28
29
30
31
32
..
92
93
94
95
96
97
98



































































































































99
100
101
102
103
104
105
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"






static int      BinaryOpSearch(
    RbcOpSpec specArr[],
    int nSpecs,
    const char *string);
static int      LinearOpSearch(
    RbcOpSpec specArr[],
    int nSpecs,
    const char *string);







































































































































































































































































































































static char     stringRep[200];

/*
 *--------------------------------------------------------------
 *
 * RbcItoa --
................................................................................
    Tcl_Interp * interp,
    double value)
{
    Tcl_PrintDouble(interp, value, stringRep);
    return stringRep;
}




































































































































/*
 * The hash table below is used to keep track of all the RbcUids created
 * so far.
 */
static Tcl_HashTable uidTable;
static int      uidInitialized = 0;

Changes to generic/rbc/rbcVecMath.c.

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        hPtr = Tcl_CreateHashEntry(tablePtr, mathPtr->name, &isNew);
        Tcl_SetHashValue(hPtr, (ClientData)mathPtr);
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcVectorInstallMathFunctions --
 *
 *      Creates a hash entry for every index
 *      and sets the value to the function.
 *
 * Results:
 *      None.
 *






|







212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        hPtr = Tcl_CreateHashEntry(tablePtr, mathPtr->name, &isNew);
        Tcl_SetHashValue(hPtr, (ClientData)mathPtr);
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcVectorInstallSpecialIndices --
 *
 *      Creates a hash entry for every index
 *      and sets the value to the function.
 *
 * Results:
 *      None.
 *

Changes to generic/rbc/rbcWin.h.

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#define Status int

/*
 * Add definitions missing from windgi.h, windowsx.h, and winspool.h
 */
#endif /* __GNUC__ */

/*
#define XCopyArea		RbcEmulateXCopyArea
#define XCopyPlane		RbcEmulateXCopyPlane
*/
#ifdef XDrawArcs
#undef XDrawArcs
#endif
#define XDrawArcs		RbcEmulateXDrawArcs

/*
#define XDrawLine		RbcEmulateXDrawLine
#define XDrawLines		RbcEmulateXDrawLines
*/
#ifdef XDrawPoints
#undef XDrawPoints
#endif
#define XDrawPoints		RbcEmulateXDrawPoints

/*
#define XDrawRectangle		RbcEmulateXDrawRectangle
*/
#ifdef XDrawRectangles
#undef XDrawRectangles
#endif
#define XDrawRectangles		RbcEmulateXDrawRectangles
#ifdef XDrawSegments
#undef XDrawSegments
#endif
#define XDrawSegments		RbcEmulateXDrawSegments
#ifdef XDrawString
#undef XDrawString
#endif
#define XDrawString		RbcEmulateXDrawString
#ifdef XFillArcs
#undef XFillArcs
#endif
#define XFillArcs		RbcEmulateXFillArcs

/*
#define XFillPolygon		RbcEmulateXFillPolygon
#define XFillRectangle		RbcEmulateXFillRectangle
#define XFillRectangles		RbcEmulateXFillRectangles
#define XFree			RbcEmulateXFree
#define XGetWindowAttributes	RbcEmulateXGetWindowAttributes
*/
#ifdef XLowerWindow
#undef XLowerWindow
#endif
#define XLowerWindow		RbcEmulateXLowerWindow
#ifdef XMaxRequestSize
#undef XMaxRequestSize
#endif
#define XMaxRequestSize		RbcEmulateXMaxRequestSize

/*
#define XRaiseWindow		RbcEmulateXRaiseWindow
*/
#ifdef XReparentWindow
#undef XReparentWindow
#endif
#define XReparentWindow		RbcEmulateXReparentWindow

/*
#define XSetDashes		RbcEmulateXSetDashes
#define XUnmapWindow		RbcEmulateXUnmapWindow
#define XWarpPointer		RbcEmulateXWarpPointer
*/

MODULE_SCOPE GC RbcEmulateXCreateGC(
    Display * display,
    Drawable drawable,
    unsigned long mask,
    XGCValues * valuesPtr);
MODULE_SCOPE void RbcEmulateXCopyArea(
    Display * display,
    Drawable src,
    Drawable dest,
    GC gc,
    int src_x,
    int src_y,
    unsigned int width,
    unsigned int height,
    int dest_x,
    int dest_y);
MODULE_SCOPE void RbcEmulateXCopyPlane(
    Display * display,
    Drawable src,
    Drawable dest,
    GC gc,
    int src_x,
    int src_y,
    unsigned int width,
    unsigned int height,
    int dest_x,
    int dest_y,
    unsigned long plane);
MODULE_SCOPE void RbcEmulateXDrawArcs(
    Display * display,
    Drawable drawable,
    GC gc,
    XArc * arcArr,
    int nArcs);
MODULE_SCOPE void RbcEmulateXDrawLine(
    Display * display,
    Drawable drawable,
    GC gc,
    int x1,
    int y1,
    int x2,
    int y2);
MODULE_SCOPE void RbcEmulateXDrawLines(
    Display * display,
    Drawable drawable,
    GC gc,
    XPoint * pointArr,
    int nPoints,
    int mode);
MODULE_SCOPE void RbcEmulateXDrawPoints(
    Display * display,
    Drawable drawable,
    GC gc,
    XPoint * pointArr,
    int nPoints,
    int mode);
MODULE_SCOPE void RbcEmulateXDrawRectangle(
    Display * display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    unsigned int width,
    unsigned int height);
MODULE_SCOPE void RbcEmulateXDrawRectangles(
    Display * display,
    Drawable drawable,
    GC gc,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE void RbcEmulateXDrawSegments(
    Display * display,
    Drawable drawable,
    GC gc,
    XSegment * segArr,
    int nSegments);
MODULE_SCOPE void RbcEmulateXDrawSegments(
    Display * display,
    Drawable drawable,
    GC gc,
    XSegment * segArr,
    int nSegments);
MODULE_SCOPE void RbcEmulateXDrawString(
    Display * display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    _Xconst char *string,
    int length);
MODULE_SCOPE void RbcEmulateXFillArcs(
    Display * display,
    Drawable drawable,
    GC gc,
    XArc * arcArr,
    int nArcs);
MODULE_SCOPE void RbcEmulateXFillPolygon(
    Display * display,
    Drawable drawable,
    GC gc,
    XPoint * points,
    int nPoints,
    int shape,
    int mode);
MODULE_SCOPE void RbcEmulateXFillRectangle(
    Display * display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    unsigned int width,
    unsigned int height);
MODULE_SCOPE void RbcEmulateXFillRectangles(
    Display * display,
    Drawable drawable,
    GC gc,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE int RbcEmulateXGetWindowAttributes(
    Display * display,
    Window window,
    XWindowAttributes * attrsPtr);
MODULE_SCOPE void RbcEmulateXMapWindow(
    Display * display,
    Window window);
MODULE_SCOPE void RbcEmulateXReparentWindow(
    Display * display,
    Window window,
    Window parent,
    int x,
    int y);
MODULE_SCOPE void RbcEmulateXSetDashes(
    Display * display,
    GC gc,
    int dashOffset,
    _Xconst char *dashList,
    int n);



MODULE_SCOPE HPEN RbcGCToPen(
    HDC dc,
    GC gc);

/* rbcWinDraw.c */
MODULE_SCOPE HPALETTE RbcGetSystemPalette(
    );
MODULE_SCOPE unsigned char *RbcGetBitmapData(
    Display * display,
    Pixmap bitmap,
    int width,
    int height,
    int *pitchPtr);
MODULE_SCOPE void RbcEmulateXFree(
    void *ptr);
MODULE_SCOPE long RbcEmulateXMaxRequestSize(
    Display * display);
MODULE_SCOPE void RbcEmulateXLowerWindow(
    Display * display,
    Window window);
MODULE_SCOPE void RbcEmulateXRaiseWindow(
    Display * display,
    Window window);
MODULE_SCOPE void RbcEmulateXUnmapWindow(
    Display * display,
    Window window);
MODULE_SCOPE void RbcEmulateXWarpPointer(
    Display * display,
    Window srcWindow,
    Window destWindow,
    int srcX,
    int srcY,
    unsigned int srcWidth,
    unsigned int srcHeight,
    int destX,
    int destY);

/* rbcWinUtil.c */
MODULE_SCOPE int RbcGetPlatformId(
    );
MODULE_SCOPE char *RbcLastError(
    );

#endif /*_RBCWIN*/

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */






|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
|
<
|
<
<








|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<




58
59
60
61
62
63
64
65

























































































































































































66











67









68

69


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103



104
105
106
107
#define Status int

/*
 * Add definitions missing from windgi.h, windowsx.h, and winspool.h
 */
#endif /* __GNUC__ */

/* rbcWinDraw.c */

























































































































































































MODULE_SCOPE int RbcGetPlatformId(











    );









MODULE_SCOPE char *RbcLastError(

    );


MODULE_SCOPE HPALETTE RbcGetSystemPalette(
    );
MODULE_SCOPE unsigned char *RbcGetBitmapData(
    Display * display,
    Pixmap bitmap,
    int width,
    int height,
    int *pitchPtr);
MODULE_SCOPE void RbcSetROP2(
    HDC dc,
    int function);
MODULE_SCOPE GC RbcEmulateXCreateGC(
    Display *display,
    Drawable drawable,
    unsigned long mask,
    XGCValues *srcPtr);
MODULE_SCOPE HPEN RbcGCToPen(
    HDC dc,
    GC gc);
MODULE_SCOPE int RbcDrawRotatedText(
    Display * display,
    Drawable drawable,
    int x,
    int y,
    double theta,
    RbcTextStyle * stylePtr,
    RbcTextLayout * textPtr);

/* Already defined in rbcInt.h:
void RbcSetDashes(Display *display,
    GC gc,
    RbcDashes *dashesPtr);

*/




#endif /*_RBCWIN*/

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Changes to generic/rbc/rbcWinDraw.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82













































83
84
85
86
87
88
89
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
739
740
741
742
743
744
745

746
747
748
749
750
751
752
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
....
2130
2131
2132
2133
2134
2135
2136

2137
2138
2139
2140

2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160

2161
2162
2163
2164
2165

2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176

2177
2178
2179
2180
2181
2182
2183






2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196















2197














2198
2199
2200


2201
2202
2203
2204
2205
2206
2207
2208
2209
2210

2211
2212
2213
2214










2215
2216
2217
2218

2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229

2230
2231
2232

2233
2234
2235
2236
2237
2238
2239
2240
2241
2242

2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253


2254


2255

2256








2257
2258






2259
2260
2261



2262
2263
2264
2265

2266
2267
2268
2269
2270
2271

2272
2273
2274
2275
2276
2277
2278
2279
2280

2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306




2307















2308
2309
2310
2311
2312

2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337

2338
2339
2340
2341
2342
2343

2344
2345
2346



2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"
#include <X11/Xlib.h>
#define WINDEBUG 0
/*
 * Data structure for setting graphics context.
 */
typedef struct {
    int function;		/* logical operation */
    unsigned long plane_mask;	/* plane mask */
    unsigned long foreground;	/* foreground pixel */
................................................................................
    Pixmap clip_mask;		/* bitmap clipping; other calls for rects */
    int dash_offset;		/* patterned/dashed line information */
    char dashes;		/* If -1, indicates that the extended
				 * information below is available. */
    int nDashValues;
    char dashValues[12];
} XGCValuesEx;
#define MASKPAT		0x00E20746 /* dest = (src & pat) | (!src & dst) */
#define COPYFG		0x00CA0749 /* dest = (pat & src) | (!pat & dst) */
#define COPYBG		0x00AC0744 /* dest = (!pat & src) | (pat & dst) */
/*
 * Translation table between X gc functions and Win32 BitBlt op modes.  Some
 * of the operations defined in X don't have names, so we have to construct
 * new opcodes for those functions.  This is arcane and probably not all that
 * useful, but at least it's accurate.
 */
#define NOTSRCAND	(DWORD)0x00220326 /* dest = (NOT src) AND dest */
#define NOTSRCINVERT	(DWORD)0x00990066 /* dest = (NOT src) XOR dest */
#define SRCORREVERSE	(DWORD)0x00DD0228 /* dest = src OR (NOT dest) */
#define SRCNAND		(DWORD)0x007700E6 /* dest = NOT (src AND dest) */
static int bltModes[] = {
    BLACKNESS,			/* GXclear */
    SRCAND,			/* GXand */
    SRCERASE,			/* GXandReverse */
    SRCCOPY,			/* GXcopy */
    NOTSRCAND,			/* GXandInverted */
    PATCOPY,			/* GXnoop */
    SRCINVERT,			/* GXxor */
    SRCPAINT,			/* GXor */
    NOTSRCERASE,		/* GXnor */
    NOTSRCINVERT,		/* GXequiv */
    DSTINVERT,			/* GXinvert */
    SRCORREVERSE,		/* GXorReverse */
    NOTSRCCOPY,			/* GXcopyInverted */
    MERGEPAINT,			/* GXorInverted */
    SRCNAND,			/* GXnand */
    WHITENESS			/* GXset */
};
static Tcl_Encoding systemEncoding = NULL;













































/*
 *--------------------------------------------------------------
 *
 * RbcGetSystemPalette --
 *
 *      TODO: Description
 *
................................................................................
        GetSystemPaletteEntries(hDC, 0, 256, palettePtr->palPalEntry);
        hPalette = CreatePalette(palettePtr);
        GlobalFree(palettePtr);
    }
    ReleaseDC(NULL, hDC);
    return hPalette;
}
/*
 *--------------------------------------------------------------
 *
 * CreateRotatedFont --
 *
 *      Creates a rotated copy of the given font.  This only works
 *      for TrueType fonts.
 *
 * Results:
 *      Returns the newly create font or NULL if the font could not
 *      be created.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
HFONT
CreateRotatedFont(
    unsigned long fontId, /* Font identifier (actually a Tk_Font) */
    double theta) /* Number of degrees to rotate font */
{
    TkFontAttributes *faPtr;	/* Set of attributes to match. */
    TkFont *fontPtr;
    HFONT hFont;
    LOGFONTW lf;
    fontPtr = (TkFont *) fontId;
    faPtr = &fontPtr->fa;
    ZeroMemory(&lf, sizeof(LOGFONT));
    lf.lfHeight = -faPtr->size;
    if (lf.lfHeight < 0) {
        HDC dc;
        dc = GetDC(NULL);
        lf.lfHeight = -MulDiv(faPtr->size,
                              GetDeviceCaps(dc, LOGPIXELSY), 72);
        ReleaseDC(NULL, dc);
    }
    lf.lfWidth = 0;
    lf.lfEscapement = lf.lfOrientation = ROUND(theta * 10.0);
#define TK_FW_NORMAL	0
    lf.lfWeight = (faPtr->weight == TK_FW_NORMAL) ? FW_NORMAL : FW_BOLD;
    lf.lfItalic = faPtr->slant;
    lf.lfUnderline = faPtr->underline;
    lf.lfStrikeOut = faPtr->overstrike;
    lf.lfCharSet = DEFAULT_CHARSET;
    lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    hFont = NULL;
    if (faPtr->family == NULL) {
        lf.lfFaceName[0] = '\0';
    } else {
        Tcl_DString dString;
        Tcl_UtfToExternalDString(systemEncoding, faPtr->family, -1, &dString);
        if (RbcGetPlatformId() == VER_PLATFORM_WIN32_NT) {
            Tcl_UniChar *src, *dst;
            /*
             * We can only store up to LF_FACESIZE wide characters
             */
            if (Tcl_DStringLength(&dString) >= (int)(LF_FACESIZE * sizeof(WCHAR))) {
                Tcl_DStringSetLength(&dString, LF_FACESIZE);
            }
            src = (Tcl_UniChar *)Tcl_DStringValue(&dString);
            dst = (Tcl_UniChar *)lf.lfFaceName;
            while (*src != '\0') {
                *dst++ = *src++;
            }
            *dst = '\0';
            hFont = CreateFontIndirectW((LOGFONTW *)&lf);
        } else {
            /*
             * We can only store up to LF_FACESIZE characters
             */
            if (Tcl_DStringLength(&dString) >= LF_FACESIZE) {
                Tcl_DStringSetLength(&dString, LF_FACESIZE);
            }
            strcpy((char *)lf.lfFaceName, Tcl_DStringValue(&dString));
            hFont = CreateFontIndirectA((LOGFONTA *)&lf);
        }
        Tcl_DStringFree(&dString);
    }
    if (hFont == NULL) {
#if WINDEBUG
        PurifyPrintf("can't create font: %s\n", RbcLastError());
#endif
    } else {
        HFONT oldFont;
        TEXTMETRIC tm;
        HDC hRefDC;
        int result;
        /* Check if the rotated font is really a TrueType font. */
        hRefDC = GetDC(NULL);		/* Get the desktop device context */
        oldFont = SelectFont(hRefDC, hFont);
        result = ((GetTextMetrics(hRefDC, &tm)) &&
                  (tm.tmPitchAndFamily & TMPF_TRUETYPE));
        SelectFont(hRefDC, oldFont);
        ReleaseDC(NULL, hRefDC);
        if (!result) {
#if WINDEBUG
            PurifyPrintf("not a true type font\n");
#endif
            DeleteFont(hFont);
            return NULL;
        }
    }
    return hFont;
}
/*
 *--------------------------------------------------------------
 *
 * RbcGetBitmapData --
 *
 *      Returns the DIB bits from a bitmap.
 *
................................................................................
        }
    }
    *pitchPtr = bytesPerRow;
    GlobalUnlock(hMem);
    GlobalFree(hMem);
    return bits;
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXFree --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXFree(
    void *ptr)
{
    ckfree((char *)ptr);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXMaxRequestSize --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
long
RbcEmulateXMaxRequestSize(
    Display *display)
{
    return (SHRT_MAX / 4);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXLowerWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXLowerWindow(
    Display *display,
    Window window)
{
    HWND hWnd;
    hWnd = Tk_GetHWND(window);
    display->request++;
    SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXRaiseWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXRaiseWindow(
    Display *display,
    Window window)
{
    HWND hWnd;
    hWnd = Tk_GetHWND(window);
    display->request++;
    SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXUnmapWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXUnmapWindow(
    Display *display,
    Window window)
{
    HWND hWnd;
    hWnd = Tk_GetHWND(window);
    display->request++;
    ShowWindow(hWnd, SW_HIDE);
    /* SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); */
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXWarpPointer --
 *
 *      If destWindow is None, moves the pointer by the offsets (destX,
 *      destY) relative to the current position of the pointer.
 *      If destWindow is a window, moves the pointer to the offsets
 *      (destX, destY) relative to the origin of destWindow.  However,
 *      if srcWindow is a window, the move only takes place if the window
 *      srcWindow contains the pointer and if the specified rectangle of
 *      srcWindow contains the pointer.
 *
 *      The srcX and srcY coordinates are relative to the origin of
 *      srcWindow.  If srcHeight is zero, it is replaced with the current
 *      height of srcWindow minus srcY.  If srcWidth is zero, it is
 *      replaced with the current width of srcWindow minus srcX.
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXWarpPointer(
    Display *display,
    Window srcWindow,
    Window destWindow,
    int srcX,
    int srcY,
    unsigned int srcWidth,
    unsigned int srcHeight,
    int destX,
    int destY)
{
    HWND hWnd;
    POINT point;
    hWnd = Tk_GetHWND(destWindow);
    point.x = destX, point.y = destY;
    if (ClientToScreen(hWnd, &point)) {
        SetCursorPos(point.x, point.y);
    }
}
typedef struct {
    HDC dc;
    int count;
    COLORREF color;
    int offset, nBits;
} DashInfo;
/*
 *--------------------------------------------------------------
 *
 * RbcSetDashes --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcSetDashes(
    Display *display,
    GC gc,
    RbcDashes *dashesPtr)
{
    XGCValuesEx *gcPtr = (XGCValuesEx *)gc;
    /* This must be used only with a privately created GC */
    assert((int)gcPtr->dashes == -1);
    gcPtr->nDashValues = strlen(dashesPtr->values);
    gcPtr->dash_offset = dashesPtr->offset;
    strcpy(gcPtr->dashValues, dashesPtr->values);
}
/*
 *--------------------------------------------------------------
 *
 * GetDashInfo --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static int
GetDashInfo(
    HDC dc,
    GC gc,
    DashInfo *infoPtr)
{
    int dashOffset, dashValue;
    dashValue = 0;
    dashOffset = gc->dash_offset;
    if ((int)gc->dashes == -1) {
        XGCValuesEx *gcPtr = (XGCValuesEx *)gc;
        if (gcPtr->nDashValues == 1) {
            dashValue = gcPtr->dashValues[0];
        }
    } else if (gc->dashes > 0) {
        dashValue = (int)gc->dashes;
    }
    if (dashValue == 0) {
        return FALSE;
    }
    infoPtr->dc = dc;
    infoPtr->nBits = dashValue;
    infoPtr->offset = dashOffset;
    infoPtr->count = 0;
    infoPtr->color = gc->foreground;
    return TRUE;
}
/*
 *--------------------------------------------------------------
 *
 * RbcSetROP2 --
 *
 *      TODO: Description
 *
................................................................................
    R2_MERGENOTPEN,		/* GXorInverted */
    R2_NOTMASKPEN,		/* GXnand */
    R2_WHITE			/* GXset */
};
    if (function < 0 || function > 15) return;
    SetROP2(dc, WinRop2Mode[function]);
}
/*
 *--------------------------------------------------------------
 *
 * CreateGC --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static XGCValuesEx *
CreateGC()
{
    XGCValuesEx *gcPtr;
    gcPtr = (XGCValuesEx *)ckalloc(sizeof(XGCValuesEx));
    if (gcPtr == NULL) {
        return NULL;
    }
    gcPtr->arc_mode = ArcPieSlice;
    gcPtr->background = 0xffffff;
    gcPtr->cap_style = CapNotLast;
    gcPtr->clip_mask = None;
    gcPtr->clip_x_origin = gcPtr->clip_y_origin = 0;
    gcPtr->dash_offset	= 0;
    gcPtr->fill_rule = WindingRule;
    gcPtr->fill_style = FillSolid;
    gcPtr->font = None;
    gcPtr->foreground = 0;
    gcPtr->function = GXcopy;
    gcPtr->graphics_exposures = True;
    gcPtr->join_style = JoinMiter;
    gcPtr->line_style = LineSolid;
    gcPtr->line_width = 0;
    gcPtr->plane_mask = ~0;
    gcPtr->stipple = None;
    gcPtr->subwindow_mode = ClipByChildren;
    gcPtr->tile = None;
    gcPtr->ts_x_origin = gcPtr->ts_y_origin = 0;
    gcPtr->dashes = -1;    /* Mark that this an extended GC */
    gcPtr->nDashValues	= 0;
    return gcPtr;
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXCreateGC --
 *
 *      Allocate a new extended GC, and initialize the specified fields.
 *
................................................................................
#define TKP_CLIP_PIXMAP 0
        clipPtr->type = TKP_CLIP_PIXMAP;
        clipPtr->pixmap = srcPtr->clip_mask;
        destPtr->clip_mask = (Pixmap) clipPtr;
    }
    return (GC)destPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGCToPen --
 *
 *      Set up the graphics port from the given GC.
 *
................................................................................
            /* Otherwise sacrifice thick lines for dashes. */
            pen = ExtCreatePen(PS_COSMETIC | lineStyle, 1, &lBrush, 0, NULL);
        }
    }
    assert(pen != NULL);
    return pen;
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXDrawRectangles --
 *
 *      Draws the outlines of the specified rectangles as if a
 *      five-point PolyLine protocol request were specified for each
 *      rectangle:
 *
 *        [x,y] [x+width,y] [x+width,y+height] [x,y+height]
 *        [x,y]
 *
 *      For the specified rectangles, these functions do not draw a
 *      pixel more than once.  XDrawRectangles draws the rectangles in
 *      the order listed in the array.  If rectangles intersect, the
 *      intersecting pixels are drawn multiple times.  Draws a
 *      rectangle.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws rectangles on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawRectangles(
    Display *display,
    Drawable drawable,
    GC gc,
    XRectangle *rectArr,
    int nRects)
{
    HPEN pen, oldPen;
    TkWinDCState state;
    HBRUSH brush, oldBrush;
    HDC dc;
    register XRectangle *rectPtr;
    register int i;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    pen = RbcGCToPen(dc, gc);
    brush = GetStockObject(NULL_BRUSH);
    oldPen = SelectPen(dc, pen);
    oldBrush = SelectBrush(dc, brush);
    RbcSetROP2(dc, gc->function);
    rectPtr = rectArr;
    for (i = 0; i < nRects; i++, rectPtr++) {
        Rectangle(dc, (int)rectPtr->x, (int)rectPtr->y,
                  (int)(rectPtr->x + rectPtr->width + 1),
                  (int)(rectPtr->y + rectPtr->height + 1));
    }
    DeletePen(SelectPen(dc, oldPen));
    DeleteBrush(SelectBrush(dc, oldBrush));
    TkWinReleaseDrawableDC(drawable, dc, &state);
}

/*
 *----------------------------------------------------------------------
 *
 * DrawArc --
 *
 *      This procedure handles the rendering of drawn or filled
 *      arcs and chords.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Renders the requested arcs.
 *
 *----------------------------------------------------------------------
 */
static void
DrawArc(
    HDC dc,
    int arcMode, /* Mode: either ArcChord or ArcPieSlice */
    XArc *arcPtr,
    HPEN pen,
    HBRUSH brush)
{
    int start, extent, clockwise;
    int xstart, ystart, xend, yend;
    double radian_start, radian_end, xr, yr;
    double dx, dy;
    if ((arcPtr->angle1 == 0) && (arcPtr->angle2 == 23040)) {
        /* Handle special case of circle or ellipse */
        Ellipse(dc, arcPtr->x, arcPtr->y, arcPtr->x + arcPtr->width + 1,
                arcPtr->y + arcPtr->height + 1);
        return;
    }
    start = arcPtr->angle1, extent = arcPtr->angle2;
    clockwise = (extent < 0);	/* Non-zero if clockwise */
    /*
     * Compute the absolute starting and ending angles in normalized radians.
     * Swap the start and end if drawing clockwise.
     */
    start = start % (64 * 360);
    if (start < 0) {
        start += (64 * 360);
    }
    extent = (start + extent) % (64 * 360);
    if (extent < 0) {
        extent += (64 * 360);
    }
    if (clockwise) {
        int tmp = start;
        start = extent;
        extent = tmp;
    }
#define XAngleToRadians(a) ((double)(a) / 64 * M_PI / 180);
    radian_start = XAngleToRadians(start);
    radian_end = XAngleToRadians(extent);
    /*
     * Now compute points on the radial lines that define the starting and
     * ending angles.  Be sure to take into account that the y-coordinate
     * system is inverted.
     */
    dx = arcPtr->width * 0.5;
    dy = arcPtr->height * 0.5;
    xr = arcPtr->x + dx;
    yr = arcPtr->y + dy;
    xstart = (int)((xr + cos(radian_start) * dx) + 0.5);
    ystart = (int)((yr + sin(-radian_start) * dy) + 0.5);
    xend = (int)((xr + cos(radian_end) * dx) + 0.5);
    yend = (int)((yr + sin(-radian_end) * dy) + 0.5);
    /*
     * Now draw a filled or open figure.  Note that we have to
     * increase the size of the bounding box by one to account for the
     * difference in pixel definitions between X and Windows.
     */
    if (brush == 0) {
        /*
         * Note that this call will leave a gap of one pixel at the
         * end of the arc for thin arcs.  We can't use ArcTo because
         * it's only supported under Windows NT.
         */
        Arc(dc, arcPtr->x, arcPtr->y, arcPtr->x + arcPtr->width + 1,
            arcPtr->y + arcPtr->height + 1, xstart, ystart, xend, yend);
        /* FIXME: */
    } else {
        if (arcMode == ArcChord) {
            Chord(dc, arcPtr->x, arcPtr->y, arcPtr->x + arcPtr->width + 1,
                  arcPtr->y + arcPtr->height + 1, xstart, ystart, xend, yend);
        } else if (arcMode == ArcPieSlice) {
            Pie(dc, arcPtr->x, arcPtr->y, arcPtr->x + arcPtr->width + 1,
                arcPtr->y + arcPtr->height + 1, xstart, ystart, xend, yend);
        }
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXDrawArcs --
 *
 *      Draws multiple circular or elliptical arcs.  Each arc is
 *      specified by a rectangle and two angles.  The center of the
 *      circle or ellipse is the center of the rect- angle, and the
 *      major and minor axes are specified by the width and height.
 *      Positive angles indicate counterclock- wise motion, and
 *      negative angles indicate clockwise motion.  If the magnitude
 *      of angle2 is greater than 360 degrees, XDrawArcs truncates it
 *      to 360 degrees.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws an arc for each array element on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawArcs(
    Display *display,
    Drawable drawable,
    GC gc,
    XArc *arcArr,
    int nArcs)
{
    HPEN pen, oldPen;
    HBRUSH brush, oldBrush;
    HDC dc;
    TkWinDCState state;
    register XArc *arcPtr, *endPtr;
    display->request++;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(dc, gc->function);
    pen = RbcGCToPen(dc, gc);
    oldPen = SelectPen(dc, pen);
    brush = GetStockBrush(NULL_BRUSH);
    oldBrush = SelectBrush(dc, brush);
    endPtr = arcArr + nArcs;
    for (arcPtr = arcArr; arcPtr < endPtr; arcPtr++) {
        DrawArc(dc, gc->arc_mode, arcPtr, pen, 0);
    }
    DeleteBrush(SelectBrush(dc, oldBrush));
    DeletePen(SelectPen(dc, oldPen));
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXFillArcs --
 *
 *      Draw a filled arc.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws a filled arc for each array element on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXFillArcs(
    Display *display,
    Drawable drawable,
    GC gc,
    XArc *arcArr,
    int nArcs)
{
    HBRUSH brush, oldBrush;
    HPEN pen, oldPen;
    HDC dc;
    register XArc *arcPtr, *endPtr;
    TkWinDCState state;
    display->request++;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(dc, gc->function);
    pen = RbcGCToPen(dc, gc);
    oldPen = SelectPen(dc, pen);
    brush = CreateSolidBrush(gc->foreground);
    oldBrush = SelectBrush(dc, brush);
    endPtr = arcArr + nArcs;
    for (arcPtr = arcArr; arcPtr < endPtr; arcPtr++) {
        DrawArc(dc, gc->arc_mode, arcPtr, pen, brush);
    }
    DeleteBrush(SelectBrush(dc, oldBrush));
    DeletePen(SelectPen(dc, oldPen));
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * DrawDot --
 *
 *      Draws a dot.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Renders a dot.
 *
 *----------------------------------------------------------------------
 */
static void CALLBACK
DrawDot(
    int x, /* y-coordinates of point */
    int y, /* y-coordinates of point */
    LPARAM clientData)
{				/* Line information */
    DashInfo *infoPtr = (DashInfo *) clientData;
    int count;
    infoPtr->count++;
    count = (infoPtr->count + infoPtr->offset) / infoPtr->nBits;
    if (count & 0x1) {
        SetPixelV(infoPtr->dc, x, y, infoPtr->color);
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXDrawLine --
 *
 *      Draw connected lines.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Renders a series of connected lines.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawLine(
    Display *display,
    Drawable drawable,
    GC gc,
    int x1,
    int y1,
    int x2,
    int y2)
{
    TkWinDCState state;
    HDC dc;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(dc, gc->function);
    if (gc->line_style != LineSolid) {
        /* Handle dotted lines specially */
        DashInfo info;
        if (!GetDashInfo(dc, gc, &info)) {
            goto solidLine;
        }
        LineDDA(x1, y1, x2, y2, DrawDot, (LPARAM)&info);
    } else {
        HPEN pen, oldPen;
        HBRUSH brush, oldBrush;
solidLine:
        pen = RbcGCToPen(dc, gc);
        oldPen = SelectPen(dc, pen);
        brush = CreateSolidBrush(gc->foreground);
        oldBrush = SelectBrush(dc, brush);
        MoveToEx(dc, x1, y1, (LPPOINT)NULL);
        LineTo(dc, x2, y2);
        DeletePen(SelectPen(dc, oldPen));
        DeleteBrush(SelectBrush(dc, oldBrush));
    }
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * DrawLine --
 *
 *      Draw connected lines.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Renders a series of connected lines.
 *
 *----------------------------------------------------------------------
 */
static void
DrawLine(
    Display *display,
    Drawable drawable,
    GC gc,
    POINT *points,
    int nPoints)
{
    TkWinDCState state;
    HDC dc;
    register int i, n;
    int start, extra, size;
    HPEN pen, oldPen;
    HBRUSH brush, oldBrush;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    pen = RbcGCToPen(dc, gc);
    oldPen = SelectPen(dc, pen);
    brush = CreateSolidBrush(gc->foreground);
    oldBrush = SelectBrush(dc, brush);
    RbcSetROP2(dc, gc->function);
    start = extra = 0;
    /*
     * Depending if the line is wide (> 1 pixel), arbitrarily break
     * the line in sections of 100 points.  This bit of weirdness has
     * to do with wide geometric pens.  The longer the polyline, the
     * slower it draws.  The trade off is that we lose dash and
     * cap uniformity for unbearably slow polyline draws.
     */
    if (gc->line_width > 1) {
        size = 100;
    } else {
        size = nPoints;
    }
    for (i = nPoints; i > 0; i -= size) {
        n = MIN(i, size);
        Polyline(dc, points + start, n + extra);
        start += (n - 1);
        extra = 1;
    }
    DeletePen(SelectPen(dc, oldPen));
    DeleteBrush(SelectBrush(dc, oldBrush));
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXDrawLines --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXDrawLines(
    Display *display,
    Drawable drawable,
    GC gc,
    XPoint *pointArr,
    int nPoints,
    int mode)
{
    if (drawable == None) {
        return;
    }
    if (gc->line_style != LineSolid) { /* Handle dotted lines specially */
        DashInfo info;
        TkWinDCState state;
        HDC dc;
        int result;
        dc = TkWinGetDrawableDC(display, drawable, &state);
        RbcSetROP2(dc, gc->function);
        result = GetDashInfo(dc, gc, &info);
        if (result) {
            register XPoint *p1, *p2;
            register int i;
            p1 = pointArr;
            p2 = p1 + 1;
            for (i = 1; i < nPoints; i++, p1++, p2++) {
                LineDDA(p1->x, p1->y, p2->x, p2->y, DrawDot, (LPARAM)&info);
            }
            result = TCL_OK;
        }
        TkWinReleaseDrawableDC(drawable, dc, &state);
        if (result) {
            return;
        }
    } else {
        POINT *points, *destPtr;
        XPoint *srcPtr, *endPtr;
        points = (POINT *)ckalloc(sizeof(POINT) * nPoints);
        if (points == NULL) {
            return;
        }
        endPtr = pointArr + nPoints;
        if (mode == CoordModeOrigin) {
            destPtr = points;
            for (srcPtr = pointArr; srcPtr < endPtr; srcPtr++) {
                destPtr->x = (int)srcPtr->x;
                destPtr->y = (int)srcPtr->y;
                destPtr++;
            }
        } else {
            POINT *lastPtr;
            srcPtr = pointArr;
            destPtr = points;
            destPtr->x = (int)srcPtr->x;
            destPtr->y = (int)srcPtr->y;
            lastPtr = destPtr;
            srcPtr++, destPtr++;
            for (/*empty*/; srcPtr < endPtr; srcPtr++) {
                destPtr->x = lastPtr->x + (int)srcPtr->x;
                destPtr->y = lastPtr->y + (int)srcPtr->y;
                lastPtr = destPtr;
                destPtr++;
            }
        }
        DrawLine(display, drawable, gc, points, nPoints);
        ckfree((char *)points);
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmultateXDrawSegments --
 *
 *      Draws multiple, unconnected lines. For each segment, draws a
 *      line between (x1, y1) and (x2, y2).  It draws the lines in the
 *      order listed in the array of XSegment structures and does not
 *      perform joining at coincident endpoints.  For any given line,
 *      does not draw a pixel more than once. If lines intersect, the
 *      intersecting pixels are drawn multiple times.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws unconnected line segments on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawSegments(
    Display *display,
    Drawable drawable,
    GC gc,
    XSegment *segArr,
    int nSegments)
{
    HDC dc;
    register XSegment *segPtr, *endPtr;
    TkWinDCState state;
    display->request++;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(dc, gc->function);
    if (gc->line_style != LineSolid) {
        /* Handle dotted lines specially */
        DashInfo info;
        if (!GetDashInfo(dc, gc, &info)) {
            goto solidLine;
        }
        endPtr = segArr + nSegments;
        for (segPtr = segArr; segPtr < endPtr; segPtr++) {
            info.count = 0; /* Reset dash counter after every segment. */
            LineDDA(segPtr->x1, segPtr->y1, segPtr->x2, segPtr->y2, DrawDot,
                    (LPARAM)&info);
        }
    } else {
        HPEN pen, oldPen;
solidLine:
        pen = RbcGCToPen(dc, gc);
        oldPen = SelectPen(dc, pen);
        endPtr = segArr + nSegments;
        for (segPtr = segArr; segPtr < endPtr; segPtr++) {
            MoveToEx(dc, segPtr->x1, segPtr->y1, (LPPOINT)NULL);
            LineTo(dc, segPtr->x2, segPtr->y2);
        }
        DeletePen(SelectPen(dc, oldPen));
    }
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmultateXDrawRectangle --
 *
 *      Draws the outlines of the specified rectangle as if a
 *      five-point PolyLine protocol request were specified for each
 *      rectangle:
 *
 *        [x,y] [x+width,y] [x+width,y+height] [x,y+height]
 *        [x,y]
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws a rectangle on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawRectangle(
    Display *display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    unsigned int width,
    unsigned int height)
{
    TkWinDCState state;
    HPEN pen, oldPen;
    HBRUSH brush, oldBrush;
    HDC dc;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    pen = RbcGCToPen(dc, gc);
    brush = GetStockObject(NULL_BRUSH);
    oldPen = SelectPen(dc, pen);
    oldBrush = SelectBrush(dc, brush);
    RbcSetROP2(dc, gc->function);
    if (gc->line_style != LineSolid) {
        /* Handle dotted lines specially */
        register int x2, y2;
        DashInfo info;
        if (!GetDashInfo(dc, gc, &info)) {
            goto solidLine;
        }
        x2 = x + width;
        y2 = y + height;
        LineDDA(x, y, x2, y, DrawDot, (LPARAM)&info);
        LineDDA(x2, y, x2, y2, DrawDot, (LPARAM)&info);
        LineDDA(x2, y2, x, y2, DrawDot, (LPARAM)&info);
        LineDDA(x, y2, x, y, DrawDot, (LPARAM)&info);
    } else {
solidLine:
        Rectangle(dc, x, y, x + width + 1, y + height + 1);
    }
    DeletePen(SelectPen(dc, oldPen));
    DeleteBrush(SelectBrush(dc, oldBrush));
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXDrawPoints --
 *
 *      Uses the foreground pixel and function components of the GC to
 *      draw a multiple points into the specified drawable.
 *      CoordModeOrigin treats all coordinates as relative to the
 *      origin, and CoordModePrevious treats all coordinates after
 *      the first as relative to the previous point.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws points on the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawPoints(
    Display *display,
    Drawable drawable,
    GC gc,
    XPoint *pointArr,
    int nPoints,
    int mode)
{				/* Ignored. CoordModeOrigin is assumed. */
    HDC dc;
    register XPoint *pointPtr, *endPtr;
    TkWinDCState state;
    display->request++;
    if (drawable == None) {
        return;
    }
    dc = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(dc, gc->function);
    endPtr = pointArr + nPoints;
    for (pointPtr = pointArr; pointPtr < endPtr; pointPtr++) {
        SetPixelV(dc, pointPtr->x, pointPtr->y, gc->foreground);
    }
    TkWinReleaseDrawableDC(drawable, dc, &state);
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmultateXReparentWindow --
 *
 *      If the specified window is mapped, automatically performs an
 *      UnmapWindow request on it, removes it from its current
 *      position in the hierarchy, and inserts it as the child of the
 *      specified parent.  The window is placed in the stacking order
 *      on top with respect to sibling windows.
 *
 *      Note: In WIN32 you can't reparent to/from another application.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Reparents the specified window.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXReparentWindow(
    Display *display,
    Window window,
    Window parent,
    int x,
    int y)
{
    HWND child, newParent;
    child = Tk_GetHWND(window);
    newParent = Tk_GetHWND(parent);
    SetParent(child, newParent);
    SetWindowLong(child, GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN |
                  WS_CLIPSIBLINGS);
    XMoveWindow(display, window, x, y);
    XRaiseWindow(display, window);
    XMapWindow(display, window);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXSetDashes --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXSetDashes(
    Display *display,
    GC gc,
    int dashOffset,
    _Xconst char *dashList,
    int n)
{
    gc->dashes = (unsigned char)strlen(dashList);
    gc->dash_offset = (int)dashList;
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmultateXDrawString --
 *
 *      Draw a single string in the current font.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Renders the specified string in the drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXDrawString(
    Display *display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    _Xconst char *string,
    int length)
{
    if (drawable == None) {
        return;
    }
    Tk_DrawChars(display, drawable, gc, (Tk_Font)gc->font, string, length,
                 x, y);
}
/*
 *--------------------------------------------------------------
 *
 * TileArea --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static void
TileArea(
      HDC destDC,
      HDC srcDC,
      int tileOriginX,
      int tileOriginY,
      int tileWidth,
      int tileHeight,
      int x,
      int y,
      int width,
      int height)
{
    int destX, destY;
    int destWidth, destHeight;
    int srcX, srcY;
    int xOrigin, yOrigin;
    int delta;
    int left, top, right, bottom;
    xOrigin = x, yOrigin = y;
    if (x < tileOriginX) {
        delta = (tileOriginX - x) % tileWidth;
        if (delta > 0) {
            xOrigin -= (tileWidth - delta);
        }
    } else if (x > tileOriginX) {
        delta = (x - tileOriginX) % tileWidth;
        if (delta > 0) {
            xOrigin -= delta;
        }
    }
    if (y < tileOriginY) {
        delta = (tileOriginY - y) % tileHeight;
        if (delta > 0) {
            yOrigin -= (tileHeight - delta);
        }
    } else if (y >= tileOriginY) {
        delta = (y - tileOriginY) % tileHeight;
        if (delta > 0) {
            yOrigin -= delta;
        }
    }
    left = x;
    right = x + width;
    top = y;
    bottom = y + height;
    for (y = yOrigin; y < bottom; y += tileHeight) {
        srcY = 0;
        destY = y;
        destHeight = tileHeight;
        if (y < top) {
            srcY = (top - y);
            destHeight = tileHeight - srcY;
            destY = top;
        }
        if ((destY + destHeight) > bottom) {
            destHeight = (bottom - destY);
        }
        for (x = xOrigin; x < right; x += tileWidth) {
            srcX = 0;
            destX = x;
            destWidth = tileWidth;
            if (x < left) {
                srcX = (left - x);
                destWidth = tileWidth - srcX;
                destX = left;
            }
            if ((destX + destWidth) > right) {
                destWidth = (right - destX);
            }
            BitBlt(destDC, destX, destY, destWidth, destHeight,
                   srcDC, srcX, srcY, SRCCOPY);
        }
    }
}
/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXFillRectangles --
 *
 *      Fill multiple rectangular areas in the given drawable.
 *      Handles tiling.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Draws onto the specified drawable.
 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXFillRectangles(
    Display *display,
    Drawable drawable,
    GC gc,
    XRectangle *rectArr,
    int nRectangles)
{
    BITMAP bm;
    HBITMAP oldBitmap, hBitmap;
    HBRUSH oldBrush, hFgBrush, hBgBrush, hBrush;
    HDC hDC;
    HDC memDC;
    RECT rect;
    TkWinDCState state;
    TkWinDrawable *twdPtr;
    register XRectangle *rectPtr, *endPtr;
    if (drawable == None) {
        return;
    }
    hDC = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(hDC, gc->function);
    switch (gc->fill_style) {
        case FillTiled:
            if (gc->tile == None) {
                goto fillSolid;
            }
            twdPtr = (TkWinDrawable *)gc->tile;
            GetObject(twdPtr->bitmap.handle, sizeof(BITMAP), &bm);
            memDC = CreateCompatibleDC(hDC);
            oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle);
            endPtr = rectArr + nRectangles;
            for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) {
                TileArea(hDC, memDC, gc->ts_x_origin, gc->ts_y_origin, bm.bmWidth,
                         bm.bmHeight, (int)rectPtr->x, (int)rectPtr->y,
                         (int)rectPtr->width, (int)rectPtr->height);
            }
            SelectBitmap(memDC, oldBitmap);
            DeleteDC(memDC);
            break;
        case FillOpaqueStippled:
        case FillStippled:
            if (gc->stipple == None) {
                goto fillSolid;
            }
            twdPtr = (TkWinDrawable *)gc->stipple;
            if (twdPtr->type != TWD_BITMAP) {
                Tcl_Panic("unexpected drawable type in stipple");
            }
            hBrush = CreatePatternBrush(twdPtr->bitmap.handle);
            SetBrushOrgEx(hDC, gc->ts_x_origin, gc->ts_y_origin, NULL);
            oldBrush = SelectBrush(hDC, hBrush);
            memDC = CreateCompatibleDC(hDC);
            /*
             * For each rectangle, create a drawing surface which is the size of
             * the rectangle and fill it with the background color.  Then merge the
             * result with the stipple pattern.
             */
            hFgBrush = CreateSolidBrush(gc->foreground);
            hBgBrush = CreateSolidBrush(gc->background);
            endPtr = rectArr + nRectangles;
            for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) {
                hBitmap = CreateCompatibleBitmap(hDC, rectPtr->width,
                                                 rectPtr->height);
                oldBitmap = SelectObject(memDC, hBitmap);
                rect.left = rect.top = 0;
                rect.right = rectPtr->width;
                rect.bottom = rectPtr->height;
                FillRect(memDC, &rect, hFgBrush);
                BitBlt(hDC, rectPtr->x, rectPtr->y, rectPtr->width, rectPtr->height,
                       memDC, 0, 0, COPYBG);
                if (gc->fill_style == FillOpaqueStippled) {
                    FillRect(memDC, &rect, hBgBrush);
                    BitBlt(hDC, rectPtr->x, rectPtr->y, rectPtr->width,
                           rectPtr->height, memDC, 0, 0, COPYFG);
                }
                SelectObject(memDC, oldBitmap);
                DeleteObject(hBitmap);
            }
            DeleteBrush(hFgBrush);
            DeleteBrush(hBgBrush);
            DeleteDC(memDC);
            SelectBrush(hDC, oldBrush);
            DeleteBrush(hBrush);
            break;
        case FillSolid:
fillSolid:
            memDC = CreateCompatibleDC(hDC);
            hFgBrush = CreateSolidBrush(gc->foreground);
            endPtr = rectArr + nRectangles;
            for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) {
                hBitmap = CreateCompatibleBitmap(hDC, rectPtr->width,
                                                 rectPtr->height);
                oldBitmap = SelectObject(memDC, hBitmap);
                rect.left = rect.top = 0;
                rect.right = rectPtr->width;
                rect.bottom = rectPtr->height;
                FillRect(memDC, &rect, hFgBrush);
                BitBlt(hDC, rectPtr->x, rectPtr->y, rectPtr->width, rectPtr->height,
                       memDC, 0, 0, SRCCOPY);
                SelectObject(memDC, oldBitmap);
                DeleteObject(hBitmap);
            }
            DeleteBrush(hFgBrush);
            DeleteDC(memDC);
            break;
    }
    TkWinReleaseDrawableDC(drawable, hDC, &state);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXFillRectangle --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXFillRectangle(
    Display *display,
    Drawable drawable,
    GC gc,
    int x,
    int y,
    unsigned int width,
    unsigned int height)
{
    HDC hDC;
    RECT rect;
    TkWinDCState state;
    if (drawable == None) {
        return;
    }
    hDC = TkWinGetDrawableDC(display, drawable, &state);
    RbcSetROP2(hDC, gc->function);
    rect.left = rect.top = 0;
    rect.right = width;
    rect.bottom = height;
    switch (gc->fill_style) {
        case FillTiled: {
                TkWinDrawable *twdPtr;
                HBITMAP oldBitmap;
                HDC memDC;
                BITMAP bm;
                if (gc->tile == None) {
                    goto fillSolid;
                }
                twdPtr = (TkWinDrawable *)gc->tile;
                /* The tiling routine needs to know the size of the bitmap */
                GetObject(twdPtr->bitmap.handle, sizeof(BITMAP), &bm);
                memDC = CreateCompatibleDC(hDC);
                oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle);
                TileArea(hDC, memDC, gc->ts_x_origin, gc->ts_y_origin, bm.bmWidth,
                         bm.bmHeight, x, y, width, height);
                SelectBitmap(memDC, oldBitmap);
                DeleteDC(memDC);
            }
            break;
        case FillOpaqueStippled:
        case FillStippled: {
                TkWinDrawable *twdPtr;
                HBRUSH oldBrush, hBrush;
                HBRUSH hBrushFg, hBrushBg;
                HBITMAP oldBitmap, hBitmap;
                HDC memDC;
                if (gc->stipple == None) {
                    goto fillSolid;
                }
                twdPtr = (TkWinDrawable *)gc->stipple;
                if (twdPtr->type != TWD_BITMAP) {
                    Tcl_Panic("unexpected drawable type in stipple");
                }
                hBrush = CreatePatternBrush(twdPtr->bitmap.handle);
                SetBrushOrgEx(hDC, gc->ts_x_origin, gc->ts_y_origin, NULL);
                oldBrush = SelectBrush(hDC, hBrush);
                memDC = CreateCompatibleDC(hDC);
                hBrushFg = CreateSolidBrush(gc->foreground);
                hBrushBg = CreateSolidBrush(gc->background);
                hBitmap = CreateCompatibleBitmap(hDC, width, height);
                oldBitmap = SelectObject(memDC, hBitmap);
                FillRect(memDC, &rect, hBrushFg);
                SetBkMode(hDC, TRANSPARENT);
                BitBlt(hDC, x, y, width, height, memDC, 0, 0, COPYFG);
                if (gc->fill_style == FillOpaqueStippled) {
                    FillRect(memDC, &rect, hBrushBg);
                    BitBlt(hDC, x, y, width, height, memDC, 0, 0, COPYBG);
                }
                SelectBrush(hDC, oldBrush);
                SelectBitmap(memDC, oldBitmap);
                DeleteBrush(hBrushFg);
                DeleteBrush(hBrushBg);
                DeleteBrush(hBrush);
                DeleteBitmap(hBitmap);
                DeleteDC(memDC);
            }
            break;
        case FillSolid: {
                HBRUSH hBrush;
                HBITMAP oldBitmap, hBitmap;
                HDC memDC;
fillSolid:
                /* TkWinFillRect(hDC, x, y, width, height, gc->foreground);  */
                memDC = CreateCompatibleDC(hDC);
                hBrush = CreateSolidBrush(gc->foreground);
                hBitmap = CreateCompatibleBitmap(hDC, width, height);
                oldBitmap = SelectBitmap(memDC, hBitmap);
                rect.left = rect.top = 0;
                rect.right = width;
                rect.bottom = height;
                FillRect(memDC, &rect, hBrush);
                BitBlt(hDC, x, y, width, height, memDC, 0, 0, SRCCOPY);
                SelectObject(memDC, oldBitmap);
                DeleteBitmap(hBitmap);
                DeleteBrush(hBrush);
                DeleteDC(memDC);
            }
            break;
    }
    TkWinReleaseDrawableDC(drawable, hDC, &state);
}
/*
 *--------------------------------------------------------------
 *
 * DrawChars --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static BOOL
DrawChars(
    HDC dc,
    int x,
    int y,
    char *string,
    int length)
{
    BOOL result;
    if (systemEncoding == NULL) {
        result = TextOutA(dc, x, y, string, length);
    } else {
        const unsigned short *wstring;
        Tcl_DString dString;
        Tcl_DStringInit(&dString);
        Tcl_UtfToExternalDString(systemEncoding, string, length, &dString);
        length = Tcl_NumUtfChars(string, -1);
        wstring = (const unsigned short *)Tcl_DStringValue(&dString);
        result = TextOutW(dc, x, y, wstring, length);
        Tcl_DStringFree(&dString);
    }
    return result;
}
/*
 *--------------------------------------------------------------
 *
 * RbcDrawRotatedText --
 *
 *      TODO: Description
 *
................................................................................
    }
done:
    SelectFont(hDC, oldFont);
    DeleteFont(hFont);
    TkWinReleaseDrawableDC(drawable, hDC, &state);
    return TRUE;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXCopyPlane --

 *
 *      Simplified version of XCopyPlane.  Right now it ignores
 *        function,
 *        clip_x_origin,
 *        clip_y_origin
 *
 *      The plane argument must always be 1.
 *
 *      This routine differs from the Tk version in how it handles
 *      transparency.  It uses a different method of drawing transparent
 *      bitmaps that doesn't copy the background or use brushes.  The
 *      second change is to call a special routine when the destDC is
 *      a printer.   Stippling is done by a very slow brute-force
 *      method of drawing 1x1 rectangles for each pixel (bleech).
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Changes the destination drawable.

 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXCopyPlane(

    Display *display,
    Drawable src,
    Drawable dest,
    GC gc,
    int srcX,
    int srcY,
    unsigned int width,
    unsigned int height,
    int destX,
    int destY,
    unsigned long plane)

{
    HDC srcDC, destDC;
    TkWinDCState srcState, destState;
    TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
    display->request++;
    if (plane != 1) {
        Tcl_Panic("Unexpected plane specified for XCopyPlane");






    }
    srcDC = TkWinGetDrawableDC(display, src, &srcState);
    if (src != dest) {
        destDC = TkWinGetDrawableDC(display, dest, &destState);
    } else {
        destDC = srcDC;
    }
    if ((clipPtr == NULL) || (clipPtr->type == TKP_CLIP_REGION)) {
        /*
         * Case 1: opaque bitmaps.  Windows handles the conversion
         * from one bit to multiple bits by setting 0 to the
         * foreground color, and 1 to the background color (seems
         * backwards, but there you are).















         */














        if ((clipPtr != NULL) && (clipPtr->type == TKP_CLIP_REGION)) {
            SelectClipRgn(destDC, (HRGN) clipPtr->value.region);
            OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin);


        }
        SetBkMode(destDC, OPAQUE);
        SetBkColor(destDC, gc->foreground);
        SetTextColor(destDC, gc->background);
        BitBlt(destDC, destX, destY, width, height, srcDC, srcX, srcY,
               SRCCOPY);
        SelectClipRgn(destDC, NULL);
    } else if (clipPtr->type == TKP_CLIP_PIXMAP) {
        Drawable mask;
        /*

         * Case 2: transparent bitmaps are handled by setting the
         * destination to the foreground color whenever the source
         * pixel is set.
         */










        /*
         * Case 3: two arbitrary bitmaps.  Copy the source rectangle
         * into a color pixmap.  Use the result as a brush when
         * copying the clip mask into the destination.

         */
        mask = clipPtr->value.pixmap;
#if WINDEBUG
        PurifyPrintf("mask %s src\n", (mask == src) ? "==" : "!=");
        PurifyPrintf("GetDeviceCaps=%x\n",
                     GetDeviceCaps(destDC, TECHNOLOGY) & DT_RASDISPLAY);
#endif
        {
            HDC maskDC;
            TkWinDCState maskState;
            if (mask != src) {

                maskDC = TkWinGetDrawableDC(display, mask, &maskState);
            } else {
                maskDC = srcDC;

            }
            SetBkMode(destDC, OPAQUE);
            SetTextColor(destDC, gc->background);
            SetBkColor(destDC, gc->foreground);
            BitBlt(destDC, destX, destY, width, height, srcDC, srcX, srcY,
                   SRCINVERT);
            /*
             * Make sure we treat the mask as a monochrome bitmap.
             * We can get alpha-blending with non-black/white fg/bg
             * color selections.

             */
            SetTextColor(destDC, RGB(255,255,255));
            SetBkColor(destDC, RGB(0,0,0));
            /* FIXME: Handle gc->clip_?_origin's */
            BitBlt(destDC, destX, destY, width, height, maskDC, 0, 0, SRCAND);
            SetTextColor(destDC, gc->background);
            SetBkColor(destDC, gc->foreground);
            BitBlt(destDC, destX, destY, width, height, srcDC, srcX, srcY,
                   SRCINVERT);
            if (mask != src) {
                TkWinReleaseDrawableDC(mask, maskDC, &maskState);


            }


        }

    }








    if (src != dest) {
        TkWinReleaseDrawableDC(dest, destDC, &destState);






    }
    TkWinReleaseDrawableDC(src, srcDC, &srcState);
}



/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXCopyArea --

 *
 *      Copies data from one drawable to another using block transfer
 *      routines.  The small enhancement over the version in Tk is
 *      that it doesn't assume that the source and destination devices
 *      have the same resolution. This isn't true when the destination
 *      device is a printer.

 *
 *      FIXME: not true anymore.  delete this routine.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Data is moved from a window or bitmap to a second window,
 *      bitmap, or printer.

 *
 *----------------------------------------------------------------------
 */
void
RbcEmulateXCopyArea(
    Display *display,
    Drawable src,
    Drawable dest,
    GC gc,
    int srcX, /* Source X-coordinate */
    int srcY, /* Source Y-coordinate. */
    unsigned int width, /* Width of area. */
    unsigned int height, /* Height of area. */
    int destX, /* Destination X-coordinate (in screen
                * coordinates). */
    int destY) /* Destination Y-coordinate (in screen
                * coordinates). */
{
    HDC srcDC, destDC;
    TkWinDCState srcState, destState;
    TkpClipMask *clipPtr;
    srcDC = TkWinGetDrawableDC(display, src, &srcState);
    if (src != dest) {
        destDC = TkWinGetDrawableDC(display, dest, &destState);
    } else {
        destDC = srcDC;




    }















    clipPtr = (TkpClipMask *)gc->clip_mask;
    if ((clipPtr != NULL) && (clipPtr->type == TKP_CLIP_REGION)) {
        SelectClipRgn(destDC, (HRGN)clipPtr->value.region);
        OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin);
    }

    BitBlt(destDC, destX, destY, width, height, srcDC, srcX, srcY,
           bltModes[gc->function]);
    SelectClipRgn(destDC, NULL);
    if (src != dest) {
        TkWinReleaseDrawableDC(dest, destDC, &destState);
    }
    TkWinReleaseDrawableDC(src, srcDC, &srcState);
}
/*
 *--------------------------------------------------------------
 *
 * StippleRegion --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static void
StippleRegion(

    Display *display,
    HDC hDC, /* Device context: For polygons, clip
              * region will be installed. */
    GC gc,
    int x,
    int y,

    int width,
    int height)
{



    BITMAP bm;
    HBITMAP oldBitmap;
    HDC maskDC, memDC;
    Pixmap mask;
    TkWinDCState maskState;
    TkWinDrawable *twdPtr;
    int destX, destY, destWidth, destHeight;
    int dx, dy;
    int left, top, right, bottom;
    int srcX, srcY;
    int startX, startY;		/* Starting upper left corner of region. */
    twdPtr = (TkWinDrawable *)gc->stipple;
    GetObject(twdPtr->bitmap.handle, sizeof(BITMAP), &bm);
    startX = x;
    if (x < gc->ts_x_origin) {
        dx = (gc->ts_x_origin - x) % bm.bmWidth;
        if (dx > 0) {
            startX -= (bm.bmWidth - dx);
        }
    } else if (x > gc->ts_x_origin) {
        dx = (x - gc->ts_x_origin) % bm.bmWidth;
        if (dx > 0) {
            startX -= dx;
        }
    }
    startY = y;
    if (y < gc->ts_y_origin) {
        dy = (gc->ts_y_origin - y) % bm.bmHeight;
        if (dy > 0) {
            startY -= (bm.bmHeight - dy);
        }
    } else if (y >= gc->ts_y_origin) {
        dy = (y - gc->ts_y_origin) % bm.bmHeight;
        if (dy > 0) {
            startY -= dy;
        }
    }
    left = x;
    right = x + width;
    top = y;
    bottom = y + height;
    maskDC = memDC = CreateCompatibleDC(hDC);
    oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle);
    mask = gc->stipple;
    if (gc->fill_style == FillStippled) { /* With transparency. */
        if (gc->clip_mask != None) {
            TkpClipMask *clipPtr;
            mask = gc->stipple;
            clipPtr = (TkpClipMask *)gc->clip_mask;
            if  (clipPtr->type == TKP_CLIP_PIXMAP) {
                mask = clipPtr->value.pixmap;
            }
        }
        if (mask != gc->stipple) {
            maskDC = TkWinGetDrawableDC(display, mask, &maskState);
        }
    }
    for (y = startY; y < bottom; y += bm.bmHeight) {
        srcY = 0;
        destY = y;
        destHeight = bm.bmHeight;
        if (y < top) {
            srcY = (top - y);
            destHeight = bm.bmHeight - srcY;
            destY = top;
        }
        if ((destY + destHeight) > bottom) {
            destHeight = (bottom - destY);
        }
        for (x = startX; x < right; x += bm.bmWidth) {
            srcX = 0;
            destX = x;
            destWidth = bm.bmWidth;
            if (x < left) {
                srcX = (left - x);
                destWidth = bm.bmWidth - srcX;
                destX = left;
            }
            if ((destX + destWidth) > right) {
                destWidth = (right - destX);
            }
            if (gc->fill_style == FillStippled) { /* With transparency. */
                SetBkMode(hDC, OPAQUE);
                SetTextColor(hDC, gc->background);
                SetBkColor(hDC, gc->foreground);
                BitBlt(hDC, destX, destY, destWidth, destHeight, memDC,
                       srcX, srcY, SRCINVERT);
                SetTextColor(hDC, RGB(255,255,255));
                SetBkColor(hDC, RGB(0,0,0));
                BitBlt(hDC, destX, destY, destWidth, destHeight, maskDC,
                       srcX, srcY, SRCAND);
                SetTextColor(hDC, gc->background);
                SetBkColor(hDC, gc->foreground);
                BitBlt(hDC, destX, destY, destWidth, destHeight, memDC,
                       srcX, srcY, SRCINVERT);
            } else if (gc->fill_style == FillOpaqueStippled) { /* Opaque. */
                SetBkColor(hDC, gc->foreground);
                SetTextColor(hDC, gc->background);
                BitBlt(hDC, destX, destY, destWidth, destHeight, memDC,
                       srcX, srcY, SRCCOPY);
            }
        }
    }
    SelectBitmap(memDC, oldBitmap);
    if (maskDC != memDC) {
        TkWinReleaseDrawableDC(mask, maskDC, &maskState);
    }
    DeleteDC(memDC);
}
/*
 *--------------------------------------------------------------
 *
 * RbcEmulateXFillPolygon --
 *
 *      This differs from Tk's XFillPolygon in that it works
 *      around deficencies in Windows 95/98:
 *        1. Stippling bitmap is limited to 8x8.
 *        2. No tiling (with or without mask).
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcEmulateXFillPolygon(
    Display *display,
    Drawable drawable,
    GC gc,
    XPoint *pointPtr,
    int nPoints,
    int shape,
    int mode)
{
    HDC hDC;
    HRGN hRgn;
    POINT *p, *winPts, *endPtr;
    RbcRegion2D bbox;
    TkWinDCState state;
    int fillMode;
    if (drawable == None) {
        return;
    }
    /* Determine the bounding box of the polygon. */
    bbox.left = bbox.right = pointPtr->x;
    bbox.top = bbox.bottom = pointPtr->y;
    hDC = TkWinGetDrawableDC(display, drawable, &state);
    /* Allocate array of POINTS to create the polygon's path. */
    winPts = (POINT *)ckalloc(sizeof(POINT) * nPoints);
    endPtr = winPts + nPoints;
    for (p = winPts; p < endPtr; p++) {
        if (pointPtr->x < bbox.left) {
            bbox.left = pointPtr->x;
        }
        if (pointPtr->x > bbox.right) {
            bbox.right = pointPtr->x;
        }
        if (pointPtr->y < bbox.top) {
            bbox.top = pointPtr->y;
        }
        if (pointPtr->y > bbox.bottom) {
            bbox.bottom = pointPtr->y;
        }
        p->x = pointPtr->x;
        p->y = pointPtr->y;
        pointPtr++;
    }
    RbcSetROP2(hDC, gc->function);
    fillMode = (gc->fill_rule == EvenOddRule) ? ALTERNATE : WINDING;
    if ((gc->fill_style == FillStippled) ||
            (gc->fill_style == FillOpaqueStippled)) {
        int width, height;
        /* Points are offsets within the bounding box. */
        for (p = winPts; p < endPtr; p++) {
            p->x -= bbox.left;
            p->y -= bbox.top;
        }
        /* Use the polygon as a clip path. */
        LPtoDP(hDC, winPts, nPoints);
        hRgn = CreatePolygonRgn(winPts, nPoints, fillMode);
        SelectClipRgn(hDC, hRgn);
        OffsetClipRgn(hDC, bbox.left, bbox.top);
        /* Tile the bounding box. */
        width = bbox.right - bbox.left + 1;
        height = bbox.bottom - bbox.top + 1;
        StippleRegion(display, hDC, gc, bbox.left, bbox.top, width, height);
        SelectClipRgn(hDC, NULL);
        DeleteRgn(hRgn);
    } else {
        HPEN oldPen;
        HBRUSH oldBrush;
        /*
         * FIXME: Right now, we're assuming that it's solid or
         * stippled and ignoring tiling. I'll merge the bits from
         * RbcTilePolygon later.
         */
        oldPen = SelectPen(hDC, GetStockObject(NULL_PEN));
        oldBrush = SelectBrush(hDC, CreateSolidBrush(gc->foreground));
        SetPolyFillMode(hDC, fillMode);
        Polygon(hDC, winPts, nPoints);
        SelectPen(hDC, oldPen);
        DeleteBrush(SelectBrush(hDC, oldBrush));
    }
    ckfree((char *)winPts);
    TkWinReleaseDrawableDC(drawable, hDC, &state);
}
/* vim: set ts=4 sw=4 sts=4 ff=unix et : */






|







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>







 







<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>

|

<
>

<
|
<
<

<
<
<
<
<
<
<
<
<

|


<
>

|


<
>

<
<

<
<
<
<
<
<
<
>

<
<
<
<
<
<
>
>
>
>
>
>
|
<
<
<
<
<
|
<
|
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
|
<
<
|
|
|
|
|
|
<
>
|
|
|
<
>
>
>
>
>
>
>
>
>
>
|
<
<
<
>
|
<
<
<
<
<
<
<
|
|
<
>
|
|
|
>

<
|
|
|
<

<
<
<
>

<
<
<
<
<
<
<
<
<
<
>
>

>
>

>

>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
|
<
|
>
>
>

|

<
>

<
<
<
<
<
>

<
<

|


<
<
>

|

<
|
|
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
>
|
|
|
<
<
|
<
|



|











|
<
>
|
<
<
<


>
|
<

>
>
>
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
158
159
160
161
162
163
164


165









































































































166
167
168
169
170
171
172
...
243
244
245
246
247
248
249


250













































































































































































































































251
252
253
254
255
256
257
...
285
286
287
288
289
290
291


292












































293
294
295
296
297
298
299
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
...
543
544
545
546
547
548
549


550

























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































551
552
553
554
555
556
557
...
669
670
671
672
673
674
675
676
677
678
679

680
681

682


683









684
685
686
687

688
689
690
691
692

693
694


695







696
697






698
699
700
701
702
703
704





705

706




707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742


743
744
745
746
747
748

749
750
751
752

753
754
755
756
757
758
759
760
761
762
763



764
765







766
767

768
769
770
771
772
773

774
775
776

777



778
779










780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811

812
813





814
815


816
817
818
819


820
821
822
823

824
825











826








827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850

851
852
853
854


855

856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872

873
874



875
876
877
878

879
880
881
882
883
884
885
886
887
888
889
890
891









892





























































































































893
894










895




















































896
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"
#include <X11/Xlib.h>

/*
 * Data structure for setting graphics context.
 */
typedef struct {
    int function;		/* logical operation */
    unsigned long plane_mask;	/* plane mask */
    unsigned long foreground;	/* foreground pixel */
................................................................................
    Pixmap clip_mask;		/* bitmap clipping; other calls for rects */
    int dash_offset;		/* patterned/dashed line information */
    char dashes;		/* If -1, indicates that the extended
				 * information below is available. */
    int nDashValues;
    char dashValues[12];
} XGCValuesEx;

static Tcl_Encoding systemEncoding = NULL;

static HFONT CreateRotatedFont(
    unsigned long fontId,
    double theta);
static XGCValuesEx *CreateGC();
static BOOL DrawChars(
    HDC dc,
    int x,
    int y,
    char *string,
    int length);

/*
 *--------------------------------------------------------------
 *
 * RbcGetPlatformId --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcGetPlatformId(
    )
{
    static int      platformId = 0;

    if (platformId == 0) {
        OSVERSIONINFO   opsysInfo;

        opsysInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        if (GetVersionEx(&opsysInfo)) {
            platformId = opsysInfo.dwPlatformId;
        }
    }
    return platformId;
}

/*
 *--------------------------------------------------------------
 *
 * RbcLastError --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
RbcLastError(
    )
{
    static char     buffer[1024];
    int             length;

    FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
        buffer, 1024, NULL);
    length = strlen(buffer);
    if (buffer[length - 2] == '\r') {
        buffer[length - 2] = '\0';
    }
    return buffer;
}

/*
 *--------------------------------------------------------------
 *
 * RbcGetSystemPalette --
 *
 *      TODO: Description
 *
................................................................................
        GetSystemPaletteEntries(hDC, 0, 256, palettePtr->palPalEntry);
        hPalette = CreatePalette(palettePtr);
        GlobalFree(palettePtr);
    }
    ReleaseDC(NULL, hDC);
    return hPalette;
}












































































































/*
 *--------------------------------------------------------------
 *
 * RbcGetBitmapData --
 *
 *      Returns the DIB bits from a bitmap.
 *
................................................................................
        }
    }
    *pitchPtr = bytesPerRow;
    GlobalUnlock(hMem);
    GlobalFree(hMem);
    return bits;
}
















































































































































































































































/*
 *--------------------------------------------------------------
 *
 * RbcSetROP2 --
 *
 *      TODO: Description
 *
................................................................................
    R2_MERGENOTPEN,		/* GXorInverted */
    R2_NOTMASKPEN,		/* GXnand */
    R2_WHITE			/* GXset */
};
    if (function < 0 || function > 15) return;
    SetROP2(dc, WinRop2Mode[function]);
}















































/*
 *----------------------------------------------------------------------
 *
 * RbcEmulateXCreateGC --
 *
 *      Allocate a new extended GC, and initialize the specified fields.
 *
................................................................................
#define TKP_CLIP_PIXMAP 0
        clipPtr->type = TKP_CLIP_PIXMAP;
        clipPtr->pixmap = srcPtr->clip_mask;
        destPtr->clip_mask = (Pixmap) clipPtr;
    }
    return (GC)destPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGCToPen --
 *
 *      Set up the graphics port from the given GC.
 *
................................................................................
            /* Otherwise sacrifice thick lines for dashes. */
            pen = ExtCreatePen(PS_COSMETIC | lineStyle, 1, &lBrush, 0, NULL);
        }
    }
    assert(pen != NULL);
    return pen;
}




























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































/*
 *--------------------------------------------------------------
 *
 * RbcDrawRotatedText --
 *
 *      TODO: Description
 *
................................................................................
    }
done:
    SelectFont(hDC, oldFont);
    DeleteFont(hFont);
    TkWinReleaseDrawableDC(drawable, hDC, &state);
    return TRUE;
}

/*
 *--------------------------------------------------------------
 *

 * RbcSetDashes --
 *

 *      TODO: Description


 *









 * Results:
 *      TODO: Results
 *
 * Side effects:

 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void

RbcSetDashes(
    Display *display,


    GC gc,







    RbcDashes *dashesPtr)
{






    XGCValuesEx *gcPtr = (XGCValuesEx *)gc;
    /* This must be used only with a privately created GC */
    assert((int)gcPtr->dashes == -1);
    gcPtr->nDashValues = strlen(dashesPtr->values);
    gcPtr->dash_offset = dashesPtr->offset;
    strcpy(gcPtr->dashValues, dashesPtr->values);
}







/*




 *--------------------------------------------------------------
 *
 * CreateRotatedFont --
 *
 *      Creates a rotated copy of the given font.  This only works
 *      for TrueType fonts.
 *
 * Results:
 *      Returns the newly create font or NULL if the font could not
 *      be created.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static HFONT
CreateRotatedFont(
    unsigned long fontId, /* Font identifier (actually a Tk_Font) */
    double theta) /* Number of degrees to rotate font */
{
    TkFontAttributes *faPtr;	/* Set of attributes to match. */
    TkFont *fontPtr;
    HFONT hFont;
    LOGFONTW lf;
    fontPtr = (TkFont *) fontId;
    faPtr = &fontPtr->fa;
    ZeroMemory(&lf, sizeof(LOGFONT));
    lf.lfHeight = -faPtr->size;
    if (lf.lfHeight < 0) {
        HDC dc;
        dc = GetDC(NULL);
        lf.lfHeight = -MulDiv(faPtr->size,
                              GetDeviceCaps(dc, LOGPIXELSY), 72);
        ReleaseDC(NULL, dc);
    }


    lf.lfWidth = 0;
    lf.lfEscapement = lf.lfOrientation = ROUND(theta * 10.0);
#define TK_FW_NORMAL	0
    lf.lfWeight = (faPtr->weight == TK_FW_NORMAL) ? FW_NORMAL : FW_BOLD;
    lf.lfItalic = faPtr->slant;
    lf.lfUnderline = faPtr->underline;

    lf.lfStrikeOut = faPtr->overstrike;
    lf.lfCharSet = DEFAULT_CHARSET;
    lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;

    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    hFont = NULL;
    if (faPtr->family == NULL) {
        lf.lfFaceName[0] = '\0';
    } else {
        Tcl_DString dString;
        Tcl_UtfToExternalDString(systemEncoding, faPtr->family, -1, &dString);
        if (RbcGetPlatformId() == VER_PLATFORM_WIN32_NT) {
            Tcl_UniChar *src, *dst;
            /*



             * We can only store up to LF_FACESIZE wide characters
             */







            if (Tcl_DStringLength(&dString) >= (int)(LF_FACESIZE * sizeof(WCHAR))) {
                Tcl_DStringSetLength(&dString, LF_FACESIZE);

            }
            src = (Tcl_UniChar *)Tcl_DStringValue(&dString);
            dst = (Tcl_UniChar *)lf.lfFaceName;
            while (*src != '\0') {
                *dst++ = *src++;
            }

            *dst = '\0';
            hFont = CreateFontIndirectW((LOGFONTW *)&lf);
        } else {

            /*



             * We can only store up to LF_FACESIZE characters
             */










            if (Tcl_DStringLength(&dString) >= LF_FACESIZE) {
                Tcl_DStringSetLength(&dString, LF_FACESIZE);
            }
            strcpy((char *)lf.lfFaceName, Tcl_DStringValue(&dString));
            hFont = CreateFontIndirectA((LOGFONTA *)&lf);
        }
        Tcl_DStringFree(&dString);
    }
    if (hFont == NULL) {
    } else {
        HFONT oldFont;
        TEXTMETRIC tm;
        HDC hRefDC;
        int result;
        /* Check if the rotated font is really a TrueType font. */
        hRefDC = GetDC(NULL);		/* Get the desktop device context */
        oldFont = SelectFont(hRefDC, hFont);
        result = ((GetTextMetrics(hRefDC, &tm)) &&
                  (tm.tmPitchAndFamily & TMPF_TRUETYPE));
        SelectFont(hRefDC, oldFont);
        ReleaseDC(NULL, hRefDC);
        if (!result) {
            DeleteFont(hFont);
            return NULL;
        }

    }
    return hFont;
}

/*
 *--------------------------------------------------------------
 *

 * CreateGC --
 *





 *      TODO: Description
 *


 * Results:
 *      TODO: Results
 *
 * Side effects:


 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */

static XGCValuesEx *
CreateGC()











{








    XGCValuesEx *gcPtr;
    gcPtr = (XGCValuesEx *)ckalloc(sizeof(XGCValuesEx));
    if (gcPtr == NULL) {
        return NULL;
    }
    gcPtr->arc_mode = ArcPieSlice;
    gcPtr->background = 0xffffff;
    gcPtr->cap_style = CapNotLast;
    gcPtr->clip_mask = None;
    gcPtr->clip_x_origin = gcPtr->clip_y_origin = 0;
    gcPtr->dash_offset	= 0;
    gcPtr->fill_rule = WindingRule;
    gcPtr->fill_style = FillSolid;
    gcPtr->font = None;
    gcPtr->foreground = 0;
    gcPtr->function = GXcopy;
    gcPtr->graphics_exposures = True;
    gcPtr->join_style = JoinMiter;
    gcPtr->line_style = LineSolid;
    gcPtr->line_width = 0;
    gcPtr->plane_mask = ~0;
    gcPtr->stipple = None;
    gcPtr->subwindow_mode = ClipByChildren;
    gcPtr->tile = None;

    gcPtr->ts_x_origin = gcPtr->ts_y_origin = 0;
    gcPtr->dashes = -1;    /* Mark that this an extended GC */
    gcPtr->nDashValues	= 0;
    return gcPtr;


}


/*
 *--------------------------------------------------------------
 *
 * DrawChars --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static BOOL

DrawChars(
    HDC dc,



    int x,
    int y,
    char *string,
    int length)

{
    BOOL result;
    if (systemEncoding == NULL) {
        result = TextOutA(dc, x, y, string, length);
    } else {
        const unsigned short *wstring;
        Tcl_DString dString;
        Tcl_DStringInit(&dString);
        Tcl_UtfToExternalDString(systemEncoding, string, length, &dString);
        length = Tcl_NumUtfChars(string, -1);
        wstring = (const unsigned short *)Tcl_DStringValue(&dString);
        result = TextOutW(dc, x, y, wstring, length);
        Tcl_DStringFree(&dString);









    }





























































































































    return result;
}































































/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Deleted generic/rbc/rbcWinUtil.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * rbcWinUtil.c --
 *
 *      This module contains WIN32 routines not included in the Tcl/Tk
 *      libraries.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/*
 *--------------------------------------------------------------
 *
 * RbcGetPlatformId --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcGetPlatformId(
    )
{
    static int      platformId = 0;

    if (platformId == 0) {
        OSVERSIONINFO   opsysInfo;

        opsysInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        if (GetVersionEx(&opsysInfo)) {
            platformId = opsysInfo.dwPlatformId;
        }
    }
    return platformId;
}

/*
 *--------------------------------------------------------------
 *
 * RbcLastError --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
RbcLastError(
    )
{
    static char     buffer[1024];
    int             length;

    FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
        buffer, 1024, NULL);
    length = strlen(buffer);
    if (buffer[length - 2] == '\r') {
        buffer[length - 2] = '\0';
    }
    return buffer;
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























































































































































Changes to generic/rbc/rbcWindow.c.

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
...
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
....
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
    int             internalBorderWidth;
    TkWinInfo      *wmInfoPtr;
    TkClassProcs   *classProcsPtr;
    ClientData      instanceData;
    TkWindowPrivate *privatePtr;
};

static void     DoConfigureNotify(
    Tk_FakeWin * winPtr);
static void     UnlinkWindow(
    TkWindow * winPtr);
static int      GetWindowSize(
    Tcl_Interp * interp,
    Window window,
    int *widthPtr,
    int *heightPtr);

#ifdef _WIN32

/*
 *----------------------------------------------------------------------
 *
 * GetWindowHandle --
 *
 *      Returns the XID for the Tk_Window given.  Starting in Tk 8.0,
 *      the toplevel widgets are wrapped by another window.
 *      Currently there's no way to get at that window, other than
 *      what is done here: query the X window hierarchy and grab the
 *      parent.
 *
 * Results:
 *      Returns the X Window ID of the widget.  If it's a toplevel,
 *      then the XID of the wrapper is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static          HWND
GetWindowHandle(
    Tk_Window tkwin)
{
    HWND            hWnd;
    Window          window;

    window = Tk_WindowId(tkwin);
    if (window == None) {
        Tk_MakeWindowExist(tkwin);
    }
    hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
    if (Tk_IsTopLevel(tkwin)) {
        hWnd = GetParent(hWnd);
    }
    return hWnd;
}

#else

/*
 *--------------------------------------------------------------
 *
 * RbcGetParent --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
Window
RbcGetParent(
    Display * display,
    Window window)
{
    Window          root, parent;
    Window         *dummy;
    unsigned int    count;

    if (XQueryTree(display, window, &root, &parent, &dummy, &count) > 0) {
        XFree(dummy);
        return parent;
    }
    return None;
}

/*
 *--------------------------------------------------------------
 *
 * GetWindowId --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static          Window
GetWindowId(
    Tk_Window tkwin)
{
    Window          window;

    Tk_MakeWindowExist(tkwin);
    window = Tk_WindowId(tkwin);

    if (Tk_IsTopLevel(tkwin)) {
        Window          parent;

        parent = RbcGetParent(Tk_Display(tkwin), window);
        if (parent != None) {
            window = parent;
        }
        window = parent;
    }
    return window;
}

#endif /* _WIN32 */

/*
 *----------------------------------------------------------------------
 *
 * DoConfigureNotify --
 *
 *      Generate a ConfigureNotify event describing the current
 *      configuration of a window.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      An event is generated and processed by Tk_HandleEvent.
 *
 *----------------------------------------------------------------------
 */
static void
DoConfigureNotify(
    Tk_FakeWin * winPtr)
{                               /* Window whose configuration was just
                                 * changed. */
    XEvent          event;

    event.type = ConfigureNotify;
    event.xconfigure.serial = LastKnownRequestProcessed(winPtr->display);
    event.xconfigure.send_event = False;
    event.xconfigure.display = winPtr->display;
    event.xconfigure.event = winPtr->window;
    event.xconfigure.window = winPtr->window;
    event.xconfigure.x = winPtr->changes.x;
    event.xconfigure.y = winPtr->changes.y;
    event.xconfigure.width = winPtr->changes.width;
    event.xconfigure.height = winPtr->changes.height;
    event.xconfigure.border_width = winPtr->changes.border_width;
    if (winPtr->changes.stack_mode == Above) {
        event.xconfigure.above = winPtr->changes.sibling;
    } else {
        event.xconfigure.above = None;
    }
    event.xconfigure.override_redirect = winPtr->atts.override_redirect;
    Tk_HandleEvent(&event);
}

/*
 *--------------------------------------------------------------
 *
 * RbcMakeTransparentWindowExist --
 *
 *      Similar to Tk_MakeWindowExist but instead creates a
 *      transparent window to block for user events from
 *      sibling windows.
 *
 *      Differences from Tk_MakeWindowExist.
 *
 *        1. This is always a "busy" window. There's never a
 *           platform-specific class procedure to execute
 *           instead.
 *        2. The window is transparent and never will contain
 *           children, so colormap information is irrelevant.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      When the procedure returns, the internal window
 *      associated with tkwin is guaranteed to exist.  This
 *      may require the window's ancestors to be created too.
 *
 *--------------------------------------------------------------
 */
void
RbcMakeTransparentWindowExist(
    Tk_Window tkwin,            /* Token for window. */
    Window parent,              /* Parent window. */
    int isBusy)
{                               /*  */
    TkWindow       *winPtr = (TkWindow *) tkwin;
    TkWindow       *winPtr2;
    Tcl_HashEntry  *hPtr;
    int             notUsed;
    TkDisplay      *dispPtr;
#ifdef _WIN32
    HWND            hParent;
    int             style;
    DWORD           exStyle;
    HWND            hWnd;
#else
    long int        mask;
#endif /* _WIN32 */

    if (winPtr->window != None) {
        return;                 /* Window already exists. */
    }
#ifdef notdef
    if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_LEVEL)) {
        parent = XRootWindow(winPtr->display, winPtr->screenNum);
        /* TODO: Make the entire screen busy */
    } else {
        if (Tk_WindowId(winPtr->parentPtr) == None) {
            Tk_MakeWindowExist((Tk_Window) winPtr->parentPtr);
        }
    }
#endif

    /* Create a transparent window and put it on top.  */

#ifdef _WIN32
    hParent = (HWND) parent;
    style = (WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
    exStyle = (WS_EX_TRANSPARENT | WS_EX_TOPMOST);
#ifndef TK_WIN_CHILD_CLASS_NAME /* from tkWinInt.h */
#define TK_WIN_CHILD_CLASS_NAME "TkChild"
#endif
    hWnd = CreateWindowEx(exStyle, TK_WIN_CHILD_CLASS_NAME, NULL, style,
        Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
        hParent, NULL, (HINSTANCE) Tk_GetHINSTANCE(), NULL);
    winPtr->window = Tk_AttachHWND(tkwin, hWnd);
#else
    mask = (!isBusy) ? 0 : (CWDontPropagate | CWEventMask);
    /* Ignore the important events while the window is mapped.  */
#define USER_EVENTS  (EnterWindowMask | LeaveWindowMask | KeyPressMask | \
	KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define PROP_EVENTS  (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
	ButtonReleaseMask | PointerMotionMask)

    winPtr->atts.do_not_propagate_mask = PROP_EVENTS;
    winPtr->atts.event_mask = USER_EVENTS;
    winPtr->changes.border_width = 0;
    winPtr->depth = 0;

    winPtr->window = XCreateWindow(winPtr->display, parent, winPtr->changes.x, winPtr->changes.y, (unsigned) winPtr->changes.width,     /* width */
        (unsigned) winPtr->changes.height,      /* height */
        (unsigned) winPtr->changes.border_width,        /* border_width */
        winPtr->depth,          /* depth */
        InputOnly,              /* class */
        winPtr->visual,         /* visual */
        mask,                   /* valuemask */
        &(winPtr->atts) /* attributes */ );
#endif /* _WIN32 */

    dispPtr = winPtr->dispPtr;
    hPtr = Tcl_CreateHashEntry(&(dispPtr->winTable), (char *) winPtr->window,
        &notUsed);
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->dirtyAtts = 0;
    winPtr->dirtyChanges = 0;
#ifdef TK_USE_INPUT_METHODS
    winPtr->inputContext = NULL;
#endif /* TK_USE_INPUT_METHODS */
    if (!(winPtr->flags & TK_TOP_LEVEL)) {
        /*
         * If any siblings higher up in the stacking order have already
         * been created then move this window to its rightful position
         * in the stacking order.
         *
         * NOTE: this code ignores any changes anyone might have made
         * to the sibling and stack_mode field of the window's attributes,
         * so it really isn't safe for these to be manipulated except
         * by calling Tk_RestackWindow.
         */
        for (winPtr2 = winPtr->nextPtr; winPtr2 != NULL;
            winPtr2 = winPtr2->nextPtr) {
            if ((winPtr2->window != None) && !(winPtr2->flags & TK_TOP_LEVEL)) {
                XWindowChanges  changes;
                changes.sibling = winPtr2->window;
                changes.stack_mode = Below;
                XConfigureWindow(winPtr->display, winPtr->window,
                    CWSibling | CWStackMode, &changes);
                break;
            }
        }
    }

    /*
     * Issue a ConfigureNotify event if there were deferred configuration
     * changes (but skip it if the window is being deleted;  the
     * ConfigureNotify event could cause problems if we're being called
     * from Tk_DestroyWindow under some conditions).
     */
    if ((winPtr->flags & TK_NEED_CONFIG_NOTIFY)
        && !(winPtr->flags & TK_ALREADY_DEAD)) {
        winPtr->flags &= ~TK_NEED_CONFIG_NOTIFY;
        DoConfigureNotify((Tk_FakeWin *) tkwin);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcFindChild --
 *
 *      Performs a linear search for the named child window in a given
 *      parent window.
................................................................................
        if (strcmp(name, winPtr->nameUid) == 0) {
            return (Tk_Window) winPtr;
        }
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcFirstChildWindow --
 *
 *      Performs a linear search for the named child window in a given
 *      parent window.
 *
 *      This can be done via Tcl, but not through Tk's C API.  It's
 *      simple enough, if you peek into the Tk_Window structure.
 *
 * Results:
 *      The child Tk_Window. If the named child can't be found, NULL
 *      is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
Tk_Window
RbcFirstChild(
    Tk_Window parent)
{
    TkWindow       *parentPtr = (TkWindow *) parent;
    return (Tk_Window) parentPtr->childList;
}

/*
 *--------------------------------------------------------------
 *
 * RbcNextChild --
 *
 *      TODO: Description
 *
 * Results:
 *      The child Tk_Window. If the named child can't be found, NULL
 *      is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
Tk_Window
RbcNextChild(
    Tk_Window tkwin)
{
    TkWindow       *winPtr = (TkWindow *) tkwin;

    if (winPtr == NULL) {
        return NULL;
    }
    return (Tk_Window) winPtr->nextPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * UnlinkWindow --
 *
 *      This procedure removes a window from the childList of its
 *      parent.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      The window is unlinked from its childList.
 *
 *----------------------------------------------------------------------
 */
static void
UnlinkWindow(
    TkWindow * winPtr)
{                               /* Child window to be unlinked. */
    TkWindow       *prevPtr;

    prevPtr = winPtr->parentPtr->childList;
    if (prevPtr == winPtr) {
        winPtr->parentPtr->childList = winPtr->nextPtr;
        if (winPtr->nextPtr == NULL) {
            winPtr->parentPtr->lastChildPtr = NULL;
        }
    } else {
        while (prevPtr->nextPtr != winPtr) {
            prevPtr = prevPtr->nextPtr;
            if (prevPtr == NULL) {
                Tcl_Panic("UnlinkWindow couldn't find child in parent");
            }
        }
        prevPtr->nextPtr = winPtr->nextPtr;
        if (winPtr->nextPtr == NULL) {
            winPtr->parentPtr->lastChildPtr = prevPtr;
        }
    }
}

/*
 *--------------------------------------------------------------
 *
 * RbcRootCoordinates --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcRootCoordinates(
    Tk_Window tkwin,
    int x,
    int y,
    int *rootXPtr,
    int *rootYPtr)
{
    int             vx, vy, vw, vh;
    int             rootX, rootY;

    Tk_GetRootCoords(tkwin, &rootX, &rootY);
    x += rootX;
    y += rootY;
    Tk_GetVRootGeometry(tkwin, &vx, &vy, &vw, &vh);
    x += vx;
    y += vy;
    *rootXPtr = x;
    *rootYPtr = y;
}

/*
 *--------------------------------------------------------------
 *
 * RbcRootX --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcRootX(
    Tk_Window tkwin)
{
    int             x;

    for (x = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
        x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width;
        if (Tk_IsTopLevel(tkwin)) {
            break;
        }
    }
    return x;
}

/*
 *--------------------------------------------------------------
 *
 * RbcRootY --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcRootY(
    Tk_Window tkwin)
{
    int             y;

    for (y = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
        y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
        if (Tk_IsTopLevel(tkwin)) {
            break;
        }
    }
    return y;
}

#ifdef _WIN32

/*
 *----------------------------------------------------------------------
 *
 * RbcGetRealWindowId --
 *
 *      Returns the XID for the Tk_Window given.  Starting in Tk 8.0,
 *      the toplevel widgets are wrapped by another window.
 *      Currently there's no way to get at that window, other than
 *      what is done here: query the X window hierarchy and grab the
 *      parent.
 *
 * Results:
 *      Returns the X Window ID of the widget.  If it's a toplevel,
 *      then the XID of the wrapper is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
Window
RbcGetRealWindowId(
    Tk_Window tkwin)
{
    return (Window) GetWindowHandle(tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGetToplevel --
 *
 *      Retrieves the toplevel window which is the nearest ancestor of
 *      of the specified window.
 *
 * Results:
 *      Returns the toplevel window or NULL if the window has no
 *      ancestor which is a toplevel.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
Tk_Window
RbcGetToplevel(
    Tk_Window tkwin)
{                               /* Window for which the toplevel
                                 * should be deterined. */
    while (!Tk_IsTopLevel(tkwin)) {
        tkwin = Tk_Parent(tkwin);
        if (tkwin == NULL) {
            return NULL;
        }
    }
    return tkwin;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcRaiseToLevelWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcRaiseToplevel(
    Tk_Window tkwin)
{
    SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, 0, 0, 0, 0,
        SWP_NOMOVE | SWP_NOSIZE);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcMapToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcMapToplevel(
    Tk_Window tkwin)
{
    ShowWindow(GetWindowHandle(tkwin), SW_SHOWNORMAL);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcUnmapToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcUnmapToplevel(
    Tk_Window tkwin)
{
    ShowWindow(GetWindowHandle(tkwin), SW_HIDE);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcMoveResizeToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcMoveResizeToplevel(
    Tk_Window tkwin,
    int x,
    int y,
    int width,
    int height)
{
    SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, x, y, width, height, 0);
}

/*
 *--------------------------------------------------------------
 *
 * RbcReparentWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcReparentWindow(
    Display * display,
    Window window,
    Window newParent,
    int x,
    int y)
{
    XReparentWindow(display, window, newParent, x, y);
    return TCL_OK;
}

#else /* _WIN32 */

/*
 *----------------------------------------------------------------------
 *
 * RbcGetRealWindowId --
 *
 *      Returns the XID for the Tk_Window given.  Starting in Tk 8.0,
 *      the toplevel widgets are wrapped by another window.
 *      Currently there's no way to get at that window, other than
 *      what is done here: query the X window hierarchy and grab the
 *      parent.
 *
 * Results:
 *      Returns the X Window ID of the widget.  If it's a toplevel, then
 *      the XID of the wrapper is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
Window
RbcGetRealWindowId(
    Tk_Window tkwin)
{
    return GetWindowId(tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcRaiseToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcRaiseToplevel(
    Tk_Window tkwin)
{
    XRaiseWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * RbcLowerToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcLowerToplevel(
    Tk_Window tkwin)
{
    XLowerWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * RbcResizeToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcResizeToplevel(
    Tk_Window tkwin,
    int width,
    int height)
{
    XResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), width, height);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcMoveResizeToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcMoveResizeToplevel(
    Tk_Window tkwin,
    int x,
    int y,
    int width,
    int height)
{
    XMoveResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y,
        width, height);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcMoveToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcMoveToplevel(
    Tk_Window tkwin,
    int x,
    int y)
{
    XMoveWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcMapToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcMapToplevel(
    Tk_Window tkwin)
{
    XMapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * RbcUnmapToplevel --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcUnmapToplevel(
    Tk_Window tkwin)
{
    XUnmapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * XReparentWindowErrorProc --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
XReparentWindowErrorProc(
    ClientData clientData,
    XErrorEvent * errEventPtr)
{
    int            *errorPtr = clientData;

    *errorPtr = TCL_ERROR;
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcReparentWindow --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcReparentWindow(
    Display * display,
    Window window,
    Window newParent,
    int x,
    int y)
{
    Tk_ErrorHandler handler;
    int             result;
    int             any = -1;

    result = TCL_OK;
    handler = Tk_CreateErrorHandler(display, any, X_ReparentWindow, any,
        XReparentWindowErrorProc, &result);
    XReparentWindow(display, window, newParent, x, y);
    Tk_DeleteErrorHandler(handler);
    XSync(display, False);
    return result;
}

#endif /* _WIN32 */

/*
 *--------------------------------------------------------------
 *
 * RbcSetWindowInstanceData --
 *
 *      TODO: Description
 *
................................................................................
        Tk_MakeWindowExist(tkwin);
    }

    if (Tk_IsTopLevel(tkwin)) {
        Tcl_SetObjResult(interp,
            Tcl_ObjPrintf("window \"%s\" is not supported toplvel", pathName));
        return TCL_ERROR;

/*TODO        window = RbcGetRealWindowId(tkwin);*/
    } else {
        window = Tk_WindowId(tkwin);
    }

    if (GetWindowSize(interp, window, &width, &height) != TCL_OK) {
        Tcl_SetObjResult(interp,
            Tcl_ObjPrintf("can't get window geometry of \"%s\"", pathName));






<
<
<
<






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<







79
80
81
82
83
84
85




86
87
88
89
90
91









































































































































































































































































































92
93
94
95
96
97
98
...
122
123
124
125
126
127
128






















































































































































































































































































































































































































































































































































































































































129
130
131
132
133
134
135
...
240
241
242
243
244
245
246


247
248
249
250
251
252
253
    int             internalBorderWidth;
    TkWinInfo      *wmInfoPtr;
    TkClassProcs   *classProcsPtr;
    ClientData      instanceData;
    TkWindowPrivate *privatePtr;
};





static int      GetWindowSize(
    Tcl_Interp * interp,
    Window window,
    int *widthPtr,
    int *heightPtr);










































































































































































































































































































/*
 *----------------------------------------------------------------------
 *
 * RbcFindChild --
 *
 *      Performs a linear search for the named child window in a given
 *      parent window.
................................................................................
        if (strcmp(name, winPtr->nameUid) == 0) {
            return (Tk_Window) winPtr;
        }
    }
    return NULL;
}























































































































































































































































































































































































































































































































































































































































/*
 *--------------------------------------------------------------
 *
 * RbcSetWindowInstanceData --
 *
 *      TODO: Description
 *
................................................................................
        Tk_MakeWindowExist(tkwin);
    }

    if (Tk_IsTopLevel(tkwin)) {
        Tcl_SetObjResult(interp,
            Tcl_ObjPrintf("window \"%s\" is not supported toplvel", pathName));
        return TCL_ERROR;


    } else {
        window = Tk_WindowId(tkwin);
    }

    if (GetWindowSize(interp, window, &width, &height) != TCL_OK) {
        Tcl_SetObjResult(interp,
            Tcl_ObjPrintf("can't get window geometry of \"%s\"", pathName));

Changes to library/tk.tcl.

684
685
686
687
688
689
690






691
692
693
694
695
    }
}

# Run the Ttk themed widget set initialization
if {$::ttk::library ne ""} {
    uplevel \#0 [list source $::ttk::library/ttk.tcl]
}






 
# Local Variables:
# mode: tcl
# fill-column: 78
# End:






>
>
>
>
>
>





684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    }
}

# Run the Ttk themed widget set initialization
if {$::ttk::library ne ""} {
    uplevel \#0 [list source $::ttk::library/ttk.tcl]
}

# load rbc related file
if {$::tk_library ne ""} {
    uplevel \#0 [list source $::tk_library/rbc/graph.tcl]
}

 
# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to unix/Makefile.in.

830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
...
850
851
852
853
854
855
856







857
858
859
860
861
862
863
	@[email protected]
	@echo "Installing pkg-config file to $(LIB_INSTALL_DIR)/pkgconfig/"
	@$(INSTALL_DATA_DIR) $(LIB_INSTALL_DIR)/pkgconfig
	@$(INSTALL_DATA) tk.pc $(LIB_INSTALL_DIR)/pkgconfig/tk.pc

install-libraries: libraries
	@for i in "$(SCRIPT_INSTALL_DIR)" "$(SCRIPT_INSTALL_DIR)/images" \
		"$(SCRIPT_INSTALL_DIR)/msgs" "$(SCRIPT_INSTALL_DIR)/ttk"; \

	    do \
	    if [ -n "$$i" -a ! -d "$$i" ] ; then \
		echo "Making directory $$i"; \
		$(INSTALL_DATA_DIR) "$$i"; \
		else true; \
		fi; \
	    done;
................................................................................
	    done;
	@echo "Installing Ttk library files to $(SCRIPT_INSTALL_DIR)/ttk/";
	@for i in $(TOP_DIR)/library/ttk/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)/ttk"; \
	    fi; \







	    done;
	@echo "Installing library image files to $(SCRIPT_INSTALL_DIR)/images/";
	@for i in $(TOP_DIR)/library/images/*; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)/images"; \
	    fi; \






|
>







 







>
>
>
>
>
>
>







830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
...
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
	@[email protected]
	@echo "Installing pkg-config file to $(LIB_INSTALL_DIR)/pkgconfig/"
	@$(INSTALL_DATA_DIR) $(LIB_INSTALL_DIR)/pkgconfig
	@$(INSTALL_DATA) tk.pc $(LIB_INSTALL_DIR)/pkgconfig/tk.pc

install-libraries: libraries
	@for i in "$(SCRIPT_INSTALL_DIR)" "$(SCRIPT_INSTALL_DIR)/images" \
		"$(SCRIPT_INSTALL_DIR)/msgs" "$(SCRIPT_INSTALL_DIR)/ttk" \
		"$(SCRIPT_INSTALL_DIR)/rbc"; \
	    do \
	    if [ -n "$$i" -a ! -d "$$i" ] ; then \
		echo "Making directory $$i"; \
		$(INSTALL_DATA_DIR) "$$i"; \
		else true; \
		fi; \
	    done;
................................................................................
	    done;
	@echo "Installing Ttk library files to $(SCRIPT_INSTALL_DIR)/ttk/";
	@for i in $(TOP_DIR)/library/ttk/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)/ttk"; \
	    fi; \
	    done;
	@echo "Installing Rbc library files to $(SCRIPT_INSTALL_DIR)/rbc/";
	@for i in $(TOP_DIR)/library/rbc/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)/rbc"; \
	    fi; \
	    done;
	@echo "Installing library image files to $(SCRIPT_INSTALL_DIR)/images/";
	@for i in $(TOP_DIR)/library/images/*; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)/images"; \
	    fi; \

Changes to win/Makefile.in.

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
...
576
577
578
579
580
581
582







583
584
585
586
587
588
589
	rbcUtil.$(OBJEXT) \
	rbcVecMath.$(OBJEXT) \
	rbcVecObjCmd.$(OBJEXT) \
	rbcVector.$(OBJEXT) \
	rbcWindow.$(OBJEXT) \
	rbcWinDraw.$(OBJEXT) \
	rbcWinImage.$(OBJEXT) \
	rbcWinUtil.$(OBJEXT) \

STUB_OBJS = \
	tkStubLib.$(OBJEXT) \
	ttkStubLib.$(OBJEXT)

TCL_DOCS = "$(TCL_SRC_DIR_NATIVE)/doc/*.[13n]"
TK_DOCS = "$(ROOT_DIR_NATIVE)/doc/*.[13n]"
................................................................................
	    fi; \
	    done

install-libraries: libraries
	@for i in $(INSTALL_ROOT)$(prefix)/lib \
		$(INCLUDE_INSTALL_DIR) $(INCLUDE_INSTALL_DIR)/X11 \
		$(SCRIPT_INSTALL_DIR) $(SCRIPT_INSTALL_DIR)/images \
		$(SCRIPT_INSTALL_DIR)/msgs $(SCRIPT_INSTALL_DIR)/ttk; \

	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		$(MKDIR) $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
................................................................................
	    done;
	@echo "Installing library ttk directory";
	@for i in $(ROOT_DIR)/library/ttk/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i $(SCRIPT_INSTALL_DIR)/ttk; \
	    fi; \







	    done;
	@echo "Installing library images directory";
	@for i in $(ROOT_DIR)/library/images/*; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i $(SCRIPT_INSTALL_DIR)/images; \
	    fi; \






<







 







|
>







 







>
>
>
>
>
>
>







426
427
428
429
430
431
432

433
434
435
436
437
438
439
...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
	rbcUtil.$(OBJEXT) \
	rbcVecMath.$(OBJEXT) \
	rbcVecObjCmd.$(OBJEXT) \
	rbcVector.$(OBJEXT) \
	rbcWindow.$(OBJEXT) \
	rbcWinDraw.$(OBJEXT) \
	rbcWinImage.$(OBJEXT) \


STUB_OBJS = \
	tkStubLib.$(OBJEXT) \
	ttkStubLib.$(OBJEXT)

TCL_DOCS = "$(TCL_SRC_DIR_NATIVE)/doc/*.[13n]"
TK_DOCS = "$(ROOT_DIR_NATIVE)/doc/*.[13n]"
................................................................................
	    fi; \
	    done

install-libraries: libraries
	@for i in $(INSTALL_ROOT)$(prefix)/lib \
		$(INCLUDE_INSTALL_DIR) $(INCLUDE_INSTALL_DIR)/X11 \
		$(SCRIPT_INSTALL_DIR) $(SCRIPT_INSTALL_DIR)/images \
		$(SCRIPT_INSTALL_DIR)/msgs $(SCRIPT_INSTALL_DIR)/ttk \
		$(SCRIPT_INSTALL_DIR)/rbc; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		$(MKDIR) $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
................................................................................
	    done;
	@echo "Installing library ttk directory";
	@for i in $(ROOT_DIR)/library/ttk/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i $(SCRIPT_INSTALL_DIR)/ttk; \
	    fi; \
	    done;
	@echo "Installing library rbc directory";
	@for i in $(ROOT_DIR)/library/rbc/*.tcl; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i $(SCRIPT_INSTALL_DIR)/rbc; \
	    fi; \
	    done;
	@echo "Installing library images directory";
	@for i in $(ROOT_DIR)/library/images/*; \
	    do \
	    if [ -f $$i ] ; then \
		$(INSTALL_DATA) $$i $(SCRIPT_INSTALL_DIR)/images; \
	    fi; \