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 #include <com/sun/star/embed/XStorage.hpp> 29 #include <boost/shared_ptr.hpp> 30 #include <boost/weak_ptr.hpp> 31 class SwAsyncRetrieveInputStreamThreadConsumer; 32 33 class SwGrfFmtColl; 34 class SwDoc; 35 class GraphicAttr; 36 class SvStorage; 37 38 39 class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode 40 { 41 friend class SwNodes; 42 43 GraphicObject maGrfObj; 44 GraphicObject* mpReplacementGraphic; 45 ::sfx2::SvBaseLinkRef refLink; // falls Grafik nur als Link, dann Pointer gesetzt 46 Size nGrfSize; 47 sal_Bool bInSwapIn :1; 48 49 sal_Bool bGrafikArrived :1; 50 sal_Bool bChgTwipSize :1; 51 sal_Bool bChgTwipSizeFromPixel :1; 52 sal_Bool bLoadLowResGrf :1; 53 sal_Bool bFrameInPaint :1; // Um Start-/EndActions im Paint (ueber SwapIn zu verhindern. 54 sal_Bool bScaleImageMap :1; // Image-Map in SetTwipSize skalieren 55 56 boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer; 57 bool mbLinkedInputStreamReady; 58 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream; 59 sal_Bool mbIsStreamReadOnly; 60 61 SwGrfNode( const SwNodeIndex& rWhere, 62 const String& rGrfName, const String& rFltName, 63 const Graphic* pGraphic, 64 SwGrfFmtColl* pGrfColl, 65 SwAttrSet* pAutoAttr = 0 ); 66 // Ctor fuer Einlesen (SW/G) ohne Grafik 67 SwGrfNode( const SwNodeIndex& rWhere, 68 const String& rGrfName, const String& rFltName, 69 SwGrfFmtColl* pGrfColl, 70 SwAttrSet* pAutoAttr = 0 ); 71 SwGrfNode( const SwNodeIndex& rWhere, 72 const GraphicObject& rGrfObj, 73 SwGrfFmtColl* pGrfColl, 74 SwAttrSet* pAutoAttr = 0 ); 75 76 void InsertLink( const String& rGrfName, const String& rFltName ); 77 sal_Bool ImportGraphic( SvStream& rStrm ); 78 sal_Bool HasStreamName() const { return maGrfObj.HasUserData(); } 79 void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const; 80 void DelStreamName(); 81 DECL_LINK( SwapGraphic, GraphicObject* ); 82 83 /** helper method to determine stream for the embedded graphic. 84 85 OD 2005-05-04 #i48434# 86 Important note: caller of this method has to handle the thrown exceptions 87 OD, MAV 2005-08-17 #i53025# 88 Storage, which should contain the stream of the embedded graphic, is 89 provided via parameter. Otherwise the returned stream will be closed 90 after the the method returns, because its parent stream is closed and deleted. 91 Proposed name of embedded graphic stream is also provided by parameter. 92 93 @author OD 94 95 @param _refPics 96 input parameter - reference to storage, which should contain the 97 embedded graphic stream. 98 99 @param _aStrmName 100 input parameter - proposed name of the embedded graphic stream. 101 102 @return SvStream* 103 new created stream of the embedded graphic, which has to be destroyed 104 after its usage. Could be NULL, if the stream isn't found. 105 */ 106 SvStream* _GetStreamForEmbedGrf( 107 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics, 108 String& _aStrmName ) const; 109 110 /** helper method to get a substorage of the document storage for readonly access. 111 112 OD, MAV 2005-08-17 #i53025# 113 A substorage with the specified name will be opened readonly. If the provided 114 name is empty the root storage will be returned. 115 116 @param _aStgName 117 input parameter - name of substorage. Can be empty. 118 119 @return XStorage 120 reference to substorage or the root storage 121 */ 122 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot( 123 const String& aStgName ) const; 124 125 public: 126 virtual ~SwGrfNode(); 127 const Graphic& GetGrf() const { return maGrfObj.GetGraphic(); } 128 const GraphicObject& GetGrfObj() const { return maGrfObj; } 129 const GraphicObject* GetReplacementGrfObj() const; 130 virtual SwCntntNode *SplitCntntNode( const SwPosition & ); 131 132 /// isolated only way to set GraphicObject to allow more actions when doing so 133 void SetGraphic(const Graphic& rGraphic, const String& rLink); 134 135 /// wrappers for non-const calls at GraphicObject 136 void ReleaseGraphicFromCache() { maGrfObj.ReleaseFromCache(); } 137 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); } 138 void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); } 139 140 /// allow reaction on change of content of GraphicObject, so always call 141 /// when GraphicObject content changes 142 void onGraphicChanged(); 143 144 virtual Size GetTwipSize() const; 145 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 146 void SetTwipSize( const Size& rSz ); 147 148 sal_Bool IsTransparent() const; 149 150 inline sal_Bool IsAnimated() const { return maGrfObj.IsAnimated(); } 151 152 inline sal_Bool IsChgTwipSize() const { return bChgTwipSize; } 153 inline sal_Bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; } 154 inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) { bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; } 155 156 inline sal_Bool IsGrafikArrived() const { return bGrafikArrived; } 157 inline void SetGrafikArrived( sal_Bool b ) { bGrafikArrived = b; } 158 159 inline sal_Bool IsFrameInPaint() const { return bFrameInPaint; } 160 inline void SetFrameInPaint( sal_Bool b ) { bFrameInPaint = b; } 161 162 inline sal_Bool IsScaleImageMap() const { return bScaleImageMap; } 163 inline void SetScaleImageMap( sal_Bool b ) { bScaleImageMap = b; } 164 #endif 165 // steht in ndcopy.cxx 166 virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const; 167 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 168 169 // erneutes Einlesen, falls Graphic nicht Ok ist. Die 170 // aktuelle wird durch die neue ersetzt. 171 sal_Bool ReRead( const String& rGrfName, const String& rFltName, 172 const Graphic* pGraphic = 0, 173 const GraphicObject* pGrfObj = 0, 174 sal_Bool bModify = sal_True ); 175 // Laden der Grafik unmittelbar vor der Anzeige 176 short SwapIn( sal_Bool bWaitForData = sal_False ); 177 // Entfernen der Grafik, um Speicher freizugeben 178 short SwapOut(); 179 180 // applying new stream name for embedded graphic - needed as saving the document might change this stream name 181 void ApplyNewEmbeddedStreamName( const String& r ) 182 { 183 maGrfObj.SetUserData( r ); 184 } 185 186 // is this node selected by any shell? 187 sal_Bool IsSelected() const; 188 #endif 189 190 // Der Grafik sagen, dass sich der Node im Undobereich befindet 191 virtual sal_Bool SavePersistentData(); 192 virtual sal_Bool RestorePersistentData(); 193 194 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 195 // Abfrage der Link-Daten 196 sal_Bool IsGrfLink() const { return refLink.Is(); } 197 inline sal_Bool IsLinkedFile() const; 198 inline sal_Bool IsLinkedDDE() const; 199 ::sfx2::SvBaseLinkRef GetLink() const { return refLink; } 200 sal_Bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const; 201 void ReleaseLink(); 202 203 // Skalieren einer Image-Map: Die Image-Map wird um den Faktor 204 // zwischen Grafik-Groesse und Rahmen-Groesse vergroessert/verkleinert 205 void ScaleImageMap(); 206 207 // returns the with our graphic attributes filled Graphic-Attr-Structure 208 GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const; 209 210 #endif 211 boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer(); 212 bool IsLinkedInputStreamReady() const; 213 void TriggerAsyncRetrieveInputStream(); 214 void ApplyInputStream( 215 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream, 216 const sal_Bool bIsStreamReadOnly ); 217 void UpdateLinkWithInputStream(); 218 bool IsAsyncRetrieveInputStreamPossible() const; 219 }; 220 221 222 // ---------------------------------------------------------------------- 223 // Inline Metoden aus Node.hxx - erst hier ist der TxtNode bekannt !! 224 inline SwGrfNode *SwNode::GetGrfNode() 225 { 226 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0; 227 } 228 inline const SwGrfNode *SwNode::GetGrfNode() const 229 { 230 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0; 231 } 232 233 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED 234 inline sal_Bool SwGrfNode::IsLinkedFile() const 235 { 236 return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType(); 237 } 238 inline sal_Bool SwGrfNode::IsLinkedDDE() const 239 { 240 return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType(); 241 } 242 #endif 243 244 245 #endif 246