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 
24 #ifndef OOX_DRAWINGML_CHART_CONVERTERBASE_HXX
25 #define OOX_DRAWINGML_CHART_CONVERTERBASE_HXX
26 
27 #include "oox/drawingml/chart/chartcontextbase.hxx"
28 #include "oox/drawingml/chart/objectformatter.hxx"
29 
30 namespace com { namespace sun { namespace star {
31     namespace awt { struct Rectangle; }
32     namespace awt { struct Size; }
33     namespace chart2 { class XChartDocument; }
34     namespace chart2 { class XTitle; }
35     namespace drawing { class XShape; }
36 } } }
37 
38 namespace oox { namespace core {
39     class XmlFilterBase;
40 } }
41 
42 namespace oox {
43 namespace drawingml {
44 namespace chart {
45 
46 class ChartConverter;
47 struct ChartSpaceModel;
48 struct ConverterData;
49 
50 // ============================================================================
51 
52 const sal_Int32 API_PRIM_AXESSET = 0;
53 const sal_Int32 API_SECN_AXESSET = 1;
54 
55 const sal_Int32 API_X_AXIS = 0;
56 const sal_Int32 API_Y_AXIS = 1;
57 const sal_Int32 API_Z_AXIS = 2;
58 
59 // ============================================================================
60 
61 class ConverterRoot
62 {
63 public:
64     explicit            ConverterRoot(
65                             ::oox::core::XmlFilterBase& rFilter,
66                             ChartConverter& rChartConverter,
67                             const ChartSpaceModel& rChartModel,
68                             const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& rxChartDoc,
69                             const ::com::sun::star::awt::Size& rChartSize );
70     virtual             ~ConverterRoot();
71 
72     /** Creates an instance for the passed service name, using the process service factory. */
73     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
74                         createInstance( const ::rtl::OUString& rServiceName ) const;
75 
76 protected:
77     /** Returns the filter object of the imported/exported document. */
78     ::oox::core::XmlFilterBase& getFilter() const;
79     /** Returns the chart converter. */
80     ChartConverter&     getChartConverter() const;
81     /** Returns the API chart document model. */
82     ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >
83                         getChartDocument() const;
84     /** Returns the position and size of the chart shape in 1/100 mm. */
85     const ::com::sun::star::awt::Size& getChartSize() const;
86     /** Returns the object formatter. */
87     ObjectFormatter&    getFormatter() const;
88 
89     /** Registers a title object and its layout data, needed for conversion of
90         the title position using the old Chart1 API. */
91     void                registerTitleLayout(
92                             const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTitle >& rxTitle,
93                             const ModelRef< LayoutModel >& rxLayout, ObjectType eObjType,
94                             sal_Int32 nMainIdx = -1, sal_Int32 nSubIdx = -1 );
95     /** Converts the positions of the main title and all axis titles. */
96     void                convertTitlePositions();
97 
98 private:
99     ::boost::shared_ptr< ConverterData > mxData;
100 };
101 
102 // ============================================================================
103 
104 /** Base class of all converter classes. Holds a reference to a model structure
105     of the specified type.
106  */
107 template< typename ModelType >
108 class ConverterBase : public ConverterRoot
109 {
110 public:
getModel() const111     inline const ModelType& getModel() const { return mrModel; }
112 
113 protected:
ConverterBase(const ConverterRoot & rParent,ModelType & rModel)114     inline explicit     ConverterBase( const ConverterRoot& rParent, ModelType& rModel ) :
115                             ConverterRoot( rParent ), mrModel( rModel ) {}
~ConverterBase()116     virtual             ~ConverterBase() {}
117 
118 protected:
119     ModelType&          mrModel;
120 };
121 
122 // ============================================================================
123 
124 /** A layout converter calculates positions and sizes for various chart objects.
125  */
126 class LayoutConverter : public ConverterBase< LayoutModel >
127 {
128 public:
129     explicit            LayoutConverter( const ConverterRoot& rParent, LayoutModel& rModel );
130     virtual             ~LayoutConverter();
131 
132     /** Tries to calculate the absolute position and size from the contained
133         OOXML layout model. Returns true, if returned rectangle is valid. */
134     bool                calcAbsRectangle( ::com::sun::star::awt::Rectangle& orRect ) const;
135 
136     /** Tries to set the position and size from the contained OOXML layout model.
137         Returns true, if a manual position and size could be calculated. */
138     bool                convertFromModel( PropertySet& rPropSet );
139 
140     /** Tries to set the position from the contained OOXML layout model.
141         Returns true, if a manual position could be calculated. */
142     bool                convertFromModel(
143                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
144                             double fRotationAngle );
getAutoLayout()145 	bool getAutoLayout(){return mrModel.mbAutoLayout;}
146 };
147 
148 // ============================================================================
149 
150 } // namespace chart
151 } // namespace drawingml
152 } // namespace oox
153 
154 #endif
155