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
|
/* -*- 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 "hintids.hxx"
#include "cntfrm.hxx" // _GetFly
#include "doc.hxx"
#include <IDocumentUndoRedo.hxx>
#include "pam.hxx" // fuer SwTxtFlyCnt
#include "flyfrm.hxx" // fuer SwTxtFlyCnt
#include "ndtxt.hxx" // SwFlyFrmFmt
#include "frmfmt.hxx" // SwFlyFrmFmt
#include <fmtflcnt.hxx>
#include <txtflcnt.hxx>
#include <fmtanchr.hxx>
#include "swfont.hxx"
#include "txtfrm.hxx"
#include "flyfrms.hxx"
#include <objectformatter.hxx>
#include <switerator.hxx>
SwFmtFlyCnt::SwFmtFlyCnt( SwFrmFmt *pFrmFmt )
: SfxPoolItem( RES_TXTATR_FLYCNT ),
pTxtAttr( 0 ),
pFmt( pFrmFmt )
{
}
int SwFmtFlyCnt::operator==( const SfxPoolItem& rAttr ) const
{
OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
return( pTxtAttr && ((SwFmtFlyCnt&)rAttr).pTxtAttr &&
*pTxtAttr->GetStart() == *((SwFmtFlyCnt&)rAttr).pTxtAttr->GetStart() &&
pFmt == ((SwFmtFlyCnt&)rAttr).GetFrmFmt() );
}
SfxPoolItem* SwFmtFlyCnt::Clone( SfxItemPool* ) const
{
return new SwFmtFlyCnt( pFmt );
}
SwTxtFlyCnt::SwTxtFlyCnt( SwFmtFlyCnt& rAttr, xub_StrLen nStartPos )
: SwTxtAttr( rAttr, nStartPos )
{
rAttr.pTxtAttr = this;
SetHasDummyChar(true);
}
/*************************************************************************
* SwTxtFlyCnt::MakeTxtHint()
*
* An dieser Stelle soll einmal der Gesamtzusammenhang bei der Erzeugung
* eines neuen SwTxtFlyCnt erlaeutert werden.
* Das MakeTxtHint() wird z.B. im SwTxtNode::Copy() gerufen.
* Fuer die komplette Verdopplung sind folgende Schritte notwendig:
* 1) Duplizieren des pFmt incl. Inhalt, Attributen etc.
* 2) Setzen des Ankers
* 3) Benachrichtigung
* Da fuer die Bewaeltigung der Aufgaben nicht immer alle Informationen
* bereitstehen und darueber hinaus bestimmte Methoden erst zu einem
* spaeteren Zeitpunkt gerufen werden duerfen (weil nocht nicht alle
* Nodeinformationen vorliegen), verteilt sich der Ablauf.
* ad 1) MakeTxtHint() wird durch den Aufruf von SwDoc::CopyLayout()
* der das neue FlyFrmFmt erzeugt und mit dem duplizierten Inhalt des
* FlyFrm verbunden.
* ad 2) SetAnchor() wird von SwTxtNode::Insert() gerufen und sorgt fuer das
* setzen des Ankers (die SwPosition des Dummy-Zeichens wird dem FlyFrmFmt
* per SetAttr bekannt gegeben). Dies kann nicht im MakeTxtHint erledigt
* werden, da der Zielnode unbestimmt ist.
* ad 3) _GetFlyFrm() wird im Formatierungsprozess vom LineIter gerufen
* und sucht den FlyFrm zum Dummyzeichen des aktuellen CntntFrm. Wird keiner
* gefunden, so wird ein neuer FlyFrm angelegt.
* Kritisch an diesem Vorgehen ist, dass das pCntnt->AppendFly() eine
* sofortige Neuformatierung von pCntnt anstoesst. Die Rekursion kommt
* allerdings durch den Lockmechanismus in SwTxtFrm::Format() nicht
* zu stande.
* Attraktiv ist der Umstand, dass niemand ueber die vom Node abhaengigen
* CntntFrms iterieren braucht, um die FlyInCntFrm anzulegen. Dies geschieht
* bei der Arbeit.
*************************************************************************/
void SwTxtFlyCnt::CopyFlyFmt( SwDoc* pDoc )
{
SwFrmFmt* pFmt = GetFlyCnt().GetFrmFmt();
OSL_ENSURE( pFmt, "von welchem Format soll ich eine Kopie erzeugen?" );
// Das FlyFrmFmt muss dupliziert werden.
// In CopyLayoutFmt (siehe doclay.cxx) wird das FlyFrmFmt erzeugt
// und der Inhalt dupliziert.
// disable undo while copying attribute
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
SwFmtAnchor aAnchor( pFmt->GetAnchor() );
if ((FLY_AT_PAGE != aAnchor.GetAnchorId()) &&
(pDoc != pFmt->GetDoc())) // different documents?
{
// JP 03.06.96: dann sorge dafuer, das der koperierte Anker auf
// gueltigen Content zeigt! Die Umsetzung auf die
// richtige Position erfolgt spaeter.
SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), +2 );
SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
if( !pCNd )
pCNd = pDoc->GetNodes().GoNext( &aIdx );
SwPosition* pPos = (SwPosition*)aAnchor.GetCntntAnchor();
pPos->nNode = aIdx;
if (FLY_AS_CHAR == aAnchor.GetAnchorId())
{
pPos->nContent.Assign( pCNd, 0 );
}
else
{
pPos->nContent.Assign( 0, 0 );
OSL_ENSURE( !this, "CopyFlyFmt: Was fuer ein Anker?" );
}
}
SwFrmFmt* pNew = pDoc->CopyLayoutFmt( *pFmt, aAnchor, false, false );
((SwFmtFlyCnt&)GetFlyCnt()).SetFlyFmt( pNew );
}
/*************************************************************************
* SwTxtFlyCnt::SetAnchor()
*
* SetAnchor() wird von SwTxtNode::Insert() gerufen und sorgt fuer das
* setzen des Ankers (die SwPosition des Dummy-Zeichens wird dem FlyFrmFmt
* per SetAttr bekannt gegeben). Dies kann nicht im MakeTxtHint erledigt
* werden, da der Zielnode unbestimmt ist.
* (siehe Kommentar in SwTxtFlyCnt::MakeTxtHint)
*************************************************************************/
void SwTxtFlyCnt::SetAnchor( const SwTxtNode *pNode )
{
// fuers Undo muss der neue Anker schon bekannt sein !
// Wir ermitteln den Index im Nodesarray zum Node
SwDoc* pDoc = (SwDoc*)pNode->GetDoc();
SwIndex aIdx( (SwTxtNode*)pNode, *GetStart() );
SwPosition aPos( *pNode->StartOfSectionNode(), aIdx );
SwFrmFmt* pFmt = GetFlyCnt().GetFrmFmt();
SwFmtAnchor aAnchor( pFmt->GetAnchor() );
if( !aAnchor.GetCntntAnchor() ||
!aAnchor.GetCntntAnchor()->nNode.GetNode().GetNodes().IsDocNodes() ||
&aAnchor.GetCntntAnchor()->nNode.GetNode() != (SwNode*)pNode )
aPos.nNode = *pNode;
else
aPos.nNode = aAnchor.GetCntntAnchor()->nNode;
aAnchor.SetType( FLY_AS_CHAR ); // default!
aAnchor.SetAnchor( &aPos );
// beim Ankerwechsel werden immer alle FlyFrms vom Attribut geloescht
// JP 25.04.95: wird innerhalb des SplitNodes die Frames verschoben
// koennen die Frames erhalten bleiben.
if( ( !pNode->GetpSwpHints() || !pNode->GetpSwpHints()->IsInSplitNode() )
&& RES_DRAWFRMFMT != pFmt->Which() )
pFmt->DelFrms();
// stehen wir noch im falschen Dokument ?
if( pDoc != pFmt->GetDoc() )
{
// disable undo while copying attribute
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
SwFrmFmt* pNew = pDoc->CopyLayoutFmt( *pFmt, aAnchor, false, false );
::sw::UndoGuard const undoGuardFmt(
pFmt->GetDoc()->GetIDocumentUndoRedo());
pFmt->GetDoc()->DelLayoutFmt( pFmt );
((SwFmtFlyCnt&)GetFlyCnt()).SetFlyFmt( pNew );
}
else if( pNode->GetpSwpHints() &&
pNode->GetpSwpHints()->IsInSplitNode() &&
RES_DRAWFRMFMT != pFmt->Which() )
{
pFmt->LockModify();
pFmt->SetFmtAttr( aAnchor ); // nur den Anker neu setzen
pFmt->UnlockModify();
}
else
pFmt->SetFmtAttr( aAnchor ); // nur den Anker neu setzen
// Am Node haengen u.a. abhaengige CntFrms.
// Fuer jeden CntFrm wird ein SwFlyInCntFrm angelegt.
}
/*************************************************************************
* SwTxtFlyCnt::_GetFlyFrm()
*
* _GetFlyFrm() wird im Formatierungsprozess vom LineIter gerufen
* und sucht den FlyFrm zum Dummyzeichen des aktuellen CntntFrm. Wird keiner
* gefunden, so wird ein neuer FlyFrm angelegt.
* (siehe Kommentar ind SwTxtFlyCnt::MakeTxtHint)
*************************************************************************/
SwFlyInCntFrm *SwTxtFlyCnt::_GetFlyFrm( const SwFrm *pCurrFrm )
{
SwFrmFmt* pFrmFmt = GetFlyCnt().GetFrmFmt();
if( RES_DRAWFRMFMT == pFrmFmt->Which() )
{
OSL_ENSURE( !this, "SwTxtFlyCnt::_GetFlyFrm: DrawInCnt-Baustelle!" );
return NULL;
}
SwIterator<SwFlyFrm,SwFmt> aIter( *GetFlyCnt().pFmt );
OSL_ENSURE( pCurrFrm->IsTxtFrm(), "SwTxtFlyCnt::_GetFlyFrm for TxtFrms only." );
SwFrm* pFrm = aIter.First();
if ( pFrm )
{
SwTxtFrm *pFirst = (SwTxtFrm*)pCurrFrm;
while ( pFirst->IsFollow() )
pFirst = pFirst->FindMaster();
do
{
SwTxtFrm *pTmp = pFirst;
do
{ if( ( (SwFlyFrm*)pFrm )->GetAnchorFrm() == (SwFrm*) pTmp )
{
if ( pTmp != pCurrFrm )
{
pTmp->RemoveFly( (SwFlyFrm*)pFrm );
((SwTxtFrm*)pCurrFrm)->AppendFly( (SwFlyFrm*)pFrm );
}
return (SwFlyInCntFrm*)pFrm;
}
pTmp = pTmp->GetFollow();
} while ( pTmp );
pFrm = aIter.Next();
} while( pFrm );
}
// Wir haben keinen passenden FlyFrm gefunden, deswegen wird ein
// neuer angelegt.
// Dabei wird eine sofortige Neuformatierung von pCurrFrm angestossen.
// Die Rekursion wird durch den Lockmechanismus in SwTxtFrm::Format()
// abgewuergt.
SwFrm* pCurrFrame = const_cast< SwFrm* >(pCurrFrm);
SwFlyInCntFrm *pFly = new SwFlyInCntFrm( (SwFlyFrmFmt*)pFrmFmt, pCurrFrame, pCurrFrame );
pCurrFrame->AppendFly( pFly );
pFly->RegistFlys();
// 7922: Wir muessen dafuer sorgen, dass der Inhalt des FlyInCnt
// nach seiner Konstruktion stramm durchformatiert wird.
// #i26945# - Use new object formatter to format Writer
// fly frame and its content.
SwObjectFormatter::FormatObj( *pFly, const_cast<SwFrm*>(pCurrFrm),
pCurrFrm->FindPageFrm() );
return pFly;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|