summaryrefslogtreecommitdiff
path: root/sw/source/core/graphic/ndgrf.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/core/graphic/ndgrf.cxx')
-rw-r--r--sw/source/core/graphic/ndgrf.cxx171
1 files changed, 121 insertions, 50 deletions
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 <com/sun/star/embed/XTransactedObject.hpp>
#include <vcl/svapp.hxx>
#include <com/sun/star/io/XSeekable.hpp>
-// #i73788#
#include <retrieveinputstreamconsumer.hxx>
+#include <drawinglayer/processor2d/objectinfoextractor2d.hxx>
+#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
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<SwGrfNode*>(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();