update credits
[LibreOffice.git] / sw / source / filter / ww8 / ww8graf2.cxx
blobd98543b9b64784f0e250f70a81874a89ae129a40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <iterator>
22 #include <hintids.hxx>
23 #include <svl/urihelper.hxx>
24 #include <svx/svdpage.hxx>
25 #include <svx/svdmodel.hxx>
26 #include <svx/svdograf.hxx>
27 #include <svx/svdoole2.hxx>
28 #include <editeng/opaqitem.hxx>
29 #include <filter/msfilter/msdffimp.hxx>
30 #include <sfx2/app.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/fcontnr.hxx>
33 #include <grfatr.hxx> // class SwCropGrf
34 #include <fmtflcnt.hxx>
35 #include <fmtanchr.hxx>
36 #include <frmfmt.hxx>
37 #include <fltshell.hxx>
38 #include <pam.hxx>
39 #include <doc.hxx>
40 #include <ndtxt.hxx> // class SwTxtNode
41 #include <mdiexp.hxx> // Progress
42 #include "writerwordglue.hxx"
43 #include "ww8struc.hxx"
44 #include "ww8scan.hxx"
45 #include "ww8par.hxx" // class SwWWImplReader
46 #include "ww8par2.hxx" // struct WWFlyPara
47 #include "ww8graf.hxx"
48 #include <vcl/graphicfilter.hxx>
49 #include <vcl/wmf.hxx>
51 using namespace ::com::sun::star;
52 using namespace sw::types;
54 wwZOrderer::wwZOrderer(const sw::util::SetLayer &rSetLayer, SdrPage* pDrawPg,
55 const SvxMSDffShapeOrders *pShapeOrders)
56 : maSetLayer(rSetLayer), mnInlines(0), mpDrawPg(pDrawPg),
57 mpShapeOrders(pShapeOrders)
59 mnNoInitialObjects = mpDrawPg->GetObjCount();
60 OSL_ENSURE(mpDrawPg,"Missing draw page impossible!");
63 void wwZOrderer::InsideEscher(sal_uLong nSpId)
65 maIndexes.push(GetEscherObjectIdx(nSpId));
68 void wwZOrderer::OutsideEscher()
70 maIndexes.pop();
73 // consider new parameter <_bInHeaderFooter>
74 void wwZOrderer::InsertEscherObject( SdrObject* pObject,
75 sal_uLong nSpId,
76 const bool _bInHeaderFooter )
78 sal_uLong nInsertPos = GetEscherObjectPos( nSpId, _bInHeaderFooter );
79 InsertObject(pObject, nInsertPos + mnNoInitialObjects + mnInlines);
82 wwZOrderer::myeiter wwZOrderer::MapEscherIdxToIter(sal_uLong nIdx)
84 myeiter aIter = maEscherLayer.begin();
85 myeiter aEnd = maEscherLayer.end();
86 while (aIter != aEnd)
88 if (aIter->mnEscherShapeOrder == nIdx)
89 break;
90 ++aIter;
92 return aIter;
95 sal_uInt16 wwZOrderer::GetEscherObjectIdx(sal_uLong nSpId)
97 sal_uInt16 nFound=0;
98 sal_uInt16 nShapeCount = mpShapeOrders ? mpShapeOrders->size() : 0;
99 // First, find out what position this shape is in in the Escher order.
100 for (sal_uInt16 nShapePos=0; nShapePos < nShapeCount; nShapePos++)
102 const SvxMSDffShapeOrder& rOrder = *(*mpShapeOrders)[nShapePos];
103 if (rOrder.nShapeId == nSpId)
105 nFound = nShapePos;
106 break;
109 return nFound;
112 // consider new parameter <_bInHeaderFooter>
113 sal_uLong wwZOrderer::GetEscherObjectPos( sal_uLong nSpId,
114 const bool _bInHeaderFooter )
117 EscherObjects have their own ordering which needs to be matched to
118 the actual ordering that should be used when inserting them into the
119 document.
121 sal_uInt16 nFound = GetEscherObjectIdx(nSpId);
122 // Match the ordering position from the ShapeOrders to the ordering of all
123 // objects in the document, there is a complexity when escherobjects
124 // contain inlines objects, we need to consider thsose as part of the
125 // escher count
126 sal_uLong nRet=0;
127 myeiter aIter = maEscherLayer.begin();
128 myeiter aEnd = maEscherLayer.end();
129 // skip objects in page header|footer,
130 // if current object isn't in page header|footer
131 if ( !_bInHeaderFooter )
133 while ( aIter != aEnd )
135 if ( !aIter->mbInHeaderFooter )
137 break;
139 nRet += aIter->mnNoInlines + 1;
140 ++aIter;
143 while (aIter != aEnd)
145 // insert object in page header|footer
146 // before objects in page body
147 if ( _bInHeaderFooter && !aIter->mbInHeaderFooter )
149 break;
151 if ( aIter->mnEscherShapeOrder > nFound )
152 break;
153 nRet += aIter->mnNoInlines+1;
154 ++aIter;
156 maEscherLayer.insert(aIter, EscherShape( nFound, _bInHeaderFooter ) );
157 return nRet;
160 // InsertObj() fuegt das Objekt in die Sw-Page ein und merkt sich die Z-Pos in
161 // einem VarArr
162 void wwZOrderer::InsertDrawingObject(SdrObject* pObj, short nWwHeight)
164 sal_uLong nPos = GetDrawingObjectPos(nWwHeight);
165 if (nWwHeight & 0x2000) // Heaven ?
166 maSetLayer.SendObjectToHeaven(*pObj);
167 else
168 maSetLayer.SendObjectToHell(*pObj);
170 InsertObject(pObj, nPos + mnNoInitialObjects + mnInlines);
173 void wwZOrderer::InsertTextLayerObject(SdrObject* pObject)
175 maSetLayer.SendObjectToHeaven(*pObject);
176 if (maIndexes.empty())
178 InsertObject(pObject, mnNoInitialObjects + mnInlines);
179 ++mnInlines;
181 else
183 //If we are inside an escher objects, place us just after that
184 //escher obj, and increment its inline count
185 sal_uInt16 nIdx = maIndexes.top();
186 myeiter aEnd = MapEscherIdxToIter(nIdx);
188 sal_uLong nInsertPos=0;
189 myeiter aIter = maEscherLayer.begin();
190 while (aIter != aEnd)
192 nInsertPos += aIter->mnNoInlines+1;
193 ++aIter;
196 OSL_ENSURE(aEnd != maEscherLayer.end(), "Something very wrong here");
197 if (aEnd != maEscherLayer.end())
199 aEnd->mnNoInlines++;
200 nInsertPos += aEnd->mnNoInlines;
203 InsertObject(pObject, mnNoInitialObjects + mnInlines + nInsertPos);
207 // Parallel zu dem Obj-Array im Dokument baue ich ein Array auf,
208 // dass die Ww-Height ( -> Wer ueberdeckt wen ) beinhaltet.
209 // Anhand dieses VARARR wird die Einfuegeposition ermittelt.
210 // Der Offset bei Datei in bestehendes Dokument mit Grafiklayer einfuegen
211 // muss der Aufrufer den Index um mnNoInitialObjects erhoeht werden, damit die
212 // neuen Objekte am Ende landen ( Einfuegen ist dann schneller )
213 sal_uLong wwZOrderer::GetDrawingObjectPos(short nWwHeight)
215 myditer aIter = maDrawHeight.begin();
216 myditer aEnd = maDrawHeight.end();
218 while (aIter != aEnd)
220 if ((*aIter & 0x1fff) > (nWwHeight & 0x1fff))
221 break;
222 ++aIter;
225 aIter = maDrawHeight.insert(aIter, nWwHeight);
226 return std::distance(maDrawHeight.begin(), aIter);
229 bool wwZOrderer::InsertObject(SdrObject* pObject, sal_uLong nPos)
231 if (!pObject->IsInserted())
233 mpDrawPg->InsertObject(pObject, nPos);
234 return true;
236 return false;
239 #ifdef __WW8_NEEDS_COPY
240 extern void WW8PicShadowToReal( WW8_PIC_SHADOW* pPicS, WW8_PIC* pPic );
241 #endif // defined __WW8_NEEDS_COPY
243 bool SwWW8ImplReader::GetPictGrafFromStream(Graphic& rGraphic, SvStream& rSrc)
245 return 0 == GraphicFilter::GetGraphicFilter().ImportGraphic(rGraphic, aEmptyStr, rSrc,
246 GRFILTER_FORMAT_DONTKNOW);
249 bool SwWW8ImplReader::ReadGrafFile(String& rFileName, Graphic*& rpGraphic,
250 const WW8_PIC& rPic, SvStream* pSt, sal_uLong nFilePos, bool* pbInDoc)
251 { // Grafik in File schreiben
252 *pbInDoc = true; // default
254 sal_uLong nPosFc = nFilePos + rPic.cbHeader;
256 switch (rPic.MFP.mm)
258 case 94: // BMP-File ( nicht embeddet ) oder GIF
259 case 99: // TIFF-File ( nicht embeddet )
260 pSt->Seek(nPosFc);
261 // Name als P-String einlesen
262 rFileName = read_uInt8_PascalString(*pSt, eStructCharSet);
263 if (rFileName.Len())
264 rFileName = URIHelper::SmartRel2Abs(
265 INetURLObject(sBaseURL), rFileName,
266 URIHelper::GetMaybeFileHdl());
267 *pbInDoc = false; // Datei anschliessend nicht loeschen
268 return rFileName.Len() != 0; // Einlesen OK
271 GDIMetaFile aWMF;
272 pSt->Seek( nPosFc );
273 bool bOk = ReadWindowMetafile( *pSt, aWMF, NULL ) ? true : false;
275 if (!bOk || pSt->GetError() || !aWMF.GetActionSize())
276 return false;
278 if (pWwFib->envr != 1) // !MAC als Creator
280 rpGraphic = new Graphic( aWMF );
281 return true;
284 // MAC - Word als Creator
285 // im WMF steht nur "Benutzen sie Word 6.0c" Mac-Pict steht dahinter
286 // allerdings ohne die ersten 512 Bytes, bei einem MAC-PICT egal sind (
287 // werden nicht ausgewertet )
288 bOk = false;
289 long nData = rPic.lcb - ( pSt->Tell() - nPosFc );
290 if (nData > 0)
292 rpGraphic = new Graphic();
293 if (0 == (bOk = SwWW8ImplReader::GetPictGrafFromStream(*rpGraphic, *pSt)))
294 DELETEZ(rpGraphic);
296 return bOk; // Grafik drin
299 struct WW8PicDesc
301 sal_Int16 nCL, nCR, nCT, nCB;
302 long nWidth, nHeight;
304 WW8PicDesc( const WW8_PIC& rPic );
307 WW8PicDesc::WW8PicDesc( const WW8_PIC& rPic )
309 //See #i21190# before fiddling with this method
310 long nOriWidth = rPic.dxaGoal; //Size in 1/100 mm before crop
311 long nOriHeight = rPic.dyaGoal;
313 nCL = rPic.dxaCropLeft;
314 nCR = rPic.dxaCropRight;
315 nCT = rPic.dyaCropTop;
316 nCB = rPic.dyaCropBottom;
318 long nAktWidth = nOriWidth - (nCL + nCR); // Size after crop
319 long nAktHeight = nOriHeight - (nCT + nCB);
320 if (!nAktWidth)
321 nAktWidth = 1;
322 if (!nAktHeight)
323 nAktHeight = 1;
324 nWidth = nAktWidth * rPic.mx / 1000; // Writer Size
325 nHeight = nAktHeight * rPic.my / 1000;
328 void SwWW8ImplReader::ReplaceObj(const SdrObject &rReplaceObj,
329 SdrObject &rSubObj)
331 // SdrGrafObj anstatt des SdrTextObj in dessen Gruppe einsetzen
332 if (SdrObject* pGroupObject = rReplaceObj.GetUpGroup())
334 SdrObjList* pObjectList = pGroupObject->GetSubList();
336 rSubObj.SetLogicRect(rReplaceObj.GetCurrentBoundRect());
337 rSubObj.SetLayer(rReplaceObj.GetLayer());
339 // altes Objekt raus aus Gruppen-Liste und neues rein
340 // (dies tauscht es ebenfalls in der Drawing-Page aus)
341 pObjectList->ReplaceObject(&rSubObj, rReplaceObj.GetOrdNum());
343 else
345 OSL_ENSURE( !this, "Impossible!");
349 // MakeGrafNotInCntnt setzt eine nicht-Zeichengebundene Grafik
350 // ( bGrafApo == true)
351 SwFlyFrmFmt* SwWW8ImplReader::MakeGrafNotInCntnt(const WW8PicDesc& rPD,
352 const Graphic* pGraph, const String& rFileName, const SfxItemSet& rGrfSet)
355 sal_uInt32 nWidth = rPD.nWidth;
356 sal_uInt32 nHeight = rPD.nHeight;
358 // Vertikale Verschiebung durch Zeilenabstand
359 sal_Int32 nNetHeight = nHeight + rPD.nCT + rPD.nCB;
360 if( pSFlyPara->nLineSpace && pSFlyPara->nLineSpace > nNetHeight )
361 pSFlyPara->nYPos =
362 (sal_uInt16)( pSFlyPara->nYPos + pSFlyPara->nLineSpace - nNetHeight );
364 WW8FlySet aFlySet(*this, pWFlyPara, pSFlyPara, true);
366 SwFmtAnchor aAnchor(pSFlyPara->eAnchor);
367 aAnchor.SetAnchor(pPaM->GetPoint());
368 aFlySet.Put(aAnchor);
370 aFlySet.Put( SwFmtFrmSize( ATT_FIX_SIZE, nWidth, nHeight ) );
372 SwFlyFrmFmt* pFlyFmt = rDoc.Insert(*pPaM, rFileName, aEmptyStr, pGraph,
373 &aFlySet, &rGrfSet, NULL);
375 // Damit die Frames bei Einfuegen in existierendes Doc erzeugt werden:
376 if (rDoc.GetCurrentViewShell() && //swmod 071108//swmod 071225
377 (FLY_AT_PARA == pFlyFmt->GetAnchor().GetAnchorId()))
379 pFlyFmt->MakeFrms();
381 return pFlyFmt;
385 // MakeGrafInCntnt fuegt zeichengebundene Grafiken ein
386 SwFrmFmt* SwWW8ImplReader::MakeGrafInCntnt(const WW8_PIC& rPic,
387 const WW8PicDesc& rPD, const Graphic* pGraph, const String& rFileName,
388 const SfxItemSet& rGrfSet)
390 WW8FlySet aFlySet(*this, pPaM, rPic, rPD.nWidth, rPD.nHeight);
392 SwFrmFmt* pFlyFmt = 0;
394 if (!rFileName.Len() && nObjLocFc) // dann sollte ists ein OLE-Object
395 pFlyFmt = ImportOle(pGraph, &aFlySet, &rGrfSet);
397 if( !pFlyFmt ) // dann eben als Graphic
400 pFlyFmt = rDoc.Insert( *pPaM, rFileName, aEmptyStr, pGraph, &aFlySet,
401 &rGrfSet, NULL);
404 // Grafik im Rahmen ? ok, Rahmen auf Bildgroesse vergroessern
405 // ( nur wenn Auto-Breite )
406 if( pSFlyPara )
407 pSFlyPara->BoxUpWidth( rPD.nWidth );
408 return pFlyFmt;
411 SwFrmFmt* SwWW8ImplReader::ImportGraf1(WW8_PIC& rPic, SvStream* pSt,
412 sal_uLong nFilePos )
414 SwFrmFmt* pRet = 0;
415 if( pSt->IsEof() || rPic.fError || rPic.MFP.mm == 99 )
416 return 0;
418 String aFileName;
419 bool bInDoc;
420 Graphic* pGraph = 0;
421 bool bOk = ReadGrafFile(aFileName, pGraph, rPic, pSt, nFilePos, &bInDoc);
423 if (!bOk)
425 delete pGraph;
426 return 0; // Grafik nicht korrekt eingelesen
429 WW8PicDesc aPD( rPic );
431 SwAttrSet aGrfSet( rDoc.GetAttrPool(), RES_GRFATR_BEGIN, RES_GRFATR_END-1);
432 if( aPD.nCL || aPD.nCR || aPD.nCT || aPD.nCB )
434 SwCropGrf aCrop( aPD.nCL, aPD.nCR, aPD.nCT, aPD.nCB) ;
435 aGrfSet.Put( aCrop );
438 if( pWFlyPara && pWFlyPara->bGrafApo )
439 pRet = MakeGrafNotInCntnt(aPD,pGraph,aFileName,aGrfSet);
440 else
441 pRet = MakeGrafInCntnt(rPic,aPD,pGraph,aFileName,aGrfSet);
442 delete pGraph;
443 return pRet;
446 void SwWW8ImplReader::PicRead(SvStream *pDataStream, WW8_PIC *pPic,
447 bool bVer67)
449 //Only the first 0x2e bytes are the same between version 6/7 and 8+
450 #ifdef __WW8_NEEDS_COPY
451 WW8_PIC_SHADOW aPicS;
452 pDataStream->Read( &aPicS, sizeof( aPicS ) );
453 WW8PicShadowToReal( &aPicS, pPic );
454 #else
455 pDataStream->Read( pPic, 0x2E);
456 #endif // defined __WW8_NEEDS_COPY
457 for (int i=0;i<4;i++)
458 pDataStream->Read( &pPic->rgbrc[i], bVer67 ? 2 : 4);
459 *pDataStream >> pPic->dxaOrigin;
460 *pDataStream >> pPic->dyaOrigin;
461 if (!bVer67)
462 pDataStream->SeekRel(2); //cProps
465 SwFrmFmt* SwWW8ImplReader::ImportGraf(SdrTextObj* pTextObj,
466 SwFrmFmt* pOldFlyFmt)
468 SwFrmFmt* pRet = 0;
469 if (
470 ((pStrm == pDataStream ) && !nPicLocFc) ||
471 (nIniFlags & WW8FL_NO_GRAF)
474 return 0;
477 ::SetProgressState(nProgress, mpDocShell); // Update
479 GrafikCtor();
482 kleiner Spass von Microsoft: manchmal existiert ein Stream Namens DATA
483 Dieser enthaelt dann den PICF und die entsprechende Grafik !!!
484 Wir mappen ansonsten die Variable pDataStream auf pStream.
487 sal_uLong nOldPos = pDataStream->Tell();
488 WW8_PIC aPic;
489 pDataStream->Seek( nPicLocFc );
490 PicRead( pDataStream, &aPic, bVer67);
492 // Plausibilitaetstest ist noetig, da z.B. bei CheckBoxen im
493 // Feld-Result ein WMF-aehnliches Struct vorkommt.
494 if ((aPic.lcb >= 58) && !pDataStream->GetError())
496 if( pFlyFmtOfJustInsertedGraphic )
498 // Soeben haben wir einen Grafik-Link ins Doc inserted.
499 // Wir muessen ihn jetzt noch Positioniern und Skalieren.
501 WW8PicDesc aPD( aPic );
503 WW8FlySet aFlySet( *this, pPaM, aPic, aPD.nWidth, aPD.nHeight );
505 // the correct anchor is set in Read_F_IncludePicture and the current PaM point's
506 // behind the position if it is anchored in content; because this anchor add
507 // a character into the textnode. IussueZilla task 2806
508 if (FLY_AS_CHAR ==
509 pFlyFmtOfJustInsertedGraphic->GetAnchor().GetAnchorId() )
511 aFlySet.ClearItem( RES_ANCHOR );
514 pFlyFmtOfJustInsertedGraphic->SetFmtAttr( aFlySet );
516 pFlyFmtOfJustInsertedGraphic = 0;
518 else if((0x64 == aPic.MFP.mm) || (0x66 == aPic.MFP.mm))
520 // verlinkte Grafik im Escher-Objekt
521 SdrObject* pObject = 0;
523 WW8PicDesc aPD( aPic );
524 if (!pMSDffManager)
525 pMSDffManager = new SwMSDffManager(*this);
527 ##835##
528 Disable use of main stream as fallback stream for inline direct
529 blips as it is known that they are directly after the record
530 header, testing for existance in main stream may lead to an
531 incorrect fallback graphic being found if other escher graphics
532 have been inserted in the document
534 pMSDffManager->DisableFallbackStream();
535 if( !pMSDffManager->GetModel() )
536 pMSDffManager->SetModel(pDrawModel, 1440);
538 if (0x66 == aPic.MFP.mm)
540 //These ones have names prepended
541 sal_uInt8 nNameLen=0;
542 *pDataStream >> nNameLen;
543 pDataStream->SeekRel( nNameLen );
546 Rectangle aChildRect;
547 Rectangle aClientRect( 0,0, aPD.nWidth, aPD.nHeight);
548 SvxMSDffImportData aData( aClientRect );
549 pObject = pMSDffManager->ImportObj(*pDataStream, &aData, aClientRect, aChildRect );
550 if (pObject)
552 // fuer den Rahmen
553 SfxItemSet aAttrSet( rDoc.GetAttrPool(), RES_FRMATR_BEGIN,
554 RES_FRMATR_END-1 );
556 SvxMSDffImportRec const*const pRecord = (1 == aData.size())
557 ? &*aData.begin() : 0;
559 if( pRecord )
562 // Horizontal rule may have its width given as % of page width
563 // (-1 is used if not given, 0 means the object has fixed width).
564 // Additionally, if it's a horizontal rule without width given,
565 // assume 100.0% width.
566 int relativeWidth = pRecord->relativeHorizontalWidth;
567 if( relativeWidth == -1 )
568 relativeWidth = pRecord->isHorizontalRule ? 1000 : 0;
569 if( relativeWidth != 0 )
571 aPic.mx = msword_cast<sal_uInt16>(
572 maSectionManager.GetPageWidth() -
573 maSectionManager.GetPageRight() -
574 maSectionManager.GetPageLeft()) * relativeWidth / 1000;
575 aPD = WW8PicDesc( aPic );
576 // This SetSnapRect() call adjusts the size of the object itself,
577 // no idea why it's this call (or even what the call actually does),
578 // but that's what ImportGraf() (called by ImportObj()) uses.
579 pObject->SetSnapRect( Rectangle( 0, 0, aPD.nWidth, aPD.nHeight ));
582 //A graphic of this type in this location is always
583 //inline, and uses the pic in the same mould as ww6
584 //graphics.
585 if (pWFlyPara && pWFlyPara->bGrafApo)
587 WW8FlySet aFlySet(*this, pWFlyPara, pSFlyPara, true);
589 SwFmtAnchor aAnchor(pSFlyPara->eAnchor);
590 aAnchor.SetAnchor(pPaM->GetPoint());
591 aFlySet.Put(aAnchor);
593 aAttrSet.Put(aFlySet);
595 else
597 WW8FlySet aFlySet( *this, pPaM, aPic, aPD.nWidth,
598 aPD.nHeight );
600 aAttrSet.Put(aFlySet);
602 //Modified for i120716,for graf importing from MS Word 2003 binary format,
603 //there is no border distance.
604 Rectangle aInnerDist(0,0,0,0);
605 MatchSdrItemsIntoFlySet( pObject, aAttrSet,
606 pRecord->eLineStyle, pRecord->eLineDashing,
607 pRecord->eShapeType, aInnerDist );
609 //Groesse aus der WinWord PIC-Struktur als
610 //Grafik-Groesse nehmen
611 aAttrSet.Put( SwFmtFrmSize( ATT_FIX_SIZE, aPD.nWidth,
612 aPD.nHeight ) );
615 // for the Grafik
616 SfxItemSet aGrSet( rDoc.GetAttrPool(), RES_GRFATR_BEGIN,
617 RES_GRFATR_END-1 );
619 if( aPD.nCL || aPD.nCR || aPD.nCT || aPD.nCB )
621 SwCropGrf aCrop( aPD.nCL, aPD.nCR, aPD.nCT, aPD.nCB );
622 aGrSet.Put( aCrop );
625 if (pRecord)
626 MatchEscherMirrorIntoFlySet(*pRecord, aGrSet);
628 // ggfs. altes AttrSet uebernehmen und
629 // horiz. Positionierungs-Relation korrigieren
630 if( pOldFlyFmt )
632 aAttrSet.Put( pOldFlyFmt->GetAttrSet() );
633 const SwFmtHoriOrient &rHori = pOldFlyFmt->GetHoriOrient();
634 if( text::RelOrientation::FRAME == rHori.GetRelationOrient() )
636 aAttrSet.Put( SwFmtHoriOrient( rHori.GetPos(),
637 text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ) );
641 bool bTextObjWasGrouped = false;
642 if (pOldFlyFmt && pTextObj && pTextObj->GetUpGroup())
643 bTextObjWasGrouped = true;
645 if (bTextObjWasGrouped)
646 ReplaceObj(*pTextObj, *pObject);
647 else
649 if (sal_uInt16(OBJ_OLE2) == pObject->GetObjIdentifier())
651 // the size from BLIP, if there is any, should be already set
652 pRet = InsertOle(*((SdrOle2Obj*)pObject), aAttrSet, aGrSet);
654 else
656 if (SdrGrafObj* pGraphObject = PTR_CAST(SdrGrafObj, pObject))
658 // Nun den Link bzw. die Grafik ins Doc stopfen
659 const Graphic& rGraph = pGraphObject->GetGraphic();
661 if (nObjLocFc) // is it a OLE-Object?
662 pRet = ImportOle(&rGraph, &aAttrSet, &aGrSet, pObject->GetBLIPSizeRectangle());
664 if (!pRet)
666 pRet = rDoc.Insert(*pPaM, aEmptyStr, aEmptyStr,
667 &rGraph, &aAttrSet, &aGrSet, NULL );
670 else
671 pRet = rDoc.Insert(*pPaM, *pObject, &aAttrSet, NULL);
675 // also nur, wenn wir ein *Insert* gemacht haben
676 if (pRet)
678 if (pRecord)
679 SetAttributesAtGrfNode(pRecord, pRet, 0);
681 // #i68101#
682 // removed pObject->HasSetName() usage since always returned true,
683 // also removed else-part and wrote an informing mail to Henning Brinkmann
684 // about this to clarify.
685 pRet->SetName(pObject->GetName());
687 // Zeiger auf neues Objekt ermitteln und Z-Order-Liste
688 // entsprechend korrigieren (oder Eintrag loeschen)
689 if (SdrObject* pOurNewObject = CreateContactObject(pRet))
691 if (pOurNewObject != pObject)
693 pMSDffManager->ExchangeInShapeOrder( pObject, 0, 0,
694 pOurNewObject );
696 // altes SdrGrafObj aus der Page loeschen und
697 // zerstoeren
698 if (pObject->GetPage())
699 pDrawPg->RemoveObject(pObject->GetOrdNum());
700 SdrObject::Free( pObject );
703 else
704 pMSDffManager->RemoveFromShapeOrder( pObject );
706 else
707 pMSDffManager->RemoveFromShapeOrder( pObject );
709 // auch das ggfs. Page loeschen, falls nicht gruppiert,
710 if (pTextObj && !bTextObjWasGrouped && pTextObj->GetPage())
711 pDrawPg->RemoveObject( pTextObj->GetOrdNum() );
713 pMSDffManager->EnableFallbackStream();
715 else if (aPic.lcb >= 58)
716 pRet = ImportGraf1(aPic, pDataStream, nPicLocFc);
718 pDataStream->Seek( nOldPos );
720 if (pRet)
722 SdrObject* pOurNewObject = CreateContactObject(pRet);
723 pWWZOrder->InsertTextLayerObject(pOurNewObject);
726 return AddAutoAnchor(pRet);
729 #ifdef __WW8_NEEDS_COPY
731 void WW8PicShadowToReal( WW8_PIC_SHADOW * pPicS, WW8_PIC * pPic )
733 pPic->lcb = SVBT32ToUInt32( pPicS->lcb );
734 pPic->cbHeader = SVBT16ToShort( pPicS->cbHeader );
735 pPic->MFP.mm = SVBT16ToShort( pPicS->MFP.mm );
736 pPic->MFP.xExt = SVBT16ToShort( pPicS->MFP.xExt );
737 pPic->MFP.yExt = SVBT16ToShort( pPicS->MFP.yExt );
738 pPic->MFP.hMF = SVBT16ToShort( pPicS->MFP.hMF );
739 for( sal_uInt16 i = 0; i < 14 ; i++ )
740 pPic->rcWinMF[i] = SVBT8ToByte( pPicS->rcWinMF[i] );
741 pPic->dxaGoal = SVBT16ToShort( pPicS->dxaGoal );
742 pPic->dyaGoal = SVBT16ToShort( pPicS->dyaGoal );
743 pPic->mx = SVBT16ToShort( pPicS->mx );
744 pPic->my = SVBT16ToShort( pPicS->my );
745 pPic->dxaCropLeft = SVBT16ToShort( pPicS->dxaCropLeft );
746 pPic->dyaCropTop = SVBT16ToShort( pPicS->dyaCropTop );
747 pPic->dxaCropRight = SVBT16ToShort( pPicS->dxaCropRight );
748 pPic->dyaCropBottom = SVBT16ToShort( pPicS->dyaCropBottom );
749 pPic->brcl = pPicS->aBits1[0] & 0x0f;
750 pPic->fFrameEmpty = (pPicS->aBits1[0] & 0x10) >> 4;
751 pPic->fBitmap = (pPicS->aBits1[0] & 0x20) >> 5;
752 pPic->fDrawHatch = (pPicS->aBits1[0] & 0x40) >> 6;
753 pPic->fError = (pPicS->aBits1[0] & 0x80) >> 7;
754 pPic->bpp = pPicS->aBits2[0];
757 void WW8FSPAShadowToReal( WW8_FSPA_SHADOW * pFSPAS, WW8_FSPA * pFSPA )
759 pFSPA->nSpId = SVBT32ToUInt32( pFSPAS->nSpId );
760 pFSPA->nXaLeft = SVBT32ToUInt32( pFSPAS->nXaLeft );
761 pFSPA->nYaTop = SVBT32ToUInt32( pFSPAS->nYaTop );
762 pFSPA->nXaRight = SVBT32ToUInt32( pFSPAS->nXaRight );
763 pFSPA->nYaBottom = SVBT32ToUInt32( pFSPAS->nYaBottom );
765 sal_uInt16 nBits = SVBT16ToShort( pFSPAS->aBits1 );
767 pFSPA->bHdr = 0 != ( nBits & 0x0001 );
768 pFSPA->nbx = ( nBits & 0x0006 ) >> 1;
769 pFSPA->nby = ( nBits & 0x0018 ) >> 3;
770 pFSPA->nwr = ( nBits & 0x01E0 ) >> 5;
771 pFSPA->nwrk = ( nBits & 0x1E00 ) >> 9;
772 pFSPA->bRcaSimple = 0 != ( nBits & 0x2000 );
773 pFSPA->bBelowText = 0 != ( nBits & 0x4000 );
774 pFSPA->bAnchorLock = 0 != ( nBits & 0x8000 );
775 pFSPA->nTxbx = SVBT32ToUInt32( pFSPAS->nTxbx );
777 #endif // defined __WW8_NEEDS_COPY
779 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */