fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / ChartTransferable.cxx
blobc6f47028d0f069445913b404cc9a8fb502581d24
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 .
20 #include "ChartTransferable.hxx"
22 #include <sot/exchange.hxx>
23 #include <sot/storage.hxx>
24 #include <unotools/streamwrap.hxx>
25 #include <vcl/graph.hxx>
26 #include <svl/itempool.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/fhgtitem.hxx>
29 #include <svx/svditer.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <svx/svdpage.hxx>
32 #include <svx/unomodel.hxx>
33 #include <svx/svdview.hxx>
35 #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL SotClipboardFormatId::STRING
37 using namespace ::com::sun::star;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
42 namespace chart
45 ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
46 :m_pMarkedObjModel( NULL )
47 ,m_bDrawing( bDrawing )
49 SdrExchangeView * pExchgView( new SdrView( pDrawModel ));
50 SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
51 if( pSelectedObj )
52 pExchgView->MarkObj( pSelectedObj, pPv );
53 else
54 pExchgView->MarkAllObj( pPv );
55 Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
56 m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
57 if ( m_bDrawing )
59 m_pMarkedObjModel = pExchgView->GetMarkedObjModel();
61 delete pExchgView;
64 ChartTransferable::~ChartTransferable()
67 void ChartTransferable::AddSupportedFormats()
69 if ( m_bDrawing )
71 AddFormat( SotClipboardFormatId::DRAWING );
73 AddFormat( SotClipboardFormatId::GDIMETAFILE );
74 AddFormat( SotClipboardFormatId::PNG );
75 AddFormat( SotClipboardFormatId::BITMAP );
78 bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
80 SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
81 bool bResult = false;
83 if( HasFormat( nFormat ))
85 if ( nFormat == SotClipboardFormatId::DRAWING )
87 bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
89 else if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
91 Graphic aGraphic( m_xMetaFileGraphic );
92 bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
94 else if( nFormat == SotClipboardFormatId::BITMAP )
96 Graphic aGraphic( m_xMetaFileGraphic );
97 bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
101 return bResult;
104 bool ChartTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, SotClipboardFormatId nUserObjectId,
105 const datatransfer::DataFlavor& /* rFlavor */ )
107 // called from SetObject, put data into stream
109 bool bRet = false;
110 switch ( nUserObjectId )
112 case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
114 SdrModel* pMarkedObjModel = static_cast< SdrModel* >( pUserObject );
115 if ( pMarkedObjModel )
117 rxOStm->SetBufferSize( 0xff00 );
119 // for the changed pool defaults from drawing layer pool set those
120 // attributes as hard attributes to preserve them for saving
121 const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
122 const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
123 rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
124 sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
125 for ( sal_uInt16 i = 0; i < nCount; ++i )
127 const SdrPage* pPage = pMarkedObjModel->GetPage( i );
128 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
129 while ( aIter.IsMore() )
131 SdrObject* pObj = aIter.Next();
132 const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
133 pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
134 if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
136 pObj->SetMergedItem( rDefaultFontHeight );
141 Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
142 if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
144 rxOStm->Commit();
147 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
150 break;
151 default:
153 OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" );
155 break;
157 return bRet;
160 } // namespace chart
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */