/src/libreoffice/chart2/source/controller/main/ChartTransferable.cxx
Line | Count | Source (jump to first uncovered line) |
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> |
28 | | #include <unotools/streamwrap.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 | | |
39 | | constexpr sal_uInt32 CHARTTRANSFER_OBJECTTYPE_DRAWMODEL = 1; |
40 | | |
41 | | using namespace ::com::sun::star; |
42 | | |
43 | | using ::com::sun::star::uno::Reference; |
44 | | |
45 | | namespace chart |
46 | | { |
47 | | |
48 | | ChartTransferable::ChartTransferable( |
49 | | SdrModel& rSdrModel, |
50 | | SdrObject* pSelectedObj, |
51 | | bool bDrawing) |
52 | 0 | : m_bDrawing(bDrawing) |
53 | 0 | { |
54 | 0 | SdrView aExchgView( rSdrModel ); |
55 | 0 | SdrPageView* pPv = aExchgView.ShowSdrPage( rSdrModel.GetPage( 0 )); |
56 | 0 | if( pSelectedObj ) |
57 | 0 | aExchgView.MarkObj( pSelectedObj, pPv ); |
58 | 0 | else |
59 | 0 | aExchgView.MarkAllObj( pPv ); |
60 | 0 | Graphic aGraphic( aExchgView.GetMarkedObjMetaFile(true)); |
61 | 0 | m_xMetaFileGraphic.set( aGraphic.GetXGraphic()); |
62 | 0 | if ( m_bDrawing ) |
63 | 0 | { |
64 | 0 | m_xMarkedObjModel = aExchgView.CreateMarkedObjModel(); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | ChartTransferable::~ChartTransferable() |
69 | 0 | {} |
70 | | |
71 | | void ChartTransferable::AddSupportedFormats() |
72 | 0 | { |
73 | 0 | if ( m_bDrawing ) |
74 | 0 | { |
75 | 0 | AddFormat( SotClipboardFormatId::DRAWING ); |
76 | 0 | } |
77 | 0 | AddFormat( SotClipboardFormatId::GDIMETAFILE ); |
78 | 0 | AddFormat( SotClipboardFormatId::PNG ); |
79 | 0 | AddFormat( SotClipboardFormatId::BITMAP ); |
80 | 0 | } |
81 | | |
82 | | bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ ) |
83 | 0 | { |
84 | 0 | SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor ); |
85 | 0 | bool bResult = false; |
86 | |
|
87 | 0 | if( HasFormat( nFormat )) |
88 | 0 | { |
89 | 0 | if ( nFormat == SotClipboardFormatId::DRAWING ) |
90 | 0 | { |
91 | 0 | bResult = SetObject(m_xMarkedObjModel.get(), CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor); |
92 | 0 | } |
93 | 0 | else if ( nFormat == SotClipboardFormatId::GDIMETAFILE ) |
94 | 0 | { |
95 | 0 | Graphic aGraphic( m_xMetaFileGraphic ); |
96 | 0 | bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile() ); |
97 | 0 | } |
98 | 0 | else if( nFormat == SotClipboardFormatId::BITMAP ) |
99 | 0 | { |
100 | 0 | Graphic aGraphic( m_xMetaFileGraphic ); |
101 | 0 | bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor ); |
102 | 0 | } |
103 | 0 | } |
104 | |
|
105 | 0 | return bResult; |
106 | 0 | } |
107 | | |
108 | | bool ChartTransferable::WriteObject( SvStream& rOStm, void* pUserObject, sal_uInt32 nUserObjectId, |
109 | | const datatransfer::DataFlavor& /* rFlavor */ ) |
110 | 0 | { |
111 | | // called from SetObject, put data into stream |
112 | |
|
113 | 0 | bool bRet = false; |
114 | 0 | switch ( nUserObjectId ) |
115 | 0 | { |
116 | 0 | case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL: |
117 | 0 | { |
118 | 0 | SdrModel* pMarkedObjModel = static_cast< SdrModel* >( pUserObject ); |
119 | 0 | if ( pMarkedObjModel ) |
120 | 0 | { |
121 | 0 | rOStm.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 | 0 | const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool(); |
126 | 0 | const SvxFontHeightItem& rDefaultFontHeight = rItemPool.GetUserOrPoolDefaultItem( EE_CHAR_FONTHEIGHT ); |
127 | 0 | sal_uInt16 nCount = pMarkedObjModel->GetPageCount(); |
128 | 0 | for ( sal_uInt16 i = 0; i < nCount; ++i ) |
129 | 0 | { |
130 | 0 | const SdrPage* pPage = pMarkedObjModel->GetPage( i ); |
131 | 0 | SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups ); |
132 | 0 | while ( aIter.IsMore() ) |
133 | 0 | { |
134 | 0 | SdrObject* pObj = aIter.Next(); |
135 | 0 | const SvxFontHeightItem& rItem = pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ); |
136 | 0 | if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() ) |
137 | 0 | { |
138 | 0 | pObj->SetMergedItem( rDefaultFontHeight ); |
139 | 0 | } |
140 | 0 | } |
141 | 0 | } |
142 | |
|
143 | 0 | Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( rOStm ) ); |
144 | 0 | SvxDrawingLayerExport( pMarkedObjModel, xDocOut ); |
145 | |
|
146 | 0 | bRet = ( rOStm.GetError() == ERRCODE_NONE ); |
147 | 0 | } |
148 | 0 | } |
149 | 0 | break; |
150 | 0 | default: |
151 | 0 | { |
152 | 0 | OSL_FAIL( "ChartTransferable::WriteObject: unknown object id" ); |
153 | 0 | } |
154 | 0 | break; |
155 | 0 | } |
156 | 0 | return bRet; |
157 | 0 | } |
158 | | |
159 | | } // namespace chart |
160 | | |
161 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |