Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "ChartRenderer.hxx"
21 : : #include "servicenames.hxx"
22 : : #include "chartview/ExplicitValueProvider.hxx"
23 : : #include "chartview/DrawModelWrapper.hxx"
24 : : #include "DrawViewWrapper.hxx"
25 : : #include "macros.hxx"
26 : : #include "ChartModelHelper.hxx"
27 : : #include <vcl/svapp.hxx>
28 : : #include <osl/mutex.hxx>
29 : :
30 : : #include <com/sun/star/util/XUpdatable.hpp>
31 : :
32 : : //.............................................................................
33 : : namespace chart
34 : : {
35 : : //.............................................................................
36 : :
37 : : using namespace ::com::sun::star;
38 : : using ::com::sun::star::uno::Reference;
39 : : using ::com::sun::star::uno::Sequence;
40 : : using rtl::OUString;
41 : :
42 : 0 : ChartRenderer::ChartRenderer( const Reference< frame::XModel >& xChartModel )
43 [ # # ][ # # ]: 0 : : m_xChartModel( uno::WeakReference< frame::XModel >(xChartModel) )
44 : : {
45 : 0 : }
46 : :
47 [ # # ][ # # ]: 0 : ChartRenderer::~ChartRenderer()
48 : : {
49 [ # # ]: 0 : }
50 : :
51 : : // ____ ChartPrettyPainter ___
52 : 0 : bool ChartRenderer::DoPaint(OutputDevice* pOutDev, const Rectangle& rLogicObjectRect /*in given output dev map units*/ ) const
53 : : {
54 [ # # ]: 0 : if(!pOutDev)
55 : 0 : return false;
56 : :
57 [ # # ]: 0 : Reference<frame::XModel> xModel(m_xChartModel);
58 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
59 [ # # ]: 0 : if( !xFact.is() )
60 : 0 : return false;
61 : :
62 : : //#i84323# ensure that the size the container has of the chart and size that chart has itself are the same
63 : : //maybe remove this workaround somewhere in future again
64 : : {
65 [ # # ]: 0 : 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
66 : : {
67 [ # # ]: 0 : awt::Size aChartSize( ChartModelHelper::getPageSize(xModel) );
68 [ # # ][ # # ]: 0 : awt::Size aContainerChartSize( rLogicObjectRect.GetWidth(), rLogicObjectRect.GetHeight() );
69 [ # # ][ # # ]: 0 : if( aContainerChartSize.Width != aChartSize.Width
70 : : || aContainerChartSize.Height != aChartSize.Height )
71 : : {
72 : : OSL_FAIL("chart size does not equal size assumed by the container");
73 : : //correct the state here on the fly -> let the container size win
74 [ # # ]: 0 : ChartModelHelper::setPageSize( aContainerChartSize, xModel );
75 : : }
76 : : }
77 : : }
78 : :
79 : : // get the chart view
80 [ # # ][ # # ]: 0 : Reference< lang::XUnoTunnel > xChartView( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
[ # # ][ # # ]
81 : :
82 : : try
83 : : {
84 : : //better performance for big data
85 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProp( xChartView, uno::UNO_QUERY );
86 [ # # ]: 0 : if( xProp.is() )
87 : : {
88 : 0 : awt::Size aResolution(1000,1000);
89 : : {
90 [ # # ]: 0 : SolarMutexGuard aGuard;
91 [ # # ]: 0 : Rectangle aPixelRect( pOutDev->LogicToPixel( rLogicObjectRect ) );
92 [ # # ]: 0 : aResolution.Width = aPixelRect.GetWidth();
93 [ # # ][ # # ]: 0 : aResolution.Height = aPixelRect.GetHeight();
94 : : }
95 [ # # ][ # # ]: 0 : xProp->setPropertyValue( C2U("Resolution"), uno::makeAny( aResolution ));
[ # # ][ # # ]
96 : : }
97 : : //
98 : :
99 [ # # ]: 0 : uno::Reference< util::XUpdatable > xUpdatable( xChartView, uno::UNO_QUERY );
100 [ # # ]: 0 : if( xUpdatable.is() )
101 [ # # ][ # # ]: 0 : xUpdatable->update();
102 : :
103 [ # # ]: 0 : SolarMutexGuard aGuard;
104 [ # # ]: 0 : ExplicitValueProvider* pProvider = ExplicitValueProvider::getExplicitValueProvider( xChartView );
105 [ # # ]: 0 : if( !pProvider )
106 : 0 : return false;
107 [ # # ]: 0 : ::boost::shared_ptr< DrawModelWrapper > pDrawModelWrapper = pProvider->getDrawModelWrapper();
108 [ # # ]: 0 : if( !pDrawModelWrapper.get() )
109 : 0 : return false;
110 [ # # ][ # # ]: 0 : ::boost::shared_ptr< DrawViewWrapper > pDrawViewWrapper( new DrawViewWrapper(&pDrawModelWrapper->getSdrModel(),pOutDev,false) );
[ # # ][ # # ]
111 [ # # ]: 0 : pDrawViewWrapper->attachParentReferenceDevice( xModel );
112 : :
113 [ # # ]: 0 : MapMode aOldMapMode( pOutDev->GetMapMode() );
114 : 0 : Point aOldOrigin( aOldMapMode.GetOrigin() );
115 [ # # ]: 0 : MapMode aMapMode( aOldMapMode );
116 [ # # ][ # # ]: 0 : Point aOldOriginMM( OutputDevice::LogicToLogic( aOldOrigin, aOldMapMode.GetMapUnit(), MAP_100TH_MM ) );
[ # # ][ # # ]
[ # # ]
117 [ # # ][ # # ]: 0 : Point aObjectTopLeftMM( OutputDevice::LogicToLogic( rLogicObjectRect.TopLeft(), aOldMapMode.GetMapUnit(), MAP_100TH_MM ) );
[ # # ][ # # ]
[ # # ]
118 [ # # ]: 0 : aMapMode.SetOrigin( aOldOriginMM + aObjectTopLeftMM );
119 [ # # ]: 0 : aMapMode.SetMapUnit( MAP_100TH_MM );
120 [ # # ]: 0 : pOutDev->SetMapMode(aMapMode);
121 : :
122 [ # # ]: 0 : Rectangle aPaintRect( OutputDevice::LogicToLogic( rLogicObjectRect, aOldMapMode, aMapMode ) );
123 [ # # ][ # # ]: 0 : pDrawViewWrapper->CompleteRedraw(pOutDev, Region(aPaintRect) );
[ # # ]
124 : :
125 [ # # ][ # # ]: 0 : pOutDev->SetMapMode(aOldMapMode);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
126 : : }
127 [ # # ]: 0 : catch( const uno::Exception & ex )
128 : : {
129 : : ASSERT_EXCEPTION( ex );
130 : : }
131 [ # # ]: 0 : catch( ... )
132 : : {
133 : : }
134 : :
135 : 0 : return true;
136 : : }
137 : :
138 : : //-----------------------------------------------------------------
139 : : // ____ XUnoTunnel ___
140 : 0 : ::sal_Int64 SAL_CALL ChartRenderer::getSomething( const Sequence< ::sal_Int8 >& aIdentifier )
141 : : throw( uno::RuntimeException)
142 : : {
143 [ # # # # ]: 0 : if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(
[ # # ]
144 : 0 : ChartPrettyPainter::getUnoTunnelId().getConstArray(),
145 : 0 : aIdentifier.getConstArray(), 16 ) )
146 : : {
147 : 0 : ChartPrettyPainter* pPaintableObject = this;
148 : 0 : return reinterpret_cast<sal_Int64>(pPaintableObject);
149 : : }
150 : 0 : return 0;
151 : : }
152 : :
153 : : //-----------------------------------------------------------------
154 : : // lang::XServiceInfo
155 : :
156 [ # # ][ # # ]: 0 : APPHELPER_XSERVICEINFO_IMPL(ChartRenderer,CHART_RENDERER_SERVICE_IMPLEMENTATION_NAME)
[ # # ][ # # ]
[ # # ]
157 : :
158 : 0 : Sequence< OUString > ChartRenderer::getSupportedServiceNames_Static()
159 : : {
160 : 0 : Sequence< OUString > aSNS;
161 : 0 : return aSNS;
162 : : }
163 : :
164 : : //.............................................................................
165 : : } //namespace chart
166 : : //.............................................................................
167 : :
168 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|