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 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
|
/*
* Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
* Copyright(c) 1995-99 Andrew Lister
*
* All rights reserved
* Permission to use, copy, modify and distribute this material for
* any purpose and without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies, and that the name of Bellcore not be used in advertising
* or publicity pertaining to this material without the specific,
* prior written permission of an authorized representative of
* Bellcore.
*
* BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
* PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
* FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS. THE
* SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
* ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
* LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
* ING TO THE SOFTWARE.
*
* $Id: Actions.c,v 1.1 2001-07-18 11:05:59 root Exp $
*/
/*
* Actions.c created by Andrew Lister (7 August, 1995)
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <Xm/Xm.h>
#include <Xm/XmP.h>
#if XmVersion > 1001
#include <Xm/DrawP.h>
#endif
#include <Xm/ScrollBar.h>
#include "MatrixP.h"
#include "Clip.h"
#include "Draw.h"
#include "Actions.h"
#include "Utils.h"
#include "ScrollMgr.h"
#include "ClipP.h"
#include <X11/cursorfont.h>
#ifndef XlibSpecificationRelease
#define XrmPermStringToQuark XrmStringToQuark
#endif
#if !defined(DRAW_RESIZE_LINE) && !defined(DRAW_RESIZE_SHADOW)
/* One of DRAW_RESIZE_LINE and DRAW_RESIZE_SHADOW must be defined. */
#define DRAW_RESIZE_SHADOW
#endif
#ifndef DEFAULT_SCROLL_SPEED
#define DEFAULT_SCROLL_SPEED 500
#endif
typedef struct {
XbaeMatrixWidget mw;
GC gc;
int row;
int column;
int startx;
int lastx;
int currentx;
int y, height;
short *columnWidths;
Boolean grabbed;
Boolean haveVSB;
} XbaeMatrixResizeColumnStruct;
typedef struct {
XbaeMatrixWidget mw;
int row;
int column;
Boolean pressed;
Boolean grabbed;
} XbaeMatrixButtonPressedStruct;
typedef struct {
XbaeMatrixWidget mw;
XbaeClipWidget cw;
XEvent *event;
XtIntervalId timerID;
XtAppContext app_context;
unsigned long interval;
Boolean inClip;
Boolean grabbed;
Boolean above;
Boolean below;
Boolean left;
Boolean right;
} XbaeMatrixScrollStruct;
static int DoubleClick P((XbaeMatrixWidget, XEvent *, int, int));
static void DrawSlideColumn P((XbaeMatrixWidget, int));
static void SlideColumn P((Widget, XtPointer, XEvent *, Boolean *));
static void PushButton P((Widget, XtPointer, XEvent *, Boolean *));
static void updateScroll P((XtPointer));
static void checkScrollValues P((Widget, XtPointer, XEvent *, Boolean *));
static void callSelectCellAction P((XbaeMatrixWidget, XEvent *));
static int last_row = 0;
static int last_column = 0;
static int last_selected_row = 0;
static int last_selected_column = 0;
static Boolean scrolling = False;
/* ARGSUSED */
void
xbaeDefaultActionACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
int x, y;
int row, column;
CellType cell;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else {
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"defaultActionACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to DefaultAction action",
NULL, 0);
return;
}
if (!mw->matrix.default_action_callback)
return;
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
if (!xbaeXYToRowCol(mw, &x, &y, &row, &column, cell))
return;
if (DoubleClick(mw, event, row, column))
{
XbaeMatrixDefaultActionCallbackStruct call_data;
call_data.reason = XbaeDefaultActionReason;
call_data.event = event;
call_data.row = row;
call_data.column = column;
XtCallCallbackList((Widget)mw, mw->matrix.default_action_callback,
(XtPointer)&call_data);
}
}
static void
DrawSlideColumn(mw, x)
XbaeMatrixWidget mw;
int x;
{
#ifdef DRAW_RESIZE_SHADOW
/* These values derived through that age-old process
* of what looks good to me */
#define SHADOW_WIDTH 2
#define RESIZE_COLUMN_LINE_WIDTH 4
Dimension width = RESIZE_COLUMN_LINE_WIDTH;
Dimension shadow_width = SHADOW_WIDTH;
#endif
Dimension height;
Window win;
Display *display = XtDisplay(mw);
int column = xbaeXtoCol(mw, x - COLUMN_LABEL_OFFSET(mw));
int top, bottom;
int adjusted_x;
int y;
#ifdef DRAW_RESIZE_LINE
GC gc = mw->matrix.draw_gc;
#endif
Boolean need_vert_dead_space_fill = NEED_VERT_DEAD_SPACE_FILL(mw);
unsigned int clip_reason;
/*
* If the column being resized is a fixed one then we don't need to
* bother with the clip region
*/
if (column < (int)mw->matrix.fixed_columns)
{
y = ROW_LABEL_OFFSET(mw);
height = VISIBLE_HEIGHT(mw) + FIXED_ROW_HEIGHT(mw) +
TRAILING_FIXED_ROW_HEIGHT(mw);
win = XtWindow (mw);
if (need_vert_dead_space_fill)
height += VERT_DEAD_SPACE_HEIGHT(mw);
#ifdef DRAW_RESIZE_LINE
XDrawLine(display, win, gc, x, y, x, y + height);
if (XtIsManaged(LeftClip(mw)))
XDrawLine(display, XtWindow(LeftClip(mw)), gc,
x - COLUMN_LABEL_OFFSET(mw), 0,
x - COLUMN_LABEL_OFFSET(mw),
LeftClip(mw)->core.height);
#endif
#ifdef DRAW_RESIZE_SHADOW
DRAW_SHADOW(display, win,
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, x, y, width, height, XmSHADOW_OUT);
if (XtIsManaged(LeftClip(mw)))
DRAW_SHADOW(display, XtWindow(LeftClip(mw)),
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, x - COLUMN_LABEL_OFFSET(mw),
0, width, LeftClip(mw)->core.height, XmSHADOW_OUT);
#endif
return;
}
/*
* Similarly for trailingFixedColumns - beware going off the clip child
* here also
*/
if (column >= TRAILING_HORIZ_ORIGIN(mw) ||
x >= (int)(ClipChild(mw)->core.x + ClipChild(mw)->core.width))
{
y = ROW_LABEL_OFFSET(mw);
height = VISIBLE_HEIGHT(mw) + FIXED_ROW_HEIGHT(mw) +
TRAILING_FIXED_ROW_HEIGHT(mw);
win = XtWindow(mw);
if (need_vert_dead_space_fill)
height += VERT_DEAD_SPACE_HEIGHT(mw);
#ifdef DRAW_RESIZE_LINE
XDrawLine(display, win, gc, x, y, x, y + height);
if (XtIsManaged(RightClip(mw)))
XDrawLine(display, XtWindow(RightClip(mw)),
gc, x - TRAILING_FIXED_COLUMN_LABEL_OFFSET(mw), 0,
x - TRAILING_FIXED_COLUMN_LABEL_OFFSET(mw),
RightClip(mw)->core.height);
#endif
#ifdef DRAW_RESIZE_SHADOW
DRAW_SHADOW(display, win,
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, x, y, width, height, XmSHADOW_OUT);
if (XtIsManaged(RightClip(mw)))
DRAW_SHADOW(display, XtWindow(RightClip(mw)),
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width,
x - TRAILING_FIXED_COLUMN_LABEL_OFFSET(mw), 0,
width, RightClip(mw)->core.height, XmSHADOW_OUT);
#endif
return;
}
xbaeGetVisibleRows(mw, &top, &bottom);
/*
* we need all non-fixed rows, so add 1 to bottom
* to include the last one as the return values
* are inclusive
*/
bottom += 1;
/*
* The area between top and bottom rows are the non fixed rows. They
* fall on the ClipChild
*/
y = -mw->matrix.cell_shadow_thickness; /* relative to clip */
height = ROW_HEIGHT(mw) * (bottom - top) +
2 * mw->matrix.cell_shadow_thickness;
/*
* If we are on the clip, the x location is offset by the
* fixed column width, label offset and label width
*/
adjusted_x = x - FIXED_COLUMN_LABEL_OFFSET(mw);
win = XtWindow(ClipChild(mw));
#ifdef DRAW_RESIZE_LINE
XDrawLine(display, win, gc, adjusted_x, y, adjusted_x, y + height);
#endif
#ifdef DRAW_RESIZE_SHADOW
DRAW_SHADOW(display, win,
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, adjusted_x, y, width, height, XmSHADOW_OUT);
#endif
/*
* Now draw the line (or shadow) on the non clipped region - that is
* the fixed and trailingFixed rows. First, do the leading rows.
*/
if (mw->matrix.fixed_rows)
{
y = ROW_LABEL_OFFSET(mw);
height = FIXED_ROW_HEIGHT(mw) + 2 * mw->matrix.cell_shadow_thickness;
win = XtWindow(mw);
xbaeSetClipMask(mw, CLIP_FIXED_ROWS);
#ifdef DRAW_RESIZE_LINE
if (XtIsManaged(TopClip(mw)))
XDrawLine(display, XtWindow(TopClip(mw)), gc, adjusted_x,
-mw->matrix.cell_shadow_thickness, adjusted_x, height);
#endif
#ifdef DRAW_RESIZE_SHADOW
if (XtIsManaged(TopClip(mw)))
DRAW_SHADOW(display, XtWindow(TopClip(mw)),
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, adjusted_x,
-mw->matrix.cell_shadow_thickness,
width, height, XmSHADOW_OUT);
#endif
xbaeSetClipMask(mw, CLIP_NONE);
}
/*
* The trailingFixedRows
*/
if (mw->matrix.trailing_fixed_rows)
{
y = TRAILING_FIXED_ROW_LABEL_OFFSET(mw);
height = TRAILING_FIXED_ROW_HEIGHT(mw) +
2 * mw->matrix.cell_shadow_thickness;
clip_reason = CLIP_TRAILING_FIXED_ROWS;
if (IS_LEADING_FIXED_COLUMN(mw, column))
clip_reason |= CLIP_FIXED_COLUMNS;
else if (IS_TRAILING_FIXED_COLUMN(mw, column))
clip_reason |= CLIP_TRAILING_FIXED_COLUMNS;
xbaeSetClipMask(mw, clip_reason);
#ifdef DRAW_RESIZE_LINE
if (XtIsManaged(BottomClip(mw)))
XDrawLine(display, XtWindow(BottomClip(mw)), gc, adjusted_x,
-mw->matrix.cell_shadow_thickness, adjusted_x, height);
#endif
#ifdef DRAW_RESIZE_SHADOW
if (XtIsManaged(BottomClip(mw)))
DRAW_SHADOW(display, XtWindow(BottomClip(mw)),
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, adjusted_x,
-mw->matrix.cell_shadow_thickness,
width, height, XmSHADOW_OUT);
#endif
xbaeSetClipMask(mw, CLIP_NONE);
}
if ((NEED_VERT_FILL(mw) && (! HAS_ATTACHED_TRAILING_ROWS(mw))) ||
need_vert_dead_space_fill)
{
if (need_vert_dead_space_fill)
{
y = UNATTACHED_TRAILING_ROWS_OFFSET(mw) -
mw->matrix.cell_shadow_thickness;
height = 2 * mw->matrix.cell_shadow_thickness +
VERT_DEAD_SPACE_HEIGHT(mw);
}
else
{
y = TRAILING_FIXED_ROW_LABEL_OFFSET(mw) +
TRAILING_FIXED_ROW_HEIGHT(mw);
height = FILL_VERT_HEIGHT(mw) - HORIZ_SB_SPACE(mw);
}
#ifdef DRAW_RESIZE_LINE
XDrawLine(display, XtWindow(mw), gc,
adjusted_x, y, adjusted_x, height);
#endif
#ifdef DRAW_RESIZE_SHADOW
DRAW_SHADOW(display, XtWindow(mw),
mw->matrix.resize_top_shadow_gc,
mw->matrix.resize_bottom_shadow_gc,
shadow_width, x, y,
width, height, XmSHADOW_OUT);
#endif
}
}
static void
SlideColumn(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
{
XbaeMatrixResizeColumnStruct *rd = (XbaeMatrixResizeColumnStruct *)data;
XMotionEvent *motionEvent;
Boolean relayout = False;
int numCharacters;
int i;
if (event->type == ButtonRelease)
{
DrawSlideColumn(rd->mw, rd->lastx);
XUngrabPointer(XtDisplay(w), CurrentTime);
rd->grabbed = False;
/*
* Remanage the VSB if we unmapped it earlier
*/
if (rd->haveVSB)
XtManageChild(VertScrollChild(rd->mw));
if (rd->mw->matrix.resize_column_callback)
{
XbaeMatrixResizeColumnCallbackStruct call_data;
call_data.reason = XbaeResizeColumnReason;
call_data.event = event;
call_data.row = rd->row;
call_data.column = rd->column - 1;
call_data.which = rd->column - 1;
call_data.columns = rd->mw->matrix.columns;
call_data.column_widths = rd->columnWidths;
XtCallCallbackList ((Widget)rd->mw,
rd->mw->matrix.resize_column_callback,
(XtPointer)&call_data);
}
for (i = 0; i < rd->mw->matrix.columns; i++)
if (rd->columnWidths[i] != rd->mw->matrix.column_widths[i])
{
/* Make sure everything is handled correctly with SetValues */
XtVaSetValues((Widget)rd->mw, XmNcolumnWidths,
rd->columnWidths, NULL);
break;
}
/*
* If maxColumnLengths are set and we have resized the column to
* larger, reset the corresponding maxColumnLength
*/
if (rd->mw->matrix.column_max_lengths &&
rd->columnWidths[rd->column - 1] >
rd->mw->matrix.column_max_lengths[rd->column - 1])
rd->mw->matrix.column_max_lengths[rd->column - 1] =
rd->columnWidths[rd->column - 1];
XtFree((char *)rd->columnWidths);
return;
}
if (event->type != MotionNotify) /* Double check! */
return;
motionEvent = (XMotionEvent *)event;
if (rd->currentx - motionEvent->x > FONT_WIDTH(rd->mw))
{
/* If we're only one character wide, we cannae get any smaller */
if (rd->columnWidths[rd->column - 1] == BAD_WIDTH + 1)
return;
/*
* Moved left a full character - update the column widths and force
* a redisplay
*/
numCharacters = (rd->currentx - motionEvent->x) /
FONT_WIDTH(rd->mw);
if (numCharacters >= rd->columnWidths[rd->column - 1])
/* Must keep a column at least one character wide */
numCharacters = rd->columnWidths[rd->column - 1] - 1;
rd->columnWidths[rd->column - 1] -= numCharacters;
rd->currentx -= numCharacters * FONT_WIDTH(rd->mw);
relayout = True;
}
if (motionEvent->x - rd->currentx > FONT_WIDTH(rd->mw))
{
/*
* Moved right a full character - update the column widths and force
* a redisplay
*/
numCharacters = (motionEvent->x - rd->currentx) /
FONT_WIDTH(rd->mw);
rd->columnWidths[rd->column - 1] += numCharacters;
rd->currentx += numCharacters * FONT_WIDTH(rd->mw);
relayout = True;
}
if (relayout)
{
/* Draw the marker line in the new location */
if (rd->lastx != rd->currentx)
{
DrawSlideColumn(rd->mw, rd->currentx);
DrawSlideColumn(rd->mw, rd->lastx);
rd->lastx = rd->currentx;
}
}
}
/* ARGSUSED */
void
xbaeResizeColumnsACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
int x, y;
int eventx;
int i;
int row, column;
CellType cell;
static Cursor cursor;
XbaeMatrixResizeColumnStruct resizeData;
XGCValues values;
XtAppContext appcontext;
#ifdef DRAW_RESIZE_LINE
XGCValues save;
#endif
unsigned long gcmask, event_mask;
Display *display = XtDisplay(w);
#define FUZZ_FACTOR 3
int fuzzy = FUZZ_FACTOR;
#undef FUZZ_FACTOR
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else {
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"resizeColumnsACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to ResizeColumns action",
NULL, 0);
return;
}
/*
* If we won't allow dynamic column resize, leave.
*/
if (!mw->matrix.allow_column_resize)
return;
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
eventx = x;
if (!xbaeXYToRowCol(mw, &x, &y, &row, &column, cell))
return;
/*
* Calculate if the x and y of the middle button event is on
* a column border. Allow the width of the shadow to be the
* allowed delta. x is modified in xbaeXYToRowCol() to be
* the x distance from the cell's border
*/
if ((int)mw->matrix.cell_shadow_thickness > fuzzy)
fuzzy = mw->matrix.cell_shadow_thickness;
if (x > fuzzy && COLUMN_WIDTH(mw, column) - x > fuzzy)
return;
/*
* Looks like we hit a column border, determine the column that is
* intended to be resized
*/
if ((COLUMN_WIDTH(mw, column) - x) <= fuzzy)
column++;
/* Can't adjust the origin or should you be able to?? */
if (column == 0)
return;
/*
* Make it here and it's time to start the fun stuff!
*/
/* Create the left / right cursor */
if (!cursor)
cursor = XCreateFontCursor(display, XC_sb_h_double_arrow);
/* Commit any edit in progress and unmap the text field -
it's just bad luck */
(*((XbaeMatrixWidgetClass)XtClass(mw))->matrix_class.commit_edit)
(mw, event, True);
/*
* Redraw the cell that had the text field in it or it might stay blank
*/
xbaeDrawCell(mw, mw->matrix.current_row, mw->matrix.current_column);
/*
* Say goodbye to the Vertical ScrollBar -> it only gets in the way!
*/
if ((resizeData.haveVSB = XtIsManaged(VertScrollChild(mw)) &&
((mw->matrix.scrollbar_placement == XmTOP_RIGHT) ||
(mw->matrix.scrollbar_placement == XmBOTTOM_RIGHT))))
XtUnmanageChild(VertScrollChild(mw));
/*
* Flush the commit events out to the server. Otherwise, our changes
* to the GCs below have a bad effect.
*/
XSync(display, False);
event_mask = PointerMotionMask | ButtonReleaseMask;
XtAddEventHandler(w, event_mask,
True, (XtEventHandler)SlideColumn,
(XtPointer)&resizeData);
XGrabPointer(display, XtWindow(w), True, event_mask,
GrabModeAsync, GrabModeAsync, XtWindow((Widget)mw),
cursor, CurrentTime);
/* Copy the columnWidth array */
resizeData.columnWidths =
(short *)XtMalloc(mw->matrix.columns * sizeof(short));
for (i = 0; i < mw->matrix.columns; i++)
resizeData.columnWidths[i] = mw->matrix.column_widths[i];
resizeData.grabbed = True;
resizeData.mw = mw;
resizeData.column = column;
resizeData.startx = resizeData.currentx = resizeData.lastx =
event->xbutton.x;
gcmask = GCForeground | GCBackground | GCFunction;
values.function = GXxor;
#ifdef DRAW_RESIZE_LINE
XGetGCValues(display, mw->matrix.draw_gc, gcmask, &save);
values.foreground = values.background = save.background;
XChangeGC(display, mw->matrix.draw_gc, gcmask, &values);
#endif
DrawSlideColumn(mw, resizeData.currentx);
appcontext = XtWidgetToApplicationContext(w);
while (resizeData.grabbed)
XtAppProcessEvent(appcontext, XtIMAll);
XtRemoveEventHandler(w, event_mask, True,
(XtEventHandler)SlideColumn,
(XtPointer)&resizeData);
#ifdef DRAW_RESIZE_LINE
XSetFunction(display, mw->matrix.draw_gc, GXcopy);
#endif
}
/*
* Action to process a drag out
*/
/* ARGSUSED */
void
xbaeProcessDragACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
#if XmVersion > 1001
XbaeMatrixWidget mw;
int x, y;
int row, column;
CellType cell;
XbaeMatrixProcessDragCallbackStruct call_data;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else {
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"processDragACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to ProcessDrag action",
NULL, 0);
return;
}
if (!mw->matrix.process_drag_callback)
return;
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
if (!xbaeXYToRowCol(mw, &x, &y, &row, &column, cell))
return;
call_data.reason = XbaeProcessDragReason;
call_data.event = event;
call_data.row = row;
call_data.column = column;
if (mw->matrix.draw_cell_callback)
{
Pixel bgcolor, fgcolor;
int width, height, depth;
call_data.type = xbaeGetDrawCellValue(
mw, row, column, &call_data.string, &call_data.pixmap,
&call_data.mask, &width, &height, &bgcolor, &fgcolor, &depth);
}
else
call_data.string = mw->matrix.cells ?
mw->matrix.cells[row][column] : "";
call_data.num_params = *nparams;
call_data.params = params;
XtCallCallbackList((Widget)mw, mw->matrix.process_drag_callback,
(XtPointer)&call_data);
#endif
}
/*
* Action to edit a non-fixed cell.
*/
/* ARGSUSED */
void
xbaeEditCellACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
int row, column;
XrmQuark q;
static XrmQuark QPointer, QLeft, QRight, QUp, QDown;
static Boolean haveQuarks = False;
/*
* Get static quarks for the parms we understand
*/
if (!haveQuarks)
{
QPointer = XrmPermStringToQuark("Pointer");
QLeft = XrmPermStringToQuark("Left");
QRight = XrmPermStringToQuark("Right");
QUp = XrmPermStringToQuark("Up");
QDown = XrmPermStringToQuark("Down");
haveQuarks = True;
}
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"editCellACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to EditCell action",
NULL, 0);
return;
}
/*
* Make sure we have a single parm
*/
if (*nparams != 1)
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"editCellACT", "badParms", "XbaeMatrix",
"XbaeMatrix: Wrong params passed to EditCell action, needs 1",
NULL, 0);
return;
}
/*
* Initialize row/column to the current position
*/
row = mw->matrix.current_row;
column = mw->matrix.current_column;
/*
* Quarkify the string param
*/
q = XrmStringToQuark(params[0]);
/*
* If we aren't currently editing, then the only kind of traversal that
* makes sense is pointer.
*/
if (!XtIsManaged(TextChild(mw)) && q != QPointer)
return;
if (q == QPointer)
{
CellType cellType = NonFixedCell;
int x, y;
/*
* Get the x,y point coordinate relative to the Clip window.
* Return if this event did not occur in the Clip subwindow
* (since we can only edit non-fixed cells).
*/
switch(event->type)
{
case ButtonPress:
case ButtonRelease:
x = event->xbutton.x;
y = event->xbutton.y;
break;
case KeyPress:
case KeyRelease:
x = event->xkey.x;
y = event->xkey.y;
break;
case MotionNotify:
x = event->xmotion.x;
y = event->xmotion.y;
break;
default:
return;
}
if (event->xbutton.subwindow == XtWindow(ClipChild(mw)))
{
x -= FIXED_COLUMN_LABEL_OFFSET(mw);
y -= FIXED_ROW_LABEL_OFFSET(mw);
cellType = NonFixedCell;
}
else if (event->xbutton.window != XtWindow(ClipChild(mw)))
{
if (!mw->matrix.traverse_fixed)
return;
cellType = FixedCell;
}
/*
* Convert the point to a row,column. If it does not pick a valid
* cell, then return.
*/
if (!xbaeXYToRowCol(mw, &x, &y, &row, &column, cellType))
return;
}
else if (q == QRight)
{
/*
* If we are in the lower right corner, stay there.
* Otherwise move over a column. If we move off to the right of the
* final column to which traversing is allowed then move down a row
* and back to the first column to which traversing is allowed.
*/
if (!mw->matrix.traverse_fixed)
{
/* check scrollable boundary */
if (mw->matrix.current_row != TRAILING_VERT_ORIGIN(mw) - 1 ||
mw->matrix.current_column != TRAILING_HORIZ_ORIGIN(mw) - 1)
{
column++;
if (IS_TRAILING_FIXED_COLUMN(mw, column))
{
column = mw->matrix.fixed_columns;
row++;
}
}
}
else
{
/* check matrix boundary */
if (mw->matrix.current_row != mw->matrix.rows - 1 ||
mw->matrix.current_column != mw->matrix.columns - 1)
{
column++;
if (column >= mw->matrix.columns)
{
column = 0;
row++;
}
}
}
}
else if (q == QLeft)
{
/*
* If we are in the upper left corner, stay there.
* Otherwise move back a column. If we move before the first column
* to which traversing is allowed, move up a row and over to the last
* column to which traversing is allowed.
*/
if (!mw->matrix.traverse_fixed)
{
/* check scrollable boundary */
if (mw->matrix.current_row != mw->matrix.fixed_rows ||
mw->matrix.current_column != mw->matrix.fixed_columns)
{
column--;
if (IS_LEADING_FIXED_COLUMN(mw, column))
{
column = TRAILING_HORIZ_ORIGIN(mw) - 1;
row--;
}
}
}
else
{
if (mw->matrix.current_row != 0 || mw->matrix.current_column != 0)
{
column--;
if (column < 0)
{
column = mw->matrix.columns - 1;
row--;
}
}
}
}
else if (q == QDown)
{
row++;
/* adjust row for allowable traversable regions */
if (!mw->matrix.traverse_fixed)
{
if (IS_TRAILING_FIXED_ROW(mw, row))
row = mw->matrix.fixed_rows;
}
else
{
if (row >= mw->matrix.rows)
row = 0;
}
}
else if (q == QUp)
{
row--;
if (!mw->matrix.traverse_fixed)
{
if (IS_LEADING_FIXED_ROW(mw, row))
row = TRAILING_VERT_ORIGIN(mw) - 1;
}
else
{
if (row < 0)
row = mw->matrix.rows - 1;
}
}
/*
* Call the traverseCellCallback to allow the application to
* perform custom traversal.
*/
if (mw->matrix.traverse_cell_callback)
{
XbaeMatrixTraverseCellCallbackStruct call_data;
call_data.reason = XbaeTraverseCellReason;
call_data.event = event;
call_data.row = mw->matrix.current_row;
call_data.column = mw->matrix.current_column;
call_data.next_row = row;
call_data.next_column = column;
call_data.fixed_rows = mw->matrix.fixed_rows;
call_data.fixed_columns = mw->matrix.fixed_columns;
call_data.trailing_fixed_rows = mw->matrix.trailing_fixed_rows;
call_data.trailing_fixed_columns = mw->matrix.trailing_fixed_columns;
call_data.num_rows = mw->matrix.rows;
call_data.num_columns = mw->matrix.columns;
call_data.param = params[0];
call_data.qparam = q;
XtCallCallbackList((Widget)mw, mw->matrix.traverse_cell_callback,
(XtPointer)&call_data);
row = call_data.next_row;
column = call_data.next_column;
}
/*
* Attempt to edit the new cell using the edit_cell method.
* If we are editing a cell based on pointer position, we always
* call edit_cell. Otherwise, we must be editing a new cell to
* call edit_cell.
*/
if (q == QPointer || (row != mw->matrix.current_row ||
column != mw->matrix.current_column))
(*((XbaeMatrixWidgetClass)XtClass(mw))->matrix_class.edit_cell)
(mw, event, row, column, params, *nparams);
/*
* Traverse to the textField
*/
(void)XmProcessTraversal(TextChild(mw), XmTRAVERSE_CURRENT);
}
/*
* Action to unmap the textField and discard any edits made
*/
/* ARGSUSED */
void
xbaeCancelEditACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
Boolean unmap;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"cancelEditACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to CancelEdit action",
NULL, 0);
return;
}
/*
* Make sure we have a single param
*/
if (*nparams != 1)
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"cancelEditACT", "badParms", "XbaeMatrix",
"XbaeMatrix: Wrong params passed to CancelEdit action, needs 1",
NULL, 0);
return;
}
/*
* Validate our param
*/
if (!strcmp(params[0], "True"))
unmap = True;
else if (!strcmp(params[0], "False"))
unmap = False;
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"cancelEditACT", "badParm", "XbaeMatrix",
"XbaeMatrix: Bad parameter for CancelEdit action",
NULL, 0);
return;
}
/*
* Call the cancel_edit method
*/
(*((XbaeMatrixWidgetClass)XtClass(mw))->matrix_class.cancel_edit)
(mw, unmap);
}
/*
* Action save any edits made and unmap the textField if params[0] is True
*/
/* ARGSUSED */
void
xbaeCommitEditACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
Boolean unmap;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"commitEditACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to CommitEdit action",
NULL, 0);
return;
}
/*
* Make sure we have a single param
*/
if (*nparams != 1)
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"commitEditACT", "badParms", "XbaeMatrix",
"XbaeMatrix: Wrong params for CommitEdit action, needs 1",
NULL, 0);
return;
}
/*
* Validate our param
*/
if (!strcmp(params[0], "True"))
unmap = True;
else if (!strcmp(params[0], "False"))
unmap = False;
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"commitEditACT", "badParm", "XbaeMatrix",
"XbaeMatrix: Bad parameter for CommitEdit action",
NULL, 0);
return;
}
(void)(*((XbaeMatrixWidgetClass)XtClass(mw))->matrix_class.commit_edit)
(mw, event, unmap);
}
static int
DoubleClick(mw, event, row, column)
XbaeMatrixWidget mw;
XEvent *event;
int row;
int column;
{
/* A double click in this instance is two clicks in the
same cell in a time period < double_click_interval */
Time current_time;
unsigned long delta;
static int ret = 0;
if (event->type == ButtonRelease)
{
/* If the button is released, store the current location and time -
next time through, if it's a button press event, we check for
double click */
mw->matrix.last_row = row;
mw->matrix.last_column = column;
if (ret) /* just had a double click */
mw->matrix.last_click_time = (Time)0;
else
mw->matrix.last_click_time = event->xbutton.time;
ret = 0;
return ret;
}
current_time = event->xbutton.time;
delta = current_time - mw->matrix.last_click_time;
if (row == mw->matrix.last_row && column == mw->matrix.last_column &&
delta < (unsigned long)mw->matrix.double_click_interval)
ret = 1;
else
ret = 0;
return ret;
}
/*ARGSUSED*/
static void
PushButton(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
{
XbaeMatrixButtonPressedStruct *button =
(XbaeMatrixButtonPressedStruct *)data;
XMotionEvent *motionEvent;
int x, y;
int row, column;
Boolean pressed = button->pressed;
CellType cell;
if (event->type == ButtonRelease)
{
button->grabbed = False;
XtRemoveGrab(w);
scrolling = False;
if (button->pressed)
{
/* If the button is still pressed, it has been released in the
same button that was pressed. "Unpress" it and call the
callbacks */
if (button->column == -1)
xbaeDrawRowLabel(button->mw, button->row, False);
else if (button->row == -1)
xbaeDrawColumnLabel(button->mw, button->column, False);
if (button->mw->matrix.label_activate_callback)
{
XbaeMatrixLabelActivateCallbackStruct call_data;
call_data.reason = XbaeLabelActivateReason;
call_data.event = event;
call_data.row_label = (button->column == -1);
call_data.row = button->row;
call_data.column = button->column;
if (button->column == -1)
call_data.label =
button->mw->matrix.row_labels[button->row];
else
call_data.label =
button->mw->matrix.column_labels[button->column];
XtCallCallbackList((Widget)button->mw,
button->mw->matrix.label_activate_callback,
(XtPointer)&call_data);
}
}
return;
}
if (event->type != MotionNotify) /* We want to be sure about this! */
return;
motionEvent = (XMotionEvent *)event;
x = motionEvent->x;
y = motionEvent->y;
if (!xbaeEventToXY(button->mw, event, &x, &y, &cell))
return;
if (xbaeXYToRowCol(button->mw, &x, &y, &row, &column, cell))
/* Moved off the labels */
pressed = False;
else
{
if (button->column != column || button->row != row)
/* Moved out of the button that was originally pressed */
pressed = False;
else if (button->column == column || button->row == row)
pressed = True;
}
/* If the status of whether or not the button should be pressed has
changed, redraw the appropriate visual */
if (pressed != button->pressed)
{
if (button->column == -1)
xbaeDrawRowLabel(button->mw, button->row, pressed);
else if (button->row == -1)
xbaeDrawColumnLabel(button->mw, button->column, pressed);
/* And set our struct's pressed member to the current setting */
button->pressed = pressed;
}
}
/*ARGSUSED*/
void
xbaeHandleClick(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
{
XbaeMatrixWidget mw = (XbaeMatrixWidget)data;
int x, y;
CellType cell;
int row, column;
Boolean translation;
/* if we have a double click and a callback - break out! */
if (event->type != ButtonPress && event->type != ButtonRelease)
return;
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
translation = xbaeXYToRowCol(mw, &x, &y, &row, &column, cell);
if (!translation &&
(mw->matrix.button_labels ||
(row == -1 && mw->matrix.column_button_labels &&
mw->matrix.column_button_labels[column]) ||
(column == -1 && mw->matrix.row_button_labels &&
mw->matrix.row_button_labels[row])) &&
((row == -1) ^ (column == -1)))
{
unsigned long event_mask;
XtAppContext appcontext;
XbaeMatrixButtonPressedStruct button;
/* If the row and column are invalid, return. If it is ButtonRelease
event, also return - the ButtonRelease events are handled in the
event handler loop below */
if (event->type != ButtonPress)
return;
if (column == -1 && event->type == ButtonPress)
/* row label */
xbaeDrawRowLabel(mw, row, True);
else if (row == -1 && event->type == ButtonPress)
/* Column label */
xbaeDrawColumnLabel(mw, column, True);
/* Action stations! */
event_mask = ButtonReleaseMask | PointerMotionMask;
scrolling = True;
XtAddGrab(w, True, False);
/* Copy the data needed to be passed to the event handler */
button.mw = mw;
button.row = row;
button.column = column;
button.pressed = True;
button.grabbed = True;
XtAddEventHandler(w, event_mask,
True, (XtEventHandler)PushButton,
(XtPointer)&button);
XtAddEventHandler(TextChild(mw), event_mask,
True, (XtEventHandler)PushButton,
(XtPointer)&button);
appcontext = XtWidgetToApplicationContext(w);
while (button.grabbed)
XtAppProcessEvent(appcontext, XtIMAll);
XtRemoveEventHandler(w, event_mask, True,
(XtEventHandler)PushButton,
(XtPointer)&button);
XtRemoveEventHandler(TextChild(mw), event_mask, True,
(XtEventHandler)PushButton,
(XtPointer)&button);
}
else if (translation && mw->matrix.default_action_callback &&
w != (Widget)mw &&
DoubleClick(mw, event, mw->matrix.current_row,
mw->matrix.current_column))
{
/* Put this as an else -> we don't want double clicks on labels
to be recognised */
XbaeMatrixDefaultActionCallbackStruct call_data;
if (row == -1 || column == -1)
return;
call_data.reason = XbaeDefaultActionReason;
call_data.event = event;
call_data.row = row;
call_data.column = column;
XtCallCallbackList((Widget)mw, mw->matrix.default_action_callback,
(XtPointer)&call_data);
}
}
/* ARGSUSED */
void
xbaeSelectCellACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
int x, y;
int row, column;
CellType cell;
XbaeMatrixSelectCellCallbackStruct call_data;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"xbaeSelectCellACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to SelectCell action",
NULL, 0);
return;
}
/*
* If we don't have a selectCellCallback, then return now
*/
if (!mw->matrix.select_cell_callback)
return;
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
/*
* Convert the point to a row,column. If it does not pick a valid
* cell, then return. If button up then use the last selected cell
* to make sure a valid button up event occurs when dragging out of
* the matrix
*/
if (!xbaeXYToRowCol(mw, &x, &y, &row, &column, cell))
{
if (event->type == ButtonRelease)
{
column = last_selected_column;
row = last_selected_row;
}
else
{
return;
}
}
/*
* Call our select_cell callbacks
*/
call_data.reason = XbaeSelectCellReason;
call_data.event = event;
if (scrolling)
{
call_data.row = last_row;
call_data.column = last_column;
}
else
{
call_data.row = row;
call_data.column = column;
}
last_selected_column = call_data.column;
last_selected_row = call_data.row;
call_data.selected_cells = mw->matrix.selected_cells;
call_data.cells = mw->matrix.cells;
call_data.num_params = *nparams;
call_data.params = params;
XtCallCallbackList((Widget)mw, mw->matrix.select_cell_callback,
(XtPointer)&call_data);
}
/* ARGSUSED */
void
xbaeTraverseNextACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w should be the textField widget.
*/
if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"traverseNextACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to TraverseNext action",
NULL, 0);
return;
}
/*
* Set the traversing direction flag. XmProcessTraversal may traverse
* to the Clip widget. If it does, then we will see this flag in
* the Clip focusCallback, TraverseInCB, and we will continue to traverse
* on out of the mw. yuck!
*/
mw->matrix.traversing = XmTRAVERSE_NEXT_TAB_GROUP;
(void)XmProcessTraversal(TextChild(mw), XmTRAVERSE_NEXT_TAB_GROUP);
mw->matrix.traversing = NOT_TRAVERSING;
}
/* ARGSUSED */
void
xbaeTraversePrevACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w should be the textField widget.
*/
if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"traversePrevACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to TraversePrev action",
NULL, 0);
return;
}
/*
* Set the traversing direction flag. XmProcessTraversal may traverse
* to the Clip widget. If it does, then we will see this flag in
* the Clip focusCallback, TraverseInCB, and we will continue to traverse
* on out of the mw. yuck!
*/
mw->matrix.traversing = (int)XmTRAVERSE_PREV_TAB_GROUP;
(void)XmProcessTraversal(TextChild(mw), XmTRAVERSE_PREV_TAB_GROUP);
mw->matrix.traversing = NOT_TRAVERSING;
}
static void
callSelectCellAction(mw, event)
XbaeMatrixWidget mw;
XEvent *event;
{
XbaeMatrixSelectCellCallbackStruct call_data;
Boolean old_scroll_select = mw->matrix.scroll_select;
mw->matrix.scroll_select = False;
call_data.reason = XbaeSelectCellReason;
call_data.event = event;
call_data.row = last_row;
call_data.column = last_column;
call_data.selected_cells = mw->matrix.selected_cells;
call_data.cells = mw->matrix.cells;
call_data.num_params = 1;
call_data.params = (char **)XtMalloc(sizeof(char *));
call_data.params[0] = "extend";
XtCallCallbackList(
(Widget)mw, mw->matrix.select_cell_callback,
(XtPointer)&call_data);
(void)XtFree((char *)call_data.params);
mw->matrix.scroll_select = old_scroll_select;
}
/*ARGSUSED*/
static void
checkScrollValues(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
{
XbaeMatrixScrollStruct *ss = (XbaeMatrixScrollStruct *)data;
XMotionEvent *motionEvent;
int x, y;
CellType cell;
Boolean inMatrix;
int distance = 0;
int halfRows;
int denom = 1;
int row, column;
int i;
ss->event = event;
if (event->type == ButtonRelease)
{
XtRemoveTimeOut(ss->timerID);
ss->grabbed = False;
if (ss->mw->matrix.selection_policy == XmMULTIPLE_SELECT ||
ss->mw->matrix.selection_policy == XmEXTENDED_SELECT)
callSelectCellAction(ss->mw, ss->event);
return;
}
if (!xbaeEventToXY(ss->mw, event, &x, &y, &cell))
return;
motionEvent = (XMotionEvent *)event;
/*
* In this instance, we don't care if a valid row and column are
* returned as we'll be the judge of the result
*/
inMatrix = xbaeXYToRowCol(ss->mw, &x, &y, &row, &column, cell);
/*
* Reset the flags, so the matrix stops scrolling when the
* pointer is moved back into the fixed columns/rows after a drag
* select in the fixed columns/rows which caused the matrix to
* scroll vertically/horizontally.
*/
ss->below = False;
ss->above = False;
ss->left = False;
ss->right = False;
if (inMatrix && cell == NonFixedCell)
{
ss->inClip = True;
return;
}
else
{
/*
* Calculate our position relative to the clip and adjust.
*/
if (motionEvent->y >= (int)(ss->cw->core.y + ss->cw->core.height))
{
/* Below the matrix */
distance = motionEvent->y - ss->cw->core.y - ss->cw->core.height;
ss->below = True;
ss->above = False;
/*
* If we are below the matrix, the current column may have
* still changed from horizontal motion.
*/
i = 0;
while (COLUMN_POSITION(ss->mw, i) < HORIZ_ORIGIN(ss->mw) +
motionEvent->x)
i++;
if (i <= ss->mw->matrix.columns && i > 0)
last_column = i - 1;
}
else if (motionEvent->y <= ss->cw->core.y)
{
/*
* Above the matrix - can't be both above and below at the same
* time unless we have two mouses!
*/
distance = ss->cw->core.y - motionEvent->y;
ss->below = False;
ss->above = True;
i = 0;
while (COLUMN_POSITION(ss->mw, i) < HORIZ_ORIGIN(ss->mw) +
motionEvent->x)
i++;
if (i > 0 && i <= ss->mw->matrix.columns)
last_column = i - 1;
}
if (motionEvent->x <= ss->cw->core.x)
{
/* To the left */
ss->left = True;
ss->right = False;
distance = Min(distance, ss->cw->core.x - motionEvent->x);
/*
* Check for any vertical motion
*/
if (!ss->below && !ss->above)
{
last_row = YtoRow(ss->mw, motionEvent->y -
COLUMN_LABEL_HEIGHT(ss->mw)) +
VERT_ORIGIN(ss->mw);
SANITY_CHECK_ROW(ss->mw, last_row);
}
}
else if (motionEvent->x >= (int)(ss->cw->core.x + ss->cw->core.width))
{
/* To the right */
ss->left = False;
ss->right = True;
distance = Min(distance, (int)(motionEvent->x - ss->cw->core.x -
ss->cw->core.width));
if (!ss->below && !ss->above)
{
last_row = YtoRow(ss->mw, motionEvent->y -
COLUMN_LABEL_HEIGHT(ss->mw)) +
VERT_ORIGIN(ss->mw);
SANITY_CHECK_ROW(ss->mw, last_row);
}
}
/*
* Adjust the value of the update interval based on the distance we
* are away from the matrix
*/
halfRows = distance / (ROW_HEIGHT(ss->mw) / 2);
/*
* Avoid use of the math library by doing a simple calculation
*/
for (i = 0; i < halfRows; i++)
denom *= 2;
ss->interval = DEFAULT_SCROLL_SPEED / (denom > 0 ? denom : 1);
if (ss->interval <= 0) /* Just to be on the safe side */
ss->interval = 1;
}
}
static void
updateScroll(data)
XtPointer data;
{
XbaeMatrixScrollStruct *ss = (XbaeMatrixScrollStruct *)data;
Boolean callCallback = False;
static int my_last_row = -1, my_last_column = -1;
if (!scrolling)
return;
if (my_last_column != last_column || my_last_row != last_row)
callCallback = True;
my_last_row = last_row;
my_last_column = last_column;
/*
* Off the clip widget - check there are cells that could
* be scrolled into a visible position. If there are,
* scroll them into view. If not, start setting the fixed
* rows and columns as the current row and column.
*/
if (ss->below && last_row < TRAILING_VERT_ORIGIN(ss->mw) - 1)
{
xbaeMakeRowVisible(ss->mw, ++last_row);
callCallback = True;
}
else if (ss->above && last_row > (int)ss->mw->matrix.fixed_rows)
{
xbaeMakeRowVisible(ss->mw, --last_row);
callCallback = True;
}
if (ss->right && last_column < TRAILING_HORIZ_ORIGIN(ss->mw) - 1)
{
xbaeMakeColumnVisible(ss->mw, ++last_column);
callCallback = True;
}
else if (ss->left && last_column > (int)ss->mw->matrix.fixed_columns)
{
xbaeMakeColumnVisible(ss->mw, --last_column);
callCallback = True;
}
if (callCallback &&
(ss->mw->matrix.selection_policy == XmMULTIPLE_SELECT ||
ss->mw->matrix.selection_policy == XmEXTENDED_SELECT))
callSelectCellAction(ss->mw, ss->event);
/*
* Flush the updates out to the server so we don't end up lagging
* behind too far and end up with a million redraw requests.
* Particularly for higher update speeds
*/
XFlush(XtDisplay((Widget)ss->mw));
ss->timerID = XtAppAddTimeOut(
ss->app_context, ss->interval, (XtTimerCallbackProc)updateScroll,
(XtPointer)ss);
}
/* ARGSUSED */
void
xbaeHandleMotionACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
XbaeClipWidget cw;
XMotionEvent *motionEvent;
XButtonEvent *buttonEvent;
int x, y, row, column;
CellType cell;
Boolean inMatrix;
if (scrolling)
return;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w could be Matrix, or the Clip or textField children of Matrix
*/
if (XtIsSubclass(w, xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)w;
else if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else {
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"handleMotionACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to HandleMotion action",
NULL, 0);
return;
}
motionEvent = (XMotionEvent *)event;
buttonEvent = (XButtonEvent *)event;
cw = (XbaeClipWidget)ClipChild(mw);
if (!xbaeEventToXY(mw, event, &x, &y, &cell))
return;
/*
* In this instance, we don't care if a valid row and column are
* returned as we'll be the judge of the result
*/
inMatrix = xbaeXYToRowCol(mw, &x, &y, &row, &column, cell);
if (inMatrix && cell == NonFixedCell)
{
/*
* If we are in a NonFixedCell, then we're cruisin'. Just
* update our position
*/
if (row != last_row || column != last_column)
{
if (row < mw->matrix.rows && column < mw->matrix.columns)
{
last_row = row;
last_column = column;
if (mw->matrix.selection_policy == XmMULTIPLE_SELECT ||
mw->matrix.selection_policy == XmEXTENDED_SELECT)
callSelectCellAction(mw, event);
}
}
}
else
{
XbaeMatrixScrollStruct scrollData;
Boolean cont;
/*
* Grab the pointer and add a timeout routine to start modifying
* the current row and/or column in the matrix. Also add an
* event handler to monitor the current distance outside the
* matrix so we can adjust the timeout routine to go faster when
* the pointer is further away from the matrix.
*/
scrolling = True;
XtAddGrab(w, True, False);
scrollData.mw = mw;
scrollData.cw = cw;
scrollData.event = event;
scrollData.interval = DEFAULT_SCROLL_SPEED;
scrollData.inClip = False;
scrollData.grabbed = True;
scrollData.app_context = XtWidgetToApplicationContext(w);
scrollData.above = scrollData.below = False;
scrollData.left = scrollData.right = False;
XtAddEventHandler(w, PointerMotionMask | ButtonReleaseMask,
True, (XtEventHandler)checkScrollValues,
(XtPointer)&scrollData);
/*
* Call checkScrollValues() to find out where exactly we are in
* relation to the clip widget
*/
checkScrollValues(w, (XtPointer)&scrollData, event, &cont);
/*
* The above / below / left / right members of the scrollData struct
* should now be set so we know where we should be moving. Let's
* get on with it, eh?
*/
updateScroll((XtPointer)&scrollData);
while (scrollData.grabbed && !scrollData.inClip)
XtAppProcessEvent(scrollData.app_context, XtIMAll);
XtRemoveEventHandler(w, PointerMotionMask | ButtonReleaseMask,
True, (XtEventHandler)checkScrollValues,
(XtPointer)&scrollData);
XtRemoveGrab(w);
/*
* We don't want the timeout getting called again as, in two lines,
* we'll be way out of scope!
*/
XtRemoveTimeOut(scrollData.timerID);
scrolling = False;
}
}
/* ARGSUSED */
void
xbaePageDownACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
char *down = "0";
int top;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w should be the textField widget.
*/
if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"pageDownACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to PageDown action",
NULL, 0);
return;
}
if (!XtIsManaged(VertScrollChild(mw)))
return;
/*
* Save the top row - if scrolling occurs, the text widget needs
* to be moved
*/
top = VERT_ORIGIN(mw);
XtCallActionProc(VertScrollChild(mw), "PageDownOrRight",
event, &down, 1);
if (VERT_ORIGIN(mw) != top)
/*
* Position the cursor at the top most non fixed row if there was
* a page down
*/
XbaeMatrixEditCell((Widget)mw, VERT_ORIGIN(mw) +
mw->matrix.fixed_rows, mw->matrix.current_column);
}
/* ARGSUSED */
void
xbaePageUpACT(w, event, params, nparams)
Widget w;
XEvent *event;
String *params;
Cardinal *nparams;
{
XbaeMatrixWidget mw;
char *up = "0";
int top;
/*
* Get Matrix widget and make sure it is a Matrix subclass.
* w should be the textField widget.
*/
if (XtIsSubclass(XtParent(w), xbaeMatrixWidgetClass))
mw = (XbaeMatrixWidget)XtParent(w);
else
{
XtAppWarningMsg(
XtWidgetToApplicationContext(w),
"pageUpACT", "badWidget", "XbaeMatrix",
"XbaeMatrix: Bad widget passed to PageUp action",
NULL, 0);
return;
}
if (!XtIsManaged(VertScrollChild(mw)))
return;
/*
* Save the top row - if scrolling occurs, the text widget needs
* to be moved
*/
top = VERT_ORIGIN(mw);
XtCallActionProc(VertScrollChild(mw), "PageUpOrLeft",
event, &up, 1);
if (VERT_ORIGIN(mw) != top)
/*
* Position the cursor at the top most non fixed row if there was
* a page down
*/
XbaeMatrixEditCell((Widget)mw, VERT_ORIGIN(mw) +
mw->matrix.fixed_rows, mw->matrix.current_column);
}
|