merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / svdde / ddedata.cxx
blob675635d1b9d27518e23e3d080f40e68ba72ca5a6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ddedata.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 // ACHTUNG: es wird angenommen, dass StarView-Clipboard-Foamatnummern
35 // und Windows-Formatnummern identisch sind! Ist dies einmal nicht der
36 // Fall, muessen die Routinen hier angepasst werden. Die Implementation
37 // verwendet die hier defineirten Konversionen.
39 #define UNICODE
41 #include <string.h>
42 #include "ddeimp.hxx"
43 #include <svtools/svdde.hxx>
45 #include <osl/thread.h>
47 #if defined( WIN ) && defined( MSC )
48 #pragma code_seg( "SVDDE_MISC_CODE" )
49 #endif
51 // --- DdeData::DdeData() ------------------------------------------
53 DdeData::DdeData()
55 pImp = new DdeDataImp;
56 pImp->hData = NULL;
57 pImp->nData = 0;
58 pImp->pData = NULL;
59 pImp->nFmt = CF_TEXT;
62 // --- DdeData::DdeData() ------------------------------------------
64 DdeData::DdeData( const void* p, long n, ULONG f )
66 pImp = new DdeDataImp;
67 pImp->hData = NULL;
68 pImp->pData = (LPBYTE)p;
69 pImp->nData = n;
70 pImp->nFmt = f;
73 // --- DdeData::DdeData() ------------------------------------------
75 DdeData::DdeData( const String& s )
77 pImp = new DdeDataImp;
78 pImp->hData = NULL;
79 pImp->pData = (LPBYTE)s.GetBuffer();
80 pImp->nData = s.Len()+1;
81 pImp->nFmt = CF_TEXT;
84 // --- DdeData::DdeData() ------------------------------------------
86 DdeData::DdeData( const DdeData& rData )
88 pImp = new DdeDataImp;
89 pImp->hData = rData.pImp->hData;
90 pImp->nData = rData.pImp->nData;
91 pImp->pData = rData.pImp->pData;
92 pImp->nFmt = rData.pImp->nFmt;
93 Lock();
96 // --- DdeData::~DdeData() -----------------------------------------
98 DdeData::~DdeData()
100 if ( pImp && pImp->hData )
101 DdeUnaccessData( pImp->hData );
102 delete pImp;
105 // --- DdeData::Lock() ---------------------------------------------
107 void DdeData::Lock()
109 if ( pImp->hData )
110 pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData );
113 // --- DdeData::GetFormat() ----------------------------------------
115 ULONG DdeData::GetFormat() const
117 return pImp->nFmt;
120 void DdeData::SetFormat( ULONG nFmt )
122 pImp->nFmt = nFmt;
125 // --- DdeData::operator const char*() -----------------------------
127 DdeData::operator const void*() const
129 return pImp->pData;
132 // --- DdeData::operator long() ------------------------------------
134 DdeData::operator long() const
136 return pImp->nData;
139 // --- DdeData::operator =() ---------------------------------------
141 DdeData& DdeData::operator = ( const DdeData& rData )
143 if ( &rData != this )
145 DdeData tmp( rData );
146 delete pImp;
147 pImp = tmp.pImp;
148 tmp.pImp = NULL;
151 return *this;
154 ULONG DdeData::GetExternalFormat( ULONG nFmt )
156 switch( nFmt )
158 case FORMAT_STRING:
159 nFmt = CF_TEXT;
160 break;
161 case FORMAT_BITMAP:
162 nFmt = CF_BITMAP;
163 break;
164 case FORMAT_GDIMETAFILE:
165 nFmt = CF_METAFILEPICT;
166 break;
168 default:
170 #if defined(WNT) || defined(WIN) || defined( PM2 )
171 String aName( SotExchange::GetFormatName( nFmt ) );
173 #if defined(WNT) || defined(WIN)
175 if( aName.Len() )
176 nFmt = RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.GetBuffer()) );
177 #endif
178 #if defined( PM2 )
180 if( aName.Len() )
182 HATOMTBL hSysTable = WinQuerySystemAtomTable();
183 nFmt = (ULONG)WinAddAtom( hSysTable, (PSZ)aName.GetBuffer() );
185 #endif
186 #endif
189 return nFmt;
192 ULONG DdeData::GetInternalFormat( ULONG nFmt )
194 switch( nFmt )
196 case CF_TEXT:
197 nFmt = FORMAT_STRING;
198 break;
200 case CF_BITMAP:
201 nFmt = FORMAT_BITMAP;
202 break;
204 case CF_METAFILEPICT:
205 nFmt = FORMAT_GDIMETAFILE;
206 break;
208 default:
209 #if defined(WIN) || defined(WNT)
210 if( nFmt >= CF_MAX )
212 TCHAR szName[ 256 ];
214 if( GetClipboardFormatName( nFmt, szName, sizeof(szName) ) )
215 nFmt = SotExchange::RegisterFormatName( String(reinterpret_cast<const sal_Unicode*>(szName)) );
217 #endif
218 #if defined(PM2)
219 if( nFmt > CF_PALETTE )
221 char szName[ 256 ];
223 HATOMTBL hSysTable = WinQuerySystemAtomTable();
224 WinQueryAtomName( hSysTable, (ATOM)nFmt, (PSZ)szName,
225 sizeof( szName ) );
226 nFmt = SotExchange::RegisterFormatName( String( szName ) );
228 #endif
229 break;
231 return nFmt;