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
|
/* -*- 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 <ftnidx.hxx>
#include <rootfrm.hxx>
#include <txtftn.hxx>
#include <fmtftn.hxx>
#include <pam.hxx>
#include <pagedesc.hxx>
#include <charfmt.hxx>
#include <UndoAttribute.hxx>
#include <hints.hxx>
#include <rolbck.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <ndtxt.hxx>
#include <poolfmt.hxx>
#include <ftninfo.hxx>
/*********************** SwFtnInfo ***************************/
SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo)
{
if( rInfo.GetFtnTxtColl() )
rInfo.GetFtnTxtColl()->Add(this);
else if ( GetRegisteredIn())
GetRegisteredInNonConst()->Remove(this);
if ( rInfo.aPageDescDep.GetRegisteredIn() )
((SwModify*)rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep );
else if ( aPageDescDep.GetRegisteredIn() )
((SwModify*)aPageDescDep.GetRegisteredIn())->Remove( &aPageDescDep );
if ( rInfo.aCharFmtDep.GetRegisteredIn() )
((SwModify*)rInfo.aCharFmtDep.GetRegisteredIn())->Add( &aCharFmtDep );
else if ( aCharFmtDep.GetRegisteredIn() )
((SwModify*)aCharFmtDep.GetRegisteredIn())->Remove( &aCharFmtDep );
if ( rInfo.aAnchorCharFmtDep.GetRegisteredIn() )
((SwModify*)rInfo.aAnchorCharFmtDep.GetRegisteredIn())->Add(
&aAnchorCharFmtDep );
else if( aAnchorCharFmtDep.GetRegisteredIn() )
((SwModify*)aAnchorCharFmtDep.GetRegisteredIn())->Remove(
&aAnchorCharFmtDep );
aFmt = rInfo.aFmt;
nFtnOffset = rInfo.nFtnOffset;
m_bEndNote = rInfo.m_bEndNote;
sPrefix = rInfo.sPrefix;
sSuffix = rInfo.sSuffix;
return *this;
}
sal_Bool SwEndNoteInfo::operator==( const SwEndNoteInfo& rInfo ) const
{
return aPageDescDep.GetRegisteredIn() ==
rInfo.aPageDescDep.GetRegisteredIn() &&
aCharFmtDep.GetRegisteredIn() ==
rInfo.aCharFmtDep.GetRegisteredIn() &&
aAnchorCharFmtDep.GetRegisteredIn() ==
rInfo.aAnchorCharFmtDep.GetRegisteredIn() &&
GetFtnTxtColl() == rInfo.GetFtnTxtColl() &&
aFmt.GetNumberingType() == rInfo.aFmt.GetNumberingType() &&
nFtnOffset == rInfo.nFtnOffset &&
m_bEndNote == rInfo.m_bEndNote &&
sPrefix == rInfo.sPrefix &&
sSuffix == rInfo.sSuffix;
}
SwEndNoteInfo::SwEndNoteInfo(const SwEndNoteInfo& rInfo) :
SwClient( rInfo.GetFtnTxtColl() ),
aPageDescDep( this, 0 ),
aCharFmtDep( this, 0 ),
aAnchorCharFmtDep( this, 0 ),
sPrefix( rInfo.sPrefix ),
sSuffix( rInfo.sSuffix ),
m_bEndNote( true ),
aFmt( rInfo.aFmt ),
nFtnOffset( rInfo.nFtnOffset )
{
if( rInfo.aPageDescDep.GetRegisteredIn() )
((SwModify*)rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep );
if( rInfo.aCharFmtDep.GetRegisteredIn() )
((SwModify*)rInfo.aCharFmtDep.GetRegisteredIn())->Add( &aCharFmtDep );
if( rInfo.aAnchorCharFmtDep.GetRegisteredIn() )
((SwModify*)rInfo.aAnchorCharFmtDep.GetRegisteredIn())->Add(
&aAnchorCharFmtDep );
}
SwEndNoteInfo::SwEndNoteInfo(SwTxtFmtColl *pFmt) :
SwClient(pFmt),
aPageDescDep( this, 0 ),
aCharFmtDep( this, 0 ),
aAnchorCharFmtDep( this, 0 ),
m_bEndNote( true ),
nFtnOffset( 0 )
{
aFmt.SetNumberingType(SVX_NUM_ROMAN_LOWER);
}
SwPageDesc *SwEndNoteInfo::GetPageDesc( SwDoc &rDoc ) const
{
if ( !aPageDescDep.GetRegisteredIn() )
{
SwPageDesc *pDesc = rDoc.GetPageDescFromPool( static_cast<sal_uInt16>(
m_bEndNote ? RES_POOLPAGE_ENDNOTE : RES_POOLPAGE_FOOTNOTE ) );
pDesc->Add( &((SwClient&)aPageDescDep) );
}
return (SwPageDesc*)( aPageDescDep.GetRegisteredIn() );
}
bool SwEndNoteInfo::KnowsPageDesc() const
{
return (aPageDescDep.GetRegisteredIn() != 0);
}
bool SwEndNoteInfo::DependsOn( const SwPageDesc* pDesc ) const
{
return ( aPageDescDep.GetRegisteredIn() == pDesc );
}
void SwEndNoteInfo::ChgPageDesc( SwPageDesc *pDesc )
{
pDesc->Add( &((SwClient&)aPageDescDep) );
}
void SwEndNoteInfo::SetFtnTxtColl(SwTxtFmtColl& rFmt)
{
rFmt.Add(this);
}
SwCharFmt* SwEndNoteInfo::GetCharFmt(SwDoc &rDoc) const
{
if ( !aCharFmtDep.GetRegisteredIn() )
{
SwCharFmt* pFmt = rDoc.GetCharFmtFromPool( static_cast<sal_uInt16>(
m_bEndNote ? RES_POOLCHR_ENDNOTE : RES_POOLCHR_FOOTNOTE ) );
pFmt->Add( &((SwClient&)aCharFmtDep) );
}
return (SwCharFmt*)aCharFmtDep.GetRegisteredIn();
}
void SwEndNoteInfo::SetCharFmt( SwCharFmt* pChFmt )
{
OSL_ENSURE(pChFmt, "no CharFmt?");
pChFmt->Add( &((SwClient&)aCharFmtDep) );
}
SwCharFmt* SwEndNoteInfo::GetAnchorCharFmt(SwDoc &rDoc) const
{
if( !aAnchorCharFmtDep.GetRegisteredIn() )
{
SwCharFmt* pFmt = rDoc.GetCharFmtFromPool( static_cast<sal_uInt16>(
m_bEndNote ? RES_POOLCHR_ENDNOTE_ANCHOR : RES_POOLCHR_FOOTNOTE_ANCHOR ) );
pFmt->Add( &((SwClient&)aAnchorCharFmtDep) );
}
return (SwCharFmt*)aAnchorCharFmtDep.GetRegisteredIn();
}
void SwEndNoteInfo::SetAnchorCharFmt( SwCharFmt* pChFmt )
{
OSL_ENSURE(pChFmt, "no CharFmt?");
pChFmt->Add( &((SwClient&)aAnchorCharFmtDep) );
}
void SwEndNoteInfo::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
{
sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
if( RES_ATTRSET_CHG == nWhich ||
RES_FMT_CHG == nWhich )
{
SwDoc* pDoc;
if( aCharFmtDep.GetRegisteredIn() )
pDoc = ((SwCharFmt*)aCharFmtDep.GetRegisteredIn())->GetDoc();
else
pDoc = ((SwCharFmt*)aAnchorCharFmtDep.GetRegisteredIn())->GetDoc();
SwFtnIdxs& rFtnIdxs = pDoc->GetFtnIdxs();
for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.Count(); ++nPos )
{
SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if ( rFtn.IsEndNote() == m_bEndNote )
{
pTxtFtn->SetNumber( rFtn.GetNumber(), &rFtn.GetNumStr());
}
}
}
else
CheckRegistration( pOld, pNew );
}
SwFtnInfo& SwFtnInfo::operator=(const SwFtnInfo& rInfo)
{
SwEndNoteInfo::operator=(rInfo);
aQuoVadis = rInfo.aQuoVadis;
aErgoSum = rInfo.aErgoSum;
ePos = rInfo.ePos;
eNum = rInfo.eNum;
return *this;
}
sal_Bool SwFtnInfo::operator==( const SwFtnInfo& rInfo ) const
{
return ePos == rInfo.ePos &&
eNum == rInfo.eNum &&
SwEndNoteInfo::operator==(rInfo) &&
aQuoVadis == rInfo.aQuoVadis &&
aErgoSum == rInfo.aErgoSum;
}
SwFtnInfo::SwFtnInfo(const SwFtnInfo& rInfo) :
SwEndNoteInfo( rInfo ),
aQuoVadis( rInfo.aQuoVadis ),
aErgoSum( rInfo.aErgoSum ),
ePos( rInfo.ePos ),
eNum( rInfo.eNum )
{
m_bEndNote = false;
}
SwFtnInfo::SwFtnInfo(SwTxtFmtColl *pFmt) :
SwEndNoteInfo( pFmt ),
ePos( FTNPOS_PAGE ),
eNum( FTNNUM_DOC )
{
aFmt.SetNumberingType(SVX_NUM_ARABIC);
m_bEndNote = false;
}
/*********************** SwDoc ***************************/
void SwDoc::SetFtnInfo(const SwFtnInfo& rInfo)
{
SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
if( !(GetFtnInfo() == rInfo) )
{
const SwFtnInfo &rOld = GetFtnInfo();
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo( new SwUndoFootNoteInfo(rOld) );
}
sal_Bool bFtnPos = rInfo.ePos != rOld.ePos;
sal_Bool bFtnDesc = rOld.ePos == FTNPOS_CHAPTER &&
rInfo.GetPageDesc( *this ) != rOld.GetPageDesc( *this );
sal_Bool bExtra = rInfo.aQuoVadis != rOld.aQuoVadis ||
rInfo.aErgoSum != rOld.aErgoSum ||
rInfo.aFmt.GetNumberingType() != rOld.aFmt.GetNumberingType() ||
rInfo.GetPrefix() != rOld.GetPrefix() ||
rInfo.GetSuffix() != rOld.GetSuffix();
SwCharFmt *pOldChrFmt = rOld.GetCharFmt( *this ),
*pNewChrFmt = rInfo.GetCharFmt( *this );
sal_Bool bFtnChrFmts = pOldChrFmt != pNewChrFmt;
*pFtnInfo = rInfo;
if (pTmpRoot)
{
std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080304
if ( bFtnPos )
//pTmpRoot->RemoveFtns();
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllRemoveFtns));//swmod 080305
else
{
//pTmpRoot->UpdateFtnNums();
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::UpdateFtnNums));//swmod 080304
if ( bFtnDesc )
//pTmpRoot->CheckFtnPageDescs( FALSE );
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::CheckFtnPageDescs), sal_False));//swmod 080304
if ( bExtra )
{
// For messages regarding ErgoSum etc. we save the extra code and use the
// available methods.
SwFtnIdxs& rFtnIdxs = GetFtnIdxs();
for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.Count(); ++nPos )
{
SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if ( !rFtn.IsEndNote() )
pTxtFtn->SetNumber( rFtn.GetNumber(), &rFtn.GetNumStr());
}
}
}
} //swmod 080219
if( FTNNUM_PAGE != rInfo.eNum )
GetFtnIdxs().UpdateAllFtn();
else if( bFtnChrFmts )
{
SwFmtChg aOld( pOldChrFmt );
SwFmtChg aNew( pNewChrFmt );
pFtnInfo->ModifyNotification( &aOld, &aNew );
}
// #i81002# no update during loading
if ( !IsInReading() )
{
UpdateRefFlds(NULL);
}
SetModified();
}
}
void SwDoc::SetEndNoteInfo(const SwEndNoteInfo& rInfo)
{
SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
if( !(GetEndNoteInfo() == rInfo) )
{
if(GetIDocumentUndoRedo().DoesUndo())
{
SwUndo *const pUndo( new SwUndoEndNoteInfo( GetEndNoteInfo() ) );
GetIDocumentUndoRedo().AppendUndo(pUndo);
}
sal_Bool bNumChg = rInfo.nFtnOffset != GetEndNoteInfo().nFtnOffset;
// this seems to be an optimization: UpdateAllFtn() is only called
// if the offset changes; if the offset is the same,
// but type/prefix/suffix changes, just set new numbers.
bool const bExtra = !bNumChg &&
( (rInfo.aFmt.GetNumberingType() !=
GetEndNoteInfo().aFmt.GetNumberingType())
|| (rInfo.GetPrefix() != GetEndNoteInfo().GetPrefix())
|| (rInfo.GetSuffix() != GetEndNoteInfo().GetSuffix())
);
sal_Bool bFtnDesc = rInfo.GetPageDesc( *this ) !=
GetEndNoteInfo().GetPageDesc( *this );
SwCharFmt *pOldChrFmt = GetEndNoteInfo().GetCharFmt( *this ),
*pNewChrFmt = rInfo.GetCharFmt( *this );
sal_Bool bFtnChrFmts = pOldChrFmt != pNewChrFmt;
*pEndNoteInfo = rInfo;
if ( pTmpRoot )
{
if ( bFtnDesc )
//pTmpRoot->CheckFtnPageDescs( TRUE );
{
std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::CheckFtnPageDescs), sal_True));//swmod 080304
}
if ( bExtra )
{
// For messages regarding ErgoSum etc. we save the extra code and use the
// available methods.
SwFtnIdxs& rFtnIdxs = GetFtnIdxs();
for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.Count(); ++nPos )
{
SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ];
const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
if ( rFtn.IsEndNote() )
pTxtFtn->SetNumber( rFtn.GetNumber(), &rFtn.GetNumStr());
}
}
} //swmod 080219
if( bNumChg )
GetFtnIdxs().UpdateAllFtn();
else if( bFtnChrFmts )
{
SwFmtChg aOld( pOldChrFmt );
SwFmtChg aNew( pNewChrFmt );
pEndNoteInfo->ModifyNotification( &aOld, &aNew );
}
// #i81002# no update during loading
if ( !IsInReading() )
{
UpdateRefFlds(NULL);
}
SetModified();
}
}
bool SwDoc::SetCurFtn( const SwPaM& rPam, const String& rNumStr,
sal_uInt16 nNumber, bool bIsEndNote )
{
SwFtnIdxs& rFtnArr = GetFtnIdxs();
SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
const SwPosition* pStt = rPam.Start(), *pEnd = rPam.End();
const sal_uLong nSttNd = pStt->nNode.GetIndex();
const xub_StrLen nSttCnt = pStt->nContent.GetIndex();
const sal_uLong nEndNd = pEnd->nNode.GetIndex();
const xub_StrLen nEndCnt = pEnd->nContent.GetIndex();
sal_uInt16 nPos;
rFtnArr.SeekEntry( pStt->nNode, &nPos );
SwUndoChangeFootNote* pUndo = 0;
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().ClearRedo(); // AppendUndo far below, so leave it
pUndo = new SwUndoChangeFootNote( rPam, rNumStr, nNumber, bIsEndNote );
}
SwTxtFtn* pTxtFtn;
sal_uLong nIdx;
sal_Bool bChg = sal_False;
sal_Bool bTypeChgd = sal_False;
sal_uInt16 n = nPos; // save
while( nPos < rFtnArr.Count() &&
(( nIdx = _SwTxtFtn_GetIndex((pTxtFtn = rFtnArr[ nPos++ ] )))
< nEndNd || ( nIdx == nEndNd &&
nEndCnt >= *pTxtFtn->GetStart() )) )
if( nIdx > nSttNd || ( nIdx == nSttNd &&
nSttCnt <= *pTxtFtn->GetStart() ) )
{
const SwFmtFtn& rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr() != rNumStr ||
rFtn.IsEndNote() != bIsEndNote )
{
bChg = sal_True;
if ( pUndo )
{
pUndo->GetHistory().Add( *pTxtFtn );
}
pTxtFtn->SetNumber( nNumber, &rNumStr );
if( rFtn.IsEndNote() != bIsEndNote )
{
((SwFmtFtn&)rFtn).SetEndNote( bIsEndNote );
bTypeChgd = sal_True;
pTxtFtn->CheckCondColl();
//#i11339# dispose UNO wrapper when a footnote is changed to an endnote or vice versa
SwPtrMsgPoolItem aMsgHint( RES_FOOTNOTE_DELETED, (void*)&pTxtFtn->GetAttr() );
GetUnoCallBack()->ModifyNotification( &aMsgHint, &aMsgHint );
}
}
}
nPos = n; // There are more in the front!
while( nPos &&
(( nIdx = _SwTxtFtn_GetIndex((pTxtFtn = rFtnArr[ --nPos ] )))
> nSttNd || ( nIdx == nSttNd &&
nSttCnt <= *pTxtFtn->GetStart() )) )
if( nIdx < nEndNd || ( nIdx == nEndNd &&
nEndCnt >= *pTxtFtn->GetStart() ) )
{
const SwFmtFtn& rFtn = pTxtFtn->GetFtn();
if( rFtn.GetNumStr() != rNumStr ||
rFtn.IsEndNote() != bIsEndNote )
{
bChg = sal_True;
if ( pUndo )
{
pUndo->GetHistory().Add( *pTxtFtn );
}
pTxtFtn->SetNumber( nNumber, &rNumStr );
if( rFtn.IsEndNote() != bIsEndNote )
{
((SwFmtFtn&)rFtn).SetEndNote( bIsEndNote );
bTypeChgd = sal_True;
pTxtFtn->CheckCondColl();
}
}
}
// Who needs to be triggered?
if( bChg )
{
if( pUndo )
{
GetIDocumentUndoRedo().AppendUndo(pUndo);
}
if ( bTypeChgd )
rFtnArr.UpdateAllFtn();
if( FTNNUM_PAGE != GetFtnInfo().eNum )
{
if ( !bTypeChgd )
rFtnArr.UpdateAllFtn();
}
else if( pTmpRoot )
//
{
std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::UpdateFtnNums));
} //swmod 080304pTmpRoot->UpdateFtnNums(); //swmod 080219
SetModified();
}
else
delete pUndo;
return bChg;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|