attempt to fix macos jenkins hangs - part 3
[LibreOffice.git] / svl / source / svdde / ddedata.cxx
blobd8e1e157922611c1169f863345a89b0b18c8d563
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 // ATTENTION: We assume StarView Clipboard format numbers and Windows
22 // Format numbers to be the same! If that's not the case, we need to
23 // adapt the code here. The implementation uses the conversions here.
25 #include <string.h>
26 #include "ddeimp.hxx"
27 #include <svl/svdde.hxx>
28 #include <o3tl/char16_t2wchar_t.hxx>
30 #include <osl/thread.h>
31 #include <sot/exchange.hxx>
33 DdeData::DdeData()
35 xImp.reset(new DdeDataImp);
36 xImp->hData = nullptr;
37 xImp->nData = 0;
38 xImp->pData = nullptr;
39 xImp->nFmt = SotClipboardFormatId::STRING;
42 DdeData::DdeData(const void* p, tools::Long n, SotClipboardFormatId f)
44 xImp.reset(new DdeDataImp);
45 xImp->hData = nullptr;
46 xImp->pData = p;
47 xImp->nData = n;
48 xImp->nFmt = f;
51 DdeData::DdeData( const OUString& s )
53 xImp.reset(new DdeDataImp);
54 xImp->hData = nullptr;
55 xImp->pData = s.getStr();
56 xImp->nData = s.getLength()+1;
57 xImp->nFmt = SotClipboardFormatId::STRING;
60 DdeData::DdeData(const DdeData& rData)
62 xImp.reset(new DdeDataImp);
63 xImp->hData = rData.xImp->hData;
64 xImp->nData = rData.xImp->nData;
65 xImp->pData = rData.xImp->pData;
66 xImp->nFmt = rData.xImp->nFmt;
67 Lock();
70 DdeData::DdeData(DdeData&& rData) noexcept
71 : xImp(std::move(rData.xImp))
75 DdeData::~DdeData()
77 if (xImp && xImp->hData)
78 DdeUnaccessData(xImp->hData);
81 void DdeData::Lock()
83 if (xImp->hData)
84 xImp->pData = DdeAccessData(xImp->hData, &xImp->nData);
87 SotClipboardFormatId DdeData::GetFormat() const
89 return xImp->nFmt;
92 void DdeData::SetFormat(SotClipboardFormatId nFmt)
94 xImp->nFmt = nFmt;
97 void const * DdeData::getData() const
99 return xImp->pData;
102 tools::Long DdeData::getSize() const
104 return xImp->nData;
107 DdeData& DdeData::operator=(const DdeData& rData)
109 if ( &rData != this )
111 DdeData tmp(rData);
112 xImp = std::move(tmp.xImp);
115 return *this;
118 DdeData& DdeData::operator=(DdeData&& rData) noexcept
120 xImp = std::move(rData.xImp);
121 return *this;
124 sal_uInt32 DdeData::GetExternalFormat(SotClipboardFormatId nFmt)
126 switch( nFmt )
128 case SotClipboardFormatId::STRING:
129 return CF_TEXT;
130 case SotClipboardFormatId::BITMAP:
131 return CF_BITMAP;
132 case SotClipboardFormatId::GDIMETAFILE:
133 return CF_METAFILEPICT;
134 default:
136 OUString aName( SotExchange::GetFormatName( nFmt ) );
137 if( !aName.isEmpty() )
138 return RegisterClipboardFormatW( o3tl::toW(aName.getStr()) );
141 return static_cast<sal_uInt32>(nFmt);
144 SotClipboardFormatId DdeData::GetInternalFormat(sal_uLong nFmt)
146 switch( nFmt )
148 case CF_TEXT:
149 return SotClipboardFormatId::STRING;
150 case CF_BITMAP:
151 return SotClipboardFormatId::BITMAP;
152 case CF_METAFILEPICT:
153 return SotClipboardFormatId::GDIMETAFILE;
154 default:
155 if( nFmt >= CF_MAX )
157 WCHAR szName[ 256 ];
159 if(GetClipboardFormatNameW( nFmt, szName, SAL_N_ELEMENTS(szName) ))
160 return SotExchange::RegisterFormatName( OUString(o3tl::toU(szName)) );
162 break;
164 return static_cast<SotClipboardFormatId>(nFmt);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */