xref: /aoo42x/main/sw/inc/ndgrf.hxx (revision fb0b81f5)
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 #include <com/sun/star/embed/XStorage.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 class SwAsyncRetrieveInputStreamThreadConsumer;
32 
33 class SwGrfFmtColl;
34 class SwDoc;
35 class GraphicAttr;
36 class SvStorage;
37 
38 
39 class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode
40 {
41     friend class SwNodes;
42 
43     GraphicObject maGrfObj;
44     GraphicObject* mpReplacementGraphic;
45     ::sfx2::SvBaseLinkRef refLink;       // falls Grafik nur als Link, dann Pointer gesetzt
46     Size nGrfSize;
47     sal_Bool bInSwapIn :1;
48 
49     sal_Bool bGrafikArrived :1;
50     sal_Bool bChgTwipSize :1;
51     sal_Bool bChgTwipSizeFromPixel :1;
52     sal_Bool bLoadLowResGrf :1;
53     sal_Bool bFrameInPaint :1;  // Um Start-/EndActions im Paint (ueber SwapIn zu verhindern.
54     sal_Bool bScaleImageMap :1; // Image-Map in SetTwipSize skalieren
55 
56     boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
57     bool mbLinkedInputStreamReady;
58     com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream;
59     sal_Bool mbIsStreamReadOnly;
60 
61 	SwGrfNode( const SwNodeIndex& rWhere,
62 			   const String& rGrfName, const String& rFltName,
63 			   const Graphic* pGraphic,
64 			   SwGrfFmtColl* pGrfColl,
65 			   SwAttrSet* pAutoAttr = 0 );
66 	// Ctor fuer Einlesen (SW/G) ohne Grafik
67 	SwGrfNode( const SwNodeIndex& rWhere,
68 			   const String& rGrfName, const String& rFltName,
69 			   SwGrfFmtColl* pGrfColl,
70 			   SwAttrSet* pAutoAttr = 0 );
71 	SwGrfNode( const SwNodeIndex& rWhere,
72 			   const GraphicObject& rGrfObj,
73 			   SwGrfFmtColl* pGrfColl,
74 			   SwAttrSet* pAutoAttr = 0 );
75 
76 	void InsertLink( const String& rGrfName, const String& rFltName );
77 	sal_Bool ImportGraphic( SvStream& rStrm );
78     void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const;
79 	void DelStreamName();
80 	DECL_LINK( SwapGraphic, GraphicObject* );
81 
82     /** helper method to determine stream for the embedded graphic.
83 
84         OD 2005-05-04 #i48434#
85         Important note: caller of this method has to handle the thrown exceptions
86         OD, MAV 2005-08-17 #i53025#
87         Storage, which should contain the stream of the embedded graphic, is
88         provided via parameter. Otherwise the returned stream will be closed
89         after the method returns, because its parent stream is closed and deleted.
90         Proposed name of embedded graphic stream is also provided by parameter.
91 
92         @author OD
93 
94         @param _refPics
95         input parameter - reference to storage, which should contain the
96         embedded graphic stream.
97 
98         @param _aStrmName
99         input parameter - proposed name of the embedded graphic stream.
100 
101         @return SvStream*
102         new created stream of the embedded graphic, which has to be destroyed
103         after its usage. Could be NULL, if the stream isn't found.
104     */
105     SvStream* _GetStreamForEmbedGrf(
106             const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics,
107             String& _aStrmName ) const;
108 
109     /** helper method to get a substorage of the document storage for readonly access.
110 
111         OD, MAV 2005-08-17 #i53025#
112         A substorage with the specified name will be opened readonly. If the provided
113         name is empty the root storage will be returned.
114 
115         @param _aStgName
116         input parameter - name of substorage. Can be empty.
117 
118         @return XStorage
119         reference to substorage or the root storage
120     */
121     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot(
122                                                 const String& aStgName ) const;
123 
124     /// allow reaction on change of content of GraphicObject, so always call
125     /// when GraphicObject content changes
126     void onGraphicChanged();
127 
128 public:
129 	virtual ~SwGrfNode();
GetGrf() const130 	const Graphic& 			GetGrf() const  	{ return maGrfObj.GetGraphic(); }
GetGrfObj() const131 	const GraphicObject&	GetGrfObj() const  	{ return maGrfObj; }
132     const GraphicObject* GetReplacementGrfObj() const;
133     virtual SwCntntNode *SplitCntntNode( const SwPosition & );
134 
135     /// isolated only way to set GraphicObject to allow more actions when doing so
136     void SetGraphic(const Graphic& rGraphic, const String& rLink);
137 
138     /// wrappers for non-const calls at GraphicObject
ReleaseGraphicFromCache()139     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)140     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)141     void StopGraphicAnimation(OutputDevice* pOut = NULL, long nExtraData = 0) { maGrfObj.StopAnimation(pOut, nExtraData); }
142 
143     virtual Size GetTwipSize() const;
144 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
145 	void SetTwipSize( const Size& rSz );
146 
147 	sal_Bool IsTransparent() const;
148 
IsAnimated() const149 	inline sal_Bool IsAnimated() const				{ return maGrfObj.IsAnimated(); }
150 
IsChgTwipSize() const151 	inline sal_Bool IsChgTwipSize() const			{ return bChgTwipSize; }
IsChgTwipSizeFromPixel() const152 	inline sal_Bool IsChgTwipSizeFromPixel() const	{ return bChgTwipSizeFromPixel; }
SetChgTwipSize(sal_Bool b,sal_Bool bFromPx=sal_False)153 	inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) 		{ bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
154 
IsGrafikArrived() const155 	inline sal_Bool IsGrafikArrived() const			{ return bGrafikArrived; }
SetGrafikArrived(sal_Bool b)156 	inline void SetGrafikArrived( sal_Bool b ) 		{ bGrafikArrived = b; }
157 
IsFrameInPaint() const158 	inline sal_Bool IsFrameInPaint() const			{ return bFrameInPaint; }
SetFrameInPaint(sal_Bool b)159 	inline void SetFrameInPaint( sal_Bool b )		{ bFrameInPaint = b; }
160 
IsScaleImageMap() const161 	inline sal_Bool IsScaleImageMap() const			{ return bScaleImageMap; }
SetScaleImageMap(sal_Bool b)162 	inline void SetScaleImageMap( sal_Bool b )		{ bScaleImageMap = b; }
163 #endif
164 		// steht in ndcopy.cxx
165 	virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
166 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
167 
168     // erneutes Einlesen, falls Graphic nicht Ok ist. Die
169     // aktuelle wird durch die neue ersetzt.
170 	sal_Bool ReRead( const String& rGrfName, const String& rFltName,
171                  const Graphic* pGraphic = 0,
172                  const GraphicObject* pGrfObj = 0,
173                  sal_Bool bModify = sal_True );
174     // Laden der Grafik unmittelbar vor der Anzeige
175     short SwapIn( sal_Bool bWaitForData = sal_False );
176     // Entfernen der Grafik, um Speicher freizugeben
177     short SwapOut();
178 
HasEmbeddedStreamName() const179     sal_Bool HasEmbeddedStreamName() const { return maGrfObj.HasUserData(); }
180     // applying new stream name for embedded graphic - needed as saving the document might change this stream name
ApplyNewEmbeddedStreamName(const String & r)181     void ApplyNewEmbeddedStreamName( const String& r )
182     {
183         maGrfObj.SetUserData( r );
184     }
185 
186     // is this node selected by any shell?
187     sal_Bool IsSelected() const;
188 #endif
189 
190 		// Der Grafik sagen, dass sich der Node im Undobereich befindet
191 	virtual sal_Bool SavePersistentData();
192 	virtual sal_Bool RestorePersistentData();
193 
194 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
195 		// Abfrage der Link-Daten
IsGrfLink() const196 	sal_Bool IsGrfLink() const 					{ return refLink.Is(); }
197 	inline sal_Bool IsLinkedFile() const;
198 	inline sal_Bool IsLinkedDDE() const;
GetLink() const199     ::sfx2::SvBaseLinkRef GetLink() const    { return refLink; }
200 	sal_Bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const;
201 	void ReleaseLink();
202 
203 	// Skalieren einer Image-Map: Die Image-Map wird um den Faktor
204 	// zwischen Grafik-Groesse und Rahmen-Groesse vergroessert/verkleinert
205 	void ScaleImageMap();
206 
207 	// returns the with our graphic attributes filled Graphic-Attr-Structure
208 	GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const;
209 
210 #endif
211     boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer();
212     bool IsLinkedInputStreamReady() const;
213     void TriggerAsyncRetrieveInputStream();
214     void ApplyInputStream(
215         com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
216         const sal_Bool bIsStreamReadOnly );
217     void UpdateLinkWithInputStream();
218     bool IsAsyncRetrieveInputStreamPossible() const;
219 };
220 
221 
222 // ----------------------------------------------------------------------
223 // Inline Metoden aus Node.hxx - erst hier ist der TxtNode bekannt !!
GetGrfNode()224 inline       SwGrfNode	 *SwNode::GetGrfNode()
225 {
226 	 return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
227 }
GetGrfNode() const228 inline const SwGrfNode   *SwNode::GetGrfNode() const
229 {
230 	 return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
231 }
232 
233 #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
IsLinkedFile() const234 inline sal_Bool SwGrfNode::IsLinkedFile() const
235 {
236 	return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
237 }
IsLinkedDDE() const238 inline sal_Bool SwGrfNode::IsLinkedDDE() const
239 {
240 	return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
241 }
242 #endif
243 
244 
245 #endif
246