1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
22 #include <sfx2/lnkbase.hxx>
23 #include <svtools/grfmgr.hxx>
24 #include <ndnotxt.hxx>
25 #include <com/sun/star/embed/XStorage.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/weak_ptr.hpp>
28 class SwAsyncRetrieveInputStreamThreadConsumer
;
30 class SwGrfFormatColl
;
36 class SW_DLLPUBLIC SwGrfNode
: public SwNoTextNode
40 GraphicObject maGrfObj
;
41 GraphicObject
*mpReplacementGraphic
;
42 ::sfx2::SvBaseLinkRef refLink
; ///< If graphics only as link then pointer is set.
44 OUString aLowResGrf
; ///< HTML: LowRes graphics (substitute until regular HighRes graphics is loaded).
47 bool bGraphicArrived
:1;
49 bool bFrameInPaint
:1; ///< To avoid Start-/EndActions in Paint via SwapIn.
50 bool bScaleImageMap
:1; ///< Scale image map in SetTwipSize.
52 boost::shared_ptr
< SwAsyncRetrieveInputStreamThreadConsumer
> mpThreadConsumer
;
53 bool mbLinkedInputStreamReady
;
54 com::sun::star::uno::Reference
<com::sun::star::io::XInputStream
> mxInputStream
;
55 bool mbIsStreamReadOnly
;
57 SwGrfNode( const SwNodeIndex
& rWhere
,
58 const OUString
& rGrfName
, const OUString
& rFltName
,
59 const Graphic
* pGraphic
,
60 SwGrfFormatColl
* pGrfColl
,
61 SwAttrSet
* pAutoAttr
= 0 );
62 ///< Ctor for reading (SW/G) without graphics.
63 SwGrfNode( const SwNodeIndex
& rWhere
,
64 const OUString
& rGrfName
, const OUString
& rFltName
,
65 SwGrfFormatColl
* pGrfColl
,
66 SwAttrSet
* pAutoAttr
= 0 );
67 SwGrfNode( const SwNodeIndex
& rWhere
,
68 const GraphicObject
& rGrfObj
,
69 SwGrfFormatColl
* pGrfColl
,
70 SwAttrSet
* pAutoAttr
= 0 );
72 void InsertLink( const OUString
& rGrfName
, const OUString
& rFltName
);
73 bool ImportGraphic( SvStream
& rStrm
);
74 /** adjust return type and rename method to
75 indicate that its an private one. */
78 DECL_LINK( SwapGraphic
, GraphicObject
* );
80 /** helper method to determine stream for the embedded graphic.
82 Important note: caller of this method has to handle the thrown exceptions
83 Storage, which should contain the stream of the embedded graphic, is
84 provided via parameter. Otherwise the returned stream will be closed
85 after the method returns, because its parent stream is closed and deleted.
86 Proposed name of embedded graphic stream is also provided by parameter.
91 input parameter - reference to storage, which should contain the
92 embedded graphic stream.
95 input parameter - proposed name of the embedded graphic stream.
98 new created stream of the embedded graphic, which has to be destroyed
99 after its usage. Could be NULL, if the stream isn't found.
101 SvStream
* _GetStreamForEmbedGrf(
102 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& _refPics
,
103 const OUString
& rStreamName
) const;
105 /** helper method to get a substorage of the document storage for readonly access.
107 A substorage with the specified name will be opened readonly. If the provided
108 name is empty the root storage will be returned.
111 input parameter - name of substorage. Can be empty.
114 reference to substorage or the root storage
116 ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> _GetDocSubstorageOrRoot(
117 const OUString
& aStgName
) const;
119 /// allow reaction on change of content of GraphicObject, so always call
120 /// when GraphicObject content changes
121 void onGraphicChanged();
124 virtual ~SwGrfNode();
125 const Graphic
& GetGrf(bool bWait
= false) const;
126 const GraphicObject
& GetGrfObj(bool bWait
= false) const;
127 const GraphicObject
* GetReplacementGrfObj() const;
128 virtual SwContentNode
*SplitContentNode( const SwPosition
& ) SAL_OVERRIDE
;
130 /// isolated only way to set GraphicObject to allow more actions when doing so
131 void SetGraphic(const Graphic
& rGraphic
, const OUString
& rLink
);
133 /// wrappers for non-const calls at GraphicObject
134 void StartGraphicAnimation(OutputDevice
* pOut
, const Point
& rPt
, const Size
& rSz
, long nExtraData
= 0, const GraphicAttr
* pAttr
= NULL
, GraphicManagerDrawFlags nFlags
= GraphicManagerDrawFlags::STANDARD
, OutputDevice
* pFirstFrameOutDev
= NULL
) { maGrfObj
.StartAnimation(pOut
, rPt
, rSz
, nExtraData
, pAttr
, nFlags
, pFirstFrameOutDev
); }
135 void StopGraphicAnimation(OutputDevice
* pOut
= NULL
, long nExtraData
= 0) { maGrfObj
.StopAnimation(pOut
, nExtraData
); }
137 virtual Size
GetTwipSize() const SAL_OVERRIDE
;
138 void SetTwipSize( const Size
& rSz
);
140 bool IsTransparent() const;
142 bool IsAnimated() const { return maGrfObj
.IsAnimated(); }
144 bool IsChgTwipSize() const { return bChgTwipSize
; }
145 void SetChgTwipSize( bool b
)
150 bool IsGraphicArrived() const { return bGraphicArrived
; }
151 void SetGraphicArrived( bool b
) { bGraphicArrived
= b
; }
153 bool IsFrameInPaint() const { return bFrameInPaint
; }
154 void SetFrameInPaint( bool b
) { bFrameInPaint
= b
; }
156 bool IsScaleImageMap() const { return bScaleImageMap
; }
157 void SetScaleImageMap( bool b
) { bScaleImageMap
= b
; }
160 virtual SwContentNode
* MakeCopy( SwDoc
*, const SwNodeIndex
& ) const SAL_OVERRIDE
;
162 /** Re-read in case graphic was not OK. The current one
163 gets replaced by the new one. */
164 bool ReRead( const OUString
& rGrfName
, const OUString
& rFltName
,
165 const Graphic
* pGraphic
= 0,
166 const GraphicObject
* pGrfObj
= 0,
167 bool bModify
= true );
169 /// Loading of graphic immediately before displaying.
170 bool SwapIn( bool bWaitForData
= false );
171 /// Remove graphic in order to free memory.
175 bool HasEmbeddedStreamName() const { return maGrfObj
.HasUserData(); }
177 /// Is this node selected by any shell?
178 bool IsSelected() const;
180 /// Communicate to graphic that node is in Undo-range.
181 virtual bool SavePersistentData() SAL_OVERRIDE
;
182 virtual bool RestorePersistentData() SAL_OVERRIDE
;
185 bool IsGrfLink() const { return refLink
.Is(); }
186 bool IsLinkedFile() const;
187 bool IsLinkedDDE() const;
188 ::sfx2::SvBaseLinkRef
GetLink() const { return refLink
; }
189 bool GetFileFilterNms( OUString
* pFileNm
, OUString
* pFilterNm
) const;
192 /** Scale an image-map: the image-map becomes zoomed in / out by
193 factor between graphic-size and border-size. */
194 void ScaleImageMap();
196 /// Returns the with our graphic attributes filled Graphic-Attr-Structure.
197 GraphicAttr
& GetGraphicAttr( GraphicAttr
&, const SwFrm
* pFrm
) const;
199 boost::weak_ptr
< SwAsyncRetrieveInputStreamThreadConsumer
> GetThreadConsumer() { return mpThreadConsumer
;}
200 bool IsLinkedInputStreamReady() const { return mbLinkedInputStreamReady
;}
201 void TriggerAsyncRetrieveInputStream();
202 void ApplyInputStream(
203 com::sun::star::uno::Reference
<com::sun::star::io::XInputStream
> xInputStream
,
204 const bool bIsStreamReadOnly
);
205 void UpdateLinkWithInputStream();
206 bool IsAsyncRetrieveInputStreamPossible() const;
209 // Inline methods from Node.hxx - it is only now that we know TextNode!!
210 inline SwGrfNode
*SwNode::GetGrfNode()
212 return ND_GRFNODE
== nNodeType
? static_cast<SwGrfNode
*>(this) : 0;
215 inline const SwGrfNode
*SwNode::GetGrfNode() const
217 return ND_GRFNODE
== nNodeType
? static_cast<const SwGrfNode
*>(this) : 0;
220 inline bool SwGrfNode::IsLinkedFile() const
222 return refLink
.Is() && OBJECT_CLIENT_GRF
== refLink
->GetObjType();
225 inline bool SwGrfNode::IsLinkedDDE() const
227 return refLink
.Is() && OBJECT_CLIENT_DDE
== refLink
->GetObjType();
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */