forked from amazingfate/loongoffice
Also simplify parent/child relationships, get rid of double data (SdrPage/Parent infos in SdrObjects, also in SdrObjList). This is all not needed - when a SdrObject is inserted to a SdrPage, get SdrPage by traveling over parents (no double info, member as soon as inserted, ...). More cleanups/reworks included, will need some more cleanups, too. Stabilizing: SetRectsDirty/DefaultStyleSheet Had to correct the SetRectsDirty stuff for 3D due to going down the hierarchy while the 2D implementation goes the other direction -> endless loops. Added special handling for 3D stuff for now (will be chnaged again when SnapRect is no longer needed at SdrObject level). Also had to adapt how the DefaultStyleSheet is set at incarnated SdrObjects - better: their properties. Since we now always have a SdrModel, it is possible to correctly initialize with the correct default StyleSheet from that SdrModel. This needs to be done after ForceDefaultAttributes and in a way that again deletes Items that are set in the StyleSheet. This leads to an error in CppunitTest_sd_import_tests where I checked tdf100491 - it is okay and thus I change the control instance of the imported, XML-dumped file. The less hard attributes, the better for Styles in general. Cleanup of comments for last two commits Corrected SvxShape::getParent() Needed to get the direct parent, so test for SdrObject first (to get SdrObjGroup/E3DScene), for SdrPage second Fixed CppunitTest_sc_subsequent_export_test Several problems arose. The used SdrCaptionObj was Cloned, but the clone not inserted to a SdrPage. This leads to not being able to access a UNO API imlementation of the SdrPage (SvxPage) on lower levels. It worked before due to SdrObject having a SdrPage* additionally to being added to a SdrPage - this is exactly the main cleanup this change does. Looked for why it is cloned, could see no reasons. The SdrCaptionObj exists during all im/export, not difference to other SdrObjects (that do not get cloned). It is not changed in any way. It *might* be to suppress a crash that happened due to UNO API Service emfio/emfio not being available in the UnitTest scenario. Interestingly it did not crash with the cloned SdrCaptionObj, but the Graphic exported was probably wrong. Fixed by no longer Cloning the SdrCaptionObj and adding emfio/emfio UNO API Service. d139f821a5b39535a3e7b9c6261df7e18f8ae8ac 910e7f4bc628a715fda7545dffaf3369d5e76ea0 ca1de01b723051e09ac37d7ec7bba978beea41c5 3a76da1471dfe75e69847f64a6a3519ad21c8c9c Change-Id: I986586e326b563acebf00d931a7084c6eb09e5f8 Reviewed-on: https://gerrit.libreoffice.org/54689 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
167 lines
5.6 KiB
C++
167 lines
5.6 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
#include <sal/config.h>
|
|
|
|
#include <memory>
|
|
|
|
#include "ChartTransferable.hxx"
|
|
|
|
#include <o3tl/make_unique.hxx>
|
|
#include <sot/exchange.hxx>
|
|
#include <sot/storage.hxx>
|
|
#include <unotools/streamwrap.hxx>
|
|
#include <vcl/graph.hxx>
|
|
#include <svl/itempool.hxx>
|
|
#include <editeng/eeitem.hxx>
|
|
#include <editeng/fhgtitem.hxx>
|
|
#include <svx/svditer.hxx>
|
|
#include <svx/svdmodel.hxx>
|
|
#include <svx/svdpage.hxx>
|
|
#include <svx/unomodel.hxx>
|
|
#include <svx/svdview.hxx>
|
|
|
|
constexpr sal_uInt32 CHARTTRANSFER_OBJECTTYPE_DRAWMODEL = 1;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
namespace chart
|
|
{
|
|
|
|
ChartTransferable::ChartTransferable(
|
|
SdrModel& rSdrModel,
|
|
SdrObject* pSelectedObj,
|
|
bool bDrawing)
|
|
: m_pMarkedObjModel( nullptr )
|
|
,m_bDrawing( bDrawing )
|
|
{
|
|
std::unique_ptr<SdrExchangeView> pExchgView(o3tl::make_unique<SdrView>( rSdrModel ));
|
|
SdrPageView* pPv = pExchgView->ShowSdrPage( rSdrModel.GetPage( 0 ));
|
|
if( pSelectedObj )
|
|
pExchgView->MarkObj( pSelectedObj, pPv );
|
|
else
|
|
pExchgView->MarkAllObj( pPv );
|
|
Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
|
|
m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
|
|
if ( m_bDrawing )
|
|
{
|
|
m_pMarkedObjModel = pExchgView->GetMarkedObjModel();
|
|
}
|
|
}
|
|
|
|
ChartTransferable::~ChartTransferable()
|
|
{}
|
|
|
|
void ChartTransferable::AddSupportedFormats()
|
|
{
|
|
if ( m_bDrawing )
|
|
{
|
|
AddFormat( SotClipboardFormatId::DRAWING );
|
|
}
|
|
AddFormat( SotClipboardFormatId::GDIMETAFILE );
|
|
AddFormat( SotClipboardFormatId::PNG );
|
|
AddFormat( SotClipboardFormatId::BITMAP );
|
|
}
|
|
|
|
bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
|
|
{
|
|
SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
|
|
bool bResult = false;
|
|
|
|
if( HasFormat( nFormat ))
|
|
{
|
|
if ( nFormat == SotClipboardFormatId::DRAWING )
|
|
{
|
|
bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
|
|
}
|
|
else if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
|
|
{
|
|
Graphic aGraphic( m_xMetaFileGraphic );
|
|
bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile() );
|
|
}
|
|
else if( nFormat == SotClipboardFormatId::BITMAP )
|
|
{
|
|
Graphic aGraphic( m_xMetaFileGraphic );
|
|
bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
|
|
}
|
|
}
|
|
|
|
return bResult;
|
|
}
|
|
|
|
bool ChartTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
|
|
const datatransfer::DataFlavor& /* rFlavor */ )
|
|
{
|
|
// called from SetObject, put data into stream
|
|
|
|
bool bRet = false;
|
|
switch ( nUserObjectId )
|
|
{
|
|
case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
|
|
{
|
|
SdrModel* pMarkedObjModel = static_cast< SdrModel* >( pUserObject );
|
|
if ( pMarkedObjModel )
|
|
{
|
|
rxOStm->SetBufferSize( 0xff00 );
|
|
|
|
// for the changed pool defaults from drawing layer pool set those
|
|
// attributes as hard attributes to preserve them for saving
|
|
const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
|
|
const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT );
|
|
sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
|
|
for ( sal_uInt16 i = 0; i < nCount; ++i )
|
|
{
|
|
const SdrPage* pPage = pMarkedObjModel->GetPage( i );
|
|
SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
|
|
while ( aIter.IsMore() )
|
|
{
|
|
SdrObject* pObj = aIter.Next();
|
|
const SvxFontHeightItem& rItem = pObj->GetMergedItem( EE_CHAR_FONTHEIGHT );
|
|
if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
|
|
{
|
|
pObj->SetMergedItem( rDefaultFontHeight );
|
|
}
|
|
}
|
|
}
|
|
|
|
Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
|
|
if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
|
|
{
|
|
rxOStm->Commit();
|
|
}
|
|
|
|
bRet = ( rxOStm->GetError() == ERRCODE_NONE );
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" );
|
|
}
|
|
break;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
} // namespace chart
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|