summaryrefslogtreecommitdiffstats
path: root/addon/doxmlparser/src/dochandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'addon/doxmlparser/src/dochandler.cpp')
-rw-r--r--addon/doxmlparser/src/dochandler.cpp148
1 files changed, 91 insertions, 57 deletions
diff --git a/addon/doxmlparser/src/dochandler.cpp b/addon/doxmlparser/src/dochandler.cpp
index b670de2..344e457 100644
--- a/addon/doxmlparser/src/dochandler.cpp
+++ b/addon/doxmlparser/src/dochandler.cpp
@@ -3,7 +3,7 @@
* $Id$
*
*
- * Copyright (C) 1997-2001 by Dimitri van Heesch.
+ * Copyright (C) 1997-2002 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
@@ -14,6 +14,7 @@
*/
#include "dochandler.h"
+#include "debug.h"
#include <qmap.h>
class TypeNameMapper
@@ -51,8 +52,17 @@ class TypeNameMapper
QMap<QString,SimpleSectHandler::Types> m_typeNameMap;
};
-static TypeNameMapper g_typeMapper;
+static TypeNameMapper *s_typeMapper;
+void dochandler_init()
+{
+ s_typeMapper = new TypeNameMapper;
+}
+
+void dochandler_exit()
+{
+ delete s_typeMapper;
+}
//----------------------------------------------------------------------
// MarkupHandler
@@ -92,7 +102,7 @@ void MarkupHandler::addTextNode()
if (!m_curString.isEmpty())
{
m_children.append(new TextNode(m_curString,m_curMarkup));
- printf("addTextNode() text=%s markup=%x\n",m_curString.data(),m_curMarkup);
+ debug(2,"addTextNode() text=%s markup=%x\n",m_curString.data(),m_curMarkup);
m_curString="";
}
}
@@ -216,12 +226,12 @@ ListItemHandler::~ListItemHandler()
void ListItemHandler::startListItem(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start list item handler\n");
+ debug(2,"start list item handler\n");
}
void ListItemHandler::endListItem()
{
- printf("end list item handler\n");
+ debug(2,"end list item handler\n");
m_parent->setDelegate(0);
}
@@ -336,7 +346,7 @@ void ParameterHandler::startParameterName(const QXmlAttributes& /*attrib*/)
void ParameterHandler::endParameterName()
{
m_name = m_curString;
- printf("parameter %s\n",m_name.data());
+ debug(2,"parameter %s\n",m_name.data());
m_curString="";
m_parent->setDelegate(0);
}
@@ -386,9 +396,9 @@ void ParameterListHandler::startParameterList(const QXmlAttributes& attrib)
else if (kind=="param") m_type=Param;
else
{
- printf("Error: invalid parameterlist type: %s\n",kind.data());
+ debug(1,"Error: invalid parameterlist type: %s\n",kind.data());
}
- printf("parameterlist kind=%s\n",kind.data());
+ debug(2,"parameterlist kind=%s\n",kind.data());
m_parent->setDelegate(this);
}
@@ -432,7 +442,7 @@ LinkHandler::~LinkHandler()
void LinkHandler::startLink(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
- printf("Start link\n");
+ debug(2,"Start link\n");
m_ref = attrib.value("linkend");
m_curString="";
}
@@ -442,7 +452,7 @@ void LinkHandler::endLink()
m_text = m_curString;
m_curString="";
m_parent->setDelegate(0);
- printf("End link\n");
+ debug(2,"End link\n");
}
//----------------------------------------------------------------------
@@ -462,7 +472,7 @@ EMailHandler::~EMailHandler()
void EMailHandler::startEMail(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("Start email\n");
+ debug(2,"Start email\n");
m_curString="";
}
@@ -471,7 +481,7 @@ void EMailHandler::endEMail()
m_address = m_curString;
m_curString="";
m_parent->setDelegate(0);
- printf("End email\n");
+ debug(2,"End email\n");
}
//----------------------------------------------------------------------
@@ -491,7 +501,7 @@ ULinkHandler::~ULinkHandler()
void ULinkHandler::startULink(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
- printf("Start ulink\n");
+ debug(2,"Start ulink\n");
m_url = attrib.value("url");
m_curString="";
}
@@ -501,7 +511,7 @@ void ULinkHandler::endULink()
m_text = m_curString;
m_curString="";
m_parent->setDelegate(0);
- printf("End ulink\n");
+ debug(2,"End ulink\n");
}
//----------------------------------------------------------------------
@@ -521,13 +531,13 @@ LineBreakHandler::~LineBreakHandler()
void LineBreakHandler::startLineBreak(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("Start linebreak\n");
+ debug(2,"Start linebreak\n");
}
void LineBreakHandler::endLineBreak()
{
m_parent->setDelegate(0);
- printf("End linebreak\n");
+ debug(2,"End linebreak\n");
}
//----------------------------------------------------------------------
@@ -547,13 +557,13 @@ HRulerHandler::~HRulerHandler()
void HRulerHandler::startHRuler(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("Start hruler\n");
+ debug(2,"Start hruler\n");
}
void HRulerHandler::endHRuler()
{
m_parent->setDelegate(0);
- printf("End hruler\n");
+ debug(2,"End hruler\n");
}
//----------------------------------------------------------------------
@@ -573,9 +583,12 @@ RefHandler::~RefHandler()
void RefHandler::startRef(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
- m_refId = attrib.value("idref");
- m_anchor = attrib.value("anchor");
- printf("Start ref refId=%s anchor=%s\n",m_refId.data(),m_anchor.data());
+ m_refId = attrib.value("refid");
+ m_refId = attrib.value("external");
+ ASSERT(attrib.value("kindref")=="compound" ||
+ attrib.value("kindref")=="member");
+ m_targetKind = attrib.value("kindref")=="compound" ? Compound : Member;
+ debug(2,"Start ref refId=%s\n",m_refId.data());
m_curString="";
}
@@ -583,7 +596,7 @@ void RefHandler::endRef()
{
m_linkText = m_curString;
m_parent->setDelegate(0);
- printf("End ref: text=`%s'\n",m_linkText.data());
+ debug(2,"End ref: text=`%s'\n",m_linkText.data());
}
@@ -609,7 +622,7 @@ TitleHandler::~TitleHandler()
void TitleHandler::startTitle(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("Start title\n");
+ debug(2,"Start title\n");
m_curString="";
}
@@ -617,7 +630,7 @@ void TitleHandler::endTitle()
{
addTextNode();
m_parent->setDelegate(0);
- printf("End title\n");
+ debug(2,"End title\n");
}
void TitleHandler::addTextNode()
@@ -625,7 +638,7 @@ void TitleHandler::addTextNode()
if (!m_curString.isEmpty())
{
m_children.append(new TextNode(m_curString,m_markupHandler->markup()));
- printf("addTextNode() text=\"%s\" markup=%x\n",
+ debug(2,"addTextNode() text=\"%s\" markup=%x\n",
m_curString.data(),m_markupHandler->markup());
m_curString="";
}
@@ -661,14 +674,14 @@ SimpleSectHandler::~SimpleSectHandler()
void SimpleSectHandler::startSimpleSect(const QXmlAttributes& attrib)
{
- m_type = g_typeMapper.stringToType(attrib.value("kind"));
- printf("start simple section %s\n",attrib.value("kind").data());
+ m_type = s_typeMapper->stringToType(attrib.value("kind"));
+ debug(2,"start simple section %s\n",attrib.value("kind").data());
m_parent->setDelegate(this);
}
void SimpleSectHandler::endSimpleSect()
{
- printf("end simple section\n");
+ debug(2,"end simple section\n");
m_parent->setDelegate(0);
}
@@ -708,25 +721,25 @@ VariableListEntryHandler::~VariableListEntryHandler()
void VariableListEntryHandler::startVarListEntry(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start varlistentry\n");
+ debug(2,"start varlistentry\n");
}
void VariableListEntryHandler::endVarListEntry()
{
m_parent->setDelegate(0);
- printf("end varlistentry\n");
+ debug(2,"end varlistentry\n");
}
void VariableListEntryHandler::startListItem(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start listitem\n");
+ debug(2,"start listitem\n");
}
void VariableListEntryHandler::endListItem()
{
m_parent->setDelegate(0);
- printf("end listitem\n");
+ debug(2,"end listitem\n");
}
void VariableListEntryHandler::startTerm(const QXmlAttributes& /*attrib*/)
@@ -737,7 +750,7 @@ void VariableListEntryHandler::startTerm(const QXmlAttributes& /*attrib*/)
void VariableListEntryHandler::endTerm()
{
m_term = m_curString;
- printf("term=%s\n",m_term.data());
+ debug(2,"term=%s\n",m_term.data());
}
void VariableListEntryHandler::startParagraph(const QXmlAttributes& attrib)
@@ -769,12 +782,12 @@ VariableListHandler::~VariableListHandler()
void VariableListHandler::startVariableList(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start variablelist\n");
+ debug(2,"start variablelist\n");
}
void VariableListHandler::endVariableList()
{
- printf("end variablelist\n");
+ debug(2,"end variablelist\n");
m_parent->setDelegate(0);
}
@@ -799,7 +812,9 @@ void VariableListHandler::startListItem(const QXmlAttributes& attrib)
HighlightHandler::HighlightHandler(IBaseHandler *parent)
: m_parent(parent)
{
+ m_children.setAutoDelete(TRUE);
addEndHandler("highlight",this,&HighlightHandler::endHighlight);
+ addStartHandler("ref",this,&HighlightHandler::startRef);
}
HighlightHandler::~HighlightHandler()
@@ -815,11 +830,30 @@ void HighlightHandler::startHighlight(const QXmlAttributes& attrib)
void HighlightHandler::endHighlight()
{
- m_text = m_curString;
- printf("highlight class=`%s' text=`%s'\n",m_class.data(),m_text.data());
+ addTextNode();
+ debug(2,"highlight class=`%s'\n",m_class.data());
m_parent->setDelegate(0);
}
+void HighlightHandler::startRef(const QXmlAttributes& attrib)
+{
+ addTextNode();
+ RefHandler *rh = new RefHandler(this);
+ m_children.append(rh);
+ rh->startRef(attrib);
+}
+
+void HighlightHandler::addTextNode()
+{
+ if (!m_curString.isEmpty())
+ {
+ m_children.append(new TextNode(m_curString,IDocMarkup::Normal));
+ debug(2,"addTextNode() text=\"%s\"\n",
+ m_curString.data());
+ m_curString="";
+ }
+}
+
//----------------------------------------------------------------------
// CodeLineHandler
//----------------------------------------------------------------------
@@ -842,20 +876,20 @@ CodeLineHandler::~CodeLineHandler()
void CodeLineHandler::startCodeLine(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start codeline\n");
+ debug(2,"start codeline\n");
}
void CodeLineHandler::endCodeLine()
{
addTextNode();
- printf("end codeline\n");
+ debug(2,"end codeline\n");
m_parent->setDelegate(0);
}
void CodeLineHandler::startLineNumber(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
- printf("start linenumber\n");
+ debug(2,"start linenumber\n");
m_lineNumber = attrib.value("line").toInt();
m_refId = attrib.value("refid");
}
@@ -886,7 +920,7 @@ void CodeLineHandler::addTextNode()
if (!m_curString.isEmpty())
{
m_children.append(new TextNode(m_curString,IDocMarkup::Normal));
- printf("addTextNode() text=\"%s\"\n",
+ debug(2,"addTextNode() text=\"%s\"\n",
m_curString.data());
m_curString="";
}
@@ -914,12 +948,12 @@ ProgramListingHandler::~ProgramListingHandler()
void ProgramListingHandler::startProgramListing(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start programlisting\n");
+ debug(2,"start programlisting\n");
}
void ProgramListingHandler::endProgramListing()
{
- printf("end programlisting\n");
+ debug(2,"end programlisting\n");
m_parent->setDelegate(0);
}
@@ -972,7 +1006,7 @@ void FormulaHandler::startFormula(const QXmlAttributes& attrib)
void FormulaHandler::endFormula()
{
m_text = m_curString;
- printf("formula id=`%s' text=`%s'\n",m_id.data(),m_text.data());
+ debug(2,"formula id=`%s' text=`%s'\n",m_id.data(),m_text.data());
m_parent->setDelegate(0);
}
@@ -1000,7 +1034,7 @@ void ImageHandler::startImage(const QXmlAttributes& attrib)
void ImageHandler::endImage()
{
m_caption = m_curString;
- printf("image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
+ debug(2,"image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
m_parent->setDelegate(0);
}
@@ -1028,7 +1062,7 @@ void DotFileHandler::startDotFile(const QXmlAttributes& attrib)
void DotFileHandler::endDotFile()
{
m_caption = m_curString;
- printf("image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
+ debug(2,"image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
m_parent->setDelegate(0);
}
@@ -1052,13 +1086,13 @@ IndexEntryHandler::~IndexEntryHandler()
void IndexEntryHandler::startIndexEntry(const QXmlAttributes& /*attrib*/)
{
- printf("start index entry\n");
+ debug(2,"start index entry\n");
m_parent->setDelegate(this);
}
void IndexEntryHandler::endIndexEntry()
{
- printf("index entry primary=`%s' secondary=`%s'\n",
+ debug(2,"index entry primary=`%s' secondary=`%s'\n",
m_primary.data(),m_secondary.data());
m_parent->setDelegate(0);
}
@@ -1171,7 +1205,7 @@ void TableHandler::startTable(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
m_numColumns = attrib.value("cols").toInt();
- printf("table cols=%d\n",m_numColumns);
+ debug(2,"table cols=%d\n",m_numColumns);
}
void TableHandler::endTable()
@@ -1237,13 +1271,13 @@ ParagraphHandler::~ParagraphHandler()
void ParagraphHandler::startParagraph(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("para\n");
+ debug(2,"para\n");
}
void ParagraphHandler::endParagraph()
{
addTextNode();
- printf("end para\n");
+ debug(2,"end para\n");
m_parent->setDelegate(0);
}
@@ -1388,7 +1422,7 @@ void ParagraphHandler::addTextNode()
if (!m_curString.isEmpty())
{
m_children.append(new TextNode(m_curString,m_markupHandler->markup()));
- printf("addTextNode() text=\"%s\" markup=%x\n",
+ debug(2,"addTextNode() text=\"%s\" markup=%x\n",
m_curString.data(),m_markupHandler->markup());
m_curString="";
}
@@ -1423,7 +1457,7 @@ DocSectionHandler::~DocSectionHandler()
void DocSectionHandler::startDocSection(const QXmlAttributes& attrib)
{
m_parent->setDelegate(this);
- printf("Start docsection\n");
+ debug(2,"Start docsection\n");
m_id = attrib.value("id");
m_curString="";
}
@@ -1432,7 +1466,7 @@ void DocSectionHandler::endDocSection()
{
addTextNode();
m_parent->setDelegate(0);
- printf("End docsection\n");
+ debug(2,"End docsection\n");
}
void DocSectionHandler::addTextNode()
@@ -1440,7 +1474,7 @@ void DocSectionHandler::addTextNode()
if (!m_curString.isEmpty())
{
m_children.append(new TextNode(m_curString,m_markupHandler->markup()));
- printf("addTextNode() text=\"%s\" markup=%x\n",
+ debug(2,"addTextNode() text=\"%s\" markup=%x\n",
m_curString.data(),m_markupHandler->markup());
m_curString="";
}
@@ -1483,12 +1517,12 @@ DocHandler::~DocHandler()
void DocHandler::startDoc(const QXmlAttributes& /*attrib*/)
{
m_parent->setDelegate(this);
- printf("start dochandler\n");
+ debug(2,"start dochandler\n");
}
void DocHandler::endDoc()
{
- printf("end dochandler\n");
+ debug(2,"end dochandler\n");
m_parent->setDelegate(0);
}
d='n329' href='#n329'>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 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 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 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
/* 
 * tkPanedWindow.c --
 *
 *	This module implements "paned window" widgets that are object
 *	based.  A "paned window" is a widget that manages the geometry for
 *	some number of other widgets, placing a movable "sash" between them,
 *	which can be used to alter the relative sizes of adjacent widgets.
 *
 * Copyright (c) 1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Ajuba Solutions.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkPanedWindow.c,v 1.13.2.7 2004/11/17 22:18:07 hobbs Exp $
 */

#include "tkPort.h"
#include "default.h"
#include "tkInt.h"

/* Flag values for "sticky"ness  The 16 combinations subsume the packer's
 * notion of anchor and fill.
 *
 * STICK_NORTH  	This window sticks to the top of its cavity.
 * STICK_EAST		This window sticks to the right edge of its cavity.
 * STICK_SOUTH		This window sticks to the bottom of its cavity.
 * STICK_WEST		This window sticks to the left edge of its cavity.
 */

#define STICK_NORTH		1
#define STICK_EAST		2
#define STICK_SOUTH		4
#define STICK_WEST		8
/*
 * The following table defines the legal values for the -orient option.
 */

static char *orientStrings[] = {
    "horizontal", "vertical", (char *) NULL
};

enum orient { ORIENT_HORIZONTAL, ORIENT_VERTICAL };

typedef struct {
    Tk_OptionTable pwOptions;	/* Token for paned window option table. */
    Tk_OptionTable slaveOpts;	/* Token for slave cget option table. */
} OptionTables;

/*
 * One structure of the following type is kept for each window
 * managed by a paned window widget.
 */

typedef struct Slave {
    Tk_Window tkwin;			/* Window being managed. */
    
    int minSize;			/* Minimum size of this pane, on the
					 * relevant axis, in pixels. */
    int padx;				/* Additional padding requested for
					 * slave, in the x dimension. */
    int pady;				/* Additional padding requested for
					 * slave, in the y dimension. */
    Tcl_Obj *widthPtr, *heightPtr;	/* Tcl_Obj rep's of slave width/height,
					 * to allow for null values. */
    int width;				/* Slave width. */
    int height;				/* Slave height. */
    int sticky;				/* Sticky string. */
    int x, y;				/* Coordinates of the widget. */
    int paneWidth, paneHeight;		/* Pane dimensions (may be different
					 * from slave width/height). */
    int sashx, sashy;			/* Coordinates of the sash of the
					 * right or bottom of this pane. */
    int markx, marky;			/* Coordinates of the last mark set
					 * for the sash. */
    int handlex, handley;		/* Coordinates of the sash handle. */
    struct PanedWindow *masterPtr;	/* Paned window managing the window. */
    Tk_Window after;			/* Placeholder for parsing options. */
    Tk_Window before;			/* Placeholder for parsing options. */
} Slave;

/*
 * A data structure of the following type is kept for each paned window
 * widget managed by this file:
 */

typedef struct PanedWindow {
    Tk_Window tkwin;		/* Window that embodies the paned window. */
    Tk_Window proxywin;		/* Window for the resizing proxy. */
    Display *display;		/* X's token for the window's display. */
    Tcl_Interp *interp;		/* Interpreter associated with widget. */
    Tcl_Command widgetCmd;	/* Token for square's widget command. */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
    Tk_OptionTable slaveOpts;	/* Token for slave cget table. */
    Tk_3DBorder background;	/* Background color. */
    int borderWidth;		/* Value of -borderwidth option. */
    int relief;			/* 3D border effect (TK_RELIEF_RAISED, etc) */
    Tcl_Obj *widthPtr;		/* Tcl_Obj rep for width. */
    Tcl_Obj *heightPtr;		/* Tcl_Obj rep for height. */
    int width, height;		/* Width and height of the widget. */
    enum orient orient;		/* Orientation of the widget. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    int resizeOpaque;		/* Boolean indicating whether resize should be
				 * opaque or rubberband style. */
    
    int sashRelief;		/* Relief used to draw sash. */
    int sashWidth;		/* Width of each sash, in pixels. */
    Tcl_Obj *sashWidthPtr;	/* Tcl_Obj rep for sash width. */
    int sashPad;		/* Additional padding around each sash. */
    Tcl_Obj *sashPadPtr;	/* Tcl_Obj rep for sash padding. */
    int showHandle;		/* Boolean indicating whether sash handles
				 * should be drawn. */
    int handleSize;		/* Size of one side of a sash handle (handles
				 * are square), in pixels. */
    int handlePad;		/* Distance from border to draw handle. */
    Tcl_Obj *handleSizePtr;	/* Tcl_Obj rep for handle size. */
    Tk_Cursor sashCursor;	/* Cursor used when mouse is above a sash. */

    GC gc;			/* Graphics context for copying from
				 * off-screen pixmap onto screen. */
    int proxyx, proxyy;		/* Proxy x,y coordinates. */
    Slave **slaves;		/* Pointer to array of Slaves. */
    int numSlaves;		/* Number of slaves. */
    int sizeofSlaves;		/* Number of elements in the slaves array. */
    int flags;			/* Flags for widget; see below. */
} PanedWindow;

/*
 * Flags used for paned windows:
 *
 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler has
 *				been queued to redraw this window.
 *
 * WIDGET_DELETED:		Non-zero means that the paned window has
 *				been, or is in the process of being, deleted.
 *
 * RESIZE_PENDING:		Non-zero means that the window might need to
 *				change its size (or the size of its panes)
 *				because of a change in the size of one of its
 *				children.
 */

#define REDRAW_PENDING		0x0001
#define WIDGET_DELETED		0x0002
#define REQUESTED_RELAYOUT	0x0004
#define RECOMPUTE_GEOMETRY	0x0008
#define PROXY_REDRAW_PENDING	0x0010
#define RESIZE_PENDING		0x0020

/*
 * Forward declarations for procedures defined later in this file:
 */

int		Tk_PanedWindowObjCmd _ANSI_ARGS_((ClientData clientData,
			Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
static void	PanedWindowCmdDeletedProc _ANSI_ARGS_((ClientData clientData));
static int	ConfigurePanedWindow _ANSI_ARGS_((Tcl_Interp *interp,
			PanedWindow *pwPtr, int objc, Tcl_Obj *CONST objv[]));
static void	DestroyPanedWindow _ANSI_ARGS_((PanedWindow *pwPtr));
static void	DisplayPanedWindow _ANSI_ARGS_((ClientData clientData));
static void	PanedWindowEventProc _ANSI_ARGS_((ClientData clientData,
			XEvent *eventPtr));
static void	ProxyWindowEventProc _ANSI_ARGS_((ClientData clientData,
			XEvent *eventPtr));
static void	DisplayProxyWindow _ANSI_ARGS_((ClientData clientData));
void		PanedWindowWorldChanged _ANSI_ARGS_((ClientData instanceData));
static int	PanedWindowWidgetObjCmd _ANSI_ARGS_((ClientData clientData,
			Tcl_Interp *, int objc, Tcl_Obj * CONST objv[]));
static void	PanedWindowLostSlaveProc _ANSI_ARGS_((ClientData clientData,
			Tk_Window tkwin));
static void	PanedWindowReqProc _ANSI_ARGS_((ClientData clientData,
			Tk_Window tkwin));
static void	ArrangePanes _ANSI_ARGS_((ClientData clientData));
static void	Unlink _ANSI_ARGS_((Slave *slavePtr));
static Slave *	GetPane _ANSI_ARGS_((PanedWindow *pwPtr, Tk_Window tkwin));
static void	SlaveStructureProc _ANSI_ARGS_((ClientData clientData,
			XEvent *eventPtr));
static int	PanedWindowSashCommand _ANSI_ARGS_((PanedWindow *pwPtr,
			Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
static int	PanedWindowProxyCommand _ANSI_ARGS_((PanedWindow *pwPtr,
			Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
static void	ComputeGeometry _ANSI_ARGS_((PanedWindow *pwPtr));
static int	ConfigureSlaves _ANSI_ARGS_((PanedWindow *pwPtr,
			Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
static void	DestroyOptionTables _ANSI_ARGS_((ClientData clientData,
			Tcl_Interp *interp));
static int	SetSticky _ANSI_ARGS_((ClientData clientData,
			Tcl_Interp *interp, Tk_Window tkwin,
			Tcl_Obj **value, char *recordPtr, int internalOffset,
			char *oldInternalPtr, int flags));
static Tcl_Obj *GetSticky _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin,
			char *recordPtr, int internalOffset));
static void	RestoreSticky _ANSI_ARGS_((ClientData clientData,
			Tk_Window tkwin, char *internalPtr,
			char *oldInternalPtr));
static void	AdjustForSticky _ANSI_ARGS_((int sticky, int cavityWidth,
			int cavityHeight, int *xPtr, int *yPtr,
			int *slaveWidthPtr, int *slaveHeightPtr));
static void	MoveSash _ANSI_ARGS_((PanedWindow *pwPtr, int sash, int diff));
static int	ObjectIsEmpty _ANSI_ARGS_((Tcl_Obj *objPtr));
static char *	ComputeSlotAddress _ANSI_ARGS_((char *recordPtr, int offset));
static int	PanedWindowIdentifyCoords _ANSI_ARGS_((PanedWindow *pwPtr,
			Tcl_Interp *interp, int x, int y));

/*
 * Sashes are between panes only, so there is one less sash than slaves
 */

#define ValidSashIndex(pwPtr, sash) \
	(((sash) >= 0) && ((sash) < ((pwPtr)->numSlaves-1)))

static Tk_GeomMgr panedWindowMgrType = {
    "panedwindow",		/* name */
    PanedWindowReqProc,		/* requestProc */
    PanedWindowLostSlaveProc,	/* lostSlaveProc */
};

/*
 * Information used for objv parsing.
 */

#define GEOMETRY		0x0001

/*
 * The following structure contains pointers to functions used for processing
 * the custom "-sticky" option for slave windows.
 */

static Tk_ObjCustomOption stickyOption = {
    "sticky",				/* name */
    SetSticky,				/* setProc */
    GetSticky,				/* getProc */
    RestoreSticky,			/* restoreProc */
    (Tk_CustomOptionFreeProc *)NULL,	/* freeProc */
    0
};

static Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BORDER, "-background", "background", "Background",
	 DEF_PANEDWINDOW_BG_COLOR, -1, Tk_Offset(PanedWindow, background), 0,
	 (ClientData) DEF_PANEDWINDOW_BG_MONO},
    {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
	 (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth"},
    {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL,
	 (char *) NULL, 0, -1, 0, (ClientData) "-background"},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	 DEF_PANEDWINDOW_BORDERWIDTH, -1, Tk_Offset(PanedWindow, borderWidth),
         0, 0, GEOMETRY},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	 DEF_PANEDWINDOW_CURSOR, -1, Tk_Offset(PanedWindow, cursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-handlepad", "handlePad", "HandlePad",
	 DEF_PANEDWINDOW_HANDLEPAD, -1, Tk_Offset(PanedWindow, handlePad),
         0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-handlesize", "handleSize", "HandleSize",
	 DEF_PANEDWINDOW_HANDLESIZE, Tk_Offset(PanedWindow, handleSizePtr),
	 Tk_Offset(PanedWindow, handleSize), 0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-height", "height", "Height",
	 DEF_PANEDWINDOW_HEIGHT, Tk_Offset(PanedWindow, heightPtr),
	 Tk_Offset(PanedWindow, height), TK_OPTION_NULL_OK, 0, GEOMETRY},
    {TK_OPTION_BOOLEAN, "-opaqueresize", "opaqueResize", "OpaqueResize",
	 DEF_PANEDWINDOW_OPAQUERESIZE, -1,
         Tk_Offset(PanedWindow, resizeOpaque), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
	 DEF_PANEDWINDOW_ORIENT, -1, Tk_Offset(PanedWindow, orient), 
	 0, (ClientData) orientStrings, GEOMETRY},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	 DEF_PANEDWINDOW_RELIEF, -1, Tk_Offset(PanedWindow, relief), 0, 0, 0},
    {TK_OPTION_CURSOR, "-sashcursor", "sashCursor", "Cursor",
	 DEF_PANEDWINDOW_SASHCURSOR, -1, Tk_Offset(PanedWindow, sashCursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-sashpad", "sashPad", "SashPad",
	 DEF_PANEDWINDOW_SASHPAD, -1, Tk_Offset(PanedWindow, sashPad),
         0, 0, GEOMETRY},
    {TK_OPTION_RELIEF, "-sashrelief", "sashRelief", "Relief",
	 DEF_PANEDWINDOW_SASHRELIEF, -1, Tk_Offset(PanedWindow, sashRelief),
         0, 0, 0},
    {TK_OPTION_PIXELS, "-sashwidth", "sashWidth", "Width",
	 DEF_PANEDWINDOW_SASHWIDTH, Tk_Offset(PanedWindow, sashWidthPtr),
	 Tk_Offset(PanedWindow, sashWidth), 0, 0, GEOMETRY},
    {TK_OPTION_BOOLEAN, "-showhandle", "showHandle", "ShowHandle",
	 DEF_PANEDWINDOW_SHOWHANDLE, -1, Tk_Offset(PanedWindow, showHandle),
         0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-width", "width", "Width",
	 DEF_PANEDWINDOW_WIDTH, Tk_Offset(PanedWindow, widthPtr),
	 Tk_Offset(PanedWindow, width), TK_OPTION_NULL_OK, 0, GEOMETRY},
    {TK_OPTION_END}
};

static Tk_OptionSpec slaveOptionSpecs[] = {
    {TK_OPTION_WINDOW, "-after", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_AFTER, -1, Tk_Offset(Slave, after),
         TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_WINDOW, "-before", (char *) NULL, (char *) NULL,
         DEF_PANEDWINDOW_PANE_BEFORE, -1, Tk_Offset(Slave, before),
         TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-height", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_HEIGHT, Tk_Offset(Slave, heightPtr),
         Tk_Offset(Slave, height), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-minsize", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_MINSIZE, -1, Tk_Offset(Slave, minSize), 0, 0, 0},
    {TK_OPTION_PIXELS, "-padx", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_PADX, -1, Tk_Offset(Slave, padx), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_PADY, -1, Tk_Offset(Slave, pady), 0, 0, 0},
    {TK_OPTION_CUSTOM, "-sticky", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_STICKY, -1, Tk_Offset(Slave, sticky), 0,
         (ClientData) &stickyOption, 0},
    {TK_OPTION_PIXELS, "-width", (char *) NULL, (char *) NULL,
	 DEF_PANEDWINDOW_PANE_WIDTH, Tk_Offset(Slave, widthPtr),
         Tk_Offset(Slave, width), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END}
};
    

/*
 *--------------------------------------------------------------
 *
 * Tk_PanedWindowObjCmd --
 *
 *	This procedure is invoked to process the "panedwindow" Tcl
 *	command.  It creates a new "panedwindow" widget.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	A new widget is created and configured.
 *
 *--------------------------------------------------------------
 */

int
Tk_PanedWindowObjCmd(clientData, interp, objc, objv)
    ClientData clientData;	/* NULL. */
    Tcl_Interp *interp;		/* Current interpreter. */
    int objc;			/* Number of arguments. */
    Tcl_Obj * CONST objv[];	/* Argument objects. */
{
    PanedWindow *pwPtr;
    Tk_Window tkwin, parent;
    OptionTables *pwOpts;
    XSetWindowAttributes atts;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
	return TCL_ERROR;
    }

    tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), 
	    Tcl_GetStringFromObj(objv[1], NULL), (char *) NULL);
    if (tkwin == NULL) {
	return TCL_ERROR;
    }

    pwOpts = (OptionTables *)
	Tcl_GetAssocData(interp, "PanedWindowOptionTables", NULL);
    if (pwOpts == NULL) {
	/*
	 * The first time this procedure is invoked, the option tables will
	 * be NULL.  We then create the option tables from the templates
	 * and store a pointer to the tables as the command's clinical so
	 * we'll have easy access to it in the future.
	 */
	pwOpts = (OptionTables *) ckalloc(sizeof(OptionTables));
	/* Set up an exit handler to free the optionTables struct */
	Tcl_SetAssocData(interp, "PanedWindowOptionTables",
		DestroyOptionTables, (ClientData) pwOpts);

	/* Create the paned window option tables. */
	pwOpts->pwOptions = Tk_CreateOptionTable(interp, optionSpecs);
	pwOpts->slaveOpts = Tk_CreateOptionTable(interp, slaveOptionSpecs);
    }

    Tk_SetClass(tkwin, "Panedwindow");

    /*
     * Allocate and initialize the widget record.
     */

    pwPtr = (PanedWindow *) ckalloc(sizeof(PanedWindow));
    memset((void *)pwPtr, 0, (sizeof(PanedWindow)));
    pwPtr->tkwin	= tkwin;
    pwPtr->display	= Tk_Display(tkwin);
    pwPtr->interp	= interp;
    pwPtr->widgetCmd	= Tcl_CreateObjCommand(interp,
	    Tk_PathName(pwPtr->tkwin), PanedWindowWidgetObjCmd,
	    (ClientData) pwPtr, PanedWindowCmdDeletedProc);
    pwPtr->optionTable	= pwOpts->pwOptions;
    pwPtr->slaveOpts	= pwOpts->slaveOpts;
    pwPtr->relief	= TK_RELIEF_RAISED;
    pwPtr->gc		= None;
    pwPtr->cursor	= None;
    pwPtr->sashCursor	= None;

    /*
     * Keep a hold of the associated tkwin until we destroy the widget,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve((ClientData) pwPtr->tkwin);

    if (Tk_InitOptions(interp, (char *) pwPtr, pwOpts->pwOptions,
	    tkwin) != TCL_OK) {
	Tk_DestroyWindow(pwPtr->tkwin);
	return TCL_ERROR;
    }

    Tk_CreateEventHandler(pwPtr->tkwin, ExposureMask|StructureNotifyMask,
	    PanedWindowEventProc, (ClientData) pwPtr);

    /*
     * Find the toplevel ancestor of the panedwindow, and make a proxy
     * win as a child of that window; this way the proxy can always float
     * above slaves in the panedwindow.
     */
    parent = Tk_Parent(pwPtr->tkwin);
    while (!(Tk_IsTopLevel(parent))) {
	parent = Tk_Parent(parent);
	if (parent == NULL) {
	    parent = pwPtr->tkwin;
	    break;
	}
    }

    pwPtr->proxywin = Tk_CreateAnonymousWindow(interp, parent, (char *) NULL);
    /*
     * The proxy window has to be able to share GCs with the main
     * panedwindow despite being children of windows with potentially
     * different characteristics, and it looks better that way too.
     * [Bug 702230]
     * Also Set the X window save under attribute to avoid expose events as
     * the proxy sash is dragged across the panes.  [Bug 1036963]
     */
    Tk_SetWindowVisual(pwPtr->proxywin,
	    Tk_Visual(tkwin), Tk_Depth(tkwin), Tk_Colormap(tkwin));
    Tk_CreateEventHandler(pwPtr->proxywin, ExposureMask, ProxyWindowEventProc,
	    (ClientData) pwPtr);
    atts.save_under = True;
    Tk_ChangeWindowAttributes(pwPtr->proxywin, CWSaveUnder, &atts);

    if (ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2) != TCL_OK) {
	Tk_DestroyWindow(pwPtr->proxywin);
	Tk_DestroyWindow(pwPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(pwPtr->tkwin), -1);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowWidgetObjCmd --
 *
 *	This procedure is invoked to process the Tcl command
 *	that corresponds to a widget managed by this module.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
PanedWindowWidgetObjCmd(clientData, interp, objc, objv)
    ClientData clientData;		/* Information about square widget. */
    Tcl_Interp *interp;			/* Current interpreter. */
    int objc;				/* Number of arguments. */
    Tcl_Obj * CONST objv[];		/* Argument objects. */
{
    PanedWindow *pwPtr = (PanedWindow *) clientData;
    int result = TCL_OK;
    static CONST char *optionStrings[] = {"add", "cget", "configure", "forget",
					"identify", "panecget",
                                        "paneconfigure", "panes",
                                        "proxy", "sash", (char *) NULL};
    enum options { PW_ADD, PW_CGET, PW_CONFIGURE, PW_FORGET, PW_IDENTIFY,
		       PW_PANECGET, PW_PANECONFIGURE, PW_PANES, PW_PROXY,
                       PW_SASH };
    Tcl_Obj *resultObj;
    int index, count, i, x, y;
    Tk_Window tkwin;
    Slave *slavePtr;
    
    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "command",
	    0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Tcl_Preserve((ClientData) pwPtr);
    
    switch ((enum options) index) {
	case PW_ADD: {
	    if (objc < 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
		result = TCL_ERROR;
		break;
	    }
	    
	    result = ConfigureSlaves(pwPtr, interp, objc, objv);
	    break;
	}
	
	case PW_CGET: {
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "option");
		result = TCL_ERROR;
		break;
	    }
	    resultObj = Tk_GetOptionValue(interp, (char *) pwPtr,
		    pwPtr->optionTable, objv[2], pwPtr->tkwin);
	    if (resultObj == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, resultObj);
	    }
	    break;
	}
	
	case PW_CONFIGURE: {
	    resultObj = NULL;
	    if (objc <= 3) {
		resultObj = Tk_GetOptionInfo(interp, (char *) pwPtr,
			pwPtr->optionTable,
			(objc == 3) ? objv[2] : (Tcl_Obj *) NULL,
			pwPtr->tkwin);
		if (resultObj == NULL) {
		    result = TCL_ERROR;
		} else {
		    Tcl_SetObjResult(interp, resultObj);
		}
	    } else {
		result = ConfigurePanedWindow(interp, pwPtr, objc - 2,
			objv + 2);
	    }
	    break;
	}
	
	case PW_FORGET: {
	    Tk_Window slave;
	    int i;
	    
	    if (objc < 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
		result = TCL_ERROR;
		break;
	    }

	    /*
	     * Clean up each window named in the arg list.
	     */
	    for (count = 0, i = 2; i < objc; i++) {
		slave = Tk_NameToWindow(interp, Tcl_GetString(objv[i]),
			pwPtr->tkwin);
		if (slave == NULL) {
		    continue;
		}
		slavePtr = GetPane(pwPtr, slave);
		if ((slavePtr != NULL) && (slavePtr->masterPtr != NULL)) {
		    count++;
		    Tk_ManageGeometry(slave, (Tk_GeomMgr *) NULL,
			    (ClientData) NULL);
		    Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
		    Tk_DeleteEventHandler(slavePtr->tkwin, StructureNotifyMask,
			    SlaveStructureProc, (ClientData) slavePtr);
		    Tk_UnmapWindow(slavePtr->tkwin);
		    Unlink(slavePtr);
		}
		if (count != 0) {
		    ComputeGeometry(pwPtr);
		}
	    }
	    break;
	}

	case PW_IDENTIFY: {
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 2, objv, "x y");
		result = TCL_ERROR;
		break;
	    }

	    if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		    || (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
		result = TCL_ERROR;
		break;
	    }
	    
	    result = PanedWindowIdentifyCoords(pwPtr, interp, x, y);
	    break;
	}

	case PW_PANECGET: {
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 2, objv, "pane option");
		result = TCL_ERROR;
		break;
	    }
	    tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
		    pwPtr->tkwin);
	    if (tkwin == NULL) {
		result = TCL_ERROR;
		break;
	    }
	    resultObj = NULL;
	    for (i = 0; i < pwPtr->numSlaves; i++) {
		if (pwPtr->slaves[i]->tkwin == tkwin) {
		    resultObj = Tk_GetOptionValue(interp,
			    (char *) pwPtr->slaves[i], pwPtr->slaveOpts,
			    objv[3], tkwin);
		}
	    }
	    if (i == pwPtr->numSlaves) {
		Tcl_SetResult(interp, "not managed by this window",
			TCL_STATIC);
	    }
	    if (resultObj == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, resultObj);
	    }
	    break;
	}

	case PW_PANECONFIGURE: {
	    if (objc < 3) {
		Tcl_WrongNumArgs(interp, 2, objv,
			"pane ?option? ?value option value ...?");
		result = TCL_ERROR;
		break;
	    }
	    resultObj = NULL;
	    if (objc <= 4) {
		tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
			pwPtr->tkwin);
		for (i = 0; i < pwPtr->numSlaves; i++) {
		    if (pwPtr->slaves[i]->tkwin == tkwin) {
			resultObj = Tk_GetOptionInfo(interp,
				(char *) pwPtr->slaves[i],
				pwPtr->slaveOpts,
				(objc == 4) ? objv[3] : (Tcl_Obj *) NULL,
				pwPtr->tkwin);
			if (resultObj == NULL) {
			    result = TCL_ERROR;
			} else {
			    Tcl_SetObjResult(interp, resultObj);
			}
			break;
		    }
		}
	    } else {
		result = ConfigureSlaves(pwPtr, interp, objc, objv);
	    }
	    break;
	}
	    
	case PW_PANES: {
	    resultObj = Tcl_NewObj();

	    Tcl_IncrRefCount(resultObj);

	    for (i = 0; i < pwPtr->numSlaves; i++) {
		Tcl_ListObjAppendElement(interp, resultObj,
			Tcl_NewStringObj(Tk_PathName(pwPtr->slaves[i]->tkwin),
				-1));
	    }
	    Tcl_SetObjResult(interp, resultObj);
	    Tcl_DecrRefCount(resultObj);
	    break;
	}

	case PW_PROXY: {
	    result = PanedWindowProxyCommand(pwPtr, interp, objc, objv);
	    break;
	}

	case PW_SASH: {
	    result = PanedWindowSashCommand(pwPtr, interp, objc, objv);
	    break;
	}
    }
    Tcl_Release((ClientData) pwPtr);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigureSlaves --
 *
 *	Add or alter the configuration options of a slave in a paned
 *	window.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	Depends on options; may add a slave to the paned window, may
 *	alter the geometry management options of a slave.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureSlaves(pwPtr, interp, objc, objv)
    PanedWindow *pwPtr;			/* Information about paned window. */
    Tcl_Interp *interp;			/* Current interpreter. */
    int objc;				/* Number of arguments. */
    Tcl_Obj * CONST objv[];		/* Argument objects. */
{
    int i, firstOptionArg, j, found, doubleBw, index, numNewSlaves, haveLoc;
    int insertIndex;
    Tk_Window tkwin = NULL, ancestor, parent;
    Slave *slavePtr, **inserts, **new;
    Slave options;
    char *arg;
   
    /*
     * Find the non-window name arguments; these are the configure options
     * for the slaves.  Also validate that the window names given are
     * legitimate (ie, they are real windows, they are not the panedwindow
     * itself, etc.).
     */
    for (i = 2; i < objc; i++) {
	arg = Tcl_GetString(objv[i]);
	if (arg[0] == '-') {
	    break;
	} else {
	    tkwin = Tk_NameToWindow(interp, arg, pwPtr->tkwin);
	    if (tkwin == NULL) {
		/*
		 * Just a plain old bad window; Tk_NameToWindow filled in an
		 * error message for us.
		 */
		return TCL_ERROR;
	    } else if (tkwin == pwPtr->tkwin) {
		/*
		 * A panedwindow cannot manage itself.
		 */
		Tcl_ResetResult(interp);
		Tcl_AppendResult(interp, "can't add ", arg, " to itself",
			(char *) NULL);
		return TCL_ERROR;
	    } else if (Tk_IsTopLevel(tkwin)) {
		/*
		 * A panedwindow cannot manage a toplevel.
		 */
		Tcl_ResetResult(interp);
		Tcl_AppendResult(interp, "can't add toplevel ", arg, " to ",
			Tk_PathName(pwPtr->tkwin), (char *) NULL);
		return TCL_ERROR;
	    } else {
		/*
		 * Make sure the panedwindow is the parent of the slave,
		 * or a descendant of the slave's parent.
		 */
		parent = Tk_Parent(tkwin);
		for (ancestor = pwPtr->tkwin;;ancestor = Tk_Parent(ancestor)) {
		    if (ancestor == parent) {
			break;
		    }
		    if (Tk_IsTopLevel(ancestor)) {
			Tcl_ResetResult(interp);
			Tcl_AppendResult(interp, "can't add ", arg,
				" to ", Tk_PathName(pwPtr->tkwin),
				(char *) NULL);
			return TCL_ERROR;
		    }
		}
	    }
	}
    }
    firstOptionArg = i;

    /*
     * Pre-parse the configuration options, to get the before/after specifiers
     * into an easy-to-find location (a local variable).  Also, check the
     * return from Tk_SetOptions once, here, so we can save a little bit of
     * extra testing in the for loop below.
     */
    memset((void *)&options, 0, sizeof(Slave));
    if (Tk_SetOptions(interp, (char *) &options, pwPtr->slaveOpts,
	    objc - firstOptionArg, objv + firstOptionArg,
	    pwPtr->tkwin, NULL, NULL) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * If either -after or -before was given, find the numerical index that
     * corresponds to the given window.  If both -after and -before are
     * given, the option precedence is:  -after, then -before.
     */
    index = -1;
    haveLoc = 0;
    if (options.after != None) {
	tkwin = options.after;
	haveLoc = 1;
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    if (options.after == pwPtr->slaves[i]->tkwin) {
		index = i + 1;
		break;
	    }
	}
    } else if (options.before != None) {
	tkwin = options.before;
	haveLoc = 1;
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    if (options.before == pwPtr->slaves[i]->tkwin) {
		index = i;
		break;
	    }
	}
    }

    /*
     * If a window was given for -after/-before, but it's not a window
     * managed by the panedwindow, throw an error
     */
    if (haveLoc && index == -1) {
	Tcl_ResetResult(interp);
	Tcl_AppendResult(interp, "window \"", Tk_PathName(tkwin),
		"\" is not managed by ", Tk_PathName(pwPtr->tkwin),
		(char *) NULL);
	Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts,
		pwPtr->tkwin);
	return TCL_ERROR;
    }

    /*
     * Allocate an array to hold, in order, the pointers to the slave
     * structures corresponding to the windows specified.  Some of those
     * structures may already have existed, some may be new.
     */
    inserts = (Slave **)ckalloc(sizeof(Slave *) * (firstOptionArg - 2));
    insertIndex = 0;
    
    /*
     * Populate the inserts array, creating new slave structures as necessary,
     * applying the options to each structure as we go, and, if necessary,
     * marking the spot in the original slaves array as empty (for pre-existing
     * slave structures).
     */
    for (i = 0, numNewSlaves = 0; i < firstOptionArg - 2; i++) {
	/*
	 * We don't check that tkwin is NULL here, because the pre-pass above
	 * guarantees that the input at this stage is good.
	 */
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[i + 2]),
		pwPtr->tkwin);

	found = 0;
	for (j = 0; j < pwPtr->numSlaves; j++) {
	    if (pwPtr->slaves[j] != NULL && pwPtr->slaves[j]->tkwin == tkwin) {
		Tk_SetOptions(interp, (char *) pwPtr->slaves[j],
			pwPtr->slaveOpts, objc - firstOptionArg,
			objv + firstOptionArg, pwPtr->tkwin, NULL, NULL);
		found = 1;

		/*
		 * If the slave is supposed to move, add it to the inserts
		 * array now; otherwise, leave it where it is.
		 */

		if (index != -1) {
		    inserts[insertIndex++] = pwPtr->slaves[j];
		    pwPtr->slaves[j] = NULL;
		}
		break;
	    }
	}

	if (found) {
	    continue;
	}

	/*
	 * Make sure this slave wasn't already put into the inserts array,
	 * ie, when the user specifies the same window multiple times in
	 * a single add commaned.
	 */
	for (j = 0; j < insertIndex; j++) {
	    if (inserts[j]->tkwin == tkwin) {
		found = 1;
		break;
	    }
	}
	if (found) {
	    continue;
	}
	
	/*
	 * Create a new slave structure and initialize it.  All slaves
	 * start out with their "natural" dimensions.
	 */
	
	slavePtr = (Slave *) ckalloc(sizeof(Slave));
	memset(slavePtr, 0, sizeof(Slave));
	Tk_InitOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
		pwPtr->tkwin);
	Tk_SetOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
		objc - firstOptionArg, objv + firstOptionArg,
		pwPtr->tkwin, NULL, NULL);
	slavePtr->tkwin		= tkwin;
	slavePtr->masterPtr	= pwPtr;
	doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
	if (slavePtr->width > 0) {
	    slavePtr->paneWidth = slavePtr->width;
	} else {
	    slavePtr->paneWidth = Tk_ReqWidth(tkwin) + doubleBw;
	}
	if (slavePtr->height > 0) {
	    slavePtr->paneHeight = slavePtr->height;
	} else {
	    slavePtr->paneHeight = Tk_ReqHeight(tkwin) + doubleBw;
	}

	/*
	 * Set up the geometry management callbacks for this slave.
	 */
	
	Tk_CreateEventHandler(slavePtr->tkwin, StructureNotifyMask,
		SlaveStructureProc, (ClientData) slavePtr);
	Tk_ManageGeometry(slavePtr->tkwin, &panedWindowMgrType,
		(ClientData) slavePtr);
	inserts[insertIndex++] = slavePtr;
	numNewSlaves++;
    }

    /*
     * Allocate the new slaves array, then copy the slaves into it, in
     * order.
     */
    i = sizeof(Slave *) * (pwPtr->numSlaves+numNewSlaves);
    new = (Slave **)ckalloc((unsigned) i);
    memset(new, 0, (size_t) i);
    if (index == -1) {
	/*
	 * If none of the existing slaves have to be moved, just copy the old
	 * and append the new.
	 */
	memcpy((void *)&(new[0]), pwPtr->slaves,
		sizeof(Slave *) * pwPtr->numSlaves);
	memcpy((void *)&(new[pwPtr->numSlaves]), inserts,
		sizeof(Slave *) * numNewSlaves);
    } else {
	/*
	 * If some of the existing slaves were moved, the old slaves array
	 * will be partially populated, with some valid and some invalid
	 * entries.  Walk through it, copying valid entries to the new slaves
	 * array as we go; when we get to the insert location for the new
	 * slaves, copy the inserts array over, then finish off the old slaves
	 * array.
	 */
	for (i = 0, j = 0; i < index; i++) {
	    if (pwPtr->slaves[i] != NULL) {
		new[j] = pwPtr->slaves[i];
		j++;
	    }
	}
	
	memcpy((void *)&(new[j]), inserts, sizeof(Slave *) * (insertIndex));
	j += firstOptionArg - 2;
	
	for (i = index; i < pwPtr->numSlaves; i++) {
	    if (pwPtr->slaves[i] != NULL) {
		new[j] = pwPtr->slaves[i];
		j++;
	    }
	}
    }

    /*
     * Make the new slaves array the paned window's slave array, and clean up.
     */
    ckfree((void *)pwPtr->slaves);
    ckfree((void *)inserts);
    pwPtr->slaves = new;

    /*
     * Set the paned window's slave count to the new value.
     */
    pwPtr->numSlaves += numNewSlaves;

    Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts, pwPtr->tkwin);
    
    ComputeGeometry(pwPtr);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * PanedWindowSashCommand --
 *
 *	Implementation of the panedwindow sash subcommand.  See the user
 *	documentation for details on what it does.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	Depends on the arguments.
 *
 *----------------------------------------------------------------------
 */

static int
PanedWindowSashCommand(pwPtr, interp, objc, objv)
    PanedWindow *pwPtr;		/* Pointer to paned window information. */
    Tcl_Interp *interp;		/* Current interpreter. */
    int objc;			/* Number of arguments. */
    Tcl_Obj * CONST objv[];	/* Argument objects. */
{
    static CONST char *sashOptionStrings[] = { "coord", "dragto", "mark",
					     "place", (char *) NULL };
    enum sashOptions { SASH_COORD, SASH_DRAGTO, SASH_MARK, SASH_PLACE };
    int index, sash, x, y, diff;
    Tcl_Obj *coords[2];
    Slave *slavePtr;
    
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[2], sashOptionStrings,
	    "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Tcl_ResetResult(interp);
    switch ((enum sashOptions) index) {
	case SASH_COORD: {
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		return TCL_ERROR;
	    }

	    if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
		return TCL_ERROR;
	    }

	    if (!ValidSashIndex(pwPtr, sash)) {
		Tcl_ResetResult(interp);
		Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
		return TCL_ERROR;
	    }
	    slavePtr = pwPtr->slaves[sash];
	    
	    coords[0] = Tcl_NewIntObj(slavePtr->sashx);
	    coords[1] = Tcl_NewIntObj(slavePtr->sashy);
	    Tcl_SetListObj(Tcl_GetObjResult(interp), 2, coords);
	    break;
	}

	case SASH_MARK: {
	    if (objc != 6 && objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index ?x y?");
		return TCL_ERROR;
	    }
	    
	    if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
		return TCL_ERROR;
	    }

	    if (!ValidSashIndex(pwPtr, sash)) {
		Tcl_ResetResult(interp);
		Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
		return TCL_ERROR;
	    }

	    if (objc == 6) {
		if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
		    return TCL_ERROR;
		}
		
		if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
		    return TCL_ERROR;
		}

		pwPtr->slaves[sash]->markx = x;
		pwPtr->slaves[sash]->marky = y;
	    } else {
		coords[0] = Tcl_NewIntObj(pwPtr->slaves[sash]->markx);
		coords[1] = Tcl_NewIntObj(pwPtr->slaves[sash]->marky);
		Tcl_SetListObj(Tcl_GetObjResult(interp), 2, coords);
	    }

	    break;
	}
	
	case SASH_DRAGTO:
	case SASH_PLACE: {
	    if (objc != 6) {
		Tcl_WrongNumArgs(interp, 3, objv, "index x y");
		return TCL_ERROR;
	    }
	    
	    if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
		return TCL_ERROR;
	    }

	    if (!ValidSashIndex(pwPtr, sash)) {
		Tcl_ResetResult(interp);
		Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
		return TCL_ERROR;
	    }

	    if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
		return TCL_ERROR;
	    }

	    if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
		return TCL_ERROR;
	    }
	    
	    slavePtr = pwPtr->slaves[sash];
	    if (pwPtr->orient == ORIENT_HORIZONTAL) {
		if (index == SASH_PLACE) {
		    diff = x - pwPtr->slaves[sash]->sashx;
		} else {
		    diff = x - pwPtr->slaves[sash]->markx;
		}
	    } else {
		if (index == SASH_PLACE) {
		    diff = y - pwPtr->slaves[sash]->sashy;
		} else {
		    diff = y - pwPtr->slaves[sash]->marky;
		}
	    }

	    MoveSash(pwPtr, sash, diff);
	    ComputeGeometry(pwPtr);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigurePanedWindow --
 *
 *	This procedure is called to process an argv/argc list in
 *	conjunction with the Tk option database to configure (or
 *	reconfigure) a paned window widget.
 *
 * Results:
 *	The return value is a standard Tcl result.  If TCL_ERROR is
 *	returned, then the interp's result contains an error message.
 *
 * Side effects:
 *	Configuration information, such as colors, border width,
 *	etc. get set for pwPtr;  old resources get freed,
 *	if there were any.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigurePanedWindow(interp, pwPtr, objc, objv)
    Tcl_Interp *interp;		/* Used for error reporting. */
    PanedWindow *pwPtr;		/* Information about widget. */
    int objc;			/* Number of arguments. */
    Tcl_Obj *CONST objv[];	/* Argument values. */
{
    Tk_SavedOptions savedOptions;
    int typemask = 0;
    
    if (Tk_SetOptions(interp, (char *) pwPtr, pwPtr->optionTable, objc, objv,
	    pwPtr->tkwin, &savedOptions, &typemask) != TCL_OK) {
	Tk_RestoreSavedOptions(&savedOptions);
	return TCL_ERROR;
    }

    Tk_FreeSavedOptions(&savedOptions);

    PanedWindowWorldChanged((ClientData) pwPtr);

    /*
     * If an option that affects geometry has changed, make a relayout
     * request.
     */

    if (typemask & GEOMETRY) {
	ComputeGeometry(pwPtr);
    }
    
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * PanedWindowWorldChanged --
 *
 *	This procedure is invoked anytime a paned window's world has
 *	changed in some way that causes the widget to have to recompute
 *	graphics contexts and geometry.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Paned window will be relayed out and redisplayed.
 *
 *----------------------------------------------------------------------
 */

void
PanedWindowWorldChanged(instanceData)
    ClientData instanceData;	/* Information about the paned window. */
{
    XGCValues gcValues;
    GC newGC;
    PanedWindow *pwPtr = (PanedWindow *) instanceData;

    /*
     * Allocated a graphics context for drawing the paned window widget
     * elements (background, sashes, etc.) and set the window background.
     */
    
    gcValues.background = Tk_3DBorderColor(pwPtr->background)->pixel;
    newGC = Tk_GetGC(pwPtr->tkwin, GCBackground, &gcValues);
    if (pwPtr->gc != None) {
	Tk_FreeGC(pwPtr->display, pwPtr->gc);
    }
    pwPtr->gc = newGC;
    Tk_SetWindowBackground(pwPtr->tkwin, gcValues.background);

    /*
     * Issue geometry size requests to Tk.
     */
    
    Tk_SetInternalBorder(pwPtr->tkwin, pwPtr->borderWidth);
    if (pwPtr->width > 0 || pwPtr->height > 0) {
	Tk_GeometryRequest(pwPtr->tkwin, pwPtr->width, pwPtr->height);
    }

    /*
     * Arrange for the window to be redrawn, if neccessary.
     */

    if (Tk_IsMapped(pwPtr->tkwin) && !(pwPtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
	pwPtr->flags |= REDRAW_PENDING;
    }
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for various
 *	events on paned windows.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the window gets deleted, internal structures get
 *	cleaned up.  When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
PanedWindowEventProc(clientData, eventPtr)
    ClientData clientData;	/* Information about window. */
    XEvent *eventPtr;		/* Information about event. */
{
    PanedWindow *pwPtr = (PanedWindow *) clientData;

    if (eventPtr->type == Expose) {
	if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
	    pwPtr->flags |= REDRAW_PENDING;
	}
    } else if (eventPtr->type == ConfigureNotify) {
	pwPtr->flags |= REQUESTED_RELAYOUT;
	if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
	    pwPtr->flags |= REDRAW_PENDING;
	}
    } else if (eventPtr->type == DestroyNotify) {
	DestroyPanedWindow(pwPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PanedWindowCmdDeletedProc --
 *
 *	This procedure is invoked when a widget command is deleted.  If
 *	the widget isn't already in the process of being destroyed,
 *	this command destroys it.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
PanedWindowCmdDeletedProc(clientData)
    ClientData clientData;	/* Pointer to widget record for widget. */
{
    PanedWindow *pwPtr = (PanedWindow *) clientData;

    /*
     * This procedure could be invoked either because the window was
     * destroyed and the command was then deleted or because the command was
     * deleted, and then this procedure destroys the widget.  The
     * WIDGET_DELETED flag distinguishes these cases.
     */

    if (!(pwPtr->flags & WIDGET_DELETED)) {
	Tk_DestroyWindow(pwPtr->proxywin);
	Tk_DestroyWindow(pwPtr->tkwin);
    }
}

/*
 *--------------------------------------------------------------
 *
 * DisplayPanedWindow --
 *
 *	This procedure redraws the contents of a paned window widget.
 *	It is invoked as a do-when-idle handler, so it only runs
 *	when there's nothing else for the application to do.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayPanedWindow(clientData)
    ClientData clientData;	/* Information about window. */
{
    PanedWindow *pwPtr = (PanedWindow *) clientData;
    Pixmap pixmap;
    Tk_Window tkwin = pwPtr->tkwin;
    int i, sashWidth, sashHeight;
    
    pwPtr->flags &= ~REDRAW_PENDING;
    if ((pwPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }
    
    if (pwPtr->flags & REQUESTED_RELAYOUT) {
	ArrangePanes(clientData);
    }

    /*
     * Create a pixmap for double-buffering, if necessary.
     */

    pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));

    /*
     * Redraw the widget's background and border.
     */
    Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background, 0, 0,
	    Tk_Width(tkwin), Tk_Height(tkwin), pwPtr->borderWidth,
	    pwPtr->relief);
    
    /*
     * Set up boilerplate geometry values for sashes (width, height, common
     * coordinates).
     */

    if (pwPtr->orient == ORIENT_HORIZONTAL) {
	sashHeight = Tk_Height(tkwin) - (2 * Tk_InternalBorderWidth(tkwin));
	sashWidth = pwPtr->sashWidth;
    } else {
	sashWidth = Tk_Width(tkwin) - (2 * Tk_InternalBorderWidth(tkwin));
	sashHeight = pwPtr->sashWidth;
    }

    /*
     * Draw the sashes.
     */
    for (i = 0; i < pwPtr->numSlaves - 1; i++) {
	Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
		pwPtr->slaves[i]->sashx, pwPtr->slaves[i]->sashy,
		sashWidth, sashHeight, 1, pwPtr->sashRelief);

	if (pwPtr->showHandle) {
	    Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
		    pwPtr->slaves[i]->handlex, pwPtr->slaves[i]->handley,
		    pwPtr->handleSize, pwPtr->handleSize, 1,
		    TK_RELIEF_RAISED);
	}
    }
    
    /*
     * Copy the information from the off-screen pixmap onto the screen,
     * then delete the pixmap.
     */
    
    XCopyArea(Tk_Display(tkwin), pixmap, Tk_WindowId(tkwin), pwPtr->gc,
	    0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
	    0, 0);
    Tk_FreePixmap(Tk_Display(tkwin), pixmap);
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyPanedWindow --
 *
 *	This procedure is invoked by PanedWindowEventProc to free the
 *	internal structure of a paned window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the paned window is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyPanedWindow(pwPtr)
    PanedWindow *pwPtr;		/* Info about paned window widget. */
{
    int i;
    
    /*
     * First mark the widget as in the process of being deleted,
     * so that any code that causes calls to other paned window procedures
     * will abort.
     */

    pwPtr->flags |= WIDGET_DELETED;

    /*
     * Cancel idle callbacks for redrawing the widget and for rearranging
     * the panes.
     */
    if (pwPtr->flags & REDRAW_PENDING) {
	Tcl_CancelIdleCall(DisplayPanedWindow, (ClientData) pwPtr);
    }
    if (pwPtr->flags & RESIZE_PENDING) {
	Tcl_CancelIdleCall(ArrangePanes, (ClientData) pwPtr);
    }

    /*
     * Clean up the slave list; foreach slave:
     *  o  Cancel the slave's structure notification callback
     *  o  Cancel geometry management for the slave.
     *  o  Free memory for the slave
     */
    
    for (i = 0; i < pwPtr->numSlaves; i++) {
	Tk_DeleteEventHandler(pwPtr->slaves[i]->tkwin, StructureNotifyMask,
		SlaveStructureProc, (ClientData) pwPtr->slaves[i]);
	Tk_ManageGeometry(pwPtr->slaves[i]->tkwin, NULL, NULL);
	Tk_FreeConfigOptions((char *)pwPtr->slaves[i], pwPtr->slaveOpts,
		pwPtr->tkwin);
	ckfree((void *)pwPtr->slaves[i]);
	pwPtr->slaves[i] = NULL;
    }
    if (pwPtr->slaves) {
	ckfree((char *) pwPtr->slaves);
    }

    /*
     * Remove the widget command from the interpreter.
     */

    Tcl_DeleteCommandFromToken(pwPtr->interp, pwPtr->widgetCmd);

    /*
     * Let Tk_FreeConfigOptions clean up the rest.
     */

    Tk_FreeConfigOptions((char *) pwPtr, pwPtr->optionTable, pwPtr->tkwin);
    Tcl_Release((ClientData) pwPtr->tkwin);
    pwPtr->tkwin = NULL;

    Tcl_EventuallyFree((ClientData) pwPtr, TCL_DYNAMIC);
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowReqProc --
 *
 *	This procedure is invoked by Tk_GeometryRequest for
 *	windows managed by a paned window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Arranges for tkwin, and all its managed siblings, to
 *	be re-arranged at the next idle point.
 *
 *--------------------------------------------------------------
 */

static void
PanedWindowReqProc(clientData, tkwin)
    ClientData clientData;	/* Paned window's information about
				 * window that got new preferred
				 * geometry.  */
    Tk_Window tkwin;		/* Other Tk-related information
				 * about the window. */
{
    Slave *slavePtr = (Slave *) clientData;
    PanedWindow *pwPtr = (PanedWindow *) (slavePtr->masterPtr);
    if (Tk_IsMapped(pwPtr->tkwin)) {
	if (!(pwPtr->flags & RESIZE_PENDING)) {
	    pwPtr->flags |= RESIZE_PENDING;
	    Tcl_DoWhenIdle(ArrangePanes, (ClientData) pwPtr);
	}
    } else {
	int doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
	if (slavePtr->width <= 0) {
	    slavePtr->paneWidth = Tk_ReqWidth(slavePtr->tkwin) + doubleBw;
	}
	if (slavePtr->height <= 0) {
	    slavePtr->paneHeight = Tk_ReqHeight(slavePtr->tkwin) + doubleBw;
	}
	ComputeGeometry(pwPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowLostSlaveProc --
 *
 *	This procedure is invoked by Tk whenever some other geometry
 *	claims control over a slave that used to be managed by us.
 *