Branch libreoffice-6-3
[LibreOffice.git] / sw / inc / ndgrf.hxx
blob2faed3ec01e8eff447fd2b30fae9a561dcac2695
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 .
20 #ifndef INCLUDED_SW_INC_NDGRF_HXX
21 #define INCLUDED_SW_INC_NDGRF_HXX
23 #include <sfx2/lnkbase.hxx>
24 #include <vcl/GraphicObject.hxx>
25 #include "ndnotxt.hxx"
26 #include <memory>
28 class SwAsyncRetrieveInputStreamThreadConsumer;
30 class SwGrfFormatColl;
31 class SwDoc;
33 // SwGrfNode
34 class SW_DLLPUBLIC SwGrfNode: public SwNoTextNode
36 friend class SwNodes;
38 GraphicObject maGrfObj;
39 std::unique_ptr<GraphicObject> mpReplacementGraphic;
40 tools::SvRef<sfx2::SvBaseLink> refLink; ///< If graphics only as link then pointer is set.
41 Size nGrfSize;
42 bool bInSwapIn :1;
44 bool bChgTwipSize :1;
45 bool bFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn.
46 bool bScaleImageMap :1; ///< Scale image map in SetTwipSize.
48 std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
49 bool mbLinkedInputStreamReady;
50 css::uno::Reference<css::io::XInputStream> mxInputStream;
51 bool mbIsStreamReadOnly;
53 SwGrfNode( const SwNodeIndex& rWhere,
54 const OUString& rGrfName, const OUString& rFltName,
55 const Graphic* pGraphic,
56 SwGrfFormatColl* pGrfColl,
57 SwAttrSet const * pAutoAttr );
58 ///< Ctor for reading (SW/G) without graphics.
59 SwGrfNode( const SwNodeIndex& rWhere,
60 const OUString& rGrfName, const OUString& rFltName,
61 SwGrfFormatColl* pGrfColl,
62 SwAttrSet const * pAutoAttr );
63 SwGrfNode( const SwNodeIndex& rWhere,
64 const GraphicObject& rGrfObj,
65 SwGrfFormatColl* pGrfColl,
66 SwAttrSet const * pAutoAttr );
68 void InsertLink( const OUString& rGrfName, const OUString& rFltName );
70 DECL_LINK( SwapGraphic, const GraphicObject*, SvStream* );
71 DECL_STATIC_LINK( SwGrfNode, SwapReplacement, const GraphicObject*, SvStream* );
73 /// allow reaction on change of content of GraphicObject, so always call
74 /// when GraphicObject content changes
75 void onGraphicChanged();
77 public:
78 virtual ~SwGrfNode() override;
79 const Graphic& GetGrf(bool bWait = false) const;
80 const GraphicObject& GetGrfObj(bool bWait = false) const;
81 const GraphicObject* GetReplacementGrfObj() const;
83 /// isolated only way to set GraphicObject to allow more actions when doing so
84 void SetGraphic(const Graphic& rGraphic);
86 /// wrappers for non-const calls at GraphicObject
87 void StartGraphicAnimation(OutputDevice* pOut, const Point& rPt, const Size& rSz, long nExtraData, OutputDevice* pFirstFrameOutDev)
88 { maGrfObj.StartAnimation(pOut, rPt, rSz, nExtraData, pFirstFrameOutDev); }
89 void StopGraphicAnimation(OutputDevice* pOut, long nExtraData) { maGrfObj.StopAnimation(pOut, nExtraData); }
91 virtual Size GetTwipSize() const override;
92 void SetTwipSize( const Size& rSz );
94 bool IsTransparent() const;
96 bool IsAnimated() const { return maGrfObj.IsAnimated(); }
98 bool IsChgTwipSize() const { return bChgTwipSize; }
99 void SetChgTwipSize( bool b)
101 bChgTwipSize = b;
104 bool IsFrameInPaint() const { return bFrameInPaint; }
105 void SetFrameInPaint( bool b ) { bFrameInPaint = b; }
107 bool IsScaleImageMap() const { return bScaleImageMap; }
108 void SetScaleImageMap( bool b ) { bScaleImageMap = b; }
110 /// in ndcopy.cxx
111 virtual SwContentNode* MakeCopy(SwDoc*, const SwNodeIndex&, bool bNewFrames) const override;
113 /** Re-read in case graphic was not OK. The current one
114 gets replaced by the new one. */
115 bool ReRead( const OUString& rGrfName, const OUString& rFltName,
116 const Graphic* pGraphic = nullptr,
117 bool bModify = true );
118 private:
119 /// Loading of graphic immediately before displaying.
120 bool SwapIn( bool bWaitForData = false );
122 public:
123 bool HasEmbeddedStreamName() const { return maGrfObj.HasUserData(); }
125 /// Communicate to graphic that node is in Undo-range.
126 virtual bool SavePersistentData() override;
127 virtual bool RestorePersistentData() override;
129 /// Query link-data.
130 bool IsGrfLink() const { return refLink.is(); }
131 bool IsLinkedFile() const;
132 bool IsLinkedDDE() const;
133 const tools::SvRef<sfx2::SvBaseLink>& GetLink() const { return refLink; }
134 bool GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const;
135 void ReleaseLink();
137 /** Scale an image-map: the image-map becomes zoomed in / out by
138 factor between graphic-size and border-size. */
139 void ScaleImageMap();
141 /// Returns the with our graphic attributes filled Graphic-Attr-Structure.
142 GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrame* pFrame ) const;
144 std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer() { return mpThreadConsumer;}
145 bool IsLinkedInputStreamReady() const { return mbLinkedInputStreamReady;}
146 void TriggerAsyncRetrieveInputStream();
147 void ApplyInputStream(
148 const css::uno::Reference<css::io::XInputStream>& xInputStream,
149 const bool bIsStreamReadOnly );
150 void UpdateLinkWithInputStream();
151 bool IsAsyncRetrieveInputStreamPossible() const;
154 // Inline methods from Node.hxx - it is only now that we know TextNode!!
155 inline SwGrfNode *SwNode::GetGrfNode()
157 return SwNodeType::Grf == m_nNodeType ? static_cast<SwGrfNode*>(this) : nullptr;
160 inline const SwGrfNode *SwNode::GetGrfNode() const
162 return SwNodeType::Grf == m_nNodeType ? static_cast<const SwGrfNode*>(this) : nullptr;
165 inline bool SwGrfNode::IsLinkedFile() const
167 return refLink.is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
170 inline bool SwGrfNode::IsLinkedDDE() const
172 return refLink.is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
175 #endif
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */