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