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 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "printdlg.hxx"
#include "svdata.hxx"
#include "svids.hrc"
#include "jobset.h"
#include "vcl/print.hxx"
#include "vcl/dialog.hxx"
#include "vcl/button.hxx"
#include "vcl/wall.hxx"
#include "vcl/status.hxx"
#include "vcl/decoview.hxx"
#include "vcl/arrange.hxx"
#include "vcl/configsettings.hxx"
#include "vcl/help.hxx"
#include "vcl/decoview.hxx"
#include "vcl/svapp.hxx"
#include "vcl/unohelp.hxx"
#include "unotools/localedatawrapper.hxx"
#include "rtl/strbuf.hxx"
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/container/XNameAccess.hpp"
#include "com/sun/star/beans/PropertyValue.hpp"
#include "com/sun/star/awt/Size.hpp"
using namespace vcl;
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::container;
using namespace com::sun::star::beans;
PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent, const ResId& i_rId )
: Window( i_pParent, i_rId )
, maOrigSize( 10, 10 )
, maPageVDev( *this )
, maToolTipString( String( VclResId( SV_PRINT_PRINTPREVIEW_TXT ) ) )
, mbGreyscale( false )
, maHorzDim( this, WB_HORZ | WB_CENTER )
, maVertDim( this, WB_VERT | WB_VCENTER )
{
SetPaintTransparent( sal_True );
SetBackground();
maPageVDev.SetBackground( Color( COL_WHITE ) );
maHorzDim.Show();
maVertDim.Show();
maHorzDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
maVertDim.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "2.0in" ) ) );
}
PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
{
}
void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDCEvt )
{
// react on settings changed
if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
{
maPageVDev.SetBackground( Color( COL_WHITE ) );
}
Window::DataChanged( i_rDCEvt );
}
void PrintDialog::PrintPreviewWindow::Resize()
{
Size aNewSize( GetSizePixel() );
long nTextHeight = maHorzDim.GetTextHeight();
// leave small space for decoration
aNewSize.Width() -= nTextHeight + 2;
aNewSize.Height() -= nTextHeight + 2;
Size aScaledSize;
double fScale = 1.0;
// #i106435# catch corner case of Size(0,0)
Size aOrigSize( maOrigSize );
if( aOrigSize.Width() < 1 )
aOrigSize.Width() = aNewSize.Width();
if( aOrigSize.Height() < 1 )
aOrigSize.Height() = aNewSize.Height();
if( aOrigSize.Width() > aOrigSize.Height() )
{
aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
if( aScaledSize.Height() > aNewSize.Height() )
fScale = double(aNewSize.Height())/double(aScaledSize.Height());
}
else
{
aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
if( aScaledSize.Width() > aNewSize.Width() )
fScale = double(aNewSize.Width())/double(aScaledSize.Width());
}
aScaledSize.Width() = long(aScaledSize.Width()*fScale);
aScaledSize.Height() = long(aScaledSize.Height()*fScale);
maPreviewSize = aScaledSize;
// #i104784# if we render the page too small then rounding issues result in
// layout artifacts looking really bad. So scale the page unto a device that is not
// full page size but not too small either. This also results in much better visual
// quality of the preview, e.g. when its height approaches the number of text lines
// find a good scaling factor
Size aPreviewMMSize( maPageVDev.PixelToLogic( aScaledSize, MapMode( MAP_100TH_MM ) ) );
double fZoom = double(maOrigSize.Height())/double(aPreviewMMSize.Height());
while( fZoom > 10 )
{
aScaledSize.Width() *= 2;
aScaledSize.Height() *= 2;
fZoom /= 2.0;
}
maPageVDev.SetOutputSizePixel( aScaledSize, sal_False );
// position dimension lines
Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2,
nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 );
maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ),
Size( maPreviewSize.Width(), nTextHeight ) );
maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ),
Size( nTextHeight, maPreviewSize.Height() ) );
}
void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
{
long nTextHeight = maHorzDim.GetTextHeight();
Size aSize( GetSizePixel() );
Point aOffset( (aSize.Width() - maPreviewSize.Width() + nTextHeight) / 2 ,
(aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2 );
if( maReplacementString.getLength() != 0 )
{
// replacement is active
Push();
Font aFont( GetSettings().GetStyleSettings().GetLabelFont() );
SetZoomedPointFont( aFont );
Rectangle aTextRect( aOffset + Point( 2, 2 ),
Size( maPreviewSize.Width() - 4, maPreviewSize.Height() - 4 ) );
DrawText( aTextRect, maReplacementString,
TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE
);
Pop();
}
else
{
GDIMetaFile aMtf( maMtf );
Size aVDevSize( maPageVDev.GetOutputSizePixel() );
const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) );
Size aOrigSize( maOrigSize );
if( aOrigSize.Width() < 1 )
aOrigSize.Width() = aLogicSize.Width();
if( aOrigSize.Height() < 1 )
aOrigSize.Height() = aLogicSize.Height();
double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
maPageVDev.Erase();
maPageVDev.Push();
maPageVDev.SetMapMode( MAP_100TH_MM );
sal_uLong nOldDrawMode = maPageVDev.GetDrawMode();
if( mbGreyscale )
maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() |
( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT |
DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) );
aMtf.WindStart();
aMtf.Scale( fScale, fScale );
aMtf.WindStart();
aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
maPageVDev.Pop();
SetMapMode( MAP_PIXEL );
maPageVDev.SetMapMode( MAP_PIXEL );
DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev );
maPageVDev.SetDrawMode( nOldDrawMode );
}
Rectangle aFrameRect( aOffset + Point( -1, -1 ),
Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) );
DecorationView aVw( this );
aVw.DrawFrame( aFrameRect, FRAME_DRAW_GROUP );
}
void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
{
if( rEvt.GetCommand() == COMMAND_WHEEL )
{
const CommandWheelData* pWheelData = rEvt.GetWheelData();
PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParent());
if( pDlg )
{
if( pWheelData->GetDelta() > 0 )
pDlg->previewForward();
else if( pWheelData->GetDelta() < 0 )
pDlg->previewBackward();
/*
else
huh ?
*/
}
}
}
void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
const Size& i_rOrigSize,
const rtl::OUString& i_rPaperName,
const rtl::OUString& i_rReplacement,
sal_Int32 i_nDPIX,
sal_Int32 i_nDPIY,
bool i_bGreyscale
)
{
rtl::OUStringBuffer aBuf( 256 );
aBuf.append( maToolTipString );
SetQuickHelpText( aBuf.makeStringAndClear() );
maMtf = i_rNewPreview;
maOrigSize = i_rOrigSize;
maReplacementString = i_rReplacement;
mbGreyscale = i_bGreyscale;
maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY );
maPageVDev.EnableOutput( sal_True );
// use correct measurements
const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() );
MapUnit eUnit = MAP_MM;
int nDigits = 0;
if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
{
eUnit = MAP_100TH_INCH;
nDigits = 2;
}
Size aLogicPaperSize( LogicToLogic( i_rOrigSize, MapMode( MAP_100TH_MM ), MapMode( eUnit ) ) );
String aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
aBuf.append( aNumText );
aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
if( i_rPaperName.getLength() )
{
aBuf.appendAscii( " (" );
aBuf.append( i_rPaperName );
aBuf.append( sal_Unicode(')') );
}
maHorzDim.SetText( aBuf.makeStringAndClear() );
aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
aBuf.append( aNumText );
aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" );
maVertDim.SetText( aBuf.makeStringAndClear() );
Resize();
Invalidate();
}
PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( Window* i_pParent )
: Window( i_pParent, WB_NOBORDER )
, mnOrderMode( 0 )
, mnRows( 1 )
, mnColumns( 1 )
{
ImplInitSettings();
}
PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow()
{
}
void PrintDialog::ShowNupOrderWindow::ImplInitSettings()
{
SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
}
void PrintDialog::ShowNupOrderWindow::Paint( const Rectangle& i_rRect )
{
Window::Paint( i_rRect );
SetMapMode( MAP_PIXEL );
SetTextColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
int nPages = mnRows * mnColumns;
Font aFont( GetSettings().GetStyleSettings().GetFieldFont() );
aFont.SetSize( Size( 0, 24 ) );
SetFont( aFont );
Size aSampleTextSize( GetTextWidth( rtl::OUString::valueOf( sal_Int32(nPages+1) ) ), GetTextHeight() );
Size aOutSize( GetOutputSizePixel() );
Size aSubSize( aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows );
// calculate font size: shrink the sample text so it fits
double fX = double(aSubSize.Width())/double(aSampleTextSize.Width());
double fY = double(aSubSize.Height())/double(aSampleTextSize.Height());
double fScale = (fX < fY) ? fX : fY;
long nFontHeight = long(24.0*fScale) - 3;
if( nFontHeight < 5 )
nFontHeight = 5;
aFont.SetSize( Size( 0, nFontHeight ) );
SetFont( aFont );
long nTextHeight = GetTextHeight();
for( int i = 0; i < nPages; i++ )
{
rtl::OUString aPageText( rtl::OUString::valueOf( sal_Int32(i+1) ) );
int nX = 0, nY = 0;
switch( mnOrderMode )
{
case SV_PRINT_PRT_NUP_ORDER_LRTB:
nX = (i % mnColumns); nY = (i / mnColumns);
break;
case SV_PRINT_PRT_NUP_ORDER_TBLR:
nX = (i / mnRows); nY = (i % mnRows);
break;
case SV_PRINT_PRT_NUP_ORDER_RLTB:
nX = mnColumns - 1 - (i % mnColumns); nY = (i / mnColumns);
break;
case SV_PRINT_PRT_NUP_ORDER_TBRL:
nX = mnColumns - 1 - (i / mnRows); nY = (i % mnRows);
break;
}
Size aTextSize( GetTextWidth( aPageText ), nTextHeight );
int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
DrawText( Point( nX * aSubSize.Width() + nDeltaX,
nY * aSubSize.Height() + nDeltaY ),
aPageText );
}
DecorationView aVw( this );
aVw.DrawFrame( Rectangle( Point( 0, 0), aOutSize ), FRAME_DRAW_GROUP );
}
PrintDialog::NUpTabPage::NUpTabPage( Window* i_pParent, const ResId& rResId )
: TabPage( i_pParent, rResId )
, maNupLine( this, VclResId( SV_PRINT_PRT_NUP_LAYOUT_FL ) )
, maPagesBtn( this, VclResId( SV_PRINT_PRT_NUP_PAGES_BTN ) )
, maBrochureBtn( this, VclResId( SV_PRINT_PRT_NUP_BROCHURE_BTN ) )
, maPagesBoxTitleTxt( this, 0 )
, maNupPagesBox( this, VclResId( SV_PRINT_PRT_NUP_PAGES_BOX ) )
, maNupNumPagesTxt( this, VclResId( SV_PRINT_PRT_NUP_NUM_PAGES_TXT ) )
, maNupColEdt( this, VclResId( SV_PRINT_PRT_NUP_COLS_EDT ) )
, maNupTimesTxt( this, VclResId( SV_PRINT_PRT_NUP_TIMES_TXT ) )
, maNupRowsEdt( this, VclResId( SV_PRINT_PRT_NUP_ROWS_EDT ) )
, maPageMarginTxt1( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_1_TXT ) )
, maPageMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_EDT ) )
, maPageMarginTxt2( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_2_TXT ) )
, maSheetMarginTxt1( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_1_TXT ) )
, maSheetMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_EDT ) )
, maSheetMarginTxt2( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_2_TXT ) )
, maNupOrientationTxt( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_TXT ) )
, maNupOrientationBox( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_BOX ) )
, maNupOrderTxt( this, VclResId( SV_PRINT_PRT_NUP_ORDER_TXT ) )
, maNupOrderBox( this, VclResId( SV_PRINT_PRT_NUP_ORDER_BOX ) )
, maNupOrderWin( this )
, maBorderCB( this, VclResId( SV_PRINT_PRT_NUP_BORDER_CB ) )
{
FreeResource();
maNupOrderWin.Show();
maPagesBtn.Check( sal_True );
maBrochureBtn.Show( sal_False );
// setup field units for metric fields
const LocaleDataWrapper& rLocWrap( maPageMarginEdt.GetLocaleDataWrapper() );
FieldUnit eUnit = FUNIT_MM;
sal_uInt16 nDigits = 0;
if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
{
eUnit = FUNIT_INCH;
nDigits = 2;
}
// set units
maPageMarginEdt.SetUnit( eUnit );
maSheetMarginEdt.SetUnit( eUnit );
// set precision
maPageMarginEdt.SetDecimalDigits( nDigits );
maSheetMarginEdt.SetDecimalDigits( nDigits );
setupLayout();
}
PrintDialog::NUpTabPage::~NUpTabPage()
{
}
void PrintDialog::NUpTabPage::enableNupControls( bool bEnable )
{
maNupPagesBox.Enable( sal_True );
maNupNumPagesTxt.Enable( bEnable );
maNupColEdt.Enable( bEnable );
maNupTimesTxt.Enable( bEnable );
maNupRowsEdt.Enable( bEnable );
maPageMarginTxt1.Enable( bEnable );
maPageMarginEdt.Enable( bEnable );
maPageMarginTxt2.Enable( bEnable );
maSheetMarginTxt1.Enable( bEnable );
maSheetMarginEdt.Enable( bEnable );
maSheetMarginTxt2.Enable( bEnable );
maNupOrientationTxt.Enable( bEnable );
maNupOrientationBox.Enable( bEnable );
maNupOrderTxt.Enable( bEnable );
maNupOrderBox.Enable( bEnable );
maNupOrderWin.Enable( bEnable );
maBorderCB.Enable( bEnable );
}
void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow )
{
maNupNumPagesTxt.Show( i_bShow );
maNupColEdt.Show( i_bShow );
maNupTimesTxt.Show( i_bShow );
maNupRowsEdt.Show( i_bShow );
maPageMarginTxt1.Show( i_bShow );
maPageMarginEdt.Show( i_bShow );
maPageMarginTxt2.Show( i_bShow );
maSheetMarginTxt1.Show( i_bShow );
maSheetMarginEdt.Show( i_bShow );
maSheetMarginTxt2.Show( i_bShow );
maNupOrientationTxt.Show( i_bShow );
maNupOrientationBox.Show( i_bShow );
getLayout()->resize();
}
void PrintDialog::NUpTabPage::setupLayout()
{
boost::shared_ptr<vcl::RowOrColumn> xLayout =
boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
Size aBorder( LogicToPixel( Size( 6, 6 ), MapMode( MAP_APPFONT ) ) );
/* According to OOo style guide, the horizontal indentation of child
elements to their parent element should always be 6 map units. */
long nIndent = aBorder.Width();
xLayout->addWindow( &maNupLine );
boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( xLayout.get(), false ) );
xLayout->addChild( xRow );
boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( xRow.get() ) );
xRow->addChild( xIndent );
boost::shared_ptr< vcl::RowOrColumn > xShowNupCol( new vcl::RowOrColumn( xRow.get() ) );
xRow->addChild( xShowNupCol, -1 );
xShowNupCol->setMinimumSize( xShowNupCol->addWindow( &maNupOrderWin ), Size( 70, 70 ) );
boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( xShowNupCol.get() ) );
xShowNupCol->addChild( xSpacer );
boost::shared_ptr< vcl::LabelColumn > xMainCol( new vcl::LabelColumn( xIndent.get() ) );
xIndent->setChild( xMainCol );
size_t nPagesIndex = xMainCol->addRow( &maPagesBtn, &maNupPagesBox );
mxPagesBtnLabel = boost::dynamic_pointer_cast<vcl::LabeledElement>( xMainCol->getChild( nPagesIndex ) );
xRow.reset( new vcl::RowOrColumn( xMainCol.get(), false ) );
xMainCol->addRow( &maNupNumPagesTxt, xRow, nIndent );
xRow->addWindow( &maNupColEdt );
xRow->addWindow( &maNupTimesTxt );
xRow->addWindow( &maNupRowsEdt );
boost::shared_ptr< vcl::LabeledElement > xLab( new vcl::LabeledElement( xMainCol.get(), 2 ) );
xLab->setLabel( &maPageMarginEdt );
xLab->setElement( &maPageMarginTxt2 );
xMainCol->addRow( &maPageMarginTxt1, xLab, nIndent );
xLab.reset( new vcl::LabeledElement( xMainCol.get(), 2 ) );
xLab->setLabel( &maSheetMarginEdt );
xLab->setElement( &maSheetMarginTxt2 );
xMainCol->addRow( &maSheetMarginTxt1, xLab, nIndent );
xMainCol->addRow( &maNupOrientationTxt, &maNupOrientationBox, nIndent );
xMainCol->addRow( &maNupOrderTxt, &maNupOrderBox, nIndent );
xMainCol->setBorders( xMainCol->addWindow( &maBorderCB ), nIndent, 0, 0, 0 );
xSpacer.reset( new vcl::Spacer( xMainCol.get(), 0, Size( 10, WindowArranger::getDefaultBorder() ) ) );
xMainCol->addChild( xSpacer );
xRow.reset( new vcl::RowOrColumn( xMainCol.get(), false ) );
xMainCol->addRow( &maBrochureBtn, xRow );
// remember brochure row for dependencies
mxBrochureDep = xRow;
// initially advanced controls are not shown, rows=columns=1
showAdvancedControls( false );
}
void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
{
maSheetMarginEdt.SetValue( maSheetMarginEdt.Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
maPageMarginEdt.SetValue( maPageMarginEdt.Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
maBorderCB.Check( i_rMPS.bDrawBorder );
maNupRowsEdt.SetValue( i_rMPS.nRows );
maNupColEdt.SetValue( i_rMPS.nColumns );
}
void PrintDialog::NUpTabPage::readFromSettings()
{
}
void PrintDialog::NUpTabPage::storeToSettings()
{
}
PrintDialog::JobTabPage::JobTabPage( Window* i_pParent, const ResId& rResId )
: TabPage( i_pParent, rResId )
, maPrinterFL( this, VclResId( SV_PRINT_PRINTERS_FL ) )
, maPrinters( this, VclResId( SV_PRINT_PRINTERS ) )
, maDetailsBtn( this, VclResId( SV_PRINT_DETAILS_BTN ) )
, maStatusLabel( this, VclResId( SV_PRINT_STATUS_TXT ) )
, maStatusTxt( this, 0 )
, maLocationLabel( this, VclResId( SV_PRINT_LOCATION_TXT ) )
, maLocationTxt( this, 0 )
, maCommentLabel( this, VclResId( SV_PRINT_COMMENT_TXT ) )
, maCommentTxt( this, 0 )
, maSetupButton( this, VclResId( SV_PRINT_PRT_SETUP ) )
, maCopies( this, VclResId( SV_PRINT_COPIES ) )
, maCopySpacer( this, WB_VERT )
, maCopyCount( this, VclResId( SV_PRINT_COPYCOUNT ) )
, maCopyCountField( this, VclResId( SV_PRINT_COPYCOUNT_FIELD ) )
, maCollateBox( this, VclResId( SV_PRINT_COLLATE ) )
, maCollateImage( this, VclResId( SV_PRINT_COLLATE_IMAGE ) )
, maReverseOrderBox( this, VclResId( SV_PRINT_OPT_REVERSE ) )
, maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
, maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
, mnCollateUIMode( 0 )
{
FreeResource();
maCopySpacer.Show();
maStatusTxt.Show();
maCommentTxt.Show();
maLocationTxt.Show();
setupLayout();
}
PrintDialog::JobTabPage::~JobTabPage()
{
}
void PrintDialog::JobTabPage::setupLayout()
{
// HACK: this is not a dropdown box, but the dropdown line count
// sets the results of GetOptimalSize in a normal ListBox
maPrinters.SetDropDownLineCount( 4 );
boost::shared_ptr<vcl::RowOrColumn> xLayout =
boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
// add printer fixed line
xLayout->addWindow( &maPrinterFL );
// add print LB
xLayout->addWindow( &maPrinters, 3 );
// create a row for details button/text and properties button
boost::shared_ptr< vcl::RowOrColumn > xDetRow( new vcl::RowOrColumn( xLayout.get(), false ) );
xLayout->addChild( xDetRow );
xDetRow->addWindow( &maDetailsBtn );
xDetRow->addChild( new vcl::Spacer( xDetRow.get(), 2 ) );
xDetRow->addWindow( &maSetupButton );
// create an indent for details
boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( xLayout.get() ) );
xLayout->addChild( xIndent );
// remember details controls
mxDetails = xIndent;
// create a column for the details
boost::shared_ptr< vcl::LabelColumn > xLabelCol( new vcl::LabelColumn( xIndent.get() ) );
xIndent->setChild( xLabelCol );
xLabelCol->addRow( &maStatusLabel, &maStatusTxt );
xLabelCol->addRow( &maLocationLabel, &maLocationTxt );
xLabelCol->addRow( &maCommentLabel, &maCommentTxt );
// add print range and copies columns
xLayout->addWindow( &maCopies );
boost::shared_ptr< vcl::RowOrColumn > xRangeRow( new vcl::RowOrColumn( xLayout.get(), false ) );
xLayout->addChild( xRangeRow );
// create print range and add to range row
mxPrintRange.reset( new vcl::RowOrColumn( xRangeRow.get() ) );
xRangeRow->addChild( mxPrintRange );
xRangeRow->addWindow( &maCopySpacer );
boost::shared_ptr< vcl::RowOrColumn > xCopyCollateCol( new vcl::RowOrColumn( xRangeRow.get() ) );
xRangeRow->addChild( xCopyCollateCol );
// add copies row to copy/collate column
boost::shared_ptr< vcl::LabeledElement > xCopiesRow( new vcl::LabeledElement( xCopyCollateCol.get(), 2 ) );
xCopyCollateCol->addChild( xCopiesRow );
xCopiesRow->setLabel( &maCopyCount );
xCopiesRow->setElement( &maCopyCountField );
boost::shared_ptr< vcl::LabeledElement > xCollateRow( new vcl::LabeledElement( xCopyCollateCol.get(), 2 ) );
xCopyCollateCol->addChild( xCollateRow );
xCollateRow->setLabel( &maCollateBox );
xCollateRow->setElement( &maCollateImage );
// maDetailsBtn.SetStyle( maDetailsBtn.GetStyle() | (WB_SMALLSTYLE | WB_BEVELBUTTON) );
mxDetails->show( false, false );
}
void PrintDialog::JobTabPage::readFromSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue;
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CollateBox" ) ) );
if( aValue.equalsIgnoreAsciiCaseAscii( "alwaysoff" ) )
{
mnCollateUIMode = 1;
maCollateBox.Check( sal_False );
maCollateBox.Enable( sal_False );
}
else
{
mnCollateUIMode = 0;
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) );
maCollateBox.Check( aValue.equalsIgnoreAsciiCaseAscii( "true" ) );
}
Resize();
}
void PrintDialog::JobTabPage::storeToSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
maCopyCountField.GetText() );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
maCollateBox.IsChecked() ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true")) :
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")) );
}
PrintDialog::OutputOptPage::OutputOptPage( Window* i_pParent, const ResId& i_rResId )
: TabPage( i_pParent, i_rResId )
, maOptionsLine( this, VclResId( SV_PRINT_OPT_PRINT_FL ) )
, maToFileBox( this, VclResId( SV_PRINT_OPT_TOFILE ) )
, maCollateSingleJobsBox( this, VclResId( SV_PRINT_OPT_SINGLEJOBS ) )
{
FreeResource();
setupLayout();
}
PrintDialog::OutputOptPage::~OutputOptPage()
{
}
void PrintDialog::OutputOptPage::setupLayout()
{
boost::shared_ptr<vcl::RowOrColumn> xLayout =
boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
xLayout->addWindow( &maOptionsLine );
boost::shared_ptr<vcl::Indenter> xIndent( new vcl::Indenter( xLayout.get(), -1 ) );
xLayout->addChild( xIndent );
boost::shared_ptr<vcl::RowOrColumn> xCol( new vcl::RowOrColumn( xIndent.get() ) );
xIndent->setChild( xCol );
mxOptGroup = xCol;
xCol->addWindow( &maToFileBox );
xCol->addWindow( &maCollateSingleJobsBox );
}
void PrintDialog::OutputOptPage::readFromSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue;
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CollateSingleJobs" ) ) );
if ( aValue.equalsIgnoreAsciiCaseAscii( "true" ) )
{
maCollateSingleJobsBox.Check( sal_True );
}
else
{
maCollateSingleJobsBox.Check( sal_False );
}
Resize();
}
void PrintDialog::OutputOptPage::storeToSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToFile" ) ),
maToFileBox.IsChecked() ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))
: rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")) );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CollateSingleJobs" ) ),
maCollateSingleJobsBox.IsChecked() ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true")) :
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")) );
}
PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
: ModalDialog( i_pParent, VclResId( SV_DLG_PRINT ) )
, maTabCtrl( this, VclResId( SV_PRINT_TABCTRL ) )
, maNUpPage( &maTabCtrl, VclResId( SV_PRINT_TAB_NUP ) )
, maJobPage( &maTabCtrl, VclResId( SV_PRINT_TAB_JOB ) )
, maOptionsPage( &maTabCtrl, VclResId( SV_PRINT_TAB_OPT ) )
, maPreviewWindow( this, VclResId( SV_PRINT_PAGE_PREVIEW ) )
, maPageEdit( this, VclResId( SV_PRINT_PAGE_EDIT ) )
, maNumPagesText( this, VclResId( SV_PRINT_PAGE_TXT ) )
, maBackwardBtn( this, VclResId( SV_PRINT_PAGE_BACKWARD ) )
, maForwardBtn( this, VclResId( SV_PRINT_PAGE_FORWARD ) )
, maButtonLine( this, VclResId( SV_PRINT_BUTTONLINE ) )
, maOKButton( this, VclResId( SV_PRINT_OK ) )
, maCancelButton( this, VclResId( SV_PRINT_CANCEL ) )
, maHelpButton( this, VclResId( SV_PRINT_HELP ) )
, maPController( i_rController )
, maNoPageStr( String( VclResId( SV_PRINT_NOPAGES ) ) )
, mnCurPage( 0 )
, mnCachedPages( 0 )
, maPrintToFileText( String( VclResId( SV_PRINT_TOFILE_TXT ) ) )
, maDefPrtText( String( VclResId( SV_PRINT_DEFPRT_TXT ) ) )
, mbShowLayoutPage( sal_True )
{
FreeResource();
// save printbutton text, gets exchanged occasionally with print to file
maPrintText = maOKButton.GetText();
// setup preview controls
maForwardBtn.SetStyle( maForwardBtn.GetStyle() | WB_BEVELBUTTON );
maBackwardBtn.SetStyle( maBackwardBtn.GetStyle() | WB_BEVELBUTTON );
// insert the job (general) tab page first
maTabCtrl.InsertPage( SV_PRINT_TAB_JOB, maJobPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_JOB, &maJobPage );
// set symbols on forward and backward button
maBackwardBtn.SetSymbol( SYMBOL_PREV );
maForwardBtn.SetSymbol( SYMBOL_NEXT );
maBackwardBtn.ImplSetSmallSymbol( sal_True );
maForwardBtn.ImplSetSmallSymbol( sal_True );
maPageStr = maNumPagesText.GetText();
// init reverse print
maJobPage.maReverseOrderBox.Check( maPController->getReversePrint() );
// fill printer listbox
const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() );
for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin();
it != rQueues.end(); ++it )
{
maJobPage.maPrinters.InsertEntry( *it );
}
// select current printer
if( maJobPage.maPrinters.GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
{
maJobPage.maPrinters.SelectEntry( maPController->getPrinter()->GetName() );
}
else
{
// fall back to last printer
SettingsConfigItem* pItem = SettingsConfigItem::get();
String aValue( pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ) ) );
if( maJobPage.maPrinters.GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
{
maJobPage.maPrinters.SelectEntry( aValue );
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
}
else
{
// fall back to default printer
maJobPage.maPrinters.SelectEntry( Printer::GetDefaultPrinterName() );
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
}
}
// not printing to file
maPController->resetPrinterOptions( false );
// get the first page
preparePreview( true, true );
// update the text fields for the printer
updatePrinterText();
// set a select handler
maJobPage.maPrinters.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
// setup sizes for N-Up
Size aNupSize( maPController->getPrinter()->PixelToLogic(
maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
{
maNupLandscapeSize = aNupSize;
maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
}
else
{
maNupPortraitSize = aNupSize;
maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
}
maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
// setup click handler on the various buttons
maOKButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
#if OSL_DEBUG_LEVEL > 1
maCancelButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
#endif
maHelpButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maForwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maBackwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.maCollateBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.maSetupButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.maDetailsBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maNUpPage.maBorderCB.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maOptionsPage.maToFileBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.maReverseOrderBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maOptionsPage.maCollateSingleJobsBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maNUpPage.maPagesBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
// setup modify hdl
maPageEdit.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maJobPage.maCopyCountField.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maNupRowsEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maNupColEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maPageMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maSheetMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
// setup select hdl
maNUpPage.maNupPagesBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
maNUpPage.maNupOrientationBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
maNUpPage.maNupOrderBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
// setup the layout
setupLayout();
// setup optional UI options set by application
setupOptionalUI();
// set change handler for UI options
maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
// set min size pixel to current size
Size aOutSize( GetOutputSizePixel() );
SetMinOutputSizePixel( aOutSize );
// if there is space enough, enlarge the preview so it gets roughly as
// high as the tab control
if( aOutSize.Width() < 768 )
{
Size aJobPageSize( getJobPageSize() );
Size aTabSize( maTabCtrl.GetSizePixel() );
if( aJobPageSize.Width() < 1 )
aJobPageSize.Width() = aTabSize.Width();
if( aJobPageSize.Height() < 1 )
aJobPageSize.Height() = aTabSize.Height();
long nOptPreviewWidth = aTabSize.Height() * aJobPageSize.Width() / aJobPageSize.Height();
// add space for borders
nOptPreviewWidth += 15;
if( aOutSize.Width() - aTabSize.Width() < nOptPreviewWidth )
{
aOutSize.Width() = aTabSize.Width() + nOptPreviewWidth;
if( aOutSize.Width() > 768 ) // don't enlarge the dialog too much
aOutSize.Width() = 768;
SetOutputSizePixel( aOutSize );
}
}
// append further tab pages
if( mbShowLayoutPage )
{
maTabCtrl.InsertPage( SV_PRINT_TAB_NUP, maNUpPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_NUP, &maNUpPage );
}
maTabCtrl.InsertPage( SV_PRINT_TAB_OPT, maOptionsPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_OPT, &maOptionsPage );
// restore settings from last run
readFromSettings();
// setup dependencies
checkControlDependencies();
// set initial focus to "Number of copies"
maJobPage.maCopyCountField.GrabFocus();
maJobPage.maCopyCountField.SetSelection( Selection(0, 0xFFFF) );
}
PrintDialog::~PrintDialog()
{
while( ! maControls.empty() )
{
delete maControls.front();
maControls.pop_front();
}
}
void PrintDialog::setupLayout()
{
boost::shared_ptr<vcl::RowOrColumn> xLayout =
boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
xLayout->setOuterBorder( 0 );
boost::shared_ptr< vcl::RowOrColumn > xPreviewAndTab( new vcl::RowOrColumn( xLayout.get(), false ) );
size_t nIndex = xLayout->addChild( xPreviewAndTab, 5 );
xLayout->setBorders( nIndex, -1, -1, -1, 0 );
// setup column for preview and sub controls
boost::shared_ptr< vcl::RowOrColumn > xPreview( new vcl::RowOrColumn( xPreviewAndTab.get() ) );
xPreviewAndTab->addChild( xPreview, 5 );
xPreview->addWindow( &maPreviewWindow, 5 );
// get a row for the preview controls
mxPreviewCtrls.reset( new vcl::RowOrColumn( xPreview.get(), false ) );
nIndex = xPreview->addChild( mxPreviewCtrls );
boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
mxPreviewCtrls->addChild( xSpacer );
mxPreviewCtrls->addWindow( &maPageEdit );
mxPreviewCtrls->addWindow( &maNumPagesText );
xSpacer.reset( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
mxPreviewCtrls->addChild( xSpacer );
mxPreviewCtrls->addWindow( &maBackwardBtn );
mxPreviewCtrls->addWindow( &maForwardBtn );
xSpacer.reset( new vcl::Spacer( mxPreviewCtrls.get(), 2 ) );
mxPreviewCtrls->addChild( xSpacer );
// continue with the tab ctrl
xPreviewAndTab->addWindow( &maTabCtrl );
// add the button line
xLayout->addWindow( &maButtonLine );
// add the row for the buttons
boost::shared_ptr< vcl::RowOrColumn > xButtons( new vcl::RowOrColumn( xLayout.get(), false ) );
nIndex = xLayout->addChild( xButtons );
xLayout->setBorders( nIndex, -1, 0, -1, -1 );
Size aMinSize( maCancelButton.GetSizePixel() );
// insert help button
xButtons->setMinimumSize( xButtons->addWindow( &maHelpButton ), aMinSize );
// insert a spacer, cancel and OK buttons are right aligned
xSpacer.reset( new vcl::Spacer( xButtons.get(), 2 ) );
xButtons->addChild( xSpacer );
xButtons->setMinimumSize( xButtons->addWindow( &maOKButton ), aMinSize );
xButtons->setMinimumSize( xButtons->addWindow( &maCancelButton ), aMinSize );
}
void PrintDialog::readFromSettings()
{
maJobPage.readFromSettings();
maNUpPage.readFromSettings();
maOptionsPage.readFromSettings();
// read last selected tab page; if it exists, actiavte it
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ) );
sal_uInt16 nCount = maTabCtrl.GetPageCount();
for( sal_uInt16 i = 0; i < nCount; i++ )
{
sal_uInt16 nPageId = maTabCtrl.GetPageId( i );
if( aValue.equals( maTabCtrl.GetPageText( nPageId ) ) )
{
maTabCtrl.SelectTabPage( nPageId );
break;
}
}
maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
// persistent window state
rtl::OUString aWinState( pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WindowState" ) ) ) );
if( aWinState.getLength() )
SetWindowState( rtl::OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) );
if( maOptionsPage.maToFileBox.IsChecked() )
{
maPController->resetPrinterOptions( true );
preparePreview( true, true );
}
}
void PrintDialog::storeToSettings()
{
maJobPage.storeToSettings();
maNUpPage.storeToSettings();
maOptionsPage.storeToSettings();
// store last selected printer
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ),
maJobPage.maPrinters.GetSelectEntry() );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ),
maTabCtrl.GetPageText( maTabCtrl.GetCurPageId() ) );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WindowState" ) ),
rtl::OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 )
);
pItem->Commit();
}
bool PrintDialog::isPrintToFile()
{
return maOptionsPage.maToFileBox.IsChecked();
}
int PrintDialog::getCopyCount()
{
return static_cast<int>(maJobPage.maCopyCountField.GetValue());
}
bool PrintDialog::isCollate()
{
return maJobPage.maCopyCountField.GetValue() > 1 ? maJobPage.maCollateBox.IsChecked() : sal_False;
}
bool PrintDialog::isSingleJobs()
{
return maOptionsPage.maCollateSingleJobsBox.IsChecked();
}
void setHelpId( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpIds, sal_Int32 i_nIndex )
{
if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
i_pWindow->SetHelpId( rtl::OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) );
}
static void setHelpText( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
{
// without a help text set and the correct smartID,
// help texts will be retrieved from the online help system
if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
}
void updateMaxSize( const Size& i_rCheckSize, Size& o_rMaxSize )
{
if( i_rCheckSize.Width() > o_rMaxSize.Width() )
o_rMaxSize.Width() = i_rCheckSize.Width();
if( i_rCheckSize.Height() > o_rMaxSize.Height() )
o_rMaxSize.Height() = i_rCheckSize.Height();
}
void PrintDialog::setupOptionalUI()
{
std::vector< boost::shared_ptr<vcl::RowOrColumn> > aDynamicColumns;
boost::shared_ptr< vcl::RowOrColumn > pCurColumn;
Window* pCurParent = 0, *pDynamicPageParent = 0;
sal_uInt16 nOptPageId = 9;
bool bOnStaticPage = false;
bool bSubgroupOnStaticPage = false;
std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> > aPropertyToDependencyRowMap;
const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
for( int i = 0; i < rOptions.getLength(); i++ )
{
Sequence< beans::PropertyValue > aOptProp;
rOptions[i].Value >>= aOptProp;
// extract ui element
rtl::OUString aCtrlType;
rtl::OUString aText;
rtl::OUString aPropertyName;
Sequence< rtl::OUString > aChoices;
Sequence< sal_Bool > aChoicesDisabled;
Sequence< rtl::OUString > aHelpTexts;
Sequence< rtl::OUString > aHelpIds;
sal_Int64 nMinValue = 0, nMaxValue = 0;
rtl::OUString aGroupingHint;
rtl::OUString aDependsOnName;
sal_Int32 nDependsOnValue = 0;
sal_Bool bUseDependencyRow = sal_False;
for( int n = 0; n < aOptProp.getLength(); n++ )
{
const beans::PropertyValue& rEntry( aOptProp[ n ] );
if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
{
rEntry.Value >>= aText;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ControlType" ) ) )
{
rEntry.Value >>= aCtrlType;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Choices" ) ) )
{
rEntry.Value >>= aChoices;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChoicesDisabled" ) ) )
{
rEntry.Value >>= aChoicesDisabled;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Property" ) ) )
{
PropertyValue aVal;
rEntry.Value >>= aVal;
aPropertyName = aVal.Name;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Enabled" ) ) )
{
sal_Bool bValue = sal_True;
rEntry.Value >>= bValue;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "GroupingHint" ) ) )
{
rEntry.Value >>= aGroupingHint;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DependsOnName" ) ) )
{
rEntry.Value >>= aDependsOnName;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DependsOnEntry" ) ) )
{
rEntry.Value >>= nDependsOnValue;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "AttachToDependency" ) ) )
{
rEntry.Value >>= bUseDependencyRow;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MinValue" ) ) )
{
rEntry.Value >>= nMinValue;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MaxValue" ) ) )
{
rEntry.Value >>= nMaxValue;
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HelpText" ) ) )
{
if( ! (rEntry.Value >>= aHelpTexts) )
{
rtl::OUString aHelpText;
if( (rEntry.Value >>= aHelpText) )
{
aHelpTexts.realloc( 1 );
*aHelpTexts.getArray() = aHelpText;
}
}
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HelpId" ) ) )
{
if( ! (rEntry.Value >>= aHelpIds ) )
{
rtl::OUString aHelpId;
if( (rEntry.Value >>= aHelpId) )
{
aHelpIds.realloc( 1 );
*aHelpIds.getArray() = aHelpId;
}
}
}
else if( rEntry.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HintNoLayoutPage" ) ) )
{
sal_Bool bNoLayoutPage = sal_False;
rEntry.Value >>= bNoLayoutPage;
mbShowLayoutPage = ! bNoLayoutPage;
}
}
// bUseDependencyRow should only be true if a dependency exists
bUseDependencyRow = bUseDependencyRow && (aDependsOnName.getLength() != 0);
// is it necessary to switch between static and dynamic pages ?
bool bSwitchPage = false;
if( aGroupingHint.getLength() )
bSwitchPage = true;
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Subgroup" ) ) || (bOnStaticPage && ! bSubgroupOnStaticPage ) )
bSwitchPage = true;
if( bSwitchPage )
{
// restore to dynamic
pCurParent = pDynamicPageParent;
if( ! aDynamicColumns.empty() )
pCurColumn = aDynamicColumns.back();
else
pCurColumn.reset();
bOnStaticPage = false;
bSubgroupOnStaticPage = false;
if( aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PrintRange" ) ) )
{
pCurColumn = maJobPage.mxPrintRange;
pCurParent = &maJobPage; // set job page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OptionsPage" ) ) )
{
pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maOptionsPage.getLayout());
pCurParent = &maOptionsPage; // set options page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OptionsPageOptGroup" ) ) )
{
pCurColumn = maOptionsPage.mxOptGroup;
pCurParent = &maOptionsPage; // set options page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "LayoutPage" ) ) )
{
pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maNUpPage.getLayout());
pCurParent = &maNUpPage; // set layout page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.getLength() )
{
pCurColumn = boost::dynamic_pointer_cast<vcl::RowOrColumn>(maJobPage.getLayout());
pCurParent = &maJobPage; // set job page as current parent
bOnStaticPage = true;
}
}
if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Group" ) ) ||
( ! pCurParent && ! (bOnStaticPage || aGroupingHint.getLength() ) ) )
{
// add new tab page
TabPage* pNewGroup = new TabPage( &maTabCtrl );
maControls.push_front( pNewGroup );
pDynamicPageParent = pCurParent = pNewGroup;
pNewGroup->SetText( aText );
maTabCtrl.InsertPage( ++nOptPageId, aText );
maTabCtrl.SetTabPage( nOptPageId, pNewGroup );
// set help id
setHelpId( pNewGroup, aHelpIds, 0 );
// set help text
setHelpText( pNewGroup, aHelpTexts, 0 );
aDynamicColumns.push_back( boost::dynamic_pointer_cast<vcl::RowOrColumn>(pNewGroup->getLayout()) );
pCurColumn = aDynamicColumns.back();
pCurColumn->setParentWindow( pNewGroup );
bSubgroupOnStaticPage = false;
bOnStaticPage = false;
}
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Subgroup" ) ) && (pCurParent || aGroupingHint.getLength() ) )
{
bSubgroupOnStaticPage = (aGroupingHint.getLength() != 0);
// create group FixedLine
if( ! aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PrintRange" ) ) ||
! pCurColumn->countElements() == 0
)
{
Window* pNewSub = NULL;
if( aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PrintRange" ) ) )
pNewSub = new FixedText( pCurParent, WB_VCENTER );
else
pNewSub = new FixedLine( pCurParent );
maControls.push_front( pNewSub );
pNewSub->SetText( aText );
pNewSub->Show();
// set help id
setHelpId( pNewSub, aHelpIds, 0 );
// set help text
setHelpText( pNewSub, aHelpTexts, 0 );
// add group to current column
pCurColumn->addWindow( pNewSub );
}
// add an indent to the current column
vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn.get(), -1 );
pCurColumn->addChild( pIndent );
// and create a column inside the indent
pCurColumn.reset( new vcl::RowOrColumn( pIndent ) );
pIndent->setChild( pCurColumn );
}
// EVIL
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Bool" ) ) &&
aGroupingHint.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "LayoutPage" ) ) &&
aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PrintProspect" ) )
)
{
maNUpPage.maBrochureBtn.SetText( aText );
maNUpPage.maBrochureBtn.Show();
setHelpText( &maNUpPage.maBrochureBtn, aHelpTexts, 0 );
sal_Bool bVal = sal_False;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal )
pVal->Value >>= bVal;
maNUpPage.maBrochureBtn.Check( bVal );
maNUpPage.maBrochureBtn.Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
maNUpPage.maBrochureBtn.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maPropertyToWindowMap[ aPropertyName ].push_back( &maNUpPage.maBrochureBtn );
maControlToPropertyMap[&maNUpPage.maBrochureBtn] = aPropertyName;
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, maNUpPage.mxBrochureDep ) );
}
else
{
boost::shared_ptr<vcl::RowOrColumn> pSaveCurColumn( pCurColumn );
if( bUseDependencyRow )
{
// find the correct dependency row (if any)
std::pair< std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >::iterator,
std::multimap< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >::iterator > aDepRange;
aDepRange = aPropertyToDependencyRowMap.equal_range( aDependsOnName );
if( aDepRange.first != aDepRange.second )
{
while( nDependsOnValue && aDepRange.first != aDepRange.second )
{
nDependsOnValue--;
++aDepRange.first;
}
if( aDepRange.first != aPropertyToDependencyRowMap.end() )
{
pCurColumn = aDepRange.first->second;
maReverseDependencySet.insert( aPropertyName );
}
}
}
if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Bool" ) ) && pCurParent )
{
// add a check box
CheckBox* pNewBox = new CheckBox( pCurParent );
maControls.push_front( pNewBox );
pNewBox->SetText( aText );
pNewBox->Show();
sal_Bool bVal = sal_False;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal )
pVal->Value >>= bVal;
pNewBox->Check( bVal );
pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
maPropertyToWindowMap[ aPropertyName ].push_back( pNewBox );
maControlToPropertyMap[pNewBox] = aPropertyName;
// set help id
setHelpId( pNewBox, aHelpIds, 0 );
// set help text
setHelpText( pNewBox, aHelpTexts, 0 );
boost::shared_ptr<vcl::RowOrColumn> pDependencyRow( new vcl::RowOrColumn( pCurColumn.get(), false ) );
pCurColumn->addChild( pDependencyRow );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pDependencyRow ) );
// add checkbox to current column
pDependencyRow->addWindow( pNewBox );
}
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Radio" ) ) && pCurParent )
{
sal_Int32 nCurHelpText = 0;
boost::shared_ptr<vcl::RowOrColumn> pRadioColumn( pCurColumn );
if( aText.getLength() )
{
// add a FixedText:
FixedText* pHeading = new FixedText( pCurParent );
maControls.push_front( pHeading );
pHeading->SetText( aText );
pHeading->Show();
// set help id
setHelpId( pHeading, aHelpIds, nCurHelpText );
// set help text
setHelpText( pHeading, aHelpTexts, nCurHelpText );
nCurHelpText++;
// add fixed text to current column
pCurColumn->addWindow( pHeading );
// add an indent to the current column
vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn.get(), 15 );
pCurColumn->addChild( pIndent );
// and create a column inside the indent
pRadioColumn.reset( new vcl::RowOrColumn( pIndent ) );
pIndent->setChild( pRadioColumn );
}
// iterate options
sal_Int32 nSelectVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nSelectVal;
for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
{
boost::shared_ptr<vcl::LabeledElement> pLabel( new vcl::LabeledElement( pRadioColumn.get(), 1 ) );
pRadioColumn->addChild( pLabel );
boost::shared_ptr<vcl::RowOrColumn> pDependencyRow( new vcl::RowOrColumn( pLabel.get(), false ) );
pLabel->setElement( pDependencyRow );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pDependencyRow ) );
RadioButton* pBtn = new RadioButton( pCurParent, m == 0 ? WB_GROUP : 0 );
maControls.push_front( pBtn );
pBtn->SetText( aChoices[m] );
pBtn->Check( m == nSelectVal );
pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] == sal_True )
pBtn->Enable( sal_False );
pBtn->Show();
maPropertyToWindowMap[ aPropertyName ].push_back( pBtn );
maControlToPropertyMap[pBtn] = aPropertyName;
maControlToNumValMap[pBtn] = m;
// set help id
setHelpId( pBtn, aHelpIds, nCurHelpText );
// set help text
setHelpText( pBtn, aHelpTexts, nCurHelpText );
nCurHelpText++;
// add the radio button to the column
pLabel->setLabel( pBtn );
}
}
else if( ( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "List" ) ) ||
aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Range" ) ) ||
aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Edit" ) )
) && pCurParent )
{
// create a row in the current column
boost::shared_ptr<vcl::RowOrColumn> pFieldColumn( new vcl::RowOrColumn( pCurColumn.get(), false ) );
pCurColumn->addChild( pFieldColumn );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, boost::shared_ptr<vcl::RowOrColumn> >( aPropertyName, pFieldColumn ) );
vcl::LabeledElement* pLabel = NULL;
if( aText.getLength() )
{
// add a FixedText:
FixedText* pHeading = new FixedText( pCurParent, WB_VCENTER );
maControls.push_front( pHeading );
pHeading->SetText( aText );
pHeading->Show();
// add to row
pLabel = new vcl::LabeledElement( pFieldColumn.get(), 2 );
pFieldColumn->addChild( pLabel );
pLabel->setLabel( pHeading );
}
if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "List" ) ) )
{
ListBox* pList = new ListBox( pCurParent, WB_DROPDOWN | WB_BORDER );
maControls.push_front( pList );
// iterate options
for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
{
pList->InsertEntry( aChoices[m] );
}
sal_Int32 nSelectVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nSelectVal;
pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) );
pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) );
pList->Show();
// set help id
setHelpId( pList, aHelpIds, 0 );
// set help text
setHelpText( pList, aHelpTexts, 0 );
maPropertyToWindowMap[ aPropertyName ].push_back( pList );
maControlToPropertyMap[pList] = aPropertyName;
// finish the pair
if( pLabel )
pLabel->setElement( pList );
else
pFieldColumn->addWindow( pList );
}
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Range" ) ) )
{
NumericField* pField = new NumericField( pCurParent, WB_BORDER | WB_SPIN );
maControls.push_front( pField );
// set min/max and current value
if( nMinValue != nMaxValue )
{
pField->SetMin( nMinValue );
pField->SetMax( nMaxValue );
}
sal_Int64 nCurVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nCurVal;
pField->SetValue( nCurVal );
pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
pField->Show();
// set help id
setHelpId( pField, aHelpIds, 0 );
// set help text
setHelpText( pField, aHelpTexts, 0 );
maPropertyToWindowMap[ aPropertyName ].push_back( pField );
maControlToPropertyMap[pField] = aPropertyName;
// add to row
if( pLabel )
pLabel->setElement( pField );
else
pFieldColumn->addWindow( pField );
}
else if( aCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Edit" ) ) )
{
Edit* pField = new Edit( pCurParent, WB_BORDER );
maControls.push_front( pField );
rtl::OUString aCurVal;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= aCurVal;
pField->SetText( aCurVal );
pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
pField->Show();
// set help id
setHelpId( pField, aHelpIds, 0 );
// set help text
setHelpText( pField, aHelpTexts, 0 );
maPropertyToWindowMap[ aPropertyName ].push_back( pField );
maControlToPropertyMap[pField] = aPropertyName;
// add to row
if( pLabel )
pLabel->setElement( pField );
else
pFieldColumn->addWindow( pField, 2 );
}
}
else
{
rtl::OStringBuffer sMessage;
sMessage.append(RTL_CONSTASCII_STRINGPARAM("Unsupported UI option: \""));
sMessage.append(rtl::OUStringToOString(aCtrlType, RTL_TEXTENCODING_UTF8));
sMessage.append('"');
OSL_FAIL( sMessage.getStr() );
}
pCurColumn = pSaveCurColumn;
}
}
// #i106506# if no brochure button, then the singular Pages radio button
// makes no sense, so replace it by a FixedText label
if( ! maNUpPage.maBrochureBtn.IsVisible() )
{
if( maNUpPage.mxPagesBtnLabel.get() )
{
maNUpPage.maPagesBoxTitleTxt.SetText( maNUpPage.maPagesBtn.GetText() );
maNUpPage.maPagesBoxTitleTxt.Show( sal_True );
maNUpPage.mxPagesBtnLabel->setLabel( &maNUpPage.maPagesBoxTitleTxt );
maNUpPage.maPagesBtn.Show( sal_False );
}
}
// update enable states
checkOptionalControlDependencies();
// print range empty (currently math only) -> hide print range and spacer line
if( maJobPage.mxPrintRange->countElements() == 0 )
{
maJobPage.mxPrintRange->show( false, false );
maJobPage.maCopySpacer.Show( sal_False );
maJobPage.maReverseOrderBox.Show( sal_False );
}
else
{
// add an indent to the current column
vcl::Indenter* pIndent = new vcl::Indenter( maJobPage.mxPrintRange.get(), -1 );
maJobPage.mxPrintRange->addChild( pIndent );
// and create a column inside the indent
pIndent->setWindow( &maJobPage.maReverseOrderBox );
maJobPage.maReverseOrderBox.Show( sal_True );
}
#ifdef WNT
// FIXME: the GetNativeControlRegion call on Windows has some issues
// (which skew the results of GetOptimalSize())
// however fixing this thoroughly needs to take interaction with paint into
// account, making the right fix less simple. Fix this the right way
// at some point. For now simply add some space at the lowest element
size_t nIndex = maJobPage.getLayout()->countElements();
if( nIndex > 0 ) // sanity check
maJobPage.getLayout()->setBorders( nIndex-1, 0, 0, 0, -1 );
#endif
// create auto mnemomnics now so they can be calculated in layout
ImplWindowAutoMnemonic( &maJobPage );
ImplWindowAutoMnemonic( &maNUpPage );
ImplWindowAutoMnemonic( &maOptionsPage );
ImplWindowAutoMnemonic( this );
// calculate job page
Size aMaxSize = maJobPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED );
// and layout page
updateMaxSize( maNUpPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ), aMaxSize );
// and options page
updateMaxSize( maOptionsPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ), aMaxSize );
for( std::vector< boost::shared_ptr<vcl::RowOrColumn> >::iterator it = aDynamicColumns.begin();
it != aDynamicColumns.end(); ++it )
{
Size aPageSize( (*it)->getOptimalSize( WINDOWSIZE_PREFERRED ) );
updateMaxSize( aPageSize, aMaxSize );
}
// resize dialog if necessary
Size aTabSize = maTabCtrl.GetTabPageSizePixel();
maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
if( aMaxSize.Height() > aTabSize.Height() || aMaxSize.Width() > aTabSize.Width() )
{
Size aCurSize( GetOutputSizePixel() );
if( aMaxSize.Height() > aTabSize.Height() )
{
aCurSize.Height() += aMaxSize.Height() - aTabSize.Height();
aTabSize.Height() = aMaxSize.Height();
}
if( aMaxSize.Width() > aTabSize.Width() )
{
aCurSize.Width() += aMaxSize.Width() - aTabSize.Width();
// and the tab ctrl needs more space, too
aTabSize.Width() = aMaxSize.Width();
}
maTabCtrl.SetTabPageSizePixel( aTabSize );
maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
}
Size aSz = getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED );
SetOutputSizePixel( aSz );
}
void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt )
{
// react on settings changed
if( i_rDCEvt.GetType() == DATACHANGED_SETTINGS )
checkControlDependencies();
ModalDialog::DataChanged( i_rDCEvt );
}
void PrintDialog::checkControlDependencies()
{
if( maJobPage.maCopyCountField.GetValue() > 1 )
maJobPage.maCollateBox.Enable( maJobPage.mnCollateUIMode == 0 );
else
maJobPage.maCollateBox.Enable( sal_False );
Image aImg( maJobPage.maCollateBox.IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
Size aImgSize( aImg.GetSizePixel() );
// adjust size of image
maJobPage.maCollateImage.SetSizePixel( aImgSize );
maJobPage.maCollateImage.SetImage( aImg );
maJobPage.getLayout()->resize();
// enable setup button only for printers that can be setup
bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
maJobPage.maSetupButton.Enable( bHaveSetup );
if( bHaveSetup )
{
if( ! maJobPage.maSetupButton.IsVisible() )
{
Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
aPrinterSize.Width() = aSetupPos.X() - aPrinterPos.X() - LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ).Width();
maJobPage.maPrinters.SetSizePixel( aPrinterSize );
maJobPage.maSetupButton.Show();
getLayout()->resize();
}
}
else
{
if( maJobPage.maSetupButton.IsVisible() )
{
Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
Size aSetupSize( maJobPage.maSetupButton.GetSizePixel() );
aPrinterSize.Width() = aSetupPos.X() + aSetupSize.Width() - aPrinterPos.X();
maJobPage.maPrinters.SetSizePixel( aPrinterSize );
maJobPage.maSetupButton.Hide();
getLayout()->resize();
}
}
}
void PrintDialog::checkOptionalControlDependencies()
{
for( std::map< Window*, rtl::OUString >::iterator it = maControlToPropertyMap.begin();
it != maControlToPropertyMap.end(); ++it )
{
bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
if( ! bShouldbeEnabled )
{
// enable controls that are directly attached to a dependency anyway
// if the normally disabled controls get modified, change the dependency
// so the control would be enabled
// example: in print range "Print All" is selected, "Page Range" is then of course
// not selected and the Edit for the Page Range would be disabled
// as a convenience we should enable the Edit anyway and automatically select
// "Page Range" instead of "Print All" if the Edit gets modified
if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() )
{
rtl::OUString aDep( maPController->getDependency( it->second ) );
// if the dependency is at least enabled, then enable this control anyway
if( aDep.getLength() && maPController->isUIOptionEnabled( aDep ) )
bShouldbeEnabled = true;
}
}
if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) )
{
std::map< Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first );
if( r_it != maControlToNumValMap.end() )
{
bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second );
}
}
bool bIsEnabled = it->first->IsEnabled();
// Enable does not do a change check first, so can be less cheap than expected
if( bShouldbeEnabled != bIsEnabled )
it->first->Enable( bShouldbeEnabled );
}
}
static rtl::OUString searchAndReplace( const rtl::OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const rtl::OUString& i_rRepl )
{
sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
if( nPos != -1 )
{
rtl::OUStringBuffer aBuf( i_rOrig.getLength() );
aBuf.append( i_rOrig.getStr(), nPos );
aBuf.append( i_rRepl );
if( nPos + i_nReplLen < i_rOrig.getLength() )
aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
return aBuf.makeStringAndClear();
}
return i_rOrig;
}
void PrintDialog::updatePrinterText()
{
const rtl::OUString aDefPrt( Printer::GetDefaultPrinterName() );
const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.maPrinters.GetSelectEntry(), true );
if( pInfo )
{
maJobPage.maLocationTxt.SetText( pInfo->GetLocation() );
maJobPage.maCommentTxt.SetText( pInfo->GetComment() );
// FIXME: status text
rtl::OUString aStatus;
if( aDefPrt == pInfo->GetPrinterName() )
aStatus = maDefPrtText;
maJobPage.maStatusTxt.SetText( aStatus );
}
else
{
maJobPage.maLocationTxt.SetText( String() );
maJobPage.maCommentTxt.SetText( String() );
maJobPage.maStatusTxt.SetText( String() );
}
}
void PrintDialog::setPreviewText( sal_Int32 )
{
rtl::OUString aNewText( searchAndReplace( maPageStr, "%n", 2, rtl::OUString::valueOf( mnCachedPages ) ) );
maNumPagesText.SetText( aNewText );
// if layout is already established the refresh layout of
// preview controls since text length may have changes
if( mxPreviewCtrls.get() )
mxPreviewCtrls->setManagedArea( mxPreviewCtrls->getManagedArea() );
}
void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
{
// page range may have changed depending on options
sal_Int32 nPages = maPController->getFilteredPageCount();
mnCachedPages = nPages;
if( mnCurPage >= nPages )
mnCurPage = nPages-1;
if( mnCurPage < 0 )
mnCurPage = 0;
setPreviewText( mnCurPage );
maPageEdit.SetMin( 1 );
maPageEdit.SetMax( nPages );
if( i_bNewPage )
{
const MapMode aMapMode( MAP_100TH_MM );
GDIMetaFile aMtf;
boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
if( nPages > 0 )
{
PrinterController::PageSize aPageSize =
maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
if( ! aPageSize.bFullPaper )
{
Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
aMtf.Move( aOff.X(), aOff.Y() );
}
}
Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
maPreviewWindow.setPreview( aMtf, aCurPageSize,
aPrt->GetPaperName( false ),
nPages > 0 ? rtl::OUString() : maNoPageStr,
aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(),
aPrt->GetPrinterOptions().IsConvertToGreyscales()
);
maForwardBtn.Enable( mnCurPage < nPages-1 );
maBackwardBtn.Enable( mnCurPage != 0 );
maPageEdit.Enable( nPages > 1 );
}
}
Size PrintDialog::getJobPageSize()
{
if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
{
maFirstPageSize = maNupPortraitSize;
GDIMetaFile aMtf;
if( maPController->getPageCountProtected() > 0 )
{
PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
maFirstPageSize = aPageSize.aSize;
}
}
return maFirstPageSize;
}
void PrintDialog::updateNupFromPages()
{
long nPages = long(maNUpPage.maNupPagesBox.GetEntryData(maNUpPage.maNupPagesBox.GetSelectEntryPos()));
int nRows = int(maNUpPage.maNupRowsEdt.GetValue());
int nCols = int(maNUpPage.maNupColEdt.GetValue());
long nPageMargin = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
bool bCustom = false;
if( nPages == 1 )
{
nRows = nCols = 1;
nSheetMargin = 0;
nPageMargin = 0;
}
else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
{
Size aJobPageSize( getJobPageSize() );
bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
if( nPages == 2 )
{
if( bPortrait )
nRows = 1, nCols = 2;
else
nRows = 2, nCols = 1;
}
else if( nPages == 4 )
nRows = nCols = 2;
else if( nPages == 6 )
{
if( bPortrait )
nRows = 2, nCols = 3;
else
nRows = 3, nCols = 2;
}
else if( nPages == 9 )
nRows = nCols = 3;
else if( nPages == 16 )
nRows = nCols = 4;
nPageMargin = 0;
nSheetMargin = 0;
}
else
bCustom = true;
if( nPages > 1 )
{
// set upper limits for margins based on job page size and rows/columns
Size aSize( getJobPageSize() );
// maximum sheet distance: 1/2 sheet
long nHorzMax = aSize.Width()/2;
long nVertMax = aSize.Height()/2;
if( nSheetMargin > nHorzMax )
nSheetMargin = nHorzMax;
if( nSheetMargin > nVertMax )
nSheetMargin = nVertMax;
maNUpPage.maSheetMarginEdt.SetMax(
maNUpPage.maSheetMarginEdt.Normalize(
nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
// maximum page distance
nHorzMax = (aSize.Width() - 2*nSheetMargin);
if( nCols > 1 )
nHorzMax /= (nCols-1);
nVertMax = (aSize.Height() - 2*nSheetMargin);
if( nRows > 1 )
nHorzMax /= (nRows-1);
if( nPageMargin > nHorzMax )
nPageMargin = nHorzMax;
if( nPageMargin > nVertMax )
nPageMargin = nVertMax;
maNUpPage.maPageMarginEdt.SetMax(
maNUpPage.maSheetMarginEdt.Normalize(
nHorzMax > nVertMax ? nVertMax : nHorzMax ), FUNIT_100TH_MM );
}
maNUpPage.maNupRowsEdt.SetValue( nRows );
maNUpPage.maNupColEdt.SetValue( nCols );
maNUpPage.maPageMarginEdt.SetValue( maNUpPage.maPageMarginEdt.Normalize( nPageMargin ), FUNIT_100TH_MM );
maNUpPage.maSheetMarginEdt.SetValue( maNUpPage.maSheetMarginEdt.Normalize( nSheetMargin ), FUNIT_100TH_MM );
maNUpPage.showAdvancedControls( bCustom );
if( bCustom )
{
// see if we have to enlarge the dialog to make the tab page fit
Size aCurSize( maNUpPage.getLayout()->getOptimalSize( WINDOWSIZE_PREFERRED ) );
Size aTabSize( maTabCtrl.GetTabPageSizePixel() );
if( aTabSize.Height() < aCurSize.Height() )
{
Size aDlgSize( GetSizePixel() );
aDlgSize.Height() += aCurSize.Height() - aTabSize.Height();
SetSizePixel( aDlgSize );
}
}
updateNup();
}
void PrintDialog::updateNup()
{
int nRows = int(maNUpPage.maNupRowsEdt.GetValue());
int nCols = int(maNUpPage.maNupColEdt.GetValue());
long nPageMargin = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
PrinterController::MultiPageSetup aMPS;
aMPS.nRows = nRows;
aMPS.nColumns = nCols;
aMPS.nRepeat = 1;
aMPS.nLeftMargin =
aMPS.nTopMargin =
aMPS.nRightMargin =
aMPS.nBottomMargin = nSheetMargin;
aMPS.nHorizontalSpacing =
aMPS.nVerticalSpacing = nPageMargin;
aMPS.bDrawBorder = maNUpPage.maBorderCB.IsChecked();
int nOrderMode = int(sal_IntPtr(maNUpPage.maNupOrderBox.GetEntryData(
maNUpPage.maNupOrderBox.GetSelectEntryPos() )));
if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_LRTB )
aMPS.nOrder = PrinterController::LRTB;
else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBLR )
aMPS.nOrder = PrinterController::TBLR;
else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_RLTB )
aMPS.nOrder = PrinterController::RLTB;
else if( nOrderMode == SV_PRINT_PRT_NUP_ORDER_TBRL )
aMPS.nOrder = PrinterController::TBRL;
int nOrientationMode = int(sal_IntPtr(maNUpPage.maNupOrientationBox.GetEntryData(
maNUpPage.maNupOrientationBox.GetSelectEntryPos() )));
if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
aMPS.aPaperSize = maNupLandscapeSize;
else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
aMPS.aPaperSize = maNupPortraitSize;
else // automatic mode
{
// get size of first real page to see if it is portrait or landscape
// we assume same page sizes for all the pages for this
Size aPageSize = getJobPageSize();
Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
aMPS.aPaperSize = maNupLandscapeSize;
else
aMPS.aPaperSize = maNupPortraitSize;
}
maPController->setMultipage( aMPS );
maNUpPage.maNupOrderWin.setValues( nOrderMode, nCols, nRows );
preparePreview( true, true );
}
IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
{
if( pBox == &maJobPage.maPrinters )
{
String aNewPrinter( pBox->GetSelectEntry() );
// set new printer
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() );
// update text fields
updatePrinterText();
preparePreview( true, false );
}
else if( pBox == &maNUpPage.maNupOrientationBox || pBox == &maNUpPage.maNupOrderBox )
{
updateNup();
}
else if( pBox == &maNUpPage.maNupPagesBox )
{
if( !maNUpPage.maPagesBtn.IsChecked() )
maNUpPage.maPagesBtn.Check();
updateNupFromPages();
}
return 0;
}
IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
{
if( pButton == &maOKButton || pButton == &maCancelButton )
{
storeToSettings();
EndDialog( pButton == &maOKButton );
}
else if( pButton == &maHelpButton )
{
// start help system
Help* pHelp = Application::GetHelp();
if( pHelp )
{
pHelp->Start( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:OK" ) ), &maOKButton );
}
}
else if( pButton == &maForwardBtn )
{
previewForward();
}
else if( pButton == &maBackwardBtn )
{
previewBackward();
}
else if( pButton == &maOptionsPage.maToFileBox )
{
maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() );
getLayout()->resize();
preparePreview( true, true );
}
else if( pButton == &maNUpPage.maBrochureBtn )
{
PropertyValue* pVal = getValueForWindow( pButton );
if( pVal )
{
sal_Bool bVal = maNUpPage.maBrochureBtn.IsChecked();
pVal->Value <<= bVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
if( maNUpPage.maBrochureBtn.IsChecked() )
{
maNUpPage.maNupPagesBox.SelectEntryPos( 0 );
updateNupFromPages();
maNUpPage.showAdvancedControls( false );
maNUpPage.enableNupControls( false );
}
}
else if( pButton == &maNUpPage.maPagesBtn )
{
maNUpPage.enableNupControls( true );
updateNupFromPages();
}
else if( pButton == &maJobPage.maDetailsBtn )
{
bool bShow = maJobPage.maDetailsBtn.IsChecked();
maJobPage.mxDetails->show( bShow );
if( bShow )
{
maDetailsCollapsedSize = GetOutputSizePixel();
// enlarge dialog if necessary
Size aMinSize( maJobPage.getLayout()->getOptimalSize( WINDOWSIZE_MINIMUM ) );
Size aCurSize( maJobPage.GetSizePixel() );
if( aCurSize.Height() < aMinSize.Height() )
{
Size aDlgSize( GetOutputSizePixel() );
aDlgSize.Height() += aMinSize.Height() - aCurSize.Height();
SetOutputSizePixel( aDlgSize );
}
maDetailsExpandedSize = GetOutputSizePixel();
}
else if( maDetailsCollapsedSize.Width() > 0 &&
maDetailsCollapsedSize.Height() > 0 )
{
// if the user did not resize the dialog
// make it smaller again on collapsing the details
Size aDlgSize( GetOutputSizePixel() );
if( aDlgSize == maDetailsExpandedSize &&
aDlgSize.Height() > maDetailsCollapsedSize.Height() )
{
SetOutputSizePixel( maDetailsCollapsedSize );
}
}
}
else if( pButton == &maJobPage.maCollateBox )
{
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
makeAny( sal_Bool(isCollate()) ) );
checkControlDependencies();
}
else if( pButton == &maJobPage.maReverseOrderBox )
{
sal_Bool bChecked = maJobPage.maReverseOrderBox.IsChecked();
maPController->setReversePrint( bChecked );
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintReverse" ) ),
makeAny( bChecked ) );
preparePreview( true, true );
}
else if( pButton == &maNUpPage.maBorderCB )
{
updateNup();
}
else
{
if( pButton == &maJobPage.maSetupButton )
{
maPController->setupPrinter( this );
preparePreview( true, true );
}
checkControlDependencies();
}
return 0;
}
IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
{
checkControlDependencies();
if( pEdit == &maNUpPage.maNupRowsEdt || pEdit == &maNUpPage.maNupColEdt ||
pEdit == &maNUpPage.maSheetMarginEdt || pEdit == &maNUpPage.maPageMarginEdt
)
{
updateNupFromPages();
}
else if( pEdit == &maPageEdit )
{
mnCurPage = sal_Int32( maPageEdit.GetValue() - 1 );
preparePreview( true, true );
}
else if( pEdit == &maJobPage.maCopyCountField )
{
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
makeAny( sal_Int32(maJobPage.maCopyCountField.GetValue()) ) );
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
makeAny( sal_Bool(isCollate()) ) );
}
return 0;
}
IMPL_LINK( PrintDialog, UIOptionsChanged, void*, EMPTYARG )
{
checkOptionalControlDependencies();
return 0;
}
PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
{
PropertyValue* pVal = NULL;
std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
if( it != maControlToPropertyMap.end() )
{
pVal = maPController->getValue( it->second );
DBG_ASSERT( pVal, "property value not found" );
}
else
{
OSL_FAIL( "changed control not in property map" );
}
return pVal;
}
void PrintDialog::updateWindowFromProperty( const rtl::OUString& i_rProperty )
{
beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
std::map< rtl::OUString, std::vector< Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty );
if( pValue && it != maPropertyToWindowMap.end() )
{
const std::vector< Window* >& rWindows( it->second );
if( ! rWindows.empty() )
{
sal_Bool bVal = sal_False;
sal_Int32 nVal = -1;
if( pValue->Value >>= bVal )
{
// we should have a CheckBox for this one
CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() );
if( pBox )
{
pBox->Check( bVal );
}
else if( i_rProperty.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PrintProspect" ) ) )
{
// EVIL special case
if( bVal )
maNUpPage.maBrochureBtn.Check();
else
maNUpPage.maPagesBtn.Check();
}
else
{
DBG_ASSERT( 0, "missing a checkbox" );
}
}
else if( pValue->Value >>= nVal )
{
// this could be a ListBox or a RadioButtonGroup
ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() );
if( pList )
{
pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) );
}
else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
{
RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] );
DBG_ASSERT( pBtn, "unexpected control for property" );
if( pBtn )
pBtn->Check();
}
}
}
}
}
void PrintDialog::makeEnabled( Window* i_pWindow )
{
std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
if( it != maControlToPropertyMap.end() )
{
rtl::OUString aDependency( maPController->makeEnabled( it->second ) );
if( aDependency.getLength() )
updateWindowFromProperty( aDependency );
}
}
IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
makeEnabled( i_pBox );
sal_Bool bVal = i_pBox->IsChecked();
pVal->Value <<= bVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
{
// this handler gets called for all radiobuttons that get unchecked, too
// however we only want one notificaction for the new value (that is for
// the button that gets checked)
if( i_pBtn->IsChecked() )
{
PropertyValue* pVal = getValueForWindow( i_pBtn );
std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
if( pVal && it != maControlToNumValMap.end() )
{
makeEnabled( i_pBtn );
sal_Int32 nVal = it->second;
pVal->Value <<= nVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
}
return 0;
}
IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
makeEnabled( i_pBox );
sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
pVal->Value <<= nVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
makeEnabled( i_pBox );
NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
if( pNum )
{
sal_Int64 nVal = pNum->GetValue();
pVal->Value <<= nVal;
}
else if( pMetric )
{
sal_Int64 nVal = pMetric->GetValue();
pVal->Value <<= nVal;
}
else
{
rtl::OUString aVal( i_pBox->GetText() );
pVal->Value <<= aVal;
}
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
void PrintDialog::Command( const CommandEvent& rEvt )
{
if( rEvt.GetCommand() == COMMAND_WHEEL )
{
const CommandWheelData* pWheelData = rEvt.GetWheelData();
if( pWheelData->GetDelta() > 0 )
previewForward();
else if( pWheelData->GetDelta() < 0 )
previewBackward();
/*
else
huh ?
*/
}
}
void PrintDialog::Resize()
{
// maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
// and do the preview; however the metafile does not need to be gotten anew
preparePreview( false );
// do an invalidate for the benefit of the grouping elements
Invalidate();
}
void PrintDialog::previewForward()
{
maPageEdit.Up();
}
void PrintDialog::previewBackward()
{
maPageEdit.Down();
}
// -----------------------------------------------------------------------------
//
// PrintProgressDialog
//
// -----------------------------------------------------------------------------
PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
mbCanceled( false ),
mnCur( 0 ),
mnMax( i_nMax ),
mnProgressHeight( 15 ),
mbNativeProgress( false )
{
FreeResource();
if( mnMax < 1 )
mnMax = 1;
maStr = maText.GetText();
maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
}
PrintProgressDialog::~PrintProgressDialog()
{
}
IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
{
if( pButton == &maButton )
mbCanceled = true;
return 0;
}
void PrintProgressDialog::implCalcProgressRect()
{
if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
{
ImplControlValue aValue;
Rectangle aControlRegion( Point(), Size( 100, mnProgressHeight ) );
Rectangle aNativeControlRegion, aNativeContentRegion;
if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
CTRL_STATE_ENABLED, aValue, rtl::OUString(),
aNativeControlRegion, aNativeContentRegion ) )
{
mnProgressHeight = aNativeControlRegion.GetHeight();
}
mbNativeProgress = true;
}
maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
}
void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
{
if( maProgressRect.IsEmpty() )
implCalcProgressRect();
mnCur = i_nCurrent;
if( i_nMax != -1 )
mnMax = i_nMax;
if( mnMax < 1 )
mnMax = 1;
rtl::OUString aNewText( searchAndReplace( maStr, "%p", 2, rtl::OUString::valueOf( mnCur ) ) );
aNewText = searchAndReplace( aNewText, "%n", 2, rtl::OUString::valueOf( mnMax ) );
maText.SetText( aNewText );
// update progress
Invalidate( maProgressRect, INVALIDATE_UPDATE );
}
void PrintProgressDialog::tick()
{
if( mnCur < mnMax )
setProgress( ++mnCur );
}
void PrintProgressDialog::reset()
{
mbCanceled = false;
setProgress( 0 );
}
void PrintProgressDialog::Paint( const Rectangle& )
{
if( maProgressRect.IsEmpty() )
implCalcProgressRect();
Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
Color aPrgsColor = rStyleSettings.GetHighlightColor();
if ( aPrgsColor == rStyleSettings.GetFaceColor() )
aPrgsColor = rStyleSettings.GetDarkShadowColor();
SetLineColor();
SetFillColor( aPrgsColor );
const long nOffset = 3;
const long nWidth = 3*mnProgressHeight/2;
const long nFullWidth = nWidth + nOffset;
const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
DrawProgress( this, maProgressRect.TopLeft(),
nOffset,
nWidth,
mnProgressHeight,
static_cast<sal_uInt16>(0),
static_cast<sal_uInt16>(10000*mnCur/mnMax),
static_cast<sal_uInt16>(10000/nMaxCount),
maProgressRect
);
Pop();
if( ! mbNativeProgress )
{
DecorationView aDecoView( this );
Rectangle aFrameRect( maProgressRect );
aFrameRect.Left() -= nOffset;
aFrameRect.Right() += nOffset;
aFrameRect.Top() -= nOffset;
aFrameRect.Bottom() += nOffset;
aDecoView.DrawFrame( aFrameRect );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|