LibreOffice Module chart2 (master) 1
ChartTransferable.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <memory>
23
24#include "ChartTransferable.hxx"
25
26#include <sot/exchange.hxx>
27#include <sot/storage.hxx>
29#include <vcl/graph.hxx>
30#include <svl/itempool.hxx>
31#include <editeng/eeitem.hxx>
32#include <editeng/fhgtitem.hxx>
33#include <svx/svditer.hxx>
34#include <svx/svdmodel.hxx>
35#include <svx/unomodel.hxx>
36#include <svx/svdview.hxx>
37#include <osl/diagnose.h>
38
39constexpr sal_uInt32 CHARTTRANSFER_OBJECTTYPE_DRAWMODEL = 1;
40
41using namespace ::com::sun::star;
42
43using ::com::sun::star::uno::Reference;
44
45namespace chart
46{
47
49 SdrModel& rSdrModel,
50 SdrObject* pSelectedObj,
51 bool bDrawing)
52 : m_bDrawing(bDrawing)
53{
54 std::unique_ptr<SdrExchangeView> pExchgView(std::make_unique<SdrView>( rSdrModel ));
55 SdrPageView* pPv = pExchgView->ShowSdrPage( rSdrModel.GetPage( 0 ));
56 if( pSelectedObj )
57 pExchgView->MarkObj( pSelectedObj, pPv );
58 else
59 pExchgView->MarkAllObj( pPv );
60 Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
61 m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
62 if ( m_bDrawing )
63 {
64 m_xMarkedObjModel = pExchgView->CreateMarkedObjModel();
65 }
66}
67
69{}
70
72{
73 if ( m_bDrawing )
74 {
75 AddFormat( SotClipboardFormatId::DRAWING );
76 }
77 AddFormat( SotClipboardFormatId::GDIMETAFILE );
78 AddFormat( SotClipboardFormatId::PNG );
79 AddFormat( SotClipboardFormatId::BITMAP );
80}
81
82bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
83{
85 bool bResult = false;
86
87 if( HasFormat( nFormat ))
88 {
89 if ( nFormat == SotClipboardFormatId::DRAWING )
90 {
92 }
93 else if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
94 {
95 Graphic aGraphic( m_xMetaFileGraphic );
96 bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile() );
97 }
98 else if( nFormat == SotClipboardFormatId::BITMAP )
99 {
100 Graphic aGraphic( m_xMetaFileGraphic );
101 bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
102 }
103 }
104
105 return bResult;
106}
107
108bool ChartTransferable::WriteObject( tools::SvRef<SotTempStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
109 const datatransfer::DataFlavor& /* rFlavor */ )
110{
111 // called from SetObject, put data into stream
112
113 bool bRet = false;
114 switch ( nUserObjectId )
115 {
117 {
118 SdrModel* pMarkedObjModel = static_cast< SdrModel* >( pUserObject );
119 if ( pMarkedObjModel )
120 {
121 rxOStm->SetBufferSize( 0xff00 );
122
123 // for the changed pool defaults from drawing layer pool set those
124 // attributes as hard attributes to preserve them for saving
125 const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
126 const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT );
127 sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
128 for ( sal_uInt16 i = 0; i < nCount; ++i )
129 {
130 const SdrPage* pPage = pMarkedObjModel->GetPage( i );
131 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
132 while ( aIter.IsMore() )
133 {
134 SdrObject* pObj = aIter.Next();
135 const SvxFontHeightItem& rItem = pObj->GetMergedItem( EE_CHAR_FONTHEIGHT );
136 if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
137 {
138 pObj->SetMergedItem( rDefaultFontHeight );
139 }
140 }
141 }
142
144 SvxDrawingLayerExport( pMarkedObjModel, xDocOut );
145
146 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
147 }
148 }
149 break;
150 default:
151 {
152 OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" );
153 }
154 break;
155 }
156 return bRet;
157}
158
159} // namespace chart
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt32 CHARTTRANSFER_OBJECTTYPE_DRAWMODEL
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
const GDIMetaFile & GetGDIMetaFile() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
const SfxItemPool & GetItemPool() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * Next()
bool IsMore() const
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
void SetMergedItem(const SfxPoolItem &rItem)
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
sal_uInt32 GetHeight() const
bool SetObject(void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor)
bool SetBitmapEx(const BitmapEx &rBitmap, const css::datatransfer::DataFlavor &rFlavor)
bool HasFormat(SotClipboardFormatId nFormat)
void AddFormat(SotClipboardFormatId nFormat)
bool SetGDIMetaFile(const GDIMetaFile &rMtf)
ChartTransferable(SdrModel &rSdrModel, SdrObject *pSelectedObj, bool bDrawing)
std::unique_ptr< SdrModel > m_xMarkedObjModel
virtual ~ChartTransferable() override
virtual bool WriteObject(tools::SvRef< SotTempStream > &rxOStm, void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor) override
virtual void AddSupportedFormats() override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
css::uno::Reference< css::graphic::XGraphic > m_xMetaFileGraphic
int nCount
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
#define ERRCODE_NONE
SotClipboardFormatId
int i
SVXCORE_DLLPUBLIC bool SvxDrawingLayerExport(SdrModel *pModel, const css::uno::Reference< css::io::XOutputStream > &xOut)