lok: Hide file linking in section
[LibreOffice.git] / sw / inc / ndgrf.hxx
blob5434d301761a0e33e06d7f6d7247c640b134913f
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; // to avoid recursion in SwGrfNode::SwapIn
43 bool bInBaseLinkSwapIn :1; // to avoid recursion in SwBaseLink::SwapIn
45 bool bChgTwipSize :1;
46 bool bFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn.
47 bool bScaleImageMap :1; ///< Scale image map in SetTwipSize.
49 std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
50 bool mbLinkedInputStreamReady;
51 css::uno::Reference<css::io::XInputStream> mxInputStream;
52 bool mbIsStreamReadOnly;
54 SwGrfNode( const SwNodeIndex& rWhere,
55 const OUString& rGrfName, const OUString& rFltName,
56 const Graphic* pGraphic,
57 SwGrfFormatColl* pGrfColl,
58 SwAttrSet const * pAutoAttr );
59 ///< Ctor for reading (SW/G) without graphics.
60 SwGrfNode( const SwNodeIndex& rWhere,
61 const OUString& rGrfName, const OUString& rFltName,
62 SwGrfFormatColl* pGrfColl,
63 SwAttrSet const * pAutoAttr );
64 SwGrfNode( const SwNodeIndex& rWhere,
65 const GraphicObject& rGrfObj,
66 SwGrfFormatColl* pGrfColl,
67 SwAttrSet const * pAutoAttr );
69 void InsertLink( const OUString& rGrfName, const OUString& rFltName );
71 DECL_LINK( SwapGraphic, const GraphicObject*, SvStream* );
72 DECL_STATIC_LINK( SwGrfNode, SwapReplacement, const GraphicObject*, SvStream* );
74 /// allow reaction on change of content of GraphicObject, so always call
75 /// when GraphicObject content changes
76 void onGraphicChanged();
78 public:
79 virtual ~SwGrfNode() override;
80 const Graphic& GetGrf(bool bWait = false) const;
81 const GraphicObject& GetGrfObj(bool bWait = false) const;
82 const GraphicObject* GetReplacementGrfObj() const;
84 /// isolated only way to set GraphicObject to allow more actions when doing so
85 void SetGraphic(const Graphic& rGraphic);
87 /// wrappers for non-const calls at GraphicObject
88 void StartGraphicAnimation(OutputDevice* pOut, const Point& rPt, const Size& rSz, long nExtraData, OutputDevice* pFirstFrameOutDev)
89 { maGrfObj.StartAnimation(pOut, rPt, rSz, nExtraData, pFirstFrameOutDev); }
90 void StopGraphicAnimation(OutputDevice* pOut, long nExtraData) { maGrfObj.StopAnimation(pOut, nExtraData); }
92 virtual Size GetTwipSize() const override;
93 void SetTwipSize( const Size& rSz );
95 bool IsTransparent() const;
97 bool IsAnimated() const { return maGrfObj.IsAnimated(); }
99 bool IsChgTwipSize() const { return bChgTwipSize; }
100 void SetChgTwipSize( bool b)
102 bChgTwipSize = b;
105 bool IsFrameInPaint() const { return bFrameInPaint; }
106 void SetFrameInPaint( bool b ) { bFrameInPaint = b; }
108 bool IsScaleImageMap() const { return bScaleImageMap; }
109 void SetScaleImageMap( bool b ) { bScaleImageMap = b; }
111 /// in ndcopy.cxx
112 virtual SwContentNode* MakeCopy(SwDoc*, const SwNodeIndex&, bool bNewFrames) const override;
114 /** Re-read in case graphic was not OK. The current one
115 gets replaced by the new one. */
116 bool ReRead( const OUString& rGrfName, const OUString& rFltName,
117 const Graphic* pGraphic = nullptr,
118 bool bModify = true );
119 private:
120 /// Loading of graphic immediately before displaying.
121 bool SwapIn( bool bWaitForData = false );
123 public:
124 bool HasEmbeddedStreamName() const { return maGrfObj.HasUserData(); }
126 /// Communicate to graphic that node is in Undo-range.
127 virtual bool SavePersistentData() override;
128 virtual bool RestorePersistentData() override;
130 /// Query link-data.
131 bool IsGrfLink() const { return refLink.is(); }
132 bool IsLinkedFile() const;
133 bool IsLinkedDDE() const;
134 const tools::SvRef<sfx2::SvBaseLink>& GetLink() const { return refLink; }
135 bool GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const;
136 void ReleaseLink();
138 /** Scale an image-map: the image-map becomes zoomed in / out by
139 factor between graphic-size and border-size. */
140 void ScaleImageMap();
142 /// Returns the with our graphic attributes filled Graphic-Attr-Structure.
143 GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrame* pFrame ) const;
145 std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer() const { return mpThreadConsumer;}
146 bool IsLinkedInputStreamReady() const { return mbLinkedInputStreamReady;}
147 void TriggerAsyncRetrieveInputStream();
148 void ApplyInputStream(
149 const css::uno::Reference<css::io::XInputStream>& xInputStream,
150 const bool bIsStreamReadOnly );
151 void UpdateLinkWithInputStream();
152 bool IsAsyncRetrieveInputStreamPossible() const;
155 // Inline methods from Node.hxx - it is only now that we know TextNode!!
156 inline SwGrfNode *SwNode::GetGrfNode()
158 return SwNodeType::Grf == m_nNodeType ? static_cast<SwGrfNode*>(this) : nullptr;
161 inline const SwGrfNode *SwNode::GetGrfNode() const
163 return SwNodeType::Grf == m_nNodeType ? static_cast<const SwGrfNode*>(this) : nullptr;
166 inline bool SwGrfNode::IsLinkedFile() const
168 return refLink.is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
171 inline bool SwGrfNode::IsLinkedDDE() const
173 return refLink.is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
176 #endif
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */