LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartTransferable.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 60 0.0 %
Date: 2014-04-11 Functions: 0 6 0.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             : 
      32             : // header for class SdrView
      33             : #include <svx/svdview.hxx>
      34             : 
      35             : #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL      1
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : using ::com::sun::star::uno::Reference;
      40             : using ::com::sun::star::uno::Sequence;
      41             : 
      42             : namespace chart
      43             : {
      44             : 
      45           0 : ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
      46             :     :m_pMarkedObjModel( NULL )
      47           0 :     ,m_bDrawing( bDrawing )
      48             : {
      49           0 :     SdrExchangeView * pExchgView( new SdrView( pDrawModel ));
      50           0 :     SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
      51           0 :     if( pSelectedObj )
      52           0 :         pExchgView->MarkObj( pSelectedObj, pPv );
      53             :     else
      54           0 :         pExchgView->MarkAllObj( pPv );
      55           0 :     Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
      56           0 :     m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
      57           0 :     if ( m_bDrawing )
      58             :     {
      59           0 :         m_pMarkedObjModel = pExchgView->GetMarkedObjModel();
      60             :     }
      61           0 :     delete pExchgView;
      62           0 : }
      63             : 
      64           0 : ChartTransferable::~ChartTransferable()
      65           0 : {}
      66             : 
      67           0 : void ChartTransferable::AddSupportedFormats()
      68             : {
      69           0 :     if ( m_bDrawing )
      70             :     {
      71           0 :         AddFormat( SOT_FORMATSTR_ID_DRAWING );
      72             :     }
      73           0 :     AddFormat( SOT_FORMAT_GDIMETAFILE );
      74           0 :     AddFormat( SOT_FORMATSTR_ID_PNG );
      75           0 :     AddFormat( SOT_FORMAT_BITMAP );
      76           0 : }
      77             : 
      78           0 : bool ChartTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
      79             : {
      80           0 :     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
      81           0 :     bool        bResult = false;
      82             : 
      83           0 :     if( HasFormat( nFormat ))
      84             :     {
      85           0 :         if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
      86             :         {
      87           0 :             bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
      88             :         }
      89           0 :         else if ( nFormat == FORMAT_GDIMETAFILE )
      90             :         {
      91           0 :             Graphic aGraphic( m_xMetaFileGraphic );
      92           0 :             bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
      93             :         }
      94           0 :         else if( nFormat == FORMAT_BITMAP )
      95             :         {
      96           0 :             Graphic aGraphic( m_xMetaFileGraphic );
      97           0 :             bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
      98             :         }
      99             :     }
     100             : 
     101           0 :     return bResult;
     102             : }
     103             : 
     104           0 : bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
     105             :     const datatransfer::DataFlavor& /* rFlavor */ )
     106             : {
     107             :     // called from SetObject, put data into stream
     108             : 
     109           0 :     bool bRet = false;
     110           0 :     switch ( nUserObjectId )
     111             :     {
     112             :         case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
     113             :             {
     114           0 :                 SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject );
     115           0 :                 if ( pMarkedObjModel )
     116             :                 {
     117           0 :                     rxOStm->SetBufferSize( 0xff00 );
     118             : 
     119             :                     // for the changed pool defaults from drawing layer pool set those
     120             :                     // attributes as hard attributes to preserve them for saving
     121           0 :                     const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
     122             :                     const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
     123           0 :                         rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
     124           0 :                     sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
     125           0 :                     for ( sal_uInt16 i = 0; i < nCount; ++i )
     126             :                     {
     127           0 :                         const SdrPage* pPage = pMarkedObjModel->GetPage( i );
     128           0 :                         SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
     129           0 :                         while ( aIter.IsMore() )
     130             :                         {
     131           0 :                             SdrObject* pObj = aIter.Next();
     132             :                             const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
     133           0 :                                 pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
     134           0 :                             if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
     135             :                             {
     136           0 :                                 pObj->SetMergedItem( rDefaultFontHeight );
     137             :                             }
     138             :                         }
     139           0 :                     }
     140             : 
     141           0 :                     Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
     142           0 :                     if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
     143             :                     {
     144           0 :                         rxOStm->Commit();
     145             :                     }
     146             : 
     147           0 :                     bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     148             :                 }
     149             :             }
     150           0 :             break;
     151             :         default:
     152             :             {
     153             :                 OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" );
     154             :             }
     155           0 :             break;
     156             :     }
     157           0 :     return bRet;
     158             : }
     159             : 
     160             : } //  namespace chart
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10