merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / misc / chartprettypainter.cxx
blob042958e15c14201f28bbed87209504eb35f94300
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chartprettypainter.cxx,v $
11 * $Revision: 1.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svtools.hxx"
35 #include <svtools/chartprettypainter.hxx>
37 #include <tools/globname.hxx>
38 #include <sot/clsids.hxx>
39 // header for function rtl_createUuid
40 #include <rtl/uuid.h>
41 #include <vcl/pdfextoutdevdata.hxx>
43 #include <com/sun/star/lang/XUnoTunnel.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <svtools/embedhlp.hxx>
47 using namespace ::com::sun::star;
49 ChartPrettyPainter::ChartPrettyPainter()
53 ChartPrettyPainter::~ChartPrettyPainter()
57 bool ChartPrettyPainter::DoPaint(OutputDevice* /*pOutDev*/, const Rectangle& /*rLogicObjectRect*/) const
59 return false;
62 //static
63 const uno::Sequence<sal_Int8>& ChartPrettyPainter::getUnoTunnelId()
65 static uno::Sequence<sal_Int8> * pSeq = 0;
66 if( !pSeq )
68 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
69 if( !pSeq )
71 static uno::Sequence< sal_Int8 > aSeq( 16 );
72 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
73 pSeq = &aSeq;
76 return *pSeq;
79 bool ChartPrettyPainter::IsChart( const svt::EmbeddedObjectRef& xObjRef )
81 if ( !xObjRef.is() )
82 return false;
84 SvGlobalName aObjClsId( xObjRef->getClassID() );
85 if(
86 SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
87 || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
88 || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
89 || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
91 return true;
94 return false;
97 bool ChartPrettyPainter::ShouldPrettyPaintChartOnThisDevice( OutputDevice* pOutDev )
99 if( !pOutDev )
100 return false;
101 //at least the print preview in calc has a paint loop due to too much invalidate calls deep in sdr
102 //to avoid the paint loop we use the metafile replacement in this case instead of direct rendering
103 if( OUTDEV_WINDOW == pOutDev->GetOutDevType() )
104 return false;
105 if( OUTDEV_PRINTER == pOutDev->GetOutDevType() )
106 return true;
107 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pOutDev->GetExtOutDevData() );
108 if( pPDFData )
109 return true;
110 return false;
113 bool ChartPrettyPainter::DoPrettyPaintChart( uno::Reference< frame::XModel > xChartModel, OutputDevice* pOutDev, const Rectangle& rLogicObjectRect )
115 //charts must be painted resolution dependent!! #i82893#, #i75867#
116 if( !xChartModel.is() || !ShouldPrettyPaintChartOnThisDevice( pOutDev ) )
117 return false;
121 uno::Reference< lang::XMultiServiceFactory > xFact( xChartModel, uno::UNO_QUERY );
122 OSL_ENSURE( xFact.is(), "Chart cannot be painted pretty!\n" );
123 if( xFact.is() )
125 uno::Reference< lang::XUnoTunnel > xChartRenderer( xFact->createInstance(
126 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ChartRenderer" ) ) ), uno::UNO_QUERY );
127 OSL_ENSURE( xChartRenderer.is(), "Chart cannot be painted pretty!\n" );
128 if( xChartRenderer.is() )
130 ChartPrettyPainter* pPrettyPainter = reinterpret_cast<ChartPrettyPainter*>(
131 xChartRenderer->getSomething( ChartPrettyPainter::getUnoTunnelId() ));
132 if( pPrettyPainter )
133 return pPrettyPainter->DoPaint(pOutDev, rLogicObjectRect);
137 catch( uno::Exception& e )
139 (void)e;
140 DBG_ERROR( "Chart cannot be painted pretty!" );
142 return false;