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 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <memory>
#include <i18nutil/searchopt.hxx>
#include <o3tl/deleter.hxx>
#include <vcl/textview.hxx>
#include <vcl/texteng.hxx>
#include <vcl/settings.hxx>
#include "textdoc.hxx"
#include <vcl/textdata.hxx>
#include <vcl/xtextedt.hxx>
#include "textdat2.hxx"
#include <vcl/commandevent.hxx>
#include <vcl/inputctx.hxx>
#include <svl/undo.hxx>
#include <vcl/cursor.hxx>
#include <vcl/weld.hxx>
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <tools/stream.hxx>
#include <sal/log.hxx>
#include <sot/formats.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
#include <com/sun/star/util/SearchFlags.hpp>
#include <vcl/edit.hxx>
#include <sot/exchange.hxx>
#include <algorithm>
#include <cstddef>
TETextDataObject::TETextDataObject( const OUString& rText ) : maText( rText )
{
}
// css::uno::XInterface
css::uno::Any TETextDataObject::queryInterface( const css::uno::Type & rType )
{
css::uno::Any aRet = ::cppu::queryInterface( rType, static_cast< css::datatransfer::XTransferable* >(this) );
return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
}
// css::datatransfer::XTransferable
css::uno::Any TETextDataObject::getTransferData( const css::datatransfer::DataFlavor& rFlavor )
{
css::uno::Any aAny;
SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
if ( nT == SotClipboardFormatId::STRING )
{
aAny <<= maText;
}
else if ( nT == SotClipboardFormatId::HTML )
{
sal_uLong nLen = GetHTMLStream().TellEnd();
GetHTMLStream().Seek(0);
css::uno::Sequence< sal_Int8 > aSeq( nLen );
memcpy( aSeq.getArray(), GetHTMLStream().GetData(), nLen );
aAny <<= aSeq;
}
else
{
throw css::datatransfer::UnsupportedFlavorException();
}
return aAny;
}
css::uno::Sequence< css::datatransfer::DataFlavor > TETextDataObject::getTransferDataFlavors( )
{
GetHTMLStream().Seek( STREAM_SEEK_TO_END );
bool bHTML = GetHTMLStream().Tell() > 0;
css::uno::Sequence< css::datatransfer::DataFlavor > aDataFlavors( bHTML ? 2 : 1 );
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aDataFlavors.getArray()[0] );
if ( bHTML )
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::HTML, aDataFlavors.getArray()[1] );
return aDataFlavors;
}
sal_Bool TETextDataObject::isDataFlavorSupported( const css::datatransfer::DataFlavor& rFlavor )
{
SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
return ( nT == SotClipboardFormatId::STRING );
}
struct ImpTextView
{
ExtTextEngine* mpTextEngine;
VclPtr<vcl::Window> mpWindow;
TextSelection maSelection;
Point maStartDocPos;
std::unique_ptr<vcl::Cursor, o3tl::default_delete<vcl::Cursor>> mpCursor;
std::unique_ptr<TextDDInfo, o3tl::default_delete<TextDDInfo>> mpDDInfo;
std::unique_ptr<SelectionEngine> mpSelEngine;
std::unique_ptr<TextSelFunctionSet> mpSelFuncSet;
css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
sal_uInt16 mnTravelXPos;
bool mbAutoScroll : 1;
bool mbInsertMode : 1;
bool mbReadOnly : 1;
bool mbPaintSelection : 1;
bool mbAutoIndent : 1;
bool mbHighlightSelection : 1;
bool mbCursorEnabled : 1;
bool mbClickedInSelection : 1;
bool mbCursorAtEndOfLine;
};
TextView::TextView( ExtTextEngine* pEng, vcl::Window* pWindow ) :
mpImpl(new ImpTextView)
{
pWindow->EnableRTL( false );
mpImpl->mpWindow = pWindow;
mpImpl->mpTextEngine = pEng;
mpImpl->mbPaintSelection = true;
mpImpl->mbAutoScroll = true;
mpImpl->mbInsertMode = true;
mpImpl->mbReadOnly = false;
mpImpl->mbHighlightSelection = false;
mpImpl->mbAutoIndent = false;
mpImpl->mbCursorEnabled = true;
mpImpl->mbClickedInSelection = false;
// mbInSelection = false;
mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
mpImpl->mpSelFuncSet = std::make_unique<TextSelFunctionSet>( this );
mpImpl->mpSelEngine = std::make_unique<SelectionEngine>( mpImpl->mpWindow, mpImpl->mpSelFuncSet.get() );
mpImpl->mpSelEngine->SetSelectionMode( SelectionMode::Range );
mpImpl->mpSelEngine->EnableDrag( true );
mpImpl->mpCursor.reset(new vcl::Cursor);
mpImpl->mpCursor->Show();
pWindow->SetCursor( mpImpl->mpCursor.get() );
pWindow->SetInputContext( InputContext( pEng->GetFont(), InputContextFlags::Text|InputContextFlags::ExtText ) );
if ( pWindow->GetSettings().GetStyleSettings().GetSelectionOptions() & SelectionOptions::Invert )
mpImpl->mbHighlightSelection = true;
pWindow->SetLineColor();
if ( pWindow->GetDragGestureRecognizer().is() )
{
vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper( this );
mpImpl->mxDnDListener = pDnDWrapper;
css::uno::Reference< css::datatransfer::dnd::XDragGestureListener> xDGL( mpImpl->mxDnDListener, css::uno::UNO_QUERY );
pWindow->GetDragGestureRecognizer()->addDragGestureListener( xDGL );
css::uno::Reference< css::datatransfer::dnd::XDropTargetListener> xDTL( xDGL, css::uno::UNO_QUERY );
pWindow->GetDropTarget()->addDropTargetListener( xDTL );
pWindow->GetDropTarget()->setActive( true );
pWindow->GetDropTarget()->setDefaultActions( css::datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE );
}
}
TextView::~TextView()
{
mpImpl->mpSelEngine.reset();
mpImpl->mpSelFuncSet.reset();
if ( mpImpl->mpWindow->GetCursor() == mpImpl->mpCursor.get() )
mpImpl->mpWindow->SetCursor( nullptr );
mpImpl->mpCursor.reset();
mpImpl->mpDDInfo.reset();
}
void TextView::Invalidate()
{
mpImpl->mpWindow->Invalidate();
}
void TextView::SetSelection( const TextSelection& rTextSel, bool bGotoCursor )
{
// if someone left an empty attribute and then the Outliner manipulated the selection
if ( !mpImpl->maSelection.HasRange() )
mpImpl->mpTextEngine->CursorMoved( mpImpl->maSelection.GetStart().GetPara() );
// if the selection is manipulated after a KeyInput
mpImpl->mpTextEngine->CheckIdleFormatter();
HideSelection();
TextSelection aNewSel( rTextSel );
mpImpl->mpTextEngine->ValidateSelection( aNewSel );
ImpSetSelection( aNewSel );
ShowSelection();
ShowCursor( bGotoCursor );
}
void TextView::SetSelection( const TextSelection& rTextSel )
{
SetSelection( rTextSel, mpImpl->mbAutoScroll );
}
const TextSelection& TextView::GetSelection() const
{
return mpImpl->maSelection;
}
TextSelection& TextView::GetSelection()
{
return mpImpl->maSelection;
}
void TextView::DeleteSelected()
{
// HideSelection();
mpImpl->mpTextEngine->UndoActionStart();
TextPaM aPaM = mpImpl->mpTextEngine->ImpDeleteText( mpImpl->maSelection );
mpImpl->mpTextEngine->UndoActionEnd();
ImpSetSelection( aPaM );
mpImpl->mpTextEngine->FormatAndUpdate( this );
ShowCursor();
}
void TextView::ImpPaint(vcl::RenderContext& rRenderContext, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection)
{
if (!mpImpl->mbPaintSelection)
{
pSelection = nullptr;
}
else
{
// set correct background color;
// unfortunately we cannot detect if it has changed
vcl::Font aFont = mpImpl->mpTextEngine->GetFont();
Color aColor = rRenderContext.GetBackground().GetColor();
aColor.SetTransparency(0);
if (aColor != aFont.GetFillColor())
{
if (aFont.IsTransparent())
aColor = COL_TRANSPARENT;
aFont.SetFillColor(aColor);
mpImpl->mpTextEngine->maFont = aFont;
}
}
mpImpl->mpTextEngine->ImpPaint(&rRenderContext, rStartPos, pPaintArea, pSelection);
}
void TextView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
ImpPaint(rRenderContext, rRect);
}
void TextView::ImpPaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
if ( !mpImpl->mpTextEngine->GetUpdateMode() || mpImpl->mpTextEngine->IsInUndo() )
return;
TextSelection *pDrawSelection = nullptr;
if (!mpImpl->mbHighlightSelection && mpImpl->maSelection.HasRange())
pDrawSelection = &mpImpl->maSelection;
Point aStartPos = ImpGetOutputStartPos(mpImpl->maStartDocPos);
ImpPaint(rRenderContext, aStartPos, &rRect, pDrawSelection);
if (mpImpl->mbHighlightSelection)
ImpHighlight(mpImpl->maSelection);
}
void TextView::ImpHighlight( const TextSelection& rSel )
{
TextSelection aSel( rSel );
aSel.Justify();
if ( aSel.HasRange() && !mpImpl->mpTextEngine->IsInUndo() && mpImpl->mpTextEngine->GetUpdateMode() )
{
mpImpl->mpCursor->Hide();
SAL_WARN_IF( mpImpl->mpTextEngine->mpIdleFormatter->IsActive(), "vcl", "ImpHighlight: Not formatted!" );
tools::Rectangle aVisArea( mpImpl->maStartDocPos, mpImpl->mpWindow->GetOutputSizePixel() );
long nY = 0;
const sal_uInt32 nStartPara = aSel.GetStart().GetPara();
const sal_uInt32 nEndPara = aSel.GetEnd().GetPara();
for ( sal_uInt32 nPara = 0; nPara <= nEndPara; ++nPara )
{
const long nParaHeight = mpImpl->mpTextEngine->CalcParaHeight( nPara );
if ( ( nPara >= nStartPara ) && ( ( nY + nParaHeight ) > aVisArea.Top() ) )
{
TEParaPortion* pTEParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( nPara );
std::vector<TextLine>::size_type nStartLine = 0;
std::vector<TextLine>::size_type nEndLine = pTEParaPortion->GetLines().size() -1;
if ( nPara == nStartPara )
nStartLine = pTEParaPortion->GetLineNumber( aSel.GetStart().GetIndex(), false );
if ( nPara == nEndPara )
nEndLine = pTEParaPortion->GetLineNumber( aSel.GetEnd().GetIndex(), true );
// iterate over all lines
for ( std::vector<TextLine>::size_type nLine = nStartLine; nLine <= nEndLine; nLine++ )
{
TextLine& rLine = pTEParaPortion->GetLines()[ nLine ];
sal_Int32 nStartIndex = rLine.GetStart();
sal_Int32 nEndIndex = rLine.GetEnd();
if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) )
nStartIndex = aSel.GetStart().GetIndex();
if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) )
nEndIndex = aSel.GetEnd().GetIndex();
// possible if at the beginning of a wrapped line
if ( nEndIndex < nStartIndex )
nEndIndex = nStartIndex;
tools::Rectangle aTmpRect( mpImpl->mpTextEngine->GetEditCursor( TextPaM( nPara, nStartIndex ), false ) );
aTmpRect.AdjustTop(nY );
aTmpRect.AdjustBottom(nY );
Point aTopLeft( aTmpRect.TopLeft() );
aTmpRect = mpImpl->mpTextEngine->GetEditCursor( TextPaM( nPara, nEndIndex ), true );
aTmpRect.AdjustTop(nY );
aTmpRect.AdjustBottom(nY );
Point aBottomRight( aTmpRect.BottomRight() );
aBottomRight.AdjustX( -1 );
// only paint if in the visible region
if ( ( aTopLeft.X() < aBottomRight.X() ) && ( aBottomRight.Y() >= aVisArea.Top() ) )
{
Point aPnt1( GetWindowPos( aTopLeft ) );
Point aPnt2( GetWindowPos( aBottomRight ) );
tools::Rectangle aRect( aPnt1, aPnt2 );
mpImpl->mpWindow->Invert( aRect );
}
}
}
nY += nParaHeight;
if ( nY >= aVisArea.Bottom() )
break;
}
}
}
void TextView::ImpSetSelection( const TextSelection& rSelection )
{
if (rSelection != mpImpl->maSelection)
{
bool bCaret = false, bSelection = false;
const TextPaM &rEnd = rSelection.GetEnd();
const TextPaM &rOldEnd = mpImpl->maSelection.GetEnd();
bool bGap = rSelection.HasRange(), bOldGap = mpImpl->maSelection.HasRange();
if (rEnd != rOldEnd)
bCaret = true;
if (bGap || bOldGap)
bSelection = true;
mpImpl->maSelection = rSelection;
if (bSelection)
mpImpl->mpTextEngine->Broadcast(TextHint(SfxHintId::TextViewSelectionChanged));
if (bCaret)
mpImpl->mpTextEngine->Broadcast(TextHint(SfxHintId::TextViewCaretChanged));
}
}
void TextView::ShowSelection()
{
ImpShowHideSelection();
}
void TextView::HideSelection()
{
ImpShowHideSelection();
}
void TextView::ShowSelection( const TextSelection& rRange )
{
ImpShowHideSelection( &rRange );
}
void TextView::ImpShowHideSelection(const TextSelection* pRange)
{
const TextSelection* pRangeOrSelection = pRange ? pRange : &mpImpl->maSelection;
if ( pRangeOrSelection->HasRange() )
{
if ( mpImpl->mbHighlightSelection )
{
ImpHighlight( *pRangeOrSelection );
}
else
{
if( mpImpl->mpWindow->IsPaintTransparent() )
mpImpl->mpWindow->Invalidate();
else
{
TextSelection aRange( *pRangeOrSelection );
aRange.Justify();
bool bVisCursor = mpImpl->mpCursor->IsVisible();
mpImpl->mpCursor->Hide();
Invalidate();
if (bVisCursor)
mpImpl->mpCursor->Show();
}
}
}
}
bool TextView::KeyInput( const KeyEvent& rKeyEvent )
{
bool bDone = true;
bool bModified = false;
bool bMoved = false;
bool bEndKey = false; // special CursorPosition
bool bAllowIdle = true;
// check mModified;
// the local bModified is not set e.g. by Cut/Paste, as here
// the update happens somewhere else
bool bWasModified = mpImpl->mpTextEngine->IsModified();
mpImpl->mpTextEngine->SetModified( false );
TextSelection aCurSel( mpImpl->maSelection );
TextSelection aOldSel( aCurSel );
sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode();
KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
if ( eFunc != KeyFuncType::DONTKNOW )
{
switch ( eFunc )
{
case KeyFuncType::CUT:
{
if ( !mpImpl->mbReadOnly )
Cut();
}
break;
case KeyFuncType::COPY:
{
Copy();
}
break;
case KeyFuncType::PASTE:
{
if ( !mpImpl->mbReadOnly )
Paste();
}
break;
case KeyFuncType::UNDO:
{
if ( !mpImpl->mbReadOnly )
Undo();
}
break;
case KeyFuncType::REDO:
{
if ( !mpImpl->mbReadOnly )
Redo();
}
break;
default: // might get processed below
eFunc = KeyFuncType::DONTKNOW;
}
}
if ( eFunc == KeyFuncType::DONTKNOW )
{
switch ( nCode )
{
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
case KEY_HOME:
case KEY_END:
case KEY_PAGEUP:
case KEY_PAGEDOWN:
case css::awt::Key::MOVE_WORD_FORWARD:
case css::awt::Key::SELECT_WORD_FORWARD:
case css::awt::Key::MOVE_WORD_BACKWARD:
case css::awt::Key::SELECT_WORD_BACKWARD:
case css::awt::Key::MOVE_TO_BEGIN_OF_LINE:
case css::awt::Key::MOVE_TO_END_OF_LINE:
case css::awt::Key::SELECT_TO_BEGIN_OF_LINE:
case css::awt::Key::SELECT_TO_END_OF_LINE:
case css::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
case css::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
case css::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
case css::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
case css::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
case css::awt::Key::MOVE_TO_END_OF_DOCUMENT:
case css::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
case css::awt::Key::SELECT_TO_END_OF_DOCUMENT:
{
if ( ( !rKeyEvent.GetKeyCode().IsMod2() || ( nCode == KEY_LEFT ) || ( nCode == KEY_RIGHT ) )
&& !( rKeyEvent.GetKeyCode().IsMod1() && ( nCode == KEY_PAGEUP || nCode == KEY_PAGEDOWN ) ) )
{
aCurSel = ImpMoveCursor( rKeyEvent );
if ( aCurSel.HasRange() ) {
css::uno::Reference<css::datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
Copy( aSelection );
}
bMoved = true;
if ( nCode == KEY_END )
bEndKey = true;
}
else
bDone = false;
}
break;
case KEY_BACKSPACE:
case KEY_DELETE:
case css::awt::Key::DELETE_WORD_BACKWARD:
case css::awt::Key::DELETE_WORD_FORWARD:
case css::awt::Key::DELETE_TO_BEGIN_OF_LINE:
case css::awt::Key::DELETE_TO_END_OF_LINE:
{
if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsMod2() )
{
sal_uInt8 nDel = ( nCode == KEY_DELETE ) ? DEL_RIGHT : DEL_LEFT;
sal_uInt8 nMode = rKeyEvent.GetKeyCode().IsMod1() ? DELMODE_RESTOFWORD : DELMODE_SIMPLE;
if ( ( nMode == DELMODE_RESTOFWORD ) && rKeyEvent.GetKeyCode().IsShift() )
nMode = DELMODE_RESTOFCONTENT;
switch( nCode )
{
case css::awt::Key::DELETE_WORD_BACKWARD:
nDel = DEL_LEFT;
nMode = DELMODE_RESTOFWORD;
break;
case css::awt::Key::DELETE_WORD_FORWARD:
nDel = DEL_RIGHT;
nMode = DELMODE_RESTOFWORD;
break;
case css::awt::Key::DELETE_TO_BEGIN_OF_LINE:
nDel = DEL_LEFT;
nMode = DELMODE_RESTOFCONTENT;
break;
case css::awt::Key::DELETE_TO_END_OF_LINE:
nDel = DEL_RIGHT;
nMode = DELMODE_RESTOFCONTENT;
break;
default: break;
}
mpImpl->mpTextEngine->UndoActionStart();
aCurSel = ImpDelete( nDel, nMode );
mpImpl->mpTextEngine->UndoActionEnd();
bModified = true;
bAllowIdle = false;
}
else
bDone = false;
}
break;
case KEY_TAB:
{
if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsShift() &&
!rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() &&
ImplCheckTextLen( OUString('x') ) )
{
aCurSel = mpImpl->mpTextEngine->ImpInsertText( aCurSel, '\t', !IsInsertMode() );
bModified = true;
}
else
bDone = false;
}
break;
case KEY_RETURN:
{
// do not swallow Shift-RETURN, as this would disable multi-line entries
// in dialogs & property editors
if ( !mpImpl->mbReadOnly && !rKeyEvent.GetKeyCode().IsMod1() &&
!rKeyEvent.GetKeyCode().IsMod2() && ImplCheckTextLen( OUString('x') ) )
{
mpImpl->mpTextEngine->UndoActionStart();
aCurSel = mpImpl->mpTextEngine->ImpInsertParaBreak( aCurSel );
if ( mpImpl->mbAutoIndent )
{
TextNode* pPrev = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aCurSel.GetEnd().GetPara() - 1 ].get();
sal_Int32 n = 0;
while ( ( n < pPrev->GetText().getLength() ) && (
( pPrev->GetText()[ n ] == ' ' ) ||
( pPrev->GetText()[ n ] == '\t' ) ) )
{
n++;
}
if ( n )
aCurSel = mpImpl->mpTextEngine->ImpInsertText( aCurSel, pPrev->GetText().copy( 0, n ) );
}
mpImpl->mpTextEngine->UndoActionEnd();
bModified = true;
}
else
bDone = false;
}
break;
case KEY_INSERT:
{
if ( !mpImpl->mbReadOnly )
SetInsertMode( !IsInsertMode() );
}
break;
default:
{
if ( TextEngine::IsSimpleCharInput( rKeyEvent ) )
{
sal_Unicode nCharCode = rKeyEvent.GetCharCode();
if ( !mpImpl->mbReadOnly && ImplCheckTextLen( OUString(nCharCode) ) ) // otherwise swallow the character anyway
{
aCurSel = mpImpl->mpTextEngine->ImpInsertText( nCharCode, aCurSel, !IsInsertMode(), true );
bModified = true;
}
}
else
bDone = false;
}
}
}
if ( aCurSel != aOldSel ) // Check if changed, maybe other method already changed mpImpl->maSelection, don't overwrite that!
ImpSetSelection( aCurSel );
if ( ( nCode != KEY_UP ) && ( nCode != KEY_DOWN ) )
mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
if ( bModified )
{
// Idle-Formatter only if AnyInput
if ( bAllowIdle && Application::AnyInput( VclInputFlags::KEYBOARD) )
mpImpl->mpTextEngine->IdleFormatAndUpdate( this );
else
mpImpl->mpTextEngine->FormatAndUpdate( this);
}
else if ( bMoved )
{
// selection is painted now in ImpMoveCursor
ImpShowCursor( mpImpl->mbAutoScroll, true, bEndKey );
}
if ( mpImpl->mpTextEngine->IsModified() )
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) );
else if ( bWasModified )
mpImpl->mpTextEngine->SetModified( true );
return bDone;
}
void TextView::MouseButtonUp( const MouseEvent& rMouseEvent )
{
mpImpl->mbClickedInSelection = false;
mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
mpImpl->mpSelEngine->SelMouseButtonUp( rMouseEvent );
if ( rMouseEvent.IsMiddle() && !IsReadOnly() &&
( GetWindow()->GetSettings().GetMouseSettings().GetMiddleButtonAction() == MouseMiddleButtonAction::PasteSelection ) )
{
css::uno::Reference<css::datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
Paste( aSelection );
if ( mpImpl->mpTextEngine->IsModified() )
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) );
}
else if ( rMouseEvent.IsLeft() && GetSelection().HasRange() )
{
css::uno::Reference<css::datatransfer::clipboard::XClipboard> aSelection(GetWindow()->GetPrimarySelection());
Copy( aSelection );
}
}
void TextView::MouseButtonDown( const MouseEvent& rMouseEvent )
{
mpImpl->mpTextEngine->CheckIdleFormatter(); // for fast typing and MouseButtonDown
mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
mpImpl->mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() );
mpImpl->mpTextEngine->SetActiveView( this );
mpImpl->mpSelEngine->SelMouseButtonDown( rMouseEvent );
// mbu 20.01.2005 - SelMouseButtonDown() possibly triggers a 'selection changed'
// notification. The appropriate handler could change the current selection,
// which is the case in the MailMerge address block control. To enable select'n'drag
// we need to reevaluate the selection after the notification has been fired.
mpImpl->mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() );
// special cases
if ( !rMouseEvent.IsShift() && ( rMouseEvent.GetClicks() >= 2 ) )
{
if ( rMouseEvent.IsMod2() )
{
HideSelection();
ImpSetSelection( mpImpl->maSelection.GetEnd() );
SetCursorAtPoint( rMouseEvent.GetPosPixel() ); // not set by SelectionEngine for MOD2
}
if ( rMouseEvent.GetClicks() == 2 )
{
// select word
if ( mpImpl->maSelection.GetEnd().GetIndex() < mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection.GetEnd().GetPara() ) )
{
HideSelection();
// tdf#57879 - expand selection to include connector punctuations
TextSelection aNewSel;
mpImpl->mpTextEngine->GetWord( mpImpl->maSelection.GetEnd(), &aNewSel.GetStart(), &aNewSel.GetEnd() );
ImpSetSelection( aNewSel );
ShowSelection();
ShowCursor();
}
}
else if ( rMouseEvent.GetClicks() == 3 )
{
// select paragraph
if ( mpImpl->maSelection.GetStart().GetIndex() || ( mpImpl->maSelection.GetEnd().GetIndex() < mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection.GetEnd().GetPara() ) ) )
{
HideSelection();
TextSelection aNewSel( mpImpl->maSelection );
aNewSel.GetStart().GetIndex() = 0;
aNewSel.GetEnd().GetIndex() = mpImpl->mpTextEngine->mpDoc->GetNodes()[ mpImpl->maSelection.GetEnd().GetPara() ]->GetText().getLength();
ImpSetSelection( aNewSel );
ShowSelection();
ShowCursor();
}
}
}
}
void TextView::MouseMove( const MouseEvent& rMouseEvent )
{
mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
mpImpl->mpSelEngine->SelMouseMove( rMouseEvent );
}
void TextView::Command( const CommandEvent& rCEvt )
{
mpImpl->mpTextEngine->CheckIdleFormatter(); // for fast typing and MouseButtonDown
mpImpl->mpTextEngine->SetActiveView( this );
if ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput )
{
DeleteSelected();
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ GetSelection().GetEnd().GetPara() ].get();
mpImpl->mpTextEngine->mpIMEInfos = std::make_unique<TEIMEInfos>( GetSelection().GetEnd(), pNode->GetText().copy( GetSelection().GetEnd().GetIndex() ) );
mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite = !IsInsertMode();
}
else if ( rCEvt.GetCommand() == CommandEventId::EndExtTextInput )
{
SAL_WARN_IF( !mpImpl->mpTextEngine->mpIMEInfos, "vcl", "CommandEventId::EndExtTextInput => No Start ?" );
if( mpImpl->mpTextEngine->mpIMEInfos )
{
TEParaPortion* pPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara() );
pPortion->MarkSelectionInvalid( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex() );
bool bInsertMode = !mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite;
mpImpl->mpTextEngine->mpIMEInfos.reset();
mpImpl->mpTextEngine->TextModified();
mpImpl->mpTextEngine->FormatAndUpdate( this );
SetInsertMode( bInsertMode );
if ( mpImpl->mpTextEngine->IsModified() )
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) );
}
}
else if ( rCEvt.GetCommand() == CommandEventId::ExtTextInput )
{
SAL_WARN_IF( !mpImpl->mpTextEngine->mpIMEInfos, "vcl", "CommandEventId::ExtTextInput => No Start ?" );
if( mpImpl->mpTextEngine->mpIMEInfos )
{
const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData();
if ( !pData->IsOnlyCursorChanged() )
{
TextSelection aSelect( mpImpl->mpTextEngine->mpIMEInfos->aPos );
aSelect.GetEnd().GetIndex() += mpImpl->mpTextEngine->mpIMEInfos->nLen;
aSelect = mpImpl->mpTextEngine->ImpDeleteText( aSelect );
aSelect = mpImpl->mpTextEngine->ImpInsertText( aSelect, pData->GetText() );
if ( mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite )
{
const sal_Int32 nOldIMETextLen = mpImpl->mpTextEngine->mpIMEInfos->nLen;
const sal_Int32 nNewIMETextLen = pData->GetText().getLength();
if ( ( nOldIMETextLen > nNewIMETextLen ) &&
( nNewIMETextLen < mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.getLength() ) )
{
// restore old characters
sal_Int32 nRestore = nOldIMETextLen - nNewIMETextLen;
TextPaM aPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos );
aPaM.GetIndex() += nNewIMETextLen;
mpImpl->mpTextEngine->ImpInsertText( aPaM, mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.copy( nNewIMETextLen, nRestore ) );
}
else if ( ( nOldIMETextLen < nNewIMETextLen ) &&
( nOldIMETextLen < mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.getLength() ) )
{
// overwrite
const sal_Int32 nOverwrite = std::min( nNewIMETextLen, mpImpl->mpTextEngine->mpIMEInfos->aOldTextAfterStartPos.getLength() ) - nOldIMETextLen;
SAL_WARN_IF( !nOverwrite || (nOverwrite >= 0xFF00), "vcl", "IME Overwrite?!" );
TextPaM aPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos );
aPaM.GetIndex() += nNewIMETextLen;
TextSelection aSel( aPaM );
aSel.GetEnd().GetIndex() += nOverwrite;
mpImpl->mpTextEngine->ImpDeleteText( aSel );
}
}
if ( pData->GetTextAttr() )
{
mpImpl->mpTextEngine->mpIMEInfos->CopyAttribs( pData->GetTextAttr(), pData->GetText().getLength() );
}
else
{
mpImpl->mpTextEngine->mpIMEInfos->DestroyAttribs();
}
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara() );
pPPortion->MarkSelectionInvalid( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex() );
mpImpl->mpTextEngine->FormatAndUpdate( this );
}
TextSelection aNewSel = TextPaM( mpImpl->mpTextEngine->mpIMEInfos->aPos.GetPara(), mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex()+pData->GetCursorPos() );
SetSelection( aNewSel );
SetInsertMode( !pData->IsCursorOverwrite() );
if ( pData->IsCursorVisible() )
ShowCursor();
else
HideCursor();
}
}
else if ( rCEvt.GetCommand() == CommandEventId::CursorPos )
{
if ( mpImpl->mpTextEngine->mpIMEInfos && mpImpl->mpTextEngine->mpIMEInfos->nLen )
{
TextPaM aPaM( GetSelection().GetEnd() );
tools::Rectangle aR1 = mpImpl->mpTextEngine->PaMtoEditCursor( aPaM );
sal_Int32 nInputEnd = mpImpl->mpTextEngine->mpIMEInfos->aPos.GetIndex() + mpImpl->mpTextEngine->mpIMEInfos->nLen;
if ( !mpImpl->mpTextEngine->IsFormatted() )
mpImpl->mpTextEngine->FormatDoc();
TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
std::vector<TextLine>::size_type nLine = pParaPortion->GetLineNumber( aPaM.GetIndex(), true );
TextLine& rLine = pParaPortion->GetLines()[ nLine ];
if ( nInputEnd > rLine.GetEnd() )
nInputEnd = rLine.GetEnd();
tools::Rectangle aR2 = mpImpl->mpTextEngine->PaMtoEditCursor( TextPaM( aPaM.GetPara(), nInputEnd ) );
long nWidth = aR2.Left()-aR1.Right();
aR1.Move( -GetStartDocPos().X(), -GetStartDocPos().Y() );
GetWindow()->SetCursorRect( &aR1, nWidth );
}
else
{
GetWindow()->SetCursorRect();
}
}
else
{
mpImpl->mpSelEngine->Command( rCEvt );
}
}
void TextView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
{
// this setting has more weight
if ( !mpImpl->mbAutoScroll )
bGotoCursor = false;
ImpShowCursor( bGotoCursor, bForceVisCursor, false );
}
void TextView::HideCursor()
{
mpImpl->mpCursor->Hide();
}
void TextView::Scroll( long ndX, long ndY )
{
SAL_WARN_IF( !mpImpl->mpTextEngine->IsFormatted(), "vcl", "Scroll: Not formatted!" );
if ( !ndX && !ndY )
return;
Point aNewStartPos( mpImpl->maStartDocPos );
// Vertical:
aNewStartPos.AdjustY( -ndY );
if ( aNewStartPos.Y() < 0 )
aNewStartPos.setY( 0 );
// Horizontal:
aNewStartPos.AdjustX( -ndX );
if ( aNewStartPos.X() < 0 )
aNewStartPos.setX( 0 );
long nDiffX = mpImpl->maStartDocPos.X() - aNewStartPos.X();
long nDiffY = mpImpl->maStartDocPos.Y() - aNewStartPos.Y();
if ( nDiffX || nDiffY )
{
bool bVisCursor = mpImpl->mpCursor->IsVisible();
mpImpl->mpCursor->Hide();
mpImpl->mpWindow->PaintImmediately();
mpImpl->maStartDocPos = aNewStartPos;
if ( mpImpl->mpTextEngine->IsRightToLeft() )
nDiffX = -nDiffX;
mpImpl->mpWindow->Scroll( nDiffX, nDiffY );
mpImpl->mpWindow->PaintImmediately();
mpImpl->mpCursor->SetPos( mpImpl->mpCursor->GetPos() + Point( nDiffX, nDiffY ) );
if ( bVisCursor && !mpImpl->mbReadOnly )
mpImpl->mpCursor->Show();
}
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextViewScrolled ) );
}
void TextView::Undo()
{
mpImpl->mpTextEngine->SetActiveView( this );
mpImpl->mpTextEngine->GetUndoManager().Undo();
}
void TextView::Redo()
{
mpImpl->mpTextEngine->SetActiveView( this );
mpImpl->mpTextEngine->GetUndoManager().Redo();
}
void TextView::Cut()
{
mpImpl->mpTextEngine->UndoActionStart();
Copy();
DeleteSelected();
mpImpl->mpTextEngine->UndoActionEnd();
}
void TextView::Copy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard )
{
if ( rxClipboard.is() )
{
TETextDataObject* pDataObj = new TETextDataObject( GetSelected() );
SolarMutexReleaser aReleaser;
try
{
rxClipboard->setContents( pDataObj, nullptr );
css::uno::Reference< css::datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, css::uno::UNO_QUERY );
if( xFlushableClipboard.is() )
xFlushableClipboard->flushClipboard();
}
catch( const css::uno::Exception& )
{
}
}
}
void TextView::Copy()
{
css::uno::Reference<css::datatransfer::clipboard::XClipboard> aClipboard(GetWindow()->GetClipboard());
Copy( aClipboard );
}
void TextView::Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard )
{
if ( rxClipboard.is() )
{
css::uno::Reference< css::datatransfer::XTransferable > xDataObj;
try
{
SolarMutexReleaser aReleaser;
xDataObj = rxClipboard->getContents();
}
catch( const css::uno::Exception& )
{
}
if ( xDataObj.is() )
{
css::datatransfer::DataFlavor aFlavor;
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
if ( xDataObj->isDataFlavorSupported( aFlavor ) )
{
try
{
css::uno::Any aData = xDataObj->getTransferData( aFlavor );
OUString aText;
aData >>= aText;
bool bWasTruncated = false;
if( mpImpl->mpTextEngine->GetMaxTextLen() != 0 )
bWasTruncated = ImplTruncateNewText( aText );
InsertText( aText );
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) );
if( bWasTruncated )
Edit::ShowTruncationWarning(mpImpl->mpWindow->GetFrameWeld());
}
catch( const css::datatransfer::UnsupportedFlavorException& )
{
}
}
}
}
}
void TextView::Paste()
{
css::uno::Reference<css::datatransfer::clipboard::XClipboard> aClipboard(GetWindow()->GetClipboard());
Paste( aClipboard );
}
OUString TextView::GetSelected()
{
return GetSelected( GetSystemLineEnd() );
}
OUString TextView::GetSelected( LineEnd aSeparator )
{
return mpImpl->mpTextEngine->GetText( mpImpl->maSelection, aSeparator );
}
void TextView::SetInsertMode( bool bInsert )
{
if ( mpImpl->mbInsertMode != bInsert )
{
mpImpl->mbInsertMode = bInsert;
ShowCursor( mpImpl->mbAutoScroll, false );
}
}
void TextView::SetReadOnly( bool bReadOnly )
{
if ( mpImpl->mbReadOnly != bReadOnly )
{
mpImpl->mbReadOnly = bReadOnly;
if ( !mpImpl->mbReadOnly )
ShowCursor( mpImpl->mbAutoScroll, false );
else
HideCursor();
GetWindow()->SetInputContext( InputContext( mpImpl->mpTextEngine->GetFont(), bReadOnly ? InputContextFlags::Text|InputContextFlags::ExtText : InputContextFlags::NONE ) );
}
}
TextSelection const & TextView::ImpMoveCursor( const KeyEvent& rKeyEvent )
{
// normally only needed for Up/Down; but who cares
mpImpl->mpTextEngine->CheckIdleFormatter();
TextPaM aPaM( mpImpl->maSelection.GetEnd() );
TextPaM aOldEnd( aPaM );
TextDirectionality eTextDirection = TextDirectionality::LeftToRight_TopToBottom;
if ( mpImpl->mpTextEngine->IsRightToLeft() )
eTextDirection = TextDirectionality::RightToLeft_TopToBottom;
KeyEvent aTranslatedKeyEvent = rKeyEvent.LogicalTextDirectionality( eTextDirection );
bool bCtrl = aTranslatedKeyEvent.GetKeyCode().IsMod1();
sal_uInt16 nCode = aTranslatedKeyEvent.GetKeyCode().GetCode();
bool bSelect = aTranslatedKeyEvent.GetKeyCode().IsShift();
switch ( nCode )
{
case KEY_UP: aPaM = CursorUp( aPaM );
break;
case KEY_DOWN: aPaM = CursorDown( aPaM );
break;
case KEY_HOME: aPaM = bCtrl ? CursorStartOfDoc() : CursorStartOfLine( aPaM );
break;
case KEY_END: aPaM = bCtrl ? CursorEndOfDoc() : CursorEndOfLine( aPaM );
break;
case KEY_PAGEUP: aPaM = bCtrl ? CursorStartOfDoc() : PageUp( aPaM );
break;
case KEY_PAGEDOWN: aPaM = bCtrl ? CursorEndOfDoc() : PageDown( aPaM );
break;
case KEY_LEFT: aPaM = bCtrl ? CursorWordLeft( aPaM ) : CursorLeft( aPaM, aTranslatedKeyEvent.GetKeyCode().IsMod2() ? sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCHARACTER) : sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCELL) );
break;
case KEY_RIGHT: aPaM = bCtrl ? CursorWordRight( aPaM ) : CursorRight( aPaM, aTranslatedKeyEvent.GetKeyCode().IsMod2() ? sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCHARACTER) : sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCELL) );
break;
case css::awt::Key::SELECT_WORD_FORWARD:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_WORD_FORWARD:
aPaM = CursorWordRight( aPaM );
break;
case css::awt::Key::SELECT_WORD_BACKWARD:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_WORD_BACKWARD:
aPaM = CursorWordLeft( aPaM );
break;
case css::awt::Key::SELECT_TO_BEGIN_OF_LINE:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_BEGIN_OF_LINE:
aPaM = CursorStartOfLine( aPaM );
break;
case css::awt::Key::SELECT_TO_END_OF_LINE:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_END_OF_LINE:
aPaM = CursorEndOfLine( aPaM );
break;
case css::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
aPaM = CursorStartOfParagraph( aPaM );
break;
case css::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
aPaM = CursorEndOfParagraph( aPaM );
break;
case css::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
aPaM = CursorStartOfDoc();
break;
case css::awt::Key::SELECT_TO_END_OF_DOCUMENT:
bSelect = true;
[[fallthrough]];
case css::awt::Key::MOVE_TO_END_OF_DOCUMENT:
aPaM = CursorEndOfDoc();
break;
}
// might cause a CreateAnchor or Deselection all
mpImpl->mpSelEngine->CursorPosChanging( bSelect, aTranslatedKeyEvent.GetKeyCode().IsMod1() );
if ( aOldEnd != aPaM )
{
mpImpl->mpTextEngine->CursorMoved( aOldEnd.GetPara() );
TextSelection aNewSelection( mpImpl->maSelection );
aNewSelection.GetEnd() = aPaM;
if ( bSelect )
{
// extend the selection
ImpSetSelection( aNewSelection );
ShowSelection( TextSelection( aOldEnd, aPaM ) );
}
else
{
aNewSelection.GetStart() = aPaM;
ImpSetSelection( aNewSelection );
}
}
return mpImpl->maSelection;
}
void TextView::InsertText( const OUString& rStr )
{
mpImpl->mpTextEngine->UndoActionStart();
TextSelection aNewSel = mpImpl->mpTextEngine->ImpInsertText( mpImpl->maSelection, rStr );
ImpSetSelection( aNewSel );
mpImpl->mpTextEngine->UndoActionEnd();
mpImpl->mpTextEngine->FormatAndUpdate( this );
}
TextPaM TextView::CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode )
{
TextPaM aPaM( rPaM );
if ( aPaM.GetIndex() )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
sal_Int32 nCount = 1;
aPaM.GetIndex() = xBI->previousCharacters( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), nCharacterIteratorMode, nCount, nCount );
}
else if ( aPaM.GetPara() )
{
aPaM.GetPara()--;
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
aPaM.GetIndex() = pNode->GetText().getLength();
}
return aPaM;
}
TextPaM TextView::CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode )
{
TextPaM aPaM( rPaM );
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( aPaM.GetIndex() < pNode->GetText().getLength() )
{
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
sal_Int32 nCount = 1;
aPaM.GetIndex() = xBI->nextCharacters( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), nCharacterIteratorMode, nCount, nCount );
}
else if ( aPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().size()-1) )
{
aPaM.GetPara()++;
aPaM.GetIndex() = 0;
}
return aPaM;
}
TextPaM TextView::CursorWordLeft( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
if ( aPaM.GetIndex() )
{
// tdf#57879 - expand selection to the left to include connector punctuations
mpImpl->mpTextEngine->GetWord( rPaM, &aPaM );
if ( aPaM.GetIndex() >= rPaM.GetIndex() )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
aPaM.GetIndex() = xBI->previousWord( pNode->GetText(), rPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES ).startPos;
if ( aPaM.GetIndex() > 0 )
mpImpl->mpTextEngine->GetWord( aPaM, &aPaM );
else
aPaM.GetIndex() = 0;
}
}
else if ( aPaM.GetPara() )
{
aPaM.GetPara()--;
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
aPaM.GetIndex() = pNode->GetText().getLength();
}
return aPaM;
}
TextPaM TextView::CursorWordRight( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( aPaM.GetIndex() < pNode->GetText().getLength() )
{
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
aPaM.GetIndex() = xBI->nextWord( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES ).endPos;
mpImpl->mpTextEngine->GetWord( aPaM, nullptr, &aPaM );
}
else if ( aPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().size()-1) )
{
aPaM.GetPara()++;
aPaM.GetIndex() = 0;
}
return aPaM;
}
TextPaM TextView::ImpDelete( sal_uInt8 nMode, sal_uInt8 nDelMode )
{
if ( mpImpl->maSelection.HasRange() ) // only delete selection
return mpImpl->mpTextEngine->ImpDeleteText( mpImpl->maSelection );
TextPaM aStartPaM = mpImpl->maSelection.GetStart();
TextPaM aEndPaM = aStartPaM;
if ( nMode == DEL_LEFT )
{
if ( nDelMode == DELMODE_SIMPLE )
{
aEndPaM = CursorLeft( aEndPaM, sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCHARACTER) );
}
else if ( nDelMode == DELMODE_RESTOFWORD )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
if ( aBoundary.startPos == mpImpl->maSelection.GetEnd().GetIndex() )
aBoundary = xBI->previousWord( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
// #i63506# startPos is -1 when the paragraph starts with a tab
aEndPaM.GetIndex() = std::max<sal_Int32>(aBoundary.startPos, 0);
}
else // DELMODE_RESTOFCONTENT
{
if ( aEndPaM.GetIndex() != 0 )
aEndPaM.GetIndex() = 0;
else if ( aEndPaM.GetPara() )
{
// previous paragraph
aEndPaM.GetPara()--;
aEndPaM.GetIndex() = 0;
}
}
}
else
{
if ( nDelMode == DELMODE_SIMPLE )
{
aEndPaM = CursorRight( aEndPaM, sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCELL) );
}
else if ( nDelMode == DELMODE_RESTOFWORD )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->nextWord( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
aEndPaM.GetIndex() = aBoundary.startPos;
}
else // DELMODE_RESTOFCONTENT
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
if ( aEndPaM.GetIndex() < pNode->GetText().getLength() )
aEndPaM.GetIndex() = pNode->GetText().getLength();
else if ( aEndPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().size() - 1 ) )
{
// next paragraph
aEndPaM.GetPara()++;
TextNode* pNextNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
aEndPaM.GetIndex() = pNextNode->GetText().getLength();
}
}
}
return mpImpl->mpTextEngine->ImpDeleteText( TextSelection( aStartPaM, aEndPaM ) );
}
TextPaM TextView::CursorUp( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
long nX;
if ( mpImpl->mnTravelXPos == TRAVEL_X_DONTKNOW )
{
nX = mpImpl->mpTextEngine->GetEditCursor( rPaM, false ).Left();
mpImpl->mnTravelXPos = static_cast<sal_uInt16>(nX)+1;
}
else
nX = mpImpl->mnTravelXPos;
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
std::vector<TextLine>::size_type nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), false );
if ( nLine ) // same paragraph
{
aPaM.GetIndex() = mpImpl->mpTextEngine->GetCharPos( rPaM.GetPara(), nLine-1, nX );
// If we need to go to the end of a line that was wrapped automatically,
// the cursor ends up at the beginning of the 2nd line
// Problem: Last character of an automatically wrapped line = Cursor
TextLine& rLine = pPPortion->GetLines()[ nLine - 1 ];
if ( aPaM.GetIndex() && ( aPaM.GetIndex() == rLine.GetEnd() ) )
--aPaM.GetIndex();
}
else if ( rPaM.GetPara() ) // previous paragraph
{
aPaM.GetPara()--;
pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
std::vector<TextLine>::size_type nL = pPPortion->GetLines().size() - 1;
aPaM.GetIndex() = mpImpl->mpTextEngine->GetCharPos( aPaM.GetPara(), nL, nX+1 );
}
return aPaM;
}
TextPaM TextView::CursorDown( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
long nX;
if ( mpImpl->mnTravelXPos == TRAVEL_X_DONTKNOW )
{
nX = mpImpl->mpTextEngine->GetEditCursor( rPaM, false ).Left();
mpImpl->mnTravelXPos = static_cast<sal_uInt16>(nX)+1;
}
else
nX = mpImpl->mnTravelXPos;
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
std::vector<TextLine>::size_type nLine = pPPortion->GetLineNumber( rPaM.GetIndex(), false );
if ( nLine < ( pPPortion->GetLines().size() - 1 ) )
{
aPaM.GetIndex() = mpImpl->mpTextEngine->GetCharPos( rPaM.GetPara(), nLine+1, nX );
// special case CursorUp
TextLine& rLine = pPPortion->GetLines()[ nLine + 1 ];
if ( ( aPaM.GetIndex() == rLine.GetEnd() ) && ( aPaM.GetIndex() > rLine.GetStart() ) && aPaM.GetIndex() < pPPortion->GetNode()->GetText().getLength() )
--aPaM.GetIndex();
}
else if ( rPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().size() - 1 ) ) // next paragraph
{
aPaM.GetPara()++;
pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
aPaM.GetIndex() = mpImpl->mpTextEngine->GetCharPos( aPaM.GetPara(), 0, nX+1 );
TextLine& rLine = pPPortion->GetLines().front();
if ( ( aPaM.GetIndex() == rLine.GetEnd() ) && ( aPaM.GetIndex() > rLine.GetStart() ) && ( pPPortion->GetLines().size() > 1 ) )
--aPaM.GetIndex();
}
return aPaM;
}
TextPaM TextView::CursorStartOfLine( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
std::vector<TextLine>::size_type nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), false );
TextLine& rLine = pPPortion->GetLines()[ nLine ];
aPaM.GetIndex() = rLine.GetStart();
return aPaM;
}
TextPaM TextView::CursorEndOfLine( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( rPaM.GetPara() );
std::vector<TextLine>::size_type nLine = pPPortion->GetLineNumber( aPaM.GetIndex(), false );
TextLine& rLine = pPPortion->GetLines()[ nLine ];
aPaM.GetIndex() = rLine.GetEnd();
if ( rLine.GetEnd() > rLine.GetStart() ) // empty line
{
sal_Unicode cLastChar = pPPortion->GetNode()->GetText()[ aPaM.GetIndex()-1 ];
if ( ( cLastChar == ' ' ) && ( aPaM.GetIndex() != pPPortion->GetNode()->GetText().getLength() ) )
{
// for a blank in an automatically-wrapped line it is better to stand before it,
// as the user will intend to stand behind the prior word.
// If there is a change, special case for Pos1 after End!
--aPaM.GetIndex();
}
}
return aPaM;
}
TextPaM TextView::CursorStartOfParagraph( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
aPaM.GetIndex() = 0;
return aPaM;
}
TextPaM TextView::CursorEndOfParagraph( const TextPaM& rPaM )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ rPaM.GetPara() ].get();
TextPaM aPaM( rPaM );
aPaM.GetIndex() = pNode->GetText().getLength();
return aPaM;
}
TextPaM TextView::CursorStartOfDoc()
{
TextPaM aPaM( 0, 0 );
return aPaM;
}
TextPaM TextView::CursorEndOfDoc()
{
const sal_uInt32 nNode = static_cast<sal_uInt32>(mpImpl->mpTextEngine->mpDoc->GetNodes().size() - 1);
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ nNode ].get();
TextPaM aPaM( nNode, pNode->GetText().getLength() );
return aPaM;
}
TextPaM TextView::PageUp( const TextPaM& rPaM )
{
tools::Rectangle aRect = mpImpl->mpTextEngine->PaMtoEditCursor( rPaM );
Point aTopLeft = aRect.TopLeft();
aTopLeft.AdjustY( -(mpImpl->mpWindow->GetOutputSizePixel().Height() * 9/10) );
aTopLeft.AdjustX(1 );
if ( aTopLeft.Y() < 0 )
aTopLeft.setY( 0 );
TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aTopLeft );
return aPaM;
}
TextPaM TextView::PageDown( const TextPaM& rPaM )
{
tools::Rectangle aRect = mpImpl->mpTextEngine->PaMtoEditCursor( rPaM );
Point aBottomRight = aRect.BottomRight();
aBottomRight.AdjustY(mpImpl->mpWindow->GetOutputSizePixel().Height() * 9/10 );
aBottomRight.AdjustX(1 );
long nHeight = mpImpl->mpTextEngine->GetTextHeight();
if ( aBottomRight.Y() > nHeight )
aBottomRight.setY( nHeight-1 );
TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aBottomRight );
return aPaM;
}
void TextView::ImpShowCursor( bool bGotoCursor, bool bForceVisCursor, bool bSpecial )
{
if ( mpImpl->mpTextEngine->IsFormatting() )
return;
if ( !mpImpl->mpTextEngine->GetUpdateMode() )
return;
if ( mpImpl->mpTextEngine->IsInUndo() )
return;
mpImpl->mpTextEngine->CheckIdleFormatter();
if ( !mpImpl->mpTextEngine->IsFormatted() )
mpImpl->mpTextEngine->FormatAndUpdate( this );
TextPaM aPaM( mpImpl->maSelection.GetEnd() );
tools::Rectangle aEditCursor = mpImpl->mpTextEngine->PaMtoEditCursor( aPaM, bSpecial );
// Remember that we placed the cursor behind the last character of a line
mpImpl->mbCursorAtEndOfLine = false;
if( bSpecial )
{
TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
mpImpl->mbCursorAtEndOfLine =
pParaPortion->GetLineNumber( aPaM.GetIndex(), true ) != pParaPortion->GetLineNumber( aPaM.GetIndex(), false );
}
if ( !IsInsertMode() && !mpImpl->maSelection.HasRange() )
{
TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( !pNode->GetText().isEmpty() && ( aPaM.GetIndex() < pNode->GetText().getLength() ) )
{
// If we are behind a portion, and the next portion has other direction, we must change position...
aEditCursor.SetLeft( mpImpl->mpTextEngine->GetEditCursor( aPaM, false, true ).Left() );
aEditCursor.SetRight( aEditCursor.Left() );
TEParaPortion* pParaPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
sal_Int32 nTextPortionStart = 0;
std::size_t nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true );
TETextPortion* pTextPortion = pParaPortion->GetTextPortions()[ nTextPortion ];
if ( pTextPortion->GetKind() == PORTIONKIND_TAB )
{
aEditCursor.AdjustRight(pTextPortion->GetWidth() );
}
else
{
TextPaM aNext = CursorRight( TextPaM( aPaM.GetPara(), aPaM.GetIndex() ), sal_uInt16(css::i18n::CharacterIteratorMode::SKIPCELL) );
aEditCursor.SetRight( mpImpl->mpTextEngine->GetEditCursor( aNext, true ).Left() );
}
}
}
Size aOutSz = mpImpl->mpWindow->GetOutputSizePixel();
if ( aEditCursor.GetHeight() > aOutSz.Height() )
aEditCursor.SetBottom( aEditCursor.Top() + aOutSz.Height() - 1 );
aEditCursor.AdjustLeft( -1 );
if ( bGotoCursor
// #i81283# protect maStartDocPos against initialization problems
&& aOutSz.Width() && aOutSz.Height()
)
{
long nVisStartY = mpImpl->maStartDocPos.Y();
long nVisEndY = mpImpl->maStartDocPos.Y() + aOutSz.Height();
long nVisStartX = mpImpl->maStartDocPos.X();
long nVisEndX = mpImpl->maStartDocPos.X() + aOutSz.Width();
long nMoreX = aOutSz.Width() / 4;
Point aNewStartPos( mpImpl->maStartDocPos );
if ( aEditCursor.Bottom() > nVisEndY )
{
aNewStartPos.AdjustY( aEditCursor.Bottom() - nVisEndY);
}
else if ( aEditCursor.Top() < nVisStartY )
{
aNewStartPos.AdjustY( -( nVisStartY - aEditCursor.Top() ) );
}
if ( aEditCursor.Right() >= nVisEndX )
{
aNewStartPos.AdjustX( aEditCursor.Right() - nVisEndX );
// do you want some more?
aNewStartPos.AdjustX(nMoreX );
}
else if ( aEditCursor.Left() <= nVisStartX )
{
aNewStartPos.AdjustX( -( nVisStartX - aEditCursor.Left() ) );
// do you want some more?
aNewStartPos.AdjustX( -nMoreX );
}
// X can be wrong for the 'some more' above:
// sal_uLong nMaxTextWidth = mpImpl->mpTextEngine->GetMaxTextWidth();
// if ( !nMaxTextWidth || ( nMaxTextWidth > 0x7FFFFFFF ) )
// nMaxTextWidth = 0x7FFFFFFF;
// long nMaxX = (long)nMaxTextWidth - aOutSz.Width();
long nMaxX = mpImpl->mpTextEngine->CalcTextWidth() - aOutSz.Width();
if ( nMaxX < 0 )
nMaxX = 0;
if ( aNewStartPos.X() < 0 )
aNewStartPos.setX( 0 );
else if ( aNewStartPos.X() > nMaxX )
aNewStartPos.setX( nMaxX );
// Y should not be further down than needed
long nYMax = mpImpl->mpTextEngine->GetTextHeight() - aOutSz.Height();
if ( nYMax < 0 )
nYMax = 0;
if ( aNewStartPos.Y() > nYMax )
aNewStartPos.setY( nYMax );
if ( aNewStartPos != mpImpl->maStartDocPos )
Scroll( -(aNewStartPos.X() - mpImpl->maStartDocPos.X()), -(aNewStartPos.Y() - mpImpl->maStartDocPos.Y()) );
}
if ( aEditCursor.Right() < aEditCursor.Left() )
{
long n = aEditCursor.Left();
aEditCursor.SetLeft( aEditCursor.Right() );
aEditCursor.SetRight( n );
}
Point aPoint( GetWindowPos( !mpImpl->mpTextEngine->IsRightToLeft() ? aEditCursor.TopLeft() : aEditCursor.TopRight() ) );
mpImpl->mpCursor->SetPos( aPoint );
mpImpl->mpCursor->SetSize( aEditCursor.GetSize() );
if ( bForceVisCursor && mpImpl->mbCursorEnabled )
mpImpl->mpCursor->Show();
}
void TextView::SetCursorAtPoint( const Point& rPosPixel )
{
mpImpl->mpTextEngine->CheckIdleFormatter();
Point aDocPos = GetDocPos( rPosPixel );
TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aDocPos );
// aTmpNewSel: Diff between old and new; not the new selection
TextSelection aTmpNewSel( mpImpl->maSelection.GetEnd(), aPaM );
TextSelection aNewSel( mpImpl->maSelection );
aNewSel.GetEnd() = aPaM;
if ( !mpImpl->mpSelEngine->HasAnchor() )
{
if ( mpImpl->maSelection.GetStart() != aPaM )
mpImpl->mpTextEngine->CursorMoved( mpImpl->maSelection.GetStart().GetPara() );
aNewSel.GetStart() = aPaM;
ImpSetSelection( aNewSel );
}
else
{
ImpSetSelection( aNewSel );
ShowSelection( aTmpNewSel );
}
bool bForceCursor = !mpImpl->mpDDInfo; // && !mbInSelection
ImpShowCursor( mpImpl->mbAutoScroll, bForceCursor, false );
}
bool TextView::IsSelectionAtPoint( const Point& rPosPixel )
{
Point aDocPos = GetDocPos( rPosPixel );
TextPaM aPaM = mpImpl->mpTextEngine->GetPaM( aDocPos );
// BeginDrag is only called, however, if IsSelectionAtPoint()
// Problem: IsSelectionAtPoint is not called by Command()
// if before MBDown returned false.
return IsInSelection( aPaM );
}
bool TextView::IsInSelection( const TextPaM& rPaM )
{
TextSelection aSel = mpImpl->maSelection;
aSel.Justify();
const sal_uInt32 nStartNode = aSel.GetStart().GetPara();
const sal_uInt32 nEndNode = aSel.GetEnd().GetPara();
const sal_uInt32 nCurNode = rPaM.GetPara();
if ( ( nCurNode > nStartNode ) && ( nCurNode < nEndNode ) )
return true;
if ( nStartNode == nEndNode )
{
if ( nCurNode == nStartNode )
if ( ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
return true;
}
else if ( ( nCurNode == nStartNode ) && ( rPaM.GetIndex() >= aSel.GetStart().GetIndex() ) )
return true;
else if ( ( nCurNode == nEndNode ) && ( rPaM.GetIndex() < aSel.GetEnd().GetIndex() ) )
return true;
return false;
}
void TextView::ImpHideDDCursor()
{
if ( mpImpl->mpDDInfo && mpImpl->mpDDInfo->mbVisCursor )
{
mpImpl->mpDDInfo->maCursor.Hide();
mpImpl->mpDDInfo->mbVisCursor = false;
}
}
void TextView::ImpShowDDCursor()
{
if ( !mpImpl->mpDDInfo->mbVisCursor )
{
tools::Rectangle aCursor = mpImpl->mpTextEngine->PaMtoEditCursor( mpImpl->mpDDInfo->maDropPos, true );
aCursor.AdjustRight( 1 );
aCursor.SetPos( GetWindowPos( aCursor.TopLeft() ) );
mpImpl->mpDDInfo->maCursor.SetWindow( mpImpl->mpWindow );
mpImpl->mpDDInfo->maCursor.SetPos( aCursor.TopLeft() );
mpImpl->mpDDInfo->maCursor.SetSize( aCursor.GetSize() );
mpImpl->mpDDInfo->maCursor.Show();
mpImpl->mpDDInfo->mbVisCursor = true;
}
}
void TextView::SetPaintSelection( bool bPaint )
{
if ( bPaint != mpImpl->mbPaintSelection )
{
mpImpl->mbPaintSelection = bPaint;
ShowSelection( mpImpl->maSelection );
}
}
void TextView::Read( SvStream& rInput )
{
mpImpl->mpTextEngine->Read( rInput, &mpImpl->maSelection );
ShowCursor();
}
bool TextView::ImplTruncateNewText( OUString& rNewText ) const
{
bool bTruncated = false;
const sal_Int32 nMaxLen = mpImpl->mpTextEngine->GetMaxTextLen();
// 0 means unlimited
if( nMaxLen != 0 )
{
const sal_Int32 nCurLen = mpImpl->mpTextEngine->GetTextLen();
const sal_Int32 nNewLen = rNewText.getLength();
if ( nCurLen + nNewLen > nMaxLen )
{
// see how much text will be replaced
const sal_Int32 nSelLen = mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection );
if ( nCurLen + nNewLen - nSelLen > nMaxLen )
{
const sal_Int32 nTruncatedLen = nMaxLen - (nCurLen - nSelLen);
rNewText = rNewText.copy( 0, nTruncatedLen );
bTruncated = true;
}
}
}
return bTruncated;
}
bool TextView::ImplCheckTextLen( const OUString& rNewText )
{
bool bOK = true;
if ( mpImpl->mpTextEngine->GetMaxTextLen() )
{
sal_Int32 n = mpImpl->mpTextEngine->GetTextLen() + rNewText.getLength();
if ( n > mpImpl->mpTextEngine->GetMaxTextLen() )
{
// calculate how much text is being deleted
n -= mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection );
if ( n > mpImpl->mpTextEngine->GetMaxTextLen() )
bOK = false;
}
}
return bOK;
}
void TextView::dragGestureRecognized( const css::datatransfer::dnd::DragGestureEvent& rDGE )
{
if ( mpImpl->mbClickedInSelection )
{
SolarMutexGuard aVclGuard;
SAL_WARN_IF( !mpImpl->maSelection.HasRange(), "vcl", "TextView::dragGestureRecognized: mpImpl->mbClickedInSelection, but no selection?" );
mpImpl->mpDDInfo.reset(new TextDDInfo);
mpImpl->mpDDInfo->mbStarterOfDD = true;
TETextDataObject* pDataObj = new TETextDataObject( GetSelected() );
mpImpl->mpCursor->Hide();
sal_Int8 nActions = css::datatransfer::dnd::DNDConstants::ACTION_COPY;
if ( !IsReadOnly() )
nActions |= css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
rDGE.DragSource->startDrag( rDGE, nActions, 0 /*cursor*/, 0 /*image*/, pDataObj, mpImpl->mxDnDListener );
}
}
void TextView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent& )
{
ImpHideDDCursor();
mpImpl->mpDDInfo.reset();
}
void TextView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE )
{
SolarMutexGuard aVclGuard;
if ( !mpImpl->mbReadOnly && mpImpl->mpDDInfo )
{
ImpHideDDCursor();
// Data for deleting after DROP_MOVE:
TextSelection aPrevSel( mpImpl->maSelection );
aPrevSel.Justify();
const sal_uInt32 nPrevParaCount = mpImpl->mpTextEngine->GetParagraphCount();
const sal_Int32 nPrevStartParaLen = mpImpl->mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() );
bool bStarterOfDD = false;
for ( sal_uInt16 nView = mpImpl->mpTextEngine->GetViewCount(); nView && !bStarterOfDD; )
bStarterOfDD = mpImpl->mpTextEngine->GetView( --nView )->mpImpl->mpDDInfo && mpImpl->mpTextEngine->GetView( nView )->mpImpl->mpDDInfo->mbStarterOfDD;
HideSelection();
ImpSetSelection( mpImpl->mpDDInfo->maDropPos );
mpImpl->mpTextEngine->UndoActionStart();
OUString aText;
css::uno::Reference< css::datatransfer::XTransferable > xDataObj = rDTDE.Transferable;
if ( xDataObj.is() )
{
css::datatransfer::DataFlavor aFlavor;
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
if ( xDataObj->isDataFlavorSupported( aFlavor ) )
{
css::uno::Any aData = xDataObj->getTransferData( aFlavor );
OUString aOUString;
aData >>= aOUString;
aText = convertLineEnd(aOUString, LINEEND_LF);
}
}
if ( !aText.isEmpty() && ( aText[ aText.getLength()-1 ] == LINE_SEP ) )
aText = aText.copy(0, aText.getLength()-1);
if ( ImplCheckTextLen( aText ) )
ImpSetSelection( mpImpl->mpTextEngine->ImpInsertText( mpImpl->mpDDInfo->maDropPos, aText ) );
if ( aPrevSel.HasRange() &&
(( rDTDE.DropAction & css::datatransfer::dnd::DNDConstants::ACTION_MOVE ) || !bStarterOfDD) )
{
// adjust selection if necessary
if ( ( mpImpl->mpDDInfo->maDropPos.GetPara() < aPrevSel.GetStart().GetPara() ) ||
( ( mpImpl->mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
&& ( mpImpl->mpDDInfo->maDropPos.GetIndex() < aPrevSel.GetStart().GetIndex() ) ) )
{
const sal_uInt32 nNewParasBeforeSelection =
mpImpl->mpTextEngine->GetParagraphCount() - nPrevParaCount;
aPrevSel.GetStart().GetPara() += nNewParasBeforeSelection;
aPrevSel.GetEnd().GetPara() += nNewParasBeforeSelection;
if ( mpImpl->mpDDInfo->maDropPos.GetPara() == aPrevSel.GetStart().GetPara() )
{
const sal_Int32 nNewChars =
mpImpl->mpTextEngine->GetTextLen( aPrevSel.GetStart().GetPara() ) - nPrevStartParaLen;
aPrevSel.GetStart().GetIndex() += nNewChars;
if ( aPrevSel.GetStart().GetPara() == aPrevSel.GetEnd().GetPara() )
aPrevSel.GetEnd().GetIndex() += nNewChars;
}
}
else
{
// adjust current selection
TextPaM aPaM = mpImpl->maSelection.GetStart();
aPaM.GetPara() -= ( aPrevSel.GetEnd().GetPara() - aPrevSel.GetStart().GetPara() );
if ( aPrevSel.GetEnd().GetPara() == mpImpl->mpDDInfo->maDropPos.GetPara() )
{
aPaM.GetIndex() -= aPrevSel.GetEnd().GetIndex();
if ( aPrevSel.GetStart().GetPara() == mpImpl->mpDDInfo->maDropPos.GetPara() )
aPaM.GetIndex() += aPrevSel.GetStart().GetIndex();
}
ImpSetSelection( aPaM );
}
mpImpl->mpTextEngine->ImpDeleteText( aPrevSel );
}
mpImpl->mpTextEngine->UndoActionEnd();
mpImpl->mpDDInfo.reset();
mpImpl->mpTextEngine->FormatAndUpdate( this );
mpImpl->mpTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) );
}
rDTDE.Context->dropComplete( false/*bChanges*/ );
}
void TextView::dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& )
{
}
void TextView::dragExit( const css::datatransfer::dnd::DropTargetEvent& )
{
SolarMutexGuard aVclGuard;
ImpHideDDCursor();
}
void TextView::dragOver( const css::datatransfer::dnd::DropTargetDragEvent& rDTDE )
{
SolarMutexGuard aVclGuard;
if (!mpImpl->mpDDInfo)
mpImpl->mpDDInfo.reset(new TextDDInfo);
TextPaM aPrevDropPos = mpImpl->mpDDInfo->maDropPos;
Point aMousePos( rDTDE.LocationX, rDTDE.LocationY );
Point aDocPos = GetDocPos( aMousePos );
mpImpl->mpDDInfo->maDropPos = mpImpl->mpTextEngine->GetPaM( aDocPos );
// Don't drop in selection or in read only engine
if ( IsReadOnly() || IsInSelection( mpImpl->mpDDInfo->maDropPos ))
{
ImpHideDDCursor();
rDTDE.Context->rejectDrag();
}
else
{
// delete old Cursor
if ( !mpImpl->mpDDInfo->mbVisCursor || ( aPrevDropPos != mpImpl->mpDDInfo->maDropPos ) )
{
ImpHideDDCursor();
ImpShowDDCursor();
}
rDTDE.Context->acceptDrag( rDTDE.DropAction );
}
}
Point TextView::ImpGetOutputStartPos( const Point& rStartDocPos ) const
{
Point aStartPos( -rStartDocPos.X(), -rStartDocPos.Y() );
if ( mpImpl->mpTextEngine->IsRightToLeft() )
{
Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
aStartPos.setX( rStartDocPos.X() + aSz.Width() - 1 ); // -1: Start is 0
}
return aStartPos;
}
Point TextView::GetDocPos( const Point& rWindowPos ) const
{
// Window Position => Document Position
Point aPoint;
aPoint.setY( rWindowPos.Y() + mpImpl->maStartDocPos.Y() );
if ( !mpImpl->mpTextEngine->IsRightToLeft() )
{
aPoint.setX( rWindowPos.X() + mpImpl->maStartDocPos.X() );
}
else
{
Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
aPoint.setX( ( aSz.Width() - 1 ) - rWindowPos.X() + mpImpl->maStartDocPos.X() );
}
return aPoint;
}
Point TextView::GetWindowPos( const Point& rDocPos ) const
{
// Document Position => Window Position
Point aPoint;
aPoint.setY( rDocPos.Y() - mpImpl->maStartDocPos.Y() );
if ( !mpImpl->mpTextEngine->IsRightToLeft() )
{
aPoint.setX( rDocPos.X() - mpImpl->maStartDocPos.X() );
}
else
{
Size aSz = mpImpl->mpWindow->GetOutputSizePixel();
aPoint.setX( ( aSz.Width() - 1 ) - ( rDocPos.X() - mpImpl->maStartDocPos.X() ) );
}
return aPoint;
}
sal_Int32 TextView::GetLineNumberOfCursorInSelection() const
{
// PROGRESS
sal_Int32 nLineNo = -1;
if( mpImpl->mbCursorEnabled )
{
TextPaM aPaM = GetSelection().GetEnd();
TEParaPortion* pPPortion = mpImpl->mpTextEngine->mpTEParaPortions->GetObject( aPaM.GetPara() );
nLineNo = pPPortion->GetLineNumber( aPaM.GetIndex(), false );
//TODO: std::vector<TextLine>::size_type -> sal_Int32!
if( mpImpl->mbCursorAtEndOfLine )
--nLineNo;
}
return nLineNo;
}
// (+) class TextSelFunctionSet
TextSelFunctionSet::TextSelFunctionSet( TextView* pView )
{
mpView = pView;
}
void TextSelFunctionSet::BeginDrag()
{
}
void TextSelFunctionSet::CreateAnchor()
{
// TextSelection aSel( mpView->GetSelection() );
// aSel.GetStart() = aSel.GetEnd();
// mpView->SetSelection( aSel );
// may not be followed by ShowCursor
mpView->HideSelection();
mpView->ImpSetSelection( mpView->mpImpl->maSelection.GetEnd() );
}
void TextSelFunctionSet::SetCursorAtPoint( const Point& rPointPixel, bool )
{
mpView->SetCursorAtPoint( rPointPixel );
}
bool TextSelFunctionSet::IsSelectionAtPoint( const Point& rPointPixel )
{
return mpView->IsSelectionAtPoint( rPointPixel );
}
void TextSelFunctionSet::DeselectAll()
{
CreateAnchor();
}
void TextSelFunctionSet::DeselectAtPoint( const Point& )
{
// only for multiple selection
}
void TextSelFunctionSet::DestroyAnchor()
{
// only for multiple selection
}
TextEngine* TextView::GetTextEngine() const
{ return mpImpl->mpTextEngine; }
vcl::Window* TextView::GetWindow() const
{ return mpImpl->mpWindow; }
void TextView::EnableCursor( bool bEnable )
{ mpImpl->mbCursorEnabled = bEnable; }
bool TextView::IsCursorEnabled() const
{ return mpImpl->mbCursorEnabled; }
void TextView::SetStartDocPos( const Point& rPos )
{ mpImpl->maStartDocPos = rPos; }
const Point& TextView::GetStartDocPos() const
{ return mpImpl->maStartDocPos; }
void TextView::SetAutoIndentMode( bool bAutoIndent )
{ mpImpl->mbAutoIndent = bAutoIndent; }
bool TextView::IsReadOnly() const
{ return mpImpl->mbReadOnly; }
void TextView::SetAutoScroll( bool bAutoScroll )
{ mpImpl->mbAutoScroll = bAutoScroll; }
bool TextView::IsAutoScroll() const
{ return mpImpl->mbAutoScroll; }
bool TextView::HasSelection() const
{ return mpImpl->maSelection.HasRange(); }
bool TextView::IsInsertMode() const
{ return mpImpl->mbInsertMode; }
void TextView::MatchGroup()
{
TextSelection aTmpSel( GetSelection() );
aTmpSel.Justify();
if ( ( aTmpSel.GetStart().GetPara() != aTmpSel.GetEnd().GetPara() ) ||
( ( aTmpSel.GetEnd().GetIndex() - aTmpSel.GetStart().GetIndex() ) > 1 ) )
{
return;
}
TextSelection aMatchSel = static_cast<ExtTextEngine*>(GetTextEngine())->MatchGroup( aTmpSel.GetStart() );
if ( aMatchSel.HasRange() )
SetSelection( aMatchSel );
}
void TextView::CenterPaM( const TextPaM& rPaM )
{
// Get textview size and the corresponding y-coordinates
Size aOutSz = mpImpl->mpWindow->GetOutputSizePixel();
long nVisStartY = mpImpl->maStartDocPos.Y();
long nVisEndY = mpImpl->maStartDocPos.Y() + aOutSz.Height();
// Retrieve the coordinates of the PaM
tools::Rectangle aRect = mpImpl->mpTextEngine->PaMtoEditCursor(rPaM);
// Recalculate the offset of the center y-coordinates and scroll
Scroll(0, (nVisStartY + nVisEndY) / 2 - aRect.TopLeft().getY());
}
bool TextView::Search( const i18nutil::SearchOptions& rSearchOptions, bool bForward )
{
bool bFound = false;
TextSelection aSel( GetSelection() );
if ( static_cast<ExtTextEngine*>(GetTextEngine())->Search( aSel, rSearchOptions, bForward ) )
{
bFound = true;
// First add the beginning of the word to the selection,
// so that the whole word is in the visible region.
SetSelection( aSel.GetStart() );
ShowCursor( true, false );
}
else
{
aSel = GetSelection().GetEnd();
}
SetSelection( aSel );
// tdf#49482: Move the start of the selection to the center of the textview
if (bFound)
{
CenterPaM( aSel.GetStart() );
}
ShowCursor();
return bFound;
}
sal_uInt16 TextView::Replace( const i18nutil::SearchOptions& rSearchOptions, bool bAll, bool bForward )
{
sal_uInt16 nFound = 0;
if ( !bAll )
{
if ( GetSelection().HasRange() )
{
InsertText( rSearchOptions.replaceString );
nFound = 1;
Search( rSearchOptions, bForward ); // right away to the next
}
else
{
if( Search( rSearchOptions, bForward ) )
nFound = 1;
}
}
else
{
// the writer replaces all, from beginning to end
ExtTextEngine* pTextEngine = static_cast<ExtTextEngine*>(GetTextEngine());
// HideSelection();
TextSelection aSel;
bool bSearchInSelection = (0 != (rSearchOptions.searchFlag & css::util::SearchFlags::REG_NOT_BEGINOFLINE) );
if ( bSearchInSelection )
{
aSel = GetSelection();
aSel.Justify();
}
TextSelection aSearchSel( aSel );
bool bFound = pTextEngine->Search( aSel, rSearchOptions );
if ( bFound )
pTextEngine->UndoActionStart();
while ( bFound )
{
nFound++;
TextPaM aNewStart = pTextEngine->ImpInsertText( aSel, rSearchOptions.replaceString );
// tdf#64690 - extend selection to include inserted text portions
if ( aSel.GetEnd().GetPara() == aSearchSel.GetEnd().GetPara() )
{
aSearchSel.GetEnd().GetIndex() += rSearchOptions.replaceString.getLength() - 1;
}
aSel = aSearchSel;
aSel.GetStart() = aNewStart;
bFound = pTextEngine->Search( aSel, rSearchOptions );
}
if ( nFound )
{
SetSelection( aSel.GetStart() );
pTextEngine->FormatAndUpdate( this );
pTextEngine->UndoActionEnd();
}
}
return nFound;
}
bool TextView::ImpIndentBlock( bool bRight )
{
bool bDone = false;
TextSelection aSel = GetSelection();
aSel.Justify();
HideSelection();
GetTextEngine()->UndoActionStart();
const sal_uInt32 nStartPara = aSel.GetStart().GetPara();
sal_uInt32 nEndPara = aSel.GetEnd().GetPara();
if ( aSel.HasRange() && !aSel.GetEnd().GetIndex() )
{
nEndPara--; // do not indent
}
for ( sal_uInt32 nPara = nStartPara; nPara <= nEndPara; ++nPara )
{
if ( bRight )
{
// add tabs
GetTextEngine()->ImpInsertText( TextPaM( nPara, 0 ), '\t' );
bDone = true;
}
else
{
// remove Tabs/Blanks
OUString aText = GetTextEngine()->GetText( nPara );
if ( !aText.isEmpty() && (
( aText[ 0 ] == '\t' ) ||
( aText[ 0 ] == ' ' ) ) )
{
GetTextEngine()->ImpDeleteText( TextSelection( TextPaM( nPara, 0 ), TextPaM( nPara, 1 ) ) );
bDone = true;
}
}
}
GetTextEngine()->UndoActionEnd();
bool bRange = aSel.HasRange();
if ( bRight )
{
++aSel.GetStart().GetIndex();
if ( bRange && ( aSel.GetEnd().GetPara() == nEndPara ) )
++aSel.GetEnd().GetIndex();
}
else
{
if ( aSel.GetStart().GetIndex() )
--aSel.GetStart().GetIndex();
if ( bRange && aSel.GetEnd().GetIndex() )
--aSel.GetEnd().GetIndex();
}
ImpSetSelection( aSel );
GetTextEngine()->FormatAndUpdate( this );
return bDone;
}
bool TextView::IndentBlock()
{
return ImpIndentBlock( true );
}
bool TextView::UnindentBlock()
{
return ImpIndentBlock( false );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|