xref: /AOO41X/main/chart2/source/controller/main/ChartTransferable.cxx (revision c945f2553a89a0730a645e382b4d7941bc6e551c)
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 
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 
72 ChartTransferable::~ChartTransferable()
73 {}
74 
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_FORMAT_BITMAP );
83 }
84 
85 sal_Bool ChartTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
86 {
87     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
88     sal_Bool    bResult = sal_False;
89 
90     if( HasFormat( nFormat ))
91     {
92         if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
93         {
94             bResult = SetObject( m_pMarkedObjModel, CHARTTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
95         }
96         else if ( nFormat == FORMAT_GDIMETAFILE )
97         {
98             Graphic aGraphic( m_xMetaFileGraphic );
99             bResult = SetGDIMetaFile( aGraphic.GetGDIMetaFile(), rFlavor );
100         }
101         else if( nFormat == FORMAT_BITMAP )
102         {
103             Graphic aGraphic( m_xMetaFileGraphic );
104             bResult = SetBitmapEx( aGraphic.GetBitmapEx(), rFlavor );
105         }
106     }
107 
108     return bResult;
109 }
110 
111 sal_Bool ChartTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
112     const datatransfer::DataFlavor& /* rFlavor */ )
113 {
114     // called from SetObject, put data into stream
115 
116     sal_Bool bRet = sal_False;
117     switch ( nUserObjectId )
118     {
119         case CHARTTRANSFER_OBJECTTYPE_DRAWMODEL:
120             {
121                 SdrModel* pMarkedObjModel = reinterpret_cast< SdrModel* >( pUserObject );
122                 if ( pMarkedObjModel )
123                 {
124                     rxOStm->SetBufferSize( 0xff00 );
125 
126 				    // #108584#
127 				    // for the changed pool defaults from drawing layer pool set those
128 				    // attributes as hard attributes to preserve them for saving
129 				    const SfxItemPool& rItemPool = pMarkedObjModel->GetItemPool();
130 				    const SvxFontHeightItem& rDefaultFontHeight = static_cast< const SvxFontHeightItem& >(
131                         rItemPool.GetDefaultItem( EE_CHAR_FONTHEIGHT ) );
132                     sal_uInt16 nCount = pMarkedObjModel->GetPageCount();
133 				    for ( sal_uInt16 i = 0; i < nCount; ++i )
134 				    {
135 					    const SdrPage* pPage = pMarkedObjModel->GetPage( i );
136 					    SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
137 					    while ( aIter.IsMore() )
138 					    {
139 						    SdrObject* pObj = aIter.Next();
140 						    const SvxFontHeightItem& rItem = static_cast< const SvxFontHeightItem& >(
141                                 pObj->GetMergedItem( EE_CHAR_FONTHEIGHT ) );
142 						    if ( rItem.GetHeight() == rDefaultFontHeight.GetHeight() )
143 						    {
144 							    pObj->SetMergedItem( rDefaultFontHeight );
145 						    }
146 					    }
147 				    }
148 
149 				    Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
150 				    if ( SvxDrawingLayerExport( pMarkedObjModel, xDocOut ) )
151                     {
152 					    rxOStm->Commit();
153                     }
154 
155 				    bRet = ( rxOStm->GetError() == ERRCODE_NONE );
156                 }
157             }
158             break;
159         default:
160             {
161                 DBG_ERROR( "ChartTransferable::WriteObject: unknown object id" );
162             }
163             break;
164     }
165     return bRet;
166 }
167 
168 } //  namespace chart
169