xref: /aoo42x/main/sw/inc/ndgrf.hxx (revision ddde725d)
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 aGrfObj;
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 aGrfObj.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 aGrfObj.GetGraphic(); }
148 	const GraphicObject&	GetGrfObj() const  	{ return aGrfObj; }
149 		  GraphicObject&	GetGrfObj() 		{ return aGrfObj; }
150     const GraphicObject* GetReplacementGrfObj() const;
151 
152     virtual SwCntntNode *SplitCntntNode( const SwPosition & );
153 
154 	virtual Size GetTwipSize() const;
155 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
156 	void SetTwipSize( const Size& rSz );
157 
158 	sal_Bool IsTransparent() const;
159 
160 	inline sal_Bool IsAnimated() const				{ return aGrfObj.IsAnimated(); }
161 
162 	inline sal_Bool IsChgTwipSize() const			{ return bChgTwipSize; }
163 	inline sal_Bool IsChgTwipSizeFromPixel() const	{ return bChgTwipSizeFromPixel; }
164 	inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) 		{ bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
165 
166 	inline sal_Bool IsGrafikArrived() const			{ return bGrafikArrived; }
167 	inline void SetGrafikArrived( sal_Bool b ) 		{ bGrafikArrived = b; }
168 
169 	inline sal_Bool IsFrameInPaint() const			{ return bFrameInPaint; }
170 	inline void SetFrameInPaint( sal_Bool b )		{ bFrameInPaint = b; }
171 
172 	inline sal_Bool IsScaleImageMap() const			{ return bScaleImageMap; }
173 	inline void SetScaleImageMap( sal_Bool b )		{ bScaleImageMap = b; }
174 #endif
175 		// steht in ndcopy.cxx
176 	virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
177 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
178 
179     // erneutes Einlesen, falls Graphic nicht Ok ist. Die
180     // aktuelle wird durch die neue ersetzt.
181 	sal_Bool ReRead( const String& rGrfName, const String& rFltName,
182                  const Graphic* pGraphic = 0,
183                  const GraphicObject* pGrfObj = 0,
184                  sal_Bool bModify = sal_True );
185     // Laden der Grafik unmittelbar vor der Anzeige
186 	short SwapIn( sal_Bool bWaitForData = sal_False );
187 		// Entfernen der Grafik, um Speicher freizugeben
188 	short SwapOut();
189 		// Zugriff auf den Storage-Streamnamen
190 	void SetStreamName( const String& r ) { aGrfObj.SetUserData( r ); }
191 	void SetNewStreamName( const String& r ) { aNewStrmName = r; }
192 	// is this node selected by any shell?
193 	sal_Bool IsSelected() const;
194 #endif
195 
196 		// Der Grafik sagen, dass sich der Node im Undobereich befindet
197 	virtual sal_Bool SavePersistentData();
198 	virtual sal_Bool RestorePersistentData();
199 
200 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
201 		// Abfrage der Link-Daten
202 	sal_Bool IsGrfLink() const 					{ return refLink.Is(); }
203 	inline sal_Bool IsLinkedFile() const;
204 	inline sal_Bool IsLinkedDDE() const;
205     ::sfx2::SvBaseLinkRef GetLink() const    { return refLink; }
206 	sal_Bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const;
207 	void ReleaseLink();
208 
209 	// Skalieren einer Image-Map: Die Image-Map wird um den Faktor
210 	// zwischen Grafik-Groesse und Rahmen-Groesse vergroessert/verkleinert
211 	void ScaleImageMap();
212 
213 	// returns the with our graphic attributes filled Graphic-Attr-Structure
214 	GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const;
215 
216 #endif
217     // --> OD 2007-01-18 #i73788#
218     boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer();
219     bool IsLinkedInputStreamReady() const;
220     void TriggerAsyncRetrieveInputStream();
221     void ApplyInputStream(
222         com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
223         const sal_Bool bIsStreamReadOnly );
224     void UpdateLinkWithInputStream();
225     // <--
226     // --> OD 2008-07-21 #i90395#
227     bool IsAsyncRetrieveInputStreamPossible() const;
228     // <--
229 };
230 
231 
232 // ----------------------------------------------------------------------
233 // Inline Metoden aus Node.hxx - erst hier ist der TxtNode bekannt !!
234 inline       SwGrfNode	 *SwNode::GetGrfNode()
235 {
236 	 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
237 }
238 inline const SwGrfNode   *SwNode::GetGrfNode() const
239 {
240 	 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
241 }
242 
243 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
244 inline sal_Bool SwGrfNode::IsLinkedFile() const
245 {
246 	return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
247 }
248 inline sal_Bool SwGrfNode::IsLinkedDDE() const
249 {
250 	return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
251 }
252 #endif
253 
254 
255 #endif
256