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_STORAGE_HXX
21 #define INCLUDED_SOT_STORAGE_HXX
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/embed/XStorage.hpp>
26 #include <sot/object.hxx>
27 #include <tools/stream.hxx>
28 #include <vcl/errcode.hxx>
29 #include <sot/storinfo.hxx>
30 #include <sot/sotdllapi.h>
32 enum class SotClipboardFormatId
: sal_uLong
;
35 class BaseStorageStream
;
36 class SOT_DLLPUBLIC SotStorageStream
: virtual public SotObject
, public SvStream
38 friend class SotStorage
;
39 BaseStorageStream
* pOwnStm
; // pointer to the own stream
41 virtual std::size_t GetData(void* pData
, std::size_t nSize
) override
;
42 virtual std::size_t PutData(const void* pData
, std::size_t nSize
) override
;
43 virtual sal_uInt64
SeekPos(sal_uInt64 nPos
) override
;
44 virtual void FlushData() override
;
45 virtual ~SotStorageStream() override
;
47 SotStorageStream( const OUString
&,
48 StreamMode
= StreamMode::STD_READWRITE
);
49 SotStorageStream( BaseStorageStream
*pStm
);
51 virtual void ResetError() override
;
53 virtual void SetSize( sal_uInt64 nNewSize
) override
;
54 sal_uInt32
GetSize() const;
55 void CopyTo( SotStorageStream
* pDestStm
);
57 bool SetProperty( const OUString
& rName
, const css::uno::Any
& rValue
);
58 virtual sal_uInt64
remainingSize() override
;
62 class SOT_DLLPUBLIC SotStorage
: virtual public SotObject
64 friend class SotStorageStream
;
66 BaseStorage
* m_pOwnStg
; // target storage
67 SvStream
* m_pStorStm
; // only for SDSTORAGES
69 OUString m_aName
; // name of the storage
70 bool m_bIsRoot
; // e.g.: File Storage
72 OString m_aKey
; // aKey.Len != 0 -> encryption
76 virtual ~SotStorage() override
;
77 void CreateStorage( bool bUCBStorage
, StreamMode
);
79 SotStorage( const OUString
&,
80 StreamMode
= StreamMode::STD_READWRITE
);
81 SotStorage( bool bUCBStorage
, const OUString
&,
82 StreamMode
= StreamMode::STD_READWRITE
);
83 SotStorage( BaseStorage
* );
84 SotStorage( SvStream
& rStm
);
85 SotStorage( bool bUCBStorage
, SvStream
& rStm
);
86 SotStorage( SvStream
* pStm
, bool bDelete
);
88 SvMemoryStream
* CreateMemoryStream();
90 static bool IsStorageFile( const OUString
& rFileName
);
91 static bool IsStorageFile( SvStream
* pStream
);
93 const OUString
& GetName() const;
97 const OString
& GetKey() const { return m_aKey
;}
99 void SetVersion( long nVers
)
103 long GetVersion() const
108 ErrCode
GetError() const { return ERRCODE_TOERROR(m_nError
); }
109 void SetError( ErrCode nErrorCode
)
111 if( m_nError
== SVSTREAM_OK
)
112 m_nError
= nErrorCode
;
115 void SignAsRoot( bool b
) { m_bIsRoot
= b
; }
118 void SetClass( const SvGlobalName
& rClass
,
119 SotClipboardFormatId bOriginalClipFormat
,
120 const OUString
& rUserTypeName
);
121 SvGlobalName
GetClassName(); // type of data in the storage
122 SotClipboardFormatId
GetFormat();
123 OUString
GetUserName();
125 // list of all elements
126 void FillInfoList( SvStorageInfoList
* ) const;
127 bool CopyTo( SotStorage
* pDestStg
);
130 // create stream with connection to Storage,
131 // more or less a Parent-Child relationship
132 SotStorageStream
* OpenSotStream( const OUString
& rEleName
,
133 StreamMode
= StreamMode::STD_READWRITE
);
134 SotStorage
* OpenSotStorage( const OUString
& rEleName
,
135 StreamMode
= StreamMode::STD_READWRITE
,
136 bool transacted
= true );
137 // query whether Storage or Stream
138 bool IsStream( const OUString
& rEleName
) const;
139 bool IsStorage( const OUString
& rEleName
) const;
140 bool IsContained( const OUString
& rEleName
) const;
142 bool Remove( const OUString
& rEleName
);
143 bool CopyTo( const OUString
& rEleName
, SotStorage
* pDest
,
144 const OUString
& rNewName
);
146 bool IsOLEStorage() const;
147 static bool IsOLEStorage( const OUString
& rFileName
);
148 static bool IsOLEStorage( SvStream
* pStream
);
150 static SotStorage
* OpenOLEStorage( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
151 const OUString
& rEleName
, StreamMode
= StreamMode::STD_READWRITE
);
152 static SotClipboardFormatId
GetFormatID( const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
153 static sal_Int32
GetVersion( const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
156 #endif // _SVSTOR_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */