1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svl.hxx" 26 27 // ACHTUNG: es wird angenommen, dass StarView-Clipboard-Foamatnummern 28 // und Windows-Formatnummern identisch sind! Ist dies einmal nicht der 29 // Fall, muessen die Routinen hier angepasst werden. Die Implementation 30 // verwendet die hier defineirten Konversionen. 31 32 #define UNICODE 33 34 #include <string.h> 35 #include "ddeimp.hxx" 36 #include <svl/svdde.hxx> 37 38 #include <osl/thread.h> 39 40 // --- DdeData::DdeData() ------------------------------------------ 41 42 DdeData::DdeData() 43 { 44 pImp = new DdeDataImp; 45 pImp->hData = NULL; 46 pImp->nData = 0; 47 pImp->pData = NULL; 48 pImp->nFmt = CF_TEXT; 49 } 50 51 // --- DdeData::DdeData() ------------------------------------------ 52 53 DdeData::DdeData( const void* p, long n, sal_uLong f ) 54 { 55 pImp = new DdeDataImp; 56 pImp->hData = NULL; 57 pImp->pData = (LPBYTE)p; 58 pImp->nData = n; 59 pImp->nFmt = f; 60 } 61 62 // --- DdeData::DdeData() ------------------------------------------ 63 64 DdeData::DdeData( const String& s ) 65 { 66 pImp = new DdeDataImp; 67 pImp->hData = NULL; 68 pImp->pData = (LPBYTE)s.GetBuffer(); 69 pImp->nData = s.Len()+1; 70 pImp->nFmt = CF_TEXT; 71 } 72 73 // --- DdeData::DdeData() ------------------------------------------ 74 75 DdeData::DdeData( const DdeData& rData ) 76 { 77 pImp = new DdeDataImp; 78 pImp->hData = rData.pImp->hData; 79 pImp->nData = rData.pImp->nData; 80 pImp->pData = rData.pImp->pData; 81 pImp->nFmt = rData.pImp->nFmt; 82 Lock(); 83 } 84 85 // --- DdeData::~DdeData() ----------------------------------------- 86 87 DdeData::~DdeData() 88 { 89 if ( pImp && pImp->hData ) 90 DdeUnaccessData( pImp->hData ); 91 delete pImp; 92 } 93 94 // --- DdeData::Lock() --------------------------------------------- 95 96 void DdeData::Lock() 97 { 98 if ( pImp->hData ) 99 pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData ); 100 } 101 102 // --- DdeData::GetFormat() ---------------------------------------- 103 104 sal_uLong DdeData::GetFormat() const 105 { 106 return pImp->nFmt; 107 } 108 109 void DdeData::SetFormat( sal_uLong nFmt ) 110 { 111 pImp->nFmt = nFmt; 112 } 113 114 // --- DdeData::operator const char*() ----------------------------- 115 116 DdeData::operator const void*() const 117 { 118 return pImp->pData; 119 } 120 121 // --- DdeData::operator long() ------------------------------------ 122 123 DdeData::operator long() const 124 { 125 return pImp->nData; 126 } 127 128 // --- DdeData::operator =() --------------------------------------- 129 130 DdeData& DdeData::operator = ( const DdeData& rData ) 131 { 132 if ( &rData != this ) 133 { 134 DdeData tmp( rData ); 135 delete pImp; 136 pImp = tmp.pImp; 137 tmp.pImp = NULL; 138 } 139 140 return *this; 141 } 142 143 sal_uLong DdeData::GetExternalFormat( sal_uLong nFmt ) 144 { 145 switch( nFmt ) 146 { 147 case FORMAT_STRING: 148 nFmt = CF_TEXT; 149 break; 150 case FORMAT_BITMAP: 151 nFmt = CF_BITMAP; 152 break; 153 case FORMAT_GDIMETAFILE: 154 nFmt = CF_METAFILEPICT; 155 break; 156 157 default: 158 { 159 #if defined(WNT) || defined( PM2 ) 160 String aName( SotExchange::GetFormatName( nFmt ) ); 161 162 #if defined(WNT) 163 164 if( aName.Len() ) 165 nFmt = RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.GetBuffer()) ); 166 #endif 167 #if defined( PM2 ) 168 169 if( aName.Len() ) 170 { 171 HATOMTBL hSysTable = WinQuerySystemAtomTable(); 172 nFmt = (sal_uLong)WinAddAtom( hSysTable, (PSZ)aName.GetBuffer() ); 173 } 174 #endif 175 #endif 176 } 177 } 178 return nFmt; 179 } 180 181 sal_uLong DdeData::GetInternalFormat( sal_uLong nFmt ) 182 { 183 switch( nFmt ) 184 { 185 case CF_TEXT: 186 nFmt = FORMAT_STRING; 187 break; 188 189 case CF_BITMAP: 190 nFmt = FORMAT_BITMAP; 191 break; 192 193 case CF_METAFILEPICT: 194 nFmt = FORMAT_GDIMETAFILE; 195 break; 196 197 default: 198 #if defined(WNT) 199 if( nFmt >= CF_MAX ) 200 { 201 TCHAR szName[ 256 ]; 202 203 if( GetClipboardFormatName( nFmt, szName, sizeof(szName) ) ) 204 nFmt = SotExchange::RegisterFormatName( String(reinterpret_cast<const sal_Unicode*>(szName)) ); 205 } 206 #endif 207 #if defined(PM2) 208 if( nFmt > CF_PALETTE ) 209 { 210 char szName[ 256 ]; 211 212 HATOMTBL hSysTable = WinQuerySystemAtomTable(); 213 WinQueryAtomName( hSysTable, (ATOM)nFmt, (PSZ)szName, 214 sizeof( szName ) ); 215 nFmt = SotExchange::RegisterFormatName( String( szName ) ); 216 } 217 #endif 218 break; 219 } 220 return nFmt; 221 } 222 223