Branch libreoffice-5-0-4
[LibreOffice.git] / svl / source / svdde / ddedata.cxx
blob9b338b82d82dc36c9e7e57d16e3dcf10ab7183ed
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 #define UNICODE
27 #include <string.h>
28 #include "ddeimp.hxx"
29 #include <svl/svdde.hxx>
31 #include <osl/thread.h>
33 DdeData::DdeData()
35 pImp = new DdeDataImp;
36 pImp->hData = NULL;
37 pImp->nData = 0;
38 pImp->pData = NULL;
39 pImp->nFmt = SotClipboardFormatId::STRING;
42 DdeData::DdeData(const void* p, long n, SotClipboardFormatId f)
44 pImp = new DdeDataImp;
45 pImp->hData = NULL;
46 pImp->pData = (LPBYTE)p;
47 pImp->nData = n;
48 pImp->nFmt = f;
51 DdeData::DdeData( const OUString& s )
53 pImp = new DdeDataImp;
54 pImp->hData = NULL;
55 pImp->pData = (LPBYTE)s.getStr();
56 pImp->nData = s.getLength()+1;
57 pImp->nFmt = SotClipboardFormatId::STRING;
60 DdeData::DdeData( const DdeData& rData )
62 pImp = new DdeDataImp;
63 pImp->hData = rData.pImp->hData;
64 pImp->nData = rData.pImp->nData;
65 pImp->pData = rData.pImp->pData;
66 pImp->nFmt = rData.pImp->nFmt;
67 Lock();
70 DdeData::~DdeData()
72 if ( pImp && pImp->hData )
73 DdeUnaccessData( pImp->hData );
74 delete pImp;
77 void DdeData::Lock()
79 if ( pImp->hData )
80 pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData );
83 SotClipboardFormatId DdeData::GetFormat() const
85 return pImp->nFmt;
88 void DdeData::SetFormat(SotClipboardFormatId nFmt)
90 pImp->nFmt = nFmt;
93 DdeData::operator const void*() const
95 return pImp->pData;
98 DdeData::operator long() const
100 return pImp->nData;
103 DdeData& DdeData::operator = ( const DdeData& rData )
105 if ( &rData != this )
107 DdeData tmp( rData );
108 delete pImp;
109 pImp = tmp.pImp;
110 tmp.pImp = NULL;
113 return *this;
116 sal_uLong DdeData::GetExternalFormat(SotClipboardFormatId nFmt)
118 switch( nFmt )
120 case SotClipboardFormatId::STRING:
121 return CF_TEXT;
122 case SotClipboardFormatId::BITMAP:
123 return CF_BITMAP;
124 case SotClipboardFormatId::GDIMETAFILE:
125 return CF_METAFILEPICT;
126 default:
128 #if defined(WNT)
129 OUString aName( SotExchange::GetFormatName( nFmt ) );
130 if( !aName.isEmpty() )
131 return RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.getStr()) );
132 #endif
135 return static_cast<sal_uLong>(nFmt);
138 SotClipboardFormatId DdeData::GetInternalFormat(sal_uLong nFmt)
140 switch( nFmt )
142 case CF_TEXT:
143 return SotClipboardFormatId::STRING;
144 case CF_BITMAP:
145 return SotClipboardFormatId::BITMAP;
146 case CF_METAFILEPICT:
147 return SotClipboardFormatId::GDIMETAFILE;
148 default:
149 #if defined(WNT)
150 if( nFmt >= CF_MAX )
152 TCHAR szName[ 256 ];
154 if(GetClipboardFormatName( nFmt, szName, sizeof(szName) ))
155 return SotExchange::RegisterFormatName( OUString(reinterpret_cast<const sal_Unicode*>(szName)) );
157 #endif
158 break;
160 return static_cast<SotClipboardFormatId>(nFmt);
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */