Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _NDGRF_HXX
21 : #define _NDGRF_HXX
22 : #include <sfx2/lnkbase.hxx>
23 : #include <svtools/grfmgr.hxx>
24 : #include <ndnotxt.hxx>
25 : #include <com/sun/star/embed/XStorage.hpp>
26 : #include <boost/shared_ptr.hpp>
27 : #include <boost/weak_ptr.hpp>
28 : class SwAsyncRetrieveInputStreamThreadConsumer;
29 :
30 : class SwGrfFmtColl;
31 : class SwDoc;
32 : class GraphicAttr;
33 : class SvStorage;
34 :
35 : // SwGrfNode
36 : class SW_DLLPUBLIC SwGrfNode: public SwNoTxtNode
37 : {
38 : friend class SwNodes;
39 :
40 : GraphicObject aGrfObj;
41 : GraphicObject *mpReplacementGraphic;
42 : ::sfx2::SvBaseLinkRef refLink; ///< If graphics only as link then pointer is set.
43 : Size nGrfSize;
44 : String aNewStrmName; /**< SW3/XML: new stream name (either SW3 stream
45 : // name or package url) */
46 : String aLowResGrf; ///< HTML: LowRes graphics (substitute until regular HighRes graphics is loaded).
47 : sal_Bool bTransparentFlagValid :1;
48 : sal_Bool bInSwapIn :1;
49 :
50 : sal_Bool bGrafikArrived :1;
51 : sal_Bool bChgTwipSize :1;
52 : sal_Bool bChgTwipSizeFromPixel :1;
53 : sal_Bool bLoadLowResGrf :1;
54 : sal_Bool bFrameInPaint :1; ///< To avoid Start-/EndActions in Paint via SwapIn.
55 : sal_Bool bScaleImageMap :1; ///< Scale image map in SetTwipSize.
56 :
57 : boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > mpThreadConsumer;
58 : bool mbLinkedInputStreamReady;
59 : com::sun::star::uno::Reference<com::sun::star::io::XInputStream> mxInputStream;
60 : sal_Bool mbIsStreamReadOnly;
61 :
62 : SwGrfNode( const SwNodeIndex& rWhere,
63 : const String& rGrfName, const String& rFltName,
64 : const Graphic* pGraphic,
65 : SwGrfFmtColl* pGrfColl,
66 : SwAttrSet* pAutoAttr = 0 );
67 : ///< Ctor for reading (SW/G) without graphics.
68 : SwGrfNode( const SwNodeIndex& rWhere,
69 : const String& rGrfName, const String& rFltName,
70 : SwGrfFmtColl* pGrfColl,
71 : SwAttrSet* pAutoAttr = 0 );
72 : SwGrfNode( const SwNodeIndex& rWhere,
73 : const GraphicObject& rGrfObj,
74 : SwGrfFmtColl* pGrfColl,
75 : SwAttrSet* pAutoAttr = 0 );
76 :
77 : void InsertLink( const String& rGrfName, const String& rFltName );
78 : sal_Bool ImportGraphic( SvStream& rStrm );
79 50 : sal_Bool HasStreamName() const { return aGrfObj.HasUserData(); }
80 : /** adjust return type and rename method to
81 : indicate that its an private one. */
82 :
83 : /** embedded graphic stream couldn't be inside a 3.1 - 5.2 storage any more.
84 : Thus, return value isn't needed any more. */
85 : void _GetStreamStorageNames( String& rStrmName, String& rStgName ) const;
86 :
87 : void DelStreamName();
88 : DECL_LINK( SwapGraphic, GraphicObject* );
89 :
90 : /** helper method to determine stream for the embedded graphic.
91 :
92 : Important note: caller of this method has to handle the thrown exceptions
93 : Storage, which should contain the stream of the embedded graphic, is
94 : provided via parameter. Otherwise the returned stream will be closed
95 : after the the method returns, because its parent stream is closed and deleted.
96 : Proposed name of embedded graphic stream is also provided by parameter.
97 :
98 : @author OD
99 :
100 : @param _refPics
101 : input parameter - reference to storage, which should contain the
102 : embedded graphic stream.
103 :
104 : @param _aStrmName
105 : input parameter - proposed name of the embedded graphic stream.
106 :
107 : @return SvStream*
108 : new created stream of the embedded graphic, which has to be destroyed
109 : after its usage. Could be NULL, if the stream isn't found.
110 : */
111 : SvStream* _GetStreamForEmbedGrf(
112 : const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _refPics,
113 : String& _aStrmName ) const;
114 :
115 : /** helper method to get a substorage of the document storage for readonly access.
116 :
117 : A substorage with the specified name will be opened readonly. If the provided
118 : name is empty the root storage will be returned.
119 :
120 : @param _aStgName
121 : input parameter - name of substorage. Can be empty.
122 :
123 : @return XStorage
124 : reference to substorage or the root storage
125 : */
126 : ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > _GetDocSubstorageOrRoot(
127 : const String& aStgName ) const;
128 :
129 : public:
130 : virtual ~SwGrfNode();
131 2 : const Graphic& GetGrf() const { return aGrfObj.GetGraphic(); }
132 0 : const GraphicObject& GetGrfObj() const { return aGrfObj; }
133 16 : GraphicObject& GetGrfObj() { return aGrfObj; }
134 : const GraphicObject* GetReplacementGrfObj() const;
135 :
136 : virtual SwCntntNode *SplitCntntNode( const SwPosition & );
137 :
138 : virtual Size GetTwipSize() const;
139 : #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
140 : void SetTwipSize( const Size& rSz );
141 :
142 : sal_Bool IsTransparent() const;
143 :
144 38 : inline sal_Bool IsAnimated() const { return aGrfObj.IsAnimated(); }
145 :
146 0 : inline sal_Bool IsChgTwipSize() const { return bChgTwipSize; }
147 0 : inline sal_Bool IsChgTwipSizeFromPixel() const { return bChgTwipSizeFromPixel; }
148 21 : inline void SetChgTwipSize( sal_Bool b, sal_Bool bFromPx=sal_False ) { bChgTwipSize = b; bChgTwipSizeFromPixel = bFromPx; }
149 :
150 0 : inline sal_Bool IsGrafikArrived() const { return bGrafikArrived; }
151 0 : inline void SetGrafikArrived( sal_Bool b ) { bGrafikArrived = b; }
152 :
153 0 : inline sal_Bool IsFrameInPaint() const { return bFrameInPaint; }
154 32 : inline void SetFrameInPaint( sal_Bool b ) { bFrameInPaint = b; }
155 :
156 41 : inline sal_Bool IsScaleImageMap() const { return bScaleImageMap; }
157 0 : inline void SetScaleImageMap( sal_Bool b ) { bScaleImageMap = b; }
158 : #endif
159 : /// in ndcopy.cxx
160 : virtual SwCntntNode* MakeCopy( SwDoc*, const SwNodeIndex& ) const;
161 : #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
162 :
163 : /** Re-read in case graphic was not OK. The current one
164 : gets replaced by the new one. */
165 : sal_Bool ReRead( const String& rGrfName, const String& rFltName,
166 : const Graphic* pGraphic = 0,
167 : const GraphicObject* pGrfObj = 0,
168 : sal_Bool bModify = sal_True );
169 : /// Loading of graphic immediately before displaying.
170 : short SwapIn( sal_Bool bWaitForData = sal_False );
171 : /// Remove graphic in order to free memory.
172 : short SwapOut();
173 : /// Access to storage stream-name.
174 : void SetStreamName( const String& r ) { aGrfObj.SetUserData( r ); }
175 : void SetNewStreamName( const String& r ) { aNewStrmName = r; }
176 : /// Is this node selected by any shell?
177 : sal_Bool IsSelected() const;
178 : #endif
179 :
180 : /// Communicate to graphic that node is in Undo-range.
181 : virtual sal_Bool SavePersistentData();
182 : virtual sal_Bool RestorePersistentData();
183 :
184 : #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
185 :
186 : /// Query link-data.
187 0 : bool IsGrfLink() const { return refLink.Is(); }
188 : inline bool IsLinkedFile() const;
189 : inline bool IsLinkedDDE() const;
190 0 : ::sfx2::SvBaseLinkRef GetLink() const { return refLink; }
191 : bool GetFileFilterNms( String* pFileNm, String* pFilterNm ) const;
192 : void ReleaseLink();
193 :
194 : /** Scale an image-map: the image-map becomes zoomed in / out by
195 : factor between graphic-size and border-size. */
196 : void ScaleImageMap();
197 :
198 : /// Returns the with our graphic attributes filled Graphic-Attr-Structure.
199 : GraphicAttr& GetGraphicAttr( GraphicAttr&, const SwFrm* pFrm ) const;
200 :
201 : #endif
202 : boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > GetThreadConsumer();
203 : bool IsLinkedInputStreamReady() const;
204 : void TriggerAsyncRetrieveInputStream();
205 : void ApplyInputStream(
206 : com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
207 : const sal_Bool bIsStreamReadOnly );
208 : void UpdateLinkWithInputStream();
209 : bool IsAsyncRetrieveInputStreamPossible() const;
210 : };
211 :
212 :
213 : // Inline methods from Node.hxx - it is only now that we know TxtNode!!
214 450 : inline SwGrfNode *SwNode::GetGrfNode()
215 : {
216 450 : return ND_GRFNODE == nNodeType ? (SwGrfNode*)this : 0;
217 : }
218 723 : inline const SwGrfNode *SwNode::GetGrfNode() const
219 : {
220 723 : return ND_GRFNODE == nNodeType ? (const SwGrfNode*)this : 0;
221 : }
222 :
223 : #ifndef _FESHVIEW_ONLY_INLINE_NEEDED
224 2 : inline bool SwGrfNode::IsLinkedFile() const
225 : {
226 2 : return refLink.Is() && OBJECT_CLIENT_GRF == refLink->GetObjType();
227 : }
228 1 : inline bool SwGrfNode::IsLinkedDDE() const
229 : {
230 1 : return refLink.Is() && OBJECT_CLIENT_DDE == refLink->GetObjType();
231 : }
232 : #endif
233 :
234 : #endif
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|