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
|
/* -*- 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/uri.hxx>
#include <svl/urihelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <editeng/adjitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/brkitem.hxx>
#include <svtools/htmltokn.h>
#include <svtools/htmlkywd.hxx>
#include <sfx2/linkmgr.hxx>
#include "hintids.hxx"
#include <fmtornt.hxx>
#include <fmthdft.hxx>
#include <fmtcntnt.hxx>
#include <fmtfsize.hxx>
#include <fmtclds.hxx>
#include <fmtanchr.hxx>
#include <fmtpdsc.hxx>
#include <fmtsrnd.hxx>
#include <fmtflcnt.hxx>
#include "frmatr.hxx"
#include "doc.hxx"
#include "pam.hxx"
#include "ndtxt.hxx"
#include "shellio.hxx"
#include "section.hxx"
#include "poolfmt.hxx"
#include "pagedesc.hxx"
#include "swtable.hxx"
#include "viewsh.hxx"
#include "swcss1.hxx"
#include "swhtml.hxx"
#define CONTEXT_FLAGS_MULTICOL (HTML_CNTXT_STRIP_PARA | \
HTML_CNTXT_KEEP_NUMRULE | \
HTML_CNTXT_KEEP_ATTRS)
#define CONTEXT_FLAGS_HDRFTR (CONTEXT_FLAGS_MULTICOL)
#define CONTEXT_FLAGS_FTN (CONTEXT_FLAGS_MULTICOL)
using namespace ::com::sun::star;
void SwHTMLParser::NewDivision( int nToken )
{
String aId, aHRef, aStyle, aClass, aLang, aDir;
SvxAdjust eAdjust = HTML_CENTER_ON==nToken ? SVX_ADJUST_CENTER
: SVX_ADJUST_END;
sal_Bool bHeader=sal_False, bFooter=sal_False;
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_ALIGN:
if( HTML_DIVISION_ON==nToken )
eAdjust = (SvxAdjust)rOption.GetEnum( aHTMLPAlignTable,
static_cast< sal_uInt16 >(eAdjust) );
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_LANG:
aLang = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
case HTML_O_HREF:
aHRef = rOption.GetString();
break;
case HTML_O_TYPE:
{
const String& rType = rOption.GetString();
if( rType.EqualsIgnoreCaseAscii( "HEADER" ) )
bHeader = sal_True;
else if( rType.EqualsIgnoreCaseAscii( "FOOTER" ) )
bFooter = sal_True;
}
}
}
sal_Bool bAppended = sal_False;
if( pPam->GetPoint()->nContent.GetIndex() )
{
AppendTxtNode( bHeader||bFooter||aId.Len()||aHRef.Len() ? AM_NORMAL
: AM_NOSPACE );
bAppended = sal_True;
}
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( static_cast< sal_uInt16 >(nToken) );
sal_Bool bStyleParsed = sal_False, bPositioned = sal_False;
SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
{
bStyleParsed = ParseStyleOptions( aStyle, aId, aClass,
aItemSet, aPropInfo, &aLang, &aDir );
if( bStyleParsed )
{
bPositioned = HTML_DIVISION_ON == nToken && aClass.Len() &&
CreateContainer( aClass, aItemSet, aPropInfo,
pCntxt );
if( !bPositioned )
bPositioned = DoPositioning( aItemSet, aPropInfo, pCntxt );
}
}
if( !bPositioned && (bHeader || bFooter) && IsNewDoc() )
{
SwPageDesc *pPageDesc = pCSS1Parser->GetMasterPageDesc();
SwFrmFmt& rPageFmt = pPageDesc->GetMaster();
SwFrmFmt *pHdFtFmt;
sal_Bool bNew = sal_False;
sal_uInt16 nFlags = CONTEXT_FLAGS_HDRFTR;
if( bHeader )
{
pHdFtFmt = (SwFrmFmt*)rPageFmt.GetHeader().GetHeaderFmt();
if( !pHdFtFmt )
{
// noch keine Header, dann erzeuge einen.
rPageFmt.SetFmtAttr( SwFmtHeader( sal_True ));
pHdFtFmt = (SwFrmFmt*)rPageFmt.GetHeader().GetHeaderFmt();
bNew = sal_True;
}
nFlags |= HTML_CNTXT_HEADER_DIST;
}
else
{
pHdFtFmt = (SwFrmFmt*)rPageFmt.GetFooter().GetFooterFmt();
if( !pHdFtFmt )
{
// noch keine Footer, dann erzeuge einen.
rPageFmt.SetFmtAttr( SwFmtFooter( sal_True ));
pHdFtFmt = (SwFrmFmt*)rPageFmt.GetFooter().GetFooterFmt();
bNew = sal_True;
}
nFlags |= HTML_CNTXT_FOOTER_DIST;
}
const SwFmtCntnt& rFlyCntnt = pHdFtFmt->GetCntnt();
const SwNodeIndex& rCntntStIdx = *rFlyCntnt.GetCntntIdx();
SwCntntNode *pCNd;
if( bNew )
{
pCNd = pDoc->GetNodes()[rCntntStIdx.GetIndex()+1]
->GetCntntNode();
}
else
{
// Einen neuen Node zu Beginn der Section anlegen
SwNodeIndex aSttIdx( rCntntStIdx, 1 );
pCNd = pDoc->GetNodes().MakeTxtNode( aSttIdx,
pCSS1Parser->GetTxtCollFromPool(RES_POOLCOLL_TEXT));
// Den bisherigen Inhalt der Section loeschen
SwPaM aDelPam( aSttIdx );
aDelPam.SetMark();
const SwStartNode *pStNd =
(const SwStartNode *) &rCntntStIdx.GetNode();
aDelPam.GetPoint()->nNode = pStNd->EndOfSectionIndex() - 1;
pDoc->DelFullPara( aDelPam );
// Die Seitenvorlage aktualisieren
for( sal_uInt16 i=0; i < pDoc->GetPageDescCnt(); i++ )
{
if( RES_POOLPAGE_HTML==const_cast<const SwDoc *>(pDoc)
->GetPageDesc(i).GetPoolFmtId() )
{
pDoc->ChgPageDesc( i, *pPageDesc );
break;
}
}
}
SwPosition aNewPos( SwNodeIndex( rCntntStIdx, 1 ), SwIndex( pCNd, 0 ) );
SaveDocContext( pCntxt, nFlags, &aNewPos );
}
else if( !bPositioned && aId.Len() > 9 &&
('s' == aId.GetChar(0) || 'S' == aId.GetChar(0) ) &&
('d' == aId.GetChar(1) || 'D' == aId.GetChar(1) ) )
{
sal_Bool bEndNote = sal_False, bFootNote = sal_False;
if( aId.CompareIgnoreCaseToAscii( OOO_STRING_SVTOOLS_HTML_sdendnote, 9 ) == COMPARE_EQUAL )
bEndNote = sal_True;
else if( aId.CompareIgnoreCaseToAscii( OOO_STRING_SVTOOLS_HTML_sdfootnote, 10 ) == COMPARE_EQUAL )
bFootNote = sal_True;
if( bFootNote || bEndNote )
{
SwNodeIndex *pStartNdIdx = GetFootEndNoteSection( aId );
if( pStartNdIdx )
{
SwCntntNode *pCNd =
pDoc->GetNodes()[pStartNdIdx->GetIndex()+1]->GetCntntNode();
SwNodeIndex aTmpSwNodeIndex = SwNodeIndex(*pCNd);
SwPosition aNewPos( aTmpSwNodeIndex, SwIndex( pCNd, 0 ) );
SaveDocContext( pCntxt, CONTEXT_FLAGS_FTN, &aNewPos );
aId = aPropInfo.aId = aEmptyStr;
}
}
}
// Bereiche fuegen wir in Rahmen nur dann ein, wenn der Bereich gelinkt ist.
if( (aId.Len() && !bPositioned) || aHRef.Len() )
{
// Bereich einfuegen (muss vor dem Setzten von Attributen erfolgen,
// weil die Section vor der PaM-Position eingefuegt.
// wenn wir im ersten Node einer Section stehen, wir die neue
// Section nicht in der aktuellen, sondern vor der aktuellen
// Section eingefuegt. Deshalb muessen wir dann einen Node
// einfuegen. UND IN LOESCHEN!!!
if( !bAppended )
{
SwNodeIndex aPrvNdIdx( pPam->GetPoint()->nNode, -1 );
if (aPrvNdIdx.GetNode().IsSectionNode())
{
AppendTxtNode();
bAppended = sal_True;
}
}
_HTMLAttrs *pPostIts = bAppended ? 0 : new _HTMLAttrs;
SetAttr( sal_True, sal_True, pPostIts );
// Namen der Section eindeutig machen
String aName( pDoc->GetUniqueSectionName( aId.Len() ? &aId : 0 ) );
if( aHRef.Len() )
{
sal_Unicode cDelim = 255U;
String aURL;
xub_StrLen nPos = aHRef.SearchBackward( cDelim );
xub_StrLen nPos2 = STRING_NOTFOUND;
if( STRING_NOTFOUND != nPos )
{
nPos2 = aHRef.SearchBackward( cDelim, nPos );
if( STRING_NOTFOUND != nPos2 )
{
xub_StrLen nTmp = nPos;
nPos = nPos2;
nPos2 = nTmp;
}
}
if( STRING_NOTFOUND == nPos )
{
aURL = URIHelper::SmartRel2Abs(INetURLObject( sBaseURL ), aHRef, Link(), false);
}
else
{
aURL = URIHelper::SmartRel2Abs(INetURLObject( sBaseURL ), aHRef.Copy( 0, nPos ), Link(), false );
aURL += sfx2::cTokenSeperator;
if( STRING_NOTFOUND == nPos2 )
{
aURL += aHRef.Copy( nPos+1 );
}
else
{
aURL += aHRef.Copy( nPos+1, nPos2 - (nPos+1) );
aURL += sfx2::cTokenSeperator;
aURL += String(rtl::Uri::decode( aHRef.Copy( nPos2+1 ),
rtl_UriDecodeWithCharset,
RTL_TEXTENCODING_ISO_8859_1 ));
}
}
aHRef = aURL;
}
SwSectionData aSection( (aHRef.Len()) ? FILE_LINK_SECTION
: CONTENT_SECTION, aName );
if( aHRef.Len() )
{
aSection.SetLinkFileName( aHRef );
aSection.SetProtectFlag(true);
}
SfxItemSet aFrmItemSet( pDoc->GetAttrPool(),
RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
if( !IsNewDoc() )
Reader::ResetFrmFmtAttrs(aFrmItemSet );
const SfxPoolItem *pItem;
if( SFX_ITEM_SET == aItemSet.GetItemState( RES_BACKGROUND, sal_False,
&pItem ) )
{
aFrmItemSet.Put( *pItem );
aItemSet.ClearItem( RES_BACKGROUND );
}
if( SFX_ITEM_SET == aItemSet.GetItemState( RES_FRAMEDIR, sal_False,
&pItem ) )
{
aFrmItemSet.Put( *pItem );
aItemSet.ClearItem( RES_FRAMEDIR );
}
pDoc->InsertSwSection( *pPam, aSection, 0, &aFrmItemSet, false );
// ggfs. einen Bereich anspringen
if( JUMPTO_REGION == eJumpTo && aName == sJmpMark )
{
bChkJumpMark = sal_True;
eJumpTo = JUMPTO_NONE;
}
SwTxtNode* pOldTxtNd =
(bAppended) ? 0 : pPam->GetPoint()->nNode.GetNode().GetTxtNode();
pPam->Move( fnMoveBackward );
// PageDesc- und SwFmtBreak Attribute vom aktuellen Node in den
// (ersten) Node des Bereich verschieben.
if( pOldTxtNd )
MovePageDescAttrs( pOldTxtNd, pPam->GetPoint()->nNode.GetIndex(),
sal_True );
if( pPostIts )
{
// noch vorhandene PostIts in den ersten Absatz
// der Tabelle setzen
InsertAttrs( *pPostIts );
delete pPostIts;
pPostIts = 0;
}
pCntxt->SetSpansSection( sal_True );
// keine text::Bookmarks mit dem gleichen Namen wie Bereiche einfuegen
if( aPropInfo.aId.Len() && aPropInfo.aId==aName )
aPropInfo.aId.Erase();
}
else
{
pCntxt->SetAppendMode( AM_NOSPACE );
}
if( SVX_ADJUST_END != eAdjust )
{
InsertAttr( &aAttrTab.pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST), pCntxt );
}
// Style parsen
if( bStyleParsed )
InsertAttrs( aItemSet, aPropInfo, pCntxt, sal_True );
PushContext( pCntxt );
}
void SwHTMLParser::EndDivision( int /*nToken*/ )
{
// Stack-Eintrag zu dem Token suchen (weil wir noch den Div-Stack
// haben unterscheiden wir erst einmal nicht zwischen DIV und CENTER
_HTMLAttrContext *pCntxt = 0;
sal_uInt16 nPos = aContexts.Count();
while( !pCntxt && nPos>nContextStMin )
{
switch( aContexts[--nPos]->GetToken() )
{
case HTML_CENTER_ON:
case HTML_DIVISION_ON:
pCntxt = aContexts[nPos];
aContexts.Remove( nPos, 1 );
break;
}
}
if( pCntxt )
{
// Attribute beenden
EndContext( pCntxt );
SetAttr(); // Absatz-Atts wegen JavaScript moeglichst schnell setzen
delete pCntxt;
}
}
void SwHTMLParser::FixHeaderFooterDistance( sal_Bool bHeader,
const SwPosition *pOldPos )
{
SwPageDesc *pPageDesc = pCSS1Parser->GetMasterPageDesc();
SwFrmFmt& rPageFmt = pPageDesc->GetMaster();
SwFrmFmt *pHdFtFmt =
bHeader ? (SwFrmFmt*)rPageFmt.GetHeader().GetHeaderFmt()
: (SwFrmFmt*)rPageFmt.GetFooter().GetFooterFmt();
OSL_ENSURE( pHdFtFmt, "Doch keine Kopf- oder Fusszeile" );
const SwFmtCntnt& rFlyCntnt = pHdFtFmt->GetCntnt();
const SwNodeIndex& rCntntStIdx = *rFlyCntnt.GetCntntIdx();
sal_uLong nPrvNxtIdx;
if( bHeader )
{
nPrvNxtIdx = rCntntStIdx.GetNode().EndOfSectionIndex()-1;
}
else
{
nPrvNxtIdx = pOldPos->nNode.GetIndex() - 1;
}
sal_uInt16 nSpace = 0;
SwTxtNode *pTxtNode = pDoc->GetNodes()[nPrvNxtIdx]->GetTxtNode();
if( pTxtNode )
{
const SvxULSpaceItem& rULSpace =
((const SvxULSpaceItem&)pTxtNode
->SwCntntNode::GetAttr( RES_UL_SPACE ));
// Der untere Absatz-Abstand wird zum Abstand zur
// Kopf- oder Fusszeile
nSpace = rULSpace.GetLower();
// und anschliessend auf einen vernuenftigen Wert
// gesetzt
const SvxULSpaceItem& rCollULSpace =
pTxtNode->GetAnyFmtColl().GetULSpace();
if( rCollULSpace.GetUpper() == rULSpace.GetUpper() )
pTxtNode->ResetAttr( RES_UL_SPACE );
else
pTxtNode->SetAttr(
SvxULSpaceItem( rULSpace.GetUpper(),
rCollULSpace.GetLower(), RES_UL_SPACE ) );
}
if( bHeader )
{
nPrvNxtIdx = pOldPos->nNode.GetIndex();
}
else
{
nPrvNxtIdx = rCntntStIdx.GetIndex() + 1;
}
pTxtNode = pDoc->GetNodes()[nPrvNxtIdx]
->GetTxtNode();
if( pTxtNode )
{
const SvxULSpaceItem& rULSpace =
((const SvxULSpaceItem&)pTxtNode
->SwCntntNode::GetAttr( RES_UL_SPACE ));
// Der obere Absatz-Abstand wird zum Abstand zur
// Kopf- oder Fusszeile, wenn er groesser ist als
// der untere vom Absatz davor
if( rULSpace.GetUpper() > nSpace )
nSpace = rULSpace.GetUpper();
// und anschliessend auf einen vernuenftigen Wert gesetzt
const SvxULSpaceItem& rCollULSpace =
pTxtNode->GetAnyFmtColl().GetULSpace();
if( rCollULSpace.GetLower() == rULSpace.GetLower() )
pTxtNode->ResetAttr( RES_UL_SPACE );
else
pTxtNode->SetAttr(
SvxULSpaceItem( rCollULSpace.GetUpper(),
rULSpace.GetLower(), RES_UL_SPACE ) );
}
SvxULSpaceItem aULSpace( RES_UL_SPACE );
if( bHeader )
aULSpace.SetLower( nSpace );
else
aULSpace.SetUpper( nSpace );
pHdFtFmt->SetFmtAttr( aULSpace );
}
sal_Bool SwHTMLParser::EndSection( sal_Bool bLFStripped )
{
SwEndNode *pEndNd = pDoc->GetNodes()[pPam->GetPoint()->nNode.GetIndex()+1]
->GetEndNode();
if( pEndNd && pEndNd->StartOfSectionNode()->IsSectionNode() )
{
// den Bereich beenden
if( !bLFStripped )
StripTrailingPara();
pPam->Move( fnMoveForward );
return sal_True;
}
OSL_ENSURE( !this, "Falsche PaM Position Beenden eines Bereichs" );
return sal_False;
}
sal_Bool SwHTMLParser::EndSections( sal_Bool bLFStripped )
{
sal_Bool bSectionClosed = sal_False;
sal_uInt16 nPos = aContexts.Count();
while( nPos>nContextStMin )
{
_HTMLAttrContext *pCntxt = aContexts[--nPos];
if( pCntxt->GetSpansSection() && EndSection( bLFStripped ) )
{
bSectionClosed = sal_True;
pCntxt->SetSpansSection( sal_False );
bLFStripped = sal_False;
}
}
return bSectionClosed;
}
void SwHTMLParser::NewMultiCol()
{
String aId, aStyle, aClass, aLang, aDir;
long nWidth = 100;
sal_uInt16 nCols = 0, nGutter = 10;
sal_Bool bPrcWidth = sal_True;
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_LANG:
aLang = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
case HTML_O_COLS:
nCols = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_WIDTH:
nWidth = rOption.GetNumber();
bPrcWidth = (rOption.GetString().Search('%') != STRING_NOTFOUND);
if( bPrcWidth && nWidth>100 )
nWidth = 100;
break;
case HTML_O_GUTTER:
nGutter = (sal_uInt16)rOption.GetNumber();
break;
}
}
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_MULTICOL_ON );
//.is the multicol elememt contained in a container? That may be the
// case for 5.0 documents.
sal_Bool bInCntnr = sal_False;
sal_uInt16 i = aContexts.Count();
while( !bInCntnr && i > nContextStMin )
bInCntnr = 0 != aContexts[--i]->GetFrmItemSet();
// Parse style sheets, but don't position anything by now.
sal_Bool bStyleParsed = sal_False;
SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
bStyleParsed = ParseStyleOptions( aStyle, aId, aClass,
aItemSet, aPropInfo, &aLang, &aDir );
// Calculate width.
sal_uInt8 nPrcWidth = bPrcWidth ? (sal_uInt8)nWidth : 0;
sal_uInt16 nTwipWidth = 0;
if( !bPrcWidth && nWidth && Application::GetDefaultDevice() )
{
nTwipWidth = (sal_uInt16)Application::GetDefaultDevice()
->PixelToLogic( Size(nWidth, 0),
MapMode(MAP_TWIP) ).Width();
}
if( !nPrcWidth && nTwipWidth < MINFLY )
nTwipWidth = MINFLY;
// Do positioning.
sal_Bool bPositioned = sal_False;
if( bInCntnr || pCSS1Parser->MayBePositioned( aPropInfo, sal_True ) )
{
SfxItemSet aFrmItemSet( pDoc->GetAttrPool(),
RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
if( !IsNewDoc() )
Reader::ResetFrmFmtAttrs(aFrmItemSet );
SetAnchorAndAdjustment( text::VertOrientation::NONE, text::HoriOrientation::NONE, aItemSet, aPropInfo,
aFrmItemSet );
// The width is either the WIDTH attribute's value or contained
// in some style option.
SetVarSize( aItemSet, aPropInfo, aFrmItemSet, nTwipWidth, nPrcWidth );
SetSpace( Size(0,0), aItemSet, aPropInfo, aFrmItemSet );
// Set some other frame attributes. If the background is set, its
// it will be cleared here. That for, it won't be set at the section,
// too.
SetFrmFmtAttrs( aItemSet, aPropInfo,
HTML_FF_BOX|HTML_FF_BACKGROUND|HTML_FF_PADDING|HTML_FF_DIRECTION,
aFrmItemSet );
// Insert fly frame. If the are columns, the fly frame's name is not
// the sections name but a generated one.
String aFlyName( aEmptyStr );
if( nCols < 2 )
{
aFlyName = aId;
aPropInfo.aId.Erase();
}
InsertFlyFrame( aFrmItemSet, pCntxt, aFlyName, CONTEXT_FLAGS_ABSPOS );
pCntxt->SetPopStack( sal_True );
bPositioned = sal_True;
}
sal_Bool bAppended = sal_False;
if( !bPositioned )
{
if( pPam->GetPoint()->nContent.GetIndex() )
{
AppendTxtNode( AM_SPACE );
bAppended = sal_True;
}
else
{
AddParSpace();
}
}
// If there are less then 2 columns, no section is inserted.
if( nCols >= 2 )
{
if( !bAppended )
{
// If the pam is at the start of a section, a additional text
// node must be inserted. Otherwise, the new section will be
// inserted in front of the old one.
SwNodeIndex aPrvNdIdx( pPam->GetPoint()->nNode, -1 );
if (aPrvNdIdx.GetNode().IsSectionNode())
{
AppendTxtNode();
bAppended = sal_True;
}
}
_HTMLAttrs *pPostIts = bAppended ? 0 : new _HTMLAttrs;
SetAttr( sal_True, sal_True, pPostIts );
// Make section name unique.
String aName( pDoc->GetUniqueSectionName( aId.Len() ? &aId : 0 ) );
SwSectionData aSection( CONTENT_SECTION, aName );
SfxItemSet aFrmItemSet( pDoc->GetAttrPool(),
RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
if( !IsNewDoc() )
Reader::ResetFrmFmtAttrs(aFrmItemSet );
if( nGutter && Application::GetDefaultDevice() )
{
nGutter = (sal_uInt16)Application::GetDefaultDevice()
->PixelToLogic( Size(nGutter, 0),
MapMode(MAP_TWIP) ).Width();
}
SwFmtCol aFmtCol;
#ifndef WIDTH_SUPPORTED_BY_SECTIONS
nPrcWidth = 100;
#endif
aFmtCol.Init( nCols, nGutter, nPrcWidth ? USHRT_MAX : nTwipWidth );
aFrmItemSet.Put( aFmtCol );
const SfxPoolItem *pItem;
if( SFX_ITEM_SET == aItemSet.GetItemState( RES_BACKGROUND, sal_False,
&pItem ) )
{
aFrmItemSet.Put( *pItem );
aItemSet.ClearItem( RES_BACKGROUND );
}
if( SFX_ITEM_SET == aItemSet.GetItemState( RES_FRAMEDIR, sal_False,
&pItem ) )
{
aFrmItemSet.Put( *pItem );
aItemSet.ClearItem( RES_FRAMEDIR );
}
pDoc->InsertSwSection( *pPam, aSection, 0, &aFrmItemSet, false );
// Jump to section, if this is requested.
if( JUMPTO_REGION == eJumpTo && aName == sJmpMark )
{
bChkJumpMark = sal_True;
eJumpTo = JUMPTO_NONE;
}
SwTxtNode* pOldTxtNd =
(bAppended) ? 0 : pPam->GetPoint()->nNode.GetNode().GetTxtNode();
pPam->Move( fnMoveBackward );
// Move PageDesc and SwFmtBreak attributes of the current node
// to the section's first node.
if( pOldTxtNd )
MovePageDescAttrs( pOldTxtNd, pPam->GetPoint()->nNode.GetIndex(),
sal_True );
if( pPostIts )
{
// Move pending PostIts into the section.
InsertAttrs( *pPostIts );
delete pPostIts;
pPostIts = 0;
}
pCntxt->SetSpansSection( sal_True );
// Insert a bookmark if its name differs from the section's name only.
if( aPropInfo.aId.Len() && aPropInfo.aId==aName )
aPropInfo.aId.Erase();
}
// Additional attributes must be set as hard ones.
if( bStyleParsed )
InsertAttrs( aItemSet, aPropInfo, pCntxt, sal_True );
PushContext( pCntxt );
}
void SwHTMLParser::InsertFlyFrame( const SfxItemSet& rItemSet,
_HTMLAttrContext *pCntxt,
const String& rName,
sal_uInt16 nFlags )
{
RndStdIds eAnchorId =
((const SwFmtAnchor&)rItemSet.Get( RES_ANCHOR )).GetAnchorId();
// Den Rahmen anlegen
SwFlyFrmFmt* pFlyFmt = pDoc->MakeFlySection( eAnchorId, pPam->GetPoint(),
&rItemSet );
// Ggf. den Namen setzen
if( rName.Len() )
pFlyFmt->SetName( rName );
RegisterFlyFrm( pFlyFmt );
const SwFmtCntnt& rFlyCntnt = pFlyFmt->GetCntnt();
const SwNodeIndex& rFlyCntIdx = *rFlyCntnt.GetCntntIdx();
SwCntntNode *pCNd = pDoc->GetNodes()[rFlyCntIdx.GetIndex()+1]
->GetCntntNode();
SwPosition aNewPos( SwNodeIndex( rFlyCntIdx, 1 ), SwIndex( pCNd, 0 ) );
SaveDocContext( pCntxt, nFlags, &aNewPos );
}
void SwHTMLParser::MovePageDescAttrs( SwNode *pSrcNd,
sal_uLong nDestIdx,
sal_Bool bFmtBreak )
{
SwCntntNode* pDestCntntNd =
pDoc->GetNodes()[nDestIdx]->GetCntntNode();
OSL_ENSURE( pDestCntntNd, "Wieso ist das Ziel kein Content-Node?" );
if( pSrcNd->IsCntntNode() )
{
SwCntntNode* pSrcCntntNd = pSrcNd->GetCntntNode();
const SfxPoolItem* pItem;
if( SFX_ITEM_SET == pSrcCntntNd->GetSwAttrSet()
.GetItemState( RES_PAGEDESC, sal_False, &pItem ) &&
((SwFmtPageDesc *)pItem)->GetPageDesc() )
{
pDestCntntNd->SetAttr( *pItem );
pSrcCntntNd->ResetAttr( RES_PAGEDESC );
}
if( SFX_ITEM_SET == pSrcCntntNd->GetSwAttrSet()
.GetItemState( RES_BREAK, sal_False, &pItem ) )
{
switch( ((SvxFmtBreakItem *)pItem)->GetBreak() )
{
case SVX_BREAK_PAGE_BEFORE:
case SVX_BREAK_PAGE_AFTER:
case SVX_BREAK_PAGE_BOTH:
if( bFmtBreak )
pDestCntntNd->SetAttr( *pItem );
pSrcCntntNd->ResetAttr( RES_BREAK );
default:
;
}
}
}
else if( pSrcNd->IsTableNode() )
{
SwFrmFmt *pFrmFmt = pSrcNd->GetTableNode()->GetTable().GetFrmFmt();
const SfxPoolItem* pItem;
if( SFX_ITEM_SET == pFrmFmt->GetAttrSet().
GetItemState( RES_PAGEDESC, sal_False, &pItem ) )
{
pDestCntntNd->SetAttr( *pItem );
pFrmFmt->ResetFmtAttr( RES_PAGEDESC );
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|