1cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5cde9e8dcSAndrew Rist * distributed with this work for additional information
6cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18cde9e8dcSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20cde9e8dcSAndrew Rist *************************************************************/
21cde9e8dcSAndrew Rist
22cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "ChartTransferable.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
30cdf0e10cSrcweir #include <vcl/graph.hxx>
31cdf0e10cSrcweir #include <svl/itempool.hxx>
32cdf0e10cSrcweir #include <editeng/eeitem.hxx>
33cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
34cdf0e10cSrcweir #include <svx/svditer.hxx>
35cdf0e10cSrcweir #include <svx/svdmodel.hxx>
36cdf0e10cSrcweir #include <svx/svdpage.hxx>
37cdf0e10cSrcweir #include <svx/unomodel.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir // header for class SdrView
40cdf0e10cSrcweir #include <svx/svdview.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL 1
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir
46cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
47cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
48cdf0e10cSrcweir using ::rtl::OUString;
49cdf0e10cSrcweir
50cdf0e10cSrcweir namespace chart
51cdf0e10cSrcweir {
52cdf0e10cSrcweir
ChartTransferable(SdrModel * pDrawModel,SdrObject * pSelectedObj,bool bDrawing)53cdf0e10cSrcweir ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
54cdf0e10cSrcweir :m_pMarkedObjModel( NULL )
55cdf0e10cSrcweir ,m_bDrawing( bDrawing )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir SdrExchangeView * pExchgView( new SdrView( pDrawModel ));
58cdf0e10cSrcweir SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
59cdf0e10cSrcweir if( pSelectedObj )
60cdf0e10cSrcweir pExchgView->MarkObj( pSelectedObj, pPv );
61cdf0e10cSrcweir else
62cdf0e10cSrcweir pExchgView->MarkAllObj( pPv );
63bb18ee55SArmin Le Grand Graphic aGraphic( pExchgView->GetMarkedObjMetaFile(true));
64cdf0e10cSrcweir m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
65cdf0e10cSrcweir if ( m_bDrawing )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir m_pMarkedObjModel = ( pExchgView ? pExchgView->GetAllMarkedModel() : NULL );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir delete pExchgView;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
~ChartTransferable()72cdf0e10cSrcweir ChartTransferable::~ChartTransferable()
73cdf0e10cSrcweir {}
74cdf0e10cSrcweir
AddSupportedFormats()75cdf0e10cSrcweir void ChartTransferable::AddSupportedFormats()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir if ( m_bDrawing )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_DRAWING );
80cdf0e10cSrcweir }
81cdf0e10cSrcweir AddFormat( SOT_FORMAT_GDIMETAFILE );
82*a206ee71SArmin Le Grand AddFormat( SOT_FORMATSTR_ID_PNG );
83cdf0e10cSrcweir AddFormat( SOT_FORMAT_BITMAP );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
GetData(const::com::sun::star::datatransfer::DataFlavor & rFlavor)86cdf0e10cSrcweir sal_Bool ChartTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
89cdf0e10cSrcweir sal_Bool bResult = sal_False;
90cdf0e10cSrcweir
91cdf0e10cSrcweir if( HasFormat( nFormat ))
92cdf0e10cSrcweir {
93cdf0e10cSrcweir if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir else if ( nFormat == FORMAT_GDIMETAFILE )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir Graphic aGraphic( m_xMetaFileGraphic );
100cdf0e10cSrcweir bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir else if( nFormat == FORMAT_BITMAP )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir Graphic aGraphic( m_xMetaFileGraphic );
10545fd3b9aSArmin Le Grand bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir return bResult;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
WriteObject(SotStorageStreamRef & rxOStm,void * pUserObject,sal_uInt32 nUserObjectId,const datatransfer::DataFlavor &)112cdf0e10cSrcweir sal_Bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
113cdf0e10cSrcweir const datatransfer::DataFlavor& /* rFlavor */ )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir // called from SetObject, put data into stream
116cdf0e10cSrcweir
117cdf0e10cSrcweir sal_Bool bRet = sal_False;
118cdf0e10cSrcweir switch ( nUserObjectId )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
121cdf0e10cSrcweir {
122cdf0e10cSrcweir SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject );
123cdf0e10cSrcweir if ( pMarkedObjModel )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir rxOStm->SetBufferSize( 0xff00 );
126cdf0e10cSrcweir
127cdf0e10cSrcweir // #108584#
128cdf0e10cSrcweir // for the changed pool defaults from drawing layer pool set those
129cdf0e10cSrcweir // attributes as hard attributes to preserve them for saving
130cdf0e10cSrcweir const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
131cdf0e10cSrcweir const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
132cdf0e10cSrcweir rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
133cdf0e10cSrcweir sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
134cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir const SdrPage* pPage = pMarkedObjModel->GetPage( i );
137cdf0e10cSrcweir SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
138cdf0e10cSrcweir while ( aIter.IsMore() )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir SdrObject* pObj = aIter.Next();
141cdf0e10cSrcweir const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
142cdf0e10cSrcweir pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
143cdf0e10cSrcweir if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir pObj->SetMergedItem( rDefaultFontHeight );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
151cdf0e10cSrcweir if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir rxOStm->Commit();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir break;
160cdf0e10cSrcweir default:
161cdf0e10cSrcweir {
162cdf0e10cSrcweir DBG_ERROR( "ChartTransferable::WriteObject: unknown object id" );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir break;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir return bRet;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
169cdf0e10cSrcweir } // namespace chart
170