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
|
/* -*- 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 <svl/smplhint.hxx>
#include <vcl/svapp.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editobj.hxx>
#include <editeng/flditem.hxx>
#include <comphelper/servicehelper.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
#include <com/sun/star/text/FilenameDisplayFormat.hpp>
#include "fielduno.hxx"
#include "textuno.hxx"
#include "miscuno.hxx"
#include "docsh.hxx"
#include "hints.hxx"
#include "editsrc.hxx"
#include "cellsuno.hxx"
#include "servuno.hxx" // fuer IDs
#include "unonames.hxx"
#include "editutil.hxx"
using namespace com::sun::star;
//------------------------------------------------------------------------
// alles ohne Which-ID, Map nur fuer PropertySetInfo
const SfxItemPropertySet* lcl_GetURLPropertySet()
{
static SfxItemPropertyMapEntry aURLPropertyMap_Impl[] =
{
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_REPR), 0, &getCppuType((rtl::OUString*)0), 0, 0},
{MAP_CHAR_LEN(SC_UNONAME_TARGET), 0, &getCppuType((rtl::OUString*)0), 0, 0},
{MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_URL), 0, &getCppuType((rtl::OUString*)0), 0, 0},
{0,0,0,0,0,0}
};
static SfxItemPropertySet aURLPropertySet_Impl( aURLPropertyMap_Impl );
return &aURLPropertySet_Impl;
}
const SfxItemPropertySet* lcl_GetHeaderFieldPropertySet()
{
static SfxItemPropertyMapEntry aHeaderFieldPropertyMap_Impl[] =
{
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
{0,0,0,0,0,0}
};
static SfxItemPropertySet aHeaderFieldPropertySet_Impl( aHeaderFieldPropertyMap_Impl );
return &aHeaderFieldPropertySet_Impl;
}
const SfxItemPropertySet* lcl_GetFileFieldPropertySet()
{
static SfxItemPropertyMapEntry aFileFieldPropertyMap_Impl[] =
{
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNONAME_FILEFORM), 0, &getCppuType((sal_Int16*)0), 0, 0 },
{MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
{0,0,0,0,0,0}
};
static SfxItemPropertySet aFileFieldPropertySet_Impl( aFileFieldPropertyMap_Impl );
return &aFileFieldPropertySet_Impl;
}
//------------------------------------------------------------------------
#define SCTEXTFIELD_SERVICE "com.sun.star.text.TextField"
#define SCTEXTCONTENT_SERVICE "com.sun.star.text.TextContent"
SC_SIMPLE_SERVICE_INFO( ScCellFieldsObj, "ScCellFieldsObj", "com.sun.star.text.TextFields" )
SC_SIMPLE_SERVICE_INFO( ScHeaderFieldsObj, "ScHeaderFieldsObj", "com.sun.star.text.TextFields" )
//------------------------------------------------------------------------
// ScUnoEditEngine nur um aus einer EditEngine die Felder herauszubekommen...
enum ScUnoCollectMode
{
SC_UNO_COLLECT_NONE,
SC_UNO_COLLECT_COUNT,
SC_UNO_COLLECT_FINDINDEX,
SC_UNO_COLLECT_FINDPOS
};
class ScUnoEditEngine : public ScEditEngineDefaulter
{
ScUnoCollectMode eMode;
sal_uInt16 nFieldCount;
TypeId aFieldType;
SvxFieldData* pFound; // lokale Kopie
sal_uInt16 nFieldPar;
xub_StrLen nFieldPos;
sal_uInt16 nFieldIndex;
public:
ScUnoEditEngine(ScEditEngineDefaulter* pSource);
~ScUnoEditEngine();
//! nPos should be xub_StrLen
virtual String CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos,
Color*& rTxtColor, Color*& rFldColor );
sal_uInt16 CountFields(TypeId aType);
SvxFieldData* FindByIndex(sal_uInt16 nIndex, TypeId aType);
SvxFieldData* FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType);
sal_uInt16 GetFieldPar() const { return nFieldPar; }
xub_StrLen GetFieldPos() const { return nFieldPos; }
};
ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) :
ScEditEngineDefaulter( *pSource ),
eMode( SC_UNO_COLLECT_NONE ),
nFieldCount( 0 ),
aFieldType( NULL ),
pFound( NULL )
{
if (pSource)
{
EditTextObject* pData = pSource->CreateTextObject();
SetText( *pData );
delete pData;
}
}
ScUnoEditEngine::~ScUnoEditEngine()
{
delete pFound;
}
String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
sal_uInt16 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor )
{
String aRet(EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor ));
if (eMode != SC_UNO_COLLECT_NONE)
{
const SvxFieldData* pFieldData = rField.GetField();
if ( pFieldData )
{
if ( !aFieldType || pFieldData->Type() == aFieldType )
{
if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex )
{
pFound = pFieldData->Clone();
nFieldPar = nPara;
nFieldPos = nPos;
}
if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound &&
nPara == nFieldPar && nPos == nFieldPos )
{
pFound = pFieldData->Clone();
nFieldIndex = nFieldCount;
}
++nFieldCount;
}
}
}
return aRet;
}
sal_uInt16 ScUnoEditEngine::CountFields(TypeId aType)
{
eMode = SC_UNO_COLLECT_COUNT;
aFieldType = aType;
nFieldCount = 0;
UpdateFields();
aFieldType = NULL;
eMode = SC_UNO_COLLECT_NONE;
return nFieldCount;
}
SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex, TypeId aType)
{
eMode = SC_UNO_COLLECT_FINDINDEX;
nFieldIndex = nIndex;
aFieldType = aType;
nFieldCount = 0;
UpdateFields();
aFieldType = NULL;
eMode = SC_UNO_COLLECT_NONE;
return pFound;
}
SvxFieldData* ScUnoEditEngine::FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType)
{
eMode = SC_UNO_COLLECT_FINDPOS;
nFieldPar = nPar;
nFieldPos = nPos;
aFieldType = aType;
nFieldCount = 0;
UpdateFields();
aFieldType = NULL;
eMode = SC_UNO_COLLECT_NONE;
return pFound;
}
//------------------------------------------------------------------------
ScCellFieldsObj::ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos) :
pDocShell( pDocSh ),
aCellPos( rPos ),
mpRefreshListeners( NULL )
{
pDocShell->GetDocument()->AddUnoObject(*this);
pEditSource = new ScCellEditSource( pDocShell, aCellPos );
}
ScCellFieldsObj::~ScCellFieldsObj()
{
if (pDocShell)
pDocShell->GetDocument()->RemoveUnoObject(*this);
delete pEditSource;
// increment refcount to prevent double call off dtor
osl_incrementInterlockedCount( &m_refCount );
if (mpRefreshListeners)
{
lang::EventObject aEvent;
aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
if (mpRefreshListeners)
{
mpRefreshListeners->disposeAndClear(aEvent);
DELETEZ( mpRefreshListeners );
}
}
}
void ScCellFieldsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
if ( rHint.ISA( ScUpdateRefHint ) )
{
//! Ref-Update
}
else if ( rHint.ISA( SfxSimpleHint ) &&
((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
{
pDocShell = NULL; // ungueltig geworden
}
// EditSource hat sich selber als Listener angemeldet
}
// XIndexAccess (via XTextFields)
ScCellFieldObj* ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
{
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
if ( aTempEngine.FindByIndex( (sal_uInt16)Index, NULL ) ) // in der Zelle ist der Typ egal
{
sal_uInt16 nPar = aTempEngine.GetFieldPar();
xub_StrLen nPos = aTempEngine.GetFieldPos();
ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Feld ist 1 Zeichen
return new ScCellFieldObj( pDocShell, aCellPos, aSelection );
}
return NULL;
}
sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
return aTempEngine.CountFields(NULL); // Felder zaehlen, in Zelle ist der Typ egal
}
uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex )
throw(lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
if (xField.is())
return uno::makeAny(xField);
else
throw lang::IndexOutOfBoundsException();
}
uno::Type SAL_CALL ScCellFieldsObj::getElementType() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return getCppuType((uno::Reference<text::XTextField>*)0);
}
sal_Bool SAL_CALL ScCellFieldsObj::hasElements() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return ( getCount() != 0 );
}
uno::Reference<container::XEnumeration> SAL_CALL ScCellFieldsObj::createEnumeration()
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
}
void SAL_CALL ScCellFieldsObj::addContainerListener(
const uno::Reference<container::XContainerListener>& /* xListener */ )
throw(uno::RuntimeException)
{
OSL_FAIL("not implemented");
}
void SAL_CALL ScCellFieldsObj::removeContainerListener(
const uno::Reference<container::XContainerListener>& /* xListener */ )
throw(uno::RuntimeException)
{
OSL_FAIL("not implemented");
}
// XRefreshable
void SAL_CALL ScCellFieldsObj::refresh( )
throw (uno::RuntimeException)
{
if (mpRefreshListeners)
{
// Call all listeners.
uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
sal_uInt32 nLength(aListeners.getLength());
if (nLength)
{
const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
if (pInterfaces)
{
lang::EventObject aEvent;
aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScCellFieldsObj*>(this)));
sal_uInt32 i(0);
while (i < nLength)
{
try
{
while(i < nLength)
{
static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
++pInterfaces;
++i;
}
}
catch(uno::RuntimeException&)
{
++pInterfaces;
++i;
}
}
}
}
}
}
void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
throw (uno::RuntimeException)
{
if (xListener.is())
{
SolarMutexGuard aGuard;
if (!mpRefreshListeners)
mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
mpRefreshListeners->addInterface(xListener);
}
}
void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
throw (uno::RuntimeException)
{
if (xListener.is())
{
SolarMutexGuard aGuard;
if (mpRefreshListeners)
mpRefreshListeners->removeInterface(xListener);
}
}
//------------------------------------------------------------------------
// Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
ScCellFieldObj::ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos,
const ESelection& rSel) :
OComponentHelper( getMutex() ),
pPropSet( lcl_GetURLPropertySet() ),
pDocShell( pDocSh ),
aCellPos( rPos ),
aSelection( rSel )
{
// pDocShell ist Null, wenn per ServiceProvider erzeugt
if (pDocShell)
{
pDocShell->GetDocument()->AddUnoObject(*this);
pEditSource = new ScCellEditSource( pDocShell, aCellPos );
}
else
pEditSource = NULL;
}
uno::Any SAL_CALL ScCellFieldObj::queryAggregation( const uno::Type& rType )
throw(uno::RuntimeException)
{
SC_QUERYINTERFACE( text::XTextField )
SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField
SC_QUERYINTERFACE( beans::XPropertySet )
SC_QUERYINTERFACE( lang::XUnoTunnel )
SC_QUERYINTERFACE( lang::XServiceInfo )
return OComponentHelper::queryAggregation( rType ); // XComponent
}
uno::Sequence<uno::Type> SAL_CALL ScCellFieldObj::getTypes() throw(uno::RuntimeException)
{
static uno::Sequence<uno::Type> aTypes;
if ( aTypes.getLength() == 0 )
{
uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
long nParentLen = aParentTypes.getLength();
const uno::Type* pParentPtr = aParentTypes.getConstArray();
aTypes.realloc( nParentLen + 4 );
uno::Type* pPtr = aTypes.getArray();
pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
for (long i=0; i<nParentLen; i++)
pPtr[i] = pParentPtr[i]; // parent types first
}
return aTypes;
}
namespace
{
class theScCellFieldObjImplementationId : public rtl::Static< UnoTunnelIdInit, theScCellFieldObjImplementationId > {};
}
uno::Sequence<sal_Int8> SAL_CALL ScCellFieldObj::getImplementationId()
throw(uno::RuntimeException)
{
return theScCellFieldObjImplementationId::get().getSeq();
}
uno::Any SAL_CALL ScCellFieldObj::queryInterface( const uno::Type& rType )
throw(uno::RuntimeException)
{
return OComponentHelper::queryInterface( rType );
}
void SAL_CALL ScCellFieldObj::acquire() throw()
{
OComponentHelper::acquire();
}
void SAL_CALL ScCellFieldObj::release() throw()
{
OComponentHelper::release();
}
void ScCellFieldObj::InitDoc( ScDocShell* pDocSh, const ScAddress& rPos,
const ESelection& rSel )
{
if ( pDocSh && !pEditSource )
{
aCellPos = rPos;
aSelection = rSel;
pDocShell = pDocSh;
pDocShell->GetDocument()->AddUnoObject(*this);
pEditSource = new ScCellEditSource( pDocShell, aCellPos );
}
}
ScCellFieldObj::~ScCellFieldObj()
{
if (pDocShell)
pDocShell->GetDocument()->RemoveUnoObject(*this);
delete pEditSource;
}
void ScCellFieldObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
//! Updates fuer aSelection (muessen erst noch erzeugt werden) !!!!!!
if ( rHint.ISA( ScUpdateRefHint ) )
{
//! Ref-Update
}
else if ( rHint.ISA( SfxSimpleHint ) &&
((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
{
pDocShell = NULL; // ungueltig geworden
}
// EditSource hat sich selber als Listener angemeldet
}
// per getImplementation gerufen:
SvxFieldItem ScCellFieldObj::CreateFieldItem()
{
OSL_ENSURE( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
SvxURLField aField;
aField.SetFormat(SVXURLFORMAT_APPDEFAULT);
aField.SetURL( aUrl );
aField.SetRepresentation( aRepresentation );
aField.SetTargetFrame( aTarget );
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
void ScCellFieldObj::DeleteField()
{
if (pEditSource)
{
SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
pForwarder->QuickInsertText( String(), aSelection );
pEditSource->UpdateData();
aSelection.nEndPara = aSelection.nStartPara;
aSelection.nEndPos = aSelection.nStartPos;
//! Broadcast, um Selektion in anderen Objekten anzupassen
//! (auch bei anderen Aktionen)
}
}
// XTextField
rtl::OUString SAL_CALL ScCellFieldObj::getPresentation( sal_Bool bShowCommand )
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
String aRet;
if (pEditSource)
{
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
OSL_ENSURE(pField,"getPresentation: Feld nicht gefunden");
if (pField)
{
SvxURLField* pURL = (SvxURLField*)pField;
if (bShowCommand)
aRet = pURL->GetURL();
else
aRet = pURL->GetRepresentation();
}
}
return aRet;
}
// XTextContent
void SAL_CALL ScCellFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
throw(lang::IllegalArgumentException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (xTextRange.is())
{
uno::Reference<text::XText> xText(xTextRange->getText());
if (xText.is())
{
xText->insertTextContent( xTextRange, this, sal_True );
}
}
}
uno::Reference<text::XTextRange> SAL_CALL ScCellFieldObj::getAnchor() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (pDocShell)
return new ScCellObj( pDocShell, aCellPos );
return NULL;
}
// XComponent
void SAL_CALL ScCellFieldObj::dispose() throw(uno::RuntimeException)
{
OComponentHelper::dispose();
}
void SAL_CALL ScCellFieldObj::addEventListener(
const uno::Reference<lang::XEventListener>& xListener )
throw(uno::RuntimeException)
{
OComponentHelper::addEventListener( xListener );
}
void SAL_CALL ScCellFieldObj::removeEventListener(
const uno::Reference<lang::XEventListener>& xListener )
throw(uno::RuntimeException)
{
OComponentHelper::removeEventListener( xListener );
}
// XPropertySet
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellFieldObj::getPropertySetInfo()
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
return aRef;
}
void SAL_CALL ScCellFieldObj::setPropertyValue(
const rtl::OUString& aPropertyName, const uno::Any& aValue )
throw(beans::UnknownPropertyException, beans::PropertyVetoException,
lang::IllegalArgumentException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
String aNameString(aPropertyName);
rtl::OUString aStrVal;
if (pEditSource)
{
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
OSL_ENSURE(pField,"setPropertyValue: Feld nicht gefunden");
if (pField)
{
SvxURLField* pURL = (SvxURLField*)pField; // ist eine Kopie in der ScUnoEditEngine
sal_Bool bOk = sal_True;
if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
{
if (aValue >>= aStrVal)
pURL->SetURL( aStrVal );
}
else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
{
if (aValue >>= aStrVal)
pURL->SetRepresentation( aStrVal );
}
else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
{
if (aValue >>= aStrVal)
pURL->SetTargetFrame( aStrVal );
}
else
bOk = false;
if (bOk)
{
pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
pEditSource->UpdateData();
}
}
}
else // noch nicht eingefuegt
{
if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
{
if (aValue >>= aStrVal)
aUrl = String( aStrVal );
}
else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
{
if (aValue >>= aStrVal)
aRepresentation = String( aStrVal );
}
else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
{
if (aValue >>= aStrVal)
aTarget = String( aStrVal );
}
}
}
uno::Any SAL_CALL ScCellFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
throw(beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Any aRet;
String aNameString(aPropertyName);
// anchor type is always "as character", text wrap always "none"
if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
aRet <<= text::TextContentAnchorType_AS_CHARACTER;
else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
{
uno::Sequence<text::TextContentAnchorType> aSeq(1);
aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
aRet <<= aSeq;
}
else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
aRet <<= text::WrapTextMode_NONE;
else if (pEditSource)
{
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
// Typ egal (in Zellen gibts nur URLs)
SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
OSL_ENSURE(pField,"getPropertyValue: Feld nicht gefunden");
if (pField)
{
SvxURLField* pURL = (SvxURLField*)pField;
if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
aRet <<= rtl::OUString( pURL->GetURL() );
else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
aRet <<= rtl::OUString( pURL->GetRepresentation() );
else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
aRet <<= rtl::OUString( pURL->GetTargetFrame() );
}
}
else // noch nicht eingefuegt
{
if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
aRet <<= rtl::OUString( aUrl );
else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
aRet <<= rtl::OUString( aRepresentation );
else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
aRet <<= rtl::OUString( aTarget );
}
return aRet;
}
SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellFieldObj )
// XUnoTunnel
sal_Int64 SAL_CALL ScCellFieldObj::getSomething(
const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
{
if ( rId.getLength() == 16 &&
0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
rId.getConstArray(), 16 ) )
{
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
}
return 0;
}
namespace
{
class theScCellFieldObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScCellFieldObjUnoTunnelId> {};
}
const uno::Sequence<sal_Int8>& ScCellFieldObj::getUnoTunnelId()
{
return theScCellFieldObjUnoTunnelId::get().getSeq();
}
ScCellFieldObj* ScCellFieldObj::getImplementation(
const uno::Reference<text::XTextContent> xObj )
{
ScCellFieldObj* pRet = NULL;
uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
if (xUT.is())
pRet = reinterpret_cast<ScCellFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
return pRet;
}
// XServiceInfo
rtl::OUString SAL_CALL ScCellFieldObj::getImplementationName() throw(uno::RuntimeException)
{
return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ScCellFieldObj" ));
}
sal_Bool SAL_CALL ScCellFieldObj::supportsService( const rtl::OUString& rServiceName )
throw(uno::RuntimeException)
{
String aServiceStr( rServiceName );
return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
}
uno::Sequence<rtl::OUString> SAL_CALL ScCellFieldObj::getSupportedServiceNames()
throw(uno::RuntimeException)
{
uno::Sequence<rtl::OUString> aRet(2);
rtl::OUString* pArray = aRet.getArray();
pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTFIELD_SERVICE ));
pArray[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTCONTENT_SERVICE ));
return aRet;
}
//------------------------------------------------------------------------
ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP, sal_uInt16 nT) :
pContentObj( pContent ),
nPart( nP ),
nType( nT ),
mpRefreshListeners( NULL )
{
OSL_ENSURE( pContentObj, "ScHeaderFieldsObj ohne Objekt?" );
if (pContentObj)
{
pContentObj->acquire(); // darf nicht wegkommen
pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
}
else
pEditSource = NULL;
}
ScHeaderFieldsObj::~ScHeaderFieldsObj()
{
delete pEditSource;
if (pContentObj)
pContentObj->release();
// increment refcount to prevent double call off dtor
osl_incrementInterlockedCount( &m_refCount );
if (mpRefreshListeners)
{
lang::EventObject aEvent;
aEvent.Source = static_cast<cppu::OWeakObject*>(this);
if (mpRefreshListeners)
{
mpRefreshListeners->disposeAndClear(aEvent);
DELETEZ( mpRefreshListeners );
}
}
}
// XIndexAccess (via XTextFields)
ScHeaderFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
{
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
TypeId aTypeId = NULL;
switch (nType)
{
case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break;
case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break;
case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break;
case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break;
case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break;
case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break;
case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break;
// bei SC_SERVICE_INVALID bleibt TypeId Null
}
SvxFieldData* pData = aTempEngine.FindByIndex( (sal_uInt16)Index, aTypeId );
if ( pData )
{
sal_uInt16 nPar = aTempEngine.GetFieldPar();
xub_StrLen nPos = aTempEngine.GetFieldPos();
sal_uInt16 nFieldType = nType;
if ( nFieldType == SC_SERVICE_INVALID )
{
if ( pData->ISA( SvxPageField ) ) nFieldType = SC_SERVICE_PAGEFIELD;
else if ( pData->ISA( SvxPagesField ) ) nFieldType = SC_SERVICE_PAGESFIELD;
else if ( pData->ISA( SvxDateField ) ) nFieldType = SC_SERVICE_DATEFIELD;
else if ( pData->ISA( SvxTimeField ) ) nFieldType = SC_SERVICE_TIMEFIELD;
else if ( pData->ISA( SvxFileField ) ) nFieldType = SC_SERVICE_TITLEFIELD;
else if ( pData->ISA( SvxExtFileField ) ) nFieldType = SC_SERVICE_FILEFIELD;
else if ( pData->ISA( SvxTableField ) ) nFieldType = SC_SERVICE_SHEETFIELD;
}
ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field is 1 character
return new ScHeaderFieldObj( pContentObj, nPart, nFieldType, aSelection );
}
return NULL;
}
sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
//! Feld-Funktionen muessen an den Forwarder !!!
ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
TypeId aTypeId = NULL;
switch (nType)
{
case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break;
case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break;
case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break;
case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break;
case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break;
case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break;
case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break;
}
return aTempEngine.CountFields(aTypeId); // Felder zaehlen
}
uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex )
throw(lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
if (xField.is())
return uno::makeAny(xField);
else
throw lang::IndexOutOfBoundsException();
}
uno::Type SAL_CALL ScHeaderFieldsObj::getElementType() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return getCppuType((uno::Reference<text::XTextField>*)0);
}
sal_Bool SAL_CALL ScHeaderFieldsObj::hasElements() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return ( getCount() != 0 );
}
uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFieldsObj::createEnumeration()
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
}
void SAL_CALL ScHeaderFieldsObj::addContainerListener(
const uno::Reference<container::XContainerListener>& /* xListener */ )
throw(uno::RuntimeException)
{
OSL_FAIL("not implemented");
}
void SAL_CALL ScHeaderFieldsObj::removeContainerListener(
const uno::Reference<container::XContainerListener>& /* xListener */ )
throw(uno::RuntimeException)
{
OSL_FAIL("not implemented");
}
// XRefreshable
void SAL_CALL ScHeaderFieldsObj::refresh( )
throw (uno::RuntimeException)
{
if (mpRefreshListeners)
{
// Call all listeners.
uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
sal_uInt32 nLength(aListeners.getLength());
if (nLength)
{
const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
if (pInterfaces)
{
lang::EventObject aEvent;
aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScHeaderFieldsObj*>(this)));
sal_uInt32 i(0);
while (i < nLength)
{
try
{
while(i < nLength)
{
static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
++pInterfaces;
++i;
}
}
catch(uno::RuntimeException&)
{
++pInterfaces;
++i;
}
}
}
}
}
}
void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
throw (uno::RuntimeException)
{
if (xListener.is())
{
SolarMutexGuard aGuard;
if (!mpRefreshListeners)
mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
mpRefreshListeners->addInterface(xListener);
}
}
void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
throw (uno::RuntimeException)
{
if (xListener.is())
{
SolarMutexGuard aGuard;
if (mpRefreshListeners)
mpRefreshListeners->removeInterface(xListener);
}
}
//------------------------------------------------------------------------
SvxFileFormat lcl_UnoToSvxFileFormat( sal_Int16 nUnoValue )
{
switch( nUnoValue )
{
case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH;
case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH;
case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME;
default:
return SVXFILEFORMAT_NAME_EXT;
}
}
sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue )
{
switch( nSvxValue )
{
case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT;
case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL;
case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH;
default:
return text::FilenameDisplayFormat::NAME;
}
}
ScHeaderFieldObj::ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
sal_uInt16 nT, const ESelection& rSel) :
OComponentHelper( getMutex() ),
pPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertySet() : lcl_GetHeaderFieldPropertySet() ),
pContentObj( pContent ),
nPart( nP ),
nType( nT ),
aSelection( rSel ),
nFileFormat( SVXFILEFORMAT_NAME_EXT )
{
// pContent ist Null, wenn per ServiceProvider erzeugt
if (pContentObj)
{
pContentObj->acquire(); // darf nicht wegkommen
pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
}
else
pEditSource = NULL;
}
uno::Any SAL_CALL ScHeaderFieldObj::queryAggregation( const uno::Type& rType )
throw(uno::RuntimeException)
{
SC_QUERYINTERFACE( text::XTextField )
SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField
SC_QUERYINTERFACE( beans::XPropertySet )
SC_QUERYINTERFACE( lang::XUnoTunnel )
SC_QUERYINTERFACE( lang::XServiceInfo )
return OComponentHelper::queryAggregation( rType ); // XComponent
}
uno::Sequence<uno::Type> SAL_CALL ScHeaderFieldObj::getTypes() throw(uno::RuntimeException)
{
static uno::Sequence<uno::Type> aTypes;
if ( aTypes.getLength() == 0 )
{
uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
long nParentLen = aParentTypes.getLength();
const uno::Type* pParentPtr = aParentTypes.getConstArray();
aTypes.realloc( nParentLen + 4 );
uno::Type* pPtr = aTypes.getArray();
pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
for (long i=0; i<nParentLen; i++)
pPtr[i] = pParentPtr[i]; // parent types first
}
return aTypes;
}
namespace
{
class theScHeaderFieldObjImplementationId : public rtl::Static< UnoTunnelIdInit, theScHeaderFieldObjImplementationId > {};
}
uno::Sequence<sal_Int8> SAL_CALL ScHeaderFieldObj::getImplementationId()
throw(uno::RuntimeException)
{
return theScHeaderFieldObjImplementationId::get().getSeq();
}
uno::Any SAL_CALL ScHeaderFieldObj::queryInterface( const uno::Type& rType )
throw(uno::RuntimeException)
{
return OComponentHelper::queryInterface( rType );
}
void SAL_CALL ScHeaderFieldObj::acquire() throw()
{
OComponentHelper::acquire();
}
void SAL_CALL ScHeaderFieldObj::release() throw()
{
OComponentHelper::release();
}
void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
const ESelection& rSel )
{
if ( pContent && !pEditSource )
{
OSL_ENSURE( !pContentObj, "ContentObj, aber kein EditSource?" );
aSelection = rSel;
nPart = nP;
pContentObj = pContent;
pContentObj->acquire(); // darf nicht wegkommen
pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
}
}
ScHeaderFieldObj::~ScHeaderFieldObj()
{
delete pEditSource;
if (pContentObj)
pContentObj->release();
}
// per getImplementation gerufen:
SvxFieldItem ScHeaderFieldObj::CreateFieldItem()
{
OSL_ENSURE( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
switch (nType)
{
case SC_SERVICE_PAGEFIELD:
{
SvxPageField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_PAGESFIELD:
{
SvxPagesField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_DATEFIELD:
{
SvxDateField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_TIMEFIELD:
{
SvxTimeField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_TITLEFIELD:
{
SvxFileField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_FILEFIELD:
{
SvxExtFileField aField;
aField.SetFormat( (SvxFileFormat) nFileFormat );
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
case SC_SERVICE_SHEETFIELD:
{
SvxTableField aField;
return SvxFieldItem( aField, EE_FEATURE_FIELD );
}
}
return SvxFieldItem( SvxFieldData(), EE_FEATURE_FIELD );
}
void ScHeaderFieldObj::DeleteField()
{
if (pEditSource)
{
SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
pForwarder->QuickInsertText( String(), aSelection );
pEditSource->UpdateData();
aSelection.nEndPara = aSelection.nStartPara;
aSelection.nEndPos = aSelection.nStartPos;
//! Broadcast, um Selektion in anderen Objekten anzupassen
//! (auch bei anderen Aktionen)
}
}
// XTextField
rtl::OUString SAL_CALL ScHeaderFieldObj::getPresentation( sal_Bool /* bShowCommand */ )
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
String aRet;
if (pEditSource)
{
// Feld von der EditEngine formatieren lassen, bShowCommand gibt's nicht
SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
aRet = pForwarder->GetText( aSelection );
}
return aRet;
}
// XTextContent
void SAL_CALL ScHeaderFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
throw(lang::IllegalArgumentException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (xTextRange.is())
{
uno::Reference<text::XText> xText(xTextRange->getText());
if (xText.is())
{
xText->insertTextContent( xTextRange, this, sal_True );
}
}
}
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFieldObj::getAnchor() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (pContentObj)
{
uno::Reference<text::XText> xText;
if ( nPart == SC_HDFT_LEFT )
xText = pContentObj->getLeftText();
else if (nPart == SC_HDFT_CENTER)
xText = pContentObj->getCenterText();
else
xText = pContentObj->getRightText();
return uno::Reference<text::XTextRange>( xText, uno::UNO_QUERY );
}
return NULL;
}
// XComponent
void SAL_CALL ScHeaderFieldObj::dispose() throw(uno::RuntimeException)
{
OComponentHelper::dispose();
}
void SAL_CALL ScHeaderFieldObj::addEventListener(
const uno::Reference<lang::XEventListener>& xListener )
throw(uno::RuntimeException)
{
OComponentHelper::addEventListener( xListener );
}
void SAL_CALL ScHeaderFieldObj::removeEventListener(
const uno::Reference<lang::XEventListener>& xListener )
throw(uno::RuntimeException)
{
OComponentHelper::removeEventListener( xListener );
}
// XPropertySet
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScHeaderFieldObj::getPropertySetInfo()
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (nType == SC_SERVICE_FILEFIELD)
{
// file field has different properties
static uno::Reference<beans::XPropertySetInfo> aFileFieldInfo = pPropSet->getPropertySetInfo();
return aFileFieldInfo;
}
else
{
static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
return aRef;
}
}
void SAL_CALL ScHeaderFieldObj::setPropertyValue(
const rtl::OUString& aPropertyName, const uno::Any& aValue )
throw(beans::UnknownPropertyException, beans::PropertyVetoException,
lang::IllegalArgumentException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
String aNameString(aPropertyName);
if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
{
sal_Int16 nIntVal = 0;
if ( aValue >>= nIntVal )
{
SvxFileFormat eFormat = lcl_UnoToSvxFileFormat( nIntVal );
if (pEditSource)
{
ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
OSL_ENSURE(pField,"setPropertyValue: Field not found");
if (pField)
{
SvxExtFileField* pExtFile = (SvxExtFileField*)pField; // local to the ScUnoEditEngine
pExtFile->SetFormat( eFormat );
pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
pEditSource->UpdateData();
}
}
else
nFileFormat = sal::static_int_cast<sal_Int16>(eFormat); // not inserted yet - store value
}
}
}
uno::Any SAL_CALL ScHeaderFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
throw(beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
//! Properties?
uno::Any aRet;
String aNameString(aPropertyName);
// anchor type is always "as character", text wrap always "none"
if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
aRet <<= text::TextContentAnchorType_AS_CHARACTER;
else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
{
uno::Sequence<text::TextContentAnchorType> aSeq(1);
aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
aRet <<= aSeq;
}
else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
aRet <<= text::WrapTextMode_NONE;
else if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
{
SvxFileFormat eFormat = SVXFILEFORMAT_NAME_EXT;
if (pEditSource)
{
ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
ScUnoEditEngine aTempEngine(pEditEngine);
SvxFieldData* pField = aTempEngine.FindByPos(
aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
OSL_ENSURE(pField,"setPropertyValue: Field not found");
if (pField)
{
const SvxExtFileField* pExtFile = (const SvxExtFileField*)pField;
eFormat = pExtFile->GetFormat();
}
}
else
eFormat = (SvxFileFormat) nFileFormat; // not inserted yet - use stored value
sal_Int16 nIntVal = lcl_SvxToUnoFileFormat( eFormat );
aRet <<= nIntVal;
}
return aRet;
}
SC_IMPL_DUMMY_PROPERTY_LISTENER( ScHeaderFieldObj )
// XUnoTunnel
sal_Int64 SAL_CALL ScHeaderFieldObj::getSomething(
const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
{
if ( rId.getLength() == 16 &&
0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
rId.getConstArray(), 16 ) )
{
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
}
return 0;
}
namespace
{
class theScHeaderFieldObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScHeaderFieldObjUnoTunnelId> {};
}
const uno::Sequence<sal_Int8>& ScHeaderFieldObj::getUnoTunnelId()
{
return theScHeaderFieldObjUnoTunnelId::get().getSeq();
}
ScHeaderFieldObj* ScHeaderFieldObj::getImplementation(
const uno::Reference<text::XTextContent> xObj )
{
ScHeaderFieldObj* pRet = NULL;
uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
if (xUT.is())
pRet = reinterpret_cast<ScHeaderFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
return pRet;
}
// XServiceInfo
rtl::OUString SAL_CALL ScHeaderFieldObj::getImplementationName() throw(uno::RuntimeException)
{
return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ScHeaderFieldObj" ));
}
sal_Bool SAL_CALL ScHeaderFieldObj::supportsService( const rtl::OUString& rServiceName )
throw(uno::RuntimeException)
{
String aServiceStr( rServiceName );
return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
}
uno::Sequence<rtl::OUString> SAL_CALL ScHeaderFieldObj::getSupportedServiceNames()
throw(uno::RuntimeException)
{
uno::Sequence<rtl::OUString> aRet(2);
rtl::OUString* pArray = aRet.getArray();
pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTFIELD_SERVICE ));
pArray[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTCONTENT_SERVICE ));
return aRet;
}
//------------------------------------------------------------------------
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|