Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sot / source / sdstor / storinfo.cxx
blob4e42ea315c29ee3ff13bdcc4465685e2293aa138
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <memory>
27 /************** class SvStorageInfo **************************************
28 *************************************************************************/
29 SotClipboardFormatId ReadClipboardFormat( SvStream & rStm )
31 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
32 sal_Int32 nLen = 0;
33 rStm.ReadInt32( nLen );
34 if( rStm.eof() )
35 rStm.SetError( SVSTREAM_GENERALERROR );
36 if( nLen > 0 )
38 // get a string name
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));
44 else
45 rStm.SetError( SVSTREAM_GENERALERROR );
47 else if( nLen == -1 )
49 // Windows clipboard format
50 // SV and Win match (up to and including SotClipboardFormatId::GDIMETAFILE)
51 sal_uInt32 nTmp;
52 rStm.ReadUInt32( nTmp );
53 nFormat = static_cast<SotClipboardFormatId>(nTmp);
55 else if( nLen == -2 )
57 sal_uInt32 nTmp;
58 rStm.ReadUInt32( nTmp );
59 nFormat = static_cast<SotClipboardFormatId>(nTmp);
60 // Mac clipboard format
61 // ??? not implemented
62 rStm.SetError( SVSTREAM_GENERALERROR );
64 else if( nLen != 0 )
66 // unknown identifier
67 rStm.SetError( SVSTREAM_GENERALERROR );
69 return nFormat;
72 void WriteClipboardFormat( SvStream & rStm, SotClipboardFormatId nFormat )
74 // determine the clipboard format string
75 OUString aCbFmt;
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 );
84 rStm.WriteUChar( 0 );
86 else if( nFormat != SotClipboardFormatId::NONE )
88 rStm.WriteInt32( -1 ) // for Windows
89 .WriteInt32( static_cast<sal_Int32>(nFormat) );
91 else
93 rStm.WriteInt32( 0 ); // no clipboard format
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */