bump product version to 4.2.0.1
[LibreOffice.git] / svl / source / svdde / ddedata.cxx
blob4c9e465f572f87c443446bebb38307511a463867
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 // ACHTUNG: es wird angenommen, dass StarView-Clipboard-Foamatnummern
22 // und Windows-Formatnummern identisch sind! Ist dies einmal nicht der
23 // Fall, muessen die Routinen hier angepasst werden. Die Implementation
24 // verwendet die hier defineirten Konversionen.
26 #define UNICODE
28 #include <string.h>
29 #include "ddeimp.hxx"
30 #include <svl/svdde.hxx>
32 #include <osl/thread.h>
34 // --- DdeData::DdeData() ------------------------------------------
36 DdeData::DdeData()
38 pImp = new DdeDataImp;
39 pImp->hData = NULL;
40 pImp->nData = 0;
41 pImp->pData = NULL;
42 pImp->nFmt = CF_TEXT;
45 // --- DdeData::DdeData() ------------------------------------------
47 DdeData::DdeData( const void* p, long n, sal_uLong f )
49 pImp = new DdeDataImp;
50 pImp->hData = NULL;
51 pImp->pData = (LPBYTE)p;
52 pImp->nData = n;
53 pImp->nFmt = f;
56 // --- DdeData::DdeData() ------------------------------------------
58 DdeData::DdeData( const OUString& s )
60 pImp = new DdeDataImp;
61 pImp->hData = NULL;
62 pImp->pData = (LPBYTE)s.getStr();
63 pImp->nData = s.getLength()+1;
64 pImp->nFmt = CF_TEXT;
67 // --- DdeData::DdeData() ------------------------------------------
69 DdeData::DdeData( const DdeData& rData )
71 pImp = new DdeDataImp;
72 pImp->hData = rData.pImp->hData;
73 pImp->nData = rData.pImp->nData;
74 pImp->pData = rData.pImp->pData;
75 pImp->nFmt = rData.pImp->nFmt;
76 Lock();
79 // --- DdeData::~DdeData() -----------------------------------------
81 DdeData::~DdeData()
83 if ( pImp && pImp->hData )
84 DdeUnaccessData( pImp->hData );
85 delete pImp;
88 // --- DdeData::Lock() ---------------------------------------------
90 void DdeData::Lock()
92 if ( pImp->hData )
93 pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData );
96 // --- DdeData::GetFormat() ----------------------------------------
98 sal_uLong DdeData::GetFormat() const
100 return pImp->nFmt;
103 void DdeData::SetFormat( sal_uLong nFmt )
105 pImp->nFmt = nFmt;
108 // --- DdeData::operator const char*() -----------------------------
110 DdeData::operator const void*() const
112 return pImp->pData;
115 // --- DdeData::operator long() ------------------------------------
117 DdeData::operator long() const
119 return pImp->nData;
122 // --- DdeData::operator =() ---------------------------------------
124 DdeData& DdeData::operator = ( const DdeData& rData )
126 if ( &rData != this )
128 DdeData tmp( rData );
129 delete pImp;
130 pImp = tmp.pImp;
131 tmp.pImp = NULL;
134 return *this;
137 sal_uLong DdeData::GetExternalFormat( sal_uLong nFmt )
139 switch( nFmt )
141 case FORMAT_STRING:
142 nFmt = CF_TEXT;
143 break;
144 case FORMAT_BITMAP:
145 nFmt = CF_BITMAP;
146 break;
147 case FORMAT_GDIMETAFILE:
148 nFmt = CF_METAFILEPICT;
149 break;
151 default:
153 #if defined(WNT)
154 OUString aName( SotExchange::GetFormatName( nFmt ) );
155 if( !aName.isEmpty() )
156 nFmt = RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.getStr()) );
157 #endif
160 return nFmt;
163 sal_uLong DdeData::GetInternalFormat( sal_uLong nFmt )
165 switch( nFmt )
167 case CF_TEXT:
168 nFmt = FORMAT_STRING;
169 break;
171 case CF_BITMAP:
172 nFmt = FORMAT_BITMAP;
173 break;
175 case CF_METAFILEPICT:
176 nFmt = FORMAT_GDIMETAFILE;
177 break;
179 default:
180 #if defined(WNT)
181 if( nFmt >= CF_MAX )
183 TCHAR szName[ 256 ];
185 if( GetClipboardFormatName( nFmt, szName, sizeof(szName) ) )
186 nFmt = SotExchange::RegisterFormatName( OUString(reinterpret_cast<const sal_Unicode*>(szName)) );
188 #endif
189 break;
191 return nFmt;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */