LibreOffice Module sot (master) 1
storinfo.cxx
Go to the documentation of this file.
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
21#include <sot/storinfo.hxx>
22#include <sot/exchange.hxx>
23#include <tools/stream.hxx>
25#include <memory>
26
27/************** class SvStorageInfo **************************************
28*************************************************************************/
30{
32 sal_Int32 nLen = 0;
33 rStm.ReadInt32( nLen );
34 if( rStm.eof() )
36 if( nLen > 0 )
37 {
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))
41 {
42 nFormat = SotExchange::RegisterFormatName(OUString(p.get(), nLen-1, RTL_TEXTENCODING_ASCII_US));
43 }
44 else
46 }
47 else if( nLen == -1 )
48 {
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);
54 }
55 else if( nLen == -2 )
56 {
57 sal_uInt32 nTmp;
58 rStm.ReadUInt32( nTmp );
59 nFormat = static_cast<SotClipboardFormatId>(nTmp);
60 // Mac clipboard format
61 // ??? not implemented
63 }
64 else if( nLen != 0 )
65 {
66 // unknown identifier
68 }
69 return nFormat;
70}
71
73{
74 // determine the clipboard format string
75 OUString aCbFmt;
77 aCbFmt = SotExchange::GetFormatName( nFormat );
78 if( !aCbFmt.isEmpty() )
79 {
80 OString aAsciiCbFmt(OUStringToOString(aCbFmt,
81 RTL_TEXTENCODING_ASCII_US));
82 rStm.WriteInt32( aAsciiCbFmt.getLength() + 1 );
83 rStm.WriteOString( aAsciiCbFmt );
84 rStm.WriteUChar( 0 );
85 }
86 else if( nFormat != SotClipboardFormatId::NONE )
87 {
88 rStm.WriteInt32( -1 ) // for Windows
89 .WriteInt32( static_cast<sal_Int32>(nFormat) );
90 }
91 else
92 {
93 rStm.WriteInt32( 0 ); // no clipboard format
94 }
95}
96
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString GetFormatName(SotClipboardFormatId nFormat)
Definition: exchange.cxx:461
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
Definition: exchange.cxx:223
SvStream & WriteInt32(sal_Int32 nInt32)
bool eof() const
SvStream & WriteUChar(unsigned char nChar)
SvStream & WriteOString(std::string_view rStr)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
void SetError(ErrCode nErrorCode)
SvStream & ReadInt32(sal_Int32 &rInt32)
std::size_t ReadBytes(void *pData, std::size_t nSize)
#define SVSTREAM_GENERALERROR
SotClipboardFormatId
Definition: formats.hxx:28
void * p
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SotClipboardFormatId ReadClipboardFormat(SvStream &rStm)
Definition: storinfo.cxx:29
void WriteClipboardFormat(SvStream &rStm, SotClipboardFormatId nFormat)
Definition: storinfo.cxx:72