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 #include "precompiled_reportdesign.hxx"
28 #include "dlgedclip.hxx"
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
31 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
32 
33 namespace rptui
34 {
35 
36 using namespace comphelper;
37 using namespace ::com::sun::star;
38 
39 //============================================================================
40 // OReportExchange
41 //============================================================================
42 //----------------------------------------------------------------------------
43 OReportExchange::OReportExchange(const TSectionElements& _rCopyElements )
44 : m_aCopyElements(_rCopyElements)
45 {
46 }
47 //--------------------------------------------------------------------
48 sal_uInt32 OReportExchange::getDescriptorFormatId()
49 {
50 	static sal_uInt32 s_nFormat = (sal_uInt32)-1;
51 	if ((sal_uInt32)-1 == s_nFormat)
52 	{
53 		s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"report.ReportObjectsTransfer\""));
54 		OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OReportExchange::getDescriptorFormatId: bad exchange id!");
55 	}
56 	return s_nFormat;
57 }
58 //--------------------------------------------------------------------
59 void OReportExchange::AddSupportedFormats()
60 {
61 	AddFormat(getDescriptorFormatId());
62 }
63 //--------------------------------------------------------------------
64 sal_Bool OReportExchange::GetData( const datatransfer::DataFlavor& _rFlavor )
65 {
66 	const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
67 	return (nFormatId == getDescriptorFormatId()) ?
68         SetAny( uno::Any(m_aCopyElements), _rFlavor )
69         : sal_False;
70 }
71 // -----------------------------------------------------------------------------
72 sal_Bool OReportExchange::canExtract(const DataFlavorExVector& _rFlavor)
73 {
74     return IsFormatSupported(_rFlavor,getDescriptorFormatId());
75 }
76 // -----------------------------------------------------------------------------
77 OReportExchange::TSectionElements OReportExchange::extractCopies(const TransferableDataHelper& _rData)
78 {
79 	sal_Int32 nKnownFormatId = getDescriptorFormatId();
80 	if ( _rData.HasFormat( nKnownFormatId ) )
81 	{
82 		// extract the any from the transferable
83         datatransfer::DataFlavor aFlavor;
84 #if OSL_DEBUG_LEVEL > 0
85 		sal_Bool bSuccess =
86 #endif
87 		SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
88 		OSL_ENSURE(bSuccess, "OReportExchange::extractCopies: invalid data format (no flavor)!");
89 
90         uno::Any aDescriptor = _rData.GetAny(aFlavor);
91 
92         TSectionElements aCopies;
93 #if OSL_DEBUG_LEVEL > 0
94 		bSuccess =
95 #endif
96 		aDescriptor >>= aCopies;
97 		OSL_ENSURE(bSuccess, "OReportExchange::extractCopies: invalid clipboard format!");
98 
99 		// build the real descriptor
100 		return aCopies;
101 	}
102 
103 	return TSectionElements();
104 }
105 //============================================================================
106 } // rptui
107 //============================================================================
108