1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SOT_STG_HXX
21 #define INCLUDED_SOT_STG_HXX
23 #include <com/sun/star/uno/Any.h>
24 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/io/XInputStream.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
30 #include <com/sun/star/embed/XStorage.hpp>
33 #include <tools/solar.h>
34 #include <tools/stream.hxx>
35 #include <tools/globname.hxx>
36 #include <sot/storinfo.hxx>
37 #include <sot/sotdllapi.h>
45 typedef struct SvGUID ClsId
;
47 class SOT_DLLPUBLIC StorageBase
: public SvRefBase
50 mutable ErrCode m_nError
; // error code
51 StreamMode m_nMode
; // open mode
54 virtual ~StorageBase() override
;
56 virtual bool Validate( bool=false ) const = 0;
57 virtual bool ValidateMode( StreamMode
) const = 0;
58 void ResetError() const;
59 void SetError( ErrCode
) const;
60 ErrCode
GetError() const;
61 bool Good() const { return m_nError
== ERRCODE_NONE
; }
62 StreamMode
GetMode() const { return m_nMode
; }
63 void SetAutoCommit( bool bSet
)
64 { m_bAutoCommit
= bSet
; }
67 class BaseStorageStream
: public StorageBase
70 virtual sal_uLong
Read( void * pData
, sal_uLong nSize
) = 0;
71 virtual sal_uLong
Write( const void* pData
, sal_uLong nSize
) = 0;
72 virtual sal_uInt64
Seek( sal_uInt64 nPos
) = 0;
73 virtual sal_uLong
Tell() = 0;
74 virtual void Flush() = 0;
75 virtual bool SetSize( sal_uLong nNewSize
) = 0;
76 virtual sal_uLong
GetSize() const = 0;
77 virtual void CopyTo( BaseStorageStream
* pDestStm
) = 0;
78 virtual bool Commit() = 0;
79 virtual bool Equals( const BaseStorageStream
& rStream
) const = 0;
82 enum class SotClipboardFormatId
: sal_uInt32
;
84 class SAL_DLLPUBLIC_RTTI BaseStorage
: public StorageBase
87 virtual const OUString
& GetName() const = 0;
88 virtual bool IsRoot() const = 0;
89 virtual void SetClassId( const ClsId
& ) = 0;
90 virtual const ClsId
& GetClassId() const = 0;
91 virtual void SetDirty() = 0;
92 virtual void SetClass( const SvGlobalName
& rClass
,
93 SotClipboardFormatId nOriginalClipFormat
,
94 const OUString
& rUserTypeName
) = 0;
95 virtual SvGlobalName
GetClassName() = 0;
96 virtual SotClipboardFormatId
GetFormat() = 0;
97 virtual OUString
GetUserName() = 0;
98 virtual void FillInfoList( SvStorageInfoList
* ) const = 0;
99 virtual bool CopyTo( BaseStorage
* pDestStg
) const = 0;
100 virtual bool Commit() = 0;
101 virtual bool Revert() = 0;
102 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
103 StreamMode
= StreamMode::STD_READWRITE
,
104 bool bDirect
= true ) = 0;
105 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
106 StreamMode
= StreamMode::STD_READWRITE
,
107 bool bDirect
= false ) = 0;
108 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
109 StreamMode
= StreamMode::STD_READWRITE
,
110 bool bDirect
= false ) = 0;
111 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
112 StreamMode
= StreamMode::STD_READWRITE
,
113 bool bDirect
= false ) = 0;
114 virtual bool IsStream( const OUString
& rEleName
) const = 0;
115 virtual bool IsStorage( const OUString
& rEleName
) const = 0;
116 virtual bool IsContained( const OUString
& rEleName
) const = 0;
117 virtual void Remove( const OUString
& rEleName
) = 0;
118 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) = 0;
119 virtual bool ValidateFAT() = 0;
120 virtual bool Equals( const BaseStorage
& rStream
) const = 0;
126 StreamMode
& nStreamMode
; // open mode
127 StgIo
* pIo
; // I/O subsystem
128 StgDirEntry
* pEntry
; // the dir entry
129 OLEStorageBase( StgIo
*, StgDirEntry
*, StreamMode
& );
131 bool Validate_Impl( bool ) const;
132 static bool ValidateMode_Impl( StreamMode
, StgDirEntry
const * p
= nullptr );
135 class StorageStream
: public BaseStorageStream
, public OLEStorageBase
137 //friend class Storage;
138 sal_uLong nPos
; // current position
140 virtual ~StorageStream() override
;
142 StorageStream( StgIo
*, StgDirEntry
*, StreamMode
);
143 virtual sal_uLong
Read( void * pData
, sal_uLong nSize
) override
;
144 virtual sal_uLong
Write( const void* pData
, sal_uLong nSize
) override
;
145 virtual sal_uInt64
Seek( sal_uInt64 nPos
) override
;
146 virtual sal_uLong
Tell() override
{ return nPos
; }
147 virtual void Flush() override
;
148 virtual bool SetSize( sal_uLong nNewSize
) override
;
149 virtual sal_uLong
GetSize() const override
;
150 virtual void CopyTo( BaseStorageStream
* pDestStm
) override
;
151 virtual bool Commit() final override
;
152 virtual bool Validate( bool=false ) const override
;
153 virtual bool ValidateMode( StreamMode
) const override
;
154 virtual bool Equals( const BaseStorageStream
& rStream
) const override
;
157 class UCBStorageStream
;
159 class SOT_DLLPUBLIC Storage
: public BaseStorage
, public OLEStorageBase
163 void Init( bool bCreate
);
164 Storage( StgIo
*, StgDirEntry
*, StreamMode
);
166 virtual ~Storage() override
;
168 Storage( const OUString
&, StreamMode
, bool bDirect
);
169 Storage( SvStream
& rStrm
, bool bDirect
);
170 Storage( UCBStorageStream
& rStrm
, bool bDirect
);
172 static bool IsStorageFile( const OUString
& rFileName
);
173 static bool IsStorageFile( SvStream
* );
175 virtual const OUString
& GetName() const final override
;
176 virtual bool IsRoot() const override
{ return bIsRoot
; }
177 virtual void SetClassId( const ClsId
& ) override
;
178 virtual const ClsId
& GetClassId() const override
;
179 virtual void SetDirty() override
;
180 virtual void SetClass( const SvGlobalName
& rClass
,
181 SotClipboardFormatId nOriginalClipFormat
,
182 const OUString
& rUserTypeName
) override
;
183 virtual SvGlobalName
GetClassName() override
;
184 virtual SotClipboardFormatId
GetFormat() override
;
185 virtual OUString
GetUserName() override
;
186 virtual void FillInfoList( SvStorageInfoList
* ) const override
;
187 virtual bool CopyTo( BaseStorage
* pDestStg
) const override
;
188 virtual bool Commit() final override
;
189 virtual bool Revert() override
;
190 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
191 StreamMode
= StreamMode::STD_READWRITE
,
192 bool bDirect
= true ) override
;
193 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
194 StreamMode
= StreamMode::STD_READWRITE
,
195 bool bDirect
= false ) override
;
196 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
197 StreamMode
= StreamMode::STD_READWRITE
,
198 bool bDirect
= false ) override
;
199 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
200 StreamMode
= StreamMode::STD_READWRITE
,
201 bool bDirect
= false ) override
;
202 virtual bool IsStream( const OUString
& rEleName
) const override
;
203 virtual bool IsStorage( const OUString
& rEleName
) const override
;
204 virtual bool IsContained( const OUString
& rEleName
) const override
;
205 virtual void Remove( const OUString
& rEleName
) override
;
206 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) override
;
207 virtual bool ValidateFAT() override
;
208 virtual bool Validate( bool=false ) const override
;
209 virtual bool ValidateMode( StreamMode
) const override
;
210 bool ValidateMode( StreamMode
, StgDirEntry
const * p
) const;
211 virtual bool Equals( const BaseStorage
& rStream
) const override
;
214 class UCBStorageStream_Impl
;
215 class UCBStorageStream
: public BaseStorageStream
217 friend class UCBStorage
;
219 UCBStorageStream_Impl
*
222 virtual ~UCBStorageStream() override
;
224 UCBStorageStream( const OUString
& rName
, StreamMode nMode
, bool bDirect
, bool bRepair
, css::uno::Reference
< css::ucb::XProgressHandler
> const & xProgress
);
225 UCBStorageStream( UCBStorageStream_Impl
* );
227 virtual sal_uLong
Read( void * pData
, sal_uLong nSize
) override
;
228 virtual sal_uLong
Write( const void* pData
, sal_uLong nSize
) override
;
229 virtual sal_uInt64
Seek( sal_uInt64 nPos
) override
;
230 virtual sal_uLong
Tell() override
;
231 virtual void Flush() override
;
232 virtual bool SetSize( sal_uLong nNewSize
) override
;
233 virtual sal_uLong
GetSize() const override
;
234 virtual void CopyTo( BaseStorageStream
* pDestStm
) override
;
235 virtual bool Commit() override
;
236 virtual bool Validate( bool=false ) const override
;
237 virtual bool ValidateMode( StreamMode
) const override
;
238 virtual bool Equals( const BaseStorageStream
& rStream
) const override
;
239 bool SetProperty( const OUString
& rName
, const css::uno::Any
& rValue
);
241 SvStream
* GetModifySvStream();
249 class UCBStorage_Impl
;
250 struct UCBStorageElement_Impl
;
251 class SOT_DLLPUBLIC UCBStorage
: public BaseStorage
253 UCBStorage_Impl
* pImp
;
256 virtual ~UCBStorage() override
;
258 static bool IsStorageFile( SvStream
* );
259 static OUString
GetLinkedFile( SvStream
& );
261 UCBStorage( const ::ucbhelper::Content
& rContent
,
262 const OUString
& rName
,
267 UCBStorage( const OUString
& rName
,
272 UCBStorage( const OUString
& rName
,
277 css::uno::Reference
< css::ucb::XProgressHandler
> const &
280 UCBStorage( UCBStorage_Impl
* );
282 UCBStorage( SvStream
& rStrm
, bool bDirect
);
284 virtual const OUString
& GetName() const override
;
285 virtual bool IsRoot() const override
;
286 virtual void SetClassId( const ClsId
& ) override
;
287 virtual const ClsId
& GetClassId() const override
;
288 virtual void SetDirty() override
;
289 virtual void SetClass( const SvGlobalName
& rClass
,
290 SotClipboardFormatId nOriginalClipFormat
,
291 const OUString
& rUserTypeName
) override
;
292 virtual SvGlobalName
GetClassName() override
;
293 virtual SotClipboardFormatId
GetFormat() override
;
294 virtual OUString
GetUserName() override
;
295 virtual void FillInfoList( SvStorageInfoList
* ) const override
;
296 virtual bool CopyTo( BaseStorage
* pDestStg
) const override
;
297 virtual bool Commit() final override
;
298 virtual bool Revert() override
;
299 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
300 StreamMode
= StreamMode::STD_READWRITE
,
301 bool bDirect
= true ) override
;
302 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
303 StreamMode
= StreamMode::STD_READWRITE
,
304 bool bDirect
= false ) override
;
305 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
306 StreamMode
= StreamMode::STD_READWRITE
,
307 bool bDirect
= false ) override
;
308 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
309 StreamMode
= StreamMode::STD_READWRITE
,
310 bool bDirect
= false ) override
;
311 virtual bool IsStream( const OUString
& rEleName
) const override
;
312 virtual bool IsStorage( const OUString
& rEleName
) const override
;
313 virtual bool IsContained( const OUString
& rEleName
) const override
;
314 virtual void Remove( const OUString
& rEleName
) override
;
315 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) override
;
316 virtual bool ValidateFAT() override
;
317 virtual bool Validate( bool=false ) const override
;
318 virtual bool ValidateMode( StreamMode
) const override
;
319 virtual bool Equals( const BaseStorage
& rStream
) const override
;
321 UCBStorageElement_Impl
* FindElement_Impl( const OUString
& rName
) const;
322 bool CopyStorageElement_Impl( UCBStorageElement_Impl
const & rElement
,
323 BaseStorage
* pDest
, const OUString
& rNew
) const;
324 BaseStorage
* OpenStorage_Impl( const OUString
& rEleName
,
325 StreamMode
, bool bDirect
, bool bForceUCBStorage
);
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */