1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svl.hxx" 30 31 // ACHTUNG: es wird angenommen, dass StarView-Clipboard-Foamatnummern 32 // und Windows-Formatnummern identisch sind! Ist dies einmal nicht der 33 // Fall, muessen die Routinen hier angepasst werden. Die Implementation 34 // verwendet die hier defineirten Konversionen. 35 36 #define UNICODE 37 38 #include <string.h> 39 #include "ddeimp.hxx" 40 #include <svl/svdde.hxx> 41 42 #include <osl/thread.h> 43 44 // --- DdeData::DdeData() ------------------------------------------ 45 46 DdeData::DdeData() 47 { 48 pImp = new DdeDataImp; 49 pImp->hData = NULL; 50 pImp->nData = 0; 51 pImp->pData = NULL; 52 pImp->nFmt = CF_TEXT; 53 } 54 55 // --- DdeData::DdeData() ------------------------------------------ 56 57 DdeData::DdeData( const void* p, long n, sal_uLong f ) 58 { 59 pImp = new DdeDataImp; 60 pImp->hData = NULL; 61 pImp->pData = (LPBYTE)p; 62 pImp->nData = n; 63 pImp->nFmt = f; 64 } 65 66 // --- DdeData::DdeData() ------------------------------------------ 67 68 DdeData::DdeData( const String& s ) 69 { 70 pImp = new DdeDataImp; 71 pImp->hData = NULL; 72 pImp->pData = (LPBYTE)s.GetBuffer(); 73 pImp->nData = s.Len()+1; 74 pImp->nFmt = CF_TEXT; 75 } 76 77 // --- DdeData::DdeData() ------------------------------------------ 78 79 DdeData::DdeData( const DdeData& rData ) 80 { 81 pImp = new DdeDataImp; 82 pImp->hData = rData.pImp->hData; 83 pImp->nData = rData.pImp->nData; 84 pImp->pData = rData.pImp->pData; 85 pImp->nFmt = rData.pImp->nFmt; 86 Lock(); 87 } 88 89 // --- DdeData::~DdeData() ----------------------------------------- 90 91 DdeData::~DdeData() 92 { 93 if ( pImp && pImp->hData ) 94 DdeUnaccessData( pImp->hData ); 95 delete pImp; 96 } 97 98 // --- DdeData::Lock() --------------------------------------------- 99 100 void DdeData::Lock() 101 { 102 if ( pImp->hData ) 103 pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData ); 104 } 105 106 // --- DdeData::GetFormat() ---------------------------------------- 107 108 sal_uLong DdeData::GetFormat() const 109 { 110 return pImp->nFmt; 111 } 112 113 void DdeData::SetFormat( sal_uLong nFmt ) 114 { 115 pImp->nFmt = nFmt; 116 } 117 118 // --- DdeData::operator const char*() ----------------------------- 119 120 DdeData::operator const void*() const 121 { 122 return pImp->pData; 123 } 124 125 // --- DdeData::operator long() ------------------------------------ 126 127 DdeData::operator long() const 128 { 129 return pImp->nData; 130 } 131 132 // --- DdeData::operator =() --------------------------------------- 133 134 DdeData& DdeData::operator = ( const DdeData& rData ) 135 { 136 if ( &rData != this ) 137 { 138 DdeData tmp( rData ); 139 delete pImp; 140 pImp = tmp.pImp; 141 tmp.pImp = NULL; 142 } 143 144 return *this; 145 } 146 147 sal_uLong DdeData::GetExternalFormat( sal_uLong nFmt ) 148 { 149 switch( nFmt ) 150 { 151 case FORMAT_STRING: 152 nFmt = CF_TEXT; 153 break; 154 case FORMAT_BITMAP: 155 nFmt = CF_BITMAP; 156 break; 157 case FORMAT_GDIMETAFILE: 158 nFmt = CF_METAFILEPICT; 159 break; 160 161 default: 162 { 163 #if defined(WNT) || defined( PM2 ) 164 String aName( SotExchange::GetFormatName( nFmt ) ); 165 166 #if defined(WNT) 167 168 if( aName.Len() ) 169 nFmt = RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.GetBuffer()) ); 170 #endif 171 #if defined( PM2 ) 172 173 if( aName.Len() ) 174 { 175 HATOMTBL hSysTable = WinQuerySystemAtomTable(); 176 nFmt = (sal_uLong)WinAddAtom( hSysTable, (PSZ)aName.GetBuffer() ); 177 } 178 #endif 179 #endif 180 } 181 } 182 return nFmt; 183 } 184 185 sal_uLong DdeData::GetInternalFormat( sal_uLong nFmt ) 186 { 187 switch( nFmt ) 188 { 189 case CF_TEXT: 190 nFmt = FORMAT_STRING; 191 break; 192 193 case CF_BITMAP: 194 nFmt = FORMAT_BITMAP; 195 break; 196 197 case CF_METAFILEPICT: 198 nFmt = FORMAT_GDIMETAFILE; 199 break; 200 201 default: 202 #if defined(WNT) 203 if( nFmt >= CF_MAX ) 204 { 205 TCHAR szName[ 256 ]; 206 207 if( GetClipboardFormatName( nFmt, szName, sizeof(szName) ) ) 208 nFmt = SotExchange::RegisterFormatName( String(reinterpret_cast<const sal_Unicode*>(szName)) ); 209 } 210 #endif 211 #if defined(PM2) 212 if( nFmt > CF_PALETTE ) 213 { 214 char szName[ 256 ]; 215 216 HATOMTBL hSysTable = WinQuerySystemAtomTable(); 217 WinQueryAtomName( hSysTable, (ATOM)nFmt, (PSZ)szName, 218 sizeof( szName ) ); 219 nFmt = SotExchange::RegisterFormatName( String( szName ) ); 220 } 221 #endif 222 break; 223 } 224 return nFmt; 225 } 226 227