update credits
[LibreOffice.git] / sw / inc / ndgrf.hxx
blobe970615e9fe83b5e1d512c128a7f325dea1ee56a
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 _NDGRF_HXX
21 #define _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 SwGrfFmtColl;
31 class SwDoc;
32 class GraphicAttr;
33 class SvStorage;
35 // SwGrfNode
36 class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode
38 friend class SwNodes;
40 GraphicObject maGrfObj;
41 GraphicObject *mpReplacementGraphic;
42 ::sfx2::SvBaseLinkRef refLink; ///< If graphics only as link then pointer is set.
43 Size nGrfSize;
44 String aNewStrmName; /**< SW3/XML: new stream name (either SW3 stream
45 // name or package url) */
46 String aLowResGrf; ///< HTML: LowRes graphics (substitute until regular HighRes graphics is loaded).
47 sal_Bool bTransparentFlagValid :1;
48 sal_Bool bInSwapIn :1;
50 sal_Bool bGrafikArrived :1;
51 sal_Bool bChgTwipSize :1;
52 sal_Bool bChgTwipSizeFromPixel :1;
53 sal_Bool bLoadLowResGrf :1;
54 sal_Bool bFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn.
55 sal_Bool bScaleImageMap :1; ///< Scale image map in SetTwipSize.
57 boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
58 bool mbLinkedInputStreamReady;
59 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream;
60 sal_Bool mbIsStreamReadOnly;
62 SwGrfNode( const SwNodeIndex& rWhere,
63 const String& rGrfName, const String& rFltName,
64 const Graphic* pGraphic,
65 SwGrfFmtColl* pGrfColl,
66 SwAttrSet* pAutoAttr = 0 );
67 ///< Ctor for reading (SW/G) without graphics.
68 SwGrfNode( const SwNodeIndex& rWhere,
69 const String& rGrfName, const String& rFltName,
70 SwGrfFmtColl* pGrfColl,
71 SwAttrSet* pAutoAttr = 0 );
72 SwGrfNode( const SwNodeIndex& rWhere,
73 const GraphicObject& rGrfObj,
74 SwGrfFmtColl* pGrfColl,
75 SwAttrSet* pAutoAttr = 0 );
77 void InsertLink( const String& rGrfName, const String& rFltName );
78 sal_Bool ImportGraphic( SvStream& rStrm );
79 sal_Bool HasStreamName() const { return maGrfObj.HasUserData(); }
80 /** adjust return type and rename method to
81 indicate that its an private one. */
83 /** embedded graphic stream couldn't be inside a 3.1 - 5.2 storage any more.
84 Thus, return value isn't needed any more. */
85 void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const;
87 void DelStreamName();
88 DECL_LINK( SwapGraphic, GraphicObject* );
90 /** helper method to determine stream for the embedded graphic.
92 Important note: caller of this method has to handle the thrown exceptions
93 Storage, which should contain the stream of the embedded graphic, is
94 provided via parameter. Otherwise the returned stream will be closed
95 after the method returns, because its parent stream is closed and deleted.
96 Proposed name of embedded graphic stream is also provided by parameter.
98 @author OD
100 @param _refPics
101 input parameter - reference to storage, which should contain the
102 embedded graphic stream.
104 @param _aStrmName
105 input parameter - proposed name of the embedded graphic stream.
107 @return SvStream*
108 new created stream of the embedded graphic, which has to be destroyed
109 after its usage. Could be NULL, if the stream isn't found.
111 SvStream* _GetStreamForEmbedGrf(
112 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics,
113 String& _aStrmName ) const;
115 /** helper method to get a substorage of the document storage for readonly access.
117 A substorage with the specified name will be opened readonly. If the provided
118 name is empty the root storage will be returned.
120 @param _aStgName
121 input parameter - name of substorage. Can be empty.
123 @return XStorage
124 reference to substorage or the root storage
126 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot(
127 const String& aStgName ) const;
129 public:
130 virtual ~SwGrfNode();
131 const Graphic& GetGrf() const { return maGrfObj.GetGraphic(); }
132 const GraphicObject& GetGrfObj() const { return maGrfObj; }
133 const GraphicObject* GetReplacementGrfObj() const;
134 virtual SwCntntNode *SplitCntntNode( const SwPosition & );
136 /// isolated only way to set GraphicObject to allow more actions when doing so
137 void SetGraphic(const Graphic& rGraphic, const String& rLink);
139 /// wrappers for non-const calls at GraphicObject
140 void ReleaseGraphicFromCache() { maGrfObj.ReleaseFromCache(); }
141 void DrawGraphicWithPDFHandling(OutputDevice& rOutDev, const Point& rPt, const Size& rSz, const GraphicAttr* pGrfAttr = NULL, const sal_uLong nFlags = GRFMGR_DRAW_STANDARD) { maGrfObj.DrawWithPDFHandling(rOutDev, rPt, rSz, pGrfAttr, nFlags); }
142 void StartGraphicAnimation(OutputDevice* pOut, const Point& rPt, const Size& rSz, long nExtraData = 0, const GraphicAttr* pAttr = NULL, sal_uLong nFlags = GRFMGR_DRAW_STANDARD, OutputDevice* pFirstFrameOutDev = NULL) { maGrfObj.StartAnimation(pOut, rPt, rSz, nExtraData, pAttr, nFlags, pFirstFrameOutDev); }
143 void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); }
145 /// allow reaction on change of content of GraphicObject, so always call
146 /// when GraphicObject content changes
147 void onGraphicChanged();
149 virtual Size GetTwipSize() const;
150 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
151 void SetTwipSize( const Size& rSz );
153 sal_Bool IsTransparent() const;
155 inline sal_Bool IsAnimated() const { return maGrfObj.IsAnimated(); }
157 inline sal_Bool IsChgTwipSize() const { return bChgTwipSize; }
158 inline sal_Bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; }
159 inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) { bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
161 inline sal_Bool IsGrafikArrived() const { return bGrafikArrived; }
162 inline void SetGrafikArrived( sal_Bool b ) { bGrafikArrived = b; }
164 inline sal_Bool IsFrameInPaint() const { return bFrameInPaint; }
165 inline void SetFrameInPaint( sal_Bool b ) { bFrameInPaint = b; }
167 inline sal_Bool IsScaleImageMap() const { return bScaleImageMap; }
168 inline void SetScaleImageMap( sal_Bool b ) { bScaleImageMap = b; }
169 #endif
170 /// in ndcopy.cxx
171 virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
172 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
174 /** Re-read in case graphic was not OK. The current one
175 gets replaced by the new one. */
176 sal_Bool ReRead( const String& rGrfName, const String& rFltName,
177 const Graphic* pGraphic = 0,
178 const GraphicObject* pGrfObj = 0,
179 sal_Bool bModify = sal_True );
180 /// Loading of graphic immediately before displaying.
181 short SwapIn( sal_Bool bWaitForData = sal_False );
182 /// Remove graphic in order to free memory.
183 short SwapOut();
184 /// Access to storage stream-name.
185 void SetStreamName( const String& r ) { maGrfObj.SetUserData( r ); }
186 void SetNewStreamName( const String& r ) { aNewStrmName = r; }
187 /// Is this node selected by any shell?
188 sal_Bool IsSelected() const;
189 #endif
191 /// Communicate to graphic that node is in Undo-range.
192 virtual sal_Bool SavePersistentData();
193 virtual sal_Bool RestorePersistentData();
195 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
197 /// Query link-data.
198 bool IsGrfLink() const { return refLink.Is(); }
199 inline bool IsLinkedFile() const;
200 inline bool IsLinkedDDE() const;
201 ::sfx2::SvBaseLinkRef GetLink() const { return refLink; }
202 bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const;
203 void ReleaseLink();
205 /** Scale an image-map: the image-map becomes zoomed in / out by
206 factor between graphic-size and border-size. */
207 void ScaleImageMap();
209 /// Returns the with our graphic attributes filled Graphic-Attr-Structure.
210 GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const;
212 #endif
213 boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer();
214 bool IsLinkedInputStreamReady() const;
215 void TriggerAsyncRetrieveInputStream();
216 void ApplyInputStream(
217 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
218 const sal_Bool bIsStreamReadOnly );
219 void UpdateLinkWithInputStream();
220 bool IsAsyncRetrieveInputStreamPossible() const;
224 // Inline methods from Node.hxx - it is only now that we know TxtNode!!
225 inline SwGrfNode *SwNode::GetGrfNode()
227 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
229 inline const SwGrfNode *SwNode::GetGrfNode() const
231 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
234 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
235 inline bool SwGrfNode::IsLinkedFile() const
237 return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
239 inline bool SwGrfNode::IsLinkedDDE() const
241 return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
243 #endif
245 #endif
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */