xref: /aoo42x/main/sw/inc/ndgrf.hxx (revision 1d2dbeb0)
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     ::sfx2::SvBaseLinkRef refLink;       // falls Grafik nur als Link, dann Pointer gesetzt
50 	Size nGrfSize;
51 //	String aStrmName;			// SW3: Name des Storage-Streams fuer Embedded
52 	String aNewStrmName;		// SW3/XML: new stream name (either SW3 stream
53 								// name or package url)
54 	String aLowResGrf;			// HTML: LowRes Grafik (Ersatzdarstellung bis
55 								// 		die normale (HighRes) geladen ist.
56 	sal_Bool bTransparentFlagValid	:1;
57 	sal_Bool bInSwapIn				:1;
58 
59 	sal_Bool bGrafikArrived			:1;
60 	sal_Bool bChgTwipSize			:1;
61 	sal_Bool bChgTwipSizeFromPixel	:1;
62 	sal_Bool bLoadLowResGrf			:1;
63 	sal_Bool bFrameInPaint			:1;	//Um Start-/EndActions im Paint (ueber
64 									//SwapIn zu verhindern.
65 	sal_Bool bScaleImageMap	 		:1; //Image-Map in SetTwipSize skalieren
66 
67     // --> OD 2007-01-19 #i73788#
68     boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
69     bool mbLinkedInputStreamReady;
70     com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream;
71     sal_Bool mbIsStreamReadOnly;
72     // <--
73 
74 	SwGrfNode( const SwNodeIndex& rWhere,
75 			   const String& rGrfName, const String& rFltName,
76 			   const Graphic* pGraphic,
77 			   SwGrfFmtColl* pGrfColl,
78 			   SwAttrSet* pAutoAttr = 0 );
79 	// Ctor fuer Einlesen (SW/G) ohne Grafik
80 	SwGrfNode( const SwNodeIndex& rWhere,
81 			   const String& rGrfName, const String& rFltName,
82 			   SwGrfFmtColl* pGrfColl,
83 			   SwAttrSet* pAutoAttr = 0 );
84 	SwGrfNode( const SwNodeIndex& rWhere,
85 			   const GraphicObject& rGrfObj,
86 			   SwGrfFmtColl* pGrfColl,
87 			   SwAttrSet* pAutoAttr = 0 );
88 
89 	void InsertLink( const String& rGrfName, const String& rFltName );
90 	sal_Bool ImportGraphic( SvStream& rStrm );
91 	sal_Bool HasStreamName() const { return aGrfObj.HasUserData(); }
92     // --> OD 2005-05-04 #i48434# - adjust return type and rename method to
93     // indicate that its an private one.
94     // --> OD 2005-08-17 #i53025#
95     // embedded graphic stream couldn't be inside a 3.1 - 5.2 storage any more.
96     // Thus, return value isn't needed any more.
97     void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const;
98     // <--
99 	void DelStreamName();
100 	DECL_LINK( SwapGraphic, GraphicObject* );
101 
102     /** helper method to determine stream for the embedded graphic.
103 
104         OD 2005-05-04 #i48434#
105         Important note: caller of this method has to handle the thrown exceptions
106         OD, MAV 2005-08-17 #i53025#
107         Storage, which should contain the stream of the embedded graphic, is
108         provided via parameter. Otherwise the returned stream will be closed
109         after the the method returns, because its parent stream is closed and deleted.
110         Proposed name of embedded graphic stream is also provided by parameter.
111 
112         @author OD
113 
114         @param _refPics
115         input parameter - reference to storage, which should contain the
116         embedded graphic stream.
117 
118         @param _aStrmName
119         input parameter - proposed name of the embedded graphic stream.
120 
121         @return SvStream*
122         new created stream of the embedded graphic, which has to be destroyed
123         after its usage. Could be NULL, if the stream isn't found.
124     */
125     SvStream* _GetStreamForEmbedGrf(
126             const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics,
127             String& _aStrmName ) const;
128 
129     /** helper method to get a substorage of the document storage for readonly access.
130 
131         OD, MAV 2005-08-17 #i53025#
132         A substorage with the specified name will be opened readonly. If the provided
133         name is empty the root storage will be returned.
134 
135         @param _aStgName
136         input parameter - name of substorage. Can be empty.
137 
138         @return XStorage
139         reference to substorage or the root storage
140     */
141     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot(
142                                                 const String& aStgName ) const;
143 
144 public:
145 	virtual ~SwGrfNode();
146 	const Graphic& 			GetGrf() const  	{ return aGrfObj.GetGraphic(); }
147 	const GraphicObject&	GetGrfObj() const  	{ return aGrfObj; }
148 		  GraphicObject&	GetGrfObj() 		{ return aGrfObj; }
149 
150     virtual SwCntntNode *SplitCntntNode( const SwPosition & );
151 
152 	virtual Size GetTwipSize() const;
153 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
154 	void SetTwipSize( const Size& rSz );
155 
156 	sal_Bool IsTransparent() const;
157 
158 	inline sal_Bool IsAnimated() const				{ return aGrfObj.IsAnimated(); }
159 
160 	inline sal_Bool IsChgTwipSize() const			{ return bChgTwipSize; }
161 	inline sal_Bool IsChgTwipSizeFromPixel() const	{ return bChgTwipSizeFromPixel; }
162 	inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) 		{ bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
163 
164 	inline sal_Bool IsGrafikArrived() const			{ return bGrafikArrived; }
165 	inline void SetGrafikArrived( sal_Bool b ) 		{ bGrafikArrived = b; }
166 
167 	inline sal_Bool IsFrameInPaint() const			{ return bFrameInPaint; }
168 	inline void SetFrameInPaint( sal_Bool b )		{ bFrameInPaint = b; }
169 
170 	inline sal_Bool IsScaleImageMap() const			{ return bScaleImageMap; }
171 	inline void SetScaleImageMap( sal_Bool b )		{ bScaleImageMap = b; }
172 #endif
173 		// steht in ndcopy.cxx
174 	virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
175 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
176 
177     // erneutes Einlesen, falls Graphic nicht Ok ist. Die
178     // aktuelle wird durch die neue ersetzt.
179 	sal_Bool ReRead( const String& rGrfName, const String& rFltName,
180                  const Graphic* pGraphic = 0,
181                  const GraphicObject* pGrfObj = 0,
182                  sal_Bool bModify = sal_True );
183     // Laden der Grafik unmittelbar vor der Anzeige
184 	short SwapIn( sal_Bool bWaitForData = sal_False );
185 		// Entfernen der Grafik, um Speicher freizugeben
186 	short SwapOut();
187 		// Zugriff auf den Storage-Streamnamen
188 	void SetStreamName( const String& r ) { aGrfObj.SetUserData( r ); }
189 	void SetNewStreamName( const String& r ) { aNewStrmName = r; }
190 	// is this node selected by any shell?
191 	sal_Bool IsSelected() const;
192 #endif
193 
194 		// Der Grafik sagen, dass sich der Node im Undobereich befindet
195 	virtual sal_Bool SavePersistentData();
196 	virtual sal_Bool RestorePersistentData();
197 
198 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
199 		// Abfrage der Link-Daten
200 	sal_Bool IsGrfLink() const 					{ return refLink.Is(); }
201 	inline sal_Bool IsLinkedFile() const;
202 	inline sal_Bool IsLinkedDDE() const;
203     ::sfx2::SvBaseLinkRef GetLink() const    { return refLink; }
204 	sal_Bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const;
205 	void ReleaseLink();
206 
207 	// Skalieren einer Image-Map: Die Image-Map wird um den Faktor
208 	// zwischen Grafik-Groesse und Rahmen-Groesse vergroessert/verkleinert
209 	void ScaleImageMap();
210 
211 	// returns the with our graphic attributes filled Graphic-Attr-Structure
212 	GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const;
213 
214 #endif
215     // --> OD 2007-01-18 #i73788#
216     boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer();
217     bool IsLinkedInputStreamReady() const;
218     void TriggerAsyncRetrieveInputStream();
219     void ApplyInputStream(
220         com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
221         const sal_Bool bIsStreamReadOnly );
222     void UpdateLinkWithInputStream();
223     // <--
224     // --> OD 2008-07-21 #i90395#
225     bool IsAsyncRetrieveInputStreamPossible() const;
226     // <--
227 };
228 
229 
230 // ----------------------------------------------------------------------
231 // Inline Metoden aus Node.hxx - erst hier ist der TxtNode bekannt !!
232 inline       SwGrfNode	 *SwNode::GetGrfNode()
233 {
234 	 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
235 }
236 inline const SwGrfNode   *SwNode::GetGrfNode() const
237 {
238 	 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
239 }
240 
241 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
242 inline sal_Bool SwGrfNode::IsLinkedFile() const
243 {
244 	return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
245 }
246 inline sal_Bool SwGrfNode::IsLinkedDDE() const
247 {
248 	return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
249 }
250 #endif
251 
252 
253 #endif
254