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 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 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 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 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
|
/* Copyright(c) 1993 Association of Universities for Research in Astronomy Inc.
*/
#include <ObmP.h>
#include "widget.h"
/*
* HTML widget class (a subclass of Widget).
* -------------------------------------------------------------------------
* The HTML (hypertext markup language) widget displays a block of HTML
* formatted text, the "document" to be displayed. The text consists of a
* mixture of text to be displayed and embedded formatting directives. The
* text may also contain "hot links" pointing to other HTML-formatted
* documents.
*
* setText text [target [header_text [footer_text]]]
* text = getText [format [font]]
* retestAnchors
*
* id = positionToId x y
* idToPosition id x y
* anchorToPosition name x y
* id = anchorToId name
* gotoId id
*
* n = getHRefs list
* n = getImageSrcs list
* n = getLinks list
*
* setSelection start end
* text = getSelection start end
* clearSelection
*
* searchText pattern start end [direction [search_type]]
*
* addCallback procedure-name [callback-type]
* deleteCallback procedure-name [callback-type]
*
* The possible callback types and their callback arguments are as follows.
*
* anchor widget cbtype event text href element_id
* testAnchor widget cbtype href
* submitForm widget cbtype event attrs href method enctype encentity
* link widget cbtype href role
* pointerMotion widget cbtype href
*
* See the comments below for further details on the callback types and their
* arguments.
*
* All a "hot link" is to the HTML widget is a document object containing a
* HREF which causes a callback when selected by the user viewing the document.
* It is up to the application using the HTML widget to define what the meaning
* of an HREF is.
*
* This version of the HTML widget binding does not yet support inline images.
*/
#define CB_Anchor 1
#define CB_TestAnchor 2
#define CB_PointerMotion 3
#define CB_SubmitForm 4
#define CB_Link 5
/* HTML class instance descriptor. */
struct htmlPrivate {
ObmCallback callback_list;
};
typedef struct htmlPrivate *HTMLPrivate;
struct htmlObject {
struct obmObjectCore core;
struct widgetPrivate widget;
struct htmlPrivate html;
};
typedef struct htmlObject *HTMLObject;
/* HTML class class record private data. */
typedef struct {
/* standard MsgContext fields. */
Tcl_Interp *tcl; /* class interpreter */
ObmObject object[MAX_LEVELS]; /* object which received last message */
int level;
/* HTML specific fields. */
/* (none) */
} htmlClassData, *HTMLClassData;
void HTMLDestroy();
void HTMLClassDestroy();
ObmObject HTMLCreate();
static int htmlSetText(), htmlGetText(), htmlGetHRefs();
static int htmlGetImageSrcs(), htmlGetLinks();
static int htmlRetestAnchors(), htmlPositionToId(), htmlIdToPosition();
static int htmlAnchorToPosition(), htmlAnchorToId();
static int htmlGotoId(), htmlAddCallback(), htmlDeleteCallback();
static int htmlSetSelection(), htmlGetSelection(), htmlClearSelection();
static int htmlSearchText();
static void anchorCallback(), pointerMotionCallback();
static void submitFormCallback(), linkCallback();
static char *cb_encode(), *makeList();
static int testAnchorCallback();
static void cb_error();
static int cb_decode();
extern long strtol();
/* HTMLClassInit -- Initialize the class record for the HTML widget class.
*/
void
HTMLClassInit (obm, classrec)
ObmContext obm;
register ObjClassRec classrec;
{
register HTMLClassData gcd;
register Tcl_Interp *tcl;
register ClientData c_gcd;
/* Install the class methods. */
classrec->ClassDestroy = HTMLClassDestroy;
classrec->Create = (ObmFunc) HTMLCreate;
classrec->Destroy = HTMLDestroy;
classrec->Evaluate = WidgetEvaluate;
/* The HTML widget subclass has its own command set hence has its
* own interpreter. The widget will respond both to all the commands
* defined here, and to all the commands implemented by the base
* Widget class.
*/
if (!classrec->class_data) {
gcd = (HTMLClassData) XtCalloc (1, sizeof (htmlClassData));
gcd->tcl = tcl = Tcl_CreateInterp();
classrec->class_data = (XtPointer) gcd;
c_gcd = (ClientData)gcd;
gcd->level = 0;
Tcl_CreateCommand (tcl,
"addCallback", htmlAddCallback, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"deleteCallback", htmlDeleteCallback, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"setText", htmlSetText, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"getText", htmlGetText, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"positionToId", htmlPositionToId, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"idToPosition", htmlIdToPosition, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"anchorToPosition", htmlAnchorToPosition, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"anchorToId", htmlAnchorToId, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"gotoId", htmlGotoId, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"getHRefs", htmlGetHRefs, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"getImageSrcs", htmlGetImageSrcs, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"getLinks", htmlGetLinks, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"retestAnchors", htmlRetestAnchors, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"setSelection", htmlSetSelection, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"getSelection", htmlGetSelection, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"clearSelection", htmlClearSelection, c_gcd, NULL);
Tcl_CreateCommand (tcl,
"searchText", htmlSearchText, c_gcd, NULL);
}
}
/* HTMLClassDestroy -- Custom destroy procedure for the HTML class.
*/
void
HTMLClassDestroy (obm, classrec)
ObmContext obm;
register ObjClassRec classrec;
{
register HTMLClassData gcd = (HTMLClassData) classrec->class_data;
if (gcd) {
if (gcd->tcl)
Tcl_DeleteInterp (gcd->tcl);
XtFree ((char *)gcd);
classrec->class_data = NULL;
}
}
/* HTMLCreate -- Create an instance of a HTML object.
*/
ObmObject
HTMLCreate (obm, name, classrec, parent, a_args, a_nargs)
ObmContext obm;
char *name;
ObjClassRec classrec;
char *parent;
ArgList a_args;
int a_nargs;
{
register HTMLObject obj;
register Widget w;
Arg args[128];
int nargs = 0;
for (nargs = 0; nargs < a_nargs; nargs++)
args[nargs] = a_args[nargs];
XtSetArg (args[nargs], WbNpreviouslyVisitedTestFunction,
(long)testAnchorCallback); nargs++;
XtSetArg (args[nargs], WbNpointerMotionCallback,
(long)pointerMotionCallback); nargs++;
obj = (HTMLObject) WidgetCreate (obm, name,classrec,parent,args,nargs);
if (obj == NULL)
return (NULL);
obj = (HTMLObject) XtRealloc ((char *)obj, sizeof(struct htmlObject));
if (obj == NULL)
return (NULL);
w = obj->widget.w;
/* register_image_resolution_function (w); */
XtAddCallback (w, WbNanchorCallback, anchorCallback, (XtPointer)obj);
XtAddCallback (w, WbNlinkCallback, linkCallback, (XtPointer)obj);
XtAddCallback (w, WbNsubmitFormCallback, submitFormCallback,
(XtPointer)obj);
XtSetArg (args[0], WbNpreviouslyVisitedTestData, obj);
XtSetArg (args[1], WbNpointerMotionData, obj);
XtSetValues (w, args, 2);
/* Initialize HTMLPrivate instance structure. */
obj->html.callback_list = NULL;
return ((ObmObject) obj);
}
/* HTMLDestroy -- Destroy an instance of a HTML object.
*/
void
HTMLDestroy (object)
ObmObject object;
{
HTMLObject obj = (HTMLObject) object;
ObjClassRec classrec = obj->core.classrec;
register HTMLClassData gcd = (HTMLClassData) classrec->class_data;
register ObmCallback cb, cb_next;
ObmContext obm = obj->widget.obm;
Widget w = obj->widget.w;
/* Destroy the object in the second final call to Destroy. */
if (!obj->core.being_destroyed++)
return;
/* Free any HTML callback descriptors. */
for (cb = obj->html.callback_list; cb; cb = cb_next) {
cb_next = cb->next;
XtFree ((char *)cb);
}
WidgetDestroy (object);
}
/*
* HTML class functions.
* -----------------------
*/
/* setText -- Set the text to be displayed in the HTML widget.
*
* Usage: setText text [target [header_text [footer_text]]]
*
* If a target anchor is given the text will be positioned to view the
* given anchor. The target anchor may be specified either by name or by
* its element_id (tag number within the document, e.g. as returned in the
* anchor callback). If any HTML-formatted header or footer text is given
* this will be displayed before or after the document passed in as "text".
*/
static int
htmlSetText (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
ObmContext obm = wp->obm;
char *text, *target_anchor;
char *header_text, *footer_text;
int element_id;
text = (argc > 1) ? argv[1] : NULL;
target_anchor = (argc > 2) ? argv[2] : NULL;
header_text = (argc > 3) ? argv[3] : NULL;
footer_text = (argc > 4) ? argv[4] : NULL;
element_id = target_anchor ? atoi (target_anchor) : 0;
HTMLSetText (wp->w, text,
header_text, footer_text, element_id, target_anchor, NULL);
return (TCL_OK);
}
/* getText -- Get the text of the document currently being displayed.
*
* Usage: text = getText [format [font]]
*
* The optional format argument determines the type of text to be returned.
* The possible values are as follows.
*
* simple No formatting other than indents.
* pretty Simple formatting.
* postscript Return formatted Postscript.
*
* The default output format is simple. If Postscript output is selected
* the font can be selected from one of the following:
*
* times Times
* helvetica Helvetica
* schoolbook New century schoolbook
* lucida Lucida Bright
*
* The default Postscript font is Times.
*/
static int
htmlGetText (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
char *text, *format, *font;
int pretty = 0;
format = (argc > 1) ? argv[1] : "simple";
font = (argc > 2) ? argv[2] : "times";
if (strcmp (format, "simple") == 0)
pretty = 0;
else if (strcmp (format, "pretty") == 0)
pretty = 1;
else if (strcmp (format, "postscript") == 0) {
if (strcmp (font, "times") == 0)
pretty = 2;
else if (strcmp (font, "helvetica") == 0)
pretty = 3;
else if (strcmp (font, "schoolbook") == 0)
pretty = 4;
else if (strcmp (font, "lucida") == 0)
pretty = 5;
else
pretty = 2;
}
if (text = HTMLGetText (wp->w, pretty)) {
Tcl_SetResult (wp->obm->tcl, text, TCL_VOLATILE);
free (text);
}
return (TCL_OK);
}
/* positionToId -- Return the element id of the HTML element nearest to the
* given position x,y.
*
* Usage: id = positionToId x y
*
* If there is no element at the given position the first element in the
* current line is returned. If we are not positioned to a line, either the
* beginning or the end of the document is returned.
*/
static int
htmlPositionToId (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
int element_id, x, y;
char buf[SZ_NUMBER];
if (argc < 3)
return (TCL_ERROR);
x = atoi (argv[1]);
y = atoi (argv[2]);
element_id = HTMLPositionToId (wp->w, x, y);
sprintf (buf, "%d", element_id);
Tcl_SetResult (wp->obm->tcl, buf, TCL_VOLATILE);
return (TCL_OK);
}
/* idToPosition -- Return the position of an HTML element given its
* element id.
*
* Usage: idToPosition id x y
*
* If there is no element with the given element id false is returned and
* the coordinates x,y are undefined.
*/
static int
htmlIdToPosition (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
int status, element_id, x, y;
char buf[SZ_NUMBER];
char *s_x, *s_y;
if (argc < 2)
return (TCL_ERROR);
element_id = atoi (argv[1]);
s_x = (argc > 2) ? argv[2] : NULL;
s_y = (argc > 3) ? argv[3] : NULL;
status = HTMLIdToPosition (wp->w, element_id, &x, &y);
if (status < 0)
Tcl_SetResult (obm->tcl, FALSESTR, TCL_STATIC);
else {
if (s_x) {
sprintf (buf, "%d", x);
if ((Tcl_SetVar (obm->tcl, s_x, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
}
if (s_y) {
sprintf (buf, "%d", y);
if ((Tcl_SetVar (obm->tcl, s_y, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
}
Tcl_SetResult (obm->tcl, TRUESTR, TCL_STATIC);
}
return (TCL_OK);
}
/* anchorToPosition -- Return the position of the named anchor.
*
* Usage: bool = anchorToPosition anchor [x y]
*
* If there is no anchor with the given name false is returned and the
* coordinates x,y are undefined.
*/
static int
htmlAnchorToPosition (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
char *anchor, *s_x, *s_y;
char buf[SZ_NUMBER];
int status, x, y;
if (argc < 2)
return (TCL_ERROR);
anchor = argv[1];
s_x = (argc > 2) ? argv[2] : NULL;
s_y = (argc > 3) ? argv[3] : NULL;
status = HTMLAnchorToPosition (wp->w, anchor, &x, &y);
if (status < 0)
Tcl_SetResult (obm->tcl, FALSESTR, TCL_STATIC);
else {
if (s_x) {
sprintf (buf, "%d", x);
if ((Tcl_SetVar (obm->tcl, s_x, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
}
if (s_y) {
sprintf (buf, "%d", y);
if ((Tcl_SetVar (obm->tcl, s_y, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
}
Tcl_SetResult (obm->tcl, TRUESTR, TCL_STATIC);
}
return (TCL_OK);
}
/* anchorToId -- Return the element id of the named anchor.
*
* Usage: id = anchorToId anchor
*
* If there is no anchor with the given name false is returned.
*/
static int
htmlAnchorToId (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
char buf[SZ_NUMBER];
int element_id;
char *anchor;
if (argc < 2)
return (TCL_ERROR);
anchor = argv[1];
element_id = HTMLAnchorToId (wp->w, anchor);
sprintf (buf, "%d", element_id);
Tcl_SetResult (wp->obm->tcl, buf, TCL_VOLATILE);
return (TCL_OK);
}
/* gotoId -- Position to the given element given its element id.
*
* Usage: gotoId element_id
*
* An id of zero means go to the top of the document.
*/
static int
htmlGotoId (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
int element_id;
if (argc < 2)
return (TCL_ERROR);
element_id = atoi (argv[1]);
HTMLGotoId (wp->w, element_id);
return (TCL_OK);
}
/* getHRefs -- Get a list of the HREFs of all the active anchors in the
* document being displayed.
*
* Usage: n = getHRefs list
*
* The number of HREFs is returned as the function value; zero is returned
* if there are no HREFs, in which case "list" is undefined. If the document
* has HREFs on output list will contain a list of HREFs in the form { {HREF1}
* {HREF2} ... {HREFn} }.
*
* An HREF is a hypertext reference, i.e. hot-link or hypertext link to
* some other hypertext document that can be referenced by clicking on an
* anchor in the document being displayed.
*/
static int
htmlGetHRefs (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
char *a_list, *lbuf, **list;
char buf[SZ_NUMBER];
int n;
if (argc < 2)
return (TCL_ERROR);
else
a_list = argv[1];
if (list = HTMLGetHRefs (wp->w, &n)) {
if (!(lbuf = makeList (list, n))) {
free ((char *)list);
return (TCL_ERROR);
}
if ((Tcl_SetVar (obm->tcl, a_list, lbuf, 0)) == NULL) { /* MF024 */
free ((char *)list);
XtFree (lbuf);
return (TCL_ERROR);
}
free ((char *)list);
XtFree (lbuf);
} else
n = 0;
sprintf (buf, "%d", n);
Tcl_SetResult (wp->obm->tcl, buf, TCL_VOLATILE);
return (TCL_OK);
}
/* getImageSrcs -- Get a list of the image sources (SRC=) for all the
* inline images referenced by the document being displayed.
*
* Usage: n = getImageSrcs list
*
* The number of SRCs is returned as the function value; zero is returned
* if there are no SRCs, in which case "list" is undefined. If the document
* has SRCs on output the list will contain a list of SRCs in the form
* { {SRC1} {SRC2} ... {SRCn} }.
*
* A SRC is a HREF pointing to an image file.
*/
static int
htmlGetImageSrcs (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
char *a_list, *lbuf, **list;
char buf[SZ_NUMBER];
int n;
if (argc < 2)
return (TCL_ERROR);
else
a_list = argv[1];
if (list = HTMLGetImageSrcs (wp->w, &n)) {
if (!(lbuf = makeList (list, n))) {
free ((char *)list);
return (TCL_ERROR);
}
if ((Tcl_SetVar (obm->tcl, a_list, lbuf, 0)) == NULL) { /* MF024 */
free ((char *)list);
XtFree (lbuf);
return (TCL_ERROR);
}
free ((char *)list);
XtFree (lbuf);
} else
n = 0;
sprintf (buf, "%d", n);
Tcl_SetResult (wp->obm->tcl, buf, TCL_VOLATILE);
return (TCL_OK);
}
/* getLinks -- Get a list of the link tags (<LINK>) referenced by the
* document being displayed.
*
* Usage: n = getLinks list
*
* The number of links is returned as the function value; zero is returned
* if there are no links, in which case "list" is undefined. If there are
* any links the returned list will have the format { {{href} {role}} ...}
* where the structure {{href} {role}} describes each link.
*/
static int
htmlGetLinks (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
char *a_list, *lbuf;
char buf[SZ_NUMBER];
LinkInfo *list;
int nchars, n;
if (argc < 2)
return (TCL_ERROR);
else
a_list = argv[1];
if (list = HTMLGetLinks (wp->w, &n)) {
register char *ip, *op;
register int i;
/* Determine how much storage we need for the list. */
for (i=0, nchars=0; i < n; i++) {
nchars += strlen (list[i].href) + 4;
nchars += strlen (list[i].role) + 4;
}
nchars += 5;
/* Get the storage. */
if (!(lbuf = op = XtMalloc (nchars))) {
free ((char *)list);
return (TCL_ERROR);
}
/* Encode the list as a Tcl list of lists. */
*op++ = '{'; *op++ = ' ';
for (i=0; i < n; i++) {
*op++ = '{';
*op++ = '{';
for (ip=list[i].href; ip && *ip; )
*op++ = *ip++;
*op++ = '}'; *op++ = ' ';
*op++ = '{';
for (ip=list[i].role; ip && *ip; )
*op++ = *ip++;
*op++ = '}';
*op++ = '}'; *op++ = ' ';
}
*op++ = '}';
*op++ = '\0';
if ((Tcl_SetVar (obm->tcl, a_list, lbuf, 0)) == NULL) { /* MF024 */
free ((char *)list);
XtFree (lbuf);
return (TCL_ERROR);
}
free ((char *)list);
XtFree (lbuf);
} else
n = 0;
sprintf (buf, "%d", n);
Tcl_SetResult (wp->obm->tcl, buf, TCL_VOLATILE);
return (TCL_OK);
}
/* makeList -- Take a list of NULL terminated strings and turn it into a
* Tcl list of strings.
*/
static char *
makeList (list, n)
char **list;
int n;
{
register char *ip, *op;
register int i;
int nchars;
char *buf;
/* Determine how much storage we need for the list. */
for (i=0, nchars=0; i < n; i++)
nchars += strlen (list[i]) + 4;
nchars += 5;
/* Get the storage. */
if (!(buf = op = XtMalloc (nchars))) {
free ((char *)list);
return (NULL);
}
/* Encode the list as a Tcl list of strings. */
*op++ = '{'; *op++ = ' ';
for (i=0; i < n; i++) {
*op++ = '{';
for (ip=list[i]; ip && *ip; )
*op++ = *ip++;
*op++ = '}'; *op++ = ' ';
}
*op++ = '}';
*op++ = '\0';
return (buf);
}
/* retestAnchors -- Test each anchor and update the display to indicate
* the current status of the anchor.
*
* Usage: retestAnchors
*
* retestAnchors should be called after loading new text into a widget,
* or when the status of one or more anchors has changed, e.g. after a
* given URL has been visited.
*/
static int
htmlRetestAnchors (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
HTMLRetestAnchors (wp->w, NULL, 0);
return (TCL_OK);
}
/* setSelection -- Set the current text selection to the text bracketed by
* the input start and end element refs.
*
* Usage: setSelection start end
*
* "start" and "end" are elements refs such as returned by searchText.
* An element ref is a structure of the form {element_id offset} specifying
* the element id within the document, and the character offset within
* that element.
*/
static int
htmlSetSelection (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
ElementRef start, end;
char *ip = (char *)NULL;
if (argc < 3)
return (TCL_ERROR);
ip = (char *)NULL;
start.id = strtol (&argv[1][1], &ip, 0);
start.pos = strtol (ip, &ip, 0);
if (ip == argv[1])
return (TCL_ERROR);
ip = (char *)NULL;
end.id = strtol (&argv[2][1], &ip, 0);
end.pos = strtol (ip, &ip, 0);
if (ip == argv[2])
return (TCL_ERROR);
HTMLSetSelection (wp->w, &start, &end);
return (TCL_OK);
}
/* getSelection -- Get the selected text, if any.
*
* Usage: text = getSelection
*
* An empty string is returned if there is no current text selection.
*/
static int
htmlGetSelection (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
char *text, *start, *end, *insert;
text = HTMLGetTextAndSelection (wp->w, &start, &end, &insert);
if (text && start) {
int nchars = end - start + 1;
start[nchars] = '\0';
Tcl_SetResult (wp->obm->tcl, start, TCL_VOLATILE);
}
if (text)
free (text);
return (TCL_OK);
}
/* clearSelection -- Clear the current selection, if any.
*
* Usage: clearSelection
*/
static int
htmlClearSelection (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
HTMLClearSelection (wp->w);
return (TCL_OK);
}
/* searchText -- Search the document for the given pattern.
*
* Usage: bool = searchText pattern start end [direction [search_type]]
*
* direction "forward" or "backward"
* search_type "caseSensitive" or "caseless"
*
* If the search is successful start and end are set to the element refs
* of the matched region and the function returns a true (nonzero) value.
* False is returned if the search fails. An element ref is a structure of
* the form {element_id offset} specifying the element id within the document,
* and the character offset within that element. The search will automatically
* wrap around the page if not found initially.
*
*/
static int
htmlSearchText (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
register HTMLClassData gcd = (HTMLClassData) msg;
HTMLObject obj = (HTMLObject) gcd->object[gcd->level];
register WidgetPrivate wp = &obj->widget;
ObmContext obm = obj->widget.obm;
char *pattern, *a_start, *a_end;
int backward = 0, caseless = 1;
static ElementRef start, end;
static char patstr[64];
int status, again = 1;
if (argc < 4)
return (TCL_ERROR);
pattern = argv[1];
a_start = argv[2];
a_end = argv[3];
backward = 0;
if (argc > 4)
backward = (strcmp (argv[4], "backward") == 0);
caseless = 0;
if (argc > 5)
caseless = (strcmp (argv[5], "caseless") == 0);
/* See whether the pattern has changed and we need to reset the
* start and end element refs.
*/
if (strcmp (pattern, patstr) != 0) {
retry: start.id = start.pos = 0;
end.id = end.pos = 0;
strcpy (patstr, "");
again = 0;
}
/* Do the search. */
status = HTMLSearchText (wp->w, pattern,
&start, &end, backward, caseless);
if (status == 1) {
char buf[SZ_LINE];
sprintf (buf, "{%d %d}", start.id, start.pos);
if ((Tcl_SetVar (obm->tcl, a_start, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
sprintf (buf, "{%d %d}", end.id, end.pos);
if ((Tcl_SetVar (obm->tcl, a_end, buf, 0)) == NULL) /* MF024 */
return (TCL_ERROR);
Tcl_SetResult (wp->obm->tcl, TRUESTR, TCL_STATIC);
} else {
if (again == 1)
goto retry;
Tcl_SetResult (wp->obm->tcl, FALSESTR, TCL_STATIC);
}
/* Save the pattern string so we can reset later if it changes. */
strcpy (patstr, pattern);
return (TCL_OK);
}
/* AddCallback -- Post a callback for a HTML widget event.
*
* Usage: addCallback procedure-name [callback-type]
*
* The recognized HTML callbacks are
*
* anchor Called to load a new URL.
*
* testAnchor Called to test whether a given URL has
* been previously visited.
*
* pointerMotion Called when the pointer enters an object
* which has a URL.
*
* submitForm Called when a form is submitted from within
* the document being viewed.
*
* link Called when a <LINK> tag is encountered
* while loading text.
*
* The default callback type is "anchor", which is called when the user
* selects a new URL while viewing a document.
*/
static int
htmlAddCallback (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
HTMLObject obj = (HTMLObject) msg->object[msg->level];
register WidgetPrivate wp = &obj->widget;
register HTMLPrivate hp = &obj->html;
register Widget w = wp->w;
char *userproc, *callback_type;
ObmCallback cb, new;
int type;
if (argc < 2)
return (TCL_ERROR);
userproc = argv[1];
callback_type = (argc > 2) ? argv[2] : "anchor";
if (!(type = cb_decode (callback_type)))
return (TCL_ERROR);
/* Initialize callback descriptor. */
new = (ObmCallback) XtCalloc (1, sizeof (obmCallback));
new->u.obj = (ObmObject) obj;
new->callback_type = type;
strncpy (new->name, userproc, SZ_NAME);
/* Append descriptor to callback list for widget. */
for (cb = hp->callback_list; cb && cb->next; cb = cb->next)
;
if (cb)
cb->next = new;
else
hp->callback_list = new;
return (TCL_OK);
}
/* DeleteCallback -- Delete a HTML callback.
*
* Usage: deleteCallback procedure [callback_type]
*
* If a callback type is specified all entries of type callback_type for
* the named procedure are deleted, else all entries of any type for the
* named procedure are deleted.
*/
static int
htmlDeleteCallback (msg, tcl, argc, argv)
MsgContext msg;
Tcl_Interp *tcl;
int argc;
char **argv;
{
HTMLObject obj = (HTMLObject) msg->object[msg->level];
register HTMLPrivate hp = &obj->html;
register ObmCallback cb, prev, next;
char *procedure, *callback_type;
int type;
if (argc < 2)
return (TCL_ERROR);
procedure = argv[1];
callback_type = (argc > 2) ? argv[2] : NULL;
type = callback_type ? cb_decode(callback_type) : 0;
/* Locate and delete procedure entry in callback list. */
for (prev=NULL, cb=hp->callback_list; cb; prev=cb, cb=next) {
next = cb->next;
if (strcmp (cb->name, procedure) == 0 &&
(!type || cb->callback_type == type)) {
if (prev)
prev->next = next;
else
hp->callback_list = next;
XtFree ((char *)cb);
}
}
return (TCL_OK);
}
/* anchorCallback -- Callback procedure called by the HTML widget when an
* anchor (URL) is selected.
*
* Calling sequence:
*
* userproc widget cbtype event text href element_id
*
* All callbacks registered with the current widget for the anchor callback
* are called in the order in which they were registered.
*/
static void
anchorCallback (w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
register char *ip, *op;
register ObmCallback cb;
register WbAnchorCallbackData *ap = (WbAnchorCallbackData *)call_data;
HTMLObject obj = (HTMLObject) client_data;
ObmContext obm = obj->widget.obm;
char *text, *href, *none = "none";
char event_type[SZ_LINE];
char element_id[SZ_NUMBER];
int status;
text = ap->text ? ap->text : none;
href = ap->href ? ap->href : none;
sprintf (element_id, "%d", ap->element_id);
op = event_type;
/* Compose the event type information. This is the name of the
* key typed, or "Button1", "Button2", etc. for the mouse buttons.
*/
switch (ap->event->type) {
case KeyPress:
case KeyRelease:
{ XKeyPressedEvent *ev = (XKeyPressedEvent *) ap->event;
char buf[20];
int n;
if ((n = XLookupString(ev,buf,sizeof(buf),NULL,NULL)) > 0) {
for (ip=buf; --n >= 0; )
if (*ip <= ' ') {
*op++ = '^';
*op++ = *ip++ + 'A' - 1;
} else if (isprint (*ip)) {
*op++ = *ip++;
} else
ip++;
} else {
/* This case occurs when only a modifier is typed. */
for (ip = "??"; *op++ = *ip++; )
;
}
*op = '\0';
}
break;
case ButtonPress:
case ButtonRelease:
{ XButtonPressedEvent *ev = (XButtonPressedEvent *) ap->event;
sprintf (op, "Button%d", ev->button);
}
break;
default:
strcpy (event_type, "unknown");
}
/* Call any registered callback functions. */
for (cb = obj->html.callback_list; cb; cb = cb->next) {
if (cb->callback_type != CB_Anchor)
continue;
status = Tcl_VarEval (obm->tcl,
cb->name, " ",
obj->core.name, " ",
cb_encode(cb->callback_type), " ",
event_type, " ",
"{", text, "} ",
"{", href, "} ",
element_id,
NULL);
if (status != TCL_OK)
cb_error (obm, cb);
}
}
/* testAnchorCallback -- Callback procedure called by the HTML widget to
* test whether a given anchor (URL) has been previously visited.
*
* Calling sequence:
*
* userproc widget cbtype href
*
* A nonzero value should be returned by the userproc if the given anchor
* has been visited previously, otherwise a zero should be returned.
*/
static int
testAnchorCallback (w, client_data, href)
Widget w;
XtPointer client_data;
char *href;
{
register ObmCallback cb;
register HTMLObject obj = (HTMLObject) client_data;
register ObmContext obm = obj->widget.obm;
int status, retval = 0;
/* Call any registered callback functions. */
for (cb = obj->html.callback_list; cb; cb = cb->next) {
if (cb->callback_type != CB_TestAnchor)
continue;
status = Tcl_VarEval (obm->tcl,
cb->name, " ",
obj->core.name, " ",
cb_encode(cb->callback_type), " ",
"{", href, "} ",
NULL);
if (status != TCL_OK)
cb_error (obm, cb);
else if (atoi (obm->tcl->result))
retval = 1;
}
return (retval);
}
/* submitFormCallback -- Callback procedure called by the HTML widget when
* a form is submitted from the document.
*
* Calling sequence:
*
* userproc widget cbtype event attrs href method enctype encentity
*
* "widget" is the name of the HTML widget which generated the callback.
* "cbtype" is the type of callback, i.e., "submitForm". "event" is the
* key/button event which triggered the callback, e.g. "Button1".
*
* "attrs" is a list of attribute-value pairs defining the contents of the
* form. That is, a list of the form { {attr1 value1} {attr2 value2} ... }.
*
* The final block of arguments deal with how to process or deliver the form.
* "href", "method", "enctype", and "encentity" are strings defined by the
* HTML form. The application is free to use these as it wishes, except for
* an HTML form query where the meaning of these fields is well defined.
* The "href" field is normally the URL to which the form is to be submitted,
* while "method" is the method to be used to submit the form.
*/
static void
submitFormCallback (w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
register char *ip, *op;
register ObmCallback cb;
register WbFormCallbackData *fp = (WbFormCallbackData *)call_data;
HTMLObject obj = (HTMLObject) client_data;
ObmContext obm = obj->widget.obm;
char *href, *method, *enctype, *encentity;
char *abuf, event_type[SZ_LINE];
char *none = "none";
int status, i, n;
href = fp->href ? fp->href : none;
method = fp->method ? fp->method : none;
enctype = fp->enctype ? fp->enctype : none;
encentity = fp->enc_entity ? fp->enc_entity : none;
op = event_type;
/* Compose the event type information. This is the name of the
* key typed, or "Button1", "Button2", etc. for the mouse buttons.
*/
switch (fp->event->type) {
case KeyPress:
case KeyRelease:
{ XKeyPressedEvent *ev = (XKeyPressedEvent *) fp->event;
char buf[20];
int n;
if ((n = XLookupString(ev,buf,sizeof(buf),NULL,NULL)) > 0) {
for (ip=buf; --n >= 0; )
if (*ip <= ' ') {
*op++ = '^';
*op++ = *ip++ + 'A' - 1;
} else if (isprint (*ip)) {
*op++ = *ip++;
} else
ip++;
} else {
/* This case occurs when only a modifier is typed. */
for (ip = "??"; *op++ = *ip++; )
;
}
*op = '\0';
}
break;
case ButtonPress:
case ButtonRelease:
{ XButtonPressedEvent *ev = (XButtonPressedEvent *) fp->event;
sprintf (op, "Button%d", ev->button);
}
break;
default:
strcpy (event_type, "unknown");
}
/* Get storage for the attribute list. */
for (i=0, n=0; i < fp->attribute_count; i++) {
n += strlen (fp->attribute_names[i]);
n += strlen (fp->attribute_values[i]);
n += 10;
}
if (!(abuf = XtMalloc (n)))
return;
/* Construct the attribute list.
*/
for (i=0, op=abuf; i < fp->attribute_count; i++) {
*op++ = '{';
*op++ = '{';
for (ip = fp->attribute_names[i]; ip && *ip; )
*op++ = *ip++;
*op++ = '}'; *op++ = ' ';
*op++ = '{';
for (ip = fp->attribute_values[i]; ip && *ip; )
*op++ = *ip++;
*op++ = '}';
*op++ = '}'; *op++ = ' ';
}
*op = '\0';
/* Call any registered callback functions. */
for (cb = obj->html.callback_list; cb; cb = cb->next) {
if (cb->callback_type != CB_SubmitForm)
continue;
status = Tcl_VarEval (obm->tcl,
cb->name, " ",
obj->core.name, " ",
cb_encode(cb->callback_type), " ",
event_type, " ",
"{ ", abuf, "} ",
href, " ",
method, " ",
enctype, " ",
encentity, " ",
NULL);
if (status != TCL_OK)
cb_error (obm, cb);
}
XtFree (abuf);
}
/* linkCallback -- Callback procedure called by the HTML widget when
* a <LINK> directive is encountered while loading text into the widget.
*
* Calling sequence:
*
* userproc widget cbtype href role
*
* All callbacks registered with the current widget for the callback
* are called in the order in which they were registered.
*/
static void
linkCallback (w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
register char *ip, *op;
register ObmCallback cb;
LinkInfo *l_info = (LinkInfo *) call_data;
HTMLObject obj = (HTMLObject) client_data;
ObmContext obm = obj->widget.obm;
char *href, *role, *none = "none";
int status;
href = l_info->href ? l_info->href : none;
role = l_info->role ? l_info->role : none;
/* Call any registered callback functions. */
for (cb = obj->html.callback_list; cb; cb = cb->next) {
if (cb->callback_type != CB_Link)
continue;
status = Tcl_VarEval (obm->tcl,
cb->name, " ",
obj->core.name, " ",
cb_encode(cb->callback_type), " ",
href, " ",
role, " ",
NULL);
if (status != TCL_OK)
cb_error (obm, cb);
}
}
/* pointerMotionCallback -- Callback procedure called by the HTML widget when
* the pointer enters an anchor.
*
* Calling sequence:
*
* userproc widget cbtype href
*/
static void
pointerMotionCallback (w, client_data, href)
Widget w;
XtPointer client_data;
char *href;
{
register ObmCallback cb;
register HTMLObject obj = (HTMLObject) client_data;
register ObmContext obm = obj->widget.obm;
int status;
/* Call any registered callback functions. */
for (cb = obj->html.callback_list; cb; cb = cb->next) {
if (cb->callback_type != CB_PointerMotion)
continue;
status = Tcl_VarEval (obm->tcl,
cb->name, " ",
obj->core.name, " ",
cb_encode(cb->callback_type), " ",
"{", href, "} ",
NULL);
if (status != TCL_OK)
cb_error (obm, cb);
}
}
/* cb_error -- Convenience routine to return an error from a callback.
*/
static void
cb_error (obm, cb)
register ObmContext obm;
register ObmCallback cb;
{
register Tcl_Interp *tcl = obm->tcl;
char *errstr = Tcl_GetVar (tcl, "errorInfo", 0);
fprintf (stderr, "Error on line %d in %s: %s\n",
tcl->errorLine, cb->name,
errstr ? errstr : tcl->result);
}
/* cb_decode -- Convert a callback_type string to a callback type code.
*/
static int
cb_decode (callback_type)
register char *callback_type;
{
register int type = 0;
if (strcmp (callback_type, "anchor") == 0)
type = CB_Anchor;
else if (strcmp (callback_type, "testAnchor") == 0)
type = CB_TestAnchor;
else if (strcmp (callback_type, "pointerMotion") == 0)
type = CB_PointerMotion;
else if (strcmp (callback_type, "submitForm") == 0)
type = CB_SubmitForm;
else if (strcmp (callback_type, "link") == 0)
type = CB_Link;
return (type);
}
/* cb_encode -- Convert a callback_type string to a callback type code.
*/
static char *
cb_encode (callback_type)
int callback_type;
{
register char *type = "unknown";
switch (callback_type) {
case CB_Anchor:
type = "anchor";
break;
case CB_TestAnchor:
type = "testAnchor";
break;
case CB_PointerMotion:
type = "pointerMotion";
break;
case CB_SubmitForm:
type = "submitForm";
break;
case CB_Link:
type = "link";
break;
}
return (type);
}
|