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