1cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5cde9e8dcSAndrew Rist * distributed with this work for additional information 6cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20cde9e8dcSAndrew Rist *************************************************************/ 21cde9e8dcSAndrew Rist 22cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "ChartTransferable.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 30cdf0e10cSrcweir #include <vcl/graph.hxx> 31cdf0e10cSrcweir #include <svl/itempool.hxx> 32cdf0e10cSrcweir #include <editeng/eeitem.hxx> 33cdf0e10cSrcweir #include <editeng/fhgtitem.hxx> 34cdf0e10cSrcweir #include <svx/svditer.hxx> 35cdf0e10cSrcweir #include <svx/svdmodel.hxx> 36cdf0e10cSrcweir #include <svx/svdpage.hxx> 37cdf0e10cSrcweir #include <svx/unomodel.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir // header for class SdrView 40cdf0e10cSrcweir #include <svx/svdview.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL 1 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::com::sun::star; 45cdf0e10cSrcweir 46cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 47cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 48cdf0e10cSrcweir using ::rtl::OUString; 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace chart 51cdf0e10cSrcweir { 52cdf0e10cSrcweir 53cdf0e10cSrcweir ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing ) 54cdf0e10cSrcweir :m_pMarkedObjModel( NULL ) 55cdf0e10cSrcweir ,m_bDrawing( bDrawing ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir SdrExchangeView * pExchgView( new SdrView( pDrawModel )); 58cdf0e10cSrcweir SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 )); 59cdf0e10cSrcweir if( pSelectedObj ) 60cdf0e10cSrcweir pExchgView->MarkObj( pSelectedObj, pPv ); 61cdf0e10cSrcweir else 62cdf0e10cSrcweir pExchgView->MarkAllObj( pPv ); 63bb18ee55SArmin Le Grand Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true)); 64cdf0e10cSrcweir m_xMetaFileGraphic.set( aGraphic.GetXGraphic()); 65cdf0e10cSrcweir if ( m_bDrawing ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir m_pMarkedObjModel = ( pExchgView ? pExchgView->GetAllMarkedModel() : NULL ); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir delete pExchgView; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir ChartTransferable::~ChartTransferable() 73cdf0e10cSrcweir {} 74cdf0e10cSrcweir 75cdf0e10cSrcweir void ChartTransferable::AddSupportedFormats() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if ( m_bDrawing ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_DRAWING ); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir AddFormat( SOT_FORMAT_GDIMETAFILE ); 82cdf0e10cSrcweir AddFormat( SOT_FORMAT_BITMAP ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir sal_Bool ChartTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor ); 88cdf0e10cSrcweir sal_Bool bResult = sal_False; 89cdf0e10cSrcweir 90cdf0e10cSrcweir if( HasFormat( nFormat )) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir if ( nFormat == SOT_FORMATSTR_ID_DRAWING ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir else if ( nFormat == FORMAT_GDIMETAFILE ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir Graphic aGraphic( m_xMetaFileGraphic ); 99cdf0e10cSrcweir bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir else if( nFormat == FORMAT_BITMAP ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir Graphic aGraphic( m_xMetaFileGraphic ); 104*45fd3b9aSArmin Le Grand bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir return bResult; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir sal_Bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, 112cdf0e10cSrcweir const datatransfer::DataFlavor& /* rFlavor */ ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir // called from SetObject, put data into stream 115cdf0e10cSrcweir 116cdf0e10cSrcweir sal_Bool bRet = sal_False; 117cdf0e10cSrcweir switch ( nUserObjectId ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL: 120cdf0e10cSrcweir { 121cdf0e10cSrcweir SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject ); 122cdf0e10cSrcweir if ( pMarkedObjModel ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir rxOStm->SetBufferSize( 0xff00 ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir // #108584# 127cdf0e10cSrcweir // for the changed pool defaults from drawing layer pool set those 128cdf0e10cSrcweir // attributes as hard attributes to preserve them for saving 129cdf0e10cSrcweir const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool(); 130cdf0e10cSrcweir const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >( 131cdf0e10cSrcweir rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) ); 132cdf0e10cSrcweir sal_uInt16 nCount = pMarkedObjModel->GetPageCount(); 133cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir const SdrPage* pPage = pMarkedObjModel->GetPage( i ); 136cdf0e10cSrcweir SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); 137cdf0e10cSrcweir while ( aIter.IsMore() ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir SdrObject* pObj = aIter.Next(); 140cdf0e10cSrcweir const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >( 141cdf0e10cSrcweir pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) ); 142cdf0e10cSrcweir if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir pObj->SetMergedItem( rDefaultFontHeight ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) ); 150cdf0e10cSrcweir if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir rxOStm->Commit(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir default: 160cdf0e10cSrcweir { 161cdf0e10cSrcweir DBG_ERROR( "ChartTransferable::WriteObject: unknown object id" ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir break; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir return bRet; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir } // namespace chart 169