/src/libreoffice/sw/inc/ndgrf.hxx
Line | Count | Source |
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 | | #ifndef INCLUDED_SW_INC_NDGRF_HXX |
21 | | #define INCLUDED_SW_INC_NDGRF_HXX |
22 | | |
23 | | #include <sfx2/lnkbase.hxx> |
24 | | #include <vcl/GraphicObject.hxx> |
25 | | #include "ndnotxt.hxx" |
26 | | #include "swbaslnk.hxx" |
27 | | #include <memory> |
28 | | |
29 | | class SwAsyncRetrieveInputStreamThreadConsumer; |
30 | | |
31 | | class SwGrfFormatColl; |
32 | | |
33 | | // SwGrfNode |
34 | | class SAL_DLLPUBLIC_RTTI SwGrfNode final: public SwNoTextNode |
35 | | { |
36 | | friend class SwNodes; |
37 | | |
38 | | GraphicObject maGrfObj; |
39 | | std::unique_ptr<GraphicObject> mpReplacementGraphic; |
40 | | tools::SvRef<SwBaseLink> mxLink; ///< If graphics only as link then pointer is set. |
41 | | Size mnGrfSize; |
42 | | bool mbInSwapIn :1; // to avoid recursion in SwGrfNode::SwapIn |
43 | | bool mbInBaseLinkSwapIn :1; // to avoid recursion in SwBaseLink::SwapIn |
44 | | |
45 | | bool mbChangeTwipSize :1; |
46 | | bool mbFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn. |
47 | | bool mbScaleImageMap :1; ///< Scale image map in SetTwipSize. |
48 | | |
49 | | std::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer; |
50 | | bool mbLinkedInputStreamReady; |
51 | | css::uno::Reference<css::io::XInputStream> mxInputStream; |
52 | | bool mbIsStreamReadOnly; |
53 | | |
54 | | SwGrfNode( const SwNode& 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 SwNode& rWhere, |
61 | | std::u16string_view rGrfName, const OUString& rFltName, |
62 | | SwGrfFormatColl* pGrfColl, |
63 | | SwAttrSet const * pAutoAttr ); |
64 | | |
65 | | void InsertLink( std::u16string_view rGrfName, const OUString& rFltName ); |
66 | | |
67 | | /// allow reaction on change of content of GraphicObject, so always call |
68 | | /// when GraphicObject content changes |
69 | | void onGraphicChanged(); |
70 | | |
71 | | public: |
72 | | virtual ~SwGrfNode() override; |
73 | | SW_DLLPUBLIC const Graphic& GetGrf(bool bWait = false) const; |
74 | | SW_DLLPUBLIC const GraphicObject& GetGrfObj(bool bWait = false) const; |
75 | | const GraphicObject* GetReplacementGrfObj() const; |
76 | | |
77 | | /// isolated only way to set GraphicObject to allow more actions when doing so |
78 | | void SetGraphic(const Graphic& rGraphic); |
79 | | void TriggerGraphicArrived(); |
80 | | |
81 | | /// wrappers for non-const calls at GraphicObject |
82 | | void StartGraphicAnimation(OutputDevice* pOut, const Point& rPt, const Size& rSz, tools::Long nRendererId, OutputDevice* pFirstFrameOutDev) |
83 | 0 | { maGrfObj.StartAnimation(*pOut, rPt, rSz, nRendererId, pFirstFrameOutDev); } |
84 | 0 | void StopGraphicAnimation(const OutputDevice* pOut, tools::Long nRendererId) { maGrfObj.StopAnimation(pOut, nRendererId); } |
85 | | |
86 | | SW_DLLPUBLIC virtual Size GetTwipSize() const override; |
87 | | void SetTwipSize( const Size& rSz ); |
88 | | |
89 | | bool IsTransparent() const; |
90 | | |
91 | 2.00k | bool IsAnimated() const { return maGrfObj.IsAnimated(); } |
92 | | |
93 | 0 | bool IsChgTwipSize() const { return mbChangeTwipSize; } |
94 | | void SetChgTwipSize( bool b) |
95 | 114k | { |
96 | 114k | mbChangeTwipSize = b; |
97 | 114k | } |
98 | | |
99 | 22.8k | bool IsFrameInPaint() const { return mbFrameInPaint; } |
100 | 316 | void SetFrameInPaint( bool b ) { mbFrameInPaint = b; } |
101 | | |
102 | 215k | bool IsScaleImageMap() const { return mbScaleImageMap; } |
103 | 2.04k | void SetScaleImageMap( bool b ) { mbScaleImageMap = b; } |
104 | | |
105 | | /// in ndcopy.cxx |
106 | | virtual SwContentNode* MakeCopy(SwDoc&, SwNode&, bool bNewFrames) const override; |
107 | | |
108 | | /** Re-read in case graphic was not OK. The current one |
109 | | gets replaced by the new one. */ |
110 | | bool ReRead( const OUString& rGrfName, const OUString& rFltName, |
111 | | const Graphic* pGraphic = nullptr, |
112 | | bool bModify = true ); |
113 | | private: |
114 | | /// Loading of graphic immediately before displaying. |
115 | | bool SwapIn( bool bWaitForData = false ); |
116 | | |
117 | | public: |
118 | 0 | bool HasEmbeddedStreamName() const { return maGrfObj.HasUserData(); } |
119 | | |
120 | | /// Communicate to graphic that node is in Undo-range. |
121 | | virtual bool SavePersistentData() override; |
122 | | virtual bool RestorePersistentData() override; |
123 | | |
124 | | /// Query link-data. |
125 | 0 | bool IsGrfLink() const { return mxLink.is(); } |
126 | | bool IsLinkedFile() const; |
127 | | bool IsLinkedDDE() const; |
128 | 0 | const tools::SvRef<SwBaseLink>& GetLink() const { return mxLink; } |
129 | | SW_DLLPUBLIC bool GetFileFilterNms( OUString* pFileNm, OUString* pFilterNm ) const; |
130 | | void ReleaseLink(); |
131 | | |
132 | | /** Scale an image-map: the image-map becomes zoomed in / out by |
133 | | factor between graphic-size and border-size. */ |
134 | | void ScaleImageMap(); |
135 | | |
136 | | /// Returns the with our graphic attributes filled Graphic-Attr-Structure. |
137 | | GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrame* pFrame ) const; |
138 | | |
139 | 0 | std::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer() const { return mpThreadConsumer;} |
140 | 0 | bool IsLinkedInputStreamReady() const { return mbLinkedInputStreamReady;} |
141 | | void TriggerAsyncRetrieveInputStream(); |
142 | | void ApplyInputStream( |
143 | | const css::uno::Reference<css::io::XInputStream>& xInputStream, |
144 | | const bool bIsStreamReadOnly ); |
145 | | void UpdateLinkWithInputStream(); |
146 | | bool IsAsyncRetrieveInputStreamPossible() const; |
147 | | }; |
148 | | |
149 | | // Inline methods from Node.hxx - it is only now that we know TextNode!! |
150 | | inline SwGrfNode *SwNode::GetGrfNode() |
151 | 145k | { |
152 | 145k | return SwNodeType::Grf == m_nNodeType ? static_cast<SwGrfNode*>(this) : nullptr; |
153 | 145k | } |
154 | | |
155 | | inline const SwGrfNode *SwNode::GetGrfNode() const |
156 | 3.14k | { |
157 | 3.14k | return SwNodeType::Grf == m_nNodeType ? static_cast<const SwGrfNode*>(this) : nullptr; |
158 | 3.14k | } |
159 | | |
160 | | inline bool SwGrfNode::IsLinkedFile() const |
161 | 125k | { |
162 | 125k | return mxLink.is() && sfx2::SvBaseLinkObjectType::ClientGraphic == mxLink->GetObjType(); |
163 | 125k | } |
164 | | |
165 | | inline bool SwGrfNode::IsLinkedDDE() const |
166 | 3.50k | { |
167 | 3.50k | return mxLink.is() && sfx2::SvBaseLinkObjectType::ClientDde == mxLink->GetObjType(); |
168 | 3.50k | } |
169 | | |
170 | | #endif |
171 | | |
172 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |