From bd55f05b332c1573bd410fd9e21ea7fcf977e1b0 Mon Sep 17 00:00:00 2001 From: Armin Le Grand Date: Tue, 15 May 2012 10:16:23 +0000 Subject: Resolves: #i118780# Moved ObjectInfoPrimitive2D extractor to drawinglayer... changed name to be the filename only, added code to SW to set Title and Desc Conflicts: drawinglayer/Library_drawinglayer.mk drawinglayer/Package_inc.mk svx/source/svdraw/svdograf.cxx sw/inc/ndgrf.hxx sw/source/core/doc/doc.cxx sw/source/core/doc/notxtfrm.cxx sw/source/core/docnode/swbaslnk.cxx sw/source/core/graphic/ndgrf.cxx sw/source/filter/rtf/rtffly.cxx Change-Id: Id433031958529498441574dafe2fbd5261371efc --- drawinglayer/Library_drawinglayer.mk | 1 + drawinglayer/Package_inc.mk | 1 + .../processor2d/objectinfoextractor2d.hxx | 61 ++++++++ .../source/processor2d/objectinfoextractor2d.cxx | 67 ++++++++ svgio/source/svgreader/svgnode.cxx | 11 ++ svx/inc/svx/svdograf.hxx | 1 + svx/source/svdraw/svdograf.cxx | 59 +++++++ sw/inc/ndgrf.hxx | 27 +++- sw/source/core/doc/doc.cxx | 14 +- sw/source/core/doc/notxtfrm.cxx | 21 +-- sw/source/core/docnode/swbaslnk.cxx | 18 ++- sw/source/core/graphic/ndgrf.cxx | 171 +++++++++++++++------ 12 files changed, 373 insertions(+), 79 deletions(-) create mode 100644 drawinglayer/inc/drawinglayer/processor2d/objectinfoextractor2d.hxx create mode 100644 drawinglayer/source/processor2d/objectinfoextractor2d.cxx diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk index 8e7d44e1a3fe..daa522a59b55 100644 --- a/drawinglayer/Library_drawinglayer.mk +++ b/drawinglayer/Library_drawinglayer.mk @@ -164,6 +164,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\ drawinglayer/source/processor2d/helperwrongspellrenderer \ drawinglayer/source/processor2d/hittestprocessor2d \ drawinglayer/source/processor2d/linegeometryextractor2d \ + drawinglayer/source/processor2d/objectinfoextractor2d \ drawinglayer/source/processor2d/processorfromoutputdevice \ drawinglayer/source/processor2d/textaspolygonextractor2d \ drawinglayer/source/processor2d/vclhelperbitmaprender \ diff --git a/drawinglayer/Package_inc.mk b/drawinglayer/Package_inc.mk index fe492b16101f..23e8b81fd697 100644 --- a/drawinglayer/Package_inc.mk +++ b/drawinglayer/Package_inc.mk @@ -131,6 +131,7 @@ $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/ $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/hittestprocessor2d.hxx,drawinglayer/processor2d/hittestprocessor2d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/processorfromoutputdevice.hxx,drawinglayer/processor2d/processorfromoutputdevice.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/linegeometryextractor2d.hxx,drawinglayer/processor2d/linegeometryextractor2d.hxx)) +$(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/objectinfoextractor2d.hxx,drawinglayer/processor2d/objectinfoextractor2d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/textaspolygonextractor2d.hxx,drawinglayer/processor2d/textaspolygonextractor2d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/vclmetafileprocessor2d.hxx,drawinglayer/processor2d/vclmetafileprocessor2d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor2d/vclpixelprocessor2d.hxx,drawinglayer/processor2d/vclpixelprocessor2d.hxx)) diff --git a/drawinglayer/inc/drawinglayer/processor2d/objectinfoextractor2d.hxx b/drawinglayer/inc/drawinglayer/processor2d/objectinfoextractor2d.hxx new file mode 100644 index 000000000000..42f4fb3970de --- /dev/null +++ b/drawinglayer/inc/drawinglayer/processor2d/objectinfoextractor2d.hxx @@ -0,0 +1,61 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_DRAWINGLAYER_PROCESSOR2D_OBJECTINFOEXTRACTOR2D_HXX +#define INCLUDED_DRAWINGLAYER_PROCESSOR2D_OBJECTINFOEXTRACTOR2D_HXX + +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +namespace drawinglayer { namespace primitive2d { class ObjectInfoPrimitive2D; }} + +////////////////////////////////////////////////////////////////////////////// + +namespace drawinglayer +{ + namespace processor2d + { + /** ObjectInfoPrimitiveExtractor2D class + + A processor to find the first incarnation of ObjectInfoPrimitive2D + in a given hierarchy + */ + class DRAWINGLAYER_DLLPUBLIC ObjectInfoPrimitiveExtractor2D : public BaseProcessor2D + { + private: + /// the target + const primitive2d::ObjectInfoPrimitive2D* mpFound; + + /// tooling methods + void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate); + + public: + ObjectInfoPrimitiveExtractor2D(const geometry::ViewInformation2D& rViewInformation); + virtual ~ObjectInfoPrimitiveExtractor2D(); + + const primitive2d::ObjectInfoPrimitive2D* getResult() const { return mpFound; } + }; + } // end of namespace processor2d +} // end of namespace drawinglayer + +////////////////////////////////////////////////////////////////////////////// + +#endif // INCLUDED_DRAWINGLAYER_PROCESSOR2D_OBJECTINFOEXTRACTOR2D_HXX + +// eof diff --git a/drawinglayer/source/processor2d/objectinfoextractor2d.cxx b/drawinglayer/source/processor2d/objectinfoextractor2d.cxx new file mode 100644 index 000000000000..d6171ce72c0b --- /dev/null +++ b/drawinglayer/source/processor2d/objectinfoextractor2d.cxx @@ -0,0 +1,67 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////// + +using namespace com::sun::star; + +////////////////////////////////////////////////////////////////////////////// + +namespace drawinglayer +{ + namespace processor2d + { + void ObjectInfoPrimitiveExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) + { + if(!mpFound) + { + switch(rCandidate.getPrimitive2DID()) + { + case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D : + { + mpFound = dynamic_cast< const primitive2d::ObjectInfoPrimitive2D* >(&rCandidate); + break; + } + default : + { + // process recursively + process(rCandidate.get2DDecomposition(getViewInformation2D())); + break; + } + } + } + } + + ObjectInfoPrimitiveExtractor2D::ObjectInfoPrimitiveExtractor2D(const geometry::ViewInformation2D& rViewInformation) + : BaseProcessor2D(rViewInformation), + mpFound(0) + { + } + + ObjectInfoPrimitiveExtractor2D::~ObjectInfoPrimitiveExtractor2D() + { + } + } // end of namespace processor2d +} // end of namespace drawinglayer + +////////////////////////////////////////////////////////////////////////////// +// eof diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx index acab42aeadee..639aa0cafadb 100644 --- a/svgio/source/svgreader/svgnode.cxx +++ b/svgio/source/svgreader/svgnode.cxx @@ -22,6 +22,7 @@ #include #include #include +#include ////////////////////////////////////////////////////////////////////////////// @@ -204,6 +205,16 @@ namespace svgio if(SVGTokenSvg == getType()) { aObjectName = getDocument().getAbsolutePath(); + + if(aObjectName.getLength()) + { + INetURLObject aURL(aObjectName); + + aObjectName = aURL.getName( + INetURLObject::LAST_SEGMENT, + true, + INetURLObject::DECODE_WITH_CHARSET); + } } // pack in ObjectInfoPrimitive2D group diff --git a/svx/inc/svx/svdograf.hxx b/svx/inc/svx/svdograf.hxx index ba50873914ae..1399ca9f629a 100644 --- a/svx/inc/svx/svdograf.hxx +++ b/svx/inc/svx/svdograf.hxx @@ -116,6 +116,7 @@ private: bool ImpUpdateGraphicLink( bool bAsynchron = true ) const; void ImpSetLinkedGraphic( const Graphic& rGraphic ); DECL_LINK( ImpSwapHdl, GraphicObject* ); + void onGraphicChanged(); public: TYPEINFO(); diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index dfdc9adfe6c8..c9622d1ca5e2 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -58,6 +58,8 @@ #include #include #include +#include +#include using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -301,6 +303,58 @@ sdr::contact::ViewContact* SdrGrafObj::CreateObjectSpecificViewContact() return new sdr::contact::ViewContactOfGraphic(*this); } +////////////////////////////////////////////////////////////////////////////// +// check if SVG and if try to get ObjectInfoPrimitive2D and extract info + +void SdrGrafObj::onGraphicChanged() +{ + String aName; + String aTitle; + String aDesc; + + if(pGraphic) + { + const SvgDataPtr& rSvgDataPtr = pGraphic->GetGraphic().getSvgData(); + + if(rSvgDataPtr.get()) + { + const drawinglayer::primitive2d::Primitive2DSequence aSequence(rSvgDataPtr->getPrimitive2DSequence()); + + if(aSequence.hasElements()) + { + drawinglayer::geometry::ViewInformation2D aViewInformation2D; + drawinglayer::processor2d::ObjectInfoPrimitiveExtractor2D aProcessor(aViewInformation2D); + + aProcessor.process(aSequence); + + const drawinglayer::primitive2d::ObjectInfoPrimitive2D* pResult = aProcessor.getResult(); + + if(pResult) + { + aName = pResult->getName(); + aTitle = pResult->getTitle(); + aDesc = pResult->getDesc(); + } + } + } + } + + if(aName.Len()) + { + SetName(aName); + } + + if(aTitle.Len()) + { + SetTitle(aTitle); + } + + if(aDesc.Len()) + { + SetDescription(aDesc); + } +} + ////////////////////////////////////////////////////////////////////////////// TYPEINIT1(SdrGrafObj,SdrRectObj); @@ -315,6 +369,7 @@ SdrGrafObj::SdrGrafObj() pGraphic = new GraphicObject; mpReplacementGraphic = 0; pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); + onGraphicChanged(); // #i118485# Shear allowed and possible now bNoShear = false; @@ -340,6 +395,7 @@ SdrGrafObj::SdrGrafObj(const Graphic& rGrf, const Rectangle& rRect) pGraphic = new GraphicObject( rGrf ); mpReplacementGraphic = 0; pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); + onGraphicChanged(); // #i118485# Shear allowed and possible now bNoShear = false; @@ -365,6 +421,7 @@ SdrGrafObj::SdrGrafObj( const Graphic& rGrf ) pGraphic = new GraphicObject( rGrf ); mpReplacementGraphic = 0; pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); + onGraphicChanged(); // #i118485# Shear allowed and possible now bNoShear = false; @@ -401,6 +458,7 @@ void SdrGrafObj::SetGraphicObject( const GraphicObject& rGrfObj ) mbIsPreview = false; SetChanged(); BroadcastObjectChange(); + onGraphicChanged(); } // ----------------------------------------------------------------------------- @@ -439,6 +497,7 @@ void SdrGrafObj::NbcSetGraphic( const Graphic& rGrf ) mpReplacementGraphic = 0; pGraphic->SetUserData(); mbIsPreview = false; + onGraphicChanged(); } void SdrGrafObj::SetGraphic( const Graphic& rGrf ) diff --git a/sw/inc/ndgrf.hxx b/sw/inc/ndgrf.hxx index bf01d924ce46..e970615e9fe8 100644 --- a/sw/inc/ndgrf.hxx +++ b/sw/inc/ndgrf.hxx @@ -37,7 +37,7 @@ class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode { friend class SwNodes; - GraphicObject aGrfObj; + GraphicObject maGrfObj; GraphicObject *mpReplacementGraphic; ::sfx2::SvBaseLinkRef refLink; ///< If graphics only as link then pointer is set. Size nGrfSize; @@ -76,7 +76,7 @@ class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode void InsertLink( const String& rGrfName, const String& rFltName ); sal_Bool ImportGraphic( SvStream& rStrm ); - sal_Bool HasStreamName() const { return aGrfObj.HasUserData(); } + sal_Bool HasStreamName() const { return maGrfObj.HasUserData(); } /** adjust return type and rename method to indicate that its an private one. */ @@ -128,20 +128,31 @@ class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode public: virtual ~SwGrfNode(); - const Graphic& GetGrf() const { return aGrfObj.GetGraphic(); } - const GraphicObject& GetGrfObj() const { return aGrfObj; } - GraphicObject& GetGrfObj() { return aGrfObj; } + const Graphic& GetGrf() const { return maGrfObj.GetGraphic(); } + const GraphicObject& GetGrfObj() const { return maGrfObj; } const GraphicObject* GetReplacementGrfObj() const; - virtual SwCntntNode *SplitCntntNode( const SwPosition & ); + /// isolated only way to set GraphicObject to allow more actions when doing so + void SetGraphic(const Graphic& rGraphic, const String& rLink); + + /// wrappers for non-const calls at GraphicObject + void ReleaseGraphicFromCache() { maGrfObj.ReleaseFromCache(); } + void DrawGraphicWithPDFHandling(OutputDevice& rOutDev, const Point& rPt, const Size& rSz, const GraphicAttr* pGrfAttr = NULL, const sal_uLong nFlags = GRFMGR_DRAW_STANDARD) { maGrfObj.DrawWithPDFHandling(rOutDev, rPt, rSz, pGrfAttr, nFlags); } + void StartGraphicAnimation(OutputDevice* pOut, const Point& rPt, const Size& rSz, long nExtraData = 0, const GraphicAttr* pAttr = NULL, sal_uLong nFlags = GRFMGR_DRAW_STANDARD, OutputDevice* pFirstFrameOutDev = NULL) { maGrfObj.StartAnimation(pOut, rPt, rSz, nExtraData, pAttr, nFlags, pFirstFrameOutDev); } + void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); } + + /// allow reaction on change of content of GraphicObject, so always call + /// when GraphicObject content changes + void onGraphicChanged(); + virtual Size GetTwipSize() const; #ifndef _FESHVIEW_ONLY_INLINE_NEEDED void SetTwipSize( const Size& rSz ); sal_Bool IsTransparent() const; - inline sal_Bool IsAnimated() const { return aGrfObj.IsAnimated(); } + inline sal_Bool IsAnimated() const { return maGrfObj.IsAnimated(); } inline sal_Bool IsChgTwipSize() const { return bChgTwipSize; } inline sal_Bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; } @@ -171,7 +182,7 @@ public: /// Remove graphic in order to free memory. short SwapOut(); /// Access to storage stream-name. - void SetStreamName( const String& r ) { aGrfObj.SetUserData( r ); } + void SetStreamName( const String& r ) { maGrfObj.SetUserData( r ); } void SetNewStreamName( const String& r ) { aNewStrmName = r; } /// Is this node selected by any shell? sal_Bool IsSelected() const; diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index c6a5c444c85f..670059091ebe 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1039,11 +1039,14 @@ SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg, { if( !pFrmFmt ) pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC ); - return _InsNoTxtNode( *rRg.GetPoint(), GetNodes().MakeGrfNode( + SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode( SwNodeIndex( GetNodes().GetEndOfAutotext() ), rGrfName, rFltName, pGraphic, - mpDfltGrfFmtColl ), + mpDfltGrfFmtColl ); + SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode, pFlyAttrSet, pGrfAttrSet, pFrmFmt ); + pSwGrfNode->onGraphicChanged(); + return pSwFlyFrmFmt; } SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg, const GraphicObject& rGrfObj, @@ -1053,10 +1056,13 @@ SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg, const GraphicObject& rGrfObj, { if( !pFrmFmt ) pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC ); - return _InsNoTxtNode( *rRg.GetPoint(), GetNodes().MakeGrfNode( + SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode( SwNodeIndex( GetNodes().GetEndOfAutotext() ), - rGrfObj, mpDfltGrfFmtColl ), + rGrfObj, mpDfltGrfFmtColl ); + SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode, pFlyAttrSet, pGrfAttrSet, pFrmFmt ); + pSwGrfNode->onGraphicChanged(); + return pSwFlyFrmFmt; } SwFlyFrmFmt* SwDoc::Insert(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj, diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index 05935356fc0f..c42d80201065 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -609,7 +609,7 @@ sal_Bool SwNoTxtFrm::GetCrsrOfst(SwPosition* pPos, Point& , } #define CLEARCACHE( pNd ) {\ - (pNd)->GetGrfObj().ReleaseFromCache();\ + (pNd)->ReleaseGraphicFromCache();\ SwFlyFrm* pFly = FindFlyFrm();\ if( pFly && pFly->GetFmt()->GetSurround().IsContour() )\ {\ @@ -907,7 +907,7 @@ void SwNoTxtFrm::PaintPicture( OutputDevice* pOut, const SwRect &rGrfArea ) cons } bool bForceSwap = false, bContinue = true; - GraphicObject& rGrfObj = pGrfNd->GetGrfObj(); + const GraphicObject& rGrfObj = pGrfNd->GetGrfObj(); GraphicAttr aGrfAttr; pGrfNd->GetGraphicAttr( aGrfAttr, this ); @@ -944,9 +944,9 @@ void SwNoTxtFrm::PaintPicture( OutputDevice* pOut, const SwRect &rGrfArea ) cons else if( rGrfObj.IsCached( pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), &aGrfAttr )) { - rGrfObj.DrawWithPDFHandling( *pOut, - aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), - &aGrfAttr ); + pGrfNd->DrawGraphicWithPDFHandling(*pOut, + aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), + &aGrfAttr ); bContinue = false; } } @@ -979,7 +979,7 @@ void SwNoTxtFrm::PaintPicture( OutputDevice* pOut, const SwRect &rGrfArea ) cons pShell->GetViewOptions()->IsPDFExport(), "pOut should not be a virtual device" ); - rGrfObj.StartAnimation( pOut, aAlignedGrfArea.Pos(), + pGrfNd->StartGraphicAnimation(pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), long(this), 0, GRFMGR_DRAW_STANDARD, pVout ); } @@ -1012,7 +1012,7 @@ void SwNoTxtFrm::PaintPicture( OutputDevice* pOut, const SwRect &rGrfArea ) cons if(!bDone) { // fallback paint, uses replacement image - rGrfObj.DrawWithPDFHandling(*pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), &aGrfAttr); + pGrfNd->DrawGraphicWithPDFHandling(*pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), &aGrfAttr); } } } @@ -1170,9 +1170,12 @@ sal_Bool SwNoTxtFrm::IsTransparent() const void SwNoTxtFrm::StopAnimation( OutputDevice* pOut ) const { // Stop animated graphics - SwGrfNode* pGrfNd = (SwGrfNode*)GetNode()->GetGrfNode(); + const SwGrfNode* pGrfNd = dynamic_cast< const SwGrfNode* >(GetNode()->GetGrfNode()); + if( pGrfNd && pGrfNd->IsAnimated() ) - pGrfNd->GetGrfObj().StopAnimation( pOut, long(this) ); + { + const_cast< SwGrfNode* >(pGrfNd)->StopGraphicAnimation( pOut, long(this) ); + } } diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx index 88ddb0091f71..6dcee9022f1e 100644 --- a/sw/source/core/docnode/swbaslnk.cxx +++ b/sw/source/core/docnode/swbaslnk.cxx @@ -135,13 +135,15 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) if( pCntntNode->IsGrfNode() ) { - GraphicObject& rGrfObj = ((SwGrfNode*)pCntntNode)->GetGrfObj(); + SwGrfNode* pSwGrfNode = dynamic_cast< SwGrfNode* >(pCntntNode); + OSL_ENSURE(pSwGrfNode, "Error, pSwGrfNode expected when node answers IsGrfNode() with true (!)"); + const GraphicObject& rGrfObj = pSwGrfNode->GetGrfObj(); - bDontNotify = ((SwGrfNode*)pCntntNode)->IsFrameInPaint(); + bDontNotify = pSwGrfNode->IsFrameInPaint(); bGraphicArrived = GetObj()->IsDataComplete(); bGraphicPieceArrived = GetObj()->IsPending(); - ((SwGrfNode*)pCntntNode)->SetGrafikArrived( bGraphicArrived ); + pSwGrfNode->SetGrafikArrived( bGraphicArrived ); Graphic aGrf; if( sfx2::LinkManager::GetGraphicFromAny( rMimeType, rValue, aGrf ) && @@ -149,7 +151,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) GRAPHIC_DEFAULT != rGrfObj.GetType() ) ) { aGrfSz = ::GetGraphicSizeTwip( aGrf, 0 ); - if( static_cast< const SwGrfNode * >( pCntntNode )->IsChgTwipSizeFromPixel() ) + if( pSwGrfNode->IsChgTwipSizeFromPixel() ) { const MapMode aMapTwip( MAP_TWIP ); aFrmFmtSz = @@ -161,7 +163,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) { aFrmFmtSz = aGrfSz; } - Size aSz( ((SwGrfNode*)pCntntNode)->GetTwipSize() ); + Size aSz( pSwGrfNode->GetTwipSize() ); if( bGraphicPieceArrived && GRAPHIC_DEFAULT != aGrf.GetType() && ( !aSz.Width() || !aSz.Height() ) ) @@ -173,7 +175,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) bGraphicPieceArrived = sal_False; } - rGrfObj.SetGraphic( aGrf, rGrfObj.GetLink() ); + pSwGrfNode->SetGraphic(aGrf, rGrfObj.GetLink()); bUpdate = true; // In order for the Node to have the right transparency status @@ -185,11 +187,11 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem ) if( aGrfSz.Height() && aGrfSz.Width() && aSz.Height() && aSz.Width() && aGrfSz != aSz ) - ((SwGrfNode*)pCntntNode)->SetTwipSize( aGrfSz ); + pSwGrfNode->SetTwipSize( aGrfSz ); } } if ( bUpdate && !bGraphicArrived && !bGraphicPieceArrived ) - ((SwGrfNode*)pCntntNode)->SetTwipSize( Size(0,0) ); + pSwGrfNode->SetTwipSize( Size(0,0) ); } else if( pCntntNode->IsOLENode() ) bUpdate = true; diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx index b30c26d93aeb..96365a4519a1 100644 --- a/sw/source/core/graphic/ndgrf.cxx +++ b/sw/source/core/graphic/ndgrf.cxx @@ -49,8 +49,9 @@ #include #include #include -// #i73788# #include +#include +#include using namespace com::sun::star; @@ -64,13 +65,13 @@ SwGrfNode::SwGrfNode( SwGrfFmtColl *pGrfColl, SwAttrSet* pAutoAttr ) : SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ), - aGrfObj(), + maGrfObj(), mpReplacementGraphic(0), // #i73788# mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( sal_False ) { - aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); + maGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel = bLoadLowResGrf = bFrameInPaint = bScaleImageMap = sal_False; @@ -82,16 +83,15 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere, const GraphicObject& rGrfObj, SwGrfFmtColl *pGrfColl, SwAttrSet* pAutoAttr ) : SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ), - aGrfObj(), + maGrfObj(rGrfObj), mpReplacementGraphic(0), // #i73788# mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( sal_False ) { - aGrfObj = rGrfObj; - aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); + maGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); if( rGrfObj.HasUserData() && rGrfObj.IsSwappedOut() ) - aGrfObj.SetSwapState(); + maGrfObj.SetSwapState(); bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel= bLoadLowResGrf = bFrameInPaint = bScaleImageMap = sal_False; bGrafikArrived = sal_True; @@ -106,16 +106,16 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere, SwGrfFmtColl *pGrfColl, SwAttrSet* pAutoAttr ) : SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ), - aGrfObj(), + maGrfObj(), mpReplacementGraphic(0), // #i73788# mbLinkedInputStreamReady( false ), mbIsStreamReadOnly( sal_False ) { - aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); + maGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) ); Graphic aGrf; aGrf.SetDefaultType(); - aGrfObj.SetGraphic( aGrf, rGrfName ); + maGrfObj.SetGraphic( aGrf, rGrfName ); bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel = bLoadLowResGrf = bFrameInPaint = bScaleImageMap = sal_False; @@ -184,15 +184,17 @@ sal_Bool SwGrfNode::ReRead( if( pGraphic ) { - aGrfObj.SetGraphic( *pGraphic, rGrfName ); + maGrfObj.SetGraphic( *pGraphic, rGrfName ); + onGraphicChanged(); bReadGrf = sal_True; } else if( pGrfObj ) { - aGrfObj = *pGrfObj; + maGrfObj = *pGrfObj; if( pGrfObj->HasUserData() && pGrfObj->IsSwappedOut() ) - aGrfObj.SetSwapState(); - aGrfObj.SetLink( rGrfName ); + maGrfObj.SetSwapState(); + maGrfObj.SetLink( rGrfName ); + onGraphicChanged(); bReadGrf = sal_True; } else @@ -201,7 +203,7 @@ sal_Bool SwGrfNode::ReRead( // die korrekte Ersatz-Darstellung erscheint, wenn die // der neue Link nicht geladen werden konnte. Graphic aGrf; aGrf.SetDefaultType(); - aGrfObj.SetGraphic( aGrf, rGrfName ); + maGrfObj.SetGraphic( aGrf, rGrfName ); if( refLink.Is() ) { @@ -219,6 +221,7 @@ sal_Bool SwGrfNode::ReRead( ((SwBaseLink*)&refLink)->SwapIn(); } } + onGraphicChanged(); bSetTwipSize = sal_False; } } @@ -228,7 +231,8 @@ sal_Bool SwGrfNode::ReRead( if( HasStreamName() ) DelStreamName(); - aGrfObj.SetGraphic( *pGraphic ); + maGrfObj.SetGraphic( *pGraphic ); + onGraphicChanged(); bReadGrf = sal_True; } else if( pGrfObj && !rGrfName.Len() ) @@ -237,14 +241,15 @@ sal_Bool SwGrfNode::ReRead( if( HasStreamName() ) DelStreamName(); - aGrfObj = *pGrfObj; + maGrfObj = *pGrfObj; + onGraphicChanged(); if( pGrfObj->HasUserData() && pGrfObj->IsSwappedOut() ) - aGrfObj.SetSwapState(); + maGrfObj.SetSwapState(); bReadGrf = sal_True; } // Import einer Grafik: // Ist die Grafik bereits geladen? - else if( !bNewGrf && GRAPHIC_NONE != aGrfObj.GetType() ) + else if( !bNewGrf && GRAPHIC_NONE != maGrfObj.GetType() ) return sal_True; else @@ -259,15 +264,17 @@ sal_Bool SwGrfNode::ReRead( { if( pGraphic ) { - aGrfObj.SetGraphic( *pGraphic, rGrfName ); + maGrfObj.SetGraphic( *pGraphic, rGrfName ); + onGraphicChanged(); bReadGrf = sal_True; // Verbindung herstellen ohne ein Update; Grafik haben wir! ((SwBaseLink*)&refLink)->Connect(); } else if( pGrfObj ) { - aGrfObj = *pGrfObj; - aGrfObj.SetLink( rGrfName ); + maGrfObj = *pGrfObj; + maGrfObj.SetLink( rGrfName ); + onGraphicChanged(); bReadGrf = sal_True; // Verbindung herstellen ohne ein Update; Grafik haben wir! ((SwBaseLink*)&refLink)->Connect(); @@ -278,7 +285,8 @@ sal_Bool SwGrfNode::ReRead( // die korrekte Ersatz-Darstellung erscheint, wenn die // der neue Kink nicht geladen werden konnte. Graphic aGrf; aGrf.SetDefaultType(); - aGrfObj.SetGraphic( aGrf, rGrfName ); + maGrfObj.SetGraphic( aGrf, rGrfName ); + onGraphicChanged(); // #i59688# - do not load linked graphic, if it isn't a new linked graphic. if ( bNewGrf ) { @@ -291,7 +299,7 @@ sal_Bool SwGrfNode::ReRead( // Bug 39281: Size nicht sofort loeschen - Events auf ImageMaps // sollten nicht beim Austauschen nicht ins "leere greifen" if( bSetTwipSize ) - SetTwipSize( ::GetGraphicSizeTwip( aGrfObj.GetGraphic(), 0 ) ); + SetTwipSize( ::GetGraphicSizeTwip( maGrfObj.GetGraphic(), 0 ) ); // erzeuge noch einen Update auf die Frames if( bReadGrf && bNewGrf ) @@ -339,6 +347,67 @@ SwGrfNode::~SwGrfNode() DelFrms(); } +/// allow reaction on change of content of GraphicObject +void SwGrfNode::onGraphicChanged() +{ + // try to access SwFlyFrmFmt; since title/desc/name are set there, there is no + // use to continue if it is not yet set. If not yet set, call onGraphicChanged() + // when it is set. + SwFlyFrmFmt* pFlyFmt = dynamic_cast< SwFlyFrmFmt* >(GetFlyFmt()); + + if(pFlyFmt) + { + String aName; + String aTitle; + String aDesc; + const SvgDataPtr& rSvgDataPtr = GetGrf().getSvgData(); + + if(rSvgDataPtr.get()) + { + const drawinglayer::primitive2d::Primitive2DSequence aSequence(rSvgDataPtr->getPrimitive2DSequence()); + + if(aSequence.hasElements()) + { + drawinglayer::geometry::ViewInformation2D aViewInformation2D; + drawinglayer::processor2d::ObjectInfoPrimitiveExtractor2D aProcessor(aViewInformation2D); + + aProcessor.process(aSequence); + + const drawinglayer::primitive2d::ObjectInfoPrimitive2D* pResult = aProcessor.getResult(); + + if(pResult) + { + aName = pResult->getName(); + aTitle = pResult->getTitle(); + aDesc = pResult->getDesc(); + } + } + } + + // do not use this currently; it seems that this name has to be unique in + // the writer model and is already set to some default + //if(aName.Len() && pFlyFmt) + //{ + // pFlyFmt->SetName(aName); + //} + + if(aTitle.Len()) + { + SetTitle(aTitle); + } + + if(aDesc.Len()) + { + SetDescription(aDesc); + } + } +} + +void SwGrfNode::SetGraphic(const Graphic& rGraphic, const String& rLink) +{ + maGrfObj.SetGraphic(rGraphic, rLink); + onGraphicChanged(); +} const GraphicObject* SwGrfNode::GetReplacementGrfObj() const { @@ -399,15 +468,16 @@ Size SwGrfNode::GetTwipSize() const sal_Bool SwGrfNode::ImportGraphic( SvStream& rStrm ) { Graphic aGraphic; - const String aURL(aGrfObj.GetUserData()); + const String aURL(maGrfObj.GetUserData()); if(!GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, rStrm)) { delete mpReplacementGraphic; mpReplacementGraphic = 0; - aGrfObj.SetGraphic( aGraphic ); - aGrfObj.SetUserData( aURL ); + maGrfObj.SetGraphic( aGraphic ); + maGrfObj.SetUserData( aURL ); + onGraphicChanged(); return sal_True; } @@ -422,7 +492,7 @@ sal_Bool SwGrfNode::ImportGraphic( SvStream& rStrm ) short SwGrfNode::SwapIn( sal_Bool bWaitForData ) { if( bInSwapIn ) // nicht rekuriv!! - return !aGrfObj.IsSwappedOut(); + return !maGrfObj.IsSwappedOut(); short nRet = 0; bInSwapIn = sal_True; @@ -430,25 +500,26 @@ short SwGrfNode::SwapIn( sal_Bool bWaitForData ) if( pLink ) { - if( GRAPHIC_NONE == aGrfObj.GetType() || - GRAPHIC_DEFAULT == aGrfObj.GetType() ) + if( GRAPHIC_NONE == maGrfObj.GetType() || + GRAPHIC_DEFAULT == maGrfObj.GetType() ) { // noch nicht geladener Link //TODO pLink->setInputStream(getInputStream()); if( pLink->SwapIn( bWaitForData ) ) nRet = -1; - else if( GRAPHIC_DEFAULT == aGrfObj.GetType() ) + else if( GRAPHIC_DEFAULT == maGrfObj.GetType() ) { // keine default Bitmap mehr, also neu Painten! delete mpReplacementGraphic; mpReplacementGraphic = 0; - aGrfObj.SetGraphic( Graphic() ); + maGrfObj.SetGraphic( Graphic() ); + onGraphicChanged(); SwMsgPoolItem aMsgHint( RES_GRAPHIC_PIECE_ARRIVED ); ModifyNotification( &aMsgHint, &aMsgHint ); } } - else if( aGrfObj.IsSwappedOut() ) { + else if( maGrfObj.IsSwappedOut() ) { // nachzuladender Link //TODO pLink->setInputStream(getInputStream()); nRet = pLink->SwapIn( bWaitForData ) ? 1 : 0; @@ -456,11 +527,11 @@ short SwGrfNode::SwapIn( sal_Bool bWaitForData ) else nRet = 1; } - else if( aGrfObj.IsSwappedOut() ) + else if( maGrfObj.IsSwappedOut() ) { // Die Grafik ist im Storage oder im TempFile drin if( !HasStreamName() ) - nRet = (short)aGrfObj.SwapIn(); + nRet = (short)maGrfObj.SwapIn(); else { @@ -499,7 +570,7 @@ short SwGrfNode::SwapIn( sal_Bool bWaitForData ) if( nRet ) { if( !nGrfSize.Width() && !nGrfSize.Height() ) - SetTwipSize( ::GetGraphicSizeTwip( aGrfObj.GetGraphic(), 0 ) ); + SetTwipSize( ::GetGraphicSizeTwip( maGrfObj.GetGraphic(), 0 ) ); } bInSwapIn = sal_False; return nRet; @@ -508,9 +579,9 @@ short SwGrfNode::SwapIn( sal_Bool bWaitForData ) short SwGrfNode::SwapOut() { - if( aGrfObj.GetType() != GRAPHIC_DEFAULT && - aGrfObj.GetType() != GRAPHIC_NONE && - !aGrfObj.IsSwappedOut() && !bInSwapIn ) + if( maGrfObj.GetType() != GRAPHIC_DEFAULT && + maGrfObj.GetType() != GRAPHIC_NONE && + !maGrfObj.IsSwappedOut() && !bInSwapIn ) { if( !refLink.Is() ) { @@ -519,11 +590,11 @@ short SwGrfNode::SwapOut() // sie frisch eingefuegt war, d.h. wenn es noch keinen // Streamnamen im Storage gibt. if( !HasStreamName() ) - if( !aGrfObj.SwapOut() ) + if( !maGrfObj.SwapOut() ) return 0; } // Geschriebene Grafiken oder Links werden jetzt weggeschmissen - return (short) aGrfObj.SwapOut( NULL ); + return (short) maGrfObj.SwapOut( NULL ); } return 1; } @@ -633,7 +704,7 @@ void SwGrfNode::InsertLink( const String& rGrfName, const String& rFltName ) (!bSync && rFltName.Len() ? &rFltName : 0) ); } } - aGrfObj.SetLink( rGrfName ); + maGrfObj.SetLink( rGrfName ); } @@ -650,7 +721,7 @@ void SwGrfNode::ReleaseLink() } getIDocumentLinksAdministration()->GetLinkManager().Remove( refLink ); refLink.Clear(); - aGrfObj.SetLink(); + maGrfObj.SetLink(); } } @@ -756,7 +827,7 @@ void SwGrfNode::DelStreamName() } } - aGrfObj.SetUserData(); + maGrfObj.SetUserData(); } } @@ -845,7 +916,7 @@ void SwGrfNode::_GetStreamStorageNames( String& rStrmName, rStorName.Erase(); rStrmName.Erase(); - String aUserData( aGrfObj.GetUserData() ); + String aUserData( maGrfObj.GetUserData() ); if( !aUserData.Len() ) return; @@ -898,7 +969,7 @@ SwCntntNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const SvStream* pStrm = _GetStreamForEmbedGrf( refPics, aStrmName ); if ( pStrm ) { - const String aURL(aGrfObj.GetUserData()); + const OUString aURL(maGrfObj.GetUserData()); GraphicFilter::GetGraphicFilter().ImportGraphic(aTmpGrf, aURL, *pStrm); delete pStrm; } @@ -911,9 +982,9 @@ SwCntntNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const } else { - if( aGrfObj.IsSwappedOut() ) + if( maGrfObj.IsSwappedOut() ) const_cast(this)->SwapIn(); - aTmpGrf = aGrfObj.GetGraphic(); + aTmpGrf = maGrfObj.GetGraphic(); } const sfx2::LinkManager& rMgr = getIDocumentLinksAdministration()->GetLinkManager(); @@ -1022,7 +1093,7 @@ void DelAllGrfCacheEntries( SwDoc* pDoc ) pLnk->ISA( SwBaseLink ) && 0 != ( pGrfNd = ((SwBaseLink*)pLnk)->GetCntntNode()->GetGrfNode()) ) { - pGrfNd->GetGrfObj().ReleaseFromCache(); + pGrfNd->ReleaseGraphicFromCache(); } } } @@ -1086,7 +1157,7 @@ GraphicAttr& SwGrfNode::GetGraphicAttr( GraphicAttr& rGA, sal_Bool SwGrfNode::IsTransparent() const { - sal_Bool bRet = aGrfObj.IsTransparent(); + sal_Bool bRet = maGrfObj.IsTransparent(); if( !bRet ) // ask the attribut bRet = 0 != GetSwAttrSet().GetTransparencyGrf().GetValue(); -- cgit v1.2.3