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