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
|
/* -*- 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 <rtl/ustrbuf.hxx>
#include <tools/urlobj.hxx>
#ifndef _SVSTDARR_STRINGSSORT_DECL
#define _SVSTDARR_STRINGSSORT
#include <svl/svstdarr.hxx>
#endif
#include <xmloff/nmspmap.hxx>
#include <format.hxx>
#include <fmtcol.hxx>
#include <hints.hxx>
#include <poolfmt.hxx>
#include <charfmt.hxx>
#include <paratr.hxx>
#include <doc.hxx>
#include "docary.hxx"
#include "unostyle.hxx"
#include "fmtpdsc.hxx"
#include "pagedesc.hxx"
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/i18nmap.hxx>
#include <xmloff/xmltkmap.hxx>
#include "xmlitem.hxx"
#include <xmloff/xmlstyle.hxx>
#include <xmloff/txtstyli.hxx>
#include <xmloff/txtimp.hxx>
#include <xmloff/families.hxx>
#include <xmloff/XMLTextMasterStylesContext.hxx>
#include <xmloff/XMLTextShapeStyleContext.hxx>
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
#include "xmlimp.hxx"
#include "xmltbli.hxx"
#include "cellatr.hxx"
#include <SwStyleNameMapper.hxx>
#include <xmloff/attrlist.hxx>
#include <unotxdoc.hxx>
#include <docsh.hxx>
using namespace ::com::sun::star;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using namespace ::xmloff::token;
class SwXMLConditionParser_Impl
{
OUString sInput;
sal_uInt32 nCondition;
sal_uInt32 nSubCondition;
sal_Int32 nPos;
sal_Int32 nLength;
inline sal_Bool SkipWS();
inline sal_Bool MatchChar( sal_Unicode c );
inline sal_Bool MatchName( OUString& rName );
inline sal_Bool MatchNumber( sal_uInt32& rNumber );
public:
SwXMLConditionParser_Impl( const OUString& rInp );
sal_Bool IsValid() const { return 0 != nCondition; }
sal_uInt32 GetCondition() const { return nCondition; }
sal_uInt32 GetSubCondition() const { return nSubCondition; }
};
inline sal_Bool SwXMLConditionParser_Impl::SkipWS()
{
while( nPos < nLength && ' ' == sInput[nPos] )
nPos++;
return sal_True;
}
inline sal_Bool SwXMLConditionParser_Impl::MatchChar( sal_Unicode c )
{
sal_Bool bRet = sal_False;
if( nPos < nLength && c == sInput[nPos] )
{
nPos++;
bRet = sal_True;
}
return bRet;
}
inline sal_Bool SwXMLConditionParser_Impl::MatchName( OUString& rName )
{
OUStringBuffer sBuffer( nLength );
while( nPos < nLength &&
( ('a' <= sInput[nPos] && sInput[nPos] <= 'z') ||
'-' == sInput[nPos] ) )
{
sBuffer.append( sInput[nPos] );
nPos++;
}
rName = sBuffer.makeStringAndClear();
return rName.getLength() > 0;
}
inline sal_Bool SwXMLConditionParser_Impl::MatchNumber( sal_uInt32& rNumber )
{
OUStringBuffer sBuffer( nLength );
while( nPos < nLength && '0' <= sInput[nPos] && sInput[nPos] <= '9' )
{
sBuffer.append( sInput[nPos] );
nPos++;
}
OUString sNum( sBuffer.makeStringAndClear() );
if( sNum.getLength() )
rNumber = sNum.toInt32();
return sNum.getLength() > 0;
}
SwXMLConditionParser_Impl::SwXMLConditionParser_Impl( const OUString& rInp ) :
sInput( rInp ),
nCondition( 0 ),
nSubCondition( 0 ),
nPos( 0 ),
nLength( rInp.getLength() )
{
OUString sFunc;
sal_Bool bHasSub = sal_False;
sal_uInt32 nSub = 0;
sal_Bool bOK = SkipWS() && MatchName( sFunc ) && SkipWS() &&
MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
if( bOK && MatchChar( '=' ) )
{
bOK = SkipWS() && MatchNumber( nSub ) && SkipWS();
bHasSub = sal_True;
}
bOK &= nPos == nLength;
if( bOK )
{
if( IsXMLToken( sFunc, XML_ENDNOTE ) && !bHasSub )
nCondition = PARA_IN_ENDNOTE;
else if( IsXMLToken( sFunc, XML_FOOTER ) && !bHasSub )
nCondition = PARA_IN_FOOTER;
else if( IsXMLToken( sFunc, XML_FOOTNOTE ) && !bHasSub )
nCondition = PARA_IN_FOOTENOTE;
else if( IsXMLToken( sFunc, XML_HEADER ) && !bHasSub )
nCondition = PARA_IN_HEADER;
else if( IsXMLToken( sFunc, XML_LIST_LEVEL) &&
nSub >=1 && nSub <= MAXLEVEL )
{
nCondition = PARA_IN_LIST;
nSubCondition = nSub-1;
}
else if( IsXMLToken( sFunc, XML_OUTLINE_LEVEL) &&
nSub >=1 && nSub <= MAXLEVEL )
{
nCondition = PARA_IN_OUTLINE;
nSubCondition = nSub-1;
}
else if( IsXMLToken( sFunc, XML_SECTION ) && !bHasSub )
{
nCondition = PARA_IN_SECTION;
}
else if( IsXMLToken( sFunc, XML_TABLE ) && !bHasSub )
{
nCondition = PARA_IN_TABLEBODY;
}
else if( IsXMLToken( sFunc, XML_TABLE_HEADER ) && !bHasSub )
{
nCondition = PARA_IN_TABLEHEAD;
}
else if( IsXMLToken( sFunc, XML_TEXT_BOX ) && !bHasSub )
{
nCondition = PARA_IN_FRAME;
}
}
}
// ---------------------------------------------------------------------
class SwXMLConditionContext_Impl : public SvXMLImportContext
{
sal_uInt32 nCondition;
sal_uInt32 nSubCondition;
OUString sApplyStyle;
void ParseCondition( const OUString& rCond );
public:
SwXMLConditionContext_Impl(
SvXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
virtual ~SwXMLConditionContext_Impl();
TYPEINFO();
sal_Bool IsValid() const { return 0 != nCondition; }
sal_uInt32 GetCondition() const { return nCondition; }
sal_uInt32 GetSubCondition() const { return nSubCondition; }
const OUString& GetApplyStyle() const { return sApplyStyle; }
};
SwXMLConditionContext_Impl::SwXMLConditionContext_Impl(
SvXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList ) :
SvXMLImportContext( rImport, nPrfx, rLName ),
nCondition( 0 ),
nSubCondition( 0 )
{
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; i++ )
{
const OUString& rAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix =
GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
&aLocalName );
const OUString& rValue = xAttrList->getValueByIndex( i );
// TODO: use a map here
if( XML_NAMESPACE_STYLE == nPrefix )
{
if( IsXMLToken( aLocalName, XML_CONDITION ) )
{
SwXMLConditionParser_Impl aCondParser( rValue );
if( aCondParser.IsValid() )
{
nCondition = aCondParser.GetCondition();
nSubCondition = aCondParser.GetSubCondition();
}
}
else if( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME ) )
{
sApplyStyle = rValue;
}
}
}
}
SwXMLConditionContext_Impl::~SwXMLConditionContext_Impl()
{
}
TYPEINIT1( SwXMLConditionContext_Impl, XMLTextStyleContext );
// ---------------------------------------------------------------------
typedef SwXMLConditionContext_Impl *SwXMLConditionContextPtr;
SV_DECL_PTRARR( SwXMLConditions_Impl, SwXMLConditionContextPtr, 5, 2 )
class SwXMLTextStyleContext_Impl : public XMLTextStyleContext
{
SwXMLConditions_Impl *pConditions;
protected:
virtual uno::Reference < style::XStyle > Create();
public:
TYPEINFO();
SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
sal_uInt16 nFamily,
SvXMLStylesContext& rStyles );
virtual ~SwXMLTextStyleContext_Impl();
virtual SvXMLImportContext *CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
virtual void Finish( sal_Bool bOverwrite );
};
TYPEINIT1( SwXMLTextStyleContext_Impl, XMLTextStyleContext );
uno::Reference < style::XStyle > SwXMLTextStyleContext_Impl::Create()
{
uno::Reference < style::XStyle > xNewStyle;
if( pConditions && XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() )
{
uno::Reference< lang::XMultiServiceFactory > xFactory( GetImport().GetModel(),
uno::UNO_QUERY );
if( xFactory.is() )
{
OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.style.ConditionalParagraphStyle" ) );
uno::Reference < uno::XInterface > xIfc =
xFactory->createInstance( sServiceName );
if( xIfc.is() )
xNewStyle = uno::Reference < style::XStyle >( xIfc, uno::UNO_QUERY );
}
}
else
{
xNewStyle = XMLTextStyleContext::Create();
}
return xNewStyle;
}
SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
sal_uInt16 nFamily,
SvXMLStylesContext& rStyles ) :
XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
pConditions( 0 )
{
}
SwXMLTextStyleContext_Impl::~SwXMLTextStyleContext_Impl()
{
if( pConditions )
{
while( pConditions->Count() )
{
SwXMLConditionContext_Impl *pCond = pConditions->GetObject(0);
pConditions->Remove( 0UL );
pCond->ReleaseRef();
}
delete pConditions;
}
}
SvXMLImportContext *SwXMLTextStyleContext_Impl::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = 0;
if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_MAP ) )
{
SwXMLConditionContext_Impl *pCond =
new SwXMLConditionContext_Impl( GetImport(), nPrefix,
rLocalName, xAttrList );
if( pCond->IsValid() )
{
if( !pConditions )
pConditions = new SwXMLConditions_Impl;
pConditions->Insert( pCond, pConditions->Count() );
pCond->AddRef();
}
pContext = pCond;
}
if( !pContext )
pContext = XMLTextStyleContext::CreateChildContext( nPrefix, rLocalName,
xAttrList );
return pContext;
}
void SwXMLTextStyleContext_Impl::Finish( sal_Bool bOverwrite )
{
XMLTextStyleContext::Finish( bOverwrite );
if( !pConditions || XML_STYLE_FAMILY_TEXT_PARAGRAPH != GetFamily() )
return;
uno::Reference < style::XStyle > xStyle = GetStyle();
if( !xStyle.is() )
return;
const SwXStyle* pStyle = 0;
uno::Reference<lang::XUnoTunnel> xStyleTunnel( xStyle, uno::UNO_QUERY);
if( xStyleTunnel.is() )
{
pStyle = reinterpret_cast< SwXStyle * >(
sal::static_int_cast< sal_IntPtr >( xStyleTunnel->getSomething( SwXStyle::getUnoTunnelId() )));
}
if( !pStyle )
return;
const SwDoc *pDoc = pStyle->GetDoc();
SwTxtFmtColl *pColl = pDoc->FindTxtFmtCollByName( pStyle->GetStyleName() );
OSL_ENSURE( pColl, "Text collection not found" );
if( !pColl || RES_CONDTXTFMTCOLL != pColl->Which() )
return;
sal_uInt16 nCount = pConditions->Count();
String aString;
OUString sName;
for( sal_uInt16 i = 0; i < nCount; i++ )
{
const SwXMLConditionContext_Impl *pCond = (*pConditions)[i];
OUString aDisplayName(
GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_PARAGRAPH,
pCond->GetApplyStyle() ) );
SwStyleNameMapper::FillUIName( aDisplayName,
aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
sal_True);
sName = aString;
SwTxtFmtColl* pCondColl = pDoc->FindTxtFmtCollByName( sName );
OSL_ENSURE( pCondColl,
"SwXMLItemSetStyleContext_Impl::ConnectConditions: cond coll missing" );
if( pCondColl )
{
SwCollCondition aCond( pCondColl, pCond->GetCondition(),
pCond->GetSubCondition() );
((SwConditionTxtFmtColl*)pColl)->InsertCondition( aCond );
}
}
}
// ---------------------------------------------------------------------
class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext
{
OUString sMasterPageName;
SfxItemSet *pItemSet;
SwXMLTextStyleContext_Impl *pTextStyle;
SvXMLStylesContext &rStyles;
OUString sDataStyleName;
sal_Bool bHasMasterPageName : 1;
sal_Bool bPageDescConnected : 1;
sal_Bool bDataStyleIsResolved;
SvXMLImportContext *CreateItemSetContext(
sal_uInt16 nPrefix,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList);
protected:
virtual void SetAttribute( sal_uInt16 nPrefixKey,
const OUString& rLocalName,
const OUString& rValue );
const SwXMLImport& GetSwImport() const
{ return (const SwXMLImport&)GetImport(); }
SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
public:
TYPEINFO();
SwXMLItemSetStyleContext_Impl(
SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
SvXMLStylesContext& rStylesC,
sal_uInt16 nFamily);
virtual ~SwXMLItemSetStyleContext_Impl();
virtual void CreateAndInsert( sal_Bool bOverwrite );
virtual SvXMLImportContext *CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
// The item set may be empty!
SfxItemSet *GetItemSet() { return pItemSet; }
const SfxItemSet *GetItemSet() const { return pItemSet; }
const OUString& GetMasterPageName() const { return sMasterPageName; }
sal_Bool HasMasterPageName() const { return bHasMasterPageName; }
sal_Bool IsPageDescConnected() const { return bPageDescConnected; }
void ConnectPageDesc();
sal_Bool ResolveDataStyleName();
};
void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
const OUString& rLocalName,
const OUString& rValue )
{
if( XML_NAMESPACE_STYLE == nPrefixKey )
{
if ( IsXMLToken( rLocalName, XML_MASTER_PAGE_NAME ) )
{
sMasterPageName = rValue;
bHasMasterPageName = sal_True;
}
else if ( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
{
// if we have a valid data style name
if (rValue.getLength() > 0)
{
sDataStyleName = rValue;
bDataStyleIsResolved = sal_False; // needs to be resolved
}
}
else
{
SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
}
}
else
{
SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
}
}
SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext(
sal_uInt16 nPrefix, const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
OSL_ENSURE( !pItemSet,
"SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" );
SvXMLImportContext *pContext = 0;
SwDoc* pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
SfxItemPool& rItemPool = pDoc->GetAttrPool();
switch( GetFamily() )
{
case XML_STYLE_FAMILY_TABLE_TABLE:
pItemSet = new SfxItemSet( rItemPool, aTableSetRange );
break;
case XML_STYLE_FAMILY_TABLE_COLUMN:
pItemSet = new SfxItemSet( rItemPool, RES_FRM_SIZE, RES_FRM_SIZE, 0 );
break;
case XML_STYLE_FAMILY_TABLE_ROW:
pItemSet = new SfxItemSet( rItemPool, aTableLineSetRange );
break;
case XML_STYLE_FAMILY_TABLE_CELL:
pItemSet = new SfxItemSet( rItemPool, aTableBoxSetRange );
break;
default:
OSL_ENSURE( !this,
"SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
break;
}
if( pItemSet )
pContext = GetSwImport().CreateTableItemImportContext(
nPrefix, rLName, xAttrList, GetFamily(),
*pItemSet );
if( !pContext )
{
delete pItemSet;
pItemSet = 0;
}
return pContext;
}
TYPEINIT1( SwXMLItemSetStyleContext_Impl, SvXMLStyleContext );
SwXMLItemSetStyleContext_Impl::SwXMLItemSetStyleContext_Impl( SwXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
SvXMLStylesContext& rStylesC,
sal_uInt16 nFamily ) :
SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, nFamily ),
pItemSet( 0 ),
pTextStyle( 0 ),
rStyles( rStylesC ),
bHasMasterPageName( sal_False ),
bPageDescConnected( sal_False ),
bDataStyleIsResolved( sal_True )
{
}
SwXMLItemSetStyleContext_Impl::~SwXMLItemSetStyleContext_Impl()
{
delete pItemSet;
}
void SwXMLItemSetStyleContext_Impl::CreateAndInsert( sal_Bool bOverwrite )
{
if( pTextStyle )
pTextStyle->CreateAndInsert( bOverwrite );
}
SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = 0;
if( XML_NAMESPACE_STYLE == nPrefix )
{
if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ||
IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) ||
IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ||
IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
{
pContext = CreateItemSetContext( nPrefix, rLocalName, xAttrList );
}
else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ||
IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ))
{
if( !pTextStyle )
{
SvXMLAttributeList *pTmp = new SvXMLAttributeList;
OUString aStr = GetImport().GetNamespaceMap().GetQNameByKey( nPrefix, GetXMLToken(XML_NAME) );
pTmp->AddAttribute( aStr, GetName() );
uno::Reference <xml::sax::XAttributeList> xTmpAttrList = pTmp;
pTextStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix,
rLocalName, xTmpAttrList, XML_STYLE_FAMILY_TEXT_PARAGRAPH, rStyles );
pTextStyle->StartElement( xTmpAttrList );
rStyles.AddStyle( *pTextStyle );
}
pContext = pTextStyle->CreateChildContext( nPrefix, rLocalName, xAttrList );
}
}
if( !pContext )
pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
xAttrList );
return pContext;
}
void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
{
if( bPageDescConnected || !HasMasterPageName() )
return;
bPageDescConnected = sal_True;
SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
String sName;
// #i40788# - first determine the display name of the page style,
// then map this name to the corresponding user interface name.
sName = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE,
GetMasterPageName() );
SwStyleNameMapper::FillUIName( sName,
sName,
nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC,
sal_True);
SwPageDesc *pPageDesc = pDoc->FindPageDescByName( sName );
if( !pPageDesc )
{
// If the page style is a pool style, then we maybe have to create it
// first if it hasn't been used by now.
sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( sName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
if( USHRT_MAX != nPoolId )
pPageDesc = pDoc->GetPageDescFromPool( nPoolId, false );
}
if( !pPageDesc )
return;
if( !pItemSet )
{
SfxItemPool& rItemPool = pDoc->GetAttrPool();
pItemSet = new SfxItemSet( rItemPool, aTableSetRange );
}
const SfxPoolItem *pItem;
SwFmtPageDesc *pFmtPageDesc = 0;
if( SFX_ITEM_SET == pItemSet->GetItemState( RES_PAGEDESC, sal_False,
&pItem ) )
{
if( ((SwFmtPageDesc *)pItem)->GetPageDesc() != pPageDesc )
pFmtPageDesc = new SwFmtPageDesc( *(SwFmtPageDesc *)pItem );
}
else
pFmtPageDesc = new SwFmtPageDesc();
if( pFmtPageDesc )
{
pFmtPageDesc->RegisterToPageDesc( *pPageDesc );
pItemSet->Put( *pFmtPageDesc );
delete pFmtPageDesc;
}
}
sal_Bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
{
// resolve, if not already done
if (! bDataStyleIsResolved)
{
// get the format key
sal_Int32 nFormat =
GetImport().GetTextImport()->GetDataStyleKey(sDataStyleName);
// if the key is valid, insert Item into ItemSet
if( -1 != nFormat )
{
if( !pItemSet )
{
SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
SfxItemPool& rItemPool = pDoc->GetAttrPool();
pItemSet = new SfxItemSet( rItemPool, aTableBoxSetRange );
}
SwTblBoxNumFormat aNumFormatItem(nFormat);
pItemSet->Put(aNumFormatItem);
}
// now resolved
bDataStyleIsResolved = sal_True;
return sal_True;
}
else
{
// was already resolved; nothing to do
return sal_False;
}
}
// ---------------------------------------------------------------------
//
class SwXMLStylesContext_Impl : public SvXMLStylesContext
{
SwXMLItemSetStyleContext_Impl *GetSwStyle( sal_uInt16 i ) const;
SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
const SwXMLImport& GetSwImport() const
{ return (const SwXMLImport&)GetImport(); }
protected:
virtual SvXMLStyleContext *CreateStyleStyleChildContext( sal_uInt16 nFamily,
sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext(
sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
// HACK
virtual UniReference < SvXMLImportPropertyMapper > GetImportPropertyMapper(
sal_uInt16 nFamily ) const;
virtual uno::Reference < container::XNameContainer >
GetStylesContainer( sal_uInt16 nFamily ) const;
virtual ::rtl::OUString GetServiceName( sal_uInt16 nFamily ) const;
// HACK
public:
TYPEINFO();
SwXMLStylesContext_Impl(
SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName ,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
sal_Bool bAuto );
virtual ~SwXMLStylesContext_Impl();
virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const;
virtual void EndElement();
};
TYPEINIT1( SwXMLStylesContext_Impl, SvXMLStylesContext );
inline SwXMLItemSetStyleContext_Impl *SwXMLStylesContext_Impl::GetSwStyle(
sal_uInt16 i ) const
{
return PTR_CAST( SwXMLItemSetStyleContext_Impl, GetStyle( i ) );
}
SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLStyleContext *pStyle = 0;
switch( nFamily )
{
case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
pStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix,
rLocalName, xAttrList, nFamily, *this );
break;
case XML_STYLE_FAMILY_TABLE_TABLE:
case XML_STYLE_FAMILY_TABLE_COLUMN:
case XML_STYLE_FAMILY_TABLE_ROW:
case XML_STYLE_FAMILY_TABLE_CELL:
pStyle = new SwXMLItemSetStyleContext_Impl( GetSwImport(), nPrefix,
rLocalName, xAttrList, *this, nFamily );
break;
case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
// As long as there are no element items, we can use the text
// style class.
pStyle = new XMLTextShapeStyleContext( GetImport(), nPrefix,
rLocalName, xAttrList, *this, nFamily );
break;
default:
pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily,
nPrefix,
rLocalName,
xAttrList );
break;
}
return pStyle;
}
SvXMLStyleContext *SwXMLStylesContext_Impl::CreateDefaultStyleStyleChildContext(
sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLStyleContext *pStyle = 0;
switch( nFamily )
{
case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
case XML_STYLE_FAMILY_TABLE_TABLE:
case XML_STYLE_FAMILY_TABLE_ROW:
pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
xAttrList, *this, nFamily,
sal_True );
break;
case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
// There are no writer specific defaults for graphic styles!
pStyle = new XMLGraphicsDefaultStyle( GetImport(), nPrefix,
rLocalName, xAttrList, *this );
break;
default:
pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
nPrefix,
rLocalName,
xAttrList );
break;
}
return pStyle;
}
SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
SwXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
sal_Bool bAuto ) :
SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList, bAuto )
{
}
SwXMLStylesContext_Impl::~SwXMLStylesContext_Impl()
{
}
sal_Bool SwXMLStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily ) const
{
const SwXMLImport& rSwImport = GetSwImport();
sal_uInt16 nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
sal_Bool bIns = sal_True;
switch( nFamily )
{
case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PARA) != 0;
break;
case XML_STYLE_FAMILY_TEXT_TEXT:
bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_CHAR) != 0;
break;
case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_FRAME) != 0;
break;
case XML_STYLE_FAMILY_TEXT_LIST:
bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PSEUDO) != 0;
break;
case XML_STYLE_FAMILY_TEXT_OUTLINE:
case XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG:
case XML_STYLE_FAMILY_TEXT_ENDNOTECONFIG:
case XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG:
case XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG:
bIns = !(rSwImport.IsInsertMode() || rSwImport.IsStylesOnlyMode() ||
rSwImport.IsBlockMode());
break;
default:
bIns = SvXMLStylesContext::InsertStyleFamily( nFamily );
break;
}
return bIns;
}
UniReference < SvXMLImportPropertyMapper > SwXMLStylesContext_Impl::GetImportPropertyMapper(
sal_uInt16 nFamily ) const
{
UniReference < SvXMLImportPropertyMapper > xMapper;
if( nFamily == XML_STYLE_FAMILY_TABLE_TABLE )
xMapper = XMLTextImportHelper::CreateTableDefaultExtPropMapper(
const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
else if( nFamily == XML_STYLE_FAMILY_TABLE_ROW )
xMapper = XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
const_cast<SwXMLStylesContext_Impl*>( this )->GetImport() );
else
xMapper = SvXMLStylesContext::GetImportPropertyMapper( nFamily );
return xMapper;
}
uno::Reference < container::XNameContainer > SwXMLStylesContext_Impl::GetStylesContainer(
sal_uInt16 nFamily ) const
{
uno::Reference < container::XNameContainer > xStyles;
if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
xStyles = ((SvXMLImport *)&GetImport())->GetTextImport()->GetFrameStyles();
else
xStyles = SvXMLStylesContext::GetStylesContainer( nFamily );
return xStyles;
}
OUString SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily ) const
{
String sServiceName;
if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
sServiceName = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.FrameStyle") );
else
sServiceName = SvXMLStylesContext::GetServiceName( nFamily );
return sServiceName;
}
void SwXMLStylesContext_Impl::EndElement()
{
GetSwImport().InsertStyles( IsAutomaticStyle() );
}
// ---------------------------------------------------------------------
//
class SwXMLMasterStylesContext_Impl : public XMLTextMasterStylesContext
{
protected:
virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const;
SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
const SwXMLImport& GetSwImport() const
{ return (const SwXMLImport&)GetImport(); }
public:
TYPEINFO();
SwXMLMasterStylesContext_Impl(
SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName ,
const uno::Reference< xml::sax::XAttributeList > & xAttrList );
virtual ~SwXMLMasterStylesContext_Impl();
virtual void EndElement();
};
TYPEINIT1( SwXMLMasterStylesContext_Impl, XMLTextMasterStylesContext );
SwXMLMasterStylesContext_Impl::SwXMLMasterStylesContext_Impl(
SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName ,
const uno::Reference< xml::sax::XAttributeList > & xAttrList ) :
XMLTextMasterStylesContext( rImport, nPrfx, rLName, xAttrList )
{
}
SwXMLMasterStylesContext_Impl::~SwXMLMasterStylesContext_Impl()
{
}
sal_Bool SwXMLMasterStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily ) const
{
sal_Bool bIns;
const SwXMLImport& rSwImport = GetSwImport();
sal_uInt16 nStyleFamilyMask = rSwImport.GetStyleFamilyMask();
if( XML_STYLE_FAMILY_MASTER_PAGE == nFamily )
bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PAGE) != 0;
else
bIns = XMLTextMasterStylesContext::InsertStyleFamily( nFamily );
return bIns;
}
void SwXMLMasterStylesContext_Impl::EndElement()
{
FinishStyles( !GetSwImport().IsInsertMode() );
GetSwImport().FinishStyles();
}
// ---------------------------------------------------------------------
SvXMLImportContext *SwXMLImport::CreateStylesContext(
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList,
sal_Bool bAuto )
{
SvXMLStylesContext *pContext =
new SwXMLStylesContext_Impl( *this, XML_NAMESPACE_OFFICE, rLocalName,
xAttrList, bAuto );
if( bAuto )
SetAutoStyles( pContext );
else
SetStyles( pContext );
return pContext;
}
SvXMLImportContext *SwXMLImport::CreateMasterStylesContext(
const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLStylesContext *pContext =
new SwXMLMasterStylesContext_Impl( *this, XML_NAMESPACE_OFFICE, rLocalName,
xAttrList );
SetMasterStyles( pContext );
return pContext;
}
void SwXMLImport::InsertStyles( sal_Bool bAuto )
{
if( bAuto && GetAutoStyles() )
GetAutoStyles()->CopyAutoStylesToDoc();
if( !bAuto && GetStyles() )
GetStyles()->CopyStylesToDoc( !IsInsertMode(), sal_False );
}
void SwXMLImport::FinishStyles()
{
if( GetStyles() )
GetStyles()->FinishStyles( !IsInsertMode() );
}
void SwXMLImport::UpdateTxtCollConditions( SwDoc *pDoc )
{
if( !pDoc )
pDoc = SwImport::GetDocFromXMLImport( *this );
const SwTxtFmtColls& rColls = *pDoc->GetTxtFmtColls();
sal_uInt16 nCount = rColls.Count();
for( sal_uInt16 i=0; i < nCount; i++ )
{
SwTxtFmtColl *pColl = rColls[i];
if( pColl && RES_CONDTXTFMTCOLL == pColl->Which() )
{
const SwFmtCollConditions& rConditions =
((const SwConditionTxtFmtColl *)pColl)->GetCondColls();
sal_Bool bSendModify = sal_False;
for( sal_uInt16 j=0; j < rConditions.Count() && !bSendModify; j++ )
{
const SwCollCondition& rCond = *rConditions[j];
switch( rCond.GetCondition() )
{
case PARA_IN_TABLEHEAD:
case PARA_IN_TABLEBODY:
case PARA_IN_FOOTER:
case PARA_IN_HEADER:
bSendModify = sal_True;
break;
}
}
if( bSendModify )
{
SwCondCollCondChg aMsg( pColl );
pColl->ModifyNotification( &aMsg, &aMsg );
}
}
}
}
sal_Bool SwXMLImport::FindAutomaticStyle(
sal_uInt16 nFamily,
const OUString& rName,
const SfxItemSet **ppItemSet,
OUString *pParent ) const
{
SwXMLItemSetStyleContext_Impl *pStyle = 0;
if( GetAutoStyles() )
{
pStyle = PTR_CAST( SwXMLItemSetStyleContext_Impl,
GetAutoStyles()->
FindStyleChildContext( nFamily, rName,
sal_True ) );
if( pStyle )
{
if( ppItemSet )
{
if( XML_STYLE_FAMILY_TABLE_TABLE == pStyle->GetFamily() &&
pStyle->HasMasterPageName() &&
!pStyle->IsPageDescConnected() )
pStyle->ConnectPageDesc();
(*ppItemSet) = pStyle->GetItemSet();
// resolve data style name late
if( XML_STYLE_FAMILY_TABLE_CELL == pStyle->GetFamily() &&
pStyle->ResolveDataStyleName() )
{
(*ppItemSet) = pStyle->GetItemSet();
}
}
if( pParent )
*pParent = pStyle->GetParentName();
}
}
return pStyle != 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|