1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef CHART2_DIALOGMODEL_HXX
28 #define CHART2_DIALOGMODEL_HXX
29 
30 #include "TimerTriggeredControllerLock.hxx"
31 #include <com/sun/star/chart2/XChartDocument.hpp>
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 
35 #include <vector>
36 #include <map>
37 #include <boost/shared_ptr.hpp>
38 
39 namespace com { namespace sun { namespace star { namespace chart2 {
40     class XDataSeriesContainer;
41     class XDataSeries;
42     class XChartType;
43     class XChartTypeTemplate;
44     struct InterpretedData;
45     namespace data {
46         class XDataProvider;
47         class XLabeledDataSequence;
48     }
49 }}}}
50 
51 namespace chart
52 {
53 
54 class RangeSelectionHelper;
55 
56 class DialogModel
57 {
58 public:
59 	explicit DialogModel(
60         const ::com::sun::star::uno::Reference<
61             ::com::sun::star::chart2::XChartDocument > & xChartDocument,
62         const ::com::sun::star::uno::Reference<
63             ::com::sun::star::uno::XComponentContext > & xContext );
64 	~DialogModel();
65 
66     typedef ::std::pair<
67                 ::rtl::OUString,
68                 ::std::pair< ::com::sun::star::uno::Reference<
69                                  ::com::sun::star::chart2::XDataSeries >,
70                              ::com::sun::star::uno::Reference<
71                                  ::com::sun::star::chart2::XChartType > > >
72         tSeriesWithChartTypeByName;
73 
74     typedef ::std::map< ::rtl::OUString, ::rtl::OUString >
75         tRolesWithRanges;
76 
77     void setTemplate(
78         const ::com::sun::star::uno::Reference<
79             ::com::sun::star::chart2::XChartTypeTemplate > & xTemplate );
80 
81     ::boost::shared_ptr< RangeSelectionHelper >
82         getRangeSelectionHelper() const;
83 
84     ::com::sun::star::uno::Reference<
85         ::com::sun::star::frame::XModel >
86         getChartModel() const;
87 
88     ::com::sun::star::uno::Reference<
89             ::com::sun::star::chart2::data::XDataProvider >
90         getDataProvider() const;
91 
92     ::std::vector< ::com::sun::star::uno::Reference<
93             ::com::sun::star::chart2::XDataSeriesContainer > >
94         getAllDataSeriesContainers() const;
95 
96     ::std::vector< tSeriesWithChartTypeByName >
97         getAllDataSeriesWithLabel() const;
98 
99     tRolesWithRanges getRolesWithRanges(
100         const ::com::sun::star::uno::Reference<
101             ::com::sun::star::chart2::XDataSeries > & xSeries,
102         const ::rtl::OUString & aRoleOfSequenceForLabel,
103         const ::com::sun::star::uno::Reference<
104             ::com::sun::star::chart2::XChartType > & xChartType ) const;
105 
106     enum eMoveDirection
107     {
108         MOVE_DOWN,
109         MOVE_UP
110     };
111 
112     void moveSeries( const ::com::sun::star::uno::Reference<
113                          ::com::sun::star::chart2::XDataSeries > & xSeries,
114                      eMoveDirection eDirection );
115 
116     /// @return the newly inserted series
117     ::com::sun::star::uno::Reference<
118             ::com::sun::star::chart2::XDataSeries > insertSeriesAfter(
119                 const ::com::sun::star::uno::Reference<
120                     ::com::sun::star::chart2::XDataSeries > & xSeries,
121                 const ::com::sun::star::uno::Reference<
122                     ::com::sun::star::chart2::XChartType > & xChartType,
123                 bool bCreateDataCachedSequences = false );
124 
125     void deleteSeries(
126         const ::com::sun::star::uno::Reference<
127             ::com::sun::star::chart2::XDataSeries > & xSeries,
128         const ::com::sun::star::uno::Reference<
129             ::com::sun::star::chart2::XChartType > & xChartType );
130 
131     ::com::sun::star::uno::Reference<
132             ::com::sun::star::chart2::data::XLabeledDataSequence >
133         getCategories() const;
134 
135     void setCategories( const ::com::sun::star::uno::Reference<
136                         ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories );
137 
138     ::rtl::OUString getCategoriesRange() const;
139 
140     bool isCategoryDiagram() const;
141 
142     void detectArguments(
143         ::rtl::OUString & rOutRangeString,
144         bool & rOutUseColumns, bool & rOutFirstCellAsLabel, bool & rOutHasCategories ) const;
145 
146     bool allArgumentsForRectRangeDetected() const;
147 
148     bool setData( const ::com::sun::star::uno::Sequence<
149                       ::com::sun::star::beans::PropertyValue > & rArguments );
150 
151     void startControllerLockTimer();
152 
153     static ::rtl::OUString ConvertRoleFromInternalToUI( const ::rtl::OUString & rRoleString );
154     static ::rtl::OUString GetRoleDataLabel();
155 
156     // pass a role string (not translated) and get an index that serves for
157     // relative ordering, to get e.g. x-values and y-values in the right order
158     static sal_Int32 GetRoleIndexForSorting( const ::rtl::OUString & rInternalRoleString );
159 
160 private:
161     ::com::sun::star::uno::Reference<
162             ::com::sun::star::chart2::XChartDocument >
163         m_xChartDocument;
164 
165     ::com::sun::star::uno::Reference<
166             ::com::sun::star::chart2::XChartTypeTemplate >
167         m_xTemplate;
168 
169     ::com::sun::star::uno::Reference<
170             ::com::sun::star::uno::XComponentContext >
171         m_xContext;
172 
173     mutable ::boost::shared_ptr< RangeSelectionHelper >
174         m_spRangeSelectionHelper;
175 
176     TimerTriggeredControllerLock   m_aTimerTriggeredControllerLock;
177 
178 private:
179     void createBackup();
180 
181     void applyInterpretedData(
182         const ::com::sun::star::chart2::InterpretedData & rNewData,
183         const ::std::vector< ::com::sun::star::uno::Reference<
184             ::com::sun::star::chart2::XDataSeries > > & rSeriesToReUse,
185         bool bSetStyles );
186 
187     sal_Int32 countSeries() const;
188 };
189 
190 } //  namespace chart
191 
192 // CHART2_DIALOGMODEL_HXX
193 #endif
194