LibreOffice Module sw (master)  1
ndgrf.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <hintids.hxx>
21 #include <tools/helpers.hxx>
22 #include <tools/urlobj.hxx>
23 #include <tools/fract.hxx>
24 #include <svl/fstathelper.hxx>
25 #include <vcl/imap.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/linkmgr.hxx>
28 #include <editeng/boxitem.hxx>
29 #include <sot/formats.hxx>
30 #include <fmtfsize.hxx>
31 #include <fmturl.hxx>
32 #include <frmfmt.hxx>
33 #include <doc.hxx>
36 #include <frmatr.hxx>
37 #include <grfatr.hxx>
38 #include <swtypes.hxx>
39 #include <ndgrf.hxx>
40 #include <fmtcol.hxx>
41 #include <hints.hxx>
42 #include <swbaslnk.hxx>
43 #include <pagefrm.hxx>
44 
45 #include <rtl/ustring.hxx>
46 #include <o3tl/deleter.hxx>
50 
51 using namespace com::sun::star;
52 
54  const SwNodeIndex & rWhere,
55  const OUString& rGrfName,
56  const OUString& rFltName,
57  const Graphic* pGraphic,
58  SwGrfFormatColl *pGrfColl,
59  SwAttrSet const * pAutoAttr ) :
60  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
61  maGrfObj(),
62  mbInBaseLinkSwapIn(true),
63  // #i73788#
64  mbLinkedInputStreamReady( false ),
65  mbIsStreamReadOnly( false )
66 {
69 
70  ReRead(rGrfName, rFltName, pGraphic, false);
71 }
72 
74  const GraphicObject& rGrfObj,
75  SwGrfFormatColl *pGrfColl,
76  SwAttrSet const * pAutoAttr ) :
77  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
78  maGrfObj(rGrfObj),
79  mbInBaseLinkSwapIn(true),
80  // #i73788#
81  mbLinkedInputStreamReady( false ),
82  mbIsStreamReadOnly( false )
83 {
86 }
87 
95  const OUString& rGrfName,
96  const OUString& rFltName,
97  SwGrfFormatColl *pGrfColl,
98  SwAttrSet const * pAutoAttr ) :
99  SwNoTextNode( rWhere, SwNodeType::Grf, pGrfColl, pAutoAttr ),
100  maGrfObj(),
101  mbInBaseLinkSwapIn(true),
102  // #i73788#
103  mbLinkedInputStreamReady( false ),
104  mbIsStreamReadOnly( false )
105 {
106  Graphic aGrf; aGrf.SetDefaultType();
107  maGrfObj.SetGraphic( aGrf, rGrfName );
108 
111 
112  InsertLink( rGrfName, rFltName );
113  if( IsLinkedFile() )
114  {
115  INetURLObject aUrl( rGrfName );
116  if( INetProtocol::File == aUrl.GetProtocol() &&
118  {
119  // file exists, so create connection without an update
120  static_cast<SwBaseLink*>( mxLink.get() )->Connect();
121  }
122  }
123 }
124 
126  const OUString& rGrfName, const OUString& rFltName,
127  const Graphic* pGraphic,
128  bool bNewGrf )
129 {
130  bool bReadGrf = false;
131  bool bSetTwipSize = true;
132  mpReplacementGraphic.reset();
133 
134  OSL_ENSURE( pGraphic || !rGrfName.isEmpty(),
135  "GraphicNode without a name, Graphic or GraphicObject" );
136 
137  OUString sURLLink;
138  if (pGraphic)
139  {
140  Graphic aGraphic(*pGraphic);
141 
142  sURLLink = aGraphic.getOriginURL();
143  if (sURLLink.isEmpty() && !rGrfName.isEmpty())
144  {
145  sURLLink = rGrfName;
146  aGraphic.setOriginURL(sURLLink);
147  }
148  }
149  else
150  {
151  sURLLink = rGrfName;
152  }
153 
154  // with name
155  if( mxLink.is() )
156  {
157  OSL_ENSURE( !mbInSwapIn, "ReRead: I am still in SwapIn" );
158 
159  if( !sURLLink.isEmpty() )
160  {
161  // Note: if there is DDE in the FltName, then it is a DDE-linked graphic
162  OUString sCmd( sURLLink );
163  if( !rFltName.isEmpty() )
164  {
165  sal_uInt16 nNewType;
166  if( rFltName == "DDE" )
167  nNewType = OBJECT_CLIENT_DDE;
168  else
169  {
170  sfx2::MakeLnkName( sCmd, nullptr, sURLLink, OUString(), &rFltName );
171  nNewType = OBJECT_CLIENT_GRF;
172  }
173 
174  if( nNewType != mxLink->GetObjType() )
175  {
176  mxLink->Disconnect();
177  static_cast<SwBaseLink*>( mxLink.get() )->SetObjType( nNewType );
178  }
179  }
180 
181  mxLink->SetLinkSourceName( sCmd );
182  }
183  else // no name anymore, so remove link
184  {
186  mxLink.clear();
187  }
188 
189  if( pGraphic )
190  {
191  maGrfObj.SetGraphic( *pGraphic, sURLLink );
193  bReadGrf = true;
194  }
195  else
196  {
197  // reset data of the old graphic so that the correct placeholder is
198  // shown in case the new link could not be loaded
199  Graphic aGrf; aGrf.SetDefaultType();
200  maGrfObj.SetGraphic( aGrf, sURLLink );
201 
202  if( mxLink.is() )
203  {
204  if( getLayoutFrame( GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) )
205  {
207  ModifyNotification( &aMsgHint, &aMsgHint );
208  }
209  else if ( bNewGrf )
210  {
211  //TODO refLink->setInputStream(getInputStream());
212  static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
213  }
214  }
216  bSetTwipSize = false;
217  }
218  }
219  else if( pGraphic && sURLLink.isEmpty() )
220  {
221  maGrfObj.SetGraphic( *pGraphic );
223  bReadGrf = true;
224  }
225  // Was the graphic already loaded?
226  else if( !bNewGrf && GraphicType::NONE != maGrfObj.GetType() )
227  return true;
228  else
229  {
230  // create new link for the graphic object
231  InsertLink( sURLLink, rFltName );
232 
233  if( GetNodes().IsDocNodes() )
234  {
235  if( pGraphic )
236  {
237  maGrfObj.SetGraphic( *pGraphic, sURLLink );
239  bReadGrf = true;
240  // create connection without update, as we have the graphic
241  static_cast<SwBaseLink*>( mxLink.get() )->Connect();
242  }
243  else
244  {
245  Graphic aGrf;
246  aGrf.SetDefaultType();
247  maGrfObj.SetGraphic( aGrf, sURLLink );
249  if ( bNewGrf )
250  {
251  static_cast<SwBaseLink*>( mxLink.get() )->SwapIn();
252  }
253  }
254  }
255  }
256 
257  // Bug 39281: Do not delete Size immediately - Events on ImageMaps should have
258  // something to work with when swapping
259  if( bSetTwipSize )
261 
262  // create an updates for the frames
263  if( bReadGrf && bNewGrf )
264  {
265  SwMsgPoolItem aMsgHint( RES_UPDATE_ATTR );
266  ModifyNotification( &aMsgHint, &aMsgHint );
267  }
268 
269  return bReadGrf;
270 }
271 
273 {
274  mpReplacementGraphic.reset();
275 
276  // #i73788#
277  mpThreadConsumer.reset();
278 
279  SwDoc* pDoc = GetDoc();
280  if( mxLink.is() )
281  {
282  OSL_ENSURE( !mbInSwapIn, "DTOR: I am still in SwapIn" );
284  mxLink->Disconnect();
285  }
286  else
287  {
288  // #i40014# - A graphic node, which is in a linked
289  // section, whose link is another section in the document, doesn't
290  // have to remove the stream from the storage.
291  // Because it's hard to detect this case here and it would only fix
292  // one problem with shared graphic files - there are also problems,
293  // a certain graphic file is referenced by two independent graphic nodes,
294  // brush item or drawing objects, the stream isn't no longer removed here.
295  // To do this stuff correctly, a reference counting on shared streams
296  // inside one document has to be implemented.
297  }
298  //#39289# delete frames already here since the Frames' dtor needs the graphic for its StopAnimation
299  if( HasWriterListeners() )
300  DelFrames(nullptr);
301 }
302 
305 {
306  // try to access SwFlyFrameFormat; since title/desc/name are set there, there is no
307  // use to continue if it is not yet set. If not yet set, call onGraphicChanged()
308  // when it is set.
309  SwFlyFrameFormat* pFlyFormat = dynamic_cast< SwFlyFrameFormat* >(GetFlyFormat());
310 
311  if(pFlyFormat)
312  {
313  OUString aName;
314  OUString aTitle;
315  OUString aDesc;
316  const VectorGraphicDataPtr& rVectorGraphicDataPtr = GetGrf().getVectorGraphicData();
317 
318  if(rVectorGraphicDataPtr.get())
319  {
320  const drawinglayer::primitive2d::Primitive2DContainer aSequence(rVectorGraphicDataPtr->getPrimitive2DSequence());
321 
322  if(!aSequence.empty())
323  {
325  drawinglayer::processor2d::ObjectInfoPrimitiveExtractor2D aProcessor(aViewInformation2D);
326 
327  aProcessor.process(aSequence);
328 
329  const drawinglayer::primitive2d::ObjectInfoPrimitive2D* pResult = aProcessor.getResult();
330 
331  if(pResult)
332  {
333  aName = pResult->getName();
334  aTitle = pResult->getTitle();
335  aDesc = pResult->getDesc();
336  }
337  }
338  }
339 
340  if(!aTitle.isEmpty())
341  {
342  SetTitle(aTitle);
343  }
344  else if (!aName.isEmpty())
345  {
346  SetTitle(aName);
347  }
348 
349  if(!aDesc.isEmpty())
350  {
351  SetDescription(aDesc);
352  }
353  }
354 }
355 
356 void SwGrfNode::SetGraphic(const Graphic& rGraphic)
357 {
358  maGrfObj.SetGraphic(rGraphic, OUString());
360 }
361 
362 const Graphic& SwGrfNode::GetGrf(bool bWait) const
363 {
364  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
365  return maGrfObj.GetGraphic();
366 }
367 
368 const GraphicObject& SwGrfNode::GetGrfObj(bool bWait) const
369 {
370  const_cast<SwGrfNode*>(this)->SwapIn(bWait);
371  return maGrfObj;
372 }
373 
375 {
377  {
378  const VectorGraphicDataPtr& rVectorGraphicDataPtr = GetGrfObj().GetGraphic().getVectorGraphicData();
379 
380  if(rVectorGraphicDataPtr.get())
381  {
382  const_cast< SwGrfNode* >(this)->mpReplacementGraphic.reset( new GraphicObject(rVectorGraphicDataPtr->getReplacement()) );
383  }
384  else if (GetGrfObj().GetGraphic().GetType() == GraphicType::GdiMetafile)
385  {
386  // Replacement graphic for PDF and metafiles is just the bitmap.
387  const_cast<SwGrfNode*>(this)->mpReplacementGraphic.reset( new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx()) );
388  }
389  }
390 
391  return mpReplacementGraphic.get();
392 }
393 
395  const OUString& rGrfName,
396  const OUString& rFltName,
397  const Graphic* pGraphic,
398  SwGrfFormatColl* pGrfColl,
399  SwAttrSet const * pAutoAttr )
400 {
401  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
402  SwGrfNode *pNode;
403  // create object delayed, only from a SW/G-reader
404  if( !pGraphic )
405  pNode = new SwGrfNode( rWhere, rGrfName,
406  rFltName, pGrfColl, pAutoAttr );
407  else
408  pNode = new SwGrfNode( rWhere, rGrfName,
409  rFltName, pGraphic, pGrfColl, pAutoAttr );
410  return pNode;
411 }
412 
414  const GraphicObject& rGrfObj,
415  SwGrfFormatColl* pGrfColl )
416 {
417  OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer is 0." );
418  return new SwGrfNode( rWhere, rGrfObj, pGrfColl, nullptr );
419 }
420 
422 {
423  if( !mnGrfSize.Width() && !mnGrfSize.Height() )
424  {
425  const_cast<SwGrfNode*>(this)->SwapIn();
426  }
427  return mnGrfSize;
428 }
429 
434 bool SwGrfNode::SwapIn(bool bWaitForData)
435 {
436  if(mbInSwapIn) // not recursively!
437  return true;
438 
439  bool bRet = false;
440  mbInSwapIn = true;
441  SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
442 
443  if( pLink )
444  {
445  if( (GraphicType::NONE == maGrfObj.GetType() ||
446  GraphicType::Default == maGrfObj.GetType()) &&
448  {
449  // link was not loaded yet
450  if( pLink->SwapIn( bWaitForData ) )
451  {
452  bRet = true;
453  mbInBaseLinkSwapIn = false;
454  }
455  else if( GraphicType::Default == maGrfObj.GetType() )
456  {
457  // no default bitmap anymore, thus re-paint
458  mpReplacementGraphic.reset();
459 
463  ModifyNotification( &aMsgHint, &aMsgHint );
464  }
465  }
466  else
467  {
468  bRet = true;
469  }
470  }
471  else
472  bRet = true;
473 
474  if (bRet)
475  {
476  if( !mnGrfSize.Width() && !mnGrfSize.Height() )
478  }
479  mbInSwapIn = false;
480  return bRet;
481 }
482 
483 bool SwGrfNode::GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const
484 {
485  bool bRet = false;
486  if( mxLink.is() && mxLink->GetLinkManager() )
487  {
488  sal_uInt16 nType = mxLink->GetObjType();
489  if( OBJECT_CLIENT_GRF == nType )
491  mxLink.get(), nullptr, pFileNm, nullptr, pFilterNm );
492  else if( OBJECT_CLIENT_DDE == nType && pFileNm && pFilterNm )
493  {
494  OUString sApp;
495  OUString sTopic;
496  OUString sItem;
498  mxLink.get(), &sApp, &sTopic, &sItem ) )
499  {
500  *pFileNm = sApp + OUStringChar(sfx2::cTokenSeparator)
501  + sTopic + OUStringChar(sfx2::cTokenSeparator)
502  + sItem;
503  *pFilterNm = "DDE";
504  bRet = true;
505  }
506  }
507  }
508  return bRet;
509 }
510 
516 {
517  if( mxLink.is() )
518  {
519  OSL_ENSURE( !mbInSwapIn, "SavePersistentData: I am still in SwapIn" );
521  return true;
522  }
523 
524  // swap in first if in storage
525  if( HasEmbeddedStreamName() && !SwapIn() )
526  return false;
527 
528  // #i44367#
529  // Do not delete graphic file in storage, because the graphic file could
530  // be referenced by other graphic nodes.
531  // Because it's hard to detect this case here and it would only fix
532  // one problem with shared graphic files - there are also problems, if
533  // a certain graphic file is referenced by two independent graphic nodes,
534  // brush item or drawing objects, the stream isn't no longer removed here.
535  // To do this stuff correct, a reference counting on shared streams
536  // inside one document has to be implemented.
537  // Important note: see also fix for #i40014#
538 
539  // swap out into temp file
540  return true;
541 }
542 
544 {
545  if( mxLink.is() )
546  {
548  mxLink->SetVisible( rIDLA.IsVisibleLinks() );
549  rIDLA.GetLinkManager().InsertDDELink( mxLink.get() );
551  mxLink->Update();
552  }
553  return true;
554 }
555 
556 void SwGrfNode::InsertLink( const OUString& rGrfName, const OUString& rFltName )
557 {
558  mxLink = new SwBaseLink( SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::GDIMETAFILE, this );
559 
561  if( GetNodes().IsDocNodes() )
562  {
563  mxLink->SetVisible( rIDLA.IsVisibleLinks() );
564  if( rFltName == "DDE" )
565  {
566  sal_Int32 nTmp = 0;
567  const OUString sApp{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
568  const OUString sTopic{ rGrfName.getToken( 0, sfx2::cTokenSeparator, nTmp ) };
569  const OUString sItem{ rGrfName.copy( nTmp ) };
570  rIDLA.GetLinkManager().InsertDDELink( mxLink.get(), sApp, sTopic, sItem );
571  }
572  else
573  {
574  const bool bSync = rFltName == "SYNCHRON";
575  mxLink->SetSynchron( bSync );
576  mxLink->SetContentType( SotClipboardFormatId::SVXB );
577 
579  OBJECT_CLIENT_GRF, rGrfName,
580  (!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
581  }
582  }
583 }
584 
586 {
587  if( mxLink.is() )
588  {
589  Graphic aLocalGraphic(maGrfObj.GetGraphic());
590  const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
591 
592  {
593  mbInSwapIn = true;
594  SwBaseLink* pLink = static_cast<SwBaseLink*>( mxLink.get() );
595  pLink->SwapIn( true, true );
596  mbInSwapIn = false;
597  }
598 
600  mxLink.clear();
601  aLocalGraphic.setOriginURL("");
602 
603  // #i15508# added extra processing after getting rid of the link. Use whatever is
604  // known from the formerly linked graphic to get to a state as close to a directly
605  // unlinked inserted graphic as possible. Goal is to have a valid GfxLink at the
606  // ImplGraphic (see there) that holds temporary data to the original data and type
607  // information about the original data. Only when this is given will
608  // SvXMLGraphicHelper::ImplInsertGraphicURL which is used at export use that type
609  // and use the original graphic at export for the ODF, without evtl. recoding
610  // of the bitmap graphic data to something without loss (e.g. PNG) but bigger
611  if(bHasOriginalData)
612  {
613  // #i15508# if we have the original data at the Graphic, let it survive
614  // by using that Graphic again, this time at a GraphicObject without link.
615  // This happens e.g. when inserting a linked graphic and breaking the link
616  maGrfObj.SetGraphic(aLocalGraphic);
617  }
618  }
619 }
620 
621 void SwGrfNode::SetTwipSize( const Size& rSz )
622 {
623  mnGrfSize = rSz;
625  {
626  // resize Image-Map to size of the graphic
627  ScaleImageMap();
628 
629  // do not re-scale Image-Map
630  SetScaleImageMap( false );
631  }
632 }
633 
635 {
636  if( !mnGrfSize.Width() || !mnGrfSize.Height() )
637  return;
638 
639  // re-scale Image-Map
640  SwFrameFormat* pFormat = GetFlyFormat();
641 
642  if( !pFormat )
643  return;
644 
645  SwFormatURL aURL( pFormat->GetURL() );
646  if ( !aURL.GetMap() )
647  return;
648 
649  bool bScale = false;
650  Fraction aScaleX( 1, 1 );
651  Fraction aScaleY( 1, 1 );
652 
653  const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize();
654  const SvxBoxItem& rBox = pFormat->GetBox();
655 
656  if( !rFrameSize.GetWidthPercent() )
657  {
658  SwTwips nWidth = rFrameSize.GetWidth();
659 
660  nWidth -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) +
661  rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
662 
663  OSL_ENSURE( nWidth>0, "Do any 0 twip wide graphics exist!?" );
664 
665  if( mnGrfSize.Width() != nWidth )
666  {
667  aScaleX = Fraction( mnGrfSize.Width(), nWidth );
668  bScale = true;
669  }
670  }
671  if( !rFrameSize.GetHeightPercent() )
672  {
673  SwTwips nHeight = rFrameSize.GetHeight();
674 
675  nHeight -= rBox.CalcLineSpace(SvxBoxItemLine::TOP) +
676  rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
677 
678  OSL_ENSURE( nHeight>0, "Do any 0 twip high graphics exist!?" );
679 
680  if( mnGrfSize.Height() != nHeight )
681  {
682  aScaleY = Fraction( mnGrfSize.Height(), nHeight );
683  bScale = true;
684  }
685  }
686 
687  if( bScale )
688  {
689  aURL.GetMap()->Scale( aScaleX, aScaleY );
690  pFormat->SetFormatAttr( aURL );
691  }
692 }
693 
694 SwContentNode* SwGrfNode::MakeCopy(SwDoc* pDoc, const SwNodeIndex& rIdx, bool) const
695 {
696  // copy formats into the other document
697  SwGrfFormatColl* pColl = pDoc->CopyGrfColl( *GetGrfColl() );
698 
699  Graphic aTmpGrf = GetGrf();
700 
701  OUString sFile, sFilter;
702  if( IsLinkedFile() )
703  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sFile, nullptr, &sFilter );
704  else if( IsLinkedDDE() )
705  {
706  OUString sTmp1, sTmp2;
707  sfx2::LinkManager::GetDisplayNames( mxLink.get(), &sTmp1, &sTmp2, &sFilter );
708  sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
709  sFilter = "DDE";
710  }
711 
712  SwGrfNode* pGrfNd = SwNodes::MakeGrfNode( rIdx, sFile, sFilter,
713  &aTmpGrf, pColl,
714  GetpSwAttrSet() );
715  pGrfNd->SetTitle( GetTitle() );
716  pGrfNd->SetDescription( GetDescription() );
717  pGrfNd->SetContour( HasContour(), HasAutomaticContour() );
718  return pGrfNd;
719 }
720 
723  const SwFrame* pFrame ) const
724 {
725  const SwAttrSet& rSet = GetSwAttrSet();
726 
727  rGA.SetDrawMode( rSet.GetDrawModeGrf().GetValue() );
728 
729  const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
730  BmpMirrorFlags nMirror = BmpMirrorFlags::NONE;
731  if( rMirror.IsGrfToggle() && pFrame && !pFrame->FindPageFrame()->OnRightPage() )
732  {
733  switch( rMirror.GetValue() )
734  {
735  case MirrorGraph::Dont:
736  nMirror = BmpMirrorFlags::Horizontal;
737  break;
739  nMirror = BmpMirrorFlags::NONE;
740  break;
742  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
743  break;
744  default:
745  nMirror = BmpMirrorFlags::Vertical;
746  break;
747  }
748  }
749  else
750  switch( rMirror.GetValue() )
751  {
752  case MirrorGraph::Both:
753  nMirror = BmpMirrorFlags::Horizontal|BmpMirrorFlags::Vertical;
754  break;
756  nMirror = BmpMirrorFlags::Horizontal;
757  break;
759  nMirror = BmpMirrorFlags::Vertical;
760  break;
761  default: break;
762  }
763 
764  rGA.SetMirrorFlags( nMirror );
765 
766  const SwCropGrf& rCrop = rSet.GetCropGrf();
767  rGA.SetCrop( convertTwipToMm100( rCrop.GetLeft() ),
768  convertTwipToMm100( rCrop.GetTop() ),
769  convertTwipToMm100( rCrop.GetRight() ),
770  convertTwipToMm100( rCrop.GetBottom() ));
771 
772  const SwRotationGrf& rRotation = rSet.GetRotationGrf();
773  rGA.SetRotation( rRotation.GetValue() );
774 
775  rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
776  rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
777  rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
778  rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
779  rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
780  rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
781  rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
782 
783  const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
784  rGA.SetTransparency( static_cast<sal_uInt8>(FRound(
785  std::min( nTrans, sal_uInt16(100) ) * 2.55 )) );
786 
787  return rGA;
788 }
789 
791 {
792  return maGrfObj.IsTransparent() ||
794 }
795 
797 {
798  if ( !IsLinkedFile() )
799  {
800  OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
801  return;
802  }
803 
804  if (mpThreadConsumer == nullptr)
805  {
807 
808  OUString sGrfNm;
809  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
810  OUString sReferer;
811  SfxObjectShell * sh = GetDoc()->GetPersist();
812  if (sh != nullptr && sh->HasName())
813  {
814  sReferer = sh->GetMedium()->GetName();
815  }
816  mpThreadConsumer->CreateThread( sGrfNm, sReferer );
817  }
818 }
819 
820 
822  const css::uno::Reference<css::io::XInputStream>& xInputStream,
823  const bool bIsStreamReadOnly )
824 {
825  if ( IsLinkedFile() )
826  {
827  if ( xInputStream.is() )
828  {
829  mxInputStream = xInputStream;
830  mbIsStreamReadOnly = bIsStreamReadOnly;
833  ModifyNotification( &aMsgHint, &aMsgHint );
834  }
835  }
836 }
837 
839 {
840  // do not work on link, if a <SwapIn> has been triggered.
841  if ( !mbInSwapIn && IsLinkedFile() )
842  {
844  GetLink()->Update();
846  ModifyNotification( &aMsgHint, &aMsgHint );
847 
848  // #i88291#
849  mxInputStream.clear();
851  mbLinkedInputStreamReady = false;
852  mpThreadConsumer.reset();
853  }
854 }
855 
856 // #i90395#
858 {
859  bool bRet = false;
860 
861  if ( IsLinkedFile() )
862  {
863  OUString sGrfNm;
864  sfx2::LinkManager::GetDisplayNames( mxLink.get(), nullptr, &sGrfNm );
865  if ( !sGrfNm.startsWith( "vnd.sun.star.pkg:" ) )
866  {
867  bRet = true;
868  }
869  }
870 
871  return bRet;
872 }
873 
874 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwGrfNode(const SwNodeIndex &rWhere, const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic, SwGrfFormatColl *pGrfColl, SwAttrSet const *pAutoAttr)
Ctor for reading (SW/G) without graphics.
Definition: ndgrf.cxx:53
bool GetValue() const
Graphic GetGraphic() const
Definition: ndnotxt.cxx:228
long Width() const
bool is() const
void SetTransparency(sal_uInt8 cTransparency)
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:269
void SetGamma(double fGamma)
Base class of the Writer layout elements.
Definition: frame.hxx:297
std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer
Definition: ndgrf.hxx:49
SVL_DLLPUBLIC bool IsDocument(const OUString &rURL)
URL aURL
const VectorGraphicDataPtr & getVectorGraphicData() const
const SwGammaGrf & GetGammaGrf(bool=true) const
Definition: grfatr.hxx:296
void ApplyInputStream(const css::uno::Reference< css::io::XInputStream > &xInputStream, const bool bIsStreamReadOnly)
Definition: ndgrf.cxx:821
const double & GetValue() const
Definition: grfatr.hxx:209
sal_Int32 GetLeft() const
bool HasEmbeddedStreamName() const
Definition: ndgrf.hxx:121
const tools::SvRef< sfx2::SvBaseLink > & GetLink() const
Definition: ndgrf.hxx:131
virtual void ModifyNotification(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: node.hxx:475
long FRound(double fVal)
bool HasAutomaticContour() const
Definition: ndnotxt.hxx:78
virtual const SwRootFrame * GetCurrentLayout() const =0
tools::SvRef< sfx2::SvBaseLink > mxLink
If graphics only as link then pointer is set.
Definition: ndgrf.hxx:40
long Height() const
#define RES_GRF_REREAD_AND_INCACHE
Definition: hintids.hxx:399
void ScaleImageMap()
Scale an image-map: the image-map becomes zoomed in / out by factor between graphic-size and border-s...
Definition: ndgrf.cxx:634
long GetWidth() const
const OUString & GetName() const
void SetInvert(bool bInvert)
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:244
const sal_Unicode cTokenSeparator
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
Definition: doc.hxx:186
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:259
sal_uInt16 GetValue() const
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
void setOriginURL(OUString const &rOriginURL)
bool IsLinkedFile() const
Definition: ndgrf.hxx:163
const SwChannelRGrf & GetChannelRGrf(bool=true) const
Definition: grfatr.hxx:290
long SwTwips
Definition: swtypes.hxx:49
bool mbScaleImageMap
Scale image map in SetTwipSize.
Definition: ndgrf.hxx:47
const GraphicObject * GetReplacementGrfObj() const
Definition: ndgrf.cxx:374
bool HasWriterListeners() const
Definition: calbck.hxx:208
void SetDrawMode(GraphicDrawMode eDrawMode)
bool mbInSwapIn
Definition: ndgrf.hxx:42
#define RES_LINKED_GRAPHIC_STREAM_ARRIVED
Definition: hintids.hxx:407
virtual ~SwGrfNode() override
Definition: ndgrf.cxx:272
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:84
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:104
Size mnGrfSize
Definition: ndgrf.hxx:41
#define OBJECT_CLIENT_GRF
const SwChannelBGrf & GetChannelBGrf(bool=true) const
Definition: grfatr.hxx:294
#define RES_UPDATE_ATTR
Definition: hintids.hxx:384
bool IsAsyncRetrieveInputStreamPossible() const
Definition: ndgrf.cxx:857
const SwTransparencyGrf & GetTransparencyGrf(bool=true) const
Definition: grfatr.hxx:300
void TriggerAsyncRetrieveInputStream()
Definition: ndgrf.cxx:796
GraphicAttr & GetGraphicAttr(GraphicAttr &, const SwFrame *pFrame) const
Returns the with our graphic attributes filled Graphic-Attr-Structure.
Definition: ndgrf.cxx:722
static SwGrfNode * MakeGrfNode(const SwNodeIndex &rWhere, const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic, SwGrfFormatColl *pColl, SwAttrSet const *pAutoAttr=nullptr)
in ndgrf.cxx
Definition: ndgrf.cxx:394
bool OnRightPage() const
Definition: frame.hxx:713
#define RES_GRAPHIC_ARRIVED
Definition: hintids.hxx:393
class to provide creation of a thread to retrieve an input stream given by a URL and to consume the r...
bool GetFileFilterNms(OUString *pFileNm, OUString *pFilterNm) const
Definition: ndgrf.cxx:483
const SwCropGrf & GetCropGrf(bool=true) const
Definition: grfatr.hxx:282
const IDocumentLinksAdministration & getIDocumentLinksAdministration() const
Provides access to the document links administration interface.
Definition: node.cxx:2071
SwGrfFormatColl * GetGrfColl() const
Definition: ndnotxt.hxx:58
#define RES_GRAPHIC_PIECE_ARRIVED
Definition: hintids.hxx:394
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
T * get() const
Style of a layout element.
Definition: frmfmt.hxx:57
SwNodeType
Definition: ndtyp.hxx:28
sal_Int16 GetValue() const
bool mbLinkedInputStreamReady
Definition: ndgrf.hxx:50
void SetGraphic(const Graphic &rGraphic)
isolated only way to set GraphicObject to allow more actions when doing so
Definition: ndgrf.cxx:356
GraphicType GetType() const
css::uno::Reference< css::io::XInputStream > mxInputStream
Definition: ndgrf.hxx:51
void Remove(SvBaseLink const *pLink)
void SetContrast(short nContrastPercent)
void SetCrop(long nLeft_100TH_MM, long nTop_100TH_MM, long nRight_100TH_MM, long nBottom_100TH_MM)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
virtual bool SavePersistentData() override
Communicate to graphic that node is in Undo-range.
Definition: ndgrf.cxx:515
void InsertFileLink(sfx2::SvBaseLink &, sal_uInt16 nFileType, const OUString &rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
const primitive2d::ObjectInfoPrimitive2D * getResult() const
sal_uInt8 GetHeightPercent() const
Definition: fmtfsize.hxx:88
void DelFrames(SwRootFrame const *pLayout)
Method deletes all views of document for the node.
Definition: node.cxx:1346
SwDoc * GetDoc()
Definition: node.hxx:702
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:78
void SetChannelG(short nChannelGPercent)
void process(const primitive2d::Primitive2DContainer &rSource)
BmpMirrorFlags
bool mbChangeTwipSize
Definition: ndgrf.hxx:45
GraphicObject maGrfObj
Definition: ndgrf.hxx:38
Marks a node in the document model.
Definition: ndindex.hxx:31
bool HasName() const
OUString getOriginURL() const
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
Document links administration interface.
const SwRotationGrf & GetRotationGrf(bool=true) const
Definition: grfatr.hxx:284
const SwContrastGrf & GetContrastGrf(bool=true) const
Definition: grfatr.hxx:288
OUString GetDescription() const
Definition: ndnotxt.cxx:281
sal_uInt8 GetWidthPercent() const
Definition: fmtfsize.hxx:91
void SetChannelR(short nChannelRPercent)
bool ReRead(const OUString &rGrfName, const OUString &rFltName, const Graphic *pGraphic=nullptr, bool bModify=true)
Re-read in case graphic was not OK.
Definition: ndgrf.cxx:125
void SetTwipSize(const Size &rSz)
Definition: ndgrf.cxx:621
const GraphicObject & GetGrfObj(bool bWait=false) const
Definition: ndgrf.cxx:368
bool IsScaleImageMap() const
Definition: ndgrf.hxx:105
GraphicType GetType() const
virtual Size GetTwipSize() const override
Definition: ndgrf.cxx:421
void InsertLink(const OUString &rGrfName, const OUString &rFltName)
Definition: ndgrf.cxx:556
void SetChannelB(short nChannelBPercent)
void InsertDDELink(SvBaseLink *, const OUString &rServer, const OUString &rTopic, const OUString &rItem)
SwGrfFormatColl * CopyGrfColl(const SwGrfFormatColl &rColl)
copy the graphic nodes
Definition: docfmt.cxx:1230
void SetGraphic(const Graphic &rGraphic, const GraphicObject *pCopyObj=nullptr)
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2069
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
sal_Int32 GetBottom() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SwMirrorGrf & GetMirrorGrf(bool=true) const
Definition: grfatr.hxx:280
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
sal_Int32 GetTop() const
bool IsLinkedDDE() const
Definition: ndgrf.hxx:168
void MakeLnkName(OUString &rName, const OUString *pType, const OUString &rFile, const OUString &rLink, const OUString *pFilter)
void SetScaleImageMap(bool b)
Definition: ndgrf.hxx:106
const Graphic & GetGraphic() const
SvBaseLink * pLink
OUString GetTitle() const
Definition: ndnotxt.cxx:257
void SetLuminance(short nLuminancePercent)
#define OBJECT_CLIENT_DDE
OUString aName
INetProtocol GetProtocol() const
virtual SwContentNode * MakeCopy(SwDoc *, const SwNodeIndex &, bool bNewFrames) const override
in ndcopy.cxx
Definition: ndgrf.cxx:694
bool mbIsStreamReadOnly
Definition: ndgrf.hxx:52
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:615
void UpdateLinkWithInputStream()
Definition: ndgrf.cxx:838
std::unique_ptr< GraphicObject > mpReplacementGraphic
Definition: ndgrf.hxx:39
void onGraphicChanged()
allow reaction on change of content of GraphicObject, so always call when GraphicObject content chang...
Definition: ndgrf.cxx:304
const SwChannelGGrf & GetChannelGGrf(bool=true) const
Definition: grfatr.hxx:292
QPRO_FUNC_TYPE nType
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
sal_uInt16 CalcLineSpace(SvxBoxItemLine nLine, bool bEvenIfNoLine=false) const
sal_Int32 GetRight() const
virtual sfx2::LinkManager & GetLinkManager()=0
const SwDrawModeGrf & GetDrawModeGrf(bool=true) const
Definition: grfatr.hxx:302
bool SwapIn(bool bWaitForData=false)
Loading of graphic immediately before displaying.
Definition: ndgrf.cxx:434
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
void ReleaseLink()
Definition: ndgrf.cxx:585
const SwInvertGrf & GetInvertGrf(bool=true) const
Definition: grfatr.hxx:298
bool IsTransparent() const
Definition: ndgrf.cxx:790
void SetDefaultType()
sal_uInt8 GetValue() const
bool mbInBaseLinkSwapIn
Definition: ndgrf.hxx:43
const SwLuminanceGrf & GetLuminanceGrf(bool=true) const
Definition: grfatr.hxx:286
long GetHeight() const
virtual bool RestorePersistentData() override
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndgrf.cxx:543
bool IsTransparent() const
bool IsGrfToggle() const
Definition: grfatr.hxx:65
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:709
void SetRotation(sal_uInt16 nRotate10)
const Graphic & GetGrf(bool bWait=false) const
Definition: ndgrf.cxx:362
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:84
bool mbFrameInPaint
To avoid Start-/EndActions in Paint via SwapIn.
Definition: ndgrf.hxx:46
Size GetGraphicSizeTwip(const Graphic &rGraphic, vcl::RenderContext *pOutDev)
Definition: swtypes.cxx:28
virtual bool IsVisibleLinks() const =0
Insert links in-/visibly into LinkManager (linked ranges).
EnumT GetValue() const
SfxMedium * GetMedium() const