LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartTransferable.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 61 1.6 %
Date: 2014-11-03 Functions: 2 8 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "ChartTransferable.hxx"
      21             : 
      22             : #include <unotools/streamwrap.hxx>
      23             : #include <vcl/graph.hxx>
      24             : #include <svl/itempool.hxx>
      25             : #include <editeng/eeitem.hxx>
      26             : #include <editeng/fhgtitem.hxx>
      27             : #include <svx/svditer.hxx>
      28             : #include <svx/svdmodel.hxx>
      29             : #include <svx/svdpage.hxx>
      30             : #include <svx/unomodel.hxx>
      31             : #include <svx/svdview.hxx>
      32             : 
      33             : #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL      1
      34             : 
      35             : using namespace ::com::sun::star;
      36             : 
      37             : using ::com::sun::star::uno::Reference;
      38             : using ::com::sun::star::uno::Sequence;
      39             : 
      40             : namespace chart
      41             : {
      42             : 
      43           0 : ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
      44             :     :m_pMarkedObjModel( NULL )
      45           0 :     ,m_bDrawing( bDrawing )
      46             : {
      47           0 :     SdrExchangeView * pExchgView( new SdrView( pDrawModel ));
      48           0 :     SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
      49           0 :     if( pSelectedObj )
      50           0 :         pExchgView->MarkObj( pSelectedObj, pPv );
      51             :     else
      52           0 :         pExchgView->MarkAllObj( pPv );
      53           0 :     Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
      54           0 :     m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
      55           0 :     if ( m_bDrawing )
      56             :     {
      57           0 :         m_pMarkedObjModel = pExchgView->GetMarkedObjModel();
      58             :     }
      59           0 :     delete pExchgView;
      60           0 : }
      61             : 
      62           0 : ChartTransferable::~ChartTransferable()
      63           0 : {}
      64             : 
      65           0 : void ChartTransferable::AddSupportedFormats()
      66             : {
      67           0 :     if ( m_bDrawing )
      68             :     {
      69           0 :         AddFormat( SOT_FORMATSTR_ID_DRAWING );
      70             :     }
      71           0 :     AddFormat( SOT_FORMAT_GDIMETAFILE );
      72           0 :     AddFormat( SOT_FORMATSTR_ID_PNG );
      73           0 :     AddFormat( SOT_FORMAT_BITMAP );
      74           0 : }
      75             : 
      76           0 : bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
      77             : {
      78           0 :     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
      79           0 :     bool        bResult = false;
      80             : 
      81           0 :     if( HasFormat( nFormat ))
      82             :     {
      83           0 :         if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
      84             :         {
      85           0 :             bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
      86             :         }
      87           0 :         else if ( nFormat == FORMAT_GDIMETAFILE )
      88             :         {
      89           0 :             Graphic aGraphic( m_xMetaFileGraphic );
      90           0 :             bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
      91             :         }
      92           0 :         else if( nFormat == FORMAT_BITMAP )
      93             :         {
      94           0 :             Graphic aGraphic( m_xMetaFileGraphic );
      95           0 :             bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
      96             :         }
      97             :     }
      98             : 
      99           0 :     return bResult;
     100             : }
     101             : 
     102           0 : bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
     103             :     const datatransfer::DataFlavor& /* rFlavor */ )
     104             : {
     105             :     // called from SetObject, put data into stream
     106             : 
     107           0 :     bool bRet = false;
     108           0 :     switch ( nUserObjectId )
     109             :     {
     110             :         case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
     111             :             {
     112           0 :                 SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject );
     113           0 :                 if ( pMarkedObjModel )
     114             :                 {
     115           0 :                     rxOStm->SetBufferSize( 0xff00 );
     116             : 
     117             :                     // for the changed pool defaults from drawing layer pool set those
     118             :                     // attributes as hard attributes to preserve them for saving
     119           0 :                     const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
     120             :                     const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
     121           0 :                         rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
     122           0 :                     sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
     123           0 :                     for ( sal_uInt16 i = 0; i < nCount; ++i )
     124             :                     {
     125           0 :                         const SdrPage* pPage = pMarkedObjModel->GetPage( i );
     126           0 :                         SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
     127           0 :                         while ( aIter.IsMore() )
     128             :                         {
     129           0 :                             SdrObject* pObj = aIter.Next();
     130             :                             const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
     131           0 :                                 pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
     132           0 :                             if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
     133             :                             {
     134           0 :                                 pObj->SetMergedItem( rDefaultFontHeight );
     135             :                             }
     136             :                         }
     137           0 :                     }
     138             : 
     139           0 :                     Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
     140           0 :                     if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
     141             :                     {
     142           0 :                         rxOStm->Commit();
     143             :                     }
     144             : 
     145           0 :                     bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     146             :                 }
     147             :             }
     148           0 :             break;
     149             :         default:
     150             :             {
     151             :                 OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" );
     152             :             }
     153           0 :             break;
     154             :     }
     155           0 :     return bRet;
     156             : }
     157             : 
     158         102 : } //  namespace chart
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10