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