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 <sot/exchange.hxx>
23 : #include <sot/storage.hxx>
24 : #include <unotools/streamwrap.hxx>
25 : #include <vcl/graph.hxx>
26 : #include <svl/itempool.hxx>
27 : #include <editeng/eeitem.hxx>
28 : #include <editeng/fhgtitem.hxx>
29 : #include <svx/svditer.hxx>
30 : #include <svx/svdmodel.hxx>
31 : #include <svx/svdpage.hxx>
32 : #include <svx/unomodel.hxx>
33 : #include <svx/svdview.hxx>
34 :
35 : #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL SotClipboardFormatId::STRING
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( SotClipboardFormatId::DRAWING );
72 : }
73 0 : AddFormat( SotClipboardFormatId::GDIMETAFILE );
74 0 : AddFormat( SotClipboardFormatId::PNG );
75 0 : AddFormat( SotClipboardFormatId::BITMAP );
76 0 : }
77 :
78 0 : bool ChartTransferable::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ )
79 : {
80 0 : SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
81 0 : bool bResult = false;
82 :
83 0 : if( HasFormat( nFormat ))
84 : {
85 0 : if ( nFormat == SotClipboardFormatId::DRAWING )
86 : {
87 0 : bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
88 : }
89 0 : else if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
90 : {
91 0 : Graphic aGraphic( m_xMetaFileGraphic );
92 0 : bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
93 : }
94 0 : else if( nFormat == SotClipboardFormatId::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( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, SotClipboardFormatId 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 = static_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 57 : } // namespace chart
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|