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 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
|
/* vibextra.c
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information (NCBI)
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government do not place any restriction on its use or reproduction.
* We would, however, appreciate having the NCBI and the author cited in
* any work or product based on this material
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* ===========================================================================
*
* File Name: vibextra.c
*
* Author: Jonathan Kans, Alex Smirnov
*
* Version Creation Date: 3/9/93
*
* $Revision: 6.3 $
*
* File Description:
* Vibrant miscellaneous extensions
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* ------- ---------- -----------------------------------------------------
*
*
* $Log: vibextra.c,v $
* Revision 6.3 2008/04/25 15:54:01 kans
* trivial changes for compatibility with MinGW cross-compiler - allows building Windows executable on Macintosh
*
* Revision 6.2 2001/03/19 19:15:17 juran
* Change "for (...);" to "for (...) ;" (added space before semicolon) to silence trying-to-be-helpful compiler warning.
*
* Revision 6.1 1997/11/26 21:30:14 vakatov
* Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
*
* Revision 6.0 1997/08/25 18:56:53 madden
* Revision changed to 6.0
*
* Revision 5.2 1996/10/28 19:33:47 vakatov
* [WIN_MOTIF] Use Nlm_VibrantDefaultColormap() instead of the display
* default colormap everywhere in the color handling code.
* Made a lot of type castings to get rid of all compiler warnings.
*
* Revision 5.1 1996/07/25 19:48:09 vakatov
* [WIN_X] Added #VOID_PIXEL to serve as the tmpColorPixel's void value
*
* Revision 5.0 1996/05/28 13:45:08 ostell
* Set to revision 5.0
*
* Revision 4.2 1996/04/24 21:20:45 vakatov
* Nlm_ChooseColorDialog(): Nlm_WaitForCondition() to wait for the modal
* dialog finishing
*
* Revision 4.1 1996/02/27 16:31:13 kans
* subclass folder tabs to allow SetValue (but with 0, not 1, as first value)
*
* Revision 4.0 1995/07/26 13:51:04 ostell
* force revision to 4.0
*
* Revision 1.20 1995/05/20 18:27:38 kans
* replaced ; accidentally removed when log message was added
*
* Revision 1.19 1995/05/17 15:15:14 kans
* added Log line
*
*
* ==========================================================================
*/
#include <vibtypes.h>
#include <vibprocs.h>
#include <vibincld.h>
#include <ncbiport.h>
#ifdef WIN_MSWIN
#include<commdlg.h>
/*
#include<colordlg.h>
*/
#endif
#ifdef VAR_ARGS
#include <varargs.h>
#else
#include <stdarg.h>
#endif
typedef struct Nlm_repeatdata {
Nlm_Handle title;
Nlm_RptClckProc action;
} Nlm_RepeatData;
typedef struct Nlm_switchdata {
Nlm_Int2 max;
Nlm_Int2 val;
Nlm_Boolean text;
Nlm_Boolean vert;
Nlm_Boolean upActv;
Nlm_Boolean dnActv;
Nlm_SwtChngProc actn;
} Nlm_SwitchData;
typedef struct Nlm_icondata {
Nlm_IcnChngProc inval;
Nlm_Int2 value;
Nlm_Boolean status;
Nlm_Handle title;
} Nlm_IconData;
static Nlm_GphPrcsPtr gphprcsptr = NULL;
static Nlm_GphPrcsPtr repeatProcs;
static Nlm_GphPrcsPtr switchProcs;
static Nlm_GphPrcsPtr iconProcs;
extern Nlm_GphPrcsPtr Nlm_folderTabProcs;
Nlm_GphPrcsPtr Nlm_folderTabProcs = NULL;
static Nlm_Boolean inRepeatButton;
static Nlm_Uint1 upFillArrow [] = {
0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00
};
static Nlm_Uint1 downFillArrow [] = {
0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00
};
static Nlm_Uint1 leftFillArrow [] = {
0x06, 0x1E, 0x7E, 0xFE, 0x7E, 0x1E, 0x06, 0x00
};
static Nlm_Uint1 rightFillArrow [] = {
0xC0, 0xF0, 0xFC, 0xFE, 0xFC, 0xF0, 0xC0, 0x00
};
static Nlm_Uint1 upOpenArrow [] = {
0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0xFE, 0x00
};
static Nlm_Uint1 downOpenArrow [] = {
0xFE, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x00
};
static Nlm_Uint1 leftOpenArrow [] = {
0x06, 0x1A, 0x62, 0x82, 0x62, 0x1A, 0x06, 0x00
};
static Nlm_Uint1 rightOpenArrow [] = {
0xC0, 0xB0, 0x8C, 0x82, 0x8C, 0xB0, 0xC0, 0x00
};
#ifdef VAR_ARGS
extern void CDECL Nlm_AlignObjects (align, va_alist)
int align;
va_dcl
#else
extern void CDECL Nlm_AlignObjects (int align, ...)
#endif
{
va_list args;
Nlm_Int2 delta;
Nlm_Int2 maxX;
Nlm_Int2 maxY;
Nlm_Int2 minX;
Nlm_Int2 minY;
Nlm_Handle obj;
Nlm_RecT r;
#ifdef VAR_ARGS
va_start (args);
#else
va_start (args, align);
#endif
minX = 0;
minY = 0;
maxX = 0;
maxY = 0;
obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
while (obj != NULL) {
Nlm_GetPosition (obj, &r);
minX = MAX (minX, r.left);
minY = MAX (minY, r.top);
maxX = MAX (maxX, r.right);
maxY = MAX (maxY, r.bottom);
obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
}
va_end(args);
#ifdef VAR_ARGS
va_start (args);
#else
va_start (args, align);
#endif
obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
while (obj != NULL) {
Nlm_GetPosition (obj, &r);
switch (align) {
case ALIGN_LEFT:
if (r.left < minX) {
r.left = minX;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_RIGHT:
if (r.right < maxX) {
r.right = maxX;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_CENTER:
delta = maxX - r.right;
if (delta > 0) {
Nlm_OffsetRect (&r, (Nlm_Int2)(delta/2), 0);
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_JUSTIFY:
if (r.left < minX || r.right < maxX) {
r.left = minX;
r.right = maxX;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_UPPER:
if (r.top < minY) {
r.top = minY;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_LOWER:
if (r.bottom < maxY) {
r.bottom = maxY;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_MIDDLE:
delta = maxY - r.bottom;
if (delta > 0) {
Nlm_OffsetRect (&r, 0, (Nlm_Int2)(delta/2));
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
case ALIGN_VERTICAL:
if (r.top < minY || r.bottom < maxY) {
r.top = minY;
r.bottom = maxY;
Nlm_SetPosition (obj, &r);
Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
}
break;
default:
break;
}
obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
}
va_end(args);
}
static void Nlm_DrawSwitchProc (Nlm_PaneL s)
{
Nlm_RecT dn;
Nlm_SwitchData extra;
Nlm_Int2 mid;
Nlm_RecT r;
Nlm_Char str [32];
Nlm_RecT tx;
Nlm_RecT up;
Nlm_GetPanelExtra (s, &extra);
Nlm_ObjectRect (s, &r);
if (extra.text && extra.max > 0 && extra.val > 0) {
sprintf (str, "%d/%d", (int) extra.val, (int) extra.max);
Nlm_SelectFont (Nlm_programFont);
if (extra.vert) {
Nlm_LoadRect (&tx, (Nlm_Int2)(r.left + 1), (Nlm_Int2)(r.top + 1),
(Nlm_Int2)(r.right - 11), (Nlm_Int2)(r.bottom - 1));
} else {
Nlm_LoadRect (&tx, (Nlm_Int2)(r.left + 1), (Nlm_Int2)(r.top + 1),
(Nlm_Int2)(r.right - 20), (Nlm_Int2)(r.bottom - 1));
}
Nlm_DrawString (&tx, str, 'r', FALSE);
Nlm_SelectFont (Nlm_systemFont);
}
Nlm_FrameRect (&r);
if (extra.vert) {
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
if (extra.upActv) {
Nlm_CopyBits (&up, upFillArrow);
} else {
Nlm_CopyBits (&up, upOpenArrow);
}
} else {
mid = (r.top + r.bottom) / 2;
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
if (extra.upActv) {
Nlm_CopyBits (&up, rightFillArrow);
} else {
Nlm_CopyBits (&up, rightOpenArrow);
}
}
if (extra.vert) {
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
if (extra.dnActv) {
Nlm_CopyBits (&dn, downFillArrow);
} else {
Nlm_CopyBits (&dn, downOpenArrow);
}
} else {
mid = (r.top + r.bottom) / 2;
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
if (extra.dnActv) {
Nlm_CopyBits (&dn, leftFillArrow);
} else {
Nlm_CopyBits (&dn, leftOpenArrow);
}
}
}
static void Nlm_SwitchClickProc (Nlm_PaneL s, Nlm_PoinT pt)
{
Nlm_RecT dn;
Nlm_SwitchData extra;
Nlm_Int2 mid;
Nlm_RecT r;
Nlm_RecT up;
Nlm_GetPanelExtra (s, &extra);
Nlm_ObjectRect (s, &r);
if (extra.vert) {
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
} else {
mid = (r.top + r.bottom) / 2;
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
}
if (Nlm_PtInRect (pt, &up)) {
if (extra.val < extra.max) {
Nlm_DoSetValue ((Nlm_GraphiC) s, (Nlm_Int2)(extra.val + 1), FALSE);
if (extra.actn != NULL) {
extra.actn ((Nlm_SwitcH) s, (Nlm_Int2)(extra.val + 1), extra.val);
}
}
} else if (Nlm_PtInRect (pt, &dn)) {
if (extra.val > 1) {
Nlm_DoSetValue ((Nlm_GraphiC) s, (Nlm_Int2)(extra.val - 1), FALSE);
if (extra.actn != NULL) {
extra.actn ((Nlm_SwitcH) s, (Nlm_Int2)(extra.val - 1), extra.val);
}
}
}
}
static Nlm_SwitcH Nlm_CommonSwitch (Nlm_GrouP prnt, Nlm_Boolean text,
Nlm_Boolean vert, Nlm_SwtChngProc actn)
{
Nlm_SwitchData extra;
Nlm_Int2 height;
Nlm_PaneL s;
Nlm_Int2 width;
s = NULL;
if (prnt != NULL) {
Nlm_SelectFont (Nlm_programFont);
if (vert) {
height = 20;
width = 11;
} else {
height = 11;
width = 20;
}
if (text) {
width += Nlm_StringWidth ("99/99") + 4;
height = MAX (height, Nlm_LineHeight () + 2);
}
Nlm_SelectFont (Nlm_systemFont);
s = Nlm_AutonomousPanel (prnt, width, height, Nlm_DrawSwitchProc, NULL,
NULL, sizeof (Nlm_SwitchData), NULL, switchProcs);
if (s != NULL) {
Nlm_SetPanelClick (s, Nlm_SwitchClickProc, NULL, NULL, NULL);
Nlm_MemSet ((Nlm_VoidPtr) (&extra), 0, sizeof (Nlm_SwitchData));
extra.max = 0;
extra.val = 0;
extra.text = text;
extra.vert = vert;
extra.upActv = FALSE;
extra.dnActv = FALSE;
extra.actn = actn;
Nlm_SetPanelExtra (s, &extra);
}
}
return (Nlm_SwitcH) s;
}
extern Nlm_SwitcH Nlm_UpDownSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
{
return Nlm_CommonSwitch (prnt, text, TRUE, actn);
}
extern Nlm_SwitcH Nlm_LeftRightSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
{
return Nlm_CommonSwitch (prnt, text, FALSE, actn);
}
static void Nlm_UpdateSwitch (Nlm_SwitcH s)
{
Nlm_RecT dn;
Nlm_SwitchData extra;
Nlm_Int2 mid;
Nlm_RecT r;
Nlm_RecT tx;
Nlm_RecT up;
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
if (Nlm_Visible (s) && Nlm_AllParentsVisible (s)) {
Nlm_ObjectRect (s, &r);
if (extra.vert) {
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.top + 2),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.top + 9));
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(r.bottom - 9),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(r.bottom - 2));
} else {
mid = (r.top + r.bottom) / 2;
Nlm_LoadRect (&up, (Nlm_Int2)(r.right - 9), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 2), (Nlm_Int2)(mid + 4));
Nlm_LoadRect (&dn, (Nlm_Int2)(r.right - 18), (Nlm_Int2)(mid - 3),
(Nlm_Int2)(r.right - 11), (Nlm_Int2)(mid + 4));
}
Nlm_Select (s);
if (extra.upActv != (Nlm_Boolean) (extra.val < extra.max)) {
Nlm_InsetRect (&up, -1, -1);
Nlm_InvalRect (&up);
}
if (extra.dnActv != (Nlm_Boolean) (extra.val > 1)) {
Nlm_InsetRect (&dn, -1, -1);
Nlm_InvalRect (&dn);
}
if (extra.text) {
if (extra.vert) {
Nlm_LoadRect (&tx, (Nlm_Int2)(r.left + 1), (Nlm_Int2)(r.top + 1),
(Nlm_Int2)(r.right - 10), (Nlm_Int2)(r.bottom - 1));
} else {
Nlm_LoadRect (&tx, (Nlm_Int2)(r.left + 1), (Nlm_Int2)(r.top + 1),
(Nlm_Int2)(r.right - 19), (Nlm_Int2)(r.bottom - 1));
}
Nlm_InvalRect (&tx);
}
}
extra.upActv = (Nlm_Boolean) (extra.val < extra.max);
extra.dnActv = (Nlm_Boolean) (extra.val > 1);
Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
}
static void Nlm_SetSwitchValue (Nlm_GraphiC s, Nlm_Int2 value, Nlm_Boolean savePort)
{
Nlm_SwitchData extra;
Nlm_Int2 oldval;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePortIfNeeded (s, savePort);
if (s != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
oldval = extra.val;
extra.val = value;
Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
if (oldval != value) {
Nlm_UpdateSwitch ((Nlm_SwitcH) s);
}
}
Nlm_RestorePort (tempPort);
}
static Nlm_Int2 Nlm_GetSwitchValue (Nlm_GraphiC s)
{
Nlm_SwitchData extra;
Nlm_Int2 value;
value = 0;
if (s != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
value = extra.val;
}
return value;
}
extern void Nlm_SetSwitchMax (Nlm_SwitcH s, Nlm_Int2 max)
{
Nlm_SwitchData extra;
Nlm_Int2 oldmax;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePort (s);
if (s != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
oldmax = extra.max;
extra.max = max;
if (max == 0) {
extra.val = 0;
}
Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
if (oldmax != max) {
Nlm_UpdateSwitch (s);
}
}
Nlm_RestorePort (tempPort);
}
extern Nlm_Int2 Nlm_GetSwitchMax (Nlm_SwitcH s)
{
Nlm_SwitchData extra;
Nlm_Int2 max;
max = 0;
if (s != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
max = extra.max;
}
return max;
}
extern void Nlm_SetSwitchParams (Nlm_SwitcH s, Nlm_Int2 value, Nlm_Int2 max)
{
Nlm_SwitchData extra;
Nlm_Int2 oldmax;
Nlm_Int2 oldval;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePort (s);
if (s != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
oldmax = extra.max;
extra.max = max;
if (value > max) {
value = max;
}
oldval = extra.val;
extra.val = value;
Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
if (oldval != value || oldmax != max) {
Nlm_UpdateSwitch (s);
}
}
Nlm_RestorePort (tempPort);
}
static void Nlm_DoRepeatAction (Nlm_RepeaT rb, Nlm_PoinT pt)
{
Nlm_RptClckProc actn;
Nlm_RepeatData rdata;
Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
actn = rdata.action;
if (actn != NULL) {
actn (rb, pt);
}
}
static void Nlm_RepeatClick (Nlm_PaneL rb, Nlm_PoinT pt)
{
Nlm_RecT r;
Nlm_GetRect ((Nlm_GraphiC) rb, &r);
if (Nlm_PtInRect (pt, &r)) {
inRepeatButton = TRUE;
Nlm_InsetRect (&r, 2, 2);
Nlm_InvertRect (&r);
Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
}
}
static void Nlm_RepeatPress (Nlm_PaneL rb, Nlm_PoinT pt)
{
Nlm_RecT r;
Nlm_GetRect ((Nlm_GraphiC) rb, &r);
if (Nlm_PtInRect (pt, &r)) {
if (! inRepeatButton) {
inRepeatButton = TRUE;
Nlm_InsetRect (&r, 2, 2);
Nlm_InvertRect (&r);
}
Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
} else if (inRepeatButton) {
inRepeatButton = FALSE;
Nlm_InsetRect (&r, 2, 2);
Nlm_InvertRect (&r);
}
}
static void Nlm_RepeatRelease (Nlm_PaneL rb, Nlm_PoinT pt)
{
Nlm_RecT r;
Nlm_GetRect ((Nlm_GraphiC) rb, &r);
if (inRepeatButton) {
inRepeatButton = FALSE;
Nlm_InsetRect (&r, 2, 2);
Nlm_InvertRect (&r);
}
}
static void Nlm_DrawRepeat (Nlm_PaneL rb)
{
Nlm_Handle h;
Nlm_RecT r;
Nlm_RepeatData rdata;
Nlm_Char str [64];
if (Nlm_GetVisible ((Nlm_GraphiC) rb) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) rb)) {
Nlm_GetRect ((Nlm_GraphiC) rb, &r);
Nlm_FrameRect (&r);
Nlm_InsetRect (&r, 1, 1);
Nlm_FrameRect (&r);
Nlm_InsetRect (&r, 1, 1);
Nlm_GetPanelExtra (rb, &rdata);
h = rdata.title;
if (h != NULL) {
Nlm_SelectFont (Nlm_systemFont);
Nlm_GetString (h, str, sizeof (str));
if (Nlm_StringLen (str) > 0) {
Nlm_DrawString (&r, str, 'c', FALSE);
}
}
}
}
static void Nlm_SetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
Nlm_CharPtr title, Nlm_Boolean savePort)
{
Nlm_Handle h;
Nlm_RecT r;
Nlm_RepeatData rdata;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePortIfNeeded (rb, savePort);
Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
h = rdata.title;
h = Nlm_SetString (h, title);
rdata.title = h;
Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
if (Nlm_GetVisible (rb) && Nlm_GetAllParentsVisible (rb)) {
Nlm_GetRect (rb, &r);
Nlm_InvalRect (&r);
}
Nlm_RestorePort (tempPort);
}
static void Nlm_GetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
Nlm_CharPtr title, size_t maxsize)
{
Nlm_Handle h;
Nlm_RepeatData rdata;
if (title != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
h = rdata.title;
Nlm_GetString (h, title, maxsize);
}
}
static void Nlm_ResetRepeat (Nlm_PaneL rb)
{
Nlm_RepeatData rdata;
Nlm_GetPanelExtra (rb, &rdata);
if (rdata.title != NULL) {
rdata.title = Nlm_HandFree (rdata.title);
}
Nlm_SetPanelExtra (rb, &rdata);
}
extern Nlm_RepeaT Nlm_RepeatButton (Nlm_GrouP prnt, Nlm_CharPtr title,
Nlm_RptClckProc actn)
{
Nlm_RepeaT rb;
Nlm_RepeatData rdata;
Nlm_Int2 vbounds;
Nlm_Int2 width;
rb = NULL;
if (prnt != NULL) {
Nlm_SelectFont (Nlm_systemFont);
width = Nlm_StringWidth (title);
#ifdef WIN_MAC
vbounds = 2;
#endif
#ifdef WIN_MSWIN
vbounds = 4;
#endif
#ifdef WIN_MOTIF
vbounds = 2;
#endif
rb = (Nlm_RepeaT) Nlm_AutonomousPanel (prnt,
(Nlm_Int2)(width + 8), (Nlm_Int2)(Nlm_stdLineHeight + vbounds*2),
Nlm_DrawRepeat, NULL, NULL,
sizeof (Nlm_RepeatData), Nlm_ResetRepeat, repeatProcs);
if (rb != NULL) {
Nlm_SetPanelClick ((Nlm_PaneL) rb, Nlm_RepeatClick, NULL,
Nlm_RepeatPress, Nlm_RepeatRelease);
rdata.title = NULL;
rdata.action = actn;
Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
Nlm_SetRepeatTitle ((Nlm_GraphiC) rb, 0, title, FALSE);
}
}
return rb;
}
static void Nlm_SetIconValue (Nlm_GraphiC i, Nlm_Int2 value, Nlm_Boolean savePort)
{
Nlm_IconData extra;
Nlm_Int2 oldval;
Nlm_RecT r;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePortIfNeeded (i, savePort);
if (i != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
oldval = extra.value;
extra.value = value;
Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
if (oldval != value) {
if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
Nlm_Select (i);
if (extra.inval != NULL) {
extra.inval ((Nlm_IcoN) i, value, oldval);
} else {
Nlm_ObjectRect (i, &r);
Nlm_InsetRect (&r, -1, -1);
Nlm_InvalRect (&r);
}
}
}
}
Nlm_RestorePort (tempPort);
}
static Nlm_Int2 Nlm_GetIconValue (Nlm_GraphiC i)
{
Nlm_IconData extra;
Nlm_Int2 value;
value = 0;
if (i != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
value = extra.value;
}
return value;
}
static void Nlm_SetIconStatus (Nlm_GraphiC i, Nlm_Int2 item,
Nlm_Boolean set, Nlm_Boolean savePort)
{
Nlm_IconData extra;
Nlm_Boolean oldstat;
Nlm_RecT r;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePortIfNeeded (i, savePort);
if (i != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
oldstat = extra.status;
extra.status = set;
Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
if (oldstat != set) {
if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
Nlm_Select (i);
if (extra.inval != NULL) {
extra.inval ((Nlm_IcoN) i, extra.value, extra.value);
} else {
Nlm_ObjectRect (i, &r);
Nlm_InsetRect (&r, -1, -1);
Nlm_InvalRect (&r);
}
}
}
}
Nlm_RestorePort (tempPort);
}
static Nlm_Boolean Nlm_GetIconStatus (Nlm_GraphiC i, Nlm_Int2 item)
{
Nlm_IconData extra;
Nlm_Boolean status;
status = 0;
if (i != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
status = extra.status;
}
return status;
}
static void Nlm_SetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
Nlm_CharPtr title, Nlm_Boolean savePort)
{
Nlm_IconData extra;
Nlm_Handle h;
Nlm_RecT r;
Nlm_WindoW tempPort;
tempPort = Nlm_SavePortIfNeeded (i, savePort);
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
h = extra.title;
h = Nlm_SetString (h, title);
extra.title = h;
Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
if (Nlm_GetVisible (i) && Nlm_GetAllParentsVisible (i)) {
Nlm_GetRect (i, &r);
Nlm_InvalRect (&r);
}
Nlm_RestorePort (tempPort);
}
static void Nlm_GetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
Nlm_CharPtr title, size_t maxsize)
{
Nlm_IconData extra;
Nlm_Handle h;
if (title != NULL) {
Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
h = extra.title;
Nlm_GetString (h, title, maxsize);
}
}
static void Nlm_ResetIcon (Nlm_PaneL i)
{
Nlm_IconData extra;
Nlm_GetPanelExtra (i, &extra);
if (extra.title != NULL) {
extra.title = Nlm_HandFree (extra.title);
}
Nlm_SetPanelExtra (i, &extra);
}
extern Nlm_IcoN Nlm_IconButton (Nlm_GrouP prnt, Nlm_Int2 pixwidth, Nlm_Int2 pixheight,
Nlm_IcnActnProc draw, Nlm_IcnChngProc inval,
Nlm_IcnClckProc click, Nlm_IcnClckProc drag,
Nlm_IcnClckProc hold, Nlm_IcnClckProc release)
{
Nlm_IcoN ic;
Nlm_IconData idata;
ic = NULL;
if (prnt != NULL) {
Nlm_SelectFont (Nlm_systemFont);
ic = (Nlm_IcoN) Nlm_AutonomousPanel (prnt, pixwidth, pixheight,
(Nlm_PnlActnProc) draw, NULL, NULL,
sizeof (Nlm_IconData), Nlm_ResetIcon,
iconProcs);
if (ic != NULL) {
Nlm_SetPanelClick ((Nlm_PaneL) ic, (Nlm_PnlClckProc) click, (Nlm_PnlClckProc) drag,
(Nlm_PnlClckProc) hold, (Nlm_PnlClckProc) release);
idata.inval = inval;
idata.value = 0;
idata.status = FALSE;
idata.title = NULL;
Nlm_SetPanelExtra ((Nlm_PaneL) ic, &idata);
}
}
return ic;
}
extern void Nlm_SetFolderTabValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort);
extern void Nlm_SetFolderTabSubclass (Nlm_GrouP g);
extern void Nlm_SetFolderTabSubclass (Nlm_GrouP g)
{
Nlm_GraphicData gdata;
if (Nlm_folderTabProcs != NULL) {
Nlm_folderTabProcs->setValue = Nlm_SetFolderTabValue;
Nlm_GetGraphicData ((Nlm_GraphiC) g, &gdata);
Nlm_folderTabProcs->ancestor = gdata.classptr;
gdata.classptr = Nlm_folderTabProcs;
Nlm_SetGraphicData ((Nlm_GraphiC) g, &gdata);
}
}
extern void Nlm_FreeExtras (void)
{
gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
}
extern void Nlm_InitExtras (void)
{
gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 4);
repeatProcs = &(gphprcsptr [0]);
repeatProcs->setTitle = Nlm_SetRepeatTitle;
repeatProcs->getTitle = Nlm_GetRepeatTitle;
switchProcs = &(gphprcsptr [1]);
switchProcs->setValue = Nlm_SetSwitchValue;
switchProcs->getValue = Nlm_GetSwitchValue;
iconProcs = &(gphprcsptr [2]);
iconProcs->setValue = Nlm_SetIconValue;
iconProcs->getValue = Nlm_GetIconValue;
iconProcs->setStatus = Nlm_SetIconStatus;
iconProcs->getStatus = Nlm_GetIconStatus;
iconProcs->setTitle = Nlm_SetIconTitle;
iconProcs->getTitle = Nlm_GetIconTitle;
Nlm_folderTabProcs = &(gphprcsptr [3]);
}
/* ---------------------- Start ------------------------- */
/* --------------------MS-Windows------------------------ */
#ifdef WIN_MSWIN
extern HWND Nlm_currentHWnd;
static DWORD win_CustomColors[16];
extern Nlm_Boolean Nlm_ChooseColorDialog (
Nlm_Uint1 PNTR redptr,
Nlm_Uint1 PNTR greenptr,
Nlm_Uint1 PNTR blueptr,
Nlm_Boolean Initial ){
CHOOSECOLOR chc;
Nlm_Boolean res;
chc.lStructSize = sizeof (CHOOSECOLOR);
chc.hwndOwner = Nlm_currentHWnd;
chc.lpCustColors = win_CustomColors;
chc.Flags = CC_FULLOPEN;
if ( Initial ) {
chc.Flags |= CC_RGBINIT;
chc.rgbResult = RGB ( *redptr, *greenptr, *blueptr );
}
res = (Nlm_Boolean)ChooseColor ( &chc );
if ( res ){
if ( redptr != NULL ) *redptr = GetRValue (chc.rgbResult);
if ( greenptr != NULL ) *greenptr = GetGValue (chc.rgbResult);
if ( blueptr != NULL ) *blueptr = GetBValue (chc.rgbResult);
}
return res;
}
/* ---------------------End MS-Windows--------------------- */
#else
/* --------------------- Non MS-Window -------------------- */
/* --------------------- Defines -------------------------- */
/* Sizes */
#define NLM_CHCOLOR_BOXW 26
#define NLM_CHCOLOR_BOXH 20
#define NLM_CHCOLOR_SHLW 180
#define NLM_CHCOLOR_SHLH 20
#define NLM_CHCOLOR_PTRH 10
#define NLM_CHCOLOR_PTRW 16
#define NLM_CHCOLOR_PTRW2 8
#define NLM_CHCOLOR_EXW 160
#define NLM_CHCOLOR_EXH 40
/* Owners */
#define NLM_CHCOLOR_OBC 0
#define NLM_CHCOLOR_OCC 1
#define NLM_CHCOLOR_OSP 2
#define NLM_CHCOLOR_OST 3
#define NLM_CHCOLOR_OHP 4
#define NLM_CHCOLOR_OHT 5
#define NLM_CHCOLOR_OLP 6
#define NLM_CHCOLOR_OLT 7
#define NLM_CHCOLOR_ORT 8
#define NLM_CHCOLOR_OGT 9
#define NLM_CHCOLOR_OBT 10
/* --------------------- Typedefs ------------------------- */
typedef struct {
Nlm_Uint1 red;
Nlm_Uint1 green;
Nlm_Uint1 blue;
} NLMINTERNALCOLOR;
/* -------------------Global variable---------------------- */
#ifdef WIN_X
extern Display *Nlm_currentXDisplay;
extern int Nlm_currentXScreen;
extern Window Nlm_currentXWindow;
extern GC Nlm_currentXGC;
extern Nlm_Uint4 Nlm_XbackColor;
extern Nlm_Uint4 Nlm_XforeColor;
extern Nlm_Int2 Nlm_XOffset;
extern Nlm_Int2 Nlm_YOffset;
extern Nlm_RegioN Nlm_clpRgn;
extern Nlm_Boolean Nlm_hasColor;
#endif
/* -------------------Static variable---------------------- */
static Nlm_Boolean colorDlgUp;
static Nlm_Boolean colorDlgOK;
static Nlm_PaneL pBasicColor;
static Nlm_PaneL pCustomColor;
static Nlm_PaneL pSColor;
static Nlm_PaneL pSPtrColor;
static Nlm_PaneL pHColor;
static Nlm_PaneL pHPtrColor;
static Nlm_PaneL pLColor;
static Nlm_PaneL pLPtrColor;
static Nlm_PaneL pRetColor;
static Nlm_TexT tColorRed;
static Nlm_TexT tColorGreen;
static Nlm_TexT tColorBlue;
static Nlm_TexT tColorHue;
static Nlm_TexT tColorSat;
static Nlm_TexT tColorLum;
static Nlm_Int2 stColorRGB[3];
static Nlm_Int2 stColorHSL[3];
static Nlm_Int2 stColorCurCustom;
static Nlm_Int2 stColorModel;
#ifdef WIN_X
#define VOID_PIXEL ((unsigned long)(-1))
static unsigned long tmpColorPixel = VOID_PIXEL;
#endif
static NLMINTERNALCOLOR theCustomColors[16];
static NLMINTERNALCOLOR theBasicColors[48] = {
{255,128,128},{255,255,232},{128,255,128},{0,255,128},
{128,255,255},{0,128,255}, {255,128,192},{255,128,255},
{255,0,0}, {255,255,128},{128,255,0}, {0,255,64},
{0,255,255}, {0,128,192}, {128,128,192},{255,0,255},
{128,64,64}, {255,255,0}, {0,255,0}, {0,128,128},
{0,64,128}, {128,128,255},{128,0,64}, {255,0,128},
{128,0,0}, {255,128,0}, {0,128,0}, {0,128,64},
{0,0,255}, {0,0,160}, {128,0,128}, {128,0,255},
{64,0,0}, {128,64,0}, {0,64,0}, {0,64,64,},
{0,0,128}, {0,0,64}, {64,0,64}, {64,0,128},
{0,0,0}, {128,128,0}, {128,128,64}, {128,128,128},
{64,128,128}, {192,192,192},{130,130,130},{255,255,255} };
static Nlm_Uint1 thePointer[] = { /*16 X 10*/
0x01, 0x80, 0x03, 0xC0, 0x07, 0xE0,
0x0F, 0xF0, 0x1F, 0xF8, 0x3F, 0xFC,
0x7F, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF };
/* ----------------Utility functions ---------------------- */
static void Nlm_SafeSetTitleExtra (Nlm_Handle a, Nlm_CharPtr title)
{
Nlm_Char str [256];
Nlm_GetTitle (a, str, sizeof (str));
if (Nlm_StringCmp (title, str) != 0) {
Nlm_SetTitle (a, title);
}
}
static int Nlm_GetColorVal ( Nlm_TexT t ) {
Nlm_Char cValue[64];
Nlm_Char PNTR cValuePtr;
int iValue = -1;
int update = 0;
Nlm_GetTitle( t, cValue, 64 );
cValue[63] = 0;
for ( cValuePtr = cValue; IS_DIGIT(*cValuePtr); cValuePtr++ ) ;
if ( *cValuePtr != '\0' ) {
*cValuePtr = 0;
update = 1;
}
sscanf ( cValue, "%d", &iValue );
if ( iValue <= 0 ) {
iValue = 0;
update = 2;
}
if ( iValue > 255 ) {
iValue = 255 ;
update = 1;
}
if ( update ==2 ){
Nlm_SetTitle ( t, "" );
} else if ( update ) {
sprintf ( cValue, "%d", iValue );
Nlm_SafeSetTitleExtra ( t, cValue );
}
return iValue;
}
static void Nlm_HSL2RGB ( Nlm_Int2 PNTR rgb, Nlm_Int2 PNTR hsl ){
int i, min;
double maxVal, minVal;
double sumDoub, difDoub;
/* S = (maxRGB-minRGB)/(maxRGB+minRGB)*256 */
/* L = (maxRGB+minRGB)/2 */
/* H = (maxRGB-minRGB)/(maxRGB+midRGB-2*minRGB)*(256/3) + C */
sumDoub = (double)hsl[2] * 2;
difDoub = (double)hsl[1] * sumDoub / 256.0;
maxVal = (sumDoub + difDoub) / 2.0;
if ( maxVal > 255 ) maxVal = 255;
minVal = sumDoub - maxVal;
if ( (double)hsl[0] > (256.0*2.0/3.0) ) {
min = 1; difDoub = (double)hsl[0] - (256.0*2.0/3.0);
} else if ( (double)hsl[0] > (256.0*1.0/3.0) ){
min = 0; difDoub = (double)hsl[0] - (256.0*1.0/3.0);
} else {
min = 2; difDoub = (double)hsl[0];
}
rgb[min] = (Nlm_Int2)minVal;
difDoub *= 3.0/256.0;
if ( difDoub < 0.5 ){
i = min + 1; if ( i > 2 ) i=0;
rgb[i] = (Nlm_Int2)maxVal;
i++; if ( i > 2 ) i=0;
difDoub = 1.0 - difDoub;
}else{
i = min - 1; if ( i < 0 ) i=2;
rgb[i] = (Nlm_Int2)maxVal;
i --; if ( i < 0 ) i=2;
}
if ( (maxVal-minVal) < 1.0E-12 ) {
rgb[i] = (Nlm_Int2)minVal;
} else {
rgb[i] = (Nlm_Int2)((maxVal-minVal)/difDoub - maxVal + 2*minVal);
}
}
static void Nlm_RGB2HSL ( Nlm_Int2 PNTR hsl, Nlm_Int2 PNTR rgb ){
int i, min;
double maxVal, minVal;
double sumDoub, difDoub;
/* S = (maxRGB-minRGB)/(maxRGB+minRGB)*256 */
/* L = (maxRGB+minRGB)/2 */
/* H = (maxRGB-minRGB)/(maxRGB+midRGB-2*minRGB)*(256/3) + C */
maxVal = -1;
minVal = 256;
for ( i=0; i<3; i++ ){
if ( rgb[i] < minVal ) {
minVal = (double)rgb[i];
min = i;
}
if ( rgb[i] > maxVal ) maxVal = (double)rgb[i];
}
sumDoub = minVal + maxVal;
difDoub = maxVal - minVal;
if ( sumDoub < 1.0E-10 ) hsl[1] = 255;
else hsl[1] = (Nlm_Int2)( difDoub * 256.0/sumDoub );
if ( hsl[1] > 255 ) hsl[1] = 255;
hsl[2] = (Nlm_Int2)(sumDoub/ 2.0);
if ( hsl[2] > 255 ) hsl[2] = 255;
if ( (rgb[0] == rgb[1]) && (rgb[0] == rgb[2]) ) hsl[0] = 0;
else {
i = (min + 1); if ( i > 2 ) i=0;
difDoub = (double)rgb[i] - minVal;
sumDoub = (double)rgb[i];
i++; if ( i > 2 ) i=0;
sumDoub += (double)rgb[i] - 2*minVal;
i = min + 1; if ( i > 2 ) i=0;
hsl[0] = (Nlm_Int2)( 256.0/3.0 *((double)i + (1.0-difDoub/sumDoub)) );
hsl[0] += 1;
if ( hsl[0] > 255 ) hsl[0] = 0;
}
}
static void Nlm_UpdColorPanel ( Nlm_PaneL p ){
Nlm_RecT rp;
Nlm_WindoW tmpPort;
tmpPort = Nlm_SavePort (p);
Nlm_ObjectRect (p, &rp);
Nlm_Select (p);
Nlm_InvalRect ( &rp );
Nlm_RestorePort (tmpPort);
}
static void Nlm_UpdColorText ( Nlm_TexT t, Nlm_Int2 iVal ){
Nlm_Char cValue[64];
sprintf ( cValue, "%d", iVal );
Nlm_SafeSetTitleExtra ( t, cValue );
}
static void Nlm_DrawColorPtr ( Nlm_Int2 x, Nlm_Int2 y ){
Nlm_RecT r;
Nlm_LoadRect ( &r, x-NLM_CHCOLOR_PTRW2, y,
x+NLM_CHCOLOR_PTRW2, y+NLM_CHCOLOR_PTRH );
Nlm_CopyBits ( &r, (Nlm_VoidPtr)thePointer );
}
/* -------------------Draw functions ---------------------- */
static void Nlm_BasicColorDraw ( Nlm_PaneL p ){
int x, y, xx, yy;
Nlm_RecT rp;
Nlm_RecT rdraw;
Nlm_ObjectRect (pBasicColor, &rp);
for ( y=0; y<6; y++ ){
for ( x=0; x<8; x++ ){
xx = rp.left + x*NLM_CHCOLOR_BOXW;
yy = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, xx + 2, yy + 2,
xx + NLM_CHCOLOR_BOXW - 2, yy + NLM_CHCOLOR_BOXH - 2 );
Nlm_FrameRect ( &rdraw );
}
}
for ( y=0; y<6; y++ ){
for ( x=0; x<8; x++ ){
xx = rp.left + x*NLM_CHCOLOR_BOXW;
yy = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, xx + 3, yy + 3,
xx + NLM_CHCOLOR_BOXW - 3, yy + NLM_CHCOLOR_BOXH - 3 );
Nlm_SelectColor ( theBasicColors[y*8+x].red,
theBasicColors[y*8+x].green,
theBasicColors[y*8+x].blue );
Nlm_PaintRect ( &rdraw );
}
}
}
static void Nlm_CustomColorDraw ( Nlm_PaneL p ){
int x,y,xx,yy;
Nlm_RecT rp;
Nlm_RecT rdraw;
Nlm_ObjectRect (pCustomColor, &rp);
if ( p != NULL ){
y = stColorCurCustom / 8;
x = stColorCurCustom - y*8;
xx = rp.left + x*NLM_CHCOLOR_BOXW;
yy = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, xx, yy,
xx + NLM_CHCOLOR_BOXW, yy + NLM_CHCOLOR_BOXH );
Nlm_InvertMode();
Nlm_FrameRect ( &rdraw );
Nlm_CopyMode();
}
for ( x=0; x<8; x++ ){
for ( y=0; y<2; y++ ){
xx = rp.left + x*NLM_CHCOLOR_BOXW;
yy = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, xx + 2, yy + 2,
xx + NLM_CHCOLOR_BOXW - 2, yy + NLM_CHCOLOR_BOXH - 2 );
Nlm_FrameRect ( &rdraw );
}
}
for ( x=0; x<8; x++ ){
for ( y=0; y<2; y++ ){
xx = rp.left + x*NLM_CHCOLOR_BOXW;
yy = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, xx + 3, yy + 3,
xx + NLM_CHCOLOR_BOXW - 3, yy + NLM_CHCOLOR_BOXH - 3 );
Nlm_SelectColor ( theCustomColors[y*8+x].red,
theCustomColors[y*8+x].green,
theCustomColors[y*8+x].blue );
Nlm_PaintRect ( &rdraw );
}
}
}
static void Nlm_HColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
int i;
int x0, y0, xcur;
Nlm_ObjectRect (pHColor, &rp);
rp.left += NLM_CHCOLOR_PTRW2;
rp.right -= NLM_CHCOLOR_PTRW2;
Nlm_FrameRect ( &rp );
x0 = xcur = rp.left + 1;
y0 = rp.top + 1;
if ( stColorModel == 1 ) {
for ( i=0; i<6; i++ ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+1))/18, y0+NLM_CHCOLOR_SHLH-2);
Nlm_SelectColor ( (Nlm_Uint1)(255-(i*255)/6),
(Nlm_Uint1)((i*255)/6), 0 );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/18;
Nlm_PaintRect ( &rp );
}
for ( i=0; i<6; i++ ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+7))/18, y0+NLM_CHCOLOR_SHLH-2);
Nlm_SelectColor ( 0, (Nlm_Uint1)(255-(i*255)/6),
(Nlm_Uint1)((i*255)/6) );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+7))/18;
Nlm_PaintRect ( &rp );
}
for ( i=0; i<6; i++ ){
if ( i == 5 ) {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
} else {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+13))/18, y0+NLM_CHCOLOR_SHLH-2);
}
Nlm_SelectColor ( (Nlm_Uint1)((i*255)/6), 0,
(Nlm_Uint1)(255-(i*255)/6) );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+13))/18;
Nlm_PaintRect ( &rp );
}
} else {
for ( i=0; i<6; i++ ){
if ( i == 5 ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
} else {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
}
Nlm_SelectColor ( (Nlm_Uint1)(((i+1)*255)/7), 0, 0 );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
Nlm_PaintRect ( &rp );
}
}
}
static void Nlm_HPtrColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pHPtrColor, &rp);
if ( stColorModel == 1 ) {
val = stColorHSL[0];
} else {
val = stColorRGB[0];
}
Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
(Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
rp.top );
}
static void Nlm_SColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
int i;
int x0, y0, xcur;
Nlm_ObjectRect (pSColor, &rp);
rp.left += NLM_CHCOLOR_PTRW2;
rp.right -= NLM_CHCOLOR_PTRW2;
Nlm_FrameRect ( &rp );
x0 = xcur = rp.left + 1;
y0 = rp.top + 1;
for ( i=0; i<6; i++ ){
if ( i == 5 ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
} else {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
}
if ( stColorModel == 1 ) {
Nlm_SelectColor ( (Nlm_Uint1)(((7-i)*255)/10),
(Nlm_Uint1)((255*(14+i)/21)),
(Nlm_Uint1)(((7-i)*255)/10) );
} else {
Nlm_SelectColor ( 0, (Nlm_Uint1)(((i+1)*255)/7), 0 );
}
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
Nlm_PaintRect ( &rp );
}
}
static void Nlm_SPtrColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pSPtrColor, &rp);
if ( stColorModel == 1 ) {
val = stColorHSL[1];
} else {
val = stColorRGB[1];
}
Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
(Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
rp.top );
}
static void Nlm_LColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
int i;
int x0, y0, xcur;
Nlm_ObjectRect (pLColor, &rp);
rp.left += NLM_CHCOLOR_PTRW2;
rp.right -= NLM_CHCOLOR_PTRW2;
Nlm_FrameRect ( &rp );
x0 = xcur = rp.left + 1;
y0 = rp.top + 1;
if ( stColorModel == 1 ) {
for ( i=0; i<8; i++ ){
if ( i == 7 ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
} else {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+1))/8, y0+NLM_CHCOLOR_SHLH-2);
}
Nlm_SelectColor ( (Nlm_Uint1)((i*255)/7),
(Nlm_Uint1)((i*255)/7),
(Nlm_Uint1)((i*255)/7) );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/8;
Nlm_PaintRect ( &rp );
}
} else {
for ( i=0; i<6; i++ ){
if ( i == 5 ){
Nlm_LoadRect ( &rp, xcur, y0,
x0 + NLM_CHCOLOR_SHLW - 2, y0+NLM_CHCOLOR_SHLH-2);
} else {
Nlm_LoadRect ( &rp, xcur, y0,
x0 + (NLM_CHCOLOR_SHLW*(i+1))/6, y0+NLM_CHCOLOR_SHLH-2);
}
Nlm_SelectColor ( 0, 0, (Nlm_Uint1)(((i+1)*255)/7) );
xcur = x0 + (NLM_CHCOLOR_SHLW*(i+1))/6;
Nlm_PaintRect ( &rp );
}
}
}
static void Nlm_LPtrColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pLPtrColor, &rp);
if ( stColorModel == 1 ) {
val = stColorHSL[2];
} else {
val = stColorRGB[2];
}
Nlm_DrawColorPtr ( rp.left + NLM_CHCOLOR_PTRW2 +
(Nlm_Int2)((long)val*(long)NLM_CHCOLOR_SHLW/(long)256),
rp.top );
}
static void Nlm_SelectDynColor (Nlm_Uint1 red,
Nlm_Uint1 green,
Nlm_Uint1 blue) {
#ifdef WIN_X
if (Nlm_hasColor && (tmpColorPixel != VOID_PIXEL))
{
Nlm_Uint2 rd = (Nlm_Uint2)red;
Nlm_Uint2 gn = (Nlm_Uint2)green;
Nlm_Uint2 bl = (Nlm_Uint2)blue;
XColor xcolor;
xcolor.red = rd << 8 | rd;
xcolor.green = gn << 8 | gn;
xcolor.blue = bl << 8 | bl;
xcolor.pixel = tmpColorPixel;
xcolor.flags = DoRed|DoGreen|DoBlue;
XStoreColor(Nlm_currentXDisplay, Nlm_VibrantDefaultColormap(), &xcolor);
XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, tmpColorPixel);
}
else
Nlm_SelectColor(red, green, blue);
#else
Nlm_SelectColor(red, green, blue);
#endif
}
static void Nlm_RetColorDraw ( Nlm_PaneL p ){
Nlm_RecT rp;
Nlm_ObjectRect (pRetColor, &rp);
Nlm_FrameRect ( &rp );
Nlm_InsetRect ( &rp, 1, 1 );
Nlm_SelectDynColor ( (Nlm_Uint1)stColorRGB[0],
(Nlm_Uint1)stColorRGB[1],
(Nlm_Uint1)stColorRGB[2] );
Nlm_PaintRect ( &rp );
}
/* -------------------Button callbacks--------------------- */
static void Nlm_OKChooseColor ( Nlm_ButtoN bn ){
colorDlgUp = FALSE;
colorDlgOK = TRUE;
}
static void Nlm_CancelChooseColor ( Nlm_ButtoN bn ){
colorDlgUp = FALSE;
}
static void Nlm_SaveCustomColor ( Nlm_ButtoN bn ){
Nlm_WindoW tmpPort;
theCustomColors[stColorCurCustom].red = (Nlm_Uint1)stColorRGB[0];
theCustomColors[stColorCurCustom].green = (Nlm_Uint1)stColorRGB[1];
theCustomColors[stColorCurCustom].blue = (Nlm_Uint1)stColorRGB[2];
tmpPort = Nlm_SavePort (pCustomColor);
Nlm_Select (pCustomColor);
Nlm_CustomColorDraw ( NULL );
Nlm_RestorePort (tmpPort);
}
/* -------------------Update dialog------------------------ */
static void Nlm_UpdateColorDialog ( Nlm_Int2 owner ){
Nlm_WindoW tmpPort;
Nlm_ResetClip ();
switch ( owner ){
case NLM_CHCOLOR_OSP:
case NLM_CHCOLOR_OHP:
case NLM_CHCOLOR_OLP:
if ( stColorModel == 1 ) {
Nlm_HSL2RGB ( stColorRGB, stColorHSL );
} else {
Nlm_RGB2HSL ( stColorHSL, stColorRGB );
}
break;
case NLM_CHCOLOR_OST:
case NLM_CHCOLOR_OHT:
case NLM_CHCOLOR_OLT:
Nlm_HSL2RGB ( stColorRGB, stColorHSL );
break;
default:
Nlm_RGB2HSL ( stColorHSL, stColorRGB );
}
tmpPort = Nlm_SavePort (pRetColor);
Nlm_Select (pRetColor);
Nlm_RetColorDraw ( pRetColor );
Nlm_RestorePort (tmpPort);
switch ( owner ){
case NLM_CHCOLOR_OHP:
case NLM_CHCOLOR_OHT:
case NLM_CHCOLOR_OLP:
case NLM_CHCOLOR_OLT:
break;
default:
Nlm_UpdColorPanel ( pSPtrColor );
}
switch ( owner ){
case NLM_CHCOLOR_OSP:
case NLM_CHCOLOR_OST:
case NLM_CHCOLOR_OLP:
case NLM_CHCOLOR_OLT:
break;
default:
Nlm_UpdColorPanel ( pHPtrColor );
}
switch ( owner ){
case NLM_CHCOLOR_OSP:
case NLM_CHCOLOR_OST:
case NLM_CHCOLOR_OHP:
case NLM_CHCOLOR_OHT:
break;
default:
Nlm_UpdColorPanel ( pLPtrColor );
}
if ( owner != NLM_CHCOLOR_OHT ) Nlm_UpdColorText ( tColorHue, stColorHSL[0] );
if ( owner != NLM_CHCOLOR_OST ) Nlm_UpdColorText ( tColorSat, stColorHSL[1] );
if ( owner != NLM_CHCOLOR_OLT ) Nlm_UpdColorText ( tColorLum, stColorHSL[2] );
if ( owner != NLM_CHCOLOR_ORT ) Nlm_UpdColorText ( tColorRed, stColorRGB[0] );
if ( owner != NLM_CHCOLOR_OGT ) Nlm_UpdColorText ( tColorGreen, stColorRGB[1] );
if ( owner != NLM_CHCOLOR_OBT ) Nlm_UpdColorText ( tColorBlue, stColorRGB[2] );
}
/* -------------------Text callbacks----------------------- */
static void Nlm_EditColorRGB ( Nlm_TexT t ){
int ival;
Nlm_Int2 owner;
ival = Nlm_GetColorVal ( t );
if ( t == tColorRed ){
stColorRGB[0] = ival;
owner = NLM_CHCOLOR_ORT;
} else if ( t == tColorGreen ){
stColorRGB[1] = ival;
owner = NLM_CHCOLOR_OGT;
} else {
stColorRGB[2] = ival;
owner = NLM_CHCOLOR_OBT;
}
Nlm_UpdateColorDialog (owner);
}
static void Nlm_EditColorHSL ( Nlm_TexT t ){
int ival;
Nlm_Int2 owner;
ival = Nlm_GetColorVal ( t );
if ( t == tColorHue ){
stColorHSL[0] = ival;
owner = NLM_CHCOLOR_OHT;
} else if ( t == tColorSat ){
stColorHSL[1] = ival;
owner = NLM_CHCOLOR_OST;
} else {
stColorHSL[2] = ival;
owner = NLM_CHCOLOR_OLT;
}
Nlm_UpdateColorDialog (owner);
}
/* -------------------Click callback----------------------- */
static void Nlm_BasicColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
Nlm_RecT rp;
int colorNum;
Nlm_ObjectRect (pBasicColor, &rp);
pt.x -= rp.left;
pt.y -= rp.top;
pt.x /= NLM_CHCOLOR_BOXW;
pt.y /= NLM_CHCOLOR_BOXH;
colorNum = pt.y*8+pt.x;
if ( (colorNum >= 0) && (colorNum < 48) ){
stColorRGB[0] = theBasicColors[colorNum].red;
stColorRGB[1] = theBasicColors[colorNum].green;
stColorRGB[2] = theBasicColors[colorNum].blue;
Nlm_UpdateColorDialog(NLM_CHCOLOR_OBC);
}
}
static void Nlm_CustomColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
Nlm_RecT rp;
Nlm_RecT rdraw;
int colorNum,i,x,y;
Nlm_ObjectRect (pCustomColor, &rp);
pt.x -= rp.left;
pt.y -= rp.top;
pt.x /= NLM_CHCOLOR_BOXW;
pt.y /= NLM_CHCOLOR_BOXH;
colorNum = pt.y*8+pt.x;
if ( (colorNum >= 0) && (colorNum < 16) ){
stColorRGB[0] = theCustomColors[colorNum].red;
stColorRGB[1] = theCustomColors[colorNum].green;
stColorRGB[2] = theCustomColors[colorNum].blue;
Nlm_InvertMode();
for ( i=0;i<2;i++){
y = stColorCurCustom / 8;
x = stColorCurCustom - y*8;
x = rp.left + x*NLM_CHCOLOR_BOXW;
y = rp.top + y*NLM_CHCOLOR_BOXH;
Nlm_LoadRect ( &rdraw, x, y,
x + NLM_CHCOLOR_BOXW, y + NLM_CHCOLOR_BOXH );
Nlm_FrameRect ( &rdraw );
stColorCurCustom = colorNum;
}
Nlm_CopyMode();
Nlm_UpdateColorDialog (NLM_CHCOLOR_OCC);
}
}
static void Nlm_HColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pHColor, &rp);
pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
if ( val > 255 ) val = 255;
if ( stColorModel == 1 ) {
stColorHSL[0] = val;
} else {
stColorRGB[0] = val;
}
Nlm_UpdateColorDialog (NLM_CHCOLOR_OHP);
}
}
static void Nlm_SColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pSColor, &rp);
pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
if ( val > 255 ) val = 255;
if ( stColorModel == 1 ) {
stColorHSL[1] = val;
} else {
stColorRGB[1] = val;
}
Nlm_UpdateColorDialog (NLM_CHCOLOR_OSP);
}
}
static void Nlm_LColorClick ( Nlm_PaneL p, Nlm_PoinT pt ){
Nlm_RecT rp;
Nlm_Int2 val;
Nlm_ObjectRect (pLColor, &rp);
pt.x -= rp.left + NLM_CHCOLOR_PTRW2;
if ( (pt.x >= 0) && (pt.x <= NLM_CHCOLOR_SHLW) ){
val = (Nlm_Int2)(((long)pt.x * (long)256)/(long)NLM_CHCOLOR_SHLW);
if ( val > 255 ) val = 255;
if ( stColorModel == 1 ) {
stColorHSL[2] = val;
} else {
stColorRGB[2] = val;
}
Nlm_UpdateColorDialog (NLM_CHCOLOR_OLP);
}
}
/* ---------------Radio Button callback-------------------- */
static void Nlm_ChangeColorModel ( Nlm_GrouP g ){
Nlm_RecT rp;
Nlm_PaneL p[6];
Nlm_Int2 i;
Nlm_WindoW tmpPort;
if ( Nlm_GetValue(g) != stColorModel ){
stColorModel = Nlm_GetValue(g);
p[0] = pSColor;
p[1] = pSPtrColor;
p[2] = pHColor;
p[3] = pHPtrColor;
p[4] = pLColor;
p[5] = pLPtrColor;
for (i=0; i<6; i++ ) {
Nlm_ObjectRect (p[i], &rp);
tmpPort = Nlm_SavePort (p[i]);
Nlm_Select (p[i]);
Nlm_InvalRect (&rp);
Nlm_RestorePort (tmpPort);
}
}
}
/* ---------------Main dialog function--------------------- */
extern Nlm_Boolean Nlm_ChooseColorDialog (
Nlm_Uint1 PNTR redptr,Nlm_Uint1 PNTR greenptr, Nlm_Uint1 PNTR blueptr,
Nlm_Boolean Initial ){
Nlm_WindoW w;
Nlm_GrouP gw, gleft, gright, g, gtmp;
#ifdef WIN_X
unsigned long plane_masks[1];
#endif
w = Nlm_MovableModalWindow (-50, -20, -20, -20, "Color", NULL);
gw = Nlm_HiddenGroup (w, 2,0, NULL);
Nlm_SetGroupMargins (gw, 1, 1);
Nlm_SetGroupSpacing (gw, 10, 1);
gleft = Nlm_HiddenGroup (gw, 1, 0, NULL);
Nlm_SetGroupSpacing (gleft, 1, 10 );
Nlm_StaticPrompt (gleft, " Basic colors:", 0, 0, Nlm_systemFont, 'l');
pBasicColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_BOXW * 8,
NLM_CHCOLOR_BOXH * 6, Nlm_BasicColorDraw );
Nlm_SetPanelClick ( pBasicColor, Nlm_BasicColorClick, NULL, NULL, NULL );
Nlm_StaticPrompt (gleft, " Custom colors:", 0, 0, Nlm_systemFont, 'l');
pCustomColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_BOXW * 8,
NLM_CHCOLOR_BOXH * 2, Nlm_CustomColorDraw );
Nlm_SetPanelClick ( pCustomColor, Nlm_CustomColorClick, NULL, NULL, NULL );
pRetColor = Nlm_SimplePanel ( gleft, NLM_CHCOLOR_EXW,
NLM_CHCOLOR_EXH, Nlm_RetColorDraw );
gright = Nlm_HiddenGroup (gw, 1, 0, NULL);
Nlm_SetGroupSpacing (gright, 1, 1);
g = Nlm_HiddenGroup (gright, 2, 0, Nlm_ChangeColorModel );
Nlm_SetGroupMargins (g, 20, 0);
Nlm_RadioButton ( g, "HSL" );
Nlm_RadioButton ( g, "RGB" );
Nlm_SetValue(g,1);
stColorModel = 1;
g = Nlm_HiddenGroup (gright, 1, 0, NULL);
Nlm_SetGroupMargins (g, 1, 20);
Nlm_SetGroupSpacing (g, 5, 10);
gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
Nlm_SetGroupSpacing (gtmp, 0, 0);
pHColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_SHLH, Nlm_HColorDraw );
Nlm_SetPanelClick ( pHColor, Nlm_HColorClick, Nlm_HColorClick, NULL, NULL );
pHPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_PTRH, Nlm_HPtrColorDraw );
Nlm_SetPanelClick ( pHPtrColor, Nlm_HColorClick, Nlm_HColorClick, NULL, NULL );
Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pHColor,
(Nlm_HANDLE)pHPtrColor, NULL);
gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
Nlm_SetGroupSpacing (gtmp, 0, 0);
pSColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_SHLH, Nlm_SColorDraw );
Nlm_SetPanelClick ( pSColor, Nlm_SColorClick, Nlm_SColorClick, NULL, NULL );
pSPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_PTRH, Nlm_SPtrColorDraw );
Nlm_SetPanelClick ( pSPtrColor, Nlm_SColorClick, Nlm_SColorClick, NULL, NULL );
Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pSColor,
(Nlm_HANDLE)pSPtrColor, NULL );
gtmp = Nlm_HiddenGroup (g, 1, 0, NULL);
Nlm_SetGroupSpacing (gtmp, 0, 0);
pLColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_SHLH, Nlm_LColorDraw );
Nlm_SetPanelClick ( pLColor, Nlm_LColorClick, Nlm_LColorClick, NULL, NULL );
pLPtrColor = Nlm_SimplePanel ( gtmp, NLM_CHCOLOR_SHLW + NLM_CHCOLOR_PTRW,
NLM_CHCOLOR_PTRH, Nlm_LPtrColorDraw );
Nlm_SetPanelClick ( pLPtrColor, Nlm_LColorClick, Nlm_LColorClick, NULL, NULL );
Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE)pLColor,
(Nlm_HANDLE)pLPtrColor, NULL);
g = Nlm_HiddenGroup (gright, 2, 0, NULL);
Nlm_SetGroupMargins (g, 10, 2);
gtmp = Nlm_HiddenGroup (g, 2, 0, NULL);
Nlm_StaticPrompt (gtmp, "Hue:", 0, 0, Nlm_systemFont, 'r');
tColorHue = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
Nlm_StaticPrompt (gtmp, "Sat:", 0, 0, Nlm_systemFont, 'r');
tColorSat = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
Nlm_StaticPrompt (gtmp, "Lum:", 0, 0, Nlm_systemFont, 'r');
tColorLum = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorHSL );
gtmp = Nlm_HiddenGroup (g, 2, 0, NULL);
Nlm_StaticPrompt (gtmp, "Red:", 0, 0, Nlm_systemFont, 'r');
tColorRed = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
Nlm_StaticPrompt (gtmp, "Green:", 0, 0, Nlm_systemFont, 'r');
tColorGreen = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
Nlm_StaticPrompt (gtmp, "Blue:", 0, 0, Nlm_systemFont, 'r');
tColorBlue = Nlm_DialogText ( gtmp, NULL, 3, Nlm_EditColorRGB );
g = Nlm_HiddenGroup (w, 3,0, NULL);
Nlm_SetGroupSpacing (g, 15, 1);
Nlm_SetGroupMargins (g, 60,1);
Nlm_DefaultButton (g, " OK ", Nlm_OKChooseColor );
Nlm_PushButton (g, "Cancel", Nlm_CancelChooseColor );
Nlm_PushButton (g, "Save Custom Color", Nlm_SaveCustomColor );
/* Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE); */
Nlm_RealizeWindow (w);
Nlm_UpdateColorDialog (NLM_CHCOLOR_OBC);
Nlm_Show ((Nlm_GraphiC) w);
Nlm_ArrowCursor ();
colorDlgUp = TRUE;
colorDlgOK = FALSE;
#ifdef WIN_X
if (tmpColorPixel == VOID_PIXEL &&
Nlm_currentXDisplay != NULL &&
XAllocColorCells(Nlm_currentXDisplay,
Nlm_VibrantDefaultColormap(),
FALSE, plane_masks, 0, &tmpColorPixel, 1) == 0)
{
tmpColorPixel = VOID_PIXEL;
}
#endif
Nlm_WaitForCondition( colorDlgUp );
Nlm_ProcessAnEvent ();
/* Nlm_DoRemove ((Nlm_GraphiC) w, TRUE); */
Nlm_Remove ((Nlm_GraphiC) w);
if ( colorDlgOK ){
*redptr = (Nlm_Uint1)stColorRGB[0];
*greenptr = (Nlm_Uint1)stColorRGB[1];
*blueptr = (Nlm_Uint1)stColorRGB[2];
return TRUE;
}
return FALSE;
}
#endif
/* -------------------End Non MS-Window ------------------- */
|