xref: /AOO41X/main/chart2/source/controller/main/ChartTransferable.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "ChartTransferable.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
34*cdf0e10cSrcweir #include <vcl/graph.hxx>
35*cdf0e10cSrcweir #include <svl/itempool.hxx>
36*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
37*cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
38*cdf0e10cSrcweir #include <svx/svditer.hxx>
39*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
40*cdf0e10cSrcweir #include <svx/svdpage.hxx>
41*cdf0e10cSrcweir #include <svx/unomodel.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir // header for class SdrView
44*cdf0e10cSrcweir #include <svx/svdview.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #define CHARTTRANSFER_OBJECTTYPE_DRAWMODEL      1
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace ::com::sun::star;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
51*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
52*cdf0e10cSrcweir using ::rtl::OUString;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace chart
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
58*cdf0e10cSrcweir     :m_pMarkedObjModel( NULL )
59*cdf0e10cSrcweir     ,m_bDrawing( bDrawing )
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     SdrExchangeView * pExchgView( new SdrView( pDrawModel ));
62*cdf0e10cSrcweir     SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
63*cdf0e10cSrcweir     if( pSelectedObj )
64*cdf0e10cSrcweir         pExchgView->MarkObj( pSelectedObj, pPv );
65*cdf0e10cSrcweir     else
66*cdf0e10cSrcweir         pExchgView->MarkAllObj( pPv );
67*cdf0e10cSrcweir     Graphic aGraphic( pExchgView->GetMarkedObjMetaFile( sal_True ));
68*cdf0e10cSrcweir     m_xMetaFileGraphic.set( aGraphic.GetXGraphic());
69*cdf0e10cSrcweir     if ( m_bDrawing )
70*cdf0e10cSrcweir     {
71*cdf0e10cSrcweir         m_pMarkedObjModel = ( pExchgView ? pExchgView->GetAllMarkedModel() : NULL );
72*cdf0e10cSrcweir     }
73*cdf0e10cSrcweir     delete pExchgView;
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir ChartTransferable::~ChartTransferable()
77*cdf0e10cSrcweir {}
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void ChartTransferable::AddSupportedFormats()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     if ( m_bDrawing )
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_DRAWING );
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir     AddFormat( SOT_FORMAT_GDIMETAFILE );
86*cdf0e10cSrcweir     AddFormat( SOT_FORMAT_BITMAP );
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir sal_Bool ChartTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
92*cdf0e10cSrcweir     sal_Bool    bResult = sal_False;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     if( HasFormat( nFormat ))
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
97*cdf0e10cSrcweir         {
98*cdf0e10cSrcweir             bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir         else if ( nFormat == FORMAT_GDIMETAFILE )
101*cdf0e10cSrcweir         {
102*cdf0e10cSrcweir             Graphic aGraphic( m_xMetaFileGraphic );
103*cdf0e10cSrcweir             bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir         else if( nFormat == FORMAT_BITMAP )
106*cdf0e10cSrcweir         {
107*cdf0e10cSrcweir             Graphic aGraphic( m_xMetaFileGraphic );
108*cdf0e10cSrcweir             bResult = SetBitmap( aGraphic.GetBitmap(), rFlavor );
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     return bResult;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir sal_Bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
116*cdf0e10cSrcweir     const datatransfer::DataFlavor& /* rFlavor */ )
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     // called from SetObject, put data into stream
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
121*cdf0e10cSrcweir     switch ( nUserObjectId )
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
124*cdf0e10cSrcweir             {
125*cdf0e10cSrcweir                 SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject );
126*cdf0e10cSrcweir                 if ( pMarkedObjModel )
127*cdf0e10cSrcweir                 {
128*cdf0e10cSrcweir                     rxOStm->SetBufferSize( 0xff00 );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 				    // #108584#
131*cdf0e10cSrcweir 				    // for the changed pool defaults from drawing layer pool set those
132*cdf0e10cSrcweir 				    // attributes as hard attributes to preserve them for saving
133*cdf0e10cSrcweir 				    const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
134*cdf0e10cSrcweir 				    const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
135*cdf0e10cSrcweir                         rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
136*cdf0e10cSrcweir                     sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
137*cdf0e10cSrcweir 				    for ( sal_uInt16 i = 0; i < nCount; ++i )
138*cdf0e10cSrcweir 				    {
139*cdf0e10cSrcweir 					    const SdrPage* pPage = pMarkedObjModel->GetPage( i );
140*cdf0e10cSrcweir 					    SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
141*cdf0e10cSrcweir 					    while ( aIter.IsMore() )
142*cdf0e10cSrcweir 					    {
143*cdf0e10cSrcweir 						    SdrObject* pObj = aIter.Next();
144*cdf0e10cSrcweir 						    const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
145*cdf0e10cSrcweir                                 pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
146*cdf0e10cSrcweir 						    if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
147*cdf0e10cSrcweir 						    {
148*cdf0e10cSrcweir 							    pObj->SetMergedItem( rDefaultFontHeight );
149*cdf0e10cSrcweir 						    }
150*cdf0e10cSrcweir 					    }
151*cdf0e10cSrcweir 				    }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 				    Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
154*cdf0e10cSrcweir 				    if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
155*cdf0e10cSrcweir                     {
156*cdf0e10cSrcweir 					    rxOStm->Commit();
157*cdf0e10cSrcweir                     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 				    bRet = ( rxOStm->GetError() == ERRCODE_NONE );
160*cdf0e10cSrcweir                 }
161*cdf0e10cSrcweir             }
162*cdf0e10cSrcweir             break;
163*cdf0e10cSrcweir         default:
164*cdf0e10cSrcweir             {
165*cdf0e10cSrcweir                 DBG_ERROR( "ChartTransferable::WriteObject: unknown object id" );
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir             break;
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir     return bRet;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir } //  namespace chart
173