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 #ifndef _CHARTVIEWIMPL_HXX
24 #define _CHARTVIEWIMPL_HXX
25 
26 #include "chartview/ExplicitValueProvider.hxx"
27 #include "ServiceMacros.hxx"
28 #include <cppuhelper/implbase9.hxx>
29 #include <cppuhelper/interfacecontainer.hxx>
30 
31 // header for class SfxListener
32 #include <svl/lstner.hxx>
33 #include <com/sun/star/datatransfer/XTransferable.hpp>
34 #include <com/sun/star/drawing/XDrawPage.hpp>
35 #include <com/sun/star/frame/XModel.hpp>
36 #include <com/sun/star/io/XOutputStream.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <com/sun/star/util/XModifyListener.hpp>
43 #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
44 #include <com/sun/star/util/XUpdatable.hpp>
45 
46 #include <vector>
47 #include <boost/shared_ptr.hpp>
48 
49 class SdrPage;
50 
51 //.............................................................................
52 namespace chart
53 {
54 //.............................................................................
55 
56 class VCoordinateSystem;
57 class DrawModelWrapper;
58 class SeriesPlotterContainer;
59 
60 //-----------------------------------------------------------------------------
61 /** The ChartView is responsible to manage the generation of Drawing Objects
62 for visualization on a given OutputDevice. The ChartModel is responsible to notify changes to the view.
63 The view than changes to state dirty. The view can be updated with call 'update'.
64 
65 The View is not responsible to handle single user events (that is instead done by the ChartWindow).
66 */
67 
68 class ChartView : public ::cppu::WeakImplHelper9<
69 	::com::sun::star::lang::XInitialization
70 		, ::com::sun::star::lang::XServiceInfo
71         , ::com::sun::star::datatransfer::XTransferable
72         ,::com::sun::star::lang::XUnoTunnel
73 		//::com::sun::star::lang::XComponent ???
74 		//::com::sun::star::uno::XWeak			// implemented by WeakImplHelper(optional interface)
75 		//::com::sun::star::uno::XInterface		// implemented by WeakImplHelper(optional interface)
76 		//::com::sun::star::lang::XTypeProvider	// implemented by WeakImplHelper
77         ,::com::sun::star::util::XModifyListener
78         ,::com::sun::star::util::XModeChangeBroadcaster
79         ,::com::sun::star::util::XUpdatable
80         ,::com::sun::star::beans::XPropertySet
81         ,::com::sun::star::lang::XMultiServiceFactory
82 		>
83         , public ExplicitValueProvider
84         , private SfxListener
85 {
86 public:
87     ChartView(::com::sun::star::uno::Reference<
88 			   ::com::sun::star::uno::XComponentContext > const & xContext);
89 	virtual ~ChartView();
90 
91     // ___lang::XServiceInfo___
92 	APPHELPER_XSERVICEINFO_DECL()
93 	APPHELPER_SERVICE_FACTORY_HELPER(ChartView)
94 
95 	// ___lang::XInitialization___
96     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
97                 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
98 
99     // ___ExplicitValueProvider___
100     virtual sal_Bool getExplicitValuesForAxis(
101         ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > xAxis
102         , ExplicitScaleData&  rExplicitScale
103         , ExplicitIncrementData& rExplicitIncrement );
104     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
105         getShapeForCID( const rtl::OUString& rObjectCID );
106 
107     virtual ::com::sun::star::awt::Rectangle getRectangleOfObject( const rtl::OUString& rObjectCID, bool bSnapRect=false );
108 
109     virtual ::com::sun::star::awt::Rectangle getDiagramRectangleExcludingAxes();
110 
111     ::boost::shared_ptr< DrawModelWrapper > getDrawModelWrapper();
112 
113     // ___XTransferable___
114     virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
115                 throw (::com::sun::star::datatransfer::UnsupportedFlavorException
116                      , ::com::sun::star::io::IOException
117                      , ::com::sun::star::uno::RuntimeException);
118     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors(  )
119                 throw (::com::sun::star::uno::RuntimeException);
120     virtual ::sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
121                 throw (::com::sun::star::uno::RuntimeException);
122 
123     //-------------------------------------------------------------------------------------
124 	// ::com::sun::star::util::XEventListener (base of XCloseListener and XModifyListener)
125 	//-------------------------------------------------------------------------------------
126 	virtual void SAL_CALL
127 		disposing( const ::com::sun::star::lang::EventObject& Source )
128 							throw (::com::sun::star::uno::RuntimeException);
129 
130     //-----------------------------------------------------------------
131     // ::com::sun::star::util::XModifyListener
132     //-----------------------------------------------------------------
133     virtual void SAL_CALL modified(
134         const ::com::sun::star::lang::EventObject& aEvent )
135         throw (::com::sun::star::uno::RuntimeException);
136 
137     //SfxListener
138     virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
139 
140     //-----------------------------------------------------------------
141     // ::com::sun::star::util::XModeChangeBroadcaster
142     //-----------------------------------------------------------------
143 
144     virtual void SAL_CALL addModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
145     virtual void SAL_CALL removeModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
146     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);
147     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);
148 
149     //-----------------------------------------------------------------
150     // ::com::sun::star::util::XUpdatable
151     //-----------------------------------------------------------------
152     virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);
153 
154     //-----------------------------------------------------------------
155     // ::com::sun::star::beans::XPropertySet
156     //-----------------------------------------------------------------
157     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (::com::sun::star::uno::RuntimeException);
158     virtual void SAL_CALL setPropertyValue( const ::rtl::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);
159     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
160     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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);
161     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::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);
162     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::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);
163     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::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);
164 
165     //-----------------------------------------------------------------
166     // ::com::sun::star::lang::XMultiServiceFactory
167     //-----------------------------------------------------------------
168     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier )
169         throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
170     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments(
171         const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments )
172         throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
173     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames() throw (::com::sun::star::uno::RuntimeException);
174 
175     // for ExplicitValueProvider
176     // ____ XUnoTunnel ___
177     virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier )
178             throw (::com::sun::star::uno::RuntimeException);
179 
180 private: //methods
181     ChartView();
182 
183     void createShapes();
184     void getMetaFile( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream
185                       , bool bUseHighContrast );
186     SdrPage* getSdrPage();
187 
188     void impl_setChartModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel );
189     void impl_deleteCoordinateSystems();
190     void impl_notifyModeChangeListener( const rtl::OUString& rNewMode );
191 
192     void impl_refreshAddIn();
193     bool impl_AddInDrawsAllByItself();
194 
195     void impl_updateView();
196 
197     ::com::sun::star::awt::Rectangle impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer
198         , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes>& xDiagramPlusAxes_Shapes
199         , const ::com::sun::star::awt::Point& rAvailablePos
200         , const ::com::sun::star::awt::Size& rAvailableSize
201         , const ::com::sun::star::awt::Size& rPageSize
202         , bool bUseFixedInnerSize
203         , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& xDiagram_MarkHandles );
204 
205 
206 private: //member
207     ::osl::Mutex m_aMutex;
208 
209 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
210 			m_xCC;
211     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
212             m_xChartModel;
213 
214 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>
215 			m_xShapeFactory;
216 	::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>
217 			m_xDrawPage;
218 
219     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xDashTable;
220     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xGradientTable;
221     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xHatchTable;
222     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xBitmapTable;
223     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xTransGradientTable;
224     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xMarkerTable;
225 
226     ::boost::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;
227 
228     std::vector< VCoordinateSystem* > m_aVCooSysList;
229 
230     ::cppu::OMultiTypeInterfaceContainerHelper
231                         m_aListenerContainer;
232 
233     bool volatile       m_bViewDirty; //states wether the view needs to be rebuild
234     bool volatile       m_bInViewUpdate;
235     bool volatile       m_bViewUpdatePending;
236     bool volatile		m_bRefreshAddIn;
237 
238     //better performance for big data
239     ::com::sun::star::awt::Size m_aPageResolution;
240     bool m_bPointsWereSkipped;
241 
242     //#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100%
243     sal_Int32 m_nScaleXNumerator;
244     sal_Int32 m_nScaleXDenominator;
245     sal_Int32 m_nScaleYNumerator;
246     sal_Int32 m_nScaleYDenominator;
247 
248     sal_Bool m_bSdrViewIsInEditMode;
249 
250     ::com::sun::star::awt::Rectangle m_aResultingDiagramRectangleExcludingAxes;
251 };
252 
253 //.............................................................................
254 } //namespace chart
255 //.............................................................................
256 
257 #endif
258