xref: /aoo41x/main/sw/inc/ndgrf.hxx (revision 8a2cae91)
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;
3757326f99SOliver-Rainer Wittmann 
3857326f99SOliver-Rainer Wittmann 
39cdf0e10cSrcweir class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode
40cdf0e10cSrcweir {
4157326f99SOliver-Rainer Wittmann     friend class SwNodes;
42cdf0e10cSrcweir 
4357326f99SOliver-Rainer Wittmann     GraphicObject maGrfObj;
4457326f99SOliver-Rainer Wittmann     GraphicObject* mpReplacementGraphic;
45cdf0e10cSrcweir     ::sfx2::SvBaseLinkRef refLink;       // falls Grafik nur als Link, dann Pointer gesetzt
4657326f99SOliver-Rainer Wittmann     Size nGrfSize;
4757326f99SOliver-Rainer Wittmann     sal_Bool bInSwapIn :1;
4857326f99SOliver-Rainer Wittmann 
4957326f99SOliver-Rainer Wittmann     sal_Bool bGrafikArrived :1;
5057326f99SOliver-Rainer Wittmann     sal_Bool bChgTwipSize :1;
5157326f99SOliver-Rainer Wittmann     sal_Bool bChgTwipSizeFromPixel :1;
5257326f99SOliver-Rainer Wittmann     sal_Bool bLoadLowResGrf :1;
5357326f99SOliver-Rainer Wittmann     sal_Bool bFrameInPaint :1;  // Um Start-/EndActions im Paint (ueber SwapIn zu verhindern.
5457326f99SOliver-Rainer Wittmann     sal_Bool bScaleImageMap :1; // Image-Map in SetTwipSize skalieren
5557326f99SOliver-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 );
78cdf0e10cSrcweir     void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const;
79cdf0e10cSrcweir 	void DelStreamName();
80cdf0e10cSrcweir 	DECL_LINK( SwapGraphic, GraphicObject* );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /** helper method to determine stream for the embedded graphic.
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         OD 2005-05-04 #i48434#
85cdf0e10cSrcweir         Important note: caller of this method has to handle the thrown exceptions
86cdf0e10cSrcweir         OD, MAV 2005-08-17 #i53025#
87cdf0e10cSrcweir         Storage, which should contain the stream of the embedded graphic, is
88cdf0e10cSrcweir         provided via parameter. Otherwise the returned stream will be closed
89cdf0e10cSrcweir         after the the method returns, because its parent stream is closed and deleted.
90cdf0e10cSrcweir         Proposed name of embedded graphic stream is also provided by parameter.
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         @author OD
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         @param _refPics
95cdf0e10cSrcweir         input parameter - reference to storage, which should contain the
96cdf0e10cSrcweir         embedded graphic stream.
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         @param _aStrmName
99cdf0e10cSrcweir         input parameter - proposed name of the embedded graphic stream.
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         @return SvStream*
102cdf0e10cSrcweir         new created stream of the embedded graphic, which has to be destroyed
103cdf0e10cSrcweir         after its usage. Could be NULL, if the stream isn't found.
104cdf0e10cSrcweir     */
105cdf0e10cSrcweir     SvStream* _GetStreamForEmbedGrf(
106cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics,
107cdf0e10cSrcweir             String& _aStrmName ) const;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     /** helper method to get a substorage of the document storage for readonly access.
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         OD, MAV 2005-08-17 #i53025#
112cdf0e10cSrcweir         A substorage with the specified name will be opened readonly. If the provided
113cdf0e10cSrcweir         name is empty the root storage will be returned.
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         @param _aStgName
116cdf0e10cSrcweir         input parameter - name of substorage. Can be empty.
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         @return XStorage
119cdf0e10cSrcweir         reference to substorage or the root storage
120cdf0e10cSrcweir     */
121cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot(
122cdf0e10cSrcweir                                                 const String& aStgName ) const;
123cdf0e10cSrcweir 
124*8a2cae91SOliver-Rainer Wittmann     /// allow reaction on change of content of GraphicObject, so always call
125*8a2cae91SOliver-Rainer Wittmann     /// when GraphicObject content changes
126*8a2cae91SOliver-Rainer Wittmann     void onGraphicChanged();
127*8a2cae91SOliver-Rainer Wittmann 
128cdf0e10cSrcweir public:
129cdf0e10cSrcweir 	virtual ~SwGrfNode();
GetGrf() const130172c67b2SArmin Le Grand 	const Graphic& 			GetGrf() const  	{ return maGrfObj.GetGraphic(); }
GetGrfObj() const131172c67b2SArmin Le Grand 	const GraphicObject&	GetGrfObj() const  	{ return maGrfObj; }
132ddde725dSArmin Le Grand     const GraphicObject* GetReplacementGrfObj() const;
133cdf0e10cSrcweir     virtual SwCntntNode *SplitCntntNode( const SwPosition & );
134cdf0e10cSrcweir 
135172c67b2SArmin Le Grand     /// isolated only way to set GraphicObject to allow more actions when doing so
136172c67b2SArmin Le Grand     void SetGraphic(const Graphic& rGraphic, const String& rLink);
137172c67b2SArmin Le Grand 
138172c67b2SArmin Le Grand     /// wrappers for non-const calls at GraphicObject
ReleaseGraphicFromCache()139172c67b2SArmin Le Grand     void ReleaseGraphicFromCache() { maGrfObj.ReleaseFromCache(); }
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)140172c67b2SArmin 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); }
StopGraphicAnimation(OutputDevice * pOut=NULL,long nExtraData=0)141172c67b2SArmin Le Grand     void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); }
142172c67b2SArmin Le Grand 
143172c67b2SArmin Le Grand     virtual Size GetTwipSize() const;
144cdf0e10cSrcweir #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
145cdf0e10cSrcweir 	void SetTwipSize( const Size& rSz );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	sal_Bool IsTransparent() const;
148cdf0e10cSrcweir 
IsAnimated() const149172c67b2SArmin Le Grand 	inline sal_Bool IsAnimated() const				{ return maGrfObj.IsAnimated(); }
150cdf0e10cSrcweir 
IsChgTwipSize() const151cdf0e10cSrcweir 	inline sal_Bool IsChgTwipSize() const			{ return bChgTwipSize; }
IsChgTwipSizeFromPixel() const152cdf0e10cSrcweir 	inline sal_Bool IsChgTwipSizeFromPixel() const	{ return bChgTwipSizeFromPixel; }
SetChgTwipSize(sal_Bool b,sal_Bool bFromPx=sal_False)153cdf0e10cSrcweir 	inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) 		{ bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
154cdf0e10cSrcweir 
IsGrafikArrived() const155cdf0e10cSrcweir 	inline sal_Bool IsGrafikArrived() const			{ return bGrafikArrived; }
SetGrafikArrived(sal_Bool b)156cdf0e10cSrcweir 	inline void SetGrafikArrived( sal_Bool b ) 		{ bGrafikArrived = b; }
157cdf0e10cSrcweir 
IsFrameInPaint() const158cdf0e10cSrcweir 	inline sal_Bool IsFrameInPaint() const			{ return bFrameInPaint; }
SetFrameInPaint(sal_Bool b)159cdf0e10cSrcweir 	inline void SetFrameInPaint( sal_Bool b )		{ bFrameInPaint = b; }
160cdf0e10cSrcweir 
IsScaleImageMap() const161cdf0e10cSrcweir 	inline sal_Bool IsScaleImageMap() const			{ return bScaleImageMap; }
SetScaleImageMap(sal_Bool b)162cdf0e10cSrcweir 	inline void SetScaleImageMap( sal_Bool b )		{ bScaleImageMap = b; }
163cdf0e10cSrcweir #endif
164cdf0e10cSrcweir 		// steht in ndcopy.cxx
165cdf0e10cSrcweir 	virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
166cdf0e10cSrcweir #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     // erneutes Einlesen, falls Graphic nicht Ok ist. Die
169cdf0e10cSrcweir     // aktuelle wird durch die neue ersetzt.
170cdf0e10cSrcweir 	sal_Bool ReRead( const String& rGrfName, const String& rFltName,
171cdf0e10cSrcweir                  const Graphic* pGraphic = 0,
172cdf0e10cSrcweir                  const GraphicObject* pGrfObj = 0,
173cdf0e10cSrcweir                  sal_Bool bModify = sal_True );
174cdf0e10cSrcweir     // Laden der Grafik unmittelbar vor der Anzeige
17557326f99SOliver-Rainer Wittmann     short SwapIn( sal_Bool bWaitForData = sal_False );
17657326f99SOliver-Rainer Wittmann     // Entfernen der Grafik, um Speicher freizugeben
17757326f99SOliver-Rainer Wittmann     short SwapOut();
17857326f99SOliver-Rainer Wittmann 
HasEmbeddedStreamName() const1790b19465bSOliver-Rainer Wittmann     sal_Bool HasEmbeddedStreamName() const { return maGrfObj.HasUserData(); }
18057326f99SOliver-Rainer Wittmann     // applying new stream name for embedded graphic - needed as saving the document might change this stream name
ApplyNewEmbeddedStreamName(const String & r)18157326f99SOliver-Rainer Wittmann     void ApplyNewEmbeddedStreamName( const String& r )
18257326f99SOliver-Rainer Wittmann     {
18357326f99SOliver-Rainer Wittmann         maGrfObj.SetUserData( r );
18457326f99SOliver-Rainer Wittmann     }
18557326f99SOliver-Rainer Wittmann 
18657326f99SOliver-Rainer Wittmann     // is this node selected by any shell?
18757326f99SOliver-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
IsGrfLink() const196cdf0e10cSrcweir 	sal_Bool IsGrfLink() const 					{ return refLink.Is(); }
197cdf0e10cSrcweir 	inline sal_Bool IsLinkedFile() const;
198cdf0e10cSrcweir 	inline sal_Bool IsLinkedDDE() const;
GetLink() const199cdf0e10cSrcweir     ::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 !!
GetGrfNode()224cdf0e10cSrcweir inline       SwGrfNode	 *SwNode::GetGrfNode()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
227cdf0e10cSrcweir }
GetGrfNode() const228cdf0e10cSrcweir inline const SwGrfNode   *SwNode::GetGrfNode() const
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
IsLinkedFile() const234cdf0e10cSrcweir inline sal_Bool SwGrfNode::IsLinkedFile() const
235cdf0e10cSrcweir {
236cdf0e10cSrcweir 	return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
237cdf0e10cSrcweir }
IsLinkedDDE() const238cdf0e10cSrcweir inline sal_Bool SwGrfNode::IsLinkedDDE() const
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
241cdf0e10cSrcweir }
242cdf0e10cSrcweir #endif
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir #endif
246