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
|
/* -*- 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 <unocrsrhelper.hxx>
#include <map>
#include <algorithm>
#include <memory>
#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/text/XTextSection.hpp>
#include <svx/svxids.hrc>
#include <svx/unoshape.hxx>
#include <cmdid.h>
#include <unotextrange.hxx>
#include <unodraw.hxx>
#include <unofootnote.hxx>
#include <unobookmark.hxx>
#include <unorefmark.hxx>
#include <unostyle.hxx>
#include <unoidx.hxx>
#include <unofield.hxx>
#include <unotbl.hxx>
#include <unosett.hxx>
#include <unoframe.hxx>
#include <unocrsr.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <fmtftn.hxx>
#include <fmtpdsc.hxx>
#include <charfmt.hxx>
#include <pagedesc.hxx>
#include <docstyle.hxx>
#include <ndtxt.hxx>
#include <txtrfmrk.hxx>
#include <fmtfld.hxx>
#include <docsh.hxx>
#include <section.hxx>
#include <shellio.hxx>
#include <edimp.hxx>
#include <swundo.hxx>
#include <cntfrm.hxx>
#include <pagefrm.hxx>
#include <svl/eitem.hxx>
#include <docary.hxx>
#include <swtable.hxx>
#include <tox.hxx>
#include <doctxm.hxx>
#include <fchrfmt.hxx>
#include <editeng/flstitem.hxx>
#include <vcl/metric.hxx>
#include <svtools/ctrltool.hxx>
#include <sfx2/docfilt.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/fcontnr.hxx>
#include <svl/stritem.hxx>
#include <SwStyleNameMapper.hxx>
#include <redline.hxx>
#include <numrule.hxx>
#include <comphelper/storagehelper.hxx>
#include <unotools/mediadescriptor.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <SwNodeNum.hxx>
#include <fmtmeta.hxx>
#include <txtfld.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::table;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
namespace SwUnoCursorHelper
{
static SwPaM* lcl_createPamCopy(const SwPaM& rPam)
{
SwPaM *const pRet = new SwPaM(*rPam.GetPoint());
::sw::DeepCopyPaM(rPam, *pRet);
return pRet;
}
void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
SwDoc & rTargetDoc,
SwPaM *& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
OUString & o_rTableName, SwUnoTableCursor const*& o_rpTableCursor,
::sw::mark::IMark const*& o_rpMark,
std::vector<SdrObject *> & o_rSdrObjects)
{
uno::Reference<drawing::XShapes> const xShapes(xIfc, UNO_QUERY);
if (xShapes.is())
{
sal_Int32 nShapes(xShapes->getCount());
for (sal_Int32 i = 0; i < nShapes; ++i)
{
uno::Reference<lang::XUnoTunnel> xShape;
xShapes->getByIndex(i) >>= xShape;
if (xShape.is())
{
SvxShape *const pSvxShape(
::sw::UnoTunnelGetImplementation<SvxShape>(xShape));
if (pSvxShape)
{
SdrObject *const pSdrObject = pSvxShape->GetSdrObject();
if (pSdrObject)
{ // hmm... needs view to verify it's in right doc...
o_rSdrObjects.push_back(pSdrObject);
}
}
}
}
return;
}
uno::Reference<lang::XUnoTunnel> const xTunnel(xIfc, UNO_QUERY);
if (!xTunnel.is()) // everything below needs tunnel
{
return;
}
SwXShape *const pShape(::sw::UnoTunnelGetImplementation<SwXShape>(xTunnel));
if (pShape)
{
uno::Reference<uno::XAggregation> const xAgg(
pShape->GetAggregationInterface());
if (xAgg.is())
{
SvxShape *const pSvxShape(
::sw::UnoTunnelGetImplementation<SvxShape>(xTunnel));
if (pSvxShape)
{
SdrObject *const pSdrObject = pSvxShape->GetSdrObject();
if (pSdrObject)
{ // hmm... needs view to verify it's in right doc...
o_rSdrObjects.push_back(pSdrObject);
}
}
}
return;
}
OTextCursorHelper *const pCursor(
::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xTunnel));
if (pCursor)
{
if (pCursor->GetDoc() == &rTargetDoc)
{
o_rpPaM = lcl_createPamCopy(*pCursor->GetPaM());
}
return;
}
SwXTextRanges* const pRanges(
::sw::UnoTunnelGetImplementation<SwXTextRanges>(xTunnel));
if (pRanges)
{
SwUnoCursor const* pUnoCursor = pRanges->GetCursor();
if (pUnoCursor && pUnoCursor->GetDoc() == &rTargetDoc)
{
o_rpPaM = lcl_createPamCopy(*pUnoCursor);
}
return;
}
// check these before Range to prevent misinterpretation of text frames
// and cells also implement XTextRange
SwXFrame *const pFrame(
::sw::UnoTunnelGetImplementation<SwXFrame>(xTunnel));
if (pFrame)
{
const SwFrameFormat *const pFrameFormat(pFrame->GetFrameFormat());
if (pFrameFormat && pFrameFormat->GetDoc() == &rTargetDoc)
{
o_rFrame = std::make_pair(pFrameFormat->GetName(), pFrame->GetFlyCntType());
}
return;
}
SwXTextTable *const pTextTable(
::sw::UnoTunnelGetImplementation<SwXTextTable>(xTunnel));
if (pTextTable)
{
SwFrameFormat *const pFrameFormat(pTextTable->GetFrameFormat());
if (pFrameFormat && pFrameFormat->GetDoc() == &rTargetDoc)
{
o_rTableName = pFrameFormat->GetName();
}
return;
}
SwXCell *const pCell(
::sw::UnoTunnelGetImplementation<SwXCell>(xTunnel));
if (pCell)
{
SwFrameFormat *const pFrameFormat(pCell->GetFrameFormat());
if (pFrameFormat && pFrameFormat->GetDoc() == &rTargetDoc)
{
SwTableBox * pBox = pCell->GetTableBox();
SwTable *const pTable = SwTable::FindTable(pFrameFormat);
// ??? what's the benefit of setting pBox in this convoluted way?
pBox = pCell->FindBox(pTable, pBox);
if (pBox)
{
SwPosition const aPos(*pBox->GetSttNd());
SwPaM aPam(aPos);
aPam.Move(fnMoveForward, fnGoNode);
o_rpPaM = lcl_createPamCopy(aPam);
}
}
return;
}
uno::Reference<text::XTextRange> const xTextRange(xTunnel, UNO_QUERY);
if (xTextRange.is())
{
SwUnoInternalPaM aPam(rTargetDoc);
if (::sw::XTextRangeToSwPaM(aPam, xTextRange))
{
o_rpPaM = lcl_createPamCopy(aPam);
}
return;
}
SwXCellRange *const pCellRange(
::sw::UnoTunnelGetImplementation<SwXCellRange>(xTunnel));
if (pCellRange)
{
SwUnoCursor const*const pUnoCursor(pCellRange->GetTableCursor());
if (pUnoCursor && pUnoCursor->GetDoc() == &rTargetDoc)
{
// probably can't copy it to o_rpPaM for this since it's
// a SwTableCursor
o_rpTableCursor = dynamic_cast<SwUnoTableCursor const*>(pUnoCursor);
}
return;
}
::sw::mark::IMark const*const pMark(
SwXBookmark::GetBookmarkInDoc(& rTargetDoc, xTunnel));
if (pMark)
{
o_rpMark = pMark;
return;
}
}
uno::Reference<text::XTextContent>
GetNestedTextContent(SwTextNode & rTextNode, sal_Int32 const nIndex,
bool const bParent)
{
// these should be unambiguous because of the dummy character
SwTextNode::GetTextAttrMode const eMode( (bParent)
? SwTextNode::PARENT : SwTextNode::EXPAND );
SwTextAttr *const pMetaTextAttr =
rTextNode.GetTextAttrAt(nIndex, RES_TXTATR_META, eMode);
SwTextAttr *const pMetaFieldTextAttr =
rTextNode.GetTextAttrAt(nIndex, RES_TXTATR_METAFIELD, eMode);
// which is innermost?
SwTextAttr *const pTextAttr = (pMetaTextAttr)
? ((pMetaFieldTextAttr)
? ((pMetaFieldTextAttr->GetStart() >
pMetaTextAttr->GetStart())
? pMetaFieldTextAttr : pMetaTextAttr)
: pMetaTextAttr)
: pMetaFieldTextAttr;
uno::Reference<XTextContent> xRet;
if (pTextAttr)
{
::sw::Meta *const pMeta(
static_cast<SwFormatMeta &>(pTextAttr->GetAttr()).GetMeta());
OSL_ASSERT(pMeta);
xRet.set(pMeta->MakeUnoObject(), uno::UNO_QUERY);
}
return xRet;
}
// Read the special properties of the cursor
bool getCursorPropertyValue(const SfxItemPropertySimpleEntry& rEntry
, SwPaM& rPam
, Any *pAny
, PropertyState& eState
, const SwTextNode* pNode )
{
PropertyState eNewState = PropertyState_DIRECT_VALUE;
bool bDone = true;
switch(rEntry.nWID)
{
case FN_UNO_PARA_CONT_PREV_SUBTREE:
if (pAny)
{
const SwTextNode * pTmpNode = pNode;
if (!pTmpNode)
pTmpNode = rPam.GetNode().GetTextNode();
bool bRet = false;
if ( pTmpNode &&
pTmpNode->GetNum() &&
pTmpNode->GetNum()->IsContinueingPreviousSubTree() )
{
bRet = true;
}
*pAny <<= bRet;
}
break;
case FN_UNO_PARA_NUM_STRING:
if (pAny)
{
const SwTextNode * pTmpNode = pNode;
if (!pTmpNode)
pTmpNode = rPam.GetNode().GetTextNode();
OUString sRet;
if ( pTmpNode && pTmpNode->GetNum() )
{
sRet = pTmpNode->GetNumString();
}
*pAny <<= sRet;
}
break;
case RES_PARATR_OUTLINELEVEL:
if (pAny)
{
const SwTextNode * pTmpNode = pNode;
if (!pTmpNode)
pTmpNode = rPam.GetNode().GetTextNode();
sal_Int16 nRet = -1;
if ( pTmpNode )
nRet = sal::static_int_cast< sal_Int16 >( pTmpNode->GetAttrOutlineLevel() );
*pAny <<= nRet;
}
break;
case FN_UNO_PARA_CONDITIONAL_STYLE_NAME:
case FN_UNO_PARA_STYLE :
{
SwFormatColl* pFormat = nullptr;
if(pNode)
pFormat = FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID
? pNode->GetFormatColl() : &pNode->GetAnyFormatColl();
else
{
pFormat = SwUnoCursorHelper::GetCurTextFormatColl(rPam,
FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID);
}
if(pFormat)
{
if( pAny )
{
OUString sVal;
SwStyleNameMapper::FillProgName(pFormat->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
*pAny <<= sVal;
}
}
else
eNewState = PropertyState_AMBIGUOUS_VALUE;
}
break;
case FN_UNO_PAGE_STYLE :
{
OUString sVal;
GetCurPageStyle(rPam, sVal);
if( pAny )
*pAny <<= sVal;
if(sVal.isEmpty())
eNewState = PropertyState_AMBIGUOUS_VALUE;
}
break;
case FN_UNO_NUM_START_VALUE :
if( pAny )
{
sal_Int16 nValue = IsNodeNumStart(rPam, eNewState);
*pAny <<= nValue;
}
break;
case FN_UNO_NUM_LEVEL :
case FN_UNO_IS_NUMBER :
// #i91601#
case FN_UNO_LIST_ID:
case FN_NUMBER_NEWSTART:
{
// a multi selection is not considered
const SwTextNode* pTextNd = rPam.GetNode().GetTextNode();
if ( pTextNd && pTextNd->IsInList() )
{
if( pAny )
{
if(rEntry.nWID == FN_UNO_NUM_LEVEL)
*pAny <<= (sal_Int16)(pTextNd->GetActualListLevel());
else if(rEntry.nWID == FN_UNO_IS_NUMBER)
{
*pAny <<= pTextNd->IsCountedInList();
}
// #i91601#
else if ( rEntry.nWID == FN_UNO_LIST_ID )
{
*pAny <<= pTextNd->GetListId();
}
else
{
*pAny <<= pTextNd->IsListRestart();
}
}
}
else
{
eNewState = PropertyState_DEFAULT_VALUE;
if( pAny )
{
// #i30838# set default values for default properties
if(rEntry.nWID == FN_UNO_NUM_LEVEL)
*pAny <<= static_cast<sal_Int16>( 0 );
else if(rEntry.nWID == FN_UNO_IS_NUMBER)
*pAny <<= false;
// #i91601#
else if ( rEntry.nWID == FN_UNO_LIST_ID )
{
*pAny <<= OUString();
}
else
*pAny <<= false;
}
}
//PROPERTY_MAYBEVOID!
}
break;
case FN_UNO_NUM_RULES :
if( pAny )
getNumberingProperty(rPam, eNewState, pAny);
else
{
if( !SwDoc::GetNumRuleAtPos( *rPam.GetPoint() ) )
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_DOCUMENT_INDEX_MARK:
{
::std::vector<SwTextAttr *> marks;
if (rPam.GetNode().IsTextNode())
{
marks = rPam.GetNode().GetTextNode()->GetTextAttrsAt(
rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK);
}
if (marks.size())
{
if( pAny )
{ // hmm... can only return 1 here
SwTOXMark & rMark =
static_cast<SwTOXMark &>((*marks.begin())->GetAttr());
const uno::Reference< text::XDocumentIndexMark > xRef =
SwXDocumentIndexMark::CreateXDocumentIndexMark(
*rPam.GetDoc(), &rMark);
(*pAny) <<= xRef;
}
}
else
//also here - indistinguishable
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_DOCUMENT_INDEX:
{
SwTOXBase* pBase = SwDoc::GetCurTOX(
*rPam.Start() );
if( pBase )
{
if( pAny )
{
const uno::Reference< text::XDocumentIndex > xRef =
SwXDocumentIndex::CreateXDocumentIndex(*rPam.GetDoc(),
static_cast<SwTOXBaseSection *>(pBase));
(*pAny) <<= xRef;
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_TEXT_FIELD:
{
const SwPosition *pPos = rPam.Start();
const SwTextNode *pTextNd =
rPam.GetDoc()->GetNodes()[pPos->nNode.GetIndex()]->GetTextNode();
const SwTextAttr* pTextAttr = (pTextNd)
? pTextNd->GetFieldTextAttrAt( pPos->nContent.GetIndex(), true )
: nullptr;
if ( pTextAttr != nullptr )
{
if( pAny )
{
uno::Reference<text::XTextField> const xField(
SwXTextField::CreateXTextField(rPam.GetDoc(),
&pTextAttr->GetFormatField()));
*pAny <<= xField;
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_TEXT_TABLE:
case FN_UNO_CELL:
{
SwStartNode* pSttNode = rPam.GetNode().StartOfSectionNode();
SwStartNodeType eType = pSttNode->GetStartNodeType();
if(SwTableBoxStartNode == eType)
{
if( pAny )
{
const SwTableNode* pTableNode = pSttNode->FindTableNode();
SwFrameFormat* pTableFormat = static_cast<SwFrameFormat*>(pTableNode->GetTable().GetFrameFormat());
//SwTable& rTable = static_cast<SwTableNode*>(pSttNode)->GetTable();
if(FN_UNO_TEXT_TABLE == rEntry.nWID)
{
uno::Reference< XTextTable > xTable = SwXTextTables::GetObject(*pTableFormat);
pAny->setValue(&xTable, cppu::UnoType<XTextTable>::get());
}
else
{
SwTableBox* pBox = pSttNode->GetTableBox();
uno::Reference< XCell > xCell = SwXCell::CreateXCell(pTableFormat, pBox);
pAny->setValue(&xCell, cppu::UnoType<XCell>::get());
}
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_TEXT_FRAME:
{
SwStartNode* pSttNode = rPam.GetNode().StartOfSectionNode();
SwStartNodeType eType = pSttNode->GetStartNodeType();
SwFrameFormat* pFormat;
if(eType == SwFlyStartNode && nullptr != (pFormat = pSttNode->GetFlyFormat()))
{
if( pAny )
{
uno::Reference<XTextFrame> const xFrame(
SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat));
(*pAny) <<= xFrame;
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_TEXT_SECTION:
{
SwSection* pSect = SwDoc::GetCurrSection(*rPam.GetPoint());
if(pSect)
{
if( pAny )
{
uno::Reference< XTextSection > xSect = SwXTextSections::GetObject( *pSect->GetFormat() );
pAny->setValue(&xSect, cppu::UnoType<XTextSection>::get());
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_ENDNOTE:
case FN_UNO_FOOTNOTE:
{
SwTextAttr *const pTextAttr = rPam.GetNode().IsTextNode() ?
rPam.GetNode().GetTextNode()->GetTextAttrForCharAt(
rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN) : nullptr;
if(pTextAttr)
{
const SwFormatFootnote& rFootnote = pTextAttr->GetFootnote();
if(rFootnote.IsEndNote() == (FN_UNO_ENDNOTE == rEntry.nWID))
{
if( pAny )
{
const uno::Reference< text::XFootnote > xFootnote =
SwXFootnote::CreateXFootnote(*rPam.GetDoc(),
&const_cast<SwFormatFootnote&>(rFootnote));
*pAny <<= xFootnote;
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_REFERENCE_MARK:
{
::std::vector<SwTextAttr *> marks;
if (rPam.GetNode().IsTextNode())
{
marks = (
rPam.GetNode().GetTextNode()->GetTextAttrsAt(
rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK));
}
if (marks.size())
{
if( pAny )
{ // hmm... can only return 1 here
const SwFormatRefMark& rRef = (*marks.begin())->GetRefMark();
uno::Reference<XTextContent> const xRef =
SwXReferenceMark::CreateXReferenceMark(*rPam.GetDoc(),
const_cast<SwFormatRefMark*>(&rRef));
pAny->setValue(&xRef, cppu::UnoType<XTextContent>::get());
}
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case FN_UNO_NESTED_TEXT_CONTENT:
{
uno::Reference<XTextContent> const xRet(rPam.GetNode().IsTextNode()
? GetNestedTextContent(*rPam.GetNode().GetTextNode(),
rPam.GetPoint()->nContent.GetIndex(), false)
: nullptr);
if (xRet.is())
{
if (pAny)
{
(*pAny) <<= xRet;
}
}
else
{
eNewState = PropertyState_DEFAULT_VALUE;
}
}
break;
case FN_UNO_CHARFMT_SEQUENCE:
{
SwTextNode *const pTextNode = rPam.GetNode().GetTextNode();
if (&rPam.GetNode() == &rPam.GetNode(false)
&& pTextNode && pTextNode->GetpSwpHints())
{
sal_Int32 nPaMStart = rPam.GetPoint()->nContent.GetIndex();
sal_Int32 nPaMEnd = rPam.GetMark() ? rPam.GetMark()->nContent.GetIndex() : nPaMStart;
if(nPaMStart > nPaMEnd)
{
std::swap(nPaMStart, nPaMEnd);
}
Sequence< OUString> aCharStyles;
SwpHints* pHints = pTextNode->GetpSwpHints();
for( size_t nAttr = 0; nAttr < pHints->Count(); ++nAttr )
{
SwTextAttr* pAttr = pHints->Get( nAttr );
if(pAttr->Which() != RES_TXTATR_CHARFMT)
continue;
const sal_Int32 nAttrStart = pAttr->GetStart();
const sal_Int32 nAttrEnd = *pAttr->GetEnd();
//check if the attribute touches the selection
if( ( nAttrEnd > nPaMStart && nAttrStart < nPaMEnd ) ||
( !nAttrStart && !nAttrEnd && !nPaMStart && !nPaMEnd ) )
{
//check for overlapping
if(nAttrStart > nPaMStart ||
nAttrEnd < nPaMEnd)
{
aCharStyles.realloc(0);
break;
}
else
{
//now the attribute should start before or at the selection
//and it should end at the end of the selection or behind
OSL_ENSURE(nAttrStart <= nPaMStart && nAttrEnd >=nPaMEnd,
"attribute overlaps or is outside");
//now the name of the style has to be added to the sequence
aCharStyles.realloc(aCharStyles.getLength() + 1);
OSL_ENSURE(pAttr->GetCharFormat().GetCharFormat(), "no character format set");
aCharStyles.getArray()[aCharStyles.getLength() - 1] =
SwStyleNameMapper::GetProgName(
pAttr->GetCharFormat().GetCharFormat()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
}
}
}
eNewState =
aCharStyles.getLength() ?
PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
if(pAny)
(*pAny) <<= aCharStyles;
}
else
eNewState = PropertyState_DEFAULT_VALUE;
}
break;
case RES_TXTATR_CHARFMT:
// no break here!
default: bDone = false;
}
if( bDone )
eState = eNewState;
return bDone;
};
sal_Int16 IsNodeNumStart(SwPaM& rPam, PropertyState& eState)
{
const SwTextNode* pTextNd = rPam.GetNode().GetTextNode();
// correction: check, if restart value is set at the text node and use
// new method <SwTextNode::GetAttrListRestartValue()> to retrieve the value
if ( pTextNd && pTextNd->GetNumRule() && pTextNd->IsListRestart() &&
pTextNd->HasAttrListRestartValue() )
{
eState = PropertyState_DIRECT_VALUE;
sal_Int16 nTmp = sal::static_int_cast< sal_Int16 >(pTextNd->GetAttrListRestartValue());
return nTmp;
}
eState = PropertyState_DEFAULT_VALUE;
return -1;
}
void setNumberingProperty(const Any& rValue, SwPaM& rPam)
{
uno::Reference<XIndexReplace> xIndexReplace;
if(rValue >>= xIndexReplace)
{
SwXNumberingRules* pSwNum = nullptr;
uno::Reference<XUnoTunnel> xNumTunnel(xIndexReplace, UNO_QUERY);
if(xNumTunnel.is())
{
pSwNum = reinterpret_cast< SwXNumberingRules * >(
sal::static_int_cast< sal_IntPtr >( xNumTunnel->getSomething( SwXNumberingRules::getUnoTunnelId() )));
}
if(pSwNum)
{
SwDoc* pDoc = rPam.GetDoc();
if(pSwNum->GetNumRule())
{
SwNumRule aRule(*pSwNum->GetNumRule());
const OUString* pNewCharStyles = pSwNum->GetNewCharStyleNames();
const OUString* pBulletFontNames = pSwNum->GetBulletFontNames();
for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
{
SwNumFormat aFormat(aRule.Get( i ));
if (!pNewCharStyles[i].isEmpty() &&
!SwXNumberingRules::isInvalidStyle(pNewCharStyles[i]) &&
(!aFormat.GetCharFormat() || pNewCharStyles[i] != aFormat.GetCharFormat()->GetName()))
{
if (pNewCharStyles[i].isEmpty())
{
// FIXME
// Is something missing/wrong here?
// if condition is always false due to outer check!
aFormat.SetCharFormat(nullptr);
}
else
{
// get CharStyle and set the rule
const size_t nChCount = pDoc->GetCharFormats()->size();
SwCharFormat* pCharFormat = nullptr;
for(size_t nCharFormat = 0; nCharFormat < nChCount; ++nCharFormat)
{
SwCharFormat& rChFormat = *((*(pDoc->GetCharFormats()))[nCharFormat]);
if(rChFormat.GetName() == pNewCharStyles[i])
{
pCharFormat = &rChFormat;
break;
}
}
if(!pCharFormat)
{
SfxStyleSheetBasePool* pPool = pDoc->GetDocShell()->GetStyleSheetPool();
SfxStyleSheetBase* pBase;
pBase = pPool->Find(pNewCharStyles[i], SfxStyleFamily::Char);
// shall it really be created?
if(!pBase)
pBase = &pPool->Make(pNewCharStyles[i], SfxStyleFamily::Page);
pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
}
if(pCharFormat)
aFormat.SetCharFormat(pCharFormat);
}
}
//Now again for fonts
if(
!pBulletFontNames[i].isEmpty() &&
!SwXNumberingRules::isInvalidStyle(pBulletFontNames[i]) &&
(!aFormat.GetBulletFont() || aFormat.GetBulletFont()->GetFamilyName() != pBulletFontNames[i])
)
{
const SvxFontListItem* pFontListItem =
static_cast<const SvxFontListItem* >(pDoc->GetDocShell()
->GetItem( SID_ATTR_CHAR_FONTLIST ));
const FontList* pList = pFontListItem->GetFontList();
FontMetric aFontMetric = pList->Get(
pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE);
vcl::Font aFont(aFontMetric);
aFormat.SetBulletFont(&aFont);
}
aRule.Set( i, aFormat );
}
UnoActionContext aAction(pDoc);
if( rPam.GetNext() != &rPam ) // Multiple selection?
{
pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, nullptr );
SwPamRanges aRangeArr( rPam );
SwPaM aPam( *rPam.GetPoint() );
for ( size_t n = 0; n < aRangeArr.Count(); ++n )
{
// no start of a new list
pDoc->SetNumRule( aRangeArr.SetPam( n, aPam ), aRule, false );
}
pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, nullptr );
}
else
{
// no start of a new list
pDoc->SetNumRule( rPam, aRule, false );
}
}
else if(!pSwNum->GetCreatedNumRuleName().isEmpty())
{
UnoActionContext aAction( pDoc );
SwNumRule* pRule = pDoc->FindNumRulePtr( pSwNum->GetCreatedNumRuleName() );
if ( !pRule )
throw RuntimeException();
// no start of a new list
pDoc->SetNumRule( rPam, *pRule, false );
}
else
{
// #i103817#
// outline numbering
UnoActionContext aAction(pDoc);
SwNumRule* pRule = pDoc->GetOutlineNumRule();
if(!pRule)
throw RuntimeException();
pDoc->SetNumRule( rPam, *pRule, false );
}
}
}
else if ( rValue.getValueType() == cppu::UnoType<void>::get() )
{
rPam.GetDoc()->DelNumRules(rPam);
}
}
void getNumberingProperty(SwPaM& rPam, PropertyState& eState, Any * pAny )
{
const SwNumRule* pNumRule = SwDoc::GetNumRuleAtPos( *rPam.GetPoint() );
if(pNumRule)
{
uno::Reference< XIndexReplace > xNum = new SwXNumberingRules(*pNumRule);
if ( pAny )
pAny->setValue(&xNum, cppu::UnoType<XIndexReplace>::get());
eState = PropertyState_DIRECT_VALUE;
}
else
eState = PropertyState_DEFAULT_VALUE;
}
void GetCurPageStyle(SwPaM& rPaM, OUString &rString)
{
if (!rPaM.GetContentNode())
return; // TODO: is there an easy way to get it for tables/sections?
SwContentFrame* pFrame = rPaM.GetContentNode()->getLayoutFrame(rPaM.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout());
if(pFrame)
{
const SwPageFrame* pPage = pFrame->FindPageFrame();
if(pPage)
{
SwStyleNameMapper::FillProgName(pPage->GetPageDesc()->GetName(),
rString, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true);
}
}
}
// reset special properties of the cursor
void resetCursorPropertyValue(const SfxItemPropertySimpleEntry& rEntry, SwPaM& rPam)
{
SwDoc* pDoc = rPam.GetDoc();
switch(rEntry.nWID)
{
case FN_UNO_PARA_STYLE :
break;
case FN_UNO_PAGE_STYLE :
break;
case FN_UNO_NUM_START_VALUE :
{
UnoActionContext aAction(pDoc);
if( rPam.GetNext() != &rPam ) // Multiple selection?
{
pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, nullptr );
SwPamRanges aRangeArr( rPam );
SwPaM aPam( *rPam.GetPoint() );
for( size_t n = 0; n < aRangeArr.Count(); ++n )
pDoc->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), 1 );
pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, nullptr );
}
else
pDoc->SetNodeNumStart( *rPam.GetPoint(), 0 );
}
break;
case FN_UNO_NUM_LEVEL :
break;
case FN_UNO_NUM_RULES:
break;
case FN_UNO_CHARFMT_SEQUENCE:
{
std::set<sal_uInt16> aWhichIds;
aWhichIds.insert( RES_TXTATR_CHARFMT);
pDoc->ResetAttrs(rPam, true, aWhichIds);
}
break;
}
}
void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
const uno::Sequence< beans::PropertyValue >& rOptions)
throw (lang::IllegalArgumentException, io::IOException,
uno::RuntimeException, std::exception)
{
std::unique_ptr<SfxMedium> pMed;
SwDoc* pDoc = pUnoCursor->GetDoc();
SwDocShell* pDocSh = pDoc->GetDocShell();
utl::MediaDescriptor aMediaDescriptor( rOptions );
OUString sFileName = rURL;
OUString sFilterName, sFilterOptions, sPassword, sBaseURL;
uno::Reference < io::XStream > xStream;
uno::Reference < io::XInputStream > xInputStream;
if( sFileName.isEmpty() )
aMediaDescriptor[utl::MediaDescriptor::PROP_URL()] >>= sFileName;
if( sFileName.isEmpty() )
aMediaDescriptor[utl::MediaDescriptor::PROP_FILENAME()] >>= sFileName;
aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
aMediaDescriptor[utl::MediaDescriptor::PROP_STREAM()] >>= xStream;
aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
aMediaDescriptor[utl::MediaDescriptor::PROP_FILTERNAME()] >>= sFilterName;
aMediaDescriptor[utl::MediaDescriptor::PROP_FILTEROPTIONS()] >>= sFilterOptions;
aMediaDescriptor[utl::MediaDescriptor::PROP_PASSWORD()] >>= sPassword;
aMediaDescriptor[utl::MediaDescriptor::PROP_DOCUMENTBASEURL() ] >>= sBaseURL;
if ( !xInputStream.is() && xStream.is() )
xInputStream = xStream->getInputStream();
if(!pDocSh || (sFileName.isEmpty() && !xInputStream.is()))
return;
SfxObjectFactory& rFact = pDocSh->GetFactory();
std::shared_ptr<const SfxFilter> pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( sFilterName );
uno::Reference < embed::XStorage > xReadStorage;
if( xInputStream.is() )
{
uno::Sequence< uno::Any > aArgs( 2 );
aArgs[0] <<= xInputStream;
aArgs[1] <<= embed::ElementModes::READ;
try
{
xReadStorage.set( ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
}
catch( const io::IOException& rEx)
{
(void)rEx;
}
}
if ( !pFilter )
{
if( xInputStream.is() && !xReadStorage.is())
{
pMed.reset(new SfxMedium);
pMed->setStreamToLoadFrom(xInputStream, true );
}
else
pMed.reset(xReadStorage.is() ?
new SfxMedium(xReadStorage, sBaseURL, nullptr ) :
new SfxMedium(sFileName, StreamMode::READ, nullptr, nullptr ));
if( !sBaseURL.isEmpty() )
pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() );
ErrCode nErr = aMatcher.GuessFilter(*pMed, pFilter, SfxFilterFlags::NONE);
if ( nErr || !pFilter)
return;
pMed->SetFilter( pFilter );
}
else
{
if( xInputStream.is() && !xReadStorage.is())
{
pMed.reset(new SfxMedium);
pMed->setStreamToLoadFrom(xInputStream, true );
pMed->SetFilter( pFilter );
}
else
{
if( xReadStorage.is() )
{
pMed.reset(new SfxMedium(xReadStorage, sBaseURL, nullptr ));
pMed->SetFilter( pFilter );
}
else
pMed.reset(new SfxMedium(sFileName, StreamMode::READ, pFilter, nullptr));
}
if(!sFilterOptions.isEmpty())
pMed->GetItemSet()->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, sFilterOptions ) );
if(!sBaseURL.isEmpty())
pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
}
// this sourcecode is not responsible for the lifetime of the shell, SfxObjectShellLock should not be used
SfxObjectShellRef aRef( pDocSh );
pMed->Download(); // if necessary: start the download
if( aRef.Is() && 1 < aRef->GetRefCount() ) // Ref still valid?
{
SwReader* pRdr;
SfxItemSet* pSet = pMed->GetItemSet();
pSet->Put(SfxBoolItem(FN_API_CALL, true));
if(!sPassword.isEmpty())
pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
Reader *pRead = pDocSh->StartConvertFrom( *pMed, &pRdr, nullptr, pUnoCursor);
if( pRead )
{
UnoActionContext aContext(pDoc);
if(pUnoCursor->HasMark())
pDoc->getIDocumentContentOperations().DeleteAndJoin(*pUnoCursor);
SwNodeIndex aSave( pUnoCursor->GetPoint()->nNode, -1 );
sal_Int32 nContent = pUnoCursor->GetPoint()->nContent.GetIndex();
sal_uInt32 nErrno = pRdr->Read( *pRead ); // and paste the document
if(!nErrno)
{
++aSave;
pUnoCursor->SetMark();
pUnoCursor->GetMark()->nNode = aSave;
SwContentNode* pCntNode = aSave.GetNode().GetContentNode();
if( !pCntNode )
nContent = 0;
pUnoCursor->GetMark()->nContent.Assign( pCntNode, nContent );
}
delete pRdr;
}
}
}
// insert text and scan for CR characters in order to insert
// paragraph breaks at those positions by calling SplitNode
bool DocInsertStringSplitCR(
SwDoc &rDoc,
const SwPaM &rNewCursor,
const OUString &rText,
const bool bForceExpandHints )
{
bool bOK = true;
const SwInsertFlags nInsertFlags =
bForceExpandHints
? ( SwInsertFlags::FORCEHINTEXPAND | SwInsertFlags::EMPTYEXPAND)
: SwInsertFlags::EMPTYEXPAND;
// grouping done in InsertString is intended for typing, not API calls
::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
SwTextNode* const pTextNd =
rNewCursor.GetPoint()->nNode.GetNode().GetTextNode();
if (!pTextNd)
{
SAL_INFO("sw.uno", "DocInsertStringSplitCR: need a text node");
return false;
}
OUString aText;
sal_Int32 nStartIdx = 0;
const sal_Int32 nMaxLength = COMPLETE_STRING - pTextNd->GetText().getLength();
sal_Int32 nIdx = rText.indexOf( '\r', nStartIdx );
if( ( nIdx == -1 && nMaxLength < rText.getLength() ) ||
( nIdx != -1 && nMaxLength < nIdx ) )
{
nIdx = nMaxLength;
}
while (nIdx != -1 )
{
OSL_ENSURE( nIdx - nStartIdx >= 0, "index negative!" );
aText = rText.copy( nStartIdx, nIdx - nStartIdx );
if (!aText.isEmpty() &&
!rDoc.getIDocumentContentOperations().InsertString( rNewCursor, aText, nInsertFlags ))
{
OSL_FAIL( "Doc->Insert(Str) failed." );
bOK = false;
}
if (!rDoc.getIDocumentContentOperations().SplitNode( *rNewCursor.GetPoint(), false ) )
{
OSL_FAIL( "SplitNode failed" );
bOK = false;
}
nStartIdx = nIdx + 1;
nIdx = rText.indexOf( '\r', nStartIdx );
}
aText = rText.copy( nStartIdx );
if (!aText.isEmpty() &&
!rDoc.getIDocumentContentOperations().InsertString( rNewCursor, aText, nInsertFlags ))
{
OSL_FAIL( "Doc->Insert(Str) failed." );
bOK = false;
}
return bOK;
}
void makeRedline( SwPaM& rPaM,
const OUString& rRedlineType,
const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
IDocumentRedlineAccess* pRedlineAccess = &rPaM.GetDoc()->getIDocumentRedlineAccess();
RedlineType_t eType;
if ( rRedlineType == "Insert" )
eType = nsRedlineType_t::REDLINE_INSERT;
else if ( rRedlineType == "Delete" )
eType = nsRedlineType_t::REDLINE_DELETE;
else if ( rRedlineType == "Format" )
eType = nsRedlineType_t::REDLINE_FORMAT;
else if ( rRedlineType == "TextTable" )
eType = nsRedlineType_t::REDLINE_TABLE;
else if ( rRedlineType == "ParagraphFormat" )
eType = nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT;
else
throw lang::IllegalArgumentException();
//todo: what about REDLINE_FMTCOLL?
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
{
aRedlineData.SetTimeStamp(
DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
}
SwRedlineExtraData_FormattingChanges* pRedlineExtraData = nullptr;
// Read the 'Redline Revert Properties' from the parameters
uno::Sequence< beans::PropertyValue > aRevertProperties;
uno::Any aRevertPropertiesValue;
aRevertPropertiesValue = aPropMap.getUnpackedValueOrDefault("RedlineRevertProperties", aRevertPropertiesValue);
// Check if the value exists
if ( aRevertPropertiesValue >>= aRevertProperties )
{
int nMap = 0;
// Make sure that paragraph format gets its own map, otherwise e.g. fill attributes are not preserved.
if (eType == nsRedlineType_t::REDLINE_PARAGRAPH_FORMAT)
nMap = PROPERTY_MAP_PARAGRAPH;
else
nMap = PROPERTY_MAP_TEXTPORTION_EXTENSIONS;
SfxItemPropertySet const& rPropSet = (*aSwMapProvider.GetPropertySet(nMap));
// Check if there are any properties
if (aRevertProperties.getLength())
{
SwDoc *const pDoc = rPaM.GetDoc();
OUString aUnknownExMsg, aPropertyVetoExMsg;
// Build set of attributes we want to fetch
std::vector<sal_uInt16> aWhichPairs;
std::vector<SfxItemPropertySimpleEntry const*> aEntries;
aEntries.reserve(aRevertProperties.getLength());
for (sal_Int32 i = 0; i < aRevertProperties.getLength(); ++i)
{
const OUString &rPropertyName = aRevertProperties[i].Name;
SfxItemPropertySimpleEntry const* pEntry = rPropSet.getPropertyMap().getByName(rPropertyName);
// Queue up any exceptions until the end ...
if (!pEntry)
{
aUnknownExMsg += "Unknown property: '" + rPropertyName + "' ";
break;
}
else if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
{
aPropertyVetoExMsg += "Property is read-only: '" + rPropertyName + "' ";
break;
}
else
{
// FIXME: we should have some nice way of merging ranges surely ?
aWhichPairs.push_back(pEntry->nWID);
aWhichPairs.push_back(pEntry->nWID);
}
aEntries.push_back(pEntry);
}
if (!aWhichPairs.empty())
{
aWhichPairs.push_back(0); // terminate
SfxItemSet aItemSet(pDoc->GetAttrPool(), &aWhichPairs[0]);
for (size_t i = 0; i < aEntries.size(); ++i)
{
SfxItemPropertySimpleEntry const*const pEntry = aEntries[i];
const uno::Any &rValue = aRevertProperties[i].Value;
rPropSet.setPropertyValue(*pEntry, rValue, aItemSet);
}
pRedlineExtraData = new SwRedlineExtraData_FormattingChanges( &aItemSet );
}
}
}
SwRangeRedline* pRedline = new SwRangeRedline( aRedlineData, rPaM );
RedlineMode_t nPrevMode = pRedlineAccess->GetRedlineMode( );
pRedline->SetExtraData( pRedlineExtraData );
pRedlineAccess->SetRedlineMode_intern(nsRedlineMode_t::REDLINE_ON);
bool bRet = pRedlineAccess->AppendRedline( pRedline, false );
pRedlineAccess->SetRedlineMode_intern( nPrevMode );
if( !bRet )
throw lang::IllegalArgumentException();
}
void makeTableRowRedline( SwTableLine& rTableLine,
const OUString& rRedlineType,
const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
IDocumentRedlineAccess* pRedlineAccess = &rTableLine.GetFrameFormat()->GetDoc()->getIDocumentRedlineAccess();
RedlineType_t eType;
if ( rRedlineType == "TableRowInsert" )
{
eType = nsRedlineType_t::REDLINE_TABLE_ROW_INSERT;
}
else if ( rRedlineType == "TableRowDelete" )
{
eType = nsRedlineType_t::REDLINE_TABLE_ROW_DELETE;
}
else
{
throw lang::IllegalArgumentException();
}
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
{
aRedlineData.SetTimeStamp(
DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
}
SwTableRowRedline* pRedline = new SwTableRowRedline( aRedlineData, rTableLine );
RedlineMode_t nPrevMode = pRedlineAccess->GetRedlineMode( );
pRedline->SetExtraData( nullptr );
pRedlineAccess->SetRedlineMode_intern(nsRedlineMode_t::REDLINE_ON);
bool bRet = pRedlineAccess->AppendTableRowRedline( pRedline, false );
pRedlineAccess->SetRedlineMode_intern( nPrevMode );
if( !bRet )
throw lang::IllegalArgumentException();
}
void makeTableCellRedline( SwTableBox& rTableBox,
const OUString& rRedlineType,
const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
IDocumentRedlineAccess* pRedlineAccess = &rTableBox.GetFrameFormat()->GetDoc()->getIDocumentRedlineAccess();
RedlineType_t eType;
if ( rRedlineType == "TableCellInsert" )
{
eType = nsRedlineType_t::REDLINE_TABLE_CELL_INSERT;
}
else if ( rRedlineType == "TableCellDelete" )
{
eType = nsRedlineType_t::REDLINE_TABLE_CELL_DELETE;
}
else
{
throw lang::IllegalArgumentException();
}
comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
uno::Any aAuthorValue;
aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue);
sal_uInt16 nAuthor = 0;
OUString sAuthor;
if( aAuthorValue >>= sAuthor )
nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
OUString sComment;
uno::Any aCommentValue;
aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue);
SwRedlineData aRedlineData( eType, nAuthor );
if( aCommentValue >>= sComment )
aRedlineData.SetComment( sComment );
::util::DateTime aStamp;
uno::Any aDateTimeValue;
aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue);
if( aDateTimeValue >>= aStamp )
{
aRedlineData.SetTimeStamp(
DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
}
SwTableCellRedline* pRedline = new SwTableCellRedline( aRedlineData, rTableBox );
RedlineMode_t nPrevMode = pRedlineAccess->GetRedlineMode( );
pRedline->SetExtraData( nullptr );
pRedlineAccess->SetRedlineMode_intern(nsRedlineMode_t::REDLINE_ON);
bool bRet = pRedlineAccess->AppendTableCellRedline( pRedline, false );
pRedlineAccess->SetRedlineMode_intern( nPrevMode );
if( !bRet )
throw lang::IllegalArgumentException();
}
void SwAnyMapHelper::SetValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& rAny )
{
sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
auto aIt = m_Map.find( nKey );
if (aIt != m_Map.end())
aIt->second = rAny;
else
m_Map.insert(std::make_pair(nKey, rAny));
}
bool SwAnyMapHelper::FillValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& pAny )
{
bool bRet = false;
sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
auto aIt = m_Map.find( nKey );
if (aIt != m_Map.end())
{
pAny = & aIt->second;
bRet = true;
}
return bRet;
}
}//namespace SwUnoCursorHelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|