LibreOffice Module svl (master) 1
ddedata.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// 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.
24
25#include <string.h>
26#include "ddeimp.hxx"
27#include <svl/svdde.hxx>
29
30#include <osl/thread.h>
31#include <sot/exchange.hxx>
32
34{
35 xImp.reset(new DdeDataImp);
36 xImp->hData = nullptr;
37 xImp->nData = 0;
38 xImp->pData = nullptr;
39 xImp->nFmt = SotClipboardFormatId::STRING;
40}
41
43{
44 xImp.reset(new DdeDataImp);
45 xImp->hData = nullptr;
46 xImp->pData = p;
47 xImp->nData = n;
48 xImp->nFmt = f;
49}
50
51DdeData::DdeData( const OUString& s )
52{
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;
58}
59
61{
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();
68}
69
70DdeData::DdeData(DdeData&& rData) noexcept
71 : xImp(std::move(rData.xImp))
72{
73}
74
76{
77 if (xImp && xImp->hData)
78 DdeUnaccessData(xImp->hData);
79}
80
82{
83 if (xImp->hData)
84 xImp->pData = DdeAccessData(xImp->hData, &xImp->nData);
85}
86
88{
89 return xImp->nFmt;
90}
91
93{
94 xImp->nFmt = nFmt;
95}
96
97void const * DdeData::getData() const
98{
99 return xImp->pData;
100}
101
103{
104 return xImp->nData;
105}
106
108{
109 if ( &rData != this )
110 {
111 DdeData tmp(rData);
112 xImp = std::move(tmp.xImp);
113 }
114
115 return *this;
116}
117
119{
120 xImp = std::move(rData.xImp);
121 return *this;
122}
123
125{
126 switch( nFmt )
127 {
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:
135 {
136 OUString aName( SotExchange::GetFormatName( nFmt ) );
137 if( !aName.isEmpty() )
138 return RegisterClipboardFormatW( o3tl::toW(aName.getStr()) );
139 }
140 }
141 return static_cast<sal_uInt32>(nFmt);
142}
143
145{
146 switch( nFmt )
147 {
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 )
156 {
157 WCHAR szName[ 256 ];
158
159 if(GetClipboardFormatNameW( nFmt, szName, SAL_N_ELEMENTS(szName) ))
160 return SotExchange::RegisterFormatName( OUString(o3tl::toU(szName)) );
161 }
162 break;
163 }
164 return static_cast<SotClipboardFormatId>(nFmt);
165}
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~DdeData()
Definition: ddedata.cxx:75
tools::Long getSize() const
Definition: ddedata.cxx:102
SVL_DLLPRIVATE void Lock()
Definition: ddedata.cxx:81
SotClipboardFormatId GetFormat() const
Definition: ddedata.cxx:87
DdeData()
Definition: ddedata.cxx:33
static SotClipboardFormatId GetInternalFormat(sal_uLong nFmt)
Definition: ddedata.cxx:144
void SetFormat(SotClipboardFormatId nFmt)
Definition: ddedata.cxx:92
DdeData & operator=(const DdeData &)
Definition: ddedata.cxx:107
static sal_uInt32 GetExternalFormat(SotClipboardFormatId nFmt)
Definition: ddedata.cxx:124
void const * getData() const
Definition: ddedata.cxx:97
std::unique_ptr< DdeDataImp > xImp
Definition: svdde.hxx:52
static OUString GetFormatName(SotClipboardFormatId nFormat)
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
SotClipboardFormatId
OUString aName
void * p
sal_Int64 n
#define SAL_N_ELEMENTS(arr)
long Long
sal_uIntPtr sal_uLong