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 .
21 #include <sot/storinfo.hxx>
22 #include <sot/exchange.hxx>
23 #include <tools/stream.hxx>
24 #include <comphelper/errcode.hxx>
27 /************** class SvStorageInfo **************************************
28 *************************************************************************/
29 SotClipboardFormatId
ReadClipboardFormat( SvStream
& rStm
)
31 SotClipboardFormatId nFormat
= SotClipboardFormatId::NONE
;
33 rStm
.ReadInt32( nLen
);
35 rStm
.SetError( SVSTREAM_GENERALERROR
);
39 std::unique_ptr
<char[]> p(new( ::std::nothrow
) char[ nLen
]);
40 if (p
&& rStm
.ReadBytes(p
.get(), nLen
) == static_cast<std::size_t>(nLen
))
42 nFormat
= SotExchange::RegisterFormatName(OUString(p
.get(), nLen
-1, RTL_TEXTENCODING_ASCII_US
));
45 rStm
.SetError( SVSTREAM_GENERALERROR
);
49 // Windows clipboard format
50 // SV and Win match (up to and including SotClipboardFormatId::GDIMETAFILE)
52 rStm
.ReadUInt32( nTmp
);
53 nFormat
= static_cast<SotClipboardFormatId
>(nTmp
);
58 rStm
.ReadUInt32( nTmp
);
59 nFormat
= static_cast<SotClipboardFormatId
>(nTmp
);
60 // Mac clipboard format
61 // ??? not implemented
62 rStm
.SetError( SVSTREAM_GENERALERROR
);
67 rStm
.SetError( SVSTREAM_GENERALERROR
);
72 void WriteClipboardFormat( SvStream
& rStm
, SotClipboardFormatId nFormat
)
74 // determine the clipboard format string
76 if( nFormat
> SotClipboardFormatId::GDIMETAFILE
)
77 aCbFmt
= SotExchange::GetFormatName( nFormat
);
78 if( !aCbFmt
.isEmpty() )
80 OString
aAsciiCbFmt(OUStringToOString(aCbFmt
,
81 RTL_TEXTENCODING_ASCII_US
));
82 rStm
.WriteInt32( aAsciiCbFmt
.getLength() + 1 );
83 rStm
.WriteOString( aAsciiCbFmt
);
86 else if( nFormat
!= SotClipboardFormatId::NONE
)
88 rStm
.WriteInt32( -1 ) // for Windows
89 .WriteInt32( static_cast<sal_Int32
>(nFormat
) );
93 rStm
.WriteInt32( 0 ); // no clipboard format
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */