1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _NDGRF_HXX 24 #define _NDGRF_HXX 25 #include <sfx2/lnkbase.hxx> 26 #include <svtools/grfmgr.hxx> 27 #include <ndnotxt.hxx> 28 // --> OD, MAV 2005-08-17 #i53025# 29 #include <com/sun/star/embed/XStorage.hpp> 30 // <-- 31 // --> OD 2007-03-28 #i73788# 32 #include <boost/shared_ptr.hpp> 33 #include <boost/weak_ptr.hpp> 34 class SwAsyncRetrieveInputStreamThreadConsumer; 35 // <-- 36 37 class SwGrfFmtColl; 38 class SwDoc; 39 class GraphicAttr; 40 class SvStorage; 41 // -------------------- 42 // SwGrfNode 43 // -------------------- 44 class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode 45 { 46 friend class SwNodes; 47 48 GraphicObject maGrfObj; 49 GraphicObject* mpReplacementGraphic; 50 ::sfx2::SvBaseLinkRef refLink; // falls Grafik nur als Link, dann Pointer gesetzt 51 Size nGrfSize; 52 // String aStrmName; // SW3: Name des Storage-Streams fuer Embedded 53 String aNewStrmName; // SW3/XML: new stream name (either SW3 stream 54 // name or package url) 55 String aLowResGrf; // HTML: LowRes Grafik (Ersatzdarstellung bis 56 // die normale (HighRes) geladen ist. 57 sal_Bool bTransparentFlagValid :1; 58 sal_Bool bInSwapIn :1; 59 60 sal_Bool bGrafikArrived :1; 61 sal_Bool bChgTwipSize :1; 62 sal_Bool bChgTwipSizeFromPixel :1; 63 sal_Bool bLoadLowResGrf :1; 64 sal_Bool bFrameInPaint :1; //Um Start-/EndActions im Paint (ueber 65 //SwapIn zu verhindern. 66 sal_Bool bScaleImageMap :1; //Image-Map in SetTwipSize skalieren 67 68 // --> OD 2007-01-19 #i73788# 69 boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer; 70 bool mbLinkedInputStreamReady; 71 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream; 72 sal_Bool mbIsStreamReadOnly; 73 // <-- 74 75 SwGrfNode( const SwNodeIndex& rWhere, 76 const String& rGrfName, const String& rFltName, 77 const Graphic* pGraphic, 78 SwGrfFmtColl* pGrfColl, 79 SwAttrSet* pAutoAttr = 0 ); 80 // Ctor fuer Einlesen (SW/G) ohne Grafik 81 SwGrfNode( const SwNodeIndex& rWhere, 82 const String& rGrfName, const String& rFltName, 83 SwGrfFmtColl* pGrfColl, 84 SwAttrSet* pAutoAttr = 0 ); 85 SwGrfNode( const SwNodeIndex& rWhere, 86 const GraphicObject& rGrfObj, 87 SwGrfFmtColl* pGrfColl, 88 SwAttrSet* pAutoAttr = 0 ); 89 90 void InsertLink( const String& rGrfName, const String& rFltName ); 91 sal_Bool ImportGraphic( SvStream& rStrm ); 92 sal_Bool HasStreamName() const { return maGrfObj.HasUserData(); } 93 // --> OD 2005-05-04 #i48434# - adjust return type and rename method to 94 // indicate that its an private one. 95 // --> OD 2005-08-17 #i53025# 96 // embedded graphic stream couldn't be inside a 3.1 - 5.2 storage any more. 97 // Thus, return value isn't needed any more. 98 void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const; 99 // <-- 100 void DelStreamName(); 101 DECL_LINK( SwapGraphic, GraphicObject* ); 102 103 /** helper method to determine stream for the embedded graphic. 104 105 OD 2005-05-04 #i48434# 106 Important note: caller of this method has to handle the thrown exceptions 107 OD, MAV 2005-08-17 #i53025# 108 Storage, which should contain the stream of the embedded graphic, is 109 provided via parameter. Otherwise the returned stream will be closed 110 after the the method returns, because its parent stream is closed and deleted. 111 Proposed name of embedded graphic stream is also provided by parameter. 112 113 @author OD 114 115 @param _refPics 116 input parameter - reference to storage, which should contain the 117 embedded graphic stream. 118 119 @param _aStrmName 120 input parameter - proposed name of the embedded graphic stream. 121 122 @return SvStream* 123 new created stream of the embedded graphic, which has to be destroyed 124 after its usage. Could be NULL, if the stream isn't found. 125 */ 126 SvStream* _GetStreamForEmbedGrf( 127 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics, 128 String& _aStrmName ) const; 129 130 /** helper method to get a substorage of the document storage for readonly access. 131 132 OD, MAV 2005-08-17 #i53025# 133 A substorage with the specified name will be opened readonly. If the provided 134 name is empty the root storage will be returned. 135 136 @param _aStgName 137 input parameter - name of substorage. Can be empty. 138 139 @return XStorage 140 reference to substorage or the root storage 141 */ 142 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot( 143 const String& aStgName ) const; 144 145 public: 146 virtual ~SwGrfNode(); 147 const Graphic& GetGrf() const { return maGrfObj.GetGraphic(); } 148 const GraphicObject& GetGrfObj() const { return maGrfObj; } 149 const GraphicObject* GetReplacementGrfObj() const; 150 virtual SwCntntNode *SplitCntntNode( const SwPosition & ); 151 152 /// isolated only way to set GraphicObject to allow more actions when doing so 153 void SetGraphic(const Graphic& rGraphic, const String& rLink); 154 155 /// wrappers for non-const calls at GraphicObject 156 void ReleaseGraphicFromCache() { maGrfObj.ReleaseFromCache(); } 157 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); } 158 void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); } 159 160 /// allow reaction on change of content of GraphicObject, so always call 161 /// when GraphicObject content changes 162 void onGraphicChanged(); 163 164 virtual Size GetTwipSize() const; 165 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 166 void SetTwipSize( const Size& rSz ); 167 168 sal_Bool IsTransparent() const; 169 170 inline sal_Bool IsAnimated() const { return maGrfObj.IsAnimated(); } 171 172 inline sal_Bool IsChgTwipSize() const { return bChgTwipSize; } 173 inline sal_Bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; } 174 inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) { bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; } 175 176 inline sal_Bool IsGrafikArrived() const { return bGrafikArrived; } 177 inline void SetGrafikArrived( sal_Bool b ) { bGrafikArrived = b; } 178 179 inline sal_Bool IsFrameInPaint() const { return bFrameInPaint; } 180 inline void SetFrameInPaint( sal_Bool b ) { bFrameInPaint = b; } 181 182 inline sal_Bool IsScaleImageMap() const { return bScaleImageMap; } 183 inline void SetScaleImageMap( sal_Bool b ) { bScaleImageMap = b; } 184 #endif 185 // steht in ndcopy.cxx 186 virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const; 187 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 188 189 // erneutes Einlesen, falls Graphic nicht Ok ist. Die 190 // aktuelle wird durch die neue ersetzt. 191 sal_Bool ReRead( const String& rGrfName, const String& rFltName, 192 const Graphic* pGraphic = 0, 193 const GraphicObject* pGrfObj = 0, 194 sal_Bool bModify = sal_True ); 195 // Laden der Grafik unmittelbar vor der Anzeige 196 short SwapIn( sal_Bool bWaitForData = sal_False ); 197 // Entfernen der Grafik, um Speicher freizugeben 198 short SwapOut(); 199 // Zugriff auf den Storage-Streamnamen 200 void SetStreamName( const String& r ) { maGrfObj.SetUserData( r ); } 201 void SetNewStreamName( const String& r ) { aNewStrmName = r; } 202 // is this node selected by any shell? 203 sal_Bool IsSelected() const; 204 #endif 205 206 // Der Grafik sagen, dass sich der Node im Undobereich befindet 207 virtual sal_Bool SavePersistentData(); 208 virtual sal_Bool RestorePersistentData(); 209 210 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 211 // Abfrage der Link-Daten 212 sal_Bool IsGrfLink() const { return refLink.Is(); } 213 inline sal_Bool IsLinkedFile() const; 214 inline sal_Bool IsLinkedDDE() const; 215 ::sfx2::SvBaseLinkRef GetLink() const { return refLink; } 216 sal_Bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const; 217 void ReleaseLink(); 218 219 // Skalieren einer Image-Map: Die Image-Map wird um den Faktor 220 // zwischen Grafik-Groesse und Rahmen-Groesse vergroessert/verkleinert 221 void ScaleImageMap(); 222 223 // returns the with our graphic attributes filled Graphic-Attr-Structure 224 GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const; 225 226 #endif 227 // --> OD 2007-01-18 #i73788# 228 boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer(); 229 bool IsLinkedInputStreamReady() const; 230 void TriggerAsyncRetrieveInputStream(); 231 void ApplyInputStream( 232 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream, 233 const sal_Bool bIsStreamReadOnly ); 234 void UpdateLinkWithInputStream(); 235 // <-- 236 // --> OD 2008-07-21 #i90395# 237 bool IsAsyncRetrieveInputStreamPossible() const; 238 // <-- 239 }; 240 241 242 // ---------------------------------------------------------------------- 243 // Inline Metoden aus Node.hxx - erst hier ist der TxtNode bekannt !! 244 inline SwGrfNode *SwNode::GetGrfNode() 245 { 246 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0; 247 } 248 inline const SwGrfNode *SwNode::GetGrfNode() const 249 { 250 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0; 251 } 252 253 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 254 inline sal_Bool SwGrfNode::IsLinkedFile() const 255 { 256 return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType(); 257 } 258 inline sal_Bool SwGrfNode::IsLinkedDDE() const 259 { 260 return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType(); 261 } 262 #endif 263 264 265 #endif 266