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 : #ifndef INCLUDED_CHART2_INC_CHARTVIEW_HXX
20 : #define INCLUDED_CHART2_INC_CHARTVIEW_HXX
21 :
22 : #include "ChartModel.hxx"
23 : #include "chartview/ExplicitValueProvider.hxx"
24 : #include <cppuhelper/implbase10.hxx>
25 : #include <cppuhelper/interfacecontainer.hxx>
26 :
27 : #include <svl/lstner.hxx>
28 : #include <com/sun/star/datatransfer/XTransferable.hpp>
29 : #include <com/sun/star/drawing/XDrawPage.hpp>
30 : #include <com/sun/star/frame/XModel.hpp>
31 : #include <com/sun/star/io/XOutputStream.hpp>
32 : #include <com/sun/star/lang/XInitialization.hpp>
33 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : #include <com/sun/star/lang/XUnoTunnel.hpp>
36 : #include <com/sun/star/uno/XComponentContext.hpp>
37 : #include <com/sun/star/util/XModifyListener.hpp>
38 : #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
39 : #include <com/sun/star/util/XUpdatable2.hpp>
40 : #include <com/sun/star/qa/XDumper.hpp>
41 :
42 : #include <vector>
43 : #include <boost/shared_ptr.hpp>
44 : #include <boost/ptr_container/ptr_vector.hpp>
45 :
46 : #include <vcl/timer.hxx>
47 :
48 : class SdrPage;
49 :
50 : namespace chart {
51 :
52 : class VCoordinateSystem;
53 : class DrawModelWrapper;
54 : class VDataSeries;
55 : class GL3DPlotterBase;
56 : class GL2DRenderer;
57 : struct CreateShapeParam2D;
58 :
59 : enum TimeBasedMode
60 : {
61 : MANUAL,
62 : AUTOMATIC,
63 : AUTOMATIC_WRAP
64 : };
65 :
66 305 : struct TimeBasedInfo
67 : {
68 321 : TimeBasedInfo():
69 : bTimeBased(false),
70 : nFrame(0),
71 321 : eMode(AUTOMATIC) {}
72 :
73 : bool bTimeBased;
74 : size_t nFrame;
75 : TimeBasedMode eMode;
76 : Timer maTimer;
77 :
78 : // only valid when we are in the time based mode
79 : ::std::vector< std::vector< VDataSeries* > > m_aDataSeriesList;
80 : };
81 :
82 : /**
83 : * The ChartView is responsible to manage the generation of Drawing Objects
84 : * for visualization on a given OutputDevice. The ChartModel is responsible
85 : * to notify changes to the view. The view than changes to state dirty. The
86 : * view can be updated with call 'update'.
87 : *
88 : * The View is not responsible to handle single user events (that is instead
89 : * done by the ChartWindow).
90 : */
91 : class ChartView : public ::cppu::WeakImplHelper10<
92 : ::com::sun::star::lang::XInitialization
93 : ,::com::sun::star::lang::XServiceInfo
94 : ,::com::sun::star::datatransfer::XTransferable
95 : ,::com::sun::star::lang::XUnoTunnel
96 : ,::com::sun::star::util::XModifyListener
97 : ,::com::sun::star::util::XModeChangeBroadcaster
98 : ,::com::sun::star::util::XUpdatable2
99 : ,::com::sun::star::beans::XPropertySet
100 : ,::com::sun::star::lang::XMultiServiceFactory
101 : ,::com::sun::star::qa::XDumper
102 : >
103 : , public ExplicitValueProvider
104 : , private SfxListener
105 : {
106 : friend class GL2DRenderer;
107 : private:
108 : void init();
109 :
110 : public:
111 : ChartView(::com::sun::star::uno::Reference<
112 : ::com::sun::star::uno::XComponentContext > const & xContext,
113 : ChartModel& rModel);
114 :
115 : virtual ~ChartView();
116 :
117 : // ___lang::XServiceInfo___
118 : virtual OUString SAL_CALL getImplementationName()
119 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
120 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
121 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
122 : virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
123 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
124 :
125 : static OUString getImplementationName_Static();
126 : static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
127 :
128 : // ___lang::XInitialization___
129 : virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
130 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 :
132 : // ___ExplicitValueProvider___
133 : virtual bool getExplicitValuesForAxis(
134 : ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > xAxis
135 : , ExplicitScaleData& rExplicitScale
136 : , ExplicitIncrementData& rExplicitIncrement ) SAL_OVERRIDE;
137 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
138 : getShapeForCID( const OUString& rObjectCID ) SAL_OVERRIDE;
139 :
140 : virtual ::com::sun::star::awt::Rectangle getRectangleOfObject( const OUString& rObjectCID, bool bSnapRect=false ) SAL_OVERRIDE;
141 :
142 : virtual ::com::sun::star::awt::Rectangle getDiagramRectangleExcludingAxes() SAL_OVERRIDE;
143 :
144 : ::boost::shared_ptr< DrawModelWrapper > getDrawModelWrapper() SAL_OVERRIDE;
145 :
146 : // ___XTransferable___
147 : virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
148 : throw (::com::sun::star::datatransfer::UnsupportedFlavorException
149 : , ::com::sun::star::io::IOException
150 : , ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( )
152 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 : virtual sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
154 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 :
156 : // ::com::sun::star::util::XEventListener (base of XCloseListener and XModifyListener)
157 : virtual void SAL_CALL
158 : disposing( const ::com::sun::star::lang::EventObject& Source )
159 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 :
161 : // ::com::sun::star::util::XModifyListener
162 : virtual void SAL_CALL modified(
163 : const ::com::sun::star::lang::EventObject& aEvent )
164 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 :
166 : //SfxListener
167 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
168 :
169 : // ::com::sun::star::util::XModeChangeBroadcaster
170 :
171 : virtual void SAL_CALL addModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual void SAL_CALL removeModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual void SAL_CALL addModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 : virtual void SAL_CALL removeModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 :
176 : // ::com::sun::star::util::XUpdatable
177 : virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 :
179 : // util::XUpdatable2
180 : virtual void SAL_CALL updateSoft() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 : virtual void SAL_CALL updateHard() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 :
183 : // ::com::sun::star::beans::XPropertySet
184 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
185 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
186 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
188 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
189 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
191 :
192 : // ::com::sun::star::lang::XMultiServiceFactory
193 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier )
194 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
195 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments(
196 : const OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments )
197 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
198 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 :
200 : // for ExplicitValueProvider
201 : // ____ XUnoTunnel ___
202 : virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier )
203 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
204 :
205 : // XDumper
206 : virtual OUString SAL_CALL dump()
207 : throw(::com::sun::star::uno::RuntimeException,
208 : std::exception) SAL_OVERRIDE;
209 :
210 : void setViewDirty();
211 : void updateOpenGLWindow();
212 :
213 : private: //methods
214 : ChartView();
215 :
216 : void createShapes();
217 : void createShapes2D( const css::awt::Size& rPageSize );
218 : bool createAxisTitleShapes2D( CreateShapeParam2D& rParam, const css::awt::Size& rPageSize );
219 : void createShapes3D();
220 : bool isReal3DChart();
221 : void getMetaFile( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream
222 : , bool bUseHighContrast );
223 : SdrPage* getSdrPage();
224 :
225 : void impl_deleteCoordinateSystems();
226 : void impl_notifyModeChangeListener( const OUString& rNewMode );
227 :
228 : void impl_refreshAddIn();
229 :
230 : void impl_updateView( bool bCheckLockedCtrler = true );
231 :
232 : void render();
233 :
234 : css::awt::Rectangle impl_createDiagramAndContent( const CreateShapeParam2D& rParam, const css::awt::Size& rPageSize );
235 :
236 : DECL_LINK_TYPED( UpdateTimeBased, Timer*, void );
237 :
238 : private: //member
239 : ::osl::Mutex m_aMutex;
240 :
241 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
242 : m_xCC;
243 :
244 : chart::ChartModel& mrChartModel;
245 :
246 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>
247 : m_xShapeFactory;
248 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>
249 : m_xDrawPage;
250 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
251 : mxRootShape;
252 :
253 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xDashTable;
254 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xGradientTable;
255 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xHatchTable;
256 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xBitmapTable;
257 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xTransGradientTable;
258 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xMarkerTable;
259 :
260 : ::boost::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;
261 :
262 : std::vector< VCoordinateSystem* > m_aVCooSysList;
263 :
264 : ::cppu::OMultiTypeInterfaceContainerHelper
265 : m_aListenerContainer;
266 :
267 : bool m_bViewDirty; //states whether the view needs to be rebuild
268 : bool m_bInViewUpdate;
269 : bool m_bViewUpdatePending;
270 : bool m_bRefreshAddIn;
271 :
272 : //better performance for big data
273 : ::com::sun::star::awt::Size m_aPageResolution;
274 : bool m_bPointsWereSkipped;
275 :
276 : //#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100%
277 : sal_Int32 m_nScaleXNumerator;
278 : sal_Int32 m_nScaleXDenominator;
279 : sal_Int32 m_nScaleYNumerator;
280 : sal_Int32 m_nScaleYDenominator;
281 :
282 : bool m_bSdrViewIsInEditMode;
283 :
284 : ::com::sun::star::awt::Rectangle m_aResultingDiagramRectangleExcludingAxes;
285 :
286 : boost::shared_ptr<GL3DPlotterBase> m_pGL3DPlotter;
287 : TimeBasedInfo maTimeBased;
288 : osl::Mutex maTimeMutex;
289 : boost::scoped_ptr<GL2DRenderer> mp2DRenderer;
290 : };
291 :
292 : }
293 :
294 : #endif
295 :
296 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|