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