merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / main / ChartRenderer.cxx
blobc0a0fd971d911a851babb9e64593cc0449ee1f81
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: ChartRenderer.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_chart2.hxx"
35 #include "ChartRenderer.hxx"
36 #include "servicenames.hxx"
37 #include "chartview/ExplicitValueProvider.hxx"
38 #include "chartview/DrawModelWrapper.hxx"
39 #include "DrawViewWrapper.hxx"
40 #include "macros.hxx"
41 #include "ChartModelHelper.hxx"
42 #include <vcl/svapp.hxx>
43 #include <vos/mutex.hxx>
45 #include <com/sun/star/util/XUpdatable.hpp>
47 //.............................................................................
48 namespace chart
50 //.............................................................................
52 using namespace ::com::sun::star;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::Sequence;
55 using rtl::OUString;
57 ChartRenderer::ChartRenderer( const Reference< frame::XModel >& xChartModel )
58 : m_xChartModel( uno::WeakReference< frame::XModel >(xChartModel) )
62 ChartRenderer::~ChartRenderer()
66 // ____ ChartPrettyPainter ___
67 bool ChartRenderer::DoPaint(OutputDevice* pOutDev, const Rectangle& rLogicObjectRect /*in given output dev map units*/ ) const
69 if(!pOutDev)
70 return false;
72 Reference<frame::XModel> xModel(m_xChartModel);
73 uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
74 if( !xFact.is() )
75 return false;
77 //#i84323# ensure that the size the container has of the chart and size that chart has itself are the same
78 //maybe remove this workaround somewhere in future again
80 if( MAP_100TH_MM == pOutDev->GetMapMode().GetMapUnit() )//no problem for writer in issue #i84323#; but writer uses twips instead of 100thmm which causes small differences in size always when converting to 100thmm and back
82 awt::Size aChartSize( ChartModelHelper::getPageSize(xModel) );
83 awt::Size aContainerChartSize( rLogicObjectRect.GetWidth(), rLogicObjectRect.GetHeight() );
84 if( aContainerChartSize.Width != aChartSize.Width
85 || aContainerChartSize.Height != aChartSize.Height )
87 DBG_ERROR("chart size does not equal size assumed by the container");
88 //correct the state here on the fly -> let the container size win
89 ChartModelHelper::setPageSize( aContainerChartSize, xModel );
94 // get the chart view
95 Reference< lang::XUnoTunnel > xChartView( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
97 try
99 //better performance for big data
100 uno::Reference< beans::XPropertySet > xProp( xChartView, uno::UNO_QUERY );
101 if( xProp.is() )
103 awt::Size aResolution(1000,1000);
105 ::vos::OGuard aGuard( Application::GetSolarMutex());
106 Rectangle aPixelRect( pOutDev->LogicToPixel( rLogicObjectRect ) );
107 aResolution.Width = aPixelRect.GetWidth();
108 aResolution.Height = aPixelRect.GetHeight();
110 xProp->setPropertyValue( C2U("Resolution"), uno::makeAny( aResolution ));
114 uno::Reference< util::XUpdatable > xUpdatable( xChartView, uno::UNO_QUERY );
115 if( xUpdatable.is() )
116 xUpdatable->update();
118 ::vos::OGuard aGuard( Application::GetSolarMutex());
119 ExplicitValueProvider* pProvider = ExplicitValueProvider::getExplicitValueProvider( xChartView );
120 if( !pProvider )
121 return false;
122 ::boost::shared_ptr< DrawModelWrapper > pDrawModelWrapper = pProvider->getDrawModelWrapper();
123 if( !pDrawModelWrapper.get() )
124 return false;
125 ::boost::shared_ptr< DrawViewWrapper > pDrawViewWrapper( new DrawViewWrapper(&pDrawModelWrapper->getSdrModel(),pOutDev,false) );
126 pDrawViewWrapper->attachParentReferenceDevice( xModel );
128 MapMode aOldMapMode( pOutDev->GetMapMode() );
129 Point aOldOrigin( aOldMapMode.GetOrigin() );
130 MapMode aMapMode( aOldMapMode );
131 Point aOldOriginMM( OutputDevice::LogicToLogic( aOldOrigin, aOldMapMode.GetMapUnit(), MAP_100TH_MM ) );
132 Point aObjectTopLeftMM( OutputDevice::LogicToLogic( rLogicObjectRect.TopLeft(), aOldMapMode.GetMapUnit(), MAP_100TH_MM ) );
133 aMapMode.SetOrigin( aOldOriginMM + aObjectTopLeftMM );
134 aMapMode.SetMapUnit( MAP_100TH_MM );
135 pOutDev->SetMapMode(aMapMode);
137 Rectangle aPaintRect( OutputDevice::LogicToLogic( rLogicObjectRect, aOldMapMode, aMapMode ) );
138 pDrawViewWrapper->CompleteRedraw(pOutDev, Region(aPaintRect) );
140 pOutDev->SetMapMode(aOldMapMode);
142 catch( uno::Exception & ex )
144 ASSERT_EXCEPTION( ex );
146 catch( ... )
150 return true;
153 //-----------------------------------------------------------------
154 // ____ XUnoTunnel ___
155 ::sal_Int64 SAL_CALL ChartRenderer::getSomething( const Sequence< ::sal_Int8 >& aIdentifier )
156 throw( uno::RuntimeException)
158 if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(
159 ChartPrettyPainter::getUnoTunnelId().getConstArray(),
160 aIdentifier.getConstArray(), 16 ) )
162 ChartPrettyPainter* pPaintableObject = this;
163 return reinterpret_cast<sal_Int64>(pPaintableObject);
165 return 0;
168 //-----------------------------------------------------------------
169 // lang::XServiceInfo
171 APPHELPER_XSERVICEINFO_IMPL(ChartRenderer,CHART_RENDERER_SERVICE_IMPLEMENTATION_NAME)
173 Sequence< OUString > ChartRenderer::getSupportedServiceNames_Static()
175 Sequence< OUString > aSNS;
176 return aSNS;
179 //.............................................................................
180 } //namespace chart
181 //.............................................................................