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